lubbock_machdep.c revision 1.8.2.2 1 /* $NetBSD: lubbock_machdep.c,v 1.8.2.2 2006/12/30 20:45:51 yamt Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
5 * Written by Hiroyuki Bessho for Genetec Corporation.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of Genetec Corporation may not be used to endorse or
16 * promote products derived from this software without specific prior
17 * written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Machine dependant functions for kernel setup for
32 * Intel DBPXA250 evaluation board (a.k.a. Lubbock).
33 * Based on iq80310_machhdep.c
34 */
35 /*
36 * Copyright (c) 2001 Wasabi Systems, Inc.
37 * All rights reserved.
38 *
39 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed for the NetBSD Project by
52 * Wasabi Systems, Inc.
53 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
54 * or promote products derived from this software without specific prior
55 * written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
59 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
61 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
62 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
63 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
64 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
65 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
66 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
67 * POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 /*
71 * Copyright (c) 1997,1998 Mark Brinicombe.
72 * Copyright (c) 1997,1998 Causality Limited.
73 * All rights reserved.
74 *
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 * must display the following acknowledgement:
85 * This product includes software developed by Mark Brinicombe
86 * for the NetBSD Project.
87 * 4. The name of the company nor the name of the author may be used to
88 * endorse or promote products derived from this software without specific
89 * prior written permission.
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
92 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
93 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
94 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
95 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
96 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 * SUCH DAMAGE.
102 *
103 * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
104 * boards using RedBoot firmware.
105 */
106
107 /*
108 * DIP switches:
109 *
110 * S19: no-dot: set RB_KDB. enter kgdb session.
111 * S20: no-dot: set RB_SINGLE. don't go multi user mode.
112 */
113
114 #include <sys/cdefs.h>
115 __KERNEL_RCSID(0, "$NetBSD: lubbock_machdep.c,v 1.8.2.2 2006/12/30 20:45:51 yamt Exp $");
116
117 #include "opt_ddb.h"
118 #include "opt_kgdb.h"
119 #include "opt_ipkdb.h"
120 #include "opt_pmap_debug.h"
121 #include "opt_md.h"
122 #include "opt_com.h"
123 #include "md.h"
124 #include "lcd.h"
125
126 #include <sys/param.h>
127 #include <sys/device.h>
128 #include <sys/systm.h>
129 #include <sys/kernel.h>
130 #include <sys/exec.h>
131 #include <sys/proc.h>
132 #include <sys/msgbuf.h>
133 #include <sys/reboot.h>
134 #include <sys/termios.h>
135 #include <sys/ksyms.h>
136
137 #include <uvm/uvm_extern.h>
138
139 #include <sys/conf.h>
140 #include <dev/cons.h>
141 #include <dev/md.h>
142 #include <dev/ic/smc91cxxreg.h>
143
144 #include <machine/db_machdep.h>
145 #include <ddb/db_sym.h>
146 #include <ddb/db_extern.h>
147 #ifdef KGDB
148 #include <sys/kgdb.h>
149 #endif
150
151 #include <machine/bootconfig.h>
152 #include <machine/bus.h>
153 #include <machine/cpu.h>
154 #include <machine/frame.h>
155 #include <arm/undefined.h>
156
157 #include <arm/arm32/machdep.h>
158
159 #include <arm/xscale/pxa2x0reg.h>
160 #include <arm/xscale/pxa2x0var.h>
161 #include <arm/xscale/pxa2x0_gpio.h>
162 #include <arm/sa11x0/sa1111_reg.h>
163 #include <evbarm/lubbock/lubbock_reg.h>
164 #include <evbarm/lubbock/lubbock_var.h>
165
166 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
167 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
168 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
169
170 /*
171 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
172 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
173 */
174 #define KERNEL_VM_SIZE 0x0C000000
175
176
177 /*
178 * Address to call from cpu_reset() to reset the machine.
179 * This is machine architecture dependant as it varies depending
180 * on where the ROM appears when you turn the MMU off.
181 */
182
183 u_int cpu_reset_address = 0;
184
185 /* Define various stack sizes in pages */
186 #define IRQ_STACK_SIZE 1
187 #define ABT_STACK_SIZE 1
188 #ifdef IPKDB
189 #define UND_STACK_SIZE 2
190 #else
191 #define UND_STACK_SIZE 1
192 #endif
193
194 BootConfig bootconfig; /* Boot config storage */
195 char *boot_args = NULL;
196 char *boot_file = NULL;
197
198 vm_offset_t physical_start;
199 vm_offset_t physical_freestart;
200 vm_offset_t physical_freeend;
201 vm_offset_t physical_end;
202 u_int free_pages;
203 vm_offset_t pagetables_start;
204 int physmem = 0;
205
206 /*int debug_flags;*/
207 #ifndef PMAP_STATIC_L1S
208 int max_processes = 64; /* Default number */
209 #endif /* !PMAP_STATIC_L1S */
210
211 /* Physical and virtual addresses for some global pages */
212 pv_addr_t systempage;
213 pv_addr_t irqstack;
214 pv_addr_t undstack;
215 pv_addr_t abtstack;
216 pv_addr_t kernelstack;
217 pv_addr_t minidataclean;
218
219 vm_offset_t msgbufphys;
220
221 extern u_int data_abort_handler_address;
222 extern u_int prefetch_abort_handler_address;
223 extern u_int undefined_handler_address;
224
225 #ifdef PMAP_DEBUG
226 extern int pmap_debug_level;
227 #endif
228
229 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
230 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
231 #define KERNEL_PT_KERNEL_NUM 4
232 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
233 /* Page tables for mapping kernel VM */
234 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
235 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
236
237 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
238
239 struct user *proc0paddr;
240
241 /* Prototypes */
242
243 #if 0
244 void process_kernel_args(char *);
245 #endif
246
247 void consinit(void);
248 void kgdb_port_init(void);
249 void change_clock(uint32_t v);
250
251 bs_protos(bs_notimpl);
252
253 #include "com.h"
254 #if NCOM > 0
255 #include <dev/ic/comreg.h>
256 #include <dev/ic/comvar.h>
257 #endif
258
259 #ifndef CONSPEED
260 #define CONSPEED B115200 /* What RedBoot uses */
261 #endif
262 #ifndef CONMODE
263 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
264 #endif
265
266 int comcnspeed = CONSPEED;
267 int comcnmode = CONMODE;
268
269 /*
270 * void cpu_reboot(int howto, char *bootstr)
271 *
272 * Reboots the system
273 *
274 * Deal with any syncing, unmounting, dumping and shutdown hooks,
275 * then reset the CPU.
276 */
277 void
278 cpu_reboot(int howto, char *bootstr)
279 {
280 #ifdef DIAGNOSTIC
281 /* info */
282 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
283 #endif
284
285 /*
286 * If we are still cold then hit the air brakes
287 * and crash to earth fast
288 */
289 if (cold) {
290 doshutdownhooks();
291 printf("The operating system has halted.\n");
292 printf("Please press any key to reboot.\n\n");
293 cngetc();
294 printf("rebooting...\n");
295 cpu_reset();
296 /*NOTREACHED*/
297 }
298
299 /* Disable console buffering */
300 /* cnpollc(1);*/
301
302 /*
303 * If RB_NOSYNC was not specified sync the discs.
304 * Note: Unless cold is set to 1 here, syslogd will die during the
305 * unmount. It looks like syslogd is getting woken up only to find
306 * that it cannot page part of the binary in as the filesystem has
307 * been unmounted.
308 */
309 if (!(howto & RB_NOSYNC))
310 bootsync();
311
312 /* Say NO to interrupts */
313 splhigh();
314
315 /* Do a dump if requested. */
316 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
317 dumpsys();
318
319 /* Run any shutdown hooks */
320 doshutdownhooks();
321
322 /* Make sure IRQ's are disabled */
323 IRQdisable;
324
325 if (howto & RB_HALT) {
326 printf("The operating system has halted.\n");
327 printf("Please press any key to reboot.\n\n");
328 cngetc();
329 }
330
331 printf("rebooting...\n");
332 cpu_reset();
333 /*NOTREACHED*/
334 }
335
336 static inline
337 pd_entry_t *
338 read_ttb(void)
339 {
340 long ttb;
341
342 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
343
344
345 return (pd_entry_t *)(ttb & ~((1<<14)-1));
346 }
347
348 /*
349 * Static device mappings. These peripheral registers are mapped at
350 * fixed virtual addresses very early in initarm() so that we can use
351 * them while booting the kernel, and stay at the same address
352 * throughout whole kernel's life time.
353 *
354 * We use this table twice; once with bootstrap page table, and once
355 * with kernel's page table which we build up in initarm().
356 *
357 * Since we map these registers into the bootstrap page table using
358 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
359 * registers segment-aligned and segment-rounded in order to avoid
360 * using the 2nd page tables.
361 */
362
363 #define _A(a) ((a) & ~L1_S_OFFSET)
364 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
365
366 static const struct pmap_devmap lubbock_devmap[] = {
367 {
368 LUBBOCK_OBIO_VBASE,
369 _A(LUBBOCK_OBIO_PBASE),
370 _S(LUBBOCK_OBIO_SIZE),
371 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
372 },
373 {
374 LUBBOCK_GPIO_VBASE,
375 _A(PXA2X0_GPIO_BASE),
376 _S(PXA250_GPIO_SIZE),
377 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
378 },
379 {
380 LUBBOCK_CLKMAN_VBASE,
381 _A(PXA2X0_CLKMAN_BASE),
382 _S(PXA2X0_CLKMAN_SIZE),
383 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
384 },
385 {
386 LUBBOCK_INTCTL_VBASE,
387 _A(PXA2X0_INTCTL_BASE),
388 _S(PXA2X0_INTCTL_SIZE),
389 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
390 },
391 {
392 LUBBOCK_FFUART_VBASE,
393 _A(PXA2X0_FFUART_BASE),
394 _S(4 * COM_NPORTS),
395 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
396 },
397 {
398 LUBBOCK_BTUART_VBASE,
399 _A(PXA2X0_BTUART_BASE),
400 _S(4 * COM_NPORTS),
401 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
402 },
403
404 {0, 0, 0, 0,}
405 };
406
407 #undef _A
408 #undef _S
409
410 /*
411 * u_int initarm(...)
412 *
413 * Initial entry point on startup. This gets called before main() is
414 * entered.
415 * It should be responsible for setting up everything that must be
416 * in place when main is called.
417 * This includes
418 * Taking a copy of the boot configuration structure.
419 * Initialising the physical console so characters can be printed.
420 * Setting up page tables for the kernel
421 * Relocating the kernel to the bottom of physical memory
422 */
423 u_int
424 initarm(void *arg)
425 {
426 extern vaddr_t xscale_cache_clean_addr;
427 int loop;
428 int loop1;
429 u_int l1pagetable;
430 pv_addr_t kernel_l1pt;
431 paddr_t memstart;
432 psize_t memsize;
433 int led_data = 0;
434 #ifdef DIAGNOSTIC
435 extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
436 #endif
437 #define LEDSTEP_P() ioreg_write(LUBBOCK_OBIO_PBASE+LUBBOCK_HEXLED, led_data++)
438 #define LEDSTEP() hex_led(led_data++)
439
440 /* use physical address until pagetable is set */
441 LEDSTEP_P();
442
443 /* map some peripheral registers at static I/O area */
444 pmap_devmap_bootstrap((vaddr_t)read_ttb(), lubbock_devmap);
445
446 LEDSTEP_P();
447
448 /* start 32.768 kHz OSC */
449 ioreg_write(LUBBOCK_CLKMAN_VBASE + 0x08, 2);
450 /* Get ready for splfoo() */
451 pxa2x0_intr_bootstrap(LUBBOCK_INTCTL_VBASE);
452
453 LEDSTEP();
454
455 /*
456 * Heads up ... Setup the CPU / MMU / TLB functions
457 */
458 if (set_cpufuncs())
459 panic("cpu not recognized!");
460
461 LEDSTEP();
462
463
464 #if 0
465 /* Calibrate the delay loop. */
466 #endif
467
468 /*
469 * Okay, RedBoot has provided us with the following memory map:
470 *
471 * Physical Address Range Description
472 * ----------------------- ----------------------------------
473 * 0x00000000 - 0x01ffffff flash Memory (32MB)
474 * 0x04000000 - 0x05ffffff Application flash Memory (32MB)
475 * 0x08000000 - 0x080000ff I/O baseboard registers
476 * 0x0a000000 - 0x0a0fffff SRAM (1MB)
477 * 0x0c000000 - 0x0c0fffff Ethernet Controller
478 * 0x0e000000 - 0x0e0fffff Ethernet Controller (Attribute)
479 * 0x10000000 - 0x103fffff SA-1111 Companion Chip
480 * 0x14000000 - 0x17ffffff Expansion Card (64MB)
481 * 0x40000000 - 0x480fffff Processor Registers
482 * 0xa0000000 - 0xa3ffffff SDRAM Bank 0 (64MB)
483 *
484 *
485 * Virtual Address Range X C B Description
486 * ----------------------- - - - ----------------------------------
487 * 0x00000000 - 0x00003fff N Y Y SDRAM
488 * 0x00004000 - 0x000fffff N Y N Boot ROM
489 * 0x00100000 - 0x01ffffff N N N Application Flash
490 * 0x04000000 - 0x05ffffff N N N Exp Application Flash
491 * 0x08000000 - 0x080fffff N N N I/O baseboard registers
492 * 0x0a000000 - 0x0a0fffff N N N SRAM
493 * 0x40000000 - 0x480fffff N N N Processor Registers
494 * 0xa0000000 - 0xa000ffff N Y N RedBoot SDRAM
495 * 0xa0017000 - 0xa3ffffff Y Y Y SDRAM
496 * 0xc0000000 - 0xcfffffff Y Y Y Cache Flush Region
497 * (done by this routine)
498 * 0xfd000000 - 0xfd0000ff N N N I/O baseboard registers
499 * 0xfd100000 - 0xfd3fffff N N N Processor Registers.
500 * 0xfd400000 - 0xfd4fffff N N N FF-UART
501 * 0xfd500000 - 0xfd5fffff N N N BT-UART
502 *
503 * RedBoot's first level page table is at 0xa0004000. There
504 * are also 2 second-level tables at 0xa0008000 and
505 * 0xa0008400. We will continue to use them until we switch to
506 * our pagetable by setttb().
507 *
508 */
509
510 /* setup GPIO for BTUART, in case bootloader doesn't take care of it */
511 pxa2x0_gpio_bootstrap(LUBBOCK_GPIO_VBASE);
512 pxa2x0_gpio_set_function(42, GPIO_ALT_FN_1_IN);
513 pxa2x0_gpio_set_function(43, GPIO_ALT_FN_2_OUT);
514 pxa2x0_gpio_set_function(44, GPIO_ALT_FN_1_IN);
515 pxa2x0_gpio_set_function(45, GPIO_ALT_FN_2_OUT);
516
517 /* turn on clock to UART block.
518 XXX: this should not be done here. */
519 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN, CKEN_FFUART|CKEN_BTUART |
520 ioreg_read(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN));
521
522 LEDSTEP();
523
524 consinit();
525 LEDSTEP();
526 #ifdef KGDB
527 kgdb_port_init();
528 LEDSTEP();
529 #endif
530
531
532 /* Talk to the user */
533 printf("\nNetBSD/evbarm (lubbock) booting ...\n");
534
535 /* Tweak memory controller */
536 {
537 /* Modify access timing for CS3 (91c96) */
538
539 uint32_t tmp =
540 ioreg_read(PXA2X0_MEMCTL_BASE+MEMCTL_MSC1);
541 ioreg_write(PXA2X0_MEMCTL_BASE+MEMCTL_MSC1,
542 (tmp & 0xffff) | (0x3881<<16));
543 /* RRR=3, RDN=8, RDF=8
544 * XXX: can be faster?
545 */
546 }
547
548
549 /* Initialize for PCMCIA/CF sockets */
550 {
551 uint32_t tmp;
552
553 /* Activate two sockets.
554 XXX: This code segment should be moved to
555 pcmcia MD attach routine.
556 XXX: These bits should be toggled based on
557 existene of PCMCIA/CF cards
558 */
559 ioreg_write(PXA2X0_MEMCTL_BASE+MEMCTL_MECR,
560 MECR_NOS|MECR_CIT);
561
562 tmp = ioreg_read(LUBBOCK_SACC_PBASE+SACCSBI_SKCR);
563 ioreg_write(LUBBOCK_SACC_PBASE+SACCSBI_SKCR,
564 (tmp & ~(1<<4)) | (1<<0));
565 }
566
567 #if 0
568 /*
569 * Examine the boot args string for options we need to know about
570 * now.
571 */
572 process_kernel_args((char *)nwbootinfo.bt_args);
573 #endif
574
575 {
576 int processor_card_id;
577
578 processor_card_id = 0x000f &
579 ioreg_read(LUBBOCK_OBIO_VBASE+LUBBOCK_MISCRD);
580 switch(processor_card_id){
581 case 0:
582 /* Cotulla */
583 memstart = 0xa0000000;
584 memsize = 0x04000000; /* 64MB */
585 break;
586 case 1:
587 /* XXX: Sabiani */
588 memstart = 0xa0000000;
589 memsize = 0x04000000; /* 64MB */
590 break;
591 default:
592 /* XXX: Unknown */
593 memstart = 0xa0000000;
594 memsize = 0x04000000; /* 64MB */
595 }
596 }
597
598 printf("initarm: Configuring system ...\n");
599
600 /* Fake bootconfig structure for the benefit of pmap.c */
601 /* XXX must make the memory description h/w independent */
602 bootconfig.dramblocks = 1;
603 bootconfig.dram[0].address = memstart;
604 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
605
606 /*
607 * Set up the variables that define the availablilty of
608 * physical memory. For now, we're going to set
609 * physical_freestart to 0xa0200000 (where the kernel
610 * was loaded), and allocate the memory we need downwards.
611 * If we get too close to the page tables that RedBoot
612 * set up, we will panic. We will update physical_freestart
613 * and physical_freeend later to reflect what pmap_bootstrap()
614 * wants to see.
615 *
616 * XXX pmap_bootstrap() needs an enema.
617 */
618 physical_start = bootconfig.dram[0].address;
619 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
620
621 physical_freestart = 0xa0009000UL;
622 physical_freeend = 0xa0200000UL;
623
624 physmem = (physical_end - physical_start) / PAGE_SIZE;
625
626 #ifdef VERBOSE_INIT_ARM
627 /* Tell the user about the memory */
628 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
629 physical_start, physical_end - 1);
630 #endif
631
632 /*
633 * Okay, the kernel starts 2MB in from the bottom of physical
634 * memory. We are going to allocate our bootstrap pages downwards
635 * from there.
636 *
637 * We need to allocate some fixed page tables to get the kernel
638 * going. We allocate one page directory and a number of page
639 * tables and store the physical addresses in the kernel_pt_table
640 * array.
641 *
642 * The kernel page directory must be on a 16K boundary. The page
643 * tables must be on 4K boundaries. What we do is allocate the
644 * page directory on the first 16K boundary that we encounter, and
645 * the page tables on 4K boundaries otherwise. Since we allocate
646 * at least 3 L2 page tables, we are guaranteed to encounter at
647 * least one 16K aligned region.
648 */
649
650 #ifdef VERBOSE_INIT_ARM
651 printf("Allocating page tables\n");
652 #endif
653
654 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
655
656 #ifdef VERBOSE_INIT_ARM
657 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
658 physical_freestart, free_pages, free_pages);
659 #endif
660
661 /* Define a macro to simplify memory allocation */
662 #define valloc_pages(var, np) \
663 alloc_pages((var).pv_pa, (np)); \
664 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
665
666 #define alloc_pages(var, np) \
667 physical_freeend -= ((np) * PAGE_SIZE); \
668 if (physical_freeend < physical_freestart) \
669 panic("initarm: out of memory"); \
670 (var) = physical_freeend; \
671 free_pages -= (np); \
672 memset((char *)(var), 0, ((np) * PAGE_SIZE));
673
674 loop1 = 0;
675 kernel_l1pt.pv_pa = 0;
676 kernel_l1pt.pv_va = 0;
677 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
678 /* Are we 16KB aligned for an L1 ? */
679 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
680 && kernel_l1pt.pv_pa == 0) {
681 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
682 } else {
683 valloc_pages(kernel_pt_table[loop1],
684 L2_TABLE_SIZE / PAGE_SIZE);
685 ++loop1;
686 }
687 }
688
689 /* This should never be able to happen but better confirm that. */
690 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
691 panic("initarm: Failed to align the kernel page directory");
692
693 LEDSTEP();
694
695 /*
696 * Allocate a page for the system page mapped to V0x00000000
697 * This page will just contain the system vectors and can be
698 * shared by all processes.
699 */
700 alloc_pages(systempage.pv_pa, 1);
701
702 /* Allocate stacks for all modes */
703 valloc_pages(irqstack, IRQ_STACK_SIZE);
704 valloc_pages(abtstack, ABT_STACK_SIZE);
705 valloc_pages(undstack, UND_STACK_SIZE);
706 valloc_pages(kernelstack, UPAGES);
707
708 /* Allocate enough pages for cleaning the Mini-Data cache. */
709 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
710 valloc_pages(minidataclean, 1);
711
712 #ifdef VERBOSE_INIT_ARM
713 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
714 irqstack.pv_va);
715 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
716 abtstack.pv_va);
717 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
718 undstack.pv_va);
719 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
720 kernelstack.pv_va);
721 #endif
722
723 /*
724 * XXX Defer this to later so that we can reclaim the memory
725 * XXX used by the RedBoot page tables.
726 */
727 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
728
729 /*
730 * Ok we have allocated physical pages for the primary kernel
731 * page tables
732 */
733
734 #ifdef VERBOSE_INIT_ARM
735 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
736 #endif
737
738 /*
739 * Now we start construction of the L1 page table
740 * We start by mapping the L2 page tables into the L1.
741 * This means that we can replace L1 mappings later on if necessary
742 */
743 l1pagetable = kernel_l1pt.pv_pa;
744
745 /* Map the L2 pages tables in the L1 page table */
746 pmap_link_l2pt(l1pagetable, 0x00000000,
747 &kernel_pt_table[KERNEL_PT_SYS]);
748 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
749 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
750 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
751 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
752 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
753 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
754
755 /* update the top of the kernel VM */
756 pmap_curmaxkvaddr =
757 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
758
759 #ifdef VERBOSE_INIT_ARM
760 printf("Mapping kernel\n");
761 #endif
762
763 /* Now we fill in the L2 pagetable for the kernel static code/data */
764 {
765 extern char etext[], _end[];
766 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
767 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
768 u_int logical;
769
770 textsize = (textsize + PGOFSET) & ~PGOFSET;
771 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
772
773 logical = 0x00200000; /* offset of kernel in RAM */
774
775 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
776 physical_start + logical, textsize,
777 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
778 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
779 physical_start + logical, totalsize - textsize,
780 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
781 }
782
783 #ifdef VERBOSE_INIT_ARM
784 printf("Constructing L2 page tables\n");
785 #endif
786
787 /* Map the stack pages */
788 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
789 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
790 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
791 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
792 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
793 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
794 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
795 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
796
797 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
798 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
799
800 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
801 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
802 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
803 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
804 }
805
806 /* Map the Mini-Data cache clean area. */
807 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
808 minidataclean.pv_pa);
809
810 /* Map the vector page. */
811 #if 1
812 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
813 * cache-clean code there. */
814 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
815 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
816 #else
817 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
818 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
819 #endif
820
821 /*
822 * map integrated peripherals at same address in l1pagetable
823 * so that we can continue to use console.
824 */
825 pmap_devmap_bootstrap(l1pagetable, lubbock_devmap);
826
827 /*
828 * Give the XScale global cache clean code an appropriately
829 * sized chunk of unmapped VA space starting at 0xff000000
830 * (our device mappings end before this address).
831 */
832 xscale_cache_clean_addr = 0xff000000U;
833
834 /*
835 * Now we have the real page tables in place so we can switch to them.
836 * Once this is done we will be running with the REAL kernel page
837 * tables.
838 */
839
840 /*
841 * Update the physical_freestart/physical_freeend/free_pages
842 * variables.
843 */
844 {
845 extern char _end[];
846
847 physical_freestart = physical_start +
848 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
849 KERNEL_BASE);
850 physical_freeend = physical_end;
851 free_pages =
852 (physical_freeend - physical_freestart) / PAGE_SIZE;
853 }
854
855 /* Switch tables */
856 #ifdef VERBOSE_INIT_ARM
857 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
858 physical_freestart, free_pages, free_pages);
859 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
860 #endif
861
862 LEDSTEP();
863
864 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
865 setttb(kernel_l1pt.pv_pa);
866 cpu_tlb_flushID();
867 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
868 LEDSTEP();
869
870 /*
871 * Moved from cpu_startup() as data_abort_handler() references
872 * this during uvm init
873 */
874 proc0paddr = (struct user *)kernelstack.pv_va;
875 lwp0.l_addr = proc0paddr;
876
877 #ifdef VERBOSE_INIT_ARM
878 printf("bootstrap done.\n");
879 #endif
880
881 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
882
883 /*
884 * Pages were allocated during the secondary bootstrap for the
885 * stacks for different CPU modes.
886 * We must now set the r13 registers in the different CPU modes to
887 * point to these stacks.
888 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
889 * of the stack memory.
890 */
891 printf("init subsystems: stacks ");
892
893 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
894 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
895 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
896
897 /*
898 * Well we should set a data abort handler.
899 * Once things get going this will change as we will need a proper
900 * handler.
901 * Until then we will use a handler that just panics but tells us
902 * why.
903 * Initialisation of the vectors will just panic on a data abort.
904 * This just fills in a slightly better one.
905 */
906 printf("vectors ");
907 data_abort_handler_address = (u_int)data_abort_handler;
908 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
909 undefined_handler_address = (u_int)undefinedinstruction_bounce;
910
911 /* Initialise the undefined instruction handlers */
912 printf("undefined ");
913 undefined_init();
914
915 /* Load memory into UVM. */
916 printf("page ");
917 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
918 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
919 atop(physical_freestart), atop(physical_freeend),
920 VM_FREELIST_DEFAULT);
921
922 /* Boot strap pmap telling it where the kernel page table is */
923 printf("pmap ");
924 LEDSTEP();
925 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
926 KERNEL_VM_BASE + KERNEL_VM_SIZE);
927 LEDSTEP();
928
929 #ifdef __HAVE_MEMORY_DISK__
930 md_root_setconf(memory_disk, sizeof memory_disk);
931 #endif
932
933 {
934 uint16_t sw = ioreg16_read(LUBBOCK_OBIO_VBASE+LUBBOCK_USERSW);
935
936 if (0 == (sw & (1<<13))) /* check S19 */
937 boothowto |= RB_KDB;
938 if (0 == (sw & (1<<12))) /* S20 */
939 boothowto |= RB_SINGLE;
940 }
941
942 LEDSTEP();
943
944 #ifdef IPKDB
945 /* Initialise ipkdb */
946 ipkdb_init();
947 if (boothowto & RB_KDB)
948 ipkdb_connect(0);
949 #endif
950
951 #ifdef KGDB
952 if (boothowto & RB_KDB) {
953 kgdb_debug_init = 1;
954 kgdb_connect(1);
955 }
956 #endif
957
958 #ifdef DDB
959 db_machine_init();
960
961 /* Firmware doesn't load symbols. */
962 ddb_init(0, NULL, NULL);
963
964 if (boothowto & RB_KDB)
965 Debugger();
966 #endif
967
968 /* We return the new stack pointer address */
969 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
970 }
971
972 #if 0
973 void
974 process_kernel_args(char *args)
975 {
976
977 boothowto = 0;
978
979 /* Make a local copy of the bootargs */
980 strncpy(bootargs, args, MAX_BOOT_STRING);
981
982 args = bootargs;
983 boot_file = bootargs;
984
985 /* Skip the kernel image filename */
986 while (*args != ' ' && *args != 0)
987 ++args;
988
989 if (*args != 0)
990 *args++ = 0;
991
992 while (*args == ' ')
993 ++args;
994
995 boot_args = args;
996
997 printf("bootfile: %s\n", boot_file);
998 printf("bootargs: %s\n", boot_args);
999
1000 parse_mi_bootargs(boot_args);
1001 }
1002 #endif
1003
1004 #ifdef KGDB
1005 #ifndef KGDB_DEVNAME
1006 #define KGDB_DEVNAME "ffuart"
1007 #endif
1008 const char kgdb_devname[] = KGDB_DEVNAME;
1009
1010 #if (NCOM > 0)
1011 #ifndef KGDB_DEVMODE
1012 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
1013 #endif
1014 int comkgdbmode = KGDB_DEVMODE;
1015 #endif /* NCOM */
1016
1017 #endif /* KGDB */
1018
1019
1020 void
1021 consinit(void)
1022 {
1023 static int consinit_called = 0;
1024 uint32_t ckenreg = ioreg_read(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN);
1025 #if 0
1026 char *console = CONSDEVNAME;
1027 #endif
1028
1029 if (consinit_called != 0)
1030 return;
1031
1032 consinit_called = 1;
1033
1034 #if NCOM > 0
1035
1036 #ifdef FFUARTCONSOLE
1037 /* Check switch. */
1038 if (0 == (ioreg_read(LUBBOCK_OBIO_VBASE+LUBBOCK_USERSW) & (1<<15))) {
1039 /* We don't use FF serial when S17=no-dot position */
1040 }
1041 #ifdef KGDB
1042 else if (0 == strcmp(kgdb_devname, "ffuart")) {
1043 /* port is reserved for kgdb */
1044 }
1045 #endif
1046 else if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
1047 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
1048 #if 0
1049 /* XXX: can't call pxa2x0_clkman_config yet */
1050 pxa2x0_clkman_config(CKEN_FFUART, 1);
1051 #else
1052 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN,
1053 ckenreg|CKEN_FFUART);
1054 #endif
1055
1056 return;
1057 }
1058 #endif /* FFUARTCONSOLE */
1059
1060 #ifdef BTUARTCONSOLE
1061 #ifdef KGDB
1062 if (0 == strcmp(kgdb_devname, "btuart")) {
1063 /* port is reserved for kgdb */
1064 } else
1065 #endif
1066 if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
1067 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
1068 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN,
1069 ckenreg|CKEN_BTUART);
1070 return;
1071 }
1072 #endif /* BTUARTCONSOLE */
1073
1074
1075 #endif /* NCOM */
1076
1077 }
1078
1079 #ifdef KGDB
1080 void
1081 kgdb_port_init(void)
1082 {
1083 #if (NCOM > 0) && defined(COM_PXA2X0)
1084 paddr_t paddr = 0;
1085 uint32_t ckenreg = ioreg_read(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN);
1086
1087 if (0 == strcmp(kgdb_devname, "ffuart")) {
1088 paddr = PXA2X0_FFUART_BASE;
1089 ckenreg |= CKEN_FFUART;
1090 }
1091 else if (0 == strcmp(kgdb_devname, "btuart")) {
1092 paddr = PXA2X0_BTUART_BASE;
1093 ckenreg |= CKEN_BTUART;
1094 }
1095
1096 if (paddr &&
1097 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
1098 kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
1099
1100 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN, ckenreg);
1101 }
1102 #endif
1103 }
1104 #endif
1105
1106 #if 0
1107 /*
1108 * display a number in hex LED.
1109 * a digit is blank when the corresponding bit in arg blank is 1
1110 */
1111 unsigned short led_control_value = 0;
1112
1113 void
1114 hex_led_blank(uint32_t value, int blank)
1115 {
1116 int save = disable_interrupts(I32_bit);
1117
1118 ioreg_write(LUBBOCK_OBIO_VBASE+0x10, value);
1119 led_control_value = (led_control_value & 0xff)
1120 | ((blank & 0xff)<<8);
1121 ioreg_write(LUBBOCK_OBIO_VBASE+0x40, led_control_value);
1122 restore_interrupts(save);
1123 }
1124 #endif
1125