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