PC cleanups
cover PC cleanups
This series contains some random trivial cleanups I came across when working on the PC machines. It consists of reducing the usage of global variables and eliminating some redundancies.
Testing done:
* make check
* `qemu-system-x86_64 -M q35 -m 2G -cdrom \
manjaro-kde-21.3.2-220704-linux515.iso`
* qemu-system-x86_64 -M pc -m 2G -cdrom manjaro-kde-21.3.2-220704-linux515.iso
Bernhard Beschow (7):
hw/pci-host/i440fx: Inline sysbus_add_io() hw/pci-host/q35: Inline sysbus_add_io()
hw/i386/ich9: Rename Q35_MASK to ICH9_MASK hw/i386/pc_q35: Resolve redundant q35_host variable hw/i386/pc_{q35,piix}: Reuse MachineClass::desc as SMB product name hw/i386/pc_{q35,piix}: Minimize usage of get_system_memory() hw/i386/pc: Initialize ram_memory variable directly
include/hw/i386/ich9.h | 10 +++++----- include/hw/i386/pc.h | 1 - hw/i386/pc.c | 2 -- hw/i386/pc_piix.c | 8 ++++---- hw/i386/pc_q35.c | 34 ++++++++++++++++------------------ hw/pci-host/i440fx.c | 5 +++-- hw/pci-host/q35.c | 6 ++++-- 7 files changed, 32 insertions(+), 34 deletions(-)
Signature · 1 line
2.39.1
PATCH 1/7 hw/pci-host/i440fx: Inline sysbus_add_io()
Rather than using get_system_io() as the parent memory region, use s->bus->address_space_io which is set up as an alias in the pc machine.
--- hw/pci-host/i440fx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/pci-host/i440fx.c +3 -2
@@ -27,6 +27,7 @@#include "qemu/range.h" #include "hw/i386/pc.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "hw/pci-host/i440fx.h" #include "hw/qdev-properties.h"
@@ -217,10 +218,10 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)PCIHostState *s =PCI_HOST_BRIDGE (dev);SysBusDevice *sbd =SYS_BUS_DEVICE (dev); -sysbus_add_io (sbd,0xcf8 , &s->conf_mem); +memory_region_add_subregion (s->bus->address_space_io,0xcf8 , &s->conf_mem);sysbus_init_ioports (sbd,0xcf8 ,4 ); -sysbus_add_io (sbd,0xcfc , &s->data_mem); +memory_region_add_subregion (s->bus->address_space_io,0xcfc , &s->data_mem);sysbus_init_ioports (sbd,0xcfc ,4 );/* register i440fx 0xcf8 port as coalesced pio */
Signature · 1 line
2.39.1
PATCH 2/7 hw/pci-host/q35: Inline sysbus_add_io()
In reply to Bernhard BeschowRather than using get_system_io() as the parent memory region, use s->mch.address_space_io which is set up as an alias in the q35 machine.
--- hw/pci-host/q35.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pci-host/q35.c +4 -2
@@ -50,10 +50,12 @@ static void q35_host_realize(DeviceState *dev, Error **errp)Q35PCIHost *s =Q35_HOST_DEVICE (dev);SysBusDevice *sbd =SYS_BUS_DEVICE (dev); -sysbus_add_io (sbd,MCH_HOST_BRIDGE_CONFIG_ADDR , &pci->conf_mem); +memory_region_add_subregion (s->mch.address_space_io, +MCH_HOST_BRIDGE_CONFIG_ADDR , &pci->conf_mem);sysbus_init_ioports (sbd,MCH_HOST_BRIDGE_CONFIG_ADDR ,4 ); -sysbus_add_io (sbd,MCH_HOST_BRIDGE_CONFIG_DATA , &pci->data_mem); +memory_region_add_subregion (s->mch.address_space_io, +MCH_HOST_BRIDGE_CONFIG_DATA , &pci->data_mem);sysbus_init_ioports (sbd,MCH_HOST_BRIDGE_CONFIG_DATA ,4 );/* register q35 0xcf8 port as coalesced pio */
Signature · 1 line
2.39.1
PATCH 3/7 hw/i386/ich9: Rename Q35_MASK to ICH9_MASK
In reply to Bernhard BeschowThe Q35_MASK macro is already defined by TYPE_Q35_HOST_DEVICE, so let TYPE_ICH9_LPC_DEVICE have its own one to prevent potential name collisions.
--- include/hw/i386/ich9.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
include/hw/i386/ich9.h +5 -5
@@ -75,7 +75,7 @@ struct ICH9LPCState {qemu_irq gsi[GSI_NUM_PINS ]; }; -#define Q35_MASK (bit, ms_bit, ls_bit) \ +#define ICH9_MASK (bit, ms_bit, ls_bit) \ ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1)))/* ICH9: Chipset Configuration Registers */
@@ -137,13 +137,13 @@ struct ICH9LPCState {#define ICH9_LPC_NB_PIRQS 8/* PCI A-H */ #define ICH9_LPC_PMBASE 0x40 -#define ICH9_LPC_PMBASE_BASE_ADDRESS_MASK Q35_MASK(32, 15, 7) +#define ICH9_LPC_PMBASE_BASE_ADDRESS_MASK ICH9_MASK(32, 15, 7)#define ICH9_LPC_PMBASE_RTE 0x1#define ICH9_LPC_PMBASE_DEFAULT 0x1#define ICH9_LPC_ACPI_CTRL 0x44#define ICH9_LPC_ACPI_CTRL_ACPI_EN 0x80 -#define ICH9_LPC_ACPI_CTRL_SCI_IRQ_SEL_MASK Q35_MASK(8, 2, 0) +#define ICH9_LPC_ACPI_CTRL_SCI_IRQ_SEL_MASK ICH9_MASK(8, 2, 0)#define ICH9_LPC_ACPI_CTRL_9 0x0#define ICH9_LPC_ACPI_CTRL_10 0x1#define ICH9_LPC_ACPI_CTRL_11 0x2
@@ -162,7 +162,7 @@ struct ICH9LPCState {#define ICH9_LPC_PIRQH_ROUT 0x6b#define ICH9_LPC_PIRQ_ROUT_IRQEN 0x80 -#define ICH9_LPC_PIRQ_ROUT_MASK Q35_MASK(8, 3, 0) +#define ICH9_LPC_PIRQ_ROUT_MASK ICH9_MASK(8, 3, 0)#define ICH9_LPC_PIRQ_ROUT_DEFAULT 0x80#define ICH9_LPC_GEN_PMCON_1 0xa0
@@ -172,7 +172,7 @@ struct ICH9LPCState {#define ICH9_LPC_GEN_PMCON_LOCK 0xa6#define ICH9_LPC_RCBA 0xf0 -#define ICH9_LPC_RCBA_BA_MASK Q35_MASK(32, 31, 14) +#define ICH9_LPC_RCBA_BA_MASK ICH9_MASK(32, 31, 14)#define ICH9_LPC_RCBA_EN 0x1#define ICH9_LPC_RCBA_DEFAULT 0x0
Signature · 1 line
2.39.1
PATCH 4/7 hw/i386/pc_q35: Resolve redundant q35_host variable
In reply to Bernhard BeschowThe variable is redundant to "phb" and is never used by its real type.
--- hw/i386/pc_q35.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
hw/i386/pc_q35.c +10 -12
@@ -118,7 +118,6 @@ static void pc_q35_init(MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); -Q35PCIHost *q35_host;PCIHostState *phb;PCIBus *host_bus;PCIDevice *lpc;
@@ -206,10 +205,10 @@ static void pc_q35_init(MachineState *machine) }/* create pci host bus */ - q35_host =Q35_HOST_DEVICE (qdev_new (TYPE_Q35_HOST_DEVICE )); + phb =PCI_HOST_BRIDGE (qdev_new (TYPE_Q35_HOST_DEVICE ));if (pcmc->pci_enabled) { - pci_hole64_size =object_property_get_uint (OBJECT (q35_host), + pci_hole64_size =object_property_get_uint (OBJECT (phb),PCI_HOST_PROP_PCI_HOLE64_SIZE , &error_abort); }
@@ -218,22 +217,21 @@ static void pc_q35_init(MachineState *machine)pc_memory_init (pcms,get_system_memory (), rom_memory, &ram_memory, pci_hole64_size); -object_property_add_child (qdev_get_machine (),"q35" ,OBJECT (q35_host)); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_RAM_MEM , +object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb)); +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_RAM_MEM ,OBJECT (ram_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_PCI_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_PCI_MEM ,OBJECT (pci_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_SYSTEM_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_SYSTEM_MEM ,OBJECT (get_system_memory ()),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_IO_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_IO_MEM ,OBJECT (system_io),NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_BELOW_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_BELOW_4G_MEM_SIZE , x86ms->below_4g_mem_size,NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_ABOVE_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_ABOVE_4G_MEM_SIZE , x86ms->above_4g_mem_size,NULL );/* pci */ -sysbus_realize_and_unref (SYS_BUS_DEVICE (q35_host), &error_fatal); - phb =PCI_HOST_BRIDGE (q35_host); +sysbus_realize_and_unref (SYS_BUS_DEVICE (phb), &error_fatal); host_bus = phb->bus;/* create ISA bus */ lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
Signature · 1 line
2.39.1
Re: [PATCH 4/7] hw/i386/pc_q35: Resolve redundant q35_host variable
Quoted 1 line · Bernhard Beschow
The variable is redundant to "phb" and is never used by its real type.
Also replace qdev_get_machine() with reference already passed to init function. (Maybe worth mentioning in commit message even if too small change for a separate patch.)
Quoted 10 lines
Signed-off-by Bernhard Beschow <[email protected]>---
hw/i386/pc_q35.c| 22 ++++++++++------------1 file changed, 10 insertions(+), 12 deletions(-)hw/i386/pc_q35.c +0
-0
hw/i386/pc_q35.c static void pc_q35_init(MachineState *machine) · line 121
Quoted 5 lines
hw/i386/pc_q35.c +0
-1@@ -118,7 +118,6 @@ static void pc_q35_init(MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); -Q35PCIHost *q35_host;PCIHostState *phb;
The phb variable itself is only used once to get the bus from it and it's mostly cast to Object * so maybe store it in a variable of that type to remove most of the casts and IMO you can also remove PCIHostState *phb and just use:
host_bus = PCI_HOST_BRIDGE(phost)->bus;
Regards,
BALATON Zoltan
Quoted 47 lines
hw/i386/pc_q35.c +10
-11PCIBus *host_bus;PCIDevice *lpc;@@ -206,10 +205,10 @@ static void pc_q35_init(MachineState *machine) }/* create pci host bus */ - q35_host =Q35_HOST_DEVICE (qdev_new (TYPE_Q35_HOST_DEVICE )); + phb =PCI_HOST_BRIDGE (qdev_new (TYPE_Q35_HOST_DEVICE ));if (pcmc->pci_enabled) { - pci_hole64_size =object_property_get_uint (OBJECT (q35_host), + pci_hole64_size =object_property_get_uint (OBJECT (phb),PCI_HOST_PROP_PCI_HOLE64_SIZE , &error_abort); }@@ -218,22 +217,21 @@ static void pc_q35_init(MachineState *machine)pc_memory_init (pcms,get_system_memory (), rom_memory, &ram_memory, pci_hole64_size); -object_property_add_child (qdev_get_machine (),"q35" ,OBJECT (q35_host)); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_RAM_MEM , +object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb)); +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_RAM_MEM ,OBJECT (ram_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_PCI_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_PCI_MEM ,OBJECT (pci_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_SYSTEM_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_SYSTEM_MEM ,OBJECT (get_system_memory ()),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_IO_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_IO_MEM ,OBJECT (system_io),NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_BELOW_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_BELOW_4G_MEM_SIZE , x86ms->below_4g_mem_size,NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_ABOVE_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_ABOVE_4G_MEM_SIZE , x86ms->above_4g_mem_size,NULL );/* pci */ -sysbus_realize_and_unref (SYS_BUS_DEVICE (q35_host), &error_fatal); - phb =PCI_HOST_BRIDGE (q35_host); +sysbus_realize_and_unref (SYS_BUS_DEVICE (phb), &error_fatal); host_bus = phb->bus;/* create ISA bus */ lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
Re: [PATCH 4/7] hw/i386/pc_q35: Resolve redundant q35_host variable
Am 27. Januar 2023 19:22:49 UTC schrieb BALATON Zoltan <[email protected]>:
Quoted 4 lines · Bernhard Beschow
Quoted 1 line
The variable is redundant to "phb" and is never used by its real type.
Also replace
qdev_get_machine()with reference already passed to init function. (Maybe worth mentioning in commit message even if too small change for a separate patch.)
Indeed, this can easily be missed. A separate patch allows for clean justification.
Quoted 19 lines
Quoted 11 lines
Signed-off-by Bernhard Beschow <[email protected]>---
hw/i386/pc_q35.c| 22 ++++++++++------------1 file changed, 10 insertions(+), 12 deletions(-)hw/i386/pc_q35.c +0
-0hw/i386/pc_q35.c static void pc_q35_init(MachineState *machine) · line 121
Quoted 5 lines
hw/i386/pc_q35.c +0
-1@@ -118,7 +118,6 @@ static void pc_q35_init(MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); -Q35PCIHost *q35_host;PCIHostState *phb;The phb variable itself is only used once to get the bus from it and it's mostly cast to Object * so maybe store it in a variable of that type to remove most of the casts and IMO you can also remove PCIHostState *phb and just use:
Quoted 1 line
host_bus= PCI_HOST_BRIDGE(phost)->bus;
Maybe one could also fish out the PCI bus using qdev_get_child_bus() like we do in pc_piix for the ISA bus already. Hm...
Best regards,
Bernhard
Quoted 51 lines
Regards,
BALATON ZoltanQuoted 47 lines
hw/i386/pc_q35.c +10
-11PCIBus *host_bus;PCIDevice *lpc;@@ -206,10 +205,10 @@ static void pc_q35_init(MachineState *machine) }/* create pci host bus */ - q35_host =Q35_HOST_DEVICE (qdev_new (TYPE_Q35_HOST_DEVICE )); + phb =PCI_HOST_BRIDGE (qdev_new (TYPE_Q35_HOST_DEVICE ));if (pcmc->pci_enabled) { - pci_hole64_size =object_property_get_uint (OBJECT (q35_host), + pci_hole64_size =object_property_get_uint (OBJECT (phb),PCI_HOST_PROP_PCI_HOLE64_SIZE , &error_abort); }@@ -218,22 +217,21 @@ static void pc_q35_init(MachineState *machine)pc_memory_init (pcms,get_system_memory (), rom_memory, &ram_memory, pci_hole64_size); -object_property_add_child (qdev_get_machine (),"q35" ,OBJECT (q35_host)); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_RAM_MEM , +object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb)); +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_RAM_MEM ,OBJECT (ram_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_PCI_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_PCI_MEM ,OBJECT (pci_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_SYSTEM_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_SYSTEM_MEM ,OBJECT (get_system_memory ()),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_IO_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_IO_MEM ,OBJECT (system_io),NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_BELOW_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_BELOW_4G_MEM_SIZE , x86ms->below_4g_mem_size,NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_ABOVE_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_ABOVE_4G_MEM_SIZE , x86ms->above_4g_mem_size,NULL );/* pci */ -sysbus_realize_and_unref (SYS_BUS_DEVICE (q35_host), &error_fatal); - phb =PCI_HOST_BRIDGE (q35_host); +sysbus_realize_and_unref (SYS_BUS_DEVICE (phb), &error_fatal); host_bus = phb->bus;/* create ISA bus */ lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
Re: [PATCH 4/7] hw/i386/pc_q35: Resolve redundant q35_host variable
Quoted 7 lines · Bernhard Beschow
Am 27. Januar 2023 19:22:49 UTC schrieb BALATON Zoltan <[email protected]>:
Quoted 4 lines · Bernhard Beschow
Quoted 1 line
The variable is redundant to "phb" and is never used by its real type.
Also replace
qdev_get_machine()with reference already passed to init function. (Maybe worth mentioning in commit message even if too small change for a separate patch.)Indeed, this can easily be missed. A separate patch allows for clean justification.
I think just adding a sentence to commit message to clarify it is enough no need to split it out but up to you.
Regards,
BALATON Zoltan
Quoted 77 lines
Quoted 18 lines
Quoted 10 lines
Signed-off-by Bernhard Beschow <[email protected]>---
hw/i386/pc_q35.c| 22 ++++++++++------------1 file changed, 10 insertions(+), 12 deletions(-)hw/i386/pc_q35.c +0
-0hw/i386/pc_q35.c static void pc_q35_init(MachineState *machine) · line 121
Quoted 5 lines
hw/i386/pc_q35.c +0
-1@@ -118,7 +118,6 @@ static void pc_q35_init(MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine); -Q35PCIHost *q35_host;PCIHostState *phb;The phb variable itself is only used once to get the bus from it and it's mostly cast to Object * so maybe store it in a variable of that type to remove most of the casts and IMO you can also remove PCIHostState *phb and just use:
Quoted 1 line
host_bus= PCI_HOST_BRIDGE(phost)->bus;Maybe one could also fish out the PCI bus using
qdev_get_child_bus()like we do inpc_piixfor the ISA bus already. Hm...Best regards,
BernhardQuoted 51 lines
Regards,
BALATON ZoltanQuoted 47 lines
hw/i386/pc_q35.c +10
-11PCIBus *host_bus;PCIDevice *lpc;@@ -206,10 +205,10 @@ static void pc_q35_init(MachineState *machine) }/* create pci host bus */ - q35_host =Q35_HOST_DEVICE (qdev_new (TYPE_Q35_HOST_DEVICE )); + phb =PCI_HOST_BRIDGE (qdev_new (TYPE_Q35_HOST_DEVICE ));if (pcmc->pci_enabled) { - pci_hole64_size =object_property_get_uint (OBJECT (q35_host), + pci_hole64_size =object_property_get_uint (OBJECT (phb),PCI_HOST_PROP_PCI_HOLE64_SIZE , &error_abort); }@@ -218,22 +217,21 @@ static void pc_q35_init(MachineState *machine)pc_memory_init (pcms,get_system_memory (), rom_memory, &ram_memory, pci_hole64_size); -object_property_add_child (qdev_get_machine (),"q35" ,OBJECT (q35_host)); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_RAM_MEM , +object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb)); +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_RAM_MEM ,OBJECT (ram_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_PCI_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_PCI_MEM ,OBJECT (pci_memory),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_SYSTEM_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_SYSTEM_MEM ,OBJECT (get_system_memory ()),NULL ); -object_property_set_link (OBJECT (q35_host),MCH_HOST_PROP_IO_MEM , +object_property_set_link (OBJECT (phb),MCH_HOST_PROP_IO_MEM ,OBJECT (system_io),NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_BELOW_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_BELOW_4G_MEM_SIZE , x86ms->below_4g_mem_size,NULL ); -object_property_set_int (OBJECT (q35_host),PCI_HOST_ABOVE_4G_MEM_SIZE , +object_property_set_int (OBJECT (phb),PCI_HOST_ABOVE_4G_MEM_SIZE , x86ms->above_4g_mem_size,NULL );/* pci */ -sysbus_realize_and_unref (SYS_BUS_DEVICE (q35_host), &error_fatal); - phb =PCI_HOST_BRIDGE (q35_host); +sysbus_realize_and_unref (SYS_BUS_DEVICE (phb), &error_fatal); host_bus = phb->bus;/* create ISA bus */ lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV,
PATCH 5/7 hw/i386/pc_{q35, piix}: Reuse MachineClass::desc as SMB product name
In reply to Bernhard BeschowNo need to repeat the descriptions.
--- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/i386/pc_piix.c +1 -1
@@ -197,7 +197,7 @@ static void pc_init1(MachineState *machine,if (pcmc->smbios_defaults) {MachineClass *mc =MACHINE_GET_CLASS (machine);/* These values are guest ABI, do not change */ -smbios_set_defaults ("QEMU" ,"Standard PC (i440FX + PIIX, 1996)" , +smbios_set_defaults ("QEMU" , mc->desc, mc->name, pcmc->smbios_legacy_mode, pcmc->smbios_uuid_encoded, pcms->smbios_entry_point_type);
hw/i386/pc_q35.c +1 -1
@@ -198,7 +198,7 @@ static void pc_q35_init(MachineState *machine)if (pcmc->smbios_defaults) {/* These values are guest ABI, do not change */ -smbios_set_defaults ("QEMU" ,"Standard PC (Q35 + ICH9, 2009)" , +smbios_set_defaults ("QEMU" , mc->desc, mc->name, pcmc->smbios_legacy_mode, pcmc->smbios_uuid_encoded, pcms->smbios_entry_point_type);
Signature · 1 line
2.39.1
Re: [PATCH 5/7] hw/i386/pc_{q35, piix}: Reuse MachineClass::desc as SMB product name
Quoted 7 lines · Bernhard Beschow
No need to repeat the descriptions.
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
PATCH 6/7 hw/i386/pc_{q35, piix}: Minimize usage of get_system_memory()
In reply to Bernhard Beschow--- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +1 -1
@@ -241,7 +241,7 @@ static void pc_init1(MachineState *machine, isa_bus =ISA_BUS (qdev_get_child_bus (DEVICE (piix3),"isa.0" )); }else { pci_bus =NULL ; - isa_bus =isa_bus_new (NULL ,get_system_memory (), system_io, + isa_bus =isa_bus_new (NULL , system_memory, system_io, &error_abort);i8257_dma_init (isa_bus,0 ); pcms->hpet_enabled = false;
hw/i386/pc_q35.c +4 -3
@@ -124,6 +124,7 @@ static void pc_q35_init(MachineState *machine)DeviceState *lpc_dev;BusState *idebus[MAX_SATA_PORTS ];ISADevice *rtc_state; +MemoryRegion *system_memory =get_system_memory ();MemoryRegion *system_io =get_system_io ();MemoryRegion *pci_memory;MemoryRegion *rom_memory;
@@ -191,7 +192,7 @@ static void pc_q35_init(MachineState *machine) rom_memory = pci_memory; }else { pci_memory =NULL ; - rom_memory =get_system_memory (); + rom_memory = system_memory; }pc_guest_info_init (pcms);
@@ -214,7 +215,7 @@ static void pc_q35_init(MachineState *machine) }/* allocate ram and load rom/bios */ -pc_memory_init (pcms,get_system_memory (), rom_memory, &ram_memory, +pc_memory_init (pcms, system_memory, rom_memory, &ram_memory, pci_hole64_size);object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb));
@@ -223,7 +224,7 @@ static void pc_q35_init(MachineState *machine)object_property_set_link (OBJECT (phb),MCH_HOST_PROP_PCI_MEM ,OBJECT (pci_memory),NULL );object_property_set_link (OBJECT (phb),MCH_HOST_PROP_SYSTEM_MEM , -OBJECT (get_system_memory ()),NULL ); +OBJECT (system_memory),NULL );object_property_set_link (OBJECT (phb),MCH_HOST_PROP_IO_MEM ,OBJECT (system_io),NULL ); object_property_set_int(OBJECT(phb), PCI_HOST_BELOW_4G_MEM_SIZE,
Signature · 1 line
2.39.1
Re: [PATCH 6/7] hw/i386/pc_{q35, piix}: Minimize usage of get_system_memory()
Quoted 1 line · Bernhard Beschow
Signed-off-by Bernhard Beschow <[email protected]>
Why? I'd rather replace locals with direct call to function as it's not expensive (just returns a global) and adding a local name to it is not much shorter so why do that?
Regards,
BALATON Zoltan
Quoted 58 lines
---
hw/i386/pc_piix.c| 2 +-hw/i386/pc_q35.c| 7 ++++---2 files changed, 5 insertions(+), 4 deletions(-)hw/i386/pc_piix.c +1
-1@@ -241,7 +241,7 @@ static void pc_init1(MachineState *machine, isa_bus =ISA_BUS (qdev_get_child_bus (DEVICE (piix3),"isa.0" )); }else { pci_bus =NULL ; - isa_bus =isa_bus_new (NULL ,get_system_memory (), system_io, + isa_bus =isa_bus_new (NULL , system_memory, system_io, &error_abort);i8257_dma_init (isa_bus,0 ); pcms->hpet_enabled = false;hw/i386/pc_q35.c +4
-3@@ -124,6 +124,7 @@ static void pc_q35_init(MachineState *machine)DeviceState *lpc_dev;BusState *idebus[MAX_SATA_PORTS ];ISADevice *rtc_state; +MemoryRegion *system_memory =get_system_memory ();MemoryRegion *system_io =get_system_io ();MemoryRegion *pci_memory;MemoryRegion *rom_memory;@@ -191,7 +192,7 @@ static void pc_q35_init(MachineState *machine) rom_memory = pci_memory; }else { pci_memory =NULL ; - rom_memory =get_system_memory (); + rom_memory = system_memory; }pc_guest_info_init (pcms);@@ -214,7 +215,7 @@ static void pc_q35_init(MachineState *machine) }/* allocate ram and load rom/bios */ -pc_memory_init (pcms,get_system_memory (), rom_memory, &ram_memory, +pc_memory_init (pcms, system_memory, rom_memory, &ram_memory, pci_hole64_size);object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb));@@ -223,7 +224,7 @@ static void pc_q35_init(MachineState *machine)object_property_set_link (OBJECT (phb),MCH_HOST_PROP_PCI_MEM ,OBJECT (pci_memory),NULL );object_property_set_link (OBJECT (phb),MCH_HOST_PROP_SYSTEM_MEM , -OBJECT (get_system_memory ()),NULL ); +OBJECT (system_memory),NULL );object_property_set_link (OBJECT (phb),MCH_HOST_PROP_IO_MEM ,OBJECT (system_io),NULL ); object_property_set_int(OBJECT(phb), PCI_HOST_BELOW_4G_MEM_SIZE,
Re: [PATCH 6/7] hw/i386/pc_{q35, piix}: Minimize usage of get_system_memory()
Am 27. Januar 2023 19:30:21 UTC schrieb BALATON Zoltan <[email protected]>:
Quoted 4 lines · Bernhard Beschow
Quoted 1 line
Signed-off-by Bernhard Beschow <[email protected]>Why? I'd rather replace locals with direct call to function as it's not expensive (just returns a global) and adding a local name to it is not much shorter so why do that?
The function has the assumption baked in to return a global which I'd like to factor out into a single variable assignment. This allows for easier experimentation with alternatives to global variables.
Moreover, extrating to a single variable mirrors how similar things are done in the pc and q35 machines.
Best regards,
Bernhard
Quoted 62 lines
Regards,
BALATON ZoltanQuoted 58 lines
---
hw/i386/pc_piix.c| 2 +-hw/i386/pc_q35.c| 7 ++++---2 files changed, 5 insertions(+), 4 deletions(-)hw/i386/pc_piix.c +1
-1@@ -241,7 +241,7 @@ static void pc_init1(MachineState *machine, isa_bus =ISA_BUS (qdev_get_child_bus (DEVICE (piix3),"isa.0" )); }else { pci_bus =NULL ; - isa_bus =isa_bus_new (NULL ,get_system_memory (), system_io, + isa_bus =isa_bus_new (NULL , system_memory, system_io, &error_abort);i8257_dma_init (isa_bus,0 ); pcms->hpet_enabled = false;hw/i386/pc_q35.c +4
-3@@ -124,6 +124,7 @@ static void pc_q35_init(MachineState *machine)DeviceState *lpc_dev;BusState *idebus[MAX_SATA_PORTS ];ISADevice *rtc_state; +MemoryRegion *system_memory =get_system_memory ();MemoryRegion *system_io =get_system_io ();MemoryRegion *pci_memory;MemoryRegion *rom_memory;@@ -191,7 +192,7 @@ static void pc_q35_init(MachineState *machine) rom_memory = pci_memory; }else { pci_memory =NULL ; - rom_memory =get_system_memory (); + rom_memory = system_memory; }pc_guest_info_init (pcms);@@ -214,7 +215,7 @@ static void pc_q35_init(MachineState *machine) }/* allocate ram and load rom/bios */ -pc_memory_init (pcms,get_system_memory (), rom_memory, &ram_memory, +pc_memory_init (pcms, system_memory, rom_memory, &ram_memory, pci_hole64_size);object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb));@@ -223,7 +224,7 @@ static void pc_q35_init(MachineState *machine)object_property_set_link (OBJECT (phb),MCH_HOST_PROP_PCI_MEM ,OBJECT (pci_memory),NULL );object_property_set_link (OBJECT (phb),MCH_HOST_PROP_SYSTEM_MEM , -OBJECT (get_system_memory ()),NULL ); +OBJECT (system_memory),NULL );object_property_set_link (OBJECT (phb),MCH_HOST_PROP_IO_MEM ,OBJECT (system_io),NULL ); object_property_set_int(OBJECT(phb), PCI_HOST_BELOW_4G_MEM_SIZE,
PATCH 7/7 hw/i386/pc: Initialize ram_memory variable directly
In reply to Bernhard BeschowGoing through pc_memory_init() seems quite complicated for a simple assignment.
--- include/hw/i386/pc.h | 1 - hw/i386/pc.c | 2 -- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 5 ++--- 4 files changed, 4 insertions(+), 8 deletions(-)
include/hw/i386/pc.h +0 -1
@@ -163,7 +163,6 @@ void xen_load_linux(PCMachineState *pcms);void pc_memory_init (PCMachineState *pcms,MemoryRegion *system_memory,MemoryRegion *rom_memory, -MemoryRegion **ram_memory,uint64_t pci_hole64_size);uint64_t pc_pci_hole64_start (void );DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus);
hw/i386/pc.c +0 -2
@@ -936,7 +936,6 @@ static hwaddr pc_max_used_gpa(PCMachineState *pcms, uint64_t pci_hole64_size)void pc_memory_init (PCMachineState *pcms,MemoryRegion *system_memory,MemoryRegion *rom_memory, -MemoryRegion **ram_memory,uint64_t pci_hole64_size) {int linux_boot, i;
@@ -994,7 +993,6 @@ void pc_memory_init(PCMachineState *pcms,* Split single memory region and use aliases to address portions of it, * done for backwards compatibility with older qemus. */ - *ram_memory = machine->ram; ram_below_4g =g_malloc (sizeof (*ram_below_4g));memory_region_init_alias (ram_below_4g,NULL ,"ram-below-4g" , machine->ram,0 , x86ms->below_4g_mem_size);
hw/i386/pc_piix.c +2 -2
@@ -143,6 +143,7 @@ static void pc_init1(MachineState *machine,if (xen_enabled ()) {xen_hvm_init_pc (pcms, &ram_memory); }else { + ram_memory = machine->ram;if (!pcms->max_ram_below_4g) { pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ }
@@ -205,8 +206,7 @@ static void pc_init1(MachineState *machine,/* allocate ram and load rom/bios */ if (!xen_enabled ()) { -pc_memory_init (pcms, system_memory, - rom_memory, &ram_memory, hole64_size); +pc_memory_init (pcms, system_memory, rom_memory, hole64_size); }else {pc_system_flash_cleanup_unused (pcms);if (machine->kernel_filename !=NULL ) {
hw/i386/pc_q35.c +2 -3
@@ -128,7 +128,7 @@ static void pc_q35_init(MachineState *machine)MemoryRegion *system_io =get_system_io ();MemoryRegion *pci_memory;MemoryRegion *rom_memory; -MemoryRegion *ram_memory; +MemoryRegion *ram_memory = machine->ram;GSIState *gsi_state;ISABus *isa_bus;int i;
@@ -215,8 +215,7 @@ static void pc_q35_init(MachineState *machine) }/* allocate ram and load rom/bios */ -pc_memory_init (pcms, system_memory, rom_memory, &ram_memory, - pci_hole64_size); +pc_memory_init (pcms, system_memory, rom_memory, pci_hole64_size);object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb)); object_property_set_link(OBJECT(phb), MCH_HOST_PROP_RAM_MEM,
Signature · 1 line
2.39.1
Re: [PATCH 7/7] hw/i386/pc: Initialize ram_memory variable directly
Quoted 4 lines · Bernhard Beschow
Going through
pc_memory_init()seems quite complicated for a simple assignment.Signed-off-by Bernhard Beschow <[email protected]>
Quoted 84 lines
--- include/hw/i386/pc.h | 1 - hw/i386/pc.c | 2 -- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 5 ++--- 4 files changed, 4 insertions(+), 8 deletions(-)include/hw/i386/pc.h +0
-1@@ -163,7 +163,6 @@ void xen_load_linux(PCMachineState *pcms);void pc_memory_init (PCMachineState *pcms,MemoryRegion *system_memory,MemoryRegion *rom_memory, -MemoryRegion **ram_memory,uint64_t pci_hole64_size);uint64_t pc_pci_hole64_start (void );DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus);hw/i386/pc.c +0
-2@@ -936,7 +936,6 @@ static hwaddr pc_max_used_gpa(PCMachineState *pcms, uint64_t pci_hole64_size)void pc_memory_init (PCMachineState *pcms,MemoryRegion *system_memory,MemoryRegion *rom_memory, -MemoryRegion **ram_memory,uint64_t pci_hole64_size) {int linux_boot, i;@@ -994,7 +993,6 @@ void pc_memory_init(PCMachineState *pcms,* Split single memory region and use aliases to address portions of it, * done for backwards compatibility with older qemus. */ - *ram_memory = machine->ram; ram_below_4g =g_malloc (sizeof (*ram_below_4g));memory_region_init_alias (ram_below_4g,NULL ,"ram-below-4g" , machine->ram,0 , x86ms->below_4g_mem_size);hw/i386/pc_piix.c +2
-2@@ -143,6 +143,7 @@ static void pc_init1(MachineState *machine,if (xen_enabled ()) {xen_hvm_init_pc (pcms, &ram_memory); }else { + ram_memory = machine->ram;if (!pcms->max_ram_below_4g) { pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ }@@ -205,8 +206,7 @@ static void pc_init1(MachineState *machine,/* allocate ram and load rom/bios */ if (!xen_enabled ()) { -pc_memory_init (pcms, system_memory, - rom_memory, &ram_memory, hole64_size); +pc_memory_init (pcms, system_memory, rom_memory, hole64_size); }else {pc_system_flash_cleanup_unused (pcms);if (machine->kernel_filename !=NULL ) {hw/i386/pc_q35.c +2
-3@@ -128,7 +128,7 @@ static void pc_q35_init(MachineState *machine)MemoryRegion *system_io =get_system_io ();MemoryRegion *pci_memory;MemoryRegion *rom_memory; -MemoryRegion *ram_memory; +MemoryRegion *ram_memory = machine->ram;GSIState *gsi_state;ISABus *isa_bus;int i;@@ -215,8 +215,7 @@ static void pc_q35_init(MachineState *machine) }/* allocate ram and load rom/bios */ -pc_memory_init (pcms, system_memory, rom_memory, &ram_memory, - pci_hole64_size); +pc_memory_init (pcms, system_memory, rom_memory, pci_hole64_size);object_property_add_child (OBJECT (machine),"q35" ,OBJECT (phb)); object_property_set_link(OBJECT(phb), MCH_HOST_PROP_RAM_MEM,