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