Skip to contentSkip to conversation

hw/acpi: some cosmetic improvements to existing code

PATCH Superseded Ani Sinha 2 participants 7 messages Jul 21, 2021 – Jul 26, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH 1/1 hw/acpi: some cosmetic improvements to existing code

All existing code using acpi_get_i386_pci_host() checks for a non-null return from this function call. This change brings the same check to acpi_pcihp_disable_root_bus() function. Also adds a comment describing why we unconditionally pass a truth value to the last argument when calling acpi_pcihp_reset() from ich9 platform.

Fixes c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
---
 hw/acpi/ich9.c  | 1 +
 hw/acpi/pcihp.c | 5 +++++
 2 files changed, 6 insertions(+)
hw/acpi/ich9.c +1 -0
index 778e27b659..58d8430eb9 100644
@@ -281,6 +281,7 @@ static void pm_reset(void *opaque)
     pm->smi_en_wmask = ~0;
 
     if (pm->use_acpi_hotplug_bridge) {
+        /* on root PCIE bus, we always use native or SHPC based hotplug */
         acpi_pcihp_reset(&pm->acpi_pci_hotplug, true);
     }
 
hw/acpi/pcihp.c +5 -0
index f4d706e47d..856c6e1b47 100644
@@ -136,6 +136,11 @@ static void acpi_pcihp_disable_root_bus(void)
         return;
     }
 
+    if (!host) {
+        root_hp_disabled = true;
+        return;
+    }
+
     bus = PCI_HOST_BRIDGE(host)->bus;
     if (bus) {
         /* setting the hotplug handler to NULL makes the bus non-hotpluggable */
Signature · 1 line
2.25.1
author
#1 lore raw

ping ...

Quoted 46 lines · Ani Sinha

All existing code using acpi_get_i386_pci_host() checks for a non-null return from this function call. This change brings the same check to acpi_pcihp_disable_root_bus() function. Also adds a comment describing why we unconditionally pass a truth value to the last argument when calling acpi_pcihp_reset() from ich9 platform.

Fixes c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
---
 hw/acpi/ich9.c  | 1 +
 hw/acpi/pcihp.c | 5 +++++
 2 files changed, 6 insertions(+)
hw/acpi/ich9.c +1 -0
index 778e27b659..58d8430eb9 100644
@@ -281,6 +281,7 @@ static void pm_reset(void *opaque)
     pm->smi_en_wmask = ~0;
 
     if (pm->use_acpi_hotplug_bridge) {
+        /* on root PCIE bus, we always use native or SHPC based hotplug */
         acpi_pcihp_reset(&pm->acpi_pci_hotplug, true);
     }
 
hw/acpi/pcihp.c +5 -1
index f4d706e47d..856c6e1b47 100644
@@ -136,6 +136,11 @@ static void acpi_pcihp_disable_root_bus(void)
         return;
     }
 
+    if (!host) {
+        root_hp_disabled = true;
+        return;
+    }
+
     bus = PCI_HOST_BRIDGE(host)->bus;
     if (bus) {
         /* setting the hotplug handler to NULL makes the bus non-hotpluggable */
--

2.25.1

#2 lore raw
In reply to Ani Sinha
Quoted 19 lines · On Wed, 21 Jul 2021 19:46:10 +0530 Ani Sinha <[email protected]> wrote:

All existing code using acpi_get_i386_pci_host() checks for a non-null return from this function call. This change brings the same check to acpi_pcihp_disable_root_bus() function. Also adds a comment describing why we unconditionally pass a truth value to the last argument when calling acpi_pcihp_reset() from ich9 platform.

Fixes c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
---
 hw/acpi/ich9.c  | 1 +
 hw/acpi/pcihp.c | 5 +++++
 2 files changed, 6 insertions(+)
hw/acpi/ich9.c +0 -0
index 778e27b659..58d8430eb9 100644

hw/acpi/ich9.c static void pm_reset(void *opaque) · line 284

Quoted 4 lines
hw/acpi/ich9.c +1 -0
@@ -281,6 +281,7 @@ static void pm_reset(void *opaque)
     pm->smi_en_wmask = ~0;
 
     if (pm->use_acpi_hotplug_bridge) {
+        /* on root PCIE bus, we always use native or SHPC based hotplug */

I had an impression that root bus doesn't support hotplug at all, and to have hotplug there one should attach a root-port to root bus at start up time.

Quoted 8 lines
hw/acpi/ich9.c +0 -0
         acpi_pcihp_reset(&pm->acpi_pci_hotplug, true);
     }
 
hw/acpi/pcihp.c +0 -0
index f4d706e47d..856c6e1b47 100644

hw/acpi/pcihp.c static void acpi_pcihp_disable_root_bus(void) · line 142

Quoted 7 lines
hw/acpi/pcihp.c +4 -0
@@ -136,6 +136,11 @@ static void acpi_pcihp_disable_root_bus(void)
         return;
     }
 
