All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API
@ 2014-12-19  2:01 Igor Mammedov
  2014-12-19  2:01 ` [Qemu-devel] [RFC 01/47] acpi: introduce AML composer aml_append() Igor Mammedov
                   ` (46 more replies)
  0 siblings, 47 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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.

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


Tested with XPsp3, WS2012R2, RHEL6/7 guests. 

Depends on:
    [PATCH V2 0/8] pc: acpi: various fixes and cleanups
    http://lists.gnu.org/archive/html/qemu-devel/2014-12/msg02454.html

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

 
Igor Mammedov (47):
  acpi: introduce AML composer aml_append()
  acpi: add acpi_scope() term
  acpi: add acpi_device() term
  acpi: add acpi_method() term
  acpi: add acpi_if() term
  acpi: add acpi_name() & acpi_name_decl() term
  acpi: factor out ACPI const int packing out build_append_value()
  acpi: extend build_append_{value|int}() to support 64-bit values
  acpi: add acpi_int() term
  acpi: add acpi_return() term
  acpi: add acpi_arg0(), acpi_arg1(), acpi_arg2(), acpi_arg3() terms
  acpi: add acpi_store() term
  acpi: add acpi_and() term
  acpi: add acpi_notify() term
  acpi: add acpi_call1(), acpi_call2(), acpi_call3(), acpi_call4()
    helpers
  pc: acpi-build: drop template patching and create PCI bus tree
    dinamically
  acpi: add acpi_package() term
  pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  pc: acpi-build: generate _S[345] packages dynamically
  acpi: add acpi_buffer() term
  acpi: add acpi_resource_template() helper
  acpi: add acpi_io() helper
  acpi: include PkgLength size only when requested
  acpi: add acpi_operation_region() term
  acpi: add acpi_field() & acpi_named_field() terms
  acpi: add acpi_local0() term
  acpi: add acpi_string() term
  pc: acpi-build: generate pvpanic device description dynamically
  acpi: add acpi_varpackage() term
  acpi: add acpi_equal() term
  acpi: add acpi_processor() term
  acpi: add acpi_eisaid() term
  pc: acpi-build: drop template patching and CPU hotplug objects
    dynamically
  pc: acpi-build: create CPU hotplug IO region dynamically
  acpi: add acpi_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 acpi_word_bus_number(), acpi_word_io(), acpi_dword_memory(),
    acpi_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
  acpi: make tables linker-loader available to other targets
  acpi: add acpi_def_block() term
  pc: acpi-build: prepare to make ACPI tables blob opaque for table
    building functions
  pc: acpi-build: drop remaining ssdt_misc template and use
    acpi_def_block()
  pc: acpi: update DSTD blobs
  tests: acpi: update reference DSDT/SSDT tables

 hw/acpi/Makefile.objs                |   2 +-
 hw/acpi/acpi_gen_utils.c             | 670 ++++++++++++++++++++++++++++--
 hw/acpi/bios-linker-loader.c         | 157 +++++++
 hw/acpi/pcihp.c                      |  18 +-
 hw/acpi/piix4.c                      |   2 +-
 hw/i386/Makefile.objs                |   5 +-
 hw/i386/acpi-build.c                 | 785 ++++++++++++++++++-----------------
 hw/i386/acpi-dsdt-cpu-hotplug.dsl    |  17 +-
 hw/i386/acpi-dsdt-mem-hotplug.dsl    |  36 +-
 hw/i386/acpi-dsdt-pci-crs.dsl        |  92 ----
 hw/i386/acpi-dsdt.dsl                |  45 --
 hw/i386/acpi-dsdt.hex.generated      | 678 +++---------------------------
 hw/i386/bios-linker-loader.c         | 157 -------
 hw/i386/bios-linker-loader.h         |  27 --
 hw/i386/q35-acpi-dsdt.dsl            |  18 -
 hw/i386/q35-acpi-dsdt.hex.generated  | 616 ++-------------------------
 hw/i386/ssdt-mem.dsl                 |  77 ----
 hw/i386/ssdt-mem.hex.generated       | 213 ----------
 hw/i386/ssdt-misc.dsl                | 122 ------
 hw/i386/ssdt-misc.hex.generated      | 399 ------------------
 hw/i386/ssdt-pcihp.dsl               | 100 -----
 hw/i386/ssdt-pcihp.hex.generated     | 251 -----------
 hw/i386/ssdt-proc.dsl                |  63 ---
 hw/i386/ssdt-proc.hex.generated      | 134 ------
 include/hw/acpi/acpi_gen_utils.h     | 167 +++++++-
 include/hw/acpi/bios-linker-loader.h |  27 ++
 include/hw/acpi/pc-hotplug.h         |   1 +
 include/hw/acpi/pcihp.h              |   7 +-
 tests/acpi-test-data/pc/DSDT         | Bin 3592 -> 3016 bytes
 tests/acpi-test-data/pc/SSDT         | Bin 2279 -> 2406 bytes
 tests/acpi-test-data/q35/DSDT        | Bin 8182 -> 7654 bytes
 tests/acpi-test-data/q35/SSDT        | Bin 560 -> 635 bytes
 32 files changed, 1527 insertions(+), 3359 deletions(-)
 create mode 100644 hw/acpi/bios-linker-loader.c
 delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl
 delete mode 100644 hw/i386/bios-linker-loader.c
 delete mode 100644 hw/i386/bios-linker-loader.h
 delete mode 100644 hw/i386/ssdt-mem.dsl
 delete mode 100644 hw/i386/ssdt-mem.hex.generated
 delete mode 100644 hw/i386/ssdt-misc.dsl
 delete mode 100644 hw/i386/ssdt-misc.hex.generated
 delete mode 100644 hw/i386/ssdt-pcihp.dsl
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
 delete mode 100644 hw/i386/ssdt-proc.dsl
 delete mode 100644 hw/i386/ssdt-proc.hex.generated
 create mode 100644 include/hw/acpi/bios-linker-loader.h

-- 
1.8.3.1

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

* [Qemu-devel] [RFC 01/47] acpi: introduce AML composer aml_append()
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
@ 2014-12-19  2:01 ` Igor Mammedov
  2014-12-19  2:01 ` [Qemu-devel] [RFC 02/47] acpi: add acpi_scope() term Igor Mammedov
                   ` (45 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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:

AcpiAml scope = acpi_scope("PCI0")
AcpiAml dev = acpi_device("PM")
    aml_append(&dev, acpi_name_decl("_ADR", acpi_int(addr)))
aml_append(&scope, dev);

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 291b938..c9050ef 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -242,3 +242,42 @@ void build_append_int(GArray *table, uint32_t value)
         build_append_value(table, value, 4);
     }
 }
+
+static void build_prepend_int(GArray *array, uint32_t value)
+{
+    GArray *data = build_alloc_array();
+
+    build_append_int(data, value);
+    g_array_prepend_vals(array, data->data, data->len);
+    build_free_array(data);
+}
+
+void aml_append(AcpiAml *parent_ctx, AcpiAml child)
+{
+    switch (child.block_flags) {
+    case EXT_PACKAGE:
+        build_extop_package(child.buf, child.op);
+        break;
+
+    case PACKAGE:
+        build_package(child.buf, child.op);
+        break;
+
+    case RES_TEMPLATE:
+        build_append_byte(child.buf, 0x79); /* EndTag */
+        /*
+         * checksum operations is treated as succeeded if checksum
+         * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
+         */
+        build_append_byte(child.buf, 0);
+        /* fall through, to pack resources in buffer */
+    case BUFFER:
+        build_prepend_int(child.buf, child.buf->len);
+        build_package(child.buf, child.op);
+        break;
+    default:
+        break;
+    }
+    build_append_array(parent_ctx->buf, child.buf);
+    build_free_array(child.buf);
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 199f003..64e7ec3 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -5,6 +5,22 @@
 #include <glib.h>
 #include "qemu/compiler.h"
 
+typedef enum {
+    NON_BLOCK,
+    PACKAGE,
+    EXT_PACKAGE,
+    BUFFER,
+    RES_TEMPLATE,
+} AcpiBlockFlags;
+
+typedef struct AcpiAml {
+    GArray *buf;
+    uint8_t op;
+    AcpiBlockFlags block_flags;
+} AcpiAml;
+
+void aml_append(AcpiAml *parent_ctx, AcpiAml child);
+
 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] 58+ messages in thread

* [Qemu-devel] [RFC 02/47] acpi: add acpi_scope() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
  2014-12-19  2:01 ` [Qemu-devel] [RFC 01/47] acpi: introduce AML composer aml_append() Igor Mammedov
@ 2014-12-19  2:01 ` Igor Mammedov
  2014-12-19  2:01 ` [Qemu-devel] [RFC 03/47] acpi: add acpi_device() term Igor Mammedov
                   ` (44 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index c9050ef..56b69dd 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -281,3 +281,21 @@ void aml_append(AcpiAml *parent_ctx, AcpiAml child)
     build_append_array(parent_ctx->buf, child.buf);
     build_free_array(child.buf);
 }
+
+static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
+{
+    AcpiAml var = { .op = op, .block_flags = flags };
+    var.buf = build_alloc_array();
+    return var;
+}
+
+/* ACPI 5.0: 20.2.5.1 Namespace Modifier Objects Encoding: DefScope */
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...)
+{
+    va_list ap;
+    AcpiAml var = aml_allocate_internal(0x10 /* ScopeOp */, 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/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 64e7ec3..bbb786b 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -21,6 +21,10 @@ typedef struct AcpiAml {
 
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
+/* Block ASL object primitives */
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
+
+/* 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] 58+ messages in thread

* [Qemu-devel] [RFC 03/47] acpi: add acpi_device() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
  2014-12-19  2:01 ` [Qemu-devel] [RFC 01/47] acpi: introduce AML composer aml_append() Igor Mammedov
  2014-12-19  2:01 ` [Qemu-devel] [RFC 02/47] acpi: add acpi_scope() term Igor Mammedov
@ 2014-12-19  2:01 ` Igor Mammedov
  2014-12-19  2:01 ` [Qemu-devel] [RFC 04/47] acpi: add acpi_method() term Igor Mammedov
                   ` (43 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 56b69dd..80fa6ac 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -299,3 +299,14 @@ AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...)
     va_end(ap);
     return var;
 }
+
+/* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefDevice */
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...)
+{
+    va_list ap;
+    AcpiAml var = aml_allocate_internal(0x82 /* DeviceOp */, 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/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index bbb786b..56165e6 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -23,6 +23,7 @@ void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* Block ASL object primitives */
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 04/47] acpi: add acpi_method() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (2 preceding siblings ...)
  2014-12-19  2:01 ` [Qemu-devel] [RFC 03/47] acpi: add acpi_device() term Igor Mammedov
@ 2014-12-19  2:01 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 05/47] acpi: add acpi_if() term Igor Mammedov
                   ` (42 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 80fa6ac..a481adb 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -289,6 +289,15 @@ static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefMethod */
+AcpiAml acpi_method(const char *name, int arg_count)
+{
+    AcpiAml var = aml_allocate_internal(0x14 /* MethodOp */, PACKAGE);
+    build_append_namestring(var.buf, "%s", name);
+    build_append_byte(var.buf, arg_count); /* MethodFlags: ArgCount */
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.1 Namespace Modifier Objects Encoding: DefScope */
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 56165e6..19ebc2d 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -22,6 +22,7 @@ typedef struct AcpiAml {
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* Block ASL object primitives */
+AcpiAml acpi_method(const char *name, int arg_count);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
 
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 05/47] acpi: add acpi_if() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (3 preceding siblings ...)
  2014-12-19  2:01 ` [Qemu-devel] [RFC 04/47] acpi: add acpi_method() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 06/47] acpi: add acpi_name() & acpi_name_decl() term Igor Mammedov
                   ` (41 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index a481adb..7bb41ce 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -289,6 +289,14 @@ static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
+AcpiAml acpi_if(AcpiAml predicate)
+{
+    AcpiAml var = aml_allocate_internal(0xA0 /* IfOp */, PACKAGE);
+    aml_append(&var, predicate);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefMethod */
 AcpiAml acpi_method(const char *name, int arg_count)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 19ebc2d..177f9ed 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -22,6 +22,7 @@ typedef struct AcpiAml {
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* Block ASL object primitives */
+AcpiAml acpi_if(AcpiAml predicate);
 AcpiAml acpi_method(const char *name, int arg_count);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 06/47] acpi: add acpi_name() & acpi_name_decl() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (4 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 05/47] acpi: add acpi_if() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 07/47] acpi: factor out ACPI const int packing out build_append_value() Igor Mammedov
                   ` (40 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 7bb41ce..cfccb42 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -289,6 +289,30 @@ static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
     return var;
 }
 
+/*
+ * help to construct NameString, which return AcpiAml object
+ * for using with other aml_append or other acpi_* terms
+ */
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...)
+{
+    va_list ap;
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    va_start(ap, name_format);
+    build_append_namestringv(var.buf, name_format, ap);
+    va_end(ap);
+    return var;
+}
+
+/* ACPI 5.0: 20.2.5.1 Namespace Modifier Objects Encoding: DefName */
+AcpiAml acpi_name_decl(const char *name, AcpiAml val)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x08);
+    build_append_namestring(var.buf, "%s", name);
+    aml_append(&var, val);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 177f9ed..868cfa5 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -21,6 +21,9 @@ typedef struct AcpiAml {
 
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
+/* non block ASL object primitives */
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...);
+AcpiAml acpi_name_decl(const char *name, AcpiAml val);
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
 AcpiAml acpi_method(const char *name, int arg_count);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 07/47] acpi: factor out ACPI const int packing out build_append_value()
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (5 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 06/47] acpi: add acpi_name() & acpi_name_decl() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 08/47] acpi: extend build_append_{value|int}() to support 64-bit values Igor Mammedov
                   ` (39 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index cfccb42..36d7a47 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -204,24 +204,8 @@ void build_extop_package(GArray *package, uint8_t op)
 
 void build_append_value(GArray *table, uint32_t value, int size)
 {
-    uint8_t prefix;
     int i;
 
-    switch (size) {
-    case 1:
-        prefix = 0x0A; /* BytePrefix */
-        break;
-    case 2:
-        prefix = 0x0B; /* WordPrefix */
-        break;
-    case 4:
-        prefix = 0x0C; /* DWordPrefix */
-        break;
-    default:
-        assert(0);
-        return;
-    }
-    build_append_byte(table, prefix);
     for (i = 0; i < size; ++i) {
         build_append_byte(table, value & 0xFF);
         value = value >> 8;
@@ -235,10 +219,13 @@ void build_append_int(GArray *table, uint32_t value)
     } else if (value == 0x01) {
         build_append_byte(table, 0x01); /* OneOp */
     } else if (value <= 0xFF) {
+        build_append_byte(table, 0x0A); /* BytePrefix */
         build_append_value(table, value, 1);
     } else if (value <= 0xFFFF) {
+        build_append_byte(table, 0x0B); /* WordPrefix */
         build_append_value(table, value, 2);
     } else {
+        build_append_byte(table, 0x0C); /* DWordPrefix */
         build_append_value(table, value, 4);
     }
 }
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 08/47] acpi: extend build_append_{value|int}() to support 64-bit values
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (6 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 07/47] acpi: factor out ACPI const int packing out build_append_value() Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 09/47] acpi: add acpi_int() term Igor Mammedov
                   ` (38 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

it will be used for generating 64bit _CRS entries

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 36d7a47..606efcd 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -202,7 +202,7 @@ void build_extop_package(GArray *package, uint8_t op)
     build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
-void build_append_value(GArray *table, uint32_t value, int size)
+void build_append_value(GArray *table, uint64_t value, int size)
 {
     int i;
 
@@ -212,7 +212,7 @@ void build_append_value(GArray *table, uint32_t value, int size)
     }
 }
 
-void build_append_int(GArray *table, uint32_t value)
+void build_append_int(GArray *table, uint64_t value)
 {
     if (value == 0x00) {
         build_append_byte(table, 0x00); /* ZeroOp */
@@ -224,9 +224,12 @@ void build_append_int(GArray *table, uint32_t value)
     } else if (value <= 0xFFFF) {
         build_append_byte(table, 0x0B); /* WordPrefix */
         build_append_value(table, value, 2);
-    } else {
+    } else if (value <= 0xFFFFFFFF) {
         build_append_byte(table, 0x0C); /* DWordPrefix */
         build_append_value(table, value, 4);
+    } else {
+        build_append_byte(table, 0x0E); /* QWordPrefix */
+        build_append_value(table, value, 8);
     }
 }
 
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 868cfa5..d21e107 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -42,8 +42,8 @@ build_append_namestring(GArray *array, const char *format, ...);
 
 void build_prepend_package_length(GArray *package);
 void build_package(GArray *package, uint8_t op);
-void build_append_value(GArray *table, uint32_t value, int size);
-void build_append_int(GArray *table, uint32_t value);
+void build_append_value(GArray *table, uint64_t value, int size);
+void build_append_int(GArray *table, uint64_t value);
 void build_extop_package(GArray *package, uint8_t op);
 
 #endif
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 09/47] acpi: add acpi_int() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (7 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 08/47] acpi: extend build_append_{value|int}() to support 64-bit values Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 10/47] acpi: add acpi_return() term Igor Mammedov
                   ` (37 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 606efcd..8a37bac 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -280,6 +280,17 @@ static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
 }
 
 /*
+ * ACPI 5.0: 20.2.3 Data Objects Encoding:
+ * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
+ */
+AcpiAml acpi_int(const uint64_t val)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_int(var.buf, val);
+    return var;
+}
+
+/*
  * help to construct NameString, which return AcpiAml object
  * for using with other aml_append or other acpi_* terms
  */
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index d21e107..2ea53f9 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -22,6 +22,7 @@ typedef struct AcpiAml {
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* non block ASL object primitives */
+AcpiAml acpi_int(const uint64_t val);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...);
 AcpiAml acpi_name_decl(const char *name, AcpiAml val);
 /* Block ASL object primitives */
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 10/47] acpi: add acpi_return() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (8 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 09/47] acpi: add acpi_int() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 11/47] acpi: add acpi_arg0(), acpi_arg1(), acpi_arg2(), acpi_arg3() terms Igor Mammedov
                   ` (36 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 8a37bac..57614ea 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -279,6 +279,15 @@ static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefReturn */
+AcpiAml acpi_return(AcpiAml val)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0xA4); /* ReturnOp */
+    aml_append(&var, val);
+    return var;
+}
+
 /*
  * ACPI 5.0: 20.2.3 Data Objects Encoding:
  * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 2ea53f9..9e9ef1a 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -22,6 +22,7 @@ typedef struct AcpiAml {
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* non block ASL object primitives */
+AcpiAml acpi_return(AcpiAml val);
 AcpiAml acpi_int(const uint64_t val);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...);
 AcpiAml acpi_name_decl(const char *name, AcpiAml val);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 11/47] acpi: add acpi_arg0(), acpi_arg1(), acpi_arg2(), acpi_arg3() terms
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (9 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 10/47] acpi: add acpi_return() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 12/47] acpi: add acpi_store() term Igor Mammedov
                   ` (35 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 57614ea..48c0599 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -323,6 +323,38 @@ AcpiAml acpi_name_decl(const char *name, AcpiAml val)
     return var;
 }
 
+/* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg0Op */
+AcpiAml acpi_arg0(void)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x68); /* ARG0 op */
+    return var;
+}
+
+/* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg1Op */
+AcpiAml acpi_arg1(void)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x69); /* ARG1 op */
+    return var;
+}
+
+/* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg2Op */
+AcpiAml acpi_arg2(void)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x6A); /* ARG2 op */
+    return var;
+}
+
+/* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg3Op */
+AcpiAml acpi_arg3(void)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x6B); /* ARG3 op */
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 9e9ef1a..18d9efa 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -26,6 +26,11 @@ AcpiAml acpi_return(AcpiAml val);
 AcpiAml acpi_int(const uint64_t val);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...);
 AcpiAml acpi_name_decl(const char *name, AcpiAml val);
+AcpiAml acpi_arg0(void);
+AcpiAml acpi_arg1(void);
+AcpiAml acpi_arg2(void);
+AcpiAml acpi_arg3(void);
+
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
 AcpiAml acpi_method(const char *name, int arg_count);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 12/47] acpi: add acpi_store() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (10 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 11/47] acpi: add acpi_arg0(), acpi_arg1(), acpi_arg2(), acpi_arg3() terms Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 13/47] acpi: add acpi_and() term Igor Mammedov
                   ` (34 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 48c0599..a28485c 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -355,6 +355,16 @@ AcpiAml acpi_arg3(void)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefStore */
+AcpiAml acpi_store(AcpiAml val, AcpiAml target)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x70); /* StoreOp */
+    aml_append(&var, val);
+    aml_append(&var, target);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 18d9efa..5d3651d 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -30,6 +30,7 @@ AcpiAml acpi_arg0(void);
 AcpiAml acpi_arg1(void);
 AcpiAml acpi_arg2(void);
 AcpiAml acpi_arg3(void);
+AcpiAml acpi_store(AcpiAml val, AcpiAml target);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 13/47] acpi: add acpi_and() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (11 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 12/47] acpi: add acpi_store() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 14/47] acpi: add acpi_notify() term Igor Mammedov
                   ` (33 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index a28485c..15a65c2 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -365,6 +365,17 @@ AcpiAml acpi_store(AcpiAml val, AcpiAml target)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefAnd */
+AcpiAml acpi_and(AcpiAml arg1, AcpiAml arg2)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x7B); /* AndOp */
+    aml_append(&var, arg1);
+    aml_append(&var, arg2);
+    build_append_int(var.buf, 0x00); /* NullNameOp */
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 5d3651d..50bb1aa 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -31,6 +31,7 @@ AcpiAml acpi_arg1(void);
 AcpiAml acpi_arg2(void);
 AcpiAml acpi_arg3(void);
 AcpiAml acpi_store(AcpiAml val, AcpiAml target);
+AcpiAml acpi_and(AcpiAml arg1, AcpiAml arg2);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 14/47] acpi: add acpi_notify() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (12 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 13/47] acpi: add acpi_and() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2015-01-19 12:32   ` Paolo Bonzini
  2014-12-19  2:02 ` [Qemu-devel] [RFC 15/47] acpi: add acpi_call1(), acpi_call2(), acpi_call3(), acpi_call4() helpers Igor Mammedov
                   ` (32 subsequent siblings)
  46 siblings, 1 reply; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 15a65c2..d6bdc16 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -376,6 +376,16 @@ AcpiAml acpi_and(AcpiAml arg1, AcpiAml arg2)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefNotify */
+AcpiAml acpi_notify(AcpiAml arg1, AcpiAml arg2)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x86); /* NotifyOp */ \
+    aml_append(&var, arg1);
+    aml_append(&var, arg2);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 50bb1aa..1395b32 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -32,6 +32,7 @@ AcpiAml acpi_arg2(void);
 AcpiAml acpi_arg3(void);
 AcpiAml acpi_store(AcpiAml val, AcpiAml target);
 AcpiAml acpi_and(AcpiAml arg1, AcpiAml arg2);
+AcpiAml acpi_notify(AcpiAml arg1, AcpiAml arg2);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 15/47] acpi: add acpi_call1(), acpi_call2(), acpi_call3(), acpi_call4() helpers
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (13 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 14/47] acpi: add acpi_notify() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 16/47] pc: acpi-build: drop template patching and create PCI bus tree dinamically Igor Mammedov
                   ` (31 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index d6bdc16..33478ef 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -386,6 +386,49 @@ AcpiAml acpi_notify(AcpiAml arg1, AcpiAml arg2)
     return var;
 }
 
+/* helper to call method with 1 argument */
+AcpiAml acpi_call1(const char *method, AcpiAml arg1)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_namestring(var.buf, "%s", method);
+    aml_append(&var, arg1);
+    return var;
+}
+
+/* helper to call method with 2 arguments */
+AcpiAml acpi_call2(const char *method, AcpiAml arg1, AcpiAml arg2)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_namestring(var.buf, "%s", method);
+    aml_append(&var, arg1);
+    aml_append(&var, arg2);
+    return var;
+}
+
+/* helper to call method with 3 arguments */
+AcpiAml acpi_call3(const char *method, AcpiAml arg1, AcpiAml arg2, AcpiAml arg3)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    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 */
+AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2,
+                   AcpiAml arg3, AcpiAml arg4)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    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 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 1395b32..473589d 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -33,6 +33,12 @@ AcpiAml acpi_arg3(void);
 AcpiAml acpi_store(AcpiAml val, AcpiAml target);
 AcpiAml acpi_and(AcpiAml arg1, AcpiAml arg2);
 AcpiAml acpi_notify(AcpiAml arg1, AcpiAml arg2);
