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