lubbock_machdep.c revision 1.10.6.2 1 /* $NetBSD: lubbock_machdep.c,v 1.10.6.2 2006/06/01 22:34:20 kardel 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.10.6.2 2006/06/01 22:34:20 kardel 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 void parse_mi_bootargs(char *args);
246 #endif
247
248 void consinit(void);
249 void kgdb_port_init(void);
250 void change_clock(uint32_t v);
251
252 bs_protos(bs_notimpl);
253
254 #include "com.h"
255 #if NCOM > 0
256 #include <dev/ic/comreg.h>
257 #include <dev/ic/comvar.h>
258 #endif
259
260 #ifndef CONSPEED
261 #define CONSPEED B115200 /* What RedBoot uses */
262 #endif
263 #ifndef CONMODE
264 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
265 #endif
266
267 int comcnspeed = CONSPEED;
268 int comcnmode = CONMODE;
269
270 /*
271 * void cpu_reboot(int howto, char *bootstr)
272 *
273 * Reboots the system
274 *
275 * Deal with any syncing, unmounting, dumping and shutdown hooks,
276 * then reset the CPU.
277 */
278 void
279 cpu_reboot(int howto, char *bootstr)
280 {
281 #ifdef DIAGNOSTIC
282 /* info */
283 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
284 #endif
285
286 /*
287 * If we are still cold then hit the air brakes
288 * and crash to earth fast
289 */
290 if (cold) {
291 doshutdownhooks();
292 printf("The operating system has halted.\n");
293 printf("Please press any key to reboot.\n\n");
294 cngetc();
295 printf("rebooting...\n");
296 cpu_reset();
297 /*NOTREACHED*/
298 }
299
300 /* Disable console buffering */
301 /* cnpollc(1);*/
302
303 /*
304 * If RB_NOSYNC was not specified sync the discs.
305 * Note: Unless cold is set to 1 here, syslogd will die during the
306 * unmount. It looks like syslogd is getting woken up only to find
307 * that it cannot page part of the binary in as the filesystem has
308 * been unmounted.
309 */
310 if (!(howto & RB_NOSYNC))
311 bootsync();
312
313 /* Say NO to interrupts */
314 splhigh();
315
316 /* Do a dump if requested. */
317 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
318 dumpsys();
319
320 /* Run any shutdown hooks */
321 doshutdownhooks();
322
323 /* Make sure IRQ's are disabled */
324 IRQdisable;
325
326 if (howto & RB_HALT) {
327 printf("The operating system has halted.\n");
328 printf("Please press any key to reboot.\n\n");
329 cngetc();
330 }
331
332 printf("rebooting...\n");
333 cpu_reset();
334 /*NOTREACHED*/
335 }
336
337 static inline
338 pd_entry_t *
339 read_ttb(void)
340 {
341 long ttb;
342
343 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
344
345
346 return (pd_entry_t *)(ttb & ~((1<<14)-1));
347 }
348
349 /*
350 * Static device mappings. These peripheral registers are mapped at
351 * fixed virtual addresses very early in initarm() so that we can use
352 * them while booting the kernel, and stay at the same address
353 * throughout whole kernel's life time.
354 *
355 * We use this table twice; once with bootstrap page table, and once
356 * with kernel's page table which we build up in initarm().
357 *
358 * Since we map these registers into the bootstrap page table using
359 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
360 * registers segment-aligned and segment-rounded in order to avoid
361 * using the 2nd page tables.
362 */
363
364 #define _A(a) ((a) & ~L1_S_OFFSET)
365 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
366
367 static const struct pmap_devmap lubbock_devmap[] = {
368 {
369 LUBBOCK_OBIO_VBASE,
370 _A(LUBBOCK_OBIO_PBASE),
371 _S(LUBBOCK_OBIO_SIZE),
372 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
373 },
374 {
375 LUBBOCK_GPIO_VBASE,
376 _A(PXA2X0_GPIO_BASE),
377 _S(PXA250_GPIO_SIZE),
378 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
379 },
380 {
381 LUBBOCK_CLKMAN_VBASE,
382 _A(PXA2X0_CLKMAN_BASE),
383 _S(PXA2X0_CLKMAN_SIZE),
384 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
385 },
386 {
387 LUBBOCK_INTCTL_VBASE,
388 _A(PXA2X0_INTCTL_BASE),
389 _S(PXA2X0_INTCTL_SIZE),
390 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
391 },
392 {
393 LUBBOCK_FFUART_VBASE,
394 _A(PXA2X0_FFUART_BASE),
395 _S(4 * COM_NPORTS),
396 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
397 },
398 {
399 LUBBOCK_BTUART_VBASE,
400 _A(PXA2X0_BTUART_BASE),
401 _S(4 * COM_NPORTS),
402 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
403 },
404
405 {0, 0, 0, 0,}
406 };
407
408 #undef _A
409 #undef _S
410
411 /*
412 * u_int initarm(...)
413 *
414 * Initial entry point on startup. This gets called before main() is
415 * entered.
416 * It should be responsible for setting up everything that must be
417 * in place when main is called.
418 * This includes
419 * Taking a copy of the boot configuration structure.
420 * Initialising the physical console so characters can be printed.
421 * Setting up page tables for the kernel
422 * Relocating the kernel to the bottom of physical memory
423 */
424 u_int
425 initarm(void *arg)
426 {
427 extern vaddr_t xscale_cache_clean_addr;
428 int loop;
429 int loop1;
430 u_int l1pagetable;
431 pv_addr_t kernel_l1pt;
432 paddr_t memstart;
433 psize_t memsize;
434 int led_data = 0;
435 #ifdef DIAGNOSTIC
436 extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
437 #endif
438 #define LEDSTEP_P() ioreg_write(LUBBOCK_OBIO_PBASE+LUBBOCK_HEXLED, led_data++)
439 #define LEDSTEP() hex_led(led_data++)
440
441 /* use physical address until pagetable is set */
442 LEDSTEP_P();
443
444 /* map some peripheral registers at static I/O area */
445 pmap_devmap_bootstrap((vaddr_t)read_ttb(), lubbock_devmap);
446
447 LEDSTEP_P();
448
449 /* start 32.768 kHz OSC */
450 ioreg_write(LUBBOCK_CLKMAN_VBASE + 0x08, 2);
451 /* Get ready for splfoo() */
452 pxa2x0_intr_bootstrap(LUBBOCK_INTCTL_VBASE);
453
454 LEDSTEP();
455
456 /*
457 * Heads up ... Setup the CPU / MMU / TLB functions
458 */
459 if (set_cpufuncs())
460 panic("cpu not recognized!");
461
462 LEDSTEP();
463
464
465 #if 0
466 /* Calibrate the delay loop. */
467 #endif
468
469 /*
470 * Okay, RedBoot has provided us with the following memory map:
471 *
472 * Physical Address Range Description
473 * ----------------------- ----------------------------------
474 * 0x00000000 - 0x01ffffff flash Memory (32MB)
475 * 0x04000000 - 0x05ffffff Application flash Memory (32MB)
476 * 0x08000000 - 0x080000ff I/O baseboard registers
477 * 0x0a000000 - 0x0a0fffff SRAM (1MB)
478 * 0x0c000000 - 0x0c0fffff Ethernet Controller
479 * 0x0e000000 - 0x0e0fffff Ethernet Controller (Attribute)
480 * 0x10000000 - 0x103fffff SA-1111 Companion Chip
481 * 0x14000000 - 0x17ffffff Expansion Card (64MB)
482 * 0x40000000 - 0x480fffff Processor Registers
483 * 0xa0000000 - 0xa3ffffff SDRAM Bank 0 (64MB)
484 *
485 *
486 * Virtual Address Range X C B Description
487 * ----------------------- - - - ----------------------------------
488 * 0x00000000 - 0x00003fff N Y Y SDRAM
489 * 0x00004000 - 0x000fffff N Y N Boot ROM
490 * 0x00100000 - 0x01ffffff N N N Application Flash
491 * 0x04000000 - 0x05ffffff N N N Exp Application Flash
492 * 0x08000000 - 0x080fffff N N N I/O baseboard registers
493 * 0x0a000000 - 0x0a0fffff N N N SRAM
494 * 0x40000000 - 0x480fffff N N N Processor Registers
495 * 0xa0000000 - 0xa000ffff N Y N RedBoot SDRAM
496 * 0xa0017000 - 0xa3ffffff Y Y Y SDRAM
497 * 0xc0000000 - 0xcfffffff Y Y Y Cache Flush Region
498 * (done by this routine)
499 * 0xfd000000 - 0xfd0000ff N N N I/O baseboard registers
500 * 0xfd100000 - 0xfd3fffff N N N Processor Registers.
501 * 0xfd400000 - 0xfd4fffff N N N FF-UART
502 * 0xfd500000 - 0xfd5fffff N N N BT-UART
503 *
504 * RedBoot's first level page table is at 0xa0004000. There
505 * are also 2 second-level tables at 0xa0008000 and
506 * 0xa0008400. We will continue to use them until we switch to
507 * our pagetable by setttb().
508 *
509 */
510
511 /* setup GPIO for BTUART, in case bootloader doesn't take care of it */
512 pxa2x0_gpio_bootstrap(LUBBOCK_GPIO_VBASE);
513 pxa2x0_gpio_set_function(42, GPIO_ALT_FN_1_IN);
514 pxa2x0_gpio_set_function(43, GPIO_ALT_FN_2_OUT);
515 pxa2x0_gpio_set_function(44, GPIO_ALT_FN_1_IN);
516 pxa2x0_gpio_set_function(45, GPIO_ALT_FN_2_OUT);
517
518 /* turn on clock to UART block.
519 XXX: this should not be done here. */
520 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN, CKEN_FFUART|CKEN_BTUART |
521 ioreg_read(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN));
522
523 LEDSTEP();
524
525 consinit();
526 LEDSTEP();
527 #ifdef KGDB
528 kgdb_port_init();
529 LEDSTEP();
530 #endif
531
532
533 /* Talk to the user */
534 printf("\nNetBSD/evbarm (lubbock) booting ...\n");
535
536 /* Tweak memory controller */
537 {
538 /* Modify access timing for CS3 (91c96) */
539
540 uint32_t tmp =
541 ioreg_read(PXA2X0_MEMCTL_BASE+MEMCTL_MSC1);
542 ioreg_write(PXA2X0_MEMCTL_BASE+MEMCTL_MSC1,
543 (tmp & 0xffff) | (0x3881<<16));
544 /* RRR=3, RDN=8, RDF=8
545 * XXX: can be faster?
546 */
547 }
548
549
550 /* Initialize for PCMCIA/CF sockets */
551 {
552 uint32_t tmp;
553
554 /* Activate two sockets.
555 XXX: This code segment should be moved to
556 pcmcia MD attach routine.
557 XXX: These bits should be toggled based on
558 existene of PCMCIA/CF cards
559 */
560 ioreg_write(PXA2X0_MEMCTL_BASE+MEMCTL_MECR,
561 MECR_NOS|MECR_CIT);
562
563 tmp = ioreg_read(LUBBOCK_SACC_PBASE+SACCSBI_SKCR);
564 ioreg_write(LUBBOCK_SACC_PBASE+SACCSBI_SKCR,
565 (tmp & ~(1<<4)) | (1<<0));
566 }
567
568 #if 0
569 /*
570 * Examine the boot args string for options we need to know about
571 * now.
572 */
573 process_kernel_args((char *)nwbootinfo.bt_args);
574 #endif
575
576 {
577 int processor_card_id;
578
579 processor_card_id = 0x000f &
580 ioreg_read(LUBBOCK_OBIO_VBASE+LUBBOCK_MISCRD);
581 switch(processor_card_id){
582 case 0:
583 /* Cotulla */
584 memstart = 0xa0000000;
585 memsize = 0x04000000; /* 64MB */
586 break;
587 case 1:
588 /* XXX: Sabiani */
589 memstart = 0xa0000000;
590 memsize = 0x04000000; /* 64MB */
591 break;
592 default:
593 /* XXX: Unknown */
594 memstart = 0xa0000000;
595 memsize = 0x04000000; /* 64MB */
596 }
597 }
598
599 printf("initarm: Configuring system ...\n");
600
601 /* Fake bootconfig structure for the benefit of pmap.c */
602 /* XXX must make the memory description h/w independant */
603 bootconfig.dramblocks = 1;
604 bootconfig.dram[0].address = memstart;
605 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
606
607 /*
608 * Set up the variables that define the availablilty of
609 * physical memory. For now, we're going to set
610 * physical_freestart to 0xa0200000 (where the kernel
611 * was loaded), and allocate the memory we need downwards.
612 * If we get too close to the page tables that RedBoot
613 * set up, we will panic. We will update physical_freestart
614 * and physical_freeend later to reflect what pmap_bootstrap()
615 * wants to see.
616 *
617 * XXX pmap_bootstrap() needs an enema.
618 */
619 physical_start = bootconfig.dram[0].address;
620 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
621
622 physical_freestart = 0xa0009000UL;
623 physical_freeend = 0xa0200000UL;
624
625 physmem = (physical_end - physical_start) / PAGE_SIZE;
626
627 #ifdef VERBOSE_INIT_ARM
628 /* Tell the user about the memory */
629 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
630 physical_start, physical_end - 1);
631 #endif
632
633 /*
634 * Okay, the kernel starts 2MB in from the bottom of physical
635 * memory. We are going to allocate our bootstrap pages downwards
636 * from there.
637 *
638 * We need to allocate some fixed page tables to get the kernel
639 * going. We allocate one page directory and a number of page
640 * tables and store the physical addresses in the kernel_pt_table
641 * array.
642 *
643 * The kernel page directory must be on a 16K boundary. The page
644 * tables must be on 4K boundaries. What we do is allocate the
645 * page directory on the first 16K boundary that we encounter, and
646 * the page tables on 4K boundaries otherwise. Since we allocate
647 * at least 3 L2 page tables, we are guaranteed to encounter at
648 * least one 16K aligned region.
649 */
650
651 #ifdef VERBOSE_INIT_ARM
652 printf("Allocating page tables\n");
653 #endif
654
655 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
656
657 #ifdef VERBOSE_INIT_ARM
658 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
659 physical_freestart, free_pages, free_pages);
660 #endif
661
662 /* Define a macro to simplify memory allocation */
663 #define valloc_pages(var, np) \
664 alloc_pages((var).pv_pa, (np)); \
665 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
666
667 #define alloc_pages(var, np) \
668 physical_freeend -= ((np) * PAGE_SIZE); \
669 if (physical_freeend < physical_freestart) \
670 panic("initarm: out of memory"); \
671 (var) = physical_freeend; \
672 free_pages -= (np); \
673 memset((char *)(var), 0, ((np) * PAGE_SIZE));
674
675 loop1 = 0;
676 kernel_l1pt.pv_pa = 0;
677 kernel_l1pt.pv_va = 0;
678 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
679 /* Are we 16KB aligned for an L1 ? */
680 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
681 && kernel_l1pt.pv_pa == 0) {
682 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
683 } else {
684 valloc_pages(kernel_pt_table[loop1],
685 L2_TABLE_SIZE / PAGE_SIZE);
686 ++loop1;
687 }
688 }
689
690 /* This should never be able to happen but better confirm that. */
691 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
692 panic("initarm: Failed to align the kernel page directory");
693
694 LEDSTEP();
695
696 /*
697 * Allocate a page for the system page mapped to V0x00000000
698 * This page will just contain the system vectors and can be
699 * shared by all processes.
700 */
701 alloc_pages(systempage.pv_pa, 1);
702
703 /* Allocate stacks for all modes */
704 valloc_pages(irqstack, IRQ_STACK_SIZE);
705 valloc_pages(abtstack, ABT_STACK_SIZE);
706 valloc_pages(undstack, UND_STACK_SIZE);
707 valloc_pages(kernelstack, UPAGES);
708
709 /* Allocate enough pages for cleaning the Mini-Data cache. */
710 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
711 valloc_pages(minidataclean, 1);
712
713 #ifdef VERBOSE_INIT_ARM
714 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
715 irqstack.pv_va);
716 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
717 abtstack.pv_va);
718 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
719 undstack.pv_va);
720 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
721 kernelstack.pv_va);
722 #endif
723
724 /*
725 * XXX Defer this to later so that we can reclaim the memory
726 * XXX used by the RedBoot page tables.
727 */
728 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
729
730 /*
731 * Ok we have allocated physical pages for the primary kernel
732 * page tables
733 */
734
735 #ifdef VERBOSE_INIT_ARM
736 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
737 #endif
738
739 /*
740 * Now we start construction of the L1 page table
741 * We start by mapping the L2 page tables into the L1.
742 * This means that we can replace L1 mappings later on if necessary
743 */
744 l1pagetable = kernel_l1pt.pv_pa;
745
746 /* Map the L2 pages tables in the L1 page table */
747 pmap_link_l2pt(l1pagetable, 0x00000000,
748 &kernel_pt_table[KERNEL_PT_SYS]);
749 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
750 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
751 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
752 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
753 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
754 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
755
756 /* update the top of the kernel VM */
757 pmap_curmaxkvaddr =
758 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
759
760 #ifdef VERBOSE_INIT_ARM
761 printf("Mapping kernel\n");
762 #endif
763
764 /* Now we fill in the L2 pagetable for the kernel static code/data */
765 {
766 extern char etext[], _end[];
767 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
768 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
769 u_int logical;
770
771 textsize = (textsize + PGOFSET) & ~PGOFSET;
772 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
773
774 logical = 0x00200000; /* offset of kernel in RAM */
775
776 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
777 physical_start + logical, textsize,
778 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
779 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
780 physical_start + logical, totalsize - textsize,
781 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
782 }
783
784 #ifdef VERBOSE_INIT_ARM
785 printf("Constructing L2 page tables\n");
786 #endif
787
788 /* Map the stack pages */
789 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
790 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
791 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
792 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
793 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
794 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
795 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
796 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
797
798 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
799 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
800
801 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
802 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
803 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
804 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
805 }
806
807 /* Map the Mini-Data cache clean area. */
808 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
809 minidataclean.pv_pa);
810
811 /* Map the vector page. */
812 #if 1
813 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
814 * cache-clean code there. */
815 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
816 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
817 #else
818 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
819 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
820 #endif
821
822 /*
823 * map integrated peripherals at same address in l1pagetable
824 * so that we can continue to use console.
825 */
826 pmap_devmap_bootstrap(l1pagetable, lubbock_devmap);
827
828 /*
829 * Give the XScale global cache clean code an appropriately
830 * sized chunk of unmapped VA space starting at 0xff000000
831 * (our device mappings end before this address).
832 */
833 xscale_cache_clean_addr = 0xff000000U;
834
835 /*
836 * Now we have the real page tables in place so we can switch to them.
837 * Once this is done we will be running with the REAL kernel page
838 * tables.
839 */
840
841 /*
842 * Update the physical_freestart/physical_freeend/free_pages
843 * variables.
844 */
845 {
846 extern char _end[];
847
848 physical_freestart = physical_start +
849 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
850 KERNEL_BASE);
851 physical_freeend = physical_end;
852 free_pages =
853 (physical_freeend - physical_freestart) / PAGE_SIZE;
854 }
855
856 /* Switch tables */
857 #ifdef VERBOSE_INIT_ARM
858 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
859 physical_freestart, free_pages, free_pages);
860 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
861 #endif
862
863 LEDSTEP();
864
865 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
866 setttb(kernel_l1pt.pv_pa);
867 cpu_tlb_flushID();
868 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
869 LEDSTEP();
870
871 /*
872 * Moved from cpu_startup() as data_abort_handler() references
873 * this during uvm init
874 */
875 proc0paddr = (struct user *)kernelstack.pv_va;
876 lwp0.l_addr = proc0paddr;
877
878 #ifdef VERBOSE_INIT_ARM
879 printf("bootstrap done.\n");
880 #endif
881
882 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
883
884 /*
885 * Pages were allocated during the secondary bootstrap for the
886 * stacks for different CPU modes.
887 * We must now set the r13 registers in the different CPU modes to
888 * point to these stacks.
889 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
890 * of the stack memory.
891 */
892 printf("init subsystems: stacks ");
893
894 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
895 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
896 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
897
898 /*
899 * Well we should set a data abort handler.
900 * Once things get going this will change as we will need a proper
901 * handler.
902 * Until then we will use a handler that just panics but tells us
903 * why.
904 * Initialisation of the vectors will just panic on a data abort.
905 * This just fills in a slightly better one.
906 */
907 printf("vectors ");
908 data_abort_handler_address = (u_int)data_abort_handler;
909 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
910 undefined_handler_address = (u_int)undefinedinstruction_bounce;
911
912 /* Initialise the undefined instruction handlers */
913 printf("undefined ");
914 undefined_init();
915
916 /* Load memory into UVM. */
917 printf("page ");
918 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
919 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
920 atop(physical_freestart), atop(physical_freeend),
921 VM_FREELIST_DEFAULT);
922
923 /* Boot strap pmap telling it where the kernel page table is */
924 printf("pmap ");
925 LEDSTEP();
926 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
927 KERNEL_VM_BASE + KERNEL_VM_SIZE);
928 LEDSTEP();
929
930 #ifdef __HAVE_MEMORY_DISK__
931 md_root_setconf(memory_disk, sizeof memory_disk);
932 #endif
933
934 {
935 uint16_t sw = ioreg16_read(LUBBOCK_OBIO_VBASE+LUBBOCK_USERSW);
936
937 if (0 == (sw & (1<<13))) /* check S19 */
938 boothowto |= RB_KDB;
939 if (0 == (sw & (1<<12))) /* S20 */
940 boothowto |= RB_SINGLE;
941 }
942
943 LEDSTEP();
944
945 #ifdef IPKDB
946 /* Initialise ipkdb */
947 ipkdb_init();
948 if (boothowto & RB_KDB)
949 ipkdb_connect(0);
950 #endif
951
952 #ifdef KGDB
953 if (boothowto & RB_KDB) {
954 kgdb_debug_init = 1;
955 kgdb_connect(1);
956 }
957 #endif
958
959 #ifdef DDB
960 db_machine_init();
961
962 /* Firmware doesn't load symbols. */
963 ddb_init(0, NULL, NULL);
964
965 if (boothowto & RB_KDB)
966 Debugger();
967 #endif
968
969 /* We return the new stack pointer address */
970 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
971 }
972
973 #if 0
974 void
975 process_kernel_args(char *args)
976 {
977
978 boothowto = 0;
979
980 /* Make a local copy of the bootargs */
981 strncpy(bootargs, args, MAX_BOOT_STRING);
982
983 args = bootargs;
984 boot_file = bootargs;
985
986 /* Skip the kernel image filename */
987 while (*args != ' ' && *args != 0)
988 ++args;
989
990 if (*args != 0)
991 *args++ = 0;
992
993 while (*args == ' ')
994 ++args;
995
996 boot_args = args;
997
998 printf("bootfile: %s\n", boot_file);
999 printf("bootargs: %s\n", boot_args);
1000
1001 parse_mi_bootargs(boot_args);
1002 }
1003 #endif
1004
1005 #ifdef KGDB
1006 #ifndef KGDB_DEVNAME
1007 #define KGDB_DEVNAME "ffuart"
1008 #endif
1009 const char kgdb_devname[] = KGDB_DEVNAME;
1010
1011 #if (NCOM > 0)
1012 #ifndef KGDB_DEVMODE
1013 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
1014 #endif
1015 int comkgdbmode = KGDB_DEVMODE;
1016 #endif /* NCOM */
1017
1018 #endif /* KGDB */
1019
1020
1021 void
1022 consinit(void)
1023 {
1024 static int consinit_called = 0;
1025 uint32_t ckenreg = ioreg_read(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN);
1026 #if 0
1027 char *console = CONSDEVNAME;
1028 #endif
1029
1030 if (consinit_called != 0)
1031 return;
1032
1033 consinit_called = 1;
1034
1035 #if NCOM > 0
1036
1037 #ifdef FFUARTCONSOLE
1038 /* Check switch. */
1039 if (0 == (ioreg_read(LUBBOCK_OBIO_VBASE+LUBBOCK_USERSW) & (1<<15))) {
1040 /* We don't use FF serial when S17=no-dot position */
1041 }
1042 #ifdef KGDB
1043 else if (0 == strcmp(kgdb_devname, "ffuart")) {
1044 /* port is reserved for kgdb */
1045 }
1046 #endif
1047 else if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
1048 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
1049 #if 0
1050 /* XXX: can't call pxa2x0_clkman_config yet */
1051 pxa2x0_clkman_config(CKEN_FFUART, 1);
1052 #else
1053 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN,
1054 ckenreg|CKEN_FFUART);
1055 #endif
1056
1057 return;
1058 }
1059 #endif /* FFUARTCONSOLE */
1060
1061 #ifdef BTUARTCONSOLE
1062 #ifdef KGDB
1063 if (0 == strcmp(kgdb_devname, "btuart")) {
1064 /* port is reserved for kgdb */
1065 } else
1066 #endif
1067 if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
1068 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
1069 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN,
1070 ckenreg|CKEN_BTUART);
1071 return;
1072 }
1073 #endif /* BTUARTCONSOLE */
1074
1075
1076 #endif /* NCOM */
1077
1078 }
1079
1080 #ifdef KGDB
1081 void
1082 kgdb_port_init(void)
1083 {
1084 #if (NCOM > 0) && defined(COM_PXA2X0)
1085 paddr_t paddr = 0;
1086 uint32_t ckenreg = ioreg_read(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN);
1087
1088 if (0 == strcmp(kgdb_devname, "ffuart")) {
1089 paddr = PXA2X0_FFUART_BASE;
1090 ckenreg |= CKEN_FFUART;
1091 }
1092 else if (0 == strcmp(kgdb_devname, "btuart")) {
1093 paddr = PXA2X0_BTUART_BASE;
1094 ckenreg |= CKEN_BTUART;
1095 }
1096
1097 if (paddr &&
1098 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
1099 kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
1100
1101 ioreg_write(LUBBOCK_CLKMAN_VBASE+CLKMAN_CKEN, ckenreg);
1102 }
1103 #endif
1104 }
1105 #endif
1106
1107 #if 0
1108 /*
1109 * display a number in hex LED.
1110 * a digit is blank when the corresponding bit in arg blank is 1
1111 */
1112 unsigned short led_control_value = 0;
1113
1114 void
1115 hex_led_blank(uint32_t value, int blank)
1116 {
1117 int save = disable_interrupts(I32_bit);
1118
1119 ioreg_write(LUBBOCK_OBIO_VBASE+0x10, value);
1120 led_control_value = (led_control_value & 0xff)
1121 | ((blank & 0xff)<<8);
1122 ioreg_write(LUBBOCK_OBIO_VBASE+0x40, led_control_value);
1123 restore_interrupts(save);
1124 }
1125 #endif
1126