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