From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liviu Dudau Subject: Re: [PATCH v5 1/4] pci: APM X-Gene PCIe controller driver Date: Tue, 25 Mar 2014 14:02:01 +0000 Message-ID: <20140325140201.GE17163@e106497-lin.cambridge.arm.com> References: <1395270762-6055-1-git-send-email-tinamdar@apm.com> <1395270762-6055-2-git-send-email-tinamdar@apm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <1395270762-6055-2-git-send-email-tinamdar@apm.com> Content-Disposition: inline Sender: linux-pci-owner@vger.kernel.org To: Tanmay Inamdar Cc: Bjorn Helgaas , Arnd Bergmann , Jason Gunthorpe , "grant.likely@linaro.org" , Rob Herring , Catalin Marinas , Rob Landley , "linux-pci@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "patches@apm.com" , "jcm@redhat.com" List-Id: devicetree@vger.kernel.org On Wed, Mar 19, 2014 at 11:12:39PM +0000, Tanmay Inamdar wrote: > This patch adds the AppliedMicro X-Gene SOC PCIe controller driver. > X-Gene PCIe controller supports maximum up to 8 lanes and GEN3 speed. > X-Gene SOC supports maximum 5 PCIe ports. >=20 > Signed-off-by: Tanmay Inamdar Hi Tanmay, Some comments below. > --- > drivers/pci/host/Kconfig | 10 + > drivers/pci/host/Makefile | 1 + > drivers/pci/host/pci-xgene.c | 725 ++++++++++++++++++++++++++++++++= ++++++++++ > 3 files changed, 736 insertions(+) > create mode 100644 drivers/pci/host/pci-xgene.c >=20 > diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig > index 47d46c6..19ce97d 100644 > --- a/drivers/pci/host/Kconfig > +++ b/drivers/pci/host/Kconfig > @@ -33,4 +33,14 @@ config PCI_RCAR_GEN2 > There are 3 internal PCI controllers available with a singl= e > built-in EHCI/OHCI host controller present on each one. >=20 > +config PCI_XGENE > + bool "X-Gene PCIe controller" > + depends on ARCH_XGENE > + depends on OF > + select PCIEPORTBUS > + help > + Say Y here if you want internal PCI support on APM X-Gene S= oC. > + There are 5 internal PCIe ports available. Each port is GEN= 3 capable > + and have varied lanes from x1 to x8. > + > endmenu > diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile > index 13fb333..34c7c36 100644 > --- a/drivers/pci/host/Makefile > +++ b/drivers/pci/host/Makefile > @@ -4,3 +4,4 @@ obj-$(CONFIG_PCI_IMX6) +=3D pci-imx6.o > obj-$(CONFIG_PCI_MVEBU) +=3D pci-mvebu.o > obj-$(CONFIG_PCI_TEGRA) +=3D pci-tegra.o > obj-$(CONFIG_PCI_RCAR_GEN2) +=3D pci-rcar-gen2.o > +obj-$(CONFIG_PCI_XGENE) +=3D pci-xgene.o > diff --git a/drivers/pci/host/pci-xgene.c b/drivers/pci/host/pci-xgen= e.c > new file mode 100644 > index 0000000..9e312f6 > --- /dev/null > +++ b/drivers/pci/host/pci-xgene.c > @@ -0,0 +1,725 @@ > +/** > + * APM X-Gene PCIe Driver > + * > + * Copyright (c) 2013 Applied Micro Circuits Corporation. > + * > + * Author: Tanmay Inamdar . > + * > + * This program is free software; you can redistribute it and/or mo= dify it > + * under the terms of the GNU General Public License as published= by the > + * Free Software Foundation; either version 2 of the License, or (= at your > + * option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define PCIECORE_LTSSM 0x4c > +#define PCIECORE_CTLANDSTATUS 0x50 > +#define INTXSTATUSMASK 0x6c > +#define PIM1_1L 0x80 > +#define IBAR2 0x98 > +#define IR2MSK 0x9c > +#define PIM2_1L 0xa0 > +#define IBAR3L 0xb4 > +#define IR3MSKL 0xbc > +#define PIM3_1L 0xc4 > +#define OMR1BARL 0x100 > +#define OMR2BARL 0x118 > +#define OMR3BARL 0x130 > +#define CFGBARL 0x154 > +#define CFGBARH 0x158 > +#define CFGCTL 0x15c > +#define RTDID 0x160 > +#define BRIDGE_CFG_0 0x2000 > +#define BRIDGE_CFG_1 0x2004 > +#define BRIDGE_CFG_4 0x2010 > +#define BRIDGE_CFG_32 0x2030 > +#define BRIDGE_CFG_14 0x2038 > +#define BRIDGE_CTRL_1 0x2204 > +#define BRIDGE_CTRL_2 0x2208 > +#define BRIDGE_CTRL_5 0x2214 > +#define BRIDGE_STATUS_0 0x2600 > +#define MEM_RAM_SHUTDOWN 0xd070 > +#define BLOCK_MEM_RDY 0xd074 > + > +#define DEVICE_PORT_TYPE_MASK 0x03c00000 > +#define PM_FORCE_RP_MODE_MASK 0x00000400 > +#define SWITCH_PORT_MODE_MASK 0x00000800 > +#define CLASS_CODE_MASK 0xffffff00 > +#define LINK_UP_MASK 0x00000100 > +#define AER_OPTIONAL_ERROR_EN 0xffc00000 > +#define XGENE_PCIE_DEV_CTRL 0x2f0f > +#define AXI_EP_CFG_ACCESS 0x10000 > +#define ENABLE_ASPM 0x08000000 > +#define XGENE_PORT_TYPE_RC 0x05000000 > +#define BLOCK_MEM_RDY_VAL 0xFFFFFFFF > +#define EN_COHERENCY 0xF0000000 > +#define EN_REG 0x00000001 > +#define OB_LO_IO 0x00000002 > +#define XGENE_PCIE_VENDORID 0xE008 > +#define XGENE_PCIE_DEVICEID 0xE004 > +#define XGENE_PCIE_ECC_TIMEOUT 10 /* ms */ > +#define XGENE_LTSSM_DETECT_WAIT 20 /* ms */ > +#define XGENE_LTSSM_L0_WAIT 4 /* ms */ > +#define SZ_1T (SZ_1G*1024ULL) > +#define PIPE_PHY_RATE_RD(src) ((0xc000 & (u32)(src)) >> 0xe= ) > + > +struct xgene_pcie_port { > + struct device_node *node; > + struct device *dev; > + struct clk *clk; > + void __iomem *csr_base; > + void __iomem *cfg_base; > + u8 link_up; > +}; > + > +static inline u32 pcie_bar_low_val(u32 addr, u32 flags) > +{ > + return (addr & PCI_BASE_ADDRESS_MEM_MASK) | flags; > +} > + > +/* PCIE Configuration Out/In */ > +static inline void xgene_pcie_cfg_out32(void __iomem *addr, int offs= et, u32 val) > +{ > + writel(val, addr + offset); > +} > + > +static inline void xgene_pcie_cfg_out16(void __iomem *addr, int offs= et, u16 val) > +{ > + u32 val32 =3D readl(addr + (offset & ~0x3)); > + > + switch (offset & 0x3) { > + case 2: > + val32 &=3D ~0xFFFF0000; > + val32 |=3D (u32)val << 16; > + break; > + case 0: > + default: > + val32 &=3D ~0xFFFF; > + val32 |=3D val; > + break; > + } > + writel(val32, addr + (offset & ~0x3)); > +} > + > +static inline void xgene_pcie_cfg_out8(void __iomem *addr, int offse= t, u8 val) > +{ > + u32 val32 =3D readl(addr + (offset & ~0x3)); > + > + switch (offset & 0x3) { > + case 0: > + val32 &=3D ~0xFF; > + val32 |=3D val; > + break; > + case 1: > + val32 &=3D ~0xFF00; > + val32 |=3D (u32)val << 8; > + break; > + case 2: > + val32 &=3D ~0xFF0000; > + val32 |=3D (u32)val << 16; > + break; > + case 3: > + default: > + val32 &=3D ~0xFF000000; > + val32 |=3D (u32)val << 24; > + break; > + } > + writel(val32, addr + (offset & ~0x3)); > +} > + > +static inline void xgene_pcie_cfg_in32(void __iomem *addr, int offse= t, u32 *val) > +{ > + *val =3D readl(addr + offset); > +} > + > +static inline void > +xgene_pcie_cfg_in16(void __iomem *addr, int offset, u32 *val) > +{ > + *val =3D readl(addr + (offset & ~0x3)); > + > + switch (offset & 0x3) { > + case 2: > + *val >>=3D 16; > + break; > + } > + > + *val &=3D 0xFFFF; > +} > + > +static inline void > +xgene_pcie_cfg_in8(void __iomem *addr, int offset, u32 *val) > +{ > + *val =3D readl(addr + (offset & ~0x3)); > + > + switch (offset & 0x3) { > + case 3: > + *val =3D *val >> 24; > + break; > + case 2: > + *val =3D *val >> 16; > + break; > + case 1: > + *val =3D *val >> 8; > + break; > + } > + *val &=3D 0xFF; > +} > + > +/* When the address bit [17:16] is 2'b01, the Configuration access w= ill be > + * treated as Type 1 and it will be forwarded to external PCIe devic= e. > + */ > +static void __iomem *xgene_pcie_get_cfg_base(struct pci_bus *bus) > +{ > + struct xgene_pcie_port *port =3D bus->sysdata; > + > + if (bus->number >=3D (bus->primary + 1)) I fail to see the link between what the comment says and what the code = does. It looks to me like any bus with a number from bus->primary +1 onwards wil= l have it's cfg_base altered. How does that translate into address bits? > + return port->cfg_base + AXI_EP_CFG_ACCESS; > + > + return port->cfg_base; > +} > + > +/* For Configuration request, RTDID register is used as Bus Number, > + * Device Number and Function number of the header fields. > + */ > +static void xgene_pcie_set_rtdid_reg(struct pci_bus *bus, uint devfn= ) > +{ > + struct xgene_pcie_port *port =3D bus->sysdata; > + unsigned int b, d, f; > + u32 rtdid_val =3D 0; > + > + b =3D bus->number; > + d =3D PCI_SLOT(devfn); > + f =3D PCI_FUNC(devfn); > + > + if (!pci_is_root_bus(bus)) > + rtdid_val =3D (b << 8) | (d << 3) | f; > + > + writel(rtdid_val, port->csr_base + RTDID); > + /* read the register back to ensure flush */ > + readl(port->csr_base + RTDID); > +} > + > +static int xgene_pcie_read_config(struct pci_bus *bus, unsigned int = devfn, > + int offset, int len, u32 *val) > +{ > + struct xgene_pcie_port *port =3D bus->sysdata; > + void __iomem *addr; > + > + if ((pci_is_root_bus(bus) && devfn !=3D 0) || !port->link_up) > + return PCIBIOS_DEVICE_NOT_FOUND; > + > + xgene_pcie_set_rtdid_reg(bus, devfn); > + addr =3D xgene_pcie_get_cfg_base(bus); > + switch (len) { > + case 1: > + xgene_pcie_cfg_in8(addr, offset, val); > + break; > + case 2: > + xgene_pcie_cfg_in16(addr, offset, val); > + break; > + default: > + xgene_pcie_cfg_in32(addr, offset, val); > + break; > + } > + return PCIBIOS_SUCCESSFUL; > +} > + > +static int xgene_pcie_write_config(struct pci_bus *bus, unsigned int= devfn, > + int offset, int len, u32 val) > +{ > + struct xgene_pcie_port *port =3D bus->sysdata; > + void __iomem *addr; > + > + if ((pci_is_root_bus(bus) && devfn !=3D 0) || !port->link_up) > + return PCIBIOS_DEVICE_NOT_FOUND; > + > + xgene_pcie_set_rtdid_reg(bus, devfn); > + addr =3D xgene_pcie_get_cfg_base(bus); > + switch (len) { > + case 1: > + xgene_pcie_cfg_out8(addr, offset, (u8)val); > + break; > + case 2: > + xgene_pcie_cfg_out16(addr, offset, (u16)val); > + break; > + default: > + xgene_pcie_cfg_out32(addr, offset, val); > + break; > + } > + return PCIBIOS_SUCCESSFUL; > +} > + > +static struct pci_ops xgene_pcie_ops =3D { > + .read =3D xgene_pcie_read_config, > + .write =3D xgene_pcie_write_config > +}; > + > +static void xgene_pcie_program_core(void __iomem *csr_base) > +{ > + u32 val; > + > + val =3D readl(csr_base + BRIDGE_CFG_0); > + val |=3D AER_OPTIONAL_ERROR_EN; > + writel(val, csr_base + BRIDGE_CFG_0); > + writel(0x0, csr_base + INTXSTATUSMASK); > + val =3D readl(csr_base + BRIDGE_CTRL_1); > + val =3D (val & ~0xffff) | XGENE_PCIE_DEV_CTRL; > + writel(val, csr_base + BRIDGE_CTRL_1); > +} > + > +static u64 xgene_pcie_set_ib_mask(void __iomem *csr_base, u32 addr, > + u32 flags, u64 size) > +{ > + u64 mask =3D (~(size - 1) & PCI_BASE_ADDRESS_MEM_MASK) | flag= s; > + u32 val32 =3D 0; > + u32 val; > + > + val32 =3D readl(csr_base + addr); > + val =3D (val32 & 0x0000ffff) | (lower_32_bits(mask) << 16); > + writel(val, csr_base + addr); > + > + val32 =3D readl(csr_base + addr + 0x04); > + val =3D (val32 & 0xffff0000) | (lower_32_bits(mask) >> 16); > + writel(val, csr_base + addr + 0x04); > + > + val32 =3D readl(csr_base + addr + 0x04); > + val =3D (val32 & 0x0000ffff) | (upper_32_bits(mask) << 16); > + writel(val, csr_base + addr + 0x04); > + > + val32 =3D readl(csr_base + addr + 0x08); > + val =3D (val32 & 0xffff0000) | (upper_32_bits(mask) >> 16); > + writel(val, csr_base + addr + 0x08); > + > + return mask; > +} > + > +static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, > + u32 *lanes, u32 *speed) > +{ > + void __iomem *csr_base =3D port->csr_base; > + ulong timeout; > + u32 val32; > + > + /* > + * A component enters the LTSSM Detect state within > + * 20ms of the end of fundamental core reset. > + */ > + msleep(XGENE_LTSSM_DETECT_WAIT); > + port->link_up =3D 0; > + timeout =3D jiffies + msecs_to_jiffies(XGENE_LTSSM_L0_WAIT); > + while (time_before(jiffies, timeout)) { > + val32 =3D readl(csr_base + PCIECORE_CTLANDSTATUS); > + if (val32 & LINK_UP_MASK) { > + port->link_up =3D 1; > + *speed =3D PIPE_PHY_RATE_RD(val32); > + val32 =3D readl(csr_base + BRIDGE_STATUS_0); > + *lanes =3D val32 >> 26; > + break; > + } > + msleep(1); > + } > +} > + > +static void xgene_pcie_setup_root_complex(struct xgene_pcie_port *po= rt) > +{ > + void __iomem *csr_base =3D port->csr_base; > + u32 val; > + > + val =3D (XGENE_PCIE_DEVICEID << 16) | XGENE_PCIE_VENDORID; > + writel(val, csr_base + BRIDGE_CFG_0); > + > + val =3D readl(csr_base + BRIDGE_CFG_1); > + val &=3D ~CLASS_CODE_MASK; > + val |=3D PCI_CLASS_BRIDGE_PCI << 16; > + writel(val, csr_base + BRIDGE_CFG_1); > + > + val =3D readl(csr_base + BRIDGE_CFG_14); > + val |=3D SWITCH_PORT_MODE_MASK; > + val &=3D ~PM_FORCE_RP_MODE_MASK; > + writel(val, csr_base + BRIDGE_CFG_14); > + > + val =3D readl(csr_base + BRIDGE_CTRL_5); > + val &=3D ~DEVICE_PORT_TYPE_MASK; > + val |=3D XGENE_PORT_TYPE_RC; > + writel(val, csr_base + BRIDGE_CTRL_5); > + > + val =3D readl(csr_base + BRIDGE_CTRL_2); > + val |=3D ENABLE_ASPM; > + writel(val, csr_base + BRIDGE_CTRL_2); > + > + val =3D readl(csr_base + BRIDGE_CFG_32); > + writel(val | (1 << 19), csr_base + BRIDGE_CFG_32); > +} > + > +/* Return 0 on success */ Comment is not very helpful, this is supposed to be the default behavio= ur in kernel code. > +static int xgene_pcie_init_ecc(struct xgene_pcie_port *port) > +{ > + void __iomem *csr_base =3D port->csr_base; > + ulong timeout; > + u32 val; > + > + val =3D readl(csr_base + MEM_RAM_SHUTDOWN); > + if (!val) > + return 0; > + writel(0x0, csr_base + MEM_RAM_SHUTDOWN); > + timeout =3D jiffies + msecs_to_jiffies(XGENE_PCIE_ECC_TIMEOUT= ); > + while (time_before(jiffies, timeout)) { > + val =3D readl(csr_base + BLOCK_MEM_RDY); > + if (val =3D=3D BLOCK_MEM_RDY_VAL) > + return 0; > + msleep(1); > + } > + Maybe add a comment here suggesting this is the error return. Better ye= t, use the kernel convention of returning negative numbers for errors and use one of the errno-base.h values. > + return 1; > +} > + > +static int xgene_pcie_init_port(struct xgene_pcie_port *port) > +{ > + int rc; > + > + port->clk =3D clk_get(port->dev, NULL); > + if (IS_ERR(port->clk)) { > + dev_err(port->dev, "clock not available\n"); > + return -ENODEV; > + } > + > + rc =3D clk_prepare_enable(port->clk); > + if (rc) { > + dev_err(port->dev, "clock enable failed\n"); > + return rc; > + } > + > + rc =3D xgene_pcie_init_ecc(port); > + if (rc) { > + dev_err(port->dev, "memory init failed\n"); > + return rc; > + } > + > + return 0; > +} > + > +static void xgene_pcie_fixup_bridge(struct pci_dev *dev) > +{ > + int i; > + > + /* Hide the PCI host BARs from the kernel as their content do= esn't > + * fit well in the resource management > + */ > + for (i =3D 0; i < DEVICE_COUNT_RESOURCE; i++) { > + dev->resource[i].start =3D dev->resource[i].end =3D 0= ; > + dev->resource[i].flags =3D 0; > + } > + dev_info(&dev->dev, "Hiding X-Gene pci host bridge resources = %s\n", > + pci_name(dev)); > +} > +DECLARE_PCI_FIXUP_HEADER(XGENE_PCIE_VENDORID, XGENE_PCIE_DEVICEID, > + xgene_pcie_fixup_bridge); > + > +static int xgene_pcie_map_reg(struct xgene_pcie_port *port, > + struct platform_device *pdev, u64 *cfg_= addr) > +{ > + struct resource *res; > + > + res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "c= sr"); > + port->csr_base =3D devm_ioremap_resource(port->dev, res); > + if (IS_ERR(port->csr_base)) > + return PTR_ERR(port->csr_base); > + > + res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "c= fg"); > + port->cfg_base =3D devm_ioremap_resource(port->dev, res); > + if (IS_ERR(port->cfg_base)) > + return PTR_ERR(port->cfg_base); > + *cfg_addr =3D res->start; > + > + return 0; > +} > + > +static void xgene_pcie_setup_ob_reg(struct xgene_pcie_port *port, > + struct resource *res, u32 offset,= u64 addr) > +{ > + void __iomem *base =3D port->csr_base + offset; > + resource_size_t size =3D resource_size(res); > + u64 restype =3D resource_type(res); > + u64 cpu_addr, pci_addr; > + u64 mask =3D 0; > + u32 min_size; > + u32 flag =3D EN_REG; > + > + if (restype =3D=3D IORESOURCE_MEM) { > + cpu_addr =3D res->start; > + pci_addr =3D addr; > + min_size =3D SZ_128M; > + } else { > + cpu_addr =3D addr; > + pci_addr =3D res->start; > + min_size =3D 128; > + flag |=3D OB_LO_IO; > + } > + if (size >=3D min_size) > + mask =3D ~(size - 1) | flag; > + else > + dev_warn(port->dev, "res size 0x%llx less than minimu= m 0x%x\n", > + (u64)size, min_size); > + writel(lower_32_bits(cpu_addr), base); > + writel(upper_32_bits(cpu_addr), base + 0x04); > + writel(lower_32_bits(mask), base + 0x08); > + writel(upper_32_bits(mask), base + 0x0c); > + writel(lower_32_bits(pci_addr), base + 0x10); > + writel(upper_32_bits(pci_addr), base + 0x14); > +} > + > +static void xgene_pcie_setup_cfg_reg(void __iomem *csr_base, u64 add= r) > +{ > + writel(lower_32_bits(addr), csr_base + CFGBARL); > + writel(upper_32_bits(addr), csr_base + CFGBARH); > + writel(EN_REG, csr_base + CFGCTL); > +} > + > +static int xgene_pcie_map_ranges(struct xgene_pcie_port *port, > + struct pci_host_bridge *bridge, > + u64 cfg_addr) > +{ > + struct device *dev =3D port->dev; > + struct pci_host_bridge_window *window; > + int ret; > + > + list_for_each_entry(window, &bridge->windows, list) { > + struct resource *res =3D window->res; > + u64 restype =3D resource_type(res); > + dev_dbg(port->dev, "0x%08lx 0x%016llx...0x%016llx\n", > + res->flags, res->start, res->end); > + > + switch (restype) { > + case IORESOURCE_IO: > + xgene_pcie_setup_ob_reg(port, res, OMR2BARL, > + bridge->io_base); > + ret =3D pci_ioremap_io(res, bridge->io_base); > + if (ret < 0) > + return ret; > + break; > + case IORESOURCE_MEM: > + xgene_pcie_setup_ob_reg(port, res, OMR3BARL, > + res->start - window->= offset); > + break; > + case IORESOURCE_BUS: > + break; > + default: > + dev_err(dev, "invalid io resource!"); > + return -EINVAL; > + } > + } > + xgene_pcie_setup_cfg_reg(port->csr_base, cfg_addr); > + return 0; > +} > + > +static void xgene_pcie_setup_pims(void *addr, u64 pim, u64 size) > +{ > + writel(lower_32_bits(pim), addr); > + writel(upper_32_bits(pim) | EN_COHERENCY, addr + 0x04); > + writel(lower_32_bits(size), addr + 0x10); > + writel(upper_32_bits(size), addr + 0x14); > +} > + > +/* > + * X-Gene PCIe support maximum 3 inbound memory regions > + * This function helps to select a region based on size of region > + */ > +static int xgene_pcie_select_ib_reg(u8 *ib_reg_mask, u64 size) > +{ > + if ((size > 4) && (size < SZ_16M) && !(*ib_reg_mask & (1 << 1= ))) { > + *ib_reg_mask |=3D (1 << 1); > + return 1; > + } > + > + if ((size > SZ_1K) && (size < SZ_1T) && !(*ib_reg_mask & (1 <= < 0))) { > + *ib_reg_mask |=3D (1 << 0); > + return 0; > + } > + > + if ((size > SZ_1M) && (size < SZ_1T) && !(*ib_reg_mask & (1 <= < 2))) { > + *ib_reg_mask |=3D (1 << 2); > + return 2; > + } > + return -EINVAL; > +} > + > +static void xgene_pcie_setup_ib_reg(struct xgene_pcie_port *port, > + struct of_pci_range *range, u8 *i= b_reg_mask) > +{ > + void __iomem *csr_base =3D port->csr_base; > + void __iomem *cfg_base =3D port->cfg_base; > + void *bar_addr; > + void *pim_addr; > + u64 restype =3D range->flags & IORESOURCE_TYPE_BITS; > + u64 cpu_addr =3D range->cpu_addr; > + u64 pci_addr =3D range->pci_addr; > + u64 size =3D range->size; > + u64 mask =3D ~(size - 1) | EN_REG; > + u32 flags =3D PCI_BASE_ADDRESS_MEM_TYPE_64; > + u32 bar_low; > + int region; > + > + region =3D xgene_pcie_select_ib_reg(ib_reg_mask, range->size)= ; > + if (region < 0) { > + dev_warn(port->dev, "invalid pcie dma-range config\n"= ); > + return; > + } > + > + if (restype =3D=3D PCI_BASE_ADDRESS_MEM_PREFETCH) > + flags |=3D PCI_BASE_ADDRESS_MEM_PREFETCH; > + > + bar_low =3D pcie_bar_low_val((u32)cpu_addr, flags); > + switch (region) { > + case 0: > + xgene_pcie_set_ib_mask(csr_base, BRIDGE_CFG_4, flags,= size); > + bar_addr =3D cfg_base + PCI_BASE_ADDRESS_0; > + writel(bar_low, bar_addr); > + writel(upper_32_bits(cpu_addr), bar_addr + 0x4); > + pim_addr =3D csr_base + PIM1_1L; > + break; > + case 1: > + bar_addr =3D csr_base + IBAR2; > + writel(bar_low, bar_addr); > + writel(lower_32_bits(mask), csr_base + IR2MSK); > + pim_addr =3D csr_base + PIM2_1L; > + break; > + case 2: > + bar_addr =3D csr_base + IBAR3L; > + writel(bar_low, bar_addr); > + writel(upper_32_bits(cpu_addr), bar_addr + 0x4); > + writel(lower_32_bits(mask), csr_base + IR3MSKL); > + writel(upper_32_bits(mask), csr_base + IR3MSKL + 0x4)= ; > + pim_addr =3D csr_base + PIM3_1L; > + break; > + } > + > + xgene_pcie_setup_pims(pim_addr, pci_addr, size); > +} > + > +static int pci_dma_range_parser_init(struct of_pci_range_parser *par= ser, > + struct device_node *node) > +{ > + const int na =3D 3, ns =3D 2; > + int rlen; > + > + parser->node =3D node; > + parser->pna =3D of_n_addr_cells(node); > + parser->np =3D parser->pna + na + ns; > + > + parser->range =3D of_get_property(node, "dma-ranges", &rlen); > + if (!parser->range) > + return -ENOENT; > + > + parser->end =3D parser->range + rlen / sizeof(__be32); > + return 0; > +} > + > +static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *p= ort) > +{ > + struct device_node *np =3D port->node; > + struct of_pci_range range; > + struct of_pci_range_parser parser; > + struct device *dev =3D port->dev; > + u8 ib_reg_mask =3D 0; > + > + if (pci_dma_range_parser_init(&parser, np)) { > + dev_err(dev, "missing dma-ranges property\n"); > + return -EINVAL; > + } > + > + /* Get the dma-ranges from DT */ > + for_each_of_pci_range(&parser, &range) { > + u64 end =3D range.cpu_addr + range.size - 1; > + dev_dbg(port->dev, "0x%08x 0x%016llx..0x%016llx -> 0x= %016llx\n", > + range.flags, range.cpu_addr, end, range.pci_a= ddr); > + xgene_pcie_setup_ib_reg(port, &range, &ib_reg_mask); > + } > + return 0; > +} > + > +static int xgene_pcie_probe_bridge(struct platform_device *pdev) > +{ > + struct device_node *np =3D of_node_get(pdev->dev.of_node); > + struct xgene_pcie_port *port; > + struct pci_host_bridge *bridge; > + resource_size_t lastbus; > + u32 lanes =3D 0, speed =3D 0; > + u64 cfg_addr =3D 0; > + int ret; > + > + port =3D devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); > + if (!port) > + return -ENOMEM; > + port->node =3D np; > + port->dev =3D &pdev->dev; > + > + ret =3D xgene_pcie_map_reg(port, pdev, &cfg_addr); > + if (ret) > + return ret; > + > + ret =3D xgene_pcie_init_port(port); > + if (ret) > + return ret; > + xgene_pcie_program_core(port->csr_base); > + xgene_pcie_setup_root_complex(port); > + > + bridge =3D of_create_pci_host_bridge(&pdev->dev, &xgene_pcie_= ops, port); > + if (IS_ERR_OR_NULL(bridge)) If bridge is NULL (can't see how in my code, but anyway) > + return PTR_ERR(bridge); Then this will return zero (i.e. success). s/IS_ERR_OR_NULL/IS_ERR/g > + > + ret =3D xgene_pcie_map_ranges(port, bridge, cfg_addr); > + if (ret) > + return ret; > + > + ret =3D xgene_pcie_parse_map_dma_ranges(port); > + if (ret) > + return ret; > + > + xgene_pcie_poll_linkup(port, &lanes, &speed); > + if (!port->link_up) > + dev_info(port->dev, "(rc) link down\n"); > + else > + dev_info(port->dev, "(rc) x%d gen-%d link up\n", > + lanes, speed + 1); > + platform_set_drvdata(pdev, port); > + lastbus =3D pci_rescan_bus(bridge->bus); If you look in drivers/pci/probe.c *after* the definition of pci_rescan= _bus() there is a comment about the function needing to be guarded by pci_lock_rescan_remove() and pci_unlock_rescan_remove(). The only one d= oing it is drivers/pci/pci-sysfs.c, while s390 seems oblivious to it. > + pci_bus_update_busn_res_end(bridge->bus, lastbus); > + return 0; > +} > + > +static const struct of_device_id xgene_pcie_match_table[] =3D { > + {.compatible =3D "apm,xgene-pcie",}, > + {}, > +}; > + > +static struct platform_driver xgene_pcie_driver =3D { > + .driver =3D { > + .name =3D "xgene-pcie", > + .owner =3D THIS_MODULE, > + .of_match_table =3D of_match_ptr(xgene_pcie_match_= table), > + }, > + .probe =3D xgene_pcie_probe_bridge, > +}; > +module_platform_driver(xgene_pcie_driver); > + > +MODULE_AUTHOR("Tanmay Inamdar "); > +MODULE_DESCRIPTION("APM X-Gene PCIe driver"); > +MODULE_LICENSE("GPL v2"); > -- > 1.7.9.5 >=20 >=20 --=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- =C2=AF\_(=E3=83=84)_/=C2=AF