Skip to content

Commit cbce790

Browse files
Zhou Wangbjorn-helgaas
Zhou Wang
authored andcommitted
PCI: designware: Make driver arch-agnostic
Previously, dw_pcie_host_init() created the PCI host bridge with pci_common_init_dev(), an ARM-specific function that supplies the ARM- specific pci_sys_data structure as the PCI "sysdata". Make pcie-designware.c arch-agnostic by reimplementing the functionality of pci_common_init_dev() directly in dw_pcie_host_init(). Note that this changes the bridge sysdata from the ARM pci_sys_data to the DesignWare pcie_port structure. This doesn't affect the ARM sysdata users because they are all specific to non-DesignWare host bridges, which will still have pci_sys_data. [bhelgaas: changelog] Tested-by: James Morse <[email protected]> Tested-by: Gabriel Fernandez <[email protected]> Tested-by: Minghuan Lian <[email protected]> Signed-off-by: Zhou Wang <[email protected]> Signed-off-by: Gabriele Paoloni <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Acked-by: Pratyush Anand <[email protected]>
1 parent b3a7238 commit cbce790

File tree

2 files changed

+39
-92
lines changed

2 files changed

+39
-92
lines changed

drivers/pci/host/pcie-designware.c

+39-91
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,7 @@
6969
#define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16)
7070
#define PCIE_ATU_UPPER_TARGET 0x91C
7171

72-
static struct hw_pci dw_pci;
73-
74-
static unsigned long global_io_offset;
75-
76-
static inline struct pcie_port *sys_to_pcie(struct pci_sys_data *sys)
77-
{
78-
BUG_ON(!sys->private_data);
79-
80-
return sys->private_data;
81-
}
72+
static struct pci_ops dw_pcie_ops;
8273

