2 * Copyright (C) 2008 MARVELL INTERNATIONAL LTD.
5 * Developed by Semihalf.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of MARVELL nor the names of contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/systm.h>
38 #include <machine/bus.h>
40 #include <arm/mv/mvreg.h>
41 #include <arm/mv/mvvar.h>
42 #include <arm/mv/mvwin.h>
44 static int win_eth_can_remap(int i);
46 static int decode_win_cpu_valid(void);
47 static int decode_win_usb_valid(void);
48 static int decode_win_eth_valid(void);
49 static int decode_win_pcie_valid(void);
50 static int decode_win_sata_valid(void);
51 static int decode_win_cesa_valid(void);
53 static void decode_win_cpu_setup(void);
54 static void decode_win_usb_setup(void);
55 static void decode_win_eth_setup(uint32_t base);
56 static void decode_win_pcie_setup(uint32_t base);
57 static void decode_win_sata_setup(void);
58 static void decode_win_cesa_setup(void);
60 static void decode_win_cesa_dump(void);
61 static void decode_win_usb_dump(void);
63 static uint32_t used_cpu_wins;
66 read_cpu_ctrl(uint32_t reg)
69 return (bus_space_read_4(obio_tag, MV_CPU_CONTROL_BASE, reg));
73 write_cpu_ctrl(uint32_t reg, uint32_t val)
76 bus_space_write_4(obio_tag, MV_CPU_CONTROL_BASE, reg, val);
83 write_cpu_ctrl(RSTOUTn_MASK, SOFT_RST_OUT_EN);
84 write_cpu_ctrl(SYSTEM_SOFT_RESET, SYS_SOFT_RST);
95 if (dev == MV_DEV_88F6281 || dev == MV_DEV_MV78100_Z0 ||
96 dev == MV_DEV_MV78100)
97 __asm __volatile("mrc p15, 1, %0, c15, c1, 0" : "=r" (ef));
98 else if (dev == MV_DEV_88F5182 || dev == MV_DEV_88F5281)
99 __asm __volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (ef));
100 else if (bootverbose)
101 printf("This ARM Core does not support any extra features\n");
107 soc_power_ctrl_get(uint32_t mask)
110 if (mask != CPU_PM_CTRL_NONE)
111 mask &= read_cpu_ctrl(CPU_PM_CTRL);
117 soc_id(uint32_t *dev, uint32_t *rev)
121 * Notice: system identifiers are available in the registers range of
122 * PCIE controller, so using this function is only allowed (and
123 * possible) after the internal registers range has been mapped in via
124 * pmap_devmap_bootstrap().
126 *dev = bus_space_read_4(obio_tag, MV_PCIE_BASE, 0) >> 16;
127 *rev = bus_space_read_4(obio_tag, MV_PCIE_BASE, 8) & 0xff;
141 printf("(0x%4x:0x%02x) ", d, r);
146 dev = "Marvell 88F5181";
151 dev = "Marvell 88F5182";
156 dev = "Marvell 88F5281";
165 dev = "Marvell 88F6281";
171 case MV_DEV_MV78100_Z0:
172 dev = "Marvell MV78100 Z0";
175 dev = "Marvell MV78100";
184 printf(" rev %s", rev);
185 printf(", TClock %dMHz\n", get_tclk() / 1000 / 1000);
187 /* TODO add info on currently set endianess */
195 /* Retrieve our ID: some windows facilities vary between SoC models */
198 if (decode_win_cpu_valid() != 1 || decode_win_usb_valid() != 1 ||
199 decode_win_eth_valid() != 1 || decode_win_idma_valid() != 1 ||
200 decode_win_pcie_valid() != 1 || decode_win_sata_valid() != 1 ||
201 decode_win_cesa_valid() != 1)
204 decode_win_cpu_setup();
205 decode_win_usb_setup();
206 decode_win_eth_setup(MV_ETH0_BASE);
207 if (dev == MV_DEV_MV78100 || dev == MV_DEV_MV78100_Z0)
208 decode_win_eth_setup(MV_ETH1_BASE);
209 if (dev == MV_DEV_88F6281 || dev == MV_DEV_MV78100 ||
210 dev == MV_DEV_MV78100_Z0)
211 decode_win_cesa_setup();
213 decode_win_idma_setup();
214 decode_win_xor_setup();
216 if (dev == MV_DEV_MV78100 || dev == MV_DEV_MV78100_Z0) {
217 decode_win_pcie_setup(MV_PCIE00_BASE);
218 decode_win_pcie_setup(MV_PCIE01_BASE);
219 decode_win_pcie_setup(MV_PCIE02_BASE);
220 decode_win_pcie_setup(MV_PCIE03_BASE);
221 decode_win_pcie_setup(MV_PCIE10_BASE);
222 decode_win_pcie_setup(MV_PCIE11_BASE);
223 decode_win_pcie_setup(MV_PCIE12_BASE);
224 decode_win_pcie_setup(MV_PCIE13_BASE);
226 decode_win_pcie_setup(MV_PCIE_BASE);
228 if (dev != MV_DEV_88F5281)
229 decode_win_sata_setup();
234 /**************************************************************************
235 * Decode windows registers accessors
236 **************************************************************************/
237 WIN_REG_IDX_RD(win_cpu, cr, MV_WIN_CPU_CTRL, MV_MBUS_BRIDGE_BASE)
238 WIN_REG_IDX_RD(win_cpu, br, MV_WIN_CPU_BASE, MV_MBUS_BRIDGE_BASE)
239 WIN_REG_IDX_RD(win_cpu, remap_l, MV_WIN_CPU_REMAP_LO, MV_MBUS_BRIDGE_BASE)
240 WIN_REG_IDX_RD(win_cpu, remap_h, MV_WIN_CPU_REMAP_HI, MV_MBUS_BRIDGE_BASE)
241 WIN_REG_IDX_WR(win_cpu, cr, MV_WIN_CPU_CTRL, MV_MBUS_BRIDGE_BASE)
242 WIN_REG_IDX_WR(win_cpu, br, MV_WIN_CPU_BASE, MV_MBUS_BRIDGE_BASE)
243 WIN_REG_IDX_WR(win_cpu, remap_l, MV_WIN_CPU_REMAP_LO, MV_MBUS_BRIDGE_BASE)
244 WIN_REG_IDX_WR(win_cpu, remap_h, MV_WIN_CPU_REMAP_HI, MV_MBUS_BRIDGE_BASE)
246 WIN_REG_IDX_RD(ddr, br, MV_WIN_DDR_BASE, MV_DDR_CADR_BASE)
247 WIN_REG_IDX_RD(ddr, sz, MV_WIN_DDR_SIZE, MV_DDR_CADR_BASE)
249 WIN_REG_IDX_RD2(win_usb, cr, MV_WIN_USB_CTRL, MV_USB_AWR_BASE)
250 WIN_REG_IDX_RD2(win_usb, br, MV_WIN_USB_BASE, MV_USB_AWR_BASE)
251 WIN_REG_IDX_WR2(win_usb, cr, MV_WIN_USB_CTRL, MV_USB_AWR_BASE)
252 WIN_REG_IDX_WR2(win_usb, br, MV_WIN_USB_BASE, MV_USB_AWR_BASE)
254 WIN_REG_IDX_RD(win_cesa, cr, MV_WIN_CESA_CTRL, MV_CESA_BASE)
255 WIN_REG_IDX_RD(win_cesa, br, MV_WIN_CESA_BASE, MV_CESA_BASE)
256 WIN_REG_IDX_WR(win_cesa, cr, MV_WIN_CESA_CTRL, MV_CESA_BASE)
257 WIN_REG_IDX_WR(win_cesa, br, MV_WIN_CESA_BASE, MV_CESA_BASE)
259 WIN_REG_BASE_IDX_RD(win_eth, br, MV_WIN_ETH_BASE)
260 WIN_REG_BASE_IDX_RD(win_eth, sz, MV_WIN_ETH_SIZE)
261 WIN_REG_BASE_IDX_RD(win_eth, har, MV_WIN_ETH_REMAP)
262 WIN_REG_BASE_IDX_WR(win_eth, br, MV_WIN_ETH_BASE)
263 WIN_REG_BASE_IDX_WR(win_eth, sz, MV_WIN_ETH_SIZE)
264 WIN_REG_BASE_IDX_WR(win_eth, har, MV_WIN_ETH_REMAP)
266 WIN_REG_IDX_RD2(win_xor, br, MV_WIN_XOR_BASE, MV_XOR_BASE)
267 WIN_REG_IDX_RD2(win_xor, sz, MV_WIN_XOR_SIZE, MV_XOR_BASE)
268 WIN_REG_IDX_RD2(win_xor, har, MV_WIN_XOR_REMAP, MV_XOR_BASE)
269 WIN_REG_IDX_RD2(win_xor, ctrl, MV_WIN_XOR_CTRL, MV_XOR_BASE)
270 WIN_REG_IDX_WR2(win_xor, br, MV_WIN_XOR_BASE, MV_XOR_BASE)
271 WIN_REG_IDX_WR2(win_xor, sz, MV_WIN_XOR_SIZE, MV_XOR_BASE)
272 WIN_REG_IDX_WR2(win_xor, har, MV_WIN_XOR_REMAP, MV_XOR_BASE)
273 WIN_REG_IDX_WR2(win_xor, ctrl, MV_WIN_XOR_CTRL, MV_XOR_BASE)
275 WIN_REG_BASE_RD(win_eth, bare, 0x290)
276 WIN_REG_BASE_RD(win_eth, epap, 0x294)
277 WIN_REG_BASE_WR(win_eth, bare, 0x290)
278 WIN_REG_BASE_WR(win_eth, epap, 0x294)
280 WIN_REG_BASE_IDX_RD(win_pcie, cr, MV_WIN_PCIE_CTRL);
281 WIN_REG_BASE_IDX_RD(win_pcie, br, MV_WIN_PCIE_BASE);
282 WIN_REG_BASE_IDX_RD(win_pcie, remap, MV_WIN_PCIE_REMAP);
283 WIN_REG_BASE_IDX_WR(win_pcie, cr, MV_WIN_PCIE_CTRL);
284 WIN_REG_BASE_IDX_WR(win_pcie, br, MV_WIN_PCIE_BASE);
285 WIN_REG_BASE_IDX_WR(win_pcie, remap, MV_WIN_PCIE_REMAP);
286 WIN_REG_BASE_IDX_WR(pcie, bar, MV_PCIE_BAR);
288 WIN_REG_IDX_RD(win_idma, br, MV_WIN_IDMA_BASE, MV_IDMA_BASE)
289 WIN_REG_IDX_RD(win_idma, sz, MV_WIN_IDMA_SIZE, MV_IDMA_BASE)
290 WIN_REG_IDX_RD(win_idma, har, MV_WIN_IDMA_REMAP, MV_IDMA_BASE)
291 WIN_REG_IDX_RD(win_idma, cap, MV_WIN_IDMA_CAP, MV_IDMA_BASE)
292 WIN_REG_IDX_WR(win_idma, br, MV_WIN_IDMA_BASE, MV_IDMA_BASE)
293 WIN_REG_IDX_WR(win_idma, sz, MV_WIN_IDMA_SIZE, MV_IDMA_BASE)
294 WIN_REG_IDX_WR(win_idma, har, MV_WIN_IDMA_REMAP, MV_IDMA_BASE)
295 WIN_REG_IDX_WR(win_idma, cap, MV_WIN_IDMA_CAP, MV_IDMA_BASE)
296 WIN_REG_RD(win_idma, bare, 0xa80, MV_IDMA_BASE)
297 WIN_REG_WR(win_idma, bare, 0xa80, MV_IDMA_BASE)
299 WIN_REG_IDX_RD(win_sata, cr, MV_WIN_SATA_CTRL, MV_SATAHC_BASE);
300 WIN_REG_IDX_RD(win_sata, br, MV_WIN_SATA_BASE, MV_SATAHC_BASE);
301 WIN_REG_IDX_WR(win_sata, cr, MV_WIN_SATA_CTRL, MV_SATAHC_BASE);
302 WIN_REG_IDX_WR(win_sata, br, MV_WIN_SATA_BASE, MV_SATAHC_BASE);
304 /**************************************************************************
305 * Decode windows helper routines
306 **************************************************************************/
308 soc_dump_decode_win(void)
315 for (i = 0; i < MV_WIN_CPU_MAX; i++) {
316 printf("CPU window#%d: c 0x%08x, b 0x%08x", i,
320 if (win_cpu_can_remap(i))
321 printf(", rl 0x%08x, rh 0x%08x",
322 win_cpu_remap_l_read(i),
323 win_cpu_remap_h_read(i));
327 printf("Internal regs base: 0x%08x\n",
328 bus_space_read_4(obio_tag, MV_INTREGS_BASE, 0));
330 for (i = 0; i < MV_WIN_DDR_MAX; i++)
331 printf("DDR CS#%d: b 0x%08x, s 0x%08x\n", i,
332 ddr_br_read(i), ddr_sz_read(i));
334 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
335 printf("ETH window#%d: b 0x%08x, s 0x%08x", i,
336 win_eth_br_read(MV_ETH0_BASE, i),
337 win_eth_sz_read(MV_ETH0_BASE, i));
339 if (win_eth_can_remap(i))
340 printf(", ha 0x%08x",
341 win_eth_har_read(MV_ETH0_BASE, i));
345 printf("ETH windows: bare 0x%08x, epap 0x%08x\n",
346 win_eth_bare_read(MV_ETH0_BASE),
347 win_eth_epap_read(MV_ETH0_BASE));
349 decode_win_idma_dump();
350 decode_win_cesa_dump();
351 decode_win_usb_dump();
355 /**************************************************************************
356 * CPU windows routines
357 **************************************************************************/
359 win_cpu_can_remap(int i)
365 /* Depending on the SoC certain windows have remap capability */
366 if ((dev == MV_DEV_88F5182 && i < 2) ||
367 (dev == MV_DEV_88F5281 && i < 4) ||
368 (dev == MV_DEV_88F6281 && i < 4) ||
369 (dev == MV_DEV_MV78100 && i < 8) ||
370 (dev == MV_DEV_MV78100_Z0 && i < 8))
376 /* XXX This should check for overlapping remap fields too.. */
378 decode_win_overlap(int win, int win_no, const struct decode_win *wintab)
380 const struct decode_win *tab;
385 for (i = 0; i < win_no; i++, tab++) {
390 if ((tab->base + tab->size - 1) < (wintab + win)->base)
393 else if (((wintab + win)->base + (wintab + win)->size - 1) <
404 decode_win_cpu_valid(void)
409 if (cpu_wins_no > MV_WIN_CPU_MAX) {
410 printf("CPU windows: too many entries: %d\n", cpu_wins_no);
415 for (i = 0; i < cpu_wins_no; i++) {
417 if (cpu_wins[i].target == 0) {
418 printf("CPU window#%d: DDR target window is not "
419 "supposed to be reprogrammed!\n", i);
423 if (cpu_wins[i].remap >= 0 && win_cpu_can_remap(i) != 1) {
424 printf("CPU window#%d: not capable of remapping, but "
425 "val 0x%08x defined\n", i, cpu_wins[i].remap);
429 s = cpu_wins[i].size;
430 b = cpu_wins[i].base;
432 if (s > (0xFFFFFFFF - b + 1)) {
434 * XXX this boundary check should account for 64bit
437 printf("CPU window#%d: no space for size 0x%08x at "
438 "0x%08x\n", i, s, b);
443 j = decode_win_overlap(i, cpu_wins_no, &cpu_wins[0]);
445 printf("CPU window#%d: (0x%08x - 0x%08x) overlaps "
446 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
448 cpu_wins[j].base + cpu_wins[j].size - 1);
457 decode_win_cpu_set(int target, int attr, vm_paddr_t base, uint32_t size,
463 if (used_cpu_wins >= MV_WIN_CPU_MAX)
466 win = used_cpu_wins++;
468 br = base & 0xffff0000;
469 win_cpu_br_write(win, br);
471 if (win_cpu_can_remap(win)) {
473 win_cpu_remap_l_write(win, remap & 0xffff0000);
474 win_cpu_remap_h_write(win, 0);
477 * Remap function is not used for a given window
478 * (capable of remapping) - set remap field with the
479 * same value as base.
481 win_cpu_remap_l_write(win, base & 0xffff0000);
482 win_cpu_remap_h_write(win, 0);
486 cr = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
487 win_cpu_cr_write(win, cr);
493 decode_win_cpu_setup(void)
499 /* Disable all CPU windows */
500 for (i = 0; i < MV_WIN_CPU_MAX; i++) {
501 win_cpu_cr_write(i, 0);
502 win_cpu_br_write(i, 0);
503 if (win_cpu_can_remap(i)) {
504 win_cpu_remap_l_write(i, 0);
505 win_cpu_remap_h_write(i, 0);
509 for (i = 0; i < cpu_wins_no; i++)
510 if (cpu_wins[i].target > 0)
511 decode_win_cpu_set(cpu_wins[i].target,
512 cpu_wins[i].attr, cpu_wins[i].base,
513 cpu_wins[i].size, cpu_wins[i].remap);
518 * Check if we're able to cover all active DDR banks.
521 decode_win_can_cover_ddr(int max)
526 for (i = 0; i < MV_WIN_DDR_MAX; i++)
527 if (ddr_is_active(i))
531 printf("Unable to cover all active DDR banks: "
532 "%d, available windows: %d\n", c, max);
539 /**************************************************************************
540 * DDR windows routines
541 **************************************************************************/
546 if (ddr_sz_read(i) & 0x1)
556 return (ddr_br_read(i) & 0xff000000);
563 return ((ddr_sz_read(i) | 0x00ffffff) + 1);
570 return (i == 0 ? 0xe :
573 (i == 3 ? 0x7 : 0xff))));
580 /* Mbus unit ID is 0x0 for DDR SDRAM controller */
584 /**************************************************************************
585 * USB windows routines
586 **************************************************************************/
588 decode_win_usb_valid(void)
591 return (decode_win_can_cover_ddr(MV_WIN_USB_MAX));
600 return ((dev == MV_DEV_MV78100 || dev == MV_DEV_MV78100_Z0) ? 3 : 1);
604 decode_win_usb_dump(void)
609 for (p = 0; p < m; p++)
610 for (i = 0; i < MV_WIN_USB_MAX; i++)
611 printf("USB window#%d: c 0x%08x, b 0x%08x\n", i,
612 win_usb_cr_read(i, p), win_usb_br_read(i, p));
616 * Set USB decode windows.
619 decode_win_usb_setup(void)
624 /* Disable and clear all USB windows for all ports */
626 for (p = 0; p < m; p++) {
628 for (i = 0; i < MV_WIN_USB_MAX; i++) {
629 win_usb_cr_write(i, p, 0);
630 win_usb_br_write(i, p, 0);
633 /* Only access to active DRAM banks is required */
634 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
635 if (ddr_is_active(i)) {
638 * XXX for 6281 we should handle Mbus write
639 * burst limit field in the ctrl reg
641 cr = (((ddr_size(i) - 1) & 0xffff0000) |
643 (ddr_target(i) << 4) | 1);
645 /* Set the first free USB window */
646 for (j = 0; j < MV_WIN_USB_MAX; j++) {
647 if (win_usb_cr_read(j, p) & 0x1)
650 win_usb_br_write(j, p, br);
651 win_usb_cr_write(j, p, cr);
659 /**************************************************************************
660 * ETH windows routines
661 **************************************************************************/
664 win_eth_can_remap(int i)
667 /* ETH encode windows 0-3 have remap capability */
675 eth_bare_read(uint32_t base, int i)
679 v = win_eth_bare_read(base);
686 eth_bare_write(uint32_t base, int i, int val)
690 v = win_eth_bare_read(base);
693 win_eth_bare_write(base, v);
697 eth_epap_write(uint32_t base, int i, int val)
701 v = win_eth_epap_read(base);
702 v &= ~(0x3 << (i * 2));
703 v |= (val << (i * 2));
704 win_eth_epap_write(base, v);
708 decode_win_eth_setup(uint32_t base)
713 /* Disable, clear and revoke protection for all ETH windows */
714 for (i = 0; i < MV_WIN_ETH_MAX; i++) {
716 eth_bare_write(base, i, 1);
717 eth_epap_write(base, i, 0);
718 win_eth_br_write(base, i, 0);
719 win_eth_sz_write(base, i, 0);
720 if (win_eth_can_remap(i))
721 win_eth_har_write(base, i, 0);
724 /* Only access to active DRAM banks is required */
725 for (i = 0; i < MV_WIN_DDR_MAX; i++)
726 if (ddr_is_active(i)) {
728 br = ddr_base(i) | (ddr_attr(i) << 8) | ddr_target(i);
729 sz = ((ddr_size(i) - 1) & 0xffff0000);
731 /* Set the first free ETH window */
732 for (j = 0; j < MV_WIN_ETH_MAX; j++) {
733 if (eth_bare_read(base, j) == 0)
736 win_eth_br_write(base, j, br);
737 win_eth_sz_write(base, j, sz);
739 /* XXX remapping ETH windows not supported */
741 /* Set protection RW */
742 eth_epap_write(base, j, 0x3);
745 eth_bare_write(base, j, 0);
752 decode_win_eth_valid(void)
755 return (decode_win_can_cover_ddr(MV_WIN_ETH_MAX));
758 /**************************************************************************
759 * PCIE windows routines
760 **************************************************************************/
763 decode_win_pcie_setup(uint32_t base)
769 for (i = 0; i < MV_PCIE_BAR_MAX; i++)
770 pcie_bar_write(base, i, 0);
772 for (i = 0; i < MV_WIN_PCIE_MAX; i++) {
773 win_pcie_cr_write(base, i, 0);
774 win_pcie_br_write(base, i, 0);
775 win_pcie_remap_write(base, i, 0);
778 for (i = 0; i < MV_WIN_DDR_MAX; i++) {
779 if (ddr_is_active(i)) {
780 /* Map DDR to BAR 1 */
781 cr = (ddr_size(i) - 1) & 0xffff0000;
782 size += ddr_size(i) & 0xffff0000;
783 cr |= (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
786 /* Use the first available PCIE window */
787 for (j = 0; j < MV_WIN_PCIE_MAX; j++) {
788 if (win_pcie_cr_read(base, j) != 0)
791 win_pcie_br_write(base, j, br);
792 win_pcie_cr_write(base, j, cr);
799 * Upper 16 bits in BAR register is interpreted as BAR size
800 * (in 64 kB units) plus 64kB, so substract 0x10000
801 * form value passed to register to get correct value.
804 pcie_bar_write(base, 0, size | 1);
808 decode_win_pcie_valid(void)
811 return (decode_win_can_cover_ddr(MV_WIN_PCIE_MAX));
814 /**************************************************************************
815 * IDMA windows routines
816 **************************************************************************/
817 #if defined(SOC_MV_ORION) || defined(SOC_MV_DISCOVERY)
819 idma_bare_read(int i)
823 v = win_idma_bare_read();
830 idma_bare_write(int i, int val)
834 v = win_idma_bare_read();
837 win_idma_bare_write(v);
841 * Sets channel protection 'val' for window 'w' on channel 'c'
844 idma_cap_write(int c, int w, int val)
848 v = win_idma_cap_read(c);
849 v &= ~(0x3 << (w * 2));
850 v |= (val << (w * 2));
851 win_idma_cap_write(c, v);
855 * Set protection 'val' on all channels for window 'w'
858 idma_set_prot(int w, int val)
862 for (c = 0; c < MV_IDMA_CHAN_MAX; c++)
863 idma_cap_write(c, w, val);
867 win_idma_can_remap(int i)
870 /* IDMA decode windows 0-3 have remap capability */
878 decode_win_idma_setup(void)
884 * Disable and clear all IDMA windows, revoke protection for all channels
886 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
888 idma_bare_write(i, 1);
889 win_idma_br_write(i, 0);
890 win_idma_sz_write(i, 0);
891 if (win_idma_can_remap(i) == 1)
892 win_idma_har_write(i, 0);
894 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
895 win_idma_cap_write(i, 0);
898 * Set up access to all active DRAM banks
900 for (i = 0; i < MV_WIN_DDR_MAX; i++)
901 if (ddr_is_active(i)) {
902 br = ddr_base(i) | (ddr_attr(i) << 8) | ddr_target(i);
903 sz = ((ddr_size(i) - 1) & 0xffff0000);
905 /* Place DDR entries in non-remapped windows */
906 for (j = 0; j < MV_WIN_IDMA_MAX; j++)
907 if (win_idma_can_remap(j) != 1 &&
908 idma_bare_read(j) == 1) {
910 /* Configure window */
911 win_idma_br_write(j, br);
912 win_idma_sz_write(j, sz);
914 /* Set protection RW on all channels */
915 idma_set_prot(j, 0x3);
918 idma_bare_write(j, 0);
924 * Remaining targets -- from statically defined table
926 for (i = 0; i < idma_wins_no; i++)
927 if (idma_wins[i].target > 0) {
928 br = (idma_wins[i].base & 0xffff0000) |
929 (idma_wins[i].attr << 8) | idma_wins[i].target;
930 sz = ((idma_wins[i].size - 1) & 0xffff0000);
932 /* Set the first free IDMA window */
933 for (j = 0; j < MV_WIN_IDMA_MAX; j++) {
934 if (idma_bare_read(j) == 0)
937 /* Configure window */
938 win_idma_br_write(j, br);
939 win_idma_sz_write(j, sz);
940 if (win_idma_can_remap(j) &&
941 idma_wins[j].remap >= 0)
942 win_idma_har_write(j, idma_wins[j].remap);
944 /* Set protection RW on all channels */
945 idma_set_prot(j, 0x3);
948 idma_bare_write(j, 0);
955 decode_win_idma_valid(void)
957 const struct decode_win *wintab;
961 if (idma_wins_no > MV_WIN_IDMA_MAX) {
962 printf("IDMA windows: too many entries: %d\n", idma_wins_no);
965 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
966 if (ddr_is_active(i))
969 if (idma_wins_no > (MV_WIN_IDMA_MAX - c)) {
970 printf("IDMA windows: too many entries: %d, available: %d\n",
971 idma_wins_no, MV_WIN_IDMA_MAX - c);
977 for (i = 0; i < idma_wins_no; i++, wintab++) {
979 if (wintab->target == 0) {
980 printf("IDMA window#%d: DDR target window is not "
981 "supposed to be reprogrammed!\n", i);
985 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
986 printf("IDMA window#%d: not capable of remapping, but "
987 "val 0x%08x defined\n", i, wintab->remap);
994 if (s > (0xFFFFFFFF - b + 1)) {
995 /* XXX this boundary check should account for 64bit and
997 printf("IDMA window#%d: no space for size 0x%08x at "
998 "0x%08x\n", i, s, b);
1003 j = decode_win_overlap(i, idma_wins_no, &idma_wins[0]);
1005 printf("IDMA window#%d: (0x%08x - 0x%08x) overlaps "
1006 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
1008 idma_wins[j].base + idma_wins[j].size - 1);
1017 decode_win_idma_dump(void)
1021 for (i = 0; i < MV_WIN_IDMA_MAX; i++) {
1022 printf("IDMA window#%d: b 0x%08x, s 0x%08x", i,
1023 win_idma_br_read(i), win_idma_sz_read(i));
1025 if (win_idma_can_remap(i))
1026 printf(", ha 0x%08x", win_idma_har_read(i));
1030 for (i = 0; i < MV_IDMA_CHAN_MAX; i++)
1031 printf("IDMA channel#%d: ap 0x%08x\n", i,
1032 win_idma_cap_read(i));
1033 printf("IDMA windows: bare 0x%08x\n", win_idma_bare_read());
1037 /* Provide dummy functions to satisfy the build for SoCs not equipped with IDMA */
1039 decode_win_idma_valid(void)
1046 decode_win_idma_setup(void)
1051 decode_win_idma_dump(void)
1056 /**************************************************************************
1057 * XOR windows routines
1058 **************************************************************************/
1059 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
1061 xor_ctrl_read(int i, int c, int e)
1064 v = win_xor_ctrl_read(c, e);
1071 xor_ctrl_write(int i, int c, int e, int val)
1075 v = win_xor_ctrl_read(c, e);
1078 win_xor_ctrl_write(c, e, v);
1082 * Set channel protection 'val' for window 'w' on channel 'c'
1086 xor_chan_write(int c, int e, int w, int val)
1090 v = win_xor_ctrl_read(c, e);
1091 v &= ~(0x3 << (w * 2 + 16));
1092 v |= (val << (w * 2 + 16));
1093 win_xor_ctrl_write(c, e, v);
1097 * Set protection 'val' on all channels for window 'w' on engine 'e'
1100 xor_set_prot(int w, int e, int val)
1104 for (c = 0; c < MV_XOR_CHAN_MAX; c++)
1105 xor_chan_write(c, e, w, val);
1109 win_xor_can_remap(int i)
1112 /* XOR decode windows 0-3 have remap capability */
1125 if (dev == MV_DEV_88F6281)
1127 else if ((dev == MV_DEV_MV78100) || (dev == MV_DEV_MV78100_Z0))
1134 xor_active_dram(int c, int e, int *window)
1140 * Set up access to all active DRAM banks
1143 for (i = 0; i < m; i++)
1144 if (ddr_is_active(i)) {
1145 br = ddr_base(i) | (ddr_attr(i) << 8) |
1147 sz = ((ddr_size(i) - 1) & 0xffff0000);
1149 /* Place DDR entries in non-remapped windows */
1150 for (w = 0; w < MV_WIN_XOR_MAX; w++)
1151 if (win_xor_can_remap(w) != 1 &&
1152 (xor_ctrl_read(w, c, e) == 0) &&
1154 /* Configure window */
1155 win_xor_br_write(w, e, br);
1156 win_xor_sz_write(w, e, sz);
1158 /* Set protection RW on all channels */
1159 xor_set_prot(w, e, 0x3);
1162 xor_ctrl_write(w, c, e, 1);
1170 decode_win_xor_setup(void)
1173 int i, j, z, e = 1, m, window;
1176 * Disable and clear all XOR windows, revoke protection for all
1180 for (j = 0; j < m; j++, e--) {
1182 /* Number of non-remaped windows */
1183 window = MV_XOR_NON_REMAP - 1;
1185 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
1186 win_xor_br_write(i, e, 0);
1187 win_xor_sz_write(i, e, 0);
1190 if (win_xor_can_remap(i) == 1)
1191 win_xor_har_write(i, e, 0);
1193 for (i = 0; i < MV_XOR_CHAN_MAX; i++) {
1194 win_xor_ctrl_write(i, e, 0);
1195 xor_active_dram(i, e, &window);
1199 * Remaining targets -- from a statically defined table
1201 for (i = 0; i < xor_wins_no; i++)
1202 if (xor_wins[i].target > 0) {
1203 br = (xor_wins[i].base & 0xffff0000) |
1204 (xor_wins[i].attr << 8) |
1206 sz = ((xor_wins[i].size - 1) & 0xffff0000);
1208 /* Set the first free XOR window */
1209 for (z = 0; z < MV_WIN_XOR_MAX; z++) {
1210 if (xor_ctrl_read(z, 0, e) &&
1211 xor_ctrl_read(z, 1, e))
1214 /* Configure window */
1215 win_xor_br_write(z, e, br);
1216 win_xor_sz_write(z, e, sz);
1217 if (win_xor_can_remap(z) &&
1218 xor_wins[z].remap >= 0)
1219 win_xor_har_write(z, e,
1222 /* Set protection RW on all channels */
1223 xor_set_prot(z, e, 0x3);
1226 xor_ctrl_write(z, 0, e, 1);
1227 xor_ctrl_write(z, 1, e, 1);
1235 decode_win_xor_valid(void)
1237 const struct decode_win *wintab;
1241 if (xor_wins_no > MV_WIN_XOR_MAX) {
1242 printf("XOR windows: too many entries: %d\n", xor_wins_no);
1245 for (i = 0, c = 0; i < MV_WIN_DDR_MAX; i++)
1246 if (ddr_is_active(i))
1249 if (xor_wins_no > (MV_WIN_XOR_MAX - c)) {
1250 printf("XOR windows: too many entries: %d, available: %d\n",
1251 xor_wins_no, MV_WIN_IDMA_MAX - c);
1257 for (i = 0; i < xor_wins_no; i++, wintab++) {
1259 if (wintab->target == 0) {
1260 printf("XOR window#%d: DDR target window is not "
1261 "supposed to be reprogrammed!\n", i);
1265 if (wintab->remap >= 0 && win_cpu_can_remap(i) != 1) {
1266 printf("XOR window#%d: not capable of remapping, but "
1267 "val 0x%08x defined\n", i, wintab->remap);
1274 if (s > (0xFFFFFFFF - b + 1)) {
1276 * XXX this boundary check should account for 64bit
1279 printf("XOR window#%d: no space for size 0x%08x at "
1280 "0x%08x\n", i, s, b);
1285 j = decode_win_overlap(i, xor_wins_no, &xor_wins[0]);
1287 printf("XOR window#%d: (0x%08x - 0x%08x) overlaps "
1288 "with #%d (0x%08x - 0x%08x)\n", i, b, e, j,
1290 xor_wins[j].base + xor_wins[j].size - 1);
1299 decode_win_xor_dump(void)
1304 for (j = 0; j < xor_max_eng(); j++, e--) {
1305 for (i = 0; i < MV_WIN_XOR_MAX; i++) {
1306 printf("XOR window#%d: b 0x%08x, s 0x%08x", i,
1307 win_xor_br_read(i, e), win_xor_sz_read(i, e));
1309 if (win_xor_can_remap(i))
1310 printf(", ha 0x%08x", win_xor_har_read(i, e));
1314 for (i = 0; i < MV_XOR_CHAN_MAX; i++)
1315 printf("XOR control#%d: 0x%08x\n", i,
1316 win_xor_ctrl_read(i, e));
1321 /* Provide dummy functions to satisfy the build for SoCs not equipped with XOR */
1323 decode_win_xor_valid(void)
1330 decode_win_xor_setup(void)
1335 decode_win_xor_dump(void)
1340 /**************************************************************************
1341 * CESA TDMA windows routines
1342 **************************************************************************/
1343 #if defined(SOC_MV_KIRKWOOD) || defined(SOC_MV_DISCOVERY)
1345 * Dump CESA TDMA decode windows.
1348 decode_win_cesa_dump(void)
1352 for (i = 0; i < MV_WIN_CESA_MAX; i++)
1353 printf("CESA window#%d: c 0x%08x, b 0x%08x\n", i,
1354 win_cesa_cr_read(i), win_cesa_br_read(i));
1359 * Set CESA TDMA decode windows.
1362 decode_win_cesa_setup(void)
1367 /* Disable and clear all CESA windows */
1368 for (i = 0; i < MV_WIN_CESA_MAX; i++) {
1369 win_cesa_cr_write(i, 0);
1370 win_cesa_br_write(i, 0);
1373 /* Only access to active DRAM banks is required. */
1374 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1375 if (ddr_is_active(i)) {
1377 cr = (((ddr_size(i) - 1) & 0xffff0000) |
1378 (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1);
1380 /* Set the first available CESA window */
1381 for (j = 0; j < MV_WIN_CESA_MAX; j++) {
1382 if (win_cesa_cr_read(j) & 0x1)
1385 win_cesa_br_write(j, br);
1386 win_cesa_cr_write(j, cr);
1393 * Check CESA TDMA decode windows.
1396 decode_win_cesa_valid(void)
1399 return (decode_win_can_cover_ddr(MV_WIN_CESA_MAX));
1404 * Provide dummy functions to satisfy the build for SoCs not equipped with
1409 decode_win_cesa_valid(void)
1416 decode_win_cesa_setup(void)
1421 decode_win_cesa_dump(void)
1426 /**************************************************************************
1427 * SATA windows routines
1428 **************************************************************************/
1430 decode_win_sata_setup(void)
1435 for (i = 0; i < MV_WIN_SATA_MAX; i++) {
1436 win_sata_cr_write(i, 0);
1437 win_sata_br_write(i, 0);
1440 for (i = 0; i < MV_WIN_DDR_MAX; i++)
1441 if (ddr_is_active(i)) {
1442 cr = ((ddr_size(i) - 1) & 0xffff0000) |
1443 (ddr_attr(i) << 8) | (ddr_target(i) << 4) | 1;
1446 /* Use the first available SATA window */
1447 for (j = 0; j < MV_WIN_SATA_MAX; j++) {
1448 if ((win_sata_cr_read(j) & 1) != 0)
1451 win_sata_br_write(j, br);
1452 win_sata_cr_write(j, cr);
1459 decode_win_sata_valid(void)
1464 if (dev == MV_DEV_88F5281)
1467 return (decode_win_can_cover_ddr(MV_WIN_SATA_MAX));