diff options
author | Zhou Wang <wangzhou1@hisilicon.com> | 2015-10-29 20:57:21 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2015-11-02 15:49:18 -0500 |
commit | cbce7900598c26a12652f8ca9c41c5b29034c38d (patch) | |
tree | 349cf4e2ec58e44c139a58d1150a62219e2a43fb | |
parent | b3a72384fe29eec41a202b480145de225a148dbc (diff) |
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 <james.morse@arm.com>
Tested-by: Gabriel Fernandez <gabriel.fernandez@st.com>
Tested-by: Minghuan Lian <Minghuan.Lian@freescale.com>
Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
-rw-r--r-- | drivers/pci/host/pcie-designware.c | 130 | ||||
-rw-r--r-- | drivers/pci/host/pcie-designware.h | 1 |
2 files changed, 39 insertions, 92 deletions
diff --git a/drivers/pci/host/pcie-designware.c b/drivers/pci/host/pcie-designware.c index 21ae17e52a4c..540f077c37ea 100644 --- a/drivers/pci/host/pcie-designware.c +++ b/drivers/pci/host/pcie-designware.c | |||
@@ -69,16 +69,7 @@ | |||
69 | #define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16) | 69 | #define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16) |
70 | #define PCIE_ATU_UPPER_TARGET 0x91C | 70 | #define PCIE_ATU_UPPER_TARGET 0x91C |
71 | 71 | ||
72 | static struct hw_pci dw_pci; | 72 | static struct pci_ops dw_pcie_ops; |
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 | } | ||
82 | 73 | ||
83 | int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val) | 74 | int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val) |
84 | { | 75 | { |
@@ -267,7 +258,7 @@ static void dw_pcie_msi_set_irq(struct pcie_port *pp, int irq) | |||
267 | static int assign_irq(int no_irqs, struct msi_desc *desc, int *pos) | 258 | static int assign_irq(int no_irqs, struct msi_desc *desc, int *pos) |
268 | { | 259 | { |
269 | int irq, pos0, i; | 260 | 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); |
271 | 262 | ||
272 | pos0 = bitmap_find_free_region(pp->msi_irq_in_use, MAX_MSI_IRQS, | 263 | pos0 = bitmap_find_free_region(pp->msi_irq_in_use, MAX_MSI_IRQS, |
273 | order_base_2(no_irqs)); | 264 | order_base_2(no_irqs)); |
@@ -333,7 +324,7 @@ static int dw_msi_setup_irq(struct msi_controller *chip, struct pci_dev *pdev, | |||
333 | struct msi_desc *desc) | 324 | struct msi_desc *desc) |
334 | { | 325 | { |
335 | int irq, pos; | 326 | int irq, pos; |
336 | struct pcie_port *pp = sys_to_pcie(pdev->bus->sysdata); | 327 | struct pcie_port *pp = pdev->bus->sysdata; |
337 | 328 | ||
338 | if (desc->msi_attrib.is_msix) | 329 | if (desc->msi_attrib.is_msix) |
339 | return -EINVAL; | 330 | return -EINVAL; |
@@ -353,7 +344,7 @@ static int dw_msi_setup_irqs(struct msi_controller *chip, struct pci_dev *pdev, | |||
353 | #ifdef CONFIG_PCI_MSI | 344 | #ifdef CONFIG_PCI_MSI |
354 | int irq, pos; | 345 | int irq, pos; |
355 | struct msi_desc *desc; | 346 | struct msi_desc *desc; |
356 | struct pcie_port *pp = sys_to_pcie(pdev->bus->sysdata); | 347 | struct pcie_port *pp = pdev->bus->sysdata; |
357 | 348 | ||
358 | /* MSI-X interrupts are not supported */ | 349 | /* MSI-X interrupts are not supported */ |
359 | if (type == PCI_CAP_ID_MSIX) | 350 | if (type == PCI_CAP_ID_MSIX) |
@@ -378,7 +369,7 @@ static void dw_msi_teardown_irq(struct msi_controller *chip, unsigned int irq) | |||
378 | { | 369 | { |
379 | struct irq_data *data = irq_get_irq_data(irq); | 370 | struct irq_data *data = irq_get_irq_data(irq); |
380 | struct msi_desc *msi = irq_data_get_msi_desc(data); | 371 | 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); |
382 | 373 | ||
383 | clear_irq_range(pp, irq, 1, data->hwirq); | 374 | clear_irq_range(pp, irq, 1, data->hwirq); |
384 | } | 375 | } |
@@ -414,6 +405,7 @@ int dw_pcie_host_init(struct pcie_port *pp) | |||
414 | { | 405 | { |
415 | struct device_node *np = pp->dev->of_node; | 406 | struct device_node *np = pp->dev->of_node; |
416 | struct platform_device *pdev = to_platform_device(pp->dev); | 407 | struct platform_device *pdev = to_platform_device(pp->dev); |
408 | struct pci_bus *bus, *child; | ||
417 | struct resource *cfg_res; | 409 | struct resource *cfg_res; |
418 | u32 val; | 410 | u32 val; |
419 | int i, ret; | 411 | int i, ret; |
@@ -442,14 +434,13 @@ int dw_pcie_host_init(struct pcie_port *pp) | |||
442 | pp->io->name = "I/O"; | 434 | pp->io->name = "I/O"; |
443 | pp->io_size = resource_size(pp->io); | 435 | pp->io_size = resource_size(pp->io); |
444 | pp->io_bus_addr = pp->io->start - win->offset; | 436 | pp->io_bus_addr = pp->io->start - win->offset; |
445 | pp->io->start = max_t(resource_size_t, PCIBIOS_MIN_IO, | 437 | ret = pci_remap_iospace(pp->io, pp->io_base); |
446 | pp->io_bus_addr + | 438 | if (ret) { |
447 | global_io_offset); | 439 | dev_warn(pp->dev, "error %d: failed to map resource %pR\n", |
448 | pp->io->end = min_t(resource_size_t, IO_SPACE_LIMIT, | 440 | ret, pp->io); |
449 | pp->io_bus_addr + pp->io_size + | 441 | continue; |
450 | global_io_offset - 1); | 442 | } |
451 | pp->io_base = pp->io->start; | 443 | pp->io_base = pp->io->start; |
452 | pp->io_base_tmp = pp->io->start; | ||
453 | break; | 444 | break; |
454 | case IORESOURCE_MEM: | 445 | case IORESOURCE_MEM: |
455 | pp->mem = win->res; | 446 | pp->mem = win->res; |
@@ -541,15 +532,35 @@ int dw_pcie_host_init(struct pcie_port *pp) | |||
541 | val |= PORT_LOGIC_SPEED_CHANGE; | 532 | val |= PORT_LOGIC_SPEED_CHANGE; |
542 | dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val); | 533 | dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val); |
543 | 534 | ||
544 | #ifdef CONFIG_PCI_MSI | 535 | pp->root_bus_nr = pp->busn->start; |
545 | dw_pcie_msi_chip.dev = pp->dev; | 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); | ||
546 | #endif | 553 | #endif |
547 | 554 | ||
548 | dw_pci.nr_controllers = 1; | 555 | if (!pci_has_flag(PCI_PROBE_ONLY)) { |
549 | dw_pci.private_data = (void **)&pp; | 556 | pci_bus_size_bridges(bus); |
557 | pci_bus_assign_resources(bus); | ||
550 | 558 | ||
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 | } | ||
552 | 562 | ||
563 | pci_bus_add_devices(bus); | ||
553 | return 0; | 564 | return 0; |
554 | } | 565 | } |
555 | 566 | ||
@@ -647,7 +658,7 @@ static int dw_pcie_valid_config(struct pcie_port *pp, | |||
647 | static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, | 658 | static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, |
648 | int size, u32 *val) | 659 | int size, u32 *val) |
649 | { | 660 | { |
650 | struct pcie_port *pp = sys_to_pcie(bus->sysdata); | 661 | struct pcie_port *pp = bus->sysdata; |
651 | int ret; | 662 | int ret; |
652 | 663 | ||
653 | if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0) { | 664 | 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, | |||
671 | static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn, | 682 | static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn, |
672 | int where, int size, u32 val) | 683 | int where, int size, u32 val) |
673 | { | 684 | { |
674 | struct pcie_port *pp = sys_to_pcie(bus->sysdata); | 685 | struct pcie_port *pp = bus->sysdata; |
675 | int ret; | 686 | int ret; |
676 | 687 | ||
677 | if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0) | 688 | if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0) |
@@ -695,69 +706,6 @@ static struct pci_ops dw_pcie_ops = { | |||
695 | .write = dw_pcie_wr_conf, | 706 | .write = dw_pcie_wr_conf, |
696 | }; | 707 | }; |
697 | 708 | ||
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 | |||
761 | void dw_pcie_setup_rc(struct pcie_port *pp) | 709 | void dw_pcie_setup_rc(struct pcie_port *pp) |
762 | { | 710 | { |
763 | u32 val; | 711 | u32 val; |
diff --git a/drivers/pci/host/pcie-designware.h b/drivers/pci/host/pcie-designware.h index 631f5a6f6547..2356d29e8527 100644 --- a/drivers/pci/host/pcie-designware.h +++ b/drivers/pci/host/pcie-designware.h | |||
@@ -33,7 +33,6 @@ struct pcie_port { | |||
33 | void __iomem *va_cfg1_base; | 33 | void __iomem *va_cfg1_base; |
34 | u32 cfg1_size; | 34 | u32 cfg1_size; |
35 | resource_size_t io_base; | 35 | resource_size_t io_base; |
36 | resource_size_t io_base_tmp; | ||
37 | phys_addr_t io_bus_addr; | 36 | phys_addr_t io_bus_addr; |
38 | u32 io_size; | 37 | u32 io_size; |
39 | u64 mem_base; | 38 | u64 mem_base; |