aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug
diff options
context:
space:
mode:
authorYijing Wang <wangyijing@huawei.com>2013-01-14 22:12:19 -0500
committerBjorn Helgaas <bhelgaas@google.com>2013-01-25 11:21:10 -0500
commitba518e3c177547dfebf7fa7252cea0c850e7ce25 (patch)
treed4095f6395b8159a8301ee155ce81a5a33f9193b /drivers/pci/hotplug
parentb1bd58e448f28531207124eea3fd43b81d6f8d06 (diff)
PCI: pciehp: Iterate over all devices in slot, not functions 0-7
Currently, we enumerate devices in a slot with pci_scan_slot(), then iterate through all the devices we found by looking for functions 0-7. But that's wrong for ARI devices, which may have function numbers up to 255. This means that when we hot-add an ARI device, pciehp only initializes functions 0-7, and other functions don't work correctly. Additionally, if we hot-remove the device, pciehp only removes functions 0-7, leaving stale pci_dev structures for any other functions. This patch fixes the problem by iterating over devices in a slot by using the upstream bridge's "bus->devices" list instead. [bhelgaas: changelog] Signed-off-by: Yijing Wang <wangyijing@huawei.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/hotplug')
-rw-r--r--drivers/pci/hotplug/pciehp_pci.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
index 09cecaf450c5..aac7a40e4a4a 100644
--- a/drivers/pci/hotplug/pciehp_pci.c
+++ b/drivers/pci/hotplug/pciehp_pci.c
@@ -39,7 +39,7 @@ int pciehp_configure_device(struct slot *p_slot)
39 struct pci_dev *dev; 39 struct pci_dev *dev;
40 struct pci_dev *bridge = p_slot->ctrl->pcie->port; 40 struct pci_dev *bridge = p_slot->ctrl->pcie->port;
41 struct pci_bus *parent = bridge->subordinate; 41 struct pci_bus *parent = bridge->subordinate;
42 int num, fn; 42 int num;
43 struct controller *ctrl = p_slot->ctrl; 43 struct controller *ctrl = p_slot->ctrl;
44 44
45 dev = pci_get_slot(parent, PCI_DEVFN(0, 0)); 45 dev = pci_get_slot(parent, PCI_DEVFN(0, 0));
@@ -57,28 +57,18 @@ int pciehp_configure_device(struct slot *p_slot)
57 return -ENODEV; 57 return -ENODEV;
58 } 58 }
59 59
60 for (fn = 0; fn < 8; fn++) { 60 list_for_each_entry(dev, &parent->devices, bus_list)
61 dev = pci_get_slot(parent, PCI_DEVFN(0, fn));
62 if (!dev)
63 continue;
64 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 61 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) ||
65 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) 62 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS))
66 pci_hp_add_bridge(dev); 63 pci_hp_add_bridge(dev);
67 pci_dev_put(dev);
68 }
69 64
70 pci_assign_unassigned_bridge_resources(bridge); 65 pci_assign_unassigned_bridge_resources(bridge);
71 66
72 for (fn = 0; fn < 8; fn++) { 67 list_for_each_entry(dev, &parent->devices, bus_list) {
73 dev = pci_get_slot(parent, PCI_DEVFN(0, fn)); 68 if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY)
74 if (!dev)
75 continue; 69 continue;
76 if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) { 70
77 pci_dev_put(dev);
78 continue;
79 }
80 pci_configure_slot(dev); 71 pci_configure_slot(dev);
81 pci_dev_put(dev);
82 } 72 }
83 73
84 pci_bus_add_devices(parent); 74 pci_bus_add_devices(parent);
@@ -89,9 +79,9 @@ int pciehp_configure_device(struct slot *p_slot)
89int pciehp_unconfigure_device(struct slot *p_slot) 79int pciehp_unconfigure_device(struct slot *p_slot)
90{ 80{
91 int ret, rc = 0; 81 int ret, rc = 0;
92 int j;
93 u8 bctl = 0; 82 u8 bctl = 0;
94 u8 presence = 0; 83 u8 presence = 0;
84 struct pci_dev *dev, *temp;
95 struct pci_bus *parent = p_slot->ctrl->pcie->port->subordinate; 85 struct pci_bus *parent = p_slot->ctrl->pcie->port->subordinate;
96 u16 command; 86 u16 command;
97 struct controller *ctrl = p_slot->ctrl; 87 struct controller *ctrl = p_slot->ctrl;
@@ -102,33 +92,31 @@ int pciehp_unconfigure_device(struct slot *p_slot)
102 if (ret) 92 if (ret)
103 presence = 0; 93 presence = 0;
104 94
105 for (j = 0; j < 8; j++) { 95 list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) {
106 struct pci_dev *temp = pci_get_slot(parent, PCI_DEVFN(0, j)); 96 pci_dev_get(dev);
107 if (!temp) 97 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE && presence) {
108 continue; 98 pci_read_config_byte(dev, PCI_BRIDGE_CONTROL, &bctl);
109 if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE && presence) {
110 pci_read_config_byte(temp, PCI_BRIDGE_CONTROL, &bctl);
111 if (bctl & PCI_BRIDGE_CTL_VGA) { 99 if (bctl & PCI_BRIDGE_CTL_VGA) {
112 ctrl_err(ctrl, 100 ctrl_err(ctrl,
113 "Cannot remove display device %s\n", 101 "Cannot remove display device %s\n",
114 pci_name(temp)); 102 pci_name(dev));
115 pci_dev_put(temp); 103 pci_dev_put(dev);
116 rc = -EINVAL; 104 rc = -EINVAL;
117 break; 105 break;
118 } 106 }
119 } 107 }
120 pci_stop_and_remove_bus_device(temp); 108 pci_stop_and_remove_bus_device(dev);
121 /* 109 /*
122 * Ensure that no new Requests will be generated from 110 * Ensure that no new Requests will be generated from
123 * the device. 111 * the device.
124 */ 112 */
125 if (presence) { 113 if (presence) {
126 pci_read_config_word(temp, PCI_COMMAND, &command); 114 pci_read_config_word(dev, PCI_COMMAND, &command);
127 command &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_SERR); 115 command &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_SERR);
128 command |= PCI_COMMAND_INTX_DISABLE; 116 command |= PCI_COMMAND_INTX_DISABLE;
129 pci_write_config_word(temp, PCI_COMMAND, command); 117 pci_write_config_word(dev, PCI_COMMAND, command);
130 } 118 }
131 pci_dev_put(temp); 119 pci_dev_put(dev);
132 } 120 }
133 121
134 return rc; 122 return rc;