All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods
@ 2016-05-17 14:42 Igor Mammedov
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode Igor Mammedov
                   ` (32 more replies)
  0 siblings, 33 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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:
    git@github.com: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

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
@ 2016-05-17 14:42 ` Igor Mammedov
  2016-05-24 16:58   ` Marcel Apfelbaum
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 02/33] acpi: add aml_debug() Igor Mammedov
                   ` (31 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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 set

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 tests/bios-tables-test.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index 0352814..9acf9ba 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -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);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 02/33] acpi: add aml_debug()
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode Igor Mammedov
@ 2016-05-17 14:42 ` Igor Mammedov
  2016-05-24 16:59   ` Marcel Apfelbaum
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 03/33] acpi: add aml_refof() Igor Mammedov
                   ` (30 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/aml-build.c         | 9 +++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cedb74e..f7d99be 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -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
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 7eb51c7..70a4b14 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -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);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 03/33] acpi: add aml_refof()
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode Igor Mammedov
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 02/33] acpi: add aml_debug() Igor Mammedov
@ 2016-05-17 14:42 ` Igor Mammedov
  2016-05-24 17:00   ` Marcel Apfelbaum
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers Igor Mammedov
                   ` (29 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/aml-build.c         | 8 ++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index f7d99be..95f6021 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -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)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 70a4b14..dd432d2 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -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);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (2 preceding siblings ...)
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 03/33] acpi: add aml_refof() Igor Mammedov
@ 2016-05-17 14:42 ` Igor Mammedov
  2016-05-25  9:11   ` Marcel Apfelbaum
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML Igor Mammedov
                   ` (28 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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 <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 279f0d7..ff98ad8 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (3 preceding siblings ...)
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers Igor Mammedov
@ 2016-05-17 14:42 ` Igor Mammedov
  2016-05-30 18:18   ` Marcel Apfelbaum
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 06/33] pc: acpi: consolidate \GPE._E02 with the rest of " Igor Mammedov
                   ` (27 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

move the former SSDT part of CPU hoplug close to DSDT part.
AML is only moved but there isn't any functional change.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
index 97bb109..730f44c 100644
--- a/hw/acpi/cpu_hotplug_acpi_table.c
+++ b/hw/acpi/cpu_hotplug_acpi_table.c
@@ -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);
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index ff98ad8..822230f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
 
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index f22640e..9b1d0cf 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 06/33] pc: acpi: consolidate \GPE._E02 with the rest of CPU hotplug AML
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (4 preceding siblings ...)
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML Igor Mammedov
@ 2016-05-17 14:42 ` Igor Mammedov
  2016-05-30 18:22   ` Marcel Apfelbaum
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 07/33] pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c Igor Mammedov
                   ` (26 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/cpu_hotplug_acpi_table.c | 4 ++++
 hw/i386/acpi-build.c             | 4 ----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
index 730f44c..c31f346 100644
--- a/hw/acpi/cpu_hotplug_acpi_table.c
+++ b/hw/acpi/cpu_hotplug_acpi_table.c
@@ -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);
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 822230f..63e2723 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 07/33] pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (5 preceding siblings ...)
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 06/33] pc: acpi: consolidate \GPE._E02 with the rest of " Igor Mammedov
@ 2016-05-17 14:42 ` Igor Mammedov
  2016-05-30 18:23   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 08/33] pc: acpi: mark current CPU hotplug functions as legacy Igor Mammedov
                   ` (25 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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 <imammedo@redhat.com>
---
 hw/acpi/cpu_hotplug_acpi_table.c | 7 +++++++
 include/hw/acpi/cpu_hotplug.h    | 7 -------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
index c31f346..9fdde6d 100644
--- a/hw/acpi/cpu_hotplug_acpi_table.c
+++ b/hw/acpi/cpu_hotplug_acpi_table.c
@@ -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)
 {
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 9b1d0cf..565f96c 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 08/33] pc: acpi: mark current CPU hotplug functions as legacy
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (6 preceding siblings ...)
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 07/33] pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:28   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 09/33] pc: acpi: consolidate legacy CPU hotplug in one file Igor Mammedov
                   ` (24 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 4d86743..ba9d903 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -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;
 
diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
index 9fdde6d..fc79c54 100644
--- a/hw/acpi/cpu_hotplug_acpi_table.c
+++ b/hw/acpi/cpu_hotplug_acpi_table.c
@@ -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;
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 27e978f..af340d0 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -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)));
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 16abdf1..3e8d80b 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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);
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 63e2723..2f6de43 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
 
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 565f96c..241b50f 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 09/33] pc: acpi: consolidate legacy CPU hotplug in one file
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (7 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 08/33] pc: acpi: mark current CPU hotplug functions as legacy Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:31   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 10/33] pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature Igor Mammedov
                   ` (23 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Since 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

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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

diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index faee86c..66bd727 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -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
diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index ba9d903..2d4e034 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -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);
+}
diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
deleted file mode 100644
index fc79c54..0000000
--- a/hw/acpi/cpu_hotplug_acpi_table.c
+++ /dev/null
@@ -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;
-    }
-    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);
-}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 10/33] pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (8 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 09/33] pc: acpi: consolidate legacy CPU hotplug in one file Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:31   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx Igor Mammedov
                   ` (22 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

since 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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 2d4e034..36ea6c2 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -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);
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 2f6de43..b33fec9 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
 
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 241b50f..6d729d8 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (9 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 10/33] pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:39   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 12/33] tests: acpi: update tables with consolidated legacy cpu-hotplug AML Igor Mammedov
                   ` (21 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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 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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/cpu_hotplug.c | 23 +++++++++++++----------
 hw/i386/acpi-build.c  |  2 +-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 36ea6c2..9d71d2f 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -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;
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b33fec9..768918f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 12/33] tests: acpi: update tables with consolidated legacy cpu-hotplug AML
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (10 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 13/33] acpi: extend ACPI interface to provide send_event hook Igor Mammedov
                   ` (20 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/tests/acpi-test-data/pc/DSDT b/tests/acpi-test-data/pc/DSDT
index 9d1274d3c2e2b7a316d5133d013b0550024ee413..8b4f1a09b87f8361fb572022f69d304ddeeace99 100644
GIT binary patch
delta 174
zcmcbt{a=gACD<jTUX+1>(Rw3SB|ERHM0~JQyojlDfUhId<O%GOjG2>Hu`iq4$(t!*
z;v8ULzyJm!yz#z{Aq-1E$`~ed@|lZ^h{fo|y9c<&yBZiV0GU8j0)m2_HwSP$U=s0U
z14(hjdw9C=Iywh<8W<RuP4?!tk(2}~H)e>@X925s_B8PI2ypQYcJ|xM%2Uh8?o}BB
LlGyCPH<=v(JBlpX

delta 221
zcmeybby=IsCD<k8vM2)sqxnXzN_Jjfp7>y=co9?Q0AEMO$rIQm88arYVqdmdp7Q|{
zlPm9JMjjDXws;={gUP}?HUa|it_DU7F?t|90YSmell^$4LPS9FCJbQ86hfInD02v9
z0ii4*lp}<4f>6#7$^}BXLMS(e%^5tkjO>oBF(8{J2XJJH8#@OW7%+f=2v5APV+g|%
Qkeer8<S^g-hIcYM0Eja(?f?J)

diff --git a/tests/acpi-test-data/pc/DSDT.bridge b/tests/acpi-test-data/pc/DSDT.bridge
index cf48c62aa71a7dd7d816fd4ef8ad626e39d4965c..0d09b5cc61114b68fee0f14729732786854b19fe 100644
GIT binary patch
delta 174
zcmbPcb;y#-CD<k8kPHI@W6MUaN_JjXiTGfrco9?Q0AEL@$rIQm88auZVqZ47lQ&bs
z#5usgfB_6dc;kH?Ll~BTlrc=^<TDo+5sT4_cMoulcQr6#05XB51Ox>;Zw}yiz$D_y
z29n~4_waP#b#xB!G%zqQo9xYPBPj_~Zp;v)&jMEO>}lZZ5#Zt*?CiIhm8X`G-S=$_
LNMf@C-!(n}U^p$&

delta 221
zcmX?PIn9d8CD<iIOqPLxv3?_0B|EP#PkgXbyojlDfUhIt<O%GOj2V+xu`k;!&-s9f
z$(469Baa9xTfC2f!DL|`8v%iMR|6x47(I}lfS_RK$$mUiAtE4o69zD43Zcv(lsSa5
zfKZkY$`L|2K`3Vk<pQBxA(R`#<_w-%Ms}B<F(8{J2XJJH8#@OW7%+f=2v5APV+g|%
Qkeer8<S^g-hW8pD0P)W<<^TWy

diff --git a/tests/acpi-test-data/q35/DSDT b/tests/acpi-test-data/q35/DSDT
index 1c089c34b06c9f2ea9fe67abb45498021319303c..67445428d935bd6ea5957526089ba7e719a1783a 100644
GIT binary patch
delta 167
zcmZ4Lc+!E(CD<jzQ-Ohjv1cP!qolg4M0~JQyojlDfUhG{L34+5fWKb`LqdTdHx~y3
z2Ll)+7GzG|B)M#|kbI_uiF1H~0Yq4YH{RDVgkcFtE5qbT^5)_qVljI0?g6gxt_DU7
zKqk=SfS_RK%@I-$m_)!b9Pu8WF1(J;0iFg124)PCb7ZA9-;y<CWOwF^0V$t+QvMDA
Dr{gPK

delta 259
zcmX@<u+)*uCD<iosR9E7qrpb5MoD#Fp7>y=co9?Q0AEMOg60nA0Dr#>hJ*q^ZY~Z6
z4hAqtEXbI=Npjg{b?FC8CQe-O?g6eG@gANoypGNRo(2X6W(*>1@jeCy5Xz82L?GVP
zz=$D64`g&eP_Xl4X*sD7uo@GH8dC@b)o2dkSwJXD2;~T&oFJ4lgmQsUt`N$NVY8{6
rAtSq&WDLlr$q`bS;>OMaK!<>V2v5APV+g|%kk=;Plro>3D}M(70tPv}

diff --git a/tests/acpi-test-data/q35/DSDT.bridge b/tests/acpi-test-data/q35/DSDT.bridge
index b29fcda0bb1717ff708668c6e98f3ded3f34a96c..e85f5b1af9fcd36c9522b05e0085af84d6c010cb 100644
GIT binary patch
delta 167
zcmdnyc*}vyCD<h-N`ZlaQD-Apqolg4M0~JQyojlDfUhG{L34+5fWKb`LqdTdHx~y3
z2Ll)+7GzG|B)M#|kbI_uiF1H~0Yq4YH{RDVgkcFtE5qbT^5)_qVljI0?g6gxt_DU7
zKqk=SfS_RK%@I-$m_)!b9Pu8WF1(J;0iFg124)PCb7ZA9-;y<CWOw0@0V$t+QvNLf
Dk25Pn

delta 259
zcmccRu+5RnCD<ion*sv^<Ase}jgsoVJn_L!@gk<q0ltom1<f7K0sej&3<(8-+*}+C
z91LKPSdcM!ljO3^>e3IGOq{sl-2+@X;ypZFcpaSsJPiyC%os%2;(ZJZAe144h(Nrn
zfe}ND9?0l`pkU|8(sEKEU^ONXHKq^>s?i+6vw%>R5XuokIYB6A2;~ByTp^Sj!)8-C
rLq>LQsThz=lOv=u#f_Z<fDQoz5uSKo#}I}kAg@inDP=x6SN<&k&T2ZM

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 13/33] acpi: extend ACPI interface to provide send_event hook
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (11 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 12/33] tests: acpi: update tables with consolidated legacy cpu-hotplug AML Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:45   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events Igor Mammedov
                   ` (19 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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 call acpi_foo() API directly.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
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(-)

diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 6a2f452..d05844b 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -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);
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 3e8d80b..4f5658f 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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 = {
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 99cd3ba..305ccd6 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -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 = {
diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
index e0978c8..24dd572 100644
--- a/include/hw/acpi/acpi.h
+++ b/include/hw/acpi/acpi.h
@@ -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);
 
diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
index f245f8d..fdfc163 100644
--- a/include/hw/acpi/acpi_dev_interface.h
+++ b/include/hw/acpi/acpi_dev_interface.h
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (12 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 13/33] acpi: extend ACPI interface to provide send_event hook Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-31 10:01   ` [Qemu-devel] [PATCH v2 " Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol Igor Mammedov
                   ` (18 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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_event callback
to trigger events usiong GPIO instead of GPE
as fixed hadrware ACPI model doen't have GPE at all.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 9d71d2f..6c0b555 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -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,
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index af340d0..853c9c4 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -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)));
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index f65a3a2..cde1abd 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -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,
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 71f4c4e..01fd488 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -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)
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 4f5658f..c66d3ed 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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"
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 305ccd6..86d4547 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -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;
 }
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 6d729d8..6fef67e 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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,
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 63fa198..bbd657c 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -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);
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 3a646b1..d2c7452 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -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,
diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
index 79a4392..04528b7 100644
--- a/include/hw/acpi/pcihp.h
+++ b/include/hw/acpi/pcihp.h
@@ -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 */
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (13 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-31  4:49   ` Michael S. Tsirkin
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug Igor Mammedov
                   ` (17 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------
 1 file changed, 76 insertions(+), 12 deletions(-)

diff --git a/docs/specs/acpi_cpu_hotplug.txt b/docs/specs/acpi_cpu_hotplug.txt
index 340b751..c5bce6a 100644
--- a/docs/specs/acpi_cpu_hotplug.txt
+++ b/docs/specs/acpi_cpu_hotplug.txt
@@ -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.
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (14 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:50   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 17/33] pc: add generic CPU unplug callbacks Igor Mammedov
                   ` (16 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
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

diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 66bd727..f200419 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -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
diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
new file mode 100644
index 0000000..171a5f5
--- /dev/null
+++ b/hw/acpi/cpu.c
@@ -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()
+    }
+};
diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
new file mode 100644
index 0000000..3fdf4eb
--- /dev/null
+++ b/include/hw/acpi/cpu.h
@@ -0,0 +1,52 @@
+/*
+ * QEMU ACPI hotplug utilities
+ *
+ * Copyright (C) 2016 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <imammedo@redhat.com>
+ *
+ * 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
diff --git a/trace-events b/trace-events
index 4fce005..7101ba9 100644
--- a/trace-events
+++ b/trace-events
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 17/33] pc: add generic CPU unplug callbacks
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (15 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine Igor Mammedov
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/cpu.c |  1 +
 hw/i386/pc.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 171a5f5..73258a1 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -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);
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 99437e0..1cad132 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1713,6 +1713,49 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 out:
     error_propagate(errp, local_err);
 }
+static void pc_cpu_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                     DeviceState *dev, Error **errp)
+{
+    HotplugHandlerClass *hhc;
+    Error *local_err = NULL;
+    PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    hhc->unplug_request(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err);
+
+    if (local_err) {
+        goto out;
+    }
+
+ out:
+    error_propagate(errp, local_err);
+
+}
+
+static void pc_cpu_unplug_cb(HotplugHandler *hotplug_dev,
+                             DeviceState *dev, Error **errp)
+{
+    HotplugHandlerClass *hhc;
+    Error *local_err = NULL;
+    PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    hhc->unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err);
+
+    if (local_err) {
+        goto out;
+    }
+
+    /*
+     * TODO: enable unplug once generic CPU remove bits land
+     * for now guest will be able to eject CPU ACPI wise but
+     * it will come back again on machine reset.
+     */
+    /*  object_unparent(OBJECT(dev)); */
+
+ out:
+    error_propagate(errp, local_err);
+}
 
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
                                       DeviceState *dev, Error **errp)
@@ -1729,6 +1772,8 @@ static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 {
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         pc_dimm_unplug_request(hotplug_dev, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+        pc_cpu_unplug_request_cb(hotplug_dev, dev, errp);
     } else {
         error_setg(errp, "acpi: device unplug request for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
@@ -1740,6 +1785,8 @@ static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
 {
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         pc_dimm_unplug(hotplug_dev, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+        pc_cpu_unplug_cb(hotplug_dev, dev, errp);
     } else {
         error_setg(errp, "acpi: device unplug for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (16 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 17/33] pc: add generic CPU unplug callbacks Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:53   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 19/33] pc: piix4/ich9: add 'cpu-hotplug-legacy' property Igor Mammedov
                   ` (14 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 7f50116..cdbdd69 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -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);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 04aae89..4787df1 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -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);
diff --git a/include/hw/compat.h b/include/hw/compat.h
index a5dbbf8..636befe 100644
--- a/include/hw/compat.h
+++ b/include/hw/compat.h
@@ -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",\
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 96f0b66..f1e40ae 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -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 \
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 19/33] pc: piix4/ich9: add 'cpu-hotplug-legacy' property
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (17 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 18:59   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw Igor Mammedov
                   ` (13 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/ich9.c         | 29 ++++++++++++++++++++++++++---
 hw/acpi/piix4.c        | 12 +++++++++---
 include/hw/acpi/ich9.h |  1 +
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 853c9c4..121e30c 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -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"
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index c66d3ed..d25479c 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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(),
 };
 
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index bbd657c..e29a856 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -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;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (18 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 19/33] pc: piix4/ich9: add 'cpu-hotplug-legacy' property Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-30 19:02   ` Marcel Apfelbaum
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 21/33] pc: piix4: " Igor Mammedov
                   ` (12 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

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 <imammedo@redhat.com>
---
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(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 121e30c..b0285b9 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -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)));
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index e29a856..198c017 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -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;
 
diff --git a/include/hw/compat.h b/include/hw/compat.h
index 636befe..a65d9d2 100644
--- a/include/hw/compat.h
+++ b/include/hw/compat.h
@@ -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 \
     {\
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 21/33] pc: piix4: initialize new CPU hotplug hw
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (19 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 22/33] pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook Igor Mammedov
                   ` (11 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

add 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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
v1:
  - drop PIIX4_PM.cpu-hotplug property
---
 hw/acpi/piix4.c     | 55 +++++++++++++++++++++++++++++++++++++++++++++++------
 include/hw/compat.h |  5 +++++
 2 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index d25479c..05ce725 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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(),
 };
 
diff --git a/include/hw/compat.h b/include/hw/compat.h
index a65d9d2..862776e 100644
--- a/include/hw/compat.h
+++ b/include/hw/compat.h
@@ -7,6 +7,11 @@
         .property = "cpu-hotplug-legacy",\
         .value    = "on",\
     },\
