marvell_machdep.c revision 1.14 1 /* $NetBSD: marvell_machdep.c,v 1.14 2012/08/10 02:33:11 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.14 2012/08/10 02:33:11 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 mvsoc_bootstrap(MARVELL_INTERREGS_VBASE);
298
299 /* map some peripheral registers */
300 pmap_devmap_bootstrap((vaddr_t)read_ttb(), marvell_devmap);
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, if args is valid. */
426 if (u_boot_args[3] != 0) /* XXXXX: need more check?? */
427 strncpy(bootargs, (char *)u_boot_args[3], sizeof(bootargs));
428
429 #ifdef VERBOSE_INIT_ARM
430 printf("initarm: Configuring system ...\n");
431 #endif
432
433 bootconfig.dramblocks = 0;
434 physical_end = physmem = 0;
435 for (cs = MARVELL_TAG_SDRAM_CS0; cs <= MARVELL_TAG_SDRAM_CS3; cs++) {
436 mvsoc_target(cs, &target, &attr, &base, &size);
437 if (size == 0)
438 continue;
439
440 bootconfig.dram[bootconfig.dramblocks].address = base;
441 bootconfig.dram[bootconfig.dramblocks].pages = size / PAGE_SIZE;
442
443 if (base != physical_end)
444 panic("memory hole not support");
445
446 physical_end += size;
447 physmem += size / PAGE_SIZE;
448
449 bootconfig.dramblocks++;
450 }
451
452 /*
453 * Set up the variables that define the availablilty of
454 * physical memory. For now, we're going to set
455 * physical_freestart to 0xa0008000 (where the kernel
456 * was loaded), and allocate the memory we need downwards.
457 * If we get too close to the L1 table that we set up, we
458 * will panic. We will update physical_freestart and
459 * physical_freeend later to reflect what pmap_bootstrap()
460 * wants to see.
461 *
462 * XXX pmap_bootstrap() needs an enema.
463 */
464 physical_start = bootconfig.dram[0].address;
465
466 /*
467 * Our kernel is at the beginning of memory, so set our free space to
468 * all the memory after the kernel.
469 */
470 physical_freestart = KERN_VTOPHYS(round_page((vaddr_t)_end));
471 physical_freeend = physical_end;
472
473 #ifdef VERBOSE_INIT_ARM
474 /* Tell the user about the memory */
475 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
476 physical_start, physical_end - 1);
477 #endif
478
479 /*
480 * Okay, the kernel starts 8kB in from the bottom of physical
481 * memory. We are going to allocate our bootstrap pages upwards
482 * from physical_freestart.
483 *
484 * We need to allocate some fixed page tables to get the kernel
485 * going. We allocate one page directory and a number of page
486 * tables and store the physical addresses in the kernel_pt_table
487 * array.
488 *
489 * The kernel page directory must be on a 16K boundary. The page
490 * tables must be on 4K bounaries. What we do is allocate the
491 * page directory on the first 16K boundary that we encounter, and
492 * the page tables on 4K boundaries otherwise. Since we allocate
493 * at least 3 L2 page tables, we are guaranteed to encounter at
494 * least one 16K aligned region.
495 */
496
497 #ifdef VERBOSE_INIT_ARM
498 printf("Allocating page tables\n");
499 #endif
500
501 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
502
503 #ifdef VERBOSE_INIT_ARM
504 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
505 physical_freestart, free_pages, free_pages);
506 #endif
507
508 /*
509 * Define a macro to simplify memory allocation. As we allocate the
510 * memory, make sure that we don't walk over our temporary first level
511 * translation table.
512 */
513 #define valloc_pages(var, np) \
514 (var).pv_pa = physical_freestart; \
515 physical_freestart += ((np) * PAGE_SIZE); \
516 if (physical_freestart > (physical_freeend - L1_TABLE_SIZE)) \
517 panic("initarm: out of memory"); \
518 free_pages -= (np); \
519 (var).pv_va = KERN_PHYSTOV((var).pv_pa); \
520 memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
521
522 pt_index = 0;
523 kernel_l1pt.pv_pa = 0;
524 kernel_l1pt.pv_va = 0;
525 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
526 /* Are we 16KB aligned for an L1 ? */
527 if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0 &&
528 kernel_l1pt.pv_pa == 0) {
529 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
530 } else {
531 valloc_pages(kernel_pt_table[pt_index],
532 L2_TABLE_SIZE / PAGE_SIZE);
533 ++pt_index;
534 }
535 }
536
537 /* This should never be able to happen but better confirm that. */
538 if (!kernel_l1pt.pv_pa ||
539 (kernel_l1pt.pv_pa & (L1_TABLE_SIZE - 1)) != 0)
540 panic("initarm: Failed to align the kernel page directory");
541
542 /*
543 * Allocate a page for the system page mapped to V0x00000000
544 * This page will just contain the system vectors and can be
545 * shared by all processes.
546 */
547 valloc_pages(systempage, 1);
548 systempage.pv_va = 0x00000000;
549
550 /* Allocate stacks for all modes */
551 valloc_pages(irqstack, IRQ_STACK_SIZE);
552 valloc_pages(abtstack, ABT_STACK_SIZE);
553 valloc_pages(undstack, UND_STACK_SIZE);
554 valloc_pages(kernelstack, UPAGES);
555
556 #ifdef VERBOSE_INIT_ARM
557 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
558 irqstack.pv_va);
559 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
560 abtstack.pv_va);
561 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
562 undstack.pv_va);
563 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
564 kernelstack.pv_va);
565 #endif
566
567 /* Allocate the message buffer. */
568 {
569 pv_addr_t msgbuf;
570
571 valloc_pages(msgbuf, round_page(MSGBUFSIZE) / PAGE_SIZE);
572 msgbufphys = msgbuf.pv_pa;
573 }
574
575 /*
576 * Ok we have allocated physical pages for the primary kernel
577 * page tables
578 */
579
580 #ifdef VERBOSE_INIT_ARM
581 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
582 #endif
583
584 /*
585 * Now we start construction of the L1 page table
586 * We start by mapping the L2 page tables into the L1.
587 * This means that we can replace L1 mappings later on if necessary
588 */
589 l1pagetable = kernel_l1pt.pv_va;
590
591 /* Map the L2 pages tables in the L1 page table */
592 pmap_link_l2pt(l1pagetable, 0x00000000,
593 &kernel_pt_table[KERNEL_PT_SYS]);
594 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
595 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
596 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
597 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
598 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
599 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
600
601 /* update the top of the kernel VM */
602 pmap_curmaxkvaddr =
603 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
604
605 #ifdef VERBOSE_INIT_ARM
606 printf("Mapping kernel\n");
607 #endif
608
609 /* Now we fill in the L2 pagetable for the kernel static code/data */
610 {
611 extern char etext[], _end[];
612 size_t textsize = (uintptr_t)etext - KERNEL_TEXT_BASE;
613 size_t totalsize = (uintptr_t)_end - KERNEL_TEXT_BASE;
614 u_int logical;
615
616 textsize = (textsize + PGOFSET) & ~PGOFSET;
617 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
618
619 logical = 0x00000000; /* offset of kernel in RAM */
620
621 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
622 physical_start + logical, textsize,
623 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
624 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
625 physical_start + logical, totalsize - textsize,
626 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
627 }
628
629 #ifdef VERBOSE_INIT_ARM
630 printf("Constructing L2 page tables\n");
631 #endif
632
633 /* Map the stack pages */
634 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
635 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
636 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
637 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
638 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
639 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
640 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
641 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
642
643 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
644 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
645
646 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop)
647 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
648 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
649 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
650
651 /* Map the vector page. */
652 pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa,
653 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
654
655 /*
656 * Map integrated peripherals at same address in first level page
657 * table so that we can continue to use console.
658 */
659 pmap_devmap_bootstrap(l1pagetable, marvell_devmap);
660
661 /*
662 * Now we have the real page tables in place so we can switch to them.
663 * Once this is done we will be running with the REAL kernel page
664 * tables.
665 */
666
667 /* Switch tables */
668 #ifdef VERBOSE_INIT_ARM
669 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
670 #endif
671
672 cpu_setttb(kernel_l1pt.pv_pa);
673 cpu_tlb_flushID();
674 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
675
676 /*
677 * Moved from cpu_startup() as data_abort_handler() references
678 * this during uvm init.
679 */
680 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
681
682 #ifdef VERBOSE_INIT_ARM
683 printf("bootstrap done.\n");
684 #endif
685
686 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
687
688 /*
689 * Pages were allocated during the secondary bootstrap for the
690 * stacks for different CPU modes.
691 * We must now set the r13 registers in the different CPU modes to
692 * point to these stacks.
693 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
694 * of the stack memory.
695 */
696 #ifdef VERBOSE_INIT_ARM
697 printf("init subsystems: stacks ");
698 #endif
699
700 set_stackptr(PSR_IRQ32_MODE,
701 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
702 set_stackptr(PSR_ABT32_MODE,
703 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
704 set_stackptr(PSR_UND32_MODE,
705 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
706
707 /*
708 * Well we should set a data abort handler.
709 * Once things get going this will change as we will need a proper
710 * handler.
711 * Until then we will use a handler that just panics but tells us
712 * why.
713 * Initialisation of the vectors will just panic on a data abort.
714 * This just fills in a slightly better one.
715 */
716 #ifdef VERBOSE_INIT_ARM
717 printf("vectors ");
718 #endif
719 data_abort_handler_address = (u_int)data_abort_handler;
720 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
721 undefined_handler_address = (u_int)undefinedinstruction_bounce;
722
723 /* Initialise the undefined instruction handlers */
724 #ifdef VERBOSE_INIT_ARM
725 printf("undefined ");
726 #endif
727 undefined_init();
728
729 /* Load memory into UVM. */
730 #ifdef VERBOSE_INIT_ARM
731 printf("page ");
732 #endif
733 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
734 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
735 atop(physical_freestart), atop(physical_freeend),
736 VM_FREELIST_DEFAULT);
737
738 /* Boot strap pmap telling it where the kernel page table is */
739 #ifdef VERBOSE_INIT_ARM
740 printf("pmap ");
741 #endif
742 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
743
744 #ifdef VERBOSE_INIT_ARM
745 printf("done.\n");
746 #endif
747
748 #ifdef __HAVE_MEMORY_DISK__
749 md_root_setconf(memory_disk, sizeof memory_disk);
750 #endif
751
752 boot_args = bootargs;
753 parse_mi_bootargs(boot_args);
754
755 #ifdef BOOTHOWTO
756 boothowto |= BOOTHOWTO;
757 #endif
758
759 #ifdef KGDB
760 if (boothowto & RB_KDB) {
761 kgdb_debug_init = 1;
762 kgdb_connect(1);
763 }
764 #endif
765
766 #ifdef DDB
767 db_machine_init();
768 if (boothowto & RB_KDB)
769 Debugger();
770 #endif
771
772 /* we've a specific device_register routine */
773 evbarm_device_register = marvell_device_register;
774
775 /* We return the new stack pointer address */
776 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
777 }
778
779 void
780 consinit(void)
781 {
782 static int consinit_called = 0;
783
784 if (consinit_called != 0)
785 return;
786
787 consinit_called = 1;
788
789 #if NCOM > 0
790 {
791 extern int mvuart_cnattach(bus_space_tag_t, bus_addr_t, int,
792 uint32_t, int);
793
794 if (mvuart_cnattach(&mvsoc_bs_tag,
795 MARVELL_INTERREGS_VBASE + MVSOC_COM0_BASE,
796 comcnspeed, mvTclk, comcnmode))
797 panic("can't init serial console");
798 }
799 #else
800 panic("serial console not configured");
801 #endif
802 }
803
804
805 static void
806 marvell_device_register(device_t dev, void *aux)
807 {
808 prop_dictionary_t dict = device_properties(dev);
809
810 #if NCOM > 0
811 if (device_is_a(dev, "com") &&
812 device_is_a(device_parent(dev), "mvsoc"))
813 prop_dictionary_set_uint32(dict, "frequency", mvTclk);
814 #endif
815 if (device_is_a(dev, "gtidmac"))
816 prop_dictionary_set_uint32(dict,
817 "dmb_speed", mvTclk * sizeof(uint32_t)); /* XXXXXX */
818 #if NGTPCI > 0 && defined(ORION)
819 if (device_is_a(dev, "gtpci")) {
820 extern struct bus_space
821 orion_pci_io_bs_tag, orion_pci_mem_bs_tag;
822 extern struct arm32_pci_chipset arm32_gtpci_chipset;
823
824 prop_data_t io_bs_tag, mem_bs_tag, pc;
825 prop_array_t int2gpp;
826 prop_number_t gpp;
827 uint64_t start, end;
828 int i, j;
829 static struct {
830 const char *boardtype;
831 int pin[PCI_INTERRUPT_PIN_MAX];
832 } hints[] = {
833 { "kuronas_x4",
834 { 11, PCI_INTERRUPT_PIN_NONE } },
835
836 { NULL,
837 { PCI_INTERRUPT_PIN_NONE } },
838 };
839
840 arm32_gtpci_chipset.pc_conf_v = device_private(dev);
841 arm32_gtpci_chipset.pc_intr_v = device_private(dev);
842
843 io_bs_tag = prop_data_create_data_nocopy(
844 &orion_pci_io_bs_tag, sizeof(struct bus_space));
845 KASSERT(io_bs_tag != NULL);
846 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
847 prop_object_release(io_bs_tag);
848 mem_bs_tag = prop_data_create_data_nocopy(
849 &orion_pci_mem_bs_tag, sizeof(struct bus_space));
850 KASSERT(mem_bs_tag != NULL);
851 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
852 prop_object_release(mem_bs_tag);
853
854 pc = prop_data_create_data_nocopy(&arm32_gtpci_chipset,
855 sizeof(struct arm32_pci_chipset));
856 KASSERT(pc != NULL);
857 prop_dictionary_set(dict, "pci-chipset", pc);
858 prop_object_release(pc);
859
860 marvell_startend_by_tag(ORION_TAG_PCI_IO, &start, &end);
861 prop_dictionary_set_uint64(dict, "iostart", start);
862 prop_dictionary_set_uint64(dict, "ioend", end);
863 marvell_startend_by_tag(ORION_TAG_PCI_MEM, &start, &end);
864 prop_dictionary_set_uint64(dict, "memstart", start);
865 prop_dictionary_set_uint64(dict, "memend", end);
866 prop_dictionary_set_uint32(dict,
867 "cache-line-size", arm_dcache_align);
868
869 /* Setup the hint for interrupt-pin. */
870 #define BDSTR(s) _BDSTR(s)
871 #define _BDSTR(s) #s
872 #define THIS_BOARD(str) (strcmp(str, BDSTR(EVBARM_BOARDTYPE)) == 0)
873 for (i = 0; hints[i].boardtype != NULL; i++)
874 if (THIS_BOARD(hints[i].boardtype))
875 break;
876 if (hints[i].boardtype == NULL)
877 return;
878
879 int2gpp =
880 prop_array_create_with_capacity(PCI_INTERRUPT_PIN_MAX + 1);
881
882 /* first set dummy */
883 gpp = prop_number_create_integer(0);
884 prop_array_add(int2gpp, gpp);
885 prop_object_release(gpp);
886
887 for (j = 0; hints[i].pin[j] != PCI_INTERRUPT_PIN_NONE; j++) {
888 gpp = prop_number_create_integer(hints[i].pin[j]);
889 prop_array_add(int2gpp, gpp);
890 prop_object_release(gpp);
891 }
892 prop_dictionary_set(dict, "int2gpp", int2gpp);
893 }
894 #endif /* NGTPCI > 0 && defined(ORION) */
895 #if NMVPEX > 0
896 if (device_is_a(dev, "mvpex")) {
897 #ifdef ORION
898 extern struct bus_space
899 orion_pex0_io_bs_tag, orion_pex0_mem_bs_tag,
900 orion_pex1_io_bs_tag, orion_pex1_mem_bs_tag;
901 #endif
902 #ifdef KIRKWOOD
903 extern struct bus_space
904 kirkwood_pex_io_bs_tag, kirkwood_pex_mem_bs_tag,
905 kirkwood_pex1_io_bs_tag, kirkwood_pex1_mem_bs_tag;
906 #endif
907 extern struct arm32_pci_chipset arm32_mvpex0_chipset;
908 #if defined(ORION) || defined(KIRKWOOD)
909 extern struct arm32_pci_chipset arm32_mvpex1_chipset;
910
911 struct marvell_attach_args *mva = aux;
912 #endif
913 struct bus_space *mvpex_io_bs_tag, *mvpex_mem_bs_tag;
914 struct arm32_pci_chipset *arm32_mvpex_chipset;
915 prop_data_t io_bs_tag, mem_bs_tag, pc;
916 uint64_t start, end;
917 int iotag, memtag;
918
919 switch (mvsoc_model()) {
920 #ifdef ORION
921 case MARVELL_ORION_1_88F5180N:
922 case MARVELL_ORION_1_88F5181:
923 case MARVELL_ORION_1_88F5182:
924 case MARVELL_ORION_1_88W8660:
925 case MARVELL_ORION_2_88F5281:
926 if (mva->mva_offset == MVSOC_PEX_BASE) {
927 mvpex_io_bs_tag = &orion_pex0_io_bs_tag;
928 mvpex_mem_bs_tag = &orion_pex0_mem_bs_tag;
929 arm32_mvpex_chipset = &arm32_mvpex0_chipset;
930 iotag = ORION_TAG_PEX0_IO;
931 memtag = ORION_TAG_PEX0_MEM;
932 } else {
933 mvpex_io_bs_tag = &orion_pex1_io_bs_tag;
934 mvpex_mem_bs_tag = &orion_pex1_mem_bs_tag;
935 arm32_mvpex_chipset = &arm32_mvpex1_chipset;
936 iotag = ORION_TAG_PEX1_IO;
937 memtag = ORION_TAG_PEX1_MEM;
938 }
939 break;
940 #endif
941
942 #ifdef KIRKWOOD
943 case MARVELL_KIRKWOOD_88F6282:
944 if (mva->mva_offset != MVSOC_PEX_BASE) {
945 mvpex_io_bs_tag = &kirkwood_pex1_io_bs_tag;
946 mvpex_mem_bs_tag = &kirkwood_pex1_mem_bs_tag;
947 arm32_mvpex_chipset = &arm32_mvpex1_chipset;
948 iotag = KIRKWOOD_TAG_PEX1_IO;
949 memtag = KIRKWOOD_TAG_PEX1_MEM;
950 break;
951 }
952
953 /* FALLTHROUGH */
954
955 case MARVELL_KIRKWOOD_88F6180:
956 case MARVELL_KIRKWOOD_88F6192:
957 case MARVELL_KIRKWOOD_88F6281:
958 mvpex_io_bs_tag = &kirkwood_pex_io_bs_tag;
959 mvpex_mem_bs_tag = &kirkwood_pex_mem_bs_tag;
960 arm32_mvpex_chipset = &arm32_mvpex0_chipset;
961 iotag = KIRKWOOD_TAG_PEX_IO;
962 memtag = KIRKWOOD_TAG_PEX_MEM;
963 break;
964 #endif
965
966 default:
967 return;
968 }
969
970 arm32_mvpex_chipset->pc_conf_v = device_private(dev);
971 arm32_mvpex_chipset->pc_intr_v = device_private(dev);
972
973 io_bs_tag = prop_data_create_data_nocopy(
974 mvpex_io_bs_tag, sizeof(struct bus_space));
975 KASSERT(io_bs_tag != NULL);
976 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
977 prop_object_release(io_bs_tag);
978 mem_bs_tag = prop_data_create_data_nocopy(
979 mvpex_mem_bs_tag, sizeof(struct bus_space));
980 KASSERT(mem_bs_tag != NULL);
981 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
982 prop_object_release(mem_bs_tag);
983
984 pc = prop_data_create_data_nocopy(arm32_mvpex_chipset,
985 sizeof(struct arm32_pci_chipset));
986 KASSERT(pc != NULL);
987 prop_dictionary_set(dict, "pci-chipset", pc);
988 prop_object_release(pc);
989
990 marvell_startend_by_tag(iotag, &start, &end);
991 prop_dictionary_set_uint64(dict, "iostart", start);
992 prop_dictionary_set_uint64(dict, "ioend", end);
993 marvell_startend_by_tag(memtag, &start, &end);
994 prop_dictionary_set_uint64(dict, "memstart", start);
995 prop_dictionary_set_uint64(dict, "memend", end);
996 prop_dictionary_set_uint32(dict,
997 "cache-line-size", arm_dcache_align);
998 }
999 #endif
1000 }
1001
1002 #if NGTPCI > 0 || NMVPEX > 0
1003 static void
1004 marvell_startend_by_tag(int tag, uint64_t *start, uint64_t *end)
1005 {
1006 uint32_t base, size;
1007 int win;
1008
1009 win = mvsoc_target(tag, NULL, NULL, &base, &size);
1010 if (size != 0) {
1011 if (win < nremap)
1012 *start = read_mlmbreg(MVSOC_MLMB_WRLR(win)) |
1013 ((read_mlmbreg(MVSOC_MLMB_WRHR(win)) << 16) << 16);
1014 else
1015 *start = base;
1016 *end = *start + size - 1;
1017 }
1018 }
1019 #endif
1020