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