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

changes since v3:
 * drop acpi_def_block() for now
 * exclude PCI refactoring
 * minor ammends as requested on list
 * not much tested, but XP boots.

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_v4



Igor Mammedov (42):
  acpi: introduce AML composer aml_append()
  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: 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
  acpi: add aml_package() term
  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
  acpi: add acpi_irq_no_flags() term
  pc: export applesmc IO port/len
  pc: acpi-build: drop template patching and create Device(SMC)
    dynamically

 hw/acpi/aml-build.c               | 681 ++++++++++++++++++++++++++++++++++++--
 hw/acpi/pcihp.c                   |  18 +-
 hw/acpi/piix4.c                   |   2 +-
 hw/i386/Makefile.objs             |   5 +-
 hw/i386/acpi-build.c              | 503 ++++++++++++++++++----------
 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/q35-acpi-dsdt.dsl         |  19 --
 hw/i386/ssdt-mem.dsl              |  77 -----
 hw/i386/ssdt-misc.dsl             | 122 -------
 hw/i386/ssdt-proc.dsl             |  63 ----
 hw/misc/applesmc.c                |   5 +-
 include/hw/acpi/aml-build.h       | 190 ++++++++++-
 include/hw/acpi/pc-hotplug.h      |   1 +
 include/hw/acpi/pcihp.h           |   7 +-
 include/hw/isa/isa.h              |  11 +-
 19 files changed, 1205 insertions(+), 701 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-misc.dsl
 delete mode 100644 hw/i386/ssdt-proc.dsl

-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 01/42] acpi: introduce AML composer aml_append()
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 02/42] acpi: add aml_scope() term Igor Mammedov
                   ` (40 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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         | 78 +++++++++++++++++++++++++++++++++++++++++++++
 include/hw/acpi/aml-build.h | 55 ++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index bcb288e..caf792b 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -25,6 +25,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include "hw/acpi/aml-build.h"
+#include "qemu/bswap.h"
 
 GArray *build_alloc_array(void)
 {
@@ -257,3 +258,80 @@ 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_NO_OPCODE;
+    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(void)
+{
+    Aml *var;
+
+    assert(!alloc_list);
+    alloc_list = g_ptr_array_new_with_free_func(aml_free);
+    var = aml_alloc();
+    return var;
+}
+
+void free_aml_allocator(void)
+{
+    g_ptr_array_free(alloc_list, true);
+    alloc_list = 0;
+}
+
+/* pack data with DefBuffer encoding */
+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_OPCODE:
+        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 are treated as succeeded if checksum
+         * field is zero. [ACPI Spec 1.0b, 6.4.2.8 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_NO_OPCODE:
+        break;
+    default:
+        assert(0);
+        break;
+    }
+    build_append_array(parent_ctx->buf, child->buf);
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 199f003..1e1b03b 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -5,6 +5,61 @@
 #include <glib.h>
 #include "qemu/compiler.h"
 
+typedef enum {
+    AML_NO_OPCODE = 0,/* has only data */
+    AML_OPCODE,       /* has opcode optionally followed by data */
+    AML_PACKAGE,      /* has opcode and uses PkgLength for its length */
+    AML_EXT_PACKAGE,  /* ame as AML_PACKAGE but also has 'ExOpPrefix' */
+    AML_BUFFER,       /* data encoded as 'DefBuffer' */
+    AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */
+} AmlBlockFlags;
+
+struct Aml {
+    GArray *buf;
+
+    /*< private >*/
+    uint8_t op;
+    AmlBlockFlags block_flags;
+};
+typedef struct Aml Aml;
+
+/**
+ * init_aml_allocator:
+ *
+ * Called for initializing API allocator which allow to use
+ * AML API.
+ * Returns: toplevel container which accumulates all other
+ * AML elements for a table.
+ */
+Aml *init_aml_allocator(void);
+
+/**
+ * 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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 02/42] acpi: add aml_scope() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 01/42] acpi: introduce AML composer aml_append() Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 03/42] pc: acpi-build: use aml_scope() for \_SB scope Igor Mammedov
                   ` (39 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index caf792b..f891406 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -271,6 +271,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;
@@ -335,3 +344,14 @@ void aml_append(Aml *parent_ctx, Aml *child)
     }
     build_append_array(parent_ctx->buf, child->buf);
 }