+    {\
+        .driver   = "PIIX4_PM",\
+        .property = "cpu-hotplug-legacy",\
+        .value    = "on",\
+    },\
 
 #define HW_COMPAT_2_5 \
     {\
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 22/33] pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (20 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 21/33] pc: piix4: " Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 23/33] acpi: add CPU devices AML to DSDT Igor Mammedov
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Add 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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 05ce725..ee83d10 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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 = {
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 768918f..af939bc 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -331,12 +331,38 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
                  (void *)fadt, "FACP", sizeof(*fadt), 1, oem_id, oem_table_id);
 }
 
+void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
+                       CPUArchIdList *apic_ids, GArray *entry)
+{
+    int apic_id;
+    AcpiMadtProcessorApic *apic = acpi_data_push(entry, sizeof *apic);
+
+    apic_id = apic_ids->cpus[uid].arch_id;
+    apic->type = ACPI_APIC_PROCESSOR;
+    apic->length = sizeof(*apic);
+    apic->processor_id = uid;
+    apic->local_apic_id = apic_id;
+    if (apic_ids->cpus[uid].cpu != NULL) {
+        apic->flags = cpu_to_le32(1);
+    } else {
+        /* ACPI spec says that LAPIC entry for non present
+         * CPU may be omitted from MADT or it must be marked
+         * as disabled. However omitting non present CPU from
+         * MADT breaks hotplug on linux. So possible CPUs
+         * should be put in MADT but kept disabled.
+         */
+        apic->flags = cpu_to_le32(0);
+    }
+}
+
 static void
 build_madt(GArray *table_data, GArray *linker, PCMachineState *pcms)
 {
     MachineClass *mc = MACHINE_GET_CLASS(pcms);
     CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(pcms));
     int madt_start = table_data->len;
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(pcms->acpi_dev);
+    AcpiDeviceIf *adev = ACPI_DEVICE_IF(pcms->acpi_dev);
 
     AcpiMultipleApicTable *madt;
     AcpiMadtIoApic *io_apic;
@@ -349,24 +375,7 @@ build_madt(GArray *table_data, GArray *linker, PCMachineState *pcms)
     madt->flags = cpu_to_le32(1);
 
     for (i = 0; i < apic_ids->len; i++) {
-        AcpiMadtProcessorApic *apic = acpi_data_push(table_data, sizeof *apic);
-        int apic_id = apic_ids->cpus[i].arch_id;
-
-        apic->type = ACPI_APIC_PROCESSOR;
-        apic->length = sizeof(*apic);
-        apic->processor_id = i;
-        apic->local_apic_id = apic_id;
-        if (apic_ids->cpus[i].cpu != NULL) {
-            apic->flags = cpu_to_le32(1);
-        } else {
-            /* ACPI spec says that LAPIC entry for non present
-             * CPU may be omitted from MADT or it must be marked
-             * as disabled. However omitting non present CPU from
-             * MADT breaks hotplug on linux. So possible CPUs
-             * should be put in MADT but kept disabled.
-             */
-            apic->flags = cpu_to_le32(0);
-        }
+        adevc->madt_cpu(adev, i, apic_ids, table_data);
     }
     g_free(apic_ids);
 
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 86d4547..0aaaad3 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -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 = {
diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
index fdfc163..61b5505 100644
--- a/include/hw/acpi/acpi_dev_interface.h
+++ b/include/hw/acpi/acpi_dev_interface.h
@@ -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
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index f1e40ae..8d2dc19 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -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
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 4b258a6..e8ff38d 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -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
diff --git a/stubs/pc_madt_cpu_entry.c b/stubs/pc_madt_cpu_entry.c
new file mode 100644
index 0000000..427e772
--- /dev/null
+++ b/stubs/pc_madt_cpu_entry.c
@@ -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)
+{
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 23/33] acpi: add CPU devices AML to DSDT
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (21 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 22/33] pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods " Igor Mammedov
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/cpu.c         | 38 ++++++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c  | 10 +++++++++-
 include/hw/acpi/cpu.h |  3 +++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 73258a1..b3e1cca 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -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);
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index af939bc..47d4182 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
 
diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
index 3fdf4eb..ca32e07 100644
--- a/include/hw/acpi/cpu.h
+++ b/include/hw/acpi/cpu.h
@@ -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, \
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods to DSDT
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (22 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 23/33] acpi: add CPU devices AML to DSDT Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-31  4:38   ` Michael S. Tsirkin
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 25/33] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback Igor Mammedov
                   ` (8 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Add necessary CPU hotplug methods to handle hotplug
events.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
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(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index b3e1cca..28d3894 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -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);
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 47d4182..c62c020 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
index ca32e07..0346f24 100644
--- a/include/hw/acpi/cpu.h
+++ b/include/hw/acpi/cpu.h
@@ -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) \
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 25/33] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (23 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods " Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 26/33] target-i386: add X86CPU.node property Igor Mammedov
                   ` (7 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

pre_plug callback is to be called before device.realize() is executed.
This would allow to check/set device's properties from HotplugHandler.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 hw/core/hotplug.c    | 11 +++++++++++
 hw/core/qdev.c       |  9 ++++++++-
 include/hw/hotplug.h | 14 +++++++++++++-
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c
index 645cfca..17ac986 100644
--- a/hw/core/hotplug.c
+++ b/hw/core/hotplug.c
@@ -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)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index db41aa1..a0b3aad 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -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);
         }
diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h
index da1d0e4..c0db869 100644
--- a/include/hw/hotplug.h
+++ b/include/hw/hotplug.h
@@ -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.
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 26/33] target-i386: add X86CPU.node property
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (24 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 25/33] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 27/33] pc: numa: replace node_cpu indexing by apic_id with possible_cpus index Igor Mammedov
                   ` (6 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 target-i386/cpu-qom.h |  1 +
 target-i386/cpu.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index cb75017..7b09fa5 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -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;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d0b5b69..060131a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1802,6 +1802,44 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, const char *name,
     cpu->apic_id = value;
 }
 
+static void x86_cpu_get_numa_node(Object *obj, Visitor *v, const char *name,
+                                  void *opaque, Error **errp)
+{
+    X86CPU *cpu = X86_CPU(obj);
+    int64_t value = cpu->numa_node;
+
+    if (value == -1) {
+        error_setg(errp, "Attempt to get not initialized property '%s' on '%s'",
+                   name, object_get_typename(obj));
+        return;
+    }
+
+    visit_type_int(v, name, &value, errp);
+}
+
+static void x86_cpu_set_numa_node(Object *obj, Visitor *v, const char *name,
+                                  void *opaque, Error **errp)
+{
+    X86CPU *cpu = X86_CPU(obj);
+    DeviceState *dev = DEVICE(obj);
+    Error *error = NULL;
+    int64_t value;
+
+    if (dev->realized) {
+        error_setg(errp, "Attempt to set property '%s' on '%s' after "
+                   "it was realized", name, object_get_typename(obj));
+        return;
+    }
+
+    visit_type_int(v, name, &value, &error);
+    if (error) {
+        error_propagate(errp, error);
+        return;
+    }
+    cpu->numa_node = value;
+}
+
+
 /* Generic getter for "feature-words" and "filtered-features" properties */
 static void x86_cpu_get_feature_words(Object *obj, Visitor *v,
                                       const char *name, void *opaque,
@@ -3133,6 +3171,10 @@ static void x86_cpu_initfn(Object *obj)
     object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo",
                         x86_cpu_get_feature_words,
                         NULL, NULL, (void *)cpu->filtered_features, NULL);
+    cpu->numa_node = -1;
+    object_property_add(obj, "node", "int",
+                        x86_cpu_get_numa_node,
+                        x86_cpu_set_numa_node, NULL, NULL, NULL);
 
     cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 27/33] pc: numa: replace node_cpu indexing by apic_id with possible_cpus index
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (25 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 26/33] target-i386: add X86CPU.node property Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 28/33] pc: set X86CPU.node property if QEMU starts with numa enabled Igor Mammedov
                   ` (5 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

that 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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c |  2 +-
 hw/i386/pc.c         | 28 ++++++++++++----------------
 2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index c62c020..9b9ef62 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1cad132..2dba916 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -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);
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 28/33] pc: set X86CPU.node property if QEMU starts with numa enabled
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (26 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 27/33] pc: numa: replace node_cpu indexing by apic_id with possible_cpus index Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 29/33] acpi: cpuhp: provide cpu._PXM method if running in numa mode Igor Mammedov
                   ` (4 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/pc.c | 43 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 2dba916..2d29b5e 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -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;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 29/33] acpi: cpuhp: provide cpu._PXM method if running in numa mode
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (27 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 28/33] pc: set X86CPU.node property if QEMU starts with numa enabled Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling Igor Mammedov
                   ` (3 subsequent siblings)
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Having 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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/cpu.c         | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/acpi/cpu.h |  1 +
 trace-events          |  2 ++
 3 files changed, 75 insertions(+)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 28d3894..6961c64 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -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);
         }
     }
diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
index 0346f24..f1f6165 100644
--- a/include/hw/acpi/cpu.h
+++ b/include/hw/acpi/cpu.h
@@ -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;
diff --git a/trace-events b/trace-events
index 7101ba9..b141d49 100644
--- a/trace-events
+++ b/trace-events
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (28 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 29/33] acpi: cpuhp: provide cpu._PXM method if running in numa mode Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 15:29   ` Eric Blake
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 31/33] tests: acpi: update expected tables with new cpu-hotplug methods enabled by default Igor Mammedov
                   ` (2 subsequent siblings)
  32 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 6961c64..642e8e5 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -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);
         }
     }
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index b0285b9..3d65519 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -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);
+    }
 }
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index ee83d10..59f5c2a 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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)
diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
index f1f6165..ccbeccb 100644
--- a/include/hw/acpi/cpu.h
+++ b/include/hw/acpi/cpu.h
@@ -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, \
diff --git a/qapi-schema.json b/qapi-schema.json
index 54634c4..54ce851 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4018,8 +4018,9 @@
 ## @ACPISlotType
 #
 # @DIMM: memory slot
+# @CPU: logical CPU slot
 #
-{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] }
+{ 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }
 
 ## @ACPIOSTInfo
 #
diff --git a/trace-events b/trace-events
index b141d49..4716b96 100644
--- a/trace-events
+++ b/trace-events
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 31/33] tests: acpi: update expected tables with new cpu-hotplug methods enabled by default
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (29 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 32/33] tests: acpi: add CPU hotplug testcase Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 33/33] tests: acpi: add DSDT/MADT expected tables for cpu-hotplug case Igor Mammedov
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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(-)

diff --git a/tests/acpi-test-data/pc/DSDT b/tests/acpi-test-data/pc/DSDT
index 8b4f1a09b87f8361fb572022f69d304ddeeace99..13cee3d31880435cf79a4004befcc6b876f6968a 100644
GIT binary patch
delta 850
zcmb7DO>5gg5Z#TPbiGniTowu~v<4pnIXIh;d!vk$M6u-xuM#M0kdAgvBDb7WJCHwM
zdUs0hrt}B&FZ3U|Gp3hF>Y+LaY3Jj;H}iIV@T(_%<0qfqGR8mrkoT|Jrzfd7OYQu;
zH9l<6=i*xQ3d<oL^qELuWZJt@UU0TzEAHMi`!yb!gga~{T|4X2kH<O?2SX0w&~O+<
zHyna1%~=y5@`atfp`-?wV9>!#-%C1netIzO5gNqTMx>Xazw1F9YJH>$v<Q9I`z^Os
z8<O)cTT8i^ut(5ZPu1lPAY#jQ$A?X75JRZrQDBJgdYw<o$B3G<Z24|c4iMv9zRv7^
zB{C@b&zXw0Nyh&n@p3QhPzTUg0|yKYMZJz<jhw#+;#<b^tlSb6EsrX4HnYcJVMT=m
z#-2`=$CaARs;EXbUKSNJP>kMXymmf)6}8~AN!)t+|5!tX7uqAAmgS*8@<MKvk16-I
ze2BTV)3pyllkCDak8)GAjCdyFpt~Y3X**Idfp-Ao%1Ozsv}>mJQdH$Y7vF3$y;bkg
Xr5ACK2Kt!&y&vRQTHVi&t<3!c!q?=r

