2 * IO workarounds for PCI on Celleb/Cell platform
4 * (C) Copyright 2006-2007 TOSHIBA CORPORATION
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <linux/kernel.h>
24 #include <linux/of_platform.h>
27 #include <asm/ppc-pci.h>
28 #include <asm/pci-bridge.h>
30 #include "io-workarounds.h"
32 #define SPIDER_PCI_DISABLE_PREFETCH
34 struct spiderpci_iowa_private {
38 static void spiderpci_io_flush(struct iowa_bus *bus)
40 struct spiderpci_iowa_private *priv;
44 val = in_be32(priv->regs + SPIDER_PCI_DUMMY_READ);
48 #define SPIDER_PCI_MMIO_READ(name, ret) \
49 static ret spiderpci_##name(const PCI_IO_ADDR addr) \
51 ret val = __do_##name(addr); \
52 spiderpci_io_flush(iowa_mem_find_bus(addr)); \
56 #define SPIDER_PCI_MMIO_READ_STR(name) \
57 static void spiderpci_##name(const PCI_IO_ADDR addr, void *buf, \
58 unsigned long count) \
60 __do_##name(addr, buf, count); \
61 spiderpci_io_flush(iowa_mem_find_bus(addr)); \
64 SPIDER_PCI_MMIO_READ(readb, u8)
65 SPIDER_PCI_MMIO_READ(readw, u16)
66 SPIDER_PCI_MMIO_READ(readl, u32)
67 SPIDER_PCI_MMIO_READ(readq, u64)
68 SPIDER_PCI_MMIO_READ(readw_be, u16)
69 SPIDER_PCI_MMIO_READ(readl_be, u32)
70 SPIDER_PCI_MMIO_READ(readq_be, u64)
71 SPIDER_PCI_MMIO_READ_STR(readsb)
72 SPIDER_PCI_MMIO_READ_STR(readsw)
73 SPIDER_PCI_MMIO_READ_STR(readsl)
75 static void spiderpci_memcpy_fromio(void *dest, const PCI_IO_ADDR src,
78 __do_memcpy_fromio(dest, src, n);
79 spiderpci_io_flush(iowa_mem_find_bus(src));
82 static int __init spiderpci_pci_setup_chip(struct pci_controller *phb,
86 dma_addr_t dummy_page_da;
88 #ifdef SPIDER_PCI_DISABLE_PREFETCH
89 u32 val = in_be32(regs + SPIDER_PCI_VCI_CNTL_STAT);
90 pr_debug("SPIDER_IOWA:PVCI_Control_Status was 0x%08x\n", val);
91 out_be32(regs + SPIDER_PCI_VCI_CNTL_STAT, val | 0x8);
92 #endif /* SPIDER_PCI_DISABLE_PREFETCH */
94 /* setup dummy read */
96 * On CellBlade, we can't know that which XDR memory is used by
97 * kmalloc() to allocate dummy_page_va.
98 * In order to imporve the performance, the XDR which is used to
99 * allocate dummy_page_va is the nearest the spider-pci.
100 * We have to select the CBE which is the nearest the spider-pci
101 * to allocate memory from the best XDR, but I don't know that
104 * Celleb does not have this problem, because it has only one XDR.
106 dummy_page_va = kmalloc(PAGE_SIZE, GFP_KERNEL);
107 if (!dummy_page_va) {
108 pr_err("SPIDERPCI-IOWA:Alloc dummy_page_va failed.\n");
112 dummy_page_da = dma_map_single(phb->parent, dummy_page_va,
113 PAGE_SIZE, DMA_FROM_DEVICE);
114 if (dma_mapping_error(dummy_page_da)) {
115 pr_err("SPIDER-IOWA:Map dummy page filed.\n");
116 kfree(dummy_page_va);
120 out_be32(regs + SPIDER_PCI_DUMMY_READ_BASE, dummy_page_da);
125 int __init spiderpci_iowa_init(struct iowa_bus *bus, void *data)
127 void __iomem *regs = NULL;
128 struct spiderpci_iowa_private *priv;
129 struct device_node *np = bus->phb->dn;
131 unsigned long offset = (unsigned long)data;
133 pr_debug("SPIDERPCI-IOWA:Bus initialize for spider(%s)\n",
136 priv = kzalloc(sizeof(struct spiderpci_iowa_private), GFP_KERNEL);
138 pr_err("SPIDERPCI-IOWA:"
139 "Can't allocate struct spiderpci_iowa_private");
143 if (of_address_to_resource(np, 0, &r)) {
144 pr_err("SPIDERPCI-IOWA:Can't get resource.\n");
148 regs = ioremap(r.start + offset, SPIDER_PCI_REG_SIZE);
150 pr_err("SPIDERPCI-IOWA:ioremap failed.\n");
156 if (spiderpci_pci_setup_chip(bus->phb, regs))
171 struct ppc_pci_io spiderpci_ops = {
172 .readb = spiderpci_readb,
173 .readw = spiderpci_readw,
174 .readl = spiderpci_readl,
175 .readq = spiderpci_readq,
176 .readw_be = spiderpci_readw_be,
177 .readl_be = spiderpci_readl_be,
178 .readq_be = spiderpci_readq_be,
179 .readsb = spiderpci_readsb,
180 .readsw = spiderpci_readsw,
181 .readsl = spiderpci_readsl,
182 .memcpy_fromio = spiderpci_memcpy_fromio,