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