AML Housekeeping
v3 cover AML Housekeeping
This series resolves the AcpiDeviceIfClass::madt_cpu function pointer. It turns out that it isn't needed and it even frees the ACPI controllers from assigning it an x86 specific function. This is especially interesting for the PIIX4 PM which is also used in MIPS only contexts.
Furthermore, the series introduces qbus_build_aml() which then gets used to resolve isa_build_aml().
v3:
- Clean up includes in AcpiDeviceIfClass::madt_cpu sub series last (Markus)
- Restructure qbus_build_aml() sub series (Phil, me)
v2:
- Don't inline qbus_build_aml() (Phil)
- Add 'hw/acpi/piix4: No need to #include "hw/southbridge/piix.h"'
Testing done:
* make check
* make check-avocado
* qemu-system-x86_64 -M pc -m 2G -cdrom manjaro-kde-21.2.6-220416-linux515.iso
* `qemu-system-x86_64 -M q35 -m 2G -cdrom \
manjaro-kde-21.2.6-220416-linux515.iso`
Bernhard Beschow (7):
hw/acpi/acpi_dev_interface: Remove unused parameter from
AcpiDeviceIfClass::madt_cpu
hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu hw/acpi/acpi_dev_interface: Remove now unused #include "hw/boards.h" hw/acpi/piix4: No need to #include "hw/southbridge/piix.h" hw/i386/acpi-build: Remove unused attributes hw/isa/isa-bus: Turn isa_build_aml() into qbus_build_aml() piix3, ich9: Reuse qbus_build_aml()
hw/acpi/hmat.h | 3 ++- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_aml_interface.h | 3 +++ include/hw/acpi/acpi_dev_interface.h | 4 ---- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 6 ------ include/hw/isa/isa.h | 1 - hw/acpi/acpi-x86-stub.c | 7 ------- hw/acpi/acpi_interface.c | 10 ++++++++++ hw/acpi/cpu.c | 12 +++++------- hw/acpi/hmat.c | 1 + hw/acpi/memory_hotplug.c | 1 + hw/acpi/piix4.c | 3 --- hw/i2c/smbus_ich9.c | 5 +---- hw/i386/acpi-build.c | 7 ++----- hw/i386/acpi-common.c | 10 ++++------ hw/i386/acpi-microvm.c | 6 +++--- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/isa-bus.c | 10 ---------- hw/isa/lpc_ich9.c | 6 +----- hw/isa/piix3.c | 5 +---- monitor/qmp-cmds.c | 1 + 22 files changed, 45 insertions(+), 78 deletions(-)
Signature · 1 line
2.39.0
PATCH v3 1/7 hw/acpi/acpi_dev_interface: Remove unused parameter from AcpiDeviceIfClass::madt_cpu
The only function ever assigned to AcpiDeviceIfClass::madt_cpu is pc_madt_cpu_entry() which doesn't use the AcpiDeviceIf parameter.
--- include/hw/acpi/acpi_dev_interface.h | 3 +-- include/hw/i386/pc.h | 6 ++---- hw/acpi/acpi-x86-stub.c | 5 ++--- hw/acpi/cpu.c | 3 +-- hw/i386/acpi-common.c | 7 +++---- 5 files changed, 9 insertions(+), 15 deletions(-)
include/hw/acpi/acpi_dev_interface.h +1 -2
@@ -52,8 +52,7 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list);void (*send_event)(AcpiDeviceIf *adev,AcpiEventStatusBits ev); -void (*madt_cpu)(AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, +void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, bool force_enabled); };#endif
include/hw/i386/pc.h +2 -4
@@ -9,7 +9,6 @@#include "hw/block/flash.h" #include "hw/i386/x86.h" -#include "hw/acpi/acpi_dev_interface.h" #include "hw/hotplug.h" #include "qom/object.h" #include "hw/i386/sgx-epc.h"
@@ -193,9 +192,8 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data,void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size);/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, -bool force_enabled); +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled);/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);
hw/acpi/acpi-x86-stub.c +2 -3
@@ -2,9 +2,8 @@#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, -bool force_enabled) +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled) { }
hw/acpi/cpu.c +1 -2
@@ -355,7 +355,6 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root);Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL );AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); -AcpiDeviceIf *adev =ACPI_DEVICE_IF (obj); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {
@@ -666,7 +665,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,/* build _MAT object */ assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (adev, i, arch_ids, madt_buf, + adevc->madt_cpu (i, arch_ids, madt_buf, true);/* set enabled flag */ aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));
hw/i386/acpi-common.c +3 -4
@@ -33,9 +33,8 @@#include "acpi-build.h" #include "acpi-common.h" -void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, -bool force_enabled) +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled) {uint32_t apic_id = apic_ids->cpus[uid].arch_id;/* Flags – Local APIC Flags */
@@ -112,7 +111,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (adev, i, apic_ids, table_data, false); + adevc->madt_cpu (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }
Signature · 1 line
2.39.0
Re: [PATCH v3 1/7] hw/acpi/acpi_dev_interface: Remove unused parameter from AcpiDeviceIfClass::madt_cpu
Quoted 4 lines · On Mon, 16 Jan 2023 16:29:02 +0100 Bernhard Beschow <[email protected]> wrote:
The only function ever assigned to
AcpiDeviceIfClass::madt_cpuispc_madt_cpu_entry()which doesn't use the AcpiDeviceIf parameter.Signed-off-by Bernhard Beschow <[email protected]>
Quoted 108 lines
--- include/hw/acpi/acpi_dev_interface.h | 3 +-- include/hw/i386/pc.h | 6 ++---- hw/acpi/acpi-x86-stub.c | 5 ++--- hw/acpi/cpu.c | 3 +-- hw/i386/acpi-common.c | 7 +++---- 5 files changed, 9 insertions(+), 15 deletions(-)include/hw/acpi/acpi_dev_interface.h +1
-2@@ -52,8 +52,7 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list);void (*send_event)(AcpiDeviceIf *adev,AcpiEventStatusBits ev); -void (*madt_cpu)(AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, +void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, bool force_enabled); };#endif include/hw/i386/pc.h +2
-4@@ -9,7 +9,6 @@#include "hw/block/flash.h" #include "hw/i386/x86.h" -#include "hw/acpi/acpi_dev_interface.h" #include "hw/hotplug.h" #include "qom/object.h" #include "hw/i386/sgx-epc.h" @@ -193,9 +192,8 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data,void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size);/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, -bool force_enabled); +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled);/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +2
-3@@ -2,9 +2,8 @@#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, -bool force_enabled) +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled) { }hw/acpi/cpu.c +1
-2@@ -355,7 +355,6 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root);Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL );AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); -AcpiDeviceIf *adev =ACPI_DEVICE_IF (obj); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -666,7 +665,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,/* build _MAT object */ assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (adev, i, arch_ids, madt_buf, + adevc->madt_cpu (i, arch_ids, madt_buf, true);/* set enabled flag */ aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));hw/i386/acpi-common.c +3
-4@@ -33,9 +33,8 @@#include "acpi-build.h" #include "acpi-common.h" -void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, -const CPUArchIdList *apic_ids,GArray *entry, -bool force_enabled) +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled) {uint32_t apic_id = apic_ids->cpus[uid].arch_id;/* Flags – Local APIC Flags */ @@ -112,7 +111,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (adev, i, apic_ids, table_data, false); + adevc->madt_cpu (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }
PATCH v3 2/7 hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
In reply to Bernhard BeschowThis class attribute was always set to pc_madt_cpu_entry(). pc_madt_cpu_entry() is architecture dependent and was assigned to the attribute even in architecture agnostic code such as in hw/acpi/piix4.c and hw/isa/lpc_ich9. Not having to set madt_cpu there resolves the assumption that these device models are only ever used with ACPI on x86 targets.
The only target independent location where madt_cpu was called was hw/ acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was in x86-specific code where pc_madt_cpu_entry() can be used directly.
While at it, move pc_madt_cpu_entry() from the public include/hw/i386/ pc.h to the private hw/i386/acpi-common where it is also implemented.
--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)
hw/i386/acpi-common.h +5 -2
@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" /* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids,GArray *entry, +bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id);#endif
include/hw/acpi/acpi_dev_interface.h +0 -2
@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); -void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, - bool force_enabled); };#endif
include/hw/acpi/cpu.h +5 -1
@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {
@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn )(int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled); +void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method);
include/hw/i386/pc.h +0 -4
@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len);void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size); -/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);
hw/acpi/acpi-x86-stub.c +0 -6
@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Object *acpi_get_i386_pci_host (void ) {return NULL ;
hw/acpi/cpu.c +4 -6
@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method) {
@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,MachineClass *mc =MACHINE_GET_CLASS (machine);const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine);char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root); -Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL ); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {
@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */ );aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));g_array_free (madt_buf, true);
hw/acpi/piix4.c +0 -2
@@ -20,7 +20,6 @@*/ #include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h"
@@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }static const TypeInfo piix4_pm_info = {
hw/i386/acpi-build.c +2 -3
@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry,"\\_SB.PCI0" ,"\\_GPE._E02" ); }if (pcms->memhp_io_base && nr_mem) {
@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker, x86ms, -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {
hw/i386/acpi-common.c +2 -3
@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms);const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (MACHINE (x86ms)); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };
@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }
hw/i386/acpi-microvm.c +1 -2
@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables *tables,acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker,X86_MACHINE (machine), -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {
hw/i386/generic_event_device_x86.c +0 -9
@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init (ObjectClass *class,void *data) -{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init, .interfaces = (InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },
hw/isa/lpc_ich9.c +0 -1
@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Signature · 1 line
2.39.0
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
Quoted 7 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned to the attribute even in architecture agnostic code such as inhw/acpi/piix4.cand hw/isa/lpc_ich9. Not having to setmadt_cputhere resolves the assumption that these device models are only ever used with ACPI on x86 targets.
Quoted 7 lines
The only target independent location where
madt_cpuwas called was hw/acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was in x86-specific code wherepc_madt_cpu_entry()can be used directly.While at it, move
pc_madt_cpu_entry()from the publicinclude/hw/i386/pc.hto the private hw/i386/acpi-common where it is also implemented.
I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).
So I'd prefer to keep AcpiDeviceIfClass::madt_cpu.
What's the end goal you are trying to achieve by getting rid of this callback?
Quoted 267 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +5
-2@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" /* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids,GArray *entry, +bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id);#endif include/hw/acpi/acpi_dev_interface.h +0
-2@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); -void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, - bool force_enabled); };#endif include/hw/acpi/cpu.h +5
-1@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn )(int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled); +void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method);include/hw/i386/pc.h +0
-4@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len);void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size); -/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-6@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +4
-6@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,MachineClass *mc =MACHINE_GET_CLASS (machine);const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine);char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root); -Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL ); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */ );aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-2@@ -20,7 +20,6 @@*/ #include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +2
-3@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry,"\\_SB.PCI0" ,"\\_GPE._E02" ); }if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker, x86ms, -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +2
-3@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms);const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (MACHINE (x86ms)); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +1
-2@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables *tables,acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker,X86_MACHINE (machine), -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/generic_event_device_x86.c +0
-9@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init (ObjectClass *class,void *data) -{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init, .interfaces = (InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-1@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
Am 16. Januar 2023 16:29:30 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 15 lines
Quoted 12 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned to the attribute even in architecture agnostic code such as inhw/acpi/piix4.cand hw/isa/lpc_ich9. Not having to setmadt_cputhere resolves the assumption that these device models are only ever used with ACPI on x86 targets.The only target independent location where
madt_cpuwas called was hw/acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was in x86-specific code wherepc_madt_cpu_entry()can be used directly.
Quoted 7 lines
Quoted 2 lines
While at it, move
pc_madt_cpu_entry()from the publicinclude/hw/i386/pc.hto the private hw/i386/acpi-common where it is also implemented.I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).
IIUC one would call the target-independent build_cpus_aml() from the ARM-specific build_madt(). There, one could pass a function pointer to an ARM-specific madt_cpu_fn. Shouldn't that get us covered?
Quoted 5 lines
So I'd prefer to keep
AcpiDeviceIfClass::madt_cpu.What's the end goal you are trying to achieve by getting rid of this callback?
ACPI controllers are in principle not x86-specific, yet our PIIX4 and ICH9 device models always assign an x86-specific function to AcpiDeviceIfClass::madt_cpu. That doesn't seem right because the device models make assumptions about their usage contexts which they ideally shouldn't.
In addition, it seems to me that ACPI controllers and AML generation should not be mixed: An ACPI controller deals with (hardware) events while AML generation is usually a BIOS task to inject code into an OS. Therefore, ACPI controllers don't seem to be the right place to assign AML-generating functions because that doesn't match how reality works.
To solve both issues, one could factor out e.g. an AmlDeviceIf from AcpiDeviceIf, so one would't force the device models to provide an madt_cpu. Then one could assign a target-specific AmlDeviceIfClass::madt_cpu e.g. in board code. At the moment I don't see a need for a new interface, however, since the function pointer works just fine: It frees the device models from having to provide it and it is used in code which already deals with AML generation.
My end goal is to make the VT82xx south bridges compatible with x86 and to bring them to feature parity with PIIX. For this, I need to implement the VIA ACPI controller proper, and since these south bridges are currently only used in MIPS and PowerPC contexts I'm feeling a bit uncomfortable having to drag in x86 assumptions into these devices.
Best regards,
Bernhard
Quoted 269 lines
Quoted 268 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +5
-2@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" /* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids,GArray *entry, +bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id);#endif include/hw/acpi/acpi_dev_interface.h +0
-2@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); -void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, - bool force_enabled); };#endif include/hw/acpi/cpu.h +5
-1@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn )(int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled); +void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method);include/hw/i386/pc.h +0
-4@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len);void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size); -/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-6@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +4
-6@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,MachineClass *mc =MACHINE_GET_CLASS (machine);const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine);char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root); -Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL ); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */ );aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-2@@ -20,7 +20,6 @@*/ #include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +2
-3@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry,"\\_SB.PCI0" ,"\\_GPE._E02" ); }if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker, x86ms, -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +2
-3@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms);const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (MACHINE (x86ms)); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +1
-2@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables *tables,acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker,X86_MACHINE (machine), -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/generic_event_device_x86.c +0
-9@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init (ObjectClass *class,void *data) -{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init, .interfaces = (InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-1@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
Quoted 50 lines · Bernhard Beschow
Am 16. Januar 2023 16:29:30 UTC schrieb Igor Mammedov <[email protected]
Quoted 14 lines
:
Quoted 10 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned to the attribute even in architecture agnostic code such as inhw/acpi/piix4.cand hw/isa/lpc_ich9. Not having to setmadt_cputhere resolves the assumption that these device models are only ever used with ACPI on x86 targets.The only target independent location where
madt_cpuwas called was hw/acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was in x86-specificcode
Quoted 9 lines
Quoted 4 lines
where
pc_madt_cpu_entry()can be used directly.While at it, move
pc_madt_cpu_entry()from the publicinclude/hw/i386/pc.hto the private hw/i386/acpi-common where it is also implemented.I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).IIUC one would call the target-independent
build_cpus_aml()from the ARM-specificbuild_madt(). There, one could pass a function pointer to an ARM-specificmadt_cpu_fn. Shouldn't that get us covered?Quoted 5 lines
So I'd prefer to keep
AcpiDeviceIfClass::madt_cpu.What's the end goal you are trying to achieve by getting rid of this callback?
ACPI controllers are in principle not x86-specific, yet our PIIX4 and ICH9 device models always assign an x86-specific function to
AcpiDeviceIfClass::madt_cpu. That doesn't seem right because the device models make assumptions about their usage contexts which they ideally shouldn't.In addition, it seems to me that ACPI controllers and AML generation should not be mixed: An ACPI controller deals with (hardware) events while AML generation is usually a BIOS task to inject code into an OS. Therefore, ACPI controllers don't seem to be the right place to assign AML-generating functions because that doesn't match how reality works.
Quoted 8 lines
To solve both issues, one could factor out e.g. an AmlDeviceIf from AcpiDeviceIf, so one would't force the device models to provide an
madt_cpu. Then one could assign a target-specificAmlDeviceIfClass::madt_cpue.g. in board code. At the moment I don't see a need for a new interface, however, since the function pointer works just
fine: It frees the device models from having to provide it and it is used in code which already deals with AML generation.
Well, yeah, this interface already exists as AcpiDevAmlIf which I even touched in the last part of this series... CPUs could possibly implement it though this needs a lot more thought. But, as mentioned above, I don't see a big urge to do this at the moment.
Best regards,
Bernhard
Quoted 300 lines
My end goal is to make the VT82xx south bridges compatible with x86 and to bring them to feature parity with PIIX. For this, I need to implement the VIA ACPI controller proper, and since these south bridges are currently only used in MIPS and PowerPC contexts I'm feeling a bit uncomfortable having to drag in x86 assumptions into these devices.
Best regards,
BernhardQuoted 30 lines
Quoted 30 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +1
-1@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" Quoted 4 lines
hw/i386/acpi-common.h
Quoted 4 lines
hw/i386/acpi-common.h +1
-0/* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids, GArray*entry,
Quoted 9 lines
Review
Quoted 9 lines
hw/i386/acpi-common.h +3
-1+ bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id);#endif (quoted diff) +0
-0
b/include/hw/acpi/acpi_dev_interface.hQuoted 8 lines
include/hw/acpi/acpi_dev_interface.h struct AcpiDeviceIfClass { · line 55
Quoted 8 lines
index
a1648220ff..ca92928124100644include/hw/acpi/acpi_dev_interface.h +0
-1@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list);void (*send_event)(AcpiDeviceIf *adev,AcpiEventStatusBits ev); - void (*madt_cpu)(int uid, const CPUArchIdList *apic_ids, GArray*entry,
Quoted 19 lines
Quoted 19 lines
include/hw/acpi/acpi_dev_interface.h +0
-1- bool force_enabled); };#endif include/hw/acpi/cpu.h +1
-0@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures;Quoted 4 lines
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures {
Quoted 4 lines
include/hw/acpi/cpu.h +3
-0+typedef void (*madt_cpu_fn )(int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled); + void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
Quoted 10 lines
include/hw/i386/pc.h bool pc_system_ovmf_table_find(const char *entry,
Quoted 10 lines
include/hw/acpi/cpu.h +1
-1-hwaddr io_base, + hwaddr io_base, madt_cpu_fn madt_cpu, const char *res_root, const char *event_handler_method);include/hw/i386/pc.h +0
-0@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char *entry,
uint8_t**data,Quoted 34 lines
Quoted 34 lines
include/hw/i386/pc.h +0
-4int *data_len);void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size); -/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-6@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +0
-0@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"Quoted 1 line
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug = { · line 340
Quoted 1 line
hw/acpi/cpu.c +0
-0void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
Quoted 6 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 6 lines
hw/acpi/cpu.c +1
-1-hwaddr io_base, + hwaddr io_base, madt_cpu_fn madt_cpu, const char *res_root, const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 3 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 3 lines
hw/acpi/cpu.c +0
-0MachineClass *mc =MACHINE_GET_CLASS (machine);const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine); char *cphp_res_path = g_strdup_printf("%s." CPUHP_RES_DEVICE,
res_root);Quoted 1 line
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 356
Quoted 1 line
hw/acpi/cpu.c +0
-1- Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF,NULL);
Quoted 7 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 7 lines
hw/acpi/cpu.c +2
-1-AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 7 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 7 lines
hw/acpi/cpu.c +1
-3aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */);
Quoted 10 lines
Quoted 10 lines
hw/acpi/cpu.c +0
-0aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-0@@ -20,7 +20,6 @@*/ Quoted 6 lines
hw/acpi/piix4.c static void piix4_pm_class_init(ObjectClass *klass,
Quoted 6 lines
hw/acpi/piix4.c +0
-1#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass *klass,void *data)
Quoted 19 lines
Quoted 19 lines
hw/acpi/piix4.c +0
-1hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +1
-1@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry,"\\_SB.PCI0" ,"\\_GPE._E02" ); }Quoted 2 lines
hw/i386/acpi-build.c void acpi_build(AcpiBuildTables *tables,
Quoted 2 lines
hw/i386/acpi-build.c +0
-0if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables,MachineState *machine)
Quoted 7 lines
Quoted 7 lines
hw/i386/acpi-build.c +1
-2acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker, x86ms, -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);Quoted 7 lines
hw/i386/acpi-common.c build_xrupt_override(GArray *entry, uint8_t src,
Quoted 7 lines
hw/i386/acpi-build.c +0
-0#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +0
-0@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_t src,
uint32_tgsi,uint16_tflags)Quoted 11 lines
hw/i386/acpi-common.c build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)
Quoted 11 lines
hw/i386/acpi-common.c +1
-1* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms); const CPUArchIdList *apic_ids =mc->possible_cpu_arch_ids(MACHINE(x86ms));
Quoted 5 lines
hw/i386/acpi-common.c void acpi_build_madt(GArray *table_data, BIOSLinker
Quoted 5 lines
hw/i386/acpi-common.c +0
-1-AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker*linker,
Quoted 1 line
hw/i386/acpi-common.c void acpi_build_madt(GArray *table_data, BIOSLinker · line 110
Quoted 1 line
hw/i386/acpi-common.c +0
-0build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */
Quoted 12 lines
hw/i386/acpi-microvm.c static void acpi_build_microvm(AcpiBuildTables
Quoted 12 lines
hw/i386/acpi-common.c +1
-1for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +0
-0@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables*tables,
Quoted 10 lines
Review
Quoted 10 lines
hw/i386/acpi-microvm.c +1
-2acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker,X86_MACHINE (machine), -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {(quoted diff) +0
-0
b/hw/i386/generic_event_device_x86.cQuoted 16 lines
Quoted 16 lines
index
e26fb02a2e..8fc233e1f1100644hw/i386/generic_event_device_x86.c +0
-8@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init (ObjectClass *class,void *data) -{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}Quoted 12 lines
hw/isa/lpc_ich9.c static void ich9_lpc_class_init(ObjectClass *klass,
Quoted 12 lines
hw/i386/generic_event_device_x86.c +0
-1static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init, .interfaces = (InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-0@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass *klass,void *data)
Quoted 8 lines
Quoted 7 lines
hw/isa/lpc_ich9.c +0
-1hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
In reply to Bernhard BeschowQuoted 19 lines · On Tue, 17 Jan 2023 00:30:23 +0000 Bernhard Beschow <[email protected]> wrote:
Am 16. Januar 2023 16:29:30 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 18 lines
Quoted 14 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned to the attribute even in architecture agnostic code such as inhw/acpi/piix4.cand hw/isa/lpc_ich9. Not having to setmadt_cputhere resolves the assumption that these device models are only ever used with ACPI on x86 targets.The only target independent location where
madt_cpuwas called was hw/acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was in x86-specific code wherepc_madt_cpu_entry()can be used directly.While at it, move
pc_madt_cpu_entry()from the publicinclude/hw/i386/pc.hto the private hw/i386/acpi-common where it is also implemented.
Quoted 6 lines
Quoted 4 lines
I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).IIUC one would call the target-independent
build_cpus_aml()from the ARM-specificbuild_madt(). There, one could pass a function pointer to an ARM-specificmadt_cpu_fn. Shouldn't that get us covered?
it will work in this case, but I don't like going back to random function pointer argument approach instead of using QOM and interfaces which is much better in describing expectations/contract for interfaces adn objects it's attached to.
Howver that is not the reason why I'm against this approach, see bellow.
Quoted 8 lines
Quoted 4 lines
So I'd prefer to keep
AcpiDeviceIfClass::madt_cpu.What's the end goal you are trying to achieve by getting rid of this callback?
ACPI controllers are in principle not x86-specific, yet our PIIX4 and ICH9 device models always assign an x86-specific function to
AcpiDeviceIfClass::madt_cpu. That doesn't seem right because the device models make assumptions about their usage contexts which they ideally shouldn't.In addition, it seems to me that ACPI controllers and AML generation should not be mixed: An ACPI controller deals with (hardware) events while AML generation is usually a BIOS task to inject code into an OS. Therefore, ACPI controllers don't seem to be the right place to assign AML-generating functions because that doesn't match how reality works.
It would be nice to have pristine hardware-only device models
and firmware composing ACPI tables like baremetal systems do (they have a luxury of fixed hardware which makes it way simpler), however it was not practical nor sustainable in mainstream virt case. That's the reason why ACPI tables (firmware) were moved into QEMU (hardware).
Quoted 2 lines
To solve both issues, one could factor out e.g. an AmlDeviceIf from AcpiDeviceIf, so one would't force the device models to provide an
madt_cpu. Then one could assign a target-specificAmlDeviceIfClass::madt_cpue.g. in board code.
ACPI tables in QEMU started this way, It stopped being maintainable at certain point, see below for more.
Quoted 1 line
At the moment I don't see a need for a new interface, however, since the function pointer works just fine: It frees the device models from having to provide it and it is used in code which already deals with AML generation.
When the move happened, the bulk of ACPI code was as you suggest made as machine specific and it's still the case for the most of it. Then, with ease of adding new related features, it exploded into I would say hard to maintain mess. Hence before adding more and making it worse, I introduced call_dev_aml_func()/AcpiDevAmlIf and started refactoring PCI AML code. That simplified main PCI bus enumeration quite a bit.
The new interface however does exactly opposite of what you are doing, i.e. it pushes device specific AML generation into corresponding device model. It's not ideal as we have to provide stubs for targets where it's not needed. But stubs for target independent code is typical and proven approach we use in QEMU for such cases and is relatively easy to maintain. So I'd call it a reasonable compromise.
Recently posted series (that untangles generic PCI slots AML from ACPI PCI hotplug frankenstein) continues with AcpiDevAmlIf approach and pushes more AML into target in-depended device models.
And there is more coming on top of it (with the goal to make most of what we accumulated in PC/Q35 PCI ACPI code become generic enough to replace most of PCI related AML elsewhere (microvm, arm/virt, whatever else that is interested in ACPI tables support). My ambition with this refactoring stops at making qdev device tree self-describable at PCI boundary but AcpiDevAmlIf can be applied to other devices described in DSDT, that hang off the board.
Quoted 1 line
My end goal is to make the VT82xx south bridges compatible with x86 and to bring them to feature parity with PIIX. For this, I need to implement the VIA ACPI controller proper, and since these south bridges are currently only used in MIPS and PowerPC contexts I'm feeling a bit uncomfortable having to drag in x86 assumptions into these devices.
basic ACPI hardware (GPE/PM registers) code is relatively isolated, so you probably can implement that without touching piix much. (with little to no stubs).
If you want to cleanup piix and free other targets from unfortunate ACPI/x86 specific dependencies, it would probably need another approach than presented here.
ex:
Isolating core(pristine) piix code in piix-basic class for PPC/MIPS use, and then branching/inheriting of it current piix class with all extra x86 'features' might work without breaking migration. (/me assuming cross version migration should work in this arrangement, though I won't bet on it)
Quoted 273 lines
Best regards,
BernhardQuoted 269 lines
Quoted 268 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +5
-2@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" /* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids,GArray *entry, +bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id);#endif include/hw/acpi/acpi_dev_interface.h +0
-2@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); -void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, - bool force_enabled); };#endif include/hw/acpi/cpu.h +5
-1@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn )(int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled); +void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method);include/hw/i386/pc.h +0
-4@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len);void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size); -/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-6@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +4
-6@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,MachineClass *mc =MACHINE_GET_CLASS (machine);const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine);char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root); -Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL ); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */ );aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-2@@ -20,7 +20,6 @@*/ #include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +2
-3@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry,"\\_SB.PCI0" ,"\\_GPE._E02" ); }if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker, x86ms, -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +2
-3@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms);const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (MACHINE (x86ms)); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +1
-2@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables *tables,acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker,X86_MACHINE (machine), -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/generic_event_device_x86.c +0
-9@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init (ObjectClass *class,void *data) -{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init, .interfaces = (InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-1@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
Am 18. Januar 2023 14:59:05 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 72 lines
Quoted 19 lines · On Tue, 17 Jan 2023 00:30:23 +0000 Bernhard Beschow <[email protected]> wrote:
Am 16. Januar 2023 16:29:30 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 18 lines
Quoted 14 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned to the attribute even in architecture agnostic code such as inhw/acpi/piix4.cand hw/isa/lpc_ich9. Not having to setmadt_cputhere resolves the assumption that these device models are only ever used with ACPI on x86 targets.The only target independent location where
madt_cpuwas called was hw/acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was in x86-specific code wherepc_madt_cpu_entry()can be used directly.While at it, move
pc_madt_cpu_entry()from the publicinclude/hw/i386/pc.hto the private hw/i386/acpi-common where it is also implemented.Quoted 6 lines
Quoted 4 lines
I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).IIUC one would call the target-independent
build_cpus_aml()from the ARM-specificbuild_madt(). There, one could pass a function pointer to an ARM-specificmadt_cpu_fn. Shouldn't that get us covered?it will work in this case, but I don't like going back to random function pointer argument approach instead of using QOM and interfaces which is much better in describing expectations/contract for interfaces adn objects it's attached to.
Howver that is not the reason why I'm against this approach, see bellow.
Quoted 8 lines
Quoted 4 lines
So I'd prefer to keep
AcpiDeviceIfClass::madt_cpu.What's the end goal you are trying to achieve by getting rid of this callback?
ACPI controllers are in principle not x86-specific, yet our PIIX4 and ICH9 device models always assign an x86-specific function to
AcpiDeviceIfClass::madt_cpu. That doesn't seem right because the device models make assumptions about their usage contexts which they ideally shouldn't.In addition, it seems to me that ACPI controllers and AML generation should not be mixed: An ACPI controller deals with (hardware) events while AML generation is usually a BIOS task to inject code into an OS. Therefore, ACPI controllers don't seem to be the right place to assign AML-generating functions because that doesn't match how reality works.
It would be nice to have pristine hardware-only device models
and firmware composing ACPI tables like baremetal systems do (they have a luxury of fixed hardware which makes it way simpler), however it was not practical nor sustainable in mainstream virt case. That's the reason why ACPI tables (firmware) were moved into QEMU (hardware).Quoted 2 lines
To solve both issues, one could factor out e.g. an AmlDeviceIf from AcpiDeviceIf, so one would't force the device models to provide an
madt_cpu. Then one could assign a target-specificAmlDeviceIfClass::madt_cpue.g. in board code.ACPI tables in QEMU started this way, It stopped being maintainable at certain point, see below for more.
Quoted 1 line
At the moment I don't see a need for a new interface, however, since the function pointer works just fine: It frees the device models from having to provide it and it is used in code which already deals with AML generation.
When the move happened, the bulk of ACPI code was as you suggest made as machine specific and it's still the case for the most of it. Then, with ease of adding new related features, it exploded into I would say hard to maintain mess. Hence before adding more and making it worse, I introduced call_dev_aml_func()/AcpiDevAmlIf and started refactoring PCI AML code. That simplified main PCI bus enumeration quite a bit.
The new interface however does exactly opposite of what you are doing, i.e. it pushes device specific AML generation into corresponding device model. It's not ideal as we have to provide stubs for targets where it's not needed. But stubs for target independent code is typical and proven approach we use in QEMU for such cases and is relatively easy to maintain. So I'd call it a reasonable compromise.
Quoted 3 lines
Recently posted series (that untangles generic PCI slots AML from ACPI PCI hotplug frankenstein) continues with AcpiDevAmlIf approach and pushes more AML into target in-depended device models.
I fully agree with the introduction of AcpiDevAmlIf. In fact I was following your work closely since it helped me making the VT82xx south bridges work with the PC machine. In order to make your approach even more elegant and efficient I'm following up with qbus_build_aml().
This patch doesn't actually question the AcpiDevAmlIf. It rather questions the mixing of CPU-related AML concerns into the ACPI controllers which are a priori CPU-agnostic. The only reason for dragging x86 concerns into these device models is that the AcpiDeviceIfClass requires madt_cpu to be assigned. Here we can apply the "interface segregation principle" which is why I proposed factoring out a dedicated interface from the AcpiDeviceIfClass (and possibly have CPUs implement it). I think that this would match your approach with AcpiDevAmlIf.
Quoted 7 lines
And there is more coming on top of it (with the goal to make most of what we accumulated in PC/Q35 PCI ACPI code become generic enough to replace most of PCI related AML elsewhere (microvm, arm/virt, whatever else that is interested in ACPI tables support). My ambition with this refactoring stops at making qdev device tree self-describable at PCI boundary but AcpiDevAmlIf can be applied to other devices described in DSDT, that hang off the board.
Sounds good!
Quoted 10 lines
Quoted 1 line
My end goal is to make the VT82xx south bridges compatible with x86 and to bring them to feature parity with PIIX. For this, I need to implement the VIA ACPI controller proper, and since these south bridges are currently only used in MIPS and PowerPC contexts I'm feeling a bit uncomfortable having to drag in x86 assumptions into these devices.
basic ACPI hardware (GPE/PM registers) code is relatively isolated, so you probably can implement that without touching piix much. (with little to no stubs).
If you want to cleanup piix and free other targets from unfortunate ACPI/x86 specific dependencies, it would probably need another approach than presented here.
Quoted 7 lines
ex:
Isolating core(pristine) piix code in piix-basic class for PPC/MIPS use, and then branching/inheriting of it current piix class with all extra x86 'features' might work without breaking migration. (/me assuming cross version migration should work in this arrangement, though I won't bet on it)
It seems to me that extending the PIIX4 PM class hierarchy with piix-basic is just a workaround for the root problem I mentioned above, which is the mixing of unrelated concerns into one interface. So let my try to factor out an AcpiCpuAmlIf from AcpiDeviceIfClass and see how it goes.
Best regards,
Bernhard
Quoted 275 lines
Quoted 274 lines
Best regards,
BernhardQuoted 269 lines
Quoted 268 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +5
-2@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" /* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids,GArray *entry, +bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id);#endif include/hw/acpi/acpi_dev_interface.h +0
-2@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); -void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, - bool force_enabled); };#endif include/hw/acpi/cpu.h +5
-1@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn )(int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled); +void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method);include/hw/i386/pc.h +0
-4@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len);void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size); -/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-6@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +4
-6@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,MachineClass *mc =MACHINE_GET_CLASS (machine);const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine);char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root); -Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL ); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */ );aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-2@@ -20,7 +20,6 @@*/ #include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +2
-3@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry,"\\_SB.PCI0" ,"\\_GPE._E02" ); }if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker, x86ms, -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +2
-3@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms);const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (MACHINE (x86ms)); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +1
-2@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables *tables,acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker,X86_MACHINE (machine), -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/generic_event_device_x86.c +0
-9@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init (ObjectClass *class,void *data) -{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init, .interfaces = (InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-1@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
Quoted 73 lines · On Thu, 19 Jan 2023 14:47:41 +0000 Bernhard Beschow <[email protected]> wrote:
Am 18. Januar 2023 14:59:05 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 72 lines
Quoted 19 lines · On Tue, 17 Jan 2023 00:30:23 +0000 Bernhard Beschow <[email protected]> wrote:
Am 16. Januar 2023 16:29:30 UTC schrieb Igor Mammedov <[email protected]>:
Quoted 18 lines
Quoted 14 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned to the attribute even in architecture agnostic code such as inhw/acpi/piix4.cand hw/isa/lpc_ich9. Not having to setmadt_cputhere resolves the assumption that these device models are only ever used with ACPI on x86 targets.The only target independent location where
madt_cpuwas called was hw/acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was in x86-specific code wherepc_madt_cpu_entry()can be used directly.While at it, move
pc_madt_cpu_entry()from the publicinclude/hw/i386/pc.hto the private hw/i386/acpi-common where it is also implemented.Quoted 6 lines
Quoted 4 lines
I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).IIUC one would call the target-independent
build_cpus_aml()from the ARM-specificbuild_madt(). There, one could pass a function pointer to an ARM-specificmadt_cpu_fn. Shouldn't that get us covered?it will work in this case, but I don't like going back to random function pointer argument approach instead of using QOM and interfaces which is much better in describing expectations/contract for interfaces adn objects it's attached to.
Howver that is not the reason why I'm against this approach, see bellow.
Quoted 8 lines
Quoted 4 lines
So I'd prefer to keep
AcpiDeviceIfClass::madt_cpu.What's the end goal you are trying to achieve by getting rid of this callback?
ACPI controllers are in principle not x86-specific, yet our PIIX4 and ICH9 device models always assign an x86-specific function to
AcpiDeviceIfClass::madt_cpu. That doesn't seem right because the device models make assumptions about their usage contexts which they ideally shouldn't.In addition, it seems to me that ACPI controllers and AML generation should not be mixed: An ACPI controller deals with (hardware) events while AML generation is usually a BIOS task to inject code into an OS. Therefore, ACPI controllers don't seem to be the right place to assign AML-generating functions because that doesn't match how reality works.
It would be nice to have pristine hardware-only device models
and firmware composing ACPI tables like baremetal systems do (they have a luxury of fixed hardware which makes it way simpler), however it was not practical nor sustainable in mainstream virt case. That's the reason why ACPI tables (firmware) were moved into QEMU (hardware).Quoted 2 lines
To solve both issues, one could factor out e.g. an AmlDeviceIf from AcpiDeviceIf, so one would't force the device models to provide an
madt_cpu. Then one could assign a target-specificAmlDeviceIfClass::madt_cpue.g. in board code.ACPI tables in QEMU started this way, It stopped being maintainable at certain point, see below for more.
Quoted 1 line
At the moment I don't see a need for a new interface, however, since the function pointer works just fine: It frees the device models from having to provide it and it is used in code which already deals with AML generation.
When the move happened, the bulk of ACPI code was as you suggest made as machine specific and it's still the case for the most of it. Then, with ease of adding new related features, it exploded into I would say hard to maintain mess. Hence before adding more and making it worse, I introduced call_dev_aml_func()/AcpiDevAmlIf and started refactoring PCI AML code. That simplified main PCI bus enumeration quite a bit.
The new interface however does exactly opposite of what you are doing, i.e. it pushes device specific AML generation into corresponding device model. It's not ideal as we have to provide stubs for targets where it's not needed. But stubs for target independent code is typical and proven approach we use in QEMU for such cases and is relatively easy to maintain. So I'd call it a reasonable compromise.
Quoted 5 lines
Quoted 3 lines
Recently posted series (that untangles generic PCI slots AML from ACPI PCI hotplug frankenstein) continues with AcpiDevAmlIf approach and pushes more AML into target in-depended device models.
I fully agree with the introduction of AcpiDevAmlIf. In fact I was following your work closely since it helped me making the VT82xx south bridges work with the PC machine. In order to make your approach even more elegant and efficient I'm following up with
qbus_build_aml().
Reviewed/acked it, thanks for nice cleanuup.
Quoted 1 line
This patch doesn't actually question the AcpiDevAmlIf. It rather questions the mixing of CPU-related AML concerns into the ACPI controllers which are a priori CPU-agnostic. The only reason for dragging x86 concerns into these device models is that the AcpiDeviceIfClass requires
madt_cputo be assigned. Here we can apply the "interface segregation principle" which is why I proposed factoring out a dedicated interface from the AcpiDeviceIfClass (and possibly have CPUs implement it). I think that this would match your approach with AcpiDevAmlIf.
There was and still is a reason for madt_cpu being part of AcpiDeviceIfClass and x86-ed piix impl.
(It might have been a poor choice to use acpi controller as hotplug controller as well but that boat has sailed and can't be fixed without breaking ABI/migration.)
But as it is now, hotplug controller is an owner of CPU hotplug data on which ::madt_cpu relies.
I'd say the same about ::send_event hook which is only used in hotplug case (GPE events do not have predefined meaning)
That only leaves AcpiDeviceIfClass::ospm_status, which in turn implicitly depends on hotplug controller to provide status data.
So question is why do you need AcpiDeviceIfClass for VIA, how much of it and how current impl. gets in the way of your goal?
Quoted 28 lines
Quoted 7 lines
And there is more coming on top of it (with the goal to make most of what we accumulated in PC/Q35 PCI ACPI code become generic enough to replace most of PCI related AML elsewhere (microvm, arm/virt, whatever else that is interested in ACPI tables support). My ambition with this refactoring stops at making qdev device tree self-describable at PCI boundary but AcpiDevAmlIf can be applied to other devices described in DSDT, that hang off the board.
Sounds good!
Quoted 10 lines
Quoted 1 line
My end goal is to make the VT82xx south bridges compatible with x86 and to bring them to feature parity with PIIX. For this, I need to implement the VIA ACPI controller proper, and since these south bridges are currently only used in MIPS and PowerPC contexts I'm feeling a bit uncomfortable having to drag in x86 assumptions into these devices.
basic ACPI hardware (GPE/PM registers) code is relatively isolated, so you probably can implement that without touching piix much. (with little to no stubs).
If you want to cleanup piix and free other targets from unfortunate ACPI/x86 specific dependencies, it would probably need another approach than presented here.
Quoted 7 lines
ex:
Isolating core(pristine) piix code in piix-basic class for PPC/MIPS use, and then branching/inheriting of it current piix class with all extra x86 'features' might work without breaking migration. (/me assuming cross version migration should work in this arrangement, though I won't bet on it)
Quoted 1 line
It seems to me that extending the PIIX4 PM class hierarchy with piix-basic is just a workaround for the root problem I mentioned above, which is the mixing of unrelated concerns into one interface. So let my try to factor out an AcpiCpuAmlIf from AcpiDeviceIfClass and see how it goes.
See above, lets discuss it there.
Quoted 279 lines
Best regards,
BernhardQuoted 275 lines
Quoted 274 lines
Best regards,
BernhardQuoted 269 lines
Quoted 268 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +5
-2@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" /* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids,GArray *entry, +bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id);#endif include/hw/acpi/acpi_dev_interface.h +0
-2@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); -void (*madt_cpu)(int uid,const CPUArchIdList *apic_ids,GArray *entry, - bool force_enabled); };#endif include/hw/acpi/cpu.h +5
-1@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn )(int uid,const CPUArchIdList *apic_ids, +GArray *entry,bool force_enabled); +void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method);include/hw/i386/pc.h +0
-4@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len);void pc_system_parse_ovmf_flash (uint8_t *flash_ptr,size_t flash_size); -/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-6@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +4
-6@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +hwaddr io_base,madt_cpu_fn madt_cpu,const char *res_root,const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,MachineClass *mc =MACHINE_GET_CLASS (machine);const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine);char *cphp_res_path =g_strdup_printf ("%s." CPUHP_RES_DEVICE , res_root); -Object *obj =object_resolve_path_type ("" ,TYPE_ACPI_DEVICE_IF ,NULL ); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */ );aml_append (dev,aml_name_decl ("_MAT" ,aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data)));g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-2@@ -20,7 +20,6 @@*/ #include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +2
-3@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry,"\\_SB.PCI0" ,"\\_GPE._E02" ); }if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker, x86ms, -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +2
-3@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms);const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (MACHINE (x86ms)); -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,build_append_int_noprefix (table_data,1 /* PCAT_COMPAT */ ,4 );/* Flags */ for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +1
-2@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables *tables,acpi_add_table (table_offsets, tables_blob);acpi_build_madt (tables_blob, tables->linker,X86_MACHINE (machine), -ACPI_DEVICE_IF (x86ms->acpi_dev), x86ms->oem_id, - x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/generic_event_device_x86.c +0
-9@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init (ObjectClass *class,void *data) -{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init, .interfaces = (InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-1@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
Quoted 123 lines · Igor Mammedov
Quoted 1 line · On Thu, 19 Jan 2023 14:47:41 +0000 Bernhard Beschow <[email protected]> wrote:
Am 18. Januar 2023 14:59:05 UTC schrieb Igor Mammedov <
Quoted 4 lines
Quoted 4 lines
Quoted 1 line · On Tue, 17 Jan 2023 00:30:23 +0000 Bernhard Beschow <[email protected]> wrote:
Am 16. Januar 2023 16:29:30 UTC schrieb Igor Mammedov <
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned tothe
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
attribute even in architecture agnostic code such as in
hw/acpi/piix4.cQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
and hw/isa/lpc_ich9. Not having to set
madt_cputhere resolves the assumption that these device models are only ever used with ACPIon x86
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
targets.
The only target independent location where
madt_cpuwas called washw/
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was inx86-specific code
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
where
pc_madt_cpu_entry()can be used directly.While at it, move
pc_madt_cpu_entry()from the public
include/hw/i386/Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
pc.hto the private hw/i386/acpi-common where it is alsoimplemented.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).IIUC one would call the target-independent
build_cpus_aml()from theARM-specific
build_madt(). There, one could pass a function pointer to an ARM-specificmadt_cpu_fn. Shouldn't that get us covered?Quoted 6 lines
Quoted 6 lines
it will work in this case, but I don't like going back to random function pointer argument approach instead of using QOM and interfaces which is much better in describing expectations/contract for interfaces adn objects it's attached to.
Quoted 8 lines
Quoted 8 lines
Howver that is not the reason why I'm against this approach, see bellow.
Quoted 6 lines
Quoted 4 lines
So I'd prefer to keep
AcpiDeviceIfClass::madt_cpu.What's the end goal you are trying to achieve by getting rid of this callback?
ACPI controllers are in principle not x86-specific, yet our PIIX4 and
ICH9 device models always assign an x86-specific function to
AcpiDeviceIfClass::madt_cpu. That doesn't seem right because the device models make assumptions about their usage contexts which they ideally shouldn't.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
In addition, it seems to me that ACPI controllers and AML generation
should not be mixed: An ACPI controller deals with (hardware) events while AML generation is usually a BIOS task to inject code into an OS. Therefore, ACPI controllers don't seem to be the right place to assign AML-generating functions because that doesn't match how reality works.
Quoted 6 lines
Quoted 6 lines
It would be nice to have pristine hardware-only device models and firmware composing ACPI tables like baremetal systems do (they have a luxury of fixed hardware which makes it way simpler), however it was not practical nor sustainable in mainstream virt case. That's the reason why ACPI tables (firmware) were moved into QEMU
(hardware).
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
To solve both issues, one could factor out e.g. an AmlDeviceIf from
AcpiDeviceIf, so one would't force the device models to provide an
madt_cpu.Quoted 1 line
Quoted 1 line
Quoted 1 line
Then one could assign a target-specific
AmlDeviceIfClass::madt_cpue.g. in board code.
Quoted 4 lines
Quoted 4 lines
ACPI tables in QEMU started this way, It stopped being maintainable at certain point, see below for more.
Quoted 1 line
At the moment I don't see a need for a new interface, however, since
the function pointer works just fine: It frees the device models from having to provide it and it is used in code which already deals with AML generation.
Quoted 8 lines
Quoted 8 lines
When the move happened, the bulk of ACPI code was as you suggest made as machine specific and it's still the case for the most of it. Then, with ease of adding new related features, it exploded into I would say hard to maintain mess. Hence before adding more and making it worse, I introduced call_dev_aml_func()/AcpiDevAmlIf and started refactoring PCI AML code. That simplified main PCI bus enumeration quite a bit.
Quoted 5 lines
Quoted 5 lines
The new interface however does exactly opposite of what you are doing, i.e. it pushes device specific AML generation into corresponding device model. It's not ideal as we have to provide stubs for targets where it's not needed. But stubs for target independent code is typical and proven approach we use in QEMU for such cases and is relatively easy to
maintain.
Quoted 7 lines
Quoted 5 lines
So I'd call it a reasonable compromise.
Recently posted series (that untangles generic PCI slots AML from ACPI PCI hotplug frankenstein) continues with AcpiDevAmlIf approach and pushes more AML into target in-depended device models.
I fully agree with the introduction of AcpiDevAmlIf. In fact I was
following your work closely since it helped me making the VT82xx south bridges work with the PC machine. In order to make your approach even more elegant and efficient I'm following up with
qbus_build_aml().Reviewed/acked it, thanks for nice cleanuup.
Quoted 1 line
This patch doesn't actually question the AcpiDevAmlIf. It rather
questions the mixing of CPU-related AML concerns into the ACPI controllers which are a priori CPU-agnostic. The only reason for dragging x86 concerns into these device models is that the AcpiDeviceIfClass requires
madt_cputo be assigned. Here we can apply the "interface segregation principle" which is why I proposed factoring out a dedicated interface from the AcpiDeviceIfClass (and possibly have CPUs implement it). I think that this would match your approach with AcpiDevAmlIf.
Quoted 8 lines
There was and still is a reason for
madt_cpubeing part of AcpiDeviceIfClass and x86-ed piix impl.(It might have been a poor choice to use acpi controller as hotplug controller as well
but that boat has sailed and can't be fixed without breaking ABI/migration.)
Could you please elaborate a bit on how the ABI is affected? Migration seems clear to me.
Quoted 4 lines
But as it is now, hotplug controller is an owner of CPU hotplug data on which ::madt_cpu relies.
Could you please also elaborate a bit here on how hotplug and ::madt_cpu are coupled? When generating the AML, one could check if both AcpiDeviceIfClass and ::madt_cpu are available. There is code instantiating TYPE_ACPI_GED in ARM and Loongarch which does not set ::madt_cpu. In order to see what I mean, I've prepared v4 of this series:
https://lore.kernel.org/qemu-devel/[email protected]
I'd say the same about ::send_event hook which is only used in hotplug case
Quoted 6 lines
(GPE events do not have predefined meaning)
That only leavesAcpiDeviceIfClass::ospm_status, which in turn implicitly depends on hotplug controller to provide status data.
So question is why do you need AcpiDeviceIfClass for VIA, how much of it and how current impl. gets in the way of your goal?
I would just like to get feature parity with PIIX. Do you suggest taking a different approach which avoids the hotplug state in the ACPI controller?
Thanks,
Bernhard
Quoted 354 lines
Quoted 9 lines
Quoted 8 lines
And there is more coming on top of it (with the goal to make most of what we accumulated in PC/Q35 PCI ACPI code become generic enough to replace most of PCI related AML elsewhere (microvm, arm/virt, whatever else that is interested in ACPI tables support). My ambition with this refactoring stops at making qdev device tree self-describable at PCI boundary but AcpiDevAmlIf can be applied to other devices described in DSDT, that hang off the board.
Quoted 3 lines
Sounds good!
Quoted 1 line
Quoted 1 line
My end goal is to make the VT82xx south bridges compatible with x86
and to bring them to feature parity with PIIX. For this, I need to implement the VIA ACPI controller proper, and since these south bridges are currently only used in MIPS and PowerPC contexts I'm feeling a bit uncomfortable having to drag in x86 assumptions into these devices.
Quoted 17 lines
Quoted 9 lines
basic ACPI hardware (GPE/PM registers) code is relatively isolated, so you probably can implement that without touching piix much. (with little to no stubs).
If you want to cleanup piix and free other targets from unfortunate ACPI/x86 specific dependencies, it would probably need another approach than presented here.
Quoted 7 lines
ex:
Isolating core(pristine) piix code in piix-basic class for PPC/MIPS use, and then branching/inheriting of it current piix class with all extra x86 'features' might work without breaking migration. (/me assuming cross version migration should work in this arrangement, though I won't bet on it)Quoted 1 line
It seems to me that extending the PIIX4 PM class hierarchy with
piix-basic is just a workaround for the root problem I mentioned above, which is the mixing of unrelated concerns into one interface. So let my try to factor out an AcpiCpuAmlIf from AcpiDeviceIfClass and see how it goes. See above, lets discuss it there.
Quoted 37 lines
Best regards,
BernhardQuoted 34 lines
Quoted 34 lines
Best regards,
BernhardQuoted 30 lines
Quoted 30 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +1
-1@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-common.h
Quoted 4 lines
hw/i386/acpi-common.h +1
-0/* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,GArray *entry,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/i386/acpi-common.h
Quoted 6 lines
hw/i386/acpi-common.h +3
-1+ bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms, const char *oem_id, const char
*oem_table_id);Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
hw/i386/acpi-common.h +0
-0#endif (quoted diff) +0
-0
b/include/hw/acpi/acpi_dev_interface.hQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/hw/acpi/acpi_dev_interface.h struct AcpiDeviceIfClass { · line 53
Quoted 6 lines
index
a1648220ff..ca92928124100644include/hw/acpi/acpi_dev_interface.h +0
-0@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev, ACPIOSTInfoList***list);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h struct AcpiDeviceIfClass { · line 54
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h +0
-0void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBitsev);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h struct AcpiDeviceIfClass { · line 55
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h +0
-1- void (*madt_cpu)(int uid, const CPUArchIdList *apic_ids,GArray *entry,
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
include/hw/acpi/acpi_dev_interface.h +0
-1- bool force_enabled); };#endif include/hw/acpi/cpu.h +1
-0@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures { · line 59
Quoted 6 lines
include/hw/acpi/cpu.h +1
-0typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn)(int uid, const CPUArchIdList
*apic_ids,Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures {
Quoted 3 lines
include/hw/acpi/cpu.h +2
-0+ GArray *entry, bool force_enabled); + void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
include/hw/i386/pc.h bool pc_system_ovmf_table_find(const char
Quoted 10 lines
include/hw/acpi/cpu.h +1
-1-hwaddr io_base, + hwaddr io_base, madt_cpu_fn madt_cpu, const char *res_root, const char *event_handler_method);include/hw/i386/pc.h +0
-0@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char*entry,
uint8_t**data,Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
include/hw/i386/pc.h bool pc_system_ovmf_table_find(const char · line 192
Quoted 2 lines
include/hw/i386/pc.h +0
-0int *data_len); void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t
flash_size);Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
include/hw/i386/pc.h +0
-4-/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-1@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/acpi/acpi-x86-stub.c +0
-5-void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug =
Quoted 8 lines
hw/acpi/acpi-x86-stub.c +0
-0Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +0
-0@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug ={
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug = {
Quoted 3 lines
hw/acpi/cpu.c +0
-0#define CPU_FW_EJECT_EVENT "CEJF" void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 6 lines
hw/acpi/cpu.c +1
-1-hwaddr io_base, + hwaddr io_base, madt_cpu_fn madt_cpu, const char *res_root, const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 354
Quoted 2 lines
hw/acpi/cpu.c +0
-0MachineClass *mc =MACHINE_GET_CLASS (machine); const CPUArchIdList *arch_ids =
mc->possible_cpu_arch_ids(machine);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 355
Quoted 1 line
hw/acpi/cpu.c +0
-0char *cphp_res_path = g_strdup_printf("%s." CPUHP_RES_DEVICE,
res_root);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 356
Quoted 1 line
hw/acpi/cpu.c +0
-1- Object *obj = object_resolve_path_type("",
TYPE_ACPI_DEVICE_IF, NULL);Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 7 lines
hw/acpi/cpu.c +2
-1-AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 7 lines
hw/acpi/cpu.c +1
-3aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 669
Quoted 2 lines
hw/acpi/cpu.c +0
-0aml_append(dev, aml_name_decl("_MAT", aml_buffer(madt_buf->len, (uint8_t*)madt_buf->data)));
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/acpi/cpu.c +0
-0g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-0@@ -20,7 +20,6 @@*/ Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/acpi/piix4.c static void piix4_pm_class_init(ObjectClass
Quoted 6 lines
hw/acpi/piix4.c +0
-1#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass*klass, void *data)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/acpi/piix4.c +0
-1hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/i386/acpi-build.c build_dsdt(GArray *table_data, BIOSLinker
Quoted 6 lines
hw/acpi/piix4.c +0
-0static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +0
-0@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker*linker,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/i386/acpi-build.c build_dsdt(GArray *table_data, BIOSLinker *linker,
Quoted 5 lines
hw/i386/acpi-build.c +1
-1.fw_unplugs_cpu = pm->smi_on_cpu_unplug, }; build_cpus_aml(dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry, "\\_SB.PCI0","\\_GPE._E02");
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-build.c void acpi_build(AcpiBuildTables *tables,
Quoted 4 lines
hw/i386/acpi-build.c +0
-0}if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables,MachineState *machine)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-build.c void acpi_build(AcpiBuildTables *tables, MachineState *machine)
Quoted 4 lines
hw/i386/acpi-build.c +0
-1acpi_add_table (table_offsets, tables_blob); acpi_build_madt(tables_blob, tables->linker, x86ms, - ACPI_DEVICE_IF(x86ms->acpi_dev),
x86ms->oem_id,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/i386/acpi-common.c build_xrupt_override(GArray *entry, uint8_t
Quoted 10 lines
hw/i386/acpi-build.c +1
-1- x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +0
-0@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_tsrc,
uint32_tgsi,uint16_tflags)Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
hw/i386/acpi-common.c build_xrupt_override(GArray *entry, uint8_t src, uint32_t gsi, uint16_t flags)
Quoted 11 lines
hw/i386/acpi-common.c +1
-1* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms); const CPUArchIdList *apic_ids =mc->possible_cpu_arch_ids(MACHINE(x86ms));
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/i386/acpi-common.c void acpi_build_madt(GArray *table_data,
Quoted 5 lines
hw/i386/acpi-common.c +0
-1-AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data,BIOSLinker *linker,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/acpi-common.c void acpi_build_madt(GArray *table_data, · line 110
Quoted 1 line
hw/i386/acpi-common.c +0
-0build_append_int_noprefix(table_data, 1 /* PCAT_COMPAT */,4); /* Flags */
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
hw/i386/acpi-microvm.c static void acpi_build_microvm(AcpiBuildTables
Quoted 12 lines
hw/i386/acpi-common.c +1
-1for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +0
-0@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables*tables,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
hw/i386/acpi-microvm.c static void acpi_build_microvm(AcpiBuildTables · line 214
Quoted 3 lines
hw/i386/acpi-microvm.c +0
-0acpi_add_table (table_offsets, tables_blob); acpi_build_madt(tables_blob, tables->linker,
X86_MACHINE(machine),Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/acpi-microvm.c static void acpi_build_microvm(AcpiBuildTables · line 215
Quoted 1 line
hw/i386/acpi-microvm.c +0
-1- ACPI_DEVICE_IF(x86ms->acpi_dev),
x86ms->oem_id,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 6 lines
hw/i386/acpi-microvm.c +1
-1- x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {(quoted diff) +0
-0
b/hw/i386/generic_event_device_x86.cQuoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/i386/generic_event_device_x86.c line 13
Quoted 10 lines
index
e26fb02a2e..8fc233e1f1100644hw/i386/generic_event_device_x86.c +0
-3@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init(ObjectClass *class, void*data)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/i386/generic_event_device_x86.c +0
-5-{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/generic_event_device_x86.c +0
-1static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/isa/lpc_ich9.c static void ich9_lpc_class_init(ObjectClass
Quoted 8 lines
hw/i386/generic_event_device_x86.c +0
-0.interfaces = (InterfaceInfo[]) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-0@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass*klass, void *data)
Quoted 11 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
hw/isa/lpc_ich9.c +0
-1hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
Re: [PATCH v3 2/7] hw/acpi/acpi_dev_interface: Resolve AcpiDeviceIfClass::madt_cpu
Quoted 128 lines · On Sat, 21 Jan 2023 16:37:26 +0100 Bernhard Beschow <[email protected]> wrote:
Quoted 126 lines · Igor Mammedov
Quoted 1 line · On Thu, 19 Jan 2023 14:47:41 +0000 Bernhard Beschow <[email protected]> wrote:
Am 18. Januar 2023 14:59:05 UTC schrieb Igor Mammedov <
Quoted 4 lines
Quoted 4 lines
Quoted 1 line · On Tue, 17 Jan 2023 00:30:23 +0000 Bernhard Beschow <[email protected]> wrote:
Am 16. Januar 2023 16:29:30 UTC schrieb Igor Mammedov <
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines · On Mon, 16 Jan 2023 16:29:03 +0100 Bernhard Beschow <[email protected]> wrote:
This class attribute was always set to
pc_madt_cpu_entry().pc_madt_cpu_entry()is architecture dependent and was assigned tothe
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
attribute even in architecture agnostic code such as in
hw/acpi/piix4.cQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
and hw/isa/lpc_ich9. Not having to set
madt_cputhere resolves the assumption that these device models are only ever used with ACPIon x86
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
targets.
The only target independent location where
madt_cpuwas called washw/
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
acpi/cpu.c. Here a function pointer can be passed via an argument instead. The other locations where it was called was inx86-specific code
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
where
pc_madt_cpu_entry()can be used directly.While at it, move
pc_madt_cpu_entry()from the public
include/hw/i386/Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
pc.hto the private hw/i386/acpi-common where it is alsoimplemented.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I'm not sure about this approach,
the callback is intend to be used not only by x86 but also in the end by ARM (it's just that arm/virt CPU hotplug patches are still work in progress and haven't been merged).IIUC one would call the target-independent
build_cpus_aml()from theARM-specific
build_madt(). There, one could pass a function pointer to an ARM-specificmadt_cpu_fn. Shouldn't that get us covered?Quoted 6 lines
Quoted 6 lines
it will work in this case, but I don't like going back to random function pointer argument approach instead of using QOM and interfaces which is much better in describing expectations/contract for interfaces adn objects it's attached to.
Quoted 8 lines
Quoted 8 lines
Howver that is not the reason why I'm against this approach, see bellow.
Quoted 6 lines
Quoted 4 lines
So I'd prefer to keep
AcpiDeviceIfClass::madt_cpu.What's the end goal you are trying to achieve by getting rid of this callback?
ACPI controllers are in principle not x86-specific, yet our PIIX4 and
ICH9 device models always assign an x86-specific function to
AcpiDeviceIfClass::madt_cpu. That doesn't seem right because the device models make assumptions about their usage contexts which they ideally shouldn't.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
In addition, it seems to me that ACPI controllers and AML generation
should not be mixed: An ACPI controller deals with (hardware) events while AML generation is usually a BIOS task to inject code into an OS. Therefore, ACPI controllers don't seem to be the right place to assign AML-generating functions because that doesn't match how reality works.
Quoted 6 lines
Quoted 6 lines
It would be nice to have pristine hardware-only device models and firmware composing ACPI tables like baremetal systems do (they have a luxury of fixed hardware which makes it way simpler), however it was not practical nor sustainable in mainstream virt case. That's the reason why ACPI tables (firmware) were moved into QEMU
(hardware).
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
To solve both issues, one could factor out e.g. an AmlDeviceIf from
AcpiDeviceIf, so one would't force the device models to provide an
madt_cpu.Quoted 1 line
Quoted 1 line
Quoted 1 line
Then one could assign a target-specific
AmlDeviceIfClass::madt_cpue.g. in board code.
Quoted 4 lines
Quoted 4 lines
ACPI tables in QEMU started this way, It stopped being maintainable at certain point, see below for more.
Quoted 1 line
At the moment I don't see a need for a new interface, however, since
the function pointer works just fine: It frees the device models from having to provide it and it is used in code which already deals with AML generation.
Quoted 8 lines
Quoted 8 lines
When the move happened, the bulk of ACPI code was as you suggest made as machine specific and it's still the case for the most of it. Then, with ease of adding new related features, it exploded into I would say hard to maintain mess. Hence before adding more and making it worse, I introduced call_dev_aml_func()/AcpiDevAmlIf and started refactoring PCI AML code. That simplified main PCI bus enumeration quite a bit.
Quoted 5 lines
Quoted 5 lines
The new interface however does exactly opposite of what you are doing, i.e. it pushes device specific AML generation into corresponding device model. It's not ideal as we have to provide stubs for targets where it's not needed. But stubs for target independent code is typical and proven approach we use in QEMU for such cases and is relatively easy to
maintain.
Quoted 7 lines
Quoted 5 lines
So I'd call it a reasonable compromise.
Recently posted series (that untangles generic PCI slots AML from ACPI PCI hotplug frankenstein) continues with AcpiDevAmlIf approach and pushes more AML into target in-depended device models.
I fully agree with the introduction of AcpiDevAmlIf. In fact I was
following your work closely since it helped me making the VT82xx south bridges work with the PC machine. In order to make your approach even more elegant and efficient I'm following up with
qbus_build_aml().Reviewed/acked it, thanks for nice cleanuup.
Quoted 1 line
This patch doesn't actually question the AcpiDevAmlIf. It rather
questions the mixing of CPU-related AML concerns into the ACPI controllers which are a priori CPU-agnostic. The only reason for dragging x86 concerns into these device models is that the AcpiDeviceIfClass requires
madt_cputo be assigned. Here we can apply the "interface segregation principle" which is why I proposed factoring out a dedicated interface from the AcpiDeviceIfClass (and possibly have CPUs implement it). I think that this would match your approach with AcpiDevAmlIf.There was and still is a reason for
madt_cpubeing part of AcpiDeviceIfClass and x86-ed piix impl.
Quoted 8 lines
Quoted 5 lines
(It might have been a poor choice to use acpi controller as hotplug controller as well
but that boat has sailed and can't be fixed without breaking ABI/migration.)Could you please elaborate a bit on how the ABI is affected? Migration seems clear to me.
What I'm saying wrt piix refactoring is that ACPI part of piix exposes registers (including made up ones) to guest and then migrates various hotplug state.
That behavior should not change when doing cross version migration. (upstream policy is: version-ed machine type from older QEMU should be migratable to new QEMU with the same machine type and keep exposed old QEMU ABI behavior the same, and nice to have would be backward also working)
I don't think it's possible to isolate/remove hotplug controller from piix without breaking ABI, hence was a suggestion to have piix-basic and leave qemu extensions in current piix which should be inherited from piix-basic. This way PPC target would pull only piix-basic and drop ACPI dependencies.
Quoted 19 lines
Quoted 3 lines
But as it is now, hotplug controller is an owner of CPU hotplug data on which ::madt_cpu relies.
Could you please also elaborate a bit here on how hotplug and ::madt_cpu are coupled? When generating the AML, one could check if both AcpiDeviceIfClass and ::madt_cpu are available. There is code instantiating
TYPE_ACPI_GEDin ARM and Loongarch which does not set ::madt_cpu. In order to see what I mean, I've prepared v4 of this series:
https://lore.kernel.org/qemu-devel/[email protected]I'd say the same about ::send_event hook which is only used in hotplug case
Quoted 6 lines
(GPE events do not have predefined meaning)
That only leavesAcpiDeviceIfClass::ospm_status, which in turn implicitly depends on hotplug controller to provide status data.
So question is why do you need AcpiDeviceIfClass for VIA, how much of it and how current impl. gets in the way of your goal?
Quoted 2 lines
I would just like to get feature parity with PIIX. Do you suggest taking a different approach which avoids the hotplug state in the ACPI controller?
I'd avoid pulling QEMU specific ACPI hotplug into VIA (we already have trouble as it is with piix pulling in unrelevant ACPI dependencies into other targets)
If one really needs ACPI hotplug on machine that uses VIA, I'd rather inherit via-qemu from basic VIA (as per spec) or better reuse generic hotplug controller (GED_DEVICE) that we already have (used in virt-arm/microvm). Though the later would limit guest OS to something modern (since it uses other means then legacy GPE registers block).
Quoted 358 lines
Thanks,
BernhardQuoted 354 lines
Quoted 9 lines
Quoted 8 lines
And there is more coming on top of it (with the goal to make most of what we accumulated in PC/Q35 PCI ACPI code become generic enough to replace most of PCI related AML elsewhere (microvm, arm/virt, whatever else that is interested in ACPI tables support). My ambition with this refactoring stops at making qdev device tree self-describable at PCI boundary but AcpiDevAmlIf can be applied to other devices described in DSDT, that hang off the board.
Quoted 3 lines
Sounds good!
Quoted 1 line
Quoted 1 line
My end goal is to make the VT82xx south bridges compatible with x86
and to bring them to feature parity with PIIX. For this, I need to implement the VIA ACPI controller proper, and since these south bridges are currently only used in MIPS and PowerPC contexts I'm feeling a bit uncomfortable having to drag in x86 assumptions into these devices.
Quoted 17 lines
Quoted 9 lines
basic ACPI hardware (GPE/PM registers) code is relatively isolated, so you probably can implement that without touching piix much. (with little to no stubs).
If you want to cleanup piix and free other targets from unfortunate ACPI/x86 specific dependencies, it would probably need another approach than presented here.
Quoted 7 lines
ex:
Isolating core(pristine) piix code in piix-basic class for PPC/MIPS use, and then branching/inheriting of it current piix class with all extra x86 'features' might work without breaking migration. (/me assuming cross version migration should work in this arrangement, though I won't bet on it)Quoted 1 line
It seems to me that extending the PIIX4 PM class hierarchy with
piix-basic is just a workaround for the root problem I mentioned above, which is the mixing of unrelated concerns into one interface. So let my try to factor out an AcpiCpuAmlIf from AcpiDeviceIfClass and see how it goes. See above, lets discuss it there.
Quoted 37 lines
Best regards,
BernhardQuoted 34 lines
Quoted 34 lines
Best regards,
BernhardQuoted 30 lines
Quoted 30 lines
Signed-off-by Bernhard Beschow <[email protected]>--- hw/i386/acpi-common.h | 7 +++++-- include/hw/acpi/acpi_dev_interface.h | 2 -- include/hw/acpi/cpu.h | 6 +++++- include/hw/i386/pc.h | 4 ---- hw/acpi/acpi-x86-stub.c | 6 ------ hw/acpi/cpu.c | 10 ++++------ hw/acpi/piix4.c | 2 -- hw/i386/acpi-build.c | 5 ++--- hw/i386/acpi-common.c | 5 ++--- hw/i386/acpi-microvm.c | 3 +-- hw/i386/generic_event_device_x86.c | 9 --------- hw/isa/lpc_ich9.c | 1 - 12 files changed, 19 insertions(+), 41 deletions(-)hw/i386/acpi-common.h +1
-1@@ -1,15 +1,18 @@#ifndef HW_I386_ACPI_COMMON_H #define HW_I386_ACPI_COMMON_H -#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/i386/x86.h" +#include "hw/boards.h" Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-common.h line 11
Quoted 4 lines
hw/i386/acpi-common.h +1
-0/* Default IOAPIC ID */ #define ACPI_BUILD_IOAPIC_ID 0x0 +void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,GArray *entry,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/i386/acpi-common.h line 16
Quoted 6 lines
hw/i386/acpi-common.h +3
-1+ bool force_enabled); +void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms, const char *oem_id, const char
*oem_table_id);Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
hw/i386/acpi-common.h +0
-0#endif (quoted diff) +0
-0
b/include/hw/acpi/acpi_dev_interface.hQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/hw/acpi/acpi_dev_interface.h struct AcpiDeviceIfClass { · line 53
Quoted 6 lines
index
a1648220ff..ca92928124100644include/hw/acpi/acpi_dev_interface.h +0
-0@@ -52,7 +52,5 @@ struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev, ACPIOSTInfoList***list);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h struct AcpiDeviceIfClass { · line 54
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h +0
-0void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBitsev);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h struct AcpiDeviceIfClass { · line 55
Quoted 1 line
include/hw/acpi/acpi_dev_interface.h +0
-1- void (*madt_cpu)(int uid, const CPUArchIdList *apic_ids,GArray *entry,
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
include/hw/acpi/acpi_dev_interface.h +0
-1- bool force_enabled); };#endif include/hw/acpi/cpu.h +1
-0@@ -15,6 +15,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/boards.h" #include "hw/hotplug.h" Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures { · line 59
Quoted 6 lines
include/hw/acpi/cpu.h +1
-0typedef struct AcpiCpuStatus {@@ -55,8 +56,11 @@ typedef struct CPUHotplugFeatures {const char *smi_path; } CPUHotplugFeatures; +typedef void (*madt_cpu_fn)(int uid, const CPUArchIdList
*apic_ids,Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures { · line 62
Quoted 3 lines
include/hw/acpi/cpu.h +2
-0+ GArray *entry, bool force_enabled); + void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
include/hw/i386/pc.h bool pc_system_ovmf_table_find(const char
Quoted 10 lines
include/hw/acpi/cpu.h +1
-1-hwaddr io_base, + hwaddr io_base, madt_cpu_fn madt_cpu, const char *res_root, const char *event_handler_method);include/hw/i386/pc.h +0
-0@@ -191,10 +191,6 @@ bool pc_system_ovmf_table_find(const char*entry,
uint8_t**data,Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
include/hw/i386/pc.h bool pc_system_ovmf_table_find(const char · line 192
Quoted 2 lines
include/hw/i386/pc.h +0
-0int *data_len); void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t
flash_size);Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
include/hw/i386/pc.h +0
-4-/* hw/i386/acpi-common.c */ -void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled); -/* sgx.c */ void pc_machine_init_sgx_epc (PCMachineState *pcms);hw/acpi/acpi-x86-stub.c +0
-1@@ -1,12 +1,6 @@#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/i386/acpi-build.h" Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/acpi/acpi-x86-stub.c +0
-5-void pc_madt_cpu_entry (int uid,const CPUArchIdList *apic_ids, -GArray *entry,bool force_enabled) -{ -} -Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug =
Quoted 8 lines
hw/acpi/acpi-x86-stub.c +0
-0Object *acpi_get_i386_pci_host (void ) {return NULL ;hw/acpi/cpu.c +0
-0@@ -338,7 +338,7 @@ const VMStateDescription vmstate_cpu_hotplug ={
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug = · line 340
Quoted 3 lines
hw/acpi/cpu.c +0
-0#define CPU_FW_EJECT_EVENT "CEJF" void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 6 lines
hw/acpi/cpu.c +1
-1-hwaddr io_base, + hwaddr io_base, madt_cpu_fn madt_cpu, const char *res_root, const char *event_handler_method) {@@ -353,8 +353,8 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 354
Quoted 2 lines
hw/acpi/cpu.c +0
-0MachineClass *mc =MACHINE_GET_CLASS (machine); const CPUArchIdList *arch_ids =
mc->possible_cpu_arch_ids(machine);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 355
Quoted 1 line
hw/acpi/cpu.c +0
-0char *cphp_res_path = g_strdup_printf("%s." CPUHP_RES_DEVICE,
res_root);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 356
Quoted 1 line
hw/acpi/cpu.c +0
-1- Object *obj = object_resolve_path_type("",
TYPE_ACPI_DEVICE_IF, NULL);Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 7 lines
hw/acpi/cpu.c +2
-1-AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj); + +assert (madt_cpu); cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); {@@ -664,9 +664,7 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 667
Quoted 7 lines
hw/acpi/cpu.c +1
-3aml_append (dev, method);/* build _MAT object */ -assert (adevc && adevc->madt_cpu); - adevc->madt_cpu (i, arch_ids, madt_buf, - true);/* set enabled flag */ +madt_cpu (i, arch_ids, madt_buf, true/* set enabled flag */);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 669
Quoted 2 lines
hw/acpi/cpu.c +0
-0aml_append(dev, aml_name_decl("_MAT", aml_buffer(madt_buf->len, (uint8_t*)madt_buf->data)));
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/acpi/cpu.c +0
-0g_array_free (madt_buf, true);hw/acpi/piix4.c +0
-0@@ -20,7 +20,6 @@*/ Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/acpi/piix4.c static void piix4_pm_class_init(ObjectClass
Quoted 6 lines
hw/acpi/piix4.c +0
-1#include "qemu/osdep.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" @@ -643,7 +642,6 @@ static void piix4_pm_class_init(ObjectClass*klass, void *data)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/acpi/piix4.c +0
-1hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; adevc->send_event = piix4_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; }Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/i386/acpi-build.c build_dsdt(GArray *table_data, BIOSLinker
Quoted 6 lines
hw/acpi/piix4.c +0
-0static const TypeInfo piix4_pm_info = {hw/i386/acpi-build.c +0
-0@@ -1440,7 +1440,7 @@ build_dsdt(GArray *table_data, BIOSLinker*linker,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/i386/acpi-build.c build_dsdt(GArray *table_data, BIOSLinker · line 1443
Quoted 5 lines
hw/i386/acpi-build.c +1
-1.fw_unplugs_cpu = pm->smi_on_cpu_unplug, }; build_cpus_aml(dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); + pc_madt_cpu_entry, "\\_SB.PCI0","\\_GPE._E02");
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-build.c void acpi_build(AcpiBuildTables *tables,
Quoted 4 lines
hw/i386/acpi-build.c +0
-0}if (pcms->memhp_io_base && nr_mem) {@@ -2424,8 +2424,7 @@ void acpi_build(AcpiBuildTables *tables,MachineState *machine)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-build.c void acpi_build(AcpiBuildTables *tables, · line 2426
Quoted 4 lines
hw/i386/acpi-build.c +0
-1acpi_add_table (table_offsets, tables_blob); acpi_build_madt(tables_blob, tables->linker, x86ms, - ACPI_DEVICE_IF(x86ms->acpi_dev),
x86ms->oem_id,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/i386/acpi-common.c build_xrupt_override(GArray *entry, uint8_t
Quoted 10 lines
hw/i386/acpi-build.c +1
-1- x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {hw/i386/acpi-common.c +0
-0@@ -94,14 +94,13 @@ build_xrupt_override(GArray *entry, uint8_tsrc,
uint32_tgsi,uint16_tflags)Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
hw/i386/acpi-common.c build_xrupt_override(GArray *entry, uint8_t · line 103
Quoted 11 lines
hw/i386/acpi-common.c +1
-1* 5.2.8 Multiple APIC Description Table */ void acpi_build_madt (GArray *table_data,BIOSLinker *linker, -X86MachineState *x86ms,AcpiDeviceIf *adev, +X86MachineState *x86ms,const char *oem_id,const char *oem_table_id) {int i;bool x2apic_mode = false;MachineClass *mc =MACHINE_GET_CLASS (x86ms); const CPUArchIdList *apic_ids =mc->possible_cpu_arch_ids(MACHINE(x86ms));
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/i386/acpi-common.c void acpi_build_madt(GArray *table_data,
Quoted 5 lines
hw/i386/acpi-common.c +0
-1-AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (adev);AcpiTable table = { .sig ="APIC" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id };@@ -111,7 +110,7 @@ void acpi_build_madt(GArray *table_data,BIOSLinker *linker,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/acpi-common.c void acpi_build_madt(GArray *table_data, · line 110
Quoted 1 line
hw/i386/acpi-common.c +0
-0build_append_int_noprefix(table_data, 1 /* PCAT_COMPAT */,4); /* Flags */
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
hw/i386/acpi-microvm.c static void acpi_build_microvm(AcpiBuildTables
Quoted 12 lines
hw/i386/acpi-common.c +1
-1for (i =0 ; i < apic_ids->len; i++) { - adevc->madt_cpu (i, apic_ids, table_data, false); +pc_madt_cpu_entry (i, apic_ids, table_data, false);if (apic_ids->cpus[i].arch_id >254 ) { x2apic_mode = true; }hw/i386/acpi-microvm.c +0
-0@@ -213,8 +213,7 @@ static void acpi_build_microvm(AcpiBuildTables*tables,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
hw/i386/acpi-microvm.c static void acpi_build_microvm(AcpiBuildTables · line 214
Quoted 3 lines
hw/i386/acpi-microvm.c +0
-0acpi_add_table (table_offsets, tables_blob); acpi_build_madt(tables_blob, tables->linker,
X86_MACHINE(machine),Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/acpi-microvm.c static void acpi_build_microvm(AcpiBuildTables · line 215
Quoted 1 line
hw/i386/acpi-microvm.c +0
-1- ACPI_DEVICE_IF(x86ms->acpi_dev),
x86ms->oem_id,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 6 lines
hw/i386/acpi-microvm.c +1
-1- x86ms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id);#ifdef CONFIG_ACPI_ERST {(quoted diff) +0
-0
b/hw/i386/generic_event_device_x86.cQuoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/i386/generic_event_device_x86.c line 13
Quoted 10 lines
index
e26fb02a2e..8fc233e1f1100644hw/i386/generic_event_device_x86.c +0
-3@@ -8,19 +8,10 @@#include "qemu/osdep.h" #include "hw/acpi/generic_event_device.h" -#include "hw/i386/pc.h" - -static void acpi_ged_x86_class_init(ObjectClass *class, void*data)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/i386/generic_event_device_x86.c +0
-5-{ -AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_CLASS (class); - - adevc->madt_cpu = pc_madt_cpu_entry; -}Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/generic_event_device_x86.c +0
-1static const TypeInfo acpi_ged_x86_info = { .name =TYPE_ACPI_GED_X86 , .parent =TYPE_ACPI_GED , - .class_init = acpi_ged_x86_class_init,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/isa/lpc_ich9.c static void ich9_lpc_class_init(ObjectClass
Quoted 8 lines
hw/i386/generic_event_device_x86.c +0
-0.interfaces = (InterfaceInfo[]) { {TYPE_HOTPLUG_HANDLER }, {TYPE_ACPI_DEVICE_IF },hw/isa/lpc_ich9.c +0
-0@@ -870,7 +870,6 @@ static void ich9_lpc_class_init(ObjectClass*klass, void *data)
Quoted 11 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
hw/isa/lpc_ich9.c +0
-1hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; - adevc->madt_cpu = pc_madt_cpu_entry; amldevc->build_dev_aml = build_ich9_isa_aml; }
PATCH v3 3/7 hw/acpi/acpi_dev_interface: Remove now unused #include "hw/boards.h"
In reply to Bernhard BeschowRemoving the "hw/boards.h" include from hw/acpi/acpi_dev_interface.h requires include fixes in various unrelated files to keep the code compiling.
--- hw/acpi/hmat.h | 3 ++- include/hw/acpi/acpi_dev_interface.h | 1 - hw/acpi/cpu.c | 1 + hw/acpi/hmat.c | 1 + hw/acpi/memory_hotplug.c | 1 + monitor/qmp-cmds.c | 1 + 6 files changed, 6 insertions(+), 2 deletions(-)
hw/acpi/hmat.h +2 -1
@@ -27,7 +27,8 @@#ifndef HMAT_H #define HMAT_H -#include "hw/acpi/aml-build.h" +#include "hw/acpi/bios-linker-loader.h" +#include "sysemu/numa.h" /* * ACPI 6.3: 5.2.27.3 Memory Proximity Domain Attributes Structure,
include/hw/acpi/acpi_dev_interface.h +0 -1
@@ -3,7 +3,6 @@#include "qapi/qapi-types-acpi.h" #include "qom/object.h" -#include "hw/boards.h" #include "hw/qdev-core.h" /* These values are part of guest ABI, and can not be changed */
hw/acpi/cpu.c +1 -0
@@ -1,6 +1,7 @@#include "qemu/osdep.h" #include "migration/vmstate.h" #include "hw/acpi/cpu.h" +#include "hw/core/cpu.h" #include "qapi/error.h" #include "qapi/qapi-events-acpi.h" #include "trace.h"
hw/acpi/hmat.c +1 -0
@@ -27,6 +27,7 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "sysemu/numa.h" +#include "hw/acpi/aml-build.h" #include "hw/acpi/hmat.h" /*
hw/acpi/memory_hotplug.c +1 -0
@@ -1,6 +1,7 @@#include "qemu/osdep.h" #include "hw/acpi/memory_hotplug.h" #include "hw/mem/pc-dimm.h" +#include "hw/boards.h" #include "hw/qdev-core.h" #include "migration/vmstate.h" #include "trace.h"
monitor/qmp-cmds.c +1 -0
@@ -44,6 +44,7 @@#include "hw/acpi/acpi_dev_interface.h" #include "hw/intc/intc.h" #include "hw/rdma/rdma.h" +#include "hw/boards.h" #include "monitor/stats.h" NameInfo *qmp_query_name (Error **errp)
Signature · 1 line
2.39.0
PATCH v3 4/7 hw/acpi/piix4: No need to #include "hw/southbridge/piix.h"
In reply to Bernhard Beschowhw/acpi/piix4 has its own header with its structure definition etc.
Ammends commit 2bfd0845f0 'hw/acpi/piix4: move PIIX4PMState into separate piix4.h header'.
--- hw/acpi/piix4.c | 1 - 1 file changed, 1 deletion(-)
hw/acpi/piix4.c +0 -1
@@ -20,7 +20,6 @@*/ #include "qemu/osdep.h" -#include "hw/southbridge/piix.h" #include "hw/irq.h" #include "hw/isa/apm.h" #include "hw/i2c/pm_smbus.h"
Signature · 1 line
2.39.0
PATCH v3 5/7 hw/i386/acpi-build: Remove unused attributes
In reply to Bernhard BeschowAmmends commit 3db119da7915 'pc: acpi: switch to AML API composed DSDT'.
--- hw/i386/acpi-build.c | 2 -- 1 file changed, 2 deletions(-)
hw/i386/acpi-build.c +0 -2
@@ -117,8 +117,6 @@ typedef struct AcpiMiscInfo {#ifdef CONFIG_TPM TPMVersion tpm_version;#endif -const unsigned char *dsdt_code; -unsigned dsdt_size; } AcpiMiscInfo; typedef struct FwCfgTPMConfig {
Signature · 1 line
2.39.0
Re: [PATCH v3 5/7] hw/i386/acpi-build: Remove unused attributes
Quoted 4 lines · On Mon, 16 Jan 2023 16:29:06 +0100 Bernhard Beschow <[email protected]> wrote:
Ammends commit
3db119da7915'pc: acpi: switch to AML API composed DSDT'.Signed-off-by Bernhard Beschow <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
--- hw/i386/acpi-build.c | 2 -- 1 file changed, 2 deletions(-)hw/i386/acpi-build.c +0
-2@@ -117,8 +117,6 @@ typedef struct AcpiMiscInfo {#ifdef CONFIG_TPM TPMVersion tpm_version;#endif -const unsigned char *dsdt_code; -unsigned dsdt_size; } AcpiMiscInfo; typedef struct FwCfgTPMConfig {
PATCH v3 6/7 hw/isa/isa-bus: Turn isa_build_aml() into qbus_build_aml()
In reply to Bernhard BeschowFrees isa-bus.c from implicit ACPI dependency.
--- include/hw/acpi/acpi_aml_interface.h | 3 +++ include/hw/isa/isa.h | 1 - hw/acpi/acpi_interface.c | 10 ++++++++++ hw/i386/acpi-microvm.c | 3 ++- hw/isa/isa-bus.c | 10 ---------- 5 files changed, 15 insertions(+), 12 deletions(-)
include/hw/acpi/acpi_aml_interface.h +3 -0
@@ -3,6 +3,7 @@#include "qom/object.h" #include "hw/acpi/aml-build.h" +#include "hw/qdev-core.h" #define TYPE_ACPI_DEV_AML_IF "acpi-dev-aml-interface"typedef struct AcpiDevAmlIfClass AcpiDevAmlIfClass ;
@@ -46,4 +47,6 @@ static inline void call_dev_aml_func(DeviceState *dev, Aml *scope) } } +void qbus_build_aml (BusState *bus,Aml *scope); +#endif
include/hw/isa/isa.h +0 -1
@@ -86,7 +86,6 @@ bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp);ISADevice *isa_create_simple (ISABus *bus,const char *name);ISADevice *isa_vga_init (ISABus *bus); -void isa_build_aml (ISABus *bus,Aml *scope);/** * isa_register_ioport: Install an I/O port region on the ISA bus.
hw/acpi/acpi_interface.c +10 -0
@@ -2,6 +2,7 @@#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/acpi_aml_interface.h" #include "qemu/module.h" +#include "qemu/queue.h" void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) {
@@ -12,6 +13,15 @@ void acpi_send_event(DeviceState *dev, AcpiEventStatusBits event) } } +void qbus_build_aml (BusState *bus,Aml *scope) +{ +BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { +call_dev_aml_func (DEVICE (kid->child), scope); + } +} +static void register_types (void ) {static const TypeInfo acpi_dev_if_info = {
hw/i386/acpi-microvm.c +2 -1
@@ -26,6 +26,7 @@#include "exec/memory.h" #include "hw/acpi/acpi.h" +#include "hw/acpi/acpi_aml_interface.h" #include "hw/acpi/aml-build.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/acpi/generic_event_device.h"
@@ -129,7 +130,7 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker, sb_scope =aml_scope ("_SB" );fw_cfg_add_acpi_dsdt (sb_scope, x86ms->fw_cfg); -isa_build_aml (ISA_BUS (isabus), sb_scope); +qbus_build_aml (BUS (isabus), sb_scope);build_ged_aml (sb_scope,GED_DEVICE , x86ms->acpi_dev,GED_MMIO_IRQ ,AML_SYSTEM_MEMORY ,GED_MMIO_BASE );acpi_dsdt_add_power_button (sb_scope);
hw/isa/isa-bus.c +0 -10
@@ -24,7 +24,6 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "hw/isa/isa.h" -#include "hw/acpi/acpi_aml_interface.h" static ISABus *isabus;
@@ -188,15 +187,6 @@ ISADevice *isa_vga_init(ISABus *bus) } } -void isa_build_aml (ISABus *bus,Aml *scope) -{ -BusChild *kid; - - QTAILQ_FOREACH(kid, &bus->parent_obj.children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } -} -static void isabus_bridge_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
Signature · 1 line
2.39.0
Re: [PATCH v3 6/7] hw/isa/isa-bus: Turn isa_build_aml() into qbus_build_aml()
Quoted 4 lines · On Mon, 16 Jan 2023 16:29:07 +0100 Bernhard Beschow <[email protected]> wrote:
Frees
isa-bus.cfrom implicit ACPI dependency.Signed-off-by Bernhard Beschow <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 116 lines
--- include/hw/acpi/acpi_aml_interface.h | 3 +++ include/hw/isa/isa.h | 1 - hw/acpi/acpi_interface.c | 10 ++++++++++ hw/i386/acpi-microvm.c | 3 ++- hw/isa/isa-bus.c | 10 ---------- 5 files changed, 15 insertions(+), 12 deletions(-)include/hw/acpi/acpi_aml_interface.h +3
-0@@ -3,6 +3,7 @@#include "qom/object.h" #include "hw/acpi/aml-build.h" +#include "hw/qdev-core.h" #define TYPE_ACPI_DEV_AML_IF "acpi-dev-aml-interface"typedef struct AcpiDevAmlIfClass AcpiDevAmlIfClass ;@@ -46,4 +47,6 @@ static inline void call_dev_aml_func(DeviceState *dev, Aml *scope) } } +void qbus_build_aml (BusState *bus,Aml *scope); +#endif include/hw/isa/isa.h +0
-1@@ -86,7 +86,6 @@ bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp);ISADevice *isa_create_simple (ISABus *bus,const char *name);ISADevice *isa_vga_init (ISABus *bus); -void isa_build_aml (ISABus *bus,Aml *scope);/** * isa_register_ioport: Install an I/O port region on the ISA bus. hw/acpi/acpi_interface.c +10
-0@@ -2,6 +2,7 @@#include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/acpi_aml_interface.h" #include "qemu/module.h" +#include "qemu/queue.h" void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) {@@ -12,6 +13,15 @@ void acpi_send_event(DeviceState *dev, AcpiEventStatusBits event) } } +void qbus_build_aml (BusState *bus,Aml *scope) +{ +BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { +call_dev_aml_func (DEVICE (kid->child), scope); + } +} +static void register_types (void ) {static const TypeInfo acpi_dev_if_info = {hw/i386/acpi-microvm.c +2
-1@@ -26,6 +26,7 @@#include "exec/memory.h" #include "hw/acpi/acpi.h" +#include "hw/acpi/acpi_aml_interface.h" #include "hw/acpi/aml-build.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/acpi/generic_event_device.h" @@ -129,7 +130,7 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker, sb_scope =aml_scope ("_SB" );fw_cfg_add_acpi_dsdt (sb_scope, x86ms->fw_cfg); -isa_build_aml (ISA_BUS (isabus), sb_scope); +qbus_build_aml (BUS (isabus), sb_scope);build_ged_aml (sb_scope,GED_DEVICE , x86ms->acpi_dev,GED_MMIO_IRQ ,AML_SYSTEM_MEMORY ,GED_MMIO_BASE );acpi_dsdt_add_power_button (sb_scope);hw/isa/isa-bus.c +0
-10@@ -24,7 +24,6 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "hw/isa/isa.h" -#include "hw/acpi/acpi_aml_interface.h" static ISABus *isabus;@@ -188,15 +187,6 @@ ISADevice *isa_vga_init(ISABus *bus) } } -void isa_build_aml (ISABus *bus,Aml *scope) -{ -BusChild *kid; - - QTAILQ_FOREACH(kid, &bus->parent_obj.children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } -} -static void isabus_bridge_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
PATCH v3 7/7 piix3, ich9: Reuse qbus_build_aml()
In reply to Bernhard Beschow--- hw/i2c/smbus_ich9.c | 5 +---- hw/isa/lpc_ich9.c | 5 +---- hw/isa/piix3.c | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-)
hw/i2c/smbus_ich9.c +1 -4
@@ -97,13 +97,10 @@ static void ich9_smbus_realize(PCIDevice *d, Error **errp)static void build_ich9_smb_aml (AcpiDevAmlIf *adev,Aml *scope) { -BusChild *kid;ICH9SMBState *s =ICH9_SMB_DEVICE (adev);BusState *bus =BUS (s->smb.smbus); - QTAILQ_FOREACH(kid, &bus->children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } +qbus_build_aml (bus, scope); }static void ich9_smb_class_init (ObjectClass *klass,void *data)
hw/isa/lpc_ich9.c +1 -4
@@ -813,7 +813,6 @@ static void ich9_send_gpe(AcpiDeviceIf *adev, AcpiEventStatusBits ev)static void build_ich9_isa_aml (AcpiDevAmlIf *adev,Aml *scope) {Aml *field; -BusChild *kid;ICH9LPCState *s =ICH9_LPC_DEVICE (adev);BusState *bus =BUS (s->isa_bus);Aml *sb_scope =aml_scope ("\\_SB" );
@@ -835,9 +834,7 @@ static void build_ich9_isa_aml(AcpiDevAmlIf *adev, Aml *scope)aml_append (sb_scope, field);aml_append (scope, sb_scope); - QTAILQ_FOREACH(kid, &bus->children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } +qbus_build_aml (bus, scope); }static void ich9_lpc_class_init (ObjectClass *klass,void *data)
hw/isa/piix3.c +1 -4
@@ -306,7 +306,6 @@ static void pci_piix3_realize(PCIDevice *dev, Error **errp)static void build_pci_isa_aml (AcpiDevAmlIf *adev,Aml *scope) {Aml *field; -BusChild *kid;Aml *sb_scope =aml_scope ("\\_SB" );BusState *bus =qdev_get_child_bus (DEVICE (adev),"isa.0" );
@@ -322,9 +321,7 @@ static void build_pci_isa_aml(AcpiDevAmlIf *adev, Aml *scope)aml_append (sb_scope, field);aml_append (scope, sb_scope); - QTAILQ_FOREACH(kid, &bus->children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } +qbus_build_aml (bus, scope); }static void pci_piix3_class_init (ObjectClass *klass,void *data)
Signature · 1 line
2.39.0
Re: [PATCH v3 7/7] piix3, ich9: Reuse qbus_build_aml()
Quoted 2 lines · On Mon, 16 Jan 2023 16:29:08 +0100 Bernhard Beschow <[email protected]> wrote:
Signed-off-by Bernhard Beschow <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>
I'd squash it in previous patch, and rename that to something
'remove no longer needed isa_build_aml()
isa_build_aml() doesn't do anything except
calling call_dev_aml_func() on bus children
along with other places that do the same.
Move that into ... and cleanup those places
as well.
'
Quoted 71 lines
--- hw/i2c/smbus_ich9.c | 5 +---- hw/isa/lpc_ich9.c | 5 +---- hw/isa/piix3.c | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-)hw/i2c/smbus_ich9.c +1
-4@@ -97,13 +97,10 @@ static void ich9_smbus_realize(PCIDevice *d, Error **errp)static void build_ich9_smb_aml (AcpiDevAmlIf *adev,Aml *scope) { -BusChild *kid;ICH9SMBState *s =ICH9_SMB_DEVICE (adev);BusState *bus =BUS (s->smb.smbus); - QTAILQ_FOREACH(kid, &bus->children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } +qbus_build_aml (bus, scope); }static void ich9_smb_class_init (ObjectClass *klass,void *data)hw/isa/lpc_ich9.c +1
-4@@ -813,7 +813,6 @@ static void ich9_send_gpe(AcpiDeviceIf *adev, AcpiEventStatusBits ev)static void build_ich9_isa_aml (AcpiDevAmlIf *adev,Aml *scope) {Aml *field; -BusChild *kid;ICH9LPCState *s =ICH9_LPC_DEVICE (adev);BusState *bus =BUS (s->isa_bus);Aml *sb_scope =aml_scope ("\\_SB" );@@ -835,9 +834,7 @@ static void build_ich9_isa_aml(AcpiDevAmlIf *adev, Aml *scope)aml_append (sb_scope, field);aml_append (scope, sb_scope); - QTAILQ_FOREACH(kid, &bus->children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } +qbus_build_aml (bus, scope); }static void ich9_lpc_class_init (ObjectClass *klass,void *data)hw/isa/piix3.c +1
-4@@ -306,7 +306,6 @@ static void pci_piix3_realize(PCIDevice *dev, Error **errp)static void build_pci_isa_aml (AcpiDevAmlIf *adev,Aml *scope) {Aml *field; -BusChild *kid;Aml *sb_scope =aml_scope ("\\_SB" );BusState *bus =qdev_get_child_bus (DEVICE (adev),"isa.0" );@@ -322,9 +321,7 @@ static void build_pci_isa_aml(AcpiDevAmlIf *adev, Aml *scope)aml_append (sb_scope, field);aml_append (scope, sb_scope); - QTAILQ_FOREACH(kid, &bus->children, sibling) { -call_dev_aml_func (DEVICE (kid->child), scope); - } +qbus_build_aml (bus, scope); }static void pci_piix3_class_init (ObjectClass *klass,void *data)