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