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;
268 struct decode_win_spec *soc_decode_win_spec;
270 static struct decode_win_spec decode_win_specs[] =
273 &read_cpu_ctrl_armv7,
274 &write_cpu_ctrl_armv7,
275 &win_cpu_armv7_cr_read,
276 &win_cpu_armv7_br_read,
277 &win_cpu_armv7_remap_l_read,
278 &win_cpu_armv7_remap_h_read,
279 &win_cpu_armv7_cr_write,
280 &win_cpu_armv7_br_write,
281 &win_cpu_armv7_remap_l_write,
282 &win_cpu_armv7_remap_h_write,
283 MV_WIN_CPU_MAX_ARMV7,
284 &mv_win_cesa_attr_armada38x,
285 MV_WIN_CESA_TARGET_ARMADA38X,
292 &get_cpu_freq_armada38x,
296 &read_cpu_ctrl_armv7,
297 &write_cpu_ctrl_armv7,
298 &win_cpu_armv7_cr_read,
299 &win_cpu_armv7_br_read,
300 &win_cpu_armv7_remap_l_read,
301 &win_cpu_armv7_remap_h_read,
302 &win_cpu_armv7_cr_write,
303 &win_cpu_armv7_br_write,
304 &win_cpu_armv7_remap_l_write,
305 &win_cpu_armv7_remap_h_write,
306 MV_WIN_CPU_MAX_ARMV7,
307 &mv_win_cesa_attr_armadaxp,
308 MV_WIN_CESA_TARGET_ARMADAXP,
315 &get_cpu_freq_armadaxp,
319 &read_cpu_ctrl_armv5,
320 &write_cpu_ctrl_armv5,
321 &win_cpu_armv5_cr_read,
322 &win_cpu_armv5_br_read,
323 &win_cpu_armv5_remap_l_read,
324 &win_cpu_armv5_remap_h_read,
325 &win_cpu_armv5_cr_write,
326 &win_cpu_armv5_br_write,
327 &win_cpu_armv5_remap_l_write,
328 &win_cpu_armv5_remap_h_write,
330 &mv_win_cesa_attr_armv5,
343 struct fdt_pm_mask_entry {
348 static struct fdt_pm_mask_entry fdt_pm_mask_table[] = {
349 { "mrvl,ge", CPU_PM_CTRL_GE(0) },
350 { "mrvl,ge", CPU_PM_CTRL_GE(1) },
351 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(0) },
352 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(1) },
353 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(2) },
354 { "mrvl,xor", CPU_PM_CTRL_XOR },
355 { "mrvl,sata", CPU_PM_CTRL_SATA },
360 pm_is_disabled(uint32_t mask)
362 #if SOC_MV_POWER_STAT_SUPPORTED
363 return (soc_power_ctrl_get(mask) == mask ? 0 : 1);
370 * Disable device using power management register.
371 * 1 - Device Power On
372 * 0 - Device Power Off
373 * Mask can be set in loader.
375 * loader> set hw.pm-disable-mask=0x2
378 * |-------------------------------|
379 * | Device | Kirkwood | Discovery |
380 * |-------------------------------|
381 * | USB0 | 0x00008 | 0x020000 |
382 * |-------------------------------|
383 * | USB1 | - | 0x040000 |
384 * |-------------------------------|
385 * | USB2 | - | 0x080000 |
386 * |-------------------------------|
387 * | GE0 | 0x00001 | 0x000002 |
388 * |-------------------------------|
389 * | GE1 | - | 0x000004 |
390 * |-------------------------------|
391 * | IDMA | - | 0x100000 |
392 * |-------------------------------|
393 * | XOR | 0x10000 | 0x200000 |
394 * |-------------------------------|
395 * | CESA | 0x20000 | 0x400000 |
396 * |-------------------------------|
397 * | SATA | 0x04000 | 0x004000 |
398 * --------------------------------|
399 * This feature can be used only on Kirkwood and Discovery
403 static int mv_win_cesa_attr_armv5(int eng_sel)
406 return MV_WIN_CESA_ATTR(eng_sel);
409 static int mv_win_cesa_attr_armada38x(int eng_sel)
412 return MV_WIN_CESA_ATTR_ARMADA38X(eng_sel);
415 static int mv_win_cesa_attr_armadaxp(int eng_sel)
418 return MV_WIN_CESA_ATTR_ARMADAXP(eng_sel);
422 mv_check_soc_family()
431 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMADA_XP];
432 soc_family = MV_SOC_ARMADA_XP;
437 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMADA_38X];
438 soc_family = MV_SOC_ARMADA_38X;
444 case MV_DEV_88RC8180:
445 case MV_DEV_88RC9480:
446 case MV_DEV_88RC9580:
449 case MV_DEV_MV78100_Z0:
452 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMV5];
453 soc_family = MV_SOC_ARMV5;
456 soc_family = MV_SOC_UNSUPPORTED;
457 return (MV_SOC_UNSUPPORTED);
460 soc_identify(dev, rev);
466 pm_disable_device(int mask)
471 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
472 printf("Power Management Register: 0%x\n", reg);
475 soc_power_ctrl_set(reg);
476 printf("Device %x is disabled\n", mask);
478 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
479 printf("Power Management Register: 0%x\n", reg);
484 mv_fdt_is_type(phandle_t node, const char *typestr)
486 #define FDT_TYPE_LEN 64
487 char type[FDT_TYPE_LEN];
489 if (OF_getproplen(node, "device_type") <= 0)
492 if (OF_getprop(node, "device_type", type, FDT_TYPE_LEN) < 0)
495 if (strncasecmp(type, typestr, FDT_TYPE_LEN) == 0)
504 mv_fdt_pm(phandle_t node)
506 uint32_t cpu_pm_ctrl;
510 cpu_pm_ctrl = read_cpu_ctrl(CPU_PM_CTRL);
511 for (i = 0; fdt_pm_mask_table[i].compat != NULL; i++) {
512 if (dev_mask & (1 << i))
515 compat = ofw_bus_node_is_compatible(node,
516 fdt_pm_mask_table[i].compat);
517 #if defined(SOC_MV_KIRKWOOD)
518 if (compat && (cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
519 dev_mask |= (1 << i);
523 dev_mask |= (1 << i);
527 if (compat && (~cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
528 dev_mask |= (1 << i);
532 dev_mask |= (1 << i);
542 read_cpu_ctrl(uint32_t reg)
545 if (soc_decode_win_spec->read_cpu_ctrl != NULL)
546 return (soc_decode_win_spec->read_cpu_ctrl(reg));
551 read_cpu_ctrl_armv5(uint32_t reg)
554 return (bus_space_read_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg));
558 read_cpu_ctrl_armv7(uint32_t reg)
561 return (bus_space_read_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE_ARMV7, reg));
565 write_cpu_ctrl(uint32_t reg, uint32_t val)
568 if (soc_decode_win_spec->write_cpu_ctrl != NULL)
569 soc_decode_win_spec->write_cpu_ctrl(reg, val);
573 write_cpu_ctrl_armv5(uint32_t reg, uint32_t val)
576 bus_space_write_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg, val);
580 write_cpu_ctrl_armv7(uint32_t reg, uint32_t val)
583 bus_space_write_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE_ARMV7, reg, val);
587 read_cpu_mp_clocks(uint32_t reg)
590 return (bus_space_read_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg));
594 write_cpu_mp_clocks(uint32_t reg, uint32_t val)
597 bus_space_write_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg, val);
601 read_cpu_misc(uint32_t reg)
604 return (bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE, reg));
608 write_cpu_misc(uint32_t reg, uint32_t val)
611 bus_space_write_4(fdtbus_bs_tag, MV_MISC_BASE, reg, val);
625 case MV_DEV_88RC8180:
626 case MV_DEV_MV78100_Z0:
628 __asm __volatile("mrc p15, 1, %0, c15, c1, 0" : "=r" (ef));
632 __asm __volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (ef));
636 printf("This ARM Core does not support any extra features\n");
643 * Get the power status of device. This feature is only supported on
644 * Kirkwood and Discovery SoCs.
647 soc_power_ctrl_get(uint32_t mask)
650 #if SOC_MV_POWER_STAT_SUPPORTED
651 if (mask != CPU_PM_CTRL_NONE)
652 mask &= read_cpu_ctrl(CPU_PM_CTRL);
661 * Set the power status of device. This feature is only supported on
662 * Kirkwood and Discovery SoCs.
665 soc_power_ctrl_set(uint32_t mask)
668 #if !defined(SOC_MV_ORION)
669 if (mask != CPU_PM_CTRL_NONE)
670 write_cpu_ctrl(CPU_PM_CTRL, mask);
675 soc_id(uint32_t *dev, uint32_t *rev)
677 uint64_t mv_pcie_base = MV_PCIE_BASE;
681 * Notice: system identifiers are available in the registers range of
682 * PCIE controller, so using this function is only allowed (and
683 * possible) after the internal registers range has been mapped in via
684 * devmap_bootstrap().
688 if ((node = OF_finddevice("/")) == -1)
690 if (ofw_bus_node_is_compatible(node, "marvell,armada380"))
691 mv_pcie_base = MV_PCIE_BASE_ARMADA38X;
693 *dev = bus_space_read_4(fdtbus_bs_tag, mv_pcie_base, 0) >> 16;
694 *rev = bus_space_read_4(fdtbus_bs_tag, mv_pcie_base, 8) & 0xff;
698 soc_identify(uint32_t d, uint32_t r)
700 uint32_t size, mode, freq;
706 printf("(0x%4x:0x%02x) ", d, r);
711 dev = "Marvell 88F5181";
716 dev = "Marvell 88F5182";
721 dev = "Marvell 88F5281";
730 dev = "Marvell 88F6281";
738 case MV_DEV_88RC8180:
739 dev = "Marvell 88RC8180";
741 case MV_DEV_88RC9480:
742 dev = "Marvell 88RC9480";
744 case MV_DEV_88RC9580:
745 dev = "Marvell 88RC9580";
748 dev = "Marvell 88F6781";
753 dev = "Marvell 88F6282";
760 dev = "Marvell 88F6828";
763 dev = "Marvell 88F6820";
766 dev = "Marvell 88F6810";
768 case MV_DEV_MV78100_Z0:
769 dev = "Marvell MV78100 Z0";
772 dev = "Marvell MV78100";
775 dev = "Marvell MV78160";
778 dev = "Marvell MV78260";
781 dev = "Marvell MV78460";
790 printf(" rev %s", rev);
791 printf(", TClock %dMHz", get_tclk() / 1000 / 1000);
792 freq = get_cpu_freq();
794 printf(", Frequency %dMHz", freq / 1000 / 1000);
797 mode = read_cpu_ctrl(CPU_CONFIG);
798 printf(" Instruction cache prefetch %s, data cache prefetch %s\n",
799 (mode & CPU_CONFIG_IC_PREF) ? "enabled" : "disabled",
800 (mode & CPU_CONFIG_DC_PREF) ? "enabled" : "disabled");
805 mode = read_cpu_ctrl(CPU_L2_CONFIG) & CPU_L2_CONFIG_MODE;
806 printf(" 256KB 4-way set-associative %s unified L2 cache\n",
807 mode ? "write-through" : "write-back");
810 mode = read_cpu_ctrl(CPU_CONTROL);
811 size = mode & CPU_CONTROL_L2_SIZE;
812 mode = mode & CPU_CONTROL_L2_MODE;
813 printf(" %s set-associative %s unified L2 cache\n",
814 size ? "256KB 4-way" : "512KB 8-way",
815 mode ? "write-through" : "write-back");
824 mv_enter_debugger(void *dummy)
827 if (boothowto & RB_KDB)
828 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
830 SYSINIT(mv_enter_debugger, SI_SUB_CPU, SI_ORDER_ANY, mv_enter_debugger, NULL);
840 TUNABLE_INT_FETCH("hw.pm-disable-mask", &mask);
843 pm_disable_device(mask);
845 /* Retrieve data about physical addresses from device tree. */
846 if ((err = win_cpu_from_dt()) != 0)
849 /* Retrieve our ID: some windows facilities vary between SoC models */
852 if (soc_family == MV_SOC_ARMADA_XP)
853 if ((err = decode_win_sdram_fixup()) != 0)
856 decode_win_cpu_setup();
858 soc_dump_decode_win();
862 if ((err = fdt_win_setup()) != 0)
868 /**************************************************************************
869 * Decode windows registers accessors
870 **************************************************************************/
871 WIN_REG_IDX_RD(win_cpu_armv5, cr, MV_WIN_CPU_CTRL_ARMV5, MV_MBUS_BRIDGE_BASE)
872 WIN_REG_IDX_RD(win_cpu_armv5, br, MV_WIN_CPU_BASE_ARMV5, MV_MBUS_BRIDGE_BASE)
873 WIN_REG_IDX_RD(win_cpu_armv5, remap_l, MV_WIN_CPU_REMAP_LO_ARMV5, MV_MBUS_BRIDGE_BASE)
874 WIN_REG_IDX_RD(win_cpu_armv5, remap_h, MV_WIN_CPU_REMAP_HI_ARMV5, MV_MBUS_BRIDGE_BASE)
875 WIN_REG_IDX_WR(win_cpu_armv5, cr, MV_WIN_CPU_CTRL_ARMV5, MV_MBUS_BRIDGE_BASE)
876 WIN_REG_IDX_WR(win_cpu_armv5, br, MV_WIN_CPU_BASE_ARMV5, MV_MBUS_BRIDGE_BASE)
877 WIN_REG_IDX_WR(win_cpu_armv5, remap_l, MV_WIN_CPU_REMAP_LO_ARMV5, MV_MBUS_BRIDGE_BASE)
878 WIN_REG_IDX_WR(win_cpu_armv5, remap_h, MV_WIN_CPU_REMAP_HI_ARMV5, MV_MBUS_BRIDGE_BASE)
880 WIN_REG_IDX_RD(win_cpu_armv7, cr, MV_WIN_CPU_CTRL_ARMV7, MV_MBUS_BRIDGE_BASE)
881 WIN_REG_IDX_RD(win_cpu_armv7, br, MV_WIN_CPU_BASE_ARMV7, MV_MBUS_BRIDGE_BASE)
882 WIN_REG_IDX_RD(win_cpu_armv7, remap_l, MV_WIN_CPU_REMAP_LO_ARMV7, MV_MBUS_BRIDGE_BASE)
883 WIN_REG_IDX_RD(win_cpu_armv7, remap_h, MV_WIN_CPU_REMAP_HI_ARMV7, MV_MBUS_BRIDGE_BASE)
884 WIN_REG_IDX_WR(win_cpu_armv7, cr, MV_WIN_CPU_CTRL_ARMV7, MV_MBUS_BRIDGE_BASE)
885 WIN_REG_IDX_WR(win_cpu_armv7, br, MV_WIN_CPU_BASE_ARMV7, MV_MBUS_BRIDGE_BASE)
886 WIN_REG_IDX_WR(win_cpu_armv7, remap_l, MV_WIN_CPU_REMAP_LO_ARMV7, MV_MBUS_BRIDGE_BASE)
887 WIN_REG_IDX_WR(win_cpu_armv7, remap_h, MV_WIN_CPU_REMAP_HI_ARMV7, MV_MBUS_BRIDGE_BASE)
890 win_cpu_cr_read(int i)
893 if (soc_decode_win_spec->cr_read != NULL)
894 return (soc_decode_win_spec->cr_read(i));
899 win_cpu_br_read(int i)
902 if (soc_decode_win_spec->br_read != NULL)
903 return (soc_decode_win_spec->br_read(i));
908 win_cpu_remap_l_read(int i)
911 if (soc_decode_win_spec->remap_l_read != NULL)
912 return (soc_decode_win_spec->remap_l_read(i));
917 win_cpu_remap_h_read(int i)
920 if (soc_decode_win_spec->remap_h_read != NULL)
921 return soc_decode_win_spec->remap_h_read(i);
926 win_cpu_cr_write(int i, uint32_t val)
929 if (soc_decode_win_spec->cr_write != NULL)
930 soc_decode_win_spec->cr_write(i, val);
934 win_cpu_br_write(int i, uint32_t val)
937 if (soc_decode_win_spec->br_write != NULL)
938 soc_decode_win_spec->br_write(i, val);
942 win_cpu_remap_l_write(int i, uint32_t val)
945 if (soc_decode_win_spec->remap_l_write != NULL)
946 soc_decode_win_spec->remap_l_write(i, val);
950 win_cpu_remap_h_write(int i, uint32_t val)
953 if (soc_decode_win_spec->remap_h_write != NULL)
954 soc_decode_win_spec->remap_h_write(i, val);
957 WIN_REG_BASE_IDX_RD(win_cesa, cr, MV_WIN_CESA_CTRL)
958 WIN_REG_BASE_IDX_RD(win_cesa, br, MV_WIN_CESA_BASE)
959 WIN_REG_BASE_IDX_WR(win_cesa, cr, MV_WIN_CESA_CTRL)
960 WIN_REG_BASE_IDX_WR(win_cesa, br, MV_WIN_CESA_BASE)
962 WIN_REG_BASE_IDX_RD(win_usb, cr, MV_WIN_USB_CTRL)
963 WIN_REG_BASE_IDX_RD(win_usb, br, MV_WIN_USB_BASE)
964 WIN_REG_BASE_IDX_WR(win_usb, cr, MV_WIN_USB_CTRL)
965 WIN_REG_BASE_IDX_WR(win_usb, br, MV_WIN_USB_BASE)
967 WIN_REG_BASE_IDX_RD(win_usb3, cr, MV_WIN_USB3_CTRL)
968 WIN_REG_BASE_IDX_RD(win_usb3, br, MV_WIN_USB3_BASE)
969 WIN_REG_BASE_IDX_WR(win_usb3, cr, MV_WIN_USB3_CTRL)
970 WIN_REG_BASE_IDX_WR(win_usb3, br, MV_WIN_USB3_BASE)
972 WIN_REG_BASE_IDX_RD(win_eth, br, MV_WIN_ETH_BASE)
973 WIN_REG_BASE_IDX_RD(win_eth, sz, MV_WIN_ETH_SIZE)
974 WIN_REG_BASE_IDX_RD(win_eth, har, MV_WIN_ETH_REMAP)
975 WIN_REG_BASE_IDX_WR(win_eth, br, MV_WIN_ETH_BASE)
976 WIN_REG_BASE_IDX_WR(win_eth, sz, MV_WIN_ETH_SIZE)
977 WIN_REG_BASE_IDX_WR(win_eth, har, MV_WIN_ETH_REMAP)
979 WIN_REG_BASE_RD(win_eth, bare, 0x290)
980 WIN_REG_BASE_RD(win_eth, epap, 0x294)
981 WIN_REG_BASE_WR(win_eth, bare, 0x290)
982 WIN_REG_BASE_WR(win_eth, epap, 0x294)
984 WIN_REG_BASE_IDX_RD(win_pcie, cr, MV_WIN_PCIE_CTRL);
985 WIN_REG_BASE_IDX_RD(win_pcie, br, MV_WIN_PCIE_BASE);
986 WIN_REG_BASE_IDX_RD(win_pcie, remap, MV_WIN_PCIE_REMAP);
987 WIN_REG_BASE_IDX_WR(win_pcie, cr, MV_WIN_PCIE_CTRL);
988 WIN_REG_BASE_IDX_WR(win_pcie, br, MV_WIN_PCIE_BASE);
989 WIN_REG_BASE_IDX_WR(win_pcie, remap, MV_WIN_PCIE_REMAP);
990 WIN_REG_BASE_IDX_RD(pcie_bar, br, MV_PCIE_BAR_BASE);
991 WIN_REG_BASE_IDX_RD(pcie_bar, brh, MV_PCIE_BAR_BASE_H);
992 WIN_REG_BASE_IDX_RD(pcie_bar, cr, MV_PCIE_BAR_CTRL);
993 WIN_REG_BASE_IDX_WR(pcie_bar, br, MV_PCIE_BAR_BASE);
994 WIN_REG_BASE_IDX_WR(pcie_bar, brh, MV_PCIE_BAR_BASE_H);
995 WIN_REG_BASE_IDX_WR(pcie_bar, cr, MV_PCIE_BAR_CTRL);
997 WIN_REG_BASE_IDX_RD(win_sata, cr, MV_WIN_SATA_CTRL);
998 WIN_REG_BASE_IDX_RD(win_sata, br, MV_WIN_SATA_BASE);
999 WIN_REG_BASE_IDX_WR(win_sata, cr, MV_WIN_SATA_CTRL);
1000 WIN_REG_BASE_IDX_WR(win_sata, br, MV_WIN_SATA_BASE);
1002 WIN_REG_BASE_IDX_RD(win_sata_armada38x, sz, MV_WIN_SATA_SIZE_ARMADA38X);
1003 WIN_REG_BASE_IDX_WR(win_sata_armada38x, sz, MV_WIN_SATA_SIZE_ARMADA38X);
1004 WIN_REG_BASE_IDX_RD(win_sata_armada38x, cr, MV_WIN_SATA_CTRL_ARMADA38X);
1005 WIN_REG_BASE_IDX_WR(win_sata_armada38x, cr, MV_WIN_SATA_CTRL_ARMADA38X);
1006 WIN_REG_BASE_IDX_WR(win_sata_armada38x, br, MV_WIN_SATA_BASE_ARMADA38X);
1008 WIN_REG_BASE_IDX_RD(win_sdhci, cr, MV_WIN_SDHCI_CTRL);
1009 WIN_REG_BASE_IDX_RD(win_sdhci, br, MV_WIN_SDHCI_BASE);
1010 WIN_REG_BASE_IDX_WR(win_sdhci, cr, MV_WIN_SDHCI_CTRL);
1011 WIN_REG_BASE_IDX_WR(win_sdhci, br, MV_WIN_SDHCI_BASE);
1014 WIN_REG_IDX_RD(ddr_armv5, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
1015 WIN_REG_IDX_RD(ddr_armv5, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
1016 WIN_REG_IDX_WR(ddr_armv5, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
1017 WIN_REG_IDX_WR(ddr_armv5, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
1019 WIN_REG_IDX_RD(ddr_armv7, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE_ARMV7)
1020 WIN_REG_IDX_RD(ddr_armv7, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE_ARMV7)
1021 WIN_REG_IDX_WR(ddr_armv7, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE_ARMV7)
1022 WIN_REG_IDX_WR(ddr_armv7, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE_ARMV7)
1024 static inline uint32_t
1028 if (soc_decode_win_spec->ddr_br_read != NULL)
1029 return (soc_decode_win_spec->ddr_br_read(i));
1033 static inline uint32_t
1037 if (soc_decode_win_spec->ddr_sz_read != NULL)
1038 return (soc_decode_win_spec->ddr_sz_read(i));
1043 ddr_br_write(int i, uint32_t val)
1046 if (soc_decode_win_spec->ddr_br_write != NULL)
1047 soc_decode_win_spec->ddr_br_write(i, val);
1051 ddr_sz_write(int i, uint32_t val)
1054 if (soc_decode_win_spec->ddr_sz_write != NULL)
1055 soc_decode_win_spec->ddr_sz_write(i, val);
1059 * On 88F6781 (Dove) SoC DDR Controller is accessed through
1060 * single MBUS <-> AXI bridge. In this case we provide emulated
1061 * ddr_br_read() and ddr_sz_read() functions to keep compatibility
1062 * with common decoding windows setup code.
1065 static inline uint32_t ddr_br_read(int i)
1069 /* Read Memory Address Map Register for CS i */
1070 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
1072 /* Return CS i base address */
1073 return (mmap & 0xFF000000);
1076 static inline uint32_t ddr_sz_read(int i)
1078 uint32_t mmap, size;
1080 /* Read Memory Address Map Register for CS i */
1081 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
1083 /* Extract size of CS space in 64kB units */
1084 size = (1 << ((mmap >> 16) & 0x0F));
1086 /* Return CS size and enable/disable status */
1087 return (((size - 1) << 16) | (mmap & 0x01));
1091 /**************************************************************************
1092 * Decode windows helper routines
1093 **************************************************************************/
1095 soc_dump_decode_win(void)
1099 for (i = 0; i < soc_decode_win_spec->mv_win_cpu_max; i++) {
1100 printf("CPU window#%d: c 0x%08x, b 0x%08x", i,
1102 win_cpu_br_read(i));
1104 if (win_cpu_can_remap(i))
1105 printf(", rl 0x%08x, rh 0x%08x",
1106 win_cpu_remap_l_read(i),
1107 win_cpu_remap_h_read(i));
1111 printf("Internal regs base: 0x%08x\n",
1112 bus_space_read_4(fdtbus_bs_tag, MV_INTREGS_BASE, 0));
1114 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1115 printf("DDR CS#%d: b 0x%08x, s 0x%08x\n", i,
1116 ddr_br_read(i), ddr_sz_read(i));
1119 /**************************************************************************
1120 * CPU windows routines
1121 **************************************************************************/
1123 win_cpu_can_remap(int i)
1129 /* Depending on the SoC certain windows have remap capability */
1130 if ((dev == MV_DEV_88F5182 && i < 2) ||
1131 (dev == MV_DEV_88F5281 && i < 4) ||
1132 (dev == MV_DEV_88F6281 && i < 4) ||
1133 (dev == MV_DEV_88F6282 && i < 4) ||
1134 (dev == MV_DEV_88F6828 && i < 20) ||
1135 (dev == MV_DEV_88F6820 && i < 20) ||
1136 (dev == MV_DEV_88F6810 && i < 20) ||
1137 (dev == MV_DEV_88RC8180 && i < 2) ||
1138 (dev == MV_DEV_88F6781 && i < 4) ||
1139 (dev == MV_DEV_MV78100_Z0 && i < 8) ||
1140 ((dev & MV_DEV_FAMILY_MASK) == MV_DEV_DISCOVERY && i < 8))
1146 /* XXX This should check for overlapping remap fields too.. */
1148 decode_win_overlap(int win, int win_no, const struct decode_win *wintab)
1150 const struct decode_win *tab;
1155 for (i = 0; i < win_no; i++, tab++) {
1160 if ((tab->base + tab->size - 1) < (wintab + win)->base)
1163 else if (((wintab + win)->base + (wintab + win)->size - 1) <
1174 decode_win_cpu_set(int target, int attr, vm_paddr_t base, uint32_t size,
1181 win = soc_decode_win_spec->mv_win_cpu_max - 1;
1188 while ((win >= 0) && (win < soc_decode_win_spec->mv_win_cpu_max)) {
1189 cr = win_cpu_cr_read(win);
1190 if ((cr & MV_WIN_CPU_ENABLE_BIT) == 0)
1192 if ((cr & ((0xff << MV_WIN_CPU_ATTR_SHIFT) |
1193 (0x1f << MV_WIN_CPU_TARGET_SHIFT))) ==
1194 ((attr << MV_WIN_CPU_ATTR_SHIFT) |
1195 (target << MV_WIN_CPU_TARGET_SHIFT)))
1199 if ((win < 0) || (win >= soc_decode_win_spec->mv_win_cpu_max) ||
1200 ((remap != ~0) && (win_cpu_can_remap(win) == 0)))
1203 br = base & 0xffff0000;
1204 win_cpu_br_write(win, br);
1206 if (win_cpu_can_remap(win)) {
1208 win_cpu_remap_l_write(win, remap & 0xffff0000);
1209 win_cpu_remap_h_write(win, 0);
1212 * Remap function is not used for a given window
1213 * (capable of remapping) - set remap field with the
1214 * same value as base.
1216 win_cpu_remap_l_write(win, base & 0xffff0000);
1217 win_cpu_remap_h_write(win, 0);
1221 cr = ((size - 1) & 0xffff0000) | (attr << MV_WIN_CPU_ATTR_SHIFT) |
1222 (target << MV_WIN_CPU_TARGET_SHIFT) | MV_WIN_CPU_ENABLE_BIT;
1223 win_cpu_cr_write(win, cr);
1229 decode_win_cpu_setup(void)
1233 /* Disable all CPU windows */
1234 for (i = 0; i < soc_decode_win_spec->mv_win_cpu_max; i++) {
1235 win_cpu_cr_write(i, 0);
1236 win_cpu_br_write(i, 0);
1237 if (win_cpu_can_remap(i)) {
1238 win_cpu_remap_l_write(i, 0);
1239 win_cpu_remap_h_write(i, 0);
1243 for (i = 0; i < cpu_wins_no; i++)
1244 if (cpu_wins[i].target > 0)
1245 decode_win_cpu_set(cpu_wins[i].target,
1246 cpu_wins[i].attr, cpu_wins[i].base,
1247 cpu_wins[i].size, cpu_wins[i].remap);
1252 decode_win_sdram_fixup(void)
1254 struct mem_region mr[FDT_MEM_REGIONS];
1255 uint8_t window_valid[MV_WIN_DDR_MAX];
1256 int mr_cnt, err, i, j;
1257 uint32_t valid_win_num = 0;
1259 /* Grab physical memory regions information from device tree. */
1260 err = fdt_get_mem_regions(mr, &mr_cnt, NULL);
1264 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1265 window_valid[i] = 0;
1267 /* Try to match entries from device tree with settings from u-boot */
1268 for (i = 0; i < mr_cnt; i++) {
1269 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
1270 if (ddr_is_active(j) &&
1271 (ddr_base(j) == mr[i].mr_start) &&
1272 (ddr_size(j) == mr[i].mr_size)) {
1273 window_valid[j] = 1;
1279 if (mr_cnt != valid_win_num)
1282 /* Destroy windows without corresponding device tree entry */
1283 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
1284 if (ddr_is_active(j) && (window_valid[j] != 1)) {
1285 printf("Disabling SDRAM decoding window: %d\n", j);
1293 * Check if we're able to cover all active DDR banks.
1296 decode_win_can_cover_ddr(int max)
1301 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1302 if (ddr_is_active(i))
1306 printf("Unable to cover all active DDR banks: "
1307 "%d, available windows: %d\n", c, max);
1314 /**************************************************************************
1315 * DDR windows routines
1316 **************************************************************************/
1318 ddr_is_active(int i)
1321 if (ddr_sz_read(i) & 0x1)
1339 return (ddr_br_read(i) & 0xff000000);
1346 return ((ddr_sz_read(i) | 0x00ffffff) + 1);
1352 uint32_t dev, rev, attr;
1355 if (dev == MV_DEV_88RC8180)
1356 return ((ddr_sz_read(i) & 0xf0) >> 4);
1357 if (dev == MV_DEV_88F6781)
1360 attr = (i == 0 ? 0xe :
1363 (i == 3 ? 0x7 : 0xff))));
1364 if (platform_io_coherent)
1376 if (dev == MV_DEV_88RC8180) {
1377 i = (ddr_sz_read(i) & 0xf0) >> 4;
1378 return (i == 0xe ? 0xc :
1381 (i == 0x7 ? 0xf : 0xc))));
1385 * On SOCs other than 88RC8180 Mbus unit ID for
1386 * DDR SDRAM controller is always 0x0.
1391 /**************************************************************************
1392 * CESA windows routines
1393 **************************************************************************/
1395 decode_win_cesa_valid(void)
1398 return (decode_win_can_cover_ddr(MV_WIN_CESA_MAX));
1402 decode_win_cesa_dump(u_long base)
1406 for (i = 0; i < MV_WIN_CESA_MAX; i++)
1407 printf("CESA window#%d: c 0x%08x, b 0x%08x\n", i,
1408 win_cesa_cr_read(base, i), win_cesa_br_read(base, i));
1412 * Set CESA decode windows.
1415 decode_win_cesa_setup(u_long base)
1421 for (i = 0; i < MV_WIN_CESA_MAX; i++) {
1422 win_cesa_cr_write(base, i, 0);
1423 win_cesa_br_write(base, i, 0);
1426 /* Only access to active DRAM banks is required */
1427 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1428 if (ddr_is_active(i)) {
1433 * Armada 38x SoC's equipped with 4GB DRAM
1434 * suffer freeze during CESA operation, if
1435 * MBUS window opened at given DRAM CS reaches
1436 * end of the address space. Apply a workaround
1437 * by setting the window size to the closest possible
1438 * value, i.e. divide it by 2.
1440 if ((soc_family == MV_SOC_ARMADA_38X) &&
1441 (size + ddr_base(i) == 0x100000000ULL))
1444 cr = (((size - 1) & 0xffff0000) |
1445 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
1446 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
1449 /* Set the first free CESA window */
1450 for (j = 0; j < MV_WIN_CESA_MAX; j++) {
1451 if (win_cesa_cr_read(base, j) & 0x1)
1454 win_cesa_br_write(base, j, br);
1455 win_cesa_cr_write(base, j, cr);
1463 decode_win_a38x_cesa_setup(u_long base)
1465 decode_win_cesa_setup(base);
1466 decode_win_cesa_setup(base + MV_WIN_CESA_OFFSET);
1470 decode_win_a38x_cesa_dump(u_long base)
1472 decode_win_cesa_dump(base);
1473 decode_win_cesa_dump(base + MV_WIN_CESA_OFFSET);
1476 /**************************************************************************
1477 * USB windows routines
1478 **************************************************************************/
1480 decode_win_usb_valid(void)
1483 return (decode_win_can_cover_ddr(MV_WIN_USB_MAX));
1487 decode_win_usb_dump(u_long base)
1491 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port - 1)))
1494 for (i = 0; i < MV_WIN_USB_MAX; i++)
1495 printf("USB window#%d: c 0x%08x, b 0x%08x\n", i,
1496 win_usb_cr_read(base, i), win_usb_br_read(base, i));
1500 * Set USB decode windows.
1503 decode_win_usb_setup(u_long base)
1508 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port)))
1513 for (i = 0; i < MV_WIN_USB_MAX; i++) {
1514 win_usb_cr_write(base, i, 0);
1515 win_usb_br_write(base, i, 0);
1518 /* Only access to active DRAM banks is required */
1519 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1520 if (ddr_is_active(i)) {
1523 * XXX for 6281 we should handle Mbus write
1524 * burst limit field in the ctrl reg
1526 cr = (((ddr_size(i) - 1) & 0xffff0000) |
1527 (ddr_attr(i) << 8) |
1528 (ddr_target(i) << 4) | 1);
1530 /* Set the first free USB window */
1531 for (j = 0; j < MV_WIN_USB_MAX; j++) {
1532 if (win_usb_cr_read(base, j) & 0x1)
1535 win_usb_br_write(base, j, br);
1536 win_usb_cr_write(base, j, cr);
1543 /**************************************************************************
1544 * USB3 windows routines
1545 **************************************************************************/
1547 decode_win_usb3_valid(void)
1550 return (decode_win_can_cover_ddr(MV_WIN_USB3_MAX));
1554 decode_win_usb3_dump(u_long base)
1558 for (i = 0; i < MV_WIN_USB3_MAX; i++)
1559 printf("USB3.0 window#%d: c 0x%08x, b 0x%08x\n", i,
1560 win_usb3_cr_read(base, i), win_usb3_br_read(base, i));
1564 * Set USB3 decode windows
1567 decode_win_usb3_setup(u_long base)
1572 for (i = 0; i < MV_WIN_USB3_MAX; i++) {
1573 win_usb3_cr_write(base, i, 0);
1574 win_usb3_br_write(base, i, 0);
1577 /* Only access to active DRAM banks is required */
1578 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1579 if (ddr_is_active(i)) {
1581 cr = (((ddr_size(i) - 1) &
1582 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT)) |
1583 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
1584 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
1587 /* Set the first free USB3.0 window */
1588 for (j = 0; j < MV_WIN_USB3_MAX; j++) {
1589 if (win_usb3_cr_read(base, j) & IO_WIN_ENA_MASK)
1592 win_usb3_br_write(base, j, br);
1593 win_usb3_cr_write(base, j, cr);
1600 /**************************************************************************
1601 * ETH windows routines
1602 **************************************************************************/
1605 win_eth_can_remap(int i)
1608 /* ETH encode windows 0-3 have remap capability */
1616 eth_bare_read(uint32_t base, int i)
1620 v = win_eth_bare_read(base);
1627 eth_bare_write(uint32_t base, int i, int val)
1631 v = win_eth_bare_read(base);
1634 win_eth_bare_write(base, v);
1638 eth_epap_write(uint32_t base, int i, int val)
1642 v = win_eth_epap_read(base);
1643 v &= ~(0x3 << (i * 2));
1644 v |= (val << (i * 2));
1645 win_eth_epap_write(base, v);
1649 decode_win_eth_dump(u_long base)
1653 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port - 1)))
1656 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1657 printf("ETH window#%d: b 0x%08x, s 0x%08x", i,
1658 win_eth_br_read(base, i),
1659 win_eth_sz_read(base, i));
1661 if (win_eth_can_remap(i))
1662 printf(", ha 0x%08x",
1663 win_eth_har_read(base, i));
1667 printf("ETH windows: bare 0x%08x, epap 0x%08x\n",
1668 win_eth_bare_read(base),
1669 win_eth_epap_read(base));
1672 #define MV_WIN_ETH_DDR_TRGT(n) ddr_target(n)
1675 decode_win_eth_setup(u_long base)
1680 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port)))
1685 /* Disable, clear and revoke protection for all ETH windows */
1686 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1687 eth_bare_write(base, i, 1);
1688 eth_epap_write(base, i, 0);
1689 win_eth_br_write(base, i, 0);
1690 win_eth_sz_write(base, i, 0);
1691 if (win_eth_can_remap(i))
1692 win_eth_har_write(base, i, 0);
1695 /* Only access to active DRAM banks is required */
1696 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1697 if (ddr_is_active(i)) {
1698 br = ddr_base(i) | (ddr_attr(i) << 8) | MV_WIN_ETH_DDR_TRGT(i);
1699 sz = ((ddr_size(i) - 1) & 0xffff0000);
1701 /* Set the first free ETH window */
1702 for (j = 0; j < MV_WIN_ETH_MAX; j++) {
1703 if (eth_bare_read(base, j) == 0)
1706 win_eth_br_write(base, j, br);
1707 win_eth_sz_write(base, j, sz);
1709 /* XXX remapping ETH windows not supported */
1711 /* Set protection RW */
1712 eth_epap_write(base, j, 0x3);
1715 eth_bare_write(base, j, 0);
1722 decode_win_neta_dump(u_long base)
1725 decode_win_eth_dump(base + MV_WIN_NETA_OFFSET);
1729 decode_win_neta_setup(u_long base)
1732 decode_win_eth_setup(base + MV_WIN_NETA_OFFSET);
1736 decode_win_eth_valid(void)
1739 return (decode_win_can_cover_ddr(MV_WIN_ETH_MAX));
1742 /**************************************************************************
1743 * PCIE windows routines
1744 **************************************************************************/
1746 decode_win_pcie_dump(u_long base)
1750 printf("PCIE windows base 0x%08lx\n", base);
1751 for (i = 0; i < MV_WIN_PCIE_MAX; i++)
1752 printf("PCIE window#%d: cr 0x%08x br 0x%08x remap 0x%08x\n",
1753 i, win_pcie_cr_read(base, i),
1754 win_pcie_br_read(base, i), win_pcie_remap_read(base, i));
1756 for (i = 0; i < MV_PCIE_BAR_MAX; i++)
1757 printf("PCIE bar#%d: cr 0x%08x br 0x%08x brh 0x%08x\n",
1758 i, pcie_bar_cr_read(base, i),
1759 pcie_bar_br_read(base, i), pcie_bar_brh_read(base, i));
1763 decode_win_pcie_setup(u_long base)
1765 uint32_t size = 0, ddrbase = ~0;
1769 for (i = 0; i < MV_PCIE_BAR_MAX; i++) {
1770 pcie_bar_br_write(base, i,
1771 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1773 pcie_bar_brh_write(base, i, 0);
1775 pcie_bar_cr_write(base, i, 0);
1778 for (i = 0; i < MV_WIN_PCIE_MAX; i++) {
1779 win_pcie_cr_write(base, i, 0);
1780 win_pcie_br_write(base, i, 0);
1781 win_pcie_remap_write(base, i, 0);
1784 /* On End-Point only set BAR size to 1MB regardless of DDR size */
1785 if ((bus_space_read_4(fdtbus_bs_tag, base, MV_PCIE_CONTROL)
1786 & MV_PCIE_ROOT_CMPLX) == 0) {
1787 pcie_bar_cr_write(base, 1, 0xf0000 | 1);
1791 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1792 if (ddr_is_active(i)) {
1793 /* Map DDR to BAR 1 */
1794 cr = (ddr_size(i) - 1) & 0xffff0000;
1795 size += ddr_size(i) & 0xffff0000;
1796 cr |= (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
1801 /* Use the first available PCIE window */
1802 for (j = 0; j < MV_WIN_PCIE_MAX; j++) {
1803 if (win_pcie_cr_read(base, j) != 0)
1806 win_pcie_br_write(base, j, br);
1807 win_pcie_cr_write(base, j, cr);
1814 * Upper 16 bits in BAR register is interpreted as BAR size
1815 * (in 64 kB units) plus 64kB, so subtract 0x10000
1816 * form value passed to register to get correct value.
1819 pcie_bar_cr_write(base, 1, size | 1);
1820 pcie_bar_br_write(base, 1, ddrbase |
1821 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1822 pcie_bar_br_write(base, 0, fdt_immr_pa |
1823 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1827 decode_win_pcie_valid(void)
1830 return (decode_win_can_cover_ddr(MV_WIN_PCIE_MAX));
1833 /**************************************************************************
1834 * IDMA windows routines
1835 **************************************************************************/
1836 #if defined(SOC_MV_ORION) || defined(SOC_MV_DISCOVERY)
1838 idma_bare_read(u_long base, int i)
1842 v = win_idma_bare_read(base);
1849 idma_bare_write(u_long base, int i, int val)
1853 v = win_idma_bare_read(base);
1856 win_idma_bare_write(base, v);
1860 * Sets channel protection 'val' for window 'w' on channel 'c'
1863 idma_cap_write(u_long base, int c, int w, int val)
1867 v = win_idma_cap_read(base, c);
1868 v &= ~(0x3 << (w * 2));
1869 v |= (val << (w * 2));
1870 win_idma_cap_write(base, c, v);
1874 * Set protection 'val' on all channels for window 'w'
1877 idma_set_prot(u_long base, int w, int val)
1881 for (c = 0; c < MV_IDMA_CHAN_MAX; c++)
1882 idma_cap_write(base, c, w, val);
1886 win_idma_can_remap(int i)
1889 /* IDMA decode windows 0-3 have remap capability */
1897 decode_win_idma_setup(u_long base)
1902 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
1905 * Disable and clear all IDMA windows, revoke protection for all channels
1907 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
1908 idma_bare_write(base, i, 1);
1909 win_idma_br_write(base, i, 0);
1910 win_idma_sz_write(base, i, 0);
1911 if (win_idma_can_remap(i) == 1)
1912 win_idma_har_write(base, i, 0);
1914 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
1915 win_idma_cap_write(base, i, 0);
1918 * Set up access to all active DRAM banks
1920 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1921 if (ddr_is_active(i)) {
1922 br = ddr_base(i) | (ddr_attr(i) << 8) | ddr_target(i);
1923 sz = ((ddr_size(i) - 1) & 0xffff0000);
1925 /* Place DDR entries in non-remapped windows */
1926 for (j = 0; j < MV_WIN_IDMA_MAX; j++)
1927 if (win_idma_can_remap(j) != 1 &&
1928 idma_bare_read(base, j) == 1) {
1929 /* Configure window */
1930 win_idma_br_write(base, j, br);
1931 win_idma_sz_write(base, j, sz);
1933 /* Set protection RW on all channels */
1934 idma_set_prot(base, j, 0x3);
1937 idma_bare_write(base, j, 0);
1943 * Remaining targets -- from statically defined table
1945 for (i = 0; i < idma_wins_no; i++)
1946 if (idma_wins[i].target > 0) {
1947 br = (idma_wins[i].base & 0xffff0000) |
1948 (idma_wins[i].attr << 8) | idma_wins[i].target;
1949 sz = ((idma_wins[i].size - 1) & 0xffff0000);
1951 /* Set the first free IDMA window */
1952 for (j = 0; j < MV_WIN_IDMA_MAX; j++) {
1953 if (idma_bare_read(base, j) == 0)
1956 /* Configure window */
1957 win_idma_br_write(base, j, br);
1958 win_idma_sz_write(base, j, sz);
1959 if (win_idma_can_remap(j) &&
1960 idma_wins[j].remap >= 0)
1961 win_idma_har_write(base, j,
1962 idma_wins[j].remap);
1964 /* Set protection RW on all channels */
1965 idma_set_prot(base, j, 0x3);
1968 idma_bare_write(base, j, 0);
1975 decode_win_idma_valid(void)
1977 const struct decode_win *wintab;
1981 if (idma_wins_no > MV_WIN_IDMA_MAX) {
1982 printf("IDMA windows: too many entries: %d\n", idma_wins_no);
1985 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
1986 if (ddr_is_active(i))
1989 if (idma_wins_no > (MV_WIN_IDMA_MAX - c)) {
1990 printf("IDMA windows: too many entries: %d, available: %d\n",
1991 idma_wins_no, MV_WIN_IDMA_MAX - c);
1997 for (i = 0; i < idma_wins_no; i++, wintab++) {
1998 if (wintab->target == 0) {
1999 printf("IDMA window#%d: DDR target window is not "
2000 "supposed to be reprogrammed!\n", i);
2004 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
2005 printf("IDMA window#%d: not capable of remapping, but "
2006 "val 0x%08x defined\n", i, wintab->remap);
2013 if (s > (0xFFFFFFFF - b + 1)) {
2014 /* XXX this boundary check should account for 64bit and
2016 printf("IDMA window#%d: no space for size 0x%08x at "
2017 "0x%08x\n", i, s, b);
2022 j = decode_win_overlap(i, idma_wins_no, &idma_wins[0]);
2024 printf("IDMA window#%d: (0x%08x - 0x%08x) overlaps "
2025 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
2027 idma_wins[j].base + idma_wins[j].size - 1);
2036 decode_win_idma_dump(u_long base)
2040 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
2043 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
2044 printf("IDMA window#%d: b 0x%08x, s 0x%08x", i,
2045 win_idma_br_read(base, i), win_idma_sz_read(base, i));
2047 if (win_idma_can_remap(i))
2048 printf(", ha 0x%08x", win_idma_har_read(base, i));
2052 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
2053 printf("IDMA channel#%d: ap 0x%08x\n", i,
2054 win_idma_cap_read(base, i));
2055 printf("IDMA windows: bare 0x%08x\n", win_idma_bare_read(base));
2059 /* Provide dummy functions to satisfy the build for SoCs not equipped with IDMA */
2061 decode_win_idma_valid(void)
2068 decode_win_idma_setup(u_long base)
2073 decode_win_idma_dump(u_long base)
2078 /**************************************************************************
2079 * XOR windows routines
2080 **************************************************************************/
2081 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
2083 xor_ctrl_read(u_long base, int i, int c, int e)
2086 v = win_xor_ctrl_read(base, c, e);
2093 xor_ctrl_write(u_long base, int i, int c, int e, int val)
2097 v = win_xor_ctrl_read(base, c, e);
2100 win_xor_ctrl_write(base, c, e, v);
2104 * Set channel protection 'val' for window 'w' on channel 'c'
2107 xor_chan_write(u_long base, int c, int e, int w, int val)
2111 v = win_xor_ctrl_read(base, c, e);
2112 v &= ~(0x3 << (w * 2 + 16));
2113 v |= (val << (w * 2 + 16));
2114 win_xor_ctrl_write(base, c, e, v);
2118 * Set protection 'val' on all channels for window 'w' on engine 'e'
2121 xor_set_prot(u_long base, int w, int e, int val)
2125 for (c = 0; c < MV_XOR_CHAN_MAX; c++)
2126 xor_chan_write(base, c, e, w, val);
2130 win_xor_can_remap(int i)
2133 /* XOR decode windows 0-3 have remap capability */
2147 case MV_DEV_88F6281:
2148 case MV_DEV_88F6282:
2149 case MV_DEV_MV78130:
2150 case MV_DEV_MV78160:
2151 case MV_DEV_MV78230:
2152 case MV_DEV_MV78260:
2153 case MV_DEV_MV78460:
2155 case MV_DEV_MV78100:
2156 case MV_DEV_MV78100_Z0:
2164 xor_active_dram(u_long base, int c, int e, int *window)
2170 * Set up access to all active DRAM banks
2173 for (i = 0; i < m; i++)
2174 if (ddr_is_active(i)) {
2175 br = ddr_base(i) | (ddr_attr(i) << 8) |
2177 sz = ((ddr_size(i) - 1) & 0xffff0000);
2179 /* Place DDR entries in non-remapped windows */
2180 for (w = 0; w < MV_WIN_XOR_MAX; w++)
2181 if (win_xor_can_remap(w) != 1 &&
2182 (xor_ctrl_read(base, w, c, e) == 0) &&
2184 /* Configure window */
2185 win_xor_br_write(base, w, e, br);
2186 win_xor_sz_write(base, w, e, sz);
2188 /* Set protection RW on all channels */
2189 xor_set_prot(base, w, e, 0x3);
2192 xor_ctrl_write(base, w, c, e, 1);
2200 decode_win_xor_setup(u_long base)
2203 int i, j, z, e = 1, m, window;
2205 if (pm_is_disabled(CPU_PM_CTRL_XOR))
2209 * Disable and clear all XOR windows, revoke protection for all
2213 for (j = 0; j < m; j++, e--) {
2214 /* Number of non-remaped windows */
2215 window = MV_XOR_NON_REMAP - 1;
2217 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
2218 win_xor_br_write(base, i, e, 0);
2219 win_xor_sz_write(base, i, e, 0);
2222 if (win_xor_can_remap(i) == 1)
2223 win_xor_har_write(base, i, e, 0);
2225 for (i = 0; i < MV_XOR_CHAN_MAX; i++) {
2226 win_xor_ctrl_write(base, i, e, 0);
2227 xor_active_dram(base, i, e, &window);
2231 * Remaining targets -- from a statically defined table
2233 for (i = 0; i < xor_wins_no; i++)
2234 if (xor_wins[i].target > 0) {
2235 br = (xor_wins[i].base & 0xffff0000) |
2236 (xor_wins[i].attr << 8) |
2238 sz = ((xor_wins[i].size - 1) & 0xffff0000);
2240 /* Set the first free XOR window */
2241 for (z = 0; z < MV_WIN_XOR_MAX; z++) {
2242 if (xor_ctrl_read(base, z, 0, e) &&
2243 xor_ctrl_read(base, z, 1, e))
2246 /* Configure window */
2247 win_xor_br_write(base, z, e, br);
2248 win_xor_sz_write(base, z, e, sz);
2249 if (win_xor_can_remap(z) &&
2250 xor_wins[z].remap >= 0)
2251 win_xor_har_write(base, z, e,
2254 /* Set protection RW on all channels */
2255 xor_set_prot(base, z, e, 0x3);
2258 xor_ctrl_write(base, z, 0, e, 1);
2259 xor_ctrl_write(base, z, 1, e, 1);
2267 decode_win_xor_valid(void)
2269 const struct decode_win *wintab;
2273 if (xor_wins_no > MV_WIN_XOR_MAX) {
2274 printf("XOR windows: too many entries: %d\n", xor_wins_no);
2277 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
2278 if (ddr_is_active(i))
2281 if (xor_wins_no > (MV_WIN_XOR_MAX - c)) {
2282 printf("XOR windows: too many entries: %d, available: %d\n",
2283 xor_wins_no, MV_WIN_IDMA_MAX - c);
2289 for (i = 0; i < xor_wins_no; i++, wintab++) {
2290 if (wintab->target == 0) {
2291 printf("XOR window#%d: DDR target window is not "
2292 "supposed to be reprogrammed!\n", i);
2296 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
2297 printf("XOR window#%d: not capable of remapping, but "
2298 "val 0x%08x defined\n", i, wintab->remap);
2305 if (s > (0xFFFFFFFF - b + 1)) {
2307 * XXX this boundary check should account for 64bit
2310 printf("XOR window#%d: no space for size 0x%08x at "
2311 "0x%08x\n", i, s, b);
2316 j = decode_win_overlap(i, xor_wins_no, &xor_wins[0]);
2318 printf("XOR window#%d: (0x%08x - 0x%08x) overlaps "
2319 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
2321 xor_wins[j].base + xor_wins[j].size - 1);
2330 decode_win_xor_dump(u_long base)
2335 if (pm_is_disabled(CPU_PM_CTRL_XOR))
2338 for (j = 0; j < xor_max_eng(); j++, e--) {
2339 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
2340 printf("XOR window#%d: b 0x%08x, s 0x%08x", i,
2341 win_xor_br_read(base, i, e), win_xor_sz_read(base, i, e));
2343 if (win_xor_can_remap(i))
2344 printf(", ha 0x%08x", win_xor_har_read(base, i, e));
2348 for (i = 0; i < MV_XOR_CHAN_MAX; i++)
2349 printf("XOR control#%d: 0x%08x\n", i,
2350 win_xor_ctrl_read(base, i, e));
2355 /* Provide dummy functions to satisfy the build for SoCs not equipped with XOR */
2357 decode_win_xor_valid(void)
2364 decode_win_xor_setup(u_long base)
2369 decode_win_xor_dump(u_long base)
2374 /**************************************************************************
2375 * SATA windows routines
2376 **************************************************************************/
2378 decode_win_sata_setup(u_long base)
2383 if (pm_is_disabled(CPU_PM_CTRL_SATA))
2386 for (i = 0; i < MV_WIN_SATA_MAX; i++) {
2387 win_sata_cr_write(base, i, 0);
2388 win_sata_br_write(base, i, 0);
2391 for (i = 0; i < MV_WIN_DDR_MAX; i++)
2392 if (ddr_is_active(i)) {
2393 cr = ((ddr_size(i) - 1) & 0xffff0000) |
2394 (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
2397 /* Use the first available SATA window */
2398 for (j = 0; j < MV_WIN_SATA_MAX; j++) {
2399 if ((win_sata_cr_read(base, j) & 1) != 0)
2402 win_sata_br_write(base, j, br);
2403 win_sata_cr_write(base, j, cr);
2410 * Configure AHCI decoding windows
2413 decode_win_ahci_setup(u_long base)
2415 uint32_t br, cr, sz;
2418 for (i = 0; i < MV_WIN_SATA_MAX_ARMADA38X; i++) {
2419 win_sata_armada38x_cr_write(base, i, 0);
2420 win_sata_armada38x_br_write(base, i, 0);
2421 win_sata_armada38x_sz_write(base, i, 0);
2424 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
2425 if (ddr_is_active(i)) {
2426 cr = (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
2427 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
2430 sz = (ddr_size(i) - 1) &
2431 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT);
2433 /* Use first available SATA window */
2434 for (j = 0; j < MV_WIN_SATA_MAX_ARMADA38X; j++) {
2435 if (win_sata_armada38x_cr_read(base, j) & IO_WIN_ENA_MASK)
2438 /* BASE is set to DRAM base (0x00000000) */
2439 win_sata_armada38x_br_write(base, j, br);
2440 /* CTRL targets DRAM ctrl with 0x0E or 0x0D */
2441 win_sata_armada38x_cr_write(base, j, cr);
2442 /* SIZE is set to 16MB - max value */
2443 win_sata_armada38x_sz_write(base, j, sz);
2451 decode_win_ahci_dump(u_long base)
2455 for (i = 0; i < MV_WIN_SATA_MAX_ARMADA38X; i++)
2456 printf("SATA window#%d: cr 0x%08x, br 0x%08x, sz 0x%08x\n", i,
2457 win_sata_armada38x_cr_read(base, i), win_sata_br_read(base, i),
2458 win_sata_armada38x_sz_read(base,i));
2462 decode_win_sata_valid(void)
2467 if (dev == MV_DEV_88F5281)
2470 return (decode_win_can_cover_ddr(MV_WIN_SATA_MAX));
2474 decode_win_sdhci_setup(u_long base)
2479 for (i = 0; i < MV_WIN_SDHCI_MAX; i++) {
2480 win_sdhci_cr_write(base, i, 0);
2481 win_sdhci_br_write(base, i, 0);
2484 for (i = 0; i < MV_WIN_DDR_MAX; i++)
2485 if (ddr_is_active(i)) {
2487 cr = (((ddr_size(i) - 1) &
2488 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT)) |
2489 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
2490 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
2493 /* Use the first available SDHCI window */
2494 for (j = 0; j < MV_WIN_SDHCI_MAX; j++) {
2495 if (win_sdhci_cr_read(base, j) & IO_WIN_ENA_MASK)
2498 win_sdhci_cr_write(base, j, cr);
2499 win_sdhci_br_write(base, j, br);
2506 decode_win_sdhci_dump(u_long base)
2510 for (i = 0; i < MV_WIN_SDHCI_MAX; i++)
2511 printf("SDHCI window#%d: c 0x%08x, b 0x%08x\n", i,
2512 win_sdhci_cr_read(base, i), win_sdhci_br_read(base, i));
2516 decode_win_sdhci_valid(void)
2519 return (decode_win_can_cover_ddr(MV_WIN_SDHCI_MAX));
2522 /**************************************************************************
2523 * FDT parsing routines.
2524 **************************************************************************/
2527 fdt_get_ranges(const char *nodename, void *buf, int size, int *tuples,
2531 pcell_t addr_cells, par_addr_cells, size_cells;
2532 int len, tuple_size, tuples_count;
2534 node = OF_finddevice(nodename);
2538 if ((fdt_addrsize_cells(node, &addr_cells, &size_cells)) != 0)
2541 par_addr_cells = fdt_parent_addr_cells(node);
2542 if (par_addr_cells > 2)
2545 tuple_size = sizeof(pcell_t) * (addr_cells + par_addr_cells +
2548 /* Note the OF_getprop_alloc() cannot be used at this early stage. */
2549 len = OF_getprop(node, "ranges", buf, size);
2552 * XXX this does not handle the empty 'ranges;' case, which is
2553 * legitimate and should be allowed.
2555 tuples_count = len / tuple_size;
2556 if (tuples_count <= 0)
2559 if (par_addr_cells > 2 || addr_cells > 2 || size_cells > 2)
2562 *tuples = tuples_count;
2563 *tuplesize = tuple_size;
2568 win_cpu_from_dt(void)
2572 int i, entry_size, err, t, tuple_size, tuples;
2573 u_long sram_base, sram_size;
2576 /* Retrieve 'ranges' property of '/localbus' node. */
2577 if ((err = fdt_get_ranges("/localbus", ranges, sizeof(ranges),
2578 &tuples, &tuple_size)) == 0) {
2580 * Fill CPU decode windows table.
2582 bzero((void *)&cpu_win_tbl, sizeof(cpu_win_tbl));
2584 entry_size = tuple_size / sizeof(pcell_t);
2585 cpu_wins_no = tuples;
2588 if (tuples > nitems(cpu_win_tbl)) {
2589 debugf("too many tuples to fit into cpu_win_tbl\n");
2593 for (i = 0, t = 0; t < tuples; i += entry_size, t++) {
2594 cpu_win_tbl[t].target = 1;
2595 cpu_win_tbl[t].attr = fdt32_to_cpu(ranges[i + 1]);
2596 cpu_win_tbl[t].base = fdt32_to_cpu(ranges[i + 2]);
2597 cpu_win_tbl[t].size = fdt32_to_cpu(ranges[i + 3]);
2598 cpu_win_tbl[t].remap = ~0;
2599 debugf("target = 0x%0x attr = 0x%0x base = 0x%0x "
2600 "size = 0x%0x remap = 0x%0x\n",
2601 cpu_win_tbl[t].target,
2602 cpu_win_tbl[t].attr, cpu_win_tbl[t].base,
2603 cpu_win_tbl[t].size, cpu_win_tbl[t].remap);
2608 * Retrieve CESA SRAM data.
2610 if ((node = OF_finddevice("sram")) != -1)
2611 if (ofw_bus_node_is_compatible(node, "mrvl,cesa-sram"))
2614 if ((node = OF_finddevice("/")) == -1)
2617 if ((node = fdt_find_compatible(node, "mrvl,cesa-sram", 0)) == 0)
2618 /* SRAM block is not always present. */
2621 sram_base = sram_size = 0;
2622 if (fdt_regsize(node, &sram_base, &sram_size) != 0)
2626 if (t >= nitems(cpu_win_tbl)) {
2627 debugf("cannot fit CESA tuple into cpu_win_tbl\n");
2631 cpu_win_tbl[t].target = soc_decode_win_spec->win_cesa_target;
2632 if (soc_family == MV_SOC_ARMADA_38X)
2633 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(0);
2635 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(1);
2636 cpu_win_tbl[t].base = sram_base;
2637 cpu_win_tbl[t].size = sram_size;
2638 cpu_win_tbl[t].remap = ~0;
2640 debugf("sram: base = 0x%0lx size = 0x%0lx\n", sram_base, sram_size);
2642 /* Check if there is a second CESA node */
2643 while ((node = OF_peer(node)) != 0) {
2644 if (ofw_bus_node_is_compatible(node, "mrvl,cesa-sram")) {
2645 if (fdt_regsize(node, &sram_base, &sram_size) != 0)
2655 if (t >= nitems(cpu_win_tbl)) {
2656 debugf("cannot fit CESA tuple into cpu_win_tbl\n");
2660 /* Configure window for CESA1 */
2661 cpu_win_tbl[t].target = soc_decode_win_spec->win_cesa_target;
2662 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(1);
2663 cpu_win_tbl[t].base = sram_base;
2664 cpu_win_tbl[t].size = sram_size;
2665 cpu_win_tbl[t].remap = ~0;
2667 debugf("sram: base = 0x%0lx size = 0x%0lx\n", sram_base, sram_size);
2673 fdt_win_process(phandle_t child)
2677 for (i = 0; soc_nodes[i].compat != NULL; i++) {
2678 /* Setup only for enabled devices */
2679 if (ofw_bus_node_status_okay(child) == 0)
2682 if (!ofw_bus_node_is_compatible(child, soc_nodes[i].compat))
2685 ret = fdt_win_process_child(child, &soc_nodes[i], "reg");
2694 fdt_win_process_child(phandle_t child, struct soc_node_spec *soc_node,
2695 const char* mimo_reg_source)
2697 int addr_cells, size_cells;
2701 if (fdt_addrsize_cells(OF_parent(child), &addr_cells,
2705 if ((sizeof(pcell_t) * (addr_cells + size_cells)) > sizeof(reg))
2707 if (OF_getprop(child, mimo_reg_source, ®, sizeof(reg)) <= 0)
2710 if (addr_cells <= 2)
2711 base = fdt_data_get(®[0], addr_cells);
2713 base = fdt_data_get(®[addr_cells - 2], 2);
2714 size = fdt_data_get(®[addr_cells], size_cells);
2716 if (soc_node->valid_handler != NULL)
2717 if (!soc_node->valid_handler())
2720 base = (base & 0x000fffff) | fdt_immr_va;
2721 if (soc_node->decode_handler != NULL)
2722 soc_node->decode_handler(base);
2726 if (MV_DUMP_WIN && (soc_node->dump_handler != NULL))
2727 soc_node->dump_handler(base);
2735 phandle_t node, child, sb;
2736 phandle_t child_pci;
2740 node = OF_finddevice("/");
2742 panic("fdt_win_setup: no root node");
2744 /* Allow for coherent transactions on the A38x MBUS */
2745 if (ofw_bus_node_is_compatible(node, "marvell,armada380"))
2746 platform_io_coherent = true;
2749 * Traverse through all children of root and simple-bus nodes.
2750 * For each found device retrieve decode windows data (if applicable).
2752 child = OF_child(node);
2753 while (child != 0) {
2754 /* Lookup for callback and run */
2755 err = fdt_win_process(child);
2759 /* Process Marvell Armada-XP/38x PCIe controllers */
2760 if (ofw_bus_node_is_compatible(child, "marvell,armada-370-pcie")) {
2761 child_pci = OF_child(child);
2762 while (child_pci != 0) {
2763 err = fdt_win_process_child(child_pci,
2764 &soc_nodes[SOC_NODE_PCIE_ENTRY_IDX],
2765 "assigned-addresses");
2769 child_pci = OF_peer(child_pci);
2774 * Once done with root-level children let's move down to
2775 * simple-bus and its children.
2777 child = OF_peer(child);
2778 if ((child == 0) && (node == OF_finddevice("/"))) {
2779 sb = node = fdt_find_compatible(node, "simple-bus", 0);
2782 child = OF_child(node);
2785 * Next, move one more level down to internal-regs node (if
2786 * it is present) and its children. This node also have
2787 * "simple-bus" compatible.
2789 if ((child == 0) && (node == sb)) {
2790 node = fdt_find_compatible(node, "simple-bus", 0);
2793 child = OF_child(node);
2801 fdt_fixup_busfreq(phandle_t root)
2806 freq = cpu_to_fdt32(get_tclk());
2809 * Fix bus speed in cpu node
2811 if ((sb = OF_finddevice("cpu")) != -1)
2812 if (fdt_is_compatible_strict(sb, "ARM,88VS584"))
2813 OF_setprop(sb, "bus-frequency", (void *)&freq,
2817 * This fixup sets the simple-bus bus-frequency property.
2819 if ((sb = fdt_find_compatible(root, "simple-bus", 1)) != 0)
2820 OF_setprop(sb, "bus-frequency", (void *)&freq, sizeof(freq));
2824 fdt_fixup_ranges(phandle_t root)
2827 pcell_t par_addr_cells, addr_cells, size_cells;
2828 pcell_t ranges[3], reg[2], *rangesptr;
2829 int len, tuple_size, tuples_count;
2832 /* Fix-up SoC ranges according to real fdt_immr_pa */
2833 if ((node = fdt_find_compatible(root, "simple-bus", 1)) != 0) {
2834 if (fdt_addrsize_cells(node, &addr_cells, &size_cells) == 0 &&
2835 ((par_addr_cells = fdt_parent_addr_cells(node)) <= 2)) {
2836 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2837 addr_cells + size_cells);
2838 len = OF_getprop(node, "ranges", ranges,
2840 tuples_count = len / tuple_size;
2841 /* Unexpected settings are not supported */
2842 if (tuples_count != 1)
2845 rangesptr = &ranges[0];
2846 rangesptr += par_addr_cells;
2847 base = fdt_data_get((void *)rangesptr, addr_cells);
2848 *rangesptr = cpu_to_fdt32(fdt_immr_pa);
2849 if (OF_setprop(node, "ranges", (void *)&ranges[0],
2850 sizeof(ranges)) < 0)
2855 /* Fix-up PCIe reg according to real PCIe registers' PA */
2856 if ((node = fdt_find_compatible(root, "mrvl,pcie", 1)) != 0) {
2857 if (fdt_addrsize_cells(OF_parent(node), &par_addr_cells,
2858 &size_cells) == 0) {
2859 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2861 len = OF_getprop(node, "reg", reg, sizeof(reg));
2862 tuples_count = len / tuple_size;
2863 /* Unexpected settings are not supported */
2864 if (tuples_count != 1)
2867 base = fdt_data_get((void *)®[0], par_addr_cells);
2868 base &= ~0xFF000000;
2869 base |= fdt_immr_pa;
2870 reg[0] = cpu_to_fdt32(base);
2871 if (OF_setprop(node, "reg", (void *)®[0],
2876 /* Fix-up succeeded. May return and continue */
2882 * In case of any error while fixing ranges just hang.
2883 * 1. No message can be displayed yet since console
2884 * is not initialized.
2885 * 2. Going further will cause failure on bus_space_map()
2886 * relying on the wrong ranges or data abort when
2887 * accessing PCIe registers.
2892 struct fdt_fixup_entry fdt_fixup_table[] = {
2893 { "mrvl,DB-88F6281", &fdt_fixup_busfreq },
2894 { "mrvl,DB-78460", &fdt_fixup_busfreq },
2895 { "mrvl,DB-78460", &fdt_fixup_ranges },
2904 if (soc_decode_win_spec->get_tclk != NULL)
2905 return soc_decode_win_spec->get_tclk();
2914 if (soc_decode_win_spec->get_cpu_freq != NULL)
2915 return soc_decode_win_spec->get_cpu_freq();
2923 fdt_pic_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
2927 if (!ofw_bus_node_is_compatible(node, "mrvl,pic") &&
2928 !ofw_bus_node_is_compatible(node, "mrvl,mpic"))
2931 *interrupt = fdt32_to_cpu(intr[0]);
2932 *trig = INTR_TRIGGER_CONFORM;
2933 *pol = INTR_POLARITY_CONFORM;
2938 fdt_pic_decode_t fdt_pic_table[] = {