marvell_machdep.c revision 1.26 1 /* $NetBSD: marvell_machdep.c,v 1.26 2013/12/23 04:12:09 kiyohara 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.26 2013/12/23 04:12:09 kiyohara 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/mv78xx0reg.h>
69 #include <arm/marvell/armadaxpreg.h>
70 #include <arm/marvell/mvsocgppvar.h>
71
72 #include <evbarm/marvell/marvellreg.h>
73 #include <evbarm/marvell/marvellvar.h>
74
75 #include <ddb/db_extern.h>
76 #include <ddb/db_sym.h>
77
78 #include "ksyms.h"
79
80
81 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
82 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00000000)
83 #define KERNEL_VM_BASE (KERNEL_BASE + 0x02000000)
84
85 /*
86 * The range 0xc2000000 - 0xdfffffff is available for kernel VM space
87 * Core-logic registers and I/O mappings occupy 0xfe000000 - 0xffffffff
88 */
89 #define KERNEL_VM_SIZE 0x1e000000
90
91 BootConfig bootconfig; /* Boot config storage */
92 static char bootargs[MAX_BOOT_STRING];
93 char *boot_args = NULL;
94
95 extern int KERNEL_BASE_phys[];
96 extern char _end[];
97
98 /*
99 * Macros to translate between physical and virtual for a subset of the
100 * kernel address space. *Not* for general use.
101 */
102 #define KERNEL_BASE_PHYS physical_start
103 #define KERN_VTOPHYS(va) \
104 ((paddr_t)((vaddr_t)va - KERNEL_BASE + KERNEL_BASE_PHYS))
105 #define KERN_PHYSTOV(pa) \
106 ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE))
107
108
109 #include "com.h"
110 #if NCOM > 0
111 #include <dev/ic/comreg.h>
112 #include <dev/ic/comvar.h>
113 #endif
114
115 #ifndef CONSPEED
116 #define CONSPEED B115200 /* It's a setting of the default of u-boot */
117 #endif
118 #ifndef CONMODE
119 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
120
121 int comcnspeed = CONSPEED;
122 int comcnmode = CONMODE;
123 #endif
124
125 #include "opt_kgdb.h"
126 #ifdef KGDB
127 #include <sys/kgdb.h>
128 #endif
129
130 static void marvell_device_register(device_t, void *);
131 #if NGTPCI > 0 || NMVPEX > 0
132 static void marvell_startend_by_tag(int, uint64_t *, uint64_t *);
133 #endif
134
135 #if defined(ORION) || defined(KIRKWOOD) || defined(MV78XX0)
136 static void
137 marvell_system_reset(void)
138 {
139 /* unmask soft reset */
140 write_mlmbreg(MVSOC_MLMB_RSTOUTNMASKR,
141 MVSOC_MLMB_RSTOUTNMASKR_SOFTRSTOUTEN);
142 /* assert soft reset */
143 write_mlmbreg(MVSOC_MLMB_SSRR, MVSOC_MLMB_SSRR_SYSTEMSOFTRST);
144
145 /* if we're still running, jump to the reset address */
146 cpu_reset_address = 0;
147 cpu_reset_address_paddr = 0xffff0000;
148 cpu_reset();
149 /*NOTREACHED*/
150 }
151 #endif
152
153 #if defined(ARMADAXP)
154 static void
155 armadaxp_system_reset(void)
156 {
157 extern vaddr_t misc_base;
158
159 #define write_miscreg(r, v) (*(volatile uint32_t *)(misc_base + (r)) = (v))
160
161 /* Unmask soft reset */
162 write_miscreg(ARMADAXP_MISC_RSTOUTNMASKR,
163 ARMADAXP_MISC_RSTOUTNMASKR_GLOBALSOFTRSTOUTEN);
164 /* Assert soft reset */
165 write_miscreg(ARMADAXP_MISC_SSRR, ARMADAXP_MISC_SSRR_GLOBALSOFTRST);
166
167 while (1);
168
169 /*NOTREACHED*/
170 }
171 #endif
172
173
174 static inline
175 pd_entry_t *
176 read_ttb(void)
177 {
178 long ttb;
179
180 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
181
182 return (pd_entry_t *)(ttb & ~((1<<14)-1));
183 }
184
185 /*
186 * Static device mappings. These peripheral registers are mapped at
187 * fixed virtual addresses very early in initarm() so that we can use
188 * them while booting the kernel, and stay at the same address
189 * throughout whole kernel's life time.
190 *
191 * We use this table twice; once with bootstrap page table, and once
192 * with kernel's page table which we build up in initarm().
193 *
194 * Since we map these registers into the bootstrap page table using
195 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
196 * registers segment-aligned and segment-rounded in order to avoid
197 * using the 2nd page tables.
198 */
199 #define _A(a) ((a) & ~L1_S_OFFSET)
200 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
201
202 static struct pmap_devmap marvell_devmap[] = {
203 {
204 MARVELL_INTERREGS_VBASE,
205 #if (defined(ORION) || defined(KIRKWOOD) || defined(MV78XX0)) && \
206 defined(ARMADAXP)
207 _A(0x00000000),
208 #else
209 _A(MARVELL_INTERREGS_PBASE),
210 #endif
211 _S(MARVELL_INTERREGS_SIZE),
212 VM_PROT_READ|VM_PROT_WRITE,
213 PTE_NOCACHE,
214 },
215
216 { 0, 0, 0, 0, 0 }
217 };
218
219 extern uint32_t *u_boot_args[];
220
221 /*
222 * u_int initarm(...)
223 *
224 * Initial entry point on startup. This gets called before main() is
225 * entered.
226 * It should be responsible for setting up everything that must be
227 * in place when main is called.
228 * This includes
229 * Taking a copy of the boot configuration structure.
230 * Initialising the physical console so characters can be printed.
231 * Setting up page tables for the kernel
232 * Relocating the kernel to the bottom of physical memory
233 */
234 u_int
235 initarm(void *arg)
236 {
237 uint32_t target, attr, base, size;
238 int cs, memtag = 0, iotag = 0, window;
239
240 mvsoc_bootstrap(MARVELL_INTERREGS_VBASE);
241
242 /*
243 * Heads up ... Setup the CPU / MMU / TLB functions
244 */
245 if (set_cpufuncs())
246 panic("cpu not recognized!");
247
248 #if (defined(ORION) || defined(KIRKWOOD) || defined(MV78XX0)) && \
249 defined(ARMADAXP)
250 int i;
251
252 for (i = 0; marvell_devmap[i].pd_size != 0; i++)
253 if (marvell_devmap[i].pd_va == MARVELL_INTERREGS_VBASE) {
254 marvell_devmap[i].pd_pa = _A(MARVELL_INTERREGS_PBASE);
255 break;
256 }
257 #endif
258
259 /* map some peripheral registers */
260 pmap_devmap_bootstrap((vaddr_t)read_ttb(), marvell_devmap);
261
262 /*
263 * U-Boot doesn't use the virtual memory.
264 *
265 * Physical Address Range Description
266 * ----------------------- ----------------------------------
267 * 0x00000000 - 0x0fffffff SDRAM Bank 0 (max 256MB)
268 * 0x10000000 - 0x1fffffff SDRAM Bank 1 (max 256MB)
269 * 0x20000000 - 0x2fffffff SDRAM Bank 2 (max 256MB)
270 * 0x30000000 - 0x3fffffff SDRAM Bank 3 (max 256MB)
271 * 0xf1000000 - 0xf10fffff SoC Internal Registers
272 */
273
274 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
275
276 /* Get ready for splfoo() */
277 switch (mvsoc_model()) {
278 #ifdef ORION
279 case MARVELL_ORION_1_88F1181:
280 case MARVELL_ORION_1_88F5082:
281 case MARVELL_ORION_1_88F5180N:
282 case MARVELL_ORION_1_88F5181:
283 case MARVELL_ORION_1_88F5182:
284 case MARVELL_ORION_1_88F6082:
285 case MARVELL_ORION_1_88F6183:
286 case MARVELL_ORION_1_88W8660:
287 case MARVELL_ORION_2_88F1281:
288 case MARVELL_ORION_2_88F5281:
289 cpu_reset_address = marvell_system_reset;
290
291 orion_intr_bootstrap();
292
293 memtag = ORION_TAG_PEX0_MEM;
294 iotag = ORION_TAG_PEX0_IO;
295 nwindow = ORION_MLMB_NWINDOW;
296 nremap = ORION_MLMB_NREMAP;
297
298 orion_getclks(MARVELL_INTERREGS_VBASE);
299 break;
300 #endif /* ORION */
301
302 #ifdef KIRKWOOD
303 case MARVELL_KIRKWOOD_88F6180:
304 case MARVELL_KIRKWOOD_88F6192:
305 case MARVELL_KIRKWOOD_88F6281:
306 case MARVELL_KIRKWOOD_88F6282:
307 cpu_reset_address = marvell_system_reset;
308
309 kirkwood_intr_bootstrap();
310
311 memtag = KIRKWOOD_TAG_PEX_MEM;
312 iotag = KIRKWOOD_TAG_PEX_IO;
313 nwindow = KIRKWOOD_MLMB_NWINDOW;
314 nremap = KIRKWOOD_MLMB_NREMAP;
315
316 kirkwood_getclks(MARVELL_INTERREGS_VBASE);
317 mvsoc_clkgating = kirkwood_clkgating;
318 break;
319 #endif /* KIRKWOOD */
320
321 #ifdef MV78XX0
322 case MARVELL_MV78XX0_MV78100:
323 case MARVELL_MV78XX0_MV78200:
324 cpu_reset_address = marvell_system_reset;
325
326 mv78xx0_intr_bootstrap();
327
328 memtag = MV78XX0_TAG_PEX0_MEM;
329 iotag = MV78XX0_TAG_PEX0_IO;
330 nwindow = MV78XX0_MLMB_NWINDOW;
331 nremap = MV78XX0_MLMB_NREMAP;
332
333 mv78xx0_getclks(MARVELL_INTERREGS_VBASE);
334 break;
335 #endif /* MV78XX0 */
336
337 #ifdef ARMADAXP
338 case MARVELL_ARMADAXP_MV78130:
339 case MARVELL_ARMADAXP_MV78160:
340 case MARVELL_ARMADAXP_MV78230:
341 case MARVELL_ARMADAXP_MV78260:
342 case MARVELL_ARMADAXP_MV78460:
343 cpu_reset_address = armadaxp_system_reset;
344
345 armadaxp_intr_bootstrap(MARVELL_INTERREGS_PBASE);
346
347 memtag = ARMADAXP_TAG_PEX00_MEM;
348 iotag = ARMADAXP_TAG_PEX00_IO;
349 nwindow = ARMADAXP_MLMB_NWINDOW;
350 nremap = ARMADAXP_MLMB_NREMAP;
351
352 extern vaddr_t misc_base;
353 misc_base = MARVELL_INTERREGS_VBASE + ARMADAXP_MISC_BASE;
354 armadaxp_getclks();
355 mvsoc_clkgating = armadaxp_clkgating;
356
357 #ifdef L2CACHE_ENABLE
358 /* Initialize L2 Cache */
359 {
360 extern int armadaxp_l2_init(bus_addr_t);
361
362 (void)armadaxp_l2_init(MARVELL_INTERREGS_PBASE);
363 }
364 #endif
365
366 #ifdef AURORA_IO_CACHE_COHERENCY
367 /* Initialize cache coherency */
368 armadaxp_io_coherency_init();
369 #endif
370 break;
371 #endif /* ARMADAXP */
372
373 default:
374 /* We can't output console here yet... */
375 panic("unknown model...\n");
376
377 /* NOTREACHED */
378 }
379
380 consinit();
381
382 /* Talk to the user */
383 #ifndef EVBARM_BOARDTYPE
384 #define EVBARM_BOARDTYPE Marvell
385 #endif
386 #define BDSTR(s) _BDSTR(s)
387 #define _BDSTR(s) #s
388 printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
389
390 /* Reset PCI-Express space to window register. */
391 window = mvsoc_target(memtag, &target, &attr, NULL, NULL);
392 write_mlmbreg(MVSOC_MLMB_WCR(window),
393 MVSOC_MLMB_WCR_WINEN |
394 MVSOC_MLMB_WCR_TARGET(target) |
395 MVSOC_MLMB_WCR_ATTR(attr) |
396 MVSOC_MLMB_WCR_SIZE(MARVELL_PEXMEM_SIZE));
397 write_mlmbreg(MVSOC_MLMB_WBR(window),
398 MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
399 #ifdef PCI_NETBSD_CONFIGURE
400 if (window < nremap) {
401 write_mlmbreg(MVSOC_MLMB_WRLR(window),
402 MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
403 write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
404 }
405 #endif
406 window = mvsoc_target(iotag, &target, &attr, NULL, NULL);
407 write_mlmbreg(MVSOC_MLMB_WCR(window),
408 MVSOC_MLMB_WCR_WINEN |
409 MVSOC_MLMB_WCR_TARGET(target) |
410 MVSOC_MLMB_WCR_ATTR(attr) |
411 MVSOC_MLMB_WCR_SIZE(MARVELL_PEXIO_SIZE));
412 write_mlmbreg(MVSOC_MLMB_WBR(window),
413 MARVELL_PEXIO_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
414 #ifdef PCI_NETBSD_CONFIGURE
415 if (window < nremap) {
416 write_mlmbreg(MVSOC_MLMB_WRLR(window),
417 MARVELL_PEXIO_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
418 write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
419 }
420 #endif
421
422 /* copy command line U-Boot gave us, if args is valid. */
423 if (u_boot_args[3] != 0) /* XXXXX: need more check?? */
424 strncpy(bootargs, (char *)u_boot_args[3], sizeof(bootargs));
425
426 #ifdef VERBOSE_INIT_ARM
427 printf("initarm: Configuring system ...\n");
428 #endif
429
430 bootconfig.dramblocks = 0;
431 paddr_t segment_end;
432 segment_end = physmem = 0;
433 for (cs = MARVELL_TAG_SDRAM_CS0; cs <= MARVELL_TAG_SDRAM_CS3; cs++) {
434 mvsoc_target(cs, &target, &attr, &base, &size);
435 if (size == 0)
436 continue;
437
438 bootconfig.dram[bootconfig.dramblocks].address = base;
439 bootconfig.dram[bootconfig.dramblocks].pages = size / PAGE_SIZE;
440
441 if (base != segment_end)
442 panic("memory hole not support");
443
444 segment_end += size;
445 physmem += size / PAGE_SIZE;
446
447 bootconfig.dramblocks++;
448 }
449
450 arm32_bootmem_init(0, segment_end, (uintptr_t) KERNEL_BASE_phys);
451 arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
452 marvell_devmap, false);
453
454 /* we've a specific device_register routine */
455 evbarm_device_register = marvell_device_register;
456
457 /* parse bootargs from U-Boot */
458 boot_args = bootargs;
459 parse_mi_bootargs(boot_args);
460
461 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
462 }
463
464 void
465 consinit(void)
466 {
467 static int consinit_called = 0;
468
469 if (consinit_called != 0)
470 return;
471
472 consinit_called = 1;
473
474 #if NCOM > 0
475 {
476 extern int mvuart_cnattach(bus_space_tag_t, bus_addr_t, int,
477 uint32_t, int);
478
479 if (mvuart_cnattach(&mvsoc_bs_tag,
480 MARVELL_INTERREGS_PBASE + MVSOC_COM0_BASE,
481 comcnspeed, mvTclk, comcnmode))
482 panic("can't init serial console");
483 }
484 #else
485 panic("serial console not configured");
486 #endif
487 }
488
489
490 static void
491 marvell_device_register(device_t dev, void *aux)
492 {
493 prop_dictionary_t dict = device_properties(dev);
494
495 #if NCOM > 0
496 if (device_is_a(dev, "com") &&
497 device_is_a(device_parent(dev), "mvsoc"))
498 prop_dictionary_set_uint32(dict, "frequency", mvTclk);
499 #endif
500
501 if (device_is_a(dev, "gtidmac"))
502 prop_dictionary_set_uint32(dict,
503 "dmb_speed", mvTclk * sizeof(uint32_t)); /* XXXXXX */
504
505 #if NGTPCI > 0 && defined(ORION)
506 if (device_is_a(dev, "gtpci")) {
507 extern struct bus_space
508 orion_pci_io_bs_tag, orion_pci_mem_bs_tag;
509 extern struct arm32_pci_chipset arm32_gtpci_chipset;
510
511 prop_data_t io_bs_tag, mem_bs_tag, pc;
512 prop_array_t int2gpp;
513 prop_number_t gpp;
514 uint64_t start, end;
515 int i, j;
516 static struct {
517 const char *boardtype;
518 int pin[PCI_INTERRUPT_PIN_MAX];
519 } hints[] = {
520 { "kuronas_x4",
521 { 11, PCI_INTERRUPT_PIN_NONE } },
522
523 { NULL,
524 { PCI_INTERRUPT_PIN_NONE } },
525 };
526
527 arm32_gtpci_chipset.pc_conf_v = device_private(dev);
528 arm32_gtpci_chipset.pc_intr_v = device_private(dev);
529
530 io_bs_tag = prop_data_create_data_nocopy(
531 &orion_pci_io_bs_tag, sizeof(struct bus_space));
532 KASSERT(io_bs_tag != NULL);
533 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
534 prop_object_release(io_bs_tag);
535 mem_bs_tag = prop_data_create_data_nocopy(
536 &orion_pci_mem_bs_tag, sizeof(struct bus_space));
537 KASSERT(mem_bs_tag != NULL);
538 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
539 prop_object_release(mem_bs_tag);
540
541 pc = prop_data_create_data_nocopy(&arm32_gtpci_chipset,
542 sizeof(struct arm32_pci_chipset));
543 KASSERT(pc != NULL);
544 prop_dictionary_set(dict, "pci-chipset", pc);
545 prop_object_release(pc);
546
547 marvell_startend_by_tag(ORION_TAG_PCI_IO, &start, &end);
548 prop_dictionary_set_uint64(dict, "iostart", start);
549 prop_dictionary_set_uint64(dict, "ioend", end);
550 marvell_startend_by_tag(ORION_TAG_PCI_MEM, &start, &end);
551 prop_dictionary_set_uint64(dict, "memstart", start);
552 prop_dictionary_set_uint64(dict, "memend", end);
553 prop_dictionary_set_uint32(dict,
554 "cache-line-size", arm_dcache_align);
555
556 /* Setup the hint for interrupt-pin. */
557 #define BDSTR(s) _BDSTR(s)
558 #define _BDSTR(s) #s
559 #define THIS_BOARD(str) (strcmp(str, BDSTR(EVBARM_BOARDTYPE)) == 0)
560 for (i = 0; hints[i].boardtype != NULL; i++)
561 if (THIS_BOARD(hints[i].boardtype))
562 break;
563 if (hints[i].boardtype == NULL)
564 return;
565
566 int2gpp =
567 prop_array_create_with_capacity(PCI_INTERRUPT_PIN_MAX + 1);
568
569 /* first set dummy */
570 gpp = prop_number_create_integer(0);
571 prop_array_add(int2gpp, gpp);
572 prop_object_release(gpp);
573
574 for (j = 0; hints[i].pin[j] != PCI_INTERRUPT_PIN_NONE; j++) {
575 gpp = prop_number_create_integer(hints[i].pin[j]);
576 prop_array_add(int2gpp, gpp);
577 prop_object_release(gpp);
578 }
579 prop_dictionary_set(dict, "int2gpp", int2gpp);
580 }
581 #endif /* NGTPCI > 0 && defined(ORION) */
582
583 #if NMVPEX > 0
584 if (device_is_a(dev, "mvpex")) {
585 #ifdef ORION
586 extern struct bus_space
587 orion_pex0_io_bs_tag, orion_pex0_mem_bs_tag,
588 orion_pex1_io_bs_tag, orion_pex1_mem_bs_tag;
589 #endif
590 #ifdef KIRKWOOD
591 extern struct bus_space
592 kirkwood_pex_io_bs_tag, kirkwood_pex_mem_bs_tag,
593 kirkwood_pex1_io_bs_tag, kirkwood_pex1_mem_bs_tag;
594 #endif
595 #ifdef ARMADAXP
596 extern struct bus_space
597 armadaxp_pex00_io_bs_tag, armadaxp_pex00_mem_bs_tag,
598 armadaxp_pex01_io_bs_tag, armadaxp_pex01_mem_bs_tag,
599 armadaxp_pex02_io_bs_tag, armadaxp_pex02_mem_bs_tag,
600 armadaxp_pex03_io_bs_tag, armadaxp_pex03_mem_bs_tag,
601 armadaxp_pex2_io_bs_tag, armadaxp_pex2_mem_bs_tag,
602 armadaxp_pex3_io_bs_tag, armadaxp_pex3_mem_bs_tag;
603 int i;
604 #endif
605 extern struct arm32_pci_chipset
606 arm32_mvpex0_chipset, arm32_mvpex1_chipset;
607
608 struct marvell_attach_args *mva = aux;
609 struct bus_space *mvpex_io_bs_tag, *mvpex_mem_bs_tag;
610 struct arm32_pci_chipset *arm32_mvpex_chipset;
611 prop_data_t io_bs_tag, mem_bs_tag, pc;
612 uint64_t start, end;
613 int iotag, memtag;
614
615 switch (mvsoc_model()) {
616 #ifdef ORION
617 case MARVELL_ORION_1_88F5180N:
618 case MARVELL_ORION_1_88F5181:
619 case MARVELL_ORION_1_88F5182:
620 case MARVELL_ORION_1_88W8660:
621 case MARVELL_ORION_2_88F5281:
622 if (mva->mva_offset == MVSOC_PEX_BASE) {
623 mvpex_io_bs_tag = &orion_pex0_io_bs_tag;
624 mvpex_mem_bs_tag = &orion_pex0_mem_bs_tag;
625 arm32_mvpex_chipset = &arm32_mvpex0_chipset;
626 iotag = ORION_TAG_PEX0_IO;
627 memtag = ORION_TAG_PEX0_MEM;
628 } else {
629 mvpex_io_bs_tag = &orion_pex1_io_bs_tag;
630 mvpex_mem_bs_tag = &orion_pex1_mem_bs_tag;
631 arm32_mvpex_chipset = &arm32_mvpex1_chipset;
632 iotag = ORION_TAG_PEX1_IO;
633 memtag = ORION_TAG_PEX1_MEM;
634 }
635 break;
636 #endif
637
638 #ifdef KIRKWOOD
639 case MARVELL_KIRKWOOD_88F6282:
640 if (mva->mva_offset != MVSOC_PEX_BASE) {
641 mvpex_io_bs_tag = &kirkwood_pex1_io_bs_tag;
642 mvpex_mem_bs_tag = &kirkwood_pex1_mem_bs_tag;
643 arm32_mvpex_chipset = &arm32_mvpex1_chipset;
644 iotag = KIRKWOOD_TAG_PEX1_IO;
645 memtag = KIRKWOOD_TAG_PEX1_MEM;
646 break;
647 }
648
649 /* FALLTHROUGH */
650
651 case MARVELL_KIRKWOOD_88F6180:
652 case MARVELL_KIRKWOOD_88F6192:
653 case MARVELL_KIRKWOOD_88F6281:
654 mvpex_io_bs_tag = &kirkwood_pex_io_bs_tag;
655 mvpex_mem_bs_tag = &kirkwood_pex_mem_bs_tag;
656 arm32_mvpex_chipset = &arm32_mvpex0_chipset;
657 iotag = KIRKWOOD_TAG_PEX_IO;
658 memtag = KIRKWOOD_TAG_PEX_MEM;
659 break;
660 #endif
661
662 #ifdef ARMADAXP
663 case MARVELL_ARMADAXP_MV78130:
664 case MARVELL_ARMADAXP_MV78160:
665 case MARVELL_ARMADAXP_MV78230:
666 case MARVELL_ARMADAXP_MV78260:
667 case MARVELL_ARMADAXP_MV78460:
668 {
669 extern struct arm32_pci_chipset
670 arm32_mvpex2_chipset, arm32_mvpex3_chipset,
671 arm32_mvpex4_chipset, arm32_mvpex5_chipset;
672 const struct {
673 bus_size_t offset;
674 struct bus_space *io_bs_tag;
675 struct bus_space *mem_bs_tag;
676 struct arm32_pci_chipset *chipset;
677 int iotag;
678 int memtag;
679 } mvpex_tags[] = {
680 { MVSOC_PEX_BASE,
681 &armadaxp_pex00_io_bs_tag,
682 &armadaxp_pex00_mem_bs_tag,
683 &arm32_mvpex0_chipset,
684 ARMADAXP_TAG_PEX00_IO,
685 ARMADAXP_TAG_PEX00_MEM },
686
687 { ARMADAXP_PEX01_BASE,
688 &armadaxp_pex01_io_bs_tag,
689 &armadaxp_pex01_mem_bs_tag,
690 &arm32_mvpex1_chipset,
691 ARMADAXP_TAG_PEX01_IO,
692 ARMADAXP_TAG_PEX01_MEM },
693
694 { ARMADAXP_PEX02_BASE,
695 &armadaxp_pex02_io_bs_tag,
696 &armadaxp_pex02_mem_bs_tag,
697 &arm32_mvpex2_chipset,
698 ARMADAXP_TAG_PEX02_IO,
699 ARMADAXP_TAG_PEX02_MEM },
700
701 { ARMADAXP_PEX03_BASE,
702 &armadaxp_pex03_io_bs_tag,
703 &armadaxp_pex03_mem_bs_tag,
704 &arm32_mvpex3_chipset,
705 ARMADAXP_TAG_PEX03_IO,
706 ARMADAXP_TAG_PEX03_MEM },
707
708 { ARMADAXP_PEX2_BASE,
709 &armadaxp_pex2_io_bs_tag,
710 &armadaxp_pex2_mem_bs_tag,
711 &arm32_mvpex4_chipset,
712 ARMADAXP_TAG_PEX2_IO,
713 ARMADAXP_TAG_PEX2_MEM },
714
715 { ARMADAXP_PEX3_BASE,
716 &armadaxp_pex3_io_bs_tag,
717 &armadaxp_pex3_mem_bs_tag,
718 &arm32_mvpex5_chipset,
719 ARMADAXP_TAG_PEX3_IO,
720 ARMADAXP_TAG_PEX3_MEM },
721
722 { 0, 0, 0, 0, 0 },
723 };
724
725 for (i = 0; mvpex_tags[i].offset != 0; i++) {
726 if (mva->mva_offset != mvpex_tags[i].offset)
727 continue;
728 break;
729 }
730 if (mvpex_tags[i].offset == 0)
731 return;
732 mvpex_io_bs_tag = mvpex_tags[i].io_bs_tag;
733 mvpex_mem_bs_tag = mvpex_tags[i].mem_bs_tag;
734 arm32_mvpex_chipset = mvpex_tags[i].chipset;
735 iotag = mvpex_tags[i].iotag;
736 memtag = mvpex_tags[i].memtag;
737 break;
738 }
739 #endif
740
741 default:
742 return;
743 }
744
745 arm32_mvpex_chipset->pc_conf_v = device_private(dev);
746 arm32_mvpex_chipset->pc_intr_v = device_private(dev);
747
748 io_bs_tag = prop_data_create_data_nocopy(
749 mvpex_io_bs_tag, sizeof(struct bus_space));
750 KASSERT(io_bs_tag != NULL);
751 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
752 prop_object_release(io_bs_tag);
753 mem_bs_tag = prop_data_create_data_nocopy(
754 mvpex_mem_bs_tag, sizeof(struct bus_space));
755 KASSERT(mem_bs_tag != NULL);
756 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
757 prop_object_release(mem_bs_tag);
758
759 pc = prop_data_create_data_nocopy(arm32_mvpex_chipset,
760 sizeof(struct arm32_pci_chipset));
761 KASSERT(pc != NULL);
762 prop_dictionary_set(dict, "pci-chipset", pc);
763 prop_object_release(pc);
764
765 marvell_startend_by_tag(iotag, &start, &end);
766 prop_dictionary_set_uint64(dict, "iostart", start);
767 prop_dictionary_set_uint64(dict, "ioend", end);
768 marvell_startend_by_tag(memtag, &start, &end);
769 prop_dictionary_set_uint64(dict, "memstart", start);
770 prop_dictionary_set_uint64(dict, "memend", end);
771 prop_dictionary_set_uint32(dict,
772 "cache-line-size", arm_dcache_align);
773 }
774 #endif
775 }
776
777 #if NGTPCI > 0 || NMVPEX > 0
778 static void
779 marvell_startend_by_tag(int tag, uint64_t *start, uint64_t *end)
780 {
781 uint32_t base, size;
782 int win;
783
784 win = mvsoc_target(tag, NULL, NULL, &base, &size);
785 if (size != 0) {
786 if (win < nremap)
787 *start = read_mlmbreg(MVSOC_MLMB_WRLR(win)) |
788 ((read_mlmbreg(MVSOC_MLMB_WRHR(win)) << 16) << 16);
789 else
790 *start = base;
791 *end = *start + size - 1;
792 }
793 }
794 #endif
795