[PATCH 08/10] hw/hppa: PCI devices depend on availability of PCI bus

deller@kernel.org posted 10 patches 3 weeks, 6 days ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, Fam Zheng <fam@euphon.net>
There is a newer version of this series
[PATCH 08/10] hw/hppa: PCI devices depend on availability of PCI bus
Posted by deller@kernel.org 3 weeks, 6 days ago
From: Helge Deller <deller@gmx.de>

Only create the PCI serial ports (DIVA) and PCI network cards when there is
actually a PCI bus. The shortly added 715 machine will not have a PCI bus, so
avoid creating further PCI devices.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 hw/hppa/machine.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index bec5a86f24..b6cdbc74ba 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -387,11 +387,13 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
                         enable_lasi_lan());
     }
 
-    pci_init_nic_devices(pci_bus, mc->default_nic);
+    if (pci_bus) {
+        pci_init_nic_devices(pci_bus, mc->default_nic);
+    }
 
     /* BMC board: HP Diva GSP */
-    dev = qdev_new("diva-gsp");
-    if (!object_property_get_bool(OBJECT(dev), "disable", NULL)) {
+    dev = pci_bus ? qdev_new("diva-gsp") : NULL;
+    if (dev && !object_property_get_bool(OBJECT(dev), "disable", NULL)) {
         pci_dev = pci_new_multifunction(PCI_DEVFN(2, 0), "diva-gsp");
         if (!lasi_dev) {
             /* bind default keyboard/serial to Diva card */
-- 
2.51.0
Re: [PATCH 08/10] hw/hppa: PCI devices depend on availability of PCI bus
Posted by Richard Henderson 3 weeks, 1 day ago
On 10/17/25 15:06, deller@kernel.org wrote:
> From: Helge Deller <deller@gmx.de>
> 
> Only create the PCI serial ports (DIVA) and PCI network cards when there is
> actually a PCI bus. The shortly added 715 machine will not have a PCI bus, so
> avoid creating further PCI devices.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
>   hw/hppa/machine.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
> index bec5a86f24..b6cdbc74ba 100644
> --- a/hw/hppa/machine.c
> +++ b/hw/hppa/machine.c
> @@ -387,11 +387,13 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
>                           enable_lasi_lan());
>       }
>   
> -    pci_init_nic_devices(pci_bus, mc->default_nic);
> +    if (pci_bus) {
> +        pci_init_nic_devices(pci_bus, mc->default_nic);
> +    }
>   
>       /* BMC board: HP Diva GSP */
> -    dev = qdev_new("diva-gsp");
> -    if (!object_property_get_bool(OBJECT(dev), "disable", NULL)) {
> +    dev = pci_bus ? qdev_new("diva-gsp") : NULL;
> +    if (dev && !object_property_get_bool(OBJECT(dev), "disable", NULL)) {

Sequential testing of NULL pointers isn't ideal.

Better as

     if (pci_bus) {
	pci_init_nic_devices(pci_bus, mc->default_nic);

	/* BMC board: HP Diva GSP */
	dev = qdev_new("diva-gsp");
	if (!object_property_get_bool(OBJECT(dev), "disable", NULL)) {
	    PCIDevice *pci_dev = pci_new_multifunction(...);
	}
     }


r~