From a7718df2e71900af4cd6505c9e4bc3729ca51a5c Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Mon, 10 Jul 2017 15:22:45 +0800 Subject: [PATCH 01/32] ACPICA: Small indentation changes, no functional change ACPICA commit bb457076d42b95b1453e261da2c8cc0c05ba4718 Fix some alignment issues Link: https://github.com/acpica/acpica/commit/bb457076 Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/aclocal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h index 8ddd3b20e0c6..822dbc5eee18 100644 --- a/drivers/acpi/acpica/aclocal.h +++ b/drivers/acpi/acpica/aclocal.h @@ -867,7 +867,7 @@ struct acpi_parse_obj_named { /* This version is used by the iASL compiler only */ -#define ACPI_MAX_PARSEOP_NAME 20 +#define ACPI_MAX_PARSEOP_NAME 20 struct acpi_parse_obj_asl { ACPI_PARSE_COMMON union acpi_parse_object *child; @@ -907,7 +907,7 @@ union acpi_parse_object { struct asl_comment_state { u8 comment_type; u32 spaces_before; - union acpi_parse_object *latest_parse_node; + union acpi_parse_object *latest_parse_op; union acpi_parse_object *parsing_paren_brace_node; u8 capture_comments; }; From 0c2021c047baa75f88996f2c732ecbac3e4fba29 Mon Sep 17 00:00:00 2001 From: Robin Murphy Date: Mon, 10 Jul 2017 15:22:51 +0800 Subject: [PATCH 02/32] ACPICA: IORT: Update SMMU models for revision C ACPICA commit d00a4eb86e64bb4fa70f57ab5e5ca0a4ca2ad8ef IORT revision C has been published with a number of new SMMU implementation identifiers; define them. Link: https://github.com/acpica/acpica/commit/d00a4eb8 Signed-off-by: Robin Murphy Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- include/acpi/actbl2.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 707dda74c272..5829eedbf3ff 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -664,7 +664,7 @@ struct acpi_ibft_target { * IORT - IO Remapping Table * * Conforms to "IO Remapping Table System Software on ARM Platforms", - * Document number: ARM DEN 0049B, October 2015 + * Document number: ARM DEN 0049C, May 2017 * ******************************************************************************/ @@ -779,6 +779,8 @@ struct acpi_iort_smmu { #define ACPI_IORT_SMMU_V2 0x00000001 /* Generic SMMUv2 */ #define ACPI_IORT_SMMU_CORELINK_MMU400 0x00000002 /* ARM Corelink MMU-400 */ #define ACPI_IORT_SMMU_CORELINK_MMU500 0x00000003 /* ARM Corelink MMU-500 */ +#define ACPI_IORT_SMMU_CORELINK_MMU401 0x00000004 /* ARM Corelink MMU-401 */ +#define ACPI_IORT_SMMU_CAVIUM_THUNDERX 0x00000005 /* Cavium thunder_x SMMUv2 */ /* Masks for Flags field above */ @@ -799,13 +801,19 @@ struct acpi_iort_smmu_v3 { u32 flags; u32 reserved; u64 vatos_address; - u32 model; /* O: generic SMMUv3 */ + u32 model; u32 event_gsiv; u32 pri_gsiv; u32 gerr_gsiv; u32 sync_gsiv; }; +/* Values for Model field above */ + +#define ACPI_IORT_SMMU_V3_GENERIC 0x00000000 /* Generic SMMUv3 */ +#define ACPI_IORT_SMMU_V3_HISILICON_HI161X 0x00000001 /* hi_silicon Hi161x SMMUv3 */ +#define ACPI_IORT_SMMU_V3_CAVIUM_CN99XX 0x00000002 /* Cavium CN99xx SMMUv3 */ + /* Masks for Flags field above */ #define ACPI_IORT_SMMU_V3_COHACC_OVERRIDE (1) From ff7993a753413b19c1fb9566fc80ddbf5dc785e1 Mon Sep 17 00:00:00 2001 From: Erik Schmauss Date: Mon, 10 Jul 2017 15:22:56 +0800 Subject: [PATCH 03/32] ACPICA: Tools: Deallocate memory allocated by ac_get_all_tables_from_file via ac_delete_table_list ACPICA commit 8521b98ebdea450011fa62c14a77fed9affa4236 Link: https://github.com/acpica/acpica/commit/8521b98e Signed-off-by: Erik Schmauss Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/acapps.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/acpi/acpica/acapps.h b/drivers/acpi/acpica/acapps.h index bb6a84b0b4b3..7a1a68b5ac5c 100644 --- a/drivers/acpi/acpica/acapps.h +++ b/drivers/acpi/acpica/acapps.h @@ -114,6 +114,8 @@ ac_get_all_tables_from_file(char *filename, u8 get_only_aml_tables, struct acpi_new_table_desc **return_list_head); +void ac_delete_table_list(struct acpi_new_table_desc *list_head); + u8 ac_is_file_binary(FILE * file); acpi_status ac_validate_table_header(FILE * file, long table_offset); From 3ddd3f6a94108a5d2abfaa2a2f809b1520361e5e Mon Sep 17 00:00:00 2001 From: Erik Schmauss Date: Mon, 10 Jul 2017 15:23:02 +0800 Subject: [PATCH 04/32] ACPICA: iASL compiler: allow compilation of externals with paths that refer to existing names ACPICA commit 9a252114197409290813bee570e9d53c22b99d32 This change allows compilation of code like the following: definition_block (...) { External (ABCD.EFGH) Device (ABCD) { Name (IJLK,0) } } but does not allow compilation of code like the following: definition_block (...) { External (ABCD) Device (ABCD) { Name (EFGH,0) } } Link: https://github.com/acpica/acpica/commit/9a252114 Signed-off-by: Erik Schmauss Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/aclocal.h | 1 + drivers/acpi/acpica/nsaccess.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h index 822dbc5eee18..bae943b5f377 100644 --- a/drivers/acpi/acpica/aclocal.h +++ b/drivers/acpi/acpica/aclocal.h @@ -199,6 +199,7 @@ struct acpi_namespace_node { #define ANOBJ_EVALUATED 0x20 /* Set on first evaluation of node */ #define ANOBJ_ALLOCATED_BUFFER 0x40 /* Method AML buffer is dynamic (install_method) */ +#define IMPLICIT_EXTERNAL 0x02 /* iASL only: This object created implicitly via External */ #define ANOBJ_IS_EXTERNAL 0x08 /* iASL only: This object created via External() */ #define ANOBJ_METHOD_NO_RETVAL 0x10 /* iASL only: Method has no return value */ #define ANOBJ_METHOD_SOME_NO_RETVAL 0x20 /* iASL only: Method has at least one return value */ diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c index e5f4fa496572..14be12fe9f35 100644 --- a/drivers/acpi/acpica/nsaccess.c +++ b/drivers/acpi/acpica/nsaccess.c @@ -634,6 +634,12 @@ acpi_ns_lookup(union acpi_generic_state *scope_info, this_node->object; } } +#ifdef ACPI_ASL_COMPILER + if (!acpi_gbl_disasm_flag && + (this_node->flags & ANOBJ_IS_EXTERNAL)) { + this_node->flags |= IMPLICIT_EXTERNAL; + } +#endif } /* Special handling for the last segment (num_segments == 0) */ From 99e597adf60e1a6f83ec746db8cab225b16a838b Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Mon, 10 Jul 2017 15:23:08 +0800 Subject: [PATCH 05/32] Back port of "ACPICA: Use designated initializers" ACPICA commit 47538f5f0773c0820d8f552e20f6e77104290c01 The following commit is not correctly linuxized by its ACPICA form (see link #1 for reference): Commit: 3d867f6c5fd6535cdeceef3170e5e84e5dd80fc1 Subject: ACPICA: Use designated initializers Thus breaks linuxize process. This patch is a linuxized back port result of the upstreamed ACPICA commit (see link #2 for reference). Link: https://github.com/acpica/acpica/pull/248/ [#1] Link: https://github.com/acpica/acpica/commit/47538f5f [#2] Signed-off-by: Kees Cook Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/hwxfsleep.c | 9 ++++++--- include/acpi/platform/acenv.h | 9 +++++---- include/acpi/platform/aclinux.h | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c index 7ef13934968f..e5c095ca6083 100644 --- a/drivers/acpi/acpica/hwxfsleep.c +++ b/drivers/acpi/acpica/hwxfsleep.c @@ -72,13 +72,16 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id); static struct acpi_sleep_functions acpi_sleep_dispatch[] = { {ACPI_STRUCT_INIT(legacy_function, ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep)), - ACPI_STRUCT_INIT(extended_function, acpi_hw_extended_sleep) }, + ACPI_STRUCT_INIT(extended_function, + acpi_hw_extended_sleep)}, {ACPI_STRUCT_INIT(legacy_function, ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep)), - ACPI_STRUCT_INIT(extended_function, acpi_hw_extended_wake_prep) }, + ACPI_STRUCT_INIT(extended_function, + acpi_hw_extended_wake_prep)}, {ACPI_STRUCT_INIT(legacy_function, ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake)), - ACPI_STRUCT_INIT(extended_function, acpi_hw_extended_wake) } + ACPI_STRUCT_INIT(extended_function, + acpi_hw_extended_wake)} }; /* diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h index 912563c66948..043fd559de6e 100644 --- a/include/acpi/platform/acenv.h +++ b/include/acpi/platform/acenv.h @@ -288,6 +288,11 @@ #define ACPI_INLINE #endif +/* Use ordered initialization if compiler doesn't support designated. */ +#ifndef ACPI_STRUCT_INIT +#define ACPI_STRUCT_INIT(field, value) value +#endif + /* * Configurable calling conventions: * @@ -382,8 +387,4 @@ #define ACPI_INIT_FUNCTION #endif -#ifndef ACPI_STRUCT_INIT -#define ACPI_STRUCT_INIT(field, value) value -#endif - #endif /* __ACENV_H__ */ diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h index 047f13865608..afd95f28c8f0 100644 --- a/include/acpi/platform/aclinux.h +++ b/include/acpi/platform/aclinux.h @@ -178,6 +178,9 @@ #define ACPI_MSG_BIOS_ERROR KERN_ERR "ACPI BIOS Error (bug): " #define ACPI_MSG_BIOS_WARNING KERN_WARNING "ACPI BIOS Warning (bug): " +/* + * Linux wants to use designated initializers for function pointer structs. + */ #define ACPI_STRUCT_INIT(field, value) .field = value #else /* !__KERNEL__ */ From 7679c35da5b5afa78ce6766f5966a5a4579d4332 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 10 Jul 2017 15:23:15 +0800 Subject: [PATCH 06/32] ACPICA: linuxize: cleanup typedef definitions ACPICA commit 894e49ef22db354eb1685cdb6f5f991766351d3c acpisrc now has capability to convert both the followings: 1. Form 1: typedef struct/union foo { struct/union foo { .... --> ... } FOO; } 2. Form 2: typedef struct/union foo FOO; --> typedef struct/union foo foo; It becomes unable to handle the following: 3. Form3: typedef struct/union foo { /* comment */ ... } FOO; --> strut/union foo { /* comment */ ... }; As: 1. The purpose of acpisrc is to convert formatted code (ACPICA coding style) into linux coding style, 2. acpisrc is a very simple tool that doesn't fully handle C language. This commit changes the definitions side in order not to regress and we shall make "no comments in struct/union line" as a new ACPICA coding style rule. Lv Zheng. Link: https://github.com/acpica/acpica/commit/894e49ef Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/acobject.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/acpica/acobject.h b/drivers/acpi/acpica/acobject.h index 27c3f982d810..549f227348cd 100644 --- a/drivers/acpi/acpica/acobject.h +++ b/drivers/acpi/acpica/acobject.h @@ -122,7 +122,9 @@ struct acpi_object_integer { _type *pointer; \ u32 length; -struct acpi_object_string { /* Null terminated, ASCII characters only */ +/* Null terminated, ASCII characters only */ + +struct acpi_object_string { ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(char) /* String in AML stream or allocated string */ }; @@ -211,7 +213,9 @@ struct acpi_object_method { union acpi_operand_object *notify_list[2]; /* Handlers for system/device notifies */\ union acpi_operand_object *handler; /* Handler for Address space */ -struct acpi_object_notify_common { /* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */ +/* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */ + +struct acpi_object_notify_common { ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO}; struct acpi_object_device { @@ -258,7 +262,9 @@ ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO}; u8 access_length; /* For serial regions/fields */ -struct acpi_object_field_common { /* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */ +/* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */ + +struct acpi_object_field_common { ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj; /* Parent Operation Region object (REGION/BANK fields only) */ }; From 96d07940623a2a40b2eec01daebf93bbaaee8a3b Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 10 Jul 2017 15:23:21 +0800 Subject: [PATCH 07/32] ACPICA: Tables: Add sanity check in acpi_put_table() ACPICA commit 73512384c9eb1e7f1b28d0a7372df26a3732f96b To avoid caller to trigger unexpected warning messages (Link #1): ACPI Warning: Table ffffffffbb461d20, Validation count is zero before decrement Which is reported from acpi_tb_put_table(). When the table is validated, the pointer must be non-zero. Thus the message is not suitable for invalidated tables. This patch fixes the callee side based on this fact. Reported by Cristian Aravena Romero, Fixed by Lv Zheng. Link: https://github.com/acpica/acpica/commit/73512384 Link: https://bugzilla.kernel.org/show_bug.cgi?id=191221 [#1] Reported-by: Cristian Aravena Romero Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/tbxface.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c index 010b1c43df92..18508b2c0c05 100644 --- a/drivers/acpi/acpica/tbxface.c +++ b/drivers/acpi/acpica/tbxface.c @@ -369,6 +369,10 @@ void acpi_put_table(struct acpi_table_header *table) ACPI_FUNCTION_TRACE(acpi_put_table); + if (!table) { + return_VOID; + } + (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); /* Walk the root table list */ From 9b019b0f67bf527d6412de0497702026ff37e8a6 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 10 Jul 2017 15:23:28 +0800 Subject: [PATCH 08/32] ACPICA: Tables: Cleanup table handler invokers ACPICA commit 4551f51fa8ba33a977721c3b250cb70a309e3f23 Recently, we allows the table mutex to be held in both early and late stage APIs. This patch further cleans up the related code to reduce redundant code related to acpi_gbl_table_handler. Lv Zheng. Link: https://github.com/acpica/acpica/commit/4551f51f Tested-by: Hans de Goede Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/actables.h | 2 ++ drivers/acpi/acpica/tbdata.c | 43 +++++++++++++++++++++++----------- drivers/acpi/acpica/tbinstal.c | 8 ++----- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/acpica/actables.h b/drivers/acpi/acpica/actables.h index c8da453bd960..89ed31b0f739 100644 --- a/drivers/acpi/acpica/actables.h +++ b/drivers/acpi/acpica/actables.h @@ -132,6 +132,8 @@ acpi_tb_install_and_load_table(acpi_physical_address address, acpi_status acpi_tb_unload_table(u32 table_index); +void acpi_tb_notify_table(u32 event, void *table); + void acpi_tb_terminate(void); acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index); diff --git a/drivers/acpi/acpica/tbdata.c b/drivers/acpi/acpica/tbdata.c index c9d6fa6d7cc6..7056ca01e875 100644 --- a/drivers/acpi/acpica/tbdata.c +++ b/drivers/acpi/acpica/tbdata.c @@ -818,13 +818,9 @@ acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node) acpi_ev_update_gpes(owner_id); } - /* Invoke table handler if present */ - - if (acpi_gbl_table_handler) { - (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table, - acpi_gbl_table_handler_context); - } + /* Invoke table handler */ + acpi_tb_notify_table(ACPI_TABLE_EVENT_LOAD, table); return_ACPI_STATUS(status); } @@ -894,15 +890,11 @@ acpi_status acpi_tb_unload_table(u32 table_index) return_ACPI_STATUS(AE_NOT_EXIST); } - /* Invoke table handler if present */ + /* Invoke table handler */ - if (acpi_gbl_table_handler) { - status = acpi_get_table_by_index(table_index, &table); - if (ACPI_SUCCESS(status)) { - (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD, - table, - acpi_gbl_table_handler_context); - } + status = acpi_get_table_by_index(table_index, &table); + if (ACPI_SUCCESS(status)) { + acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table); } /* Delete the portion of the namespace owned by this table */ @@ -918,3 +910,26 @@ acpi_status acpi_tb_unload_table(u32 table_index) } ACPI_EXPORT_SYMBOL(acpi_tb_unload_table) + +/******************************************************************************* + * + * FUNCTION: acpi_tb_notify_table + * + * PARAMETERS: event - Table event + * table - Validated table pointer + * + * RETURN: None + * + * DESCRIPTION: Notify a table event to the users. + * + ******************************************************************************/ + +void acpi_tb_notify_table(u32 event, void *table) +{ + /* Invoke table handler if present */ + + if (acpi_gbl_table_handler) { + (void)acpi_gbl_table_handler(event, table, + acpi_gbl_table_handler_context); + } +} diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c index 4620f3c68c13..ee745152f25b 100644 --- a/drivers/acpi/acpica/tbinstal.c +++ b/drivers/acpi/acpica/tbinstal.c @@ -306,14 +306,10 @@ acpi_tb_install_standard_table(acpi_physical_address address, acpi_tb_install_table_with_override(&new_table_desc, override, table_index); - /* Invoke table handler if present */ + /* Invoke table handler */ (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); - if (acpi_gbl_table_handler) { - (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_INSTALL, - new_table_desc.pointer, - acpi_gbl_table_handler_context); - } + acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer); (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); unlock_and_exit: From 04ba15aa55cf16e18757faea55d62d1b7e407fe3 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 10 Jul 2017 15:23:37 +0800 Subject: [PATCH 09/32] ACPICA: Tables: Do not validate signature for dynamic table load ACPICA commit d3c944f2cdc8c7e847b7942b1864f285189f7bce Windows seems to allow arbitrary table signatures for Load/load_table opcodes: ACPI BIOS Error (bug): Table has invalid signature [PRAD] (0x44415250) So this patch removes dynamic load signature checks. However we need to find a way to avoid table loading against tables like MADT. This is not covered by this commit. This Windows behavior has been validated on link #1. An end user bug report can also be found on link #2. This patch also includes simple cleanup for static load signature check code. Reported by Ye Xiaolong, Fixed by Lv Zheng. Link: https://github.com/acpica/acpica/commit/d3c944f2 Link: https://github.com/acpica/acpica/pull/121 [#1] Link: https://bugzilla.kernel.org/show_bug.cgi?id=118601 [#2] Reported-by: Ye Xiaolong Reported-by: Olga Uhina Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/tbinstal.c | 28 ---------------------------- drivers/acpi/acpica/tbxfload.c | 2 +- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c index ee745152f25b..9d212967fad8 100644 --- a/drivers/acpi/acpica/tbinstal.c +++ b/drivers/acpi/acpica/tbinstal.c @@ -222,34 +222,6 @@ acpi_tb_install_standard_table(acpi_physical_address address, (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); if (reload) { - /* - * Validate the incoming table signature. - * - * 1) Originally, we checked the table signature for "SSDT" or "PSDT". - * 2) We added support for OEMx tables, signature "OEM". - * 3) Valid tables were encountered with a null signature, so we just - * gave up on validating the signature, (05/2008). - * 4) We encountered non-AML tables such as the MADT, which caused - * interpreter errors and kernel faults. So now, we once again allow - * only "SSDT", "OEMx", and now, also a null signature. (05/2011). - */ - if ((new_table_desc.signature.ascii[0] != 0x00) && - (!ACPI_COMPARE_NAME - (&new_table_desc.signature, ACPI_SIG_SSDT)) - && (strncmp(new_table_desc.signature.ascii, "OEM", 3))) { - ACPI_BIOS_ERROR((AE_INFO, - "Table has invalid signature [%4.4s] (0x%8.8X), " - "must be SSDT or OEMx", - acpi_ut_valid_nameseg(new_table_desc. - signature. - ascii) ? - new_table_desc.signature. - ascii : "????", - new_table_desc.signature.integer)); - - status = AE_BAD_SIGNATURE; - goto unlock_and_exit; - } /* Check if table is already registered */ diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c index b71ce3b817ea..d81f442228b8 100644 --- a/drivers/acpi/acpica/tbxfload.c +++ b/drivers/acpi/acpica/tbxfload.c @@ -206,7 +206,7 @@ acpi_status acpi_tb_load_namespace(void) for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { table = &acpi_gbl_root_table_list.tables[i]; - if (!acpi_gbl_root_table_list.tables[i].address || + if (!table->address || (!ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_SSDT) && !ACPI_COMPARE_NAME(table->signature.ascii, ACPI_SIG_PSDT) From 023e2ee16c51da7f6a9455ac936e4fb00295f47a Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 10 Jul 2017 15:23:45 +0800 Subject: [PATCH 10/32] ACPICA: Tables: Change table duplication check to be related to acpi_gbl_verify_table_checksum ACPICA commit 3d837b5d4b1033942b4d91c7d3801a09c3157918 acpi_gbl_verify_table_checksum is used to avoid validating (mapping) an entire table in OS boot stage. 2nd "Reload" check in acpi_tb_install_standard_table() is prepared for the same purpose. So this patch combines them together using a renamed acpi_gbl_enable_table_validation flag. Lv Zheng. Link: https://github.com/acpica/acpica/commit/3d837b5d Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/tbdata.c | 4 ++-- drivers/acpi/acpica/tbinstal.c | 2 +- drivers/acpi/acpica/tbxface.c | 8 ++++++++ drivers/acpi/bus.c | 3 --- drivers/acpi/tables.c | 4 ++-- include/acpi/acpixf.h | 13 +++++++------ 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/acpi/acpica/tbdata.c b/drivers/acpi/acpica/tbdata.c index 7056ca01e875..24d99711b2a4 100644 --- a/drivers/acpi/acpica/tbdata.c +++ b/drivers/acpi/acpica/tbdata.c @@ -338,7 +338,7 @@ void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc) acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc) { - if (!table_desc->pointer && !acpi_gbl_verify_table_checksum) { + if (!table_desc->pointer && !acpi_gbl_enable_table_validation) { /* * Only validates the header of the table. * Note that Length contains the size of the mapping after invoking @@ -394,7 +394,7 @@ acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature) /* Verify the checksum */ - if (acpi_gbl_verify_table_checksum) { + if (acpi_gbl_enable_table_validation) { status = acpi_tb_verify_checksum(table_desc->pointer, table_desc->length); diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c index 9d212967fad8..f7bc362bd3c5 100644 --- a/drivers/acpi/acpica/tbinstal.c +++ b/drivers/acpi/acpica/tbinstal.c @@ -221,7 +221,7 @@ acpi_tb_install_standard_table(acpi_physical_address address, (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); - if (reload) { + if (acpi_gbl_enable_table_validation) { /* Check if table is already registered */ diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c index 18508b2c0c05..38c01049afd5 100644 --- a/drivers/acpi/acpica/tbxface.c +++ b/drivers/acpi/acpica/tbxface.c @@ -194,6 +194,14 @@ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void) } } + if (!acpi_gbl_enable_table_validation) { + /* + * Now it's safe to do full table validation. We can do deferred + * table initilization here once the flag is set. + */ + acpi_gbl_enable_table_validation = TRUE; + } + acpi_gbl_root_table_list.flags |= ACPI_ROOT_ALLOW_RESIZE; status = acpi_tb_resize_root_table_list(); diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index af74b420ec83..59f2f96fdb7e 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -995,9 +995,6 @@ void __init acpi_early_init(void) printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); - /* It's safe to verify table checksums during late stage */ - acpi_gbl_verify_table_checksum = TRUE; - /* enable workarounds, unless strict ACPI spec. compliance */ if (!acpi_strict) acpi_gbl_enable_interpreter_slack = TRUE; diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index ff425390bfa8..80ce2a7d224b 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -740,10 +740,10 @@ int __init acpi_table_init(void) if (acpi_verify_table_checksum) { pr_info("Early table checksum verification enabled\n"); - acpi_gbl_verify_table_checksum = TRUE; + acpi_gbl_enable_table_validation = TRUE; } else { pr_info("Early table checksum verification disabled\n"); - acpi_gbl_verify_table_checksum = FALSE; + acpi_gbl_enable_table_validation = FALSE; } status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0); diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h index a59c44c3edd8..12dac84c98c9 100644 --- a/include/acpi/acpixf.h +++ b/include/acpi/acpixf.h @@ -160,13 +160,14 @@ ACPI_INIT_GLOBAL(u8, acpi_gbl_create_osi_method, TRUE); ACPI_INIT_GLOBAL(u8, acpi_gbl_use_default_register_widths, TRUE); /* - * Whether or not to verify the table checksum before installation. Set - * this to TRUE to verify the table checksum before install it to the table - * manager. Note that enabling this option causes errors to happen in some - * OSPMs during early initialization stages. Default behavior is to do such - * verification. + * Whether or not to validate (map) an entire table to verify + * checksum/duplication in early stage before install. Set this to TRUE to + * allow early table validation before install it to the table manager. + * Note that enabling this option causes errors to happen in some OSPMs + * during early initialization stages. Default behavior is to allow such + * validation. */ -ACPI_INIT_GLOBAL(u8, acpi_gbl_verify_table_checksum, TRUE); +ACPI_INIT_GLOBAL(u8, acpi_gbl_enable_table_validation, TRUE); /* * Optionally enable output from the AML Debug Object. From f9d472ee3214cf8fc3e4b418b376869799adaf67 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 10 Jul 2017 15:23:50 +0800 Subject: [PATCH 11/32] ACPICA: Tables: Combine checksum/duplication verification together ACPICA commit 182bdffc0644f568be614a6d4debd651e29ca587 They are all mechanisms used to verify if a table is qualified to be installed and controlled by acpi_gbl_enable_table_validation, so combine them together. By doing so, table duplication check is applied to the statically loaded tables (however whether it is actually enabled is still determined by acpi_gbl_enable_table_validation). Lv Zheng. Link: https://github.com/acpica/acpica/commit/182bdffc Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/actables.h | 3 +- drivers/acpi/acpica/tbdata.c | 151 ++++++++++++++++++++++++++++++++- drivers/acpi/acpica/tbinstal.c | 125 +++++---------------------- 3 files changed, 169 insertions(+), 110 deletions(-) diff --git a/drivers/acpi/acpica/actables.h b/drivers/acpi/acpica/actables.h index 89ed31b0f739..84a3ceb6e384 100644 --- a/drivers/acpi/acpica/actables.h +++ b/drivers/acpi/acpica/actables.h @@ -76,7 +76,8 @@ void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc); acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc); acpi_status -acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature); +acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, + char *signature, u32 *table_index); u8 acpi_tb_is_table_loaded(u32 table_index); diff --git a/drivers/acpi/acpica/tbdata.c b/drivers/acpi/acpica/tbdata.c index 24d99711b2a4..577361b05ea9 100644 --- a/drivers/acpi/acpica/tbdata.c +++ b/drivers/acpi/acpica/tbdata.c @@ -50,6 +50,57 @@ #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbdata") +/* Local prototypes */ +static acpi_status +acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index); + +static u8 +acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index); + +/******************************************************************************* + * + * FUNCTION: acpi_tb_compare_tables + * + * PARAMETERS: table_desc - Table 1 descriptor to be compared + * table_index - Index of table 2 to be compared + * + * RETURN: TRUE if both tables are identical. + * + * DESCRIPTION: This function compares a table with another table that has + * already been installed in the root table list. + * + ******************************************************************************/ + +static u8 +acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index) +{ + acpi_status status = AE_OK; + u8 is_identical; + struct acpi_table_header *table; + u32 table_length; + u8 table_flags; + + status = + acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index], + &table, &table_length, &table_flags); + if (ACPI_FAILURE(status)) { + return (FALSE); + } + + /* + * Check for a table match on the entire table length, + * not just the header. + */ + is_identical = (u8)((table_desc->length != table_length || + memcmp(table_desc->pointer, table, table_length)) ? + FALSE : TRUE); + + /* Release the acquired table */ + + acpi_tb_release_table(table, table_length, table_flags); + return (is_identical); +} + /******************************************************************************* * * FUNCTION: acpi_tb_init_table_descriptor @@ -64,6 +115,7 @@ ACPI_MODULE_NAME("tbdata") * DESCRIPTION: Initialize a new table descriptor * ******************************************************************************/ + void acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc, acpi_physical_address address, @@ -354,12 +406,78 @@ acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc) return (acpi_tb_validate_table(table_desc)); } +/******************************************************************************* + * + * FUNCTION: acpi_tb_check_duplication + * + * PARAMETERS: table_desc - Table descriptor + * table_index - Where the table index is returned + * + * RETURN: Status + * + * DESCRIPTION: Avoid installing duplicated tables. However table override and + * user aided dynamic table load is allowed, thus comparing the + * address of the table is not sufficient, and checking the entire + * table content is required. + * + ******************************************************************************/ + +static acpi_status +acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index) +{ + u32 i; + + ACPI_FUNCTION_TRACE(tb_check_duplication); + + /* Check if table is already registered */ + + for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { + /* + * Check for a table match on the entire table length, + * not just the header. + */ + if (!acpi_tb_compare_tables(table_desc, i)) { + continue; + } + + /* + * Note: the current mechanism does not unregister a table if it is + * dynamically unloaded. The related namespace entries are deleted, + * but the table remains in the root table list. + * + * The assumption here is that the number of different tables that + * will be loaded is actually small, and there is minimal overhead + * in just keeping the table in case it is needed again. + * + * If this assumption changes in the future (perhaps on large + * machines with many table load/unload operations), tables will + * need to be unregistered when they are unloaded, and slots in the + * root table list should be reused when empty. + */ + if (acpi_gbl_root_table_list.tables[i].flags & + ACPI_TABLE_IS_LOADED) { + + /* Table is still loaded, this is an error */ + + return_ACPI_STATUS(AE_ALREADY_EXISTS); + } else { + *table_index = i; + return_ACPI_STATUS(AE_CTRL_TERMINATE); + } + } + + /* Indicate no duplication to the caller */ + + return_ACPI_STATUS(AE_OK); +} + /****************************************************************************** * * FUNCTION: acpi_tb_verify_temp_table * * PARAMETERS: table_desc - Table descriptor * signature - Table signature to verify + * table_index - Where the table index is returned * * RETURN: Status * @@ -369,7 +487,8 @@ acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc) *****************************************************************************/ acpi_status -acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature) +acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, + char *signature, u32 *table_index) { acpi_status status = AE_OK; @@ -392,9 +511,10 @@ acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature) goto invalidate_and_exit; } - /* Verify the checksum */ - if (acpi_gbl_enable_table_validation) { + + /* Verify the checksum */ + status = acpi_tb_verify_checksum(table_desc->pointer, table_desc->length); @@ -411,9 +531,32 @@ acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature) goto invalidate_and_exit; } + + /* Avoid duplications */ + + if (table_index) { + status = + acpi_tb_check_duplication(table_desc, table_index); + if (ACPI_FAILURE(status)) { + if (status != AE_CTRL_TERMINATE) { + ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, + "%4.4s 0x%8.8X%8.8X" + " Table is duplicated", + acpi_ut_valid_nameseg + (table_desc->signature. + ascii) ? table_desc-> + signature. + ascii : "????", + ACPI_FORMAT_UINT64 + (table_desc->address))); + } + + goto invalidate_and_exit; + } + } } - return_ACPI_STATUS(AE_OK); + return_ACPI_STATUS(status); invalidate_and_exit: acpi_tb_invalidate_table(table_desc); diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c index f7bc362bd3c5..0dfc0ac3c141 100644 --- a/drivers/acpi/acpica/tbinstal.c +++ b/drivers/acpi/acpica/tbinstal.c @@ -48,54 +48,6 @@ #define _COMPONENT ACPI_TABLES ACPI_MODULE_NAME("tbinstal") -/* Local prototypes */ -static u8 -acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index); - -/******************************************************************************* - * - * FUNCTION: acpi_tb_compare_tables - * - * PARAMETERS: table_desc - Table 1 descriptor to be compared - * table_index - Index of table 2 to be compared - * - * RETURN: TRUE if both tables are identical. - * - * DESCRIPTION: This function compares a table with another table that has - * already been installed in the root table list. - * - ******************************************************************************/ - -static u8 -acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index) -{ - acpi_status status = AE_OK; - u8 is_identical; - struct acpi_table_header *table; - u32 table_length; - u8 table_flags; - - status = - acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index], - &table, &table_length, &table_flags); - if (ACPI_FAILURE(status)) { - return (FALSE); - } - - /* - * Check for a table match on the entire table length, - * not just the header. - */ - is_identical = (u8)((table_desc->length != table_length || - memcmp(table_desc->pointer, table, table_length)) ? - FALSE : TRUE); - - /* Release the acquired table */ - - acpi_tb_release_table(table, table_length, table_flags); - return (is_identical); -} - /******************************************************************************* * * FUNCTION: acpi_tb_install_table_with_override @@ -112,7 +64,6 @@ acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index) * table array. * ******************************************************************************/ - void acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc, u8 override, u32 *table_index) @@ -210,67 +161,29 @@ acpi_tb_install_standard_table(acpi_physical_address address, goto release_and_exit; } - /* Validate and verify a table before installation */ - - status = acpi_tb_verify_temp_table(&new_table_desc, NULL); - if (ACPI_FAILURE(status)) { - goto release_and_exit; - } - /* Acquire the table lock */ (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); - if (acpi_gbl_enable_table_validation) { + /* Validate and verify a table before installation */ - /* Check if table is already registered */ - - for (i = 0; i < acpi_gbl_root_table_list.current_table_count; - ++i) { + status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i); + if (ACPI_FAILURE(status)) { + if (status == AE_CTRL_TERMINATE) { /* - * Check for a table match on the entire table length, - * not just the header. + * Table was unloaded, allow it to be reloaded. + * As we are going to return AE_OK to the caller, we should + * take the responsibility of freeing the input descriptor. + * Refill the input descriptor to ensure + * acpi_tb_install_table_with_override() can be called again to + * indicate the re-installation. */ - if (!acpi_tb_compare_tables(&new_table_desc, i)) { - continue; - } - - /* - * Note: the current mechanism does not unregister a table if it is - * dynamically unloaded. The related namespace entries are deleted, - * but the table remains in the root table list. - * - * The assumption here is that the number of different tables that - * will be loaded is actually small, and there is minimal overhead - * in just keeping the table in case it is needed again. - * - * If this assumption changes in the future (perhaps on large - * machines with many table load/unload operations), tables will - * need to be unregistered when they are unloaded, and slots in the - * root table list should be reused when empty. - */ - if (acpi_gbl_root_table_list.tables[i].flags & - ACPI_TABLE_IS_LOADED) { - - /* Table is still loaded, this is an error */ - - status = AE_ALREADY_EXISTS; - goto unlock_and_exit; - } else { - /* - * Table was unloaded, allow it to be reloaded. - * As we are going to return AE_OK to the caller, we should - * take the responsibility of freeing the input descriptor. - * Refill the input descriptor to ensure - * acpi_tb_install_table_with_override() can be called again to - * indicate the re-installation. - */ - acpi_tb_uninstall_table(&new_table_desc); - (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); - *table_index = i; - return_ACPI_STATUS(AE_OK); - } + acpi_tb_uninstall_table(&new_table_desc); + (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); + *table_index = i; + return_ACPI_STATUS(AE_OK); } + goto unlock_and_exit; } /* Add the table to the global root table list */ @@ -350,9 +263,11 @@ void acpi_tb_override_table(struct acpi_table_desc *old_table_desc) finish_override: - /* Validate and verify a table before overriding */ - - status = acpi_tb_verify_temp_table(&new_table_desc, NULL); + /* + * Validate and verify a table before overriding, no nested table + * duplication check as it's too complicated and unnecessary. + */ + status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL); if (ACPI_FAILURE(status)) { return; } From 19df56bdf0833a8ad9dfe056931696b9e0e30463 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 10 Jul 2017 15:23:56 +0800 Subject: [PATCH 12/32] ACPICA: Tables: Add deferred table verification support ACPICA commit 2dd6c151d5d5e76dacba8f7db9e259fc72982d17 ACPICA commit ffddee6638aced83be18b8bc88569586c1a43e03 This patch allows tables not verified in early stage verfied in acpi_reallocate_root_table(). This is useful for OSPMs like linux where tables cannot be verified in early stage due to early ioremp limitations on some architectures. Reported by Hans de Geode, fixed by Lv Zheng. Link: https://github.com/acpica/acpica/commit/2dd6c151 Link: https://github.com/acpica/acpica/commit/ffddee66 Reported-by: Hans de Goede Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/tbdata.c | 34 ++++++++++++++++++++++++++++------ drivers/acpi/acpica/tbxface.c | 27 ++++++++++++++++++++++----- include/acpi/actbl.h | 1 + 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/acpica/tbdata.c b/drivers/acpi/acpica/tbdata.c index 577361b05ea9..b19a2f0ea331 100644 --- a/drivers/acpi/acpica/tbdata.c +++ b/drivers/acpi/acpica/tbdata.c @@ -432,6 +432,15 @@ acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index) /* Check if table is already registered */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { + + /* Do not compare with unverified tables */ + + if (! + (acpi_gbl_root_table_list.tables[i]. + flags & ACPI_TABLE_IS_VERIFIED)) { + continue; + } + /* * Check for a table match on the entire table length, * not just the header. @@ -483,6 +492,8 @@ acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index) * * DESCRIPTION: This function is called to validate and verify the table, the * returned table descriptor is in "VALIDATED" state. + * Note that 'TableIndex' is required to be set to !NULL to + * enable duplication check. * *****************************************************************************/ @@ -554,6 +565,8 @@ acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, goto invalidate_and_exit; } } + + table_desc->flags |= ACPI_TABLE_IS_VERIFIED; } return_ACPI_STATUS(status); @@ -579,6 +592,8 @@ acpi_status acpi_tb_resize_root_table_list(void) { struct acpi_table_desc *tables; u32 table_count; + u32 current_table_count, max_table_count; + u32 i; ACPI_FUNCTION_TRACE(tb_resize_root_table_list); @@ -598,8 +613,8 @@ acpi_status acpi_tb_resize_root_table_list(void) table_count = acpi_gbl_root_table_list.current_table_count; } - tables = ACPI_ALLOCATE_ZEROED(((acpi_size)table_count + - ACPI_ROOT_TABLE_SIZE_INCREMENT) * + max_table_count = table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT; + tables = ACPI_ALLOCATE_ZEROED(((acpi_size)max_table_count) * sizeof(struct acpi_table_desc)); if (!tables) { ACPI_ERROR((AE_INFO, @@ -609,9 +624,16 @@ acpi_status acpi_tb_resize_root_table_list(void) /* Copy and free the previous table array */ + current_table_count = 0; if (acpi_gbl_root_table_list.tables) { - memcpy(tables, acpi_gbl_root_table_list.tables, - (acpi_size)table_count * sizeof(struct acpi_table_desc)); + for (i = 0; i < table_count; i++) { + if (acpi_gbl_root_table_list.tables[i].address) { + memcpy(tables + current_table_count, + acpi_gbl_root_table_list.tables + i, + sizeof(struct acpi_table_desc)); + current_table_count++; + } + } if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { ACPI_FREE(acpi_gbl_root_table_list.tables); @@ -619,8 +641,8 @@ acpi_status acpi_tb_resize_root_table_list(void) } acpi_gbl_root_table_list.tables = tables; - acpi_gbl_root_table_list.max_table_count = - table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT; + acpi_gbl_root_table_list.max_table_count = max_table_count; + acpi_gbl_root_table_list.current_table_count = current_table_count; acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED; return_ACPI_STATUS(AE_OK); diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c index 38c01049afd5..26ad596c973e 100644 --- a/drivers/acpi/acpica/tbxface.c +++ b/drivers/acpi/acpica/tbxface.c @@ -167,7 +167,8 @@ ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_tables) acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void) { acpi_status status; - u32 i; + struct acpi_table_desc *table_desc; + u32 i, j; ACPI_FUNCTION_TRACE(acpi_reallocate_root_table); @@ -179,6 +180,8 @@ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void) return_ACPI_STATUS(AE_SUPPORT); } + (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); + /* * Ensure OS early boot logic, which is required by some hosts. If the * table state is reported to be wrong, developers should fix the @@ -186,11 +189,11 @@ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void) * early stage. */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { - if (acpi_gbl_root_table_list.tables[i].pointer) { + table_desc = &acpi_gbl_root_table_list.tables[i]; + if (table_desc->pointer) { ACPI_ERROR((AE_INFO, "Table [%4.4s] is not invalidated during early boot stage", - acpi_gbl_root_table_list.tables[i]. - signature.ascii)); + table_desc->signature.ascii)); } } @@ -200,11 +203,25 @@ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void) * table initilization here once the flag is set. */ acpi_gbl_enable_table_validation = TRUE; + for (i = 0; i < acpi_gbl_root_table_list.current_table_count; + ++i) { + table_desc = &acpi_gbl_root_table_list.tables[i]; + if (!(table_desc->flags & ACPI_TABLE_IS_VERIFIED)) { + status = + acpi_tb_verify_temp_table(table_desc, NULL, + &j); + if (ACPI_FAILURE(status)) { + acpi_tb_uninstall_table(table_desc); + } + } + } } acpi_gbl_root_table_list.flags |= ACPI_ROOT_ALLOW_RESIZE; - status = acpi_tb_resize_root_table_list(); + acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED; + + (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); return_ACPI_STATUS(status); } diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h index bdc55c0da19c..89509b86cb54 100644 --- a/include/acpi/actbl.h +++ b/include/acpi/actbl.h @@ -394,6 +394,7 @@ struct acpi_table_desc { #define ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL (1) /* Physical address, internally mapped */ #define ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL (2) /* Virtual address, internallly allocated */ #define ACPI_TABLE_ORIGIN_MASK (3) +#define ACPI_TABLE_IS_VERIFIED (4) #define ACPI_TABLE_IS_LOADED (8) /* From 4e6cbe5689a5af8435bebc57b77d7dd4420b4134 Mon Sep 17 00:00:00 2001 From: Alex James Date: Mon, 10 Jul 2017 15:24:02 +0800 Subject: [PATCH 13/32] ACPICA: iASL: Ensure that the target node is valid in acpi_ex_create_alias ACPICA commit 8b14afac65d983610cc5387ede6d85ea5ee075be The following ACPI table contains an invalid target node within the Alias operator: definition_block ("", "SSDT", 1, "Bug", "BugTable", 0x00001000) { Scope (_SB) { Device (DEV0) { Name (_ADR, 1) Device (DEV1) { Alias (_ADR, _ADR) } } } } If an ACPI table contains such an invalid target node in an Alias operator, a segmentation fault will occur when the target node is dereferenced within acpi_ex_create_alias. Add a check for such an invalid target node in acpi_ex_create_alias and return AE_NULL_OBJECT as suggested by @acpibob. Link: https://github.com/acpica/acpica/commit/8b14afac Signed-off-by: Alex James Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/excreate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/acpi/acpica/excreate.c b/drivers/acpi/acpica/excreate.c index d43d7da4c734..68675868e20f 100644 --- a/drivers/acpi/acpica/excreate.c +++ b/drivers/acpi/acpica/excreate.c @@ -87,6 +87,11 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state) target_node->object); } + /* Ensure that the target node is valid */ + if (!target_node) { + return_ACPI_STATUS(AE_NULL_OBJECT); + } + /* * For objects that can never change (i.e., the NS node will * permanently point to the same object), we can simply attach From 3f20ea15f07546a20ec2caca98c65dc5f441431a Mon Sep 17 00:00:00 2001 From: Erik Schmauss Date: Mon, 10 Jul 2017 15:24:09 +0800 Subject: [PATCH 14/32] ACPICA: Disassembler: skip parsing of incorrect external declarations ACPICA commit ed25461901d34120067b07ec280af30abc0458f1 Link: https://github.com/acpica/acpica/commit/ed254619 Signed-off-by: Erik Schmauss Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/psobject.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/acpi/acpica/psobject.c b/drivers/acpi/acpica/psobject.c index ef6384e374fc..0bef6df71bba 100644 --- a/drivers/acpi/acpica/psobject.c +++ b/drivers/acpi/acpica/psobject.c @@ -359,6 +359,32 @@ acpi_ps_create_op(struct acpi_walk_state *walk_state, acpi_ps_build_named_op(walk_state, aml_op_start, op, &named_op); acpi_ps_free_op(op); + +#ifdef ACPI_ASL_COMPILER + if (acpi_gbl_disasm_flag + && walk_state->opcode == AML_EXTERNAL_OP + && status == AE_NOT_FOUND) { + /* + * If parsing of AML_EXTERNAL_OP's name path fails, then skip + * past this opcode and keep parsing. This is a much better + * alternative than to abort the entire disassembler. At this + * point, the parser_state is at the end of the namepath of the + * external declaration opcode. Setting walk_state->Aml to + * walk_state->parser_state.Aml + 2 moves increments the + * walk_state->Aml past the object type and the paramcount of the + * external opcode. For the error message, only print the AML + * offset. We could attempt to print the name but this may cause + * a segmentation fault when printing the namepath because the + * AML may be incorrect. + */ + acpi_os_printf + ("// Invalid external declaration at AML offset 0x%x.\n", + walk_state->aml - + walk_state->parser_state.aml_start); + walk_state->aml = walk_state->parser_state.aml + 2; + return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); + } +#endif if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } From c944230064eb65e4fa018d86779b4fd200b1d7e7 Mon Sep 17 00:00:00 2001 From: Ganapatrao Kulkarni Date: Mon, 10 Jul 2017 15:24:15 +0800 Subject: [PATCH 15/32] ACPICA: iasl: Update to IORT SMMUv3 disassembling ACPICA commit 8cadc4fb500e2aa52241e367c87a0f95d9760c58 ARM IORT specification has provision to define Proximity domain in SMMUv3 IORT table. Adding required changes to decode Proximity domain of SMMUv3 IORT table. Link: https://github.com/acpica/acpica/commit/8cadc4fb Signed-off-by: Ganapatrao Kulkarni Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- include/acpi/actbl2.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 5829eedbf3ff..d568948d3a82 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -806,6 +806,9 @@ struct acpi_iort_smmu_v3 { u32 pri_gsiv; u32 gerr_gsiv; u32 sync_gsiv; + u8 pxm; + u8 reserved1; + u16 reserved2; }; /* Values for Model field above */ @@ -818,6 +821,7 @@ struct acpi_iort_smmu_v3 { #define ACPI_IORT_SMMU_V3_COHACC_OVERRIDE (1) #define ACPI_IORT_SMMU_V3_HTTU_OVERRIDE (1<<1) +#define ACPI_IORT_SMMU_V3_PXM_VALID (1<<3) /******************************************************************************* * From 852d4f9c71bc1582199200310c8951b79e451d6a Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Mon, 5 Jun 2017 16:40:50 +0800 Subject: [PATCH 16/32] ACPICA: Update resource descriptor handling ACPICA commit c8eac10178b387f9eb1935694e509d4518da77bb This change restores the change introduced by commit 23b5bbe and adds a comment concerning resource descriptor buffers that extend beyond the END_TAG descriptor. Link: https://github.com/acpica/acpica/commit/c8eac101 Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/utresrc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/acpica/utresrc.c b/drivers/acpi/acpica/utresrc.c index 70f78a4bf13b..d955bf852a03 100644 --- a/drivers/acpi/acpica/utresrc.c +++ b/drivers/acpi/acpica/utresrc.c @@ -184,9 +184,11 @@ acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state, ACPI_FUNCTION_TRACE(ut_walk_aml_resources); - /* The absolute minimum resource template is one end_tag descriptor */ - - if (aml_length < sizeof(struct aml_resource_end_tag)) { + /* + * The absolute minimum resource template is one end_tag descriptor. + * However, we will treat a lone end_tag as just a simple buffer. + */ + if (aml_length <= sizeof(struct aml_resource_end_tag)) { return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } @@ -243,8 +245,10 @@ acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state, *context = aml; } - /* Normal exit */ - + /* + * Normal exit. Note: We allow the buffer to be larger than + * the resource template, as long as the END_TAG exists. + */ return_ACPI_STATUS(AE_OK); } From ab539eaa50c6a97f1d6287c5ce3ee75155cb10b8 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Mon, 10 Jul 2017 15:24:27 +0800 Subject: [PATCH 17/32] ACPICA: Update version to 20170629 ACPICA commit 7271c1c54c095c06ed9e7d28641f2356da840038 Version 20170629 Link: https://github.com/acpica/acpica/commit/7271c1c5 Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- include/acpi/acpixf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h index 12dac84c98c9..06b87adc97ef 100644 --- a/include/acpi/acpixf.h +++ b/include/acpi/acpixf.h @@ -46,7 +46,7 @@ /* Current ACPICA subsystem version in YYYYMMDD format */ -#define ACPI_CA_VERSION 0x20170531 +#define ACPI_CA_VERSION 0x20170629 #include #include From 4eebedd8f1a6609739c2e9a9b020791b23cbcceb Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 3 Aug 2017 14:26:19 +0800 Subject: [PATCH 18/32] ACPICA: Divergences: reduce access size definitions ACPICA commit cf27b3c98883d2a15d932016792fcb8272ace96d The following commit introduces definition of access width to ACPICA. Commit: 2bece49394872d36bbc5767fd643deac05920c55 Subject: ACPI: SPCR: Use access width to determine mmio usage Actually the access bit width can be calculated via access width. It would be better to define a macro calculating bit width rather than defining fixed values. This patch thus cleans up the definitions to reduce divergences. Link: https://github.com/acpica/acpica/commit/cf27b3c9 Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/hwregs.c | 2 +- drivers/acpi/spcr.c | 9 +++++---- include/acpi/acrestyp.h | 7 ------- include/acpi/actypes.h | 7 +++++++ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c index de74a4c25085..acb417b58bbb 100644 --- a/drivers/acpi/acpica/hwregs.c +++ b/drivers/acpi/acpica/hwregs.c @@ -107,7 +107,7 @@ acpi_hw_get_access_bit_width(u64 address, ACPI_IS_ALIGNED(reg->bit_width, 8)) { access_bit_width = reg->bit_width; } else if (reg->access_width) { - access_bit_width = (1 << (reg->access_width + 2)); + access_bit_width = ACPI_ACCESS_BIT_WIDTH(reg->access_width); } else { access_bit_width = ACPI_ROUND_UP_POWER_OF_TWO_8(reg->bit_offset + diff --git a/drivers/acpi/spcr.c b/drivers/acpi/spcr.c index 4ac3e06b41d8..1230f969256b 100644 --- a/drivers/acpi/spcr.c +++ b/drivers/acpi/spcr.c @@ -95,16 +95,17 @@ int __init parse_spcr(bool earlycon) } if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { - switch (table->serial_port.access_width) { + switch (ACPI_ACCESS_BIT_WIDTH(( + table->serial_port.access_width))) { default: pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n"); - case ACPI_ACCESS_SIZE_BYTE: + case 8: iotype = "mmio"; break; - case ACPI_ACCESS_SIZE_WORD: + case 16: iotype = "mmio16"; break; - case ACPI_ACCESS_SIZE_DWORD: + case 32: iotype = "mmio32"; break; } diff --git a/include/acpi/acrestyp.h b/include/acpi/acrestyp.h index 4f7f39a02820..343dbdcef20c 100644 --- a/include/acpi/acrestyp.h +++ b/include/acpi/acrestyp.h @@ -377,13 +377,6 @@ struct acpi_resource_generic_register { u64 address; }; -/* Generic Address Space Access Sizes */ -#define ACPI_ACCESS_SIZE_UNDEFINED 0 -#define ACPI_ACCESS_SIZE_BYTE 1 -#define ACPI_ACCESS_SIZE_WORD 2 -#define ACPI_ACCESS_SIZE_DWORD 3 -#define ACPI_ACCESS_SIZE_QWORD 4 - struct acpi_resource_gpio { u8 revision_id; u8 connection_type; diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h index 2fcbaec8b368..0260be595d40 100644 --- a/include/acpi/actypes.h +++ b/include/acpi/actypes.h @@ -554,6 +554,13 @@ typedef u64 acpi_integer; #define ACPI_VALIDATE_RSDP_SIG(a) (!strncmp (ACPI_CAST_PTR (char, (a)), ACPI_SIG_RSDP, 8)) #define ACPI_MAKE_RSDP_SIG(dest) (memcpy (ACPI_CAST_PTR (char, (dest)), ACPI_SIG_RSDP, 8)) +/* + * Algorithm to obtain access bit width. + * Can be used with access_width of struct acpi_generic_address and access_size of + * struct acpi_resource_generic_register. + */ +#define ACPI_ACCESS_BIT_WIDTH(size) (1 << ((size) + 2)) + /******************************************************************************* * * Miscellaneous constants From 3bd38469df0a0f4b3c73e490538c8de104914a4a Mon Sep 17 00:00:00 2001 From: James Morse Date: Thu, 3 Aug 2017 14:26:25 +0800 Subject: [PATCH 19/32] ACPICA: iASL: Add support for the SDEI table ACPICA commit 5ad4f0b7bf9e7ba175bd320cf7950f3b38799ff3 ACPI 6.2 adds support for the Software Delegated Exception Interface, which is described by "Software Delegated Exception Interface (SDEI)" ARM DEN0054A. Add the necessary types in the ACPICA header files and support for compiling/decompiling the table. Link: https://github.com/acpica/acpica/commit/5ad4f0b7 Signed-off-by: James Morse Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- include/acpi/actbl2.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index d568948d3a82..686b6f8c09dc 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -76,6 +76,7 @@ #define ACPI_SIG_MCHI "MCHI" /* Management Controller Host Interface table */ #define ACPI_SIG_MSDM "MSDM" /* Microsoft Data Management Table */ #define ACPI_SIG_MTMR "MTMR" /* MID Timer table */ +#define ACPI_SIG_SDEI "SDEI" /* Software Delegated Exception Interface Table */ #define ACPI_SIG_SLIC "SLIC" /* Software Licensing Description Table */ #define ACPI_SIG_SPCR "SPCR" /* Serial Port Console Redirection table */ #define ACPI_SIG_SPMI "SPMI" /* Server Platform Management Interface table */ @@ -1132,6 +1133,19 @@ struct acpi_mtmr_entry { u32 irq; }; +/******************************************************************************* + * + * SDEI - Software Delegated Exception Interface Descriptor Table + * + * Conforms to "Software Delegated Exception Interface (SDEI)" ARM DEN0054A, + * May 8th, 2017. Copyright 2017 ARM Ltd. + * + ******************************************************************************/ + +struct acpi_table_sdei { + struct acpi_table_header header; /* Common ACPI table header */ +}; + /******************************************************************************* * * SLIC - Software Licensing Description Table From 6d9229d67df35f9b7f922d6bdb4d6505eb0b900f Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:26:31 +0800 Subject: [PATCH 20/32] ACPICA: Namespace: Update/fix an error message ACPICA commit 8b7fa979ef81469e70f501f582466a265d6f595b Was emitting an internal namestring without converting it to the external format. Link: https://github.com/acpica/acpica/commit/8b7fa979 Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/nsaccess.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c index 14be12fe9f35..f2733f51ca8d 100644 --- a/drivers/acpi/acpica/nsaccess.c +++ b/drivers/acpi/acpica/nsaccess.c @@ -292,6 +292,7 @@ acpi_ns_lookup(union acpi_generic_state *scope_info, { acpi_status status; char *path = pathname; + char *external_path; struct acpi_namespace_node *prefix_node; struct acpi_namespace_node *current_node = NULL; struct acpi_namespace_node *this_node = NULL; @@ -427,13 +428,22 @@ acpi_ns_lookup(union acpi_generic_state *scope_info, num_carats++; this_node = this_node->parent; if (!this_node) { + /* + * Current scope has no parent scope. Externalize + * the internal path for error message. + */ + status = + acpi_ns_externalize_name + (ACPI_UINT32_MAX, pathname, NULL, + &external_path); + if (ACPI_SUCCESS(status)) { + ACPI_ERROR((AE_INFO, + "%s: Path has too many parent prefixes (^)", + external_path)); - /* Current scope has no parent scope */ + ACPI_FREE(external_path); + } - ACPI_ERROR((AE_INFO, - "%s: Path has too many parent prefixes (^) " - "- reached beyond root node", - pathname)); return_ACPI_STATUS(AE_NOT_FOUND); } } From 583abc9bd585ff0d5fb7411e5601053b21fdd9d9 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:26:38 +0800 Subject: [PATCH 21/32] ACPICA: Add a comment, no functional change ACPICA commit d586c29a026a6172c1113df4d75fd6d764196e77 Describe 2nd byte of the end_tag resource descriptor. Link: https://github.com/acpica/acpica/commit/d586c29a Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/utresrc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/acpi/acpica/utresrc.c b/drivers/acpi/acpica/utresrc.c index d955bf852a03..517acf8e77c8 100644 --- a/drivers/acpi/acpica/utresrc.c +++ b/drivers/acpi/acpica/utresrc.c @@ -239,6 +239,13 @@ acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state, return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } + /* + * Don't attempt to perform any validation on the 2nd byte. + * Although all known ASL compilers insert a zero for the 2nd + * byte, it can also be a checksum (as per the ACPI spec), + * and this is occasionally seen in the field. July 2017. + */ + /* Return the pointer to the end_tag if requested */ if (!user_function) { From d5f23fe192b5b549a85e98ee9f0a3b8a0f9c04c3 Mon Sep 17 00:00:00 2001 From: Shao Ming Date: Thu, 3 Aug 2017 14:26:44 +0800 Subject: [PATCH 22/32] ACPICA: EFI/EDK2: Sort acpi.h inclusion order ACPICA commit 43ff22215f0fcd8ca80abec5712a07d2cc9a801d acpi.h inclusion order need to be changed to build EDK-II ports of acpidump on Windows as va_list is used before it's definition in that environment. As we only need to ensure order of acenv.h/acenvex.h to be pre/post ACPICA type definitions, inclusion order is changed to make MSVC builds happy. Lv Zheng. Link: https://github.com/acpica/acpica/commit/43ff2221 Signed-off-by: "Shao, Ming" Signed-off-by: Lv Zheng Signed-off-by: Shao Ming Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- include/acpi/acpi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/acpi/acpi.h b/include/acpi/acpi.h index ca036620703c..0887d7cbb7e1 100644 --- a/include/acpi/acpi.h +++ b/include/acpi/acpi.h @@ -58,10 +58,10 @@ #include /* ACPICA data types and structures */ #include /* ACPICA exceptions */ #include /* ACPI table definitions */ -#include /* Error output and Debug macros */ #include /* Resource Descriptor structs */ +#include /* Extra environment-specific items */ +#include /* Error output and Debug macros */ #include /* OSL interfaces (ACPICA-to-OS) */ #include /* ACPI core subsystem external interfaces */ -#include /* Extra environment-specific items */ #endif /* __ACPI_H__ */ From 65082bfcb486ef06f93b7603a9045cdf0c0022e8 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 3 Aug 2017 14:26:50 +0800 Subject: [PATCH 23/32] ACPICA: CLib: Add short multiply/shift support ACPICA commit 01b8f5a2350b9cc329cd8402ac8faec36fc501f5 In order to build ACPICA EFI tools with EDK-II on Windows, 64-bit multiply/shift supports are also required to be implemented. Otherwise, MSVC complains: acpidump.lib(utstrtoul64.obj) : error LNK2001: unresolved external symbol __allmul acpidump.lib(uthex.obj) : error LNK2001: unresolved external symbol __aullshr Note: 1. This patch also splits _EDK2_EFI from _GNU_EFI as they might have different math64 supports. 2. Support of gcc math64 is not included in this patch. 3. Support of EDK2 arch independent math64 is done via linking to base_lib. This patch fixes this issue. Reported by Shao Ming, fixed by Lv Zheng. For Linux kernel, this patch is a functional no-op. Link: https://github.com/acpica/acpica/commit/01b8f5a2 Tested-by: "Shao, Ming" Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/acutils.h | 7 + drivers/acpi/acpica/uthex.c | 4 +- drivers/acpi/acpica/utmath.c | 222 +++++++++++++++++++++- drivers/acpi/acpica/utprint.c | 2 +- drivers/acpi/acpica/utstrtoul64.c | 9 +- include/acpi/actypes.h | 1 + include/acpi/platform/acgcc.h | 4 + include/acpi/platform/aclinux.h | 2 + tools/power/acpi/tools/acpidump/apfiles.c | 2 +- tools/power/acpi/tools/acpidump/apmain.c | 2 +- 10 files changed, 237 insertions(+), 18 deletions(-) diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h index 2a3cc4296481..0a5601405584 100644 --- a/drivers/acpi/acpica/acutils.h +++ b/drivers/acpi/acpica/acutils.h @@ -538,6 +538,13 @@ acpi_status acpi_ut_short_divide(u64 in_dividend, u32 divisor, u64 *out_quotient, u32 *out_remainder); +acpi_status +acpi_ut_short_multiply(u64 in_multiplicand, u32 multiplier, u64 *outproduct); + +acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result); + +acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result); + /* * utmisc */ diff --git a/drivers/acpi/acpica/uthex.c b/drivers/acpi/acpica/uthex.c index 6600bc257516..fb406daf47fa 100644 --- a/drivers/acpi/acpica/uthex.c +++ b/drivers/acpi/acpica/uthex.c @@ -69,8 +69,10 @@ static const char acpi_gbl_hex_to_ascii[] = { char acpi_ut_hex_to_ascii_char(u64 integer, u32 position) { + u64 index; - return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]); + acpi_ut_short_shift_right(integer, position, &index); + return (acpi_gbl_hex_to_ascii[index & 0xF]); } /******************************************************************************* diff --git a/drivers/acpi/acpica/utmath.c b/drivers/acpi/acpica/utmath.c index aa0502d1d019..5f9c680076c4 100644 --- a/drivers/acpi/acpica/utmath.c +++ b/drivers/acpi/acpica/utmath.c @@ -47,15 +47,6 @@ #define _COMPONENT ACPI_UTILITIES ACPI_MODULE_NAME("utmath") -/* - * Optional support for 64-bit double-precision integer divide. This code - * is configurable and is implemented in order to support 32-bit kernel - * environments where a 64-bit double-precision math library is not available. - * - * Support for a more normal 64-bit divide/modulo (with check for a divide- - * by-zero) appears after this optional section of code. - */ -#ifndef ACPI_USE_NATIVE_DIVIDE /* Structures used only for 64-bit divide */ typedef struct uint64_struct { u32 lo; @@ -69,6 +60,217 @@ typedef union uint64_overlay { } uint64_overlay; +/* + * Optional support for 64-bit double-precision integer multiply and shift. + * This code is configurable and is implemented in order to support 32-bit + * kernel environments where a 64-bit double-precision math library is not + * available. + */ +#ifndef ACPI_USE_NATIVE_MATH64 + +/******************************************************************************* + * + * FUNCTION: acpi_ut_short_multiply + * + * PARAMETERS: multiplicand - 64-bit multiplicand + * multiplier - 32-bit multiplier + * out_product - Pointer to where the product is returned + * + * DESCRIPTION: Perform a short multiply. + * + ******************************************************************************/ + +acpi_status +acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product) +{ + union uint64_overlay multiplicand_ovl; + union uint64_overlay product; + u32 carry32; + + ACPI_FUNCTION_TRACE(ut_short_multiply); + + multiplicand_ovl.full = multiplicand; + + /* + * The Product is 64 bits, the carry is always 32 bits, + * and is generated by the second multiply. + */ + ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.hi, multiplier, + product.part.hi, carry32); + + ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.lo, multiplier, + product.part.lo, carry32); + + product.part.hi += carry32; + + /* Return only what was requested */ + + if (out_product) { + *out_product = product.full; + } + + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_short_shift_left + * + * PARAMETERS: operand - 64-bit shift operand + * count - 32-bit shift count + * out_result - Pointer to where the result is returned + * + * DESCRIPTION: Perform a short left shift. + * + ******************************************************************************/ + +acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result) +{ + union uint64_overlay operand_ovl; + + ACPI_FUNCTION_TRACE(ut_short_shift_left); + + operand_ovl.full = operand; + + if ((count & 63) >= 32) { + operand_ovl.part.hi = operand_ovl.part.lo; + operand_ovl.part.lo ^= operand_ovl.part.lo; + count = (count & 63) - 32; + } + ACPI_SHIFT_LEFT_64_BY_32(operand_ovl.part.hi, + operand_ovl.part.lo, count); + + /* Return only what was requested */ + + if (out_result) { + *out_result = operand_ovl.full; + } + + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_short_shift_right + * + * PARAMETERS: operand - 64-bit shift operand + * count - 32-bit shift count + * out_result - Pointer to where the result is returned + * + * DESCRIPTION: Perform a short right shift. + * + ******************************************************************************/ + +acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result) +{ + union uint64_overlay operand_ovl; + + ACPI_FUNCTION_TRACE(ut_short_shift_right); + + operand_ovl.full = operand; + + if ((count & 63) >= 32) { + operand_ovl.part.lo = operand_ovl.part.hi; + operand_ovl.part.hi ^= operand_ovl.part.hi; + count = (count & 63) - 32; + } + ACPI_SHIFT_RIGHT_64_BY_32(operand_ovl.part.hi, + operand_ovl.part.lo, count); + + /* Return only what was requested */ + + if (out_result) { + *out_result = operand_ovl.full; + } + + return_ACPI_STATUS(AE_OK); +} +#else + +/******************************************************************************* + * + * FUNCTION: acpi_ut_short_multiply + * + * PARAMETERS: See function headers above + * + * DESCRIPTION: Native version of the ut_short_multiply function. + * + ******************************************************************************/ + +acpi_status +acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product) +{ + + ACPI_FUNCTION_TRACE(ut_short_multiply); + + /* Return only what was requested */ + + if (out_product) { + *out_product = multiplicand * multiplier; + } + + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_short_shift_left + * + * PARAMETERS: See function headers above + * + * DESCRIPTION: Native version of the ut_short_shift_left function. + * + ******************************************************************************/ + +acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result) +{ + + ACPI_FUNCTION_TRACE(ut_short_shift_left); + + /* Return only what was requested */ + + if (out_result) { + *out_result = operand << count; + } + + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_short_shift_right + * + * PARAMETERS: See function headers above + * + * DESCRIPTION: Native version of the ut_short_shift_right function. + * + ******************************************************************************/ + +acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result) +{ + + ACPI_FUNCTION_TRACE(ut_short_shift_right); + + /* Return only what was requested */ + + if (out_result) { + *out_result = operand >> count; + } + + return_ACPI_STATUS(AE_OK); +} +#endif + +/* + * Optional support for 64-bit double-precision integer divide. This code + * is configurable and is implemented in order to support 32-bit kernel + * environments where a 64-bit double-precision math library is not available. + * + * Support for a more normal 64-bit divide/modulo (with check for a divide- + * by-zero) appears after this optional section of code. + */ +#ifndef ACPI_USE_NATIVE_DIVIDE + /******************************************************************************* * * FUNCTION: acpi_ut_short_divide @@ -258,6 +460,7 @@ acpi_ut_divide(u64 in_dividend, } #else + /******************************************************************************* * * FUNCTION: acpi_ut_short_divide, acpi_ut_divide @@ -272,6 +475,7 @@ acpi_ut_divide(u64 in_dividend, * perform the divide. * ******************************************************************************/ + acpi_status acpi_ut_short_divide(u64 in_dividend, u32 divisor, u64 *out_quotient, u32 *out_remainder) diff --git a/drivers/acpi/acpica/utprint.c b/drivers/acpi/acpica/utprint.c index 7e6e1ae6140f..23cb472e5dc8 100644 --- a/drivers/acpi/acpica/utprint.c +++ b/drivers/acpi/acpica/utprint.c @@ -176,7 +176,7 @@ const char *acpi_ut_scan_number(const char *string, u64 *number_ptr) u64 number = 0; while (isdigit((int)*string)) { - number *= 10; + acpi_ut_short_multiply(number, 10, &number); number += *(string++) - '0'; } diff --git a/drivers/acpi/acpica/utstrtoul64.c b/drivers/acpi/acpica/utstrtoul64.c index f42be01d99fd..9633ee142855 100644 --- a/drivers/acpi/acpica/utstrtoul64.c +++ b/drivers/acpi/acpica/utstrtoul64.c @@ -276,8 +276,8 @@ static u64 acpi_ut_strtoul_base10(char *string, u32 flags) /* Convert and insert (add) the decimal digit */ - next_value = - (return_value * 10) + (ascii_digit - ACPI_ASCII_ZERO); + acpi_ut_short_multiply(return_value, 10, &next_value); + next_value += (ascii_digit - ACPI_ASCII_ZERO); /* Check for overflow (32 or 64 bit) - return current converted value */ @@ -335,9 +335,8 @@ static u64 acpi_ut_strtoul_base16(char *string, u32 flags) /* Convert and insert the hex digit */ - return_value = - (return_value << 4) | - acpi_ut_ascii_char_to_hex(ascii_digit); + acpi_ut_short_shift_left(return_value, 4, &return_value); + return_value |= acpi_ut_ascii_char_to_hex(ascii_digit); string++; valid_digits++; diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h index 0260be595d40..dc3bb153420a 100644 --- a/include/acpi/actypes.h +++ b/include/acpi/actypes.h @@ -166,6 +166,7 @@ typedef u64 acpi_physical_address; #define ACPI_SIZE_MAX ACPI_UINT64_MAX #define ACPI_USE_NATIVE_DIVIDE /* Has native 64-bit integer support */ +#define ACPI_USE_NATIVE_MATH64 /* Has native 64-bit integer support */ /* * In the case of the Itanium Processor Family (IPF), the hardware does not diff --git a/include/acpi/platform/acgcc.h b/include/acpi/platform/acgcc.h index 97a7e21cfbe0..9c8f8b79644e 100644 --- a/include/acpi/platform/acgcc.h +++ b/include/acpi/platform/acgcc.h @@ -84,4 +84,8 @@ typedef __builtin_va_list va_list; #define COMPILER_VA_MACRO 1 +/* GCC supports native multiply/shift on 32-bit platforms */ + +#define ACPI_USE_NATIVE_MATH64 + #endif /* __ACGCC_H__ */ diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h index afd95f28c8f0..1b473efd9eb6 100644 --- a/include/acpi/platform/aclinux.h +++ b/include/acpi/platform/aclinux.h @@ -128,6 +128,7 @@ /* Host-dependent types and defines for in-kernel ACPICA */ #define ACPI_MACHINE_WIDTH BITS_PER_LONG +#define ACPI_USE_NATIVE_MATH64 #define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol); #define strtoul simple_strtoul @@ -216,6 +217,7 @@ #define COMPILER_DEPENDENT_INT64 long long #define COMPILER_DEPENDENT_UINT64 unsigned long long #define ACPI_USE_NATIVE_DIVIDE +#define ACPI_USE_NATIVE_MATH64 #endif #ifndef __cdecl diff --git a/tools/power/acpi/tools/acpidump/apfiles.c b/tools/power/acpi/tools/acpidump/apfiles.c index 31b5a7f74015..d686e11936c4 100644 --- a/tools/power/acpi/tools/acpidump/apfiles.c +++ b/tools/power/acpi/tools/acpidump/apfiles.c @@ -61,7 +61,7 @@ static int ap_is_existing_file(char *pathname); static int ap_is_existing_file(char *pathname) { -#ifndef _GNU_EFI +#if !defined(_GNU_EFI) && !defined(_EDK2_EFI) struct stat stat_info; if (!stat(pathname, &stat_info)) { diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c index dd82afa897bd..943b6b614683 100644 --- a/tools/power/acpi/tools/acpidump/apmain.c +++ b/tools/power/acpi/tools/acpidump/apmain.c @@ -300,7 +300,7 @@ static int ap_do_options(int argc, char **argv) * ******************************************************************************/ -#ifndef _GNU_EFI +#if !defined(_GNU_EFI) && !defined(_EDK2_EFI) int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) #else int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[]) From 03c5b6b0da3f8ce8a4ba463daeb26b151d36f10e Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 3 Aug 2017 14:26:56 +0800 Subject: [PATCH 24/32] ACPICA: acpidump: Add DSDT/FACS instance support for Linux and EFI ACPICA commit 343fc31840d40c06001f3b170ee5bcdfd3c7f3e0 ACPI spec allows to configure different 32-bit/64-bit table addresses for DSDT and FACS. And for FACS, it's meaningful to dump both of them as they are used to support different suspend protocols. While: 1. on Linux, only 1 instance is supported for DSDT/FACS; and 2. on EFI, the code in osl_get_table() is buggy with special table instances, causing endless file dump for such tables (reported by Shao Ming in link #2). This patch adds DSDT/FACS instance support for Linux/EFI acpidump. Fixed by Lv Zheng. Link: https://github.com/acpica/acpica/commit/343fc318 Link: https://bugs.acpica.org/show_bug.cgi?id=1407 [#1] Link: https://github.com/acpica/acpica/issues/285 [#2] Reported-by: Shao Ming Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- .../os_specific/service_layers/oslinuxtbl.c | 105 ++++++++++++------ 1 file changed, 73 insertions(+), 32 deletions(-) diff --git a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c index 82a2ff896a95..52a39ecf5ca1 100644 --- a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c +++ b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c @@ -759,7 +759,7 @@ static acpi_status osl_list_bios_tables(void) /* Skip NULL entries in RSDT/XSDT */ - if (!table_address) { + if (table_address == 0) { continue; } @@ -808,7 +808,8 @@ osl_get_bios_table(char *signature, u8 number_of_tables; u8 item_size; u32 current_instance = 0; - acpi_physical_address table_address = 0; + acpi_physical_address table_address; + acpi_physical_address first_table_address = 0; u32 table_length = 0; acpi_status status = AE_OK; u32 i; @@ -820,9 +821,10 @@ osl_get_bios_table(char *signature, ACPI_COMPARE_NAME(signature, ACPI_SIG_XSDT) || ACPI_COMPARE_NAME(signature, ACPI_SIG_DSDT) || ACPI_COMPARE_NAME(signature, ACPI_SIG_FACS)) { - if (instance > 0) { - return (AE_LIMIT); - } + +find_next_instance: + + table_address = 0; /* * Get the appropriate address, either 32-bit or 64-bit. Be very @@ -830,41 +832,66 @@ osl_get_bios_table(char *signature, * Note: The 64-bit addresses have priority. */ if (ACPI_COMPARE_NAME(signature, ACPI_SIG_DSDT)) { - if ((gbl_fadt->header.length >= MIN_FADT_FOR_XDSDT) && - gbl_fadt->Xdsdt) { - table_address = - (acpi_physical_address)gbl_fadt->Xdsdt; - } else - if ((gbl_fadt->header.length >= MIN_FADT_FOR_DSDT) - && gbl_fadt->dsdt) { - table_address = - (acpi_physical_address)gbl_fadt->dsdt; + if (current_instance < 2) { + if ((gbl_fadt->header.length >= + MIN_FADT_FOR_XDSDT) && gbl_fadt->Xdsdt + && current_instance == 0) { + table_address = + (acpi_physical_address)gbl_fadt-> + Xdsdt; + } else + if ((gbl_fadt->header.length >= + MIN_FADT_FOR_DSDT) + && gbl_fadt->dsdt != + first_table_address) { + table_address = + (acpi_physical_address)gbl_fadt-> + dsdt; + } } } else if (ACPI_COMPARE_NAME(signature, ACPI_SIG_FACS)) { - if ((gbl_fadt->header.length >= MIN_FADT_FOR_XFACS) && - gbl_fadt->Xfacs) { - table_address = - (acpi_physical_address)gbl_fadt->Xfacs; - } else - if ((gbl_fadt->header.length >= MIN_FADT_FOR_FACS) - && gbl_fadt->facs) { - table_address = - (acpi_physical_address)gbl_fadt->facs; + if (current_instance < 2) { + if ((gbl_fadt->header.length >= + MIN_FADT_FOR_XFACS) && gbl_fadt->Xfacs + && current_instance == 0) { + table_address = + (acpi_physical_address)gbl_fadt-> + Xfacs; + } else + if ((gbl_fadt->header.length >= + MIN_FADT_FOR_FACS) + && gbl_fadt->facs != + first_table_address) { + table_address = + (acpi_physical_address)gbl_fadt-> + facs; + } } } else if (ACPI_COMPARE_NAME(signature, ACPI_SIG_XSDT)) { if (!gbl_revision) { return (AE_BAD_SIGNATURE); } - table_address = - (acpi_physical_address)gbl_rsdp. - xsdt_physical_address; + if (current_instance == 0) { + table_address = + (acpi_physical_address)gbl_rsdp. + xsdt_physical_address; + } } else if (ACPI_COMPARE_NAME(signature, ACPI_SIG_RSDT)) { - table_address = - (acpi_physical_address)gbl_rsdp. - rsdt_physical_address; + if (current_instance == 0) { + table_address = + (acpi_physical_address)gbl_rsdp. + rsdt_physical_address; + } } else { - table_address = (acpi_physical_address)gbl_rsdp_address; - signature = ACPI_SIG_RSDP; + if (current_instance == 0) { + table_address = + (acpi_physical_address)gbl_rsdp_address; + signature = ACPI_SIG_RSDP; + } + } + + if (table_address == 0) { + goto exit_find_table; } /* Now we can get the requested special table */ @@ -875,6 +902,18 @@ osl_get_bios_table(char *signature, } table_length = ap_get_table_length(mapped_table); + if (first_table_address == 0) { + first_table_address = table_address; + } + + /* Match table instance */ + + if (current_instance != instance) { + osl_unmap_table(mapped_table); + mapped_table = NULL; + current_instance++; + goto find_next_instance; + } } else { /* Case for a normal ACPI table */ if (osl_can_use_xsdt()) { @@ -913,7 +952,7 @@ osl_get_bios_table(char *signature, /* Skip NULL entries in RSDT/XSDT */ - if (!table_address) { + if (table_address == 0) { continue; } @@ -946,6 +985,8 @@ osl_get_bios_table(char *signature, } } +exit_find_table: + if (!mapped_table) { return (AE_LIMIT); } From 3958168fc8c67b69849f2b1170ab4484e1800d31 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 3 Aug 2017 14:27:03 +0800 Subject: [PATCH 25/32] ACPICA: EFI/EDK2: Cleanup to enable /WX for MSVC builds ACPICA commit a7c6d65a5dab20b1e191c197e09af337fc54b341 /WX turns warning into fatal erros for MSVC builds. We need /WX- during EDK2 porting to allow agile development. Now it is time to enable /WX and some explicit type conversion cleanups are required for enabling /WX. Lv Zheng. Link: https://github.com/acpica/acpica/commit/a7c6d65a Signed-off-by: Lv Zheng Signed-off-by: Bob Moore Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/utprint.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/acpica/utprint.c b/drivers/acpi/acpica/utprint.c index 23cb472e5dc8..c008589b41bd 100644 --- a/drivers/acpi/acpica/utprint.c +++ b/drivers/acpi/acpica/utprint.c @@ -286,7 +286,7 @@ static char *acpi_ut_format_number(char *string, /* Generate full string in reverse order */ pos = acpi_ut_put_number(reversed_string, number, base, upper); - i = ACPI_PTR_DIFF(pos, reversed_string); + i = (s32)ACPI_PTR_DIFF(pos, reversed_string); /* Printing 100 using %2d gives "100", not "00" */ @@ -475,7 +475,7 @@ int vsnprintf(char *string, acpi_size size, const char *format, va_list args) if (!s) { s = ""; } - length = acpi_ut_bound_string_length(s, precision); + length = (s32)acpi_ut_bound_string_length(s, precision); if (!(type & ACPI_FORMAT_LEFT)) { while (length < width--) { pos = @@ -579,7 +579,7 @@ int vsnprintf(char *string, acpi_size size, const char *format, va_list args) } } - return (ACPI_PTR_DIFF(pos, string)); + return ((int)ACPI_PTR_DIFF(pos, string)); } /******************************************************************************* From a5b6e982fb9dc8e49307ff33ddc4b95f1b8e385c Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:27:09 +0800 Subject: [PATCH 26/32] ACPICA: Interpreter: Update handling for Alias operator ACPICA commit 719d0bdd48e3e8e7a62a86c04922b9f41da6def0 Provide common creation code for the Alias operator. All objects are now handled the same, with the only exception being the Method() operator. It has a special internal Alias type. Link: https://github.com/acpica/acpica/commit/719d0bdd Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/excreate.c | 61 ++++++++-------------------------- 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/drivers/acpi/acpica/excreate.c b/drivers/acpi/acpica/excreate.c index 68675868e20f..b8adb11f1b07 100644 --- a/drivers/acpi/acpica/excreate.c +++ b/drivers/acpi/acpica/excreate.c @@ -88,36 +88,26 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state) } /* Ensure that the target node is valid */ + if (!target_node) { return_ACPI_STATUS(AE_NULL_OBJECT); } - /* - * For objects that can never change (i.e., the NS node will - * permanently point to the same object), we can simply attach - * the object to the new NS node. For other objects (such as - * Integers, buffers, etc.), we have to point the Alias node - * to the original Node. - */ + /* Construct the alias object (a namespace node) */ + switch (target_node->type) { - - /* For these types, the sub-object can change dynamically via a Store */ - - case ACPI_TYPE_INTEGER: - case ACPI_TYPE_STRING: - case ACPI_TYPE_BUFFER: - case ACPI_TYPE_PACKAGE: - case ACPI_TYPE_BUFFER_FIELD: + case ACPI_TYPE_METHOD: /* - * These types open a new scope, so we need the NS node in order to access - * any children. + * Control method aliases need to be differentiated with + * a special type */ - case ACPI_TYPE_DEVICE: - case ACPI_TYPE_POWER: - case ACPI_TYPE_PROCESSOR: - case ACPI_TYPE_THERMAL: - case ACPI_TYPE_LOCAL_SCOPE: + alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS; + break; + + default: /* + * All other object types. + * * The new alias has the type ALIAS and points to the original * NS node, not the object itself. */ @@ -125,35 +115,12 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state) alias_node->object = ACPI_CAST_PTR(union acpi_operand_object, target_node); break; - - case ACPI_TYPE_METHOD: - /* - * Control method aliases need to be differentiated - */ - alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS; - alias_node->object = - ACPI_CAST_PTR(union acpi_operand_object, target_node); - break; - - default: - - /* Attach the original source object to the new Alias Node */ - - /* - * The new alias assumes the type of the target, and it points - * to the same object. The reference count of the object has an - * additional reference to prevent deletion out from under either the - * target node or the alias Node - */ - status = acpi_ns_attach_object(alias_node, - acpi_ns_get_attached_object - (target_node), - target_node->type); - break; } /* Since both operands are Nodes, we don't need to delete them */ + alias_node->object = + ACPI_CAST_PTR(union acpi_operand_object, target_node); return_ACPI_STATUS(status); } From 7ab58197d84c29cf20162eaaed1eb2cc94fc73a7 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:27:15 +0800 Subject: [PATCH 27/32] ACPICA: Debugger: Improve support for Alias objects ACPICA commit 916993dbcd45b46e01f6c9b8337a01513f5d8dcc Properly resolve alias objects for display. General cleanup of related output. Link: https://github.com/acpica/acpica/commit/916993db Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/dbdisply.c | 37 +++++++++++++++++++++++++++++----- drivers/acpi/acpica/exdump.c | 34 +++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/drivers/acpi/acpica/dbdisply.c b/drivers/acpi/acpica/dbdisply.c index 46bf270ac525..5a606eac0c22 100644 --- a/drivers/acpi/acpica/dbdisply.c +++ b/drivers/acpi/acpica/dbdisply.c @@ -310,7 +310,7 @@ dump_node: } else { - acpi_os_printf("Object (%p) Pathname: %s\n", + acpi_os_printf("Object %p: Namespace Node - Pathname: %s\n", node, (char *)ret_buf.pointer); } @@ -326,7 +326,7 @@ dump_node: obj_desc = acpi_ns_get_attached_object(node); if (obj_desc) { - acpi_os_printf("\nAttached Object (%p):\n", obj_desc); + acpi_os_printf("\nAttached Object %p:", obj_desc); if (!acpi_os_readable (obj_desc, sizeof(union acpi_operand_object))) { acpi_os_printf @@ -335,9 +335,36 @@ dump_node: return; } - acpi_ut_debug_dump_buffer((void *)obj_desc, - sizeof(union acpi_operand_object), - display, ACPI_UINT32_MAX); + if (ACPI_GET_DESCRIPTOR_TYPE(((struct acpi_namespace_node *) + obj_desc)) == + ACPI_DESC_TYPE_NAMED) { + acpi_os_printf(" Namespace Node - "); + status = + acpi_get_name((struct acpi_namespace_node *) + obj_desc, + ACPI_FULL_PATHNAME_NO_TRAILING, + &ret_buf); + if (ACPI_FAILURE(status)) { + acpi_os_printf + ("Could not convert name to pathname\n"); + } else { + acpi_os_printf("Pathname: %s", + (char *)ret_buf.pointer); + } + + acpi_os_printf("\n"); + acpi_ut_debug_dump_buffer((void *)obj_desc, + sizeof(struct + acpi_namespace_node), + display, ACPI_UINT32_MAX); + } else { + acpi_os_printf("\n"); + acpi_ut_debug_dump_buffer((void *)obj_desc, + sizeof(union + acpi_operand_object), + display, ACPI_UINT32_MAX); + } + acpi_ex_dump_object_descriptor(obj_desc, 1); } } diff --git a/drivers/acpi/acpica/exdump.c b/drivers/acpi/acpica/exdump.c index 44092f744477..83398dc4b7c2 100644 --- a/drivers/acpi/acpica/exdump.c +++ b/drivers/acpi/acpica/exdump.c @@ -102,7 +102,7 @@ static struct acpi_exdump_info acpi_ex_dump_package[6] = { {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_package), NULL}, {ACPI_EXD_NODE, ACPI_EXD_OFFSET(package.node), "Parent Node"}, {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(package.flags), "Flags"}, - {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(package.count), "Elements"}, + {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(package.count), "Element Count"}, {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(package.elements), "Element List"}, {ACPI_EXD_PACKAGE, 0, NULL} }; @@ -384,6 +384,10 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc, count = info->offset; while (count) { + if (!obj_desc) { + return; + } + target = ACPI_ADD_PTR(u8, obj_desc, info->offset); name = info->name; @@ -469,9 +473,9 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc, start = *ACPI_CAST_PTR(void *, target); next = start; - acpi_os_printf("%20s : %p", name, next); + acpi_os_printf("%20s : %p ", name, next); if (next) { - acpi_os_printf("(%s %2.2X)", + acpi_os_printf("%s (Type %2.2X)", acpi_ut_get_object_type_name (next), next->common.type); @@ -493,6 +497,8 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc, break; } } + } else { + acpi_os_printf("- No attached objects"); } acpi_os_printf("\n"); @@ -1129,7 +1135,9 @@ acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc, default: - acpi_os_printf("[Unknown Type] %X\n", obj_desc->common.type); + acpi_os_printf("[%s] Type: %2.2X\n", + acpi_ut_get_type_name(obj_desc->common.type), + obj_desc->common.type); break; } } @@ -1167,11 +1175,17 @@ acpi_ex_dump_object_descriptor(union acpi_operand_object *obj_desc, u32 flags) acpi_ex_dump_namespace_node((struct acpi_namespace_node *) obj_desc, flags); - acpi_os_printf("\nAttached Object (%p):\n", - ((struct acpi_namespace_node *)obj_desc)-> - object); - obj_desc = ((struct acpi_namespace_node *)obj_desc)->object; + if (!obj_desc) { + return_VOID; + } + + acpi_os_printf("\nAttached Object %p", obj_desc); + if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_NAMED) { + acpi_os_printf(" - Namespace Node"); + } + + acpi_os_printf(":\n"); goto dump_object; } @@ -1191,6 +1205,10 @@ acpi_ex_dump_object_descriptor(union acpi_operand_object *obj_desc, u32 flags) dump_object: + if (!obj_desc) { + return_VOID; + } + /* Common Fields */ acpi_ex_dump_object(obj_desc, acpi_ex_dump_common); From a62a7117d91ca83d319566cbe16039f4e9f413c2 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:27:22 +0800 Subject: [PATCH 28/32] ACPICA: Implement deferred resolution of reference package elements ACPICA commit 0c08790c56fdf0dc081ae869495a09d8c4230854 This change defers the resolution of package elements that are named references until after the entire namespace has been loaded from the definition block. This allows such references to be in fact forward references for both module level code and control methods. Link: https://github.com/acpica/acpica/commit/0c08790c Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/Makefile | 1 + drivers/acpi/acpica/acdispat.h | 13 + drivers/acpi/acpica/aclocal.h | 2 +- drivers/acpi/acpica/acobject.h | 3 +- drivers/acpi/acpica/acutils.h | 2 +- drivers/acpi/acpica/dsobject.c | 396 ++++-------------------- drivers/acpi/acpica/dsopcode.c | 9 + drivers/acpi/acpica/dspkginit.c | 496 ++++++++++++++++++++++++++++++ drivers/acpi/acpica/nsarguments.c | 21 +- drivers/acpi/acpica/nsinit.c | 14 + drivers/acpi/acpica/nsnames.c | 9 +- drivers/acpi/acpica/psloop.c | 14 + drivers/acpi/acpica/utmisc.c | 8 +- drivers/acpi/acpica/utobject.c | 5 + drivers/acpi/acpica/utstate.c | 2 +- drivers/acpi/acpica/uttrack.c | 9 +- 16 files changed, 660 insertions(+), 344 deletions(-) create mode 100644 drivers/acpi/acpica/dspkginit.c diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile index b125bdd3d58b..1709551bc4aa 100644 --- a/drivers/acpi/acpica/Makefile +++ b/drivers/acpi/acpica/Makefile @@ -18,6 +18,7 @@ acpi-y := \ dsmthdat.o \ dsobject.o \ dsopcode.o \ + dspkginit.o \ dsutils.o \ dswexec.o \ dswload.o \ diff --git a/drivers/acpi/acpica/acdispat.h b/drivers/acpi/acpica/acdispat.h index 0d95c85cce06..f8f3a6e74128 100644 --- a/drivers/acpi/acpica/acdispat.h +++ b/drivers/acpi/acpica/acdispat.h @@ -237,6 +237,11 @@ acpi_ds_initialize_objects(u32 table_index, * dsobject - Parser/Interpreter interface - object initialization and conversion */ acpi_status +acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, + union acpi_parse_object *op, + union acpi_operand_object **obj_desc_ptr); + +acpi_status acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state, union acpi_parse_object *op, u32 buffer_length, @@ -258,6 +263,14 @@ acpi_ds_create_node(struct acpi_walk_state *walk_state, struct acpi_namespace_node *node, union acpi_parse_object *op); +/* + * dspkginit - Package object initialization + */ +acpi_status +acpi_ds_init_package_element(u8 object_type, + union acpi_operand_object *source_object, + union acpi_generic_state *state, void *context); + /* * dsutils - Parser/Interpreter interface utility routines */ diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h index bae943b5f377..0d45b8bb1678 100644 --- a/drivers/acpi/acpica/aclocal.h +++ b/drivers/acpi/acpica/aclocal.h @@ -605,7 +605,7 @@ struct acpi_update_state { * Pkg state - used to traverse nested package structures */ struct acpi_pkg_state { - ACPI_STATE_COMMON u16 index; + ACPI_STATE_COMMON u32 index; union acpi_operand_object *source_object; union acpi_operand_object *dest_object; struct acpi_walk_state *walk_state; diff --git a/drivers/acpi/acpica/acobject.h b/drivers/acpi/acpica/acobject.h index 549f227348cd..5226146190bf 100644 --- a/drivers/acpi/acpica/acobject.h +++ b/drivers/acpi/acpica/acobject.h @@ -339,11 +339,12 @@ struct acpi_object_addr_handler { struct acpi_object_reference { ACPI_OBJECT_COMMON_HEADER u8 class; /* Reference Class */ u8 target_type; /* Used for Index Op */ - u8 reserved; + u8 resolved; /* Reference has been resolved to a value */ void *object; /* name_op=>HANDLE to obj, index_op=>union acpi_operand_object */ struct acpi_namespace_node *node; /* ref_of or Namepath */ union acpi_operand_object **where; /* Target of Index */ u8 *index_pointer; /* Used for Buffers and Strings */ + u8 *aml; /* Used for deferred resolution of the ref */ u32 value; /* Used for Local/Arg/Index/ddb_handle */ }; diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h index 0a5601405584..745134ade35f 100644 --- a/drivers/acpi/acpica/acutils.h +++ b/drivers/acpi/acpica/acutils.h @@ -516,7 +516,7 @@ union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object, void *external_object, - u16 index); + u32 index); acpi_status acpi_ut_create_update_state_and_push(union acpi_operand_object *object, diff --git a/drivers/acpi/acpica/dsobject.c b/drivers/acpi/acpica/dsobject.c index 7df3152ed856..82448551781b 100644 --- a/drivers/acpi/acpica/dsobject.c +++ b/drivers/acpi/acpica/dsobject.c @@ -52,12 +52,6 @@ #define _COMPONENT ACPI_DISPATCHER ACPI_MODULE_NAME("dsobject") -/* Local prototypes */ -static acpi_status -acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, - union acpi_parse_object *op, - union acpi_operand_object **obj_desc_ptr); - #ifndef ACPI_NO_METHOD_EXECUTION /******************************************************************************* * @@ -73,15 +67,13 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, * Simple objects are any objects other than a package object! * ******************************************************************************/ - -static acpi_status +acpi_status acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, union acpi_parse_object *op, union acpi_operand_object **obj_desc_ptr) { union acpi_operand_object *obj_desc; acpi_status status; - acpi_object_type type; ACPI_FUNCTION_TRACE(ds_build_internal_object); @@ -89,140 +81,47 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { /* * This is a named object reference. If this name was - * previously looked up in the namespace, it was stored in this op. - * Otherwise, go ahead and look it up now + * previously looked up in the namespace, it was stored in + * this op. Otherwise, go ahead and look it up now */ if (!op->common.node) { - status = acpi_ns_lookup(walk_state->scope_info, - op->common.value.string, - ACPI_TYPE_ANY, - ACPI_IMODE_EXECUTE, - ACPI_NS_SEARCH_PARENT | - ACPI_NS_DONT_OPEN_SCOPE, NULL, - ACPI_CAST_INDIRECT_PTR(struct - acpi_namespace_node, - &(op-> - common. - node))); - if (ACPI_FAILURE(status)) { - /* Check if we are resolving a named reference within a package */ + /* Check if we are resolving a named reference within a package */ - if ((status == AE_NOT_FOUND) - && (acpi_gbl_enable_interpreter_slack) - && - ((op->common.parent->common.aml_opcode == - AML_PACKAGE_OP) - || (op->common.parent->common.aml_opcode == - AML_VARIABLE_PACKAGE_OP))) { - /* - * We didn't find the target and we are populating elements - * of a package - ignore if slack enabled. Some ASL code - * contains dangling invalid references in packages and - * expects that no exception will be issued. Leave the - * element as a null element. It cannot be used, but it - * can be overwritten by subsequent ASL code - this is - * typically the case. - */ - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "Ignoring unresolved reference in package [%4.4s]\n", - walk_state-> - scope_info->scope. - node->name.ascii)); - - return_ACPI_STATUS(AE_OK); - } else { + if ((op->common.parent->common.aml_opcode == + AML_PACKAGE_OP) + || (op->common.parent->common.aml_opcode == + AML_VARIABLE_PACKAGE_OP)) { + /* + * We won't resolve package elements here, we will do this + * after all ACPI tables are loaded into the namespace. This + * behavior supports both forward references to named objects + * and external references to objects in other tables. + */ + goto create_new_object; + } else { + status = acpi_ns_lookup(walk_state->scope_info, + op->common.value.string, + ACPI_TYPE_ANY, + ACPI_IMODE_EXECUTE, + ACPI_NS_SEARCH_PARENT | + ACPI_NS_DONT_OPEN_SCOPE, + NULL, + ACPI_CAST_INDIRECT_PTR + (struct + acpi_namespace_node, + &(op->common.node))); + if (ACPI_FAILURE(status)) { ACPI_ERROR_NAMESPACE(op->common.value. string, status); + return_ACPI_STATUS(status); } - - return_ACPI_STATUS(status); - } - } - - /* Special object resolution for elements of a package */ - - if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || - (op->common.parent->common.aml_opcode == - AML_VARIABLE_PACKAGE_OP)) { - /* - * Attempt to resolve the node to a value before we insert it into - * the package. If this is a reference to a common data type, - * resolve it immediately. According to the ACPI spec, package - * elements can only be "data objects" or method references. - * Attempt to resolve to an Integer, Buffer, String or Package. - * If cannot, return the named reference (for things like Devices, - * Methods, etc.) Buffer Fields and Fields will resolve to simple - * objects (int/buf/str/pkg). - * - * NOTE: References to things like Devices, Methods, Mutexes, etc. - * will remain as named references. This behavior is not described - * in the ACPI spec, but it appears to be an oversight. - */ - obj_desc = - ACPI_CAST_PTR(union acpi_operand_object, - op->common.node); - - status = - acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR - (struct - acpi_namespace_node, - &obj_desc), - walk_state); - if (ACPI_FAILURE(status)) { - return_ACPI_STATUS(status); - } - - /* - * Special handling for Alias objects. We need to setup the type - * and the Op->Common.Node to point to the Alias target. Note, - * Alias has at most one level of indirection internally. - */ - type = op->common.node->type; - if (type == ACPI_TYPE_LOCAL_ALIAS) { - type = obj_desc->common.type; - op->common.node = - ACPI_CAST_PTR(struct acpi_namespace_node, - op->common.node->object); - } - - switch (type) { - /* - * For these types, we need the actual node, not the subobject. - * However, the subobject did not get an extra reference count above. - * - * TBD: should ex_resolve_node_to_value be changed to fix this? - */ - case ACPI_TYPE_DEVICE: - case ACPI_TYPE_THERMAL: - - acpi_ut_add_reference(op->common.node->object); - - /*lint -fallthrough */ - /* - * For these types, we need the actual node, not the subobject. - * The subobject got an extra reference count in ex_resolve_node_to_value. - */ - case ACPI_TYPE_MUTEX: - case ACPI_TYPE_METHOD: - case ACPI_TYPE_POWER: - case ACPI_TYPE_PROCESSOR: - case ACPI_TYPE_EVENT: - case ACPI_TYPE_REGION: - - /* We will create a reference object for these types below */ - break; - - default: - /* - * All other types - the node was resolved to an actual - * object, we are done. - */ - goto exit; } } } +create_new_object: + /* Create and init a new internal ACPI object */ obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info @@ -240,7 +139,27 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, return_ACPI_STATUS(status); } -exit: + /* + * Handling for unresolved package reference elements. + * These are elements that are namepaths. + */ + if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || + (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) { + obj_desc->reference.resolved = TRUE; + + if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) && + !obj_desc->reference.node) { + /* + * Name was unresolved above. + * Get the prefix node for later lookup + */ + obj_desc->reference.node = + walk_state->scope_info->scope.node; + obj_desc->reference.aml = op->common.aml; + obj_desc->reference.resolved = FALSE; + } + } + *obj_desc_ptr = obj_desc; return_ACPI_STATUS(status); } @@ -349,200 +268,6 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state, return_ACPI_STATUS(AE_OK); } -/******************************************************************************* - * - * FUNCTION: acpi_ds_build_internal_package_obj - * - * PARAMETERS: walk_state - Current walk state - * op - Parser object to be translated - * element_count - Number of elements in the package - this is - * the num_elements argument to Package() - * obj_desc_ptr - Where the ACPI internal object is returned - * - * RETURN: Status - * - * DESCRIPTION: Translate a parser Op package object to the equivalent - * namespace object - * - * NOTE: The number of elements in the package will be always be the num_elements - * count, regardless of the number of elements in the package list. If - * num_elements is smaller, only that many package list elements are used. - * if num_elements is larger, the Package object is padded out with - * objects of type Uninitialized (as per ACPI spec.) - * - * Even though the ASL compilers do not allow num_elements to be smaller - * than the Package list length (for the fixed length package opcode), some - * BIOS code modifies the AML on the fly to adjust the num_elements, and - * this code compensates for that. This also provides compatibility with - * other AML interpreters. - * - ******************************************************************************/ - -acpi_status -acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state, - union acpi_parse_object *op, - u32 element_count, - union acpi_operand_object **obj_desc_ptr) -{ - union acpi_parse_object *arg; - union acpi_parse_object *parent; - union acpi_operand_object *obj_desc = NULL; - acpi_status status = AE_OK; - u32 i; - u16 index; - u16 reference_count; - - ACPI_FUNCTION_TRACE(ds_build_internal_package_obj); - - /* Find the parent of a possibly nested package */ - - parent = op->common.parent; - while ((parent->common.aml_opcode == AML_PACKAGE_OP) || - (parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) { - parent = parent->common.parent; - } - - /* - * If we are evaluating a Named package object "Name (xxxx, Package)", - * the package object already exists, otherwise it must be created. - */ - obj_desc = *obj_desc_ptr; - if (!obj_desc) { - obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE); - *obj_desc_ptr = obj_desc; - if (!obj_desc) { - return_ACPI_STATUS(AE_NO_MEMORY); - } - - obj_desc->package.node = parent->common.node; - } - - /* - * Allocate the element array (array of pointers to the individual - * objects) based on the num_elements parameter. Add an extra pointer slot - * so that the list is always null terminated. - */ - obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size) - element_count + - 1) * sizeof(void *)); - - if (!obj_desc->package.elements) { - acpi_ut_delete_object_desc(obj_desc); - return_ACPI_STATUS(AE_NO_MEMORY); - } - - obj_desc->package.count = element_count; - - /* - * Initialize the elements of the package, up to the num_elements count. - * Package is automatically padded with uninitialized (NULL) elements - * if num_elements is greater than the package list length. Likewise, - * Package is truncated if num_elements is less than the list length. - */ - arg = op->common.value.arg; - arg = arg->common.next; - for (i = 0; arg && (i < element_count); i++) { - if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { - if (arg->common.node->type == ACPI_TYPE_METHOD) { - /* - * A method reference "looks" to the parser to be a method - * invocation, so we special case it here - */ - arg->common.aml_opcode = AML_INT_NAMEPATH_OP; - status = - acpi_ds_build_internal_object(walk_state, - arg, - &obj_desc-> - package. - elements[i]); - } else { - /* This package element is already built, just get it */ - - obj_desc->package.elements[i] = - ACPI_CAST_PTR(union acpi_operand_object, - arg->common.node); - } - } else { - status = - acpi_ds_build_internal_object(walk_state, arg, - &obj_desc->package. - elements[i]); - } - - if (*obj_desc_ptr) { - - /* Existing package, get existing reference count */ - - reference_count = - (*obj_desc_ptr)->common.reference_count; - if (reference_count > 1) { - - /* Make new element ref count match original ref count */ - - for (index = 0; index < (reference_count - 1); - index++) { - acpi_ut_add_reference((obj_desc-> - package. - elements[i])); - } - } - } - - arg = arg->common.next; - } - - /* Check for match between num_elements and actual length of package_list */ - - if (arg) { - /* - * num_elements was exhausted, but there are remaining elements in the - * package_list. Truncate the package to num_elements. - * - * Note: technically, this is an error, from ACPI spec: "It is an error - * for NumElements to be less than the number of elements in the - * PackageList". However, we just print a message and - * no exception is returned. This provides Windows compatibility. Some - * BIOSs will alter the num_elements on the fly, creating this type - * of ill-formed package object. - */ - while (arg) { - /* - * We must delete any package elements that were created earlier - * and are not going to be used because of the package truncation. - */ - if (arg->common.node) { - acpi_ut_remove_reference(ACPI_CAST_PTR - (union - acpi_operand_object, - arg->common.node)); - arg->common.node = NULL; - } - - /* Find out how many elements there really are */ - - i++; - arg = arg->common.next; - } - - ACPI_INFO(("Actual Package length (%u) is larger than " - "NumElements field (%u), truncated", - i, element_count)); - } else if (i < element_count) { - /* - * Arg list (elements) was exhausted, but we did not reach num_elements count. - * Note: this is not an error, the package is padded out with NULLs. - */ - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "Package List length (%u) smaller than NumElements " - "count (%u), padded with null elements\n", - i, element_count)); - } - - obj_desc->package.flags |= AOPOBJ_DATA_VALID; - op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc); - return_ACPI_STATUS(status); -} - /******************************************************************************* * * FUNCTION: acpi_ds_create_node @@ -662,11 +387,20 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state, case ACPI_TYPE_PACKAGE: /* - * Defer evaluation of Package term_arg operand + * Defer evaluation of Package term_arg operand and all + * package elements. (01/2017): We defer the element + * resolution to allow forward references from the package + * in order to provide compatibility with other ACPI + * implementations. */ obj_desc->package.node = ACPI_CAST_PTR(struct acpi_namespace_node, walk_state->operands[0]); + + if (!op->named.data) { + return_ACPI_STATUS(AE_OK); + } + obj_desc->package.aml_start = op->named.data; obj_desc->package.aml_length = op->named.length; break; @@ -818,9 +552,11 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state, /* Node was saved in Op */ obj_desc->reference.node = op->common.node; - obj_desc->reference.object = - op->common.node->object; obj_desc->reference.class = ACPI_REFCLASS_NAME; + if (op->common.node) { + obj_desc->reference.object = + op->common.node->object; + } break; case AML_DEBUG_OP: diff --git a/drivers/acpi/acpica/dsopcode.c b/drivers/acpi/acpica/dsopcode.c index dfc3c25a083d..0336df7ac47d 100644 --- a/drivers/acpi/acpica/dsopcode.c +++ b/drivers/acpi/acpica/dsopcode.c @@ -599,6 +599,15 @@ acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state, */ walk_state->operand_index = walk_state->num_operands; + /* Ignore if child is not valid */ + + if (!op->common.value.arg) { + ACPI_ERROR((AE_INFO, + "Dispatch: Missing child while executing TermArg for %X", + op->common.aml_opcode)); + return_ACPI_STATUS(AE_OK); + } + status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); diff --git a/drivers/acpi/acpica/dspkginit.c b/drivers/acpi/acpica/dspkginit.c new file mode 100644 index 000000000000..6d487edfe2de --- /dev/null +++ b/drivers/acpi/acpica/dspkginit.c @@ -0,0 +1,496 @@ +/****************************************************************************** + * + * Module Name: dspkginit - Completion of deferred package initialization + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2017, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include "accommon.h" +#include "acnamesp.h" +#include "amlcode.h" +#include "acdispat.h" +#include "acinterp.h" + +#define _COMPONENT ACPI_NAMESPACE +ACPI_MODULE_NAME("dspkginit") + +/* Local prototypes */ +static void +acpi_ds_resolve_package_element(union acpi_operand_object **element); + +/******************************************************************************* + * + * FUNCTION: acpi_ds_build_internal_package_obj + * + * PARAMETERS: walk_state - Current walk state + * op - Parser object to be translated + * element_count - Number of elements in the package - this is + * the num_elements argument to Package() + * obj_desc_ptr - Where the ACPI internal object is returned + * + * RETURN: Status + * + * DESCRIPTION: Translate a parser Op package object to the equivalent + * namespace object + * + * NOTE: The number of elements in the package will be always be the num_elements + * count, regardless of the number of elements in the package list. If + * num_elements is smaller, only that many package list elements are used. + * if num_elements is larger, the Package object is padded out with + * objects of type Uninitialized (as per ACPI spec.) + * + * Even though the ASL compilers do not allow num_elements to be smaller + * than the Package list length (for the fixed length package opcode), some + * BIOS code modifies the AML on the fly to adjust the num_elements, and + * this code compensates for that. This also provides compatibility with + * other AML interpreters. + * + ******************************************************************************/ + +acpi_status +acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state, + union acpi_parse_object *op, + u32 element_count, + union acpi_operand_object **obj_desc_ptr) +{ + union acpi_parse_object *arg; + union acpi_parse_object *parent; + union acpi_operand_object *obj_desc = NULL; + acpi_status status = AE_OK; + u16 reference_count; + u32 index; + u32 i; + + ACPI_FUNCTION_TRACE(ds_build_internal_package_obj); + + /* Find the parent of a possibly nested package */ + + parent = op->common.parent; + while ((parent->common.aml_opcode == AML_PACKAGE_OP) || + (parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) { + parent = parent->common.parent; + } + + /* + * If we are evaluating a Named package object of the form: + * Name (xxxx, Package) + * the package object already exists, otherwise it must be created. + */ + obj_desc = *obj_desc_ptr; + if (!obj_desc) { + obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE); + *obj_desc_ptr = obj_desc; + if (!obj_desc) { + return_ACPI_STATUS(AE_NO_MEMORY); + } + + obj_desc->package.node = parent->common.node; + } + + if (obj_desc->package.flags & AOPOBJ_DATA_VALID) { /* Just in case */ + return_ACPI_STATUS(AE_OK); + } + + /* + * Allocate the element array (array of pointers to the individual + * objects) based on the num_elements parameter. Add an extra pointer slot + * so that the list is always null terminated. + */ + obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size) + element_count + + 1) * sizeof(void *)); + + if (!obj_desc->package.elements) { + acpi_ut_delete_object_desc(obj_desc); + return_ACPI_STATUS(AE_NO_MEMORY); + } + + obj_desc->package.count = element_count; + arg = op->common.value.arg; + arg = arg->common.next; + + if (arg) { + obj_desc->package.flags |= AOPOBJ_DATA_VALID; + } + + /* + * Initialize the elements of the package, up to the num_elements count. + * Package is automatically padded with uninitialized (NULL) elements + * if num_elements is greater than the package list length. Likewise, + * Package is truncated if num_elements is less than the list length. + */ + for (i = 0; arg && (i < element_count); i++) { + if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { + if (arg->common.node->type == ACPI_TYPE_METHOD) { + /* + * A method reference "looks" to the parser to be a method + * invocation, so we special case it here + */ + arg->common.aml_opcode = AML_INT_NAMEPATH_OP; + status = + acpi_ds_build_internal_object(walk_state, + arg, + &obj_desc-> + package. + elements[i]); + } else { + /* This package element is already built, just get it */ + + obj_desc->package.elements[i] = + ACPI_CAST_PTR(union acpi_operand_object, + arg->common.node); + } + } else { + status = + acpi_ds_build_internal_object(walk_state, arg, + &obj_desc->package. + elements[i]); + if (status == AE_NOT_FOUND) { + ACPI_ERROR((AE_INFO, "%-48s", + "****DS namepath not found")); + } + + /* + * Initialize this package element. This function handles the + * resolution of named references within the package. + */ + acpi_ds_init_package_element(0, + obj_desc->package. + elements[i], NULL, + &obj_desc->package. + elements[i]); + } + + if (*obj_desc_ptr) { + + /* Existing package, get existing reference count */ + + reference_count = + (*obj_desc_ptr)->common.reference_count; + if (reference_count > 1) { + + /* Make new element ref count match original ref count */ + /* TBD: Probably need an acpi_ut_add_references function */ + + for (index = 0; + index < ((u32)reference_count - 1); + index++) { + acpi_ut_add_reference((obj_desc-> + package. + elements[i])); + } + } + } + + arg = arg->common.next; + } + + /* Check for match between num_elements and actual length of package_list */ + + if (arg) { + /* + * num_elements was exhausted, but there are remaining elements in + * the package_list. Truncate the package to num_elements. + * + * Note: technically, this is an error, from ACPI spec: "It is an + * error for NumElements to be less than the number of elements in + * the PackageList". However, we just print a message and no + * exception is returned. This provides compatibility with other + * ACPI implementations. Some firmware implementations will alter + * the num_elements on the fly, possibly creating this type of + * ill-formed package object. + */ + while (arg) { + /* + * We must delete any package elements that were created earlier + * and are not going to be used because of the package truncation. + */ + if (arg->common.node) { + acpi_ut_remove_reference(ACPI_CAST_PTR + (union + acpi_operand_object, + arg->common.node)); + arg->common.node = NULL; + } + + /* Find out how many elements there really are */ + + i++; + arg = arg->common.next; + } + + ACPI_INFO(("Actual Package length (%u) is larger than " + "NumElements field (%u), truncated", + i, element_count)); + } else if (i < element_count) { + /* + * Arg list (elements) was exhausted, but we did not reach + * num_elements count. + * + * Note: this is not an error, the package is padded out + * with NULLs. + */ + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "Package List length (%u) smaller than NumElements " + "count (%u), padded with null elements\n", + i, element_count)); + } + + obj_desc->package.flags |= AOPOBJ_DATA_VALID; + op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc); + return_ACPI_STATUS(status); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ds_init_package_element + * + * PARAMETERS: acpi_pkg_callback + * + * RETURN: Status + * + * DESCRIPTION: Resolve a named reference element within a package object + * + ******************************************************************************/ + +acpi_status +acpi_ds_init_package_element(u8 object_type, + union acpi_operand_object *source_object, + union acpi_generic_state *state, void *context) +{ + union acpi_operand_object **element_ptr; + + if (!source_object) { + return (AE_OK); + } + + /* + * The following code is a bit of a hack to workaround a (current) + * limitation of the acpi_pkg_callback interface. We need a pointer + * to the location within the element array because a new object + * may be created and stored there. + */ + if (context) { + + /* A direct call was made to this function */ + + element_ptr = (union acpi_operand_object **)context; + } else { + /* Call came from acpi_ut_walk_package_tree */ + + element_ptr = state->pkg.this_target_obj; + } + + /* We are only interested in reference objects/elements */ + + if (source_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) { + + /* Attempt to resolve the (named) reference to a namespace node */ + + acpi_ds_resolve_package_element(element_ptr); + } else if (source_object->common.type == ACPI_TYPE_PACKAGE) { + source_object->package.flags |= AOPOBJ_DATA_VALID; + } + + return (AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ds_resolve_package_element + * + * PARAMETERS: element_ptr - Pointer to a reference object + * + * RETURN: Possible new element is stored to the indirect element_ptr + * + * DESCRIPTION: Resolve a package element that is a reference to a named + * object. + * + ******************************************************************************/ + +static void +acpi_ds_resolve_package_element(union acpi_operand_object **element_ptr) +{ + acpi_status status; + union acpi_generic_state scope_info; + union acpi_operand_object *element = *element_ptr; + struct acpi_namespace_node *resolved_node; + char *external_path = NULL; + acpi_object_type type; + + ACPI_FUNCTION_TRACE(ds_resolve_package_element); + + /* Check if reference element is already resolved */ + + if (element->reference.resolved) { + return_VOID; + } + + /* Element must be a reference object of correct type */ + + scope_info.scope.node = element->reference.node; /* Prefix node */ + + status = acpi_ns_lookup(&scope_info, (char *)element->reference.aml, /* Pointer to AML path */ + ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, + ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, + NULL, &resolved_node); + if (ACPI_FAILURE(status)) { + status = acpi_ns_externalize_name(ACPI_UINT32_MAX, + (char *)element->reference. + aml, NULL, &external_path); + + ACPI_EXCEPTION((AE_INFO, status, + "Could not find/resolve named package element: %s", + external_path)); + + ACPI_FREE(external_path); + *element_ptr = NULL; + return_VOID; + } else if (resolved_node->type == ACPI_TYPE_ANY) { + + /* Named reference not resolved, return a NULL package element */ + + ACPI_ERROR((AE_INFO, + "Could not resolve named package element [%4.4s] in [%4.4s]", + resolved_node->name.ascii, + scope_info.scope.node->name.ascii)); + *element_ptr = NULL; + return_VOID; + } +#if 0 + else if (resolved_node->flags & ANOBJ_TEMPORARY) { + /* + * A temporary node found here indicates that the reference is + * to a node that was created within this method. We are not + * going to allow it (especially if the package is returned + * from the method) -- the temporary node will be deleted out + * from under the method. (05/2017). + */ + ACPI_ERROR((AE_INFO, + "Package element refers to a temporary name [%4.4s], " + "inserting a NULL element", + resolved_node->name.ascii)); + *element_ptr = NULL; + return_VOID; + } +#endif + + /* + * Special handling for Alias objects. We need resolved_node to point + * to the Alias target. This effectively "resolves" the alias. + */ + if (resolved_node->type == ACPI_TYPE_LOCAL_ALIAS) { + resolved_node = ACPI_CAST_PTR(struct acpi_namespace_node, + resolved_node->object); + } + + /* Update the reference object */ + + element->reference.resolved = TRUE; + element->reference.node = resolved_node; + type = element->reference.node->type; + + /* + * Attempt to resolve the node to a value before we insert it into + * the package. If this is a reference to a common data type, + * resolve it immediately. According to the ACPI spec, package + * elements can only be "data objects" or method references. + * Attempt to resolve to an Integer, Buffer, String or Package. + * If cannot, return the named reference (for things like Devices, + * Methods, etc.) Buffer Fields and Fields will resolve to simple + * objects (int/buf/str/pkg). + * + * NOTE: References to things like Devices, Methods, Mutexes, etc. + * will remain as named references. This behavior is not described + * in the ACPI spec, but it appears to be an oversight. + */ + status = acpi_ex_resolve_node_to_value(&resolved_node, NULL); + if (ACPI_FAILURE(status)) { + return_VOID; + } +#if 0 +/* TBD - alias support */ + /* + * Special handling for Alias objects. We need to setup the type + * and the Op->Common.Node to point to the Alias target. Note, + * Alias has at most one level of indirection internally. + */ + type = op->common.node->type; + if (type == ACPI_TYPE_LOCAL_ALIAS) { + type = obj_desc->common.type; + op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, + op->common.node->object); + } +#endif + + switch (type) { + /* + * These object types are a result of named references, so we will + * leave them as reference objects. In other words, these types + * have no intrinsic "value". + */ + case ACPI_TYPE_DEVICE: + case ACPI_TYPE_THERMAL: + + /* TBD: This may not be necesssary */ + + acpi_ut_add_reference(resolved_node->object); + break; + + case ACPI_TYPE_MUTEX: + case ACPI_TYPE_METHOD: + case ACPI_TYPE_POWER: + case ACPI_TYPE_PROCESSOR: + case ACPI_TYPE_EVENT: + case ACPI_TYPE_REGION: + + break; + + default: + /* + * For all other types - the node was resolved to an actual + * operand object with a value, return the object + */ + *element_ptr = (union acpi_operand_object *)resolved_node; + break; + } + + return_VOID; +} diff --git a/drivers/acpi/acpica/nsarguments.c b/drivers/acpi/acpica/nsarguments.c index 9095d51f6b37..67b7370dcae5 100644 --- a/drivers/acpi/acpica/nsarguments.c +++ b/drivers/acpi/acpica/nsarguments.c @@ -69,9 +69,14 @@ void acpi_ns_check_argument_types(struct acpi_evaluate_info *info) u8 user_arg_type; u32 i; - /* If not a predefined name, cannot typecheck args */ - - if (!info->predefined) { + /* + * If not a predefined name, cannot typecheck args, because + * we have no idea what argument types are expected. + * Also, ignore typecheck if warnings/errors if this method + * has already been evaluated at least once -- in order + * to suppress repetitive messages. + */ + if (!info->predefined || (info->node->flags & ANOBJ_EVALUATED)) { return; } @@ -93,6 +98,10 @@ void acpi_ns_check_argument_types(struct acpi_evaluate_info *info) acpi_ut_get_type_name (user_arg_type), acpi_ut_get_type_name(arg_type))); + + /* Prevent any additional typechecking for this method */ + + info->node->flags |= ANOBJ_EVALUATED; } } } @@ -121,7 +130,7 @@ acpi_ns_check_acpi_compliance(char *pathname, u32 aml_param_count; u32 required_param_count; - if (!predefined) { + if (!predefined || (node->flags & ANOBJ_EVALUATED)) { return; } @@ -215,6 +224,10 @@ acpi_ns_check_argument_count(char *pathname, u32 aml_param_count; u32 required_param_count; + if (node->flags & ANOBJ_EVALUATED) { + return; + } + if (!predefined) { /* * Not a predefined name. Check the incoming user argument count diff --git a/drivers/acpi/acpica/nsinit.c b/drivers/acpi/acpica/nsinit.c index ce33e7297ea7..9c6297949712 100644 --- a/drivers/acpi/acpica/nsinit.c +++ b/drivers/acpi/acpica/nsinit.c @@ -396,6 +396,20 @@ acpi_ns_init_one_object(acpi_handle obj_handle, info->package_init++; status = acpi_ds_get_package_arguments(obj_desc); + if (ACPI_FAILURE(status)) { + break; + } + + /* + * Resolve all named references in package objects (and all + * sub-packages). This action has been deferred until the entire + * namespace has been loaded, in order to support external and + * forward references from individual package elements (05/2017). + */ + status = acpi_ut_walk_package_tree(obj_desc, NULL, + acpi_ds_init_package_element, + NULL); + obj_desc->package.flags |= AOPOBJ_DATA_VALID; break; default: diff --git a/drivers/acpi/acpica/nsnames.c b/drivers/acpi/acpica/nsnames.c index aa16aeaa8937..a410760a0308 100644 --- a/drivers/acpi/acpica/nsnames.c +++ b/drivers/acpi/acpica/nsnames.c @@ -89,7 +89,14 @@ acpi_size acpi_ns_get_pathname_length(struct acpi_namespace_node *node) { acpi_size size; - ACPI_FUNCTION_ENTRY(); + /* Validate the Node */ + + if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) { + ACPI_ERROR((AE_INFO, + "Invalid/cached reference target node: %p, descriptor type %d", + node, ACPI_GET_DESCRIPTOR_TYPE(node))); + return (0); + } size = acpi_ns_build_normalized_path(node, NULL, 0, FALSE); return (size); diff --git a/drivers/acpi/acpica/psloop.c b/drivers/acpi/acpica/psloop.c index b4224005783c..bb04dec168ad 100644 --- a/drivers/acpi/acpica/psloop.c +++ b/drivers/acpi/acpica/psloop.c @@ -164,6 +164,11 @@ acpi_ps_get_arguments(struct acpi_walk_state *walk_state, INCREMENT_ARG_LIST(walk_state->arg_types); } + ACPI_DEBUG_PRINT((ACPI_DB_PARSE, + "Final argument count: %u pass %u\n", + walk_state->arg_count, + walk_state->pass_number)); + /* * Handle executable code at "module-level". This refers to * executable opcodes that appear outside of any control method. @@ -277,6 +282,11 @@ acpi_ps_get_arguments(struct acpi_walk_state *walk_state, AML_NAME_OP) && (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2)) { + ACPI_DEBUG_PRINT((ACPI_DB_PARSE, + "Setup Package/Buffer: Pass %u, AML Ptr: %p\n", + walk_state->pass_number, + aml_op_start)); + /* * Skip parsing of Buffers and Packages because we don't have * enough info in the first pass to parse them correctly. @@ -570,6 +580,10 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state) /* Check for arguments that need to be processed */ + ACPI_DEBUG_PRINT((ACPI_DB_PARSE, + "Parseloop: argument count: %u\n", + walk_state->arg_count)); + if (walk_state->arg_count) { /* * There are arguments (complex ones), push Op and diff --git a/drivers/acpi/acpica/utmisc.c b/drivers/acpi/acpica/utmisc.c index 443ffad01209..4d9f3a2a4f8e 100644 --- a/drivers/acpi/acpica/utmisc.c +++ b/drivers/acpi/acpica/utmisc.c @@ -224,7 +224,7 @@ acpi_ut_create_update_state_and_push(union acpi_operand_object *object, * * RETURN: Status * - * DESCRIPTION: Walk through a package + * DESCRIPTION: Walk through a package, including subpackages * ******************************************************************************/ @@ -236,8 +236,8 @@ acpi_ut_walk_package_tree(union acpi_operand_object *source_object, acpi_status status = AE_OK; union acpi_generic_state *state_list = NULL; union acpi_generic_state *state; - u32 this_index; union acpi_operand_object *this_source_obj; + u32 this_index; ACPI_FUNCTION_TRACE(ut_walk_package_tree); @@ -251,8 +251,10 @@ acpi_ut_walk_package_tree(union acpi_operand_object *source_object, /* Get one element of the package */ this_index = state->pkg.index; - this_source_obj = (union acpi_operand_object *) + this_source_obj = state->pkg.source_object->package.elements[this_index]; + state->pkg.this_target_obj = + &state->pkg.source_object->package.elements[this_index]; /* * Check for: diff --git a/drivers/acpi/acpica/utobject.c b/drivers/acpi/acpica/utobject.c index 64e6641bfe82..cb3db9fed50d 100644 --- a/drivers/acpi/acpica/utobject.c +++ b/drivers/acpi/acpica/utobject.c @@ -483,6 +483,11 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object, /* A namespace node should never get here */ + ACPI_ERROR((AE_INFO, + "Received a namespace node [%4.4s] " + "where an operand object is required", + ACPI_CAST_PTR(struct acpi_namespace_node, + internal_object)->name.ascii)); return_ACPI_STATUS(AE_AML_INTERNAL); } diff --git a/drivers/acpi/acpica/utstate.c b/drivers/acpi/acpica/utstate.c index 64308c304ade..eafabcd2fada 100644 --- a/drivers/acpi/acpica/utstate.c +++ b/drivers/acpi/acpica/utstate.c @@ -226,7 +226,7 @@ union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object, void *external_object, - u16 index) + u32 index) { union acpi_generic_state *state; diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c index 9a07a42cae34..3c8de88ecbd5 100644 --- a/drivers/acpi/acpica/uttrack.c +++ b/drivers/acpi/acpica/uttrack.c @@ -591,6 +591,10 @@ void acpi_ut_dump_allocations(u32 component, const char *module) return_VOID; } + if (!acpi_gbl_global_list) { + goto exit; + } + element = acpi_gbl_global_list->list_head; while (element) { if ((element->component & component) && @@ -602,7 +606,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module) if (element->size < sizeof(struct acpi_common_descriptor)) { - acpi_os_printf("%p Length 0x%04X %9.9s-%u " + acpi_os_printf("%p Length 0x%04X %9.9s-%4.4u " "[Not a Descriptor - too small]\n", descriptor, element->size, element->module, element->line); @@ -612,7 +616,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module) if (ACPI_GET_DESCRIPTOR_TYPE(descriptor) != ACPI_DESC_TYPE_CACHED) { acpi_os_printf - ("%p Length 0x%04X %9.9s-%u [%s] ", + ("%p Length 0x%04X %9.9s-%4.4u [%s] ", descriptor, element->size, element->module, element->line, acpi_ut_get_descriptor_name @@ -705,6 +709,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module) element = element->next; } +exit: (void)acpi_ut_release_mutex(ACPI_MTX_MEMORY); /* Print summary */ From 376a588ceca401289cb40287503cc31dd643188f Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:27:28 +0800 Subject: [PATCH 29/32] ACPICA: Ensure all instances of AE_AML_INTERNAL have error messages ACPICA commit ea9152daaec30760fa4c25285998f58233ec0db5 This exception is only meaningful with an associated error message. Link: https://github.com/acpica/acpica/commit/ea9152da Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/dsfield.c | 2 ++ drivers/acpi/acpica/exmisc.c | 9 +++++++++ drivers/acpi/acpica/exoparg2.c | 3 +++ drivers/acpi/acpica/nsprepkg.c | 2 ++ drivers/acpi/acpica/utmisc.c | 2 ++ 5 files changed, 18 insertions(+) diff --git a/drivers/acpi/acpica/dsfield.c b/drivers/acpi/acpica/dsfield.c index c5dccc54307d..7bcf5f5ea029 100644 --- a/drivers/acpi/acpica/dsfield.c +++ b/drivers/acpi/acpica/dsfield.c @@ -184,6 +184,7 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op, /* Execute flag should always be set when this function is entered */ if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) { + ACPI_ERROR((AE_INFO, "Parse execute mode is not set")); return_ACPI_STATUS(AE_AML_INTERNAL); } @@ -556,6 +557,7 @@ acpi_ds_init_field_objects(union acpi_parse_object *op, return_ACPI_STATUS(AE_OK); } + ACPI_ERROR((AE_INFO, "Parse deferred mode is not set")); return_ACPI_STATUS(AE_AML_INTERNAL); } diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c index f222a80ca38e..1e7649ce0a7b 100644 --- a/drivers/acpi/acpica/exmisc.c +++ b/drivers/acpi/acpica/exmisc.c @@ -265,6 +265,8 @@ acpi_ex_do_logical_numeric_op(u16 opcode, default: + ACPI_ERROR((AE_INFO, + "Invalid numeric logical opcode: %X", opcode)); status = AE_AML_INTERNAL; break; } @@ -345,6 +347,9 @@ acpi_ex_do_logical_op(u16 opcode, default: + ACPI_ERROR((AE_INFO, + "Invalid object type for logical operator: %X", + operand0->common.type)); status = AE_AML_INTERNAL; break; } @@ -388,6 +393,8 @@ acpi_ex_do_logical_op(u16 opcode, default: + ACPI_ERROR((AE_INFO, + "Invalid comparison opcode: %X", opcode)); status = AE_AML_INTERNAL; break; } @@ -456,6 +463,8 @@ acpi_ex_do_logical_op(u16 opcode, default: + ACPI_ERROR((AE_INFO, + "Invalid comparison opcode: %X", opcode)); status = AE_AML_INTERNAL; break; } diff --git a/drivers/acpi/acpica/exoparg2.c b/drivers/acpi/acpica/exoparg2.c index eecb3bff7fd7..57980b7d3594 100644 --- a/drivers/acpi/acpica/exoparg2.c +++ b/drivers/acpi/acpica/exoparg2.c @@ -414,6 +414,9 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state) default: + ACPI_ERROR((AE_INFO, + "Invalid object type: %X", + (operand[0])->common.type)); status = AE_AML_INTERNAL; goto cleanup; } diff --git a/drivers/acpi/acpica/nsprepkg.c b/drivers/acpi/acpica/nsprepkg.c index 4954cb6c9090..a8ea8fb1d299 100644 --- a/drivers/acpi/acpica/nsprepkg.c +++ b/drivers/acpi/acpica/nsprepkg.c @@ -614,6 +614,8 @@ acpi_ns_check_package_list(struct acpi_evaluate_info *info, default: /* Should not get here, type was validated by caller */ + ACPI_ERROR((AE_INFO, "Invalid Package type: %X", + package->ret_info.type)); return (AE_AML_INTERNAL); } diff --git a/drivers/acpi/acpica/utmisc.c b/drivers/acpi/acpica/utmisc.c index 4d9f3a2a4f8e..45c78c2adbf0 100644 --- a/drivers/acpi/acpica/utmisc.c +++ b/drivers/acpi/acpica/utmisc.c @@ -341,6 +341,8 @@ acpi_ut_walk_package_tree(union acpi_operand_object *source_object, /* We should never get here */ + ACPI_ERROR((AE_INFO, "State list did not terminate correctly")); + return_ACPI_STATUS(AE_AML_INTERNAL); } From 137c78352ea98db70d0f2aa648f723bb444faee8 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:27:35 +0800 Subject: [PATCH 30/32] ACPICA: Resources: Allow _DMA method in walk resources ACPICA commit af661c00afac7aa481a961fa48c6540a99ad64a6 The _DMA object contains a resource template, this change adds support for the walk resources function so that ACPI devices containing a _DMA object can actually parse it to detect DMA ranges for the respective bus. Link: https://github.com/acpica/acpica/commit/af661c00 Signed-off-by: Lorenzo Pieralisi Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/rsxface.c | 7 ++++--- include/acpi/acnames.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/acpica/rsxface.c b/drivers/acpi/acpica/rsxface.c index 59a4f9ed06a7..be65e65e216e 100644 --- a/drivers/acpi/acpica/rsxface.c +++ b/drivers/acpi/acpica/rsxface.c @@ -615,7 +615,7 @@ ACPI_EXPORT_SYMBOL(acpi_walk_resource_buffer) * device we are querying * name - Method name of the resources we want. * (METHOD_NAME__CRS, METHOD_NAME__PRS, or - * METHOD_NAME__AEI) + * METHOD_NAME__AEI or METHOD_NAME__DMA) * user_function - Called for each resource * context - Passed to user_function * @@ -641,11 +641,12 @@ acpi_walk_resources(acpi_handle device_handle, if (!device_handle || !user_function || !name || (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) && !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS) && - !ACPI_COMPARE_NAME(name, METHOD_NAME__AEI))) { + !ACPI_COMPARE_NAME(name, METHOD_NAME__AEI) && + !ACPI_COMPARE_NAME(name, METHOD_NAME__DMA))) { return_ACPI_STATUS(AE_BAD_PARAMETER); } - /* Get the _CRS/_PRS/_AEI resource list */ + /* Get the _CRS/_PRS/_AEI/_DMA resource list */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_rs_get_method_data(device_handle, name, &buffer); diff --git a/include/acpi/acnames.h b/include/acpi/acnames.h index b421584033a5..d8dd3bf51ca7 100644 --- a/include/acpi/acnames.h +++ b/include/acpi/acnames.h @@ -54,6 +54,7 @@ #define METHOD_NAME__CLS "_CLS" #define METHOD_NAME__CRS "_CRS" #define METHOD_NAME__DDN "_DDN" +#define METHOD_NAME__DMA "_DMA" #define METHOD_NAME__HID "_HID" #define METHOD_NAME__INI "_INI" #define METHOD_NAME__PLD "_PLD" From d5efc154e797f72064ce5bac82213df09f1586b1 Mon Sep 17 00:00:00 2001 From: Erik Schmauss Date: Thu, 3 Aug 2017 14:27:42 +0800 Subject: [PATCH 31/32] ACPICA: Revert "Update resource descriptor handling" ACPICA commit f3300640c63df138d133740b54e2c0a1befa4086 This reverts commit c8eac10178b387f9eb1935694e509d4518da77bb. Link: https://github.com/acpica/acpica/commit/f3300640 Signed-off-by: Erik Schmauss Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/utresrc.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/acpica/utresrc.c b/drivers/acpi/acpica/utresrc.c index 517acf8e77c8..f9801d13547f 100644 --- a/drivers/acpi/acpica/utresrc.c +++ b/drivers/acpi/acpica/utresrc.c @@ -184,11 +184,9 @@ acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state, ACPI_FUNCTION_TRACE(ut_walk_aml_resources); - /* - * The absolute minimum resource template is one end_tag descriptor. - * However, we will treat a lone end_tag as just a simple buffer. - */ - if (aml_length <= sizeof(struct aml_resource_end_tag)) { + /* The absolute minimum resource template is one end_tag descriptor */ + + if (aml_length < sizeof(struct aml_resource_end_tag)) { return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } @@ -252,10 +250,8 @@ acpi_ut_walk_aml_resources(struct acpi_walk_state *walk_state, *context = aml; } - /* - * Normal exit. Note: We allow the buffer to be larger than - * the resource template, as long as the END_TAG exists. - */ + /* Normal exit */ + return_ACPI_STATUS(AE_OK); } From 4a9673dd50c2362f5bd2d03c89099267b49d400a Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Thu, 3 Aug 2017 14:27:48 +0800 Subject: [PATCH 32/32] ACPICA: Update version to 20170728 ACPICA commit 50f61636543a55d143c792a4814da7700a7fafc2 Version 20170728. Link: https://github.com/acpica/acpica/commit/50f61636 Signed-off-by: Bob Moore Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- include/acpi/acpixf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h index 06b87adc97ef..53c5e2f7bcec 100644 --- a/include/acpi/acpixf.h +++ b/include/acpi/acpixf.h @@ -46,7 +46,7 @@ /* Current ACPICA subsystem version in YYYYMMDD format */ -#define ACPI_CA_VERSION 0x20170629 +#define ACPI_CA_VERSION 0x20170728 #include #include