+
+/* 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 1e1b03b..05dd3fc 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -59,6 +59,9 @@ void free_aml_allocator(void);
  */
 void aml_append(Aml *parent_ctx, Aml *child);
 
+/* Block AML object primitives */
+Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+
 /* other helpers */
 GArray *build_alloc_array(void);
 void build_free_array(GArray *array);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 03/42] pc: acpi-build: use aml_scope() for \_SB scope
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 01/42] acpi: introduce AML composer aml_append() Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 02/42] acpi: add aml_scope() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 04/42] acpi: add aml_device() term Igor Mammedov
                   ` (38 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

prepares for incremental conversion of SSDT content to AML API

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

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 5e4b333..c66fe56 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -923,17 +923,18 @@ build_ssdt(GArray *table_data, GArray *linker,
     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, *sb_scope;
     int i;
 
+    ssdt = init_aml_allocator();
     /* The current AML generator can cover the APIC ID range [0..255],
      * inclusive, for VCPU hotplug. */
     QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256);
     g_assert(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));
+    ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
     memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
     if (pm->s3_disabled) {
         ssdt_ptr[acpi_s3_name[0]] = 'X';
@@ -953,15 +954,11 @@ build_ssdt(GArray *table_data, GArray *linker,
     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);
@@ -973,11 +970,12 @@ build_ssdt(GArray *table_data, GArray *linker,
          *   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();
@@ -1002,7 +1000,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             }
 
             build_package(package, op);
-            build_append_array(sb_scope, package);
+            build_append_array(sb_scope->buf, package);
             build_free_array(package);
         }
 
@@ -1011,7 +1009,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             /* 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);
@@ -1022,7 +1020,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             /* 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);
         }
@@ -1046,17 +1044,18 @@ build_ssdt(GArray *table_data, GArray *linker,
                                              build_pci_bus_end, &hotplug_state);
             }
 
-            build_append_array(sb_scope, hotplug_state.device_table);
+            build_append_array(sb_scope->buf, hotplug_state.device_table);
             build_pci_bus_state_cleanup(&hotplug_state);
         }
-        build_package(sb_scope, op);
-        build_append_array(table_data, sb_scope);
-        build_free_array(sb_scope);
+        aml_append(ssdt, sb_scope);
     }
 
+    /* copy AML table into ACPI tables blob and patch header there */
+    g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
     build_header(linker, table_data,
-                 (void *)(table_data->data + ssdt_start),
-                 "SSDT", table_data->len - ssdt_start, 1);
+        (void *)(table_data->data + table_data->len - ssdt->buf->len),
+        "SSDT", ssdt->buf->len, 1);
+    free_aml_allocator();
 }
 
 static void
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 04/42] acpi: add aml_device() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (2 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 03/42] pc: acpi-build: use aml_scope() for \_SB scope Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 05/42] acpi: add aml_method() term Igor Mammedov
                   ` (37 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 f891406..c955d66 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -355,3 +355,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 05dd3fc..004fa05 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -61,6 +61,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 
 /* Block AML object primitives */
 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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 05/42] acpi: add aml_method() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (3 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 04/42] acpi: add aml_device() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 06/42] acpi: add aml_if() term Igor Mammedov
                   ` (36 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 c955d66..4e0685e 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -356,6 +356,15 @@ Aml *aml_scope(const char *name_format, ...)
     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.2 Named Objects Encoding: DefDevice */
 Aml *aml_device(const char *name_format, ...)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 004fa05..97e210a 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -62,6 +62,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 /* Block AML object primitives */
 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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 06/42] acpi: add aml_if() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (4 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 05/42] acpi: add aml_method() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 07/42] acpi: add aml_name() & aml_name_decl() term Igor Mammedov
                   ` (35 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 4e0685e..d19d1fb 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -356,6 +356,14 @@ Aml *aml_scope(const char *name_format, ...)
     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 97e210a..13cc9e9 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -63,6 +63,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 07/42] acpi: add aml_name() & aml_name_decl() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (5 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 06/42] acpi: add aml_if() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 08/42] acpi: add aml_int() term Igor Mammedov
                   ` (34 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 d19d1fb..cb00a1b 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -271,6 +271,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_OPCODE;
+    return var;
+}
+
 static Aml *aml_bundle(uint8_t op, AmlBlockFlags flags)
 {
     Aml *var = aml_alloc();
@@ -356,6 +365,29 @@ Aml *aml_scope(const char *name_format, ...)
     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 13cc9e9..946aece 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -59,6 +59,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 08/42] acpi: add aml_int() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (6 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 07/42] acpi: add aml_name() & aml_name_decl() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 09/42] acpi: add aml_return() term Igor Mammedov
                   ` (33 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

* factor out ACPI const int packing out of build_append_value()
  and rename build_append_value() to build_append_int_noprefix()
  it will be reused for adding a plain integer value into AML.
  will be used by is aml_processor() and CRS macro helpers
* extend build_append_int{_noprefix}() to support 64-bit values
  it will be used PCI for generating 64bit _CRS entries

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

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cb00a1b..aaa80e5 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -218,44 +218,34 @@ 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)
+static void build_append_int_noprefix(GArray *table, uint64_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;
     }
 }
 
