marvell_machdep.c revision 1.11 1 /* $NetBSD: marvell_machdep.c,v 1.11 2012/07/29 00:07:09 matt Exp $ */
2 /*
3 * Copyright (c) 2007, 2008, 2010 KIYOHARA Takashi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: marvell_machdep.c,v 1.11 2012/07/29 00:07:09 matt Exp $");
29
30 #include "opt_evbarm_boardtype.h"
31 #include "opt_ddb.h"
32 #include "opt_pci.h"
33 #include "opt_mvsoc.h"
34 #include "com.h"
35 #include "gtpci.h"
36 #include "mvpex.h"
37
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/reboot.h>
41 #include <sys/systm.h>
42 #include <sys/termios.h>
43
44 #include <prop/proplib.h>
45
46 #include <dev/cons.h>
47 #include <dev/md.h>
48
49 #include <dev/marvell/marvellreg.h>
50 #include <dev/marvell/marvellvar.h>
51 #include <dev/pci/pcireg.h>
52 #include <dev/pci/pcivar.h>
53
54 #include <machine/autoconf.h>
55 #include <machine/bootconfig.h>
56 #include <machine/pci_machdep.h>
57
58 #include <uvm/uvm_extern.h>
59
60 #include <arm/db_machdep.h>
61 #include <arm/undefined.h>
62 #include <arm/arm32/machdep.h>
63
64 #include <arm/marvell/mvsocreg.h>
65 #include <arm/marvell/mvsocvar.h>
66 #include <arm/marvell/orionreg.h>
67 #include <arm/marvell/kirkwoodreg.h>
68 #include <arm/marvell/mvsocgppvar.h>
69
70 #include <evbarm/marvell/marvellreg.h>
71 #include <evbarm/marvell/marvellvar.h>
72
73 #include <ddb/db_extern.h>
74 #include <ddb/db_sym.h>
75
76 #include "ksyms.h"
77
78
79 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
80 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00000000)
81 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
82
83 /*
84 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
85 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
86 */
87 #define KERNEL_VM_SIZE 0x0c000000
88
89 /*
90 * Address to call from cpu_reset() to reset the machine.
91 * This is machine architecture dependent as it varies depending
92 * on where the ROM appears when you turn the MMU off.
93 */
94
95 u_int cpu_reset_address = 0xffff0000;
96
97 /* Define various stack sizes in pages */
98 #define IRQ_STACK_SIZE 1
99 #define ABT_STACK_SIZE 1
100 #ifdef IPKDB
101 #define UND_STACK_SIZE 2
102 #else
103 #define UND_STACK_SIZE 1
104 #endif
105
106 BootConfig bootconfig; /* Boot config storage */
107 static char bootargs[MAX_BOOT_STRING];
108 char *boot_args = NULL;
109
110 vm_offset_t physical_start;
111 vm_offset_t physical_freestart;
112 vm_offset_t physical_freeend;
113 vm_offset_t physical_end;
114 u_int free_pages;
115
116 vm_offset_t msgbufphys;
117
118 extern char _end[];
119
120 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
121 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
122 #define KERNEL_PT_KERNEL_NUM 4
123 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
124 /* Page tables for mapping kernel VM */
125 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
126 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
127
128 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
129
130 /*
131 * Macros to translate between physical and virtual for a subset of the
132 * kernel address space. *Not* for general use.
133 */
134 #define KERNEL_BASE_PHYS physical_start
135 #define KERN_VTOPHYS(va) \
136 ((paddr_t)((vaddr_t)va - KERNEL_BASE + KERNEL_BASE_PHYS))
137 #define KERN_PHYSTOV(pa) \
138 ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE))
139
140
141 #include "com.h"
142 #if NCOM > 0
143 #include <dev/ic/comreg.h>
144 #include <dev/ic/comvar.h>
145 #endif
146
147 #ifndef CONSPEED
148 #define CONSPEED B115200 /* It's a setting of the default of u-boot */
149 #endif
150 #ifndef CONMODE
151 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
152
153 int comcnspeed = CONSPEED;
154 int comcnmode = CONMODE;
155 #endif
156
157 #include "opt_kgdb.h"
158 #ifdef KGDB
159 #include <sys/kgdb.h>
160 #endif
161
162 static void marvell_device_register(device_t, void *);
163 #if NGTPCI > 0 || NMVPEX > 0
164 static void marvell_startend_by_tag(int, uint64_t *, uint64_t *);
165 #endif
166
167 static void
168 marvell_system_reset(void)
169 {
170 /* unmask soft reset */
171 write_mlmbreg(MVSOC_MLMB_RSTOUTNMASKR,
172 MVSOC_MLMB_RSTOUTNMASKR_SOFTRSTOUTEN);
173 /* assert soft reset */
174 write_mlmbreg(MVSOC_MLMB_SSRR, MVSOC_MLMB_SSRR_SYSTEMSOFTRST);
175 /* if we're still running, jump to the reset address */
176 cpu_reset();
177 /*NOTREACHED*/
178 }
179
180 void
181 cpu_reboot(int howto, char *bootstr)
182 {
183
184 /*
185 * If we are still cold then hit the air brakes
186 * and crash to earth fast
187 */
188 if (cold) {
189 doshutdownhooks();
190 printf("The operating system has halted.\r\n");
191 printf("Please press any key to reboot.\r\n");
192 cngetc();
193 printf("rebooting...\r\n");
194 marvell_system_reset();
195 }
196
197 /*
198 * If RB_NOSYNC was not specified sync the discs.
199 * Note: Unless cold is set to 1 here, syslogd will die during the
200 * unmount. It looks like syslogd is getting woken up only to find
201 * that it cannot page part of the binary in as the filesystem has
202 * been unmounted.
203 */
204 if (!(howto & RB_NOSYNC))
205 bootsync();
206
207 /* Say NO to interrupts */
208 splhigh();
209
210 /* Do a dump if requested. */
211 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
212 dumpsys();
213
214 /* Run any shutdown hooks */
215 doshutdownhooks();
216
217 /* Make sure IRQ's are disabled */
218 IRQdisable;
219
220 if (howto & RB_HALT) {
221 printf("The operating system has halted.\r\n");
222 printf("Please press any key to reboot.\r\n");
223 cngetc();
224 }
225
226 printf("rebooting...\r\n");
227 marvell_system_reset();
228
229 /*NOTREACHED*/
230 }
231
232 static inline
233 pd_entry_t *
234 read_ttb(void)
235 {
236 long ttb;
237
238 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
239
240 return (pd_entry_t *)(ttb & ~((1<<14)-1));
241 }
242
243 /*
244 * Static device mappings. These peripheral registers are mapped at
245 * fixed virtual addresses very early in initarm() so that we can use
246 * them while booting the kernel, and stay at the same address
247 * throughout whole kernel's life time.
248 *
249 * We use this table twice; once with bootstrap page table, and once
250 * with kernel's page table which we build up in initarm().
251 *
252 * Since we map these registers into the bootstrap page table using
253 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
254 * registers segment-aligned and segment-rounded in order to avoid
255 * using the 2nd page tables.
256 */
257 #define _A(a) ((a) & ~L1_S_OFFSET)
258 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
259
260 static const struct pmap_devmap marvell_devmap[] = {
261 {
262 MARVELL_INTERREGS_VBASE,
263 _A(MARVELL_INTERREGS_PBASE),
264 _S(MARVELL_INTERREGS_SIZE),
265 VM_PROT_READ|VM_PROT_WRITE,
266 PTE_NOCACHE,
267 },
268
269 { 0, 0, 0, 0, 0 }
270 };
271
272 #undef _A
273 #undef _S
274
275 extern uint32_t *u_boot_args[];
276
277 /*
278 * u_int initarm(...)
279 *
280 * Initial entry point on startup. This gets called before main() is
281 * entered.
282 * It should be responsible for setting up everything that must be
283 * in place when main is called.
284 * This includes
285 * Taking a copy of the boot configuration structure.
286 * Initialising the physical console so characters can be printed.
287 * Setting up page tables for the kernel
288 * Relocating the kernel to the bottom of physical memory
289 */
290 u_int
291 initarm(void *arg)
292 {
293 uint32_t target, attr, base, size;
294 u_int l1pagetable;
295 int loop, pt_index, cs, memtag = 0, iotag = 0, window;
296
297 /* map some peripheral registers */
298 pmap_devmap_bootstrap((vaddr_t)read_ttb(), marvell_devmap);
299
300 mvsoc_bootstrap(MARVELL_INTERREGS_VBASE);
301
302 /* Get ready for splfoo() */
303 switch (mvsoc_model()) {
304 #ifdef ORION
305 case MARVELL_ORION_1_88F1181:
306 case MARVELL_ORION_1_88F5082:
307 case MARVELL_ORION_1_88F5180N:
308 case MARVELL_ORION_1_88F5181:
309 case MARVELL_ORION_1_88F5182:
310 case MARVELL_ORION_1_88F6082:
311 case MARVELL_ORION_1_88F6183:
312 case MARVELL_ORION_1_88W8660:
313 case MARVELL_ORION_2_88F1281:
314 case MARVELL_ORION_2_88F5281:
315 orion_intr_bootstrap();
316
317 memtag = ORION_TAG_PEX0_MEM;
318 iotag = ORION_TAG_PEX0_IO;
319 nwindow = ORION_MLMB_NWINDOW;
320 nremap = ORION_MLMB_NREMAP;
321
322 orion_getclks(MARVELL_INTERREGS_VBASE);
323 break;
324 #endif /* ORION */
325
326 #ifdef KIRKWOOD
327 case MARVELL_KIRKWOOD_88F6180:
328 case MARVELL_KIRKWOOD_88F6192:
329 case MARVELL_KIRKWOOD_88F6281:
330 case MARVELL_KIRKWOOD_88F6282:
331 kirkwood_intr_bootstrap();
332
333 memtag = KIRKWOOD_TAG_PEX_MEM;
334 iotag = KIRKWOOD_TAG_PEX_IO;
335 nwindow = KIRKWOOD_MLMB_NWINDOW;
336 nremap = KIRKWOOD_MLMB_NREMAP;
337
338 kirkwood_getclks(MARVELL_INTERREGS_VBASE);
339 break;
340 #endif /* KIRKWOOD */
341
342 #ifdef MV78XX0
343 case MARVELL_MV78XX0_MV78100:
344 case MARVELL_MV78XX0_MV78200:
345 mv78xx0_intr_bootstrap();
346
347 memtag = MV78XX0_TAG_PEX_MEM;
348 iotag = MV78XX0_TAG_PEX_IO;
349 nwindow = MV78XX0_MLMB_NWINDOW;
350 nremap = MV78XX0_MLMB_NREMAP;
351
352 mv78xx0_getclks(MARVELL_INTERREGS_VBASE);
353 break;
354 #endif /* MV78XX0 */
355
356 default:
357 /* We can't output console here yet... */
358 panic("unknown model...\n");
359
360 /* NOTREACHED */
361 }
362
363 /* Reset PCI-Express space to window register. */
364 window = mvsoc_target(memtag, &target, &attr, NULL, NULL);
365 write_mlmbreg(MVSOC_MLMB_WCR(window),
366 MVSOC_MLMB_WCR_WINEN |
367 MVSOC_MLMB_WCR_TARGET(target) |
368 MVSOC_MLMB_WCR_ATTR(attr) |
369 MVSOC_MLMB_WCR_SIZE(MARVELL_PEXMEM_SIZE));
370 write_mlmbreg(MVSOC_MLMB_WBR(window),
371 MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
372 #ifdef PCI_NETBSD_CONFIGURE
373 if (window < nremap) {
374 write_mlmbreg(MVSOC_MLMB_WRLR(window),
375 MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
376 write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
377 }
378 #endif
379 window = mvsoc_target(iotag, &target, &attr, NULL, NULL);
380 write_mlmbreg(MVSOC_MLMB_WCR(window),
381 MVSOC_MLMB_WCR_WINEN |
382 MVSOC_MLMB_WCR_TARGET(target) |
383 MVSOC_MLMB_WCR_ATTR(attr) |
384 MVSOC_MLMB_WCR_SIZE(MARVELL_PEXIO_SIZE));
385 write_mlmbreg(MVSOC_MLMB_WBR(window),
386 MARVELL_PEXIO_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
387 #ifdef PCI_NETBSD_CONFIGURE
388 if (window < nremap) {
389 write_mlmbreg(MVSOC_MLMB_WRLR(window),
390 MARVELL_PEXIO_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
391 write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
392 }
393 #endif
394
395 /*
396 * Heads up ... Setup the CPU / MMU / TLB functions
397 */
398 if (set_cpufuncs())
399 panic("cpu not recognized!");
400
401 /*
402 * U-Boot doesn't use the virtual memory.
403 *
404 * Physical Address Range Description
405 * ----------------------- ----------------------------------
406 * 0x00000000 - 0x0fffffff SDRAM Bank 0 (max 256MB)
407 * 0x10000000 - 0x1fffffff SDRAM Bank 1 (max 256MB)
408 * 0x20000000 - 0x2fffffff SDRAM Bank 2 (max 256MB)
409 * 0x30000000 - 0x3fffffff SDRAM Bank 3 (max 256MB)
410 * 0xf1000000 - 0xf10fffff SoC Internal Registers
411 */
412
413 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
414
415 consinit();
416
417 /* Talk to the user */
418 #ifndef EVBARM_BOARDTYPE
419 #define EVBARM_BOARDTYPE Marvell
420 #endif
421 #define BDSTR(s) _BDSTR(s)
422 #define _BDSTR(s) #s
423 printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
424
425 /* copy command line U-Boot gave us */
426 strncpy(bootargs, (char *)u_boot_args[3], sizeof(bootargs));
427
428 #ifdef VERBOSE_INIT_ARM
429 printf("initarm: Configuring system ...\n");
430 #endif
431
432 bootconfig.dramblocks = 0;
433 physical_end = physmem = 0;
434 for (cs = MARVELL_TAG_SDRAM_CS0; cs <= MARVELL_TAG_SDRAM_CS3; cs++) {
435 mvsoc_target(cs, &target, &attr, &base, &size);
436 if (size == 0)
437 continue;
438
439 bootconfig.dram[bootconfig.dramblocks].address = base;
440 bootconfig.dram[bootconfig.dramblocks].pages = size / PAGE_SIZE;
441
442 if (base != physical_end)
443 panic("memory hole not support");
444
445 physical_end += size;
446 physmem += size / PAGE_SIZE;
447
448 bootconfig.dramblocks++;
449 }
450
451 /*
452 * Set up the variables that define the availablilty of
453 * physical memory. For now, we're going to set
454 * physical_freestart to 0xa0008000 (where the kernel
455 * was loaded), and allocate the memory we need downwards.
456 * If we get too close to the L1 table that we set up, we
457 * will panic. We will update physical_freestart and
458 * physical_freeend later to reflect what pmap_bootstrap()
459 * wants to see.
460 *
461 * XXX pmap_bootstrap() needs an enema.
462 */
463 physical_start = bootconfig.dram[0].address;
464
465 /*
466 * Our kernel is at the beginning of memory, so set our free space to
467 * all the memory after the kernel.
468 */
469 physical_freestart = KERN_VTOPHYS(round_page((vaddr_t)_end));
470 physical_freeend = physical_end;
471
472 #ifdef VERBOSE_INIT_ARM
473 /* Tell the user about the memory */
474 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
475 physical_start, physical_end - 1);
476 #endif
477
478 /*
479 * Okay, the kernel starts 8kB in from the bottom of physical
480 * memory. We are going to allocate our bootstrap pages upwards
481 * from physical_freestart.
482 *
483 * We need to allocate some fixed page tables to get the kernel
484 * going. We allocate one page directory and a number of page
485 * tables and store the physical addresses in the kernel_pt_table
486 * array.
487 *
488 * The kernel page directory must be on a 16K boundary. The page
489 * tables must be on 4K bounaries. What we do is allocate the
490 * page directory on the first 16K boundary that we encounter, and
491 * the page tables on 4K boundaries otherwise. Since we allocate
492 * at least 3 L2 page tables, we are guaranteed to encounter at
493 * least one 16K aligned region.
494 */
495
496 #ifdef VERBOSE_INIT_ARM
497 printf("Allocating page tables\n");
498 #endif
499
500 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
501
502 #ifdef VERBOSE_INIT_ARM
503 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
504 physical_freestart, free_pages, free_pages);
505 #endif
506
507 /*
508 * Define a macro to simplify memory allocation. As we allocate the
509 * memory, make sure that we don't walk over our temporary first level
510 * translation table.
511 */
512 #define valloc_pages(var, np) \
513 (var).pv_pa = physical_freestart; \
514 physical_freestart += ((np) * PAGE_SIZE); \
515 if (physical_freestart > (physical_freeend - L1_TABLE_SIZE)) \
516 panic("initarm: out of memory"); \
517 free_pages -= (np); \
518 (var).pv_va = KERN_PHYSTOV((var).pv_pa); \
519 memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
520
521 pt_index = 0;
522 kernel_l1pt.pv_pa = 0;
523 kernel_l1pt.pv_va = 0;
524 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
525 /* Are we 16KB aligned for an L1 ? */
526 if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0 &&
527 kernel_l1pt.pv_pa == 0) {
528 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
529 } else {
530 valloc_pages(kernel_pt_table[pt_index],
531 L2_TABLE_SIZE / PAGE_SIZE);
532 ++pt_index;
533 }
534 }
535
536 /* This should never be able to happen but better confirm that. */
537 if (!kernel_l1pt.pv_pa ||
538 (kernel_l1pt.pv_pa & (L1_TABLE_SIZE - 1)) != 0)
539 panic("initarm: Failed to align the kernel page directory");
540
541 /*
542 * Allocate a page for the system page mapped to V0x00000000
543 * This page will just contain the system vectors and can be
544 * shared by all processes.
545 */
546 valloc_pages(systempage, 1);
547 systempage.pv_va = 0x00000000;
548
549 /* Allocate stacks for all modes */
550 valloc_pages(irqstack, IRQ_STACK_SIZE);
551 valloc_pages(abtstack, ABT_STACK_SIZE);
552 valloc_pages(undstack, UND_STACK_SIZE);
553 valloc_pages(kernelstack, UPAGES);
554
555 #ifdef VERBOSE_INIT_ARM
556 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
557 irqstack.pv_va);
558 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
559 abtstack.pv_va);
560 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
561 undstack.pv_va);
562 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
563 kernelstack.pv_va);
564 #endif
565
566 /* Allocate the message buffer. */
567 {
568 pv_addr_t msgbuf;
569
570 valloc_pages(msgbuf, round_page(MSGBUFSIZE) / PAGE_SIZE);
571 msgbufphys = msgbuf.pv_pa;
572 }
573
574 /*
575 * Ok we have allocated physical pages for the primary kernel
576 * page tables
577 */
578
579 #ifdef VERBOSE_INIT_ARM
580 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
581 #endif
582
583 /*
584 * Now we start construction of the L1 page table
585 * We start by mapping the L2 page tables into the L1.
586 * This means that we can replace L1 mappings later on if necessary
587 */
588 l1pagetable = kernel_l1pt.pv_va;
589
590 /* Map the L2 pages tables in the L1 page table */
591 pmap_link_l2pt(l1pagetable, 0x00000000,
592 &kernel_pt_table[KERNEL_PT_SYS]);
593 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
594 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
595 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
596 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
597 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
598 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
599
600 /* update the top of the kernel VM */
601 pmap_curmaxkvaddr =
602 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
603
604 #ifdef VERBOSE_INIT_ARM
605 printf("Mapping kernel\n");
606 #endif
607
608 /* Now we fill in the L2 pagetable for the kernel static code/data */
609 {
610 extern char etext[], _end[];
611 size_t textsize = (uintptr_t)etext - KERNEL_TEXT_BASE;
612 size_t totalsize = (uintptr_t)_end - KERNEL_TEXT_BASE;
613 u_int logical;
614
615 textsize = (textsize + PGOFSET) & ~PGOFSET;
616 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
617
618 logical = 0x00000000; /* offset of kernel in RAM */
619
620 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
621 physical_start + logical, textsize,
622 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
623 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
624 physical_start + logical, totalsize - textsize,
625 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
626 }
627
628 #ifdef VERBOSE_INIT_ARM
629 printf("Constructing L2 page tables\n");
630 #endif
631
632 /* Map the stack pages */
633 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
634 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
635 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
636 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
637 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
638 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
639 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
640 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
641
642 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
643 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
644
645 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop)
646 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
647 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
648 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
649
650 /* Map the vector page. */
651 pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa,
652 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
653
654 /*
655 * Map integrated peripherals at same address in first level page
656 * table so that we can continue to use console.
657 */
658 pmap_devmap_bootstrap(l1pagetable, marvell_devmap);
659
660 /*
661 * Now we have the real page tables in place so we can switch to them.
662 * Once this is done we will be running with the REAL kernel page
663 * tables.
664 */
665
666 /* Switch tables */
667 #ifdef VERBOSE_INIT_ARM
668 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
669 #endif
670
671 cpu_setttb(kernel_l1pt.pv_pa);
672 cpu_tlb_flushID();
673 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
674
675 /*
676 * Moved from cpu_startup() as data_abort_handler() references
677 * this during uvm init.
678 */
679 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
680
681 #ifdef VERBOSE_INIT_ARM
682 printf("bootstrap done.\n");
683 #endif
684
685 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
686
687 /*
688 * Pages were allocated during the secondary bootstrap for the
689 * stacks for different CPU modes.
690 * We must now set the r13 registers in the different CPU modes to
691 * point to these stacks.
692 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
693 * of the stack memory.
694 */
695 #ifdef VERBOSE_INIT_ARM
696 printf("init subsystems: stacks ");
697 #endif
698
699 set_stackptr(PSR_IRQ32_MODE,
700 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
701 set_stackptr(PSR_ABT32_MODE,
702 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
703 set_stackptr(PSR_UND32_MODE,
704 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
705
706 /*
707 * Well we should set a data abort handler.
708 * Once things get going this will change as we will need a proper
709 * handler.
710 * Until then we will use a handler that just panics but tells us
711 * why.
712 * Initialisation of the vectors will just panic on a data abort.
713 * This just fills in a slightly better one.
714 */
715 #ifdef VERBOSE_INIT_ARM
716 printf("vectors ");
717 #endif
718 data_abort_handler_address = (u_int)data_abort_handler;
719 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
720 undefined_handler_address = (u_int)undefinedinstruction_bounce;
721
722 /* Initialise the undefined instruction handlers */
723 #ifdef VERBOSE_INIT_ARM
724 printf("undefined ");
725 #endif
726 undefined_init();
727
728 /* Load memory into UVM. */
729 #ifdef VERBOSE_INIT_ARM
730 printf("page ");
731 #endif
732 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
733 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
734 atop(physical_freestart), atop(physical_freeend),
735 VM_FREELIST_DEFAULT);
736
737 /* Boot strap pmap telling it where the kernel page table is */
738 #ifdef VERBOSE_INIT_ARM
739 printf("pmap ");
740 #endif
741 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
742
743 #ifdef VERBOSE_INIT_ARM
744 printf("done.\n");
745 #endif
746
747 #ifdef __HAVE_MEMORY_DISK__
748 md_root_setconf(memory_disk, sizeof memory_disk);
749 #endif
750
751 boot_args = bootargs;
752 parse_mi_bootargs(boot_args);
753
754 #ifdef BOOTHOWTO
755 boothowto |= BOOTHOWTO;
756 #endif
757
758 #ifdef KGDB
759 if (boothowto & RB_KDB) {
760 kgdb_debug_init = 1;
761 kgdb_connect(1);
762 }
763 #endif
764
765 #ifdef DDB
766 db_machine_init();
767 if (boothowto & RB_KDB)
768 Debugger();
769 #endif
770
771 /* we've a specific device_register routine */
772 evbarm_device_register = marvell_device_register;
773
774 /* We return the new stack pointer address */
775 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
776 }
777
778 void
779 consinit(void)
780 {
781 static int consinit_called = 0;
782
783 if (consinit_called != 0)
784 return;
785
786 consinit_called = 1;
787
788 #if NCOM > 0
789 {
790 extern int mvuart_cnattach(bus_space_tag_t, bus_addr_t, int,
791 uint32_t, int);
792
793 if (mvuart_cnattach(&mvsoc_bs_tag,
794 MARVELL_INTERREGS_VBASE + MVSOC_COM0_BASE,
795 comcnspeed, mvTclk, comcnmode))
796 panic("can't init serial console");
797 }
798 #else
799 panic("serial console not configured");
800 #endif
801 }
802
803
804 static void
805 marvell_device_register(device_t dev, void *aux)
806 {
807 prop_dictionary_t dict = device_properties(dev);
808
809 #if NCOM > 0
810 if (device_is_a(dev, "com") &&
811 device_is_a(device_parent(dev), "mvsoc"))
812 prop_dictionary_set_uint32(dict, "frequency", mvTclk);
813 #endif
814 if (device_is_a(dev, "gtidmac")) {
815 prop_dictionary_set_uint32(dict,
816 "dmb_speed", mvTclk * sizeof(uint32_t)); /* XXXXXX */
817 prop_dictionary_set_uint32(dict,
818 "xore-irq-begin", ORION_IRQ_XOR0);
819 }
820 #if NGTPCI > 0 && defined(ORION)
821 if (device_is_a(dev, "gtpci")) {
822 extern struct bus_space
823 orion_pci_io_bs_tag, orion_pci_mem_bs_tag;
824 extern struct arm32_pci_chipset arm32_gtpci_chipset;
825
826 prop_data_t io_bs_tag, mem_bs_tag, pc;
827 prop_array_t int2gpp;
828 prop_number_t gpp;
829 uint64_t start, end;
830 int i, j;
831 static struct {
832 const char *boardtype;
833 int pin[PCI_INTERRUPT_PIN_MAX];
834 } hints[] = {
835 { "kuronas_x4",
836 { 11, PCI_INTERRUPT_PIN_NONE } },
837
838 { NULL,
839 { PCI_INTERRUPT_PIN_NONE } },
840 };
841
842 arm32_gtpci_chipset.pc_conf_v = device_private(dev);
843 arm32_gtpci_chipset.pc_intr_v = device_private(dev);
844
845 io_bs_tag = prop_data_create_data_nocopy(
846 &orion_pci_io_bs_tag, sizeof(struct bus_space));
847 KASSERT(io_bs_tag != NULL);
848 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
849 prop_object_release(io_bs_tag);
850 mem_bs_tag = prop_data_create_data_nocopy(
851 &orion_pci_mem_bs_tag, sizeof(struct bus_space));
852 KASSERT(mem_bs_tag != NULL);
853 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
854 prop_object_release(mem_bs_tag);
855
856 pc = prop_data_create_data_nocopy(&arm32_gtpci_chipset,
857 sizeof(struct arm32_pci_chipset));
858 KASSERT(pc != NULL);
859 prop_dictionary_set(dict, "pci-chipset", pc);
860 prop_object_release(pc);
861
862 marvell_startend_by_tag(ORION_TAG_PCI_IO, &start, &end);
863 prop_dictionary_set_uint64(dict, "iostart", start);
864 prop_dictionary_set_uint64(dict, "ioend", end);
865 marvell_startend_by_tag(ORION_TAG_PCI_MEM, &start, &end);
866 prop_dictionary_set_uint64(dict, "memstart", start);
867 prop_dictionary_set_uint64(dict, "memend", end);
868 prop_dictionary_set_uint32(dict,
869 "cache-line-size", arm_dcache_align);
870
871 /* Setup the hint for interrupt-pin. */
872 #define BDSTR(s) _BDSTR(s)
873 #define _BDSTR(s) #s
874 #define THIS_BOARD(str) (strcmp(str, BDSTR(EVBARM_BOARDTYPE)) == 0)
875 for (i = 0; hints[i].boardtype != NULL; i++)
876 if (THIS_BOARD(hints[i].boardtype))
877 break;
878 if (hints[i].boardtype == NULL)
879 return;
880
881 int2gpp =
882 prop_array_create_with_capacity(PCI_INTERRUPT_PIN_MAX + 1);
883
884 /* first set dummy */
885 gpp = prop_number_create_integer(0);
886 prop_array_add(int2gpp, gpp);
887 prop_object_release(gpp);
888
889 for (j = 0; hints[i].pin[j] != PCI_INTERRUPT_PIN_NONE; j++) {
890 gpp = prop_number_create_integer(hints[i].pin[j]);
891 prop_array_add(int2gpp, gpp);
892 prop_object_release(gpp);
893 }
894 prop_dictionary_set(dict, "int2gpp", int2gpp);
895 }
896 #endif /* NGTPCI > 0 && defined(ORION) */
897 #if NMVPEX > 0
898 if (device_is_a(dev, "mvpex")) {
899 #ifdef ORION
900 extern struct bus_space
901 orion_pex0_io_bs_tag, orion_pex0_mem_bs_tag,
902 orion_pex1_io_bs_tag, orion_pex1_mem_bs_tag;
903 #endif
904 #ifdef KIRKWOOD
905 extern struct bus_space
906 kirkwood_pex_io_bs_tag, kirkwood_pex_mem_bs_tag,
907 kirkwood_pex1_io_bs_tag, kirkwood_pex1_mem_bs_tag;
908 #endif
909 extern struct arm32_pci_chipset arm32_mvpex0_chipset;
910 #if defined(ORION) || defined(KIRKWOOD)
911 extern struct arm32_pci_chipset arm32_mvpex1_chipset;
912
913 struct marvell_attach_args *mva = aux;
914 #endif
915 struct bus_space *mvpex_io_bs_tag, *mvpex_mem_bs_tag;
916 struct arm32_pci_chipset *arm32_mvpex_chipset;
917 prop_data_t io_bs_tag, mem_bs_tag, pc;
918 uint64_t start, end;
919 int iotag, memtag;
920
921 switch (mvsoc_model()) {
922 #ifdef ORION
923 case MARVELL_ORION_1_88F5180N:
924 case MARVELL_ORION_1_88F5181:
925 case MARVELL_ORION_1_88F5182:
926 case MARVELL_ORION_1_88W8660:
927 case MARVELL_ORION_2_88F5281:
928 if (mva->mva_offset == MVSOC_PEX_BASE) {
929 mvpex_io_bs_tag = &orion_pex0_io_bs_tag;
930 mvpex_mem_bs_tag = &orion_pex0_mem_bs_tag;
931 arm32_mvpex_chipset = &arm32_mvpex0_chipset;
932 iotag = ORION_TAG_PEX0_IO;
933 memtag = ORION_TAG_PEX0_MEM;
934 } else {
935 mvpex_io_bs_tag = &orion_pex1_io_bs_tag;
936 mvpex_mem_bs_tag = &orion_pex1_mem_bs_tag;
937 arm32_mvpex_chipset = &arm32_mvpex1_chipset;
938 iotag = ORION_TAG_PEX1_IO;
939 memtag = ORION_TAG_PEX1_MEM;
940 }
941 break;
942 #endif
943
944 #ifdef KIRKWOOD
945 case MARVELL_KIRKWOOD_88F6282:
946 if (mva->mva_offset != MVSOC_PEX_BASE) {
947 mvpex_io_bs_tag = &kirkwood_pex1_io_bs_tag;
948 mvpex_mem_bs_tag = &kirkwood_pex1_mem_bs_tag;
949 arm32_mvpex_chipset = &arm32_mvpex1_chipset;
950 iotag = KIRKWOOD_TAG_PEX1_IO;
951 memtag = KIRKWOOD_TAG_PEX1_MEM;
952 break;
953 }
954
955 /* FALLTHROUGH */
956
957 case MARVELL_KIRKWOOD_88F6180:
958 case MARVELL_KIRKWOOD_88F6192:
959 case MARVELL_KIRKWOOD_88F6281:
960 mvpex_io_bs_tag = &kirkwood_pex_io_bs_tag;
961 mvpex_mem_bs_tag = &kirkwood_pex_mem_bs_tag;
962 arm32_mvpex_chipset = &arm32_mvpex0_chipset;
963 iotag = KIRKWOOD_TAG_PEX_IO;
964 memtag = KIRKWOOD_TAG_PEX_MEM;
965 break;
966 #endif
967
968 default:
969 return;
970 }
971
972 arm32_mvpex_chipset->pc_conf_v = device_private(dev);
973 arm32_mvpex_chipset->pc_intr_v = device_private(dev);
974
975 io_bs_tag = prop_data_create_data_nocopy(
976 mvpex_io_bs_tag, sizeof(struct bus_space));
977 KASSERT(io_bs_tag != NULL);
978 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
979 prop_object_release(io_bs_tag);
980 mem_bs_tag = prop_data_create_data_nocopy(
981 mvpex_mem_bs_tag, sizeof(struct bus_space));
982 KASSERT(mem_bs_tag != NULL);
983 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
984 prop_object_release(mem_bs_tag);
985
986 pc = prop_data_create_data_nocopy(arm32_mvpex_chipset,
987 sizeof(struct arm32_pci_chipset));
988 KASSERT(pc != NULL);
989 prop_dictionary_set(dict, "pci-chipset", pc);
990 prop_object_release(pc);
991
992 marvell_startend_by_tag(iotag, &start, &end);
993 prop_dictionary_set_uint64(dict, "iostart", start);
994 prop_dictionary_set_uint64(dict, "ioend", end);
995 marvell_startend_by_tag(memtag, &start, &end);
996 prop_dictionary_set_uint64(dict, "memstart", start);
997 prop_dictionary_set_uint64(dict, "memend", end);
998 prop_dictionary_set_uint32(dict,
999 "cache-line-size", arm_dcache_align);
1000 }
1001 #endif
1002 }
1003
1004 #if NGTPCI > 0 || NMVPEX > 0
1005 static void
1006 marvell_startend_by_tag(int tag, uint64_t *start, uint64_t *end)
1007 {
1008 uint32_t base, size;
1009 int win;
1010
1011 win = mvsoc_target(tag, NULL, NULL, &base, &size);
1012 if (size != 0) {
1013 if (win < nremap)
1014 *start = read_mlmbreg(MVSOC_MLMB_WRLR(win)) |
1015 ((read_mlmbreg(MVSOC_MLMB_WRHR(win)) << 16) << 16);
1016 else
1017 *start = base;
1018 *end = *start + size - 1;
1019 }
1020 }
1021 #endif
1022