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