+    if (!host) {
+        root_hp_disabled = true;
+        return;
+    }

It should be a separate patch,
when this could return NULL?
If it should never be null then assert here would be better.

Quoted 4 lines
hw/acpi/pcihp.c +1 -0
+
     bus = PCI_HOST_BRIDGE(host)->bus;
     if (bus) {
         /* setting the hotplug handler to NULL makes the bus non-hotpluggable */
author
#3 lore raw
Quoted 24 lines · Igor Mammedov
Quoted 21 lines · On Wed, 21 Jul 2021 19:46:10 +0530 Ani Sinha <[email protected]> wrote:

All existing code using acpi_get_i386_pci_host() checks for a non-null return from this function call. This change brings the same check to acpi_pcihp_disable_root_bus() function. Also adds a comment describing why we unconditionally pass a truth value to the last argument when calling acpi_pcihp_reset() from ich9 platform.

Fixes c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
---
 hw/acpi/ich9.c  | 1 +
 hw/acpi/pcihp.c | 5 +++++
 2 files changed, 6 insertions(+)
hw/acpi/ich9.c +0 -0
index 778e27b659..58d8430eb9 100644
@@ -281,6 +281,7 @@ static void pm_reset(void *opaque)
     pm->smi_en_wmask = ~0;
 
Quoted 5 lines

hw/acpi/ich9.c static void pm_reset(void *opaque) · line 284

Quoted 2 lines
hw/acpi/ich9.c +1 -0
     if (pm->use_acpi_hotplug_bridge) {
+        /* on root PCIE bus, we always use native or SHPC based hotplug */

I had an impression that root bus doesn't support hotplug at all, and to have hotplug there one should attach a root-port to root bus at start up time.

I think you are right. However, I will let others confirm this and update the comment accordingly in a separate patch.

Quoted 12 lines
Quoted 12 lines
hw/acpi/ich9.c +0 -0
         acpi_pcihp_reset(&pm->acpi_pci_hotplug, true);
     }
 
hw/acpi/pcihp.c +0 -0
index f4d706e47d..856c6e1b47 100644
@@ -136,6 +136,11 @@ static void acpi_pcihp_disable_root_bus(void)
         return;
     }
 
Quoted 7 lines

hw/acpi/pcihp.c static void acpi_pcihp_disable_root_bus(void) · line 142

Quoted 4 lines
hw/acpi/pcihp.c +4 -0
+    if (!host) {
+        root_hp_disabled = true;
+        return;
+    }

It should be a separate patch,
when this could return NULL?
If it should never be null then assert here would be better.

I have sent a v2 without the comment addition. I left the code this way because everywhere else, the code checking host for NULL value is similar. I wanted to keep the symmetry. However, if you strongly feel about the assertion, I will send a v3.

Quoted 7 lines
Quoted 5 lines
hw/acpi/pcihp.c +1 -0
+
     bus = PCI_HOST_BRIDGE(host)->bus;
     if (bus) {
         /* setting the hotplug handler to NULL makes the bus non-hotpluggable */
#4 lore raw
Quoted 56 lines · On Mon, 26 Jul 2021 18:26:28 +0530 (IST) Ani Sinha <[email protected]> wrote:
Quoted 24 lines · Igor Mammedov
Quoted 21 lines · On Wed, 21 Jul 2021 19:46:10 +0530 Ani Sinha <[email protected]> wrote:

All existing code using acpi_get_i386_pci_host() checks for a non-null return from this function call. This change brings the same check to acpi_pcihp_disable_root_bus() function. Also adds a comment describing why we unconditionally pass a truth value to the last argument when calling acpi_pcihp_reset() from ich9 platform.

Fixes c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
---
 hw/acpi/ich9.c  | 1 +
 hw/acpi/pcihp.c | 5 +++++
 2 files changed, 6 insertions(+)
hw/acpi/ich9.c +0 -0
index 778e27b659..58d8430eb9 100644
@@ -281,6 +281,7 @@ static void pm_reset(void *opaque)
     pm->smi_en_wmask = ~0;
 
Quoted 5 lines

hw/acpi/ich9.c static void pm_reset(void *opaque) · line 284

Quoted 2 lines
hw/acpi/ich9.c +1 -0
     if (pm->use_acpi_hotplug_bridge) {
+        /* on root PCIE bus, we always use native or SHPC based hotplug */  

I had an impression that root bus doesn't support hotplug at all, and to have hotplug there one should attach a root-port to root bus at start up time.

I think you are right. However, I will let others confirm this and update the comment accordingly in a separate patch.

Quoted 12 lines
Quoted 12 lines
hw/acpi/ich9.c +0 -0
         acpi_pcihp_reset(&pm->acpi_pci_hotplug, true);
     }
 
hw/acpi/pcihp.c +0 -0
index f4d706e47d..856c6e1b47 100644
@@ -136,6 +136,11 @@ static void acpi_pcihp_disable_root_bus(void)
         return;
     }
 
