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