hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pci/hotplug/pciehp_pci.c
....@@ -13,20 +13,28 @@
1313 *
1414 */
1515
16
-#include <linux/module.h>
16
+#define dev_fmt(fmt) "pciehp: " fmt
17
+
1718 #include <linux/kernel.h>
1819 #include <linux/types.h>
1920 #include <linux/pci.h>
2021 #include "../pci.h"
2122 #include "pciehp.h"
2223
23
-int pciehp_configure_device(struct slot *p_slot)
24
+/**
25
+ * pciehp_configure_device() - enumerate PCI devices below a hotplug bridge
26
+ * @ctrl: PCIe hotplug controller
27
+ *
28
+ * Enumerate PCI devices below a hotplug bridge and add them to the system.
29
+ * Return 0 on success, %-EEXIST if the devices are already enumerated or
30
+ * %-ENODEV if enumeration failed.
31
+ */
32
+int pciehp_configure_device(struct controller *ctrl)
2433 {
2534 struct pci_dev *dev;
26
- struct pci_dev *bridge = p_slot->ctrl->pcie->port;
35
+ struct pci_dev *bridge = ctrl->pcie->port;
2736 struct pci_bus *parent = bridge->subordinate;
2837 int num, ret = 0;
29
- struct controller *ctrl = p_slot->ctrl;
3038
3139 pci_lock_rescan_remove();
3240
....@@ -55,24 +63,42 @@
5563
5664 pci_assign_unassigned_bridge_resources(bridge);
5765 pcie_bus_configure_settings(parent);
66
+
67
+ /*
68
+ * Release reset_lock during driver binding
69
+ * to avoid AB-BA deadlock with device_lock.
70
+ */
71
+ up_read(&ctrl->reset_lock);
5872 pci_bus_add_devices(parent);
73
+ down_read_nested(&ctrl->reset_lock, ctrl->depth);
5974
6075 out:
6176 pci_unlock_rescan_remove();
6277 return ret;
6378 }
6479
65
-void pciehp_unconfigure_device(struct slot *p_slot)
80
+/**
81
+ * pciehp_unconfigure_device() - remove PCI devices below a hotplug bridge
82
+ * @ctrl: PCIe hotplug controller
83
+ * @presence: whether the card is still present in the slot;
84
+ * true for safe removal via sysfs or an Attention Button press,
85
+ * false for surprise removal
86
+ *
87
+ * Unbind PCI devices below a hotplug bridge from their drivers and remove
88
+ * them from the system. Safely removed devices are quiesced. Surprise
89
+ * removed devices are marked as such to prevent further accesses.
90
+ */
91
+void pciehp_unconfigure_device(struct controller *ctrl, bool presence)
6692 {
67
- u8 presence = 0;
6893 struct pci_dev *dev, *temp;
69
- struct pci_bus *parent = p_slot->ctrl->pcie->port->subordinate;
94
+ struct pci_bus *parent = ctrl->pcie->port->subordinate;
7095 u16 command;
71
- struct controller *ctrl = p_slot->ctrl;
7296
7397 ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:00\n",
7498 __func__, pci_domain_nr(parent), parent->number);
75
- pciehp_get_adapter_status(p_slot, &presence);
99
+
100
+ if (!presence)
101
+ pci_walk_bus(parent, pci_dev_set_disconnected, NULL);
76102
77103 pci_lock_rescan_remove();
78104
....@@ -85,13 +111,15 @@
85111 list_for_each_entry_safe_reverse(dev, temp, &parent->devices,
86112 bus_list) {
87113 pci_dev_get(dev);
88
- if (!presence) {
89
- pci_dev_set_disconnected(dev, NULL);
90
- if (pci_has_subordinate(dev))
91
- pci_walk_bus(dev->subordinate,
92
- pci_dev_set_disconnected, NULL);
93
- }
114
+
115
+ /*
116
+ * Release reset_lock during driver unbinding
117
+ * to avoid AB-BA deadlock with device_lock.
118
+ */
119
+ up_read(&ctrl->reset_lock);
94120 pci_stop_and_remove_bus_device(dev);
121
+ down_read_nested(&ctrl->reset_lock, ctrl->depth);
122
+
95123 /*
96124 * Ensure that no new Requests will be generated from
97125 * the device.