diff mbox series

pci: Clarify power down logic

Message ID 20180731084322.25473-1-oohall@gmail.com
State Accepted
Headers show
Series pci: Clarify power down logic | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/make_check success Test make_check on branch master

Commit Message

Oliver O'Halloran July 31, 2018, 8:43 a.m. UTC
Currently pci_scan_bus() unconditionally calls pci_slot_set_power_state()
when it's finished scanning a bus. This is one of those things that
makes you go "WHAT?" when you first see it and frankly the skiboot PCI
code could do with less of that.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 core/pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Stewart Smith Aug. 2, 2018, 6:49 a.m. UTC | #1
"Oliver O'Halloran" <oohall@gmail.com> writes:
> Currently pci_scan_bus() unconditionally calls pci_slot_set_power_state()
> when it's finished scanning a bus. This is one of those things that
> makes you go "WHAT?" when you first see it and frankly the skiboot PCI
> code could do with less of that.
>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
> ---
>  core/pci.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Not being something that makes you go "WHAT?" is totally against a bunch
of our PCI code, but I'll make an exception this time :)

Merged to master as of 7a311b9dec275522d3479e019354913553b1f5bc
diff mbox series

Patch

diff --git a/core/pci.c b/core/pci.c
index 5ec7dabd94eb..cd196b5ab26b 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -406,8 +406,10 @@  static void pci_slot_set_power_state(struct phb *phb,
 
 	if (state == PCI_SLOT_POWER_OFF) {
 		/* Bail if there're something connected */
-		if (!list_empty(&pd->children))
+		if (!list_empty(&pd->children)) {
+			PCIERR(phb, pd->bdfn, "Attempted to power off slot with attached devices!\n");
 			return;
+		}
 
 		pci_slot_add_flags(slot, PCI_SLOT_FLAG_BOOTUP);
 		rc = slot->ops.get_power_state(slot, &cur_state);
@@ -920,7 +922,9 @@  uint8_t pci_scan_bus(struct phb *phb, uint8_t bus, uint8_t max_bus,
 		pci_cfg_write8(phb, pd->bdfn, PCI_CFG_SUBORDINATE_BUS, max_sub);
 		next_bus = max_sub + 1;
 
-		pci_slot_set_power_state(phb, pd, PCI_SLOT_POWER_OFF);
+		/* power off the slot if there's nothing below it */
+		if (list_empty(&pd->children))
+			pci_slot_set_power_state(phb, pd, PCI_SLOT_POWER_OFF);
 	}
 
 	return max_sub;