1 /******************************************************************************
3 * Module Name: psxface - Parser external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
53 #define _COMPONENT ACPI_PARSER
54 ACPI_MODULE_NAME ("psxface")
56 /* Local Prototypes */
59 AcpiPsUpdateParameterList (
60 ACPI_EVALUATE_INFO
*Info
,
64 /*******************************************************************************
66 * FUNCTION: AcpiDebugTrace
68 * PARAMETERS: MethodName - Valid ACPI name string
69 * DebugLevel - Optional level mask. 0 to use default
70 * DebugLayer - Optional layer mask. 0 to use default
71 * Flags - bit 1: one shot(1) or persistent(0)
75 * DESCRIPTION: External interface to enable debug tracing during control
78 ******************************************************************************/
90 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
91 if (ACPI_FAILURE (Status
))
96 AcpiGbl_TraceMethodName
= Name
;
97 AcpiGbl_TraceFlags
= Flags
;
98 AcpiGbl_TraceDbgLevel
= DebugLevel
;
99 AcpiGbl_TraceDbgLayer
= DebugLayer
;
102 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
107 /*******************************************************************************
109 * FUNCTION: AcpiPsExecuteMethod
111 * PARAMETERS: Info - Method info block, contains:
112 * Node - Method Node to execute
113 * ObjDesc - Method object
114 * Parameters - List of parameters to pass to the method,
115 * terminated by NULL. Params itself may be
116 * NULL if no parameters are being passed.
117 * ReturnObject - Where to put method's return value (if
118 * any). If NULL, no value is returned.
119 * ParameterType - Type of Parameter list
120 * ReturnObject - Where to put method's return value (if
121 * any). If NULL, no value is returned.
122 * PassNumber - Parse or execute pass
126 * DESCRIPTION: Execute a control method
128 ******************************************************************************/
131 AcpiPsExecuteMethod (
132 ACPI_EVALUATE_INFO
*Info
)
135 ACPI_PARSE_OBJECT
*Op
;
136 ACPI_WALK_STATE
*WalkState
;
139 ACPI_FUNCTION_TRACE (PsExecuteMethod
);
142 /* Quick validation of DSDT header */
144 AcpiTbCheckDsdtHeader ();
146 /* Validate the Info and method Node */
148 if (!Info
|| !Info
->Node
)
150 return_ACPI_STATUS (AE_NULL_ENTRY
);
153 /* Init for new method, wait on concurrency semaphore */
155 Status
= AcpiDsBeginMethodExecution (Info
->Node
, Info
->ObjDesc
, NULL
);
156 if (ACPI_FAILURE (Status
))
158 return_ACPI_STATUS (Status
);
162 * The caller "owns" the parameters, so give each one an extra reference
164 AcpiPsUpdateParameterList (Info
, REF_INCREMENT
);
167 * Execute the method. Performs parse simultaneously
169 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
,
170 "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
171 Info
->Node
->Name
.Ascii
, Info
->Node
, Info
->ObjDesc
));
173 /* Create and init a Root Node */
175 Op
= AcpiPsCreateScopeOp (Info
->ObjDesc
->Method
.AmlStart
);
178 Status
= AE_NO_MEMORY
;
182 /* Create and initialize a new walk state */
184 Info
->PassNumber
= ACPI_IMODE_EXECUTE
;
185 WalkState
= AcpiDsCreateWalkState (
186 Info
->ObjDesc
->Method
.OwnerId
, NULL
, NULL
, NULL
);
189 Status
= AE_NO_MEMORY
;
193 Status
= AcpiDsInitAmlWalk (WalkState
, Op
, Info
->Node
,
194 Info
->ObjDesc
->Method
.AmlStart
,
195 Info
->ObjDesc
->Method
.AmlLength
, Info
, Info
->PassNumber
);
196 if (ACPI_FAILURE (Status
))
198 AcpiDsDeleteWalkState (WalkState
);
202 WalkState
->MethodPathname
= Info
->FullPathname
;
203 WalkState
->MethodIsNested
= FALSE
;
205 if (Info
->ObjDesc
->Method
.InfoFlags
& ACPI_METHOD_MODULE_LEVEL
)
207 WalkState
->ParseFlags
|= ACPI_PARSE_MODULE_LEVEL
;
210 /* Invoke an internal method if necessary */
212 if (Info
->ObjDesc
->Method
.InfoFlags
& ACPI_METHOD_INTERNAL_ONLY
)
214 Status
= Info
->ObjDesc
->Method
.Dispatch
.Implementation (WalkState
);
215 Info
->ReturnObject
= WalkState
->ReturnDesc
;
219 AcpiDsScopeStackClear (WalkState
);
220 AcpiPsCleanupScope (&WalkState
->ParserState
);
221 AcpiDsTerminateControlMethod (WalkState
->MethodDesc
, WalkState
);
222 AcpiDsDeleteWalkState (WalkState
);
227 * Start method evaluation with an implicit return of zero.
228 * This is done for Windows compatibility.
230 if (AcpiGbl_EnableInterpreterSlack
)
232 WalkState
->ImplicitReturnObj
=
233 AcpiUtCreateIntegerObject ((UINT64
) 0);
234 if (!WalkState
->ImplicitReturnObj
)
236 Status
= AE_NO_MEMORY
;
237 AcpiDsDeleteWalkState (WalkState
);
244 Status
= AcpiPsParseAml (WalkState
);
246 /* WalkState was deleted by ParseAml */
249 AcpiPsDeleteParseTree (Op
);
251 /* Take away the extra reference that we gave the parameters above */
253 AcpiPsUpdateParameterList (Info
, REF_DECREMENT
);
255 /* Exit now if error above */
257 if (ACPI_FAILURE (Status
))
259 return_ACPI_STATUS (Status
);
263 * If the method has returned an object, signal this to the caller with
264 * a control exception code
266 if (Info
->ReturnObject
)
268 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "Method returned ObjDesc=%p\n",
269 Info
->ReturnObject
));
270 ACPI_DUMP_STACK_ENTRY (Info
->ReturnObject
);
272 Status
= AE_CTRL_RETURN_VALUE
;
275 return_ACPI_STATUS (Status
);
279 /*******************************************************************************
281 * FUNCTION: AcpiPsExecuteTable
283 * PARAMETERS: Info - Method info block, contains:
284 * Node - Node to where the is entered into the
286 * ObjDesc - Pseudo method object describing the AML
287 * code of the entire table
288 * PassNumber - Parse or execute pass
292 * DESCRIPTION: Execute a table
294 ******************************************************************************/
298 ACPI_EVALUATE_INFO
*Info
)
301 ACPI_PARSE_OBJECT
*Op
= NULL
;
302 ACPI_WALK_STATE
*WalkState
= NULL
;
305 ACPI_FUNCTION_TRACE (PsExecuteTable
);
308 /* Create and init a Root Node */
310 Op
= AcpiPsCreateScopeOp (Info
->ObjDesc
->Method
.AmlStart
);
313 Status
= AE_NO_MEMORY
;
317 /* Create and initialize a new walk state */
319 WalkState
= AcpiDsCreateWalkState (
320 Info
->ObjDesc
->Method
.OwnerId
, NULL
, NULL
, NULL
);
323 Status
= AE_NO_MEMORY
;
327 Status
= AcpiDsInitAmlWalk (WalkState
, Op
, Info
->Node
,
328 Info
->ObjDesc
->Method
.AmlStart
,
329 Info
->ObjDesc
->Method
.AmlLength
, Info
, Info
->PassNumber
);
330 if (ACPI_FAILURE (Status
))
335 WalkState
->MethodPathname
= Info
->FullPathname
;
336 WalkState
->MethodIsNested
= FALSE
;
338 if (Info
->ObjDesc
->Method
.InfoFlags
& ACPI_METHOD_MODULE_LEVEL
)
340 WalkState
->ParseFlags
|= ACPI_PARSE_MODULE_LEVEL
;
343 /* Info->Node is the default location to load the table */
345 if (Info
->Node
&& Info
->Node
!= AcpiGbl_RootNode
)
347 Status
= AcpiDsScopeStackPush (
348 Info
->Node
, ACPI_TYPE_METHOD
, WalkState
);
349 if (ACPI_FAILURE (Status
))
356 * Parse the AML, WalkState will be deleted by ParseAml
358 AcpiExEnterInterpreter ();
359 Status
= AcpiPsParseAml (WalkState
);
360 AcpiExExitInterpreter ();
366 AcpiDsDeleteWalkState (WalkState
);
370 AcpiPsDeleteParseTree (Op
);
372 return_ACPI_STATUS (Status
);
376 /*******************************************************************************
378 * FUNCTION: AcpiPsUpdateParameterList
380 * PARAMETERS: Info - See ACPI_EVALUATE_INFO
381 * (Used: ParameterType and Parameters)
382 * Action - Add or Remove reference
386 * DESCRIPTION: Update reference count on all method parameter objects
388 ******************************************************************************/
391 AcpiPsUpdateParameterList (
392 ACPI_EVALUATE_INFO
*Info
,
398 if (Info
->Parameters
)
400 /* Update reference count for each parameter */
402 for (i
= 0; Info
->Parameters
[i
]; i
++)
404 /* Ignore errors, just do them all */
406 (void) AcpiUtUpdateObjectReference (
407 Info
->Parameters
[i
], Action
);