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