delta 384
zcmYLFy-ve082p^HG;+gFD}xYI)sZ2J5KJr-H$@6+iEtJaBs+;JrJEN9+Mz%t=uBWw
zQT7V)0IWO$8;=4`K*EF1XMd+V-@Em_i@U7rPd5S3;VZtbO`UDdjyXA?UcaNs*_?W3
zg9L<Z)Ug2ulq-~@d5ATTi2@y@P*8z9Bs<h&KKfT>RgvTMg`NY!)N@=dXyXs!u6XB+
zf>b*nN{A$gmtOT*JSZ<V_)`lAGdvNv2IB}t3sYSW$3nTO`ALKz&f1S@7|Xa!C?LaW
zj0S%1LZF3FBG#`&aCcg<(x;l0ey%mAu!JRQT|;oAtbJ66C2j?`W=V=LM;pOxpL(|a
z`%SXS`yC(hq6z?Fa^`mm#(Ypuj%y=D92XMOC=4|fA%XisKQfBinmR&c>(b&Up2Hn`
QuMX<0%2ihM?F$R@2bG;?KmY&$

diff --git a/tests/acpi-test-data/pc/DSDT.bridge b/tests/acpi-test-data/pc/DSDT.bridge
index 0d09b5cc61114b68fee0f14729732786854b19fe..599963e42caf6e41050625094120e97dab5acbde 100644
GIT binary patch
delta 850
zcmb7DO;6iE5ZxuAY}TeIWlyaHk#eZi11yLOhf0{S0h2hjvZhkCk?b1@CyN^=msH{p
zMBLMsdsOuw^cVCWr87}4wauYESoY4xdvE6LujA=^=^H<p?l8u$f5^Ly_Q_FdPE$KQ
zYmN3B^f|i{dxhl?_j^pFFf{E=DbG1uumyMTnEf0NO~M_vkgmP&(vQbF5C;Pe;lOYh
zMjtr@mzuLCK;#R1|B8|tV1j-JGkq`V*y+i;(H@~ed}Ty>5&D}R#G%#)nm~)tcfH?o
zU9}-O`?NNfvoU)Bt@T7*yZ}UO+3sk+NeyBMbvz6V@m((SarqcgbC%6t&&mN}oXf4u
zzO6+1Meiw7(K^ZaKO|o6g&pbudaCb$fq|&kQ7n=3w?I5*JkQE4QPKRMB4;&w92Qno
zNMP*i(fqJdvsx9^$i}}#1q~FVw;8XUPftZH_+S#Zp8hjysPIC2<dd>I^haLEwem6L
z-jok9w|2VrOVA{{u+^j76fGm3$T;Y($V=Le6inb9z_@Z!ax3kcsh26La-fTEHlEz5
ZH|WyyI7kD1$o}3BaxAUx=Wgr!_8)Vw<u(8S

delta 384
zcmYLFy-ve082p^HG;+&Ni-izksQLg^gkWGmqPQtiP>V&fpdi^vR4Hs;7}^en7C~nM
zdkWbr#2a+t5!iSYoPdM}pU?hIcfQHd@({P3w!7Q~K=<!>P#Rm?+&SUofU<5&lhYYx
z=e-Dotd_9>2IR|^*E1h$AR`4jNTHwrsZVw&b6oVVN{S-I>vKH?f+@3X&1>LKVz00Z
zhk{f)?@I_Ih}TZ>MLa4mr}w88;3s$_a0!M13g#7c-5(0&rshWhf-q@3#eOKmJfVOD
z$06#uolAk{Mvhp&5#Hpi(2So;&G>7rHiiW(P<;U2t+IAe85X$i-Bogug*o2vru&qc
z=I=MjD(|*jNV6&cNQFCYD`Soe>dCTAq=;ohM5>vgrXob}km;|DthSnt5ZStF@>6DU
S%iJr2I;(P(75(_eZ<{~jNoT<T

diff --git a/tests/acpi-test-data/q35/DSDT b/tests/acpi-test-data/q35/DSDT
index 67445428d935bd6ea5957526089ba7e719a1783a..dc80ec1431009a652fe3206d280fae1850c9fdbe 100644
GIT binary patch
delta 850
zcmb7DO;6iE5Zxt7<*W@=&|ZK`L=H$jz=HAvV#Wqc;?&Bzm8uQ0j|mqnZk$Z0RH^5v
z_kj2Vh+o02$NZagCgM`tJ=6!w-uZa%&Aff<{q%&Vy|}s07{7TDvz=D2o9NTTJe)Ph
zM>YDKU+o^|hC?*yGb@3SZfy#2&X>;8;m#d1_t8kl++I4uF|!W+xU3D4KjaV$HHT67
zm4kn&II9DMo@Hj+lvD%l589aNxpCV(^gfLb2@Rqz+Da}0Z_|Y+Q0iC_XdZZu`&%?*
z3*xhH8w)X?upgk5n#zk0fQU`g86VZDK?H${M!qJ#t5r5B9wTbT(#7t)7$C-(_?Vi5
zQe=?#pHmq&NXGvm@nSFRPzBJJ0~<69t!f?l3OPUd)~}RjX|W|LS{#?;tY?qI!io|J
zj6HT2C#9P8s;EZP{w~UCpcuVPdF6ciGHk+U9Xr+Z|FMP=FSJKCEy_cGWVzTV9#igh
z@ep$>r)$3Zb+QXvKhjCiGS)L02i+CAamyAKv+xdJT-ph_m3GbKR)VT*=-``8rq^;0
YU3wn*iLXxB`~4ut(&}Ch_Vycp0Qp(vLjV8(

delta 384
zcmYLFK}y3w6#bL58m19#8N`Z<&;yhpx^GNVG15Ai*+_&;5(?>VHZE)zwHCC3D}y^1
zsl)?_m(UyZ242HS6r9Dpc{Bg<-n@tIR|j{!E;}&*(BnIvHK)!_;2j0z(58J$5%Yyj
z&jtx_QLkYQG$>anMvD+DAQA~G2ri)lc}R9`>M``M%Bnoan@cqZf^F)!ir>PY#9gE3
zo()3o!B9XXfWP*t&-`9`d4oSShcLqvj@Mxvp=hbg>*1J7H#t9v5X4#QDGg&0mkBv!
zIE~SO^)5JCY9(Uziu<>xm3I2lY^QHVW4h8;Ix?=ozme7q)mAz-{Fz>oB1~t?pC8!N
zG=INIHiEvzATO!_AbQ|2t6&}j`Q*4JlEiT#A@#ygkr5KOEA%6+sI8$QM7A&6!7+6L
T$K0=hJj-&WmHqL(*Q)*i<e6u!

diff --git a/tests/acpi-test-data/q35/DSDT.bridge b/tests/acpi-test-data/q35/DSDT.bridge
index e85f5b1af9fcd36c9522b05e0085af84d6c010cb..5277c91c2e47a04bee848fe35cf8243323eb7b00 100644
GIT binary patch
delta 850
zcmb7D%}(1u5Z)z8<*ZFns=YK^B62|D01M>-V#Wqc;$UUnO4X*aj|nHMH%=y0;sv5!
zdJ2dasCW^MQC}vViMU{!13p;x&d>LKGvEH}{qcmSy|}%@7~lFUW}jQV<3yh%=JvEX
zKB&>>{6~8~HyoltpIHfvbZb+HGrn||4tK7Zxrs(P=JwJNj+u4o$7LOe{2_;6s5y+n
zZyfv!#aSI7^ei*`L`gN!{-A@Io*Q?}ZEtV9PiPQ*)mCyIc$+Rnfl`NxK=Z(J+-K2{
zEr?IQZ!E-o!tOvRHI?Td01=y}J3gpWg9ri@jeJdfSF3DNJVw-vrHl5w7$C-(*h<ZA
zDKg0WkEskBB;$QZyx0pnQ~~tmzy=LNt6E3CLe3Aq^*iNRT5O4m7KbG{>)GS5u%bi)
zWB134qf*U!Ra7HtuZwaTC`Ny#ymCH$88+ck$4)i<H`Y+%h4#p%MS19tEEgNaW6HfM
z9%63gbj>fnPIh7IM>+{w#(E^<pu0jhZrQ?O7Ty7jOFJRA(yp2On4l^fy7*?3>6P3@
Xm!3s_;;SR}azDtiw7RF=?Jtf0XqM$C

delta 384
zcmYLF%}T>S82mPAHEbi=vWOKAp=T+<pL=VX3X#^}=AsdHlTb)+d-2frP-{VZHh2*a
zsl*2mU&2QyzJRacCJOFhXJ_{tW_F%CUoG6B9q-BjK>P1_R-f8CjGi!ZY`ML*BIXOr
zJ@3cBMYV!8(4bg>7%l>=fQTiiAh?7QWC7W=T<W2JRa)j5-dw5~5Nx@&qxcQ{Nt`wJ
zf?6Qt&ISTP0sOUFe&P?(i}wH29D)>2I9`Wwh{B~VuLol;-Q@fvL=dHo$0UeER3zk(
z;v_<SuY1YSQY#RvH{8EFD>ajsdNX-5YSWdz(vdL&|5jRisIt<r;m`Df<Y8J{{`|;t
zP4oAgWP|nE9%OkH07PfhYv+u5AfIf<M3UGJ#H5-VDl$S0_ql$k<+asRgvj=FlbyOY
Tv(1AF$g?b0T3H|8dxzy8rNC#A

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 32/33] tests: acpi: add CPU hotplug testcase
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (30 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 31/33] tests: acpi: update expected tables with new cpu-hotplug methods enabled by default Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 33/33] tests: acpi: add DSDT/MADT expected tables for cpu-hotplug case Igor Mammedov
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Test 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.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
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

diff --git a/tests/acpi-test-data/pc/SRAT.cphp b/tests/acpi-test-data/pc/SRAT.cphp
new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98
GIT binary patch
literal 304
zcmWFzattwGWME)4bMklg2v%^42yhMtiUEZfKx_~V!f+sf!DmF1XF}yOvY_!<(fDl0
pd`1npO;83GTmZW|po75R12aq^syaB21u74tQT&BzFU&Ml8UVWm2>}2A

literal 0
HcmV?d00001

diff --git a/tests/acpi-test-data/q35/SRAT.cphp b/tests/acpi-test-data/q35/SRAT.cphp
new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98
GIT binary patch
literal 304
zcmWFzattwGWME)4bMklg2v%^42yhMtiUEZfKx_~V!f+sf!DmF1XF}yOvY_!<(fDl0
pd`1npO;83GTmZW|po75R12aq^syaB21u74tQT&BzFU&Ml8UVWm2>}2A

literal 0
HcmV?d00001

diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index 9acf9ba..b74ec7f 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -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);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH 33/33] tests: acpi: add DSDT/MADT expected tables for cpu-hotplug case
  2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
                   ` (31 preceding siblings ...)
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 32/33] tests: acpi: add CPU hotplug testcase Igor Mammedov
@ 2016-05-17 14:43 ` Igor Mammedov
  32 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-17 14:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru, marcel

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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

diff --git a/tests/acpi-test-data/pc/APIC.cphp b/tests/acpi-test-data/pc/APIC.cphp
new file mode 100644
index 0000000000000000000000000000000000000000..1bf8a0a63bc1c9b716d937b96eb34b05016b9366
GIT binary patch
literal 160
zcmXwx!3}^Q3`JW6f}%UP3UJYrBwpObWgNv(oJ8%n@zB24pP!~WmxG9S&r6xsF>kdb
z$yhQtNOavFgY<9)W~DJWDKu7Tozi)bd+hVZHk}Lv=1?18ZTnj%1<hjo%=$-Oyrt<4
A0RR91

literal 0
HcmV?d00001

