.. | .. |
---|
13 | 13 | * |
---|
14 | 14 | */ |
---|
15 | 15 | |
---|
16 | | -#include <linux/module.h> |
---|
| 16 | +#define dev_fmt(fmt) "pciehp: " fmt |
---|
| 17 | + |
---|
17 | 18 | #include <linux/kernel.h> |
---|
18 | 19 | #include <linux/types.h> |
---|
19 | 20 | #include <linux/pci.h> |
---|
20 | 21 | #include "../pci.h" |
---|
21 | 22 | #include "pciehp.h" |
---|
22 | 23 | |
---|
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) |
---|
24 | 33 | { |
---|
25 | 34 | struct pci_dev *dev; |
---|
26 | | - struct pci_dev *bridge = p_slot->ctrl->pcie->port; |
---|
| 35 | + struct pci_dev *bridge = ctrl->pcie->port; |
---|
27 | 36 | struct pci_bus *parent = bridge->subordinate; |
---|
28 | 37 | int num, ret = 0; |
---|
29 | | - struct controller *ctrl = p_slot->ctrl; |
---|
30 | 38 | |
---|
31 | 39 | pci_lock_rescan_remove(); |
---|
32 | 40 | |
---|
.. | .. |
---|
55 | 63 | |
---|
56 | 64 | pci_assign_unassigned_bridge_resources(bridge); |
---|
57 | 65 | 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); |
---|
58 | 72 | pci_bus_add_devices(parent); |
---|
| 73 | + down_read_nested(&ctrl->reset_lock, ctrl->depth); |
---|
59 | 74 | |
---|
60 | 75 | out: |
---|
61 | 76 | pci_unlock_rescan_remove(); |
---|
62 | 77 | return ret; |
---|
63 | 78 | } |
---|
64 | 79 | |
---|
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) |
---|
66 | 92 | { |
---|
67 | | - u8 presence = 0; |
---|
68 | 93 | 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; |
---|
70 | 95 | u16 command; |
---|
71 | | - struct controller *ctrl = p_slot->ctrl; |
---|
72 | 96 | |
---|
73 | 97 | ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:00\n", |
---|
74 | 98 | __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); |
---|
76 | 102 | |
---|
77 | 103 | pci_lock_rescan_remove(); |
---|
78 | 104 | |
---|
.. | .. |
---|
85 | 111 | list_for_each_entry_safe_reverse(dev, temp, &parent->devices, |
---|
86 | 112 | bus_list) { |
---|
87 | 113 | 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); |
---|
94 | 120 | pci_stop_and_remove_bus_device(dev); |
---|
| 121 | + down_read_nested(&ctrl->reset_lock, ctrl->depth); |
---|
| 122 | + |
---|
95 | 123 | /* |
---|
96 | 124 | * Ensure that no new Requests will be generated from |
---|
97 | 125 | * the device. |
---|