ACPI refactoring: replace template patching with C AML API
v3 cover ACPI refactoring: replace template patching with C AML API
changes since v2:
* rename acpi prefixes in API to aml
* reverse conversion order from bottom->top to top->bottom
* introduce internal Aml garbage collector and 2 API functions to initialize and cleanup it up
* replace acpi_argX() helpers with a single aml_arg(X) helper do the same for acpi_localX() helpers.
* add 3 internal allocators, for allocating dummy Aml struct for helpers aml_alloc(), aml_opcode(OPCODE) for simple Aml elements and aml_bundle(opcode, kind) for complex elements that require post-processing after element has been composed
* amend spec references to ACPI 1.0b and later if AML element was introduced later
* various codestyle fixes
* rebase on top of PCI tree
changes since RFC:
* conflicts with vmgenid (broken) patches, so it's not based on PCI tree
* rebased on top of today's master +
[PATCH v5 0/5] pc: acpi: various fixes and cleanups +
some patches from PCI tree that above series depends on
* small cleanups
* droped [42/47] acpi: make tables linker-loader available to other targets since Michael has a cleaner similar patch(es) in PCI tree,
so reuse them (not included in here)
* move SMC device from DSDT to SSDT and create it only when applesmc device is present.
This series refactors SSDT runtime composing and gets rid of:
* patching AML templates, with related pointer arithmetic magic
* manual AML composition, i.e. creating AML terms practically byte by byte
* using AML templates for SSDT creation, reducing dependency on IASL. as result of above, QEMU source tree doesn't have to carry 'binary' template blobs that used to be part of SSDT.
* hand-crafted PCI0._CRSes for pc/q35 machines in DSDT with manual hole punching of reserved resources
and adds following:
* introduces ASL like API for creating AML objects using ASL like constructs/terms. API:
* provides a necessary minimum set of terms/helpers to replace currently used SSDT templates.
* simplifies AML composition and keeps track of AML object contexts, transparently managing their (de)allocation and merging into parent context, making composition of SSDT 'almost' like writing native ASL definition of the table.
* hides pointer arithmetic from user when composing SSDT.
* dynamically creates unified PCI0._CRS in SSDT for pc/q35 machines allowing to reserve resources at runtime vs current compile time
* while adding new API, make it target independed CONFIG_ACPI and also make some other utilities for composing ACPI tables target independed (i.e. utils on which API depends) so that they could be reused for ARM target later without moving stuff around uncessarily.
* trims SSDT by not creating objects that are not present (S[34] Package if disabled, pvpanic, applesmc)
As result of replacing AML templates with ASL API, codebase reduces on ~1900LOC even with net addition of API 1050LOC counted in.
Tested with XPsp3, WS2012R2, RHEL6/7 guests.
Git tree for playing with:
https://github.com/imammedo/qemu/commits/ASL_API_v3
Igor Mammedov (52):
acpi: introduce AML composer aml_append()
pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
pc: acpi: make top level ACPI tables blob Aml*
acpi: factor out ACPI const int packing out of build_append_value()
acpi: add aml_def_block() term
pc: acpi-build: use aml_def_block() for declaring SSDT table
acpi: add aml_scope() term
pc: acpi-build: use aml_scope() for \_SB scope
acpi: add aml_device() term
acpi: add aml_method() term
acpi: add aml_if() term
acpi: add aml_name() & aml_name_decl() term
acpi: extend build_append_{value|int}() to support 64-bit values
acpi: add aml_int() term
acpi: add aml_return() term
acpi: add aml_arg() term
acpi: add aml_store() term
acpi: add aml_and() term
acpi: add aml_notify() term
acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
pc: acpi-build: drop template patching and create PCI bus tree
dynamically
acpi: add aml_package() term
pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
pc: acpi-build: generate _S[345] packages dynamically
acpi: add aml_buffer() term
acpi: add aml_resource_template() helper
acpi: add aml_io() helper
acpi: include PkgLength size only when requested
acpi: add aml_operation_region() term
acpi: add aml_field() & aml_named_field() terms
acpi: add aml_local() term
acpi: add aml_string() term
pc: acpi-build: generate pvpanic device description dynamically
acpi: add aml_varpackage() term
acpi: add aml_equal() term
acpi: add aml_processor() term
acpi: add aml_eisaid() term
pc: acpi-build: drop template patching and CPU hotplug objects
dynamically
pc: acpi-build: create CPU hotplug IO region dynamically
acpi: add aml_reserved_field() term
pc: acpi-build: drop template patching and memory hotplug objects
dynamically
pc: acpi-build: create memory hotplug IO region dynamically
acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(),
aml_qword_memory() terms
pc: pcihp: expose MMIO base and len as properties
pc: acpi-build: reserve PCIHP MMIO resources
pc: acpi-build: create PCI0._CRS dynamically
pc: acpi-build: drop remaining ssdt_misc template and use
acpi_def_block()
acpi: add acpi_irq_no_flags() term
pc: export applesmc IO port/len
pc: acpi-build: drop template patching and create Device(SMC)
dynamically
pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC
acpi: make build_*() routines static to aml-build.c
hw/acpi/aml-build.c | 744 ++++++++++++++++++++++++++++++-- hw/acpi/pcihp.c | 18 +- hw/acpi/piix4.c | 2 +- hw/i386/Makefile.objs | 4 +- hw/i386/acpi-build.c | 825 +++++++++++++++++++----------------- hw/i386/acpi-dsdt-cpu-hotplug.dsl | 17 +- hw/i386/acpi-dsdt-isa.dsl | 11 - hw/i386/acpi-dsdt-mem-hotplug.dsl | 36 +- hw/i386/acpi-dsdt-pci-crs.dsl | 92 ---- hw/i386/acpi-dsdt.dsl | 46 -- hw/i386/acpi-dsdt.hex.generated | 714 ++----------------------------- hw/i386/q35-acpi-dsdt.dsl | 19 - hw/i386/q35-acpi-dsdt.hex.generated | 662 ++--------------------------- hw/i386/ssdt-mem.dsl | 77 ---- hw/i386/ssdt-mem.hex.generated | 213 ---------- hw/i386/ssdt-misc.dsl | 122 ------ hw/i386/ssdt-misc.hex.generated | 399 ----------------- hw/i386/ssdt-pcihp.dsl | 100 ----- hw/i386/ssdt-pcihp.hex.generated | 251 ----------- hw/i386/ssdt-proc.dsl | 63 --- hw/i386/ssdt-proc.hex.generated | 134 ------ hw/misc/applesmc.c | 5 +- include/hw/acpi/aml-build.h | 210 ++++++++- include/hw/acpi/pc-hotplug.h | 1 + include/hw/acpi/pcihp.h | 7 +- include/hw/isa/isa.h | 11 +- 26 files changed, 1436 insertions(+), 3347 deletions(-) delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl delete mode 100644 hw/i386/ssdt-mem.dsl delete mode 100644 hw/i386/ssdt-mem.hex.generated delete mode 100644 hw/i386/ssdt-misc.dsl delete mode 100644 hw/i386/ssdt-misc.hex.generated delete mode 100644 hw/i386/ssdt-pcihp.dsl delete mode 100644 hw/i386/ssdt-pcihp.hex.generated delete mode 100644 hw/i386/ssdt-proc.dsl delete mode 100644 hw/i386/ssdt-proc.hex.generated
Signature · 1 line
1.8.3.1
PATCH v3 1/52 acpi: introduce AML composer aml_append()
Adds for dynamic AML creation, which will be used for piecing ASL/AML primitives together and hiding from user/caller details about how nested context should be closed/packed leaving less space for mistakes and necessity to know how AML should be encoded, allowing user to concentrate on ASL representation instead.
For example it will allow to create AML like this:
init_aml_allocator();
...
Aml *scope = aml_scope("PCI0")
Aml *dev = aml_device("PM")
aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))aml_append(scope, dev);
...free_aml_allocator();
--- hw/acpi/aml-build.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 1 - include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-)
hw/acpi/aml-build.c +91 -0
@@ -25,6 +25,8 @@#include <stdbool.h> #include <string.h> #include "hw/acpi/aml-build.h" +#include "qemu/bswap.h" +#include "hw/acpi/bios-linker-loader.h" GArray *build_alloc_array (void ) {
@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)build_append_value (table, value,4 ); } } + +static GPtrArray *alloc_list; + +static Aml *aml_alloc (void ) +{ +Aml *var =g_new0 (typeof (*var),1 ); + +g_ptr_array_add (alloc_list, var); + var->block_flags =AML_HELPER ; + var->buf =build_alloc_array (); +return var; +} + +static void aml_free (gpointer data) +{ +Aml *var = data; +build_free_array (var->buf); +} + +Aml *init_aml_allocator (GArray *linker) +{ +Aml *var; + +assert (!alloc_list); + alloc_list =g_ptr_array_new_with_free_func (aml_free); + var =aml_alloc (); + var->linker = linker; +return var; +} + +void free_aml_allocator (void ) +{ +g_ptr_array_free (alloc_list, true); + alloc_list =0 ; +} + +static void build_buffer (GArray *array,uint8_t op) +{ +GArray *data =build_alloc_array (); + +build_append_int (data, array->len); +g_array_prepend_vals (array, data->data, data->len); +build_free_array (data); +build_package (array, op); +} + +void aml_append (Aml *parent_ctx,Aml *child) +{ +switch (child->block_flags) { +case AML_NON_BLOCK : +build_append_byte (parent_ctx->buf, child->op); +break ; +case AML_EXT_PACKAGE : +build_extop_package (child->buf, child->op); +break ; +case AML_PACKAGE : +build_package (child->buf, child->op); +break ; +case AML_RES_TEMPLATE : +build_append_byte (child->buf,0x79 );/* EndTag */ +/* +* checksum operations is treated as succeeded if checksum +* field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag] +*/ +build_append_byte (child->buf,0 ); +/* fall through, to pack resources in buffer */ +case AML_BUFFER : +build_buffer (child->buf, child->op); +break ; +case AML_DEF_BLOCK : { +uint8_t *start = (uint8_t *)parent_ctx->buf->data + + parent_ctx->buf->len; +uint32_t le32_len =cpu_to_le32 (child->buf->len); + +/* create linker entry for the DefinitionBlock */ +bios_linker_loader_add_checksum (parent_ctx->linker, +ACPI_BUILD_TABLE_FILE , + parent_ctx->buf->data, + start, child->buf->len, start +9 /* checksum offset */ ); + +/* set DefinitionBlock length at TableLength offset*/ +memcpy (child->buf->data +4 , &le32_len,sizeof le32_len); +break ; + } +default : +break ; + } +build_append_array (parent_ctx->buf, child->buf); +}
hw/i386/acpi-build.c +0 -1
@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)#define ACPI_BUILD_APPNAME6 "BOCHS "#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
include/hw/acpi/aml-build.h +61 -0
67 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
Quoted 103 lines · Igor Mammedov
Adds for dynamic AML creation, which will be used for piecing ASL/AML primitives together and hiding from user/caller details about how nested context should be closed/packed leaving less space for mistakes and necessity to know how AML should be encoded, allowing user to concentrate on ASL representation instead.
For example it will allow to create AML like this:
init_aml_allocator();
...
Aml *scope =aml_scope("PCI0")
Aml *dev =aml_device("PM")aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
aml_append(scope, dev);
...free_aml_allocator();Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 1 - include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-)hw/acpi/aml-build.c +62
-0@@ -25,6 +25,8 @@#include <stdbool.h> #include <string.h> #include "hw/acpi/aml-build.h" +#include "qemu/bswap.h" +#include "hw/acpi/bios-linker-loader.h" GArray *build_alloc_array (void ) {@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)build_append_value (table, value,4 ); } } + +static GPtrArray *alloc_list; + +static Aml *aml_alloc (void ) +{ +Aml *var =g_new0 (typeof (*var),1 ); + +g_ptr_array_add (alloc_list, var); + var->block_flags =AML_HELPER ; + var->buf =build_alloc_array (); +return var; +} + +static void aml_free (gpointer data) +{ +Aml *var = data; +build_free_array (var->buf); +} + +Aml *init_aml_allocator (GArray *linker) +{ +Aml *var; + +assert (!alloc_list); + alloc_list =g_ptr_array_new_with_free_func (aml_free); + var =aml_alloc (); + var->linker = linker; +return var; +} + +void free_aml_allocator (void ) +{ +g_ptr_array_free (alloc_list, true); + alloc_list =0 ; +} + +static void build_buffer (GArray *array,uint8_t op) +{ +GArray *data =build_alloc_array (); + +build_append_int (data, array->len); +g_array_prepend_vals (array, data->data, data->len); +build_free_array (data); +build_package (array, op); +} + +void aml_append (Aml *parent_ctx,Aml *child) +{ +switch (child->block_flags) { +case AML_NON_BLOCK : +build_append_byte (parent_ctx->buf, child->op); +break ; +case AML_EXT_PACKAGE : +build_extop_package (child->buf, child->op); +break ; +case AML_PACKAGE : +build_package (child->buf, child->op); +break ; +case AML_RES_TEMPLATE : +build_append_byte (child->buf,0x79 );/* EndTag */
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 331
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+/* +* checksum operations is treated as succeeded if checksum +* field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag] +*/ +build_append_byte (child->buf,0 ); +/* fall through, to pack resources in buffer */ +case AML_BUFFER : +build_buffer (child->buf, child->op); +break ; +case AML_DEF_BLOCK : {
This one is inelegant.
It's not a definition block, and the patching and manual offset calculation are scary.
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 338
Quoted 7 lines
hw/acpi/aml-build.c +7
-0+uint8_t *start = (uint8_t *)parent_ctx->buf->data + + parent_ctx->buf->len; +uint32_t le32_len =cpu_to_le32 (child->buf->len); + +/* create linker entry for the DefinitionBlock */ + bios_linker_loader_add_checksum(parent_ctx->linker, + ACPI_BUILD_TABLE_FILE,
Hard-coding file name here is very ugly. All this does not belong in this file, this is fw cfg interface.
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 343
Quoted 5 lines
hw/acpi/aml-build.c +5
-0+ parent_ctx->buf->data, + start, child->buf->len, start + 9 /* checksum offset */); + +/* set DefinitionBlock length at TableLength offset*/ +memcpy (child->buf->data +4 , &le32_len,sizeof le32_len);
This make no sense.
In AML, there are no objects which are higher level than the table.
So for now, please just leave this alone:
drop linker completely, keep table_data
a simple GArray, not AML, and reuse build_header to fill in headers.
This way this file just deals with AML and ACPI spec.
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 346
Quoted 3 lines
hw/acpi/aml-build.c +3
-0+break ; + } +default :
This should assert.
Quoted 90 lines
hw/acpi/aml-build.c +4
-0+break ; + } +build_append_array (parent_ctx->buf, child->buf); +}hw/i386/acpi-build.c +0
-1@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)#define ACPI_BUILD_APPNAME6 "BOCHS "#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +61
-0@@ -5,6 +5,67 @@#include <glib.h> #include "qemu/compiler.h" +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" + +typedef enum { +AML_HELPER =0 , +AML_NON_BLOCK , +AML_PACKAGE , +AML_EXT_PACKAGE , +AML_BUFFER , +AML_RES_TEMPLATE , +AML_DEF_BLOCK , +}AmlBlockFlags ; + +struct Aml { +GArray *buf; + +/*< private >*/ +uint8_t op; +AmlBlockFlags block_flags; +GArray *linker; +}; +typedef struct Aml Aml ; + +/** +* init_aml_allocator: +* @linker: linker that used by API for registering ACPI tables +* with linker firmware interfac +* +* Called for initializing API allocator which allow to use +* AML API. +* Returns: toplevel container which accumulates all other +* ACPI tables. +*/ +Aml *init_aml_allocator (GArray *linker); + +/** +* free_aml_allocator: +* +* Releases all elements used by AML API, frees associated memory +* and invalidates AML allocator. After this call @init_aml_allocator +* should be called again if AML API is to be used again. +*/ +void free_aml_allocator (void ); + +/** +* aml_append: +* @parent_ctx: context to which @child element is added +* @child: element that is copied into @parent_ctx context +* +* Joins Aml elements together and helps to construct AML tables +* Examle of usage: +* Aml *table = aml_def_block("SSDT", ...); +* Aml *sb = aml_scope("\_SB"); +* Aml *dev = aml_device("PCI0"); +* +* aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); +* aml_append(sb, dev); +* aml_append(table, sb); +*/ +void aml_append (Aml *parent_ctx,Aml *child); + +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);void build_prepend_byte (GArray *array,uint8_t val);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
Quoted 109 lines · On Tue, 17 Feb 2015 17:26:16 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 108 lines · Igor Mammedov
Adds for dynamic AML creation, which will be used for piecing ASL/AML primitives together and hiding from user/caller details about how nested context should be closed/packed leaving less space for mistakes and necessity to know how AML should be encoded, allowing user to concentrate on ASL representation instead.
For example it will allow to create AML like this:
init_aml_allocator();
...
Aml *scope =aml_scope("PCI0")
Aml *dev =aml_device("PM")aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
aml_append(scope, dev);
...free_aml_allocator();Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 1 - include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-)hw/acpi/aml-build.c +67
-0@@ -25,6 +25,8 @@#include <stdbool.h> #include <string.h> #include "hw/acpi/aml-build.h" +#include "qemu/bswap.h" +#include "hw/acpi/bios-linker-loader.h" GArray *build_alloc_array (void ) {@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)build_append_value (table, value,4 ); } } + +static GPtrArray *alloc_list; + +static Aml *aml_alloc (void ) +{ +Aml *var =g_new0 (typeof (*var),1 ); + +g_ptr_array_add (alloc_list, var); + var->block_flags =AML_HELPER ; + var->buf =build_alloc_array (); +return var; +} + +static void aml_free (gpointer data) +{ +Aml *var = data; +build_free_array (var->buf); +} + +Aml *init_aml_allocator (GArray *linker) +{ +Aml *var; + +assert (!alloc_list); + alloc_list =g_ptr_array_new_with_free_func (aml_free); + var =aml_alloc (); + var->linker = linker; +return var; +} + +void free_aml_allocator (void ) +{ +g_ptr_array_free (alloc_list, true); + alloc_list =0 ; +} + +static void build_buffer (GArray *array,uint8_t op) +{ +GArray *data =build_alloc_array (); + +build_append_int (data, array->len); +g_array_prepend_vals (array, data->data, data->len); +build_free_array (data); +build_package (array, op); +} + +void aml_append (Aml *parent_ctx,Aml *child) +{ +switch (child->block_flags) { +case AML_NON_BLOCK : +build_append_byte (parent_ctx->buf, child->op); +break ; +case AML_EXT_PACKAGE : +build_extop_package (child->buf, child->op); +break ; +case AML_PACKAGE : +build_package (child->buf, child->op); +break ; +case AML_RES_TEMPLATE : +build_append_byte (child->buf,0x79 );/* EndTag */ +/* +* checksum operations is treated as succeeded if checksum +* field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag] +*/ +build_append_byte (child->buf,0 );
Quoted 8 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 331
Quoted 5 lines
hw/acpi/aml-build.c +5
-0+/* fall through, to pack resources in buffer */ +case AML_BUFFER : +build_buffer (child->buf, child->op); +break ; +case AML_DEF_BLOCK : {This one is inelegant.
It's not a definition block, and the patching and
it's definition block according to spec.
Quoted 1 line
manual offset calculation are scary.
it's the same thing as every user of build_header does every time, so it's less scary compared to build_header and done only in one place so user won't ever have to care about offsets.
Quoted 9 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 338
Quoted 8 lines
hw/acpi/aml-build.c +7
-0+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,
Quoted 3 lines
Hard-coding file name here is very ugly. All this does not belong in this file, this is fw cfg interface.
It's but, it's the only one file and so far we don't have plans to extend it and it does the same thing as build_header()
Quoted 13 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 343
Quoted 7 lines
hw/acpi/aml-build.c +5
-0+ parent_ctx->buf->data, + start, child->buf->len, start + 9 /* checksum offset */); + +/* set DefinitionBlock length at TableLength offset*/ +memcpy (child->buf->data +4 , &le32_len,sizeof le32_len);This make no sense.
In AML, there are no objects which are higher level than the table.
Quoted 6 lines
So for now, please just leave this alone:
drop linker completely, keeptable_dataa simple GArray, not AML, and reusebuild_headerto fill in headers.This way this file just deals with AML and ACPI spec.
Using build_header() is problematic for 2 reasons:
1. it has to be done backwards,
i.e. one has to reserve space for header first, than add content and then call build_header
to patch header with current length and table definition data
2. when using build_header() user has to calculate offsets and lengths manually every time.
While using aml_def_block() process is quite straightforward and follows the declarative flow as it is in ASL, which less confusing and error-prone, like:
ssdt = aml_def_block(...);
// add content to ssdtaml_append(tables_blob, ssdt);
so hiding linker from user in this case makes usage simpler and more harder to screw up, which is the whole point of introducing this API.
I have a further plans to make other tables use aml_def_block and get rid of acpi_add_table() which is also confusing and simplify RSDT building doing it transparently for user.
That way both ARM and i386 targets would reuse the same code /API instead of re-implementing it in every target. User will just get complete tables blob from API and put it in respective fw_cfg file.
I also wish that we have had only one file for ACPI tables (including RSDP) but ship already went away, maybe we can do it for ARM though.
PS:
My secret goal is to bury linker and use it only when one have to do so :), seriously.
Quoted 7 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 346
Quoted 5 lines
hw/acpi/aml-build.c +3
-0+break ; + } +default :This should assert.
sure
Quoted 92 lines
Quoted 91 lines
hw/acpi/aml-build.c +4
-0+break ; + } +build_append_array (parent_ctx->buf, child->buf); +}hw/i386/acpi-build.c +0
-1@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)#define ACPI_BUILD_APPNAME6 "BOCHS "#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +61
-0@@ -5,6 +5,67 @@#include <glib.h> #include "qemu/compiler.h" +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" + +typedef enum { +AML_HELPER =0 , +AML_NON_BLOCK , +AML_PACKAGE , +AML_EXT_PACKAGE , +AML_BUFFER , +AML_RES_TEMPLATE , +AML_DEF_BLOCK , +}AmlBlockFlags ; + +struct Aml { +GArray *buf; + +/*< private >*/ +uint8_t op; +AmlBlockFlags block_flags; +GArray *linker; +}; +typedef struct Aml Aml ; + +/** +* init_aml_allocator: +* @linker: linker that used by API for registering ACPI tables +* with linker firmware interfac +* +* Called for initializing API allocator which allow to use +* AML API. +* Returns: toplevel container which accumulates all other +* ACPI tables. +*/ +Aml *init_aml_allocator (GArray *linker); + +/** +* free_aml_allocator: +* +* Releases all elements used by AML API, frees associated memory +* and invalidates AML allocator. After this call @init_aml_allocator +* should be called again if AML API is to be used again. +*/ +void free_aml_allocator (void ); + +/** +* aml_append: +* @parent_ctx: context to which @child element is added +* @child: element that is copied into @parent_ctx context +* +* Joins Aml elements together and helps to construct AML tables +* Examle of usage: +* Aml *table = aml_def_block("SSDT", ...); +* Aml *sb = aml_scope("\_SB"); +* Aml *dev = aml_device("PCI0"); +* +* aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); +* aml_append(sb, dev); +* aml_append(table, sb); +*/ +void aml_append (Aml *parent_ctx,Aml *child); + +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);void build_prepend_byte (GArray *array,uint8_t val);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
Quoted 120 lines · Igor Mammedov
Quoted 109 lines · On Tue, 17 Feb 2015 17:26:16 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 108 lines · Igor Mammedov
Adds for dynamic AML creation, which will be used for piecing ASL/AML primitives together and hiding from user/caller details about how nested context should be closed/packed leaving less space for mistakes and necessity to know how AML should be encoded, allowing user to concentrate on ASL representation instead.
For example it will allow to create AML like this:
init_aml_allocator();
...
Aml *scope =aml_scope("PCI0")
Aml *dev =aml_device("PM")aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
aml_append(scope, dev);
...free_aml_allocator();Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 1 - include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-)hw/acpi/aml-build.c +67
-0@@ -25,6 +25,8 @@#include <stdbool.h> #include <string.h> #include "hw/acpi/aml-build.h" +#include "qemu/bswap.h" +#include "hw/acpi/bios-linker-loader.h" GArray *build_alloc_array (void ) {@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)build_append_value (table, value,4 ); } } + +static GPtrArray *alloc_list; + +static Aml *aml_alloc (void ) +{ +Aml *var =g_new0 (typeof (*var),1 ); + +g_ptr_array_add (alloc_list, var); + var->block_flags =AML_HELPER ; + var->buf =build_alloc_array (); +return var; +} + +static void aml_free (gpointer data) +{ +Aml *var = data; +build_free_array (var->buf); +} + +Aml *init_aml_allocator (GArray *linker) +{ +Aml *var; + +assert (!alloc_list); + alloc_list =g_ptr_array_new_with_free_func (aml_free); + var =aml_alloc (); + var->linker = linker; +return var; +} + +void free_aml_allocator (void ) +{ +g_ptr_array_free (alloc_list, true); + alloc_list =0 ; +} + +static void build_buffer (GArray *array,uint8_t op) +{ +GArray *data =build_alloc_array (); + +build_append_int (data, array->len); +g_array_prepend_vals (array, data->data, data->len); +build_free_array (data); +build_package (array, op); +} + +void aml_append (Aml *parent_ctx,Aml *child) +{ +switch (child->block_flags) { +case AML_NON_BLOCK : +build_append_byte (parent_ctx->buf, child->op); +break ; +case AML_EXT_PACKAGE : +build_extop_package (child->buf, child->op); +break ; +case AML_PACKAGE : +build_package (child->buf, child->op); +break ; +case AML_RES_TEMPLATE : +build_append_byte (child->buf,0x79 );/* EndTag */ +/* +* checksum operations is treated as succeeded if checksum +* field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag] +*/ +build_append_byte (child->buf,0 );Quoted 8 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 331
Quoted 5 lines
hw/acpi/aml-build.c +5
-0+/* fall through, to pack resources in buffer */ +case AML_BUFFER : +build_buffer (child->buf, child->op); +break ; +case AML_DEF_BLOCK : {This one is inelegant.
It's not a definition block, and the patching and
Quoted 1 line
it's definition block according to spec.
definition block is not an AML thing, is it?
It's an ASL construct I think.
AML calls them tables, e.g.:
20.2.1 Table and Table Header Encoding
Quoted 4 lines
Quoted 1 line
manual offset calculation are scary.
it's the same thing as every user of
build_headerdoes every time, so it's less scary compared tobuild_headerand done only in one place so user won't ever have to care about offsets.
We have different definitions of scary.
C structures is the standard way to lay out memory.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
hw/acpi/aml-build.c +7
-0+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,
Quoted 5 lines
Quoted 3 lines
Hard-coding file name here is very ugly. All this does not belong in this file, this is fw cfg interface.
It's but, it's the only one file and so far we don't have plans to extend it and it does the same thing as
build_header()
So just call build_header.
Quoted 20 lines
Quoted 14 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 343
Quoted 8 lines
hw/acpi/aml-build.c +5
-0+ parent_ctx->buf->data, + start, child->buf->len, start + 9 /* checksum offset */); + +/* set DefinitionBlock length at TableLength offset*/ +memcpy (child->buf->data +4 , &le32_len,sizeof le32_len);This make no sense.
In AML, there are no objects which are higher level than the table.Quoted 6 lines
So for now, please just leave this alone:
drop linker completely, keeptable_dataa simple GArray, not AML, and reusebuild_headerto fill in headers.This way this file just deals with AML and ACPI spec.
Quoted 8 lines
Using
build_header()is problematic for 2 reasons:
1. it has to be done backwards,
i.e. one has to reserve space for header first, than add content and then callbuild_header
to patch header with current length and table definition data2. when using
build_header()user has to calculate offsets and lengths manually every time.
It's not easy to use, but it's not too hard either. As there's a single instance now,
let's merge the rest, we'll work on a cleaner interface for build_header.
this is not it.
Quoted 17 lines
While using
aml_def_block()process is quite straightforward and follows the declarative flow as it is in ASL, which less confusing and error-prone, like:ssdt =
aml_def_block(...);
// add content to ssdtaml_append(tables_blob, ssdt);so hiding linker from user in this case makes usage simpler and more harder to screw up, which is the whole point of introducing this API.
I have a further plans to make other tables use
aml_def_blockand get rid ofacpi_add_table()which is also confusing and simplify RSDT building doing it transparently for user.
Quoted 7 lines
That way both ARM and i386 targets would reuse the same code /API instead of re-implementing it in every target. User will just get complete tables blob from API and put it in respective
fw_cfgfile.
I also wish that we have had only one file for ACPI tables (including RSDP) but ship already went away, maybe we can do it for ARM though.
Unlikely.
Quoted 3 lines
PS:
My secret goal is to bury linker and use it only when one have to do so :), seriously.
You are doing too many things at once.
We need a minimal patchset to start merging your work. so drop this part please, just use build_header.
Quoted 101 lines
Quoted 7 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 346
Quoted 5 lines
hw/acpi/aml-build.c +3
-0+break ; + } +default :This should assert.
sure
Quoted 92 lines
Quoted 91 lines
hw/acpi/aml-build.c +4
-0+break ; + } +build_append_array (parent_ctx->buf, child->buf); +}hw/i386/acpi-build.c +0
-1@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)#define ACPI_BUILD_APPNAME6 "BOCHS "#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +61
-0@@ -5,6 +5,67 @@#include <glib.h> #include "qemu/compiler.h" +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" + +typedef enum { +AML_HELPER =0 , +AML_NON_BLOCK , +AML_PACKAGE , +AML_EXT_PACKAGE , +AML_BUFFER , +AML_RES_TEMPLATE , +AML_DEF_BLOCK , +}AmlBlockFlags ; + +struct Aml { +GArray *buf; + +/*< private >*/ +uint8_t op; +AmlBlockFlags block_flags; +GArray *linker; +}; +typedef struct Aml Aml ; + +/** +* init_aml_allocator: +* @linker: linker that used by API for registering ACPI tables +* with linker firmware interfac +* +* Called for initializing API allocator which allow to use +* AML API. +* Returns: toplevel container which accumulates all other +* ACPI tables. +*/ +Aml *init_aml_allocator (GArray *linker); + +/** +* free_aml_allocator: +* +* Releases all elements used by AML API, frees associated memory +* and invalidates AML allocator. After this call @init_aml_allocator +* should be called again if AML API is to be used again. +*/ +void free_aml_allocator (void ); + +/** +* aml_append: +* @parent_ctx: context to which @child element is added +* @child: element that is copied into @parent_ctx context +* +* Joins Aml elements together and helps to construct AML tables +* Examle of usage: +* Aml *table = aml_def_block("SSDT", ...); +* Aml *sb = aml_scope("\_SB"); +* Aml *dev = aml_device("PCI0"); +* +* aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); +* aml_append(sb, dev); +* aml_append(table, sb); +*/ +void aml_append (Aml *parent_ctx,Aml *child); + +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);void build_prepend_byte (GArray *array,uint8_t val);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
In reply to Igor MammedovQuoted 14 lines · Igor Mammedov
Adds for dynamic AML creation, which will be used for piecing ASL/AML primitives together and hiding from user/caller details about how nested context should be closed/packed leaving less space for mistakes and necessity to know how AML should be encoded, allowing user to concentrate on ASL representation instead.
For example it will allow to create AML like this:
init_aml_allocator();
...
Aml *scope =aml_scope("PCI0")
Aml *dev =aml_device("PM")
Quoted 6 lines
aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
aml_append(scope, dev);
...free_aml_allocator();Signed-off-by Igor Mammedov <[email protected]>
This should be split up, so we can see functionality added in the same patch where it's used. It's too hard to evaluate this alone.
Quoted 50 lines
--- hw/acpi/aml-build.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 1 - include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-)hw/acpi/aml-build.c +29
-0@@ -25,6 +25,8 @@#include <stdbool.h> #include <string.h> #include "hw/acpi/aml-build.h" +#include "qemu/bswap.h" +#include "hw/acpi/bios-linker-loader.h" GArray *build_alloc_array (void ) {@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)build_append_value (table, value,4 ); } } + +static GPtrArray *alloc_list; + +static Aml *aml_alloc (void ) +{ +Aml *var =g_new0 (typeof (*var),1 ); + +g_ptr_array_add (alloc_list, var); + var->block_flags =AML_HELPER ; + var->buf =build_alloc_array (); +return var; +} + +static void aml_free (gpointer data) +{ +Aml *var = data; +build_free_array (var->buf); +} + +Aml *init_aml_allocator (GArray *linker) +{ +Aml *var; + +assert (!alloc_list); + alloc_list =g_ptr_array_new_with_free_func (aml_free); + var =aml_alloc (); + var->linker = linker;
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 298
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+return var; +} + +void free_aml_allocator (void ) +{ +g_ptr_array_free (alloc_list, true); + alloc_list =0 ; +} + +static void build_buffer (GArray *array,uint8_t op)
What does this do?
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 303
Quoted 5 lines
hw/acpi/aml-build.c +5
-0+{ +GArray *data =build_alloc_array (); + +build_append_int (data, array->len); +g_array_prepend_vals (array, data->data, data->len);
Prepend is best avoided. Can't say whether it's necessary here.
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+build_free_array (data); +build_package (array, op); +} + +void aml_append (Aml *parent_ctx,Aml *child) +{ +switch (child->block_flags) { +case AML_NON_BLOCK : +build_append_byte (parent_ctx->buf, child->op); +break ;
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 323
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+case AML_EXT_PACKAGE : +build_extop_package (child->buf, child->op); +break ; +case AML_PACKAGE : +build_package (child->buf, child->op); +break ; +case AML_RES_TEMPLATE : +build_append_byte (child->buf,0x79 );/* EndTag */ +/* +* checksum operations is treated as succeeded if checksum
are treated?
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 324
Quoted 1 line
hw/acpi/aml-build.c +1
-0+* field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
Pls always quote oldest spec, not latest one.
Quoted 43 lines
hw/acpi/aml-build.c +26
-0+*/ +build_append_byte (child->buf,0 ); +/* fall through, to pack resources in buffer */ +case AML_BUFFER : +build_buffer (child->buf, child->op); +break ; +case AML_DEF_BLOCK : { +uint8_t *start = (uint8_t *)parent_ctx->buf->data + + parent_ctx->buf->len; +uint32_t le32_len =cpu_to_le32 (child->buf->len); + +/* create linker entry for the DefinitionBlock */ +bios_linker_loader_add_checksum (parent_ctx->linker, +ACPI_BUILD_TABLE_FILE , + parent_ctx->buf->data, + start, child->buf->len, start +9 /* checksum offset */ ); + +/* set DefinitionBlock length at TableLength offset*/ +memcpy (child->buf->data +4 , &le32_len,sizeof le32_len); +break ; + } +default : +break ; + } +build_append_array (parent_ctx->buf, child->buf); +}hw/i386/acpi-build.c +0
-1@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)#define ACPI_BUILD_APPNAME6 "BOCHS "#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +0
-0
include/hw/acpi/aml-build.h line 8
Quoted 4 lines
include/hw/acpi/aml-build.h +1
-0@@ -5,6 +5,67 @@#include <glib.h> #include "qemu/compiler.h" +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
fw cfg stuff doesn't belong in aml generator.
include/hw/acpi/aml-build.h line 12
Quoted 4 lines
include/hw/acpi/aml-build.h +4
-0+ +typedef enum { + AML_HELPER = 0, + AML_NON_BLOCK,
What are the above two?
The names aren't really helpful.
include/hw/acpi/aml-build.h line 15
Quoted 3 lines
include/hw/acpi/aml-build.h +3
-0+AML_PACKAGE , +AML_EXT_PACKAGE , + AML_BUFFER,
And what's a buffer?
Quoted 58 lines
include/hw/acpi/aml-build.h +53
-0+AML_RES_TEMPLATE , +AML_DEF_BLOCK , +} AmlBlockFlags; + +struct Aml { +GArray *buf; + +/*< private >*/ +uint8_t op; +AmlBlockFlags block_flags; +GArray *linker; +}; +typedef struct Aml Aml ; + +/** +* init_aml_allocator: +* @linker: linker that used by API for registering ACPI tables +* with linker firmware interfac +* +* Called for initializing API allocator which allow to use +* AML API. +* Returns: toplevel container which accumulates all other +* ACPI tables. +*/ +Aml *init_aml_allocator (GArray *linker); + +/** +* free_aml_allocator: +* +* Releases all elements used by AML API, frees associated memory +* and invalidates AML allocator. After this call @init_aml_allocator +* should be called again if AML API is to be used again. +*/ +void free_aml_allocator (void ); + +/** +* aml_append: +* @parent_ctx: context to which @child element is added +* @child: element that is copied into @parent_ctx context +* +* Joins Aml elements together and helps to construct AML tables +* Examle of usage: +* Aml *table = aml_def_block("SSDT", ...); +* Aml *sb = aml_scope("\_SB"); +* Aml *dev = aml_device("PCI0"); +* +* aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); +* aml_append(sb, dev); +* aml_append(table, sb); +*/ +void aml_append (Aml *parent_ctx,Aml *child); + +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);void build_prepend_byte (GArray *array,uint8_t val);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()
Quoted 20 lines · On Tue, 17 Feb 2015 20:46:32 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 19 lines · Igor Mammedov
Adds for dynamic AML creation, which will be used for piecing ASL/AML primitives together and hiding from user/caller details about how nested context should be closed/packed leaving less space for mistakes and necessity to know how AML should be encoded, allowing user to concentrate on ASL representation instead.
For example it will allow to create AML like this:
init_aml_allocator();
...
Aml *scope =aml_scope("PCI0")
Aml *dev =aml_device("PM")aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
aml_append(scope, dev);
...free_aml_allocator();
Quoted 5 lines
Quoted 1 line
Signed-off-by Igor Mammedov <[email protected]>This should be split up, so we can see functionality added in the same patch where it's used. It's too hard to evaluate this alone.
I'll try to split it
Quoted 56 lines
Quoted 56 lines
--- hw/acpi/aml-build.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 1 - include/hw/acpi/aml-build.h | 61 ++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-)hw/acpi/aml-build.c +33
-0@@ -25,6 +25,8 @@#include <stdbool.h> #include <string.h> #include "hw/acpi/aml-build.h" +#include "qemu/bswap.h" +#include "hw/acpi/bios-linker-loader.h" GArray *build_alloc_array (void ) {@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)build_append_value (table, value,4 ); } } + +static GPtrArray *alloc_list; + +static Aml *aml_alloc (void ) +{ +Aml *var =g_new0 (typeof (*var),1 ); + +g_ptr_array_add (alloc_list, var); + var->block_flags =AML_HELPER ; + var->buf =build_alloc_array (); +return var; +} + +static void aml_free (gpointer data) +{ +Aml *var = data; +build_free_array (var->buf); +} + +Aml *init_aml_allocator (GArray *linker) +{ +Aml *var; + +assert (!alloc_list); + alloc_list =g_ptr_array_new_with_free_func (aml_free); + var =aml_alloc (); + var->linker = linker; +return var; +} + +void free_aml_allocator (void )
Quoted 8 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 298
Quoted 6 lines
hw/acpi/aml-build.c +6
-0+{ +g_ptr_array_free (alloc_list, true); + alloc_list =0 ; +} + +static void build_buffer (GArray *array,uint8_t op)What does this do?
that's block of code moved to helper you asked for in previous review it finishes up AML buffer construction pretty much the same way as build_package() does.
Quoted 9 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 303
Quoted 6 lines
hw/acpi/aml-build.c +5
-0+{ +GArray *data =build_alloc_array (); + +build_append_int (data, array->len); +g_array_prepend_vals (array, data->data, data->len);Prepend is best avoided. Can't say whether it's necessary here.
can't be helped, it does similar thing to as adding PkgLength
Quoted 15 lines
Quoted 15 lines
hw/acpi/aml-build.c +14
-0+build_free_array (data); +build_package (array, op); +} + +void aml_append (Aml *parent_ctx,Aml *child) +{ +switch (child->block_flags) { +case AML_NON_BLOCK : +build_append_byte (parent_ctx->buf, child->op); +break ; +case AML_EXT_PACKAGE : +build_extop_package (child->buf, child->op); +break ; +case AML_PACKAGE :
Quoted 8 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 323
Quoted 6 lines
hw/acpi/aml-build.c +6
-0+build_package (child->buf, child->op); +break ; +case AML_RES_TEMPLATE : +build_append_byte (child->buf,0x79 );/* EndTag */ +/* +* checksum operations is treated as succeeded if checksum are treated?
sure
Quoted 56 lines
hw/acpi/aml-build.c void build_append_int(GArray *table, uint32_t value) · line 324
Quoted 2 lines
hw/acpi/aml-build.c +1
-0+* field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag] Pls always quote oldest spec, not latest one.
Quoted 43 lines
hw/acpi/aml-build.c +26
-0+*/ +build_append_byte (child->buf,0 ); +/* fall through, to pack resources in buffer */ +case AML_BUFFER : +build_buffer (child->buf, child->op); +break ; +case AML_DEF_BLOCK : { +uint8_t *start = (uint8_t *)parent_ctx->buf->data + + parent_ctx->buf->len; +uint32_t le32_len =cpu_to_le32 (child->buf->len); + +/* create linker entry for the DefinitionBlock */ +bios_linker_loader_add_checksum (parent_ctx->linker, +ACPI_BUILD_TABLE_FILE , + parent_ctx->buf->data, + start, child->buf->len, start +9 /* checksum offset */ ); + +/* set DefinitionBlock length at TableLength offset*/ +memcpy (child->buf->data +4 , &le32_len,sizeof le32_len); +break ; + } +default : +break ; + } +build_append_array (parent_ctx->buf, child->buf); +}hw/i386/acpi-build.c +0
-1@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)#define ACPI_BUILD_APPNAME6 "BOCHS "#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +0
-0include/hw/acpi/aml-build.h line 8
Quoted 4 lines
include/hw/acpi/aml-build.h +1
-0@@ -5,6 +5,67 @@#include <glib.h> #include "qemu/compiler.h" +#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"fw cfg stuff doesn't belong in aml generator.
Quoted 7 lines
include/hw/acpi/aml-build.h line 12
Quoted 4 lines
include/hw/acpi/aml-build.h +4
-0+ +typedef enum { + AML_HELPER = 0, + AML_NON_BLOCK,What are the above two?
The names aren't really helpful.
AML_HELPER - to distinguish terms that do not need extra processing and just need to be copied into parent context, which is mostly only helpers like aml_callXX(), terms put in resource template, e.t.c. allocated by aml_alloc()
AML_NON_BLOCK - is used for simple inline terms with 1 byte opcode allocated by aml_opcode(opcode)
the rest of the flags are used for more complex structures which are allocated with aml_bundle(opcode, flags)
I've thought we came to agreement when we discussed this.
Quoted 6 lines
include/hw/acpi/aml-build.h line 15
Quoted 4 lines
include/hw/acpi/aml-build.h +3
-0+AML_PACKAGE , +AML_EXT_PACKAGE , + AML_BUFFER,And what's a buffer?
DefBuffer := BufferOp PkgLength BufferSize ByteList
Quoted 59 lines
Quoted 59 lines
include/hw/acpi/aml-build.h +53
-0+AML_RES_TEMPLATE , +AML_DEF_BLOCK , +} AmlBlockFlags; + +struct Aml { +GArray *buf; + +/*< private >*/ +uint8_t op; +AmlBlockFlags block_flags; +GArray *linker; +}; +typedef struct Aml Aml ; + +/** +* init_aml_allocator: +* @linker: linker that used by API for registering ACPI tables +* with linker firmware interfac +* +* Called for initializing API allocator which allow to use +* AML API. +* Returns: toplevel container which accumulates all other +* ACPI tables. +*/ +Aml *init_aml_allocator (GArray *linker); + +/** +* free_aml_allocator: +* +* Releases all elements used by AML API, frees associated memory +* and invalidates AML allocator. After this call @init_aml_allocator +* should be called again if AML API is to be used again. +*/ +void free_aml_allocator (void ); + +/** +* aml_append: +* @parent_ctx: context to which @child element is added +* @child: element that is copied into @parent_ctx context +* +* Joins Aml elements together and helps to construct AML tables +* Examle of usage: +* Aml *table = aml_def_block("SSDT", ...); +* Aml *sb = aml_scope("\_SB"); +* Aml *dev = aml_device("PCI0"); +* +* aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); +* aml_append(sb, dev); +* aml_append(table, sb); +*/ +void aml_append (Aml *parent_ctx,Aml *child); + +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);void build_prepend_byte (GArray *array,uint8_t val);Signature · 1 line
1.8.3.1
PATCH v3 2/52 pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
In reply to Igor Mammedovexcept of shortening of lines and making code a bit more readable, it will reduce renaming noise when changing tables blob from GArray* to Aml* type.
--- hw/i386/acpi-build.c | 69 ++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 34 deletions(-)
hw/i386/acpi-build.c +35 -34
@@ -1317,6 +1317,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)PcPciInfo pci;uint8_t *u;size_t aml_len =0 ; +GArray *tables_blob = tables->table_data;acpi_get_cpu_info (&cpu);acpi_get_pm_info (&pm);
@@ -1337,66 +1338,66 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)* We place it first since it's the only table that has alignment * requirements. */ - facs = tables->table_data->len; -build_facs (tables->table_data, tables->linker, guest_info); + facs = tables_blob->len; +build_facs (tables_blob, tables->linker, guest_info);/* DSDT is pointed to by FADT */ - dsdt = tables->table_data->len; -build_dsdt (tables->table_data, tables->linker, &misc); + dsdt = tables_blob->len; +build_dsdt (tables_blob, tables->linker, &misc);/* Count the size of the DSDT and SSDT, we will need it for legacy * sizing of ACPI tables. */ - aml_len += tables->table_data->len - dsdt; + aml_len += tables_blob->len - dsdt;/* ACPI tables pointed to by RSDT */ -acpi_add_table (table_offsets, tables->table_data); -build_fadt (tables->table_data, tables->linker, &pm, facs, dsdt); +acpi_add_table (table_offsets, tables_blob); +build_fadt (tables_blob, tables->linker, &pm, facs, dsdt); - ssdt = tables->table_data->len; -acpi_add_table (table_offsets, tables->table_data); -build_ssdt (tables->table_data, tables->linker, &cpu, &pm, &misc, &pci, + ssdt = tables_blob->len; +acpi_add_table (table_offsets, tables_blob); +build_ssdt (tables_blob, tables->linker, &cpu, &pm, &misc, &pci, guest_info); - aml_len += tables->table_data->len - ssdt; + aml_len += tables_blob->len - ssdt; -acpi_add_table (table_offsets, tables->table_data); -build_madt (tables->table_data, tables->linker, &cpu, guest_info); +acpi_add_table (table_offsets, tables_blob); +build_madt (tables_blob, tables->linker, &cpu, guest_info);if (misc.has_hpet) { -acpi_add_table (table_offsets, tables->table_data); -build_hpet (tables->table_data, tables->linker); +acpi_add_table (table_offsets, tables_blob); +build_hpet (tables_blob, tables->linker); }if (misc.has_tpm) { -acpi_add_table (table_offsets, tables->table_data); -build_tpm_tcpa (tables->table_data, tables->linker, tables->tcpalog); +acpi_add_table (table_offsets, tables_blob); +build_tpm_tcpa (tables_blob, tables->linker, tables->tcpalog); -acpi_add_table (table_offsets, tables->table_data); -build_tpm_ssdt (tables->table_data, tables->linker); +acpi_add_table (table_offsets, tables_blob); +build_tpm_ssdt (tables_blob, tables->linker); }if (guest_info->numa_nodes) { -acpi_add_table (table_offsets, tables->table_data); -build_srat (tables->table_data, tables->linker, guest_info); +acpi_add_table (table_offsets, tables_blob); +build_srat (tables_blob, tables->linker, guest_info); }if (acpi_get_mcfg (&mcfg)) { -acpi_add_table (table_offsets, tables->table_data); -build_mcfg_q35 (tables->table_data, tables->linker, &mcfg); +acpi_add_table (table_offsets, tables_blob); +build_mcfg_q35 (tables_blob, tables->linker, &mcfg); }if (acpi_has_iommu ()) { -acpi_add_table (table_offsets, tables->table_data); -build_dmar_q35 (tables->table_data, tables->linker); +acpi_add_table (table_offsets, tables_blob); +build_dmar_q35 (tables_blob, tables->linker); }/* Add tables supplied by user (if any) */ for (u =acpi_table_first (); u; u =acpi_table_next (u)) {unsigned len =acpi_table_len (u); -acpi_add_table (table_offsets, tables->table_data); -g_array_append_vals (tables->table_data, u, len); +acpi_add_table (table_offsets, tables_blob); +g_array_append_vals (tables_blob, u, len); }/* RSDT is pointed to by RSDP */ - rsdt = tables->table_data->len; -build_rsdt (tables->table_data, tables->linker, table_offsets); + rsdt = tables_blob->len; +build_rsdt (tables_blob, tables->linker, table_offsets);/* RSDP is in FSEG memory, so allocate it separately */ build_rsdp (tables->rsdp, tables->linker, rsdt);
@@ -1428,23 +1429,23 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) guest_info->legacy_acpi_table_size +ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;int legacy_table_size = -ROUND_UP (tables->table_data->len - aml_len + legacy_aml_len, +ROUND_UP (tables_blob->len - aml_len + legacy_aml_len,ACPI_BUILD_ALIGN_SIZE ); -if (tables->table_data->len > legacy_table_size) { +if (tables_blob->len > legacy_table_size) {/* Should happen only with PCI bridges and -M pc-i440fx-2.0. */ error_report ("Warning: migration may not work." ); } -g_array_set_size (tables->table_data, legacy_table_size); +g_array_set_size (tables_blob, legacy_table_size); }else {/* Make sure we have a buffer in case we need to resize the tables. */ -if (tables->table_data->len >ACPI_BUILD_TABLE_SIZE /2 ) { +if (tables_blob->len >ACPI_BUILD_TABLE_SIZE /2 ) {/* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots. */ error_report ("Warning: ACPI tables are larger than 64k." );error_report ("Warning: migration may not work." );error_report ("Warning: please remove CPUs, NUMA nodes, " "memory slots or PCI bridges." ); } -acpi_align_size (tables->table_data,ACPI_BUILD_TABLE_SIZE ); +acpi_align_size (tables_blob,ACPI_BUILD_TABLE_SIZE ); }acpi_align_size (tables->linker,ACPI_BUILD_ALIGN_SIZE );
Signature · 1 line
1.8.3.1
PATCH v3 3/52 pc: acpi: make top level ACPI tables blob Aml*
In reply to Igor Mammedovit will permit to add a separate tables into blob like other AML constructs using aml_append() routine and hide from user need to invoke linker manually for tables, handling it automatically inside of aml_append() helper.
Later when all tables are converted to use AML API, it would be possible to generate RSDT automatically and drop manual table offsets tracking for RSDT.
--- hw/i386/acpi-build.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
hw/i386/acpi-build.c +10 -9
@@ -1238,7 +1238,7 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt) typedef struct AcpiBuildTables { - GArray *table_data; + Aml *table_data; GArray *rsdp; GArray *tcpalog; GArray *linker;
@@ -1247,17 +1247,17 @@ struct AcpiBuildTables {static inline void acpi_build_tables_init (AcpiBuildTables *tables) { tables->rsdp =g_array_new (false, true/* clear */ ,1 ); - tables->table_data =g_array_new (false, true/* clear */ ,1 ); tables->tcpalog =g_array_new (false, true/* clear */ ,1 ); tables->linker =bios_linker_loader_init (); + tables->table_data =init_aml_allocator (tables->linker); }static inline void acpi_build_tables_cleanup (AcpiBuildTables *tables,bool mfre) {void *linker_data =bios_linker_loader_cleanup (tables->linker); +free_aml_allocator ();g_free (linker_data);g_array_free (tables->rsdp, mfre); -g_array_free (tables->table_data, true);g_array_free (tables->tcpalog, mfre); }
@@ -1317,7 +1317,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)PcPciInfo pci;uint8_t *u;size_t aml_len =0 ; -GArray *tables_blob = tables->table_data; +GArray *tables_blob = tables->table_data->buf;acpi_get_cpu_info (&cpu);acpi_get_pm_info (&pm);
@@ -1469,14 +1469,14 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)acpi_build (build_state->guest_info, &tables); -assert (acpi_data_len (tables.table_data) == build_state->table_size); +assert (acpi_data_len (tables.table_data->buf) == build_state->table_size);/* Make sure RAM size is correct - in case it got changed by migration */ qemu_ram_resize (build_state->table_ram, build_state->table_size, &error_abort); -memcpy (qemu_get_ram_ptr (build_state->table_ram), tables.table_data->data, - build_state->table_size); +memcpy (qemu_get_ram_ptr (build_state->table_ram), + tables.table_data->buf->data, build_state->table_size);cpu_physical_memory_set_dirty_range_nocode (build_state->table_ram, build_state->table_size);
@@ -1537,11 +1537,12 @@ void acpi_setup(PcGuestInfo *guest_info)acpi_build (build_state->guest_info, &tables);/* Now expose it all to Guest */ - build_state->table_ram =acpi_add_rom_blob (build_state, tables.table_data, + build_state->table_ram =acpi_add_rom_blob (build_state, + tables.table_data->buf,ACPI_BUILD_TABLE_FILE ,ACPI_BUILD_TABLE_MAX_SIZE );assert (build_state->table_ram !=RAM_ADDR_MAX ); - build_state->table_size =acpi_data_len (tables.table_data); + build_state->table_size =acpi_data_len (tables.table_data->buf);acpi_add_rom_blob (NULL , tables.linker,"etc/table-loader" ,0 );
Signature · 1 line
1.8.3.1
PATCH v3 4/52 acpi: factor out ACPI const int packing out of build_append_value()
In reply to Igor Mammedovit will be reused for adding a plain integer value into AML.
--- hw/acpi/aml-build.c | 19 +++---------------- hw/i386/acpi-build.c | 6 +++--- 2 files changed, 6 insertions(+), 19 deletions(-)
hw/acpi/aml-build.c +3 -16
@@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)void build_append_value (GArray *table,uint32_t value,int size) { -uint8_t prefix;int i; -switch (size) { -case 1 : - prefix =0x0A ;/* BytePrefix */ -break ; -case 2 : - prefix =0x0B ;/* WordPrefix */ -break ; -case 4 : - prefix =0x0C ;/* DWordPrefix */ -break ; -default : -assert (0 ); -return ; - } -build_append_byte (table, prefix);for (i =0 ; i < size; ++i) {build_append_byte (table, value &0xFF ); value = value >>8 ;
@@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value) }else if (value ==0x01 ) {build_append_byte (table,0x01 );/* OneOp */ }else if (value <=0xFF ) { +build_append_byte (table,0x0A );/* BytePrefix */ build_append_value (table, value,1 ); }else if (value <=0xFFFF ) { +build_append_byte (table,0x0B );/* WordPrefix */ build_append_value (table, value,2 ); }else { +build_append_byte (table,0x0C );/* DWordPrefix */ build_append_value (table, value,4 ); } }
hw/i386/acpi-build.c +3 -3
@@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)static void build_append_notify_target_ifequal (GArray *method,GArray *target_name, -uint32_t value,int size) +uint32_t value) {GArray *notify =build_alloc_array ();uint8_t op =0xA0 ;/* IfOp */ build_append_byte (notify,0x93 );/* LEqualOp */ build_append_byte (notify,0x68 );/* Arg0Op */ -build_append_value (notify, value, size); +build_append_int (notify, value);build_append_byte (notify,0x86 );/* NotifyOp */ build_append_array (notify, target_name);build_append_byte (notify,0x69 );/* Arg1Op */
@@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,GArray *target =build_alloc_array ();build_append_namestring (target, format, i);assert (i <256 );/* Fits in 1 byte */ -build_append_notify_target_ifequal (method, target, i,1 ); +build_append_notify_target_ifequal (method, target, i);build_free_array (target); }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()
Quoted 27 lines · Igor Mammedov
it will be reused for adding a plain integer value into AML.
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 19 +++---------------- hw/i386/acpi-build.c | 6 +++--- 2 files changed, 6 insertions(+), 19 deletions(-)hw/acpi/aml-build.c +0
-9@@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)void build_append_value (GArray *table,uint32_t value,int size) { -uint8_t prefix;int i; -switch (size) { -case 1 : - prefix =0x0A ;/* BytePrefix */ -break ; -case 2 : - prefix =0x0B ;/* WordPrefix */ -break ; -case 4 :
hw/acpi/aml-build.c void build_extop_package(GArray *package, uint8_t op) · line 228
Quoted 10 lines
hw/acpi/aml-build.c +0
-7- prefix =0x0C ;/* DWordPrefix */ -break ; -default : -assert (0 ); -return ; - } -build_append_byte (table, prefix);for (i =0 ; i < size; ++i) {build_append_byte (table, value &0xFF ); value = value >>8 ;
This really makes this an awkward API,
you must remember to add the prefix.
IMO you want a new name - build_append_value_noprefix maybe - then call build_append_value_noprefix from build_append_value.
But really, it's best to squash such changes with where they are used, it's just making review harder:
as you add APIs with no documentation, I can't see what they do without reading follow up patch to see how they are used.
Quoted 46 lines
hw/acpi/aml-build.c +3
-0@@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value) }else if (value ==0x01 ) {build_append_byte (table,0x01 );/* OneOp */ }else if (value <=0xFF ) { +build_append_byte (table,0x0A );/* BytePrefix */ build_append_value (table, value,1 ); }else if (value <=0xFFFF ) { +build_append_byte (table,0x0B );/* WordPrefix */ build_append_value (table, value,2 ); }else { +build_append_byte (table,0x0C );/* DWordPrefix */ build_append_value (table, value,4 ); } }hw/i386/acpi-build.c +3
-3@@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)static void build_append_notify_target_ifequal (GArray *method,GArray *target_name, -uint32_t value,int size) +uint32_t value) {GArray *notify =build_alloc_array ();uint8_t op =0xA0 ;/* IfOp */ build_append_byte (notify,0x93 );/* LEqualOp */ build_append_byte (notify,0x68 );/* Arg0Op */ -build_append_value (notify, value, size); +build_append_int (notify, value);build_append_byte (notify,0x86 );/* NotifyOp */ build_append_array (notify, target_name);build_append_byte (notify,0x69 );/* Arg1Op */ @@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,GArray *target =build_alloc_array ();build_append_namestring (target, format, i);assert (i <256 );/* Fits in 1 byte */ -build_append_notify_target_ifequal (method, target, i,1 ); +build_append_notify_target_ifequal (method, target, i);build_free_array (target); }Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()
Quoted 33 lines · On Tue, 17 Feb 2015 20:53:52 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 32 lines · Igor Mammedov
it will be reused for adding a plain integer value into AML.
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 19 +++---------------- hw/i386/acpi-build.c | 6 +++--- 2 files changed, 6 insertions(+), 19 deletions(-)hw/acpi/aml-build.c +0
-14@@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)void build_append_value (GArray *table,uint32_t value,int size) { -uint8_t prefix;int i; -switch (size) { -case 1 : - prefix =0x0A ;/* BytePrefix */ -break ; -case 2 : - prefix =0x0B ;/* WordPrefix */ -break ; -case 4 : - prefix =0x0C ;/* DWordPrefix */ -break ; -default : -assert (0 ); -return ;
Quoted 8 lines
hw/acpi/aml-build.c void build_extop_package(GArray *package, uint8_t op) · line 228
Quoted 5 lines
hw/acpi/aml-build.c +0
-2- } -build_append_byte (table, prefix);for (i =0 ; i < size; ++i) {build_append_byte (table, value &0xFF ); value = value >>8 ;This really makes this an awkward API, you must remember to add the prefix.
it's internal helper for adding plain values,
it's not intended for using outside aml-build.c
I should have marked it as static.
[...]
Quoted 1 line
then call
build_append_value_noprefixfrombuild_append_value.
lets rename it to build_append_int_noprefix as int is less vague then value and leave prefixed part as it's /i.e. build_append_int()/
Quoted 6 lines
But really, it's best to squash such changes with where they are used, it's just making review harder:
as you add APIs with no documentation, I can't see what they do without reading follow up patch to see how they are used.
It's split out to make the rest of patches more review-able
if I drop aml_def_block() patch then this patch might be squashed with:
"acpi: extend build_append_{value|int}() to support 64-bit values" "acpi: add aml_int() term"
and that might be squashed into already huge patch
"pc: acpi-build: drop template patching and create PCI bus tree dynamically"
Squashing 3 different changes into a bigger patch doesn't make review any easier and squashing that into 4th conversion patch makes it even worse.
Quoted 48 lines
Quoted 48 lines
hw/acpi/aml-build.c +3
-0@@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value) }else if (value ==0x01 ) {build_append_byte (table,0x01 );/* OneOp */ }else if (value <=0xFF ) { +build_append_byte (table,0x0A );/* BytePrefix */ build_append_value (table, value,1 ); }else if (value <=0xFFFF ) { +build_append_byte (table,0x0B );/* WordPrefix */ build_append_value (table, value,2 ); }else { +build_append_byte (table,0x0C );/* DWordPrefix */ build_append_value (table, value,4 ); } }hw/i386/acpi-build.c +3
-3@@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)static void build_append_notify_target_ifequal (GArray *method,GArray *target_name, -uint32_t value,int size) +uint32_t value) {GArray *notify =build_alloc_array ();uint8_t op =0xA0 ;/* IfOp */ build_append_byte (notify,0x93 );/* LEqualOp */ build_append_byte (notify,0x68 );/* Arg0Op */ -build_append_value (notify, value, size); +build_append_int (notify, value);build_append_byte (notify,0x86 );/* NotifyOp */ build_append_array (notify, target_name);build_append_byte (notify,0x69 );/* Arg1Op */ @@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,GArray *target =build_alloc_array ();build_append_namestring (target, format, i);assert (i <256 );/* Fits in 1 byte */ -build_append_notify_target_ifequal (method, target, i,1 ); +build_append_notify_target_ifequal (method, target, i);build_free_array (target); }Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()
Quoted 67 lines · Igor Mammedov
Quoted 33 lines · On Tue, 17 Feb 2015 20:53:52 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 32 lines · Igor Mammedov
it will be reused for adding a plain integer value into AML.
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 19 +++---------------- hw/i386/acpi-build.c | 6 +++--- 2 files changed, 6 insertions(+), 19 deletions(-)hw/acpi/aml-build.c +0
-14@@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)void build_append_value (GArray *table,uint32_t value,int size) { -uint8_t prefix;int i; -switch (size) { -case 1 : - prefix =0x0A ;/* BytePrefix */ -break ; -case 2 : - prefix =0x0B ;/* WordPrefix */ -break ; -case 4 : - prefix =0x0C ;/* DWordPrefix */ -break ; -default : -assert (0 ); -return ;Quoted 8 lines
hw/acpi/aml-build.c void build_extop_package(GArray *package, uint8_t op) · line 228
Quoted 5 lines
hw/acpi/aml-build.c +0
-2- } -build_append_byte (table, prefix);for (i =0 ; i < size; ++i) {build_append_byte (table, value &0xFF ); value = value >>8 ;This really makes this an awkward API, you must remember to add the prefix.
it's internal helper for adding plain values,
it's not intended for using outsideaml-build.c
I should have marked it as static.[...]
Quoted 1 line
then call
build_append_value_noprefixfrombuild_append_value.lets rename it to
build_append_int_noprefixas int is less vague then value and leave prefixed part as it's /i.e. build_append_int()/Quoted 6 lines
But really, it's best to squash such changes with where they are used, it's just making review harder:
as you add APIs with no documentation, I can't see what they do without reading follow up patch to see how they are used.It's split out to make the rest of patches more review-able
if I dropaml_def_block()patch then this patch might be squashed with:
"acpi: extend build_append_{value|int}() to support 64-bit values" "acpi: addaml_int()term"
and that might be squashed into already huge patch
"pc: acpi-build: drop template patching and create PCI bus tree dynamically"
Quoted 2 lines
Squashing 3 different changes into a bigger patch doesn't make review any easier and squashing that into 4th conversion patch makes it even worse.
ok
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
hw/acpi/aml-build.c +3
-0@@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value) }else if (value ==0x01 ) {build_append_byte (table,0x01 );/* OneOp */ }else if (value <=0xFF ) { +build_append_byte (table,0x0A );/* BytePrefix */ build_append_value (table, value,1 ); }else if (value <=0xFFFF ) { +build_append_byte (table,0x0B );/* WordPrefix */ build_append_value (table, value,2 ); }else { +build_append_byte (table,0x0C );/* DWordPrefix */ build_append_value (table, value,4 ); } }hw/i386/acpi-build.c +3
-3@@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)static void build_append_notify_target_ifequal (GArray *method,GArray *target_name, -uint32_t value,int size) +uint32_t value) {GArray *notify =build_alloc_array ();uint8_t op =0xA0 ;/* IfOp */ build_append_byte (notify,0x93 );/* LEqualOp */ build_append_byte (notify,0x68 );/* Arg0Op */ -build_append_value (notify, value, size); +build_append_int (notify, value);build_append_byte (notify,0x86 );/* NotifyOp */ build_append_array (notify, target_name);build_append_byte (notify,0x69 );/* Arg1Op */ @@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,GArray *target =build_alloc_array ();build_append_namestring (target, format, i);assert (i <256 );/* Fits in 1 byte */ -build_append_notify_target_ifequal (method, target, i,1 ); +build_append_notify_target_ifequal (method, target, i);build_free_array (target); }Signature · 1 line
1.8.3.1
PATCH v3 5/52 acpi: add aml_def_block() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)
hw/acpi/aml-build.c +38 -0
@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); + + len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var; +}
hw/i386/acpi-build.c +0 -4
@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
include/hw/acpi/aml-build.h +10 -0
@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,
@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +
hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;
Please don't do this.
First, this is not a definition block encoding, so name is wrong.
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
Pls keep using build_header for now.
Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
Quoted 59 lines · On Tue, 17 Feb 2015 17:35:55 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;Please don't do this.
First, this is not a definition block encoding, so name is wrong.
Quoted 6 lines
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
it does, in ACPI 5.1,
20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID OemTableID OemRevision CreatorID CreatorRevision
Quoted 50 lines
Pls keep using
build_headerfor now.Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
Quoted 68 lines · Igor Mammedov
Quoted 59 lines · On Tue, 17 Feb 2015 17:35:55 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;Please don't do this.
First, this is not a definition block encoding, so name is wrong.Quoted 6 lines
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
Quoted 6 lines
it does, in ACPI 5.1,
20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID OemTableID OemRevision CreatorID CreatorRevision
Sorry I'm not merging this in this form, we should use structures where possible, this is where C shines, just use the language properly.
Quoted 50 lines
Quoted 50 lines
Pls keep using
build_headerfor now.Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
Quoted 71 lines · On Tue, 17 Feb 2015 20:03:52 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 70 lines · Igor Mammedov
Quoted 59 lines · On Tue, 17 Feb 2015 17:35:55 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;Please don't do this.
First, this is not a definition block encoding, so name is wrong.Quoted 6 lines
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
it does, in ACPI 5.1,
Quoted 8 lines
Quoted 4 lines
20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID OemTableID OemRevision CreatorID CreatorRevisionSorry I'm not merging this in this form, we should use structures where possible, this is where C shines, just use the language properly.
Although I don't see benefits of using C structures here as I've wrote in previous reply, I can easily switch internal API functions to structures, if it helps with merging.
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Pls keep using
build_headerfor now.Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
Quoted 79 lines · Igor Mammedov
Quoted 76 lines · On Tue, 17 Feb 2015 20:03:52 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 74 lines · Igor Mammedov
Quoted 59 lines · On Tue, 17 Feb 2015 17:35:55 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;Please don't do this.
First, this is not a definition block encoding, so name is wrong.Quoted 6 lines
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
it does, in ACPI 5.1,
20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID OemTableID OemRevision CreatorID CreatorRevision
Quoted 6 lines
Quoted 3 lines
Sorry I'm not merging this in this form, we should use structures where possible, this is where C shines, just use the language properly.
Although I don't see benefits of using C structures here as I've wrote in previous reply, I can easily switch internal API functions to structures, if it helps with merging.
I don't think we need to change too much.
Let's defer aml_def_block and its users for now,
the rest of the series is fine I think.
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Pls keep using
build_headerfor now.Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
In reply to Igor MammedovQuoted 68 lines · Igor Mammedov
Quoted 59 lines · On Tue, 17 Feb 2015 17:35:55 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;Please don't do this.
First, this is not a definition block encoding, so name is wrong.Quoted 6 lines
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
Quoted 6 lines
it does, in ACPI 5.1,
20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID OemTableID OemRevision CreatorID CreatorRevision
So spec explains it very badly, but these all are fixed width fields.
Filling them in using add_byte just makes for hard to read code.
Quoted 50 lines
Quoted 50 lines
Pls keep using
build_headerfor now.Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
Quoted 76 lines · On Tue, 17 Feb 2015 20:15:42 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 68 lines · Igor Mammedov
Quoted 59 lines · On Tue, 17 Feb 2015 17:35:55 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;Please don't do this.
First, this is not a definition block encoding, so name is wrong.Quoted 6 lines
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
Quoted 6 lines
it does, in ACPI 5.1,
20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID OemTableID OemRevision CreatorID CreatorRevision
Quoted 4 lines
So spec explains it very badly, but these all are fixed width fields.
Filling them in usingadd_bytejust makes for hard to read code.
If it were only add_byte, I'd agree but it basically composes by whole fields and in this particular case is easy to verify just by looking to spec, just like the rest of AML terms does.
And one doesn't have to care about endianness because build_append_value() packs integer fields as expected by spec as opposed to using C struct-s.
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Pls keep using
build_headerfor now.Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term
Quoted 83 lines · Igor Mammedov
Quoted 76 lines · On Tue, 17 Feb 2015 20:15:42 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 68 lines · Igor Mammedov
Quoted 59 lines · On Tue, 17 Feb 2015 17:35:55 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 42 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 4 ---- include/hw/acpi/aml-build.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)hw/acpi/aml-build.c +27
-0@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* +* ACPI 1.0b: 16.2.1 Top Level AML +* 5.2.3 System Description Table Header +* +* ACPI 5.0: 20.2.1 Table and Table Header Encoding +*/ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision) +{ +int len; +Aml *var =aml_alloc (); + var->block_flags =AML_DEF_BLOCK ; + +assert (strlen (signature) ==4 ); +g_array_append_vals (var->buf, signature,4 ); +build_append_value (var->buf,0 ,4 );/* Length place holder */ +build_append_byte (var->buf, revision); +build_append_byte (var->buf,0 );/* place holder for Checksum */ + + len =strlen (oem_id); +assert (len <=6 ); +g_array_append_vals (var->buf, oem_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,6 - len); +hw/acpi/aml-build.c void aml_append(Aml *parent_ctx, Aml *child) · line 374
Quoted 10 lines
hw/acpi/aml-build.c +10
-0+ len =strlen (oem_table_id); +assert (len <=8 ); +g_array_append_vals (var->buf, oem_table_id, len); +g_array_append_vals (var->buf,"\0\0\0\0\0\0\0\0" ,8 - len); + +build_append_value (var->buf, oem_revision,4 ); +build_append_value (var->buf, creator_id,4 ); +build_append_value (var->buf, creator_revision,4 ); + +return var;Please don't do this.
First, this is not a definition block encoding, so name is wrong.Quoted 6 lines
Second, we already have functions to fill in headers. So just call them.
Filling structures byte by byte is unreadable - I know ACPI spec often makes us do this but when it doesn't, we should not do it.
Quoted 6 lines
it does, in ACPI 5.1,
20.2.1 Table and Table Header Encoding
AMLCode := DefBlockHeader TermList
DefBlockHeader := TableSignature TableLength SpecCompliance CheckSum OemID OemTableID OemRevision CreatorID CreatorRevisionQuoted 4 lines
So spec explains it very badly, but these all are fixed width fields.
Filling them in usingadd_bytejust makes for hard to read code.
Quoted 7 lines
If it were only
add_byte, I'd agree but it basically composes by whole fields and in this particular case is easy to verify just by looking to spec, just like the rest of AML terms does.
And one doesn't have to care about endianness becausebuild_append_value()packs integer fields as expected by spec as opposed to using C struct-s.
things like
assert(len <= 8); g_array_append_vals(var->buf, oem_table_id, len); g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
are kind of ugly, are they not? 8 is repeated 3 times here, and you need to go look at spec to figure out what 8 stands for.
Besides, we aren't yet getting rid of build_header, are we? How about this, we get rest of this code in, then work on rewriting build_header everywhere?
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Pls keep using
build_headerfor now.Quoted 46 lines
hw/acpi/aml-build.c +1
-0+}hw/i386/acpi-build.c +0
-4@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info) NULL); } -#define ACPI_BUILD_APPNAME "Bochs" -#define ACPI_BUILD_APPNAME6 "BOCHS " -#define ACPI_BUILD_APPNAME4 "BXPC" -#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"include/hw/acpi/aml-build.h +10
-0@@ -6,6 +6,10 @@#include "qemu/compiler.h" #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" +#define ACPI_BUILD_APPNAME "Bochs" +#define ACPI_BUILD_APPNAME6 "BOCHS " +#define ACPI_BUILD_APPNAME4 "BXPC" +#define ACPI_BUILD_APPNAME4_HEX 0x43505842 typedef enum { AML_HELPER = 0,@@ -65,6 +69,12 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_def_block (const char *signature,uint8_t revision, +const char *oem_id,const char *oem_table_id, +uint32_t oem_revision,uint32_t creator_id, +uint32_t creator_revision); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);Signature · 1 line
1.8.3.1
PATCH v3 6/52 pc: acpi-build: use aml_def_block() for declaring SSDT table
In reply to Igor Mammedovit replaces prebuilt SSDT table header template copying/patching with AML API
--- hw/i386/acpi-build.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
hw/i386/acpi-build.c +16 -10
@@ -816,15 +816,15 @@ static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size) }static void -build_ssdt (GArray *table_data,GArray *linker, +build_ssdt (Aml *table_data,AcpiCpuInfo *cpu,AcpiPmInfo *pm,AcpiMiscInfo *misc,PcPciInfo *pci,PcGuestInfo *guest_info) {MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -int ssdt_start = table_data->len;uint8_t *ssdt_ptr; +Aml *ssdt;int i;/* The current AML generator can cover the APIC ID range [0..255],
@@ -832,9 +832,17 @@ build_ssdt(GArray *table_data, GArray *linker,QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 );g_assert (acpi_cpus <=ACPI_CPU_HOTPLUG_ID_LIMIT ); -/* Copy header and patch values in the S3_ / S4_ / S5_ packages */ - ssdt_ptr =acpi_data_push (table_data,sizeof (ssdp_misc_aml)); -memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); +/* Init SSDT Definition Block */ + ssdt =aml_def_block ("SSDT" ,1 ,ACPI_BUILD_APPNAME6 , +ACPI_BUILD_APPNAME4 ,1 , +ACPI_BUILD_APPNAME4_HEX ,1 ); + +/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */ +acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); + ssdt_ptr = (uint8_t *)ssdt->buf->data; +memcpy (ssdt_ptr +sizeof (AcpiTableHeader), + ssdp_misc_aml +sizeof (AcpiTableHeader), +sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader));if (pm->s3_disabled) { ssdt_ptr[acpi_s3_name[0 ]] ='X' ; }
@@ -944,13 +952,11 @@ build_ssdt(GArray *table_data, GArray *linker, } }build_package (sb_scope, op); -build_append_array (table_data, sb_scope); +build_append_array (ssdt->buf, sb_scope);build_free_array (sb_scope); } -build_header (linker, table_data, - (void *)(table_data->data + ssdt_start), -"SSDT" , table_data->len - ssdt_start,1 ); +aml_append (table_data, ssdt); } static void
@@ -1352,7 +1358,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) ssdt = tables_blob->len;acpi_add_table (table_offsets, tables_blob); -build_ssdt (tables_blob, tables->linker, &cpu, &pm, &misc, &pci, +build_ssdt (tables->table_data, &cpu, &pm, &misc, &pci, guest_info); aml_len += tables_blob->len - ssdt;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table
Quoted 4 lines · Igor Mammedov
it replaces prebuilt SSDT table header template copying/patching with AML API
Signed-off-by Igor Mammedov <[email protected]>
I note that this changed the SSDT signature in random ways, for example, it used to be named BXPCSSDT, now it's BXPC.
Pls keep using build_header, this problem will go away then.
Quoted 74 lines
--- hw/i386/acpi-build.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)hw/i386/acpi-build.c +16
-10@@ -816,15 +816,15 @@ static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size) }static void -build_ssdt (GArray *table_data,GArray *linker, +build_ssdt (Aml *table_data,AcpiCpuInfo *cpu,AcpiPmInfo *pm,AcpiMiscInfo *misc,PcPciInfo *pci,PcGuestInfo *guest_info) {MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -int ssdt_start = table_data->len;uint8_t *ssdt_ptr; +Aml *ssdt;int i;/* The current AML generator can cover the APIC ID range [0..255], @@ -832,9 +832,17 @@ build_ssdt(GArray *table_data, GArray *linker,QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 );g_assert (acpi_cpus <=ACPI_CPU_HOTPLUG_ID_LIMIT ); -/* Copy header and patch values in the S3_ / S4_ / S5_ packages */ - ssdt_ptr =acpi_data_push (table_data,sizeof (ssdp_misc_aml)); -memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); +/* Init SSDT Definition Block */ + ssdt =aml_def_block ("SSDT" ,1 ,ACPI_BUILD_APPNAME6 , +ACPI_BUILD_APPNAME4 ,1 , +ACPI_BUILD_APPNAME4_HEX ,1 ); + +/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */ +acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); + ssdt_ptr = (uint8_t *)ssdt->buf->data; +memcpy (ssdt_ptr +sizeof (AcpiTableHeader), + ssdp_misc_aml +sizeof (AcpiTableHeader), +sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader));if (pm->s3_disabled) { ssdt_ptr[acpi_s3_name[0 ]] ='X' ; }@@ -944,13 +952,11 @@ build_ssdt(GArray *table_data, GArray *linker, } }build_package (sb_scope, op); -build_append_array (table_data, sb_scope); +build_append_array (ssdt->buf, sb_scope);build_free_array (sb_scope); } -build_header (linker, table_data, - (void *)(table_data->data + ssdt_start), -"SSDT" , table_data->len - ssdt_start,1 ); +aml_append (table_data, ssdt); } static void@@ -1352,7 +1358,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) ssdt = tables_blob->len;acpi_add_table (table_offsets, tables_blob); -build_ssdt (tables_blob, tables->linker, &cpu, &pm, &misc, &pci, +build_ssdt (tables->table_data, &cpu, &pm, &misc, &pci, guest_info); aml_len += tables_blob->len - ssdt;Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table
Quoted 10 lines · On Tue, 17 Feb 2015 17:42:00 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Igor Mammedov
it replaces prebuilt SSDT table header template copying/patching with AML API
Signed-off-by Igor Mammedov <[email protected]>I note that this changed the SSDT signature in random ways, for example, it used to be named BXPCSSDT, now it's BXPC.
Pls keep using
build_header, this problem will go away then.
[...]
Quoted 3 lines
hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 837
Quoted 3 lines
hw/i386/acpi-build.c +3
-0+/* Init SSDT Definition Block */ + ssdt = aml_def_block("SSDT", 1, ACPI_BUILD_APPNAME6, + ACPI_BUILD_APPNAME4, 1,
I've missed that build_header() composes oem_table_id implicitly by merging table signature and ACPI_BUILD_APPNAME4.
following should fix issue:
- ACPI_BUILD_APPNAME4, 1,
+ "BXPCSSDT", 1,
Quoted 1 line
Quoted 1 line
+
ACPI_BUILD_APPNAME4_HEX, 1);
Re: [Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table
Quoted 21 lines · Igor Mammedov
Quoted 10 lines · On Tue, 17 Feb 2015 17:42:00 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Igor Mammedov
it replaces prebuilt SSDT table header template copying/patching with AML API
Signed-off-by Igor Mammedov <[email protected]>I note that this changed the SSDT signature in random ways, for example, it used to be named BXPCSSDT, now it's BXPC.
Pls keep using
build_header, this problem will go away then.[...]
Quoted 3 lines
hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 837
Quoted 3 lines
hw/i386/acpi-build.c +3
-0+/* Init SSDT Definition Block */ + ssdt = aml_def_block("SSDT", 1, ACPI_BUILD_APPNAME6, + ACPI_BUILD_APPNAME4, 1,I've missed that
build_header()composesoem_table_idimplicitly by merging table signature andACPI_BUILD_APPNAME4.following should fix issue:
Review
Quoted 2 lines
(quoted diff) +1
-1- ACPI_BUILD_APPNAME4, 1, + "BXPCSSDT", 1,
True but that's the result of code duplication.
Let's reuse build_header at step 1,
and in step 2, we'll replace it with something
else everywhere.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
ACPI_BUILD_APPNAME4_HEX, 1);
PATCH v3 7/52 acpi: add aml_scope() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 20 ++++++++++++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 21 insertions(+)
hw/acpi/aml-build.c +20 -0
@@ -259,6 +259,15 @@ static Aml *aml_alloc(void)return var; } +static Aml *aml_bundle (uint8_t op,AmlBlockFlags flags) +{ +Aml *var =aml_alloc (); + + var->op = op; + var->block_flags = flags; +return var; +} +static void aml_free (gpointer data) {Aml *var = data;
@@ -373,3 +382,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,return var; } + +/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */ +Aml *aml_scope (const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_bundle (0x10 /* ScopeOp */ ,AML_PACKAGE ); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -74,6 +74,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision, const char *oem_id, const char *oem_table_id, uint32_t oem_revision, uint32_t creator_id, uint32_t creator_revision); +Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 8/52 pc: acpi-build: use aml_scope() for \_SB scope
In reply to Igor Mammedovprepares for incremental conversion of SSDT contents to AML API
--- hw/i386/acpi-build.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)
hw/i386/acpi-build.c +12 -17
@@ -824,7 +824,7 @@ build_ssdt(Aml *table_data,uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit;uint8_t *ssdt_ptr; -Aml *ssdt; +Aml *ssdt, *sb_scope;int i;/* The current AML generator can cover the APIC ID range [0..255],
@@ -861,15 +861,11 @@ build_ssdt(Aml *table_data,ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_mctrl_nr_slots[0 ],32 , nr_mem); + sb_scope =aml_scope ("_SB" ); { -GArray *sb_scope =build_alloc_array (); -uint8_t op =0x10 ;/* ScopeOp */ - -build_append_namestring (sb_scope,"_SB" ); -/* build Processor object for each processor */ for (i =0 ; i < acpi_cpus; i++) { -uint8_t *proc =acpi_data_push (sb_scope,ACPI_PROC_SIZEOF ); +uint8_t *proc =acpi_data_push (sb_scope->buf,ACPI_PROC_SIZEOF );memcpy (proc,ACPI_PROC_AML ,ACPI_PROC_SIZEOF ); proc[ACPI_PROC_OFFSET_CPUHEX ] =acpi_get_hex (i >>4 ); proc[ACPI_PROC_OFFSET_CPUHEX +1 ] =acpi_get_hex (i);
@@ -881,11 +877,12 @@ build_ssdt(Aml *table_data,* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} */ /* Arg0 = Processor ID = APIC ID */ -build_append_notify_method (sb_scope,"NTFY" ,"CP%0.02X" , acpi_cpus); +build_append_notify_method (sb_scope->buf,"NTFY" , +"CP%0.02X" , acpi_cpus);/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */ -build_append_byte (sb_scope,0x08 );/* NameOp */ -build_append_namestring (sb_scope,"CPON" ); +build_append_byte (sb_scope->buf,0x08 );/* NameOp */ +build_append_namestring (sb_scope->buf,"CPON" ); {GArray *package =build_alloc_array ();
@@ -910,7 +907,7 @@ build_ssdt(Aml *table_data, }build_package (package, op); -build_append_array (sb_scope, package); +build_append_array (sb_scope->buf, package);build_free_array (package); }
@@ -919,7 +916,7 @@ build_ssdt(Aml *table_data,/* build memory devices */ for (i =0 ; i < nr_mem; i++) {char id[3 ]; -uint8_t *mem =acpi_data_push (sb_scope,ACPI_MEM_SIZEOF ); +uint8_t *mem =acpi_data_push (sb_scope->buf,ACPI_MEM_SIZEOF );snprintf (id,sizeof (id),"%02X" , i);memcpy (mem,ACPI_MEM_AML ,ACPI_MEM_SIZEOF );
@@ -930,7 +927,7 @@ build_ssdt(Aml *table_data,/* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) { * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ... */ -build_append_notify_method (sb_scope, +build_append_notify_method (sb_scope->buf,stringify (MEMORY_SLOT_NOTIFY_METHOD ),"MP%0.02X" , nr_mem); }
@@ -947,13 +944,11 @@ build_ssdt(Aml *table_data,if (bus) {/* Scan all PCI buses. Generate tables to support hotplug. */ -build_append_pci_bus_devices (sb_scope, bus, +build_append_pci_bus_devices (sb_scope->buf, bus, pm->pcihp_bridge_en); } } -build_package (sb_scope, op); -build_append_array (ssdt->buf, sb_scope); -build_free_array (sb_scope); +aml_append (ssdt, sb_scope); }aml_append (table_data, ssdt);
Signature · 1 line
1.8.3.1
PATCH v3 9/52 acpi: add aml_device() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 11 +++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 12 insertions(+)
hw/acpi/aml-build.c +11 -0
@@ -393,3 +393,14 @@ Aml *aml_scope(const char *name_format, ...)va_end (ap);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefDevice */ +Aml *aml_device (const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_bundle (0x82 /* DeviceOp */ ,AML_EXT_PACKAGE ); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -75,6 +75,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision, uint32_t oem_revision, uint32_t creator_id, uint32_t creator_revision);Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 10/52 acpi: add aml_method() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 9 +++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 10 insertions(+)
hw/acpi/aml-build.c +9 -0
@@ -383,6 +383,15 @@ Aml *aml_def_block(const char *signature, uint8_t revision,return var; } +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */ +Aml *aml_method (const char *name,int arg_count) +{ +Aml *var =aml_bundle (0x14 /* MethodOp */ ,AML_PACKAGE ); +build_append_namestring (var->buf,"%s" , name); +build_append_byte (var->buf, arg_count);/* MethodFlags: ArgCount */ +return var; +} +/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */ Aml *aml_scope (const char *name_format, ...) {
include/hw/acpi/aml-build.h +1 -0
@@ -76,6 +76,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision, uint32_t creator_revision);Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_method (const char *name,int arg_count);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 11/52 acpi: add aml_if() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -383,6 +383,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,return var; } +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ +Aml *aml_if (Aml *predicate) +{ +Aml *var =aml_bundle (0xA0 /* IfOp */ ,AML_PACKAGE ); +aml_append (var, predicate); +return var; +} +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */ Aml *aml_method (const char *name,int arg_count) {
include/hw/acpi/aml-build.h +1 -0
@@ -77,6 +77,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_method (const char *name,int arg_count); +Aml *aml_if (Aml *predicate);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 12/52 acpi: add aml_name() & aml_name_decl() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 32 ++++++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 4 ++++ 2 files changed, 36 insertions(+)
hw/acpi/aml-build.c +32 -0
@@ -259,6 +259,15 @@ static Aml *aml_alloc(void)return var; } +static Aml *aml_opcode (uint8_t op) +{ +Aml *var =aml_alloc (); + + var->op = op; + var->block_flags =AML_NON_BLOCK ; +return var; +} +static Aml *aml_bundle (uint8_t op,AmlBlockFlags flags) {Aml *var =aml_alloc ();
@@ -383,6 +392,29 @@ Aml *aml_def_block(const char *signature, uint8_t revision,return var; } +/* +* helper to construct NameString, which returns Aml object +* for using with aml_append or other aml_* terms +*/ +Aml *aml_name (const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_alloc (); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +return var; +} + +/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefName */ +Aml *aml_name_decl (const char *name,Aml *val) +{ +Aml *var =aml_opcode (0x08 /* NameOp */ ); +build_append_namestring (var->buf,"%s" , name); +aml_append (var, val); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +4 -0
@@ -69,6 +69,10 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* non block AML object primitives */ +Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_name_decl (const char *name,Aml *val); +/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision, const char *oem_id, const char *oem_table_id,
Signature · 1 line
1.8.3.1
PATCH v3 13/52 acpi: extend build_append_{value|int}() to support 64-bit values
In reply to Igor Mammedovit will be used for generating 64bit _CRS entries
--- hw/acpi/aml-build.c | 9 ++++++--- include/hw/acpi/aml-build.h | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-)
hw/acpi/aml-build.c +6 -3
@@ -219,7 +219,7 @@ void build_extop_package(GArray *package, uint8_t op)build_prepend_byte (package,0x5B );/* ExtOpPrefix */ } -void build_append_value (GArray *table,uint32_t value,int size) +void build_append_value (GArray *table,uint64_t value,int size) {int i;
@@ -229,7 +229,7 @@ void build_append_value(GArray *table, uint32_t value, int size) } } -void build_append_int (GArray *table,uint32_t value) +void build_append_int (GArray *table,uint64_t value) {if (value ==0x00 ) {build_append_byte (table,0x00 );/* ZeroOp */
@@ -241,9 +241,12 @@ void build_append_int(GArray *table, uint32_t value) }else if (value <=0xFFFF ) {build_append_byte (table,0x0B );/* WordPrefix */ build_append_value (table, value,2 ); - }else { + }else if (value <=0xFFFFFFFF ) {build_append_byte (table,0x0C );/* DWordPrefix */ build_append_value (table, value,4 ); + }else { +build_append_byte (table,0x0E );/* QWordPrefix */ +build_append_value (table, value,8 ); } }
include/hw/acpi/aml-build.h +2 -2
@@ -95,8 +95,8 @@ build_append_namestring(GArray *array, const char *format, ...);void build_prepend_package_length (GArray *package);void build_package (GArray *package,uint8_t op); -void build_append_value (GArray *table,uint32_t value,int size); -void build_append_int (GArray *table,uint32_t value); +void build_append_value (GArray *table,uint64_t value,int size); +void build_append_int (GArray *table,uint64_t value);void build_extop_package (GArray *package,uint8_t op);#endif
Signature · 1 line
1.8.3.1
PATCH v3 14/52 acpi: add aml_int() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 11 +++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 12 insertions(+)
hw/acpi/aml-build.c +11 -0
@@ -396,6 +396,17 @@ Aml *aml_def_block(const char *signature, uint8_t revision, }/* +* ACPI 1.0b: 16.2.3 Data Objects Encoding: +* encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp +*/ +Aml *aml_int (const uint64_t val) +{ +Aml *var =aml_alloc (); +build_append_int (var->buf, val); +return var; +} + +/* * helper to construct NameString, which returns Aml object * for using with aml_append or other aml_* terms */
include/hw/acpi/aml-build.h +1 -0
@@ -72,6 +72,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* non block AML object primitives */ Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_name_decl (const char *name,Aml *val); +Aml *aml_int (const uint64_t val);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 15/52 acpi: add aml_return() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -395,6 +395,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,return var; } +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefReturn */ +Aml *aml_return (Aml *val) +{ +Aml *var =aml_opcode (0xA4 /* ReturnOp */ ); +aml_append (var, val); +return var; +} +/* * ACPI 1.0b: 16.2.3 Data Objects Encoding: * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
include/hw/acpi/aml-build.h +1 -0
@@ -72,6 +72,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* non block AML object primitives */ Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_name_decl (const char *name,Aml *val); +Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val);/* Block AML object primitives */
Signature · 1 line
1.8.3.1
PATCH v3 16/52 acpi: add aml_arg() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 11 +++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 12 insertions(+)
hw/acpi/aml-build.c +11 -0
@@ -437,6 +437,17 @@ Aml *aml_name_decl(const char *name, Aml *val)return var; } +/* ACPI 1.0b: 16.2.6.1 Arg Objects Encoding */ +Aml *aml_arg (int pos) +{ +Aml *var; +uint8_t op =0x68 /* ARG0 op */ + pos; + +assert (pos <=6 ); + var =aml_opcode (op); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -74,6 +74,7 @@ Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_name_decl (const char *name,Aml *val);Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val); +Aml *aml_arg (int pos);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 17/52 acpi: add aml_store() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 9 +++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 10 insertions(+)
hw/acpi/aml-build.c +9 -0
@@ -448,6 +448,15 @@ Aml *aml_arg(int pos)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefStore */ +Aml *aml_store (Aml *val,Aml *target) +{ +Aml *var =aml_opcode (0x70 /* StoreOp */ ); +aml_append (var, val); +aml_append (var, target); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -75,6 +75,7 @@ Aml *aml_name_decl(const char *name, Aml *val);Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val);Aml *aml_arg (int pos); +Aml *aml_store (Aml *val,Aml *target);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 18/52 acpi: add aml_and() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -457,6 +457,16 @@ Aml *aml_store(Aml *val, Aml *target)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAnd */ +Aml *aml_and (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x7B /* AndOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +build_append_int (var->buf,0x00 /* NullNameOp */ ); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -76,6 +76,7 @@ Aml *aml_return(Aml *val);Aml *aml_int (const uint64_t val);Aml *aml_arg (int pos);Aml *aml_store (Aml *val,Aml *target); +Aml *aml_and (Aml *arg1,Aml *arg2);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 19/52 acpi: add aml_notify() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 9 +++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 10 insertions(+)
hw/acpi/aml-build.c +9 -0
@@ -467,6 +467,15 @@ Aml *aml_and(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */ +Aml *aml_notify (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x86 /* NotifyOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -77,6 +77,7 @@ Aml *aml_int(const uint64_t val);Aml *aml_arg (int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2); +Aml *aml_notify (Aml *arg1,Aml *arg2);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 20/52 acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 4 ++++ 2 files changed, 46 insertions(+)
hw/acpi/aml-build.c +42 -0
@@ -476,6 +476,48 @@ Aml *aml_notify(Aml *arg1, Aml *arg2)return var; } +/* helper to call method with 1 argument */ +Aml *aml_call1 (const char *method,Aml *arg1) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +return var; +} + +/* helper to call method with 2 arguments */ +Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +aml_append (var, arg2); +return var; +} + +/* helper to call method with 3 arguments */ +Aml *aml_call3 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +aml_append (var, arg2); +aml_append (var, arg3); +return var; +} + +/* helper to call method with 4 arguments */ +Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +aml_append (var, arg2); +aml_append (var, arg3); +aml_append (var, arg4); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +4 -0
@@ -78,6 +78,10 @@ Aml *aml_arg(int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2);Aml *aml_notify (Aml *arg1,Aml *arg2); +Aml *aml_call1 (const char *method,Aml *arg1); +Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2); +Aml *aml_call3 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3); +Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 21/52 pc: acpi-build: drop template patching and create PCI bus tree dynamically
In reply to Igor MammedovReplace 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.
--- hw/i386/Makefile.objs | 6 +- hw/i386/acpi-build.c | 207 +++++++++++--------------------- hw/i386/ssdt-pcihp.dsl | 100 ---------------- hw/i386/ssdt-pcihp.hex.generated | 251 --------------------------------------- 4 files changed, 72 insertions(+), 492 deletions(-) delete mode 100644 hw/i386/ssdt-pcihp.dsl delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
hw/i386/Makefile.objs +2 -4
@@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ - hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \ - hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \ - hw/i386/ssdt-tpm.hex + hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ + hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \ ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +70 -137
298 lines not on this page · raw message
hw/i386/ssdt-pcihp.dsl deleted +0 -100
100 lines not on this page · raw message
hw/i386/ssdt-pcihp.hex.generated deleted +0 -251
251 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
Quoted 8 lines · Igor Mammedov
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 <[email protected]>
Some comments below, this looks nice.
However, something strange is going on.
This looks like it should produce identical code to what was there, but in fact your previous patch pc: acpi-build: simplify PCI bus tree generation changes SSDT, then this patch changes it back to what it was.
I'm confused by this. Can't refactoring be done without changing the output back and forth, somehow?
Quoted 213 lines
--- hw/i386/Makefile.objs | 6 +- hw/i386/acpi-build.c | 207 +++++++++++--------------------- hw/i386/ssdt-pcihp.dsl | 100 ---------------- hw/i386/ssdt-pcihp.hex.generated | 251 --------------------------------------- 4 files changed, 72 insertions(+), 492 deletions(-) delete mode 100644 hw/i386/ssdt-pcihp.dsl delete mode 100644 hw/i386/ssdt-pcihp.hex.generatedhw/i386/Makefile.objs +2
-4@@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ - hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \ - hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \ - hw/i386/ssdt-tpm.hex + hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ + hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \ ; then echo "$(2)"; else echo "$(3)"; fi ;)hw/i386/acpi-build.c +30
-98@@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start) -/* 0x5B 0x82 DeviceOp PkgLength NameString */ -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1) -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start) -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start) -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start) - -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1) -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start) - -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1) -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start) -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start) -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start) - -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1) -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start) -#include "hw/i386/ssdt-mem.hex" /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */ @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_SSDT_HEADER_LENGTH 36#include "hw/i386/ssdt-misc.hex" -#include "hw/i386/ssdt-pcihp.hex" #include "hw/i386/ssdt-tpm.hex" static void@@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,build_append_and_cleanup_method (device, method); } -static void patch_pcihp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIHP_OFFSET_ID ] = slot; - ssdt_ptr[ACPI_PCIHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcinohp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcivga (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR +2 ] = slot; -} - -static void patch_pciqxl (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR +2 ] = slot; -} -/* Assign BSEL property to all buses. In the future, this can be changed * to only assign to buses that support hotplug. */ @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void) } } -static void build_append_pcihp_notify_entry (GArray *method,int slot) +static void build_append_pcihp_notify_entry (Aml *method,int slot) { -GArray *ifctx; +Aml *if_ctx; +int32_t devfn =PCI_DEVFN (slot,0 ); - ifctx =build_alloc_array (); -build_append_byte (ifctx,0x7B );/* AndOp */ -build_append_byte (ifctx,0x68 );/* Arg0Op */ -build_append_int (ifctx,0x1U << slot); -build_append_byte (ifctx,0x00 );/* NullName */ -build_append_byte (ifctx,0x86 );/* NotifyOp */ -build_append_namestring (ifctx,"S%.02X" ,PCI_DEVFN (slot,0 )); -build_append_byte (ifctx,0x69 );/* Arg1Op */ - -/* Pack it up */ -build_package (ifctx,0xA0 /* IfOp */ ); -build_append_array (method, ifctx); -build_free_array (ifctx); + if_ctx =aml_if (aml_and (aml_arg (0 ),aml_int (0x1U << slot))); +aml_append (if_ctx,aml_notify (aml_name ("S%.02X" , devfn),aml_arg (1 ))); +aml_append (method, if_ctx); } -static void build_append_pci_bus_devices (GArray *parent_scope,PCIBus *bus, +static void build_append_pci_bus_devices (Aml *parent_scope,PCIBus *bus,bool pcihp_bridge_en) { -GArray *bus_table =build_alloc_array (); -GArray *method =NULL ; +Aml *dev, *notify_method, *method;QObject *bsel;PCIBus *sec;int i; -if (bus->parent_dev) { -build_append_namestring (bus_table,"S%.02X_" , bus->parent_dev->devfn); - }else { -build_append_namestring (bus_table,"PCI0" ); - } - bsel =object_property_get_qobject (OBJECT (bus),ACPI_PCIHP_PROP_BSEL ,NULL );if (bsel) { -build_append_byte (bus_table,0x08 );/* NameOp */ -build_append_namestring (bus_table,"BSEL" ); -build_append_int (bus_table,qint_get_int (qobject_to_qint (bsel))); - method =build_alloc_method ("DVNT" ,2 ); +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); + +aml_append (parent_scope,aml_name_decl ("BSEL" ,aml_int (bsel_val))); + notify_method =aml_method ("DVNT" ,2 ); }for (i =0 ; i <ARRAY_SIZE (bus->devices); i +=PCI_FUNC_MAX ) {@@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (!pdev) {if (bsel) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); - -build_append_pcihp_notify_entry (method, slot); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method); +aml_append (parent_scope, dev); + +build_append_pcihp_notify_entry (notify_method, slot); }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +aml_append (parent_scope, dev); }continue ; }@@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, bridge_in_acpi = pc->is_bridge && pcihp_bridge_en && !DEVICE (pdev)->hotplugged; + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +if (pc->class_id ==PCI_CLASS_DISPLAY_VGA ) { +int s3d =0 ;if (object_dynamic_cast (OBJECT (pdev),"qxl-vga" )) { - void *pcihp = acpi_data_push(bus_table,
hw/i386/acpi-build.c static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, · line 663
Quoted 10 lines
hw/i386/acpi-build.c +1
-8- ACPI_PCIQXL_SIZEOF); -memcpy (pcihp,ACPI_PCIQXL_AML ,ACPI_PCIQXL_SIZEOF ); -patch_pciqxl (slot, pcihp); - }else { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCIVGA_SIZEOF ); -memcpy (pcihp,ACPI_PCIVGA_AML ,ACPI_PCIVGA_SIZEOF ); -patch_pcivga (slot, pcihp); + s3d =3 ; }
I dislike this style, where 0 is set, then over-written. Please do
if (cond) {
s = 3;
} else {
s = 0;
}Quoted 222 lines
hw/i386/acpi-build.c +39
-31+ + method =aml_method ("_S1D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S2D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S3D" ,0 ); +aml_append (method,aml_return (aml_int (s3d))); +aml_append (dev, method); }else if (dc->hotpluggable && !bridge_in_acpi) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); + + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method);if (bsel) { -build_append_pcihp_notify_entry (method, slot); +build_append_pcihp_notify_entry (notify_method, slot); } }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); -/* When hotplug for bridges is enabled, bridges that are * described in ACPI separately aren't themselves hot-pluggable. * Hotplugged bridges *are* hot-pluggable. @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (bridge_in_acpi) {PCIBus *sec_bus =pci_bridge_get_sec_bus (PCI_BRIDGE (pdev)); -build_append_pci_bus_devices (bus_table, sec_bus, - pcihp_bridge_en); +build_append_pci_bus_devices (dev, sec_bus, pcihp_bridge_en); } } +aml_append (parent_scope, dev); }if (bsel) { -build_append_and_cleanup_method (bus_table, method); +aml_append (parent_scope, notify_method); }/* Append PCNT method to notify about events on local and child buses. * Add unconditionally for root since DSDT expects it. */ - method =build_alloc_method ("PCNT" ,0 ); + method =aml_method ("PCNT" ,0 );/* If bus supports hotplug select it and notify about local events */ if (bsel) { -build_append_byte (method,0x70 );/* StoreOp */ -build_append_int (method,qint_get_int (qobject_to_qint (bsel))); -build_append_namestring (method,"BNUM" ); -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCIU" ); -build_append_int (method,1 );/* Device Check */ -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCID" ); -build_append_int (method,3 );/* Eject Request */ +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); +aml_append (method,aml_store (aml_int (bsel_val),aml_name ("BNUM" ))); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCIU" ),aml_int (1 )/* Device Check */ ) + ); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCID" ),aml_int (3 )/* Eject Request */ ) + ); }/* Notify about child bus events in any case */ if (pcihp_bridge_en) { QLIST_FOREACH(sec, &bus->child, sibling) { -build_append_namestring (method,"^S%.02X.PCNT" , - sec->parent_dev->devfn); +int32_t devfn = sec->parent_dev->devfn; + +aml_append (method,aml_name ("^S%.02X.PCNT" , devfn)); } } - -build_append_and_cleanup_method (bus_table, method); - -build_package (bus_table,0x10 );/* ScopeOp */ -build_append_array (parent_scope, bus_table); -build_free_array (bus_table); +aml_append (parent_scope, method); }static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size)@@ -943,9 +875,10 @@ build_ssdt(Aml *table_data, }if (bus) { +Aml *scope =aml_scope ("PCI0" );/* Scan all PCI buses. Generate tables to support hotplug. */ -build_append_pci_bus_devices (sb_scope->buf, bus, - pm->pcihp_bridge_en); +build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +aml_append (sb_scope, scope); } }aml_append (ssdt, sb_scope);hw/i386/ssdt-pcihp.dsl deleted +0
-100@@ -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 - } - } - } -}hw/i386/ssdt-pcihp.hex.generated deleted +0
-0
hw/i386/ssdt-pcihp.hex.generated
Quoted 1 line
hw/i386/ssdt-pcihp.hex.generated deleted +0
-1--- a/hw/i386/ssdt-pcihp.hex.generated
Pls don't send generated file patches.
Just note it should be removed in comment, I'll do it.
Quoted 255 lines
+++
/dev/nullhw/i386/ssdt-pcihp.hex.generated deleted +0
-251@@ -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 -};Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
Quoted 19 lines · On Tue, 17 Feb 2015 20:39:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 8 lines · Igor Mammedov
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 <[email protected]>Some comments below, this looks nice.
However, something strange is going on.
This looks like it should produce identical code to what was there, but in fact your previous patch pc: acpi-build: simplify PCI bus tree generation changes SSDT, then this patch changes it back to what it was.
Quoted 2 lines
I'm confused by this. Can't refactoring be done without changing the output back and forth, somehow?
Probably can, I'll check if it's feasible.
Quoted 227 lines
Quoted 214 lines
--- hw/i386/Makefile.objs | 6 +- hw/i386/acpi-build.c | 207 +++++++++++--------------------- hw/i386/ssdt-pcihp.dsl | 100 ---------------- hw/i386/ssdt-pcihp.hex.generated | 251 --------------------------------------- 4 files changed, 72 insertions(+), 492 deletions(-) delete mode 100644 hw/i386/ssdt-pcihp.dsl delete mode 100644 hw/i386/ssdt-pcihp.hex.generatedhw/i386/Makefile.objs +2
-4@@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ - hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \ - hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \ - hw/i386/ssdt-tpm.hex + hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ + hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \ ; then echo "$(2)"; else echo "$(3)"; fi ;)hw/i386/acpi-build.c +30
-98@@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start) -/* 0x5B 0x82 DeviceOp PkgLength NameString */ -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1) -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start) -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start) -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start) - -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1) -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start) - -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1) -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start) -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start) -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start) - -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1) -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start) -#include "hw/i386/ssdt-mem.hex" /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */ @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_SSDT_HEADER_LENGTH 36#include "hw/i386/ssdt-misc.hex" -#include "hw/i386/ssdt-pcihp.hex" #include "hw/i386/ssdt-tpm.hex" static void@@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,build_append_and_cleanup_method (device, method); } -static void patch_pcihp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIHP_OFFSET_ID ] = slot; - ssdt_ptr[ACPI_PCIHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcinohp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcivga (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR +2 ] = slot; -} - -static void patch_pciqxl (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR +2 ] = slot; -} -/* Assign BSEL property to all buses. In the future, this can be changed * to only assign to buses that support hotplug. */ @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void) } } -static void build_append_pcihp_notify_entry (GArray *method,int slot) +static void build_append_pcihp_notify_entry (Aml *method,int slot) { -GArray *ifctx; +Aml *if_ctx; +int32_t devfn =PCI_DEVFN (slot,0 ); - ifctx =build_alloc_array (); -build_append_byte (ifctx,0x7B );/* AndOp */ -build_append_byte (ifctx,0x68 );/* Arg0Op */ -build_append_int (ifctx,0x1U << slot); -build_append_byte (ifctx,0x00 );/* NullName */ -build_append_byte (ifctx,0x86 );/* NotifyOp */ -build_append_namestring (ifctx,"S%.02X" ,PCI_DEVFN (slot,0 )); -build_append_byte (ifctx,0x69 );/* Arg1Op */ - -/* Pack it up */ -build_package (ifctx,0xA0 /* IfOp */ ); -build_append_array (method, ifctx); -build_free_array (ifctx); + if_ctx =aml_if (aml_and (aml_arg (0 ),aml_int (0x1U << slot))); +aml_append (if_ctx,aml_notify (aml_name ("S%.02X" , devfn),aml_arg (1 ))); +aml_append (method, if_ctx); } -static void build_append_pci_bus_devices (GArray *parent_scope,PCIBus *bus, +static void build_append_pci_bus_devices (Aml *parent_scope,PCIBus *bus,bool pcihp_bridge_en) { -GArray *bus_table =build_alloc_array (); -GArray *method =NULL ; +Aml *dev, *notify_method, *method;QObject *bsel;PCIBus *sec;int i; -if (bus->parent_dev) { -build_append_namestring (bus_table,"S%.02X_" , bus->parent_dev->devfn); - }else { -build_append_namestring (bus_table,"PCI0" ); - } - bsel =object_property_get_qobject (OBJECT (bus),ACPI_PCIHP_PROP_BSEL ,NULL );if (bsel) { -build_append_byte (bus_table,0x08 );/* NameOp */ -build_append_namestring (bus_table,"BSEL" ); -build_append_int (bus_table,qint_get_int (qobject_to_qint (bsel))); - method =build_alloc_method ("DVNT" ,2 ); +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); + +aml_append (parent_scope,aml_name_decl ("BSEL" ,aml_int (bsel_val))); + notify_method =aml_method ("DVNT" ,2 ); }for (i =0 ; i <ARRAY_SIZE (bus->devices); i +=PCI_FUNC_MAX ) {@@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (!pdev) {if (bsel) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); - -build_append_pcihp_notify_entry (method, slot); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method); +aml_append (parent_scope, dev); + +build_append_pcihp_notify_entry (notify_method, slot); }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +aml_append (parent_scope, dev); }continue ; }@@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, bridge_in_acpi = pc->is_bridge && pcihp_bridge_en && !DEVICE (pdev)->hotplugged; + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +if (pc->class_id ==PCI_CLASS_DISPLAY_VGA ) { +int s3d =0 ;if (object_dynamic_cast (OBJECT (pdev),"qxl-vga" )) { - void *pcihp = acpi_data_push(bus_table,hw/i386/acpi-build.c static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, · line 663
Quoted 10 lines
hw/i386/acpi-build.c +1
-8- ACPI_PCIQXL_SIZEOF); -memcpy (pcihp,ACPI_PCIQXL_AML ,ACPI_PCIQXL_SIZEOF ); -patch_pciqxl (slot, pcihp); - }else { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCIVGA_SIZEOF ); -memcpy (pcihp,ACPI_PCIVGA_AML ,ACPI_PCIVGA_SIZEOF ); -patch_pcivga (slot, pcihp); + s3d =3 ; }I dislike this style, where 0 is set, then over-written. Please do
Quoted 5 lines
if (cond) {
s = 3;
} else {
s = 0;
}sure
Quoted 484 lines
Quoted 224 lines
hw/i386/acpi-build.c +39
-31+ + method =aml_method ("_S1D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S2D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S3D" ,0 ); +aml_append (method,aml_return (aml_int (s3d))); +aml_append (dev, method); }else if (dc->hotpluggable && !bridge_in_acpi) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); + + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method);if (bsel) { -build_append_pcihp_notify_entry (method, slot); +build_append_pcihp_notify_entry (notify_method, slot); } }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); -/* When hotplug for bridges is enabled, bridges that are * described in ACPI separately aren't themselves hot-pluggable. * Hotplugged bridges *are* hot-pluggable. @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (bridge_in_acpi) {PCIBus *sec_bus =pci_bridge_get_sec_bus (PCI_BRIDGE (pdev)); -build_append_pci_bus_devices (bus_table, sec_bus, - pcihp_bridge_en); +build_append_pci_bus_devices (dev, sec_bus, pcihp_bridge_en); } } +aml_append (parent_scope, dev); }if (bsel) { -build_append_and_cleanup_method (bus_table, method); +aml_append (parent_scope, notify_method); }/* Append PCNT method to notify about events on local and child buses. * Add unconditionally for root since DSDT expects it. */ - method =build_alloc_method ("PCNT" ,0 ); + method =aml_method ("PCNT" ,0 );/* If bus supports hotplug select it and notify about local events */ if (bsel) { -build_append_byte (method,0x70 );/* StoreOp */ -build_append_int (method,qint_get_int (qobject_to_qint (bsel))); -build_append_namestring (method,"BNUM" ); -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCIU" ); -build_append_int (method,1 );/* Device Check */ -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCID" ); -build_append_int (method,3 );/* Eject Request */ +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); +aml_append (method,aml_store (aml_int (bsel_val),aml_name ("BNUM" ))); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCIU" ),aml_int (1 )/* Device Check */ ) + ); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCID" ),aml_int (3 )/* Eject Request */ ) + ); }/* Notify about child bus events in any case */ if (pcihp_bridge_en) { QLIST_FOREACH(sec, &bus->child, sibling) { -build_append_namestring (method,"^S%.02X.PCNT" , - sec->parent_dev->devfn); +int32_t devfn = sec->parent_dev->devfn; + +aml_append (method,aml_name ("^S%.02X.PCNT" , devfn)); } } - -build_append_and_cleanup_method (bus_table, method); - -build_package (bus_table,0x10 );/* ScopeOp */ -build_append_array (parent_scope, bus_table); -build_free_array (bus_table); +aml_append (parent_scope, method); }static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size)@@ -943,9 +875,10 @@ build_ssdt(Aml *table_data, }if (bus) { +Aml *scope =aml_scope ("PCI0" );/* Scan all PCI buses. Generate tables to support hotplug. */ -build_append_pci_bus_devices (sb_scope->buf, bus, - pm->pcihp_bridge_en); +build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +aml_append (sb_scope, scope); } }aml_append (ssdt, sb_scope);hw/i386/ssdt-pcihp.dsl deleted +0
-100@@ -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 - } - } - } -}hw/i386/ssdt-pcihp.hex.generated deleted +0
-0hw/i386/ssdt-pcihp.hex.generated
Quoted 1 line
hw/i386/ssdt-pcihp.hex.generated deleted +0
-1--- a/hw/i386/ssdt-pcihp.hex.generatedPls don't send generated file patches.
Just note it should be removed in comment, I'll do it.Quoted 255 lines
+++
/dev/nullhw/i386/ssdt-pcihp.hex.generated deleted +0
-251@@ -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 -};Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
In reply to Michael S. TsirkinQuoted 19 lines · On Tue, 17 Feb 2015 20:39:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 8 lines · Igor Mammedov
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 <[email protected]>Some comments below, this looks nice.
However, something strange is going on.
This looks like it should produce identical code to what was there, but in fact your previous patch pc: acpi-build: simplify PCI bus tree generation changes SSDT, then this patch changes it back to what it was.
Quoted 2 lines
I'm confused by this. Can't refactoring be done without changing the output back and forth, somehow?
just checked with make check ASL diff
if you you stop when applying patches on this patch and run make check you'll get a trivial diff:
@@ -153,7 +153,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
Method (NTFY, 2, NotSerialized)
{
- If (LEqual (Arg0, 0x00))
+ If (LEqual (Arg0, Zero))
{
Notify (CP00, Arg1)
}
@@ -168,7 +168,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS
Name (BSEL, Zero)
Device (S00)
{
- Name (_ADR, 0x00000000) // _ADR: Address
+ Name (_ADR, Zero) // _ADR: Address
}
Device (S10)which is result of switching to aml_int() which encodes Zero opcode instead of 0x00 ByteConst.
Quoted 717 lines
Quoted 214 lines
--- hw/i386/Makefile.objs | 6 +- hw/i386/acpi-build.c | 207 +++++++++++--------------------- hw/i386/ssdt-pcihp.dsl | 100 ---------------- hw/i386/ssdt-pcihp.hex.generated | 251 --------------------------------------- 4 files changed, 72 insertions(+), 492 deletions(-) delete mode 100644 hw/i386/ssdt-pcihp.dsl delete mode 100644 hw/i386/ssdt-pcihp.hex.generatedhw/i386/Makefile.objs +2
-4@@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ - hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \ - hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \ - hw/i386/ssdt-tpm.hex + hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ + hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \ ; then echo "$(2)"; else echo "$(3)"; fi ;)hw/i386/acpi-build.c +30
-98@@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start) -/* 0x5B 0x82 DeviceOp PkgLength NameString */ -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1) -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start) -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start) -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start) - -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1) -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start) - -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1) -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start) -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start) -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start) - -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1) -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start) -#include "hw/i386/ssdt-mem.hex" /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */ @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_SSDT_HEADER_LENGTH 36#include "hw/i386/ssdt-misc.hex" -#include "hw/i386/ssdt-pcihp.hex" #include "hw/i386/ssdt-tpm.hex" static void@@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,build_append_and_cleanup_method (device, method); } -static void patch_pcihp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIHP_OFFSET_ID ] = slot; - ssdt_ptr[ACPI_PCIHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcinohp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcivga (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR +2 ] = slot; -} - -static void patch_pciqxl (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR +2 ] = slot; -} -/* Assign BSEL property to all buses. In the future, this can be changed * to only assign to buses that support hotplug. */ @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void) } } -static void build_append_pcihp_notify_entry (GArray *method,int slot) +static void build_append_pcihp_notify_entry (Aml *method,int slot) { -GArray *ifctx; +Aml *if_ctx; +int32_t devfn =PCI_DEVFN (slot,0 ); - ifctx =build_alloc_array (); -build_append_byte (ifctx,0x7B );/* AndOp */ -build_append_byte (ifctx,0x68 );/* Arg0Op */ -build_append_int (ifctx,0x1U << slot); -build_append_byte (ifctx,0x00 );/* NullName */ -build_append_byte (ifctx,0x86 );/* NotifyOp */ -build_append_namestring (ifctx,"S%.02X" ,PCI_DEVFN (slot,0 )); -build_append_byte (ifctx,0x69 );/* Arg1Op */ - -/* Pack it up */ -build_package (ifctx,0xA0 /* IfOp */ ); -build_append_array (method, ifctx); -build_free_array (ifctx); + if_ctx =aml_if (aml_and (aml_arg (0 ),aml_int (0x1U << slot))); +aml_append (if_ctx,aml_notify (aml_name ("S%.02X" , devfn),aml_arg (1 ))); +aml_append (method, if_ctx); } -static void build_append_pci_bus_devices (GArray *parent_scope,PCIBus *bus, +static void build_append_pci_bus_devices (Aml *parent_scope,PCIBus *bus,bool pcihp_bridge_en) { -GArray *bus_table =build_alloc_array (); -GArray *method =NULL ; +Aml *dev, *notify_method, *method;QObject *bsel;PCIBus *sec;int i; -if (bus->parent_dev) { -build_append_namestring (bus_table,"S%.02X_" , bus->parent_dev->devfn); - }else { -build_append_namestring (bus_table,"PCI0" ); - } - bsel =object_property_get_qobject (OBJECT (bus),ACPI_PCIHP_PROP_BSEL ,NULL );if (bsel) { -build_append_byte (bus_table,0x08 );/* NameOp */ -build_append_namestring (bus_table,"BSEL" ); -build_append_int (bus_table,qint_get_int (qobject_to_qint (bsel))); - method =build_alloc_method ("DVNT" ,2 ); +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); + +aml_append (parent_scope,aml_name_decl ("BSEL" ,aml_int (bsel_val))); + notify_method =aml_method ("DVNT" ,2 ); }for (i =0 ; i <ARRAY_SIZE (bus->devices); i +=PCI_FUNC_MAX ) {@@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (!pdev) {if (bsel) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); - -build_append_pcihp_notify_entry (method, slot); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method); +aml_append (parent_scope, dev); + +build_append_pcihp_notify_entry (notify_method, slot); }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +aml_append (parent_scope, dev); }continue ; }@@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, bridge_in_acpi = pc->is_bridge && pcihp_bridge_en && !DEVICE (pdev)->hotplugged; + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +if (pc->class_id ==PCI_CLASS_DISPLAY_VGA ) { +int s3d =0 ;if (object_dynamic_cast (OBJECT (pdev),"qxl-vga" )) { - void *pcihp = acpi_data_push(bus_table,hw/i386/acpi-build.c static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, · line 663
Quoted 10 lines
hw/i386/acpi-build.c +1
-8- ACPI_PCIQXL_SIZEOF); -memcpy (pcihp,ACPI_PCIQXL_AML ,ACPI_PCIQXL_SIZEOF ); -patch_pciqxl (slot, pcihp); - }else { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCIVGA_SIZEOF ); -memcpy (pcihp,ACPI_PCIVGA_AML ,ACPI_PCIVGA_SIZEOF ); -patch_pcivga (slot, pcihp); + s3d =3 ; }I dislike this style, where 0 is set, then over-written. Please do
if (cond) { s = 3; } else { s = 0; }Quoted 222 lines
hw/i386/acpi-build.c +39
-31+ + method =aml_method ("_S1D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S2D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S3D" ,0 ); +aml_append (method,aml_return (aml_int (s3d))); +aml_append (dev, method); }else if (dc->hotpluggable && !bridge_in_acpi) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); + + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method);if (bsel) { -build_append_pcihp_notify_entry (method, slot); +build_append_pcihp_notify_entry (notify_method, slot); } }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); -/* When hotplug for bridges is enabled, bridges that are * described in ACPI separately aren't themselves hot-pluggable. * Hotplugged bridges *are* hot-pluggable. @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (bridge_in_acpi) {PCIBus *sec_bus =pci_bridge_get_sec_bus (PCI_BRIDGE (pdev)); -build_append_pci_bus_devices (bus_table, sec_bus, - pcihp_bridge_en); +build_append_pci_bus_devices (dev, sec_bus, pcihp_bridge_en); } } +aml_append (parent_scope, dev); }if (bsel) { -build_append_and_cleanup_method (bus_table, method); +aml_append (parent_scope, notify_method); }/* Append PCNT method to notify about events on local and child buses. * Add unconditionally for root since DSDT expects it. */ - method =build_alloc_method ("PCNT" ,0 ); + method =aml_method ("PCNT" ,0 );/* If bus supports hotplug select it and notify about local events */ if (bsel) { -build_append_byte (method,0x70 );/* StoreOp */ -build_append_int (method,qint_get_int (qobject_to_qint (bsel))); -build_append_namestring (method,"BNUM" ); -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCIU" ); -build_append_int (method,1 );/* Device Check */ -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCID" ); -build_append_int (method,3 );/* Eject Request */ +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); +aml_append (method,aml_store (aml_int (bsel_val),aml_name ("BNUM" ))); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCIU" ),aml_int (1 )/* Device Check */ ) + ); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCID" ),aml_int (3 )/* Eject Request */ ) + ); }/* Notify about child bus events in any case */ if (pcihp_bridge_en) { QLIST_FOREACH(sec, &bus->child, sibling) { -build_append_namestring (method,"^S%.02X.PCNT" , - sec->parent_dev->devfn); +int32_t devfn = sec->parent_dev->devfn; + +aml_append (method,aml_name ("^S%.02X.PCNT" , devfn)); } } - -build_append_and_cleanup_method (bus_table, method); - -build_package (bus_table,0x10 );/* ScopeOp */ -build_append_array (parent_scope, bus_table); -build_free_array (bus_table); +aml_append (parent_scope, method); }static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size)@@ -943,9 +875,10 @@ build_ssdt(Aml *table_data, }if (bus) { +Aml *scope =aml_scope ("PCI0" );/* Scan all PCI buses. Generate tables to support hotplug. */ -build_append_pci_bus_devices (sb_scope->buf, bus, - pm->pcihp_bridge_en); +build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +aml_append (sb_scope, scope); } }aml_append (ssdt, sb_scope);hw/i386/ssdt-pcihp.dsl deleted +0
-100@@ -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 - } - } - } -}hw/i386/ssdt-pcihp.hex.generated deleted +0
-0hw/i386/ssdt-pcihp.hex.generated
Quoted 1 line
hw/i386/ssdt-pcihp.hex.generated deleted +0
-1--- a/hw/i386/ssdt-pcihp.hex.generatedPls don't send generated file patches.
Just note it should be removed in comment, I'll do it.Quoted 255 lines
+++
/dev/nullhw/i386/ssdt-pcihp.hex.generated deleted +0
-251@@ -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 -};Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically
Quoted 48 lines · Igor Mammedov
Quoted 19 lines · On Tue, 17 Feb 2015 20:39:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 8 lines · Igor Mammedov
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 <[email protected]>Some comments below, this looks nice.
However, something strange is going on.
This looks like it should produce identical code to what was there, but in fact your previous patch pc: acpi-build: simplify PCI bus tree generation changes SSDT, then this patch changes it back to what it was.Quoted 2 lines
I'm confused by this. Can't refactoring be done without changing the output back and forth, somehow?
just checked with make check ASL diff
if you you stop when applying patches on this patch and run make check you'll get a trivial diff:(quoted diff) +2
-2@@ -153,7 +153,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS Method (NTFY, 2, NotSerialized) { - If (LEqual (Arg0, 0x00)) + If (LEqual (Arg0, Zero)) { Notify (CP00, Arg1) }@@ -168,7 +168,7 @@ DefinitionBlock ("tests/acpi-test-data/pc/SSDT.aml", "SSDT", 1, "BOCHS ", "BXPCS Name (BSEL, Zero) Device (S00) { - Name (_ADR, 0x00000000) // _ADR: Address + Name (_ADR, Zero) // _ADR: Address } Device (S10)
Quoted 2 lines
which is result of switching to
aml_int()which encodes Zero opcode instead of0x00ByteConst.
Right, but if you try before this patch, you see a huge diff. So this patch mostly cancels the changes you made with the previous pci rework.
Quoted 717 lines
Quoted 717 lines
Quoted 214 lines
--- hw/i386/Makefile.objs | 6 +- hw/i386/acpi-build.c | 207 +++++++++++--------------------- hw/i386/ssdt-pcihp.dsl | 100 ---------------- hw/i386/ssdt-pcihp.hex.generated | 251 --------------------------------------- 4 files changed, 72 insertions(+), 492 deletions(-) delete mode 100644 hw/i386/ssdt-pcihp.dsl delete mode 100644 hw/i386/ssdt-pcihp.hex.generatedhw/i386/Makefile.objs +2
-4@@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ - hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \ - hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \ - hw/i386/ssdt-tpm.hex + hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ + hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \ ; then echo "$(2)"; else echo "$(3)"; fi ;)hw/i386/acpi-build.c +30
-98@@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start) -/* 0x5B 0x82 DeviceOp PkgLength NameString */ -#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1) -#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start) -#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start) -#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start) -#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start) - -#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1) -#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start) -#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start) - -#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1) -#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start) -#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start) -#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start) - -#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1) -#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start) -#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start) -#include "hw/i386/ssdt-mem.hex" /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */ @@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_SSDT_HEADER_LENGTH 36#include "hw/i386/ssdt-misc.hex" -#include "hw/i386/ssdt-pcihp.hex" #include "hw/i386/ssdt-tpm.hex" static void@@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char *name,build_append_and_cleanup_method (device, method); } -static void patch_pcihp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIHP_OFFSET_ID ] = slot; - ssdt_ptr[ACPI_PCIHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcinohp (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR +2 ] = slot; -} - -static void patch_pcivga (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR +2 ] = slot; -} - -static void patch_pciqxl (int slot,uint8_t *ssdt_ptr) -{ -unsigned devfn =PCI_DEVFN (slot,0 ); - - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX ] =acpi_get_hex (devfn >>4 ); - ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX +1 ] =acpi_get_hex (devfn); - ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR +2 ] = slot; -} -/* Assign BSEL property to all buses. In the future, this can be changed * to only assign to buses that support hotplug. */ @@ -648,46 +587,30 @@ static void acpi_set_pci_info(void) } } -static void build_append_pcihp_notify_entry (GArray *method,int slot) +static void build_append_pcihp_notify_entry (Aml *method,int slot) { -GArray *ifctx; +Aml *if_ctx; +int32_t devfn =PCI_DEVFN (slot,0 ); - ifctx =build_alloc_array (); -build_append_byte (ifctx,0x7B );/* AndOp */ -build_append_byte (ifctx,0x68 );/* Arg0Op */ -build_append_int (ifctx,0x1U << slot); -build_append_byte (ifctx,0x00 );/* NullName */ -build_append_byte (ifctx,0x86 );/* NotifyOp */ -build_append_namestring (ifctx,"S%.02X" ,PCI_DEVFN (slot,0 )); -build_append_byte (ifctx,0x69 );/* Arg1Op */ - -/* Pack it up */ -build_package (ifctx,0xA0 /* IfOp */ ); -build_append_array (method, ifctx); -build_free_array (ifctx); + if_ctx =aml_if (aml_and (aml_arg (0 ),aml_int (0x1U << slot))); +aml_append (if_ctx,aml_notify (aml_name ("S%.02X" , devfn),aml_arg (1 ))); +aml_append (method, if_ctx); } -static void build_append_pci_bus_devices (GArray *parent_scope,PCIBus *bus, +static void build_append_pci_bus_devices (Aml *parent_scope,PCIBus *bus,bool pcihp_bridge_en) { -GArray *bus_table =build_alloc_array (); -GArray *method =NULL ; +Aml *dev, *notify_method, *method;QObject *bsel;PCIBus *sec;int i; -if (bus->parent_dev) { -build_append_namestring (bus_table,"S%.02X_" , bus->parent_dev->devfn); - }else { -build_append_namestring (bus_table,"PCI0" ); - } - bsel =object_property_get_qobject (OBJECT (bus),ACPI_PCIHP_PROP_BSEL ,NULL );if (bsel) { -build_append_byte (bus_table,0x08 );/* NameOp */ -build_append_namestring (bus_table,"BSEL" ); -build_append_int (bus_table,qint_get_int (qobject_to_qint (bsel))); - method =build_alloc_method ("DVNT" ,2 ); +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); + +aml_append (parent_scope,aml_name_decl ("BSEL" ,aml_int (bsel_val))); + notify_method =aml_method ("DVNT" ,2 ); }for (i =0 ; i <ARRAY_SIZE (bus->devices); i +=PCI_FUNC_MAX ) {@@ -699,15 +622,21 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (!pdev) {if (bsel) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); - -build_append_pcihp_notify_entry (method, slot); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method); +aml_append (parent_scope, dev); + +build_append_pcihp_notify_entry (notify_method, slot); }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +aml_append (parent_scope, dev); }continue ; }@@ -723,32 +652,40 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, bridge_in_acpi = pc->is_bridge && pcihp_bridge_en && !DEVICE (pdev)->hotplugged; + dev =aml_device ("S%.02X" ,PCI_DEVFN (slot,0 )); +aml_append (dev,aml_name_decl ("_ADR" ,aml_int (slot <<16 ))); +if (pc->class_id ==PCI_CLASS_DISPLAY_VGA ) { +int s3d =0 ;if (object_dynamic_cast (OBJECT (pdev),"qxl-vga" )) { - void *pcihp = acpi_data_push(bus_table,hw/i386/acpi-build.c static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus, · line 663
Quoted 10 lines
hw/i386/acpi-build.c +1
-8- ACPI_PCIQXL_SIZEOF); -memcpy (pcihp,ACPI_PCIQXL_AML ,ACPI_PCIQXL_SIZEOF ); -patch_pciqxl (slot, pcihp); - }else { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCIVGA_SIZEOF ); -memcpy (pcihp,ACPI_PCIVGA_AML ,ACPI_PCIVGA_SIZEOF ); -patch_pcivga (slot, pcihp); + s3d =3 ; }I dislike this style, where 0 is set, then over-written. Please do
if (cond) { s = 3; } else { s = 0; }Quoted 222 lines
hw/i386/acpi-build.c +39
-31+ + method =aml_method ("_S1D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S2D" ,0 ); +aml_append (method,aml_return (aml_int (0 ))); +aml_append (dev, method); + + method =aml_method ("_S3D" ,0 ); +aml_append (method,aml_return (aml_int (s3d))); +aml_append (dev, method); }else if (dc->hotpluggable && !bridge_in_acpi) { -void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (slot, pcihp); +aml_append (dev,aml_name_decl ("_SUN" ,aml_int (slot))); + + method =aml_method ("_EJ0" ,1 ); +aml_append (method, +aml_call2 ("PCEJ" ,aml_name ("BSEL" ),aml_name ("_SUN" )) + ); +aml_append (dev, method);if (bsel) { -build_append_pcihp_notify_entry (method, slot); +build_append_pcihp_notify_entry (notify_method, slot); } }else { -void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); -memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (slot, pcihp); -/* When hotplug for bridges is enabled, bridges that are * described in ACPI separately aren't themselves hot-pluggable. * Hotplugged bridges *are* hot-pluggable. @@ -756,47 +693,42 @@ static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,if (bridge_in_acpi) {PCIBus *sec_bus =pci_bridge_get_sec_bus (PCI_BRIDGE (pdev)); -build_append_pci_bus_devices (bus_table, sec_bus, - pcihp_bridge_en); +build_append_pci_bus_devices (dev, sec_bus, pcihp_bridge_en); } } +aml_append (parent_scope, dev); }if (bsel) { -build_append_and_cleanup_method (bus_table, method); +aml_append (parent_scope, notify_method); }/* Append PCNT method to notify about events on local and child buses. * Add unconditionally for root since DSDT expects it. */ - method =build_alloc_method ("PCNT" ,0 ); + method =aml_method ("PCNT" ,0 );/* If bus supports hotplug select it and notify about local events */ if (bsel) { -build_append_byte (method,0x70 );/* StoreOp */ -build_append_int (method,qint_get_int (qobject_to_qint (bsel))); -build_append_namestring (method,"BNUM" ); -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCIU" ); -build_append_int (method,1 );/* Device Check */ -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCID" ); -build_append_int (method,3 );/* Eject Request */ +int64_t bsel_val =qint_get_int (qobject_to_qint (bsel)); +aml_append (method,aml_store (aml_int (bsel_val),aml_name ("BNUM" ))); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCIU" ),aml_int (1 )/* Device Check */ ) + ); +aml_append (method, +aml_call2 ("DVNT" ,aml_name ("PCID" ),aml_int (3 )/* Eject Request */ ) + ); }/* Notify about child bus events in any case */ if (pcihp_bridge_en) { QLIST_FOREACH(sec, &bus->child, sibling) { -build_append_namestring (method,"^S%.02X.PCNT" , - sec->parent_dev->devfn); +int32_t devfn = sec->parent_dev->devfn; + +aml_append (method,aml_name ("^S%.02X.PCNT" , devfn)); } } - -build_append_and_cleanup_method (bus_table, method); - -build_package (bus_table,0x10 );/* ScopeOp */ -build_append_array (parent_scope, bus_table); -build_free_array (bus_table); +aml_append (parent_scope, method); }static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size)@@ -943,9 +875,10 @@ build_ssdt(Aml *table_data, }if (bus) { +Aml *scope =aml_scope ("PCI0" );/* Scan all PCI buses. Generate tables to support hotplug. */ -build_append_pci_bus_devices (sb_scope->buf, bus, - pm->pcihp_bridge_en); +build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +aml_append (sb_scope, scope); } }aml_append (ssdt, sb_scope);hw/i386/ssdt-pcihp.dsl deleted +0
-100@@ -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 - } - } - } -}hw/i386/ssdt-pcihp.hex.generated deleted +0
-0hw/i386/ssdt-pcihp.hex.generated
Quoted 1 line
hw/i386/ssdt-pcihp.hex.generated deleted +0
-1--- a/hw/i386/ssdt-pcihp.hex.generatedPls don't send generated file patches.
Just note it should be removed in comment, I'll do it.Quoted 255 lines
+++
/dev/nullhw/i386/ssdt-pcihp.hex.generated deleted +0
-251@@ -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 -};Signature · 1 line
1.8.3.1
PATCH v3 22/52 acpi: add aml_package() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -556,3 +556,11 @@ Aml *aml_device(const char *name_format, ...)va_end (ap);return var; } + +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */ +Aml *aml_package (uint8_t num_elements) +{ +Aml *var =aml_bundle (0x12 /* PackageOp */ ,AML_PACKAGE ); +build_append_byte (var->buf, num_elements); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -92,6 +92,7 @@ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_method (const char *name,int arg_count);Aml *aml_if (Aml *predicate); +Aml *aml_package (uint8_t num_elements);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 23/52 pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
In reply to Igor MammedovQEMU doesn't implement/advertize PM1b_CNT_BLK
register block so do not set/patch its \_Sx
values to avoid confusion.
--- hw/i386/acpi-build.c | 3 +-- hw/i386/ssdt-misc.dsl | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +1 -2
@@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,if (pm->s4_disabled) { ssdt_ptr[acpi_s4_name[0 ]] ='X' ; }else { - ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = ssdt_ptr[acpi_s4_pkg[0 ] +3 ] = - pm->s4_val; + ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = pm->s4_val; }patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));
hw/i386/ssdt-misc.dsl +2 -2
@@ -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 */ })
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
Quoted 5 lines · Igor Mammedov
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 <[email protected]>
I doubt guests are confused.
I think you mean this confuses you, but I'd rather stay bug for bug compatible with what we did historically. We probably should add a comment saying this is here for historical reasons, but let's get your patchset merged first, it's too big as is.
Quoted 43 lines
--- hw/i386/acpi-build.c | 3 +-- hw/i386/ssdt-misc.dsl | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-)hw/i386/acpi-build.c +1
-2@@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,if (pm->s4_disabled) { ssdt_ptr[acpi_s4_name[0 ]] ='X' ; }else { - ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = ssdt_ptr[acpi_s4_pkg[0 ] +3 ] = - pm->s4_val; + ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = pm->s4_val; }patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));hw/i386/ssdt-misc.dsl +2
-2@@ -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 */ })Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
Quoted 8 lines · On Tue, 17 Feb 2015 17:41:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov
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 <[email protected]>I doubt guests are confused.
They just happen to ignore it, it doesn't mean that it's correct
Quoted 5 lines
I think you mean this confuses you, but I'd rather stay bug for bug compatible with what we did historically. We probably should add a comment saying this is here for historical reasons, but let's get your patchset merged first, it's too big as is.
I don't see point in being bug compatible in this case.
Quoted 45 lines
Quoted 45 lines
--- hw/i386/acpi-build.c | 3 +-- hw/i386/ssdt-misc.dsl | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-)hw/i386/acpi-build.c +1
-2@@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,if (pm->s4_disabled) { ssdt_ptr[acpi_s4_name[0 ]] ='X' ; }else { - ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = ssdt_ptr[acpi_s4_pkg[0 ] +3 ] = - pm->s4_val; + ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = pm->s4_val; }patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));hw/i386/ssdt-misc.dsl +2
-2@@ -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 */ })Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
Quoted 11 lines · Igor Mammedov
Quoted 8 lines · On Tue, 17 Feb 2015 17:41:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov
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 <[email protected]>I doubt guests are confused.
Quoted 8 lines
They just happen to ignore it, it doesn't mean that it's correct
Quoted 5 lines
I think you mean this confuses you, but I'd rather stay bug for bug compatible with what we did historically. We probably should add a comment saying this is here for historical reasons, but let's get your patchset merged first, it's too big as is.
I don't see point in being bug compatible in this case.
yes but don't make unrelated changes part of this series. it's too big already.
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
--- hw/i386/acpi-build.c | 3 +-- hw/i386/ssdt-misc.dsl | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-)hw/i386/acpi-build.c +1
-2@@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,if (pm->s4_disabled) { ssdt_ptr[acpi_s4_name[0 ]] ='X' ; }else { - ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = ssdt_ptr[acpi_s4_pkg[0 ] +3 ] = - pm->s4_val; + ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = pm->s4_val; }patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));hw/i386/ssdt-misc.dsl +2
-2@@ -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 */ })Signature · 1 line
1.8.3.1
PATCH v3 24/52 pc: acpi-build: generate _S[345] packages dynamically
In reply to Igor MammedovReplaces template patching with packages composed using AML API.
Note on behavior change:
If S3 or S4 is disabled, respective packages won't be created and put into SSDT. Which saves us some space in SSDT and doesn't confuse guest OS with mangled package names as it was done originally.
--- hw/i386/acpi-build.c | 38 +++++++++++++++++++++++++++++--------- hw/i386/ssdt-misc.dsl | 33 --------------------------------- 2 files changed, 29 insertions(+), 42 deletions(-)
hw/i386/acpi-build.c +29 -9
@@ -756,7 +756,7 @@ build_ssdt(Aml *table_data,uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit;uint8_t *ssdt_ptr; -Aml *ssdt, *sb_scope; +Aml *ssdt, *sb_scope, *scope, *pkg;int i;/* The current AML generator can cover the APIC ID range [0..255],
@@ -775,14 +775,6 @@ build_ssdt(Aml *table_data,memcpy (ssdt_ptr +sizeof (AcpiTableHeader), ssdp_misc_aml +sizeof (AcpiTableHeader),sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); -if (pm->s3_disabled) { - ssdt_ptr[acpi_s3_name[0 ]] ='X' ; - } -if (pm->s4_disabled) { - ssdt_ptr[acpi_s4_name[0 ]] ='X' ; - }else { - ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = pm->s4_val; - }patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));
@@ -792,6 +784,34 @@ build_ssdt(Aml *table_data,ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_mctrl_nr_slots[0 ],32 , nr_mem); +/* create S3_ / S4_ / S5_ packages if necessary */ + scope =aml_scope ("\\" ); +if (!pm->s3_disabled) { + pkg =aml_package (4 ); +aml_append (pkg,aml_int (1 ));/* PM1a_CNT.SLP_TYP */ +aml_append (pkg,aml_int (0 ));/* PM1b_CNT.SLP_TYP not impl. */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (scope,aml_name_decl ("_S3" , pkg)); + } + +if (!pm->s4_disabled) { + pkg =aml_package (4 ); +aml_append (pkg,aml_int (pm->s4_val));/* PM1a_CNT.SLP_TYP */ +aml_append (pkg,aml_int (0 ));/* PM1b_CNT.SLP_TYP not impl. */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (scope,aml_name_decl ("_S4" , pkg)); + } + + pkg =aml_package (4 ); +aml_append (pkg,aml_int (0 ));/* PM1a_CNT.SLP_TYP */ +aml_append (pkg,aml_int (0 ));/* PM1b_CNT.SLP_TYP not impl. */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (scope,aml_name_decl ("_S5" , pkg)); +aml_append (ssdt, scope); + sb_scope =aml_scope ("_SB" ); {/* build Processor object for each processor */
hw/i386/ssdt-misc.dsl +0 -33
@@ -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)
Signature · 1 line
1.8.3.1
PATCH v3 25/52 acpi: add aml_buffer() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 7 +++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 8 insertions(+)
hw/acpi/aml-build.c +7 -0
@@ -557,6 +557,13 @@ Aml *aml_device(const char *name_format, ...)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */ +Aml *aml_buffer (void ) +{ +Aml *var =aml_bundle (0x11 /* BufferOp */ ,AML_BUFFER ); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */ Aml *aml_package (uint8_t num_elements) {
include/hw/acpi/aml-build.h +1 -0
@@ -93,6 +93,7 @@ Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_method (const char *name,int arg_count);Aml *aml_if (Aml *predicate);Aml *aml_package (uint8_t num_elements); +Aml *aml_buffer (void );/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 26/52 acpi: add aml_resource_template() helper
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -557,6 +557,14 @@ Aml *aml_device(const char *name_format, ...)return var; } +/* ACPI 1.0b: 6.4.1 ASL Macros for Resource Descriptors */ +Aml *aml_resource_template (void ) +{ +/* ResourceTemplate is a buffer of Resources with EndTag at the end */ +Aml *var =aml_bundle (0x11 /* BufferOp */ ,AML_RES_TEMPLATE ); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */ Aml *aml_buffer (void ) {
include/hw/acpi/aml-build.h +1 -0
@@ -94,6 +94,7 @@ Aml *aml_method(const char *name, int arg_count);Aml *aml_if (Aml *predicate);Aml *aml_package (uint8_t num_elements);Aml *aml_buffer (void ); +Aml *aml_resource_template (void );/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 27/52 acpi: add aml_io() helper
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 16 ++++++++++++++++ include/hw/acpi/aml-build.h | 7 +++++++ 2 files changed, 23 insertions(+)
hw/acpi/aml-build.c +16 -0
@@ -518,6 +518,22 @@ Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4)return var; } +/* ACPI 1.0b: 6.4.2.5 I/O Port Descriptor */ +Aml *aml_io (AmlIODecode dec,uint16_t min_base,uint16_t max_base, +uint8_t aln,uint8_t len) +{ +Aml *var =aml_alloc (); +build_append_byte (var->buf,0x47 );/* IO port descriptor */ +build_append_byte (var->buf, dec); +build_append_byte (var->buf, min_base &0xff ); +build_append_byte (var->buf, (min_base >>8 ) &0xff ); +build_append_byte (var->buf, max_base &0xff ); +build_append_byte (var->buf, (max_base >>8 ) &0xff ); +build_append_byte (var->buf, aln); +build_append_byte (var->buf, len); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +7 -0
@@ -31,6 +31,11 @@ struct Aml { };typedef struct Aml Aml ; +typedef enum { + aml_decode10 =0 , + aml_decode16 =1 , +}AmlIODecode ; +/** * init_aml_allocator: * @linker: linker that used by API for registering ACPI tables
@@ -82,6 +87,8 @@ Aml *aml_call1(const char *method, Aml *arg1);Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2);Aml *aml_call3 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3);Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4); +Aml *aml_io (AmlIODecode dec,uint16_t min_base,uint16_t max_base, +uint8_t aln,uint8_t len);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 28/52 acpi: include PkgLength size only when requested
In reply to Igor MammedovNamed/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
--- hw/acpi/aml-build.c | 20 +++++++++++++++----- include/hw/acpi/aml-build.h | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-)
hw/acpi/aml-build.c +15 -5
@@ -159,10 +159,10 @@ enum { PACKAGE_LENGTH_4BYTE_SHIFT = 20, }; -void build_prepend_package_length (GArray *package) +void +build_prepend_package_length (GArray *package,unsigned length,bool incl_self) {uint8_t byte; -unsigned length = package->len;unsigned length_bytes;if (length +1 < (1 <<PACKAGE_LENGTH_1BYTE_SHIFT )) {
@@ -175,8 +175,18 @@ void build_prepend_package_length(GArray *package) length_bytes =4 ; } -/* PkgLength is the length of the inclusive length of the data. */ - length += length_bytes; +/* +* NamedField uses PkgLength encoding but it doesn't include length +* of PkgLength itself. +*/ +if (incl_self) { +/* +* PkgLength is the length of the inclusive length of the data +* and PkgLength's length itself when used for terms with +* explitit length. +*/ + length += length_bytes; + }switch (length_bytes) {case 1 :
@@ -209,7 +219,7 @@ void build_prepend_package_length(GArray *package)void build_package (GArray *package,uint8_t op) { -build_prepend_package_length (package); +build_prepend_package_length (package, package->len, true);build_prepend_byte (package, op); }
include/hw/acpi/aml-build.h +2 -1
@@ -113,7 +113,8 @@ void build_append_array(GArray *array, GArray *val); void GCC_FMT_ATTR(2, 3) build_append_namestring(GArray *array, const char *format, ...); -void build_prepend_package_length(GArray *package); +void +build_prepend_package_length(GArray *package, unsigned length, bool incl_self); void build_package(GArray *package, uint8_t op); void build_append_value(GArray *table, uint64_t value, int size); void build_append_int(GArray *table, uint64_t value);
Signature · 1 line
1.8.3.1
PATCH v3 29/52 acpi: add aml_operation_region() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 14 ++++++++++++++ include/hw/acpi/aml-build.h | 7 +++++++ 2 files changed, 21 insertions(+)
hw/acpi/aml-build.c +14 -0
@@ -605,3 +605,17 @@ Aml *aml_package(uint8_t num_elements)build_append_byte (var->buf, num_elements);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefOpRegion */ +Aml *aml_operation_region (const char *name,AmlRegionSpace rs, +uint32_t offset,uint32_t len) +{ +Aml *var =aml_alloc (); +build_append_byte (var->buf,0x5B );/* ExtOpPrefix */ +build_append_byte (var->buf,0x80 );/* OpRegionOp */ +build_append_namestring (var->buf,"%s" , name); +build_append_byte (var->buf, rs); +build_append_int (var->buf, offset); +build_append_int (var->buf, len); +return var; +}
include/hw/acpi/aml-build.h +7 -0
@@ -36,6 +36,11 @@ typedef enum { aml_decode16 =1 , } AmlIODecode; +typedef enum { + aml_system_memory =0x00 , + aml_system_io =0x01 , +}AmlRegionSpace ; +/** * init_aml_allocator: * @linker: linker that used by API for registering ACPI tables
@@ -89,6 +94,8 @@ Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4);Aml *aml_io (AmlIODecode dec,uint16_t min_base,uint16_t max_base,uint8_t aln,uint8_t len); +Aml *aml_operation_region (const char *name,AmlRegionSpace rs, +uint32_t offset,uint32_t len);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 30/52 acpi: add aml_field() & aml_named_field() terms
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 28 ++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 6 ++++++ 2 files changed, 34 insertions(+)
hw/acpi/aml-build.c +28 -0
@@ -217,6 +217,16 @@ build_prepend_package_length(GArray *package, unsigned length, bool incl_self)build_prepend_byte (package, byte); } +static void +build_append_pkg_length (GArray *array,unsigned length,bool incl_self) +{ +GArray *tmp =build_alloc_array (); + +build_prepend_package_length (tmp, length, incl_self); +build_append_array (array, tmp); +build_free_array (tmp); +} +void build_package (GArray *package,uint8_t op) {build_prepend_package_length (package, package->len, true);
@@ -619,3 +629,21 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs,build_append_int (var->buf, len);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: NamedField */ +Aml *aml_named_field (const char *name,unsigned length) +{ +Aml *var =aml_alloc (); +build_append_nameseg (var->buf, name); +build_append_pkg_length (var->buf, length, false); +return var; +} + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */ +Aml *aml_field (const char *name,AmlFieldFlags flags) +{ +Aml *var =aml_bundle (0x81 /* FieldOp */ ,AML_EXT_PACKAGE ); +build_append_namestring (var->buf,"%s" , name); +build_append_byte (var->buf, flags); +return var; +}
include/hw/acpi/aml-build.h +6 -0
@@ -37,6 +37,10 @@ typedef enum { } AmlIODecode;typedef enum { + aml_byte_acc =1 , +}AmlFieldFlags ; + +typedef enum { aml_system_memory =0x00 , aml_system_io =0x01 , }AmlRegionSpace ;
@@ -96,6 +100,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, uint8_t aln, uint8_t len);Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len); +Aml *aml_named_field (const char *name,unsigned length);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
@@ -109,6 +114,7 @@ Aml *aml_if(Aml *predicate);Aml *aml_package (uint8_t num_elements);Aml *aml_buffer (void );Aml *aml_resource_template (void ); +Aml *aml_field (const char *name,AmlFieldFlags flags);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 31/52 acpi: add aml_local() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 11 +++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 12 insertions(+)
hw/acpi/aml-build.c +11 -0
@@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)build_append_byte (var->buf, flags);return var; } + +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */ +Aml *aml_local (int num) +{ +Aml *var; +uint8_t op =0x60 /* Local0Op */ + num; + +assert (op <=7 ); + var =aml_opcode (op); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len);Aml *aml_named_field (const char *name,unsigned length); +Aml *aml_local (int num);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term
Quoted 2 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
This causes asserts.
Quoted 9 lines
hw/acpi/aml-build.c | 11 +++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 12 insertions(+)hw/acpi/aml-build.c +0
-0
hw/acpi/aml-build.c Aml *aml_field(const char *name, AmlFieldFlags flags) · line 655
Quoted 9 lines
hw/acpi/aml-build.c +6
-0@@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)build_append_byte (var->buf, flags);return var; } + +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */ +Aml *aml_local (int num) +{ +Aml *var; +uint8_t op =0x60 /* Local0Op */ + num;
So op is 0x6X here.
hw/acpi/aml-build.c Aml *aml_field(const char *name, AmlFieldFlags flags) · line 657
Quoted 2 lines
hw/acpi/aml-build.c +2
-0+ +assert (op <=7 );
And here we assert it is <= 7?
Quoted 17 lines
hw/acpi/aml-build.c +3
-0+ var =aml_opcode (op); +return var; +}include/hw/acpi/aml-build.h +1
-0@@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len);Aml *aml_named_field (const char *name,unsigned length); +Aml *aml_local (int num);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term
Quoted 27 lines · On Tue, 17 Feb 2015 13:18:19 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
This causes asserts.
Quoted 9 lines
hw/acpi/aml-build.c | 11 +++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 12 insertions(+)hw/acpi/aml-build.c +0
-0hw/acpi/aml-build.c Aml *aml_field(const char *name, AmlFieldFlags flags) · line 655
Quoted 9 lines
hw/acpi/aml-build.c +6
-0@@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)build_append_byte (var->buf, flags);return var; } + +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */ +Aml *aml_local (int num) +{ +Aml *var; +uint8_t op =0x60 /* Local0Op */ + num;So op is 0x6X here.
Quoted 4 lines
hw/acpi/aml-build.c Aml *aml_field(const char *name, AmlFieldFlags flags) · line 657
Quoted 2 lines
hw/acpi/aml-build.c +2
-0+ +assert (op <=7 );And here we assert it is <= 7?
yep, it should s/op/num/
I'm sorry for not running make check on the last iteration, I'll post fixup shortly.
Quoted 19 lines
Quoted 19 lines
hw/acpi/aml-build.c +3
-0+ var =aml_opcode (op); +return var; +}include/hw/acpi/aml-build.h +1
-0@@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len);Aml *aml_named_field (const char *name,unsigned length); +Aml *aml_local (int num);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,Signature · 1 line
1.8.3.1
PATCH v3 31/52 fixup! acpi: add aml_local() term
In reply to Igor Mammedovfixes:
qemu-system-i386: hw/acpi/aml-build.c:723: aml_local: Assertion `op <= 7' failed. when pvpanic device is present
---
this time make check on my host for all targets passes, /me sorry for mess again
--- hw/acpi/aml-build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/acpi/aml-build.c +1 -1
@@ -720,7 +720,7 @@ Aml *aml_local(int num)Aml *var;uint8_t op =0x60 /* Local0Op */ + num; -assert (op <=7 ); +assert (num <=7 ); var =aml_opcode (op);return var; }
Signature · 1 line
1.8.3.1
PATCH v3 32/52 acpi: add aml_string() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 25 +++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 26 insertions(+)
hw/acpi/aml-build.c +25 -0
@@ -648,6 +648,31 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)return var; } +/* ACPI 1.0b: 16.2.3 Data Objects Encoding: String */ +Aml *aml_string (const char *name_format, ...) +{ +Aml *var =aml_opcode (0x0D /* StringPrefix */ ); +va_list ap, va_len; +char *s; +int len; + +va_start (ap, name_format); +va_copy (va_len, ap); + len =vsnprintf (NULL ,0 , name_format, va_len); +va_end (va_len); + len +=1 ; + s =g_new0 (typeof (*s), len); + + len =vsnprintf (s, len, name_format, ap); +va_end (ap); + +g_array_append_vals (var->buf, s, len); +build_append_byte (var->buf,0x0 );/* NullChar */ +g_free (s); + +return var; +} +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */ Aml *aml_local (int num) {
include/hw/acpi/aml-build.h +1 -0
@@ -102,6 +102,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs, uint32_t offset, uint32_t len);Aml *aml_named_field (const char *name,unsigned length);Aml *aml_local (int num); +Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 33/52 pc: acpi-build: generate pvpanic device description dynamically
In reply to Igor MammedovDrops 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.
--- hw/i386/acpi-build.c | 36 ++++++++++++++++++++++++++++++++---- hw/i386/ssdt-misc.dsl | 47 ----------------------------------------------- 2 files changed, 32 insertions(+), 51 deletions(-)
hw/i386/acpi-build.c +32 -4
@@ -756,7 +756,7 @@ build_ssdt(Aml *table_data,uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit;uint8_t *ssdt_ptr; -Aml *ssdt, *sb_scope, *scope, *pkg; +Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field;int i;/* The current AML generator can cover the APIC ID range [0..255],
@@ -779,9 +779,6 @@ build_ssdt(Aml *table_data,patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), - ssdt_isa_pest[0 ],16 , misc->pvpanic_port); - -ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_mctrl_nr_slots[0 ],32 , nr_mem);/* create S3_ / S4_ / S5_ packages if necessary */
@@ -812,6 +809,37 @@ build_ssdt(Aml *table_data,aml_append (scope,aml_name_decl ("_S5" , pkg));aml_append (ssdt, scope); +if (misc->pvpanic_port) { + scope =aml_scope ("\\_SB.PCI0.ISA" ); + + dev =aml_device ("PEVR" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("QEMU0002" ))); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, misc->pvpanic_port, misc->pvpanic_port,1 ,1 ) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); + +aml_append (dev,aml_operation_region ("PEOR" , aml_system_io, + misc->pvpanic_port,1 )); + field =aml_field ("PEOR" , aml_byte_acc); +aml_append (field,aml_named_field ("PEPT" ,8 )); +aml_append (dev, field); + + method =aml_method ("RDPT" ,0 ); +aml_append (method,aml_store (aml_name ("PEPT" ),aml_local (0 ))); +aml_append (method,aml_return (aml_local (0 ))); +aml_append (dev, method); + + method =aml_method ("WRPT" ,1 ); +aml_append (method,aml_store (aml_arg (0 ),aml_name ("PEPT" ))); +aml_append (dev, method); + +aml_append (scope, dev); +aml_append (ssdt, scope); + } + sb_scope =aml_scope ("_SB" ); {/* build Processor object for each processor */
hw/i386/ssdt-misc.dsl +0 -47
51 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 34/52 acpi: add aml_varpackage() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -683,3 +683,11 @@ Aml *aml_local(int num) var =aml_opcode (op);return var; } + +/* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */ +Aml *aml_varpackage (uint32_t num_elements) +{ +Aml *var =aml_bundle (0x13 /* VarPackageOp */ ,AML_PACKAGE ); +build_append_int (var->buf, num_elements); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -117,6 +117,7 @@ Aml *aml_package(uint8_t num_elements);Aml *aml_buffer (void );Aml *aml_resource_template (void );Aml *aml_field (const char *name,AmlFieldFlags flags); +Aml *aml_varpackage (uint32_t num_elements);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v3 35/52 acpi: add aml_equal() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -554,6 +554,16 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */ +Aml *aml_equal (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x93 /* LequalOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +build_append_int (var->buf,0x00 );/* NullNameOp */ +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -103,6 +103,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs,Aml *aml_named_field (const char *name,unsigned length);Aml *aml_local (int num);Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_equal (Aml *arg1,Aml *arg2);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 36/52 acpi: add aml_processor() term
In reply to Igor Mammedov---
v2:
* use build_append_value() to pack PblkAddr
instead of doing it manually
--- hw/acpi/aml-build.c | 15 +++++++++++++++ include/hw/acpi/aml-build.h | 2 ++ 2 files changed, 17 insertions(+)
hw/acpi/aml-build.c +15 -0
@@ -701,3 +701,18 @@ Aml *aml_varpackage(uint32_t num_elements)build_append_int (var->buf, num_elements);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefProcessor */ +Aml *aml_processor (uint8_t proc_id,uint32_t pblk_addr,uint8_t pblk_len, +const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_bundle (0x83 /* ProcessorOp */ ,AML_EXT_PACKAGE ); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +build_append_byte (var->buf, proc_id);/* ProcID */ +build_append_value (var->buf, pblk_addr,sizeof (pblk_addr));/* PblkAddr */ +build_append_byte (var->buf, pblk_len);/* PblkLen */ +return var; +}
include/hw/acpi/aml-build.h +2 -0
@@ -104,6 +104,8 @@ Aml *aml_named_field(const char *name, unsigned length);Aml *aml_local (int num);Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_equal (Aml *arg1,Aml *arg2); +Aml *aml_processor (uint8_t proc_id,uint32_t pblk_addr,uint8_t pblk_len, +const char *name_format, ...)GCC_FMT_ATTR (4 ,5 );/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 37/52 acpi: add aml_eisaid() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 29 +++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 30 insertions(+)
hw/acpi/aml-build.c +29 -0
@@ -716,3 +716,32 @@ Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,build_append_byte (var->buf, pblk_len);/* PblkLen */ return var; } + +static uint8_t Hex2Digit (char c) +{ +if (c >='A' ) { +return c -'A' +10 ; + } + +return c -'0' ; +} + +/* ACPI 1.0b: 15.2.3.6.4.1 EISAID Macro - Convert EISA ID String To Integer */ +Aml *aml_eisaid (const char *str) +{ +Aml *var =aml_alloc (); +uint32_t id; + +g_assert (strlen (str) ==7 ); + id = (str[0 ] -0x40 ) <<26 | + (str[1 ] -0x40 ) <<21 | + (str[2 ] -0x40 ) <<16 | +Hex2Digit (str[3 ]) <<12 | +Hex2Digit (str[4 ]) <<8 | +Hex2Digit (str[5 ]) <<4 | +Hex2Digit (str[6 ]); + +build_append_byte (var->buf,0x0C );/* DWordPrefix */ +build_append_value (var->buf,bswap32 (id),sizeof (id)); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -106,6 +106,7 @@ Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_equal (Aml *arg1,Aml *arg2);Aml *aml_processor (uint8_t proc_id,uint32_t pblk_addr,uint8_t pblk_len,const char *name_format, ...)GCC_FMT_ATTR (4 ,5 ); +Aml *aml_eisaid (const char *str);/* Block AML object primitives */ Aml *aml_def_block(const char *signature, uint8_t revision,
Signature · 1 line
1.8.3.1
PATCH v3 38/52 pc: acpi-build: drop template patching and CPU hotplug objects dynamically
In reply to Igor Mammedovin 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.
--- hw/i386/Makefile.objs | 2 +- hw/i386/acpi-build.c | 95 ++++++++++++---------------- hw/i386/ssdt-proc.dsl | 63 ------------------- hw/i386/ssdt-proc.hex.generated | 134 ---------------------------------------- 4 files changed, 42 insertions(+), 252 deletions(-) delete mode 100644 hw/i386/ssdt-proc.dsl delete mode 100644 hw/i386/ssdt-proc.hex.generated
hw/i386/Makefile.objs +1 -1
@@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ - hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ + hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
hw/i386/acpi-build.c +41 -54
121 lines not on this page · raw message
hw/i386/ssdt-proc.dsl deleted +0 -63
63 lines not on this page · raw message
hw/i386/ssdt-proc.hex.generated deleted +0 -134
134 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 39/52 pc: acpi-build: create CPU hotplug IO region dynamically
In reply to Igor Mammedovit 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.
--- 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(-)
hw/i386/acpi-build.c +27 -0
@@ -101,6 +101,8 @@ typedef struct AcpiPmInfo {uint32_t gpe0_blk;uint32_t gpe0_blk_len;uint32_t io_base; +uint16_t cpu_hp_io_base; +uint16_t cpu_hp_io_len; } AcpiPmInfo; typedef struct AcpiMiscInfo {
@@ -175,12 +177,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)if (piix) { obj = piix; + pm->cpu_hp_io_base =PIIX4_CPU_HOTPLUG_IO_BASE ; }if (lpc) { obj = lpc; + pm->cpu_hp_io_base =ICH9_CPU_HOTPLUG_IO_BASE ; }assert (obj); + pm->cpu_hp_io_len =ACPI_GPE_PROC_LEN ;/* Fill in optional s3/s4 related properties */ o =object_property_get_qobject (obj,ACPI_PM_PROP_S3_DISABLED ,NULL );if (o) {
@@ -826,6 +831,28 @@ build_ssdt(Aml *table_data, sb_scope =aml_scope ("_SB" ); { +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, pm->cpu_hp_io_base, pm->cpu_hp_io_base,1 , + pm->cpu_hp_io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" , aml_system_io, pm->cpu_hp_io_base, pm->cpu_hp_io_len)); + field =aml_field ("PRST" , aml_byte_acc); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); +/* build Processor object for each processor */ for (i =0 ; i < acpi_cpus; i++) { dev =aml_processor (i,0 ,0 ,"CP%.02X" , i);
hw/i386/acpi-dsdt-cpu-hotplug.dsl +1 -16
@@ -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 */ - } }
include/hw/acpi/pc-hotplug.h +1 -0
@@ -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
Signature · 1 line
1.8.3.1
PATCH v3 40/52 acpi: add aml_reserved_field() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 6 ++++++ 2 files changed, 16 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -649,6 +649,16 @@ Aml *aml_named_field(const char *name, unsigned length)return var; } +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: ReservedField */ +Aml *aml_reserved_field (unsigned length) +{ +Aml *var =aml_alloc (); +/* ReservedField := 0x00 PkgLength */ +build_append_byte (var->buf,0x00 ); +build_append_pkg_length (var->buf, length, false); +return var; +} +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */ Aml *aml_field (const char *name,AmlFieldFlags flags) {
include/hw/acpi/aml-build.h +6 -0
@@ -37,7 +37,12 @@ typedef enum { } AmlIODecode;typedef enum { + aml_any_acc =0 , aml_byte_acc =1 , + aml_word_acc =2 , + aml_dword_acc =3 , + aml_qword_acc =4 , + aml_buffer_acc =5 , }AmlFieldFlags ; typedef enum {
@@ -101,6 +106,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len);Aml *aml_named_field (const char *name,unsigned length); +Aml *aml_reserved_field (unsigned length);Aml *aml_local (int num);Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_equal (Aml *arg1,Aml *arg2);
Signature · 1 line
1.8.3.1
PATCH v3 41/52 pc: acpi-build: drop template patching and memory hotplug objects dynamically
In reply to Igor Mammedovin 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.
--- hw/i386/Makefile.objs | 2 +- hw/i386/acpi-build.c | 133 +++++++++---------------- hw/i386/ssdt-mem.dsl | 77 --------------- hw/i386/ssdt-mem.hex.generated | 213 ----------------------------------------- 4 files changed, 47 insertions(+), 378 deletions(-) delete mode 100644 hw/i386/ssdt-mem.dsl delete mode 100644 hw/i386/ssdt-mem.hex.generated
hw/i386/Makefile.objs +1 -1
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex + hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \ ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +46 -87
159 lines not on this page · raw message
hw/i386/ssdt-mem.dsl deleted +0 -77
77 lines not on this page · raw message
hw/i386/ssdt-mem.hex.generated deleted +0 -213
213 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 42/52 pc: acpi-build: create memory hotplug IO region dynamically
In reply to Igor Mammedovit 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.
--- 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(-)
hw/i386/acpi-build.c +54 -3
@@ -103,6 +103,8 @@ typedef struct AcpiPmInfo {uint32_t io_base;uint16_t cpu_hp_io_base;uint16_t cpu_hp_io_len; +uint16_t mem_hp_io_base; +uint16_t mem_hp_io_len; } AcpiPmInfo; typedef struct AcpiMiscInfo {
@@ -186,6 +188,9 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)assert (obj); pm->cpu_hp_io_len =ACPI_GPE_PROC_LEN ; + pm->mem_hp_io_base =ACPI_MEMORY_HOTPLUG_BASE ; + pm->mem_hp_io_len =ACPI_MEMORY_HOTPLUG_IO_LEN ; +/* Fill in optional s3/s4 related properties */ o =object_property_get_qobject (obj,ACPI_PM_PROP_S3_DISABLED ,NULL );if (o) {
@@ -698,9 +703,6 @@ build_ssdt(Aml *table_data,patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); -ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), - ssdt_mctrl_nr_slots[0 ],32 , nr_mem); -/* create S3_ / S4_ / S5_ packages if necessary */ scope =aml_scope ("\\" );if (!pm->s3_disabled) {
@@ -837,6 +839,55 @@ build_ssdt(Aml *table_data,/* build memory devices */ assert (nr_mem <=ACPI_MAX_RAM_SLOTS ); + scope =aml_scope ("\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE )); +aml_append (scope, +aml_name_decl (stringify (MEMORY_SLOTS_NUMBER ),aml_int (nr_mem)) + ); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, pm->mem_hp_io_base, pm->mem_hp_io_base,0 , + pm->mem_hp_io_len) + ); +aml_append (scope,aml_name_decl ("_CRS" , crs)); + +aml_append (scope,aml_operation_region ( +stringify (MEMORY_HOTPLUG_IO_REGION ), aml_system_io, + pm->mem_hp_io_base, pm->mem_hp_io_len) + ); + + field =aml_field (stringify (MEMORY_HOTPLUG_IO_REGION ), aml_dword_acc); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_ADDR_LOW ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_ADDR_HIGH ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_SIZE_LOW ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_SIZE_HIGH ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_PROXIMITY ),32 )); +aml_append (scope, field); + + field =aml_field (stringify (MEMORY_HOTPLUG_IO_REGION ), aml_byte_acc); +aml_append (field,aml_reserved_field (160 /* bits, Offset(20) */ )); +aml_append (field,/* 1 if enabled, read only */ +aml_named_field (stringify (MEMORY_SLOT_ENABLED ),1 )); +aml_append (field, +/*(read) 1 if has a insert event. (write) 1 to clear event */ +aml_named_field (stringify (MEMORY_SLOT_INSERT_EVENT ),1 )); +aml_append (scope, field); + + field =aml_field (stringify (MEMORY_HOTPLUG_IO_REGION ), aml_dword_acc); +aml_append (field,/* DIMM selector, write only */ +aml_named_field (stringify (MEMORY_SLOT_SLECTOR ),32 )); +aml_append (field,/* _OST event code, write only */ +aml_named_field (stringify (MEMORY_SLOT_OST_EVENT ),32 )); +aml_append (field,/* _OST status code, write only */ +aml_named_field (stringify (MEMORY_SLOT_OST_STATUS ),32 )); +aml_append (scope, field); + +aml_append (sb_scope, scope);for (i =0 ; i < nr_mem; i++) {#define BASEPATH "\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE) "."
hw/i386/acpi-dsdt-mem-hotplug.dsl +10 -26
@@ -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)) {
hw/i386/ssdt-misc.dsl +0 -2
@@ -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) } }
Signature · 1 line
1.8.3.1
PATCH v3 43/52 acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 161 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 72 ++++++++++++++++++++ 2 files changed, 233 insertions(+)
hw/acpi/aml-build.c +161 -0
@@ -755,3 +755,164 @@ Aml *aml_eisaid(const char *str)build_append_value (var->buf,bswap32 (id),sizeof (id));return var; } + +/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor: bytes 3-5 */ +static Aml *aml_as_desc_header (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint8_t type_flags) +{ +uint8_t flags = max_fixed | min_fixed | dec; +Aml *var =aml_alloc (); + +build_append_byte (var->buf, type); +build_append_byte (var->buf, flags); +build_append_byte (var->buf, type_flags);/* Type Specific Flags */ +return var; +} + +/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor */ +static Aml *aml_word_as_desc (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint16_t addr_gran,uint16_t addr_min, +uint16_t addr_max,uint16_t addr_trans, +uint16_t len,uint8_t type_flags) +{ +Aml *var =aml_alloc (); + +build_append_byte (var->buf,0x88 );/* Word Address Space Descriptor */ +/* minimum length since we do not encode optional fields */ +build_append_byte (var->buf,0x0D ); +build_append_byte (var->buf,0x0 ); + +aml_append (var, +aml_as_desc_header (type, min_fixed, max_fixed, dec, type_flags)); +build_append_value (var->buf, addr_gran,sizeof (addr_gran)); +build_append_value (var->buf, addr_min,sizeof (addr_min)); +build_append_value (var->buf, addr_max,sizeof (addr_max)); +build_append_value (var->buf, addr_trans,sizeof (addr_trans)); +build_append_value (var->buf, len,sizeof (len)); +return var; +} + +/* ACPI 1.0b: 6.4.3.5.3 DWord Address Space Descriptor */ +static Aml *aml_dword_as_desc (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint32_t addr_gran,uint32_t addr_min, +uint32_t addr_max,uint32_t addr_trans, +uint32_t len,uint8_t type_flags) +{ +Aml *var =aml_alloc (); + +build_append_byte (var->buf,0x87 );/* DWord Address Space Descriptor */ +/* minimum length since we do not encode optional fields */ +build_append_byte (var->buf,23 ); +build_append_byte (var->buf,0x0 ); + + +aml_append (var, +aml_as_desc_header (type, min_fixed, max_fixed, dec, type_flags)); +build_append_value (var->buf, addr_gran,sizeof (addr_gran)); +build_append_value (var->buf, addr_min,sizeof (addr_min)); +build_append_value (var->buf, addr_max,sizeof (addr_max)); +build_append_value (var->buf, addr_trans,sizeof (addr_trans)); +build_append_value (var->buf, len,sizeof (len)); +return var; +} + +/* ACPI 1.0b: 6.4.3.5.1 QWord Address Space Descriptor */ +static Aml *aml_qword_as_desc (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint64_t addr_gran,uint64_t addr_min, +uint64_t addr_max,uint64_t addr_trans, +uint64_t len,uint8_t type_flags) +{ +Aml *var =aml_alloc (); + +build_append_byte (var->buf,0x8A );/* QWord Address Space Descriptor */ +/* minimum length since we do not encode optional fields */ +build_append_byte (var->buf,0x2B ); +build_append_byte (var->buf,0x0 ); + +aml_append (var, +aml_as_desc_header (type, min_fixed, max_fixed, dec, type_flags)); +build_append_value (var->buf, addr_gran,sizeof (addr_gran)); +build_append_value (var->buf, addr_min,sizeof (addr_min)); +build_append_value (var->buf, addr_max,sizeof (addr_max)); +build_append_value (var->buf, addr_trans,sizeof (addr_trans)); +build_append_value (var->buf, len,sizeof (len)); +return var; +} + +/* +* ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.141 WordBusNumber (Word Bus Number Resource Descriptor Macro) +*/ +Aml *aml_word_bus_number (AmlMinFixed min_fixed,AmlMaxFixed max_fixed, +AmlDecode dec,uint16_t addr_gran, +uint16_t addr_min,uint16_t addr_max, +uint16_t addr_trans,uint16_t len) + +{ +return aml_word_as_desc (aml_bus_number_range, min_fixed, max_fixed, dec, + addr_gran, addr_min, addr_max, addr_trans, len,0 ); +} + +/* +* ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.142 WordIO (Word IO Resource Descriptor Macro) +*/ +Aml *aml_word_io (AmlMinFixed min_fixed,AmlMaxFixed max_fixed, +AmlDecode dec,AmlISARanges isa_ranges, +uint16_t addr_gran,uint16_t addr_min, +uint16_t addr_max,uint16_t addr_trans, +uint16_t len) + +{ +return aml_word_as_desc (aml_io_range, min_fixed, max_fixed, dec, + addr_gran, addr_min, addr_max, addr_trans, len, + isa_ranges); +} + +/* +* ACPI 1.0b: 6.4.3.5.4 ASL Macros for DWORD Address Space Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.34 DWordMemory (DWord Memory Resource Descriptor Macro) +*/ +Aml *aml_dword_memory (AmlDecode dec,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlCacheble cacheable, +AmlReadAndWrite read_and_write, +uint32_t addr_gran,uint32_t addr_min, +uint32_t addr_max,uint32_t addr_trans, +uint32_t len) +{ +uint8_t flags = read_and_write | (cacheable <<1 ); + +return aml_dword_as_desc (aml_memory_range, min_fixed, max_fixed, + dec, addr_gran, addr_min, addr_max, + addr_trans, len, flags); +} + +/* +* ACPI 1.0b: 6.4.3.5.2 ASL Macros for QWORD Address Space Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.102 QWordMemory (QWord Memory Resource Descriptor Macro) +*/ +Aml *aml_qword_memory (AmlDecode dec,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlCacheble cacheable, +AmlReadAndWrite read_and_write, +uint64_t addr_gran,uint64_t addr_min, +uint64_t addr_max,uint64_t addr_trans, +uint64_t len) +{ +uint8_t flags = read_and_write | (cacheable <<1 ); + +return aml_qword_as_desc (aml_memory_range, min_fixed, max_fixed, + dec, addr_gran, addr_min, addr_max, + addr_trans, len, flags); +}
include/hw/acpi/aml-build.h +72 -0
84 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 44/52 pc: pcihp: expose MMIO base and len as properties
In reply to Igor Mammedovit will be used later to dynamically reserve MMIO region instead of manually punching holes in PCI0._CRS
--- hw/acpi/pcihp.c | 18 ++++++++++++------ hw/acpi/piix4.c | 2 +- include/hw/acpi/pcihp.h | 7 ++++++- 3 files changed, 19 insertions(+), 8 deletions(-)
hw/acpi/pcihp.c +12 -6
@@ -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 = {
hw/acpi/piix4.c +1 -1
@@ -562,7 +562,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, "acpi-gpe0", GPE_LEN);memory_region_add_subregion (parent,GPE_BASE , &s->io_gpe); -acpi_pcihp_init (&s->acpi_pci_hotplug, bus, parent, +acpi_pcihp_init (OBJECT (s), &s->acpi_pci_hotplug, bus, parent, s->use_acpi_pci_hotplug); acpi_cpu_hotplug_init(parent, OBJECT(s), &s->gpe_cpu,
include/hw/acpi/pcihp.h +6 -1
@@ -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,
Signature · 1 line
1.8.3.1
PATCH v3 45/52 pc: acpi-build: reserve PCIHP MMIO resources
In reply to Igor Mammedov--- hw/i386/acpi-build.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
hw/i386/acpi-build.c +27 -0
@@ -105,6 +105,8 @@ typedef struct AcpiPmInfo {uint16_t cpu_hp_io_len;uint16_t mem_hp_io_base;uint16_t mem_hp_io_len; +uint16_t pcihp_io_base; +uint16_t pcihp_io_len; } AcpiPmInfo; typedef struct AcpiMiscInfo {
@@ -177,9 +179,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)Object *obj =NULL ;QObject *o; + pm->pcihp_io_base =0 ; + pm->pcihp_io_len =0 ;if (piix) { obj = piix; pm->cpu_hp_io_base =PIIX4_CPU_HOTPLUG_IO_BASE ; + pm->pcihp_io_base = +object_property_get_int (obj,ACPI_PCIHP_IO_BASE_PROP ,NULL ); + pm->pcihp_io_len = +object_property_get_int (obj,ACPI_PCIHP_IO_LEN_PROP ,NULL ); }if (lpc) { obj = lpc;
@@ -703,6 +711,25 @@ build_ssdt(Aml *table_data,patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); + scope =aml_scope ("\\_SB.PCI0" ); +/* reserve PCIHP resources */ +if (pm->pcihp_io_len) { + dev =aml_device ("PHPR" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("PCI Hotplug resources" ))); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, pm->pcihp_io_base, pm->pcihp_io_base,1 , + pm->pcihp_io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (scope, dev); + } +aml_append (ssdt, scope); +/* create S3_ / S4_ / S5_ packages if necessary */ scope =aml_scope ("\\" );if (!pm->s3_disabled) {
Signature · 1 line
1.8.3.1
PATCH v3 46/52 pc: acpi-build: create PCI0._CRS dynamically
In reply to Igor MammedovReplace 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.
--- hw/i386/acpi-build.c | 69 ++++++++++++++++---------------- hw/i386/acpi-dsdt-pci-crs.dsl | 92 ------------------------------------------- hw/i386/acpi-dsdt.dsl | 45 --------------------- hw/i386/q35-acpi-dsdt.dsl | 18 --------- hw/i386/ssdt-misc.dsl | 19 --------- 5 files changed, 33 insertions(+), 210 deletions(-) delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl
hw/i386/acpi-build.c +33 -36
@@ -319,24 +319,6 @@ static void acpi_align_size(GArray *blob, unsigned align)g_array_set_size (blob,ROUND_UP (acpi_data_len (blob), align)); } -/* Set a value within table in a safe manner */ -#define ACPI_BUILD_SET_LE (table, size, off, bits, val) \ - do { \ - uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \ - memcpy(acpi_data_get_ptr(table, size, off, \ - (bits) / BITS_PER_BYTE), \ - &ACPI_BUILD_SET_LE_val, \ - (bits) / BITS_PER_BYTE); \ - } while (0) - -static inline void *acpi_data_get_ptr (uint8_t *table_data,unsigned table_size, -unsigned off,unsigned size) -{ -assert (off + size > off); -assert (off + size <= table_size); -return table_data + off; -} -static inline void acpi_add_table (GArray *table_offsets,GArray *table_data) {uint32_t offset =cpu_to_le32 (table_data->len);
@@ -664,22 +646,6 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,aml_append (parent_scope, method); } -static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size) -{ -ACPI_BUILD_SET_LE (start, size, acpi_pci32_start[0 ],32 , pci->w32.begin); - -ACPI_BUILD_SET_LE (start, size, acpi_pci32_end[0 ],32 , pci->w32.end -1 ); - -if (pci->w64.end || pci->w64.begin) { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_start[0 ],64 , pci->w64.begin); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_end[0 ],64 , pci->w64.end -1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_length[0 ],64 , pci->w64.end - pci->w64.begin); - }else { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,0 ); - } -} - static void build_ssdt(Aml *table_data, AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -709,9 +675,40 @@ build_ssdt(Aml *table_data, ssdp_misc_aml +sizeof (AcpiTableHeader), sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader)); -patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); - scope =aml_scope ("\\_SB.PCI0" ); +/* build PCI0._CRS */ + crs =aml_resource_template (); +aml_append (crs, +aml_word_bus_number (aml_min_fixed, aml_max_fixed, aml_pos_decode, +0x0000 ,0x0000 ,0x00FF ,0x0000 ,0x0100 )); +aml_append (crs,aml_io (aml_decode16,0x0CF8 ,0x0CF8 ,0x01 ,0x08 )); + +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0000 ,0x0CF7 ,0x0000 ,0x0CF8 )); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0D00 ,0xFFFF ,0x0000 ,0xF300 )); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 ,0x000A0000 ,0x000BFFFF ,0 ,0x00020000 )); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_non_cacheable, aml_ReadWrite, +0 , pci->w32.begin, pci->w32.end -1 ,0 , + pci->w32.end - pci->w32.begin)); +if (pci->w64.begin) { +aml_append (crs, +aml_qword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 , pci->w64.begin, pci->w64.end -1 ,0 , + pci->w64.end - pci->w64.begin)); + } +aml_append (scope,aml_name_decl ("_CRS" , crs)); +/* reserve PCIHP resources */ if (pm->pcihp_io_len) { dev =aml_device ("PHPR" );
hw/i386/acpi-dsdt-pci-crs.dsl deleted +0 -92
92 lines not on this page · raw message
hw/i386/acpi-dsdt.dsl +0 -45
57 lines not on this page · raw message
hw/i386/q35-acpi-dsdt.dsl +0 -18
@@ -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"
hw/i386/ssdt-misc.dsl +0 -19
@@ -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 }) - } }
Signature · 1 line
1.8.3.1
PATCH v3 47/52 pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
In reply to Igor MammedovIt 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.
--- hw/i386/Makefile.objs | 2 +- hw/i386/acpi-build.c | 12 -- hw/i386/ssdt-misc.dsl | 21 --- hw/i386/ssdt-misc.hex.generated | 399 ---------------------------------------- 4 files changed, 1 insertion(+), 433 deletions(-) delete mode 100644 hw/i386/ssdt-misc.dsl delete mode 100644 hw/i386/ssdt-misc.hex.generated
hw/i386/Makefile.objs +1 -1
@@ -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`" \
hw/i386/acpi-build.c +0 -12
@@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, table_data->len - madt_start, 1); } -#define ACPI_SSDT_SIGNATURE 0x54445353/* SSDT */ -#define ACPI_SSDT_HEADER_LENGTH 36 - -#include "hw/i386/ssdt-misc.hex" #include "hw/i386/ssdt-tpm.hex" /* Assign BSEL property to all buses. In the future, this can be changed
@@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -uint8_t *ssdt_ptr;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;int i;
@@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,ACPI_BUILD_APPNAME4 ,1 , ACPI_BUILD_APPNAME4_HEX, 1); -/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */ -acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - ssdt_ptr = (uint8_t *)ssdt->buf->data; -memcpy (ssdt_ptr +sizeof (AcpiTableHeader), - ssdp_misc_aml +sizeof (AcpiTableHeader), -sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - scope =aml_scope ("\\_SB.PCI0" );/* build PCI0._CRS */ crs =aml_resource_template ();
hw/i386/ssdt-misc.dsl deleted +0 -21
@@ -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) -{ -}
hw/i386/ssdt-misc.hex.generated deleted +0 -399
399 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
Quoted 7 lines · Igor Mammedov
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 taskbuild_ssdt()should be doing/.
Quoted 6 lines
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 <[email protected]>
I see where we drop ssdt_misc here but I don't see acpi_def_block anywhere.
Also pls don't include generated files in patches, they just make rebases painful.
just say in commit log they need to be updated.
Quoted 49 lines
--- hw/i386/Makefile.objs | 2 +- hw/i386/acpi-build.c | 12 -- hw/i386/ssdt-misc.dsl | 21 --- hw/i386/ssdt-misc.hex.generated | 399 ---------------------------------------- 4 files changed, 1 insertion(+), 433 deletions(-) delete mode 100644 hw/i386/ssdt-misc.dsl delete mode 100644 hw/i386/ssdt-misc.hex.generatedhw/i386/Makefile.objs +1
-1@@ -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`" \hw/i386/acpi-build.c +0
-5@@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, table_data->len - madt_start, 1); } -#define ACPI_SSDT_SIGNATURE 0x54445353/* SSDT */ -#define ACPI_SSDT_HEADER_LENGTH 36 - -#include "hw/i386/ssdt-misc.hex" #include "hw/i386/ssdt-tpm.hex" /* Assign BSEL property to all buses. In the future, this can be changed @@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -uint8_t *ssdt_ptr;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;int i;@@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,ACPI_BUILD_APPNAME4 ,1 , ACPI_BUILD_APPNAME4_HEX, 1);
hw/i386/acpi-build.c build_ssdt(Aml *table_data, · line 668
Quoted 10 lines
hw/i386/acpi-build.c +0
-7-/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */ -acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - ssdt_ptr = (uint8_t *)ssdt->buf->data; -memcpy (ssdt_ptr +sizeof (AcpiTableHeader), - ssdp_misc_aml +sizeof (AcpiTableHeader), -sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - scope =aml_scope ("\\_SB.PCI0" );/* build PCI0._CRS */ crs =aml_resource_template ();
So before this patch, we had two headers? I don't see how this makes sense, and it does not match commit log.
Quoted 434 lines
hw/i386/ssdt-misc.dsl deleted +0
-21@@ -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) -{ -}hw/i386/ssdt-misc.hex.generated deleted +0
-399@@ -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 -};Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
Quoted 13 lines · On Tue, 17 Feb 2015 17:44:31 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 12 lines · Igor Mammedov
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 taskbuild_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.
Quoted 5 lines
Quoted 1 line
Signed-off-by Igor Mammedov <[email protected]>I see where we drop
ssdt_mischere but I don't seeacpi_def_blockanywhere.
that's been introduced when conversion began in patch:
[6/52] pc: acpi-build: use aml_def_block() for declaring SSDT table"
Quoted 3 lines
Also pls don't include generated files in patches, they just make rebases painful.
just say in commit log they need to be updated.
sure
Quoted 50 lines
Quoted 50 lines
--- hw/i386/Makefile.objs | 2 +- hw/i386/acpi-build.c | 12 -- hw/i386/ssdt-misc.dsl | 21 --- hw/i386/ssdt-misc.hex.generated | 399 ---------------------------------------- 4 files changed, 1 insertion(+), 433 deletions(-) delete mode 100644 hw/i386/ssdt-misc.dsl delete mode 100644 hw/i386/ssdt-misc.hex.generatedhw/i386/Makefile.objs +1
-1@@ -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`" \hw/i386/acpi-build.c +0
-5@@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, table_data->len - madt_start, 1); } -#define ACPI_SSDT_SIGNATURE 0x54445353/* SSDT */ -#define ACPI_SSDT_HEADER_LENGTH 36 - -#include "hw/i386/ssdt-misc.hex" #include "hw/i386/ssdt-tpm.hex" /* Assign BSEL property to all buses. In the future, this can be changed @@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -uint8_t *ssdt_ptr;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;int i;@@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,ACPI_BUILD_APPNAME4 ,1 , ACPI_BUILD_APPNAME4_HEX, 1);
Quoted 14 lines
hw/i386/acpi-build.c build_ssdt(Aml *table_data, · line 668
Quoted 10 lines
hw/i386/acpi-build.c +0
-7-/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */ -acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - ssdt_ptr = (uint8_t *)ssdt->buf->data; -memcpy (ssdt_ptr +sizeof (AcpiTableHeader), - ssdp_misc_aml +sizeof (AcpiTableHeader), -sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - scope =aml_scope ("\\_SB.PCI0" );/* build PCI0._CRS */ crs =aml_resource_template ();So before this patch, we had two headers? I don't see how this makes sense, and it does not match commit log.
nope, see
[6/52] pc: acpi-build: use aml_def_block() for declaring SSDT table" where header from template is skipped and only content is copied
Quoted 436 lines
Quoted 436 lines
hw/i386/ssdt-misc.dsl deleted +0
-21@@ -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) -{ -}hw/i386/ssdt-misc.hex.generated deleted +0
-399@@ -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 -};Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()
Quoted 16 lines · Igor Mammedov
Quoted 13 lines · On Tue, 17 Feb 2015 17:44:31 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 12 lines · Igor Mammedov
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 taskbuild_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.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Igor Mammedov <[email protected]>I see where we drop
ssdt_mischere but I don't seeacpi_def_blockanywhere.that's been introduced when conversion began in patch:
[6/52] pc: acpi-build: useaml_def_block()for declaring SSDT table"
OK, the description is confusing. just say dsl is now empty.
Quoted 69 lines
Quoted 3 lines
Also pls don't include generated files in patches, they just make rebases painful.
just say in commit log they need to be updated.sure
Quoted 50 lines
Quoted 50 lines
--- hw/i386/Makefile.objs | 2 +- hw/i386/acpi-build.c | 12 -- hw/i386/ssdt-misc.dsl | 21 --- hw/i386/ssdt-misc.hex.generated | 399 ---------------------------------------- 4 files changed, 1 insertion(+), 433 deletions(-) delete mode 100644 hw/i386/ssdt-misc.dsl delete mode 100644 hw/i386/ssdt-misc.hex.generatedhw/i386/Makefile.objs +1
-1@@ -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`" \hw/i386/acpi-build.c +0
-5@@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, table_data->len - madt_start, 1); } -#define ACPI_SSDT_SIGNATURE 0x54445353/* SSDT */ -#define ACPI_SSDT_HEADER_LENGTH 36 - -#include "hw/i386/ssdt-misc.hex" #include "hw/i386/ssdt-tpm.hex" /* Assign BSEL property to all buses. In the future, this can be changed @@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -uint8_t *ssdt_ptr;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;int i;@@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,ACPI_BUILD_APPNAME4 ,1 , ACPI_BUILD_APPNAME4_HEX, 1);Quoted 14 lines
hw/i386/acpi-build.c build_ssdt(Aml *table_data, · line 668
Quoted 10 lines
hw/i386/acpi-build.c +0
-7-/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */ -acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - ssdt_ptr = (uint8_t *)ssdt->buf->data; -memcpy (ssdt_ptr +sizeof (AcpiTableHeader), - ssdp_misc_aml +sizeof (AcpiTableHeader), -sizeof (ssdp_misc_aml) -sizeof (AcpiTableHeader)); - scope =aml_scope ("\\_SB.PCI0" );/* build PCI0._CRS */ crs =aml_resource_template ();So before this patch, we had two headers? I don't see how this makes sense, and it does not match commit log.
Quoted 3 lines
nope, see
[6/52] pc: acpi-build: useaml_def_block()for declaring SSDT table" where header from template is skipped and only content is copied
Pls squash this chunk there then.
Quoted 436 lines
Quoted 436 lines
Quoted 436 lines
hw/i386/ssdt-misc.dsl deleted +0
-21@@ -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) -{ -}hw/i386/ssdt-misc.hex.generated deleted +0
-399@@ -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 -};Signature · 1 line
1.8.3.1
PATCH v3 48/52 acpi: add acpi_irq_no_flags() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 21 +++++++++++++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 22 insertions(+)
hw/acpi/aml-build.c +21 -0
@@ -554,6 +554,27 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,return var; } +/* +* ACPI 1.0b: 6.4.2.1.1 ASL Macro for IRQ Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro) +* 6.4.2.1 IRQ Descriptor +*/ +Aml *aml_irq_no_flags (uint8_t irq) +{ +uint16_t irq_mask; +Aml *var =aml_alloc (); + +assert (irq <16 ); +build_append_byte (var->buf,0x22 );/* IRQ descriptor 2 byte form */ + + irq_mask =1U << irq; +build_append_byte (var->buf, irq_mask &0xFF );/* IRQ mask bits[7:0] */ +build_append_byte (var->buf, irq_mask >>8 );/* IRQ mask bits[15:8] */ +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */ Aml *aml_equal (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -156,6 +156,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, uint8_t aln, uint8_t len);Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len); +Aml *aml_irq_no_flags (uint8_t irq);Aml *aml_named_field (const char *name,unsigned length);Aml *aml_reserved_field (unsigned length);Aml *aml_local (int num);
Signature · 1 line
1.8.3.1
PATCH v3 49/52 pc: export applesmc IO port/len
In reply to Igor MammedovIO port and length will be used in following patch to correctly generate SMC ACPI device in SSDT.
--- hw/i386/acpi-build.c | 2 +- hw/misc/applesmc.c | 5 ++--- include/hw/isa/isa.h | 11 +++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-)
hw/i386/acpi-build.c +1 -1
@@ -144,7 +144,7 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)/* Patch in appropriate value for AppleSMC _STA */ *(uint8_t *)(info->dsdt_code + *applesmc_sta) = -applesmc_find () ?0x0b :0x00 ; +applesmc_port () ?0x0b :0x00 ; } static
hw/misc/applesmc.c +2 -3
@@ -43,7 +43,6 @@/* command/status port used by Apple SMC */ #define APPLESMC_CMD_PORT 0x4#define APPLESMC_NR_PORTS 32 -#define APPLESMC_MAX_DATA_LENGTH 32#define APPLESMC_READ_CMD 0x10#define APPLESMC_WRITE_CMD 0x11
@@ -249,8 +248,8 @@ static void applesmc_isa_realize(DeviceState *dev, Error **errp) }static Property applesmc_isa_properties[] = { -DEFINE_PROP_UINT32 ("iobase" , AppleSMCState, iobase, -APPLESMC_DEFAULT_IOBASE ), +DEFINE_PROP_UINT32 (APPLESMC_PROP_IO_BASE , AppleSMCState, iobase, +APPLESMC_DEFAULT_IOBASE ),DEFINE_PROP_STRING ("osk" , AppleSMCState, osk),DEFINE_PROP_END_OF_LIST (), };
include/hw/isa/isa.h +9 -2
@@ -21,10 +21,17 @@#define ISA_BUS (obj) OBJECT_CHECK(ISABus, (obj), TYPE_ISA_BUS)#define TYPE_APPLE_SMC "isa-applesmc" +#define APPLESMC_MAX_DATA_LENGTH 32 +#define APPLESMC_PROP_IO_BASE "iobase" -static inline bool applesmc_find (void ) +static inline uint16_t applesmc_port (void ) { -return object_resolve_path_type ("" ,TYPE_APPLE_SMC ,NULL ); +Object *obj =object_resolve_path_type ("" ,TYPE_APPLE_SMC ,NULL ); + +if (obj) { +return object_property_get_int (obj,APPLESMC_PROP_IO_BASE ,NULL ); + } +return 0 ; } typedef struct ISADeviceClass {
Signature · 1 line
1.8.3.1
PATCH v3 50/52 pc: acpi-build: drop template patching and create Device(SMC) dynamically
In reply to Igor Mammedovpatch moves SMC device into SSDT and creates it only when device is present, which makes ACPI tables smaller in default case when device is not present.
PS:
also it fixes wrong IO range in CRS if "iobase" property is set to a not default value.
--- hw/i386/acpi-build.c | 29 ++++++++++++++++++++++------- hw/i386/acpi-dsdt-isa.dsl | 11 ----------- hw/i386/acpi-dsdt.dsl | 1 - hw/i386/q35-acpi-dsdt.dsl | 1 - 4 files changed, 22 insertions(+), 20 deletions(-)
hw/i386/acpi-build.c +22 -7
@@ -115,6 +115,7 @@ typedef struct AcpiMiscInfo {const unsigned char *dsdt_code;unsigned dsdt_size;uint16_t pvpanic_port; +uint16_t applesmc_io_base; } AcpiMiscInfo; typedef struct AcpiBuildPciBusHotplugState {
@@ -126,7 +127,6 @@ typedef struct AcpiBuildPciBusHotplugState {static void acpi_get_dsdt (AcpiMiscInfo *info) { -uint16_t *applesmc_sta;Object *piix =piix4_pm_find ();Object *lpc =ich9_lpc_find ();assert (!!piix != !!lpc);
@@ -134,17 +134,11 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)if (piix) { info->dsdt_code = AcpiDsdtAmlCode; info->dsdt_size =sizeof AcpiDsdtAmlCode; - applesmc_sta = piix_dsdt_applesmc_sta; }if (lpc) { info->dsdt_code = Q35AcpiDsdtAmlCode; info->dsdt_size =sizeof Q35AcpiDsdtAmlCode; - applesmc_sta = q35_dsdt_applesmc_sta; } - -/* Patch in appropriate value for AppleSMC _STA */ - *(uint8_t *)(info->dsdt_code + *applesmc_sta) = -applesmc_port () ?0x0b :0x00 ; } static
@@ -247,6 +241,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) info->has_hpet =hpet_find (); info->has_tpm =tpm_find (); info->pvpanic_port =pvpanic_port (); + info->applesmc_io_base =applesmc_port (); }static void acpi_get_pci_info (PcPciInfo *info)
@@ -743,6 +738,26 @@ build_ssdt(Aml *table_data,aml_append (scope,aml_name_decl ("_S5" , pkg));aml_append (ssdt, scope); +if (misc->applesmc_io_base) { + scope =aml_scope ("\\_SB.PCI0.ISA" ); + dev =aml_device ("SMC" ); + +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("APP0001" ))); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, misc->applesmc_io_base, misc->applesmc_io_base, +0x01 ,APPLESMC_MAX_DATA_LENGTH ) + ); +aml_append (crs,aml_irq_no_flags (6 )); +aml_append (dev,aml_name_decl ("_CRS" , crs)); + +aml_append (scope, dev); +aml_append (ssdt, scope); + } +if (misc->pvpanic_port) { scope =aml_scope ("\\_SB.PCI0.ISA" );
hw/i386/acpi-dsdt-isa.dsl +0 -11
@@ -16,17 +16,6 @@ /* Common legacy ISA style devices. */ Scope(\_SB.PCI0.ISA) { - Device (SMC) { - Name(_HID, EisaId("APP0001")) - /* _STA will be patched to 0x0B if AppleSMC is present */ - ACPI_EXTRACT_NAME_BYTE_CONST DSDT_APPLESMC_STA - Name(_STA, 0xF0) - Name(_CRS, ResourceTemplate () { - IO (Decode16, 0x0300, 0x0300, 0x01, 0x20) - IRQNoFlags() { 6 } - }) - } - Device(RTC) { Name(_HID, EisaId("PNP0B00")) Name(_CRS, ResourceTemplate() {
hw/i386/acpi-dsdt.dsl +0 -1
@@ -85,7 +85,6 @@ DefinitionBlock ( } } -#define DSDT_APPLESMC_STA piix_dsdt_applesmc_sta #include "acpi-dsdt-isa.dsl"
hw/i386/q35-acpi-dsdt.dsl +0 -1
@@ -150,7 +150,6 @@ DefinitionBlock ( } } -#define DSDT_APPLESMC_STA q35_dsdt_applesmc_sta #include "acpi-dsdt-isa.dsl"
Signature · 1 line
1.8.3.1
PATCH v3 51/52 pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC
In reply to Igor Mammedovso that build on IASL less hosts won't fail due to present but unused variable warning
--- hw/i386/acpi-dsdt.hex.generated | 714 ++---------------------------------- hw/i386/q35-acpi-dsdt.hex.generated | 662 ++------------------------------- 2 files changed, 58 insertions(+), 1318 deletions(-)
hw/i386/acpi-dsdt.hex.generated +30 -684
@@ -3,12 +3,12 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x53, 0x44, 0x54, -0x25, -0xe, +0x9a, +0xb, 0x0, 0x0, 0x1, -0x6c, +0xe1, 0x42, 0x58, 0x50,
@@ -31,8 +31,8 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x4e, 0x54, 0x4c, -0x7, -0x11, +0x26, +0x9, 0x14, 0x20, 0x10,
@@ -145,405 +145,6 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x44, 0x1, 0x10, -0x4e, -0x18, -0x2e, -0x5f, -0x53, -0x42, -0x5f, -0x50, -0x43, -0x49, -0x30, -0x8, -0x43, -0x52, -0x45, -0x53, -0x11, -0x42, -0xa, -0xa, -0x9e, -0x88, -0xd, -0x0, -0x2, -0xc, -0x0, -0x0, -0x0, -0x0, -0x0, -0xff, -0x0, -0x0, -0x0, -0x0, -0x1, -0x47, -0x1, -0xf8, -0xc, -0xf8, -0xc, -0x1, -0x8, -0x88, -0xd, -0x0, -0x1, -0xc, -0x3, -0x0, -0x0, -0x0, -0x0, -0xf7, -0xc, -0x0, -0x0, -0xf8, -0xc, -0x88, -0xd, -0x0, -0x1, -0xc, -0x3, -0x0, -0x0, -0x0, -0xd, -0xff, -0xad, -0x0, -0x0, -0x0, -0xa1, -0x88, -0xd, -0x0, -0x1, -0xc, -0x3, -0x0, -0x0, -0xf, -0xae, -0xff, -0xae, -0x0, -0x0, -0xf1, -0x0, -0x88, -0xd, -0x0, -0x1, -0xc, -0x3, -0x0, -0x0, -0x20, -0xaf, -0xdf, -0xaf, -0x0, -0x0, -0xc0, -0x0, -0x88, -0xd, -0x0, -0x1, -0xc, -0x3, -0x0, -0x0, -0xe4, -0xaf, -0xff, -0xff, -0x0, -0x0, -0x1c, -0x50, -0x87, -0x17, -0x0, -0x0, -0xc, -0x3, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0xa, -0x0, -0xff, -0xff, -0xb, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x2, -0x0, -0x87, -0x17, -0x0, -0x0, -0xc, -0x1, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0xe0, -0xff, -0xff, -0xbf, -0xfe, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0xc0, -0x1e, -0x79, -0x0, -0x8, -0x43, -0x52, -0x36, -0x34, -0x11, -0x33, -0xa, -0x30, -0x8a, -0x2b, -0x0, -0x0, -0xc, -0x3, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x80, -0x0, -0x0, -0x0, -0xff, -0xff, -0xff, -0xff, -0xff, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x80, -0x0, -0x0, -0x0, -0x79, -0x0, -0x14, -0x41, -0xa, -0x5f, -0x43, -0x52, -0x53, -0x0, -0x8a, -0x43, -0x52, -0x45, -0x53, -0xa, -0x8c, -0x50, -0x53, -0x33, -0x32, -0x8a, -0x43, -0x52, -0x45, -0x53, -0xa, -0x90, -0x50, -0x45, -0x33, -0x32, -0x8a, -0x43, -0x52, -0x45, -0x53, -0xa, -0x98, -0x50, -0x4c, -0x33, -0x32, -0x70, -0x50, -0x30, -0x53, -0x5f, -0x50, -0x53, -0x33, -0x32, -0x70, -0x50, -0x30, -0x45, -0x5f, -0x50, -0x45, -0x33, -0x32, -0x70, -0x72, -0x74, -0x50, -0x30, -0x45, -0x5f, -0x50, -0x30, -0x53, -0x5f, -0x0, -0x1, -0x0, -0x50, -0x4c, -0x33, -0x32, -0xa0, -0xc, -0x93, -0x50, -0x31, -0x56, -0x5f, -0x0, -0xa4, -0x43, -0x52, -0x45, -0x53, -0x8f, -0x43, -0x52, -0x36, -0x34, -0xa, -0xe, -0x50, -0x53, -0x36, -0x34, -0x8f, -0x43, -0x52, -0x36, -0x34, -0xa, -0x16, -0x50, -0x45, -0x36, -0x34, -0x8f, -0x43, -0x52, -0x36, -0x34, -0xa, -0x26, -0x50, -0x4c, -0x36, -0x34, -0x70, -0x50, -0x31, -0x53, -0x5f, -0x50, -0x53, -0x36, -0x34, -0x70, -0x50, -0x31, -0x45, -0x5f, -0x50, -0x45, -0x36, -0x34, -0x70, -0x50, -0x31, -0x4c, -0x5f, -0x50, -0x4c, -0x36, -0x34, -0x84, -0x43, -0x52, -0x45, -0x53, -0x43, -0x52, -0x36, -0x34, -0x60, -0xa4, -0x60, -0x10, 0x4d, 0x8, 0x5f,
@@ -801,78 +402,32 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x3, 0x43, 0x42, -0x45, -0x4e, -0x1, -0x8, -0x46, -0x44, -0x45, -0x4e, -0x1, -0x10, -0x4a, -0x1e, -0x2f, -0x3, -0x5f, -0x53, -0x42, -0x5f, -0x50, -0x43, -0x49, -0x30, -0x49, -0x53, -0x41, -0x5f, -0x5b, -0x82, -0x2c, -0x53, -0x4d, -0x43, -0x5f, -0x8, -0x5f, -0x48, -0x49, -0x44, -0xc, -0x6, -0x10, -0x0, +0x45, +0x4e, 0x1, 0x8, +0x46, +0x44, +0x45, +0x4e, +0x1, +0x10, +0x4c, +0x1b, +0x2f, +0x3, 0x5f, 0x53, -0x54, -0x41, -0xa, -0xf0, -0x8, +0x42, 0x5f, +0x50, 0x43, -0x52, +0x49, +0x30, +0x49, 0x53, -0x11, -0x10, -0xa, -0xd, -0x47, -0x1, -0x0, -0x3, -0x0, -0x3, -0x1, -0x20, -0x22, -0x40, -0x0, -0x79, -0x0, +0x41, +0x5f, 0x5b, 0x82, 0x2d,
@@ -2318,8 +1873,8 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x53, 0x1, 0x10, -0x4f, -0x12, +0x4d, +0xc, 0x5f, 0x53, 0x42,
@@ -2416,32 +1971,6 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x22, 0xa, 0xc8, -0x5b, -0x80, -0x50, -0x52, -0x53, -0x54, -0x1, -0xb, -0x0, -0xaf, -0xa, -0x20, -0x5b, -0x81, -0xc, -0x50, -0x52, -0x53, -0x54, -0x1, -0x50, -0x52, -0x53, -0x5f, -0x40, -0x10, 0x14, 0x4a, 0x6,
@@ -2549,81 +2078,9 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x3, 0x75, 0x60, -0x5b, -0x82, -0x46, -0x4, -0x50, -0x52, -0x45, -0x53, -0x8, -0x5f, -0x48, -0x49, -0x44, -0xc, -0x41, -0xd0, -0xa, -0x6, -0x8, -0x5f, -0x55, -0x49, -0x44, -0xd, -0x43, -0x50, -0x55, -0x20, -0x68, -0x6f, -0x74, -0x70, -0x6c, -0x75, -0x67, -0x20, -0x72, -0x65, -0x73, -0x6f, -0x75, -0x72, -0x63, -0x65, -0x73, -0x0, -0x8, -0x5f, -0x43, -0x52, -0x53, -0x11, -0xd, -0xa, -0xa, -0x47, -0x1, -0x0, -0xaf, -0x0, -0xaf, -0x0, -0x20, -0x79, -0x0, -0x8, -0x5f, -0x53, -0x54, -0x41, -0xa, -0xb, 0x10, -0x40, -0x31, +0x44, +0x2a, 0x2e, 0x5f, 0x53,
@@ -2635,8 +2092,8 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x30, 0x5b, 0x82, -0x43, -0x30, +0x47, +0x29, 0x4d, 0x48, 0x50,
@@ -2686,37 +2143,6 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x65, 0x73, 0x0, -0x5b, -0x80, -0x48, -0x50, -0x4d, -0x52, -0x1, -0xb, -0x0, -0xa, -0xa, -0x18, -0x8, -0x5f, -0x43, -0x52, -0x53, -0x11, -0xd, -0xa, -0xa, -0x47, -0x1, -0x0, -0xa, -0x0, -0xa, -0x0, -0x18, -0x79, -0x0, 0x14, 0x13, 0x5f,
@@ -2738,89 +2164,12 @@ static unsigned char AcpiDsdtAmlCode[] = { 0xa, 0xb, 0x5b, -0x81, -0x1f, -0x48, -0x50, -0x4d, -0x52, -0x3, -0x4d, -0x52, -0x42, -0x4c, -0x20, -0x4d, -0x52, -0x42, -0x48, -0x20, -0x4d, -0x52, -0x4c, -0x4c, -0x20, -0x4d, -0x52, -0x4c, -0x48, -0x20, -0x4d, -0x50, -0x58, -0x5f, -0x20, -0x5b, -0x81, -0x13, -0x48, -0x50, -0x4d, -0x52, -0x1, -0x0, -0x40, -0xa, -0x4d, -0x45, -0x53, -0x5f, -0x1, -0x4d, -0x49, -0x4e, -0x53, -0x1, -0x5b, 0x1, 0x4d, 0x4c, 0x43, 0x4b, 0x0, -0x5b, -0x81, -0x15, -0x48, -0x50, -0x4d, -0x52, -0x3, -0x4d, -0x53, -0x45, -0x4c, -0x20, -0x4d, -0x4f, -0x45, -0x56, -0x20, -0x4d, -0x4f, -0x53, -0x43, -0x20, 0x14, 0x4a, 0x4,
@@ -3621,6 +2970,3 @@ static unsigned char AcpiDsdtAmlCode[] = { 0x46, 0x0 }; -static unsigned short piix_dsdt_applesmc_sta[] = { -0x353 -};
hw/i386/q35-acpi-dsdt.hex.generated +28 -634
740 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 52/52 acpi: make build_*() routines static to aml-build.c
In reply to Igor Mammedovbuild_*() routines were used for composing AML structures manually in acpi-build.c but after conversion to AML API they are not used outside of aml-build.c anymore, so hide them from external users.
--- hw/acpi/aml-build.c | 22 +++++++++++----------- include/hw/acpi/aml-build.h | 17 ----------------- 2 files changed, 11 insertions(+), 28 deletions(-)
hw/acpi/aml-build.c +11 -11
@@ -28,27 +28,27 @@#include "qemu/bswap.h" #include "hw/acpi/bios-linker-loader.h" -GArray *build_alloc_array (void ) +static GArray *build_alloc_array (void ) {return g_array_new (false, true/* clear */ ,1 ); } -void build_free_array (GArray *array) +static void build_free_array (GArray *array) {g_array_free (array, true); } -void build_prepend_byte (GArray *array,uint8_t val) +static void build_prepend_byte (GArray *array,uint8_t val) {g_array_prepend_val (array, val); } -void build_append_byte (GArray *array,uint8_t val) +static void build_append_byte (GArray *array,uint8_t val) {g_array_append_val (array, val); } -void build_append_array (GArray *array,GArray *val) +static void build_append_array (GArray *array,GArray *val) {g_array_append_vals (array, val->data, val->len); }
@@ -142,7 +142,7 @@ build_append_namestringv(GArray *array, const char *format, va_list ap)g_strfreev (segs); } -void build_append_namestring (GArray *array,const char *format, ...) +static void build_append_namestring (GArray *array,const char *format, ...) {va_list ap;
@@ -159,7 +159,7 @@ enum { PACKAGE_LENGTH_4BYTE_SHIFT = 20, }; -void +static void build_prepend_package_length (GArray *package,unsigned length,bool incl_self) {uint8_t byte;
@@ -227,19 +227,19 @@ build_append_pkg_length(GArray *array, unsigned length, bool incl_self)build_free_array (tmp); } -void build_package (GArray *package,uint8_t op) +static void build_package (GArray *package,uint8_t op) {build_prepend_package_length (package, package->len, true);build_prepend_byte (package, op); } -void build_extop_package (GArray *package,uint8_t op) +static void build_extop_package (GArray *package,uint8_t op) {build_package (package, op);build_prepend_byte (package,0x5B );/* ExtOpPrefix */ } -void build_append_value (GArray *table,uint64_t value,int size) +static void build_append_value (GArray *table,uint64_t value,int size) {int i;
@@ -249,7 +249,7 @@ void build_append_value(GArray *table, uint64_t value, int size) } } -void build_append_int (GArray *table,uint64_t value) +static void build_append_int (GArray *table,uint64_t value) {if (value ==0x00 ) {build_append_byte (table,0x00 );/* ZeroOp */
include/hw/acpi/aml-build.h +0 -17
@@ -202,21 +202,4 @@ Aml *aml_resource_template(void);Aml *aml_field (const char *name,AmlFieldFlags flags);Aml *aml_varpackage (uint32_t num_elements); -/* other helpers */ -GArray *build_alloc_array (void ); -void build_free_array (GArray *array); -void build_prepend_byte (GArray *array,uint8_t val); -void build_append_byte (GArray *array,uint8_t val); -void build_append_array (GArray *array,GArray *val); - -void GCC_FMT_ATTR(2, 3) -build_append_namestring(GArray *array, const char *format, ...); - -void -build_prepend_package_length(GArray *package, unsigned length, bool incl_self); -void build_package(GArray *package, uint8_t op); -void build_append_value(GArray *table, uint64_t value, int size); -void build_append_int(GArray *table, uint64_t value); -void build_extop_package(GArray *package, uint8_t op); -#endif
Signature · 1 line
1.8.3.1
This seems to change the contents of the tables in too many ways. So of it needs changing since PCI are somewhat broken by your recent patch.
So let's do this: please prepare a minimal patchset that just generates PCI description dynamically. Drop everything that's not necessary, and verify that make check produces trivial diffs only.
We'll go from there.
Signature · 1 line
MST
Quoted 2 lines · On Tue, 17 Feb 2015 17:47:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
This seems to change the contents of the tables in too many ways. So of it needs changing since PCI are somewhat broken by your recent patch.
In which way is it broken?
Quoted 7 lines
So let's do this: please prepare a minimal patchset that just generates PCI description dynamically. Drop everything that's not necessary, and verify that make check produces trivial diffs only.
We'll go from there.
Quoted 6 lines · Igor Mammedov
Quoted 2 lines · On Tue, 17 Feb 2015 17:47:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
This seems to change the contents of the tables in too many ways. So of it needs changing since PCI are somewhat broken by your recent patch.
In which way is it broken?
Try make check and look at the diffs.
They shouldn't be so big.
I want differences to be trivial, e.g. 0->Zero would be ok.
Refactoring code generation should be separate from changing generated code.
Quoted 7 lines
Quoted 7 lines
So let's do this: please prepare a minimal patchset that just generates PCI description dynamically. Drop everything that's not necessary, and verify that make check produces trivial diffs only.
We'll go from there.
Quoted 6 lines · On Tue, 17 Feb 2015 20:14:06 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov
Quoted 2 lines · On Tue, 17 Feb 2015 17:47:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
This seems to change the contents of the tables in too many ways. So of it needs changing since PCI are somewhat broken by your recent patch.
Quoted 8 lines
Quoted 1 line
In which way is it broken?
Try make check and look at the diffs.
They shouldn't be so big.
I want differences to be trivial, e.g. 0->Zero would be ok.
Refactoring code generation should be separate from changing generated code.
if you run make check on whole series you will of cause se a lot of changes however if you run make check on every patch that switches current code to AML API you'll see small incremental changes, that's basically every patch with prefix: "pc: acpi-build: "
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
So let's do this: please prepare a minimal patchset that just generates PCI description dynamically. Drop everything that's not necessary, and verify that make check produces trivial diffs only.
We'll go from there.