diff --git a/tests/acpi-test-data/pc/DSDT.cphp b/tests/acpi-test-data/pc/DSDT.cphp
new file mode 100644
index 0000000000000000000000000000000000000000..afd2082d4d83626589e552f9b48ef0f8fa22b3e2
GIT binary patch
literal 6578
zcmb7I|8En?6`$E%JL|EXtdj)-fx`-L^k@Np34v3q3VYXy4PIyQI+SWry$(Tj(6y{`
zAYBffl=!3^$8RT>Q~R4i`5C1C1MQ!1f5P=&xT*&~k-oR<S({B(IxNL`Z{BA<@6F7c
zH#62Pz4g!IgwU7e6|HJz%Xdsohc-$GK^gxmHR&#~xApRJn<fQ`+B->4hOe@${zfma
zF4Mnvo$npz(Kin5xMc06@_eo1e*M&0BM5rD<}!wYGT*k!ZM!#TYPFo)uGaKa=?5mt
z?ULRka(lI=Q^k;dOhvAml@<q40D&38sG2Q<qzL)pU6M%lj)MBk?Mg$>noYf(RTtY<
zt3+IEaa?TbeCaU78Kl1JJEZR<_xJb6VDh_uhy1ORBLDecY>(`*DY>mRtxSeZ?j~Tw
zKu#n=wuo}>5=MjJ+P&lEoqW-YH6;=Xp_uuiCJ?r-T#t>xG^u8l+CB~@7I6zXO<)d#
za6kUjC1k;#gj6q+iMm;7P;!lkS_uVFE5koUJAGN?j*-poU2L{AAoZs#36q8K&axxR
z)Fm!agn2@j=_c7ELVSzZy{k9NdH@$iHQ~)lFi@|fLmWb(*E(5;|MLQj*Y2G+R#t<K
zQ#0X?GK<X<1%V}bN!Nl!oESzl$7Yx5PvTD^k(TKj@eNGW{B?3c^0@O$b+g15dr7ZN
zXBEO?Y=z}0d(8xP4*sUu9NTA~v7gx#ljZi3UdbF|DyHH1M*zj{{l0Ftf><S@&iYG_
zQ|b)ju-tp(g%pfgVd-W1h4_Ui%k$e_JQYb>G4gy;W7N+;PJ;^)Me|mCD-wBL@o1Ki
zrVyfGLcjwn8p$KP6@W(u9;GUel4#r1tQJj@S4@T!M@54iT+PClp0&5F$_?0x@+-`!
zBq~}tSGfU(a>HoSq~aS;(aMcgBWu%gUAsxtbEa0gA=qb7+uwJ)Xmq#e2Ep$3d2HSz
zN&~h~xvkt}nD(m9+Gevw+-YIkaY^T8Iq|&1w%so~OdxCSlg-W=VIsLVQ2O@(lz?qh
zZ`{<$`rvH;9vx)*9VP|M7FmCh4zv=0GW~l@2wKX+7BOhi$h!O0)*4d?Y+Ukmoe=j)
z2mC!<r^H=<>U7BC&YolMoV_e!w76Grw^6fsD<{KO9={6sRg~44+AWyXLE;J9?!u-|
z?6IV}Si7Y)698!DGLtO%ZJZ>$WZNRou#LswyEaHZ@4}e7DDPpj-K$T)Fd>=!4Vi)h
zg5^nuxw0}x+03_-Bq7EiOBwtn;cttmQ~n;rATT^N)7EPi`3hyW?X^tdt|ogJlBXYQ
zTTP2T>-teZHEY(eedxU$@(%g?i@oQ^yyrddd5CY^dtN=<d*1FDICd@Moe3Y{zA)y#
z;JGh^+!rF;7l!WjuzNTle(~swWA2Nd`(ns_F~WV(?yX2LdMoT+^4;?k!czp6oR{6C
z8uu1kP5N_;p+Xa`uA<rgfwz>nJ1Y8Svl6&qaWA>jnz@>-K78bU_V~})&HJA}e7t$@
z{^!J|npwX&EWc^SmMM8nUegrRXh<rrio9kid*=))C6d+fz|m?Ai)u~dHid$aqeRj)
zLx)l`jUZ98D)lTN^-?Qq_q1Dgy}|_U{gBcn&8+2e`5Zd+kMNjkNLp*@kHUcUyJT0(
z<#HP+QWWzWgJi$U1e6QDETUZWWeMd4Uyh-CWkapTq2!ek_L;kvC4LU#l;BXYaD|&8
zV3#<96aBCO2kWva$3B0+Qop(9s74GY;KLlzFcmNy%C8zp&C(ij)G&zia!G#fu(<1l
zDPcf^{DIMUs|M5TQ1?I(V0*DJC>-eHEi(3D;=xW}+;r&Sv!m)0nt8|gu(=`Ofk0ll
z;Wo&t!(HNnB(xQ)m5Q3OLs$O5T%gm9L%h072)82iLAVhDJaj?rugft=&>U=T_^2r?
z=<*(>Dr^O#)XF58Ok}+Dfi>C2t%d1@NSH}L!Z%ST+c3f;4wG~@9t=72{uO7O6Y6=u
zNok0aj&ss6PU>+kVVniLCP5_WQJh$%15!coNK-+eaA`@8A_Z+K2$cyV-lBMr7s_wI
zD@tKr@jYH~oL3z2F2Lm>952+>fLDrzd8PMwrEy+q#Crt~;?O+A#&~1#FmLQV-q<*A
z40zQ!D2dBvrCrGtAmhEOI+jP=?Mma~=pNTAT{Nnue^#Z<hM6nn79myOs*pDB|K;K4
zR<?VfpsO?9Jz<dO8+xM&cUZWl*wpYYaHY5bF389RRnI<yw*CE=zkBXr57#lUdd&0<
zEEmSGT%hve=s@ioSP;BcEC{Ii6#z;0sCv=BGh>X_{YRI0gvq{9vD(9G>Y*LAG;6?}
z0ZN1)0>{cmb8#V4WVvU*CIlW!q0hU0|HGSy>OS1Lup^s<VC%j(4Pw<7Kdx7J>je;p
ztw)X0ogwxFh*j5UmaEtag*p;}P_JSK6zWK_iOncrUsOCZ_8zFuu?_8;s8g>o<2BMp
zK?_QCwABatL?4?847pgyoMtD#IW|6I94ZbIhv*HjSYQn3+b|{&C!z09JPHA|UG$7*
z7s=7+Vw`BQ&wF!@-2!oOK|O0gO`+ihaG|vgHFmg6zcQfMNC!Y0#!BV3`v8oZ4^`(4
zC|B@6cz-z|P2i2;LzG$^GvB-Z3@-wZ((0$M74ihDcJOZX9~ol}rq=Mv>U#+FIP@%z
z9~-z~Fw2!n#=m&r#omAKmM7R>pQecb&wrd#{DSxE+tk|>m7$&bsrClUZ&QJu_EzA(
z<Lkm;J@8VFAAxultN{3t_xJzx&KLjvGrn^*35M&xb3;2A+s7_q@ViB;#FBob-bL)k
z*FV0d5|Z4I%&OV+C++<*0E0W^Qg@Jxydtlt3eUt(?m_{vitXvRgl7WC3+-uHf~PZ7
zd(f_+1qYz~b~Jr<@6ysAv?V`)TNPs!4zU8FLlG-6C5Bf=<;K=s?-6LoV+-h&GOs9&
z4H8~BjLhO~vufhwlQ1@G@0><O#4VV`4GCX$l<FWsW@hc3QwS)L>&z=Ekn&Kfyvl@6
zTYKk--ybicn56J!X<0RnbxTl;hh9pQ!3uMmv~oH46##!ivU?Y-{7``;5Qqvx%<E7?
zQ7CYsh=Sew#L8cTj@D{p_!AU#5s5nO9f$Z*Mh9p{XaQ*v3I`In0x1085CP?^aK`x1
zSQNC#S>cNBL*tQ9&N{)N6H(9w&I&)E_^fgyl(Qx{G!X^8!dV%IvPdXrh27u>kc@&Z
za@G`wrXr!7HO-;vDCkwrI?17vkx<SGPk2ApsVL|*&Z=;z5((w384k@vK|kfJ(;PY-
z3FWLa96A#PEpb-Je1BMKB$Trr;m{*d&@yK|%ArRip`7&?haQW9YMgbJLuVtQob@<|
z9*=_Rob?2Uo`{5U);SKHi-J}->q!nh842aAr#SRf6m*HRe#D_4MM632X%0Po7*ws!
z>9-p#VUT*#g-6LQ*18Q(Q9yxe<||oLxaB%1P?3DgHY#XIKj|jnMYC%`Ss7{qYJp7x
z4T{6ihQ6)@HgpDCd}u>&i-8T@!A2e0(BD<GO+D#Cb%mpC*MbelbvWEWAKBrE+qGcp
za67!ZKp)u^)L|2Fd)CuO_UouaI&=HBr;qI3h#@h#9S)OSOB=J}s3FAyJC0i)v*XAi
pSps_&^)dT(&|%pF`!?!eS5M<T34YVZA7^n1;jCMwLqTWa{{iV_OIrW{

literal 0
HcmV?d00001

diff --git a/tests/acpi-test-data/q35/APIC.cphp b/tests/acpi-test-data/q35/APIC.cphp
new file mode 100644
index 0000000000000000000000000000000000000000..1bf8a0a63bc1c9b716d937b96eb34b05016b9366
GIT binary patch
literal 160
zcmXwx!3}^Q3`JW6f}%UP3UJYrBwpObWgNv(oJ8%n@zB24pP!~WmxG9S&r6xsF>kdb
z$yhQtNOavFgY<9)W~DJWDKu7Tozi)bd+hVZHk}Lv=1?18ZTnj%1<hjo%=$-Oyrt<4
A0RR91

literal 0
HcmV?d00001

diff --git a/tests/acpi-test-data/q35/DSDT.cphp b/tests/acpi-test-data/q35/DSDT.cphp
new file mode 100644
index 0000000000000000000000000000000000000000..ebaefcca0033c4c10fb8c11a18840ea69264ddde
GIT binary patch
literal 9340
zcmb7KTW=f38J#7U)M`mdD`_Rmw@7e;rb+9By2LGd2~6(tR&ynaq!R};K-x`ODQO!*
zae$<0080UK@k4=xb<n=ifu8dhnxBxj2Ix~?`x+GSQ`GZ)!=YxD5)kQuns4@;@0&Bb
zJ7>7duo<@g@{|zPw}q{s(p)Lrss|zZEFlE7>AzRCZ;ST*uu$$;nS^b%_cPqaN5S!b
z8WwJrt-tSdKks($eblw?^u*mSyoY!1^gj5wdsh(X?YlkKrH1!Rr&;K<@7IH7%gTr^
z-7L2YRwnx;rA2??dOfHX9B(Vj(1UUoan9*fs$n+&wd**YK(>-jCm%M1)45p<EvI?2
zUKdW#YSe@uPIk7Mf&JhO5ri+V4oVaKo!NQUYe)ZH|8Dux_0M0vm;dV5|N7m7H(VQl
zHT-w*f4xTm<)OwprFxG(+{^Si@ILGBTJPh?Dx+5ii=XusPIh~Aut#9(f0UKIRATk;
z4KH$}o}yE!7h6h?1r-=SX17vrMItN2*WYJ^-QM>oo`0#h8LreDVQ0m^)@io#qDMX5
z9(CRMbJz8{gY2jMuIP6&M@NTZF#T!&j`-W1toYCWQitNuoxyB1nzOU+^oNr;kw`9V
zA>I|<^@-<bI5f5GgCJdP<~ux{7{D?HQ?E9*6K<DIPYu^Y!oBY%+WY6JErP8mpA;7U
z74WZCZ-og)6%+0Op%#EDiXdOyw1NUYYIS^g*UvqlR28XO``~J$6`-g*uNj<28tIa|
zP_}xaC%nWJVU?{tu_qGgcSZZ)XEzGr2%b#(lRO_IiA?N@uCTy*RlJJ-R}xU#K6pCX
zx;Y}w%*Tn2o4O)A0=@_>BcLt(B{}0X{_Y@+Sw0kx>`_6_ohn=JB;QFo&XxOIsAywO
zR+XZZC9h1Ch9=~+G>?;ylft>;ahejPS&OA{6Qews(^K;#9w(5;K^~`G4NAh#cJSZo
z?NH?X^%aXwffxLjZ>f5tRiC@@*8RDRjjKo0Hg6P#Y+GoT#9Ws8-2{TN3X%vaVs6UL
z9vxw6khoz)EC8qFG3EiPLSiC6V-w5-b{G*;K@)<RfHD&yF)<p(CYh;5K-V8<WoS||
z0aYO}RTW(K63cmPW-6#HnQHI|b)6|gXNs8$nvzU4c!avnw4pQ2Oa)DwIuYtRCk&kv
zhRz97CqiAPW9W1YosOv!p{^4vgf`QYhR#V-CqiAPYv^<hovx`9p{_Gy=*$>8Gp0_2
zx=yTA+WE{HI<uxugu2ctL+6yCbIR0-P}eza=$tlmPMbOr>N;l(oim2c8B-@hU8iU0
z^bDPzsS}~DbJox~Yv`Ocbt2St&KWxA44rePPK3J7c|+&Cp>y8UiBQ++8#;YMr*G;+
zsOwxXbS@Y=7fhW9b)Acb&P7A#qNx+1uJfFs^PHjcoT(F`u5-!Ixn$^EGIb)<b)IKt
zez+2zXJ%oz*qxWm;5Z~^IK*Bsm=_G@1(S(TXI?az7Y*h`lZjAgUNV@M4CW=1iBM-=
zHkg+U=4F$KP-i~DOyx39FjKAZPe`U(xDgUlImxn7bJ?i5Y}Q05YdSE{yk?-~W_4ts
zXru7ZKoOv<43Y>`Q5dMiu_am9?=Vm~W<o+$NK7RS1}d@2Ks6{CsDv_;3=|<oqYPAH
zhY{6OUP}flp(6uDh@mqU1}d?`h?r_}$v`EPnPi{{l};F_#4-~GszJ#>C6t+Dpa_*t
z7^uWD69%e5$v`EPnPi{{l};F_#4-~GszJ#>C6t+Dpa_*t7^uWD69%e5$v`EPnPi{{
zl};F_#4-~GszJ#>C6t+Dpa_*t7^uWD69%e5$v`EPnPi{{l};F_#4-~GszJ#>C6t+D
zpa_*t7^uWD69%e5$v`EPnPi{{l};F_#4-~GszJ#>C6t+Dpa_*t7^uWD69%e5$v`EP
znPi{{l};F_#4-~GszJ#>C6t+Dpa_*t7^uWD69%e5$v`EPnPi{{l};F_#4-~GszJ#>
zC6t+Dpa_*t7^uWD69%e5$v`EPnPi{{l};F_#4-~GszJ#>C6t+Dpa_*t7^uWD69%e5
z$v`EPnPi{{l};F_#4-~GszJ#>C6t+Dpa_*t7^uWD69%e5$v`EPnPi{{l};F_#4-~G
zszJ#>C6t+Dpa_*t7^uWD69%e5$v`EPnPi{{l};EaBF#V%=?02WH&BF{foe<`sKz7%
z)tF?U8WRSpF=3z@lMGa2l7VVW7^udCfoe=LP>o3jsxe`p8WRSpG08wRCK;&4gn=Sb
zXBP&F2xp8ZlMECgPJ;@Gspb|2ib%~Z3>1-?TQX3DYHrCu5r)FQ(1C@DLAK9dRuAb5
z>7z9L%eVJ`@qCiLrP8wkdKzKX8{2s}?skDb0{RFYfoCJzMQWGmqf8$a$Dglm<MGm9
z@;&$d4jzI`9=aKSqq-e5CIM*VW~bfECuuQBkGAkl`2qF0DSTFY@9nrVf?60v15ZY3
z6WAl<)pzkM9;eX58VAE}&Mvz1pG=F%B-~A4{T5h>k<Fix&n0LG7){=v?S$2)c%Rzt
zeeRi|CmrID2E_5XPP5Up9_$RqK;@}_SiKOdj>if=xOzdWUf}8lj8Cs#@K3H@XdgtR
zJ&09z6K5zNXypSgAH>QBr<4zd<->S+JTCje>O-x3$mPRW`S6tT;jnx$Ufw=K`Jz_7
z$mNT%^2Jli7l-9b@$#uNlrL%JOI*GbD_=ULd}&y|950_fL;12+zRcyzvGV0p%9n@b
zEAjFZXDDCM%2&92C04$2O8E-P+q9I$%X_lCT0F3=pvP?d)Y9zp(|pV0AKll(bn)BR
zoi)>8uQ8TR_MMn+?7o~c(_sTLmQMDam~QMon>W*8S2C7P_MMn+?7s2Mbl9qlrIURp
zrW?Bt7R+?mzl^1meJ7?HyRH|_blB94rIURprW?CX&zb44(-})A`^<D+(3WoqN|U#b
zpOx1e#iqIvUEF~1pQ)gJbEWd;z1|<*{{70{Yj3^z_TFz_drP#fpkBK%ydtMuw`_fr
z{U&Q=@n{>qL+@L@$>M?j{*x5s#Y#ZW<%8;G(+V2VOIA?)P0kW_5JaKV-k&2-GH4cS
zD?o<%)(Tz|Y~SXW1}HCwG?fqP)m&~hM@8jJnUo*dL96siV&L|7#D_sHm)oVLMa|XS
zL8iasCaAq8+evD#%eGDJ4cSgn`-NS<lE#~&{AByd+t1tT^#M%@Nj*C1?Zmq=;GXCX
zF7)FENNmrY>9(I9J5sxG*!80nO~Ba-S@BfJaAJNx$^^||(>YCs=zdXh9(LVyuNzMZ
zL4(yXHGI}E&0VWEHV7Phv@uv4<M2r)j+-1O;ox4^I(c^da3ZMRiq1ASA}$2iRWII$
z>+0l^bV4SBt!68G+LWDm=EvrOite6JwdW?{y##$d-iZO8ctYDB6jHcAbGWtfhqo-a
zNS#BvRB<ar`POX4bp#$H&=%9rbm-Qi%ZuN~+=_t2d<uUWuPIv@k|}m}UmxaN<!z~v
z6I;GfPRokrwCEj=%4umiEzVh@ajxNc5shT(c$~D68zoI7IB9k?P`qxMI?jq{W;9ec
zah!J@uVdnQu|pf>P1^CiNh5Dk&zn5XyMbp-@x0i2jq=*5cwXDcYwLOK<Ge4>UOhGs
z*i()2rqc1eDI;%6&znMC|00&ea=q9o=GJh<^BYcD9_eoPHm_>$So2q-N?qFQRDH9a
z%jd4)QlZs6dhL&I?!CLRGq#}n^ZZp}Fxij7%?92+;(JWnifX|P;pfv4N{HiQSoPXZ
z(y^nXFMjo~ON?GOqSa%*AJK9V4VMcF9xV?1enblb_tJtukz4^N$)V+6jmR^!w7q}q
z2u_&kN5y7mxSBG$>*tpue67F|A%~!_PSm)zF}v>O9{fazth`$I6v&V7kK~`~8iq&s
zQbt5~8iTFL<{X+8+5AzhsCu78bJ)8W<!=qK7tpNqqDG-YBx=+s5gN4$5vWn4Bzx3N
z4dPP3hlxG#A5tG3-=o;#&ROoX?u~k=Rik6IK{(N;ZUM>bYqQJlrH^3p$C61Z$s~y^
zZ+*>mk-h^>XikGWY%XFzogP)D!#zq)2YWP5I@Ere=bUJx=Cuv~sR*lp6+Zzz^meeu
z4o}mMBP=%d7-%=zD!$Zv9R~vm^{+%&t`cKF3*Ey3czogW)?~O3z!mME$DOdQul;n@
z)1~TFvvT(!f6YPf`U?~8pFW-v2|S3TiJ=d?yMLU0oV6VETXOQg!{Nu-Q9Q-d_^m#<
zE+&<}eA8b-@DaL=>F=wfqkn!sY`#eE_yZevtNb-d>^7u+Z8wEqYqauiM(*!<H?@*p
zNn7}#fcMO8+_}y5&Rp82#Tf04&YWYr2^Y&Oq8I2074?33EV+H~T<PUN?qsL7i_uNE
z#~PtyRlJm!qCJ}zOyB00^^v3P26+wP)j%5<o<6u@iMDx_dep$rYFu}zy}wLBlCJ#~
zx)bnGqgD+qToNno{mTT%i|a1m&A8UEM(~n=Q;gr@EJ!}>0O{($M>AOQ)3jhDypk<{
tIg)ASa`?#v{SK#n@N6^pa~a^2Sps|h=4yy#iyCXHvCfTjJ=koC{{uk$!+8Jz

literal 0
HcmV?d00001

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling Igor Mammedov
@ 2016-05-17 15:29   ` Eric Blake
  2016-05-18  8:09     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Eric Blake @ 2016-05-17 15:29 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: drjones, ehabkost, rkrcmar, mst, armbru, marcel

[-- Attachment #1: Type: text/plain, Size: 974 bytes --]

On 05/17/2016 08:43 AM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  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
> @@ -4018,8 +4018,9 @@
>  ## @ACPISlotType
>  #
>  # @DIMM: memory slot
> +# @CPU: logical CPU slot

Missing a marker '(since 2.7)'

>  #
> -{ '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.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
  2016-05-17 15:29   ` Eric Blake
@ 2016-05-18  8:09     ` Igor Mammedov
  2016-05-30 18:21       ` Michael S. Tsirkin
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-18  8:09 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel, drjones, ehabkost, rkrcmar, mst, armbru, marcel

On Tue, 17 May 2016 09:29:15 -0600
Eric Blake <eblake@redhat.com> wrote:

> On 05/17/2016 08:43 AM, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  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
> > @@ -4018,8 +4018,9 @@
> >  ## @ACPISlotType
> >  #
> >  # @DIMM: memory slot
> > +# @CPU: logical CPU slot  
> 
> Missing a marker '(since 2.7)'
thanks, fixed in v2.

> >  #
> > -{ '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.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode Igor Mammedov
@ 2016-05-24 16:58   ` Marcel Apfelbaum
  2016-05-26  9:46     ` [Qemu-devel] [PATCH v2 1/33] " Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-24 16:58 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> 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 set
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   tests/bios-tables-test.c | 24 ++++++++++++++++--------
>   1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
> index 0352814..9acf9ba 100644
> --- a/tests/bios-tables-test.c
> +++ b/tests/bios-tables-test.c
> @@ -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) {

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

>               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);
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 02/33] acpi: add aml_debug()
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 02/33] acpi: add aml_debug() Igor Mammedov
@ 2016-05-24 16:59   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-24 16:59 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   hw/acpi/aml-build.c         | 9 +++++++++
>   include/hw/acpi/aml-build.h | 1 +
>   2 files changed, 10 insertions(+)
>
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index cedb74e..f7d99be 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -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
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 7eb51c7..70a4b14 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -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);
>


Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 03/33] acpi: add aml_refof()
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 03/33] acpi: add aml_refof() Igor Mammedov
@ 2016-05-24 17:00   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-24 17:00 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   hw/acpi/aml-build.c         | 8 ++++++++
>   include/hw/acpi/aml-build.h | 1 +
>   2 files changed, 9 insertions(+)
>
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index f7d99be..95f6021 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -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)
>   {
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 70a4b14..dd432d2 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -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);
>

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers Igor Mammedov
@ 2016-05-25  9:11   ` Marcel Apfelbaum
  2016-05-25 13:19     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-25  9:11 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> 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 <imammedo@redhat.com>
> ---
>   hw/i386/acpi-build.c | 17 -----------------
>   1 file changed, 17 deletions(-)
>
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 279f0d7..ff98ad8 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
>
>


Is this patch related to the series? Or is it a cleanup opportunity?
Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers
  2016-05-25  9:11   ` Marcel Apfelbaum
@ 2016-05-25 13:19     ` Igor Mammedov
  2016-05-31 10:06       ` Marcel Apfelbaum
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-25 13:19 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, mst, rkrcmar, ehabkost, drjones, armbru

On Wed, 25 May 2016 12:11:33 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> > 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 <imammedo@redhat.com>
> > ---
> >   hw/i386/acpi-build.c | 17 -----------------
> >   1 file changed, 17 deletions(-)
> >
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index 279f0d7..ff98ad8 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -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);
> >
> >  
> 
> 
> 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

> Thanks,
> Marcel
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH v2 1/33] tests: acpi: report names of expected files in verbose mode
  2016-05-24 16:58   ` Marcel Apfelbaum
@ 2016-05-26  9:46     ` Igor Mammedov
  2016-05-30 18:14       ` Marcel Apfelbaum
  2016-06-02 11:02       ` Marcel Apfelbaum
  0 siblings, 2 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-26  9:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, marcel

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 set

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 v2: replace 'for' loop with more readble 'goto'
     Marcel Apfelbaum <marcel@redhat.com>
---
 tests/bios-tables-test.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index 0352814..f0493f8 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -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);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/33] tests: acpi: report names of expected files in verbose mode
  2016-05-26  9:46     ` [Qemu-devel] [PATCH v2 1/33] " Igor Mammedov
@ 2016-05-30 18:14       ` Marcel Apfelbaum
  2016-06-02 11:02       ` Marcel Apfelbaum
  1 sibling, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:14 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: marcel, mst

On 05/26/2016 12:46 PM, Igor Mammedov wrote:
> 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 set
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   v2: replace 'for' loop with more readble 'goto'
>       Marcel Apfelbaum <marcel@redhat.com>
> ---
>   tests/bios-tables-test.c | 18 +++++++++++++-----
>   1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
> index 0352814..f0493f8 100644
> --- a/tests/bios-tables-test.c
> +++ b/tests/bios-tables-test.c
> @@ -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);
>

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML Igor Mammedov
@ 2016-05-30 18:18   ` Marcel Apfelbaum
  2016-05-31  7:50     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:18 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> 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:

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel


> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   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(-)
>
> diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
> index 97bb109..730f44c 100644
> --- a/hw/acpi/cpu_hotplug_acpi_table.c
> +++ b/hw/acpi/cpu_hotplug_acpi_table.c
> @@ -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);
>   }
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index ff98ad8..822230f 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
>
> diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> index f22640e..9b1d0cf 100644
> --- a/include/hw/acpi/cpu_hotplug.h
> +++ b/include/hw/acpi/cpu_hotplug.h
> @@ -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
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
  2016-05-18  8:09     ` Igor Mammedov
@ 2016-05-30 18:21       ` Michael S. Tsirkin
  2016-05-31 12:53         ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Michael S. Tsirkin @ 2016-05-30 18:21 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Eric Blake, drjones, ehabkost, rkrcmar, armbru, qemu-devel, marcel

On Wed, May 18, 2016 at 10:09:27AM +0200, Igor Mammedov wrote:
> On Tue, 17 May 2016 09:29:15 -0600
> Eric Blake <eblake@redhat.com> wrote:
> 
> > On 05/17/2016 08:43 AM, Igor Mammedov wrote:
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > >  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
> > > @@ -4018,8 +4018,9 @@
> > >  ## @ACPISlotType
> > >  #
> > >  # @DIMM: memory slot
> > > +# @CPU: logical CPU slot  
> > 
> > Missing a marker '(since 2.7)'
> thanks, fixed in v2.

v2 was never posted.

> > >  #
> > > -{ '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.
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 06/33] pc: acpi: consolidate \GPE._E02 with the rest of CPU hotplug AML
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 06/33] pc: acpi: consolidate \GPE._E02 with the rest of " Igor Mammedov
@ 2016-05-30 18:22   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:22 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   hw/acpi/cpu_hotplug_acpi_table.c | 4 ++++
>   hw/i386/acpi-build.c             | 4 ----
>   2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
> index 730f44c..c31f346 100644
> --- a/hw/acpi/cpu_hotplug_acpi_table.c
> +++ b/hw/acpi/cpu_hotplug_acpi_table.c
> @@ -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);
>   }
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 822230f..63e2723 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
>

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 07/33] pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c
  2016-05-17 14:42 ` [Qemu-devel] [PATCH 07/33] pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c Igor Mammedov
@ 2016-05-30 18:23   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:23 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> 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 <imammedo@redhat.com>
> ---
>   hw/acpi/cpu_hotplug_acpi_table.c | 7 +++++++
>   include/hw/acpi/cpu_hotplug.h    | 7 -------
>   2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
> index c31f346..9fdde6d 100644
> --- a/hw/acpi/cpu_hotplug_acpi_table.c
> +++ b/hw/acpi/cpu_hotplug_acpi_table.c
> @@ -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)
>   {
> diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> index 9b1d0cf..565f96c 100644
> --- a/include/hw/acpi/cpu_hotplug.h
> +++ b/include/hw/acpi/cpu_hotplug.h
> @@ -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
>

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 08/33] pc: acpi: mark current CPU hotplug functions as legacy
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 08/33] pc: acpi: mark current CPU hotplug functions as legacy Igor Mammedov
@ 2016-05-30 18:28   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:28 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   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(-)
>
> diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> index 4d86743..ba9d903 100644
> --- a/hw/acpi/cpu_hotplug.c
> +++ b/hw/acpi/cpu_hotplug.c
> @@ -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;
>
> diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
> index 9fdde6d..fc79c54 100644
> --- a/hw/acpi/cpu_hotplug_acpi_table.c
> +++ b/hw/acpi/cpu_hotplug_acpi_table.c
> @@ -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;
> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> index 27e978f..af340d0 100644
> --- a/hw/acpi/ich9.c
> +++ b/hw/acpi/ich9.c
> @@ -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)));
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index 16abdf1..3e8d80b 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -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);
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 63e2723..2f6de43 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
>
> diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> index 565f96c..241b50f 100644
> --- a/include/hw/acpi/cpu_hotplug.h
> +++ b/include/hw/acpi/cpu_hotplug.h
> @@ -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
>


Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 09/33] pc: acpi: consolidate legacy CPU hotplug in one file
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 09/33] pc: acpi: consolidate legacy CPU hotplug in one file Igor Mammedov
@ 2016-05-30 18:31   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:31 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> Since 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
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   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
>
> diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> index faee86c..66bd727 100644
> --- a/hw/acpi/Makefile.objs
> +++ b/hw/acpi/Makefile.objs
> @@ -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
> diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> index ba9d903..2d4e034 100644
> --- a/hw/acpi/cpu_hotplug.c
> +++ b/hw/acpi/cpu_hotplug.c
> @@ -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);
> +}
> diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
> deleted file mode 100644
> index fc79c54..0000000
> --- a/hw/acpi/cpu_hotplug_acpi_table.c
> +++ /dev/null
> @@ -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;
> -    }
> -    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);
> -}
>

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 10/33] pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 10/33] pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature Igor Mammedov
@ 2016-05-30 18:31   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:31 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> since 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.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   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(-)
>
> diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> index 2d4e034..36ea6c2 100644
> --- a/hw/acpi/cpu_hotplug.c
> +++ b/hw/acpi/cpu_hotplug.c
> @@ -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);
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 2f6de43..b33fec9 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
>
> diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> index 241b50f..6d729d8 100644
> --- a/include/hw/acpi/cpu_hotplug.h
> +++ b/include/hw/acpi/cpu_hotplug.h
> @@ -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
>


Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx Igor Mammedov
@ 2016-05-30 18:39   ` Marcel Apfelbaum
  2016-05-31 13:03     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:39 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> 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 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.
>

I vaguely understood the explanation, I'll let Eduardo have a look :)

Thanks,
Marcel

> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   hw/acpi/cpu_hotplug.c | 23 +++++++++++++----------
>   hw/i386/acpi-build.c  |  2 +-
>   2 files changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> index 36ea6c2..9d71d2f 100644
> --- a/hw/acpi/cpu_hotplug.c
> +++ b/hw/acpi/cpu_hotplug.c
> @@ -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;
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index b33fec9..768918f 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 13/33] acpi: extend ACPI interface to provide send_event hook
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 13/33] acpi: extend ACPI interface to provide send_event hook Igor Mammedov
@ 2016-05-30 18:45   ` Marcel Apfelbaum
  2016-05-31  9:57     ` [Qemu-devel] [PATCH v2 " Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:45 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> 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 call acpi_foo() API directly.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> 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(-)
>
> diff --git a/hw/acpi/core.c b/hw/acpi/core.c
> index 6a2f452..d05844b 100644
> --- a/hw/acpi/core.c
> +++ b/hw/acpi/core.c
> @@ -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);
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index 3e8d80b..4f5658f 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -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 = {
> diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
> index 99cd3ba..305ccd6 100644
> --- a/hw/isa/lpc_ich9.c
> +++ b/hw/isa/lpc_ich9.c
> @@ -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 = {
> diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> index e0978c8..24dd572 100644
> --- a/include/hw/acpi/acpi.h
> +++ b/include/hw/acpi/acpi.h
> @@ -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);
>
> diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
> index f245f8d..fdfc163 100644
> --- a/include/hw/acpi/acpi_dev_interface.h
> +++ b/include/hw/acpi/acpi_dev_interface.h
> @@ -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)
> +

Does it have to be a macro? I would prefer a function if is possible.

Thanks,
Marcel

>   /**
>    * 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
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug Igor Mammedov
@ 2016-05-30 18:50   ` Marcel Apfelbaum
  2016-05-31 13:24     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:50 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Maybe it worth adding some kind of explanation
