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