Home | History | Annotate | Line # | Download | only in oea
prep_machdep.c revision 1.4
      1 /* $NetBSD: prep_machdep.c,v 1.4 2008/11/12 12:36:05 ad Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tim Rightnour
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * This is a set of general routines that most PReP-similar machines have
     34  * in common.  Machines that use these routines do not have to be fully
     35  * PReP compliant, the only requirement is that they use a PReP memory map.
     36  * IE, io at 0x80000000 and mem at 0xc0000000.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: prep_machdep.c,v 1.4 2008/11/12 12:36:05 ad Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/extent.h>
     44 #include <sys/kernel.h>
     45 #include <sys/malloc.h>
     46 #include <sys/reboot.h>
     47 #include <sys/ksyms.h>
     48 
     49 #include <uvm/uvm_extern.h>
     50 #include <machine/powerpc.h>
     51 #include <machine/bus.h>
     52 #include <machine/pmap.h>
     53 #include <powerpc/oea/bat.h>
     54 
     55 #include "opt_ddb.h"
     56 #ifdef DDB
     57 #include <machine/db_machdep.h>
     58 #include <ddb/db_extern.h>
     59 #endif
     60 
     61 #include "ksyms.h"
     62 
     63 #if NKSYMS || defined(DDB) || defined(MODULAR)
     64 extern void *endsym, *startsym;
     65 #endif
     66 extern struct mem_region physmemr[2], availmemr[2];
     67 
     68 struct powerpc_bus_space prep_io_space_tag = {
     69 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
     70 	.pbs_offset = PREP_BUS_SPACE_IO,
     71 	.pbs_base = 0x00000000,
     72 	.pbs_limit = PREP_PHYS_SIZE_IO,
     73 };
     74 
     75 struct powerpc_bus_space genppc_isa_io_space_tag = {
     76 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
     77 	.pbs_offset = PREP_BUS_SPACE_IO,
     78 	.pbs_base = 0x00000000,
     79 	.pbs_limit = PREP_ISA_SIZE_IO,
     80 };
     81 
     82 struct powerpc_bus_space prep_mem_space_tag = {
     83 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
     84 	.pbs_offset = PREP_BUS_SPACE_MEM,
     85 	.pbs_base = 0x00000000,
     86 	.pbs_limit = PREP_PHYS_SIZE_MEM,
     87 };
     88 
     89 struct powerpc_bus_space genppc_isa_mem_space_tag = {
     90 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
     91 	.pbs_offset = PREP_BUS_SPACE_MEM,
     92 	.pbs_base = 0x00000000,
     93 	.pbs_limit = PREP_ISA_SIZE_MEM,
     94 };
     95 
     96 static char ex_storage[2][EXTENT_FIXED_STORAGE_SIZE(8)]
     97 	__attribute__((aligned(8)));
     98 
     99 void
    100 prep_bus_space_init(void)
    101 {
    102 	int error;
    103 
    104 	error = bus_space_init(&prep_io_space_tag, "ioport",
    105 	    ex_storage[0], sizeof(ex_storage[0]));
    106 	if (error)
    107 		panic("prep_bus_space_init: can't init io tag");
    108 
    109 	error = extent_alloc_region(prep_io_space_tag.pbs_extent,
    110 	    PREP_PHYS_RESVD_START_IO, PREP_PHYS_RESVD_SIZE_IO, EX_NOWAIT);
    111 	if (error)
    112 		panic("prep_bus_space_init: can't block out reserved I/O"
    113 		    " space 0x10000-0x7fffff: error=%d", error);
    114 
    115 	error = bus_space_init(&prep_mem_space_tag, "iomem",
    116 	    ex_storage[1], sizeof(ex_storage[1]));
    117 	if (error)
    118 		panic("prep_bus_space_init: can't init mem tag");
    119 
    120 	genppc_isa_io_space_tag.pbs_extent = prep_io_space_tag.pbs_extent;
    121 	error = bus_space_init(&genppc_isa_io_space_tag, "isa-ioport", NULL, 0);	if (error)
    122 		panic("prep_bus_space_init: can't init isa io tag");
    123 
    124 	genppc_isa_mem_space_tag.pbs_extent = prep_mem_space_tag.pbs_extent;
    125 	error = bus_space_init(&genppc_isa_mem_space_tag, "isa-iomem", NULL, 0);
    126 	if (error)
    127 		panic("prep_bus_space_init: can't init isa mem tag");
    128 }
    129 
    130 /*
    131  * just a few calls used in initppc() all in one place so everything gets
    132  * done the same across the ports
    133  */
    134 
    135 void
    136 prep_initppc(u_long startkernel, u_long endkernel, u_int args)
    137 {
    138 
    139 	/*
    140 	 * Now setup fixed bat registers
    141 	 * We setup the memory BAT, the IO space BAT, and a special
    142 	 * BAT for certain machines that have rs6k style PCI bridges
    143 	 * (only on port-prep)
    144 	 */
    145 	oea_batinit(
    146 	    PREP_BUS_SPACE_MEM, BAT_BL_256M,
    147 	    PREP_BUS_SPACE_IO,  BAT_BL_256M,
    148 #ifdef prep
    149 	    0xbf800000, BAT_BL_8M,
    150 #endif
    151 	    0);
    152 
    153 	/* Install vectors and interrupt handler. */
    154 	oea_init(NULL);
    155 
    156 	/* Initialize bus_space. */
    157 	prep_bus_space_init();
    158 
    159 	/* Initialize the console asap. */
    160 	consinit();
    161 
    162 	/* Set the page size */
    163 	uvm_setpagesize();
    164 
    165 	/* Initialize pmap module */
    166 	pmap_bootstrap(startkernel, endkernel);
    167 
    168 #if NKSYMS || defined(DDB) || defined(MODULAR)
    169 	ksyms_init((int)((u_long)endsym - (u_long)startsym), startsym, endsym);
    170 #endif
    171 
    172 #ifdef DDB
    173 	boothowto = args;
    174 	if (boothowto & RB_KDB)
    175 		Debugger();
    176 #endif
    177 }
    178 
    179 void
    180 mem_regions(struct mem_region **mem, struct mem_region **avail)
    181 {
    182 
    183 	*mem = physmemr;
    184 	*avail = availmemr;
    185 }
    186