of the functionality added here.

Thanks,
Marcel

> ---
> 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
>
> diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> index 66bd727..f200419 100644
> --- a/hw/acpi/Makefile.objs
> +++ b/hw/acpi/Makefile.objs
> @@ -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
> diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> new file mode 100644
> index 0000000..171a5f5
> --- /dev/null
> +++ b/hw/acpi/cpu.c
> @@ -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()
> +    }
> +};
> diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
> new file mode 100644
> index 0000000..3fdf4eb
> --- /dev/null
> +++ b/include/hw/acpi/cpu.h
> @@ -0,0 +1,52 @@
> +/*
> + * QEMU ACPI hotplug utilities
> + *
> + * Copyright (C) 2016 Red Hat Inc
> + *
> + * Authors:
> + *   Igor Mammedov <imammedo@redhat.com>
> + *
> + * 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
> diff --git a/trace-events b/trace-events
> index 4fce005..7101ba9 100644
> --- a/trace-events
> +++ b/trace-events
> @@ -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
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine Igor Mammedov
@ 2016-05-30 18:53   ` Marcel Apfelbaum
  2016-05-30 19:04     ` Eduardo Habkost
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:53 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>


Eduardo also posted a patch for 2.7 machine.

Thanks,
Marcel

> ---
>   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(-)
>
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 7f50116..cdbdd69 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -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);
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 04aae89..4787df1 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -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);
> diff --git a/include/hw/compat.h b/include/hw/compat.h
> index a5dbbf8..636befe 100644
> --- a/include/hw/compat.h
> +++ b/include/hw/compat.h
> @@ -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",\
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index 96f0b66..f1e40ae 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -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 \
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 19/33] pc: piix4/ich9: add 'cpu-hotplug-legacy' property
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 19/33] pc: piix4/ich9: add 'cpu-hotplug-legacy' property Igor Mammedov
@ 2016-05-30 18:59   ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 18:59 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   hw/acpi/ich9.c         | 29 ++++++++++++++++++++++++++---
>   hw/acpi/piix4.c        | 12 +++++++++---
>   include/hw/acpi/ich9.h |  1 +
>   3 files changed, 36 insertions(+), 6 deletions(-)
>
> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> index 853c9c4..121e30c 100644
> --- a/hw/acpi/ich9.c
> +++ b/hw/acpi/ich9.c
> @@ -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"
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index c66d3ed..d25479c 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -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(),
>   };
>
> diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> index bbd657c..e29a856 100644
> --- a/include/hw/acpi/ich9.h
> +++ b/include/hw/acpi/ich9.h
> @@ -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.

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>


Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw Igor Mammedov
@ 2016-05-30 19:02   ` Marcel Apfelbaum
  2016-05-31 10:06     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-30 19:02 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst, rkrcmar, ehabkost, drjones, armbru

On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> 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 <imammedo@redhat.com>
> ---
> 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(-)
>
> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> index 121e30c..b0285b9 100644
> --- a/hw/acpi/ich9.c
> +++ b/hw/acpi/ich9.c
> @@ -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;

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

>       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)));
> diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> index e29a856..198c017 100644
> --- a/include/hw/acpi/ich9.h
> +++ b/include/hw/acpi/ich9.h
> @@ -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;
>
> diff --git a/include/hw/compat.h b/include/hw/compat.h
> index 636befe..a65d9d2 100644
> --- a/include/hw/compat.h
> +++ b/include/hw/compat.h
> @@ -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 \
>       {\
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine
  2016-05-30 18:53   ` Marcel Apfelbaum
@ 2016-05-30 19:04     ` Eduardo Habkost
  0 siblings, 0 replies; 83+ messages in thread
From: Eduardo Habkost @ 2016-05-30 19:04 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: Igor Mammedov, qemu-devel, mst, rkrcmar, drjones, armbru

On Mon, May 30, 2016 at 09:53:59PM +0300, Marcel Apfelbaum wrote:
> On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> 
> Eduardo also posted a patch for 2.7 machine.

It was the same patch, with a "From:" line from Igor.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods to DSDT
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods " Igor Mammedov
@ 2016-05-31  4:38   ` Michael S. Tsirkin
  2016-05-31  8:45     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Michael S. Tsirkin @ 2016-05-31  4:38 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, rkrcmar, ehabkost, drjones, armbru, marcel

On Tue, May 17, 2016 at 04:43:16PM +0200, Igor Mammedov wrote:
> Add necessary CPU hotplug methods to handle hotplug
> events.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> 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(-)
> 
> diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> index b3e1cca..28d3894 100644
> --- a/hw/acpi/cpu.c
> +++ b/hw/acpi/cpu.c
> @@ -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++) {

wow that will be a ton of acpi code. why not create an AML loop?

> +            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);
>  }
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 47d4182..c62c020 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
> diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
> index ca32e07..0346f24 100644
> --- a/include/hw/acpi/cpu.h
> +++ b/include/hw/acpi/cpu.h
> @@ -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) \
> -- 
> 1.8.3.1

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol Igor Mammedov
@ 2016-05-31  4:49   ` Michael S. Tsirkin
  2016-05-31 15:07     ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Michael S. Tsirkin @ 2016-05-31  4:49 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, rkrcmar, ehabkost, drjones, armbru, marcel

On Tue, May 17, 2016 at 04:43:07PM +0200, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------
>  1 file changed, 76 insertions(+), 12 deletions(-)
> 
> diff --git a/docs/specs/acpi_cpu_hotplug.txt b/docs/specs/acpi_cpu_hotplug.txt
> index 340b751..c5bce6a 100644
> --- a/docs/specs/acpi_cpu_hotplug.txt
> +++ b/docs/specs/acpi_cpu_hotplug.txt
> @@ -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

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.


> +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.


> +    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.

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.

> +    [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.

why not 0?

> -- 
> 1.8.3.1

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
  2016-05-30 18:18   ` Marcel Apfelbaum
@ 2016-05-31  7:50     ` Igor Mammedov
  2016-05-31 10:18       ` Marcel Apfelbaum
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31  7:50 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, armbru, drjones, rkrcmar, ehabkost, mst

On Mon, 30 May 2016 21:18:59 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/17/2016 05:42 PM, Igor Mammedov wrote:
> > 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:
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.

> 
> Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
> 
> Thanks,
> Marcel
> 
> 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >   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(-)
> >
> > diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
> > index 97bb109..730f44c 100644
> > --- a/hw/acpi/cpu_hotplug_acpi_table.c
> > +++ b/hw/acpi/cpu_hotplug_acpi_table.c
> > @@ -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);
> >   }
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index ff98ad8..822230f 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -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);
> >
> > diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> > index f22640e..9b1d0cf 100644
> > --- a/include/hw/acpi/cpu_hotplug.h
> > +++ b/include/hw/acpi/cpu_hotplug.h
> > @@ -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
> >  
> 
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods to DSDT
  2016-05-31  4:38   ` Michael S. Tsirkin
@ 2016-05-31  8:45     ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31  8:45 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel, rkrcmar, ehabkost, drjones, armbru, marcel

On Tue, 31 May 2016 07:38:08 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, May 17, 2016 at 04:43:16PM +0200, Igor Mammedov wrote:
> > Add necessary CPU hotplug methods to handle hotplug
> > events.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > 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(-)
> > 
> > diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> > index b3e1cca..28d3894 100644
> > --- a/hw/acpi/cpu.c
> > +++ b/hw/acpi/cpu.c
> > @@ -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++) {  
> 
> 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.

 
> > +            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);
> >  }
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index 47d4182..c62c020 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -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);
> > diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
> > index ca32e07..0346f24 100644
> > --- a/include/hw/acpi/cpu.h
> > +++ b/include/hw/acpi/cpu.h
> > @@ -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) \
> > -- 
> > 1.8.3.1  

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH v2 13/33] acpi: extend ACPI interface to provide send_event hook
  2016-05-30 18:45   ` Marcel Apfelbaum
@ 2016-05-31  9:57     ` Igor Mammedov
  2016-06-02 11:09       ` Marcel Apfelbaum
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31  9:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, marcel

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 call acpi_foo() API directly.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
Following patch will use hook to simplify hotplug callbacks
in piix4pm/ich9.

v2:
 -  make ACPI_SEND_EVENT macro a function
       Marcel Apfelbaum <marcel@redhat.com>
---
 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(-)

diff --git a/hw/acpi/acpi_interface.c b/hw/acpi/acpi_interface.c
index d821313..6583917 100644
--- a/hw/acpi/acpi_interface.c
+++ b/hw/acpi/acpi_interface.c
@@ -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 = {
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 1ffd155..d24b9a9 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -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);
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 522c9a8..5b4fcb5 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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 = {
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 4f8ca45..72d0781 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -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 = {
diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
index dc6ee00..c717f15 100644
--- a/include/hw/acpi/acpi.h
+++ b/include/hw/acpi/acpi.h
@@ -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);
 
diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
index f245f8d..a0c4a33 100644
--- a/include/hw/acpi/acpi_dev_interface.h
+++ b/include/hw/acpi/acpi_dev_interface.h
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [Qemu-devel] [PATCH v2 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events
  2016-05-17 14:43 ` [Qemu-devel] [PATCH 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events Igor Mammedov
@ 2016-05-31 10:01   ` Igor Mammedov
  2016-06-02 11:13     ` Marcel Apfelbaum
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 10:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, marcel

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_event callback
to trigger events usiong GPIO instead of GPE
as fixed hadrware ACPI model doen't have GPE at all.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
 -  make ACPI_SEND_EVENT macro a function
       Marcel Apfelbaum <marcel@redhat.com>
---
 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(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 9d71d2f..fe75bd9 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -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,
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index af340d0..853c9c4 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -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)));
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index f65a3a2..ec4e64b 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -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,
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 71f4c4e..d957d1e 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -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)
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 5b4fcb5..c48cb1b 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -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"
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 72d0781..2a2d52e 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -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;
 }
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 6d729d8..6fef67e 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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,
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 63fa198..bbd657c 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -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);
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 3a646b1..d2c7452 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -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,
diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
index 79a4392..04528b7 100644
--- a/include/hw/acpi/pcihp.h
+++ b/include/hw/acpi/pcihp.h
@@ -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 */
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers
  2016-05-25 13:19     ` Igor Mammedov
@ 2016-05-31 10:06       ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-31 10:06 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, mst, rkrcmar, ehabkost, drjones, armbru

On 05/25/2016 04:19 PM, Igor Mammedov wrote:
> On Wed, 25 May 2016 12:11:33 +0300
> Marcel Apfelbaum <marcel@redhat.com> wrote:
>
>> On 05/17/2016 05:42 PM, Igor Mammedov wrote:
>>> 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 <imammedo@redhat.com>
>>> ---
>>>    hw/i386/acpi-build.c | 17 -----------------
>>>    1 file changed, 17 deletions(-)
>>>
>>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>>> index 279f0d7..ff98ad8 100644
>>> --- a/hw/i386/acpi-build.c
>>> +++ b/hw/i386/acpi-build.c
>>> @@ -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);
>>>
>>>
>>
>>
>> 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
>

Sure,

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

>> Thanks,
>> Marcel
>>
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
  2016-05-30 19:02   ` Marcel Apfelbaum
