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