ACPI: boot time AML overlay support
cover ACPI: boot time AML overlay support
Hi, all,
ACPICA support for OSDT (Override System Definition Table) is introduced recently. commit fe536995f2 (ACPICA: Namespace: Add support of OSDT table)
With this support, it is able to partially override the ACPI namespace by providing an OSDT table, which either can be used by OEMs to make fast changes to match their BOM changes, or can be used by end user/developer to verify/workaround some BIOS bugs.
This patch set introduces boot time AML overlay, by using the ACPI_INITRD_TABLE_OVERRIDE feature. In this way, people can append the compiled OSDT table to initrd, and install them at boot time, so that they are recognized just like any other static tables described in RSDT/XSDT table.
In order to use AML overlay, we need to
1. rebuild the kernel with CONFIG_ACPI_INITRD_TABLE_OVERRIDE set
2. write an OSDT table, for example, I use the following ASL code to a. override the existing _SB.ADP1.PSR control method.
b. override the existing _SB.RUIX name object.
c. introduce new _SB.ADP2 device object, with its own name/method objects. DefinitionBlock ("osdt1.aml", "OSDT", 1, "", "ADPX", 0x00001000) {
External (PWRS, IntObj)
External (\_SB.ADP1, DeviceObj)
Scope (_SB.ADP1)
{
Method (_PSR, 0, NotSerialized) // _PSR: Power Source
{
Store ("Customized ADP1", Debug)
Return (PWRS) /* External reference */
}
}
Scope (_SB)
{
Name (RUIX, 0x02)
Device (ADP2)
{
Name (_HID, "ACPI0003" /* Power Source Device */)
Name (_STA, 0x0F) // _STA: Status
Method (_PSR, 0, NotSerialized) // _PSR: Power Source
{
Store ("Customized ADP2", Debug)
Store (RUIX, Debug)
Return (PWRS) /* External reference */
}
}
} }
3. compile the asl code to get .aml file (iasl -tc foo.dsl).
4. append the .aml tables into initrd, e.g.
# directory of .aml files in initrd mkdir -p kernel/firmware/acpi cp ./foo.aml kernel/firmware/acpi/ # create a new initrd with .aml and the clean initrd appended find kernel | cpio -H newc --create > /boot/initrd.img-new cat /boot/initrd.img-origin >>/boot/initrd.img-new for more details of using ACPI_INITRD_TABLE_OVERRIDE feature, you can refer to https://www.kernel.org/doc/Documentation/acpi/initrd_table_override.txt 5. reboot using the new initrd 6. In the dmesg, you should see something like [ 0.000000] ACPI: Override [OSDT-ADPX ], this is unsafe: tainting kernel [ 0.000000] Disabling lock debugging due to kernel taint which means the OSDT table is successfully loaded to ACPI namespace.
I have tested this patch set to override existing method/name objects, and introduce new device/name/method objects, using the sample ASL code above, and everything seems to work well.
Any comments are welcome.
thanks,
rui
PATCH 1/2 ACPI / OSL: Cleanup initrd table override code.
From: Lv Zheng <[email protected]>
This patch cleans up initrd table override code, merging redundant logics and re-ordering code blocks. No functional changes.
--- drivers/acpi/osl.c | 100 +++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 56 deletions(-)
drivers/acpi/osl.c +44 -56
@@ -576,6 +576,14 @@ acpi_os_predefined_override(const struct acpi_predefined_names *init_val,return AE_OK ; } +static void acpi_table_taint (struct acpi_table_header *table) +{ +pr_warn (PREFIX +"Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n" , + table->signature, table->oem_table_id); +add_taint (TAINT_OVERRIDDEN_ACPI_TABLE ,LOCKDEP_NOW_UNRELIABLE ); +} +#ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE #include <linux/earlycpio.h> #include <linux/memblock.h>
@@ -720,96 +728,76 @@ void __init acpi_initrd_override(void *data, size_t size) } } } -#endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */ - -static void acpi_table_taint (struct acpi_table_header *table) -{ -pr_warn (PREFIX -"Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n" , - table->signature, table->oem_table_id); -add_taint (TAINT_OVERRIDDEN_ACPI_TABLE ,LOCKDEP_NOW_UNRELIABLE ); -} - - -acpi_status -acpi_os_table_override (struct acpi_table_header * existing_table, -struct acpi_table_header ** new_table) -{ -if (!existing_table || !new_table) -return AE_BAD_PARAMETER ; - - *new_table =NULL ; - -#ifdef CONFIG_ACPI_CUSTOM_DSDT -if (strncmp (existing_table->signature,"DSDT" ,4 ) ==0 ) - *new_table = (struct acpi_table_header *)AmlCode; -#endif -if (*new_table !=NULL ) -acpi_table_taint (existing_table); -return AE_OK ; -}acpi_status acpi_os_physical_table_override (struct acpi_table_header *existing_table,acpi_physical_address *address,u32 *table_length) { -#ifndef CONFIG_ACPI_INITRD_TABLE_OVERRIDE - *table_length =0 ; - *address =0 ; -return AE_OK ; -#else int table_offset =0 ;struct acpi_table_header *table; *table_length =0 ; *address =0 ; -if (!acpi_tables_addr)return AE_OK ; -do { -if (table_offset +ACPI_HEADER_SIZE > all_tables_size) { -WARN_ON (1 ); -return AE_OK ; - } - +while (table_offset +ACPI_HEADER_SIZE < all_tables_size) { table =acpi_os_map_memory (acpi_tables_addr + table_offset,ACPI_HEADER_SIZE ); -if (table_offset + table->length > all_tables_size) {acpi_os_unmap_memory (table,ACPI_HEADER_SIZE );WARN_ON (1 );return AE_OK ; } - table_offset += table->length; - -if (memcmp (existing_table->signature, table->signature,4 )) { -acpi_os_unmap_memory (table, -ACPI_HEADER_SIZE ); -continue ; - } - -/* Only override tables with matching oem id */ -if (memcmp (table->oem_table_id, existing_table->oem_table_id, +/* Only override tables matched */ +if (memcmp (existing_table->signature, table->signature,4 ) || +memcmp (table->oem_table_id, existing_table->oem_table_id,ACPI_OEM_TABLE_ID_SIZE )) { + table_offset += table->length;acpi_os_unmap_memory (table,ACPI_HEADER_SIZE );continue ; } - table_offset -= table->length; *table_length = table->length; -acpi_os_unmap_memory (table,ACPI_HEADER_SIZE ); *address = acpi_tables_addr + table_offset; +acpi_table_taint (existing_table); + +acpi_os_unmap_memory (table,ACPI_HEADER_SIZE );break ; - }while (table_offset +ACPI_HEADER_SIZE < all_tables_size); + } +return AE_OK ; +} +#else +acpi_status +acpi_os_physical_table_override (struct acpi_table_header *existing_table, +acpi_physical_address *address, +u32 *table_length) +{ + *table_length =0 ; + *address =0 ; +return AE_OK ; +} +#endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */ -if (*address !=0 ) +acpi_status +acpi_os_table_override (struct acpi_table_header * existing_table, +struct acpi_table_header ** new_table) +{ +if (!existing_table || !new_table) +return AE_BAD_PARAMETER ; + + *new_table =NULL ; + +#ifdef CONFIG_ACPI_CUSTOM_DSDT +if (strncmp (existing_table->signature,"DSDT" ,4 ) ==0 ) + *new_table = (struct acpi_table_header *)AmlCode; +#endif +if (*new_table !=NULL )acpi_table_taint (existing_table);return AE_OK ; -#endif }static irqreturn_t acpi_irq (int irq,void *dev_id)
Signature · 1 line
1.9.1
RFC PATCH 2/2 ACPI: Load OSDT tables from initrd at boot time
In reply to Zhang RuiThis patch uses ACPI_INITRD_TABLE_OVERRIDE feature to load the OSDT tables from initrd and install them at boot time.
--- drivers/acpi/internal.h | 1 + drivers/acpi/osl.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/acpi/tables.c | 3 +++ 3 files changed, 51 insertions(+), 1 deletion(-)
drivers/acpi/internal.h +1 -0
@@ -25,6 +25,7 @@acpi_status acpi_os_initialize1 (void );int init_acpi_device_notify (void ); +int acpi_load_osdt (void );int acpi_scan_init (void );void acpi_pci_root_init (void );void acpi_pci_link_init (void );
drivers/acpi/osl.c +47 -1
66 lines not on this page · raw message
drivers/acpi/tables.c +3 -0
@@ -37,6 +37,7 @@#include <linux/acpi.h> #include <linux/bootmem.h> +#include "internal.h" #define ACPI_MAX_TABLES 128static char *mps_inti_flags_polarity[] = {"dfl" ,"high" ,"res" ,"low" };
@@ -403,6 +404,8 @@ int __init acpi_table_init(void)if (ACPI_FAILURE (status))return -EINVAL ; +acpi_load_osdt (); +check_multiple_madt ();return 0 ; }
Signature · 1 line
1.9.1