Home | History | Annotate | Line # | Download | only in oea
prep_machdep.c revision 1.11
      1 /* $NetBSD: prep_machdep.c,v 1.11 2016/12/22 14:47:58 cherry 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.11 2016/12/22 14:47:58 cherry Exp $");
     41 
     42 #include "opt_modular.h"
     43 
     44 #include <sys/param.h>
     45 #include <sys/extent.h>
     46 #include <sys/kernel.h>
     47 #include <sys/reboot.h>
     48 #include <sys/ksyms.h>
     49 
     50 #include <uvm/uvm_extern.h>
     51 #include <machine/powerpc.h>
     52 #include <sys/bus.h>
     53 #include <machine/pmap.h>
     54 #include <powerpc/oea/bat.h>
     55 
     56 #include "opt_ddb.h"
     57 #ifdef DDB
     58 #include <machine/db_machdep.h>
     59 #include <ddb/db_extern.h>
     60 #endif
     61 
     62 #include "ksyms.h"
     63 
     64 #if NKSYMS || defined(DDB) || defined(MODULAR)
     65 extern void *endsym, *startsym;
     66 #endif
     67 extern struct mem_region physmemr[2], availmemr[2];
     68 
     69 struct powerpc_bus_space prep_io_space_tag = {
     70 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
     71 	.pbs_offset = PREP_BUS_SPACE_IO,
     72 	.pbs_base = 0x00000000,
     73 	.pbs_limit = PREP_PHYS_SIZE_IO,
     74 };
     75 
     76 struct powerpc_bus_space genppc_isa_io_space_tag = {
     77 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
     78 	.pbs_offset = PREP_BUS_SPACE_IO,
     79 	.pbs_base = 0x00000000,
     80 	.pbs_limit = PREP_ISA_SIZE_IO,
     81 };
     82 
     83 struct powerpc_bus_space prep_mem_space_tag = {
     84 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
     85 	.pbs_offset = PREP_BUS_SPACE_MEM,
     86 	.pbs_base = 0x00000000,
     87 	.pbs_limit = PREP_PHYS_SIZE_MEM,
     88 };
     89 
     90 struct powerpc_bus_space genppc_isa_mem_space_tag = {
     91 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
     92 	.pbs_offset = PREP_BUS_SPACE_MEM,
     93 	.pbs_base = 0x00000000,
     94 	.pbs_limit = PREP_ISA_SIZE_MEM,
     95 };
     96 
     97 static char ex_storage[2][EXTENT_FIXED_STORAGE_SIZE(8)]
     98 	__attribute__((aligned(8)));
     99 
    100 void
    101 prep_bus_space_init(void)
    102 {
    103 	int error;
    104 
    105 	error = bus_space_init(&prep_io_space_tag, "ioport",
    106 	    ex_storage[0], sizeof(ex_storage[0]));
    107 	if (error)
    108 		panic("prep_bus_space_init: can't init io tag");
    109 
    110 	error = extent_alloc_region(prep_io_space_tag.pbs_extent,
    111 	    PREP_PHYS_RESVD_START_IO, PREP_PHYS_RESVD_SIZE_IO, EX_NOWAIT);
    112 	if (error)
    113 		panic("prep_bus_space_init: can't block out reserved I/O"
    114 		    " space 0x10000-0x7fffff: error=%d", error);
    115 
    116 	error = bus_space_init(&prep_mem_space_tag, "iomem",
    117 	    ex_storage[1], sizeof(ex_storage[1]));
    118 	if (error)
    119 		panic("prep_bus_space_init: can't init mem tag");
    120 
    121 	genppc_isa_io_space_tag.pbs_extent = prep_io_space_tag.pbs_extent;
    122 	error = bus_space_init(&genppc_isa_io_space_tag, "isa-ioport", NULL, 0);	if (error)
    123 		panic("prep_bus_space_init: can't init isa io tag");
    124 
    125 	genppc_isa_mem_space_tag.pbs_extent = prep_mem_space_tag.pbs_extent;
    126 	error = bus_space_init(&genppc_isa_mem_space_tag, "isa-iomem", NULL, 0);
    127 	if (error)
    128 		panic("prep_bus_space_init: can't init isa mem tag");
    129 }
    130 
    131 /*
    132  * just a few calls used in initppc() all in one place so everything gets
    133  * done the same across the ports
    134  */
    135 
    136 void
    137 prep_initppc(u_long startkernel, u_long endkernel, u_int args)
    138 {
    139 
    140 	/*
    141 	 * Now setup fixed bat registers
    142 	 * We setup the memory BAT, the IO space BAT, and a special
    143 	 * BAT for certain machines that have rs6k style PCI bridges
    144 	 * (only on port-prep)
    145 	 */
    146 	oea_batinit(
    147 	    PREP_BUS_SPACE_MEM, BAT_BL_256M,
    148 	    PREP_BUS_SPACE_IO,  BAT_BL_256M,
    149 #if defined(bebox)
    150 	    0x7ffff000, BAT_BL_8M,	/* BeBox Mainboard Registers (4KB) */
    151 #elif defined(prep)
    152 	    0xbf800000, BAT_BL_8M,
    153 #endif
    154 	    0);
    155 
    156 	/* Install vectors and interrupt handler. */
    157 	oea_init(NULL);
    158 
    159 	/* Initialize bus_space. */
    160 	prep_bus_space_init();
    161 
    162 	/* Initialize the console asap. */
    163 	consinit();
    164 
    165 	/* Set the page size */
    166 	uvm_md_init();
    167 
    168 	/* Initialize pmap module */
    169 	pmap_bootstrap(startkernel, endkernel);
    170 
    171 #if NKSYMS || defined(DDB) || defined(MODULAR)
    172 	ksyms_addsyms_elf((int)((u_long)endsym - (u_long)startsym), startsym, endsym);
    173 #endif
    174 
    175 #ifdef DDB
    176 	boothowto = args;
    177 	if (boothowto & RB_KDB)
    178 		Debugger();
    179 #endif
    180 }
    181 
    182 void
    183 mem_regions(struct mem_region **mem, struct mem_region **avail)
    184 {
    185 
    186 	*mem = physmemr;
    187 	*avail = availmemr;
    188 }
    189