+AcpiAml acpi_call1(const char *method, AcpiAml arg1);
+AcpiAml acpi_call2(const char *method, AcpiAml arg1, AcpiAml arg2);
+AcpiAml acpi_call3(const char *method, AcpiAml arg1, AcpiAml arg2,
+                   AcpiAml arg3);
+AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2,
+                   AcpiAml arg3, AcpiAml arg4);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 16/47] pc: acpi-build: drop template patching and create PCI bus tree dinamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (14 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 15/47] acpi: add acpi_call1(), acpi_call2(), acpi_call3(), acpi_call4() helpers Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 17/47] acpi: add acpi_package() term Igor Mammedov
                   ` (30 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

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

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 9d419ad..d8dd99f 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -9,10 +9,8 @@ obj-y += kvmvapic.o
 obj-y += acpi-build.o
 obj-y += bios-linker-loader.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-	hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
-	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \
-	hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
     ; then echo "$(2)"; else echo "$(3)"; fi ;)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a893f5e..7d32408 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -523,29 +523,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
 #define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
 
-/* 0x5B 0x82 DeviceOp PkgLength NameString */
-#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
-#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
-#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
-#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
-
-#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
-#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
-
-#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
-#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
-
-#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
-#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
-
 #include "hw/i386/ssdt-mem.hex"
 
 /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
@@ -558,7 +535,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_SSDT_HEADER_LENGTH 36
 
 #include "hw/i386/ssdt-misc.hex"
-#include "hw/i386/ssdt-pcihp.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
 static void
@@ -579,43 +555,6 @@ build_append_notify_method(GArray *device, const char *name,
     build_append_and_cleanup_method(device, method);
 }
 
-static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
-    ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
-{
-    unsigned devfn = PCI_DEVFN(slot, 0);
-
-    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-    ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-    ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
-}
-
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
  */
@@ -646,46 +585,36 @@ static void acpi_set_pci_info(void)
     }
 }
 
-static void build_append_pcihp_notify_entry(GArray *method, int slot)
+static void build_append_pcihp_notify_entry(AcpiAml *method, int slot)
 {
-    GArray *ifctx;
-
-    ifctx = build_alloc_array();
-    build_append_byte(ifctx, 0x7B); /* AndOp */
-    build_append_byte(ifctx, 0x68); /* Arg0Op */
-    build_append_int(ifctx, 0x1U << slot);
-    build_append_byte(ifctx, 0x00); /* NullName */
-    build_append_byte(ifctx, 0x86); /* NotifyOp */
-    build_append_namestring(ifctx, "S%.02X", PCI_DEVFN(slot, 0));
-    build_append_byte(ifctx, 0x69); /* Arg1Op */
+    AcpiAml if_ctx;
+    int32_t devfn = PCI_DEVFN(slot, 0);
 
-    /* Pack it up */
-    build_package(ifctx, 0xA0 /* IfOp */);
-    build_append_array(method, ifctx);
-    build_free_array(ifctx);
+    if_ctx = acpi_if(acpi_and(acpi_arg0(), acpi_int(0x1U << slot)));
+    aml_append(&if_ctx, acpi_notify(acpi_name("S%.02X", devfn), acpi_arg1()));
+    aml_append(method, if_ctx);
 }
 
-static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
+static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus,
                                          bool pcihp_bridge_en)
 {
-    GArray *bus_table = build_alloc_array();
-    GArray *method = NULL;
+    AcpiAml scope, dev, notify_method, method;
     QObject *bsel;
     PCIBus *sec;
     int i;
 
     if (bus->parent_dev) {
-        build_append_namestring(bus_table, "S%.02X_", bus->parent_dev->devfn);
+        scope = acpi_scope("S%.02X_", bus->parent_dev->devfn);
     } else {
-        build_append_namestring(bus_table, "PCI0");
+        scope = acpi_scope("PCI0");
     }
 
     bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
     if (bsel) {
-        build_append_byte(bus_table, 0x08); /* NameOp */
-        build_append_namestring(bus_table, "BSEL");
-        build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
-        method = build_alloc_method("DVNT", 2);
+        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
+
+        aml_append(&scope, acpi_name_decl("BSEL", acpi_int(bsel_val)));
+        notify_method = acpi_method("DVNT", 2);
     }
 
     for (i = 0; i < ARRAY_SIZE(bus->devices); i += PCI_FUNC_MAX) {
@@ -696,11 +625,17 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
 
         if (!pdev) {
             if (bsel) {
-                void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
-                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
-                patch_pcihp(slot, pcihp);
-
-                build_append_pcihp_notify_entry(method, slot);
+                dev = acpi_device("S%.02X", PCI_DEVFN(slot, 0));
+                aml_append(&dev, acpi_name_decl("_SUN", acpi_int(slot)));
+                aml_append(&dev, acpi_name_decl("_ADR", acpi_int(slot << 16)));
+                method = acpi_method("_EJ0", 1);
+                aml_append(&method,
+                    acpi_call2("PCEJ", acpi_name("BSEL"), acpi_name("_SUN"))
+                );
+                aml_append(&dev, method);
+                aml_append(&scope, dev);
+
+                build_append_pcihp_notify_entry(&notify_method, slot);
             }
             continue;
         }
@@ -712,76 +647,84 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
             continue;
         }
 
+        dev = acpi_device("S%.02X", PCI_DEVFN(slot, 0));
+        aml_append(&dev, acpi_name_decl("_ADR", acpi_int(slot << 16)));
+
         if (pc->class_id == PCI_CLASS_DISPLAY_VGA) {
+            int s3d = 0;
 
             if (object_dynamic_cast(OBJECT(pdev), "qxl-vga")) {
-                void *pcihp = acpi_data_push(bus_table,
-                                             ACPI_PCIQXL_SIZEOF);
-                      memcpy(pcihp, ACPI_PCIQXL_AML, ACPI_PCIQXL_SIZEOF);
-                      patch_pciqxl(slot, pcihp);
-            } else {
-                void *pcihp = acpi_data_push(bus_table,
-                                             ACPI_PCIVGA_SIZEOF);
-                memcpy(pcihp, ACPI_PCIVGA_AML, ACPI_PCIVGA_SIZEOF);
-                patch_pcivga(slot, pcihp);
+                s3d = 3;
             }
+
+            method = acpi_method("_S1D", 0);
+            aml_append(&method, acpi_return(acpi_int(0)));
+            aml_append(&dev, method);
+
+            method = acpi_method("_S2D", 0);
+            aml_append(&method, acpi_return(acpi_int(0)));
+            aml_append(&dev, method);
+
+            method = acpi_method("_S3D", 0);
+            aml_append(&method, acpi_return(acpi_int(s3d)));
+            aml_append(&dev, method);
         } else if (dc->hotpluggable && !pc->is_bridge) {
-            void *pcihp = acpi_data_push(bus_table, ACPI_PCIHP_SIZEOF);
-            memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
-            patch_pcihp(slot, pcihp);
+            aml_append(&dev, acpi_name_decl("_SUN", acpi_int(slot)));
+
+            method = acpi_method("_EJ0", 1);
+            aml_append(&method,
+                acpi_call2("PCEJ", acpi_name("BSEL"), acpi_name("_SUN"))
+            );
+            aml_append(&dev, method);
 
             if (bsel) {
-                build_append_pcihp_notify_entry(method, slot);
+                build_append_pcihp_notify_entry(&notify_method, slot);
             }
         } else {
-            void *pcihp = acpi_data_push(bus_table, ACPI_PCINOHP_SIZEOF);
-            memcpy(pcihp, ACPI_PCINOHP_AML, ACPI_PCINOHP_SIZEOF);
-            patch_pcinohp(slot, pcihp);
-
             if (pc->is_bridge) {
                 PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
 
-                build_append_pci_bus_devices(bus_table, sec_bus,
-                                             pcihp_bridge_en);
+                build_append_pci_bus_devices(&dev, sec_bus, pcihp_bridge_en);
             }
         }
+        aml_append(&scope, dev);
     }
 
     if (bsel) {
-        build_append_and_cleanup_method(bus_table, method);
+        aml_append(&scope, notify_method);
     }
 
     /* Append PCNT method to notify about events on local and child buses.
      * Add unconditionally for root since DSDT expects it.
      */
-    method = build_alloc_method("PCNT", 0);
+    method = acpi_method("PCNT", 0);
 
     /* If bus supports hotplug select it and notify about local events */
     if (bsel) {
-        build_append_byte(method, 0x70); /* StoreOp */
-        build_append_int(method, qint_get_int(qobject_to_qint(bsel)));
-        build_append_namestring(method, "BNUM");
-        build_append_namestring(method, "DVNT");
-        build_append_namestring(method, "PCIU");
-        build_append_int(method, 1); /* Device Check */
-        build_append_namestring(method, "DVNT");
-        build_append_namestring(method, "PCID");
-        build_append_int(method, 3); /* Eject Request */
+        int64_t bsel_val = qint_get_int(qobject_to_qint(bsel));
+        aml_append(&method, acpi_store(acpi_int(bsel_val), acpi_name("BNUM")));
+        aml_append(&method,
+            acpi_call2("DVNT", acpi_name("PCIU"),
+                       acpi_int(1) /* Device Check */)
+        );
+        aml_append(&method,
+            acpi_call2("DVNT", acpi_name("PCID"),
+                       acpi_int(3)/* Eject Request */)
+        );
     }
 
     /* Notify about child bus events in any case */
     if (pcihp_bridge_en) {
         QLIST_FOREACH(sec, &bus->child, sibling) {
-            build_append_namestring(method, "^S%.02X.PCNT",
-                                    sec->parent_dev->devfn);
+            int32_t devfn = sec->parent_dev->devfn;
+
+            aml_append(&method, acpi_name("^S%.02X.PCNT", devfn));
         }
     }
+    aml_append(&scope, method);
 
-    build_append_and_cleanup_method(bus_table, method);
-
-    build_package(bus_table, 0x10); /* ScopeOp */
-    build_append_array(parent_scope, bus_table);
-    build_free_array(bus_table);
+    /* Append generated BUS scope object to parent scope */
+    aml_append(parent_scope, scope);
 }
 
 static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
@@ -809,6 +752,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     int ssdt_start = table_data->len;
+    AcpiAml table_aml = { .buf = table_data };
     uint8_t *ssdt_ptr;
     int i;
 
@@ -839,14 +783,11 @@ build_ssdt(GArray *table_data, GArray *linker,
                       ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
     {
-        GArray *sb_scope = build_alloc_array();
-        uint8_t op = 0x10; /* ScopeOp */
-
-        build_append_namestring(sb_scope, "_SB");
+        AcpiAml sb_scope = acpi_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);
@@ -858,11 +799,11 @@ 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();
@@ -887,7 +828,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);
         }
 
@@ -896,7 +837,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);
@@ -907,7 +848,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);
         }
@@ -924,13 +865,11 @@ build_ssdt(GArray *table_data, GArray *linker,
 
             if (bus) {
                 /* Scan all PCI buses. Generate tables to support hotplug. */
-                build_append_pci_bus_devices(sb_scope, bus,
+                build_append_pci_bus_devices(&sb_scope, bus,
                                              pm->pcihp_bridge_en);
             }
         }
-        build_package(sb_scope, op);
-        build_append_array(table_data, sb_scope);
-        build_free_array(sb_scope);
+        aml_append(&table_aml, sb_scope);
     }
 
     build_header(linker, table_data,
diff --git a/hw/i386/ssdt-pcihp.dsl b/hw/i386/ssdt-pcihp.dsl
deleted file mode 100644
index ac91c05..0000000
--- a/hw/i386/ssdt-pcihp.dsl
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-ACPI_EXTRACT_ALL_CODE ssdp_pcihp_aml
-
-DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
-{
-
-/****************************************************************
- * PCI hotplug
- ****************************************************************/
-
-    /* Objects supplied by DSDT */
-    External(\_SB.PCI0, DeviceObj)
-    External(\_SB.PCI0.PCEJ, MethodObj)
-    External(BSEL, IntObj)
-
-    Scope(\_SB.PCI0) {
-
-        /* Bulk generated PCI hotplug devices */
-        ACPI_EXTRACT_DEVICE_START ssdt_pcihp_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pcihp_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pcihp_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SAA) {
-            ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcihp_id
-            Name(_SUN, 0xAA)
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcihp_adr
-            Name(_ADR, 0xAA0000)
-            Method(_EJ0, 1) {
-                PCEJ(BSEL, _SUN)
-            }
-        }
-
-        ACPI_EXTRACT_DEVICE_START ssdt_pcinohp_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pcinohp_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pcinohp_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SBB) {
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcinohp_adr
-            Name(_ADR, 0xAA0000)
-        }
-
-        ACPI_EXTRACT_DEVICE_START ssdt_pcivga_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pcivga_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pcivga_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SCC) {
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcivga_adr
-            Name(_ADR, 0xAA0000)
-            Method(_S1D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S2D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S3D, 0, NotSerialized) {
-                Return (0x00)
-            }
-        }
-
-        ACPI_EXTRACT_DEVICE_START ssdt_pciqxl_start
-        ACPI_EXTRACT_DEVICE_END ssdt_pciqxl_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_pciqxl_name
-
-        // Extract the offsets of the device name, address dword and the slot
-        // name byte - we fill them in for each device.
-        Device(SDD) {
-            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pciqxl_adr
-            Name(_ADR, 0xAA0000)
-            Method(_S1D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S2D, 0, NotSerialized) {
-                Return (0x00)
-            }
-            Method(_S3D, 0, NotSerialized) {
-                Return (0x03)           // QXL
-            }
-        }
-    }
-}
diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
deleted file mode 100644
index 72ffa84..0000000
--- a/hw/i386/ssdt-pcihp.hex.generated
+++ /dev/null
@@ -1,251 +0,0 @@
-static unsigned char ssdt_pcihp_name[] = {
-0x34
-};
-static unsigned char ssdt_pcivga_end[] = {
-0x99
-};
-static unsigned char ssdt_pcivga_name[] = {
-0x70
-};
-static unsigned char ssdt_pcihp_adr[] = {
-0x45
-};
-static unsigned char ssdt_pcinohp_end[] = {
-0x6d
-};
-static unsigned char ssdt_pcihp_end[] = {
-0x5c
-};
-static unsigned char ssdt_pciqxl_start[] = {
-0x99
-};
-static unsigned char ssdt_pcinohp_name[] = {
-0x5f
-};
-static unsigned char ssdp_pcihp_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0xc6,
-0x0,
-0x0,
-0x0,
-0x1,
-0x70,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x50,
-0x43,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x15,
-0x11,
-0x13,
-0x20,
-0x10,
-0x41,
-0xa,
-0x5c,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x5b,
-0x82,
-0x29,
-0x53,
-0x41,
-0x41,
-0x5f,
-0x8,
-0x5f,
-0x53,
-0x55,
-0x4e,
-0xa,
-0xaa,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x12,
-0x5f,
-0x45,
-0x4a,
-0x30,
-0x1,
-0x50,
-0x43,
-0x45,
-0x4a,
-0x42,
-0x53,
-0x45,
-0x4c,
-0x5f,
-0x53,
-0x55,
-0x4e,
-0x5b,
-0x82,
-0xf,
-0x53,
-0x42,
-0x42,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x5b,
-0x82,
-0x2a,
-0x53,
-0x43,
-0x43,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x31,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x32,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x33,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x5b,
-0x82,
-0x2b,
-0x53,
-0x44,
-0x44,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x31,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x32,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x9,
-0x5f,
-0x53,
-0x33,
-0x44,
-0x0,
-0xa4,
-0xa,
-0x3
-};
-static unsigned char ssdt_pciqxl_adr[] = {
-0xa6
-};
-static unsigned char ssdt_pcinohp_adr[] = {
-0x69
-};
-static unsigned char ssdt_pcivga_adr[] = {
-0x7a
-};
-static unsigned char ssdt_pciqxl_name[] = {
-0x9c
-};
-static unsigned char ssdt_pcivga_start[] = {
-0x6d
-};
-static unsigned char ssdt_pciqxl_end[] = {
-0xc6
-};
-static unsigned char ssdt_pcihp_start[] = {
-0x31
-};
-static unsigned char ssdt_pcihp_id[] = {
-0x3e
-};
-static unsigned char ssdt_pcinohp_start[] = {
-0x5c
-};
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 17/47] acpi: add acpi_package() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (15 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 16/47] pc: acpi-build: drop template patching and create PCI bus tree dinamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 18/47] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP Igor Mammedov
                   ` (29 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 33478ef..ae23b4a 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -467,3 +467,11 @@ AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...)
     va_end(ap);
     return var;
 }
+
+/* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefPackage */
+AcpiAml acpi_package(uint8_t num_elements)
+{
+    AcpiAml var = aml_allocate_internal(0x12 /* PackageOp */, PACKAGE);
+    build_append_byte(var.buf, num_elements);
+    return var;
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 473589d..e34e19a 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -45,6 +45,7 @@ AcpiAml acpi_if(AcpiAml predicate);
 AcpiAml acpi_method(const char *name, int arg_count);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
+AcpiAml acpi_package(uint8_t num_elements);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 18/47] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (16 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 17/47] acpi: add acpi_package() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 19/47] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
                   ` (28 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

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

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

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

* [Qemu-devel] [RFC 19/47] pc: acpi-build: generate _S[345] packages dynamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (17 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 18/47] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 20/47] acpi: add acpi_buffer() term Igor Mammedov
                   ` (27 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

Replaces template patching with packages composed
using ASL 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  | 39 ++++++++++++++++++++++++++++++---------
 hw/i386/ssdt-misc.dsl | 33 ---------------------------------
 2 files changed, 30 insertions(+), 42 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b520f4f..48a72ad 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -754,6 +754,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     int ssdt_start = table_data->len;
     AcpiAml table_aml = { .buf = table_data };
     uint8_t *ssdt_ptr;
+    AcpiAml pkg, scope;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -761,17 +762,9 @@ 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 */
+    /* Copy header and ssdt template and patch values */
     ssdt_ptr = acpi_data_push(table_data, 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] = pm->s4_val;
-    }
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
@@ -781,6 +774,34 @@ 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 = acpi_scope("\\");
+    if (!pm->s3_disabled) {
+        pkg = acpi_package(4);
+        aml_append(&pkg, acpi_int(1)); /* PM1a_CNT.SLP_TYP */
+        aml_append(&pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+        aml_append(&pkg, acpi_int(0)); /* reserved */
+        aml_append(&pkg, acpi_int(0)); /* reserved */
+        aml_append(&scope, acpi_name_decl("_S3", pkg));
+    }
+
+    if (!pm->s4_disabled) {
+        pkg = acpi_package(4);
+        aml_append(&pkg, acpi_int(pm->s4_val)); /* PM1a_CNT.SLP_TYP */
+        aml_append(&pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+        aml_append(&pkg, acpi_int(0)); /* reserved */
+        aml_append(&pkg, acpi_int(0)); /* reserved */
+        aml_append(&scope, acpi_name_decl("_S4", pkg));
+    }
+
+    pkg = acpi_package(4);
+    aml_append(&pkg, acpi_int(0)); /* PM1a_CNT.SLP_TYP */
+    aml_append(&pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+    aml_append(&pkg, acpi_int(0)); /* reserved */
+    aml_append(&pkg, acpi_int(0)); /* reserved */
+    aml_append(&scope, acpi_name_decl("_S5", pkg));
+    aml_append(&table_aml, scope);
+
     {
         AcpiAml sb_scope = acpi_scope("_SB");
 
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 96382a6..26b9241 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -41,39 +41,6 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
     }
 
 
-/****************************************************************
- * Suspend
- ****************************************************************/
-
-    Scope(\) {
-    /*
-     * S3 (suspend-to-ram), S4 (suspend-to-disk) and S5 (power-off) type codes:
-     * must match piix4 emulation.
-     */
-
-        ACPI_EXTRACT_NAME_STRING acpi_s3_name
-        Name(_S3, Package(0x04) {
-            One,  /* PM1a_CNT.SLP_TYP */
-            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
-            Zero,  /* reserved */
-            Zero   /* reserved */
-        })
-        ACPI_EXTRACT_NAME_STRING acpi_s4_name
-        ACPI_EXTRACT_PKG_START acpi_s4_pkg
-        Name(_S4, Package(0x04) {
-            0x2,  /* PM1a_CNT.SLP_TYP */
-            Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
-            Zero,  /* reserved */
-            Zero   /* reserved */
-        })
-        Name(_S5, Package(0x04) {
-            Zero,  /* PM1a_CNT.SLP_TYP */
-            Zero,  /* PM1b_CNT.SLP_TYP */
-            Zero,  /* reserved */
-            Zero   /* reserved */
-        })
-    }
-
     External(\_SB.PCI0, DeviceObj)
     External(\_SB.PCI0.ISA, DeviceObj)
 
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 20/47] acpi: add acpi_buffer() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (18 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 19/47] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 21/47] acpi: add acpi_resource_template() helper Igor Mammedov
                   ` (26 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index ae23b4a..d5acbcb 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -468,6 +468,13 @@ AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefBuffer */
+AcpiAml acpi_buffer(void)
+{
+    AcpiAml var = aml_allocate_internal(0x11 /* BufferOp */, BUFFER);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefPackage */
 AcpiAml acpi_package(uint8_t num_elements)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index e34e19a..a79c085 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -45,6 +45,7 @@ AcpiAml acpi_if(AcpiAml predicate);
 AcpiAml acpi_method(const char *name, int arg_count);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
+AcpiAml acpi_buffer(void);
 AcpiAml acpi_package(uint8_t num_elements);
 
 /* other helpers */
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 21/47] acpi: add acpi_resource_template() helper
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (19 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 20/47] acpi: add acpi_buffer() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 22/47] acpi: add acpi_io() helper Igor Mammedov
                   ` (25 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index d5acbcb..01d5c77 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -468,6 +468,14 @@ AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...)
     return var;
 }
 
+/* ResourceTemplate marcos helper */
+AcpiAml acpi_resource_template(void)
+{
+    /* ResourceTemplate is a buffer of Resources with EndTag at the end */
+    AcpiAml var = aml_allocate_internal(0x11 /* BufferOp */, RES_TEMPLATE);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefBuffer */
 AcpiAml acpi_buffer(void)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index a79c085..594fae7 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -46,6 +46,7 @@ AcpiAml acpi_method(const char *name, int arg_count);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
 AcpiAml acpi_buffer(void);
+AcpiAml acpi_resource_template(void);
 AcpiAml acpi_package(uint8_t num_elements);
 
 /* other helpers */
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 22/47] acpi: add acpi_io() helper
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (20 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 21/47] acpi: add acpi_resource_template() helper Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 23/47] acpi: include PkgLength size only when requested Igor Mammedov
                   ` (24 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 01d5c77..e9b2606 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -429,6 +429,25 @@ AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2,
     return var;
 }
 
+/*
+ * ACPI 5.0: 19.5.62 IO (IO Resource Descriptor Macro)
+ *           6.4.2 Small Resource Data Type
+*/
+AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
+                uint8_t aln, uint8_t len)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    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 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 594fae7..91575f1 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -19,6 +19,11 @@ typedef struct AcpiAml {
     AcpiBlockFlags block_flags;
 } AcpiAml;
 
+typedef enum {
+    acpi_decode10 = 0,
+    acpi_decode16 = 1,
+} acpiIODecode;
+
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* non block ASL object primitives */
@@ -39,6 +44,8 @@ AcpiAml acpi_call3(const char *method, AcpiAml arg1, AcpiAml arg2,
                    AcpiAml arg3);
 AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2,
                    AcpiAml arg3, AcpiAml arg4);
+AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
+                uint8_t aln, uint8_t len);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 23/47] acpi: include PkgLength size only when requested
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (21 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 22/47] acpi: add acpi_io() helper Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 24/47] acpi: add acpi_operation_region() term Igor Mammedov
                   ` (23 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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/acpi_gen_utils.c         | 20 +++++++++++++++-----
 include/hw/acpi/acpi_gen_utils.h |  3 ++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index e9b2606..37d59d0 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -142,10 +142,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)) {
@@ -158,8 +158,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:
@@ -192,7 +202,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/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 91575f1..176596e 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -66,7 +66,8 @@ void build_append_array(GArray *array, GArray *val);
 void GCC_FMT_ATTR(2, 3)
 build_append_namestring(GArray *array, const char *format, ...);
 
-void build_prepend_package_length(GArray *package);
+void
+build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
 void build_package(GArray *package, uint8_t op);
 void build_append_value(GArray *table, uint64_t value, int size);
 void build_append_int(GArray *table, uint64_t value);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 24/47] acpi: add acpi_operation_region() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (22 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 23/47] acpi: include PkgLength size only when requested Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 25/47] acpi: add acpi_field() & acpi_named_field() terms Igor Mammedov
                   ` (22 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 37d59d0..c69c708 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -519,3 +519,17 @@ AcpiAml acpi_package(uint8_t num_elements)
     build_append_byte(var.buf, num_elements);
     return var;
 }
+
+/* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefOpRegion */
+AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
+                              uint32_t offset, uint32_t len)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    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/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 176596e..cb45129 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -24,6 +24,11 @@ typedef enum {
     acpi_decode16 = 1,
 } acpiIODecode;
 
+typedef enum {
+    acpi_system_memory = 0x00,
+    acpi_system_io = 0x01,
+} acpiRegionSpace;
+
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* non block ASL object primitives */
@@ -46,6 +51,8 @@ AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2,
                    AcpiAml arg3, AcpiAml arg4);
 AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
                 uint8_t aln, uint8_t len);
+AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
+                              uint32_t offset, uint32_t len);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 25/47] acpi: add acpi_field() & acpi_named_field() terms
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (23 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 24/47] acpi: add acpi_operation_region() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 26/47] acpi: add acpi_local0() term Igor Mammedov
                   ` (21 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index c69c708..acb40fb 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -200,6 +200,15 @@ 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);
@@ -533,3 +542,21 @@ AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
     build_append_int(var.buf, len);
     return var;
 }
+
+/* ACPI 5.0: 20.2.5.2 Named Objects Encoding: NamedField */
+AcpiAml acpi_named_field(const char *name, unsigned length)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_nameseg(var.buf, "%s", name);
+    build_append_pkg_length(var.buf, length, false);
+    return var;
+}
+
+/* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefField */
+AcpiAml acpi_field(const char *name, acpiFieldFlags flags)
+{
+    AcpiAml var = aml_allocate_internal(0x81 /* FieldOp */, EXT_PACKAGE);
+    build_append_namestring(var.buf, "%s", name);
+    build_append_byte(var.buf, flags);
+    return var;
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index cb45129..b94098a 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -25,6 +25,10 @@ typedef enum {
 } acpiIODecode;
 
 typedef enum {
+    acpi_byte_acc = 1,
+} acpiFieldFlags;
+
+typedef enum {
     acpi_system_memory = 0x00,
     acpi_system_io = 0x01,
 } acpiRegionSpace;
@@ -53,6 +57,7 @@ AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
                 uint8_t aln, uint8_t len);
 AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
                               uint32_t offset, uint32_t len);
+AcpiAml acpi_named_field(const char *name, unsigned length);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
@@ -62,6 +67,7 @@ AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
 AcpiAml acpi_buffer(void);
 AcpiAml acpi_resource_template(void);
 AcpiAml acpi_package(uint8_t num_elements);
+AcpiAml acpi_field(const char *name, acpiFieldFlags flags);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 26/47] acpi: add acpi_local0() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (24 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 25/47] acpi: add acpi_field() & acpi_named_field() terms Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 27/47] acpi: add acpi_string() term Igor Mammedov
                   ` (20 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index acb40fb..6bd7974 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -560,3 +560,11 @@ AcpiAml acpi_field(const char *name, acpiFieldFlags flags)
     build_append_byte(var.buf, flags);
     return var;
 }
+
+/* ACPI 5.0: 20.2.6.2 Local Objects Encoding: Local0Op */
+AcpiAml acpi_local0(void)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x60); /* Local0Op */
+    return var;
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index b94098a..8261ee5 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -58,6 +58,7 @@ AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
 AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
                               uint32_t offset, uint32_t len);
 AcpiAml acpi_named_field(const char *name, unsigned length);
+AcpiAml acpi_local0(void);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 27/47] acpi: add acpi_string() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (25 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 26/47] acpi: add acpi_local0() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 28/47] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
                   ` (19 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 6bd7974..920d8c2 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -561,6 +561,32 @@ AcpiAml acpi_field(const char *name, acpiFieldFlags flags)
     return var;
 }
 
+/* ACPI 5.0: 20.2.3 Data Objects Encoding: String */
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    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_new(typeof(*s), len);
+
+    len = vsnprintf(s, len, name_format, ap);
+    va_end(ap);
+
+    build_append_byte(var.buf, 0x0D); /* StringPrefix */
+    g_array_append_vals(var.buf, s, len);
+    build_append_byte(var.buf, 0x0); /* NullChar */
+    g_free(s);
+
+    return var;
+}
+
 /* ACPI 5.0: 20.2.6.2 Local Objects Encoding: Local0Op */
 AcpiAml acpi_local0(void)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 8261ee5..c823fb8 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -58,6 +58,7 @@ AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
 AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
                               uint32_t offset, uint32_t len);
 AcpiAml acpi_named_field(const char *name, unsigned length);
+AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...);
 AcpiAml acpi_local0(void);
 
 /* Block ASL object primitives */
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 28/47] pc: acpi-build: generate pvpanic device description dynamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (26 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 27/47] acpi: add acpi_string() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 29/47] acpi: add acpi_varpackage() term Igor Mammedov
                   ` (18 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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 48a72ad..b1495b6 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -754,7 +754,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     int ssdt_start = table_data->len;
     AcpiAml table_aml = { .buf = table_data };
     uint8_t *ssdt_ptr;
-    AcpiAml pkg, scope;
+    AcpiAml pkg, scope, dev, method, crs, field;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -769,9 +769,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 */
@@ -802,6 +799,37 @@ build_ssdt(GArray *table_data, GArray *linker,
     aml_append(&scope, acpi_name_decl("_S5", pkg));
     aml_append(&table_aml, scope);
 
+    if (misc->pvpanic_port) {
+        scope = acpi_scope("\\_SB.PCI0.ISA");
+
+        dev = acpi_device("PEVR");
+        aml_append(&dev, acpi_name_decl("_HID", acpi_string("QEMU0002")));
+
+        crs = acpi_resource_template();
+        aml_append(&crs,
+            acpi_io(acpi_decode16, misc->pvpanic_port, misc->pvpanic_port, 1, 1)
+        );
+        aml_append(&dev, acpi_name_decl("_CRS", crs));
+
+        aml_append(&dev, acpi_operation_region("PEOR", acpi_system_io,
+                                               misc->pvpanic_port, 1));
+        field = acpi_field("PEOR", acpi_byte_acc);
+        aml_append(&field, acpi_named_field("PEPT", 8));
+        aml_append(&dev, field);
+
+        method = acpi_method("RDPT", 0);
+        aml_append(&method, acpi_store(acpi_name("PEPT"), acpi_local0()));
+        aml_append(&method, acpi_return(acpi_local0()));
+        aml_append(&dev, method);
+
+        method = acpi_method("WRPT", 1);
+        aml_append(&method, acpi_store(acpi_arg0(), acpi_name("PEPT")));
+        aml_append(&dev, method);
+
+        aml_append(&scope, dev);
+        aml_append(&table_aml, scope);
+    }
+
     {
         AcpiAml sb_scope = acpi_scope("_SB");
 
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] 58+ messages in thread

* [Qemu-devel] [RFC 29/47] acpi: add acpi_varpackage() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (27 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 28/47] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 30/47] acpi: add acpi_equal() term Igor Mammedov
                   ` (17 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 920d8c2..985ee33 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -594,3 +594,11 @@ AcpiAml acpi_local0(void)
     build_append_byte(var.buf, 0x60); /* Local0Op */
     return var;
 }
