diff options
Diffstat (limited to 'drivers/pci/host')
-rw-r--r-- | drivers/pci/host/pci-mvebu.c | 92 | ||||
-rw-r--r-- | drivers/pci/host/pci-rcar-gen2.c | 8 | ||||
-rw-r--r-- | drivers/pci/host/pci-tegra.c | 7 | ||||
-rw-r--r-- | drivers/pci/host/pcie-designware.c | 20 |
4 files changed, 102 insertions, 25 deletions
diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c index d3d1cfd51e09..e384e2534594 100644 --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c | |||
@@ -293,6 +293,58 @@ static int mvebu_pcie_hw_wr_conf(struct mvebu_pcie_port *port, | |||
293 | return PCIBIOS_SUCCESSFUL; | 293 | return PCIBIOS_SUCCESSFUL; |
294 | } | 294 | } |
295 | 295 | ||
296 | /* | ||
297 | * Remove windows, starting from the largest ones to the smallest | ||
298 | * ones. | ||
299 | */ | ||
300 | static void mvebu_pcie_del_windows(struct mvebu_pcie_port *port, | ||
301 | phys_addr_t base, size_t size) | ||
302 | { | ||
303 | while (size) { | ||
304 | size_t sz = 1 << (fls(size) - 1); | ||
305 | |||
306 | mvebu_mbus_del_window(base, sz); | ||
307 | base += sz; | ||
308 | size -= sz; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | /* | ||
313 | * MBus windows can only have a power of two size, but PCI BARs do not | ||
314 | * have this constraint. Therefore, we have to split the PCI BAR into | ||
315 | * areas each having a power of two size. We start from the largest | ||
316 | * one (i.e highest order bit set in the size). | ||
317 | */ | ||
318 | static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port, | ||
319 | unsigned int target, unsigned int attribute, | ||
320 | phys_addr_t base, size_t size, | ||
321 | phys_addr_t remap) | ||
322 | { | ||
323 | size_t size_mapped = 0; | ||
324 | |||
325 | while (size) { | ||
326 | size_t sz = 1 << (fls(size) - 1); | ||
327 | int ret; | ||
328 | |||
329 | ret = mvebu_mbus_add_window_remap_by_id(target, attribute, base, | ||
330 | sz, remap); | ||
331 | if (ret) { | ||
332 | dev_err(&port->pcie->pdev->dev, | ||
333 | "Could not create MBus window at 0x%x, size 0x%x: %d\n", | ||
334 | base, sz, ret); | ||
335 | mvebu_pcie_del_windows(port, base - size_mapped, | ||
336 | size_mapped); | ||
337 | return; | ||
338 | } | ||
339 | |||
340 | size -= sz; | ||
341 | size_mapped += sz; | ||
342 | base += sz; | ||
343 | if (remap != MVEBU_MBUS_NO_REMAP) | ||
344 | remap += sz; | ||
345 | } | ||
346 | } | ||
347 | |||
296 | static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) | 348 | static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) |
297 | { | 349 | { |
298 | phys_addr_t iobase; | 350 | phys_addr_t iobase; |
@@ -304,8 +356,8 @@ static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) | |||
304 | 356 | ||
305 | /* If a window was configured, remove it */ | 357 | /* If a window was configured, remove it */ |
306 | if (port->iowin_base) { | 358 | if (port->iowin_base) { |
307 | mvebu_mbus_del_window(port->iowin_base, | 359 | mvebu_pcie_del_windows(port, port->iowin_base, |
308 | port->iowin_size); | 360 | port->iowin_size); |
309 | port->iowin_base = 0; | 361 | port->iowin_base = 0; |
310 | port->iowin_size = 0; | 362 | port->iowin_size = 0; |
311 | } | 363 | } |
@@ -331,11 +383,11 @@ static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port) | |||
331 | port->iowin_base = port->pcie->io.start + iobase; | 383 | port->iowin_base = port->pcie->io.start + iobase; |
332 | port->iowin_size = ((0xFFF | ((port->bridge.iolimit & 0xF0) << 8) | | 384 | port->iowin_size = ((0xFFF | ((port->bridge.iolimit & 0xF0) << 8) | |
333 | (port->bridge.iolimitupper << 16)) - | 385 | (port->bridge.iolimitupper << 16)) - |
334 | iobase); | 386 | iobase) + 1; |
335 | 387 | ||
336 | mvebu_mbus_add_window_remap_by_id(port->io_target, port->io_attr, | 388 | mvebu_pcie_add_windows(port, port->io_target, port->io_attr, |
337 | port->iowin_base, port->iowin_size, | 389 | port->iowin_base, port->iowin_size, |
338 | iobase); | 390 | iobase); |
339 | } | 391 | } |
340 | 392 | ||
341 | static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) | 393 | static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) |
@@ -346,8 +398,8 @@ static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) | |||
346 | 398 | ||
347 | /* If a window was configured, remove it */ | 399 | /* If a window was configured, remove it */ |
348 | if (port->memwin_base) { | 400 | if (port->memwin_base) { |
349 | mvebu_mbus_del_window(port->memwin_base, | 401 | mvebu_pcie_del_windows(port, port->memwin_base, |
350 | port->memwin_size); | 402 | port->memwin_size); |
351 | port->memwin_base = 0; | 403 | port->memwin_base = 0; |
352 | port->memwin_size = 0; | 404 | port->memwin_size = 0; |
353 | } | 405 | } |
@@ -364,10 +416,11 @@ static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port) | |||
364 | port->memwin_base = ((port->bridge.membase & 0xFFF0) << 16); | 416 | port->memwin_base = ((port->bridge.membase & 0xFFF0) << 16); |
365 | port->memwin_size = | 417 | port->memwin_size = |
366 | (((port->bridge.memlimit & 0xFFF0) << 16) | 0xFFFFF) - | 418 | (((port->bridge.memlimit & 0xFFF0) << 16) | 0xFFFFF) - |
367 | port->memwin_base; | 419 | port->memwin_base + 1; |
368 | 420 | ||
369 | mvebu_mbus_add_window_by_id(port->mem_target, port->mem_attr, | 421 | mvebu_pcie_add_windows(port, port->mem_target, port->mem_attr, |
370 | port->memwin_base, port->memwin_size); | 422 | port->memwin_base, port->memwin_size, |
423 | MVEBU_MBUS_NO_REMAP); | ||
371 | } | 424 | } |
372 | 425 | ||
373 | /* | 426 | /* |
@@ -743,14 +796,21 @@ static resource_size_t mvebu_pcie_align_resource(struct pci_dev *dev, | |||
743 | 796 | ||
744 | /* | 797 | /* |
745 | * On the PCI-to-PCI bridge side, the I/O windows must have at | 798 | * On the PCI-to-PCI bridge side, the I/O windows must have at |
746 | * least a 64 KB size and be aligned on their size, and the | 799 | * least a 64 KB size and the memory windows must have at |
747 | * memory windows must have at least a 1 MB size and be | 800 | * least a 1 MB size. Moreover, MBus windows need to have a |
748 | * aligned on their size | 801 | * base address aligned on their size, and their size must be |
802 | * a power of two. This means that if the BAR doesn't have a | ||
803 | * power of two size, several MBus windows will actually be | ||
804 | * created. We need to ensure that the biggest MBus window | ||
805 | * (which will be the first one) is aligned on its size, which | ||
806 | * explains the rounddown_pow_of_two() being done here. | ||
749 | */ | 807 | */ |
750 | if (res->flags & IORESOURCE_IO) | 808 | if (res->flags & IORESOURCE_IO) |
751 | return round_up(start, max_t(resource_size_t, SZ_64K, size)); | 809 | return round_up(start, max_t(resource_size_t, SZ_64K, |
810 | rounddown_pow_of_two(size))); | ||
752 | else if (res->flags & IORESOURCE_MEM) | 811 | else if (res->flags & IORESOURCE_MEM) |
753 | return round_up(start, max_t(resource_size_t, SZ_1M, size)); | 812 | return round_up(start, max_t(resource_size_t, SZ_1M, |
813 | rounddown_pow_of_two(size))); | ||
754 | else | 814 | else |
755 | return start; | 815 | return start; |
756 | } | 816 | } |
diff --git a/drivers/pci/host/pci-rcar-gen2.c b/drivers/pci/host/pci-rcar-gen2.c index fd3e3ab56509..4fe349dcaf59 100644 --- a/drivers/pci/host/pci-rcar-gen2.c +++ b/drivers/pci/host/pci-rcar-gen2.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/io.h> | 15 | #include <linux/io.h> |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/of_pci.h> | ||
18 | #include <linux/pci.h> | 19 | #include <linux/pci.h> |
19 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
20 | #include <linux/pm_runtime.h> | 21 | #include <linux/pm_runtime.h> |
@@ -180,8 +181,13 @@ static int rcar_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) | |||
180 | { | 181 | { |
181 | struct pci_sys_data *sys = dev->bus->sysdata; | 182 | struct pci_sys_data *sys = dev->bus->sysdata; |
182 | struct rcar_pci_priv *priv = sys->private_data; | 183 | struct rcar_pci_priv *priv = sys->private_data; |
184 | int irq; | ||
185 | |||
186 | irq = of_irq_parse_and_map_pci(dev, slot, pin); | ||
187 | if (!irq) | ||
188 | irq = priv->irq; | ||
183 | 189 | ||
184 | return priv->irq; | 190 | return irq; |
185 | } | 191 | } |
186 | 192 | ||
187 | #ifdef CONFIG_PCI_DEBUG | 193 | #ifdef CONFIG_PCI_DEBUG |
diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c index 330f7e3a32dd..083cf37ca047 100644 --- a/drivers/pci/host/pci-tegra.c +++ b/drivers/pci/host/pci-tegra.c | |||
@@ -639,10 +639,15 @@ static int tegra_pcie_setup(int nr, struct pci_sys_data *sys) | |||
639 | static int tegra_pcie_map_irq(const struct pci_dev *pdev, u8 slot, u8 pin) | 639 | static int tegra_pcie_map_irq(const struct pci_dev *pdev, u8 slot, u8 pin) |
640 | { | 640 | { |
641 | struct tegra_pcie *pcie = sys_to_pcie(pdev->bus->sysdata); | 641 | struct tegra_pcie *pcie = sys_to_pcie(pdev->bus->sysdata); |
642 | int irq; | ||
642 | 643 | ||
643 | tegra_cpuidle_pcie_irqs_in_use(); | 644 | tegra_cpuidle_pcie_irqs_in_use(); |
644 | 645 | ||
645 | return pcie->irq; | 646 | irq = of_irq_parse_and_map_pci(pdev, slot, pin); |
647 | if (!irq) | ||
648 | irq = pcie->irq; | ||
649 | |||
650 | return irq; | ||
646 | } | 651 | } |
647 | 652 | ||
648 | static void tegra_pcie_add_bus(struct pci_bus *bus) | 653 | static void tegra_pcie_add_bus(struct pci_bus *bus) |
diff --git a/drivers/pci/host/pcie-designware.c b/drivers/pci/host/pcie-designware.c index 509a29d84509..c4e373294476 100644 --- a/drivers/pci/host/pcie-designware.c +++ b/drivers/pci/host/pcie-designware.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/msi.h> | 18 | #include <linux/msi.h> |
19 | #include <linux/of_address.h> | 19 | #include <linux/of_address.h> |
20 | #include <linux/of_pci.h> | ||
20 | #include <linux/pci.h> | 21 | #include <linux/pci.h> |
21 | #include <linux/pci_regs.h> | 22 | #include <linux/pci_regs.h> |
22 | #include <linux/types.h> | 23 | #include <linux/types.h> |
@@ -490,7 +491,7 @@ int __init dw_pcie_host_init(struct pcie_port *pp) | |||
490 | dw_pci.nr_controllers = 1; | 491 | dw_pci.nr_controllers = 1; |
491 | dw_pci.private_data = (void **)&pp; | 492 | dw_pci.private_data = (void **)&pp; |
492 | 493 | ||
493 | pci_common_init(&dw_pci); | 494 | pci_common_init_dev(pp->dev, &dw_pci); |
494 | pci_assign_unassigned_resources(); | 495 | pci_assign_unassigned_resources(); |
495 | #ifdef CONFIG_PCI_DOMAINS | 496 | #ifdef CONFIG_PCI_DOMAINS |
496 | dw_pci.domain++; | 497 | dw_pci.domain++; |
@@ -520,13 +521,13 @@ static void dw_pcie_prog_viewport_cfg1(struct pcie_port *pp, u32 busdev) | |||
520 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, | 521 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, |
521 | PCIE_ATU_VIEWPORT); | 522 | PCIE_ATU_VIEWPORT); |
522 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG1, PCIE_ATU_CR1); | 523 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG1, PCIE_ATU_CR1); |
523 | dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2); | ||
524 | dw_pcie_writel_rc(pp, pp->cfg1_base, PCIE_ATU_LOWER_BASE); | 524 | dw_pcie_writel_rc(pp, pp->cfg1_base, PCIE_ATU_LOWER_BASE); |
525 | dw_pcie_writel_rc(pp, (pp->cfg1_base >> 32), PCIE_ATU_UPPER_BASE); | 525 | dw_pcie_writel_rc(pp, (pp->cfg1_base >> 32), PCIE_ATU_UPPER_BASE); |
526 | dw_pcie_writel_rc(pp, pp->cfg1_base + pp->config.cfg1_size - 1, | 526 | dw_pcie_writel_rc(pp, pp->cfg1_base + pp->config.cfg1_size - 1, |
527 | PCIE_ATU_LIMIT); | 527 | PCIE_ATU_LIMIT); |
528 | dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET); | 528 | dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET); |
529 | dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET); | 529 | dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET); |
530 | dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2); | ||
530 | } | 531 | } |
531 | 532 | ||
532 | static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp) | 533 | static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp) |
@@ -535,7 +536,6 @@ static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp) | |||
535 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0, | 536 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0, |
536 | PCIE_ATU_VIEWPORT); | 537 | PCIE_ATU_VIEWPORT); |
537 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1); | 538 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1); |
538 | dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2); | ||
539 | dw_pcie_writel_rc(pp, pp->mem_base, PCIE_ATU_LOWER_BASE); | 539 | dw_pcie_writel_rc(pp, pp->mem_base, PCIE_ATU_LOWER_BASE); |
540 | dw_pcie_writel_rc(pp, (pp->mem_base >> 32), PCIE_ATU_UPPER_BASE); | 540 | dw_pcie_writel_rc(pp, (pp->mem_base >> 32), PCIE_ATU_UPPER_BASE); |
541 | dw_pcie_writel_rc(pp, pp->mem_base + pp->config.mem_size - 1, | 541 | dw_pcie_writel_rc(pp, pp->mem_base + pp->config.mem_size - 1, |
@@ -543,6 +543,7 @@ static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp) | |||
543 | dw_pcie_writel_rc(pp, pp->config.mem_bus_addr, PCIE_ATU_LOWER_TARGET); | 543 | dw_pcie_writel_rc(pp, pp->config.mem_bus_addr, PCIE_ATU_LOWER_TARGET); |
544 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.mem_bus_addr), | 544 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.mem_bus_addr), |
545 | PCIE_ATU_UPPER_TARGET); | 545 | PCIE_ATU_UPPER_TARGET); |
546 | dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2); | ||
546 | } | 547 | } |
547 | 548 | ||
548 | static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp) | 549 | static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp) |
@@ -551,7 +552,6 @@ static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp) | |||
551 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, | 552 | dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1, |
552 | PCIE_ATU_VIEWPORT); | 553 | PCIE_ATU_VIEWPORT); |
553 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_IO, PCIE_ATU_CR1); | 554 | dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_IO, PCIE_ATU_CR1); |
554 | dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2); | ||
555 | dw_pcie_writel_rc(pp, pp->io_base, PCIE_ATU_LOWER_BASE); | 555 | dw_pcie_writel_rc(pp, pp->io_base, PCIE_ATU_LOWER_BASE); |
556 | dw_pcie_writel_rc(pp, (pp->io_base >> 32), PCIE_ATU_UPPER_BASE); | 556 | dw_pcie_writel_rc(pp, (pp->io_base >> 32), PCIE_ATU_UPPER_BASE); |
557 | dw_pcie_writel_rc(pp, pp->io_base + pp->config.io_size - 1, | 557 | dw_pcie_writel_rc(pp, pp->io_base + pp->config.io_size - 1, |
@@ -559,6 +559,7 @@ static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp) | |||
559 | dw_pcie_writel_rc(pp, pp->config.io_bus_addr, PCIE_ATU_LOWER_TARGET); | 559 | dw_pcie_writel_rc(pp, pp->config.io_bus_addr, PCIE_ATU_LOWER_TARGET); |
560 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.io_bus_addr), | 560 | dw_pcie_writel_rc(pp, upper_32_bits(pp->config.io_bus_addr), |
561 | PCIE_ATU_UPPER_TARGET); | 561 | PCIE_ATU_UPPER_TARGET); |
562 | dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2); | ||
562 | } | 563 | } |
563 | 564 | ||
564 | static int dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus, | 565 | static int dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus, |
@@ -723,7 +724,7 @@ static struct pci_bus *dw_pcie_scan_bus(int nr, struct pci_sys_data *sys) | |||
723 | 724 | ||
724 | if (pp) { | 725 | if (pp) { |
725 | pp->root_bus_nr = sys->busnr; | 726 | pp->root_bus_nr = sys->busnr; |
726 | bus = pci_scan_root_bus(NULL, sys->busnr, &dw_pcie_ops, | 727 | bus = pci_scan_root_bus(pp->dev, sys->busnr, &dw_pcie_ops, |
727 | sys, &sys->resources); | 728 | sys, &sys->resources); |
728 | } else { | 729 | } else { |
729 | bus = NULL; | 730 | bus = NULL; |
@@ -736,8 +737,13 @@ static struct pci_bus *dw_pcie_scan_bus(int nr, struct pci_sys_data *sys) | |||
736 | static int dw_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) | 737 | static int dw_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) |
737 | { | 738 | { |
738 | struct pcie_port *pp = sys_to_pcie(dev->bus->sysdata); | 739 | struct pcie_port *pp = sys_to_pcie(dev->bus->sysdata); |
740 | int irq; | ||
741 | |||
742 | irq = of_irq_parse_and_map_pci(dev, slot, pin); | ||
743 | if (!irq) | ||
744 | irq = pp->irq; | ||
739 | 745 | ||
740 | return pp->irq; | 746 | return irq; |
741 | } | 747 | } |
742 | 748 | ||
743 | static void dw_pcie_add_bus(struct pci_bus *bus) | 749 | static void dw_pcie_add_bus(struct pci_bus *bus) |
@@ -764,7 +770,7 @@ void dw_pcie_setup_rc(struct pcie_port *pp) | |||
764 | u32 membase; | 770 | u32 membase; |
765 | u32 memlimit; | 771 | u32 memlimit; |
766 | 772 | ||
767 | /* set the number of lines as 4 */ | 773 | /* set the number of lanes */ |
768 | dw_pcie_readl_rc(pp, PCIE_PORT_LINK_CONTROL, &val); | 774 | dw_pcie_readl_rc(pp, PCIE_PORT_LINK_CONTROL, &val); |
769 | val &= ~PORT_LINK_MODE_MASK; | 775 | val &= ~PORT_LINK_MODE_MASK; |
770 | switch (pp->lanes) { | 776 | switch (pp->lanes) { |