diff options
| -rw-r--r-- | Documentation/devicetree/bindings/pci/versatile.txt | 59 | ||||
| -rw-r--r-- | MAINTAINERS | 8 | ||||
| -rw-r--r-- | arch/arm/boot/dts/versatile-pb.dts | 37 | ||||
| -rw-r--r-- | drivers/of/of_pci.c | 4 | ||||
| -rw-r--r-- | drivers/pci/host/Kconfig | 4 | ||||
| -rw-r--r-- | drivers/pci/host/Makefile | 1 | ||||
| -rw-r--r-- | drivers/pci/host/pci-versatile.c | 237 |
7 files changed, 350 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/pci/versatile.txt b/Documentation/devicetree/bindings/pci/versatile.txt new file mode 100644 index 000000000000..ebd1e7d0403e --- /dev/null +++ b/Documentation/devicetree/bindings/pci/versatile.txt | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | * ARM Versatile Platform Baseboard PCI interface | ||
| 2 | |||
| 3 | PCI host controller found on the ARM Versatile PB board's FPGA. | ||
| 4 | |||
| 5 | Required properties: | ||
| 6 | - compatible: should contain "arm,versatile-pci" to identify the Versatile PCI | ||
| 7 | controller. | ||
| 8 | - reg: base addresses and lengths of the pci controller. There must be 3 | ||
| 9 | entries: | ||
| 10 | - Versatile-specific registers | ||
| 11 | - Self Config space | ||
| 12 | - Config space | ||
| 13 | - #address-cells: set to <3> | ||
| 14 | - #size-cells: set to <2> | ||
| 15 | - device_type: set to "pci" | ||
| 16 | - bus-range: set to <0 0xff> | ||
| 17 | - ranges: ranges for the PCI memory and I/O regions | ||
| 18 | - #interrupt-cells: set to <1> | ||
| 19 | - interrupt-map-mask and interrupt-map: standard PCI properties to define | ||
| 20 | the mapping of the PCI interface to interrupt numbers. | ||
| 21 | |||
| 22 | Example: | ||
| 23 | |||
| 24 | pci-controller@10001000 { | ||
| 25 | compatible = "arm,versatile-pci"; | ||
| 26 | device_type = "pci"; | ||
| 27 | reg = <0x10001000 0x1000 | ||
| 28 | 0x41000000 0x10000 | ||
| 29 | 0x42000000 0x100000>; | ||
| 30 | bus-range = <0 0xff>; | ||
| 31 | #address-cells = <3>; | ||
| 32 | #size-cells = <2>; | ||
| 33 | #interrupt-cells = <1>; | ||
| 34 | |||
| 35 | ranges = <0x01000000 0 0x00000000 0x43000000 0 0x00010000 /* downstream I/O */ | ||
| 36 | 0x02000000 0 0x50000000 0x50000000 0 0x10000000 /* non-prefetchable memory */ | ||
| 37 | 0x42000000 0 0x60000000 0x60000000 0 0x10000000>; /* prefetchable memory */ | ||
| 38 | |||
| 39 | interrupt-map-mask = <0x1800 0 0 7>; | ||
| 40 | interrupt-map = <0x1800 0 0 1 &sic 28 | ||
| 41 | 0x1800 0 0 2 &sic 29 | ||
| 42 | 0x1800 0 0 3 &sic 30 | ||
| 43 | 0x1800 0 0 4 &sic 27 | ||
| 44 | |||
| 45 | 0x1000 0 0 1 &sic 27 | ||
| 46 | 0x1000 0 0 2 &sic 28 | ||
| 47 | 0x1000 0 0 3 &sic 29 | ||
| 48 | 0x1000 0 0 4 &sic 30 | ||
| 49 | |||
| 50 | 0x0800 0 0 1 &sic 30 | ||
| 51 | 0x0800 0 0 2 &sic 27 | ||
| 52 | 0x0800 0 0 3 &sic 28 | ||
| 53 | 0x0800 0 0 4 &sic 29 | ||
| 54 | |||
| 55 | 0x0000 0 0 1 &sic 29 | ||
| 56 | 0x0000 0 0 2 &sic 30 | ||
| 57 | 0x0000 0 0 3 &sic 27 | ||
| 58 | 0x0000 0 0 4 &sic 28>; | ||
| 59 | }; | ||
diff --git a/MAINTAINERS b/MAINTAINERS index ddb9ac8d32b3..1d38850a4b87 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -7210,6 +7210,14 @@ F: include/linux/pci* | |||
| 7210 | F: arch/x86/pci/ | 7210 | F: arch/x86/pci/ |
| 7211 | F: arch/x86/kernel/quirks.c | 7211 | F: arch/x86/kernel/quirks.c |
| 7212 | 7212 | ||
| 7213 | PCI DRIVER FOR ARM VERSATILE PLATFORM | ||
| 7214 | M: Rob Herring <robh@kernel.org> | ||
| 7215 | L: linux-pci@vger.kernel.org | ||
| 7216 | L: linux-arm-kernel@lists.infradead.org | ||
| 7217 | S: Maintained | ||
| 7218 | F: Documentation/devicetree/bindings/pci/versatile.txt | ||
| 7219 | F: drivers/pci/host/pci-versatile.c | ||
| 7220 | |||
| 7213 | PCI DRIVER FOR APPLIEDMICRO XGENE | 7221 | PCI DRIVER FOR APPLIEDMICRO XGENE |
| 7214 | M: Tanmay Inamdar <tinamdar@apm.com> | 7222 | M: Tanmay Inamdar <tinamdar@apm.com> |
| 7215 | L: linux-pci@vger.kernel.org | 7223 | L: linux-pci@vger.kernel.org |
diff --git a/arch/arm/boot/dts/versatile-pb.dts b/arch/arm/boot/dts/versatile-pb.dts index e36c1e82fea7..b83137f66034 100644 --- a/arch/arm/boot/dts/versatile-pb.dts +++ b/arch/arm/boot/dts/versatile-pb.dts | |||
| @@ -29,6 +29,43 @@ | |||
| 29 | clock-names = "apb_pclk"; | 29 | clock-names = "apb_pclk"; |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | pci-controller@10001000 { | ||
| 33 | compatible = "arm,versatile-pci"; | ||
| 34 | device_type = "pci"; | ||
| 35 | reg = <0x10001000 0x1000 | ||
| 36 | 0x41000000 0x10000 | ||
| 37 | 0x42000000 0x100000>; | ||
| 38 | bus-range = <0 0xff>; | ||
| 39 | #address-cells = <3>; | ||
| 40 | #size-cells = <2>; | ||
| 41 | #interrupt-cells = <1>; | ||
| 42 | |||
| 43 | ranges = <0x01000000 0 0x00000000 0x43000000 0 0x00010000 /* downstream I/O */ | ||
| 44 | 0x02000000 0 0x50000000 0x50000000 0 0x10000000 /* non-prefetchable memory */ | ||
| 45 | 0x42000000 0 0x60000000 0x60000000 0 0x10000000>; /* prefetchable memory */ | ||
| 46 | |||
| 47 | interrupt-map-mask = <0x1800 0 0 7>; | ||
| 48 | interrupt-map = <0x1800 0 0 1 &sic 28 | ||
| 49 | 0x1800 0 0 2 &sic 29 | ||
| 50 | 0x1800 0 0 3 &sic 30 | ||
| 51 | 0x1800 0 0 4 &sic 27 | ||
| 52 | |||
| 53 | 0x1000 0 0 1 &sic 27 | ||
| 54 | 0x1000 0 0 2 &sic 28 | ||
| 55 | 0x1000 0 0 3 &sic 29 | ||
| 56 | 0x1000 0 0 4 &sic 30 | ||
| 57 | |||
| 58 | 0x0800 0 0 1 &sic 30 | ||
| 59 | 0x0800 0 0 2 &sic 27 | ||
| 60 | 0x0800 0 0 3 &sic 28 | ||
| 61 | 0x0800 0 0 4 &sic 29 | ||
| 62 | |||
| 63 | 0x0000 0 0 1 &sic 29 | ||
| 64 | 0x0000 0 0 2 &sic 30 | ||
| 65 | 0x0000 0 0 3 &sic 27 | ||
| 66 | 0x0000 0 0 4 &sic 28>; | ||
| 67 | }; | ||
| 68 | |||
| 32 | fpga { | 69 | fpga { |
| 33 | uart@9000 { | 70 | uart@9000 { |
| 34 | compatible = "arm,pl011", "arm,primecell"; | 71 | compatible = "arm,pl011", "arm,primecell"; |
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 88471d3d98cd..60dc36c865b5 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c | |||
| @@ -140,6 +140,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, | |||
| 140 | unsigned char busno, unsigned char bus_max, | 140 | unsigned char busno, unsigned char bus_max, |
| 141 | struct list_head *resources, resource_size_t *io_base) | 141 | struct list_head *resources, resource_size_t *io_base) |
| 142 | { | 142 | { |
| 143 | struct pci_host_bridge_window *window; | ||
| 143 | struct resource *res; | 144 | struct resource *res; |
| 144 | struct resource *bus_range; | 145 | struct resource *bus_range; |
| 145 | struct of_pci_range range; | 146 | struct of_pci_range range; |
| @@ -225,7 +226,10 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, | |||
| 225 | conversion_failed: | 226 | conversion_failed: |
| 226 | kfree(res); | 227 | kfree(res); |
| 227 | parse_failed: | 228 | parse_failed: |
| 229 | list_for_each_entry(window, resources, list) | ||
| 230 | kfree(window->res); | ||
| 228 | pci_free_resource_list(resources); | 231 | pci_free_resource_list(resources); |
| 232 | kfree(bus_range); | ||
| 229 | return err; | 233 | return err; |
| 230 | } | 234 | } |
| 231 | EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources); | 235 | EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources); |
diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig index c4b6568e486d..7b892a9cc4fc 100644 --- a/drivers/pci/host/Kconfig +++ b/drivers/pci/host/Kconfig | |||
| @@ -102,4 +102,8 @@ config PCI_LAYERSCAPE | |||
| 102 | help | 102 | help |
| 103 | Say Y here if you want PCIe controller support on Layerscape SoCs. | 103 | Say Y here if you want PCIe controller support on Layerscape SoCs. |
| 104 | 104 | ||
| 105 | config PCI_VERSATILE | ||
| 106 | bool "ARM Versatile PB PCI controller" | ||
| 107 | depends on ARCH_VERSATILE | ||
| 108 | |||
| 105 | endmenu | 109 | endmenu |
diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile index 44c26998027f..e61d91c92bf1 100644 --- a/drivers/pci/host/Makefile +++ b/drivers/pci/host/Makefile | |||
| @@ -12,3 +12,4 @@ obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o | |||
| 12 | obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o | 12 | obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o |
| 13 | obj-$(CONFIG_PCI_XGENE) += pci-xgene.o | 13 | obj-$(CONFIG_PCI_XGENE) += pci-xgene.o |
| 14 | obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o | 14 | obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o |
| 15 | obj-$(CONFIG_PCI_VERSATILE) += pci-versatile.o | ||
diff --git a/drivers/pci/host/pci-versatile.c b/drivers/pci/host/pci-versatile.c new file mode 100644 index 000000000000..341529ca23e8 --- /dev/null +++ b/drivers/pci/host/pci-versatile.c | |||
| @@ -0,0 +1,237 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2004 Koninklijke Philips Electronics NV | ||
| 3 | * | ||
| 4 | * Conversion to platform driver and DT: | ||
| 5 | * Copyright 2014 Linaro Ltd. | ||
| 6 | * | ||
| 7 | * This software is licensed under the terms of the GNU General Public | ||
| 8 | * License version 2, as published by the Free Software Foundation, and | ||
| 9 | * may be copied, distributed, and modified under those terms. | ||
| 10 | * | ||
| 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. | ||
| 15 | * | ||
| 16 | * 14/04/2005 Initial version, colin.king@philips.com | ||
| 17 | */ | ||
| 18 | #include <linux/kernel.h> | ||
| 19 | #include <linux/module.h> | ||
| 20 | #include <linux/of_address.h> | ||
| 21 | #include <linux/of_pci.h> | ||
| 22 | #include <linux/of_platform.h> | ||
| 23 | #include <linux/pci.h> | ||
| 24 | #include <linux/platform_device.h> | ||
| 25 | |||
| 26 | static void __iomem *versatile_pci_base; | ||
| 27 | static void __iomem *versatile_cfg_base[2]; | ||
| 28 | |||
| 29 | #define PCI_IMAP(m) (versatile_pci_base + ((m) * 4)) | ||
| 30 | #define PCI_SMAP(m) (versatile_pci_base + 0x14 + ((m) * 4)) | ||
| 31 | #define PCI_SELFID (versatile_pci_base + 0xc) | ||
| 32 | |||
| 33 | #define VP_PCI_DEVICE_ID 0x030010ee | ||
| 34 | #define VP_PCI_CLASS_ID 0x0b400000 | ||
| 35 | |||
| 36 | static u32 pci_slot_ignore; | ||
| 37 | |||
| 38 | static int __init versatile_pci_slot_ignore(char *str) | ||
| 39 | { | ||
| 40 | int retval; | ||
| 41 | int slot; | ||
| 42 | |||
| 43 | while ((retval = get_option(&str, &slot))) { | ||
| 44 | if ((slot < 0) || (slot > 31)) | ||
| 45 | pr_err("Illegal slot value: %d\n", slot); | ||
| 46 | else | ||
| 47 | pci_slot_ignore |= (1 << slot); | ||
| 48 | } | ||
| 49 | return 1; | ||
| 50 | } | ||
| 51 | __setup("pci_slot_ignore=", versatile_pci_slot_ignore); | ||
| 52 | |||
| 53 | |||
| 54 | static void __iomem *versatile_map_bus(struct pci_bus *bus, | ||
| 55 | unsigned int devfn, int offset) | ||
| 56 | { | ||
| 57 | unsigned int busnr = bus->number; | ||
| 58 | |||
| 59 | if (pci_slot_ignore & (1 << PCI_SLOT(devfn))) | ||
| 60 | return NULL; | ||
| 61 | |||
| 62 | return versatile_cfg_base[1] + ((busnr << 16) | (devfn << 8) | offset); | ||
| 63 | } | ||
| 64 | |||
| 65 | static struct pci_ops pci_versatile_ops = { | ||
| 66 | .map_bus = versatile_map_bus, | ||
| 67 | .read = pci_generic_config_read32, | ||
| 68 | .write = pci_generic_config_write, | ||
| 69 | }; | ||
| 70 | |||
| 71 | static int versatile_pci_parse_request_of_pci_ranges(struct device *dev, | ||
| 72 | struct list_head *res) | ||
| 73 | { | ||
| 74 | int err, mem = 1, res_valid = 0; | ||
| 75 | struct device_node *np = dev->of_node; | ||
| 76 | resource_size_t iobase; | ||
| 77 | struct pci_host_bridge_window *win; | ||
| 78 | |||
| 79 | err = of_pci_get_host_bridge_resources(np, 0, 0xff, res, &iobase); | ||
| 80 | if (err) | ||
| 81 | return err; | ||
| 82 | |||
| 83 | list_for_each_entry(win, res, list) { | ||
| 84 | struct resource *parent, *res = win->res; | ||
| 85 | |||
| 86 | switch (resource_type(res)) { | ||
| 87 | case IORESOURCE_IO: | ||
| 88 | parent = &ioport_resource; | ||
| 89 | err = pci_remap_iospace(res, iobase); | ||
| 90 | if (err) { | ||
| 91 | dev_warn(dev, "error %d: failed to map resource %pR\n", | ||
| 92 | err, res); | ||
| 93 | continue; | ||
| 94 | } | ||
| 95 | break; | ||
| 96 | case IORESOURCE_MEM: | ||
| 97 | parent = &iomem_resource; | ||
| 98 | res_valid |= !(res->flags & IORESOURCE_PREFETCH); | ||
| 99 | |||
| 100 | writel(res->start >> 28, PCI_IMAP(mem)); | ||
| 101 | writel(PHYS_OFFSET >> 28, PCI_SMAP(mem)); | ||
| 102 | mem++; | ||
| 103 | |||
| 104 | break; | ||
| 105 | case IORESOURCE_BUS: | ||
| 106 | default: | ||
| 107 | continue; | ||
| 108 | } | ||
| 109 | |||
| 110 | err = devm_request_resource(dev, parent, res); | ||
| 111 | if (err) | ||
| 112 | goto out_release_res; | ||
| 113 | } | ||
| 114 | |||
| 115 | if (!res_valid) { | ||
| 116 | dev_err(dev, "non-prefetchable memory resource required\n"); | ||
| 117 | err = -EINVAL; | ||
| 118 | goto out_release_res; | ||
| 119 | } | ||
| 120 | |||
| 121 | return 0; | ||
| 122 | |||
| 123 | out_release_res: | ||
| 124 | pci_free_resource_list(res); | ||
| 125 | return err; | ||
| 126 | } | ||
| 127 | |||
| 128 | /* Unused, temporary to satisfy ARM arch code */ | ||
| 129 | struct pci_sys_data sys; | ||
| 130 | |||
| 131 | static int versatile_pci_probe(struct platform_device *pdev) | ||
| 132 | { | ||
| 133 | struct resource *res; | ||
| 134 | int ret, i, myslot = -1; | ||
| 135 | u32 val; | ||
| 136 | void __iomem *local_pci_cfg_base; | ||
| 137 | struct pci_bus *bus; | ||
| 138 | LIST_HEAD(pci_res); | ||
| 139 | |||
| 140 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 141 | if (!res) | ||
| 142 | return -ENODEV; | ||
| 143 | versatile_pci_base = devm_ioremap_resource(&pdev->dev, res); | ||
| 144 | |||
| 145 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
| 146 | if (!res) | ||
| 147 | return -ENODEV; | ||
| 148 | versatile_cfg_base[0] = devm_ioremap_resource(&pdev->dev, res); | ||
| 149 | |||
| 150 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); | ||
| 151 | if (!res) | ||
| 152 | return -ENODEV; | ||
| 153 | versatile_cfg_base[1] = devm_ioremap_resource(&pdev->dev, res); | ||
| 154 | |||
| 155 | ret = versatile_pci_parse_request_of_pci_ranges(&pdev->dev, &pci_res); | ||
| 156 | if (ret) | ||
| 157 | return ret; | ||
| 158 | |||
| 159 | /* | ||
| 160 | * We need to discover the PCI core first to configure itself | ||
| 161 | * before the main PCI probing is performed | ||
| 162 | */ | ||
| 163 | for (i = 0; i < 32; i++) { | ||
| 164 | if ((readl(versatile_cfg_base[0] + (i << 11) + PCI_VENDOR_ID) == VP_PCI_DEVICE_ID) && | ||
| 165 | (readl(versatile_cfg_base[0] + (i << 11) + PCI_CLASS_REVISION) == VP_PCI_CLASS_ID)) { | ||
| 166 | myslot = i; | ||
| 167 | break; | ||
| 168 | } | ||
| 169 | } | ||
| 170 | if (myslot == -1) { | ||
| 171 | dev_err(&pdev->dev, "Cannot find PCI core!\n"); | ||
| 172 | return -EIO; | ||
| 173 | } | ||
| 174 | /* | ||
| 175 | * Do not to map Versatile FPGA PCI device into memory space | ||
| 176 | */ | ||
| 177 | pci_slot_ignore |= (1 << myslot); | ||
| 178 | |||
| 179 | dev_info(&pdev->dev, "PCI core found (slot %d)\n", myslot); | ||
| 180 | |||
| 181 | writel(myslot, PCI_SELFID); | ||
| 182 | local_pci_cfg_base = versatile_cfg_base[1] + (myslot << 11); | ||
| 183 | |||
| 184 | val = readl(local_pci_cfg_base + PCI_COMMAND); | ||
| 185 | val |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE; | ||
| 186 | writel(val, local_pci_cfg_base + PCI_COMMAND); | ||
| 187 | |||
| 188 | /* | ||
| 189 | * Configure the PCI inbound memory windows to be 1:1 mapped to SDRAM | ||
| 190 | */ | ||
| 191 | writel(PHYS_OFFSET, local_pci_cfg_base + PCI_BASE_ADDRESS_0); | ||
| 192 | writel(PHYS_OFFSET, local_pci_cfg_base + PCI_BASE_ADDRESS_1); | ||
| 193 | writel(PHYS_OFFSET, local_pci_cfg_base + PCI_BASE_ADDRESS_2); | ||
| 194 | |||
| 195 | /* | ||
| 196 | * For many years the kernel and QEMU were symbiotically buggy | ||
| 197 | * in that they both assumed the same broken IRQ mapping. | ||
| 198 | * QEMU therefore attempts to auto-detect old broken kernels | ||
| 199 | * so that they still work on newer QEMU as they did on old | ||
| 200 | * QEMU. Since we now use the correct (ie matching-hardware) | ||
| 201 | * IRQ mapping we write a definitely different value to a | ||
| 202 | * PCI_INTERRUPT_LINE register to tell QEMU that we expect | ||
| 203 | * real hardware behaviour and it need not be backwards | ||
| 204 | * compatible for us. This write is harmless on real hardware. | ||
| 205 | */ | ||
| 206 | writel(0, versatile_cfg_base[0] + PCI_INTERRUPT_LINE); | ||
| 207 | |||
| 208 | pci_add_flags(PCI_ENABLE_PROC_DOMAINS); | ||
| 209 | pci_add_flags(PCI_REASSIGN_ALL_BUS | PCI_REASSIGN_ALL_RSRC); | ||
| 210 | |||
| 211 | bus = pci_scan_root_bus(&pdev->dev, 0, &pci_versatile_ops, &sys, &pci_res); | ||
| 212 | if (!bus) | ||
| 213 | return -ENOMEM; | ||
| 214 | |||
| 215 | pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci); | ||
| 216 | pci_assign_unassigned_bus_resources(bus); | ||
| 217 | |||
| 218 | return 0; | ||
| 219 | } | ||
| 220 | |||
| 221 | static const struct of_device_id versatile_pci_of_match[] = { | ||
| 222 | { .compatible = "arm,versatile-pci", }, | ||
| 223 | { }, | ||
| 224 | }; | ||
| 225 | MODULE_DEVICE_TABLE(of, versatile_pci_of_match); | ||
| 226 | |||
| 227 | static struct platform_driver versatile_pci_driver = { | ||
| 228 | .driver = { | ||
| 229 | .name = "versatile-pci", | ||
| 230 | .of_match_table = versatile_pci_of_match, | ||
| 231 | }, | ||
| 232 | .probe = versatile_pci_probe, | ||
| 233 | }; | ||
| 234 | module_platform_driver(versatile_pci_driver); | ||
| 235 | |||
| 236 | MODULE_DESCRIPTION("Versatile PCI driver"); | ||
| 237 | MODULE_LICENSE("GPL v2"); | ||