-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 */
     } else if (value == 0x01) {
         build_append_byte(table, 0x01); /* OneOp */
     } else if (value <= 0xFF) {
-        build_append_value(table, value, 1);
+        build_append_byte(table, 0x0A); /* BytePrefix */
+        build_append_int_noprefix(table, value, 1);
     } else if (value <= 0xFFFF) {
-        build_append_value(table, value, 2);
+        build_append_byte(table, 0x0B); /* WordPrefix */
+        build_append_int_noprefix(table, value, 2);
+    } else if (value <= 0xFFFFFFFF) {
+        build_append_byte(table, 0x0C); /* DWordPrefix */
+        build_append_int_noprefix(table, value, 4);
     } else {
-        build_append_value(table, value, 4);
+        build_append_byte(table, 0x0E); /* QWordPrefix */
+        build_append_int_noprefix(table, value, 8);
     }
 }
 
@@ -366,6 +356,17 @@ Aml *aml_scope(const char *name_format, ...)
 }
 
 /*
+ * 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/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index c66fe56..bf34415 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -304,14 +304,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 */
@@ -580,7 +580,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);
     }
 
@@ -715,11 +715,11 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
                              bus->parent_dev->devfn);
         build_append_byte(bus_table, 0x08); /* NameOp */
         build_append_namestring(bus_table, "_SUN");
-        build_append_value(bus_table, PCI_SLOT(bus->parent_dev->devfn), 1);
+        build_append_int(bus_table, PCI_SLOT(bus->parent_dev->devfn));
         build_append_byte(bus_table, 0x08); /* NameOp */
         build_append_namestring(bus_table, "_ADR");
