Skip to content

Commit 97ad2bd

Browse files
Lorenzo Pieralisibjorn-helgaas
authored andcommitted
ARM/PCI: 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 ARM bios32 code to pci_scan_root_bus_bridge() to improve the PCI root bus scanning interface. Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> [bhelgaas: fold in warning fix from Arnd Bergmann <arnd@arndb.de>: http://lkml.kernel.org/r/20170621215323.3921382-1-arnd@arndb.de] [bhelgaas: set bridge->ops for mv78xx0] [bhelgaas: fold in fixes from Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>: http://lkml.kernel.org/r/20170701135457.GB8977@red-moon] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Jason Cooper <jason@lakedaemon.net> Cc: Russell King <linux@armlinux.org.uk> Cc: Andrew Lunn <andrew@lunn.ch>
1 parent cea9bc0 commit 97ad2bd

8 files changed

Lines changed: 91 additions & 46 deletions

File tree

‎arch/arm/include/asm/mach/pci.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
struct pci_sys_data;
1717
struct pci_ops;
1818
struct pci_bus;
19+
struct pci_host_bridge;
1920
struct device;
2021

2122
struct hw_pci {
@@ -25,7 +26,7 @@ struct hw_pci {
2526
unsigned int io_optional:1;
2627
void **private_data;
2728
int (*setup)(int nr, struct pci_sys_data *);
28-
struct pci_bus *(*scan)(int nr, struct pci_sys_data *);
29+
int (*scan)(int nr, struct pci_host_bridge *);
2930
void (*preinit)(void);
3031
void (*postinit)(void);
3132
u8 (*swizzle)(struct pci_dev *dev, u8 *pin);

‎arch/arm/kernel/bios32.c‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,14 @@ static void pcibios_init_hw(struct device *parent, struct hw_pci *hw,
458458
int nr, busnr;
459459

460460
for (nr = busnr = 0; nr < hw->nr_controllers; nr++) {
461-
sys = kzalloc(sizeof(struct pci_sys_data), GFP_KERNEL);
462-
if (WARN(!sys, "PCI: unable to allocate sys data!"))
461+
struct pci_host_bridge *bridge;
462+
463+
bridge = pci_alloc_host_bridge(sizeof(struct pci_sys_data));
464+
if (WARN(!bridge, "PCI: unable to allocate bridge!"))
463465
break;
464466

467+
sys = pci_host_bridge_priv(bridge);
468+
465469
sys->busnr = busnr;
466470
sys->swizzle = hw->swizzle;
467471
sys->map_irq = hw->map_irq;
@@ -473,7 +477,6 @@ static void pcibios_init_hw(struct device *parent, struct hw_pci *hw,
473477
ret = hw->setup(nr, sys);
474478

475479
if (ret > 0) {
476-
struct pci_host_bridge *host_bridge;
477480

478481
ret = pcibios_init_resource(nr, sys, hw->io_optional);
479482
if (ret) {
@@ -482,25 +485,33 @@ static void pcibios_init_hw(struct device *parent, struct hw_pci *hw,
482485
}
483486

484487
if (hw->scan)
485-
sys->bus = hw->scan(nr, sys);
486-
else
487-
sys->bus = pci_scan_root_bus_msi(parent,
488-
sys->busnr, hw->ops, sys,
489-
&sys->resources, hw->msi_ctrl);
488+
ret = hw->scan(nr, bridge);
489+
else {
490+
list_splice_init(&sys->resources,
491+
&bridge->windows);
492+
bridge->dev.parent = parent;
493+
bridge->sysdata = sys;
494+
bridge->busnr = sys->busnr;
495+
bridge->ops = hw->ops;
496+
bridge->msi = hw->msi_ctrl;
497+
bridge->align_resource =
498+
hw->align_resource;
499+
500+
ret = pci_scan_root_bus_bridge(bridge);
501+
}
490502

491-
if (WARN(!sys->bus, "PCI: unable to scan bus!")) {
492-
kfree(sys);
503+
if (WARN(ret < 0, "PCI: unable to scan bus!")) {
504+
pci_free_host_bridge(bridge);
493505
break;
494506
}
495507

508+
sys->bus = bridge->bus;
509+
496510
busnr = sys->bus->busn_res.end + 1;
497511

498512
list_add(&sys->node, head);
499-
500-
host_bridge = pci_find_host_bridge(sys->bus);
501-
host_bridge->align_resource = hw->align_resource;
502513
} else {
503-
kfree(sys);
514+
pci_free_host_bridge(bridge);
504515
if (ret < 0)
505516
break;
506517
}

‎arch/arm/mach-dove/pcie.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,23 @@ static void rc_pci_fixup(struct pci_dev *dev)
152152
}
153153
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
154154

155-
static struct pci_bus __init *
156-
dove_pcie_scan_bus(int nr, struct pci_sys_data *sys)
155+
static int __init
156+
dove_pcie_scan_bus(int nr, struct pci_host_bridge *bridge)
157157
{
158+
struct pci_sys_data *sys = pci_host_bridge_priv(bridge);
159+
158160
if (nr >= num_pcie_ports) {
159161
BUG();
160-
return NULL;
162+
return -EINVAL;
161163
}
162164

163-
return pci_scan_root_bus(NULL, sys->busnr, &pcie_ops, sys,
164-
&sys->resources);
165+
list_splice_init(&sys->resources, &bridge->windows);
166+
bridge->dev.parent = NULL;
167+
bridge->sysdata = sys;
168+
bridge->busnr = sys->busnr;
169+
bridge->ops = &pcie_ops;
170+
171+
return pci_scan_root_bus_bridge(bridge);
165172
}
166173

167174
static int __init dove_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)

‎arch/arm/mach-iop13xx/pci.c‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ iop13xx_pci_abort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
504504

505505
/* Scan an IOP13XX PCI bus. nr selects which ATU we use.
506506
*/
507-
struct pci_bus *iop13xx_scan_bus(int nr, struct pci_sys_data *sys)
507+
int iop13xx_scan_bus(int nr, struct pci_host_bridge *bridge)
508508
{
509-
int which_atu;
510-
struct pci_bus *bus = NULL;
509+
int which_atu, ret;
510+
struct pci_sys_data *sys = pci_host_bridge_priv(bridge);
511511

512512
switch (init_atu) {
513513
case IOP13XX_INIT_ATU_ATUX:
@@ -525,28 +525,37 @@ struct pci_bus *iop13xx_scan_bus(int nr, struct pci_sys_data *sys)
525525

526526
if (!which_atu) {
527527
BUG();
528-
return NULL;
528+
return -ENODEV;
529529
}
530530

531+
list_splice_init(&sys->resources, &bridge->windows);
532+
bridge->dev.parent = NULL;
533+
bridge->sysdata = sys;
534+
bridge->busnr = sys->busnr;
535+
531536
switch (which_atu) {
532537
case IOP13XX_INIT_ATU_ATUX:
533538
if (time_after_eq(jiffies + msecs_to_jiffies(1000),
534539
atux_trhfa_timeout)) /* ensure not wrap */
535540
while(time_before(jiffies, atux_trhfa_timeout))
536541
udelay(100);
537542

538-
bus = pci_bus_atux = pci_scan_root_bus(NULL, sys->busnr,
539-
&iop13xx_atux_ops,
540-
sys, &sys->resources);
543+
bridge->ops = &iop13xx_atux_ops;
544+
ret = pci_scan_root_bus_bridge(bridge);
545+
if (!ret)
546+
pci_bus_atux = bridge->bus;
541547
break;
542548
case IOP13XX_INIT_ATU_ATUE:
543-
bus = pci_bus_atue = pci_scan_root_bus(NULL, sys->busnr,
544-
&iop13xx_atue_ops,
545-
sys, &sys->resources);
549+
bridge->ops = &iop13xx_atue_ops;
550+
ret = pci_scan_root_bus_bridge(bridge);
551+
if (!ret)
552+
pci_bus_atue = bridge->bus;
546553
break;
554+
default:
555+
ret = -EINVAL;
547556
}
548557

549-
return bus;
558+
return ret;
550559
}
551560

552561
/* This function is called from iop13xx_pci_init() after assigning valid

‎arch/arm/mach-iop13xx/pci.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ extern size_t iop13xx_atue_mem_size;
1111
extern size_t iop13xx_atux_mem_size;
1212

1313
struct pci_sys_data;
14+
struct pci_host_bridge;
1415
struct hw_pci;
1516
int iop13xx_pci_setup(int nr, struct pci_sys_data *sys);
16-
struct pci_bus *iop13xx_scan_bus(int nr, struct pci_sys_data *);
17+
int iop13xx_scan_bus(int nr, struct pci_host_bridge *bridge);
1718
void iop13xx_atu_select(struct hw_pci *plat_pci);
1819
void iop13xx_pci_init(void);
1920
void iop13xx_map_pci_memory(void);

‎arch/arm/mach-mv78xx0/pcie.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,22 @@ static void rc_pci_fixup(struct pci_dev *dev)
194194
}
195195
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
196196

197-
static struct pci_bus __init *
198-
mv78xx0_pcie_scan_bus(int nr, struct pci_sys_data *sys)
197+
static int __init mv78xx0_pcie_scan_bus(int nr, struct pci_host_bridge *bridge)
199198
{
199+
struct pci_sys_data *sys = pci_host_bridge_priv(bridge);
200+
200201
if (nr >= num_pcie_ports) {
201202
BUG();
202-
return NULL;
203+
return -EINVAL;
203204
}
204205

205-
return pci_scan_root_bus(NULL, sys->busnr, &pcie_ops, sys,
206-
&sys->resources);
206+
list_splice_init(&sys->resources, &bridge->windows);
207+
bridge->dev.parent = NULL;
208+
bridge->sysdata = sys;
209+
bridge->busnr = sys->busnr;
210+
bridge->ops = &pcie_ops;
211+
212+
return pci_scan_root_bus_bridge(bridge);
207213
}
208214

209215
static int __init mv78xx0_pcie_map_irq(const struct pci_dev *dev, u8 slot,

‎arch/arm/mach-orion5x/common.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ void orion5x_restart(enum reboot_mode, const char *);
5454
* PCIe/PCI functions.
5555
*/
5656
struct pci_bus;
57+
struct pci_host_bridge;
5758
struct pci_sys_data;
5859
struct pci_dev;
5960

6061
void orion5x_pcie_id(u32 *dev, u32 *rev);
6162
void orion5x_pci_disable(void);
6263
void orion5x_pci_set_cardbus_mode(void);
6364
int orion5x_pci_sys_setup(int nr, struct pci_sys_data *sys);
64-
struct pci_bus *orion5x_pci_sys_scan_bus(int nr, struct pci_sys_data *sys);
65+
int orion5x_pci_sys_scan_bus(int nr, struct pci_host_bridge *bridge);
6566
int orion5x_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
6667

6768
struct tag;

‎arch/arm/mach-orion5x/pci.c‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,18 +555,27 @@ int __init orion5x_pci_sys_setup(int nr, struct pci_sys_data *sys)
555555
return 0;
556556
}
557557

558-
struct pci_bus __init *orion5x_pci_sys_scan_bus(int nr, struct pci_sys_data *sys)
558+
int __init orion5x_pci_sys_scan_bus(int nr, struct pci_host_bridge *bridge)
559559
{
560-
if (nr == 0)
561-
return pci_scan_root_bus(NULL, sys->busnr, &pcie_ops, sys,
562-
&sys->resources);
560+
struct pci_sys_data *sys = pci_host_bridge_priv(bridge);
563561

564-
if (nr == 1 && !orion5x_pci_disabled)
565-
return pci_scan_root_bus(NULL, sys->busnr, &pci_ops, sys,
566-
&sys->resources);
562+
list_splice_init(&sys->resources, &bridge->windows);
563+
bridge->dev.parent = NULL;
564+
bridge->sysdata = sys;
565+
bridge->busnr = sys->busnr;
566+
567+
if (nr == 0) {
568+
bridge->ops = &pcie_ops;
569+
return pci_scan_root_bus_bridge(bridge);
570+
}
571+
572+
if (nr == 1 && !orion5x_pci_disabled) {
573+
bridge->ops = &pci_ops;
574+
return pci_scan_root_bus_bridge(bridge);
575+
}
567576

568577
BUG();
569-
return NULL;
578+
return -ENODEV;
570579
}
571580

572581
int __init orion5x_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)

0 commit comments

Comments
 (0)