2 * Copyright (C) 2008-2011 MARVELL INTERNATIONAL LTD.
5 * Developed by Semihalf.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of MARVELL nor the names of contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include "opt_global.h"
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/malloc.h>
43 #include <sys/reboot.h>
45 #include <dev/fdt/fdt_common.h>
46 #include <dev/ofw/openfirm.h>
48 #include <machine/bus.h>
49 #include <machine/fdt.h>
50 #include <machine/vmparam.h>
52 #include <arm/mv/mvreg.h>
53 #include <arm/mv/mvvar.h>
54 #include <arm/mv/mvwin.h>
57 MALLOC_DEFINE(M_IDMA, "idma", "idma dma test memory");
65 #define debugf(fmt, args...) do { printf("%s(): ", __func__); \
66 printf(fmt,##args); } while (0)
68 #define debugf(fmt, args...)
77 static int win_eth_can_remap(int i);
80 static int decode_win_cpu_valid(void);
82 static int decode_win_usb_valid(void);
83 static int decode_win_eth_valid(void);
84 static int decode_win_pcie_valid(void);
85 static int decode_win_sata_valid(void);
87 static int decode_win_idma_valid(void);
88 static int decode_win_xor_valid(void);
91 static void decode_win_cpu_setup(void);
93 #ifdef SOC_MV_ARMADAXP
94 static int decode_win_sdram_fixup(void);
96 static void decode_win_usb_setup(u_long);
97 static void decode_win_eth_setup(u_long);
98 static void decode_win_sata_setup(u_long);
100 static void decode_win_idma_setup(u_long);
101 static void decode_win_xor_setup(u_long);
103 static void decode_win_usb_dump(u_long);
104 static void decode_win_eth_dump(u_long base);
105 static void decode_win_idma_dump(u_long base);
106 static void decode_win_xor_dump(u_long base);
108 static int fdt_get_ranges(const char *, void *, int, int *, int *);
110 static int win_cpu_from_dt(void);
111 static int fdt_win_setup(void);
113 static uint32_t dev_mask = 0;
114 static int cpu_wins_no = 0;
115 static int eth_port = 0;
116 static int usb_port = 0;
118 static struct decode_win cpu_win_tbl[MAX_CPU_WIN];
120 const struct decode_win *cpu_wins = cpu_win_tbl;
122 typedef void (*decode_win_setup_t)(u_long);
123 typedef void (*dump_win_t)(u_long);
125 struct soc_node_spec {
127 decode_win_setup_t decode_handler;
128 dump_win_t dump_handler;
131 static struct soc_node_spec soc_nodes[] = {
132 { "mrvl,ge", &decode_win_eth_setup, &decode_win_eth_dump },
133 { "mrvl,usb-ehci", &decode_win_usb_setup, &decode_win_usb_dump },
134 { "mrvl,sata", &decode_win_sata_setup, NULL },
135 { "mrvl,xor", &decode_win_xor_setup, &decode_win_xor_dump },
136 { "mrvl,idma", &decode_win_idma_setup, &decode_win_idma_dump },
137 { "mrvl,pcie", &decode_win_pcie_setup, NULL },
138 { NULL, NULL, NULL },
141 struct fdt_pm_mask_entry fdt_pm_mask_table[] = {
142 { "mrvl,ge", CPU_PM_CTRL_GE(0) },
143 { "mrvl,ge", CPU_PM_CTRL_GE(1) },
144 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(0) },
145 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(1) },
146 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(2) },
147 { "mrvl,xor", CPU_PM_CTRL_XOR },
148 { "mrvl,sata", CPU_PM_CTRL_SATA },
154 pm_is_disabled(uint32_t mask)
156 #if defined(SOC_MV_KIRKWOOD)
157 return (soc_power_ctrl_get(mask) == mask);
159 return (soc_power_ctrl_get(mask) == mask ? 0 : 1);
164 * Disable device using power management register.
165 * 1 - Device Power On
166 * 0 - Device Power Off
167 * Mask can be set in loader.
169 * loader> set hw.pm-disable-mask=0x2
172 * |-------------------------------|
173 * | Device | Kirkwood | Discovery |
174 * |-------------------------------|
175 * | USB0 | 0x00008 | 0x020000 |
176 * |-------------------------------|
177 * | USB1 | - | 0x040000 |
178 * |-------------------------------|
179 * | USB2 | - | 0x080000 |
180 * |-------------------------------|
181 * | GE0 | 0x00001 | 0x000002 |
182 * |-------------------------------|
183 * | GE1 | - | 0x000004 |
184 * |-------------------------------|
185 * | IDMA | - | 0x100000 |
186 * |-------------------------------|
187 * | XOR | 0x10000 | 0x200000 |
188 * |-------------------------------|
189 * | CESA | 0x20000 | 0x400000 |
190 * |-------------------------------|
191 * | SATA | 0x04000 | 0x004000 |
192 * --------------------------------|
193 * This feature can be used only on Kirkwood and Discovery
197 pm_disable_device(int mask)
202 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
203 printf("Power Management Register: 0%x\n", reg);
206 soc_power_ctrl_set(reg);
207 printf("Device %x is disabled\n", mask);
209 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
210 printf("Power Management Register: 0%x\n", reg);
215 fdt_pm(phandle_t node)
217 uint32_t cpu_pm_ctrl;
221 cpu_pm_ctrl = read_cpu_ctrl(CPU_PM_CTRL);
222 for (i = 0; fdt_pm_mask_table[i].compat != NULL; i++) {
223 if (dev_mask & (1 << i))
226 compat = fdt_is_compatible(node, fdt_pm_mask_table[i].compat);
227 #if defined(SOC_MV_KIRKWOOD)
228 if (compat && (cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
229 dev_mask |= (1 << i);
233 dev_mask |= (1 << i);
237 if (compat && (~cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
238 dev_mask |= (1 << i);
242 dev_mask |= (1 << i);
252 read_cpu_ctrl(uint32_t reg)
255 return (bus_space_read_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg));
259 write_cpu_ctrl(uint32_t reg, uint32_t val)
262 bus_space_write_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg, val);
265 #if defined(SOC_MV_ARMADAXP)
267 read_cpu_mp_clocks(uint32_t reg)
270 return (bus_space_read_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg));
274 write_cpu_mp_clocks(uint32_t reg, uint32_t val)
277 bus_space_write_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg, val);
281 read_cpu_misc(uint32_t reg)
284 return (bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE, reg));
288 write_cpu_misc(uint32_t reg, uint32_t val)
291 bus_space_write_4(fdtbus_bs_tag, MV_MISC_BASE, reg, val);
299 #if defined(SOC_MV_ARMADAXP)
300 write_cpu_misc(RSTOUTn_MASK, SOFT_RST_OUT_EN);
301 write_cpu_misc(SYSTEM_SOFT_RESET, SYS_SOFT_RST);
303 write_cpu_ctrl(RSTOUTn_MASK, SOFT_RST_OUT_EN);
304 write_cpu_ctrl(SYSTEM_SOFT_RESET, SYS_SOFT_RST);
320 case MV_DEV_88RC8180:
321 case MV_DEV_MV78100_Z0:
323 __asm __volatile("mrc p15, 1, %0, c15, c1, 0" : "=r" (ef));
327 __asm __volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (ef));
331 printf("This ARM Core does not support any extra features\n");
338 * Get the power status of device. This feature is only supported on
339 * Kirkwood and Discovery SoCs.
342 soc_power_ctrl_get(uint32_t mask)
345 #if !defined(SOC_MV_ORION) && !defined(SOC_MV_LOKIPLUS) && !defined(SOC_MV_FREY)
346 if (mask != CPU_PM_CTRL_NONE)
347 mask &= read_cpu_ctrl(CPU_PM_CTRL);
356 * Set the power status of device. This feature is only supported on
357 * Kirkwood and Discovery SoCs.
360 soc_power_ctrl_set(uint32_t mask)
363 #if !defined(SOC_MV_ORION) && !defined(SOC_MV_LOKIPLUS)
364 if (mask != CPU_PM_CTRL_NONE)
365 write_cpu_ctrl(CPU_PM_CTRL, mask);
370 soc_id(uint32_t *dev, uint32_t *rev)
374 * Notice: system identifiers are available in the registers range of
375 * PCIE controller, so using this function is only allowed (and
376 * possible) after the internal registers range has been mapped in via
377 * pmap_devmap_bootstrap().
379 *dev = bus_space_read_4(fdtbus_bs_tag, MV_PCIE_BASE, 0) >> 16;
380 *rev = bus_space_read_4(fdtbus_bs_tag, MV_PCIE_BASE, 8) & 0xff;
386 uint32_t d, r, size, mode;
394 printf("(0x%4x:0x%02x) ", d, r);
399 dev = "Marvell 88F5181";
404 dev = "Marvell 88F5182";
409 dev = "Marvell 88F5281";
418 dev = "Marvell 88F6281";
426 case MV_DEV_88RC8180:
427 dev = "Marvell 88RC8180";
429 case MV_DEV_88RC9480:
430 dev = "Marvell 88RC9480";
432 case MV_DEV_88RC9580:
433 dev = "Marvell 88RC9580";
436 dev = "Marvell 88F6781";
441 dev = "Marvell 88F6282";
447 case MV_DEV_MV78100_Z0:
448 dev = "Marvell MV78100 Z0";
451 dev = "Marvell MV78100";
454 dev = "Marvell MV78160";
457 dev = "Marvell MV78260";
460 dev = "Marvell MV78460";
469 printf(" rev %s", rev);
470 printf(", TClock %dMHz\n", get_tclk() / 1000 / 1000);
472 mode = read_cpu_ctrl(CPU_CONFIG);
473 printf(" Instruction cache prefetch %s, data cache prefetch %s\n",
474 (mode & CPU_CONFIG_IC_PREF) ? "enabled" : "disabled",
475 (mode & CPU_CONFIG_DC_PREF) ? "enabled" : "disabled");
480 mode = read_cpu_ctrl(CPU_L2_CONFIG) & CPU_L2_CONFIG_MODE;
481 printf(" 256KB 4-way set-associative %s unified L2 cache\n",
482 mode ? "write-through" : "write-back");
485 mode = read_cpu_ctrl(CPU_CONTROL);
486 size = mode & CPU_CONTROL_L2_SIZE;
487 mode = mode & CPU_CONTROL_L2_MODE;
488 printf(" %s set-associative %s unified L2 cache\n",
489 size ? "256KB 4-way" : "512KB 8-way",
490 mode ? "write-through" : "write-back");
498 platform_identify(void *dummy)
504 * XXX Board identification e.g. read out from FPGA or similar should
508 SYSINIT(platform_identify, SI_SUB_CPU, SI_ORDER_SECOND, platform_identify,
513 mv_enter_debugger(void *dummy)
516 if (boothowto & RB_KDB)
517 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
519 SYSINIT(mv_enter_debugger, SI_SUB_CPU, SI_ORDER_ANY, mv_enter_debugger, NULL);
529 TUNABLE_INT_FETCH("hw.pm-disable-mask", &mask);
532 pm_disable_device(mask);
534 /* Retrieve data about physical addresses from device tree. */
535 if ((err = win_cpu_from_dt()) != 0)
538 /* Retrieve our ID: some windows facilities vary between SoC models */
541 #ifdef SOC_MV_ARMADAXP
542 if ((err = decode_win_sdram_fixup()) != 0)
547 if (!decode_win_cpu_valid() || !decode_win_usb_valid() ||
548 !decode_win_eth_valid() || !decode_win_idma_valid() ||
549 !decode_win_pcie_valid() || !decode_win_sata_valid() ||
550 !decode_win_xor_valid())
553 decode_win_cpu_setup();
555 if (!decode_win_usb_valid() ||
556 !decode_win_eth_valid() || !decode_win_idma_valid() ||
557 !decode_win_pcie_valid() || !decode_win_sata_valid() ||
558 !decode_win_xor_valid())
562 soc_dump_decode_win();
566 if ((err = fdt_win_setup()) != 0)
572 /**************************************************************************
573 * Decode windows registers accessors
574 **************************************************************************/
575 #if !defined(SOC_MV_FREY)
576 WIN_REG_IDX_RD(win_cpu, cr, MV_WIN_CPU_CTRL, MV_MBUS_BRIDGE_BASE)
577 WIN_REG_IDX_RD(win_cpu, br, MV_WIN_CPU_BASE, MV_MBUS_BRIDGE_BASE)
578 WIN_REG_IDX_RD(win_cpu, remap_l, MV_WIN_CPU_REMAP_LO, MV_MBUS_BRIDGE_BASE)
579 WIN_REG_IDX_RD(win_cpu, remap_h, MV_WIN_CPU_REMAP_HI, MV_MBUS_BRIDGE_BASE)
580 WIN_REG_IDX_WR(win_cpu, cr, MV_WIN_CPU_CTRL, MV_MBUS_BRIDGE_BASE)
581 WIN_REG_IDX_WR(win_cpu, br, MV_WIN_CPU_BASE, MV_MBUS_BRIDGE_BASE)
582 WIN_REG_IDX_WR(win_cpu, remap_l, MV_WIN_CPU_REMAP_LO, MV_MBUS_BRIDGE_BASE)
583 WIN_REG_IDX_WR(win_cpu, remap_h, MV_WIN_CPU_REMAP_HI, MV_MBUS_BRIDGE_BASE)
586 WIN_REG_BASE_IDX_RD(win_usb, cr, MV_WIN_USB_CTRL)
587 WIN_REG_BASE_IDX_RD(win_usb, br, MV_WIN_USB_BASE)
588 WIN_REG_BASE_IDX_WR(win_usb, cr, MV_WIN_USB_CTRL)
589 WIN_REG_BASE_IDX_WR(win_usb, br, MV_WIN_USB_BASE)
591 WIN_REG_BASE_IDX_RD(win_eth, br, MV_WIN_ETH_BASE)
592 WIN_REG_BASE_IDX_RD(win_eth, sz, MV_WIN_ETH_SIZE)
593 WIN_REG_BASE_IDX_RD(win_eth, har, MV_WIN_ETH_REMAP)
594 WIN_REG_BASE_IDX_WR(win_eth, br, MV_WIN_ETH_BASE)
595 WIN_REG_BASE_IDX_WR(win_eth, sz, MV_WIN_ETH_SIZE)
596 WIN_REG_BASE_IDX_WR(win_eth, har, MV_WIN_ETH_REMAP)
598 WIN_REG_BASE_IDX_RD2(win_xor, br, MV_WIN_XOR_BASE)
599 WIN_REG_BASE_IDX_RD2(win_xor, sz, MV_WIN_XOR_SIZE)
600 WIN_REG_BASE_IDX_RD2(win_xor, har, MV_WIN_XOR_REMAP)
601 WIN_REG_BASE_IDX_RD2(win_xor, ctrl, MV_WIN_XOR_CTRL)
602 WIN_REG_BASE_IDX_WR2(win_xor, br, MV_WIN_XOR_BASE)
603 WIN_REG_BASE_IDX_WR2(win_xor, sz, MV_WIN_XOR_SIZE)
604 WIN_REG_BASE_IDX_WR2(win_xor, har, MV_WIN_XOR_REMAP)
605 WIN_REG_BASE_IDX_WR2(win_xor, ctrl, MV_WIN_XOR_CTRL)
607 WIN_REG_BASE_RD(win_eth, bare, 0x290)
608 WIN_REG_BASE_RD(win_eth, epap, 0x294)
609 WIN_REG_BASE_WR(win_eth, bare, 0x290)
610 WIN_REG_BASE_WR(win_eth, epap, 0x294)
612 WIN_REG_BASE_IDX_RD(win_pcie, cr, MV_WIN_PCIE_CTRL);
613 WIN_REG_BASE_IDX_RD(win_pcie, br, MV_WIN_PCIE_BASE);
614 WIN_REG_BASE_IDX_RD(win_pcie, remap, MV_WIN_PCIE_REMAP);
615 WIN_REG_BASE_IDX_WR(win_pcie, cr, MV_WIN_PCIE_CTRL);
616 WIN_REG_BASE_IDX_WR(win_pcie, br, MV_WIN_PCIE_BASE);
617 WIN_REG_BASE_IDX_WR(win_pcie, remap, MV_WIN_PCIE_REMAP);
618 WIN_REG_BASE_IDX_RD(pcie_bar, br, MV_PCIE_BAR_BASE);
619 WIN_REG_BASE_IDX_WR(pcie_bar, br, MV_PCIE_BAR_BASE);
620 WIN_REG_BASE_IDX_WR(pcie_bar, brh, MV_PCIE_BAR_BASE_H);
621 WIN_REG_BASE_IDX_WR(pcie_bar, cr, MV_PCIE_BAR_CTRL);
623 WIN_REG_BASE_IDX_RD(win_idma, br, MV_WIN_IDMA_BASE)
624 WIN_REG_BASE_IDX_RD(win_idma, sz, MV_WIN_IDMA_SIZE)
625 WIN_REG_BASE_IDX_RD(win_idma, har, MV_WIN_IDMA_REMAP)
626 WIN_REG_BASE_IDX_RD(win_idma, cap, MV_WIN_IDMA_CAP)
627 WIN_REG_BASE_IDX_WR(win_idma, br, MV_WIN_IDMA_BASE)
628 WIN_REG_BASE_IDX_WR(win_idma, sz, MV_WIN_IDMA_SIZE)
629 WIN_REG_BASE_IDX_WR(win_idma, har, MV_WIN_IDMA_REMAP)
630 WIN_REG_BASE_IDX_WR(win_idma, cap, MV_WIN_IDMA_CAP)
631 WIN_REG_BASE_RD(win_idma, bare, 0xa80)
632 WIN_REG_BASE_WR(win_idma, bare, 0xa80)
634 WIN_REG_BASE_IDX_RD(win_sata, cr, MV_WIN_SATA_CTRL);
635 WIN_REG_BASE_IDX_RD(win_sata, br, MV_WIN_SATA_BASE);
636 WIN_REG_BASE_IDX_WR(win_sata, cr, MV_WIN_SATA_CTRL);
637 WIN_REG_BASE_IDX_WR(win_sata, br, MV_WIN_SATA_BASE);
639 WIN_REG_IDX_RD(ddr, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
640 WIN_REG_IDX_RD(ddr, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
641 WIN_REG_IDX_WR(ddr, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
642 WIN_REG_IDX_WR(ddr, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
645 * On 88F6781 (Dove) SoC DDR Controller is accessed through
646 * single MBUS <-> AXI bridge. In this case we provide emulated
647 * ddr_br_read() and ddr_sz_read() functions to keep compatibility
648 * with common decoding windows setup code.
651 static inline uint32_t ddr_br_read(int i)
655 /* Read Memory Address Map Register for CS i */
656 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
658 /* Return CS i base address */
659 return (mmap & 0xFF000000);
662 static inline uint32_t ddr_sz_read(int i)
666 /* Read Memory Address Map Register for CS i */
667 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
669 /* Extract size of CS space in 64kB units */
670 size = (1 << ((mmap >> 16) & 0x0F));
672 /* Return CS size and enable/disable status */
673 return (((size - 1) << 16) | (mmap & 0x01));
677 #if !defined(SOC_MV_FREY)
678 /**************************************************************************
679 * Decode windows helper routines
680 **************************************************************************/
682 soc_dump_decode_win(void)
689 for (i = 0; i < MV_WIN_CPU_MAX; i++) {
690 printf("CPU window#%d: c 0x%08x, b 0x%08x", i,
694 if (win_cpu_can_remap(i))
695 printf(", rl 0x%08x, rh 0x%08x",
696 win_cpu_remap_l_read(i),
697 win_cpu_remap_h_read(i));
701 printf("Internal regs base: 0x%08x\n",
702 bus_space_read_4(fdtbus_bs_tag, MV_INTREGS_BASE, 0));
704 for (i = 0; i < MV_WIN_DDR_MAX; i++)
705 printf("DDR CS#%d: b 0x%08x, s 0x%08x\n", i,
706 ddr_br_read(i), ddr_sz_read(i));
709 /**************************************************************************
710 * CPU windows routines
711 **************************************************************************/
713 win_cpu_can_remap(int i)
719 /* Depending on the SoC certain windows have remap capability */
720 if ((dev == MV_DEV_88F5182 && i < 2) ||
721 (dev == MV_DEV_88F5281 && i < 4) ||
722 (dev == MV_DEV_88F6281 && i < 4) ||
723 (dev == MV_DEV_88F6282 && i < 4) ||
724 (dev == MV_DEV_88RC8180 && i < 2) ||
725 (dev == MV_DEV_88F6781 && i < 4) ||
726 (dev == MV_DEV_MV78100_Z0 && i < 8) ||
727 ((dev & MV_DEV_FAMILY_MASK) == MV_DEV_DISCOVERY && i < 8))
733 /* XXX This should check for overlapping remap fields too.. */
735 decode_win_overlap(int win, int win_no, const struct decode_win *wintab)
737 const struct decode_win *tab;
742 for (i = 0; i < win_no; i++, tab++) {
747 if ((tab->base + tab->size - 1) < (wintab + win)->base)
750 else if (((wintab + win)->base + (wintab + win)->size - 1) <
761 decode_win_cpu_valid(void)
766 if (cpu_wins_no > MV_WIN_CPU_MAX) {
767 printf("CPU windows: too many entries: %d\n", cpu_wins_no);
772 for (i = 0; i < cpu_wins_no; i++) {
774 if (cpu_wins[i].target == 0) {
775 printf("CPU window#%d: DDR target window is not "
776 "supposed to be reprogrammed!\n", i);
780 if (cpu_wins[i].remap != ~0 && win_cpu_can_remap(i) != 1) {
781 printf("CPU window#%d: not capable of remapping, but "
782 "val 0x%08x defined\n", i, cpu_wins[i].remap);
786 s = cpu_wins[i].size;
787 b = cpu_wins[i].base;
789 if (s > (0xFFFFFFFF - b + 1)) {
791 * XXX this boundary check should account for 64bit
794 printf("CPU window#%d: no space for size 0x%08x at "
795 "0x%08x\n", i, s, b);
800 if (b != (b & ~(s - 1))) {
801 printf("CPU window#%d: address 0x%08x is not aligned "
802 "to 0x%08x\n", i, b, s);
807 j = decode_win_overlap(i, cpu_wins_no, &cpu_wins[0]);
809 printf("CPU window#%d: (0x%08x - 0x%08x) overlaps "
810 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
812 cpu_wins[j].base + cpu_wins[j].size - 1);
821 decode_win_cpu_set(int target, int attr, vm_paddr_t base, uint32_t size,
828 win = MV_WIN_CPU_MAX - 1;
835 while ((win >= 0) && (win < MV_WIN_CPU_MAX)) {
836 cr = win_cpu_cr_read(win);
837 if ((cr & MV_WIN_CPU_ENABLE_BIT) == 0)
839 if ((cr & ((0xff << MV_WIN_CPU_ATTR_SHIFT) |
840 (0x1f << MV_WIN_CPU_TARGET_SHIFT))) ==
841 ((attr << MV_WIN_CPU_ATTR_SHIFT) |
842 (target << MV_WIN_CPU_TARGET_SHIFT)))
846 if ((win < 0) || (win >= MV_WIN_CPU_MAX) ||
847 ((remap != ~0) && (win_cpu_can_remap(win) == 0)))
850 br = base & 0xffff0000;
851 win_cpu_br_write(win, br);
853 if (win_cpu_can_remap(win)) {
855 win_cpu_remap_l_write(win, remap & 0xffff0000);
856 win_cpu_remap_h_write(win, 0);
859 * Remap function is not used for a given window
860 * (capable of remapping) - set remap field with the
861 * same value as base.
863 win_cpu_remap_l_write(win, base & 0xffff0000);
864 win_cpu_remap_h_write(win, 0);
868 cr = ((size - 1) & 0xffff0000) | (attr << MV_WIN_CPU_ATTR_SHIFT) |
869 (target << MV_WIN_CPU_TARGET_SHIFT) | MV_WIN_CPU_ENABLE_BIT;
870 win_cpu_cr_write(win, cr);
876 decode_win_cpu_setup(void)
880 /* Disable all CPU windows */
881 for (i = 0; i < MV_WIN_CPU_MAX; i++) {
882 win_cpu_cr_write(i, 0);
883 win_cpu_br_write(i, 0);
884 if (win_cpu_can_remap(i)) {
885 win_cpu_remap_l_write(i, 0);
886 win_cpu_remap_h_write(i, 0);
890 for (i = 0; i < cpu_wins_no; i++)
891 if (cpu_wins[i].target > 0)
892 decode_win_cpu_set(cpu_wins[i].target,
893 cpu_wins[i].attr, cpu_wins[i].base,
894 cpu_wins[i].size, cpu_wins[i].remap);
899 #ifdef SOC_MV_ARMADAXP
901 decode_win_sdram_fixup(void)
903 struct mem_region mr[FDT_MEM_REGIONS];
904 uint8_t window_valid[MV_WIN_DDR_MAX];
905 int mr_cnt, memsize, err, i, j;
906 uint32_t valid_win_num = 0;
908 /* Grab physical memory regions information from device tree. */
909 err = fdt_get_mem_regions(mr, &mr_cnt, &memsize);
913 for (i = 0; i < MV_WIN_DDR_MAX; i++)
916 /* Try to match entries from device tree with settings from u-boot */
917 for (i = 0; i < mr_cnt; i++) {
918 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
919 if (ddr_is_active(j) &&
920 (ddr_base(j) == mr[i].mr_start) &&
921 (ddr_size(j) == mr[i].mr_size)) {
928 if (mr_cnt != valid_win_num)
931 /* Destroy windows without corresponding device tree entry */
932 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
933 if (ddr_is_active(j) && (window_valid[j] != 1)) {
934 printf("Disabling SDRAM decoding window: %d\n", j);
943 * Check if we're able to cover all active DDR banks.
946 decode_win_can_cover_ddr(int max)
951 for (i = 0; i < MV_WIN_DDR_MAX; i++)
952 if (ddr_is_active(i))
956 printf("Unable to cover all active DDR banks: "
957 "%d, available windows: %d\n", c, max);
964 /**************************************************************************
965 * DDR windows routines
966 **************************************************************************/
971 if (ddr_sz_read(i) & 0x1)
989 return (ddr_br_read(i) & 0xff000000);
996 return ((ddr_sz_read(i) | 0x00ffffff) + 1);
1005 if (dev == MV_DEV_88RC8180)
1006 return ((ddr_sz_read(i) & 0xf0) >> 4);
1007 if (dev == MV_DEV_88F6781)
1010 return (i == 0 ? 0xe :
1013 (i == 3 ? 0x7 : 0xff))));
1022 if (dev == MV_DEV_88RC8180) {
1023 i = (ddr_sz_read(i) & 0xf0) >> 4;
1024 return (i == 0xe ? 0xc :
1027 (i == 0x7 ? 0xf : 0xc))));
1031 * On SOCs other than 88RC8180 Mbus unit ID for
1032 * DDR SDRAM controller is always 0x0.
1037 /**************************************************************************
1038 * USB windows routines
1039 **************************************************************************/
1041 decode_win_usb_valid(void)
1044 return (decode_win_can_cover_ddr(MV_WIN_USB_MAX));
1048 decode_win_usb_dump(u_long base)
1052 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port - 1)))
1055 for (i = 0; i < MV_WIN_USB_MAX; i++)
1056 printf("USB window#%d: c 0x%08x, b 0x%08x\n", i,
1057 win_usb_cr_read(base, i), win_usb_br_read(base, i));
1061 * Set USB decode windows.
1064 decode_win_usb_setup(u_long base)
1070 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port)))
1075 for (i = 0; i < MV_WIN_USB_MAX; i++) {
1076 win_usb_cr_write(base, i, 0);
1077 win_usb_br_write(base, i, 0);
1080 /* Only access to active DRAM banks is required */
1081 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1082 if (ddr_is_active(i)) {
1085 * XXX for 6281 we should handle Mbus write
1086 * burst limit field in the ctrl reg
1088 cr = (((ddr_size(i) - 1) & 0xffff0000) |
1089 (ddr_attr(i) << 8) |
1090 (ddr_target(i) << 4) | 1);
1092 /* Set the first free USB window */
1093 for (j = 0; j < MV_WIN_USB_MAX; j++) {
1094 if (win_usb_cr_read(base, j) & 0x1)
1097 win_usb_br_write(base, j, br);
1098 win_usb_cr_write(base, j, cr);
1105 /**************************************************************************
1106 * ETH windows routines
1107 **************************************************************************/
1110 win_eth_can_remap(int i)
1113 /* ETH encode windows 0-3 have remap capability */
1121 eth_bare_read(uint32_t base, int i)
1125 v = win_eth_bare_read(base);
1132 eth_bare_write(uint32_t base, int i, int val)
1136 v = win_eth_bare_read(base);
1139 win_eth_bare_write(base, v);
1143 eth_epap_write(uint32_t base, int i, int val)
1147 v = win_eth_epap_read(base);
1148 v &= ~(0x3 << (i * 2));
1149 v |= (val << (i * 2));
1150 win_eth_epap_write(base, v);
1154 decode_win_eth_dump(u_long base)
1158 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port - 1)))
1161 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1162 printf("ETH window#%d: b 0x%08x, s 0x%08x", i,
1163 win_eth_br_read(base, i),
1164 win_eth_sz_read(base, i));
1166 if (win_eth_can_remap(i))
1167 printf(", ha 0x%08x",
1168 win_eth_har_read(base, i));
1172 printf("ETH windows: bare 0x%08x, epap 0x%08x\n",
1173 win_eth_bare_read(base),
1174 win_eth_epap_read(base));
1177 #if defined(SOC_MV_LOKIPLUS)
1178 #define MV_WIN_ETH_DDR_TRGT(n) 0
1180 #define MV_WIN_ETH_DDR_TRGT(n) ddr_target(n)
1184 decode_win_eth_setup(u_long base)
1189 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port)))
1194 /* Disable, clear and revoke protection for all ETH windows */
1195 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1197 eth_bare_write(base, i, 1);
1198 eth_epap_write(base, i, 0);
1199 win_eth_br_write(base, i, 0);
1200 win_eth_sz_write(base, i, 0);
1201 if (win_eth_can_remap(i))
1202 win_eth_har_write(base, i, 0);
1205 /* Only access to active DRAM banks is required */
1206 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1207 if (ddr_is_active(i)) {
1209 br = ddr_base(i) | (ddr_attr(i) << 8) | MV_WIN_ETH_DDR_TRGT(i);
1210 sz = ((ddr_size(i) - 1) & 0xffff0000);
1212 /* Set the first free ETH window */
1213 for (j = 0; j < MV_WIN_ETH_MAX; j++) {
1214 if (eth_bare_read(base, j) == 0)
1217 win_eth_br_write(base, j, br);
1218 win_eth_sz_write(base, j, sz);
1220 /* XXX remapping ETH windows not supported */
1222 /* Set protection RW */
1223 eth_epap_write(base, j, 0x3);
1226 eth_bare_write(base, j, 0);
1233 decode_win_eth_valid(void)
1236 return (decode_win_can_cover_ddr(MV_WIN_ETH_MAX));
1239 /**************************************************************************
1240 * PCIE windows routines
1241 **************************************************************************/
1244 decode_win_pcie_setup(u_long base)
1246 uint32_t size = 0, ddrbase = ~0;
1250 for (i = 0; i < MV_PCIE_BAR_MAX; i++) {
1251 pcie_bar_br_write(base, i,
1252 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1254 pcie_bar_brh_write(base, i, 0);
1256 pcie_bar_cr_write(base, i, 0);
1259 for (i = 0; i < MV_WIN_PCIE_MAX; i++) {
1260 win_pcie_cr_write(base, i, 0);
1261 win_pcie_br_write(base, i, 0);
1262 win_pcie_remap_write(base, i, 0);
1265 /* On End-Point only set BAR size to 1MB regardless of DDR size */
1266 if ((bus_space_read_4(fdtbus_bs_tag, base, MV_PCIE_CONTROL)
1267 & MV_PCIE_ROOT_CMPLX) == 0) {
1268 pcie_bar_cr_write(base, 1, 0xf0000 | 1);
1272 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1273 if (ddr_is_active(i)) {
1274 /* Map DDR to BAR 1 */
1275 cr = (ddr_size(i) - 1) & 0xffff0000;
1276 size += ddr_size(i) & 0xffff0000;
1277 cr |= (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
1282 /* Use the first available PCIE window */
1283 for (j = 0; j < MV_WIN_PCIE_MAX; j++) {
1284 if (win_pcie_cr_read(base, j) != 0)
1287 win_pcie_br_write(base, j, br);
1288 win_pcie_cr_write(base, j, cr);
1295 * Upper 16 bits in BAR register is interpreted as BAR size
1296 * (in 64 kB units) plus 64kB, so substract 0x10000
1297 * form value passed to register to get correct value.
1300 pcie_bar_cr_write(base, 1, size | 1);
1301 pcie_bar_br_write(base, 1, ddrbase |
1302 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1303 pcie_bar_br_write(base, 0, fdt_immr_pa |
1304 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1308 decode_win_pcie_valid(void)
1311 return (decode_win_can_cover_ddr(MV_WIN_PCIE_MAX));
1314 /**************************************************************************
1315 * IDMA windows routines
1316 **************************************************************************/
1317 #if defined(SOC_MV_ORION) || defined(SOC_MV_DISCOVERY)
1319 idma_bare_read(u_long base, int i)
1323 v = win_idma_bare_read(base);
1330 idma_bare_write(u_long base, int i, int val)
1334 v = win_idma_bare_read(base);
1337 win_idma_bare_write(base, v);
1341 * Sets channel protection 'val' for window 'w' on channel 'c'
1344 idma_cap_write(u_long base, int c, int w, int val)
1348 v = win_idma_cap_read(base, c);
1349 v &= ~(0x3 << (w * 2));
1350 v |= (val << (w * 2));
1351 win_idma_cap_write(base, c, v);
1355 * Set protection 'val' on all channels for window 'w'
1358 idma_set_prot(u_long base, int w, int val)
1362 for (c = 0; c < MV_IDMA_CHAN_MAX; c++)
1363 idma_cap_write(base, c, w, val);
1367 win_idma_can_remap(int i)
1370 /* IDMA decode windows 0-3 have remap capability */
1378 decode_win_idma_setup(u_long base)
1383 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
1386 * Disable and clear all IDMA windows, revoke protection for all channels
1388 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
1390 idma_bare_write(base, i, 1);
1391 win_idma_br_write(base, i, 0);
1392 win_idma_sz_write(base, i, 0);
1393 if (win_idma_can_remap(i) == 1)
1394 win_idma_har_write(base, i, 0);
1396 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
1397 win_idma_cap_write(base, i, 0);
1400 * Set up access to all active DRAM banks
1402 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1403 if (ddr_is_active(i)) {
1404 br = ddr_base(i) | (ddr_attr(i) << 8) | ddr_target(i);
1405 sz = ((ddr_size(i) - 1) & 0xffff0000);
1407 /* Place DDR entries in non-remapped windows */
1408 for (j = 0; j < MV_WIN_IDMA_MAX; j++)
1409 if (win_idma_can_remap(j) != 1 &&
1410 idma_bare_read(base, j) == 1) {
1412 /* Configure window */
1413 win_idma_br_write(base, j, br);
1414 win_idma_sz_write(base, j, sz);
1416 /* Set protection RW on all channels */
1417 idma_set_prot(base, j, 0x3);
1420 idma_bare_write(base, j, 0);
1426 * Remaining targets -- from statically defined table
1428 for (i = 0; i < idma_wins_no; i++)
1429 if (idma_wins[i].target > 0) {
1430 br = (idma_wins[i].base & 0xffff0000) |
1431 (idma_wins[i].attr << 8) | idma_wins[i].target;
1432 sz = ((idma_wins[i].size - 1) & 0xffff0000);
1434 /* Set the first free IDMA window */
1435 for (j = 0; j < MV_WIN_IDMA_MAX; j++) {
1436 if (idma_bare_read(base, j) == 0)
1439 /* Configure window */
1440 win_idma_br_write(base, j, br);
1441 win_idma_sz_write(base, j, sz);
1442 if (win_idma_can_remap(j) &&
1443 idma_wins[j].remap >= 0)
1444 win_idma_har_write(base, j,
1445 idma_wins[j].remap);
1447 /* Set protection RW on all channels */
1448 idma_set_prot(base, j, 0x3);
1451 idma_bare_write(base, j, 0);
1458 decode_win_idma_valid(void)
1460 const struct decode_win *wintab;
1464 if (idma_wins_no > MV_WIN_IDMA_MAX) {
1465 printf("IDMA windows: too many entries: %d\n", idma_wins_no);
1468 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
1469 if (ddr_is_active(i))
1472 if (idma_wins_no > (MV_WIN_IDMA_MAX - c)) {
1473 printf("IDMA windows: too many entries: %d, available: %d\n",
1474 idma_wins_no, MV_WIN_IDMA_MAX - c);
1480 for (i = 0; i < idma_wins_no; i++, wintab++) {
1482 if (wintab->target == 0) {
1483 printf("IDMA window#%d: DDR target window is not "
1484 "supposed to be reprogrammed!\n", i);
1488 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
1489 printf("IDMA window#%d: not capable of remapping, but "
1490 "val 0x%08x defined\n", i, wintab->remap);
1497 if (s > (0xFFFFFFFF - b + 1)) {
1498 /* XXX this boundary check should account for 64bit and
1500 printf("IDMA window#%d: no space for size 0x%08x at "
1501 "0x%08x\n", i, s, b);
1506 j = decode_win_overlap(i, idma_wins_no, &idma_wins[0]);
1508 printf("IDMA window#%d: (0x%08x - 0x%08x) overlaps "
1509 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
1511 idma_wins[j].base + idma_wins[j].size - 1);
1520 decode_win_idma_dump(u_long base)
1524 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
1527 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
1528 printf("IDMA window#%d: b 0x%08x, s 0x%08x", i,
1529 win_idma_br_read(base, i), win_idma_sz_read(base, i));
1531 if (win_idma_can_remap(i))
1532 printf(", ha 0x%08x", win_idma_har_read(base, i));
1536 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
1537 printf("IDMA channel#%d: ap 0x%08x\n", i,
1538 win_idma_cap_read(base, i));
1539 printf("IDMA windows: bare 0x%08x\n", win_idma_bare_read(base));
1543 /* Provide dummy functions to satisfy the build for SoCs not equipped with IDMA */
1545 decode_win_idma_valid(void)
1552 decode_win_idma_setup(u_long base)
1557 decode_win_idma_dump(u_long base)
1562 /**************************************************************************
1563 * XOR windows routines
1564 **************************************************************************/
1565 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
1567 xor_ctrl_read(u_long base, int i, int c, int e)
1570 v = win_xor_ctrl_read(base, c, e);
1577 xor_ctrl_write(u_long base, int i, int c, int e, int val)
1581 v = win_xor_ctrl_read(base, c, e);
1584 win_xor_ctrl_write(base, c, e, v);
1588 * Set channel protection 'val' for window 'w' on channel 'c'
1591 xor_chan_write(u_long base, int c, int e, int w, int val)
1595 v = win_xor_ctrl_read(base, c, e);
1596 v &= ~(0x3 << (w * 2 + 16));
1597 v |= (val << (w * 2 + 16));
1598 win_xor_ctrl_write(base, c, e, v);
1602 * Set protection 'val' on all channels for window 'w' on engine 'e'
1605 xor_set_prot(u_long base, int w, int e, int val)
1609 for (c = 0; c < MV_XOR_CHAN_MAX; c++)
1610 xor_chan_write(base, c, e, w, val);
1614 win_xor_can_remap(int i)
1617 /* XOR decode windows 0-3 have remap capability */
1631 case MV_DEV_88F6281:
1632 case MV_DEV_88F6282:
1633 case MV_DEV_MV78130:
1634 case MV_DEV_MV78160:
1635 case MV_DEV_MV78230:
1636 case MV_DEV_MV78260:
1637 case MV_DEV_MV78460:
1639 case MV_DEV_MV78100:
1640 case MV_DEV_MV78100_Z0:
1648 xor_active_dram(u_long base, int c, int e, int *window)
1654 * Set up access to all active DRAM banks
1657 for (i = 0; i < m; i++)
1658 if (ddr_is_active(i)) {
1659 br = ddr_base(i) | (ddr_attr(i) << 8) |
1661 sz = ((ddr_size(i) - 1) & 0xffff0000);
1663 /* Place DDR entries in non-remapped windows */
1664 for (w = 0; w < MV_WIN_XOR_MAX; w++)
1665 if (win_xor_can_remap(w) != 1 &&
1666 (xor_ctrl_read(base, w, c, e) == 0) &&
1668 /* Configure window */
1669 win_xor_br_write(base, w, e, br);
1670 win_xor_sz_write(base, w, e, sz);
1672 /* Set protection RW on all channels */
1673 xor_set_prot(base, w, e, 0x3);
1676 xor_ctrl_write(base, w, c, e, 1);
1684 decode_win_xor_setup(u_long base)
1687 int i, j, z, e = 1, m, window;
1689 if (pm_is_disabled(CPU_PM_CTRL_XOR))
1693 * Disable and clear all XOR windows, revoke protection for all
1697 for (j = 0; j < m; j++, e--) {
1699 /* Number of non-remaped windows */
1700 window = MV_XOR_NON_REMAP - 1;
1702 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
1703 win_xor_br_write(base, i, e, 0);
1704 win_xor_sz_write(base, i, e, 0);
1707 if (win_xor_can_remap(i) == 1)
1708 win_xor_har_write(base, i, e, 0);
1710 for (i = 0; i < MV_XOR_CHAN_MAX; i++) {
1711 win_xor_ctrl_write(base, i, e, 0);
1712 xor_active_dram(base, i, e, &window);
1716 * Remaining targets -- from a statically defined table
1718 for (i = 0; i < xor_wins_no; i++)
1719 if (xor_wins[i].target > 0) {
1720 br = (xor_wins[i].base & 0xffff0000) |
1721 (xor_wins[i].attr << 8) |
1723 sz = ((xor_wins[i].size - 1) & 0xffff0000);
1725 /* Set the first free XOR window */
1726 for (z = 0; z < MV_WIN_XOR_MAX; z++) {
1727 if (xor_ctrl_read(base, z, 0, e) &&
1728 xor_ctrl_read(base, z, 1, e))
1731 /* Configure window */
1732 win_xor_br_write(base, z, e, br);
1733 win_xor_sz_write(base, z, e, sz);
1734 if (win_xor_can_remap(z) &&
1735 xor_wins[z].remap >= 0)
1736 win_xor_har_write(base, z, e,
1739 /* Set protection RW on all channels */
1740 xor_set_prot(base, z, e, 0x3);
1743 xor_ctrl_write(base, z, 0, e, 1);
1744 xor_ctrl_write(base, z, 1, e, 1);
1752 decode_win_xor_valid(void)
1754 const struct decode_win *wintab;
1758 if (xor_wins_no > MV_WIN_XOR_MAX) {
1759 printf("XOR windows: too many entries: %d\n", xor_wins_no);
1762 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
1763 if (ddr_is_active(i))
1766 if (xor_wins_no > (MV_WIN_XOR_MAX - c)) {
1767 printf("XOR windows: too many entries: %d, available: %d\n",
1768 xor_wins_no, MV_WIN_IDMA_MAX - c);
1774 for (i = 0; i < xor_wins_no; i++, wintab++) {
1776 if (wintab->target == 0) {
1777 printf("XOR window#%d: DDR target window is not "
1778 "supposed to be reprogrammed!\n", i);
1782 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
1783 printf("XOR window#%d: not capable of remapping, but "
1784 "val 0x%08x defined\n", i, wintab->remap);
1791 if (s > (0xFFFFFFFF - b + 1)) {
1793 * XXX this boundary check should account for 64bit
1796 printf("XOR window#%d: no space for size 0x%08x at "
1797 "0x%08x\n", i, s, b);
1802 j = decode_win_overlap(i, xor_wins_no, &xor_wins[0]);
1804 printf("XOR window#%d: (0x%08x - 0x%08x) overlaps "
1805 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
1807 xor_wins[j].base + xor_wins[j].size - 1);
1816 decode_win_xor_dump(u_long base)
1821 if (pm_is_disabled(CPU_PM_CTRL_XOR))
1824 for (j = 0; j < xor_max_eng(); j++, e--) {
1825 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
1826 printf("XOR window#%d: b 0x%08x, s 0x%08x", i,
1827 win_xor_br_read(base, i, e), win_xor_sz_read(base, i, e));
1829 if (win_xor_can_remap(i))
1830 printf(", ha 0x%08x", win_xor_har_read(base, i, e));
1834 for (i = 0; i < MV_XOR_CHAN_MAX; i++)
1835 printf("XOR control#%d: 0x%08x\n", i,
1836 win_xor_ctrl_read(base, i, e));
1841 /* Provide dummy functions to satisfy the build for SoCs not equipped with XOR */
1843 decode_win_xor_valid(void)
1850 decode_win_xor_setup(u_long base)
1855 decode_win_xor_dump(u_long base)
1860 /**************************************************************************
1861 * SATA windows routines
1862 **************************************************************************/
1864 decode_win_sata_setup(u_long base)
1869 if (pm_is_disabled(CPU_PM_CTRL_SATA))
1872 for (i = 0; i < MV_WIN_SATA_MAX; i++) {
1873 win_sata_cr_write(base, i, 0);
1874 win_sata_br_write(base, i, 0);
1877 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1878 if (ddr_is_active(i)) {
1879 cr = ((ddr_size(i) - 1) & 0xffff0000) |
1880 (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
1883 /* Use the first available SATA window */
1884 for (j = 0; j < MV_WIN_SATA_MAX; j++) {
1885 if ((win_sata_cr_read(base, j) & 1) != 0)
1888 win_sata_br_write(base, j, br);
1889 win_sata_cr_write(base, j, cr);
1896 decode_win_sata_valid(void)
1901 if (dev == MV_DEV_88F5281)
1904 return (decode_win_can_cover_ddr(MV_WIN_SATA_MAX));
1907 /**************************************************************************
1908 * FDT parsing routines.
1909 **************************************************************************/
1912 fdt_get_ranges(const char *nodename, void *buf, int size, int *tuples,
1916 pcell_t addr_cells, par_addr_cells, size_cells;
1917 int len, tuple_size, tuples_count;
1919 node = OF_finddevice(nodename);
1923 if ((fdt_addrsize_cells(node, &addr_cells, &size_cells)) != 0)
1926 par_addr_cells = fdt_parent_addr_cells(node);
1927 if (par_addr_cells > 2)
1930 tuple_size = sizeof(pcell_t) * (addr_cells + par_addr_cells +
1933 /* Note the OF_getprop_alloc() cannot be used at this early stage. */
1934 len = OF_getprop(node, "ranges", buf, size);
1937 * XXX this does not handle the empty 'ranges;' case, which is
1938 * legitimate and should be allowed.
1940 tuples_count = len / tuple_size;
1941 if (tuples_count <= 0)
1944 if (fdt_ranges_verify(buf, tuples_count, par_addr_cells,
1945 addr_cells, size_cells) != 0)
1948 *tuples = tuples_count;
1949 *tuplesize = tuple_size;
1954 win_cpu_from_dt(void)
1958 int i, entry_size, err, t, tuple_size, tuples;
1959 u_long sram_base, sram_size;
1962 /* Retrieve 'ranges' property of '/localbus' node. */
1963 if ((err = fdt_get_ranges("/localbus", ranges, sizeof(ranges),
1964 &tuples, &tuple_size)) == 0) {
1966 * Fill CPU decode windows table.
1968 bzero((void *)&cpu_win_tbl, sizeof(cpu_win_tbl));
1970 entry_size = tuple_size / sizeof(pcell_t);
1971 cpu_wins_no = tuples;
1973 for (i = 0, t = 0; t < tuples; i += entry_size, t++) {
1974 cpu_win_tbl[t].target = 1;
1975 cpu_win_tbl[t].attr = fdt32_to_cpu(ranges[i + 1]);
1976 cpu_win_tbl[t].base = fdt32_to_cpu(ranges[i + 2]);
1977 cpu_win_tbl[t].size = fdt32_to_cpu(ranges[i + 3]);
1978 cpu_win_tbl[t].remap = ~0;
1979 debugf("target = 0x%0x attr = 0x%0x base = 0x%0x "
1980 "size = 0x%0x remap = 0x%0x\n",
1981 cpu_win_tbl[t].target,
1982 cpu_win_tbl[t].attr, cpu_win_tbl[t].base,
1983 cpu_win_tbl[t].size, cpu_win_tbl[t].remap);
1988 * Retrieve CESA SRAM data.
1990 if ((node = OF_finddevice("sram")) != -1)
1991 if (fdt_is_compatible(node, "mrvl,cesa-sram"))
1994 if ((node = OF_finddevice("/")) == 0)
1997 if ((node = fdt_find_compatible(node, "mrvl,cesa-sram", 0)) == 0)
1998 /* SRAM block is not always present. */
2001 sram_base = sram_size = 0;
2002 if (fdt_regsize(node, &sram_base, &sram_size) != 0)
2005 cpu_win_tbl[t].target = MV_WIN_CESA_TARGET;
2006 cpu_win_tbl[t].attr = MV_WIN_CESA_ATTR(1);
2007 cpu_win_tbl[t].base = sram_base;
2008 cpu_win_tbl[t].size = sram_size;
2009 cpu_win_tbl[t].remap = ~0;
2011 debugf("sram: base = 0x%0lx size = 0x%0lx\n", sram_base, sram_size);
2019 phandle_t node, child;
2020 struct soc_node_spec *soc_node;
2024 node = OF_finddevice("/");
2026 panic("fdt_win_setup: no root node");
2029 * Traverse through all children of root and simple-bus nodes.
2030 * For each found device retrieve decode windows data (if applicable).
2032 child = OF_child(node);
2033 while (child != 0) {
2034 for (i = 0; soc_nodes[i].compat != NULL; i++) {
2036 soc_node = &soc_nodes[i];
2038 if (!fdt_is_compatible(child, soc_node->compat))
2041 err = fdt_regsize(child, &base, &size);
2045 base = (base & 0x000fffff) | fdt_immr_va;
2046 if (soc_node->decode_handler != NULL)
2047 soc_node->decode_handler(base);
2051 if (MV_DUMP_WIN && (soc_node->dump_handler != NULL))
2052 soc_node->dump_handler(base);
2056 * Once done with root-level children let's move down to
2057 * simple-bus and its children.
2059 child = OF_peer(child);
2060 if ((child == 0) && (node == OF_finddevice("/"))) {
2061 node = fdt_find_compatible(node, "simple-bus", 1);
2064 child = OF_child(node);
2072 fdt_fixup_busfreq(phandle_t root)
2077 freq = cpu_to_fdt32(get_tclk());
2080 * Fix bus speed in cpu node
2082 if ((sb = OF_finddevice("cpu")) != 0)
2083 if (fdt_is_compatible_strict(sb, "ARM,88VS584"))
2084 OF_setprop(sb, "bus-frequency", (void *)&freq,
2088 * This fixup sets the simple-bus bus-frequency property.
2090 if ((sb = fdt_find_compatible(root, "simple-bus", 1)) != 0)
2091 OF_setprop(sb, "bus-frequency", (void *)&freq, sizeof(freq));
2095 fdt_fixup_ranges(phandle_t root)
2098 pcell_t par_addr_cells, addr_cells, size_cells;
2099 pcell_t ranges[3], reg[2], *rangesptr;
2100 int len, tuple_size, tuples_count;
2103 /* Fix-up SoC ranges according to real fdt_immr_pa */
2104 if ((node = fdt_find_compatible(root, "simple-bus", 1)) != 0) {
2105 if (fdt_addrsize_cells(node, &addr_cells, &size_cells) == 0 &&
2106 (par_addr_cells = fdt_parent_addr_cells(node) <= 2)) {
2107 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2108 addr_cells + size_cells);
2109 len = OF_getprop(node, "ranges", ranges,
2111 tuples_count = len / tuple_size;
2112 /* Unexpected settings are not supported */
2113 if (tuples_count != 1)
2116 rangesptr = &ranges[0];
2117 rangesptr += par_addr_cells;
2118 base = fdt_data_get((void *)rangesptr, addr_cells);
2119 *rangesptr = cpu_to_fdt32(fdt_immr_pa);
2120 if (OF_setprop(node, "ranges", (void *)&ranges[0],
2121 sizeof(ranges)) < 0)
2126 /* Fix-up PCIe reg according to real PCIe registers' PA */
2127 if ((node = fdt_find_compatible(root, "mrvl,pcie", 1)) != 0) {
2128 if (fdt_addrsize_cells(OF_parent(node), &par_addr_cells,
2129 &size_cells) == 0) {
2130 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2132 len = OF_getprop(node, "reg", reg, sizeof(reg));
2133 tuples_count = len / tuple_size;
2134 /* Unexpected settings are not supported */
2135 if (tuples_count != 1)
2138 base = fdt_data_get((void *)®[0], par_addr_cells);
2139 base &= ~0xFF000000;
2140 base |= fdt_immr_pa;
2141 reg[0] = cpu_to_fdt32(base);
2142 if (OF_setprop(node, "reg", (void *)®[0],
2147 /* Fix-up succeeded. May return and continue */
2153 * In case of any error while fixing ranges just hang.
2154 * 1. No message can be displayed yet since console
2155 * is not initialized.
2156 * 2. Going further will cause failure on bus_space_map()
2157 * relying on the wrong ranges or data abort when
2158 * accessing PCIe registers.
2163 struct fdt_fixup_entry fdt_fixup_table[] = {
2164 { "mrvl,DB-88F6281", &fdt_fixup_busfreq },
2165 { "mrvl,DB-78460", &fdt_fixup_busfreq },
2166 { "mrvl,DB-78460", &fdt_fixup_ranges },
2171 fdt_pic_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
2175 if (!fdt_is_compatible(node, "mrvl,pic") &&
2176 !fdt_is_compatible(node, "mrvl,mpic"))
2179 *interrupt = fdt32_to_cpu(intr[0]);
2180 *trig = INTR_TRIGGER_CONFORM;
2181 *pol = INTR_POLARITY_CONFORM;
2186 fdt_pic_decode_t fdt_pic_table[] = {
2194 uint32_t sar_low, sar_high;
2196 #if defined(SOC_MV_ARMADAXP)
2197 sar_high = bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE,
2198 SAMPLE_AT_RESET_HI);
2199 sar_low = bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE,
2200 SAMPLE_AT_RESET_LO);
2203 * TODO: Add getting proper values for other SoC configurations
2209 return (((uint64_t)sar_high << 32) | sar_low);