+
+/* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefVarPackage */
+AcpiAml acpi_varpackage(uint32_t num_elements)
+{
+    AcpiAml var = aml_allocate_internal(0x13 /* VarPackageOp */, PACKAGE);
+    build_append_int(var.buf, num_elements);
+    return var;
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index c823fb8..8a21b4b 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -70,6 +70,7 @@ AcpiAml acpi_buffer(void);
 AcpiAml acpi_resource_template(void);
 AcpiAml acpi_package(uint8_t num_elements);
 AcpiAml acpi_field(const char *name, acpiFieldFlags flags);
+AcpiAml acpi_varpackage(uint32_t num_elements);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 30/47] acpi: add acpi_equal() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (28 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 29/47] acpi: add acpi_varpackage() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 31/47] acpi: add acpi_processor() term Igor Mammedov
                   ` (16 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 985ee33..2de1ea6 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -467,6 +467,17 @@ AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefLEqual */
+AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    build_append_byte(var.buf, 0x93); /* LequalOp */
+    aml_append(&var, arg1);
+    aml_append(&var, arg2);
+    build_append_int(var.buf, 0x00); /* NullNameOp */
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 AcpiAml acpi_if(AcpiAml predicate)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 8a21b4b..76b8d9f 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -60,6 +60,7 @@ AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
 AcpiAml acpi_named_field(const char *name, unsigned length);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...);
 AcpiAml acpi_local0(void);
+AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 31/47] acpi: add acpi_processor() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (29 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 30/47] acpi: add acpi_equal() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 32/47] acpi: add acpi_eisaid() term Igor Mammedov
                   ` (15 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 2de1ea6..4606d1e 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -613,3 +613,23 @@ AcpiAml acpi_varpackage(uint32_t num_elements)
     build_append_int(var.buf, num_elements);
     return var;
 }
+
+/* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefProcessor */
+AcpiAml GCC_FMT_ATTR(4, 5)
+acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
+               const char *name_format, ...)
+{
+    va_list ap;
+    AcpiAml var = aml_allocate_internal(0x83 /* ProcessorOp */, 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 */
+    /* PblkAddr */
+    build_append_byte(var.buf, pblk_addr & 0xFF);
+    build_append_byte(var.buf, (pblk_addr >> 8) & 0xFF);
+    build_append_byte(var.buf, (pblk_addr >> 16) & 0xFF);
+    build_append_byte(var.buf, (pblk_addr >> 24) & 0xFF);
+    build_append_byte(var.buf, pblk_len); /* PblkLen */
+    return var;
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 76b8d9f..753171f 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -61,6 +61,9 @@ AcpiAml acpi_named_field(const char *name, unsigned length);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...);
 AcpiAml acpi_local0(void);
 AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2);
+AcpiAml GCC_FMT_ATTR(4, 5)
+acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
+               const char *name_format, ...);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 32/47] acpi: add acpi_eisaid() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (30 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 31/47] acpi: add acpi_processor() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 33/47] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
                   ` (14 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 4606d1e..68d1855 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -2,7 +2,9 @@
 #include <stdarg.h>
 #include <assert.h>
 #include <stdbool.h>
+#include <string.h>
 #include "hw/acpi/acpi_gen_utils.h"
+#include "qemu/bswap.h"
 
 GArray *build_alloc_array(void)
 {
@@ -633,3 +635,32 @@ acpi_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 5.0: 19.5.36 EISAID (EISA ID String To Integer Conversion Macro) */
+AcpiAml acpi_eisaid(const char *str)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    uint32_t id;
+
+    g_assert(strlen(str) == 7);
+    id = (str[0] - 0x40) << 26 |
+    (str[1] - 0x40) << 21 |
+    (str[2] - 0x40) << 16 |
+    Hex2Digit(str[3]) << 12 |
+    Hex2Digit(str[4]) << 8 |
+    Hex2Digit(str[5]) << 4 |
+    Hex2Digit(str[6]);
+
+    build_append_byte(var.buf, 0x0C); /* DWordPrefix */
+    build_append_value(var.buf, bswap32(id), sizeof(id));
+    return var;
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 753171f..02d5aa8 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -64,6 +64,7 @@ AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2);
 AcpiAml GCC_FMT_ATTR(4, 5)
 acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
                const char *name_format, ...);
+AcpiAml acpi_eisaid(const char *str);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 33/47] pc: acpi-build: drop template patching and CPU hotplug objects dynamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (31 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 32/47] acpi: add acpi_eisaid() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 34/47] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
                   ` (13 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

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

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index d8dd99f..92f2ee6 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
 obj-y += acpi-build.o
 obj-y += bios-linker-loader.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-	hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b1495b6..cf6c166 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -507,22 +507,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
                  table_data->len - madt_start, 1);
 }
 
-/* Encode a hex value */
-static inline char acpi_get_hex(uint32_t val)
-{
-    val &= 0x0f;
-    return (val <= 9) ? ('0' + val) : ('A' + val - 10);
-}
-
-#include "hw/i386/ssdt-proc.hex"
-
-/* 0x5B 0x83 ProcessorOp PkgLength NameString ProcID */
-#define ACPI_PROC_OFFSET_CPUHEX (*ssdt_proc_name - *ssdt_proc_start + 2)
-#define ACPI_PROC_OFFSET_CPUID1 (*ssdt_proc_name - *ssdt_proc_start + 4)
-#define ACPI_PROC_OFFSET_CPUID2 (*ssdt_proc_id - *ssdt_proc_start)
-#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
-#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
-
 #include "hw/i386/ssdt-mem.hex"
 
 /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
@@ -754,7 +738,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     int ssdt_start = table_data->len;
     AcpiAml table_aml = { .buf = table_data };
     uint8_t *ssdt_ptr;
-    AcpiAml pkg, scope, dev, method, crs, field;
+    AcpiAml pkg, scope, dev, method, crs, field, ifctx;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -835,50 +819,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 = acpi_processor(i, 0, 0, "CP%.02X", i);
+
+            method = acpi_method("_MAT", 0);
+            aml_append(&method, acpi_return(acpi_call1("CPMA", acpi_int(i))));
+            aml_append(&dev, method);
+
+            method = acpi_method("_STA", 0);
+            aml_append(&method, acpi_return(acpi_call1("CPST", acpi_int(i))));
+            aml_append(&dev, method);
+
+            method = acpi_method("_EJ0", 1);
+            aml_append(&method,
+                acpi_return(acpi_call2("CPEJ", acpi_int(i), acpi_arg0()))
+            );
+            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 = acpi_method("NTFY", 2);
+        for (i = 0; i < acpi_cpus; i++) {
+            ifctx = acpi_if(acpi_equal(acpi_arg0(), acpi_int(i)));
+            aml_append(&ifctx,
+                acpi_notify(acpi_name("CP%.02X", i), acpi_arg1())
+            );
+            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 ? acpi_package(acpi_cpus) :
+                                 acpi_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, acpi_int(b));
         }