@ 2016-05-31 10:06     ` Igor Mammedov
  2016-05-31 10:21       ` Marcel Apfelbaum
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 10:06 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, mst, rkrcmar, ehabkost, drjones, armbru

On Mon, 30 May 2016 22:02:31 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> > 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 <imammedo@redhat.com>
> > ---
> > 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(-)
> >
> > diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> > index 121e30c..b0285b9 100644
> > --- a/hw/acpi/ich9.c
> > +++ b/hw/acpi/ich9.c
> > @@ -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;  
> 
> 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.

>
> Thanks,
> Marcel
> 
> >       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)));
> > diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> > index e29a856..198c017 100644
> > --- a/include/hw/acpi/ich9.h
> > +++ b/include/hw/acpi/ich9.h
> > @@ -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;
> >
> > diff --git a/include/hw/compat.h b/include/hw/compat.h
> > index 636befe..a65d9d2 100644
> > --- a/include/hw/compat.h
> > +++ b/include/hw/compat.h
> > @@ -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 \
> >       {\
> >  
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
  2016-05-31  7:50     ` Igor Mammedov
@ 2016-05-31 10:18       ` Marcel Apfelbaum
  2016-05-31 12:49         ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-31 10:18 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, armbru, drjones, rkrcmar, ehabkost, mst

On 05/31/2016 10:50 AM, Igor Mammedov wrote:
> On Mon, 30 May 2016 21:18:59 +0300
> Marcel Apfelbaum <marcel@redhat.com> wrote:
>
>> On 05/17/2016 05:42 PM, Igor Mammedov wrote:
>>> 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:
> 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.


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

> For new hotplug it's even necessary so that it would be easy to share
> with ARM target.
>


>>
>> Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
>>
>> Thanks,
>> Marcel
>>
>>
>>> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
>>> ---
>>>    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(-)
>>>
>>> diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
>>> index 97bb109..730f44c 100644
>>> --- a/hw/acpi/cpu_hotplug_acpi_table.c
>>> +++ b/hw/acpi/cpu_hotplug_acpi_table.c
>>> @@ -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);
>>>    }
>>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>>> index ff98ad8..822230f 100644
>>> --- a/hw/i386/acpi-build.c
>>> +++ b/hw/i386/acpi-build.c
>>> @@ -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);
>>>
>>> diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
>>> index f22640e..9b1d0cf 100644
>>> --- a/include/hw/acpi/cpu_hotplug.h
>>> +++ b/include/hw/acpi/cpu_hotplug.h
>>> @@ -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
>>>
>>
>>
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
  2016-05-31 10:06     ` Igor Mammedov
@ 2016-05-31 10:21       ` Marcel Apfelbaum
  2016-05-31 12:51         ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-05-31 10:21 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, mst, rkrcmar, ehabkost, drjones, armbru

On 05/31/2016 01:06 PM, Igor Mammedov wrote:
> On Mon, 30 May 2016 22:02:31 +0300
> Marcel Apfelbaum <marcel@redhat.com> wrote:
>
>> On 05/17/2016 05:43 PM, Igor Mammedov wrote:
>>> 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 <imammedo@redhat.com>
>>> ---
>>> 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(-)
>>>
>>> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
>>> index 121e30c..b0285b9 100644
>>> --- a/hw/acpi/ich9.c
>>> +++ b/hw/acpi/ich9.c
>>> @@ -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;
>>
>> 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.
>

Exactly, I would move the "enabling" code after the new hotplug mechanism
is functional. The same for the next patch for piix4.

Thanks,
Marcel