-        build_append_value(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) |
-                           PCI_FUNC(bus->parent_dev->devfn), 4);
+        build_append_int(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) |
+                           PCI_FUNC(bus->parent_dev->devfn));
     } else {
         op = 0x10; /* ScopeOp */;
         build_append_namestring(bus_table, "PCI0");
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 946aece..a385132 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -62,6 +62,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
@@ -81,8 +82,7 @@ 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_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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 09/42] acpi: add aml_return() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (7 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 08/42] acpi: add aml_int() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 10/42] acpi: add aml_arg() term Igor Mammedov
                   ` (32 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 aaa80e5..8207d9c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -355,6 +355,14 @@ Aml *aml_scope(const char *name_format, ...)
     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 a385132..e7fa977 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -62,6 +62,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 10/42] acpi: add aml_arg() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (8 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 09/42] acpi: add aml_return() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 11/42] acpi: add aml_store() term Igor Mammedov
                   ` (31 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 8207d9c..99d213c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -397,6 +397,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 e7fa977..63e9754 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -64,6 +64,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 11/42] acpi: add aml_store() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (9 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 10/42] acpi: add aml_arg() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 12/42] acpi: add aml_and() term Igor Mammedov
                   ` (30 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 99d213c..57e3176 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -408,6 +408,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 63e9754..6ad76dd 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -65,6 +65,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 12/42] acpi: add aml_and() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (10 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 11/42] acpi: add aml_store() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 13/42] acpi: add aml_notify() term Igor Mammedov
                   ` (29 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 57e3176..bb1fbbc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -417,6 +417,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 6ad76dd..2fca361 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -66,6 +66,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 13/42] acpi: add aml_notify() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (11 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 12/42] acpi: add aml_and() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 14/42] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Igor Mammedov
                   ` (28 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 bb1fbbc..3e187fa 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -427,6 +427,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 2fca361..cbef236 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -67,6 +67,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 14/42] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (12 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 13/42] acpi: add aml_notify() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 15/42] acpi: add aml_package() term Igor Mammedov
                   ` (27 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 3e187fa..18427b6 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -436,6 +436,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 cbef236..5f00b07 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -68,6 +68,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 15/42] acpi: add aml_package() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (13 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 14/42] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 16/42] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
                   ` (26 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 18427b6..fdeeacc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -505,3 +505,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 5f00b07..92097b5 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -78,6 +78,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 16/42] pc: acpi-build: generate _S[345] packages dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (14 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 15/42] acpi: add aml_package() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 17/42] acpi: add aml_buffer() term Igor Mammedov
                   ` (25 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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  | 40 ++++++++++++++++++++++++++++++----------
 hw/i386/ssdt-misc.dsl | 33 ---------------------------------
 2 files changed, 30 insertions(+), 43 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index bf34415..4536fba 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -924,7 +924,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     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;
 
     ssdt = init_aml_allocator();
@@ -936,15 +936,6 @@ build_ssdt(GArray *table_data, GArray *linker,
     /* Copy header and patch values in the S3_ / S4_ / S5_ packages */
     ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
     memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
-    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] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
-            pm->s4_val;
-    }
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
@@ -954,6 +945,35 @@ build_ssdt(GArray *table_data, GArray *linker,
     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(1)); /* PM1b_CNT.SLP_TYP, FIXME: 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 */
