aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/bus.c43
-rw-r--r--drivers/pci/pci.c40
-rw-r--r--drivers/pci/pci.h1
-rw-r--r--drivers/pci/quirks.c14
-rw-r--r--drivers/pci/setup-bus.c56
5 files changed, 138 insertions, 16 deletions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 73aef51a28f0..8fb16188cd82 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -228,6 +228,49 @@ int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
228} 228}
229EXPORT_SYMBOL(pci_bus_alloc_resource); 229EXPORT_SYMBOL(pci_bus_alloc_resource);
230 230
231/*
232 * The @idx resource of @dev should be a PCI-PCI bridge window. If this
233 * resource fits inside a window of an upstream bridge, do nothing. If it
234 * overlaps an upstream window but extends outside it, clip the resource so
235 * it fits completely inside.
236 */
237bool pci_bus_clip_resource(struct pci_dev *dev, int idx)
238{
239 struct pci_bus *bus = dev->bus;
240 struct resource *res = &dev->resource[idx];
241 struct resource orig_res = *res;
242 struct resource *r;
243 int i;
244
245 pci_bus_for_each_resource(bus, r, i) {
246 resource_size_t start, end;
247
248 if (!r)
249 continue;
250
251 if (resource_type(res) != resource_type(r))
252 continue;
253
254 start = max(r->start, res->start);
255 end = min(r->end, res->end);
256
257 if (start > end)
258 continue; /* no overlap */
259
260 if (res->start == start && res->end == end)
261 return false; /* no change */
262
263 res->start = start;
264 res->end = end;
265 dev_printk(KERN_DEBUG, &dev->dev, "%pR clipped to %pR\n",
266 &orig_res, res);
267
268 return true;
269 }
270
271 return false;
272}
273
231void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } 274void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
232 275
233/** 276/**
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index cab05f31223f..e9d4fd861ba1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3271,7 +3271,8 @@ static int pci_parent_bus_reset(struct pci_dev *dev, int probe)
3271{ 3271{
3272 struct pci_dev *pdev; 3272 struct pci_dev *pdev;
3273 3273
3274 if (pci_is_root_bus(dev->bus) || dev->subordinate || !dev->bus->self) 3274 if (pci_is_root_bus(dev->bus) || dev->subordinate ||
3275 !dev->bus->self || dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
3275 return -ENOTTY; 3276 return -ENOTTY;
3276 3277
3277 list_for_each_entry(pdev, &dev->bus->devices, bus_list) 3278 list_for_each_entry(pdev, &dev->bus->devices, bus_list)
@@ -3305,7 +3306,8 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
3305{ 3306{
3306 struct pci_dev *pdev; 3307 struct pci_dev *pdev;
3307 3308
3308 if (dev->subordinate || !dev->slot) 3309 if (dev->subordinate || !dev->slot ||
3310 dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
3309 return -ENOTTY; 3311 return -ENOTTY;
3310 3312
3311 list_for_each_entry(pdev, &dev->bus->devices, bus_list) 3313 list_for_each_entry(pdev, &dev->bus->devices, bus_list)
@@ -3557,6 +3559,20 @@ int pci_try_reset_function(struct pci_dev *dev)
3557} 3559}
3558EXPORT_SYMBOL_GPL(pci_try_reset_function); 3560EXPORT_SYMBOL_GPL(pci_try_reset_function);
3559 3561
3562/* Do any devices on or below this bus prevent a bus reset? */
3563static bool pci_bus_resetable(struct pci_bus *bus)
3564{
3565 struct pci_dev *dev;
3566
3567 list_for_each_entry(dev, &bus->devices, bus_list) {
3568 if (dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET ||
3569 (dev->subordinate && !pci_bus_resetable(dev->subordinate)))
3570 return false;
3571 }
3572
3573 return true;
3574}
3575
3560/* Lock devices from the top of the tree down */ 3576/* Lock devices from the top of the tree down */
3561static void pci_bus_lock(struct pci_bus *bus) 3577static void pci_bus_lock(struct pci_bus *bus)
3562{ 3578{
@@ -3607,6 +3623,22 @@ unlock:
3607 return 0; 3623 return 0;
3608} 3624}
3609 3625
3626/* Do any devices on or below this slot prevent a bus reset? */
3627static bool pci_slot_resetable(struct pci_slot *slot)
3628{
3629 struct pci_dev *dev;
3630
3631 list_for_each_entry(dev, &slot->bus->devices, bus_list) {
3632 if (!dev->slot || dev->slot != slot)
3633 continue;
3634 if (dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET ||
3635 (dev->subordinate && !pci_bus_resetable(dev->subordinate)))
3636 return false;
3637 }
3638
3639 return true;
3640}
3641
3610/* Lock devices from the top of the tree down */ 3642/* Lock devices from the top of the tree down */
3611static void pci_slot_lock(struct pci_slot *slot) 3643static void pci_slot_lock(struct pci_slot *slot)
3612{ 3644{
@@ -3728,7 +3760,7 @@ static int pci_slot_reset(struct pci_slot *slot, int probe)
3728{ 3760{
3729 int rc; 3761 int rc;
3730 3762
3731 if (!slot) 3763 if (!slot || !pci_slot_resetable(slot))
3732 return -ENOTTY; 3764 return -ENOTTY;
3733 3765
3734 if (!probe) 3766 if (!probe)
@@ -3820,7 +3852,7 @@ EXPORT_SYMBOL_GPL(pci_try_reset_slot);
3820 3852
3821static int pci_bus_reset(struct pci_bus *bus, int probe) 3853static int pci_bus_reset(struct pci_bus *bus, int probe)
3822{ 3854{
3823 if (!bus->self) 3855 if (!bus->self || !pci_bus_resetable(bus))
3824 return -ENOTTY; 3856 return -ENOTTY;
3825 3857
3826 if (probe) 3858 if (probe)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 8aff29a804ff..d54632a1db43 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -208,6 +208,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus,
208void __pci_bus_assign_resources(const struct pci_bus *bus, 208void __pci_bus_assign_resources(const struct pci_bus *bus,
209 struct list_head *realloc_head, 209 struct list_head *realloc_head,
210 struct list_head *fail_head); 210 struct list_head *fail_head);
211bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
211 212
212/** 213/**
213 * pci_ari_enabled - query ARI forwarding status 214 * pci_ari_enabled - query ARI forwarding status
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index ed6f89b6efe5..e52356aa09b8 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3028,6 +3028,20 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_REALTEK, 0x8169,
3028DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MELLANOX, PCI_ANY_ID, 3028DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MELLANOX, PCI_ANY_ID,
3029 quirk_broken_intx_masking); 3029 quirk_broken_intx_masking);
3030 3030
3031static void quirk_no_bus_reset(struct pci_dev *dev)
3032{
3033 dev->dev_flags |= PCI_DEV_FLAGS_NO_BUS_RESET;
3034}
3035
3036/*
3037 * Atheros AR93xx chips do not behave after a bus reset. The device will
3038 * throw a Link Down error on AER-capable systems and regardless of AER,
3039 * config space of the device is never accessible again and typically
3040 * causes the system to hang or reset when access is attempted.
3041 * http://www.spinics.net/lists/linux-pci/msg34797.html
3042 */
3043DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0030, quirk_no_bus_reset);
3044
3031#ifdef CONFIG_ACPI 3045#ifdef CONFIG_ACPI
3032/* 3046/*
3033 * Apple: Shutdown Cactus Ridge Thunderbolt controller. 3047 * Apple: Shutdown Cactus Ridge Thunderbolt controller.
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 0482235eee92..e3e17f3c0f0f 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -530,9 +530,8 @@ EXPORT_SYMBOL(pci_setup_cardbus);
530 config space writes, so it's quite possible that an I/O window of 530 config space writes, so it's quite possible that an I/O window of
531 the bridge will have some undesirable address (e.g. 0) after the 531 the bridge will have some undesirable address (e.g. 0) after the
532 first write. Ditto 64-bit prefetchable MMIO. */ 532 first write. Ditto 64-bit prefetchable MMIO. */
533static void pci_setup_bridge_io(struct pci_bus *bus) 533static void pci_setup_bridge_io(struct pci_dev *bridge)
534{ 534{
535 struct pci_dev *bridge = bus->self;
536 struct resource *res; 535 struct resource *res;
537 struct pci_bus_region region; 536 struct pci_bus_region region;
538 unsigned long io_mask; 537 unsigned long io_mask;
@@ -545,7 +544,7 @@ static void pci_setup_bridge_io(struct pci_bus *bus)
545 io_mask = PCI_IO_1K_RANGE_MASK; 544 io_mask = PCI_IO_1K_RANGE_MASK;
546 545
547 /* Set up the top and bottom of the PCI I/O segment for this bus. */ 546 /* Set up the top and bottom of the PCI I/O segment for this bus. */
548 res = bus->resource[0]; 547 res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0];
549 pcibios_resource_to_bus(bridge->bus, &region, res); 548 pcibios_resource_to_bus(bridge->bus, &region, res);
550 if (res->flags & IORESOURCE_IO) { 549 if (res->flags & IORESOURCE_IO) {
551 pci_read_config_word(bridge, PCI_IO_BASE, &l); 550 pci_read_config_word(bridge, PCI_IO_BASE, &l);
@@ -568,15 +567,14 @@ static void pci_setup_bridge_io(struct pci_bus *bus)
568 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16); 567 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16);
569} 568}
570 569
571static void pci_setup_bridge_mmio(struct pci_bus *bus) 570static void pci_setup_bridge_mmio(struct pci_dev *bridge)
572{ 571{
573 struct pci_dev *bridge = bus->self;
574 struct resource *res; 572 struct resource *res;
575 struct pci_bus_region region; 573 struct pci_bus_region region;
576 u32 l; 574 u32 l;
577 575
578 /* Set up the top and bottom of the PCI Memory segment for this bus. */ 576 /* Set up the top and bottom of the PCI Memory segment for this bus. */
579 res = bus->resource[1]; 577 res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1];
580 pcibios_resource_to_bus(bridge->bus, &region, res); 578 pcibios_resource_to_bus(bridge->bus, &region, res);
581 if (res->flags & IORESOURCE_MEM) { 579 if (res->flags & IORESOURCE_MEM) {
582 l = (region.start >> 16) & 0xfff0; 580 l = (region.start >> 16) & 0xfff0;
@@ -588,9 +586,8 @@ static void pci_setup_bridge_mmio(struct pci_bus *bus)
588 pci_write_config_dword(bridge, PCI_MEMORY_BASE, l); 586 pci_write_config_dword(bridge, PCI_MEMORY_BASE, l);
589} 587}
590 588
591static void pci_setup_bridge_mmio_pref(struct pci_bus *bus) 589static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge)
592{ 590{
593 struct pci_dev *bridge = bus->self;
594 struct resource *res; 591 struct resource *res;
595 struct pci_bus_region region; 592 struct pci_bus_region region;
596 u32 l, bu, lu; 593 u32 l, bu, lu;
@@ -602,7 +599,7 @@ static void pci_setup_bridge_mmio_pref(struct pci_bus *bus)
602 599
603 /* Set up PREF base/limit. */ 600 /* Set up PREF base/limit. */
604 bu = lu = 0; 601 bu = lu = 0;
605 res = bus->resource[2]; 602 res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2];
606 pcibios_resource_to_bus(bridge->bus, &region, res); 603 pcibios_resource_to_bus(bridge->bus, &region, res);
607 if (res->flags & IORESOURCE_PREFETCH) { 604 if (res->flags & IORESOURCE_PREFETCH) {
608 l = (region.start >> 16) & 0xfff0; 605 l = (region.start >> 16) & 0xfff0;
@@ -630,13 +627,13 @@ static void __pci_setup_bridge(struct pci_bus *bus, unsigned long type)
630 &bus->busn_res); 627 &bus->busn_res);
631 628
632 if (type & IORESOURCE_IO) 629 if (type & IORESOURCE_IO)
633 pci_setup_bridge_io(bus); 630 pci_setup_bridge_io(bridge);
634 631
635 if (type & IORESOURCE_MEM) 632 if (type & IORESOURCE_MEM)
636 pci_setup_bridge_mmio(bus); 633 pci_setup_bridge_mmio(bridge);
637 634
638 if (type & IORESOURCE_PREFETCH) 635 if (type & IORESOURCE_PREFETCH)
639 pci_setup_bridge_mmio_pref(bus); 636 pci_setup_bridge_mmio_pref(bridge);
640 637
641 pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl); 638 pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
642} 639}
@@ -649,6 +646,41 @@ void pci_setup_bridge(struct pci_bus *bus)
649 __pci_setup_bridge(bus, type); 646 __pci_setup_bridge(bus, type);
650} 647}
651 648
649
650int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
651{
652 if (i < PCI_BRIDGE_RESOURCES || i > PCI_BRIDGE_RESOURCE_END)
653 return 0;
654
655 if (pci_claim_resource(bridge, i) == 0)
656 return 0; /* claimed the window */
657
658 if ((bridge->class >> 8) != PCI_CLASS_BRIDGE_PCI)
659 return 0;
660
661 if (!pci_bus_clip_resource(bridge, i))
662 return -EINVAL; /* clipping didn't change anything */
663
664 switch (i - PCI_BRIDGE_RESOURCES) {
665 case 0:
666 pci_setup_bridge_io(bridge);
667 break;
668 case 1:
669 pci_setup_bridge_mmio(bridge);
670 break;
671 case 2:
672 pci_setup_bridge_mmio_pref(bridge);
673 break;
674 default:
675 return -EINVAL;
676 }
677
678 if (pci_claim_resource(bridge, i) == 0)
679 return 0; /* claimed a smaller window */
680
681 return -EINVAL;
682}
683
652/* Check whether the bridge supports optional I/O and 684/* Check whether the bridge supports optional I/O and
653 prefetchable memory ranges. If not, the respective 685 prefetchable memory ranges. If not, the respective
654 base/limit registers must be read-only and read as 0. */ 686 base/limit registers must be read-only and read as 0. */