1 /******************************************************************************
3 * Module Name: psxface - Parser external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acparser.h>
49 #include <contrib/dev/acpica/include/acdispat.h>
50 #include <contrib/dev/acpica/include/acinterp.h>
51 #include <contrib/dev/acpica/include/actables.h>
54 #define _COMPONENT ACPI_PARSER
55 ACPI_MODULE_NAME ("psxface")
57 /* Local Prototypes */
61 ACPI_EVALUATE_INFO *Info);
65 ACPI_EVALUATE_INFO *Info);
68 AcpiPsUpdateParameterList (
69 ACPI_EVALUATE_INFO *Info,
73 /*******************************************************************************
75 * FUNCTION: AcpiDebugTrace
77 * PARAMETERS: MethodName - Valid ACPI name string
78 * DebugLevel - Optional level mask. 0 to use default
79 * DebugLayer - Optional layer mask. 0 to use default
80 * Flags - bit 1: one shot(1) or persistent(0)
84 * DESCRIPTION: External interface to enable debug tracing during control
87 ******************************************************************************/
99 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
100 if (ACPI_FAILURE (Status))
105 /* TBDs: Validate name, allow full path or just nameseg */
107 AcpiGbl_TraceMethodName = *ACPI_CAST_PTR (UINT32, Name);
108 AcpiGbl_TraceFlags = Flags;
112 AcpiGbl_TraceDbgLevel = DebugLevel;
116 AcpiGbl_TraceDbgLayer = DebugLayer;
119 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
124 /*******************************************************************************
126 * FUNCTION: AcpiPsStartTrace
128 * PARAMETERS: Info - Method info struct
132 * DESCRIPTION: Start control method execution trace
134 ******************************************************************************/
138 ACPI_EVALUATE_INFO *Info)
143 ACPI_FUNCTION_ENTRY ();
146 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
147 if (ACPI_FAILURE (Status))
152 if ((!AcpiGbl_TraceMethodName) ||
153 (AcpiGbl_TraceMethodName != Info->Node->Name.Integer))
158 AcpiGbl_OriginalDbgLevel = AcpiDbgLevel;
159 AcpiGbl_OriginalDbgLayer = AcpiDbgLayer;
161 AcpiDbgLevel = 0x00FFFFFF;
162 AcpiDbgLayer = ACPI_UINT32_MAX;
164 if (AcpiGbl_TraceDbgLevel)
166 AcpiDbgLevel = AcpiGbl_TraceDbgLevel;
168 if (AcpiGbl_TraceDbgLayer)
170 AcpiDbgLayer = AcpiGbl_TraceDbgLayer;
175 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
179 /*******************************************************************************
181 * FUNCTION: AcpiPsStopTrace
183 * PARAMETERS: Info - Method info struct
187 * DESCRIPTION: Stop control method execution trace
189 ******************************************************************************/
193 ACPI_EVALUATE_INFO *Info)
198 ACPI_FUNCTION_ENTRY ();
201 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
202 if (ACPI_FAILURE (Status))
207 if ((!AcpiGbl_TraceMethodName) ||
208 (AcpiGbl_TraceMethodName != Info->Node->Name.Integer))
213 /* Disable further tracing if type is one-shot */
215 if (AcpiGbl_TraceFlags & 1)
217 AcpiGbl_TraceMethodName = 0;
218 AcpiGbl_TraceDbgLevel = 0;
219 AcpiGbl_TraceDbgLayer = 0;
222 AcpiDbgLevel = AcpiGbl_OriginalDbgLevel;
223 AcpiDbgLayer = AcpiGbl_OriginalDbgLayer;
226 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
230 /*******************************************************************************
232 * FUNCTION: AcpiPsExecuteMethod
234 * PARAMETERS: Info - Method info block, contains:
235 * Node - Method Node to execute
236 * ObjDesc - Method object
237 * Parameters - List of parameters to pass to the method,
238 * terminated by NULL. Params itself may be
239 * NULL if no parameters are being passed.
240 * ReturnObject - Where to put method's return value (if
241 * any). If NULL, no value is returned.
242 * ParameterType - Type of Parameter list
243 * ReturnObject - Where to put method's return value (if
244 * any). If NULL, no value is returned.
245 * PassNumber - Parse or execute pass
249 * DESCRIPTION: Execute a control method
251 ******************************************************************************/
254 AcpiPsExecuteMethod (
255 ACPI_EVALUATE_INFO *Info)
258 ACPI_PARSE_OBJECT *Op;
259 ACPI_WALK_STATE *WalkState;
262 ACPI_FUNCTION_TRACE (PsExecuteMethod);
265 /* Quick validation of DSDT header */
267 AcpiTbCheckDsdtHeader ();
269 /* Validate the Info and method Node */
271 if (!Info || !Info->Node)
273 return_ACPI_STATUS (AE_NULL_ENTRY);
276 /* Init for new method, wait on concurrency semaphore */
278 Status = AcpiDsBeginMethodExecution (Info->Node, Info->ObjDesc, NULL);
279 if (ACPI_FAILURE (Status))
281 return_ACPI_STATUS (Status);
285 * The caller "owns" the parameters, so give each one an extra reference
287 AcpiPsUpdateParameterList (Info, REF_INCREMENT);
289 /* Begin tracing if requested */
291 AcpiPsStartTrace (Info);
294 * Execute the method. Performs parse simultaneously
296 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
297 "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
298 Info->Node->Name.Ascii, Info->Node, Info->ObjDesc));
300 /* Create and init a Root Node */
302 Op = AcpiPsCreateScopeOp ();
305 Status = AE_NO_MEMORY;
309 /* Create and initialize a new walk state */
311 Info->PassNumber = ACPI_IMODE_EXECUTE;
312 WalkState = AcpiDsCreateWalkState (
313 Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL);
316 Status = AE_NO_MEMORY;
320 Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node,
321 Info->ObjDesc->Method.AmlStart,
322 Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber);
323 if (ACPI_FAILURE (Status))
325 AcpiDsDeleteWalkState (WalkState);
329 if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
331 WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL;
334 /* Invoke an internal method if necessary */
336 if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
338 Status = Info->ObjDesc->Method.Dispatch.Implementation (WalkState);
339 Info->ReturnObject = WalkState->ReturnDesc;
343 AcpiDsScopeStackClear (WalkState);
344 AcpiPsCleanupScope (&WalkState->ParserState);
345 AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
346 AcpiDsDeleteWalkState (WalkState);
351 * Start method evaluation with an implicit return of zero.
352 * This is done for Windows compatibility.
354 if (AcpiGbl_EnableInterpreterSlack)
356 WalkState->ImplicitReturnObj =
357 AcpiUtCreateIntegerObject ((UINT64) 0);
358 if (!WalkState->ImplicitReturnObj)
360 Status = AE_NO_MEMORY;
361 AcpiDsDeleteWalkState (WalkState);
368 Status = AcpiPsParseAml (WalkState);
370 /* WalkState was deleted by ParseAml */
373 AcpiPsDeleteParseTree (Op);
375 /* End optional tracing */
377 AcpiPsStopTrace (Info);
379 /* Take away the extra reference that we gave the parameters above */
381 AcpiPsUpdateParameterList (Info, REF_DECREMENT);
383 /* Exit now if error above */
385 if (ACPI_FAILURE (Status))
387 return_ACPI_STATUS (Status);
391 * If the method has returned an object, signal this to the caller with
392 * a control exception code
394 if (Info->ReturnObject)
396 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n",
397 Info->ReturnObject));
398 ACPI_DUMP_STACK_ENTRY (Info->ReturnObject);
400 Status = AE_CTRL_RETURN_VALUE;
403 return_ACPI_STATUS (Status);
407 /*******************************************************************************
409 * FUNCTION: AcpiPsUpdateParameterList
411 * PARAMETERS: Info - See ACPI_EVALUATE_INFO
412 * (Used: ParameterType and Parameters)
413 * Action - Add or Remove reference
417 * DESCRIPTION: Update reference count on all method parameter objects
419 ******************************************************************************/
422 AcpiPsUpdateParameterList (
423 ACPI_EVALUATE_INFO *Info,
429 if (Info->Parameters)
431 /* Update reference count for each parameter */
433 for (i = 0; Info->Parameters[i]; i++)
435 /* Ignore errors, just do them all */
437 (void) AcpiUtUpdateObjectReference (Info->Parameters[i], Action);