+        aml_append(&sb_scope, acpi_name_decl("CPON", pkg));
 
         if (nr_mem) {
             assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
diff --git a/hw/i386/ssdt-proc.dsl b/hw/i386/ssdt-proc.dsl
deleted file mode 100644
index 8229bfd..0000000
--- a/hw/i386/ssdt-proc.dsl
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/* This file is the basis for the ssdt table generated in src/acpi.c.
- * It defines the contents of the per-cpu Processor() object.  At
- * runtime, a dynamically generated SSDT will contain one copy of this
- * AML snippet for every possible cpu in the system.  The objects will
- * be placed in the \_SB_ namespace.
- *
- * In addition to the aml code generated from this file, the
- * src/acpi.c file creates a NTFY method with an entry for each cpu:
- *     Method(NTFY, 2) {
- *         If (LEqual(Arg0, 0x00)) { Notify(CP00, Arg1) }
- *         If (LEqual(Arg0, 0x01)) { Notify(CP01, Arg1) }
- *         ...
- *     }
- * and a CPON array with the list of active and inactive cpus:
- *     Name(CPON, Package() { One, One, ..., Zero, Zero, ... })
- */
-
-ACPI_EXTRACT_ALL_CODE ssdp_proc_aml
-
-DefinitionBlock ("ssdt-proc.aml", "SSDT", 0x01, "BXPC", "BXSSDT", 0x1)
-{
-    ACPI_EXTRACT_PROCESSOR_START ssdt_proc_start
-    ACPI_EXTRACT_PROCESSOR_END ssdt_proc_end
-    ACPI_EXTRACT_PROCESSOR_STRING ssdt_proc_name
-    Processor(CPAA, 0xAA, 0x00000000, 0x0) {
-        ACPI_EXTRACT_NAME_BYTE_CONST ssdt_proc_id
-        Name(ID, 0xAA)
-/*
- * The src/acpi.c code requires the above ACP_EXTRACT tags so that it can update
- * CPAA and 0xAA with the appropriate CPU id (see
- * SD_OFFSET_CPUHEX/CPUID1/CPUID2).  Don't change the above without
- * also updating the C code.
- */
-        Name(_HID, "ACPI0007")
-        External(CPMA, MethodObj)
-        External(CPST, MethodObj)
-        External(CPEJ, MethodObj)
-        Method(_MAT, 0) {
-            Return (CPMA(ID))
-        }
-        Method(_STA, 0) {
-            Return (CPST(ID))
-        }
-        Method(_EJ0, 1, NotSerialized) {
-            CPEJ(ID, Arg0)
-        }
-    }
-}
diff --git a/hw/i386/ssdt-proc.hex.generated b/hw/i386/ssdt-proc.hex.generated
deleted file mode 100644
index 4df0734..0000000
--- a/hw/i386/ssdt-proc.hex.generated
+++ /dev/null
@@ -1,134 +0,0 @@
-static unsigned char ssdt_proc_name[] = {
-0x28
-};
-static unsigned char ssdp_proc_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0x78,
-0x0,
-0x0,
-0x0,
-0x1,
-0x7d,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x0,
-0x0,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x15,
-0x11,
-0x13,
-0x20,
-0x5b,
-0x83,
-0x42,
-0x5,
-0x43,
-0x50,
-0x41,
-0x41,
-0xaa,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0xa,
-0xaa,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xd,
-0x41,
-0x43,
-0x50,
-0x49,
-0x30,
-0x30,
-0x30,
-0x37,
-0x0,
-0x14,
-0xf,
-0x5f,
-0x4d,
-0x41,
-0x54,
-0x0,
-0xa4,
-0x43,
-0x50,
-0x4d,
-0x41,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x14,
-0xf,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0xa4,
-0x43,
-0x50,
-0x53,
-0x54,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x14,
-0xf,
-0x5f,
-0x45,
-0x4a,
-0x30,
-0x1,
-0x43,
-0x50,
-0x45,
-0x4a,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x68
-};
-static unsigned char ssdt_proc_id[] = {
-0x38
-};
-static unsigned char ssdt_proc_end[] = {
-0x78
-};
-static unsigned char ssdt_proc_start[] = {
-0x24
-};
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 34/47] pc: acpi-build: create CPU hotplug IO region dynamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (32 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 33/47] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 35/47] acpi: add acpi_reserved_field() term Igor Mammedov
                   ` (12 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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 cf6c166..7829ea5 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -98,6 +98,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 {
@@ -174,12 +176,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) {
@@ -817,6 +822,28 @@ build_ssdt(GArray *table_data, GArray *linker,
     {
         AcpiAml sb_scope = acpi_scope("_SB");
 
+        /* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */
+        dev = acpi_device("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE));
+        aml_append(&dev, acpi_name_decl("_HID", acpi_eisaid("PNP0A06")));
+        aml_append(&dev,
+            acpi_name_decl("_UID", acpi_string("CPU Hotplug resources"))
+        );
+        /* device present, functioning, decoding, not shown in UI */
+        aml_append(&dev, acpi_name_decl("_STA", acpi_int(0xB)));
+        crs = acpi_resource_template();
+        aml_append(&crs,
+            acpi_io(acpi_decode16, pm->cpu_hp_io_base, pm->cpu_hp_io_base,
+                    1, pm->cpu_hp_io_len)
+        );
+        aml_append(&dev, acpi_name_decl("_CRS", crs));
+        aml_append(&sb_scope, dev);
+        /* declare CPU hotplug MMIO region and PRS field to access it */
+        aml_append(&sb_scope, acpi_operation_region(
+            "PRST", acpi_system_io, pm->cpu_hp_io_base, pm->cpu_hp_io_len));
+        field = acpi_field("PRST", acpi_byte_acc);
+        aml_append(&field, acpi_named_field("PRS", 256));
+        aml_append(&sb_scope, field);
+
         /* build Processor object for each processor */
         for (i = 0; i < acpi_cpus; i++) {
             dev = acpi_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] 58+ messages in thread

* [Qemu-devel] [RFC 35/47] acpi: add acpi_reserved_field() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (33 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 34/47] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 36/47] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
                   ` (11 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 68d1855..a77d18c 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -565,6 +565,16 @@ AcpiAml acpi_named_field(const char *name, unsigned length)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.2 Named Objects Encoding: ReservedField */
+AcpiAml acpi_reserved_field(unsigned length)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    /* ReservedField  := 0x00 PkgLength */
+    build_append_byte(var.buf, 0x00);
+    build_append_pkg_length(var.buf, length, false);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefField */
 AcpiAml acpi_field(const char *name, acpiFieldFlags flags)
 {
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 02d5aa8..048ed26 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -25,7 +25,12 @@ typedef enum {
 } acpiIODecode;
 
 typedef enum {
+    acpi_any_acc = 0,
     acpi_byte_acc = 1,
+    acpi_word_acc = 2,
+    acpi_dword_acc = 3,
+    acpi_qword_acc = 4,
+    acpi_buffer_acc = 5,
 } acpiFieldFlags;
 
 typedef enum {
@@ -58,6 +63,7 @@ AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base,
 AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs,
                               uint32_t offset, uint32_t len);
 AcpiAml acpi_named_field(const char *name, unsigned length);
+AcpiAml acpi_reserved_field(unsigned length);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...);
 AcpiAml acpi_local0(void);
 AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 36/47] pc: acpi-build: drop template patching and memory hotplug objects dynamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (34 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 35/47] acpi: add acpi_reserved_field() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 37/47] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
                   ` (10 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

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

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 92f2ee6..790a56c 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -10,7 +10,7 @@ obj-y += acpi-build.o
 obj-y += bios-linker-loader.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
 	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
     ; then echo "$(2)"; else echo "$(3)"; fi ;)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 7829ea5..241bb2a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -279,48 +279,6 @@ build_header(GArray *linker, GArray *table_data,
                                     table_data->data, h, len, &h->checksum);
 }
 
-static GArray *build_alloc_method(const char *name, uint8_t arg_count)
-{
-    GArray *method = build_alloc_array();
-
-    build_append_namestring(method, "%s", name);
-    build_append_byte(method, arg_count); /* MethodFlags: ArgCount */
-
-    return method;
-}
-
-static void build_append_and_cleanup_method(GArray *device, GArray *method)
-{
-    uint8_t op = 0x14; /* MethodOp */
-
-    build_package(method, op);
-
-    build_append_array(device, method);
-    build_free_array(method);
-}
-
-static void build_append_notify_target_ifequal(GArray *method,
-                                               GArray *target_name,
-                                               uint32_t value, int size)
-{
-    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_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 */
 
@@ -512,38 +470,12 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
                  table_data->len - madt_start, 1);
 }
 
-#include "hw/i386/ssdt-mem.hex"
-
-/* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
-#define ACPI_MEM_OFFSET_HEX (*ssdt_mem_name - *ssdt_mem_start + 2)
-#define ACPI_MEM_OFFSET_ID (*ssdt_mem_id - *ssdt_mem_start + 7)
-#define ACPI_MEM_SIZEOF (*ssdt_mem_end - *ssdt_mem_start)
-#define ACPI_MEM_AML (ssdm_mem_aml + *ssdt_mem_start)
-
 #define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 #define ACPI_SSDT_HEADER_LENGTH 36
 
 #include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
-static void
-build_append_notify_method(GArray *device, const char *name,
-                           const char *format, int count)
-{
-    int i;
-    GArray *method = build_alloc_method(name, 2);
-
-    for (i = 0; i < count; i++) {
-        GArray *target = build_alloc_array();
-        build_append_namestring(target, format, i);
-        assert(i < 256); /* Fits in 1 byte */
-        build_append_notify_target_ifequal(method, target, i, 1);
-        build_free_array(target);
-    }
-
-    build_append_and_cleanup_method(device, method);
-}
-
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
  */
@@ -895,27 +827,55 @@ build_ssdt(GArray *table_data, GArray *linker,
         }
         aml_append(&sb_scope, acpi_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 = acpi_device("MP%02X", i);
+            aml_append(&dev, acpi_name_decl("_UID", acpi_string("0x%02X", i)));
+            aml_append(&dev, acpi_name_decl("_HID", acpi_eisaid("PNP0C80")));
+
+            method = acpi_method("_CRS", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_CRS_METHOD);
+            aml_append(&method, acpi_return(acpi_call1(s, acpi_name("_UID"))));
+            aml_append(&dev, method);
+
+            method = acpi_method("_STA", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_STATUS_METHOD);
+            aml_append(&method, acpi_return(acpi_call1(s, acpi_name("_UID"))));
+            aml_append(&dev, method);
+
+            method = acpi_method("_PXM", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_PROXIMITY_METHOD);
+            aml_append(&method, acpi_return(acpi_call1(s, acpi_name("_UID"))));
+            aml_append(&dev, method);
 
-            /* 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 = acpi_method("_OST", 3);
+            s = BASEPATH stringify(MEMORY_SLOT_OST_METHOD);
+            aml_append(&method, acpi_return(acpi_call4(
+                s, acpi_name("_UID"), acpi_arg0(), acpi_arg1(), acpi_arg2()
+            )));
+            aml_append(&dev, method);
+
+            aml_append(&sb_scope, dev);
         }
 
+        /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
+         *     If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
+         */
+        method = acpi_method(stringify(MEMORY_SLOT_NOTIFY_METHOD), 2);
+        for (i = 0; i < nr_mem; i++) {
+            ifctx = acpi_if(acpi_equal(acpi_arg0(), acpi_int(i)));
+            aml_append(&ifctx,
+                acpi_notify(acpi_name("MP%.02X", i), acpi_arg1())
+            );
+            aml_append(&method, ifctx);
+        }
+        aml_append(&sb_scope, method);
+
         {
             Object *pci_host;
             PCIBus *bus = NULL;
diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
deleted file mode 100644
index 22ff5dd..0000000
--- a/hw/i386/ssdt-mem.dsl
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Memory hotplug ACPI DSDT static objects definitions
- *
- * Copyright ProfitBricks GmbH 2012
- * Copyright (C) 2013-2014 Red Hat Inc
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>
- */
-
-/* This file is the basis for the ssdt_mem[] variable in src/acpi.c.
- * It defines the contents of the memory device object.  At
- * runtime, a dynamically generated SSDT will contain one copy of this
- * AML snippet for every possible memory device in the system.  The
- * objects will be placed in the \_SB_ namespace.
- *
- * In addition to the aml code generated from this file, the
- * src/acpi.c file creates a MTFY method with an entry for each memdevice:
- *     Method(MTFY, 2) {
- *         If (LEqual(Arg0, 0x00)) { Notify(MP00, Arg1) }
- *         If (LEqual(Arg0, 0x01)) { Notify(MP01, Arg1) }
- *         ...
- *     }
- */
-#include "hw/acpi/pc-hotplug.h"
-
-ACPI_EXTRACT_ALL_CODE ssdm_mem_aml
-
-DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1)
-{
-
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_CRS_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, MethodObj)
-
-    Scope(\_SB) {
-/*  v------------------ DO NOT EDIT ------------------v */
-        ACPI_EXTRACT_DEVICE_START ssdt_mem_start
-        ACPI_EXTRACT_DEVICE_END ssdt_mem_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_mem_name
-        Device(MPAA) {
-            ACPI_EXTRACT_NAME_STRING ssdt_mem_id
-            Name(_UID, "0xAA")
-/*  ^------------------ DO NOT EDIT ------------------^
- * Don't change the above without also updating the C code.
- */
-            Name(_HID, EISAID("PNP0C80"))
-
-            Method(_CRS, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_CRS_METHOD(_UID))
-            }
-
-            Method(_STA, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD(_UID))
-            }
-
-            Method(_PXM, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD(_UID))
-            }
-
-            Method(_OST, 3) {
-                \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, Arg0, Arg1, Arg2)
-            }
-        }
-    }
-}
diff --git a/hw/i386/ssdt-mem.hex.generated b/hw/i386/ssdt-mem.hex.generated
deleted file mode 100644
index b3bfbbd..0000000
--- a/hw/i386/ssdt-mem.hex.generated
+++ /dev/null
@@ -1,213 +0,0 @@
-static unsigned char ssdt_mem_id[] = {
-0x35
-};
-static unsigned char ssdm_mem_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0xc7,
-0x0,
-0x0,
-0x0,
-0x2,
-0x66,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x43,
-0x53,
-0x53,
-0x44,
-0x54,
-0x0,
-0x0,
-0x0,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x28,
-0x8,
-0x14,
-0x20,
-0x10,
-0x42,
-0xa,
-0x5c,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x5b,
-0x82,
-0x49,
-0x9,
-0x4d,
-0x50,
-0x41,
-0x41,
-0x8,
-0x5f,
-0x55,
-0x49,
-0x44,
-0xd,
-0x30,
-0x78,
-0x41,
-0x41,
-0x0,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xc,
-0x80,
-0x14,
-0x1e,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x43,
-0x52,
-0x53,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x1e,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x52,
-0x53,
-0x54,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x1e,
-0x5f,
-0x50,
-0x58,
-0x4d,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x50,
-0x58,
-0x4d,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x20,
-0x5f,
-0x4f,
-0x53,
-0x54,
-0x3,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x4f,
-0x53,
-0x54,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x68,
-0x69,
-0x6a
-};
-static unsigned char ssdt_mem_start[] = {
-0x2c
-};
-static unsigned char ssdt_mem_end[] = {
-0xc7
-};
-static unsigned char ssdt_mem_name[] = {
-0x30
-};
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 37/47] pc: acpi-build: create memory hotplug IO region dynamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (35 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 36/47] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 38/47] acpi: add acpi_word_bus_number(), acpi_word_io(), acpi_dword_memory(), acpi_qword_memory() terms Igor Mammedov
                   ` (9 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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 241bb2a..ec0aac6 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -100,6 +100,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 {
@@ -185,6 +187,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) {
@@ -689,9 +694,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 = acpi_scope("\\");
     if (!pm->s3_disabled) {
@@ -829,6 +831,55 @@ build_ssdt(GArray *table_data, GArray *linker,
 
         /* build memory devices */
         assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
+        scope = acpi_scope("\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE));
+        aml_append(&scope,
+            acpi_name_decl(stringify(MEMORY_SLOTS_NUMBER), acpi_int(nr_mem))
+        );
+
+        crs = acpi_resource_template();
+        aml_append(&crs,
+            acpi_io(acpi_decode16, pm->mem_hp_io_base, pm->mem_hp_io_base,
+                    0, pm->mem_hp_io_len)
+        );
+        aml_append(&scope, acpi_name_decl("_CRS", crs));
+
+        aml_append(&scope, acpi_operation_region(
+            stringify(MEMORY_HOTPLUG_IO_REGION), acpi_system_io,
+            pm->mem_hp_io_base, pm->mem_hp_io_len)
+        );
+
+        field = acpi_field(stringify(MEMORY_HOTPLUG_IO_REGION), acpi_dword_acc);
+        aml_append(&field, /* read only */
+            acpi_named_field(stringify(MEMORY_SLOT_ADDR_LOW), 32));
+        aml_append(&field, /* read only */
+            acpi_named_field(stringify(MEMORY_SLOT_ADDR_HIGH), 32));
+        aml_append(&field, /* read only */
+            acpi_named_field(stringify(MEMORY_SLOT_SIZE_LOW), 32));
+        aml_append(&field, /* read only */
+            acpi_named_field(stringify(MEMORY_SLOT_SIZE_HIGH), 32));
+        aml_append(&field, /* read only */
+            acpi_named_field(stringify(MEMORY_SLOT_PROXIMITY), 32));
+        aml_append(&scope, field);
+
+        field = acpi_field(stringify(MEMORY_HOTPLUG_IO_REGION), acpi_byte_acc);
+        aml_append(&field, acpi_reserved_field(160 /* Offset(20) */));
+        aml_append(&field, /* 1 if enabled, read only */
+            acpi_named_field(stringify(MEMORY_SLOT_ENABLED), 1));
+        aml_append(&field,
+            /*(read) 1 if has a insert event. (write) 1 to clear event */
+            acpi_named_field(stringify(MEMORY_SLOT_INSERT_EVENT), 1));
+        aml_append(&scope, field);
+
+        field = acpi_field(stringify(MEMORY_HOTPLUG_IO_REGION), acpi_dword_acc);
+        aml_append(&field, /* DIMM selector, write only */
+            acpi_named_field(stringify(MEMORY_SLOT_SLECTOR), 32));
+        aml_append(&field, /* _OST event code, write only */
+            acpi_named_field(stringify(MEMORY_SLOT_OST_EVENT), 32));
+        aml_append(&field, /* _OST status code, write only */
+            acpi_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] 58+ messages in thread

* [Qemu-devel] [RFC 38/47] acpi: add acpi_word_bus_number(), acpi_word_io(), acpi_dword_memory(), acpi_qword_memory() terms
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (36 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 37/47] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 39/47] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
                   ` (8 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/acpi_gen_utils.c         | 143 +++++++++++++++++++++++++++++++++++++++
 include/hw/acpi/acpi_gen_utils.h |  73 ++++++++++++++++++++
 2 files changed, 216 insertions(+)

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index a77d18c..39cbab7 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -674,3 +674,146 @@ AcpiAml acpi_eisaid(const char *str)
     build_append_value(var.buf, bswap32(id), sizeof(id));
     return var;
 }
+
+/* ACPI 5.0: 6.4.3.5.3 Word Address Space Descriptor */
+static AcpiAml
+acpi_as_desc_header(acpiResourceType type, acpiMinFixed min_fixed,
+                    acpiMaxFixed max_fixed, acpiDecode dec, uint8_t type_flags)
+{
+    uint8_t flags = max_fixed | min_fixed | dec;
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+
+    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 5.0: 6.4.3.5.3 Word Address Space Descriptor */
+static AcpiAml acpi_word_as_desc(acpiResourceType type, acpiMinFixed min_fixed,
+                                 acpiMaxFixed max_fixed, acpiDecode dec,
+                                 uint16_t addr_gran, uint16_t addr_min,
+                                 uint16_t addr_max, uint16_t addr_trans,
+                                 uint16_t len, uint8_t type_flags)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+
+    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,
+        acpi_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+    build_append_value(var.buf, addr_gran, sizeof(addr_gran));
+    build_append_value(var.buf, addr_min, sizeof(addr_min));
+    build_append_value(var.buf, addr_max, sizeof(addr_max));
+    build_append_value(var.buf, addr_trans, sizeof(addr_trans));
+    build_append_value(var.buf, len, sizeof(len));
+    return var;
+}
+
+/* ACPI 5.0: 6.4.3.5.2 DWord Address Space Descriptor */
+static AcpiAml acpi_dword_as_desc(acpiResourceType type, acpiMinFixed min_fixed,
+                                  acpiMaxFixed max_fixed, acpiDecode dec,
+                                  uint32_t addr_gran, uint32_t addr_min,
+                                  uint32_t addr_max, uint32_t addr_trans,
+                                  uint32_t len, uint8_t type_flags)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+
+    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,
+        acpi_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+    build_append_value(var.buf, addr_gran, sizeof(addr_gran));
+    build_append_value(var.buf, addr_min, sizeof(addr_min));
+    build_append_value(var.buf, addr_max, sizeof(addr_max));
+    build_append_value(var.buf, addr_trans, sizeof(addr_trans));
+    build_append_value(var.buf, len, sizeof(len));
+    return var;
+}
+
+/* ACPI 5.0: 6.4.3.5.1 QWord Address Space Descriptor */
+static AcpiAml acpi_qword_as_desc(acpiResourceType type, acpiMinFixed min_fixed,
+                                  acpiMaxFixed max_fixed, acpiDecode dec,
+                                  uint64_t addr_gran, uint64_t addr_min,
+                                  uint64_t addr_max, uint64_t addr_trans,
+                                  uint64_t len, uint8_t type_flags)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+
+    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,
+        acpi_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+    build_append_value(var.buf, addr_gran, sizeof(addr_gran));
+    build_append_value(var.buf, addr_min, sizeof(addr_min));
+    build_append_value(var.buf, addr_max, sizeof(addr_max));
+    build_append_value(var.buf, addr_trans, sizeof(addr_trans));
+    build_append_value(var.buf, len, sizeof(len));
+    return var;
+}
+
+/*
+ * ACPI 5.0: 19.5.141 WordBusNumber (Word Bus Number Resource Descriptor Macro)
+ */
+AcpiAml acpi_word_bus_number(acpiMinFixed min_fixed, acpiMaxFixed max_fixed,
+                             acpiDecode dec, uint16_t addr_gran,
+                             uint16_t addr_min, uint16_t addr_max,
+                             uint16_t addr_trans, uint16_t len)
+
+{
+    return acpi_word_as_desc(acpi_bus_number_range, min_fixed, max_fixed, dec,
+                             addr_gran, addr_min, addr_max, addr_trans, len, 0);
+}
+
+/* ACPI 5.0: 19.5.142 WordIO (Word IO Resource Descriptor Macro) */
+AcpiAml acpi_word_io(acpiMinFixed min_fixed, acpiMaxFixed max_fixed,
+                     acpiDecode dec, acpiISARanges isa_ranges,
+                     uint16_t addr_gran, uint16_t addr_min,
+                     uint16_t addr_max, uint16_t addr_trans,
+                     uint16_t len)
+
+{
+    return acpi_word_as_desc(acpi_io_range, min_fixed, max_fixed, dec,
+                             addr_gran, addr_min, addr_max, addr_trans, len,
+                             isa_ranges);
+}
+
+/* ACPI 5.0: 19.5.34 DWordMemory (DWord Memory Resource Descriptor Macro) */
+AcpiAml acpi_dword_memory(acpiDecode dec, acpiMinFixed min_fixed,
+                          acpiMaxFixed max_fixed, acpiCacheble cacheable,
+                          acpiReadAndWrite 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 acpi_dword_as_desc(acpi_memory_range, min_fixed, max_fixed,
+                              dec, addr_gran, addr_min, addr_max,
+                              addr_trans, len, flags);
+}
+
+/* ACPI 5.0: 19.5.102 QWordMemory (QWord Memory Resource Descriptor Macro) */
+AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed,
+                          acpiMaxFixed max_fixed, acpiCacheble cacheable,
+                          acpiReadAndWrite 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 acpi_qword_as_desc(acpi_memory_range, min_fixed, max_fixed,
+                              dec, addr_gran, addr_min, addr_max,
+                              addr_trans, len, flags);
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 048ed26..5e8db3d 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -38,6 +38,58 @@ typedef enum {
     acpi_system_io = 0x01,
 } acpiRegionSpace;
 
+typedef enum {
+    acpi_memory_range = 0,
+    acpi_io_range = 1,
+    acpi_bus_number_range = 2,
+} acpiResourceType;
+
+typedef enum {
+    acpi_sub_decode = 1 << 1,
+    acpi_pos_decode = 0
+} acpiDecode;
+
+typedef enum {
+    acpi_max_fixed = 1 << 3,
+    acpi_max_not_fixed = 0,
+} acpiMaxFixed;
+
+typedef enum {
+    acpi_min_fixed = 1 << 2,
+    acpi_min_not_fixed = 0
+} acpiMinFixed;
+
+/*
+ * ACPI 5.0: Table 6-185 I/O Resource Flag (Resource Type = 1) Definitions
+ * _RNG field definition
+ */
+typedef enum {
+    acpi_isa_only = 1,
+    acpi_non_isa_only = 2,
+    acpi_entire_range = 3,
+} acpiISARanges;
+
+/*
+ * ACPI 5.0: Table 6-184 Memory Resource Flag (Resource Type = 0) Definitions
+ * _MEM field definition
+ */
+typedef enum {
+    acpi_non_cacheable = 0,
+    acpi_cacheable = 1,
+    acpi_write_combining = 2,
+    acpi_prefetchable = 3,
+} acpiCacheble;
+
+/*
+ * ACPI 5.0: Table 6-184 Memory Resource Flag (Resource Type = 0) Definitions
+ * _RW field definition
+ */
+typedef enum {
+    acpi_ReadOnly = 0,
+    acpi_ReadWrite = 1,
+} acpiReadAndWrite;
+
+
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* non block ASL object primitives */
@@ -71,6 +123,27 @@ AcpiAml GCC_FMT_ATTR(4, 5)
 acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
                const char *name_format, ...);
 AcpiAml acpi_eisaid(const char *str);
+AcpiAml acpi_word_bus_number(acpiMinFixed min_fixed, acpiMaxFixed max_fixed,
+                             acpiDecode dec, uint16_t addr_gran,
+                             uint16_t addr_min, uint16_t addr_max,
+                             uint16_t addr_trans, uint16_t len);
+AcpiAml acpi_word_io(acpiMinFixed min_fixed, acpiMaxFixed max_fixed,
+                     acpiDecode dec, acpiISARanges isa_ranges,
+                     uint16_t addr_gran, uint16_t addr_min,
+                     uint16_t addr_max, uint16_t addr_trans,
+                     uint16_t len);
+AcpiAml acpi_dword_memory(acpiDecode dec, acpiMinFixed min_fixed,
+                          acpiMaxFixed max_fixed, acpiCacheble cacheable,
+                          acpiReadAndWrite read_and_write,
+                          uint32_t addr_gran, uint32_t addr_min,
+                          uint32_t addr_max, uint32_t addr_trans,
+                          uint32_t len);
+AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed,
+                          acpiMaxFixed max_fixed, acpiCacheble cacheable,
+                          acpiReadAndWrite read_and_write,
+                          uint64_t addr_gran, uint64_t addr_min,
+                          uint64_t addr_max, uint64_t addr_trans,
+                          uint64_t len);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 39/47] pc: pcihp: expose MMIO base and len as properties
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (37 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 38/47] acpi: add acpi_word_bus_number(), acpi_word_io(), acpi_dword_memory(), acpi_qword_memory() terms Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 40/47] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
                   ` (7 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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 481a16c..757f7d8 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -556,7 +556,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] 58+ messages in thread

* [Qemu-devel] [RFC 40/47] pc: acpi-build: reserve PCIHP MMIO resources
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (38 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 39/47] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
                   ` (6 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index ec0aac6..af61b88 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -102,6 +102,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 {
@@ -179,6 +181,10 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
     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;
@@ -694,6 +700,25 @@ build_ssdt(GArray *table_data, GArray *linker,
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
+    scope = acpi_scope("\\_SB.PCI0");
+    /* reserve PCIHP resources */
+    if (pm->pcihp_io_len) {
+        dev = acpi_device("PHPR");
+        aml_append(&dev, acpi_name_decl("_HID", acpi_string("PNP0A06")));
+        aml_append(&dev,
+            acpi_name_decl("_UID", acpi_string("PCI Hotplug resources")));
+        /* device present, functioning, decoding, not shown in UI */
+        aml_append(&dev, acpi_name_decl("_STA", acpi_int(0xB)));
+        crs = acpi_resource_template();
+        aml_append(&crs,
+            acpi_io(acpi_decode16, pm->pcihp_io_base, pm->pcihp_io_base,
+                    1, pm->pcihp_io_len)
+        );
+        aml_append(&dev, acpi_name_decl("_CRS", crs));
+        aml_append(&scope, dev);
+    }
+    aml_append(&table_aml, scope);
+
     /*  create S3_ / S4_ / S5_ packages if necessary */
     scope = acpi_scope("\\");
     if (!pm->s3_disabled) {
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (39 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 40/47] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2015-01-19 12:42   ` Paolo Bonzini
  2014-12-19  2:02 ` [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets Igor Mammedov
                   ` (5 subsequent siblings)
  46 siblings, 1 reply; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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          | 71 ++++++++++++++++-----------------
 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, 34 insertions(+), 211 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 af61b88..b425156 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -316,24 +316,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);
@@ -659,22 +641,6 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus,
     aml_append(parent_scope, scope);
 }
 
-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,
@@ -694,13 +660,44 @@ 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 ssdt template and patch values */
+    /* Copy SSDT  header */
     ssdt_ptr = acpi_data_push(table_data, 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 = acpi_scope("\\_SB.PCI0");
+    /* build PCI0._CRS */
+    crs = acpi_resource_template();
+    aml_append(&crs,
+        acpi_word_bus_number(acpi_min_fixed, acpi_max_fixed, acpi_pos_decode,
+                             0x0000, 0x0000, 0x00FF, 0x0000, 0x0100));
+    aml_append(&crs, acpi_io(acpi_decode16, 0x0CF8, 0x0CF8, 0x01, 0x08));
+
+    aml_append(&crs,
+        acpi_word_io(acpi_min_fixed, acpi_max_fixed,
+                     acpi_pos_decode, acpi_entire_range,
+                     0x0000, 0x0000, 0x0CF7, 0x0000, 0x0CF8));
+    aml_append(&crs,
+        acpi_word_io(acpi_min_fixed, acpi_max_fixed,
+                     acpi_pos_decode, acpi_entire_range,
+                     0x0000, 0x0D00, 0xFFFF, 0x0000, 0xF300));
+    aml_append(&crs,
+        acpi_dword_memory(acpi_pos_decode, acpi_min_fixed, acpi_max_fixed,
+                          acpi_cacheable, acpi_ReadWrite,
+                          0, 0x000A0000, 0x000BFFFF, 0, 0x00020000));
+    aml_append(&crs,
+        acpi_dword_memory(acpi_pos_decode, acpi_min_fixed, acpi_max_fixed,
+                          acpi_non_cacheable, acpi_ReadWrite,
+                          0, pci->w32.begin, pci->w32.end - 1, 0,
+                          pci->w32.end - pci->w32.begin));
+    if (pci->w64.begin) {
+        aml_append(&crs,
+            acpi_qword_memory(acpi_pos_decode, acpi_min_fixed, acpi_max_fixed,
+                              acpi_cacheable, acpi_ReadWrite,
+                              0, pci->w64.begin, pci->w64.end - 1, 0,
+                              pci->w64.end - pci->w64.begin));
+    }
+    aml_append(&scope, acpi_name_decl("_CRS", crs));
+
     /* reserve PCIHP resources */
     if (pm->pcihp_io_len) {
         dev = acpi_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] 58+ messages in thread

* [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (40 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2015-01-19 12:36   ` Paolo Bonzini
  2015-01-19 22:05   ` Michael S. Tsirkin
  2014-12-19  2:02 ` [Qemu-devel] [RFC 43/47] acpi: add acpi_def_block() term Igor Mammedov
                   ` (4 subsequent siblings)
  46 siblings, 2 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

keeping bios-linker-loader.c i386 specific would break build
of mips target which is built with CONFIG_ACPI which would
dependend on it in following patch that adds acpi_def_block()
term. Also UEFI for ARM target is going to use linker as well
so it makes sense to move it into generic target independent
ACPI part.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/Makefile.objs                |   2 +-
 hw/acpi/acpi_gen_utils.c             |   1 +
 hw/acpi/bios-linker-loader.c         | 157 +++++++++++++++++++++++++++++++++++
 hw/i386/Makefile.objs                |   1 -
 hw/i386/acpi-build.c                 |   2 +-
 hw/i386/bios-linker-loader.c         | 157 -----------------------------------
 hw/i386/bios-linker-loader.h         |  27 ------
 include/hw/acpi/bios-linker-loader.h |  27 ++++++
 8 files changed, 187 insertions(+), 187 deletions(-)
 create mode 100644 hw/acpi/bios-linker-loader.c
 delete mode 100644 hw/i386/bios-linker-loader.c
 delete mode 100644 hw/i386/bios-linker-loader.h
 create mode 100644 include/hw/acpi/bios-linker-loader.h

diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 4237232..02ca4ed 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -1,4 +1,4 @@
 common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
 common-obj-$(CONFIG_ACPI) += memory_hotplug.o
 common-obj-$(CONFIG_ACPI) += acpi_interface.o
-common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o
+common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o bios-linker-loader.o
diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 39cbab7..cc2fa03 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -5,6 +5,7 @@
 #include <string.h>
 #include "hw/acpi/acpi_gen_utils.h"
 #include "qemu/bswap.h"
+#include "hw/acpi/bios-linker-loader.h"
 
 GArray *build_alloc_array(void)
 {
diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c
new file mode 100644
index 0000000..5cc4d90
--- /dev/null
+++ b/hw/acpi/bios-linker-loader.c
@@ -0,0 +1,157 @@
+/* Dynamic linker/loader of ACPI tables
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Author: Michael S. Tsirkin <mst@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu-common.h"
+#include "hw/acpi/bios-linker-loader.h"
+#include "hw/nvram/fw_cfg.h"
+
+#include "qemu/bswap.h"
+
+#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
+
+struct BiosLinkerLoaderEntry {
+    uint32_t command;
+    union {
+        /*
+         * COMMAND_ALLOCATE - allocate a table from @alloc.file
+         * subject to @alloc.align alignment (must be power of 2)
+         * and @alloc.zone (can be HIGH or FSEG) requirements.
+         *
+         * Must appear exactly once for each file, and before
+         * this file is referenced by any other command.
+         */
+        struct {
+            char file[BIOS_LINKER_LOADER_FILESZ];
+            uint32_t align;
+            uint8_t zone;
+        } alloc;
+
+        /*
+         * COMMAND_ADD_POINTER - patch the table (originating from
+         * @dest_file) at @pointer.offset, by adding a pointer to the table
+         * originating from @src_file. 1,2,4 or 8 byte unsigned
+         * addition is used depending on @pointer.size.
+         */
+        struct {
+            char dest_file[BIOS_LINKER_LOADER_FILESZ];
+            char src_file[BIOS_LINKER_LOADER_FILESZ];
+            uint32_t offset;
+            uint8_t size;
+        } pointer;
+
+        /*
+         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
+         * @cksum_start and @cksum_length fields,
+         * and then add the value at @cksum.offset.
+         * Checksum simply sums -X for each byte X in the range
+         * using 8-bit math.
+         */
+        struct {
+            char file[BIOS_LINKER_LOADER_FILESZ];
+            uint32_t offset;
+            uint32_t start;
+            uint32_t length;
+        } cksum;
+
+        /* padding */
+        char pad[124];
+    };
+} QEMU_PACKED;
+typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
+
+enum {
+    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
+    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
+    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
+};
+
+enum {
+    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
+    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
+};
+
+GArray *bios_linker_loader_init(void)
+{
+    return g_array_new(false, true /* clear */, 1);
+}
+
+/* Free linker wrapper and return the linker array. */
+void *bios_linker_loader_cleanup(GArray *linker)
+{
+    return g_array_free(linker, false);
+}
+
+void bios_linker_loader_alloc(GArray *linker,
+                              const char *file,
+                              uint32_t alloc_align,
+                              bool alloc_fseg)
+{
+    BiosLinkerLoaderEntry entry;
+
+    memset(&entry, 0, sizeof entry);
+    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
+    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
+    entry.alloc.align = cpu_to_le32(alloc_align);
+    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
+                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
+                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
+
+    /* Alloc entries must come first, so prepend them */
+    g_array_prepend_vals(linker, &entry, sizeof entry);
+}
+
+void bios_linker_loader_add_checksum(GArray *linker, const char *file,
+                                     void *table,
+                                     void *start, unsigned size,
+                                     uint8_t *checksum)
+{
+    BiosLinkerLoaderEntry entry;
+
+    memset(&entry, 0, sizeof entry);
+    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
+    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
+    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
+    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
+    entry.cksum.length = cpu_to_le32(size);
+
+    g_array_append_vals(linker, &entry, sizeof entry);
+}
+
+void bios_linker_loader_add_pointer(GArray *linker,
+                                    const char *dest_file,
+                                    const char *src_file,
+                                    GArray *table, void *pointer,
+                                    uint8_t pointer_size)
+{
+    BiosLinkerLoaderEntry entry;
+
+    memset(&entry, 0, sizeof entry);
+    strncpy(entry.pointer.dest_file, dest_file,
+            sizeof entry.pointer.dest_file - 1);
+    strncpy(entry.pointer.src_file, src_file,
+            sizeof entry.pointer.src_file - 1);
+    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
+    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
+    entry.pointer.size = pointer_size;
+    assert(pointer_size == 1 || pointer_size == 2 ||
+           pointer_size == 4 || pointer_size == 8);
+
+    g_array_append_vals(linker, &entry, sizeof entry);
+}
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 790a56c..6c8705d 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -7,7 +7,6 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
-obj-y += bios-linker-loader.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
 	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-tpm.hex
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b425156..e0fa30a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -36,7 +36,7 @@
 #include "hw/i386/acpi-defs.h"
 #include "hw/acpi/acpi.h"
 #include "hw/nvram/fw_cfg.h"
-#include "bios-linker-loader.h"
+#include "hw/acpi/bios-linker-loader.h"
 #include "hw/loader.h"
 #include "hw/isa/isa.h"
 #include "hw/acpi/memory_hotplug.h"
diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
deleted file mode 100644
index aa56184..0000000
--- a/hw/i386/bios-linker-loader.c
+++ /dev/null
@@ -1,157 +0,0 @@
-/* Dynamic linker/loader of ACPI tables
- *
- * Copyright (C) 2013 Red Hat Inc
- *
- * Author: Michael S. Tsirkin <mst@redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "qemu-common.h"
-#include "bios-linker-loader.h"
-#include "hw/nvram/fw_cfg.h"
-
-#include "qemu/bswap.h"
-
-#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
-
-struct BiosLinkerLoaderEntry {
-    uint32_t command;
-    union {
-        /*
-         * COMMAND_ALLOCATE - allocate a table from @alloc.file
-         * subject to @alloc.align alignment (must be power of 2)
-         * and @alloc.zone (can be HIGH or FSEG) requirements.
-         *
-         * Must appear exactly once for each file, and before
-         * this file is referenced by any other command.
-         */
-        struct {
-            char file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t align;
-            uint8_t zone;
-        } alloc;
-
-        /*
-         * COMMAND_ADD_POINTER - patch the table (originating from
-         * @dest_file) at @pointer.offset, by adding a pointer to the table
-         * originating from @src_file. 1,2,4 or 8 byte unsigned
-         * addition is used depending on @pointer.size.
-         */
-        struct {
-            char dest_file[BIOS_LINKER_LOADER_FILESZ];
-            char src_file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t offset;
-            uint8_t size;
-        } pointer;
-
-        /*
-         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
-         * @cksum_start and @cksum_length fields,
-         * and then add the value at @cksum.offset.
-         * Checksum simply sums -X for each byte X in the range
-         * using 8-bit math.
-         */
-        struct {
-            char file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t offset;
-            uint32_t start;
-            uint32_t length;
-        } cksum;
-
-        /* padding */
-        char pad[124];
-    };
-} QEMU_PACKED;
-typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
-
-enum {
-    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
-    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
-    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
-};
-
-enum {
-    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
-    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
-};
-
-GArray *bios_linker_loader_init(void)
-{
-    return g_array_new(false, true /* clear */, 1);
-}
-
-/* Free linker wrapper and return the linker array. */
-void *bios_linker_loader_cleanup(GArray *linker)
-{
-    return g_array_free(linker, false);
-}
-
-void bios_linker_loader_alloc(GArray *linker,
-                              const char *file,
-                              uint32_t alloc_align,
-                              bool alloc_fseg)
-{
-    BiosLinkerLoaderEntry entry;
-
-    memset(&entry, 0, sizeof entry);
-    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
-    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
-    entry.alloc.align = cpu_to_le32(alloc_align);
-    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
-                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
-                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
-
-    /* Alloc entries must come first, so prepend them */
-    g_array_prepend_vals(linker, &entry, sizeof entry);
-}
-
-void bios_linker_loader_add_checksum(GArray *linker, const char *file,
-                                     void *table,
-                                     void *start, unsigned size,
-                                     uint8_t *checksum)
-{
-    BiosLinkerLoaderEntry entry;
-
-    memset(&entry, 0, sizeof entry);
-    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
-    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
-    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
-    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
-    entry.cksum.length = cpu_to_le32(size);
-
-    g_array_append_vals(linker, &entry, sizeof entry);
-}
-
-void bios_linker_loader_add_pointer(GArray *linker,
-                                    const char *dest_file,
-                                    const char *src_file,
-                                    GArray *table, void *pointer,
-                                    uint8_t pointer_size)
-{
-    BiosLinkerLoaderEntry entry;
-
-    memset(&entry, 0, sizeof entry);
-    strncpy(entry.pointer.dest_file, dest_file,
-            sizeof entry.pointer.dest_file - 1);
-    strncpy(entry.pointer.src_file, src_file,
-            sizeof entry.pointer.src_file - 1);
-    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
-    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
-    entry.pointer.size = pointer_size;
-    assert(pointer_size == 1 || pointer_size == 2 ||
-           pointer_size == 4 || pointer_size == 8);
-
-    g_array_append_vals(linker, &entry, sizeof entry);
-}
diff --git a/hw/i386/bios-linker-loader.h b/hw/i386/bios-linker-loader.h
deleted file mode 100644
index 498c0af..0000000
--- a/hw/i386/bios-linker-loader.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef BIOS_LINKER_LOADER_H
-#define BIOS_LINKER_LOADER_H
-
-#include <glib.h>
-#include <stdbool.h>
-#include <inttypes.h>
-
-GArray *bios_linker_loader_init(void);
-
-void bios_linker_loader_alloc(GArray *linker,
-                              const char *file,
-                              uint32_t alloc_align,
-                              bool alloc_fseg);
-
-void bios_linker_loader_add_checksum(GArray *linker, const char *file,
-                                     void *table,
-                                     void *start, unsigned size,
-                                     uint8_t *checksum);
-
-void bios_linker_loader_add_pointer(GArray *linker,
-                                    const char *dest_file,
-                                    const char *src_file,
-                                    GArray *table, void *pointer,
-                                    uint8_t pointer_size);
-
-void *bios_linker_loader_cleanup(GArray *linker);
-#endif
diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-linker-loader.h
new file mode 100644
index 0000000..498c0af
--- /dev/null
+++ b/include/hw/acpi/bios-linker-loader.h
@@ -0,0 +1,27 @@
+#ifndef BIOS_LINKER_LOADER_H
+#define BIOS_LINKER_LOADER_H
+
+#include <glib.h>
+#include <stdbool.h>
+#include <inttypes.h>
+
+GArray *bios_linker_loader_init(void);
+
+void bios_linker_loader_alloc(GArray *linker,
+                              const char *file,
+                              uint32_t alloc_align,
+                              bool alloc_fseg);
+
+void bios_linker_loader_add_checksum(GArray *linker, const char *file,
+                                     void *table,
+                                     void *start, unsigned size,
+                                     uint8_t *checksum);
+
+void bios_linker_loader_add_pointer(GArray *linker,
+                                    const char *dest_file,
+                                    const char *src_file,
+                                    GArray *table, void *pointer,
+                                    uint8_t pointer_size);
+
+void *bios_linker_loader_cleanup(GArray *linker);
+#endif
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 43/47] acpi: add acpi_def_block() term
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (41 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 44/47] pc: acpi-build: prepare to make ACPI tables blob opaque for table building functions Igor Mammedov
                   ` (3 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index cc2fa03..583ceb3 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -287,6 +287,21 @@ void aml_append(AcpiAml *parent_ctx, AcpiAml child)
         build_prepend_int(child.buf, child.buf->len);
         build_package(child.buf, child.op);
         break;
+    case DEF_BLOCK: {
+        uint8_t *start = (uint8_t *)parent_ctx->buf->data +
+                         parent_ctx->buf->len;
+        uint32_t le32_len = cpu_to_le32(child.buf->len);
+
+        /* create linker entry for the DefinitionBlock */
+        bios_linker_loader_add_checksum(parent_ctx->linker,
+            ACPI_BUILD_TABLE_FILE,
+            parent_ctx->buf->data,
+            start, child.buf->len, start + 9 /* checksum offset */);
+
+        /* set DefinitionBlock length at TableLength offset*/
+        memcpy(child.buf->data + 4, &le32_len, sizeof le32_len);
+        break;
+    }
     default:
         break;
     }
@@ -818,3 +833,34 @@ AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed,
                               dec, addr_gran, addr_min, addr_max,
                               addr_trans, len, flags);
 }
+
+/* ACPI 5.0: 20.2.1 Table and Table Header Encoding */
+AcpiAml acpi_def_block(const char *signature, uint8_t revision,
+                       const char *oem_id, const char *oem_table_id,
+                       uint32_t oem_revision)
+{
+    int len;
+    AcpiAml var = aml_allocate_internal(0, DEF_BLOCK);
+
+    assert(strlen(signature) == 4);
+    g_array_append_vals(var.buf, signature, 4);
+    build_append_value(var.buf, 0, 4); /* Length place holder */
+    build_append_byte(var.buf, revision);
+    build_append_byte(var.buf, 0); /* place holder for Checksum */
+
+    len = strlen(oem_id);
+    assert(len <= 6);
+    g_array_append_vals(var.buf, oem_id, len);
+    g_array_append_vals(var.buf, "\0\0\0\0\0\0\0\0", 6 - len);
+
+    len = strlen(oem_table_id);
+    assert(len <= 8);
+    g_array_append_vals(var.buf, oem_table_id, len);
+    g_array_append_vals(var.buf, "\0\0\0\0\0\0\0\0", 8 - len);
+
+    build_append_value(var.buf, oem_revision, 4);
+    g_array_append_vals(var.buf, ACPI_BUILD_APPNAME4, 4); /* asl_compiler_id */
+    build_append_value(var.buf, 1, 4); /* asl_compiler_revision */
+
+    return var;
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index e0fa30a..3a22bdb 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -267,7 +267,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
 #define ACPI_BUILD_APPNAME6 "BOCHS "
 #define ACPI_BUILD_APPNAME4 "BXPC"
 
-#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
 
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 5e8db3d..868d439 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -11,12 +11,17 @@ typedef enum {
     EXT_PACKAGE,
     BUFFER,
     RES_TEMPLATE,
+    DEF_BLOCK,
 } AcpiBlockFlags;
 
+#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
+#define ACPI_BUILD_APPNAME4 "BXPC"
+
 typedef struct AcpiAml {
     GArray *buf;
     uint8_t op;
     AcpiBlockFlags block_flags;
+    GArray *linker;
 } AcpiAml;
 
 typedef enum {
@@ -146,6 +151,9 @@ AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed,
                           uint64_t len);
 
 /* Block ASL object primitives */
+AcpiAml acpi_def_block(const char *signature, uint8_t revision,
+                       const char *oem_id, const char *oem_table_id,
+                       uint32_t oem_revision);
 AcpiAml acpi_if(AcpiAml predicate);
 AcpiAml acpi_method(const char *name, int arg_count);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 44/47] pc: acpi-build: prepare to make ACPI tables blob opaque for table building functions
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (42 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 43/47] acpi: add acpi_def_block() term Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 45/47] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block() Igor Mammedov
                   ` (2 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

it allows to hide linker and direct access to table's
storage from table building function if it would use
acpi_def_block() to declare table and ASL/AML API to
compose it. Which following patch will do for
build_ssdt() function.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
PS:
 this series does it only for build_ssdt(), but it also
 could be done for other tables later by using there
 acpi_def_block() to describe table's header and
 adding addtional API to compose table's entries.
---
 hw/i386/acpi-build.c | 85 ++++++++++++++++++++++++++--------------------------
 1 file changed, 43 insertions(+), 42 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 3a22bdb..347448b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1253,7 +1253,7 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
 
 typedef
 struct AcpiBuildTables {
-    GArray *table_data;
+    AcpiAml table_data;
     GArray *rsdp;
     GArray *tcpalog;
     GArray *linker;
@@ -1262,9 +1262,10 @@ struct AcpiBuildTables {
 static inline void acpi_build_tables_init(AcpiBuildTables *tables)
 {
     tables->rsdp = g_array_new(false, true /* clear */, 1);
-    tables->table_data = g_array_new(false, true /* clear */, 1);
+    tables->table_data.buf = g_array_new(false, true /* clear */, 1);
     tables->tcpalog = g_array_new(false, true /* clear */, 1);
     tables->linker = bios_linker_loader_init();
+    tables->table_data.linker = tables->linker;
 }
 
 static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
@@ -1272,7 +1273,7 @@ static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
     void *linker_data = bios_linker_loader_cleanup(tables->linker);
     g_free(linker_data);
     g_array_free(tables->rsdp, mfre);
-    g_array_free(tables->table_data, true);
+    g_array_free(tables->table_data.buf, true);
     g_array_free(tables->tcpalog, mfre);
 }
 
@@ -1352,66 +1353,66 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
      * We place it first since it's the only table that has alignment
      * requirements.
      */
-    facs = tables->table_data->len;
-    build_facs(tables->table_data, tables->linker, guest_info);
+    facs = tables->table_data.buf->len;
+    build_facs(tables->table_data.buf, tables->linker, guest_info);
 
     /* DSDT is pointed to by FADT */
-    dsdt = tables->table_data->len;
-    build_dsdt(tables->table_data, tables->linker, &misc);
+    dsdt = tables->table_data.buf->len;
+    build_dsdt(tables->table_data.buf, tables->linker, &misc);
 
     /* Count the size of the DSDT and SSDT, we will need it for legacy
      * sizing of ACPI tables.
      */
-    aml_len += tables->table_data->len - dsdt;
+    aml_len += tables->table_data.buf->len - dsdt;
 
     /* ACPI tables pointed to by RSDT */
-    acpi_add_table(table_offsets, tables->table_data);
-    build_fadt(tables->table_data, tables->linker, &pm, facs, dsdt);
+    acpi_add_table(table_offsets, tables->table_data.buf);
+    build_fadt(tables->table_data.buf, tables->linker, &pm, facs, dsdt);
 
-    ssdt = tables->table_data->len;
-    acpi_add_table(table_offsets, tables->table_data);
-    build_ssdt(tables->table_data, tables->linker, &cpu, &pm, &misc, &pci,
+    ssdt = tables->table_data.buf->len;
+    acpi_add_table(table_offsets, tables->table_data.buf);
+    build_ssdt(tables->table_data.buf, tables->linker, &cpu, &pm, &misc, &pci,
                guest_info);
-    aml_len += tables->table_data->len - ssdt;
+    aml_len += tables->table_data.buf->len - ssdt;
 
-    acpi_add_table(table_offsets, tables->table_data);
-    build_madt(tables->table_data, tables->linker, &cpu, guest_info);
+    acpi_add_table(table_offsets, tables->table_data.buf);
+    build_madt(tables->table_data.buf, tables->linker, &cpu, guest_info);
 
     if (misc.has_hpet) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_hpet(tables->table_data, tables->linker);
+        acpi_add_table(table_offsets, tables->table_data.buf);
+        build_hpet(tables->table_data.buf, tables->linker);
     }
     if (misc.has_tpm) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_tpm_tcpa(tables->table_data, tables->linker, tables->tcpalog);
+        acpi_add_table(table_offsets, tables->table_data.buf);
+        build_tpm_tcpa(tables->table_data.buf, tables->linker, tables->tcpalog);
 
-        acpi_add_table(table_offsets, tables->table_data);
-        build_tpm_ssdt(tables->table_data, tables->linker);
+        acpi_add_table(table_offsets, tables->table_data.buf);
+        build_tpm_ssdt(tables->table_data.buf, tables->linker);
     }
     if (guest_info->numa_nodes) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_srat(tables->table_data, tables->linker, guest_info);
+        acpi_add_table(table_offsets, tables->table_data.buf);
+        build_srat(tables->table_data.buf, tables->linker, guest_info);
     }
     if (acpi_get_mcfg(&mcfg)) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_mcfg_q35(tables->table_data, tables->linker, &mcfg);
+        acpi_add_table(table_offsets, tables->table_data.buf);
+        build_mcfg_q35(tables->table_data.buf, tables->linker, &mcfg);
     }
     if (acpi_has_iommu()) {
-        acpi_add_table(table_offsets, tables->table_data);
-        build_dmar_q35(tables->table_data, tables->linker);
+        acpi_add_table(table_offsets, tables->table_data.buf);
+        build_dmar_q35(tables->table_data.buf, tables->linker);
     }
 
     /* Add tables supplied by user (if any) */
     for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
         unsigned len = acpi_table_len(u);
 
