2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (C) 2008-2011 MARVELL INTERNATIONAL LTD.
7 * Developed by Semihalf.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of MARVELL nor the names of contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
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>
47 #include <dev/ofw/ofw_bus_subr.h>
49 #include <machine/bus.h>
50 #include <machine/fdt.h>
51 #include <machine/vmparam.h>
52 #include <machine/intr.h>
54 #include <arm/mv/mvreg.h>
55 #include <arm/mv/mvvar.h>
56 #include <arm/mv/mvwin.h>
58 MALLOC_DEFINE(M_IDMA, "idma", "idma dma test memory");
66 #define debugf(fmt, args...) do { printf("%s(): ", __func__); \
67 printf(fmt,##args); } while (0)
69 #define debugf(fmt, args...)
80 static enum soc_family soc_family;
82 static int mv_win_cesa_attr_armv5(int eng_sel);
83 static int mv_win_cesa_attr_armada38x(int eng_sel);
84 static int mv_win_cesa_attr_armadaxp(int eng_sel);
86 uint32_t read_cpu_ctrl_armv5(uint32_t reg);
87 uint32_t read_cpu_ctrl_armv7(uint32_t reg);
89 void write_cpu_ctrl_armv5(uint32_t reg, uint32_t val);
90 void write_cpu_ctrl_armv7(uint32_t reg, uint32_t val);
92 static int win_eth_can_remap(int i);
94 static int decode_win_cesa_valid(void);
95 static int decode_win_usb_valid(void);
96 static int decode_win_usb3_valid(void);
97 static int decode_win_eth_valid(void);
98 static int decode_win_pcie_valid(void);
99 static int decode_win_sata_valid(void);
100 static int decode_win_sdhci_valid(void);
102 static int decode_win_idma_valid(void);
103 static int decode_win_xor_valid(void);
105 static void decode_win_cpu_setup(void);
106 static int decode_win_sdram_fixup(void);
107 static void decode_win_cesa_setup(u_long);
108 static void decode_win_a38x_cesa_setup(u_long);
109 static void decode_win_usb_setup(u_long);
110 static void decode_win_usb3_setup(u_long);
111 static void decode_win_eth_setup(u_long);
112 static void decode_win_neta_setup(u_long);
113 static void decode_win_sata_setup(u_long);
114 static void decode_win_ahci_setup(u_long);
115 static void decode_win_sdhci_setup(u_long);
117 static void decode_win_idma_setup(u_long);
118 static void decode_win_xor_setup(u_long);
120 static void decode_win_cesa_dump(u_long);
121 static void decode_win_a38x_cesa_dump(u_long);
122 static void decode_win_usb_dump(u_long);
123 static void decode_win_usb3_dump(u_long);
124 static void decode_win_eth_dump(u_long base);
125 static void decode_win_neta_dump(u_long base);
126 static void decode_win_idma_dump(u_long base);
127 static void decode_win_xor_dump(u_long base);
128 static void decode_win_ahci_dump(u_long base);
129 static void decode_win_sdhci_dump(u_long);
130 static void decode_win_pcie_dump(u_long);
132 static uint32_t win_cpu_cr_read(int);
133 static uint32_t win_cpu_armv5_cr_read(int);
134 static uint32_t win_cpu_armv7_cr_read(int);
135 static uint32_t win_cpu_br_read(int);
136 static uint32_t win_cpu_armv5_br_read(int);
137 static uint32_t win_cpu_armv7_br_read(int);
138 static uint32_t win_cpu_remap_l_read(int);
139 static uint32_t win_cpu_armv5_remap_l_read(int);
140 static uint32_t win_cpu_armv7_remap_l_read(int);
141 static uint32_t win_cpu_remap_h_read(int);
142 static uint32_t win_cpu_armv5_remap_h_read(int);
143 static uint32_t win_cpu_armv7_remap_h_read(int);
145 static void win_cpu_cr_write(int, uint32_t);
146 static void win_cpu_armv5_cr_write(int, uint32_t);
147 static void win_cpu_armv7_cr_write(int, uint32_t);
148 static void win_cpu_br_write(int, uint32_t);
149 static void win_cpu_armv5_br_write(int, uint32_t);
150 static void win_cpu_armv7_br_write(int, uint32_t);
151 static void win_cpu_remap_l_write(int, uint32_t);
152 static void win_cpu_armv5_remap_l_write(int, uint32_t);
153 static void win_cpu_armv7_remap_l_write(int, uint32_t);
154 static void win_cpu_remap_h_write(int, uint32_t);
155 static void win_cpu_armv5_remap_h_write(int, uint32_t);
156 static void win_cpu_armv7_remap_h_write(int, uint32_t);
158 static uint32_t ddr_br_read(int);
159 static uint32_t ddr_sz_read(int);
160 static uint32_t ddr_armv5_br_read(int);
161 static uint32_t ddr_armv5_sz_read(int);
162 static uint32_t ddr_armv7_br_read(int);
163 static uint32_t ddr_armv7_sz_read(int);
164 static void ddr_br_write(int, uint32_t);
165 static void ddr_sz_write(int, uint32_t);
166 static void ddr_armv5_br_write(int, uint32_t);
167 static void ddr_armv5_sz_write(int, uint32_t);
168 static void ddr_armv7_br_write(int, uint32_t);
169 static void ddr_armv7_sz_write(int, uint32_t);
171 static int fdt_get_ranges(const char *, void *, int, int *, int *);
172 int gic_decode_fdt(phandle_t iparent, pcell_t *intr, int *interrupt,
173 int *trig, int *pol);
175 static int win_cpu_from_dt(void);
176 static int fdt_win_setup(void);
178 static int fdt_win_process_child(phandle_t, struct soc_node_spec *, const char*);
180 static void soc_identify(uint32_t, uint32_t);
182 static uint32_t dev_mask = 0;
183 static int cpu_wins_no = 0;
184 static int eth_port = 0;
185 static int usb_port = 0;
186 static boolean_t platform_io_coherent = false;
188 static struct decode_win cpu_win_tbl[MAX_CPU_WIN];
190 const struct decode_win *cpu_wins = cpu_win_tbl;
192 typedef void (*decode_win_setup_t)(u_long);
193 typedef void (*dump_win_t)(u_long);
194 typedef int (*valid_t)(void);
197 * The power status of device feature is only supported on
198 * Kirkwood and Discovery SoCs.
200 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
201 #define SOC_MV_POWER_STAT_SUPPORTED 1
203 #define SOC_MV_POWER_STAT_SUPPORTED 0
206 struct soc_node_spec {
208 decode_win_setup_t decode_handler;
209 dump_win_t dump_handler;
210 valid_t valid_handler;
213 static struct soc_node_spec soc_nodes[] = {
214 { "mrvl,ge", &decode_win_eth_setup, &decode_win_eth_dump, &decode_win_eth_valid},
215 { "marvell,armada-370-neta", &decode_win_neta_setup,
216 &decode_win_neta_dump, NULL },
217 { "mrvl,usb-ehci", &decode_win_usb_setup, &decode_win_usb_dump, &decode_win_usb_valid},
218 { "marvell,orion-ehci", &decode_win_usb_setup, &decode_win_usb_dump, &decode_win_usb_valid },
219 { "marvell,armada-380-xhci", &decode_win_usb3_setup,
220 &decode_win_usb3_dump, &decode_win_usb3_valid },
221 { "marvell,armada-380-ahci", &decode_win_ahci_setup,
222 &decode_win_ahci_dump, NULL },
223 { "marvell,armada-380-sdhci", &decode_win_sdhci_setup,
224 &decode_win_sdhci_dump, &decode_win_sdhci_valid},
225 { "mrvl,sata", &decode_win_sata_setup, NULL, &decode_win_sata_valid},
226 { "mrvl,xor", &decode_win_xor_setup, &decode_win_xor_dump, &decode_win_xor_valid},
227 { "mrvl,idma", &decode_win_idma_setup, &decode_win_idma_dump, &decode_win_idma_valid},
228 { "mrvl,cesa", &decode_win_cesa_setup, &decode_win_cesa_dump, &decode_win_cesa_valid},
229 { "mrvl,pcie", &decode_win_pcie_setup, &decode_win_pcie_dump, &decode_win_pcie_valid},
230 { "marvell,armada-38x-crypto", &decode_win_a38x_cesa_setup,
231 &decode_win_a38x_cesa_dump, &decode_win_cesa_valid},
232 { NULL, NULL, NULL, NULL },
235 #define SOC_NODE_PCIE_ENTRY_IDX 11
237 typedef uint32_t(*read_cpu_ctrl_t)(uint32_t);
238 typedef void(*write_cpu_ctrl_t)(uint32_t, uint32_t);
239 typedef uint32_t (*win_read_t)(int);
240 typedef void (*win_write_t)(int, uint32_t);
241 typedef int (*win_cesa_attr_t)(int);
242 typedef uint32_t (*get_t)(void);
244 struct decode_win_spec {
245 read_cpu_ctrl_t read_cpu_ctrl;
246 write_cpu_ctrl_t write_cpu_ctrl;
249 win_read_t remap_l_read;
250 win_read_t remap_h_read;
251 win_write_t cr_write;
252 win_write_t br_write;
253 win_write_t remap_l_write;
254 win_write_t remap_h_write;
255 uint32_t mv_win_cpu_max;
256 win_cesa_attr_t win_cesa_attr;
258 win_read_t ddr_br_read;
259 win_read_t ddr_sz_read;
260 win_write_t ddr_br_write;
261 win_write_t ddr_sz_write;
266 struct decode_win_spec *soc_decode_win_spec;
268 static struct decode_win_spec decode_win_specs[] =
271 &read_cpu_ctrl_armv7,
272 &write_cpu_ctrl_armv7,
273 &win_cpu_armv7_cr_read,
274 &win_cpu_armv7_br_read,
275 &win_cpu_armv7_remap_l_read,
276 &win_cpu_armv7_remap_h_read,
277 &win_cpu_armv7_cr_write,
278 &win_cpu_armv7_br_write,
279 &win_cpu_armv7_remap_l_write,
280 &win_cpu_armv7_remap_h_write,
281 MV_WIN_CPU_MAX_ARMV7,
282 &mv_win_cesa_attr_armada38x,
283 MV_WIN_CESA_TARGET_ARMADA38X,
289 &get_cpu_freq_armada38x,
292 &read_cpu_ctrl_armv7,
293 &write_cpu_ctrl_armv7,
294 &win_cpu_armv7_cr_read,
295 &win_cpu_armv7_br_read,
296 &win_cpu_armv7_remap_l_read,
297 &win_cpu_armv7_remap_h_read,
298 &win_cpu_armv7_cr_write,
299 &win_cpu_armv7_br_write,
300 &win_cpu_armv7_remap_l_write,
301 &win_cpu_armv7_remap_h_write,
302 MV_WIN_CPU_MAX_ARMV7,
303 &mv_win_cesa_attr_armadaxp,
304 MV_WIN_CESA_TARGET_ARMADAXP,
310 &get_cpu_freq_armadaxp,
313 &read_cpu_ctrl_armv5,
314 &write_cpu_ctrl_armv5,
315 &win_cpu_armv5_cr_read,
316 &win_cpu_armv5_br_read,
317 &win_cpu_armv5_remap_l_read,
318 &win_cpu_armv5_remap_h_read,
319 &win_cpu_armv5_cr_write,
320 &win_cpu_armv5_br_write,
321 &win_cpu_armv5_remap_l_write,
322 &win_cpu_armv5_remap_h_write,
324 &mv_win_cesa_attr_armv5,
335 struct fdt_pm_mask_entry {
340 static struct fdt_pm_mask_entry fdt_pm_mask_table[] = {
341 { "mrvl,ge", CPU_PM_CTRL_GE(0) },
342 { "mrvl,ge", CPU_PM_CTRL_GE(1) },
343 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(0) },
344 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(1) },
345 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(2) },
346 { "mrvl,xor", CPU_PM_CTRL_XOR },
347 { "mrvl,sata", CPU_PM_CTRL_SATA },
352 pm_is_disabled(uint32_t mask)
354 #if SOC_MV_POWER_STAT_SUPPORTED
355 return (soc_power_ctrl_get(mask) == mask ? 0 : 1);
362 * Disable device using power management register.
363 * 1 - Device Power On
364 * 0 - Device Power Off
365 * Mask can be set in loader.
367 * loader> set hw.pm-disable-mask=0x2
370 * |-------------------------------|
371 * | Device | Kirkwood | Discovery |
372 * |-------------------------------|
373 * | USB0 | 0x00008 | 0x020000 |
374 * |-------------------------------|
375 * | USB1 | - | 0x040000 |
376 * |-------------------------------|
377 * | USB2 | - | 0x080000 |
378 * |-------------------------------|
379 * | GE0 | 0x00001 | 0x000002 |
380 * |-------------------------------|
381 * | GE1 | - | 0x000004 |
382 * |-------------------------------|
383 * | IDMA | - | 0x100000 |
384 * |-------------------------------|
385 * | XOR | 0x10000 | 0x200000 |
386 * |-------------------------------|
387 * | CESA | 0x20000 | 0x400000 |
388 * |-------------------------------|
389 * | SATA | 0x04000 | 0x004000 |
390 * --------------------------------|
391 * This feature can be used only on Kirkwood and Discovery
395 static int mv_win_cesa_attr_armv5(int eng_sel)
398 return MV_WIN_CESA_ATTR(eng_sel);
401 static int mv_win_cesa_attr_armada38x(int eng_sel)
404 return MV_WIN_CESA_ATTR_ARMADA38X(eng_sel);
407 static int mv_win_cesa_attr_armadaxp(int eng_sel)
410 return MV_WIN_CESA_ATTR_ARMADAXP(eng_sel);
414 mv_check_soc_family(void)
423 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMADA_XP];
424 soc_family = MV_SOC_ARMADA_XP;
429 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMADA_38X];
430 soc_family = MV_SOC_ARMADA_38X;
436 case MV_DEV_88RC8180:
437 case MV_DEV_88RC9480:
438 case MV_DEV_88RC9580:
441 case MV_DEV_MV78100_Z0:
444 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMV5];
445 soc_family = MV_SOC_ARMV5;
448 soc_family = MV_SOC_UNSUPPORTED;
449 return (MV_SOC_UNSUPPORTED);
452 soc_identify(dev, rev);
458 pm_disable_device(int mask)
463 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
464 printf("Power Management Register: 0%x\n", reg);
467 soc_power_ctrl_set(reg);
468 printf("Device %x is disabled\n", mask);
470 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
471 printf("Power Management Register: 0%x\n", reg);
476 mv_fdt_is_type(phandle_t node, const char *typestr)
478 #define FDT_TYPE_LEN 64
479 char type[FDT_TYPE_LEN];
481 if (OF_getproplen(node, "device_type") <= 0)
484 if (OF_getprop(node, "device_type", type, FDT_TYPE_LEN) < 0)
487 if (strncasecmp(type, typestr, FDT_TYPE_LEN) == 0)
496 mv_fdt_pm(phandle_t node)
498 uint32_t cpu_pm_ctrl;
502 cpu_pm_ctrl = read_cpu_ctrl(CPU_PM_CTRL);
503 for (i = 0; fdt_pm_mask_table[i].compat != NULL; i++) {
504 if (dev_mask & (1 << i))
507 compat = ofw_bus_node_is_compatible(node,
508 fdt_pm_mask_table[i].compat);
509 #if defined(SOC_MV_KIRKWOOD)
510 if (compat && (cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
511 dev_mask |= (1 << i);
515 dev_mask |= (1 << i);
519 if (compat && (~cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
520 dev_mask |= (1 << i);
524 dev_mask |= (1 << i);
534 read_cpu_ctrl(uint32_t reg)
537 if (soc_decode_win_spec->read_cpu_ctrl != NULL)
538 return (soc_decode_win_spec->read_cpu_ctrl(reg));
543 read_cpu_ctrl_armv5(uint32_t reg)
546 return (bus_space_read_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg));
550 read_cpu_ctrl_armv7(uint32_t reg)
553 return (bus_space_read_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE_ARMV7, reg));
557 write_cpu_ctrl(uint32_t reg, uint32_t val)
560 if (soc_decode_win_spec->write_cpu_ctrl != NULL)
561 soc_decode_win_spec->write_cpu_ctrl(reg, val);
565 write_cpu_ctrl_armv5(uint32_t reg, uint32_t val)
568 bus_space_write_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg, val);
572 write_cpu_ctrl_armv7(uint32_t reg, uint32_t val)
575 bus_space_write_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE_ARMV7, reg, val);
579 read_cpu_mp_clocks(uint32_t reg)
582 return (bus_space_read_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg));
586 write_cpu_mp_clocks(uint32_t reg, uint32_t val)
589 bus_space_write_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg, val);
593 read_cpu_misc(uint32_t reg)
596 return (bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE, reg));
600 write_cpu_misc(uint32_t reg, uint32_t val)
603 bus_space_write_4(fdtbus_bs_tag, MV_MISC_BASE, reg, val);
617 case MV_DEV_88RC8180:
618 case MV_DEV_MV78100_Z0:
620 __asm __volatile("mrc p15, 1, %0, c15, c1, 0" : "=r" (ef));
624 __asm __volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (ef));
628 printf("This ARM Core does not support any extra features\n");
635 * Get the power status of device. This feature is only supported on
636 * Kirkwood and Discovery SoCs.
639 soc_power_ctrl_get(uint32_t mask)
642 #if SOC_MV_POWER_STAT_SUPPORTED
643 if (mask != CPU_PM_CTRL_NONE)
644 mask &= read_cpu_ctrl(CPU_PM_CTRL);
653 * Set the power status of device. This feature is only supported on
654 * Kirkwood and Discovery SoCs.
657 soc_power_ctrl_set(uint32_t mask)
660 #if !defined(SOC_MV_ORION)
661 if (mask != CPU_PM_CTRL_NONE)
662 write_cpu_ctrl(CPU_PM_CTRL, mask);
667 soc_id(uint32_t *dev, uint32_t *rev)
669 uint64_t mv_pcie_base = MV_PCIE_BASE;
673 * Notice: system identifiers are available in the registers range of
674 * PCIE controller, so using this function is only allowed (and
675 * possible) after the internal registers range has been mapped in via
676 * devmap_bootstrap().
680 if ((node = OF_finddevice("/")) == -1)
682 if (ofw_bus_node_is_compatible(node, "marvell,armada380"))
683 mv_pcie_base = MV_PCIE_BASE_ARMADA38X;
685 *dev = bus_space_read_4(fdtbus_bs_tag, mv_pcie_base, 0) >> 16;
686 *rev = bus_space_read_4(fdtbus_bs_tag, mv_pcie_base, 8) & 0xff;
690 soc_identify(uint32_t d, uint32_t r)
692 uint32_t size, mode, freq;
698 printf("(0x%4x:0x%02x) ", d, r);
703 dev = "Marvell 88F5181";
708 dev = "Marvell 88F5182";
713 dev = "Marvell 88F5281";
722 dev = "Marvell 88F6281";
730 case MV_DEV_88RC8180:
731 dev = "Marvell 88RC8180";
733 case MV_DEV_88RC9480:
734 dev = "Marvell 88RC9480";
736 case MV_DEV_88RC9580:
737 dev = "Marvell 88RC9580";
740 dev = "Marvell 88F6781";
745 dev = "Marvell 88F6282";
752 dev = "Marvell 88F6828";
755 dev = "Marvell 88F6820";
758 dev = "Marvell 88F6810";
760 case MV_DEV_MV78100_Z0:
761 dev = "Marvell MV78100 Z0";
764 dev = "Marvell MV78100";
767 dev = "Marvell MV78160";
770 dev = "Marvell MV78260";
773 dev = "Marvell MV78460";
782 printf(" rev %s", rev);
783 printf(", TClock %dMHz", get_tclk() / 1000 / 1000);
784 freq = get_cpu_freq();
786 printf(", Frequency %dMHz", freq / 1000 / 1000);
789 mode = read_cpu_ctrl(CPU_CONFIG);
790 printf(" Instruction cache prefetch %s, data cache prefetch %s\n",
791 (mode & CPU_CONFIG_IC_PREF) ? "enabled" : "disabled",
792 (mode & CPU_CONFIG_DC_PREF) ? "enabled" : "disabled");
797 mode = read_cpu_ctrl(CPU_L2_CONFIG) & CPU_L2_CONFIG_MODE;
798 printf(" 256KB 4-way set-associative %s unified L2 cache\n",
799 mode ? "write-through" : "write-back");
802 mode = read_cpu_ctrl(CPU_CONTROL);
803 size = mode & CPU_CONTROL_L2_SIZE;
804 mode = mode & CPU_CONTROL_L2_MODE;
805 printf(" %s set-associative %s unified L2 cache\n",
806 size ? "256KB 4-way" : "512KB 8-way",
807 mode ? "write-through" : "write-back");
816 mv_enter_debugger(void *dummy)
819 if (boothowto & RB_KDB)
820 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
822 SYSINIT(mv_enter_debugger, SI_SUB_CPU, SI_ORDER_ANY, mv_enter_debugger, NULL);
832 TUNABLE_INT_FETCH("hw.pm-disable-mask", &mask);
835 pm_disable_device(mask);
837 /* Retrieve data about physical addresses from device tree. */
838 if ((err = win_cpu_from_dt()) != 0)
841 /* Retrieve our ID: some windows facilities vary between SoC models */
844 if (soc_family == MV_SOC_ARMADA_XP)
845 if ((err = decode_win_sdram_fixup()) != 0)
848 decode_win_cpu_setup();
850 soc_dump_decode_win();
854 if ((err = fdt_win_setup()) != 0)
860 /**************************************************************************
861 * Decode windows registers accessors
862 **************************************************************************/
863 WIN_REG_IDX_RD(win_cpu_armv5, cr, MV_WIN_CPU_CTRL_ARMV5, MV_MBUS_BRIDGE_BASE)
864 WIN_REG_IDX_RD(win_cpu_armv5, br, MV_WIN_CPU_BASE_ARMV5, MV_MBUS_BRIDGE_BASE)
865 WIN_REG_IDX_RD(win_cpu_armv5, remap_l, MV_WIN_CPU_REMAP_LO_ARMV5, MV_MBUS_BRIDGE_BASE)
866 WIN_REG_IDX_RD(win_cpu_armv5, remap_h, MV_WIN_CPU_REMAP_HI_ARMV5, MV_MBUS_BRIDGE_BASE)
867 WIN_REG_IDX_WR(win_cpu_armv5, cr, MV_WIN_CPU_CTRL_ARMV5, MV_MBUS_BRIDGE_BASE)
868 WIN_REG_IDX_WR(win_cpu_armv5, br, MV_WIN_CPU_BASE_ARMV5, MV_MBUS_BRIDGE_BASE)
869 WIN_REG_IDX_WR(win_cpu_armv5, remap_l, MV_WIN_CPU_REMAP_LO_ARMV5, MV_MBUS_BRIDGE_BASE)
870 WIN_REG_IDX_WR(win_cpu_armv5, remap_h, MV_WIN_CPU_REMAP_HI_ARMV5, MV_MBUS_BRIDGE_BASE)
872 WIN_REG_IDX_RD(win_cpu_armv7, cr, MV_WIN_CPU_CTRL_ARMV7, MV_MBUS_BRIDGE_BASE)
873 WIN_REG_IDX_RD(win_cpu_armv7, br, MV_WIN_CPU_BASE_ARMV7, MV_MBUS_BRIDGE_BASE)
874 WIN_REG_IDX_RD(win_cpu_armv7, remap_l, MV_WIN_CPU_REMAP_LO_ARMV7, MV_MBUS_BRIDGE_BASE)
875 WIN_REG_IDX_RD(win_cpu_armv7, remap_h, MV_WIN_CPU_REMAP_HI_ARMV7, MV_MBUS_BRIDGE_BASE)
876 WIN_REG_IDX_WR(win_cpu_armv7, cr, MV_WIN_CPU_CTRL_ARMV7, MV_MBUS_BRIDGE_BASE)
877 WIN_REG_IDX_WR(win_cpu_armv7, br, MV_WIN_CPU_BASE_ARMV7, MV_MBUS_BRIDGE_BASE)
878 WIN_REG_IDX_WR(win_cpu_armv7, remap_l, MV_WIN_CPU_REMAP_LO_ARMV7, MV_MBUS_BRIDGE_BASE)
879 WIN_REG_IDX_WR(win_cpu_armv7, remap_h, MV_WIN_CPU_REMAP_HI_ARMV7, MV_MBUS_BRIDGE_BASE)
882 win_cpu_cr_read(int i)
885 if (soc_decode_win_spec->cr_read != NULL)
886 return (soc_decode_win_spec->cr_read(i));
891 win_cpu_br_read(int i)
894 if (soc_decode_win_spec->br_read != NULL)
895 return (soc_decode_win_spec->br_read(i));
900 win_cpu_remap_l_read(int i)
903 if (soc_decode_win_spec->remap_l_read != NULL)
904 return (soc_decode_win_spec->remap_l_read(i));
909 win_cpu_remap_h_read(int i)
912 if (soc_decode_win_spec->remap_h_read != NULL)
913 return soc_decode_win_spec->remap_h_read(i);
918 win_cpu_cr_write(int i, uint32_t val)
921 if (soc_decode_win_spec->cr_write != NULL)
922 soc_decode_win_spec->cr_write(i, val);
926 win_cpu_br_write(int i, uint32_t val)
929 if (soc_decode_win_spec->br_write != NULL)
930 soc_decode_win_spec->br_write(i, val);
934 win_cpu_remap_l_write(int i, uint32_t val)
937 if (soc_decode_win_spec->remap_l_write != NULL)
938 soc_decode_win_spec->remap_l_write(i, val);
942 win_cpu_remap_h_write(int i, uint32_t val)
945 if (soc_decode_win_spec->remap_h_write != NULL)
946 soc_decode_win_spec->remap_h_write(i, val);
949 WIN_REG_BASE_IDX_RD(win_cesa, cr, MV_WIN_CESA_CTRL)
950 WIN_REG_BASE_IDX_RD(win_cesa, br, MV_WIN_CESA_BASE)
951 WIN_REG_BASE_IDX_WR(win_cesa, cr, MV_WIN_CESA_CTRL)
952 WIN_REG_BASE_IDX_WR(win_cesa, br, MV_WIN_CESA_BASE)
954 WIN_REG_BASE_IDX_RD(win_usb, cr, MV_WIN_USB_CTRL)
955 WIN_REG_BASE_IDX_RD(win_usb, br, MV_WIN_USB_BASE)
956 WIN_REG_BASE_IDX_WR(win_usb, cr, MV_WIN_USB_CTRL)
957 WIN_REG_BASE_IDX_WR(win_usb, br, MV_WIN_USB_BASE)
959 WIN_REG_BASE_IDX_RD(win_usb3, cr, MV_WIN_USB3_CTRL)
960 WIN_REG_BASE_IDX_RD(win_usb3, br, MV_WIN_USB3_BASE)
961 WIN_REG_BASE_IDX_WR(win_usb3, cr, MV_WIN_USB3_CTRL)
962 WIN_REG_BASE_IDX_WR(win_usb3, br, MV_WIN_USB3_BASE)
964 WIN_REG_BASE_IDX_RD(win_eth, br, MV_WIN_ETH_BASE)
965 WIN_REG_BASE_IDX_RD(win_eth, sz, MV_WIN_ETH_SIZE)
966 WIN_REG_BASE_IDX_RD(win_eth, har, MV_WIN_ETH_REMAP)
967 WIN_REG_BASE_IDX_WR(win_eth, br, MV_WIN_ETH_BASE)
968 WIN_REG_BASE_IDX_WR(win_eth, sz, MV_WIN_ETH_SIZE)
969 WIN_REG_BASE_IDX_WR(win_eth, har, MV_WIN_ETH_REMAP)
971 WIN_REG_BASE_RD(win_eth, bare, 0x290)
972 WIN_REG_BASE_RD(win_eth, epap, 0x294)
973 WIN_REG_BASE_WR(win_eth, bare, 0x290)
974 WIN_REG_BASE_WR(win_eth, epap, 0x294)
976 WIN_REG_BASE_IDX_RD(win_pcie, cr, MV_WIN_PCIE_CTRL);
977 WIN_REG_BASE_IDX_RD(win_pcie, br, MV_WIN_PCIE_BASE);
978 WIN_REG_BASE_IDX_RD(win_pcie, remap, MV_WIN_PCIE_REMAP);
979 WIN_REG_BASE_IDX_WR(win_pcie, cr, MV_WIN_PCIE_CTRL);
980 WIN_REG_BASE_IDX_WR(win_pcie, br, MV_WIN_PCIE_BASE);
981 WIN_REG_BASE_IDX_WR(win_pcie, remap, MV_WIN_PCIE_REMAP);
982 WIN_REG_BASE_IDX_RD(pcie_bar, br, MV_PCIE_BAR_BASE);
983 WIN_REG_BASE_IDX_RD(pcie_bar, brh, MV_PCIE_BAR_BASE_H);
984 WIN_REG_BASE_IDX_RD(pcie_bar, cr, MV_PCIE_BAR_CTRL);
985 WIN_REG_BASE_IDX_WR(pcie_bar, br, MV_PCIE_BAR_BASE);
986 WIN_REG_BASE_IDX_WR(pcie_bar, brh, MV_PCIE_BAR_BASE_H);
987 WIN_REG_BASE_IDX_WR(pcie_bar, cr, MV_PCIE_BAR_CTRL);
989 WIN_REG_BASE_IDX_RD(win_sata, cr, MV_WIN_SATA_CTRL);
990 WIN_REG_BASE_IDX_RD(win_sata, br, MV_WIN_SATA_BASE);
991 WIN_REG_BASE_IDX_WR(win_sata, cr, MV_WIN_SATA_CTRL);
992 WIN_REG_BASE_IDX_WR(win_sata, br, MV_WIN_SATA_BASE);
994 WIN_REG_BASE_IDX_RD(win_sata_armada38x, sz, MV_WIN_SATA_SIZE_ARMADA38X);
995 WIN_REG_BASE_IDX_WR(win_sata_armada38x, sz, MV_WIN_SATA_SIZE_ARMADA38X);
996 WIN_REG_BASE_IDX_RD(win_sata_armada38x, cr, MV_WIN_SATA_CTRL_ARMADA38X);
997 WIN_REG_BASE_IDX_WR(win_sata_armada38x, cr, MV_WIN_SATA_CTRL_ARMADA38X);
998 WIN_REG_BASE_IDX_WR(win_sata_armada38x, br, MV_WIN_SATA_BASE_ARMADA38X);
1000 WIN_REG_BASE_IDX_RD(win_sdhci, cr, MV_WIN_SDHCI_CTRL);
1001 WIN_REG_BASE_IDX_RD(win_sdhci, br, MV_WIN_SDHCI_BASE);
1002 WIN_REG_BASE_IDX_WR(win_sdhci, cr, MV_WIN_SDHCI_CTRL);
1003 WIN_REG_BASE_IDX_WR(win_sdhci, br, MV_WIN_SDHCI_BASE);
1006 WIN_REG_IDX_RD(ddr_armv5, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
1007 WIN_REG_IDX_RD(ddr_armv5, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
1008 WIN_REG_IDX_WR(ddr_armv5, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
1009 WIN_REG_IDX_WR(ddr_armv5, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
1011 WIN_REG_IDX_RD(ddr_armv7, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE_ARMV7)
1012 WIN_REG_IDX_RD(ddr_armv7, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE_ARMV7)
1013 WIN_REG_IDX_WR(ddr_armv7, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE_ARMV7)
1014 WIN_REG_IDX_WR(ddr_armv7, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE_ARMV7)
1016 static inline uint32_t
1020 if (soc_decode_win_spec->ddr_br_read != NULL)
1021 return (soc_decode_win_spec->ddr_br_read(i));
1025 static inline uint32_t
1029 if (soc_decode_win_spec->ddr_sz_read != NULL)
1030 return (soc_decode_win_spec->ddr_sz_read(i));
1035 ddr_br_write(int i, uint32_t val)
1038 if (soc_decode_win_spec->ddr_br_write != NULL)
1039 soc_decode_win_spec->ddr_br_write(i, val);
1043 ddr_sz_write(int i, uint32_t val)
1046 if (soc_decode_win_spec->ddr_sz_write != NULL)
1047 soc_decode_win_spec->ddr_sz_write(i, val);
1051 * On 88F6781 (Dove) SoC DDR Controller is accessed through
1052 * single MBUS <-> AXI bridge. In this case we provide emulated
1053 * ddr_br_read() and ddr_sz_read() functions to keep compatibility
1054 * with common decoding windows setup code.
1057 static inline uint32_t ddr_br_read(int i)
1061 /* Read Memory Address Map Register for CS i */
1062 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
1064 /* Return CS i base address */
1065 return (mmap & 0xFF000000);
1068 static inline uint32_t ddr_sz_read(int i)
1070 uint32_t mmap, size;
1072 /* Read Memory Address Map Register for CS i */
1073 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
1075 /* Extract size of CS space in 64kB units */
1076 size = (1 << ((mmap >> 16) & 0x0F));
1078 /* Return CS size and enable/disable status */
1079 return (((size - 1) << 16) | (mmap & 0x01));
1083 /**************************************************************************
1084 * Decode windows helper routines
1085 **************************************************************************/
1087 soc_dump_decode_win(void)
1091 for (i = 0; i < soc_decode_win_spec->mv_win_cpu_max; i++) {
1092 printf("CPU window#%d: c 0x%08x, b 0x%08x", i,
1094 win_cpu_br_read(i));
1096 if (win_cpu_can_remap(i))
1097 printf(", rl 0x%08x, rh 0x%08x",
1098 win_cpu_remap_l_read(i),
1099 win_cpu_remap_h_read(i));
1103 printf("Internal regs base: 0x%08x\n",
1104 bus_space_read_4(fdtbus_bs_tag, MV_INTREGS_BASE, 0));
1106 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1107 printf("DDR CS#%d: b 0x%08x, s 0x%08x\n", i,
1108 ddr_br_read(i), ddr_sz_read(i));
1111 /**************************************************************************
1112 * CPU windows routines
1113 **************************************************************************/
1115 win_cpu_can_remap(int i)
1121 /* Depending on the SoC certain windows have remap capability */
1122 if ((dev == MV_DEV_88F5182 && i < 2) ||
1123 (dev == MV_DEV_88F5281 && i < 4) ||
1124 (dev == MV_DEV_88F6281 && i < 4) ||
1125 (dev == MV_DEV_88F6282 && i < 4) ||
1126 (dev == MV_DEV_88F6828 && i < 20) ||
1127 (dev == MV_DEV_88F6820 && i < 20) ||
1128 (dev == MV_DEV_88F6810 && i < 20) ||
1129 (dev == MV_DEV_88RC8180 && i < 2) ||
1130 (dev == MV_DEV_88F6781 && i < 4) ||
1131 (dev == MV_DEV_MV78100_Z0 && i < 8) ||
1132 ((dev & MV_DEV_FAMILY_MASK) == MV_DEV_DISCOVERY && i < 8))
1138 /* XXX This should check for overlapping remap fields too.. */
1140 decode_win_overlap(int win, int win_no, const struct decode_win *wintab)
1142 const struct decode_win *tab;
1147 for (i = 0; i < win_no; i++, tab++) {
1152 if ((tab->base + tab->size - 1) < (wintab + win)->base)
1155 else if (((wintab + win)->base + (wintab + win)->size - 1) <
1166 decode_win_cpu_set(int target, int attr, vm_paddr_t base, uint32_t size,
1173 win = soc_decode_win_spec->mv_win_cpu_max - 1;
1180 while ((win >= 0) && (win < soc_decode_win_spec->mv_win_cpu_max)) {
1181 cr = win_cpu_cr_read(win);
1182 if ((cr & MV_WIN_CPU_ENABLE_BIT) == 0)
1184 if ((cr & ((0xff << MV_WIN_CPU_ATTR_SHIFT) |
1185 (0x1f << MV_WIN_CPU_TARGET_SHIFT))) ==
1186 ((attr << MV_WIN_CPU_ATTR_SHIFT) |
1187 (target << MV_WIN_CPU_TARGET_SHIFT)))
1191 if ((win < 0) || (win >= soc_decode_win_spec->mv_win_cpu_max) ||
1192 ((remap != ~0) && (win_cpu_can_remap(win) == 0)))
1195 br = base & 0xffff0000;
1196 win_cpu_br_write(win, br);
1198 if (win_cpu_can_remap(win)) {
1200 win_cpu_remap_l_write(win, remap & 0xffff0000);
1201 win_cpu_remap_h_write(win, 0);
1204 * Remap function is not used for a given window
1205 * (capable of remapping) - set remap field with the
1206 * same value as base.
1208 win_cpu_remap_l_write(win, base & 0xffff0000);
1209 win_cpu_remap_h_write(win, 0);
1213 cr = ((size - 1) & 0xffff0000) | (attr << MV_WIN_CPU_ATTR_SHIFT) |
1214 (target << MV_WIN_CPU_TARGET_SHIFT) | MV_WIN_CPU_ENABLE_BIT;
1215 win_cpu_cr_write(win, cr);
1221 decode_win_cpu_setup(void)
1225 /* Disable all CPU windows */
1226 for (i = 0; i < soc_decode_win_spec->mv_win_cpu_max; i++) {
1227 win_cpu_cr_write(i, 0);
1228 win_cpu_br_write(i, 0);
1229 if (win_cpu_can_remap(i)) {
1230 win_cpu_remap_l_write(i, 0);
1231 win_cpu_remap_h_write(i, 0);
1235 for (i = 0; i < cpu_wins_no; i++)
1236 if (cpu_wins[i].target > 0)
1237 decode_win_cpu_set(cpu_wins[i].target,
1238 cpu_wins[i].attr, cpu_wins[i].base,
1239 cpu_wins[i].size, cpu_wins[i].remap);
1244 decode_win_sdram_fixup(void)
1246 struct mem_region mr[FDT_MEM_REGIONS];
1247 uint8_t window_valid[MV_WIN_DDR_MAX];
1248 int mr_cnt, err, i, j;
1249 uint32_t valid_win_num = 0;
1251 /* Grab physical memory regions information from device tree. */
1252 err = fdt_get_mem_regions(mr, &mr_cnt, NULL);
1256 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1257 window_valid[i] = 0;
1259 /* Try to match entries from device tree with settings from u-boot */
1260 for (i = 0; i < mr_cnt; i++) {
1261 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
1262 if (ddr_is_active(j) &&
1263 (ddr_base(j) == mr[i].mr_start) &&
1264 (ddr_size(j) == mr[i].mr_size)) {
1265 window_valid[j] = 1;
1271 if (mr_cnt != valid_win_num)
1274 /* Destroy windows without corresponding device tree entry */
1275 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
1276 if (ddr_is_active(j) && (window_valid[j] != 1)) {
1277 printf("Disabling SDRAM decoding window: %d\n", j);
1285 * Check if we're able to cover all active DDR banks.
1288 decode_win_can_cover_ddr(int max)
1293 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1294 if (ddr_is_active(i))
1298 printf("Unable to cover all active DDR banks: "
1299 "%d, available windows: %d\n", c, max);
1306 /**************************************************************************
1307 * DDR windows routines
1308 **************************************************************************/
1310 ddr_is_active(int i)
1313 if (ddr_sz_read(i) & 0x1)
1331 return (ddr_br_read(i) & 0xff000000);
1338 return ((ddr_sz_read(i) | 0x00ffffff) + 1);
1344 uint32_t dev, rev, attr;
1347 if (dev == MV_DEV_88RC8180)
1348 return ((ddr_sz_read(i) & 0xf0) >> 4);
1349 if (dev == MV_DEV_88F6781)
1352 attr = (i == 0 ? 0xe :
1355 (i == 3 ? 0x7 : 0xff))));
1356 if (platform_io_coherent)
1368 if (dev == MV_DEV_88RC8180) {
1369 i = (ddr_sz_read(i) & 0xf0) >> 4;
1370 return (i == 0xe ? 0xc :
1373 (i == 0x7 ? 0xf : 0xc))));
1377 * On SOCs other than 88RC8180 Mbus unit ID for
1378 * DDR SDRAM controller is always 0x0.
1383 /**************************************************************************
1384 * CESA windows routines
1385 **************************************************************************/
1387 decode_win_cesa_valid(void)
1390 return (decode_win_can_cover_ddr(MV_WIN_CESA_MAX));
1394 decode_win_cesa_dump(u_long base)
1398 for (i = 0; i < MV_WIN_CESA_MAX; i++)
1399 printf("CESA window#%d: c 0x%08x, b 0x%08x\n", i,
1400 win_cesa_cr_read(base, i), win_cesa_br_read(base, i));
1404 * Set CESA decode windows.
1407 decode_win_cesa_setup(u_long base)
1413 for (i = 0; i < MV_WIN_CESA_MAX; i++) {
1414 win_cesa_cr_write(base, i, 0);
1415 win_cesa_br_write(base, i, 0);
1418 /* Only access to active DRAM banks is required */
1419 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1420 if (ddr_is_active(i)) {
1425 * Armada 38x SoC's equipped with 4GB DRAM
1426 * suffer freeze during CESA operation, if
1427 * MBUS window opened at given DRAM CS reaches
1428 * end of the address space. Apply a workaround
1429 * by setting the window size to the closest possible
1430 * value, i.e. divide it by 2.
1432 if ((soc_family == MV_SOC_ARMADA_38X) &&
1433 (size + ddr_base(i) == 0x100000000ULL))
1436 cr = (((size - 1) & 0xffff0000) |
1437 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
1438 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
1441 /* Set the first free CESA window */
1442 for (j = 0; j < MV_WIN_CESA_MAX; j++) {
1443 if (win_cesa_cr_read(base, j) & 0x1)
1446 win_cesa_br_write(base, j, br);
1447 win_cesa_cr_write(base, j, cr);
1455 decode_win_a38x_cesa_setup(u_long base)
1457 decode_win_cesa_setup(base);
1458 decode_win_cesa_setup(base + MV_WIN_CESA_OFFSET);
1462 decode_win_a38x_cesa_dump(u_long base)
1464 decode_win_cesa_dump(base);
1465 decode_win_cesa_dump(base + MV_WIN_CESA_OFFSET);
1468 /**************************************************************************
1469 * USB windows routines
1470 **************************************************************************/
1472 decode_win_usb_valid(void)
1475 return (decode_win_can_cover_ddr(MV_WIN_USB_MAX));
1479 decode_win_usb_dump(u_long base)
1483 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port - 1)))
1486 for (i = 0; i < MV_WIN_USB_MAX; i++)
1487 printf("USB window#%d: c 0x%08x, b 0x%08x\n", i,
1488 win_usb_cr_read(base, i), win_usb_br_read(base, i));
1492 * Set USB decode windows.
1495 decode_win_usb_setup(u_long base)
1500 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port)))
1505 for (i = 0; i < MV_WIN_USB_MAX; i++) {
1506 win_usb_cr_write(base, i, 0);
1507 win_usb_br_write(base, i, 0);
1510 /* Only access to active DRAM banks is required */
1511 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1512 if (ddr_is_active(i)) {
1515 * XXX for 6281 we should handle Mbus write
1516 * burst limit field in the ctrl reg
1518 cr = (((ddr_size(i) - 1) & 0xffff0000) |
1519 (ddr_attr(i) << 8) |
1520 (ddr_target(i) << 4) | 1);
1522 /* Set the first free USB window */
1523 for (j = 0; j < MV_WIN_USB_MAX; j++) {
1524 if (win_usb_cr_read(base, j) & 0x1)
1527 win_usb_br_write(base, j, br);
1528 win_usb_cr_write(base, j, cr);
1535 /**************************************************************************
1536 * USB3 windows routines
1537 **************************************************************************/
1539 decode_win_usb3_valid(void)
1542 return (decode_win_can_cover_ddr(MV_WIN_USB3_MAX));
1546 decode_win_usb3_dump(u_long base)
1550 for (i = 0; i < MV_WIN_USB3_MAX; i++)
1551 printf("USB3.0 window#%d: c 0x%08x, b 0x%08x\n", i,
1552 win_usb3_cr_read(base, i), win_usb3_br_read(base, i));
1556 * Set USB3 decode windows
1559 decode_win_usb3_setup(u_long base)
1564 for (i = 0; i < MV_WIN_USB3_MAX; i++) {
1565 win_usb3_cr_write(base, i, 0);
1566 win_usb3_br_write(base, i, 0);
1569 /* Only access to active DRAM banks is required */
1570 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1571 if (ddr_is_active(i)) {
1573 cr = (((ddr_size(i) - 1) &
1574 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT)) |
1575 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
1576 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
1579 /* Set the first free USB3.0 window */
1580 for (j = 0; j < MV_WIN_USB3_MAX; j++) {
1581 if (win_usb3_cr_read(base, j) & IO_WIN_ENA_MASK)
1584 win_usb3_br_write(base, j, br);
1585 win_usb3_cr_write(base, j, cr);
1592 /**************************************************************************
1593 * ETH windows routines
1594 **************************************************************************/
1597 win_eth_can_remap(int i)
1600 /* ETH encode windows 0-3 have remap capability */
1608 eth_bare_read(uint32_t base, int i)
1612 v = win_eth_bare_read(base);
1619 eth_bare_write(uint32_t base, int i, int val)
1623 v = win_eth_bare_read(base);
1626 win_eth_bare_write(base, v);
1630 eth_epap_write(uint32_t base, int i, int val)
1634 v = win_eth_epap_read(base);
1635 v &= ~(0x3 << (i * 2));
1636 v |= (val << (i * 2));
1637 win_eth_epap_write(base, v);
1641 decode_win_eth_dump(u_long base)
1645 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port - 1)))
1648 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1649 printf("ETH window#%d: b 0x%08x, s 0x%08x", i,
1650 win_eth_br_read(base, i),
1651 win_eth_sz_read(base, i));
1653 if (win_eth_can_remap(i))
1654 printf(", ha 0x%08x",
1655 win_eth_har_read(base, i));
1659 printf("ETH windows: bare 0x%08x, epap 0x%08x\n",
1660 win_eth_bare_read(base),
1661 win_eth_epap_read(base));
1664 #define MV_WIN_ETH_DDR_TRGT(n) ddr_target(n)
1667 decode_win_eth_setup(u_long base)
1672 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port)))
1677 /* Disable, clear and revoke protection for all ETH windows */
1678 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1679 eth_bare_write(base, i, 1);
1680 eth_epap_write(base, i, 0);
1681 win_eth_br_write(base, i, 0);
1682 win_eth_sz_write(base, i, 0);
1683 if (win_eth_can_remap(i))
1684 win_eth_har_write(base, i, 0);
1687 /* Only access to active DRAM banks is required */
1688 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1689 if (ddr_is_active(i)) {
1690 br = ddr_base(i) | (ddr_attr(i) << 8) | MV_WIN_ETH_DDR_TRGT(i);
1691 sz = ((ddr_size(i) - 1) & 0xffff0000);
1693 /* Set the first free ETH window */
1694 for (j = 0; j < MV_WIN_ETH_MAX; j++) {
1695 if (eth_bare_read(base, j) == 0)
1698 win_eth_br_write(base, j, br);
1699 win_eth_sz_write(base, j, sz);
1701 /* XXX remapping ETH windows not supported */
1703 /* Set protection RW */
1704 eth_epap_write(base, j, 0x3);
1707 eth_bare_write(base, j, 0);
1714 decode_win_neta_dump(u_long base)
1717 decode_win_eth_dump(base + MV_WIN_NETA_OFFSET);
1721 decode_win_neta_setup(u_long base)
1724 decode_win_eth_setup(base + MV_WIN_NETA_OFFSET);
1728 decode_win_eth_valid(void)
1731 return (decode_win_can_cover_ddr(MV_WIN_ETH_MAX));
1734 /**************************************************************************
1735 * PCIE windows routines
1736 **************************************************************************/
1738 decode_win_pcie_dump(u_long base)
1742 printf("PCIE windows base 0x%08lx\n", base);
1743 for (i = 0; i < MV_WIN_PCIE_MAX; i++)
1744 printf("PCIE window#%d: cr 0x%08x br 0x%08x remap 0x%08x\n",
1745 i, win_pcie_cr_read(base, i),
1746 win_pcie_br_read(base, i), win_pcie_remap_read(base, i));
1748 for (i = 0; i < MV_PCIE_BAR_MAX; i++)
1749 printf("PCIE bar#%d: cr 0x%08x br 0x%08x brh 0x%08x\n",
1750 i, pcie_bar_cr_read(base, i),
1751 pcie_bar_br_read(base, i), pcie_bar_brh_read(base, i));
1755 decode_win_pcie_setup(u_long base)
1757 uint32_t size = 0, ddrbase = ~0;
1761 for (i = 0; i < MV_PCIE_BAR_MAX; i++) {
1762 pcie_bar_br_write(base, i,
1763 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1765 pcie_bar_brh_write(base, i, 0);
1767 pcie_bar_cr_write(base, i, 0);
1770 for (i = 0; i < MV_WIN_PCIE_MAX; i++) {
1771 win_pcie_cr_write(base, i, 0);
1772 win_pcie_br_write(base, i, 0);
1773 win_pcie_remap_write(base, i, 0);
1776 /* On End-Point only set BAR size to 1MB regardless of DDR size */
1777 if ((bus_space_read_4(fdtbus_bs_tag, base, MV_PCIE_CONTROL)
1778 & MV_PCIE_ROOT_CMPLX) == 0) {
1779 pcie_bar_cr_write(base, 1, 0xf0000 | 1);
1783 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1784 if (ddr_is_active(i)) {
1785 /* Map DDR to BAR 1 */
1786 cr = (ddr_size(i) - 1) & 0xffff0000;
1787 size += ddr_size(i) & 0xffff0000;
1788 cr |= (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
1793 /* Use the first available PCIE window */
1794 for (j = 0; j < MV_WIN_PCIE_MAX; j++) {
1795 if (win_pcie_cr_read(base, j) != 0)
1798 win_pcie_br_write(base, j, br);
1799 win_pcie_cr_write(base, j, cr);
1806 * Upper 16 bits in BAR register is interpreted as BAR size
1807 * (in 64 kB units) plus 64kB, so subtract 0x10000
1808 * form value passed to register to get correct value.
1811 pcie_bar_cr_write(base, 1, size | 1);
1812 pcie_bar_br_write(base, 1, ddrbase |
1813 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1814 pcie_bar_br_write(base, 0, fdt_immr_pa |
1815 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1819 decode_win_pcie_valid(void)
1822 return (decode_win_can_cover_ddr(MV_WIN_PCIE_MAX));
1825 /**************************************************************************
1826 * IDMA windows routines
1827 **************************************************************************/
1828 #if defined(SOC_MV_ORION) || defined(SOC_MV_DISCOVERY)
1830 idma_bare_read(u_long base, int i)
1834 v = win_idma_bare_read(base);
1841 idma_bare_write(u_long base, int i, int val)
1845 v = win_idma_bare_read(base);
1848 win_idma_bare_write(base, v);
1852 * Sets channel protection 'val' for window 'w' on channel 'c'
1855 idma_cap_write(u_long base, int c, int w, int val)
1859 v = win_idma_cap_read(base, c);
1860 v &= ~(0x3 << (w * 2));
1861 v |= (val << (w * 2));
1862 win_idma_cap_write(base, c, v);
1866 * Set protection 'val' on all channels for window 'w'
1869 idma_set_prot(u_long base, int w, int val)
1873 for (c = 0; c < MV_IDMA_CHAN_MAX; c++)
1874 idma_cap_write(base, c, w, val);
1878 win_idma_can_remap(int i)
1881 /* IDMA decode windows 0-3 have remap capability */
1889 decode_win_idma_setup(u_long base)
1894 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
1897 * Disable and clear all IDMA windows, revoke protection for all channels
1899 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
1900 idma_bare_write(base, i, 1);
1901 win_idma_br_write(base, i, 0);
1902 win_idma_sz_write(base, i, 0);
1903 if (win_idma_can_remap(i) == 1)
1904 win_idma_har_write(base, i, 0);
1906 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
1907 win_idma_cap_write(base, i, 0);
1910 * Set up access to all active DRAM banks
1912 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1913 if (ddr_is_active(i)) {
1914 br = ddr_base(i) | (ddr_attr(i) << 8) | ddr_target(i);
1915 sz = ((ddr_size(i) - 1) & 0xffff0000);
1917 /* Place DDR entries in non-remapped windows */
1918 for (j = 0; j < MV_WIN_IDMA_MAX; j++)
1919 if (win_idma_can_remap(j) != 1 &&
1920 idma_bare_read(base, j) == 1) {
1921 /* Configure window */
1922 win_idma_br_write(base, j, br);
1923 win_idma_sz_write(base, j, sz);
1925 /* Set protection RW on all channels */
1926 idma_set_prot(base, j, 0x3);
1929 idma_bare_write(base, j, 0);
1935 * Remaining targets -- from statically defined table
1937 for (i = 0; i < idma_wins_no; i++)
1938 if (idma_wins[i].target > 0) {
1939 br = (idma_wins[i].base & 0xffff0000) |
1940 (idma_wins[i].attr << 8) | idma_wins[i].target;
1941 sz = ((idma_wins[i].size - 1) & 0xffff0000);
1943 /* Set the first free IDMA window */
1944 for (j = 0; j < MV_WIN_IDMA_MAX; j++) {
1945 if (idma_bare_read(base, j) == 0)
1948 /* Configure window */
1949 win_idma_br_write(base, j, br);
1950 win_idma_sz_write(base, j, sz);
1951 if (win_idma_can_remap(j) &&
1952 idma_wins[j].remap >= 0)
1953 win_idma_har_write(base, j,
1954 idma_wins[j].remap);
1956 /* Set protection RW on all channels */
1957 idma_set_prot(base, j, 0x3);
1960 idma_bare_write(base, j, 0);
1967 decode_win_idma_valid(void)
1969 const struct decode_win *wintab;
1973 if (idma_wins_no > MV_WIN_IDMA_MAX) {
1974 printf("IDMA windows: too many entries: %d\n", idma_wins_no);
1977 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
1978 if (ddr_is_active(i))
1981 if (idma_wins_no > (MV_WIN_IDMA_MAX - c)) {
1982 printf("IDMA windows: too many entries: %d, available: %d\n",
1983 idma_wins_no, MV_WIN_IDMA_MAX - c);
1989 for (i = 0; i < idma_wins_no; i++, wintab++) {
1990 if (wintab->target == 0) {
1991 printf("IDMA window#%d: DDR target window is not "
1992 "supposed to be reprogrammed!\n", i);
1996 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
1997 printf("IDMA window#%d: not capable of remapping, but "
1998 "val 0x%08x defined\n", i, wintab->remap);
2005 if (s > (0xFFFFFFFF - b + 1)) {
2006 /* XXX this boundary check should account for 64bit and
2008 printf("IDMA window#%d: no space for size 0x%08x at "
2009 "0x%08x\n", i, s, b);
2014 j = decode_win_overlap(i, idma_wins_no, &idma_wins[0]);
2016 printf("IDMA window#%d: (0x%08x - 0x%08x) overlaps "
2017 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
2019 idma_wins[j].base + idma_wins[j].size - 1);
2028 decode_win_idma_dump(u_long base)
2032 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
2035 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
2036 printf("IDMA window#%d: b 0x%08x, s 0x%08x", i,
2037 win_idma_br_read(base, i), win_idma_sz_read(base, i));
2039 if (win_idma_can_remap(i))
2040 printf(", ha 0x%08x", win_idma_har_read(base, i));
2044 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
2045 printf("IDMA channel#%d: ap 0x%08x\n", i,
2046 win_idma_cap_read(base, i));
2047 printf("IDMA windows: bare 0x%08x\n", win_idma_bare_read(base));
2051 /* Provide dummy functions to satisfy the build for SoCs not equipped with IDMA */
2053 decode_win_idma_valid(void)
2060 decode_win_idma_setup(u_long base)
2065 decode_win_idma_dump(u_long base)
2070 /**************************************************************************
2071 * XOR windows routines
2072 **************************************************************************/
2073 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
2075 xor_ctrl_read(u_long base, int i, int c, int e)
2078 v = win_xor_ctrl_read(base, c, e);
2085 xor_ctrl_write(u_long base, int i, int c, int e, int val)
2089 v = win_xor_ctrl_read(base, c, e);
2092 win_xor_ctrl_write(base, c, e, v);
2096 * Set channel protection 'val' for window 'w' on channel 'c'
2099 xor_chan_write(u_long base, int c, int e, int w, int val)
2103 v = win_xor_ctrl_read(base, c, e);
2104 v &= ~(0x3 << (w * 2 + 16));
2105 v |= (val << (w * 2 + 16));
2106 win_xor_ctrl_write(base, c, e, v);
2110 * Set protection 'val' on all channels for window 'w' on engine 'e'
2113 xor_set_prot(u_long base, int w, int e, int val)
2117 for (c = 0; c < MV_XOR_CHAN_MAX; c++)
2118 xor_chan_write(base, c, e, w, val);
2122 win_xor_can_remap(int i)
2125 /* XOR decode windows 0-3 have remap capability */
2139 case MV_DEV_88F6281:
2140 case MV_DEV_88F6282:
2141 case MV_DEV_MV78130:
2142 case MV_DEV_MV78160:
2143 case MV_DEV_MV78230:
2144 case MV_DEV_MV78260:
2145 case MV_DEV_MV78460:
2147 case MV_DEV_MV78100:
2148 case MV_DEV_MV78100_Z0:
2156 xor_active_dram(u_long base, int c, int e, int *window)
2162 * Set up access to all active DRAM banks
2165 for (i = 0; i < m; i++)
2166 if (ddr_is_active(i)) {
2167 br = ddr_base(i) | (ddr_attr(i) << 8) |
2169 sz = ((ddr_size(i) - 1) & 0xffff0000);
2171 /* Place DDR entries in non-remapped windows */
2172 for (w = 0; w < MV_WIN_XOR_MAX; w++)
2173 if (win_xor_can_remap(w) != 1 &&
2174 (xor_ctrl_read(base, w, c, e) == 0) &&
2176 /* Configure window */
2177 win_xor_br_write(base, w, e, br);
2178 win_xor_sz_write(base, w, e, sz);
2180 /* Set protection RW on all channels */
2181 xor_set_prot(base, w, e, 0x3);
2184 xor_ctrl_write(base, w, c, e, 1);
2192 decode_win_xor_setup(u_long base)
2195 int i, j, z, e = 1, m, window;
2197 if (pm_is_disabled(CPU_PM_CTRL_XOR))
2201 * Disable and clear all XOR windows, revoke protection for all
2205 for (j = 0; j < m; j++, e--) {
2206 /* Number of non-remaped windows */
2207 window = MV_XOR_NON_REMAP - 1;
2209 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
2210 win_xor_br_write(base, i, e, 0);
2211 win_xor_sz_write(base, i, e, 0);
2214 if (win_xor_can_remap(i) == 1)
2215 win_xor_har_write(base, i, e, 0);
2217 for (i = 0; i < MV_XOR_CHAN_MAX; i++) {
2218 win_xor_ctrl_write(base, i, e, 0);
2219 xor_active_dram(base, i, e, &window);
2223 * Remaining targets -- from a statically defined table
2225 for (i = 0; i < xor_wins_no; i++)
2226 if (xor_wins[i].target > 0) {
2227 br = (xor_wins[i].base & 0xffff0000) |
2228 (xor_wins[i].attr << 8) |
2230 sz = ((xor_wins[i].size - 1) & 0xffff0000);
2232 /* Set the first free XOR window */
2233 for (z = 0; z < MV_WIN_XOR_MAX; z++) {
2234 if (xor_ctrl_read(base, z, 0, e) &&
2235 xor_ctrl_read(base, z, 1, e))
2238 /* Configure window */
2239 win_xor_br_write(base, z, e, br);
2240 win_xor_sz_write(base, z, e, sz);
2241 if (win_xor_can_remap(z) &&
2242 xor_wins[z].remap >= 0)
2243 win_xor_har_write(base, z, e,
2246 /* Set protection RW on all channels */
2247 xor_set_prot(base, z, e, 0x3);
2250 xor_ctrl_write(base, z, 0, e, 1);
2251 xor_ctrl_write(base, z, 1, e, 1);
2259 decode_win_xor_valid(void)
2261 const struct decode_win *wintab;
2265 if (xor_wins_no > MV_WIN_XOR_MAX) {
2266 printf("XOR windows: too many entries: %d\n", xor_wins_no);
2269 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
2270 if (ddr_is_active(i))
2273 if (xor_wins_no > (MV_WIN_XOR_MAX - c)) {
2274 printf("XOR windows: too many entries: %d, available: %d\n",
2275 xor_wins_no, MV_WIN_IDMA_MAX - c);
2281 for (i = 0; i < xor_wins_no; i++, wintab++) {
2282 if (wintab->target == 0) {
2283 printf("XOR window#%d: DDR target window is not "
2284 "supposed to be reprogrammed!\n", i);
2288 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
2289 printf("XOR window#%d: not capable of remapping, but "
2290 "val 0x%08x defined\n", i, wintab->remap);
2297 if (s > (0xFFFFFFFF - b + 1)) {
2299 * XXX this boundary check should account for 64bit
2302 printf("XOR window#%d: no space for size 0x%08x at "
2303 "0x%08x\n", i, s, b);
2308 j = decode_win_overlap(i, xor_wins_no, &xor_wins[0]);
2310 printf("XOR window#%d: (0x%08x - 0x%08x) overlaps "
2311 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
2313 xor_wins[j].base + xor_wins[j].size - 1);
2322 decode_win_xor_dump(u_long base)
2327 if (pm_is_disabled(CPU_PM_CTRL_XOR))
2330 for (j = 0; j < xor_max_eng(); j++, e--) {
2331 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
2332 printf("XOR window#%d: b 0x%08x, s 0x%08x", i,
2333 win_xor_br_read(base, i, e), win_xor_sz_read(base, i, e));
2335 if (win_xor_can_remap(i))
2336 printf(", ha 0x%08x", win_xor_har_read(base, i, e));
2340 for (i = 0; i < MV_XOR_CHAN_MAX; i++)
2341 printf("XOR control#%d: 0x%08x\n", i,
2342 win_xor_ctrl_read(base, i, e));
2347 /* Provide dummy functions to satisfy the build for SoCs not equipped with XOR */
2349 decode_win_xor_valid(void)
2356 decode_win_xor_setup(u_long base)
2361 decode_win_xor_dump(u_long base)
2366 /**************************************************************************
2367 * SATA windows routines
2368 **************************************************************************/
2370 decode_win_sata_setup(u_long base)
2375 if (pm_is_disabled(CPU_PM_CTRL_SATA))
2378 for (i = 0; i < MV_WIN_SATA_MAX; i++) {
2379 win_sata_cr_write(base, i, 0);
2380 win_sata_br_write(base, i, 0);
2383 for (i = 0; i < MV_WIN_DDR_MAX; i++)
2384 if (ddr_is_active(i)) {
2385 cr = ((ddr_size(i) - 1) & 0xffff0000) |
2386 (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
2389 /* Use the first available SATA window */
2390 for (j = 0; j < MV_WIN_SATA_MAX; j++) {
2391 if ((win_sata_cr_read(base, j) & 1) != 0)
2394 win_sata_br_write(base, j, br);
2395 win_sata_cr_write(base, j, cr);
2402 * Configure AHCI decoding windows
2405 decode_win_ahci_setup(u_long base)
2407 uint32_t br, cr, sz;
2410 for (i = 0; i < MV_WIN_SATA_MAX_ARMADA38X; i++) {
2411 win_sata_armada38x_cr_write(base, i, 0);
2412 win_sata_armada38x_br_write(base, i, 0);
2413 win_sata_armada38x_sz_write(base, i, 0);
2416 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
2417 if (ddr_is_active(i)) {
2418 cr = (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
2419 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
2422 sz = (ddr_size(i) - 1) &
2423 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT);
2425 /* Use first available SATA window */
2426 for (j = 0; j < MV_WIN_SATA_MAX_ARMADA38X; j++) {
2427 if (win_sata_armada38x_cr_read(base, j) & IO_WIN_ENA_MASK)
2430 /* BASE is set to DRAM base (0x00000000) */
2431 win_sata_armada38x_br_write(base, j, br);
2432 /* CTRL targets DRAM ctrl with 0x0E or 0x0D */
2433 win_sata_armada38x_cr_write(base, j, cr);
2434 /* SIZE is set to 16MB - max value */
2435 win_sata_armada38x_sz_write(base, j, sz);
2443 decode_win_ahci_dump(u_long base)
2447 for (i = 0; i < MV_WIN_SATA_MAX_ARMADA38X; i++)
2448 printf("SATA window#%d: cr 0x%08x, br 0x%08x, sz 0x%08x\n", i,
2449 win_sata_armada38x_cr_read(base, i), win_sata_br_read(base, i),
2450 win_sata_armada38x_sz_read(base,i));
2454 decode_win_sata_valid(void)
2459 if (dev == MV_DEV_88F5281)
2462 return (decode_win_can_cover_ddr(MV_WIN_SATA_MAX));
2466 decode_win_sdhci_setup(u_long base)
2471 for (i = 0; i < MV_WIN_SDHCI_MAX; i++) {
2472 win_sdhci_cr_write(base, i, 0);
2473 win_sdhci_br_write(base, i, 0);
2476 for (i = 0; i < MV_WIN_DDR_MAX; i++)
2477 if (ddr_is_active(i)) {
2479 cr = (((ddr_size(i) - 1) &
2480 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT)) |
2481 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
2482 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
2485 /* Use the first available SDHCI window */
2486 for (j = 0; j < MV_WIN_SDHCI_MAX; j++) {
2487 if (win_sdhci_cr_read(base, j) & IO_WIN_ENA_MASK)
2490 win_sdhci_cr_write(base, j, cr);
2491 win_sdhci_br_write(base, j, br);
2498 decode_win_sdhci_dump(u_long base)
2502 for (i = 0; i < MV_WIN_SDHCI_MAX; i++)
2503 printf("SDHCI window#%d: c 0x%08x, b 0x%08x\n", i,
2504 win_sdhci_cr_read(base, i), win_sdhci_br_read(base, i));
2508 decode_win_sdhci_valid(void)
2511 return (decode_win_can_cover_ddr(MV_WIN_SDHCI_MAX));
2514 /**************************************************************************
2515 * FDT parsing routines.
2516 **************************************************************************/
2519 fdt_get_ranges(const char *nodename, void *buf, int size, int *tuples,
2523 pcell_t addr_cells, par_addr_cells, size_cells;
2524 int len, tuple_size, tuples_count;
2526 node = OF_finddevice(nodename);
2530 if ((fdt_addrsize_cells(node, &addr_cells, &size_cells)) != 0)
2533 par_addr_cells = fdt_parent_addr_cells(node);
2534 if (par_addr_cells > 2)
2537 tuple_size = sizeof(pcell_t) * (addr_cells + par_addr_cells +
2540 /* Note the OF_getprop_alloc() cannot be used at this early stage. */
2541 len = OF_getprop(node, "ranges", buf, size);
2544 * XXX this does not handle the empty 'ranges;' case, which is
2545 * legitimate and should be allowed.
2547 tuples_count = len / tuple_size;
2548 if (tuples_count <= 0)
2551 if (par_addr_cells > 2 || addr_cells > 2 || size_cells > 2)
2554 *tuples = tuples_count;
2555 *tuplesize = tuple_size;
2560 win_cpu_from_dt(void)
2564 int i, entry_size, err, t, tuple_size, tuples;
2565 u_long sram_base, sram_size;
2568 /* Retrieve 'ranges' property of '/localbus' node. */
2569 if ((err = fdt_get_ranges("/localbus", ranges, sizeof(ranges),
2570 &tuples, &tuple_size)) == 0) {
2572 * Fill CPU decode windows table.
2574 bzero((void *)&cpu_win_tbl, sizeof(cpu_win_tbl));
2576 entry_size = tuple_size / sizeof(pcell_t);
2577 cpu_wins_no = tuples;
2580 if (tuples > nitems(cpu_win_tbl)) {
2581 debugf("too many tuples to fit into cpu_win_tbl\n");
2585 for (i = 0, t = 0; t < tuples; i += entry_size, t++) {
2586 cpu_win_tbl[t].target = 1;
2587 cpu_win_tbl[t].attr = fdt32_to_cpu(ranges[i + 1]);
2588 cpu_win_tbl[t].base = fdt32_to_cpu(ranges[i + 2]);
2589 cpu_win_tbl[t].size = fdt32_to_cpu(ranges[i + 3]);
2590 cpu_win_tbl[t].remap = ~0;
2591 debugf("target = 0x%0x attr = 0x%0x base = 0x%0x "
2592 "size = 0x%0x remap = 0x%0x\n",
2593 cpu_win_tbl[t].target,
2594 cpu_win_tbl[t].attr, cpu_win_tbl[t].base,
2595 cpu_win_tbl[t].size, cpu_win_tbl[t].remap);
2600 * Retrieve CESA SRAM data.
2602 if ((node = OF_finddevice("sram")) != -1)
2603 if (ofw_bus_node_is_compatible(node, "mrvl,cesa-sram"))
2606 if ((node = OF_finddevice("/")) == -1)
2609 if ((node = fdt_find_compatible(node, "mrvl,cesa-sram", 0)) == 0)
2610 /* SRAM block is not always present. */
2613 sram_base = sram_size = 0;
2614 if (fdt_regsize(node, &sram_base, &sram_size) != 0)
2618 if (t >= nitems(cpu_win_tbl)) {
2619 debugf("cannot fit CESA tuple into cpu_win_tbl\n");
2623 cpu_win_tbl[t].target = soc_decode_win_spec->win_cesa_target;
2624 if (soc_family == MV_SOC_ARMADA_38X)
2625 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(0);
2627 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(1);
2628 cpu_win_tbl[t].base = sram_base;
2629 cpu_win_tbl[t].size = sram_size;
2630 cpu_win_tbl[t].remap = ~0;
2632 debugf("sram: base = 0x%0lx size = 0x%0lx\n", sram_base, sram_size);
2634 /* Check if there is a second CESA node */
2635 while ((node = OF_peer(node)) != 0) {
2636 if (ofw_bus_node_is_compatible(node, "mrvl,cesa-sram")) {
2637 if (fdt_regsize(node, &sram_base, &sram_size) != 0)
2647 if (t >= nitems(cpu_win_tbl)) {
2648 debugf("cannot fit CESA tuple into cpu_win_tbl\n");
2652 /* Configure window for CESA1 */
2653 cpu_win_tbl[t].target = soc_decode_win_spec->win_cesa_target;
2654 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(1);
2655 cpu_win_tbl[t].base = sram_base;
2656 cpu_win_tbl[t].size = sram_size;
2657 cpu_win_tbl[t].remap = ~0;
2659 debugf("sram: base = 0x%0lx size = 0x%0lx\n", sram_base, sram_size);
2665 fdt_win_process(phandle_t child)
2669 for (i = 0; soc_nodes[i].compat != NULL; i++) {
2670 /* Setup only for enabled devices */
2671 if (ofw_bus_node_status_okay(child) == 0)
2674 if (!ofw_bus_node_is_compatible(child, soc_nodes[i].compat))
2677 ret = fdt_win_process_child(child, &soc_nodes[i], "reg");
2686 fdt_win_process_child(phandle_t child, struct soc_node_spec *soc_node,
2687 const char* mimo_reg_source)
2689 int addr_cells, size_cells;
2693 if (fdt_addrsize_cells(OF_parent(child), &addr_cells,
2697 if ((sizeof(pcell_t) * (addr_cells + size_cells)) > sizeof(reg))
2699 if (OF_getprop(child, mimo_reg_source, ®, sizeof(reg)) <= 0)
2702 if (addr_cells <= 2)
2703 base = fdt_data_get(®[0], addr_cells);
2705 base = fdt_data_get(®[addr_cells - 2], 2);
2706 fdt_data_get(®[addr_cells], size_cells);
2708 if (soc_node->valid_handler != NULL)
2709 if (!soc_node->valid_handler())
2712 base = (base & 0x000fffff) | fdt_immr_va;
2713 if (soc_node->decode_handler != NULL)
2714 soc_node->decode_handler(base);
2718 if (MV_DUMP_WIN && (soc_node->dump_handler != NULL))
2719 soc_node->dump_handler(base);
2727 phandle_t node, child, sb;
2728 phandle_t child_pci;
2732 node = OF_finddevice("/");
2734 panic("fdt_win_setup: no root node");
2736 /* Allow for coherent transactions on the A38x MBUS */
2737 if (ofw_bus_node_is_compatible(node, "marvell,armada380"))
2738 platform_io_coherent = true;
2741 * Traverse through all children of root and simple-bus nodes.
2742 * For each found device retrieve decode windows data (if applicable).
2744 child = OF_child(node);
2745 while (child != 0) {
2746 /* Lookup for callback and run */
2747 err = fdt_win_process(child);
2751 /* Process Marvell Armada-XP/38x PCIe controllers */
2752 if (ofw_bus_node_is_compatible(child, "marvell,armada-370-pcie")) {
2753 child_pci = OF_child(child);
2754 while (child_pci != 0) {
2755 err = fdt_win_process_child(child_pci,
2756 &soc_nodes[SOC_NODE_PCIE_ENTRY_IDX],
2757 "assigned-addresses");
2761 child_pci = OF_peer(child_pci);
2766 * Once done with root-level children let's move down to
2767 * simple-bus and its children.
2769 child = OF_peer(child);
2770 if ((child == 0) && (node == OF_finddevice("/"))) {
2771 sb = node = fdt_find_compatible(node, "simple-bus", 0);
2774 child = OF_child(node);
2777 * Next, move one more level down to internal-regs node (if
2778 * it is present) and its children. This node also have
2779 * "simple-bus" compatible.
2781 if ((child == 0) && (node == sb)) {
2782 node = fdt_find_compatible(node, "simple-bus", 0);
2785 child = OF_child(node);
2793 fdt_fixup_busfreq(phandle_t root)
2798 freq = cpu_to_fdt32(get_tclk());
2801 * Fix bus speed in cpu node
2803 if ((sb = OF_finddevice("cpu")) != -1)
2804 if (fdt_is_compatible_strict(sb, "ARM,88VS584"))
2805 OF_setprop(sb, "bus-frequency", (void *)&freq,
2809 * This fixup sets the simple-bus bus-frequency property.
2811 if ((sb = fdt_find_compatible(root, "simple-bus", 1)) != 0)
2812 OF_setprop(sb, "bus-frequency", (void *)&freq, sizeof(freq));
2816 fdt_fixup_ranges(phandle_t root)
2819 pcell_t par_addr_cells, addr_cells, size_cells;
2820 pcell_t ranges[3], reg[2], *rangesptr;
2821 int len, tuple_size, tuples_count;
2824 /* Fix-up SoC ranges according to real fdt_immr_pa */
2825 if ((node = fdt_find_compatible(root, "simple-bus", 1)) != 0) {
2826 if (fdt_addrsize_cells(node, &addr_cells, &size_cells) == 0 &&
2827 ((par_addr_cells = fdt_parent_addr_cells(node)) <= 2)) {
2828 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2829 addr_cells + size_cells);
2830 len = OF_getprop(node, "ranges", ranges,
2832 tuples_count = len / tuple_size;
2833 /* Unexpected settings are not supported */
2834 if (tuples_count != 1)
2837 rangesptr = &ranges[0];
2838 rangesptr += par_addr_cells;
2839 base = fdt_data_get((void *)rangesptr, addr_cells);
2840 *rangesptr = cpu_to_fdt32(fdt_immr_pa);
2841 if (OF_setprop(node, "ranges", (void *)&ranges[0],
2842 sizeof(ranges)) < 0)
2847 /* Fix-up PCIe reg according to real PCIe registers' PA */
2848 if ((node = fdt_find_compatible(root, "mrvl,pcie", 1)) != 0) {
2849 if (fdt_addrsize_cells(OF_parent(node), &par_addr_cells,
2850 &size_cells) == 0) {
2851 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2853 len = OF_getprop(node, "reg", reg, sizeof(reg));
2854 tuples_count = len / tuple_size;
2855 /* Unexpected settings are not supported */
2856 if (tuples_count != 1)
2859 base = fdt_data_get((void *)®[0], par_addr_cells);
2860 base &= ~0xFF000000;
2861 base |= fdt_immr_pa;
2862 reg[0] = cpu_to_fdt32(base);
2863 if (OF_setprop(node, "reg", (void *)®[0],
2868 /* Fix-up succeeded. May return and continue */
2874 * In case of any error while fixing ranges just hang.
2875 * 1. No message can be displayed yet since console
2876 * is not initialized.
2877 * 2. Going further will cause failure on bus_space_map()
2878 * relying on the wrong ranges or data abort when
2879 * accessing PCIe registers.
2884 struct fdt_fixup_entry fdt_fixup_table[] = {
2885 { "mrvl,DB-88F6281", &fdt_fixup_busfreq },
2886 { "mrvl,DB-78460", &fdt_fixup_busfreq },
2887 { "mrvl,DB-78460", &fdt_fixup_ranges },
2895 if (soc_decode_win_spec->get_tclk != NULL)
2896 return soc_decode_win_spec->get_tclk();
2905 if (soc_decode_win_spec->get_cpu_freq != NULL)
2906 return soc_decode_win_spec->get_cpu_freq();