Deleted Added
full compact
dsmethod.c (316303) dsmethod.c (322877)
1/******************************************************************************
2 *
3 * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************
115 *
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
133 *
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 *
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
149 *
150 *****************************************************************************/
151
152#include <contrib/dev/acpica/include/acpi.h>
153#include <contrib/dev/acpica/include/accommon.h>
154#include <contrib/dev/acpica/include/acdispat.h>
155#include <contrib/dev/acpica/include/acinterp.h>
156#include <contrib/dev/acpica/include/acnamesp.h>
157#include <contrib/dev/acpica/include/acparser.h>
158#include <contrib/dev/acpica/include/amlcode.h>
159#include <contrib/dev/acpica/include/acdebug.h>
160
161
162#define _COMPONENT ACPI_DISPATCHER
163 ACPI_MODULE_NAME ("dsmethod")
164
165/* Local prototypes */
166
167static ACPI_STATUS
168AcpiDsDetectNamedOpcodes (
169 ACPI_WALK_STATE *WalkState,
170 ACPI_PARSE_OBJECT **OutOp);
171
172static ACPI_STATUS
173AcpiDsCreateMethodMutex (
174 ACPI_OPERAND_OBJECT *MethodDesc);
175
176
177/*******************************************************************************
178 *
179 * FUNCTION: AcpiDsAutoSerializeMethod
180 *
181 * PARAMETERS: Node - Namespace Node of the method
182 * ObjDesc - Method object attached to node
183 *
184 * RETURN: Status
185 *
186 * DESCRIPTION: Parse a control method AML to scan for control methods that
187 * need serialization due to the creation of named objects.
188 *
189 * NOTE: It is a bit of overkill to mark all such methods serialized, since
190 * there is only a problem if the method actually blocks during execution.
191 * A blocking operation is, for example, a Sleep() operation, or any access
192 * to an operation region. However, it is probably not possible to easily
193 * detect whether a method will block or not, so we simply mark all suspicious
194 * methods as serialized.
195 *
196 * NOTE2: This code is essentially a generic routine for parsing a single
197 * control method.
198 *
199 ******************************************************************************/
200
201ACPI_STATUS
202AcpiDsAutoSerializeMethod (
203 ACPI_NAMESPACE_NODE *Node,
204 ACPI_OPERAND_OBJECT *ObjDesc)
205{
206 ACPI_STATUS Status;
207 ACPI_PARSE_OBJECT *Op = NULL;
208 ACPI_WALK_STATE *WalkState;
209
210
211 ACPI_FUNCTION_TRACE_PTR (DsAutoSerializeMethod, Node);
212
213
214 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
215 "Method auto-serialization parse [%4.4s] %p\n",
216 AcpiUtGetNodeName (Node), Node));
217
218 /* Create/Init a root op for the method parse tree */
219
220 Op = AcpiPsAllocOp (AML_METHOD_OP, ObjDesc->Method.AmlStart);
221 if (!Op)
222 {
223 return_ACPI_STATUS (AE_NO_MEMORY);
224 }
225
226 AcpiPsSetName (Op, Node->Name.Integer);
227 Op->Common.Node = Node;
228
229 /* Create and initialize a new walk state */
230
231 WalkState = AcpiDsCreateWalkState (Node->OwnerId, NULL, NULL, NULL);
232 if (!WalkState)
233 {
234 AcpiPsFreeOp (Op);
235 return_ACPI_STATUS (AE_NO_MEMORY);
236 }
237
238 Status = AcpiDsInitAmlWalk (WalkState, Op, Node,
239 ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength, NULL, 0);
240 if (ACPI_FAILURE (Status))
241 {
242 AcpiDsDeleteWalkState (WalkState);
243 AcpiPsFreeOp (Op);
244 return_ACPI_STATUS (Status);
245 }
246
247 WalkState->DescendingCallback = AcpiDsDetectNamedOpcodes;
248
249 /* Parse the method, scan for creation of named objects */
250
251 Status = AcpiPsParseAml (WalkState);
252
253 AcpiPsDeleteParseTree (Op);
254 return_ACPI_STATUS (Status);
255}
256
257
258/*******************************************************************************
259 *
260 * FUNCTION: AcpiDsDetectNamedOpcodes
261 *
262 * PARAMETERS: WalkState - Current state of the parse tree walk
263 * OutOp - Unused, required for parser interface
264 *
265 * RETURN: Status
266 *
267 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
268 * Currently used to detect methods that must be marked serialized
269 * in order to avoid problems with the creation of named objects.
270 *
271 ******************************************************************************/
272
273static ACPI_STATUS
274AcpiDsDetectNamedOpcodes (
275 ACPI_WALK_STATE *WalkState,
276 ACPI_PARSE_OBJECT **OutOp)
277{
278
279 ACPI_FUNCTION_NAME (AcpiDsDetectNamedOpcodes);
280
281
282 /* We are only interested in opcodes that create a new name */
283
284 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_FIELD)))
285 {
286 return (AE_OK);
287 }
288
289 /*
290 * At this point, we know we have a Named object opcode.
291 * Mark the method as serialized. Later code will create a mutex for
292 * this method to enforce serialization.
293 *
294 * Note, ACPI_METHOD_IGNORE_SYNC_LEVEL flag means that we will ignore the
295 * Sync Level mechanism for this method, even though it is now serialized.
296 * Otherwise, there can be conflicts with existing ASL code that actually
297 * uses sync levels.
298 */
299 WalkState->MethodDesc->Method.SyncLevel = 0;
300 WalkState->MethodDesc->Method.InfoFlags |=
301 (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
302
303 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
304 "Method serialized [%4.4s] %p - [%s] (%4.4X)\n",
305 WalkState->MethodNode->Name.Ascii, WalkState->MethodNode,
306 WalkState->OpInfo->Name, WalkState->Opcode));
307
308 /* Abort the parse, no need to examine this method any further */
309
310 return (AE_CTRL_TERMINATE);
311}
312
313
314/*******************************************************************************
315 *
316 * FUNCTION: AcpiDsMethodError
317 *
318 * PARAMETERS: Status - Execution status
319 * WalkState - Current state
320 *
321 * RETURN: Status
322 *
323 * DESCRIPTION: Called on method error. Invoke the global exception handler if
324 * present, dump the method data if the debugger is configured
325 *
326 * Note: Allows the exception handler to change the status code
327 *
328 ******************************************************************************/
329
330ACPI_STATUS
331AcpiDsMethodError (
332 ACPI_STATUS Status,
333 ACPI_WALK_STATE *WalkState)
334{
335 UINT32 AmlOffset;
1/******************************************************************************
2 *
3 * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************
115 *
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
133 *
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 *
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
149 *
150 *****************************************************************************/
151
152#include <contrib/dev/acpica/include/acpi.h>
153#include <contrib/dev/acpica/include/accommon.h>
154#include <contrib/dev/acpica/include/acdispat.h>
155#include <contrib/dev/acpica/include/acinterp.h>
156#include <contrib/dev/acpica/include/acnamesp.h>
157#include <contrib/dev/acpica/include/acparser.h>
158#include <contrib/dev/acpica/include/amlcode.h>
159#include <contrib/dev/acpica/include/acdebug.h>
160
161
162#define _COMPONENT ACPI_DISPATCHER
163 ACPI_MODULE_NAME ("dsmethod")
164
165/* Local prototypes */
166
167static ACPI_STATUS
168AcpiDsDetectNamedOpcodes (
169 ACPI_WALK_STATE *WalkState,
170 ACPI_PARSE_OBJECT **OutOp);
171
172static ACPI_STATUS
173AcpiDsCreateMethodMutex (
174 ACPI_OPERAND_OBJECT *MethodDesc);
175
176
177/*******************************************************************************
178 *
179 * FUNCTION: AcpiDsAutoSerializeMethod
180 *
181 * PARAMETERS: Node - Namespace Node of the method
182 * ObjDesc - Method object attached to node
183 *
184 * RETURN: Status
185 *
186 * DESCRIPTION: Parse a control method AML to scan for control methods that
187 * need serialization due to the creation of named objects.
188 *
189 * NOTE: It is a bit of overkill to mark all such methods serialized, since
190 * there is only a problem if the method actually blocks during execution.
191 * A blocking operation is, for example, a Sleep() operation, or any access
192 * to an operation region. However, it is probably not possible to easily
193 * detect whether a method will block or not, so we simply mark all suspicious
194 * methods as serialized.
195 *
196 * NOTE2: This code is essentially a generic routine for parsing a single
197 * control method.
198 *
199 ******************************************************************************/
200
201ACPI_STATUS
202AcpiDsAutoSerializeMethod (
203 ACPI_NAMESPACE_NODE *Node,
204 ACPI_OPERAND_OBJECT *ObjDesc)
205{
206 ACPI_STATUS Status;
207 ACPI_PARSE_OBJECT *Op = NULL;
208 ACPI_WALK_STATE *WalkState;
209
210
211 ACPI_FUNCTION_TRACE_PTR (DsAutoSerializeMethod, Node);
212
213
214 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
215 "Method auto-serialization parse [%4.4s] %p\n",
216 AcpiUtGetNodeName (Node), Node));
217
218 /* Create/Init a root op for the method parse tree */
219
220 Op = AcpiPsAllocOp (AML_METHOD_OP, ObjDesc->Method.AmlStart);
221 if (!Op)
222 {
223 return_ACPI_STATUS (AE_NO_MEMORY);
224 }
225
226 AcpiPsSetName (Op, Node->Name.Integer);
227 Op->Common.Node = Node;
228
229 /* Create and initialize a new walk state */
230
231 WalkState = AcpiDsCreateWalkState (Node->OwnerId, NULL, NULL, NULL);
232 if (!WalkState)
233 {
234 AcpiPsFreeOp (Op);
235 return_ACPI_STATUS (AE_NO_MEMORY);
236 }
237
238 Status = AcpiDsInitAmlWalk (WalkState, Op, Node,
239 ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength, NULL, 0);
240 if (ACPI_FAILURE (Status))
241 {
242 AcpiDsDeleteWalkState (WalkState);
243 AcpiPsFreeOp (Op);
244 return_ACPI_STATUS (Status);
245 }
246
247 WalkState->DescendingCallback = AcpiDsDetectNamedOpcodes;
248
249 /* Parse the method, scan for creation of named objects */
250
251 Status = AcpiPsParseAml (WalkState);
252
253 AcpiPsDeleteParseTree (Op);
254 return_ACPI_STATUS (Status);
255}
256
257
258/*******************************************************************************
259 *
260 * FUNCTION: AcpiDsDetectNamedOpcodes
261 *
262 * PARAMETERS: WalkState - Current state of the parse tree walk
263 * OutOp - Unused, required for parser interface
264 *
265 * RETURN: Status
266 *
267 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
268 * Currently used to detect methods that must be marked serialized
269 * in order to avoid problems with the creation of named objects.
270 *
271 ******************************************************************************/
272
273static ACPI_STATUS
274AcpiDsDetectNamedOpcodes (
275 ACPI_WALK_STATE *WalkState,
276 ACPI_PARSE_OBJECT **OutOp)
277{
278
279 ACPI_FUNCTION_NAME (AcpiDsDetectNamedOpcodes);
280
281
282 /* We are only interested in opcodes that create a new name */
283
284 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_FIELD)))
285 {
286 return (AE_OK);
287 }
288
289 /*
290 * At this point, we know we have a Named object opcode.
291 * Mark the method as serialized. Later code will create a mutex for
292 * this method to enforce serialization.
293 *
294 * Note, ACPI_METHOD_IGNORE_SYNC_LEVEL flag means that we will ignore the
295 * Sync Level mechanism for this method, even though it is now serialized.
296 * Otherwise, there can be conflicts with existing ASL code that actually
297 * uses sync levels.
298 */
299 WalkState->MethodDesc->Method.SyncLevel = 0;
300 WalkState->MethodDesc->Method.InfoFlags |=
301 (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
302
303 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
304 "Method serialized [%4.4s] %p - [%s] (%4.4X)\n",
305 WalkState->MethodNode->Name.Ascii, WalkState->MethodNode,
306 WalkState->OpInfo->Name, WalkState->Opcode));
307
308 /* Abort the parse, no need to examine this method any further */
309
310 return (AE_CTRL_TERMINATE);
311}
312
313
314/*******************************************************************************
315 *
316 * FUNCTION: AcpiDsMethodError
317 *
318 * PARAMETERS: Status - Execution status
319 * WalkState - Current state
320 *
321 * RETURN: Status
322 *
323 * DESCRIPTION: Called on method error. Invoke the global exception handler if
324 * present, dump the method data if the debugger is configured
325 *
326 * Note: Allows the exception handler to change the status code
327 *
328 ******************************************************************************/
329
330ACPI_STATUS
331AcpiDsMethodError (
332 ACPI_STATUS Status,
333 ACPI_WALK_STATE *WalkState)
334{
335 UINT32 AmlOffset;
336 ACPI_NAME Name = 0;
336
337
338 ACPI_FUNCTION_ENTRY ();
339
340
341 /* Ignore AE_OK and control exception codes */
342
343 if (ACPI_SUCCESS (Status) ||
344 (Status & AE_CODE_CONTROL))
345 {
346 return (Status);
347 }
348
349 /* Invoke the global exception handler */
350
351 if (AcpiGbl_ExceptionHandler)
352 {
353 /* Exit the interpreter, allow handler to execute methods */
354
355 AcpiExExitInterpreter ();
356
357 /*
358 * Handler can map the exception code to anything it wants, including
359 * AE_OK, in which case the executing method will not be aborted.
360 */
361 AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
362 WalkState->ParserState.AmlStart);
363
337
338
339 ACPI_FUNCTION_ENTRY ();
340
341
342 /* Ignore AE_OK and control exception codes */
343
344 if (ACPI_SUCCESS (Status) ||
345 (Status & AE_CODE_CONTROL))
346 {
347 return (Status);
348 }
349
350 /* Invoke the global exception handler */
351
352 if (AcpiGbl_ExceptionHandler)
353 {
354 /* Exit the interpreter, allow handler to execute methods */
355
356 AcpiExExitInterpreter ();
357
358 /*
359 * Handler can map the exception code to anything it wants, including
360 * AE_OK, in which case the executing method will not be aborted.
361 */
362 AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
363 WalkState->ParserState.AmlStart);
364
364 Status = AcpiGbl_ExceptionHandler (Status,
365 WalkState->MethodNode ?
366 WalkState->MethodNode->Name.Integer : 0,
365 if (WalkState->MethodNode)
366 {
367 Name = WalkState->MethodNode->Name.Integer;
368 }
369 else if (WalkState->DeferredNode)
370 {
371 Name = WalkState->DeferredNode->Name.Integer;
372 }
373
374 Status = AcpiGbl_ExceptionHandler (Status, Name,
367 WalkState->Opcode, AmlOffset, NULL);
368 AcpiExEnterInterpreter ();
369 }
370
371 AcpiDsClearImplicitReturn (WalkState);
372
373 if (ACPI_FAILURE (Status))
374 {
375 AcpiDsDumpMethodStack (Status, WalkState, WalkState->Op);
376
377 /* Display method locals/args if debugger is present */
378
379#ifdef ACPI_DEBUGGER
380 AcpiDbDumpMethodInfo (Status, WalkState);
381#endif
382 }
383
384 return (Status);
385}
386
387
388/*******************************************************************************
389 *
390 * FUNCTION: AcpiDsCreateMethodMutex
391 *
392 * PARAMETERS: ObjDesc - The method object
393 *
394 * RETURN: Status
395 *
396 * DESCRIPTION: Create a mutex object for a serialized control method
397 *
398 ******************************************************************************/
399
400static ACPI_STATUS
401AcpiDsCreateMethodMutex (
402 ACPI_OPERAND_OBJECT *MethodDesc)
403{
404 ACPI_OPERAND_OBJECT *MutexDesc;
405 ACPI_STATUS Status;
406
407
408 ACPI_FUNCTION_TRACE (DsCreateMethodMutex);
409
410
411 /* Create the new mutex object */
412
413 MutexDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
414 if (!MutexDesc)
415 {
416 return_ACPI_STATUS (AE_NO_MEMORY);
417 }
418
419 /* Create the actual OS Mutex */
420
421 Status = AcpiOsCreateMutex (&MutexDesc->Mutex.OsMutex);
422 if (ACPI_FAILURE (Status))
423 {
424 AcpiUtDeleteObjectDesc (MutexDesc);
425 return_ACPI_STATUS (Status);
426 }
427
428 MutexDesc->Mutex.SyncLevel = MethodDesc->Method.SyncLevel;
429 MethodDesc->Method.Mutex = MutexDesc;
430 return_ACPI_STATUS (AE_OK);
431}
432
433
434/*******************************************************************************
435 *
436 * FUNCTION: AcpiDsBeginMethodExecution
437 *
438 * PARAMETERS: MethodNode - Node of the method
439 * ObjDesc - The method object
440 * WalkState - current state, NULL if not yet executing
441 * a method.
442 *
443 * RETURN: Status
444 *
445 * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
446 * increments the thread count, and waits at the method semaphore
447 * for clearance to execute.
448 *
449 ******************************************************************************/
450
451ACPI_STATUS
452AcpiDsBeginMethodExecution (
453 ACPI_NAMESPACE_NODE *MethodNode,
454 ACPI_OPERAND_OBJECT *ObjDesc,
455 ACPI_WALK_STATE *WalkState)
456{
457 ACPI_STATUS Status = AE_OK;
458
459
460 ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution, MethodNode);
461
462
463 if (!MethodNode)
464 {
465 return_ACPI_STATUS (AE_NULL_ENTRY);
466 }
467
468 AcpiExStartTraceMethod (MethodNode, ObjDesc, WalkState);
469
470 /* Prevent wraparound of thread count */
471
472 if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX)
473 {
474 ACPI_ERROR ((AE_INFO,
475 "Method reached maximum reentrancy limit (255)"));
476 return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
477 }
478
479 /*
480 * If this method is serialized, we need to acquire the method mutex.
481 */
482 if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
483 {
484 /*
485 * Create a mutex for the method if it is defined to be Serialized
486 * and a mutex has not already been created. We defer the mutex creation
487 * until a method is actually executed, to minimize the object count
488 */
489 if (!ObjDesc->Method.Mutex)
490 {
491 Status = AcpiDsCreateMethodMutex (ObjDesc);
492 if (ACPI_FAILURE (Status))
493 {
494 return_ACPI_STATUS (Status);
495 }
496 }
497
498 /*
499 * The CurrentSyncLevel (per-thread) must be less than or equal to
500 * the sync level of the method. This mechanism provides some
501 * deadlock prevention.
502 *
503 * If the method was auto-serialized, we just ignore the sync level
504 * mechanism, because auto-serialization of methods can interfere
505 * with ASL code that actually uses sync levels.
506 *
507 * Top-level method invocation has no walk state at this point
508 */
509 if (WalkState &&
510 (!(ObjDesc->Method.InfoFlags & ACPI_METHOD_IGNORE_SYNC_LEVEL)) &&
511 (WalkState->Thread->CurrentSyncLevel >
512 ObjDesc->Method.Mutex->Mutex.SyncLevel))
513 {
514 ACPI_ERROR ((AE_INFO,
515 "Cannot acquire Mutex for method [%4.4s]"
516 ", current SyncLevel is too large (%u)",
517 AcpiUtGetNodeName (MethodNode),
518 WalkState->Thread->CurrentSyncLevel));
519
520 return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
521 }
522
523 /*
524 * Obtain the method mutex if necessary. Do not acquire mutex for a
525 * recursive call.
526 */
527 if (!WalkState ||
528 !ObjDesc->Method.Mutex->Mutex.ThreadId ||
529 (WalkState->Thread->ThreadId !=
530 ObjDesc->Method.Mutex->Mutex.ThreadId))
531 {
532 /*
533 * Acquire the method mutex. This releases the interpreter if we
534 * block (and reacquires it before it returns)
535 */
536 Status = AcpiExSystemWaitMutex (
537 ObjDesc->Method.Mutex->Mutex.OsMutex, ACPI_WAIT_FOREVER);
538 if (ACPI_FAILURE (Status))
539 {
540 return_ACPI_STATUS (Status);
541 }
542
543 /* Update the mutex and walk info and save the original SyncLevel */
544
545 if (WalkState)
546 {
547 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
548 WalkState->Thread->CurrentSyncLevel;
549
550 ObjDesc->Method.Mutex->Mutex.ThreadId =
551 WalkState->Thread->ThreadId;
552
553 /*
554 * Update the current SyncLevel only if this is not an auto-
555 * serialized method. In the auto case, we have to ignore
556 * the sync level for the method mutex (created for the
557 * auto-serialization) because we have no idea of what the
558 * sync level should be. Therefore, just ignore it.
559 */
560 if (!(ObjDesc->Method.InfoFlags &
561 ACPI_METHOD_IGNORE_SYNC_LEVEL))
562 {
563 WalkState->Thread->CurrentSyncLevel =
564 ObjDesc->Method.SyncLevel;
565 }
566 }
567 else
568 {
569 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
570 ObjDesc->Method.Mutex->Mutex.SyncLevel;
571
572 ObjDesc->Method.Mutex->Mutex.ThreadId =
573 AcpiOsGetThreadId ();
574 }
575 }
576
577 /* Always increase acquisition depth */
578
579 ObjDesc->Method.Mutex->Mutex.AcquisitionDepth++;
580 }
581
582 /*
583 * Allocate an Owner ID for this method, only if this is the first thread
584 * to begin concurrent execution. We only need one OwnerId, even if the
585 * method is invoked recursively.
586 */
587 if (!ObjDesc->Method.OwnerId)
588 {
589 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
590 if (ACPI_FAILURE (Status))
591 {
592 goto Cleanup;
593 }
594 }
595
596 /*
597 * Increment the method parse tree thread count since it has been
598 * reentered one more time (even if it is the same thread)
599 */
600 ObjDesc->Method.ThreadCount++;
601 AcpiMethodCount++;
602 return_ACPI_STATUS (Status);
603
604
605Cleanup:
606 /* On error, must release the method mutex (if present) */
607
608 if (ObjDesc->Method.Mutex)
609 {
610 AcpiOsReleaseMutex (ObjDesc->Method.Mutex->Mutex.OsMutex);
611 }
612 return_ACPI_STATUS (Status);
613}
614
615
616/*******************************************************************************
617 *
618 * FUNCTION: AcpiDsCallControlMethod
619 *
620 * PARAMETERS: Thread - Info for this thread
621 * ThisWalkState - Current walk state
622 * Op - Current Op to be walked
623 *
624 * RETURN: Status
625 *
626 * DESCRIPTION: Transfer execution to a called control method
627 *
628 ******************************************************************************/
629
630ACPI_STATUS
631AcpiDsCallControlMethod (
632 ACPI_THREAD_STATE *Thread,
633 ACPI_WALK_STATE *ThisWalkState,
634 ACPI_PARSE_OBJECT *Op)
635{
636 ACPI_STATUS Status;
637 ACPI_NAMESPACE_NODE *MethodNode;
638 ACPI_WALK_STATE *NextWalkState = NULL;
639 ACPI_OPERAND_OBJECT *ObjDesc;
640 ACPI_EVALUATE_INFO *Info;
641 UINT32 i;
642
643
644 ACPI_FUNCTION_TRACE_PTR (DsCallControlMethod, ThisWalkState);
645
646 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
647 "Calling method %p, currentstate=%p\n",
648 ThisWalkState->PrevOp, ThisWalkState));
649
650 /*
651 * Get the namespace entry for the control method we are about to call
652 */
653 MethodNode = ThisWalkState->MethodCallNode;
654 if (!MethodNode)
655 {
656 return_ACPI_STATUS (AE_NULL_ENTRY);
657 }
658
659 ObjDesc = AcpiNsGetAttachedObject (MethodNode);
660 if (!ObjDesc)
661 {
662 return_ACPI_STATUS (AE_NULL_OBJECT);
663 }
664
665 /* Init for new method, possibly wait on method mutex */
666
667 Status = AcpiDsBeginMethodExecution (
668 MethodNode, ObjDesc, ThisWalkState);
669 if (ACPI_FAILURE (Status))
670 {
671 return_ACPI_STATUS (Status);
672 }
673
674 /* Begin method parse/execution. Create a new walk state */
675
676 NextWalkState = AcpiDsCreateWalkState (
677 ObjDesc->Method.OwnerId, NULL, ObjDesc, Thread);
678 if (!NextWalkState)
679 {
680 Status = AE_NO_MEMORY;
681 goto Cleanup;
682 }
683
684 /*
685 * The resolved arguments were put on the previous walk state's operand
686 * stack. Operands on the previous walk state stack always
687 * start at index 0. Also, null terminate the list of arguments
688 */
689 ThisWalkState->Operands [ThisWalkState->NumOperands] = NULL;
690
691 /*
692 * Allocate and initialize the evaluation information block
693 * TBD: this is somewhat inefficient, should change interface to
694 * DsInitAmlWalk. For now, keeps this struct off the CPU stack
695 */
696 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
697 if (!Info)
698 {
699 Status = AE_NO_MEMORY;
700 goto Cleanup;
701 }
702
703 Info->Parameters = &ThisWalkState->Operands[0];
704
705 Status = AcpiDsInitAmlWalk (NextWalkState, NULL, MethodNode,
706 ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength,
707 Info, ACPI_IMODE_EXECUTE);
708
709 ACPI_FREE (Info);
710 if (ACPI_FAILURE (Status))
711 {
712 goto Cleanup;
713 }
714
715 /*
716 * Delete the operands on the previous walkstate operand stack
717 * (they were copied to new objects)
718 */
719 for (i = 0; i < ObjDesc->Method.ParamCount; i++)
720 {
721 AcpiUtRemoveReference (ThisWalkState->Operands [i]);
722 ThisWalkState->Operands [i] = NULL;
723 }
724
725 /* Clear the operand stack */
726
727 ThisWalkState->NumOperands = 0;
728
729 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
730 "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
731 MethodNode->Name.Ascii, NextWalkState));
732
733 /* Invoke an internal method if necessary */
734
735 if (ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
736 {
737 Status = ObjDesc->Method.Dispatch.Implementation (NextWalkState);
738 if (Status == AE_OK)
739 {
740 Status = AE_CTRL_TERMINATE;
741 }
742 }
743
744 return_ACPI_STATUS (Status);
745
746
747Cleanup:
748
749 /* On error, we must terminate the method properly */
750
751 AcpiDsTerminateControlMethod (ObjDesc, NextWalkState);
752 AcpiDsDeleteWalkState (NextWalkState);
753
754 return_ACPI_STATUS (Status);
755}
756
757
758/*******************************************************************************
759 *
760 * FUNCTION: AcpiDsRestartControlMethod
761 *
762 * PARAMETERS: WalkState - State for preempted method (caller)
763 * ReturnDesc - Return value from the called method
764 *
765 * RETURN: Status
766 *
767 * DESCRIPTION: Restart a method that was preempted by another (nested) method
768 * invocation. Handle the return value (if any) from the callee.
769 *
770 ******************************************************************************/
771
772ACPI_STATUS
773AcpiDsRestartControlMethod (
774 ACPI_WALK_STATE *WalkState,
775 ACPI_OPERAND_OBJECT *ReturnDesc)
776{
777 ACPI_STATUS Status;
778 int SameAsImplicitReturn;
779
780
781 ACPI_FUNCTION_TRACE_PTR (DsRestartControlMethod, WalkState);
782
783
784 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
785 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
786 AcpiUtGetNodeName (WalkState->MethodNode),
787 WalkState->MethodCallOp, ReturnDesc));
788
789 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
790 " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
791 WalkState->ReturnUsed,
792 WalkState->Results, WalkState));
793
794 /* Did the called method return a value? */
795
796 if (ReturnDesc)
797 {
798 /* Is the implicit return object the same as the return desc? */
799
800 SameAsImplicitReturn = (WalkState->ImplicitReturnObj == ReturnDesc);
801
802 /* Are we actually going to use the return value? */
803
804 if (WalkState->ReturnUsed)
805 {
806 /* Save the return value from the previous method */
807
808 Status = AcpiDsResultPush (ReturnDesc, WalkState);
809 if (ACPI_FAILURE (Status))
810 {
811 AcpiUtRemoveReference (ReturnDesc);
812 return_ACPI_STATUS (Status);
813 }
814
815 /*
816 * Save as THIS method's return value in case it is returned
817 * immediately to yet another method
818 */
819 WalkState->ReturnDesc = ReturnDesc;
820 }
821
822 /*
823 * The following code is the optional support for the so-called
824 * "implicit return". Some AML code assumes that the last value of the
825 * method is "implicitly" returned to the caller, in the absence of an
826 * explicit return value.
827 *
828 * Just save the last result of the method as the return value.
829 *
830 * NOTE: this is optional because the ASL language does not actually
831 * support this behavior.
832 */
833 else if (!AcpiDsDoImplicitReturn (ReturnDesc, WalkState, FALSE) ||
834 SameAsImplicitReturn)
835 {
836 /*
837 * Delete the return value if it will not be used by the
838 * calling method or remove one reference if the explicit return
839 * is the same as the implicit return value.
840 */
841 AcpiUtRemoveReference (ReturnDesc);
842 }
843 }
844
845 return_ACPI_STATUS (AE_OK);
846}
847
848
849/*******************************************************************************
850 *
851 * FUNCTION: AcpiDsTerminateControlMethod
852 *
853 * PARAMETERS: MethodDesc - Method object
854 * WalkState - State associated with the method
855 *
856 * RETURN: None
857 *
858 * DESCRIPTION: Terminate a control method. Delete everything that the method
859 * created, delete all locals and arguments, and delete the parse
860 * tree if requested.
861 *
862 * MUTEX: Interpreter is locked
863 *
864 ******************************************************************************/
865
866void
867AcpiDsTerminateControlMethod (
868 ACPI_OPERAND_OBJECT *MethodDesc,
869 ACPI_WALK_STATE *WalkState)
870{
871
872 ACPI_FUNCTION_TRACE_PTR (DsTerminateControlMethod, WalkState);
873
874
875 /* MethodDesc is required, WalkState is optional */
876
877 if (!MethodDesc)
878 {
879 return_VOID;
880 }
881
882 if (WalkState)
883 {
884 /* Delete all arguments and locals */
885
886 AcpiDsMethodDataDeleteAll (WalkState);
887
888 /*
889 * Delete any namespace objects created anywhere within the
890 * namespace by the execution of this method. Unless:
891 * 1) This method is a module-level executable code method, in which
892 * case we want make the objects permanent.
893 * 2) There are other threads executing the method, in which case we
894 * will wait until the last thread has completed.
895 */
896 if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) &&
897 (MethodDesc->Method.ThreadCount == 1))
898 {
899 /* Delete any direct children of (created by) this method */
900
901 (void) AcpiExExitInterpreter ();
902 AcpiNsDeleteNamespaceSubtree (WalkState->MethodNode);
903 (void) AcpiExEnterInterpreter ();
904
905 /*
906 * Delete any objects that were created by this method
907 * elsewhere in the namespace (if any were created).
908 * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
909 * deletion such that we don't have to perform an entire
910 * namespace walk for every control method execution.
911 */
912 if (MethodDesc->Method.InfoFlags & ACPI_METHOD_MODIFIED_NAMESPACE)
913 {
914 (void) AcpiExExitInterpreter ();
915 AcpiNsDeleteNamespaceByOwner (MethodDesc->Method.OwnerId);
916 (void) AcpiExEnterInterpreter ();
917 MethodDesc->Method.InfoFlags &=
918 ~ACPI_METHOD_MODIFIED_NAMESPACE;
919 }
920 }
921
922 /*
923 * If method is serialized, release the mutex and restore the
924 * current sync level for this thread
925 */
926 if (MethodDesc->Method.Mutex)
927 {
928 /* Acquisition Depth handles recursive calls */
929
930 MethodDesc->Method.Mutex->Mutex.AcquisitionDepth--;
931 if (!MethodDesc->Method.Mutex->Mutex.AcquisitionDepth)
932 {
933 WalkState->Thread->CurrentSyncLevel =
934 MethodDesc->Method.Mutex->Mutex.OriginalSyncLevel;
935
936 AcpiOsReleaseMutex (
937 MethodDesc->Method.Mutex->Mutex.OsMutex);
938 MethodDesc->Method.Mutex->Mutex.ThreadId = 0;
939 }
940 }
941 }
942
943 /* Decrement the thread count on the method */
944
945 if (MethodDesc->Method.ThreadCount)
946 {
947 MethodDesc->Method.ThreadCount--;
948 }
949 else
950 {
951 ACPI_ERROR ((AE_INFO,
952 "Invalid zero thread count in method"));
953 }
954
955 /* Are there any other threads currently executing this method? */
956
957 if (MethodDesc->Method.ThreadCount)
958 {
959 /*
960 * Additional threads. Do not release the OwnerId in this case,
961 * we immediately reuse it for the next thread executing this method
962 */
963 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
964 "*** Completed execution of one thread, %u threads remaining\n",
965 MethodDesc->Method.ThreadCount));
966 }
967 else
968 {
969 /* This is the only executing thread for this method */
970
971 /*
972 * Support to dynamically change a method from NotSerialized to
973 * Serialized if it appears that the method is incorrectly written and
974 * does not support multiple thread execution. The best example of this
975 * is if such a method creates namespace objects and blocks. A second
976 * thread will fail with an AE_ALREADY_EXISTS exception.
977 *
978 * This code is here because we must wait until the last thread exits
979 * before marking the method as serialized.
980 */
981 if (MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED_PENDING)
982 {
983 if (WalkState)
984 {
985 ACPI_INFO ((
986 "Marking method %4.4s as Serialized "
987 "because of AE_ALREADY_EXISTS error",
988 WalkState->MethodNode->Name.Ascii));
989 }
990
991 /*
992 * Method tried to create an object twice and was marked as
993 * "pending serialized". The probable cause is that the method
994 * cannot handle reentrancy.
995 *
996 * The method was created as NotSerialized, but it tried to create
997 * a named object and then blocked, causing the second thread
998 * entrance to begin and then fail. Workaround this problem by
999 * marking the method permanently as Serialized when the last
1000 * thread exits here.
1001 */
1002 MethodDesc->Method.InfoFlags &=
1003 ~ACPI_METHOD_SERIALIZED_PENDING;
1004
1005 MethodDesc->Method.InfoFlags |=
1006 (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
1007 MethodDesc->Method.SyncLevel = 0;
1008 }
1009
1010 /* No more threads, we can free the OwnerId */
1011
1012 if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL))
1013 {
1014 AcpiUtReleaseOwnerId (&MethodDesc->Method.OwnerId);
1015 }
1016 }
1017
1018 AcpiExStopTraceMethod ((ACPI_NAMESPACE_NODE *) MethodDesc->Method.Node,
1019 MethodDesc, WalkState);
1020
1021 return_VOID;
1022}
375 WalkState->Opcode, AmlOffset, NULL);
376 AcpiExEnterInterpreter ();
377 }
378
379 AcpiDsClearImplicitReturn (WalkState);
380
381 if (ACPI_FAILURE (Status))
382 {
383 AcpiDsDumpMethodStack (Status, WalkState, WalkState->Op);
384
385 /* Display method locals/args if debugger is present */
386
387#ifdef ACPI_DEBUGGER
388 AcpiDbDumpMethodInfo (Status, WalkState);
389#endif
390 }
391
392 return (Status);
393}
394
395
396/*******************************************************************************
397 *
398 * FUNCTION: AcpiDsCreateMethodMutex
399 *
400 * PARAMETERS: ObjDesc - The method object
401 *
402 * RETURN: Status
403 *
404 * DESCRIPTION: Create a mutex object for a serialized control method
405 *
406 ******************************************************************************/
407
408static ACPI_STATUS
409AcpiDsCreateMethodMutex (
410 ACPI_OPERAND_OBJECT *MethodDesc)
411{
412 ACPI_OPERAND_OBJECT *MutexDesc;
413 ACPI_STATUS Status;
414
415
416 ACPI_FUNCTION_TRACE (DsCreateMethodMutex);
417
418
419 /* Create the new mutex object */
420
421 MutexDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
422 if (!MutexDesc)
423 {
424 return_ACPI_STATUS (AE_NO_MEMORY);
425 }
426
427 /* Create the actual OS Mutex */
428
429 Status = AcpiOsCreateMutex (&MutexDesc->Mutex.OsMutex);
430 if (ACPI_FAILURE (Status))
431 {
432 AcpiUtDeleteObjectDesc (MutexDesc);
433 return_ACPI_STATUS (Status);
434 }
435
436 MutexDesc->Mutex.SyncLevel = MethodDesc->Method.SyncLevel;
437 MethodDesc->Method.Mutex = MutexDesc;
438 return_ACPI_STATUS (AE_OK);
439}
440
441
442/*******************************************************************************
443 *
444 * FUNCTION: AcpiDsBeginMethodExecution
445 *
446 * PARAMETERS: MethodNode - Node of the method
447 * ObjDesc - The method object
448 * WalkState - current state, NULL if not yet executing
449 * a method.
450 *
451 * RETURN: Status
452 *
453 * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
454 * increments the thread count, and waits at the method semaphore
455 * for clearance to execute.
456 *
457 ******************************************************************************/
458
459ACPI_STATUS
460AcpiDsBeginMethodExecution (
461 ACPI_NAMESPACE_NODE *MethodNode,
462 ACPI_OPERAND_OBJECT *ObjDesc,
463 ACPI_WALK_STATE *WalkState)
464{
465 ACPI_STATUS Status = AE_OK;
466
467
468 ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution, MethodNode);
469
470
471 if (!MethodNode)
472 {
473 return_ACPI_STATUS (AE_NULL_ENTRY);
474 }
475
476 AcpiExStartTraceMethod (MethodNode, ObjDesc, WalkState);
477
478 /* Prevent wraparound of thread count */
479
480 if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX)
481 {
482 ACPI_ERROR ((AE_INFO,
483 "Method reached maximum reentrancy limit (255)"));
484 return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
485 }
486
487 /*
488 * If this method is serialized, we need to acquire the method mutex.
489 */
490 if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
491 {
492 /*
493 * Create a mutex for the method if it is defined to be Serialized
494 * and a mutex has not already been created. We defer the mutex creation
495 * until a method is actually executed, to minimize the object count
496 */
497 if (!ObjDesc->Method.Mutex)
498 {
499 Status = AcpiDsCreateMethodMutex (ObjDesc);
500 if (ACPI_FAILURE (Status))
501 {
502 return_ACPI_STATUS (Status);
503 }
504 }
505
506 /*
507 * The CurrentSyncLevel (per-thread) must be less than or equal to
508 * the sync level of the method. This mechanism provides some
509 * deadlock prevention.
510 *
511 * If the method was auto-serialized, we just ignore the sync level
512 * mechanism, because auto-serialization of methods can interfere
513 * with ASL code that actually uses sync levels.
514 *
515 * Top-level method invocation has no walk state at this point
516 */
517 if (WalkState &&
518 (!(ObjDesc->Method.InfoFlags & ACPI_METHOD_IGNORE_SYNC_LEVEL)) &&
519 (WalkState->Thread->CurrentSyncLevel >
520 ObjDesc->Method.Mutex->Mutex.SyncLevel))
521 {
522 ACPI_ERROR ((AE_INFO,
523 "Cannot acquire Mutex for method [%4.4s]"
524 ", current SyncLevel is too large (%u)",
525 AcpiUtGetNodeName (MethodNode),
526 WalkState->Thread->CurrentSyncLevel));
527
528 return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
529 }
530
531 /*
532 * Obtain the method mutex if necessary. Do not acquire mutex for a
533 * recursive call.
534 */
535 if (!WalkState ||
536 !ObjDesc->Method.Mutex->Mutex.ThreadId ||
537 (WalkState->Thread->ThreadId !=
538 ObjDesc->Method.Mutex->Mutex.ThreadId))
539 {
540 /*
541 * Acquire the method mutex. This releases the interpreter if we
542 * block (and reacquires it before it returns)
543 */
544 Status = AcpiExSystemWaitMutex (
545 ObjDesc->Method.Mutex->Mutex.OsMutex, ACPI_WAIT_FOREVER);
546 if (ACPI_FAILURE (Status))
547 {
548 return_ACPI_STATUS (Status);
549 }
550
551 /* Update the mutex and walk info and save the original SyncLevel */
552
553 if (WalkState)
554 {
555 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
556 WalkState->Thread->CurrentSyncLevel;
557
558 ObjDesc->Method.Mutex->Mutex.ThreadId =
559 WalkState->Thread->ThreadId;
560
561 /*
562 * Update the current SyncLevel only if this is not an auto-
563 * serialized method. In the auto case, we have to ignore
564 * the sync level for the method mutex (created for the
565 * auto-serialization) because we have no idea of what the
566 * sync level should be. Therefore, just ignore it.
567 */
568 if (!(ObjDesc->Method.InfoFlags &
569 ACPI_METHOD_IGNORE_SYNC_LEVEL))
570 {
571 WalkState->Thread->CurrentSyncLevel =
572 ObjDesc->Method.SyncLevel;
573 }
574 }
575 else
576 {
577 ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
578 ObjDesc->Method.Mutex->Mutex.SyncLevel;
579
580 ObjDesc->Method.Mutex->Mutex.ThreadId =
581 AcpiOsGetThreadId ();
582 }
583 }
584
585 /* Always increase acquisition depth */
586
587 ObjDesc->Method.Mutex->Mutex.AcquisitionDepth++;
588 }
589
590 /*
591 * Allocate an Owner ID for this method, only if this is the first thread
592 * to begin concurrent execution. We only need one OwnerId, even if the
593 * method is invoked recursively.
594 */
595 if (!ObjDesc->Method.OwnerId)
596 {
597 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
598 if (ACPI_FAILURE (Status))
599 {
600 goto Cleanup;
601 }
602 }
603
604 /*
605 * Increment the method parse tree thread count since it has been
606 * reentered one more time (even if it is the same thread)
607 */
608 ObjDesc->Method.ThreadCount++;
609 AcpiMethodCount++;
610 return_ACPI_STATUS (Status);
611
612
613Cleanup:
614 /* On error, must release the method mutex (if present) */
615
616 if (ObjDesc->Method.Mutex)
617 {
618 AcpiOsReleaseMutex (ObjDesc->Method.Mutex->Mutex.OsMutex);
619 }
620 return_ACPI_STATUS (Status);
621}
622
623
624/*******************************************************************************
625 *
626 * FUNCTION: AcpiDsCallControlMethod
627 *
628 * PARAMETERS: Thread - Info for this thread
629 * ThisWalkState - Current walk state
630 * Op - Current Op to be walked
631 *
632 * RETURN: Status
633 *
634 * DESCRIPTION: Transfer execution to a called control method
635 *
636 ******************************************************************************/
637
638ACPI_STATUS
639AcpiDsCallControlMethod (
640 ACPI_THREAD_STATE *Thread,
641 ACPI_WALK_STATE *ThisWalkState,
642 ACPI_PARSE_OBJECT *Op)
643{
644 ACPI_STATUS Status;
645 ACPI_NAMESPACE_NODE *MethodNode;
646 ACPI_WALK_STATE *NextWalkState = NULL;
647 ACPI_OPERAND_OBJECT *ObjDesc;
648 ACPI_EVALUATE_INFO *Info;
649 UINT32 i;
650
651
652 ACPI_FUNCTION_TRACE_PTR (DsCallControlMethod, ThisWalkState);
653
654 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
655 "Calling method %p, currentstate=%p\n",
656 ThisWalkState->PrevOp, ThisWalkState));
657
658 /*
659 * Get the namespace entry for the control method we are about to call
660 */
661 MethodNode = ThisWalkState->MethodCallNode;
662 if (!MethodNode)
663 {
664 return_ACPI_STATUS (AE_NULL_ENTRY);
665 }
666
667 ObjDesc = AcpiNsGetAttachedObject (MethodNode);
668 if (!ObjDesc)
669 {
670 return_ACPI_STATUS (AE_NULL_OBJECT);
671 }
672
673 /* Init for new method, possibly wait on method mutex */
674
675 Status = AcpiDsBeginMethodExecution (
676 MethodNode, ObjDesc, ThisWalkState);
677 if (ACPI_FAILURE (Status))
678 {
679 return_ACPI_STATUS (Status);
680 }
681
682 /* Begin method parse/execution. Create a new walk state */
683
684 NextWalkState = AcpiDsCreateWalkState (
685 ObjDesc->Method.OwnerId, NULL, ObjDesc, Thread);
686 if (!NextWalkState)
687 {
688 Status = AE_NO_MEMORY;
689 goto Cleanup;
690 }
691
692 /*
693 * The resolved arguments were put on the previous walk state's operand
694 * stack. Operands on the previous walk state stack always
695 * start at index 0. Also, null terminate the list of arguments
696 */
697 ThisWalkState->Operands [ThisWalkState->NumOperands] = NULL;
698
699 /*
700 * Allocate and initialize the evaluation information block
701 * TBD: this is somewhat inefficient, should change interface to
702 * DsInitAmlWalk. For now, keeps this struct off the CPU stack
703 */
704 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
705 if (!Info)
706 {
707 Status = AE_NO_MEMORY;
708 goto Cleanup;
709 }
710
711 Info->Parameters = &ThisWalkState->Operands[0];
712
713 Status = AcpiDsInitAmlWalk (NextWalkState, NULL, MethodNode,
714 ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength,
715 Info, ACPI_IMODE_EXECUTE);
716
717 ACPI_FREE (Info);
718 if (ACPI_FAILURE (Status))
719 {
720 goto Cleanup;
721 }
722
723 /*
724 * Delete the operands on the previous walkstate operand stack
725 * (they were copied to new objects)
726 */
727 for (i = 0; i < ObjDesc->Method.ParamCount; i++)
728 {
729 AcpiUtRemoveReference (ThisWalkState->Operands [i]);
730 ThisWalkState->Operands [i] = NULL;
731 }
732
733 /* Clear the operand stack */
734
735 ThisWalkState->NumOperands = 0;
736
737 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
738 "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
739 MethodNode->Name.Ascii, NextWalkState));
740
741 /* Invoke an internal method if necessary */
742
743 if (ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
744 {
745 Status = ObjDesc->Method.Dispatch.Implementation (NextWalkState);
746 if (Status == AE_OK)
747 {
748 Status = AE_CTRL_TERMINATE;
749 }
750 }
751
752 return_ACPI_STATUS (Status);
753
754
755Cleanup:
756
757 /* On error, we must terminate the method properly */
758
759 AcpiDsTerminateControlMethod (ObjDesc, NextWalkState);
760 AcpiDsDeleteWalkState (NextWalkState);
761
762 return_ACPI_STATUS (Status);
763}
764
765
766/*******************************************************************************
767 *
768 * FUNCTION: AcpiDsRestartControlMethod
769 *
770 * PARAMETERS: WalkState - State for preempted method (caller)
771 * ReturnDesc - Return value from the called method
772 *
773 * RETURN: Status
774 *
775 * DESCRIPTION: Restart a method that was preempted by another (nested) method
776 * invocation. Handle the return value (if any) from the callee.
777 *
778 ******************************************************************************/
779
780ACPI_STATUS
781AcpiDsRestartControlMethod (
782 ACPI_WALK_STATE *WalkState,
783 ACPI_OPERAND_OBJECT *ReturnDesc)
784{
785 ACPI_STATUS Status;
786 int SameAsImplicitReturn;
787
788
789 ACPI_FUNCTION_TRACE_PTR (DsRestartControlMethod, WalkState);
790
791
792 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
793 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
794 AcpiUtGetNodeName (WalkState->MethodNode),
795 WalkState->MethodCallOp, ReturnDesc));
796
797 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
798 " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
799 WalkState->ReturnUsed,
800 WalkState->Results, WalkState));
801
802 /* Did the called method return a value? */
803
804 if (ReturnDesc)
805 {
806 /* Is the implicit return object the same as the return desc? */
807
808 SameAsImplicitReturn = (WalkState->ImplicitReturnObj == ReturnDesc);
809
810 /* Are we actually going to use the return value? */
811
812 if (WalkState->ReturnUsed)
813 {
814 /* Save the return value from the previous method */
815
816 Status = AcpiDsResultPush (ReturnDesc, WalkState);
817 if (ACPI_FAILURE (Status))
818 {
819 AcpiUtRemoveReference (ReturnDesc);
820 return_ACPI_STATUS (Status);
821 }
822
823 /*
824 * Save as THIS method's return value in case it is returned
825 * immediately to yet another method
826 */
827 WalkState->ReturnDesc = ReturnDesc;
828 }
829
830 /*
831 * The following code is the optional support for the so-called
832 * "implicit return". Some AML code assumes that the last value of the
833 * method is "implicitly" returned to the caller, in the absence of an
834 * explicit return value.
835 *
836 * Just save the last result of the method as the return value.
837 *
838 * NOTE: this is optional because the ASL language does not actually
839 * support this behavior.
840 */
841 else if (!AcpiDsDoImplicitReturn (ReturnDesc, WalkState, FALSE) ||
842 SameAsImplicitReturn)
843 {
844 /*
845 * Delete the return value if it will not be used by the
846 * calling method or remove one reference if the explicit return
847 * is the same as the implicit return value.
848 */
849 AcpiUtRemoveReference (ReturnDesc);
850 }
851 }
852
853 return_ACPI_STATUS (AE_OK);
854}
855
856
857/*******************************************************************************
858 *
859 * FUNCTION: AcpiDsTerminateControlMethod
860 *
861 * PARAMETERS: MethodDesc - Method object
862 * WalkState - State associated with the method
863 *
864 * RETURN: None
865 *
866 * DESCRIPTION: Terminate a control method. Delete everything that the method
867 * created, delete all locals and arguments, and delete the parse
868 * tree if requested.
869 *
870 * MUTEX: Interpreter is locked
871 *
872 ******************************************************************************/
873
874void
875AcpiDsTerminateControlMethod (
876 ACPI_OPERAND_OBJECT *MethodDesc,
877 ACPI_WALK_STATE *WalkState)
878{
879
880 ACPI_FUNCTION_TRACE_PTR (DsTerminateControlMethod, WalkState);
881
882
883 /* MethodDesc is required, WalkState is optional */
884
885 if (!MethodDesc)
886 {
887 return_VOID;
888 }
889
890 if (WalkState)
891 {
892 /* Delete all arguments and locals */
893
894 AcpiDsMethodDataDeleteAll (WalkState);
895
896 /*
897 * Delete any namespace objects created anywhere within the
898 * namespace by the execution of this method. Unless:
899 * 1) This method is a module-level executable code method, in which
900 * case we want make the objects permanent.
901 * 2) There are other threads executing the method, in which case we
902 * will wait until the last thread has completed.
903 */
904 if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) &&
905 (MethodDesc->Method.ThreadCount == 1))
906 {
907 /* Delete any direct children of (created by) this method */
908
909 (void) AcpiExExitInterpreter ();
910 AcpiNsDeleteNamespaceSubtree (WalkState->MethodNode);
911 (void) AcpiExEnterInterpreter ();
912
913 /*
914 * Delete any objects that were created by this method
915 * elsewhere in the namespace (if any were created).
916 * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
917 * deletion such that we don't have to perform an entire
918 * namespace walk for every control method execution.
919 */
920 if (MethodDesc->Method.InfoFlags & ACPI_METHOD_MODIFIED_NAMESPACE)
921 {
922 (void) AcpiExExitInterpreter ();
923 AcpiNsDeleteNamespaceByOwner (MethodDesc->Method.OwnerId);
924 (void) AcpiExEnterInterpreter ();
925 MethodDesc->Method.InfoFlags &=
926 ~ACPI_METHOD_MODIFIED_NAMESPACE;
927 }
928 }
929
930 /*
931 * If method is serialized, release the mutex and restore the
932 * current sync level for this thread
933 */
934 if (MethodDesc->Method.Mutex)
935 {
936 /* Acquisition Depth handles recursive calls */
937
938 MethodDesc->Method.Mutex->Mutex.AcquisitionDepth--;
939 if (!MethodDesc->Method.Mutex->Mutex.AcquisitionDepth)
940 {
941 WalkState->Thread->CurrentSyncLevel =
942 MethodDesc->Method.Mutex->Mutex.OriginalSyncLevel;
943
944 AcpiOsReleaseMutex (
945 MethodDesc->Method.Mutex->Mutex.OsMutex);
946 MethodDesc->Method.Mutex->Mutex.ThreadId = 0;
947 }
948 }
949 }
950
951 /* Decrement the thread count on the method */
952
953 if (MethodDesc->Method.ThreadCount)
954 {
955 MethodDesc->Method.ThreadCount--;
956 }
957 else
958 {
959 ACPI_ERROR ((AE_INFO,
960 "Invalid zero thread count in method"));
961 }
962
963 /* Are there any other threads currently executing this method? */
964
965 if (MethodDesc->Method.ThreadCount)
966 {
967 /*
968 * Additional threads. Do not release the OwnerId in this case,
969 * we immediately reuse it for the next thread executing this method
970 */
971 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
972 "*** Completed execution of one thread, %u threads remaining\n",
973 MethodDesc->Method.ThreadCount));
974 }
975 else
976 {
977 /* This is the only executing thread for this method */
978
979 /*
980 * Support to dynamically change a method from NotSerialized to
981 * Serialized if it appears that the method is incorrectly written and
982 * does not support multiple thread execution. The best example of this
983 * is if such a method creates namespace objects and blocks. A second
984 * thread will fail with an AE_ALREADY_EXISTS exception.
985 *
986 * This code is here because we must wait until the last thread exits
987 * before marking the method as serialized.
988 */
989 if (MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED_PENDING)
990 {
991 if (WalkState)
992 {
993 ACPI_INFO ((
994 "Marking method %4.4s as Serialized "
995 "because of AE_ALREADY_EXISTS error",
996 WalkState->MethodNode->Name.Ascii));
997 }
998
999 /*
1000 * Method tried to create an object twice and was marked as
1001 * "pending serialized". The probable cause is that the method
1002 * cannot handle reentrancy.
1003 *
1004 * The method was created as NotSerialized, but it tried to create
1005 * a named object and then blocked, causing the second thread
1006 * entrance to begin and then fail. Workaround this problem by
1007 * marking the method permanently as Serialized when the last
1008 * thread exits here.
1009 */
1010 MethodDesc->Method.InfoFlags &=
1011 ~ACPI_METHOD_SERIALIZED_PENDING;
1012
1013 MethodDesc->Method.InfoFlags |=
1014 (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
1015 MethodDesc->Method.SyncLevel = 0;
1016 }
1017
1018 /* No more threads, we can free the OwnerId */
1019
1020 if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL))
1021 {
1022 AcpiUtReleaseOwnerId (&MethodDesc->Method.OwnerId);
1023 }
1024 }
1025
1026 AcpiExStopTraceMethod ((ACPI_NAMESPACE_NODE *) MethodDesc->Method.Node,
1027 MethodDesc, WalkState);
1028
1029 return_VOID;
1030}