Re: [PATCH v3 5/9] pci: pcie_dw_rockchip: Hide BARs of the root complex
Hi Kever, On 2023-07-19 10:20, Kever Yang wrote: > Hi Jonas, > > Pls check if below patch available for you: > > https://patchwork.ozlabs.org/project/uboot/patch/20230719081749.976334-1-kever.y...@rock-chips.com/ That works great and is much cleaner, thanks! I had to rework the patch a little bit for it to apply with other changes in this series. See https://github.com/Kwiboo/u-boot-rockchip/commit/0e0bbc8edecff356e6b0ae33912393b26de3dad1 Should I send a v4 series with above patch included? Regards, Jonas > > > Thanks, > > - Kever > > On 2023/7/18 15:55, Jonas Karlman wrote: >> PCI Autoconfig read the Root Complex BARs and try to claim the entire >> 1 GiB memory region on RK3568, leaving no space for any attached device. >> >> With a memory region less than 1 GiB this was not a real issue: >> >>PCI Autoconfig: Bus Memory region: [0-3eef], >>PCI Autoconfig: Bus I/O region: [3ef0-3eff], >>PCI Autoconfig: Found P2P bridge, device 0 >>PCI Autoconfig: BAR 0, Mem, size=0x4000, No room in resource, avail >> start=1000 / size=3ef0, need=4000 >>PCI: Failed autoconfig bar 10 >>PCI Autoconfig: BAR 1, Mem, size=0x4000, No room in resource, avail >> start=1000 / size=3ef0, need=4000 >>PCI: Failed autoconfig bar 14 >>PCI Autoconfig: ROM, size=0x1, address=0x1 bus_lower=0x2 >> >>PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x10 >> bus_lower=0x104000 >> >> With a memory region of the entire 1 GiB this leads to: >> >>PCI Autoconfig: Bus Memory region: [4000-7fff], >>PCI Autoconfig: Bus I/O region: [f010-f01f], >>PCI Autoconfig: Found P2P bridge, device 0 >>PCI Autoconfig: BAR 0, Mem, size=0x4000, address=0x4000 >> bus_lower=0x8000 >>PCI Autoconfig: BAR 1, Mem, size=0x4000, No room in resource, avail >> start=8000 / size=4000, need=4000 >>PCI: Failed autoconfig bar 14 >>PCI Autoconfig: ROM, size=0x1, No room in resource, avail >> start=8000 / size=4000, need=1 >> >>PCI Autoconfig: BAR 0, Mem64, size=0x4000, No room in resource, avail >> start=8000 / size=4000, need=4000 >>PCI: Failed autoconfig bar 10 >> >> After this change with a memory region of the entire 1 GiB: >> >>PCI Autoconfig: Bus Memory region: [4000-7fff], >>PCI Autoconfig: Bus I/O region: [f010-f01f], >>PCI Autoconfig: Found P2P bridge, device 0 >>PCI Autoconfig: ROM, size=0x1, address=0x4000 bus_lower=0x4001 >> >>PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x4010 >> bus_lower=0x40104000 >> >> Return an invalid value during config read of Root Complex BARs during >> autoconfig to work around such issue. >> >> Signed-off-by: Jonas Karlman [...]
Re: [PATCH v3 5/9] pci: pcie_dw_rockchip: Hide BARs of the root complex
Hi Jonas, Pls check if below patch available for you: https://patchwork.ozlabs.org/project/uboot/patch/20230719081749.976334-1-kever.y...@rock-chips.com/ Thanks, - Kever On 2023/7/18 15:55, Jonas Karlman wrote: PCI Autoconfig read the Root Complex BARs and try to claim the entire 1 GiB memory region on RK3568, leaving no space for any attached device. With a memory region less than 1 GiB this was not a real issue: PCI Autoconfig: Bus Memory region: [0-3eef], PCI Autoconfig: Bus I/O region: [3ef0-3eff], PCI Autoconfig: Found P2P bridge, device 0 PCI Autoconfig: BAR 0, Mem, size=0x4000, No room in resource, avail start=1000 / size=3ef0, need=4000 PCI: Failed autoconfig bar 10 PCI Autoconfig: BAR 1, Mem, size=0x4000, No room in resource, avail start=1000 / size=3ef0, need=4000 PCI: Failed autoconfig bar 14 PCI Autoconfig: ROM, size=0x1, address=0x1 bus_lower=0x2 PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x10 bus_lower=0x104000 With a memory region of the entire 1 GiB this leads to: PCI Autoconfig: Bus Memory region: [4000-7fff], PCI Autoconfig: Bus I/O region: [f010-f01f], PCI Autoconfig: Found P2P bridge, device 0 PCI Autoconfig: BAR 0, Mem, size=0x4000, address=0x4000 bus_lower=0x8000 PCI Autoconfig: BAR 1, Mem, size=0x4000, No room in resource, avail start=8000 / size=4000, need=4000 PCI: Failed autoconfig bar 14 PCI Autoconfig: ROM, size=0x1, No room in resource, avail start=8000 / size=4000, need=1 PCI Autoconfig: BAR 0, Mem64, size=0x4000, No room in resource, avail start=8000 / size=4000, need=4000 PCI: Failed autoconfig bar 10 After this change with a memory region of the entire 1 GiB: PCI Autoconfig: Bus Memory region: [4000-7fff], PCI Autoconfig: Bus I/O region: [f010-f01f], PCI Autoconfig: Found P2P bridge, device 0 PCI Autoconfig: ROM, size=0x1, address=0x4000 bus_lower=0x4001 PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x4010 bus_lower=0x40104000 Return an invalid value during config read of Root Complex BARs during autoconfig to work around such issue. Signed-off-by: Jonas Karlman --- v3: - No change v2: - Update commit message drivers/pci/pcie_dw_rockchip.c | 28 +++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c index 82a8b9c96e2b..f56773c2e58c 100644 --- a/drivers/pci/pcie_dw_rockchip.c +++ b/drivers/pci/pcie_dw_rockchip.c @@ -146,6 +146,32 @@ static inline void rk_pcie_writel_apb(struct rk_pcie *rk_pcie, u32 reg, __rk_pcie_write_apb(rk_pcie, rk_pcie->apb_base, reg, 0x4, val); } +/** + * The BARs of bridge should be hidden during enumeration to avoid + * allocation of the entire memory region by PCIe core on RK3568. + */ +static bool rk_pcie_hide_rc_bar(struct pcie_dw *pcie, pci_dev_t bdf, + uint offset) +{ + int bus = PCI_BUS(bdf) - pcie->first_busno; + + return bus == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 && + offset >= PCI_BASE_ADDRESS_0 && offset <= PCI_BASE_ADDRESS_1; +} + +static int rk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, + uint offset, ulong *valuep, + enum pci_size_t size) +{ + struct pcie_dw *pcie = dev_get_priv(bus); + int ret = pcie_dw_read_config(bus, bdf, offset, valuep, size); + + if (!ret && rk_pcie_hide_rc_bar(pcie, bdf, offset)) + *valuep = pci_get_ff(size); + + return ret; +} + /** * rk_pcie_configure() - Configure link capabilities and speed * @@ -476,7 +502,7 @@ rockchip_pcie_probe_err_init_port: } static const struct dm_pci_ops rockchip_pcie_ops = { - .read_config= pcie_dw_read_config, + .read_config= rk_pcie_read_config, .write_config = pcie_dw_write_config, };
[PATCH v3 5/9] pci: pcie_dw_rockchip: Hide BARs of the root complex
PCI Autoconfig read the Root Complex BARs and try to claim the entire 1 GiB memory region on RK3568, leaving no space for any attached device. With a memory region less than 1 GiB this was not a real issue: PCI Autoconfig: Bus Memory region: [0-3eef], PCI Autoconfig: Bus I/O region: [3ef0-3eff], PCI Autoconfig: Found P2P bridge, device 0 PCI Autoconfig: BAR 0, Mem, size=0x4000, No room in resource, avail start=1000 / size=3ef0, need=4000 PCI: Failed autoconfig bar 10 PCI Autoconfig: BAR 1, Mem, size=0x4000, No room in resource, avail start=1000 / size=3ef0, need=4000 PCI: Failed autoconfig bar 14 PCI Autoconfig: ROM, size=0x1, address=0x1 bus_lower=0x2 PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x10 bus_lower=0x104000 With a memory region of the entire 1 GiB this leads to: PCI Autoconfig: Bus Memory region: [4000-7fff], PCI Autoconfig: Bus I/O region: [f010-f01f], PCI Autoconfig: Found P2P bridge, device 0 PCI Autoconfig: BAR 0, Mem, size=0x4000, address=0x4000 bus_lower=0x8000 PCI Autoconfig: BAR 1, Mem, size=0x4000, No room in resource, avail start=8000 / size=4000, need=4000 PCI: Failed autoconfig bar 14 PCI Autoconfig: ROM, size=0x1, No room in resource, avail start=8000 / size=4000, need=1 PCI Autoconfig: BAR 0, Mem64, size=0x4000, No room in resource, avail start=8000 / size=4000, need=4000 PCI: Failed autoconfig bar 10 After this change with a memory region of the entire 1 GiB: PCI Autoconfig: Bus Memory region: [4000-7fff], PCI Autoconfig: Bus I/O region: [f010-f01f], PCI Autoconfig: Found P2P bridge, device 0 PCI Autoconfig: ROM, size=0x1, address=0x4000 bus_lower=0x4001 PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x4010 bus_lower=0x40104000 Return an invalid value during config read of Root Complex BARs during autoconfig to work around such issue. Signed-off-by: Jonas Karlman --- v3: - No change v2: - Update commit message drivers/pci/pcie_dw_rockchip.c | 28 +++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c index 82a8b9c96e2b..f56773c2e58c 100644 --- a/drivers/pci/pcie_dw_rockchip.c +++ b/drivers/pci/pcie_dw_rockchip.c @@ -146,6 +146,32 @@ static inline void rk_pcie_writel_apb(struct rk_pcie *rk_pcie, u32 reg, __rk_pcie_write_apb(rk_pcie, rk_pcie->apb_base, reg, 0x4, val); } +/** + * The BARs of bridge should be hidden during enumeration to avoid + * allocation of the entire memory region by PCIe core on RK3568. + */ +static bool rk_pcie_hide_rc_bar(struct pcie_dw *pcie, pci_dev_t bdf, + uint offset) +{ + int bus = PCI_BUS(bdf) - pcie->first_busno; + + return bus == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 && + offset >= PCI_BASE_ADDRESS_0 && offset <= PCI_BASE_ADDRESS_1; +} + +static int rk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, + uint offset, ulong *valuep, + enum pci_size_t size) +{ + struct pcie_dw *pcie = dev_get_priv(bus); + int ret = pcie_dw_read_config(bus, bdf, offset, valuep, size); + + if (!ret && rk_pcie_hide_rc_bar(pcie, bdf, offset)) + *valuep = pci_get_ff(size); + + return ret; +} + /** * rk_pcie_configure() - Configure link capabilities and speed * @@ -476,7 +502,7 @@ rockchip_pcie_probe_err_init_port: } static const struct dm_pci_ops rockchip_pcie_ops = { - .read_config= pcie_dw_read_config, + .read_config= rk_pcie_read_config, .write_config = pcie_dw_write_config, }; -- 2.41.0