diff options
author | Frederic Barrat <fbarrat@linux.ibm.com> | 2019-10-09 21:37:56 +0200 |
---|---|---|
committer | Oliver O'Halloran <oohall@gmail.com> | 2019-10-22 17:31:18 +1100 |
commit | f6f247a8c46848a0c42fec7cab27f09cd8f2d5e2 (patch) | |
tree | e1a6561f77b0bc9321b0723a4aaa85be87c91e11 | |
parent | d75e82dbfbb9443efeb3f9a5921ac23605aab469 (diff) | |
download | skiboot-f6f247a8c46848a0c42fec7cab27f09cd8f2d5e2.zip skiboot-f6f247a8c46848a0c42fec7cab27f09cd8f2d5e2.tar.gz skiboot-f6f247a8c46848a0c42fec7cab27f09cd8f2d5e2.tar.bz2 |
core/pci: Refactor common paths on slot hotplug
Refactor code executed to remove or rescan devices when a slot power
state changes, synchronously or asynchronously through a timer
callback. It will be more useful in a future patch.
No functional changes.
Reviewed-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
-rw-r--r-- | core/pci-opal.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/core/pci-opal.c b/core/pci-opal.c index 213a725..d520960 100644 --- a/core/pci-opal.c +++ b/core/pci-opal.c @@ -647,11 +647,30 @@ static int64_t opal_pci_get_power_state(uint64_t id, uint64_t data) } opal_call(OPAL_PCI_GET_POWER_STATE, opal_pci_get_power_state, 2); +static void rescan_slot_devices(struct pci_slot *slot) +{ + struct phb *phb = slot->phb; + struct pci_device *pd = slot->pd; + + slot->ops.prepare_link_change(slot, true); + pci_scan_bus(phb, pd->secondary_bus, + pd->subordinate_bus, &pd->children, pd, true); + pci_add_device_nodes(phb, &pd->children, pd->dn, + &phb->lstate, 0); +} + +static void remove_slot_devices(struct pci_slot *slot) +{ + struct phb *phb = slot->phb; + struct pci_device *pd = slot->pd; + + pci_remove_bus(phb, &pd->children); +} + static void set_power_timer(struct timer *t __unused, void *data, uint64_t now __unused) { struct pci_slot *slot = data; - struct phb *phb = slot->phb; struct pci_device *pd = slot->pd; struct dt_node *dn = pd->dn; uint8_t link; @@ -670,7 +689,7 @@ static void set_power_timer(struct timer *t __unused, void *data, break; case PCI_SLOT_STATE_SPOWER_DONE: if (slot->power_state == OPAL_PCI_SLOT_POWER_OFF) { - pci_remove_bus(phb, &pd->children); + remove_slot_devices(slot); pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL); opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, slot->async_token, dn->phandle, @@ -682,12 +701,7 @@ static void set_power_timer(struct timer *t __unused, void *data, if (slot->ops.get_link_state(slot, &link) != OPAL_SUCCESS) link = 0; if (link) { - slot->ops.prepare_link_change(slot, true); - pci_scan_bus(phb, pd->secondary_bus, - pd->subordinate_bus, - &pd->children, pd, true); - pci_add_device_nodes(phb, &pd->children, dn, - &phb->lstate, 0); + rescan_slot_devices(slot); pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL); opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, slot->async_token, dn->phandle, @@ -782,15 +796,10 @@ static int64_t opal_pci_set_power_state(uint64_t async_token, init_timer(&slot->timer, set_power_timer, slot); schedule_timer(&slot->timer, msecs_to_tb(10)); } else if (rc == OPAL_SUCCESS) { - if (*state == OPAL_PCI_SLOT_POWER_OFF) { - pci_remove_bus(phb, &pd->children); - } else { - slot->ops.prepare_link_change(slot, true); - pci_scan_bus(phb, pd->secondary_bus, - pd->subordinate_bus, &pd->children, pd, true); - pci_add_device_nodes(phb, &pd->children, pd->dn, - &phb->lstate, 0); - } + if (*state == OPAL_PCI_SLOT_POWER_OFF) + remove_slot_devices(slot); + else + rescan_slot_devices(slot); } phb_unlock(phb); |