Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: iproc: Convert PCI scan API to pci_scan_root_bus_bridge()

The introduction of pci_scan_root_bus_bridge() provides a PCI core API to
scan a PCI root bus backed by an already initialized struct pci_host_bridge
object, which simplifies the bus scan interface and makes the PCI scan root
bus interface easier to generalize as members are added to the struct
pci_host_bridge.

Convert PCI iproc host code to pci_scan_root_bus_bridge() to improve the
PCI root bus scanning interface.

Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Jon Mason <jonmason@broadcom.com>

authored by

Lorenzo Pieralisi and committed by
Bjorn Helgaas
52774076 90634e85

+30 -22
+5 -2
drivers/pci/host/pcie-iproc-bcma.c
··· 45 45 struct device *dev = &bdev->dev; 46 46 struct iproc_pcie *pcie; 47 47 LIST_HEAD(resources); 48 + struct pci_host_bridge *bridge; 48 49 int ret; 49 50 50 - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); 51 - if (!pcie) 51 + bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie)); 52 + if (!bridge) 52 53 return -ENOMEM; 54 + 55 + pcie = pci_host_bridge_priv(bridge); 53 56 54 57 pcie->dev = dev; 55 58
+5 -2
drivers/pci/host/pcie-iproc-platform.c
··· 52 52 struct resource reg; 53 53 resource_size_t iobase = 0; 54 54 LIST_HEAD(resources); 55 + struct pci_host_bridge *bridge; 55 56 int ret; 56 57 57 - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); 58 - if (!pcie) 58 + bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie)); 59 + if (!bridge) 59 60 return -ENOMEM; 61 + 62 + pcie = pci_host_bridge_priv(bridge); 60 63 61 64 pcie->dev = dev; 62 65 pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev);
+20 -18
drivers/pci/host/pcie-iproc.c
··· 1259 1259 struct device *dev; 1260 1260 int ret; 1261 1261 void *sysdata; 1262 - struct pci_bus *bus, *child; 1262 + struct pci_bus *child; 1263 + struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); 1263 1264 1264 1265 dev = pcie->dev; 1265 1266 ··· 1307 1306 sysdata = pcie; 1308 1307 #endif 1309 1308 1310 - bus = pci_create_root_bus(dev, 0, &iproc_pcie_ops, sysdata, res); 1311 - if (!bus) { 1312 - dev_err(dev, "unable to create PCI root bus\n"); 1313 - ret = -ENOMEM; 1314 - goto err_power_off_phy; 1315 - } 1316 - pcie->root_bus = bus; 1317 - 1318 1309 ret = iproc_pcie_check_link(pcie); 1319 1310 if (ret) { 1320 1311 dev_err(dev, "no PCIe EP device detected\n"); 1321 - goto err_rm_root_bus; 1312 + goto err_power_off_phy; 1322 1313 } 1323 1314 1324 1315 iproc_pcie_enable(pcie); ··· 1319 1326 if (iproc_pcie_msi_enable(pcie)) 1320 1327 dev_info(dev, "not using iProc MSI\n"); 1321 1328 1322 - pci_scan_child_bus(bus); 1323 - pci_assign_unassigned_bus_resources(bus); 1329 + list_splice_init(res, &host->windows); 1330 + host->busnr = 0; 1331 + host->dev.parent = dev; 1332 + host->ops = &iproc_pcie_ops; 1333 + host->sysdata = sysdata; 1334 + 1335 + ret = pci_scan_root_bus_bridge(host); 1336 + if (ret < 0) { 1337 + dev_err(dev, "failed to scan host: %d\n", ret); 1338 + goto err_power_off_phy; 1339 + } 1324 1340 1325 1341 if (pcie->map_irq) 1326 1342 pci_fixup_irqs(pci_common_swizzle, pcie->map_irq); 1327 1343 1328 - list_for_each_entry(child, &bus->children, node) 1344 + pci_assign_unassigned_bus_resources(host->bus); 1345 + 1346 + pcie->root_bus = host->bus; 1347 + 1348 + list_for_each_entry(child, &host->bus->children, node) 1329 1349 pcie_bus_configure_settings(child); 1330 1350 1331 - pci_bus_add_devices(bus); 1351 + pci_bus_add_devices(host->bus); 1332 1352 1333 1353 return 0; 1334 - 1335 - err_rm_root_bus: 1336 - pci_stop_root_bus(bus); 1337 - pci_remove_root_bus(bus); 1338 1354 1339 1355 err_power_off_phy: 1340 1356 phy_power_off(pcie->phy);