hw/i386: separate isapc out from pc_piix
v2 cover hw/i386: separate isapc out from pc_piix
For various historical reasons the initialisation of the isapc machine is closely intertwined with the initialisation of the pc machine, which is preventing some future improvements to the pc machine initialisation logic.
Since the consensus [1] was that the isapc is still useful for testing and running older OSs, this series splits the isapc machine and its main initialisation routine pc_init_isa() into a separate isapc.c file to reduce the maintenance burden on pc machine developers.
[1] https://lists.gnu.org/archive/html/qemu-devel/2024-03/msg06137.html
v2:
- Rebase onto master to account for the fix in commit 0b006153b7 ("hw/i386/pc_piix: Fix RTC ISA IRQ wiring of isapc machine")
- Replace verbatim MIT licence text with SPDX identifier as discussed with Daniel
Mark Cave-Ayland (12):
hw/i386/pc_piix.c: duplicate pc_init1() into pc_isa_init() hw/i386/pc_piix.c: remove pcmc->pci_enabled dependent initialisation
from pc_init_isa()
hw/i386/pc_piix.c: remove SMI and piix4_pm initialisation from
pc_init_isa()
hw/i386/pc_piix.c: remove SGX initialisation from pc_init_isa()
hw/i386/pc_piix.c: remove nvdimm initialisation from pc_init_isa()
hw/i386/pc_piix.c: simplify RAM size logic in pc_init_isa()
hw/i386/pc_piix.c: hardcode hole64_size to 0 in pc_init_isa()
hw/i386/pc_piix.c: remove pc_system_flash_cleanup_unused() from
pc_init_isa()
hw/i386/pc_piix.c: always initialise ISA IDE drives in pc_init_isa()
hw/i386/pc_piix.c: assume pcmc->pci_enabled is always false in
pc_init_isa() hw/i386/pc_piix.c: hardcode pcms->pci_bus to NULL in pc_init_isa() hw/i386: move isapc machine to separate isapc.c file
hw/i386/Kconfig | 3 - hw/i386/isapc.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/meson.build | 1 + hw/i386/pc_piix.c | 31 ---------- 4 files changed, 146 insertions(+), 34 deletions(-) create mode 100644 hw/i386/isapc.c
Signature · 1 line
2.43.0
PATCH v2 1/12 hw/i386/pc_piix.c: duplicate pc_init1() into pc_isa_init()
This is to prepare for splitting the isapc machine into its own separate file.
--- hw/i386/pc_piix.c | 260 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 259 insertions(+), 1 deletion(-)
hw/i386/pc_piix.c +259 -1
@@ -418,7 +418,265 @@ static void pc_set_south_bridge(Object *obj, int value, Error **errp)#ifdef CONFIG_ISAPC static void pc_init_isa (MachineState *machine) { -pc_init1 (machine,NULL ); +const char *pci_type =NULL ; +PCMachineState *pcms =PC_MACHINE (machine); +PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms); +X86MachineState *x86ms =X86_MACHINE (machine); +MemoryRegion *system_memory =get_system_memory (); +MemoryRegion *system_io =get_system_io (); +Object *phb =NULL ; +ISABus *isa_bus; +Object *piix4_pm =NULL ; +qemu_irq smi_irq; +GSIState *gsi_state; +MemoryRegion *ram_memory; +MemoryRegion *pci_memory =NULL ; +MemoryRegion *rom_memory = system_memory; +ram_addr_t lowmem; +uint64_t hole64_size =0 ; + +/* +* Calculate ram split, for memory below and above 4G. It's a bit +* complicated for backward compatibility reasons ... +* +* - Traditional split is 3.5G (lowmem = 0xe0000000). This is the +* default value for max_ram_below_4g now. +* +* - Then, to gigabyte align the memory, we move the split to 3G +* (lowmem = 0xc0000000). But only in case we have to split in +* the first place, i.e. ram_size is larger than (traditional) +* lowmem. And for new machine types (gigabyte_align = true) +* only, for live migration compatibility reasons. +* +* - Next the max-ram-below-4g option was added, which allowed to +* reduce lowmem to a smaller value, to allow a larger PCI I/O +* window below 4G. qemu doesn't enforce gigabyte alignment here, +* but prints a warning. +* +* - Finally max-ram-below-4g got updated to also allow raising lowmem, +* so legacy non-PAE guests can get as much memory as possible in +* the 32bit address space below 4G. +* +* - Note that Xen has its own ram setup code in xen_ram_init(), +* called via xen_hvm_init_pc(). +* +* Examples: +* qemu -M pc-1.7 -m 4G (old default) -> 3584M low, 512M high +* qemu -M pc -m 4G (new default) -> 3072M low, 1024M high +* qemu -M pc,max-ram-below-4g=2G -m 4G -> 2048M low, 2048M high +* qemu -M pc,max-ram-below-4g=4G -m 3968M -> 3968M low (=4G-128M) +*/ +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 */ + } + lowmem = pcms->max_ram_below_4g; +if (machine->ram_size >= pcms->max_ram_below_4g) { +if (pcmc->gigabyte_align) { +if (lowmem >0xc0000000 ) { + lowmem =0xc0000000 ; + } +if (lowmem & (1 * GiB -1 )) { +warn_report ("Large machine and max_ram_below_4g " +"(%" PRIu64") not a multiple of 1G; " +"possible bad performance." , + pcms->max_ram_below_4g); + } + } + } + +if (machine->ram_size >= lowmem) { + x86ms->above_4g_mem_size = machine->ram_size - lowmem; + x86ms->below_4g_mem_size = lowmem; + }else { + x86ms->above_4g_mem_size =0 ; + x86ms->below_4g_mem_size = machine->ram_size; + } + } + +pc_machine_init_sgx_epc (pcms); +x86_cpus_init (x86ms, pcmc->default_cpu_version); + +if (kvm_enabled ()) { +kvmclock_create (pcmc->kvmclock_create_always); + } + +if (pcmc->pci_enabled) { + pci_memory =g_new (MemoryRegion,1 ); +memory_region_init (pci_memory,NULL ,"pci" ,UINT64_MAX ); + rom_memory = pci_memory; + + phb =OBJECT (qdev_new (TYPE_I440FX_PCI_HOST_BRIDGE )); +object_property_add_child (OBJECT (machine),"i440fx" , phb); +object_property_set_link (phb,PCI_HOST_PROP_RAM_MEM , +OBJECT (ram_memory), &error_fatal); +object_property_set_link (phb,PCI_HOST_PROP_PCI_MEM , +OBJECT (pci_memory), &error_fatal); +object_property_set_link (phb,PCI_HOST_PROP_SYSTEM_MEM , +OBJECT (system_memory), &error_fatal); +object_property_set_link (phb,PCI_HOST_PROP_IO_MEM , +OBJECT (system_io), &error_fatal); +object_property_set_uint (phb,PCI_HOST_BELOW_4G_MEM_SIZE , + x86ms->below_4g_mem_size, &error_fatal); +object_property_set_uint (phb,PCI_HOST_ABOVE_4G_MEM_SIZE , + x86ms->above_4g_mem_size, &error_fatal); +object_property_set_str (phb,I440FX_HOST_PROP_PCI_TYPE , pci_type, + &error_fatal); +sysbus_realize_and_unref (SYS_BUS_DEVICE (phb), &error_fatal); + + pcms->pcibus =PCI_BUS (qdev_get_child_bus (DEVICE (phb),"pci.0" )); +pci_bus_map_irqs (pcms->pcibus, +xen_enabled () ? xen_pci_slot_get_pirq + : pc_pci_slot_get_pirq); + + hole64_size =object_property_get_uint (phb, +PCI_HOST_PROP_PCI_HOLE64_SIZE , + &error_abort); + } + +/* allocate ram and load rom/bios */ +if (!xen_enabled ()) { +pc_memory_init (pcms, system_memory, rom_memory, hole64_size); + }else { +assert (machine->ram_size == x86ms->below_4g_mem_size + + x86ms->above_4g_mem_size); + +pc_system_flash_cleanup_unused (pcms); +if (machine->kernel_filename !=NULL ) { +/* For xen HVM direct kernel boot, load linux here */ +xen_load_linux (pcms); + } + } + + gsi_state =pc_gsi_create (&x86ms->gsi, pcmc->pci_enabled); + +if (pcmc->pci_enabled) { +PCIDevice *pci_dev; +DeviceState *dev; +size_t i; + + pci_dev =pci_new_multifunction (-1 , pcms->south_bridge); +object_property_set_bool (OBJECT (pci_dev),"has-usb" , +machine_usb (machine), &error_abort); +object_property_set_bool (OBJECT (pci_dev),"has-acpi" , +x86_machine_is_acpi_enabled (x86ms), + &error_abort); +object_property_set_bool (OBJECT (pci_dev),"has-pic" , false, + &error_abort); +object_property_set_bool (OBJECT (pci_dev),"has-pit" , false, + &error_abort); +qdev_prop_set_uint32 (DEVICE (pci_dev),"smb_io_base" ,0xb100 ); +object_property_set_bool (OBJECT (pci_dev),"smm-enabled" , +x86_machine_is_smm_enabled (x86ms), + &error_abort); + dev =DEVICE (pci_dev); +for (i =0 ; i <ISA_NUM_IRQS ; i++) { +qdev_connect_gpio_out_named (dev,"isa-irqs" , i, x86ms->gsi[i]); + } +pci_realize_and_unref (pci_dev, pcms->pcibus, &error_fatal); + +if (xen_enabled ()) { +pci_device_set_intx_routing_notifier ( + pci_dev, piix_intx_routing_notifier_xen); + +/* +* Xen supports additional interrupt routes from the PCI devices to +* the IOAPIC: the four pins of each PCI device on the bus are also +* connected to the IOAPIC directly. +* These additional routes can be discovered through ACPI. +*/ +pci_bus_irqs (pcms->pcibus, xen_intx_set_irq, pci_dev, +XEN_IOAPIC_NUM_PIRQS ); + } + + isa_bus =ISA_BUS (qdev_get_child_bus (DEVICE (pci_dev),"isa.0" )); + x86ms->rtc =ISA_DEVICE (object_resolve_path_component (OBJECT (pci_dev), +"rtc" )); + piix4_pm =object_resolve_path_component (OBJECT (pci_dev),"pm" ); + dev =DEVICE (object_resolve_path_component (OBJECT (pci_dev),"ide" )); +pci_ide_create_devs (PCI_DEVICE (dev)); + pcms->idebus[0 ] =qdev_get_child_bus (dev,"ide.0" ); + pcms->idebus[1 ] =qdev_get_child_bus (dev,"ide.1" ); + }else { + isa_bus =isa_bus_new (NULL , system_memory, system_io, + &error_abort); +isa_bus_register_input_irqs (isa_bus, x86ms->gsi); + + x86ms->rtc =isa_new (TYPE_MC146818_RTC ); +qdev_prop_set_int32 (DEVICE (x86ms->rtc),"base_year" ,2000 ); +isa_realize_and_unref (x86ms->rtc, isa_bus, &error_fatal); + +i8257_dma_init (OBJECT (machine), isa_bus,0 ); + pcms->hpet_enabled = false; + } + +if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) { +pc_i8259_create (isa_bus, gsi_state->i8259_irq); + } + +if (phb) { +ioapic_init_gsi (gsi_state, phb); + } + +if (tcg_enabled ()) { +x86_register_ferr_irq (x86ms->gsi[13 ]); + } + +pc_vga_init (isa_bus, pcmc->pci_enabled ? pcms->pcibus :NULL ); + +/* init basic PC hardware */ +pc_basic_device_init (pcms, isa_bus, x86ms->gsi, x86ms->rtc, + !MACHINE_CLASS (pcmc)->no_floppy,0x4 ); + +pc_nic_init (pcmc, isa_bus, pcms->pcibus); + +#ifdef CONFIG_IDE_ISA +if (!pcmc->pci_enabled) { +DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; +int i; + +ide_drive_get (hd,ARRAY_SIZE (hd)); +for (i =0 ; i <MAX_IDE_BUS ; i++) { +ISADevice *dev; +char busname[] ="ide.0" ; + dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], + ide_irq[i], + hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); +/* +* The ide bus name is ide.0 for the first bus and ide.1 for the +* second one. +*/ + busname[4 ] ='0' + i; + pcms->idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); + } + } +#endif + +if (piix4_pm) { + smi_irq =qemu_allocate_irq (pc_acpi_smi_interrupt, first_cpu,0 ); + +qdev_connect_gpio_out_named (DEVICE (piix4_pm),"smi-irq" ,0 , smi_irq); + pcms->smbus =I2C_BUS (qdev_get_child_bus (DEVICE (piix4_pm),"i2c" )); +/* TODO: Populate SPD eeprom data. */ +smbus_eeprom_init (pcms->smbus,8 ,NULL ,0 ); + +object_property_add_link (OBJECT (machine),PC_MACHINE_ACPI_DEVICE_PROP , +TYPE_HOTPLUG_HANDLER , + (Object **)&x86ms->acpi_dev, + object_property_allow_set_link, +OBJ_PROP_LINK_STRONG ); +object_property_set_link (OBJECT (machine),PC_MACHINE_ACPI_DEVICE_PROP , + piix4_pm, &error_abort); + } + +if (machine->nvdimms_state->is_enabled) { +nvdimm_init_acpi_state (machine->nvdimms_state, system_io, + x86_nvdimm_acpi_dsmio, + x86ms->fw_cfg,OBJECT (pcms)); + } }#endif
Signature · 1 line
2.43.0
Re: [PATCH v2 01/12] hw/i386/pc_piix.c: duplicate pc_init1() into pc_isa_init()
Quoted 6 lines · Mark Cave-Ayland
This is to prepare for splitting the isapc machine into its own separate file.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 260 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 259 insertions(+), 1 deletion(-)
PATCH v2 2/12 hw/i386/pc_piix.c: remove pcmc->pci_enabled dependent initialisation from pc_init_isa()
In reply to Mark Cave-AylandThis code will never be used for an isapc machine.
--- hw/i386/pc_piix.c | 105 ++++------------------------------------------ 1 file changed, 8 insertions(+), 97 deletions(-)
hw/i386/pc_piix.c +8 -97
@@ -418,19 +418,16 @@ static void pc_set_south_bridge(Object *obj, int value, Error **errp)#ifdef CONFIG_ISAPC static void pc_init_isa (MachineState *machine) { -const char *pci_type =NULL ;PCMachineState *pcms =PC_MACHINE (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);X86MachineState *x86ms =X86_MACHINE (machine);MemoryRegion *system_memory =get_system_memory ();MemoryRegion *system_io =get_system_io (); -Object *phb =NULL ;ISABus *isa_bus;Object *piix4_pm =NULL ;qemu_irq smi_irq;GSIState *gsi_state;MemoryRegion *ram_memory; -MemoryRegion *pci_memory =NULL ;MemoryRegion *rom_memory = system_memory;ram_addr_t lowmem;uint64_t hole64_size =0 ;
@@ -504,39 +501,6 @@ static void pc_init_isa(MachineState *machine)kvmclock_create (pcmc->kvmclock_create_always); } -if (pcmc->pci_enabled) { - pci_memory =g_new (MemoryRegion,1 ); -memory_region_init (pci_memory,NULL ,"pci" ,UINT64_MAX ); - rom_memory = pci_memory; - - phb =OBJECT (qdev_new (TYPE_I440FX_PCI_HOST_BRIDGE )); -object_property_add_child (OBJECT (machine),"i440fx" , phb); -object_property_set_link (phb,PCI_HOST_PROP_RAM_MEM , -OBJECT (ram_memory), &error_fatal); -object_property_set_link (phb,PCI_HOST_PROP_PCI_MEM , -OBJECT (pci_memory), &error_fatal); -object_property_set_link (phb,PCI_HOST_PROP_SYSTEM_MEM , -OBJECT (system_memory), &error_fatal); -object_property_set_link (phb,PCI_HOST_PROP_IO_MEM , -OBJECT (system_io), &error_fatal); -object_property_set_uint (phb,PCI_HOST_BELOW_4G_MEM_SIZE , - x86ms->below_4g_mem_size, &error_fatal); -object_property_set_uint (phb,PCI_HOST_ABOVE_4G_MEM_SIZE , - x86ms->above_4g_mem_size, &error_fatal); -object_property_set_str (phb,I440FX_HOST_PROP_PCI_TYPE , pci_type, - &error_fatal); -sysbus_realize_and_unref (SYS_BUS_DEVICE (phb), &error_fatal); - - pcms->pcibus =PCI_BUS (qdev_get_child_bus (DEVICE (phb),"pci.0" )); -pci_bus_map_irqs (pcms->pcibus, -xen_enabled () ? xen_pci_slot_get_pirq - : pc_pci_slot_get_pirq); - - hole64_size =object_property_get_uint (phb, -PCI_HOST_PROP_PCI_HOLE64_SIZE , - &error_abort); - } -/* allocate ram and load rom/bios */ if (!xen_enabled ()) {pc_memory_init (pcms, system_memory, rom_memory, hole64_size);
@@ -553,74 +517,21 @@ static void pc_init_isa(MachineState *machine) gsi_state =pc_gsi_create (&x86ms->gsi, pcmc->pci_enabled); -if (pcmc->pci_enabled) { -PCIDevice *pci_dev; -DeviceState *dev; -size_t i; - - pci_dev =pci_new_multifunction (-1 , pcms->south_bridge); -object_property_set_bool (OBJECT (pci_dev),"has-usb" , -machine_usb (machine), &error_abort); -object_property_set_bool (OBJECT (pci_dev),"has-acpi" , -x86_machine_is_acpi_enabled (x86ms), - &error_abort); -object_property_set_bool (OBJECT (pci_dev),"has-pic" , false, - &error_abort); -object_property_set_bool (OBJECT (pci_dev),"has-pit" , false, - &error_abort); -qdev_prop_set_uint32 (DEVICE (pci_dev),"smb_io_base" ,0xb100 ); -object_property_set_bool (OBJECT (pci_dev),"smm-enabled" , -x86_machine_is_smm_enabled (x86ms), - &error_abort); - dev =DEVICE (pci_dev); -for (i =0 ; i <ISA_NUM_IRQS ; i++) { -qdev_connect_gpio_out_named (dev,"isa-irqs" , i, x86ms->gsi[i]); - } -pci_realize_and_unref (pci_dev, pcms->pcibus, &error_fatal); - -if (xen_enabled ()) { -pci_device_set_intx_routing_notifier ( - pci_dev, piix_intx_routing_notifier_xen); - -/* -* Xen supports additional interrupt routes from the PCI devices to -* the IOAPIC: the four pins of each PCI device on the bus are also -* connected to the IOAPIC directly. -* These additional routes can be discovered through ACPI. -*/ -pci_bus_irqs (pcms->pcibus, xen_intx_set_irq, pci_dev, -XEN_IOAPIC_NUM_PIRQS ); - } - - isa_bus =ISA_BUS (qdev_get_child_bus (DEVICE (pci_dev),"isa.0" )); - x86ms->rtc =ISA_DEVICE (object_resolve_path_component (OBJECT (pci_dev), -"rtc" )); - piix4_pm =object_resolve_path_component (OBJECT (pci_dev),"pm" ); - dev =DEVICE (object_resolve_path_component (OBJECT (pci_dev),"ide" )); -pci_ide_create_devs (PCI_DEVICE (dev)); - pcms->idebus[0 ] =qdev_get_child_bus (dev,"ide.0" ); - pcms->idebus[1 ] =qdev_get_child_bus (dev,"ide.1" ); - }else { - isa_bus =isa_bus_new (NULL , system_memory, system_io, - &error_abort); -isa_bus_register_input_irqs (isa_bus, x86ms->gsi); + isa_bus =isa_bus_new (NULL , system_memory, system_io, + &error_abort); +isa_bus_register_input_irqs (isa_bus, x86ms->gsi); - x86ms->rtc =isa_new (TYPE_MC146818_RTC ); -qdev_prop_set_int32 (DEVICE (x86ms->rtc),"base_year" ,2000 ); -isa_realize_and_unref (x86ms->rtc, isa_bus, &error_fatal); + x86ms->rtc =isa_new (TYPE_MC146818_RTC ); +qdev_prop_set_int32 (DEVICE (x86ms->rtc),"base_year" ,2000 ); +isa_realize_and_unref (x86ms->rtc, isa_bus, &error_fatal); -i8257_dma_init (OBJECT (machine), isa_bus,0 ); - pcms->hpet_enabled = false; - } +i8257_dma_init (OBJECT (machine), isa_bus,0 ); + pcms->hpet_enabled = false;if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) {pc_i8259_create (isa_bus, gsi_state->i8259_irq); } -if (phb) { -ioapic_init_gsi (gsi_state, phb); - } -if (tcg_enabled ()) {x86_register_ferr_irq (x86ms->gsi[13 ]); }
Signature · 1 line
2.43.0
Re: [PATCH v2 02/12] hw/i386/pc_piix.c: remove pcmc->pci_enabled dependent initialisation from pc_init_isa()
Quoted 1 line · Mark Cave-Ayland
This code will never be used for an isapc machine.
s/This/PCI/
Quoted 5 lines
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 105 ++++------------------------------------------ 1 file changed, 8 insertions(+), 97 deletions(-)
PATCH v2 3/12 hw/i386/pc_piix.c: remove SMI and piix4_pm initialisation from pc_init_isa()
In reply to Mark Cave-AylandThese are based upon the PIIX4 PCI chipset and so can never be used on an isapc machine.
--- hw/i386/pc_piix.c | 19 ------------------- 1 file changed, 19 deletions(-)
hw/i386/pc_piix.c +0 -19
@@ -424,8 +424,6 @@ static void pc_init_isa(MachineState *machine)MemoryRegion *system_memory =get_system_memory ();MemoryRegion *system_io =get_system_io ();ISABus *isa_bus; -Object *piix4_pm =NULL ; -qemu_irq smi_irq;GSIState *gsi_state;MemoryRegion *ram_memory;MemoryRegion *rom_memory = system_memory;
@@ -566,23 +564,6 @@ static void pc_init_isa(MachineState *machine) }#endif -if (piix4_pm) { - smi_irq =qemu_allocate_irq (pc_acpi_smi_interrupt, first_cpu,0 ); - -qdev_connect_gpio_out_named (DEVICE (piix4_pm),"smi-irq" ,0 , smi_irq); - pcms->smbus =I2C_BUS (qdev_get_child_bus (DEVICE (piix4_pm),"i2c" )); -/* TODO: Populate SPD eeprom data. */ -smbus_eeprom_init (pcms->smbus,8 ,NULL ,0 ); - -object_property_add_link (OBJECT (machine),PC_MACHINE_ACPI_DEVICE_PROP , -TYPE_HOTPLUG_HANDLER , - (Object **)&x86ms->acpi_dev, - object_property_allow_set_link, -OBJ_PROP_LINK_STRONG ); -object_property_set_link (OBJECT (machine),PC_MACHINE_ACPI_DEVICE_PROP , - piix4_pm, &error_abort); - } -if (machine->nvdimms_state->is_enabled) { nvdimm_init_acpi_state(machine->nvdimms_state, system_io, x86_nvdimm_acpi_dsmio,
Signature · 1 line
2.43.0
Re: [PATCH v2 03/12] hw/i386/pc_piix.c: remove SMI and piix4_pm initialisation from pc_init_isa()
Quoted 6 lines · Mark Cave-Ayland
These are based upon the PIIX4 PCI chipset and so can never be used on an isapc machine.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 19 ------------------- 1 file changed, 19 deletions(-)
PATCH v2 4/12 hw/i386/pc_piix.c: remove SGX initialisation from pc_init_isa()
In reply to Mark Cave-AylandThe Intel SGX instructions only exist on recent CPUs and so would never be available on a CPU from the pre-PCI era.
--- hw/i386/pc_piix.c | 1 - 1 file changed, 1 deletion(-)
hw/i386/pc_piix.c +0 -1
@@ -492,7 +492,6 @@ static void pc_init_isa(MachineState *machine) } } -pc_machine_init_sgx_epc (pcms);x86_cpus_init (x86ms, pcmc->default_cpu_version);if (kvm_enabled ()) {
Signature · 1 line
2.43.0
PATCH v2 5/12 hw/i386/pc_piix.c: remove nvdimm initialisation from pc_init_isa()
In reply to Mark Cave-AylandNVDIMMs cannot be used by PCs from a pre-PCI era.
--- hw/i386/pc_piix.c | 6 ------ 1 file changed, 6 deletions(-)
hw/i386/pc_piix.c +0 -6
@@ -562,12 +562,6 @@ static void pc_init_isa(MachineState *machine) } }#endif - -if (machine->nvdimms_state->is_enabled) { -nvdimm_init_acpi_state (machine->nvdimms_state, system_io, - x86_nvdimm_acpi_dsmio, - x86ms->fw_cfg,OBJECT (pcms)); - } }#endif
Signature · 1 line
2.43.0
Re: [PATCH v2 05/12] hw/i386/pc_piix.c: remove nvdimm initialisation from pc_init_isa()
Quoted 6 lines · Mark Cave-Ayland
NVDIMMs cannot be used by PCs from a pre-PCI era.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 6 ------ 1 file changed, 6 deletions(-)
PATCH v2 6/12 hw/i386/pc_piix.c: simplify RAM size logic in pc_init_isa()
In reply to Mark Cave-AylandAll isapc machines must have 32-bit CPUs and so the RAM split logic can be hardcoded accordingly.
--- hw/i386/pc_piix.c | 58 ++++------------------------------------------- 1 file changed, 4 insertions(+), 54 deletions(-)
hw/i386/pc_piix.c +4 -54
@@ -427,69 +427,19 @@ static void pc_init_isa(MachineState *machine)GSIState *gsi_state;MemoryRegion *ram_memory;MemoryRegion *rom_memory = system_memory; -ram_addr_t lowmem;uint64_t hole64_size =0 ;/* -* Calculate ram split, for memory below and above 4G. It's a bit -* complicated for backward compatibility reasons ... -* -* - Traditional split is 3.5G (lowmem = 0xe0000000). This is the -* default value for max_ram_below_4g now. -* -* - Then, to gigabyte align the memory, we move the split to 3G -* (lowmem = 0xc0000000). But only in case we have to split in -* the first place, i.e. ram_size is larger than (traditional) -* lowmem. And for new machine types (gigabyte_align = true) -* only, for live migration compatibility reasons. -* -* - Next the max-ram-below-4g option was added, which allowed to -* reduce lowmem to a smaller value, to allow a larger PCI I/O -* window below 4G. qemu doesn't enforce gigabyte alignment here, -* but prints a warning. -* -* - Finally max-ram-below-4g got updated to also allow raising lowmem, -* so legacy non-PAE guests can get as much memory as possible in -* the 32bit address space below 4G. -* -* - Note that Xen has its own ram setup code in xen_ram_init(), -* called via xen_hvm_init_pc(). -* -* Examples: -* qemu -M pc-1.7 -m 4G (old default) -> 3584M low, 512M high -* qemu -M pc -m 4G (new default) -> 3072M low, 1024M high -* qemu -M pc,max-ram-below-4g=2G -m 4G -> 2048M low, 2048M high -* qemu -M pc,max-ram-below-4g=4G -m 3968M -> 3968M low (=4G-128M) +* There is no RAM split for the isapc 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 */ - } - lowmem = pcms->max_ram_below_4g; -if (machine->ram_size >= pcms->max_ram_below_4g) { -if (pcmc->gigabyte_align) { -if (lowmem >0xc0000000 ) { - lowmem =0xc0000000 ; - } -if (lowmem & (1 * GiB -1 )) { -warn_report ("Large machine and max_ram_below_4g " -"(%" PRIu64") not a multiple of 1G; " -"possible bad performance." , - pcms->max_ram_below_4g); - } - } - } -if (machine->ram_size >= lowmem) { - x86ms->above_4g_mem_size = machine->ram_size - lowmem; - x86ms->below_4g_mem_size = lowmem; - }else { - x86ms->above_4g_mem_size =0 ; - x86ms->below_4g_mem_size = machine->ram_size; - } + pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ + x86ms->above_4g_mem_size =0 ; + x86ms->below_4g_mem_size = machine->ram_size; }x86_cpus_init (x86ms, pcmc->default_cpu_version);
Signature · 1 line
2.43.0
Re: [PATCH v2 06/12] hw/i386/pc_piix.c: simplify RAM size logic in pc_init_isa()
Quoted 2 lines · Mark Cave-Ayland
All isapc machines must have 32-bit CPUs and so the RAM split logic can be hardcoded accordingly.
s/32-bit CPUs/32-bit address space/?
Quoted 5 lines
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 58 ++++------------------------------------------- 1 file changed, 4 insertions(+), 54 deletions(-)
PATCH v2 7/12 hw/i386/pc_piix.c: hardcode hole64_size to 0 in pc_init_isa()
In reply to Mark Cave-AylandAll isapc machines must have 32-bit CPUs and have no PCI 64-bit hole so it can be hardcoded to 0.
--- hw/i386/pc_piix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/i386/pc_piix.c +1 -2
@@ -427,7 +427,6 @@ static void pc_init_isa(MachineState *machine)GSIState *gsi_state;MemoryRegion *ram_memory;MemoryRegion *rom_memory = system_memory; -uint64_t hole64_size =0 ;/* * There is no RAM split for the isapc machine
@@ -450,7 +449,7 @@ static void pc_init_isa(MachineState *machine)/* allocate ram and load rom/bios */ if (!xen_enabled ()) { -pc_memory_init (pcms, system_memory, rom_memory, hole64_size); +pc_memory_init (pcms, system_memory, rom_memory,0 ); }else {assert (machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size);
Signature · 1 line
2.43.0
Re: [PATCH v2 07/12] hw/i386/pc_piix.c: hardcode hole64_size to 0 in pc_init_isa()
Quoted 7 lines · Mark Cave-Ayland
All isapc machines must have 32-bit CPUs and have no PCI 64-bit hole so it can be hardcoded to 0.
Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH v2 8/12 hw/i386/pc_piix.c: remove pc_system_flash_cleanup_unused() from pc_init_isa()
In reply to Mark Cave-AylandThis function contains 'assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled)' and so we can safely assume that it should never be used for the isapc machine.
--- hw/i386/pc_piix.c | 1 - 1 file changed, 1 deletion(-)
hw/i386/pc_piix.c +0 -1
@@ -454,7 +454,6 @@ static void pc_init_isa(MachineState *machine)assert (machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size); -pc_system_flash_cleanup_unused (pcms);if (machine->kernel_filename !=NULL ) {/* For xen HVM direct kernel boot, load linux here */ xen_load_linux (pcms);
Signature · 1 line
2.43.0
PATCH v2 9/12 hw/i386/pc_piix.c: always initialise ISA IDE drives in pc_init_isa()
In reply to Mark Cave-AylandBy definition an isapc machine must always use ISA IDE drives so ensure that they are always enabled. At the same time also remove the surrounding CONFIG_IDE_ISA define since it will be enabled via the ISAPC Kconfig.
--- hw/i386/pc_piix.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
hw/i386/pc_piix.c +15 -20
@@ -427,6 +427,8 @@ static void pc_init_isa(MachineState *machine)GSIState *gsi_state;MemoryRegion *ram_memory;MemoryRegion *rom_memory = system_memory; +DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; +int i;/* * There is no RAM split for the isapc machine
@@ -489,27 +491,20 @@ static void pc_init_isa(MachineState *machine)pc_nic_init (pcmc, isa_bus, pcms->pcibus); -#ifdef CONFIG_IDE_ISA -if (!pcmc->pci_enabled) { -DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; -int i; - -ide_drive_get (hd,ARRAY_SIZE (hd)); -for (i =0 ; i <MAX_IDE_BUS ; i++) { -ISADevice *dev; -char busname[] ="ide.0" ; - dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], - ide_irq[i], - hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); -/* -* The ide bus name is ide.0 for the first bus and ide.1 for the -* second one. -*/ - busname[4 ] ='0' + i; - pcms->idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); - } +ide_drive_get (hd,ARRAY_SIZE (hd)); +for (i =0 ; i <MAX_IDE_BUS ; i++) { +ISADevice *dev; +char busname[] ="ide.0" ; + dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], + ide_irq[i], + hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); +/* +* The ide bus name is ide.0 for the first bus and ide.1 for the +* second one. +*/ + busname[4 ] ='0' + i; + pcms->idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); } -#endif }#endif
Signature · 1 line
2.43.0
Re: [PATCH v2 09/12] hw/i386/pc_piix.c: always initialise ISA IDE drives in pc_init_isa()
Quoted 1 line · Mark Cave-Ayland
By definition an isapc machine must always use ISA IDE drives
ISA: yes, IDE: not necessarily. Anyhow,
Quoted 8 lines
so ensure that they
are always enabled. At the same time also remove the surroundingCONFIG_IDE_ISAdefine since it will be enabled via the ISAPCKconfig.Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
PATCH v2 10/12 hw/i386/pc_piix.c: assume pcmc->pci_enabled is always false in pc_init_isa()
In reply to Mark Cave-AylandBy definition PCI can never be enabled on an isapc machine so hardcode the relevant values set via pcmc->pci_enabled.
--- hw/i386/pc_piix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/i386/pc_piix.c +2 -2
@@ -462,7 +462,7 @@ static void pc_init_isa(MachineState *machine) } } - gsi_state =pc_gsi_create (&x86ms->gsi, pcmc->pci_enabled); + gsi_state =pc_gsi_create (&x86ms->gsi, false); isa_bus =isa_bus_new (NULL , system_memory, system_io, &error_abort);
@@ -483,7 +483,7 @@ static void pc_init_isa(MachineState *machine)x86_register_ferr_irq (x86ms->gsi[13 ]); } -pc_vga_init (isa_bus, pcmc->pci_enabled ? pcms->pcibus :NULL ); +pc_vga_init (isa_bus,NULL );/* init basic PC hardware */ pc_basic_device_init(pcms, isa_bus, x86ms->gsi, x86ms->rtc,
Signature · 1 line
2.43.0
Re: [PATCH v2 10/12] hw/i386/pc_piix.c: assume pcmc->pci_enabled is always false in pc_init_isa()
Quoted 7 lines · Mark Cave-Ayland
By definition PCI can never be enabled on an isapc machine so hardcode the relevant values set via
pcmc->pci_enabled.Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH v2 10/12] hw/i386/pc_piix.c: assume pcmc->pci_enabled is always false in pc_init_isa()
In reply to Mark Cave-AylandAm 18. Juni 2025 11:27:15 UTC schrieb Mark Cave-Ayland <[email protected]>:
Quoted 2 lines
By definition PCI can never be enabled on an isapc machine so hardcode the relevant values set via
pcmc->pci_enabled.
The inverse should be true now for pc-i440fx, so a similar patch is needed there as well.
Best regards,
Bernhard
Quoted 28 lines
Signed-off-by Mark Cave-Ayland <[email protected]>---
hw/i386/pc_piix.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)hw/i386/pc_piix.c +2
-2@@ -462,7 +462,7 @@ static void pc_init_isa(MachineState *machine) } } - gsi_state =pc_gsi_create (&x86ms->gsi, pcmc->pci_enabled); + gsi_state =pc_gsi_create (&x86ms->gsi, false); isa_bus =isa_bus_new (NULL , system_memory, system_io, &error_abort);@@ -483,7 +483,7 @@ static void pc_init_isa(MachineState *machine)x86_register_ferr_irq (x86ms->gsi[13 ]); } -pc_vga_init (isa_bus, pcmc->pci_enabled ? pcms->pcibus :NULL ); +pc_vga_init (isa_bus,NULL );/* init basic PC hardware */ pc_basic_device_init(pcms, isa_bus, x86ms->gsi, x86ms->rtc,
Re: [PATCH v2 10/12] hw/i386/pc_piix.c: assume pcmc->pci_enabled is always false in pc_init_isa()
Quoted 8 lines · Bernhard Beschow
Am 18. Juni 2025 11:27:15 UTC schrieb Mark Cave-Ayland <[email protected]>:
Quoted 2 lines
By definition PCI can never be enabled on an isapc machine so hardcode the relevant values set via
pcmc->pci_enabled.The inverse should be true now for pc-i440fx, so a similar patch is needed there as well.
Best regards,
Bernhard
Good point. I've added a new patch that does this in v3 (soon to be posted). It certainly seems like a nice cleanup, and I think that further tidy-ups are possible in future if you can assume that PCI is always present.
ATB,
Mark.
PATCH v2 11/12 hw/i386/pc_piix.c: hardcode pcms->pci_bus to NULL in pc_init_isa()
In reply to Mark Cave-AylandBy definition PCI can never be enabled on an isapc machine so hardcode the PCIBus argument of pc_nic_init() to NULL.
--- hw/i386/pc_piix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/pc_piix.c +1 -1
@@ -489,7 +489,7 @@ static void pc_init_isa(MachineState *machine)pc_basic_device_init (pcms, isa_bus, x86ms->gsi, x86ms->rtc, !MACHINE_CLASS (pcmc)->no_floppy,0x4 ); -pc_nic_init (pcmc, isa_bus, pcms->pcibus); +pc_nic_init (pcmc, isa_bus,NULL );ide_drive_get (hd,ARRAY_SIZE (hd));for (i =0 ; i <MAX_IDE_BUS ; i++) {
Signature · 1 line
2.43.0
Re: [PATCH v2 11/12] hw/i386/pc_piix.c: hardcode pcms->pci_bus to NULL in pc_init_isa()
Quoted 7 lines · Mark Cave-Ayland
By definition PCI can never be enabled on an isapc machine so hardcode the PCIBus argument of
pc_nic_init()to NULL.Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/pc_piix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 12/12 hw/i386: move isapc machine to separate isapc.c file
In reply to Mark Cave-AylandNow that pc_init_isa() is independent of any PCI initialisation, move it into a separate isapc.c file. This enables us to finally fix the dependency of ISAPC on I440FX in hw/i386/Kconfig.
Note that as part of the move to a separate file we can see that the licence text is a verbatim copy of the MIT licence. The text originates from commit 1df912cf9e ("VL license of the day is MIT/BSD") so we can be sure that this was the original intent. As a consequence we can update the file header to use a SPDX tag as per the current project contribution guidelines.
--- hw/i386/Kconfig | 3 - hw/i386/isapc.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/meson.build | 1 + hw/i386/pc_piix.c | 117 ----------------------------------- 4 files changed, 146 insertions(+), 120 deletions(-) create mode 100644 hw/i386/isapc.c
hw/i386/Kconfig +0 -3
@@ -96,9 +96,6 @@ config ISAPC select ISA_BUS select PC select IDE_ISA - # FIXME: it is in the same file as i440fx, and does not compile - # if separated - depends on I440FX config Q35 bool
hw/i386/isapc.c new file +145 -0
145 lines not on this page · raw message
hw/i386/meson.build +1 -0
@@ -14,6 +14,7 @@ i386_ss.add(when: 'CONFIG_X86_IOMMU', if_true: files('x86-iommu.c'), i386_ss.add(when: 'CONFIG_AMD_IOMMU', if_true: files('amd_iommu.c'), if_false: files('amd_iommu-stub.c')) i386_ss.add(when: 'CONFIG_I440FX', if_true: files('pc_piix.c')) +i386_ss.add(when: 'CONFIG_ISAPC', if_true: files('isapc.c')) i386_ss.add(when: 'CONFIG_MICROVM', if_true: files('x86-common.c', 'microvm.c', 'acpi-microvm.c', 'microvm-dt.c')) i386_ss.add(when: 'CONFIG_NITRO_ENCLAVE', if_true: files('nitro_enclave.c')) i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c'))
hw/i386/pc_piix.c +0 -117
129 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 12/12] hw/i386: move isapc machine to separate isapc.c file
Quoted 73 lines · Mark Cave-Ayland
Now that
pc_init_isa()is independent of any PCI initialisation, move it into a separateisapc.cfile. This enables us to finally fix the dependency of ISAPC on I440FX in hw/i386/Kconfig.Note that as part of the move to a separate file we can see that the licence text is a verbatim copy of the MIT licence. The text originates from commit
1df912cf9e("VL license of the day is MIT/BSD") so we can be sure that this was the original intent. As a consequence we can update the file header to use a SPDX tag as per the current project contribution guidelines.Signed-off-by Mark Cave-Ayland <[email protected]>--- hw/i386/Kconfig | 3 - hw/i386/isapc.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/meson.build | 1 + hw/i386/pc_piix.c | 117 ----------------------------------- 4 files changed, 146 insertions(+), 120 deletions(-)create mode 100644
hw/i386/isapc.chw/i386/isapc.c new file +47
-0@@ -0,0 +1,145 @@ +/* +* QEMU PC System Emulator +* +* Copyright (c) 2003-2004 Fabrice Bellard +* +* SPDX-License-Identifier: MIT +*/ + +#include "qemu/osdep.h" + +#include "hw/char/parallel-isa.h" +#include "hw/dma/i8257.h" +#include "hw/loader.h" +#include "hw/i386/pc.h" +#include "hw/ide/isa.h" +#include "hw/ide/ide-bus.h" +#include "system/kvm.h" +#include "hw/i386/kvm/clock.h" +#include "hw/xen/xen-x86.h" +#include "system/xen.h" +#include "hw/rtc/mc146818rtc.h" +#include "target/i386/cpu.h" + +static const int ide_iobase[MAX_IDE_BUS ] = {0x1f0 ,0x170 }; +static const int ide_iobase2[MAX_IDE_BUS ] = {0x3f6 ,0x376 }; +static const int ide_irq[MAX_IDE_BUS ] = {14 ,15 }; + + +static void pc_init_isa (MachineState *machine) +{ +PCMachineState *pcms =PC_MACHINE (machine); +PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms); +X86MachineState *x86ms =X86_MACHINE (machine); +MemoryRegion *system_memory =get_system_memory (); +MemoryRegion *system_io =get_system_io (); +ISABus *isa_bus; +GSIState *gsi_state; +MemoryRegion *ram_memory; +MemoryRegion *rom_memory = system_memory; +DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; +uint32_t irq; +int i; + +/* +* There is no RAM split for the isapc machine +*/ +if (xen_enabled ()) {
hw/i386/isapc.c line 57
Quoted 10 lines
hw/i386/isapc.c new file +10
-0+xen_hvm_init_pc (pcms, &ram_memory); + }else { + ram_memory = machine->ram; + + pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ + x86ms->above_4g_mem_size =0 ; + x86ms->below_4g_mem_size = machine->ram_size; + } + +x86_cpus_init (x86ms, pcmc->default_cpu_version);
Should we check the CPU is 32-bit or is it OK to use 64-bit CPUs?
Re: [PATCH v2 12/12] hw/i386: move isapc machine to separate isapc.c file
In reply to Mark Cave-AylandAm 18. Juni 2025 11:27:17 UTC schrieb Mark Cave-Ayland <[email protected]>:
Quoted 49 lines
Now that
pc_init_isa()is independent of any PCI initialisation, move it into a separateisapc.cfile. This enables us to finally fix the dependency of ISAPC on I440FX in hw/i386/Kconfig.Note that as part of the move to a separate file we can see that the licence text is a verbatim copy of the MIT licence. The text originates from commit
1df912cf9e("VL license of the day is MIT/BSD") so we can be sure that this was the original intent. As a consequence we can update the file header to use a SPDX tag as per the current project contribution guidelines.Signed-off-by Mark Cave-Ayland <[email protected]>---
hw/i386/Kconfig | 3 - hw/i386/isapc.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/meson.build | 1 + hw/i386/pc_piix.c | 117 ----------------------------------- 4 files changed, 146 insertions(+), 120 deletions(-)create mode 100644
hw/i386/isapc.chw/i386/Kconfig +0
-3@@ -96,9 +96,6 @@ config ISAPC select ISA_BUS select PC select IDE_ISA - # FIXME: it is in the same file as i440fx, and does not compile - # if separated - depends on I440FXconfig Q35
boolhw/i386/isapc.c new file +10
-0@@ -0,0 +1,145 @@ +/* +* QEMU PC System Emulator +* +* Copyright (c) 2003-2004 Fabrice Bellard +* +* SPDX-License-Identifier: MIT +*/ + +#include "qemu/osdep.h" +
hw/i386/isapc.c line 20
Quoted 10 lines
hw/i386/isapc.c new file +10
-0+#include "hw/char/parallel-isa.h" +#include "hw/dma/i8257.h" +#include "hw/loader.h" +#include "hw/i386/pc.h" +#include "hw/ide/isa.h" +#include "hw/ide/ide-bus.h" +#include "system/kvm.h" +#include "hw/i386/kvm/clock.h" +#include "hw/xen/xen-x86.h" +#include "system/xen.h"
I believe that Xen can be pruned from the machine as well since it requires PCI AFAIR.
Best regards,
Bernhard
Quoted 272 lines
hw/i386/isapc.c new file +125
-0+#include "hw/rtc/mc146818rtc.h" +#include "target/i386/cpu.h" + +static const int ide_iobase[MAX_IDE_BUS ] = {0x1f0 ,0x170 }; +static const int ide_iobase2[MAX_IDE_BUS ] = {0x3f6 ,0x376 }; +static const int ide_irq[MAX_IDE_BUS ] = {14 ,15 }; + + +static void pc_init_isa (MachineState *machine) +{ +PCMachineState *pcms =PC_MACHINE (machine); +PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms); +X86MachineState *x86ms =X86_MACHINE (machine); +MemoryRegion *system_memory =get_system_memory (); +MemoryRegion *system_io =get_system_io (); +ISABus *isa_bus; +GSIState *gsi_state; +MemoryRegion *ram_memory; +MemoryRegion *rom_memory = system_memory; +DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; +uint32_t irq; +int i; + +/* +* There is no RAM split for the isapc machine +*/ +if (xen_enabled ()) { +xen_hvm_init_pc (pcms, &ram_memory); + }else { + ram_memory = machine->ram; + + pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ + x86ms->above_4g_mem_size =0 ; + x86ms->below_4g_mem_size = machine->ram_size; + } + +x86_cpus_init (x86ms, pcmc->default_cpu_version); + +if (kvm_enabled ()) { +kvmclock_create (pcmc->kvmclock_create_always); + } + +/* allocate ram and load rom/bios */ +if (!xen_enabled ()) { +pc_memory_init (pcms, system_memory, rom_memory,0 ); + }else { +assert (machine->ram_size == x86ms->below_4g_mem_size + + x86ms->above_4g_mem_size); + +if (machine->kernel_filename !=NULL ) { +/* For xen HVM direct kernel boot, load linux here */ +xen_load_linux (pcms); + } + } + + gsi_state =pc_gsi_create (&x86ms->gsi, false); + + isa_bus =isa_bus_new (NULL , system_memory, system_io, + &error_abort); +isa_bus_register_input_irqs (isa_bus, x86ms->gsi); + + x86ms->rtc =isa_new (TYPE_MC146818_RTC ); +qdev_prop_set_int32 (DEVICE (x86ms->rtc),"base_year" ,2000 ); +isa_realize_and_unref (x86ms->rtc, isa_bus, &error_fatal); + irq =object_property_get_uint (OBJECT (x86ms->rtc),"irq" , + &error_fatal); +isa_connect_gpio_out (ISA_DEVICE (x86ms->rtc),0 , irq); + +i8257_dma_init (OBJECT (machine), isa_bus,0 ); + pcms->hpet_enabled = false; + +if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) { +pc_i8259_create (isa_bus, gsi_state->i8259_irq); + } + +if (tcg_enabled ()) { +x86_register_ferr_irq (x86ms->gsi[13 ]); + } + +pc_vga_init (isa_bus,NULL ); + +/* init basic PC hardware */ +pc_basic_device_init (pcms, isa_bus, x86ms->gsi, x86ms->rtc, + !MACHINE_CLASS (pcmc)->no_floppy,0x4 ); + +pc_nic_init (pcmc, isa_bus,NULL ); + +ide_drive_get (hd,ARRAY_SIZE (hd)); +for (i =0 ; i <MAX_IDE_BUS ; i++) { +ISADevice *dev; +char busname[] ="ide.0" ; + dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], + ide_irq[i], + hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); +/* +* The ide bus name is ide.0 for the first bus and ide.1 for the +* second one. +*/ + busname[4 ] ='0' + i; + pcms->idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); + } +} + +static void isapc_machine_options (MachineClass *m) +{ +PCMachineClass *pcmc =PC_MACHINE_CLASS (m); + + m->desc ="ISA-only PC" ; + m->max_cpus =1 ; + m->option_rom_has_mr = true; + m->rom_file_has_mr = false; + pcmc->pci_enabled = false; + pcmc->has_acpi_build = false; + pcmc->smbios_defaults = false; + pcmc->gigabyte_align = false; + pcmc->smbios_legacy_mode = true; + pcmc->has_reserved_memory = false; + m->default_nic ="ne2k_isa" ; + m->default_cpu_type =X86_CPU_TYPE_NAME ("486" ); + m->no_floppy = !module_object_class_by_name (TYPE_ISA_FDC ); + m->no_parallel = !module_object_class_by_name (TYPE_ISA_PARALLEL ); +} + +DEFINE_PC_MACHINE (isapc,"isapc" , pc_init_isa, + isapc_machine_options);hw/i386/meson.build +1
-0@@ -14,6 +14,7 @@ i386_ss.add(when: 'CONFIG_X86_IOMMU', if_true: files('x86-iommu.c'), i386_ss.add(when: 'CONFIG_AMD_IOMMU', if_true: files('amd_iommu.c'), if_false: files('amd_iommu-stub.c')) i386_ss.add(when: 'CONFIG_I440FX', if_true: files('pc_piix.c')) +i386_ss.add(when: 'CONFIG_ISAPC', if_true: files('isapc.c')) i386_ss.add(when: 'CONFIG_MICROVM', if_true: files('x86-common.c', 'microvm.c', 'acpi-microvm.c', 'microvm-dt.c')) i386_ss.add(when: 'CONFIG_NITRO_ENCLAVE', if_true: files('nitro_enclave.c')) i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c'))hw/i386/pc_piix.c +0
-117@@ -415,99 +415,6 @@ static void pc_set_south_bridge(Object *obj, int value, Error **errp) pcms->south_bridge = PCSouthBridgeOption_lookup.array[value]; } -#ifdef CONFIG_ISAPC -static void pc_init_isa (MachineState *machine) -{ -PCMachineState *pcms =PC_MACHINE (machine); -PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms); -X86MachineState *x86ms =X86_MACHINE (machine); -MemoryRegion *system_memory =get_system_memory (); -MemoryRegion *system_io =get_system_io (); -ISABus *isa_bus; -GSIState *gsi_state; -MemoryRegion *ram_memory; -MemoryRegion *rom_memory = system_memory; -DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; -int i; - -/* -* There is no RAM split for the isapc machine -*/ -if (xen_enabled ()) { -xen_hvm_init_pc (pcms, &ram_memory); - }else { - ram_memory = machine->ram; - - pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ - x86ms->above_4g_mem_size =0 ; - x86ms->below_4g_mem_size = machine->ram_size; - } - -x86_cpus_init (x86ms, pcmc->default_cpu_version); - -if (kvm_enabled ()) { -kvmclock_create (pcmc->kvmclock_create_always); - } - -/* allocate ram and load rom/bios */ -if (!xen_enabled ()) { -pc_memory_init (pcms, system_memory, rom_memory,0 ); - }else { -assert (machine->ram_size == x86ms->below_4g_mem_size + - x86ms->above_4g_mem_size); - -if (machine->kernel_filename !=NULL ) { -/* For xen HVM direct kernel boot, load linux here */ -xen_load_linux (pcms); - } - } - - gsi_state =pc_gsi_create (&x86ms->gsi, false); - - isa_bus =isa_bus_new (NULL , system_memory, system_io, - &error_abort); -isa_bus_register_input_irqs (isa_bus, x86ms->gsi); - - x86ms->rtc =isa_new (TYPE_MC146818_RTC ); -qdev_prop_set_int32 (DEVICE (x86ms->rtc),"base_year" ,2000 ); -isa_realize_and_unref (x86ms->rtc, isa_bus, &error_fatal); - -i8257_dma_init (OBJECT (machine), isa_bus,0 ); - pcms->hpet_enabled = false; - -if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) { -pc_i8259_create (isa_bus, gsi_state->i8259_irq); - } - -if (tcg_enabled ()) { -x86_register_ferr_irq (x86ms->gsi[13 ]); - } - -pc_vga_init (isa_bus,NULL ); - -/* init basic PC hardware */ -pc_basic_device_init (pcms, isa_bus, x86ms->gsi, x86ms->rtc, - !MACHINE_CLASS (pcmc)->no_floppy,0x4 ); - -pc_nic_init (pcmc, isa_bus,NULL ); - -ide_drive_get (hd,ARRAY_SIZE (hd)); -for (i =0 ; i <MAX_IDE_BUS ; i++) { -ISADevice *dev; -char busname[] ="ide.0" ; - dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], - ide_irq[i], - hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); -/* -* The ide bus name is ide.0 for the first bus and ide.1 for the -* second one. -*/ - busname[4 ] ='0' + i; - pcms->idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); - } -} -#endif -#ifdef CONFIG_XEN static void pc_xen_hvm_init_pci (MachineState *machine) {@@ -869,30 +776,6 @@ static void pc_i440fx_machine_2_6_options(MachineClass *m)DEFINE_I440FX_MACHINE (2 ,6 ); -#ifdef CONFIG_ISAPC -static void isapc_machine_options (MachineClass *m) -{ -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); - m->desc ="ISA-only PC" ; - m->max_cpus =1 ; - m->option_rom_has_mr = true; - m->rom_file_has_mr = false; - pcmc->pci_enabled = false; - pcmc->has_acpi_build = false; - pcmc->smbios_defaults = false; - pcmc->gigabyte_align = false; - pcmc->smbios_legacy_mode = true; - pcmc->has_reserved_memory = false; - m->default_nic ="ne2k_isa" ; - m->default_cpu_type =X86_CPU_TYPE_NAME ("486" ); - m->no_floppy = !module_object_class_by_name (TYPE_ISA_FDC ); - m->no_parallel = !module_object_class_by_name (TYPE_ISA_PARALLEL ); -} - -DEFINE_PC_MACHINE (isapc,"isapc" , pc_init_isa, - isapc_machine_options); -#endif -#ifdef CONFIG_XEN static void xenfv_machine_4_2_options (MachineClass *m) {
Re: [PATCH v2 12/12] hw/i386: move isapc machine to separate isapc.c file
Quoted 63 lines · Bernhard Beschow
Am 18. Juni 2025 11:27:17 UTC schrieb Mark Cave-Ayland <[email protected]>:
Quoted 49 lines
Now that
pc_init_isa()is independent of any PCI initialisation, move it into a separateisapc.cfile. This enables us to finally fix the dependency of ISAPC on I440FX in hw/i386/Kconfig.Note that as part of the move to a separate file we can see that the licence text is a verbatim copy of the MIT licence. The text originates from commit
1df912cf9e("VL license of the day is MIT/BSD") so we can be sure that this was the original intent. As a consequence we can update the file header to use a SPDX tag as per the current project contribution guidelines.Signed-off-by Mark Cave-Ayland <[email protected]>---
hw/i386/Kconfig | 3 - hw/i386/isapc.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/meson.build | 1 + hw/i386/pc_piix.c | 117 ----------------------------------- 4 files changed, 146 insertions(+), 120 deletions(-)create mode 100644
hw/i386/isapc.chw/i386/Kconfig +0
-3@@ -96,9 +96,6 @@ config ISAPC select ISA_BUS select PC select IDE_ISA - # FIXME: it is in the same file as i440fx, and does not compile - # if separated - depends on I440FXconfig Q35
boolhw/i386/isapc.c new file +10
-0@@ -0,0 +1,145 @@ +/* +* QEMU PC System Emulator +* +* Copyright (c) 2003-2004 Fabrice Bellard +* +* SPDX-License-Identifier: MIT +*/ + +#include "qemu/osdep.h" +hw/i386/isapc.c line 20
Quoted 10 lines
hw/i386/isapc.c new file +10
-0+#include "hw/char/parallel-isa.h" +#include "hw/dma/i8257.h" +#include "hw/loader.h" +#include "hw/i386/pc.h" +#include "hw/ide/isa.h" +#include "hw/ide/ide-bus.h" +#include "system/kvm.h" +#include "hw/i386/kvm/clock.h" +#include "hw/xen/xen-x86.h" +#include "system/xen.h" I believe that Xen can be pruned from the machine as well since it requires PCI AFAIR.
Quoted 2 lines
Best regards,
Bernhard
Thanks for the suggestion! I got in touch with the Xen folks over Matrix to ask about this, and the feedback I received was that Xen does support non-PCI IO and that in theory it "should work". So I've left this in for now.
ATB,
Mark.
Quoted 272 lines
Quoted 272 lines
hw/i386/isapc.c new file +125
-0+#include "hw/rtc/mc146818rtc.h" +#include "target/i386/cpu.h" + +static const int ide_iobase[MAX_IDE_BUS ] = {0x1f0 ,0x170 }; +static const int ide_iobase2[MAX_IDE_BUS ] = {0x3f6 ,0x376 }; +static const int ide_irq[MAX_IDE_BUS ] = {14 ,15 }; + + +static void pc_init_isa (MachineState *machine) +{ +PCMachineState *pcms =PC_MACHINE (machine); +PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms); +X86MachineState *x86ms =X86_MACHINE (machine); +MemoryRegion *system_memory =get_system_memory (); +MemoryRegion *system_io =get_system_io (); +ISABus *isa_bus; +GSIState *gsi_state; +MemoryRegion *ram_memory; +MemoryRegion *rom_memory = system_memory; +DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; +uint32_t irq; +int i; + +/* +* There is no RAM split for the isapc machine +*/ +if (xen_enabled ()) { +xen_hvm_init_pc (pcms, &ram_memory); + }else { + ram_memory = machine->ram; + + pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ + x86ms->above_4g_mem_size =0 ; + x86ms->below_4g_mem_size = machine->ram_size; + } + +x86_cpus_init (x86ms, pcmc->default_cpu_version); + +if (kvm_enabled ()) { +kvmclock_create (pcmc->kvmclock_create_always); + } + +/* allocate ram and load rom/bios */ +if (!xen_enabled ()) { +pc_memory_init (pcms, system_memory, rom_memory,0 ); + }else { +assert (machine->ram_size == x86ms->below_4g_mem_size + + x86ms->above_4g_mem_size); + +if (machine->kernel_filename !=NULL ) { +/* For xen HVM direct kernel boot, load linux here */ +xen_load_linux (pcms); + } + } + + gsi_state =pc_gsi_create (&x86ms->gsi, false); + + isa_bus =isa_bus_new (NULL , system_memory, system_io, + &error_abort); +isa_bus_register_input_irqs (isa_bus, x86ms->gsi); + + x86ms->rtc =isa_new (TYPE_MC146818_RTC ); +qdev_prop_set_int32 (DEVICE (x86ms->rtc),"base_year" ,2000 ); +isa_realize_and_unref (x86ms->rtc, isa_bus, &error_fatal); + irq =object_property_get_uint (OBJECT (x86ms->rtc),"irq" , + &error_fatal); +isa_connect_gpio_out (ISA_DEVICE (x86ms->rtc),0 , irq); + +i8257_dma_init (OBJECT (machine), isa_bus,0 ); + pcms->hpet_enabled = false; + +if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) { +pc_i8259_create (isa_bus, gsi_state->i8259_irq); + } + +if (tcg_enabled ()) { +x86_register_ferr_irq (x86ms->gsi[13 ]); + } + +pc_vga_init (isa_bus,NULL ); + +/* init basic PC hardware */ +pc_basic_device_init (pcms, isa_bus, x86ms->gsi, x86ms->rtc, + !MACHINE_CLASS (pcmc)->no_floppy,0x4 ); + +pc_nic_init (pcmc, isa_bus,NULL ); + +ide_drive_get (hd,ARRAY_SIZE (hd)); +for (i =0 ; i <MAX_IDE_BUS ; i++) { +ISADevice *dev; +char busname[] ="ide.0" ; + dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], + ide_irq[i], + hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); +/* +* The ide bus name is ide.0 for the first bus and ide.1 for the +* second one. +*/ + busname[4 ] ='0' + i; + pcms->idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); + } +} + +static void isapc_machine_options (MachineClass *m) +{ +PCMachineClass *pcmc =PC_MACHINE_CLASS (m); + + m->desc ="ISA-only PC" ; + m->max_cpus =1 ; + m->option_rom_has_mr = true; + m->rom_file_has_mr = false; + pcmc->pci_enabled = false; + pcmc->has_acpi_build = false; + pcmc->smbios_defaults = false; + pcmc->gigabyte_align = false; + pcmc->smbios_legacy_mode = true; + pcmc->has_reserved_memory = false; + m->default_nic ="ne2k_isa" ; + m->default_cpu_type =X86_CPU_TYPE_NAME ("486" ); + m->no_floppy = !module_object_class_by_name (TYPE_ISA_FDC ); + m->no_parallel = !module_object_class_by_name (TYPE_ISA_PARALLEL ); +} + +DEFINE_PC_MACHINE (isapc,"isapc" , pc_init_isa, + isapc_machine_options);hw/i386/meson.build +1
-0@@ -14,6 +14,7 @@ i386_ss.add(when: 'CONFIG_X86_IOMMU', if_true: files('x86-iommu.c'), i386_ss.add(when: 'CONFIG_AMD_IOMMU', if_true: files('amd_iommu.c'), if_false: files('amd_iommu-stub.c')) i386_ss.add(when: 'CONFIG_I440FX', if_true: files('pc_piix.c')) +i386_ss.add(when: 'CONFIG_ISAPC', if_true: files('isapc.c')) i386_ss.add(when: 'CONFIG_MICROVM', if_true: files('x86-common.c', 'microvm.c', 'acpi-microvm.c', 'microvm-dt.c')) i386_ss.add(when: 'CONFIG_NITRO_ENCLAVE', if_true: files('nitro_enclave.c')) i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c'))hw/i386/pc_piix.c +0
-117@@ -415,99 +415,6 @@ static void pc_set_south_bridge(Object *obj, int value, Error **errp) pcms->south_bridge = PCSouthBridgeOption_lookup.array[value]; } -#ifdef CONFIG_ISAPC -static void pc_init_isa (MachineState *machine) -{ -PCMachineState *pcms =PC_MACHINE (machine); -PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms); -X86MachineState *x86ms =X86_MACHINE (machine); -MemoryRegion *system_memory =get_system_memory (); -MemoryRegion *system_io =get_system_io (); -ISABus *isa_bus; -GSIState *gsi_state; -MemoryRegion *ram_memory; -MemoryRegion *rom_memory = system_memory; -DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; -int i; - -/* -* There is no RAM split for the isapc machine -*/ -if (xen_enabled ()) { -xen_hvm_init_pc (pcms, &ram_memory); - }else { - ram_memory = machine->ram; - - pcms->max_ram_below_4g =0xe0000000 ;/* default: 3.5G */ - x86ms->above_4g_mem_size =0 ; - x86ms->below_4g_mem_size = machine->ram_size; - } - -x86_cpus_init (x86ms, pcmc->default_cpu_version); - -if (kvm_enabled ()) { -kvmclock_create (pcmc->kvmclock_create_always); - } - -/* allocate ram and load rom/bios */ -if (!xen_enabled ()) { -pc_memory_init (pcms, system_memory, rom_memory,0 ); - }else { -assert (machine->ram_size == x86ms->below_4g_mem_size + - x86ms->above_4g_mem_size); - -if (machine->kernel_filename !=NULL ) { -/* For xen HVM direct kernel boot, load linux here */ -xen_load_linux (pcms); - } - } - - gsi_state =pc_gsi_create (&x86ms->gsi, false); - - isa_bus =isa_bus_new (NULL , system_memory, system_io, - &error_abort); -isa_bus_register_input_irqs (isa_bus, x86ms->gsi); - - x86ms->rtc =isa_new (TYPE_MC146818_RTC ); -qdev_prop_set_int32 (DEVICE (x86ms->rtc),"base_year" ,2000 ); -isa_realize_and_unref (x86ms->rtc, isa_bus, &error_fatal); - -i8257_dma_init (OBJECT (machine), isa_bus,0 ); - pcms->hpet_enabled = false; - -if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) { -pc_i8259_create (isa_bus, gsi_state->i8259_irq); - } - -if (tcg_enabled ()) { -x86_register_ferr_irq (x86ms->gsi[13 ]); - } - -pc_vga_init (isa_bus,NULL ); - -/* init basic PC hardware */ -pc_basic_device_init (pcms, isa_bus, x86ms->gsi, x86ms->rtc, - !MACHINE_CLASS (pcmc)->no_floppy,0x4 ); - -pc_nic_init (pcmc, isa_bus,NULL ); - -ide_drive_get (hd,ARRAY_SIZE (hd)); -for (i =0 ; i <MAX_IDE_BUS ; i++) { -ISADevice *dev; -char busname[] ="ide.0" ; - dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], - ide_irq[i], - hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); -/* -* The ide bus name is ide.0 for the first bus and ide.1 for the -* second one. -*/ - busname[4 ] ='0' + i; - pcms->idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); - } -} -#endif -#ifdef CONFIG_XEN static void pc_xen_hvm_init_pci (MachineState *machine) {@@ -869,30 +776,6 @@ static void pc_i440fx_machine_2_6_options(MachineClass *m)DEFINE_I440FX_MACHINE (2 ,6 ); -#ifdef CONFIG_ISAPC -static void isapc_machine_options (MachineClass *m) -{ -PCMachineClass *pcmc =PC_MACHINE_CLASS (m); - m->desc ="ISA-only PC" ; - m->max_cpus =1 ; - m->option_rom_has_mr = true; - m->rom_file_has_mr = false; - pcmc->pci_enabled = false; - pcmc->has_acpi_build = false; - pcmc->smbios_defaults = false; - pcmc->gigabyte_align = false; - pcmc->smbios_legacy_mode = true; - pcmc->has_reserved_memory = false; - m->default_nic ="ne2k_isa" ; - m->default_cpu_type =X86_CPU_TYPE_NAME ("486" ); - m->no_floppy = !module_object_class_by_name (TYPE_ISA_FDC ); - m->no_parallel = !module_object_class_by_name (TYPE_ISA_PARALLEL ); -} - -DEFINE_PC_MACHINE (isapc,"isapc" , pc_init_isa, - isapc_machine_options); -#endif -#ifdef CONFIG_XEN static void xenfv_machine_4_2_options (MachineClass *m) {