All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API
@ 2015-02-09 10:53 Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append() Igor Mammedov
                   ` (52 more replies)
  0 siblings, 53 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

changes since v2:
  * rename acpi prefixes in API to aml
  * reverse conversion order from bottom->top to top->bottom
  * introduce internal Aml garbage collector and 2 API functions
    to initialize and cleanup it up
  * replace acpi_argX() helpers with a single aml_arg(X) helper
    do the same for acpi_localX() helpers.
  * add 3 internal allocators, for allocating dummy Aml struct
    for helpers aml_alloc(), aml_opcode(OPCODE) for simple Aml
    elements and aml_bundle(opcode, kind) for complex elements
    that require post-processing after element has been composed
  * amend spec references to ACPI 1.0b and later if AML element
    was introduced later
  * various codestyle fixes
  * rebase on top of PCI tree

changes since RFC:
  * conflicts with vmgenid (broken) patches, so it's not based on PCI tree
  * rebased on top of today's master +
    [PATCH v5 0/5] pc: acpi: various fixes and cleanups +
    some patches from PCI tree that above series depends on
  * small cleanups
  * droped [42/47] acpi: make tables linker-loader available to other targets
    since Michael has a cleaner similar patch(es) in PCI tree,
    so reuse them (not included in here)
  * move SMC device from DSDT to SSDT and create it only when
    applesmc device is present.


This series refactors SSDT runtime composing and gets rid of:
    * patching AML templates, with related pointer arithmetic magic
    * manual AML composition, i.e. creating AML terms practically
      byte by byte
    * using AML templates for SSDT creation, reducing dependency on IASL.
      as result of above, QEMU source tree doesn't have to carry
      'binary' template blobs that used to be part of SSDT.
    * hand-crafted PCI0._CRSes for pc/q35 machines in DSDT with
      manual hole punching of reserved resources
and adds following:
    * introduces ASL like API for creating AML objects using ASL
      like constructs/terms. API: 
          * provides a necessary minimum set of terms/helpers to
            replace currently used SSDT templates.
          * simplifies AML composition and keeps track of AML
            object contexts, transparently managing their 
            (de)allocation and merging into parent context,
            making composition of SSDT 'almost' like writing
            native ASL definition of the table.
          * hides pointer arithmetic from user when composing
            SSDT.
    * dynamically creates unified PCI0._CRS in SSDT for pc/q35
      machines allowing to reserve resources at runtime vs
      current compile time
    * while adding new API, make it target independed CONFIG_ACPI
      and also make some other utilities for composing ACPI tables
      target independed (i.e. utils on which API depends) so that
      they could be reused for ARM target later without moving
      stuff around uncessarily.
    * trims SSDT by not creating objects that are not present
      (S[34] Package if disabled, pvpanic, applesmc)

As result of replacing AML templates with ASL API, codebase
reduces on ~1900LOC even with net addition of API 1050LOC counted in.


Tested with XPsp3, WS2012R2, RHEL6/7 guests. 

Git tree for playing with:
    https://github.com/imammedo/qemu/commits/ASL_API_v3


Igor Mammedov (52):
  acpi: introduce AML composer aml_append()
  pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
  pc: acpi: make top level ACPI tables blob Aml*
  acpi: factor out ACPI const int packing out of build_append_value()
  acpi: add aml_def_block() term
  pc: acpi-build: use aml_def_block() for declaring SSDT table
  acpi: add aml_scope() term
  pc: acpi-build: use aml_scope() for \_SB scope
  acpi: add aml_device() term
  acpi: add aml_method() term
  acpi: add aml_if() term
  acpi: add aml_name() & aml_name_decl() term
  acpi: extend build_append_{value|int}() to support 64-bit values
  acpi: add aml_int() term
  acpi: add aml_return() term
  acpi: add aml_arg() term
  acpi: add aml_store() term
  acpi: add aml_and() term
  acpi: add aml_notify() term
  acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
  pc: acpi-build: drop template patching and create PCI bus tree
    dynamically
  acpi: add aml_package() term
  pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  pc: acpi-build: generate _S[345] packages dynamically
  acpi: add aml_buffer() term
  acpi: add aml_resource_template() helper
  acpi: add aml_io() helper
  acpi: include PkgLength size only when requested
  acpi: add aml_operation_region() term
  acpi: add aml_field() & aml_named_field() terms
  acpi: add aml_local() term
  acpi: add aml_string() term
  pc: acpi-build: generate pvpanic device description dynamically
  acpi: add aml_varpackage() term
  acpi: add aml_equal() term
  acpi: add aml_processor() term
  acpi: add aml_eisaid() term
  pc: acpi-build: drop template patching and CPU hotplug objects
    dynamically
  pc: acpi-build: create CPU hotplug IO region dynamically
  acpi: add aml_reserved_field() term
  pc: acpi-build: drop template patching and memory hotplug objects
    dynamically
  pc: acpi-build: create memory hotplug IO region dynamically
  acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(),
    aml_qword_memory() terms
  pc: pcihp: expose MMIO base and len as properties
  pc: acpi-build: reserve PCIHP MMIO resources
  pc: acpi-build: create PCI0._CRS dynamically
  pc: acpi-build: drop remaining ssdt_misc template and use
    acpi_def_block()
  acpi: add acpi_irq_no_flags() term
  pc: export applesmc IO port/len
  pc: acpi-build: drop template patching and create Device(SMC)
    dynamically
  pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC
  acpi: make build_*() routines static to aml-build.c

 hw/acpi/aml-build.c                 | 744 ++++++++++++++++++++++++++++++--
 hw/acpi/pcihp.c                     |  18 +-
 hw/acpi/piix4.c                     |   2 +-
 hw/i386/Makefile.objs               |   4 +-
 hw/i386/acpi-build.c                | 825 +++++++++++++++++++-----------------
 hw/i386/acpi-dsdt-cpu-hotplug.dsl   |  17 +-
 hw/i386/acpi-dsdt-isa.dsl           |  11 -
 hw/i386/acpi-dsdt-mem-hotplug.dsl   |  36 +-
 hw/i386/acpi-dsdt-pci-crs.dsl       |  92 ----
 hw/i386/acpi-dsdt.dsl               |  46 --
 hw/i386/acpi-dsdt.hex.generated     | 714 ++-----------------------------
 hw/i386/q35-acpi-dsdt.dsl           |  19 -
 hw/i386/q35-acpi-dsdt.hex.generated | 662 ++---------------------------
 hw/i386/ssdt-mem.dsl                |  77 ----
 hw/i386/ssdt-mem.hex.generated      | 213 ----------
 hw/i386/ssdt-misc.dsl               | 122 ------
 hw/i386/ssdt-misc.hex.generated     | 399 -----------------
 hw/i386/ssdt-pcihp.dsl              | 100 -----
 hw/i386/ssdt-pcihp.hex.generated    | 251 -----------
 hw/i386/ssdt-proc.dsl               |  63 ---
 hw/i386/ssdt-proc.hex.generated     | 134 ------
 hw/misc/applesmc.c                  |   5 +-
 include/hw/acpi/aml-build.h         | 210 ++++++++-
 include/hw/acpi/pc-hotplug.h        |   1 +
 include/hw/acpi/pcihp.h             |   7 +-
 include/hw/isa/isa.h                |  11 +-
 26 files changed, 1436 insertions(+), 3347 deletions(-)
 delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl
 delete mode 100644 hw/i386/ssdt-mem.dsl
 delete mode 100644 hw/i386/ssdt-mem.hex.generated
 delete mode 100644 hw/i386/ssdt-misc.dsl
 delete mode 100644 hw/i386/ssdt-misc.hex.generated
 delete mode 100644 hw/i386/ssdt-pcihp.dsl
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
 delete mode 100644 hw/i386/ssdt-proc.dsl
 delete mode 100644 hw/i386/ssdt-proc.hex.generated

-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-17 16:26   ` Michael S. Tsirkin
  2015-02-17 19:46   ` Michael S. Tsirkin
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 02/52] pc: acpi: use local var for accessing ACPI tables blob in acpi_build() Igor Mammedov
                   ` (51 subsequent siblings)
  52 siblings, 2 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Adds for dynamic AML creation, which will be used
for piecing ASL/AML primitives together and hiding
from user/caller details about how nested context
should be closed/packed leaving less space for
mistakes and necessity to know how AML should be
encoded, allowing user to concentrate on ASL
representation instead.

For example it will allow to create AML like this:

init_aml_allocator();
...
Aml *scope = aml_scope("PCI0")
Aml *dev = aml_device("PM")
    aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
aml_append(scope, dev);
...
free_aml_allocator();

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index bcb288e..096f347 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -25,6 +25,8 @@
 #include <stdbool.h>
 #include <string.h>
 #include "hw/acpi/aml-build.h"
+#include "qemu/bswap.h"
+#include "hw/acpi/bios-linker-loader.h"
 
 GArray *build_alloc_array(void)
 {
@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)
         build_append_value(table, value, 4);
     }
 }
+
+static GPtrArray *alloc_list;
+
+static Aml *aml_alloc(void)
+{
+    Aml *var = g_new0(typeof(*var), 1);
+
+    g_ptr_array_add(alloc_list, var);
+    var->block_flags = AML_HELPER;
+    var->buf = build_alloc_array();
+    return var;
+}
+
+static void aml_free(gpointer data)
+{
+    Aml *var = data;
+    build_free_array(var->buf);
+}
+
+Aml *init_aml_allocator(GArray *linker)
+{
+    Aml *var;
+
+    assert(!alloc_list);
+    alloc_list = g_ptr_array_new_with_free_func(aml_free);
+    var = aml_alloc();
+    var->linker = linker;
+    return var;
+}
+
+void free_aml_allocator(void)
+{
+    g_ptr_array_free(alloc_list, true);
+    alloc_list = 0;
+}
+
+static void build_buffer(GArray *array, uint8_t op)
+{
+    GArray *data = build_alloc_array();
+
+    build_append_int(data, array->len);
+    g_array_prepend_vals(array, data->data, data->len);
+    build_free_array(data);
+    build_package(array, op);
+}
+
+void aml_append(Aml *parent_ctx, Aml *child)
+{
+    switch (child->block_flags) {
+    case AML_NON_BLOCK:
+        build_append_byte(parent_ctx->buf, child->op);
+        break;
+    case AML_EXT_PACKAGE:
+        build_extop_package(child->buf, child->op);
+        break;
+    case AML_PACKAGE:
+        build_package(child->buf, child->op);
+        break;
+    case AML_RES_TEMPLATE:
+        build_append_byte(child->buf, 0x79); /* EndTag */
+        /*
+         * checksum operations is treated as succeeded if checksum
+         * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
+         */
+        build_append_byte(child->buf, 0);
+        /* fall through, to pack resources in buffer */
+    case AML_BUFFER:
+        build_buffer(child->buf, child->op);
+        break;
+    case AML_DEF_BLOCK: {
+        uint8_t *start = (uint8_t *)parent_ctx->buf->data +
+                         parent_ctx->buf->len;
+        uint32_t le32_len = cpu_to_le32(child->buf->len);
+
+        /* create linker entry for the DefinitionBlock */
+        bios_linker_loader_add_checksum(parent_ctx->linker,
+            ACPI_BUILD_TABLE_FILE,
+            parent_ctx->buf->data,
+            start, child->buf->len, start + 9 /* checksum offset */);
+
+        /* set DefinitionBlock length at TableLength offset*/
+        memcpy(child->buf->data + 4, &le32_len, sizeof le32_len);
+        break;
+    }
+    default:
+        break;
+    }
+    build_append_array(parent_ctx->buf, child->buf);
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 6d84f38..237080f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
 #define ACPI_BUILD_APPNAME6 "BOCHS "
 #define ACPI_BUILD_APPNAME4 "BXPC"
 
-#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 199f003..4033796 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -5,6 +5,67 @@
 #include <glib.h>
 #include "qemu/compiler.h"
 
+#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
+
+typedef enum {
+    AML_HELPER = 0,
+    AML_NON_BLOCK,
+    AML_PACKAGE,
+    AML_EXT_PACKAGE,
+    AML_BUFFER,
+    AML_RES_TEMPLATE,
+    AML_DEF_BLOCK,
+} AmlBlockFlags;
+
+struct Aml {
+    GArray *buf;
+
+    /*< private >*/
+    uint8_t op;
+    AmlBlockFlags block_flags;
+    GArray *linker;
+};
+typedef struct Aml Aml;
+
+/**
+ * init_aml_allocator:
+ * @linker: linker that used by API for registering ACPI tables
+ *          with linker firmware interfac
+ *
+ * Called for initializing API allocator which allow to use
+ * AML API.
+ * Returns: toplevel container which accumulates all other
+ * ACPI tables.
+ */
+Aml *init_aml_allocator(GArray *linker);
+
+/**
+ * free_aml_allocator:
+ *
+ * Releases all elements used by AML API, frees associated memory
+ * and invalidates AML allocator. After this call @init_aml_allocator
+ * should be called again if AML API is to be used again.
+ */
+void free_aml_allocator(void);
+
+/**
+ * aml_append:
+ * @parent_ctx: context to which @child element is added
+ * @child: element that is copied into @parent_ctx context
+ *
+ * Joins Aml elements together and helps to construct AML tables
+ * Examle of usage:
+ *   Aml *table = aml_def_block("SSDT", ...);
+ *   Aml *sb = aml_scope("\_SB");
+ *   Aml *dev = aml_device("PCI0");
+ *
+ *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
+ *   aml_append(sb, dev);
+ *   aml_append(table, sb);
+ */
+void aml_append(Aml *parent_ctx, Aml *child);
+
+/* other helpers */
 GArray *build_alloc_array(void);
 void build_free_array(GArray *array);
 void build_prepend_byte(GArray *array, uint8_t val);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 02/52] pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append() Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 03/52] pc: acpi: make top level ACPI tables blob Aml* Igor Mammedov
                   ` (50 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

except of shortening of lines and making code a bit more readable,
it will reduce renaming noise when changing tables blob from GArray* to
Aml* type.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 69 ++++++++++++++++++++++++++--------------------------
 1 file changed, 35 insertions(+), 34 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 237080f..8020899 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1317,6 +1317,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     PcPciInfo pci;
     uint8_t *u;
     size_t aml_len = 0;
+    GArray *tables_blob = tables->table_data;
 
     acpi_get_cpu_info(&cpu);
     acpi_get_pm_info(&pm);
@@ -1337,66 +1338,66 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
      * We place it first since it's the only table that has alignment
      * requirements.
      */
-    facs = tables->table_data->len;
-    build_facs(tables->table_data, tables->linker, guest_info);
+    facs = tables_blob->len;
+    build_facs(tables_blob, tables->linker, guest_info);
 
     /* DSDT is pointed to by FADT */
-    dsdt = tables->table_data->len;
-    build_dsdt(tables->table_data, tables->linker, &misc);
+    dsdt = tables_blob->len;
+    build_dsdt(tables_blob, tables->linker, &misc);
 
     /* Count the size of the DSDT and SSDT, we will need it for legacy
      * sizing of ACPI tables.
      */
-    aml_len += tables->table_data->len - dsdt;
+    aml_len += tables_blob->len - dsdt;
 
     /* ACPI tables pointed to by RSDT */
-    acpi_add_table(table_offsets, tables->table_data);
-    build_fadt(tables->table_data, tables->linker, &pm, facs, dsdt);
+    acpi_add_table(table_offsets, tables_blob);
+    build_fadt(tables_blob, tables->linker, &pm, facs, dsdt);
 
-    ssdt = tables->table_data->len;
-    acpi_add_table(table_offsets, tables->table_data);
-    build_ssdt(tables->table_data, tables->linker, &cpu, &pm, &misc, &pci,
+    ssdt = tables_blob->len;
+    acpi_add_table(table_offsets, tables_blob);
+    build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
                guest_info);
-    aml_len += tables->table_data->len - ssdt;
+    aml_len += tables_blob->len - ssdt;
 
-    acpi_add_table(table_offsets, tables->table_data);
-    build_madt(tables->table_data, tables->linker, &cpu, guest_info);
+    acpi_add_table(table_offsets, tables_blob);
+    build_madt(tables_blob, tables->linker, &cpu, guest_info);
 
     if (misc.has_hpet) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_hpet(tables->table_data, tables->linker);
+        acpi_add_table(table_offsets, tables_blob);
+        build_hpet(tables_blob, tables->linker);
     }
     if (misc.has_tpm) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_tpm_tcpa(tables->table_data, tables->linker, tables->tcpalog);
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
-        acpi_add_table(table_offsets, tables->table_data);
-        build_tpm_ssdt(tables->table_data, tables->linker);
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm_ssdt(tables_blob, tables->linker);
     }
     if (guest_info->numa_nodes) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_srat(tables->table_data, tables->linker, guest_info);
+        acpi_add_table(table_offsets, tables_blob);
+        build_srat(tables_blob, tables->linker, guest_info);
     }
     if (acpi_get_mcfg(&mcfg)) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_mcfg_q35(tables->table_data, tables->linker, &mcfg);
+        acpi_add_table(table_offsets, tables_blob);
+        build_mcfg_q35(tables_blob, tables->linker, &mcfg);
     }
     if (acpi_has_iommu()) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_dmar_q35(tables->table_data, tables->linker);
+        acpi_add_table(table_offsets, tables_blob);
+        build_dmar_q35(tables_blob, tables->linker);
     }
 
     /* Add tables supplied by user (if any) */
     for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
         unsigned len = acpi_table_len(u);
 
-        acpi_add_table(table_offsets, tables->table_data);
-        g_array_append_vals(tables->table_data, u, len);
+        acpi_add_table(table_offsets, tables_blob);
+        g_array_append_vals(tables_blob, u, len);
     }
 
     /* RSDT is pointed to by RSDP */
-    rsdt = tables->table_data->len;
-    build_rsdt(tables->table_data, tables->linker, table_offsets);
+    rsdt = tables_blob->len;
+    build_rsdt(tables_blob, tables->linker, table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
     build_rsdp(tables->rsdp, tables->linker, rsdt);
@@ -1428,23 +1429,23 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
             guest_info->legacy_acpi_table_size +
             ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;
         int legacy_table_size =
-            ROUND_UP(tables->table_data->len - aml_len + legacy_aml_len,
+            ROUND_UP(tables_blob->len - aml_len + legacy_aml_len,
                      ACPI_BUILD_ALIGN_SIZE);
-        if (tables->table_data->len > legacy_table_size) {
+        if (tables_blob->len > legacy_table_size) {
             /* Should happen only with PCI bridges and -M pc-i440fx-2.0.  */
             error_report("Warning: migration may not work.");
         }
-        g_array_set_size(tables->table_data, legacy_table_size);
+        g_array_set_size(tables_blob, legacy_table_size);
     } else {
         /* Make sure we have a buffer in case we need to resize the tables. */
-        if (tables->table_data->len > ACPI_BUILD_TABLE_SIZE / 2) {
+        if (tables_blob->len > ACPI_BUILD_TABLE_SIZE / 2) {
             /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots.  */
             error_report("Warning: ACPI tables are larger than 64k.");
             error_report("Warning: migration may not work.");
             error_report("Warning: please remove CPUs, NUMA nodes, "
                          "memory slots or PCI bridges.");
         }
-        acpi_align_size(tables->table_data, ACPI_BUILD_TABLE_SIZE);
+        acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
     }
 
     acpi_align_size(tables->linker, ACPI_BUILD_ALIGN_SIZE);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 03/52] pc: acpi: make top level ACPI tables blob Aml*
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append() Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 02/52] pc: acpi: use local var for accessing ACPI tables blob in acpi_build() Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value() Igor Mammedov
                   ` (49 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

it will permit to add a separate tables into blob like other
AML constructs using aml_append() routine and hide from user
need to invoke linker manually for tables, handling it
automatically inside of aml_append() helper.

Later when all tables are converted to use AML API, it would
be possible to generate RSDT automatically and drop manual
table offsets tracking for RSDT.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 8020899..788962e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1238,7 +1238,7 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
 
 typedef
 struct AcpiBuildTables {
-    GArray *table_data;
+    Aml *table_data;
     GArray *rsdp;
     GArray *tcpalog;
     GArray *linker;
@@ -1247,17 +1247,17 @@ struct AcpiBuildTables {
 static inline void acpi_build_tables_init(AcpiBuildTables *tables)
 {
     tables->rsdp = g_array_new(false, true /* clear */, 1);
-    tables->table_data = g_array_new(false, true /* clear */, 1);
     tables->tcpalog = g_array_new(false, true /* clear */, 1);
     tables->linker = bios_linker_loader_init();
+    tables->table_data = init_aml_allocator(tables->linker);
 }
 
 static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
 {
     void *linker_data = bios_linker_loader_cleanup(tables->linker);
+    free_aml_allocator();
     g_free(linker_data);
     g_array_free(tables->rsdp, mfre);
-    g_array_free(tables->table_data, true);
     g_array_free(tables->tcpalog, mfre);
 }
 
@@ -1317,7 +1317,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     PcPciInfo pci;
     uint8_t *u;
     size_t aml_len = 0;
-    GArray *tables_blob = tables->table_data;
+    GArray *tables_blob = tables->table_data->buf;
 
     acpi_get_cpu_info(&cpu);
     acpi_get_pm_info(&pm);
@@ -1469,14 +1469,14 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
 
     acpi_build(build_state->guest_info, &tables);
 
-    assert(acpi_data_len(tables.table_data) == build_state->table_size);
+    assert(acpi_data_len(tables.table_data->buf) == build_state->table_size);
 
     /* Make sure RAM size is correct - in case it got changed by migration */
     qemu_ram_resize(build_state->table_ram, build_state->table_size,
                     &error_abort);
 
-    memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
-           build_state->table_size);
+    memcpy(qemu_get_ram_ptr(build_state->table_ram),
+           tables.table_data->buf->data, build_state->table_size);
 
     cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
                                                build_state->table_size);
@@ -1537,11 +1537,12 @@ void acpi_setup(PcGuestInfo *guest_info)
     acpi_build(build_state->guest_info, &tables);
 
     /* Now expose it all to Guest */
-    build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data,
+    build_state->table_ram = acpi_add_rom_blob(build_state,
+                                               tables.table_data->buf,
                                                ACPI_BUILD_TABLE_FILE,
                                                ACPI_BUILD_TABLE_MAX_SIZE);
     assert(build_state->table_ram != RAM_ADDR_MAX);
-    build_state->table_size = acpi_data_len(tables.table_data);
+    build_state->table_size = acpi_data_len(tables.table_data->buf);
 
     acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader", 0);
 
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (2 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 03/52] pc: acpi: make top level ACPI tables blob Aml* Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-17 19:53   ` Michael S. Tsirkin
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term Igor Mammedov
                   ` (48 subsequent siblings)
  52 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

it will be reused for adding a plain integer value into AML.

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 096f347..67d1371 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)
 
 void build_append_value(GArray *table, uint32_t value, int size)
 {
-    uint8_t prefix;
     int i;
 
-    switch (size) {
-    case 1:
-        prefix = 0x0A; /* BytePrefix */
-        break;
-    case 2:
-        prefix = 0x0B; /* WordPrefix */
-        break;
-    case 4:
-        prefix = 0x0C; /* DWordPrefix */
-        break;
-    default:
-        assert(0);
-        return;
-    }
-    build_append_byte(table, prefix);
     for (i = 0; i < size; ++i) {
         build_append_byte(table, value & 0xFF);
         value = value >> 8;
@@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value)
     } else if (value == 0x01) {
         build_append_byte(table, 0x01); /* OneOp */
     } else if (value <= 0xFF) {
+        build_append_byte(table, 0x0A); /* BytePrefix */
         build_append_value(table, value, 1);
     } else if (value <= 0xFFFF) {
+        build_append_byte(table, 0x0B); /* WordPrefix */
         build_append_value(table, value, 2);
     } else {
+        build_append_byte(table, 0x0C); /* DWordPrefix */
         build_append_value(table, value, 4);
     }
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 788962e..a1bf450 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)
 
 static void build_append_notify_target_ifequal(GArray *method,
                                                GArray *target_name,
-                                               uint32_t value, int size)
+                                               uint32_t value)
 {
     GArray *notify = build_alloc_array();
     uint8_t op = 0xA0; /* IfOp */
 
     build_append_byte(notify, 0x93); /* LEqualOp */
     build_append_byte(notify, 0x68); /* Arg0Op */
-    build_append_value(notify, value, size);
+    build_append_int(notify, value);
     build_append_byte(notify, 0x86); /* NotifyOp */
     build_append_array(notify, target_name);
     build_append_byte(notify, 0x69); /* Arg1Op */
@@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,
         GArray *target = build_alloc_array();
         build_append_namestring(target, format, i);
         assert(i < 256); /* Fits in 1 byte */
-        build_append_notify_target_ifequal(method, target, i, 1);
+        build_append_notify_target_ifequal(method, target, i);
         build_free_array(target);
     }
 
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (3 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value() Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-17 16:35   ` Michael S. Tsirkin
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table Igor Mammedov
                   ` (47 subsequent siblings)
  52 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 67d1371..cb1a1bd 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
     }
     build_append_array(parent_ctx->buf, child->buf);
 }
+
+/*
+ * ACPI 1.0b: 16.2.1 Top Level AML
+ *            5.2.3 System Description Table Header
+ *
+ * ACPI 5.0: 20.2.1 Table and Table Header Encoding
+ */
+Aml *aml_def_block(const char *signature, uint8_t revision,
+                   const char *oem_id, const char *oem_table_id,
+                   uint32_t oem_revision, uint32_t creator_id,
+                   uint32_t creator_revision)
+{
+    int len;
+    Aml *var = aml_alloc();
+    var->block_flags = AML_DEF_BLOCK;
+
+    assert(strlen(signature) == 4);
+    g_array_append_vals(var->buf, signature, 4);
+    build_append_value(var->buf, 0, 4); /* Length place holder */
+    build_append_byte(var->buf, revision);
+    build_append_byte(var->buf, 0); /* place holder for Checksum */
+
+    len = strlen(oem_id);
+    assert(len <= 6);
+    g_array_append_vals(var->buf, oem_id, len);
+    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
+
+    len = strlen(oem_table_id);
+    assert(len <= 8);
+    g_array_append_vals(var->buf, oem_table_id, len);
+    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
+
+    build_append_value(var->buf, oem_revision, 4);
+    build_append_value(var->buf, creator_id, 4);
+    build_append_value(var->buf, creator_revision, 4);
+
+    return var;
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a1bf450..553c86b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
                                             NULL);
 }
 
-#define ACPI_BUILD_APPNAME  "Bochs"
-#define ACPI_BUILD_APPNAME6 "BOCHS "
-#define ACPI_BUILD_APPNAME4 "BXPC"
-
 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 4033796..2610336 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -6,6 +6,10 @@
 #include "qemu/compiler.h"
 
 #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
+#define ACPI_BUILD_APPNAME  "Bochs"
+#define ACPI_BUILD_APPNAME6 "BOCHS "
+#define ACPI_BUILD_APPNAME4 "BXPC"
+#define ACPI_BUILD_APPNAME4_HEX 0x43505842
 
 typedef enum {
     AML_HELPER = 0,
@@ -65,6 +69,12 @@ void free_aml_allocator(void);
  */
 void aml_append(Aml *parent_ctx, Aml *child);
 
+/* Block AML object primitives */
+Aml *aml_def_block(const char *signature, uint8_t revision,
+                   const char *oem_id, const char *oem_table_id,
+                   uint32_t oem_revision, uint32_t creator_id,
+                   uint32_t creator_revision);
+
 /* other helpers */
 GArray *build_alloc_array(void);
 void build_free_array(GArray *array);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (4 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-17 16:42   ` Michael S. Tsirkin
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 07/52] acpi: add aml_scope() term Igor Mammedov
                   ` (46 subsequent siblings)
  52 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

it replaces prebuilt SSDT table header template copying/patching
with AML API

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 553c86b..fcefa07 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -816,15 +816,15 @@ static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
 }
 
 static void
-build_ssdt(GArray *table_data, GArray *linker,
+build_ssdt(Aml *table_data,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
            PcPciInfo *pci, PcGuestInfo *guest_info)
 {
     MachineState *machine = MACHINE(qdev_get_machine());
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
-    int ssdt_start = table_data->len;
     uint8_t *ssdt_ptr;
+    Aml *ssdt;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -832,9 +832,17 @@ build_ssdt(GArray *table_data, GArray *linker,
     QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256);
     g_assert(acpi_cpus <= ACPI_CPU_HOTPLUG_ID_LIMIT);
 
-    /* Copy header and patch values in the S3_ / S4_ / S5_ packages */
-    ssdt_ptr = acpi_data_push(table_data, sizeof(ssdp_misc_aml));
-    memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
+    /* Init SSDT Definition Block */
+    ssdt = aml_def_block("SSDT", 1, ACPI_BUILD_APPNAME6,
+                         ACPI_BUILD_APPNAME4, 1,
+                         ACPI_BUILD_APPNAME4_HEX, 1);
+
+    /* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
+    acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
+    ssdt_ptr = (uint8_t *)ssdt->buf->data;
+    memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
+           ssdp_misc_aml + sizeof(AcpiTableHeader),
+           sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
     if (pm->s3_disabled) {
         ssdt_ptr[acpi_s3_name[0]] = 'X';
     }
@@ -944,13 +952,11 @@ build_ssdt(GArray *table_data, GArray *linker,
             }
         }
         build_package(sb_scope, op);
-        build_append_array(table_data, sb_scope);
+        build_append_array(ssdt->buf, sb_scope);
         build_free_array(sb_scope);
     }
 
-    build_header(linker, table_data,
-                 (void *)(table_data->data + ssdt_start),
-                 "SSDT", table_data->len - ssdt_start, 1);
+    aml_append(table_data, ssdt);
 }
 
 static void
@@ -1352,7 +1358,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 
     ssdt = tables_blob->len;
     acpi_add_table(table_offsets, tables_blob);
-    build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
+    build_ssdt(tables->table_data, &cpu, &pm, &misc, &pci,
                guest_info);
     aml_len += tables_blob->len - ssdt;
 
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 07/52] acpi: add aml_scope() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (5 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 08/52] pc: acpi-build: use aml_scope() for \_SB scope Igor Mammedov
                   ` (45 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cb1a1bd..31a3786 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -259,6 +259,15 @@ static Aml *aml_alloc(void)
     return var;
 }
 
+static Aml *aml_bundle(uint8_t op, AmlBlockFlags flags)
+{
+    Aml *var = aml_alloc();
+
+    var->op  = op;
+    var->block_flags = flags;
+    return var;
+}
+
 static void aml_free(gpointer data)
 {
     Aml *var = data;
@@ -373,3 +382,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 
     return var;
 }
+
+/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */
+Aml *aml_scope(const char *name_format, ...)
+{
+    va_list ap;
+    Aml *var = aml_bundle(0x10 /* ScopeOp */, AML_PACKAGE);
+    va_start(ap, name_format);
+    build_append_namestringv(var->buf, name_format, ap);
+    va_end(ap);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 2610336..35f1099 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -74,6 +74,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
                    const char *oem_id, const char *oem_table_id,
                    uint32_t oem_revision, uint32_t creator_id,
                    uint32_t creator_revision);
+Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 08/52] pc: acpi-build: use aml_scope() for \_SB scope
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (6 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 07/52] acpi: add aml_scope() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 09/52] acpi: add aml_device() term Igor Mammedov
                   ` (44 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

prepares for incremental conversion of SSDT contents to AML API

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index fcefa07..bdc343f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -824,7 +824,7 @@ build_ssdt(Aml *table_data,
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     uint8_t *ssdt_ptr;
-    Aml *ssdt;
+    Aml *ssdt, *sb_scope;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -861,15 +861,11 @@ build_ssdt(Aml *table_data,
     ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
                       ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
+    sb_scope = aml_scope("_SB");
     {
-        GArray *sb_scope = build_alloc_array();
-        uint8_t op = 0x10; /* ScopeOp */
-
-        build_append_namestring(sb_scope, "_SB");
-
         /* build Processor object for each processor */
         for (i = 0; i < acpi_cpus; i++) {
-            uint8_t *proc = acpi_data_push(sb_scope, ACPI_PROC_SIZEOF);
+            uint8_t *proc = acpi_data_push(sb_scope->buf, ACPI_PROC_SIZEOF);
             memcpy(proc, ACPI_PROC_AML, ACPI_PROC_SIZEOF);
             proc[ACPI_PROC_OFFSET_CPUHEX] = acpi_get_hex(i >> 4);
             proc[ACPI_PROC_OFFSET_CPUHEX+1] = acpi_get_hex(i);
@@ -881,11 +877,12 @@ build_ssdt(Aml *table_data,
          *   Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...}
          */
         /* Arg0 = Processor ID = APIC ID */
-        build_append_notify_method(sb_scope, "NTFY", "CP%0.02X", acpi_cpus);
+        build_append_notify_method(sb_scope->buf, "NTFY",
+                                   "CP%0.02X", acpi_cpus);
 
         /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */
-        build_append_byte(sb_scope, 0x08); /* NameOp */
-        build_append_namestring(sb_scope, "CPON");
+        build_append_byte(sb_scope->buf, 0x08); /* NameOp */
+        build_append_namestring(sb_scope->buf, "CPON");
 
         {
             GArray *package = build_alloc_array();
@@ -910,7 +907,7 @@ build_ssdt(Aml *table_data,
             }
 
             build_package(package, op);
-            build_append_array(sb_scope, package);
+            build_append_array(sb_scope->buf, package);
             build_free_array(package);
         }
 
@@ -919,7 +916,7 @@ build_ssdt(Aml *table_data,
             /* build memory devices */
             for (i = 0; i < nr_mem; i++) {
                 char id[3];
-                uint8_t *mem = acpi_data_push(sb_scope, ACPI_MEM_SIZEOF);
+                uint8_t *mem = acpi_data_push(sb_scope->buf, ACPI_MEM_SIZEOF);
 
                 snprintf(id, sizeof(id), "%02X", i);
                 memcpy(mem, ACPI_MEM_AML, ACPI_MEM_SIZEOF);
@@ -930,7 +927,7 @@ build_ssdt(Aml *table_data,
             /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
              *     If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
              */
-            build_append_notify_method(sb_scope,
+            build_append_notify_method(sb_scope->buf,
                                        stringify(MEMORY_SLOT_NOTIFY_METHOD),
                                        "MP%0.02X", nr_mem);
         }
@@ -947,13 +944,11 @@ build_ssdt(Aml *table_data,
 
             if (bus) {
                 /* Scan all PCI buses. Generate tables to support hotplug. */
-                build_append_pci_bus_devices(sb_scope, bus,
+                build_append_pci_bus_devices(sb_scope->buf, bus,
                                              pm->pcihp_bridge_en);
             }
         }
-        build_package(sb_scope, op);
-        build_append_array(ssdt->buf, sb_scope);
-        build_free_array(sb_scope);
+        aml_append(ssdt, sb_scope);
     }
 
     aml_append(table_data, ssdt);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 09/52] acpi: add aml_device() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (7 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 08/52] pc: acpi-build: use aml_scope() for \_SB scope Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 10/52] acpi: add aml_method() term Igor Mammedov
                   ` (43 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 31a3786..e38a222 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -393,3 +393,14 @@ Aml *aml_scope(const char *name_format, ...)
     va_end(ap);
     return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefDevice */
+Aml *aml_device(const char *name_format, ...)
+{
+    va_list ap;
+    Aml *var = aml_bundle(0x82 /* DeviceOp */, AML_EXT_PACKAGE);
+    va_start(ap, name_format);
+    build_append_namestringv(var->buf, name_format, ap);
+    va_end(ap);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 35f1099..dfc725e 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -75,6 +75,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
                    uint32_t oem_revision, uint32_t creator_id,
                    uint32_t creator_revision);
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 10/52] acpi: add aml_method() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (8 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 09/52] acpi: add aml_device() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 11/52] acpi: add aml_if() term Igor Mammedov
                   ` (42 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 e38a222..7389009 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -383,6 +383,15 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
+Aml *aml_method(const char *name, int arg_count)
+{
+    Aml *var = aml_bundle(0x14 /* MethodOp */, AML_PACKAGE);
+    build_append_namestring(var->buf, "%s", name);
+    build_append_byte(var->buf, arg_count); /* MethodFlags: ArgCount */
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */
 Aml *aml_scope(const char *name_format, ...)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index dfc725e..c1720e7 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -76,6 +76,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
                    uint32_t creator_revision);
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+Aml *aml_method(const char *name, int arg_count);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 11/52] acpi: add aml_if() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (9 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 10/52] acpi: add aml_method() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 12/52] acpi: add aml_name() & aml_name_decl() term Igor Mammedov
                   ` (41 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 7389009..9f43fef 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -383,6 +383,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
+Aml *aml_if(Aml *predicate)
+{
+    Aml *var = aml_bundle(0xA0 /* IfOp */, AML_PACKAGE);
+    aml_append(var, predicate);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
 Aml *aml_method(const char *name, int arg_count)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index c1720e7..7cd1f51 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -77,6 +77,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
+Aml *aml_if(Aml *predicate);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 12/52] acpi: add aml_name() & aml_name_decl() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (10 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 11/52] acpi: add aml_if() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 13/52] acpi: extend build_append_{value|int}() to support 64-bit values Igor Mammedov
                   ` (40 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 9f43fef..5d6553c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -259,6 +259,15 @@ static Aml *aml_alloc(void)
     return var;
 }
 
+static Aml *aml_opcode(uint8_t op)
+{
+    Aml *var = aml_alloc();
+
+    var->op  = op;
+    var->block_flags = AML_NON_BLOCK;
+    return var;
+}
+
 static Aml *aml_bundle(uint8_t op, AmlBlockFlags flags)
 {
     Aml *var = aml_alloc();
@@ -383,6 +392,29 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
     return var;
 }
 
+/*
+ * helper to construct NameString, which returns Aml object
+ * for using with aml_append or other aml_* terms
+ */
+Aml *aml_name(const char *name_format, ...)
+{
+    va_list ap;
+    Aml *var = aml_alloc();
+    va_start(ap, name_format);
+    build_append_namestringv(var->buf, name_format, ap);
+    va_end(ap);
+    return var;
+}
+
+/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefName */
+Aml *aml_name_decl(const char *name, Aml *val)
+{
+    Aml *var = aml_opcode(0x08 /* NameOp */);
+    build_append_namestring(var->buf, "%s", name);
+    aml_append(var, val);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 7cd1f51..d5d8c11 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -69,6 +69,10 @@ void free_aml_allocator(void);
  */
 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);
+
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
                    const char *oem_id, const char *oem_table_id,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 13/52] acpi: extend build_append_{value|int}() to support 64-bit values
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (11 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 12/52] acpi: add aml_name() & aml_name_decl() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 14/52] acpi: add aml_int() term Igor Mammedov
                   ` (39 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

it will be used for generating 64bit _CRS entries

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 5d6553c..d71b236 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -219,7 +219,7 @@ void build_extop_package(GArray *package, uint8_t op)
     build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
-void build_append_value(GArray *table, uint32_t value, int size)
+void build_append_value(GArray *table, uint64_t value, int size)
 {
     int i;
 
@@ -229,7 +229,7 @@ void build_append_value(GArray *table, uint32_t value, int size)
     }
 }
 
-void build_append_int(GArray *table, uint32_t value)
+void build_append_int(GArray *table, uint64_t value)
 {
     if (value == 0x00) {
         build_append_byte(table, 0x00); /* ZeroOp */
@@ -241,9 +241,12 @@ void build_append_int(GArray *table, uint32_t value)
     } else if (value <= 0xFFFF) {
         build_append_byte(table, 0x0B); /* WordPrefix */
         build_append_value(table, value, 2);
-    } else {
+    } else if (value <= 0xFFFFFFFF) {
         build_append_byte(table, 0x0C); /* DWordPrefix */
         build_append_value(table, value, 4);
+    } else {
+        build_append_byte(table, 0x0E); /* QWordPrefix */
+        build_append_value(table, value, 8);
     }
 }
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index d5d8c11..5abc56b 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -95,8 +95,8 @@ build_append_namestring(GArray *array, const char *format, ...);
 
 void build_prepend_package_length(GArray *package);
 void build_package(GArray *package, uint8_t op);
-void build_append_value(GArray *table, uint32_t value, int size);
-void build_append_int(GArray *table, uint32_t value);
+void build_append_value(GArray *table, uint64_t value, int size);
+void build_append_int(GArray *table, uint64_t value);
 void build_extop_package(GArray *package, uint8_t op);
 
 #endif
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 14/52] acpi: add aml_int() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (12 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 13/52] acpi: extend build_append_{value|int}() to support 64-bit values Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 15/52] acpi: add aml_return() term Igor Mammedov
                   ` (38 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d71b236..de775e2 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -396,6 +396,17 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 }
 
 /*
+ * ACPI 1.0b: 16.2.3 Data Objects Encoding:
+ * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
+ */
+Aml *aml_int(const uint64_t val)
+{
+    Aml *var = aml_alloc();
+    build_append_int(var->buf, val);
+    return var;
+}
+
+/*
  * helper to construct NameString, which returns Aml object
  * for using with aml_append or other aml_* terms
  */
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 5abc56b..31225c6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -72,6 +72,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_int(const uint64_t val);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 15/52] acpi: add aml_return() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (13 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 14/52] acpi: add aml_int() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 16/52] acpi: add aml_arg() term Igor Mammedov
                   ` (37 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 de775e2..2a29c8f 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -395,6 +395,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefReturn */
+Aml *aml_return(Aml *val)
+{
+    Aml *var = aml_opcode(0xA4 /* ReturnOp */);
+    aml_append(var, val);
+    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 31225c6..8d35751 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -72,6 +72,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_return(Aml *val);
 Aml *aml_int(const uint64_t val);
 
 /* Block AML object primitives */
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 16/52] acpi: add aml_arg() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (14 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 15/52] acpi: add aml_return() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 17/52] acpi: add aml_store() term Igor Mammedov
                   ` (36 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 2a29c8f..12f0653 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -437,6 +437,17 @@ Aml *aml_name_decl(const char *name, Aml *val)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.6.1 Arg Objects Encoding */
+Aml *aml_arg(int pos)
+{
+    Aml *var;
+    uint8_t op = 0x68 /* ARG0 op */ + pos;
+
+    assert(pos <= 6);
+    var = aml_opcode(op);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 8d35751..80cab77 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -74,6 +74,7 @@ Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_name_decl(const char *name, Aml *val);
 Aml *aml_return(Aml *val);
 Aml *aml_int(const uint64_t val);
+Aml *aml_arg(int pos);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 17/52] acpi: add aml_store() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (15 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 16/52] acpi: add aml_arg() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 18/52] acpi: add aml_and() term Igor Mammedov
                   ` (35 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 12f0653..ae84b25 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -448,6 +448,15 @@ Aml *aml_arg(int pos)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefStore */
+Aml *aml_store(Aml *val, Aml *target)
+{
+    Aml *var = aml_opcode(0x70 /* StoreOp */);
+    aml_append(var, val);
+    aml_append(var, target);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 80cab77..93fb662 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -75,6 +75,7 @@ Aml *aml_name_decl(const char *name, Aml *val);
 Aml *aml_return(Aml *val);
 Aml *aml_int(const uint64_t val);
 Aml *aml_arg(int pos);
+Aml *aml_store(Aml *val, Aml *target);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 18/52] acpi: add aml_and() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (16 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 17/52] acpi: add aml_store() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 19/52] acpi: add aml_notify() term Igor Mammedov
                   ` (34 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index ae84b25..61149dc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -457,6 +457,16 @@ Aml *aml_store(Aml *val, Aml *target)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAnd */
+Aml *aml_and(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x7B /* AndOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    build_append_int(var->buf, 0x00 /* NullNameOp */);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 93fb662..31db64a 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -76,6 +76,7 @@ Aml *aml_return(Aml *val);
 Aml *aml_int(const uint64_t val);
 Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
+Aml *aml_and(Aml *arg1, Aml *arg2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 19/52] acpi: add aml_notify() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (17 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 18/52] acpi: add aml_and() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 20/52] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Igor Mammedov
                   ` (33 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 61149dc..c5feb61 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -467,6 +467,15 @@ Aml *aml_and(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
+Aml *aml_notify(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x86 /* NotifyOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 31db64a..564517b 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -77,6 +77,7 @@ Aml *aml_int(const uint64_t val);
 Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
+Aml *aml_notify(Aml *arg1, Aml *arg2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 20/52] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (18 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 19/52] acpi: add aml_notify() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically Igor Mammedov
                   ` (32 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index c5feb61..0328a57 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -476,6 +476,48 @@ Aml *aml_notify(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* helper to call method with 1 argument */
+Aml *aml_call1(const char *method, Aml *arg1)
+{
+    Aml *var = aml_alloc();
+    build_append_namestring(var->buf, "%s", method);
+    aml_append(var, arg1);
+    return var;
+}
+
+/* helper to call method with 2 arguments */
+Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_alloc();
+    build_append_namestring(var->buf, "%s", method);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    return var;
+}
+
+/* helper to call method with 3 arguments */
+Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3)
+{
+    Aml *var = aml_alloc();
+    build_append_namestring(var->buf, "%s", method);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    aml_append(var, arg3);
+    return var;
+}
+
+/* helper to call method with 4 arguments */
+Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4)
+{
+    Aml *var = aml_alloc();
+    build_append_namestring(var->buf, "%s", method);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    aml_append(var, arg3);
+    aml_append(var, arg4);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 564517b..cd06669 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -78,6 +78,10 @@ Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
+Aml *aml_call1(const char *method, Aml *arg1);
+Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
+Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
+Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (19 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 20/52] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-17 19:39   ` Michael S. Tsirkin
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 22/52] acpi: add aml_package() term Igor Mammedov
                   ` (31 subsequent siblings)
  52 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Replace AML template patching with direct composing
of PCI device entries in C. It allows to simplify
PCI tree generation further and saves us about 400LOC
scattered through different files, confining tree
generation to one C function which is much easier
to deal with.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/Makefile.objs            |   6 +-
 hw/i386/acpi-build.c             | 207 +++++++++++---------------------
 hw/i386/ssdt-pcihp.dsl           | 100 ----------------
 hw/i386/ssdt-pcihp.hex.generated | 251 ---------------------------------------
 4 files changed, 72 insertions(+), 492 deletions(-)
 delete mode 100644 hw/i386/ssdt-pcihp.dsl
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 2b678ef..4509cd1 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-	hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
-	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \
-	hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
     ; then echo "$(2)"; else echo "$(3)"; fi ;)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index bdc343f..b6626f5 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
 #define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
 
-/* 0x5B 0x82 DeviceOp PkgLength NameString */
-#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
-#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
-#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
-#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
-
-#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
-#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
-
-#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
-#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
-
-#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
-#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
-
 #include "hw/i386/ssdt-mem.hex"
 
 /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
@@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_SSDT_HEADER_LENGTH 36
 
 #include "hw/i386/ssdt-misc.hex"
-#include "hw/i386/ssdt-pcihp.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
 static void
@@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,
     build_append_and_cleanup_method(device, method);
 }
 
-static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
-    ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
-}
-
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
  */
@@ -648,46 +587,30 @@ static void acpi_set_pci_info(void)
     }
 }
 
-static void build_append_pcihp_notify_entry(GArray *method, int slot)
+static void build_append_pcihp_notify_entry(Aml *method, int slot)
 {
-    GArray *ifctx;
+    Aml *if_ctx;
+    int32_t devfn = PCI_DEVFN(slot, 0);
 
-    ifctx = build_alloc_array();
-    build_append_byte(ifctx, 0x7B); /* AndOp */
-    build_append_byte(ifctx, 0x68); /* Arg0Op */
-    build_append_int(ifctx, 0x1U << slot);
-    build_append_byte(ifctx, 0x00); /* NullName */
-    build_append_byte(ifctx, 0x86); /* NotifyOp */
-    build_append_namestring(ifctx, "S%.02X", PCI_DEVFN(slot, 0));
-    build_append_byte(ifctx, 0x69); /* Arg1Op */
-
-    /* Pack it up */
-    build_package(ifctx, 0xA0 /* IfOp */);
-    build_append_array(method, ifctx);
-    build_free_array(ifctx);
+    if_ctx = aml_if(aml_and(aml_arg(0), aml_int(0x1U << slot)));
+    aml_append(if_ctx, aml_notify(aml_name("S%.02X", devfn), aml_arg(1)));
+    aml_append(method, if_ctx);
 }
 
-static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
+static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
                                          bool pcihp_bridge_en)
 {
-    GArray *bus_table = build_alloc_array();
-    GArray *method = NULL;
+    Aml *dev, *notify_method, *method;
     QObject *bsel;
     PCIBus *sec;
     int i;
 
-    if (bus->parent_dev) {
-        build_append_namestring(bus_table, "S%.02X_", bus->parent_dev->devfn);
-    } else {
-        build_append_namestring(bus_table, "PCI0");
-    }
-
     bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
     if (bsel) {
-        build_append_byte(bus_table, 0x08); /* NameOp */
-        build_append_namestring(bus_table, "BSEL");
-        build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
-        method = build_alloc_method("DVNT", 2);
+        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
+
+        aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val)));
+        notify_method = aml_method("DVNT", 2);
     }
 
     for (i = 0; i < ARRAY_SIZE(bus->devices); i += PCI_FUNC_MAX) {
@@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
 
         if (!pdev) {
             if (bsel) {
-                void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
-                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
-                patch_pcihp(slot, pcihp);
-
-                build_append_pcihp_notify_entry(method, slot);
+                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
+                aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
+                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
+                method = aml_method("_EJ0", 1);
+                aml_append(method,
+                    aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
+                );
+                aml_append(dev, method);
+                aml_append(parent_scope, dev);
+
+                build_append_pcihp_notify_entry(notify_method, slot);
             } else {
-                void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
-                memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
-                patch_pcinohp(slot, pcihp);
+                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
+                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
+                aml_append(parent_scope, dev);
             }
             continue;
         }
@@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
         bridge_in_acpi = pc->is_bridge && pcihp_bridge_en &&
             !DEVICE(pdev)->hotplugged;
 
+        dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
+        aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
+
         if (pc->class_id == PCI_CLASS_DISPLAY_VGA) {
+            int s3d = 0;
 
             if (object_dynamic_cast(OBJECT(pdev), "qxl-vga")) {
-                void *pcihp = acpi_data_push(bus_table,
-                                             ACPI_PCIQXL_SIZEOF);
-                      memcpy(pcihp, ACPI_PCIQXL_AML, ACPI_PCIQXL_SIZEOF);
-                      patch_pciqxl(slot, pcihp);
-            } else {
-                void *pcihp = acpi_data_push(bus_table,
-                                             ACPI_PCIVGA_SIZEOF);
-                memcpy(pcihp, ACPI_PCIVGA_AML, ACPI_PCIVGA_SIZEOF);
-                patch_pcivga(slot, pcihp);
+                s3d = 3;
             }
+
+            method = aml_method("_S1D", 0);
+            aml_append(method, aml_return(aml_int(0)));
+            aml_append(dev, method);
+
+            method = aml_method("_S2D", 0);
+            aml_append(method, aml_return(aml_int(0)));
+            aml_append(dev, method);
+
+            method = aml_method("_S3D", 0);
+            aml_append(method, aml_return(aml_int(s3d)));
+            aml_append(dev, method);
         } else if (dc->hotpluggable && !bridge_in_acpi) {
-            void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
-            memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
-            patch_pcihp(slot, pcihp);
+            aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
+
+            method = aml_method("_EJ0", 1);
+            aml_append(method,
+                aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
+            );
+            aml_append(dev, method);
 
             if (bsel) {
-                build_append_pcihp_notify_entry(method, slot);
+                build_append_pcihp_notify_entry(notify_method, slot);
             }
         } else {
-            void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
-            memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
-            patch_pcinohp(slot, pcihp);
-
             /* When hotplug for bridges is enabled, bridges that are
              * described in ACPI separately aren't themselves hot-pluggable.
              * Hotplugged bridges *are* hot-pluggable.
@@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
             if (bridge_in_acpi) {
                 PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
 
-                build_append_pci_bus_devices(bus_table, sec_bus,
-                                             pcihp_bridge_en);
+                build_append_pci_bus_devices(dev, sec_bus, pcihp_bridge_en);
             }
         }
+        aml_append(parent_scope, dev);
     }
 
     if (bsel) {
-        build_append_and_cleanup_method(bus_table, method);
+        aml_append(parent_scope, notify_method);
     }
 
     /* Append PCNT method to notify about events on local and child buses.
      * Add unconditionally for root since DSDT expects it.
      */
-    method = build_alloc_method("PCNT", 0);
+    method = aml_method("PCNT", 0);
 
     /* If bus supports hotplug select it and notify about local events */
     if (bsel) {
-        build_append_byte(method, 0x70); /* StoreOp */
-        build_append_int(method, qint_get_int(qobject_to_qint(bsel)));
-        build_append_namestring(method, "BNUM");
-        build_append_namestring(method, "DVNT");
-        build_append_namestring(method, "PCIU");
-        build_append_int(method, 1); /* Device Check */
-        build_append_namestring(method, "DVNT");
-        build_append_namestring(method, "PCID");
-        build_append_int(method, 3); /* Eject Request */
+        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
+        aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
+        aml_append(method,
+            aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check */)
+        );
+        aml_append(method,
+            aml_call2("DVNT", aml_name("PCID"), aml_int(3)/* Eject Request */)
+        );
     }
 
     /* Notify about child bus events in any case */
     if (pcihp_bridge_en) {
         QLIST_FOREACH(sec, &bus->child, sibling) {
-            build_append_namestring(method, "^S%.02X.PCNT",
-                                    sec->parent_dev->devfn);
+            int32_t devfn = sec->parent_dev->devfn;
+
+            aml_append(method, aml_name("^S%.02X.PCNT", devfn));
         }
     }
-
-    build_append_and_cleanup_method(bus_table, method);
-
-    build_package(bus_table, 0x10); /* ScopeOp */
-    build_append_array(parent_scope, bus_table);
-    build_free_array(bus_table);
+    aml_append(parent_scope, method);
 }
 
 static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
@@ -943,9 +875,10 @@ build_ssdt(Aml *table_data,
             }
 
             if (bus) {
+                Aml *scope = aml_scope("PCI0");
                 /* Scan all PCI buses. Generate tables to support hotplug. */
-                build_append_pci_bus_devices(sb_scope->buf, bus,
-                                             pm->pcihp_bridge_en);
+                build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en);
+                aml_append(sb_scope, scope);
             }
         }
         aml_append(ssdt, sb_scope);
diff --git a/hw/i386/ssdt-pcihp.dsl b/hw/i386/ssdt-pcihp.dsl
deleted file mode 100644
index ac91c05..0000000
--- a/hw/i386/ssdt-pcihp.dsl
+++ /dev/null
@@ -1,100 +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/>.
- */
-
-ACPI_EXTRACT_ALL_CODE ssdp_pcihp_aml
-
-DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
-{
-
-/****************************************************************
- * PCI hotplug
- ****************************************************************/
-
-    /* Objects supplied by DSDT */
-    External(\_SB.PCI0, DeviceObj)
-    External(\_SB.PCI0.PCEJ, MethodObj)
-    External(BSEL, IntObj)
-
-    Scope(\_SB.PCI0) {
-
-        /* Bulk generated PCI hotplug devices */
-        ACPI_EXTRACT_DEVICE_START ssdt_pcihp_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pcihp_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pcihp_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SAA) {
-            ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcihp_id
-            Name(_SUN, 0xAA)
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcihp_adr
-            Name(_ADR, 0xAA0000)
-            Method(_EJ0, 1) {
-                PCEJ(BSEL, _SUN)
-            }
-        }
-
-        ACPI_EXTRACT_DEVICE_START ssdt_pcinohp_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pcinohp_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pcinohp_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SBB) {
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcinohp_adr
-            Name(_ADR, 0xAA0000)
-        }
-
-        ACPI_EXTRACT_DEVICE_START ssdt_pcivga_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pcivga_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pcivga_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SCC) {
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcivga_adr
-            Name(_ADR, 0xAA0000)
-            Method(_S1D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S2D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S3D, 0, NotSerialized) {
-                Return (0x00)
-            }
-        }
-
-        ACPI_EXTRACT_DEVICE_START ssdt_pciqxl_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pciqxl_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pciqxl_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SDD) {
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pciqxl_adr
-            Name(_ADR, 0xAA0000)
-            Method(_S1D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S2D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S3D, 0, NotSerialized) {
-                Return (0x03)           // QXL
-            }
-        }
-    }
-}
diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
deleted file mode 100644
index 72ffa84..0000000
--- a/hw/i386/ssdt-pcihp.hex.generated
+++ /dev/null
@@ -1,251 +0,0 @@
-static unsigned char ssdt_pcihp_name[] = {
-0x34
-};
-static unsigned char ssdt_pcivga_end[] = {
-0x99
-};
-static unsigned char ssdt_pcivga_name[] = {
-0x70
-};
-static unsigned char ssdt_pcihp_adr[] = {
-0x45
-};
-static unsigned char ssdt_pcinohp_end[] = {
-0x6d
-};
-static unsigned char ssdt_pcihp_end[] = {
-0x5c
-};
-static unsigned char ssdt_pciqxl_start[] = {
-0x99
-};
-static unsigned char ssdt_pcinohp_name[] = {
-0x5f
-};
-static unsigned char ssdp_pcihp_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0xc6,
-0x0,
-0x0,
-0x0,
-0x1,
-0x70,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x50,
-0x43,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x15,
-0x11,
-0x13,
-0x20,
-0x10,
-0x41,
-0xa,
-0x5c,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x5b,
-0x82,
-0x29,
-0x53,
-0x41,
-0x41,
-0x5f,
-0x8,
-0x5f,
-0x53,
-0x55,
-0x4e,
-0xa,
-0xaa,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x12,
-0x5f,
-0x45,
-0x4a,
-0x30,
-0x1,
-0x50,
-0x43,
-0x45,
-0x4a,
-0x42,
-0x53,
-0x45,
-0x4c,
-0x5f,
-0x53,
-0x55,
-0x4e,
-0x5b,
-0x82,
-0xf,
-0x53,
-0x42,
-0x42,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x5b,
-0x82,
-0x2a,
-0x53,
-0x43,
-0x43,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x31,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x32,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x33,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x5b,
-0x82,
-0x2b,
-0x53,
-0x44,
-0x44,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x31,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x32,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x9,
-0x5f,
-0x53,
-0x33,
-0x44,
-0x0,
-0xa4,
-0xa,
-0x3
-};
-static unsigned char ssdt_pciqxl_adr[] = {
-0xa6
-};
-static unsigned char ssdt_pcinohp_adr[] = {
-0x69
-};
-static unsigned char ssdt_pcivga_adr[] = {
-0x7a
-};
-static unsigned char ssdt_pciqxl_name[] = {
-0x9c
-};
-static unsigned char ssdt_pcivga_start[] = {
-0x6d
-};
-static unsigned char ssdt_pciqxl_end[] = {
-0xc6
-};
-static unsigned char ssdt_pcihp_start[] = {
-0x31
-};
-static unsigned char ssdt_pcihp_id[] = {
-0x3e
-};
-static unsigned char ssdt_pcinohp_start[] = {
-0x5c
-};
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 22/52] acpi: add aml_package() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (20 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP Igor Mammedov
                   ` (30 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 0328a57..31e999d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -556,3 +556,11 @@ Aml *aml_device(const char *name_format, ...)
     va_end(ap);
     return var;
 }
+
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */
+Aml *aml_package(uint8_t num_elements)
+{
+    Aml *var = aml_bundle(0x12 /* PackageOp */, AML_PACKAGE);
+    build_append_byte(var->buf, num_elements);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index cd06669..511abf6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -92,6 +92,7 @@ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
+Aml *aml_package(uint8_t num_elements);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (21 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 22/52] acpi: add aml_package() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-17 16:41   ` Michael S. Tsirkin
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 24/52] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
                   ` (29 subsequent siblings)
  52 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

QEMU doesn't implement/advertize PM1b_CNT_BLK
register block so do not set/patch its \_Sx
values to avoid confusion.

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

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b6626f5..7cc564a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,
     if (pm->s4_disabled) {
         ssdt_ptr[acpi_s4_name[0]] = 'X';
     } else {
-        ssdt_ptr[acpi_s4_pkg[0] + 1] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
-            pm->s4_val;
+        ssdt_ptr[acpi_s4_pkg[0] + 1] = pm->s4_val;
     }
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 1e3baae..96382a6 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -54,7 +54,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
         ACPI_EXTRACT_NAME_STRING acpi_s3_name
         Name(_S3, Package(0x04) {
             One,  /* PM1a_CNT.SLP_TYP */
-            One,  /* PM1b_CNT.SLP_TYP */
+            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
             Zero,  /* reserved */
             Zero   /* reserved */
         })
@@ -62,7 +62,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
         ACPI_EXTRACT_PKG_START acpi_s4_pkg
         Name(_S4, Package(0x04) {
             0x2,  /* PM1a_CNT.SLP_TYP */
-            0x2,  /* PM1b_CNT.SLP_TYP */
+            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
             Zero,  /* reserved */
             Zero   /* reserved */
         })
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 24/52] pc: acpi-build: generate _S[345] packages dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (22 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 25/52] acpi: add aml_buffer() term Igor Mammedov
                   ` (28 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Replaces template patching with packages composed
using AML API.

Note on behavior change:
If S3 or S4 is disabled, respective packages won't
be created and put into SSDT. Which saves us some
space in SSDT and doesn't confuse guest OS with
mangled package names as it was done originally.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c  | 38 +++++++++++++++++++++++++++++---------
 hw/i386/ssdt-misc.dsl | 33 ---------------------------------
 2 files changed, 29 insertions(+), 42 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 7cc564a..1e912d1 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -756,7 +756,7 @@ build_ssdt(Aml *table_data,
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     uint8_t *ssdt_ptr;
-    Aml *ssdt, *sb_scope;
+    Aml *ssdt, *sb_scope, *scope, *pkg;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -775,14 +775,6 @@ build_ssdt(Aml *table_data,
     memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
            ssdp_misc_aml + sizeof(AcpiTableHeader),
            sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
-    if (pm->s3_disabled) {
-        ssdt_ptr[acpi_s3_name[0]] = 'X';
-    }
-    if (pm->s4_disabled) {
-        ssdt_ptr[acpi_s4_name[0]] = 'X';
-    } else {
-        ssdt_ptr[acpi_s4_pkg[0] + 1] = pm->s4_val;
-    }
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
@@ -792,6 +784,34 @@ build_ssdt(Aml *table_data,
     ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
                       ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
+    /*  create S3_ / S4_ / S5_ packages if necessary */
+    scope = aml_scope("\\");
+    if (!pm->s3_disabled) {
+        pkg = aml_package(4);
+        aml_append(pkg, aml_int(1)); /* PM1a_CNT.SLP_TYP */
+        aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+        aml_append(pkg, aml_int(0)); /* reserved */
+        aml_append(pkg, aml_int(0)); /* reserved */
+        aml_append(scope, aml_name_decl("_S3", pkg));
+    }
+
+    if (!pm->s4_disabled) {
+        pkg = aml_package(4);
+        aml_append(pkg, aml_int(pm->s4_val)); /* PM1a_CNT.SLP_TYP */
+        aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+        aml_append(pkg, aml_int(0)); /* reserved */
+        aml_append(pkg, aml_int(0)); /* reserved */
+        aml_append(scope, aml_name_decl("_S4", pkg));
+    }
+
+    pkg = aml_package(4);
+    aml_append(pkg, aml_int(0)); /* PM1a_CNT.SLP_TYP */
+    aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+    aml_append(pkg, aml_int(0)); /* reserved */
+    aml_append(pkg, aml_int(0)); /* reserved */
+    aml_append(scope, aml_name_decl("_S5", pkg));
+    aml_append(ssdt, scope);
+
     sb_scope = aml_scope("_SB");
     {
         /* build Processor object for each processor */
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 96382a6..26b9241 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -41,39 +41,6 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
     }
 
 
-/****************************************************************
- * Suspend
- ****************************************************************/
-
-    Scope(\) {
-    /*
-     * S3 (suspend-to-ram), S4 (suspend-to-disk) and S5 (power-off) type codes:
-     * must match piix4 emulation.
-     */
-
-        ACPI_EXTRACT_NAME_STRING acpi_s3_name
-        Name(_S3, Package(0x04) {
-            One,  /* PM1a_CNT.SLP_TYP */
-            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
-            Zero,  /* reserved */
-            Zero   /* reserved */
-        })
-        ACPI_EXTRACT_NAME_STRING acpi_s4_name
-        ACPI_EXTRACT_PKG_START acpi_s4_pkg
-        Name(_S4, Package(0x04) {
-            0x2,  /* PM1a_CNT.SLP_TYP */
-            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
-            Zero,  /* reserved */
-            Zero   /* reserved */
-        })
-        Name(_S5, Package(0x04) {
-            Zero,  /* PM1a_CNT.SLP_TYP */
-            Zero,  /* PM1b_CNT.SLP_TYP */
-            Zero,  /* reserved */
-            Zero   /* reserved */
-        })
-    }
-
     External(\_SB.PCI0, DeviceObj)
     External(\_SB.PCI0.ISA, DeviceObj)
 
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 25/52] acpi: add aml_buffer() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (23 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 24/52] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 26/52] acpi: add aml_resource_template() helper Igor Mammedov
                   ` (27 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 31e999d..6488433 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -557,6 +557,13 @@ Aml *aml_device(const char *name_format, ...)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */
+Aml *aml_buffer(void)
+{
+    Aml *var = aml_bundle(0x11 /* BufferOp */, AML_BUFFER);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */
 Aml *aml_package(uint8_t num_elements)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 511abf6..06826df 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -93,6 +93,7 @@ Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
+Aml *aml_buffer(void);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 26/52] acpi: add aml_resource_template() helper
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (24 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 25/52] acpi: add aml_buffer() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 27/52] acpi: add aml_io() helper Igor Mammedov
                   ` (26 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 6488433..452db25 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -557,6 +557,14 @@ Aml *aml_device(const char *name_format, ...)
     return var;
 }
 
+/* ACPI 1.0b: 6.4.1 ASL Macros for Resource Descriptors */
+Aml *aml_resource_template(void)
+{
+    /* ResourceTemplate is a buffer of Resources with EndTag at the end */
+    Aml *var = aml_bundle(0x11 /* BufferOp */, AML_RES_TEMPLATE);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */
 Aml *aml_buffer(void)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 06826df..6a8aaef 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -94,6 +94,7 @@ Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
+Aml *aml_resource_template(void);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 27/52] acpi: add aml_io() helper
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (25 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 26/52] acpi: add aml_resource_template() helper Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 28/52] acpi: include PkgLength size only when requested Igor Mammedov
                   ` (25 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 452db25..a5d5b83 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -518,6 +518,22 @@ Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4)
     return var;
 }
 
+/* ACPI 1.0b: 6.4.2.5 I/O Port Descriptor */
+Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
+            uint8_t aln, uint8_t len)
+{
+    Aml *var = aml_alloc();
+    build_append_byte(var->buf, 0x47); /* IO port descriptor */
+    build_append_byte(var->buf, dec);
+    build_append_byte(var->buf, min_base & 0xff);
+    build_append_byte(var->buf, (min_base >> 8) & 0xff);
+    build_append_byte(var->buf, max_base & 0xff);
+    build_append_byte(var->buf, (max_base >> 8) & 0xff);
+    build_append_byte(var->buf, aln);
+    build_append_byte(var->buf, len);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6a8aaef..3dab2b5 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -31,6 +31,11 @@ struct Aml {
 };
 typedef struct Aml Aml;
 
+typedef enum {
+    aml_decode10 = 0,
+    aml_decode16 = 1,
+} AmlIODecode;
+
 /**
  * init_aml_allocator:
  * @linker: linker that used by API for registering ACPI tables
@@ -82,6 +87,8 @@ Aml *aml_call1(const char *method, Aml *arg1);
 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
 Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
 Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
+Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
+            uint8_t aln, uint8_t len);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 28/52] acpi: include PkgLength size only when requested
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (26 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 27/52] acpi: add aml_io() helper Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 29/52] acpi: add aml_operation_region() term Igor Mammedov
                   ` (24 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Named/Reserved{Field} definition uses PkgLength [1] encoding to specify
field length, however it doesn't include size of PkgLength field itself,
while other block objects that have explicit length of its body account
for PkgLength size while encoding it [2].
This special casing isn't mentioned in ACPI spec, but that's what 'iasl'
compiles NamedField to so add extra argument to build_prepend_pkg_length()
to allow it handle the case.

--
1. ACPI Spec 5.0, 20.2.5.2 Named Objects Encoding, page 822
2. ACPI Spec 5.0, 5.4 Definition Block Encoding

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/aml-build.c         | 20 +++++++++++++++-----
 include/hw/acpi/aml-build.h |  3 ++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index a5d5b83..8c6b6a3 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -159,10 +159,10 @@ enum {
     PACKAGE_LENGTH_4BYTE_SHIFT = 20,
 };
 
-void build_prepend_package_length(GArray *package)
+void
+build_prepend_package_length(GArray *package, unsigned length, bool incl_self)
 {
     uint8_t byte;
-    unsigned length = package->len;
     unsigned length_bytes;
 
     if (length + 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT)) {
@@ -175,8 +175,18 @@ void build_prepend_package_length(GArray *package)
         length_bytes = 4;
     }
 
-    /* PkgLength is the length of the inclusive length of the data. */
-    length += length_bytes;
+    /*
+     * NamedField uses PkgLength encoding but it doesn't include length
+     * of PkgLength itself.
+     */
+    if (incl_self) {
+        /*
+         * PkgLength is the length of the inclusive length of the data
+         * and PkgLength's length itself when used for terms with
+         * explitit length.
+         */
+        length += length_bytes;
+    }
 
     switch (length_bytes) {
     case 1:
@@ -209,7 +219,7 @@ void build_prepend_package_length(GArray *package)
 
 void build_package(GArray *package, uint8_t op)
 {
-    build_prepend_package_length(package);
+    build_prepend_package_length(package, package->len, true);
     build_prepend_byte(package, op);
 }
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 3dab2b5..1c95845 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -113,7 +113,8 @@ void build_append_array(GArray *array, GArray *val);
 void GCC_FMT_ATTR(2, 3)
 build_append_namestring(GArray *array, const char *format, ...);
 
-void build_prepend_package_length(GArray *package);
+void
+build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
 void build_package(GArray *package, uint8_t op);
 void build_append_value(GArray *table, uint64_t value, int size);
 void build_append_int(GArray *table, uint64_t value);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 29/52] acpi: add aml_operation_region() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (27 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 28/52] acpi: include PkgLength size only when requested Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 30/52] acpi: add aml_field() & aml_named_field() terms Igor Mammedov
                   ` (23 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 8c6b6a3..05d4a3d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -605,3 +605,17 @@ Aml *aml_package(uint8_t num_elements)
     build_append_byte(var->buf, num_elements);
     return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefOpRegion */
+Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
+                          uint32_t offset, uint32_t len)
+{
+    Aml *var = aml_alloc();
+    build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */
+    build_append_byte(var->buf, 0x80); /* OpRegionOp */
+    build_append_namestring(var->buf, "%s", name);
+    build_append_byte(var->buf, rs);
+    build_append_int(var->buf, offset);
+    build_append_int(var->buf, len);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 1c95845..6db9d42 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -36,6 +36,11 @@ typedef enum {
     aml_decode16 = 1,
 } AmlIODecode;
 
+typedef enum {
+    aml_system_memory = 0x00,
+    aml_system_io = 0x01,
+} AmlRegionSpace;
+
 /**
  * init_aml_allocator:
  * @linker: linker that used by API for registering ACPI tables
@@ -89,6 +94,8 @@ Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
 Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
 Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
             uint8_t aln, uint8_t len);
+Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
+                          uint32_t offset, uint32_t len);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 30/52] acpi: add aml_field() & aml_named_field() terms
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (28 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 29/52] acpi: add aml_operation_region() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term Igor Mammedov
                   ` (22 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 05d4a3d..10995a9 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -217,6 +217,16 @@ build_prepend_package_length(GArray *package, unsigned length, bool incl_self)
     build_prepend_byte(package, byte);
 }
 
+static void
+build_append_pkg_length(GArray *array, unsigned length, bool incl_self)
+{
+    GArray *tmp = build_alloc_array();
+
+    build_prepend_package_length(tmp, length, incl_self);
+    build_append_array(array, tmp);
+    build_free_array(tmp);
+}
+
 void build_package(GArray *package, uint8_t op)
 {
     build_prepend_package_length(package, package->len, true);
@@ -619,3 +629,21 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
     build_append_int(var->buf, len);
     return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: NamedField */
+Aml *aml_named_field(const char *name, unsigned length)
+{
+    Aml *var = aml_alloc();
+    build_append_nameseg(var->buf, name);
+    build_append_pkg_length(var->buf, length, false);
+    return var;
+}
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */
+Aml *aml_field(const char *name, AmlFieldFlags flags)
+{
+    Aml *var = aml_bundle(0x81 /* FieldOp */, AML_EXT_PACKAGE);
+    build_append_namestring(var->buf, "%s", name);
+    build_append_byte(var->buf, flags);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6db9d42..8b954d9 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -37,6 +37,10 @@ typedef enum {
 } AmlIODecode;
 
 typedef enum {
+    aml_byte_acc = 1,
+} AmlFieldFlags;
+
+typedef enum {
     aml_system_memory = 0x00,
     aml_system_io = 0x01,
 } AmlRegionSpace;
@@ -96,6 +100,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
             uint8_t aln, uint8_t len);
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
                           uint32_t offset, uint32_t len);
+Aml *aml_named_field(const char *name, unsigned length);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
@@ -109,6 +114,7 @@ Aml *aml_if(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
 Aml *aml_resource_template(void);
+Aml *aml_field(const char *name, AmlFieldFlags flags);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (29 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 30/52] acpi: add aml_field() & aml_named_field() terms Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-17 12:18   ` Michael S. Tsirkin
  2015-02-17 14:24   ` [Qemu-devel] [PATCH v3 31/52] fixup! " Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 32/52] acpi: add aml_string() term Igor Mammedov
                   ` (21 subsequent siblings)
  52 siblings, 2 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 10995a9..cb58e19 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
     build_append_byte(var->buf, flags);
     return var;
 }
+
+/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
+Aml *aml_local(int num)
+{
+    Aml *var;
+    uint8_t op = 0x60 /* Local0Op */ + num;
+
+    assert(op <= 7);
+    var = aml_opcode(op);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 8b954d9..6e25315 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
                           uint32_t offset, uint32_t len);
 Aml *aml_named_field(const char *name, unsigned length);
+Aml *aml_local(int num);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 32/52] acpi: add aml_string() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (30 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 33/52] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
                   ` (20 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cb58e19..3929de9 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -648,6 +648,31 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.3 Data Objects Encoding: String */
+Aml *aml_string(const char *name_format, ...)
+{
+    Aml *var = aml_opcode(0x0D /* StringPrefix */);
+    va_list ap, va_len;
+    char *s;
+    int len;
+
+    va_start(ap, name_format);
+    va_copy(va_len, ap);
+    len = vsnprintf(NULL, 0, name_format, va_len);
+    va_end(va_len);
+    len += 1;
+    s = g_new0(typeof(*s), len);
+
+    len = vsnprintf(s, len, name_format, ap);
+    va_end(ap);
+
+    g_array_append_vals(var->buf, s, len);
+    build_append_byte(var->buf, 0x0); /* NullChar */
+    g_free(s);
+
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
 Aml *aml_local(int num)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6e25315..fee4eef 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -102,6 +102,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
                           uint32_t offset, uint32_t len);
 Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_local(int num);
+Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 33/52] pc: acpi-build: generate pvpanic device description dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (31 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 32/52] acpi: add aml_string() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 34/52] acpi: add aml_varpackage() term Igor Mammedov
                   ` (19 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Drops AML template patching and allows to
save some space in SSDT if pvpanic device doesn't
exist by not including disabled device description
into SSDT. It also makes device description
smaller by replacing _STA method with named value
and dropping _INI method.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c  | 36 ++++++++++++++++++++++++++++++++----
 hw/i386/ssdt-misc.dsl | 47 -----------------------------------------------
 2 files changed, 32 insertions(+), 51 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 1e912d1..a86dc42 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -756,7 +756,7 @@ build_ssdt(Aml *table_data,
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     uint8_t *ssdt_ptr;
-    Aml *ssdt, *sb_scope, *scope, *pkg;
+    Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -779,9 +779,6 @@ build_ssdt(Aml *table_data,
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
     ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
-                      ssdt_isa_pest[0], 16, misc->pvpanic_port);
-
-    ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
                       ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
     /*  create S3_ / S4_ / S5_ packages if necessary */
@@ -812,6 +809,37 @@ build_ssdt(Aml *table_data,
     aml_append(scope, aml_name_decl("_S5", pkg));
     aml_append(ssdt, scope);
 
+    if (misc->pvpanic_port) {
+        scope = aml_scope("\\_SB.PCI0.ISA");
+
+        dev = aml_device("PEVR");
+        aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
+
+        crs = aml_resource_template();
+        aml_append(crs,
+            aml_io(aml_decode16, misc->pvpanic_port, misc->pvpanic_port, 1, 1)
+        );
+        aml_append(dev, aml_name_decl("_CRS", crs));
+
+        aml_append(dev, aml_operation_region("PEOR", aml_system_io,
+                                              misc->pvpanic_port, 1));
+        field = aml_field("PEOR", aml_byte_acc);
+        aml_append(field, aml_named_field("PEPT", 8));
+        aml_append(dev, field);
+
+        method = aml_method("RDPT", 0);
+        aml_append(method, aml_store(aml_name("PEPT"), aml_local(0)));
+        aml_append(method, aml_return(aml_local(0)));
+        aml_append(dev, method);
+
+        method = aml_method("WRPT", 1);
+        aml_append(method, aml_store(aml_arg(0), aml_name("PEPT")));
+        aml_append(dev, method);
+
+        aml_append(scope, dev);
+        aml_append(ssdt, scope);
+    }
+
     sb_scope = aml_scope("_SB");
     {
         /* build Processor object for each processor */
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 26b9241..81be858 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -39,51 +39,4 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
        ACPI_EXTRACT_NAME_DWORD_CONST ssdt_mctrl_nr_slots
        Name(MEMORY_SLOTS_NUMBER, 0x12345678)
     }
-
-
-    External(\_SB.PCI0, DeviceObj)
-    External(\_SB.PCI0.ISA, DeviceObj)
-
-    Scope(\_SB.PCI0.ISA) {
-        Device(PEVT) {
-            Name(_HID, "QEMU0001")
-            /* PEST will be patched to be Zero if no such device */
-            ACPI_EXTRACT_NAME_WORD_CONST ssdt_isa_pest
-            Name(PEST, 0xFFFF)
-            OperationRegion(PEOR, SystemIO, PEST, 0x01)
-            Field(PEOR, ByteAcc, NoLock, Preserve) {
-                PEPT,   8,
-            }
-
-            Method(_STA, 0, NotSerialized) {
-                Store(PEST, Local0)
-                If (LEqual(Local0, Zero)) {
-                    Return (0x00)
-                } Else {
-                    Return (0x0F)
-                }
-            }
-
-            Method(RDPT, 0, NotSerialized) {
-                Store(PEPT, Local0)
-                Return (Local0)
-            }
-
-            Method(WRPT, 1, NotSerialized) {
-                Store(Arg0, PEPT)
-            }
-
-            Name(_CRS, ResourceTemplate() {
-                IO(Decode16, 0x00, 0x00, 0x01, 0x01, IO)
-            })
-
-            CreateWordField(_CRS, IO._MIN, IOMN)
-            CreateWordField(_CRS, IO._MAX, IOMX)
-
-            Method(_INI, 0, NotSerialized) {
-                Store(PEST, IOMN)
-                Store(PEST, IOMX)
-            }
-        }
-    }
 }
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 34/52] acpi: add aml_varpackage() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (32 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 33/52] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 35/52] acpi: add aml_equal() term Igor Mammedov
                   ` (18 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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 3929de9..90b7b65 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -683,3 +683,11 @@ Aml *aml_local(int num)
     var = aml_opcode(op);
     return var;
 }
+
+/* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */
+Aml *aml_varpackage(uint32_t num_elements)
+{
+    Aml *var = aml_bundle(0x13 /* VarPackageOp */, AML_PACKAGE);
+    build_append_int(var->buf, num_elements);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index fee4eef..d5b9325 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -117,6 +117,7 @@ Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
 Aml *aml_resource_template(void);
 Aml *aml_field(const char *name, AmlFieldFlags flags);
+Aml *aml_varpackage(uint32_t num_elements);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 35/52] acpi: add aml_equal() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (33 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 34/52] acpi: add aml_varpackage() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 36/52] acpi: add aml_processor() term Igor Mammedov
                   ` (17 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 90b7b65..670d3e9 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -554,6 +554,16 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */
+Aml *aml_equal(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x93 /* LequalOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    build_append_int(var->buf, 0x00); /* NullNameOp */
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index d5b9325..e918055 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -103,6 +103,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
 Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_local(int num);
 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+Aml *aml_equal(Aml *arg1, Aml *arg2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 36/52] acpi: add aml_processor() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (34 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 35/52] acpi: add aml_equal() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 37/52] acpi: add aml_eisaid() term Igor Mammedov
                   ` (16 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
   * use build_append_value() to pack PblkAddr
     instead of doing it manually
---
 hw/acpi/aml-build.c         | 15 +++++++++++++++
 include/hw/acpi/aml-build.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 670d3e9..aa5ef59 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -701,3 +701,18 @@ Aml *aml_varpackage(uint32_t num_elements)
     build_append_int(var->buf, num_elements);
     return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefProcessor */
+Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
+                   const char *name_format, ...)
+{
+    va_list ap;
+    Aml *var = aml_bundle(0x83 /* ProcessorOp */, AML_EXT_PACKAGE);
+    va_start(ap, name_format);
+    build_append_namestringv(var->buf, name_format, ap);
+    va_end(ap);
+    build_append_byte(var->buf, proc_id); /* ProcID */
+    build_append_value(var->buf, pblk_addr, sizeof(pblk_addr)); /* PblkAddr */
+    build_append_byte(var->buf, pblk_len); /* PblkLen */
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index e918055..3cf9fbb 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -104,6 +104,8 @@ Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_local(int num);
 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_equal(Aml *arg1, Aml *arg2);
+Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
+                   const char *name_format, ...) GCC_FMT_ATTR(4, 5);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 37/52] acpi: add aml_eisaid() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (35 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 36/52] acpi: add aml_processor() term Igor Mammedov
@ 2015-02-09 10:53 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 38/52] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
                   ` (15 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index aa5ef59..90c1272 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -716,3 +716,32 @@ Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
     build_append_byte(var->buf, pblk_len); /* PblkLen */
     return var;
 }
+
+static uint8_t Hex2Digit(char c)
+{
+    if (c >= 'A') {
+        return c - 'A' + 10;
+    }
+
+    return c - '0';
+}
+
+/* ACPI 1.0b: 15.2.3.6.4.1 EISAID Macro - Convert EISA ID String To Integer */
+Aml *aml_eisaid(const char *str)
+{
+    Aml *var = aml_alloc();
+    uint32_t id;
+
+    g_assert(strlen(str) == 7);
+    id = (str[0] - 0x40) << 26 |
+    (str[1] - 0x40) << 21 |
+    (str[2] - 0x40) << 16 |
+    Hex2Digit(str[3]) << 12 |
+    Hex2Digit(str[4]) << 8 |
+    Hex2Digit(str[5]) << 4 |
+    Hex2Digit(str[6]);
+
+    build_append_byte(var->buf, 0x0C); /* DWordPrefix */
+    build_append_value(var->buf, bswap32(id), sizeof(id));
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 3cf9fbb..84fe4db 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -106,6 +106,7 @@ Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_equal(Aml *arg1, Aml *arg2);
 Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
                    const char *name_format, ...) GCC_FMT_ATTR(4, 5);
+Aml *aml_eisaid(const char *str);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 38/52] pc: acpi-build: drop template patching and CPU hotplug objects dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (36 preceding siblings ...)
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 37/52] acpi: add aml_eisaid() term Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 39/52] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
                   ` (14 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

in addition it saves us ~400LOC and makes it
one binary blob less stored in QEMU source
tree by removing need to keep and update
hw/i386/ssdt-proc.hex.generated file there.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/Makefile.objs           |   2 +-
 hw/i386/acpi-build.c            |  95 ++++++++++++----------------
 hw/i386/ssdt-proc.dsl           |  63 -------------------
 hw/i386/ssdt-proc.hex.generated | 134 ----------------------------------------
 4 files changed, 42 insertions(+), 252 deletions(-)
 delete mode 100644 hw/i386/ssdt-proc.dsl
 delete mode 100644 hw/i386/ssdt-proc.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 4509cd1..a1e5aa2 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a86dc42..b82e636 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -509,22 +509,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
                  table_data->len - madt_start, 1);
 }
 
-/* Encode a hex value */
-static inline char acpi_get_hex(uint32_t val)
-{
-    val &= 0x0f;
-    return (val <= 9) ? ('0' + val) : ('A' + val - 10);
-}
-
-#include "hw/i386/ssdt-proc.hex"
-
-/* 0x5B 0x83 ProcessorOp PkgLength NameString ProcID */
-#define ACPI_PROC_OFFSET_CPUHEX (*ssdt_proc_name - *ssdt_proc_start + 2)
-#define ACPI_PROC_OFFSET_CPUID1 (*ssdt_proc_name - *ssdt_proc_start + 4)
-#define ACPI_PROC_OFFSET_CPUID2 (*ssdt_proc_id - *ssdt_proc_start)
-#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
-#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
-
 #include "hw/i386/ssdt-mem.hex"
 
 /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
@@ -756,7 +740,7 @@ build_ssdt(Aml *table_data,
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     uint8_t *ssdt_ptr;
-    Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field;
+    Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -844,51 +828,54 @@ build_ssdt(Aml *table_data,
     {
         /* build Processor object for each processor */
         for (i = 0; i < acpi_cpus; i++) {
-            uint8_t *proc = acpi_data_push(sb_scope->buf, ACPI_PROC_SIZEOF);
-            memcpy(proc, ACPI_PROC_AML, ACPI_PROC_SIZEOF);
-            proc[ACPI_PROC_OFFSET_CPUHEX] = acpi_get_hex(i >> 4);
-            proc[ACPI_PROC_OFFSET_CPUHEX+1] = acpi_get_hex(i);
-            proc[ACPI_PROC_OFFSET_CPUID1] = i;
-            proc[ACPI_PROC_OFFSET_CPUID2] = i;
+            dev = aml_processor(i, 0, 0, "CP%.02X", i);
+
+            method = aml_method("_MAT", 0);
+            aml_append(method, aml_return(aml_call1("CPMA", aml_int(i))));
+            aml_append(dev, method);
+
+            method = aml_method("_STA", 0);
+            aml_append(method, aml_return(aml_call1("CPST", aml_int(i))));
+            aml_append(dev, method);
+
+            method = aml_method("_EJ0", 1);
+            aml_append(method,
+                aml_return(aml_call2("CPEJ", aml_int(i), 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 */
-        build_append_notify_method(sb_scope->buf, "NTFY",
-                                   "CP%0.02X", acpi_cpus);
-
-        /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */
-        build_append_byte(sb_scope->buf, 0x08); /* NameOp */
-        build_append_namestring(sb_scope->buf, "CPON");
-
-        {
-            GArray *package = build_alloc_array();
-            uint8_t op;
-
-            /*
-             * Note: The ability to create variable-sized packages was first introduced in ACPI 2.0. ACPI 1.0 only
-             * allowed fixed-size packages with up to 255 elements.
-             * Windows guests up to win2k8 fail when VarPackageOp is used.
-             */
-            if (acpi_cpus <= 255) {
-                op = 0x12; /* PackageOp */
-                build_append_byte(package, acpi_cpus); /* NumElements */
-            } else {
-                op = 0x13; /* VarPackageOp */
-                build_append_int(package, acpi_cpus); /* VarNumElements */
-            }
-
-            for (i = 0; i < acpi_cpus; i++) {
-                uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0x00;
-                build_append_byte(package, b);
-            }
+        method = aml_method("NTFY", 2);
+        for (i = 0; i < acpi_cpus; i++) {
+            ifctx = aml_if(aml_equal(aml_arg(0), aml_int(i)));
+            aml_append(ifctx,
+                aml_notify(aml_name("CP%.02X", i), 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
+         * ntroduced 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 = acpi_cpus <= 255 ? aml_package(acpi_cpus) :
+                                 aml_varpackage(acpi_cpus);
 
-            build_package(package, op);
-            build_append_array(sb_scope->buf, package);
-            build_free_array(package);
+        for (i = 0; i < acpi_cpus; i++) {
+            uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0x00;
+            aml_append(pkg, aml_int(b));
         }
+        aml_append(sb_scope, aml_name_decl("CPON", pkg));
 
         if (nr_mem) {
             assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
diff --git a/hw/i386/ssdt-proc.dsl b/hw/i386/ssdt-proc.dsl
deleted file mode 100644
index 8229bfd..0000000
--- a/hw/i386/ssdt-proc.dsl
+++ /dev/null
@@ -1,63 +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/>.
- */
-
-/* This file is the basis for the ssdt table generated in src/acpi.c.
- * It defines the contents of the per-cpu Processor() object.  At
- * runtime, a dynamically generated SSDT will contain one copy of this
- * AML snippet for every possible cpu in the system.  The objects will
- * be placed in the \_SB_ namespace.
- *
- * In addition to the aml code generated from this file, the
- * src/acpi.c file creates a NTFY method with an entry for each cpu:
- *     Method(NTFY, 2) {
- *         If (LEqual(Arg0, 0x00)) { Notify(CP00, Arg1) }
- *         If (LEqual(Arg0, 0x01)) { Notify(CP01, Arg1) }
- *         ...
- *     }
- * and a CPON array with the list of active and inactive cpus:
- *     Name(CPON, Package() { One, One, ..., Zero, Zero, ... })
- */
-
-ACPI_EXTRACT_ALL_CODE ssdp_proc_aml
-
-DefinitionBlock ("ssdt-proc.aml", "SSDT", 0x01, "BXPC", "BXSSDT", 0x1)
-{
-    ACPI_EXTRACT_PROCESSOR_START ssdt_proc_start
-    ACPI_EXTRACT_PROCESSOR_END ssdt_proc_end
-    ACPI_EXTRACT_PROCESSOR_STRING ssdt_proc_name
-    Processor(CPAA, 0xAA, 0x00000000, 0x0) {
-        ACPI_EXTRACT_NAME_BYTE_CONST ssdt_proc_id
-        Name(ID, 0xAA)
-/*
- * The src/acpi.c code requires the above ACP_EXTRACT tags so that it can update
- * CPAA and 0xAA with the appropriate CPU id (see
- * SD_OFFSET_CPUHEX/CPUID1/CPUID2).  Don't change the above without
- * also updating the C code.
- */
-        Name(_HID, "ACPI0007")
-        External(CPMA, MethodObj)
-        External(CPST, MethodObj)
-        External(CPEJ, MethodObj)
-        Method(_MAT, 0) {
-            Return (CPMA(ID))
-        }
-        Method(_STA, 0) {
-            Return (CPST(ID))
-        }
-        Method(_EJ0, 1, NotSerialized) {
-            CPEJ(ID, Arg0)
-        }
-    }
-}
diff --git a/hw/i386/ssdt-proc.hex.generated b/hw/i386/ssdt-proc.hex.generated
deleted file mode 100644
index 4df0734..0000000
--- a/hw/i386/ssdt-proc.hex.generated
+++ /dev/null
@@ -1,134 +0,0 @@
-static unsigned char ssdt_proc_name[] = {
-0x28
-};
-static unsigned char ssdp_proc_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0x78,
-0x0,
-0x0,
-0x0,
-0x1,
-0x7d,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x0,
-0x0,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x15,
-0x11,
-0x13,
-0x20,
-0x5b,
-0x83,
-0x42,
-0x5,
-0x43,
-0x50,
-0x41,
-0x41,
-0xaa,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0xa,
-0xaa,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xd,
-0x41,
-0x43,
-0x50,
-0x49,
-0x30,
-0x30,
-0x30,
-0x37,
-0x0,
-0x14,
-0xf,
-0x5f,
-0x4d,
-0x41,
-0x54,
-0x0,
-0xa4,
-0x43,
-0x50,
-0x4d,
-0x41,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x14,
-0xf,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0xa4,
-0x43,
-0x50,
-0x53,
-0x54,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x14,
-0xf,
-0x5f,
-0x45,
-0x4a,
-0x30,
-0x1,
-0x43,
-0x50,
-0x45,
-0x4a,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x68
-};
-static unsigned char ssdt_proc_id[] = {
-0x38
-};
-static unsigned char ssdt_proc_end[] = {
-0x78
-};
-static unsigned char ssdt_proc_start[] = {
-0x24
-};
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 39/52] pc: acpi-build: create CPU hotplug IO region dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (37 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 38/52] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 40/52] acpi: add aml_reserved_field() term Igor Mammedov
                   ` (13 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

it replaces a static complied in DSDT MMIO region
for CPU hotplug with one created at runtime
leaving only truly static CPU hotplug related ASL
bits in DSDT.
It also puts CPU_HOTPLUG_RESOURCE_DEVICE into
PCI0 scope and reserves resources from it,
preparing for dropping manual hole punching
in PCI0._CRS.

Later it also would make easier to reuse current
ACPI CPU hotplug on other targets.

Also later it would be possible to move remaining
CPU hotplug ASL methods into build_ssdt() and
add all CPU hotplug related AML into SSDT only
when CPU hotplug is enabled, further reducing
ACPI tables blob if CPU hotplug isn't used.

impl. detail:
Windows XP can't handle /BSODs/ OperationRegion
declaration in DSDT when variable from SSDT is used
for specifying its address/length and also when
Field declared in DSDT with OperationRegion from
SSDT if DSDT is being parsed before SSDT.
But it works just fine when referencing named
fields from another table. Hence OperationRegion
and Field declaration are moved to SSDT to make
XP based editions work.

PS:
Later Windows editions seem to be fine with above
conditions.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c              | 27 +++++++++++++++++++++++++++
 hw/i386/acpi-dsdt-cpu-hotplug.dsl | 17 +----------------
 include/hw/acpi/pc-hotplug.h      |  1 +
 3 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b82e636..eceba1c 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -101,6 +101,8 @@ typedef struct AcpiPmInfo {
     uint32_t gpe0_blk;
     uint32_t gpe0_blk_len;
     uint32_t io_base;
+    uint16_t cpu_hp_io_base;
+    uint16_t cpu_hp_io_len;
 } AcpiPmInfo;
 
 typedef struct AcpiMiscInfo {
@@ -175,12 +177,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 
     if (piix) {
         obj = piix;
+        pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
     }
     if (lpc) {
         obj = lpc;
+        pm->cpu_hp_io_base = ICH9_CPU_HOTPLUG_IO_BASE;
     }
     assert(obj);
 
+    pm->cpu_hp_io_len = ACPI_GPE_PROC_LEN;
     /* Fill in optional s3/s4 related properties */
     o = object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
     if (o) {
@@ -826,6 +831,28 @@ build_ssdt(Aml *table_data,
 
     sb_scope = aml_scope("_SB");
     {
+        /* 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, pm->cpu_hp_io_base, pm->cpu_hp_io_len));
+        field = aml_field("PRST", aml_byte_acc);
+        aml_append(field, aml_named_field("PRS", 256));
+        aml_append(sb_scope, field);
+
         /* build Processor object for each processor */
         for (i = 0; i < acpi_cpus; i++) {
             dev = aml_processor(i, 0, 0, "CP%.02X", i);
diff --git a/hw/i386/acpi-dsdt-cpu-hotplug.dsl b/hw/i386/acpi-dsdt-cpu-hotplug.dsl
index 268d870..1aff746 100644
--- a/hw/i386/acpi-dsdt-cpu-hotplug.dsl
+++ b/hw/i386/acpi-dsdt-cpu-hotplug.dsl
@@ -16,12 +16,12 @@
 /****************************************************************
  * CPU hotplug
  ****************************************************************/
-#define CPU_HOTPLUG_RESOURCE_DEVICE PRES
 
 Scope(\_SB) {
     /* Objects filled in by run-time generated SSDT */
     External(NTFY, MethodObj)
     External(CPON, PkgObj)
+    External(PRS, FieldUnitObj)
 
     /* Methods called by run-time generated SSDT Processor objects */
     Method(CPMA, 1, NotSerialized) {
@@ -54,10 +54,6 @@ Scope(\_SB) {
     }
 
 #define CPU_STATUS_LEN ACPI_GPE_PROC_LEN
-    OperationRegion(PRST, SystemIO, CPU_STATUS_BASE, CPU_STATUS_LEN)
-    Field(PRST, ByteAcc, NoLock, Preserve) {
-        PRS, 256
-    }
     Method(PRSC, 0) {
         // Local5 = active cpu bitmap
         Store(PRS, Local5)
@@ -91,15 +87,4 @@ Scope(\_SB) {
             Increment(Local0)
         }
     }
-
-    Device(CPU_HOTPLUG_RESOURCE_DEVICE) {
-        Name(_HID, EisaId("PNP0A06"))
-        Name(_UID, "CPU hotplug resources")
-
-        Name(_CRS, ResourceTemplate() {
-            IO(Decode16, CPU_STATUS_BASE, CPU_STATUS_BASE, 0, CPU_STATUS_LEN)
-        })
-
-        Name(_STA, 0xB) /* present, functioning, decoding, not shown in UI */
-    }
 }
diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..efa6ed7 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -28,6 +28,7 @@
 
 #define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
 #define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
+#define CPU_HOTPLUG_RESOURCE_DEVICE PRES
 
 #define ACPI_MEMORY_HOTPLUG_IO_LEN 24
 #define ACPI_MEMORY_HOTPLUG_BASE 0x0a00
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 40/52] acpi: add aml_reserved_field() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (38 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 39/52] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 41/52] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
                   ` (12 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 90c1272..1b23459 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -649,6 +649,16 @@ Aml *aml_named_field(const char *name, unsigned length)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: ReservedField */
+Aml *aml_reserved_field(unsigned length)
+{
+    Aml *var = aml_alloc();
+    /* ReservedField  := 0x00 PkgLength */
+    build_append_byte(var->buf, 0x00);
+    build_append_pkg_length(var->buf, length, false);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */
 Aml *aml_field(const char *name, AmlFieldFlags flags)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 84fe4db..a04c107 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -37,7 +37,12 @@ typedef enum {
 } AmlIODecode;
 
 typedef enum {
+    aml_any_acc = 0,
     aml_byte_acc = 1,
+    aml_word_acc = 2,
+    aml_dword_acc = 3,
+    aml_qword_acc = 4,
+    aml_buffer_acc = 5,
 } AmlFieldFlags;
 
 typedef enum {
@@ -101,6 +106,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
                           uint32_t offset, uint32_t len);
 Aml *aml_named_field(const char *name, unsigned length);
+Aml *aml_reserved_field(unsigned length);
 Aml *aml_local(int num);
 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_equal(Aml *arg1, Aml *arg2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 41/52] pc: acpi-build: drop template patching and memory hotplug objects dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (39 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 40/52] acpi: add aml_reserved_field() term Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 42/52] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
                   ` (11 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

in addition it saves us ~330LOC and makes it one binary blob less
stored in QEMU source tree by removing need to keep and update
hw/i386/ssdt-mem.hex.generated file there.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/Makefile.objs          |   2 +-
 hw/i386/acpi-build.c           | 133 +++++++++----------------
 hw/i386/ssdt-mem.dsl           |  77 ---------------
 hw/i386/ssdt-mem.hex.generated | 213 -----------------------------------------
 4 files changed, 47 insertions(+), 378 deletions(-)
 delete mode 100644 hw/i386/ssdt-mem.dsl
 delete mode 100644 hw/i386/ssdt-mem.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index a1e5aa2..6c8705d 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
 	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
     ; then echo "$(2)"; else echo "$(3)"; fi ;)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index eceba1c..18e69a7 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -281,49 +281,6 @@ build_header(GArray *linker, GArray *table_data,
                                     table_data->data, h, len, &h->checksum);
 }
 
-static GArray *build_alloc_method(const char *name, uint8_t arg_count)
-{
-    GArray *method = build_alloc_array();
-
-    build_append_namestring(method, "%s", name);
-    build_append_byte(method, arg_count); /* MethodFlags: ArgCount */
-
-    return method;
-}
-
-static void build_append_and_cleanup_method(GArray *device, GArray *method)
-{
-    uint8_t op = 0x14; /* MethodOp */
-
-    build_package(method, op);
-
-    build_append_array(device, method);
-    build_free_array(method);
-}
-
-static void build_append_notify_target_ifequal(GArray *method,
-                                               GArray *target_name,
-                                               uint32_t value)
-{
-    GArray *notify = build_alloc_array();
-    uint8_t op = 0xA0; /* IfOp */
-
-    build_append_byte(notify, 0x93); /* LEqualOp */
-    build_append_byte(notify, 0x68); /* Arg0Op */
-    build_append_int(notify, value);
-    build_append_byte(notify, 0x86); /* NotifyOp */
-    build_append_array(notify, target_name);
-    build_append_byte(notify, 0x69); /* Arg1Op */
-
-    /* Pack it up */
-    build_package(notify, op);
-
-    build_append_array(method, notify);
-
-    build_free_array(notify);
-}
-
-/* End here */
 #define ACPI_PORT_SMI_CMD           0x00b2 /* TODO: this is APM_CNT_IOPORT */
 
 static inline void *acpi_data_push(GArray *table_data, unsigned size)
@@ -514,38 +471,12 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
                  table_data->len - madt_start, 1);
 }
 
-#include "hw/i386/ssdt-mem.hex"
-
-/* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
-#define ACPI_MEM_OFFSET_HEX (*ssdt_mem_name - *ssdt_mem_start + 2)
-#define ACPI_MEM_OFFSET_ID (*ssdt_mem_id - *ssdt_mem_start + 7)
-#define ACPI_MEM_SIZEOF (*ssdt_mem_end - *ssdt_mem_start)
-#define ACPI_MEM_AML (ssdm_mem_aml + *ssdt_mem_start)
-
 #define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 #define ACPI_SSDT_HEADER_LENGTH 36
 
 #include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
-static void
-build_append_notify_method(GArray *device, const char *name,
-                           const char *format, int count)
-{
-    int i;
-    GArray *method = build_alloc_method(name, 2);
-
-    for (i = 0; i < count; i++) {
-        GArray *target = build_alloc_array();
-        build_append_namestring(target, format, i);
-        assert(i < 256); /* Fits in 1 byte */
-        build_append_notify_target_ifequal(method, target, i);
-        build_free_array(target);
-    }
-
-    build_append_and_cleanup_method(device, method);
-}
-
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
  */
@@ -904,26 +835,54 @@ build_ssdt(Aml *table_data,
         }
         aml_append(sb_scope, aml_name_decl("CPON", pkg));
 
-        if (nr_mem) {
-            assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
-            /* build memory devices */
-            for (i = 0; i < nr_mem; i++) {
-                char id[3];
-                uint8_t *mem = acpi_data_push(sb_scope->buf, ACPI_MEM_SIZEOF);
-
-                snprintf(id, sizeof(id), "%02X", i);
-                memcpy(mem, ACPI_MEM_AML, ACPI_MEM_SIZEOF);
-                memcpy(mem + ACPI_MEM_OFFSET_HEX, id, 2);
-                memcpy(mem + ACPI_MEM_OFFSET_ID, id, 2);
-            }
+        /* build memory devices */
+        assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
 
-            /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
-             *     If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
-             */
-            build_append_notify_method(sb_scope->buf,
-                                       stringify(MEMORY_SLOT_NOTIFY_METHOD),
-                                       "MP%0.02X", nr_mem);
+        for (i = 0; i < nr_mem; i++) {
+            #define BASEPATH "\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE) "."
+            const char *s;
+
+            dev = aml_device("MP%02X", i);
+            aml_append(dev, aml_name_decl("_UID", aml_string("0x%02X", i)));
+            aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C80")));
+
+            method = aml_method("_CRS", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_CRS_METHOD);
+            aml_append(method, aml_return(aml_call1(s, aml_name("_UID"))));
+            aml_append(dev, method);
+
+            method = aml_method("_STA", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_STATUS_METHOD);
+            aml_append(method, aml_return(aml_call1(s, aml_name("_UID"))));
+            aml_append(dev, method);
+
+            method = aml_method("_PXM", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_PROXIMITY_METHOD);
+            aml_append(method, aml_return(aml_call1(s, aml_name("_UID"))));
+            aml_append(dev, method);
+
+            method = aml_method("_OST", 3);
+            s = BASEPATH stringify(MEMORY_SLOT_OST_METHOD);
+            aml_append(method, aml_return(aml_call4(
+                s, aml_name("_UID"), aml_arg(0), aml_arg(1), aml_arg(2)
+            )));
+            aml_append(dev, method);
+
+            aml_append(sb_scope, dev);
+        }
+
+        /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
+         *     If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
+         */
+        method = aml_method(stringify(MEMORY_SLOT_NOTIFY_METHOD), 2);
+        for (i = 0; i < nr_mem; i++) {
+            ifctx = aml_if(aml_equal(aml_arg(0), aml_int(i)));
+            aml_append(ifctx,
+                aml_notify(aml_name("MP%.02X", i), aml_arg(1))
+            );
+            aml_append(method, ifctx);
         }
+        aml_append(sb_scope, method);
 
         {
             Object *pci_host;
diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
deleted file mode 100644
index 22ff5dd..0000000
--- a/hw/i386/ssdt-mem.dsl
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Memory hotplug ACPI DSDT static objects definitions
- *
- * Copyright ProfitBricks GmbH 2012
- * Copyright (C) 2013-2014 Red Hat Inc
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>
- */
-
-/* This file is the basis for the ssdt_mem[] variable in src/acpi.c.
- * It defines the contents of the memory device object.  At
- * runtime, a dynamically generated SSDT will contain one copy of this
- * AML snippet for every possible memory device in the system.  The
- * objects will be placed in the \_SB_ namespace.
- *
- * In addition to the aml code generated from this file, the
- * src/acpi.c file creates a MTFY method with an entry for each memdevice:
- *     Method(MTFY, 2) {
- *         If (LEqual(Arg0, 0x00)) { Notify(MP00, Arg1) }
- *         If (LEqual(Arg0, 0x01)) { Notify(MP01, Arg1) }
- *         ...
- *     }
- */
-#include "hw/acpi/pc-hotplug.h"
-
-ACPI_EXTRACT_ALL_CODE ssdm_mem_aml
-
-DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1)
-{
-
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_CRS_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, MethodObj)
-
-    Scope(\_SB) {
-/*  v------------------ DO NOT EDIT ------------------v */
-        ACPI_EXTRACT_DEVICE_START ssdt_mem_start
-        ACPI_EXTRACT_DEVICE_END ssdt_mem_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_mem_name
-        Device(MPAA) {
-            ACPI_EXTRACT_NAME_STRING ssdt_mem_id
-            Name(_UID, "0xAA")
-/*  ^------------------ DO NOT EDIT ------------------^
- * Don't change the above without also updating the C code.
- */
-            Name(_HID, EISAID("PNP0C80"))
-
-            Method(_CRS, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_CRS_METHOD(_UID))
-            }
-
-            Method(_STA, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD(_UID))
-            }
-
-            Method(_PXM, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD(_UID))
-            }
-
-            Method(_OST, 3) {
-                \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, Arg0, Arg1, Arg2)
-            }
-        }
-    }
-}
diff --git a/hw/i386/ssdt-mem.hex.generated b/hw/i386/ssdt-mem.hex.generated
deleted file mode 100644
index b3bfbbd..0000000
--- a/hw/i386/ssdt-mem.hex.generated
+++ /dev/null
@@ -1,213 +0,0 @@
-static unsigned char ssdt_mem_id[] = {
-0x35
-};
-static unsigned char ssdm_mem_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0xc7,
-0x0,
-0x0,
-0x0,
-0x2,
-0x66,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x43,
-0x53,
-0x53,
-0x44,
-0x54,
-0x0,
-0x0,
-0x0,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x28,
-0x8,
-0x14,
-0x20,
-0x10,
-0x42,
-0xa,
-0x5c,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x5b,
-0x82,
-0x49,
-0x9,
-0x4d,
-0x50,
-0x41,
-0x41,
-0x8,
-0x5f,
-0x55,
-0x49,
-0x44,
-0xd,
-0x30,
-0x78,
-0x41,
-0x41,
-0x0,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xc,
-0x80,
-0x14,
-0x1e,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x43,
-0x52,
-0x53,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x1e,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x52,
-0x53,
-0x54,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x1e,
-0x5f,
-0x50,
-0x58,
-0x4d,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x50,
-0x58,
-0x4d,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x20,
-0x5f,
-0x4f,
-0x53,
-0x54,
-0x3,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x4f,
-0x53,
-0x54,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x68,
-0x69,
-0x6a
-};
-static unsigned char ssdt_mem_start[] = {
-0x2c
-};
-static unsigned char ssdt_mem_end[] = {
-0xc7
-};
-static unsigned char ssdt_mem_name[] = {
-0x30
-};
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 42/52] pc: acpi-build: create memory hotplug IO region dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (40 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 41/52] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 43/52] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Igor Mammedov
                   ` (10 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

it replaces a static complied in DSDT MMIO region
for memory hotplug with one created at runtime
leaving only truly static memory hotplug related
ASL bits in DSDT. And replaces template patching
of MEMORY_SLOTS_NUMBER value with ASL API created
named value.

Later it also would make easier to reuse current
ACPI memory hotplug on other targets.

Also later it would be possible to move remaining
memory hotplug ASL methods into build_ssdt() and
add all memory hotplug related AML into SSDT only
when memory hotplug is enabled, further reducing
ACPI tables blob if memory hotplug isn't used.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c              | 57 ++++++++++++++++++++++++++++++++++++---
 hw/i386/acpi-dsdt-mem-hotplug.dsl | 36 +++++++------------------
 hw/i386/ssdt-misc.dsl             |  2 --
 3 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 18e69a7..256870b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -103,6 +103,8 @@ typedef struct AcpiPmInfo {
     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;
 } AcpiPmInfo;
 
 typedef struct AcpiMiscInfo {
@@ -186,6 +188,9 @@ 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;
+
     /* Fill in optional s3/s4 related properties */
     o = object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
     if (o) {
@@ -698,9 +703,6 @@ build_ssdt(Aml *table_data,
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
-    ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
-                      ssdt_mctrl_nr_slots[0], 32, nr_mem);
-
     /*  create S3_ / S4_ / S5_ packages if necessary */
     scope = aml_scope("\\");
     if (!pm->s3_disabled) {
@@ -837,6 +839,55 @@ build_ssdt(Aml *table_data,
 
         /* build memory devices */
         assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
+        scope = aml_scope("\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE));
+        aml_append(scope,
+            aml_name_decl(stringify(MEMORY_SLOTS_NUMBER), aml_int(nr_mem))
+        );
+
+        crs = aml_resource_template();
+        aml_append(crs,
+            aml_io(aml_decode16, pm->mem_hp_io_base, pm->mem_hp_io_base, 0,
+                   pm->mem_hp_io_len)
+        );
+        aml_append(scope, aml_name_decl("_CRS", crs));
+
+        aml_append(scope, aml_operation_region(
+            stringify(MEMORY_HOTPLUG_IO_REGION), aml_system_io,
+            pm->mem_hp_io_base, pm->mem_hp_io_len)
+        );
+
+        field = aml_field(stringify(MEMORY_HOTPLUG_IO_REGION), aml_dword_acc);
+        aml_append(field, /* read only */
+            aml_named_field(stringify(MEMORY_SLOT_ADDR_LOW), 32));
+        aml_append(field, /* read only */
+            aml_named_field(stringify(MEMORY_SLOT_ADDR_HIGH), 32));
+        aml_append(field, /* read only */
+            aml_named_field(stringify(MEMORY_SLOT_SIZE_LOW), 32));
+        aml_append(field, /* read only */
+            aml_named_field(stringify(MEMORY_SLOT_SIZE_HIGH), 32));
+        aml_append(field, /* read only */
+            aml_named_field(stringify(MEMORY_SLOT_PROXIMITY), 32));
+        aml_append(scope, field);
+
+        field = aml_field(stringify(MEMORY_HOTPLUG_IO_REGION), aml_byte_acc);
+        aml_append(field, aml_reserved_field(160 /* bits, Offset(20) */));
+        aml_append(field, /* 1 if enabled, read only */
+            aml_named_field(stringify(MEMORY_SLOT_ENABLED), 1));
+        aml_append(field,
+            /*(read) 1 if has a insert event. (write) 1 to clear event */
+            aml_named_field(stringify(MEMORY_SLOT_INSERT_EVENT), 1));
+        aml_append(scope, field);
+
+        field = aml_field(stringify(MEMORY_HOTPLUG_IO_REGION), aml_dword_acc);
+        aml_append(field, /* DIMM selector, write only */
+            aml_named_field(stringify(MEMORY_SLOT_SLECTOR), 32));
+        aml_append(field, /* _OST event code, write only */
+            aml_named_field(stringify(MEMORY_SLOT_OST_EVENT), 32));
+        aml_append(field, /* _OST status code, write only */
+            aml_named_field(stringify(MEMORY_SLOT_OST_STATUS), 32));
+        aml_append(scope, field);
+
+        aml_append(sb_scope, scope);
 
         for (i = 0; i < nr_mem; i++) {
             #define BASEPATH "\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE) "."
diff --git a/hw/i386/acpi-dsdt-mem-hotplug.dsl b/hw/i386/acpi-dsdt-mem-hotplug.dsl
index 2a36c47..1e9ec39 100644
--- a/hw/i386/acpi-dsdt-mem-hotplug.dsl
+++ b/hw/i386/acpi-dsdt-mem-hotplug.dsl
@@ -22,14 +22,16 @@
             External(MEMORY_SLOTS_NUMBER, IntObj)
 
             /* Memory hotplug IO registers */
-            OperationRegion(MEMORY_HOTPLUG_IO_REGION, SystemIO,
-                            ACPI_MEMORY_HOTPLUG_BASE,
-                            ACPI_MEMORY_HOTPLUG_IO_LEN)
-
-            Name(_CRS, ResourceTemplate() {
-                IO(Decode16, ACPI_MEMORY_HOTPLUG_BASE, ACPI_MEMORY_HOTPLUG_BASE,
-                   0, ACPI_MEMORY_HOTPLUG_IO_LEN, IO)
-            })
+            External(MEMORY_SLOT_ADDR_LOW, FieldUnitObj) // read only
+            External(MEMORY_SLOT_ADDR_HIGH, FieldUnitObj) // read only
+            External(MEMORY_SLOT_SIZE_LOW, FieldUnitObj) // read only
+            External(MEMORY_SLOT_SIZE_HIGH, FieldUnitObj) // read only
+            External(MEMORY_SLOT_PROXIMITY, FieldUnitObj) // read only
+            External(MEMORY_SLOT_ENABLED, FieldUnitObj) // 1 if enabled, read only
+            External(MEMORY_SLOT_INSERT_EVENT, FieldUnitObj) // (read) 1 if has a insert event. (write) 1 to clear event
+            External(MEMORY_SLOT_SLECTOR, FieldUnitObj) // DIMM selector, write only
+            External(MEMORY_SLOT_OST_EVENT, FieldUnitObj) // _OST event code, write only
+            External(MEMORY_SLOT_OST_STATUS, FieldUnitObj) // _OST status code, write only
 
             Method(_STA, 0) {
                 If (LEqual(MEMORY_SLOTS_NUMBER, Zero)) {
@@ -39,25 +41,7 @@
                 Return(0xB)
             }
 
-            Field(MEMORY_HOTPLUG_IO_REGION, DWordAcc, NoLock, Preserve) {
-                MEMORY_SLOT_ADDR_LOW, 32,  // read only
-                MEMORY_SLOT_ADDR_HIGH, 32, // read only
-                MEMORY_SLOT_SIZE_LOW, 32,  // read only
-                MEMORY_SLOT_SIZE_HIGH, 32, // read only
-                MEMORY_SLOT_PROXIMITY, 32, // read only
-            }
-            Field(MEMORY_HOTPLUG_IO_REGION, ByteAcc, NoLock, Preserve) {
-                Offset(20),
-                MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
-                MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert event. (write) 1 to clear event
-            }
-
             Mutex (MEMORY_SLOT_LOCK, 0)
-            Field (MEMORY_HOTPLUG_IO_REGION, DWordAcc, NoLock, Preserve) {
-                MEMORY_SLOT_SLECTOR, 32,  // DIMM selector, write only
-                MEMORY_SLOT_OST_EVENT, 32,  // _OST event code, write only
-                MEMORY_SLOT_OST_STATUS, 32,  // _OST status code, write only
-            }
 
             Method(MEMORY_SLOT_SCAN_METHOD, 0) {
                 If (LEqual(MEMORY_SLOTS_NUMBER, Zero)) {
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 81be858..2588e30 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -36,7 +36,5 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
        Name(P1E, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
        ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_length
        Name(P1L, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
-       ACPI_EXTRACT_NAME_DWORD_CONST ssdt_mctrl_nr_slots
-       Name(MEMORY_SLOTS_NUMBER, 0x12345678)
     }
 }
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 43/52] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (41 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 42/52] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 44/52] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
                   ` (9 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 1b23459..bfebdb4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -755,3 +755,164 @@ Aml *aml_eisaid(const char *str)
     build_append_value(var->buf, bswap32(id), sizeof(id));
     return var;
 }
+
+/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor: bytes 3-5 */
+static Aml *aml_as_desc_header(AmlResourceType type, AmlMinFixed min_fixed,
+                               AmlMaxFixed max_fixed, AmlDecode dec,
+                               uint8_t type_flags)
+{
+    uint8_t flags = max_fixed | min_fixed | dec;
+    Aml *var = aml_alloc();
+
+    build_append_byte(var->buf, type);
+    build_append_byte(var->buf, flags);
+    build_append_byte(var->buf, type_flags); /* Type Specific Flags */
+    return var;
+}
+
+/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor */
+static Aml *aml_word_as_desc(AmlResourceType type, AmlMinFixed min_fixed,
+                             AmlMaxFixed max_fixed, AmlDecode dec,
+                             uint16_t addr_gran, uint16_t addr_min,
+                             uint16_t addr_max, uint16_t addr_trans,
+                             uint16_t len, uint8_t type_flags)
+{
+    Aml *var = aml_alloc();
+
+    build_append_byte(var->buf, 0x88); /* Word Address Space Descriptor */
+    /* minimum length since we do not encode optional fields */
+    build_append_byte(var->buf, 0x0D);
+    build_append_byte(var->buf, 0x0);
+
+    aml_append(var,
+        aml_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+    build_append_value(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_value(var->buf, addr_min, sizeof(addr_min));
+    build_append_value(var->buf, addr_max, sizeof(addr_max));
+    build_append_value(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_value(var->buf, len, sizeof(len));
+    return var;
+}
+
+/* ACPI 1.0b: 6.4.3.5.3 DWord Address Space Descriptor */
+static Aml *aml_dword_as_desc(AmlResourceType type, AmlMinFixed min_fixed,
+                              AmlMaxFixed max_fixed, AmlDecode dec,
+                              uint32_t addr_gran, uint32_t addr_min,
+                              uint32_t addr_max, uint32_t addr_trans,
+                              uint32_t len, uint8_t type_flags)
+{
+    Aml *var = aml_alloc();
+
+    build_append_byte(var->buf, 0x87); /* DWord Address Space Descriptor */
+    /* minimum length since we do not encode optional fields */
+    build_append_byte(var->buf, 23);
+    build_append_byte(var->buf, 0x0);
+
+
+    aml_append(var,
+        aml_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+    build_append_value(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_value(var->buf, addr_min, sizeof(addr_min));
+    build_append_value(var->buf, addr_max, sizeof(addr_max));
+    build_append_value(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_value(var->buf, len, sizeof(len));
+    return var;
+}
+
+/* ACPI 1.0b: 6.4.3.5.1 QWord Address Space Descriptor */
+static Aml *aml_qword_as_desc(AmlResourceType type, AmlMinFixed min_fixed,
+                              AmlMaxFixed max_fixed, AmlDecode dec,
+                              uint64_t addr_gran, uint64_t addr_min,
+                              uint64_t addr_max, uint64_t addr_trans,
+                              uint64_t len, uint8_t type_flags)
+{
+    Aml *var = aml_alloc();
+
+    build_append_byte(var->buf, 0x8A); /* QWord Address Space Descriptor */
+    /* minimum length since we do not encode optional fields */
+    build_append_byte(var->buf, 0x2B);
+    build_append_byte(var->buf, 0x0);
+
+    aml_append(var,
+        aml_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+    build_append_value(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_value(var->buf, addr_min, sizeof(addr_min));
+    build_append_value(var->buf, addr_max, sizeof(addr_max));
+    build_append_value(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_value(var->buf, len, sizeof(len));
+    return var;
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.141 WordBusNumber (Word Bus Number Resource Descriptor Macro)
+ */
+Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
+                         AmlDecode dec, uint16_t addr_gran,
+                         uint16_t addr_min, uint16_t addr_max,
+                         uint16_t addr_trans, uint16_t len)
+
+{
+    return aml_word_as_desc(aml_bus_number_range, min_fixed, max_fixed, dec,
+                            addr_gran, addr_min, addr_max, addr_trans, len, 0);
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.142 WordIO (Word IO Resource Descriptor Macro)
+ */
+Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
+                 AmlDecode dec, AmlISARanges isa_ranges,
+                 uint16_t addr_gran, uint16_t addr_min,
+                 uint16_t addr_max, uint16_t addr_trans,
+                 uint16_t len)
+
+{
+    return aml_word_as_desc(aml_io_range, min_fixed, max_fixed, dec,
+                            addr_gran, addr_min, addr_max, addr_trans, len,
+                            isa_ranges);
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.4 ASL Macros for DWORD Address Space Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.34 DWordMemory (DWord Memory Resource Descriptor Macro)
+ */
+Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint32_t addr_gran, uint32_t addr_min,
+                      uint32_t addr_max, uint32_t addr_trans,
+                      uint32_t len)
+{
+    uint8_t flags = read_and_write | (cacheable << 1);
+
+    return aml_dword_as_desc(aml_memory_range, min_fixed, max_fixed,
+                             dec, addr_gran, addr_min, addr_max,
+                             addr_trans, len, flags);
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.2 ASL Macros for QWORD Address Space Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.102 QWordMemory (QWord Memory Resource Descriptor Macro)
+ */
+Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint64_t addr_gran, uint64_t addr_min,
+                      uint64_t addr_max, uint64_t addr_trans,
+                      uint64_t len)
+{
+    uint8_t flags = read_and_write | (cacheable << 1);
+
+    return aml_qword_as_desc(aml_memory_range, min_fixed, max_fixed,
+                             dec, addr_gran, addr_min, addr_max,
+                             addr_trans, len, flags);
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index a04c107..0f499a6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -50,6 +50,57 @@ typedef enum {
     aml_system_io = 0x01,
 } AmlRegionSpace;
 
+typedef enum {
+    aml_memory_range = 0,
+    aml_io_range = 1,
+    aml_bus_number_range = 2,
+} AmlResourceType;
+
+typedef enum {
+    aml_sub_decode = 1 << 1,
+    aml_pos_decode = 0
+} AmlDecode;
+
+typedef enum {
+    aml_max_fixed = 1 << 3,
+    aml_max_not_fixed = 0,
+} AmlMaxFixed;
+
+typedef enum {
+    aml_min_fixed = 1 << 2,
+    aml_min_not_fixed = 0
+} AmlMinFixed;
+
+/*
+ * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions
+ * _RNG field definition
+ */
+typedef enum {
+    aml_isa_only = 1,
+    aml_non_isa_only = 2,
+    aml_entire_range = 3,
+} AmlISARanges;
+
+/*
+ * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
+ * _MEM field definition
+ */
+typedef enum {
+    aml_non_cacheable = 0,
+    aml_cacheable = 1,
+    aml_write_combining = 2,
+    aml_prefetchable = 3,
+} AmlCacheble;
+
+/*
+ * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
+ * _RW field definition
+ */
+typedef enum {
+    aml_ReadOnly = 0,
+    aml_ReadWrite = 1,
+} AmlReadAndWrite;
+
 /**
  * init_aml_allocator:
  * @linker: linker that used by API for registering ACPI tables
@@ -113,6 +164,27 @@ Aml *aml_equal(Aml *arg1, Aml *arg2);
 Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
                    const char *name_format, ...) GCC_FMT_ATTR(4, 5);
 Aml *aml_eisaid(const char *str);
+Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
+                         AmlDecode dec, uint16_t addr_gran,
+                         uint16_t addr_min, uint16_t addr_max,
+                         uint16_t addr_trans, uint16_t len);
+Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
+                 AmlDecode dec, AmlISARanges isa_ranges,
+                 uint16_t addr_gran, uint16_t addr_min,
+                 uint16_t addr_max, uint16_t addr_trans,
+                 uint16_t len);
+Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint32_t addr_gran, uint32_t addr_min,
+                      uint32_t addr_max, uint32_t addr_trans,
+                      uint32_t len);
+Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint64_t addr_gran, uint64_t addr_min,
+                      uint64_t addr_max, uint64_t addr_trans,
+                      uint64_t len);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 44/52] pc: pcihp: expose MMIO base and len as properties
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (42 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 43/52] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 45/52] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
                   ` (8 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

it will be used later to dynamically reserve MMIO region
instead of manually punching holes in PCI0._CRS

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/pcihp.c         | 18 ++++++++++++------
 hw/acpi/piix4.c         |  2 +-
 include/hw/acpi/pcihp.h |  7 ++++++-
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 34dedf1..612fec0 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -297,10 +297,11 @@ static const MemoryRegionOps acpi_pcihp_io_ops = {
     },
 };
 
-void acpi_pcihp_init(AcpiPciHpState *s, PCIBus *root_bus,
+void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus,
                      MemoryRegion *address_space_io, bool bridges_enabled)
 {
-    uint16_t io_size = ACPI_PCIHP_SIZE;
+    s->io_len = ACPI_PCIHP_SIZE;
+    s->io_base = ACPI_PCIHP_ADDR;
 
     s->root= root_bus;
     s->legacy_piix = !bridges_enabled;
@@ -308,16 +309,21 @@ void acpi_pcihp_init(AcpiPciHpState *s, PCIBus *root_bus,
     if (s->legacy_piix) {
         unsigned *bus_bsel = g_malloc(sizeof *bus_bsel);
 
-        io_size = ACPI_PCIHP_LEGACY_SIZE;
+        s->io_len = ACPI_PCIHP_LEGACY_SIZE;
 
         *bus_bsel = ACPI_PCIHP_BSEL_DEFAULT;
         object_property_add_uint32_ptr(OBJECT(root_bus), ACPI_PCIHP_PROP_BSEL,
                                        bus_bsel, NULL);
     }
 
-    memory_region_init_io(&s->io, NULL, &acpi_pcihp_io_ops, s,
-                          "acpi-pci-hotplug", io_size);
-    memory_region_add_subregion(address_space_io, ACPI_PCIHP_ADDR, &s->io);
+    memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s,
+                          "acpi-pci-hotplug", s->io_len);
+    memory_region_add_subregion(address_space_io, s->io_base, &s->io);
+
+    object_property_add_uint16_ptr(owner, ACPI_PCIHP_IO_BASE_PROP, &s->io_base,
+                                   &error_abort);
+    object_property_add_uint16_ptr(owner, ACPI_PCIHP_IO_LEN_PROP, &s->io_len,
+                                   &error_abort);
 }
 
 const VMStateDescription vmstate_acpi_pcihp_pci_status = {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 766f1b8..d1f1179 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -562,7 +562,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
                           "acpi-gpe0", GPE_LEN);
     memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
 
-    acpi_pcihp_init(&s->acpi_pci_hotplug, bus, 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,
diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
index 9323838..f3526d4 100644
--- a/include/hw/acpi/pcihp.h
+++ b/include/hw/acpi/pcihp.h
@@ -32,6 +32,9 @@
 #include "hw/acpi/acpi.h"
 #include "migration/vmstate.h"
 
+#define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"
+#define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"
+
 typedef struct AcpiPciHpPciStatus {
     uint32_t up;
     uint32_t down;
@@ -48,9 +51,11 @@ typedef struct AcpiPciHpState {
     PCIBus *root;
     MemoryRegion io;
     bool legacy_piix;
+    uint16_t io_base;
+    uint16_t io_len;
 } AcpiPciHpState;
 
-void acpi_pcihp_init(AcpiPciHpState *, PCIBus *root,
+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,
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 45/52] pc: acpi-build: reserve PCIHP MMIO resources
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (43 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 44/52] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 46/52] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
                   ` (7 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 256870b..e195017 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -105,6 +105,8 @@ typedef struct AcpiPmInfo {
     uint16_t cpu_hp_io_len;
     uint16_t mem_hp_io_base;
     uint16_t mem_hp_io_len;
+    uint16_t pcihp_io_base;
+    uint16_t pcihp_io_len;
 } AcpiPmInfo;
 
 typedef struct AcpiMiscInfo {
@@ -177,9 +179,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
     Object *obj = NULL;
     QObject *o;
 
+    pm->pcihp_io_base = 0;
+    pm->pcihp_io_len = 0;
     if (piix) {
         obj = piix;
         pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
+        pm->pcihp_io_base =
+            object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP, NULL);
+        pm->pcihp_io_len =
+            object_property_get_int(obj, ACPI_PCIHP_IO_LEN_PROP, NULL);
     }
     if (lpc) {
         obj = lpc;
@@ -703,6 +711,25 @@ build_ssdt(Aml *table_data,
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
+    scope = aml_scope("\\_SB.PCI0");
+    /* reserve PCIHP resources */
+    if (pm->pcihp_io_len) {
+        dev = aml_device("PHPR");
+        aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A06")));
+        aml_append(dev,
+            aml_name_decl("_UID", aml_string("PCI 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->pcihp_io_base, pm->pcihp_io_base, 1,
+                   pm->pcihp_io_len)
+        );
+        aml_append(dev, aml_name_decl("_CRS", crs));
+        aml_append(scope, dev);
+    }
+    aml_append(ssdt, scope);
+
     /*  create S3_ / S4_ / S5_ packages if necessary */
     scope = aml_scope("\\");
     if (!pm->s3_disabled) {
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 46/52] pc: acpi-build: create PCI0._CRS dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (44 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 45/52] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block() Igor Mammedov
                   ` (6 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

Replace template patching and runtime
calculation in _CRS() method with static _CRS
defined in SSDT.

It also drops manual hole patching for reserved
PCI/MEM/CPU hoptlug MMIO resources and utilizes
the fact that MMIO resources are reserved by
respective child /i.e. PHPR, MHPD, PRES/ containers.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c          | 69 ++++++++++++++++----------------
 hw/i386/acpi-dsdt-pci-crs.dsl | 92 -------------------------------------------
 hw/i386/acpi-dsdt.dsl         | 45 ---------------------
 hw/i386/q35-acpi-dsdt.dsl     | 18 ---------
 hw/i386/ssdt-misc.dsl         | 19 ---------
 5 files changed, 33 insertions(+), 210 deletions(-)
 delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index e195017..bead77e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -319,24 +319,6 @@ static void acpi_align_size(GArray *blob, unsigned align)
     g_array_set_size(blob, ROUND_UP(acpi_data_len(blob), align));
 }
 
-/* Set a value within table in a safe manner */
-#define ACPI_BUILD_SET_LE(table, size, off, bits, val) \
-    do { \
-        uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \
-        memcpy(acpi_data_get_ptr(table, size, off, \
-                                 (bits) / BITS_PER_BYTE), \
-               &ACPI_BUILD_SET_LE_val, \
-               (bits) / BITS_PER_BYTE); \
-    } while (0)
-
-static inline void *acpi_data_get_ptr(uint8_t *table_data, unsigned table_size,
-                                      unsigned off, unsigned size)
-{
-    assert(off + size > off);
-    assert(off + size <= table_size);
-    return table_data + off;
-}
-
 static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
 {
     uint32_t offset = cpu_to_le32(table_data->len);
@@ -664,22 +646,6 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
     aml_append(parent_scope, method);
 }
 
-static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
-{
-    ACPI_BUILD_SET_LE(start, size, acpi_pci32_start[0], 32, pci->w32.begin);
-
-    ACPI_BUILD_SET_LE(start, size, acpi_pci32_end[0], 32, pci->w32.end - 1);
-
-    if (pci->w64.end || pci->w64.begin) {
-        ACPI_BUILD_SET_LE(start, size, acpi_pci64_valid[0], 8, 1);
-        ACPI_BUILD_SET_LE(start, size, acpi_pci64_start[0], 64, pci->w64.begin);
-        ACPI_BUILD_SET_LE(start, size, acpi_pci64_end[0], 64, pci->w64.end - 1);
-        ACPI_BUILD_SET_LE(start, size, acpi_pci64_length[0], 64, pci->w64.end - pci->w64.begin);
-    } else {
-        ACPI_BUILD_SET_LE(start, size, acpi_pci64_valid[0], 8, 0);
-    }
-}
-
 static void
 build_ssdt(Aml *table_data,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -709,9 +675,40 @@ build_ssdt(Aml *table_data,
            ssdp_misc_aml + sizeof(AcpiTableHeader),
            sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
 
-    patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
-
     scope = aml_scope("\\_SB.PCI0");
+    /* build PCI0._CRS */
+    crs = aml_resource_template();
+    aml_append(crs,
+        aml_word_bus_number(aml_min_fixed, aml_max_fixed, aml_pos_decode,
+                            0x0000, 0x0000, 0x00FF, 0x0000, 0x0100));
+    aml_append(crs, aml_io(aml_decode16, 0x0CF8, 0x0CF8, 0x01, 0x08));
+
+    aml_append(crs,
+        aml_word_io(aml_min_fixed, aml_max_fixed,
+                    aml_pos_decode, aml_entire_range,
+                    0x0000, 0x0000, 0x0CF7, 0x0000, 0x0CF8));
+    aml_append(crs,
+        aml_word_io(aml_min_fixed, aml_max_fixed,
+                    aml_pos_decode, aml_entire_range,
+                    0x0000, 0x0D00, 0xFFFF, 0x0000, 0xF300));
+    aml_append(crs,
+        aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+                         aml_cacheable, aml_ReadWrite,
+                         0, 0x000A0000, 0x000BFFFF, 0, 0x00020000));
+    aml_append(crs,
+        aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+                         aml_non_cacheable, aml_ReadWrite,
+                         0, pci->w32.begin, pci->w32.end - 1, 0,
+                         pci->w32.end - pci->w32.begin));
+    if (pci->w64.begin) {
+        aml_append(crs,
+            aml_qword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+                             aml_cacheable, aml_ReadWrite,
+                             0, pci->w64.begin, pci->w64.end - 1, 0,
+                             pci->w64.end - pci->w64.begin));
+    }
+    aml_append(scope, aml_name_decl("_CRS", crs));
+
     /* reserve PCIHP resources */
     if (pm->pcihp_io_len) {
         dev = aml_device("PHPR");
diff --git a/hw/i386/acpi-dsdt-pci-crs.dsl b/hw/i386/acpi-dsdt-pci-crs.dsl
deleted file mode 100644
index 4648e90..0000000
--- a/hw/i386/acpi-dsdt-pci-crs.dsl
+++ /dev/null
@@ -1,92 +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/>.
- */
-
-/* PCI CRS (current resources) definition. */
-Scope(\_SB.PCI0) {
-
-    Name(CRES, ResourceTemplate() {
-        WordBusNumber(ResourceProducer, MinFixed, MaxFixed, PosDecode,
-            0x0000,             // Address Space Granularity
-            0x0000,             // Address Range Minimum
-            0x00FF,             // Address Range Maximum
-            0x0000,             // Address Translation Offset
-            0x0100,             // Address Length
-            ,, )
-        IO(Decode16,
-            0x0CF8,             // Address Range Minimum
-            0x0CF8,             // Address Range Maximum
-            0x01,               // Address Alignment
-            0x08,               // Address Length
-            )
-        BOARD_SPECIFIC_PCI_RESOURSES
-        DWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
-            0x00000000,         // Address Space Granularity
-            0x000A0000,         // Address Range Minimum
-            0x000BFFFF,         // Address Range Maximum
-            0x00000000,         // Address Translation Offset
-            0x00020000,         // Address Length
-            ,, , AddressRangeMemory, TypeStatic)
-        DWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
-            0x00000000,         // Address Space Granularity
-            0xE0000000,         // Address Range Minimum
-            0xFEBFFFFF,         // Address Range Maximum
-            0x00000000,         // Address Translation Offset
-            0x1EC00000,         // Address Length
-            ,, PW32, AddressRangeMemory, TypeStatic)
-    })
-
-    Name(CR64, ResourceTemplate() {
-        QWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
-            0x00000000,          // Address Space Granularity
-            0x8000000000,        // Address Range Minimum
-            0xFFFFFFFFFF,        // Address Range Maximum
-            0x00000000,          // Address Translation Offset
-            0x8000000000,        // Address Length
-            ,, PW64, AddressRangeMemory, TypeStatic)
-    })
-
-    Method(_CRS, 0) {
-        /* Fields provided by dynamically created ssdt */
-        External(P0S, IntObj)
-        External(P0E, IntObj)
-        External(P1V, IntObj)
-        External(P1S, BuffObj)
-        External(P1E, BuffObj)
-        External(P1L, BuffObj)
-
-        /* fixup 32bit pci io window */
-        CreateDWordField(CRES, \_SB.PCI0.PW32._MIN, PS32)
-        CreateDWordField(CRES, \_SB.PCI0.PW32._MAX, PE32)
-        CreateDWordField(CRES, \_SB.PCI0.PW32._LEN, PL32)
-        Store(P0S, PS32)
-        Store(P0E, PE32)
-        Store(Add(Subtract(P0E, P0S), 1), PL32)
-
-        If (LEqual(P1V, Zero)) {
-            Return (CRES)
-        }
-
-        /* fixup 64bit pci io window */
-        CreateQWordField(CR64, \_SB.PCI0.PW64._MIN, PS64)
-        CreateQWordField(CR64, \_SB.PCI0.PW64._MAX, PE64)
-        CreateQWordField(CR64, \_SB.PCI0.PW64._LEN, PL64)
-        Store(P1S, PS64)
-        Store(P1E, PE64)
-        Store(P1L, PL64)
-        /* add window and return result */
-        ConcatenateResTemplate(CRES, CR64, Local0)
-        Return (Local0)
-    }
-}
diff --git a/hw/i386/acpi-dsdt.dsl b/hw/i386/acpi-dsdt.dsl
index a611e07..09b68f0 100644
--- a/hw/i386/acpi-dsdt.dsl
+++ b/hw/i386/acpi-dsdt.dsl
@@ -31,50 +31,6 @@ DefinitionBlock (
 
 #include "acpi-dsdt-dbug.dsl"
 
-
-/****************************************************************
- * PCI Bus definition
- ****************************************************************/
-#define BOARD_SPECIFIC_PCI_RESOURSES \
-     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
-         0x0000, \
-         0x0000, \
-         0x0CF7, \
-         0x0000, \
-         0x0CF8, \
-         ,, , TypeStatic) \
-     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
-         0x0000, \
-         0x0D00, \
-         0xADFF, \
-         0x0000, \
-         0xA100, \
-         ,, , TypeStatic) \
-     /* 0xae00-0xae0e hole for PCI hotplug, hw/acpi/piix4.c:PCI_HOTPLUG_ADDR */ \
-     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
-         0x0000, \
-         0xAE0F, \
-         0xAEFF, \
-         0x0000, \
-         0x00F1, \
-         ,, , TypeStatic) \
-     /* 0xaf00-0xaf1f hole for CPU hotplug, hw/acpi/piix4.c:PIIX4_PROC_BASE */ \
-     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
-         0x0000, \
-         0xAF20, \
-         0xAFDF, \
-         0x0000, \
-         0x00C0, \
-         ,, , TypeStatic) \
-     /* 0xafe0-0xafe3 hole for ACPI.GPE0, hw/acpi/piix4.c:GPE_BASE */ \
-     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
-         0x0000, \
-         0xAFE4, \
-         0xFFFF, \
-         0x0000, \
-         0x501C, \
-         ,, , TypeStatic)
-
     Scope(\_SB) {
         Device(PCI0) {
             Name(_HID, EisaId("PNP0A03"))
@@ -85,7 +41,6 @@ DefinitionBlock (
         }
     }
 
-#include "acpi-dsdt-pci-crs.dsl"
 #include "acpi-dsdt-hpet.dsl"
 
 
diff --git a/hw/i386/q35-acpi-dsdt.dsl b/hw/i386/q35-acpi-dsdt.dsl
index e1cee5d..3fb4b2f 100644
--- a/hw/i386/q35-acpi-dsdt.dsl
+++ b/hw/i386/q35-acpi-dsdt.dsl
@@ -48,23 +48,6 @@ DefinitionBlock (
 /****************************************************************
  * PCI Bus definition
  ****************************************************************/
-#define BOARD_SPECIFIC_PCI_RESOURSES \
-     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
-         0x0000, \
-         0x0000, \
-         0x0CD7, \
-         0x0000, \
-         0x0CD8, \
-         ,, , TypeStatic) \
-     /* 0xcd8-0xcf7 hole for CPU hotplug, hw/acpi/ich9.c:ICH9_PROC_BASE */ \
-     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
-         0x0000, \
-         0x0D00, \
-         0xFFFF, \
-         0x0000, \
-         0xF300, \
-         ,, , TypeStatic)
-
     Scope(\_SB) {
         Device(PCI0) {
             Name(_HID, EisaId("PNP0A08"))
@@ -131,7 +114,6 @@ DefinitionBlock (
         }
     }
 
-#include "acpi-dsdt-pci-crs.dsl"
 #include "acpi-dsdt-hpet.dsl"
 
 
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 2588e30..8d61f21 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -18,23 +18,4 @@ ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
 
 DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
 {
-
-/****************************************************************
- * PCI memory ranges
- ****************************************************************/
-
-    Scope(\) {
-       ACPI_EXTRACT_NAME_DWORD_CONST acpi_pci32_start
-       Name(P0S, 0x12345678)
-       ACPI_EXTRACT_NAME_DWORD_CONST acpi_pci32_end
-       Name(P0E, 0x12345678)
-       ACPI_EXTRACT_NAME_BYTE_CONST acpi_pci64_valid
-       Name(P1V, 0x12)
-       ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_start
-       Name(P1S, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
-       ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_end
-       Name(P1E, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
-       ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_length
-       Name(P1L, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
-    }
 }
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (45 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 46/52] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-17 16:44   ` Michael S. Tsirkin
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 48/52] acpi: add acpi_irq_no_flags() term Igor Mammedov
                   ` (5 subsequent siblings)
  52 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

It completes dynamic SSDT generation and makes it
independed of IASL binary blobs. It also hides
from user all pointer arithmetic when building
SSDT which makes resulting code a bit cleaner
and concentrating only on composing ASL construct
/i.e. a task build_ssdt() should be doing/.

Also it makes one binary blob less stored in QEMU
source tree by removing need to keep and update
hw/i386/ssdt-misc.hex.generated file here in total
saving us ~430LOC.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/Makefile.objs           |   2 +-
 hw/i386/acpi-build.c            |  12 --
 hw/i386/ssdt-misc.dsl           |  21 ---
 hw/i386/ssdt-misc.hex.generated | 399 ----------------------------------------
 4 files changed, 1 insertion(+), 433 deletions(-)
 delete mode 100644 hw/i386/ssdt-misc.dsl
 delete mode 100644 hw/i386/ssdt-misc.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 6c8705d..dc8c38a 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+	hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index bead77e..14c1c7d 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
                  table_data->len - madt_start, 1);
 }
 
-#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
-#define ACPI_SSDT_HEADER_LENGTH 36
-
-#include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
@@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,
     MachineState *machine = MACHINE(qdev_get_machine());
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
-    uint8_t *ssdt_ptr;
     Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
     int i;
 
@@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,
                          ACPI_BUILD_APPNAME4, 1,
                          ACPI_BUILD_APPNAME4_HEX, 1);
 
-    /* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
-    acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
-    ssdt_ptr = (uint8_t *)ssdt->buf->data;
-    memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
-           ssdp_misc_aml + sizeof(AcpiTableHeader),
-           sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
-
     scope = aml_scope("\\_SB.PCI0");
     /* build PCI0._CRS */
     crs = aml_resource_template();
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
deleted file mode 100644
index 8d61f21..0000000
--- a/hw/i386/ssdt-misc.dsl
+++ /dev/null
@@ -1,21 +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 "hw/acpi/pc-hotplug.h"
-
-ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
-
-DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
-{
-}
diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
deleted file mode 100644
index cbcf61d..0000000
--- a/hw/i386/ssdt-misc.hex.generated
+++ /dev/null
@@ -1,399 +0,0 @@
-static unsigned char acpi_pci64_length[] = {
-0x6f
-};
-static unsigned char acpi_s4_pkg[] = {
-0x99
-};
-static unsigned char ssdt_mctrl_nr_slots[] = {
-0x7d
-};
-static unsigned char acpi_s3_name[] = {
-0x86
-};
-static unsigned char acpi_pci32_start[] = {
-0x2f
-};
-static unsigned char acpi_pci64_valid[] = {
-0x43
-};
-static unsigned char ssdp_misc_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0x6c,
-0x1,
-0x0,
-0x0,
-0x1,
-0x3,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x53,
-0x55,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x28,
-0x8,
-0x14,
-0x20,
-0x10,
-0x4c,
-0x5,
-0x5c,
-0x0,
-0x8,
-0x50,
-0x30,
-0x53,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x30,
-0x45,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x31,
-0x56,
-0x5f,
-0xa,
-0x12,
-0x8,
-0x50,
-0x31,
-0x53,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x50,
-0x31,
-0x4c,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x4d,
-0x44,
-0x4e,
-0x52,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x10,
-0x29,
-0x5c,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x33,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x1,
-0x1,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x34,
-0x5f,
-0x12,
-0x8,
-0x4,
-0xa,
-0x2,
-0xa,
-0x2,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x35,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x0,
-0x0,
-0x0,
-0x0,
-0x10,
-0x40,
-0xc,
-0x5c,
-0x2f,
-0x3,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x49,
-0x53,
-0x41,
-0x5f,
-0x5b,
-0x82,
-0x4d,
-0xa,
-0x50,
-0x45,
-0x56,
-0x54,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xd,
-0x51,
-0x45,
-0x4d,
-0x55,
-0x30,
-0x30,
-0x30,
-0x31,
-0x0,
-0x8,
-0x50,
-0x45,
-0x53,
-0x54,
-0xb,
-0xff,
-0xff,
-0x5b,
-0x80,
-0x50,
-0x45,
-0x4f,
-0x52,
-0x1,
-0x50,
-0x45,
-0x53,
-0x54,
-0x1,
-0x5b,
-0x81,
-0xb,
-0x50,
-0x45,
-0x4f,
-0x52,
-0x1,
-0x50,
-0x45,
-0x50,
-0x54,
-0x8,
-0x14,
-0x18,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x60,
-0xa0,
-0x6,
-0x93,
-0x60,
-0x0,
-0xa4,
-0x0,
-0xa1,
-0x4,
-0xa4,
-0xa,
-0xf,
-0x14,
-0xe,
-0x52,
-0x44,
-0x50,
-0x54,
-0x0,
-0x70,
-0x50,
-0x45,
-0x50,
-0x54,
-0x60,
-0xa4,
-0x60,
-0x14,
-0xc,
-0x57,
-0x52,
-0x50,
-0x54,
-0x1,
-0x70,
-0x68,
-0x50,
-0x45,
-0x50,
-0x54,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x1,
-0x79,
-0x0,
-0x8b,
-0x5f,
-0x43,
-0x52,
-0x53,
-0xa,
-0x2,
-0x49,
-0x4f,
-0x4d,
-0x4e,
-0x8b,
-0x5f,
-0x43,
-0x52,
-0x53,
-0xa,
-0x4,
-0x49,
-0x4f,
-0x4d,
-0x58,
-0x14,
-0x18,
-0x5f,
-0x49,
-0x4e,
-0x49,
-0x0,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x49,
-0x4f,
-0x4d,
-0x4e,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x49,
-0x4f,
-0x4d,
-0x58
-};
-static unsigned char ssdt_isa_pest[] = {
-0xda
-};
-static unsigned char acpi_s4_name[] = {
-0x92
-};
-static unsigned char acpi_pci64_start[] = {
-0x4d
-};
-static unsigned char acpi_pci64_end[] = {
-0x5e
-};
-static unsigned char acpi_pci32_end[] = {
-0x39
-};
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 48/52] acpi: add acpi_irq_no_flags() term
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (46 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block() Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 49/52] pc: export applesmc IO port/len Igor Mammedov
                   ` (4 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index bfebdb4..3f87d51 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -554,6 +554,27 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
     return var;
 }
 
+/*
+ * ACPI 1.0b: 6.4.2.1.1 ASL Macro for IRQ Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro)
+ *           6.4.2.1 IRQ Descriptor
+ */
+Aml *aml_irq_no_flags(uint8_t irq)
+{
+    uint16_t irq_mask;
+    Aml *var = aml_alloc();
+
+    assert(irq < 16);
+    build_append_byte(var->buf, 0x22); /* IRQ descriptor 2 byte form */
+
+    irq_mask = 1U << irq;
+    build_append_byte(var->buf, irq_mask & 0xFF); /* IRQ mask bits[7:0] */
+    build_append_byte(var->buf, irq_mask >> 8); /* IRQ mask bits[15:8] */
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */
 Aml *aml_equal(Aml *arg1, Aml *arg2)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 0f499a6..44cb7ea 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -156,6 +156,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
             uint8_t aln, uint8_t len);
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
                           uint32_t offset, uint32_t len);
+Aml *aml_irq_no_flags(uint8_t irq);
 Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_reserved_field(unsigned length);
 Aml *aml_local(int num);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 49/52] pc: export applesmc IO port/len
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (47 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 48/52] acpi: add acpi_irq_no_flags() term Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 50/52] pc: acpi-build: drop template patching and create Device(SMC) dynamically Igor Mammedov
                   ` (3 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

IO port and length will be used in following patch
to correctly generate SMC ACPI device in SSDT.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c |  2 +-
 hw/misc/applesmc.c   |  5 ++---
 include/hw/isa/isa.h | 11 +++++++++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 14c1c7d..26076dd 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -144,7 +144,7 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
 
     /* Patch in appropriate value for AppleSMC _STA */
     *(uint8_t *)(info->dsdt_code + *applesmc_sta) =
-        applesmc_find() ? 0x0b : 0x00;
+        applesmc_port() ? 0x0b : 0x00;
 }
 
 static
diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 6a56b07..6bd61e7 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -43,7 +43,6 @@
 /* command/status port used by Apple SMC */
 #define APPLESMC_CMD_PORT              0x4
 #define APPLESMC_NR_PORTS              32
-#define APPLESMC_MAX_DATA_LENGTH       32
 
 #define APPLESMC_READ_CMD              0x10
 #define APPLESMC_WRITE_CMD             0x11
@@ -249,8 +248,8 @@ static void applesmc_isa_realize(DeviceState *dev, Error **errp)
 }
 
 static Property applesmc_isa_properties[] = {
-    DEFINE_PROP_UINT32("iobase", AppleSMCState, iobase,
-                      APPLESMC_DEFAULT_IOBASE),
+    DEFINE_PROP_UINT32(APPLESMC_PROP_IO_BASE, AppleSMCState, iobase,
+                       APPLESMC_DEFAULT_IOBASE),
     DEFINE_PROP_STRING("osk", AppleSMCState, osk),
     DEFINE_PROP_END_OF_LIST(),
 };
diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h
index e0c749f..1ee9fa0 100644
--- a/include/hw/isa/isa.h
+++ b/include/hw/isa/isa.h
@@ -21,10 +21,17 @@
 #define ISA_BUS(obj) OBJECT_CHECK(ISABus, (obj), TYPE_ISA_BUS)
 
 #define TYPE_APPLE_SMC "isa-applesmc"
+#define APPLESMC_MAX_DATA_LENGTH       32
+#define APPLESMC_PROP_IO_BASE "iobase"
 
-static inline bool applesmc_find(void)
+static inline uint16_t applesmc_port(void)
 {
-    return object_resolve_path_type("", TYPE_APPLE_SMC, NULL);
+    Object *obj = object_resolve_path_type("", TYPE_APPLE_SMC, NULL);
+
+    if (obj) {
+        return object_property_get_int(obj, APPLESMC_PROP_IO_BASE, NULL);
+    }
+    return 0;
 }
 
 typedef struct ISADeviceClass {
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 50/52] pc: acpi-build: drop template patching and create Device(SMC) dynamically
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (48 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 49/52] pc: export applesmc IO port/len Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 51/52] pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC Igor Mammedov
                   ` (2 subsequent siblings)
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

patch moves SMC device into SSDT and creates it only
when device is present, which makes ACPI tables smaller
in default case when device is not present.

PS:
also it fixes wrong IO range in CRS if "iobase"
property is set to a not default value.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c      | 29 ++++++++++++++++++++++-------
 hw/i386/acpi-dsdt-isa.dsl | 11 -----------
 hw/i386/acpi-dsdt.dsl     |  1 -
 hw/i386/q35-acpi-dsdt.dsl |  1 -
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 26076dd..d564a61 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -115,6 +115,7 @@ typedef struct AcpiMiscInfo {
     const unsigned char *dsdt_code;
     unsigned dsdt_size;
     uint16_t pvpanic_port;
+    uint16_t applesmc_io_base;
 } AcpiMiscInfo;
 
 typedef struct AcpiBuildPciBusHotplugState {
@@ -126,7 +127,6 @@ typedef struct AcpiBuildPciBusHotplugState {
 
 static void acpi_get_dsdt(AcpiMiscInfo *info)
 {
-    uint16_t *applesmc_sta;
     Object *piix = piix4_pm_find();
     Object *lpc = ich9_lpc_find();
     assert(!!piix != !!lpc);
@@ -134,17 +134,11 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
     if (piix) {
         info->dsdt_code = AcpiDsdtAmlCode;
         info->dsdt_size = sizeof AcpiDsdtAmlCode;
-        applesmc_sta = piix_dsdt_applesmc_sta;
     }
     if (lpc) {
         info->dsdt_code = Q35AcpiDsdtAmlCode;
         info->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
-        applesmc_sta = q35_dsdt_applesmc_sta;
     }
-
-    /* Patch in appropriate value for AppleSMC _STA */
-    *(uint8_t *)(info->dsdt_code + *applesmc_sta) =
-        applesmc_port() ? 0x0b : 0x00;
 }
 
 static
@@ -247,6 +241,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info)
     info->has_hpet = hpet_find();
     info->has_tpm = tpm_find();
     info->pvpanic_port = pvpanic_port();
+    info->applesmc_io_base = applesmc_port();
 }
 
 static void acpi_get_pci_info(PcPciInfo *info)
@@ -743,6 +738,26 @@ build_ssdt(Aml *table_data,
     aml_append(scope, aml_name_decl("_S5", pkg));
     aml_append(ssdt, scope);
 
+    if (misc->applesmc_io_base) {
+        scope = aml_scope("\\_SB.PCI0.ISA");
+        dev = aml_device("SMC");
+
+        aml_append(dev, aml_name_decl("_HID", aml_eisaid("APP0001")));
+        /* 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, misc->applesmc_io_base, misc->applesmc_io_base,
+                   0x01, APPLESMC_MAX_DATA_LENGTH)
+        );
+        aml_append(crs, aml_irq_no_flags(6));
+        aml_append(dev, aml_name_decl("_CRS", crs));
+
+        aml_append(scope, dev);
+        aml_append(ssdt, scope);
+    }
+
     if (misc->pvpanic_port) {
         scope = aml_scope("\\_SB.PCI0.ISA");
 
diff --git a/hw/i386/acpi-dsdt-isa.dsl b/hw/i386/acpi-dsdt-isa.dsl
index deb37de..89caa16 100644
--- a/hw/i386/acpi-dsdt-isa.dsl
+++ b/hw/i386/acpi-dsdt-isa.dsl
@@ -16,17 +16,6 @@
 /* Common legacy ISA style devices. */
 Scope(\_SB.PCI0.ISA) {
 
-    Device (SMC) {
-        Name(_HID, EisaId("APP0001"))
-        /* _STA will be patched to 0x0B if AppleSMC is present */
-        ACPI_EXTRACT_NAME_BYTE_CONST DSDT_APPLESMC_STA
-        Name(_STA, 0xF0)
-        Name(_CRS, ResourceTemplate () {
-            IO (Decode16, 0x0300, 0x0300, 0x01, 0x20)
-            IRQNoFlags() { 6 }
-        })
-    }
-
     Device(RTC) {
         Name(_HID, EisaId("PNP0B00"))
         Name(_CRS, ResourceTemplate() {
diff --git a/hw/i386/acpi-dsdt.dsl b/hw/i386/acpi-dsdt.dsl
index 09b68f0..a2d84ec 100644
--- a/hw/i386/acpi-dsdt.dsl
+++ b/hw/i386/acpi-dsdt.dsl
@@ -85,7 +85,6 @@ DefinitionBlock (
         }
     }
 
-#define DSDT_APPLESMC_STA piix_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
diff --git a/hw/i386/q35-acpi-dsdt.dsl b/hw/i386/q35-acpi-dsdt.dsl
index 3fb4b2f..16eaca3 100644
--- a/hw/i386/q35-acpi-dsdt.dsl
+++ b/hw/i386/q35-acpi-dsdt.dsl
@@ -150,7 +150,6 @@ DefinitionBlock (
         }
     }
 
-#define DSDT_APPLESMC_STA q35_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 51/52] pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (49 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 50/52] pc: acpi-build: drop template patching and create Device(SMC) dynamically Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 52/52] acpi: make build_*() routines static to aml-build.c Igor Mammedov
  2015-02-17 16:47 ` [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Michael S. Tsirkin
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

so that build on IASL less hosts won't fail due to
present but unused variable warning

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-dsdt.hex.generated     | 714 ++----------------------------------
 hw/i386/q35-acpi-dsdt.hex.generated | 662 ++-------------------------------
 2 files changed, 58 insertions(+), 1318 deletions(-)

diff --git a/hw/i386/acpi-dsdt.hex.generated b/hw/i386/acpi-dsdt.hex.generated
index 498b194..09f064e 100644
--- a/hw/i386/acpi-dsdt.hex.generated
+++ b/hw/i386/acpi-dsdt.hex.generated
@@ -3,12 +3,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x44,
 0x54,
-0x25,
-0xe,
+0x9a,
+0xb,
 0x0,
 0x0,
 0x1,
-0x6c,
+0xe1,
 0x42,
 0x58,
 0x50,
@@ -31,8 +31,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x4e,
 0x54,
 0x4c,
-0x7,
-0x11,
+0x26,
+0x9,
 0x14,
 0x20,
 0x10,
@@ -145,405 +145,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x44,
 0x1,
 0x10,
-0x4e,
-0x18,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x8,
-0x43,
-0x52,
-0x45,
-0x53,
-0x11,
-0x42,
-0xa,
-0xa,
-0x9e,
-0x88,
-0xd,
-0x0,
-0x2,
-0xc,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x47,
-0x1,
-0xf8,
-0xc,
-0xf8,
-0xc,
-0x1,
-0x8,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0xf7,
-0xc,
-0x0,
-0x0,
-0xf8,
-0xc,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0xd,
-0xff,
-0xad,
-0x0,
-0x0,
-0x0,
-0xa1,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0xf,
-0xae,
-0xff,
-0xae,
-0x0,
-0x0,
-0xf1,
-0x0,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x20,
-0xaf,
-0xdf,
-0xaf,
-0x0,
-0x0,
-0xc0,
-0x0,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0xe4,
-0xaf,
-0xff,
-0xff,
-0x0,
-0x0,
-0x1c,
-0x50,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xa,
-0x0,
-0xff,
-0xff,
-0xb,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x2,
-0x0,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xe0,
-0xff,
-0xff,
-0xbf,
-0xfe,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xc0,
-0x1e,
-0x79,
-0x0,
-0x8,
-0x43,
-0x52,
-0x36,
-0x34,
-0x11,
-0x33,
-0xa,
-0x30,
-0x8a,
-0x2b,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0xff,
-0xff,
-0xff,
-0xff,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0x79,
-0x0,
-0x14,
-0x41,
-0xa,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x8c,
-0x50,
-0x53,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x90,
-0x50,
-0x45,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x98,
-0x50,
-0x4c,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x33,
-0x32,
-0x70,
-0x72,
-0x74,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x0,
-0x1,
-0x0,
-0x50,
-0x4c,
-0x33,
-0x32,
-0xa0,
-0xc,
-0x93,
-0x50,
-0x31,
-0x56,
-0x5f,
-0x0,
-0xa4,
-0x43,
-0x52,
-0x45,
-0x53,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0xe,
-0x50,
-0x53,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x16,
-0x50,
-0x45,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x26,
-0x50,
-0x4c,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x4c,
-0x5f,
-0x50,
-0x4c,
-0x36,
-0x34,
-0x84,
-0x43,
-0x52,
-0x45,
-0x53,
-0x43,
-0x52,
-0x36,
-0x34,
-0x60,
-0xa4,
-0x60,
-0x10,
 0x4d,
 0x8,
 0x5f,
@@ -801,78 +402,32 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x3,
 0x43,
 0x42,
-0x45,
-0x4e,
-0x1,
-0x8,
-0x46,
-0x44,
-0x45,
-0x4e,
-0x1,
-0x10,
-0x4a,
-0x1e,
-0x2f,
-0x3,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x49,
-0x53,
-0x41,
-0x5f,
-0x5b,
-0x82,
-0x2c,
-0x53,
-0x4d,
-0x43,
-0x5f,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x6,
-0x10,
-0x0,
+0x45,
+0x4e,
 0x1,
 0x8,
+0x46,
+0x44,
+0x45,
+0x4e,
+0x1,
+0x10,
+0x4c,
+0x1b,
+0x2f,
+0x3,
 0x5f,
 0x53,
-0x54,
-0x41,
-0xa,
-0xf0,
-0x8,
+0x42,
 0x5f,
+0x50,
 0x43,
-0x52,
+0x49,
+0x30,
+0x49,
 0x53,
-0x11,
-0x10,
-0xa,
-0xd,
-0x47,
-0x1,
-0x0,
-0x3,
-0x0,
-0x3,
-0x1,
-0x20,
-0x22,
-0x40,
-0x0,
-0x79,
-0x0,
+0x41,
+0x5f,
 0x5b,
 0x82,
 0x2d,
@@ -2318,8 +1873,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x1,
 0x10,
-0x4f,
-0x12,
+0x4d,
+0xc,
 0x5f,
 0x53,
 0x42,
@@ -2416,32 +1971,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x22,
 0xa,
 0xc8,
-0x5b,
-0x80,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0xb,
-0x0,
-0xaf,
-0xa,
-0x20,
-0x5b,
-0x81,
-0xc,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0x50,
-0x52,
-0x53,
-0x5f,
-0x40,
-0x10,
 0x14,
 0x4a,
 0x6,
@@ -2549,81 +2078,9 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x3,
 0x75,
 0x60,
-0x5b,
-0x82,
-0x46,
-0x4,
-0x50,
-0x52,
-0x45,
-0x53,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xa,
-0x6,
-0x8,
-0x5f,
-0x55,
-0x49,
-0x44,
-0xd,
-0x43,
-0x50,
-0x55,
-0x20,
-0x68,
-0x6f,
-0x74,
-0x70,
-0x6c,
-0x75,
-0x67,
-0x20,
-0x72,
-0x65,
-0x73,
-0x6f,
-0x75,
-0x72,
-0x63,
-0x65,
-0x73,
-0x0,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xaf,
-0x0,
-0xaf,
-0x0,
-0x20,
-0x79,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x54,
-0x41,
-0xa,
-0xb,
 0x10,
-0x40,
-0x31,
+0x44,
+0x2a,
 0x2e,
 0x5f,
 0x53,
@@ -2635,8 +2092,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x30,
 0x5b,
 0x82,
-0x43,
-0x30,
+0x47,
+0x29,
 0x4d,
 0x48,
 0x50,
@@ -2686,37 +2143,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x65,
 0x73,
 0x0,
-0x5b,
-0x80,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0xb,
-0x0,
-0xa,
-0xa,
-0x18,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xa,
-0x0,
-0xa,
-0x0,
-0x18,
-0x79,
-0x0,
 0x14,
 0x13,
 0x5f,
@@ -2738,89 +2164,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0xa,
 0xb,
 0x5b,
-0x81,
-0x1f,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x52,
-0x42,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x42,
-0x48,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x48,
-0x20,
-0x4d,
-0x50,
-0x58,
-0x5f,
-0x20,
-0x5b,
-0x81,
-0x13,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0x0,
-0x40,
-0xa,
-0x4d,
-0x45,
-0x53,
-0x5f,
-0x1,
-0x4d,
-0x49,
-0x4e,
-0x53,
-0x1,
-0x5b,
 0x1,
 0x4d,
 0x4c,
 0x43,
 0x4b,
 0x0,
-0x5b,
-0x81,
-0x15,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x53,
-0x45,
-0x4c,
-0x20,
-0x4d,
-0x4f,
-0x45,
-0x56,
-0x20,
-0x4d,
-0x4f,
-0x53,
-0x43,
-0x20,
 0x14,
 0x4a,
 0x4,
@@ -3621,6 +2970,3 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x46,
 0x0
 };
-static unsigned short piix_dsdt_applesmc_sta[] = {
-0x353
-};
diff --git a/hw/i386/q35-acpi-dsdt.hex.generated b/hw/i386/q35-acpi-dsdt.hex.generated
index 0d5b133..4800f36 100644
--- a/hw/i386/q35-acpi-dsdt.hex.generated
+++ b/hw/i386/q35-acpi-dsdt.hex.generated
@@ -3,12 +3,12 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x53,
 0x44,
 0x54,
-0x13,
-0x20,
+0xb8,
+0x1d,
 0x0,
 0x0,
 0x1,
-0x0,
+0x1e,
 0x42,
 0x58,
 0x50,
@@ -31,8 +31,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x4e,
 0x54,
 0x4c,
-0x7,
-0x11,
+0x26,
+0x9,
 0x14,
 0x20,
 0x10,
@@ -360,357 +360,6 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0xa4,
 0x6b,
 0x10,
-0x4e,
-0x15,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x8,
-0x43,
-0x52,
-0x45,
-0x53,
-0x11,
-0x42,
-0x7,
-0xa,
-0x6e,
-0x88,
-0xd,
-0x0,
-0x2,
-0xc,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x47,
-0x1,
-0xf8,
-0xc,
-0xf8,
-0xc,
-0x1,
-0x8,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0xd7,
-0xc,
-0x0,
-0x0,
-0xd8,
-0xc,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0xd,
-0xff,
-0xff,
-0x0,
-0x0,
-0x0,
-0xf3,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xa,
-0x0,
-0xff,
-0xff,
-0xb,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x2,
-0x0,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xe0,
-0xff,
-0xff,
-0xbf,
-0xfe,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xc0,
-0x1e,
-0x79,
-0x0,
-0x8,
-0x43,
-0x52,
-0x36,
-0x34,
-0x11,
-0x33,
-0xa,
-0x30,
-0x8a,
-0x2b,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0xff,
-0xff,
-0xff,
-0xff,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0x79,
-0x0,
-0x14,
-0x41,
-0xa,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x5c,
-0x50,
-0x53,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x60,
-0x50,
-0x45,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x68,
-0x50,
-0x4c,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x33,
-0x32,
-0x70,
-0x72,
-0x74,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x0,
-0x1,
-0x0,
-0x50,
-0x4c,
-0x33,
-0x32,
-0xa0,
-0xc,
-0x93,
-0x50,
-0x31,
-0x56,
-0x5f,
-0x0,
-0xa4,
-0x43,
-0x52,
-0x45,
-0x53,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0xe,
-0x50,
-0x53,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x16,
-0x50,
-0x45,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x26,
-0x50,
-0x4c,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x4c,
-0x5f,
-0x50,
-0x4c,
-0x36,
-0x34,
-0x84,
-0x43,
-0x52,
-0x45,
-0x53,
-0x43,
-0x52,
-0x36,
-0x34,
-0x60,
-0xa4,
-0x60,
-0x10,
 0x4d,
 0x8,
 0x5f,
@@ -972,74 +621,28 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x45,
 0x4e,
 0x1,
-0x46,
-0x44,
-0x45,
-0x4e,
-0x1,
-0x10,
-0x4a,
-0x1e,
-0x2f,
-0x3,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x49,
-0x53,
-0x41,
-0x5f,
-0x5b,
-0x82,
-0x2c,
-0x53,
-0x4d,
-0x43,
-0x5f,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x6,
-0x10,
-0x0,
-0x1,
-0x8,
+0x46,
+0x44,
+0x45,
+0x4e,
+0x1,
+0x10,
+0x4c,
+0x1b,
+0x2f,
+0x3,
 0x5f,
 0x53,
-0x54,
-0x41,
-0xa,
-0xf0,
-0x8,
+0x42,
 0x5f,
+0x50,
 0x43,
-0x52,
+0x49,
+0x30,
+0x49,
 0x53,
-0x11,
-0x10,
-0xa,
-0xd,
-0x47,
-0x1,
-0x0,
-0x3,
-0x0,
-0x3,
-0x1,
-0x20,
-0x22,
-0x40,
-0x0,
-0x79,
-0x0,
+0x41,
+0x5f,
 0x5b,
 0x82,
 0x2d,
@@ -6959,8 +6562,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x53,
 0x1,
 0x10,
-0x4f,
-0x12,
+0x4d,
+0xc,
 0x5f,
 0x53,
 0x42,
@@ -7057,32 +6660,6 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x22,
 0xa,
 0xc8,
-0x5b,
-0x80,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0xb,
-0xd8,
-0xc,
-0xa,
-0x20,
-0x5b,
-0x81,
-0xc,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0x50,
-0x52,
-0x53,
-0x5f,
-0x40,
-0x10,
 0x14,
 0x4a,
 0x6,
@@ -7190,81 +6767,9 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x3,
 0x75,
 0x60,
-0x5b,
-0x82,
-0x46,
-0x4,
-0x50,
-0x52,
-0x45,
-0x53,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xa,
-0x6,
-0x8,
-0x5f,
-0x55,
-0x49,
-0x44,
-0xd,
-0x43,
-0x50,
-0x55,
-0x20,
-0x68,
-0x6f,
-0x74,
-0x70,
-0x6c,
-0x75,
-0x67,
-0x20,
-0x72,
-0x65,
-0x73,
-0x6f,
-0x75,
-0x72,
-0x63,
-0x65,
-0x73,
-0x0,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0xd8,
-0xc,
-0xd8,
-0xc,
-0x0,
-0x20,
-0x79,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x54,
-0x41,
-0xa,
-0xb,
 0x10,
-0x40,
-0x31,
+0x44,
+0x2a,
 0x2e,
 0x5f,
 0x53,
@@ -7276,8 +6781,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x30,
 0x5b,
 0x82,
-0x43,
-0x30,
+0x47,
+0x29,
 0x4d,
 0x48,
 0x50,
@@ -7327,37 +6832,6 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x65,
 0x73,
 0x0,
-0x5b,
-0x80,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0xb,
-0x0,
-0xa,
-0xa,
-0x18,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xa,
-0x0,
-0xa,
-0x0,
-0x18,
-0x79,
-0x0,
 0x14,
 0x13,
 0x5f,
@@ -7379,89 +6853,12 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0xa,
 0xb,
 0x5b,
-0x81,
-0x1f,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x52,
-0x42,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x42,
-0x48,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x48,
-0x20,
-0x4d,
-0x50,
-0x58,
-0x5f,
-0x20,
-0x5b,
-0x81,
-0x13,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0x0,
-0x40,
-0xa,
-0x4d,
-0x45,
-0x53,
-0x5f,
-0x1,
-0x4d,
-0x49,
-0x4e,
-0x53,
-0x1,
-0x5b,
 0x1,
 0x4d,
 0x4c,
 0x43,
 0x4b,
 0x0,
-0x5b,
-0x81,
-0x15,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x53,
-0x45,
-0x4c,
-0x20,
-0x4d,
-0x4f,
-0x45,
-0x56,
-0x20,
-0x4d,
-0x4f,
-0x53,
-0x43,
-0x20,
 0x14,
 0x4a,
 0x4,
@@ -8211,6 +7608,3 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x46,
 0x0
 };
-static unsigned short q35_dsdt_applesmc_sta[] = {
-0x3fa
-};
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v3 52/52] acpi: make build_*() routines static to aml-build.c
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (50 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 51/52] pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC Igor Mammedov
@ 2015-02-09 10:54 ` Igor Mammedov
  2015-02-17 16:47 ` [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Michael S. Tsirkin
  52 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-09 10:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, marcel.a, claudio.fontana, mst, zhaoshenglong

build_*() routines were used for composing AML
structures manually in acpi-build.c but after
conversion to AML API they are not used outside
of aml-build.c anymore, so hide them from external
users.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/aml-build.c         | 22 +++++++++++-----------
 include/hw/acpi/aml-build.h | 17 -----------------
 2 files changed, 11 insertions(+), 28 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 3f87d51..8f06f56 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -28,27 +28,27 @@
 #include "qemu/bswap.h"
 #include "hw/acpi/bios-linker-loader.h"
 
-GArray *build_alloc_array(void)
+static GArray *build_alloc_array(void)
 {
     return g_array_new(false, true /* clear */, 1);
 }
 
-void build_free_array(GArray *array)
+static void build_free_array(GArray *array)
 {
     g_array_free(array, true);
 }
 
-void build_prepend_byte(GArray *array, uint8_t val)
+static void build_prepend_byte(GArray *array, uint8_t val)
 {
     g_array_prepend_val(array, val);
 }
 
-void build_append_byte(GArray *array, uint8_t val)
+static void build_append_byte(GArray *array, uint8_t val)
 {
     g_array_append_val(array, val);
 }
 
-void build_append_array(GArray *array, GArray *val)
+static void build_append_array(GArray *array, GArray *val)
 {
     g_array_append_vals(array, val->data, val->len);
 }
@@ -142,7 +142,7 @@ build_append_namestringv(GArray *array, const char *format, va_list ap)
     g_strfreev(segs);
 }
 
-void build_append_namestring(GArray *array, const char *format, ...)
+static void build_append_namestring(GArray *array, const char *format, ...)
 {
     va_list ap;
 
@@ -159,7 +159,7 @@ enum {
     PACKAGE_LENGTH_4BYTE_SHIFT = 20,
 };
 
-void
+static void
 build_prepend_package_length(GArray *package, unsigned length, bool incl_self)
 {
     uint8_t byte;
@@ -227,19 +227,19 @@ build_append_pkg_length(GArray *array, unsigned length, bool incl_self)
     build_free_array(tmp);
 }
 
-void build_package(GArray *package, uint8_t op)
+static void build_package(GArray *package, uint8_t op)
 {
     build_prepend_package_length(package, package->len, true);
     build_prepend_byte(package, op);
 }
 
-void build_extop_package(GArray *package, uint8_t op)
+static void build_extop_package(GArray *package, uint8_t op)
 {
     build_package(package, op);
     build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
-void build_append_value(GArray *table, uint64_t value, int size)
+static void build_append_value(GArray *table, uint64_t value, int size)
 {
     int i;
 
@@ -249,7 +249,7 @@ void build_append_value(GArray *table, uint64_t value, int size)
     }
 }
 
-void build_append_int(GArray *table, uint64_t value)
+static void build_append_int(GArray *table, uint64_t value)
 {
     if (value == 0x00) {
         build_append_byte(table, 0x00); /* ZeroOp */
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 44cb7ea..7e9ce38 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -202,21 +202,4 @@ Aml *aml_resource_template(void);
 Aml *aml_field(const char *name, AmlFieldFlags flags);
 Aml *aml_varpackage(uint32_t num_elements);
 
-/* other helpers */
-GArray *build_alloc_array(void);
-void build_free_array(GArray *array);
-void build_prepend_byte(GArray *array, uint8_t val);
-void build_append_byte(GArray *array, uint8_t val);
-void build_append_array(GArray *array, GArray *val);
-
-void GCC_FMT_ATTR(2, 3)
-build_append_namestring(GArray *array, const char *format, ...);
-
-void
-build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
-void build_package(GArray *package, uint8_t op);
-void build_append_value(GArray *table, uint64_t value, int size);
-void build_append_int(GArray *table, uint64_t value);
-void build_extop_package(GArray *package, uint8_t op);
-
 #endif
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term Igor Mammedov
@ 2015-02-17 12:18   ` Michael S. Tsirkin
  2015-02-17 14:06     ` Igor Mammedov
  2015-02-17 14:24   ` [Qemu-devel] [PATCH v3 31/52] fixup! " Igor Mammedov
  1 sibling, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 12:18 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:53AM +0000, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---

This causes asserts.

>  hw/acpi/aml-build.c         | 11 +++++++++++
>  include/hw/acpi/aml-build.h |  1 +
>  2 files changed, 12 insertions(+)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 10995a9..cb58e19 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
>      build_append_byte(var->buf, flags);
>      return var;
>  }
> +
> +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
> +Aml *aml_local(int num)
> +{
> +    Aml *var;
> +    uint8_t op = 0x60 /* Local0Op */ + num;

So op is 0x6X here.

> +
> +    assert(op <= 7);

And here we assert it is <= 7?


> +    var = aml_opcode(op);
> +    return var;
> +}
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 8b954d9..6e25315 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
>  Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
>                            uint32_t offset, uint32_t len);
>  Aml *aml_named_field(const char *name, unsigned length);
> +Aml *aml_local(int num);
>  
>  /* Block AML object primitives */
>  Aml *aml_def_block(const char *signature, uint8_t revision,
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term
  2015-02-17 12:18   ` Michael S. Tsirkin
@ 2015-02-17 14:06     ` Igor Mammedov
  0 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-17 14:06 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 13:18:19 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:53AM +0000, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> 
> This causes asserts.
> 
> >  hw/acpi/aml-build.c         | 11 +++++++++++
> >  include/hw/acpi/aml-build.h |  1 +
> >  2 files changed, 12 insertions(+)
> > 
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index 10995a9..cb58e19 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
> >      build_append_byte(var->buf, flags);
> >      return var;
> >  }
> > +
> > +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
> > +Aml *aml_local(int num)
> > +{
> > +    Aml *var;
> > +    uint8_t op = 0x60 /* Local0Op */ + num;
> 
> So op is 0x6X here.
> 
> > +
> > +    assert(op <= 7);
> 
> And here we assert it is <= 7?
yep, it should s/op/num/

I'm sorry for not running make check on the last iteration,
I'll post fixup shortly.
> 
> 
> > +    var = aml_opcode(op);
> > +    return var;
> > +}
> > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > index 8b954d9..6e25315 100644
> > --- a/include/hw/acpi/aml-build.h
> > +++ b/include/hw/acpi/aml-build.h
> > @@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
> >  Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
> >                            uint32_t offset, uint32_t len);
> >  Aml *aml_named_field(const char *name, unsigned length);
> > +Aml *aml_local(int num);
> >  
> >  /* Block AML object primitives */
> >  Aml *aml_def_block(const char *signature, uint8_t revision,
> > -- 
> > 1.8.3.1

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

* [Qemu-devel] [PATCH v3 31/52] fixup! acpi: add aml_local() term
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term Igor Mammedov
  2015-02-17 12:18   ` Michael S. Tsirkin
@ 2015-02-17 14:24   ` Igor Mammedov
  1 sibling, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-17 14:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst

fixes:
qemu-system-i386: hw/acpi/aml-build.c:723: aml_local: Assertion `op <= 7' failed.
when pvpanic device is present

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
this time make check on my host for all targets passes,
/me sorry for mess again
---
 hw/acpi/aml-build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 8f06f56..6e12031 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -720,7 +720,7 @@ Aml *aml_local(int num)
     Aml *var;
     uint8_t op = 0x60 /* Local0Op */ + num;
 
-    assert(op <= 7);
+    assert(num <= 7);
     var = aml_opcode(op);
     return var;
 }
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append() Igor Mammedov
@ 2015-02-17 16:26   ` Michael S. Tsirkin
  2015-02-17 17:50     ` Igor Mammedov
  2015-02-17 19:46   ` Michael S. Tsirkin
  1 sibling, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 16:26 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:23AM +0000, Igor Mammedov wrote:
> Adds for dynamic AML creation, which will be used
> for piecing ASL/AML primitives together and hiding
> from user/caller details about how nested context
> should be closed/packed leaving less space for
> mistakes and necessity to know how AML should be
> encoded, allowing user to concentrate on ASL
> representation instead.
> 
> For example it will allow to create AML like this:
> 
> init_aml_allocator();
> ...
> Aml *scope = aml_scope("PCI0")
> Aml *dev = aml_device("PM")
>     aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
> aml_append(scope, dev);
> ...
> free_aml_allocator();
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  hw/acpi/aml-build.c         | 91 +++++++++++++++++++++++++++++++++++++++++++++
>  hw/i386/acpi-build.c        |  1 -
>  include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++
>  3 files changed, 152 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index bcb288e..096f347 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -25,6 +25,8 @@
>  #include <stdbool.h>
>  #include <string.h>
>  #include "hw/acpi/aml-build.h"
> +#include "qemu/bswap.h"
> +#include "hw/acpi/bios-linker-loader.h"
>  
>  GArray *build_alloc_array(void)
>  {
> @@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)
>          build_append_value(table, value, 4);
>      }
>  }
> +
> +static GPtrArray *alloc_list;
> +
> +static Aml *aml_alloc(void)
> +{
> +    Aml *var = g_new0(typeof(*var), 1);
> +
> +    g_ptr_array_add(alloc_list, var);
> +    var->block_flags = AML_HELPER;
> +    var->buf = build_alloc_array();
> +    return var;
> +}
> +
> +static void aml_free(gpointer data)
> +{
> +    Aml *var = data;
> +    build_free_array(var->buf);
> +}
> +
> +Aml *init_aml_allocator(GArray *linker)
> +{
> +    Aml *var;
> +
> +    assert(!alloc_list);
> +    alloc_list = g_ptr_array_new_with_free_func(aml_free);
> +    var = aml_alloc();
> +    var->linker = linker;
> +    return var;
> +}
> +
> +void free_aml_allocator(void)
> +{
> +    g_ptr_array_free(alloc_list, true);
> +    alloc_list = 0;
> +}
> +
> +static void build_buffer(GArray *array, uint8_t op)
> +{
> +    GArray *data = build_alloc_array();
> +
> +    build_append_int(data, array->len);
> +    g_array_prepend_vals(array, data->data, data->len);
> +    build_free_array(data);
> +    build_package(array, op);
> +}
> +
> +void aml_append(Aml *parent_ctx, Aml *child)
> +{
> +    switch (child->block_flags) {
> +    case AML_NON_BLOCK:
> +        build_append_byte(parent_ctx->buf, child->op);
> +        break;
> +    case AML_EXT_PACKAGE:
> +        build_extop_package(child->buf, child->op);
> +        break;
> +    case AML_PACKAGE:
> +        build_package(child->buf, child->op);
> +        break;
> +    case AML_RES_TEMPLATE:
> +        build_append_byte(child->buf, 0x79); /* EndTag */
> +        /*
> +         * checksum operations is treated as succeeded if checksum
> +         * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
> +         */
> +        build_append_byte(child->buf, 0);
> +        /* fall through, to pack resources in buffer */
> +    case AML_BUFFER:
> +        build_buffer(child->buf, child->op);
> +        break;
> +    case AML_DEF_BLOCK: {

This one is inelegant.
It's not a definition block, and the patching and
manual offset calculation are scary.

> +        uint8_t *start = (uint8_t *)parent_ctx->buf->data +
> +                         parent_ctx->buf->len;
> +        uint32_t le32_len = cpu_to_le32(child->buf->len);
> +
> +        /* create linker entry for the DefinitionBlock */
> +        bios_linker_loader_add_checksum(parent_ctx->linker,
> +            ACPI_BUILD_TABLE_FILE,

Hard-coding file name here is very ugly.
All this does not belong in this file, this
is fw cfg interface.


> +            parent_ctx->buf->data,
> +            start, child->buf->len, start + 9 /* checksum offset */);
> +
> +        /* set DefinitionBlock length at TableLength offset*/
> +        memcpy(child->buf->data + 4, &le32_len, sizeof le32_len);


This make no sense.
In AML, there are no objects which are higher level
than the table.

So for now, please just leave this alone:
drop linker completely, keep table_data
a simple GArray, not AML, and reuse build_header
to fill in headers.

This way this file just deals with AML and ACPI spec.


> +        break;
> +    }
> +    default:

This should assert.

> +        break;
> +    }
> +    build_append_array(parent_ctx->buf, child->buf);
> +}
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 6d84f38..237080f 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
>  #define ACPI_BUILD_APPNAME6 "BOCHS "
>  #define ACPI_BUILD_APPNAME4 "BXPC"
>  
> -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
>  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
>  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
>  
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 199f003..4033796 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -5,6 +5,67 @@
>  #include <glib.h>
>  #include "qemu/compiler.h"
>  
> +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> +
> +typedef enum {
> +    AML_HELPER = 0,
> +    AML_NON_BLOCK,
> +    AML_PACKAGE,
> +    AML_EXT_PACKAGE,
> +    AML_BUFFER,
> +    AML_RES_TEMPLATE,
> +    AML_DEF_BLOCK,
> +} AmlBlockFlags;
> +
> +struct Aml {
> +    GArray *buf;
> +
> +    /*< private >*/
> +    uint8_t op;
> +    AmlBlockFlags block_flags;
> +    GArray *linker;
> +};
> +typedef struct Aml Aml;
> +
> +/**
> + * init_aml_allocator:
> + * @linker: linker that used by API for registering ACPI tables
> + *          with linker firmware interfac
> + *
> + * Called for initializing API allocator which allow to use
> + * AML API.
> + * Returns: toplevel container which accumulates all other
> + * ACPI tables.
> + */
> +Aml *init_aml_allocator(GArray *linker);
> +
> +/**
> + * free_aml_allocator:
> + *
> + * Releases all elements used by AML API, frees associated memory
> + * and invalidates AML allocator. After this call @init_aml_allocator
> + * should be called again if AML API is to be used again.
> + */
> +void free_aml_allocator(void);
> +
> +/**
> + * aml_append:
> + * @parent_ctx: context to which @child element is added
> + * @child: element that is copied into @parent_ctx context
> + *
> + * Joins Aml elements together and helps to construct AML tables
> + * Examle of usage:
> + *   Aml *table = aml_def_block("SSDT", ...);
> + *   Aml *sb = aml_scope("\_SB");
> + *   Aml *dev = aml_device("PCI0");
> + *
> + *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
> + *   aml_append(sb, dev);
> + *   aml_append(table, sb);
> + */
> +void aml_append(Aml *parent_ctx, Aml *child);
> +
> +/* other helpers */
>  GArray *build_alloc_array(void);
>  void build_free_array(GArray *array);
>  void build_prepend_byte(GArray *array, uint8_t val);
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term Igor Mammedov
@ 2015-02-17 16:35   ` Michael S. Tsirkin
  2015-02-17 16:47     ` Igor Mammedov
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 16:35 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
>  hw/i386/acpi-build.c        |  4 ----
>  include/hw/acpi/aml-build.h | 10 ++++++++++
>  3 files changed, 48 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 67d1371..cb1a1bd 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
>      }
>      build_append_array(parent_ctx->buf, child->buf);
>  }
> +
> +/*
> + * ACPI 1.0b: 16.2.1 Top Level AML
> + *            5.2.3 System Description Table Header
> + *
> + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> + */
> +Aml *aml_def_block(const char *signature, uint8_t revision,
> +                   const char *oem_id, const char *oem_table_id,
> +                   uint32_t oem_revision, uint32_t creator_id,
> +                   uint32_t creator_revision)
> +{
> +    int len;
> +    Aml *var = aml_alloc();
> +    var->block_flags = AML_DEF_BLOCK;
> +
> +    assert(strlen(signature) == 4);
> +    g_array_append_vals(var->buf, signature, 4);
> +    build_append_value(var->buf, 0, 4); /* Length place holder */
> +    build_append_byte(var->buf, revision);
> +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> +
> +    len = strlen(oem_id);
> +    assert(len <= 6);
> +    g_array_append_vals(var->buf, oem_id, len);
> +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> +
> +    len = strlen(oem_table_id);
> +    assert(len <= 8);
> +    g_array_append_vals(var->buf, oem_table_id, len);
> +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> +
> +    build_append_value(var->buf, oem_revision, 4);
> +    build_append_value(var->buf, creator_id, 4);
> +    build_append_value(var->buf, creator_revision, 4);
> +
> +    return var;


Please don't do this.
First, this is not a definition block encoding, so name
is wrong.

Second, we already have functions to fill in headers.
So just call them.

Filling structures byte by byte is unreadable -
I know ACPI spec often makes us do this but
when it doesn't, we should not do it.

Pls keep using build_header for now.


> +}
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index a1bf450..553c86b 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
>                                              NULL);
>  }
>  
> -#define ACPI_BUILD_APPNAME  "Bochs"
> -#define ACPI_BUILD_APPNAME6 "BOCHS "
> -#define ACPI_BUILD_APPNAME4 "BXPC"
> -
>  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
>  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
>  
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 4033796..2610336 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -6,6 +6,10 @@
>  #include "qemu/compiler.h"
>  
>  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> +#define ACPI_BUILD_APPNAME  "Bochs"
> +#define ACPI_BUILD_APPNAME6 "BOCHS "
> +#define ACPI_BUILD_APPNAME4 "BXPC"
> +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
>  
>  typedef enum {
>      AML_HELPER = 0,
> @@ -65,6 +69,12 @@ void free_aml_allocator(void);
>   */
>  void aml_append(Aml *parent_ctx, Aml *child);
>  
> +/* Block AML object primitives */
> +Aml *aml_def_block(const char *signature, uint8_t revision,
> +                   const char *oem_id, const char *oem_table_id,
> +                   uint32_t oem_revision, uint32_t creator_id,
> +                   uint32_t creator_revision);
> +
>  /* other helpers */
>  GArray *build_alloc_array(void);
>  void build_free_array(GArray *array);
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP Igor Mammedov
@ 2015-02-17 16:41   ` Michael S. Tsirkin
  2015-02-18 10:03     ` Igor Mammedov
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 16:41 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:45AM +0000, Igor Mammedov wrote:
> QEMU doesn't implement/advertize PM1b_CNT_BLK
> register block so do not set/patch its \_Sx
> values to avoid confusion.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

I doubt guests are confused.
I think you mean this confuses you, but I'd rather stay
bug for bug compatible with what we did historically.
We probably should add a comment saying this is here
for historical reasons, but let's get your patchset
merged first, it's too big as is.


> ---
>  hw/i386/acpi-build.c  | 3 +--
>  hw/i386/ssdt-misc.dsl | 4 ++--
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index b6626f5..7cc564a 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,
>      if (pm->s4_disabled) {
>          ssdt_ptr[acpi_s4_name[0]] = 'X';
>      } else {
> -        ssdt_ptr[acpi_s4_pkg[0] + 1] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
> -            pm->s4_val;
> +        ssdt_ptr[acpi_s4_pkg[0] + 1] = pm->s4_val;
>      }
>  
>      patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
> diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> index 1e3baae..96382a6 100644
> --- a/hw/i386/ssdt-misc.dsl
> +++ b/hw/i386/ssdt-misc.dsl
> @@ -54,7 +54,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
>          ACPI_EXTRACT_NAME_STRING acpi_s3_name
>          Name(_S3, Package(0x04) {
>              One,  /* PM1a_CNT.SLP_TYP */
> -            One,  /* PM1b_CNT.SLP_TYP */
> +            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
>              Zero,  /* reserved */
>              Zero   /* reserved */
>          })
> @@ -62,7 +62,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
>          ACPI_EXTRACT_PKG_START acpi_s4_pkg
>          Name(_S4, Package(0x04) {
>              0x2,  /* PM1a_CNT.SLP_TYP */
> -            0x2,  /* PM1b_CNT.SLP_TYP */
> +            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
>              Zero,  /* reserved */
>              Zero   /* reserved */
>          })
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table Igor Mammedov
@ 2015-02-17 16:42   ` Michael S. Tsirkin
  2015-02-18  9:57     ` Igor Mammedov
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 16:42 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:28AM +0000, Igor Mammedov wrote:
> it replaces prebuilt SSDT table header template copying/patching
> with AML API
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

I note that this changed the SSDT signature in random ways,
for example, it used to be named BXPCSSDT, now it's BXPC.

Pls keep using build_header, this problem will go away then.


> ---
>  hw/i386/acpi-build.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 553c86b..fcefa07 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -816,15 +816,15 @@ static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
>  }
>  
>  static void
> -build_ssdt(GArray *table_data, GArray *linker,
> +build_ssdt(Aml *table_data,
>             AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
>             PcPciInfo *pci, PcGuestInfo *guest_info)
>  {
>      MachineState *machine = MACHINE(qdev_get_machine());
>      uint32_t nr_mem = machine->ram_slots;
>      unsigned acpi_cpus = guest_info->apic_id_limit;
> -    int ssdt_start = table_data->len;
>      uint8_t *ssdt_ptr;
> +    Aml *ssdt;
>      int i;
>  
>      /* The current AML generator can cover the APIC ID range [0..255],
> @@ -832,9 +832,17 @@ build_ssdt(GArray *table_data, GArray *linker,
>      QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256);
>      g_assert(acpi_cpus <= ACPI_CPU_HOTPLUG_ID_LIMIT);
>  
> -    /* Copy header and patch values in the S3_ / S4_ / S5_ packages */
> -    ssdt_ptr = acpi_data_push(table_data, sizeof(ssdp_misc_aml));
> -    memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
> +    /* Init SSDT Definition Block */
> +    ssdt = aml_def_block("SSDT", 1, ACPI_BUILD_APPNAME6,
> +                         ACPI_BUILD_APPNAME4, 1,
> +                         ACPI_BUILD_APPNAME4_HEX, 1);
> +
> +    /* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
> +    acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
> +    ssdt_ptr = (uint8_t *)ssdt->buf->data;
> +    memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
> +           ssdp_misc_aml + sizeof(AcpiTableHeader),
> +           sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
>      if (pm->s3_disabled) {
>          ssdt_ptr[acpi_s3_name[0]] = 'X';
>      }
> @@ -944,13 +952,11 @@ build_ssdt(GArray *table_data, GArray *linker,
>              }
>          }
>          build_package(sb_scope, op);
> -        build_append_array(table_data, sb_scope);
> +        build_append_array(ssdt->buf, sb_scope);
>          build_free_array(sb_scope);
>      }
>  
> -    build_header(linker, table_data,
> -                 (void *)(table_data->data + ssdt_start),
> -                 "SSDT", table_data->len - ssdt_start, 1);
> +    aml_append(table_data, ssdt);
>  }
>  
>  static void
> @@ -1352,7 +1358,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
>  
>      ssdt = tables_blob->len;
>      acpi_add_table(table_offsets, tables_blob);
> -    build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
> +    build_ssdt(tables->table_data, &cpu, &pm, &misc, &pci,
>                 guest_info);
>      aml_len += tables_blob->len - ssdt;
>  
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block() Igor Mammedov
@ 2015-02-17 16:44   ` Michael S. Tsirkin
  2015-02-18 10:09     ` Igor Mammedov
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 16:44 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:54:09AM +0000, Igor Mammedov wrote:
> It completes dynamic SSDT generation and makes it
> independed of IASL binary blobs. It also hides
> from user all pointer arithmetic when building
> SSDT which makes resulting code a bit cleaner
> and concentrating only on composing ASL construct
> /i.e. a task build_ssdt() should be doing/.
> 
> Also it makes one binary blob less stored in QEMU
> source tree by removing need to keep and update
> hw/i386/ssdt-misc.hex.generated file here in total
> saving us ~430LOC.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>


I see where we drop ssdt_misc here but I don't see
acpi_def_block anywhere.

Also pls don't include generated files in patches,
they just make rebases painful.
just say in commit log they need to be updated.

> ---
>  hw/i386/Makefile.objs           |   2 +-
>  hw/i386/acpi-build.c            |  12 --
>  hw/i386/ssdt-misc.dsl           |  21 ---
>  hw/i386/ssdt-misc.hex.generated | 399 ----------------------------------------
>  4 files changed, 1 insertion(+), 433 deletions(-)
>  delete mode 100644 hw/i386/ssdt-misc.dsl
>  delete mode 100644 hw/i386/ssdt-misc.hex.generated
> 
> diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> index 6c8705d..dc8c38a 100644
> --- a/hw/i386/Makefile.objs
> +++ b/hw/i386/Makefile.objs
> @@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
>  obj-y += kvmvapic.o
>  obj-y += acpi-build.o
>  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> -	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> +	hw/i386/q35-acpi-dsdt.hex \
>  	hw/i386/ssdt-tpm.hex
>  
>  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index bead77e..14c1c7d 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
>                   table_data->len - madt_start, 1);
>  }
>  
> -#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
> -#define ACPI_SSDT_HEADER_LENGTH 36
> -
> -#include "hw/i386/ssdt-misc.hex"
>  #include "hw/i386/ssdt-tpm.hex"
>  
>  /* Assign BSEL property to all buses.  In the future, this can be changed
> @@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,
>      MachineState *machine = MACHINE(qdev_get_machine());
>      uint32_t nr_mem = machine->ram_slots;
>      unsigned acpi_cpus = guest_info->apic_id_limit;
> -    uint8_t *ssdt_ptr;
>      Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
>      int i;
>  
> @@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,
>                           ACPI_BUILD_APPNAME4, 1,
>                           ACPI_BUILD_APPNAME4_HEX, 1);
>  
> -    /* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
> -    acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
> -    ssdt_ptr = (uint8_t *)ssdt->buf->data;
> -    memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
> -           ssdp_misc_aml + sizeof(AcpiTableHeader),
> -           sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
> -
>      scope = aml_scope("\\_SB.PCI0");
>      /* build PCI0._CRS */
>      crs = aml_resource_template();

So before this patch, we had two headers?
I don't see how this makes sense, and it does not
match commit log.


> diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> deleted file mode 100644
> index 8d61f21..0000000
> --- a/hw/i386/ssdt-misc.dsl
> +++ /dev/null
> @@ -1,21 +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 "hw/acpi/pc-hotplug.h"
> -
> -ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
> -
> -DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
> -{
> -}
> diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
> deleted file mode 100644
> index cbcf61d..0000000
> --- a/hw/i386/ssdt-misc.hex.generated
> +++ /dev/null
> @@ -1,399 +0,0 @@
> -static unsigned char acpi_pci64_length[] = {
> -0x6f
> -};
> -static unsigned char acpi_s4_pkg[] = {
> -0x99
> -};
> -static unsigned char ssdt_mctrl_nr_slots[] = {
> -0x7d
> -};
> -static unsigned char acpi_s3_name[] = {
> -0x86
> -};
> -static unsigned char acpi_pci32_start[] = {
> -0x2f
> -};
> -static unsigned char acpi_pci64_valid[] = {
> -0x43
> -};
> -static unsigned char ssdp_misc_aml[] = {
> -0x53,
> -0x53,
> -0x44,
> -0x54,
> -0x6c,
> -0x1,
> -0x0,
> -0x0,
> -0x1,
> -0x3,
> -0x42,
> -0x58,
> -0x50,
> -0x43,
> -0x0,
> -0x0,
> -0x42,
> -0x58,
> -0x53,
> -0x53,
> -0x44,
> -0x54,
> -0x53,
> -0x55,
> -0x1,
> -0x0,
> -0x0,
> -0x0,
> -0x49,
> -0x4e,
> -0x54,
> -0x4c,
> -0x28,
> -0x8,
> -0x14,
> -0x20,
> -0x10,
> -0x4c,
> -0x5,
> -0x5c,
> -0x0,
> -0x8,
> -0x50,
> -0x30,
> -0x53,
> -0x5f,
> -0xc,
> -0x78,
> -0x56,
> -0x34,
> -0x12,
> -0x8,
> -0x50,
> -0x30,
> -0x45,
> -0x5f,
> -0xc,
> -0x78,
> -0x56,
> -0x34,
> -0x12,
> -0x8,
> -0x50,
> -0x31,
> -0x56,
> -0x5f,
> -0xa,
> -0x12,
> -0x8,
> -0x50,
> -0x31,
> -0x53,
> -0x5f,
> -0x11,
> -0xb,
> -0xa,
> -0x8,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x8,
> -0x50,
> -0x31,
> -0x45,
> -0x5f,
> -0x11,
> -0xb,
> -0xa,
> -0x8,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x8,
> -0x50,
> -0x31,
> -0x4c,
> -0x5f,
> -0x11,
> -0xb,
> -0xa,
> -0x8,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x8,
> -0x4d,
> -0x44,
> -0x4e,
> -0x52,
> -0xc,
> -0x78,
> -0x56,
> -0x34,
> -0x12,
> -0x10,
> -0x29,
> -0x5c,
> -0x0,
> -0x8,
> -0x5f,
> -0x53,
> -0x33,
> -0x5f,
> -0x12,
> -0x6,
> -0x4,
> -0x1,
> -0x1,
> -0x0,
> -0x0,
> -0x8,
> -0x5f,
> -0x53,
> -0x34,
> -0x5f,
> -0x12,
> -0x8,
> -0x4,
> -0xa,
> -0x2,
> -0xa,
> -0x2,
> -0x0,
> -0x0,
> -0x8,
> -0x5f,
> -0x53,
> -0x35,
> -0x5f,
> -0x12,
> -0x6,
> -0x4,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x10,
> -0x40,
> -0xc,
> -0x5c,
> -0x2f,
> -0x3,
> -0x5f,
> -0x53,
> -0x42,
> -0x5f,
> -0x50,
> -0x43,
> -0x49,
> -0x30,
> -0x49,
> -0x53,
> -0x41,
> -0x5f,
> -0x5b,
> -0x82,
> -0x4d,
> -0xa,
> -0x50,
> -0x45,
> -0x56,
> -0x54,
> -0x8,
> -0x5f,
> -0x48,
> -0x49,
> -0x44,
> -0xd,
> -0x51,
> -0x45,
> -0x4d,
> -0x55,
> -0x30,
> -0x30,
> -0x30,
> -0x31,
> -0x0,
> -0x8,
> -0x50,
> -0x45,
> -0x53,
> -0x54,
> -0xb,
> -0xff,
> -0xff,
> -0x5b,
> -0x80,
> -0x50,
> -0x45,
> -0x4f,
> -0x52,
> -0x1,
> -0x50,
> -0x45,
> -0x53,
> -0x54,
> -0x1,
> -0x5b,
> -0x81,
> -0xb,
> -0x50,
> -0x45,
> -0x4f,
> -0x52,
> -0x1,
> -0x50,
> -0x45,
> -0x50,
> -0x54,
> -0x8,
> -0x14,
> -0x18,
> -0x5f,
> -0x53,
> -0x54,
> -0x41,
> -0x0,
> -0x70,
> -0x50,
> -0x45,
> -0x53,
> -0x54,
> -0x60,
> -0xa0,
> -0x6,
> -0x93,
> -0x60,
> -0x0,
> -0xa4,
> -0x0,
> -0xa1,
> -0x4,
> -0xa4,
> -0xa,
> -0xf,
> -0x14,
> -0xe,
> -0x52,
> -0x44,
> -0x50,
> -0x54,
> -0x0,
> -0x70,
> -0x50,
> -0x45,
> -0x50,
> -0x54,
> -0x60,
> -0xa4,
> -0x60,
> -0x14,
> -0xc,
> -0x57,
> -0x52,
> -0x50,
> -0x54,
> -0x1,
> -0x70,
> -0x68,
> -0x50,
> -0x45,
> -0x50,
> -0x54,
> -0x8,
> -0x5f,
> -0x43,
> -0x52,
> -0x53,
> -0x11,
> -0xd,
> -0xa,
> -0xa,
> -0x47,
> -0x1,
> -0x0,
> -0x0,
> -0x0,
> -0x0,
> -0x1,
> -0x1,
> -0x79,
> -0x0,
> -0x8b,
> -0x5f,
> -0x43,
> -0x52,
> -0x53,
> -0xa,
> -0x2,
> -0x49,
> -0x4f,
> -0x4d,
> -0x4e,
> -0x8b,
> -0x5f,
> -0x43,
> -0x52,
> -0x53,
> -0xa,
> -0x4,
> -0x49,
> -0x4f,
> -0x4d,
> -0x58,
> -0x14,
> -0x18,
> -0x5f,
> -0x49,
> -0x4e,
> -0x49,
> -0x0,
> -0x70,
> -0x50,
> -0x45,
> -0x53,
> -0x54,
> -0x49,
> -0x4f,
> -0x4d,
> -0x4e,
> -0x70,
> -0x50,
> -0x45,
> -0x53,
> -0x54,
> -0x49,
> -0x4f,
> -0x4d,
> -0x58
> -};
> -static unsigned char ssdt_isa_pest[] = {
> -0xda
> -};
> -static unsigned char acpi_s4_name[] = {
> -0x92
> -};
> -static unsigned char acpi_pci64_start[] = {
> -0x4d
> -};
> -static unsigned char acpi_pci64_end[] = {
> -0x5e
> -};
> -static unsigned char acpi_pci32_end[] = {
> -0x39
> -};
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API
  2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (51 preceding siblings ...)
  2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 52/52] acpi: make build_*() routines static to aml-build.c Igor Mammedov
@ 2015-02-17 16:47 ` Michael S. Tsirkin
  2015-02-17 17:51   ` Igor Mammedov
  52 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 16:47 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

This seems to change the contents of the tables in too many ways.  So of
it needs changing since PCI are somewhat broken by your recent patch.

So let's do this: please prepare a minimal patchset that just generates
PCI description dynamically.  Drop everything that's not necessary, and
verify that make check produces trivial diffs only.

We'll go from there.

-- 
MST

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-17 16:35   ` Michael S. Tsirkin
@ 2015-02-17 16:47     ` Igor Mammedov
  2015-02-17 19:03       ` Michael S. Tsirkin
  2015-02-17 19:15       ` Michael S. Tsirkin
  0 siblings, 2 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-17 16:47 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 17:35:55 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
> >  hw/i386/acpi-build.c        |  4 ----
> >  include/hw/acpi/aml-build.h | 10 ++++++++++
> >  3 files changed, 48 insertions(+), 4 deletions(-)
> > 
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index 67d1371..cb1a1bd 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
> >      }
> >      build_append_array(parent_ctx->buf, child->buf);
> >  }
> > +
> > +/*
> > + * ACPI 1.0b: 16.2.1 Top Level AML
> > + *            5.2.3 System Description Table Header
> > + *
> > + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> > + */
> > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > +                   const char *oem_id, const char *oem_table_id,
> > +                   uint32_t oem_revision, uint32_t creator_id,
> > +                   uint32_t creator_revision)
> > +{
> > +    int len;
> > +    Aml *var = aml_alloc();
> > +    var->block_flags = AML_DEF_BLOCK;
> > +
> > +    assert(strlen(signature) == 4);
> > +    g_array_append_vals(var->buf, signature, 4);
> > +    build_append_value(var->buf, 0, 4); /* Length place holder */
> > +    build_append_byte(var->buf, revision);
> > +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> > +
> > +    len = strlen(oem_id);
> > +    assert(len <= 6);
> > +    g_array_append_vals(var->buf, oem_id, len);
> > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> > +
> > +    len = strlen(oem_table_id);
> > +    assert(len <= 8);
> > +    g_array_append_vals(var->buf, oem_table_id, len);
> > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> > +
> > +    build_append_value(var->buf, oem_revision, 4);
> > +    build_append_value(var->buf, creator_id, 4);
> > +    build_append_value(var->buf, creator_revision, 4);
> > +
> > +    return var;
> 
> 
> Please don't do this.
> First, this is not a definition block encoding, so name
> is wrong.
> 
> Second, we already have functions to fill in headers.
> So just call them.
> 
> Filling structures byte by byte is unreadable -
> I know ACPI spec often makes us do this but
> when it doesn't, we should not do it.
it does, in ACPI 5.1,

20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID
OemTableID OemRevision CreatorID CreatorRevision

> 
> Pls keep using build_header for now.
> 
> 
> > +}
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index a1bf450..553c86b 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> >                                              NULL);
> >  }
> >  
> > -#define ACPI_BUILD_APPNAME  "Bochs"
> > -#define ACPI_BUILD_APPNAME6 "BOCHS "
> > -#define ACPI_BUILD_APPNAME4 "BXPC"
> > -
> >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> >  
> > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > index 4033796..2610336 100644
> > --- a/include/hw/acpi/aml-build.h
> > +++ b/include/hw/acpi/aml-build.h
> > @@ -6,6 +6,10 @@
> >  #include "qemu/compiler.h"
> >  
> >  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > +#define ACPI_BUILD_APPNAME  "Bochs"
> > +#define ACPI_BUILD_APPNAME6 "BOCHS "
> > +#define ACPI_BUILD_APPNAME4 "BXPC"
> > +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
> >  
> >  typedef enum {
> >      AML_HELPER = 0,
> > @@ -65,6 +69,12 @@ void free_aml_allocator(void);
> >   */
> >  void aml_append(Aml *parent_ctx, Aml *child);
> >  
> > +/* Block AML object primitives */
> > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > +                   const char *oem_id, const char *oem_table_id,
> > +                   uint32_t oem_revision, uint32_t creator_id,
> > +                   uint32_t creator_revision);
> > +
> >  /* other helpers */
> >  GArray *build_alloc_array(void);
> >  void build_free_array(GArray *array);
> > -- 
> > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
  2015-02-17 16:26   ` Michael S. Tsirkin
@ 2015-02-17 17:50     ` Igor Mammedov
  2015-02-17 19:12       ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-17 17:50 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, zhaoshenglong, claudio.fontana, qemu-devel, marcel.a

On Tue, 17 Feb 2015 17:26:16 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:23AM +0000, Igor Mammedov wrote:
> > Adds for dynamic AML creation, which will be used
> > for piecing ASL/AML primitives together and hiding
> > from user/caller details about how nested context
> > should be closed/packed leaving less space for
> > mistakes and necessity to know how AML should be
> > encoded, allowing user to concentrate on ASL
> > representation instead.
> > 
> > For example it will allow to create AML like this:
> > 
> > init_aml_allocator();
> > ...
> > Aml *scope = aml_scope("PCI0")
> > Aml *dev = aml_device("PM")
> >     aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
> > aml_append(scope, dev);
> > ...
> > free_aml_allocator();
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  hw/acpi/aml-build.c         | 91 +++++++++++++++++++++++++++++++++++++++++++++
> >  hw/i386/acpi-build.c        |  1 -
> >  include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++
> >  3 files changed, 152 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index bcb288e..096f347 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -25,6 +25,8 @@
> >  #include <stdbool.h>
> >  #include <string.h>
> >  #include "hw/acpi/aml-build.h"
> > +#include "qemu/bswap.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> >  
> >  GArray *build_alloc_array(void)
> >  {
> > @@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)
> >          build_append_value(table, value, 4);
> >      }
> >  }
> > +
> > +static GPtrArray *alloc_list;
> > +
> > +static Aml *aml_alloc(void)
> > +{
> > +    Aml *var = g_new0(typeof(*var), 1);
> > +
> > +    g_ptr_array_add(alloc_list, var);
> > +    var->block_flags = AML_HELPER;
> > +    var->buf = build_alloc_array();
> > +    return var;
> > +}
> > +
> > +static void aml_free(gpointer data)
> > +{
> > +    Aml *var = data;
> > +    build_free_array(var->buf);
> > +}
> > +
> > +Aml *init_aml_allocator(GArray *linker)
> > +{
> > +    Aml *var;
> > +
> > +    assert(!alloc_list);
> > +    alloc_list = g_ptr_array_new_with_free_func(aml_free);
> > +    var = aml_alloc();
> > +    var->linker = linker;
> > +    return var;
> > +}
> > +
> > +void free_aml_allocator(void)
> > +{
> > +    g_ptr_array_free(alloc_list, true);
> > +    alloc_list = 0;
> > +}
> > +
> > +static void build_buffer(GArray *array, uint8_t op)
> > +{
> > +    GArray *data = build_alloc_array();
> > +
> > +    build_append_int(data, array->len);
> > +    g_array_prepend_vals(array, data->data, data->len);
> > +    build_free_array(data);
> > +    build_package(array, op);
> > +}
> > +
> > +void aml_append(Aml *parent_ctx, Aml *child)
> > +{
> > +    switch (child->block_flags) {
> > +    case AML_NON_BLOCK:
> > +        build_append_byte(parent_ctx->buf, child->op);
> > +        break;
> > +    case AML_EXT_PACKAGE:
> > +        build_extop_package(child->buf, child->op);
> > +        break;
> > +    case AML_PACKAGE:
> > +        build_package(child->buf, child->op);
> > +        break;
> > +    case AML_RES_TEMPLATE:
> > +        build_append_byte(child->buf, 0x79); /* EndTag */
> > +        /*
> > +         * checksum operations is treated as succeeded if checksum
> > +         * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
> > +         */
> > +        build_append_byte(child->buf, 0);
> > +        /* fall through, to pack resources in buffer */
> > +    case AML_BUFFER:
> > +        build_buffer(child->buf, child->op);
> > +        break;
> > +    case AML_DEF_BLOCK: {
> 
> This one is inelegant.
> It's not a definition block, and the patching and
it's definition block according to spec.

> manual offset calculation are scary.
it's the same thing as every user of build_header does every time,
so it's less scary compared to build_header and done only in one
place so user won't ever have to care about offsets.

> 
> > +        uint8_t *start = (uint8_t *)parent_ctx->buf->data +
> > +                         parent_ctx->buf->len;
> > +        uint32_t le32_len = cpu_to_le32(child->buf->len);
> > +
> > +        /* create linker entry for the DefinitionBlock */
> > +        bios_linker_loader_add_checksum(parent_ctx->linker,
> > +            ACPI_BUILD_TABLE_FILE,
> 
> Hard-coding file name here is very ugly.
> All this does not belong in this file, this
> is fw cfg interface.
It's but, it's the only one file and so far we don't have
plans to extend it and it does the same thing as build_header()


> 
> 
> > +            parent_ctx->buf->data,
> > +            start, child->buf->len, start + 9 /* checksum offset */);
> > +
> > +        /* set DefinitionBlock length at TableLength offset*/
> > +        memcpy(child->buf->data + 4, &le32_len, sizeof le32_len);
> 
> 
> This make no sense.
> In AML, there are no objects which are higher level
> than the table.
> 
> So for now, please just leave this alone:
> drop linker completely, keep table_data
> a simple GArray, not AML, and reuse build_header
> to fill in headers.
> 
> This way this file just deals with AML and ACPI spec.
Using build_header() is problematic for 2 reasons:
  1. it has to be done backwards,
     i.e. one has to reserve space for header first,
     than add content and then call build_header
     to patch header with current length and table definition data

  2. when using build_header() user has to calculate offsets and lengths
     manually every time.

While using aml_def_block() process is quite straightforward
and follows the declarative flow as it is in ASL,
which less confusing and error-prone, like:

ssdt = aml_def_block(...);
// add content to ssdt
aml_append(tables_blob, ssdt);

so hiding linker from user in this case makes usage simpler
and more harder to screw up, which is the whole point of
introducing this API.

I have a further plans to make other tables use
aml_def_block and get rid of acpi_add_table() which is also
confusing and simplify RSDT building doing it transparently
for user.

That way both ARM and i386 targets would reuse the same code
/API instead of re-implementing it in every target.
User will just get complete tables blob from API and
put it in respective fw_cfg file.
I also wish that we have had only one file for ACPI tables
(including RSDP) but ship already went away, maybe we can do
it for ARM though.

PS:
My secret goal is to bury linker and use it only when one
have to do so :), seriously.

> 
> 
> > +        break;
> > +    }
> > +    default:
> 
> This should assert.
sure

> 
> > +        break;
> > +    }
> > +    build_append_array(parent_ctx->buf, child->buf);
> > +}
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index 6d84f38..237080f 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> >  #define ACPI_BUILD_APPNAME6 "BOCHS "
> >  #define ACPI_BUILD_APPNAME4 "BXPC"
> >  
> > -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> >  
> > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > index 199f003..4033796 100644
> > --- a/include/hw/acpi/aml-build.h
> > +++ b/include/hw/acpi/aml-build.h
> > @@ -5,6 +5,67 @@
> >  #include <glib.h>
> >  #include "qemu/compiler.h"
> >  
> > +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > +
> > +typedef enum {
> > +    AML_HELPER = 0,
> > +    AML_NON_BLOCK,
> > +    AML_PACKAGE,
> > +    AML_EXT_PACKAGE,
> > +    AML_BUFFER,
> > +    AML_RES_TEMPLATE,
> > +    AML_DEF_BLOCK,
> > +} AmlBlockFlags;
> > +
> > +struct Aml {
> > +    GArray *buf;
> > +
> > +    /*< private >*/
> > +    uint8_t op;
> > +    AmlBlockFlags block_flags;
> > +    GArray *linker;
> > +};
> > +typedef struct Aml Aml;
> > +
> > +/**
> > + * init_aml_allocator:
> > + * @linker: linker that used by API for registering ACPI tables
> > + *          with linker firmware interfac
> > + *
> > + * Called for initializing API allocator which allow to use
> > + * AML API.
> > + * Returns: toplevel container which accumulates all other
> > + * ACPI tables.
> > + */
> > +Aml *init_aml_allocator(GArray *linker);
> > +
> > +/**
> > + * free_aml_allocator:
> > + *
> > + * Releases all elements used by AML API, frees associated memory
> > + * and invalidates AML allocator. After this call @init_aml_allocator
> > + * should be called again if AML API is to be used again.
> > + */
> > +void free_aml_allocator(void);
> > +
> > +/**
> > + * aml_append:
> > + * @parent_ctx: context to which @child element is added
> > + * @child: element that is copied into @parent_ctx context
> > + *
> > + * Joins Aml elements together and helps to construct AML tables
> > + * Examle of usage:
> > + *   Aml *table = aml_def_block("SSDT", ...);
> > + *   Aml *sb = aml_scope("\_SB");
> > + *   Aml *dev = aml_device("PCI0");
> > + *
> > + *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
> > + *   aml_append(sb, dev);
> > + *   aml_append(table, sb);
> > + */
> > +void aml_append(Aml *parent_ctx, Aml *child);
> > +
> > +/* other helpers */
> >  GArray *build_alloc_array(void);
> >  void build_free_array(GArray *array);
> >  void build_prepend_byte(GArray *array, uint8_t val);
> > -- 
> > 1.8.3.1
> 

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

* Re: [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API
  2015-02-17 16:47 ` [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Michael S. Tsirkin
@ 2015-02-17 17:51   ` Igor Mammedov
  2015-02-17 19:14     ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-17 17:51 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 17:47:03 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> This seems to change the contents of the tables in too many ways.  So of
> it needs changing since PCI are somewhat broken by your recent patch.
In which way is it broken?

> 
> So let's do this: please prepare a minimal patchset that just generates
> PCI description dynamically.  Drop everything that's not necessary, and
> verify that make check produces trivial diffs only.
> 
> We'll go from there.
> 

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-17 16:47     ` Igor Mammedov
@ 2015-02-17 19:03       ` Michael S. Tsirkin
  2015-02-18 10:47         ` Igor Mammedov
  2015-02-17 19:15       ` Michael S. Tsirkin
  1 sibling, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 19:03 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, Feb 17, 2015 at 05:47:26PM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 17:35:55 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > >  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
> > >  hw/i386/acpi-build.c        |  4 ----
> > >  include/hw/acpi/aml-build.h | 10 ++++++++++
> > >  3 files changed, 48 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > index 67d1371..cb1a1bd 100644
> > > --- a/hw/acpi/aml-build.c
> > > +++ b/hw/acpi/aml-build.c
> > > @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
> > >      }
> > >      build_append_array(parent_ctx->buf, child->buf);
> > >  }
> > > +
> > > +/*
> > > + * ACPI 1.0b: 16.2.1 Top Level AML
> > > + *            5.2.3 System Description Table Header
> > > + *
> > > + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> > > + */
> > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > +                   const char *oem_id, const char *oem_table_id,
> > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > +                   uint32_t creator_revision)
> > > +{
> > > +    int len;
> > > +    Aml *var = aml_alloc();
> > > +    var->block_flags = AML_DEF_BLOCK;
> > > +
> > > +    assert(strlen(signature) == 4);
> > > +    g_array_append_vals(var->buf, signature, 4);
> > > +    build_append_value(var->buf, 0, 4); /* Length place holder */
> > > +    build_append_byte(var->buf, revision);
> > > +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> > > +
> > > +    len = strlen(oem_id);
> > > +    assert(len <= 6);
> > > +    g_array_append_vals(var->buf, oem_id, len);
> > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> > > +
> > > +    len = strlen(oem_table_id);
> > > +    assert(len <= 8);
> > > +    g_array_append_vals(var->buf, oem_table_id, len);
> > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> > > +
> > > +    build_append_value(var->buf, oem_revision, 4);
> > > +    build_append_value(var->buf, creator_id, 4);
> > > +    build_append_value(var->buf, creator_revision, 4);
> > > +
> > > +    return var;
> > 
> > 
> > Please don't do this.
> > First, this is not a definition block encoding, so name
> > is wrong.
> > 
> > Second, we already have functions to fill in headers.
> > So just call them.
> > 
> > Filling structures byte by byte is unreadable -
> > I know ACPI spec often makes us do this but
> > when it doesn't, we should not do it.
> it does, in ACPI 5.1,
> 
> 20.2.1 Table and Table Header Encoding
> AMLCode := DefBlockHeader TermList
> DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID
> OemTableID OemRevision CreatorID CreatorRevision

Sorry I'm not merging this in this form, we should use structures
where possible, this is where C shines, just use the language
properly.


> > 
> > Pls keep using build_header for now.
> > 
> > 
> > > +}
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index a1bf450..553c86b 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> > >                                              NULL);
> > >  }
> > >  
> > > -#define ACPI_BUILD_APPNAME  "Bochs"
> > > -#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > -#define ACPI_BUILD_APPNAME4 "BXPC"
> > > -
> > >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> > >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> > >  
> > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > > index 4033796..2610336 100644
> > > --- a/include/hw/acpi/aml-build.h
> > > +++ b/include/hw/acpi/aml-build.h
> > > @@ -6,6 +6,10 @@
> > >  #include "qemu/compiler.h"
> > >  
> > >  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > > +#define ACPI_BUILD_APPNAME  "Bochs"
> > > +#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > +#define ACPI_BUILD_APPNAME4 "BXPC"
> > > +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
> > >  
> > >  typedef enum {
> > >      AML_HELPER = 0,
> > > @@ -65,6 +69,12 @@ void free_aml_allocator(void);
> > >   */
> > >  void aml_append(Aml *parent_ctx, Aml *child);
> > >  
> > > +/* Block AML object primitives */
> > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > +                   const char *oem_id, const char *oem_table_id,
> > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > +                   uint32_t creator_revision);
> > > +
> > >  /* other helpers */
> > >  GArray *build_alloc_array(void);
> > >  void build_free_array(GArray *array);
> > > -- 
> > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
  2015-02-17 17:50     ` Igor Mammedov
@ 2015-02-17 19:12       ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 19:12 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, zhaoshenglong, claudio.fontana, qemu-devel, marcel.a

On Tue, Feb 17, 2015 at 06:50:11PM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 17:26:16 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:53:23AM +0000, Igor Mammedov wrote:
> > > Adds for dynamic AML creation, which will be used
> > > for piecing ASL/AML primitives together and hiding
> > > from user/caller details about how nested context
> > > should be closed/packed leaving less space for
> > > mistakes and necessity to know how AML should be
> > > encoded, allowing user to concentrate on ASL
> > > representation instead.
> > > 
> > > For example it will allow to create AML like this:
> > > 
> > > init_aml_allocator();
> > > ...
> > > Aml *scope = aml_scope("PCI0")
> > > Aml *dev = aml_device("PM")
> > >     aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
> > > aml_append(scope, dev);
> > > ...
> > > free_aml_allocator();
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > >  hw/acpi/aml-build.c         | 91 +++++++++++++++++++++++++++++++++++++++++++++
> > >  hw/i386/acpi-build.c        |  1 -
> > >  include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++
> > >  3 files changed, 152 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > index bcb288e..096f347 100644
> > > --- a/hw/acpi/aml-build.c
> > > +++ b/hw/acpi/aml-build.c
> > > @@ -25,6 +25,8 @@
> > >  #include <stdbool.h>
> > >  #include <string.h>
> > >  #include "hw/acpi/aml-build.h"
> > > +#include "qemu/bswap.h"
> > > +#include "hw/acpi/bios-linker-loader.h"
> > >  
> > >  GArray *build_alloc_array(void)
> > >  {
> > > @@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)
> > >          build_append_value(table, value, 4);
> > >      }
> > >  }
> > > +
> > > +static GPtrArray *alloc_list;
> > > +
> > > +static Aml *aml_alloc(void)
> > > +{
> > > +    Aml *var = g_new0(typeof(*var), 1);
> > > +
> > > +    g_ptr_array_add(alloc_list, var);
> > > +    var->block_flags = AML_HELPER;
> > > +    var->buf = build_alloc_array();
> > > +    return var;
> > > +}
> > > +
> > > +static void aml_free(gpointer data)
> > > +{
> > > +    Aml *var = data;
> > > +    build_free_array(var->buf);
> > > +}
> > > +
> > > +Aml *init_aml_allocator(GArray *linker)
> > > +{
> > > +    Aml *var;
> > > +
> > > +    assert(!alloc_list);
> > > +    alloc_list = g_ptr_array_new_with_free_func(aml_free);
> > > +    var = aml_alloc();
> > > +    var->linker = linker;
> > > +    return var;
> > > +}
> > > +
> > > +void free_aml_allocator(void)
> > > +{
> > > +    g_ptr_array_free(alloc_list, true);
> > > +    alloc_list = 0;
> > > +}
> > > +
> > > +static void build_buffer(GArray *array, uint8_t op)
> > > +{
> > > +    GArray *data = build_alloc_array();
> > > +
> > > +    build_append_int(data, array->len);
> > > +    g_array_prepend_vals(array, data->data, data->len);
> > > +    build_free_array(data);
> > > +    build_package(array, op);
> > > +}
> > > +
> > > +void aml_append(Aml *parent_ctx, Aml *child)
> > > +{
> > > +    switch (child->block_flags) {
> > > +    case AML_NON_BLOCK:
> > > +        build_append_byte(parent_ctx->buf, child->op);
> > > +        break;
> > > +    case AML_EXT_PACKAGE:
> > > +        build_extop_package(child->buf, child->op);
> > > +        break;
> > > +    case AML_PACKAGE:
> > > +        build_package(child->buf, child->op);
> > > +        break;
> > > +    case AML_RES_TEMPLATE:
> > > +        build_append_byte(child->buf, 0x79); /* EndTag */
> > > +        /*
> > > +         * checksum operations is treated as succeeded if checksum
> > > +         * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
> > > +         */
> > > +        build_append_byte(child->buf, 0);
> > > +        /* fall through, to pack resources in buffer */
> > > +    case AML_BUFFER:
> > > +        build_buffer(child->buf, child->op);
> > > +        break;
> > > +    case AML_DEF_BLOCK: {
> > 
> > This one is inelegant.
> > It's not a definition block, and the patching and
> it's definition block according to spec.

definition block is not an AML thing, is it?
It's an ASL construct I think.

AML calls them tables, e.g.:

20.2.1 Table and Table Header Encoding




> > manual offset calculation are scary.
> it's the same thing as every user of build_header does every time,
> so it's less scary compared to build_header and done only in one
> place so user won't ever have to care about offsets.

We have different definitions of scary.
C structures is the standard way to lay out memory.

> > 
> > > +        uint8_t *start = (uint8_t *)parent_ctx->buf->data +
> > > +                         parent_ctx->buf->len;
> > > +        uint32_t le32_len = cpu_to_le32(child->buf->len);
> > > +
> > > +        /* create linker entry for the DefinitionBlock */
> > > +        bios_linker_loader_add_checksum(parent_ctx->linker,
> > > +            ACPI_BUILD_TABLE_FILE,
> > 
> > Hard-coding file name here is very ugly.
> > All this does not belong in this file, this
> > is fw cfg interface.
> It's but, it's the only one file and so far we don't have
> plans to extend it and it does the same thing as build_header()

So just call build_header.

> 
> > 
> > 
> > > +            parent_ctx->buf->data,
> > > +            start, child->buf->len, start + 9 /* checksum offset */);
> > > +
> > > +        /* set DefinitionBlock length at TableLength offset*/
> > > +        memcpy(child->buf->data + 4, &le32_len, sizeof le32_len);
> > 
> > 
> > This make no sense.
> > In AML, there are no objects which are higher level
> > than the table.
> > 
> > So for now, please just leave this alone:
> > drop linker completely, keep table_data
> > a simple GArray, not AML, and reuse build_header
> > to fill in headers.
> > 
> > This way this file just deals with AML and ACPI spec.
> Using build_header() is problematic for 2 reasons:
>   1. it has to be done backwards,
>      i.e. one has to reserve space for header first,
>      than add content and then call build_header
>      to patch header with current length and table definition data
> 
>   2. when using build_header() user has to calculate offsets and lengths
>      manually every time.

It's not easy to use, but it's not too hard either.
As there's a single instance now,
let's merge the rest, we'll work on a cleaner interface
for build_header.

this is not it.


> While using aml_def_block() process is quite straightforward
> and follows the declarative flow as it is in ASL,
> which less confusing and error-prone, like:
> 
> ssdt = aml_def_block(...);
> // add content to ssdt
> aml_append(tables_blob, ssdt);
> 
> so hiding linker from user in this case makes usage simpler
> and more harder to screw up, which is the whole point of
> introducing this API.
> 
> I have a further plans to make other tables use
> aml_def_block and get rid of acpi_add_table() which is also
> confusing and simplify RSDT building doing it transparently
> for user.
> 
> That way both ARM and i386 targets would reuse the same code
> /API instead of re-implementing it in every target.
> User will just get complete tables blob from API and
> put it in respective fw_cfg file.
> I also wish that we have had only one file for ACPI tables
> (including RSDP) but ship already went away, maybe we can do
> it for ARM though.

Unlikely.

> PS:
> My secret goal is to bury linker and use it only when one
> have to do so :), seriously.

You are doing too many things at once.
We need a minimal patchset to start merging your work.
so drop this part please, just use build_header.


> > 
> > 
> > > +        break;
> > > +    }
> > > +    default:
> > 
> > This should assert.
> sure
> 
> > 
> > > +        break;
> > > +    }
> > > +    build_append_array(parent_ctx->buf, child->buf);
> > > +}
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index 6d84f38..237080f 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> > >  #define ACPI_BUILD_APPNAME6 "BOCHS "
> > >  #define ACPI_BUILD_APPNAME4 "BXPC"
> > >  
> > > -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> > >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> > >  
> > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > > index 199f003..4033796 100644
> > > --- a/include/hw/acpi/aml-build.h
> > > +++ b/include/hw/acpi/aml-build.h
> > > @@ -5,6 +5,67 @@
> > >  #include <glib.h>
> > >  #include "qemu/compiler.h"
> > >  
> > > +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > > +
> > > +typedef enum {
> > > +    AML_HELPER = 0,
> > > +    AML_NON_BLOCK,
> > > +    AML_PACKAGE,
> > > +    AML_EXT_PACKAGE,
> > > +    AML_BUFFER,
> > > +    AML_RES_TEMPLATE,
> > > +    AML_DEF_BLOCK,
> > > +} AmlBlockFlags;
> > > +
> > > +struct Aml {
> > > +    GArray *buf;
> > > +
> > > +    /*< private >*/
> > > +    uint8_t op;
> > > +    AmlBlockFlags block_flags;
> > > +    GArray *linker;
> > > +};
> > > +typedef struct Aml Aml;
> > > +
> > > +/**
> > > + * init_aml_allocator:
> > > + * @linker: linker that used by API for registering ACPI tables
> > > + *          with linker firmware interfac
> > > + *
> > > + * Called for initializing API allocator which allow to use
> > > + * AML API.
> > > + * Returns: toplevel container which accumulates all other
> > > + * ACPI tables.
> > > + */
> > > +Aml *init_aml_allocator(GArray *linker);
> > > +
> > > +/**
> > > + * free_aml_allocator:
> > > + *
> > > + * Releases all elements used by AML API, frees associated memory
> > > + * and invalidates AML allocator. After this call @init_aml_allocator
> > > + * should be called again if AML API is to be used again.
> > > + */
> > > +void free_aml_allocator(void);
> > > +
> > > +/**
> > > + * aml_append:
> > > + * @parent_ctx: context to which @child element is added
> > > + * @child: element that is copied into @parent_ctx context
> > > + *
> > > + * Joins Aml elements together and helps to construct AML tables
> > > + * Examle of usage:
> > > + *   Aml *table = aml_def_block("SSDT", ...);
> > > + *   Aml *sb = aml_scope("\_SB");
> > > + *   Aml *dev = aml_device("PCI0");
> > > + *
> > > + *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
> > > + *   aml_append(sb, dev);
> > > + *   aml_append(table, sb);
> > > + */
> > > +void aml_append(Aml *parent_ctx, Aml *child);
> > > +
> > > +/* other helpers */
> > >  GArray *build_alloc_array(void);
> > >  void build_free_array(GArray *array);
> > >  void build_prepend_byte(GArray *array, uint8_t val);
> > > -- 
> > > 1.8.3.1
> > 

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

* Re: [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API
  2015-02-17 17:51   ` Igor Mammedov
@ 2015-02-17 19:14     ` Michael S. Tsirkin
  2015-02-18 10:35       ` Igor Mammedov
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 19:14 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, Feb 17, 2015 at 06:51:16PM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 17:47:03 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > This seems to change the contents of the tables in too many ways.  So of
> > it needs changing since PCI are somewhat broken by your recent patch.
> In which way is it broken?

Try make check and look at the diffs.
They shouldn't be so big.
I want differences to be trivial, e.g.
0->Zero would be ok.
Refactoring code generation should be separate from
changing generated code.


> > 
> > So let's do this: please prepare a minimal patchset that just generates
> > PCI description dynamically.  Drop everything that's not necessary, and
> > verify that make check produces trivial diffs only.
> > 
> > We'll go from there.
> > 

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-17 16:47     ` Igor Mammedov
  2015-02-17 19:03       ` Michael S. Tsirkin
@ 2015-02-17 19:15       ` Michael S. Tsirkin
  2015-02-18  9:50         ` Igor Mammedov
  1 sibling, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 19:15 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, Feb 17, 2015 at 05:47:26PM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 17:35:55 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > >  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
> > >  hw/i386/acpi-build.c        |  4 ----
> > >  include/hw/acpi/aml-build.h | 10 ++++++++++
> > >  3 files changed, 48 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > index 67d1371..cb1a1bd 100644
> > > --- a/hw/acpi/aml-build.c
> > > +++ b/hw/acpi/aml-build.c
> > > @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
> > >      }
> > >      build_append_array(parent_ctx->buf, child->buf);
> > >  }
> > > +
> > > +/*
> > > + * ACPI 1.0b: 16.2.1 Top Level AML
> > > + *            5.2.3 System Description Table Header
> > > + *
> > > + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> > > + */
> > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > +                   const char *oem_id, const char *oem_table_id,
> > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > +                   uint32_t creator_revision)
> > > +{
> > > +    int len;
> > > +    Aml *var = aml_alloc();
> > > +    var->block_flags = AML_DEF_BLOCK;
> > > +
> > > +    assert(strlen(signature) == 4);
> > > +    g_array_append_vals(var->buf, signature, 4);
> > > +    build_append_value(var->buf, 0, 4); /* Length place holder */
> > > +    build_append_byte(var->buf, revision);
> > > +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> > > +
> > > +    len = strlen(oem_id);
> > > +    assert(len <= 6);
> > > +    g_array_append_vals(var->buf, oem_id, len);
> > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> > > +
> > > +    len = strlen(oem_table_id);
> > > +    assert(len <= 8);
> > > +    g_array_append_vals(var->buf, oem_table_id, len);
> > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> > > +
> > > +    build_append_value(var->buf, oem_revision, 4);
> > > +    build_append_value(var->buf, creator_id, 4);
> > > +    build_append_value(var->buf, creator_revision, 4);
> > > +
> > > +    return var;
> > 
> > 
> > Please don't do this.
> > First, this is not a definition block encoding, so name
> > is wrong.
> > 
> > Second, we already have functions to fill in headers.
> > So just call them.
> > 
> > Filling structures byte by byte is unreadable -
> > I know ACPI spec often makes us do this but
> > when it doesn't, we should not do it.
> it does, in ACPI 5.1,
> 
> 20.2.1 Table and Table Header Encoding
> AMLCode := DefBlockHeader TermList
> DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID
> OemTableID OemRevision CreatorID CreatorRevision

So spec explains it very badly, but these all are
fixed width fields.
Filling them in using add_byte just makes for hard to
read code.


> > 
> > Pls keep using build_header for now.
> > 
> > 
> > > +}
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index a1bf450..553c86b 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> > >                                              NULL);
> > >  }
> > >  
> > > -#define ACPI_BUILD_APPNAME  "Bochs"
> > > -#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > -#define ACPI_BUILD_APPNAME4 "BXPC"
> > > -
> > >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> > >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> > >  
> > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > > index 4033796..2610336 100644
> > > --- a/include/hw/acpi/aml-build.h
> > > +++ b/include/hw/acpi/aml-build.h
> > > @@ -6,6 +6,10 @@
> > >  #include "qemu/compiler.h"
> > >  
> > >  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > > +#define ACPI_BUILD_APPNAME  "Bochs"
> > > +#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > +#define ACPI_BUILD_APPNAME4 "BXPC"
> > > +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
> > >  
> > >  typedef enum {
> > >      AML_HELPER = 0,
> > > @@ -65,6 +69,12 @@ void free_aml_allocator(void);
> > >   */
> > >  void aml_append(Aml *parent_ctx, Aml *child);
> > >  
> > > +/* Block AML object primitives */
> > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > +                   const char *oem_id, const char *oem_table_id,
> > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > +                   uint32_t creator_revision);
> > > +
> > >  /* other helpers */
> > >  GArray *build_alloc_array(void);
> > >  void build_free_array(GArray *array);
> > > -- 
> > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically Igor Mammedov
@ 2015-02-17 19:39   ` Michael S. Tsirkin
  2015-02-18 10:00     ` Igor Mammedov
  2015-02-18 10:42     ` Igor Mammedov
  0 siblings, 2 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 19:39 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:43AM +0000, Igor Mammedov wrote:
> Replace AML template patching with direct composing
> of PCI device entries in C. It allows to simplify
> PCI tree generation further and saves us about 400LOC
> scattered through different files, confining tree
> generation to one C function which is much easier
> to deal with.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Some comments below, this looks nice.

However, something strange is going on.
This looks like it should produce identical
code to what was there, but in fact your previous
patch pc: acpi-build: simplify PCI bus tree generation
changes SSDT, then this patch changes it back to
what it was.

I'm confused by this.  Can't refactoring be done without changing the
output back and forth, somehow?

> ---
>  hw/i386/Makefile.objs            |   6 +-
>  hw/i386/acpi-build.c             | 207 +++++++++++---------------------
>  hw/i386/ssdt-pcihp.dsl           | 100 ----------------
>  hw/i386/ssdt-pcihp.hex.generated | 251 ---------------------------------------
>  4 files changed, 72 insertions(+), 492 deletions(-)
>  delete mode 100644 hw/i386/ssdt-pcihp.dsl
>  delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
> 
> diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> index 2b678ef..4509cd1 100644
> --- a/hw/i386/Makefile.objs
> +++ b/hw/i386/Makefile.objs
> @@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
>  obj-y += kvmvapic.o
>  obj-y += acpi-build.o
>  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> -	hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
> -	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
> -	hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \
> -	hw/i386/ssdt-tpm.hex
> +	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> +	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
>  
>  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
>      ; then echo "$(2)"; else echo "$(3)"; fi ;)
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index bdc343f..b6626f5 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)
>  #define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
>  #define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
>  
> -/* 0x5B 0x82 DeviceOp PkgLength NameString */
> -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
> -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
> -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
> -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
> -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
> -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
> -
> -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
> -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
> -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
> -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
> -
> -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
> -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
> -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
> -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
> -
> -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
> -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
> -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
> -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
> -
>  #include "hw/i386/ssdt-mem.hex"
>  
>  /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
> @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)
>  #define ACPI_SSDT_HEADER_LENGTH 36
>  
>  #include "hw/i386/ssdt-misc.hex"
> -#include "hw/i386/ssdt-pcihp.hex"
>  #include "hw/i386/ssdt-tpm.hex"
>  
>  static void
> @@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,
>      build_append_and_cleanup_method(device, method);
>  }
>  
> -static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
> -{
> -    unsigned devfn = PCI_DEVFN(slot, 0);
> -
> -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> -    ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
> -    ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
> -}
> -
> -static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
> -{
> -    unsigned devfn = PCI_DEVFN(slot, 0);
> -
> -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> -    ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
> -}
> -
> -static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
> -{
> -    unsigned devfn = PCI_DEVFN(slot, 0);
> -
> -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> -    ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
> -}
> -
> -static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
> -{
> -    unsigned devfn = PCI_DEVFN(slot, 0);
> -
> -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> -    ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
> -}
> -
>  /* Assign BSEL property to all buses.  In the future, this can be changed
>   * to only assign to buses that support hotplug.
>   */
> @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void)
>      }
>  }
>  
> -static void build_append_pcihp_notify_entry(GArray *method, int slot)
> +static void build_append_pcihp_notify_entry(Aml *method, int slot)
>  {
> -    GArray *ifctx;
> +    Aml *if_ctx;
> +    int32_t devfn = PCI_DEVFN(slot, 0);
>  
> -    ifctx = build_alloc_array();
> -    build_append_byte(ifctx, 0x7B); /* AndOp */
> -    build_append_byte(ifctx, 0x68); /* Arg0Op */
> -    build_append_int(ifctx, 0x1U << slot);
> -    build_append_byte(ifctx, 0x00); /* NullName */
> -    build_append_byte(ifctx, 0x86); /* NotifyOp */
> -    build_append_namestring(ifctx, "S%.02X", PCI_DEVFN(slot, 0));
> -    build_append_byte(ifctx, 0x69); /* Arg1Op */
> -
> -    /* Pack it up */
> -    build_package(ifctx, 0xA0 /* IfOp */);
> -    build_append_array(method, ifctx);
> -    build_free_array(ifctx);
> +    if_ctx = aml_if(aml_and(aml_arg(0), aml_int(0x1U << slot)));
> +    aml_append(if_ctx, aml_notify(aml_name("S%.02X", devfn), aml_arg(1)));
> +    aml_append(method, if_ctx);
>  }
>  
> -static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> +static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
>                                           bool pcihp_bridge_en)
>  {
> -    GArray *bus_table = build_alloc_array();
> -    GArray *method = NULL;
> +    Aml *dev, *notify_method, *method;
>      QObject *bsel;
>      PCIBus *sec;
>      int i;
>  
> -    if (bus->parent_dev) {
> -        build_append_namestring(bus_table, "S%.02X_", bus->parent_dev->devfn);
> -    } else {
> -        build_append_namestring(bus_table, "PCI0");
> -    }
> -
>      bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
>      if (bsel) {
> -        build_append_byte(bus_table, 0x08); /* NameOp */
> -        build_append_namestring(bus_table, "BSEL");
> -        build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
> -        method = build_alloc_method("DVNT", 2);
> +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> +
> +        aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val)));
> +        notify_method = aml_method("DVNT", 2);
>      }
>  
>      for (i = 0; i < ARRAY_SIZE(bus->devices); i += PCI_FUNC_MAX) {
> @@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
>  
>          if (!pdev) {
>              if (bsel) {
> -                void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> -                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> -                patch_pcihp(slot, pcihp);
> -
> -                build_append_pcihp_notify_entry(method, slot);
> +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> +                aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> +                method = aml_method("_EJ0", 1);
> +                aml_append(method,
> +                    aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> +                );
> +                aml_append(dev, method);
> +                aml_append(parent_scope, dev);
> +
> +                build_append_pcihp_notify_entry(notify_method, slot);
>              } else {
> -                void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> -                memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> -                patch_pcinohp(slot, pcihp);
> +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> +                aml_append(parent_scope, dev);
>              }
>              continue;
>          }
> @@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
>          bridge_in_acpi = pc->is_bridge && pcihp_bridge_en &&
>              !DEVICE(pdev)->hotplugged;
>  
> +        dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> +        aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> +
>          if (pc->class_id == PCI_CLASS_DISPLAY_VGA) {
> +            int s3d = 0;
>  
>              if (object_dynamic_cast(OBJECT(pdev), "qxl-vga")) {
> -                void *pcihp = acpi_data_push(bus_table,
> -                                             ACPI_PCIQXL_SIZEOF);
> -                      memcpy(pcihp, ACPI_PCIQXL_AML, ACPI_PCIQXL_SIZEOF);
> -                      patch_pciqxl(slot, pcihp);
> -            } else {
> -                void *pcihp = acpi_data_push(bus_table,
> -                                             ACPI_PCIVGA_SIZEOF);
> -                memcpy(pcihp, ACPI_PCIVGA_AML, ACPI_PCIVGA_SIZEOF);
> -                patch_pcivga(slot, pcihp);
> +                s3d = 3;
>              }

I dislike this style, where 0 is set, then over-written.
Please do
    if (cond) {
        s = 3;
    } else {
        s = 0;
    }



> +
> +            method = aml_method("_S1D", 0);
> +            aml_append(method, aml_return(aml_int(0)));
> +            aml_append(dev, method);
> +
> +            method = aml_method("_S2D", 0);
> +            aml_append(method, aml_return(aml_int(0)));
> +            aml_append(dev, method);
> +
> +            method = aml_method("_S3D", 0);
> +            aml_append(method, aml_return(aml_int(s3d)));
> +            aml_append(dev, method);
>          } else if (dc->hotpluggable && !bridge_in_acpi) {
> -            void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> -            memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> -            patch_pcihp(slot, pcihp);
> +            aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> +
> +            method = aml_method("_EJ0", 1);
> +            aml_append(method,
> +                aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> +            );
> +            aml_append(dev, method);
>  
>              if (bsel) {
> -                build_append_pcihp_notify_entry(method, slot);
> +                build_append_pcihp_notify_entry(notify_method, slot);
>              }
>          } else {
> -            void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> -            memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> -            patch_pcinohp(slot, pcihp);
> -
>              /* When hotplug for bridges is enabled, bridges that are
>               * described in ACPI separately aren't themselves hot-pluggable.
>               * Hotplugged bridges *are* hot-pluggable.
> @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
>              if (bridge_in_acpi) {
>                  PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
>  
> -                build_append_pci_bus_devices(bus_table, sec_bus,
> -                                             pcihp_bridge_en);
> +                build_append_pci_bus_devices(dev, sec_bus, pcihp_bridge_en);
>              }
>          }
> +        aml_append(parent_scope, dev);
>      }
>  
>      if (bsel) {
> -        build_append_and_cleanup_method(bus_table, method);
> +        aml_append(parent_scope, notify_method);
>      }
>  
>      /* Append PCNT method to notify about events on local and child buses.
>       * Add unconditionally for root since DSDT expects it.
>       */
> -    method = build_alloc_method("PCNT", 0);
> +    method = aml_method("PCNT", 0);
>  
>      /* If bus supports hotplug select it and notify about local events */
>      if (bsel) {
> -        build_append_byte(method, 0x70); /* StoreOp */
> -        build_append_int(method, qint_get_int(qobject_to_qint(bsel)));
> -        build_append_namestring(method, "BNUM");
> -        build_append_namestring(method, "DVNT");
> -        build_append_namestring(method, "PCIU");
> -        build_append_int(method, 1); /* Device Check */
> -        build_append_namestring(method, "DVNT");
> -        build_append_namestring(method, "PCID");
> -        build_append_int(method, 3); /* Eject Request */
> +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> +        aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
> +        aml_append(method,
> +            aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check */)
> +        );
> +        aml_append(method,
> +            aml_call2("DVNT", aml_name("PCID"), aml_int(3)/* Eject Request */)
> +        );
>      }
>  
>      /* Notify about child bus events in any case */
>      if (pcihp_bridge_en) {
>          QLIST_FOREACH(sec, &bus->child, sibling) {
> -            build_append_namestring(method, "^S%.02X.PCNT",
> -                                    sec->parent_dev->devfn);
> +            int32_t devfn = sec->parent_dev->devfn;
> +
> +            aml_append(method, aml_name("^S%.02X.PCNT", devfn));
>          }
>      }
> -
> -    build_append_and_cleanup_method(bus_table, method);
> -
> -    build_package(bus_table, 0x10); /* ScopeOp */
> -    build_append_array(parent_scope, bus_table);
> -    build_free_array(bus_table);
> +    aml_append(parent_scope, method);
>  }
>  
>  static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
> @@ -943,9 +875,10 @@ build_ssdt(Aml *table_data,
>              }
>  
>              if (bus) {
> +                Aml *scope = aml_scope("PCI0");
>                  /* Scan all PCI buses. Generate tables to support hotplug. */
> -                build_append_pci_bus_devices(sb_scope->buf, bus,
> -                                             pm->pcihp_bridge_en);
> +                build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en);
> +                aml_append(sb_scope, scope);
>              }
>          }
>          aml_append(ssdt, sb_scope);
> diff --git a/hw/i386/ssdt-pcihp.dsl b/hw/i386/ssdt-pcihp.dsl
> deleted file mode 100644
> index ac91c05..0000000
> --- a/hw/i386/ssdt-pcihp.dsl
> +++ /dev/null
> @@ -1,100 +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/>.
> - */
> -
> -ACPI_EXTRACT_ALL_CODE ssdp_pcihp_aml
> -
> -DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
> -{
> -
> -/****************************************************************
> - * PCI hotplug
> - ****************************************************************/
> -
> -    /* Objects supplied by DSDT */
> -    External(\_SB.PCI0, DeviceObj)
> -    External(\_SB.PCI0.PCEJ, MethodObj)
> -    External(BSEL, IntObj)
> -
> -    Scope(\_SB.PCI0) {
> -
> -        /* Bulk generated PCI hotplug devices */
> -        ACPI_EXTRACT_DEVICE_START ssdt_pcihp_start
> -        ACPI_EXTRACT_DEVICE_END ssdt_pcihp_end
> -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcihp_name
> -
> -        // Extract the offsets of the device name, address dword and the slot
> -        // name byte - we fill them in for each device.
> -        Device(SAA) {
> -            ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcihp_id
> -            Name(_SUN, 0xAA)
> -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcihp_adr
> -            Name(_ADR, 0xAA0000)
> -            Method(_EJ0, 1) {
> -                PCEJ(BSEL, _SUN)
> -            }
> -        }
> -
> -        ACPI_EXTRACT_DEVICE_START ssdt_pcinohp_start
> -        ACPI_EXTRACT_DEVICE_END ssdt_pcinohp_end
> -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcinohp_name
> -
> -        // Extract the offsets of the device name, address dword and the slot
> -        // name byte - we fill them in for each device.
> -        Device(SBB) {
> -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcinohp_adr
> -            Name(_ADR, 0xAA0000)
> -        }
> -
> -        ACPI_EXTRACT_DEVICE_START ssdt_pcivga_start
> -        ACPI_EXTRACT_DEVICE_END ssdt_pcivga_end
> -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcivga_name
> -
> -        // Extract the offsets of the device name, address dword and the slot
> -        // name byte - we fill them in for each device.
> -        Device(SCC) {
> -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcivga_adr
> -            Name(_ADR, 0xAA0000)
> -            Method(_S1D, 0, NotSerialized) {
> -                Return (0x00)
> -            }
> -            Method(_S2D, 0, NotSerialized) {
> -                Return (0x00)
> -            }
> -            Method(_S3D, 0, NotSerialized) {
> -                Return (0x00)
> -            }
> -        }
> -
> -        ACPI_EXTRACT_DEVICE_START ssdt_pciqxl_start
> -        ACPI_EXTRACT_DEVICE_END ssdt_pciqxl_end
> -        ACPI_EXTRACT_DEVICE_STRING ssdt_pciqxl_name
> -
> -        // Extract the offsets of the device name, address dword and the slot
> -        // name byte - we fill them in for each device.
> -        Device(SDD) {
> -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pciqxl_adr
> -            Name(_ADR, 0xAA0000)
> -            Method(_S1D, 0, NotSerialized) {
> -                Return (0x00)
> -            }
> -            Method(_S2D, 0, NotSerialized) {
> -                Return (0x00)
> -            }
> -            Method(_S3D, 0, NotSerialized) {
> -                Return (0x03)           // QXL
> -            }
> -        }
> -    }
> -}
> diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
> deleted file mode 100644
> index 72ffa84..0000000
> --- a/hw/i386/ssdt-pcihp.hex.generated

Pls don't send generated file patches.
Just note it should be removed in comment, I'll do it.

> +++ /dev/null
> @@ -1,251 +0,0 @@
> -static unsigned char ssdt_pcihp_name[] = {
> -0x34
> -};
> -static unsigned char ssdt_pcivga_end[] = {
> -0x99
> -};
> -static unsigned char ssdt_pcivga_name[] = {
> -0x70
> -};
> -static unsigned char ssdt_pcihp_adr[] = {
> -0x45
> -};
> -static unsigned char ssdt_pcinohp_end[] = {
> -0x6d
> -};
> -static unsigned char ssdt_pcihp_end[] = {
> -0x5c
> -};
> -static unsigned char ssdt_pciqxl_start[] = {
> -0x99
> -};
> -static unsigned char ssdt_pcinohp_name[] = {
> -0x5f
> -};
> -static unsigned char ssdp_pcihp_aml[] = {
> -0x53,
> -0x53,
> -0x44,
> -0x54,
> -0xc6,
> -0x0,
> -0x0,
> -0x0,
> -0x1,
> -0x70,
> -0x42,
> -0x58,
> -0x50,
> -0x43,
> -0x0,
> -0x0,
> -0x42,
> -0x58,
> -0x53,
> -0x53,
> -0x44,
> -0x54,
> -0x50,
> -0x43,
> -0x1,
> -0x0,
> -0x0,
> -0x0,
> -0x49,
> -0x4e,
> -0x54,
> -0x4c,
> -0x15,
> -0x11,
> -0x13,
> -0x20,
> -0x10,
> -0x41,
> -0xa,
> -0x5c,
> -0x2e,
> -0x5f,
> -0x53,
> -0x42,
> -0x5f,
> -0x50,
> -0x43,
> -0x49,
> -0x30,
> -0x5b,
> -0x82,
> -0x29,
> -0x53,
> -0x41,
> -0x41,
> -0x5f,
> -0x8,
> -0x5f,
> -0x53,
> -0x55,
> -0x4e,
> -0xa,
> -0xaa,
> -0x8,
> -0x5f,
> -0x41,
> -0x44,
> -0x52,
> -0xc,
> -0x0,
> -0x0,
> -0xaa,
> -0x0,
> -0x14,
> -0x12,
> -0x5f,
> -0x45,
> -0x4a,
> -0x30,
> -0x1,
> -0x50,
> -0x43,
> -0x45,
> -0x4a,
> -0x42,
> -0x53,
> -0x45,
> -0x4c,
> -0x5f,
> -0x53,
> -0x55,
> -0x4e,
> -0x5b,
> -0x82,
> -0xf,
> -0x53,
> -0x42,
> -0x42,
> -0x5f,
> -0x8,
> -0x5f,
> -0x41,
> -0x44,
> -0x52,
> -0xc,
> -0x0,
> -0x0,
> -0xaa,
> -0x0,
> -0x5b,
> -0x82,
> -0x2a,
> -0x53,
> -0x43,
> -0x43,
> -0x5f,
> -0x8,
> -0x5f,
> -0x41,
> -0x44,
> -0x52,
> -0xc,
> -0x0,
> -0x0,
> -0xaa,
> -0x0,
> -0x14,
> -0x8,
> -0x5f,
> -0x53,
> -0x31,
> -0x44,
> -0x0,
> -0xa4,
> -0x0,
> -0x14,
> -0x8,
> -0x5f,
> -0x53,
> -0x32,
> -0x44,
> -0x0,
> -0xa4,
> -0x0,
> -0x14,
> -0x8,
> -0x5f,
> -0x53,
> -0x33,
> -0x44,
> -0x0,
> -0xa4,
> -0x0,
> -0x5b,
> -0x82,
> -0x2b,
> -0x53,
> -0x44,
> -0x44,
> -0x5f,
> -0x8,
> -0x5f,
> -0x41,
> -0x44,
> -0x52,
> -0xc,
> -0x0,
> -0x0,
> -0xaa,
> -0x0,
> -0x14,
> -0x8,
> -0x5f,
> -0x53,
> -0x31,
> -0x44,
> -0x0,
> -0xa4,
> -0x0,
> -0x14,
> -0x8,
> -0x5f,
> -0x53,
> -0x32,
> -0x44,
> -0x0,
> -0xa4,
> -0x0,
> -0x14,
> -0x9,
> -0x5f,
> -0x53,
> -0x33,
> -0x44,
> -0x0,
> -0xa4,
> -0xa,
> -0x3
> -};
> -static unsigned char ssdt_pciqxl_adr[] = {
> -0xa6
> -};
> -static unsigned char ssdt_pcinohp_adr[] = {
> -0x69
> -};
> -static unsigned char ssdt_pcivga_adr[] = {
> -0x7a
> -};
> -static unsigned char ssdt_pciqxl_name[] = {
> -0x9c
> -};
> -static unsigned char ssdt_pcivga_start[] = {
> -0x6d
> -};
> -static unsigned char ssdt_pciqxl_end[] = {
> -0xc6
> -};
> -static unsigned char ssdt_pcihp_start[] = {
> -0x31
> -};
> -static unsigned char ssdt_pcihp_id[] = {
> -0x3e
> -};
> -static unsigned char ssdt_pcinohp_start[] = {
> -0x5c
> -};
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append() Igor Mammedov
  2015-02-17 16:26   ` Michael S. Tsirkin
@ 2015-02-17 19:46   ` Michael S. Tsirkin
  2015-02-18  8:50     ` Igor Mammedov
  1 sibling, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 19:46 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:23AM +0000, Igor Mammedov wrote:
> Adds for dynamic AML creation, which will be used
> for piecing ASL/AML primitives together and hiding
> from user/caller details about how nested context
> should be closed/packed leaving less space for
> mistakes and necessity to know how AML should be
> encoded, allowing user to concentrate on ASL
> representation instead.
> 
> For example it will allow to create AML like this:
> 
> init_aml_allocator();
> ...
> Aml *scope = aml_scope("PCI0")
> Aml *dev = aml_device("PM")
>     aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
> aml_append(scope, dev);
> ...
> free_aml_allocator();
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

This should be split up, so we can see
functionality added in the same patch where it's used.
It's too hard to evaluate this alone.


> ---
>  hw/acpi/aml-build.c         | 91 +++++++++++++++++++++++++++++++++++++++++++++
>  hw/i386/acpi-build.c        |  1 -
>  include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++
>  3 files changed, 152 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index bcb288e..096f347 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -25,6 +25,8 @@
>  #include <stdbool.h>
>  #include <string.h>
>  #include "hw/acpi/aml-build.h"
> +#include "qemu/bswap.h"
> +#include "hw/acpi/bios-linker-loader.h"
>  
>  GArray *build_alloc_array(void)
>  {
> @@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)
>          build_append_value(table, value, 4);
>      }
>  }
> +
> +static GPtrArray *alloc_list;
> +
> +static Aml *aml_alloc(void)
> +{
> +    Aml *var = g_new0(typeof(*var), 1);
> +
> +    g_ptr_array_add(alloc_list, var);
> +    var->block_flags = AML_HELPER;
> +    var->buf = build_alloc_array();
> +    return var;
> +}
> +
> +static void aml_free(gpointer data)
> +{
> +    Aml *var = data;
> +    build_free_array(var->buf);
> +}
> +
> +Aml *init_aml_allocator(GArray *linker)
> +{
> +    Aml *var;
> +
> +    assert(!alloc_list);
> +    alloc_list = g_ptr_array_new_with_free_func(aml_free);
> +    var = aml_alloc();
> +    var->linker = linker;
> +    return var;
> +}
> +
> +void free_aml_allocator(void)
> +{
> +    g_ptr_array_free(alloc_list, true);
> +    alloc_list = 0;
> +}
> +
> +static void build_buffer(GArray *array, uint8_t op)

What does this do?

> +{
> +    GArray *data = build_alloc_array();
> +
> +    build_append_int(data, array->len);
> +    g_array_prepend_vals(array, data->data, data->len);

Prepend is best avoided. Can't say whether it's necessary
here.

> +    build_free_array(data);
> +    build_package(array, op);
> +}
> +
> +void aml_append(Aml *parent_ctx, Aml *child)
> +{
> +    switch (child->block_flags) {
> +    case AML_NON_BLOCK:
> +        build_append_byte(parent_ctx->buf, child->op);
> +        break;
> +    case AML_EXT_PACKAGE:
> +        build_extop_package(child->buf, child->op);
> +        break;
> +    case AML_PACKAGE:
> +        build_package(child->buf, child->op);
> +        break;
> +    case AML_RES_TEMPLATE:
> +        build_append_byte(child->buf, 0x79); /* EndTag */
> +        /*
> +         * checksum operations is treated as succeeded if checksum

are treated?

> +         * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]

Pls always quote oldest spec, not latest one.


> +         */
> +        build_append_byte(child->buf, 0);
> +        /* fall through, to pack resources in buffer */
> +    case AML_BUFFER:
> +        build_buffer(child->buf, child->op);
> +        break;
> +    case AML_DEF_BLOCK: {
> +        uint8_t *start = (uint8_t *)parent_ctx->buf->data +
> +                         parent_ctx->buf->len;
> +        uint32_t le32_len = cpu_to_le32(child->buf->len);
> +
> +        /* create linker entry for the DefinitionBlock */
> +        bios_linker_loader_add_checksum(parent_ctx->linker,
> +            ACPI_BUILD_TABLE_FILE,
> +            parent_ctx->buf->data,
> +            start, child->buf->len, start + 9 /* checksum offset */);
> +
> +        /* set DefinitionBlock length at TableLength offset*/
> +        memcpy(child->buf->data + 4, &le32_len, sizeof le32_len);
> +        break;
> +    }
> +    default:
> +        break;
> +    }
> +    build_append_array(parent_ctx->buf, child->buf);
> +}
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 6d84f38..237080f 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
>  #define ACPI_BUILD_APPNAME6 "BOCHS "
>  #define ACPI_BUILD_APPNAME4 "BXPC"
>  
> -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
>  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
>  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
>  
> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> index 199f003..4033796 100644
> --- a/include/hw/acpi/aml-build.h
> +++ b/include/hw/acpi/aml-build.h
> @@ -5,6 +5,67 @@
>  #include <glib.h>
>  #include "qemu/compiler.h"
>  
> +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"

fw cfg stuff doesn't belong in aml generator.

> +
> +typedef enum {
> +    AML_HELPER = 0,
> +    AML_NON_BLOCK,

What are the above two?
The names aren't really helpful.

> +    AML_PACKAGE,
> +    AML_EXT_PACKAGE,
> +    AML_BUFFER,

And what's a buffer?

> +    AML_RES_TEMPLATE,
> +    AML_DEF_BLOCK,
> +} AmlBlockFlags;
> +
> +struct Aml {
> +    GArray *buf;
> +
> +    /*< private >*/
> +    uint8_t op;
> +    AmlBlockFlags block_flags;
> +    GArray *linker;
> +};
> +typedef struct Aml Aml;
> +
> +/**
> + * init_aml_allocator:
> + * @linker: linker that used by API for registering ACPI tables
> + *          with linker firmware interfac
> + *
> + * Called for initializing API allocator which allow to use
> + * AML API.
> + * Returns: toplevel container which accumulates all other
> + * ACPI tables.
> + */
> +Aml *init_aml_allocator(GArray *linker);
> +
> +/**
> + * free_aml_allocator:
> + *
> + * Releases all elements used by AML API, frees associated memory
> + * and invalidates AML allocator. After this call @init_aml_allocator
> + * should be called again if AML API is to be used again.
> + */
> +void free_aml_allocator(void);
> +
> +/**
> + * aml_append:
> + * @parent_ctx: context to which @child element is added
> + * @child: element that is copied into @parent_ctx context
> + *
> + * Joins Aml elements together and helps to construct AML tables
> + * Examle of usage:
> + *   Aml *table = aml_def_block("SSDT", ...);
> + *   Aml *sb = aml_scope("\_SB");
> + *   Aml *dev = aml_device("PCI0");
> + *
> + *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
> + *   aml_append(sb, dev);
> + *   aml_append(table, sb);
> + */
> +void aml_append(Aml *parent_ctx, Aml *child);
> +
> +/* other helpers */
>  GArray *build_alloc_array(void);
>  void build_free_array(GArray *array);
>  void build_prepend_byte(GArray *array, uint8_t val);
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()
  2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value() Igor Mammedov
@ 2015-02-17 19:53   ` Michael S. Tsirkin
  2015-02-18  9:41     ` Igor Mammedov
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-17 19:53 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Mon, Feb 09, 2015 at 10:53:26AM +0000, Igor Mammedov wrote:
> it will be reused for adding a plain integer value into AML.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  hw/acpi/aml-build.c  | 19 +++----------------
>  hw/i386/acpi-build.c |  6 +++---
>  2 files changed, 6 insertions(+), 19 deletions(-)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 096f347..67d1371 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)
>  
>  void build_append_value(GArray *table, uint32_t value, int size)
>  {
> -    uint8_t prefix;
>      int i;
>  
> -    switch (size) {
> -    case 1:
> -        prefix = 0x0A; /* BytePrefix */
> -        break;
> -    case 2:
> -        prefix = 0x0B; /* WordPrefix */
> -        break;
> -    case 4:
> -        prefix = 0x0C; /* DWordPrefix */
> -        break;
> -    default:
> -        assert(0);
> -        return;
> -    }
> -    build_append_byte(table, prefix);
>      for (i = 0; i < size; ++i) {
>          build_append_byte(table, value & 0xFF);
>          value = value >> 8;

This really makes this an awkward API,
you must remember to add the prefix.
IMO you want a new name - build_append_value_noprefix maybe -
then call build_append_value_noprefix from build_append_value.

But really, it's best to squash such changes with
where they are used, it's just making review harder:
as you add APIs with no documentation, I can't
see what they do without reading follow up patch
to see how they are used.


> @@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value)
>      } else if (value == 0x01) {
>          build_append_byte(table, 0x01); /* OneOp */
>      } else if (value <= 0xFF) {
> +        build_append_byte(table, 0x0A); /* BytePrefix */
>          build_append_value(table, value, 1);
>      } else if (value <= 0xFFFF) {
> +        build_append_byte(table, 0x0B); /* WordPrefix */
>          build_append_value(table, value, 2);
>      } else {
> +        build_append_byte(table, 0x0C); /* DWordPrefix */
>          build_append_value(table, value, 4);
>      }
>  }
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 788962e..a1bf450 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)
>  
>  static void build_append_notify_target_ifequal(GArray *method,
>                                                 GArray *target_name,
> -                                               uint32_t value, int size)
> +                                               uint32_t value)
>  {
>      GArray *notify = build_alloc_array();
>      uint8_t op = 0xA0; /* IfOp */
>  
>      build_append_byte(notify, 0x93); /* LEqualOp */
>      build_append_byte(notify, 0x68); /* Arg0Op */
> -    build_append_value(notify, value, size);
> +    build_append_int(notify, value);
>      build_append_byte(notify, 0x86); /* NotifyOp */
>      build_append_array(notify, target_name);
>      build_append_byte(notify, 0x69); /* Arg1Op */
> @@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,
>          GArray *target = build_alloc_array();
>          build_append_namestring(target, format, i);
>          assert(i < 256); /* Fits in 1 byte */
> -        build_append_notify_target_ifequal(method, target, i, 1);
> +        build_append_notify_target_ifequal(method, target, i);
>          build_free_array(target);
>      }
>  
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
  2015-02-17 19:46   ` Michael S. Tsirkin
@ 2015-02-18  8:50     ` Igor Mammedov
  0 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18  8:50 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 20:46:32 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:23AM +0000, Igor Mammedov wrote:
> > Adds for dynamic AML creation, which will be used
> > for piecing ASL/AML primitives together and hiding
> > from user/caller details about how nested context
> > should be closed/packed leaving less space for
> > mistakes and necessity to know how AML should be
> > encoded, allowing user to concentrate on ASL
> > representation instead.
> > 
> > For example it will allow to create AML like this:
> > 
> > init_aml_allocator();
> > ...
> > Aml *scope = aml_scope("PCI0")
> > Aml *dev = aml_device("PM")
> >     aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
> > aml_append(scope, dev);
> > ...
> > free_aml_allocator();
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> This should be split up, so we can see
> functionality added in the same patch where it's used.
> It's too hard to evaluate this alone.
I'll try to split it
> 
> 
> > ---
> >  hw/acpi/aml-build.c         | 91 +++++++++++++++++++++++++++++++++++++++++++++
> >  hw/i386/acpi-build.c        |  1 -
> >  include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++
> >  3 files changed, 152 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index bcb288e..096f347 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -25,6 +25,8 @@
> >  #include <stdbool.h>
> >  #include <string.h>
> >  #include "hw/acpi/aml-build.h"
> > +#include "qemu/bswap.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> >  
> >  GArray *build_alloc_array(void)
> >  {
> > @@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)
> >          build_append_value(table, value, 4);
> >      }
> >  }
> > +
> > +static GPtrArray *alloc_list;
> > +
> > +static Aml *aml_alloc(void)
> > +{
> > +    Aml *var = g_new0(typeof(*var), 1);
> > +
> > +    g_ptr_array_add(alloc_list, var);
> > +    var->block_flags = AML_HELPER;
> > +    var->buf = build_alloc_array();
> > +    return var;
> > +}
> > +
> > +static void aml_free(gpointer data)
> > +{
> > +    Aml *var = data;
> > +    build_free_array(var->buf);
> > +}
> > +
> > +Aml *init_aml_allocator(GArray *linker)
> > +{
> > +    Aml *var;
> > +
> > +    assert(!alloc_list);
> > +    alloc_list = g_ptr_array_new_with_free_func(aml_free);
> > +    var = aml_alloc();
> > +    var->linker = linker;
> > +    return var;
> > +}
> > +
> > +void free_aml_allocator(void)
> > +{
> > +    g_ptr_array_free(alloc_list, true);
> > +    alloc_list = 0;
> > +}
> > +
> > +static void build_buffer(GArray *array, uint8_t op)
> 
> What does this do?
that's block of code moved to helper you asked for in previous review
it finishes up AML buffer construction pretty much the same way as
build_package() does.

> 
> > +{
> > +    GArray *data = build_alloc_array();
> > +
> > +    build_append_int(data, array->len);
> > +    g_array_prepend_vals(array, data->data, data->len);
> 
> Prepend is best avoided. Can't say whether it's necessary
> here.
can't be helped, it does similar thing to as adding PkgLength

> 
> > +    build_free_array(data);
> > +    build_package(array, op);
> > +}
> > +
> > +void aml_append(Aml *parent_ctx, Aml *child)
> > +{
> > +    switch (child->block_flags) {
> > +    case AML_NON_BLOCK:
> > +        build_append_byte(parent_ctx->buf, child->op);
> > +        break;
> > +    case AML_EXT_PACKAGE:
> > +        build_extop_package(child->buf, child->op);
> > +        break;
> > +    case AML_PACKAGE:
> > +        build_package(child->buf, child->op);
> > +        break;
> > +    case AML_RES_TEMPLATE:
> > +        build_append_byte(child->buf, 0x79); /* EndTag */
> > +        /*
> > +         * checksum operations is treated as succeeded if checksum
> 
> are treated?
sure

> 
> > +         * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
> 
> Pls always quote oldest spec, not latest one.
> 
> 
> > +         */
> > +        build_append_byte(child->buf, 0);
> > +        /* fall through, to pack resources in buffer */
> > +    case AML_BUFFER:
> > +        build_buffer(child->buf, child->op);
> > +        break;
> > +    case AML_DEF_BLOCK: {
> > +        uint8_t *start = (uint8_t *)parent_ctx->buf->data +
> > +                         parent_ctx->buf->len;
> > +        uint32_t le32_len = cpu_to_le32(child->buf->len);
> > +
> > +        /* create linker entry for the DefinitionBlock */
> > +        bios_linker_loader_add_checksum(parent_ctx->linker,
> > +            ACPI_BUILD_TABLE_FILE,
> > +            parent_ctx->buf->data,
> > +            start, child->buf->len, start + 9 /* checksum offset */);
> > +
> > +        /* set DefinitionBlock length at TableLength offset*/
> > +        memcpy(child->buf->data + 4, &le32_len, sizeof le32_len);
> > +        break;
> > +    }
> > +    default:
> > +        break;
> > +    }
> > +    build_append_array(parent_ctx->buf, child->buf);
> > +}
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index 6d84f38..237080f 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> >  #define ACPI_BUILD_APPNAME6 "BOCHS "
> >  #define ACPI_BUILD_APPNAME4 "BXPC"
> >  
> > -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> >  
> > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > index 199f003..4033796 100644
> > --- a/include/hw/acpi/aml-build.h
> > +++ b/include/hw/acpi/aml-build.h
> > @@ -5,6 +5,67 @@
> >  #include <glib.h>
> >  #include "qemu/compiler.h"
> >  
> > +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> 
> fw cfg stuff doesn't belong in aml generator.
> 
> > +
> > +typedef enum {
> > +    AML_HELPER = 0,
> > +    AML_NON_BLOCK,
> 
> What are the above two?
> The names aren't really helpful.
AML_HELPER - to distinguish terms that do not need extra processing
and just need to be copied into parent context, which is mostly
only helpers like aml_callXX(), terms put in resource template, e.t.c.
allocated by aml_alloc()

AML_NON_BLOCK - is used for simple inline terms with 1 byte opcode
allocated by aml_opcode(opcode)

the rest of the flags are used for more complex structures
which are allocated with aml_bundle(opcode, flags)

I've thought we came to agreement when we discussed this.


> 
> > +    AML_PACKAGE,
> > +    AML_EXT_PACKAGE,
> > +    AML_BUFFER,
> 
> And what's a buffer?
DefBuffer := BufferOp PkgLength BufferSize ByteList

> 
> > +    AML_RES_TEMPLATE,
> > +    AML_DEF_BLOCK,
> > +} AmlBlockFlags;
> > +
> > +struct Aml {
> > +    GArray *buf;
> > +
> > +    /*< private >*/
> > +    uint8_t op;
> > +    AmlBlockFlags block_flags;
> > +    GArray *linker;
> > +};
> > +typedef struct Aml Aml;
> > +
> > +/**
> > + * init_aml_allocator:
> > + * @linker: linker that used by API for registering ACPI tables
> > + *          with linker firmware interfac
> > + *
> > + * Called for initializing API allocator which allow to use
> > + * AML API.
> > + * Returns: toplevel container which accumulates all other
> > + * ACPI tables.
> > + */
> > +Aml *init_aml_allocator(GArray *linker);
> > +
> > +/**
> > + * free_aml_allocator:
> > + *
> > + * Releases all elements used by AML API, frees associated memory
> > + * and invalidates AML allocator. After this call @init_aml_allocator
> > + * should be called again if AML API is to be used again.
> > + */
> > +void free_aml_allocator(void);
> > +
> > +/**
> > + * aml_append:
> > + * @parent_ctx: context to which @child element is added
> > + * @child: element that is copied into @parent_ctx context
> > + *
> > + * Joins Aml elements together and helps to construct AML tables
> > + * Examle of usage:
> > + *   Aml *table = aml_def_block("SSDT", ...);
> > + *   Aml *sb = aml_scope("\_SB");
> > + *   Aml *dev = aml_device("PCI0");
> > + *
> > + *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
> > + *   aml_append(sb, dev);
> > + *   aml_append(table, sb);
> > + */
> > +void aml_append(Aml *parent_ctx, Aml *child);
> > +
> > +/* other helpers */
> >  GArray *build_alloc_array(void);
> >  void build_free_array(GArray *array);
> >  void build_prepend_byte(GArray *array, uint8_t val);
> > -- 
> > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()
  2015-02-17 19:53   ` Michael S. Tsirkin
@ 2015-02-18  9:41     ` Igor Mammedov
  2015-02-18 13:51       ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18  9:41 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 20:53:52 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:26AM +0000, Igor Mammedov wrote:
> > it will be reused for adding a plain integer value into AML.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  hw/acpi/aml-build.c  | 19 +++----------------
> >  hw/i386/acpi-build.c |  6 +++---
> >  2 files changed, 6 insertions(+), 19 deletions(-)
> > 
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index 096f347..67d1371 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)
> >  
> >  void build_append_value(GArray *table, uint32_t value, int size)
> >  {
> > -    uint8_t prefix;
> >      int i;
> >  
> > -    switch (size) {
> > -    case 1:
> > -        prefix = 0x0A; /* BytePrefix */
> > -        break;
> > -    case 2:
> > -        prefix = 0x0B; /* WordPrefix */
> > -        break;
> > -    case 4:
> > -        prefix = 0x0C; /* DWordPrefix */
> > -        break;
> > -    default:
> > -        assert(0);
> > -        return;
> > -    }
> > -    build_append_byte(table, prefix);
> >      for (i = 0; i < size; ++i) {
> >          build_append_byte(table, value & 0xFF);
> >          value = value >> 8;
> 
> This really makes this an awkward API,
> you must remember to add the prefix.
it's internal helper for adding plain values,
it's not intended for using outside aml-build.c
I should have marked it as static.

[...]
> then call build_append_value_noprefix from build_append_value.
lets rename it to build_append_int_noprefix as int is less vague then value
and leave prefixed part as it's /i.e. build_append_int()/


> 
> But really, it's best to squash such changes with
> where they are used, it's just making review harder:
> as you add APIs with no documentation, I can't
> see what they do without reading follow up patch
> to see how they are used.
It's split out to make the rest of patches more review-able
if I drop aml_def_block() patch then this patch might be squashed with:
"acpi: extend build_append_{value|int}() to support 64-bit values"
"acpi: add aml_int() term"
and that might be squashed into already huge patch
"pc: acpi-build: drop template patching and create PCI bus tree dynamically"

Squashing 3 different changes into a bigger patch doesn't make review any
easier and squashing that into 4th conversion patch makes it even worse.

> 
> 
> > @@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value)
> >      } else if (value == 0x01) {
> >          build_append_byte(table, 0x01); /* OneOp */
> >      } else if (value <= 0xFF) {
> > +        build_append_byte(table, 0x0A); /* BytePrefix */
> >          build_append_value(table, value, 1);
> >      } else if (value <= 0xFFFF) {
> > +        build_append_byte(table, 0x0B); /* WordPrefix */
> >          build_append_value(table, value, 2);
> >      } else {
> > +        build_append_byte(table, 0x0C); /* DWordPrefix */
> >          build_append_value(table, value, 4);
> >      }
> >  }
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index 788962e..a1bf450 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)
> >  
> >  static void build_append_notify_target_ifequal(GArray *method,
> >                                                 GArray *target_name,
> > -                                               uint32_t value, int size)
> > +                                               uint32_t value)
> >  {
> >      GArray *notify = build_alloc_array();
> >      uint8_t op = 0xA0; /* IfOp */
> >  
> >      build_append_byte(notify, 0x93); /* LEqualOp */
> >      build_append_byte(notify, 0x68); /* Arg0Op */
> > -    build_append_value(notify, value, size);
> > +    build_append_int(notify, value);
> >      build_append_byte(notify, 0x86); /* NotifyOp */
> >      build_append_array(notify, target_name);
> >      build_append_byte(notify, 0x69); /* Arg1Op */
> > @@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,
> >          GArray *target = build_alloc_array();
> >          build_append_namestring(target, format, i);
> >          assert(i < 256); /* Fits in 1 byte */
> > -        build_append_notify_target_ifequal(method, target, i, 1);
> > +        build_append_notify_target_ifequal(method, target, i);
> >          build_free_array(target);
> >      }
> >  
> > -- 
> > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-17 19:15       ` Michael S. Tsirkin
@ 2015-02-18  9:50         ` Igor Mammedov
  2015-02-18 11:35           ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18  9:50 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 20:15:42 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, Feb 17, 2015 at 05:47:26PM +0100, Igor Mammedov wrote:
> > On Tue, 17 Feb 2015 17:35:55 +0100
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > 
> > > On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > ---
> > > >  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
> > > >  hw/i386/acpi-build.c        |  4 ----
> > > >  include/hw/acpi/aml-build.h | 10 ++++++++++
> > > >  3 files changed, 48 insertions(+), 4 deletions(-)
> > > > 
> > > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > > index 67d1371..cb1a1bd 100644
> > > > --- a/hw/acpi/aml-build.c
> > > > +++ b/hw/acpi/aml-build.c
> > > > @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
> > > >      }
> > > >      build_append_array(parent_ctx->buf, child->buf);
> > > >  }
> > > > +
> > > > +/*
> > > > + * ACPI 1.0b: 16.2.1 Top Level AML
> > > > + *            5.2.3 System Description Table Header
> > > > + *
> > > > + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> > > > + */
> > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > +                   const char *oem_id, const char *oem_table_id,
> > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > +                   uint32_t creator_revision)
> > > > +{
> > > > +    int len;
> > > > +    Aml *var = aml_alloc();
> > > > +    var->block_flags = AML_DEF_BLOCK;
> > > > +
> > > > +    assert(strlen(signature) == 4);
> > > > +    g_array_append_vals(var->buf, signature, 4);
> > > > +    build_append_value(var->buf, 0, 4); /* Length place holder */
> > > > +    build_append_byte(var->buf, revision);
> > > > +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> > > > +
> > > > +    len = strlen(oem_id);
> > > > +    assert(len <= 6);
> > > > +    g_array_append_vals(var->buf, oem_id, len);
> > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> > > > +
> > > > +    len = strlen(oem_table_id);
> > > > +    assert(len <= 8);
> > > > +    g_array_append_vals(var->buf, oem_table_id, len);
> > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> > > > +
> > > > +    build_append_value(var->buf, oem_revision, 4);
> > > > +    build_append_value(var->buf, creator_id, 4);
> > > > +    build_append_value(var->buf, creator_revision, 4);
> > > > +
> > > > +    return var;
> > > 
> > > 
> > > Please don't do this.
> > > First, this is not a definition block encoding, so name
> > > is wrong.
> > > 
> > > Second, we already have functions to fill in headers.
> > > So just call them.
> > > 
> > > Filling structures byte by byte is unreadable -
> > > I know ACPI spec often makes us do this but
> > > when it doesn't, we should not do it.
> > it does, in ACPI 5.1,
> > 
> > 20.2.1 Table and Table Header Encoding
> > AMLCode := DefBlockHeader TermList
> > DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID
> > OemTableID OemRevision CreatorID CreatorRevision
> 
> So spec explains it very badly, but these all are
> fixed width fields.
> Filling them in using add_byte just makes for hard to
> read code.
If it were only add_byte, I'd agree but it basically composes
by whole fields and in this particular case is easy to
verify just by looking to spec, just like the rest of AML
terms does.

And one doesn't have to care about endianness because
build_append_value() packs integer fields as expected
by spec as opposed to using C struct-s.

> 
> > > 
> > > Pls keep using build_header for now.
> > > 
> > > 
> > > > +}
> > > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > > index a1bf450..553c86b 100644
> > > > --- a/hw/i386/acpi-build.c
> > > > +++ b/hw/i386/acpi-build.c
> > > > @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> > > >                                              NULL);
> > > >  }
> > > >  
> > > > -#define ACPI_BUILD_APPNAME  "Bochs"
> > > > -#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > -#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > -
> > > >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> > > >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> > > >  
> > > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > > > index 4033796..2610336 100644
> > > > --- a/include/hw/acpi/aml-build.h
> > > > +++ b/include/hw/acpi/aml-build.h
> > > > @@ -6,6 +6,10 @@
> > > >  #include "qemu/compiler.h"
> > > >  
> > > >  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > > > +#define ACPI_BUILD_APPNAME  "Bochs"
> > > > +#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > +#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
> > > >  
> > > >  typedef enum {
> > > >      AML_HELPER = 0,
> > > > @@ -65,6 +69,12 @@ void free_aml_allocator(void);
> > > >   */
> > > >  void aml_append(Aml *parent_ctx, Aml *child);
> > > >  
> > > > +/* Block AML object primitives */
> > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > +                   const char *oem_id, const char *oem_table_id,
> > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > +                   uint32_t creator_revision);
> > > > +
> > > >  /* other helpers */
> > > >  GArray *build_alloc_array(void);
> > > >  void build_free_array(GArray *array);
> > > > -- 
> > > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table
  2015-02-17 16:42   ` Michael S. Tsirkin
@ 2015-02-18  9:57     ` Igor Mammedov
  2015-02-18 11:39       ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18  9:57 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 17:42:00 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:28AM +0000, Igor Mammedov wrote:
> > it replaces prebuilt SSDT table header template copying/patching
> > with AML API
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> I note that this changed the SSDT signature in random ways,
> for example, it used to be named BXPCSSDT, now it's BXPC.
> 
> Pls keep using build_header, this problem will go away then.
[...]
> > +    /* Init SSDT Definition Block */
> > +    ssdt = aml_def_block("SSDT", 1, ACPI_BUILD_APPNAME6,
> > +                         ACPI_BUILD_APPNAME4, 1,
I've missed that build_header() composes oem_table_id implicitly
by merging table signature and ACPI_BUILD_APPNAME4.

following should fix issue:
-                         ACPI_BUILD_APPNAME4, 1,
+                         "BXPCSSDT", 1,

> > +                         ACPI_BUILD_APPNAME4_HEX, 1);

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

* Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
  2015-02-17 19:39   ` Michael S. Tsirkin
@ 2015-02-18 10:00     ` Igor Mammedov
  2015-02-18 10:42     ` Igor Mammedov
  1 sibling, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18 10:00 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 20:39:03 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:43AM +0000, Igor Mammedov wrote:
> > Replace AML template patching with direct composing
> > of PCI device entries in C. It allows to simplify
> > PCI tree generation further and saves us about 400LOC
> > scattered through different files, confining tree
> > generation to one C function which is much easier
> > to deal with.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> Some comments below, this looks nice.
> 
> However, something strange is going on.
> This looks like it should produce identical
> code to what was there, but in fact your previous
> patch pc: acpi-build: simplify PCI bus tree generation
> changes SSDT, then this patch changes it back to
> what it was.
> 
> I'm confused by this.  Can't refactoring be done without changing the
> output back and forth, somehow?
Probably can, I'll check if it's feasible.

> 
> > ---
> >  hw/i386/Makefile.objs            |   6 +-
> >  hw/i386/acpi-build.c             | 207 +++++++++++---------------------
> >  hw/i386/ssdt-pcihp.dsl           | 100 ----------------
> >  hw/i386/ssdt-pcihp.hex.generated | 251 ---------------------------------------
> >  4 files changed, 72 insertions(+), 492 deletions(-)
> >  delete mode 100644 hw/i386/ssdt-pcihp.dsl
> >  delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
> > 
> > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> > index 2b678ef..4509cd1 100644
> > --- a/hw/i386/Makefile.objs
> > +++ b/hw/i386/Makefile.objs
> > @@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
> >  obj-y += kvmvapic.o
> >  obj-y += acpi-build.o
> >  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> > -	hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
> > -	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
> > -	hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \
> > -	hw/i386/ssdt-tpm.hex
> > +	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> > +	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
> >  
> >  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
> >      ; then echo "$(2)"; else echo "$(3)"; fi ;)
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index bdc343f..b6626f5 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)
> >  #define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
> >  #define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
> >  
> > -/* 0x5B 0x82 DeviceOp PkgLength NameString */
> > -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
> > -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
> > -
> > -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
> > -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
> > -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
> > -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
> > -
> > -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
> > -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
> > -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
> > -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
> > -
> > -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
> > -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
> > -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
> > -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
> > -
> >  #include "hw/i386/ssdt-mem.hex"
> >  
> >  /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
> > @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)
> >  #define ACPI_SSDT_HEADER_LENGTH 36
> >  
> >  #include "hw/i386/ssdt-misc.hex"
> > -#include "hw/i386/ssdt-pcihp.hex"
> >  #include "hw/i386/ssdt-tpm.hex"
> >  
> >  static void
> > @@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,
> >      build_append_and_cleanup_method(device, method);
> >  }
> >  
> > -static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
> > -}
> > -
> > -static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
> > -}
> > -
> > -static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
> > -}
> > -
> > -static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
> > -}
> > -
> >  /* Assign BSEL property to all buses.  In the future, this can be changed
> >   * to only assign to buses that support hotplug.
> >   */
> > @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void)
> >      }
> >  }
> >  
> > -static void build_append_pcihp_notify_entry(GArray *method, int slot)
> > +static void build_append_pcihp_notify_entry(Aml *method, int slot)
> >  {
> > -    GArray *ifctx;
> > +    Aml *if_ctx;
> > +    int32_t devfn = PCI_DEVFN(slot, 0);
> >  
> > -    ifctx = build_alloc_array();
> > -    build_append_byte(ifctx, 0x7B); /* AndOp */
> > -    build_append_byte(ifctx, 0x68); /* Arg0Op */
> > -    build_append_int(ifctx, 0x1U << slot);
> > -    build_append_byte(ifctx, 0x00); /* NullName */
> > -    build_append_byte(ifctx, 0x86); /* NotifyOp */
> > -    build_append_namestring(ifctx, "S%.02X", PCI_DEVFN(slot, 0));
> > -    build_append_byte(ifctx, 0x69); /* Arg1Op */
> > -
> > -    /* Pack it up */
> > -    build_package(ifctx, 0xA0 /* IfOp */);
> > -    build_append_array(method, ifctx);
> > -    build_free_array(ifctx);
> > +    if_ctx = aml_if(aml_and(aml_arg(0), aml_int(0x1U << slot)));
> > +    aml_append(if_ctx, aml_notify(aml_name("S%.02X", devfn), aml_arg(1)));
> > +    aml_append(method, if_ctx);
> >  }
> >  
> > -static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> > +static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
> >                                           bool pcihp_bridge_en)
> >  {
> > -    GArray *bus_table = build_alloc_array();
> > -    GArray *method = NULL;
> > +    Aml *dev, *notify_method, *method;
> >      QObject *bsel;
> >      PCIBus *sec;
> >      int i;
> >  
> > -    if (bus->parent_dev) {
> > -        build_append_namestring(bus_table, "S%.02X_", bus->parent_dev->devfn);
> > -    } else {
> > -        build_append_namestring(bus_table, "PCI0");
> > -    }
> > -
> >      bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
> >      if (bsel) {
> > -        build_append_byte(bus_table, 0x08); /* NameOp */
> > -        build_append_namestring(bus_table, "BSEL");
> > -        build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
> > -        method = build_alloc_method("DVNT", 2);
> > +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> > +
> > +        aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val)));
> > +        notify_method = aml_method("DVNT", 2);
> >      }
> >  
> >      for (i = 0; i < ARRAY_SIZE(bus->devices); i += PCI_FUNC_MAX) {
> > @@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> >  
> >          if (!pdev) {
> >              if (bsel) {
> > -                void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> > -                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> > -                patch_pcihp(slot, pcihp);
> > -
> > -                build_append_pcihp_notify_entry(method, slot);
> > +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > +                aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> > +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > +                method = aml_method("_EJ0", 1);
> > +                aml_append(method,
> > +                    aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> > +                );
> > +                aml_append(dev, method);
> > +                aml_append(parent_scope, dev);
> > +
> > +                build_append_pcihp_notify_entry(notify_method, slot);
> >              } else {
> > -                void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> > -                memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> > -                patch_pcinohp(slot, pcihp);
> > +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > +                aml_append(parent_scope, dev);
> >              }
> >              continue;
> >          }
> > @@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> >          bridge_in_acpi = pc->is_bridge && pcihp_bridge_en &&
> >              !DEVICE(pdev)->hotplugged;
> >  
> > +        dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > +        aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > +
> >          if (pc->class_id == PCI_CLASS_DISPLAY_VGA) {
> > +            int s3d = 0;
> >  
> >              if (object_dynamic_cast(OBJECT(pdev), "qxl-vga")) {
> > -                void *pcihp = acpi_data_push(bus_table,
> > -                                             ACPI_PCIQXL_SIZEOF);
> > -                      memcpy(pcihp, ACPI_PCIQXL_AML, ACPI_PCIQXL_SIZEOF);
> > -                      patch_pciqxl(slot, pcihp);
> > -            } else {
> > -                void *pcihp = acpi_data_push(bus_table,
> > -                                             ACPI_PCIVGA_SIZEOF);
> > -                memcpy(pcihp, ACPI_PCIVGA_AML, ACPI_PCIVGA_SIZEOF);
> > -                patch_pcivga(slot, pcihp);
> > +                s3d = 3;
> >              }
> 
> I dislike this style, where 0 is set, then over-written.
> Please do
>     if (cond) {
>         s = 3;
>     } else {
>         s = 0;
>     }
sure

> 
> 
> > +
> > +            method = aml_method("_S1D", 0);
> > +            aml_append(method, aml_return(aml_int(0)));
> > +            aml_append(dev, method);
> > +
> > +            method = aml_method("_S2D", 0);
> > +            aml_append(method, aml_return(aml_int(0)));
> > +            aml_append(dev, method);
> > +
> > +            method = aml_method("_S3D", 0);
> > +            aml_append(method, aml_return(aml_int(s3d)));
> > +            aml_append(dev, method);
> >          } else if (dc->hotpluggable && !bridge_in_acpi) {
> > -            void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> > -            memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> > -            patch_pcihp(slot, pcihp);
> > +            aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> > +
> > +            method = aml_method("_EJ0", 1);
> > +            aml_append(method,
> > +                aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> > +            );
> > +            aml_append(dev, method);
> >  
> >              if (bsel) {
> > -                build_append_pcihp_notify_entry(method, slot);
> > +                build_append_pcihp_notify_entry(notify_method, slot);
> >              }
> >          } else {
> > -            void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> > -            memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> > -            patch_pcinohp(slot, pcihp);
> > -
> >              /* When hotplug for bridges is enabled, bridges that are
> >               * described in ACPI separately aren't themselves hot-pluggable.
> >               * Hotplugged bridges *are* hot-pluggable.
> > @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> >              if (bridge_in_acpi) {
> >                  PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
> >  
> > -                build_append_pci_bus_devices(bus_table, sec_bus,
> > -                                             pcihp_bridge_en);
> > +                build_append_pci_bus_devices(dev, sec_bus, pcihp_bridge_en);
> >              }
> >          }
> > +        aml_append(parent_scope, dev);
> >      }
> >  
> >      if (bsel) {
> > -        build_append_and_cleanup_method(bus_table, method);
> > +        aml_append(parent_scope, notify_method);
> >      }
> >  
> >      /* Append PCNT method to notify about events on local and child buses.
> >       * Add unconditionally for root since DSDT expects it.
> >       */
> > -    method = build_alloc_method("PCNT", 0);
> > +    method = aml_method("PCNT", 0);
> >  
> >      /* If bus supports hotplug select it and notify about local events */
> >      if (bsel) {
> > -        build_append_byte(method, 0x70); /* StoreOp */
> > -        build_append_int(method, qint_get_int(qobject_to_qint(bsel)));
> > -        build_append_namestring(method, "BNUM");
> > -        build_append_namestring(method, "DVNT");
> > -        build_append_namestring(method, "PCIU");
> > -        build_append_int(method, 1); /* Device Check */
> > -        build_append_namestring(method, "DVNT");
> > -        build_append_namestring(method, "PCID");
> > -        build_append_int(method, 3); /* Eject Request */
> > +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> > +        aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
> > +        aml_append(method,
> > +            aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check */)
> > +        );
> > +        aml_append(method,
> > +            aml_call2("DVNT", aml_name("PCID"), aml_int(3)/* Eject Request */)
> > +        );
> >      }
> >  
> >      /* Notify about child bus events in any case */
> >      if (pcihp_bridge_en) {
> >          QLIST_FOREACH(sec, &bus->child, sibling) {
> > -            build_append_namestring(method, "^S%.02X.PCNT",
> > -                                    sec->parent_dev->devfn);
> > +            int32_t devfn = sec->parent_dev->devfn;
> > +
> > +            aml_append(method, aml_name("^S%.02X.PCNT", devfn));
> >          }
> >      }
> > -
> > -    build_append_and_cleanup_method(bus_table, method);
> > -
> > -    build_package(bus_table, 0x10); /* ScopeOp */
> > -    build_append_array(parent_scope, bus_table);
> > -    build_free_array(bus_table);
> > +    aml_append(parent_scope, method);
> >  }
> >  
> >  static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
> > @@ -943,9 +875,10 @@ build_ssdt(Aml *table_data,
> >              }
> >  
> >              if (bus) {
> > +                Aml *scope = aml_scope("PCI0");
> >                  /* Scan all PCI buses. Generate tables to support hotplug. */
> > -                build_append_pci_bus_devices(sb_scope->buf, bus,
> > -                                             pm->pcihp_bridge_en);
> > +                build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en);
> > +                aml_append(sb_scope, scope);
> >              }
> >          }
> >          aml_append(ssdt, sb_scope);
> > diff --git a/hw/i386/ssdt-pcihp.dsl b/hw/i386/ssdt-pcihp.dsl
> > deleted file mode 100644
> > index ac91c05..0000000
> > --- a/hw/i386/ssdt-pcihp.dsl
> > +++ /dev/null
> > @@ -1,100 +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/>.
> > - */
> > -
> > -ACPI_EXTRACT_ALL_CODE ssdp_pcihp_aml
> > -
> > -DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
> > -{
> > -
> > -/****************************************************************
> > - * PCI hotplug
> > - ****************************************************************/
> > -
> > -    /* Objects supplied by DSDT */
> > -    External(\_SB.PCI0, DeviceObj)
> > -    External(\_SB.PCI0.PCEJ, MethodObj)
> > -    External(BSEL, IntObj)
> > -
> > -    Scope(\_SB.PCI0) {
> > -
> > -        /* Bulk generated PCI hotplug devices */
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pcihp_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pcihp_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcihp_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SAA) {
> > -            ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcihp_id
> > -            Name(_SUN, 0xAA)
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcihp_adr
> > -            Name(_ADR, 0xAA0000)
> > -            Method(_EJ0, 1) {
> > -                PCEJ(BSEL, _SUN)
> > -            }
> > -        }
> > -
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pcinohp_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pcinohp_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcinohp_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SBB) {
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcinohp_adr
> > -            Name(_ADR, 0xAA0000)
> > -        }
> > -
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pcivga_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pcivga_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcivga_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SCC) {
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcivga_adr
> > -            Name(_ADR, 0xAA0000)
> > -            Method(_S1D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S2D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S3D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -        }
> > -
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pciqxl_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pciqxl_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pciqxl_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SDD) {
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pciqxl_adr
> > -            Name(_ADR, 0xAA0000)
> > -            Method(_S1D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S2D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S3D, 0, NotSerialized) {
> > -                Return (0x03)           // QXL
> > -            }
> > -        }
> > -    }
> > -}
> > diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
> > deleted file mode 100644
> > index 72ffa84..0000000
> > --- a/hw/i386/ssdt-pcihp.hex.generated
> 
> Pls don't send generated file patches.
> Just note it should be removed in comment, I'll do it.
> 
> > +++ /dev/null
> > @@ -1,251 +0,0 @@
> > -static unsigned char ssdt_pcihp_name[] = {
> > -0x34
> > -};
> > -static unsigned char ssdt_pcivga_end[] = {
> > -0x99
> > -};
> > -static unsigned char ssdt_pcivga_name[] = {
> > -0x70
> > -};
> > -static unsigned char ssdt_pcihp_adr[] = {
> > -0x45
> > -};
> > -static unsigned char ssdt_pcinohp_end[] = {
> > -0x6d
> > -};
> > -static unsigned char ssdt_pcihp_end[] = {
> > -0x5c
> > -};
> > -static unsigned char ssdt_pciqxl_start[] = {
> > -0x99
> > -};
> > -static unsigned char ssdt_pcinohp_name[] = {
> > -0x5f
> > -};
> > -static unsigned char ssdp_pcihp_aml[] = {
> > -0x53,
> > -0x53,
> > -0x44,
> > -0x54,
> > -0xc6,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x1,
> > -0x70,
> > -0x42,
> > -0x58,
> > -0x50,
> > -0x43,
> > -0x0,
> > -0x0,
> > -0x42,
> > -0x58,
> > -0x53,
> > -0x53,
> > -0x44,
> > -0x54,
> > -0x50,
> > -0x43,
> > -0x1,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x49,
> > -0x4e,
> > -0x54,
> > -0x4c,
> > -0x15,
> > -0x11,
> > -0x13,
> > -0x20,
> > -0x10,
> > -0x41,
> > -0xa,
> > -0x5c,
> > -0x2e,
> > -0x5f,
> > -0x53,
> > -0x42,
> > -0x5f,
> > -0x50,
> > -0x43,
> > -0x49,
> > -0x30,
> > -0x5b,
> > -0x82,
> > -0x29,
> > -0x53,
> > -0x41,
> > -0x41,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x55,
> > -0x4e,
> > -0xa,
> > -0xaa,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x14,
> > -0x12,
> > -0x5f,
> > -0x45,
> > -0x4a,
> > -0x30,
> > -0x1,
> > -0x50,
> > -0x43,
> > -0x45,
> > -0x4a,
> > -0x42,
> > -0x53,
> > -0x45,
> > -0x4c,
> > -0x5f,
> > -0x53,
> > -0x55,
> > -0x4e,
> > -0x5b,
> > -0x82,
> > -0xf,
> > -0x53,
> > -0x42,
> > -0x42,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x5b,
> > -0x82,
> > -0x2a,
> > -0x53,
> > -0x43,
> > -0x43,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x31,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x32,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x33,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x5b,
> > -0x82,
> > -0x2b,
> > -0x53,
> > -0x44,
> > -0x44,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x31,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x32,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x9,
> > -0x5f,
> > -0x53,
> > -0x33,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0xa,
> > -0x3
> > -};
> > -static unsigned char ssdt_pciqxl_adr[] = {
> > -0xa6
> > -};
> > -static unsigned char ssdt_pcinohp_adr[] = {
> > -0x69
> > -};
> > -static unsigned char ssdt_pcivga_adr[] = {
> > -0x7a
> > -};
> > -static unsigned char ssdt_pciqxl_name[] = {
> > -0x9c
> > -};
> > -static unsigned char ssdt_pcivga_start[] = {
> > -0x6d
> > -};
> > -static unsigned char ssdt_pciqxl_end[] = {
> > -0xc6
> > -};
> > -static unsigned char ssdt_pcihp_start[] = {
> > -0x31
> > -};
> > -static unsigned char ssdt_pcihp_id[] = {
> > -0x3e
> > -};
> > -static unsigned char ssdt_pcinohp_start[] = {
> > -0x5c
> > -};
> > -- 
> > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  2015-02-17 16:41   ` Michael S. Tsirkin
@ 2015-02-18 10:03     ` Igor Mammedov
  2015-02-18 12:41       ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18 10:03 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 17:41:03 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:45AM +0000, Igor Mammedov wrote:
> > QEMU doesn't implement/advertize PM1b_CNT_BLK
> > register block so do not set/patch its \_Sx
> > values to avoid confusion.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> I doubt guests are confused.
They just happen to ignore it, it doesn't mean that it's correct

> I think you mean this confuses you, but I'd rather stay
> bug for bug compatible with what we did historically.
> We probably should add a comment saying this is here
> for historical reasons, but let's get your patchset
> merged first, it's too big as is.
I don't see point in being bug compatible in this case.

> 
> 
> > ---
> >  hw/i386/acpi-build.c  | 3 +--
> >  hw/i386/ssdt-misc.dsl | 4 ++--
> >  2 files changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index b6626f5..7cc564a 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,
> >      if (pm->s4_disabled) {
> >          ssdt_ptr[acpi_s4_name[0]] = 'X';
> >      } else {
> > -        ssdt_ptr[acpi_s4_pkg[0] + 1] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
> > -            pm->s4_val;
> > +        ssdt_ptr[acpi_s4_pkg[0] + 1] = pm->s4_val;
> >      }
> >  
> >      patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
> > diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> > index 1e3baae..96382a6 100644
> > --- a/hw/i386/ssdt-misc.dsl
> > +++ b/hw/i386/ssdt-misc.dsl
> > @@ -54,7 +54,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
> >          ACPI_EXTRACT_NAME_STRING acpi_s3_name
> >          Name(_S3, Package(0x04) {
> >              One,  /* PM1a_CNT.SLP_TYP */
> > -            One,  /* PM1b_CNT.SLP_TYP */
> > +            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
> >              Zero,  /* reserved */
> >              Zero   /* reserved */
> >          })
> > @@ -62,7 +62,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
> >          ACPI_EXTRACT_PKG_START acpi_s4_pkg
> >          Name(_S4, Package(0x04) {
> >              0x2,  /* PM1a_CNT.SLP_TYP */
> > -            0x2,  /* PM1b_CNT.SLP_TYP */
> > +            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
> >              Zero,  /* reserved */
> >              Zero   /* reserved */
> >          })
> > -- 
> > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
  2015-02-17 16:44   ` Michael S. Tsirkin
@ 2015-02-18 10:09     ` Igor Mammedov
  2015-02-18 13:13       ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18 10:09 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 17:44:31 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:54:09AM +0000, Igor Mammedov wrote:
> > It completes dynamic SSDT generation and makes it
> > independed of IASL binary blobs. It also hides
> > from user all pointer arithmetic when building
> > SSDT which makes resulting code a bit cleaner
> > and concentrating only on composing ASL construct
> > /i.e. a task build_ssdt() should be doing/.
> > 
> > Also it makes one binary blob less stored in QEMU
> > source tree by removing need to keep and update
> > hw/i386/ssdt-misc.hex.generated file here in total
> > saving us ~430LOC.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> 
> I see where we drop ssdt_misc here but I don't see
> acpi_def_block anywhere.
that's been introduced when conversion began in patch:
[6/52] pc: acpi-build: use aml_def_block() for declaring SSDT table"

 
> Also pls don't include generated files in patches,
> they just make rebases painful.
> just say in commit log they need to be updated.
sure

> 
> > ---
> >  hw/i386/Makefile.objs           |   2 +-
> >  hw/i386/acpi-build.c            |  12 --
> >  hw/i386/ssdt-misc.dsl           |  21 ---
> >  hw/i386/ssdt-misc.hex.generated | 399 ----------------------------------------
> >  4 files changed, 1 insertion(+), 433 deletions(-)
> >  delete mode 100644 hw/i386/ssdt-misc.dsl
> >  delete mode 100644 hw/i386/ssdt-misc.hex.generated
> > 
> > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> > index 6c8705d..dc8c38a 100644
> > --- a/hw/i386/Makefile.objs
> > +++ b/hw/i386/Makefile.objs
> > @@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
> >  obj-y += kvmvapic.o
> >  obj-y += acpi-build.o
> >  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> > -	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> > +	hw/i386/q35-acpi-dsdt.hex \
> >  	hw/i386/ssdt-tpm.hex
> >  
> >  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index bead77e..14c1c7d 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
> >                   table_data->len - madt_start, 1);
> >  }
> >  
> > -#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
> > -#define ACPI_SSDT_HEADER_LENGTH 36
> > -
> > -#include "hw/i386/ssdt-misc.hex"
> >  #include "hw/i386/ssdt-tpm.hex"
> >  
> >  /* Assign BSEL property to all buses.  In the future, this can be changed
> > @@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,
> >      MachineState *machine = MACHINE(qdev_get_machine());
> >      uint32_t nr_mem = machine->ram_slots;
> >      unsigned acpi_cpus = guest_info->apic_id_limit;
> > -    uint8_t *ssdt_ptr;
> >      Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
> >      int i;
> >  
> > @@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,
> >                           ACPI_BUILD_APPNAME4, 1,
> >                           ACPI_BUILD_APPNAME4_HEX, 1);
> >  
> > -    /* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
> > -    acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
> > -    ssdt_ptr = (uint8_t *)ssdt->buf->data;
> > -    memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
> > -           ssdp_misc_aml + sizeof(AcpiTableHeader),
> > -           sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
> > -
> >      scope = aml_scope("\\_SB.PCI0");
> >      /* build PCI0._CRS */
> >      crs = aml_resource_template();
> 
> So before this patch, we had two headers?
> I don't see how this makes sense, and it does not
> match commit log.
nope, see
[6/52] pc: acpi-build: use aml_def_block() for declaring SSDT table"
where header from template is skipped and only content is copied

> 
> 
> > diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> > deleted file mode 100644
> > index 8d61f21..0000000
> > --- a/hw/i386/ssdt-misc.dsl
> > +++ /dev/null
> > @@ -1,21 +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 "hw/acpi/pc-hotplug.h"
> > -
> > -ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
> > -
> > -DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
> > -{
> > -}
> > diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
> > deleted file mode 100644
> > index cbcf61d..0000000
> > --- a/hw/i386/ssdt-misc.hex.generated
> > +++ /dev/null
> > @@ -1,399 +0,0 @@
> > -static unsigned char acpi_pci64_length[] = {
> > -0x6f
> > -};
> > -static unsigned char acpi_s4_pkg[] = {
> > -0x99
> > -};
> > -static unsigned char ssdt_mctrl_nr_slots[] = {
> > -0x7d
> > -};
> > -static unsigned char acpi_s3_name[] = {
> > -0x86
> > -};
> > -static unsigned char acpi_pci32_start[] = {
> > -0x2f
> > -};
> > -static unsigned char acpi_pci64_valid[] = {
> > -0x43
> > -};
> > -static unsigned char ssdp_misc_aml[] = {
> > -0x53,
> > -0x53,
> > -0x44,
> > -0x54,
> > -0x6c,
> > -0x1,
> > -0x0,
> > -0x0,
> > -0x1,
> > -0x3,
> > -0x42,
> > -0x58,
> > -0x50,
> > -0x43,
> > -0x0,
> > -0x0,
> > -0x42,
> > -0x58,
> > -0x53,
> > -0x53,
> > -0x44,
> > -0x54,
> > -0x53,
> > -0x55,
> > -0x1,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x49,
> > -0x4e,
> > -0x54,
> > -0x4c,
> > -0x28,
> > -0x8,
> > -0x14,
> > -0x20,
> > -0x10,
> > -0x4c,
> > -0x5,
> > -0x5c,
> > -0x0,
> > -0x8,
> > -0x50,
> > -0x30,
> > -0x53,
> > -0x5f,
> > -0xc,
> > -0x78,
> > -0x56,
> > -0x34,
> > -0x12,
> > -0x8,
> > -0x50,
> > -0x30,
> > -0x45,
> > -0x5f,
> > -0xc,
> > -0x78,
> > -0x56,
> > -0x34,
> > -0x12,
> > -0x8,
> > -0x50,
> > -0x31,
> > -0x56,
> > -0x5f,
> > -0xa,
> > -0x12,
> > -0x8,
> > -0x50,
> > -0x31,
> > -0x53,
> > -0x5f,
> > -0x11,
> > -0xb,
> > -0xa,
> > -0x8,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x8,
> > -0x50,
> > -0x31,
> > -0x45,
> > -0x5f,
> > -0x11,
> > -0xb,
> > -0xa,
> > -0x8,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x8,
> > -0x50,
> > -0x31,
> > -0x4c,
> > -0x5f,
> > -0x11,
> > -0xb,
> > -0xa,
> > -0x8,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x8,
> > -0x4d,
> > -0x44,
> > -0x4e,
> > -0x52,
> > -0xc,
> > -0x78,
> > -0x56,
> > -0x34,
> > -0x12,
> > -0x10,
> > -0x29,
> > -0x5c,
> > -0x0,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x33,
> > -0x5f,
> > -0x12,
> > -0x6,
> > -0x4,
> > -0x1,
> > -0x1,
> > -0x0,
> > -0x0,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x34,
> > -0x5f,
> > -0x12,
> > -0x8,
> > -0x4,
> > -0xa,
> > -0x2,
> > -0xa,
> > -0x2,
> > -0x0,
> > -0x0,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x35,
> > -0x5f,
> > -0x12,
> > -0x6,
> > -0x4,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x10,
> > -0x40,
> > -0xc,
> > -0x5c,
> > -0x2f,
> > -0x3,
> > -0x5f,
> > -0x53,
> > -0x42,
> > -0x5f,
> > -0x50,
> > -0x43,
> > -0x49,
> > -0x30,
> > -0x49,
> > -0x53,
> > -0x41,
> > -0x5f,
> > -0x5b,
> > -0x82,
> > -0x4d,
> > -0xa,
> > -0x50,
> > -0x45,
> > -0x56,
> > -0x54,
> > -0x8,
> > -0x5f,
> > -0x48,
> > -0x49,
> > -0x44,
> > -0xd,
> > -0x51,
> > -0x45,
> > -0x4d,
> > -0x55,
> > -0x30,
> > -0x30,
> > -0x30,
> > -0x31,
> > -0x0,
> > -0x8,
> > -0x50,
> > -0x45,
> > -0x53,
> > -0x54,
> > -0xb,
> > -0xff,
> > -0xff,
> > -0x5b,
> > -0x80,
> > -0x50,
> > -0x45,
> > -0x4f,
> > -0x52,
> > -0x1,
> > -0x50,
> > -0x45,
> > -0x53,
> > -0x54,
> > -0x1,
> > -0x5b,
> > -0x81,
> > -0xb,
> > -0x50,
> > -0x45,
> > -0x4f,
> > -0x52,
> > -0x1,
> > -0x50,
> > -0x45,
> > -0x50,
> > -0x54,
> > -0x8,
> > -0x14,
> > -0x18,
> > -0x5f,
> > -0x53,
> > -0x54,
> > -0x41,
> > -0x0,
> > -0x70,
> > -0x50,
> > -0x45,
> > -0x53,
> > -0x54,
> > -0x60,
> > -0xa0,
> > -0x6,
> > -0x93,
> > -0x60,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0xa1,
> > -0x4,
> > -0xa4,
> > -0xa,
> > -0xf,
> > -0x14,
> > -0xe,
> > -0x52,
> > -0x44,
> > -0x50,
> > -0x54,
> > -0x0,
> > -0x70,
> > -0x50,
> > -0x45,
> > -0x50,
> > -0x54,
> > -0x60,
> > -0xa4,
> > -0x60,
> > -0x14,
> > -0xc,
> > -0x57,
> > -0x52,
> > -0x50,
> > -0x54,
> > -0x1,
> > -0x70,
> > -0x68,
> > -0x50,
> > -0x45,
> > -0x50,
> > -0x54,
> > -0x8,
> > -0x5f,
> > -0x43,
> > -0x52,
> > -0x53,
> > -0x11,
> > -0xd,
> > -0xa,
> > -0xa,
> > -0x47,
> > -0x1,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x1,
> > -0x1,
> > -0x79,
> > -0x0,
> > -0x8b,
> > -0x5f,
> > -0x43,
> > -0x52,
> > -0x53,
> > -0xa,
> > -0x2,
> > -0x49,
> > -0x4f,
> > -0x4d,
> > -0x4e,
> > -0x8b,
> > -0x5f,
> > -0x43,
> > -0x52,
> > -0x53,
> > -0xa,
> > -0x4,
> > -0x49,
> > -0x4f,
> > -0x4d,
> > -0x58,
> > -0x14,
> > -0x18,
> > -0x5f,
> > -0x49,
> > -0x4e,
> > -0x49,
> > -0x0,
> > -0x70,
> > -0x50,
> > -0x45,
> > -0x53,
> > -0x54,
> > -0x49,
> > -0x4f,
> > -0x4d,
> > -0x4e,
> > -0x70,
> > -0x50,
> > -0x45,
> > -0x53,
> > -0x54,
> > -0x49,
> > -0x4f,
> > -0x4d,
> > -0x58
> > -};
> > -static unsigned char ssdt_isa_pest[] = {
> > -0xda
> > -};
> > -static unsigned char acpi_s4_name[] = {
> > -0x92
> > -};
> > -static unsigned char acpi_pci64_start[] = {
> > -0x4d
> > -};
> > -static unsigned char acpi_pci64_end[] = {
> > -0x5e
> > -};
> > -static unsigned char acpi_pci32_end[] = {
> > -0x39
> > -};
> > -- 
> > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API
  2015-02-17 19:14     ` Michael S. Tsirkin
@ 2015-02-18 10:35       ` Igor Mammedov
  0 siblings, 0 replies; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18 10:35 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 20:14:06 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, Feb 17, 2015 at 06:51:16PM +0100, Igor Mammedov wrote:
> > On Tue, 17 Feb 2015 17:47:03 +0100
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > 
> > > This seems to change the contents of the tables in too many ways.  So of
> > > it needs changing since PCI are somewhat broken by your recent patch.
> > In which way is it broken?
> 
> Try make check and look at the diffs.
> They shouldn't be so big.
> I want differences to be trivial, e.g.
> 0->Zero would be ok.
> Refactoring code generation should be separate from
> changing generated code.
if you run make check on whole series you will of cause se a lot of changes
however if you run make check on every patch that switches current code
to AML API you'll see small incremental changes, that's basically
every patch with prefix: "pc: acpi-build: "

> 
> 
> > > 
> > > So let's do this: please prepare a minimal patchset that just generates
> > > PCI description dynamically.  Drop everything that's not necessary, and
> > > verify that make check produces trivial diffs only.
> > > 
> > > We'll go from there.
> > > 

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

* Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
  2015-02-17 19:39   ` Michael S. Tsirkin
  2015-02-18 10:00     ` Igor Mammedov
@ 2015-02-18 10:42     ` Igor Mammedov
  2015-02-18 11:38       ` Michael S. Tsirkin
  1 sibling, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18 10:42 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 20:39:03 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Feb 09, 2015 at 10:53:43AM +0000, Igor Mammedov wrote:
> > Replace AML template patching with direct composing
> > of PCI device entries in C. It allows to simplify
> > PCI tree generation further and saves us about 400LOC
> > scattered through different files, confining tree
> > generation to one C function which is much easier
> > to deal with.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> Some comments below, this looks nice.
> 
> However, something strange is going on.
> This looks like it should produce identical
> code to what was there, but in fact your previous
> patch pc: acpi-build: simplify PCI bus tree generation
> changes SSDT, then this patch changes it back to
> what it was.
> 
> I'm confused by this.  Can't refactoring be done without changing the
> output back and forth, somehow?
just checked with make check ASL diff
if you you stop when applying patches on this patch and run make check
you'll get a  trivial diff:

@@ -153,7 +153,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
 
         Method (NTFY, 2, NotSerialized)
         {
-            If (LEqual (Arg0, 0x00))
+            If (LEqual (Arg0, Zero))
             {
                 Notify (CP00, Arg1)
             }
@@ -168,7 +168,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
             Name (BSEL, Zero)
             Device (S00)
             {
-                Name (_ADR, 0x00000000)  // _ADR: Address
+                Name (_ADR, Zero)  // _ADR: Address
             }
 
             Device (S10)


which is result of switching to aml_int() which encodes Zero opcode
instead of 0x00 ByteConst.

> 
> > ---
> >  hw/i386/Makefile.objs            |   6 +-
> >  hw/i386/acpi-build.c             | 207 +++++++++++---------------------
> >  hw/i386/ssdt-pcihp.dsl           | 100 ----------------
> >  hw/i386/ssdt-pcihp.hex.generated | 251 ---------------------------------------
> >  4 files changed, 72 insertions(+), 492 deletions(-)
> >  delete mode 100644 hw/i386/ssdt-pcihp.dsl
> >  delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
> > 
> > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> > index 2b678ef..4509cd1 100644
> > --- a/hw/i386/Makefile.objs
> > +++ b/hw/i386/Makefile.objs
> > @@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
> >  obj-y += kvmvapic.o
> >  obj-y += acpi-build.o
> >  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> > -	hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
> > -	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
> > -	hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \
> > -	hw/i386/ssdt-tpm.hex
> > +	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> > +	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
> >  
> >  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
> >      ; then echo "$(2)"; else echo "$(3)"; fi ;)
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index bdc343f..b6626f5 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)
> >  #define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
> >  #define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
> >  
> > -/* 0x5B 0x82 DeviceOp PkgLength NameString */
> > -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
> > -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
> > -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
> > -
> > -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
> > -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
> > -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
> > -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
> > -
> > -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
> > -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
> > -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
> > -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
> > -
> > -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
> > -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
> > -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
> > -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
> > -
> >  #include "hw/i386/ssdt-mem.hex"
> >  
> >  /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
> > @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)
> >  #define ACPI_SSDT_HEADER_LENGTH 36
> >  
> >  #include "hw/i386/ssdt-misc.hex"
> > -#include "hw/i386/ssdt-pcihp.hex"
> >  #include "hw/i386/ssdt-tpm.hex"
> >  
> >  static void
> > @@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,
> >      build_append_and_cleanup_method(device, method);
> >  }
> >  
> > -static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
> > -    ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
> > -}
> > -
> > -static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
> > -}
> > -
> > -static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
> > -}
> > -
> > -static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
> > -{
> > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > -
> > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
> > -}
> > -
> >  /* Assign BSEL property to all buses.  In the future, this can be changed
> >   * to only assign to buses that support hotplug.
> >   */
> > @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void)
> >      }
> >  }
> >  
> > -static void build_append_pcihp_notify_entry(GArray *method, int slot)
> > +static void build_append_pcihp_notify_entry(Aml *method, int slot)
> >  {
> > -    GArray *ifctx;
> > +    Aml *if_ctx;
> > +    int32_t devfn = PCI_DEVFN(slot, 0);
> >  
> > -    ifctx = build_alloc_array();
> > -    build_append_byte(ifctx, 0x7B); /* AndOp */
> > -    build_append_byte(ifctx, 0x68); /* Arg0Op */
> > -    build_append_int(ifctx, 0x1U << slot);
> > -    build_append_byte(ifctx, 0x00); /* NullName */
> > -    build_append_byte(ifctx, 0x86); /* NotifyOp */
> > -    build_append_namestring(ifctx, "S%.02X", PCI_DEVFN(slot, 0));
> > -    build_append_byte(ifctx, 0x69); /* Arg1Op */
> > -
> > -    /* Pack it up */
> > -    build_package(ifctx, 0xA0 /* IfOp */);
> > -    build_append_array(method, ifctx);
> > -    build_free_array(ifctx);
> > +    if_ctx = aml_if(aml_and(aml_arg(0), aml_int(0x1U << slot)));
> > +    aml_append(if_ctx, aml_notify(aml_name("S%.02X", devfn), aml_arg(1)));
> > +    aml_append(method, if_ctx);
> >  }
> >  
> > -static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> > +static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
> >                                           bool pcihp_bridge_en)
> >  {
> > -    GArray *bus_table = build_alloc_array();
> > -    GArray *method = NULL;
> > +    Aml *dev, *notify_method, *method;
> >      QObject *bsel;
> >      PCIBus *sec;
> >      int i;
> >  
> > -    if (bus->parent_dev) {
> > -        build_append_namestring(bus_table, "S%.02X_", bus->parent_dev->devfn);
> > -    } else {
> > -        build_append_namestring(bus_table, "PCI0");
> > -    }
> > -
> >      bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
> >      if (bsel) {
> > -        build_append_byte(bus_table, 0x08); /* NameOp */
> > -        build_append_namestring(bus_table, "BSEL");
> > -        build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
> > -        method = build_alloc_method("DVNT", 2);
> > +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> > +
> > +        aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val)));
> > +        notify_method = aml_method("DVNT", 2);
> >      }
> >  
> >      for (i = 0; i < ARRAY_SIZE(bus->devices); i += PCI_FUNC_MAX) {
> > @@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> >  
> >          if (!pdev) {
> >              if (bsel) {
> > -                void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> > -                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> > -                patch_pcihp(slot, pcihp);
> > -
> > -                build_append_pcihp_notify_entry(method, slot);
> > +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > +                aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> > +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > +                method = aml_method("_EJ0", 1);
> > +                aml_append(method,
> > +                    aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> > +                );
> > +                aml_append(dev, method);
> > +                aml_append(parent_scope, dev);
> > +
> > +                build_append_pcihp_notify_entry(notify_method, slot);
> >              } else {
> > -                void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> > -                memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> > -                patch_pcinohp(slot, pcihp);
> > +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > +                aml_append(parent_scope, dev);
> >              }
> >              continue;
> >          }
> > @@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> >          bridge_in_acpi = pc->is_bridge && pcihp_bridge_en &&
> >              !DEVICE(pdev)->hotplugged;
> >  
> > +        dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > +        aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > +
> >          if (pc->class_id == PCI_CLASS_DISPLAY_VGA) {
> > +            int s3d = 0;
> >  
> >              if (object_dynamic_cast(OBJECT(pdev), "qxl-vga")) {
> > -                void *pcihp = acpi_data_push(bus_table,
> > -                                             ACPI_PCIQXL_SIZEOF);
> > -                      memcpy(pcihp, ACPI_PCIQXL_AML, ACPI_PCIQXL_SIZEOF);
> > -                      patch_pciqxl(slot, pcihp);
> > -            } else {
> > -                void *pcihp = acpi_data_push(bus_table,
> > -                                             ACPI_PCIVGA_SIZEOF);
> > -                memcpy(pcihp, ACPI_PCIVGA_AML, ACPI_PCIVGA_SIZEOF);
> > -                patch_pcivga(slot, pcihp);
> > +                s3d = 3;
> >              }
> 
> I dislike this style, where 0 is set, then over-written.
> Please do
>     if (cond) {
>         s = 3;
>     } else {
>         s = 0;
>     }
> 
> 
> 
> > +
> > +            method = aml_method("_S1D", 0);
> > +            aml_append(method, aml_return(aml_int(0)));
> > +            aml_append(dev, method);
> > +
> > +            method = aml_method("_S2D", 0);
> > +            aml_append(method, aml_return(aml_int(0)));
> > +            aml_append(dev, method);
> > +
> > +            method = aml_method("_S3D", 0);
> > +            aml_append(method, aml_return(aml_int(s3d)));
> > +            aml_append(dev, method);
> >          } else if (dc->hotpluggable && !bridge_in_acpi) {
> > -            void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> > -            memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> > -            patch_pcihp(slot, pcihp);
> > +            aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> > +
> > +            method = aml_method("_EJ0", 1);
> > +            aml_append(method,
> > +                aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> > +            );
> > +            aml_append(dev, method);
> >  
> >              if (bsel) {
> > -                build_append_pcihp_notify_entry(method, slot);
> > +                build_append_pcihp_notify_entry(notify_method, slot);
> >              }
> >          } else {
> > -            void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> > -            memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> > -            patch_pcinohp(slot, pcihp);
> > -
> >              /* When hotplug for bridges is enabled, bridges that are
> >               * described in ACPI separately aren't themselves hot-pluggable.
> >               * Hotplugged bridges *are* hot-pluggable.
> > @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> >              if (bridge_in_acpi) {
> >                  PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
> >  
> > -                build_append_pci_bus_devices(bus_table, sec_bus,
> > -                                             pcihp_bridge_en);
> > +                build_append_pci_bus_devices(dev, sec_bus, pcihp_bridge_en);
> >              }
> >          }
> > +        aml_append(parent_scope, dev);
> >      }
> >  
> >      if (bsel) {
> > -        build_append_and_cleanup_method(bus_table, method);
> > +        aml_append(parent_scope, notify_method);
> >      }
> >  
> >      /* Append PCNT method to notify about events on local and child buses.
> >       * Add unconditionally for root since DSDT expects it.
> >       */
> > -    method = build_alloc_method("PCNT", 0);
> > +    method = aml_method("PCNT", 0);
> >  
> >      /* If bus supports hotplug select it and notify about local events */
> >      if (bsel) {
> > -        build_append_byte(method, 0x70); /* StoreOp */
> > -        build_append_int(method, qint_get_int(qobject_to_qint(bsel)));
> > -        build_append_namestring(method, "BNUM");
> > -        build_append_namestring(method, "DVNT");
> > -        build_append_namestring(method, "PCIU");
> > -        build_append_int(method, 1); /* Device Check */
> > -        build_append_namestring(method, "DVNT");
> > -        build_append_namestring(method, "PCID");
> > -        build_append_int(method, 3); /* Eject Request */
> > +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> > +        aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
> > +        aml_append(method,
> > +            aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check */)
> > +        );
> > +        aml_append(method,
> > +            aml_call2("DVNT", aml_name("PCID"), aml_int(3)/* Eject Request */)
> > +        );
> >      }
> >  
> >      /* Notify about child bus events in any case */
> >      if (pcihp_bridge_en) {
> >          QLIST_FOREACH(sec, &bus->child, sibling) {
> > -            build_append_namestring(method, "^S%.02X.PCNT",
> > -                                    sec->parent_dev->devfn);
> > +            int32_t devfn = sec->parent_dev->devfn;
> > +
> > +            aml_append(method, aml_name("^S%.02X.PCNT", devfn));
> >          }
> >      }
> > -
> > -    build_append_and_cleanup_method(bus_table, method);
> > -
> > -    build_package(bus_table, 0x10); /* ScopeOp */
> > -    build_append_array(parent_scope, bus_table);
> > -    build_free_array(bus_table);
> > +    aml_append(parent_scope, method);
> >  }
> >  
> >  static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
> > @@ -943,9 +875,10 @@ build_ssdt(Aml *table_data,
> >              }
> >  
> >              if (bus) {
> > +                Aml *scope = aml_scope("PCI0");
> >                  /* Scan all PCI buses. Generate tables to support hotplug. */
> > -                build_append_pci_bus_devices(sb_scope->buf, bus,
> > -                                             pm->pcihp_bridge_en);
> > +                build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en);
> > +                aml_append(sb_scope, scope);
> >              }
> >          }
> >          aml_append(ssdt, sb_scope);
> > diff --git a/hw/i386/ssdt-pcihp.dsl b/hw/i386/ssdt-pcihp.dsl
> > deleted file mode 100644
> > index ac91c05..0000000
> > --- a/hw/i386/ssdt-pcihp.dsl
> > +++ /dev/null
> > @@ -1,100 +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/>.
> > - */
> > -
> > -ACPI_EXTRACT_ALL_CODE ssdp_pcihp_aml
> > -
> > -DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
> > -{
> > -
> > -/****************************************************************
> > - * PCI hotplug
> > - ****************************************************************/
> > -
> > -    /* Objects supplied by DSDT */
> > -    External(\_SB.PCI0, DeviceObj)
> > -    External(\_SB.PCI0.PCEJ, MethodObj)
> > -    External(BSEL, IntObj)
> > -
> > -    Scope(\_SB.PCI0) {
> > -
> > -        /* Bulk generated PCI hotplug devices */
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pcihp_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pcihp_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcihp_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SAA) {
> > -            ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcihp_id
> > -            Name(_SUN, 0xAA)
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcihp_adr
> > -            Name(_ADR, 0xAA0000)
> > -            Method(_EJ0, 1) {
> > -                PCEJ(BSEL, _SUN)
> > -            }
> > -        }
> > -
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pcinohp_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pcinohp_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcinohp_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SBB) {
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcinohp_adr
> > -            Name(_ADR, 0xAA0000)
> > -        }
> > -
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pcivga_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pcivga_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcivga_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SCC) {
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcivga_adr
> > -            Name(_ADR, 0xAA0000)
> > -            Method(_S1D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S2D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S3D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -        }
> > -
> > -        ACPI_EXTRACT_DEVICE_START ssdt_pciqxl_start
> > -        ACPI_EXTRACT_DEVICE_END ssdt_pciqxl_end
> > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pciqxl_name
> > -
> > -        // Extract the offsets of the device name, address dword and the slot
> > -        // name byte - we fill them in for each device.
> > -        Device(SDD) {
> > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pciqxl_adr
> > -            Name(_ADR, 0xAA0000)
> > -            Method(_S1D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S2D, 0, NotSerialized) {
> > -                Return (0x00)
> > -            }
> > -            Method(_S3D, 0, NotSerialized) {
> > -                Return (0x03)           // QXL
> > -            }
> > -        }
> > -    }
> > -}
> > diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
> > deleted file mode 100644
> > index 72ffa84..0000000
> > --- a/hw/i386/ssdt-pcihp.hex.generated
> 
> Pls don't send generated file patches.
> Just note it should be removed in comment, I'll do it.
> 
> > +++ /dev/null
> > @@ -1,251 +0,0 @@
> > -static unsigned char ssdt_pcihp_name[] = {
> > -0x34
> > -};
> > -static unsigned char ssdt_pcivga_end[] = {
> > -0x99
> > -};
> > -static unsigned char ssdt_pcivga_name[] = {
> > -0x70
> > -};
> > -static unsigned char ssdt_pcihp_adr[] = {
> > -0x45
> > -};
> > -static unsigned char ssdt_pcinohp_end[] = {
> > -0x6d
> > -};
> > -static unsigned char ssdt_pcihp_end[] = {
> > -0x5c
> > -};
> > -static unsigned char ssdt_pciqxl_start[] = {
> > -0x99
> > -};
> > -static unsigned char ssdt_pcinohp_name[] = {
> > -0x5f
> > -};
> > -static unsigned char ssdp_pcihp_aml[] = {
> > -0x53,
> > -0x53,
> > -0x44,
> > -0x54,
> > -0xc6,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x1,
> > -0x70,
> > -0x42,
> > -0x58,
> > -0x50,
> > -0x43,
> > -0x0,
> > -0x0,
> > -0x42,
> > -0x58,
> > -0x53,
> > -0x53,
> > -0x44,
> > -0x54,
> > -0x50,
> > -0x43,
> > -0x1,
> > -0x0,
> > -0x0,
> > -0x0,
> > -0x49,
> > -0x4e,
> > -0x54,
> > -0x4c,
> > -0x15,
> > -0x11,
> > -0x13,
> > -0x20,
> > -0x10,
> > -0x41,
> > -0xa,
> > -0x5c,
> > -0x2e,
> > -0x5f,
> > -0x53,
> > -0x42,
> > -0x5f,
> > -0x50,
> > -0x43,
> > -0x49,
> > -0x30,
> > -0x5b,
> > -0x82,
> > -0x29,
> > -0x53,
> > -0x41,
> > -0x41,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x55,
> > -0x4e,
> > -0xa,
> > -0xaa,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x14,
> > -0x12,
> > -0x5f,
> > -0x45,
> > -0x4a,
> > -0x30,
> > -0x1,
> > -0x50,
> > -0x43,
> > -0x45,
> > -0x4a,
> > -0x42,
> > -0x53,
> > -0x45,
> > -0x4c,
> > -0x5f,
> > -0x53,
> > -0x55,
> > -0x4e,
> > -0x5b,
> > -0x82,
> > -0xf,
> > -0x53,
> > -0x42,
> > -0x42,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x5b,
> > -0x82,
> > -0x2a,
> > -0x53,
> > -0x43,
> > -0x43,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x31,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x32,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x33,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x5b,
> > -0x82,
> > -0x2b,
> > -0x53,
> > -0x44,
> > -0x44,
> > -0x5f,
> > -0x8,
> > -0x5f,
> > -0x41,
> > -0x44,
> > -0x52,
> > -0xc,
> > -0x0,
> > -0x0,
> > -0xaa,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x31,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x8,
> > -0x5f,
> > -0x53,
> > -0x32,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0x0,
> > -0x14,
> > -0x9,
> > -0x5f,
> > -0x53,
> > -0x33,
> > -0x44,
> > -0x0,
> > -0xa4,
> > -0xa,
> > -0x3
> > -};
> > -static unsigned char ssdt_pciqxl_adr[] = {
> > -0xa6
> > -};
> > -static unsigned char ssdt_pcinohp_adr[] = {
> > -0x69
> > -};
> > -static unsigned char ssdt_pcivga_adr[] = {
> > -0x7a
> > -};
> > -static unsigned char ssdt_pciqxl_name[] = {
> > -0x9c
> > -};
> > -static unsigned char ssdt_pcivga_start[] = {
> > -0x6d
> > -};
> > -static unsigned char ssdt_pciqxl_end[] = {
> > -0xc6
> > -};
> > -static unsigned char ssdt_pcihp_start[] = {
> > -0x31
> > -};
> > -static unsigned char ssdt_pcihp_id[] = {
> > -0x3e
> > -};
> > -static unsigned char ssdt_pcinohp_start[] = {
> > -0x5c
> > -};
> > -- 
> > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-17 19:03       ` Michael S. Tsirkin
@ 2015-02-18 10:47         ` Igor Mammedov
  2015-02-18 11:36           ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Igor Mammedov @ 2015-02-18 10:47 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Tue, 17 Feb 2015 20:03:52 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, Feb 17, 2015 at 05:47:26PM +0100, Igor Mammedov wrote:
> > On Tue, 17 Feb 2015 17:35:55 +0100
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > 
> > > On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > ---
> > > >  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
> > > >  hw/i386/acpi-build.c        |  4 ----
> > > >  include/hw/acpi/aml-build.h | 10 ++++++++++
> > > >  3 files changed, 48 insertions(+), 4 deletions(-)
> > > > 
> > > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > > index 67d1371..cb1a1bd 100644
> > > > --- a/hw/acpi/aml-build.c
> > > > +++ b/hw/acpi/aml-build.c
> > > > @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
> > > >      }
> > > >      build_append_array(parent_ctx->buf, child->buf);
> > > >  }
> > > > +
> > > > +/*
> > > > + * ACPI 1.0b: 16.2.1 Top Level AML
> > > > + *            5.2.3 System Description Table Header
> > > > + *
> > > > + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> > > > + */
> > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > +                   const char *oem_id, const char *oem_table_id,
> > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > +                   uint32_t creator_revision)
> > > > +{
> > > > +    int len;
> > > > +    Aml *var = aml_alloc();
> > > > +    var->block_flags = AML_DEF_BLOCK;
> > > > +
> > > > +    assert(strlen(signature) == 4);
> > > > +    g_array_append_vals(var->buf, signature, 4);
> > > > +    build_append_value(var->buf, 0, 4); /* Length place holder */
> > > > +    build_append_byte(var->buf, revision);
> > > > +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> > > > +
> > > > +    len = strlen(oem_id);
> > > > +    assert(len <= 6);
> > > > +    g_array_append_vals(var->buf, oem_id, len);
> > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> > > > +
> > > > +    len = strlen(oem_table_id);
> > > > +    assert(len <= 8);
> > > > +    g_array_append_vals(var->buf, oem_table_id, len);
> > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> > > > +
> > > > +    build_append_value(var->buf, oem_revision, 4);
> > > > +    build_append_value(var->buf, creator_id, 4);
> > > > +    build_append_value(var->buf, creator_revision, 4);
> > > > +
> > > > +    return var;
> > > 
> > > 
> > > Please don't do this.
> > > First, this is not a definition block encoding, so name
> > > is wrong.
> > > 
> > > Second, we already have functions to fill in headers.
> > > So just call them.
> > > 
> > > Filling structures byte by byte is unreadable -
> > > I know ACPI spec often makes us do this but
> > > when it doesn't, we should not do it.
> > it does, in ACPI 5.1,
> > 
> > 20.2.1 Table and Table Header Encoding
> > AMLCode := DefBlockHeader TermList
> > DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID
> > OemTableID OemRevision CreatorID CreatorRevision
> 
> Sorry I'm not merging this in this form, we should use structures
> where possible, this is where C shines, just use the language
> properly.
Although I don't see benefits of using C structures here as
I've wrote in previous reply, I can easily switch internal API functions
to structures, if it helps with merging.

> 
> 
> > > 
> > > Pls keep using build_header for now.
> > > 
> > > 
> > > > +}
> > > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > > index a1bf450..553c86b 100644
> > > > --- a/hw/i386/acpi-build.c
> > > > +++ b/hw/i386/acpi-build.c
> > > > @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> > > >                                              NULL);
> > > >  }
> > > >  
> > > > -#define ACPI_BUILD_APPNAME  "Bochs"
> > > > -#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > -#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > -
> > > >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> > > >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> > > >  
> > > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > > > index 4033796..2610336 100644
> > > > --- a/include/hw/acpi/aml-build.h
> > > > +++ b/include/hw/acpi/aml-build.h
> > > > @@ -6,6 +6,10 @@
> > > >  #include "qemu/compiler.h"
> > > >  
> > > >  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > > > +#define ACPI_BUILD_APPNAME  "Bochs"
> > > > +#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > +#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
> > > >  
> > > >  typedef enum {
> > > >      AML_HELPER = 0,
> > > > @@ -65,6 +69,12 @@ void free_aml_allocator(void);
> > > >   */
> > > >  void aml_append(Aml *parent_ctx, Aml *child);
> > > >  
> > > > +/* Block AML object primitives */
> > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > +                   const char *oem_id, const char *oem_table_id,
> > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > +                   uint32_t creator_revision);
> > > > +
> > > >  /* other helpers */
> > > >  GArray *build_alloc_array(void);
> > > >  void build_free_array(GArray *array);
> > > > -- 
> > > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-18  9:50         ` Igor Mammedov
@ 2015-02-18 11:35           ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 11:35 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Wed, Feb 18, 2015 at 10:50:54AM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 20:15:42 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Tue, Feb 17, 2015 at 05:47:26PM +0100, Igor Mammedov wrote:
> > > On Tue, 17 Feb 2015 17:35:55 +0100
> > > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > > 
> > > > On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > > ---
> > > > >  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
> > > > >  hw/i386/acpi-build.c        |  4 ----
> > > > >  include/hw/acpi/aml-build.h | 10 ++++++++++
> > > > >  3 files changed, 48 insertions(+), 4 deletions(-)
> > > > > 
> > > > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > > > index 67d1371..cb1a1bd 100644
> > > > > --- a/hw/acpi/aml-build.c
> > > > > +++ b/hw/acpi/aml-build.c
> > > > > @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
> > > > >      }
> > > > >      build_append_array(parent_ctx->buf, child->buf);
> > > > >  }
> > > > > +
> > > > > +/*
> > > > > + * ACPI 1.0b: 16.2.1 Top Level AML
> > > > > + *            5.2.3 System Description Table Header
> > > > > + *
> > > > > + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> > > > > + */
> > > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > > +                   const char *oem_id, const char *oem_table_id,
> > > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > > +                   uint32_t creator_revision)
> > > > > +{
> > > > > +    int len;
> > > > > +    Aml *var = aml_alloc();
> > > > > +    var->block_flags = AML_DEF_BLOCK;
> > > > > +
> > > > > +    assert(strlen(signature) == 4);
> > > > > +    g_array_append_vals(var->buf, signature, 4);
> > > > > +    build_append_value(var->buf, 0, 4); /* Length place holder */
> > > > > +    build_append_byte(var->buf, revision);
> > > > > +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> > > > > +
> > > > > +    len = strlen(oem_id);
> > > > > +    assert(len <= 6);
> > > > > +    g_array_append_vals(var->buf, oem_id, len);
> > > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> > > > > +
> > > > > +    len = strlen(oem_table_id);
> > > > > +    assert(len <= 8);
> > > > > +    g_array_append_vals(var->buf, oem_table_id, len);
> > > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> > > > > +
> > > > > +    build_append_value(var->buf, oem_revision, 4);
> > > > > +    build_append_value(var->buf, creator_id, 4);
> > > > > +    build_append_value(var->buf, creator_revision, 4);
> > > > > +
> > > > > +    return var;
> > > > 
> > > > 
> > > > Please don't do this.
> > > > First, this is not a definition block encoding, so name
> > > > is wrong.
> > > > 
> > > > Second, we already have functions to fill in headers.
> > > > So just call them.
> > > > 
> > > > Filling structures byte by byte is unreadable -
> > > > I know ACPI spec often makes us do this but
> > > > when it doesn't, we should not do it.
> > > it does, in ACPI 5.1,
> > > 
> > > 20.2.1 Table and Table Header Encoding
> > > AMLCode := DefBlockHeader TermList
> > > DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID
> > > OemTableID OemRevision CreatorID CreatorRevision
> > 
> > So spec explains it very badly, but these all are
> > fixed width fields.
> > Filling them in using add_byte just makes for hard to
> > read code.
> If it were only add_byte, I'd agree but it basically composes
> by whole fields and in this particular case is easy to
> verify just by looking to spec, just like the rest of AML
> terms does.
> And one doesn't have to care about endianness because
> build_append_value() packs integer fields as expected
> by spec as opposed to using C struct-s.

things like
	assert(len <= 8);
	g_array_append_vals(var->buf, oem_table_id, len);
	g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
are kind of ugly, are they not? 8 is repeated 3 times here,
and you need to go look at spec to figure out what 8 stands for.

Besides, we aren't yet getting rid of build_header, are we?
How about this, we get rest of this code in, then
work on rewriting build_header everywhere?

> > 
> > > > 
> > > > Pls keep using build_header for now.
> > > > 
> > > > 
> > > > > +}
> > > > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > > > index a1bf450..553c86b 100644
> > > > > --- a/hw/i386/acpi-build.c
> > > > > +++ b/hw/i386/acpi-build.c
> > > > > @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> > > > >                                              NULL);
> > > > >  }
> > > > >  
> > > > > -#define ACPI_BUILD_APPNAME  "Bochs"
> > > > > -#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > > -#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > > -
> > > > >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> > > > >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> > > > >  
> > > > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > > > > index 4033796..2610336 100644
> > > > > --- a/include/hw/acpi/aml-build.h
> > > > > +++ b/include/hw/acpi/aml-build.h
> > > > > @@ -6,6 +6,10 @@
> > > > >  #include "qemu/compiler.h"
> > > > >  
> > > > >  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > > > > +#define ACPI_BUILD_APPNAME  "Bochs"
> > > > > +#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > > +#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > > +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
> > > > >  
> > > > >  typedef enum {
> > > > >      AML_HELPER = 0,
> > > > > @@ -65,6 +69,12 @@ void free_aml_allocator(void);
> > > > >   */
> > > > >  void aml_append(Aml *parent_ctx, Aml *child);
> > > > >  
> > > > > +/* Block AML object primitives */
> > > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > > +                   const char *oem_id, const char *oem_table_id,
> > > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > > +                   uint32_t creator_revision);
> > > > > +
> > > > >  /* other helpers */
> > > > >  GArray *build_alloc_array(void);
> > > > >  void build_free_array(GArray *array);
> > > > > -- 
> > > > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
  2015-02-18 10:47         ` Igor Mammedov
@ 2015-02-18 11:36           ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 11:36 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Wed, Feb 18, 2015 at 11:47:08AM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 20:03:52 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Tue, Feb 17, 2015 at 05:47:26PM +0100, Igor Mammedov wrote:
> > > On Tue, 17 Feb 2015 17:35:55 +0100
> > > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > > 
> > > > On Mon, Feb 09, 2015 at 10:53:27AM +0000, Igor Mammedov wrote:
> > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > > ---
> > > > >  hw/acpi/aml-build.c         | 38 ++++++++++++++++++++++++++++++++++++++
> > > > >  hw/i386/acpi-build.c        |  4 ----
> > > > >  include/hw/acpi/aml-build.h | 10 ++++++++++
> > > > >  3 files changed, 48 insertions(+), 4 deletions(-)
> > > > > 
> > > > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > > > index 67d1371..cb1a1bd 100644
> > > > > --- a/hw/acpi/aml-build.c
> > > > > +++ b/hw/acpi/aml-build.c
> > > > > @@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
> > > > >      }
> > > > >      build_append_array(parent_ctx->buf, child->buf);
> > > > >  }
> > > > > +
> > > > > +/*
> > > > > + * ACPI 1.0b: 16.2.1 Top Level AML
> > > > > + *            5.2.3 System Description Table Header
> > > > > + *
> > > > > + * ACPI 5.0: 20.2.1 Table and Table Header Encoding
> > > > > + */
> > > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > > +                   const char *oem_id, const char *oem_table_id,
> > > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > > +                   uint32_t creator_revision)
> > > > > +{
> > > > > +    int len;
> > > > > +    Aml *var = aml_alloc();
> > > > > +    var->block_flags = AML_DEF_BLOCK;
> > > > > +
> > > > > +    assert(strlen(signature) == 4);
> > > > > +    g_array_append_vals(var->buf, signature, 4);
> > > > > +    build_append_value(var->buf, 0, 4); /* Length place holder */
> > > > > +    build_append_byte(var->buf, revision);
> > > > > +    build_append_byte(var->buf, 0); /* place holder for Checksum */
> > > > > +
> > > > > +    len = strlen(oem_id);
> > > > > +    assert(len <= 6);
> > > > > +    g_array_append_vals(var->buf, oem_id, len);
> > > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
> > > > > +
> > > > > +    len = strlen(oem_table_id);
> > > > > +    assert(len <= 8);
> > > > > +    g_array_append_vals(var->buf, oem_table_id, len);
> > > > > +    g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
> > > > > +
> > > > > +    build_append_value(var->buf, oem_revision, 4);
> > > > > +    build_append_value(var->buf, creator_id, 4);
> > > > > +    build_append_value(var->buf, creator_revision, 4);
> > > > > +
> > > > > +    return var;
> > > > 
> > > > 
> > > > Please don't do this.
> > > > First, this is not a definition block encoding, so name
> > > > is wrong.
> > > > 
> > > > Second, we already have functions to fill in headers.
> > > > So just call them.
> > > > 
> > > > Filling structures byte by byte is unreadable -
> > > > I know ACPI spec often makes us do this but
> > > > when it doesn't, we should not do it.
> > > it does, in ACPI 5.1,
> > > 
> > > 20.2.1 Table and Table Header Encoding
> > > AMLCode := DefBlockHeader TermList
> > > DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID
> > > OemTableID OemRevision CreatorID CreatorRevision
> > 
> > Sorry I'm not merging this in this form, we should use structures
> > where possible, this is where C shines, just use the language
> > properly.
> Although I don't see benefits of using C structures here as
> I've wrote in previous reply, I can easily switch internal API functions
> to structures, if it helps with merging.

I don't think we need to change too much.
Let's defer aml_def_block and its users for now,
the rest of the series is fine I think.


> > 
> > 
> > > > 
> > > > Pls keep using build_header for now.
> > > > 
> > > > 
> > > > > +}
> > > > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > > > index a1bf450..553c86b 100644
> > > > > --- a/hw/i386/acpi-build.c
> > > > > +++ b/hw/i386/acpi-build.c
> > > > > @@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
> > > > >                                              NULL);
> > > > >  }
> > > > >  
> > > > > -#define ACPI_BUILD_APPNAME  "Bochs"
> > > > > -#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > > -#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > > -
> > > > >  #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
> > > > >  #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
> > > > >  
> > > > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
> > > > > index 4033796..2610336 100644
> > > > > --- a/include/hw/acpi/aml-build.h
> > > > > +++ b/include/hw/acpi/aml-build.h
> > > > > @@ -6,6 +6,10 @@
> > > > >  #include "qemu/compiler.h"
> > > > >  
> > > > >  #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
> > > > > +#define ACPI_BUILD_APPNAME  "Bochs"
> > > > > +#define ACPI_BUILD_APPNAME6 "BOCHS "
> > > > > +#define ACPI_BUILD_APPNAME4 "BXPC"
> > > > > +#define ACPI_BUILD_APPNAME4_HEX 0x43505842
> > > > >  
> > > > >  typedef enum {
> > > > >      AML_HELPER = 0,
> > > > > @@ -65,6 +69,12 @@ void free_aml_allocator(void);
> > > > >   */
> > > > >  void aml_append(Aml *parent_ctx, Aml *child);
> > > > >  
> > > > > +/* Block AML object primitives */
> > > > > +Aml *aml_def_block(const char *signature, uint8_t revision,
> > > > > +                   const char *oem_id, const char *oem_table_id,
> > > > > +                   uint32_t oem_revision, uint32_t creator_id,
> > > > > +                   uint32_t creator_revision);
> > > > > +
> > > > >  /* other helpers */
> > > > >  GArray *build_alloc_array(void);
> > > > >  void build_free_array(GArray *array);
> > > > > -- 
> > > > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
  2015-02-18 10:42     ` Igor Mammedov
@ 2015-02-18 11:38       ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 11:38 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Wed, Feb 18, 2015 at 11:42:15AM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 20:39:03 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:53:43AM +0000, Igor Mammedov wrote:
> > > Replace AML template patching with direct composing
> > > of PCI device entries in C. It allows to simplify
> > > PCI tree generation further and saves us about 400LOC
> > > scattered through different files, confining tree
> > > generation to one C function which is much easier
> > > to deal with.
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > 
> > Some comments below, this looks nice.
> > 
> > However, something strange is going on.
> > This looks like it should produce identical
> > code to what was there, but in fact your previous
> > patch pc: acpi-build: simplify PCI bus tree generation
> > changes SSDT, then this patch changes it back to
> > what it was.
> > 
> > I'm confused by this.  Can't refactoring be done without changing the
> > output back and forth, somehow?
> just checked with make check ASL diff
> if you you stop when applying patches on this patch and run make check
> you'll get a  trivial diff:
> 
> @@ -153,7 +153,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
>  
>          Method (NTFY, 2, NotSerialized)
>          {
> -            If (LEqual (Arg0, 0x00))
> +            If (LEqual (Arg0, Zero))
>              {
>                  Notify (CP00, Arg1)
>              }
> @@ -168,7 +168,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
>              Name (BSEL, Zero)
>              Device (S00)
>              {
> -                Name (_ADR, 0x00000000)  // _ADR: Address
> +                Name (_ADR, Zero)  // _ADR: Address
>              }
>  
>              Device (S10)
> 
> 
> which is result of switching to aml_int() which encodes Zero opcode
> instead of 0x00 ByteConst.

Right, but if you try before this patch, you see a huge diff.
So this patch mostly cancels the changes you made with
the previous pci rework.


> > 
> > > ---
> > >  hw/i386/Makefile.objs            |   6 +-
> > >  hw/i386/acpi-build.c             | 207 +++++++++++---------------------
> > >  hw/i386/ssdt-pcihp.dsl           | 100 ----------------
> > >  hw/i386/ssdt-pcihp.hex.generated | 251 ---------------------------------------
> > >  4 files changed, 72 insertions(+), 492 deletions(-)
> > >  delete mode 100644 hw/i386/ssdt-pcihp.dsl
> > >  delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
> > > 
> > > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> > > index 2b678ef..4509cd1 100644
> > > --- a/hw/i386/Makefile.objs
> > > +++ b/hw/i386/Makefile.objs
> > > @@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
> > >  obj-y += kvmvapic.o
> > >  obj-y += acpi-build.o
> > >  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> > > -	hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
> > > -	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
> > > -	hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \
> > > -	hw/i386/ssdt-tpm.hex
> > > +	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> > > +	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
> > >  
> > >  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
> > >      ; then echo "$(2)"; else echo "$(3)"; fi ;)
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index bdc343f..b6626f5 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)
> > >  #define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
> > >  #define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
> > >  
> > > -/* 0x5B 0x82 DeviceOp PkgLength NameString */
> > > -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
> > > -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
> > > -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
> > > -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
> > > -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
> > > -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
> > > -
> > > -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
> > > -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
> > > -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
> > > -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
> > > -
> > > -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
> > > -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
> > > -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
> > > -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
> > > -
> > > -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
> > > -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
> > > -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
> > > -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
> > > -
> > >  #include "hw/i386/ssdt-mem.hex"
> > >  
> > >  /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
> > > @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)
> > >  #define ACPI_SSDT_HEADER_LENGTH 36
> > >  
> > >  #include "hw/i386/ssdt-misc.hex"
> > > -#include "hw/i386/ssdt-pcihp.hex"
> > >  #include "hw/i386/ssdt-tpm.hex"
> > >  
> > >  static void
> > > @@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,
> > >      build_append_and_cleanup_method(device, method);
> > >  }
> > >  
> > > -static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
> > > -{
> > > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > > -
> > > -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > > -    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > > -    ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
> > > -    ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
> > > -}
> > > -
> > > -static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
> > > -{
> > > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > > -
> > > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > > -    ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
> > > -}
> > > -
> > > -static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
> > > -{
> > > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > > -
> > > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > > -    ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
> > > -}
> > > -
> > > -static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
> > > -{
> > > -    unsigned devfn = PCI_DEVFN(slot, 0);
> > > -
> > > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
> > > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
> > > -    ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
> > > -}
> > > -
> > >  /* Assign BSEL property to all buses.  In the future, this can be changed
> > >   * to only assign to buses that support hotplug.
> > >   */
> > > @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void)
> > >      }
> > >  }
> > >  
> > > -static void build_append_pcihp_notify_entry(GArray *method, int slot)
> > > +static void build_append_pcihp_notify_entry(Aml *method, int slot)
> > >  {
> > > -    GArray *ifctx;
> > > +    Aml *if_ctx;
> > > +    int32_t devfn = PCI_DEVFN(slot, 0);
> > >  
> > > -    ifctx = build_alloc_array();
> > > -    build_append_byte(ifctx, 0x7B); /* AndOp */
> > > -    build_append_byte(ifctx, 0x68); /* Arg0Op */
> > > -    build_append_int(ifctx, 0x1U << slot);
> > > -    build_append_byte(ifctx, 0x00); /* NullName */
> > > -    build_append_byte(ifctx, 0x86); /* NotifyOp */
> > > -    build_append_namestring(ifctx, "S%.02X", PCI_DEVFN(slot, 0));
> > > -    build_append_byte(ifctx, 0x69); /* Arg1Op */
> > > -
> > > -    /* Pack it up */
> > > -    build_package(ifctx, 0xA0 /* IfOp */);
> > > -    build_append_array(method, ifctx);
> > > -    build_free_array(ifctx);
> > > +    if_ctx = aml_if(aml_and(aml_arg(0), aml_int(0x1U << slot)));
> > > +    aml_append(if_ctx, aml_notify(aml_name("S%.02X", devfn), aml_arg(1)));
> > > +    aml_append(method, if_ctx);
> > >  }
> > >  
> > > -static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> > > +static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
> > >                                           bool pcihp_bridge_en)
> > >  {
> > > -    GArray *bus_table = build_alloc_array();
> > > -    GArray *method = NULL;
> > > +    Aml *dev, *notify_method, *method;
> > >      QObject *bsel;
> > >      PCIBus *sec;
> > >      int i;
> > >  
> > > -    if (bus->parent_dev) {
> > > -        build_append_namestring(bus_table, "S%.02X_", bus->parent_dev->devfn);
> > > -    } else {
> > > -        build_append_namestring(bus_table, "PCI0");
> > > -    }
> > > -
> > >      bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
> > >      if (bsel) {
> > > -        build_append_byte(bus_table, 0x08); /* NameOp */
> > > -        build_append_namestring(bus_table, "BSEL");
> > > -        build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
> > > -        method = build_alloc_method("DVNT", 2);
> > > +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> > > +
> > > +        aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val)));
> > > +        notify_method = aml_method("DVNT", 2);
> > >      }
> > >  
> > >      for (i = 0; i < ARRAY_SIZE(bus->devices); i += PCI_FUNC_MAX) {
> > > @@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> > >  
> > >          if (!pdev) {
> > >              if (bsel) {
> > > -                void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> > > -                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> > > -                patch_pcihp(slot, pcihp);
> > > -
> > > -                build_append_pcihp_notify_entry(method, slot);
> > > +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > > +                aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> > > +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > > +                method = aml_method("_EJ0", 1);
> > > +                aml_append(method,
> > > +                    aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> > > +                );
> > > +                aml_append(dev, method);
> > > +                aml_append(parent_scope, dev);
> > > +
> > > +                build_append_pcihp_notify_entry(notify_method, slot);
> > >              } else {
> > > -                void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> > > -                memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> > > -                patch_pcinohp(slot, pcihp);
> > > +                dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > > +                aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > > +                aml_append(parent_scope, dev);
> > >              }
> > >              continue;
> > >          }
> > > @@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> > >          bridge_in_acpi = pc->is_bridge && pcihp_bridge_en &&
> > >              !DEVICE(pdev)->hotplugged;
> > >  
> > > +        dev = aml_device("S%.02X", PCI_DEVFN(slot, 0));
> > > +        aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16)));
> > > +
> > >          if (pc->class_id == PCI_CLASS_DISPLAY_VGA) {
> > > +            int s3d = 0;
> > >  
> > >              if (object_dynamic_cast(OBJECT(pdev), "qxl-vga")) {
> > > -                void *pcihp = acpi_data_push(bus_table,
> > > -                                             ACPI_PCIQXL_SIZEOF);
> > > -                      memcpy(pcihp, ACPI_PCIQXL_AML, ACPI_PCIQXL_SIZEOF);
> > > -                      patch_pciqxl(slot, pcihp);
> > > -            } else {
> > > -                void *pcihp = acpi_data_push(bus_table,
> > > -                                             ACPI_PCIVGA_SIZEOF);
> > > -                memcpy(pcihp, ACPI_PCIVGA_AML, ACPI_PCIVGA_SIZEOF);
> > > -                patch_pcivga(slot, pcihp);
> > > +                s3d = 3;
> > >              }
> > 
> > I dislike this style, where 0 is set, then over-written.
> > Please do
> >     if (cond) {
> >         s = 3;
> >     } else {
> >         s = 0;
> >     }
> > 
> > 
> > 
> > > +
> > > +            method = aml_method("_S1D", 0);
> > > +            aml_append(method, aml_return(aml_int(0)));
> > > +            aml_append(dev, method);
> > > +
> > > +            method = aml_method("_S2D", 0);
> > > +            aml_append(method, aml_return(aml_int(0)));
> > > +            aml_append(dev, method);
> > > +
> > > +            method = aml_method("_S3D", 0);
> > > +            aml_append(method, aml_return(aml_int(s3d)));
> > > +            aml_append(dev, method);
> > >          } else if (dc->hotpluggable && !bridge_in_acpi) {
> > > -            void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
> > > -            memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
> > > -            patch_pcihp(slot, pcihp);
> > > +            aml_append(dev, aml_name_decl("_SUN", aml_int(slot)));
> > > +
> > > +            method = aml_method("_EJ0", 1);
> > > +            aml_append(method,
> > > +                aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN"))
> > > +            );
> > > +            aml_append(dev, method);
> > >  
> > >              if (bsel) {
> > > -                build_append_pcihp_notify_entry(method, slot);
> > > +                build_append_pcihp_notify_entry(notify_method, slot);
> > >              }
> > >          } else {
> > > -            void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
> > > -            memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
> > > -            patch_pcinohp(slot, pcihp);
> > > -
> > >              /* When hotplug for bridges is enabled, bridges that are
> > >               * described in ACPI separately aren't themselves hot-pluggable.
> > >               * Hotplugged bridges *are* hot-pluggable.
> > > @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
> > >              if (bridge_in_acpi) {
> > >                  PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
> > >  
> > > -                build_append_pci_bus_devices(bus_table, sec_bus,
> > > -                                             pcihp_bridge_en);
> > > +                build_append_pci_bus_devices(dev, sec_bus, pcihp_bridge_en);
> > >              }
> > >          }
> > > +        aml_append(parent_scope, dev);
> > >      }
> > >  
> > >      if (bsel) {
> > > -        build_append_and_cleanup_method(bus_table, method);
> > > +        aml_append(parent_scope, notify_method);
> > >      }
> > >  
> > >      /* Append PCNT method to notify about events on local and child buses.
> > >       * Add unconditionally for root since DSDT expects it.
> > >       */
> > > -    method = build_alloc_method("PCNT", 0);
> > > +    method = aml_method("PCNT", 0);
> > >  
> > >      /* If bus supports hotplug select it and notify about local events */
> > >      if (bsel) {
> > > -        build_append_byte(method, 0x70); /* StoreOp */
> > > -        build_append_int(method, qint_get_int(qobject_to_qint(bsel)));
> > > -        build_append_namestring(method, "BNUM");
> > > -        build_append_namestring(method, "DVNT");
> > > -        build_append_namestring(method, "PCIU");
> > > -        build_append_int(method, 1); /* Device Check */
> > > -        build_append_namestring(method, "DVNT");
> > > -        build_append_namestring(method, "PCID");
> > > -        build_append_int(method, 3); /* Eject Request */
> > > +        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
> > > +        aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
> > > +        aml_append(method,
> > > +            aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check */)
> > > +        );
> > > +        aml_append(method,
> > > +            aml_call2("DVNT", aml_name("PCID"), aml_int(3)/* Eject Request */)
> > > +        );
> > >      }
> > >  
> > >      /* Notify about child bus events in any case */
> > >      if (pcihp_bridge_en) {
> > >          QLIST_FOREACH(sec, &bus->child, sibling) {
> > > -            build_append_namestring(method, "^S%.02X.PCNT",
> > > -                                    sec->parent_dev->devfn);
> > > +            int32_t devfn = sec->parent_dev->devfn;
> > > +
> > > +            aml_append(method, aml_name("^S%.02X.PCNT", devfn));
> > >          }
> > >      }
> > > -
> > > -    build_append_and_cleanup_method(bus_table, method);
> > > -
> > > -    build_package(bus_table, 0x10); /* ScopeOp */
> > > -    build_append_array(parent_scope, bus_table);
> > > -    build_free_array(bus_table);
> > > +    aml_append(parent_scope, method);
> > >  }
> > >  
> > >  static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
> > > @@ -943,9 +875,10 @@ build_ssdt(Aml *table_data,
> > >              }
> > >  
> > >              if (bus) {
> > > +                Aml *scope = aml_scope("PCI0");
> > >                  /* Scan all PCI buses. Generate tables to support hotplug. */
> > > -                build_append_pci_bus_devices(sb_scope->buf, bus,
> > > -                                             pm->pcihp_bridge_en);
> > > +                build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en);
> > > +                aml_append(sb_scope, scope);
> > >              }
> > >          }
> > >          aml_append(ssdt, sb_scope);
> > > diff --git a/hw/i386/ssdt-pcihp.dsl b/hw/i386/ssdt-pcihp.dsl
> > > deleted file mode 100644
> > > index ac91c05..0000000
> > > --- a/hw/i386/ssdt-pcihp.dsl
> > > +++ /dev/null
> > > @@ -1,100 +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/>.
> > > - */
> > > -
> > > -ACPI_EXTRACT_ALL_CODE ssdp_pcihp_aml
> > > -
> > > -DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
> > > -{
> > > -
> > > -/****************************************************************
> > > - * PCI hotplug
> > > - ****************************************************************/
> > > -
> > > -    /* Objects supplied by DSDT */
> > > -    External(\_SB.PCI0, DeviceObj)
> > > -    External(\_SB.PCI0.PCEJ, MethodObj)
> > > -    External(BSEL, IntObj)
> > > -
> > > -    Scope(\_SB.PCI0) {
> > > -
> > > -        /* Bulk generated PCI hotplug devices */
> > > -        ACPI_EXTRACT_DEVICE_START ssdt_pcihp_start
> > > -        ACPI_EXTRACT_DEVICE_END ssdt_pcihp_end
> > > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcihp_name
> > > -
> > > -        // Extract the offsets of the device name, address dword and the slot
> > > -        // name byte - we fill them in for each device.
> > > -        Device(SAA) {
> > > -            ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcihp_id
> > > -            Name(_SUN, 0xAA)
> > > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcihp_adr
> > > -            Name(_ADR, 0xAA0000)
> > > -            Method(_EJ0, 1) {
> > > -                PCEJ(BSEL, _SUN)
> > > -            }
> > > -        }
> > > -
> > > -        ACPI_EXTRACT_DEVICE_START ssdt_pcinohp_start
> > > -        ACPI_EXTRACT_DEVICE_END ssdt_pcinohp_end
> > > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcinohp_name
> > > -
> > > -        // Extract the offsets of the device name, address dword and the slot
> > > -        // name byte - we fill them in for each device.
> > > -        Device(SBB) {
> > > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcinohp_adr
> > > -            Name(_ADR, 0xAA0000)
> > > -        }
> > > -
> > > -        ACPI_EXTRACT_DEVICE_START ssdt_pcivga_start
> > > -        ACPI_EXTRACT_DEVICE_END ssdt_pcivga_end
> > > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pcivga_name
> > > -
> > > -        // Extract the offsets of the device name, address dword and the slot
> > > -        // name byte - we fill them in for each device.
> > > -        Device(SCC) {
> > > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcivga_adr
> > > -            Name(_ADR, 0xAA0000)
> > > -            Method(_S1D, 0, NotSerialized) {
> > > -                Return (0x00)
> > > -            }
> > > -            Method(_S2D, 0, NotSerialized) {
> > > -                Return (0x00)
> > > -            }
> > > -            Method(_S3D, 0, NotSerialized) {
> > > -                Return (0x00)
> > > -            }
> > > -        }
> > > -
> > > -        ACPI_EXTRACT_DEVICE_START ssdt_pciqxl_start
> > > -        ACPI_EXTRACT_DEVICE_END ssdt_pciqxl_end
> > > -        ACPI_EXTRACT_DEVICE_STRING ssdt_pciqxl_name
> > > -
> > > -        // Extract the offsets of the device name, address dword and the slot
> > > -        // name byte - we fill them in for each device.
> > > -        Device(SDD) {
> > > -            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pciqxl_adr
> > > -            Name(_ADR, 0xAA0000)
> > > -            Method(_S1D, 0, NotSerialized) {
> > > -                Return (0x00)
> > > -            }
> > > -            Method(_S2D, 0, NotSerialized) {
> > > -                Return (0x00)
> > > -            }
> > > -            Method(_S3D, 0, NotSerialized) {
> > > -                Return (0x03)           // QXL
> > > -            }
> > > -        }
> > > -    }
> > > -}
> > > diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
> > > deleted file mode 100644
> > > index 72ffa84..0000000
> > > --- a/hw/i386/ssdt-pcihp.hex.generated
> > 
> > Pls don't send generated file patches.
> > Just note it should be removed in comment, I'll do it.
> > 
> > > +++ /dev/null
> > > @@ -1,251 +0,0 @@
> > > -static unsigned char ssdt_pcihp_name[] = {
> > > -0x34
> > > -};
> > > -static unsigned char ssdt_pcivga_end[] = {
> > > -0x99
> > > -};
> > > -static unsigned char ssdt_pcivga_name[] = {
> > > -0x70
> > > -};
> > > -static unsigned char ssdt_pcihp_adr[] = {
> > > -0x45
> > > -};
> > > -static unsigned char ssdt_pcinohp_end[] = {
> > > -0x6d
> > > -};
> > > -static unsigned char ssdt_pcihp_end[] = {
> > > -0x5c
> > > -};
> > > -static unsigned char ssdt_pciqxl_start[] = {
> > > -0x99
> > > -};
> > > -static unsigned char ssdt_pcinohp_name[] = {
> > > -0x5f
> > > -};
> > > -static unsigned char ssdp_pcihp_aml[] = {
> > > -0x53,
> > > -0x53,
> > > -0x44,
> > > -0x54,
> > > -0xc6,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x1,
> > > -0x70,
> > > -0x42,
> > > -0x58,
> > > -0x50,
> > > -0x43,
> > > -0x0,
> > > -0x0,
> > > -0x42,
> > > -0x58,
> > > -0x53,
> > > -0x53,
> > > -0x44,
> > > -0x54,
> > > -0x50,
> > > -0x43,
> > > -0x1,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x49,
> > > -0x4e,
> > > -0x54,
> > > -0x4c,
> > > -0x15,
> > > -0x11,
> > > -0x13,
> > > -0x20,
> > > -0x10,
> > > -0x41,
> > > -0xa,
> > > -0x5c,
> > > -0x2e,
> > > -0x5f,
> > > -0x53,
> > > -0x42,
> > > -0x5f,
> > > -0x50,
> > > -0x43,
> > > -0x49,
> > > -0x30,
> > > -0x5b,
> > > -0x82,
> > > -0x29,
> > > -0x53,
> > > -0x41,
> > > -0x41,
> > > -0x5f,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x55,
> > > -0x4e,
> > > -0xa,
> > > -0xaa,
> > > -0x8,
> > > -0x5f,
> > > -0x41,
> > > -0x44,
> > > -0x52,
> > > -0xc,
> > > -0x0,
> > > -0x0,
> > > -0xaa,
> > > -0x0,
> > > -0x14,
> > > -0x12,
> > > -0x5f,
> > > -0x45,
> > > -0x4a,
> > > -0x30,
> > > -0x1,
> > > -0x50,
> > > -0x43,
> > > -0x45,
> > > -0x4a,
> > > -0x42,
> > > -0x53,
> > > -0x45,
> > > -0x4c,
> > > -0x5f,
> > > -0x53,
> > > -0x55,
> > > -0x4e,
> > > -0x5b,
> > > -0x82,
> > > -0xf,
> > > -0x53,
> > > -0x42,
> > > -0x42,
> > > -0x5f,
> > > -0x8,
> > > -0x5f,
> > > -0x41,
> > > -0x44,
> > > -0x52,
> > > -0xc,
> > > -0x0,
> > > -0x0,
> > > -0xaa,
> > > -0x0,
> > > -0x5b,
> > > -0x82,
> > > -0x2a,
> > > -0x53,
> > > -0x43,
> > > -0x43,
> > > -0x5f,
> > > -0x8,
> > > -0x5f,
> > > -0x41,
> > > -0x44,
> > > -0x52,
> > > -0xc,
> > > -0x0,
> > > -0x0,
> > > -0xaa,
> > > -0x0,
> > > -0x14,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x31,
> > > -0x44,
> > > -0x0,
> > > -0xa4,
> > > -0x0,
> > > -0x14,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x32,
> > > -0x44,
> > > -0x0,
> > > -0xa4,
> > > -0x0,
> > > -0x14,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x33,
> > > -0x44,
> > > -0x0,
> > > -0xa4,
> > > -0x0,
> > > -0x5b,
> > > -0x82,
> > > -0x2b,
> > > -0x53,
> > > -0x44,
> > > -0x44,
> > > -0x5f,
> > > -0x8,
> > > -0x5f,
> > > -0x41,
> > > -0x44,
> > > -0x52,
> > > -0xc,
> > > -0x0,
> > > -0x0,
> > > -0xaa,
> > > -0x0,
> > > -0x14,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x31,
> > > -0x44,
> > > -0x0,
> > > -0xa4,
> > > -0x0,
> > > -0x14,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x32,
> > > -0x44,
> > > -0x0,
> > > -0xa4,
> > > -0x0,
> > > -0x14,
> > > -0x9,
> > > -0x5f,
> > > -0x53,
> > > -0x33,
> > > -0x44,
> > > -0x0,
> > > -0xa4,
> > > -0xa,
> > > -0x3
> > > -};
> > > -static unsigned char ssdt_pciqxl_adr[] = {
> > > -0xa6
> > > -};
> > > -static unsigned char ssdt_pcinohp_adr[] = {
> > > -0x69
> > > -};
> > > -static unsigned char ssdt_pcivga_adr[] = {
> > > -0x7a
> > > -};
> > > -static unsigned char ssdt_pciqxl_name[] = {
> > > -0x9c
> > > -};
> > > -static unsigned char ssdt_pcivga_start[] = {
> > > -0x6d
> > > -};
> > > -static unsigned char ssdt_pciqxl_end[] = {
> > > -0xc6
> > > -};
> > > -static unsigned char ssdt_pcihp_start[] = {
> > > -0x31
> > > -};
> > > -static unsigned char ssdt_pcihp_id[] = {
> > > -0x3e
> > > -};
> > > -static unsigned char ssdt_pcinohp_start[] = {
> > > -0x5c
> > > -};
> > > -- 
> > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table
  2015-02-18  9:57     ` Igor Mammedov
@ 2015-02-18 11:39       ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 11:39 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Wed, Feb 18, 2015 at 10:57:18AM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 17:42:00 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:53:28AM +0000, Igor Mammedov wrote:
> > > it replaces prebuilt SSDT table header template copying/patching
> > > with AML API
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > 
> > I note that this changed the SSDT signature in random ways,
> > for example, it used to be named BXPCSSDT, now it's BXPC.
> > 
> > Pls keep using build_header, this problem will go away then.
> [...]
> > > +    /* Init SSDT Definition Block */
> > > +    ssdt = aml_def_block("SSDT", 1, ACPI_BUILD_APPNAME6,
> > > +                         ACPI_BUILD_APPNAME4, 1,
> I've missed that build_header() composes oem_table_id implicitly
> by merging table signature and ACPI_BUILD_APPNAME4.
> 
> following should fix issue:
> -                         ACPI_BUILD_APPNAME4, 1,
> +                         "BXPCSSDT", 1,

True but that's the result of code duplication.

Let's reuse build_header at step 1,
and in step 2, we'll replace it with something
else everywhere.

> > > +                         ACPI_BUILD_APPNAME4_HEX, 1);

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

* Re: [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  2015-02-18 10:03     ` Igor Mammedov
@ 2015-02-18 12:41       ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 12:41 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Wed, Feb 18, 2015 at 11:03:47AM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 17:41:03 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:53:45AM +0000, Igor Mammedov wrote:
> > > QEMU doesn't implement/advertize PM1b_CNT_BLK
> > > register block so do not set/patch its \_Sx
> > > values to avoid confusion.
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > 
> > I doubt guests are confused.
> They just happen to ignore it, it doesn't mean that it's correct
> 
> > I think you mean this confuses you, but I'd rather stay
> > bug for bug compatible with what we did historically.
> > We probably should add a comment saying this is here
> > for historical reasons, but let's get your patchset
> > merged first, it's too big as is.
> I don't see point in being bug compatible in this case.

yes but don't make unrelated changes part of this series.
it's too big already.

> > 
> > 
> > > ---
> > >  hw/i386/acpi-build.c  | 3 +--
> > >  hw/i386/ssdt-misc.dsl | 4 ++--
> > >  2 files changed, 3 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index b6626f5..7cc564a 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,
> > >      if (pm->s4_disabled) {
> > >          ssdt_ptr[acpi_s4_name[0]] = 'X';
> > >      } else {
> > > -        ssdt_ptr[acpi_s4_pkg[0] + 1] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
> > > -            pm->s4_val;
> > > +        ssdt_ptr[acpi_s4_pkg[0] + 1] = pm->s4_val;
> > >      }
> > >  
> > >      patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
> > > diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> > > index 1e3baae..96382a6 100644
> > > --- a/hw/i386/ssdt-misc.dsl
> > > +++ b/hw/i386/ssdt-misc.dsl
> > > @@ -54,7 +54,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
> > >          ACPI_EXTRACT_NAME_STRING acpi_s3_name
> > >          Name(_S3, Package(0x04) {
> > >              One,  /* PM1a_CNT.SLP_TYP */
> > > -            One,  /* PM1b_CNT.SLP_TYP */
> > > +            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
> > >              Zero,  /* reserved */
> > >              Zero   /* reserved */
> > >          })
> > > @@ -62,7 +62,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
> > >          ACPI_EXTRACT_PKG_START acpi_s4_pkg
> > >          Name(_S4, Package(0x04) {
> > >              0x2,  /* PM1a_CNT.SLP_TYP */
> > > -            0x2,  /* PM1b_CNT.SLP_TYP */
> > > +            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
> > >              Zero,  /* reserved */
> > >              Zero   /* reserved */
> > >          })
> > > -- 
> > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
  2015-02-18 10:09     ` Igor Mammedov
@ 2015-02-18 13:13       ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 13:13 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Wed, Feb 18, 2015 at 11:09:04AM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 17:44:31 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:54:09AM +0000, Igor Mammedov wrote:
> > > It completes dynamic SSDT generation and makes it
> > > independed of IASL binary blobs. It also hides
> > > from user all pointer arithmetic when building
> > > SSDT which makes resulting code a bit cleaner
> > > and concentrating only on composing ASL construct
> > > /i.e. a task build_ssdt() should be doing/.
> > > 
> > > Also it makes one binary blob less stored in QEMU
> > > source tree by removing need to keep and update
> > > hw/i386/ssdt-misc.hex.generated file here in total
> > > saving us ~430LOC.
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > 
> > 
> > I see where we drop ssdt_misc here but I don't see
> > acpi_def_block anywhere.
> that's been introduced when conversion began in patch:
> [6/52] pc: acpi-build: use aml_def_block() for declaring SSDT table"
> 

OK, the description is confusing. just say dsl is now empty.


> > Also pls don't include generated files in patches,
> > they just make rebases painful.
> > just say in commit log they need to be updated.
> sure
> 
> > 
> > > ---
> > >  hw/i386/Makefile.objs           |   2 +-
> > >  hw/i386/acpi-build.c            |  12 --
> > >  hw/i386/ssdt-misc.dsl           |  21 ---
> > >  hw/i386/ssdt-misc.hex.generated | 399 ----------------------------------------
> > >  4 files changed, 1 insertion(+), 433 deletions(-)
> > >  delete mode 100644 hw/i386/ssdt-misc.dsl
> > >  delete mode 100644 hw/i386/ssdt-misc.hex.generated
> > > 
> > > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> > > index 6c8705d..dc8c38a 100644
> > > --- a/hw/i386/Makefile.objs
> > > +++ b/hw/i386/Makefile.objs
> > > @@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
> > >  obj-y += kvmvapic.o
> > >  obj-y += acpi-build.o
> > >  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> > > -	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> > > +	hw/i386/q35-acpi-dsdt.hex \
> > >  	hw/i386/ssdt-tpm.hex
> > >  
> > >  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index bead77e..14c1c7d 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
> > >                   table_data->len - madt_start, 1);
> > >  }
> > >  
> > > -#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
> > > -#define ACPI_SSDT_HEADER_LENGTH 36
> > > -
> > > -#include "hw/i386/ssdt-misc.hex"
> > >  #include "hw/i386/ssdt-tpm.hex"
> > >  
> > >  /* Assign BSEL property to all buses.  In the future, this can be changed
> > > @@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,
> > >      MachineState *machine = MACHINE(qdev_get_machine());
> > >      uint32_t nr_mem = machine->ram_slots;
> > >      unsigned acpi_cpus = guest_info->apic_id_limit;
> > > -    uint8_t *ssdt_ptr;
> > >      Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
> > >      int i;
> > >  
> > > @@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,
> > >                           ACPI_BUILD_APPNAME4, 1,
> > >                           ACPI_BUILD_APPNAME4_HEX, 1);
> > >  
> > > -    /* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
> > > -    acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
> > > -    ssdt_ptr = (uint8_t *)ssdt->buf->data;
> > > -    memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
> > > -           ssdp_misc_aml + sizeof(AcpiTableHeader),
> > > -           sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
> > > -
> > >      scope = aml_scope("\\_SB.PCI0");
> > >      /* build PCI0._CRS */
> > >      crs = aml_resource_template();
> > 
> > So before this patch, we had two headers?
> > I don't see how this makes sense, and it does not
> > match commit log.
> nope, see
> [6/52] pc: acpi-build: use aml_def_block() for declaring SSDT table"
> where header from template is skipped and only content is copied

Pls squash this chunk there then.


> > 
> > 
> > > diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> > > deleted file mode 100644
> > > index 8d61f21..0000000
> > > --- a/hw/i386/ssdt-misc.dsl
> > > +++ /dev/null
> > > @@ -1,21 +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 "hw/acpi/pc-hotplug.h"
> > > -
> > > -ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
> > > -
> > > -DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
> > > -{
> > > -}
> > > diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
> > > deleted file mode 100644
> > > index cbcf61d..0000000
> > > --- a/hw/i386/ssdt-misc.hex.generated
> > > +++ /dev/null
> > > @@ -1,399 +0,0 @@
> > > -static unsigned char acpi_pci64_length[] = {
> > > -0x6f
> > > -};
> > > -static unsigned char acpi_s4_pkg[] = {
> > > -0x99
> > > -};
> > > -static unsigned char ssdt_mctrl_nr_slots[] = {
> > > -0x7d
> > > -};
> > > -static unsigned char acpi_s3_name[] = {
> > > -0x86
> > > -};
> > > -static unsigned char acpi_pci32_start[] = {
> > > -0x2f
> > > -};
> > > -static unsigned char acpi_pci64_valid[] = {
> > > -0x43
> > > -};
> > > -static unsigned char ssdp_misc_aml[] = {
> > > -0x53,
> > > -0x53,
> > > -0x44,
> > > -0x54,
> > > -0x6c,
> > > -0x1,
> > > -0x0,
> > > -0x0,
> > > -0x1,
> > > -0x3,
> > > -0x42,
> > > -0x58,
> > > -0x50,
> > > -0x43,
> > > -0x0,
> > > -0x0,
> > > -0x42,
> > > -0x58,
> > > -0x53,
> > > -0x53,
> > > -0x44,
> > > -0x54,
> > > -0x53,
> > > -0x55,
> > > -0x1,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x49,
> > > -0x4e,
> > > -0x54,
> > > -0x4c,
> > > -0x28,
> > > -0x8,
> > > -0x14,
> > > -0x20,
> > > -0x10,
> > > -0x4c,
> > > -0x5,
> > > -0x5c,
> > > -0x0,
> > > -0x8,
> > > -0x50,
> > > -0x30,
> > > -0x53,
> > > -0x5f,
> > > -0xc,
> > > -0x78,
> > > -0x56,
> > > -0x34,
> > > -0x12,
> > > -0x8,
> > > -0x50,
> > > -0x30,
> > > -0x45,
> > > -0x5f,
> > > -0xc,
> > > -0x78,
> > > -0x56,
> > > -0x34,
> > > -0x12,
> > > -0x8,
> > > -0x50,
> > > -0x31,
> > > -0x56,
> > > -0x5f,
> > > -0xa,
> > > -0x12,
> > > -0x8,
> > > -0x50,
> > > -0x31,
> > > -0x53,
> > > -0x5f,
> > > -0x11,
> > > -0xb,
> > > -0xa,
> > > -0x8,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x8,
> > > -0x50,
> > > -0x31,
> > > -0x45,
> > > -0x5f,
> > > -0x11,
> > > -0xb,
> > > -0xa,
> > > -0x8,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x8,
> > > -0x50,
> > > -0x31,
> > > -0x4c,
> > > -0x5f,
> > > -0x11,
> > > -0xb,
> > > -0xa,
> > > -0x8,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x8,
> > > -0x4d,
> > > -0x44,
> > > -0x4e,
> > > -0x52,
> > > -0xc,
> > > -0x78,
> > > -0x56,
> > > -0x34,
> > > -0x12,
> > > -0x10,
> > > -0x29,
> > > -0x5c,
> > > -0x0,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x33,
> > > -0x5f,
> > > -0x12,
> > > -0x6,
> > > -0x4,
> > > -0x1,
> > > -0x1,
> > > -0x0,
> > > -0x0,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x34,
> > > -0x5f,
> > > -0x12,
> > > -0x8,
> > > -0x4,
> > > -0xa,
> > > -0x2,
> > > -0xa,
> > > -0x2,
> > > -0x0,
> > > -0x0,
> > > -0x8,
> > > -0x5f,
> > > -0x53,
> > > -0x35,
> > > -0x5f,
> > > -0x12,
> > > -0x6,
> > > -0x4,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x10,
> > > -0x40,
> > > -0xc,
> > > -0x5c,
> > > -0x2f,
> > > -0x3,
> > > -0x5f,
> > > -0x53,
> > > -0x42,
> > > -0x5f,
> > > -0x50,
> > > -0x43,
> > > -0x49,
> > > -0x30,
> > > -0x49,
> > > -0x53,
> > > -0x41,
> > > -0x5f,
> > > -0x5b,
> > > -0x82,
> > > -0x4d,
> > > -0xa,
> > > -0x50,
> > > -0x45,
> > > -0x56,
> > > -0x54,
> > > -0x8,
> > > -0x5f,
> > > -0x48,
> > > -0x49,
> > > -0x44,
> > > -0xd,
> > > -0x51,
> > > -0x45,
> > > -0x4d,
> > > -0x55,
> > > -0x30,
> > > -0x30,
> > > -0x30,
> > > -0x31,
> > > -0x0,
> > > -0x8,
> > > -0x50,
> > > -0x45,
> > > -0x53,
> > > -0x54,
> > > -0xb,
> > > -0xff,
> > > -0xff,
> > > -0x5b,
> > > -0x80,
> > > -0x50,
> > > -0x45,
> > > -0x4f,
> > > -0x52,
> > > -0x1,
> > > -0x50,
> > > -0x45,
> > > -0x53,
> > > -0x54,
> > > -0x1,
> > > -0x5b,
> > > -0x81,
> > > -0xb,
> > > -0x50,
> > > -0x45,
> > > -0x4f,
> > > -0x52,
> > > -0x1,
> > > -0x50,
> > > -0x45,
> > > -0x50,
> > > -0x54,
> > > -0x8,
> > > -0x14,
> > > -0x18,
> > > -0x5f,
> > > -0x53,
> > > -0x54,
> > > -0x41,
> > > -0x0,
> > > -0x70,
> > > -0x50,
> > > -0x45,
> > > -0x53,
> > > -0x54,
> > > -0x60,
> > > -0xa0,
> > > -0x6,
> > > -0x93,
> > > -0x60,
> > > -0x0,
> > > -0xa4,
> > > -0x0,
> > > -0xa1,
> > > -0x4,
> > > -0xa4,
> > > -0xa,
> > > -0xf,
> > > -0x14,
> > > -0xe,
> > > -0x52,
> > > -0x44,
> > > -0x50,
> > > -0x54,
> > > -0x0,
> > > -0x70,
> > > -0x50,
> > > -0x45,
> > > -0x50,
> > > -0x54,
> > > -0x60,
> > > -0xa4,
> > > -0x60,
> > > -0x14,
> > > -0xc,
> > > -0x57,
> > > -0x52,
> > > -0x50,
> > > -0x54,
> > > -0x1,
> > > -0x70,
> > > -0x68,
> > > -0x50,
> > > -0x45,
> > > -0x50,
> > > -0x54,
> > > -0x8,
> > > -0x5f,
> > > -0x43,
> > > -0x52,
> > > -0x53,
> > > -0x11,
> > > -0xd,
> > > -0xa,
> > > -0xa,
> > > -0x47,
> > > -0x1,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x0,
> > > -0x1,
> > > -0x1,
> > > -0x79,
> > > -0x0,
> > > -0x8b,
> > > -0x5f,
> > > -0x43,
> > > -0x52,
> > > -0x53,
> > > -0xa,
> > > -0x2,
> > > -0x49,
> > > -0x4f,
> > > -0x4d,
> > > -0x4e,
> > > -0x8b,
> > > -0x5f,
> > > -0x43,
> > > -0x52,
> > > -0x53,
> > > -0xa,
> > > -0x4,
> > > -0x49,
> > > -0x4f,
> > > -0x4d,
> > > -0x58,
> > > -0x14,
> > > -0x18,
> > > -0x5f,
> > > -0x49,
> > > -0x4e,
> > > -0x49,
> > > -0x0,
> > > -0x70,
> > > -0x50,
> > > -0x45,
> > > -0x53,
> > > -0x54,
> > > -0x49,
> > > -0x4f,
> > > -0x4d,
> > > -0x4e,
> > > -0x70,
> > > -0x50,
> > > -0x45,
> > > -0x53,
> > > -0x54,
> > > -0x49,
> > > -0x4f,
> > > -0x4d,
> > > -0x58
> > > -};
> > > -static unsigned char ssdt_isa_pest[] = {
> > > -0xda
> > > -};
> > > -static unsigned char acpi_s4_name[] = {
> > > -0x92
> > > -};
> > > -static unsigned char acpi_pci64_start[] = {
> > > -0x4d
> > > -};
> > > -static unsigned char acpi_pci64_end[] = {
> > > -0x5e
> > > -};
> > > -static unsigned char acpi_pci32_end[] = {
> > > -0x39
> > > -};
> > > -- 
> > > 1.8.3.1

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

* Re: [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()
  2015-02-18  9:41     ` Igor Mammedov
@ 2015-02-18 13:51       ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 13:51 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: drjones, marcel.a, claudio.fontana, qemu-devel, zhaoshenglong

On Wed, Feb 18, 2015 at 10:41:23AM +0100, Igor Mammedov wrote:
> On Tue, 17 Feb 2015 20:53:52 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Mon, Feb 09, 2015 at 10:53:26AM +0000, Igor Mammedov wrote:
> > > it will be reused for adding a plain integer value into AML.
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > >  hw/acpi/aml-build.c  | 19 +++----------------
> > >  hw/i386/acpi-build.c |  6 +++---
> > >  2 files changed, 6 insertions(+), 19 deletions(-)
> > > 
> > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > > index 096f347..67d1371 100644
> > > --- a/hw/acpi/aml-build.c
> > > +++ b/hw/acpi/aml-build.c
> > > @@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)
> > >  
> > >  void build_append_value(GArray *table, uint32_t value, int size)
> > >  {
> > > -    uint8_t prefix;
> > >      int i;
> > >  
> > > -    switch (size) {
> > > -    case 1:
> > > -        prefix = 0x0A; /* BytePrefix */
> > > -        break;
> > > -    case 2:
> > > -        prefix = 0x0B; /* WordPrefix */
> > > -        break;
> > > -    case 4:
> > > -        prefix = 0x0C; /* DWordPrefix */
> > > -        break;
> > > -    default:
> > > -        assert(0);
> > > -        return;
> > > -    }
> > > -    build_append_byte(table, prefix);
> > >      for (i = 0; i < size; ++i) {
> > >          build_append_byte(table, value & 0xFF);
> > >          value = value >> 8;
> > 
> > This really makes this an awkward API,
> > you must remember to add the prefix.
> it's internal helper for adding plain values,
> it's not intended for using outside aml-build.c
> I should have marked it as static.
> 
> [...]
> > then call build_append_value_noprefix from build_append_value.
> lets rename it to build_append_int_noprefix as int is less vague then value
> and leave prefixed part as it's /i.e. build_append_int()/
> 
> 
> > 
> > But really, it's best to squash such changes with
> > where they are used, it's just making review harder:
> > as you add APIs with no documentation, I can't
> > see what they do without reading follow up patch
> > to see how they are used.
> It's split out to make the rest of patches more review-able
> if I drop aml_def_block() patch then this patch might be squashed with:
> "acpi: extend build_append_{value|int}() to support 64-bit values"
> "acpi: add aml_int() term"
> and that might be squashed into already huge patch
> "pc: acpi-build: drop template patching and create PCI bus tree dynamically"
> 
> Squashing 3 different changes into a bigger patch doesn't make review any
> easier and squashing that into 4th conversion patch makes it even worse.

ok

> > 
> > 
> > > @@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value)
> > >      } else if (value == 0x01) {
> > >          build_append_byte(table, 0x01); /* OneOp */
> > >      } else if (value <= 0xFF) {
> > > +        build_append_byte(table, 0x0A); /* BytePrefix */
> > >          build_append_value(table, value, 1);
> > >      } else if (value <= 0xFFFF) {
> > > +        build_append_byte(table, 0x0B); /* WordPrefix */
> > >          build_append_value(table, value, 2);
> > >      } else {
> > > +        build_append_byte(table, 0x0C); /* DWordPrefix */
> > >          build_append_value(table, value, 4);
> > >      }
> > >  }
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index 788962e..a1bf450 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)
> > >  
> > >  static void build_append_notify_target_ifequal(GArray *method,
> > >                                                 GArray *target_name,
> > > -                                               uint32_t value, int size)
> > > +                                               uint32_t value)
> > >  {
> > >      GArray *notify = build_alloc_array();
> > >      uint8_t op = 0xA0; /* IfOp */
> > >  
> > >      build_append_byte(notify, 0x93); /* LEqualOp */
> > >      build_append_byte(notify, 0x68); /* Arg0Op */
> > > -    build_append_value(notify, value, size);
> > > +    build_append_int(notify, value);
> > >      build_append_byte(notify, 0x86); /* NotifyOp */
> > >      build_append_array(notify, target_name);
> > >      build_append_byte(notify, 0x69); /* Arg1Op */
> > > @@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,
> > >          GArray *target = build_alloc_array();
> > >          build_append_namestring(target, format, i);
> > >          assert(i < 256); /* Fits in 1 byte */
> > > -        build_append_notify_target_ifequal(method, target, i, 1);
> > > +        build_append_notify_target_ifequal(method, target, i);
> > >          build_free_array(target);
> > >      }
> > >  
> > > -- 
> > > 1.8.3.1

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

end of thread, other threads:[~2015-02-18 13:51 UTC | newest]

Thread overview: 89+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-09 10:53 [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append() Igor Mammedov
2015-02-17 16:26   ` Michael S. Tsirkin
2015-02-17 17:50     ` Igor Mammedov
2015-02-17 19:12       ` Michael S. Tsirkin
2015-02-17 19:46   ` Michael S. Tsirkin
2015-02-18  8:50     ` Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 02/52] pc: acpi: use local var for accessing ACPI tables blob in acpi_build() Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 03/52] pc: acpi: make top level ACPI tables blob Aml* Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value() Igor Mammedov
2015-02-17 19:53   ` Michael S. Tsirkin
2015-02-18  9:41     ` Igor Mammedov
2015-02-18 13:51       ` Michael S. Tsirkin
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term Igor Mammedov
2015-02-17 16:35   ` Michael S. Tsirkin
2015-02-17 16:47     ` Igor Mammedov
2015-02-17 19:03       ` Michael S. Tsirkin
2015-02-18 10:47         ` Igor Mammedov
2015-02-18 11:36           ` Michael S. Tsirkin
2015-02-17 19:15       ` Michael S. Tsirkin
2015-02-18  9:50         ` Igor Mammedov
2015-02-18 11:35           ` Michael S. Tsirkin
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table Igor Mammedov
2015-02-17 16:42   ` Michael S. Tsirkin
2015-02-18  9:57     ` Igor Mammedov
2015-02-18 11:39       ` Michael S. Tsirkin
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 07/52] acpi: add aml_scope() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 08/52] pc: acpi-build: use aml_scope() for \_SB scope Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 09/52] acpi: add aml_device() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 10/52] acpi: add aml_method() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 11/52] acpi: add aml_if() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 12/52] acpi: add aml_name() & aml_name_decl() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 13/52] acpi: extend build_append_{value|int}() to support 64-bit values Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 14/52] acpi: add aml_int() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 15/52] acpi: add aml_return() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 16/52] acpi: add aml_arg() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 17/52] acpi: add aml_store() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 18/52] acpi: add aml_and() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 19/52] acpi: add aml_notify() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 20/52] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically Igor Mammedov
2015-02-17 19:39   ` Michael S. Tsirkin
2015-02-18 10:00     ` Igor Mammedov
2015-02-18 10:42     ` Igor Mammedov
2015-02-18 11:38       ` Michael S. Tsirkin
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 22/52] acpi: add aml_package() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP Igor Mammedov
2015-02-17 16:41   ` Michael S. Tsirkin
2015-02-18 10:03     ` Igor Mammedov
2015-02-18 12:41       ` Michael S. Tsirkin
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 24/52] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 25/52] acpi: add aml_buffer() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 26/52] acpi: add aml_resource_template() helper Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 27/52] acpi: add aml_io() helper Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 28/52] acpi: include PkgLength size only when requested Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 29/52] acpi: add aml_operation_region() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 30/52] acpi: add aml_field() & aml_named_field() terms Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term Igor Mammedov
2015-02-17 12:18   ` Michael S. Tsirkin
2015-02-17 14:06     ` Igor Mammedov
2015-02-17 14:24   ` [Qemu-devel] [PATCH v3 31/52] fixup! " Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 32/52] acpi: add aml_string() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 33/52] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 34/52] acpi: add aml_varpackage() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 35/52] acpi: add aml_equal() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 36/52] acpi: add aml_processor() term Igor Mammedov
2015-02-09 10:53 ` [Qemu-devel] [PATCH v3 37/52] acpi: add aml_eisaid() term Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 38/52] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 39/52] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 40/52] acpi: add aml_reserved_field() term Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 41/52] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 42/52] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 43/52] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 44/52] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 45/52] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 46/52] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block() Igor Mammedov
2015-02-17 16:44   ` Michael S. Tsirkin
2015-02-18 10:09     ` Igor Mammedov
2015-02-18 13:13       ` Michael S. Tsirkin
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 48/52] acpi: add acpi_irq_no_flags() term Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 49/52] pc: export applesmc IO port/len Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 50/52] pc: acpi-build: drop template patching and create Device(SMC) dynamically Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 51/52] pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC Igor Mammedov
2015-02-09 10:54 ` [Qemu-devel] [PATCH v3 52/52] acpi: make build_*() routines static to aml-build.c Igor Mammedov
2015-02-17 16:47 ` [Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API Michael S. Tsirkin
2015-02-17 17:51   ` Igor Mammedov
2015-02-17 19:14     ` Michael S. Tsirkin
2015-02-18 10:35       ` 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.