2005-04-17 05:20:36 +07:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Module Name: nsparse - namespace interface to AML parser
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2016-01-15 07:17:03 +07:00
|
|
|
* Copyright (C) 2000 - 2016, Intel Corp.
|
2005-04-17 05:20:36 +07:00
|
|
|
* 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 <acpi/acpi.h>
|
2009-01-09 12:30:03 +07:00
|
|
|
#include "accommon.h"
|
|
|
|
#include "acnamesp.h"
|
|
|
|
#include "acparser.h"
|
|
|
|
#include "acdispat.h"
|
|
|
|
#include "actables.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define _COMPONENT ACPI_NAMESPACE
|
2005-08-05 11:44:28 +07:00
|
|
|
ACPI_MODULE_NAME("nsparse")
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: ns_one_complete_parse
|
|
|
|
*
|
|
|
|
* PARAMETERS: pass_number - 1 or 2
|
|
|
|
* table_desc - The table to be parsed.
|
|
|
|
*
|
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Perform one complete parse of an ACPI/AML table.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
acpi_status
|
2008-06-10 12:42:13 +07:00
|
|
|
acpi_ns_one_complete_parse(u32 pass_number,
|
|
|
|
u32 table_index,
|
|
|
|
struct acpi_namespace_node *start_node)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-08-05 11:44:28 +07:00
|
|
|
union acpi_parse_object *parse_root;
|
|
|
|
acpi_status status;
|
2015-07-23 11:52:05 +07:00
|
|
|
u32 aml_length;
|
2007-02-02 23:48:18 +07:00
|
|
|
u8 *aml_start;
|
2005-08-05 11:44:28 +07:00
|
|
|
struct acpi_walk_state *walk_state;
|
2007-02-02 23:48:18 +07:00
|
|
|
struct acpi_table_header *table;
|
|
|
|
acpi_owner_id owner_id;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
ACPI: ACPICA 20060421
Removed a device initialization optimization introduced in
20051216 where the _STA method was not run unless an _INI
was also present for the same device. This optimization
could cause problems because it could allow _INI methods
to be run within a not-present device subtree (If a
not-present device had no _INI, _STA would not be run,
the not-present status would not be discovered, and the
children of the device would be incorrectly traversed.)
Implemented a new _STA optimization where namespace
subtrees that do not contain _INI are identified and
ignored during device initialization. Selectively running
_STA can significantly improve boot time on large machines
(with assistance from Len Brown.)
Implemented support for the device initialization case
where the returned _STA flags indicate a device not-present
but functioning. In this case, _INI is not run, but the
device children are examined for presence, as per the
ACPI specification.
Implemented an additional change to the IndexField support
in order to conform to MS behavior. The value written to
the Index Register is not simply a byte offset, it is a
byte offset in units of the access width of the parent
Index Field. (Fiodor Suietov)
Defined and deployed a new OSL interface,
acpi_os_validate_address(). This interface is called during
the creation of all AML operation regions, and allows
the host OS to exert control over what addresses it will
allow the AML code to access. Operation Regions whose
addresses are disallowed will cause a runtime exception
when they are actually accessed (will not affect or abort
table loading.)
Defined and deployed a new OSL interface,
acpi_os_validate_interface(). This interface allows the host OS
to match the various "optional" interface/behavior strings
for the _OSI predefined control method as appropriate
(with assistance from Bjorn Helgaas.)
Restructured and corrected various problems in the
exception handling code paths within DsCallControlMethod
and DsTerminateControlMethod in dsmethod (with assistance
from Takayoshi Kochi.)
Modified the Linux source converter to ignore quoted string
literals while converting identifiers from mixed to lower
case. This will correct problems with the disassembler
and other areas where such strings must not be modified.
The ACPI_FUNCTION_* macros no longer require quotes around
the function name. This allows the Linux source converter
to convert the names, now that the converter ignores
quoted strings.
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2006-04-22 04:15:00 +07:00
|
|
|
ACPI_FUNCTION_TRACE(ns_one_complete_parse);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-07-23 11:52:24 +07:00
|
|
|
status = acpi_get_table_by_index(table_index, &table);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
return_ACPI_STATUS(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Table must consist of at least a complete header */
|
|
|
|
|
|
|
|
if (table->length < sizeof(struct acpi_table_header)) {
|
|
|
|
return_ACPI_STATUS(AE_BAD_HEADER);
|
|
|
|
}
|
|
|
|
|
|
|
|
aml_start = (u8 *)table + sizeof(struct acpi_table_header);
|
|
|
|
aml_length = table->length - sizeof(struct acpi_table_header);
|
|
|
|
|
2007-02-02 23:48:18 +07:00
|
|
|
status = acpi_tb_get_owner_id(table_index, &owner_id);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
return_ACPI_STATUS(status);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Create and init a Root Node */
|
|
|
|
|
2015-07-23 11:52:24 +07:00
|
|
|
parse_root = acpi_ps_create_scope_op(aml_start);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!parse_root) {
|
2005-08-05 11:44:28 +07:00
|
|
|
return_ACPI_STATUS(AE_NO_MEMORY);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create and initialize a new walk state */
|
|
|
|
|
2007-02-02 23:48:18 +07:00
|
|
|
walk_state = acpi_ds_create_walk_state(owner_id, NULL, NULL, NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!walk_state) {
|
2005-08-05 11:44:28 +07:00
|
|
|
acpi_ps_free_op(parse_root);
|
|
|
|
return_ACPI_STATUS(AE_NO_MEMORY);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2015-07-23 11:52:24 +07:00
|
|
|
status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
|
|
|
|
aml_start, aml_length, NULL,
|
|
|
|
(u8)pass_number);
|
2007-02-02 23:48:18 +07:00
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
acpi_ds_delete_walk_state(walk_state);
|
2015-07-23 11:52:24 +07:00
|
|
|
goto cleanup;
|
2007-02-02 23:48:18 +07:00
|
|
|
}
|
|
|
|
|
2015-07-01 13:44:23 +07:00
|
|
|
/* Found OSDT table, enable the namespace override feature */
|
|
|
|
|
|
|
|
if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_OSDT) &&
|
|
|
|
pass_number == ACPI_IMODE_LOAD_PASS1) {
|
|
|
|
walk_state->namespace_override = TRUE;
|
|
|
|
}
|
|
|
|
|
2008-04-10 22:06:39 +07:00
|
|
|
/* start_node is the default location to load the table */
|
|
|
|
|
|
|
|
if (start_node && start_node != acpi_gbl_root_node) {
|
2008-04-10 22:06:40 +07:00
|
|
|
status =
|
|
|
|
acpi_ds_scope_stack_push(start_node, ACPI_TYPE_METHOD,
|
|
|
|
walk_state);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
acpi_ds_delete_walk_state(walk_state);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-04-10 22:06:39 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Parse the AML */
|
|
|
|
|
2015-12-29 12:54:36 +07:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
|
|
|
|
"*PARSE* pass %u parse\n", pass_number));
|
2005-08-05 11:44:28 +07:00
|
|
|
status = acpi_ps_parse_aml(walk_state);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-10-29 08:30:02 +07:00
|
|
|
cleanup:
|
2005-08-05 11:44:28 +07:00
|
|
|
acpi_ps_delete_parse_tree(parse_root);
|
|
|
|
return_ACPI_STATUS(status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: acpi_ns_parse_table
|
|
|
|
*
|
|
|
|
* PARAMETERS: table_desc - An ACPI table descriptor for table to parse
|
|
|
|
* start_node - Where to enter the table into the namespace
|
|
|
|
*
|
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
acpi_status
|
2008-06-10 12:42:13 +07:00
|
|
|
acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-08-05 11:44:28 +07:00
|
|
|
acpi_status status;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
ACPI: ACPICA 20060421
Removed a device initialization optimization introduced in
20051216 where the _STA method was not run unless an _INI
was also present for the same device. This optimization
could cause problems because it could allow _INI methods
to be run within a not-present device subtree (If a
not-present device had no _INI, _STA would not be run,
the not-present status would not be discovered, and the
children of the device would be incorrectly traversed.)
Implemented a new _STA optimization where namespace
subtrees that do not contain _INI are identified and
ignored during device initialization. Selectively running
_STA can significantly improve boot time on large machines
(with assistance from Len Brown.)
Implemented support for the device initialization case
where the returned _STA flags indicate a device not-present
but functioning. In this case, _INI is not run, but the
device children are examined for presence, as per the
ACPI specification.
Implemented an additional change to the IndexField support
in order to conform to MS behavior. The value written to
the Index Register is not simply a byte offset, it is a
byte offset in units of the access width of the parent
Index Field. (Fiodor Suietov)
Defined and deployed a new OSL interface,
acpi_os_validate_address(). This interface is called during
the creation of all AML operation regions, and allows
the host OS to exert control over what addresses it will
allow the AML code to access. Operation Regions whose
addresses are disallowed will cause a runtime exception
when they are actually accessed (will not affect or abort
table loading.)
Defined and deployed a new OSL interface,
acpi_os_validate_interface(). This interface allows the host OS
to match the various "optional" interface/behavior strings
for the _OSI predefined control method as appropriate
(with assistance from Bjorn Helgaas.)
Restructured and corrected various problems in the
exception handling code paths within DsCallControlMethod
and DsTerminateControlMethod in dsmethod (with assistance
from Takayoshi Kochi.)
Modified the Linux source converter to ignore quoted string
literals while converting identifiers from mixed to lower
case. This will correct problems with the disassembler
and other areas where such strings must not be modified.
The ACPI_FUNCTION_* macros no longer require quotes around
the function name. This allows the Linux source converter
to convert the names, now that the converter ignores
quoted strings.
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2006-04-22 04:15:00 +07:00
|
|
|
ACPI_FUNCTION_TRACE(ns_parse_table);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AML Parse, pass 1
|
|
|
|
*
|
2012-10-31 09:26:55 +07:00
|
|
|
* In this pass, we load most of the namespace. Control methods
|
|
|
|
* are not parsed until later. A parse tree is not created. Instead,
|
|
|
|
* each Parser Op subtree is deleted when it is finished. This saves
|
2005-04-17 05:20:36 +07:00
|
|
|
* a great deal of memory, and allows a small cache of parse objects
|
2012-10-31 09:26:55 +07:00
|
|
|
* to service the entire parse. The second pass of the parse then
|
2007-02-02 23:48:21 +07:00
|
|
|
* performs another complete parse of the AML.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-08-05 11:44:28 +07:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n"));
|
2015-12-29 12:54:36 +07:00
|
|
|
|
2009-03-06 09:05:18 +07:00
|
|
|
status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1,
|
|
|
|
table_index, start_node);
|
2005-08-05 11:44:28 +07:00
|
|
|
if (ACPI_FAILURE(status)) {
|
ACPICA: Namespace: Fix namespace/interpreter lock ordering
There is a lock order issue in acpi_load_tables(). The namespace lock
is held before holding the interpreter lock.
With ACPI_MUTEX_DEBUG enabled in the kernel, this is printed to the
log during boot:
[ 0.885699] ACPI Error: Invalid acquire order: Thread 405884224 owns [ACPI_MTX_Namespace], wants [ACPI_MTX_Interpreter] (20160422/utmutex-263)
[ 0.885881] ACPI Error: Could not acquire AML Interpreter mutex (20160422/exutils-95)
[ 0.893846] ACPI Error: Mutex [0x0] is not acquired, cannot release (20160422/utmutex-326)
[ 0.894019] ACPI Error: Could not release AML Interpreter mutex (20160422/exutils-133)
The issue has been introduced by the following commit:
Commit: 2f38b1b16d9280689e5cfa47a4c50956bf437f0d
ACPICA Commit: bfe03ffcde8ed56a7eae38ea0b188aeb12f9c52e
Subject: ACPICA: Namespace: Fix a regression that MLC support triggers
dead lock in dynamic table loading
Which fixed a deadlock issue for acpi_ns_load_table() in
acpi_ex_add_table() but didn't take care of the lock order in
acpi_ns_load_table() correctly.
Originally (before the above commit), ACPICA used the
namespace/interpreter locks in the following 2 key code
paths:
1. Table loading:
acpi_ns_load_table
L(Namespace)
acpi_ns_parse_table
acpi_ns_one_complete_parse
U(Namespace)
2. Object evaluation:
acpi_ns_evaluate
L(Interpreter)
acpi_ps_execute_method
U(Interpreter)
acpi_ns_load_table
L(Namespace)
U(Namespace)
acpi_ev_initialize_region
L(Namespace)
U(Namespace)
address_space.setup
L(Namespace)
U(Namespace)
address_space.handler
L(Namespace)
U(Namespace)
acpi_os_wait_semaphore
acpi_os_acquire_mutex
acpi_os_sleep
L(Interpreter)
U(Interpreter)
During runtime, while acpi_ns_evaluate is called, the lock order is
always Interpreter -> Namespace.
In turn, the problematic commit acquires the locks in the following
order:
3. Table loading:
acpi_ns_load_table
L(Namespace)
acpi_ns_parse_table
L(Interpreter)
acpi_ns_one_complete_parse
U(Interpreter)
U(Namespace)
To fix the lock order issue, move the interpreter lock to
acpi_ns_load_table() to ensure the lock order correctness:
4. Table loading:
acpi_ns_load_table
L(Interpreter)
L(Namespace)
acpi_ns_parse_table
acpi_ns_one_complete_parse
U(Namespace)
U(Interpreter)
However, this doesn't fix the current design issues related to the
namespace lock. For example, we can notice that in acpi_ns_evaluate(),
outside of acpi_ns_load_table(), the namespace objects may be created
by the named object creation control methods. And the creation of
the method-owned namespace objects are not locked by the namespace
lock. This patch doesn't try to fix such kind of existing issues.
Fixes: 2f38b1b16d92 (ACPICA: Namespace: Fix a regression that MLC support triggers dead lock in dynamic table loading)
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2016-07-05 12:53:12 +07:00
|
|
|
return_ACPI_STATUS(status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AML Parse, pass 2
|
|
|
|
*
|
|
|
|
* In this pass, we resolve forward references and other things
|
|
|
|
* that could not be completed during the first pass.
|
|
|
|
* Another complete parse of the AML is performed, but the
|
|
|
|
* overhead of this is compensated for by the fact that the
|
|
|
|
* parse objects are all cached.
|
|
|
|
*/
|
2005-08-05 11:44:28 +07:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n"));
|
2009-03-06 09:05:18 +07:00
|
|
|
status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2,
|
|
|
|
table_index, start_node);
|
2005-08-05 11:44:28 +07:00
|
|
|
if (ACPI_FAILURE(status)) {
|
ACPICA: Namespace: Fix namespace/interpreter lock ordering
There is a lock order issue in acpi_load_tables(). The namespace lock
is held before holding the interpreter lock.
With ACPI_MUTEX_DEBUG enabled in the kernel, this is printed to the
log during boot:
[ 0.885699] ACPI Error: Invalid acquire order: Thread 405884224 owns [ACPI_MTX_Namespace], wants [ACPI_MTX_Interpreter] (20160422/utmutex-263)
[ 0.885881] ACPI Error: Could not acquire AML Interpreter mutex (20160422/exutils-95)
[ 0.893846] ACPI Error: Mutex [0x0] is not acquired, cannot release (20160422/utmutex-326)
[ 0.894019] ACPI Error: Could not release AML Interpreter mutex (20160422/exutils-133)
The issue has been introduced by the following commit:
Commit: 2f38b1b16d9280689e5cfa47a4c50956bf437f0d
ACPICA Commit: bfe03ffcde8ed56a7eae38ea0b188aeb12f9c52e
Subject: ACPICA: Namespace: Fix a regression that MLC support triggers
dead lock in dynamic table loading
Which fixed a deadlock issue for acpi_ns_load_table() in
acpi_ex_add_table() but didn't take care of the lock order in
acpi_ns_load_table() correctly.
Originally (before the above commit), ACPICA used the
namespace/interpreter locks in the following 2 key code
paths:
1. Table loading:
acpi_ns_load_table
L(Namespace)
acpi_ns_parse_table
acpi_ns_one_complete_parse
U(Namespace)
2. Object evaluation:
acpi_ns_evaluate
L(Interpreter)
acpi_ps_execute_method
U(Interpreter)
acpi_ns_load_table
L(Namespace)
U(Namespace)
acpi_ev_initialize_region
L(Namespace)
U(Namespace)
address_space.setup
L(Namespace)
U(Namespace)
address_space.handler
L(Namespace)
U(Namespace)
acpi_os_wait_semaphore
acpi_os_acquire_mutex
acpi_os_sleep
L(Interpreter)
U(Interpreter)
During runtime, while acpi_ns_evaluate is called, the lock order is
always Interpreter -> Namespace.
In turn, the problematic commit acquires the locks in the following
order:
3. Table loading:
acpi_ns_load_table
L(Namespace)
acpi_ns_parse_table
L(Interpreter)
acpi_ns_one_complete_parse
U(Interpreter)
U(Namespace)
To fix the lock order issue, move the interpreter lock to
acpi_ns_load_table() to ensure the lock order correctness:
4. Table loading:
acpi_ns_load_table
L(Interpreter)
L(Namespace)
acpi_ns_parse_table
acpi_ns_one_complete_parse
U(Namespace)
U(Interpreter)
However, this doesn't fix the current design issues related to the
namespace lock. For example, we can notice that in acpi_ns_evaluate(),
outside of acpi_ns_load_table(), the namespace objects may be created
by the named object creation control methods. And the creation of
the method-owned namespace objects are not locked by the namespace
lock. This patch doesn't try to fix such kind of existing issues.
Fixes: 2f38b1b16d92 (ACPICA: Namespace: Fix a regression that MLC support triggers dead lock in dynamic table loading)
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2016-07-05 12:53:12 +07:00
|
|
|
return_ACPI_STATUS(status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-08-05 11:44:28 +07:00
|
|
|
return_ACPI_STATUS(status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|