All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pci-host-ecam-generic: access config space independent of system-wide bus id
@ 2020-03-13 11:04 Vladimir Oltean
  2020-03-13 11:21 ` Alexandru Marginean
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Oltean @ 2020-03-13 11:04 UTC (permalink / raw)
  To: u-boot

From: Vladimir Oltean <vladimir.oltean@nxp.com>

The pci-host-ecam-generic code assumes that the ECAM is the first PCI
bus in the system to be probed. Therefore, the system-wide bus number
allocated by U-Boot in sequence for it is going to be zero, which
corresponds to the memory-mapped config spaces found within it.

Reuse the logic from other PCI bus drivers, and assume that U-Boot will
allocate bus numbers in sequence for all buses within the current ECAM.
So the base number of the bus needs to be subtracted when indexing the
correct config space.

Fixes: 3675cb044e68 ("PCI: Add driver for a 'pci-host-ecam-generic' host controller")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/pci/pcie_ecam_generic.c | 36 +++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pcie_ecam_generic.c b/drivers/pci/pcie_ecam_generic.c
index 00644edd2646..190919d26a67 100644
--- a/drivers/pci/pcie_ecam_generic.c
+++ b/drivers/pci/pcie_ecam_generic.c
@@ -19,6 +19,8 @@
  */
 struct generic_ecam_pcie {
 	void *cfg_base;
+	pci_size_t size;
+	int first_busno;
 };
 
 /**
@@ -42,7 +44,7 @@ static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf,
 	void *addr;
 
 	addr = pcie->cfg_base;
-	addr += PCI_BUS(bdf) << 20;
+	addr += (PCI_BUS(bdf) - pcie->first_busno) << 20;
 	addr += PCI_DEV(bdf) << 15;
 	addr += PCI_FUNC(bdf) << 12;
 	addr += offset;
@@ -51,6 +53,15 @@ static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf,
 	return 0;
 }
 
+static bool pci_generic_ecam_addr_valid(struct udevice *bus, pci_dev_t bdf)
+{
+	struct generic_ecam_pcie *pcie = dev_get_priv(bus);
+	int num_buses = DIV_ROUND_UP(pcie->size, 1 << 16);
+
+	return (PCI_BUS(bdf) >= pcie->first_busno &&
+		PCI_BUS(bdf) < pcie->first_busno + num_buses);
+}
+
 /**
  * pci_generic_ecam_read_config() - Read from configuration space
  * @bus: Pointer to the PCI bus
@@ -67,6 +78,11 @@ static int pci_generic_ecam_read_config(struct udevice *bus, pci_dev_t bdf,
 				   uint offset, ulong *valuep,
 				   enum pci_size_t size)
 {
+	if (!pci_generic_ecam_addr_valid(bus, bdf)) {
+		*valuep = pci_get_ff(size);
+		return 0;
+	}
+
 	return pci_generic_mmap_read_config(bus, pci_generic_ecam_conf_address,
 					    bdf, offset, valuep, size);
 }
@@ -87,6 +103,9 @@ static int pci_generic_ecam_write_config(struct udevice *bus, pci_dev_t bdf,
 				    uint offset, ulong value,
 				    enum pci_size_t size)
 {
+	if (!pci_generic_ecam_addr_valid(bus, bdf))
+		return 0;
+
 	return pci_generic_mmap_write_config(bus, pci_generic_ecam_conf_address,
 					     bdf, offset, value, size);
 }
@@ -115,9 +134,17 @@ static int pci_generic_ecam_ofdata_to_platdata(struct udevice *dev)
 		return err;
 	}
 
-	pcie->cfg_base = map_physmem(reg_res.start,
-				     fdt_resource_size(&reg_res),
-				     MAP_NOCACHE);
+	pcie->size = fdt_resource_size(&reg_res);
+	pcie->cfg_base = map_physmem(reg_res.start, pcie->size, MAP_NOCACHE);
+
+	return 0;
+}
+
+static int pci_generic_ecam_probe(struct udevice *dev)
+{
+	struct generic_ecam_pcie *pcie = dev_get_priv(dev);
+
+	pcie->first_busno = dev->seq;
 
 	return 0;
 }
@@ -137,6 +164,7 @@ U_BOOT_DRIVER(pci_generic_ecam) = {
 	.id			= UCLASS_PCI,
 	.of_match		= pci_generic_ecam_ids,
 	.ops			= &pci_generic_ecam_ops,
+	.probe			= pci_generic_ecam_probe,
 	.ofdata_to_platdata	= pci_generic_ecam_ofdata_to_platdata,
 	.priv_auto_alloc_size	= sizeof(struct generic_ecam_pcie),
 };
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] pci-host-ecam-generic: access config space independent of system-wide bus id
  2020-03-13 11:04 [PATCH] pci-host-ecam-generic: access config space independent of system-wide bus id Vladimir Oltean
@ 2020-03-13 11:21 ` Alexandru Marginean
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandru Marginean @ 2020-03-13 11:21 UTC (permalink / raw)
  To: u-boot

On 3/13/2020 12:04 PM, Vladimir Oltean wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
> 
> The pci-host-ecam-generic code assumes that the ECAM is the first PCI
> bus in the system to be probed. Therefore, the system-wide bus number
> allocated by U-Boot in sequence for it is going to be zero, which
> corresponds to the memory-mapped config spaces found within it.
> 
> Reuse the logic from other PCI bus drivers, and assume that U-Boot will
> allocate bus numbers in sequence for all buses within the current ECAM.
> So the base number of the bus needs to be subtracted when indexing the
> correct config space.
> 
> Fixes: 3675cb044e68 ("PCI: Add driver for a 'pci-host-ecam-generic' host controller")
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
>   drivers/pci/pcie_ecam_generic.c | 36 +++++++++++++++++++++++++++++----
>   1 file changed, 32 insertions(+), 4 deletions(-)
> 

Reviewed-by: Alex Marginean <alexandru.marginean@nxp.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-13 11:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 11:04 [PATCH] pci-host-ecam-generic: access config space independent of system-wide bus id Vladimir Oltean
2020-03-13 11:21 ` Alexandru Marginean

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.