hdlg_machdep.c revision 1.1 1 /* $NetBSD: hdlg_machdep.c,v 1.1 2006/04/16 02:22:33 nonaka 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.1 2006/04/16 02:22:33 nonaka 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 systempage;
169 pv_addr_t irqstack;
170 pv_addr_t undstack;
171 pv_addr_t abtstack;
172 pv_addr_t kernelstack;
173 pv_addr_t minidataclean;
174
175 vm_offset_t msgbufphys;
176
177 extern u_int data_abort_handler_address;
178 extern u_int prefetch_abort_handler_address;
179 extern u_int undefined_handler_address;
180
181 #ifdef PMAP_DEBUG
182 extern int pmap_debug_level;
183 #endif
184
185 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
186
187 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
188 #define KERNEL_PT_KERNEL_NUM 4
189
190 /* L2 table for mapping i80321 */
191 #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
192
193 /* L2 tables for mapping kernel VM */
194 #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
195 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
196 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
197
198 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
199
200 struct user *proc0paddr;
201
202 /* Prototypes */
203 void consinit(void);
204
205 /* Static device mappings. */
206 static const struct pmap_devmap hdlg_devmap[] = {
207 /*
208 * Map the on-board devices VA == PA so that we can access them
209 * with the MMU on or off.
210 */
211 {
212 HDLG_OBIO_BASE,
213 HDLG_OBIO_BASE,
214 HDLG_OBIO_SIZE,
215 VM_PROT_READ|VM_PROT_WRITE,
216 PTE_NOCACHE,
217 },
218
219 {
220 HDLG_IOW_VBASE,
221 VERDE_OUT_XLATE_IO_WIN0_BASE,
222 VERDE_OUT_XLATE_IO_WIN_SIZE,
223 VM_PROT_READ|VM_PROT_WRITE,
224 PTE_NOCACHE,
225 },
226
227 {
228 HDLG_80321_VBASE,
229 VERDE_PMMR_BASE,
230 VERDE_PMMR_SIZE,
231 VM_PROT_READ|VM_PROT_WRITE,
232 PTE_NOCACHE,
233 },
234
235 {
236 0,
237 0,
238 0,
239 0,
240 0,
241 }
242 };
243
244 static void
245 hardclock_hook(void)
246 {
247
248 /* Nothing to do */
249 }
250
251 /*
252 * u_int initarm(...)
253 *
254 * Initial entry point on startup. This gets called before main() is
255 * entered.
256 * It should be responsible for setting up everything that must be
257 * in place when main is called.
258 * This includes
259 * Taking a copy of the boot configuration structure.
260 * Initialising the physical console so characters can be printed.
261 * Setting up page tables for the kernel
262 * Relocating the kernel to the bottom of physical memory
263 */
264 u_int
265 initarm(void *arg)
266 {
267 extern vaddr_t xscale_cache_clean_addr;
268 #ifdef DIAGNOSTIC
269 extern vsize_t xscale_minidata_clean_size;
270 #endif
271 int loop;
272 int loop1;
273 u_int l1pagetable;
274 pv_addr_t kernel_l1pt;
275 paddr_t memstart;
276 psize_t memsize;
277
278 /* Calibrate the delay loop. */
279 i80321_calibrate_delay();
280 i80321_hardclock_hook = hardclock_hook;
281
282 /*
283 * Since we map the on-board devices VA==PA, and the kernel
284 * is running VA==PA, it's possible for us to initialize
285 * the console now.
286 */
287 consinit();
288
289 #ifdef VERBOSE_INIT_ARM
290 /* Talk to the user */
291 printf("\nNetBSD/hdlg booting ...\n");
292 #endif
293
294 /*
295 * Heads up ... Setup the CPU / MMU / TLB functions
296 */
297 if (set_cpufuncs())
298 panic("CPU not recognized!");
299
300 /*
301 * We are currently running with the MMU enabled and the
302 * entire address space mapped VA==PA, except for the
303 * first 64M of RAM is also double-mapped at 0xc0000000.
304 * There is an L1 page table at 0xa0004000.
305 */
306
307 /*
308 * Fetch the SDRAM start/size from the i80321 SDRAM configuration
309 * registers.
310 */
311 i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
312 &memstart, &memsize);
313
314 #ifdef VERBOSE_INIT_ARM
315 printf("initarm: Configuring system ...\n");
316 #endif
317
318 /* Fake bootconfig structure for the benefit of pmap.c */
319 /* XXX must make the memory description h/w independant */
320 bootconfig.dramblocks = 1;
321 bootconfig.dram[0].address = memstart;
322 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
323
324 /*
325 * Set up the variables that define the availablilty of
326 * physical memory. For now, we're going to set
327 * physical_freestart to 0xa0200000 (where the kernel
328 * was loaded), and allocate the memory we need downwards.
329 * If we get too close to the L1 table that we set up, we
330 * will panic. We will update physical_freestart and
331 * physical_freeend later to reflect what pmap_bootstrap()
332 * wants to see.
333 *
334 * XXX pmap_bootstrap() needs an enema.
335 */
336 physical_start = bootconfig.dram[0].address;
337 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
338
339 physical_freestart = 0xa0009000UL;
340 physical_freeend = 0xa0200000UL;
341
342 physmem = (physical_end - physical_start) / PAGE_SIZE;
343
344 #ifdef VERBOSE_INIT_ARM
345 /* Tell the user about the memory */
346 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
347 physical_start, physical_end - 1);
348 #endif
349
350 /*
351 * Okay, the kernel starts 2MB in from the bottom of physical
352 * memory. We are going to allocate our bootstrap pages downwards
353 * from there.
354 *
355 * We need to allocate some fixed page tables to get the kernel
356 * going. We allocate one page directory and a number of page
357 * tables and store the physical addresses in the kernel_pt_table
358 * array.
359 *
360 * The kernel page directory must be on a 16K boundary. The page
361 * tables must be on 4K boundaries. What we do is allocate the
362 * page directory on the first 16K boundary that we encounter, and
363 * the page tables on 4K boundaries otherwise. Since we allocate
364 * at least 3 L2 page tables, we are guaranteed to encounter at
365 * least one 16K aligned region.
366 */
367
368 #ifdef VERBOSE_INIT_ARM
369 printf("Allocating page tables\n");
370 #endif
371
372 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
373
374 #ifdef VERBOSE_INIT_ARM
375 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
376 physical_freestart, free_pages, free_pages);
377 #endif
378
379 /* Define a macro to simplify memory allocation */
380 #define valloc_pages(var, np) \
381 alloc_pages((var).pv_pa, (np)); \
382 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
383
384 #define alloc_pages(var, np) \
385 physical_freeend -= ((np) * PAGE_SIZE); \
386 if (physical_freeend < physical_freestart) \
387 panic("initarm: out of memory"); \
388 (var) = physical_freeend; \
389 free_pages -= (np); \
390 memset((char *)(var), 0, ((np) * PAGE_SIZE));
391
392 loop1 = 0;
393 kernel_l1pt.pv_pa = 0;
394 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
395 /* Are we 16KB aligned for an L1 ? */
396 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
397 && kernel_l1pt.pv_pa == 0) {
398 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
399 } else {
400 valloc_pages(kernel_pt_table[loop1],
401 L2_TABLE_SIZE / PAGE_SIZE);
402 ++loop1;
403 }
404 }
405
406 /* This should never be able to happen but better confirm that. */
407 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
408 panic("initarm: Failed to align the kernel page directory");
409
410 /*
411 * Allocate a page for the system page mapped to V0x00000000
412 * This page will just contain the system vectors and can be
413 * shared by all processes.
414 */
415 alloc_pages(systempage.pv_pa, 1);
416
417 /* Allocate stacks for all modes */
418 valloc_pages(irqstack, IRQ_STACK_SIZE);
419 valloc_pages(abtstack, ABT_STACK_SIZE);
420 valloc_pages(undstack, UND_STACK_SIZE);
421 valloc_pages(kernelstack, UPAGES);
422
423 /* Allocate enough pages for cleaning the Mini-Data cache. */
424 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
425 valloc_pages(minidataclean, 1);
426
427 #ifdef VERBOSE_INIT_ARM
428 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
429 irqstack.pv_va);
430 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
431 abtstack.pv_va);
432 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
433 undstack.pv_va);
434 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
435 kernelstack.pv_va);
436 #endif
437
438 /*
439 * XXX Defer this to later so that we can reclaim the memory
440 * XXX used by the RedBoot page tables.
441 */
442 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
443
444 /*
445 * Ok we have allocated physical pages for the primary kernel
446 * page tables
447 */
448
449 #ifdef VERBOSE_INIT_ARM
450 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
451 #endif
452
453 /*
454 * Now we start construction of the L1 page table
455 * We start by mapping the L2 page tables into the L1.
456 * This means that we can replace L1 mappings later on if necessary
457 */
458 l1pagetable = kernel_l1pt.pv_pa;
459
460 /* Map the L2 pages tables in the L1 page table */
461 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
462 &kernel_pt_table[KERNEL_PT_SYS]);
463 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
464 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
465 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
466 pmap_link_l2pt(l1pagetable, HDLG_IOPXS_VBASE,
467 &kernel_pt_table[KERNEL_PT_IOPXS]);
468 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
469 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
470 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
471
472 /* update the top of the kernel VM */
473 pmap_curmaxkvaddr =
474 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
475
476 #ifdef VERBOSE_INIT_ARM
477 printf("Mapping kernel\n");
478 #endif
479
480 /* Now we fill in the L2 pagetable for the kernel static code/data */
481 {
482 extern char etext[], _end[];
483 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
484 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
485 u_int logical;
486
487 textsize = (textsize + PGOFSET) & ~PGOFSET;
488 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
489
490 logical = 0x00200000; /* offset of kernel in RAM */
491
492 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
493 physical_start + logical, textsize,
494 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
495 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
496 physical_start + logical, totalsize - textsize,
497 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
498 }
499
500 #ifdef VERBOSE_INIT_ARM
501 printf("Constructing L2 page tables\n");
502 #endif
503
504 /* Map the stack pages */
505 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
506 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
507 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
508 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
509 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
510 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
511 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
512 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
513
514 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
515 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
516
517 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
518 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
519 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
520 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
521 }
522
523 /* Map the Mini-Data cache clean area. */
524 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
525 minidataclean.pv_pa);
526
527 /* Map the vector page. */
528 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
529 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
530
531 /* Map the statically mapped devices. */
532 pmap_devmap_bootstrap(l1pagetable, hdlg_devmap);
533
534 /*
535 * Give the XScale global cache clean code an appropriately
536 * sized chunk of unmapped VA space starting at 0xff000000
537 * (our device mappings end before this address).
538 */
539 xscale_cache_clean_addr = 0xff000000U;
540
541 /*
542 * Now we have the real page tables in place so we can switch to them.
543 * Once this is done we will be running with the REAL kernel page
544 * tables.
545 */
546
547 /*
548 * Update the physical_freestart/physical_freeend/free_pages
549 * variables.
550 */
551 {
552 extern char _end[];
553
554 physical_freestart = physical_start +
555 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
556 KERNEL_BASE);
557 physical_freeend = physical_end;
558 free_pages =
559 (physical_freeend - physical_freestart) / PAGE_SIZE;
560 }
561
562 /* Switch tables */
563 #ifdef VERBOSE_INIT_ARM
564 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
565 physical_freestart, free_pages, free_pages);
566 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
567 #endif
568 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
569 setttb(kernel_l1pt.pv_pa);
570 cpu_tlb_flushID();
571 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
572
573 /*
574 * Moved from cpu_startup() as data_abort_handler() references
575 * this during uvm init
576 */
577 proc0paddr = (struct user *)kernelstack.pv_va;
578 lwp0.l_addr = proc0paddr;
579
580 #ifdef VERBOSE_INIT_ARM
581 printf("done!\n");
582 #endif
583
584 #ifdef VERBOSE_INIT_ARM
585 printf("bootstrap done.\n");
586 #endif
587
588 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
589
590 /*
591 * Pages were allocated during the secondary bootstrap for the
592 * stacks for different CPU modes.
593 * We must now set the r13 registers in the different CPU modes to
594 * point to these stacks.
595 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
596 * of the stack memory.
597 */
598 #ifdef VERBOSE_INIT_ARM
599 printf("init subsystems: stacks ");
600 #endif
601
602 set_stackptr(PSR_IRQ32_MODE,
603 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
604 set_stackptr(PSR_ABT32_MODE,
605 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
606 set_stackptr(PSR_UND32_MODE,
607 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
608
609 /*
610 * Well we should set a data abort handler.
611 * Once things get going this will change as we will need a proper
612 * handler.
613 * Until then we will use a handler that just panics but tells us
614 * why.
615 * Initialisation of the vectors will just panic on a data abort.
616 * This just fills in a slightly better one.
617 */
618 #ifdef VERBOSE_INIT_ARM
619 printf("vectors ");
620 #endif
621 data_abort_handler_address = (u_int)data_abort_handler;
622 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
623 undefined_handler_address = (u_int)undefinedinstruction_bounce;
624
625 /* Initialise the undefined instruction handlers */
626 #ifdef VERBOSE_INIT_ARM
627 printf("undefined ");
628 #endif
629 undefined_init();
630
631 /* Load memory into UVM. */
632 #ifdef VERBOSE_INIT_ARM
633 printf("page ");
634 #endif
635 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
636 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
637 atop(physical_freestart), atop(physical_freeend),
638 VM_FREELIST_DEFAULT);
639
640 /* Boot strap pmap telling it where the kernel page table is */
641 #ifdef VERBOSE_INIT_ARM
642 printf("pmap ");
643 #endif
644 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
645 KERNEL_VM_BASE + KERNEL_VM_SIZE);
646
647 /* Setup the IRQ system */
648 #ifdef VERBOSE_INIT_ARM
649 printf("irq ");
650 #endif
651 i80321_intr_init();
652
653 #ifdef VERBOSE_INIT_ARM
654 printf("done.\n");
655 #endif
656
657 #ifdef BOOTHOWTO
658 boothowto = BOOTHOWTO;
659 #endif
660
661 #ifdef IPKDB
662 /* Initialise ipkdb */
663 ipkdb_init();
664 if (boothowto & RB_KDB)
665 ipkdb_connect(0);
666 #endif
667
668 #if NKSYMS || defined(DDB) || defined(LKM)
669 /* Firmware doesn't load symbols. */
670 ksyms_init(0, NULL, NULL);
671 #endif
672
673 #ifdef DDB
674 db_machine_init();
675 if (boothowto & RB_KDB)
676 Debugger();
677 #endif
678
679 /* We return the new stack pointer address */
680 return (kernelstack.pv_va + USPACE_SVC_STACK_TOP);
681 }
682
683 /*
684 * void cpu_reboot(int howto, char *bootstr)
685 *
686 * Reboots the system
687 *
688 * Deal with any syncing, unmounting, dumping and shutdown hooks,
689 * then reset the CPU.
690 */
691 void
692 cpu_reboot(int howto, char *bootstr)
693 {
694
695 /*
696 * If we are still cold then hit the air brakes
697 * and crash to earth fast
698 */
699 if (cold) {
700 *(volatile uint8_t *)HDLG_LEDCTRL |= LEDCTRL_STAT_RED;
701 howto |= RB_HALT;
702 goto haltsys;
703 }
704
705 /* Disable console buffering */
706
707 /*
708 * If RB_NOSYNC was not specified sync the discs.
709 * Note: Unless cold is set to 1 here, syslogd will die during the
710 * unmount. It looks like syslogd is getting woken up only to find
711 * that it cannot page part of the binary in as the filesystem has
712 * been unmounted.
713 */
714 if ((howto & RB_NOSYNC) == 0) {
715 bootsync();
716 /*resettodr();*/
717 }
718
719 /* wait 1s */
720 delay(1 * 1000 * 1000);
721
722 /* Say NO to interrupts */
723 splhigh();
724
725 /* Do a dump if requested. */
726 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) {
727 dumpsys();
728 }
729
730 haltsys:
731 /* Run any shutdown hooks */
732 doshutdownhooks();
733
734 /* Make sure IRQ's are disabled */
735 IRQdisable;
736
737 if (howto & RB_HALT) {
738 *(volatile uint8_t *)HDLG_PWRMNG = PWRMNG_POWOFF;
739 delay(3 * 1000 * 1000); /* wait 3s */
740
741 printf("SHUTDOWN FAILED!\n");
742 printf("The operating system has halted.\n");
743 printf("Please press any key to reboot.\n\n");
744 cngetc();
745 }
746
747 printf("rebooting...\n\r");
748
749 (void)disable_interrupts(I32_bit|F32_bit);
750 cpu_idcache_wbinv_all();
751 cpu_drain_writebuf();
752
753 *(volatile uint8_t *)HDLG_PWRMNG = PWRMNG_RESET;
754 delay(1 * 1000 * 1000); /* wait 1s */
755
756 /* ...and if that didn't work, just croak. */
757 printf("RESET FAILED!\n");
758 for (;;) {
759 continue;
760 }
761 }
762
763 /*
764 * console
765 */
766 #include "com.h"
767 #if NCOM > 0
768 #include <dev/ic/comreg.h>
769 #include <dev/ic/comvar.h>
770 #endif
771
772 /*
773 * Define the default console speed for the board. This is generally
774 * what the firmware provided with the board defaults to.
775 */
776 #ifndef CONSPEED
777 #define CONSPEED B115200
778 #endif /* ! CONSPEED */
779
780 #ifndef CONUNIT
781 #define CONUNIT 0
782 #endif
783
784 #ifndef CONMODE
785 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
786 #endif
787
788 int comcnspeed = CONSPEED;
789 int comcnmode = CONMODE;
790 int comcnunit = CONUNIT;
791
792 #if KGDB
793 #ifndef KGDB_DEVNAME
794 #error Must define KGDB_DEVNAME
795 #endif
796 const char kgdb_devname[] = KGDB_DEVNAME;
797
798 #ifndef KGDB_DEVADDR
799 #error Must define KGDB_DEVADDR
800 #endif
801 unsigned long kgdb_devaddr = KGDB_DEVADDR;
802
803 #ifndef KGDB_DEVRATE
804 #define KGDB_DEVRATE CONSPEED
805 #endif
806 int kgdb_devrate = KGDB_DEVRATE;
807
808 #ifndef KGDB_DEVMODE
809 #define KGDB_DEVMODE CONMODE
810 #endif
811 int kgdb_devmode = KGDB_DEVMODE;
812 #endif /* KGDB */
813
814 void
815 consinit(void)
816 {
817 static const bus_addr_t comcnaddrs[] = {
818 HDLG_UART1, /* com0 */
819 };
820 static int consinit_called;
821
822 if (consinit_called)
823 return;
824 consinit_called = 1;
825
826 /*
827 * Console devices are mapped VA==PA. Our devmap reflects
828 * this, so register it now so drivers can map the console
829 * device.
830 */
831 pmap_devmap_register(hdlg_devmap);
832
833 #if NCOM > 0
834 if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
835 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
836 panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
837 #else
838 panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
839 #endif
840 #if KGDB
841 #if NCOM > 0
842 if (strcmp(kgdb_devname, "com") == 0) {
843 com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate,
844 COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode);
845 }
846 #endif /* NCOM > 0 */
847 #endif /* KGDB */
848 }
849