* [PATCH] drivers: pci: host: ftpci100: Remove pre-scan bus dependency
@ 2017-06-21 16:26 Linus Walleij
2017-06-27 22:20 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2017-06-21 16:26 UTC (permalink / raw)
To: Bjorn Helgaas, Lorenzo Pieralisi, linux-pci
Cc: Hans Ulli Kroll, Florian Fainelli, Linus Walleij
From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Remove leftover pci_bus dependencies from the probe path.
We were digging around in config space before the bus was
up so we need to use a few raw accessors and avoid storing
things in the bus structure until the host is initialized.
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
This patch on top of Lorenzo's patch series make everything
work fine for me.
---
drivers/pci/host/pci-ftpci100.c | 53 +++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/drivers/pci/host/pci-ftpci100.c b/drivers/pci/host/pci-ftpci100.c
index db31ab21884e..5162dffc102b 100644
--- a/drivers/pci/host/pci-ftpci100.c
+++ b/drivers/pci/host/pci-ftpci100.c
@@ -183,12 +183,11 @@ static int faraday_res_to_memcfg(resource_size_t mem_base,
return 0;
}
-static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn,
- int config, int size, u32 *value)
+static int faraday_raw_pci_read_config(struct faraday_pci *p, int bus_number,
+ unsigned int fn, int config, int size,
+ u32 *value)
{
- struct faraday_pci *p = bus->sysdata;
-
- writel(PCI_CONF_BUS(bus->number) |
+ writel(PCI_CONF_BUS(bus_number) |
PCI_CONF_DEVICE(PCI_SLOT(fn)) |
PCI_CONF_FUNCTION(PCI_FUNC(fn)) |
PCI_CONF_WHERE(config) |
@@ -202,11 +201,19 @@ static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn,
else if (size == 2)
*value = (*value >> (8 * (config & 3))) & 0xFFFF;
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn,
+ int config, int size, u32 *value)
+{
+ struct faraday_pci *p = bus->sysdata;
+
dev_dbg(&bus->dev,
"[read] slt: %.2d, fnc: %d, cnf: 0x%.2X, val (%d bytes): 0x%.8X\n",
PCI_SLOT(fn), PCI_FUNC(fn), config, size, *value);
- return PCIBIOS_SUCCESSFUL;
+ return faraday_raw_pci_read_config(p, bus->number, fn, config, size, value);
}
static int faraday_raw_pci_write_config(struct faraday_pci *p, int bus_number,
@@ -262,10 +269,10 @@ static void faraday_pci_ack_irq(struct irq_data *d)
struct faraday_pci *p = irq_data_get_irq_chip_data(d);
unsigned int reg;
- faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
+ faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
reg &= ~(0xF << PCI_CTRL2_INTSTS_SHIFT);
reg |= BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTSTS_SHIFT);
- faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg);
+ faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg);
}
static void faraday_pci_mask_irq(struct irq_data *d)
@@ -273,10 +280,10 @@ static void faraday_pci_mask_irq(struct irq_data *d)
struct faraday_pci *p = irq_data_get_irq_chip_data(d);
unsigned int reg;
- faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
+ faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
reg &= ~((0xF << PCI_CTRL2_INTSTS_SHIFT)
| BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTMASK_SHIFT));
- faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg);
+ faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg);
}
static void faraday_pci_unmask_irq(struct irq_data *d)
@@ -284,10 +291,10 @@ static void faraday_pci_unmask_irq(struct irq_data *d)
struct faraday_pci *p = irq_data_get_irq_chip_data(d);
unsigned int reg;
- faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
+ faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
reg &= ~(0xF << PCI_CTRL2_INTSTS_SHIFT);
reg |= BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTMASK_SHIFT);
- faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg);
+ faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg);
}
static void faraday_pci_irq_handler(struct irq_desc *desc)
@@ -296,7 +303,7 @@ static void faraday_pci_irq_handler(struct irq_desc *desc)
struct irq_chip *irqchip = irq_desc_get_chip(desc);
unsigned int irq_stat, reg, i;
- faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
+ faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
irq_stat = reg >> PCI_CTRL2_INTSTS_SHIFT;
chained_irq_enter(irqchip, desc);
@@ -417,8 +424,8 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
dev_info(dev, "DMA MEM%d BASE: 0x%016llx -> 0x%016llx config %08x\n",
i + 1, range.pci_addr, end, val);
if (i <= 2) {
- faraday_pci_write_config(p->bus, 0, confreg[i],
- 4, val);
+ faraday_raw_pci_write_config(p, 0, 0, confreg[i],
+ 4, val);
} else {
dev_err(dev, "ignore extraneous dma-range %d\n", i);
break;
@@ -443,6 +450,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
struct resource *io;
struct pci_host_bridge *host;
struct clk *clk;
+ unsigned char max_bus_speed = PCI_SPEED_33MHz;
+ unsigned char cur_bus_speed = PCI_SPEED_33MHz;
int ret;
u32 val;
LIST_HEAD(res);
@@ -546,27 +555,27 @@ static int faraday_pci_probe(struct platform_device *pdev)
unsigned long rate;
u32 val;
- faraday_pci_read_config(p->bus, 0,
- FARADAY_PCI_STATUS_CMD, 4, &val);
+ faraday_raw_pci_read_config(p, 0, 0,
+ FARADAY_PCI_STATUS_CMD, 4, &val);
rate = clk_get_rate(p->bus_clk);
if ((rate == 33000000) && (val & PCI_STATUS_66MHZ_CAPABLE)) {
dev_info(dev, "33MHz bus is 66MHz capable\n");
- p->bus->max_bus_speed = PCI_SPEED_66MHz;
+ max_bus_speed = PCI_SPEED_66MHz;
ret = clk_set_rate(p->bus_clk, 66000000);
if (ret)
dev_err(dev, "failed to set bus clock\n");
} else {
dev_info(dev, "33MHz only bus\n");
- p->bus->max_bus_speed = PCI_SPEED_33MHz;
+ max_bus_speed = PCI_SPEED_33MHz;
}
/* Bumping the clock may fail so read back the rate */
rate = clk_get_rate(p->bus_clk);
if (rate == 33000000)
- p->bus->cur_bus_speed = PCI_SPEED_33MHz;
+ cur_bus_speed = PCI_SPEED_33MHz;
if (rate == 66000000)
- p->bus->cur_bus_speed = PCI_SPEED_66MHz;
+ cur_bus_speed = PCI_SPEED_66MHz;
}
ret = faraday_pci_parse_map_dma_ranges(p, dev->of_node);
@@ -580,6 +589,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
return ret;
}
p->bus = host->bus;
+ p->bus->max_bus_speed = max_bus_speed;
+ p->bus->cur_bus_speed = cur_bus_speed;
pci_bus_assign_resources(p->bus);
pci_bus_add_devices(p->bus);
--
2.9.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drivers: pci: host: ftpci100: Remove pre-scan bus dependency
2017-06-21 16:26 [PATCH] drivers: pci: host: ftpci100: Remove pre-scan bus dependency Linus Walleij
@ 2017-06-27 22:20 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2017-06-27 22:20 UTC (permalink / raw)
To: Linus Walleij
Cc: Bjorn Helgaas, Lorenzo Pieralisi, linux-pci, Hans Ulli Kroll,
Florian Fainelli
On Wed, Jun 21, 2017 at 06:26:51PM +0200, Linus Walleij wrote:
> From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>
> Remove leftover pci_bus dependencies from the probe path.
>
> We were digging around in config space before the bus was
> up so we need to use a few raw accessors and avoid storing
> things in the bus structure until the host is initialized.
>
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Tested-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Thanks for helping untangle all this, Linus.
I split this into two parts:
1) the faraday_raw_pci_read_config() stuff, which I folded into the
"PCI: faraday: Convert IRQ masking to raw PCI config accessors"
patch from Lorenzo's series.
2) the bus max/cur clock speed setting, which I folded into the
"PCI: faraday: Add clock handling" patch that you posted earlier.
I rebased pci/host-faraday on top of pci/enumeration, so I *think*
pci/host-faraday should have everything I know about for the FTPCI100.
Can you double-check it?
https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/commit/?h=pci/host-faraday&id=2e7062416fdff640c5f2ee488690fc5af4b927ff
I'm still hoping to get this all in v4.13.
> ---
> This patch on top of Lorenzo's patch series make everything
> work fine for me.
> ---
> drivers/pci/host/pci-ftpci100.c | 53 +++++++++++++++++++++++++----------------
> 1 file changed, 32 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/pci/host/pci-ftpci100.c b/drivers/pci/host/pci-ftpci100.c
> index db31ab21884e..5162dffc102b 100644
> --- a/drivers/pci/host/pci-ftpci100.c
> +++ b/drivers/pci/host/pci-ftpci100.c
> @@ -183,12 +183,11 @@ static int faraday_res_to_memcfg(resource_size_t mem_base,
> return 0;
> }
>
> -static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn,
> - int config, int size, u32 *value)
> +static int faraday_raw_pci_read_config(struct faraday_pci *p, int bus_number,
> + unsigned int fn, int config, int size,
> + u32 *value)
> {
> - struct faraday_pci *p = bus->sysdata;
> -
> - writel(PCI_CONF_BUS(bus->number) |
> + writel(PCI_CONF_BUS(bus_number) |
> PCI_CONF_DEVICE(PCI_SLOT(fn)) |
> PCI_CONF_FUNCTION(PCI_FUNC(fn)) |
> PCI_CONF_WHERE(config) |
> @@ -202,11 +201,19 @@ static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn,
> else if (size == 2)
> *value = (*value >> (8 * (config & 3))) & 0xFFFF;
>
> + return PCIBIOS_SUCCESSFUL;
> +}
> +
> +static int faraday_pci_read_config(struct pci_bus *bus, unsigned int fn,
> + int config, int size, u32 *value)
> +{
> + struct faraday_pci *p = bus->sysdata;
> +
> dev_dbg(&bus->dev,
> "[read] slt: %.2d, fnc: %d, cnf: 0x%.2X, val (%d bytes): 0x%.8X\n",
> PCI_SLOT(fn), PCI_FUNC(fn), config, size, *value);
>
> - return PCIBIOS_SUCCESSFUL;
> + return faraday_raw_pci_read_config(p, bus->number, fn, config, size, value);
> }
>
> static int faraday_raw_pci_write_config(struct faraday_pci *p, int bus_number,
> @@ -262,10 +269,10 @@ static void faraday_pci_ack_irq(struct irq_data *d)
> struct faraday_pci *p = irq_data_get_irq_chip_data(d);
> unsigned int reg;
>
> - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
> + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
> reg &= ~(0xF << PCI_CTRL2_INTSTS_SHIFT);
> reg |= BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTSTS_SHIFT);
> - faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg);
> + faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg);
> }
>
> static void faraday_pci_mask_irq(struct irq_data *d)
> @@ -273,10 +280,10 @@ static void faraday_pci_mask_irq(struct irq_data *d)
> struct faraday_pci *p = irq_data_get_irq_chip_data(d);
> unsigned int reg;
>
> - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
> + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
> reg &= ~((0xF << PCI_CTRL2_INTSTS_SHIFT)
> | BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTMASK_SHIFT));
> - faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg);
> + faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg);
> }
>
> static void faraday_pci_unmask_irq(struct irq_data *d)
> @@ -284,10 +291,10 @@ static void faraday_pci_unmask_irq(struct irq_data *d)
> struct faraday_pci *p = irq_data_get_irq_chip_data(d);
> unsigned int reg;
>
> - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
> + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
> reg &= ~(0xF << PCI_CTRL2_INTSTS_SHIFT);
> reg |= BIT(irqd_to_hwirq(d) + PCI_CTRL2_INTMASK_SHIFT);
> - faraday_pci_write_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, reg);
> + faraday_raw_pci_write_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, reg);
> }
>
> static void faraday_pci_irq_handler(struct irq_desc *desc)
> @@ -296,7 +303,7 @@ static void faraday_pci_irq_handler(struct irq_desc *desc)
> struct irq_chip *irqchip = irq_desc_get_chip(desc);
> unsigned int irq_stat, reg, i;
>
> - faraday_pci_read_config(p->bus, 0, FARADAY_PCI_CTRL2, 4, ®);
> + faraday_raw_pci_read_config(p, 0, 0, FARADAY_PCI_CTRL2, 4, ®);
> irq_stat = reg >> PCI_CTRL2_INTSTS_SHIFT;
>
> chained_irq_enter(irqchip, desc);
> @@ -417,8 +424,8 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
> dev_info(dev, "DMA MEM%d BASE: 0x%016llx -> 0x%016llx config %08x\n",
> i + 1, range.pci_addr, end, val);
> if (i <= 2) {
> - faraday_pci_write_config(p->bus, 0, confreg[i],
> - 4, val);
> + faraday_raw_pci_write_config(p, 0, 0, confreg[i],
> + 4, val);
> } else {
> dev_err(dev, "ignore extraneous dma-range %d\n", i);
> break;
> @@ -443,6 +450,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> struct resource *io;
> struct pci_host_bridge *host;
> struct clk *clk;
> + unsigned char max_bus_speed = PCI_SPEED_33MHz;
> + unsigned char cur_bus_speed = PCI_SPEED_33MHz;
> int ret;
> u32 val;
> LIST_HEAD(res);
> @@ -546,27 +555,27 @@ static int faraday_pci_probe(struct platform_device *pdev)
> unsigned long rate;
> u32 val;
>
> - faraday_pci_read_config(p->bus, 0,
> - FARADAY_PCI_STATUS_CMD, 4, &val);
> + faraday_raw_pci_read_config(p, 0, 0,
> + FARADAY_PCI_STATUS_CMD, 4, &val);
> rate = clk_get_rate(p->bus_clk);
>
> if ((rate == 33000000) && (val & PCI_STATUS_66MHZ_CAPABLE)) {
> dev_info(dev, "33MHz bus is 66MHz capable\n");
> - p->bus->max_bus_speed = PCI_SPEED_66MHz;
> + max_bus_speed = PCI_SPEED_66MHz;
> ret = clk_set_rate(p->bus_clk, 66000000);
> if (ret)
> dev_err(dev, "failed to set bus clock\n");
> } else {
> dev_info(dev, "33MHz only bus\n");
> - p->bus->max_bus_speed = PCI_SPEED_33MHz;
> + max_bus_speed = PCI_SPEED_33MHz;
> }
>
> /* Bumping the clock may fail so read back the rate */
> rate = clk_get_rate(p->bus_clk);
> if (rate == 33000000)
> - p->bus->cur_bus_speed = PCI_SPEED_33MHz;
> + cur_bus_speed = PCI_SPEED_33MHz;
> if (rate == 66000000)
> - p->bus->cur_bus_speed = PCI_SPEED_66MHz;
> + cur_bus_speed = PCI_SPEED_66MHz;
> }
>
> ret = faraday_pci_parse_map_dma_ranges(p, dev->of_node);
> @@ -580,6 +589,8 @@ static int faraday_pci_probe(struct platform_device *pdev)
> return ret;
> }
> p->bus = host->bus;
> + p->bus->max_bus_speed = max_bus_speed;
> + p->bus->cur_bus_speed = cur_bus_speed;
>
> pci_bus_assign_resources(p->bus);
> pci_bus_add_devices(p->bus);
> --
> 2.9.4
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-06-27 22:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-21 16:26 [PATCH] drivers: pci: host: ftpci100: Remove pre-scan bus dependency Linus Walleij
2017-06-27 22:20 ` Bjorn Helgaas
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.