armadillo9_machdep.c revision 1.8.6.2 1 1.8.6.2 yamt /* $NetBSD: armadillo9_machdep.c,v 1.8.6.2 2006/06/21 14:50:32 yamt Exp $ */
2 1.8.6.2 yamt
3 1.8.6.2 yamt /*
4 1.8.6.2 yamt * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 1.8.6.2 yamt * All rights reserved.
6 1.8.6.2 yamt *
7 1.8.6.2 yamt * Based on code written by Jason R. Thorpe and Steve C. Woodford for
8 1.8.6.2 yamt * Wasabi Systems, Inc.
9 1.8.6.2 yamt *
10 1.8.6.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.8.6.2 yamt * modification, are permitted provided that the following conditions
12 1.8.6.2 yamt * are met:
13 1.8.6.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.8.6.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.8.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.8.6.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.8.6.2 yamt * documentation and/or other materials provided with the distribution.
18 1.8.6.2 yamt * 3. All advertising materials mentioning features or use of this software
19 1.8.6.2 yamt * must display the following acknowledgement:
20 1.8.6.2 yamt * This product includes software developed for the NetBSD Project by
21 1.8.6.2 yamt * Wasabi Systems, Inc.
22 1.8.6.2 yamt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 1.8.6.2 yamt * or promote products derived from this software without specific prior
24 1.8.6.2 yamt * written permission.
25 1.8.6.2 yamt *
26 1.8.6.2 yamt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 1.8.6.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.8.6.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.8.6.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 1.8.6.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.8.6.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.8.6.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.8.6.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.8.6.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.8.6.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.8.6.2 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.8.6.2 yamt */
38 1.8.6.2 yamt
39 1.8.6.2 yamt /*
40 1.8.6.2 yamt * Copyright (c) 1997,1998 Mark Brinicombe.
41 1.8.6.2 yamt * Copyright (c) 1997,1998 Causality Limited.
42 1.8.6.2 yamt * All rights reserved.
43 1.8.6.2 yamt *
44 1.8.6.2 yamt * Redistribution and use in source and binary forms, with or without
45 1.8.6.2 yamt * modification, are permitted provided that the following conditions
46 1.8.6.2 yamt * are met:
47 1.8.6.2 yamt * 1. Redistributions of source code must retain the above copyright
48 1.8.6.2 yamt * notice, this list of conditions and the following disclaimer.
49 1.8.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
50 1.8.6.2 yamt * notice, this list of conditions and the following disclaimer in the
51 1.8.6.2 yamt * documentation and/or other materials provided with the distribution.
52 1.8.6.2 yamt * 3. All advertising materials mentioning features or use of this software
53 1.8.6.2 yamt * must display the following acknowledgement:
54 1.8.6.2 yamt * This product includes software developed by Mark Brinicombe
55 1.8.6.2 yamt * for the NetBSD Project.
56 1.8.6.2 yamt * 4. The name of the company nor the name of the author may be used to
57 1.8.6.2 yamt * endorse or promote products derived from this software without specific
58 1.8.6.2 yamt * prior written permission.
59 1.8.6.2 yamt *
60 1.8.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
61 1.8.6.2 yamt * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62 1.8.6.2 yamt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 1.8.6.2 yamt * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64 1.8.6.2 yamt * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
65 1.8.6.2 yamt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66 1.8.6.2 yamt * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 1.8.6.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 1.8.6.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 1.8.6.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 1.8.6.2 yamt * SUCH DAMAGE.
71 1.8.6.2 yamt *
72 1.8.6.2 yamt * Machine dependant functions for kernel setup for Armadillo.
73 1.8.6.2 yamt */
74 1.8.6.2 yamt
75 1.8.6.2 yamt /* Armadillo-9 physical memory map
76 1.8.6.2 yamt 0000 0000 - 0fff ffff reserved
77 1.8.6.2 yamt 1000 0000 - 1000 000f I/O Control Register
78 1.8.6.2 yamt 1000 0010 - 11dd ffff reserved
79 1.8.6.2 yamt 1200 0000 - 1200 ffff PC/104 I/O space (8bit)
80 1.8.6.2 yamt 1201 0000 - 12ff ffff reserved
81 1.8.6.2 yamt 1300 0000 - 13ff ffff PC/104 Memory space (8bit)
82 1.8.6.2 yamt 1400 0000 - 1fff ffff reserved
83 1.8.6.2 yamt 2000 0000 - 21ff ffff reserved
84 1.8.6.2 yamt 2200 0000 - 2200 ffff PC/104 I/O space (16bit)
85 1.8.6.2 yamt 2201 0000 - 22ff ffff reserved
86 1.8.6.2 yamt 2300 0000 - 23ff ffff PC/104 Memory space (16bit)
87 1.8.6.2 yamt 2400 0000 - 2fff ffff reserved
88 1.8.6.2 yamt 3000 0000 - 3fff ffff reserved
89 1.8.6.2 yamt 4000 0000 - 43ff ffff Compact Flash I/O space
90 1.8.6.2 yamt 4400 0000 - 47ff ffff reserved
91 1.8.6.2 yamt 4800 0000 - 4bff ffff Compact Flash Attribute space
92 1.8.6.2 yamt 4c00 0000 - 4fff ffff Compact Flash memory space
93 1.8.6.2 yamt 5000 0000 - 5fff ffff reserved
94 1.8.6.2 yamt 6000 0000 - 607f ffff Flash Memory (8MByte)
95 1.8.6.2 yamt 6080 0000 - 6fff ffff reserved
96 1.8.6.2 yamt 7000 0000 - 7fff ffff reserved
97 1.8.6.2 yamt 8000 0000 - 8008 ffff EP9315 Internal Register (AHB)
98 1.8.6.2 yamt 8009 0000 - 8009 3fff Internal Boot ROM (16kByte)
99 1.8.6.2 yamt 8009 4000 - 8009 ffff reserved
100 1.8.6.2 yamt 800a 0000 - 800f ffff EP9315 Internal Register (AHB)
101 1.8.6.2 yamt 8010 0000 - 807f ffff reserved
102 1.8.6.2 yamt 8080 0000 - 8094 ffff EP9315 Internal Register (APB)
103 1.8.6.2 yamt 8095 0000 - 8fff ffff reserved
104 1.8.6.2 yamt 9000 0000 - bfff ffff reserved
105 1.8.6.2 yamt c000 0000 - c1ff ffff SDRAM (32MByte)
106 1.8.6.2 yamt c200 0000 - c3ff ffff reserved
107 1.8.6.2 yamt c400 0000 - c5ff ffff SDRAM (32MByte)
108 1.8.6.2 yamt c600 0000 - cfff ffff reserved
109 1.8.6.2 yamt d000 0000 - ffff ffff reserved
110 1.8.6.2 yamt */
111 1.8.6.2 yamt
112 1.8.6.2 yamt #include <sys/cdefs.h>
113 1.8.6.2 yamt __KERNEL_RCSID(0, "$NetBSD: armadillo9_machdep.c,v 1.8.6.2 2006/06/21 14:50:32 yamt Exp $");
114 1.8.6.2 yamt
115 1.8.6.2 yamt #include "opt_ddb.h"
116 1.8.6.2 yamt #include "opt_kgdb.h"
117 1.8.6.2 yamt #include "opt_pmap_debug.h"
118 1.8.6.2 yamt
119 1.8.6.2 yamt #include <sys/param.h>
120 1.8.6.2 yamt #include <sys/device.h>
121 1.8.6.2 yamt #include <sys/systm.h>
122 1.8.6.2 yamt #include <sys/kernel.h>
123 1.8.6.2 yamt #include <sys/exec.h>
124 1.8.6.2 yamt #include <sys/proc.h>
125 1.8.6.2 yamt #include <sys/msgbuf.h>
126 1.8.6.2 yamt #include <sys/reboot.h>
127 1.8.6.2 yamt #include <sys/termios.h>
128 1.8.6.2 yamt #include <sys/ksyms.h>
129 1.8.6.2 yamt
130 1.8.6.2 yamt #include <net/if.h>
131 1.8.6.2 yamt #include <net/if_ether.h>
132 1.8.6.2 yamt
133 1.8.6.2 yamt #include <uvm/uvm_extern.h>
134 1.8.6.2 yamt
135 1.8.6.2 yamt #include <dev/cons.h>
136 1.8.6.2 yamt
137 1.8.6.2 yamt #include <machine/db_machdep.h>
138 1.8.6.2 yamt #include <ddb/db_sym.h>
139 1.8.6.2 yamt #include <ddb/db_extern.h>
140 1.8.6.2 yamt
141 1.8.6.2 yamt #define DRAM_BLOCKS 4
142 1.8.6.2 yamt #include <machine/bootconfig.h>
143 1.8.6.2 yamt #include <machine/autoconf.h>
144 1.8.6.2 yamt #include <machine/bus.h>
145 1.8.6.2 yamt #include <machine/cpu.h>
146 1.8.6.2 yamt #include <machine/frame.h>
147 1.8.6.2 yamt #include <arm/undefined.h>
148 1.8.6.2 yamt
149 1.8.6.2 yamt #include <arm/arm32/machdep.h>
150 1.8.6.2 yamt
151 1.8.6.2 yamt #include <arm/ep93xx/ep93xxreg.h>
152 1.8.6.2 yamt #include <arm/ep93xx/ep93xxvar.h>
153 1.8.6.2 yamt
154 1.8.6.2 yamt #include "epwdog.h"
155 1.8.6.2 yamt #if NEPWDOG > 0
156 1.8.6.2 yamt #include <arm/ep93xx/epwdogvar.h>
157 1.8.6.2 yamt #endif
158 1.8.6.2 yamt #include <arm/ep93xx/epwdogreg.h>
159 1.8.6.2 yamt
160 1.8.6.2 yamt #include <dev/ic/comreg.h>
161 1.8.6.2 yamt #include <dev/ic/comvar.h>
162 1.8.6.2 yamt
163 1.8.6.2 yamt #include "epcom.h"
164 1.8.6.2 yamt #if NEPCOM > 0
165 1.8.6.2 yamt #include <arm/ep93xx/epcomvar.h>
166 1.8.6.2 yamt #endif
167 1.8.6.2 yamt
168 1.8.6.2 yamt #include "isa.h"
169 1.8.6.2 yamt #if NISA > 0
170 1.8.6.2 yamt #include <dev/isa/isareg.h>
171 1.8.6.2 yamt #include <dev/isa/isavar.h>
172 1.8.6.2 yamt #endif
173 1.8.6.2 yamt
174 1.8.6.2 yamt #include <machine/isa_machdep.h>
175 1.8.6.2 yamt
176 1.8.6.2 yamt #include <evbarm/armadillo/armadillo9reg.h>
177 1.8.6.2 yamt #include <evbarm/armadillo/armadillo9var.h>
178 1.8.6.2 yamt
179 1.8.6.2 yamt struct armadillo_model_t *armadillo_model = 0;
180 1.8.6.2 yamt static struct armadillo_model_t armadillo_model_table[] = {
181 1.8.6.2 yamt { DEVCFG_ARMADILLO9, "Armadillo-9" },
182 1.8.6.2 yamt { DEVCFG_ARMADILLO210, "Armadillo-210" },
183 1.8.6.2 yamt { 0, "Armadillo(unknown model)" } };
184 1.8.6.2 yamt
185 1.8.6.2 yamt #include "opt_ipkdb.h"
186 1.8.6.2 yamt #include "ksyms.h"
187 1.8.6.2 yamt
188 1.8.6.2 yamt /* Kernel text starts 2MB in from the bottom of the kernel address space. */
189 1.8.6.2 yamt #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
190 1.8.6.2 yamt #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
191 1.8.6.2 yamt
192 1.8.6.2 yamt /*
193 1.8.6.2 yamt * The range 0xc1000000 - 0xccffffff is available for kernel VM space
194 1.8.6.2 yamt * Core-logic registers and I/O mappings occupy 0xf0000000 - 0xffffffff
195 1.8.6.2 yamt */
196 1.8.6.2 yamt #define KERNEL_VM_SIZE 0x0c000000
197 1.8.6.2 yamt
198 1.8.6.2 yamt /*
199 1.8.6.2 yamt * Address to call from cpu_reset() to reset the machine.
200 1.8.6.2 yamt * This is machine architecture dependant as it varies depending
201 1.8.6.2 yamt * on where the ROM appears when you turn the MMU off.
202 1.8.6.2 yamt */
203 1.8.6.2 yamt
204 1.8.6.2 yamt u_int cpu_reset_address = 0x80090000;
205 1.8.6.2 yamt
206 1.8.6.2 yamt /* Define various stack sizes in pages */
207 1.8.6.2 yamt #define IRQ_STACK_SIZE 8
208 1.8.6.2 yamt #define ABT_STACK_SIZE 8
209 1.8.6.2 yamt #ifdef IPKDB
210 1.8.6.2 yamt #define UND_STACK_SIZE 16
211 1.8.6.2 yamt #else
212 1.8.6.2 yamt #define UND_STACK_SIZE 8
213 1.8.6.2 yamt #endif
214 1.8.6.2 yamt
215 1.8.6.2 yamt BootConfig bootconfig; /* Boot config storage */
216 1.8.6.2 yamt char *boot_args = NULL;
217 1.8.6.2 yamt char *boot_file = NULL;
218 1.8.6.2 yamt
219 1.8.6.2 yamt vm_offset_t physical_start;
220 1.8.6.2 yamt vm_offset_t physical_freestart;
221 1.8.6.2 yamt vm_offset_t physical_freeend;
222 1.8.6.2 yamt vm_offset_t physical_freeend_low;
223 1.8.6.2 yamt vm_offset_t physical_end;
224 1.8.6.2 yamt u_int free_pages;
225 1.8.6.2 yamt int physmem = 0;
226 1.8.6.2 yamt
227 1.8.6.2 yamt /* Physical and virtual addresses for some global pages */
228 1.8.6.2 yamt pv_addr_t systempage;
229 1.8.6.2 yamt pv_addr_t irqstack;
230 1.8.6.2 yamt pv_addr_t undstack;
231 1.8.6.2 yamt pv_addr_t abtstack;
232 1.8.6.2 yamt pv_addr_t kernelstack;
233 1.8.6.2 yamt
234 1.8.6.2 yamt vm_offset_t msgbufphys;
235 1.8.6.2 yamt
236 1.8.6.2 yamt static struct arm32_dma_range armadillo9_dma_ranges[4];
237 1.8.6.2 yamt
238 1.8.6.2 yamt #if NISA > 0
239 1.8.6.2 yamt extern void isa_armadillo9_init(u_int, u_int);
240 1.8.6.2 yamt #endif
241 1.8.6.2 yamt
242 1.8.6.2 yamt extern u_int data_abort_handler_address;
243 1.8.6.2 yamt extern u_int prefetch_abort_handler_address;
244 1.8.6.2 yamt extern u_int undefined_handler_address;
245 1.8.6.2 yamt
246 1.8.6.2 yamt #ifdef PMAP_DEBUG
247 1.8.6.2 yamt extern int pmap_debug_level;
248 1.8.6.2 yamt #endif
249 1.8.6.2 yamt
250 1.8.6.2 yamt #define KERNEL_PT_SYS 0 /* L2 table for mapping vectors page */
251 1.8.6.2 yamt
252 1.8.6.2 yamt #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
253 1.8.6.2 yamt #define KERNEL_PT_KERNEL_NUM 4
254 1.8.6.2 yamt /* L2 tables for mapping kernel VM */
255 1.8.6.2 yamt #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
256 1.8.6.2 yamt
257 1.8.6.2 yamt #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
258 1.8.6.2 yamt #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
259 1.8.6.2 yamt
260 1.8.6.2 yamt pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
261 1.8.6.2 yamt
262 1.8.6.2 yamt struct user *proc0paddr;
263 1.8.6.2 yamt
264 1.8.6.2 yamt /* Prototypes */
265 1.8.6.2 yamt
266 1.8.6.2 yamt void consinit(void);
267 1.8.6.2 yamt /*
268 1.8.6.2 yamt * Define the default console speed for the machine.
269 1.8.6.2 yamt */
270 1.8.6.2 yamt #if NEPCOM > 0
271 1.8.6.2 yamt #ifndef CONSPEED
272 1.8.6.2 yamt #define CONSPEED B115200
273 1.8.6.2 yamt #endif /* ! CONSPEED */
274 1.8.6.2 yamt
275 1.8.6.2 yamt #ifndef CONMODE
276 1.8.6.2 yamt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
277 1.8.6.2 yamt #endif
278 1.8.6.2 yamt
279 1.8.6.2 yamt #ifndef CONUNIT
280 1.8.6.2 yamt #define CONUNIT 0
281 1.8.6.2 yamt #endif
282 1.8.6.2 yamt
283 1.8.6.2 yamt int comcnspeed = CONSPEED;
284 1.8.6.2 yamt int comcnmode = CONMODE;
285 1.8.6.2 yamt const unsigned long comaddr[] = {
286 1.8.6.2 yamt EP93XX_APB_UART1, EP93XX_APB_UART2 };
287 1.8.6.2 yamt #endif
288 1.8.6.2 yamt
289 1.8.6.2 yamt #if KGDB
290 1.8.6.2 yamt #ifndef KGDB_DEVNAME
291 1.8.6.2 yamt #error Must define KGDB_DEVNAME
292 1.8.6.2 yamt #endif
293 1.8.6.2 yamt const char kgdb_devname[] = KGDB_DEVNAME;
294 1.8.6.2 yamt
295 1.8.6.2 yamt #ifndef KGDB_DEVADDR
296 1.8.6.2 yamt #error Must define KGDB_DEVADDR
297 1.8.6.2 yamt #endif
298 1.8.6.2 yamt unsigned long kgdb_devaddr = KGDB_DEVADDR;
299 1.8.6.2 yamt
300 1.8.6.2 yamt #ifndef KGDB_DEVRATE
301 1.8.6.2 yamt #define KGDB_DEVRATE CONSPEED
302 1.8.6.2 yamt #endif
303 1.8.6.2 yamt int kgdb_devrate = KGDB_DEVRATE;
304 1.8.6.2 yamt
305 1.8.6.2 yamt #ifndef KGDB_DEVMODE
306 1.8.6.2 yamt #define KGDB_DEVMODE CONMODE
307 1.8.6.2 yamt #endif
308 1.8.6.2 yamt int kgdb_devmode = KGDB_DEVMODE;
309 1.8.6.2 yamt #endif /* KGDB */
310 1.8.6.2 yamt
311 1.8.6.2 yamt /*
312 1.8.6.2 yamt * MAC address for the built-in Ethernet.
313 1.8.6.2 yamt */
314 1.8.6.2 yamt uint8_t armadillo9_ethaddr[ETHER_ADDR_LEN];
315 1.8.6.2 yamt
316 1.8.6.2 yamt static void
317 1.8.6.2 yamt armadillo9_device_register(device_t dev, void *aux)
318 1.8.6.2 yamt {
319 1.8.6.2 yamt
320 1.8.6.2 yamt /* MAC address for the built-in Ethernet. */
321 1.8.6.2 yamt if (device_is_a(dev, "epe")) {
322 1.8.6.2 yamt prop_data_t pd = prop_data_create_data_nocopy(
323 1.8.6.2 yamt armadillo9_ethaddr, ETHER_ADDR_LEN);
324 1.8.6.2 yamt KASSERT(pd != NULL);
325 1.8.6.2 yamt if (prop_dictionary_set(device_properties(dev),
326 1.8.6.2 yamt "mac-addr", pd) == FALSE) {
327 1.8.6.2 yamt printf("WARNING: unable to set mac-addr property "
328 1.8.6.2 yamt "for %s\n", dev->dv_xname);
329 1.8.6.2 yamt }
330 1.8.6.2 yamt prop_object_release(pd);
331 1.8.6.2 yamt }
332 1.8.6.2 yamt }
333 1.8.6.2 yamt
334 1.8.6.2 yamt /*
335 1.8.6.2 yamt * void cpu_reboot(int howto, char *bootstr)
336 1.8.6.2 yamt *
337 1.8.6.2 yamt * Reboots the system
338 1.8.6.2 yamt *
339 1.8.6.2 yamt * Deal with any syncing, unmounting, dumping and shutdown hooks,
340 1.8.6.2 yamt * then reset the CPU.
341 1.8.6.2 yamt */
342 1.8.6.2 yamt void
343 1.8.6.2 yamt cpu_reboot(int howto, char *bootstr)
344 1.8.6.2 yamt {
345 1.8.6.2 yamt /*
346 1.8.6.2 yamt * If we are still cold then hit the air brakes
347 1.8.6.2 yamt * and crash to earth fast
348 1.8.6.2 yamt */
349 1.8.6.2 yamt if (cold) {
350 1.8.6.2 yamt doshutdownhooks();
351 1.8.6.2 yamt printf("\r\n");
352 1.8.6.2 yamt printf("The operating system has halted.\r\n");
353 1.8.6.2 yamt printf("Please press any key to reboot.\r\n");
354 1.8.6.2 yamt cngetc();
355 1.8.6.2 yamt printf("\r\nrebooting...\r\n");
356 1.8.6.2 yamt goto reset;
357 1.8.6.2 yamt }
358 1.8.6.2 yamt
359 1.8.6.2 yamt /* Disable console buffering */
360 1.8.6.2 yamt
361 1.8.6.2 yamt /*
362 1.8.6.2 yamt * If RB_NOSYNC was not specified sync the discs.
363 1.8.6.2 yamt * Note: Unless cold is set to 1 here, syslogd will die during the
364 1.8.6.2 yamt * unmount. It looks like syslogd is getting woken up only to find
365 1.8.6.2 yamt * that it cannot page part of the binary in as the filesystem has
366 1.8.6.2 yamt * been unmounted.
367 1.8.6.2 yamt */
368 1.8.6.2 yamt if (!(howto & RB_NOSYNC))
369 1.8.6.2 yamt bootsync();
370 1.8.6.2 yamt
371 1.8.6.2 yamt /* Say NO to interrupts */
372 1.8.6.2 yamt splhigh();
373 1.8.6.2 yamt
374 1.8.6.2 yamt /* Do a dump if requested. */
375 1.8.6.2 yamt if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
376 1.8.6.2 yamt dumpsys();
377 1.8.6.2 yamt
378 1.8.6.2 yamt /* Run any shutdown hooks */
379 1.8.6.2 yamt doshutdownhooks();
380 1.8.6.2 yamt
381 1.8.6.2 yamt /* Make sure IRQ's are disabled */
382 1.8.6.2 yamt IRQdisable;
383 1.8.6.2 yamt
384 1.8.6.2 yamt if (howto & RB_HALT) {
385 1.8.6.2 yamt printf("\r\n");
386 1.8.6.2 yamt printf("The operating system has halted.\r\n");
387 1.8.6.2 yamt printf("Please press any key to reboot.\r\n");
388 1.8.6.2 yamt cngetc();
389 1.8.6.2 yamt }
390 1.8.6.2 yamt
391 1.8.6.2 yamt printf("\r\nrebooting...\r\n");
392 1.8.6.2 yamt reset:
393 1.8.6.2 yamt /*
394 1.8.6.2 yamt * Make really really sure that all interrupts are disabled,
395 1.8.6.2 yamt * and poke the Internal Bus and Peripheral Bus reset lines.
396 1.8.6.2 yamt */
397 1.8.6.2 yamt (void) disable_interrupts(I32_bit|F32_bit);
398 1.8.6.2 yamt #if NEPWDOG > 0
399 1.8.6.2 yamt epwdog_reset();
400 1.8.6.2 yamt #else
401 1.8.6.2 yamt {
402 1.8.6.2 yamt u_int32_t ctrl = EP93XX_APB_VBASE + EP93XX_APB_WDOG + EP93XX_WDOG_Ctrl;
403 1.8.6.2 yamt u_int32_t val = EP93XX_WDOG_ENABLE;
404 1.8.6.2 yamt __asm volatile (
405 1.8.6.2 yamt "str %1, [%0]\n"
406 1.8.6.2 yamt :
407 1.8.6.2 yamt : "r" (ctrl), "r" (val)
408 1.8.6.2 yamt );
409 1.8.6.2 yamt }
410 1.8.6.2 yamt #endif
411 1.8.6.2 yamt for (;;);
412 1.8.6.2 yamt }
413 1.8.6.2 yamt
414 1.8.6.2 yamt /* Static device mappings. */
415 1.8.6.2 yamt static const struct pmap_devmap armadillo9_devmap[] = {
416 1.8.6.2 yamt {
417 1.8.6.2 yamt EP93XX_AHB_VBASE,
418 1.8.6.2 yamt EP93XX_AHB_HWBASE,
419 1.8.6.2 yamt EP93XX_AHB_SIZE,
420 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
421 1.8.6.2 yamt PTE_NOCACHE,
422 1.8.6.2 yamt },
423 1.8.6.2 yamt
424 1.8.6.2 yamt {
425 1.8.6.2 yamt EP93XX_APB_VBASE,
426 1.8.6.2 yamt EP93XX_APB_HWBASE,
427 1.8.6.2 yamt EP93XX_APB_SIZE,
428 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
429 1.8.6.2 yamt PTE_NOCACHE,
430 1.8.6.2 yamt },
431 1.8.6.2 yamt
432 1.8.6.2 yamt {
433 1.8.6.2 yamt EP93XX_PCMCIA0_VBASE,
434 1.8.6.2 yamt EP93XX_PCMCIA0_HWBASE,
435 1.8.6.2 yamt EP93XX_PCMCIA_SIZE,
436 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
437 1.8.6.2 yamt PTE_NOCACHE,
438 1.8.6.2 yamt },
439 1.8.6.2 yamt
440 1.8.6.2 yamt /*
441 1.8.6.2 yamt * IO8 and IO16 space *must* be mapped contiguously with
442 1.8.6.2 yamt * IO8_VA == IO16_VA - 64 Mbytes. ISA busmap driver depends
443 1.8.6.2 yamt * on that!
444 1.8.6.2 yamt */
445 1.8.6.2 yamt {
446 1.8.6.2 yamt ARMADILLO9_IO8_VBASE,
447 1.8.6.2 yamt ARMADILLO9_IO8_HWBASE,
448 1.8.6.2 yamt ARMADILLO9_IO8_SIZE,
449 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
450 1.8.6.2 yamt PTE_NOCACHE,
451 1.8.6.2 yamt },
452 1.8.6.2 yamt
453 1.8.6.2 yamt {
454 1.8.6.2 yamt ARMADILLO9_IO16_VBASE,
455 1.8.6.2 yamt ARMADILLO9_IO16_HWBASE,
456 1.8.6.2 yamt ARMADILLO9_IO16_SIZE,
457 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
458 1.8.6.2 yamt PTE_NOCACHE,
459 1.8.6.2 yamt },
460 1.8.6.2 yamt
461 1.8.6.2 yamt {
462 1.8.6.2 yamt 0,
463 1.8.6.2 yamt 0,
464 1.8.6.2 yamt 0,
465 1.8.6.2 yamt 0,
466 1.8.6.2 yamt 0,
467 1.8.6.2 yamt }
468 1.8.6.2 yamt };
469 1.8.6.2 yamt
470 1.8.6.2 yamt /*
471 1.8.6.2 yamt * u_int initarm(...)
472 1.8.6.2 yamt *
473 1.8.6.2 yamt * Initial entry point on startup. This gets called before main() is
474 1.8.6.2 yamt * entered.
475 1.8.6.2 yamt * It should be responsible for setting up everything that must be
476 1.8.6.2 yamt * in place when main is called.
477 1.8.6.2 yamt * This includes
478 1.8.6.2 yamt * Taking a copy of the boot configuration structure.
479 1.8.6.2 yamt * Initialising the physical console so characters can be printed.
480 1.8.6.2 yamt * Setting up page tables for the kernel
481 1.8.6.2 yamt * Initialising interrupt controllers to a sane default state
482 1.8.6.2 yamt */
483 1.8.6.2 yamt u_int
484 1.8.6.2 yamt initarm(void *arg)
485 1.8.6.2 yamt {
486 1.8.6.2 yamt int loop;
487 1.8.6.2 yamt int loop1;
488 1.8.6.2 yamt u_int l1pagetable;
489 1.8.6.2 yamt pv_addr_t kernel_l1pt;
490 1.8.6.2 yamt struct bootparam_tag *bootparam_p;
491 1.8.6.2 yamt unsigned long devcfg;
492 1.8.6.2 yamt
493 1.8.6.2 yamt /*
494 1.8.6.2 yamt * Since we map the on-board devices VA==PA, and the kernel
495 1.8.6.2 yamt * is running VA==PA, it's possible for us to initialize
496 1.8.6.2 yamt * the console now.
497 1.8.6.2 yamt */
498 1.8.6.2 yamt consinit();
499 1.8.6.2 yamt
500 1.8.6.2 yamt /* identify model */
501 1.8.6.2 yamt devcfg = *((volatile unsigned long*)(EP93XX_APB_HWBASE
502 1.8.6.2 yamt + EP93XX_APB_SYSCON
503 1.8.6.2 yamt + EP93XX_SYSCON_DeviceCfg));
504 1.8.6.2 yamt for (armadillo_model = &armadillo_model_table[0];
505 1.8.6.2 yamt armadillo_model->devcfg; armadillo_model++)
506 1.8.6.2 yamt if (devcfg == armadillo_model->devcfg)
507 1.8.6.2 yamt break;
508 1.8.6.2 yamt
509 1.8.6.2 yamt /* Talk to the user */
510 1.8.6.2 yamt printf("\nNetBSD/%s booting ...\n", armadillo_model->name);
511 1.8.6.2 yamt
512 1.8.6.2 yamt /* set some informations from bootloader */
513 1.8.6.2 yamt bootparam_p = (struct bootparam_tag *)bootparam;
514 1.8.6.2 yamt bootconfig.dramblocks = 0;
515 1.8.6.2 yamt while (bootparam_p->hdr.tag != BOOTPARAM_TAG_NONE) {
516 1.8.6.2 yamt switch (bootparam_p->hdr.tag) {
517 1.8.6.2 yamt case BOOTPARAM_TAG_MEM:
518 1.8.6.2 yamt if (bootconfig.dramblocks < DRAM_BLOCKS) {
519 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
520 1.8.6.2 yamt printf("dram[%d]: address=0x%08lx, size=0x%08lx\n",
521 1.8.6.2 yamt bootconfig.dramblocks,
522 1.8.6.2 yamt bootparam_p->u.mem.start,
523 1.8.6.2 yamt bootparam_p->u.mem.size);
524 1.8.6.2 yamt #endif
525 1.8.6.2 yamt bootconfig.dram[bootconfig.dramblocks].address =
526 1.8.6.2 yamt bootparam_p->u.mem.start;
527 1.8.6.2 yamt bootconfig.dram[bootconfig.dramblocks].pages =
528 1.8.6.2 yamt bootparam_p->u.mem.size / PAGE_SIZE;
529 1.8.6.2 yamt bootconfig.dramblocks++;
530 1.8.6.2 yamt }
531 1.8.6.2 yamt break;
532 1.8.6.2 yamt case BOOTPARAM_TAG_CMDLINE:
533 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
534 1.8.6.2 yamt printf("cmdline: %s\n", bootparam_p->u.cmdline.cmdline);
535 1.8.6.2 yamt #endif
536 1.8.6.2 yamt parse_mi_bootargs(bootparam_p->u.cmdline.cmdline);
537 1.8.6.2 yamt break;
538 1.8.6.2 yamt }
539 1.8.6.2 yamt bootparam_p = bootparam_tag_next(bootparam_p);
540 1.8.6.2 yamt }
541 1.8.6.2 yamt
542 1.8.6.2 yamt /*
543 1.8.6.2 yamt * Heads up ... Setup the CPU / MMU / TLB functions
544 1.8.6.2 yamt */
545 1.8.6.2 yamt if (set_cpufuncs())
546 1.8.6.2 yamt panic("cpu not recognized!");
547 1.8.6.2 yamt
548 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
549 1.8.6.2 yamt printf("initarm: Configuring system ...\n");
550 1.8.6.2 yamt #endif
551 1.8.6.2 yamt /*
552 1.8.6.2 yamt * Set up the variables that define the availablilty of
553 1.8.6.2 yamt * physical memory. For now, we're going to set
554 1.8.6.2 yamt * physical_freestart to 0xc0200000 (where the kernel
555 1.8.6.2 yamt * was loaded), and allocate the memory we need downwards.
556 1.8.6.2 yamt * If we get too close to the L1 table that we set up, we
557 1.8.6.2 yamt * will panic. We will update physical_freestart and
558 1.8.6.2 yamt * physical_freeend later to reflect what pmap_bootstrap()
559 1.8.6.2 yamt * wants to see.
560 1.8.6.2 yamt *
561 1.8.6.2 yamt * XXX pmap_bootstrap() needs an enema.
562 1.8.6.2 yamt */
563 1.8.6.2 yamt physical_start = bootconfig.dram[0].address;
564 1.8.6.2 yamt physical_end = bootconfig.dram[0].address
565 1.8.6.2 yamt + (bootconfig.dram[0].pages * PAGE_SIZE);
566 1.8.6.2 yamt
567 1.8.6.2 yamt physical_freestart = 0xc0018000UL;
568 1.8.6.2 yamt physical_freeend = 0xc0200000UL;
569 1.8.6.2 yamt
570 1.8.6.2 yamt physmem = (physical_end - physical_start) / PAGE_SIZE;
571 1.8.6.2 yamt
572 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
573 1.8.6.2 yamt /* Tell the user about the memory */
574 1.8.6.2 yamt printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
575 1.8.6.2 yamt physical_start, physical_end - 1);
576 1.8.6.2 yamt #endif
577 1.8.6.2 yamt
578 1.8.6.2 yamt /*
579 1.8.6.2 yamt * Okay, the kernel starts 2MB in from the bottom of physical
580 1.8.6.2 yamt * memory. We are going to allocate our bootstrap pages downwards
581 1.8.6.2 yamt * from there.
582 1.8.6.2 yamt *
583 1.8.6.2 yamt * We need to allocate some fixed page tables to get the kernel
584 1.8.6.2 yamt * going. We allocate one page directory and a number of page
585 1.8.6.2 yamt * tables and store the physical addresses in the kernel_pt_table
586 1.8.6.2 yamt * array.
587 1.8.6.2 yamt *
588 1.8.6.2 yamt * The kernel page directory must be on a 16K boundary. The page
589 1.8.6.2 yamt * tables must be on 4K bounaries. What we do is allocate the
590 1.8.6.2 yamt * page directory on the first 16K boundary that we encounter, and
591 1.8.6.2 yamt * the page tables on 4K boundaries otherwise. Since we allocate
592 1.8.6.2 yamt * at least 3 L2 page tables, we are guaranteed to encounter at
593 1.8.6.2 yamt * least one 16K aligned region.
594 1.8.6.2 yamt */
595 1.8.6.2 yamt
596 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
597 1.8.6.2 yamt printf("Allocating page tables\n");
598 1.8.6.2 yamt #endif
599 1.8.6.2 yamt
600 1.8.6.2 yamt free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
601 1.8.6.2 yamt
602 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
603 1.8.6.2 yamt printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
604 1.8.6.2 yamt physical_freestart, free_pages, free_pages);
605 1.8.6.2 yamt #endif
606 1.8.6.2 yamt
607 1.8.6.2 yamt /* Define a macro to simplify memory allocation */
608 1.8.6.2 yamt #define valloc_pages(var, np) \
609 1.8.6.2 yamt alloc_pages((var).pv_pa, (np)); \
610 1.8.6.2 yamt (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
611 1.8.6.2 yamt
612 1.8.6.2 yamt #define alloc_pages(var, np) \
613 1.8.6.2 yamt physical_freeend -= ((np) * PAGE_SIZE); \
614 1.8.6.2 yamt if (physical_freeend < physical_freestart) \
615 1.8.6.2 yamt panic("initarm: out of memory"); \
616 1.8.6.2 yamt (var) = physical_freeend; \
617 1.8.6.2 yamt free_pages -= (np); \
618 1.8.6.2 yamt memset((char *)(var), 0, ((np) * PAGE_SIZE));
619 1.8.6.2 yamt
620 1.8.6.2 yamt loop1 = 0;
621 1.8.6.2 yamt kernel_l1pt.pv_pa = 0;
622 1.8.6.2 yamt kernel_l1pt.pv_va = 0;
623 1.8.6.2 yamt for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
624 1.8.6.2 yamt /* Are we 16KB aligned for an L1 ? */
625 1.8.6.2 yamt if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
626 1.8.6.2 yamt && kernel_l1pt.pv_pa == 0) {
627 1.8.6.2 yamt valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
628 1.8.6.2 yamt } else {
629 1.8.6.2 yamt valloc_pages(kernel_pt_table[loop1],
630 1.8.6.2 yamt L2_TABLE_SIZE / PAGE_SIZE);
631 1.8.6.2 yamt ++loop1;
632 1.8.6.2 yamt }
633 1.8.6.2 yamt }
634 1.8.6.2 yamt
635 1.8.6.2 yamt /* This should never be able to happen but better confirm that. */
636 1.8.6.2 yamt if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
637 1.8.6.2 yamt panic("initarm: Failed to align the kernel page directory");
638 1.8.6.2 yamt
639 1.8.6.2 yamt /*
640 1.8.6.2 yamt * Allocate a page for the system vectors page
641 1.8.6.2 yamt */
642 1.8.6.2 yamt alloc_pages(systempage.pv_pa, 1);
643 1.8.6.2 yamt
644 1.8.6.2 yamt /* Allocate stacks for all modes */
645 1.8.6.2 yamt valloc_pages(irqstack, IRQ_STACK_SIZE);
646 1.8.6.2 yamt valloc_pages(abtstack, ABT_STACK_SIZE);
647 1.8.6.2 yamt valloc_pages(undstack, UND_STACK_SIZE);
648 1.8.6.2 yamt valloc_pages(kernelstack, UPAGES);
649 1.8.6.2 yamt
650 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
651 1.8.6.2 yamt printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
652 1.8.6.2 yamt irqstack.pv_va);
653 1.8.6.2 yamt printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
654 1.8.6.2 yamt abtstack.pv_va);
655 1.8.6.2 yamt printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
656 1.8.6.2 yamt undstack.pv_va);
657 1.8.6.2 yamt printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
658 1.8.6.2 yamt kernelstack.pv_va);
659 1.8.6.2 yamt #endif
660 1.8.6.2 yamt
661 1.8.6.2 yamt alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
662 1.8.6.2 yamt
663 1.8.6.2 yamt /*
664 1.8.6.2 yamt * Ok we have allocated physical pages for the primary kernel
665 1.8.6.2 yamt * page tables. Save physical_freeend for when we give whats left
666 1.8.6.2 yamt * of memory below 2Mbyte to UVM.
667 1.8.6.2 yamt */
668 1.8.6.2 yamt
669 1.8.6.2 yamt physical_freeend_low = physical_freeend;
670 1.8.6.2 yamt
671 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
672 1.8.6.2 yamt printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
673 1.8.6.2 yamt #endif
674 1.8.6.2 yamt
675 1.8.6.2 yamt /*
676 1.8.6.2 yamt * Now we start construction of the L1 page table
677 1.8.6.2 yamt * We start by mapping the L2 page tables into the L1.
678 1.8.6.2 yamt * This means that we can replace L1 mappings later on if necessary
679 1.8.6.2 yamt */
680 1.8.6.2 yamt l1pagetable = kernel_l1pt.pv_pa;
681 1.8.6.2 yamt
682 1.8.6.2 yamt /* Map the L2 pages tables in the L1 page table */
683 1.8.6.2 yamt pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
684 1.8.6.2 yamt &kernel_pt_table[KERNEL_PT_SYS]);
685 1.8.6.2 yamt for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
686 1.8.6.2 yamt pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
687 1.8.6.2 yamt &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
688 1.8.6.2 yamt for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
689 1.8.6.2 yamt pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
690 1.8.6.2 yamt &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
691 1.8.6.2 yamt
692 1.8.6.2 yamt /* update the top of the kernel VM */
693 1.8.6.2 yamt pmap_curmaxkvaddr =
694 1.8.6.2 yamt KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
695 1.8.6.2 yamt
696 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
697 1.8.6.2 yamt printf("Mapping kernel\n");
698 1.8.6.2 yamt #endif
699 1.8.6.2 yamt
700 1.8.6.2 yamt /* Now we fill in the L2 pagetable for the kernel static code/data */
701 1.8.6.2 yamt {
702 1.8.6.2 yamt extern char etext[], _end[];
703 1.8.6.2 yamt size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
704 1.8.6.2 yamt size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
705 1.8.6.2 yamt u_int logical;
706 1.8.6.2 yamt
707 1.8.6.2 yamt textsize = (textsize + PGOFSET) & ~PGOFSET;
708 1.8.6.2 yamt totalsize = (totalsize + PGOFSET) & ~PGOFSET;
709 1.8.6.2 yamt
710 1.8.6.2 yamt logical = 0x00200000; /* offset of kernel in RAM */
711 1.8.6.2 yamt logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
712 1.8.6.2 yamt physical_start + logical, textsize,
713 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
714 1.8.6.2 yamt logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
715 1.8.6.2 yamt physical_start + logical, totalsize - textsize,
716 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
717 1.8.6.2 yamt }
718 1.8.6.2 yamt
719 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
720 1.8.6.2 yamt printf("Constructing L2 page tables\n");
721 1.8.6.2 yamt #endif
722 1.8.6.2 yamt
723 1.8.6.2 yamt /* Map the stack pages */
724 1.8.6.2 yamt pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
725 1.8.6.2 yamt IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
726 1.8.6.2 yamt pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
727 1.8.6.2 yamt ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
728 1.8.6.2 yamt pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
729 1.8.6.2 yamt UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
730 1.8.6.2 yamt pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
731 1.8.6.2 yamt UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
732 1.8.6.2 yamt
733 1.8.6.2 yamt pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
734 1.8.6.2 yamt L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
735 1.8.6.2 yamt
736 1.8.6.2 yamt for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
737 1.8.6.2 yamt pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
738 1.8.6.2 yamt kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
739 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
740 1.8.6.2 yamt }
741 1.8.6.2 yamt
742 1.8.6.2 yamt /* Map the vector page. */
743 1.8.6.2 yamt pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
744 1.8.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
745 1.8.6.2 yamt
746 1.8.6.2 yamt /* Map the statically mapped devices. */
747 1.8.6.2 yamt pmap_devmap_bootstrap(l1pagetable, armadillo9_devmap);
748 1.8.6.2 yamt
749 1.8.6.2 yamt /*
750 1.8.6.2 yamt * Update the physical_freestart/physical_freeend/free_pages
751 1.8.6.2 yamt * variables.
752 1.8.6.2 yamt */
753 1.8.6.2 yamt {
754 1.8.6.2 yamt extern char _end[];
755 1.8.6.2 yamt
756 1.8.6.2 yamt physical_freestart = physical_start +
757 1.8.6.2 yamt (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
758 1.8.6.2 yamt KERNEL_BASE);
759 1.8.6.2 yamt physical_freeend = physical_end;
760 1.8.6.2 yamt free_pages =
761 1.8.6.2 yamt (physical_freeend - physical_freestart) / PAGE_SIZE;
762 1.8.6.2 yamt }
763 1.8.6.2 yamt
764 1.8.6.2 yamt /*
765 1.8.6.2 yamt * Now we have the real page tables in place so we can switch to them.
766 1.8.6.2 yamt * Once this is done we will be running with the REAL kernel page
767 1.8.6.2 yamt * tables.
768 1.8.6.2 yamt */
769 1.8.6.2 yamt
770 1.8.6.2 yamt /* Switch tables */
771 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
772 1.8.6.2 yamt printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
773 1.8.6.2 yamt physical_freestart, free_pages, free_pages);
774 1.8.6.2 yamt printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
775 1.8.6.2 yamt #endif
776 1.8.6.2 yamt cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
777 1.8.6.2 yamt setttb(kernel_l1pt.pv_pa);
778 1.8.6.2 yamt cpu_tlb_flushID();
779 1.8.6.2 yamt cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
780 1.8.6.2 yamt
781 1.8.6.2 yamt /*
782 1.8.6.2 yamt * Moved from cpu_startup() as data_abort_handler() references
783 1.8.6.2 yamt * this during uvm init
784 1.8.6.2 yamt */
785 1.8.6.2 yamt proc0paddr = (struct user *)kernelstack.pv_va;
786 1.8.6.2 yamt lwp0.l_addr = proc0paddr;
787 1.8.6.2 yamt
788 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
789 1.8.6.2 yamt printf("done!\n");
790 1.8.6.2 yamt #endif
791 1.8.6.2 yamt
792 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
793 1.8.6.2 yamt printf("bootstrap done.\n");
794 1.8.6.2 yamt #endif
795 1.8.6.2 yamt
796 1.8.6.2 yamt arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
797 1.8.6.2 yamt
798 1.8.6.2 yamt /*
799 1.8.6.2 yamt * Pages were allocated during the secondary bootstrap for the
800 1.8.6.2 yamt * stacks for different CPU modes.
801 1.8.6.2 yamt * We must now set the r13 registers in the different CPU modes to
802 1.8.6.2 yamt * point to these stacks.
803 1.8.6.2 yamt * Since the ARM stacks use STMFD etc. we must set r13 to the top end
804 1.8.6.2 yamt * of the stack memory.
805 1.8.6.2 yamt */
806 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
807 1.8.6.2 yamt printf("init subsystems: stacks ");
808 1.8.6.2 yamt #endif
809 1.8.6.2 yamt
810 1.8.6.2 yamt set_stackptr(PSR_IRQ32_MODE,
811 1.8.6.2 yamt irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
812 1.8.6.2 yamt set_stackptr(PSR_ABT32_MODE,
813 1.8.6.2 yamt abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
814 1.8.6.2 yamt set_stackptr(PSR_UND32_MODE,
815 1.8.6.2 yamt undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
816 1.8.6.2 yamt
817 1.8.6.2 yamt /*
818 1.8.6.2 yamt * Well we should set a data abort handler.
819 1.8.6.2 yamt * Once things get going this will change as we will need a proper
820 1.8.6.2 yamt * handler.
821 1.8.6.2 yamt * Until then we will use a handler that just panics but tells us
822 1.8.6.2 yamt * why.
823 1.8.6.2 yamt * Initialisation of the vectors will just panic on a data abort.
824 1.8.6.2 yamt * This just fills in a slightly better one.
825 1.8.6.2 yamt */
826 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
827 1.8.6.2 yamt printf("vectors ");
828 1.8.6.2 yamt #endif
829 1.8.6.2 yamt data_abort_handler_address = (u_int)data_abort_handler;
830 1.8.6.2 yamt prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
831 1.8.6.2 yamt undefined_handler_address = (u_int)undefinedinstruction_bounce;
832 1.8.6.2 yamt
833 1.8.6.2 yamt /* Initialise the undefined instruction handlers */
834 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
835 1.8.6.2 yamt printf("undefined ");
836 1.8.6.2 yamt #endif
837 1.8.6.2 yamt undefined_init();
838 1.8.6.2 yamt
839 1.8.6.2 yamt /* Load memory into UVM. */
840 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
841 1.8.6.2 yamt printf("page ");
842 1.8.6.2 yamt #endif
843 1.8.6.2 yamt uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
844 1.8.6.2 yamt uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
845 1.8.6.2 yamt atop(physical_freestart), atop(physical_freeend),
846 1.8.6.2 yamt VM_FREELIST_DEFAULT);
847 1.8.6.2 yamt uvm_page_physload(atop(0xc0000000), atop(physical_freeend_low),
848 1.8.6.2 yamt atop(0xc0000000), atop(physical_freeend_low),
849 1.8.6.2 yamt VM_FREELIST_DEFAULT);
850 1.8.6.2 yamt physmem = bootconfig.dram[0].pages;
851 1.8.6.2 yamt for (loop = 1; loop < bootconfig.dramblocks; ++loop) {
852 1.8.6.2 yamt size_t start = bootconfig.dram[loop].address;
853 1.8.6.2 yamt size_t size = bootconfig.dram[loop].pages * PAGE_SIZE;
854 1.8.6.2 yamt uvm_page_physload(atop(start), atop(start + size),
855 1.8.6.2 yamt atop(start), atop(start + size),
856 1.8.6.2 yamt VM_FREELIST_DEFAULT);
857 1.8.6.2 yamt physmem += bootconfig.dram[loop].pages;
858 1.8.6.2 yamt }
859 1.8.6.2 yamt
860 1.8.6.2 yamt /* Boot strap pmap telling it where the kernel page table is */
861 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
862 1.8.6.2 yamt printf("pmap ");
863 1.8.6.2 yamt #endif
864 1.8.6.2 yamt pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
865 1.8.6.2 yamt KERNEL_VM_BASE + KERNEL_VM_SIZE);
866 1.8.6.2 yamt
867 1.8.6.2 yamt /* Setup the IRQ system */
868 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
869 1.8.6.2 yamt printf("irq ");
870 1.8.6.2 yamt #endif
871 1.8.6.2 yamt ep93xx_intr_init();
872 1.8.6.2 yamt #if NISA > 0
873 1.8.6.2 yamt isa_intr_init();
874 1.8.6.2 yamt
875 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
876 1.8.6.2 yamt printf("isa ");
877 1.8.6.2 yamt #endif
878 1.8.6.2 yamt isa_armadillo9_init(ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAIO,
879 1.8.6.2 yamt ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAMEM);
880 1.8.6.2 yamt #endif
881 1.8.6.2 yamt
882 1.8.6.2 yamt #ifdef VERBOSE_INIT_ARM
883 1.8.6.2 yamt printf("done.\n");
884 1.8.6.2 yamt #endif
885 1.8.6.2 yamt
886 1.8.6.2 yamt #ifdef BOOTHOWTO
887 1.8.6.2 yamt boothowto = BOOTHOWTO;
888 1.8.6.2 yamt #endif
889 1.8.6.2 yamt
890 1.8.6.2 yamt #ifdef IPKDB
891 1.8.6.2 yamt /* Initialise ipkdb */
892 1.8.6.2 yamt ipkdb_init();
893 1.8.6.2 yamt if (boothowto & RB_KDB)
894 1.8.6.2 yamt ipkdb_connect(0);
895 1.8.6.2 yamt #endif
896 1.8.6.2 yamt
897 1.8.6.2 yamt #if NKSYMS || defined(DDB) || defined(LKM)
898 1.8.6.2 yamt /* Firmware doesn't load symbols. */
899 1.8.6.2 yamt ksyms_init(0, NULL, NULL);
900 1.8.6.2 yamt #endif
901 1.8.6.2 yamt
902 1.8.6.2 yamt #ifdef DDB
903 1.8.6.2 yamt db_machine_init();
904 1.8.6.2 yamt if (boothowto & RB_KDB)
905 1.8.6.2 yamt Debugger();
906 1.8.6.2 yamt #endif
907 1.8.6.2 yamt
908 1.8.6.2 yamt /* We have our own device_register() */
909 1.8.6.2 yamt evbarm_device_register = armadillo9_device_register;
910 1.8.6.2 yamt
911 1.8.6.2 yamt /* We return the new stack pointer address */
912 1.8.6.2 yamt return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
913 1.8.6.2 yamt }
914 1.8.6.2 yamt
915 1.8.6.2 yamt void
916 1.8.6.2 yamt consinit(void)
917 1.8.6.2 yamt {
918 1.8.6.2 yamt static int consinit_called;
919 1.8.6.2 yamt #if NEPCOM > 0
920 1.8.6.2 yamt bus_space_handle_t ioh;
921 1.8.6.2 yamt #endif
922 1.8.6.2 yamt
923 1.8.6.2 yamt if (consinit_called != 0)
924 1.8.6.2 yamt return;
925 1.8.6.2 yamt
926 1.8.6.2 yamt consinit_called = 1;
927 1.8.6.2 yamt
928 1.8.6.2 yamt /*
929 1.8.6.2 yamt * Console devices are already mapped in VA. Our devmap reflects
930 1.8.6.2 yamt * this, so register it now so drivers can map the console
931 1.8.6.2 yamt * device.
932 1.8.6.2 yamt */
933 1.8.6.2 yamt pmap_devmap_register(armadillo9_devmap);
934 1.8.6.2 yamt
935 1.8.6.2 yamt #if NEPCOM > 0
936 1.8.6.2 yamt bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + comaddr[CONUNIT],
937 1.8.6.2 yamt EP93XX_APB_UART_SIZE, 0, &ioh);
938 1.8.6.2 yamt if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + comaddr[CONUNIT],
939 1.8.6.2 yamt ioh, comcnspeed, comcnmode))
940 1.8.6.2 yamt {
941 1.8.6.2 yamt panic("can't init serial console");
942 1.8.6.2 yamt }
943 1.8.6.2 yamt #else
944 1.8.6.2 yamt panic("serial console not configured");
945 1.8.6.2 yamt #endif
946 1.8.6.2 yamt #if KGDB
947 1.8.6.2 yamt #if NEPCOM > 0
948 1.8.6.2 yamt if (strcmp(kgdb_devname, "epcom") == 0) {
949 1.8.6.2 yamt com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
950 1.8.6.2 yamt kgdb_devmode);
951 1.8.6.2 yamt }
952 1.8.6.2 yamt #endif /* NEPCOM > 0 */
953 1.8.6.2 yamt #endif /* KGDB */
954 1.8.6.2 yamt }
955 1.8.6.2 yamt
956 1.8.6.2 yamt
957 1.8.6.2 yamt bus_dma_tag_t
958 1.8.6.2 yamt ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
959 1.8.6.2 yamt {
960 1.8.6.2 yamt int i;
961 1.8.6.2 yamt struct arm32_bus_dma_tag *dmat;
962 1.8.6.2 yamt
963 1.8.6.2 yamt for (i = 0; i < bootconfig.dramblocks; i++) {
964 1.8.6.2 yamt armadillo9_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
965 1.8.6.2 yamt armadillo9_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
966 1.8.6.2 yamt armadillo9_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
967 1.8.6.2 yamt PAGE_SIZE;
968 1.8.6.2 yamt }
969 1.8.6.2 yamt
970 1.8.6.2 yamt dmat = dma_tag_template;
971 1.8.6.2 yamt
972 1.8.6.2 yamt dmat->_ranges = armadillo9_dma_ranges;
973 1.8.6.2 yamt dmat->_nranges = bootconfig.dramblocks;
974 1.8.6.2 yamt
975 1.8.6.2 yamt return dmat;
976 1.8.6.2 yamt }
977