-        acpi_add_table(table_offsets, tables->table_data);
-        g_array_append_vals(tables->table_data, u, len);
+        acpi_add_table(table_offsets, tables->table_data.buf);
+        g_array_append_vals(tables->table_data.buf, u, len);
     }
 
     /* RSDT is pointed to by RSDP */
-    rsdt = tables->table_data->len;
-    build_rsdt(tables->table_data, tables->linker, table_offsets);
+    rsdt = tables->table_data.buf->len;
+    build_rsdt(tables->table_data.buf, tables->linker, table_offsets);
 
     /* RSDP is in FSEG memory, so allocate it separately */
     build_rsdp(tables->rsdp, tables->linker, rsdt);
@@ -1443,23 +1444,23 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
             guest_info->legacy_acpi_table_size +
             ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;
         int legacy_table_size =
-            ROUND_UP(tables->table_data->len - aml_len + legacy_aml_len,
+            ROUND_UP(tables->table_data.buf->len - aml_len + legacy_aml_len,
                      ACPI_BUILD_ALIGN_SIZE);
-        if (tables->table_data->len > legacy_table_size) {
+        if (tables->table_data.buf->len > legacy_table_size) {
             /* Should happen only with PCI bridges and -M pc-i440fx-2.0.  */
             error_report("Warning: migration may not work.");
         }
-        g_array_set_size(tables->table_data, legacy_table_size);
+        g_array_set_size(tables->table_data.buf, legacy_table_size);
     } else {
         /* Make sure we have a buffer in case we need to resize the tables. */
-        if (tables->table_data->len > ACPI_BUILD_TABLE_SIZE / 2) {
+        if (tables->table_data.buf->len > ACPI_BUILD_TABLE_SIZE / 2) {
             /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots.  */
             error_report("Warning: ACPI tables are larger than 64k.");
             error_report("Warning: migration may not work.");
             error_report("Warning: please remove CPUs, NUMA nodes, "
                          "memory slots or PCI bridges.");
         }
-        acpi_align_size(tables->table_data, ACPI_BUILD_TABLE_SIZE);
+        acpi_align_size(tables->table_data.buf, ACPI_BUILD_TABLE_SIZE);
     }
 
     acpi_align_size(tables->linker, ACPI_BUILD_ALIGN_SIZE);
@@ -1483,8 +1484,8 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
 
     acpi_build(build_state->guest_info, &tables);
 
-    assert(acpi_data_len(tables.table_data) == build_state->table_size);
-    memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
+    assert(acpi_data_len(tables.table_data.buf) == build_state->table_size);
+    memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data.buf->data,
            build_state->table_size);
 
     cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
@@ -1546,10 +1547,10 @@ void acpi_setup(PcGuestInfo *guest_info)
     acpi_build(build_state->guest_info, &tables);
 
     /* Now expose it all to Guest */
-    build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data,
-                                               ACPI_BUILD_TABLE_FILE);
+    build_state->table_ram = acpi_add_rom_blob(build_state,
+        tables.table_data.buf, ACPI_BUILD_TABLE_FILE);
     assert(build_state->table_ram != RAM_ADDR_MAX);
-    build_state->table_size = acpi_data_len(tables.table_data);
+    build_state->table_size = acpi_data_len(tables.table_data.buf);
 
     acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader");
 
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 45/47] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (43 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 44/47] pc: acpi-build: prepare to make ACPI tables blob opaque for table building functions Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 46/47] pc: acpi: update DSTD blobs Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 47/47] tests: acpi: update reference DSDT/SSDT tables Igor Mammedov
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

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

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

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 6c8705d..dc8c38a 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+	hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 347448b..593fc4e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -265,7 +265,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
 
 #define ACPI_BUILD_APPNAME  "Bochs"
 #define ACPI_BUILD_APPNAME6 "BOCHS "
-#define ACPI_BUILD_APPNAME4 "BXPC"
 
 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
@@ -462,10 +461,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
                  table_data->len - madt_start, 1);
 }
 
-#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
-#define ACPI_SSDT_HEADER_LENGTH 36
-
-#include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
@@ -641,17 +636,14 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus,
 }
 
 static void
-build_ssdt(GArray *table_data, GArray *linker,
+build_ssdt(AcpiAml *table_aml, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
            PcPciInfo *pci, PcGuestInfo *guest_info)
 {
     MachineState *machine = MACHINE(qdev_get_machine());
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
-    int ssdt_start = table_data->len;
-    AcpiAml table_aml = { .buf = table_data };
-    uint8_t *ssdt_ptr;
-    AcpiAml pkg, scope, dev, method, crs, field, ifctx;
+    AcpiAml pkg, scope, dev, method, crs, field, ifctx, ssdt;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -659,9 +651,9 @@ 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 SSDT  header */
-    ssdt_ptr = acpi_data_push(table_data, sizeof(ssdp_misc_aml));
-    memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
+    /* Init SSDT Definition Block */
+    ssdt =
+        acpi_def_block("SSDT", 1, ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4, 1);
 
     scope = acpi_scope("\\_SB.PCI0");
     /* build PCI0._CRS */
@@ -713,7 +705,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(&dev, acpi_name_decl("_CRS", crs));
         aml_append(&scope, dev);
     }
-    aml_append(&table_aml, scope);
+    aml_append(&ssdt, scope);
 
     /*  create S3_ / S4_ / S5_ packages if necessary */
     scope = acpi_scope("\\");
@@ -741,7 +733,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     aml_append(&pkg, acpi_int(0)); /* reserved */
     aml_append(&pkg, acpi_int(0)); /* reserved */
     aml_append(&scope, acpi_name_decl("_S5", pkg));
-    aml_append(&table_aml, scope);
+    aml_append(&ssdt, scope);
 
     if (misc->pvpanic_port) {
         scope = acpi_scope("\\_SB.PCI0.ISA");
@@ -771,7 +763,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(&dev, method);
 
         aml_append(&scope, dev);
-        aml_append(&table_aml, scope);
+        aml_append(&ssdt, scope);
     }
 
     {
@@ -964,12 +956,10 @@ build_ssdt(GArray *table_data, GArray *linker,
                                              pm->pcihp_bridge_en);
             }
         }
-        aml_append(&table_aml, sb_scope);
+        aml_append(&ssdt, sb_scope);
     }
 
-    build_header(linker, table_data,
-                 (void *)(table_data->data + ssdt_start),
-                 "SSDT", table_data->len - ssdt_start, 1);
+    aml_append(table_aml, ssdt);
 }
 
 static void
@@ -1371,7 +1361,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 
     ssdt = tables->table_data.buf->len;
     acpi_add_table(table_offsets, tables->table_data.buf);
-    build_ssdt(tables->table_data.buf, tables->linker, &cpu, &pm, &misc, &pci,
+    build_ssdt(&tables->table_data, tables->linker, &cpu, &pm, &misc, &pci,
                guest_info);
     aml_len += tables->table_data.buf->len - ssdt;
 
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
deleted file mode 100644
index 8d61f21..0000000
--- a/hw/i386/ssdt-misc.dsl
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-#include "hw/acpi/pc-hotplug.h"
-
-ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
-
-DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
-{
-}
diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
deleted file mode 100644
index cbcf61d..0000000
--- a/hw/i386/ssdt-misc.hex.generated
+++ /dev/null
@@ -1,399 +0,0 @@
-static unsigned char acpi_pci64_length[] = {
-0x6f
-};
-static unsigned char acpi_s4_pkg[] = {
-0x99
-};
-static unsigned char ssdt_mctrl_nr_slots[] = {
-0x7d
-};
-static unsigned char acpi_s3_name[] = {
-0x86
-};
-static unsigned char acpi_pci32_start[] = {
-0x2f
-};
-static unsigned char acpi_pci64_valid[] = {
-0x43
-};
-static unsigned char ssdp_misc_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0x6c,
-0x1,
-0x0,
-0x0,
-0x1,
-0x3,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x53,
-0x55,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x28,
-0x8,
-0x14,
-0x20,
-0x10,
-0x4c,
-0x5,
-0x5c,
-0x0,
-0x8,
-0x50,
-0x30,
-0x53,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x30,
-0x45,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x31,
-0x56,
-0x5f,
-0xa,
-0x12,
-0x8,
-0x50,
-0x31,
-0x53,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x50,
-0x31,
-0x4c,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x4d,
-0x44,
-0x4e,
-0x52,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x10,
-0x29,
-0x5c,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x33,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x1,
-0x1,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x34,
-0x5f,
-0x12,
-0x8,
-0x4,
-0xa,
-0x2,
-0xa,
-0x2,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x35,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x0,
-0x0,
-0x0,
-0x0,
-0x10,
-0x40,
-0xc,
-0x5c,
-0x2f,
-0x3,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x49,
-0x53,
-0x41,
-0x5f,
-0x5b,
-0x82,
-0x4d,
-0xa,
-0x50,
-0x45,
-0x56,
-0x54,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xd,
-0x51,
-0x45,
-0x4d,
-0x55,
-0x30,
-0x30,
-0x30,
-0x31,
-0x0,
-0x8,
-0x50,
-0x45,
-0x53,
-0x54,
-0xb,
-0xff,
-0xff,
-0x5b,
-0x80,
-0x50,
-0x45,
-0x4f,
-0x52,
-0x1,
-0x50,
-0x45,
-0x53,
-0x54,
-0x1,
-0x5b,
-0x81,
-0xb,
-0x50,
-0x45,
-0x4f,
-0x52,
-0x1,
-0x50,
-0x45,
-0x50,
-0x54,
-0x8,
-0x14,
-0x18,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x60,
-0xa0,
-0x6,
-0x93,
-0x60,
-0x0,
-0xa4,
-0x0,
-0xa1,
-0x4,
-0xa4,
-0xa,
-0xf,
-0x14,
-0xe,
-0x52,
-0x44,
-0x50,
-0x54,
-0x0,
-0x70,
-0x50,
-0x45,
-0x50,
-0x54,
-0x60,
-0xa4,
-0x60,
-0x14,
-0xc,
-0x57,
-0x52,
-0x50,
-0x54,
-0x1,
-0x70,
-0x68,
-0x50,
-0x45,
-0x50,
-0x54,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x1,
-0x79,
-0x0,
-0x8b,
-0x5f,
-0x43,
-0x52,
-0x53,
-0xa,
-0x2,
-0x49,
-0x4f,
-0x4d,
-0x4e,
-0x8b,
-0x5f,
-0x43,
-0x52,
-0x53,
-0xa,
-0x4,
-0x49,
-0x4f,
-0x4d,
-0x58,
-0x14,
-0x18,
-0x5f,
-0x49,
-0x4e,
-0x49,
-0x0,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x49,
-0x4f,
-0x4d,
-0x4e,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x49,
-0x4f,
-0x4d,
-0x58
-};
-static unsigned char ssdt_isa_pest[] = {
-0xda
-};
-static unsigned char acpi_s4_name[] = {
-0x92
-};
-static unsigned char acpi_pci64_start[] = {
-0x4d
-};
-static unsigned char acpi_pci64_end[] = {
-0x5e
-};
-static unsigned char acpi_pci32_end[] = {
-0x39
-};
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 46/47] pc: acpi: update DSTD blobs
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (44 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 45/47] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block() Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  2014-12-19  2:02 ` [Qemu-devel] [RFC 47/47] tests: acpi: update reference DSDT/SSDT tables Igor Mammedov
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

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

diff --git a/hw/i386/acpi-dsdt.hex.generated b/hw/i386/acpi-dsdt.hex.generated
index 875570e..f41ca28 100644
--- a/hw/i386/acpi-dsdt.hex.generated
+++ b/hw/i386/acpi-dsdt.hex.generated
@@ -3,12 +3,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x44,
 0x54,
-0x8,
-0xe,
+0xc8,
+0xb,
 0x0,
 0x0,
 0x1,
-0xfc,
+0xee,
 0x42,
 0x58,
 0x50,
@@ -31,8 +31,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x4e,
 0x54,
 0x4c,
-0x28,
-0x8,
+0x26,
+0x9,
 0x14,
 0x20,
 0x10,
@@ -98,451 +98,52 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x0,
 0x44,
 0x42,
-0x47,
-0x42,
-0x75,
-0x62,
-0x70,
-0xa,
-0xa,
-0x44,
-0x42,
-0x47,
-0x42,
-0x10,
-0x22,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x5b,
-0x82,
-0x1b,
-0x50,
-0x43,
-0x49,
-0x30,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xa,
-0x3,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0x0,
-0x8,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x1,
-0x10,
-0x4e,
-0x18,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x8,
-0x43,
-0x52,
-0x45,
-0x53,
-0x11,
-0x42,
-0xa,
-0xa,
-0x9e,
-0x88,
-0xd,
-0x0,
-0x2,
-0xc,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x47,
-0x1,
-0xf8,
-0xc,
-0xf8,
-0xc,
-0x1,
-0x8,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0xf7,
-0xc,
-0x0,
-0x0,
-0xf8,
-0xc,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0xd,
-0xff,
-0xad,
-0x0,
-0x0,
-0x0,
-0xa1,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0xf,
-0xae,
-0xff,
-0xae,
-0x0,
-0x0,
-0xf1,
-0x0,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x20,
-0xaf,
-0xdf,
-0xaf,
-0x0,
-0x0,
-0xc0,
-0x0,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0xe4,
-0xaf,
-0xff,
-0xff,
-0x0,
-0x0,
-0x1c,
-0x50,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xa,
-0x0,
-0xff,
-0xff,
-0xb,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x2,
-0x0,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xe0,
-0xff,
-0xff,
-0xbf,
-0xfe,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xc0,
-0x1e,
-0x79,
-0x0,
-0x8,
-0x43,
-0x52,
-0x36,
-0x34,
-0x11,
-0x33,
-0xa,
-0x30,
-0x8a,
-0x2b,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0xff,
-0xff,
-0xff,
-0xff,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0x79,
-0x0,
-0x14,
-0x41,
-0xa,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x8c,
-0x50,
-0x53,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x90,
-0x50,
-0x45,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x98,
-0x50,
-0x4c,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x33,
-0x32,
-0x70,
-0x72,
-0x74,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x0,
-0x1,
-0x0,
-0x50,
-0x4c,
-0x33,
-0x32,
-0xa0,
-0xc,
-0x93,
-0x50,
-0x31,
-0x56,
-0x5f,
-0x0,
-0xa4,
-0x43,
-0x52,
-0x45,
-0x53,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0xe,
-0x50,
-0x53,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x16,
-0x50,
-0x45,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x26,
-0x50,
-0x4c,
-0x36,
-0x34,
+0x47,
+0x42,
+0x75,
+0x62,
 0x70,
-0x50,
-0x31,
-0x53,
+0xa,
+0xa,
+0x44,
+0x42,
+0x47,
+0x42,
+0x10,
+0x22,
 0x5f,
-0x50,
 0x53,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x4c,
+0x42,
 0x5f,
+0x5b,
+0x82,
+0x1b,
 0x50,
-0x4c,
-0x36,
-0x34,
-0x84,
-0x43,
-0x52,
-0x45,
-0x53,
 0x43,
+0x49,
+0x30,
+0x8,
+0x5f,
+0x48,
+0x49,
+0x44,
+0xc,
+0x41,
+0xd0,
+0xa,
+0x3,
+0x8,
+0x5f,
+0x41,
+0x44,
 0x52,
-0x36,
-0x34,
-0x60,
-0xa4,
-0x60,
+0x0,
+0x8,
+0x5f,
+0x55,
+0x49,
+0x44,
+0x1,
 0x10,
 0x4d,
 0x8,
@@ -2318,8 +1919,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x1,
 0x10,
-0x42,
-0x11,
+0x4d,
+0xc,
 0x5f,
 0x53,
 0x42,
@@ -2416,32 +2017,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x22,
 0xa,
 0xc8,
-0x5b,
-0x80,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0xb,
-0x0,
-0xaf,
-0xa,
-0x20,
-0x5b,
-0x81,
-0xc,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0x50,
-0x52,
-0x53,
-0x5f,
-0x40,
-0x10,
 0x14,
 0x4a,
 0x6,
@@ -2549,52 +2124,9 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x3,
 0x75,
 0x60,
-0x5b,
-0x82,
-0x29,
-0x50,
-0x52,
-0x45,
-0x53,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xa,
-0x6,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xaf,
-0x0,
-0xaf,
-0x0,
-0x20,
-0x79,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x54,
-0x41,
-0xa,
-0xb,
 0x10,
-0x40,
-0x31,
+0x44,
+0x2a,
 0x2e,
 0x5f,
 0x53,
@@ -2606,8 +2138,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x30,
 0x5b,
 0x82,
-0x43,
-0x30,
+0x47,
+0x29,
 0x4d,
 0x48,
 0x50,
@@ -2657,37 +2189,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x65,
 0x73,
 0x0,
-0x5b,
-0x80,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0xb,
-0x0,
-0xa,
-0xa,
-0x18,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xa,
-0x0,
-0xa,
-0x0,
-0x18,
-0x79,
-0x0,
 0x14,
 0x13,
 0x5f,
@@ -2709,89 +2210,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0xa,
 0xb,
 0x5b,
-0x81,
-0x1f,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x52,
-0x42,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x42,
-0x48,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x48,
-0x20,
-0x4d,
-0x50,
-0x58,
-0x5f,
-0x20,
-0x5b,
-0x81,
-0x13,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0x0,
-0x40,
-0xa,
-0x4d,
-0x45,
-0x53,
-0x5f,
-0x1,
-0x4d,
-0x49,
-0x4e,
-0x53,
-0x1,
-0x5b,
 0x1,
 0x4d,
 0x4c,
 0x43,
 0x4b,
 0x0,
-0x5b,
-0x81,
-0x15,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x53,
-0x45,
-0x4c,
-0x20,
-0x4d,
-0x4f,
-0x45,
-0x56,
-0x20,
-0x4d,
-0x4f,
-0x53,
-0x43,
-0x20,
 0x14,
 0x4a,
 0x4,
@@ -3593,5 +3017,5 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x0
 };
 static unsigned short piix_dsdt_applesmc_sta[] = {
-0x353
+0x1c4
 };
diff --git a/hw/i386/q35-acpi-dsdt.hex.generated b/hw/i386/q35-acpi-dsdt.hex.generated
index 4807bdf..28e187a 100644
--- a/hw/i386/q35-acpi-dsdt.hex.generated
+++ b/hw/i386/q35-acpi-dsdt.hex.generated
@@ -3,12 +3,12 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x53,
 0x44,
 0x54,
-0xf6,
-0x1f,
+0xe6,
+0x1d,
 0x0,
 0x0,
 0x1,
-0x91,
+0x2b,
 0x42,
 0x58,
 0x50,
@@ -31,8 +31,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x4e,
 0x54,
 0x4c,
-0x28,
-0x8,
+0x26,
+0x9,
 0x14,
 0x20,
 0x10,
@@ -317,399 +317,48 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x92,
 0x93,
 0x43,
-0x44,
-0x57,
-0x33,
-0x43,
-0x54,
-0x52,
-0x4c,
-0x7d,
-0x43,
-0x44,
-0x57,
-0x31,
-0xa,
-0x10,
-0x43,
-0x44,
-0x57,
-0x31,
-0x70,
-0x43,
-0x54,
-0x52,
-0x4c,
-0x43,
-0x44,
-0x57,
-0x33,
-0xa1,
-0xc,
-0x7d,
-0x43,
-0x44,
-0x57,
-0x31,
-0xa,
-0x4,
-0x43,
-0x44,
-0x57,
-0x31,
-0xa4,
-0x6b,
-0x10,
-0x4e,
-0x15,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x8,
-0x43,
-0x52,
-0x45,
-0x53,
-0x11,
-0x42,
-0x7,
-0xa,
-0x6e,
-0x88,
-0xd,
-0x0,
-0x2,
-0xc,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x47,
-0x1,
-0xf8,
-0xc,
-0xf8,
-0xc,
-0x1,
-0x8,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0xd7,
-0xc,
-0x0,
-0x0,
-0xd8,
-0xc,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0xd,
-0xff,
-0xff,
-0x0,
-0x0,
-0x0,
-0xf3,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xa,
-0x0,
-0xff,
-0xff,
-0xb,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x2,
-0x0,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xe0,
-0xff,
-0xff,
-0xbf,
-0xfe,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xc0,
-0x1e,
-0x79,
-0x0,
-0x8,
-0x43,
-0x52,
-0x36,
-0x34,
-0x11,
-0x33,
-0xa,
-0x30,
-0x8a,
-0x2b,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0xff,
-0xff,
-0xff,
-0xff,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0x79,
-0x0,
-0x14,
-0x41,
-0xa,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x5c,
-0x50,
-0x53,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x60,
-0x50,
-0x45,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x68,
-0x50,
-0x4c,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x33,
-0x32,
-0x70,
-0x72,
-0x74,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x0,
-0x1,
-0x0,
-0x50,
-0x4c,
-0x33,
-0x32,
-0xa0,
-0xc,
-0x93,
-0x50,
-0x31,
-0x56,
-0x5f,
-0x0,
-0xa4,
-0x43,
-0x52,
-0x45,
-0x53,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0xe,
-0x50,
-0x53,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x16,
-0x50,
-0x45,
-0x36,
-0x34,
-0x8f,
+0x44,
+0x57,
+0x33,
 0x43,
+0x54,
 0x52,
-0x36,
-0x34,
-0xa,
-0x26,
-0x50,
 0x4c,
-0x36,
-0x34,
-0x70,
-0x50,
+0x7d,
+0x43,
+0x44,
+0x57,
 0x31,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x36,
-0x34,
-0x70,
-0x50,
+0xa,
+0x10,
+0x43,
+0x44,
+0x57,
 0x31,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x36,
-0x34,
 0x70,
-0x50,
-0x31,
-0x4c,
-0x5f,
-0x50,
-0x4c,
-0x36,
-0x34,
-0x84,
 0x43,
+0x54,
 0x52,
-0x45,
-0x53,
+0x4c,
 0x43,
-0x52,
-0x36,
-0x34,
-0x60,
+0x44,
+0x57,
+0x33,
+0xa1,
+0xc,
+0x7d,
+0x43,
+0x44,
+0x57,
+0x31,
+0xa,
+0x4,
+0x43,
+0x44,
+0x57,
+0x31,
 0xa4,
-0x60,
+0x6b,
 0x10,
 0x4d,
 0x8,
@@ -6959,8 +6608,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x53,
 0x1,
 0x10,
-0x42,
-0x11,
+0x4d,
+0xc,
 0x5f,
 0x53,
 0x42,
@@ -7057,32 +6706,6 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x22,
 0xa,
 0xc8,
-0x5b,
-0x80,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0xb,
-0xd8,
-0xc,
-0xa,
-0x20,
-0x5b,
-0x81,
-0xc,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0x50,
-0x52,
-0x53,
-0x5f,
-0x40,
-0x10,
 0x14,
 0x4a,
 0x6,
@@ -7190,52 +6813,9 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x3,
 0x75,
 0x60,
-0x5b,
-0x82,
-0x29,
-0x50,
-0x52,
-0x45,
-0x53,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xa,
-0x6,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0xd8,
-0xc,
-0xd8,
-0xc,
-0x0,
-0x20,
-0x79,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x54,
-0x41,
-0xa,
-0xb,
 0x10,
-0x40,
-0x31,
+0x44,
+0x2a,
 0x2e,
 0x5f,
 0x53,
@@ -7247,8 +6827,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x30,
 0x5b,
 0x82,
-0x43,
-0x30,
+0x47,
+0x29,
 0x4d,
 0x48,
 0x50,
@@ -7298,37 +6878,6 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x65,
 0x73,
 0x0,
-0x5b,
-0x80,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0xb,
-0x0,
-0xa,
-0xa,
-0x18,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xa,
-0x0,
-0xa,
-0x0,
-0x18,
-0x79,
-0x0,
 0x14,
 0x13,
 0x5f,
@@ -7350,89 +6899,12 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0xa,
 0xb,
 0x5b,
-0x81,
-0x1f,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x52,
-0x42,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x42,
-0x48,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x48,
-0x20,
-0x4d,
-0x50,
-0x58,
-0x5f,
-0x20,
-0x5b,
-0x81,
-0x13,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0x0,
-0x40,
-0xa,
-0x4d,
-0x45,
-0x53,
-0x5f,
-0x1,
-0x4d,
-0x49,
-0x4e,
-0x53,
-0x1,
-0x5b,
 0x1,
 0x4d,
 0x4c,
 0x43,
 0x4b,
 0x0,
-0x5b,
-0x81,
-0x15,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x53,
-0x45,
-0x4c,
-0x20,
-0x4d,
-0x4f,
-0x45,
-0x56,
-0x20,
-0x4d,
-0x4f,
-0x53,
-0x43,
-0x20,
 0x14,
 0x4a,
 0x4,
@@ -8183,5 +7655,5 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x0
 };
 static unsigned short q35_dsdt_applesmc_sta[] = {
-0x3fa
+0x29b
 };
-- 
1.8.3.1

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

* [Qemu-devel] [RFC 47/47] tests: acpi: update reference DSDT/SSDT tables
  2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
                   ` (45 preceding siblings ...)
  2014-12-19  2:02 ` [Qemu-devel] [RFC 46/47] pc: acpi: update DSTD blobs Igor Mammedov
@ 2014-12-19  2:02 ` Igor Mammedov
  46 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2014-12-19  2:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, drjones, claudio.fontana, mst

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 tests/acpi-test-data/pc/DSDT  | Bin 3592 -> 3016 bytes
 tests/acpi-test-data/pc/SSDT  | Bin 2279 -> 2406 bytes
 tests/acpi-test-data/q35/DSDT | Bin 8182 -> 7654 bytes
 tests/acpi-test-data/q35/SSDT | Bin 560 -> 635 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/tests/acpi-test-data/pc/DSDT b/tests/acpi-test-data/pc/DSDT
