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