>>
>> Thanks,
>> Marcel
>>
>>>        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)));
>>> diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
>>> index e29a856..198c017 100644
>>> --- a/include/hw/acpi/ich9.h
>>> +++ b/include/hw/acpi/ich9.h
>>> @@ -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;
>>>
>>> diff --git a/include/hw/compat.h b/include/hw/compat.h
>>> index 636befe..a65d9d2 100644
>>> --- a/include/hw/compat.h
>>> +++ b/include/hw/compat.h
>>> @@ -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 \
>>>        {\
>>>
>>
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML
  2016-05-31 10:18       ` Marcel Apfelbaum
@ 2016-05-31 12:49         ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 12:49 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: drjones, ehabkost, rkrcmar, mst, qemu-devel, armbru

On Tue, 31 May 2016 13:18:44 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/31/2016 10:50 AM, Igor Mammedov wrote:
> > On Mon, 30 May 2016 21:18:59 +0300
> > Marcel Apfelbaum <marcel@redhat.com> wrote:
> >  
> >> On 05/17/2016 05:42 PM, Igor Mammedov wrote:  
> >>> 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:  
> > 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.  
> 
> 
> 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!

> 
> Thanks,
> Marcel
> 
> > For new hotplug it's even necessary so that it would be easy to share
> > with ARM target.
> >  
> 
> 
> >>
> >> Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
> >>
> >> Thanks,
> >> Marcel
> >>
> >>  
> >>> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> >>> ---
> >>>    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(-)
> >>>
> >>> diff --git a/hw/acpi/cpu_hotplug_acpi_table.c b/hw/acpi/cpu_hotplug_acpi_table.c
> >>> index 97bb109..730f44c 100644
> >>> --- a/hw/acpi/cpu_hotplug_acpi_table.c
> >>> +++ b/hw/acpi/cpu_hotplug_acpi_table.c
> >>> @@ -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);
> >>>    }
> >>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> >>> index ff98ad8..822230f 100644
> >>> --- a/hw/i386/acpi-build.c
> >>> +++ b/hw/i386/acpi-build.c
> >>> @@ -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);
> >>>
> >>> diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> >>> index f22640e..9b1d0cf 100644
> >>> --- a/include/hw/acpi/cpu_hotplug.h
> >>> +++ b/include/hw/acpi/cpu_hotplug.h
> >>> @@ -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
> >>>  
> >>
> >>  
> >  
> 
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
  2016-05-31 10:21       ` Marcel Apfelbaum
@ 2016-05-31 12:51         ` Igor Mammedov
  2016-05-31 12:52           ` Michael S. Tsirkin
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 12:51 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, mst, rkrcmar, ehabkost, drjones, armbru

On Tue, 31 May 2016 13:21:20 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/31/2016 01:06 PM, Igor Mammedov wrote:
> > On Mon, 30 May 2016 22:02:31 +0300
> > Marcel Apfelbaum <marcel@redhat.com> wrote:
> >  
> >> On 05/17/2016 05:43 PM, Igor Mammedov wrote:  
> >>> 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 <imammedo@redhat.com>
> >>> ---
> >>> 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(-)
> >>>
> >>> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> >>> index 121e30c..b0285b9 100644
> >>> --- a/hw/acpi/ich9.c
> >>> +++ b/hw/acpi/ich9.c
> >>> @@ -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;  
> >>
> >> 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.
> >  
> 
> 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.

> 
> Thanks,
> Marcel
> 
> 
> >>
> >> Thanks,
> >> Marcel
> >>  
> >>>        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)));
> >>> diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> >>> index e29a856..198c017 100644
> >>> --- a/include/hw/acpi/ich9.h
> >>> +++ b/include/hw/acpi/ich9.h
> >>> @@ -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;
> >>>
> >>> diff --git a/include/hw/compat.h b/include/hw/compat.h
> >>> index 636befe..a65d9d2 100644
> >>> --- a/include/hw/compat.h
> >>> +++ b/include/hw/compat.h
> >>> @@ -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 \
> >>>        {\
> >>>  
> >>  
> >  
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
  2016-05-31 12:51         ` Igor Mammedov
@ 2016-05-31 12:52           ` Michael S. Tsirkin
  2016-05-31 13:18             ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Michael S. Tsirkin @ 2016-05-31 12:52 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Marcel Apfelbaum, qemu-devel, rkrcmar, ehabkost, drjones, armbru

On Tue, May 31, 2016 at 02:51:03PM +0200, Igor Mammedov wrote:
> On Tue, 31 May 2016 13:21:20 +0300
> Marcel Apfelbaum <marcel@redhat.com> wrote:
> 
> > On 05/31/2016 01:06 PM, Igor Mammedov wrote:
> > > On Mon, 30 May 2016 22:02:31 +0300
> > > Marcel Apfelbaum <marcel@redhat.com> wrote:
> > >  
> > >> On 05/17/2016 05:43 PM, Igor Mammedov wrote:  
> > >>> 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 <imammedo@redhat.com>
> > >>> ---
> > >>> 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(-)
> > >>>
> > >>> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> > >>> index 121e30c..b0285b9 100644
> > >>> --- a/hw/acpi/ich9.c
> > >>> +++ b/hw/acpi/ich9.c
> > >>> @@ -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;  
> > >>
> > >> 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.
> > >  
> > 
> > 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?

> > 
> > Thanks,
> > Marcel
> > 
> > 
> > >>
> > >> Thanks,
> > >> Marcel
> > >>  
> > >>>        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)));
> > >>> diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> > >>> index e29a856..198c017 100644
> > >>> --- a/include/hw/acpi/ich9.h
> > >>> +++ b/include/hw/acpi/ich9.h
> > >>> @@ -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;
> > >>>
> > >>> diff --git a/include/hw/compat.h b/include/hw/compat.h
> > >>> index 636befe..a65d9d2 100644
> > >>> --- a/include/hw/compat.h
> > >>> +++ b/include/hw/compat.h
> > >>> @@ -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 \
> > >>>        {\
> > >>>  
> > >>  
> > >  
> > 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling
  2016-05-30 18:21       ` Michael S. Tsirkin
@ 2016-05-31 12:53         ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 12:53 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Eric Blake, drjones, ehabkost, rkrcmar, armbru, qemu-devel, marcel

On Mon, 30 May 2016 21:21:39 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Wed, May 18, 2016 at 10:09:27AM +0200, Igor Mammedov wrote:
> > On Tue, 17 May 2016 09:29:15 -0600
> > Eric Blake <eblake@redhat.com> wrote:
> >   
> > > On 05/17/2016 08:43 AM, Igor Mammedov wrote:  
> > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > ---
> > > >  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
> > > > @@ -4018,8 +4018,9 @@
> > > >  ## @ACPISlotType
> > > >  #
> > > >  # @DIMM: memory slot
> > > > +# @CPU: logical CPU slot    
> > > 
> > > Missing a marker '(since 2.7)'  
> > thanks, fixed in v2.  
> 
> v2 was never posted.
it will be included when I post v2
(after this review pass is complete)

> 
> > > >  #
> > > > -{ '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.
> >   

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx
  2016-05-30 18:39   ` Marcel Apfelbaum
@ 2016-05-31 13:03     ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 13:03 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, mst, rkrcmar, ehabkost, drjones, armbru

On Mon, 30 May 2016 21:39:50 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> > 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 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.
> >  
> 
> 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).

> 
> Thanks,
> Marcel
> 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >   hw/acpi/cpu_hotplug.c | 23 +++++++++++++----------
> >   hw/i386/acpi-build.c  |  2 +-
> >   2 files changed, 14 insertions(+), 11 deletions(-)
> >
> > diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> > index 36ea6c2..9d71d2f 100644
> > --- a/hw/acpi/cpu_hotplug.c
> > +++ b/hw/acpi/cpu_hotplug.c
> > @@ -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;
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index b33fec9..768918f 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -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);
> >  
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw
  2016-05-31 12:52           ` Michael S. Tsirkin
@ 2016-05-31 13:18             ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 13:18 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Marcel Apfelbaum, qemu-devel, rkrcmar, ehabkost, drjones, armbru

On Tue, 31 May 2016 15:52:35 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, May 31, 2016 at 02:51:03PM +0200, Igor Mammedov wrote:
> > On Tue, 31 May 2016 13:21:20 +0300
> > Marcel Apfelbaum <marcel@redhat.com> wrote:
> >   
> > > On 05/31/2016 01:06 PM, Igor Mammedov wrote:  
> > > > On Mon, 30 May 2016 22:02:31 +0300
> > > > Marcel Apfelbaum <marcel@redhat.com> wrote:
> > > >    
> > > >> On 05/17/2016 05:43 PM, Igor Mammedov wrote:    
> > > >>> 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 <imammedo@redhat.com>
> > > >>> ---
> > > >>> 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(-)
> > > >>>
> > > >>> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> > > >>> index 121e30c..b0285b9 100644
> > > >>> --- a/hw/acpi/ich9.c
> > > >>> +++ b/hw/acpi/ich9.c
> > > >>> @@ -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;    
> > > >>
> > > >> 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.
> > > >    
> > > 
> > > 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.

> 
> > > 
> > > Thanks,
> > > Marcel
> > > 
> > >   
> > > >>
> > > >> Thanks,
> > > >> Marcel
> > > >>    
> > > >>>        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)));
> > > >>> diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> > > >>> index e29a856..198c017 100644
> > > >>> --- a/include/hw/acpi/ich9.h
> > > >>> +++ b/include/hw/acpi/ich9.h
> > > >>> @@ -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;
> > > >>>
> > > >>> diff --git a/include/hw/compat.h b/include/hw/compat.h
> > > >>> index 636befe..a65d9d2 100644
> > > >>> --- a/include/hw/compat.h
> > > >>> +++ b/include/hw/compat.h
> > > >>> @@ -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 \
> > > >>>        {\
> > > >>>    
> > > >>    
> > > >    
> > >   

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug
  2016-05-30 18:50   ` Marcel Apfelbaum
@ 2016-05-31 13:24     ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 13:24 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, armbru, drjones, rkrcmar, ehabkost, mst

On Mon, 30 May 2016 21:50:08 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/17/2016 05:43 PM, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>  
> 
> Maybe it worth adding some kind of explanation
> of the functionality added here.
I'll add a bit more detailed explanation here

> Thanks,
> Marcel
> 
> > ---
> > 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
> >
> > diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> > index 66bd727..f200419 100644
> > --- a/hw/acpi/Makefile.objs
> > +++ b/hw/acpi/Makefile.objs
> > @@ -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
> > diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> > new file mode 100644
> > index 0000000..171a5f5
> > --- /dev/null
> > +++ b/hw/acpi/cpu.c
> > @@ -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()
> > +    }
> > +};
> > diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
> > new file mode 100644
> > index 0000000..3fdf4eb
> > --- /dev/null
> > +++ b/include/hw/acpi/cpu.h
> > @@ -0,0 +1,52 @@
> > +/*
> > + * QEMU ACPI hotplug utilities
> > + *
> > + * Copyright (C) 2016 Red Hat Inc
> > + *
> > + * Authors:
> > + *   Igor Mammedov <imammedo@redhat.com>
> > + *
> > + * 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
> > diff --git a/trace-events b/trace-events
> > index 4fce005..7101ba9 100644
> > --- a/trace-events
> > +++ b/trace-events
> > @@ -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
> >  
> 
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
  2016-05-31  4:49   ` Michael S. Tsirkin
@ 2016-05-31 15:07     ` Igor Mammedov
  2016-05-31 21:09       ` Michael S. Tsirkin
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-05-31 15:07 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: drjones, ehabkost, rkrcmar, armbru, qemu-devel, marcel

On Tue, 31 May 2016 07:49:16 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, May 17, 2016 at 04:43:07PM +0200, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------
> >  1 file changed, 76 insertions(+), 12 deletions(-)
> > 
> > diff --git a/docs/specs/acpi_cpu_hotplug.txt b/docs/specs/acpi_cpu_hotplug.txt
> > index 340b751..c5bce6a 100644
> > --- a/docs/specs/acpi_cpu_hotplug.txt
> > +++ b/docs/specs/acpi_cpu_hotplug.txt
> > @@ -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  
> 
> 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.


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.

> > +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).

> > +    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.  
> 
> 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.

> 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.

> 
> > +    [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.  
> 
> 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.

> 
> > -- 
> > 1.8.3.1  
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
  2016-05-31 15:07     ` Igor Mammedov
@ 2016-05-31 21:09       ` Michael S. Tsirkin
  2016-06-06  9:57         ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Michael S. Tsirkin @ 2016-05-31 21:09 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: drjones, ehabkost, rkrcmar, armbru, qemu-devel, marcel

On Tue, May 31, 2016 at 05:07:41PM +0200, Igor Mammedov wrote:
> On Tue, 31 May 2016 07:49:16 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Tue, May 17, 2016 at 04:43:07PM +0200, Igor Mammedov wrote:
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > >  docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------
> > >  1 file changed, 76 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/docs/specs/acpi_cpu_hotplug.txt b/docs/specs/acpi_cpu_hotplug.txt
> > > index 340b751..c5bce6a 100644
> > > --- a/docs/specs/acpi_cpu_hotplug.txt
> > > +++ b/docs/specs/acpi_cpu_hotplug.txt
> > > @@ -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  
> > 
> > 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.
> 
> 
> 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.

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.


> > > +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.

Interesting. Which ones? Would they be easy to detect?

> 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).
> 
> > > +    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.  
> > 
> > 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.

Right. But now you are removing them for >255 CPUs
anyway.

> 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?

> > 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?

> > 
> > > +    [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.  
> > 
> > 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)

PCI does but it's special.

> 
> that's what has been done for memory hotplug, so I'm doing the same here.
> 
> > 
> > > -- 
> > > 1.8.3.1  
> > 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/33] tests: acpi: report names of expected files in verbose mode
  2016-05-26  9:46     ` [Qemu-devel] [PATCH v2 1/33] " Igor Mammedov
  2016-05-30 18:14       ` Marcel Apfelbaum
@ 2016-06-02 11:02       ` Marcel Apfelbaum
  1 sibling, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-06-02 11:02 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst

On 05/26/2016 12:46 PM, Igor Mammedov wrote:
> 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 set
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   v2: replace 'for' loop with more readble 'goto'
>       Marcel Apfelbaum <marcel@redhat.com>
> ---
>   tests/bios-tables-test.c | 18 +++++++++++++-----
>   1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
> index 0352814..f0493f8 100644
> --- a/tests/bios-tables-test.c
> +++ b/tests/bios-tables-test.c
> @@ -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 */

:s/extention/extension

>               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);
>


Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH v2 13/33] acpi: extend ACPI interface to provide send_event hook
  2016-05-31  9:57     ` [Qemu-devel] [PATCH v2 " Igor Mammedov
@ 2016-06-02 11:09       ` Marcel Apfelbaum
  2016-06-02 11:19         ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-06-02 11:09 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst

On 05/31/2016 12:57 PM, Igor Mammedov wrote:
> 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 call acpi_foo() API directly.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> Following patch will use hook to simplify hotplug callbacks
> in piix4pm/ich9.
>
> v2:
>   -  make ACPI_SEND_EVENT macro a function
>         Marcel Apfelbaum <marcel@redhat.com>
> ---
>   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(-)
>
> diff --git a/hw/acpi/acpi_interface.c b/hw/acpi/acpi_interface.c
> index d821313..6583917 100644
> --- a/hw/acpi/acpi_interface.c
> +++ b/hw/acpi/acpi_interface.c
> @@ -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


