Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / parser / psxface.c
blob3f991570b86893252ac0e7c2fb9e74384efae462
1 /******************************************************************************
3 * Module Name: psxface - Parser external interfaces
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
44 #define __PSXFACE_C__
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acparser.h"
49 #include "acdispat.h"
50 #include "acinterp.h"
51 #include "actables.h"
54 #define _COMPONENT ACPI_PARSER
55 ACPI_MODULE_NAME ("psxface")
57 /* Local Prototypes */
59 static void
60 AcpiPsStartTrace (
61 ACPI_EVALUATE_INFO *Info);
63 static void
64 AcpiPsStopTrace (
65 ACPI_EVALUATE_INFO *Info);
67 static void
68 AcpiPsUpdateParameterList (
69 ACPI_EVALUATE_INFO *Info,
70 UINT16 Action);
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)
82 * RETURN: Status
84 * DESCRIPTION: External interface to enable debug tracing during control
85 * method execution
87 ******************************************************************************/
89 ACPI_STATUS
90 AcpiDebugTrace (
91 char *Name,
92 UINT32 DebugLevel,
93 UINT32 DebugLayer,
94 UINT32 Flags)
96 ACPI_STATUS Status;
99 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
100 if (ACPI_FAILURE (Status))
102 return (Status);
105 /* TBDs: Validate name, allow full path or just nameseg */
107 AcpiGbl_TraceMethodName = *ACPI_CAST_PTR (UINT32, Name);
108 AcpiGbl_TraceFlags = Flags;
110 if (DebugLevel)
112 AcpiGbl_TraceDbgLevel = DebugLevel;
114 if (DebugLayer)
116 AcpiGbl_TraceDbgLayer = DebugLayer;
119 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
120 return (AE_OK);
124 /*******************************************************************************
126 * FUNCTION: AcpiPsStartTrace
128 * PARAMETERS: Info - Method info struct
130 * RETURN: None
132 * DESCRIPTION: Start control method execution trace
134 ******************************************************************************/
136 static void
137 AcpiPsStartTrace (
138 ACPI_EVALUATE_INFO *Info)
140 ACPI_STATUS Status;
143 ACPI_FUNCTION_ENTRY ();
146 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
147 if (ACPI_FAILURE (Status))
149 return;
152 if ((!AcpiGbl_TraceMethodName) ||
153 (AcpiGbl_TraceMethodName != Info->Node->Name.Integer))
155 goto Exit;
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;
174 Exit:
175 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
179 /*******************************************************************************
181 * FUNCTION: AcpiPsStopTrace
183 * PARAMETERS: Info - Method info struct
185 * RETURN: None
187 * DESCRIPTION: Stop control method execution trace
189 ******************************************************************************/
191 static void
192 AcpiPsStopTrace (
193 ACPI_EVALUATE_INFO *Info)
195 ACPI_STATUS Status;
198 ACPI_FUNCTION_ENTRY ();
201 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
202 if (ACPI_FAILURE (Status))
204 return;
207 if ((!AcpiGbl_TraceMethodName) ||
208 (AcpiGbl_TraceMethodName != Info->Node->Name.Integer))
210 goto Exit;
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;
225 Exit:
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
247 * RETURN: Status
249 * DESCRIPTION: Execute a control method
251 ******************************************************************************/
253 ACPI_STATUS
254 AcpiPsExecuteMethod (
255 ACPI_EVALUATE_INFO *Info)
257 ACPI_STATUS Status;
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 ();
303 if (!Op)
305 Status = AE_NO_MEMORY;
306 goto Cleanup;
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);
314 if (!WalkState)
316 Status = AE_NO_MEMORY;
317 goto Cleanup;
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);
326 goto Cleanup;
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;
341 /* Cleanup states */
343 AcpiDsScopeStackClear (WalkState);
344 AcpiPsCleanupScope (&WalkState->ParserState);
345 AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
346 AcpiDsDeleteWalkState (WalkState);
347 goto Cleanup;
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);
362 goto Cleanup;
366 /* Parse the AML */
368 Status = AcpiPsParseAml (WalkState);
370 /* WalkState was deleted by ParseAml */
372 Cleanup:
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
415 * RETURN: Status
417 * DESCRIPTION: Update reference count on all method parameter objects
419 ******************************************************************************/
421 static void
422 AcpiPsUpdateParameterList (
423 ACPI_EVALUATE_INFO *Info,
424 UINT16 Action)
426 UINT32 i;
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);