+        /* PM1b_CNT.SLP_TYP, FIXME: not impl. */
+        aml_append(pkg, aml_int(pm->s4_val));
+        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 1e3baae..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 */
-            One,  /* PM1b_CNT.SLP_TYP */
-            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 */
-            0x2,  /* PM1b_CNT.SLP_TYP */
-            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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 17/42] acpi: add aml_buffer() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (15 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 16/42] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 18/42] acpi: add aml_resource_template() helper Igor Mammedov
                   ` (24 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 fdeeacc..98b1540 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -506,6 +506,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 92097b5..5fe66c6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -79,6 +79,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 18/42] acpi: add aml_resource_template() helper
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (16 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 17/42] acpi: add aml_buffer() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 19/42] acpi: add aml_io() helper Igor Mammedov
                   ` (23 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 98b1540..070ca81 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -506,6 +506,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 5fe66c6..2810b4c 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -80,6 +80,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 19/42] acpi: add aml_io() helper
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (17 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 18/42] acpi: add aml_resource_template() helper Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 20/42] acpi: include PkgLength size only when requested Igor Mammedov
                   ` (22 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 070ca81..d7edda1 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -478,6 +478,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 2810b4c..298e2ef 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -23,6 +23,11 @@ struct Aml {
 };
 typedef struct Aml Aml;
 
+typedef enum {
+    aml_decode10 = 0,
+    aml_decode16 = 1,
+} AmlIODecode;
+
 /**
  * init_aml_allocator:
  *
@@ -72,6 +77,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 20/42] acpi: include PkgLength size only when requested
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (18 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 19/42] acpi: add aml_io() helper Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 21/42] acpi: add aml_operation_region() term Igor Mammedov
                   ` (21 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 d7edda1..cc883cc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -158,10 +158,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)) {
@@ -174,8 +174,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:
@@ -208,7 +218,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 298e2ef..b7f491e 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -99,7 +99,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_int(GArray *table, uint64_t value);
 void build_extop_package(GArray *package, uint8_t op);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 21/42] acpi: add aml_operation_region() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (19 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 20/42] acpi: include PkgLength size only when requested Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 22/42] acpi: add aml_field() & aml_named_field() terms Igor Mammedov
                   ` (20 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 cc883cc..d72d5b4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -554,3 +554,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 b7f491e..57926e5 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -28,6 +28,11 @@ typedef enum {
     aml_decode16 = 1,
 } AmlIODecode;
 
+typedef enum {
+    aml_system_memory = 0x00,
+    aml_system_io = 0x01,
+} AmlRegionSpace;
+
 /**
  * init_aml_allocator:
  *
@@ -79,6 +84,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 22/42] acpi: add aml_field() & aml_named_field() terms
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (20 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 21/42] acpi: add aml_operation_region() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 23/42] acpi: add aml_local() term Igor Mammedov
                   ` (19 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 d72d5b4..b91141e 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -216,6 +216,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);
@@ -568,3 +578,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 57926e5..2bb5f39 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -29,6 +29,10 @@ typedef enum {
 } AmlIODecode;
 
 typedef enum {
+    aml_byte_acc = 1,
+} AmlFieldFlags;
+
+typedef enum {
     aml_system_memory = 0x00,
     aml_system_io = 0x01,
 } AmlRegionSpace;
@@ -86,6 +90,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
@@ -95,6 +100,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 23/42] acpi: add aml_local() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (21 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 22/42] acpi: add aml_field() & aml_named_field() terms Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 24/42] acpi: add aml_string() term Igor Mammedov
                   ` (18 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 b91141e..fabd0ad 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -596,3 +596,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(num <= 7);
+    var = aml_opcode(op);
+    return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 2bb5f39..de081d6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -91,6 +91,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 24/42] acpi: add aml_string() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (22 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 23/42] acpi: add aml_local() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 25/42] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
                   ` (17 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 fabd0ad..57a65dd 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -597,6 +597,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 de081d6..b1eab3c 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -92,6 +92,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 25/42] pc: acpi-build: generate pvpanic device description dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (23 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 24/42] acpi: add aml_string() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 26/42] acpi: add aml_varpackage() term Igor Mammedov
                   ` (16 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 4536fba..2c581ef 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -924,7 +924,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     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;
 
     ssdt = init_aml_allocator();
@@ -940,9 +940,6 @@ build_ssdt(GArray *table_data, GArray *linker,
     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 */
@@ -974,6 +971,37 @@ build_ssdt(GArray *table_data, GArray *linker,
     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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 26/42] acpi: add aml_varpackage() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (24 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 25/42] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 27/42] acpi: add aml_equal() term Igor Mammedov
                   ` (15 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 57a65dd..36aafe4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -632,3 +632,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 b1eab3c..7f3886f 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -103,6 +103,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 27/42] acpi: add aml_equal() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (25 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 26/42] acpi: add aml_varpackage() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 28/42] acpi: add aml_processor() term Igor Mammedov
                   ` (14 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 36aafe4..97b027c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -514,6 +514,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 7f3886f..5e2b434 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -93,6 +93,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 28/42] acpi: add aml_processor() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (26 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 27/42] acpi: add aml_equal() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 29/42] acpi: add aml_eisaid() term Igor Mammedov
                   ` (13 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 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 97b027c..9081b49 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -650,3 +650,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_int_noprefix(var->buf, pblk_addr, sizeof(pblk_addr));
+    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 5e2b434..58bbbfe 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -94,6 +94,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 29/42] acpi: add aml_eisaid() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (27 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 28/42] acpi: add aml_processor() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 30/42] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
                   ` (12 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 9081b49..eeb006f 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -665,3 +665,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_int_noprefix(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 58bbbfe..bf94155 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -96,6 +96,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 30/42] pc: acpi-build: drop template patching and CPU hotplug objects dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (28 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 29/42] acpi: add aml_eisaid() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 31/42] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
                   ` (11 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 |  7 ++--
 hw/i386/acpi-build.c  | 88 ++++++++++++++++++++++++---------------------------
 hw/i386/ssdt-proc.dsl | 63 ------------------------------------
 3 files changed, 45 insertions(+), 113 deletions(-)
 delete mode 100644 hw/i386/ssdt-proc.dsl

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 2b678ef..c9af7ba 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -7,10 +7,11 @@ 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-build.o: hw/i386/acpi-build.c \
 	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-pcihp.hex \
+	hw/i386/ssdt-misc.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 2c581ef..c6910da 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -522,15 +522,6 @@ static inline char acpi_get_hex(uint32_t val)
     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)
