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