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>
59 MALLOC_DEFINE(M_IDMA, "idma", "idma dma test memory");
67 #define debugf(fmt, args...) do { printf("%s(): ", __func__); \
68 printf(fmt,##args); } while (0)
70 #define debugf(fmt, args...)
79 static enum soc_family soc_family;
81 static int mv_win_cesa_attr(int wng_sel);
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_cpu_valid(void);
96 static int decode_win_usb_valid(void);
97 static int decode_win_usb3_valid(void);
98 static int decode_win_eth_valid(void);
99 static int decode_win_pcie_valid(void);
100 static int decode_win_sata_valid(void);
101 static int decode_win_sdhci_valid(void);
103 static int decode_win_idma_valid(void);
104 static int decode_win_xor_valid(void);
106 static void decode_win_cpu_setup(void);
107 static int decode_win_sdram_fixup(void);
108 static void decode_win_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_usb_dump(u_long);
122 static void decode_win_usb3_dump(u_long);
123 static void decode_win_eth_dump(u_long base);
124 static void decode_win_neta_dump(u_long base);
125 static void decode_win_idma_dump(u_long base);
126 static void decode_win_xor_dump(u_long base);
127 static void decode_win_ahci_dump(u_long base);
128 static void decode_win_sdhci_dump(u_long);
129 static void decode_win_pcie_dump(u_long);
131 static uint32_t win_cpu_cr_read(int);
132 static uint32_t win_cpu_armv5_cr_read(int);
133 static uint32_t win_cpu_armv7_cr_read(int);
134 static uint32_t win_cpu_br_read(int);
135 static uint32_t win_cpu_armv5_br_read(int);
136 static uint32_t win_cpu_armv7_br_read(int);
137 static uint32_t win_cpu_remap_l_read(int);
138 static uint32_t win_cpu_armv5_remap_l_read(int);
139 static uint32_t win_cpu_armv7_remap_l_read(int);
140 static uint32_t win_cpu_remap_h_read(int);
141 static uint32_t win_cpu_armv5_remap_h_read(int);
142 static uint32_t win_cpu_armv7_remap_h_read(int);
144 static void win_cpu_cr_write(int, uint32_t);
145 static void win_cpu_armv5_cr_write(int, uint32_t);
146 static void win_cpu_armv7_cr_write(int, uint32_t);
147 static void win_cpu_br_write(int, uint32_t);
148 static void win_cpu_armv5_br_write(int, uint32_t);
149 static void win_cpu_armv7_br_write(int, uint32_t);
150 static void win_cpu_remap_l_write(int, uint32_t);
151 static void win_cpu_armv5_remap_l_write(int, uint32_t);
152 static void win_cpu_armv7_remap_l_write(int, uint32_t);
153 static void win_cpu_remap_h_write(int, uint32_t);
154 static void win_cpu_armv5_remap_h_write(int, uint32_t);
155 static void win_cpu_armv7_remap_h_write(int, uint32_t);
157 static uint32_t ddr_br_read(int);
158 static uint32_t ddr_sz_read(int);
159 static uint32_t ddr_armv5_br_read(int);
160 static uint32_t ddr_armv5_sz_read(int);
161 static uint32_t ddr_armv7_br_read(int);
162 static uint32_t ddr_armv7_sz_read(int);
163 static void ddr_br_write(int, uint32_t);
164 static void ddr_sz_write(int, uint32_t);
165 static void ddr_armv5_br_write(int, uint32_t);
166 static void ddr_armv5_sz_write(int, uint32_t);
167 static void ddr_armv7_br_write(int, uint32_t);
168 static void ddr_armv7_sz_write(int, uint32_t);
170 static int fdt_get_ranges(const char *, void *, int, int *, int *);
171 int gic_decode_fdt(phandle_t iparent, pcell_t *intr, int *interrupt,
172 int *trig, int *pol);
174 static int win_cpu_from_dt(void);
175 static int fdt_win_setup(void);
177 static uint32_t dev_mask = 0;
178 static int cpu_wins_no = 0;
179 static int eth_port = 0;
180 static int usb_port = 0;
181 static boolean_t platform_io_coherent = false;
183 static struct decode_win cpu_win_tbl[MAX_CPU_WIN];
185 const struct decode_win *cpu_wins = cpu_win_tbl;
187 typedef void (*decode_win_setup_t)(u_long);
188 typedef void (*dump_win_t)(u_long);
189 typedef int (*valid_t)(void);
192 * The power status of device feature is only supported on
193 * Kirkwood and Discovery SoCs.
195 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
196 #define SOC_MV_POWER_STAT_SUPPORTED 1
198 #define SOC_MV_POWER_STAT_SUPPORTED 0
201 struct soc_node_spec {
203 decode_win_setup_t decode_handler;
204 dump_win_t dump_handler;
205 valid_t valid_handler;
208 static struct soc_node_spec soc_nodes[] = {
209 { "mrvl,ge", &decode_win_eth_setup, &decode_win_eth_dump, &decode_win_eth_valid},
210 { "marvell,armada-370-neta", &decode_win_neta_setup,
211 &decode_win_neta_dump, NULL },
212 { "mrvl,usb-ehci", &decode_win_usb_setup, &decode_win_usb_dump, &decode_win_usb_valid},
213 { "marvell,orion-ehci", &decode_win_usb_setup, &decode_win_usb_dump, &decode_win_usb_valid },
214 { "marvell,armada-380-xhci", &decode_win_usb3_setup,
215 &decode_win_usb3_dump, &decode_win_usb3_valid },
216 { "marvell,armada-380-ahci", &decode_win_ahci_setup,
217 &decode_win_ahci_dump, NULL },
218 { "marvell,armada-380-sdhci", &decode_win_sdhci_setup,
219 &decode_win_sdhci_dump, &decode_win_sdhci_valid},
220 { "mrvl,sata", &decode_win_sata_setup, NULL, &decode_win_sata_valid},
221 { "mrvl,xor", &decode_win_xor_setup, &decode_win_xor_dump, &decode_win_xor_valid},
222 { "mrvl,idma", &decode_win_idma_setup, &decode_win_idma_dump, &decode_win_idma_valid},
223 { "mrvl,cesa", &decode_win_cesa_setup, &decode_win_cesa_dump, &decode_win_cesa_valid},
224 { "mrvl,pcie", &decode_win_pcie_setup, &decode_win_pcie_dump, &decode_win_pcie_valid},
225 { NULL, NULL, NULL, NULL },
228 typedef uint32_t(*read_cpu_ctrl_t)(uint32_t);
229 typedef void(*write_cpu_ctrl_t)(uint32_t, uint32_t);
230 typedef uint32_t (*win_read_t)(int);
231 typedef void (*win_write_t)(int, uint32_t);
232 typedef int (*win_cesa_attr_t)(int);
233 typedef uint32_t (*get_t)(void);
235 struct decode_win_spec {
236 read_cpu_ctrl_t read_cpu_ctrl;
237 write_cpu_ctrl_t write_cpu_ctrl;
240 win_read_t remap_l_read;
241 win_read_t remap_h_read;
242 win_write_t cr_write;
243 win_write_t br_write;
244 win_write_t remap_l_write;
245 win_write_t remap_h_write;
246 uint32_t mv_win_cpu_max;
247 win_cesa_attr_t win_cesa_attr;
249 win_read_t ddr_br_read;
250 win_read_t ddr_sz_read;
251 win_write_t ddr_br_write;
252 win_write_t ddr_sz_write;
259 struct decode_win_spec *soc_decode_win_spec;
261 static struct decode_win_spec decode_win_specs[] =
264 &read_cpu_ctrl_armv7,
265 &write_cpu_ctrl_armv7,
266 &win_cpu_armv7_cr_read,
267 &win_cpu_armv7_br_read,
268 &win_cpu_armv7_remap_l_read,
269 &win_cpu_armv7_remap_h_read,
270 &win_cpu_armv7_cr_write,
271 &win_cpu_armv7_br_write,
272 &win_cpu_armv7_remap_l_write,
273 &win_cpu_armv7_remap_h_write,
274 MV_WIN_CPU_MAX_ARMV7,
275 &mv_win_cesa_attr_armada38x,
276 MV_WIN_CESA_TARGET_ARMADA38X,
283 &get_cpu_freq_armada38x,
287 &read_cpu_ctrl_armv7,
288 &write_cpu_ctrl_armv7,
289 &win_cpu_armv7_cr_read,
290 &win_cpu_armv7_br_read,
291 &win_cpu_armv7_remap_l_read,
292 &win_cpu_armv7_remap_h_read,
293 &win_cpu_armv7_cr_write,
294 &win_cpu_armv7_br_write,
295 &win_cpu_armv7_remap_l_write,
296 &win_cpu_armv7_remap_h_write,
297 MV_WIN_CPU_MAX_ARMV7,
298 &mv_win_cesa_attr_armadaxp,
299 MV_WIN_CESA_TARGET_ARMADAXP,
306 &get_cpu_freq_armadaxp,
310 &read_cpu_ctrl_armv5,
311 &write_cpu_ctrl_armv5,
312 &win_cpu_armv5_cr_read,
313 &win_cpu_armv5_br_read,
314 &win_cpu_armv5_remap_l_read,
315 &win_cpu_armv5_remap_h_read,
316 &win_cpu_armv5_cr_write,
317 &win_cpu_armv5_br_write,
318 &win_cpu_armv5_remap_l_write,
319 &win_cpu_armv5_remap_h_write,
321 &mv_win_cesa_attr_armv5,
334 struct fdt_pm_mask_entry {
339 static struct fdt_pm_mask_entry fdt_pm_mask_table[] = {
340 { "mrvl,ge", CPU_PM_CTRL_GE(0) },
341 { "mrvl,ge", CPU_PM_CTRL_GE(1) },
342 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(0) },
343 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(1) },
344 { "mrvl,usb-ehci", CPU_PM_CTRL_USB(2) },
345 { "mrvl,xor", CPU_PM_CTRL_XOR },
346 { "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(int eng_sel)
398 if (soc_decode_win_spec->win_cesa_attr != NULL)
399 return (soc_decode_win_spec->win_cesa_attr(eng_sel));
404 static int mv_win_cesa_attr_armv5(int eng_sel)
407 return MV_WIN_CESA_ATTR(eng_sel);
410 static int mv_win_cesa_attr_armada38x(int eng_sel)
413 return MV_WIN_CESA_ATTR_ARMADA38X(eng_sel);
416 static int mv_win_cesa_attr_armadaxp(int eng_sel)
419 return MV_WIN_CESA_ATTR_ARMADAXP(eng_sel);
423 mv_check_soc_family()
432 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMADA_XP];
433 soc_family = MV_SOC_ARMADA_XP;
434 return (MV_SOC_ARMADA_XP);
438 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMADA_38X];
439 soc_family = MV_SOC_ARMADA_38X;
440 return (MV_SOC_ARMADA_38X);
445 case MV_DEV_88RC8180:
446 case MV_DEV_88RC9480:
447 case MV_DEV_88RC9580:
450 case MV_DEV_MV78100_Z0:
453 soc_decode_win_spec = &decode_win_specs[MV_SOC_ARMV5];
454 soc_family = MV_SOC_ARMV5;
455 return (MV_SOC_ARMV5);
457 soc_family = MV_SOC_UNSUPPORTED;
458 return (MV_SOC_UNSUPPORTED);
463 pm_disable_device(int mask)
468 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
469 printf("Power Management Register: 0%x\n", reg);
472 soc_power_ctrl_set(reg);
473 printf("Device %x is disabled\n", mask);
475 reg = soc_power_ctrl_get(CPU_PM_CTRL_ALL);
476 printf("Power Management Register: 0%x\n", reg);
481 fdt_pm(phandle_t node)
483 uint32_t cpu_pm_ctrl;
487 cpu_pm_ctrl = read_cpu_ctrl(CPU_PM_CTRL);
488 for (i = 0; fdt_pm_mask_table[i].compat != NULL; i++) {
489 if (dev_mask & (1 << i))
492 compat = ofw_bus_node_is_compatible(node,
493 fdt_pm_mask_table[i].compat);
494 #if defined(SOC_MV_KIRKWOOD)
495 if (compat && (cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
496 dev_mask |= (1 << i);
500 dev_mask |= (1 << i);
504 if (compat && (~cpu_pm_ctrl & fdt_pm_mask_table[i].mask)) {
505 dev_mask |= (1 << i);
509 dev_mask |= (1 << i);
519 read_cpu_ctrl(uint32_t reg)
522 if (soc_decode_win_spec->read_cpu_ctrl != NULL)
523 return (soc_decode_win_spec->read_cpu_ctrl(reg));
528 read_cpu_ctrl_armv5(uint32_t reg)
531 return (bus_space_read_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg));
535 read_cpu_ctrl_armv7(uint32_t reg)
538 return (bus_space_read_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE_ARMV7, reg));
542 write_cpu_ctrl(uint32_t reg, uint32_t val)
545 if (soc_decode_win_spec->write_cpu_ctrl != NULL)
546 soc_decode_win_spec->write_cpu_ctrl(reg, val);
550 write_cpu_ctrl_armv5(uint32_t reg, uint32_t val)
553 bus_space_write_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE, reg, val);
557 write_cpu_ctrl_armv7(uint32_t reg, uint32_t val)
560 bus_space_write_4(fdtbus_bs_tag, MV_CPU_CONTROL_BASE_ARMV7, reg, val);
564 read_cpu_mp_clocks(uint32_t reg)
567 return (bus_space_read_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg));
571 write_cpu_mp_clocks(uint32_t reg, uint32_t val)
574 bus_space_write_4(fdtbus_bs_tag, MV_MP_CLOCKS_BASE, reg, val);
578 read_cpu_misc(uint32_t reg)
581 return (bus_space_read_4(fdtbus_bs_tag, MV_MISC_BASE, reg));
585 write_cpu_misc(uint32_t reg, uint32_t val)
588 bus_space_write_4(fdtbus_bs_tag, MV_MISC_BASE, reg, val);
602 case MV_DEV_88RC8180:
603 case MV_DEV_MV78100_Z0:
605 __asm __volatile("mrc p15, 1, %0, c15, c1, 0" : "=r" (ef));
609 __asm __volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (ef));
613 printf("This ARM Core does not support any extra features\n");
620 * Get the power status of device. This feature is only supported on
621 * Kirkwood and Discovery SoCs.
624 soc_power_ctrl_get(uint32_t mask)
627 #if SOC_MV_POWER_STAT_SUPPORTED
628 if (mask != CPU_PM_CTRL_NONE)
629 mask &= read_cpu_ctrl(CPU_PM_CTRL);
638 * Set the power status of device. This feature is only supported on
639 * Kirkwood and Discovery SoCs.
642 soc_power_ctrl_set(uint32_t mask)
645 #if !defined(SOC_MV_ORION)
646 if (mask != CPU_PM_CTRL_NONE)
647 write_cpu_ctrl(CPU_PM_CTRL, mask);
652 soc_id(uint32_t *dev, uint32_t *rev)
654 uint64_t mv_pcie_base = MV_PCIE_BASE;
658 * Notice: system identifiers are available in the registers range of
659 * PCIE controller, so using this function is only allowed (and
660 * possible) after the internal registers range has been mapped in via
661 * devmap_bootstrap().
665 if ((node = OF_finddevice("/")) == -1)
667 if (ofw_bus_node_is_compatible(node, "marvell,armada380"))
668 mv_pcie_base = MV_PCIE_BASE_ARMADA38X;
670 *dev = bus_space_read_4(fdtbus_bs_tag, mv_pcie_base, 0) >> 16;
671 *rev = bus_space_read_4(fdtbus_bs_tag, mv_pcie_base, 8) & 0xff;
677 uint32_t d, r, size, mode, freq;
685 printf("(0x%4x:0x%02x) ", d, r);
690 dev = "Marvell 88F5181";
695 dev = "Marvell 88F5182";
700 dev = "Marvell 88F5281";
709 dev = "Marvell 88F6281";
717 case MV_DEV_88RC8180:
718 dev = "Marvell 88RC8180";
720 case MV_DEV_88RC9480:
721 dev = "Marvell 88RC9480";
723 case MV_DEV_88RC9580:
724 dev = "Marvell 88RC9580";
727 dev = "Marvell 88F6781";
732 dev = "Marvell 88F6282";
739 dev = "Marvell 88F6828";
742 dev = "Marvell 88F6820";
745 dev = "Marvell 88F6810";
747 case MV_DEV_MV78100_Z0:
748 dev = "Marvell MV78100 Z0";
751 dev = "Marvell MV78100";
754 dev = "Marvell MV78160";
757 dev = "Marvell MV78260";
760 dev = "Marvell MV78460";
769 printf(" rev %s", rev);
770 printf(", TClock %dMHz", get_tclk() / 1000 / 1000);
771 freq = get_cpu_freq();
773 printf(", Frequency %dMHz", freq / 1000 / 1000);
776 mode = read_cpu_ctrl(CPU_CONFIG);
777 printf(" Instruction cache prefetch %s, data cache prefetch %s\n",
778 (mode & CPU_CONFIG_IC_PREF) ? "enabled" : "disabled",
779 (mode & CPU_CONFIG_DC_PREF) ? "enabled" : "disabled");
784 mode = read_cpu_ctrl(CPU_L2_CONFIG) & CPU_L2_CONFIG_MODE;
785 printf(" 256KB 4-way set-associative %s unified L2 cache\n",
786 mode ? "write-through" : "write-back");
789 mode = read_cpu_ctrl(CPU_CONTROL);
790 size = mode & CPU_CONTROL_L2_SIZE;
791 mode = mode & CPU_CONTROL_L2_MODE;
792 printf(" %s set-associative %s unified L2 cache\n",
793 size ? "256KB 4-way" : "512KB 8-way",
794 mode ? "write-through" : "write-back");
802 platform_identify(void *dummy)
808 * XXX Board identification e.g. read out from FPGA or similar should
812 SYSINIT(platform_identify, SI_SUB_CPU, SI_ORDER_SECOND, platform_identify,
817 mv_enter_debugger(void *dummy)
820 if (boothowto & RB_KDB)
821 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
823 SYSINIT(mv_enter_debugger, SI_SUB_CPU, SI_ORDER_ANY, mv_enter_debugger, NULL);
833 TUNABLE_INT_FETCH("hw.pm-disable-mask", &mask);
836 pm_disable_device(mask);
838 /* Retrieve data about physical addresses from device tree. */
839 if ((err = win_cpu_from_dt()) != 0)
842 /* Retrieve our ID: some windows facilities vary between SoC models */
845 if (soc_family == MV_SOC_ARMADA_XP)
846 if ((err = decode_win_sdram_fixup()) != 0)
850 decode_win_cpu_setup();
852 soc_dump_decode_win();
856 if ((err = fdt_win_setup()) != 0)
862 /**************************************************************************
863 * Decode windows registers accessors
864 **************************************************************************/
865 WIN_REG_IDX_RD(win_cpu_armv5, cr, MV_WIN_CPU_CTRL_ARMV5, MV_MBUS_BRIDGE_BASE)
866 WIN_REG_IDX_RD(win_cpu_armv5, br, MV_WIN_CPU_BASE_ARMV5, MV_MBUS_BRIDGE_BASE)
867 WIN_REG_IDX_RD(win_cpu_armv5, remap_l, MV_WIN_CPU_REMAP_LO_ARMV5, MV_MBUS_BRIDGE_BASE)
868 WIN_REG_IDX_RD(win_cpu_armv5, remap_h, MV_WIN_CPU_REMAP_HI_ARMV5, MV_MBUS_BRIDGE_BASE)
869 WIN_REG_IDX_WR(win_cpu_armv5, cr, MV_WIN_CPU_CTRL_ARMV5, MV_MBUS_BRIDGE_BASE)
870 WIN_REG_IDX_WR(win_cpu_armv5, br, MV_WIN_CPU_BASE_ARMV5, MV_MBUS_BRIDGE_BASE)
871 WIN_REG_IDX_WR(win_cpu_armv5, remap_l, MV_WIN_CPU_REMAP_LO_ARMV5, MV_MBUS_BRIDGE_BASE)
872 WIN_REG_IDX_WR(win_cpu_armv5, remap_h, MV_WIN_CPU_REMAP_HI_ARMV5, MV_MBUS_BRIDGE_BASE)
874 WIN_REG_IDX_RD(win_cpu_armv7, cr, MV_WIN_CPU_CTRL_ARMV7, MV_MBUS_BRIDGE_BASE)
875 WIN_REG_IDX_RD(win_cpu_armv7, br, MV_WIN_CPU_BASE_ARMV7, MV_MBUS_BRIDGE_BASE)
876 WIN_REG_IDX_RD(win_cpu_armv7, remap_l, MV_WIN_CPU_REMAP_LO_ARMV7, MV_MBUS_BRIDGE_BASE)
877 WIN_REG_IDX_RD(win_cpu_armv7, remap_h, MV_WIN_CPU_REMAP_HI_ARMV7, MV_MBUS_BRIDGE_BASE)
878 WIN_REG_IDX_WR(win_cpu_armv7, cr, MV_WIN_CPU_CTRL_ARMV7, MV_MBUS_BRIDGE_BASE)
879 WIN_REG_IDX_WR(win_cpu_armv7, br, MV_WIN_CPU_BASE_ARMV7, MV_MBUS_BRIDGE_BASE)
880 WIN_REG_IDX_WR(win_cpu_armv7, remap_l, MV_WIN_CPU_REMAP_LO_ARMV7, MV_MBUS_BRIDGE_BASE)
881 WIN_REG_IDX_WR(win_cpu_armv7, remap_h, MV_WIN_CPU_REMAP_HI_ARMV7, MV_MBUS_BRIDGE_BASE)
884 win_cpu_cr_read(int i)
887 if (soc_decode_win_spec->cr_read != NULL)
888 return (soc_decode_win_spec->cr_read(i));
893 win_cpu_br_read(int i)
896 if (soc_decode_win_spec->br_read != NULL)
897 return (soc_decode_win_spec->br_read(i));
902 win_cpu_remap_l_read(int i)
905 if (soc_decode_win_spec->remap_l_read != NULL)
906 return (soc_decode_win_spec->remap_l_read(i));
911 win_cpu_remap_h_read(int i)
914 if (soc_decode_win_spec->remap_h_read != NULL)
915 return soc_decode_win_spec->remap_h_read(i);
920 win_cpu_cr_write(int i, uint32_t val)
923 if (soc_decode_win_spec->cr_write != NULL)
924 soc_decode_win_spec->cr_write(i, val);
928 win_cpu_br_write(int i, uint32_t val)
931 if (soc_decode_win_spec->br_write != NULL)
932 soc_decode_win_spec->br_write(i, val);
936 win_cpu_remap_l_write(int i, uint32_t val)
939 if (soc_decode_win_spec->remap_l_write != NULL)
940 soc_decode_win_spec->remap_l_write(i, val);
944 win_cpu_remap_h_write(int i, uint32_t val)
947 if (soc_decode_win_spec->remap_h_write != NULL)
948 soc_decode_win_spec->remap_h_write(i, val);
951 WIN_REG_BASE_IDX_RD(win_cesa, cr, MV_WIN_CESA_CTRL)
952 WIN_REG_BASE_IDX_RD(win_cesa, br, MV_WIN_CESA_BASE)
953 WIN_REG_BASE_IDX_WR(win_cesa, cr, MV_WIN_CESA_CTRL)
954 WIN_REG_BASE_IDX_WR(win_cesa, br, MV_WIN_CESA_BASE)
956 WIN_REG_BASE_IDX_RD(win_usb, cr, MV_WIN_USB_CTRL)
957 WIN_REG_BASE_IDX_RD(win_usb, br, MV_WIN_USB_BASE)
958 WIN_REG_BASE_IDX_WR(win_usb, cr, MV_WIN_USB_CTRL)
959 WIN_REG_BASE_IDX_WR(win_usb, br, MV_WIN_USB_BASE)
961 WIN_REG_BASE_IDX_RD(win_usb3, cr, MV_WIN_USB3_CTRL)
962 WIN_REG_BASE_IDX_RD(win_usb3, br, MV_WIN_USB3_BASE)
963 WIN_REG_BASE_IDX_WR(win_usb3, cr, MV_WIN_USB3_CTRL)
964 WIN_REG_BASE_IDX_WR(win_usb3, br, MV_WIN_USB3_BASE)
966 WIN_REG_BASE_IDX_RD(win_eth, br, MV_WIN_ETH_BASE)
967 WIN_REG_BASE_IDX_RD(win_eth, sz, MV_WIN_ETH_SIZE)
968 WIN_REG_BASE_IDX_RD(win_eth, har, MV_WIN_ETH_REMAP)
969 WIN_REG_BASE_IDX_WR(win_eth, br, MV_WIN_ETH_BASE)
970 WIN_REG_BASE_IDX_WR(win_eth, sz, MV_WIN_ETH_SIZE)
971 WIN_REG_BASE_IDX_WR(win_eth, har, MV_WIN_ETH_REMAP)
973 WIN_REG_BASE_IDX_RD2(win_xor, br, MV_WIN_XOR_BASE)
974 WIN_REG_BASE_IDX_RD2(win_xor, sz, MV_WIN_XOR_SIZE)
975 WIN_REG_BASE_IDX_RD2(win_xor, har, MV_WIN_XOR_REMAP)
976 WIN_REG_BASE_IDX_RD2(win_xor, ctrl, MV_WIN_XOR_CTRL)
977 WIN_REG_BASE_IDX_WR2(win_xor, br, MV_WIN_XOR_BASE)
978 WIN_REG_BASE_IDX_WR2(win_xor, sz, MV_WIN_XOR_SIZE)
979 WIN_REG_BASE_IDX_WR2(win_xor, har, MV_WIN_XOR_REMAP)
980 WIN_REG_BASE_IDX_WR2(win_xor, ctrl, MV_WIN_XOR_CTRL)
982 WIN_REG_BASE_RD(win_eth, bare, 0x290)
983 WIN_REG_BASE_RD(win_eth, epap, 0x294)
984 WIN_REG_BASE_WR(win_eth, bare, 0x290)
985 WIN_REG_BASE_WR(win_eth, epap, 0x294)
987 WIN_REG_BASE_IDX_RD(win_pcie, cr, MV_WIN_PCIE_CTRL);
988 WIN_REG_BASE_IDX_RD(win_pcie, br, MV_WIN_PCIE_BASE);
989 WIN_REG_BASE_IDX_RD(win_pcie, remap, MV_WIN_PCIE_REMAP);
990 WIN_REG_BASE_IDX_WR(win_pcie, cr, MV_WIN_PCIE_CTRL);
991 WIN_REG_BASE_IDX_WR(win_pcie, br, MV_WIN_PCIE_BASE);
992 WIN_REG_BASE_IDX_WR(win_pcie, remap, MV_WIN_PCIE_REMAP);
993 WIN_REG_BASE_IDX_RD(pcie_bar, br, MV_PCIE_BAR_BASE);
994 WIN_REG_BASE_IDX_RD(pcie_bar, brh, MV_PCIE_BAR_BASE_H);
995 WIN_REG_BASE_IDX_RD(pcie_bar, cr, MV_PCIE_BAR_CTRL);
996 WIN_REG_BASE_IDX_WR(pcie_bar, br, MV_PCIE_BAR_BASE);
997 WIN_REG_BASE_IDX_WR(pcie_bar, brh, MV_PCIE_BAR_BASE_H);
998 WIN_REG_BASE_IDX_WR(pcie_bar, cr, MV_PCIE_BAR_CTRL);
1000 WIN_REG_BASE_IDX_RD(win_idma, br, MV_WIN_IDMA_BASE)
1001 WIN_REG_BASE_IDX_RD(win_idma, sz, MV_WIN_IDMA_SIZE)
1002 WIN_REG_BASE_IDX_RD(win_idma, har, MV_WIN_IDMA_REMAP)
1003 WIN_REG_BASE_IDX_RD(win_idma, cap, MV_WIN_IDMA_CAP)
1004 WIN_REG_BASE_IDX_WR(win_idma, br, MV_WIN_IDMA_BASE)
1005 WIN_REG_BASE_IDX_WR(win_idma, sz, MV_WIN_IDMA_SIZE)
1006 WIN_REG_BASE_IDX_WR(win_idma, har, MV_WIN_IDMA_REMAP)
1007 WIN_REG_BASE_IDX_WR(win_idma, cap, MV_WIN_IDMA_CAP)
1008 WIN_REG_BASE_RD(win_idma, bare, 0xa80)
1009 WIN_REG_BASE_WR(win_idma, bare, 0xa80)
1011 WIN_REG_BASE_IDX_RD(win_sata, cr, MV_WIN_SATA_CTRL);
1012 WIN_REG_BASE_IDX_RD(win_sata, br, MV_WIN_SATA_BASE);
1013 WIN_REG_BASE_IDX_WR(win_sata, cr, MV_WIN_SATA_CTRL);
1014 WIN_REG_BASE_IDX_WR(win_sata, br, MV_WIN_SATA_BASE);
1016 WIN_REG_BASE_IDX_RD(win_sata_armada38x, sz, MV_WIN_SATA_SIZE_ARMADA38X);
1017 WIN_REG_BASE_IDX_WR(win_sata_armada38x, sz, MV_WIN_SATA_SIZE_ARMADA38X);
1018 WIN_REG_BASE_IDX_RD(win_sata_armada38x, cr, MV_WIN_SATA_CTRL_ARMADA38X);
1019 WIN_REG_BASE_IDX_RD(win_sata_armada38x, br, MV_WIN_SATA_BASE_ARMADA38X);
1020 WIN_REG_BASE_IDX_WR(win_sata_armada38x, cr, MV_WIN_SATA_CTRL_ARMADA38X);
1021 WIN_REG_BASE_IDX_WR(win_sata_armada38x, br, MV_WIN_SATA_BASE_ARMADA38X);
1023 WIN_REG_BASE_IDX_RD(win_sdhci, cr, MV_WIN_SDHCI_CTRL);
1024 WIN_REG_BASE_IDX_RD(win_sdhci, br, MV_WIN_SDHCI_BASE);
1025 WIN_REG_BASE_IDX_WR(win_sdhci, cr, MV_WIN_SDHCI_CTRL);
1026 WIN_REG_BASE_IDX_WR(win_sdhci, br, MV_WIN_SDHCI_BASE);
1029 WIN_REG_IDX_RD(ddr_armv5, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
1030 WIN_REG_IDX_RD(ddr_armv5, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
1031 WIN_REG_IDX_WR(ddr_armv5, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
1032 WIN_REG_IDX_WR(ddr_armv5, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
1034 WIN_REG_IDX_RD(ddr_armv7, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE_ARMV7)
1035 WIN_REG_IDX_RD(ddr_armv7, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE_ARMV7)
1036 WIN_REG_IDX_WR(ddr_armv7, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE_ARMV7)
1037 WIN_REG_IDX_WR(ddr_armv7, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE_ARMV7)
1039 static inline uint32_t
1043 if (soc_decode_win_spec->ddr_br_read != NULL)
1044 return (soc_decode_win_spec->ddr_br_read(i));
1048 static inline uint32_t
1052 if (soc_decode_win_spec->ddr_sz_read != NULL)
1053 return (soc_decode_win_spec->ddr_sz_read(i));
1058 ddr_br_write(int i, uint32_t val)
1061 if (soc_decode_win_spec->ddr_br_write != NULL)
1062 soc_decode_win_spec->ddr_br_write(i, val);
1066 ddr_sz_write(int i, uint32_t val)
1069 if (soc_decode_win_spec->ddr_sz_write != NULL)
1070 soc_decode_win_spec->ddr_sz_write(i, val);
1074 * On 88F6781 (Dove) SoC DDR Controller is accessed through
1075 * single MBUS <-> AXI bridge. In this case we provide emulated
1076 * ddr_br_read() and ddr_sz_read() functions to keep compatibility
1077 * with common decoding windows setup code.
1080 static inline uint32_t ddr_br_read(int i)
1084 /* Read Memory Address Map Register for CS i */
1085 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
1087 /* Return CS i base address */
1088 return (mmap & 0xFF000000);
1091 static inline uint32_t ddr_sz_read(int i)
1093 uint32_t mmap, size;
1095 /* Read Memory Address Map Register for CS i */
1096 mmap = bus_space_read_4(fdtbus_bs_tag, MV_DDR_CADR_BASE + (i * 0x10), 0);
1098 /* Extract size of CS space in 64kB units */
1099 size = (1 << ((mmap >> 16) & 0x0F));
1101 /* Return CS size and enable/disable status */
1102 return (((size - 1) << 16) | (mmap & 0x01));
1106 /**************************************************************************
1107 * Decode windows helper routines
1108 **************************************************************************/
1110 soc_dump_decode_win(void)
1114 for (i = 0; i < soc_decode_win_spec->mv_win_cpu_max; i++) {
1115 printf("CPU window#%d: c 0x%08x, b 0x%08x", i,
1117 win_cpu_br_read(i));
1119 if (win_cpu_can_remap(i))
1120 printf(", rl 0x%08x, rh 0x%08x",
1121 win_cpu_remap_l_read(i),
1122 win_cpu_remap_h_read(i));
1126 printf("Internal regs base: 0x%08x\n",
1127 bus_space_read_4(fdtbus_bs_tag, MV_INTREGS_BASE, 0));
1129 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1130 printf("DDR CS#%d: b 0x%08x, s 0x%08x\n", i,
1131 ddr_br_read(i), ddr_sz_read(i));
1134 /**************************************************************************
1135 * CPU windows routines
1136 **************************************************************************/
1138 win_cpu_can_remap(int i)
1144 /* Depending on the SoC certain windows have remap capability */
1145 if ((dev == MV_DEV_88F5182 && i < 2) ||
1146 (dev == MV_DEV_88F5281 && i < 4) ||
1147 (dev == MV_DEV_88F6281 && i < 4) ||
1148 (dev == MV_DEV_88F6282 && i < 4) ||
1149 (dev == MV_DEV_88F6828 && i < 20) ||
1150 (dev == MV_DEV_88F6820 && i < 20) ||
1151 (dev == MV_DEV_88F6810 && i < 20) ||
1152 (dev == MV_DEV_88RC8180 && i < 2) ||
1153 (dev == MV_DEV_88F6781 && i < 4) ||
1154 (dev == MV_DEV_MV78100_Z0 && i < 8) ||
1155 ((dev & MV_DEV_FAMILY_MASK) == MV_DEV_DISCOVERY && i < 8))
1161 /* XXX This should check for overlapping remap fields too.. */
1163 decode_win_overlap(int win, int win_no, const struct decode_win *wintab)
1165 const struct decode_win *tab;
1170 for (i = 0; i < win_no; i++, tab++) {
1175 if ((tab->base + tab->size - 1) < (wintab + win)->base)
1178 else if (((wintab + win)->base + (wintab + win)->size - 1) <
1189 decode_win_cpu_valid(void)
1194 if (cpu_wins_no > soc_decode_win_spec->mv_win_cpu_max) {
1195 printf("CPU windows: too many entries: %d\n", cpu_wins_no);
1200 for (i = 0; i < cpu_wins_no; i++) {
1202 if (cpu_wins[i].target == 0) {
1203 printf("CPU window#%d: DDR target window is not "
1204 "supposed to be reprogrammed!\n", i);
1208 if (cpu_wins[i].remap != ~0 && win_cpu_can_remap(i) != 1) {
1209 printf("CPU window#%d: not capable of remapping, but "
1210 "val 0x%08x defined\n", i, cpu_wins[i].remap);
1214 s = cpu_wins[i].size;
1215 b = cpu_wins[i].base;
1217 if (s > (0xFFFFFFFF - b + 1)) {
1219 * XXX this boundary check should account for 64bit
1222 printf("CPU window#%d: no space for size 0x%08x at "
1223 "0x%08x\n", i, s, b);
1228 if (b != rounddown2(b, s)) {
1229 printf("CPU window#%d: address 0x%08x is not aligned "
1230 "to 0x%08x\n", i, b, s);
1235 j = decode_win_overlap(i, cpu_wins_no, &cpu_wins[0]);
1237 printf("CPU window#%d: (0x%08x - 0x%08x) overlaps "
1238 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
1240 cpu_wins[j].base + cpu_wins[j].size - 1);
1249 decode_win_cpu_set(int target, int attr, vm_paddr_t base, uint32_t size,
1256 win = soc_decode_win_spec->mv_win_cpu_max - 1;
1263 while ((win >= 0) && (win < soc_decode_win_spec->mv_win_cpu_max)) {
1264 cr = win_cpu_cr_read(win);
1265 if ((cr & MV_WIN_CPU_ENABLE_BIT) == 0)
1267 if ((cr & ((0xff << MV_WIN_CPU_ATTR_SHIFT) |
1268 (0x1f << MV_WIN_CPU_TARGET_SHIFT))) ==
1269 ((attr << MV_WIN_CPU_ATTR_SHIFT) |
1270 (target << MV_WIN_CPU_TARGET_SHIFT)))
1274 if ((win < 0) || (win >= soc_decode_win_spec->mv_win_cpu_max) ||
1275 ((remap != ~0) && (win_cpu_can_remap(win) == 0)))
1278 br = base & 0xffff0000;
1279 win_cpu_br_write(win, br);
1281 if (win_cpu_can_remap(win)) {
1283 win_cpu_remap_l_write(win, remap & 0xffff0000);
1284 win_cpu_remap_h_write(win, 0);
1287 * Remap function is not used for a given window
1288 * (capable of remapping) - set remap field with the
1289 * same value as base.
1291 win_cpu_remap_l_write(win, base & 0xffff0000);
1292 win_cpu_remap_h_write(win, 0);
1296 cr = ((size - 1) & 0xffff0000) | (attr << MV_WIN_CPU_ATTR_SHIFT) |
1297 (target << MV_WIN_CPU_TARGET_SHIFT) | MV_WIN_CPU_ENABLE_BIT;
1298 win_cpu_cr_write(win, cr);
1304 decode_win_cpu_setup(void)
1308 /* Disable all CPU windows */
1309 for (i = 0; i < soc_decode_win_spec->mv_win_cpu_max; i++) {
1310 win_cpu_cr_write(i, 0);
1311 win_cpu_br_write(i, 0);
1312 if (win_cpu_can_remap(i)) {
1313 win_cpu_remap_l_write(i, 0);
1314 win_cpu_remap_h_write(i, 0);
1318 for (i = 0; i < cpu_wins_no; i++)
1319 if (cpu_wins[i].target > 0)
1320 decode_win_cpu_set(cpu_wins[i].target,
1321 cpu_wins[i].attr, cpu_wins[i].base,
1322 cpu_wins[i].size, cpu_wins[i].remap);
1327 decode_win_sdram_fixup(void)
1329 struct mem_region mr[FDT_MEM_REGIONS];
1330 uint8_t window_valid[MV_WIN_DDR_MAX];
1331 int mr_cnt, err, i, j;
1332 uint32_t valid_win_num = 0;
1334 /* Grab physical memory regions information from device tree. */
1335 err = fdt_get_mem_regions(mr, &mr_cnt, NULL);
1339 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1340 window_valid[i] = 0;
1342 /* Try to match entries from device tree with settings from u-boot */
1343 for (i = 0; i < mr_cnt; i++) {
1344 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
1345 if (ddr_is_active(j) &&
1346 (ddr_base(j) == mr[i].mr_start) &&
1347 (ddr_size(j) == mr[i].mr_size)) {
1348 window_valid[j] = 1;
1354 if (mr_cnt != valid_win_num)
1357 /* Destroy windows without corresponding device tree entry */
1358 for (j = 0; j < MV_WIN_DDR_MAX; j++) {
1359 if (ddr_is_active(j) && (window_valid[j] != 1)) {
1360 printf("Disabling SDRAM decoding window: %d\n", j);
1368 * Check if we're able to cover all active DDR banks.
1371 decode_win_can_cover_ddr(int max)
1376 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1377 if (ddr_is_active(i))
1381 printf("Unable to cover all active DDR banks: "
1382 "%d, available windows: %d\n", c, max);
1389 /**************************************************************************
1390 * DDR windows routines
1391 **************************************************************************/
1393 ddr_is_active(int i)
1396 if (ddr_sz_read(i) & 0x1)
1414 return (ddr_br_read(i) & 0xff000000);
1421 return ((ddr_sz_read(i) | 0x00ffffff) + 1);
1427 uint32_t dev, rev, attr;
1430 if (dev == MV_DEV_88RC8180)
1431 return ((ddr_sz_read(i) & 0xf0) >> 4);
1432 if (dev == MV_DEV_88F6781)
1435 attr = (i == 0 ? 0xe :
1438 (i == 3 ? 0x7 : 0xff))));
1439 if (platform_io_coherent)
1451 if (dev == MV_DEV_88RC8180) {
1452 i = (ddr_sz_read(i) & 0xf0) >> 4;
1453 return (i == 0xe ? 0xc :
1456 (i == 0x7 ? 0xf : 0xc))));
1460 * On SOCs other than 88RC8180 Mbus unit ID for
1461 * DDR SDRAM controller is always 0x0.
1466 /**************************************************************************
1467 * CESA windows routines
1468 **************************************************************************/
1470 decode_win_cesa_valid(void)
1473 return (decode_win_can_cover_ddr(MV_WIN_CESA_MAX));
1477 decode_win_cesa_dump(u_long base)
1481 for (i = 0; i < MV_WIN_CESA_MAX; i++)
1482 printf("CESA window#%d: c 0x%08x, b 0x%08x\n", i,
1483 win_cesa_cr_read(base, i), win_cesa_br_read(base, i));
1487 * Set CESA decode windows.
1490 decode_win_cesa_setup(u_long base)
1496 for (i = 0; i < MV_WIN_CESA_MAX; i++) {
1497 win_cesa_cr_write(base, i, 0);
1498 win_cesa_br_write(base, i, 0);
1501 /* Only access to active DRAM banks is required */
1502 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1503 if (ddr_is_active(i)) {
1508 * Armada 38x SoC's equipped with 4GB DRAM
1509 * suffer freeze during CESA operation, if
1510 * MBUS window opened at given DRAM CS reaches
1511 * end of the address space. Apply a workaround
1512 * by setting the window size to the closest possible
1513 * value, i.e. divide it by 2.
1515 if ((soc_family == MV_SOC_ARMADA_38X) &&
1516 (size + ddr_base(i) == 0x100000000ULL))
1519 cr = (((size - 1) & 0xffff0000) |
1520 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
1521 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
1524 /* Set the first free CESA window */
1525 for (j = 0; j < MV_WIN_CESA_MAX; j++) {
1526 if (win_cesa_cr_read(base, j) & 0x1)
1529 win_cesa_br_write(base, j, br);
1530 win_cesa_cr_write(base, j, cr);
1537 /**************************************************************************
1538 * USB windows routines
1539 **************************************************************************/
1541 decode_win_usb_valid(void)
1544 return (decode_win_can_cover_ddr(MV_WIN_USB_MAX));
1548 decode_win_usb_dump(u_long base)
1552 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port - 1)))
1555 for (i = 0; i < MV_WIN_USB_MAX; i++)
1556 printf("USB window#%d: c 0x%08x, b 0x%08x\n", i,
1557 win_usb_cr_read(base, i), win_usb_br_read(base, i));
1561 * Set USB decode windows.
1564 decode_win_usb_setup(u_long base)
1569 if (pm_is_disabled(CPU_PM_CTRL_USB(usb_port)))
1574 for (i = 0; i < MV_WIN_USB_MAX; i++) {
1575 win_usb_cr_write(base, i, 0);
1576 win_usb_br_write(base, i, 0);
1579 /* Only access to active DRAM banks is required */
1580 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1581 if (ddr_is_active(i)) {
1584 * XXX for 6281 we should handle Mbus write
1585 * burst limit field in the ctrl reg
1587 cr = (((ddr_size(i) - 1) & 0xffff0000) |
1588 (ddr_attr(i) << 8) |
1589 (ddr_target(i) << 4) | 1);
1591 /* Set the first free USB window */
1592 for (j = 0; j < MV_WIN_USB_MAX; j++) {
1593 if (win_usb_cr_read(base, j) & 0x1)
1596 win_usb_br_write(base, j, br);
1597 win_usb_cr_write(base, j, cr);
1604 /**************************************************************************
1605 * USB3 windows routines
1606 **************************************************************************/
1608 decode_win_usb3_valid(void)
1611 return (decode_win_can_cover_ddr(MV_WIN_USB3_MAX));
1615 decode_win_usb3_dump(u_long base)
1619 for (i = 0; i < MV_WIN_USB3_MAX; i++)
1620 printf("USB3.0 window#%d: c 0x%08x, b 0x%08x\n", i,
1621 win_usb3_cr_read(base, i), win_usb3_br_read(base, i));
1625 * Set USB3 decode windows
1628 decode_win_usb3_setup(u_long base)
1633 for (i = 0; i < MV_WIN_USB3_MAX; i++) {
1634 win_usb3_cr_write(base, i, 0);
1635 win_usb3_br_write(base, i, 0);
1638 /* Only access to active DRAM banks is required */
1639 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1640 if (ddr_is_active(i)) {
1642 cr = (((ddr_size(i) - 1) &
1643 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT)) |
1644 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
1645 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
1648 /* Set the first free USB3.0 window */
1649 for (j = 0; j < MV_WIN_USB3_MAX; j++) {
1650 if (win_usb3_cr_read(base, j) & IO_WIN_ENA_MASK)
1653 win_usb3_br_write(base, j, br);
1654 win_usb3_cr_write(base, j, cr);
1662 /**************************************************************************
1663 * ETH windows routines
1664 **************************************************************************/
1667 win_eth_can_remap(int i)
1670 /* ETH encode windows 0-3 have remap capability */
1678 eth_bare_read(uint32_t base, int i)
1682 v = win_eth_bare_read(base);
1689 eth_bare_write(uint32_t base, int i, int val)
1693 v = win_eth_bare_read(base);
1696 win_eth_bare_write(base, v);
1700 eth_epap_write(uint32_t base, int i, int val)
1704 v = win_eth_epap_read(base);
1705 v &= ~(0x3 << (i * 2));
1706 v |= (val << (i * 2));
1707 win_eth_epap_write(base, v);
1711 decode_win_eth_dump(u_long base)
1715 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port - 1)))
1718 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1719 printf("ETH window#%d: b 0x%08x, s 0x%08x", i,
1720 win_eth_br_read(base, i),
1721 win_eth_sz_read(base, i));
1723 if (win_eth_can_remap(i))
1724 printf(", ha 0x%08x",
1725 win_eth_har_read(base, i));
1729 printf("ETH windows: bare 0x%08x, epap 0x%08x\n",
1730 win_eth_bare_read(base),
1731 win_eth_epap_read(base));
1734 #define MV_WIN_ETH_DDR_TRGT(n) ddr_target(n)
1737 decode_win_eth_setup(u_long base)
1742 if (pm_is_disabled(CPU_PM_CTRL_GE(eth_port)))
1747 /* Disable, clear and revoke protection for all ETH windows */
1748 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
1750 eth_bare_write(base, i, 1);
1751 eth_epap_write(base, i, 0);
1752 win_eth_br_write(base, i, 0);
1753 win_eth_sz_write(base, i, 0);
1754 if (win_eth_can_remap(i))
1755 win_eth_har_write(base, i, 0);
1758 /* Only access to active DRAM banks is required */
1759 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1760 if (ddr_is_active(i)) {
1762 br = ddr_base(i) | (ddr_attr(i) << 8) | MV_WIN_ETH_DDR_TRGT(i);
1763 sz = ((ddr_size(i) - 1) & 0xffff0000);
1765 /* Set the first free ETH window */
1766 for (j = 0; j < MV_WIN_ETH_MAX; j++) {
1767 if (eth_bare_read(base, j) == 0)
1770 win_eth_br_write(base, j, br);
1771 win_eth_sz_write(base, j, sz);
1773 /* XXX remapping ETH windows not supported */
1775 /* Set protection RW */
1776 eth_epap_write(base, j, 0x3);
1779 eth_bare_write(base, j, 0);
1786 decode_win_neta_dump(u_long base)
1789 decode_win_eth_dump(base + MV_WIN_NETA_OFFSET);
1793 decode_win_neta_setup(u_long base)
1796 decode_win_eth_setup(base + MV_WIN_NETA_OFFSET);
1800 decode_win_eth_valid(void)
1803 return (decode_win_can_cover_ddr(MV_WIN_ETH_MAX));
1806 /**************************************************************************
1807 * PCIE windows routines
1808 **************************************************************************/
1810 decode_win_pcie_dump(u_long base)
1814 printf("PCIE windows base 0x%08lx\n", base);
1815 for (i = 0; i < MV_WIN_PCIE_MAX; i++)
1816 printf("PCIE window#%d: cr 0x%08x br 0x%08x remap 0x%08x\n",
1817 i, win_pcie_cr_read(base, i),
1818 win_pcie_br_read(base, i), win_pcie_remap_read(base, i));
1820 for (i = 0; i < MV_PCIE_BAR_MAX; i++)
1821 printf("PCIE bar#%d: cr 0x%08x br 0x%08x brh 0x%08x\n",
1822 i, pcie_bar_cr_read(base, i),
1823 pcie_bar_br_read(base, i), pcie_bar_brh_read(base, i));
1827 decode_win_pcie_setup(u_long base)
1829 uint32_t size = 0, ddrbase = ~0;
1833 for (i = 0; i < MV_PCIE_BAR_MAX; i++) {
1834 pcie_bar_br_write(base, i,
1835 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1837 pcie_bar_brh_write(base, i, 0);
1839 pcie_bar_cr_write(base, i, 0);
1842 for (i = 0; i < MV_WIN_PCIE_MAX; i++) {
1843 win_pcie_cr_write(base, i, 0);
1844 win_pcie_br_write(base, i, 0);
1845 win_pcie_remap_write(base, i, 0);
1848 /* On End-Point only set BAR size to 1MB regardless of DDR size */
1849 if ((bus_space_read_4(fdtbus_bs_tag, base, MV_PCIE_CONTROL)
1850 & MV_PCIE_ROOT_CMPLX) == 0) {
1851 pcie_bar_cr_write(base, 1, 0xf0000 | 1);
1855 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
1856 if (ddr_is_active(i)) {
1857 /* Map DDR to BAR 1 */
1858 cr = (ddr_size(i) - 1) & 0xffff0000;
1859 size += ddr_size(i) & 0xffff0000;
1860 cr |= (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
1865 /* Use the first available PCIE window */
1866 for (j = 0; j < MV_WIN_PCIE_MAX; j++) {
1867 if (win_pcie_cr_read(base, j) != 0)
1870 win_pcie_br_write(base, j, br);
1871 win_pcie_cr_write(base, j, cr);
1878 * Upper 16 bits in BAR register is interpreted as BAR size
1879 * (in 64 kB units) plus 64kB, so subtract 0x10000
1880 * form value passed to register to get correct value.
1883 pcie_bar_cr_write(base, 1, size | 1);
1884 pcie_bar_br_write(base, 1, ddrbase |
1885 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1886 pcie_bar_br_write(base, 0, fdt_immr_pa |
1887 MV_PCIE_BAR_64BIT | MV_PCIE_BAR_PREFETCH_EN);
1891 decode_win_pcie_valid(void)
1894 return (decode_win_can_cover_ddr(MV_WIN_PCIE_MAX));
1897 /**************************************************************************
1898 * IDMA windows routines
1899 **************************************************************************/
1900 #if defined(SOC_MV_ORION) || defined(SOC_MV_DISCOVERY)
1902 idma_bare_read(u_long base, int i)
1906 v = win_idma_bare_read(base);
1913 idma_bare_write(u_long base, int i, int val)
1917 v = win_idma_bare_read(base);
1920 win_idma_bare_write(base, v);
1924 * Sets channel protection 'val' for window 'w' on channel 'c'
1927 idma_cap_write(u_long base, int c, int w, int val)
1931 v = win_idma_cap_read(base, c);
1932 v &= ~(0x3 << (w * 2));
1933 v |= (val << (w * 2));
1934 win_idma_cap_write(base, c, v);
1938 * Set protection 'val' on all channels for window 'w'
1941 idma_set_prot(u_long base, int w, int val)
1945 for (c = 0; c < MV_IDMA_CHAN_MAX; c++)
1946 idma_cap_write(base, c, w, val);
1950 win_idma_can_remap(int i)
1953 /* IDMA decode windows 0-3 have remap capability */
1961 decode_win_idma_setup(u_long base)
1966 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
1969 * Disable and clear all IDMA windows, revoke protection for all channels
1971 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
1973 idma_bare_write(base, i, 1);
1974 win_idma_br_write(base, i, 0);
1975 win_idma_sz_write(base, i, 0);
1976 if (win_idma_can_remap(i) == 1)
1977 win_idma_har_write(base, i, 0);
1979 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
1980 win_idma_cap_write(base, i, 0);
1983 * Set up access to all active DRAM banks
1985 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1986 if (ddr_is_active(i)) {
1987 br = ddr_base(i) | (ddr_attr(i) << 8) | ddr_target(i);
1988 sz = ((ddr_size(i) - 1) & 0xffff0000);
1990 /* Place DDR entries in non-remapped windows */
1991 for (j = 0; j < MV_WIN_IDMA_MAX; j++)
1992 if (win_idma_can_remap(j) != 1 &&
1993 idma_bare_read(base, j) == 1) {
1995 /* Configure window */
1996 win_idma_br_write(base, j, br);
1997 win_idma_sz_write(base, j, sz);
1999 /* Set protection RW on all channels */
2000 idma_set_prot(base, j, 0x3);
2003 idma_bare_write(base, j, 0);
2009 * Remaining targets -- from statically defined table
2011 for (i = 0; i < idma_wins_no; i++)
2012 if (idma_wins[i].target > 0) {
2013 br = (idma_wins[i].base & 0xffff0000) |
2014 (idma_wins[i].attr << 8) | idma_wins[i].target;
2015 sz = ((idma_wins[i].size - 1) & 0xffff0000);
2017 /* Set the first free IDMA window */
2018 for (j = 0; j < MV_WIN_IDMA_MAX; j++) {
2019 if (idma_bare_read(base, j) == 0)
2022 /* Configure window */
2023 win_idma_br_write(base, j, br);
2024 win_idma_sz_write(base, j, sz);
2025 if (win_idma_can_remap(j) &&
2026 idma_wins[j].remap >= 0)
2027 win_idma_har_write(base, j,
2028 idma_wins[j].remap);
2030 /* Set protection RW on all channels */
2031 idma_set_prot(base, j, 0x3);
2034 idma_bare_write(base, j, 0);
2041 decode_win_idma_valid(void)
2043 const struct decode_win *wintab;
2047 if (idma_wins_no > MV_WIN_IDMA_MAX) {
2048 printf("IDMA windows: too many entries: %d\n", idma_wins_no);
2051 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
2052 if (ddr_is_active(i))
2055 if (idma_wins_no > (MV_WIN_IDMA_MAX - c)) {
2056 printf("IDMA windows: too many entries: %d, available: %d\n",
2057 idma_wins_no, MV_WIN_IDMA_MAX - c);
2063 for (i = 0; i < idma_wins_no; i++, wintab++) {
2065 if (wintab->target == 0) {
2066 printf("IDMA window#%d: DDR target window is not "
2067 "supposed to be reprogrammed!\n", i);
2071 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
2072 printf("IDMA window#%d: not capable of remapping, but "
2073 "val 0x%08x defined\n", i, wintab->remap);
2080 if (s > (0xFFFFFFFF - b + 1)) {
2081 /* XXX this boundary check should account for 64bit and
2083 printf("IDMA window#%d: no space for size 0x%08x at "
2084 "0x%08x\n", i, s, b);
2089 j = decode_win_overlap(i, idma_wins_no, &idma_wins[0]);
2091 printf("IDMA window#%d: (0x%08x - 0x%08x) overlaps "
2092 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
2094 idma_wins[j].base + idma_wins[j].size - 1);
2103 decode_win_idma_dump(u_long base)
2107 if (pm_is_disabled(CPU_PM_CTRL_IDMA))
2110 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
2111 printf("IDMA window#%d: b 0x%08x, s 0x%08x", i,
2112 win_idma_br_read(base, i), win_idma_sz_read(base, i));
2114 if (win_idma_can_remap(i))
2115 printf(", ha 0x%08x", win_idma_har_read(base, i));
2119 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
2120 printf("IDMA channel#%d: ap 0x%08x\n", i,
2121 win_idma_cap_read(base, i));
2122 printf("IDMA windows: bare 0x%08x\n", win_idma_bare_read(base));
2126 /* Provide dummy functions to satisfy the build for SoCs not equipped with IDMA */
2128 decode_win_idma_valid(void)
2135 decode_win_idma_setup(u_long base)
2140 decode_win_idma_dump(u_long base)
2145 /**************************************************************************
2146 * XOR windows routines
2147 **************************************************************************/
2148 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
2150 xor_ctrl_read(u_long base, int i, int c, int e)
2153 v = win_xor_ctrl_read(base, c, e);
2160 xor_ctrl_write(u_long base, int i, int c, int e, int val)
2164 v = win_xor_ctrl_read(base, c, e);
2167 win_xor_ctrl_write(base, c, e, v);
2171 * Set channel protection 'val' for window 'w' on channel 'c'
2174 xor_chan_write(u_long base, int c, int e, int w, int val)
2178 v = win_xor_ctrl_read(base, c, e);
2179 v &= ~(0x3 << (w * 2 + 16));
2180 v |= (val << (w * 2 + 16));
2181 win_xor_ctrl_write(base, c, e, v);
2185 * Set protection 'val' on all channels for window 'w' on engine 'e'
2188 xor_set_prot(u_long base, int w, int e, int val)
2192 for (c = 0; c < MV_XOR_CHAN_MAX; c++)
2193 xor_chan_write(base, c, e, w, val);
2197 win_xor_can_remap(int i)
2200 /* XOR decode windows 0-3 have remap capability */
2214 case MV_DEV_88F6281:
2215 case MV_DEV_88F6282:
2216 case MV_DEV_MV78130:
2217 case MV_DEV_MV78160:
2218 case MV_DEV_MV78230:
2219 case MV_DEV_MV78260:
2220 case MV_DEV_MV78460:
2222 case MV_DEV_MV78100:
2223 case MV_DEV_MV78100_Z0:
2231 xor_active_dram(u_long base, int c, int e, int *window)
2237 * Set up access to all active DRAM banks
2240 for (i = 0; i < m; i++)
2241 if (ddr_is_active(i)) {
2242 br = ddr_base(i) | (ddr_attr(i) << 8) |
2244 sz = ((ddr_size(i) - 1) & 0xffff0000);
2246 /* Place DDR entries in non-remapped windows */
2247 for (w = 0; w < MV_WIN_XOR_MAX; w++)
2248 if (win_xor_can_remap(w) != 1 &&
2249 (xor_ctrl_read(base, w, c, e) == 0) &&
2251 /* Configure window */
2252 win_xor_br_write(base, w, e, br);
2253 win_xor_sz_write(base, w, e, sz);
2255 /* Set protection RW on all channels */
2256 xor_set_prot(base, w, e, 0x3);
2259 xor_ctrl_write(base, w, c, e, 1);
2267 decode_win_xor_setup(u_long base)
2270 int i, j, z, e = 1, m, window;
2272 if (pm_is_disabled(CPU_PM_CTRL_XOR))
2276 * Disable and clear all XOR windows, revoke protection for all
2280 for (j = 0; j < m; j++, e--) {
2282 /* Number of non-remaped windows */
2283 window = MV_XOR_NON_REMAP - 1;
2285 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
2286 win_xor_br_write(base, i, e, 0);
2287 win_xor_sz_write(base, i, e, 0);
2290 if (win_xor_can_remap(i) == 1)
2291 win_xor_har_write(base, i, e, 0);
2293 for (i = 0; i < MV_XOR_CHAN_MAX; i++) {
2294 win_xor_ctrl_write(base, i, e, 0);
2295 xor_active_dram(base, i, e, &window);
2299 * Remaining targets -- from a statically defined table
2301 for (i = 0; i < xor_wins_no; i++)
2302 if (xor_wins[i].target > 0) {
2303 br = (xor_wins[i].base & 0xffff0000) |
2304 (xor_wins[i].attr << 8) |
2306 sz = ((xor_wins[i].size - 1) & 0xffff0000);
2308 /* Set the first free XOR window */
2309 for (z = 0; z < MV_WIN_XOR_MAX; z++) {
2310 if (xor_ctrl_read(base, z, 0, e) &&
2311 xor_ctrl_read(base, z, 1, e))
2314 /* Configure window */
2315 win_xor_br_write(base, z, e, br);
2316 win_xor_sz_write(base, z, e, sz);
2317 if (win_xor_can_remap(z) &&
2318 xor_wins[z].remap >= 0)
2319 win_xor_har_write(base, z, e,
2322 /* Set protection RW on all channels */
2323 xor_set_prot(base, z, e, 0x3);
2326 xor_ctrl_write(base, z, 0, e, 1);
2327 xor_ctrl_write(base, z, 1, e, 1);
2335 decode_win_xor_valid(void)
2337 const struct decode_win *wintab;
2341 if (xor_wins_no > MV_WIN_XOR_MAX) {
2342 printf("XOR windows: too many entries: %d\n", xor_wins_no);
2345 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
2346 if (ddr_is_active(i))
2349 if (xor_wins_no > (MV_WIN_XOR_MAX - c)) {
2350 printf("XOR windows: too many entries: %d, available: %d\n",
2351 xor_wins_no, MV_WIN_IDMA_MAX - c);
2357 for (i = 0; i < xor_wins_no; i++, wintab++) {
2359 if (wintab->target == 0) {
2360 printf("XOR window#%d: DDR target window is not "
2361 "supposed to be reprogrammed!\n", i);
2365 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
2366 printf("XOR window#%d: not capable of remapping, but "
2367 "val 0x%08x defined\n", i, wintab->remap);
2374 if (s > (0xFFFFFFFF - b + 1)) {
2376 * XXX this boundary check should account for 64bit
2379 printf("XOR window#%d: no space for size 0x%08x at "
2380 "0x%08x\n", i, s, b);
2385 j = decode_win_overlap(i, xor_wins_no, &xor_wins[0]);
2387 printf("XOR window#%d: (0x%08x - 0x%08x) overlaps "
2388 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
2390 xor_wins[j].base + xor_wins[j].size - 1);
2399 decode_win_xor_dump(u_long base)
2404 if (pm_is_disabled(CPU_PM_CTRL_XOR))
2407 for (j = 0; j < xor_max_eng(); j++, e--) {
2408 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
2409 printf("XOR window#%d: b 0x%08x, s 0x%08x", i,
2410 win_xor_br_read(base, i, e), win_xor_sz_read(base, i, e));
2412 if (win_xor_can_remap(i))
2413 printf(", ha 0x%08x", win_xor_har_read(base, i, e));
2417 for (i = 0; i < MV_XOR_CHAN_MAX; i++)
2418 printf("XOR control#%d: 0x%08x\n", i,
2419 win_xor_ctrl_read(base, i, e));
2424 /* Provide dummy functions to satisfy the build for SoCs not equipped with XOR */
2426 decode_win_xor_valid(void)
2433 decode_win_xor_setup(u_long base)
2438 decode_win_xor_dump(u_long base)
2443 /**************************************************************************
2444 * SATA windows routines
2445 **************************************************************************/
2447 decode_win_sata_setup(u_long base)
2452 if (pm_is_disabled(CPU_PM_CTRL_SATA))
2455 for (i = 0; i < MV_WIN_SATA_MAX; i++) {
2456 win_sata_cr_write(base, i, 0);
2457 win_sata_br_write(base, i, 0);
2460 for (i = 0; i < MV_WIN_DDR_MAX; i++)
2461 if (ddr_is_active(i)) {
2462 cr = ((ddr_size(i) - 1) & 0xffff0000) |
2463 (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
2466 /* Use the first available SATA window */
2467 for (j = 0; j < MV_WIN_SATA_MAX; j++) {
2468 if ((win_sata_cr_read(base, j) & 1) != 0)
2471 win_sata_br_write(base, j, br);
2472 win_sata_cr_write(base, j, cr);
2479 * Configure AHCI decoding windows
2482 decode_win_ahci_setup(u_long base)
2484 uint32_t br, cr, sz;
2487 for (i = 0; i < MV_WIN_SATA_MAX_ARMADA38X; i++) {
2488 win_sata_armada38x_cr_write(base, i, 0);
2489 win_sata_armada38x_br_write(base, i, 0);
2490 win_sata_armada38x_sz_write(base, i, 0);
2493 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
2494 if (ddr_is_active(i)) {
2495 cr = (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
2496 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
2499 sz = (ddr_size(i) - 1) &
2500 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT);
2502 /* Use first available SATA window */
2503 for (j = 0; j < MV_WIN_SATA_MAX_ARMADA38X; j++) {
2504 if (win_sata_armada38x_cr_read(base, j) & IO_WIN_ENA_MASK)
2507 /* BASE is set to DRAM base (0x00000000) */
2508 win_sata_armada38x_br_write(base, j, br);
2509 /* CTRL targets DRAM ctrl with 0x0E or 0x0D */
2510 win_sata_armada38x_cr_write(base, j, cr);
2511 /* SIZE is set to 16MB - max value */
2512 win_sata_armada38x_sz_write(base, j, sz);
2520 decode_win_ahci_dump(u_long base)
2524 for (i = 0; i < MV_WIN_SATA_MAX_ARMADA38X; i++)
2525 printf("SATA window#%d: cr 0x%08x, br 0x%08x, sz 0x%08x\n", i,
2526 win_sata_armada38x_cr_read(base, i), win_sata_br_read(base, i),
2527 win_sata_armada38x_sz_read(base,i));
2531 decode_win_sata_valid(void)
2536 if (dev == MV_DEV_88F5281)
2539 return (decode_win_can_cover_ddr(MV_WIN_SATA_MAX));
2543 decode_win_sdhci_setup(u_long base)
2548 for (i = 0; i < MV_WIN_SDHCI_MAX; i++) {
2549 win_sdhci_cr_write(base, i, 0);
2550 win_sdhci_br_write(base, i, 0);
2553 for (i = 0; i < MV_WIN_DDR_MAX; i++)
2554 if (ddr_is_active(i)) {
2556 cr = (((ddr_size(i) - 1) &
2557 (IO_WIN_SIZE_MASK << IO_WIN_SIZE_SHIFT)) |
2558 (ddr_attr(i) << IO_WIN_ATTR_SHIFT) |
2559 (ddr_target(i) << IO_WIN_TGT_SHIFT) |
2562 /* Use the first available SDHCI window */
2563 for (j = 0; j < MV_WIN_SDHCI_MAX; j++) {
2564 if (win_sdhci_cr_read(base, j) & IO_WIN_ENA_MASK)
2567 win_sdhci_cr_write(base, j, cr);
2568 win_sdhci_br_write(base, j, br);
2575 decode_win_sdhci_dump(u_long base)
2579 for (i = 0; i < MV_WIN_SDHCI_MAX; i++)
2580 printf("SDHCI window#%d: c 0x%08x, b 0x%08x\n", i,
2581 win_sdhci_cr_read(base, i), win_sdhci_br_read(base, i));
2585 decode_win_sdhci_valid(void)
2588 return (decode_win_can_cover_ddr(MV_WIN_SDHCI_MAX));
2591 /**************************************************************************
2592 * FDT parsing routines.
2593 **************************************************************************/
2596 fdt_get_ranges(const char *nodename, void *buf, int size, int *tuples,
2600 pcell_t addr_cells, par_addr_cells, size_cells;
2601 int len, tuple_size, tuples_count;
2603 node = OF_finddevice(nodename);
2607 if ((fdt_addrsize_cells(node, &addr_cells, &size_cells)) != 0)
2610 par_addr_cells = fdt_parent_addr_cells(node);
2611 if (par_addr_cells > 2)
2614 tuple_size = sizeof(pcell_t) * (addr_cells + par_addr_cells +
2617 /* Note the OF_getprop_alloc() cannot be used at this early stage. */
2618 len = OF_getprop(node, "ranges", buf, size);
2621 * XXX this does not handle the empty 'ranges;' case, which is
2622 * legitimate and should be allowed.
2624 tuples_count = len / tuple_size;
2625 if (tuples_count <= 0)
2628 if (par_addr_cells > 2 || addr_cells > 2 || size_cells > 2)
2631 *tuples = tuples_count;
2632 *tuplesize = tuple_size;
2637 win_cpu_from_dt(void)
2641 int i, entry_size, err, t, tuple_size, tuples;
2642 u_long sram_base, sram_size;
2645 /* Retrieve 'ranges' property of '/localbus' node. */
2646 if ((err = fdt_get_ranges("/localbus", ranges, sizeof(ranges),
2647 &tuples, &tuple_size)) == 0) {
2649 * Fill CPU decode windows table.
2651 bzero((void *)&cpu_win_tbl, sizeof(cpu_win_tbl));
2653 entry_size = tuple_size / sizeof(pcell_t);
2654 cpu_wins_no = tuples;
2657 if (tuples > nitems(cpu_win_tbl)) {
2658 debugf("too many tuples to fit into cpu_win_tbl\n");
2662 for (i = 0, t = 0; t < tuples; i += entry_size, t++) {
2663 cpu_win_tbl[t].target = 1;
2664 cpu_win_tbl[t].attr = fdt32_to_cpu(ranges[i + 1]);
2665 cpu_win_tbl[t].base = fdt32_to_cpu(ranges[i + 2]);
2666 cpu_win_tbl[t].size = fdt32_to_cpu(ranges[i + 3]);
2667 cpu_win_tbl[t].remap = ~0;
2668 debugf("target = 0x%0x attr = 0x%0x base = 0x%0x "
2669 "size = 0x%0x remap = 0x%0x\n",
2670 cpu_win_tbl[t].target,
2671 cpu_win_tbl[t].attr, cpu_win_tbl[t].base,
2672 cpu_win_tbl[t].size, cpu_win_tbl[t].remap);
2677 * Retrieve CESA SRAM data.
2679 if ((node = OF_finddevice("sram")) != -1)
2680 if (ofw_bus_node_is_compatible(node, "mrvl,cesa-sram"))
2683 if ((node = OF_finddevice("/")) == -1)
2686 if ((node = fdt_find_compatible(node, "mrvl,cesa-sram", 0)) == 0)
2687 /* SRAM block is not always present. */
2690 sram_base = sram_size = 0;
2691 if (fdt_regsize(node, &sram_base, &sram_size) != 0)
2695 if (t >= nitems(cpu_win_tbl)) {
2696 debugf("cannot fit CESA tuple into cpu_win_tbl\n");
2700 cpu_win_tbl[t].target = soc_decode_win_spec->win_cesa_target;
2701 if (soc_family == MV_SOC_ARMADA_38X)
2702 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(0);
2704 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(1);
2705 cpu_win_tbl[t].base = sram_base;
2706 cpu_win_tbl[t].size = sram_size;
2707 cpu_win_tbl[t].remap = ~0;
2709 debugf("sram: base = 0x%0lx size = 0x%0lx\n", sram_base, sram_size);
2711 /* Check if there is a second CESA node */
2712 while ((node = OF_peer(node)) != 0) {
2713 if (ofw_bus_node_is_compatible(node, "mrvl,cesa-sram")) {
2714 if (fdt_regsize(node, &sram_base, &sram_size) != 0)
2724 if (t >= nitems(cpu_win_tbl)) {
2725 debugf("cannot fit CESA tuple into cpu_win_tbl\n");
2729 /* Configure window for CESA1 */
2730 cpu_win_tbl[t].target = soc_decode_win_spec->win_cesa_target;
2731 cpu_win_tbl[t].attr = soc_decode_win_spec->win_cesa_attr(1);
2732 cpu_win_tbl[t].base = sram_base;
2733 cpu_win_tbl[t].size = sram_size;
2734 cpu_win_tbl[t].remap = ~0;
2736 debugf("sram: base = 0x%0lx size = 0x%0lx\n", sram_base, sram_size);
2742 fdt_win_process(phandle_t child)
2745 struct soc_node_spec *soc_node;
2746 int addr_cells, size_cells;
2750 for (i = 0; soc_nodes[i].compat != NULL; i++) {
2752 soc_node = &soc_nodes[i];
2754 /* Setup only for enabled devices */
2755 if (ofw_bus_node_status_okay(child) == 0)
2758 if (!ofw_bus_node_is_compatible(child, soc_node->compat))
2761 if (fdt_addrsize_cells(OF_parent(child), &addr_cells,
2765 if ((sizeof(pcell_t) * (addr_cells + size_cells)) > sizeof(reg))
2768 if (OF_getprop(child, "reg", ®, sizeof(reg)) <= 0)
2771 if (addr_cells <= 2)
2772 base = fdt_data_get(®[0], addr_cells);
2774 base = fdt_data_get(®[addr_cells - 2], 2);
2775 size = fdt_data_get(®[addr_cells], size_cells);
2777 if (soc_node->valid_handler != NULL)
2778 if (!soc_node->valid_handler())
2781 base = (base & 0x000fffff) | fdt_immr_va;
2782 if (soc_node->decode_handler != NULL)
2783 soc_node->decode_handler(base);
2787 if (MV_DUMP_WIN && (soc_node->dump_handler != NULL))
2788 soc_node->dump_handler(base);
2796 phandle_t node, child, sb;
2797 phandle_t child_pci;
2801 node = OF_finddevice("/");
2803 panic("fdt_win_setup: no root node");
2805 /* Allow for coherent transactions on the A38x MBUS */
2806 if (ofw_bus_node_is_compatible(node, "marvell,armada380"))
2807 platform_io_coherent = true;
2810 * Traverse through all children of root and simple-bus nodes.
2811 * For each found device retrieve decode windows data (if applicable).
2813 child = OF_child(node);
2814 while (child != 0) {
2815 /* Lookup for callback and run */
2816 err = fdt_win_process(child);
2820 /* Process Marvell Armada-XP/38x PCIe controllers */
2821 if (ofw_bus_node_is_compatible(child, "marvell,armada-370-pcie")) {
2822 child_pci = OF_child(child);
2823 while (child_pci != 0) {
2824 err = fdt_win_process(child_pci);
2828 child_pci = OF_peer(child_pci);
2833 * Once done with root-level children let's move down to
2834 * simple-bus and its children.
2836 child = OF_peer(child);
2837 if ((child == 0) && (node == OF_finddevice("/"))) {
2838 sb = node = fdt_find_compatible(node, "simple-bus", 0);
2841 child = OF_child(node);
2844 * Next, move one more level down to internal-regs node (if
2845 * it is present) and its children. This node also have
2846 * "simple-bus" compatible.
2848 if ((child == 0) && (node == sb)) {
2849 node = fdt_find_compatible(node, "simple-bus", 0);
2852 child = OF_child(node);
2860 fdt_fixup_busfreq(phandle_t root)
2865 freq = cpu_to_fdt32(get_tclk());
2868 * Fix bus speed in cpu node
2870 if ((sb = OF_finddevice("cpu")) != -1)
2871 if (fdt_is_compatible_strict(sb, "ARM,88VS584"))
2872 OF_setprop(sb, "bus-frequency", (void *)&freq,
2876 * This fixup sets the simple-bus bus-frequency property.
2878 if ((sb = fdt_find_compatible(root, "simple-bus", 1)) != 0)
2879 OF_setprop(sb, "bus-frequency", (void *)&freq, sizeof(freq));
2883 fdt_fixup_ranges(phandle_t root)
2886 pcell_t par_addr_cells, addr_cells, size_cells;
2887 pcell_t ranges[3], reg[2], *rangesptr;
2888 int len, tuple_size, tuples_count;
2891 /* Fix-up SoC ranges according to real fdt_immr_pa */
2892 if ((node = fdt_find_compatible(root, "simple-bus", 1)) != 0) {
2893 if (fdt_addrsize_cells(node, &addr_cells, &size_cells) == 0 &&
2894 (par_addr_cells = fdt_parent_addr_cells(node) <= 2)) {
2895 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2896 addr_cells + size_cells);
2897 len = OF_getprop(node, "ranges", ranges,
2899 tuples_count = len / tuple_size;
2900 /* Unexpected settings are not supported */
2901 if (tuples_count != 1)
2904 rangesptr = &ranges[0];
2905 rangesptr += par_addr_cells;
2906 base = fdt_data_get((void *)rangesptr, addr_cells);
2907 *rangesptr = cpu_to_fdt32(fdt_immr_pa);
2908 if (OF_setprop(node, "ranges", (void *)&ranges[0],
2909 sizeof(ranges)) < 0)
2914 /* Fix-up PCIe reg according to real PCIe registers' PA */
2915 if ((node = fdt_find_compatible(root, "mrvl,pcie", 1)) != 0) {
2916 if (fdt_addrsize_cells(OF_parent(node), &par_addr_cells,
2917 &size_cells) == 0) {
2918 tuple_size = sizeof(pcell_t) * (par_addr_cells +
2920 len = OF_getprop(node, "reg", reg, sizeof(reg));
2921 tuples_count = len / tuple_size;
2922 /* Unexpected settings are not supported */
2923 if (tuples_count != 1)
2926 base = fdt_data_get((void *)®[0], par_addr_cells);
2927 base &= ~0xFF000000;
2928 base |= fdt_immr_pa;
2929 reg[0] = cpu_to_fdt32(base);
2930 if (OF_setprop(node, "reg", (void *)®[0],
2935 /* Fix-up succeeded. May return and continue */
2941 * In case of any error while fixing ranges just hang.
2942 * 1. No message can be displayed yet since console
2943 * is not initialized.
2944 * 2. Going further will cause failure on bus_space_map()
2945 * relying on the wrong ranges or data abort when
2946 * accessing PCIe registers.
2951 struct fdt_fixup_entry fdt_fixup_table[] = {
2952 { "mrvl,DB-88F6281", &fdt_fixup_busfreq },
2953 { "mrvl,DB-78460", &fdt_fixup_busfreq },
2954 { "mrvl,DB-78460", &fdt_fixup_ranges },
2963 if (soc_decode_win_spec->get_tclk != NULL)
2964 return soc_decode_win_spec->get_tclk();
2973 if (soc_decode_win_spec->get_cpu_freq != NULL)
2974 return soc_decode_win_spec->get_cpu_freq();
2982 fdt_pic_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
2986 if (!ofw_bus_node_is_compatible(node, "mrvl,pic") &&
2987 !ofw_bus_node_is_compatible(node, "mrvl,mpic"))
2990 *interrupt = fdt32_to_cpu(intr[0]);
2991 *trig = INTR_TRIGGER_CONFORM;
2992 *pol = INTR_POLARITY_CONFORM;
2997 fdt_pic_decode_t fdt_pic_table[] = {