-
 /* 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)
@@ -924,7 +915,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     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;
 
     ssdt = init_aml_allocator();
@@ -1006,51 +997,54 @@ build_ssdt(GArray *table_data, GArray *linker,
     {
         /* 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)
-        }
-    }
-}
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 31/42] pc: acpi-build: create CPU hotplug IO region dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (29 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 30/42] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 32/42] acpi: add aml_reserved_field() term Igor Mammedov
                   ` (10 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 c6910da..4f1c251 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 {
@@ -176,12 +178,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) {
@@ -995,6 +1000,28 @@ build_ssdt(GArray *table_data, GArray *linker,
 
     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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 32/42] acpi: add aml_reserved_field() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (30 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 31/42] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 33/42] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
                   ` (9 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 eeb006f..9d9b978 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -598,6 +598,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 bf94155..ea3ece3 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -29,7 +29,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 {
@@ -91,6 +96,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 33/42] pc: acpi-build: drop template patching and memory hotplug objects dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (31 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 32/42] acpi: add aml_reserved_field() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 34/42] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
                   ` (8 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 |   1 -
 hw/i386/acpi-build.c  | 112 +++++++++++++++++++++-----------------------------
 hw/i386/ssdt-mem.dsl  |  77 ----------------------------------
 3 files changed, 46 insertions(+), 144 deletions(-)
 delete mode 100644 hw/i386/ssdt-mem.dsl

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index c9af7ba..45b90a8 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -11,7 +11,6 @@ hw/i386/acpi-build.o: hw/i386/acpi-build.c \
 	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-pcihp.hex \
 	hw/i386/ssdt-misc.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 4f1c251..377dd72 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -307,28 +307,6 @@ static void build_append_and_cleanup_method(GArray *device, GArray *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 */
 
@@ -550,14 +528,6 @@ static inline char acpi_get_hex(uint32_t val)
 #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 */
-#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
 
@@ -565,24 +535,6 @@ static inline char acpi_get_hex(uint32_t val)
 #include "hw/i386/ssdt-pcihp.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);
-}
-
 static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
 {
     unsigned devfn = PCI_DEVFN(slot, 0);
@@ -1073,27 +1025,55 @@ build_ssdt(GArray *table_data, GArray *linker,
         }
         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);
+
+        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")));
 
