1 /******************************************************************************
3 * Module Name: psxface - Parser external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
52 #define _COMPONENT ACPI_PARSER
53 ACPI_MODULE_NAME ("psxface")
55 /* Local Prototypes */
59 ACPI_EVALUATE_INFO *Info);
63 ACPI_EVALUATE_INFO *Info);
66 AcpiPsUpdateParameterList (
67 ACPI_EVALUATE_INFO *Info,
71 /*******************************************************************************
73 * FUNCTION: AcpiDebugTrace
75 * PARAMETERS: MethodName - Valid ACPI name string
76 * DebugLevel - Optional level mask. 0 to use default
77 * DebugLayer - Optional layer mask. 0 to use default
78 * Flags - bit 1: one shot(1) or persistent(0)
82 * DESCRIPTION: External interface to enable debug tracing during control
85 ******************************************************************************/
97 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
98 if (ACPI_FAILURE (Status))
103 /* TBDs: Validate name, allow full path or just nameseg */
105 AcpiGbl_TraceMethodName = *ACPI_CAST_PTR (UINT32, Name);
106 AcpiGbl_TraceFlags = Flags;
110 AcpiGbl_TraceDbgLevel = DebugLevel;
114 AcpiGbl_TraceDbgLayer = DebugLayer;
117 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
122 /*******************************************************************************
124 * FUNCTION: AcpiPsStartTrace
126 * PARAMETERS: Info - Method info struct
130 * DESCRIPTION: Start control method execution trace
132 ******************************************************************************/
136 ACPI_EVALUATE_INFO *Info)
141 ACPI_FUNCTION_ENTRY ();
144 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
145 if (ACPI_FAILURE (Status))
150 if ((!AcpiGbl_TraceMethodName) ||
151 (AcpiGbl_TraceMethodName != Info->Node->Name.Integer))
156 AcpiGbl_OriginalDbgLevel = AcpiDbgLevel;
157 AcpiGbl_OriginalDbgLayer = AcpiDbgLayer;
159 AcpiDbgLevel = 0x00FFFFFF;
160 AcpiDbgLayer = ACPI_UINT32_MAX;
162 if (AcpiGbl_TraceDbgLevel)
164 AcpiDbgLevel = AcpiGbl_TraceDbgLevel;
166 if (AcpiGbl_TraceDbgLayer)
168 AcpiDbgLayer = AcpiGbl_TraceDbgLayer;
173 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
177 /*******************************************************************************
179 * FUNCTION: AcpiPsStopTrace
181 * PARAMETERS: Info - Method info struct
185 * DESCRIPTION: Stop control method execution trace
187 ******************************************************************************/
191 ACPI_EVALUATE_INFO *Info)
196 ACPI_FUNCTION_ENTRY ();
199 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
200 if (ACPI_FAILURE (Status))
205 if ((!AcpiGbl_TraceMethodName) ||
206 (AcpiGbl_TraceMethodName != Info->Node->Name.Integer))
211 /* Disable further tracing if type is one-shot */
213 if (AcpiGbl_TraceFlags & 1)
215 AcpiGbl_TraceMethodName = 0;
216 AcpiGbl_TraceDbgLevel = 0;
217 AcpiGbl_TraceDbgLayer = 0;
220 AcpiDbgLevel = AcpiGbl_OriginalDbgLevel;
221 AcpiDbgLayer = AcpiGbl_OriginalDbgLayer;
224 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
228 /*******************************************************************************
230 * FUNCTION: AcpiPsExecuteMethod
232 * PARAMETERS: Info - Method info block, contains:
233 * Node - Method Node to execute
234 * ObjDesc - Method object
235 * Parameters - List of parameters to pass to the method,
236 * terminated by NULL. Params itself may be
237 * NULL if no parameters are being passed.
238 * ReturnObject - Where to put method's return value (if
239 * any). If NULL, no value is returned.
240 * ParameterType - Type of Parameter list
241 * ReturnObject - Where to put method's return value (if
242 * any). If NULL, no value is returned.
243 * PassNumber - Parse or execute pass
247 * DESCRIPTION: Execute a control method
249 ******************************************************************************/
252 AcpiPsExecuteMethod (
253 ACPI_EVALUATE_INFO *Info)
256 ACPI_PARSE_OBJECT *Op;
257 ACPI_WALK_STATE *WalkState;
260 ACPI_FUNCTION_TRACE (PsExecuteMethod);
263 /* Quick validation of DSDT header */
265 AcpiTbCheckDsdtHeader ();
267 /* Validate the Info and method Node */
269 if (!Info || !Info->Node)
271 return_ACPI_STATUS (AE_NULL_ENTRY);
274 /* Init for new method, wait on concurrency semaphore */
276 Status = AcpiDsBeginMethodExecution (Info->Node, Info->ObjDesc, NULL);
277 if (ACPI_FAILURE (Status))
279 return_ACPI_STATUS (Status);
283 * The caller "owns" the parameters, so give each one an extra reference
285 AcpiPsUpdateParameterList (Info, REF_INCREMENT);
287 /* Begin tracing if requested */
289 AcpiPsStartTrace (Info);
292 * Execute the method. Performs parse simultaneously
294 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
295 "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
296 Info->Node->Name.Ascii, Info->Node, Info->ObjDesc));
298 /* Create and init a Root Node */
300 Op = AcpiPsCreateScopeOp ();
303 Status = AE_NO_MEMORY;
307 /* Create and initialize a new walk state */
309 Info->PassNumber = ACPI_IMODE_EXECUTE;
310 WalkState = AcpiDsCreateWalkState (
311 Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL);
314 Status = AE_NO_MEMORY;
318 Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node,
319 Info->ObjDesc->Method.AmlStart,
320 Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber);
321 if (ACPI_FAILURE (Status))
323 AcpiDsDeleteWalkState (WalkState);
327 if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
329 WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL;
332 /* Invoke an internal method if necessary */
334 if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
336 Status = Info->ObjDesc->Method.Dispatch.Implementation (WalkState);
337 Info->ReturnObject = WalkState->ReturnDesc;
341 AcpiDsScopeStackClear (WalkState);
342 AcpiPsCleanupScope (&WalkState->ParserState);
343 AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
344 AcpiDsDeleteWalkState (WalkState);
349 * Start method evaluation with an implicit return of zero.
350 * This is done for Windows compatibility.
352 if (AcpiGbl_EnableInterpreterSlack)
354 WalkState->ImplicitReturnObj =
355 AcpiUtCreateIntegerObject ((UINT64) 0);
356 if (!WalkState->ImplicitReturnObj)
358 Status = AE_NO_MEMORY;
359 AcpiDsDeleteWalkState (WalkState);
366 Status = AcpiPsParseAml (WalkState);
368 /* WalkState was deleted by ParseAml */
371 AcpiPsDeleteParseTree (Op);
373 /* End optional tracing */
375 AcpiPsStopTrace (Info);
377 /* Take away the extra reference that we gave the parameters above */
379 AcpiPsUpdateParameterList (Info, REF_DECREMENT);
381 /* Exit now if error above */
383 if (ACPI_FAILURE (Status))
385 return_ACPI_STATUS (Status);
389 * If the method has returned an object, signal this to the caller with
390 * a control exception code
392 if (Info->ReturnObject)
394 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n",
395 Info->ReturnObject));
396 ACPI_DUMP_STACK_ENTRY (Info->ReturnObject);
398 Status = AE_CTRL_RETURN_VALUE;
401 return_ACPI_STATUS (Status);
405 /*******************************************************************************
407 * FUNCTION: AcpiPsUpdateParameterList
409 * PARAMETERS: Info - See ACPI_EVALUATE_INFO
410 * (Used: ParameterType and Parameters)
411 * Action - Add or Remove reference
415 * DESCRIPTION: Update reference count on all method parameter objects
417 ******************************************************************************/
420 AcpiPsUpdateParameterList (
421 ACPI_EVALUATE_INFO *Info,
427 if (Info->Parameters)
429 /* Update reference count for each parameter */
431 for (i = 0; Info->Parameters[i]; i++)
433 /* Ignore errors, just do them all */
435 (void) AcpiUtUpdateObjectReference (Info->Parameters[i], Action);