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