index ee9cc6781cea3a9515b9a176eea3459f8e4d8655..eae08b02b0e007be3c01cb1cffd29de528d7a8e9 100644
GIT binary patch
delta 71
zcmeB>IU&yF66_Lkf}4SXF?1qV$7V&QcWg|)Jd*`E6DD_aW(x?oXz9fVJH-b$dm2PH
bxob`~<T9Mx$R*0g=<DO`&9M0;mpn57$m|nc

delta 647
zcmYjO&ubGw6n>LHJDqH5L)Annc29yAN!pN0JtWyIO>j33JD~`ROb*_>1o6^Sejqdy
zLCan|NrhZI*hTyU?9rqDfg;|;lQ}uQx9bMq!rSlr-h3ZBZ$FpkJEEgH1HK8s9-oQ%
zxL>)eRa;A^SLIINs#05sH}fLoETA&f*dbe5ON(*TnUyE$H;$LqiWkj$6yIk2%7wWA
z_yrla<F7Hm<%<7^4F>PXlX3$f4FnKiOo6hoa&S_{2}>D#Gv?Eu6kpyt2JS@nHg1e3
zs2Hk$r?MC6$8fbJv=b;erCW&?Qtj`h@Rf8k_*#1Vdm~v@n#KrRO~cXCX9+|d7|@w>
zE0VP%4GRi;=>(0s*lbDFsHgb4bTfEcdX4%>)+jOo6qx`|)95)RP{438{BZVjE!QqZ
zv-RQ4a3TXWU<HVU9Zs!;VAIX5===JUgK&07qLJ%vuVb~oh&4`^D;0$}WDw(H<65*D
zv_xU6SzG<maOPB_N4z!;Ctc|W7%xQSf2+W?S8!R|<c0H%$nW$6SinLQ!s#w~@_x|v
zY;0X@9w85re5mm=x06t43g1<l`MthkA@e=wK7`Y2sad&bdBEKx?8>n}zT><3zp%NT
A^Z)<=

diff --git a/tests/acpi-test-data/pc/SSDT b/tests/acpi-test-data/pc/SSDT
index 558e4c85b031ec081045aec6cc382a680e9c6009..9745918bdce5d19301aa5bf02e135bfe3eaf5ec9 100644
GIT binary patch
delta 656
zcma)4!EVz)5S?`**InC^n;Ov@K5{CS3Y=qaOq>uWE3b=+9BB`z&`OA)mL7U?QxI_H
z2RLwU4txN70zUzK021VcnXv_DM)G*xzFECD9)I8Z)~l2n6puFn*k(KvsS4r)DFB1v
zLp8m<zB}L5D%MhrLQ9KWZN(e>*;^M3hkBu=#D;9`tQ}_IIdeL6^b6^=^AEc<HU4;W
z9iZg_Dh_pRQ!j=A4Mma^R$YJk-Ikw!o<n&#?#fi=mQF_lS59RZg?GWy`-H?ONEa`j
zKRtUAoE)Am&Q2a3o+77;h}*4Wm-8WmE4X6*Ie0hc#O~>;XLd;s!EN2!=yIb4cQg{D
z?G0bi<mKi4?k<fl^F%ccoahTTTXiA#|4)4dD;D4+7cy4`vth-npj<i)!le6N`EpOl
zFeGIF-_coAzy~3-hyYGQKo#J-IvIxyK{AFTzc(%JJv83i?~VXo)BR&h$l0{lVayZO
z{8s1h^0HJ8tZXpNabQ}bTQy&W1BV^*mC7tfU!3oh%NqnbSsqUUOev-bRTHe_fkxlk
zO*iy;mMG1#(NwW=d9A&r66~EN4=^ba_+~~1y=>9^K{2wpPFsbcsVyB1@{fk`)%*j6
CFOup2

delta 528
zcmZ8e%}yIJ5FRffvYbGY)gCx<?WvAh#I?I#1B<d7vvz5!MVcJbTW(cP0V?$XM_vG=
zya5lu(*SP)%#d<`x%m6BKF^FF;>W?l`#d~K0I`{k&4J&}CeE-X0Dv){{n7dfNT)q^
ziAh2hyU)*ePtpyKQIR$DIOr&fSrrNPqcD0elzCNC+Je$QQ8@Z97`I!3o+JDfW7$%X
zieA|cI~?5q);;;WhCV}Q3SIaVoAXjRdmJPl6#2%HEx&86ht!bup##vIIy<ffGtr!N
z{u38uvV}gRFn0^Grq}JODJ<cpwN$-iv(8;0$GR|GPLuAB+66J6F_&m+KiE)epSJ=+
z{DDiBR8)-1Y6V*aClp^)1&8>+)*G1gFMb2}-~7$ijnkUvr;<gEyvNrmQsWAmVi%Gg
zmT7>cab?OEh;!4#DRsr|p%%v3L#DGNuEO5W=(=+?Q}B=De@WxURh(0+{dCStlbN?8
UXwG|HYm}I_bN&UmJ&W$!FHj(J>Hq)$

diff --git a/tests/acpi-test-data/q35/DSDT b/tests/acpi-test-data/q35/DSDT
index ef0c75f4236de3e6f727e21991533f2bf8279dee..60e1069e0dda60cf77be97979d246a7ebe6a1c1b 100644
GIT binary patch
delta 72
zcmV-O0Js14Kju3ML{mgm<{bb40h6%`Ujeho0%#ZlO$?JV8(@>H8*2~{L@F*{Q$k-*
eLrE}Of=4NnQXDapq8t?l0ZmLpO8~P99qa-@q!pC_

delta 583
zcmYk3u}T9$5Qb+X=&{*|L5=Z*m`bpb#Dp{{OmaC)@J^T8Ai@coQV}GGO)3)+6hSQR
z1uU!u@d5M^1PfD%m6e?kLJH5FJ0ngp_s#q>Kf8M$#r_(tifW_32tbDSRFad;*%c`&
zk{k7mW;mvZS0?D;MGPVgFnmm8oebE35l!_88^hMCl6&m0j`=wFbv_3W>HrjcKZ>I&
zA`mDftl-`EAHPE$e@eAMGrX&X`IC-n`53=rqYw7mFjJ<|a0Fc9Dd{d3xz!Mx+#KN^
zw{oj3o)Hpd1*Sx?b#xq{>H`6sxnUm9ZcDgDvundC<mqIYi$Xr+1UE;x#H~WU#j|J`
z09poMNtDje0S%hB&4)d*pNv%E-phPbcRSn>4HE4!ns&P^C{&WADKDoV6y4Kht~NDU
zt5;e1nT~6CyLgP!b<$%!25I#!QZ&jmI#tU4{Ui6($ar^pHsy9|+;&J5C{6xbRnJZ#
z+4kP_gy=5f$e8U^th7osl`JGn5#N#ORMUY6l&EbAN$mQjATF^jV*}joY`82;wX$Vy
Nt0au{!%+W>`~VF5krw~}

diff --git a/tests/acpi-test-data/q35/SSDT b/tests/acpi-test-data/q35/SSDT
index 4e45510181c4038505ae1815b76799a2cd0e8808..7ac1c8719ad075625fc7e70a58d075a83e5141c2 100644
GIT binary patch
literal 635
zcmX|8!EVz)5S>j*u-0qI1S2Xg_<)4Op%_9XPN??U)DE$;@;a!<k@kQpiiBF!(nH0C
z1PQqF104Dv@Ch9A9~{UDGh-7*^7y@(H|w`!t>fx_4}dMBsZ6yW9ViJH3?IVuc4KS4
zV{~Mc%mT~EQeTU%^5ZWK^aN?4p~UvtTC4@Lu+BuEO24ta7XP`^knq>%n*d!OfJ4*R
zB*o}K+o3N~{Ail*fBwNI7vSEVgJtx{3<p~zLHvj?DG={&u$$c?tM&5P)(-hqWuh&U
zX0Zr=@_}V$S?owP^V5@eZ{M81@=p)XPR>tX9-h%DRmkn`f)3~VY$aBL`4>=sP^GSz
zy%OB77osJY%${3+97z=folQ@eJgneSsyqZFcpMR3f#;ZH955uw7>>MQQ9XUp`(}SV
z0{BGpuPv#j#jwwqE3Ntc{$|;Es$wgTixSPz+FMt+G!EP3Dph&OY~XymUfd?q&&z1y
zV@fei2u%>F1B14&w`$nqd7=%=vqH0aaig2k32LXwb4*(L-XJG`?(_;RuwLHLL0~Ks
u#$-d!3h;*Qb(BoT5sp%=Uf$Ee<4%Qtoq>na2Qgf>;Nb?0S};(usNgTG0Eqzr

literal 560
zcmZ8dyH3L}6umB?vfMyRm4T5J7F-^Jk<<y0ilinsF9qp#EE_8u6p4kA9{{QU0l&Zx
z0r#eW1YUd|*73c^xy0)RfOzi@&7oWApIhTd69B-N@6OTuB}l6shQ!_or5JvGzJ5sC
zJ4HoS&*4%_NpkB$Li%4g`YYr~QF0n|Rw*0ZCU%>Fpx+2@VOItU6uHE<*{NUdg_rAd
z==x|)rZX2~HOZAtPrby$ELk{C^AoLgkLF38Zvj-dHXW9NnW*ks-^6+uEu-@>T(dKJ
zZa$4*3NOJ_wWGx{v7Qa<N7GRho|V>%>oIeQrgTdSN*!<~AjAzkvZNZ>FfV2>Ab3vc
zS&_}s*{Z)`qjMhuk6+#Q=Z)2xV`#-JK`yc0AvQLn9d;mUV;*~$8k@)bfH;p#-1%>w
z4zw^f9WWh7-NNr*G@e^eV+9YKekF|^7Tts<?F<60teUi))+jMfX5CklHK%uf1pyKD
S-Akwq1{*(Mvj$CT3J+f`A9n!&

-- 
1.8.3.1

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

* Re: [Qemu-devel] [RFC 14/47] acpi: add acpi_notify() term
  2014-12-19  2:02 ` [Qemu-devel] [RFC 14/47] acpi: add acpi_notify() term Igor Mammedov
@ 2015-01-19 12:32   ` Paolo Bonzini
  2015-01-20  9:40     ` Igor Mammedov
  0 siblings, 1 reply; 58+ messages in thread
From: Paolo Bonzini @ 2015-01-19 12:32 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: drjones, claudio.fontana, mst



On 19/12/2014 03:02, Igor Mammedov wrote:
> +    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
> +    build_append_byte(var.buf, 0x86); /* NotifyOp */ \

Extra backslash.

Paolo

> +    aml_append(&var, arg1);

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

* Re: [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets
  2014-12-19  2:02 ` [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets Igor Mammedov
@ 2015-01-19 12:36   ` Paolo Bonzini
  2015-01-19 21:54     ` Michael S. Tsirkin
  2015-01-19 22:05   ` Michael S. Tsirkin
  1 sibling, 1 reply; 58+ messages in thread
From: Paolo Bonzini @ 2015-01-19 12:36 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: drjones, claudio.fontana, mst



On 19/12/2014 03:02, Igor Mammedov wrote:
> keeping bios-linker-loader.c i386 specific would break build
> of mips target which is built with CONFIG_ACPI which would
> dependend on it in following patch that adds acpi_def_block()
> term. Also UEFI for ARM target is going to use linker as well
> so it makes sense to move it into generic target independent
> ACPI part.

Makes sense now that fw_cfg was added "officially" to -M virt.

Paolo

> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  hw/acpi/Makefile.objs                |   2 +-
>  hw/acpi/acpi_gen_utils.c             |   1 +
>  hw/acpi/bios-linker-loader.c         | 157 +++++++++++++++++++++++++++++++++++
>  hw/i386/Makefile.objs                |   1 -
>  hw/i386/acpi-build.c                 |   2 +-
>  hw/i386/bios-linker-loader.c         | 157 -----------------------------------
>  hw/i386/bios-linker-loader.h         |  27 ------
>  include/hw/acpi/bios-linker-loader.h |  27 ++++++
>  8 files changed, 187 insertions(+), 187 deletions(-)
>  create mode 100644 hw/acpi/bios-linker-loader.c
>  delete mode 100644 hw/i386/bios-linker-loader.c
>  delete mode 100644 hw/i386/bios-linker-loader.h
>  create mode 100644 include/hw/acpi/bios-linker-loader.h
> 
> diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> index 4237232..02ca4ed 100644
> --- a/hw/acpi/Makefile.objs
> +++ b/hw/acpi/Makefile.objs
> @@ -1,4 +1,4 @@
>  common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
>  common-obj-$(CONFIG_ACPI) += memory_hotplug.o
>  common-obj-$(CONFIG_ACPI) += acpi_interface.o
> -common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o
> +common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o bios-linker-loader.o
> diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
> index 39cbab7..cc2fa03 100644
> --- a/hw/acpi/acpi_gen_utils.c
> +++ b/hw/acpi/acpi_gen_utils.c
> @@ -5,6 +5,7 @@
>  #include <string.h>
>  #include "hw/acpi/acpi_gen_utils.h"
>  #include "qemu/bswap.h"
> +#include "hw/acpi/bios-linker-loader.h"
>  
>  GArray *build_alloc_array(void)
>  {
> diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c
> new file mode 100644
> index 0000000..5cc4d90
> --- /dev/null
> +++ b/hw/acpi/bios-linker-loader.c
> @@ -0,0 +1,157 @@
> +/* Dynamic linker/loader of ACPI tables
> + *
> + * Copyright (C) 2013 Red Hat Inc
> + *
> + * Author: Michael S. Tsirkin <mst@redhat.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> +
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> +
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include "qemu-common.h"
> +#include "hw/acpi/bios-linker-loader.h"
> +#include "hw/nvram/fw_cfg.h"
> +
> +#include "qemu/bswap.h"
> +
> +#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> +
> +struct BiosLinkerLoaderEntry {
> +    uint32_t command;
> +    union {
> +        /*
> +         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> +         * subject to @alloc.align alignment (must be power of 2)
> +         * and @alloc.zone (can be HIGH or FSEG) requirements.
> +         *
> +         * Must appear exactly once for each file, and before
> +         * this file is referenced by any other command.
> +         */
> +        struct {
> +            char file[BIOS_LINKER_LOADER_FILESZ];
> +            uint32_t align;
> +            uint8_t zone;
> +        } alloc;
> +
> +        /*
> +         * COMMAND_ADD_POINTER - patch the table (originating from
> +         * @dest_file) at @pointer.offset, by adding a pointer to the table
> +         * originating from @src_file. 1,2,4 or 8 byte unsigned
> +         * addition is used depending on @pointer.size.
> +         */
> +        struct {
> +            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> +            char src_file[BIOS_LINKER_LOADER_FILESZ];
> +            uint32_t offset;
> +            uint8_t size;
> +        } pointer;
> +
> +        /*
> +         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> +         * @cksum_start and @cksum_length fields,
> +         * and then add the value at @cksum.offset.
> +         * Checksum simply sums -X for each byte X in the range
> +         * using 8-bit math.
> +         */
> +        struct {
> +            char file[BIOS_LINKER_LOADER_FILESZ];
> +            uint32_t offset;
> +            uint32_t start;
> +            uint32_t length;
> +        } cksum;
> +
> +        /* padding */
> +        char pad[124];
> +    };
> +} QEMU_PACKED;
> +typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> +
> +enum {
> +    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> +    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> +    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> +};
> +
> +enum {
> +    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> +    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> +};
> +
> +GArray *bios_linker_loader_init(void)
> +{
> +    return g_array_new(false, true /* clear */, 1);
> +}
> +
> +/* Free linker wrapper and return the linker array. */
> +void *bios_linker_loader_cleanup(GArray *linker)
> +{
> +    return g_array_free(linker, false);
> +}
> +
> +void bios_linker_loader_alloc(GArray *linker,
> +                              const char *file,
> +                              uint32_t alloc_align,
> +                              bool alloc_fseg)
> +{
> +    BiosLinkerLoaderEntry entry;
> +
> +    memset(&entry, 0, sizeof entry);
> +    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> +    entry.alloc.align = cpu_to_le32(alloc_align);
> +    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> +
> +    /* Alloc entries must come first, so prepend them */
> +    g_array_prepend_vals(linker, &entry, sizeof entry);
> +}
> +
> +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> +                                     void *table,
> +                                     void *start, unsigned size,
> +                                     uint8_t *checksum)
> +{
> +    BiosLinkerLoaderEntry entry;
> +
> +    memset(&entry, 0, sizeof entry);
> +    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> +    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> +    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> +    entry.cksum.length = cpu_to_le32(size);
> +
> +    g_array_append_vals(linker, &entry, sizeof entry);
> +}
> +
> +void bios_linker_loader_add_pointer(GArray *linker,
> +                                    const char *dest_file,
> +                                    const char *src_file,
> +                                    GArray *table, void *pointer,
> +                                    uint8_t pointer_size)
> +{
> +    BiosLinkerLoaderEntry entry;
> +
> +    memset(&entry, 0, sizeof entry);
> +    strncpy(entry.pointer.dest_file, dest_file,
> +            sizeof entry.pointer.dest_file - 1);
> +    strncpy(entry.pointer.src_file, src_file,
> +            sizeof entry.pointer.src_file - 1);
> +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> +    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> +    entry.pointer.size = pointer_size;
> +    assert(pointer_size == 1 || pointer_size == 2 ||
> +           pointer_size == 4 || pointer_size == 8);
> +
> +    g_array_append_vals(linker, &entry, sizeof entry);
> +}
> diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> index 790a56c..6c8705d 100644
> --- a/hw/i386/Makefile.objs
> +++ b/hw/i386/Makefile.objs
> @@ -7,7 +7,6 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
>  
>  obj-y += kvmvapic.o
>  obj-y += acpi-build.o
> -obj-y += bios-linker-loader.o
>  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
>  	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
>  	hw/i386/ssdt-tpm.hex
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index b425156..e0fa30a 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -36,7 +36,7 @@
>  #include "hw/i386/acpi-defs.h"
>  #include "hw/acpi/acpi.h"
>  #include "hw/nvram/fw_cfg.h"
> -#include "bios-linker-loader.h"
> +#include "hw/acpi/bios-linker-loader.h"
>  #include "hw/loader.h"
>  #include "hw/isa/isa.h"
>  #include "hw/acpi/memory_hotplug.h"
> diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
> deleted file mode 100644
> index aa56184..0000000
> --- a/hw/i386/bios-linker-loader.c
> +++ /dev/null
> @@ -1,157 +0,0 @@
> -/* Dynamic linker/loader of ACPI tables
> - *
> - * Copyright (C) 2013 Red Hat Inc
> - *
> - * Author: Michael S. Tsirkin <mst@redhat.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> -
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> -
> - * You should have received a copy of the GNU General Public License along
> - * with this program; if not, see <http://www.gnu.org/licenses/>.
> - */
> -
> -#include "qemu-common.h"
> -#include "bios-linker-loader.h"
> -#include "hw/nvram/fw_cfg.h"
> -
> -#include "qemu/bswap.h"
> -
> -#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> -
> -struct BiosLinkerLoaderEntry {
> -    uint32_t command;
> -    union {
> -        /*
> -         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> -         * subject to @alloc.align alignment (must be power of 2)
> -         * and @alloc.zone (can be HIGH or FSEG) requirements.
> -         *
> -         * Must appear exactly once for each file, and before
> -         * this file is referenced by any other command.
> -         */
> -        struct {
> -            char file[BIOS_LINKER_LOADER_FILESZ];
> -            uint32_t align;
> -            uint8_t zone;
> -        } alloc;
> -
> -        /*
> -         * COMMAND_ADD_POINTER - patch the table (originating from
> -         * @dest_file) at @pointer.offset, by adding a pointer to the table
> -         * originating from @src_file. 1,2,4 or 8 byte unsigned
> -         * addition is used depending on @pointer.size.
> -         */
> -        struct {
> -            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> -            char src_file[BIOS_LINKER_LOADER_FILESZ];
> -            uint32_t offset;
> -            uint8_t size;
> -        } pointer;
> -
> -        /*
> -         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> -         * @cksum_start and @cksum_length fields,
> -         * and then add the value at @cksum.offset.
> -         * Checksum simply sums -X for each byte X in the range
> -         * using 8-bit math.
> -         */
> -        struct {
> -            char file[BIOS_LINKER_LOADER_FILESZ];
> -            uint32_t offset;
> -            uint32_t start;
> -            uint32_t length;
> -        } cksum;
> -
> -        /* padding */
> -        char pad[124];
> -    };
> -} QEMU_PACKED;
> -typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> -
> -enum {
> -    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> -    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> -    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> -};
> -
> -enum {
> -    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> -    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> -};
> -
> -GArray *bios_linker_loader_init(void)
> -{
> -    return g_array_new(false, true /* clear */, 1);
> -}
> -
> -/* Free linker wrapper and return the linker array. */
> -void *bios_linker_loader_cleanup(GArray *linker)
> -{
> -    return g_array_free(linker, false);
> -}
> -
> -void bios_linker_loader_alloc(GArray *linker,
> -                              const char *file,
> -                              uint32_t alloc_align,
> -                              bool alloc_fseg)
> -{
> -    BiosLinkerLoaderEntry entry;
> -
> -    memset(&entry, 0, sizeof entry);
> -    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> -    entry.alloc.align = cpu_to_le32(alloc_align);
> -    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> -
> -    /* Alloc entries must come first, so prepend them */
> -    g_array_prepend_vals(linker, &entry, sizeof entry);
> -}
> -
> -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> -                                     void *table,
> -                                     void *start, unsigned size,
> -                                     uint8_t *checksum)
> -{
> -    BiosLinkerLoaderEntry entry;
> -
> -    memset(&entry, 0, sizeof entry);
> -    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> -    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> -    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> -    entry.cksum.length = cpu_to_le32(size);
> -
> -    g_array_append_vals(linker, &entry, sizeof entry);
> -}
> -
> -void bios_linker_loader_add_pointer(GArray *linker,
> -                                    const char *dest_file,
> -                                    const char *src_file,
> -                                    GArray *table, void *pointer,
> -                                    uint8_t pointer_size)
> -{
> -    BiosLinkerLoaderEntry entry;
> -
> -    memset(&entry, 0, sizeof entry);
> -    strncpy(entry.pointer.dest_file, dest_file,
> -            sizeof entry.pointer.dest_file - 1);
> -    strncpy(entry.pointer.src_file, src_file,
> -            sizeof entry.pointer.src_file - 1);
> -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> -    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> -    entry.pointer.size = pointer_size;
> -    assert(pointer_size == 1 || pointer_size == 2 ||
> -           pointer_size == 4 || pointer_size == 8);
> -
> -    g_array_append_vals(linker, &entry, sizeof entry);
> -}
> diff --git a/hw/i386/bios-linker-loader.h b/hw/i386/bios-linker-loader.h
> deleted file mode 100644
> index 498c0af..0000000
> --- a/hw/i386/bios-linker-loader.h
> +++ /dev/null
> @@ -1,27 +0,0 @@
> -#ifndef BIOS_LINKER_LOADER_H
> -#define BIOS_LINKER_LOADER_H
> -
> -#include <glib.h>
> -#include <stdbool.h>
> -#include <inttypes.h>
> -
> -GArray *bios_linker_loader_init(void);
> -
> -void bios_linker_loader_alloc(GArray *linker,
> -                              const char *file,
> -                              uint32_t alloc_align,
> -                              bool alloc_fseg);
> -
> -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> -                                     void *table,
> -                                     void *start, unsigned size,
> -                                     uint8_t *checksum);
> -
> -void bios_linker_loader_add_pointer(GArray *linker,
> -                                    const char *dest_file,
> -                                    const char *src_file,
> -                                    GArray *table, void *pointer,
> -                                    uint8_t pointer_size);
> -
> -void *bios_linker_loader_cleanup(GArray *linker);
> -#endif
> diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-linker-loader.h
> new file mode 100644
> index 0000000..498c0af
> --- /dev/null
> +++ b/include/hw/acpi/bios-linker-loader.h
> @@ -0,0 +1,27 @@
> +#ifndef BIOS_LINKER_LOADER_H
> +#define BIOS_LINKER_LOADER_H
> +
> +#include <glib.h>
> +#include <stdbool.h>
> +#include <inttypes.h>
> +
> +GArray *bios_linker_loader_init(void);
> +
> +void bios_linker_loader_alloc(GArray *linker,
> +                              const char *file,
> +                              uint32_t alloc_align,
> +                              bool alloc_fseg);
> +
> +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> +                                     void *table,
> +                                     void *start, unsigned size,
> +                                     uint8_t *checksum);
> +
> +void bios_linker_loader_add_pointer(GArray *linker,
> +                                    const char *dest_file,
> +                                    const char *src_file,
> +                                    GArray *table, void *pointer,
> +                                    uint8_t pointer_size);
> +
> +void *bios_linker_loader_cleanup(GArray *linker);
> +#endif
> 

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