Quoted 7 lines

hw/acpi/pcihp.c static void acpi_pcihp_disable_root_bus(void) · line 142

Quoted 4 lines
hw/acpi/pcihp.c +4 -0
+    if (!host) {
+        root_hp_disabled = true;
+        return;
+    }  

It should be a separate patch,
when this could return NULL?
If it should never be null then assert here would be better.

Quoted 4 lines

I have sent a v2 without the comment addition. I left the code this way because everywhere else, the code checking host for NULL value is similar. I wanted to keep the symmetry. However, if you strongly feel about the assertion, I will send a v3.

So the first thing is to confirm if NULL return value is valid or not. When it clear we can decide whether copy existing check like you do or replace all such checks with asserts.

Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
hw/acpi/pcihp.c +1 -0
+
     bus = PCI_HOST_BRIDGE(host)->bus;
     if (bus) {
         /* setting the hotplug handler to NULL makes the bus non-hotpluggable */  
author
#5 lore raw
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 7 lines
hw/acpi/pcihp.c +0 -0
index f4d706e47d..856c6e1b47 100644

hw/acpi/pcihp.c static void acpi_pcihp_disable_root_bus(void) · line 142

Quoted 7 lines
hw/acpi/pcihp.c +4 -0
@@ -136,6 +136,11 @@ static void acpi_pcihp_disable_root_bus(void)
         return;
     }
 
+    if (!host) {
+        root_hp_disabled = true;
+        return;
+    }

It should be a separate patch,
when this could return NULL?
If it should never be null then assert here would be better.

Quoted 8 lines
Quoted 4 lines

I have sent a v2 without the comment addition. I left the code this way because everywhere else, the code checking host for NULL value is similar. I wanted to keep the symmetry. However, if you strongly feel about the assertion, I will send a v3.

So the first thing is to confirm if NULL return value is valid or not. When it clear we can decide whether copy existing check like you do or replace all such checks with asserts.

I thought about this a little and I am now inclined to put assertions everywhere. On i386 we have either q35 or i440fx host bridges. Having a null host bridge does not sound right. I will make the change, build and make check before sending out v3 with assertions.

author
#6 lore raw
In reply to Igor Mammedov
Quoted 24 lines · Igor Mammedov
Quoted 21 lines · On Wed, 21 Jul 2021 19:46:10 +0530 Ani Sinha <[email protected]> wrote:

All existing code using acpi_get_i386_pci_host() checks for a non-null return from this function call. This change brings the same check to acpi_pcihp_disable_root_bus() function. Also adds a comment describing why we unconditionally pass a truth value to the last argument when calling acpi_pcihp_reset() from ich9 platform.

Fixes c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
---
 hw/acpi/ich9.c  | 1 +
 hw/acpi/pcihp.c | 5 +++++
 2 files changed, 6 insertions(+)
hw/acpi/ich9.c +0 -0
index 778e27b659..58d8430eb9 100644
@@ -281,6 +281,7 @@ static void pm_reset(void *opaque)
     pm->smi_en_wmask = ~0;
 
Quoted 5 lines

hw/acpi/ich9.c static void pm_reset(void *opaque) · line 284

Quoted 2 lines
hw/acpi/ich9.c +1 -0
     if (pm->use_acpi_hotplug_bridge) {
+        /* on root PCIE bus, we always use native or SHPC based hotplug */

I had an impression that root bus doesn't support hotplug at all, and to have hotplug there one should attach a root-port to root bus at start up time.

Yes this is correct.
https://github.com/qemu/qemu/blob/master/docs/pcie.txt
https://libvirt.org/pci-hotplug.html

I will update the comment accordingly.