ACPI refactoring: replace template patching with C AML API
v4 cover ACPI refactoring: replace template patching with C AML API
changes since v3:
* drop acpi_def_block() for now
* exclude PCI refactoring
* minor ammends as requested on list
* not much tested, but XP boots.
changes since v2:
* rename acpi prefixes in API to aml
* reverse conversion order from bottom->top to top->bottom
* introduce internal Aml garbage collector and 2 API functions to initialize and cleanup it up
* replace acpi_argX() helpers with a single aml_arg(X) helper do the same for acpi_localX() helpers.
* add 3 internal allocators, for allocating dummy Aml struct for helpers aml_alloc(), aml_opcode(OPCODE) for simple Aml elements and aml_bundle(opcode, kind) for complex elements that require post-processing after element has been composed
* amend spec references to ACPI 1.0b and later if AML element was introduced later
* various codestyle fixes
* rebase on top of PCI tree
changes since RFC:
* conflicts with vmgenid (broken) patches, so it's not based on PCI tree
* rebased on top of today's master +
[PATCH v5 0/5] pc: acpi: various fixes and cleanups +
some patches from PCI tree that above series depends on
* small cleanups
* droped [42/47] acpi: make tables linker-loader available to other targets since Michael has a cleaner similar patch(es) in PCI tree,
so reuse them (not included in here)
* move SMC device from DSDT to SSDT and create it only when applesmc device is present.
This series refactors SSDT runtime composing and gets rid of:
* patching AML templates, with related pointer arithmetic magic
* manual AML composition, i.e. creating AML terms practically byte by byte
* using AML templates for SSDT creation, reducing dependency on IASL. as result of above, QEMU source tree doesn't have to carry 'binary' template blobs that used to be part of SSDT.
* hand-crafted PCI0._CRSes for pc/q35 machines in DSDT with manual hole punching of reserved resources
and adds following:
* introduces ASL like API for creating AML objects using ASL like constructs/terms. API:
* provides a necessary minimum set of terms/helpers to replace currently used SSDT templates.
* simplifies AML composition and keeps track of AML object contexts, transparently managing their (de)allocation and merging into parent context, making composition of SSDT 'almost' like writing native ASL definition of the table.
* hides pointer arithmetic from user when composing SSDT.
* dynamically creates unified PCI0._CRS in SSDT for pc/q35 machines allowing to reserve resources at runtime vs current compile time
* while adding new API, make it target independed CONFIG_ACPI and also make some other utilities for composing ACPI tables target independed (i.e. utils on which API depends) so that they could be reused for ARM target later without moving stuff around uncessarily.
* trims SSDT by not creating objects that are not present (S[34] Package if disabled, pvpanic, applesmc)
As result of replacing AML templates with ASL API, codebase reduces on ~1900LOC even with net addition of API 1050LOC counted in.
Tested with XPsp3, WS2012R2, RHEL6/7 guests.
Git tree for playing with:
https://github.com/imammedo/qemu/commits/ASL_API_v4
Igor Mammedov (42):
acpi: introduce AML composer aml_append()
acpi: add aml_scope() term
pc: acpi-build: use aml_scope() for \_SB scope
acpi: add aml_device() term
acpi: add aml_method() term
acpi: add aml_if() term
acpi: add aml_name() & aml_name_decl() term
acpi: add aml_int() term
acpi: add aml_return() term
acpi: add aml_arg() term
acpi: add aml_store() term
acpi: add aml_and() term
acpi: add aml_notify() term
acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
acpi: add aml_package() term
pc: acpi-build: generate _S[345] packages dynamically
acpi: add aml_buffer() term
acpi: add aml_resource_template() helper
acpi: add aml_io() helper
acpi: include PkgLength size only when requested
acpi: add aml_operation_region() term
acpi: add aml_field() & aml_named_field() terms
acpi: add aml_local() term
acpi: add aml_string() term
pc: acpi-build: generate pvpanic device description dynamically
acpi: add aml_varpackage() term
acpi: add aml_equal() term
acpi: add aml_processor() term
acpi: add aml_eisaid() term
pc: acpi-build: drop template patching and CPU hotplug objects
dynamically
pc: acpi-build: create CPU hotplug IO region dynamically
acpi: add aml_reserved_field() term
pc: acpi-build: drop template patching and memory hotplug objects
dynamically
pc: acpi-build: create memory hotplug IO region dynamically
acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(),
aml_qword_memory() terms
pc: pcihp: expose MMIO base and len as properties
pc: acpi-build: reserve PCIHP MMIO resources
pc: acpi-build: create PCI0._CRS dynamically
pc: acpi-build: drop remaining ssdt_misc template
acpi: add acpi_irq_no_flags() term
pc: export applesmc IO port/len
pc: acpi-build: drop template patching and create Device(SMC)
dynamically
hw/acpi/aml-build.c | 681 ++++++++++++++++++++++++++++++++++++-- hw/acpi/pcihp.c | 18 +- hw/acpi/piix4.c | 2 +- hw/i386/Makefile.objs | 5 +- hw/i386/acpi-build.c | 503 ++++++++++++++++++---------- hw/i386/acpi-dsdt-cpu-hotplug.dsl | 17 +- hw/i386/acpi-dsdt-isa.dsl | 11 - hw/i386/acpi-dsdt-mem-hotplug.dsl | 36 +- hw/i386/acpi-dsdt-pci-crs.dsl | 92 ----- hw/i386/acpi-dsdt.dsl | 46 --- hw/i386/q35-acpi-dsdt.dsl | 19 -- hw/i386/ssdt-mem.dsl | 77 ----- hw/i386/ssdt-misc.dsl | 122 ------- hw/i386/ssdt-proc.dsl | 63 ---- hw/misc/applesmc.c | 5 +- include/hw/acpi/aml-build.h | 190 ++++++++++- include/hw/acpi/pc-hotplug.h | 1 + include/hw/acpi/pcihp.h | 7 +- include/hw/isa/isa.h | 11 +- 19 files changed, 1205 insertions(+), 701 deletions(-) delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl delete mode 100644 hw/i386/ssdt-mem.dsl delete mode 100644 hw/i386/ssdt-misc.dsl delete mode 100644 hw/i386/ssdt-proc.dsl
Signature · 1 line
1.8.3.1
PATCH v4 1/42 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 | 78 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+)
hw/acpi/aml-build.c +78 -0
@@ -25,6 +25,7 @@#include <stdbool.h> #include <string.h> #include "hw/acpi/aml-build.h" +#include "qemu/bswap.h" GArray *build_alloc_array (void ) {
@@ -257,3 +258,80 @@ void build_append_int(GArray *table, uint32_t value)build_append_value (table, value,4 ); } } + +static GPtrArray *alloc_list; + +static Aml *aml_alloc (void ) +{ +Aml *var =g_new0 (typeof (*var),1 ); + +g_ptr_array_add (alloc_list, var); + var->block_flags =AML_NO_OPCODE ; + var->buf =build_alloc_array (); +return var; +} + +static void aml_free (gpointer data) +{ +Aml *var = data; +build_free_array (var->buf); +} + +Aml *init_aml_allocator (void ) +{ +Aml *var; + +assert (!alloc_list); + alloc_list =g_ptr_array_new_with_free_func (aml_free); + var =aml_alloc (); +return var; +} + +void free_aml_allocator (void ) +{ +g_ptr_array_free (alloc_list, true); + alloc_list =0 ; +} + +/* pack data with DefBuffer encoding */ +static void build_buffer (GArray *array,uint8_t op) +{ +GArray *data =build_alloc_array (); + +build_append_int (data, array->len); +g_array_prepend_vals (array, data->data, data->len); +build_free_array (data); +build_package (array, op); +} + +void aml_append (Aml *parent_ctx,Aml *child) +{ +switch (child->block_flags) { +case AML_OPCODE : +build_append_byte (parent_ctx->buf, child->op); +break ; +case AML_EXT_PACKAGE : +build_extop_package (child->buf, child->op); +break ; +case AML_PACKAGE : +build_package (child->buf, child->op); +break ; +case AML_RES_TEMPLATE : +build_append_byte (child->buf,0x79 );/* EndTag */ +/* +* checksum operations are treated as succeeded if checksum +* field is zero. [ACPI Spec 1.0b, 6.4.2.8 End Tag] +*/ +build_append_byte (child->buf,0 ); +/* fall through, to pack resources in buffer */ +case AML_BUFFER : +build_buffer (child->buf, child->op); +break ; +case AML_NO_OPCODE : +break ; +default : +assert (0 ); +break ; + } +build_append_array (parent_ctx->buf, child->buf); +}
include/hw/acpi/aml-build.h +55 -0
61 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 2/42 acpi: add aml_scope() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 20 ++++++++++++++++++++ include/hw/acpi/aml-build.h | 3 +++ 2 files changed, 23 insertions(+)
hw/acpi/aml-build.c +20 -0
@@ -271,6 +271,15 @@ static Aml *aml_alloc(void)return var; } +static Aml *aml_bundle (uint8_t op,AmlBlockFlags flags) +{ +Aml *var =aml_alloc (); + + var->op = op; + var->block_flags = flags; +return var; +} +static void aml_free (gpointer data) {Aml *var = data;
@@ -335,3 +344,14 @@ void aml_append(Aml *parent_ctx, Aml *child) }build_append_array (parent_ctx->buf, child->buf); } + +/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */ +Aml *aml_scope (const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_bundle (0x10 /* ScopeOp */ ,AML_PACKAGE ); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +return var; +}
include/hw/acpi/aml-build.h +3 -0
@@ -59,6 +59,9 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* Block AML object primitives */ +Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +/* other helpers */ GArray *build_alloc_array (void );void build_free_array (GArray *array);
Signature · 1 line
1.8.3.1
PATCH v4 3/42 pc: acpi-build: use aml_scope() for \_SB scope
In reply to Igor Mammedovprepares for incremental conversion of SSDT content to AML API
--- hw/i386/acpi-build.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
hw/i386/acpi-build.c +19 -20
@@ -923,17 +923,18 @@ build_ssdt(GArray *table_data, GArray *linker,MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -int ssdt_start = table_data->len;uint8_t *ssdt_ptr; +Aml *ssdt, *sb_scope;int i; + ssdt =init_aml_allocator ();/* The current AML generator can cover the APIC ID range [0..255], * inclusive, for VCPU hotplug. */ QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 );g_assert (acpi_cpus <=ACPI_CPU_HOTPLUG_ID_LIMIT );/* Copy header and patch values in the S3_ / S4_ / S5_ packages */ - ssdt_ptr =acpi_data_push (table_data,sizeof (ssdp_misc_aml)); + ssdt_ptr =acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml));memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml));if (pm->s3_disabled) { ssdt_ptr[acpi_s3_name[0 ]] ='X' ;
@@ -953,15 +954,11 @@ build_ssdt(GArray *table_data, GArray *linker,ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_mctrl_nr_slots[0 ],32 , nr_mem); + sb_scope =aml_scope ("_SB" ); { -GArray *sb_scope =build_alloc_array (); -uint8_t op =0x10 ;/* ScopeOp */ - -build_append_namestring (sb_scope,"_SB" ); -/* build Processor object for each processor */ for (i =0 ; i < acpi_cpus; i++) { -uint8_t *proc =acpi_data_push (sb_scope,ACPI_PROC_SIZEOF ); +uint8_t *proc =acpi_data_push (sb_scope->buf,ACPI_PROC_SIZEOF );memcpy (proc,ACPI_PROC_AML ,ACPI_PROC_SIZEOF ); proc[ACPI_PROC_OFFSET_CPUHEX ] =acpi_get_hex (i >>4 ); proc[ACPI_PROC_OFFSET_CPUHEX +1 ] =acpi_get_hex (i);
@@ -973,11 +970,12 @@ build_ssdt(GArray *table_data, GArray *linker,* Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} */ /* Arg0 = Processor ID = APIC ID */ -build_append_notify_method (sb_scope,"NTFY" ,"CP%0.02X" , acpi_cpus); +build_append_notify_method (sb_scope->buf,"NTFY" , +"CP%0.02X" , acpi_cpus);/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */ -build_append_byte (sb_scope,0x08 );/* NameOp */ -build_append_namestring (sb_scope,"CPON" ); +build_append_byte (sb_scope->buf,0x08 );/* NameOp */ +build_append_namestring (sb_scope->buf,"CPON" ); {GArray *package =build_alloc_array ();
@@ -1002,7 +1000,7 @@ build_ssdt(GArray *table_data, GArray *linker, }build_package (package, op); -build_append_array (sb_scope, package); +build_append_array (sb_scope->buf, package);build_free_array (package); }
@@ -1011,7 +1009,7 @@ build_ssdt(GArray *table_data, GArray *linker,/* build memory devices */ for (i =0 ; i < nr_mem; i++) {char id[3 ]; -uint8_t *mem =acpi_data_push (sb_scope,ACPI_MEM_SIZEOF ); +uint8_t *mem =acpi_data_push (sb_scope->buf,ACPI_MEM_SIZEOF );snprintf (id,sizeof (id),"%02X" , i);memcpy (mem,ACPI_MEM_AML ,ACPI_MEM_SIZEOF );
@@ -1022,7 +1020,7 @@ build_ssdt(GArray *table_data, GArray *linker,/* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) { * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ... */ -build_append_notify_method (sb_scope, +build_append_notify_method (sb_scope->buf,stringify (MEMORY_SLOT_NOTIFY_METHOD ),"MP%0.02X" , nr_mem); }
@@ -1046,17 +1044,18 @@ build_ssdt(GArray *table_data, GArray *linker, build_pci_bus_end, &hotplug_state); } -build_append_array (sb_scope, hotplug_state.device_table); +build_append_array (sb_scope->buf, hotplug_state.device_table);build_pci_bus_state_cleanup (&hotplug_state); } -build_package (sb_scope, op); -build_append_array (table_data, sb_scope); -build_free_array (sb_scope); +aml_append (ssdt, sb_scope); } +/* copy AML table into ACPI tables blob and patch header there */ +g_array_append_vals (table_data, ssdt->buf->data, ssdt->buf->len);build_header (linker, table_data, - (void *)(table_data->data + ssdt_start), -"SSDT" , table_data->len - ssdt_start,1 ); + (void *)(table_data->data + table_data->len - ssdt->buf->len), +"SSDT" , ssdt->buf->len,1 ); +free_aml_allocator (); } static void
Signature · 1 line
1.8.3.1
PATCH v4 4/42 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
@@ -355,3 +355,14 @@ Aml *aml_scope(const char *name_format, ...)va_end (ap);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefDevice */ +Aml *aml_device (const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_bundle (0x82 /* DeviceOp */ ,AML_EXT_PACKAGE ); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -61,6 +61,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 5/42 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
@@ -356,6 +356,15 @@ Aml *aml_scope(const char *name_format, ...)return var; } +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */ +Aml *aml_method (const char *name,int arg_count) +{ +Aml *var =aml_bundle (0x14 /* MethodOp */ ,AML_PACKAGE ); +build_append_namestring (var->buf,"%s" , name); +build_append_byte (var->buf, arg_count);/* MethodFlags: ArgCount */ +return var; +} +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefDevice */ Aml *aml_device (const char *name_format, ...) {
include/hw/acpi/aml-build.h +1 -0
@@ -62,6 +62,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_method (const char *name,int arg_count);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 6/42 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
@@ -356,6 +356,14 @@ Aml *aml_scope(const char *name_format, ...)return var; } +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ +Aml *aml_if (Aml *predicate) +{ +Aml *var =aml_bundle (0xA0 /* IfOp */ ,AML_PACKAGE ); +aml_append (var, predicate); +return var; +} +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */ Aml *aml_method (const char *name,int arg_count) {
include/hw/acpi/aml-build.h +1 -0
@@ -63,6 +63,7 @@ void aml_append(Aml *parent_ctx, Aml *child);Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_method (const char *name,int arg_count); +Aml *aml_if (Aml *predicate);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 7/42 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
@@ -271,6 +271,15 @@ static Aml *aml_alloc(void)return var; } +static Aml *aml_opcode (uint8_t op) +{ +Aml *var =aml_alloc (); + + var->op = op; + var->block_flags =AML_OPCODE ; +return var; +} +static Aml *aml_bundle (uint8_t op,AmlBlockFlags flags) {Aml *var =aml_alloc ();
@@ -356,6 +365,29 @@ Aml *aml_scope(const char *name_format, ...)return var; } +/* +* helper to construct NameString, which returns Aml object +* for using with aml_append or other aml_* terms +*/ +Aml *aml_name (const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_alloc (); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +return var; +} + +/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefName */ +Aml *aml_name_decl (const char *name,Aml *val) +{ +Aml *var =aml_opcode (0x08 /* NameOp */ ); +build_append_namestring (var->buf,"%s" , name); +aml_append (var, val); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +4 -0
@@ -59,6 +59,10 @@ void free_aml_allocator(void);*/ void aml_append (Aml *parent_ctx,Aml *child); +/* non block AML object primitives */ +Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_name_decl (const char *name,Aml *val); +/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 8/42 acpi: add aml_int() term
In reply to Igor Mammedov* factor out ACPI const int packing out of build_append_value() and rename build_append_value() to build_append_int_noprefix() it will be reused for adding a plain integer value into AML. will be used by is aml_processor() and CRS macro helpers
* extend build_append_int{_noprefix}() to support 64-bit values it will be used PCI for generating 64bit _CRS entries
--- hw/acpi/aml-build.c | 43 ++++++++++++++++++++++--------------------- hw/i386/acpi-build.c | 12 ++++++------ include/hw/acpi/aml-build.h | 4 ++-- 3 files changed, 30 insertions(+), 29 deletions(-)
hw/acpi/aml-build.c +22 -21
@@ -218,44 +218,34 @@ void build_extop_package(GArray *package, uint8_t op)build_prepend_byte (package,0x5B );/* ExtOpPrefix */ } -void build_append_value (GArray *table,uint32_t value,int size) +static void build_append_int_noprefix (GArray *table,uint64_t value,int size) { -uint8_t prefix;int i; -switch (size) { -case 1 : - prefix =0x0A ;/* BytePrefix */ -break ; -case 2 : - prefix =0x0B ;/* WordPrefix */ -break ; -case 4 : - prefix =0x0C ;/* DWordPrefix */ -break ; -default : -assert (0 ); -return ; - } -build_append_byte (table, prefix);for (i =0 ; i < size; ++i) {build_append_byte (table, value &0xFF ); value = value >>8 ; } } -void build_append_int (GArray *table,uint32_t value) +void build_append_int (GArray *table,uint64_t value) {if (value ==0x00 ) {build_append_byte (table,0x00 );/* ZeroOp */ }else if (value ==0x01 ) {build_append_byte (table,0x01 );/* OneOp */ }else if (value <=0xFF ) { -build_append_value (table, value,1 ); +build_append_byte (table,0x0A );/* BytePrefix */ +build_append_int_noprefix (table, value,1 ); }else if (value <=0xFFFF ) { -build_append_value (table, value,2 ); +build_append_byte (table,0x0B );/* WordPrefix */ +build_append_int_noprefix (table, value,2 ); + }else if (value <=0xFFFFFFFF ) { +build_append_byte (table,0x0C );/* DWordPrefix */ +build_append_int_noprefix (table, value,4 ); }else { -build_append_value (table, value,4 ); +build_append_byte (table,0x0E );/* QWordPrefix */ +build_append_int_noprefix (table, value,8 ); } }
@@ -366,6 +356,17 @@ Aml *aml_scope(const char *name_format, ...) }/* +* ACPI 1.0b: 16.2.3 Data Objects Encoding: +* encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp +*/ +Aml *aml_int (const uint64_t val) +{ +Aml *var =aml_alloc (); +build_append_int (var->buf, val); +return var; +} + +/* * helper to construct NameString, which returns Aml object * for using with aml_append or other aml_* terms */
hw/i386/acpi-build.c +6 -6
@@ -304,14 +304,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)static void build_append_notify_target_ifequal (GArray *method,GArray *target_name, -uint32_t value,int size) +uint32_t value) {GArray *notify =build_alloc_array ();uint8_t op =0xA0 ;/* IfOp */ build_append_byte (notify,0x93 );/* LEqualOp */ build_append_byte (notify,0x68 );/* Arg0Op */ -build_append_value (notify, value, size); +build_append_int (notify, value);build_append_byte (notify,0x86 );/* NotifyOp */ build_append_array (notify, target_name);build_append_byte (notify,0x69 );/* Arg1Op */
@@ -580,7 +580,7 @@ build_append_notify_method(GArray *device, const char *name,GArray *target =build_alloc_array ();build_append_namestring (target, format, i);assert (i <256 );/* Fits in 1 byte */ -build_append_notify_target_ifequal (method, target, i,1 ); +build_append_notify_target_ifequal (method, target, i);build_free_array (target); }
@@ -715,11 +715,11 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state) bus->parent_dev->devfn);build_append_byte (bus_table,0x08 );/* NameOp */ build_append_namestring (bus_table,"_SUN" ); -build_append_value (bus_table,PCI_SLOT (bus->parent_dev->devfn),1 ); +build_append_int (bus_table,PCI_SLOT (bus->parent_dev->devfn));build_append_byte (bus_table,0x08 );/* NameOp */ build_append_namestring (bus_table,"_ADR" ); -build_append_value (bus_table, (PCI_SLOT (bus->parent_dev->devfn) <<16 ) | -PCI_FUNC (bus->parent_dev->devfn),4 ); +build_append_int (bus_table, (PCI_SLOT (bus->parent_dev->devfn) <<16 ) | +PCI_FUNC (bus->parent_dev->devfn)); }else { op =0x10 ;/* ScopeOp */ ;build_append_namestring (bus_table,"PCI0" );
include/hw/acpi/aml-build.h +2 -2
@@ -62,6 +62,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* non block AML object primitives */ Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_name_decl (const char *name,Aml *val); +Aml *aml_int (const uint64_t val);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
@@ -81,8 +82,7 @@ build_append_namestring(GArray *array, const char *format, ...);void build_prepend_package_length (GArray *package);void build_package (GArray *package,uint8_t op); -void build_append_value (GArray *table,uint32_t value,int size); -void build_append_int (GArray *table,uint32_t value); +void build_append_int (GArray *table,uint64_t value);void build_extop_package (GArray *package,uint8_t op);#endif
Signature · 1 line
1.8.3.1
PATCH v4 9/42 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
@@ -355,6 +355,14 @@ Aml *aml_scope(const char *name_format, ...)return var; } +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefReturn */ +Aml *aml_return (Aml *val) +{ +Aml *var =aml_opcode (0xA4 /* ReturnOp */ ); +aml_append (var, val); +return var; +} +/* * ACPI 1.0b: 16.2.3 Data Objects Encoding: * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
include/hw/acpi/aml-build.h +1 -0
@@ -62,6 +62,7 @@ void aml_append(Aml *parent_ctx, Aml *child);/* non block AML object primitives */ Aml *aml_name (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_name_decl (const char *name,Aml *val); +Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val);/* Block AML object primitives */
Signature · 1 line
1.8.3.1
PATCH v4 10/42 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
@@ -397,6 +397,17 @@ Aml *aml_name_decl(const char *name, Aml *val)return var; } +/* ACPI 1.0b: 16.2.6.1 Arg Objects Encoding */ +Aml *aml_arg (int pos) +{ +Aml *var; +uint8_t op =0x68 /* ARG0 op */ + pos; + +assert (pos <=6 ); + var =aml_opcode (op); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -64,6 +64,7 @@ Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_name_decl (const char *name,Aml *val);Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val); +Aml *aml_arg (int pos);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 11/42 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
@@ -408,6 +408,15 @@ Aml *aml_arg(int pos)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefStore */ +Aml *aml_store (Aml *val,Aml *target) +{ +Aml *var =aml_opcode (0x70 /* StoreOp */ ); +aml_append (var, val); +aml_append (var, target); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -65,6 +65,7 @@ Aml *aml_name_decl(const char *name, Aml *val);Aml *aml_return (Aml *val);Aml *aml_int (const uint64_t val);Aml *aml_arg (int pos); +Aml *aml_store (Aml *val,Aml *target);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 12/42 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
@@ -417,6 +417,16 @@ Aml *aml_store(Aml *val, Aml *target)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAnd */ +Aml *aml_and (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x7B /* AndOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +build_append_int (var->buf,0x00 /* NullNameOp */ ); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -66,6 +66,7 @@ Aml *aml_return(Aml *val);Aml *aml_int (const uint64_t val);Aml *aml_arg (int pos);Aml *aml_store (Aml *val,Aml *target); +Aml *aml_and (Aml *arg1,Aml *arg2);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 13/42 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
@@ -427,6 +427,15 @@ Aml *aml_and(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */ +Aml *aml_notify (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x86 /* NotifyOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -67,6 +67,7 @@ Aml *aml_int(const uint64_t val);Aml *aml_arg (int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2); +Aml *aml_notify (Aml *arg1,Aml *arg2);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 14/42 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
@@ -436,6 +436,48 @@ Aml *aml_notify(Aml *arg1, Aml *arg2)return var; } +/* helper to call method with 1 argument */ +Aml *aml_call1 (const char *method,Aml *arg1) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +return var; +} + +/* helper to call method with 2 arguments */ +Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +aml_append (var, arg2); +return var; +} + +/* helper to call method with 3 arguments */ +Aml *aml_call3 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +aml_append (var, arg2); +aml_append (var, arg3); +return var; +} + +/* helper to call method with 4 arguments */ +Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4) +{ +Aml *var =aml_alloc (); +build_append_namestring (var->buf,"%s" , method); +aml_append (var, arg1); +aml_append (var, arg2); +aml_append (var, arg3); +aml_append (var, arg4); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +4 -0
@@ -68,6 +68,10 @@ Aml *aml_arg(int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2);Aml *aml_notify (Aml *arg1,Aml *arg2); +Aml *aml_call1 (const char *method,Aml *arg1); +Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2); +Aml *aml_call3 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3); +Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 15/42 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
@@ -505,3 +505,11 @@ Aml *aml_device(const char *name_format, ...)va_end (ap);return var; } + +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */ +Aml *aml_package (uint8_t num_elements) +{ +Aml *var =aml_bundle (0x12 /* PackageOp */ ,AML_PACKAGE ); +build_append_byte (var->buf, num_elements); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -78,6 +78,7 @@ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_method (const char *name,int arg_count);Aml *aml_if (Aml *predicate); +Aml *aml_package (uint8_t num_elements);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 16/42 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 | 40 ++++++++++++++++++++++++++++++---------- hw/i386/ssdt-misc.dsl | 33 --------------------------------- 2 files changed, 30 insertions(+), 43 deletions(-)
hw/i386/acpi-build.c +30 -10
@@ -924,7 +924,7 @@ build_ssdt(GArray *table_data, GArray *linker,uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit;uint8_t *ssdt_ptr; -Aml *ssdt, *sb_scope; +Aml *ssdt, *sb_scope, *scope, *pkg;int i; ssdt =init_aml_allocator ();
@@ -936,15 +936,6 @@ build_ssdt(GArray *table_data, GArray *linker,/* Copy header and patch values in the S3_ / S4_ / S5_ packages */ ssdt_ptr =acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml));memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); -if (pm->s3_disabled) { - ssdt_ptr[acpi_s3_name[0 ]] ='X' ; - } -if (pm->s4_disabled) { - ssdt_ptr[acpi_s4_name[0 ]] ='X' ; - }else { - ssdt_ptr[acpi_s4_pkg[0 ] +1 ] = ssdt_ptr[acpi_s4_pkg[0 ] +3 ] = - pm->s4_val; - }patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));
@@ -954,6 +945,35 @@ build_ssdt(GArray *table_data, GArray *linker,ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_mctrl_nr_slots[0 ],32 , nr_mem); +/* create S3_ / S4_ / S5_ packages if necessary */ + scope =aml_scope ("\\" ); +if (!pm->s3_disabled) { + pkg =aml_package (4 ); +aml_append (pkg,aml_int (1 ));/* PM1a_CNT.SLP_TYP */ +aml_append (pkg,aml_int (1 ));/* PM1b_CNT.SLP_TYP, FIXME: not impl. */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (scope,aml_name_decl ("_S3" , pkg)); + } + +if (!pm->s4_disabled) { + pkg =aml_package (4 ); +aml_append (pkg,aml_int (pm->s4_val));/* PM1a_CNT.SLP_TYP */ +/* PM1b_CNT.SLP_TYP, FIXME: not impl. */ +aml_append (pkg,aml_int (pm->s4_val)); +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (scope,aml_name_decl ("_S4" , pkg)); + } + + pkg =aml_package (4 ); +aml_append (pkg,aml_int (0 ));/* PM1a_CNT.SLP_TYP */ +aml_append (pkg,aml_int (0 ));/* PM1b_CNT.SLP_TYP not impl. */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (pkg,aml_int (0 ));/* reserved */ +aml_append (scope,aml_name_decl ("_S5" , pkg)); +aml_append (ssdt, scope); + sb_scope =aml_scope ("_SB" ); {/* build Processor object for each processor */
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 */ - One, /* PM1b_CNT.SLP_TYP */ - Zero, /* reserved */ - Zero /* reserved */ - }) - ACPI_EXTRACT_NAME_STRING acpi_s4_name - ACPI_EXTRACT_PKG_START acpi_s4_pkg - Name(_S4, Package(0x04) { - 0x2, /* PM1a_CNT.SLP_TYP */ - 0x2, /* PM1b_CNT.SLP_TYP */ - Zero, /* reserved */ - Zero /* reserved */ - }) - Name(_S5, Package(0x04) { - Zero, /* PM1a_CNT.SLP_TYP */ - Zero, /* PM1b_CNT.SLP_TYP */ - Zero, /* reserved */ - Zero /* reserved */ - }) - } - External(\_SB.PCI0, DeviceObj) External(\_SB.PCI0.ISA, DeviceObj)
Signature · 1 line
1.8.3.1
PATCH v4 17/42 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
@@ -506,6 +506,13 @@ Aml *aml_device(const char *name_format, ...)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */ +Aml *aml_buffer (void ) +{ +Aml *var =aml_bundle (0x11 /* BufferOp */ ,AML_BUFFER ); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */ Aml *aml_package (uint8_t num_elements) {
include/hw/acpi/aml-build.h +1 -0
@@ -79,6 +79,7 @@ Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_method (const char *name,int arg_count);Aml *aml_if (Aml *predicate);Aml *aml_package (uint8_t num_elements); +Aml *aml_buffer (void );/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 18/42 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
@@ -506,6 +506,14 @@ Aml *aml_device(const char *name_format, ...)return var; } +/* ACPI 1.0b: 6.4.1 ASL Macros for Resource Descriptors */ +Aml *aml_resource_template (void ) +{ +/* ResourceTemplate is a buffer of Resources with EndTag at the end */ +Aml *var =aml_bundle (0x11 /* BufferOp */ ,AML_RES_TEMPLATE ); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */ Aml *aml_buffer (void ) {
include/hw/acpi/aml-build.h +1 -0
@@ -80,6 +80,7 @@ Aml *aml_method(const char *name, int arg_count);Aml *aml_if (Aml *predicate);Aml *aml_package (uint8_t num_elements);Aml *aml_buffer (void ); +Aml *aml_resource_template (void );/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 19/42 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
@@ -478,6 +478,22 @@ Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4)return var; } +/* ACPI 1.0b: 6.4.2.5 I/O Port Descriptor */ +Aml *aml_io (AmlIODecode dec,uint16_t min_base,uint16_t max_base, +uint8_t aln,uint8_t len) +{ +Aml *var =aml_alloc (); +build_append_byte (var->buf,0x47 );/* IO port descriptor */ +build_append_byte (var->buf, dec); +build_append_byte (var->buf, min_base &0xff ); +build_append_byte (var->buf, (min_base >>8 ) &0xff ); +build_append_byte (var->buf, max_base &0xff ); +build_append_byte (var->buf, (max_base >>8 ) &0xff ); +build_append_byte (var->buf, aln); +build_append_byte (var->buf, len); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +7 -0
@@ -23,6 +23,11 @@ struct Aml { };typedef struct Aml Aml ; +typedef enum { + aml_decode10 =0 , + aml_decode16 =1 , +}AmlIODecode ; +/** * init_aml_allocator: *
@@ -72,6 +77,8 @@ Aml *aml_call1(const char *method, Aml *arg1);Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2);Aml *aml_call3 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3);Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4); +Aml *aml_io (AmlIODecode dec,uint16_t min_base,uint16_t max_base, +uint8_t aln,uint8_t len);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 20/42 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
@@ -158,10 +158,10 @@ enum { PACKAGE_LENGTH_4BYTE_SHIFT = 20, }; -void build_prepend_package_length (GArray *package) +void +build_prepend_package_length (GArray *package,unsigned length,bool incl_self) {uint8_t byte; -unsigned length = package->len;unsigned length_bytes;if (length +1 < (1 <<PACKAGE_LENGTH_1BYTE_SHIFT )) {
@@ -174,8 +174,18 @@ void build_prepend_package_length(GArray *package) length_bytes =4 ; } -/* PkgLength is the length of the inclusive length of the data. */ - length += length_bytes; +/* +* NamedField uses PkgLength encoding but it doesn't include length +* of PkgLength itself. +*/ +if (incl_self) { +/* +* PkgLength is the length of the inclusive length of the data +* and PkgLength's length itself when used for terms with +* explitit length. +*/ + length += length_bytes; + }switch (length_bytes) {case 1 :
@@ -208,7 +218,7 @@ void build_prepend_package_length(GArray *package)void build_package (GArray *package,uint8_t op) { -build_prepend_package_length (package); +build_prepend_package_length (package, package->len, true);build_prepend_byte (package, op); }
include/hw/acpi/aml-build.h +2 -1
@@ -99,7 +99,8 @@ void build_append_array(GArray *array, GArray *val); void GCC_FMT_ATTR(2, 3) build_append_namestring(GArray *array, const char *format, ...); -void build_prepend_package_length(GArray *package); +void +build_prepend_package_length(GArray *package, unsigned length, bool incl_self); void build_package(GArray *package, uint8_t op); void build_append_int(GArray *table, uint64_t value); void build_extop_package(GArray *package, uint8_t op);
Signature · 1 line
1.8.3.1
PATCH v4 21/42 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
@@ -554,3 +554,17 @@ Aml *aml_package(uint8_t num_elements)build_append_byte (var->buf, num_elements);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefOpRegion */ +Aml *aml_operation_region (const char *name,AmlRegionSpace rs, +uint32_t offset,uint32_t len) +{ +Aml *var =aml_alloc (); +build_append_byte (var->buf,0x5B );/* ExtOpPrefix */ +build_append_byte (var->buf,0x80 );/* OpRegionOp */ +build_append_namestring (var->buf,"%s" , name); +build_append_byte (var->buf, rs); +build_append_int (var->buf, offset); +build_append_int (var->buf, len); +return var; +}
include/hw/acpi/aml-build.h +7 -0
@@ -28,6 +28,11 @@ typedef enum { aml_decode16 =1 , } AmlIODecode; +typedef enum { + aml_system_memory =0x00 , + aml_system_io =0x01 , +}AmlRegionSpace ; +/** * init_aml_allocator: *
@@ -79,6 +84,8 @@ Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);Aml *aml_call4 (const char *method,Aml *arg1,Aml *arg2,Aml *arg3,Aml *arg4);Aml *aml_io (AmlIODecode dec,uint16_t min_base,uint16_t max_base,uint8_t aln,uint8_t len); +Aml *aml_operation_region (const char *name,AmlRegionSpace rs, +uint32_t offset,uint32_t len);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 22/42 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
@@ -216,6 +216,16 @@ build_prepend_package_length(GArray *package, unsigned length, bool incl_self)build_prepend_byte (package, byte); } +static void +build_append_pkg_length (GArray *array,unsigned length,bool incl_self) +{ +GArray *tmp =build_alloc_array (); + +build_prepend_package_length (tmp, length, incl_self); +build_append_array (array, tmp); +build_free_array (tmp); +} +void build_package (GArray *package,uint8_t op) {build_prepend_package_length (package, package->len, true);
@@ -568,3 +578,21 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs,build_append_int (var->buf, len);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: NamedField */ +Aml *aml_named_field (const char *name,unsigned length) +{ +Aml *var =aml_alloc (); +build_append_nameseg (var->buf, name); +build_append_pkg_length (var->buf, length, false); +return var; +} + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */ +Aml *aml_field (const char *name,AmlFieldFlags flags) +{ +Aml *var =aml_bundle (0x81 /* FieldOp */ ,AML_EXT_PACKAGE ); +build_append_namestring (var->buf,"%s" , name); +build_append_byte (var->buf, flags); +return var; +}
include/hw/acpi/aml-build.h +6 -0
@@ -29,6 +29,10 @@ typedef enum { } AmlIODecode;typedef enum { + aml_byte_acc =1 , +}AmlFieldFlags ; + +typedef enum { aml_system_memory =0x00 , aml_system_io =0x01 , }AmlRegionSpace ;
@@ -86,6 +90,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, uint8_t aln, uint8_t len);Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len); +Aml *aml_named_field (const char *name,unsigned length);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
@@ -95,6 +100,7 @@ Aml *aml_if(Aml *predicate);Aml *aml_package (uint8_t num_elements);Aml *aml_buffer (void );Aml *aml_resource_template (void ); +Aml *aml_field (const char *name,AmlFieldFlags flags);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 23/42 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
@@ -596,3 +596,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)build_append_byte (var->buf, flags);return var; } + +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */ +Aml *aml_local (int num) +{ +Aml *var; +uint8_t op =0x60 /* Local0Op */ + num; + +assert (num <=7 ); + var =aml_opcode (op); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -91,6 +91,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len);Aml *aml_named_field (const char *name,unsigned length); +Aml *aml_local (int num);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 24/42 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
@@ -597,6 +597,31 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)return var; } +/* ACPI 1.0b: 16.2.3 Data Objects Encoding: String */ +Aml *aml_string (const char *name_format, ...) +{ +Aml *var =aml_opcode (0x0D /* StringPrefix */ ); +va_list ap, va_len; +char *s; +int len; + +va_start (ap, name_format); +va_copy (va_len, ap); + len =vsnprintf (NULL ,0 , name_format, va_len); +va_end (va_len); + len +=1 ; + s =g_new0 (typeof (*s), len); + + len =vsnprintf (s, len, name_format, ap); +va_end (ap); + +g_array_append_vals (var->buf, s, len); +build_append_byte (var->buf,0x0 );/* NullChar */ +g_free (s); + +return var; +} +/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */ Aml *aml_local (int num) {
include/hw/acpi/aml-build.h +1 -0
@@ -92,6 +92,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs, uint32_t offset, uint32_t len);Aml *aml_named_field (const char *name,unsigned length);Aml *aml_local (int num); +Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 25/42 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
@@ -924,7 +924,7 @@ build_ssdt(GArray *table_data, GArray *linker,uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit;uint8_t *ssdt_ptr; -Aml *ssdt, *sb_scope, *scope, *pkg; +Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field;int i; ssdt =init_aml_allocator ();
@@ -940,9 +940,6 @@ build_ssdt(GArray *table_data, GArray *linker,patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml));ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), - ssdt_isa_pest[0 ],16 , misc->pvpanic_port); - -ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), ssdt_mctrl_nr_slots[0 ],32 , nr_mem);/* create S3_ / S4_ / S5_ packages if necessary */
@@ -974,6 +971,37 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (scope,aml_name_decl ("_S5" , pkg));aml_append (ssdt, scope); +if (misc->pvpanic_port) { + scope =aml_scope ("\\_SB.PCI0.ISA" ); + + dev =aml_device ("PEVR" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("QEMU0002" ))); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, misc->pvpanic_port, misc->pvpanic_port,1 ,1 ) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); + +aml_append (dev,aml_operation_region ("PEOR" , aml_system_io, + misc->pvpanic_port,1 )); + field =aml_field ("PEOR" , aml_byte_acc); +aml_append (field,aml_named_field ("PEPT" ,8 )); +aml_append (dev, field); + + method =aml_method ("RDPT" ,0 ); +aml_append (method,aml_store (aml_name ("PEPT" ),aml_local (0 ))); +aml_append (method,aml_return (aml_local (0 ))); +aml_append (dev, method); + + method =aml_method ("WRPT" ,1 ); +aml_append (method,aml_store (aml_arg (0 ),aml_name ("PEPT" ))); +aml_append (dev, method); + +aml_append (scope, dev); +aml_append (ssdt, scope); + } + sb_scope =aml_scope ("_SB" ); {/* build Processor object for each processor */
hw/i386/ssdt-misc.dsl +0 -47
51 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 26/42 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
@@ -632,3 +632,11 @@ Aml *aml_local(int num) var =aml_opcode (op);return var; } + +/* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */ +Aml *aml_varpackage (uint32_t num_elements) +{ +Aml *var =aml_bundle (0x13 /* VarPackageOp */ ,AML_PACKAGE ); +build_append_int (var->buf, num_elements); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -103,6 +103,7 @@ Aml *aml_package(uint8_t num_elements);Aml *aml_buffer (void );Aml *aml_resource_template (void );Aml *aml_field (const char *name,AmlFieldFlags flags); +Aml *aml_varpackage (uint32_t num_elements);/* other helpers */ GArray *build_alloc_array (void );
Signature · 1 line
1.8.3.1
PATCH v4 27/42 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
@@ -514,6 +514,16 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */ +Aml *aml_equal (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x93 /* LequalOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +build_append_int (var->buf,0x00 );/* NullNameOp */ +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ Aml *aml_if (Aml *predicate) {
include/hw/acpi/aml-build.h +1 -0
@@ -93,6 +93,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace rs,Aml *aml_named_field (const char *name,unsigned length);Aml *aml_local (int num);Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 ); +Aml *aml_equal (Aml *arg1,Aml *arg2);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 28/42 acpi: add aml_processor() term
In reply to Igor Mammedov--- 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
@@ -650,3 +650,18 @@ Aml *aml_varpackage(uint32_t num_elements)build_append_int (var->buf, num_elements);return var; } + +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefProcessor */ +Aml *aml_processor (uint8_t proc_id,uint32_t pblk_addr,uint8_t pblk_len, +const char *name_format, ...) +{ +va_list ap; +Aml *var =aml_bundle (0x83 /* ProcessorOp */ ,AML_EXT_PACKAGE ); +va_start (ap, name_format); +build_append_namestringv (var->buf, name_format, ap); +va_end (ap); +build_append_byte (var->buf, proc_id);/* ProcID */ +build_append_int_noprefix (var->buf, pblk_addr,sizeof (pblk_addr)); +build_append_byte (var->buf, pblk_len);/* PblkLen */ +return var; +}
include/hw/acpi/aml-build.h +2 -0
@@ -94,6 +94,8 @@ Aml *aml_named_field(const char *name, unsigned length);Aml *aml_local (int num);Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_equal (Aml *arg1,Aml *arg2); +Aml *aml_processor (uint8_t proc_id,uint32_t pblk_addr,uint8_t pblk_len, +const char *name_format, ...)GCC_FMT_ATTR (4 ,5 );/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 29/42 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
@@ -665,3 +665,32 @@ Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,build_append_byte (var->buf, pblk_len);/* PblkLen */ return var; } + +static uint8_t Hex2Digit (char c) +{ +if (c >='A' ) { +return c -'A' +10 ; + } + +return c -'0' ; +} + +/* ACPI 1.0b: 15.2.3.6.4.1 EISAID Macro - Convert EISA ID String To Integer */ +Aml *aml_eisaid (const char *str) +{ +Aml *var =aml_alloc (); +uint32_t id; + +g_assert (strlen (str) ==7 ); + id = (str[0 ] -0x40 ) <<26 | + (str[1 ] -0x40 ) <<21 | + (str[2 ] -0x40 ) <<16 | +Hex2Digit (str[3 ]) <<12 | +Hex2Digit (str[4 ]) <<8 | +Hex2Digit (str[5 ]) <<4 | +Hex2Digit (str[6 ]); + +build_append_byte (var->buf,0x0C );/* DWordPrefix */ +build_append_int_noprefix (var->buf,bswap32 (id),sizeof (id)); +return var; +}
include/hw/acpi/aml-build.h +1 -0
@@ -96,6 +96,7 @@ Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_equal (Aml *arg1,Aml *arg2);Aml *aml_processor (uint8_t proc_id,uint32_t pblk_addr,uint8_t pblk_len,const char *name_format, ...)GCC_FMT_ATTR (4 ,5 ); +Aml *aml_eisaid (const char *str);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );
Signature · 1 line
1.8.3.1
PATCH v4 30/42 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 | 7 ++-- hw/i386/acpi-build.c | 88 ++++++++++++++++++++++++--------------------------- hw/i386/ssdt-proc.dsl | 63 ------------------------------------ 3 files changed, 45 insertions(+), 113 deletions(-) delete mode 100644 hw/i386/ssdt-proc.dsl
hw/i386/Makefile.objs +4 -3
@@ -7,10 +7,11 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o -hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \ - hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \ +hw/i386/acpi-build.o: hw/i386/acpi-build.c \ hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \ + hw/i386/ssdt-pcihp.hex \ + hw/i386/ssdt-misc.hex \ + hw/i386/ssdt-mem.hex \ hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
hw/i386/acpi-build.c +41 -47
114 lines not on this page · raw message
hw/i386/ssdt-proc.dsl deleted +0 -63
63 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 31/42 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 {
@@ -176,12 +178,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)if (piix) { obj = piix; + pm->cpu_hp_io_base =PIIX4_CPU_HOTPLUG_IO_BASE ; }if (lpc) { obj = lpc; + pm->cpu_hp_io_base =ICH9_CPU_HOTPLUG_IO_BASE ; }assert (obj); + pm->cpu_hp_io_len =ACPI_GPE_PROC_LEN ;/* Fill in optional s3/s4 related properties */ o =object_property_get_qobject (obj,ACPI_PM_PROP_S3_DISABLED ,NULL );if (o) {
@@ -995,6 +1000,28 @@ build_ssdt(GArray *table_data, GArray *linker, sb_scope =aml_scope ("_SB" ); { +/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ + dev =aml_device ("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE )); +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("CPU Hotplug resources" )) + ); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, pm->cpu_hp_io_base, pm->cpu_hp_io_base,1 , + pm->cpu_hp_io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (sb_scope, dev); +/* declare CPU hotplug MMIO region and PRS field to access it */ +aml_append (sb_scope,aml_operation_region ( +"PRST" , aml_system_io, pm->cpu_hp_io_base, pm->cpu_hp_io_len)); + field =aml_field ("PRST" , aml_byte_acc); +aml_append (field,aml_named_field ("PRS" ,256 )); +aml_append (sb_scope, field); +/* build Processor object for each processor */ for (i =0 ; i < acpi_cpus; i++) { dev =aml_processor (i,0 ,0 ,"CP%.02X" , i);
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 v4 32/42 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
@@ -598,6 +598,16 @@ Aml *aml_named_field(const char *name, unsigned length)return var; } +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: ReservedField */ +Aml *aml_reserved_field (unsigned length) +{ +Aml *var =aml_alloc (); +/* ReservedField := 0x00 PkgLength */ +build_append_byte (var->buf,0x00 ); +build_append_pkg_length (var->buf, length, false); +return var; +} +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */ Aml *aml_field (const char *name,AmlFieldFlags flags) {
include/hw/acpi/aml-build.h +6 -0
@@ -29,7 +29,12 @@ typedef enum { } AmlIODecode;typedef enum { + aml_any_acc =0 , aml_byte_acc =1 , + aml_word_acc =2 , + aml_dword_acc =3 , + aml_qword_acc =4 , + aml_buffer_acc =5 , }AmlFieldFlags ; typedef enum {
@@ -91,6 +96,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len);Aml *aml_named_field (const char *name,unsigned length); +Aml *aml_reserved_field (unsigned length);Aml *aml_local (int num);Aml *aml_string (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_equal (Aml *arg1,Aml *arg2);
Signature · 1 line
1.8.3.1
PATCH v4 33/42 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 | 1 - hw/i386/acpi-build.c | 112 +++++++++++++++++++++----------------------------- hw/i386/ssdt-mem.dsl | 77 ---------------------------------- 3 files changed, 46 insertions(+), 144 deletions(-) delete mode 100644 hw/i386/ssdt-mem.dsl
hw/i386/Makefile.objs +0 -1
@@ -11,7 +11,6 @@ hw/i386/acpi-build.o: hw/i386/acpi-build.c \ hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ hw/i386/ssdt-pcihp.hex \ hw/i386/ssdt-misc.hex \ - hw/i386/ssdt-mem.hex \ hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
hw/i386/acpi-build.c +46 -66
139 lines not on this page · raw message
hw/i386/ssdt-mem.dsl deleted +0 -77
77 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 34/42 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 {
@@ -187,6 +189,9 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)assert (obj); pm->cpu_hp_io_len =ACPI_GPE_PROC_LEN ; + pm->mem_hp_io_base =ACPI_MEMORY_HOTPLUG_BASE ; + pm->mem_hp_io_len =ACPI_MEMORY_HOTPLUG_IO_LEN ; +/* Fill in optional s3/s4 related properties */ o =object_property_get_qobject (obj,ACPI_PM_PROP_S3_DISABLED ,NULL );if (o) {
@@ -887,9 +892,6 @@ build_ssdt(GArray *table_data, GArray *linker,patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); -ACPI_BUILD_SET_LE (ssdt_ptr,sizeof (ssdp_misc_aml), - ssdt_mctrl_nr_slots[0 ],32 , nr_mem); -/* create S3_ / S4_ / S5_ packages if necessary */ scope =aml_scope ("\\" );if (!pm->s3_disabled) {
@@ -1027,6 +1029,55 @@ build_ssdt(GArray *table_data, GArray *linker,/* build memory devices */ assert (nr_mem <=ACPI_MAX_RAM_SLOTS ); + scope =aml_scope ("\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE )); +aml_append (scope, +aml_name_decl (stringify (MEMORY_SLOTS_NUMBER ),aml_int (nr_mem)) + ); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, pm->mem_hp_io_base, pm->mem_hp_io_base,0 , + pm->mem_hp_io_len) + ); +aml_append (scope,aml_name_decl ("_CRS" , crs)); + +aml_append (scope,aml_operation_region ( +stringify (MEMORY_HOTPLUG_IO_REGION ), aml_system_io, + pm->mem_hp_io_base, pm->mem_hp_io_len) + ); + + field =aml_field (stringify (MEMORY_HOTPLUG_IO_REGION ), aml_dword_acc); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_ADDR_LOW ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_ADDR_HIGH ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_SIZE_LOW ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_SIZE_HIGH ),32 )); +aml_append (field,/* read only */ +aml_named_field (stringify (MEMORY_SLOT_PROXIMITY ),32 )); +aml_append (scope, field); + + field =aml_field (stringify (MEMORY_HOTPLUG_IO_REGION ), aml_byte_acc); +aml_append (field,aml_reserved_field (160 /* bits, Offset(20) */ )); +aml_append (field,/* 1 if enabled, read only */ +aml_named_field (stringify (MEMORY_SLOT_ENABLED ),1 )); +aml_append (field, +/*(read) 1 if has a insert event. (write) 1 to clear event */ +aml_named_field (stringify (MEMORY_SLOT_INSERT_EVENT ),1 )); +aml_append (scope, field); + + field =aml_field (stringify (MEMORY_HOTPLUG_IO_REGION ), aml_dword_acc); +aml_append (field,/* DIMM selector, write only */ +aml_named_field (stringify (MEMORY_SLOT_SLECTOR ),32 )); +aml_append (field,/* _OST event code, write only */ +aml_named_field (stringify (MEMORY_SLOT_OST_EVENT ),32 )); +aml_append (field,/* _OST status code, write only */ +aml_named_field (stringify (MEMORY_SLOT_OST_STATUS ),32 )); +aml_append (scope, field); + +aml_append (sb_scope, scope);for (i =0 ; i < nr_mem; i++) {#define BASEPATH "\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE) "."
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 v4 35/42 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
@@ -704,3 +704,164 @@ Aml *aml_eisaid(const char *str)build_append_int_noprefix (var->buf,bswap32 (id),sizeof (id));return var; } + +/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor: bytes 3-5 */ +static Aml *aml_as_desc_header (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint8_t type_flags) +{ +uint8_t flags = max_fixed | min_fixed | dec; +Aml *var =aml_alloc (); + +build_append_byte (var->buf, type); +build_append_byte (var->buf, flags); +build_append_byte (var->buf, type_flags);/* Type Specific Flags */ +return var; +} + +/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor */ +static Aml *aml_word_as_desc (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint16_t addr_gran,uint16_t addr_min, +uint16_t addr_max,uint16_t addr_trans, +uint16_t len,uint8_t type_flags) +{ +Aml *var =aml_alloc (); + +build_append_byte (var->buf,0x88 );/* Word Address Space Descriptor */ +/* minimum length since we do not encode optional fields */ +build_append_byte (var->buf,0x0D ); +build_append_byte (var->buf,0x0 ); + +aml_append (var, +aml_as_desc_header (type, min_fixed, max_fixed, dec, type_flags)); +build_append_int_noprefix (var->buf, addr_gran,sizeof (addr_gran)); +build_append_int_noprefix (var->buf, addr_min,sizeof (addr_min)); +build_append_int_noprefix (var->buf, addr_max,sizeof (addr_max)); +build_append_int_noprefix (var->buf, addr_trans,sizeof (addr_trans)); +build_append_int_noprefix (var->buf, len,sizeof (len)); +return var; +} + +/* ACPI 1.0b: 6.4.3.5.3 DWord Address Space Descriptor */ +static Aml *aml_dword_as_desc (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint32_t addr_gran,uint32_t addr_min, +uint32_t addr_max,uint32_t addr_trans, +uint32_t len,uint8_t type_flags) +{ +Aml *var =aml_alloc (); + +build_append_byte (var->buf,0x87 );/* DWord Address Space Descriptor */ +/* minimum length since we do not encode optional fields */ +build_append_byte (var->buf,23 ); +build_append_byte (var->buf,0x0 ); + + +aml_append (var, +aml_as_desc_header (type, min_fixed, max_fixed, dec, type_flags)); +build_append_int_noprefix (var->buf, addr_gran,sizeof (addr_gran)); +build_append_int_noprefix (var->buf, addr_min,sizeof (addr_min)); +build_append_int_noprefix (var->buf, addr_max,sizeof (addr_max)); +build_append_int_noprefix (var->buf, addr_trans,sizeof (addr_trans)); +build_append_int_noprefix (var->buf, len,sizeof (len)); +return var; +} + +/* ACPI 1.0b: 6.4.3.5.1 QWord Address Space Descriptor */ +static Aml *aml_qword_as_desc (AmlResourceType type,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlDecode dec, +uint64_t addr_gran,uint64_t addr_min, +uint64_t addr_max,uint64_t addr_trans, +uint64_t len,uint8_t type_flags) +{ +Aml *var =aml_alloc (); + +build_append_byte (var->buf,0x8A );/* QWord Address Space Descriptor */ +/* minimum length since we do not encode optional fields */ +build_append_byte (var->buf,0x2B ); +build_append_byte (var->buf,0x0 ); + +aml_append (var, +aml_as_desc_header (type, min_fixed, max_fixed, dec, type_flags)); +build_append_int_noprefix (var->buf, addr_gran,sizeof (addr_gran)); +build_append_int_noprefix (var->buf, addr_min,sizeof (addr_min)); +build_append_int_noprefix (var->buf, addr_max,sizeof (addr_max)); +build_append_int_noprefix (var->buf, addr_trans,sizeof (addr_trans)); +build_append_int_noprefix (var->buf, len,sizeof (len)); +return var; +} + +/* +* ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.141 WordBusNumber (Word Bus Number Resource Descriptor Macro) +*/ +Aml *aml_word_bus_number (AmlMinFixed min_fixed,AmlMaxFixed max_fixed, +AmlDecode dec,uint16_t addr_gran, +uint16_t addr_min,uint16_t addr_max, +uint16_t addr_trans,uint16_t len) + +{ +return aml_word_as_desc (aml_bus_number_range, min_fixed, max_fixed, dec, + addr_gran, addr_min, addr_max, addr_trans, len,0 ); +} + +/* +* ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.142 WordIO (Word IO Resource Descriptor Macro) +*/ +Aml *aml_word_io (AmlMinFixed min_fixed,AmlMaxFixed max_fixed, +AmlDecode dec,AmlISARanges isa_ranges, +uint16_t addr_gran,uint16_t addr_min, +uint16_t addr_max,uint16_t addr_trans, +uint16_t len) + +{ +return aml_word_as_desc (aml_io_range, min_fixed, max_fixed, dec, + addr_gran, addr_min, addr_max, addr_trans, len, + isa_ranges); +} + +/* +* ACPI 1.0b: 6.4.3.5.4 ASL Macros for DWORD Address Space Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.34 DWordMemory (DWord Memory Resource Descriptor Macro) +*/ +Aml *aml_dword_memory (AmlDecode dec,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlCacheble cacheable, +AmlReadAndWrite read_and_write, +uint32_t addr_gran,uint32_t addr_min, +uint32_t addr_max,uint32_t addr_trans, +uint32_t len) +{ +uint8_t flags = read_and_write | (cacheable <<1 ); + +return aml_dword_as_desc (aml_memory_range, min_fixed, max_fixed, + dec, addr_gran, addr_min, addr_max, + addr_trans, len, flags); +} + +/* +* ACPI 1.0b: 6.4.3.5.2 ASL Macros for QWORD Address Space Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.102 QWordMemory (QWord Memory Resource Descriptor Macro) +*/ +Aml *aml_qword_memory (AmlDecode dec,AmlMinFixed min_fixed, +AmlMaxFixed max_fixed,AmlCacheble cacheable, +AmlReadAndWrite read_and_write, +uint64_t addr_gran,uint64_t addr_min, +uint64_t addr_max,uint64_t addr_trans, +uint64_t len) +{ +uint8_t flags = read_and_write | (cacheable <<1 ); + +return aml_qword_as_desc (aml_memory_range, min_fixed, max_fixed, + dec, addr_gran, addr_min, addr_max, + addr_trans, len, flags); +}
include/hw/acpi/aml-build.h +72 -0
84 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 36/42 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 v4 37/42 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 {
@@ -178,9 +180,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)Object *obj =NULL ;QObject *o; + pm->pcihp_io_base =0 ; + pm->pcihp_io_len =0 ;if (piix) { obj = piix; pm->cpu_hp_io_base =PIIX4_CPU_HOTPLUG_IO_BASE ; + pm->pcihp_io_base = +object_property_get_int (obj,ACPI_PCIHP_IO_BASE_PROP ,NULL ); + pm->pcihp_io_len = +object_property_get_int (obj,ACPI_PCIHP_IO_LEN_PROP ,NULL ); }if (lpc) { obj = lpc;
@@ -892,6 +900,25 @@ build_ssdt(GArray *table_data, GArray *linker,patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); + scope =aml_scope ("\\_SB.PCI0" ); +/* reserve PCIHP resources */ +if (pm->pcihp_io_len) { + dev =aml_device ("PHPR" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A06" ))); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("PCI Hotplug resources" ))); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, pm->pcihp_io_base, pm->pcihp_io_base,1 , + pm->pcihp_io_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (scope, dev); + } +aml_append (ssdt, scope); +/* create S3_ / S4_ / S5_ packages if necessary */ scope =aml_scope ("\\" );if (!pm->s3_disabled) {
Signature · 1 line
1.8.3.1
PATCH v4 38/42 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
@@ -346,24 +346,6 @@ static void acpi_align_size(GArray *blob, unsigned align)g_array_set_size (blob,ROUND_UP (acpi_data_len (blob), align)); } -/* Set a value within table in a safe manner */ -#define ACPI_BUILD_SET_LE (table, size, off, bits, val) \ - do { \ - uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \ - memcpy(acpi_data_get_ptr(table, size, off, \ - (bits) / BITS_PER_BYTE), \ - &ACPI_BUILD_SET_LE_val, \ - (bits) / BITS_PER_BYTE); \ - } while (0) - -static inline void *acpi_data_get_ptr (uint8_t *table_data,unsigned table_size, -unsigned off,unsigned size) -{ -assert (off + size > off); -assert (off + size <= table_size); -return table_data + off; -} -static inline void acpi_add_table (GArray *table_offsets,GArray *table_data) {uint32_t offset =cpu_to_le32 (table_data->len);
@@ -860,22 +842,6 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)g_free (child); } -static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size) -{ -ACPI_BUILD_SET_LE (start, size, acpi_pci32_start[0 ],32 , pci->w32.begin); - -ACPI_BUILD_SET_LE (start, size, acpi_pci32_end[0 ],32 , pci->w32.end -1 ); - -if (pci->w64.end || pci->w64.begin) { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_start[0 ],64 , pci->w64.begin); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_end[0 ],64 , pci->w64.end -1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_length[0 ],64 , pci->w64.end - pci->w64.begin); - }else { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,0 ); - } -} - static void build_ssdt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -898,9 +864,40 @@ build_ssdt(GArray *table_data, GArray *linker, ssdt_ptr =acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml));memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); -patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); - scope =aml_scope ("\\_SB.PCI0" ); +/* build PCI0._CRS */ + crs =aml_resource_template (); +aml_append (crs, +aml_word_bus_number (aml_min_fixed, aml_max_fixed, aml_pos_decode, +0x0000 ,0x0000 ,0x00FF ,0x0000 ,0x0100 )); +aml_append (crs,aml_io (aml_decode16,0x0CF8 ,0x0CF8 ,0x01 ,0x08 )); + +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0000 ,0x0CF7 ,0x0000 ,0x0CF8 )); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0D00 ,0xFFFF ,0x0000 ,0xF300 )); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 ,0x000A0000 ,0x000BFFFF ,0 ,0x00020000 )); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_non_cacheable, aml_ReadWrite, +0 , pci->w32.begin, pci->w32.end -1 ,0 , + pci->w32.end - pci->w32.begin)); +if (pci->w64.begin) { +aml_append (crs, +aml_qword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 , pci->w64.begin, pci->w64.end -1 ,0 , + pci->w64.end - pci->w64.begin)); + } +aml_append (scope,aml_name_decl ("_CRS" , crs)); +/* reserve PCIHP resources */ if (pm->pcihp_io_len) { dev =aml_device ("PHPR" );
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
Re: [Qemu-devel] [PATCH v4 38/42] pc: acpi-build: create PCI0._CRS dynamically
Quoted 10 lines · Igor Mammedov
Replace template patching and runtime
calculation in_CRS()method with static_CRS
defined in SSDT.It also drops manual hole patching for reserved PCI/MEM/CPU hoptlug MMIO resources and utilizes the fact that MMIO resources are reserved by respective child /i.e. PHPR, MHPD, PRES/ containers.
Signed-off-by Igor Mammedov <[email protected]>
This should be split.
Can we have
patch 1 replace ASL with C
patch 2 simplify ranges
?
I seem to remember reserving ranges like that caused problems in the past, and even if not, it's cleaner not to mix code rework and functional changes.
Quoted 331 lines
--- 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.dslhw/i386/acpi-build.c +33
-36@@ -346,24 +346,6 @@ static void acpi_align_size(GArray *blob, unsigned align)g_array_set_size (blob,ROUND_UP (acpi_data_len (blob), align)); } -/* Set a value within table in a safe manner */ -#define ACPI_BUILD_SET_LE (table, size, off, bits, val) \ - do { \ - uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \ - memcpy(acpi_data_get_ptr(table, size, off, \ - (bits) / BITS_PER_BYTE), \ - &ACPI_BUILD_SET_LE_val, \ - (bits) / BITS_PER_BYTE); \ - } while (0) - -static inline void *acpi_data_get_ptr (uint8_t *table_data,unsigned table_size, -unsigned off,unsigned size) -{ -assert (off + size > off); -assert (off + size <= table_size); -return table_data + off; -} -static inline void acpi_add_table (GArray *table_offsets,GArray *table_data) {uint32_t offset =cpu_to_le32 (table_data->len);@@ -860,22 +842,6 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)g_free (child); } -static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size) -{ -ACPI_BUILD_SET_LE (start, size, acpi_pci32_start[0 ],32 , pci->w32.begin); - -ACPI_BUILD_SET_LE (start, size, acpi_pci32_end[0 ],32 , pci->w32.end -1 ); - -if (pci->w64.end || pci->w64.begin) { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_start[0 ],64 , pci->w64.begin); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_end[0 ],64 , pci->w64.end -1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_length[0 ],64 , pci->w64.end - pci->w64.begin); - }else { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,0 ); - } -} - static void build_ssdt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,@@ -898,9 +864,40 @@ build_ssdt(GArray *table_data, GArray *linker, ssdt_ptr =acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml));memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); -patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); - scope =aml_scope ("\\_SB.PCI0" ); +/* build PCI0._CRS */ + crs =aml_resource_template (); +aml_append (crs, +aml_word_bus_number (aml_min_fixed, aml_max_fixed, aml_pos_decode, +0x0000 ,0x0000 ,0x00FF ,0x0000 ,0x0100 )); +aml_append (crs,aml_io (aml_decode16,0x0CF8 ,0x0CF8 ,0x01 ,0x08 )); + +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0000 ,0x0CF7 ,0x0000 ,0x0CF8 )); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0D00 ,0xFFFF ,0x0000 ,0xF300 )); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 ,0x000A0000 ,0x000BFFFF ,0 ,0x00020000 )); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_non_cacheable, aml_ReadWrite, +0 , pci->w32.begin, pci->w32.end -1 ,0 , + pci->w32.end - pci->w32.begin)); +if (pci->w64.begin) { +aml_append (crs, +aml_qword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 , pci->w64.begin, pci->w64.end -1 ,0 , + pci->w64.end - pci->w64.begin)); + } +aml_append (scope,aml_name_decl ("_CRS" , crs)); +/* reserve PCIHP resources */ if (pm->pcihp_io_len) { dev =aml_device ("PHPR" );hw/i386/acpi-dsdt-pci-crs.dsl deleted +0
-92@@ -1,92 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License along - * with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -/* PCI CRS (current resources) definition. */ -Scope(\_SB.PCI0) { - - Name(CRES, ResourceTemplate() { - WordBusNumber(ResourceProducer, MinFixed, MaxFixed, PosDecode, - 0x0000, // Address Space Granularity - 0x0000, // Address Range Minimum - 0x00FF, // Address Range Maximum - 0x0000, // Address Translation Offset - 0x0100, // Address Length - ,, ) - IO(Decode16, - 0x0CF8, // Address Range Minimum - 0x0CF8, // Address Range Maximum - 0x01, // Address Alignment - 0x08, // Address Length - ) - BOARD_SPECIFIC_PCI_RESOURSES - DWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite, - 0x00000000, // Address Space Granularity - 0x000A0000, // Address Range Minimum - 0x000BFFFF, // Address Range Maximum - 0x00000000, // Address Translation Offset - 0x00020000, // Address Length - ,, , AddressRangeMemory, TypeStatic) - DWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite, - 0x00000000, // Address Space Granularity - 0xE0000000, // Address Range Minimum - 0xFEBFFFFF, // Address Range Maximum - 0x00000000, // Address Translation Offset - 0x1EC00000, // Address Length - ,, PW32, AddressRangeMemory, TypeStatic) - }) - - Name(CR64, ResourceTemplate() { - QWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite, - 0x00000000, // Address Space Granularity - 0x8000000000, // Address Range Minimum - 0xFFFFFFFFFF, // Address Range Maximum - 0x00000000, // Address Translation Offset - 0x8000000000, // Address Length - ,, PW64, AddressRangeMemory, TypeStatic) - }) - - Method(_CRS, 0) { - /* Fields provided by dynamically created ssdt */ - External(P0S, IntObj) - External(P0E, IntObj) - External(P1V, IntObj) - External(P1S, BuffObj) - External(P1E, BuffObj) - External(P1L, BuffObj) - - /* fixup 32bit pci io window */ - CreateDWordField(CRES, \_SB.PCI0.PW32._MIN, PS32) - CreateDWordField(CRES, \_SB.PCI0.PW32._MAX, PE32) - CreateDWordField(CRES, \_SB.PCI0.PW32._LEN, PL32) - Store(P0S, PS32) - Store(P0E, PE32) - Store(Add(Subtract(P0E, P0S), 1), PL32) - - If (LEqual(P1V, Zero)) { - Return (CRES) - } - - /* fixup 64bit pci io window */ - CreateQWordField(CR64, \_SB.PCI0.PW64._MIN, PS64) - CreateQWordField(CR64, \_SB.PCI0.PW64._MAX, PE64) - CreateQWordField(CR64, \_SB.PCI0.PW64._LEN, PL64) - Store(P1S, PS64) - Store(P1E, PE64) - Store(P1L, PL64) - /* add window and return result */ - ConcatenateResTemplate(CRES, CR64, Local0) - Return (Local0) - } -}hw/i386/acpi-dsdt.dsl +0
-45@@ -31,50 +31,6 @@ DefinitionBlock ( #include "acpi-dsdt-dbug.dsl" - -/**************************************************************** - * PCI Bus definition - ****************************************************************/ -#define BOARD_SPECIFIC_PCI_RESOURSES \ - WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \ - 0x0000, \ - 0x0000, \ - 0x0CF7, \ - 0x0000, \ - 0x0CF8, \ - ,, , TypeStatic) \ - WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \ - 0x0000, \ - 0x0D00, \ - 0xADFF, \ - 0x0000, \ - 0xA100, \ - ,, , TypeStatic) \ - /* 0xae00-0xae0e hole for PCI hotplug, hw/acpi/piix4.c:PCI_HOTPLUG_ADDR */ \ - WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \ - 0x0000, \ - 0xAE0F, \ - 0xAEFF, \ - 0x0000, \ - 0x00F1, \ - ,, , TypeStatic) \ - /* 0xaf00-0xaf1f hole for CPU hotplug, hw/acpi/piix4.c:PIIX4_PROC_BASE */ \ - WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \ - 0x0000, \ - 0xAF20, \ - 0xAFDF, \ - 0x0000, \ - 0x00C0, \ - ,, , TypeStatic) \ - /* 0xafe0-0xafe3 hole for ACPI.GPE0, hw/acpi/piix4.c:GPE_BASE */ \ - WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \ - 0x0000, \ - 0xAFE4, \ - 0xFFFF, \ - 0x0000, \ - 0x501C, \ - ,, , TypeStatic) - Scope(\_SB) { Device(PCI0) { Name(_HID, EisaId("PNP0A03"))@@ -85,7 +41,6 @@ DefinitionBlock ( } } -#include "acpi-dsdt-pci-crs.dsl" #include "acpi-dsdt-hpet.dsl"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 v4 39/42 pc: acpi-build: drop remaining ssdt_misc template
In reply to Igor MammedovIt drops empty ssdt_misc templete. It also hides from user almost all pointer arithmetic when building SSDT which makes resulting code a bit cleaner and concentrating only on composing ASL construct /i.e. a task build_ssdt() should be doing/.
Also it makes one binary blob less stored in QEMU source tree by removing need to keep and update hw/i386/ssdt-misc.hex.generated file here in total saving us ~430LOC.
--- hw/i386/Makefile.objs | 1 - hw/i386/acpi-build.c | 7 ++----- hw/i386/ssdt-misc.dsl | 21 --------------------- 3 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 hw/i386/ssdt-misc.dsl
hw/i386/Makefile.objs +0 -1
@@ -10,7 +10,6 @@ obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c \ hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ hw/i386/ssdt-pcihp.hex \ - hw/i386/ssdt-misc.hex \ hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
hw/i386/acpi-build.c +2 -5
@@ -526,7 +526,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_SSDT_SIGNATURE 0x54445353/* SSDT */ #define ACPI_SSDT_HEADER_LENGTH 36 -#include "hw/i386/ssdt-misc.hex" #include "hw/i386/ssdt-pcihp.hex" #include "hw/i386/ssdt-tpm.hex"
@@ -850,7 +849,6 @@ build_ssdt(GArray *table_data, GArray *linker,MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -uint8_t *ssdt_ptr;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;int i;
@@ -860,9 +858,8 @@ build_ssdt(GArray *table_data, GArray *linker,QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 );g_assert (acpi_cpus <=ACPI_CPU_HOTPLUG_ID_LIMIT ); -/* Copy header and patch values in the S3_ / S4_ / S5_ packages */ - ssdt_ptr =acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml)); -memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); +/* Reserve space for header */ +acpi_data_push (ssdt->buf,sizeof (AcpiTableHeader)); scope =aml_scope ("\\_SB.PCI0" );/* build PCI0._CRS */
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) -{ -}
Signature · 1 line
1.8.3.1
PATCH v4 40/42 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
@@ -514,6 +514,27 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,return var; } +/* +* ACPI 1.0b: 6.4.2.1.1 ASL Macro for IRQ Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro) +* 6.4.2.1 IRQ Descriptor +*/ +Aml *aml_irq_no_flags (uint8_t irq) +{ +uint16_t irq_mask; +Aml *var =aml_alloc (); + +assert (irq <16 ); +build_append_byte (var->buf,0x22 );/* IRQ descriptor 2 byte form */ + + irq_mask =1U << irq; +build_append_byte (var->buf, irq_mask &0xFF );/* IRQ mask bits[7:0] */ +build_append_byte (var->buf, irq_mask >>8 );/* IRQ mask bits[15:8] */ +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */ Aml *aml_equal (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -146,6 +146,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, uint8_t aln, uint8_t len);Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len); +Aml *aml_irq_no_flags (uint8_t irq);Aml *aml_named_field (const char *name,unsigned length);Aml *aml_reserved_field (unsigned length);Aml *aml_local (int num);
Signature · 1 line
1.8.3.1
PATCH v4 41/42 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
@@ -145,7 +145,7 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)/* Patch in appropriate value for AppleSMC _STA */ *(uint8_t *)(info->dsdt_code + *applesmc_sta) = -applesmc_find () ?0x0b :0x00 ; +applesmc_port () ?0x0b :0x00 ; } static
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 v4 42/42 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
@@ -116,6 +116,7 @@ typedef struct AcpiMiscInfo {const unsigned char *dsdt_code;unsigned dsdt_size;uint16_t pvpanic_port; +uint16_t applesmc_io_base; } AcpiMiscInfo; typedef struct AcpiBuildPciBusHotplugState {
@@ -127,7 +128,6 @@ typedef struct AcpiBuildPciBusHotplugState {static void acpi_get_dsdt (AcpiMiscInfo *info) { -uint16_t *applesmc_sta;Object *piix =piix4_pm_find ();Object *lpc =ich9_lpc_find ();assert (!!piix != !!lpc);
@@ -135,17 +135,11 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)if (piix) { info->dsdt_code = AcpiDsdtAmlCode; info->dsdt_size =sizeof AcpiDsdtAmlCode; - applesmc_sta = piix_dsdt_applesmc_sta; }if (lpc) { info->dsdt_code = Q35AcpiDsdtAmlCode; info->dsdt_size =sizeof Q35AcpiDsdtAmlCode; - applesmc_sta = q35_dsdt_applesmc_sta; } - -/* Patch in appropriate value for AppleSMC _STA */ - *(uint8_t *)(info->dsdt_code + *applesmc_sta) = -applesmc_port () ?0x0b :0x00 ; } static
@@ -248,6 +242,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) info->has_hpet =hpet_find (); info->has_tpm =tpm_find (); info->pvpanic_port =pvpanic_port (); + info->applesmc_io_base =applesmc_port (); }static void acpi_get_pci_info (PcPciInfo *info)
@@ -942,6 +937,26 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (scope,aml_name_decl ("_S5" , pkg));aml_append (ssdt, scope); +if (misc->applesmc_io_base) { + scope =aml_scope ("\\_SB.PCI0.ISA" ); + dev =aml_device ("SMC" ); + +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("APP0001" ))); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, misc->applesmc_io_base, misc->applesmc_io_base, +0x01 ,APPLESMC_MAX_DATA_LENGTH ) + ); +aml_append (crs,aml_irq_no_flags (6 )); +aml_append (dev,aml_name_decl ("_CRS" , crs)); + +aml_append (scope, dev); +aml_append (ssdt, scope); + } +if (misc->pvpanic_port) { scope =aml_scope ("\\_SB.PCI0.ISA" );
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