* Re: [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically
  2014-12-19  2:02 ` [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
@ 2015-01-19 12:42   ` Paolo Bonzini
  2015-01-19 21:55     ` Michael S. Tsirkin
  0 siblings, 1 reply; 58+ messages in thread
From: Paolo Bonzini @ 2015-01-19 12:42 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel; +Cc: drjones, claudio.fontana, mst



On 19/12/2014 03:02, 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 is a good idea.  It's simpler to just do this in the SSDT than to
split it between DSDT and SSDT.  The AML's purpose is just to build a
static value anyway.

Paolo

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

* Re: [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets
  2015-01-19 12:36   ` Paolo Bonzini
@ 2015-01-19 21:54     ` Michael S. Tsirkin
  0 siblings, 0 replies; 58+ messages in thread
From: Michael S. Tsirkin @ 2015-01-19 21:54 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Igor Mammedov, drjones, claudio.fontana, qemu-devel

On Mon, Jan 19, 2015 at 01:36:36PM +0100, Paolo Bonzini wrote:
> 
> 
> On 19/12/2014 03:02, Igor Mammedov wrote:
> > keeping bios-linker-loader.c i386 specific would break build
> > of mips target which is built with CONFIG_ACPI which would
> > dependend on it in following patch that adds acpi_def_block()
> > term. Also UEFI for ARM target is going to use linker as well
> > so it makes sense to move it into generic target independent
> > ACPI part.
> 
> Makes sense now that fw_cfg was added "officially" to -M virt.
> 
> Paolo

I'm not sure why doesn't git detect this as a move.
Did you also change files at the same time?  Please don't: this makes
the patch extremely hard to check. You can use tricks e.g. using the
preprocessor to split move away from code changes.


> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  hw/acpi/Makefile.objs                |   2 +-
> >  hw/acpi/acpi_gen_utils.c             |   1 +
> >  hw/acpi/bios-linker-loader.c         | 157 +++++++++++++++++++++++++++++++++++
> >  hw/i386/Makefile.objs                |   1 -
> >  hw/i386/acpi-build.c                 |   2 +-
> >  hw/i386/bios-linker-loader.c         | 157 -----------------------------------
> >  hw/i386/bios-linker-loader.h         |  27 ------
> >  include/hw/acpi/bios-linker-loader.h |  27 ++++++
> >  8 files changed, 187 insertions(+), 187 deletions(-)
> >  create mode 100644 hw/acpi/bios-linker-loader.c
> >  delete mode 100644 hw/i386/bios-linker-loader.c
> >  delete mode 100644 hw/i386/bios-linker-loader.h
> >  create mode 100644 include/hw/acpi/bios-linker-loader.h
> > 
> > diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> > index 4237232..02ca4ed 100644
> > --- a/hw/acpi/Makefile.objs
> > +++ b/hw/acpi/Makefile.objs
> > @@ -1,4 +1,4 @@
> >  common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
> >  common-obj-$(CONFIG_ACPI) += memory_hotplug.o
> >  common-obj-$(CONFIG_ACPI) += acpi_interface.o
> > -common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o
> > +common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o bios-linker-loader.o
> > diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
> > index 39cbab7..cc2fa03 100644
> > --- a/hw/acpi/acpi_gen_utils.c
> > +++ b/hw/acpi/acpi_gen_utils.c
> > @@ -5,6 +5,7 @@
> >  #include <string.h>
> >  #include "hw/acpi/acpi_gen_utils.h"
> >  #include "qemu/bswap.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> >  
> >  GArray *build_alloc_array(void)
> >  {
> > diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c
> > new file mode 100644
> > index 0000000..5cc4d90
> > --- /dev/null
> > +++ b/hw/acpi/bios-linker-loader.c
> > @@ -0,0 +1,157 @@
> > +/* Dynamic linker/loader of ACPI tables
> > + *
> > + * Copyright (C) 2013 Red Hat Inc
> > + *
> > + * Author: Michael S. Tsirkin <mst@redhat.com>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > +
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > +
> > + * You should have received a copy of the GNU General Public License along
> > + * with this program; if not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include "qemu-common.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> > +#include "hw/nvram/fw_cfg.h"
> > +
> > +#include "qemu/bswap.h"
> > +
> > +#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> > +
> > +struct BiosLinkerLoaderEntry {
> > +    uint32_t command;
> > +    union {
> > +        /*
> > +         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> > +         * subject to @alloc.align alignment (must be power of 2)
> > +         * and @alloc.zone (can be HIGH or FSEG) requirements.
> > +         *
> > +         * Must appear exactly once for each file, and before
> > +         * this file is referenced by any other command.
> > +         */
> > +        struct {
> > +            char file[BIOS_LINKER_LOADER_FILESZ];
> > +            uint32_t align;
> > +            uint8_t zone;
> > +        } alloc;
> > +
> > +        /*
> > +         * COMMAND_ADD_POINTER - patch the table (originating from
> > +         * @dest_file) at @pointer.offset, by adding a pointer to the table
> > +         * originating from @src_file. 1,2,4 or 8 byte unsigned
> > +         * addition is used depending on @pointer.size.
> > +         */
> > +        struct {
> > +            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> > +            char src_file[BIOS_LINKER_LOADER_FILESZ];
> > +            uint32_t offset;
> > +            uint8_t size;
> > +        } pointer;
> > +
> > +        /*
> > +         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> > +         * @cksum_start and @cksum_length fields,
> > +         * and then add the value at @cksum.offset.
> > +         * Checksum simply sums -X for each byte X in the range
> > +         * using 8-bit math.
> > +         */
> > +        struct {
> > +            char file[BIOS_LINKER_LOADER_FILESZ];
> > +            uint32_t offset;
> > +            uint32_t start;
> > +            uint32_t length;
> > +        } cksum;
> > +
> > +        /* padding */
> > +        char pad[124];
> > +    };
> > +} QEMU_PACKED;
> > +typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> > +
> > +enum {
> > +    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> > +    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> > +    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> > +};
> > +
> > +enum {
> > +    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> > +    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> > +};
> > +
> > +GArray *bios_linker_loader_init(void)
> > +{
> > +    return g_array_new(false, true /* clear */, 1);
> > +}
> > +
> > +/* Free linker wrapper and return the linker array. */
> > +void *bios_linker_loader_cleanup(GArray *linker)
> > +{
> > +    return g_array_free(linker, false);
> > +}
> > +
> > +void bios_linker_loader_alloc(GArray *linker,
> > +                              const char *file,
> > +                              uint32_t alloc_align,
> > +                              bool alloc_fseg)
> > +{
> > +    BiosLinkerLoaderEntry entry;
> > +
> > +    memset(&entry, 0, sizeof entry);
> > +    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> > +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> > +    entry.alloc.align = cpu_to_le32(alloc_align);
> > +    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> > +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> > +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> > +
> > +    /* Alloc entries must come first, so prepend them */
> > +    g_array_prepend_vals(linker, &entry, sizeof entry);
> > +}
> > +
> > +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > +                                     void *table,
> > +                                     void *start, unsigned size,
> > +                                     uint8_t *checksum)
> > +{
> > +    BiosLinkerLoaderEntry entry;
> > +
> > +    memset(&entry, 0, sizeof entry);
> > +    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> > +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> > +    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> > +    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> > +    entry.cksum.length = cpu_to_le32(size);
> > +
> > +    g_array_append_vals(linker, &entry, sizeof entry);
> > +}
> > +
> > +void bios_linker_loader_add_pointer(GArray *linker,
> > +                                    const char *dest_file,
> > +                                    const char *src_file,
> > +                                    GArray *table, void *pointer,
> > +                                    uint8_t pointer_size)
> > +{
> > +    BiosLinkerLoaderEntry entry;
> > +
> > +    memset(&entry, 0, sizeof entry);
> > +    strncpy(entry.pointer.dest_file, dest_file,
> > +            sizeof entry.pointer.dest_file - 1);
> > +    strncpy(entry.pointer.src_file, src_file,
> > +            sizeof entry.pointer.src_file - 1);
> > +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> > +    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> > +    entry.pointer.size = pointer_size;
> > +    assert(pointer_size == 1 || pointer_size == 2 ||
> > +           pointer_size == 4 || pointer_size == 8);
> > +
> > +    g_array_append_vals(linker, &entry, sizeof entry);
> > +}
> > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> > index 790a56c..6c8705d 100644
> > --- a/hw/i386/Makefile.objs
> > +++ b/hw/i386/Makefile.objs
> > @@ -7,7 +7,6 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
> >  
> >  obj-y += kvmvapic.o
> >  obj-y += acpi-build.o
> > -obj-y += bios-linker-loader.o
> >  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> >  	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> >  	hw/i386/ssdt-tpm.hex
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index b425156..e0fa30a 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -36,7 +36,7 @@
> >  #include "hw/i386/acpi-defs.h"
> >  #include "hw/acpi/acpi.h"
> >  #include "hw/nvram/fw_cfg.h"
> > -#include "bios-linker-loader.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> >  #include "hw/loader.h"
> >  #include "hw/isa/isa.h"
> >  #include "hw/acpi/memory_hotplug.h"
> > diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
> > deleted file mode 100644
> > index aa56184..0000000
> > --- a/hw/i386/bios-linker-loader.c
> > +++ /dev/null
> > @@ -1,157 +0,0 @@
> > -/* Dynamic linker/loader of ACPI tables
> > - *
> > - * Copyright (C) 2013 Red Hat Inc
> > - *
> > - * Author: Michael S. Tsirkin <mst@redhat.com>
> > - *
> > - * This program is free software; you can redistribute it and/or modify
> > - * it under the terms of the GNU General Public License as published by
> > - * the Free Software Foundation; either version 2 of the License, or
> > - * (at your option) any later version.
> > -
> > - * This program is distributed in the hope that it will be useful,
> > - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > - * GNU General Public License for more details.
> > -
> > - * You should have received a copy of the GNU General Public License along
> > - * with this program; if not, see <http://www.gnu.org/licenses/>.
> > - */
> > -
> > -#include "qemu-common.h"
> > -#include "bios-linker-loader.h"
> > -#include "hw/nvram/fw_cfg.h"
> > -
> > -#include "qemu/bswap.h"
> > -
> > -#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> > -
> > -struct BiosLinkerLoaderEntry {
> > -    uint32_t command;
> > -    union {
> > -        /*
> > -         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> > -         * subject to @alloc.align alignment (must be power of 2)
> > -         * and @alloc.zone (can be HIGH or FSEG) requirements.
> > -         *
> > -         * Must appear exactly once for each file, and before
> > -         * this file is referenced by any other command.
> > -         */
> > -        struct {
> > -            char file[BIOS_LINKER_LOADER_FILESZ];
> > -            uint32_t align;
> > -            uint8_t zone;
> > -        } alloc;
> > -
> > -        /*
> > -         * COMMAND_ADD_POINTER - patch the table (originating from
> > -         * @dest_file) at @pointer.offset, by adding a pointer to the table
> > -         * originating from @src_file. 1,2,4 or 8 byte unsigned
> > -         * addition is used depending on @pointer.size.
> > -         */
> > -        struct {
> > -            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> > -            char src_file[BIOS_LINKER_LOADER_FILESZ];
> > -            uint32_t offset;
> > -            uint8_t size;
> > -        } pointer;
> > -
> > -        /*
> > -         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> > -         * @cksum_start and @cksum_length fields,
> > -         * and then add the value at @cksum.offset.
> > -         * Checksum simply sums -X for each byte X in the range
> > -         * using 8-bit math.
> > -         */
> > -        struct {
> > -            char file[BIOS_LINKER_LOADER_FILESZ];
> > -            uint32_t offset;
> > -            uint32_t start;
> > -            uint32_t length;
> > -        } cksum;
> > -
> > -        /* padding */
> > -        char pad[124];
> > -    };
> > -} QEMU_PACKED;
> > -typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> > -
> > -enum {
> > -    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> > -    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> > -    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> > -};
> > -
> > -enum {
> > -    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> > -    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> > -};
> > -
> > -GArray *bios_linker_loader_init(void)
> > -{
> > -    return g_array_new(false, true /* clear */, 1);
> > -}
> > -
> > -/* Free linker wrapper and return the linker array. */
> > -void *bios_linker_loader_cleanup(GArray *linker)
> > -{
> > -    return g_array_free(linker, false);
> > -}
> > -
> > -void bios_linker_loader_alloc(GArray *linker,
> > -                              const char *file,
> > -                              uint32_t alloc_align,
> > -                              bool alloc_fseg)
> > -{
> > -    BiosLinkerLoaderEntry entry;
> > -
> > -    memset(&entry, 0, sizeof entry);
> > -    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> > -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> > -    entry.alloc.align = cpu_to_le32(alloc_align);
> > -    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> > -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> > -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> > -
> > -    /* Alloc entries must come first, so prepend them */
> > -    g_array_prepend_vals(linker, &entry, sizeof entry);
> > -}
> > -
> > -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > -                                     void *table,
> > -                                     void *start, unsigned size,
> > -                                     uint8_t *checksum)
> > -{
> > -    BiosLinkerLoaderEntry entry;
> > -
> > -    memset(&entry, 0, sizeof entry);
> > -    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> > -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> > -    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> > -    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> > -    entry.cksum.length = cpu_to_le32(size);
> > -
> > -    g_array_append_vals(linker, &entry, sizeof entry);
> > -}
> > -
> > -void bios_linker_loader_add_pointer(GArray *linker,
> > -                                    const char *dest_file,
> > -                                    const char *src_file,
> > -                                    GArray *table, void *pointer,
> > -                                    uint8_t pointer_size)
> > -{
> > -    BiosLinkerLoaderEntry entry;
> > -
> > -    memset(&entry, 0, sizeof entry);
> > -    strncpy(entry.pointer.dest_file, dest_file,
> > -            sizeof entry.pointer.dest_file - 1);
> > -    strncpy(entry.pointer.src_file, src_file,
> > -            sizeof entry.pointer.src_file - 1);
> > -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> > -    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> > -    entry.pointer.size = pointer_size;
> > -    assert(pointer_size == 1 || pointer_size == 2 ||
> > -           pointer_size == 4 || pointer_size == 8);
> > -
> > -    g_array_append_vals(linker, &entry, sizeof entry);
> > -}
> > diff --git a/hw/i386/bios-linker-loader.h b/hw/i386/bios-linker-loader.h
> > deleted file mode 100644
> > index 498c0af..0000000
> > --- a/hw/i386/bios-linker-loader.h
> > +++ /dev/null
> > @@ -1,27 +0,0 @@
> > -#ifndef BIOS_LINKER_LOADER_H
> > -#define BIOS_LINKER_LOADER_H
> > -
> > -#include <glib.h>
> > -#include <stdbool.h>
> > -#include <inttypes.h>
> > -
> > -GArray *bios_linker_loader_init(void);
> > -
> > -void bios_linker_loader_alloc(GArray *linker,
> > -                              const char *file,
> > -                              uint32_t alloc_align,
> > -                              bool alloc_fseg);
> > -
> > -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > -                                     void *table,
> > -                                     void *start, unsigned size,
> > -                                     uint8_t *checksum);
> > -
> > -void bios_linker_loader_add_pointer(GArray *linker,
> > -                                    const char *dest_file,
> > -                                    const char *src_file,
> > -                                    GArray *table, void *pointer,
> > -                                    uint8_t pointer_size);
> > -
> > -void *bios_linker_loader_cleanup(GArray *linker);
> > -#endif
> > diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-linker-loader.h
> > new file mode 100644
> > index 0000000..498c0af
> > --- /dev/null
> > +++ b/include/hw/acpi/bios-linker-loader.h
> > @@ -0,0 +1,27 @@
> > +#ifndef BIOS_LINKER_LOADER_H
> > +#define BIOS_LINKER_LOADER_H
> > +
> > +#include <glib.h>
> > +#include <stdbool.h>
> > +#include <inttypes.h>
> > +
> > +GArray *bios_linker_loader_init(void);
> > +
> > +void bios_linker_loader_alloc(GArray *linker,
> > +                              const char *file,
> > +                              uint32_t alloc_align,
> > +                              bool alloc_fseg);
> > +
> > +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > +                                     void *table,
> > +                                     void *start, unsigned size,
> > +                                     uint8_t *checksum);
> > +
> > +void bios_linker_loader_add_pointer(GArray *linker,
> > +                                    const char *dest_file,
> > +                                    const char *src_file,
> > +                                    GArray *table, void *pointer,
> > +                                    uint8_t pointer_size);
> > +
> > +void *bios_linker_loader_cleanup(GArray *linker);
> > +#endif
> > 

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

* Re: [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically
  2015-01-19 12:42   ` Paolo Bonzini
@ 2015-01-19 21:55     ` Michael S. Tsirkin
  2015-01-20  9:37       ` Marcel Apfelbaum
  2015-01-20  9:42       ` Igor Mammedov
  0 siblings, 2 replies; 58+ messages in thread
From: Michael S. Tsirkin @ 2015-01-19 21:55 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Igor Mammedov, drjones, claudio.fontana, qemu-devel, Marcel Apfelbaum

On Mon, Jan 19, 2015 at 01:42:25PM +0100, Paolo Bonzini wrote:
> 
> 
> On 19/12/2014 03:02, 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 is a good idea.  It's simpler to just do this in the SSDT than to
> split it between DSDT and SSDT.  The AML's purpose is just to build a
> static value anyway.
> 
> Paolo

I think Marcel has patches going in exactly the reverse
direction with this.
Marcel?

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

* Re: [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets
  2014-12-19  2:02 ` [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets Igor Mammedov
  2015-01-19 12:36   ` Paolo Bonzini
@ 2015-01-19 22:05   ` Michael S. Tsirkin
  2015-01-20  9:43     ` Igor Mammedov
  1 sibling, 1 reply; 58+ messages in thread
From: Michael S. Tsirkin @ 2015-01-19 22:05 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: pbonzini, drjones, claudio.fontana, qemu-devel

On Fri, Dec 19, 2014 at 02:02:37AM +0000, Igor Mammedov wrote:
> keeping bios-linker-loader.c i386 specific would break build
> of mips target which is built with CONFIG_ACPI which would
> dependend on it in following patch that adds acpi_def_block()
> term. Also UEFI for ARM target is going to use linker as well
> so it makes sense to move it into generic target independent
> ACPI part.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

I reworked this one to avoid the huge diffs.
Pls check the pci branch.

> ---
>  hw/acpi/Makefile.objs                |   2 +-
>  hw/acpi/acpi_gen_utils.c             |   1 +
>  hw/acpi/bios-linker-loader.c         | 157 +++++++++++++++++++++++++++++++++++
>  hw/i386/Makefile.objs                |   1 -
>  hw/i386/acpi-build.c                 |   2 +-
>  hw/i386/bios-linker-loader.c         | 157 -----------------------------------
>  hw/i386/bios-linker-loader.h         |  27 ------
>  include/hw/acpi/bios-linker-loader.h |  27 ++++++
>  8 files changed, 187 insertions(+), 187 deletions(-)
>  create mode 100644 hw/acpi/bios-linker-loader.c
>  delete mode 100644 hw/i386/bios-linker-loader.c
>  delete mode 100644 hw/i386/bios-linker-loader.h
>  create mode 100644 include/hw/acpi/bios-linker-loader.h
> 
> diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> index 4237232..02ca4ed 100644
> --- a/hw/acpi/Makefile.objs
> +++ b/hw/acpi/Makefile.objs
> @@ -1,4 +1,4 @@
>  common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
>  common-obj-$(CONFIG_ACPI) += memory_hotplug.o
>  common-obj-$(CONFIG_ACPI) += acpi_interface.o
> -common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o
> +common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o bios-linker-loader.o
> diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
> index 39cbab7..cc2fa03 100644
> --- a/hw/acpi/acpi_gen_utils.c
> +++ b/hw/acpi/acpi_gen_utils.c
> @@ -5,6 +5,7 @@
>  #include <string.h>
>  #include "hw/acpi/acpi_gen_utils.h"
>  #include "qemu/bswap.h"
> +#include "hw/acpi/bios-linker-loader.h"
>  
>  GArray *build_alloc_array(void)
>  {
> diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c
> new file mode 100644
> index 0000000..5cc4d90
> --- /dev/null
> +++ b/hw/acpi/bios-linker-loader.c
> @@ -0,0 +1,157 @@
> +/* Dynamic linker/loader of ACPI tables
> + *
> + * Copyright (C) 2013 Red Hat Inc
> + *
> + * Author: Michael S. Tsirkin <mst@redhat.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> +
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> +
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include "qemu-common.h"
> +#include "hw/acpi/bios-linker-loader.h"
> +#include "hw/nvram/fw_cfg.h"
> +
> +#include "qemu/bswap.h"
> +
> +#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> +
> +struct BiosLinkerLoaderEntry {
> +    uint32_t command;
> +    union {
> +        /*
> +         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> +         * subject to @alloc.align alignment (must be power of 2)
> +         * and @alloc.zone (can be HIGH or FSEG) requirements.
> +         *
> +         * Must appear exactly once for each file, and before
> +         * this file is referenced by any other command.
> +         */
> +        struct {
> +            char file[BIOS_LINKER_LOADER_FILESZ];
> +            uint32_t align;
> +            uint8_t zone;
> +        } alloc;
> +
> +        /*
> +         * COMMAND_ADD_POINTER - patch the table (originating from
> +         * @dest_file) at @pointer.offset, by adding a pointer to the table
> +         * originating from @src_file. 1,2,4 or 8 byte unsigned
> +         * addition is used depending on @pointer.size.
> +         */
> +        struct {
> +            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> +            char src_file[BIOS_LINKER_LOADER_FILESZ];
> +            uint32_t offset;
> +            uint8_t size;
> +        } pointer;
> +
> +        /*
> +         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> +         * @cksum_start and @cksum_length fields,
> +         * and then add the value at @cksum.offset.
> +         * Checksum simply sums -X for each byte X in the range
> +         * using 8-bit math.
> +         */
> +        struct {
> +            char file[BIOS_LINKER_LOADER_FILESZ];
> +            uint32_t offset;
> +            uint32_t start;
> +            uint32_t length;
> +        } cksum;
> +
> +        /* padding */
> +        char pad[124];
> +    };
> +} QEMU_PACKED;
> +typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> +
> +enum {
> +    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> +    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> +    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> +};
> +
> +enum {
> +    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> +    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> +};
> +
> +GArray *bios_linker_loader_init(void)
> +{
> +    return g_array_new(false, true /* clear */, 1);
> +}
> +
> +/* Free linker wrapper and return the linker array. */
> +void *bios_linker_loader_cleanup(GArray *linker)
> +{
> +    return g_array_free(linker, false);
> +}
> +
> +void bios_linker_loader_alloc(GArray *linker,
> +                              const char *file,
> +                              uint32_t alloc_align,
> +                              bool alloc_fseg)
> +{
> +    BiosLinkerLoaderEntry entry;
> +
> +    memset(&entry, 0, sizeof entry);
> +    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> +    entry.alloc.align = cpu_to_le32(alloc_align);
> +    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> +
> +    /* Alloc entries must come first, so prepend them */
> +    g_array_prepend_vals(linker, &entry, sizeof entry);
> +}
> +
> +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> +                                     void *table,
> +                                     void *start, unsigned size,
> +                                     uint8_t *checksum)
> +{
> +    BiosLinkerLoaderEntry entry;
> +
> +    memset(&entry, 0, sizeof entry);
> +    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> +    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> +    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> +    entry.cksum.length = cpu_to_le32(size);
> +
> +    g_array_append_vals(linker, &entry, sizeof entry);
> +}
> +
> +void bios_linker_loader_add_pointer(GArray *linker,
> +                                    const char *dest_file,
> +                                    const char *src_file,
> +                                    GArray *table, void *pointer,
> +                                    uint8_t pointer_size)
> +{
> +    BiosLinkerLoaderEntry entry;
> +
> +    memset(&entry, 0, sizeof entry);
> +    strncpy(entry.pointer.dest_file, dest_file,
> +            sizeof entry.pointer.dest_file - 1);
> +    strncpy(entry.pointer.src_file, src_file,
> +            sizeof entry.pointer.src_file - 1);
> +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> +    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> +    entry.pointer.size = pointer_size;
> +    assert(pointer_size == 1 || pointer_size == 2 ||
> +           pointer_size == 4 || pointer_size == 8);
> +
> +    g_array_append_vals(linker, &entry, sizeof entry);
> +}
> diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> index 790a56c..6c8705d 100644
> --- a/hw/i386/Makefile.objs
> +++ b/hw/i386/Makefile.objs
> @@ -7,7 +7,6 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
>  
>  obj-y += kvmvapic.o
>  obj-y += acpi-build.o
> -obj-y += bios-linker-loader.o
>  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
>  	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
>  	hw/i386/ssdt-tpm.hex
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index b425156..e0fa30a 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -36,7 +36,7 @@
>  #include "hw/i386/acpi-defs.h"
>  #include "hw/acpi/acpi.h"
>  #include "hw/nvram/fw_cfg.h"
> -#include "bios-linker-loader.h"
> +#include "hw/acpi/bios-linker-loader.h"
>  #include "hw/loader.h"
>  #include "hw/isa/isa.h"
>  #include "hw/acpi/memory_hotplug.h"
> diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
> deleted file mode 100644
> index aa56184..0000000
> --- a/hw/i386/bios-linker-loader.c
> +++ /dev/null
> @@ -1,157 +0,0 @@
> -/* Dynamic linker/loader of ACPI tables
> - *
> - * Copyright (C) 2013 Red Hat Inc
> - *
> - * Author: Michael S. Tsirkin <mst@redhat.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> -
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> -
> - * You should have received a copy of the GNU General Public License along
> - * with this program; if not, see <http://www.gnu.org/licenses/>.
> - */
> -
> -#include "qemu-common.h"
> -#include "bios-linker-loader.h"
> -#include "hw/nvram/fw_cfg.h"
> -
> -#include "qemu/bswap.h"
> -
> -#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> -
> -struct BiosLinkerLoaderEntry {
> -    uint32_t command;
> -    union {
> -        /*
> -         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> -         * subject to @alloc.align alignment (must be power of 2)
> -         * and @alloc.zone (can be HIGH or FSEG) requirements.
> -         *
> -         * Must appear exactly once for each file, and before
> -         * this file is referenced by any other command.
> -         */
> -        struct {
> -            char file[BIOS_LINKER_LOADER_FILESZ];
> -            uint32_t align;
> -            uint8_t zone;
> -        } alloc;
> -
> -        /*
> -         * COMMAND_ADD_POINTER - patch the table (originating from
> -         * @dest_file) at @pointer.offset, by adding a pointer to the table
> -         * originating from @src_file. 1,2,4 or 8 byte unsigned
> -         * addition is used depending on @pointer.size.
> -         */
> -        struct {
> -            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> -            char src_file[BIOS_LINKER_LOADER_FILESZ];
> -            uint32_t offset;
> -            uint8_t size;
> -        } pointer;
> -
> -        /*
> -         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> -         * @cksum_start and @cksum_length fields,
> -         * and then add the value at @cksum.offset.
> -         * Checksum simply sums -X for each byte X in the range
> -         * using 8-bit math.
> -         */
> -        struct {
> -            char file[BIOS_LINKER_LOADER_FILESZ];
> -            uint32_t offset;
> -            uint32_t start;
> -            uint32_t length;
> -        } cksum;
> -
> -        /* padding */
> -        char pad[124];
> -    };
> -} QEMU_PACKED;
> -typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> -
> -enum {
> -    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> -    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> -    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> -};
> -
> -enum {
> -    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> -    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> -};
> -
> -GArray *bios_linker_loader_init(void)
> -{
> -    return g_array_new(false, true /* clear */, 1);
> -}
> -
> -/* Free linker wrapper and return the linker array. */
> -void *bios_linker_loader_cleanup(GArray *linker)
> -{
> -    return g_array_free(linker, false);
> -}
> -
> -void bios_linker_loader_alloc(GArray *linker,
> -                              const char *file,
> -                              uint32_t alloc_align,
> -                              bool alloc_fseg)
> -{
> -    BiosLinkerLoaderEntry entry;
> -
> -    memset(&entry, 0, sizeof entry);
> -    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> -    entry.alloc.align = cpu_to_le32(alloc_align);
> -    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> -
> -    /* Alloc entries must come first, so prepend them */
> -    g_array_prepend_vals(linker, &entry, sizeof entry);
> -}
> -
> -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> -                                     void *table,
> -                                     void *start, unsigned size,
> -                                     uint8_t *checksum)
> -{
> -    BiosLinkerLoaderEntry entry;
> -
> -    memset(&entry, 0, sizeof entry);
> -    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> -    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> -    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> -    entry.cksum.length = cpu_to_le32(size);
> -
> -    g_array_append_vals(linker, &entry, sizeof entry);
> -}
> -
> -void bios_linker_loader_add_pointer(GArray *linker,
> -                                    const char *dest_file,
> -                                    const char *src_file,
> -                                    GArray *table, void *pointer,
> -                                    uint8_t pointer_size)
> -{
> -    BiosLinkerLoaderEntry entry;
> -
> -    memset(&entry, 0, sizeof entry);
> -    strncpy(entry.pointer.dest_file, dest_file,
> -            sizeof entry.pointer.dest_file - 1);
> -    strncpy(entry.pointer.src_file, src_file,
> -            sizeof entry.pointer.src_file - 1);
> -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> -    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> -    entry.pointer.size = pointer_size;
> -    assert(pointer_size == 1 || pointer_size == 2 ||
> -           pointer_size == 4 || pointer_size == 8);
> -
> -    g_array_append_vals(linker, &entry, sizeof entry);
> -}
> diff --git a/hw/i386/bios-linker-loader.h b/hw/i386/bios-linker-loader.h
> deleted file mode 100644
> index 498c0af..0000000
> --- a/hw/i386/bios-linker-loader.h
> +++ /dev/null
> @@ -1,27 +0,0 @@
> -#ifndef BIOS_LINKER_LOADER_H
> -#define BIOS_LINKER_LOADER_H
> -
> -#include <glib.h>
> -#include <stdbool.h>
> -#include <inttypes.h>
> -
> -GArray *bios_linker_loader_init(void);
> -
> -void bios_linker_loader_alloc(GArray *linker,
> -                              const char *file,
> -                              uint32_t alloc_align,
> -                              bool alloc_fseg);
> -
> -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> -                                     void *table,
> -                                     void *start, unsigned size,
> -                                     uint8_t *checksum);
> -
> -void bios_linker_loader_add_pointer(GArray *linker,
> -                                    const char *dest_file,
> -                                    const char *src_file,
> -                                    GArray *table, void *pointer,
> -                                    uint8_t pointer_size);
> -
> -void *bios_linker_loader_cleanup(GArray *linker);
> -#endif
> diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-linker-loader.h
> new file mode 100644
> index 0000000..498c0af
> --- /dev/null
> +++ b/include/hw/acpi/bios-linker-loader.h
> @@ -0,0 +1,27 @@
> +#ifndef BIOS_LINKER_LOADER_H
> +#define BIOS_LINKER_LOADER_H
> +
> +#include <glib.h>
> +#include <stdbool.h>
> +#include <inttypes.h>
> +
> +GArray *bios_linker_loader_init(void);
> +
> +void bios_linker_loader_alloc(GArray *linker,
> +                              const char *file,
> +                              uint32_t alloc_align,
> +                              bool alloc_fseg);
> +
> +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> +                                     void *table,
> +                                     void *start, unsigned size,
> +                                     uint8_t *checksum);
> +
> +void bios_linker_loader_add_pointer(GArray *linker,
> +                                    const char *dest_file,
> +                                    const char *src_file,
> +                                    GArray *table, void *pointer,
> +                                    uint8_t pointer_size);
> +
> +void *bios_linker_loader_cleanup(GArray *linker);
> +#endif
> -- 
> 1.8.3.1

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

* Re: [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically
  2015-01-19 21:55     ` Michael S. Tsirkin
@ 2015-01-20  9:37       ` Marcel Apfelbaum
  2015-01-20  9:42       ` Igor Mammedov
  1 sibling, 0 replies; 58+ messages in thread
From: Marcel Apfelbaum @ 2015-01-20  9:37 UTC (permalink / raw)
  To: Michael S. Tsirkin, Paolo Bonzini
  Cc: Igor Mammedov, drjones, claudio.fontana, qemu-devel, Marcel Apfelbaum

On 01/19/2015 11:55 PM, Michael S. Tsirkin wrote:
> On Mon, Jan 19, 2015 at 01:42:25PM +0100, Paolo Bonzini wrote:
>>
>>
>> On 19/12/2014 03:02, 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 is a good idea.  It's simpler to just do this in the SSDT than to
>> split it between DSDT and SSDT.  The AML's purpose is just to build a
>> static value anyway.
>>
>> Paolo
>
> I think Marcel has patches going in exactly the reverse
> direction with this.
> Marcel?

Actually I added the CRS for the extra root buses in SSDT.
The reason is that it depends on user input.

By the way, I have the code for creating the CRS in code rather that in
the file based on Igor's series.

Thanks,
Marcel

>

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

* Re: [Qemu-devel] [RFC 14/47] acpi: add acpi_notify() term
  2015-01-19 12:32   ` Paolo Bonzini
@ 2015-01-20  9:40     ` Igor Mammedov
  0 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2015-01-20  9:40 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: drjones, claudio.fontana, qemu-devel, mst

On Mon, 19 Jan 2015 13:32:48 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> 
> 
> On 19/12/2014 03:02, Igor Mammedov wrote:
> > +    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
> > +    build_append_byte(var.buf, 0x86); /* NotifyOp */ \
> 
> Extra backslash.
Thanks, I'll fix it.

> 
> Paolo
> 
> > +    aml_append(&var, arg1);

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

* Re: [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically
  2015-01-19 21:55     ` Michael S. Tsirkin
  2015-01-20  9:37       ` Marcel Apfelbaum
@ 2015-01-20  9:42       ` Igor Mammedov
  1 sibling, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2015-01-20  9:42 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Paolo Bonzini, drjones, claudio.fontana, qemu-devel, Marcel Apfelbaum

On Mon, 19 Jan 2015 23:55:37 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Jan 19, 2015 at 01:42:25PM +0100, Paolo Bonzini wrote:
> > 
> > 
> > On 19/12/2014 03:02, 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 is a good idea.  It's simpler to just do this in the SSDT than to
> > split it between DSDT and SSDT.  The AML's purpose is just to build a
> > static value anyway.
> > 
> > Paolo
> 
> I think Marcel has patches going in exactly the reverse
> direction with this.
From my talk with him, he was doing/needs a similar thing.
So this was simplifying his job.

> Marcel?

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

* Re: [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets
  2015-01-19 22:05   ` Michael S. Tsirkin
@ 2015-01-20  9:43     ` Igor Mammedov
  0 siblings, 0 replies; 58+ messages in thread
From: Igor Mammedov @ 2015-01-20  9:43 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: pbonzini, drjones, claudio.fontana, qemu-devel

On Tue, 20 Jan 2015 00:05:15 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Fri, Dec 19, 2014 at 02:02:37AM +0000, Igor Mammedov wrote:
> > keeping bios-linker-loader.c i386 specific would break build
> > of mips target which is built with CONFIG_ACPI which would
> > dependend on it in following patch that adds acpi_def_block()
> > term. Also UEFI for ARM target is going to use linker as well
> > so it makes sense to move it into generic target independent
> > ACPI part.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> I reworked this one to avoid the huge diffs.
> Pls check the pci branch.
Thanks.

> 
> > ---
> >  hw/acpi/Makefile.objs                |   2 +-
> >  hw/acpi/acpi_gen_utils.c             |   1 +
> >  hw/acpi/bios-linker-loader.c         | 157 +++++++++++++++++++++++++++++++++++
> >  hw/i386/Makefile.objs                |   1 -
> >  hw/i386/acpi-build.c                 |   2 +-
> >  hw/i386/bios-linker-loader.c         | 157 -----------------------------------
> >  hw/i386/bios-linker-loader.h         |  27 ------
> >  include/hw/acpi/bios-linker-loader.h |  27 ++++++
> >  8 files changed, 187 insertions(+), 187 deletions(-)
> >  create mode 100644 hw/acpi/bios-linker-loader.c
> >  delete mode 100644 hw/i386/bios-linker-loader.c
> >  delete mode 100644 hw/i386/bios-linker-loader.h
> >  create mode 100644 include/hw/acpi/bios-linker-loader.h
> > 
> > diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> > index 4237232..02ca4ed 100644
> > --- a/hw/acpi/Makefile.objs
> > +++ b/hw/acpi/Makefile.objs
> > @@ -1,4 +1,4 @@
> >  common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
> >  common-obj-$(CONFIG_ACPI) += memory_hotplug.o
> >  common-obj-$(CONFIG_ACPI) += acpi_interface.o
> > -common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o
> > +common-obj-$(CONFIG_ACPI) += acpi_gen_utils.o bios-linker-loader.o
> > diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
> > index 39cbab7..cc2fa03 100644
> > --- a/hw/acpi/acpi_gen_utils.c
> > +++ b/hw/acpi/acpi_gen_utils.c
> > @@ -5,6 +5,7 @@
> >  #include <string.h>
> >  #include "hw/acpi/acpi_gen_utils.h"
> >  #include "qemu/bswap.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> >  
> >  GArray *build_alloc_array(void)
> >  {
> > diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c
> > new file mode 100644
> > index 0000000..5cc4d90
> > --- /dev/null
> > +++ b/hw/acpi/bios-linker-loader.c
> > @@ -0,0 +1,157 @@
> > +/* Dynamic linker/loader of ACPI tables
> > + *
> > + * Copyright (C) 2013 Red Hat Inc
> > + *
> > + * Author: Michael S. Tsirkin <mst@redhat.com>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > +
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > +
> > + * You should have received a copy of the GNU General Public License along
> > + * with this program; if not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include "qemu-common.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> > +#include "hw/nvram/fw_cfg.h"
> > +
> > +#include "qemu/bswap.h"
> > +
> > +#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> > +
> > +struct BiosLinkerLoaderEntry {
> > +    uint32_t command;
> > +    union {
> > +        /*
> > +         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> > +         * subject to @alloc.align alignment (must be power of 2)
> > +         * and @alloc.zone (can be HIGH or FSEG) requirements.
> > +         *
> > +         * Must appear exactly once for each file, and before
> > +         * this file is referenced by any other command.
> > +         */
> > +        struct {
> > +            char file[BIOS_LINKER_LOADER_FILESZ];
> > +            uint32_t align;
> > +            uint8_t zone;
> > +        } alloc;
> > +
> > +        /*
> > +         * COMMAND_ADD_POINTER - patch the table (originating from
> > +         * @dest_file) at @pointer.offset, by adding a pointer to the table
> > +         * originating from @src_file. 1,2,4 or 8 byte unsigned
> > +         * addition is used depending on @pointer.size.
> > +         */
> > +        struct {
> > +            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> > +            char src_file[BIOS_LINKER_LOADER_FILESZ];
> > +            uint32_t offset;
> > +            uint8_t size;
> > +        } pointer;
> > +
> > +        /*
> > +         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> > +         * @cksum_start and @cksum_length fields,
> > +         * and then add the value at @cksum.offset.
> > +         * Checksum simply sums -X for each byte X in the range
> > +         * using 8-bit math.
> > +         */
> > +        struct {
> > +            char file[BIOS_LINKER_LOADER_FILESZ];
> > +            uint32_t offset;
> > +            uint32_t start;
> > +            uint32_t length;
> > +        } cksum;
> > +
> > +        /* padding */
> > +        char pad[124];
> > +    };
> > +} QEMU_PACKED;
> > +typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> > +
> > +enum {
> > +    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> > +    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> > +    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> > +};
> > +
> > +enum {
> > +    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> > +    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> > +};
> > +
> > +GArray *bios_linker_loader_init(void)
> > +{
> > +    return g_array_new(false, true /* clear */, 1);
> > +}
> > +
> > +/* Free linker wrapper and return the linker array. */
> > +void *bios_linker_loader_cleanup(GArray *linker)
> > +{
> > +    return g_array_free(linker, false);
> > +}
> > +
> > +void bios_linker_loader_alloc(GArray *linker,
> > +                              const char *file,
> > +                              uint32_t alloc_align,
> > +                              bool alloc_fseg)
> > +{
> > +    BiosLinkerLoaderEntry entry;
> > +
> > +    memset(&entry, 0, sizeof entry);
> > +    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> > +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> > +    entry.alloc.align = cpu_to_le32(alloc_align);
> > +    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> > +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> > +                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> > +
> > +    /* Alloc entries must come first, so prepend them */
> > +    g_array_prepend_vals(linker, &entry, sizeof entry);
> > +}
> > +
> > +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > +                                     void *table,
> > +                                     void *start, unsigned size,
> > +                                     uint8_t *checksum)
> > +{
> > +    BiosLinkerLoaderEntry entry;
> > +
> > +    memset(&entry, 0, sizeof entry);
> > +    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> > +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> > +    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> > +    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> > +    entry.cksum.length = cpu_to_le32(size);
> > +
> > +    g_array_append_vals(linker, &entry, sizeof entry);
> > +}
> > +
> > +void bios_linker_loader_add_pointer(GArray *linker,
> > +                                    const char *dest_file,
> > +                                    const char *src_file,
> > +                                    GArray *table, void *pointer,
> > +                                    uint8_t pointer_size)
> > +{
> > +    BiosLinkerLoaderEntry entry;
> > +
> > +    memset(&entry, 0, sizeof entry);
> > +    strncpy(entry.pointer.dest_file, dest_file,
> > +            sizeof entry.pointer.dest_file - 1);
> > +    strncpy(entry.pointer.src_file, src_file,
> > +            sizeof entry.pointer.src_file - 1);
> > +    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> > +    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> > +    entry.pointer.size = pointer_size;
> > +    assert(pointer_size == 1 || pointer_size == 2 ||
> > +           pointer_size == 4 || pointer_size == 8);
> > +
> > +    g_array_append_vals(linker, &entry, sizeof entry);
> > +}
> > diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> > index 790a56c..6c8705d 100644
> > --- a/hw/i386/Makefile.objs
> > +++ b/hw/i386/Makefile.objs
> > @@ -7,7 +7,6 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
> >  
> >  obj-y += kvmvapic.o
> >  obj-y += acpi-build.o
> > -obj-y += bios-linker-loader.o
> >  hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
> >  	hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
> >  	hw/i386/ssdt-tpm.hex
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index b425156..e0fa30a 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -36,7 +36,7 @@
> >  #include "hw/i386/acpi-defs.h"
> >  #include "hw/acpi/acpi.h"
> >  #include "hw/nvram/fw_cfg.h"
> > -#include "bios-linker-loader.h"
> > +#include "hw/acpi/bios-linker-loader.h"
> >  #include "hw/loader.h"
> >  #include "hw/isa/isa.h"
> >  #include "hw/acpi/memory_hotplug.h"
> > diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
> > deleted file mode 100644
> > index aa56184..0000000
> > --- a/hw/i386/bios-linker-loader.c
> > +++ /dev/null
> > @@ -1,157 +0,0 @@
> > -/* Dynamic linker/loader of ACPI tables
> > - *
> > - * Copyright (C) 2013 Red Hat Inc
> > - *
> > - * Author: Michael S. Tsirkin <mst@redhat.com>
> > - *
> > - * This program is free software; you can redistribute it and/or modify
> > - * it under the terms of the GNU General Public License as published by
> > - * the Free Software Foundation; either version 2 of the License, or
> > - * (at your option) any later version.
> > -
> > - * This program is distributed in the hope that it will be useful,
> > - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > - * GNU General Public License for more details.
> > -
> > - * You should have received a copy of the GNU General Public License along
> > - * with this program; if not, see <http://www.gnu.org/licenses/>.
> > - */
> > -
> > -#include "qemu-common.h"
> > -#include "bios-linker-loader.h"
> > -#include "hw/nvram/fw_cfg.h"
> > -
> > -#include "qemu/bswap.h"
> > -
> > -#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
> > -
> > -struct BiosLinkerLoaderEntry {
> > -    uint32_t command;
> > -    union {
> > -        /*
> > -         * COMMAND_ALLOCATE - allocate a table from @alloc.file
> > -         * subject to @alloc.align alignment (must be power of 2)
> > -         * and @alloc.zone (can be HIGH or FSEG) requirements.
> > -         *
> > -         * Must appear exactly once for each file, and before
> > -         * this file is referenced by any other command.
> > -         */
> > -        struct {
> > -            char file[BIOS_LINKER_LOADER_FILESZ];
> > -            uint32_t align;
> > -            uint8_t zone;
> > -        } alloc;
> > -
> > -        /*
> > -         * COMMAND_ADD_POINTER - patch the table (originating from
> > -         * @dest_file) at @pointer.offset, by adding a pointer to the table
> > -         * originating from @src_file. 1,2,4 or 8 byte unsigned
> > -         * addition is used depending on @pointer.size.
> > -         */
> > -        struct {
> > -            char dest_file[BIOS_LINKER_LOADER_FILESZ];
> > -            char src_file[BIOS_LINKER_LOADER_FILESZ];
> > -            uint32_t offset;
> > -            uint8_t size;
> > -        } pointer;
> > -
> > -        /*
> > -         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
> > -         * @cksum_start and @cksum_length fields,
> > -         * and then add the value at @cksum.offset.
> > -         * Checksum simply sums -X for each byte X in the range
> > -         * using 8-bit math.
> > -         */
> > -        struct {
> > -            char file[BIOS_LINKER_LOADER_FILESZ];
> > -            uint32_t offset;
> > -            uint32_t start;
> > -            uint32_t length;
> > -        } cksum;
> > -
> > -        /* padding */
> > -        char pad[124];
> > -    };
> > -} QEMU_PACKED;
> > -typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
> > -
> > -enum {
> > -    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
> > -    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
> > -    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
> > -};
> > -
> > -enum {
> > -    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
> > -    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
> > -};
> > -
> > -GArray *bios_linker_loader_init(void)
> > -{
> > -    return g_array_new(false, true /* clear */, 1);
> > -}
> > -
> > -/* Free linker wrapper and return the linker array. */
> > -void *bios_linker_loader_cleanup(GArray *linker)
> > -{
> > -    return g_array_free(linker, false);
> > -}
> > -
> > -void bios_linker_loader_alloc(GArray *linker,
> > -                              const char *file,
> > -                              uint32_t alloc_align,
> > -                              bool alloc_fseg)
> > -{
> > -    BiosLinkerLoaderEntry entry;
> > -
> > -    memset(&entry, 0, sizeof entry);
> > -    strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
> > -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
> > -    entry.alloc.align = cpu_to_le32(alloc_align);
> > -    entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> > -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> > -                                    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> > -
> > -    /* Alloc entries must come first, so prepend them */
> > -    g_array_prepend_vals(linker, &entry, sizeof entry);
> > -}
> > -
> > -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > -                                     void *table,
> > -                                     void *start, unsigned size,
> > -                                     uint8_t *checksum)
> > -{
> > -    BiosLinkerLoaderEntry entry;
> > -
> > -    memset(&entry, 0, sizeof entry);
> > -    strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
> > -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
> > -    entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
> > -    entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> > -    entry.cksum.length = cpu_to_le32(size);
> > -
> > -    g_array_append_vals(linker, &entry, sizeof entry);
> > -}
> > -
> > -void bios_linker_loader_add_pointer(GArray *linker,
> > -                                    const char *dest_file,
> > -                                    const char *src_file,
> > -                                    GArray *table, void *pointer,
> > -                                    uint8_t pointer_size)
> > -{
> > -    BiosLinkerLoaderEntry entry;
> > -
> > -    memset(&entry, 0, sizeof entry);
> > -    strncpy(entry.pointer.dest_file, dest_file,
> > -            sizeof entry.pointer.dest_file - 1);
> > -    strncpy(entry.pointer.src_file, src_file,
> > -            sizeof entry.pointer.src_file - 1);
> > -    entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
> > -    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
> > -    entry.pointer.size = pointer_size;
> > -    assert(pointer_size == 1 || pointer_size == 2 ||
> > -           pointer_size == 4 || pointer_size == 8);
> > -
> > -    g_array_append_vals(linker, &entry, sizeof entry);
> > -}
> > diff --git a/hw/i386/bios-linker-loader.h b/hw/i386/bios-linker-loader.h
> > deleted file mode 100644
> > index 498c0af..0000000
> > --- a/hw/i386/bios-linker-loader.h
> > +++ /dev/null
> > @@ -1,27 +0,0 @@
> > -#ifndef BIOS_LINKER_LOADER_H
> > -#define BIOS_LINKER_LOADER_H
> > -
> > -#include <glib.h>
> > -#include <stdbool.h>
> > -#include <inttypes.h>
> > -
> > -GArray *bios_linker_loader_init(void);
> > -
> > -void bios_linker_loader_alloc(GArray *linker,
> > -                              const char *file,
> > -                              uint32_t alloc_align,
> > -                              bool alloc_fseg);
> > -
> > -void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > -                                     void *table,
> > -                                     void *start, unsigned size,
> > -                                     uint8_t *checksum);
> > -
> > -void bios_linker_loader_add_pointer(GArray *linker,
> > -                                    const char *dest_file,
> > -                                    const char *src_file,
> > -                                    GArray *table, void *pointer,
> > -                                    uint8_t pointer_size);
> > -
> > -void *bios_linker_loader_cleanup(GArray *linker);
> > -#endif
> > diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-linker-loader.h
> > new file mode 100644
> > index 0000000..498c0af
> > --- /dev/null
> > +++ b/include/hw/acpi/bios-linker-loader.h
> > @@ -0,0 +1,27 @@
> > +#ifndef BIOS_LINKER_LOADER_H
> > +#define BIOS_LINKER_LOADER_H
> > +
> > +#include <glib.h>
> > +#include <stdbool.h>
> > +#include <inttypes.h>
> > +
> > +GArray *bios_linker_loader_init(void);
> > +
> > +void bios_linker_loader_alloc(GArray *linker,
> > +                              const char *file,
> > +                              uint32_t alloc_align,
> > +                              bool alloc_fseg);
> > +
> > +void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> > +                                     void *table,
> > +                                     void *start, unsigned size,
> > +                                     uint8_t *checksum);
> > +
> > +void bios_linker_loader_add_pointer(GArray *linker,
> > +                                    const char *dest_file,
> > +                                    const char *src_file,
> > +                                    GArray *table, void *pointer,
> > +                                    uint8_t pointer_size);
> > +
> > +void *bios_linker_loader_cleanup(GArray *linker);
> > +#endif
> > -- 
> > 1.8.3.1

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

end of thread, other threads:[~2015-01-20  9:43 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19  2:01 [Qemu-devel] [RFC 00/47] ACPI refactoring: replace template patching with C ASL API Igor Mammedov
2014-12-19  2:01 ` [Qemu-devel] [RFC 01/47] acpi: introduce AML composer aml_append() Igor Mammedov
2014-12-19  2:01 ` [Qemu-devel] [RFC 02/47] acpi: add acpi_scope() term Igor Mammedov
2014-12-19  2:01 ` [Qemu-devel] [RFC 03/47] acpi: add acpi_device() term Igor Mammedov
2014-12-19  2:01 ` [Qemu-devel] [RFC 04/47] acpi: add acpi_method() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 05/47] acpi: add acpi_if() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 06/47] acpi: add acpi_name() & acpi_name_decl() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 07/47] acpi: factor out ACPI const int packing out build_append_value() Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 08/47] acpi: extend build_append_{value|int}() to support 64-bit values Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 09/47] acpi: add acpi_int() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 10/47] acpi: add acpi_return() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 11/47] acpi: add acpi_arg0(), acpi_arg1(), acpi_arg2(), acpi_arg3() terms Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 12/47] acpi: add acpi_store() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 13/47] acpi: add acpi_and() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 14/47] acpi: add acpi_notify() term Igor Mammedov
2015-01-19 12:32   ` Paolo Bonzini
2015-01-20  9:40     ` Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 15/47] acpi: add acpi_call1(), acpi_call2(), acpi_call3(), acpi_call4() helpers Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 16/47] pc: acpi-build: drop template patching and create PCI bus tree dinamically Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 17/47] acpi: add acpi_package() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 18/47] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 19/47] pc: acpi-build: generate _S[345] packages dynamically Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 20/47] acpi: add acpi_buffer() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 21/47] acpi: add acpi_resource_template() helper Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 22/47] acpi: add acpi_io() helper Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 23/47] acpi: include PkgLength size only when requested Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 24/47] acpi: add acpi_operation_region() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 25/47] acpi: add acpi_field() & acpi_named_field() terms Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 26/47] acpi: add acpi_local0() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 27/47] acpi: add acpi_string() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 28/47] pc: acpi-build: generate pvpanic device description dynamically Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 29/47] acpi: add acpi_varpackage() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 30/47] acpi: add acpi_equal() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 31/47] acpi: add acpi_processor() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 32/47] acpi: add acpi_eisaid() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 33/47] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 34/47] pc: acpi-build: create CPU hotplug IO region dynamically Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 35/47] acpi: add acpi_reserved_field() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 36/47] pc: acpi-build: drop template patching and memory hotplug objects dynamically Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 37/47] pc: acpi-build: create memory hotplug IO region dynamically Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 38/47] acpi: add acpi_word_bus_number(), acpi_word_io(), acpi_dword_memory(), acpi_qword_memory() terms Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 39/47] pc: pcihp: expose MMIO base and len as properties Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 40/47] pc: acpi-build: reserve PCIHP MMIO resources Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 41/47] pc: acpi-build: create PCI0._CRS dynamically Igor Mammedov
2015-01-19 12:42   ` Paolo Bonzini
2015-01-19 21:55     ` Michael S. Tsirkin
2015-01-20  9:37       ` Marcel Apfelbaum
2015-01-20  9:42       ` Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 42/47] acpi: make tables linker-loader available to other targets Igor Mammedov
2015-01-19 12:36   ` Paolo Bonzini
2015-01-19 21:54     ` Michael S. Tsirkin
2015-01-19 22:05   ` Michael S. Tsirkin
2015-01-20  9:43     ` Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 43/47] acpi: add acpi_def_block() term Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 44/47] pc: acpi-build: prepare to make ACPI tables blob opaque for table building functions Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 45/47] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block() Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 46/47] pc: acpi: update DSTD blobs Igor Mammedov
2014-12-19  2:02 ` [Qemu-devel] [RFC 47/47] tests: acpi: update reference DSDT/SSDT tables 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.