ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods
cover ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods
Changelog:
RFC->v1:
- drop machine.cpu-hotplug property and leave CPU hotplug always enabled as it used to be.
(it also simplifies, series a bit)
- reshuffle/squash some patches to make series bisectable wrt 'make check' failures
- add doc comment in qapi schema
- fix 'make check' error for mips target, disableCPU hotplug code path in piix4_pm for mips
- drop some intermediate expected ACPI tables updates
- replace _MAT method with named buffer object
Current ACPI interface for CPU hotplug supports hotadding only upto 255 CPUs and lacks means to convey additional information needed for _PXM and _OST methods support. Also being bitmap based with bit position specifying APIC ID it doesn't scale up for 32-bit APIC IDs that will come with x2APIC support.
So factor out current CPU hotplug into legacy module, that is used by 2.6 and older machine types as we can't break ABI and build another QEMU-guest interface using as model memory-hotplug. New interface will be used since 2.7 machine types and will support:
- more than 255 CPUs with 32-bit APIC ID value
- a registers set to communicate PXM/OST information (extendable without breaking IO layout)
- possible to reuse for ARM's 'virt' machine type with minimal tweaks (add init for MMIO, add
ACPI hooks on CPU hotplug path)
Series consists of 2 parts:
1-10 patches: cleanup, consolidate legacy ACPI CPU hotplug 11-33 patches:
* extending AcpiDeviceIfClass to make ACPI event notification more target agnostic,
* adding new ACPI HW and AML parts of CPU hotplug that support more than 255 CPUs. Plus some cleanups that partially remove apic_id_limit limitation. The rest of apic_id_limit cleanups will go later on top of this series as part of x2APIC series.
* implementing unplug side of ACPI HW/AML and basic unplug hooking in hot-unplug callback. TODO:For mgmt to use unplug it needs device_add/del support which is work in progress and will go on top of this series.
* adding extra _PXM/_OST method handling so that guest would actually know to which node CPU is hotplugged and report hotplug status progress to mgmt.
Tested with following guests: RHEL7, WS2003EEx64, WS2012R2x64
* unplug is tested only with RHEL7 as Windows doesn't support it.
* untested migration.
git tree for testing:
[email protected]:imammedo/qemu.git modern_cpu_hotplug_v1
viewing:
https://github.com/imammedo/qemu/commits/modern_cpu_hotplug_v1
Igor Mammedov (33):
tests: acpi: report names of expected files in verbose mode
acpi: add aml_debug()
acpi: add aml_refof()
pc: acpi: remove AML for empty/not used GPE handlers
pc: acpi: consolidate CPU hotplug AML
pc: acpi: consolidate \GPE._E02 with the rest of CPU hotplug AML
pc: acpi: cpu-hotplug: make AML CPU_foo defines local to
cpu_hotplug_acpi_table.c
pc: acpi: mark current CPU hotplug functions as legacy
pc: acpi: consolidate legacy CPU hotplug in one file
pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature
pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx
tests: acpi: update tables with consolidated legacy cpu-hotplug AML
acpi: extend ACPI interface to provide send_event hook
pc: use AcpiDeviceIfClass.send_event to issue GPE events
docs: update ACPI CPU hotplug spec with new protocol
acpi: hardware side of CPU hotplug
pc: add generic CPU unplug callbacks
pc: add 2.7 machine
pc: piix4/ich9: add 'cpu-hotplug-legacy' property
pc: q35: initialize new CPU hotplug hw
pc: piix4: initialize new CPU hotplug hw
pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
acpi: add CPU devices AML to DSDT
acpi: add CPU hotplug methods to DSDT
qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
target-i386: add X86CPU.node property
pc: numa: replace node_cpu indexing by apic_id with possible_cpus
index
pc: set X86CPU.node property if QEMU starts with numa enabled
acpi: cpuhp: provide cpu._PXM method if running in numa mode
acpi: cpuhp: add cpu._OST handling
tests: acpi: update expected tables with new cpu-hotplug methods
enabled by default
tests: acpi: add CPU hotplug testcase
tests: acpi: add DSDT/MADT expected tables for cpu-hotplug case
docs/specs/acpi_cpu_hotplug.txt | 88 +++++- hw/acpi/Makefile.objs | 3 +- hw/acpi/aml-build.c | 17 + hw/acpi/core.c | 2 +- hw/acpi/cpu.c | 583 +++++++++++++++++++++++++++++++++++ hw/acpi/cpu_hotplug.c | 246 ++++++++++++++- hw/acpi/cpu_hotplug_acpi_table.c | 136 -------- hw/acpi/ich9.c | 94 +++++- hw/acpi/memory_hotplug.c | 12 +- hw/acpi/pcihp.c | 10 +- hw/acpi/piix4.c | 78 ++++- hw/core/hotplug.c | 11 + hw/core/qdev.c | 9 +- hw/i386/acpi-build.c | 191 +++--------- hw/i386/pc.c | 118 +++++-- hw/i386/pc_piix.c | 16 +- hw/i386/pc_q35.c | 13 +- hw/isa/lpc_ich9.c | 39 +-- include/hw/acpi/acpi.h | 10 +- include/hw/acpi/acpi_dev_interface.h | 25 ++ include/hw/acpi/aml-build.h | 2 + include/hw/acpi/cpu.h | 62 ++++ include/hw/acpi/cpu_hotplug.h | 19 +- include/hw/acpi/ich9.h | 16 +- include/hw/acpi/memory_hotplug.h | 4 +- include/hw/acpi/pcihp.h | 5 +- include/hw/compat.h | 12 + include/hw/hotplug.h | 14 +- include/hw/i386/pc.h | 9 + qapi-schema.json | 3 +- stubs/Makefile.objs | 1 + stubs/pc_madt_cpu_entry.c | 7 + target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 42 +++ tests/acpi-test-data/pc/APIC.cphp | Bin 0 -> 160 bytes tests/acpi-test-data/pc/DSDT | Bin 5587 -> 5951 bytes tests/acpi-test-data/pc/DSDT.bridge | Bin 7446 -> 7810 bytes tests/acpi-test-data/pc/DSDT.cphp | Bin 0 -> 6578 bytes tests/acpi-test-data/pc/SRAT.cphp | Bin 0 -> 304 bytes tests/acpi-test-data/q35/APIC.cphp | Bin 0 -> 160 bytes tests/acpi-test-data/q35/DSDT | Bin 8357 -> 8713 bytes tests/acpi-test-data/q35/DSDT.bridge | Bin 8374 -> 8730 bytes tests/acpi-test-data/q35/DSDT.cphp | Bin 0 -> 9340 bytes tests/acpi-test-data/q35/SRAT.cphp | Bin 0 -> 304 bytes tests/bios-tables-test.c | 54 +++- trace-events | 13 + 46 files changed, 1524 insertions(+), 441 deletions(-) create mode 100644 hw/acpi/cpu.c delete mode 100644 hw/acpi/cpu_hotplug_acpi_table.c create mode 100644 include/hw/acpi/cpu.h create mode 100644 stubs/pc_madt_cpu_entry.c create mode 100644 tests/acpi-test-data/pc/APIC.cphp create mode 100644 tests/acpi-test-data/pc/DSDT.cphp create mode 100644 tests/acpi-test-data/pc/SRAT.cphp create mode 100644 tests/acpi-test-data/q35/APIC.cphp create mode 100644 tests/acpi-test-data/q35/DSDT.cphp create mode 100644 tests/acpi-test-data/q35/SRAT.cphp
Signature · 1 line
1.8.3.1
PATCH 4/33 pc: acpi: remove AML for empty/not used GPE handlers
ACPI spec requires GPE handlers only for GPE events that hardware implements.
So remove AML for not supported by QEMU device model events.
--- hw/i386/acpi-build.c | 17 ----------------- 1 file changed, 17 deletions(-)
hw/i386/acpi-build.c +0 -17
@@ -2051,8 +2051,6 @@ build_dsdt(GArray *table_data, GArray *linker, {aml_append (scope,aml_name_decl ("_HID" ,aml_string ("ACPI0006" ))); -aml_append (scope,aml_method ("_L00" ,0 ,AML_NOTSERIALIZED )); -if (misc->is_piix4) { method =aml_method ("_E01" ,0 ,AML_NOTSERIALIZED ); aml_append(method,
@@ -2060,8 +2058,6 @@ build_dsdt(GArray *table_data, GArray *linker,aml_append (method,aml_call0 ("\\_SB.PCI0.PCNT" ));aml_append (method,aml_release (aml_name ("\\_SB.PCI0.BLCK" )));aml_append (scope, method); - }else { -aml_append (scope,aml_method ("_L01" ,0 ,AML_NOTSERIALIZED )); } method =aml_method ("_E02" ,0 ,AML_NOTSERIALIZED );
@@ -2071,19 +2067,6 @@ build_dsdt(GArray *table_data, GArray *linker, method =aml_method ("_E03" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_call0 (MEMORY_HOTPLUG_HANDLER_PATH ));aml_append (scope, method); - -aml_append (scope,aml_method ("_L04" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L05" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L06" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L07" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L08" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L09" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0A" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0B" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0C" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0D" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0E" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0F" ,0 ,AML_NOTSERIALIZED )); }aml_append (dsdt, scope);
Signature · 1 line
1.8.3.1
PATCH 1/33 tests: acpi: report names of expected files in verbose mode
In reply to Igor Mammedovprint expected file name if it doesn't exists if verbose mode is enabled*. It helps to avoid running bios-tables-test under debugger to figure out missing file name.
*)
verbose mode is enabled if "V" env. variable is set
--- tests/bios-tables-test.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
tests/bios-tables-test.c +16 -8
@@ -464,7 +464,6 @@ static GArray *load_expected_aml(test_data *data) {int i;AcpiSdtTable *sdt; -gchar *aml_file =NULL ;GError *error =NULL ;gboolean ret;
@@ -472,7 +471,9 @@ static GArray *load_expected_aml(test_data *data)for (i =0 ; i < data->tables->len; ++i) {AcpiSdtTable exp_sdt;uint32_t signature; +gchar *aml_file =NULL ;const char *ext = data->variant ? data->variant :"" ; +int j; sdt = &g_array_index (data->tables, AcpiSdtTable, i);
@@ -481,16 +482,23 @@ static GArray *load_expected_aml(test_data *data) signature =cpu_to_le32 (sdt->header.signature); -try_again: - aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, - (gchar *)&signature, ext); -if (data->variant && !g_file_test (aml_file,G_FILE_TEST_EXISTS )) { +for (j =2 ; j; j -= data->variant ?1 :2 ) {g_free (aml_file); + aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, + (gchar *)&signature, ext); +if (g_file_test (aml_file,G_FILE_TEST_EXISTS )) { + exp_sdt.aml_file = aml_file; +break ; + } +if (getenv ("V" )) { +fprintf (stderr,"\nLooking for expected file '%s'\n" , aml_file); + } ext ="" ; - goto try_again; } - exp_sdt.aml_file = aml_file; -g_assert (g_file_test (aml_file,G_FILE_TEST_EXISTS )); +g_assert (exp_sdt.aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nUsing expected file '%s'\n" , aml_file); + } ret =g_file_get_contents (aml_file, &exp_sdt.aml, &exp_sdt.aml_len, &error);g_assert (ret);
Signature · 1 line
1.8.3.1
PATCH 2/33 acpi: add aml_debug()
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 9 +++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 10 insertions(+)
hw/acpi/aml-build.c +9 -0
@@ -406,6 +406,15 @@ Aml *aml_return(Aml *val)return var; } +/* ACPI 1.0b: 16.2.6.3 Debug Objects Encoding: DebugObj */ +Aml *aml_debug (void ) +{ +Aml *var =aml_alloc (); +build_append_byte (var->buf,0x5B );/* ExtOpPrefix */ +build_append_byte (var->buf,0x31 );/* DebugOp */ +return var; +} +/* * ACPI 1.0b: 16.2.3 Data Objects Encoding: * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
include/hw/acpi/aml-build.h +1 -0
@@ -252,6 +252,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* non block AML object primitives */ Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_name_decl (const char *name,Aml *val); +Aml *aml_debug (void );Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val);Aml *aml_arg (int pos);
Signature · 1 line
1.8.3.1
PATCH 3/33 acpi: add aml_refof()
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -1416,6 +1416,14 @@ Aml *aml_unicode(const char *str)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefRefOf */ +Aml *aml_refof (Aml *arg) +{ +Aml *var =aml_opcode (0x71 /* RefOfOp */ ); +aml_append (var, arg); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefDerefOf */ Aml *aml_derefof (Aml *arg) {
include/hw/acpi/aml-build.h +1 -0
@@ -359,6 +359,7 @@ Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name);Aml *aml_varpackage (uint32_t num_elements);Aml *aml_touuid (const char *uuid);Aml *aml_unicode (const char *str); +Aml *aml_refof (Aml *arg);Aml *aml_derefof (Aml *arg);Aml *aml_sizeof (Aml *arg);Aml *aml_concatenate (Aml *source1,Aml *source2,Aml *target);
Signature · 1 line
1.8.3.1
PATCH 5/33 pc: acpi: consolidate CPU hotplug AML
In reply to Igor Mammedovmove the former SSDT part of CPU hoplug close to DSDT part. AML is only moved but there isn't any functional change.
--- hw/acpi/cpu_hotplug_acpi_table.c | 104 +++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 112 +-------------------------------------- include/hw/acpi/cpu_hotplug.h | 3 +- 3 files changed, 106 insertions(+), 113 deletions(-)
hw/acpi/cpu_hotplug_acpi_table.c +103 -1
@@ -15,12 +15,19 @@#include "qemu/osdep.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/i386/pc.h" -void build_cpu_hotplug_aml (Aml *ctx) +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) { +Aml *dev; +Aml *crs; +Aml *pkg; +Aml *field;Aml *method;Aml *if_ctx;Aml *else_ctx; +int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 };Aml *cpu_id =aml_arg (0 );
@@ -29,6 +36,9 @@ void build_cpu_hotplug_aml(Aml *ctx)Aml *cpus_map =aml_name (CPU_ON_BITMAP );Aml *zero =aml_int (0 );Aml *one =aml_int (1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); +PCMachineState *pcms =PC_MACHINE (machine);/* * _MAT method - creates an madt apic buffer
@@ -132,5 +142,97 @@ void build_cpu_hotplug_aml(Aml *ctx) }aml_append (sb_scope, method); +/* The current AML generator can cover the APIC ID range [0..255], +* inclusive, for VCPU hotplug. */ +QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); +g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); + +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); + +/* build Processor object for each processor */ +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); + + dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + + method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_arg (0 ))) + ); +aml_append (dev, method); + +aml_append (sb_scope, dev); + } + +/* build this code: +* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} +*/ +/* Arg0 = Processor ID = APIC ID */ + method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); +aml_append (if_ctx, +aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) + ); +aml_append (method, if_ctx); + } +aml_append (sb_scope, method); + +/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" +* +* Note: The ability to create variable-sized packages was first +* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages +* ith up to 255 elements. Windows guests up to win2k8 fail when +* VarPackageOp is used. +*/ + pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : +aml_varpackage (pcms->apic_id_limit); + +for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +for (; apic_idx < apic_id; apic_idx++) { +aml_append (pkg,aml_int (0 )); + } +aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); + apic_idx = apic_id +1 ; + } +aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); +g_free (apic_ids); +aml_append (ctx, sb_scope); }
hw/i386/acpi-build.c +1 -111
130 lines not on this page · raw message
include/hw/acpi/cpu_hotplug.h +2 -1
@@ -34,5 +34,6 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,#define CPU_STATUS_MAP "PRS"#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx); +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len);#endif
Signature · 1 line
1.8.3.1
PATCH 6/33 pc: acpi: consolidate \GPE._E02 with the rest of CPU hotplug AML
In reply to Igor Mammedov--- hw/acpi/cpu_hotplug_acpi_table.c | 4 ++++ hw/i386/acpi-build.c | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-)
hw/acpi/cpu_hotplug_acpi_table.c +4 -0
@@ -235,4 +235,8 @@ void build_cpu_hotplug_aml(Aml *ctx, MachineState *machine,g_free (apic_ids);aml_append (ctx, sb_scope); + + method =aml_method ("\\_GPE._E02" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB." CPU_SCAN_METHOD )); +aml_append (ctx, method); }
hw/i386/acpi-build.c +0 -4
@@ -1952,10 +1952,6 @@ build_dsdt(GArray *table_data, GArray *linker,aml_append (scope, method); } - method =aml_method ("_E02" ,0 ,AML_NOTSERIALIZED ); -aml_append (method,aml_call0 ("\\_SB." CPU_SCAN_METHOD )); -aml_append (scope, method); - method =aml_method ("_E03" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_call0 (MEMORY_HOTPLUG_HANDLER_PATH ));aml_append (scope, method);
Signature · 1 line
1.8.3.1
PATCH 7/33 pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c
In reply to Igor Mammedovnow as those defines are used only locally inside of cpu_hotplug_acpi_table.c, move them out of header file.
--- hw/acpi/cpu_hotplug_acpi_table.c | 7 +++++++ include/hw/acpi/cpu_hotplug.h | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-)
hw/acpi/cpu_hotplug_acpi_table.c +7 -0
@@ -17,6 +17,13 @@#include "hw/acpi/cpu_hotplug.h" #include "hw/i386/pc.h" +#define CPU_EJECT_METHOD "CPEJ" +#define CPU_MAT_METHOD "CPMA" +#define CPU_ON_BITMAP "CPON" +#define CPU_STATUS_METHOD "CPST" +#define CPU_STATUS_MAP "PRS" +#define CPU_SCAN_METHOD "PRSC" +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine,uint16_t io_base,uint16_t io_len) {
include/hw/acpi/cpu_hotplug.h +0 -7
@@ -27,13 +27,6 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,void acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner,AcpiCpuHotplug *gpe_cpu,uint16_t base); -#define CPU_EJECT_METHOD "CPEJ" -#define CPU_MAT_METHOD "CPMA" -#define CPU_ON_BITMAP "CPON" -#define CPU_STATUS_METHOD "CPST" -#define CPU_STATUS_MAP "PRS" -#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine,uint16_t io_base,uint16_t io_len);#endif
Signature · 1 line
1.8.3.1
PATCH 10/33 pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature
In reply to Igor Mammedovsince IO block used by CPU hotplug is fixed size and initialized it the same file as build_legacy_cpu_hotplug_aml() just use ACPI_GPE_PROC_LEN directly instead of passing it around in several files.
--- hw/acpi/cpu_hotplug.c | 6 +++--- hw/i386/acpi-build.c | 5 +---- include/hw/acpi/cpu_hotplug.h | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-)
hw/acpi/cpu_hotplug.c +3 -3
@@ -87,7 +87,7 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, }void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len) +uint16_t io_base) {Aml *dev;Aml *crs;
@@ -226,13 +226,13 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); crs =aml_resource_template ();aml_append (crs, -aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) +aml_io (AML_DECODE16 , io_base, io_base,1 ,ACPI_GPE_PROC_LEN ) );aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (sb_scope, dev);/* declare CPU hotplug MMIO region and PRS field to access it */ aml_append (sb_scope,aml_operation_region ( -"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base),ACPI_GPE_PROC_LEN )); field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE );aml_append (field,aml_named_field ("PRS" ,256 ));aml_append (sb_scope, field);
hw/i386/acpi-build.c +1 -4
@@ -94,7 +94,6 @@ typedef struct AcpiPmInfo {uint32_t gpe0_blk_len;uint32_t io_base;uint16_t cpu_hp_io_base; -uint16_t cpu_hp_io_len;uint16_t mem_hp_io_base;uint16_t mem_hp_io_len;uint16_t pcihp_io_base;
@@ -142,7 +141,6 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) }assert (obj); - pm->cpu_hp_io_len =ACPI_GPE_PROC_LEN ; pm->mem_hp_io_base =ACPI_MEMORY_HOTPLUG_BASE ; pm->mem_hp_io_len =ACPI_MEMORY_HOTPLUG_IO_LEN ;
@@ -1935,8 +1933,7 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, - pm->cpu_hp_io_len); +build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);
include/hw/acpi/cpu_hotplug.h +1 -1
@@ -28,5 +28,5 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, AcpiCpuHotplug *gpe_cpu, uint16_t base);void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len); +uint16_t io_base);#endif
Signature · 1 line
1.8.3.1
PATCH 8/33 pc: acpi: mark current CPU hotplug functions as legacy
In reply to Igor Mammedov--- hw/acpi/cpu_hotplug.c | 8 ++++---- hw/acpi/cpu_hotplug_acpi_table.c | 4 ++-- hw/acpi/ich9.c | 7 ++++--- hw/acpi/piix4.c | 6 +++--- hw/i386/acpi-build.c | 3 ++- include/hw/acpi/cpu_hotplug.h | 12 ++++++------ 6 files changed, 21 insertions(+), 19 deletions(-)
hw/acpi/cpu_hotplug.c +4 -4
@@ -54,8 +54,8 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); } -void acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, -AcpiCpuHotplug *g,DeviceState *dev,Error **errp) +void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {
@@ -65,8 +65,8 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,acpi_send_gpe_event (ar, irq,ACPI_CPU_HOTPLUG_STATUS ); } -void acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, -AcpiCpuHotplug *gpe_cpu,uint16_t base) +void legacy_acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, +AcpiCpuHotplug *gpe_cpu,uint16_t base) {CPUState *cpu;
hw/acpi/cpu_hotplug_acpi_table.c +2 -2
@@ -24,8 +24,8 @@#define CPU_STATUS_MAP "PRS"#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len) +void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) {Aml *dev;Aml *crs;
hw/acpi/ich9.c +4 -3
@@ -273,8 +273,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, pm->powerdown_notifier.notify = pm_powerdown_req;qemu_register_powerdown_notifier (&pm->powerdown_notifier); -acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), - &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), +OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE );if (pm->acpi_memory_hotplug.is_enabled) { acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
@@ -437,7 +437,8 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)acpi_memory_plug_cb (&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, &pm->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, + &pm->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
hw/acpi/piix4.c +3 -3
@@ -352,7 +352,7 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,acpi_pcihp_device_plug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -570,8 +570,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,acpi_pcihp_init (OBJECT (s), &s->acpi_pci_hotplug, bus, parent, s->use_acpi_pci_hotplug); -acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, -PIIX4_CPU_HOTPLUG_IO_BASE ); +legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, +PIIX4_CPU_HOTPLUG_IO_BASE );if (s->acpi_memory_hotplug.is_enabled) {acpi_memory_hotplug_init (parent,OBJECT (s), &s->acpi_memory_hotplug);
hw/i386/acpi-build.c +2 -1
@@ -1935,7 +1935,8 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, pm->cpu_hp_io_len); +build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, + pm->cpu_hp_io_len);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);
include/hw/acpi/cpu_hotplug.h +6 -6
@@ -21,12 +21,12 @@ typedef struct AcpiCpuHotplug { uint8_t sts[ACPI_GPE_PROC_LEN]; } AcpiCpuHotplug; -void acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, -AcpiCpuHotplug *g,DeviceState *dev,Error **errp); +void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +AcpiCpuHotplug *g,DeviceState *dev,Error **errp); -void acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, -AcpiCpuHotplug *gpe_cpu,uint16_t base); +void legacy_acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, +AcpiCpuHotplug *gpe_cpu,uint16_t base); -void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len); +void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len);#endif
Signature · 1 line
1.8.3.1
PATCH 12/33 tests: acpi: update tables with consolidated legacy cpu-hotplug AML
In reply to Igor Mammedov--- tests/acpi-test-data/pc/DSDT | Bin 5587 -> 5503 bytes tests/acpi-test-data/pc/DSDT.bridge | Bin 7446 -> 7362 bytes tests/acpi-test-data/q35/DSDT | Bin 8357 -> 8265 bytes tests/acpi-test-data/q35/DSDT.bridge | Bin 8374 -> 8282 bytes 4 files changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/pc/DSDT binary +0 -0
tests/acpi-test-data/pc/DSDT.bridge binary +0 -0
tests/acpi-test-data/q35/DSDT binary +0 -0
tests/acpi-test-data/q35/DSDT.bridge binary +0 -0
Signature · 1 line
1.8.3.1
PATCH 9/33 pc: acpi: consolidate legacy CPU hotplug in one file
In reply to Igor MammedovSince AML part of CPU hotplug is tightly coupled with its hardware part (IO port layout/protocol), move build_legacy_cpu_hotplug_aml() to cpu_hotplug.c and remove empty cpu_hotplug_acpi_table.c
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/cpu_hotplug.c | 232 ++++++++++++++++++++++++++++++++++++ hw/acpi/cpu_hotplug_acpi_table.c | 249 --------------------------------------- 3 files changed, 233 insertions(+), 250 deletions(-) delete mode 100644 hw/acpi/cpu_hotplug_acpi_table.c
hw/acpi/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o -common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o cpu_hotplug_acpi_table.o +common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.o obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/cpu_hotplug.c +232 -0
241 lines not on this page · raw message
hw/acpi/cpu_hotplug_acpi_table.c deleted +0 -249
249 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 11/33 pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx
In reply to Igor MammedovIn legacy cpu-hotplug ProcessorID == APIC ID is used in MADT and cpu-hotplug AML. It was fine as both are 8bit and unique. Spec depricated Processor() with corresponding ProcessorID and advises to use Device() and UID instead of it.
However UID is just 32bit and it can't fit ARM's arch_id(MPIDR) which is 64bit. Also in case of sparse arch_id() distribution, managment/lookup of maps by arch_id(APIC ID/MPIDR) becomes complex and expensive.
In preparation to common CPU hotplug with ARM and to simplify lookup in possible_cpus[] map switch ProcessorID to possible_cpus index in MADT.
Legacy cpu-hotplug considerations:
HW interface of it is APIC ID based bitmask so it's impossible to change, also CPON package in AML also APIC ID based as well all the methods.
To avoid massive rewrite of AML keep is so and just break assumption that ProcessorID == APIC ID, ammending CPU_MAT_METHOD to accept APIC ID and possible_cpus index, it needs them both to patch MADT entry template. Also switch to possible_cpus index Processor(ProcessorID) AML.
That way changes to MADT/AML are minimal and kept inside AML/MADT not affecting external interfaces.
--- hw/acpi/cpu_hotplug.c | 23 +++++++++++++---------- hw/i386/acpi-build.c | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)
hw/acpi/cpu_hotplug.c +13 -10
@@ -99,7 +99,8 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 }; -Aml *cpu_id =aml_arg (0 ); +Aml *cpu_id =aml_arg (1 ); +Aml *apic_id =aml_arg (0 );Aml *cpu_on =aml_local (0 );Aml *madt =aml_local (1 );Aml *cpus_map =aml_name (CPU_ON_BITMAP );
@@ -111,30 +112,31 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* * _MAT method - creates an madt apic buffer -* cpu_id = Arg0 = Processor ID = Local APIC ID +* apic_id = Arg0 = Local APIC ID +* cpu_id = Arg1 = Processor ID * cpu_on = Local0 = CPON flag for this cpu * madt = Local1 = Buffer (in madt apic form) to return */ - method =aml_method (CPU_MAT_METHOD ,1 ,AML_NOTSERIALIZED ); + method =aml_method (CPU_MAT_METHOD ,2 ,AML_NOTSERIALIZED );aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); +aml_store (aml_derefof (aml_index (cpus_map, apic_id)), cpu_on));aml_append (method,aml_store (aml_buffer (sizeof (madt_tmpl), madt_tmpl), madt));/* Update the processor id, lapic id, and enable/disable status */ aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (2 )))); -aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (3 )))); +aml_append (method,aml_store (apic_id,aml_index (madt,aml_int (3 ))));aml_append (method,aml_store (cpu_on,aml_index (madt,aml_int (4 ))));aml_append (method,aml_return (madt));aml_append (sb_scope, method);/* * _STA method - return ON status of cpu -* cpu_id = Arg0 = Processor ID = Local APIC ID +* apic_id = Arg0 = Local APIC ID * cpu_on = Local0 = CPON flag for this cpu */ method =aml_method (CPU_STATUS_METHOD ,1 ,AML_NOTSERIALIZED );aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); +aml_store (aml_derefof (aml_index (cpus_map, apic_id)), cpu_on)); if_ctx =aml_if (cpu_on); {aml_append (if_ctx,aml_return (aml_int (0xF )));
@@ -243,11 +245,12 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + dev =aml_processor (i,0 ,0 ,"CP%.02X" , apic_id); method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_return (aml_call2 (CPU_MAT_METHOD ,aml_int (apic_id),aml_int (i)) + ));aml_append (dev, method); method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED );
@@ -268,7 +271,7 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* build this code: * Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} */ -/* Arg0 = Processor ID = APIC ID */ +/* Arg0 = APIC ID */ method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED );for (i =0 ; i < apic_ids->len; i++) {int apic_id = apic_ids->cpus[i].arch_id;
hw/i386/acpi-build.c +1 -1
@@ -354,7 +354,7 @@ build_madt(GArray *table_data, GArray *linker, PCMachineState *pcms) apic->type =ACPI_APIC_PROCESSOR ; apic->length =sizeof (*apic); - apic->processor_id = apic_id; + apic->processor_id = i; apic->local_apic_id = apic_id;if (apic_ids->cpus[i].cpu !=NULL ) { apic->flags =cpu_to_le32 (1 );
Signature · 1 line
1.8.3.1
PATCH 13/33 acpi: extend ACPI interface to provide send_event hook
In reply to Igor Mammedovsend_event() hook will allow to send ACPI event in a target specific way (GPE or GPIO based impl.) it will also simplify proxy wrappers in piix4pm/ich9 that access ACPI regs and SCI which are part of piix4pm/lcp_ich9 devices and call acpi_foo() API directly.
---
Following patch will use hook to simplify hotplug callbacks in piix4pm/ich9.
--- hw/acpi/core.c | 2 +- hw/acpi/piix4.c | 8 ++++++++ hw/isa/lpc_ich9.c | 8 ++++++++ include/hw/acpi/acpi.h | 10 ++-------- include/hw/acpi/acpi_dev_interface.h | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 9 deletions(-)
hw/acpi/core.c +1 -1
@@ -692,7 +692,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) }void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status) +AcpiEventStatusBits status) { ar->gpe.sts[0 ] |= status;acpi_update_sci (ar, irq);
hw/acpi/piix4.c +8 -0
@@ -585,6 +585,13 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); } +static void piix4_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +PIIX4PMState *s =PIIX4_PM (adev); + +acpi_send_gpe_event (&s->ar, s->irq, ev); +} +static Property piix4_pm_properties[] = {DEFINE_PROP_UINT32 ("smb_io_base" , PIIX4PMState, smb_io_base,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),
@@ -623,6 +630,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug_request = piix4_device_unplug_request_cb; hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; + adevc->send_event = piix4_send_gpe; }static const TypeInfo piix4_pm_info = {
hw/isa/lpc_ich9.c +8 -0
@@ -702,6 +702,13 @@ static Property ich9_lpc_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void ich9_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (adev); + +acpi_send_gpe_event (&s->pm.acpi_regs, s->pm.irq, ev); +} +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -729,6 +736,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug_request = ich9_device_unplug_request_cb; hc->unplug = ich9_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; + adevc->send_event = ich9_send_gpe; }static const TypeInfo ich9_lpc_info = {
include/hw/acpi/acpi.h +2 -8
@@ -23,6 +23,7 @@#include "qemu/option.h" #include "exec/memory.h" #include "hw/irq.h" +#include "hw/acpi/acpi_dev_interface.h" /* * current device naming scheme supports up to 256 memory devices
@@ -89,13 +90,6 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 -/* These values are part of guest ABI, and can not be changed */ -typedef enum { -ACPI_PCI_HOTPLUG_STATUS =2 , -ACPI_CPU_HOTPLUG_STATUS =4 , -ACPI_MEMORY_HOTPLUG_STATUS =8 , -}AcpiGPEStatusBits ; -/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;
@@ -179,7 +173,7 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr);void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status); +AcpiEventStatusBits status);void acpi_update_sci (ACPIREGS *acpi_regs,qemu_irq irq);
include/hw/acpi/acpi_dev_interface.h +18 -0
@@ -4,6 +4,13 @@#include "qom/object.h" #include "qapi-types.h" +/* These values are part of guest ABI, and can not be changed */ +typedef enum { +ACPI_PCI_HOTPLUG_STATUS =2 , +ACPI_CPU_HOTPLUG_STATUS =4 , +ACPI_MEMORY_HOTPLUG_STATUS =8 , +}AcpiEventStatusBits ; +#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"#define ACPI_DEVICE_IF_CLASS (klass) \
@@ -22,11 +29,21 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf; +#define ACPI_SEND_EVENT (dev, event) \ + do { \ + AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(dev); \ + if (adevc->send_event) { \ + AcpiDeviceIf *adev = ACPI_DEVICE_IF(dev); \ + adevc->send_event(adev, event); \ + } \ + } while (0) +/** * AcpiDeviceIfClass: * * ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. +* send_event: inject a specified event into guest * * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without
@@ -39,5 +56,6 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); } AcpiDeviceIfClass;#endif
Signature · 1 line
1.8.3.1
PATCH 16/33 acpi: hardware side of CPU hotplug
In reply to Igor Mammedov---
v1:
- drop CPUHotplugState.is_enabled field
--- hw/acpi/Makefile.objs | 1 + hw/acpi/cpu.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/cpu.h | 52 +++++++++++++ trace-events | 9 +++ 4 files changed, 268 insertions(+) create mode 100644 hw/acpi/cpu.c create mode 100644 include/hw/acpi/cpu.h
hw/acpi/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.o +common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI) += acpi_interface.o common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
hw/acpi/cpu.c new file +206 -0
206 lines not on this page · raw message
include/hw/acpi/cpu.h new file +52 -0
52 lines not on this page · raw message
trace-events +9 -0
@@ -1908,3 +1908,12 @@ aspeed_vic_update_fiq(int flags) "Raising FIQ: %d" aspeed_vic_update_irq(int flags) "Raising IRQ: %d" aspeed_vic_read(uint64_t offset, unsigned size, uint32_t value) "From 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 + +# hw/acpi/cpu.c +cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32 +cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8 +cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]" +cpuhp_acpi_clear_remove_evt(uint32_t idx) "idx[0x%"PRIx32"]" +cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32 +cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32 +cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32
Signature · 1 line
1.8.3.1
PATCH 15/33 docs: update ACPI CPU hotplug spec with new protocol
In reply to Igor Mammedov--- docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 12 deletions(-)
docs/specs/acpi_cpu_hotplug.txt +76 -12
@@ -4,21 +4,85 @@ QEMU<->ACPI BIOS CPU hotplug interface QEMU supports CPU hotplug via ACPI. This document describes the interface between QEMU and the ACPI BIOS. -ACPI GPE block (IO ports 0xafe0-0xafe3, byte access): ------------------------------------------ - -Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU -hot-add/remove event to ACPI BIOS, via SCI interrupt. +ACPI BIOS GPE.2 handler is dedicated for notifying OS about CPU hot-add +and hot-remove events. +============================================ +Legacy ACPI CPU hotplug interface registers: +-------------------------------------------- CPU present bitmap for: + One bit per CPU. Bit position reflects corresponding CPU APIC ID. Read-only. ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access) PIIX-PM (IO port 0xaf00-0xaf1f, 1-byte access) --------------------------------------------------------------- -One bit per CPU. Bit position reflects corresponding CPU APIC ID. -Read-only. +QEMU sets corresponding CPU bit on hot-add event and issues SCI +with GPE.2 event set. CPU present map read by ACPI BIOS GPE.2 handler +to notify OS about CPU hot-add events. CPU hot-remove isn't supported. + +===================================== +ACPI CPU hotplug interface registers: +------------------------------------- +Register block base address: + ICH9-LPC IO port 0x0cd8 + PIIX-PM IO port 0xaf00 +Register block size: + ACPI_CPU_HOTPLUG_REG_LEN = 12 + +read access: + offset: + [0x0-0x3] reserved + [0x4] CPU device status fields: (1 byte access) + bits: + 0: Device is enabled and may be used by guest + 1: Device insert event, used to distinguish device for which + no device check event to OSPM was issued. + It's valid only when bit 0 is set. + 2: Device remove event, used to distinguish device for which + no device eject request to OSPM was issued. + 3-7: reserved and should be ignored by OSPM + [0x5-0x7] reserved + [0x8] Command data: (DWORD access) + in case of error or unsupported command reads is 0xFFFFFFFF + current 'Command field' value: + 0: returns PXM value corresponding to device + +write access: + offset: + [0x0-0x3] CPU selector: (DWORD access) + selects active CPU device. All following accesses to other + registers will read/store data from/to selected CPU. + [0x4] CPU device control fields: (1 byte access) + bits: + 0: reserved, OSPM must clear it before writing to register. + 1: if set to 1 clears device insert event, set by OSPM + after it has emitted device check event for the + selected CPU device + 2: if set to 1 clears device remove event, set by OSPM + after it has emitted device eject request for the + selected CPU device + 3: if set to 1 initiates device eject, set by OSPM when it + triggers CPU device removal and calls _EJ0 method + 4-7: reserved, OSPM must clear them before writing to register + [0x5] Command field: (1 byte access) + value: + 0: following reads from 'Command data' register returns PXM + value of device + 1: following writes to 'Command data' register set OST event + register in QEMU + 2: following writes to 'Command data' register set OST status + register in QEMU + other values: reserved + [0x6-0x7] reserved + [0x8] Command data: (DWORD access) + current 'Command field' value: + 1: stores value into OST event register + 2: stores value into OST status register, triggers + ACPI_DEVICE_OST QMP event from QEMU to external applications + with current values of OST event and status registers. + other values: reserved -CPU hot-add/remove notification: ------------------------------------------------------ -QEMU sets/clears corresponding CPU bit on hot-add/remove event. -CPU present map read by ACPI BIOS GPE.2 handler to notify OS of CPU -hot-(un)plug events. +Selecting CPU device beyond possible range has no effect on platform: + - write accesses to CPU hot-plug registers not documented above are + ignored + - read accesses to CPU hot-plug registers not documented above return + all bits set to 1.
Signature · 1 line
1.8.3.1
PATCH 17/33 pc: add generic CPU unplug callbacks
In reply to Igor Mammedov--- hw/acpi/cpu.c | 1 + hw/i386/pc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
hw/acpi/cpu.c +1 -0
@@ -104,6 +104,7 @@ void cpu_hotplug_hw_init(MemoryRegion *as, Object *owner,CPUArchIdList *id_list;int i; +assert (mc->possible_cpu_arch_ids); id_list = mc->possible_cpu_arch_ids (machine); state->dev_count = id_list->len; state->devs =g_new0 (typeof (*state->devs), state->dev_count);
hw/i386/pc.c +47 -0
65 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 14/33 pc: use AcpiDeviceIfClass.send_event to issue GPE events
In reply to Igor Mammedovit reduces number of args passed in handlers by 1 and a number of used proxy wrappers saving ~20LOC. Also it allows to make cpu/mem hotplug code more universal as it would allow ARM to reuse it without rewrite by providing its own send_event callback to trigger events usiong GPIO instead of GPE as fixed hadrware ACPI model doen't have GPE at all.
--- hw/acpi/cpu_hotplug.c | 5 ++--- hw/acpi/ich9.c | 33 ++++++++++++++++++++------------- hw/acpi/memory_hotplug.c | 12 ++++-------- hw/acpi/pcihp.c | 10 ++++------ hw/acpi/piix4.c | 11 +++++------ hw/isa/lpc_ich9.c | 30 +++--------------------------- include/hw/acpi/cpu_hotplug.h | 3 ++- include/hw/acpi/ich9.h | 9 +++++---- include/hw/acpi/memory_hotplug.h | 4 ++-- include/hw/acpi/pcihp.h | 5 +++-- 10 files changed, 50 insertions(+), 72 deletions(-)
hw/acpi/cpu_hotplug.c +2 -3
@@ -62,15 +62,14 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); } -void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {return ; } - -acpi_send_gpe_event (ar, irq,ACPI_CPU_HOTPLUG_STATUS ); +ACPI_SEND_EVENT (hotplug_dev,ACPI_CPU_HOTPLUG_STATUS ); } void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
hw/acpi/ich9.c +20 -13
@@ -430,40 +430,47 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) NULL); } -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp) +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug, +acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, - &pm->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp) +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&pm->acpi_regs, pm->irq, - &pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_request_cb (hotplug_dev, + &lpc->pm.acpi_memory_hotplug, dev, + errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_cb (&pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
hw/acpi/memory_hotplug.c +4 -8
@@ -228,7 +228,7 @@ acpi_memory_slot_status(MemHotplugState *mem_st,return &mem_st->devs[slot]; } -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {MemStatus *mdev;
@@ -247,13 +247,11 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; - -/* do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +ACPI_SEND_EVENT (hotplug_dev,ACPI_MEMORY_HOTPLUG_STATUS ); } } -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {
@@ -265,9 +263,7 @@ void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq, } mdev->is_removing = true; - -/* Do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +ACPI_SEND_EVENT (hotplug_dev,ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,
hw/acpi/pcihp.c +4 -6
@@ -182,7 +182,7 @@ void acpi_pcihp_reset(AcpiPciHpState *s)acpi_pcihp_update (s); } -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);
@@ -202,11 +202,10 @@ void acpi_pcihp_device_plug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +ACPI_SEND_EVENT (hotplug_dev,ACPI_PCI_HOTPLUG_STATUS ); } -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);
@@ -219,8 +218,7 @@ void acpi_pcihp_device_unplug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +ACPI_SEND_EVENT (hotplug_dev,ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)
hw/acpi/piix4.c +5 -6
@@ -347,12 +347,11 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, dev, errp); +acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_plug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, - errp); +acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -366,10 +365,10 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, +acpi_memory_unplug_request_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_unplug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, +acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else { error_setg(errp, "acpi: device unplug request for not supported device"
hw/isa/lpc_ich9.c +3 -27
@@ -636,30 +636,6 @@ static void ich9_lpc_realize(PCIDevice *d, Error **errp) 1); } -static void ich9_device_plug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_plug_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_request_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_request_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_cb (&lpc->pm, dev, errp); -} -static bool ich9_rst_cnt_needed (void *opaque) {ICH9LPCState *lpc = opaque;
@@ -732,9 +708,9 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)* pc_q35_init() */ dc->cannot_instantiate_with_device_add_yet = true; - hc->plug = ich9_device_plug_cb; - hc->unplug_request = ich9_device_unplug_request_cb; - hc->unplug = ich9_device_unplug_cb; + hc->plug = ich9_pm_device_plug_cb; + hc->unplug_request = ich9_pm_device_unplug_request_cb; + hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; }
include/hw/acpi/cpu_hotplug.h +2 -1
@@ -15,13 +15,14 @@#include "hw/acpi/acpi.h" #include "hw/acpi/pc-hotplug.h" #include "hw/acpi/aml-build.h" +#include "hw/hotplug.h" typedef struct AcpiCpuHotplug {MemoryRegion io;uint8_t sts[ACPI_GPE_PROC_LEN ]; }AcpiCpuHotplug ; -void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp); void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
include/hw/acpi/ich9.h +5 -4
@@ -69,10 +69,11 @@ extern const VMStateDescription vmstate_ich9_pm;void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm,Error **errp); -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp); -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp); -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp); +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp); +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp);void ich9_pm_ospm_status (AcpiDeviceIf *adev,ACPIOSTInfoList ***list);
include/hw/acpi/memory_hotplug.h +2 -2
@@ -32,9 +32,9 @@ typedef struct MemHotplugState {void acpi_memory_hotplug_init (MemoryRegion *as,Object *owner,MemHotplugState *state); -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); void acpi_memory_unplug_cb(MemHotplugState *mem_st,
include/hw/acpi/pcihp.h +3 -2
@@ -29,6 +29,7 @@#include "hw/acpi/acpi.h" #include "migration/vmstate.h" +#include "hw/hotplug.h" #define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"#define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"
@@ -56,9 +57,9 @@ typedef struct AcpiPciHpState {void acpi_pcihp_init (Object *owner,AcpiPciHpState *,PCIBus *root,MemoryRegion *address_space_io,bool bridges_enabled); -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp); -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp);/* Called on reset */
Signature · 1 line
1.8.3.1
PATCH 20/33 pc: q35: initialize new CPU hotplug hw
In reply to Igor Mammedovadd necessary wiring to init new CPU hotplug hardware if ICH9-LPC.cpu-hotplug-legacy is "off".
Set ICH9-LPC.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.
---
v1:
- drop ICH9-LPC.cpu-hotplug property
--- hw/acpi/ich9.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/acpi/ich9.h | 6 +++++- include/hw/compat.h | 6 +++++- 3 files changed, 47 insertions(+), 7 deletions(-)
hw/acpi/ich9.c +37 -5
@@ -170,6 +170,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="ich9_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, ICH9LPCPMRegs), +VMSTATE_END_OF_LIST () + } +}; +static bool vmstate_test_use_tco (void *opaque) {ICH9LPCPMRegs *s = opaque;
@@ -209,6 +227,7 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, &vmstate_tco_io_state, + &vmstate_cpuhp_state,NULL } };
@@ -275,7 +294,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,if (pm->cpu_hotplug_legacy) {legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +OBJECT (lpc_pci), &pm->cpuhp.legacy,ICH9_CPU_HOTPLUG_IO_BASE ); + }else { +cpu_hotplug_hw_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), + &pm->cpuhp.state,ICH9_CPU_HOTPLUG_IO_BASE ); }if (pm->acpi_memory_hotplug.is_enabled) {
@@ -414,7 +436,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; - pm->cpu_hotplug_legacy = true; pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;
@@ -461,9 +482,13 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (lpc->pm.cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { +if (lpc->pm.cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.legacy, dev, + errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.state, dev, errp); + } } else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -480,6 +505,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp.state, + dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -494,6 +523,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&lpc->pm.cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
include/hw/acpi/ich9.h +5 -1
@@ -23,6 +23,7 @@#include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h"
@@ -49,7 +50,10 @@ typedef struct ICH9LPCPMRegs {Notifier powerdown_notifier;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug;
include/hw/compat.h +5 -1
@@ -2,7 +2,11 @@#define HW_COMPAT_H #define HW_COMPAT_2_6 \ -/* empty */ + {\ + .driver = "ICH9-LPC",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Signature · 1 line
1.8.3.1
PATCH 18/33 pc: add 2.7 machine
In reply to Igor Mammedov--- hw/i386/pc_piix.c | 16 +++++++++++++--- hw/i386/pc_q35.c | 13 +++++++++++-- include/hw/compat.h | 3 +++ include/hw/i386/pc.h | 4 ++++ 4 files changed, 31 insertions(+), 5 deletions(-)
hw/i386/pc_piix.c +13 -3
@@ -416,13 +416,25 @@ static void pc_i440fx_machine_options(MachineClass *m) m->default_display ="std" ; } -static void pc_i440fx_2_6_machine_options (MachineClass *m) +static void pc_i440fx_2_7_machine_options (MachineClass *m) {pc_i440fx_machine_options (m); m->alias ="pc" ; m->is_default =1 ; } +DEFINE_I440FX_MACHINE (v2_7,"pc-i440fx-2.7" ,NULL , + pc_i440fx_2_7_machine_options); + + +static void pc_i440fx_2_6_machine_options (MachineClass *m) +{ +pc_i440fx_2_7_machine_options (m); + m->is_default =0 ; + m->alias =NULL ; +SET_MACHINE_COMPAT (m,PC_COMPAT_2_6 ); +} +DEFINE_I440FX_MACHINE (v2_6,"pc-i440fx-2.6" ,NULL , pc_i440fx_2_6_machine_options);
@@ -431,8 +443,6 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_2_6_machine_options (m); - m->alias =NULL ; - m->is_default =0 ; pcmc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 );
hw/i386/pc_q35.c +11 -2
@@ -283,12 +283,22 @@ static void pc_q35_machine_options(MachineClass *m) m->no_floppy =1 ; } -static void pc_q35_2_6_machine_options (MachineClass *m) +static void pc_q35_2_7_machine_options (MachineClass *m) {pc_q35_machine_options (m); m->alias ="q35" ; } +DEFINE_Q35_MACHINE (v2_7,"pc-q35-2.7" ,NULL , + pc_q35_2_7_machine_options); + +static void pc_q35_2_6_machine_options (MachineClass *m) +{ +pc_q35_2_7_machine_options (m); + m->alias =NULL ; +SET_MACHINE_COMPAT (m,PC_COMPAT_2_6 ); +} +DEFINE_Q35_MACHINE (v2_6,"pc-q35-2.6" ,NULL , pc_q35_2_6_machine_options);
@@ -296,7 +306,6 @@ static void pc_q35_2_5_machine_options(MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_2_6_machine_options (m); - m->alias =NULL ; pcmc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 );
include/hw/compat.h +3 -0
@@ -1,6 +1,9 @@#ifndef HW_COMPAT_H #define HW_COMPAT_H +#define HW_COMPAT_2_6 \ +/* empty */ +#define HW_COMPAT_2_5 \ {\ .driver = "isa-fdc",\
include/hw/i386/pc.h +4 -0
@@ -356,7 +356,11 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);int e820_get_num_entries (void );bool e820_get_entry (int ,uint32_t ,uint64_t *,uint64_t *); +#define PC_COMPAT_2_6 \ + HW_COMPAT_2_6 +#define PC_COMPAT_2_5 \ + PC_COMPAT_2_6 \ HW_COMPAT_2_5#define PC_COMPAT_2_4 \
Signature · 1 line
1.8.3.1
PATCH 21/33 pc: piix4: initialize new CPU hotplug hw
In reply to Igor Mammedovadd necessary wiring to init new CPU hotplug hardware if PIIX4_PM.cpu-hotplug-legacy is "off".
Set PIIX4_PM.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.
v1:
- drop PIIX4_PM.cpu-hotplug property
--- hw/acpi/piix4.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++------ include/hw/compat.h | 5 +++++ 2 files changed, 54 insertions(+), 6 deletions(-)
hw/acpi/piix4.c +49 -6
@@ -34,6 +34,7 @@#include "hw/acpi/piix4.h" #include "hw/acpi/pcihp.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/hotplug.h" #include "hw/mem/pc-dimm.h" #include "hw/acpi/memory_hotplug.h"
@@ -86,7 +87,10 @@ typedef struct PIIX4PMState {uint8_t s4_val;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug; } PIIX4PMState;
@@ -273,6 +277,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +PIIX4PMState *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="piix4_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, PIIX4PMState), +VMSTATE_END_OF_LIST () + } +}; +/* qemu-kvm 1.2 uses version 3 but advertised as 2 * To support incoming qemu-kvm 1.2 migration, change version_id * and minimum_version_id to 2 below (which breaks migration from
@@ -307,6 +329,7 @@ static const VMStateDescription vmstate_acpi = { }, .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, + &vmstate_cpuhp_state,NULL } };
@@ -351,9 +374,12 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); - }else if (s->cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +if (s->cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &s->cpuhp.legacy, dev, errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &s->cpuhp.state, dev, errp); + } }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -372,6 +398,9 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !s->cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &s->cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -386,6 +415,9 @@ static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&s->acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !s->cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&s->cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -572,8 +604,19 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, s->use_acpi_pci_hotplug);if (s->cpu_hotplug_legacy) { -legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, +legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->cpuhp.legacy,PIIX4_CPU_HOTPLUG_IO_BASE ); + }else { +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); + +/* piix4 is also used by MIPS target, so make sure that +user provides possible_cpu_arch_ids callback before +trying to initialize CPU hotplug +*/ +if (mc->possible_cpu_arch_ids) { +cpu_hotplug_hw_init (parent,OBJECT (s), &s->cpuhp.state, +PIIX4_CPU_HOTPLUG_IO_BASE ); + } }if (s->acpi_memory_hotplug.is_enabled) {
@@ -605,7 +648,7 @@ static Property piix4_pm_properties[] = {DEFINE_PROP_BOOL ("memory-hotplug-support" , PIIX4PMState, acpi_memory_hotplug.is_enabled, true),DEFINE_PROP_BOOL ("cpu-hotplug-legacy" , PIIX4PMState, - cpu_hotplug_legacy, true), + cpu_hotplug_legacy, false), DEFINE_PROP_END_OF_LIST(), };
include/hw/compat.h +5 -0
@@ -7,6 +7,11 @@ .property = "cpu-hotplug-legacy",\ .value = "on",\ },\ + {\ + .driver = "PIIX4_PM",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Signature · 1 line
1.8.3.1
PATCH 19/33 pc: piix4/ich9: add 'cpu-hotplug-legacy' property
In reply to Igor Mammedov--- hw/acpi/ich9.c | 29 ++++++++++++++++++++++++++--- hw/acpi/piix4.c | 12 +++++++++--- include/hw/acpi/ich9.h | 1 + 3 files changed, 36 insertions(+), 6 deletions(-)
hw/acpi/ich9.c +26 -3
@@ -273,8 +273,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, pm->powerdown_notifier.notify = pm_powerdown_req;qemu_register_powerdown_notifier (&pm->powerdown_notifier); -legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +if (pm->cpu_hotplug_legacy) { +legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), +OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); + }if (pm->acpi_memory_hotplug.is_enabled) { acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
@@ -306,6 +308,21 @@ static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value, s->pm.acpi_memory_hotplug.is_enabled = value; } +static bool ich9_pm_get_cpu_hotplug_legacy (Object *obj,Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); + +return s->pm.cpu_hotplug_legacy; +} + +static void ich9_pm_set_cpu_hotplug_legacy (Object *obj,bool value, +Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); + + s->pm.cpu_hotplug_legacy = value; +} +static void ich9_pm_get_disable_s3 (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -397,6 +414,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; + pm->cpu_hotplug_legacy = true; pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;
@@ -412,6 +430,10 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) ich9_pm_get_memory_hotplug_support, ich9_pm_set_memory_hotplug_support, NULL); +object_property_add_bool (obj,"cpu-hotplug-legacy" , + ich9_pm_get_cpu_hotplug_legacy, + ich9_pm_set_cpu_hotplug_legacy, +NULL ); object_property_add(obj, ACPI_PM_PROP_S3_DISABLED, "uint8", ich9_pm_get_disable_s3, ich9_pm_set_disable_s3,
@@ -439,7 +461,8 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + } else if (lpc->pm.cpu_hotplug_legacy && +object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) {legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); } else { error_setg(errp, "acpi: device plug request for not supported device"
hw/acpi/piix4.c +9 -3
@@ -85,6 +85,7 @@ typedef struct PIIX4PMState {uint8_t disable_s4;uint8_t s4_val; +bool cpu_hotplug_legacy;AcpiCpuHotplug gpe_cpu;MemHotplugState acpi_memory_hotplug;
@@ -350,7 +351,8 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); - }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { + }else if (s->cpu_hotplug_legacy && +object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); }else { error_setg(errp, "acpi: device plug request for not supported device"
@@ -569,8 +571,10 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,acpi_pcihp_init (OBJECT (s), &s->acpi_pci_hotplug, bus, parent, s->use_acpi_pci_hotplug); -legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, -PIIX4_CPU_HOTPLUG_IO_BASE ); +if (s->cpu_hotplug_legacy) { +legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, +PIIX4_CPU_HOTPLUG_IO_BASE ); + }if (s->acpi_memory_hotplug.is_enabled) {acpi_memory_hotplug_init (parent,OBJECT (s), &s->acpi_memory_hotplug);
@@ -600,6 +604,8 @@ static Property piix4_pm_properties[] = { use_acpi_pci_hotplug, true),DEFINE_PROP_BOOL ("memory-hotplug-support" , PIIX4PMState, acpi_memory_hotplug.is_enabled, true), +DEFINE_PROP_BOOL ("cpu-hotplug-legacy" , PIIX4PMState, + cpu_hotplug_legacy, true), DEFINE_PROP_END_OF_LIST(), };
include/hw/acpi/ich9.h +1 -0
@@ -48,6 +48,7 @@ typedef struct ICH9LPCPMRegs {uint32_t pm_io_base;Notifier powerdown_notifier; +bool cpu_hotplug_legacy;AcpiCpuHotplug gpe_cpu;MemHotplugState acpi_memory_hotplug;
Signature · 1 line
1.8.3.1
PATCH 22/33 pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
In reply to Igor MammedovAdd madt_cpu callback to AcpiDeviceIfClass and use it for generating LAPIC MADT entries for CPUs for x86 target. Later it will be used for generating x2APIC entries in case of more than 255 CPUs and also would be reused by ARM target when ACPI CPU hotplug is introduced there.
--- hw/acpi/piix4.c | 1 + hw/i386/acpi-build.c | 45 +++++++++++++++++++++--------------- hw/isa/lpc_ich9.c | 1 + include/hw/acpi/acpi_dev_interface.h | 7 ++++++ include/hw/i386/pc.h | 5 ++++ stubs/Makefile.objs | 1 + stubs/pc_madt_cpu_entry.c | 7 ++++++ 7 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 stubs/pc_madt_cpu_entry.c
hw/acpi/piix4.c +1 -0
@@ -679,6 +679,7 @@ 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 +27 -18
63 lines not on this page · raw message
hw/isa/lpc_ich9.c +1 -0
@@ -713,6 +713,7 @@ 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; }static const TypeInfo ich9_lpc_info = {
include/hw/acpi/acpi_dev_interface.h +7 -0
@@ -3,6 +3,7 @@#include "qom/object.h" #include "qapi-types.h" +#include "hw/boards.h" /* These values are part of guest ABI, and can not be changed */ typedef enum {
@@ -44,6 +45,10 @@ typedef struct AcpiDeviceIf {* ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. * send_event: inject a specified event into guest +* madt_cpu: fills @entry with Interrupt Controller Structure +* for CPU indexed by @uid in @apic_ids array, +* returned structure types are: +* 0 - Local APIC, 9 - Local x2APIC, 0xB - GICC * * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without
@@ -57,5 +62,7 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list);void (*send_event)(AcpiDeviceIf *adev,AcpiEventStatusBits ev); +void (*madt_cpu)(AcpiDeviceIf *adev,int uid, + CPUArchIdList *apic_ids, GArray *entry); } AcpiDeviceIfClass;#endif
include/hw/i386/pc.h +5 -0
@@ -17,6 +17,7 @@#include "hw/compat.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" +#include "hw/acpi/acpi_dev_interface.h" #define HPET_INTCAP "hpet-intcap"
@@ -345,6 +346,10 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,/* pvpanic.c */ uint16_t pvpanic_port (void ); +/* acpi-build.c */ +void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, +CPUArchIdList *apic_ids,GArray *entry); +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2
stubs/Makefile.objs +1 -0
@@ -41,3 +41,4 @@ stub-obj-y += target-monitor-defs.o stub-obj-y += target-get-monitor-def.o stub-obj-y += vhost.o stub-obj-y += iohandler.o +stub-obj-y += pc_madt_cpu_entry.o
stubs/pc_madt_cpu_entry.c new file +7 -0
@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" + +void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid, +CPUArchIdList *apic_ids,GArray *entry) +{ +}
Signature · 1 line
1.8.3.1
PATCH 24/33 acpi: add CPU hotplug methods to DSDT
In reply to Igor MammedovAdd necessary CPU hotplug methods to handle hotplug events.
---
v1:
- make replace _MAT method with named buffer object as its content is static
--- hw/acpi/cpu.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 3 +- include/hw/acpi/cpu.h | 4 +- 3 files changed, 190 insertions(+), 4 deletions(-)
hw/acpi/cpu.c +185 -2
@@ -207,24 +207,178 @@ const VMStateDescription vmstate_cpu_hotplug = { };#define CPU_NAME_FMT "C%.03X" - -void build_cpus_aml (Aml *table,MachineState *machine,bool acpi1_compat) +#define CPUHP_RES_DEVICE "PRES" +#define CPU_LOCK "CPLK" +#define CPU_STS_METHOD "CSTA" +#define CPU_SCAN_METHOD "CSCN" +#define CPU_EJECT_METHOD "CEJ0" +#define CPU_NOTIFY_METHOD "CTFY" + +#define CPU_ENABLED "CPEN" +#define CPU_SELECTOR "CSEL" +#define CPU_EJECT_EVENT "CEJ0" +#define CPU_INSERT_EVENT "CINS" +#define CPU_REMOVE_EVENT "CRMV" + +void build_cpus_aml (Aml *table,MachineState *machine,bool acpi1_compat, +const char *res_root,const char *event_handler_method, +hwaddr io_base) { +Aml *ifctx; +Aml *field; +Aml *method; +Aml *cpu_ctrl_dev;Aml *cpus_dev; +Aml *zero =aml_int (0 );Aml *sb_scope =aml_scope ("_SB" );MachineClass *mc =MACHINE_GET_CLASS (machine);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); +AcpiDeviceIf *adev =ACPI_DEVICE_IF (obj); + + cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); + { +Aml *crs; + +aml_append (cpu_ctrl_dev, +aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (cpu_ctrl_dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" ))); +aml_append (cpu_ctrl_dev,aml_mutex (CPU_LOCK ,0 )); + + crs =aml_resource_template (); +aml_append (crs,aml_io (AML_DECODE16 , io_base, io_base,1 , +ACPI_CPU_HOTPLUG_REG_LEN )); +aml_append (cpu_ctrl_dev,aml_name_decl ("_CRS" , crs)); + +/* declare CPU hotplug MMIO region with related access fields */ +aml_append (cpu_ctrl_dev, +aml_operation_region ("PRST" ,AML_SYSTEM_IO ,aml_int (io_base), +ACPI_CPU_HOTPLUG_REG_LEN )); + + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK , +AML_WRITE_AS_ZEROS ); +aml_append (field,aml_reserved_field (ACPI_CPU_FLAGS_OFFSET_RW *8 )); +/* 1 if enabled, read only */ +aml_append (field,aml_named_field (CPU_ENABLED ,1 )); +/* (read) 1 if has a insert event. (write) 1 to clear event */ +aml_append (field,aml_named_field (CPU_INSERT_EVENT ,1 )); +/* (read) 1 if has a remove event. (write) 1 to clear event */ +aml_append (field,aml_named_field (CPU_REMOVE_EVENT ,1 )); +/* initiates device eject, write only */ +aml_append (field,aml_named_field (CPU_EJECT_EVENT ,1 )); +aml_append (cpu_ctrl_dev, field); + + field =aml_field ("PRST" ,AML_DWORD_ACC ,AML_NOLOCK ,AML_PRESERVE ); +/* CPU selector, write only */ +aml_append (field,aml_named_field (CPU_SELECTOR ,32 )); +aml_append (cpu_ctrl_dev, field); + + } +aml_append (sb_scope, cpu_ctrl_dev); + cpus_dev =aml_device ("\\_SB.CPUS" ); {int i; +Aml *one =aml_int (1 ); +Aml *cpu_selector =aml_name ("%s.%s" , cphp_res_path,CPU_SELECTOR ); +Aml *ins_evt =aml_name ("%s.%s" , cphp_res_path,CPU_INSERT_EVENT ); +Aml *rm_evt =aml_name ("%s.%s" , cphp_res_path,CPU_REMOVE_EVENT ); +Aml *ej_evt =aml_name ("%s.%s" , cphp_res_path,CPU_EJECT_EVENT ); +Aml *is_enabled =aml_name ("%s.%s" , cphp_res_path,CPU_ENABLED ); +Aml *ctrl_lock =aml_name ("%s.%s" , cphp_res_path,CPU_LOCK );aml_append (cpus_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0010" )));aml_append (cpus_dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A05" ))); + method =aml_method (CPU_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < arch_ids->len; i++) { +Aml *cpu =aml_name (CPU_NAME_FMT , i); +Aml *uid =aml_arg (0 ); +Aml *event =aml_arg (1 ); + + ifctx =aml_if (aml_equal (uid,aml_int (i))); + { +aml_append (ifctx,aml_notify (cpu, event)); + } +aml_append (method, ifctx); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_STS_METHOD ,1 ,AML_SERIALIZED ); + { +Aml *idx =aml_arg (0 ); +Aml *sta =aml_local (0 ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (idx, cpu_selector)); +aml_append (method,aml_store (zero, sta)); + ifctx =aml_if (aml_equal (is_enabled, one)); + { +aml_append (ifctx,aml_store (aml_int (0xF ), sta)); + } +aml_append (method, ifctx); +aml_append (method,aml_release (ctrl_lock)); +aml_append (method,aml_return (sta)); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_EJECT_METHOD ,1 ,AML_SERIALIZED ); + { +Aml *idx =aml_arg (0 ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (idx, cpu_selector)); +aml_append (method,aml_store (one, ej_evt)); +aml_append (method,aml_release (ctrl_lock)); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_SCAN_METHOD ,0 ,AML_SERIALIZED ); + { +Aml *else_ctx; +Aml *while_ctx; +Aml *idx =aml_local (0 ); +Aml *eject_req =aml_int (3 ); +Aml *dev_chk =aml_int (1 ); +Aml *cpus_count =aml_int (arch_ids->len); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (zero, idx)); + while_ctx =aml_while (aml_lless (idx, cpus_count)); + { +aml_append (while_ctx,aml_store (idx, cpu_selector)); + ifctx =aml_if (aml_equal (ins_evt, one)); + { +aml_append (ifctx, +aml_call2 (CPU_NOTIFY_METHOD , idx, dev_chk)); +aml_append (ifctx,aml_store (one, ins_evt)); + } +aml_append (while_ctx, ifctx); + else_ctx =aml_else (); + ifctx =aml_if (aml_equal (rm_evt, one)); + { +aml_append (ifctx, +aml_call2 (CPU_NOTIFY_METHOD , idx, eject_req)); +aml_append (ifctx,aml_store (one, rm_evt)); + } +aml_append (else_ctx, ifctx); +aml_append (while_ctx, else_ctx); + +aml_append (while_ctx,aml_add (idx, one, idx)); + } +aml_append (method, while_ctx); +aml_append (method,aml_release (ctrl_lock)); + } +aml_append (cpus_dev, method); +/* build Processor object for each processor */ for (i =0 ; i < arch_ids->len; i++) {Aml *dev;Aml *uid =aml_int (i); +GArray *madt_buf =g_array_new (0 ,1 ,1 );int arch_id = arch_ids->cpus[i].arch_id;if (acpi1_compat && arch_id <255 ) {
@@ -235,11 +389,40 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat)aml_append (dev,aml_name_decl ("_UID" , uid)); } + method =aml_method ("_STA" ,0 ,AML_SERIALIZED ); +aml_append (method,aml_return (aml_call1 (CPU_STS_METHOD , uid))); +aml_append (dev, method); + +/* build _MAT object */ +assert (adevc && adevc->madt_cpu); + adevc->madt_cpu (adev, i, arch_ids, madt_buf); +switch (madt_buf->data[0 ]) { +case ACPI_APIC_PROCESSOR : { +AcpiMadtProcessorApic *apic = (void *)madt_buf->data; + apic->flags =cpu_to_le32 (1 ); +break ; + } +default : +assert (0 ); + } +aml_append (dev,aml_name_decl ("_MAT" , +aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data))); +g_array_free (madt_buf, true); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call1 (CPU_EJECT_METHOD , uid)); +aml_append (dev, method); +aml_append (cpus_dev, dev); } }aml_append (sb_scope, cpus_dev);aml_append (table, sb_scope); + method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); +aml_append (table, method); + +g_free (cphp_res_path);g_free (arch_ids); }
hw/i386/acpi-build.c +2 -1
@@ -1949,7 +1949,8 @@ build_dsdt(GArray *table_data, GArray *linker,if (pm->legacy_cpu_hp) {build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base); }else { -build_cpus_aml (dsdt, machine, true); +build_cpus_aml (dsdt, machine, true, +"\\_SB.PCI0" ,"\\_GPE._E02" , pm->cpu_hp_io_base); }build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);
include/hw/acpi/cpu.h +3 -1
@@ -45,7 +45,9 @@ void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner,CPUHotplugState *state,hwaddr base_addr); -void build_cpus_aml (Aml *table,MachineState *machine,bool apci1_compat); +void build_cpus_aml (Aml *table,MachineState *machine,bool apci1_compat, +const char *res_root,const char *event_handler_method, +hwaddr io_base);extern const VMStateDescription vmstate_cpu_hotplug;#define VMSTATE_CPU_HOTPLUG (cpuhp, state) \
Signature · 1 line
1.8.3.1
PATCH 23/33 acpi: add CPU devices AML to DSDT
In reply to Igor Mammedov--- hw/acpi/cpu.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 10 +++++++++- include/hw/acpi/cpu.h | 3 +++ 3 files changed, 50 insertions(+), 1 deletion(-)
hw/acpi/cpu.c +38 -0
@@ -205,3 +205,41 @@ const VMStateDescription vmstate_cpu_hotplug = { VMSTATE_END_OF_LIST() } }; + +#define CPU_NAME_FMT "C%.03X" + +void build_cpus_aml (Aml *table,MachineState *machine,bool acpi1_compat) +{ +Aml *cpus_dev; +Aml *sb_scope =aml_scope ("_SB" ); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids (machine); + cpus_dev =aml_device ("\\_SB.CPUS" ); + { +int i; + +aml_append (cpus_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0010" ))); +aml_append (cpus_dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A05" ))); + +/* build Processor object for each processor */ +for (i =0 ; i < arch_ids->len; i++) { +Aml *dev; +Aml *uid =aml_int (i); +int arch_id = arch_ids->cpus[i].arch_id; + +if (acpi1_compat && arch_id <255 ) { + dev =aml_processor (i,0 ,0 ,CPU_NAME_FMT , i); + }else { + dev =aml_device (CPU_NAME_FMT , arch_id); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("ACPI0007" ))); +aml_append (dev,aml_name_decl ("_UID" , uid)); + } + +aml_append (cpus_dev, dev); + } + } +aml_append (sb_scope, cpus_dev); +aml_append (table, sb_scope); + +g_free (arch_ids); +}
hw/i386/acpi-build.c +9 -1
@@ -93,6 +93,7 @@ typedef struct AcpiPmInfo {uint32_t gpe0_blk;uint32_t gpe0_blk_len;uint32_t io_base; +bool legacy_cpu_hp;uint16_t cpu_hp_io_base;uint16_t mem_hp_io_base;uint16_t mem_hp_io_len;
@@ -141,6 +142,9 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) }assert (obj); + pm->legacy_cpu_hp =object_property_get_bool (obj,"cpu-hotplug-legacy" , +NULL ); + pm->mem_hp_io_base =ACPI_MEMORY_HOTPLUG_BASE ; pm->mem_hp_io_len =ACPI_MEMORY_HOTPLUG_IO_LEN ;
@@ -1942,7 +1946,11 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base); +if (pm->legacy_cpu_hp) { +build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base); + }else { +build_cpus_aml (dsdt, machine, true); + }build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);
include/hw/acpi/cpu.h +3 -0
@@ -14,6 +14,7 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" +#include "hw/acpi/aml-build.h" #include "hw/hotplug.h" typedef struct AcpiCpuStatus {
@@ -44,6 +45,8 @@ void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner,CPUHotplugState *state,hwaddr base_addr); +void build_cpus_aml (Aml *table,MachineState *machine,bool apci1_compat); +extern const VMStateDescription vmstate_cpu_hotplug;#define VMSTATE_CPU_HOTPLUG (cpuhp, state) \ VMSTATE_STRUCT(cpuhp, state, 1, \
Signature · 1 line
1.8.3.1
PATCH 27/33 pc: numa: replace node_cpu indexing by apic_id with possible_cpus index
In reply to Igor Mammedovthat removes dependency on apic_id_limit, reducing size of node_cpu to a number of maxcpus and allowing usage of 32bit APIC IDs without allocating a huge array.
--- hw/i386/acpi-build.c | 2 +- hw/i386/pc.c | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-)
hw/i386/acpi-build.c +1 -1
@@ -2342,7 +2342,7 @@ build_srat(GArray *table_data, GArray *linker, MachineState *machine) core->type =ACPI_SRAT_PROCESSOR_APIC ; core->length =sizeof (*core); core->local_apic_id = apic_id; - curnode = pcms->node_cpu[apic_id]; + curnode = pcms->node_cpu[i]; core->proximity_lo = curnode;memset (core->proximity_hi,0 ,3 ); core->local_sapic_eid =0 ;
hw/i386/pc.c +12 -16
@@ -1104,7 +1104,7 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)void pc_cpus_init (PCMachineState *pcms) { -int i; +int i, j;X86CPU *cpu =NULL ;MachineState *machine =MACHINE (pcms);
@@ -1133,9 +1133,19 @@ void pc_cpus_init(PCMachineState *pcms) pcms->possible_cpus =g_malloc0 (sizeof (CPUArchIdList) +sizeof (CPUArchId) * max_cpus); + pcms->node_cpu =g_malloc0 (max_cpus *sizeof *pcms->node_cpu); +for (i =0 ; i < max_cpus; i++) { pcms->possible_cpus->cpus[i].arch_id =x86_cpu_apic_id_from_index (i); pcms->possible_cpus->len++; + +for (j =0 ; j < nb_numa_nodes; j++) { +if (test_bit (i, numa_info[j].node_cpu)) { + pcms->node_cpu[i] = j; +break ; + } + } +if (i < smp_cpus) { cpu =pc_new_cpu (machine->cpu_model,x86_cpu_apic_id_from_index (i), &error_fatal);
@@ -1185,7 +1195,7 @@ void pc_machine_done(Notifier *notifier, void *data)void pc_guest_info_init (PCMachineState *pcms) { -int i, j; +int i; pcms->apic_xrupt_override =kvm_allows_irq0_override (); pcms->numa_nodes = nb_numa_nodes;
@@ -1195,20 +1205,6 @@ void pc_guest_info_init(PCMachineState *pcms) pcms->node_mem[i] = numa_info[i].node_mem; } - pcms->node_cpu =g_malloc0 (pcms->apic_id_limit * -sizeof *pcms->node_cpu); - -for (i =0 ; i < max_cpus; i++) { -unsigned int apic_id =x86_cpu_apic_id_from_index (i); -assert (apic_id < pcms->apic_id_limit); -for (j =0 ; j < nb_numa_nodes; j++) { -if (test_bit (i, numa_info[j].node_cpu)) { - pcms->node_cpu[apic_id] = j; -break ; - } - } - } - pcms->machine_done.notify = pc_machine_done;qemu_add_machine_init_done_notifier (&pcms->machine_done); }
Signature · 1 line
1.8.3.1
PATCH 25/33 qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
In reply to Igor Mammedovpre_plug callback is to be called before device.realize() is executed. This would allow to check/set device's properties from HotplugHandler.
--- hw/core/hotplug.c | 11 +++++++++++ hw/core/qdev.c | 9 ++++++++- include/hw/hotplug.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-)
hw/core/hotplug.c +11 -0
@@ -13,6 +13,17 @@#include "hw/hotplug.h" #include "qemu/module.h" +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp) +{ +HotplugHandlerClass *hdc =HOTPLUG_HANDLER_GET_CLASS (plug_handler); + +if (hdc->pre_plug) { + hdc->pre_plug (plug_handler, plugged_dev, errp); + } +} +void hotplug_handler_plug (HotplugHandler *plug_handler,DeviceState *plugged_dev,Error **errp)
hw/core/qdev.c +8 -1
@@ -1062,6 +1062,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp)g_free (name); } + hotplug_ctrl =qdev_get_hotplug_handler (dev); +if (hotplug_ctrl) { +hotplug_handler_pre_plug (hotplug_ctrl, dev, &local_err); +if (local_err !=NULL ) { + goto fail; + } + } +if (dc->realize) { dc->realize (dev, &local_err); }
@@ -1072,7 +1080,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)DEVICE_LISTENER_CALL (realize, Forward, dev); - hotplug_ctrl =qdev_get_hotplug_handler (dev);if (hotplug_ctrl) {hotplug_handler_plug (hotplug_ctrl, dev, &local_err); }
include/hw/hotplug.h +13 -1
@@ -45,7 +45,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,* hardware (un)plug functions. * * @parent: Opaque parent interface. -* @plug: plug callback. +* @pre_plug: pre plug callback called at start of device.realize(true) +* @plug: plug callback called at end of device.realize(true). * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling.
@@ -58,6 +59,7 @@ typedef struct HotplugHandlerClass {InterfaceClass parent;/* <public> */ +hotplug_fn pre_plug;hotplug_fn plug;hotplug_fn unplug_request;hotplug_fn unplug;
@@ -73,6 +75,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, Error **errp);/** +* hotplug_handler_pre_plug: +* +* Call #HotplugHandlerClass.pre_plug callback of @plug_handler. +*/ +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp); + + +/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
Signature · 1 line
1.8.3.1
PATCH 28/33 pc: set X86CPU.node property if QEMU starts with numa enabled
In reply to Igor Mammedov--- hw/i386/pc.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-)
hw/i386/pc.c +36 -7
@@ -1672,11 +1672,27 @@ static int pc_apic_cmp(const void *a, const void *b)return apic_a->arch_id - apic_b->arch_id; } +static +CPUArchId *pc_find_possible_cpu (PCMachineState *pcms,CPUState *cpu,int *idx) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); +CPUArchId apic_id, *found_cpu; + + apic_id.arch_id = cc->get_arch_id (CPU (cpu)); + found_cpu =bsearch (&apic_id, pcms->possible_cpus->cpus, + pcms->possible_cpus->len,sizeof (*pcms->possible_cpus->cpus), + pc_apic_cmp); +assert (found_cpu); +if (idx) { + *idx = found_cpu - pcms->possible_cpus->cpus; + } +return found_cpu; +} +static void pc_cpu_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -CPUClass *cc =CPU_GET_CLASS (dev); -CPUArchId apic_id, *found_cpu; +CPUArchId *found_cpu;HotplugHandlerClass *hhc;Error *local_err =NULL ;PCMachineState *pcms =PC_MACHINE (hotplug_dev);
@@ -1700,11 +1716,7 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,/* increment the number of CPUs */ rtc_set_memory (pcms->rtc,0x5f ,rtc_get_memory (pcms->rtc,0x5f ) +1 ); - apic_id.arch_id = cc->get_arch_id (CPU (dev)); - found_cpu =bsearch (&apic_id, pcms->possible_cpus->cpus, - pcms->possible_cpus->len,sizeof (*pcms->possible_cpus->cpus), - pc_apic_cmp); -assert (found_cpu); + found_cpu =pc_find_possible_cpu (pcms,CPU (dev),NULL ); found_cpu->cpu =CPU (dev); out:error_propagate (errp, local_err);
@@ -1753,6 +1765,22 @@ static void pc_cpu_unplug_cb(HotplugHandler *hotplug_dev,error_propagate (errp, local_err); } +static void pc_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (hotplug_dev); + +if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +if (nb_numa_nodes) { +int idx; + +pc_find_possible_cpu (pcms,CPU (dev), &idx); +object_property_set_int (OBJECT (dev), pcms->node_cpu[idx],"node" , + errp); + } + } +} +static void pc_machine_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -2033,6 +2061,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) mc->hot_add_cpu = pc_hot_add_cpu; mc->max_cpus =255 ; mc->reset = pc_machine_reset; + hc->pre_plug = pc_machine_device_pre_plug_cb; hc->plug = pc_machine_device_plug_cb; hc->unplug_request = pc_machine_device_unplug_request_cb; hc->unplug = pc_machine_device_unplug_cb;
Signature · 1 line
1.8.3.1
PATCH 26/33 target-i386: add X86CPU.node property
In reply to Igor Mammedov--- target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
target-i386/cpu-qom.h +1 -0
@@ -101,6 +101,7 @@ typedef struct X86CPU {bool migratable;bool host_features;int64_t apic_id; +int64_t numa_node;/* default: -1: not configured */ /* if true the CPUID code directly forward host cache leaves to the guest */ bool cache_info_passthrough;
target-i386/cpu.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 32/33 tests: acpi: add CPU hotplug testcase
In reply to Igor MammedovTest with:
-smp 2,cores=3,sockets=2,maxcpus=6 \ -numa node,cpus=0-2 -numa node,cpus=3-5
to capture sparse APIC ID values that default
AMD CPU has in above configuration and SRAT table
genarated with NUMA option on.
---
to keep series bisectable include new template files for SRAT tables so tha test won't fail with:
ERROR:tests/bios-tables-test.c:498:load_expected_aml: assertion failed: (exp_sdt.aml_file)
--- tests/acpi-test-data/pc/SRAT.cphp | Bin 0 -> 304 bytes tests/acpi-test-data/q35/SRAT.cphp | Bin 0 -> 304 bytes tests/bios-tables-test.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/acpi-test-data/pc/SRAT.cphp create mode 100644 tests/acpi-test-data/q35/SRAT.cphp
tests/acpi-test-data/pc/SRAT.cphp new file binary +0 -0
tests/acpi-test-data/q35/SRAT.cphp new file binary +0 -0
tests/bios-tables-test.c +30 -0
@@ -789,6 +789,34 @@ static void test_acpi_q35_tcg_bridge(void)free_test_data (&data); } +static void test_acpi_piix4_tcg_cphp (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".cphp" ; +test_acpi_one ("-machine accel=tcg" +" -smp 2,cores=3,sockets=2,maxcpus=6" +" -numa node,cpus=0-2 -numa node,cpus=3-5" , + &data); +free_test_data (&data); +} + +static void test_acpi_q35_tcg_cphp (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".cphp" ; +test_acpi_one ("-machine q35,accel=tcg" +" -smp 2,cores=3,sockets=2,maxcpus=6" +" -numa node,cpus=0-2 -numa node,cpus=3-5" , + &data); +free_test_data (&data); +} +int main (int argc,char *argv[]) {const char *arch =qtest_get_arch ();
@@ -805,6 +833,8 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/piix4/tcg/bridge" , test_acpi_piix4_tcg_bridge);qtest_add_func ("acpi/q35/tcg" , test_acpi_q35_tcg);qtest_add_func ("acpi/q35/tcg/bridge" , test_acpi_q35_tcg_bridge); +qtest_add_func ("acpi/piix4/tcg/cpuhp" , test_acpi_piix4_tcg_cphp); +qtest_add_func ("acpi/q35/tcg/cpuhp" , test_acpi_q35_tcg_cphp); } ret =g_test_run ();boot_sector_cleanup (disk);
Signature · 1 line
1.8.3.1
PATCH 30/33 acpi: cpuhp: add cpu._OST handling
In reply to Igor Mammedov--- hw/acpi/cpu.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/ich9.c | 3 ++ hw/acpi/piix4.c | 3 ++ include/hw/acpi/cpu.h | 4 +++ qapi-schema.json | 3 +- trace-events | 2 ++ 6 files changed, 97 insertions(+), 1 deletion(-)
hw/acpi/cpu.c +83 -0
@@ -2,6 +2,7 @@#include "hw/boards.h" #include "hw/acpi/cpu.h" #include "qapi/error.h" +#include "qapi-event.h" #include "trace.h" #define ACPI_CPU_HOTPLUG_REG_LEN 12
@@ -12,9 +13,42 @@enum {CPHP_PXM_CMD =0 , +CPHP_OST_EVENT_CMD =1 , +CPHP_OST_STATUS_CMD =2 ,CPHP_CMD_MAX }; +static ACPIOSTInfo *acpi_cpu_device_status (int idx,AcpiCpuStatus *cdev) +{ +ACPIOSTInfo *info =g_new0 (ACPIOSTInfo,1 ); + + info->slot_type =ACPI_SLOT_TYPE_CPU ; + info->slot =g_strdup_printf ("%d" , idx); + info->source = cdev->ost_event; + info->status = cdev->ost_status; +if (cdev->cpu) { +DeviceState *dev =DEVICE (cdev->cpu); +if (dev->id) { + info->device =g_strdup (dev->id); + info->has_device = true; + } + } +return info; +} + +void acpi_cpu_ospm_status (CPUHotplugState *cpu_st,ACPIOSTInfoList ***list) +{ +int i; + +for (i =0 ; i < cpu_st->dev_count; i++) { +ACPIOSTInfoList *elem =g_new0 (ACPIOSTInfoList,1 ); + elem->value =acpi_cpu_device_status (i, &cpu_st->devs[i]); + elem->next =NULL ; + **list = elem; + *list = &elem->next; + } +} +static uint64_t cpu_hotplug_rd (void *opaque,hwaddr addr,unsigned size) {uint64_t val = ~0 ;
@@ -57,6 +91,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data, {CPUHotplugState *cpu_st = opaque;AcpiCpuStatus *cdev; +ACPIOSTInfo *info;Error *local_err =NULL ;assert (cpu_st->dev_count);
@@ -95,6 +130,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data, hotplug_ctrl =qdev_get_hotplug_handler (dev);hotplug_handler_unplug (hotplug_ctrl, dev, &local_err);if (local_err) { +/* TODO: send error QAPI event */ break ; } }
@@ -105,6 +141,28 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data, cpu_st->command = data; }break ; +case ACPI_CPU_CMD_DATA_OFFSET_RW : +switch (cpu_st->command) { +case CPHP_OST_EVENT_CMD : { + cdev = &cpu_st->devs[cpu_st->selector]; + cdev->ost_event = data; +trace_cpuhp_acpi_write_ost_ev (cpu_st->selector, cdev->ost_event); +break ; + } +case CPHP_OST_STATUS_CMD : { + cdev = &cpu_st->devs[cpu_st->selector]; + cdev->ost_status = data; + info =acpi_cpu_device_status (cpu_st->selector, cdev); +qapi_event_send_acpi_device_ost (info, &error_abort); +qapi_free_ACPIOSTInfo (info); +trace_cpuhp_acpi_write_ost_status (cpu_st->selector, + cdev->ost_status); +break ; + } +default : +break ; + } +break ;default :break ; }
@@ -214,6 +272,8 @@ static const VMStateDescription vmstate_cpuhp_sts = {VMSTATE_BOOL (is_enabled, AcpiCpuStatus),VMSTATE_BOOL (is_inserting, AcpiCpuStatus),VMSTATE_BOOL (is_removing, AcpiCpuStatus), +VMSTATE_UINT32 (ost_event, AcpiCpuStatus), +VMSTATE_UINT32 (ost_status, AcpiCpuStatus), VMSTATE_END_OF_LIST() } };
@@ -240,6 +300,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_EJECT_METHOD "CEJ0"#define CPU_NOTIFY_METHOD "CTFY"#define CPU_PXM_METHOD "CPXM" +#define CPU_OST_METHOD "COST"#define CPU_ENABLED "CPEN"#define CPU_SELECTOR "CSEL"
@@ -439,6 +500,21 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat, }aml_append (cpus_dev, method); } + method =aml_method (CPU_OST_METHOD ,4 ,AML_SERIALIZED ); + { +Aml *uid =aml_arg (0 ); +Aml *ev_cmd =aml_int (CPHP_OST_EVENT_CMD ); +Aml *st_cmd =aml_int (CPHP_OST_STATUS_CMD ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (uid, cpu_selector)); +aml_append (method,aml_store (ev_cmd, cpu_cmd)); +aml_append (method,aml_store (aml_arg (1 ), cpu_data)); +aml_append (method,aml_store (st_cmd, cpu_cmd)); +aml_append (method,aml_store (aml_arg (2 ), cpu_data)); +aml_append (method,aml_release (ctrl_lock)); + } +aml_append (cpus_dev, method);/* build Processor object for each processor */ for (i =0 ; i < arch_ids->len; i++) {
@@ -485,6 +561,13 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat, aml_return(aml_call1(CPU_PXM_METHOD, uid)));aml_append (dev, method); } + + method =aml_method ("_OST" ,3 ,AML_SERIALIZED ); +aml_append (method, +aml_call4 (CPU_OST_METHOD , uid,aml_arg (0 ), +aml_arg (1 ),aml_arg (2 )) + ); +aml_append (dev, method);aml_append (cpus_dev, dev); } }
hw/acpi/ich9.c +3 -0
@@ -537,4 +537,7 @@ void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)ICH9LPCState *s =ICH9_LPC_DEVICE (adev);acpi_memory_ospm_status (&s->pm.acpi_memory_hotplug, list); +if (!s->pm.cpu_hotplug_legacy) { +acpi_cpu_ospm_status (&s->pm.cpuhp.state, list); + } }
hw/acpi/piix4.c +3 -0
@@ -629,6 +629,9 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)PIIX4PMState *s =PIIX4_PM (adev);acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); +if (!s->cpu_hotplug_legacy) { +acpi_cpu_ospm_status (&s->cpuhp.state, list); + } }static void piix4_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev)
include/hw/acpi/cpu.h +4 -0
@@ -23,6 +23,8 @@ typedef struct AcpiCpuStatus {bool is_enabled;bool is_inserting;bool is_removing; +uint32_t ost_event; +uint32_t ost_status; } AcpiCpuStatus; typedef struct CPUHotplugState {
@@ -50,6 +52,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool apci1_compat, const char *res_root, const char *event_handler_method, hwaddr io_base); +void acpi_cpu_ospm_status (CPUHotplugState *cpu_st,ACPIOSTInfoList ***list); +extern const VMStateDescription vmstate_cpu_hotplug;#define VMSTATE_CPU_HOTPLUG (cpuhp, state) \ VMSTATE_STRUCT(cpuhp, state, 1, \
qapi-schema.json +2 -1
@@ -4018,8 +4018,9 @@ ## @ACPISlotType # # @DIMM: memory slot +# @CPU: logical CPU slot # -{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] } +{ 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] } ## @ACPIOSTInfo #
trace-events +2 -0
@@ -1919,3 +1919,5 @@ cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32 cpuhp_acpi_write_cmd(uint32_t idx, uint8_t cmd) "idx[0x%"PRIx32"] cmd: 0x%"PRIx8 cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32 +cpuhp_acpi_write_ost_ev(uint32_t slot, uint32_t ev) "idx[0x%"PRIx32"] OST EVENT: 0x%"PRIx32 +cpuhp_acpi_write_ost_status(uint32_t slot, uint32_t st) "idx[0x%"PRIx32"] OST STATUS: 0x%"PRIx32
Signature · 1 line
1.8.3.1
PATCH 31/33 tests: acpi: update expected tables with new cpu-hotplug methods enabled by default
In reply to Igor Mammedov--- tests/acpi-test-data/pc/DSDT | Bin 5503 -> 5951 bytes tests/acpi-test-data/pc/DSDT.bridge | Bin 7362 -> 7810 bytes tests/acpi-test-data/q35/DSDT | Bin 8265 -> 8713 bytes tests/acpi-test-data/q35/DSDT.bridge | Bin 8282 -> 8730 bytes 4 files changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/pc/DSDT binary +0 -0
tests/acpi-test-data/pc/DSDT.bridge binary +0 -0
tests/acpi-test-data/q35/DSDT binary +0 -0
tests/acpi-test-data/q35/DSDT.bridge binary +0 -0
Signature · 1 line
1.8.3.1
PATCH 29/33 acpi: cpuhp: provide cpu._PXM method if running in numa mode
In reply to Igor MammedovHaving proximity in SRAT table is not enough in case of linux guest as it discards SRAT table information after it's done with booting. So hotplugged CPUs will go to 1st node as kernel doesn't know to what node they belong to anymore.
So do the same as with hotplugged memory and provide _PXM method in CPU device context so that OSPM could assign CPU to a correct node.
--- hw/acpi/cpu.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/cpu.h | 1 + trace-events | 2 ++ 3 files changed, 75 insertions(+)
hw/acpi/cpu.c +72 -0
@@ -7,6 +7,13 @@#define ACPI_CPU_HOTPLUG_REG_LEN 12#define ACPI_CPU_SELECTOR_OFFSET_WR 0#define ACPI_CPU_FLAGS_OFFSET_RW 4 +#define ACPI_CPU_CMD_OFFSET_WR 5 +#define ACPI_CPU_CMD_DATA_OFFSET_RW 8 + +enum { +CPHP_PXM_CMD =0 , +CPHP_CMD_MAX +};static uint64_t cpu_hotplug_rd (void *opaque,hwaddr addr,unsigned size) {
@@ -27,6 +34,18 @@ static uint64_t cpu_hotplug_rd(void *opaque, hwaddr addr, unsigned size) val |= cdev->is_removing ?4 :0 ;trace_cpuhp_acpi_read_flags (cpu_st->selector, val);break ; +case ACPI_CPU_CMD_DATA_OFFSET_RW : +switch (cpu_st->command) { +case CPHP_PXM_CMD : { +Object *o =OBJECT (CPU (cdev->cpu)); + val = o ?object_property_get_int (o,"node" ,NULL ) : ~0 ; +trace_cpuhp_acpi_read_pxm (cpu_st->selector, val); +break ; + } +default : +break ; + } +break ;default :break ; }
@@ -80,6 +99,12 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data, } }break ; +case ACPI_CPU_CMD_OFFSET_WR : +trace_cpuhp_acpi_write_cmd (cpu_st->selector, data); +if (data <CPHP_CMD_MAX ) { + cpu_st->command = data; + } +break ;default :break ; }
@@ -200,6 +225,7 @@ const VMStateDescription vmstate_cpu_hotplug = { .minimum_version_id_old = 1, .fields = (VMStateField []) {VMSTATE_UINT32 (selector, CPUHotplugState), +VMSTATE_UINT32 (command, CPUHotplugState),VMSTATE_STRUCT_VARRAY_POINTER_UINT32 (devs, CPUHotplugState, dev_count, vmstate_cpuhp_sts, AcpiCpuStatus),VMSTATE_END_OF_LIST ()
@@ -213,12 +239,15 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_SCAN_METHOD "CSCN"#define CPU_EJECT_METHOD "CEJ0"#define CPU_NOTIFY_METHOD "CTFY" +#define CPU_PXM_METHOD "CPXM"#define CPU_ENABLED "CPEN"#define CPU_SELECTOR "CSEL"#define CPU_EJECT_EVENT "CEJ0"#define CPU_INSERT_EVENT "CINS"#define CPU_REMOVE_EVENT "CRMV" +#define CPU_COMMAND "CCMD" +#define CPU_DATA "CDAT" void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat, const char *res_root, const char *event_handler_method,
@@ -269,11 +298,16 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat,aml_append (field,aml_named_field (CPU_REMOVE_EVENT ,1 ));/* initiates device eject, write only */ aml_append (field,aml_named_field (CPU_EJECT_EVENT ,1 )); +aml_append (field,aml_reserved_field (4 )); +aml_append (field,aml_named_field (CPU_COMMAND ,8 ));aml_append (cpu_ctrl_dev, field); field =aml_field ("PRST" ,AML_DWORD_ACC ,AML_NOLOCK ,AML_PRESERVE );/* CPU selector, write only */ aml_append (field,aml_named_field (CPU_SELECTOR ,32 )); +/* flags + cmd + 2byte align */ +aml_append (field,aml_reserved_field (4 *8 )); +aml_append (field,aml_named_field (CPU_DATA ,32 ));aml_append (cpu_ctrl_dev, field); }
@@ -282,6 +316,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat, cpus_dev =aml_device ("\\_SB.CPUS" ); {int i; +bool has_pxm = true; +Error *local_err =NULL ;Aml *one =aml_int (1 );Aml *cpu_selector =aml_name ("%s.%s" , cphp_res_path,CPU_SELECTOR );Aml *ins_evt =aml_name ("%s.%s" , cphp_res_path,CPU_INSERT_EVENT );
@@ -289,10 +325,23 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat,Aml *ej_evt =aml_name ("%s.%s" , cphp_res_path,CPU_EJECT_EVENT );Aml *is_enabled =aml_name ("%s.%s" , cphp_res_path,CPU_ENABLED );Aml *ctrl_lock =aml_name ("%s.%s" , cphp_res_path,CPU_LOCK ); +Aml *cpu_cmd =aml_name ("%s.%s" , cphp_res_path,CPU_COMMAND ); +Aml *cpu_data =aml_name ("%s.%s" , cphp_res_path,CPU_DATA );aml_append (cpus_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0010" )));aml_append (cpus_dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A05" ))); +/* +* sample 1st VCPU (BSP) if it has support for numa and use result +* to enable _PXM method support +*/ +object_property_get_int (OBJECT (arch_ids->cpus[0 ].cpu),"node" , + &local_err); +if (local_err) { +error_free (local_err); + has_pxm = false; + } + method =aml_method (CPU_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED );for (i =0 ; i < arch_ids->len; i++) {Aml *cpu =aml_name (CPU_NAME_FMT , i);
@@ -374,6 +423,23 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat, }aml_append (cpus_dev, method); +if (has_pxm) { + method =aml_method (CPU_PXM_METHOD ,1 ,AML_SERIALIZED ); + { +Aml *uid =aml_arg (0 ); +Aml *pxm =aml_local (0 ); +Aml *pxm_cmd =aml_int (CPHP_PXM_CMD ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (uid, cpu_selector)); +aml_append (method,aml_store (pxm_cmd, cpu_cmd)); +aml_append (method,aml_store (cpu_data, pxm)); +aml_append (method,aml_release (ctrl_lock)); +aml_append (method,aml_return (pxm)); + } +aml_append (cpus_dev, method); + } +/* build Processor object for each processor */ for (i =0 ; i < arch_ids->len; i++) {Aml *dev;
@@ -413,6 +479,12 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat,aml_append (method,aml_call1 (CPU_EJECT_METHOD , uid));aml_append (dev, method); +if (has_pxm) { + method =aml_method ("_PXM" ,0 ,AML_SERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_PXM_METHOD , uid))); +aml_append (dev, method); + }aml_append (cpus_dev, dev); } }
include/hw/acpi/cpu.h +1 -0
@@ -28,6 +28,7 @@ typedef struct AcpiCpuStatus {typedef struct CPUHotplugState {MemoryRegion ctrl_reg;uint32_t selector; +uint32_t command;uint32_t dev_count;AcpiCpuStatus *devs; }CPUHotplugState ;
trace-events +2 -0
@@ -1912,8 +1912,10 @@ aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 # hw/acpi/cpu.c cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8 +cpuhp_acpi_read_pxm(uint32_t idx, uint32_t pxm) "idx[0x%"PRIx32"] flags: 0x%"PRIx32 cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]" cpuhp_acpi_clear_remove_evt(uint32_t idx) "idx[0x%"PRIx32"]" cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32 +cpuhp_acpi_write_cmd(uint32_t idx, uint8_t cmd) "idx[0x%"PRIx32"] cmd: 0x%"PRIx8 cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32
Signature · 1 line
1.8.3.1
PATCH 33/33 tests: acpi: add DSDT/MADT expected tables for cpu-hotplug case
In reply to Igor Mammedov--- tests/acpi-test-data/pc/APIC.cphp | Bin 0 -> 160 bytes tests/acpi-test-data/pc/DSDT.cphp | Bin 0 -> 6578 bytes tests/acpi-test-data/q35/APIC.cphp | Bin 0 -> 160 bytes tests/acpi-test-data/q35/DSDT.cphp | Bin 0 -> 9340 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/acpi-test-data/pc/APIC.cphp create mode 100644 tests/acpi-test-data/pc/DSDT.cphp create mode 100644 tests/acpi-test-data/q35/APIC.cphp create mode 100644 tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/APIC.cphp new file binary +0 -0
tests/acpi-test-data/pc/DSDT.cphp new file binary +0 -0
tests/acpi-test-data/q35/APIC.cphp new file binary +0 -0
tests/acpi-test-data/q35/DSDT.cphp new file binary +0 -0
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
In reply to Igor MammedovQuoted 13 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/ich9.c | 3 ++ hw/acpi/piix4.c | 3 ++ include/hw/acpi/cpu.h | 4 +++ qapi-schema.json | 3 +- trace-events | 2 ++ 6 files changed, 97 insertions(+), 1 deletion(-)+++
b/qapi-schema.json
qapi-schema.json line 4021
Quoted 4 lines
qapi-schema.json +1
-0@@ -4018,8 +4018,9 @@ ## @ACPISlotType # # @DIMM: memory slot +# @CPU: logical CPU slot
Missing a marker '(since 2.7)'
qapi-schema.json line 4023
Quoted 3 lines
qapi-schema.json +1
-1# -{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] } +{ 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }
Hmm. ACPISlotType is already on our whitelist of exceptions that allow upper-case names (we prefer lower), so adding another one doesn't necessarily hurt.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
Quoted 12 lines · On Tue, 17 May 2016 09:29:15 -0600 Eric Blake <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/ich9.c | 3 ++ hw/acpi/piix4.c | 3 ++ include/hw/acpi/cpu.h | 4 +++ qapi-schema.json | 3 +- trace-events | 2 ++ 6 files changed, 97 insertions(+), 1 deletion(-)
Quoted 8 lines
qapi-schema.json line 4021
Quoted 6 lines
+++
b/qapi-schema.jsonqapi-schema.json +1
-0@@ -4018,8 +4018,9 @@ ## @ACPISlotType # # @DIMM: memory slot +# @CPU: logical CPU slotMissing a marker '(since 2.7)'
thanks, fixed in v2.
Quoted 7 lines
qapi-schema.json line 4023
Quoted 3 lines
qapi-schema.json +1
-1# -{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] } +{ 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }Hmm. ACPISlotType is already on our whitelist of exceptions that allow upper-case names (we prefer lower), so adding another one doesn't necessarily hurt.
I'll keep that in mind.
Re: [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode
In reply to Igor MammedovQuoted 36 lines · Igor Mammedov
print expected file name if it doesn't exists if verbose mode is enabled*. It helps to avoid running bios-tables-test under debugger to figure out missing file name.
*)
verbose mode is enabled if "V" env. variable is setSigned-off-by Igor Mammedov <[email protected]>--- tests/bios-tables-test.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)tests/bios-tables-test.c +2
-1@@ -464,7 +464,6 @@ static GArray *load_expected_aml(test_data *data) {int i;AcpiSdtTable *sdt; -gchar *aml_file =NULL ;GError *error =NULL ;gboolean ret;@@ -472,7 +471,9 @@ static GArray *load_expected_aml(test_data *data)for (i =0 ; i < data->tables->len; ++i) {AcpiSdtTable exp_sdt;uint32_t signature; +gchar *aml_file =NULL ;const char *ext = data->variant ? data->variant :"" ; +int j; sdt = &g_array_index (data->tables, AcpiSdtTable, i);
tests/bios-tables-test.c static GArray *load_expected_aml(test_data *data) · line 485
Quoted 8 lines
tests/bios-tables-test.c +1
-4@@ -481,16 +482,23 @@ static GArray *load_expected_aml(test_data *data) signature =cpu_to_le32 (sdt->header.signature); -try_again: - aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, - (gchar *)&signature, ext); -if (data->variant && !g_file_test (aml_file,G_FILE_TEST_EXISTS )) { +for (j =2 ; j; j -= data->variant ?1 :2 ) {
Can you please make this code more readable ? I am kind of lost. I do agree with what the patch tries to achieve.
Thanks,
Marcel
Quoted 23 lines
tests/bios-tables-test.c +13
-3g_free (aml_file); + aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, + (gchar *)&signature, ext); +if (g_file_test (aml_file,G_FILE_TEST_EXISTS )) { + exp_sdt.aml_file = aml_file; +break ; + } +if (getenv ("V" )) { +fprintf (stderr,"\nLooking for expected file '%s'\n" , aml_file); + } ext ="" ; - goto try_again; } - exp_sdt.aml_file = aml_file; -g_assert (g_file_test (aml_file,G_FILE_TEST_EXISTS )); +g_assert (exp_sdt.aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nUsing expected file '%s'\n" , aml_file); + } ret =g_file_get_contents (aml_file, &exp_sdt.aml, &exp_sdt.aml_len, &error);g_assert (ret);
Re: [Qemu-devel] [PATCH 02/33] acpi: add aml_debug()
In reply to Igor MammedovQuoted 32 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 9 +++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 10 insertions(+)hw/acpi/aml-build.c +9
-0@@ -406,6 +406,15 @@ Aml *aml_return(Aml *val)return var; } +/* ACPI 1.0b: 16.2.6.3 Debug Objects Encoding: DebugObj */ +Aml *aml_debug (void ) +{ +Aml *var =aml_alloc (); +build_append_byte (var->buf,0x5B );/* ExtOpPrefix */ +build_append_byte (var->buf,0x31 );/* DebugOp */ +return var; +} +/* * ACPI 1.0b: 16.2.3 Data Objects Encoding: * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp include/hw/acpi/aml-build.h +0
-0
include/hw/acpi/aml-build.h void aml_append(Aml *parent_ctx, Aml *child); · line 258
Quoted 7 lines
include/hw/acpi/aml-build.h +1
-0@@ -252,6 +252,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* non block AML object primitives */ Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_name_decl (const char *name,Aml *val); +Aml *aml_debug (void );Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val);Aml *aml_arg (int pos);
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 03/33] acpi: add aml_refof()
In reply to Igor MammedovQuoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)hw/acpi/aml-build.c +8
-0@@ -1416,6 +1416,14 @@ Aml *aml_unicode(const char *str)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefRefOf */ +Aml *aml_refof (Aml *arg) +{ +Aml *var =aml_opcode (0x71 /* RefOfOp */ ); +aml_append (var, arg); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefDerefOf */ Aml *aml_derefof (Aml *arg) {include/hw/acpi/aml-build.h +0
-0
include/hw/acpi/aml-build.h Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name); · line 365
Quoted 7 lines
include/hw/acpi/aml-build.h +1
-0@@ -359,6 +359,7 @@ Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name);Aml *aml_varpackage (uint32_t num_elements);Aml *aml_touuid (const char *uuid);Aml *aml_unicode (const char *str); +Aml *aml_refof (Aml *arg);Aml *aml_derefof (Aml *arg);Aml *aml_sizeof (Aml *arg);Aml *aml_concatenate (Aml *source1,Aml *source2,Aml *target);
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers
In reply to Igor MammedovQuoted 43 lines · Igor Mammedov
ACPI spec requires GPE handlers only for GPE events that hardware implements.
So remove AML for not supported by QEMU device model events.Signed-off-by Igor Mammedov <[email protected]>--- hw/i386/acpi-build.c | 17 ----------------- 1 file changed, 17 deletions(-)hw/i386/acpi-build.c +0
-10@@ -2051,8 +2051,6 @@ build_dsdt(GArray *table_data, GArray *linker, {aml_append (scope,aml_name_decl ("_HID" ,aml_string ("ACPI0006" ))); -aml_append (scope,aml_method ("_L00" ,0 ,AML_NOTSERIALIZED )); -if (misc->is_piix4) { method =aml_method ("_E01" ,0 ,AML_NOTSERIALIZED ); aml_append(method,@@ -2060,8 +2058,6 @@ build_dsdt(GArray *table_data, GArray *linker,aml_append (method,aml_call0 ("\\_SB.PCI0.PCNT" ));aml_append (method,aml_release (aml_name ("\\_SB.PCI0.BLCK" )));aml_append (scope, method); - }else { -aml_append (scope,aml_method ("_L01" ,0 ,AML_NOTSERIALIZED )); } method =aml_method ("_E02" ,0 ,AML_NOTSERIALIZED );@@ -2071,19 +2067,6 @@ build_dsdt(GArray *table_data, GArray *linker, method =aml_method ("_E03" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_call0 (MEMORY_HOTPLUG_HANDLER_PATH ));aml_append (scope, method); - -aml_append (scope,aml_method ("_L04" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L05" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L06" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L07" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L08" ,0 ,AML_NOTSERIALIZED ));
hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, · line 2072
Quoted 10 lines
hw/i386/acpi-build.c +0
-7-aml_append (scope,aml_method ("_L09" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0A" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0B" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0C" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0D" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0E" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0F" ,0 ,AML_NOTSERIALIZED )); }aml_append (dsdt, scope);
Is this patch related to the series? Or is it a cleanup opportunity? Thanks,
Marcel
Re: [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers
Quoted 49 lines · On Wed, 25 May 2016 12:11:33 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 48 lines · Igor Mammedov
ACPI spec requires GPE handlers only for GPE events that hardware implements.
So remove AML for not supported by QEMU device model events.Signed-off-by Igor Mammedov <[email protected]>--- hw/i386/acpi-build.c | 17 ----------------- 1 file changed, 17 deletions(-)hw/i386/acpi-build.c +0
-16@@ -2051,8 +2051,6 @@ build_dsdt(GArray *table_data, GArray *linker, {aml_append (scope,aml_name_decl ("_HID" ,aml_string ("ACPI0006" ))); -aml_append (scope,aml_method ("_L00" ,0 ,AML_NOTSERIALIZED )); -if (misc->is_piix4) { method =aml_method ("_E01" ,0 ,AML_NOTSERIALIZED ); aml_append(method,@@ -2060,8 +2058,6 @@ build_dsdt(GArray *table_data, GArray *linker,aml_append (method,aml_call0 ("\\_SB.PCI0.PCNT" ));aml_append (method,aml_release (aml_name ("\\_SB.PCI0.BLCK" )));aml_append (scope, method); - }else { -aml_append (scope,aml_method ("_L01" ,0 ,AML_NOTSERIALIZED )); } method =aml_method ("_E02" ,0 ,AML_NOTSERIALIZED );@@ -2071,19 +2067,6 @@ build_dsdt(GArray *table_data, GArray *linker, method =aml_method ("_E03" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_call0 (MEMORY_HOTPLUG_HANDLER_PATH ));aml_append (scope, method); - -aml_append (scope,aml_method ("_L04" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L05" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L06" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L07" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L08" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L09" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0A" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0B" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0C" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0D" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0E" ,0 ,AML_NOTSERIALIZED ));
Quoted 8 lines
hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, · line 2072
Quoted 5 lines
hw/i386/acpi-build.c +0
-1-aml_append (scope,aml_method ("_L0F" ,0 ,AML_NOTSERIALIZED )); }aml_append (dsdt, scope);Is this patch related to the series? Or is it a cleanup opportunity?
It's a cleanup, I'm posting it here as it's missed its merge chance at 2.6 and Michael suggested to respin it later when 2.7 dev window is open
Quoted 3 lines
Thanks,
Marcel
PATCH v2 1/33 tests: acpi: report names of expected files in verbose mode
In reply to Marcel Apfelbaumprint expected file name if it doesn't exists if verbose mode is enabled*. It helps to avoid running bios-tables-test under debugger to figure out missing file name.
*)
verbose mode is enabled if "V" env. variable is set
---
v2: replace 'for' loop with more readble 'goto'
Marcel Apfelbaum <[email protected]>
--- tests/bios-tables-test.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
tests/bios-tables-test.c +13 -5
@@ -464,7 +464,6 @@ static GArray *load_expected_aml(test_data *data) {int i;AcpiSdtTable *sdt; -gchar *aml_file =NULL ;GError *error =NULL ;gboolean ret;
@@ -472,6 +471,7 @@ static GArray *load_expected_aml(test_data *data)for (i =0 ; i < data->tables->len; ++i) {AcpiSdtTable exp_sdt;uint32_t signature; +gchar *aml_file =NULL ;const char *ext = data->variant ? data->variant :"" ; sdt = &g_array_index (data->tables, AcpiSdtTable, i);
@@ -484,13 +484,21 @@ static GArray *load_expected_aml(test_data *data) try_again: aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, (gchar *)&signature, ext); -if (data->variant && !g_file_test (aml_file,G_FILE_TEST_EXISTS )) { -g_free (aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nLooking for expected file '%s'\n" , aml_file); + } +if (g_file_test (aml_file,G_FILE_TEST_EXISTS )) { + exp_sdt.aml_file = aml_file; + }else if (*ext !='\0' ) { +/* try fallback to generic (extention less) expected file */ ext ="" ; +g_free (aml_file); goto try_again; } - exp_sdt.aml_file = aml_file; -g_assert (g_file_test (aml_file,G_FILE_TEST_EXISTS )); +g_assert (exp_sdt.aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nUsing expected file '%s'\n" , aml_file); + } ret =g_file_get_contents (aml_file, &exp_sdt.aml, &exp_sdt.aml_len, &error);g_assert (ret);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 1/33] tests: acpi: report names of expected files in verbose mode
Quoted 53 lines · Igor Mammedov
print expected file name if it doesn't exists if verbose mode is enabled*. It helps to avoid running bios-tables-test under debugger to figure out missing file name.
*)
verbose mode is enabled if "V" env. variable is setSigned-off-by Igor Mammedov <[email protected]>---
v2: replace 'for' loop with more readble 'goto'
Marcel Apfelbaum <[email protected]>--- tests/bios-tables-test.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)tests/bios-tables-test.c +9
-3@@ -464,7 +464,6 @@ static GArray *load_expected_aml(test_data *data) {int i;AcpiSdtTable *sdt; -gchar *aml_file =NULL ;GError *error =NULL ;gboolean ret;@@ -472,6 +471,7 @@ static GArray *load_expected_aml(test_data *data)for (i =0 ; i < data->tables->len; ++i) {AcpiSdtTable exp_sdt;uint32_t signature; +gchar *aml_file =NULL ;const char *ext = data->variant ? data->variant :"" ; sdt = &g_array_index (data->tables, AcpiSdtTable, i);@@ -484,13 +484,21 @@ static GArray *load_expected_aml(test_data *data) try_again: aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, (gchar *)&signature, ext); -if (data->variant && !g_file_test (aml_file,G_FILE_TEST_EXISTS )) { -g_free (aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nLooking for expected file '%s'\n" , aml_file); + } +if (g_file_test (aml_file,G_FILE_TEST_EXISTS )) { + exp_sdt.aml_file = aml_file; + }else if (*ext !='\0' ) { +/* try fallback to generic (extention less) expected file */ ext ="" ; +g_free (aml_file); goto try_again;
tests/bios-tables-test.c static GArray *load_expected_aml(test_data *data) · line 504
Quoted 10 lines
tests/bios-tables-test.c +4
-2} - exp_sdt.aml_file = aml_file; -g_assert (g_file_test (aml_file,G_FILE_TEST_EXISTS )); +g_assert (exp_sdt.aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nUsing expected file '%s'\n" , aml_file); + } ret =g_file_get_contents (aml_file, &exp_sdt.aml, &exp_sdt.aml_len, &error);g_assert (ret);
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
In reply to Igor MammedovQuoted 3 lines · Igor Mammedov
move the former SSDT part of CPU hoplug close to DSDT part. AML is only moved but there isn't any functional change.
The patch looks good to me,
but why did you decide to get rid of the build_processor_devices function? I would simply move it to the new file.
Maybe is a matter of taste, anyway:
Thanks,
Marcel
Quoted 290 lines
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug_acpi_table.c | 104 +++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 112 +-------------------------------------- include/hw/acpi/cpu_hotplug.h | 3 +- 3 files changed, 106 insertions(+), 113 deletions(-)hw/acpi/cpu_hotplug_acpi_table.c +103
-1@@ -15,12 +15,19 @@#include "qemu/osdep.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/i386/pc.h" -void build_cpu_hotplug_aml (Aml *ctx) +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) { +Aml *dev; +Aml *crs; +Aml *pkg; +Aml *field;Aml *method;Aml *if_ctx;Aml *else_ctx; +int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 };Aml *cpu_id =aml_arg (0 );@@ -29,6 +36,9 @@ void build_cpu_hotplug_aml(Aml *ctx)Aml *cpus_map =aml_name (CPU_ON_BITMAP );Aml *zero =aml_int (0 );Aml *one =aml_int (1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); +PCMachineState *pcms =PC_MACHINE (machine);/* * _MAT method - creates an madt apic buffer @@ -132,5 +142,97 @@ void build_cpu_hotplug_aml(Aml *ctx) }aml_append (sb_scope, method); +/* The current AML generator can cover the APIC ID range [0..255], +* inclusive, for VCPU hotplug. */ +QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); +g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); + +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); + +/* build Processor object for each processor */ +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); + + dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + + method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_arg (0 ))) + ); +aml_append (dev, method); + +aml_append (sb_scope, dev); + } + +/* build this code: +* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} +*/ +/* Arg0 = Processor ID = APIC ID */ + method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); +aml_append (if_ctx, +aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) + ); +aml_append (method, if_ctx); + } +aml_append (sb_scope, method); + +/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" +* +* Note: The ability to create variable-sized packages was first +* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages +* ith up to 255 elements. Windows guests up to win2k8 fail when +* VarPackageOp is used. +*/ + pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : +aml_varpackage (pcms->apic_id_limit); + +for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +for (; apic_idx < apic_id; apic_idx++) { +aml_append (pkg,aml_int (0 )); + } +aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); + apic_idx = apic_id +1 ; + } +aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); +g_free (apic_ids); +aml_append (ctx, sb_scope); }hw/i386/acpi-build.c +1
-111@@ -943,114 +943,6 @@ static Aml *build_crs(PCIHostState *host,return crs; } -static void build_processor_devices (Aml *sb_scope,MachineState *machine, -AcpiPmInfo *pm) -{ -int i, apic_idx; -Aml *dev; -Aml *crs; -Aml *pkg; -Aml *field; -Aml *ifctx; -Aml *method; -MachineClass *mc =MACHINE_GET_CLASS (machine); -CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); -PCMachineState *pcms =PC_MACHINE (machine); - -/* The current AML generator can cover the APIC ID range [0..255], -* inclusive, for VCPU hotplug. */ -QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); -g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); - -/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ - dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); -aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); -aml_append (dev, -aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) - ); -/* device present, functioning, decoding, not shown in UI */ -aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); - crs =aml_resource_template (); -aml_append (crs, -aml_io (AML_DECODE16 , pm->cpu_hp_io_base, pm->cpu_hp_io_base,1 , - pm->cpu_hp_io_len) - ); -aml_append (dev,aml_name_decl ("_CRS" , crs)); -aml_append (sb_scope, dev); -/* declare CPU hotplug MMIO region and PRS field to access it */ -aml_append (sb_scope,aml_operation_region ( -"PRST" ,AML_SYSTEM_IO ,aml_int (pm->cpu_hp_io_base), pm->cpu_hp_io_len)); - field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); -aml_append (field,aml_named_field ("PRS" ,256 )); -aml_append (sb_scope, field); - -/* build Processor object for each processor */ -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); - - method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), -aml_arg (0 ))) - ); -aml_append (dev, method); - -aml_append (sb_scope, dev); - } - -/* build this code: -* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} -*/ -/* Arg0 = Processor ID = APIC ID */ - method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - - ifctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); -aml_append (ifctx, -aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) - ); -aml_append (method, ifctx); - } -aml_append (sb_scope, method); - -/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" -* -* Note: The ability to create variable-sized packages was first -* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages -* ith up to 255 elements. Windows guests up to win2k8 fail when -* VarPackageOp is used. -*/ - pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : -aml_varpackage (pcms->apic_id_limit); - -for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -for (; apic_idx < apic_id; apic_idx++) { -aml_append (pkg,aml_int (0 )); - } -aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); - apic_idx = apic_id +1 ; - } -aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); -g_free (apic_ids); -} -static void build_memory_devices (Aml *sb_scope,int nr_mem,uint16_t io_base,uint16_t io_len) {@@ -2043,7 +1935,7 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_cpu_hotplug_aml (dsdt); +build_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, pm->cpu_hp_io_len);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2305,8 +2197,6 @@ build_dsdt(GArray *table_data, GArray *linker, sb_scope =aml_scope ("\\_SB" ); { -build_processor_devices (sb_scope, machine, pm); -build_memory_devices (sb_scope, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu_hotplug.h +2
-1@@ -34,5 +34,6 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,#define CPU_STATUS_MAP "PRS"#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx); +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len);#endif
Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
In reply to Igor MammedovQuoted 23 lines · Igor Mammedov
Quoted 12 lines · On Tue, 17 May 2016 09:29:15 -0600 Eric Blake <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/ich9.c | 3 ++ hw/acpi/piix4.c | 3 ++ include/hw/acpi/cpu.h | 4 +++ qapi-schema.json | 3 +- trace-events | 2 ++ 6 files changed, 97 insertions(+), 1 deletion(-)Quoted 8 lines
qapi-schema.json line 4021
Quoted 6 lines
+++
b/qapi-schema.jsonqapi-schema.json +1
-0@@ -4018,8 +4018,9 @@ ## @ACPISlotType # # @DIMM: memory slot +# @CPU: logical CPU slotMissing a marker '(since 2.7)'
Quoted 1 line
thanks, fixed in v2.
v2 was never posted.
Quoted 9 lines
Quoted 7 lines
qapi-schema.json line 4023
Quoted 3 lines
qapi-schema.json +1
-1# -{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] } +{ 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }Hmm. ACPISlotType is already on our whitelist of exceptions that allow upper-case names (we prefer lower), so adding another one doesn't necessarily hurt.
I'll keep that in mind.
Re: [Qemu-devel] [PATCH 06/33] pc: acpi: consolidate \GPE._E02 with the rest of CPU hotplug AML
In reply to Igor MammedovQuoted 25 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug_acpi_table.c | 4 ++++ hw/i386/acpi-build.c | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-)hw/acpi/cpu_hotplug_acpi_table.c +4
-0@@ -235,4 +235,8 @@ void build_cpu_hotplug_aml(Aml *ctx, MachineState *machine,g_free (apic_ids);aml_append (ctx, sb_scope); + + method =aml_method ("\\_GPE._E02" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB." CPU_SCAN_METHOD )); +aml_append (ctx, method); }hw/i386/acpi-build.c +0
-0
hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, · line 1957
Quoted 10 lines
hw/i386/acpi-build.c +0
-4@@ -1952,10 +1952,6 @@ build_dsdt(GArray *table_data, GArray *linker,aml_append (scope, method); } - method =aml_method ("_E02" ,0 ,AML_NOTSERIALIZED ); -aml_append (method,aml_call0 ("\\_SB." CPU_SCAN_METHOD )); -aml_append (scope, method); - method =aml_method ("_E03" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_call0 (MEMORY_HOTPLUG_HANDLER_PATH ));aml_append (scope, method);
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 07/33] pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c
In reply to Igor MammedovQuoted 36 lines · Igor Mammedov
now as those defines are used only locally inside of
cpu_hotplug_acpi_table.c, move them out of header file.Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug_acpi_table.c | 7 +++++++ include/hw/acpi/cpu_hotplug.h | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-)hw/acpi/cpu_hotplug_acpi_table.c +7
-0@@ -17,6 +17,13 @@#include "hw/acpi/cpu_hotplug.h" #include "hw/i386/pc.h" +#define CPU_EJECT_METHOD "CPEJ" +#define CPU_MAT_METHOD "CPMA" +#define CPU_ON_BITMAP "CPON" +#define CPU_STATUS_METHOD "CPST" +#define CPU_STATUS_MAP "PRS" +#define CPU_SCAN_METHOD "PRSC" +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine,uint16_t io_base,uint16_t io_len) {include/hw/acpi/cpu_hotplug.h +0
-0@@ -27,13 +27,6 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,void acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner,AcpiCpuHotplug *gpe_cpu,uint16_t base);
include/hw/acpi/cpu_hotplug.h void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq, · line 32
Quoted 10 lines
include/hw/acpi/cpu_hotplug.h +0
-7-#define CPU_EJECT_METHOD "CPEJ" -#define CPU_MAT_METHOD "CPMA" -#define CPU_ON_BITMAP "CPON" -#define CPU_STATUS_METHOD "CPST" -#define CPU_STATUS_MAP "PRS" -#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine,uint16_t io_base,uint16_t io_len);#endif
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 08/33] pc: acpi: mark current CPU hotplug functions as legacy
In reply to Igor MammedovQuoted 128 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug.c | 8 ++++---- hw/acpi/cpu_hotplug_acpi_table.c | 4 ++-- hw/acpi/ich9.c | 7 ++++--- hw/acpi/piix4.c | 6 +++--- hw/i386/acpi-build.c | 3 ++- include/hw/acpi/cpu_hotplug.h | 12 ++++++------ 6 files changed, 21 insertions(+), 19 deletions(-)hw/acpi/cpu_hotplug.c +4
-4@@ -54,8 +54,8 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); } -void acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, -AcpiCpuHotplug *g,DeviceState *dev,Error **errp) +void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {@@ -65,8 +65,8 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,acpi_send_gpe_event (ar, irq,ACPI_CPU_HOTPLUG_STATUS ); } -void acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, -AcpiCpuHotplug *gpe_cpu,uint16_t base) +void legacy_acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, +AcpiCpuHotplug *gpe_cpu,uint16_t base) {CPUState *cpu;hw/acpi/cpu_hotplug_acpi_table.c +2
-2@@ -24,8 +24,8 @@#define CPU_STATUS_MAP "PRS"#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len) +void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) {Aml *dev;Aml *crs;hw/acpi/ich9.c +4
-3@@ -273,8 +273,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, pm->powerdown_notifier.notify = pm_powerdown_req;qemu_register_powerdown_notifier (&pm->powerdown_notifier); -acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), - &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), +OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE );if (pm->acpi_memory_hotplug.is_enabled) { acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),@@ -437,7 +437,8 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)acpi_memory_plug_cb (&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, &pm->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, + &pm->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));hw/acpi/piix4.c +3
-3@@ -352,7 +352,7 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,acpi_pcihp_device_plug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -570,8 +570,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,acpi_pcihp_init (OBJECT (s), &s->acpi_pci_hotplug, bus, parent, s->use_acpi_pci_hotplug); -acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, -PIIX4_CPU_HOTPLUG_IO_BASE ); +legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, +PIIX4_CPU_HOTPLUG_IO_BASE );if (s->acpi_memory_hotplug.is_enabled) {acpi_memory_hotplug_init (parent,OBJECT (s), &s->acpi_memory_hotplug);hw/i386/acpi-build.c +2
-1@@ -1935,7 +1935,8 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, pm->cpu_hp_io_len); +build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, + pm->cpu_hp_io_len);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu_hotplug.h +2
-2@@ -21,12 +21,12 @@ typedef struct AcpiCpuHotplug {uint8_t sts[ACPI_GPE_PROC_LEN ]; } AcpiCpuHotplug; -void acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, -AcpiCpuHotplug *g,DeviceState *dev,Error **errp); +void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +AcpiCpuHotplug *g,DeviceState *dev,Error **errp);
include/hw/acpi/cpu_hotplug.h typedef struct AcpiCpuHotplug { · line 32
Quoted 10 lines
include/hw/acpi/cpu_hotplug.h +4
-4-void acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, -AcpiCpuHotplug *gpe_cpu,uint16_t base); +void legacy_acpi_cpu_hotplug_init (MemoryRegion *parent,Object *owner, +AcpiCpuHotplug *gpe_cpu,uint16_t base); -void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len); +void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len);#endif
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 09/33] pc: acpi: consolidate legacy CPU hotplug in one file
In reply to Igor MammedovQuoted 518 lines · Igor Mammedov
Since AML part of CPU hotplug is tightly coupled with its hardware part (IO port layout/protocol), move
build_legacy_cpu_hotplug_aml()tocpu_hotplug.cand remove emptycpu_hotplug_acpi_table.cSigned-off-by Igor Mammedov <[email protected]>--- hw/acpi/Makefile.objs | 2 +- hw/acpi/cpu_hotplug.c | 232 ++++++++++++++++++++++++++++++++++++ hw/acpi/cpu_hotplug_acpi_table.c | 249 --------------------------------------- 3 files changed, 233 insertions(+), 250 deletions(-)delete mode 100644
hw/acpi/cpu_hotplug_acpi_table.chw/acpi/Makefile.objs +1
-1@@ -1,6 +1,6 @@ common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o -common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o cpu_hotplug_acpi_table.o +common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.o obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI) += acpi_interface.ohw/acpi/cpu_hotplug.c +232
-0@@ -14,6 +14,14 @@#include "hw/acpi/cpu_hotplug.h" #include "qapi/error.h" #include "qom/cpu.h" +#include "hw/i386/pc.h" + +#define CPU_EJECT_METHOD "CPEJ" +#define CPU_MAT_METHOD "CPMA" +#define CPU_ON_BITMAP "CPON" +#define CPU_STATUS_METHOD "CPST" +#define CPU_STATUS_MAP "PRS" +#define CPU_SCAN_METHOD "PRSC"static uint64_t cpu_status_read (void *opaque,hwaddr addr,unsigned int size) {@@ -77,3 +85,227 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);memory_region_add_subregion (parent, base, &gpe_cpu->io); } + +void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) +{ +Aml *dev; +Aml *crs; +Aml *pkg; +Aml *field; +Aml *method; +Aml *if_ctx; +Aml *else_ctx; +int i, apic_idx; +Aml *sb_scope =aml_scope ("_SB" ); +uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 }; +Aml *cpu_id =aml_arg (0 ); +Aml *cpu_on =aml_local (0 ); +Aml *madt =aml_local (1 ); +Aml *cpus_map =aml_name (CPU_ON_BITMAP ); +Aml *zero =aml_int (0 ); +Aml *one =aml_int (1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); +PCMachineState *pcms =PC_MACHINE (machine); + +/* +* _MAT method - creates an madt apic buffer +* cpu_id = Arg0 = Processor ID = Local APIC ID +* cpu_on = Local0 = CPON flag for this cpu +* madt = Local1 = Buffer (in madt apic form) to return +*/ + method =aml_method (CPU_MAT_METHOD ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); +aml_append (method, +aml_store (aml_buffer (sizeof (madt_tmpl), madt_tmpl), madt)); +/* Update the processor id, lapic id, and enable/disable status */ +aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (2 )))); +aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (3 )))); +aml_append (method,aml_store (cpu_on,aml_index (madt,aml_int (4 )))); +aml_append (method,aml_return (madt)); +aml_append (sb_scope, method); + +/* +* _STA method - return ON status of cpu +* cpu_id = Arg0 = Processor ID = Local APIC ID +* cpu_on = Local0 = CPON flag for this cpu +*/ + method =aml_method (CPU_STATUS_METHOD ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); + if_ctx =aml_if (cpu_on); + { +aml_append (if_ctx,aml_return (aml_int (0xF ))); + } +aml_append (method, if_ctx); + else_ctx =aml_else (); + { +aml_append (else_ctx,aml_return (zero)); + } +aml_append (method, else_ctx); +aml_append (sb_scope, method); + + method =aml_method (CPU_EJECT_METHOD ,2 ,AML_NOTSERIALIZED ); +aml_append (method,aml_sleep (200 )); +aml_append (sb_scope, method); + + method =aml_method (CPU_SCAN_METHOD ,0 ,AML_NOTSERIALIZED ); + { +Aml *while_ctx, *if_ctx2, *else_ctx2; +Aml *bus_check_evt =aml_int (1 ); +Aml *remove_evt =aml_int (3 ); +Aml *status_map =aml_local (5 );/* Local5 = active cpu bitmap */ +Aml *byte =aml_local (2 );/* Local2 = last read byte from bitmap */ +Aml *idx =aml_local (0 );/* Processor ID / APIC ID iterator */ +Aml *is_cpu_on =aml_local (1 );/* Local1 = CPON flag for cpu */ +Aml *status =aml_local (3 );/* Local3 = active state for cpu */ + +aml_append (method,aml_store (aml_name (CPU_STATUS_MAP ), status_map)); +aml_append (method,aml_store (zero, byte)); +aml_append (method,aml_store (zero, idx)); + +/* While (idx < SizeOf(CPON)) */ + while_ctx =aml_while (aml_lless (idx,aml_sizeof (cpus_map))); +aml_append (while_ctx, +aml_store (aml_derefof (aml_index (cpus_map, idx)), is_cpu_on)); + + if_ctx =aml_if (aml_and (idx,aml_int (0x07 ),NULL )); + { +/* Shift down previously read bitmap byte */ +aml_append (if_ctx,aml_shiftright (byte, one, byte)); + } +aml_append (while_ctx, if_ctx); + + else_ctx =aml_else (); + { +/* Read next byte from cpu bitmap */ +aml_append (else_ctx,aml_store (aml_derefof (aml_index (status_map, +aml_shiftright (idx,aml_int (3 ),NULL ))), byte)); + } +aml_append (while_ctx, else_ctx); + +aml_append (while_ctx,aml_store (aml_and (byte, one,NULL ), status)); + if_ctx =aml_if (aml_lnot (aml_equal (is_cpu_on, status))); + { +/* State change - update CPON with new state */ +aml_append (if_ctx,aml_store (status,aml_index (cpus_map, idx))); + if_ctx2 =aml_if (aml_equal (status, one)); + { +aml_append (if_ctx2, +aml_call2 (AML_NOTIFY_METHOD , idx, bus_check_evt)); + } +aml_append (if_ctx, if_ctx2); + else_ctx2 =aml_else (); + { +aml_append (else_ctx2, +aml_call2 (AML_NOTIFY_METHOD , idx, remove_evt)); + } + } +aml_append (if_ctx, else_ctx2); +aml_append (while_ctx, if_ctx); + +aml_append (while_ctx,aml_increment (idx));/* go to next cpu */ +aml_append (method, while_ctx); + } +aml_append (sb_scope, method); + +/* The current AML generator can cover the APIC ID range [0..255], +* inclusive, for VCPU hotplug. */ +QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); +g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); + +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); + +/* build Processor object for each processor */ +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); + + dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + + method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_arg (0 ))) + ); +aml_append (dev, method); + +aml_append (sb_scope, dev); + } + +/* build this code: +* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} +*/ +/* Arg0 = Processor ID = APIC ID */ + method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); +aml_append (if_ctx, +aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) + ); +aml_append (method, if_ctx); + } +aml_append (sb_scope, method); + +/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" +* +* Note: The ability to create variable-sized packages was first +* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages +* ith up to 255 elements. Windows guests up to win2k8 fail when +* VarPackageOp is used. +*/ + pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : +aml_varpackage (pcms->apic_id_limit); + +for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +for (; apic_idx < apic_id; apic_idx++) { +aml_append (pkg,aml_int (0 )); + } +aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); + apic_idx = apic_id +1 ; + } +aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); +g_free (apic_ids); + +aml_append (ctx, sb_scope); + + method =aml_method ("\\_GPE._E02" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB." CPU_SCAN_METHOD )); +aml_append (ctx, method); +}hw/acpi/cpu_hotplug_acpi_table.c deleted +0
-239@@ -1,249 +0,0 @@ -/* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. - -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License along -* with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#include "qemu/osdep.h" -#include "hw/acpi/cpu_hotplug.h" -#include "hw/i386/pc.h" - -#define CPU_EJECT_METHOD "CPEJ" -#define CPU_MAT_METHOD "CPMA" -#define CPU_ON_BITMAP "CPON" -#define CPU_STATUS_METHOD "CPST" -#define CPU_STATUS_MAP "PRS" -#define CPU_SCAN_METHOD "PRSC" - -void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len) -{ -Aml *dev; -Aml *crs; -Aml *pkg; -Aml *field; -Aml *method; -Aml *if_ctx; -Aml *else_ctx; -int i, apic_idx; -Aml *sb_scope =aml_scope ("_SB" ); -uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 }; -Aml *cpu_id =aml_arg (0 ); -Aml *cpu_on =aml_local (0 ); -Aml *madt =aml_local (1 ); -Aml *cpus_map =aml_name (CPU_ON_BITMAP ); -Aml *zero =aml_int (0 ); -Aml *one =aml_int (1 ); -MachineClass *mc =MACHINE_GET_CLASS (machine); -CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); -PCMachineState *pcms =PC_MACHINE (machine); - -/* -* _MAT method - creates an madt apic buffer -* cpu_id = Arg0 = Processor ID = Local APIC ID -* cpu_on = Local0 = CPON flag for this cpu -* madt = Local1 = Buffer (in madt apic form) to return -*/ - method =aml_method (CPU_MAT_METHOD ,1 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); -aml_append (method, -aml_store (aml_buffer (sizeof (madt_tmpl), madt_tmpl), madt)); -/* Update the processor id, lapic id, and enable/disable status */ -aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (2 )))); -aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (3 )))); -aml_append (method,aml_store (cpu_on,aml_index (madt,aml_int (4 )))); -aml_append (method,aml_return (madt)); -aml_append (sb_scope, method); - -/* -* _STA method - return ON status of cpu -* cpu_id = Arg0 = Processor ID = Local APIC ID -* cpu_on = Local0 = CPON flag for this cpu -*/ - method =aml_method (CPU_STATUS_METHOD ,1 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); - if_ctx =aml_if (cpu_on); - { -aml_append (if_ctx,aml_return (aml_int (0xF ))); - } -aml_append (method, if_ctx); - else_ctx =aml_else (); - { -aml_append (else_ctx,aml_return (zero)); - } -aml_append (method, else_ctx); -aml_append (sb_scope, method); - - method =aml_method (CPU_EJECT_METHOD ,2 ,AML_NOTSERIALIZED ); -aml_append (method,aml_sleep (200 )); -aml_append (sb_scope, method); - - method =aml_method (CPU_SCAN_METHOD ,0 ,AML_NOTSERIALIZED ); - { -Aml *while_ctx, *if_ctx2, *else_ctx2; -Aml *bus_check_evt =aml_int (1 ); -Aml *remove_evt =aml_int (3 ); -Aml *status_map =aml_local (5 );/* Local5 = active cpu bitmap */ -Aml *byte =aml_local (2 );/* Local2 = last read byte from bitmap */ -Aml *idx =aml_local (0 );/* Processor ID / APIC ID iterator */ -Aml *is_cpu_on =aml_local (1 );/* Local1 = CPON flag for cpu */ -Aml *status =aml_local (3 );/* Local3 = active state for cpu */ - -aml_append (method,aml_store (aml_name (CPU_STATUS_MAP ), status_map)); -aml_append (method,aml_store (zero, byte)); -aml_append (method,aml_store (zero, idx)); - -/* While (idx < SizeOf(CPON)) */ - while_ctx =aml_while (aml_lless (idx,aml_sizeof (cpus_map))); -aml_append (while_ctx, -aml_store (aml_derefof (aml_index (cpus_map, idx)), is_cpu_on)); - - if_ctx =aml_if (aml_and (idx,aml_int (0x07 ),NULL )); - { -/* Shift down previously read bitmap byte */ -aml_append (if_ctx,aml_shiftright (byte, one, byte)); - } -aml_append (while_ctx, if_ctx); - - else_ctx =aml_else (); - { -/* Read next byte from cpu bitmap */ -aml_append (else_ctx,aml_store (aml_derefof (aml_index (status_map, -aml_shiftright (idx,aml_int (3 ),NULL ))), byte)); - } -aml_append (while_ctx, else_ctx); - -aml_append (while_ctx,aml_store (aml_and (byte, one,NULL ), status)); - if_ctx =aml_if (aml_lnot (aml_equal (is_cpu_on, status))); - { -/* State change - update CPON with new state */ -aml_append (if_ctx,aml_store (status,aml_index (cpus_map, idx))); - if_ctx2 =aml_if (aml_equal (status, one)); - { -aml_append (if_ctx2, -aml_call2 (AML_NOTIFY_METHOD , idx, bus_check_evt)); - } -aml_append (if_ctx, if_ctx2); - else_ctx2 =aml_else (); - { -aml_append (else_ctx2, -aml_call2 (AML_NOTIFY_METHOD , idx, remove_evt)); - } - } -aml_append (if_ctx, else_ctx2); -aml_append (while_ctx, if_ctx); - -aml_append (while_ctx,aml_increment (idx));/* go to next cpu */ -aml_append (method, while_ctx); - } -aml_append (sb_scope, method); - -/* The current AML generator can cover the APIC ID range [0..255], -* inclusive, for VCPU hotplug. */ -QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); -g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); - -/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ - dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); -aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); -aml_append (dev, -aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) - ); -/* device present, functioning, decoding, not shown in UI */ -aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); - crs =aml_resource_template (); -aml_append (crs, -aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) - ); -aml_append (dev,aml_name_decl ("_CRS" , crs)); -aml_append (sb_scope, dev); -/* declare CPU hotplug MMIO region and PRS field to access it */ -aml_append (sb_scope,aml_operation_region ( -"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); - field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); -aml_append (field,aml_named_field ("PRS" ,256 )); -aml_append (sb_scope, field); - -/* build Processor object for each processor */ -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); - - method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), -aml_arg (0 ))) - ); -aml_append (dev, method); - -aml_append (sb_scope, dev); - } - -/* build this code: -* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} -*/ -/* Arg0 = Processor ID = APIC ID */ - method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - - if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); -aml_append (if_ctx, -aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) - ); -aml_append (method, if_ctx); - } -aml_append (sb_scope, method); - -/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" -* -* Note: The ability to create variable-sized packages was first -* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages -* ith up to 255 elements. Windows guests up to win2k8 fail when -* VarPackageOp is used. -*/ - pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : -aml_varpackage (pcms->apic_id_limit); - -for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -for (; apic_idx < apic_id; apic_idx++) { -aml_append (pkg,aml_int (0 )); - } -aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); - apic_idx = apic_id +1 ;
hw/acpi/cpu_hotplug_acpi_table.c line 249
Quoted 10 lines
hw/acpi/cpu_hotplug_acpi_table.c deleted +0
-10- } -aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); -g_free (apic_ids); - -aml_append (ctx, sb_scope); - - method =aml_method ("\\_GPE._E02" ,0 ,AML_NOTSERIALIZED ); -aml_append (method,aml_call0 ("\\_SB." CPU_SCAN_METHOD )); -aml_append (ctx, method); -}
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 10/33] pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature
In reply to Igor MammedovQuoted 77 lines · Igor Mammedov
since IO block used by CPU hotplug is fixed size and initialized it the same file as
build_legacy_cpu_hotplug_aml()just useACPI_GPE_PROC_LENdirectly instead of passing it around in several files.Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug.c | 6 +++--- hw/i386/acpi-build.c | 5 +---- include/hw/acpi/cpu_hotplug.h | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-)hw/acpi/cpu_hotplug.c +3
-3@@ -87,7 +87,7 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, }void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len) +uint16_t io_base) {Aml *dev;Aml *crs;@@ -226,13 +226,13 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); crs =aml_resource_template ();aml_append (crs, -aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) +aml_io (AML_DECODE16 , io_base, io_base,1 ,ACPI_GPE_PROC_LEN ) );aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (sb_scope, dev);/* declare CPU hotplug MMIO region and PRS field to access it */ aml_append (sb_scope,aml_operation_region ( -"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base),ACPI_GPE_PROC_LEN )); field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE );aml_append (field,aml_named_field ("PRS" ,256 ));aml_append (sb_scope, field);hw/i386/acpi-build.c +1
-4@@ -94,7 +94,6 @@ typedef struct AcpiPmInfo {uint32_t gpe0_blk_len;uint32_t io_base;uint16_t cpu_hp_io_base; -uint16_t cpu_hp_io_len;uint16_t mem_hp_io_base;uint16_t mem_hp_io_len;uint16_t pcihp_io_base;@@ -142,7 +141,6 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) }assert (obj); - pm->cpu_hp_io_len =ACPI_GPE_PROC_LEN ; pm->mem_hp_io_base =ACPI_MEMORY_HOTPLUG_BASE ; pm->mem_hp_io_len =ACPI_MEMORY_HOTPLUG_IO_LEN ;@@ -1935,8 +1933,7 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, - pm->cpu_hp_io_len); +build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu_hotplug.h +0
-0
include/hw/acpi/cpu_hotplug.h void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, · line 32
Quoted 6 lines
include/hw/acpi/cpu_hotplug.h +1
-1@@ -28,5 +28,5 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, AcpiCpuHotplug *gpe_cpu, uint16_t base);void build_legacy_cpu_hotplug_aml (Aml *ctx,MachineState *machine, -uint16_t io_base,uint16_t io_len); +uint16_t io_base);#endif
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx
In reply to Igor MammedovQuoted 22 lines · Igor Mammedov
In legacy cpu-hotplug ProcessorID == APIC ID is used in MADT and cpu-hotplug AML. It was fine as both are 8bit and unique. Spec depricated
Processor()with corresponding ProcessorID and advises to useDevice()and UID instead of it.However UID is just 32bit and it can't fit ARM's
arch_id(MPIDR)which is 64bit. Also in case of sparsearch_id()distribution, managment/lookup of maps byarch_id(APIC ID/MPIDR)becomes complex and expensive.In preparation to common CPU hotplug with ARM and to simplify lookup in possible_cpus[] map switch ProcessorID to
possible_cpusindex in MADT.Legacy cpu-hotplug considerations:
HW interface of it is APIC ID based bitmask so it's impossible to change, also CPON package in AML also APIC ID based as well all the methods.
Quoted 9 lines
To avoid massive rewrite of AML keep is so and just break assumption that ProcessorID == APIC ID, ammending
CPU_MAT_METHODto accept APIC ID andpossible_cpusindex, it needs them both to patch MADT entry template. Also switch topossible_cpusindex Processor(ProcessorID) AML.
That way changes to MADT/AML are minimal and kept inside AML/MADT not affecting external interfaces.
I vaguely understood the explanation, I'll let Eduardo have a look :)
Thanks,
Marcel
Quoted 96 lines
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug.c | 23 +++++++++++++---------- hw/i386/acpi-build.c | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)hw/acpi/cpu_hotplug.c +13
-10@@ -99,7 +99,8 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 }; -Aml *cpu_id =aml_arg (0 ); +Aml *cpu_id =aml_arg (1 ); +Aml *apic_id =aml_arg (0 );Aml *cpu_on =aml_local (0 );Aml *madt =aml_local (1 );Aml *cpus_map =aml_name (CPU_ON_BITMAP );@@ -111,30 +112,31 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* * _MAT method - creates an madt apic buffer -* cpu_id = Arg0 = Processor ID = Local APIC ID +* apic_id = Arg0 = Local APIC ID +* cpu_id = Arg1 = Processor ID * cpu_on = Local0 = CPON flag for this cpu * madt = Local1 = Buffer (in madt apic form) to return */ - method =aml_method (CPU_MAT_METHOD ,1 ,AML_NOTSERIALIZED ); + method =aml_method (CPU_MAT_METHOD ,2 ,AML_NOTSERIALIZED );aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); +aml_store (aml_derefof (aml_index (cpus_map, apic_id)), cpu_on));aml_append (method,aml_store (aml_buffer (sizeof (madt_tmpl), madt_tmpl), madt));/* Update the processor id, lapic id, and enable/disable status */ aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (2 )))); -aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (3 )))); +aml_append (method,aml_store (apic_id,aml_index (madt,aml_int (3 ))));aml_append (method,aml_store (cpu_on,aml_index (madt,aml_int (4 ))));aml_append (method,aml_return (madt));aml_append (sb_scope, method);/* * _STA method - return ON status of cpu -* cpu_id = Arg0 = Processor ID = Local APIC ID +* apic_id = Arg0 = Local APIC ID * cpu_on = Local0 = CPON flag for this cpu */ method =aml_method (CPU_STATUS_METHOD ,1 ,AML_NOTSERIALIZED );aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); +aml_store (aml_derefof (aml_index (cpus_map, apic_id)), cpu_on)); if_ctx =aml_if (cpu_on); {aml_append (if_ctx,aml_return (aml_int (0xF )));@@ -243,11 +245,12 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + dev =aml_processor (i,0 ,0 ,"CP%.02X" , apic_id); method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_return (aml_call2 (CPU_MAT_METHOD ,aml_int (apic_id),aml_int (i)) + ));aml_append (dev, method); method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED );@@ -268,7 +271,7 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* build this code: * Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} */ -/* Arg0 = Processor ID = APIC ID */ +/* Arg0 = APIC ID */ method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED );for (i =0 ; i < apic_ids->len; i++) {int apic_id = apic_ids->cpus[i].arch_id;hw/i386/acpi-build.c +1
-1@@ -354,7 +354,7 @@ build_madt(GArray *table_data, GArray *linker, PCMachineState *pcms) apic->type =ACPI_APIC_PROCESSOR ; apic->length =sizeof (*apic); - apic->processor_id = apic_id; + apic->processor_id = i; apic->local_apic_id = apic_id;if (apic_ids->cpus[i].cpu !=NULL ) { apic->flags =cpu_to_le32 (1 );
Re: [Qemu-devel] [PATCH 13/33] acpi: extend ACPI interface to provide send_event hook
In reply to Igor MammedovQuoted 139 lines · Igor Mammedov
send_event()hook will allow to send ACPI event in a target specific way (GPE or GPIO based impl.) it will also simplify proxy wrappers in piix4pm/ich9 that access ACPI regs and SCI which are part of piix4pm/lcp_ich9 devices and callacpi_foo()API directly.Signed-off-by Igor Mammedov <[email protected]>---
Following patch will use hook to simplify hotplug callbacks in piix4pm/ich9.--- hw/acpi/core.c | 2 +- hw/acpi/piix4.c | 8 ++++++++ hw/isa/lpc_ich9.c | 8 ++++++++ include/hw/acpi/acpi.h | 10 ++-------- include/hw/acpi/acpi_dev_interface.h | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 9 deletions(-)hw/acpi/core.c +1
-1@@ -692,7 +692,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) }void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status) +AcpiEventStatusBits status) { ar->gpe.sts[0 ] |= status;acpi_update_sci (ar, irq);hw/acpi/piix4.c +8
-0@@ -585,6 +585,13 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); } +static void piix4_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +PIIX4PMState *s =PIIX4_PM (adev); + +acpi_send_gpe_event (&s->ar, s->irq, ev); +} +static Property piix4_pm_properties[] = {DEFINE_PROP_UINT32 ("smb_io_base" , PIIX4PMState, smb_io_base,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),@@ -623,6 +630,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug_request = piix4_device_unplug_request_cb; hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; + adevc->send_event = piix4_send_gpe; }static const TypeInfo piix4_pm_info = {hw/isa/lpc_ich9.c +8
-0@@ -702,6 +702,13 @@ static Property ich9_lpc_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void ich9_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (adev); + +acpi_send_gpe_event (&s->pm.acpi_regs, s->pm.irq, ev); +} +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -729,6 +736,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug_request = ich9_device_unplug_request_cb; hc->unplug = ich9_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; + adevc->send_event = ich9_send_gpe; }static const TypeInfo ich9_lpc_info = {include/hw/acpi/acpi.h +2
-8@@ -23,6 +23,7 @@#include "qemu/option.h" #include "exec/memory.h" #include "hw/irq.h" +#include "hw/acpi/acpi_dev_interface.h" /* * current device naming scheme supports up to 256 memory devices @@ -89,13 +90,6 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 -/* These values are part of guest ABI, and can not be changed */ -typedef enum { -ACPI_PCI_HOTPLUG_STATUS =2 , -ACPI_CPU_HOTPLUG_STATUS =4 , -ACPI_MEMORY_HOTPLUG_STATUS =8 , -}AcpiGPEStatusBits ; -/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;@@ -179,7 +173,7 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr);void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status); +AcpiEventStatusBits status);void acpi_update_sci (ACPIREGS *acpi_regs,qemu_irq irq);include/hw/acpi/acpi_dev_interface.h +7
-0@@ -4,6 +4,13 @@#include "qom/object.h" #include "qapi-types.h" +/* These values are part of guest ABI, and can not be changed */ +typedef enum { +ACPI_PCI_HOTPLUG_STATUS =2 , +ACPI_CPU_HOTPLUG_STATUS =4 , +ACPI_MEMORY_HOTPLUG_STATUS =8 , +}AcpiEventStatusBits ; +#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"#define ACPI_DEVICE_IF_CLASS (klass) \@@ -22,11 +29,21 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf;
include/hw/acpi/acpi_dev_interface.h typedef struct AcpiDeviceIf { · line 40
Quoted 10 lines
include/hw/acpi/acpi_dev_interface.h +9
-0+#define ACPI_SEND_EVENT (dev, event) \ + do { \ + AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(dev); \ + if (adevc->send_event) { \ + AcpiDeviceIf *adev = ACPI_DEVICE_IF(dev); \ + adevc->send_event(adev, event); \ + } \ + } while (0) +
Does it have to be a macro? I would prefer a function if is possible.
Thanks,
Marcel
Quoted 17 lines
include/hw/acpi/acpi_dev_interface.h +2
-0/** * AcpiDeviceIfClass: * * ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. +* send_event: inject a specified event into guest * * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without @@ -39,5 +56,6 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); } AcpiDeviceIfClass;#endif
Re: [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug
In reply to Igor MammedovQuoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>
Maybe it worth adding some kind of explanation
of the functionality added here.
Thanks,
Marcel
Quoted 312 lines
---
v1:
- drop CPUHotplugState.is_enabled field--- hw/acpi/Makefile.objs | 1 + hw/acpi/cpu.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/cpu.h | 52 +++++++++++++ trace-events | 9 +++ 4 files changed, 268 insertions(+)create mode 100644
hw/acpi/cpu.c
create mode 100644include/hw/acpi/cpu.hhw/acpi/Makefile.objs +1
-0@@ -2,6 +2,7 @@ common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.o +common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI) += acpi_interface.o common-obj-$(CONFIG_ACPI) += bios-linker-loader.ohw/acpi/cpu.c new file +206
-0@@ -0,0 +1,206 @@ +#include "qemu/osdep.h" +#include "hw/boards.h" +#include "hw/acpi/cpu.h" +#include "qapi/error.h" +#include "trace.h" + +#define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SELECTOR_OFFSET_WR 0 +#define ACPI_CPU_FLAGS_OFFSET_RW 4 + +static uint64_t cpu_hotplug_rd (void *opaque,hwaddr addr,unsigned size) +{ +uint64_t val = ~0 ; +CPUHotplugState *cpu_st = opaque; +AcpiCpuStatus *cdev; + +if (cpu_st->selector >= cpu_st->dev_count) { +return val; + } + + cdev = &cpu_st->devs[cpu_st->selector]; +switch (addr) { +case ACPI_CPU_FLAGS_OFFSET_RW :/* pack and return is_* fields */ + val =0 ; + val |= cdev->is_enabled ?1 :0 ; + val |= cdev->is_inserting ?2 :0 ; + val |= cdev->is_removing ?4 :0 ; +trace_cpuhp_acpi_read_flags (cpu_st->selector, val); +break ; +default : +break ; + } +return val; +} + +static void cpu_hotplug_wr (void *opaque,hwaddr addr,uint64_t data, +unsigned int size) +{ +CPUHotplugState *cpu_st = opaque; +AcpiCpuStatus *cdev; +Error *local_err =NULL ; + +assert (cpu_st->dev_count); + +if (addr) { +if (cpu_st->selector >= cpu_st->dev_count) { +trace_cpuhp_acpi_invalid_idx_selected (cpu_st->selector); +return ; + } + } + +switch (addr) { +case ACPI_CPU_SELECTOR_OFFSET_WR :/* current CPU selector */ + cpu_st->selector = data; +trace_cpuhp_acpi_write_idx (cpu_st->selector); +break ; +case ACPI_CPU_FLAGS_OFFSET_RW :/* set is_* fields */ + cdev = &cpu_st->devs[cpu_st->selector]; +if (data &2 ) {/* clear insert event */ + cdev->is_inserting = false; +trace_cpuhp_acpi_clear_inserting_evt (cpu_st->selector); + }else if (data &4 ) {/* clear remove event */ + cdev->is_removing = false; +trace_cpuhp_acpi_clear_remove_evt (cpu_st->selector); + }else if (data &8 ) { +DeviceState *dev =NULL ; +HotplugHandler *hotplug_ctrl =NULL ; + +if (!cdev->is_enabled) { +trace_cpuhp_acpi_ejecting_invalid_cpu (cpu_st->selector); +break ; + } + +trace_cpuhp_acpi_ejecting_cpu (cpu_st->selector); + dev =DEVICE (cdev->cpu); + hotplug_ctrl =qdev_get_hotplug_handler (dev); +hotplug_handler_unplug (hotplug_ctrl, dev, &local_err); +if (local_err) { +break ; + } + } +break ; +default : +break ; + } +error_free (local_err); +} + +static const MemoryRegionOps cpu_hotplug_ops = { + .read = cpu_hotplug_rd, + .write = cpu_hotplug_wr, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =4 , + }, +}; + +void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner, +CPUHotplugState *state,hwaddr base_addr) +{ +MachineState *machine =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *id_list; +int i; + + id_list = mc->possible_cpu_arch_ids (machine); + state->dev_count = id_list->len; + state->devs =g_new0 (typeof (*state->devs), state->dev_count); +for (i =0 ; i < id_list->len; i++) { + state->devs[i].cpu = id_list->cpus[i].cpu; + state->devs[i].arch_id = id_list->cpus[i].arch_id; + state->devs[i].is_enabled = id_list->cpus[i].cpu ? true : false; + } +g_free (id_list); +memory_region_init_io (&state->ctrl_reg, owner, &cpu_hotplug_ops, state, +"acpi-mem-hotplug" ,ACPI_CPU_HOTPLUG_REG_LEN ); +memory_region_add_subregion (as, base_addr, &state->ctrl_reg); +} + +static AcpiCpuStatus *get_cpu_status (CPUHotplugState *cpu_st,DeviceState *dev) +{ +CPUClass *k =CPU_GET_CLASS (dev); +uint64_t cpu_arch_id = k->get_arch_id (CPU (dev)); +int i; + +for (i =0 ; i < cpu_st->dev_count; i++) { +if (cpu_arch_id == cpu_st->devs[i].arch_id) { +return &cpu_st->devs[i]; + } + } +return NULL ; +} + +void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st,DeviceState *dev,Error **errp) +{ +AcpiCpuStatus *cdev; + + cdev =get_cpu_status (cpu_st, dev); +if (!cdev) { +return ; + } + + cdev->cpu =CPU (dev); + cdev->is_enabled = true; +if (dev->hotplugged) { + cdev->is_inserting = true; +ACPI_SEND_EVENT (hotplug_dev,ACPI_CPU_HOTPLUG_STATUS ); + } +} + +void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp) +{ +AcpiCpuStatus *cdev; + + cdev =get_cpu_status (cpu_st, dev); +if (!cdev) { +return ; + } + + cdev->is_removing = true; +ACPI_SEND_EVENT (hotplug_dev,ACPI_CPU_HOTPLUG_STATUS ); +} + +void acpi_cpu_unplug_cb (CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp) +{ +AcpiCpuStatus *cdev; + + cdev =get_cpu_status (cpu_st, dev); +if (!cdev) { +return ; + } + + cdev->cpu =NULL ; + cdev->is_enabled = false; +} + +static const VMStateDescription vmstate_cpuhp_sts = { + .name ="CPU hotplug device state" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_BOOL (is_enabled, AcpiCpuStatus), +VMSTATE_BOOL (is_inserting, AcpiCpuStatus), +VMSTATE_BOOL (is_removing, AcpiCpuStatus), +VMSTATE_END_OF_LIST () + } +}; + +const VMStateDescription vmstate_cpu_hotplug = { + .name ="CPU hotplug state" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (selector, CPUHotplugState), +VMSTATE_STRUCT_VARRAY_POINTER_UINT32 (devs, CPUHotplugState, dev_count, + vmstate_cpuhp_sts, AcpiCpuStatus), +VMSTATE_END_OF_LIST () + } +};include/hw/acpi/cpu.h new file +52
-0@@ -0,0 +1,52 @@ +/* +* QEMU ACPI hotplug utilities +* +* Copyright (C) 2016 Red Hat Inc +* +* Authors: +* Igor Mammedov <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef ACPI_CPU_H +#define ACPI_CPU_H + +#include "hw/qdev-core.h" +#include "hw/acpi/acpi.h" +#include "hw/hotplug.h" + +typedef struct AcpiCpuStatus { +struct CPUState *cpu; +uint64_t arch_id; +bool is_enabled; +bool is_inserting; +bool is_removing; +}AcpiCpuStatus ; + +typedef struct CPUHotplugState { +MemoryRegion ctrl_reg; +uint32_t selector; +uint32_t dev_count; +AcpiCpuStatus *devs; +}CPUHotplugState ; + +void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st,DeviceState *dev,Error **errp); + +void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp); + +void acpi_cpu_unplug_cb (CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp); + +void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner, +CPUHotplugState *state,hwaddr base_addr); + +extern const VMStateDescription vmstate_cpu_hotplug; +#define VMSTATE_CPU_HOTPLUG (cpuhp, state) \ + VMSTATE_STRUCT(cpuhp, state, 1, \ + vmstate_cpu_hotplug, CPUHotplugState) + +#endif trace-events +9
-0@@ -1908,3 +1908,12 @@ aspeed_vic_update_fiq(int flags) "Raising FIQ: %d" aspeed_vic_update_irq(int flags) "Raising IRQ: %d" aspeed_vic_read(uint64_t offset, unsigned size, uint32_t value) "From 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 + +# hw/acpi/cpu.c +cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32 +cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8 +cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]" +cpuhp_acpi_clear_remove_evt(uint32_t idx) "idx[0x%"PRIx32"]" +cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32 +cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32 +cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32
Re: [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine
In reply to Igor MammedovQuoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>
Eduardo also posted a patch for 2.7 machine.
Thanks,
Marcel
Quoted 114 lines
--- hw/i386/pc_piix.c | 16 +++++++++++++--- hw/i386/pc_q35.c | 13 +++++++++++-- include/hw/compat.h | 3 +++ include/hw/i386/pc.h | 4 ++++ 4 files changed, 31 insertions(+), 5 deletions(-)hw/i386/pc_piix.c +13
-3@@ -416,13 +416,25 @@ static void pc_i440fx_machine_options(MachineClass *m) m->default_display ="std" ; } -static void pc_i440fx_2_6_machine_options (MachineClass *m) +static void pc_i440fx_2_7_machine_options (MachineClass *m) {pc_i440fx_machine_options (m); m->alias ="pc" ; m->is_default =1 ; } +DEFINE_I440FX_MACHINE (v2_7,"pc-i440fx-2.7" ,NULL , + pc_i440fx_2_7_machine_options); + + +static void pc_i440fx_2_6_machine_options (MachineClass *m) +{ +pc_i440fx_2_7_machine_options (m); + m->is_default =0 ; + m->alias =NULL ; +SET_MACHINE_COMPAT (m,PC_COMPAT_2_6 ); +} +DEFINE_I440FX_MACHINE (v2_6,"pc-i440fx-2.6" ,NULL , pc_i440fx_2_6_machine_options);@@ -431,8 +443,6 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_2_6_machine_options (m); - m->alias =NULL ; - m->is_default =0 ; pcmc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 );hw/i386/pc_q35.c +11
-2@@ -283,12 +283,22 @@ static void pc_q35_machine_options(MachineClass *m) m->no_floppy =1 ; } -static void pc_q35_2_6_machine_options (MachineClass *m) +static void pc_q35_2_7_machine_options (MachineClass *m) {pc_q35_machine_options (m); m->alias ="q35" ; } +DEFINE_Q35_MACHINE (v2_7,"pc-q35-2.7" ,NULL , + pc_q35_2_7_machine_options); + +static void pc_q35_2_6_machine_options (MachineClass *m) +{ +pc_q35_2_7_machine_options (m); + m->alias =NULL ; +SET_MACHINE_COMPAT (m,PC_COMPAT_2_6 ); +} +DEFINE_Q35_MACHINE (v2_6,"pc-q35-2.6" ,NULL , pc_q35_2_6_machine_options);@@ -296,7 +306,6 @@ static void pc_q35_2_5_machine_options(MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_2_6_machine_options (m); - m->alias =NULL ; pcmc->save_tsc_khz = false; m->legacy_fw_cfg_order =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 );include/hw/compat.h +3
-0@@ -1,6 +1,9 @@#ifndef HW_COMPAT_H #define HW_COMPAT_H +#define HW_COMPAT_2_6 \ +/* empty */ +#define HW_COMPAT_2_5 \ {\ .driver = "isa-fdc",\include/hw/i386/pc.h +4
-0@@ -356,7 +356,11 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);int e820_get_num_entries (void );bool e820_get_entry (int ,uint32_t ,uint64_t *,uint64_t *); +#define PC_COMPAT_2_6 \ + HW_COMPAT_2_6 +#define PC_COMPAT_2_5 \ + PC_COMPAT_2_6 \ HW_COMPAT_2_5#define PC_COMPAT_2_4 \
Re: [Qemu-devel] [PATCH 19/33] pc: piix4/ich9: add 'cpu-hotplug-legacy' property
In reply to Igor MammedovQuoted 125 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/ich9.c | 29 ++++++++++++++++++++++++++--- hw/acpi/piix4.c | 12 +++++++++--- include/hw/acpi/ich9.h | 1 + 3 files changed, 36 insertions(+), 6 deletions(-)hw/acpi/ich9.c +26
-3@@ -273,8 +273,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, pm->powerdown_notifier.notify = pm_powerdown_req;qemu_register_powerdown_notifier (&pm->powerdown_notifier); -legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +if (pm->cpu_hotplug_legacy) { +legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), +OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); + }if (pm->acpi_memory_hotplug.is_enabled) { acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),@@ -306,6 +308,21 @@ static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value, s->pm.acpi_memory_hotplug.is_enabled = value; } +static bool ich9_pm_get_cpu_hotplug_legacy (Object *obj,Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); + +return s->pm.cpu_hotplug_legacy; +} + +static void ich9_pm_set_cpu_hotplug_legacy (Object *obj,bool value, +Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); + + s->pm.cpu_hotplug_legacy = value; +} +static void ich9_pm_get_disable_s3 (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {@@ -397,6 +414,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; + pm->cpu_hotplug_legacy = true; pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;@@ -412,6 +430,10 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) ich9_pm_get_memory_hotplug_support, ich9_pm_set_memory_hotplug_support, NULL); +object_property_add_bool (obj,"cpu-hotplug-legacy" , + ich9_pm_get_cpu_hotplug_legacy, + ich9_pm_set_cpu_hotplug_legacy, +NULL ); object_property_add(obj, ACPI_PM_PROP_S3_DISABLED, "uint8", ich9_pm_get_disable_s3, ich9_pm_set_disable_s3,@@ -439,7 +461,8 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + } else if (lpc->pm.cpu_hotplug_legacy && +object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) {legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); } else { error_setg(errp, "acpi: device plug request for not supported device"hw/acpi/piix4.c +9
-3@@ -85,6 +85,7 @@ typedef struct PIIX4PMState {uint8_t disable_s4;uint8_t s4_val; +bool cpu_hotplug_legacy;AcpiCpuHotplug gpe_cpu;MemHotplugState acpi_memory_hotplug;@@ -350,7 +351,8 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); - }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { + }else if (s->cpu_hotplug_legacy && +object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); }else { error_setg(errp, "acpi: device plug request for not supported device"@@ -569,8 +571,10 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,acpi_pcihp_init (OBJECT (s), &s->acpi_pci_hotplug, bus, parent, s->use_acpi_pci_hotplug); -legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, -PIIX4_CPU_HOTPLUG_IO_BASE ); +if (s->cpu_hotplug_legacy) { +legacy_acpi_cpu_hotplug_init (parent,OBJECT (s), &s->gpe_cpu, +PIIX4_CPU_HOTPLUG_IO_BASE ); + }if (s->acpi_memory_hotplug.is_enabled) {acpi_memory_hotplug_init (parent,OBJECT (s), &s->acpi_memory_hotplug);@@ -600,6 +604,8 @@ static Property piix4_pm_properties[] = { use_acpi_pci_hotplug, true),DEFINE_PROP_BOOL ("memory-hotplug-support" , PIIX4PMState, acpi_memory_hotplug.is_enabled, true), +DEFINE_PROP_BOOL ("cpu-hotplug-legacy" , PIIX4PMState, + cpu_hotplug_legacy, true), DEFINE_PROP_END_OF_LIST(), };include/hw/acpi/ich9.h +0
-0
include/hw/acpi/ich9.h typedef struct ICH9LPCPMRegs { · line 54
Quoted 7 lines
include/hw/acpi/ich9.h +1
-0@@ -48,6 +48,7 @@ typedef struct ICH9LPCPMRegs {uint32_t pm_io_base;Notifier powerdown_notifier; +bool cpu_hotplug_legacy;AcpiCpuHotplug gpe_cpu;MemHotplugState acpi_memory_hotplug;
Looks OK to me.
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
In reply to Igor MammedovQuoted 66 lines · Igor Mammedov
add necessary wiring to init new CPU hotplug hardware if ICH9-LPC.cpu-hotplug-legacy is "off".
Set ICH9-LPC.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.Signed-off-by Igor Mammedov <[email protected]>---
v1:
- drop ICH9-LPC.cpu-hotplug property--- hw/acpi/ich9.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/acpi/ich9.h | 6 +++++- include/hw/compat.h | 6 +++++- 3 files changed, 47 insertions(+), 7 deletions(-)hw/acpi/ich9.c +23
-1@@ -170,6 +170,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="ich9_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, ICH9LPCPMRegs), +VMSTATE_END_OF_LIST () + } +}; +static bool vmstate_test_use_tco (void *opaque) {ICH9LPCPMRegs *s = opaque;@@ -209,6 +227,7 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, &vmstate_tco_io_state, + &vmstate_cpuhp_state,NULL } };@@ -275,7 +294,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,if (pm->cpu_hotplug_legacy) {legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +OBJECT (lpc_pci), &pm->cpuhp.legacy,ICH9_CPU_HOTPLUG_IO_BASE ); + }else { +cpu_hotplug_hw_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), + &pm->cpuhp.state,ICH9_CPU_HOTPLUG_IO_BASE ); }if (pm->acpi_memory_hotplug.is_enabled) {
hw/acpi/ich9.c void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) · line 417
Quoted 4 lines
hw/acpi/ich9.c +0
-1@@ -414,7 +436,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; - pm->cpu_hotplug_legacy = true;
Maybe is too soon to disable legacy CPU hotplug? Will the new cpu hotplug mechanism work from this patch on, or it will break git bisect?
Thanks,
Marcel
Quoted 83 lines
hw/acpi/ich9.c +14
-3pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;@@ -461,9 +482,13 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (lpc->pm.cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { +if (lpc->pm.cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.legacy, dev, + errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.state, dev, errp); + } } else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -480,6 +505,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp.state, + dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -494,6 +523,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&lpc->pm.cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));include/hw/acpi/ich9.h +5
-1@@ -23,6 +23,7 @@#include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" @@ -49,7 +50,10 @@ typedef struct ICH9LPCPMRegs {Notifier powerdown_notifier;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug;include/hw/compat.h +5
-1@@ -2,7 +2,11 @@#define HW_COMPAT_H #define HW_COMPAT_2_6 \ -/* empty */ + {\ + .driver = "ICH9-LPC",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Re: [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine
In reply to Marcel ApfelbaumQuoted 5 lines · Marcel Apfelbaum
Quoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>Eduardo also posted a patch for 2.7 machine.
It was the same patch, with a "From:" line from Igor.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods to DSDT
In reply to Igor MammedovQuoted 102 lines · Igor Mammedov
Add necessary CPU hotplug methods to handle hotplug events.
Signed-off-by Igor Mammedov <[email protected]>---
v1:
- make replace_MATmethod with named buffer object as its content is static--- hw/acpi/cpu.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 3 +- include/hw/acpi/cpu.h | 4 +- 3 files changed, 190 insertions(+), 4 deletions(-)hw/acpi/cpu.c +70
-2@@ -207,24 +207,178 @@ const VMStateDescription vmstate_cpu_hotplug = { };#define CPU_NAME_FMT "C%.03X" - -void build_cpus_aml (Aml *table,MachineState *machine,bool acpi1_compat) +#define CPUHP_RES_DEVICE "PRES" +#define CPU_LOCK "CPLK" +#define CPU_STS_METHOD "CSTA" +#define CPU_SCAN_METHOD "CSCN" +#define CPU_EJECT_METHOD "CEJ0" +#define CPU_NOTIFY_METHOD "CTFY" + +#define CPU_ENABLED "CPEN" +#define CPU_SELECTOR "CSEL" +#define CPU_EJECT_EVENT "CEJ0" +#define CPU_INSERT_EVENT "CINS" +#define CPU_REMOVE_EVENT "CRMV" + +void build_cpus_aml (Aml *table,MachineState *machine,bool acpi1_compat, +const char *res_root,const char *event_handler_method, +hwaddr io_base) { +Aml *ifctx; +Aml *field; +Aml *method; +Aml *cpu_ctrl_dev;Aml *cpus_dev; +Aml *zero =aml_int (0 );Aml *sb_scope =aml_scope ("_SB" );MachineClass *mc =MACHINE_GET_CLASS (machine);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); +AcpiDeviceIf *adev =ACPI_DEVICE_IF (obj); + + cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); + { +Aml *crs; + +aml_append (cpu_ctrl_dev, +aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (cpu_ctrl_dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" ))); +aml_append (cpu_ctrl_dev,aml_mutex (CPU_LOCK ,0 )); + + crs =aml_resource_template (); +aml_append (crs,aml_io (AML_DECODE16 , io_base, io_base,1 , +ACPI_CPU_HOTPLUG_REG_LEN )); +aml_append (cpu_ctrl_dev,aml_name_decl ("_CRS" , crs)); + +/* declare CPU hotplug MMIO region with related access fields */ +aml_append (cpu_ctrl_dev, +aml_operation_region ("PRST" ,AML_SYSTEM_IO ,aml_int (io_base), +ACPI_CPU_HOTPLUG_REG_LEN )); + + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK , +AML_WRITE_AS_ZEROS ); +aml_append (field,aml_reserved_field (ACPI_CPU_FLAGS_OFFSET_RW *8 )); +/* 1 if enabled, read only */ +aml_append (field,aml_named_field (CPU_ENABLED ,1 )); +/* (read) 1 if has a insert event. (write) 1 to clear event */ +aml_append (field,aml_named_field (CPU_INSERT_EVENT ,1 )); +/* (read) 1 if has a remove event. (write) 1 to clear event */ +aml_append (field,aml_named_field (CPU_REMOVE_EVENT ,1 )); +/* initiates device eject, write only */ +aml_append (field,aml_named_field (CPU_EJECT_EVENT ,1 )); +aml_append (cpu_ctrl_dev, field); + + field =aml_field ("PRST" ,AML_DWORD_ACC ,AML_NOLOCK ,AML_PRESERVE ); +/* CPU selector, write only */ +aml_append (field,aml_named_field (CPU_SELECTOR ,32 )); +aml_append (cpu_ctrl_dev, field); + + } +aml_append (sb_scope, cpu_ctrl_dev); + cpus_dev =aml_device ("\\_SB.CPUS" ); {int i; +Aml *one =aml_int (1 ); +Aml *cpu_selector =aml_name ("%s.%s" , cphp_res_path,CPU_SELECTOR ); +Aml *ins_evt =aml_name ("%s.%s" , cphp_res_path,CPU_INSERT_EVENT );
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug = { · line 297
Quoted 10 lines
hw/acpi/cpu.c +6
-0+Aml *rm_evt =aml_name ("%s.%s" , cphp_res_path,CPU_REMOVE_EVENT ); +Aml *ej_evt =aml_name ("%s.%s" , cphp_res_path,CPU_EJECT_EVENT ); +Aml *is_enabled =aml_name ("%s.%s" , cphp_res_path,CPU_ENABLED ); +Aml *ctrl_lock =aml_name ("%s.%s" , cphp_res_path,CPU_LOCK );aml_append (cpus_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0010" )));aml_append (cpus_dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A05" ))); + method =aml_method (CPU_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < arch_ids->len; i++) {
wow that will be a ton of acpi code. why not create an AML loop?
Quoted 159 lines
hw/acpi/cpu.c +109
-0+Aml *cpu =aml_name (CPU_NAME_FMT , i); +Aml *uid =aml_arg (0 ); +Aml *event =aml_arg (1 ); + + ifctx =aml_if (aml_equal (uid,aml_int (i))); + { +aml_append (ifctx,aml_notify (cpu, event)); + } +aml_append (method, ifctx); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_STS_METHOD ,1 ,AML_SERIALIZED ); + { +Aml *idx =aml_arg (0 ); +Aml *sta =aml_local (0 ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (idx, cpu_selector)); +aml_append (method,aml_store (zero, sta)); + ifctx =aml_if (aml_equal (is_enabled, one)); + { +aml_append (ifctx,aml_store (aml_int (0xF ), sta)); + } +aml_append (method, ifctx); +aml_append (method,aml_release (ctrl_lock)); +aml_append (method,aml_return (sta)); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_EJECT_METHOD ,1 ,AML_SERIALIZED ); + { +Aml *idx =aml_arg (0 ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (idx, cpu_selector)); +aml_append (method,aml_store (one, ej_evt)); +aml_append (method,aml_release (ctrl_lock)); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_SCAN_METHOD ,0 ,AML_SERIALIZED ); + { +Aml *else_ctx; +Aml *while_ctx; +Aml *idx =aml_local (0 ); +Aml *eject_req =aml_int (3 ); +Aml *dev_chk =aml_int (1 ); +Aml *cpus_count =aml_int (arch_ids->len); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (zero, idx)); + while_ctx =aml_while (aml_lless (idx, cpus_count)); + { +aml_append (while_ctx,aml_store (idx, cpu_selector)); + ifctx =aml_if (aml_equal (ins_evt, one)); + { +aml_append (ifctx, +aml_call2 (CPU_NOTIFY_METHOD , idx, dev_chk)); +aml_append (ifctx,aml_store (one, ins_evt)); + } +aml_append (while_ctx, ifctx); + else_ctx =aml_else (); + ifctx =aml_if (aml_equal (rm_evt, one)); + { +aml_append (ifctx, +aml_call2 (CPU_NOTIFY_METHOD , idx, eject_req)); +aml_append (ifctx,aml_store (one, rm_evt)); + } +aml_append (else_ctx, ifctx); +aml_append (while_ctx, else_ctx); + +aml_append (while_ctx,aml_add (idx, one, idx)); + } +aml_append (method, while_ctx); +aml_append (method,aml_release (ctrl_lock)); + } +aml_append (cpus_dev, method); +/* build Processor object for each processor */ for (i =0 ; i < arch_ids->len; i++) {Aml *dev;Aml *uid =aml_int (i); +GArray *madt_buf =g_array_new (0 ,1 ,1 );int arch_id = arch_ids->cpus[i].arch_id;if (acpi1_compat && arch_id <255 ) {@@ -235,11 +389,40 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat)aml_append (dev,aml_name_decl ("_UID" , uid)); } + method =aml_method ("_STA" ,0 ,AML_SERIALIZED ); +aml_append (method,aml_return (aml_call1 (CPU_STS_METHOD , uid))); +aml_append (dev, method); + +/* build _MAT object */ +assert (adevc && adevc->madt_cpu); + adevc->madt_cpu (adev, i, arch_ids, madt_buf); +switch (madt_buf->data[0 ]) { +case ACPI_APIC_PROCESSOR : { +AcpiMadtProcessorApic *apic = (void *)madt_buf->data; + apic->flags =cpu_to_le32 (1 ); +break ; + } +default : +assert (0 ); + } +aml_append (dev,aml_name_decl ("_MAT" , +aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data))); +g_array_free (madt_buf, true); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call1 (CPU_EJECT_METHOD , uid)); +aml_append (dev, method); +aml_append (cpus_dev, dev); } }aml_append (sb_scope, cpus_dev);aml_append (table, sb_scope); + method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); +aml_append (table, method); + +g_free (cphp_res_path);g_free (arch_ids); }hw/i386/acpi-build.c +2
-1@@ -1949,7 +1949,8 @@ build_dsdt(GArray *table_data, GArray *linker,if (pm->legacy_cpu_hp) {build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base); }else { -build_cpus_aml (dsdt, machine, true); +build_cpus_aml (dsdt, machine, true, +"\\_SB.PCI0" ,"\\_GPE._E02" , pm->cpu_hp_io_base); }build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu.h +3
-1@@ -45,7 +45,9 @@ void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner,CPUHotplugState *state,hwaddr base_addr); -void build_cpus_aml (Aml *table,MachineState *machine,bool apci1_compat); +void build_cpus_aml (Aml *table,MachineState *machine,bool apci1_compat, +const char *res_root,const char *event_handler_method, +hwaddr io_base);extern const VMStateDescription vmstate_cpu_hotplug;#define VMSTATE_CPU_HOTPLUG (cpuhp, state) \Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
In reply to Igor MammedovQuoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 12 deletions(-)docs/specs/acpi_cpu_hotplug.txt +6
-7@@ -4,21 +4,85 @@ QEMU<->ACPI BIOS CPU hotplug interface QEMU supports CPU hotplug via ACPI. This document describes the interface between QEMU and the ACPI BIOS. -ACPI GPE block (IO ports 0xafe0-0xafe3, byte access): ------------------------------------------ - -Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU -hot-add/remove event to ACPI BIOS, via SCI interrupt. +ACPI BIOS GPE.2 handler is dedicated for notifying OS about CPU hot-add +and hot-remove events. +============================================ +Legacy ACPI CPU hotplug interface registers: +-------------------------------------------- CPU present bitmap for: + One bit per CPU. Bit position reflects corresponding CPU APIC ID. Read-only. ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access) PIIX-PM (IO port 0xaf00-0xaf1f, 1-byte access) --------------------------------------------------------------- -One bit per CPU. Bit position reflects corresponding CPU APIC ID. -Read-only.
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 27
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +10
-0+QEMU sets corresponding CPU bit on hot-add event and issues SCI +with GPE.2 event set. CPU present map read by ACPI BIOS GPE.2 handler +to notify OS about CPU hot-add events. CPU hot-remove isn't supported. + +===================================== +ACPI CPU hotplug interface registers: +------------------------------------- +Register block base address: + ICH9-LPC IO port 0x0cd8 + PIIX-PM IO port 0xaf00
OK but this means we either use legacy or new one, bot both, which is problematic for people using old seabios without acpi loading support and with -M pc.
I don't say we must support them with >255 CPUs,
but I do say we should make an effort for simple
setups with <255 CPUs.
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 31
Quoted 4 lines
docs/specs/acpi_cpu_hotplug.txt +4
-0+Register block size: + ACPI_CPU_HOTPLUG_REG_LEN = 12 + +read access:
So this implies acpi must scan all cpus on each event, and this seems too aggressive.
I think we need something hierarchical where
you read one level and know which cpus to probe.
Quoted 12 lines
docs/specs/acpi_cpu_hotplug.txt +12
-0+ offset: + [0x0-0x3] reserved + [0x4] CPU device status fields: (1 byte access) + bits: + 0: Device is enabled and may be used by guest + 1: Device insert event, used to distinguish device for which + no device check event to OSPM was issued. + It's valid only when bit 0 is set. + 2: Device remove event, used to distinguish device for which + no device eject request to OSPM was issued. + 3-7: reserved and should be ignored by OSPM + [0x5-0x7] reserved
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 53
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +10
-0+ [0x8] Command data: (DWORD access) + in case of error or unsupported command reads is 0xFFFFFFFF + current 'Command field' value: + 0: returns PXM value corresponding to device + +write access: + offset: + [0x0-0x3] CPU selector: (DWORD access) + selects active CPU device. All following accesses to other + registers will read/store data from/to selected CPU.
I've been thinking - is it time to add an EmbeddedControl interface? This way we have another namespace.
Not insisting on it, just an idea.
Quoted 30 lines
docs/specs/acpi_cpu_hotplug.txt +29
-0+ [0x4] CPU device control fields: (1 byte access) + bits: + 0: reserved, OSPM must clear it before writing to register. + 1: if set to 1 clears device insert event, set by OSPM + after it has emitted device check event for the + selected CPU device + 2: if set to 1 clears device remove event, set by OSPM + after it has emitted device eject request for the + selected CPU device + 3: if set to 1 initiates device eject, set by OSPM when it + triggers CPU device removal and calls _EJ0 method + 4-7: reserved, OSPM must clear them before writing to register + [0x5] Command field: (1 byte access) + value: + 0: following reads from 'Command data' register returns PXM + value of device + 1: following writes to 'Command data' register set OST event + register in QEMU + 2: following writes to 'Command data' register set OST status + register in QEMU + other values: reserved + [0x6-0x7] reserved + [0x8] Command data: (DWORD access) + current 'Command field' value: + 1: stores value into OST event register + 2: stores value into OST status register, triggers + ACPI_DEVICE_OST QMP event from QEMU to external applications + with current values of OST event and status registers. + other values: reserved
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 88
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +5
-5-CPU hot-add/remove notification: ------------------------------------------------------ -QEMU sets/clears corresponding CPU bit on hot-add/remove event. -CPU present map read by ACPI BIOS GPE.2 handler to notify OS of CPU -hot-(un)plug events. +Selecting CPU device beyond possible range has no effect on platform: + - write accesses to CPU hot-plug registers not documented above are + ignored + - read accesses to CPU hot-plug registers not documented above return + all bits set to 1.
why not 0?
Quoted 2 lines
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
In reply to Marcel ApfelbaumQuoted 9 lines · On Mon, 30 May 2016 21:18:59 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 3 lines · Igor Mammedov
move the former SSDT part of CPU hoplug close to DSDT part. AML is only moved but there isn't any functional change.
The patch looks good to me,
but why did you decide to get rid of thebuild_processor_devicesfunction? I would simply move it to the new file.
Maybe is a matter of taste, anyway:
the only reason was that it looks cleaner to me (even for legacy code), that way CPU devices code / defines are in a smaller and
do not pollute already way too big acpi-build.c.
For new hotplug it's even necessary so that it would be easy to share with ARM target.
Quoted 299 lines
Reviewed-by Marcel Apfelbaum <[email protected]>Thanks,
MarcelQuoted 290 lines
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug_acpi_table.c | 104 +++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 112 +-------------------------------------- include/hw/acpi/cpu_hotplug.h | 3 +- 3 files changed, 106 insertions(+), 113 deletions(-)hw/acpi/cpu_hotplug_acpi_table.c +103
-1@@ -15,12 +15,19 @@#include "qemu/osdep.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/i386/pc.h" -void build_cpu_hotplug_aml (Aml *ctx) +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) { +Aml *dev; +Aml *crs; +Aml *pkg; +Aml *field;Aml *method;Aml *if_ctx;Aml *else_ctx; +int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 };Aml *cpu_id =aml_arg (0 );@@ -29,6 +36,9 @@ void build_cpu_hotplug_aml(Aml *ctx)Aml *cpus_map =aml_name (CPU_ON_BITMAP );Aml *zero =aml_int (0 );Aml *one =aml_int (1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); +PCMachineState *pcms =PC_MACHINE (machine);/* * _MAT method - creates an madt apic buffer @@ -132,5 +142,97 @@ void build_cpu_hotplug_aml(Aml *ctx) }aml_append (sb_scope, method); +/* The current AML generator can cover the APIC ID range [0..255], +* inclusive, for VCPU hotplug. */ +QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); +g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); + +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); + +/* build Processor object for each processor */ +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); + + dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + + method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_arg (0 ))) + ); +aml_append (dev, method); + +aml_append (sb_scope, dev); + } + +/* build this code: +* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} +*/ +/* Arg0 = Processor ID = APIC ID */ + method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); +aml_append (if_ctx, +aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) + ); +aml_append (method, if_ctx); + } +aml_append (sb_scope, method); + +/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" +* +* Note: The ability to create variable-sized packages was first +* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages +* ith up to 255 elements. Windows guests up to win2k8 fail when +* VarPackageOp is used. +*/ + pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : +aml_varpackage (pcms->apic_id_limit); + +for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +for (; apic_idx < apic_id; apic_idx++) { +aml_append (pkg,aml_int (0 )); + } +aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); + apic_idx = apic_id +1 ; + } +aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); +g_free (apic_ids); +aml_append (ctx, sb_scope); }hw/i386/acpi-build.c +1
-111@@ -943,114 +943,6 @@ static Aml *build_crs(PCIHostState *host,return crs; } -static void build_processor_devices (Aml *sb_scope,MachineState *machine, -AcpiPmInfo *pm) -{ -int i, apic_idx; -Aml *dev; -Aml *crs; -Aml *pkg; -Aml *field; -Aml *ifctx; -Aml *method; -MachineClass *mc =MACHINE_GET_CLASS (machine); -CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); -PCMachineState *pcms =PC_MACHINE (machine); - -/* The current AML generator can cover the APIC ID range [0..255], -* inclusive, for VCPU hotplug. */ -QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); -g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); - -/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ - dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); -aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); -aml_append (dev, -aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) - ); -/* device present, functioning, decoding, not shown in UI */ -aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); - crs =aml_resource_template (); -aml_append (crs, -aml_io (AML_DECODE16 , pm->cpu_hp_io_base, pm->cpu_hp_io_base,1 , - pm->cpu_hp_io_len) - ); -aml_append (dev,aml_name_decl ("_CRS" , crs)); -aml_append (sb_scope, dev); -/* declare CPU hotplug MMIO region and PRS field to access it */ -aml_append (sb_scope,aml_operation_region ( -"PRST" ,AML_SYSTEM_IO ,aml_int (pm->cpu_hp_io_base), pm->cpu_hp_io_len)); - field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); -aml_append (field,aml_named_field ("PRS" ,256 )); -aml_append (sb_scope, field); - -/* build Processor object for each processor */ -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); - - method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), -aml_arg (0 ))) - ); -aml_append (dev, method); - -aml_append (sb_scope, dev); - } - -/* build this code: -* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} -*/ -/* Arg0 = Processor ID = APIC ID */ - method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - - ifctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); -aml_append (ifctx, -aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) - ); -aml_append (method, ifctx); - } -aml_append (sb_scope, method); - -/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" -* -* Note: The ability to create variable-sized packages was first -* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages -* ith up to 255 elements. Windows guests up to win2k8 fail when -* VarPackageOp is used. -*/ - pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : -aml_varpackage (pcms->apic_id_limit); - -for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -for (; apic_idx < apic_id; apic_idx++) { -aml_append (pkg,aml_int (0 )); - } -aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); - apic_idx = apic_id +1 ; - } -aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); -g_free (apic_ids); -} -static void build_memory_devices (Aml *sb_scope,int nr_mem,uint16_t io_base,uint16_t io_len) {@@ -2043,7 +1935,7 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_cpu_hotplug_aml (dsdt); +build_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, pm->cpu_hp_io_len);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2305,8 +2197,6 @@ build_dsdt(GArray *table_data, GArray *linker, sb_scope =aml_scope ("\\_SB" ); { -build_processor_devices (sb_scope, machine, pm); -build_memory_devices (sb_scope, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu_hotplug.h +2
-1@@ -34,5 +34,6 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,#define CPU_STATUS_MAP "PRS"#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx); +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len);#endif
Re: [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods to DSDT
In reply to Michael S. TsirkinQuoted 108 lines · On Tue, 31 May 2016 07:38:08 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 107 lines · Igor Mammedov
Add necessary CPU hotplug methods to handle hotplug events.
Signed-off-by Igor Mammedov <[email protected]>---
v1:
- make replace_MATmethod with named buffer object as its content is static--- hw/acpi/cpu.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 3 +- include/hw/acpi/cpu.h | 4 +- 3 files changed, 190 insertions(+), 4 deletions(-)hw/acpi/cpu.c +74
-2@@ -207,24 +207,178 @@ const VMStateDescription vmstate_cpu_hotplug = { };#define CPU_NAME_FMT "C%.03X" - -void build_cpus_aml (Aml *table,MachineState *machine,bool acpi1_compat) +#define CPUHP_RES_DEVICE "PRES" +#define CPU_LOCK "CPLK" +#define CPU_STS_METHOD "CSTA" +#define CPU_SCAN_METHOD "CSCN" +#define CPU_EJECT_METHOD "CEJ0" +#define CPU_NOTIFY_METHOD "CTFY" + +#define CPU_ENABLED "CPEN" +#define CPU_SELECTOR "CSEL" +#define CPU_EJECT_EVENT "CEJ0" +#define CPU_INSERT_EVENT "CINS" +#define CPU_REMOVE_EVENT "CRMV" + +void build_cpus_aml (Aml *table,MachineState *machine,bool acpi1_compat, +const char *res_root,const char *event_handler_method, +hwaddr io_base) { +Aml *ifctx; +Aml *field; +Aml *method; +Aml *cpu_ctrl_dev;Aml *cpus_dev; +Aml *zero =aml_int (0 );Aml *sb_scope =aml_scope ("_SB" );MachineClass *mc =MACHINE_GET_CLASS (machine);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); +AcpiDeviceIf *adev =ACPI_DEVICE_IF (obj); + + cpu_ctrl_dev =aml_device ("%s" , cphp_res_path); + { +Aml *crs; + +aml_append (cpu_ctrl_dev, +aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (cpu_ctrl_dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" ))); +aml_append (cpu_ctrl_dev,aml_mutex (CPU_LOCK ,0 )); + + crs =aml_resource_template (); +aml_append (crs,aml_io (AML_DECODE16 , io_base, io_base,1 , +ACPI_CPU_HOTPLUG_REG_LEN )); +aml_append (cpu_ctrl_dev,aml_name_decl ("_CRS" , crs)); + +/* declare CPU hotplug MMIO region with related access fields */ +aml_append (cpu_ctrl_dev, +aml_operation_region ("PRST" ,AML_SYSTEM_IO ,aml_int (io_base), +ACPI_CPU_HOTPLUG_REG_LEN )); + + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK , +AML_WRITE_AS_ZEROS ); +aml_append (field,aml_reserved_field (ACPI_CPU_FLAGS_OFFSET_RW *8 )); +/* 1 if enabled, read only */ +aml_append (field,aml_named_field (CPU_ENABLED ,1 )); +/* (read) 1 if has a insert event. (write) 1 to clear event */ +aml_append (field,aml_named_field (CPU_INSERT_EVENT ,1 )); +/* (read) 1 if has a remove event. (write) 1 to clear event */ +aml_append (field,aml_named_field (CPU_REMOVE_EVENT ,1 )); +/* initiates device eject, write only */ +aml_append (field,aml_named_field (CPU_EJECT_EVENT ,1 )); +aml_append (cpu_ctrl_dev, field); + + field =aml_field ("PRST" ,AML_DWORD_ACC ,AML_NOLOCK ,AML_PRESERVE ); +/* CPU selector, write only */ +aml_append (field,aml_named_field (CPU_SELECTOR ,32 )); +aml_append (cpu_ctrl_dev, field); + + } +aml_append (sb_scope, cpu_ctrl_dev); + cpus_dev =aml_device ("\\_SB.CPUS" ); {int i; +Aml *one =aml_int (1 ); +Aml *cpu_selector =aml_name ("%s.%s" , cphp_res_path,CPU_SELECTOR ); +Aml *ins_evt =aml_name ("%s.%s" , cphp_res_path,CPU_INSERT_EVENT ); +Aml *rm_evt =aml_name ("%s.%s" , cphp_res_path,CPU_REMOVE_EVENT ); +Aml *ej_evt =aml_name ("%s.%s" , cphp_res_path,CPU_EJECT_EVENT ); +Aml *is_enabled =aml_name ("%s.%s" , cphp_res_path,CPU_ENABLED ); +Aml *ctrl_lock =aml_name ("%s.%s" , cphp_res_path,CPU_LOCK );
Quoted 7 lines
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug = { · line 297
Quoted 5 lines
hw/acpi/cpu.c +2
-0aml_append (cpus_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0010" )));aml_append (cpus_dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A05" ))); + method =aml_method (CPU_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < arch_ids->len; i++) {wow that will be a ton of acpi code. why not create an AML loop?
I wish I could that would shrink corresponding current CPU/PCI/MEM hotplug notifiers a lot.
I've spend several days trying to convince Notify() to take anything else except of plain NameString which according to spec should be possible but I failed miserably with different degree of failure/success depending on linux/windows versions.
If you have any idea how to construct name string inside AML using AML operators I'm all ears.
I've also tried other way around by sending bus check event to \_SB.CPUS, that partially worked, i.e. for linux or windows (I don't remember which one) and also depended on OS version.
So I've done it the old way, as we were doing it for current CPU/PCI/MEM hotplug.
Quoted 159 lines
Quoted 159 lines
hw/acpi/cpu.c +109
-0+Aml *cpu =aml_name (CPU_NAME_FMT , i); +Aml *uid =aml_arg (0 ); +Aml *event =aml_arg (1 ); + + ifctx =aml_if (aml_equal (uid,aml_int (i))); + { +aml_append (ifctx,aml_notify (cpu, event)); + } +aml_append (method, ifctx); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_STS_METHOD ,1 ,AML_SERIALIZED ); + { +Aml *idx =aml_arg (0 ); +Aml *sta =aml_local (0 ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (idx, cpu_selector)); +aml_append (method,aml_store (zero, sta)); + ifctx =aml_if (aml_equal (is_enabled, one)); + { +aml_append (ifctx,aml_store (aml_int (0xF ), sta)); + } +aml_append (method, ifctx); +aml_append (method,aml_release (ctrl_lock)); +aml_append (method,aml_return (sta)); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_EJECT_METHOD ,1 ,AML_SERIALIZED ); + { +Aml *idx =aml_arg (0 ); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (idx, cpu_selector)); +aml_append (method,aml_store (one, ej_evt)); +aml_append (method,aml_release (ctrl_lock)); + } +aml_append (cpus_dev, method); + + method =aml_method (CPU_SCAN_METHOD ,0 ,AML_SERIALIZED ); + { +Aml *else_ctx; +Aml *while_ctx; +Aml *idx =aml_local (0 ); +Aml *eject_req =aml_int (3 ); +Aml *dev_chk =aml_int (1 ); +Aml *cpus_count =aml_int (arch_ids->len); + +aml_append (method,aml_acquire (ctrl_lock,0xFFFF )); +aml_append (method,aml_store (zero, idx)); + while_ctx =aml_while (aml_lless (idx, cpus_count)); + { +aml_append (while_ctx,aml_store (idx, cpu_selector)); + ifctx =aml_if (aml_equal (ins_evt, one)); + { +aml_append (ifctx, +aml_call2 (CPU_NOTIFY_METHOD , idx, dev_chk)); +aml_append (ifctx,aml_store (one, ins_evt)); + } +aml_append (while_ctx, ifctx); + else_ctx =aml_else (); + ifctx =aml_if (aml_equal (rm_evt, one)); + { +aml_append (ifctx, +aml_call2 (CPU_NOTIFY_METHOD , idx, eject_req)); +aml_append (ifctx,aml_store (one, rm_evt)); + } +aml_append (else_ctx, ifctx); +aml_append (while_ctx, else_ctx); + +aml_append (while_ctx,aml_add (idx, one, idx)); + } +aml_append (method, while_ctx); +aml_append (method,aml_release (ctrl_lock)); + } +aml_append (cpus_dev, method); +/* build Processor object for each processor */ for (i =0 ; i < arch_ids->len; i++) {Aml *dev;Aml *uid =aml_int (i); +GArray *madt_buf =g_array_new (0 ,1 ,1 );int arch_id = arch_ids->cpus[i].arch_id;if (acpi1_compat && arch_id <255 ) {@@ -235,11 +389,40 @@ void build_cpus_aml(Aml *table, MachineState *machine, bool acpi1_compat)aml_append (dev,aml_name_decl ("_UID" , uid)); } + method =aml_method ("_STA" ,0 ,AML_SERIALIZED ); +aml_append (method,aml_return (aml_call1 (CPU_STS_METHOD , uid))); +aml_append (dev, method); + +/* build _MAT object */ +assert (adevc && adevc->madt_cpu); + adevc->madt_cpu (adev, i, arch_ids, madt_buf); +switch (madt_buf->data[0 ]) { +case ACPI_APIC_PROCESSOR : { +AcpiMadtProcessorApic *apic = (void *)madt_buf->data; + apic->flags =cpu_to_le32 (1 ); +break ; + } +default : +assert (0 ); + } +aml_append (dev,aml_name_decl ("_MAT" , +aml_buffer (madt_buf->len, (uint8_t *)madt_buf->data))); +g_array_free (madt_buf, true); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call1 (CPU_EJECT_METHOD , uid)); +aml_append (dev, method); +aml_append (cpus_dev, dev); } }aml_append (sb_scope, cpus_dev);aml_append (table, sb_scope); + method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); +aml_append (table, method); + +g_free (cphp_res_path);g_free (arch_ids); }hw/i386/acpi-build.c +2
-1@@ -1949,7 +1949,8 @@ build_dsdt(GArray *table_data, GArray *linker,if (pm->legacy_cpu_hp) {build_legacy_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base); }else { -build_cpus_aml (dsdt, machine, true); +build_cpus_aml (dsdt, machine, true, +"\\_SB.PCI0" ,"\\_GPE._E02" , pm->cpu_hp_io_base); }build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu.h +3
-1@@ -45,7 +45,9 @@ void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner,CPUHotplugState *state,hwaddr base_addr); -void build_cpus_aml (Aml *table,MachineState *machine,bool apci1_compat); +void build_cpus_aml (Aml *table,MachineState *machine,bool apci1_compat, +const char *res_root,const char *event_handler_method, +hwaddr io_base);extern const VMStateDescription vmstate_cpu_hotplug;#define VMSTATE_CPU_HOTPLUG (cpuhp, state) \Signature · 1 line
1.8.3.1
PATCH v2 13/33 acpi: extend ACPI interface to provide send_event hook
In reply to Marcel Apfelbaumsend_event() hook will allow to send ACPI event in a target specific way (GPE or GPIO based impl.) it will also simplify proxy wrappers in piix4pm/ich9 that access ACPI regs and SCI which are part of piix4pm/lcp_ich9 devices and call acpi_foo() API directly.
---
Following patch will use hook to simplify hotplug callbacks in piix4pm/ich9.
v2:
- make ACPI_SEND_EVENT macro a function Marcel Apfelbaum <[email protected]>
--- hw/acpi/acpi_interface.c | 9 +++++++++ hw/acpi/core.c | 2 +- hw/acpi/piix4.c | 8 ++++++++ hw/isa/lpc_ich9.c | 8 ++++++++ include/hw/acpi/acpi.h | 10 ++-------- include/hw/acpi/acpi_dev_interface.h | 11 +++++++++++ 6 files changed, 39 insertions(+), 9 deletions(-)
hw/acpi/acpi_interface.c +9 -0
@@ -2,6 +2,15 @@#include "hw/acpi/acpi_dev_interface.h" #include "qemu/module.h" +void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) +{ +AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (dev); +if (adevc->send_event) { +AcpiDeviceIf *adev =ACPI_DEVICE_IF (dev); + adevc->send_event (adev, event); + } +} +static void register_types (void ) {static const TypeInfo acpi_dev_if_info = {
hw/acpi/core.c +1 -1
@@ -698,7 +698,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) }void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status) +AcpiEventStatusBits status) { ar->gpe.sts[0 ] |= status;acpi_update_sci (ar, irq);
hw/acpi/piix4.c +8 -0
@@ -586,6 +586,13 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); } +static void piix4_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +PIIX4PMState *s =PIIX4_PM (adev); + +acpi_send_gpe_event (&s->ar, s->irq, ev); +} +static Property piix4_pm_properties[] = {DEFINE_PROP_UINT32 ("smb_io_base" , PIIX4PMState, smb_io_base,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),
@@ -624,6 +631,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug_request = piix4_device_unplug_request_cb; hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; + adevc->send_event = piix4_send_gpe; }static const TypeInfo piix4_pm_info = {
hw/isa/lpc_ich9.c +8 -0
@@ -703,6 +703,13 @@ static Property ich9_lpc_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void ich9_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (adev); + +acpi_send_gpe_event (&s->pm.acpi_regs, s->pm.irq, ev); +} +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -730,6 +737,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug_request = ich9_device_unplug_request_cb; hc->unplug = ich9_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; + adevc->send_event = ich9_send_gpe; }static const TypeInfo ich9_lpc_info = {
include/hw/acpi/acpi.h +2 -8
@@ -23,6 +23,7 @@#include "qemu/option.h" #include "exec/memory.h" #include "hw/irq.h" +#include "hw/acpi/acpi_dev_interface.h" /* * current device naming scheme supports up to 256 memory devices
@@ -89,13 +90,6 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 -/* These values are part of guest ABI, and can not be changed */ -typedef enum { -ACPI_PCI_HOTPLUG_STATUS =2 , -ACPI_CPU_HOTPLUG_STATUS =4 , -ACPI_MEMORY_HOTPLUG_STATUS =8 , -}AcpiGPEStatusBits ; -/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;
@@ -172,7 +166,7 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr);void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status); +AcpiEventStatusBits status);void acpi_update_sci (ACPIREGS *acpi_regs,qemu_irq irq);
include/hw/acpi/acpi_dev_interface.h +11 -0
@@ -4,6 +4,13 @@#include "qom/object.h" #include "qapi-types.h" +/* These values are part of guest ABI, and can not be changed */ +typedef enum { +ACPI_PCI_HOTPLUG_STATUS =2 , +ACPI_CPU_HOTPLUG_STATUS =4 , +ACPI_MEMORY_HOTPLUG_STATUS =8 , +}AcpiEventStatusBits ; +#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"#define ACPI_DEVICE_IF_CLASS (klass) \
@@ -22,11 +29,14 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf; +void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event); +/** * AcpiDeviceIfClass: * * ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. +* send_event: inject a specified event into guest * * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without
@@ -39,5 +49,6 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); } AcpiDeviceIfClass;#endif
Signature · 1 line
1.8.3.1
PATCH v2 14/33 pc: use AcpiDeviceIfClass.send_event to issue GPE events
In reply to Igor Mammedovit reduces number of args passed in handlers by 1 and a number of used proxy wrappers saving ~20LOC. Also it allows to make cpu/mem hotplug code more universal as it would allow ARM to reuse it without rewrite by providing its own send_event callback to trigger events usiong GPIO instead of GPE as fixed hadrware ACPI model doen't have GPE at all.
---
v2:
- make ACPI_SEND_EVENT macro a function Marcel Apfelbaum <[email protected]>
--- hw/acpi/cpu_hotplug.c | 5 ++--- hw/acpi/ich9.c | 33 ++++++++++++++++++++------------- hw/acpi/memory_hotplug.c | 12 ++++-------- hw/acpi/pcihp.c | 10 ++++------ hw/acpi/piix4.c | 11 +++++------ hw/isa/lpc_ich9.c | 30 +++--------------------------- include/hw/acpi/cpu_hotplug.h | 3 ++- include/hw/acpi/ich9.h | 9 +++++---- include/hw/acpi/memory_hotplug.h | 4 ++-- include/hw/acpi/pcihp.h | 5 +++-- 10 files changed, 50 insertions(+), 72 deletions(-)
hw/acpi/cpu_hotplug.c +2 -3
@@ -62,15 +62,14 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); } -void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {return ; } - -acpi_send_gpe_event (ar, irq,ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); } void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
hw/acpi/ich9.c +20 -13
@@ -430,40 +430,47 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) NULL); } -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp) +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug, +acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, - &pm->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp) +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&pm->acpi_regs, pm->irq, - &pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_request_cb (hotplug_dev, + &lpc->pm.acpi_memory_hotplug, dev, + errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_cb (&pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
hw/acpi/memory_hotplug.c +4 -8
@@ -228,7 +228,7 @@ acpi_memory_slot_status(MemHotplugState *mem_st,return &mem_st->devs[slot]; } -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {MemStatus *mdev;
@@ -247,13 +247,11 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; - -/* do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } } -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {
@@ -265,9 +263,7 @@ void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq, } mdev->is_removing = true; - -/* Do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,
hw/acpi/pcihp.c +4 -6
@@ -182,7 +182,7 @@ void acpi_pcihp_reset(AcpiPciHpState *s)acpi_pcihp_update (s); } -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);
@@ -202,11 +202,10 @@ void acpi_pcihp_device_plug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); } -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);
@@ -219,8 +218,7 @@ void acpi_pcihp_device_unplug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)
hw/acpi/piix4.c +5 -6
@@ -348,12 +348,11 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, dev, errp); +acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_plug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, - errp); +acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -367,10 +366,10 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, +acpi_memory_unplug_request_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_unplug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, +acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else { error_setg(errp, "acpi: device unplug request for not supported device"
hw/isa/lpc_ich9.c +3 -27
@@ -637,30 +637,6 @@ static void ich9_lpc_realize(PCIDevice *d, Error **errp) 1); } -static void ich9_device_plug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_plug_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_request_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_request_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_cb (&lpc->pm, dev, errp); -} -static bool ich9_rst_cnt_needed (void *opaque) {ICH9LPCState *lpc = opaque;
@@ -733,9 +709,9 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)* pc_q35_init() */ dc->cannot_instantiate_with_device_add_yet = true; - hc->plug = ich9_device_plug_cb; - hc->unplug_request = ich9_device_unplug_request_cb; - hc->unplug = ich9_device_unplug_cb; + hc->plug = ich9_pm_device_plug_cb; + hc->unplug_request = ich9_pm_device_unplug_request_cb; + hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; }
include/hw/acpi/cpu_hotplug.h +2 -1
@@ -15,13 +15,14 @@#include "hw/acpi/acpi.h" #include "hw/acpi/pc-hotplug.h" #include "hw/acpi/aml-build.h" +#include "hw/hotplug.h" typedef struct AcpiCpuHotplug {MemoryRegion io;uint8_t sts[ACPI_GPE_PROC_LEN ]; }AcpiCpuHotplug ; -void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp); void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
include/hw/acpi/ich9.h +5 -4
@@ -69,10 +69,11 @@ extern const VMStateDescription vmstate_ich9_pm;void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm,Error **errp); -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp); -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp); -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp); +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp); +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp);void ich9_pm_ospm_status (AcpiDeviceIf *adev,ACPIOSTInfoList ***list);
include/hw/acpi/memory_hotplug.h +2 -2
@@ -32,9 +32,9 @@ typedef struct MemHotplugState {void acpi_memory_hotplug_init (MemoryRegion *as,Object *owner,MemHotplugState *state); -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); void acpi_memory_unplug_cb(MemHotplugState *mem_st,
include/hw/acpi/pcihp.h +3 -2
@@ -29,6 +29,7 @@#include "hw/acpi/acpi.h" #include "migration/vmstate.h" +#include "hw/hotplug.h" #define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"#define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"
@@ -56,9 +57,9 @@ typedef struct AcpiPciHpState {void acpi_pcihp_init (Object *owner,AcpiPciHpState *,PCIBus *root,MemoryRegion *address_space_io,bool bridges_enabled); -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp); -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp);/* Called on reset */
Signature · 1 line
1.8.3.1
Marcel Apfelbaum
Reviewed-byRe: [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers
In reply to Igor MammedovQuoted 60 lines · Igor Mammedov
Quoted 49 lines · On Wed, 25 May 2016 12:11:33 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 48 lines · Igor Mammedov
ACPI spec requires GPE handlers only for GPE events that hardware implements.
So remove AML for not supported by QEMU device model events.Signed-off-by Igor Mammedov <[email protected]>--- hw/i386/acpi-build.c | 17 ----------------- 1 file changed, 17 deletions(-)hw/i386/acpi-build.c +0
-16@@ -2051,8 +2051,6 @@ build_dsdt(GArray *table_data, GArray *linker, {aml_append (scope,aml_name_decl ("_HID" ,aml_string ("ACPI0006" ))); -aml_append (scope,aml_method ("_L00" ,0 ,AML_NOTSERIALIZED )); -if (misc->is_piix4) { method =aml_method ("_E01" ,0 ,AML_NOTSERIALIZED ); aml_append(method,@@ -2060,8 +2058,6 @@ build_dsdt(GArray *table_data, GArray *linker,aml_append (method,aml_call0 ("\\_SB.PCI0.PCNT" ));aml_append (method,aml_release (aml_name ("\\_SB.PCI0.BLCK" )));aml_append (scope, method); - }else { -aml_append (scope,aml_method ("_L01" ,0 ,AML_NOTSERIALIZED )); } method =aml_method ("_E02" ,0 ,AML_NOTSERIALIZED );@@ -2071,19 +2067,6 @@ build_dsdt(GArray *table_data, GArray *linker, method =aml_method ("_E03" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_call0 (MEMORY_HOTPLUG_HANDLER_PATH ));aml_append (scope, method); - -aml_append (scope,aml_method ("_L04" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L05" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L06" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L07" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L08" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L09" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0A" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0B" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0C" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0D" ,0 ,AML_NOTSERIALIZED )); -aml_append (scope,aml_method ("_L0E" ,0 ,AML_NOTSERIALIZED ));Quoted 8 lines
hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, · line 2072
Quoted 5 lines
hw/i386/acpi-build.c +0
-1-aml_append (scope,aml_method ("_L0F" ,0 ,AML_NOTSERIALIZED )); }aml_append (dsdt, scope);Is this patch related to the series? Or is it a cleanup opportunity?
Quoted 3 lines
It's a cleanup, I'm posting it here as it's missed its merge chance at 2.6 and Michael suggested to respin it later when 2.7 dev window is open
Sure,
Thanks,
Marcel
Quoted 4 lines
Quoted 3 lines
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
In reply to Marcel ApfelbaumQuoted 65 lines · On Mon, 30 May 2016 22:02:31 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 64 lines · Igor Mammedov
add necessary wiring to init new CPU hotplug hardware if ICH9-LPC.cpu-hotplug-legacy is "off".
Set ICH9-LPC.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.Signed-off-by Igor Mammedov <[email protected]>---
v1:
- drop ICH9-LPC.cpu-hotplug property--- hw/acpi/ich9.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/acpi/ich9.h | 6 +++++- include/hw/compat.h | 6 +++++- 3 files changed, 47 insertions(+), 7 deletions(-)hw/acpi/ich9.c +23
-1@@ -170,6 +170,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="ich9_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, ICH9LPCPMRegs), +VMSTATE_END_OF_LIST () + } +}; +static bool vmstate_test_use_tco (void *opaque) {ICH9LPCPMRegs *s = opaque;@@ -209,6 +227,7 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, &vmstate_tco_io_state, + &vmstate_cpuhp_state,NULL } };@@ -275,7 +294,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,if (pm->cpu_hotplug_legacy) {legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +OBJECT (lpc_pci), &pm->cpuhp.legacy,ICH9_CPU_HOTPLUG_IO_BASE ); + }else { +cpu_hotplug_hw_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), + &pm->cpuhp.state,ICH9_CPU_HOTPLUG_IO_BASE ); }
Quoted 9 lines
hw/acpi/ich9.c void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) · line 417
Quoted 6 lines
hw/acpi/ich9.c +0
-1if (pm->acpi_memory_hotplug.is_enabled) {@@ -414,7 +436,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; - pm->cpu_hotplug_legacy = true;Maybe is too soon to disable legacy CPU hotplug? Will the new cpu hotplug mechanism work from this patch on, or it will break git bisect?
it doesn't break bisect compile wise nor 'make check' wise, but it's hotplug won't be functional till
acpi: add CPU hotplug methods to DSDT
perhaps I need to move it there or into a separate patch after it.
Quoted 88 lines
Thanks,
MarcelQuoted 83 lines
hw/acpi/ich9.c +14
-3pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;@@ -461,9 +482,13 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (lpc->pm.cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { +if (lpc->pm.cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.legacy, dev, + errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.state, dev, errp); + } } else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -480,6 +505,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp.state, + dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -494,6 +523,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&lpc->pm.cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));include/hw/acpi/ich9.h +5
-1@@ -23,6 +23,7 @@#include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" @@ -49,7 +50,10 @@ typedef struct ICH9LPCPMRegs {Notifier powerdown_notifier;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug;include/hw/compat.h +5
-1@@ -2,7 +2,11 @@#define HW_COMPAT_H #define HW_COMPAT_2_6 \ -/* empty */ + {\ + .driver = "ICH9-LPC",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
In reply to Igor MammedovQuoted 8 lines · Igor Mammedov
Quoted 5 lines · On Mon, 30 May 2016 21:18:59 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 3 lines · Igor Mammedov
move the former SSDT part of CPU hoplug close to DSDT part. AML is only moved but there isn't any functional change.
Quoted 7 lines
Quoted 4 lines
The patch looks good to me,
but why did you decide to get rid of thebuild_processor_devicesfunction? I would simply move it to the new file.
Maybe is a matter of taste, anyway:the only reason was that it looks cleaner to me (even for legacy code), that way CPU devices code / defines are in a smaller and
do not pollute already way too bigacpi-build.c.
I agree with moving the code, I was referring to the fact that you could keep the function and just move it instead of merging the code in another method. But maybe is only a matter of taste.
Thanks,
Marcel
Quoted 305 lines
For new hotplug it's even necessary so that it would be easy to share with ARM target.
Quoted 299 lines
Reviewed-by Marcel Apfelbaum <[email protected]>Thanks,
MarcelQuoted 290 lines
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug_acpi_table.c | 104 +++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 112 +-------------------------------------- include/hw/acpi/cpu_hotplug.h | 3 +- 3 files changed, 106 insertions(+), 113 deletions(-)hw/acpi/cpu_hotplug_acpi_table.c +103
-1@@ -15,12 +15,19 @@#include "qemu/osdep.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/i386/pc.h" -void build_cpu_hotplug_aml (Aml *ctx) +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) { +Aml *dev; +Aml *crs; +Aml *pkg; +Aml *field;Aml *method;Aml *if_ctx;Aml *else_ctx; +int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 };Aml *cpu_id =aml_arg (0 );@@ -29,6 +36,9 @@ void build_cpu_hotplug_aml(Aml *ctx)Aml *cpus_map =aml_name (CPU_ON_BITMAP );Aml *zero =aml_int (0 );Aml *one =aml_int (1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); +PCMachineState *pcms =PC_MACHINE (machine);/* * _MAT method - creates an madt apic buffer @@ -132,5 +142,97 @@ void build_cpu_hotplug_aml(Aml *ctx) }aml_append (sb_scope, method); +/* The current AML generator can cover the APIC ID range [0..255], +* inclusive, for VCPU hotplug. */ +QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); +g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); + +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); + +/* build Processor object for each processor */ +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); + + dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + + method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_arg (0 ))) + ); +aml_append (dev, method); + +aml_append (sb_scope, dev); + } + +/* build this code: +* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} +*/ +/* Arg0 = Processor ID = APIC ID */ + method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); +aml_append (if_ctx, +aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) + ); +aml_append (method, if_ctx); + } +aml_append (sb_scope, method); + +/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" +* +* Note: The ability to create variable-sized packages was first +* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages +* ith up to 255 elements. Windows guests up to win2k8 fail when +* VarPackageOp is used. +*/ + pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : +aml_varpackage (pcms->apic_id_limit); + +for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +for (; apic_idx < apic_id; apic_idx++) { +aml_append (pkg,aml_int (0 )); + } +aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); + apic_idx = apic_id +1 ; + } +aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); +g_free (apic_ids); +aml_append (ctx, sb_scope); }hw/i386/acpi-build.c +1
-111@@ -943,114 +943,6 @@ static Aml *build_crs(PCIHostState *host,return crs; } -static void build_processor_devices (Aml *sb_scope,MachineState *machine, -AcpiPmInfo *pm) -{ -int i, apic_idx; -Aml *dev; -Aml *crs; -Aml *pkg; -Aml *field; -Aml *ifctx; -Aml *method; -MachineClass *mc =MACHINE_GET_CLASS (machine); -CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); -PCMachineState *pcms =PC_MACHINE (machine); - -/* The current AML generator can cover the APIC ID range [0..255], -* inclusive, for VCPU hotplug. */ -QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); -g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); - -/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ - dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); -aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); -aml_append (dev, -aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) - ); -/* device present, functioning, decoding, not shown in UI */ -aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); - crs =aml_resource_template (); -aml_append (crs, -aml_io (AML_DECODE16 , pm->cpu_hp_io_base, pm->cpu_hp_io_base,1 , - pm->cpu_hp_io_len) - ); -aml_append (dev,aml_name_decl ("_CRS" , crs)); -aml_append (sb_scope, dev); -/* declare CPU hotplug MMIO region and PRS field to access it */ -aml_append (sb_scope,aml_operation_region ( -"PRST" ,AML_SYSTEM_IO ,aml_int (pm->cpu_hp_io_base), pm->cpu_hp_io_len)); - field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); -aml_append (field,aml_named_field ("PRS" ,256 )); -aml_append (sb_scope, field); - -/* build Processor object for each processor */ -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); - - method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), -aml_arg (0 ))) - ); -aml_append (dev, method); - -aml_append (sb_scope, dev); - } - -/* build this code: -* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} -*/ -/* Arg0 = Processor ID = APIC ID */ - method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - - ifctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); -aml_append (ifctx, -aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) - ); -aml_append (method, ifctx); - } -aml_append (sb_scope, method); - -/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" -* -* Note: The ability to create variable-sized packages was first -* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages -* ith up to 255 elements. Windows guests up to win2k8 fail when -* VarPackageOp is used. -*/ - pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : -aml_varpackage (pcms->apic_id_limit); - -for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -for (; apic_idx < apic_id; apic_idx++) { -aml_append (pkg,aml_int (0 )); - } -aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); - apic_idx = apic_id +1 ; - } -aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); -g_free (apic_ids); -} -static void build_memory_devices (Aml *sb_scope,int nr_mem,uint16_t io_base,uint16_t io_len) {@@ -2043,7 +1935,7 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_cpu_hotplug_aml (dsdt); +build_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, pm->cpu_hp_io_len);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2305,8 +2197,6 @@ build_dsdt(GArray *table_data, GArray *linker, sb_scope =aml_scope ("\\_SB" ); { -build_processor_devices (sb_scope, machine, pm); -build_memory_devices (sb_scope, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu_hotplug.h +2
-1@@ -34,5 +34,6 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,#define CPU_STATUS_MAP "PRS"#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx); +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len);#endif
Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
In reply to Igor MammedovQuoted 77 lines · Igor Mammedov
Quoted 65 lines · On Mon, 30 May 2016 22:02:31 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 64 lines · Igor Mammedov
add necessary wiring to init new CPU hotplug hardware if ICH9-LPC.cpu-hotplug-legacy is "off".
Set ICH9-LPC.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.Signed-off-by Igor Mammedov <[email protected]>---
v1:
- drop ICH9-LPC.cpu-hotplug property--- hw/acpi/ich9.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/acpi/ich9.h | 6 +++++- include/hw/compat.h | 6 +++++- 3 files changed, 47 insertions(+), 7 deletions(-)hw/acpi/ich9.c +23
-1@@ -170,6 +170,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="ich9_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, ICH9LPCPMRegs), +VMSTATE_END_OF_LIST () + } +}; +static bool vmstate_test_use_tco (void *opaque) {ICH9LPCPMRegs *s = opaque;@@ -209,6 +227,7 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, &vmstate_tco_io_state, + &vmstate_cpuhp_state,NULL } };@@ -275,7 +294,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,if (pm->cpu_hotplug_legacy) {legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +OBJECT (lpc_pci), &pm->cpuhp.legacy,ICH9_CPU_HOTPLUG_IO_BASE ); + }else { +cpu_hotplug_hw_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), + &pm->cpuhp.state,ICH9_CPU_HOTPLUG_IO_BASE ); }Quoted 9 lines
hw/acpi/ich9.c void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) · line 417
Quoted 6 lines
hw/acpi/ich9.c +0
-1if (pm->acpi_memory_hotplug.is_enabled) {@@ -414,7 +436,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; - pm->cpu_hotplug_legacy = true;Maybe is too soon to disable legacy CPU hotplug? Will the new cpu hotplug mechanism work from this patch on, or it will break git bisect?
Quoted 5 lines
it doesn't break bisect compile wise nor 'make check' wise, but it's hotplug won't be functional till
acpi: add CPU hotplug methods to DSDT
perhaps I need to move it there or into a separate patch after it.
Exactly, I would move the "enabling" code after the new hotplug mechanism is functional. The same for the next patch for piix4.
Thanks,
Marcel
Quoted 89 lines
Quoted 88 lines
Thanks,
MarcelQuoted 83 lines
hw/acpi/ich9.c +14
-3pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;@@ -461,9 +482,13 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (lpc->pm.cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { +if (lpc->pm.cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.legacy, dev, + errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.state, dev, errp); + } } else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -480,6 +505,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp.state, + dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -494,6 +523,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&lpc->pm.cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));include/hw/acpi/ich9.h +5
-1@@ -23,6 +23,7 @@#include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" @@ -49,7 +50,10 @@ typedef struct ICH9LPCPMRegs {Notifier powerdown_notifier;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug;include/hw/compat.h +5
-1@@ -2,7 +2,11 @@#define HW_COMPAT_H #define HW_COMPAT_2_6 \ -/* empty */ + {\ + .driver = "ICH9-LPC",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
In reply to Marcel ApfelbaumQuoted 13 lines · On Tue, 31 May 2016 13:18:44 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 12 lines · Igor Mammedov
Quoted 9 lines · On Mon, 30 May 2016 21:18:59 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 3 lines · Igor Mammedov
move the former SSDT part of CPU hoplug close to DSDT part. AML is only moved but there isn't any functional change.
The patch looks good to me,
but why did you decide to get rid of thebuild_processor_devicesfunction? I would simply move it to the new file.
Maybe is a matter of taste, anyway:
Quoted 8 lines
Quoted 3 lines
the only reason was that it looks cleaner to me (even for legacy code), that way CPU devices code / defines are in a smaller and
do not pollute already way too bigacpi-build.c.I agree with moving the code, I was referring to the fact that you could keep the function and just move it instead of merging the code in another method. But maybe is only a matter of taste.
Then I misunderstood question, merging build_processor_devices() into build_cpu_hotplug_aml() helped to reuse some local variable and since it is in a dedicated file and used only once I didn't see any reason to keep it as separate function.
But yes I guess it's matter of taste.
Thanks for reviewing series!
Quoted 311 lines
Thanks,
MarcelQuoted 305 lines
For new hotplug it's even necessary so that it would be easy to share with ARM target.
Quoted 299 lines
Reviewed-by Marcel Apfelbaum <[email protected]>Thanks,
MarcelQuoted 290 lines
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug_acpi_table.c | 104 +++++++++++++++++++++++++++++++++++- hw/i386/acpi-build.c | 112 +-------------------------------------- include/hw/acpi/cpu_hotplug.h | 3 +- 3 files changed, 106 insertions(+), 113 deletions(-)hw/acpi/cpu_hotplug_acpi_table.c +103
-1@@ -15,12 +15,19 @@#include "qemu/osdep.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/i386/pc.h" -void build_cpu_hotplug_aml (Aml *ctx) +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len) { +Aml *dev; +Aml *crs; +Aml *pkg; +Aml *field;Aml *method;Aml *if_ctx;Aml *else_ctx; +int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 };Aml *cpu_id =aml_arg (0 );@@ -29,6 +36,9 @@ void build_cpu_hotplug_aml(Aml *ctx)Aml *cpus_map =aml_name (CPU_ON_BITMAP );Aml *zero =aml_int (0 );Aml *one =aml_int (1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); +PCMachineState *pcms =PC_MACHINE (machine);/* * _MAT method - creates an madt apic buffer @@ -132,5 +142,97 @@ void build_cpu_hotplug_aml(Aml *ctx) }aml_append (sb_scope, method); +/* The current AML generator can cover the APIC ID range [0..255], +* inclusive, for VCPU hotplug. */ +QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); +g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); + +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (AML_DECODE16 , io_base, io_base,1 , io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" ,AML_SYSTEM_IO ,aml_int (io_base), io_len)); + field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); + +/* build Processor object for each processor */ +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); + + dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + + method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_append (dev, method); + + method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); +aml_append (method, +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_arg (0 ))) + ); +aml_append (dev, method); + +aml_append (sb_scope, dev); + } + +/* build this code: +* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} +*/ +/* Arg0 = Processor ID = APIC ID */ + method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); +for (i =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); +aml_append (if_ctx, +aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) + ); +aml_append (method, if_ctx); + } +aml_append (sb_scope, method); + +/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" +* +* Note: The ability to create variable-sized packages was first +* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages +* ith up to 255 elements. Windows guests up to win2k8 fail when +* VarPackageOp is used. +*/ + pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : +aml_varpackage (pcms->apic_id_limit); + +for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { +int apic_id = apic_ids->cpus[i].arch_id; + +for (; apic_idx < apic_id; apic_idx++) { +aml_append (pkg,aml_int (0 )); + } +aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); + apic_idx = apic_id +1 ; + } +aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); +g_free (apic_ids); +aml_append (ctx, sb_scope); }hw/i386/acpi-build.c +1
-111@@ -943,114 +943,6 @@ static Aml *build_crs(PCIHostState *host,return crs; } -static void build_processor_devices (Aml *sb_scope,MachineState *machine, -AcpiPmInfo *pm) -{ -int i, apic_idx; -Aml *dev; -Aml *crs; -Aml *pkg; -Aml *field; -Aml *ifctx; -Aml *method; -MachineClass *mc =MACHINE_GET_CLASS (machine); -CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids (machine); -PCMachineState *pcms =PC_MACHINE (machine); - -/* The current AML generator can cover the APIC ID range [0..255], -* inclusive, for VCPU hotplug. */ -QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 ); -g_assert (pcms->apic_id_limit <=ACPI_CPU_HOTPLUG_ID_LIMIT ); - -/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ - dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); -aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); -aml_append (dev, -aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) - ); -/* device present, functioning, decoding, not shown in UI */ -aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); - crs =aml_resource_template (); -aml_append (crs, -aml_io (AML_DECODE16 , pm->cpu_hp_io_base, pm->cpu_hp_io_base,1 , - pm->cpu_hp_io_len) - ); -aml_append (dev,aml_name_decl ("_CRS" , crs)); -aml_append (sb_scope, dev); -/* declare CPU hotplug MMIO region and PRS field to access it */ -aml_append (sb_scope,aml_operation_region ( -"PRST" ,AML_SYSTEM_IO ,aml_int (pm->cpu_hp_io_base), pm->cpu_hp_io_len)); - field =aml_field ("PRST" ,AML_BYTE_ACC ,AML_NOLOCK ,AML_PRESERVE ); -aml_append (field,aml_named_field ("PRS" ,256 )); -aml_append (sb_scope, field); - -/* build Processor object for each processor */ -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); - - method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); -aml_append (dev, method); - - method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED ); -aml_append (method, -aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), -aml_arg (0 ))) - ); -aml_append (dev, method); - -aml_append (sb_scope, dev); - } - -/* build this code: -* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} -*/ -/* Arg0 = Processor ID = APIC ID */ - method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED ); -for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - - ifctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); -aml_append (ifctx, -aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) - ); -aml_append (method, ifctx); - } -aml_append (sb_scope, method); - -/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" -* -* Note: The ability to create variable-sized packages was first -* introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages -* ith up to 255 elements. Windows guests up to win2k8 fail when -* VarPackageOp is used. -*/ - pkg = pcms->apic_id_limit <=255 ?aml_package (pcms->apic_id_limit) : -aml_varpackage (pcms->apic_id_limit); - -for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; - -for (; apic_idx < apic_id; apic_idx++) { -aml_append (pkg,aml_int (0 )); - } -aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); - apic_idx = apic_id +1 ; - } -aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg)); -g_free (apic_ids); -} -static void build_memory_devices (Aml *sb_scope,int nr_mem,uint16_t io_base,uint16_t io_len) {@@ -2043,7 +1935,7 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } -build_cpu_hotplug_aml (dsdt); +build_cpu_hotplug_aml (dsdt, machine, pm->cpu_hp_io_base, pm->cpu_hp_io_len);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2305,8 +2197,6 @@ build_dsdt(GArray *table_data, GArray *linker, sb_scope =aml_scope ("\\_SB" ); { -build_processor_devices (sb_scope, machine, pm); -build_memory_devices (sb_scope, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);include/hw/acpi/cpu_hotplug.h +2
-1@@ -34,5 +34,6 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,#define CPU_STATUS_MAP "PRS"#define CPU_SCAN_METHOD "PRSC" -void build_cpu_hotplug_aml (Aml *ctx); +void build_cpu_hotplug_aml (Aml *ctx,MachineState *machine, +uint16_t io_base,uint16_t io_len);#endif
Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
In reply to Marcel ApfelbaumQuoted 78 lines · On Tue, 31 May 2016 13:21:20 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 77 lines · Igor Mammedov
Quoted 74 lines · On Mon, 30 May 2016 22:02:31 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 66 lines · Igor Mammedov
add necessary wiring to init new CPU hotplug hardware if ICH9-LPC.cpu-hotplug-legacy is "off".
Set ICH9-LPC.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.Signed-off-by Igor Mammedov <[email protected]>---
v1:
- drop ICH9-LPC.cpu-hotplug property--- hw/acpi/ich9.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/acpi/ich9.h | 6 +++++- include/hw/compat.h | 6 +++++- 3 files changed, 47 insertions(+), 7 deletions(-)hw/acpi/ich9.c +23
-1@@ -170,6 +170,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="ich9_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, ICH9LPCPMRegs), +VMSTATE_END_OF_LIST () + } +}; +static bool vmstate_test_use_tco (void *opaque) {ICH9LPCPMRegs *s = opaque;@@ -209,6 +227,7 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, &vmstate_tco_io_state, + &vmstate_cpuhp_state,NULL } };@@ -275,7 +294,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,if (pm->cpu_hotplug_legacy) {legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +OBJECT (lpc_pci), &pm->cpuhp.legacy,ICH9_CPU_HOTPLUG_IO_BASE ); + }else { +cpu_hotplug_hw_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), + &pm->cpuhp.state,ICH9_CPU_HOTPLUG_IO_BASE ); }if (pm->acpi_memory_hotplug.is_enabled) {hw/acpi/ich9.c void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) · line 417
Quoted 4 lines
hw/acpi/ich9.c +0
-1@@ -414,7 +436,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; - pm->cpu_hotplug_legacy = true;Maybe is too soon to disable legacy CPU hotplug? Will the new cpu hotplug mechanism work from this patch on, or it will break git bisect?
Quoted 8 lines
Quoted 5 lines
it doesn't break bisect compile wise nor 'make check' wise, but it's hotplug won't be functional till
acpi: add CPU hotplug methods to DSDT
perhaps I need to move it there or into a separate patch after it.Exactly, I would move the "enabling" code after the new hotplug mechanism is functional. The same for the next patch for piix4.
ok, will do on v2 respin.
Quoted 95 lines
Thanks,
MarcelQuoted 89 lines
Quoted 88 lines
Thanks,
MarcelQuoted 83 lines
hw/acpi/ich9.c +14
-3pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;@@ -461,9 +482,13 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (lpc->pm.cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { +if (lpc->pm.cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.legacy, dev, + errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.state, dev, errp); + } } else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -480,6 +505,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp.state, + dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -494,6 +523,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&lpc->pm.cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));include/hw/acpi/ich9.h +5
-1@@ -23,6 +23,7 @@#include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" @@ -49,7 +50,10 @@ typedef struct ICH9LPCPMRegs {Notifier powerdown_notifier;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug;include/hw/compat.h +5
-1@@ -2,7 +2,11 @@#define HW_COMPAT_H #define HW_COMPAT_2_6 \ -/* empty */ + {\ + .driver = "ICH9-LPC",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
Quoted 87 lines · Igor Mammedov
Quoted 84 lines · On Tue, 31 May 2016 13:21:20 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 82 lines · Igor Mammedov
Quoted 65 lines · On Mon, 30 May 2016 22:02:31 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 64 lines · Igor Mammedov
add necessary wiring to init new CPU hotplug hardware if ICH9-LPC.cpu-hotplug-legacy is "off".
Set ICH9-LPC.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.Signed-off-by Igor Mammedov <[email protected]>---
v1:
- drop ICH9-LPC.cpu-hotplug property--- hw/acpi/ich9.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/acpi/ich9.h | 6 +++++- include/hw/compat.h | 6 +++++- 3 files changed, 47 insertions(+), 7 deletions(-)hw/acpi/ich9.c +23
-1@@ -170,6 +170,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="ich9_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, ICH9LPCPMRegs), +VMSTATE_END_OF_LIST () + } +}; +static bool vmstate_test_use_tco (void *opaque) {ICH9LPCPMRegs *s = opaque;@@ -209,6 +227,7 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, &vmstate_tco_io_state, + &vmstate_cpuhp_state,NULL } };@@ -275,7 +294,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,if (pm->cpu_hotplug_legacy) {legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +OBJECT (lpc_pci), &pm->cpuhp.legacy,ICH9_CPU_HOTPLUG_IO_BASE ); + }else { +cpu_hotplug_hw_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), + &pm->cpuhp.state,ICH9_CPU_HOTPLUG_IO_BASE ); }Quoted 9 lines
hw/acpi/ich9.c void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) · line 417
Quoted 6 lines
hw/acpi/ich9.c +0
-1if (pm->acpi_memory_hotplug.is_enabled) {@@ -414,7 +436,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; - pm->cpu_hotplug_legacy = true;Maybe is too soon to disable legacy CPU hotplug? Will the new cpu hotplug mechanism work from this patch on, or it will break git bisect?
it doesn't break bisect compile wise nor 'make check' wise, but it's hotplug won't be functional till
acpi: add CPU hotplug methods to DSDT
perhaps I need to move it there or into a separate patch after it.
Quoted 3 lines
Quoted 2 lines
Exactly, I would move the "enabling" code after the new hotplug mechanism is functional. The same for the next patch for piix4.
ok, will do on v2 respin.
I have everything up to
pc: use AcpiDeviceIfClass.send_event to issue GPE events
tentatively in my tree - do you plan to rework any of these?
Quoted 95 lines
Quoted 95 lines
Thanks,
MarcelQuoted 89 lines
Quoted 88 lines
Thanks,
MarcelQuoted 83 lines
hw/acpi/ich9.c +14
-3pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;@@ -461,9 +482,13 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (lpc->pm.cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { +if (lpc->pm.cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.legacy, dev, + errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.state, dev, errp); + } } else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -480,6 +505,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp.state, + dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -494,6 +523,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&lpc->pm.cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));include/hw/acpi/ich9.h +5
-1@@ -23,6 +23,7 @@#include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" @@ -49,7 +50,10 @@ typedef struct ICH9LPCPMRegs {Notifier powerdown_notifier;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug;include/hw/compat.h +5
-1@@ -2,7 +2,11 @@#define HW_COMPAT_H #define HW_COMPAT_2_6 \ -/* empty */ + {\ + .driver = "ICH9-LPC",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
In reply to Michael S. TsirkinQuoted 24 lines · On Mon, 30 May 2016 21:21:39 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 23 lines · Igor Mammedov
Quoted 20 lines · On Tue, 17 May 2016 09:29:15 -0600 Eric Blake <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/acpi/ich9.c | 3 ++ hw/acpi/piix4.c | 3 ++ include/hw/acpi/cpu.h | 4 +++ qapi-schema.json | 3 +- trace-events | 2 ++ 6 files changed, 97 insertions(+), 1 deletion(-)+++
b/qapi-schema.jsonqapi-schema.json line 4021
Quoted 4 lines
qapi-schema.json +1
-0@@ -4018,8 +4018,9 @@ ## @ACPISlotType # # @DIMM: memory slot +# @CPU: logical CPU slotMissing a marker '(since 2.7)'
Quoted 3 lines
Quoted 1 line
thanks, fixed in v2.
v2 was never posted.
it will be included when I post v2
(after this review pass is complete)
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
qapi-schema.json line 4023
Quoted 4 lines
qapi-schema.json +1
-1# -{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] } +{ 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }Hmm. ACPISlotType is already on our whitelist of exceptions that allow upper-case names (we prefer lower), so adding another one doesn't necessarily hurt.
I'll keep that in mind.
Re: [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx
In reply to Marcel ApfelbaumQuoted 33 lines · On Mon, 30 May 2016 21:39:50 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 22 lines · Igor Mammedov
In legacy cpu-hotplug ProcessorID == APIC ID is used in MADT and cpu-hotplug AML. It was fine as both are 8bit and unique. Spec depricated
Processor()with corresponding ProcessorID and advises to useDevice()and UID instead of it.However UID is just 32bit and it can't fit ARM's
arch_id(MPIDR)which is 64bit. Also in case of sparsearch_id()distribution, managment/lookup of maps byarch_id(APIC ID/MPIDR)becomes complex and expensive.In preparation to common CPU hotplug with ARM and to simplify lookup in possible_cpus[] map switch ProcessorID to
possible_cpusindex in MADT.Legacy cpu-hotplug considerations:
HW interface of it is APIC ID based bitmask so it's impossible to change, also CPON package in AML also APIC ID based as well all the methods.Quoted 9 lines
To avoid massive rewrite of AML keep is so and just break assumption that ProcessorID == APIC ID, ammending
CPU_MAT_METHODto accept APIC ID andpossible_cpusindex, it needs them both to patch MADT entry template. Also switch topossible_cpusindex Processor(ProcessorID) AML.
That way changes to MADT/AML are minimal and kept inside AML/MADT not affecting external interfaces.
Quoted 1 line
I vaguely understood the explanation, I'll let Eduardo have a look :)
Long story short, patch helps to avoid having different versions of MADT generation code on x86, and in future use common function to build MADT for ARM (generalization should come with ARM's cpu-hotplug support).
Quoted 101 lines
Thanks,
MarcelQuoted 96 lines
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/cpu_hotplug.c | 23 +++++++++++++---------- hw/i386/acpi-build.c | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)hw/acpi/cpu_hotplug.c +13
-10@@ -99,7 +99,8 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,int i, apic_idx;Aml *sb_scope =aml_scope ("_SB" );uint8_t madt_tmpl[8 ] = {0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0 ,0 ,0 }; -Aml *cpu_id =aml_arg (0 ); +Aml *cpu_id =aml_arg (1 ); +Aml *apic_id =aml_arg (0 );Aml *cpu_on =aml_local (0 );Aml *madt =aml_local (1 );Aml *cpus_map =aml_name (CPU_ON_BITMAP );@@ -111,30 +112,31 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* * _MAT method - creates an madt apic buffer -* cpu_id = Arg0 = Processor ID = Local APIC ID +* apic_id = Arg0 = Local APIC ID +* cpu_id = Arg1 = Processor ID * cpu_on = Local0 = CPON flag for this cpu * madt = Local1 = Buffer (in madt apic form) to return */ - method =aml_method (CPU_MAT_METHOD ,1 ,AML_NOTSERIALIZED ); + method =aml_method (CPU_MAT_METHOD ,2 ,AML_NOTSERIALIZED );aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); +aml_store (aml_derefof (aml_index (cpus_map, apic_id)), cpu_on));aml_append (method,aml_store (aml_buffer (sizeof (madt_tmpl), madt_tmpl), madt));/* Update the processor id, lapic id, and enable/disable status */ aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (2 )))); -aml_append (method,aml_store (cpu_id,aml_index (madt,aml_int (3 )))); +aml_append (method,aml_store (apic_id,aml_index (madt,aml_int (3 ))));aml_append (method,aml_store (cpu_on,aml_index (madt,aml_int (4 ))));aml_append (method,aml_return (madt));aml_append (sb_scope, method);/* * _STA method - return ON status of cpu -* cpu_id = Arg0 = Processor ID = Local APIC ID +* apic_id = Arg0 = Local APIC ID * cpu_on = Local0 = CPON flag for this cpu */ method =aml_method (CPU_STATUS_METHOD ,1 ,AML_NOTSERIALIZED );aml_append (method, -aml_store (aml_derefof (aml_index (cpus_map, cpu_id)), cpu_on)); +aml_store (aml_derefof (aml_index (cpus_map, apic_id)), cpu_on)); if_ctx =aml_if (cpu_on); {aml_append (if_ctx,aml_return (aml_int (0xF )));@@ -243,11 +245,12 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - dev =aml_processor (apic_id,0 ,0 ,"CP%.02X" , apic_id); + dev =aml_processor (i,0 ,0 ,"CP%.02X" , apic_id); method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call1 (CPU_MAT_METHOD ,aml_int (apic_id)))); +aml_return (aml_call2 (CPU_MAT_METHOD ,aml_int (apic_id),aml_int (i)) + ));aml_append (dev, method); method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED );@@ -268,7 +271,7 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* build this code: * Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} */ -/* Arg0 = Processor ID = APIC ID */ +/* Arg0 = APIC ID */ method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED );for (i =0 ; i < apic_ids->len; i++) {int apic_id = apic_ids->cpus[i].arch_id;hw/i386/acpi-build.c +1
-1@@ -354,7 +354,7 @@ build_madt(GArray *table_data, GArray *linker, PCMachineState *pcms) apic->type =ACPI_APIC_PROCESSOR ; apic->length =sizeof (*apic); - apic->processor_id = apic_id; + apic->processor_id = i; apic->local_apic_id = apic_id;if (apic_ids->cpus[i].cpu !=NULL ) { apic->flags =cpu_to_le32 (1 );
Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
In reply to Michael S. TsirkinQuoted 88 lines · On Tue, 31 May 2016 15:52:35 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 87 lines · Igor Mammedov
Quoted 84 lines · On Tue, 31 May 2016 13:21:20 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 82 lines · Igor Mammedov
Quoted 65 lines · On Mon, 30 May 2016 22:02:31 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 64 lines · Igor Mammedov
add necessary wiring to init new CPU hotplug hardware if ICH9-LPC.cpu-hotplug-legacy is "off".
Set ICH9-LPC.cpu-hotplug-legacy to "off" by default and switch legacy hotplug to enabled only for 2.6 and older machine types.Signed-off-by Igor Mammedov <[email protected]>---
v1:
- drop ICH9-LPC.cpu-hotplug property--- hw/acpi/ich9.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/acpi/ich9.h | 6 +++++- include/hw/compat.h | 6 +++++- 3 files changed, 47 insertions(+), 7 deletions(-)hw/acpi/ich9.c +23
-1@@ -170,6 +170,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_cpuhp (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return !s->cpu_hotplug_legacy; +} + +static const VMStateDescription vmstate_cpuhp_state = { + .name ="ich9_pm/cpuhp" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_cpuhp, + .fields = (VMStateField []) { +VMSTATE_CPU_HOTPLUG (cpuhp.state, ICH9LPCPMRegs), +VMSTATE_END_OF_LIST () + } +}; +static bool vmstate_test_use_tco (void *opaque) {ICH9LPCPMRegs *s = opaque;@@ -209,6 +227,7 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state, &vmstate_tco_io_state, + &vmstate_cpuhp_state,NULL } };@@ -275,7 +294,10 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,if (pm->cpu_hotplug_legacy) {legacy_acpi_cpu_hotplug_init (pci_address_space_io (lpc_pci), -OBJECT (lpc_pci), &pm->gpe_cpu,ICH9_CPU_HOTPLUG_IO_BASE ); +OBJECT (lpc_pci), &pm->cpuhp.legacy,ICH9_CPU_HOTPLUG_IO_BASE ); + }else { +cpu_hotplug_hw_init (pci_address_space_io (lpc_pci),OBJECT (lpc_pci), + &pm->cpuhp.state,ICH9_CPU_HOTPLUG_IO_BASE ); }Quoted 9 lines
hw/acpi/ich9.c void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) · line 417
Quoted 6 lines
hw/acpi/ich9.c +0
-1if (pm->acpi_memory_hotplug.is_enabled) {@@ -414,7 +436,6 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ; pm->acpi_memory_hotplug.is_enabled = true; - pm->cpu_hotplug_legacy = true;Maybe is too soon to disable legacy CPU hotplug? Will the new cpu hotplug mechanism work from this patch on, or it will break git bisect?
it doesn't break bisect compile wise nor 'make check' wise, but it's hotplug won't be functional till
acpi: add CPU hotplug methods to DSDT
perhaps I need to move it there or into a separate patch after it.
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Exactly, I would move the "enabling" code after the new hotplug mechanism is functional. The same for the next patch for piix4.
ok, will do on v2 respin.
I have everything up to
pc: use AcpiDeviceIfClass.send_event to issue GPE events
tentatively in my tree - do you plan to rework any of these?
I don't plan to rework any of those.
I'll respin v2 on top of your tree starting from:
[PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
depending on outcome of reviews.
Quoted 96 lines
Quoted 96 lines
Quoted 96 lines
Thanks,
MarcelQuoted 89 lines
Quoted 88 lines
Thanks,
MarcelQuoted 83 lines
hw/acpi/ich9.c +14
-3pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ;@@ -461,9 +482,13 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); - } else if (lpc->pm.cpu_hotplug_legacy && -object_dynamic_cast (OBJECT (dev ),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { +if (lpc->pm.cpu_hotplug_legacy) { +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.legacy, dev, + errp); + }else { +acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp.state, dev, errp); + } } else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -480,6 +505,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp.state, + dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -494,6 +523,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && + !lpc->pm.cpu_hotplug_legacy) { +acpi_cpu_unplug_cb (&lpc->pm.cpuhp.state, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));include/hw/acpi/ich9.h +5
-1@@ -23,6 +23,7 @@#include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" #include "hw/acpi/tco.h" @@ -49,7 +50,10 @@ typedef struct ICH9LPCPMRegs {Notifier powerdown_notifier;bool cpu_hotplug_legacy; -AcpiCpuHotplug gpe_cpu; +union { +AcpiCpuHotplug legacy;/* used for keeping legacy state */ +CPUHotplugState state; + } cpuhp;MemHotplugState acpi_memory_hotplug;include/hw/compat.h +5
-1@@ -2,7 +2,11 @@#define HW_COMPAT_H #define HW_COMPAT_2_6 \ -/* empty */ + {\ + .driver = "ICH9-LPC",\ + .property = "cpu-hotplug-legacy",\ + .value = "on",\ + },\#define HW_COMPAT_2_5 \ {\
Re: [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug
In reply to Marcel ApfelbaumQuoted 5 lines · On Mon, 30 May 2016 21:50:08 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>Maybe it worth adding some kind of explanation
of the functionality added here.
I'll add a bit more detailed explanation here
Quoted 317 lines
Thanks,
MarcelQuoted 312 lines
---
v1:
- drop CPUHotplugState.is_enabled field--- hw/acpi/Makefile.objs | 1 + hw/acpi/cpu.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/cpu.h | 52 +++++++++++++ trace-events | 9 +++ 4 files changed, 268 insertions(+)create mode 100644
hw/acpi/cpu.c
create mode 100644include/hw/acpi/cpu.hhw/acpi/Makefile.objs +1
-0@@ -2,6 +2,7 @@ common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.o +common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI) += acpi_interface.o common-obj-$(CONFIG_ACPI) += bios-linker-loader.ohw/acpi/cpu.c new file +206
-0@@ -0,0 +1,206 @@ +#include "qemu/osdep.h" +#include "hw/boards.h" +#include "hw/acpi/cpu.h" +#include "qapi/error.h" +#include "trace.h" + +#define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SELECTOR_OFFSET_WR 0 +#define ACPI_CPU_FLAGS_OFFSET_RW 4 + +static uint64_t cpu_hotplug_rd (void *opaque,hwaddr addr,unsigned size) +{ +uint64_t val = ~0 ; +CPUHotplugState *cpu_st = opaque; +AcpiCpuStatus *cdev; + +if (cpu_st->selector >= cpu_st->dev_count) { +return val; + } + + cdev = &cpu_st->devs[cpu_st->selector]; +switch (addr) { +case ACPI_CPU_FLAGS_OFFSET_RW :/* pack and return is_* fields */ + val =0 ; + val |= cdev->is_enabled ?1 :0 ; + val |= cdev->is_inserting ?2 :0 ; + val |= cdev->is_removing ?4 :0 ; +trace_cpuhp_acpi_read_flags (cpu_st->selector, val); +break ; +default : +break ; + } +return val; +} + +static void cpu_hotplug_wr (void *opaque,hwaddr addr,uint64_t data, +unsigned int size) +{ +CPUHotplugState *cpu_st = opaque; +AcpiCpuStatus *cdev; +Error *local_err =NULL ; + +assert (cpu_st->dev_count); + +if (addr) { +if (cpu_st->selector >= cpu_st->dev_count) { +trace_cpuhp_acpi_invalid_idx_selected (cpu_st->selector); +return ; + } + } + +switch (addr) { +case ACPI_CPU_SELECTOR_OFFSET_WR :/* current CPU selector */ + cpu_st->selector = data; +trace_cpuhp_acpi_write_idx (cpu_st->selector); +break ; +case ACPI_CPU_FLAGS_OFFSET_RW :/* set is_* fields */ + cdev = &cpu_st->devs[cpu_st->selector]; +if (data &2 ) {/* clear insert event */ + cdev->is_inserting = false; +trace_cpuhp_acpi_clear_inserting_evt (cpu_st->selector); + }else if (data &4 ) {/* clear remove event */ + cdev->is_removing = false; +trace_cpuhp_acpi_clear_remove_evt (cpu_st->selector); + }else if (data &8 ) { +DeviceState *dev =NULL ; +HotplugHandler *hotplug_ctrl =NULL ; + +if (!cdev->is_enabled) { +trace_cpuhp_acpi_ejecting_invalid_cpu (cpu_st->selector); +break ; + } + +trace_cpuhp_acpi_ejecting_cpu (cpu_st->selector); + dev =DEVICE (cdev->cpu); + hotplug_ctrl =qdev_get_hotplug_handler (dev); +hotplug_handler_unplug (hotplug_ctrl, dev, &local_err); +if (local_err) { +break ; + } + } +break ; +default : +break ; + } +error_free (local_err); +} + +static const MemoryRegionOps cpu_hotplug_ops = { + .read = cpu_hotplug_rd, + .write = cpu_hotplug_wr, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =4 , + }, +}; + +void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner, +CPUHotplugState *state,hwaddr base_addr) +{ +MachineState *machine =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (machine); +CPUArchIdList *id_list; +int i; + + id_list = mc->possible_cpu_arch_ids (machine); + state->dev_count = id_list->len; + state->devs =g_new0 (typeof (*state->devs), state->dev_count); +for (i =0 ; i < id_list->len; i++) { + state->devs[i].cpu = id_list->cpus[i].cpu; + state->devs[i].arch_id = id_list->cpus[i].arch_id; + state->devs[i].is_enabled = id_list->cpus[i].cpu ? true : false; + } +g_free (id_list); +memory_region_init_io (&state->ctrl_reg, owner, &cpu_hotplug_ops, state, +"acpi-mem-hotplug" ,ACPI_CPU_HOTPLUG_REG_LEN ); +memory_region_add_subregion (as, base_addr, &state->ctrl_reg); +} + +static AcpiCpuStatus *get_cpu_status (CPUHotplugState *cpu_st,DeviceState *dev) +{ +CPUClass *k =CPU_GET_CLASS (dev); +uint64_t cpu_arch_id = k->get_arch_id (CPU (dev)); +int i; + +for (i =0 ; i < cpu_st->dev_count; i++) { +if (cpu_arch_id == cpu_st->devs[i].arch_id) { +return &cpu_st->devs[i]; + } + } +return NULL ; +} + +void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st,DeviceState *dev,Error **errp) +{ +AcpiCpuStatus *cdev; + + cdev =get_cpu_status (cpu_st, dev); +if (!cdev) { +return ; + } + + cdev->cpu =CPU (dev); + cdev->is_enabled = true; +if (dev->hotplugged) { + cdev->is_inserting = true; +ACPI_SEND_EVENT (hotplug_dev,ACPI_CPU_HOTPLUG_STATUS ); + } +} + +void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp) +{ +AcpiCpuStatus *cdev; + + cdev =get_cpu_status (cpu_st, dev); +if (!cdev) { +return ; + } + + cdev->is_removing = true; +ACPI_SEND_EVENT (hotplug_dev,ACPI_CPU_HOTPLUG_STATUS ); +} + +void acpi_cpu_unplug_cb (CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp) +{ +AcpiCpuStatus *cdev; + + cdev =get_cpu_status (cpu_st, dev); +if (!cdev) { +return ; + } + + cdev->cpu =NULL ; + cdev->is_enabled = false; +} + +static const VMStateDescription vmstate_cpuhp_sts = { + .name ="CPU hotplug device state" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_BOOL (is_enabled, AcpiCpuStatus), +VMSTATE_BOOL (is_inserting, AcpiCpuStatus), +VMSTATE_BOOL (is_removing, AcpiCpuStatus), +VMSTATE_END_OF_LIST () + } +}; + +const VMStateDescription vmstate_cpu_hotplug = { + .name ="CPU hotplug state" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (selector, CPUHotplugState), +VMSTATE_STRUCT_VARRAY_POINTER_UINT32 (devs, CPUHotplugState, dev_count, + vmstate_cpuhp_sts, AcpiCpuStatus), +VMSTATE_END_OF_LIST () + } +};include/hw/acpi/cpu.h new file +52
-0@@ -0,0 +1,52 @@ +/* +* QEMU ACPI hotplug utilities +* +* Copyright (C) 2016 Red Hat Inc +* +* Authors: +* Igor Mammedov <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef ACPI_CPU_H +#define ACPI_CPU_H + +#include "hw/qdev-core.h" +#include "hw/acpi/acpi.h" +#include "hw/hotplug.h" + +typedef struct AcpiCpuStatus { +struct CPUState *cpu; +uint64_t arch_id; +bool is_enabled; +bool is_inserting; +bool is_removing; +}AcpiCpuStatus ; + +typedef struct CPUHotplugState { +MemoryRegion ctrl_reg; +uint32_t selector; +uint32_t dev_count; +AcpiCpuStatus *devs; +}CPUHotplugState ; + +void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st,DeviceState *dev,Error **errp); + +void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp); + +void acpi_cpu_unplug_cb (CPUHotplugState *cpu_st, +DeviceState *dev,Error **errp); + +void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner, +CPUHotplugState *state,hwaddr base_addr); + +extern const VMStateDescription vmstate_cpu_hotplug; +#define VMSTATE_CPU_HOTPLUG (cpuhp, state) \ + VMSTATE_STRUCT(cpuhp, state, 1, \ + vmstate_cpu_hotplug, CPUHotplugState) + +#endif trace-events +9
-0@@ -1908,3 +1908,12 @@ aspeed_vic_update_fiq(int flags) "Raising FIQ: %d" aspeed_vic_update_irq(int flags) "Raising IRQ: %d" aspeed_vic_read(uint64_t offset, unsigned size, uint32_t value) "From 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 + +# hw/acpi/cpu.c +cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32 +cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8 +cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]" +cpuhp_acpi_clear_remove_evt(uint32_t idx) "idx[0x%"PRIx32"]" +cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32 +cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32 +cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32
Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
In reply to Michael S. TsirkinQuoted 47 lines · On Tue, 31 May 2016 07:49:16 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 12 deletions(-)docs/specs/acpi_cpu_hotplug.txt +6
-7@@ -4,21 +4,85 @@ QEMU<->ACPI BIOS CPU hotplug interface QEMU supports CPU hotplug via ACPI. This document describes the interface between QEMU and the ACPI BIOS. -ACPI GPE block (IO ports 0xafe0-0xafe3, byte access): ------------------------------------------ - -Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU -hot-add/remove event to ACPI BIOS, via SCI interrupt. +ACPI BIOS GPE.2 handler is dedicated for notifying OS about CPU hot-add +and hot-remove events. +============================================ +Legacy ACPI CPU hotplug interface registers: +-------------------------------------------- CPU present bitmap for: + One bit per CPU. Bit position reflects corresponding CPU APIC ID. Read-only. ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access) PIIX-PM (IO port 0xaf00-0xaf1f, 1-byte access) --------------------------------------------------------------- -One bit per CPU. Bit position reflects corresponding CPU APIC ID. -Read-only.docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 27
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +10
-0+QEMU sets corresponding CPU bit on hot-add event and issues SCI +with GPE.2 event set. CPU present map read by ACPI BIOS GPE.2 handler +to notify OS about CPU hot-add events. CPU hot-remove isn't supported. + +===================================== +ACPI CPU hotplug interface registers: +------------------------------------- +Register block base address: + ICH9-LPC IO port 0x0cd8 + PIIX-PM IO port 0xaf00OK but this means we either use legacy or new one, bot both, which is problematic for people using old seabios without acpi loading support and with -M pc.
Quoted 3 lines
I don't say we must support them with >255 CPUs,
but I do say we should make an effort for simple
setups with <255 CPUs.
it works with QEMU provided(shipped) BIOS,
it works for migration case as legacy stays enables because of -M src_legacy_machine
more that 255 cpus will break old BIOS in different ways /corrupt/hang/ depending on BIOS version.
I'm not sure we should care about using old BIOS with new QEMU+new machine type though and allow expectations to be beyond what hw vendors usually set. It's the same as real hw does i.e. new hardware shipped with new BIOS.
If user insist on old BIOS+new machine type he still has property knob to force legacy mode.
on the fist glance, it's probably not that very hard to switch IO ports handling from legacy to new interface by sending from new cpu-hotplug AML a command to do so, my concerns here is:
* +1 more state to migrate
* probably issues with migration as target started with different IO layout
* IO window freed after switching from legacy to new, will not be available to guest as it started with legacy window consumed by CPUS.CRS.
* that legacy switching business is only PC specific means having a knob to turn it on so it won't pollute ARM
all in all it's probably too much headache to make sure that improbable usecase would work, so after considering this idea I've dropped it and did it the way it's now.
Quoted 9 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 31
Quoted 4 lines
docs/specs/acpi_cpu_hotplug.txt +4
-0+Register block size: + ACPI_CPU_HOTPLUG_REG_LEN = 12 + +read access:So this implies acpi must scan all cpus on each event, and this seems too aggressive.
I think we need something hierarchical where
you read one level and know which cpus to probe.
That's what we do for mem-hotplug as it's not performance critical path.
In addition to that depending on guest OS/version it will anyway do enumeration of all CPUs after our hotplug AML method scanned all CPUs and sent notifies.
not that I'm in favor of complicating this protocol, but I wouldn't do it hierarchical,
that's what Notify(BUS_CHECK) is supposed to do but it's broken on some guests.
So if I'd do a more complicated protocol,
I'd do polling from AML side telling QEMU
if (cpu = give_me_next_cpu_with_event())
switch_to_cpu(cpu)
...that means adding extra state to migrate, probably ther might be other issues I'm not aware of yet.
On the other hand mem-hotplug like interface so far hasn't caused any issues
(that of cause doesn't mean that there aren't any).
Quoted 17 lines
Quoted 17 lines
docs/specs/acpi_cpu_hotplug.txt +17
-0+ offset: + [0x0-0x3] reserved + [0x4] CPU device status fields: (1 byte access) + bits: + 0: Device is enabled and may be used by guest + 1: Device insert event, used to distinguish device for which + no device check event to OSPM was issued. + It's valid only when bit 0 is set. + 2: Device remove event, used to distinguish device for which + no device eject request to OSPM was issued. + 3-7: reserved and should be ignored by OSPM + [0x5-0x7] reserved + [0x8] Command data: (DWORD access) + in case of error or unsupported command reads is 0xFFFFFFFF + current 'Command field' value: + 0: returns PXM value corresponding to device +
Quoted 8 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 53
Quoted 5 lines
docs/specs/acpi_cpu_hotplug.txt +5
-0+write access: + offset: + [0x0-0x3] CPU selector: (DWORD access) + selects active CPU device. All following accesses to other + registers will read/store data from/to selected CPU.I've been thinking - is it time to add an EmbeddedControl interface? This way we have another namespace.
There were patches on list with it some time ago
"[PATCH RFC v2 0/7] coordinate cpu hotplug/unplug bewteen QEMU and kernel by EC"
but we dropped it as bloatware because there weren't any real need for it as current IO port interfaces aren't going away any time soon and work just fine without EC. And if we were to move current interfaces into EC namespace we would have to do it only for new machines types and keep old code in place as well and a bunch of compat code for a company.
Quoted 1 line
Not insisting on it, just an idea.
I wouldn't make it a necessary dependency and block this series. Might be worth to look at again when there is usecases for it without legacy stuff attached.
Quoted 31 lines
Quoted 31 lines
docs/specs/acpi_cpu_hotplug.txt +29
-0+ [0x4] CPU device control fields: (1 byte access) + bits: + 0: reserved, OSPM must clear it before writing to register. + 1: if set to 1 clears device insert event, set by OSPM + after it has emitted device check event for the + selected CPU device + 2: if set to 1 clears device remove event, set by OSPM + after it has emitted device eject request for the + selected CPU device + 3: if set to 1 initiates device eject, set by OSPM when it + triggers CPU device removal and calls _EJ0 method + 4-7: reserved, OSPM must clear them before writing to register + [0x5] Command field: (1 byte access) + value: + 0: following reads from 'Command data' register returns PXM + value of device + 1: following writes to 'Command data' register set OST event + register in QEMU + 2: following writes to 'Command data' register set OST status + register in QEMU + other values: reserved + [0x6-0x7] reserved + [0x8] Command data: (DWORD access) + current 'Command field' value: + 1: stores value into OST event register + 2: stores value into OST status register, triggers + ACPI_DEVICE_OST QMP event from QEMU to external applications + with current values of OST event and status registers. + other values: reserved
Quoted 12 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 88
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +5
-5-CPU hot-add/remove notification: ------------------------------------------------------ -QEMU sets/clears corresponding CPU bit on hot-add/remove event. -CPU present map read by ACPI BIOS GPE.2 handler to notify OS of CPU -hot-(un)plug events. +Selecting CPU device beyond possible range has no effect on platform: + - write accesses to CPU hot-plug registers not documented above are + ignored + - read accesses to CPU hot-plug registers not documented above return + all bits set to 1.why not 0?
isn't hardware usually return 1s on unhandled IO reads? (I even thought that's it was you who told me it)
that's what has been done for memory hotplug, so I'm doing the same here.
Quoted 4 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1
Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
Quoted 82 lines · Igor Mammedov
Quoted 47 lines · On Tue, 31 May 2016 07:49:16 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 12 deletions(-)docs/specs/acpi_cpu_hotplug.txt +6
-7@@ -4,21 +4,85 @@ QEMU<->ACPI BIOS CPU hotplug interface QEMU supports CPU hotplug via ACPI. This document describes the interface between QEMU and the ACPI BIOS. -ACPI GPE block (IO ports 0xafe0-0xafe3, byte access): ------------------------------------------ - -Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU -hot-add/remove event to ACPI BIOS, via SCI interrupt. +ACPI BIOS GPE.2 handler is dedicated for notifying OS about CPU hot-add +and hot-remove events. +============================================ +Legacy ACPI CPU hotplug interface registers: +-------------------------------------------- CPU present bitmap for: + One bit per CPU. Bit position reflects corresponding CPU APIC ID. Read-only. ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access) PIIX-PM (IO port 0xaf00-0xaf1f, 1-byte access) --------------------------------------------------------------- -One bit per CPU. Bit position reflects corresponding CPU APIC ID. -Read-only.docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 27
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +10
-0+QEMU sets corresponding CPU bit on hot-add event and issues SCI +with GPE.2 event set. CPU present map read by ACPI BIOS GPE.2 handler +to notify OS about CPU hot-add events. CPU hot-remove isn't supported. + +===================================== +ACPI CPU hotplug interface registers: +------------------------------------- +Register block base address: + ICH9-LPC IO port 0x0cd8 + PIIX-PM IO port 0xaf00OK but this means we either use legacy or new one, bot both, which is problematic for people using old seabios without acpi loading support and with -M pc.
Quoted 3 lines
I don't say we must support them with >255 CPUs,
but I do say we should make an effort for simple
setups with <255 CPUs.it works with QEMU provided(shipped) BIOS,
it works for migration case as legacy stays enables because of -Msrc_legacy_machinemore that 255 cpus will break old BIOS in different ways /corrupt/hang/ depending on BIOS version.
I'm not sure we should care about using old BIOS with new QEMU+new machine type though and allow expectations to be beyond what hw vendors usually set. It's the same as real hw does i.e. new hardware shipped with new BIOS.
If user insist on old BIOS+new machine type he still has property knob to force legacy mode.on the fist glance, it's probably not that very hard to switch IO ports handling from legacy to new interface by sending from new cpu-hotplug AML a command to do so, my concerns here is:
* +1 more state to migrate
* probably issues with migration as target started with different IO layout
* IO window freed after switching from legacy to new, will not be available to guest as it started with legacy window consumed by CPUS.CRS.
* that legacy switching business is only PC specific means having a knob to turn it on so it won't pollute ARM
Quoted 3 lines
all in all it's probably too much headache to make sure that improbable usecase would work, so after considering this idea I've dropped it and did it the way it's now.
Well I think it's worth the effort. I agree it's tricky to implement but we do maintain compatibility for years. Being orthogonal with bios version is very helpful for a variety of reasons such as debugging.
Quoted 17 lines
Quoted 9 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 31
Quoted 4 lines
docs/specs/acpi_cpu_hotplug.txt +4
-0+Register block size: + ACPI_CPU_HOTPLUG_REG_LEN = 12 + +read access:So this implies acpi must scan all cpus on each event, and this seems too aggressive.
I think we need something hierarchical where
you read one level and know which cpus to probe.That's what we do for mem-hotplug as it's not
performance critical path.In addition to that depending on guest OS/version it will anyway do enumeration of all CPUs after our hotplug AML method scanned all CPUs and
sent notifies.
Quoted 4 lines
not that I'm in favor of complicating this protocol, but I wouldn't do it hierarchical,
that's whatNotify(BUS_CHECK)is supposed to do but it's broken on some guests.
Interesting. Which ones? Would they be easy to detect?
Quoted 39 lines
So if I'd do a more complicated protocol,
I'd do polling from AML side telling QEMU
if (cpu =give_me_next_cpu_with_event())switch_to_cpu(cpu) ...that means adding extra state to migrate, probably ther might be other issues I'm not aware of yet.
On the other hand mem-hotplug like interface so far hasn't caused any issues
(that of cause doesn't mean that there aren't any).Quoted 17 lines
Quoted 17 lines
docs/specs/acpi_cpu_hotplug.txt +17
-0+ offset: + [0x0-0x3] reserved + [0x4] CPU device status fields: (1 byte access) + bits: + 0: Device is enabled and may be used by guest + 1: Device insert event, used to distinguish device for which + no device check event to OSPM was issued. + It's valid only when bit 0 is set. + 2: Device remove event, used to distinguish device for which + no device eject request to OSPM was issued. + 3-7: reserved and should be ignored by OSPM + [0x5-0x7] reserved + [0x8] Command data: (DWORD access) + in case of error or unsupported command reads is 0xFFFFFFFF + current 'Command field' value: + 0: returns PXM value corresponding to device +Quoted 8 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 53
Quoted 5 lines
docs/specs/acpi_cpu_hotplug.txt +5
-0+write access: + offset: + [0x0-0x3] CPU selector: (DWORD access) + selects active CPU device. All following accesses to other + registers will read/store data from/to selected CPU.I've been thinking - is it time to add an EmbeddedControl interface? This way we have another namespace.
Quoted 7 lines
There were patches on list with it some time ago
"[PATCH RFC v2 0/7] coordinate cpu hotplug/unplug bewteen QEMU and kernel by EC"
but we dropped it as bloatware because there weren't any real need for it as current IO port interfaces aren't going away any time soon and work just fine without EC.
Right. But now you are removing them for >255 CPUs anyway.
Quoted 4 lines
And if we were to move current interfaces into EC namespace we would have to do it only for new machines types and keep old code in place as well and a bunch of compat code for a company.
Hmm. Exactly like this current one?
Quoted 4 lines
Quoted 1 line
Not insisting on it, just an idea.
I wouldn't make it a necessary dependency and block this series. Might be worth to look at again when there is usecases for it without legacy stuff attached.
and then we'll have to maintain 3 interfaces?
Quoted 43 lines
Quoted 31 lines
Quoted 31 lines
docs/specs/acpi_cpu_hotplug.txt +29
-0+ [0x4] CPU device control fields: (1 byte access) + bits: + 0: reserved, OSPM must clear it before writing to register. + 1: if set to 1 clears device insert event, set by OSPM + after it has emitted device check event for the + selected CPU device + 2: if set to 1 clears device remove event, set by OSPM + after it has emitted device eject request for the + selected CPU device + 3: if set to 1 initiates device eject, set by OSPM when it + triggers CPU device removal and calls _EJ0 method + 4-7: reserved, OSPM must clear them before writing to register + [0x5] Command field: (1 byte access) + value: + 0: following reads from 'Command data' register returns PXM + value of device + 1: following writes to 'Command data' register set OST event + register in QEMU + 2: following writes to 'Command data' register set OST status + register in QEMU + other values: reserved + [0x6-0x7] reserved + [0x8] Command data: (DWORD access) + current 'Command field' value: + 1: stores value into OST event register + 2: stores value into OST status register, triggers + ACPI_DEVICE_OST QMP event from QEMU to external applications + with current values of OST event and status registers. + other values: reservedQuoted 12 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 88
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +5
-5-CPU hot-add/remove notification: ------------------------------------------------------ -QEMU sets/clears corresponding CPU bit on hot-add/remove event. -CPU present map read by ACPI BIOS GPE.2 handler to notify OS of CPU -hot-(un)plug events. +Selecting CPU device beyond possible range has no effect on platform: + - write accesses to CPU hot-plug registers not documented above are + ignored + - read accesses to CPU hot-plug registers not documented above return + all bits set to 1.why not 0?
Quoted 2 lines
isn't hardware usually return 1s on unhandled IO reads? (I even thought that's it was you who told me it)
PCI does but it's special.
Quoted 7 lines
that's what has been done for memory hotplug, so I'm doing the same here.
Quoted 4 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1
Re: [Qemu-devel] [PATCH v2 1/33] tests: acpi: report names of expected files in verbose mode
In reply to Igor MammedovQuoted 39 lines · Igor Mammedov
print expected file name if it doesn't exists if verbose mode is enabled*. It helps to avoid running bios-tables-test under debugger to figure out missing file name.
*)
verbose mode is enabled if "V" env. variable is setSigned-off-by Igor Mammedov <[email protected]>---
v2: replace 'for' loop with more readble 'goto'
Marcel Apfelbaum <[email protected]>--- tests/bios-tables-test.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)tests/bios-tables-test.c +1
-1@@ -464,7 +464,6 @@ static GArray *load_expected_aml(test_data *data) {int i;AcpiSdtTable *sdt; -gchar *aml_file =NULL ;GError *error =NULL ;gboolean ret;@@ -472,6 +471,7 @@ static GArray *load_expected_aml(test_data *data)for (i =0 ; i < data->tables->len; ++i) {AcpiSdtTable exp_sdt;uint32_t signature; +gchar *aml_file =NULL ;const char *ext = data->variant ? data->variant :"" ; sdt = &g_array_index (data->tables, AcpiSdtTable, i);@@ -484,13 +484,21 @@ static GArray *load_expected_aml(test_data *data) try_again: aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
tests/bios-tables-test.c static GArray *load_expected_aml(test_data *data) · line 493
Quoted 10 lines
tests/bios-tables-test.c +7
-2(gchar *)&signature, ext); -if (data->variant && !g_file_test (aml_file,G_FILE_TEST_EXISTS )) { -g_free (aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nLooking for expected file '%s'\n" , aml_file); + } +if (g_file_test (aml_file,G_FILE_TEST_EXISTS )) { + exp_sdt.aml_file = aml_file; + }else if (*ext !='\0' ) { +/* try fallback to generic (extention less) expected file */
:s/extention/extension
Quoted 4 lines
tests/bios-tables-test.c +1
-0ext ="" ; +g_free (aml_file); goto try_again;
tests/bios-tables-test.c static GArray *load_expected_aml(test_data *data) · line 504
Quoted 10 lines
tests/bios-tables-test.c +4
-2} - exp_sdt.aml_file = aml_file; -g_assert (g_file_test (aml_file,G_FILE_TEST_EXISTS )); +g_assert (exp_sdt.aml_file); +if (getenv ("V" )) { +fprintf (stderr,"\nUsing expected file '%s'\n" , aml_file); + } ret =g_file_get_contents (aml_file, &exp_sdt.aml, &exp_sdt.aml_len, &error);g_assert (ret);
Thanks,
Marcel
Re: [Qemu-devel] [PATCH v2 13/33] acpi: extend ACPI interface to provide send_event hook
In reply to Igor MammedovQuoted 28 lines · Igor Mammedov
send_event()hook will allow to send ACPI event in a target specific way (GPE or GPIO based impl.) it will also simplify proxy wrappers in piix4pm/ich9 that access ACPI regs and SCI which are part of piix4pm/lcp_ich9 devices and callacpi_foo()API directly.Signed-off-by Igor Mammedov <[email protected]>---
Following patch will use hook to simplify hotplug callbacks in piix4pm/ich9.v2:
- makeACPI_SEND_EVENTmacro a function Marcel Apfelbaum <[email protected]>--- hw/acpi/acpi_interface.c | 9 +++++++++ hw/acpi/core.c | 2 +- hw/acpi/piix4.c | 8 ++++++++ hw/isa/lpc_ich9.c | 8 ++++++++ include/hw/acpi/acpi.h | 10 ++-------- include/hw/acpi/acpi_dev_interface.h | 11 +++++++++++ 6 files changed, 39 insertions(+), 9 deletions(-)hw/acpi/acpi_interface.c +0
-0
hw/acpi/acpi_interface.c line 7
Quoted 6 lines
hw/acpi/acpi_interface.c +3
-0@@ -2,6 +2,15 @@#include "hw/acpi/acpi_dev_interface.h" #include "qemu/module.h" +void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) +{ +AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (dev);
Is the above conversion safe? Sorry for not mention it earlier.
Thanks,
Marcel
Quoted 150 lines
hw/acpi/acpi_interface.c +6
-0+if (adevc->send_event) { +AcpiDeviceIf *adev =ACPI_DEVICE_IF (dev); + adevc->send_event (adev, event); + } +} +static void register_types (void ) {static const TypeInfo acpi_dev_if_info = {hw/acpi/core.c +1
-1@@ -698,7 +698,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) }void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status) +AcpiEventStatusBits status) { ar->gpe.sts[0 ] |= status;acpi_update_sci (ar, irq);hw/acpi/piix4.c +8
-0@@ -586,6 +586,13 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); } +static void piix4_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +PIIX4PMState *s =PIIX4_PM (adev); + +acpi_send_gpe_event (&s->ar, s->irq, ev); +} +static Property piix4_pm_properties[] = {DEFINE_PROP_UINT32 ("smb_io_base" , PIIX4PMState, smb_io_base,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),@@ -624,6 +631,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug_request = piix4_device_unplug_request_cb; hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; + adevc->send_event = piix4_send_gpe; }static const TypeInfo piix4_pm_info = {hw/isa/lpc_ich9.c +8
-0@@ -703,6 +703,13 @@ static Property ich9_lpc_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void ich9_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (adev); + +acpi_send_gpe_event (&s->pm.acpi_regs, s->pm.irq, ev); +} +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -730,6 +737,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug_request = ich9_device_unplug_request_cb; hc->unplug = ich9_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; + adevc->send_event = ich9_send_gpe; }static const TypeInfo ich9_lpc_info = {include/hw/acpi/acpi.h +2
-8@@ -23,6 +23,7 @@#include "qemu/option.h" #include "exec/memory.h" #include "hw/irq.h" +#include "hw/acpi/acpi_dev_interface.h" /* * current device naming scheme supports up to 256 memory devices @@ -89,13 +90,6 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 -/* These values are part of guest ABI, and can not be changed */ -typedef enum { -ACPI_PCI_HOTPLUG_STATUS =2 , -ACPI_CPU_HOTPLUG_STATUS =4 , -ACPI_MEMORY_HOTPLUG_STATUS =8 , -}AcpiGPEStatusBits ; -/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;@@ -172,7 +166,7 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr);void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status); +AcpiEventStatusBits status);void acpi_update_sci (ACPIREGS *acpi_regs,qemu_irq irq);include/hw/acpi/acpi_dev_interface.h +11
-0@@ -4,6 +4,13 @@#include "qom/object.h" #include "qapi-types.h" +/* These values are part of guest ABI, and can not be changed */ +typedef enum { +ACPI_PCI_HOTPLUG_STATUS =2 , +ACPI_CPU_HOTPLUG_STATUS =4 , +ACPI_MEMORY_HOTPLUG_STATUS =8 , +}AcpiEventStatusBits ; +#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"#define ACPI_DEVICE_IF_CLASS (klass) \@@ -22,11 +29,14 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf; +void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event); +/** * AcpiDeviceIfClass: * * ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. +* send_event: inject a specified event into guest * * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without @@ -39,5 +49,6 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); } AcpiDeviceIfClass;#endif
Re: [Qemu-devel] [PATCH v2 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events
In reply to Igor MammedovQuoted 35 lines · Igor Mammedov
it reduces number of args passed in handlers by 1 and a number of used proxy wrappers saving ~20LOC. Also it allows to make cpu/mem hotplug code more universal as it would allow ARM to reuse it without rewrite by providing its own
send_eventcallback to trigger events usiong GPIO instead of GPE as fixed hadrware ACPI model doen't have GPE at all.Signed-off-by Igor Mammedov <[email protected]>---
v2:
- makeACPI_SEND_EVENTmacro a function Marcel Apfelbaum <[email protected]>--- hw/acpi/cpu_hotplug.c | 5 ++--- hw/acpi/ich9.c | 33 ++++++++++++++++++++------------- hw/acpi/memory_hotplug.c | 12 ++++-------- hw/acpi/pcihp.c | 10 ++++------ hw/acpi/piix4.c | 11 +++++------ hw/isa/lpc_ich9.c | 30 +++--------------------------- include/hw/acpi/cpu_hotplug.h | 3 ++- include/hw/acpi/ich9.h | 9 +++++---- include/hw/acpi/memory_hotplug.h | 4 ++-- include/hw/acpi/pcihp.h | 5 +++-- 10 files changed, 50 insertions(+), 72 deletions(-)hw/acpi/cpu_hotplug.c +0
-1@@ -62,15 +62,14 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); } -void legacy_acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
hw/acpi/cpu_hotplug.c static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, · line 72
Quoted 10 lines
hw/acpi/cpu_hotplug.c +2
-2+void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {return ; } - -acpi_send_gpe_event (ar, irq,ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS );
The patch looks good to me. I have only one question.
Why do you cast hotplug_dev to DEVICE and not a the safer expected interface? Or even HotplugHandler
Thanks,
Marcel
Quoted 307 lines
hw/acpi/cpu_hotplug.c +0
-0} void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,hw/acpi/ich9.c +20
-13@@ -430,40 +430,47 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) NULL); } -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp) +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug, +acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, - &pm->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp) +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&pm->acpi_regs, pm->irq, - &pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_request_cb (hotplug_dev, + &lpc->pm.acpi_memory_hotplug, dev, + errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_cb (&pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));hw/acpi/memory_hotplug.c +4
-8@@ -228,7 +228,7 @@ acpi_memory_slot_status(MemHotplugState *mem_st,return &mem_st->devs[slot]; } -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {MemStatus *mdev;@@ -247,13 +247,11 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; - -/* do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } } -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {@@ -265,9 +263,7 @@ void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq, } mdev->is_removing = true; - -/* Do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,hw/acpi/pcihp.c +4
-6@@ -182,7 +182,7 @@ void acpi_pcihp_reset(AcpiPciHpState *s)acpi_pcihp_update (s); } -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);@@ -202,11 +202,10 @@ void acpi_pcihp_device_plug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); } -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);@@ -219,8 +218,7 @@ void acpi_pcihp_device_unplug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)hw/acpi/piix4.c +5
-6@@ -348,12 +348,11 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, dev, errp); +acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_plug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, - errp); +acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -367,10 +366,10 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, +acpi_memory_unplug_request_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_unplug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, +acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else { error_setg(errp, "acpi: device unplug request for not supported device"hw/isa/lpc_ich9.c +3
-27@@ -637,30 +637,6 @@ static void ich9_lpc_realize(PCIDevice *d, Error **errp) 1); } -static void ich9_device_plug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_plug_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_request_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_request_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_cb (&lpc->pm, dev, errp); -} -static bool ich9_rst_cnt_needed (void *opaque) {ICH9LPCState *lpc = opaque;@@ -733,9 +709,9 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)* pc_q35_init() */ dc->cannot_instantiate_with_device_add_yet = true; - hc->plug = ich9_device_plug_cb; - hc->unplug_request = ich9_device_unplug_request_cb; - hc->unplug = ich9_device_unplug_cb; + hc->plug = ich9_pm_device_plug_cb; + hc->unplug_request = ich9_pm_device_unplug_request_cb; + hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; }include/hw/acpi/cpu_hotplug.h +2
-1@@ -15,13 +15,14 @@#include "hw/acpi/acpi.h" #include "hw/acpi/pc-hotplug.h" #include "hw/acpi/aml-build.h" +#include "hw/hotplug.h" typedef struct AcpiCpuHotplug {MemoryRegion io;uint8_t sts[ACPI_GPE_PROC_LEN ]; }AcpiCpuHotplug ; -void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp); void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,include/hw/acpi/ich9.h +5
-4@@ -69,10 +69,11 @@ extern const VMStateDescription vmstate_ich9_pm;void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm,Error **errp); -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp); -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp); -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp); +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp); +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp);void ich9_pm_ospm_status (AcpiDeviceIf *adev,ACPIOSTInfoList ***list);include/hw/acpi/memory_hotplug.h +2
-2@@ -32,9 +32,9 @@ typedef struct MemHotplugState {void acpi_memory_hotplug_init (MemoryRegion *as,Object *owner,MemHotplugState *state); -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); void acpi_memory_unplug_cb(MemHotplugState *mem_st,include/hw/acpi/pcihp.h +3
-2@@ -29,6 +29,7 @@#include "hw/acpi/acpi.h" #include "migration/vmstate.h" +#include "hw/hotplug.h" #define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"#define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"@@ -56,9 +57,9 @@ typedef struct AcpiPciHpState {void acpi_pcihp_init (Object *owner,AcpiPciHpState *,PCIBus *root,MemoryRegion *address_space_io,bool bridges_enabled); -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp); -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp);/* Called on reset */
Re: [Qemu-devel] [PATCH v2 13/33] acpi: extend ACPI interface to provide send_event hook
In reply to Marcel ApfelbaumQuoted 32 lines · On Thu, 2 Jun 2016 14:09:12 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
send_event()hook will allow to send ACPI event in a target specific way (GPE or GPIO based impl.) it will also simplify proxy wrappers in piix4pm/ich9 that access ACPI regs and SCI which are part of piix4pm/lcp_ich9 devices and callacpi_foo()API directly.Signed-off-by Igor Mammedov <[email protected]>---
Following patch will use hook to simplify hotplug callbacks in piix4pm/ich9.v2:
- makeACPI_SEND_EVENTmacro a function Marcel Apfelbaum <[email protected]>--- hw/acpi/acpi_interface.c | 9 +++++++++ hw/acpi/core.c | 2 +- hw/acpi/piix4.c | 8 ++++++++ hw/isa/lpc_ich9.c | 8 ++++++++ include/hw/acpi/acpi.h | 10 ++-------- include/hw/acpi/acpi_dev_interface.h | 11 +++++++++++ 6 files changed, 39 insertions(+), 9 deletions(-)hw/acpi/acpi_interface.c +0
-0@@ -2,6 +2,15 @@#include "hw/acpi/acpi_dev_interface.h" #include "qemu/module.h"
Quoted 6 lines
hw/acpi/acpi_interface.c line 7
Quoted 3 lines
hw/acpi/acpi_interface.c +3
-0+void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) +{ +AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (dev);Is the above conversion safe? Sorry for not mention it earlier.
It should assert if dev doesn't implement interface,
and that's fine as acpi_send_event() is supposed to be only used by device that handles ACPI hardware side and implements that interface.
Quoted 155 lines
Thanks,
MarcelQuoted 150 lines
hw/acpi/acpi_interface.c +6
-0+if (adevc->send_event) { +AcpiDeviceIf *adev =ACPI_DEVICE_IF (dev); + adevc->send_event (adev, event); + } +} +static void register_types (void ) {static const TypeInfo acpi_dev_if_info = {hw/acpi/core.c +1
-1@@ -698,7 +698,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) }void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status) +AcpiEventStatusBits status) { ar->gpe.sts[0 ] |= status;acpi_update_sci (ar, irq);hw/acpi/piix4.c +8
-0@@ -586,6 +586,13 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); } +static void piix4_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +PIIX4PMState *s =PIIX4_PM (adev); + +acpi_send_gpe_event (&s->ar, s->irq, ev); +} +static Property piix4_pm_properties[] = {DEFINE_PROP_UINT32 ("smb_io_base" , PIIX4PMState, smb_io_base,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),@@ -624,6 +631,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug_request = piix4_device_unplug_request_cb; hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; + adevc->send_event = piix4_send_gpe; }static const TypeInfo piix4_pm_info = {hw/isa/lpc_ich9.c +8
-0@@ -703,6 +703,13 @@ static Property ich9_lpc_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void ich9_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (adev); + +acpi_send_gpe_event (&s->pm.acpi_regs, s->pm.irq, ev); +} +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -730,6 +737,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug_request = ich9_device_unplug_request_cb; hc->unplug = ich9_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; + adevc->send_event = ich9_send_gpe; }static const TypeInfo ich9_lpc_info = {include/hw/acpi/acpi.h +2
-8@@ -23,6 +23,7 @@#include "qemu/option.h" #include "exec/memory.h" #include "hw/irq.h" +#include "hw/acpi/acpi_dev_interface.h" /* * current device naming scheme supports up to 256 memory devices @@ -89,13 +90,6 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 -/* These values are part of guest ABI, and can not be changed */ -typedef enum { -ACPI_PCI_HOTPLUG_STATUS =2 , -ACPI_CPU_HOTPLUG_STATUS =4 , -ACPI_MEMORY_HOTPLUG_STATUS =8 , -}AcpiGPEStatusBits ; -/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;@@ -172,7 +166,7 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr);void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status); +AcpiEventStatusBits status);void acpi_update_sci (ACPIREGS *acpi_regs,qemu_irq irq);include/hw/acpi/acpi_dev_interface.h +11
-0@@ -4,6 +4,13 @@#include "qom/object.h" #include "qapi-types.h" +/* These values are part of guest ABI, and can not be changed */ +typedef enum { +ACPI_PCI_HOTPLUG_STATUS =2 , +ACPI_CPU_HOTPLUG_STATUS =4 , +ACPI_MEMORY_HOTPLUG_STATUS =8 , +}AcpiEventStatusBits ; +#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"#define ACPI_DEVICE_IF_CLASS (klass) \@@ -22,11 +29,14 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf; +void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event); +/** * AcpiDeviceIfClass: * * ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. +* send_event: inject a specified event into guest * * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without @@ -39,5 +49,6 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); } AcpiDeviceIfClass;#endif
Marcel Apfelbaum
Reviewed-byRe: [Qemu-devel] [PATCH v2 13/33] acpi: extend ACPI interface to provide send_event hook
Quoted 41 lines · Igor Mammedov
Quoted 32 lines · On Thu, 2 Jun 2016 14:09:12 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
send_event()hook will allow to send ACPI event in a target specific way (GPE or GPIO based impl.) it will also simplify proxy wrappers in piix4pm/ich9 that access ACPI regs and SCI which are part of piix4pm/lcp_ich9 devices and callacpi_foo()API directly.Signed-off-by Igor Mammedov <[email protected]>---
Following patch will use hook to simplify hotplug callbacks in piix4pm/ich9.v2:
- makeACPI_SEND_EVENTmacro a function Marcel Apfelbaum <[email protected]>--- hw/acpi/acpi_interface.c | 9 +++++++++ hw/acpi/core.c | 2 +- hw/acpi/piix4.c | 8 ++++++++ hw/isa/lpc_ich9.c | 8 ++++++++ include/hw/acpi/acpi.h | 10 ++-------- include/hw/acpi/acpi_dev_interface.h | 11 +++++++++++ 6 files changed, 39 insertions(+), 9 deletions(-)hw/acpi/acpi_interface.c +0
-0@@ -2,6 +2,15 @@#include "hw/acpi/acpi_dev_interface.h" #include "qemu/module.h" Quoted 6 lines
hw/acpi/acpi_interface.c line 7
Quoted 3 lines
hw/acpi/acpi_interface.c +3
-0+void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) +{ +AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (dev);Is the above conversion safe? Sorry for not mention it earlier.
Quoted 4 lines
It should assert if dev doesn't implement interface,
and that's fine asacpi_send_event()is supposed to be only used by device that handles ACPI hardware side and implements that interface.
OK
Thanks,
Marcel
Quoted 156 lines
Quoted 155 lines
Thanks,
MarcelQuoted 150 lines
hw/acpi/acpi_interface.c +6
-0+if (adevc->send_event) { +AcpiDeviceIf *adev =ACPI_DEVICE_IF (dev); + adevc->send_event (adev, event); + } +} +static void register_types (void ) {static const TypeInfo acpi_dev_if_info = {hw/acpi/core.c +1
-1@@ -698,7 +698,7 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr) }void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status) +AcpiEventStatusBits status) { ar->gpe.sts[0 ] |= status;acpi_update_sci (ar, irq);hw/acpi/piix4.c +8
-0@@ -586,6 +586,13 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)acpi_memory_ospm_status (&s->acpi_memory_hotplug, list); } +static void piix4_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +PIIX4PMState *s =PIIX4_PM (adev); + +acpi_send_gpe_event (&s->ar, s->irq, ev); +} +static Property piix4_pm_properties[] = {DEFINE_PROP_UINT32 ("smb_io_base" , PIIX4PMState, smb_io_base,0 ),DEFINE_PROP_UINT8 (ACPI_PM_PROP_S3_DISABLED , PIIX4PMState, disable_s3,0 ),@@ -624,6 +631,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) hc->unplug_request = piix4_device_unplug_request_cb; hc->unplug = piix4_device_unplug_cb; adevc->ospm_status = piix4_ospm_status; + adevc->send_event = piix4_send_gpe; }static const TypeInfo piix4_pm_info = {hw/isa/lpc_ich9.c +8
-0@@ -703,6 +703,13 @@ static Property ich9_lpc_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void ich9_send_gpe (AcpiDeviceIf *adev,AcpiEventStatusBits ev) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (adev); + +acpi_send_gpe_event (&s->pm.acpi_regs, s->pm.irq, ev); +} +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -730,6 +737,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) hc->unplug_request = ich9_device_unplug_request_cb; hc->unplug = ich9_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; + adevc->send_event = ich9_send_gpe; }static const TypeInfo ich9_lpc_info = {include/hw/acpi/acpi.h +2
-8@@ -23,6 +23,7 @@#include "qemu/option.h" #include "exec/memory.h" #include "hw/irq.h" +#include "hw/acpi/acpi_dev_interface.h" /* * current device naming scheme supports up to 256 memory devices @@ -89,13 +90,6 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 -/* These values are part of guest ABI, and can not be changed */ -typedef enum { -ACPI_PCI_HOTPLUG_STATUS =2 , -ACPI_CPU_HOTPLUG_STATUS =4 , -ACPI_MEMORY_HOTPLUG_STATUS =8 , -}AcpiGPEStatusBits ; -/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;@@ -172,7 +166,7 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr);void acpi_send_gpe_event (ACPIREGS *ar,qemu_irq irq, -AcpiGPEStatusBits status); +AcpiEventStatusBits status);void acpi_update_sci (ACPIREGS *acpi_regs,qemu_irq irq);include/hw/acpi/acpi_dev_interface.h +11
-0@@ -4,6 +4,13 @@#include "qom/object.h" #include "qapi-types.h" +/* These values are part of guest ABI, and can not be changed */ +typedef enum { +ACPI_PCI_HOTPLUG_STATUS =2 , +ACPI_CPU_HOTPLUG_STATUS =4 , +ACPI_MEMORY_HOTPLUG_STATUS =8 , +}AcpiEventStatusBits ; +#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"#define ACPI_DEVICE_IF_CLASS (klass) \@@ -22,11 +29,14 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf; +void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event); +/** * AcpiDeviceIfClass: * * ospm_status: returns status of ACPI device objects, reported * via _OST method if device supports it. +* send_event: inject a specified event into guest * * Interface is designed for providing unified interface * to generic ACPI functionality that could be used without @@ -39,5 +49,6 @@ typedef struct AcpiDeviceIfClass {/* <public> */ void (*ospm_status)(AcpiDeviceIf *adev,ACPIOSTInfoList ***list); + void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev); } AcpiDeviceIfClass;#endif
Re: [Qemu-devel] [PATCH v2 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events
In reply to Marcel ApfelbaumQuoted 35 lines · On Thu, 2 Jun 2016 14:13:23 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 34 lines · Igor Mammedov
it reduces number of args passed in handlers by 1 and a number of used proxy wrappers saving ~20LOC. Also it allows to make cpu/mem hotplug code more universal as it would allow ARM to reuse it without rewrite by providing its own
send_eventcallback to trigger events usiong GPIO instead of GPE as fixed hadrware ACPI model doen't have GPE at all.Signed-off-by Igor Mammedov <[email protected]>---
v2:
- makeACPI_SEND_EVENTmacro a function Marcel Apfelbaum <[email protected]>--- hw/acpi/cpu_hotplug.c | 5 ++--- hw/acpi/ich9.c | 33 ++++++++++++++++++++------------- hw/acpi/memory_hotplug.c | 12 ++++-------- hw/acpi/pcihp.c | 10 ++++------ hw/acpi/piix4.c | 11 +++++------ hw/isa/lpc_ich9.c | 30 +++--------------------------- include/hw/acpi/cpu_hotplug.h | 3 ++- include/hw/acpi/ich9.h | 9 +++++---- include/hw/acpi/memory_hotplug.h | 4 ++-- include/hw/acpi/pcihp.h | 5 +++-- 10 files changed, 50 insertions(+), 72 deletions(-)hw/acpi/cpu_hotplug.c +0
-0@@ -62,15 +62,14 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); }
Quoted 15 lines
hw/acpi/cpu_hotplug.c static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, · line 72
Quoted 11 lines
hw/acpi/cpu_hotplug.c +2
-3-void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {return ; } - -acpi_send_gpe_event (ar, irq,ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS );The patch looks good to me. I have only one question.
Why do you casthotplug_devto DEVICE and not a the safer expected interface? Or even HotplugHandler
it's not HotplugHandler because acpi events in general is not hotplug related.
I wouldn't say that casting to interface any more safer than casting to DEVICE, I'm using DeviceState here because it will save some call sites a trouble of casting to interface.
Quoted 312 lines
Thanks,
MarcelQuoted 307 lines
hw/acpi/cpu_hotplug.c +0
-0} void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,hw/acpi/ich9.c +20
-13@@ -430,40 +430,47 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) NULL); } -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp) +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug, +acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&pm->acpi_regs, pm->irq, - &pm->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp) +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&pm->acpi_regs, pm->irq, - &pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_request_cb (hotplug_dev, + &lpc->pm.acpi_memory_hotplug, dev, + errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev))); } } -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -if (pm->acpi_memory_hotplug.is_enabled && +ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); + +if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_cb (&pm->acpi_memory_hotplug, dev, errp); +acpi_memory_unplug_cb (&lpc->pm.acpi_memory_hotplug, dev, errp); }else {error_setg (errp,"acpi: device unplug for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));hw/acpi/memory_hotplug.c +4
-8@@ -228,7 +228,7 @@ acpi_memory_slot_status(MemHotplugState *mem_st,return &mem_st->devs[slot]; } -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {MemStatus *mdev;@@ -247,13 +247,11 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; - -/* do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } } -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {@@ -265,9 +263,7 @@ void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq, } mdev->is_removing = true; - -/* Do ACPI magic */ -acpi_send_gpe_event (ar, irq,ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,hw/acpi/pcihp.c +4
-6@@ -182,7 +182,7 @@ void acpi_pcihp_reset(AcpiPciHpState *s)acpi_pcihp_update (s); } -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);@@ -202,11 +202,10 @@ void acpi_pcihp_device_plug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); } -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);@@ -219,8 +218,7 @@ void acpi_pcihp_device_unplug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); - -acpi_send_gpe_event (ar, irq,ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)hw/acpi/piix4.c +5
-6@@ -348,12 +348,11 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_plug_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, dev, errp); +acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_plug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, - errp); +acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { -legacy_acpi_cpu_plug_cb (&s->ar, s->irq, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); }else {error_setg (errp,"acpi: device plug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -367,10 +366,10 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (&s->ar, s->irq, &s->acpi_memory_hotplug, +acpi_memory_unplug_request_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_unplug_cb (&s->ar, s->irq, &s->acpi_pci_hotplug, dev, +acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else { error_setg(errp, "acpi: device unplug request for not supported device"hw/isa/lpc_ich9.c +3
-27@@ -637,30 +637,6 @@ static void ich9_lpc_realize(PCIDevice *d, Error **errp) 1); } -static void ich9_device_plug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_plug_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_request_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_request_cb (&lpc->pm, dev, errp); -} - -static void ich9_device_unplug_cb (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) -{ -ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); - -ich9_pm_device_unplug_cb (&lpc->pm, dev, errp); -} -static bool ich9_rst_cnt_needed (void *opaque) {ICH9LPCState *lpc = opaque;@@ -733,9 +709,9 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)* pc_q35_init() */ dc->cannot_instantiate_with_device_add_yet = true; - hc->plug = ich9_device_plug_cb; - hc->unplug_request = ich9_device_unplug_request_cb; - hc->unplug = ich9_device_unplug_cb; + hc->plug = ich9_pm_device_plug_cb; + hc->unplug_request = ich9_pm_device_unplug_request_cb; + hc->unplug = ich9_pm_device_unplug_cb; adevc->ospm_status = ich9_pm_ospm_status; adevc->send_event = ich9_send_gpe; }include/hw/acpi/cpu_hotplug.h +2
-1@@ -15,13 +15,14 @@#include "hw/acpi/acpi.h" #include "hw/acpi/pc-hotplug.h" #include "hw/acpi/aml-build.h" +#include "hw/hotplug.h" typedef struct AcpiCpuHotplug {MemoryRegion io;uint8_t sts[ACPI_GPE_PROC_LEN ]; }AcpiCpuHotplug ; -void legacy_acpi_cpu_plug_cb (ACPIREGS *ar,qemu_irq irq, +void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp); void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,include/hw/acpi/ich9.h +5
-4@@ -69,10 +69,11 @@ extern const VMStateDescription vmstate_ich9_pm;void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm,Error **errp); -void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp); -void ich9_pm_device_unplug_request_cb (ICH9LPCPMRegs *pm,DeviceState *dev, -Error **errp); -void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev, +void ich9_pm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp); +void ich9_pm_device_unplug_request_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp); +void ich9_pm_device_unplug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp);void ich9_pm_ospm_status (AcpiDeviceIf *adev,ACPIOSTInfoList ***list);include/hw/acpi/memory_hotplug.h +2
-2@@ -32,9 +32,9 @@ typedef struct MemHotplugState {void acpi_memory_hotplug_init (MemoryRegion *as,Object *owner,MemHotplugState *state); -void acpi_memory_plug_cb (ACPIREGS *ar,qemu_irq irq,MemHotplugState *mem_st, +void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); -void acpi_memory_unplug_request_cb (ACPIREGS *ar,qemu_irq irq, +void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); void acpi_memory_unplug_cb(MemHotplugState *mem_st,include/hw/acpi/pcihp.h +3
-2@@ -29,6 +29,7 @@#include "hw/acpi/acpi.h" #include "migration/vmstate.h" +#include "hw/hotplug.h" #define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"#define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"@@ -56,9 +57,9 @@ typedef struct AcpiPciHpState {void acpi_pcihp_init (Object *owner,AcpiPciHpState *,PCIBus *root,MemoryRegion *address_space_io,bool bridges_enabled); -void acpi_pcihp_device_plug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp); -void acpi_pcihp_device_unplug_cb (ACPIREGS *ar,qemu_irq irq,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp);/* Called on reset */
Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
In reply to Michael S. TsirkinQuoted 83 lines · On Wed, 1 Jun 2016 00:09:57 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 82 lines · Igor Mammedov
Quoted 47 lines · On Tue, 31 May 2016 07:49:16 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 31 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 12 deletions(-)docs/specs/acpi_cpu_hotplug.txt +6
-7@@ -4,21 +4,85 @@ QEMU<->ACPI BIOS CPU hotplug interface QEMU supports CPU hotplug via ACPI. This document describes the interface between QEMU and the ACPI BIOS. -ACPI GPE block (IO ports 0xafe0-0xafe3, byte access): ------------------------------------------ - -Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU -hot-add/remove event to ACPI BIOS, via SCI interrupt. +ACPI BIOS GPE.2 handler is dedicated for notifying OS about CPU hot-add +and hot-remove events. +============================================ +Legacy ACPI CPU hotplug interface registers: +-------------------------------------------- CPU present bitmap for: + One bit per CPU. Bit position reflects corresponding CPU APIC ID. Read-only. ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access) PIIX-PM (IO port 0xaf00-0xaf1f, 1-byte access) --------------------------------------------------------------- -One bit per CPU. Bit position reflects corresponding CPU APIC ID. -Read-only.docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 27
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +10
-0+QEMU sets corresponding CPU bit on hot-add event and issues SCI +with GPE.2 event set. CPU present map read by ACPI BIOS GPE.2 handler +to notify OS about CPU hot-add events. CPU hot-remove isn't supported. + +===================================== +ACPI CPU hotplug interface registers: +------------------------------------- +Register block base address: + ICH9-LPC IO port 0x0cd8 + PIIX-PM IO port 0xaf00OK but this means we either use legacy or new one, bot both, which is problematic for people using old seabios without acpi loading support and with -M pc.
Quoted 3 lines
I don't say we must support them with >255 CPUs,
but I do say we should make an effort for simple
setups with <255 CPUs.it works with QEMU provided(shipped) BIOS,
it works for migration case as legacy stays enables because of -Msrc_legacy_machinemore that 255 cpus will break old BIOS in different ways /corrupt/hang/ depending on BIOS version.
I'm not sure we should care about using old BIOS with new QEMU+new machine type though and allow expectations to be beyond what hw vendors usually set. It's the same as real hw does i.e. new hardware shipped with new BIOS.
If user insist on old BIOS+new machine type he still has property knob to force legacy mode.on the fist glance, it's probably not that very hard to switch IO ports handling from legacy to new interface by sending from new cpu-hotplug AML a command to do so, my concerns here is:
* +1 more state to migrate
* probably issues with migration as target started with different IO layout
* IO window freed after switching from legacy to new, will not be available to guest as it started with legacy window consumed by CPUS.CRS.
* that legacy switching business is only PC specific means having a knob to turn it on so it won't pollute ARM
Quoted 6 lines
Quoted 3 lines
all in all it's probably too much headache to make sure that improbable usecase would work, so after considering this idea I've dropped it and did it the way it's now.
Well I think it's worth the effort. I agree it's tricky to implement but we do maintain compatibility for years.
That's what I'm concerned about, with your suggestion QEMU maintenance efforts will increase and we will be stuck with ABI switching forever for giving ability to run (unlikely) by default pre acpi-linker BIOS on new machine types.
While my current approach makes a clean ABI switch for new machine types with old machines supporting legacy ABI.
I can try to rework series but even with reviews and testing on list there is a non zero chance of migration related regressions.
Do you insist on implementing switching from legacy ABI to a new one in runtime?
Quoted 2 lines
Being orthogonal with bios version is very helpful for a variety of reasons such as debugging.
debugging and other unconventional uses can force legacy hotplug with a property while leaving default new machine type with a clean straightforward implementation.
Quoted 17 lines
Quoted 17 lines
Quoted 9 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 31
Quoted 4 lines
docs/specs/acpi_cpu_hotplug.txt +4
-0+Register block size: + ACPI_CPU_HOTPLUG_REG_LEN = 12 + +read access:So this implies acpi must scan all cpus on each event, and this seems too aggressive.
I think we need something hierarchical where
you read one level and know which cpus to probe.That's what we do for mem-hotplug as it's not
performance critical path.In addition to that depending on guest OS/version it will anyway do enumeration of all CPUs after our hotplug AML method scanned all CPUs and
sent notifies.
Quoted 6 lines
Quoted 4 lines
not that I'm in favor of complicating this protocol, but I wouldn't do it hierarchical,
that's whatNotify(BUS_CHECK)is supposed to do but it's broken on some guests.Interesting. Which ones? Would they be easy to detect?
I've experimented with it/retested some more.
It was RHEL6, I don't think we can detect it.
Anyway BUS_CHECK would only simplify code by eleminating need for CPU_SCAN_METHOD and doing check from SAT method. We would still need to keep big custom notifier method to make hot remove work (I've spent some time again trying to make it work without if/else case switch but no success so far).
Using polling to get CPUs with hotplug events won't save us much (~1K of 32bit reads per 512 CPUs). STA checks that OSPM does will still do full scan.
So do you insist on redoing current full scan on hotplug approach using polling?
Quoted 41 lines
Quoted 41 lines
So if I'd do a more complicated protocol,
I'd do polling from AML side telling QEMU
if (cpu =give_me_next_cpu_with_event())switch_to_cpu(cpu) ...that means adding extra state to migrate, probably ther might be other issues I'm not aware of yet.
On the other hand mem-hotplug like interface so far hasn't caused any issues
(that of cause doesn't mean that there aren't any).Quoted 17 lines
Quoted 17 lines
docs/specs/acpi_cpu_hotplug.txt +17
-0+ offset: + [0x0-0x3] reserved + [0x4] CPU device status fields: (1 byte access) + bits: + 0: Device is enabled and may be used by guest + 1: Device insert event, used to distinguish device for which + no device check event to OSPM was issued. + It's valid only when bit 0 is set. + 2: Device remove event, used to distinguish device for which + no device eject request to OSPM was issued. + 3-7: reserved and should be ignored by OSPM + [0x5-0x7] reserved + [0x8] Command data: (DWORD access) + in case of error or unsupported command reads is 0xFFFFFFFF + current 'Command field' value: + 0: returns PXM value corresponding to device +Quoted 8 lines
docs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 53
Quoted 5 lines
docs/specs/acpi_cpu_hotplug.txt +5
-0+write access: + offset: + [0x0-0x3] CPU selector: (DWORD access) + selects active CPU device. All following accesses to other + registers will read/store data from/to selected CPU.I've been thinking - is it time to add an EmbeddedControl interface? This way we have another namespace.
There were patches on list with it some time ago
Quoted 8 lines
Quoted 5 lines
"[PATCH RFC v2 0/7] coordinate cpu hotplug/unplug bewteen QEMU and kernel by EC"
but we dropped it as bloatware because there weren't any real need for it as current IO port interfaces aren't going away any time soon and work just fine without EC.
Right. But now you are removing them for >255 CPUs anyway.
it still occupies the same IO region that we allocated for legacy hotplug, I'm just shrinking it.
On top of that EC protocol will channel all accesses via 1-byte channel making access even slower.
So as far as we are able to allocate some IO ports without pain, I wouldn't use EC.
Quoted 6 lines
Quoted 4 lines
And if we were to move current interfaces into EC namespace we would have to do it only for new machines types and keep old code in place as well and a bunch of compat code for a company.
Hmm. Exactly like this current one?
memhotplug/ACPI PCI hotplug/cpuhotplug (legacy/new)
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Not insisting on it, just an idea.
I wouldn't make it a necessary dependency and block this series. Might be worth to look at again when there is usecases for it without legacy stuff attached.
and then we'll have to maintain 3 interfaces?
nope, I'd leave current/implemented usecases where they are, only new stuff would go through EC.
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 32 lines
docs/specs/acpi_cpu_hotplug.txt +29
-0+ [0x4] CPU device control fields: (1 byte access) + bits: + 0: reserved, OSPM must clear it before writing to register. + 1: if set to 1 clears device insert event, set by OSPM + after it has emitted device check event for the + selected CPU device + 2: if set to 1 clears device remove event, set by OSPM + after it has emitted device eject request for the + selected CPU device + 3: if set to 1 initiates device eject, set by OSPM when it + triggers CPU device removal and calls _EJ0 method + 4-7: reserved, OSPM must clear them before writing to register + [0x5] Command field: (1 byte access) + value: + 0: following reads from 'Command data' register returns PXM + value of device + 1: following writes to 'Command data' register set OST event + register in QEMU + 2: following writes to 'Command data' register set OST status + register in QEMU + other values: reserved + [0x6-0x7] reserved + [0x8] Command data: (DWORD access) + current 'Command field' value: + 1: stores value into OST event register + 2: stores value into OST status register, triggers + ACPI_DEVICE_OST QMP event from QEMU to external applications + with current values of OST event and status registers. + other values: reserveddocs/specs/acpi_cpu_hotplug.txt QEMU<->ACPI BIOS CPU hotplug interface · line 88
Quoted 10 lines
docs/specs/acpi_cpu_hotplug.txt +5
-5-CPU hot-add/remove notification: ------------------------------------------------------ -QEMU sets/clears corresponding CPU bit on hot-add/remove event. -CPU present map read by ACPI BIOS GPE.2 handler to notify OS of CPU -hot-(un)plug events. +Selecting CPU device beyond possible range has no effect on platform: + - write accesses to CPU hot-plug registers not documented above are + ignored + - read accesses to CPU hot-plug registers not documented above return + all bits set to 1.why not 0?
Quoted 4 lines
Quoted 2 lines
isn't hardware usually return 1s on unhandled IO reads? (I even thought that's it was you who told me it)
PCI does but it's special.
Ok, it doesn't matter whether it's 1s or 0s as far as it's something defined. I've used 1s as in memhotplug.
Quoted 8 lines
Quoted 8 lines
that's what has been done for memory hotplug, so I'm doing the same here.
Quoted 4 lines
Quoted 3 lines
Signature · 2 lines
-- 1.8.3.1