-            /* 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);
+            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);
+
         {
             AcpiBuildPciBusHotplugState hotplug_state;
             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)
-            }
-        }
-    }
-}
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 34/42] pc: acpi-build: create memory hotplug IO region dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (32 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 33/42] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 35/42] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Igor Mammedov
                   ` (7 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 377dd72..98553f8 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 {
@@ -187,6 +189,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) {
@@ -887,9 +892,6 @@ build_ssdt(GArray *table_data, GArray *linker,
 
     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) {
@@ -1027,6 +1029,55 @@ build_ssdt(GArray *table_data, GArray *linker,
 
         /* 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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 35/42] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (33 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 34/42] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 36/42] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
                   ` (6 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 9d9b978..d793775 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -704,3 +704,164 @@ Aml *aml_eisaid(const char *str)
     build_append_int_noprefix(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_int_noprefix(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_int_noprefix(var->buf, addr_min, sizeof(addr_min));
+    build_append_int_noprefix(var->buf, addr_max, sizeof(addr_max));
+    build_append_int_noprefix(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_int_noprefix(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_int_noprefix(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_int_noprefix(var->buf, addr_min, sizeof(addr_min));
+    build_append_int_noprefix(var->buf, addr_max, sizeof(addr_max));
+    build_append_int_noprefix(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_int_noprefix(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_int_noprefix(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_int_noprefix(var->buf, addr_min, sizeof(addr_min));
+    build_append_int_noprefix(var->buf, addr_max, sizeof(addr_max));
+    build_append_int_noprefix(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_int_noprefix(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 ea3ece3..d2b2c35 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -42,6 +42,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:
  *
@@ -103,6 +154,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 36/42] pc: pcihp: expose MMIO base and len as properties
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (34 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 35/42] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 37/42] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
                   ` (5 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 37/42] pc: acpi-build: reserve PCIHP MMIO resources
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (35 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 36/42] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 38/42] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
                   ` (4 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 98553f8..4d5d7e3 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 {
@@ -178,9 +180,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;
@@ -892,6 +900,25 @@ build_ssdt(GArray *table_data, GArray *linker,
 
     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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 38/42] pc: acpi-build: create PCI0._CRS dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (36 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 37/42] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 20:25   ` Michael S. Tsirkin
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 39/42] pc: acpi-build: drop remaining ssdt_misc template Igor Mammedov
                   ` (3 subsequent siblings)
  41 siblings, 1 reply; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 4d5d7e3..ee254df 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -346,24 +346,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);
@@ -860,22 +842,6 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
     g_free(child);
 }
 
-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(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -898,9 +864,40 @@ build_ssdt(GArray *table_data, GArray *linker,
     ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
     memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
 
-    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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 39/42] pc: acpi-build: drop remaining ssdt_misc template
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (37 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 38/42] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 40/42] acpi: add acpi_irq_no_flags() term Igor Mammedov
                   ` (2 subsequent siblings)
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

It drops empty ssdt_misc templete. It also hides
from user almost 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 |  1 -
 hw/i386/acpi-build.c  |  7 ++-----
 hw/i386/ssdt-misc.dsl | 21 ---------------------
 3 files changed, 2 insertions(+), 27 deletions(-)
 delete mode 100644 hw/i386/ssdt-misc.dsl

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 45b90a8..9b00568 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -10,7 +10,6 @@ obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c \
 	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-pcihp.hex \
-	hw/i386/ssdt-misc.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 ee254df..027a906 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -526,7 +526,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 #define ACPI_SSDT_HEADER_LENGTH 36
 
-#include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-pcihp.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
@@ -850,7 +849,6 @@ build_ssdt(GArray *table_data, GArray *linker,
     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;
 
@@ -860,9 +858,8 @@ 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(ssdt->buf, sizeof(ssdp_misc_aml));
-    memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
+    /* Reserve space for header */
+    acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
 
     scope = aml_scope("\\_SB.PCI0");
     /* build PCI0._CRS */
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)
-{
-}
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v4 40/42] acpi: add acpi_irq_no_flags() term
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (38 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 39/42] pc: acpi-build: drop remaining ssdt_misc template Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 41/42] pc: export applesmc IO port/len Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 42/42] pc: acpi-build: drop template patching and create Device(SMC) dynamically Igor Mammedov
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 d793775..60245e7 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -514,6 +514,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 d2b2c35..1187197 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -146,6 +146,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 41/42] pc: export applesmc IO port/len
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (39 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 40/42] acpi: add acpi_irq_no_flags() term Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 42/42] pc: acpi-build: drop template patching and create Device(SMC) dynamically Igor Mammedov
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 027a906..483073b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -145,7 +145,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] 44+ messages in thread

