2018-01-27 01:50:27 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-11-22 23:14:41 +07:00
|
|
|
/*
|
2019-01-10 03:14:42 +07:00
|
|
|
* Simple, generic PCI host controller driver targeting firmware-initialised
|
2013-11-22 23:14:41 +07:00
|
|
|
* systems and virtual machines (e.g. the PCI emulation provided by kvmtool).
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 ARM Limited
|
|
|
|
*
|
|
|
|
* Author: Will Deacon <will.deacon@arm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2016-07-23 04:21:38 +07:00
|
|
|
#include <linux/init.h>
|
2013-11-22 23:14:41 +07:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_pci.h>
|
2016-06-11 02:55:09 +07:00
|
|
|
#include <linux/pci-ecam.h>
|
2013-11-22 23:14:41 +07:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2016-05-12 05:34:46 +07:00
|
|
|
static struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = {
|
2013-11-22 23:14:41 +07:00
|
|
|
.bus_shift = 16,
|
2016-05-12 05:34:46 +07:00
|
|
|
.pci_ops = {
|
|
|
|
.map_bus = pci_ecam_map_bus,
|
2015-10-08 22:15:10 +07:00
|
|
|
.read = pci_generic_config_read,
|
|
|
|
.write = pci_generic_config_write,
|
|
|
|
}
|
2013-11-22 23:14:41 +07:00
|
|
|
};
|
|
|
|
|
PCI: generic: Add support for Synopsys DesignWare RC in ECAM mode
Some implementations of the Synopsys DesignWare PCIe controller implement
a so-called ECAM shift mode, which allows a static memory window to be
configured that covers the configuration space of the entire bus range.
Usually, when the firmware performs all the low level configuration that is
required to expose this controller in a fully ECAM compatible manner, we
can simply describe it as "pci-host-ecam-generic" and be done with it.
However, in some cases (e.g., the Marvell Armada 80x0 as well as the
Socionext SynQuacer Soc), the IP was synthesized with an ATU window
granularity that does not allow the first bus to be mapped in a way that
prevents the device on the downstream port from appearing more than once,
and so we still need special handling in software to drive this static
almost-ECAM configuration.
So extend the pci-host-generic driver so it can support these controllers
as well, by adding special config space accessors that take the above quirk
into account.
Note that, unlike most drivers for this IP, this driver does not expose a
fake bridge device at B/D/F 00:00.0. There is no point in doing so, given
that this is not a true bridge, and does not require any windows to be
configured in order for the downstream device to operate correctly.
Omitting it also prevents the PCI resource allocation routines from handing
out BAR space to it unnecessarily.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
[bhelgaas: factor out pci_dw_valid_device(), add pci_dw_ecam_map_bus() and
use generic read/write functions]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Acked-by: Will Deacon <will.deacon@arm.com>
2017-10-06 23:39:18 +07:00
|
|
|
static bool pci_dw_valid_device(struct pci_bus *bus, unsigned int devfn)
|
|
|
|
{
|
|
|
|
struct pci_config_window *cfg = bus->sysdata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Synopsys DesignWare PCIe controller in ECAM mode will not filter
|
|
|
|
* type 0 config TLPs sent to devices 1 and up on its downstream port,
|
|
|
|
* resulting in devices appearing multiple times on bus 0 unless we
|
|
|
|
* filter out those accesses here.
|
|
|
|
*/
|
|
|
|
if (bus->number == cfg->busr.start && PCI_SLOT(devfn) > 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __iomem *pci_dw_ecam_map_bus(struct pci_bus *bus,
|
|
|
|
unsigned int devfn, int where)
|
|
|
|
{
|
|
|
|
if (!pci_dw_valid_device(bus, devfn))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pci_ecam_map_bus(bus, devfn, where);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_ecam_ops pci_dw_ecam_bus_ops = {
|
|
|
|
.bus_shift = 20,
|
|
|
|
.pci_ops = {
|
|
|
|
.map_bus = pci_dw_ecam_map_bus,
|
|
|
|
.read = pci_generic_config_read,
|
|
|
|
.write = pci_generic_config_write,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-22 23:14:41 +07:00
|
|
|
static const struct of_device_id gen_pci_of_match[] = {
|
|
|
|
{ .compatible = "pci-host-cam-generic",
|
|
|
|
.data = &gen_pci_cfg_cam_bus_ops },
|
|
|
|
|
|
|
|
{ .compatible = "pci-host-ecam-generic",
|
2016-05-12 05:34:46 +07:00
|
|
|
.data = &pci_generic_ecam_ops },
|
2013-11-22 23:14:41 +07:00
|
|
|
|
PCI: generic: Add support for Synopsys DesignWare RC in ECAM mode
Some implementations of the Synopsys DesignWare PCIe controller implement
a so-called ECAM shift mode, which allows a static memory window to be
configured that covers the configuration space of the entire bus range.
Usually, when the firmware performs all the low level configuration that is
required to expose this controller in a fully ECAM compatible manner, we
can simply describe it as "pci-host-ecam-generic" and be done with it.
However, in some cases (e.g., the Marvell Armada 80x0 as well as the
Socionext SynQuacer Soc), the IP was synthesized with an ATU window
granularity that does not allow the first bus to be mapped in a way that
prevents the device on the downstream port from appearing more than once,
and so we still need special handling in software to drive this static
almost-ECAM configuration.
So extend the pci-host-generic driver so it can support these controllers
as well, by adding special config space accessors that take the above quirk
into account.
Note that, unlike most drivers for this IP, this driver does not expose a
fake bridge device at B/D/F 00:00.0. There is no point in doing so, given
that this is not a true bridge, and does not require any windows to be
configured in order for the downstream device to operate correctly.
Omitting it also prevents the PCI resource allocation routines from handing
out BAR space to it unnecessarily.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
[bhelgaas: factor out pci_dw_valid_device(), add pci_dw_ecam_map_bus() and
use generic read/write functions]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Acked-by: Will Deacon <will.deacon@arm.com>
2017-10-06 23:39:18 +07:00
|
|
|
{ .compatible = "marvell,armada8k-pcie-ecam",
|
|
|
|
.data = &pci_dw_ecam_bus_ops },
|
|
|
|
|
|
|
|
{ .compatible = "socionext,synquacer-pcie-ecam",
|
|
|
|
.data = &pci_dw_ecam_bus_ops },
|
|
|
|
|
|
|
|
{ .compatible = "snps,dw-pcie-ecam",
|
|
|
|
.data = &pci_dw_ecam_bus_ops },
|
|
|
|
|
2013-11-22 23:14:41 +07:00
|
|
|
{ },
|
|
|
|
};
|
2016-05-12 05:34:46 +07:00
|
|
|
|
2016-03-12 04:25:13 +07:00
|
|
|
static int gen_pci_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
const struct of_device_id *of_id;
|
2016-05-12 05:34:46 +07:00
|
|
|
struct pci_ecam_ops *ops;
|
2016-03-12 04:25:13 +07:00
|
|
|
|
2016-05-12 05:34:46 +07:00
|
|
|
of_id = of_match_node(gen_pci_of_match, pdev->dev.of_node);
|
|
|
|
ops = (struct pci_ecam_ops *)of_id->data;
|
2016-03-12 04:25:13 +07:00
|
|
|
|
2016-05-12 05:34:46 +07:00
|
|
|
return pci_host_common_probe(pdev, ops);
|
2016-03-12 04:25:13 +07:00
|
|
|
}
|
|
|
|
|
2013-11-22 23:14:41 +07:00
|
|
|
static struct platform_driver gen_pci_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "pci-host-generic",
|
|
|
|
.of_match_table = gen_pci_of_match,
|
2017-04-21 03:36:25 +07:00
|
|
|
.suppress_bind_attrs = true,
|
2013-11-22 23:14:41 +07:00
|
|
|
},
|
|
|
|
.probe = gen_pci_probe,
|
2018-05-15 16:07:06 +07:00
|
|
|
.remove = pci_host_common_remove,
|
2013-11-22 23:14:41 +07:00
|
|
|
};
|
2016-07-23 04:21:38 +07:00
|
|
|
builtin_platform_driver(gen_pci_driver);
|