From patchwork Tue Jun 9 10:45:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurentiu Tudor X-Patchwork-Id: 241997 List-Id: U-Boot discussion From: laurentiu.tudor at nxp.com (laurentiu.tudor at nxp.com) Date: Tue, 9 Jun 2020 13:45:08 +0300 Subject: [PATCH 1/3] pci: layerscape: move per-pci device fdt fixup in a function In-Reply-To: <20200609104510.19781-1-laurentiu.tudor@nxp.com> References: <20200609104510.19781-1-laurentiu.tudor@nxp.com> Message-ID: <20200609104510.19781-2-laurentiu.tudor@nxp.com> From: Laurentiu Tudor Move the pci device related fdt fixup in a function in order to re-use it in a following patch. While at it, improve the error handling. Signed-off-by: Laurentiu Tudor --- drivers/pci/pcie_layerscape_fixup.c | 58 ++++++++++++++++------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c index 25a3c3870c..12ee5e3f20 100644 --- a/drivers/pci/pcie_layerscape_fixup.c +++ b/drivers/pci/pcie_layerscape_fixup.c @@ -167,12 +167,40 @@ static void fdt_pcie_set_iommu_map_entry_ls(void *blob, struct ls_pcie *pcie, } } +static int fdt_fixup_pcie_device_ls(void *blob, pci_dev_t bdf, + struct ls_pcie *pcie) +{ + int streamid, index; + + streamid = pcie_next_streamid(pcie->stream_id_cur, pcie->idx); + if (streamid < 0) { + printf("ERROR: out of stream ids for BDF %d.%d.%d\n", + PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf)); + return -ENOENT; + } + pcie->stream_id_cur++; + + index = ls_pcie_next_lut_index(pcie); + if (index < 0) { + printf("ERROR: out of LUT indexes for BDF %d.%d.%d\n", + PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf)); + return -ENOENT; + } + + /* map PCI b.d.f to streamID in LUT */ + ls_pcie_lut_set_mapping(pcie, index, bdf >> 8, streamid); + /* update msi-map in device tree */ + fdt_pcie_set_msi_map_entry_ls(blob, pcie, bdf >> 8, streamid); + /* update iommu-map in device tree */ + fdt_pcie_set_iommu_map_entry_ls(blob, pcie, bdf >> 8, streamid); + + return 0; +} + static void fdt_fixup_pcie_ls(void *blob) { struct udevice *dev, *bus; struct ls_pcie *pcie; - int streamid; - int index; pci_dev_t bdf; /* Scan all known buses */ @@ -183,31 +211,11 @@ static void fdt_fixup_pcie_ls(void *blob) bus = bus->parent; pcie = dev_get_priv(bus); - streamid = pcie_next_streamid(pcie->stream_id_cur, pcie->idx); - if (streamid < 0) { - debug("ERROR: no stream ids free\n"); - continue; - } else { - pcie->stream_id_cur++; - } - - index = ls_pcie_next_lut_index(pcie); - if (index < 0) { - debug("ERROR: no LUT indexes free\n"); - continue; - } - /* the DT fixup must be relative to the hose first_busno */ bdf = dm_pci_get_bdf(dev) - PCI_BDF(bus->seq, 0, 0); - /* map PCI b.d.f to streamID in LUT */ - ls_pcie_lut_set_mapping(pcie, index, bdf >> 8, - streamid); - /* update msi-map in device tree */ - fdt_pcie_set_msi_map_entry_ls(blob, pcie, bdf >> 8, - streamid); - /* update iommu-map in device tree */ - fdt_pcie_set_iommu_map_entry_ls(blob, pcie, bdf >> 8, - streamid); + + if (fdt_fixup_pcie_device_ls(blob, bdf, pcie) < 0) + break; } pcie_board_fix_fdt(blob); }