* [Qemu-devel] [PATCH v4 42/42] pc: acpi-build: drop template patching and create Device(SMC) dynamically
  2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
                   ` (40 preceding siblings ...)
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 41/42] pc: export applesmc IO port/len Igor Mammedov
@ 2015-02-18 19:14 ` Igor Mammedov
  41 siblings, 0 replies; 44+ messages in thread
From: Igor Mammedov @ 2015-02-18 19:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: drjones, mst, zhaoshenglong, marcel.a

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 483073b..cae01ee 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -116,6 +116,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 {
@@ -127,7 +128,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);
@@ -135,17 +135,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
@@ -248,6 +242,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)
@@ -942,6 +937,26 @@ build_ssdt(GArray *table_data, GArray *linker,
     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] 44+ messages in thread

* Re: [Qemu-devel] [PATCH v4 38/42] pc: acpi-build: create PCI0._CRS dynamically
  2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 38/42] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
@ 2015-02-18 20:25   ` Michael S. Tsirkin
  0 siblings, 0 replies; 44+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 20:25 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: drjones, zhaoshenglong, qemu-devel, marcel.a

On Wed, Feb 18, 2015 at 07:14:51PM +0000, Igor Mammedov wrote:
> 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>

This should be split.

Can we have
patch 1 replace ASL with C
patch 2 simplify ranges
?

I seem to remember reserving ranges like that caused
problems in the past, and even if not, it's cleaner
not to mix code rework and functional changes.

> ---
>  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 4d5d7e3..ee254df 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -346,24 +346,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);
> @@ -860,22 +842,6 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
>      g_free(child);
>  }
>  
> -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(GArray *table_data, GArray *linker,
>             AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
> @@ -898,9 +864,40 @@ build_ssdt(GArray *table_data, GArray *linker,
>      ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
>      memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
>  
> -    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	[flat|nested] 44+ messages in thread

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

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 19:14 [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 01/42] acpi: introduce AML composer aml_append() Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 02/42] acpi: add aml_scope() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 03/42] pc: acpi-build: use aml_scope() for \_SB scope Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 04/42] acpi: add aml_device() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 05/42] acpi: add aml_method() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 06/42] acpi: add aml_if() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 07/42] acpi: add aml_name() & aml_name_decl() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 08/42] acpi: add aml_int() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 09/42] acpi: add aml_return() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 10/42] acpi: add aml_arg() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 11/42] acpi: add aml_store() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 12/42] acpi: add aml_and() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 13/42] acpi: add aml_notify() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 14/42] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 15/42] acpi: add aml_package() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 16/42] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 17/42] acpi: add aml_buffer() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 18/42] acpi: add aml_resource_template() helper Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 19/42] acpi: add aml_io() helper Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 20/42] acpi: include PkgLength size only when requested Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 21/42] acpi: add aml_operation_region() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 22/42] acpi: add aml_field() & aml_named_field() terms Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 23/42] acpi: add aml_local() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 24/42] acpi: add aml_string() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 25/42] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 26/42] acpi: add aml_varpackage() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 27/42] acpi: add aml_equal() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 28/42] acpi: add aml_processor() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 29/42] acpi: add aml_eisaid() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 30/42] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 31/42] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 32/42] acpi: add aml_reserved_field() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 33/42] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 34/42] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 35/42] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 36/42] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 37/42] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 38/42] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
2015-02-18 20:25   ` Michael S. Tsirkin
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 39/42] pc: acpi-build: drop remaining ssdt_misc template Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 40/42] acpi: add acpi_irq_no_flags() term Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 41/42] pc: export applesmc IO port/len Igor Mammedov
2015-02-18 19:14 ` [Qemu-devel] [PATCH v4 42/42] pc: acpi-build: drop template patching and create Device(SMC) dynamically 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.