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