iq80310_machdep.c revision 1.20.2.4 1 1.20.2.4 jdolecek /* $NetBSD: iq80310_machdep.c,v 1.20.2.4 2002/06/23 17:35:42 jdolecek Exp $ */
2 1.20.2.2 jdolecek
3 1.20.2.2 jdolecek /*
4 1.20.2.2 jdolecek * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 1.20.2.2 jdolecek * All rights reserved.
6 1.20.2.2 jdolecek *
7 1.20.2.2 jdolecek * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.20.2.2 jdolecek *
9 1.20.2.2 jdolecek * Redistribution and use in source and binary forms, with or without
10 1.20.2.2 jdolecek * modification, are permitted provided that the following conditions
11 1.20.2.2 jdolecek * are met:
12 1.20.2.2 jdolecek * 1. Redistributions of source code must retain the above copyright
13 1.20.2.2 jdolecek * notice, this list of conditions and the following disclaimer.
14 1.20.2.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
15 1.20.2.2 jdolecek * notice, this list of conditions and the following disclaimer in the
16 1.20.2.2 jdolecek * documentation and/or other materials provided with the distribution.
17 1.20.2.2 jdolecek * 3. All advertising materials mentioning features or use of this software
18 1.20.2.2 jdolecek * must display the following acknowledgement:
19 1.20.2.2 jdolecek * This product includes software developed for the NetBSD Project by
20 1.20.2.2 jdolecek * Wasabi Systems, Inc.
21 1.20.2.2 jdolecek * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.20.2.2 jdolecek * or promote products derived from this software without specific prior
23 1.20.2.2 jdolecek * written permission.
24 1.20.2.2 jdolecek *
25 1.20.2.2 jdolecek * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.20.2.2 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.20.2.2 jdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.20.2.2 jdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.20.2.2 jdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.20.2.2 jdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.20.2.2 jdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.20.2.2 jdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.20.2.2 jdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.20.2.2 jdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.20.2.2 jdolecek * POSSIBILITY OF SUCH DAMAGE.
36 1.20.2.2 jdolecek */
37 1.20.2.2 jdolecek
38 1.20.2.2 jdolecek /*
39 1.20.2.2 jdolecek * Copyright (c) 1997,1998 Mark Brinicombe.
40 1.20.2.2 jdolecek * Copyright (c) 1997,1998 Causality Limited.
41 1.20.2.2 jdolecek * All rights reserved.
42 1.20.2.2 jdolecek *
43 1.20.2.2 jdolecek * Redistribution and use in source and binary forms, with or without
44 1.20.2.2 jdolecek * modification, are permitted provided that the following conditions
45 1.20.2.2 jdolecek * are met:
46 1.20.2.2 jdolecek * 1. Redistributions of source code must retain the above copyright
47 1.20.2.2 jdolecek * notice, this list of conditions and the following disclaimer.
48 1.20.2.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
49 1.20.2.2 jdolecek * notice, this list of conditions and the following disclaimer in the
50 1.20.2.2 jdolecek * documentation and/or other materials provided with the distribution.
51 1.20.2.2 jdolecek * 3. All advertising materials mentioning features or use of this software
52 1.20.2.2 jdolecek * must display the following acknowledgement:
53 1.20.2.2 jdolecek * This product includes software developed by Mark Brinicombe
54 1.20.2.2 jdolecek * for the NetBSD Project.
55 1.20.2.2 jdolecek * 4. The name of the company nor the name of the author may be used to
56 1.20.2.2 jdolecek * endorse or promote products derived from this software without specific
57 1.20.2.2 jdolecek * prior written permission.
58 1.20.2.2 jdolecek *
59 1.20.2.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 1.20.2.2 jdolecek * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 1.20.2.2 jdolecek * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 1.20.2.2 jdolecek * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63 1.20.2.2 jdolecek * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 1.20.2.2 jdolecek * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 1.20.2.2 jdolecek * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.20.2.2 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.20.2.2 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.20.2.2 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.20.2.2 jdolecek * SUCH DAMAGE.
70 1.20.2.2 jdolecek *
71 1.20.2.2 jdolecek * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
72 1.20.2.2 jdolecek * boards using RedBoot firmware.
73 1.20.2.2 jdolecek */
74 1.20.2.2 jdolecek
75 1.20.2.2 jdolecek #include "opt_ddb.h"
76 1.20.2.2 jdolecek #include "opt_pmap_debug.h"
77 1.20.2.2 jdolecek
78 1.20.2.2 jdolecek #include <sys/param.h>
79 1.20.2.2 jdolecek #include <sys/device.h>
80 1.20.2.2 jdolecek #include <sys/systm.h>
81 1.20.2.2 jdolecek #include <sys/kernel.h>
82 1.20.2.2 jdolecek #include <sys/exec.h>
83 1.20.2.2 jdolecek #include <sys/proc.h>
84 1.20.2.2 jdolecek #include <sys/msgbuf.h>
85 1.20.2.2 jdolecek #include <sys/reboot.h>
86 1.20.2.2 jdolecek #include <sys/termios.h>
87 1.20.2.2 jdolecek
88 1.20.2.2 jdolecek #include <dev/cons.h>
89 1.20.2.2 jdolecek
90 1.20.2.2 jdolecek #include <machine/db_machdep.h>
91 1.20.2.2 jdolecek #include <ddb/db_sym.h>
92 1.20.2.2 jdolecek #include <ddb/db_extern.h>
93 1.20.2.2 jdolecek
94 1.20.2.2 jdolecek #include <machine/bootconfig.h>
95 1.20.2.2 jdolecek #include <machine/bus.h>
96 1.20.2.2 jdolecek #include <machine/cpu.h>
97 1.20.2.2 jdolecek #include <machine/frame.h>
98 1.20.2.2 jdolecek #include <arm/undefined.h>
99 1.20.2.2 jdolecek
100 1.20.2.2 jdolecek #include <arm/arm32/machdep.h>
101 1.20.2.2 jdolecek
102 1.20.2.2 jdolecek #include <arm/xscale/i80312reg.h>
103 1.20.2.2 jdolecek #include <arm/xscale/i80312var.h>
104 1.20.2.2 jdolecek
105 1.20.2.2 jdolecek #include <dev/pci/ppbreg.h>
106 1.20.2.2 jdolecek
107 1.20.2.2 jdolecek #include <evbarm/iq80310/iq80310reg.h>
108 1.20.2.2 jdolecek #include <evbarm/iq80310/iq80310var.h>
109 1.20.2.2 jdolecek #include <evbarm/iq80310/obiovar.h>
110 1.20.2.2 jdolecek
111 1.20.2.2 jdolecek #include "opt_ipkdb.h"
112 1.20.2.2 jdolecek
113 1.20.2.2 jdolecek /*
114 1.20.2.2 jdolecek * Address to call from cpu_reset() to reset the machine.
115 1.20.2.2 jdolecek * This is machine architecture dependant as it varies depending
116 1.20.2.2 jdolecek * on where the ROM appears when you turn the MMU off.
117 1.20.2.2 jdolecek */
118 1.20.2.2 jdolecek
119 1.20.2.2 jdolecek u_int cpu_reset_address = 0;
120 1.20.2.2 jdolecek
121 1.20.2.2 jdolecek /* Define various stack sizes in pages */
122 1.20.2.2 jdolecek #define IRQ_STACK_SIZE 1
123 1.20.2.2 jdolecek #define ABT_STACK_SIZE 1
124 1.20.2.2 jdolecek #ifdef IPKDB
125 1.20.2.2 jdolecek #define UND_STACK_SIZE 2
126 1.20.2.2 jdolecek #else
127 1.20.2.2 jdolecek #define UND_STACK_SIZE 1
128 1.20.2.2 jdolecek #endif
129 1.20.2.2 jdolecek
130 1.20.2.2 jdolecek BootConfig bootconfig; /* Boot config storage */
131 1.20.2.2 jdolecek char *boot_args = NULL;
132 1.20.2.2 jdolecek char *boot_file = NULL;
133 1.20.2.2 jdolecek
134 1.20.2.2 jdolecek vm_offset_t physical_start;
135 1.20.2.2 jdolecek vm_offset_t physical_freestart;
136 1.20.2.2 jdolecek vm_offset_t physical_freeend;
137 1.20.2.2 jdolecek vm_offset_t physical_end;
138 1.20.2.2 jdolecek u_int free_pages;
139 1.20.2.2 jdolecek vm_offset_t pagetables_start;
140 1.20.2.2 jdolecek int physmem = 0;
141 1.20.2.2 jdolecek
142 1.20.2.2 jdolecek /*int debug_flags;*/
143 1.20.2.2 jdolecek #ifndef PMAP_STATIC_L1S
144 1.20.2.2 jdolecek int max_processes = 64; /* Default number */
145 1.20.2.2 jdolecek #endif /* !PMAP_STATIC_L1S */
146 1.20.2.2 jdolecek
147 1.20.2.2 jdolecek /* Physical and virtual addresses for some global pages */
148 1.20.2.2 jdolecek pv_addr_t systempage;
149 1.20.2.2 jdolecek pv_addr_t irqstack;
150 1.20.2.2 jdolecek pv_addr_t undstack;
151 1.20.2.2 jdolecek pv_addr_t abtstack;
152 1.20.2.2 jdolecek pv_addr_t kernelstack;
153 1.20.2.2 jdolecek pv_addr_t minidataclean;
154 1.20.2.2 jdolecek
155 1.20.2.2 jdolecek vm_offset_t msgbufphys;
156 1.20.2.2 jdolecek
157 1.20.2.2 jdolecek extern u_int data_abort_handler_address;
158 1.20.2.2 jdolecek extern u_int prefetch_abort_handler_address;
159 1.20.2.2 jdolecek extern u_int undefined_handler_address;
160 1.20.2.2 jdolecek
161 1.20.2.2 jdolecek #ifdef PMAP_DEBUG
162 1.20.2.2 jdolecek extern int pmap_debug_level;
163 1.20.2.2 jdolecek #endif
164 1.20.2.2 jdolecek
165 1.20.2.3 jdolecek #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
166 1.20.2.3 jdolecek
167 1.20.2.3 jdolecek #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
168 1.20.2.3 jdolecek #define KERNEL_PT_KERNEL_NUM 2
169 1.20.2.3 jdolecek
170 1.20.2.3 jdolecek /* L2 table for mapping i80312 */
171 1.20.2.3 jdolecek #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
172 1.20.2.3 jdolecek
173 1.20.2.3 jdolecek /* L2 tables for mapping kernel VM */
174 1.20.2.3 jdolecek #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
175 1.20.2.3 jdolecek #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
176 1.20.2.2 jdolecek #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
177 1.20.2.2 jdolecek
178 1.20.2.3 jdolecek pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
179 1.20.2.2 jdolecek
180 1.20.2.2 jdolecek struct user *proc0paddr;
181 1.20.2.2 jdolecek
182 1.20.2.2 jdolecek /* Prototypes */
183 1.20.2.2 jdolecek
184 1.20.2.2 jdolecek void consinit(void);
185 1.20.2.2 jdolecek
186 1.20.2.2 jdolecek #include "com.h"
187 1.20.2.2 jdolecek #if NCOM > 0
188 1.20.2.2 jdolecek #include <dev/ic/comreg.h>
189 1.20.2.2 jdolecek #include <dev/ic/comvar.h>
190 1.20.2.2 jdolecek #endif
191 1.20.2.2 jdolecek
192 1.20.2.3 jdolecek /*
193 1.20.2.3 jdolecek * Define the default console speed for the board. This is generally
194 1.20.2.3 jdolecek * what the firmware provided with the board defaults to.
195 1.20.2.3 jdolecek */
196 1.20.2.2 jdolecek #ifndef CONSPEED
197 1.20.2.3 jdolecek #define CONSPEED B115200
198 1.20.2.3 jdolecek #endif /* ! CONSPEED */
199 1.20.2.3 jdolecek
200 1.20.2.3 jdolecek #ifndef CONUNIT
201 1.20.2.3 jdolecek #define CONUNIT 0
202 1.20.2.2 jdolecek #endif
203 1.20.2.3 jdolecek
204 1.20.2.2 jdolecek #ifndef CONMODE
205 1.20.2.2 jdolecek #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
206 1.20.2.2 jdolecek #endif
207 1.20.2.2 jdolecek
208 1.20.2.2 jdolecek int comcnspeed = CONSPEED;
209 1.20.2.2 jdolecek int comcnmode = CONMODE;
210 1.20.2.2 jdolecek int comcnunit = CONUNIT;
211 1.20.2.2 jdolecek
212 1.20.2.2 jdolecek /*
213 1.20.2.2 jdolecek * void cpu_reboot(int howto, char *bootstr)
214 1.20.2.2 jdolecek *
215 1.20.2.2 jdolecek * Reboots the system
216 1.20.2.2 jdolecek *
217 1.20.2.2 jdolecek * Deal with any syncing, unmounting, dumping and shutdown hooks,
218 1.20.2.2 jdolecek * then reset the CPU.
219 1.20.2.2 jdolecek */
220 1.20.2.2 jdolecek void
221 1.20.2.2 jdolecek cpu_reboot(int howto, char *bootstr)
222 1.20.2.2 jdolecek {
223 1.20.2.2 jdolecek #ifdef DIAGNOSTIC
224 1.20.2.2 jdolecek /* info */
225 1.20.2.2 jdolecek printf("boot: howto=%08x curproc=%p\n", howto, curproc);
226 1.20.2.2 jdolecek #endif
227 1.20.2.2 jdolecek
228 1.20.2.2 jdolecek /*
229 1.20.2.2 jdolecek * If we are still cold then hit the air brakes
230 1.20.2.2 jdolecek * and crash to earth fast
231 1.20.2.2 jdolecek */
232 1.20.2.2 jdolecek if (cold) {
233 1.20.2.2 jdolecek doshutdownhooks();
234 1.20.2.2 jdolecek printf("The operating system has halted.\n");
235 1.20.2.2 jdolecek printf("Please press any key to reboot.\n\n");
236 1.20.2.2 jdolecek cngetc();
237 1.20.2.2 jdolecek printf("rebooting...\n");
238 1.20.2.2 jdolecek cpu_reset();
239 1.20.2.2 jdolecek /*NOTREACHED*/
240 1.20.2.2 jdolecek }
241 1.20.2.2 jdolecek
242 1.20.2.2 jdolecek /* Disable console buffering */
243 1.20.2.2 jdolecek
244 1.20.2.2 jdolecek /*
245 1.20.2.2 jdolecek * If RB_NOSYNC was not specified sync the discs.
246 1.20.2.2 jdolecek * Note: Unless cold is set to 1 here, syslogd will die during the
247 1.20.2.2 jdolecek * unmount. It looks like syslogd is getting woken up only to find
248 1.20.2.2 jdolecek * that it cannot page part of the binary in as the filesystem has
249 1.20.2.2 jdolecek * been unmounted.
250 1.20.2.2 jdolecek */
251 1.20.2.2 jdolecek if (!(howto & RB_NOSYNC))
252 1.20.2.2 jdolecek bootsync();
253 1.20.2.2 jdolecek
254 1.20.2.2 jdolecek /* Say NO to interrupts */
255 1.20.2.2 jdolecek splhigh();
256 1.20.2.2 jdolecek
257 1.20.2.2 jdolecek /* Do a dump if requested. */
258 1.20.2.2 jdolecek if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
259 1.20.2.2 jdolecek dumpsys();
260 1.20.2.2 jdolecek
261 1.20.2.2 jdolecek /* Run any shutdown hooks */
262 1.20.2.2 jdolecek doshutdownhooks();
263 1.20.2.2 jdolecek
264 1.20.2.2 jdolecek /* Make sure IRQ's are disabled */
265 1.20.2.2 jdolecek IRQdisable;
266 1.20.2.2 jdolecek
267 1.20.2.2 jdolecek if (howto & RB_HALT) {
268 1.20.2.4 jdolecek iq80310_7seg('.', '.');
269 1.20.2.2 jdolecek printf("The operating system has halted.\n");
270 1.20.2.2 jdolecek printf("Please press any key to reboot.\n\n");
271 1.20.2.2 jdolecek cngetc();
272 1.20.2.2 jdolecek }
273 1.20.2.2 jdolecek
274 1.20.2.2 jdolecek printf("rebooting...\n");
275 1.20.2.2 jdolecek cpu_reset();
276 1.20.2.2 jdolecek /*NOTREACHED*/
277 1.20.2.2 jdolecek }
278 1.20.2.2 jdolecek
279 1.20.2.2 jdolecek /*
280 1.20.2.2 jdolecek * Mapping table for core kernel memory. This memory is mapped at init
281 1.20.2.2 jdolecek * time with section mappings.
282 1.20.2.2 jdolecek */
283 1.20.2.2 jdolecek struct l1_sec_map {
284 1.20.2.2 jdolecek vaddr_t va;
285 1.20.2.2 jdolecek vaddr_t pa;
286 1.20.2.2 jdolecek vsize_t size;
287 1.20.2.3 jdolecek vm_prot_t prot;
288 1.20.2.3 jdolecek int cache;
289 1.20.2.2 jdolecek } l1_sec_table[] = {
290 1.20.2.2 jdolecek /*
291 1.20.2.2 jdolecek * Map the on-board devices VA == PA so that we can access them
292 1.20.2.2 jdolecek * with the MMU on or off.
293 1.20.2.2 jdolecek */
294 1.20.2.2 jdolecek {
295 1.20.2.2 jdolecek IQ80310_OBIO_BASE,
296 1.20.2.2 jdolecek IQ80310_OBIO_BASE,
297 1.20.2.2 jdolecek IQ80310_OBIO_SIZE,
298 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE,
299 1.20.2.3 jdolecek PTE_NOCACHE,
300 1.20.2.2 jdolecek },
301 1.20.2.2 jdolecek
302 1.20.2.2 jdolecek {
303 1.20.2.2 jdolecek 0,
304 1.20.2.2 jdolecek 0,
305 1.20.2.2 jdolecek 0,
306 1.20.2.2 jdolecek 0,
307 1.20.2.3 jdolecek 0,
308 1.20.2.2 jdolecek }
309 1.20.2.2 jdolecek };
310 1.20.2.2 jdolecek
311 1.20.2.2 jdolecek /*
312 1.20.2.2 jdolecek * u_int initarm(...)
313 1.20.2.2 jdolecek *
314 1.20.2.2 jdolecek * Initial entry point on startup. This gets called before main() is
315 1.20.2.2 jdolecek * entered.
316 1.20.2.2 jdolecek * It should be responsible for setting up everything that must be
317 1.20.2.2 jdolecek * in place when main is called.
318 1.20.2.2 jdolecek * This includes
319 1.20.2.2 jdolecek * Taking a copy of the boot configuration structure.
320 1.20.2.2 jdolecek * Initialising the physical console so characters can be printed.
321 1.20.2.2 jdolecek * Setting up page tables for the kernel
322 1.20.2.2 jdolecek * Relocating the kernel to the bottom of physical memory
323 1.20.2.2 jdolecek */
324 1.20.2.2 jdolecek u_int
325 1.20.2.2 jdolecek initarm(void *arg)
326 1.20.2.2 jdolecek {
327 1.20.2.4 jdolecek extern vaddr_t xscale_cache_clean_addr;
328 1.20.2.2 jdolecek extern vsize_t xscale_minidata_clean_size;
329 1.20.2.2 jdolecek int loop;
330 1.20.2.2 jdolecek int loop1;
331 1.20.2.2 jdolecek u_int l1pagetable;
332 1.20.2.2 jdolecek pv_addr_t kernel_l1pt;
333 1.20.2.2 jdolecek pv_addr_t kernel_ptpt;
334 1.20.2.2 jdolecek paddr_t memstart;
335 1.20.2.2 jdolecek psize_t memsize;
336 1.20.2.2 jdolecek
337 1.20.2.2 jdolecek /*
338 1.20.2.2 jdolecek * Clear out the 7-segment display. Whee, the first visual
339 1.20.2.2 jdolecek * indication that we're running kernel code.
340 1.20.2.2 jdolecek */
341 1.20.2.2 jdolecek iq80310_7seg(' ', ' ');
342 1.20.2.2 jdolecek
343 1.20.2.2 jdolecek /*
344 1.20.2.2 jdolecek * Heads up ... Setup the CPU / MMU / TLB functions
345 1.20.2.2 jdolecek */
346 1.20.2.2 jdolecek if (set_cpufuncs())
347 1.20.2.2 jdolecek panic("cpu not recognized!");
348 1.20.2.2 jdolecek
349 1.20.2.2 jdolecek /* Calibrate the delay loop. */
350 1.20.2.2 jdolecek iq80310_calibrate_delay();
351 1.20.2.2 jdolecek
352 1.20.2.2 jdolecek /*
353 1.20.2.2 jdolecek * Since we map the on-board devices VA==PA, and the kernel
354 1.20.2.2 jdolecek * is running VA==PA, it's possible for us to initialize
355 1.20.2.2 jdolecek * the console now.
356 1.20.2.2 jdolecek */
357 1.20.2.2 jdolecek consinit();
358 1.20.2.2 jdolecek
359 1.20.2.2 jdolecek /* Talk to the user */
360 1.20.2.2 jdolecek printf("\nNetBSD/evbarm (IQ80310) booting ...\n");
361 1.20.2.2 jdolecek
362 1.20.2.2 jdolecek /*
363 1.20.2.2 jdolecek * Reset the secondary PCI bus. RedBoot doesn't stop devices
364 1.20.2.2 jdolecek * on the PCI bus before handing us control, so we have to
365 1.20.2.2 jdolecek * do this.
366 1.20.2.2 jdolecek *
367 1.20.2.2 jdolecek * XXX This is arguably a bug in RedBoot, and doing this reset
368 1.20.2.2 jdolecek * XXX could be problematic in the future if we encounter an
369 1.20.2.2 jdolecek * XXX application where the PPB in the i80312 is used as a
370 1.20.2.2 jdolecek * XXX PPB.
371 1.20.2.2 jdolecek */
372 1.20.2.2 jdolecek {
373 1.20.2.2 jdolecek uint32_t reg;
374 1.20.2.2 jdolecek
375 1.20.2.2 jdolecek printf("Resetting secondary PCI bus...\n");
376 1.20.2.2 jdolecek reg = bus_space_read_4(&obio_bs_tag,
377 1.20.2.2 jdolecek I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL);
378 1.20.2.2 jdolecek bus_space_write_4(&obio_bs_tag,
379 1.20.2.2 jdolecek I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
380 1.20.2.2 jdolecek reg | PPB_BC_SECONDARY_RESET);
381 1.20.2.2 jdolecek delay(10 * 1000); /* 10ms enough? */
382 1.20.2.2 jdolecek bus_space_write_4(&obio_bs_tag,
383 1.20.2.2 jdolecek I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
384 1.20.2.2 jdolecek reg);
385 1.20.2.2 jdolecek }
386 1.20.2.2 jdolecek
387 1.20.2.2 jdolecek /*
388 1.20.2.3 jdolecek * We are currently running with the MMU enabled and the
389 1.20.2.3 jdolecek * entire address space mapped VA==PA, except for the
390 1.20.2.3 jdolecek * first 64M of RAM is also double-mapped at 0xc0000000.
391 1.20.2.3 jdolecek * There is an L1 page table at 0xa0004000.
392 1.20.2.2 jdolecek */
393 1.20.2.2 jdolecek
394 1.20.2.2 jdolecek /*
395 1.20.2.2 jdolecek * Fetch the SDRAM start/size from the i80312 SDRAM configration
396 1.20.2.2 jdolecek * registers.
397 1.20.2.2 jdolecek */
398 1.20.2.2 jdolecek i80312_sdram_bounds(&obio_bs_tag, I80312_PMMR_BASE + I80312_MEM_BASE,
399 1.20.2.2 jdolecek &memstart, &memsize);
400 1.20.2.2 jdolecek
401 1.20.2.2 jdolecek printf("initarm: Configuring system ...\n");
402 1.20.2.2 jdolecek
403 1.20.2.2 jdolecek /* Fake bootconfig structure for the benefit of pmap.c */
404 1.20.2.2 jdolecek /* XXX must make the memory description h/w independant */
405 1.20.2.2 jdolecek bootconfig.dramblocks = 1;
406 1.20.2.2 jdolecek bootconfig.dram[0].address = memstart;
407 1.20.2.2 jdolecek bootconfig.dram[0].pages = memsize / NBPG;
408 1.20.2.2 jdolecek
409 1.20.2.2 jdolecek /*
410 1.20.2.2 jdolecek * Set up the variables that define the availablilty of
411 1.20.2.2 jdolecek * physical memory. For now, we're going to set
412 1.20.2.2 jdolecek * physical_freestart to 0xa0200000 (where the kernel
413 1.20.2.2 jdolecek * was loaded), and allocate the memory we need downwards.
414 1.20.2.3 jdolecek * If we get too close to the L1 table that we set up, we
415 1.20.2.3 jdolecek * will panic. We will update physical_freestart and
416 1.20.2.3 jdolecek * physical_freeend later to reflect what pmap_bootstrap()
417 1.20.2.2 jdolecek * wants to see.
418 1.20.2.2 jdolecek *
419 1.20.2.2 jdolecek * XXX pmap_bootstrap() needs an enema.
420 1.20.2.2 jdolecek */
421 1.20.2.2 jdolecek physical_start = bootconfig.dram[0].address;
422 1.20.2.2 jdolecek physical_end = physical_start + (bootconfig.dram[0].pages * NBPG);
423 1.20.2.2 jdolecek
424 1.20.2.2 jdolecek physical_freestart = 0xa0009000UL;
425 1.20.2.2 jdolecek physical_freeend = 0xa0200000UL;
426 1.20.2.2 jdolecek
427 1.20.2.2 jdolecek physmem = (physical_end - physical_start) / NBPG;
428 1.20.2.2 jdolecek
429 1.20.2.2 jdolecek /* Tell the user about the memory */
430 1.20.2.2 jdolecek printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
431 1.20.2.2 jdolecek physical_start, physical_end - 1);
432 1.20.2.2 jdolecek
433 1.20.2.2 jdolecek /*
434 1.20.2.2 jdolecek * Okay, the kernel starts 2MB in from the bottom of physical
435 1.20.2.2 jdolecek * memory. We are going to allocate our bootstrap pages downwards
436 1.20.2.2 jdolecek * from there.
437 1.20.2.2 jdolecek *
438 1.20.2.2 jdolecek * We need to allocate some fixed page tables to get the kernel
439 1.20.2.2 jdolecek * going. We allocate one page directory and a number of page
440 1.20.2.2 jdolecek * tables and store the physical addresses in the kernel_pt_table
441 1.20.2.2 jdolecek * array.
442 1.20.2.2 jdolecek *
443 1.20.2.2 jdolecek * The kernel page directory must be on a 16K boundary. The page
444 1.20.2.2 jdolecek * tables must be on 4K bounaries. What we do is allocate the
445 1.20.2.2 jdolecek * page directory on the first 16K boundary that we encounter, and
446 1.20.2.2 jdolecek * the page tables on 4K boundaries otherwise. Since we allocate
447 1.20.2.2 jdolecek * at least 3 L2 page tables, we are guaranteed to encounter at
448 1.20.2.2 jdolecek * least one 16K aligned region.
449 1.20.2.2 jdolecek */
450 1.20.2.2 jdolecek
451 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
452 1.20.2.2 jdolecek printf("Allocating page tables\n");
453 1.20.2.2 jdolecek #endif
454 1.20.2.2 jdolecek
455 1.20.2.2 jdolecek free_pages = (physical_freeend - physical_freestart) / NBPG;
456 1.20.2.2 jdolecek
457 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
458 1.20.2.2 jdolecek printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
459 1.20.2.2 jdolecek physical_freestart, free_pages, free_pages);
460 1.20.2.2 jdolecek #endif
461 1.20.2.2 jdolecek
462 1.20.2.2 jdolecek /* Define a macro to simplify memory allocation */
463 1.20.2.2 jdolecek #define valloc_pages(var, np) \
464 1.20.2.2 jdolecek alloc_pages((var).pv_pa, (np)); \
465 1.20.2.2 jdolecek (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
466 1.20.2.2 jdolecek
467 1.20.2.2 jdolecek #define alloc_pages(var, np) \
468 1.20.2.2 jdolecek physical_freeend -= ((np) * NBPG); \
469 1.20.2.2 jdolecek if (physical_freeend < physical_freestart) \
470 1.20.2.2 jdolecek panic("initarm: out of memory"); \
471 1.20.2.2 jdolecek (var) = physical_freeend; \
472 1.20.2.2 jdolecek free_pages -= (np); \
473 1.20.2.2 jdolecek memset((char *)(var), 0, ((np) * NBPG));
474 1.20.2.2 jdolecek
475 1.20.2.2 jdolecek loop1 = 0;
476 1.20.2.2 jdolecek kernel_l1pt.pv_pa = 0;
477 1.20.2.2 jdolecek for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
478 1.20.2.2 jdolecek /* Are we 16KB aligned for an L1 ? */
479 1.20.2.4 jdolecek if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
480 1.20.2.2 jdolecek && kernel_l1pt.pv_pa == 0) {
481 1.20.2.4 jdolecek valloc_pages(kernel_l1pt, L1_TABLE_SIZE / NBPG);
482 1.20.2.2 jdolecek } else {
483 1.20.2.3 jdolecek alloc_pages(kernel_pt_table[loop1].pv_pa,
484 1.20.2.4 jdolecek L2_TABLE_SIZE / NBPG);
485 1.20.2.3 jdolecek kernel_pt_table[loop1].pv_va =
486 1.20.2.3 jdolecek kernel_pt_table[loop1].pv_pa;
487 1.20.2.2 jdolecek ++loop1;
488 1.20.2.2 jdolecek }
489 1.20.2.2 jdolecek }
490 1.20.2.2 jdolecek
491 1.20.2.2 jdolecek /* This should never be able to happen but better confirm that. */
492 1.20.2.4 jdolecek if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
493 1.20.2.2 jdolecek panic("initarm: Failed to align the kernel page directory\n");
494 1.20.2.2 jdolecek
495 1.20.2.2 jdolecek /*
496 1.20.2.2 jdolecek * Allocate a page for the system page mapped to V0x00000000
497 1.20.2.2 jdolecek * This page will just contain the system vectors and can be
498 1.20.2.2 jdolecek * shared by all processes.
499 1.20.2.2 jdolecek */
500 1.20.2.2 jdolecek alloc_pages(systempage.pv_pa, 1);
501 1.20.2.2 jdolecek
502 1.20.2.2 jdolecek /* Allocate a page for the page table to map kernel page tables. */
503 1.20.2.4 jdolecek valloc_pages(kernel_ptpt, L2_TABLE_SIZE / NBPG);
504 1.20.2.2 jdolecek
505 1.20.2.2 jdolecek /* Allocate stacks for all modes */
506 1.20.2.2 jdolecek valloc_pages(irqstack, IRQ_STACK_SIZE);
507 1.20.2.2 jdolecek valloc_pages(abtstack, ABT_STACK_SIZE);
508 1.20.2.2 jdolecek valloc_pages(undstack, UND_STACK_SIZE);
509 1.20.2.2 jdolecek valloc_pages(kernelstack, UPAGES);
510 1.20.2.2 jdolecek
511 1.20.2.2 jdolecek /* Allocate enough pages for cleaning the Mini-Data cache. */
512 1.20.2.2 jdolecek KASSERT(xscale_minidata_clean_size <= NBPG);
513 1.20.2.2 jdolecek valloc_pages(minidataclean, 1);
514 1.20.2.2 jdolecek
515 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
516 1.20.2.2 jdolecek printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
517 1.20.2.2 jdolecek irqstack.pv_va);
518 1.20.2.2 jdolecek printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
519 1.20.2.2 jdolecek abtstack.pv_va);
520 1.20.2.2 jdolecek printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
521 1.20.2.2 jdolecek undstack.pv_va);
522 1.20.2.2 jdolecek printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
523 1.20.2.2 jdolecek kernelstack.pv_va);
524 1.20.2.2 jdolecek #endif
525 1.20.2.2 jdolecek
526 1.20.2.2 jdolecek /*
527 1.20.2.2 jdolecek * XXX Defer this to later so that we can reclaim the memory
528 1.20.2.2 jdolecek * XXX used by the RedBoot page tables.
529 1.20.2.2 jdolecek */
530 1.20.2.2 jdolecek alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
531 1.20.2.2 jdolecek
532 1.20.2.2 jdolecek /*
533 1.20.2.2 jdolecek * Ok we have allocated physical pages for the primary kernel
534 1.20.2.2 jdolecek * page tables
535 1.20.2.2 jdolecek */
536 1.20.2.2 jdolecek
537 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
538 1.20.2.2 jdolecek printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
539 1.20.2.2 jdolecek #endif
540 1.20.2.2 jdolecek
541 1.20.2.2 jdolecek /*
542 1.20.2.3 jdolecek * Now we start construction of the L1 page table
543 1.20.2.2 jdolecek * We start by mapping the L2 page tables into the L1.
544 1.20.2.2 jdolecek * This means that we can replace L1 mappings later on if necessary
545 1.20.2.2 jdolecek */
546 1.20.2.2 jdolecek l1pagetable = kernel_l1pt.pv_pa;
547 1.20.2.2 jdolecek
548 1.20.2.2 jdolecek /* Map the L2 pages tables in the L1 page table */
549 1.20.2.3 jdolecek pmap_link_l2pt(l1pagetable, 0x00000000,
550 1.20.2.3 jdolecek &kernel_pt_table[KERNEL_PT_SYS]);
551 1.20.2.3 jdolecek for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
552 1.20.2.3 jdolecek pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
553 1.20.2.3 jdolecek &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
554 1.20.2.3 jdolecek pmap_link_l2pt(l1pagetable, IQ80310_IOPXS_VBASE,
555 1.20.2.3 jdolecek &kernel_pt_table[KERNEL_PT_IOPXS]);
556 1.20.2.3 jdolecek for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
557 1.20.2.3 jdolecek pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
558 1.20.2.3 jdolecek &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
559 1.20.2.4 jdolecek pmap_link_l2pt(l1pagetable, PTE_BASE, &kernel_ptpt);
560 1.20.2.3 jdolecek
561 1.20.2.3 jdolecek /* update the top of the kernel VM */
562 1.20.2.3 jdolecek pmap_curmaxkvaddr =
563 1.20.2.4 jdolecek KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
564 1.20.2.2 jdolecek
565 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
566 1.20.2.2 jdolecek printf("Mapping kernel\n");
567 1.20.2.2 jdolecek #endif
568 1.20.2.2 jdolecek
569 1.20.2.2 jdolecek /* Now we fill in the L2 pagetable for the kernel static code/data */
570 1.20.2.2 jdolecek {
571 1.20.2.2 jdolecek extern char etext[], _end[];
572 1.20.2.2 jdolecek size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
573 1.20.2.2 jdolecek size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
574 1.20.2.2 jdolecek u_int logical;
575 1.20.2.2 jdolecek
576 1.20.2.2 jdolecek textsize = (textsize + PGOFSET) & ~PGOFSET;
577 1.20.2.2 jdolecek totalsize = (totalsize + PGOFSET) & ~PGOFSET;
578 1.20.2.2 jdolecek
579 1.20.2.2 jdolecek logical = 0x00200000; /* offset of kernel in RAM */
580 1.20.2.2 jdolecek
581 1.20.2.3 jdolecek logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
582 1.20.2.2 jdolecek physical_start + logical, textsize,
583 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
584 1.20.2.3 jdolecek logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
585 1.20.2.2 jdolecek physical_start + logical, totalsize - textsize,
586 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
587 1.20.2.2 jdolecek }
588 1.20.2.2 jdolecek
589 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
590 1.20.2.2 jdolecek printf("Constructing L2 page tables\n");
591 1.20.2.2 jdolecek #endif
592 1.20.2.2 jdolecek
593 1.20.2.2 jdolecek /* Map the stack pages */
594 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
595 1.20.2.3 jdolecek IRQ_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
596 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
597 1.20.2.3 jdolecek ABT_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
598 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
599 1.20.2.3 jdolecek UND_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
600 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
601 1.20.2.3 jdolecek UPAGES * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
602 1.20.2.3 jdolecek
603 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
604 1.20.2.4 jdolecek L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
605 1.20.2.2 jdolecek
606 1.20.2.2 jdolecek /* Map the Mini-Data cache clean area. */
607 1.20.2.4 jdolecek xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
608 1.20.2.4 jdolecek minidataclean.pv_pa);
609 1.20.2.2 jdolecek
610 1.20.2.2 jdolecek /* Map the page table that maps the kernel pages */
611 1.20.2.3 jdolecek pmap_map_entry(l1pagetable, kernel_ptpt.pv_va, kernel_ptpt.pv_pa,
612 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
613 1.20.2.2 jdolecek
614 1.20.2.2 jdolecek /*
615 1.20.2.2 jdolecek * Map entries in the page table used to map PTE's
616 1.20.2.2 jdolecek * Basically every kernel page table gets mapped here
617 1.20.2.2 jdolecek */
618 1.20.2.2 jdolecek /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
619 1.20.2.3 jdolecek for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) {
620 1.20.2.3 jdolecek pmap_map_entry(l1pagetable,
621 1.20.2.4 jdolecek PTE_BASE + ((KERNEL_BASE +
622 1.20.2.3 jdolecek (loop * 0x00400000)) >> (PGSHIFT-2)),
623 1.20.2.3 jdolecek kernel_pt_table[KERNEL_PT_KERNEL + loop].pv_pa,
624 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
625 1.20.2.3 jdolecek }
626 1.20.2.3 jdolecek pmap_map_entry(l1pagetable,
627 1.20.2.4 jdolecek PTE_BASE + (PTE_BASE >> (PGSHIFT-2)),
628 1.20.2.3 jdolecek kernel_ptpt.pv_pa, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
629 1.20.2.3 jdolecek pmap_map_entry(l1pagetable,
630 1.20.2.4 jdolecek PTE_BASE + (0x00000000 >> (PGSHIFT-2)),
631 1.20.2.3 jdolecek kernel_pt_table[KERNEL_PT_SYS].pv_pa,
632 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
633 1.20.2.3 jdolecek for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
634 1.20.2.3 jdolecek pmap_map_entry(l1pagetable,
635 1.20.2.4 jdolecek PTE_BASE + ((KERNEL_VM_BASE +
636 1.20.2.2 jdolecek (loop * 0x00400000)) >> (PGSHIFT-2)),
637 1.20.2.3 jdolecek kernel_pt_table[KERNEL_PT_VMDATA + loop].pv_pa,
638 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
639 1.20.2.2 jdolecek
640 1.20.2.4 jdolecek /* Map the vector page. */
641 1.20.2.4 jdolecek pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
642 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
643 1.20.2.2 jdolecek
644 1.20.2.2 jdolecek /*
645 1.20.2.2 jdolecek * Map devices we can map w/ section mappings.
646 1.20.2.2 jdolecek */
647 1.20.2.2 jdolecek loop = 0;
648 1.20.2.2 jdolecek while (l1_sec_table[loop].size) {
649 1.20.2.2 jdolecek vm_size_t sz;
650 1.20.2.2 jdolecek
651 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
652 1.20.2.2 jdolecek printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
653 1.20.2.2 jdolecek l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
654 1.20.2.2 jdolecek l1_sec_table[loop].va);
655 1.20.2.2 jdolecek #endif
656 1.20.2.4 jdolecek for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
657 1.20.2.3 jdolecek pmap_map_section(l1pagetable,
658 1.20.2.3 jdolecek l1_sec_table[loop].va + sz,
659 1.20.2.2 jdolecek l1_sec_table[loop].pa + sz,
660 1.20.2.3 jdolecek l1_sec_table[loop].prot,
661 1.20.2.3 jdolecek l1_sec_table[loop].cache);
662 1.20.2.2 jdolecek ++loop;
663 1.20.2.2 jdolecek }
664 1.20.2.2 jdolecek
665 1.20.2.2 jdolecek /*
666 1.20.2.2 jdolecek * Map the PCI I/O spaces and i80312 registers. These are too
667 1.20.2.2 jdolecek * small to be mapped w/ section mappings.
668 1.20.2.2 jdolecek */
669 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
670 1.20.2.2 jdolecek printf("Mapping PIOW 0x%08lx -> 0x%08lx @ 0x%08lx\n",
671 1.20.2.2 jdolecek I80312_PCI_XLATE_PIOW_BASE,
672 1.20.2.2 jdolecek I80312_PCI_XLATE_PIOW_BASE + I80312_PCI_XLATE_IOSIZE - 1,
673 1.20.2.2 jdolecek IQ80310_PIOW_VBASE);
674 1.20.2.2 jdolecek #endif
675 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, IQ80310_PIOW_VBASE,
676 1.20.2.3 jdolecek I80312_PCI_XLATE_PIOW_BASE, I80312_PCI_XLATE_IOSIZE,
677 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
678 1.20.2.2 jdolecek
679 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
680 1.20.2.2 jdolecek printf("Mapping SIOW 0x%08lx -> 0x%08lx @ 0x%08lx\n",
681 1.20.2.2 jdolecek I80312_PCI_XLATE_SIOW_BASE,
682 1.20.2.2 jdolecek I80312_PCI_XLATE_SIOW_BASE + I80312_PCI_XLATE_IOSIZE - 1,
683 1.20.2.2 jdolecek IQ80310_SIOW_VBASE);
684 1.20.2.2 jdolecek #endif
685 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, IQ80310_SIOW_VBASE,
686 1.20.2.3 jdolecek I80312_PCI_XLATE_SIOW_BASE, I80312_PCI_XLATE_IOSIZE,
687 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
688 1.20.2.2 jdolecek
689 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
690 1.20.2.2 jdolecek printf("Mapping 80312 0x%08lx -> 0x%08lx @ 0x%08lx\n",
691 1.20.2.2 jdolecek I80312_PMMR_BASE,
692 1.20.2.2 jdolecek I80312_PMMR_BASE + I80312_PMMR_SIZE - 1,
693 1.20.2.2 jdolecek IQ80310_80312_VBASE);
694 1.20.2.2 jdolecek #endif
695 1.20.2.3 jdolecek pmap_map_chunk(l1pagetable, IQ80310_80312_VBASE,
696 1.20.2.3 jdolecek I80312_PMMR_BASE, I80312_PMMR_SIZE,
697 1.20.2.3 jdolecek VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
698 1.20.2.2 jdolecek
699 1.20.2.2 jdolecek /*
700 1.20.2.2 jdolecek * Give the XScale global cache clean code an appropriately
701 1.20.2.2 jdolecek * sized chunk of unmapped VA space starting at 0xff000000
702 1.20.2.2 jdolecek * (our device mappings end before this address).
703 1.20.2.2 jdolecek */
704 1.20.2.2 jdolecek xscale_cache_clean_addr = 0xff000000U;
705 1.20.2.2 jdolecek
706 1.20.2.2 jdolecek /*
707 1.20.2.2 jdolecek * Now we have the real page tables in place so we can switch to them.
708 1.20.2.2 jdolecek * Once this is done we will be running with the REAL kernel page
709 1.20.2.2 jdolecek * tables.
710 1.20.2.2 jdolecek */
711 1.20.2.2 jdolecek
712 1.20.2.2 jdolecek /*
713 1.20.2.2 jdolecek * Update the physical_freestart/physical_freeend/free_pages
714 1.20.2.2 jdolecek * variables.
715 1.20.2.2 jdolecek */
716 1.20.2.2 jdolecek {
717 1.20.2.2 jdolecek extern char _end[];
718 1.20.2.2 jdolecek
719 1.20.2.3 jdolecek physical_freestart = physical_start +
720 1.20.2.3 jdolecek (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
721 1.20.2.3 jdolecek KERNEL_BASE);
722 1.20.2.2 jdolecek physical_freeend = physical_end;
723 1.20.2.2 jdolecek free_pages = (physical_freeend - physical_freestart) / NBPG;
724 1.20.2.2 jdolecek }
725 1.20.2.2 jdolecek
726 1.20.2.2 jdolecek /* Switch tables */
727 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
728 1.20.2.2 jdolecek printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
729 1.20.2.2 jdolecek physical_freestart, free_pages, free_pages);
730 1.20.2.2 jdolecek printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
731 1.20.2.2 jdolecek #endif
732 1.20.2.2 jdolecek setttb(kernel_l1pt.pv_pa);
733 1.20.2.3 jdolecek cpu_tlb_flushID();
734 1.20.2.2 jdolecek
735 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
736 1.20.2.2 jdolecek printf("done!\n");
737 1.20.2.2 jdolecek #endif
738 1.20.2.2 jdolecek
739 1.20.2.2 jdolecek #ifdef VERBOSE_INIT_ARM
740 1.20.2.2 jdolecek printf("bootstrap done.\n");
741 1.20.2.2 jdolecek #endif
742 1.20.2.2 jdolecek
743 1.20.2.4 jdolecek arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
744 1.20.2.2 jdolecek
745 1.20.2.2 jdolecek /*
746 1.20.2.2 jdolecek * Pages were allocated during the secondary bootstrap for the
747 1.20.2.2 jdolecek * stacks for different CPU modes.
748 1.20.2.2 jdolecek * We must now set the r13 registers in the different CPU modes to
749 1.20.2.2 jdolecek * point to these stacks.
750 1.20.2.2 jdolecek * Since the ARM stacks use STMFD etc. we must set r13 to the top end
751 1.20.2.2 jdolecek * of the stack memory.
752 1.20.2.2 jdolecek */
753 1.20.2.2 jdolecek printf("init subsystems: stacks ");
754 1.20.2.2 jdolecek
755 1.20.2.2 jdolecek set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
756 1.20.2.2 jdolecek set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
757 1.20.2.2 jdolecek set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
758 1.20.2.2 jdolecek
759 1.20.2.2 jdolecek /*
760 1.20.2.2 jdolecek * Well we should set a data abort handler.
761 1.20.2.2 jdolecek * Once things get going this will change as we will need a proper
762 1.20.2.2 jdolecek * handler.
763 1.20.2.2 jdolecek * Until then we will use a handler that just panics but tells us
764 1.20.2.2 jdolecek * why.
765 1.20.2.2 jdolecek * Initialisation of the vectors will just panic on a data abort.
766 1.20.2.2 jdolecek * This just fills in a slighly better one.
767 1.20.2.2 jdolecek */
768 1.20.2.2 jdolecek printf("vectors ");
769 1.20.2.2 jdolecek data_abort_handler_address = (u_int)data_abort_handler;
770 1.20.2.2 jdolecek prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
771 1.20.2.2 jdolecek undefined_handler_address = (u_int)undefinedinstruction_bounce;
772 1.20.2.2 jdolecek
773 1.20.2.2 jdolecek /* Initialise the undefined instruction handlers */
774 1.20.2.2 jdolecek printf("undefined ");
775 1.20.2.2 jdolecek undefined_init();
776 1.20.2.2 jdolecek
777 1.20.2.2 jdolecek /* Boot strap pmap telling it where the kernel page table is */
778 1.20.2.2 jdolecek printf("pmap ");
779 1.20.2.2 jdolecek pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
780 1.20.2.2 jdolecek
781 1.20.2.2 jdolecek /* Setup the IRQ system */
782 1.20.2.2 jdolecek printf("irq ");
783 1.20.2.2 jdolecek iq80310_intr_init();
784 1.20.2.2 jdolecek printf("done.\n");
785 1.20.2.2 jdolecek
786 1.20.2.2 jdolecek #ifdef IPKDB
787 1.20.2.2 jdolecek /* Initialise ipkdb */
788 1.20.2.2 jdolecek ipkdb_init();
789 1.20.2.2 jdolecek if (boothowto & RB_KDB)
790 1.20.2.2 jdolecek ipkdb_connect(0);
791 1.20.2.2 jdolecek #endif
792 1.20.2.2 jdolecek
793 1.20.2.2 jdolecek #ifdef DDB
794 1.20.2.2 jdolecek db_machine_init();
795 1.20.2.2 jdolecek
796 1.20.2.2 jdolecek /* Firmware doesn't load symbols. */
797 1.20.2.2 jdolecek ddb_init(0, NULL, NULL);
798 1.20.2.2 jdolecek
799 1.20.2.2 jdolecek if (boothowto & RB_KDB)
800 1.20.2.2 jdolecek Debugger();
801 1.20.2.2 jdolecek #endif
802 1.20.2.2 jdolecek
803 1.20.2.2 jdolecek /* We return the new stack pointer address */
804 1.20.2.2 jdolecek return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
805 1.20.2.2 jdolecek }
806 1.20.2.2 jdolecek
807 1.20.2.2 jdolecek void
808 1.20.2.2 jdolecek consinit(void)
809 1.20.2.2 jdolecek {
810 1.20.2.2 jdolecek static const bus_addr_t comcnaddrs[] = {
811 1.20.2.2 jdolecek IQ80310_UART2, /* com0 (J9) */
812 1.20.2.2 jdolecek IQ80310_UART1, /* com1 (J10) */
813 1.20.2.2 jdolecek };
814 1.20.2.2 jdolecek static int consinit_called;
815 1.20.2.2 jdolecek
816 1.20.2.2 jdolecek if (consinit_called != 0)
817 1.20.2.2 jdolecek return;
818 1.20.2.2 jdolecek
819 1.20.2.2 jdolecek consinit_called = 1;
820 1.20.2.2 jdolecek
821 1.20.2.2 jdolecek #if NCOM > 0
822 1.20.2.2 jdolecek if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
823 1.20.2.2 jdolecek COM_FREQ, comcnmode))
824 1.20.2.3 jdolecek panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
825 1.20.2.2 jdolecek #else
826 1.20.2.3 jdolecek panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
827 1.20.2.2 jdolecek #endif
828 1.20.2.2 jdolecek }
829