> +    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 = {
> diff --git a/hw/acpi/core.c b/hw/acpi/core.c
> index 1ffd155..d24b9a9 100644
> --- a/hw/acpi/core.c
> +++ b/hw/acpi/core.c
> @@ -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);
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index 522c9a8..5b4fcb5 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -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 = {
> diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
> index 4f8ca45..72d0781 100644
> --- a/hw/isa/lpc_ich9.c
> +++ b/hw/isa/lpc_ich9.c
> @@ -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 = {
> diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> index dc6ee00..c717f15 100644
> --- a/include/hw/acpi/acpi.h
> +++ b/include/hw/acpi/acpi.h
> @@ -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);
>
> diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
> index f245f8d..a0c4a33 100644
> --- a/include/hw/acpi/acpi_dev_interface.h
> +++ b/include/hw/acpi/acpi_dev_interface.h
> @@ -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
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH v2 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events
  2016-05-31 10:01   ` [Qemu-devel] [PATCH v2 " Igor Mammedov
@ 2016-06-02 11:13     ` Marcel Apfelbaum
  2016-06-02 11:29       ` Igor Mammedov
  0 siblings, 1 reply; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-06-02 11:13 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: mst

On 05/31/2016 01:01 PM, Igor Mammedov wrote:
> 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_event callback
> to trigger events usiong GPIO instead of GPE
> as fixed hadrware ACPI model doen't have GPE at all.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v2:
>   -  make ACPI_SEND_EVENT macro a function
>         Marcel Apfelbaum <marcel@redhat.com>
> ---
>   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(-)
>
> diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> index 9d71d2f..fe75bd9 100644
> --- a/hw/acpi/cpu_hotplug.c
> +++ b/hw/acpi/cpu_hotplug.c
> @@ -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);


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

>   }
>
>   void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> index af340d0..853c9c4 100644
> --- a/hw/acpi/ich9.c
> +++ b/hw/acpi/ich9.c
> @@ -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)));
> diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
> index f65a3a2..ec4e64b 100644
> --- a/hw/acpi/memory_hotplug.c
> +++ b/hw/acpi/memory_hotplug.c
> @@ -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,
> diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
> index 71f4c4e..d957d1e 100644
> --- a/hw/acpi/pcihp.c
> +++ b/hw/acpi/pcihp.c
> @@ -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)
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index 5b4fcb5..c48cb1b 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -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"
> diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
> index 72d0781..2a2d52e 100644
> --- a/hw/isa/lpc_ich9.c
> +++ b/hw/isa/lpc_ich9.c
> @@ -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;
>   }
> diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> index 6d729d8..6fef67e 100644
> --- a/include/hw/acpi/cpu_hotplug.h
> +++ b/include/hw/acpi/cpu_hotplug.h
> @@ -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,
> diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> index 63fa198..bbd657c 100644
> --- a/include/hw/acpi/ich9.h
> +++ b/include/hw/acpi/ich9.h
> @@ -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);
> diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
> index 3a646b1..d2c7452 100644
> --- a/include/hw/acpi/memory_hotplug.h
> +++ b/include/hw/acpi/memory_hotplug.h
> @@ -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,
> diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
> index 79a4392..04528b7 100644
> --- a/include/hw/acpi/pcihp.h
> +++ b/include/hw/acpi/pcihp.h
> @@ -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 */
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH v2 13/33] acpi: extend ACPI interface to provide send_event hook
  2016-06-02 11:09       ` Marcel Apfelbaum
@ 2016-06-02 11:19         ` Igor Mammedov
  2016-06-02 11:21           ` Marcel Apfelbaum
  0 siblings, 1 reply; 83+ messages in thread
From: Igor Mammedov @ 2016-06-02 11:19 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, mst

On Thu, 2 Jun 2016 14:09:12 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/31/2016 12:57 PM, Igor Mammedov wrote:
> > 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 call acpi_foo() API directly.
> >
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > Following patch will use hook to simplify hotplug callbacks
> > in piix4pm/ich9.
> >
> > v2:
> >   -  make ACPI_SEND_EVENT macro a function
> >         Marcel Apfelbaum <marcel@redhat.com>
> > ---
> >   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(-)
> >
> > diff --git a/hw/acpi/acpi_interface.c b/hw/acpi/acpi_interface.c
> > index d821313..6583917 100644
> > --- a/hw/acpi/acpi_interface.c
> > +++ b/hw/acpi/acpi_interface.c
> > @@ -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.
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.

> Thanks,
> Marcel
> 
> 
> > +    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 = {
> > diff --git a/hw/acpi/core.c b/hw/acpi/core.c
> > index 1ffd155..d24b9a9 100644
> > --- a/hw/acpi/core.c
> > +++ b/hw/acpi/core.c
> > @@ -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);
> > diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> > index 522c9a8..5b4fcb5 100644
> > --- a/hw/acpi/piix4.c
> > +++ b/hw/acpi/piix4.c
> > @@ -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 = {
> > diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
> > index 4f8ca45..72d0781 100644
> > --- a/hw/isa/lpc_ich9.c
> > +++ b/hw/isa/lpc_ich9.c
> > @@ -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 = {
> > diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> > index dc6ee00..c717f15 100644
> > --- a/include/hw/acpi/acpi.h
> > +++ b/include/hw/acpi/acpi.h
> > @@ -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);
> >
> > diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
> > index f245f8d..a0c4a33 100644
> > --- a/include/hw/acpi/acpi_dev_interface.h
> > +++ b/include/hw/acpi/acpi_dev_interface.h
> > @@ -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
> >  
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH v2 13/33] acpi: extend ACPI interface to provide send_event hook
  2016-06-02 11:19         ` Igor Mammedov
@ 2016-06-02 11:21           ` Marcel Apfelbaum
  0 siblings, 0 replies; 83+ messages in thread
From: Marcel Apfelbaum @ 2016-06-02 11:21 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, mst

On 06/02/2016 02:19 PM, Igor Mammedov wrote:
> On Thu, 2 Jun 2016 14:09:12 +0300
> Marcel Apfelbaum <marcel@redhat.com> wrote:
>
>> On 05/31/2016 12:57 PM, Igor Mammedov wrote:
>>> 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 call acpi_foo() API directly.
>>>
>>> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
>>> ---
>>> Following patch will use hook to simplify hotplug callbacks
>>> in piix4pm/ich9.
>>>
>>> v2:
>>>    -  make ACPI_SEND_EVENT macro a function
>>>          Marcel Apfelbaum <marcel@redhat.com>
>>> ---
>>>    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(-)
>>>
>>> diff --git a/hw/acpi/acpi_interface.c b/hw/acpi/acpi_interface.c
>>> index d821313..6583917 100644
>>> --- a/hw/acpi/acpi_interface.c
>>> +++ b/hw/acpi/acpi_interface.c
>>> @@ -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.
> 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.
>

OK

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>


Thanks,
Marcel

>> Thanks,
>> Marcel
>>
>>
>>> +    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 = {
>>> diff --git a/hw/acpi/core.c b/hw/acpi/core.c
>>> index 1ffd155..d24b9a9 100644
>>> --- a/hw/acpi/core.c
>>> +++ b/hw/acpi/core.c
>>> @@ -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);
>>> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
>>> index 522c9a8..5b4fcb5 100644
>>> --- a/hw/acpi/piix4.c
>>> +++ b/hw/acpi/piix4.c
>>> @@ -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 = {
>>> diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
>>> index 4f8ca45..72d0781 100644
>>> --- a/hw/isa/lpc_ich9.c
>>> +++ b/hw/isa/lpc_ich9.c
>>> @@ -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 = {
>>> diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
>>> index dc6ee00..c717f15 100644
>>> --- a/include/hw/acpi/acpi.h
>>> +++ b/include/hw/acpi/acpi.h
>>> @@ -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);
>>>
>>> diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h
>>> index f245f8d..a0c4a33 100644
>>> --- a/include/hw/acpi/acpi_dev_interface.h
>>> +++ b/include/hw/acpi/acpi_dev_interface.h
>>> @@ -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
>>>
>>
>

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH v2 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events
  2016-06-02 11:13     ` Marcel Apfelbaum
@ 2016-06-02 11:29       ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-06-02 11:29 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: qemu-devel, mst

On Thu, 2 Jun 2016 14:13:23 +0300
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 05/31/2016 01:01 PM, Igor Mammedov wrote:
> > 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_event callback
> > to trigger events usiong GPIO instead of GPE
> > as fixed hadrware ACPI model doen't have GPE at all.
> >
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > v2:
> >   -  make ACPI_SEND_EVENT macro a function
> >         Marcel Apfelbaum <marcel@redhat.com>
> > ---
> >   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(-)
> >
> > diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> > index 9d71d2f..fe75bd9 100644
> > --- a/hw/acpi/cpu_hotplug.c
> > +++ b/hw/acpi/cpu_hotplug.c
> > @@ -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);  
> 
> 
> 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
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.

> 
> Thanks,
> Marcel
> 
> >   }
> >
> >   void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
> > diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> > index af340d0..853c9c4 100644
> > --- a/hw/acpi/ich9.c
> > +++ b/hw/acpi/ich9.c
> > @@ -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)));
> > diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
> > index f65a3a2..ec4e64b 100644
> > --- a/hw/acpi/memory_hotplug.c
> > +++ b/hw/acpi/memory_hotplug.c
> > @@ -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,
> > diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
> > index 71f4c4e..d957d1e 100644
> > --- a/hw/acpi/pcihp.c
> > +++ b/hw/acpi/pcihp.c
> > @@ -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)
> > diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> > index 5b4fcb5..c48cb1b 100644
> > --- a/hw/acpi/piix4.c
> > +++ b/hw/acpi/piix4.c
> > @@ -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"
> > diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
> > index 72d0781..2a2d52e 100644
> > --- a/hw/isa/lpc_ich9.c
> > +++ b/hw/isa/lpc_ich9.c
> > @@ -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;
> >   }
> > diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
> > index 6d729d8..6fef67e 100644
> > --- a/include/hw/acpi/cpu_hotplug.h
> > +++ b/include/hw/acpi/cpu_hotplug.h
> > @@ -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,
> > diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
> > index 63fa198..bbd657c 100644
> > --- a/include/hw/acpi/ich9.h
> > +++ b/include/hw/acpi/ich9.h
> > @@ -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);
> > diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
> > index 3a646b1..d2c7452 100644
> > --- a/include/hw/acpi/memory_hotplug.h
> > +++ b/include/hw/acpi/memory_hotplug.h
> > @@ -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,
> > diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
> > index 79a4392..04528b7 100644
> > --- a/include/hw/acpi/pcihp.h
> > +++ b/include/hw/acpi/pcihp.h
> > @@ -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 */
> >  
> 

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol
  2016-05-31 21:09       ` Michael S. Tsirkin
@ 2016-06-06  9:57         ` Igor Mammedov
  0 siblings, 0 replies; 83+ messages in thread
From: Igor Mammedov @ 2016-06-06  9:57 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, ehabkost, rkrcmar, armbru, qemu-devel, marcel, Paolo Bonzini

On Wed, 1 Jun 2016 00:09:57 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, May 31, 2016 at 05:07:41PM +0200, Igor Mammedov wrote:
> > On Tue, 31 May 2016 07:49:16 +0300
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> >   
> > > On Tue, May 17, 2016 at 04:43:07PM +0200, Igor Mammedov wrote:  
> > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > ---
> > > >  docs/specs/acpi_cpu_hotplug.txt | 88 +++++++++++++++++++++++++++++++++++------
> > > >  1 file changed, 76 insertions(+), 12 deletions(-)
> > > > 
> > > > diff --git a/docs/specs/acpi_cpu_hotplug.txt b/docs/specs/acpi_cpu_hotplug.txt
> > > > index 340b751..c5bce6a 100644
> > > > --- a/docs/specs/acpi_cpu_hotplug.txt
> > > > +++ b/docs/specs/acpi_cpu_hotplug.txt
> > > > @@ -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    
> > > 
> > > 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.  
> > 
> > 
> > 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.  
> 
> 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?

> 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.


> > > > +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.  
> 
> 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?

> > 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).
> >   
> > > > +    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.    
> > > 
> > > 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.  
> 
> 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.

> > 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)

> > > 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.

> 
> > >   
> > > > +    [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.    
> > > 
> > > 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)  
> 
> 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.

> 
> > 
> > that's what has been done for memory hotplug, so I'm doing the same here.
> >   
> > >   
> > > > -- 
> > > > 1.8.3.1    
> > >   

^ permalink raw reply	[flat|nested] 83+ messages in thread

end of thread, other threads:[~2016-06-06  9:58 UTC | newest]

Thread overview: 83+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-17 14:42 [Qemu-devel] [PATCH 00/33] ACPI CPU hotplug refactoring to support more than 255 CPUs and PXM/OST methods Igor Mammedov
2016-05-17 14:42 ` [Qemu-devel] [PATCH 01/33] tests: acpi: report names of expected files in verbose mode Igor Mammedov
2016-05-24 16:58   ` Marcel Apfelbaum
2016-05-26  9:46     ` [Qemu-devel] [PATCH v2 1/33] " Igor Mammedov
2016-05-30 18:14       ` Marcel Apfelbaum
2016-06-02 11:02       ` Marcel Apfelbaum
2016-05-17 14:42 ` [Qemu-devel] [PATCH 02/33] acpi: add aml_debug() Igor Mammedov
2016-05-24 16:59   ` Marcel Apfelbaum
2016-05-17 14:42 ` [Qemu-devel] [PATCH 03/33] acpi: add aml_refof() Igor Mammedov
2016-05-24 17:00   ` Marcel Apfelbaum
2016-05-17 14:42 ` [Qemu-devel] [PATCH 04/33] pc: acpi: remove AML for empty/not used GPE handlers Igor Mammedov
2016-05-25  9:11   ` Marcel Apfelbaum
2016-05-25 13:19     ` Igor Mammedov
2016-05-31 10:06       ` Marcel Apfelbaum
2016-05-17 14:42 ` [Qemu-devel] [PATCH 05/33] pc: acpi: consolidate CPU hotplug AML Igor Mammedov
2016-05-30 18:18   ` Marcel Apfelbaum
2016-05-31  7:50     ` Igor Mammedov
2016-05-31 10:18       ` Marcel Apfelbaum
2016-05-31 12:49         ` Igor Mammedov
2016-05-17 14:42 ` [Qemu-devel] [PATCH 06/33] pc: acpi: consolidate \GPE._E02 with the rest of " Igor Mammedov
2016-05-30 18:22   ` Marcel Apfelbaum
2016-05-17 14:42 ` [Qemu-devel] [PATCH 07/33] pc: acpi: cpu-hotplug: make AML CPU_foo defines local to cpu_hotplug_acpi_table.c Igor Mammedov
2016-05-30 18:23   ` Marcel Apfelbaum
2016-05-17 14:43 ` [Qemu-devel] [PATCH 08/33] pc: acpi: mark current CPU hotplug functions as legacy Igor Mammedov
2016-05-30 18:28   ` Marcel Apfelbaum
2016-05-17 14:43 ` [Qemu-devel] [PATCH 09/33] pc: acpi: consolidate legacy CPU hotplug in one file Igor Mammedov
2016-05-30 18:31   ` Marcel Apfelbaum
2016-05-17 14:43 ` [Qemu-devel] [PATCH 10/33] pc: acpi: simplify build_legacy_cpu_hotplug_aml() signature Igor Mammedov
2016-05-30 18:31   ` Marcel Apfelbaum
2016-05-17 14:43 ` [Qemu-devel] [PATCH 11/33] pc: acpi: cpuhp-legacy: switch ProcessorID to possible_cpus idx Igor Mammedov
2016-05-30 18:39   ` Marcel Apfelbaum
2016-05-31 13:03     ` Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 12/33] tests: acpi: update tables with consolidated legacy cpu-hotplug AML Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 13/33] acpi: extend ACPI interface to provide send_event hook Igor Mammedov
2016-05-30 18:45   ` Marcel Apfelbaum
2016-05-31  9:57     ` [Qemu-devel] [PATCH v2 " Igor Mammedov
2016-06-02 11:09       ` Marcel Apfelbaum
2016-06-02 11:19         ` Igor Mammedov
2016-06-02 11:21           ` Marcel Apfelbaum
2016-05-17 14:43 ` [Qemu-devel] [PATCH 14/33] pc: use AcpiDeviceIfClass.send_event to issue GPE events Igor Mammedov
2016-05-31 10:01   ` [Qemu-devel] [PATCH v2 " Igor Mammedov
2016-06-02 11:13     ` Marcel Apfelbaum
2016-06-02 11:29       ` Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 15/33] docs: update ACPI CPU hotplug spec with new protocol Igor Mammedov
2016-05-31  4:49   ` Michael S. Tsirkin
2016-05-31 15:07     ` Igor Mammedov
2016-05-31 21:09       ` Michael S. Tsirkin
2016-06-06  9:57         ` Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 16/33] acpi: hardware side of CPU hotplug Igor Mammedov
2016-05-30 18:50   ` Marcel Apfelbaum
2016-05-31 13:24     ` Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 17/33] pc: add generic CPU unplug callbacks Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 18/33] pc: add 2.7 machine Igor Mammedov
2016-05-30 18:53   ` Marcel Apfelbaum
2016-05-30 19:04     ` Eduardo Habkost
2016-05-17 14:43 ` [Qemu-devel] [PATCH 19/33] pc: piix4/ich9: add 'cpu-hotplug-legacy' property Igor Mammedov
2016-05-30 18:59   ` Marcel Apfelbaum
2016-05-17 14:43 ` [Qemu-devel] [PATCH 20/33] pc: q35: initialize new CPU hotplug hw Igor Mammedov
2016-05-30 19:02   ` Marcel Apfelbaum
2016-05-31 10:06     ` Igor Mammedov
2016-05-31 10:21       ` Marcel Apfelbaum
2016-05-31 12:51         ` Igor Mammedov
2016-05-31 12:52           ` Michael S. Tsirkin
2016-05-31 13:18             ` Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 21/33] pc: piix4: " Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 22/33] pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 23/33] acpi: add CPU devices AML to DSDT Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 24/33] acpi: add CPU hotplug methods " Igor Mammedov
2016-05-31  4:38   ` Michael S. Tsirkin
2016-05-31  8:45     ` Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 25/33] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 26/33] target-i386: add X86CPU.node property Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 27/33] pc: numa: replace node_cpu indexing by apic_id with possible_cpus index Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 28/33] pc: set X86CPU.node property if QEMU starts with numa enabled Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 29/33] acpi: cpuhp: provide cpu._PXM method if running in numa mode Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 30/33] acpi: cpuhp: add cpu._OST handling Igor Mammedov
2016-05-17 15:29   ` Eric Blake
2016-05-18  8:09     ` Igor Mammedov
2016-05-30 18:21       ` Michael S. Tsirkin
2016-05-31 12:53         ` Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 31/33] tests: acpi: update expected tables with new cpu-hotplug methods enabled by default Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 32/33] tests: acpi: add CPU hotplug testcase Igor Mammedov
2016-05-17 14:43 ` [Qemu-devel] [PATCH 33/33] tests: acpi: add DSDT/MADT expected tables for cpu-hotplug case Igor Mammedov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.