8374
int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val)
8475
{
@@ -267,7 +258,7 @@ static void dw_pcie_msi_set_irq(struct pcie_port *pp, int irq)
267258
static int assign_irq(int no_irqs, struct msi_desc *desc, int *pos)
268259
{
269260
int irq, pos0, i;
270-
struct pcie_port *pp = sys_to_pcie(msi_desc_to_pci_sysdata(desc));
261+
struct pcie_port *pp = (struct pcie_port *) msi_desc_to_pci_sysdata(desc);
271262

272263
pos0 = bitmap_find_free_region(pp->msi_irq_in_use, MAX_MSI_IRQS,
273264
order_base_2(no_irqs));
@@ -333,7 +324,7 @@ static int dw_msi_setup_irq(struct msi_controller *chip, struct pci_dev *pdev,
333324
struct msi_desc *desc)
334325
{
335326
int irq, pos;
336-
struct pcie_port *pp = sys_to_pcie(pdev->bus->sysdata);
327+
struct pcie_port *pp = pdev->bus->sysdata;
337328

338329
if (desc->msi_attrib.is_msix)
339330
return -EINVAL;
@@ -353,7 +344,7 @@ static int dw_msi_setup_irqs(struct msi_controller *chip, struct pci_dev *pdev,
353344
#ifdef CONFIG_PCI_MSI
354345
int irq, pos;
355346
struct msi_desc *desc;
356-
struct pcie_port *pp = sys_to_pcie(pdev->bus->sysdata);
347+
struct pcie_port *pp = pdev->bus->sysdata;
357348

358349
/* MSI-X interrupts are not supported */
359350
if (type == PCI_CAP_ID_MSIX)
@@ -378,7 +369,7 @@ static void dw_msi_teardown_irq(struct msi_controller *chip, unsigned int irq)
378369
{
379370
struct irq_data *data = irq_get_irq_data(irq);
380371
struct msi_desc *msi = irq_data_get_msi_desc(data);
381-
struct pcie_port *pp = sys_to_pcie(msi_desc_to_pci_sysdata(msi));
372+
struct pcie_port *pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
382373

383374
clear_irq_range(pp, irq, 1, data->hwirq);
384375
}
@@ -414,6 +405,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
414405
{
415406
struct device_node *np = pp->dev->of_node;
416407
struct platform_device *pdev = to_platform_device(pp->dev);
408+
struct pci_bus *bus, *child;
417409
struct resource *cfg_res;
418410
u32 val;
419411
int i, ret;
@@ -442,14 +434,13 @@ int dw_pcie_host_init(struct pcie_port *pp)
442434
pp->io->name = "I/O";
443435
pp->io_size = resource_size(pp->io);
444436
pp->io_bus_addr = pp->io->start - win->offset;
445-
pp->io->start = max_t(resource_size_t, PCIBIOS_MIN_IO,
446-
pp->io_bus_addr +
447-
global_io_offset);
448-
pp->io->end = min_t(resource_size_t, IO_SPACE_LIMIT,
449-
pp->io_bus_addr + pp->io_size +
450-
global_io_offset - 1);
437+
ret = pci_remap_iospace(pp->io, pp->io_base);
438+
if (ret) {
439+
dev_warn(pp->dev, "error %d: failed to map resource %pR\n",
440+
ret, pp->io);
441+
continue;
442+
}
451443
pp->io_base = pp->io->start;
452-
pp->io_base_tmp = pp->io->start;
453444
break;
454445
case IORESOURCE_MEM:
455446
pp->mem = win->res;
@@ -541,15 +532,35 @@ int dw_pcie_host_init(struct pcie_port *pp)
541532
val |= PORT_LOGIC_SPEED_CHANGE;
542533
dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val);
543534

544-
#ifdef CONFIG_PCI_MSI
545-
dw_pcie_msi_chip.dev = pp->dev;
535+
pp->root_bus_nr = pp->busn->start;
536+
if (IS_ENABLED(CONFIG_PCI_MSI)) {
537+
bus = pci_scan_root_bus_msi(pp->dev, pp->root_bus_nr,
538+
&dw_pcie_ops, pp, &res,
539+
&dw_pcie_msi_chip);
540+
dw_pcie_msi_chip.dev = pp->dev;
541+
} else
542+
bus = pci_scan_root_bus(pp->dev, pp->root_bus_nr, &dw_pcie_ops,
543+
pp, &res);
544+
if (!bus)
545+
return -ENOMEM;
546+
547+
if (pp->ops->scan_bus)
548+
pp->ops->scan_bus(pp);
549+
550+
#ifdef CONFIG_ARM
551+
/* support old dtbs that incorrectly describe IRQs */
552+
pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
546553
#endif
547554

548-
dw_pci.nr_controllers = 1;
549-
dw_pci.private_data = (void **)&pp;
555+
if (!pci_has_flag(PCI_PROBE_ONLY)) {
556+
pci_bus_size_bridges(bus);
557+
pci_bus_assign_resources(bus);
550558

551-
pci_common_init_dev(pp->dev, &dw_pci);
559+
list_for_each_entry(child, &bus->children, node)
560+
pcie_bus_configure_settings(child);
561+
}
552562

563+
pci_bus_add_devices(bus);
553564
return 0;
554565
}
555566

@@ -647,7 +658,7 @@ static int dw_pcie_valid_config(struct pcie_port *pp,
647658
static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
648659
int size, u32 *val)
649660
{
650-
struct pcie_port *pp = sys_to_pcie(bus->sysdata);
661+
struct pcie_port *pp = bus->sysdata;
651662
int ret;
652663

653664
if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0) {
@@ -671,7 +682,7 @@ static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
671682
static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
672683
int where, int size, u32 val)
673684
{
674-
struct pcie_port *pp = sys_to_pcie(bus->sysdata);
685+
struct pcie_port *pp = bus->sysdata;
675686
int ret;
676687

677688
if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0)
@@ -695,69 +706,6 @@ static struct pci_ops dw_pcie_ops = {
695706
.write = dw_pcie_wr_conf,
696707
};
697708

698-
static int dw_pcie_setup(int nr, struct pci_sys_data *sys)
699-
{
700-
struct pcie_port *pp;
701-
702-
pp = sys_to_pcie(sys);
703-
704-
if (global_io_offset < SZ_1M && pp->io_size > 0) {
705-
sys->io_offset = global_io_offset - pp->io_bus_addr;
706-
pci_ioremap_io(global_io_offset, pp->io_base_tmp);
707-
global_io_offset += SZ_64K;
708-
pci_add_resource_offset(&sys->resources, pp->io,
709-
sys->io_offset);
710-
}
711-
712-
sys->mem_offset = pp->mem->start - pp->mem_bus_addr;
713-
pci_add_resource_offset(&sys->resources, pp->mem, sys->mem_offset);
714-
pci_add_resource(&sys->resources, pp->busn);
715-
716-
return 1;
717-
}
718-
719-
static struct pci_bus *dw_pcie_scan_bus(int nr, struct pci_sys_data *sys)
720-
{
721-
struct pci_bus *bus;
722-
struct pcie_port *pp = sys_to_pcie(sys);
723-
724-
pp->root_bus_nr = sys->busnr;
725-
726-
if (IS_ENABLED(CONFIG_PCI_MSI))
727-
bus = pci_scan_root_bus_msi(pp->dev, sys->busnr, &dw_pcie_ops,
728-
sys, &sys->resources,
729-
&dw_pcie_msi_chip);
730-
else
731-
bus = pci_scan_root_bus(pp->dev, sys->busnr, &dw_pcie_ops,
732-
sys, &sys->resources);
733-
734-
if (!bus)
735-
return NULL;
736-
737-
if (bus && pp->ops->scan_bus)
738-
pp->ops->scan_bus(pp);
739-
740-
return bus;
741-
}
742-
743-
static int dw_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
744-
{
745-
struct pcie_port *pp = sys_to_pcie(dev->bus->sysdata);
746-
int irq;
747-
748-
irq = of_irq_parse_and_map_pci(dev, slot, pin);
749-
if (!irq)
750-
irq = pp->irq;
751-
752-
return irq;
753-
}
754-
755-
static struct hw_pci dw_pci = {
756-
.setup = dw_pcie_setup,
757-
.scan = dw_pcie_scan_bus,
758-
.map_irq = dw_pcie_map_irq,
759-
};
760-
761709
void dw_pcie_setup_rc(struct pcie_port *pp)
762710
{
763711
u32 val;

drivers/pci/host/pcie-designware.h

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct pcie_port {
3333
void __iomem *va_cfg1_base;
3434
u32 cfg1_size;
3535
resource_size_t io_base;
36-
resource_size_t io_base_tmp;
3736
phys_addr_t io_bus_addr;
3837
u32 io_size;
3938
u64 mem_base;

0 commit comments

Comments
 (0)