1ae115bc7Smrj /*******************************************************************************
2ae115bc7Smrj *
3ae115bc7Smrj * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4ae115bc7Smrj * ACPI Object evaluation interfaces
5ae115bc7Smrj *
6ae115bc7Smrj ******************************************************************************/
7ae115bc7Smrj
826f3cdf0SGordon Ross /*
9*cb565728SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
10ae115bc7Smrj * All rights reserved.
11ae115bc7Smrj *
1226f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
1326f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
1426f3cdf0SGordon Ross * are met:
1526f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
1626f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
1726f3cdf0SGordon Ross * without modification.
1826f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1926f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
2026f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
2126f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
2226f3cdf0SGordon Ross * binary redistribution.
2326f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
2426f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
2526f3cdf0SGordon Ross * from this software without specific prior written permission.
26ae115bc7Smrj *
2726f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the
2826f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free
2926f3cdf0SGordon Ross * Software Foundation.
30ae115bc7Smrj *
3126f3cdf0SGordon Ross * NO WARRANTY
3226f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3326f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3426f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3526f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3626f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3726f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3826f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3926f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4026f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4126f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4226f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES.
4326f3cdf0SGordon Ross */
44ae115bc7Smrj
45*cb565728SJerry Jelinek #define EXPORT_ACPI_INTERFACES
46ae115bc7Smrj
47ae115bc7Smrj #include "acpi.h"
48aa2aa9a6SDana Myers #include "accommon.h"
49ae115bc7Smrj #include "acnamesp.h"
50ae115bc7Smrj #include "acinterp.h"
51ae115bc7Smrj
52ae115bc7Smrj
53ae115bc7Smrj #define _COMPONENT ACPI_NAMESPACE
54ae115bc7Smrj ACPI_MODULE_NAME ("nsxfeval")
55ae115bc7Smrj
56db2bae30SDana Myers /* Local prototypes */
57db2bae30SDana Myers
58db2bae30SDana Myers static void
59db2bae30SDana Myers AcpiNsResolveReferences (
60db2bae30SDana Myers ACPI_EVALUATE_INFO *Info);
61db2bae30SDana Myers
62ae115bc7Smrj
63ae115bc7Smrj /*******************************************************************************
64ae115bc7Smrj *
65ae115bc7Smrj * FUNCTION: AcpiEvaluateObjectTyped
66ae115bc7Smrj *
67ae115bc7Smrj * PARAMETERS: Handle - Object handle (optional)
68ae115bc7Smrj * Pathname - Object pathname (optional)
69ae115bc7Smrj * ExternalParams - List of parameters to pass to method,
70ae115bc7Smrj * terminated by NULL. May be NULL
71ae115bc7Smrj * if no parameters are being passed.
72ae115bc7Smrj * ReturnBuffer - Where to put method's return value (if
73ae115bc7Smrj * any). If NULL, no value is returned.
74ae115bc7Smrj * ReturnType - Expected type of return object
75ae115bc7Smrj *
76ae115bc7Smrj * RETURN: Status
77ae115bc7Smrj *
78ae115bc7Smrj * DESCRIPTION: Find and evaluate the given object, passing the given
79ae115bc7Smrj * parameters if necessary. One of "Handle" or "Pathname" must
80ae115bc7Smrj * be valid (non-null)
81ae115bc7Smrj *
82ae115bc7Smrj ******************************************************************************/
83ae115bc7Smrj
84ae115bc7Smrj ACPI_STATUS
AcpiEvaluateObjectTyped(ACPI_HANDLE Handle,ACPI_STRING Pathname,ACPI_OBJECT_LIST * ExternalParams,ACPI_BUFFER * ReturnBuffer,ACPI_OBJECT_TYPE ReturnType)85ae115bc7Smrj AcpiEvaluateObjectTyped (
86ae115bc7Smrj ACPI_HANDLE Handle,
87ae115bc7Smrj ACPI_STRING Pathname,
88ae115bc7Smrj ACPI_OBJECT_LIST *ExternalParams,
89ae115bc7Smrj ACPI_BUFFER *ReturnBuffer,
90ae115bc7Smrj ACPI_OBJECT_TYPE ReturnType)
91ae115bc7Smrj {
92ae115bc7Smrj ACPI_STATUS Status;
93*cb565728SJerry Jelinek BOOLEAN FreeBufferOnError = FALSE;
94ae115bc7Smrj
95ae115bc7Smrj
96ae115bc7Smrj ACPI_FUNCTION_TRACE (AcpiEvaluateObjectTyped);
97ae115bc7Smrj
98ae115bc7Smrj
99ae115bc7Smrj /* Return buffer must be valid */
100ae115bc7Smrj
101ae115bc7Smrj if (!ReturnBuffer)
102ae115bc7Smrj {
103ae115bc7Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
104ae115bc7Smrj }
105ae115bc7Smrj
106ae115bc7Smrj if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER)
107ae115bc7Smrj {
108*cb565728SJerry Jelinek FreeBufferOnError = TRUE;
109ae115bc7Smrj }
110ae115bc7Smrj
111ae115bc7Smrj /* Evaluate the object */
112ae115bc7Smrj
113*cb565728SJerry Jelinek Status = AcpiEvaluateObject (Handle, Pathname,
114*cb565728SJerry Jelinek ExternalParams, ReturnBuffer);
115ae115bc7Smrj if (ACPI_FAILURE (Status))
116ae115bc7Smrj {
117ae115bc7Smrj return_ACPI_STATUS (Status);
118ae115bc7Smrj }
119ae115bc7Smrj
120ae115bc7Smrj /* Type ANY means "don't care" */
121ae115bc7Smrj
122ae115bc7Smrj if (ReturnType == ACPI_TYPE_ANY)
123ae115bc7Smrj {
124ae115bc7Smrj return_ACPI_STATUS (AE_OK);
125ae115bc7Smrj }
126ae115bc7Smrj
127ae115bc7Smrj if (ReturnBuffer->Length == 0)
128ae115bc7Smrj {
129ae115bc7Smrj /* Error because caller specifically asked for a return value */
130ae115bc7Smrj
131ae115bc7Smrj ACPI_ERROR ((AE_INFO, "No return value"));
132ae115bc7Smrj return_ACPI_STATUS (AE_NULL_OBJECT);
133ae115bc7Smrj }
134ae115bc7Smrj
135ae115bc7Smrj /* Examine the object type returned from EvaluateObject */
136ae115bc7Smrj
137ae115bc7Smrj if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType)
138ae115bc7Smrj {
139ae115bc7Smrj return_ACPI_STATUS (AE_OK);
140ae115bc7Smrj }
141ae115bc7Smrj
142ae115bc7Smrj /* Return object type does not match requested type */
143ae115bc7Smrj
144ae115bc7Smrj ACPI_ERROR ((AE_INFO,
145ae115bc7Smrj "Incorrect return type [%s] requested [%s]",
146ae115bc7Smrj AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type),
147ae115bc7Smrj AcpiUtGetTypeName (ReturnType)));
148ae115bc7Smrj
149*cb565728SJerry Jelinek if (FreeBufferOnError)
150ae115bc7Smrj {
151*cb565728SJerry Jelinek /*
152*cb565728SJerry Jelinek * Free a buffer created via ACPI_ALLOCATE_BUFFER.
153*cb565728SJerry Jelinek * Note: We use AcpiOsFree here because AcpiOsAllocate was used
154*cb565728SJerry Jelinek * to allocate the buffer. This purposefully bypasses the
155*cb565728SJerry Jelinek * (optionally enabled) allocation tracking mechanism since we
156*cb565728SJerry Jelinek * only want to track internal allocations.
157*cb565728SJerry Jelinek */
158ae115bc7Smrj AcpiOsFree (ReturnBuffer->Pointer);
159ae115bc7Smrj ReturnBuffer->Pointer = NULL;
160ae115bc7Smrj }
161ae115bc7Smrj
162ae115bc7Smrj ReturnBuffer->Length = 0;
163ae115bc7Smrj return_ACPI_STATUS (AE_TYPE);
164ae115bc7Smrj }
165ae115bc7Smrj
ACPI_EXPORT_SYMBOL(AcpiEvaluateObjectTyped)166ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiEvaluateObjectTyped)
167ae115bc7Smrj
168ae115bc7Smrj
169ae115bc7Smrj /*******************************************************************************
170ae115bc7Smrj *
171ae115bc7Smrj * FUNCTION: AcpiEvaluateObject
172ae115bc7Smrj *
173ae115bc7Smrj * PARAMETERS: Handle - Object handle (optional)
174ae115bc7Smrj * Pathname - Object pathname (optional)
175ae115bc7Smrj * ExternalParams - List of parameters to pass to method,
176ae115bc7Smrj * terminated by NULL. May be NULL
177ae115bc7Smrj * if no parameters are being passed.
178ae115bc7Smrj * ReturnBuffer - Where to put method's return value (if
179ae115bc7Smrj * any). If NULL, no value is returned.
180ae115bc7Smrj *
181ae115bc7Smrj * RETURN: Status
182ae115bc7Smrj *
183ae115bc7Smrj * DESCRIPTION: Find and evaluate the given object, passing the given
184ae115bc7Smrj * parameters if necessary. One of "Handle" or "Pathname" must
185ae115bc7Smrj * be valid (non-null)
186ae115bc7Smrj *
187ae115bc7Smrj ******************************************************************************/
188ae115bc7Smrj
189ae115bc7Smrj ACPI_STATUS
190ae115bc7Smrj AcpiEvaluateObject (
191ae115bc7Smrj ACPI_HANDLE Handle,
192ae115bc7Smrj ACPI_STRING Pathname,
193ae115bc7Smrj ACPI_OBJECT_LIST *ExternalParams,
194ae115bc7Smrj ACPI_BUFFER *ReturnBuffer)
195ae115bc7Smrj {
196ae115bc7Smrj ACPI_STATUS Status;
197ae115bc7Smrj ACPI_EVALUATE_INFO *Info;
198ae115bc7Smrj ACPI_SIZE BufferSpaceNeeded;
199ae115bc7Smrj UINT32 i;
200ae115bc7Smrj
201ae115bc7Smrj
202ae115bc7Smrj ACPI_FUNCTION_TRACE (AcpiEvaluateObject);
203ae115bc7Smrj
204ae115bc7Smrj
205ae115bc7Smrj /* Allocate and initialize the evaluation information block */
206ae115bc7Smrj
207ae115bc7Smrj Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
208ae115bc7Smrj if (!Info)
209ae115bc7Smrj {
210ae115bc7Smrj return_ACPI_STATUS (AE_NO_MEMORY);
211ae115bc7Smrj }
212ae115bc7Smrj
213ae115bc7Smrj /* Convert and validate the device handle */
214ae115bc7Smrj
21526f3cdf0SGordon Ross Info->PrefixNode = AcpiNsValidateHandle (Handle);
216ae115bc7Smrj if (!Info->PrefixNode)
217ae115bc7Smrj {
218ae115bc7Smrj Status = AE_BAD_PARAMETER;
219ae115bc7Smrj goto Cleanup;
220ae115bc7Smrj }
221ae115bc7Smrj
222ae115bc7Smrj /*
223*cb565728SJerry Jelinek * Get the actual namespace node for the target object.
224*cb565728SJerry Jelinek * Handles these cases:
225*cb565728SJerry Jelinek *
226*cb565728SJerry Jelinek * 1) Null node, valid pathname from root (absolute path)
227*cb565728SJerry Jelinek * 2) Node and valid pathname (path relative to Node)
228*cb565728SJerry Jelinek * 3) Node, Null pathname
229ae115bc7Smrj */
230ae115bc7Smrj if ((Pathname) &&
231*cb565728SJerry Jelinek (ACPI_IS_ROOT_PREFIX (Pathname[0])))
232ae115bc7Smrj {
233ae115bc7Smrj /* The path is fully qualified, just evaluate by name */
234ae115bc7Smrj
235ae115bc7Smrj Info->PrefixNode = NULL;
236ae115bc7Smrj }
237ae115bc7Smrj else if (!Handle)
238ae115bc7Smrj {
239ae115bc7Smrj /*
240ae115bc7Smrj * A handle is optional iff a fully qualified pathname is specified.
241ae115bc7Smrj * Since we've already handled fully qualified names above, this is
242*cb565728SJerry Jelinek * an error.
243ae115bc7Smrj */
244ae115bc7Smrj if (!Pathname)
245ae115bc7Smrj {
246ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
247ae115bc7Smrj "Both Handle and Pathname are NULL"));
248ae115bc7Smrj }
249ae115bc7Smrj else
250ae115bc7Smrj {
251ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
252ae115bc7Smrj "Null Handle with relative pathname [%s]", Pathname));
253ae115bc7Smrj }
254ae115bc7Smrj
255ae115bc7Smrj Status = AE_BAD_PARAMETER;
256*cb565728SJerry Jelinek goto Cleanup;
257ae115bc7Smrj }
258*cb565728SJerry Jelinek
259*cb565728SJerry Jelinek Info->RelativePathname = Pathname;
260*cb565728SJerry Jelinek
261*cb565728SJerry Jelinek /*
262*cb565728SJerry Jelinek * Convert all external objects passed as arguments to the
263*cb565728SJerry Jelinek * internal version(s).
264*cb565728SJerry Jelinek */
265*cb565728SJerry Jelinek if (ExternalParams && ExternalParams->Count)
266ae115bc7Smrj {
267*cb565728SJerry Jelinek Info->ParamCount = (UINT16) ExternalParams->Count;
268*cb565728SJerry Jelinek
269*cb565728SJerry Jelinek /* Warn on impossible argument count */
270*cb565728SJerry Jelinek
271*cb565728SJerry Jelinek if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)
272*cb565728SJerry Jelinek {
273*cb565728SJerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
274*cb565728SJerry Jelinek "Excess arguments (%u) - using only %u",
275*cb565728SJerry Jelinek Info->ParamCount, ACPI_METHOD_NUM_ARGS));
276*cb565728SJerry Jelinek
277*cb565728SJerry Jelinek Info->ParamCount = ACPI_METHOD_NUM_ARGS;
278*cb565728SJerry Jelinek }
279*cb565728SJerry Jelinek
280*cb565728SJerry Jelinek /*
281*cb565728SJerry Jelinek * Allocate a new parameter block for the internal objects
282*cb565728SJerry Jelinek * Add 1 to count to allow for null terminated internal list
283*cb565728SJerry Jelinek */
284*cb565728SJerry Jelinek Info->Parameters = ACPI_ALLOCATE_ZEROED (
285*cb565728SJerry Jelinek ((ACPI_SIZE) Info->ParamCount + 1) * sizeof (void *));
286*cb565728SJerry Jelinek if (!Info->Parameters)
287*cb565728SJerry Jelinek {
288*cb565728SJerry Jelinek Status = AE_NO_MEMORY;
289*cb565728SJerry Jelinek goto Cleanup;
290*cb565728SJerry Jelinek }
291*cb565728SJerry Jelinek
292*cb565728SJerry Jelinek /* Convert each external object in the list to an internal object */
293*cb565728SJerry Jelinek
294*cb565728SJerry Jelinek for (i = 0; i < Info->ParamCount; i++)
295*cb565728SJerry Jelinek {
296*cb565728SJerry Jelinek Status = AcpiUtCopyEobjectToIobject (
297*cb565728SJerry Jelinek &ExternalParams->Pointer[i], &Info->Parameters[i]);
298*cb565728SJerry Jelinek if (ACPI_FAILURE (Status))
299*cb565728SJerry Jelinek {
300*cb565728SJerry Jelinek goto Cleanup;
301*cb565728SJerry Jelinek }
302*cb565728SJerry Jelinek }
303*cb565728SJerry Jelinek
304*cb565728SJerry Jelinek Info->Parameters[Info->ParamCount] = NULL;
305*cb565728SJerry Jelinek }
306*cb565728SJerry Jelinek
307*cb565728SJerry Jelinek
308*cb565728SJerry Jelinek #ifdef _FUTURE_FEATURE
309*cb565728SJerry Jelinek
310*cb565728SJerry Jelinek /*
311*cb565728SJerry Jelinek * Begin incoming argument count analysis. Check for too few args
312*cb565728SJerry Jelinek * and too many args.
313*cb565728SJerry Jelinek */
314*cb565728SJerry Jelinek switch (AcpiNsGetType (Info->Node))
315*cb565728SJerry Jelinek {
316*cb565728SJerry Jelinek case ACPI_TYPE_METHOD:
317*cb565728SJerry Jelinek
318*cb565728SJerry Jelinek /* Check incoming argument count against the method definition */
319*cb565728SJerry Jelinek
320*cb565728SJerry Jelinek if (Info->ObjDesc->Method.ParamCount > Info->ParamCount)
321*cb565728SJerry Jelinek {
322*cb565728SJerry Jelinek ACPI_ERROR ((AE_INFO,
323*cb565728SJerry Jelinek "Insufficient arguments (%u) - %u are required",
324*cb565728SJerry Jelinek Info->ParamCount,
325*cb565728SJerry Jelinek Info->ObjDesc->Method.ParamCount));
326*cb565728SJerry Jelinek
327*cb565728SJerry Jelinek Status = AE_MISSING_ARGUMENTS;
328*cb565728SJerry Jelinek goto Cleanup;
329*cb565728SJerry Jelinek }
330*cb565728SJerry Jelinek
331*cb565728SJerry Jelinek else if (Info->ObjDesc->Method.ParamCount < Info->ParamCount)
332*cb565728SJerry Jelinek {
333*cb565728SJerry Jelinek ACPI_WARNING ((AE_INFO,
334*cb565728SJerry Jelinek "Excess arguments (%u) - only %u are required",
335*cb565728SJerry Jelinek Info->ParamCount,
336*cb565728SJerry Jelinek Info->ObjDesc->Method.ParamCount));
337*cb565728SJerry Jelinek
338*cb565728SJerry Jelinek /* Just pass the required number of arguments */
339*cb565728SJerry Jelinek
340*cb565728SJerry Jelinek Info->ParamCount = Info->ObjDesc->Method.ParamCount;
341*cb565728SJerry Jelinek }
342*cb565728SJerry Jelinek
343*cb565728SJerry Jelinek /*
344*cb565728SJerry Jelinek * Any incoming external objects to be passed as arguments to the
345*cb565728SJerry Jelinek * method must be converted to internal objects
346*cb565728SJerry Jelinek */
347*cb565728SJerry Jelinek if (Info->ParamCount)
348*cb565728SJerry Jelinek {
349*cb565728SJerry Jelinek /*
350*cb565728SJerry Jelinek * Allocate a new parameter block for the internal objects
351*cb565728SJerry Jelinek * Add 1 to count to allow for null terminated internal list
352*cb565728SJerry Jelinek */
353*cb565728SJerry Jelinek Info->Parameters = ACPI_ALLOCATE_ZEROED (
354*cb565728SJerry Jelinek ((ACPI_SIZE) Info->ParamCount + 1) * sizeof (void *));
355*cb565728SJerry Jelinek if (!Info->Parameters)
356*cb565728SJerry Jelinek {
357*cb565728SJerry Jelinek Status = AE_NO_MEMORY;
358*cb565728SJerry Jelinek goto Cleanup;
359*cb565728SJerry Jelinek }
360*cb565728SJerry Jelinek
361*cb565728SJerry Jelinek /* Convert each external object in the list to an internal object */
362*cb565728SJerry Jelinek
363*cb565728SJerry Jelinek for (i = 0; i < Info->ParamCount; i++)
364*cb565728SJerry Jelinek {
365*cb565728SJerry Jelinek Status = AcpiUtCopyEobjectToIobject (
366*cb565728SJerry Jelinek &ExternalParams->Pointer[i], &Info->Parameters[i]);
367*cb565728SJerry Jelinek if (ACPI_FAILURE (Status))
368*cb565728SJerry Jelinek {
369*cb565728SJerry Jelinek goto Cleanup;
370*cb565728SJerry Jelinek }
371*cb565728SJerry Jelinek }
372*cb565728SJerry Jelinek
373*cb565728SJerry Jelinek Info->Parameters[Info->ParamCount] = NULL;
374*cb565728SJerry Jelinek }
375*cb565728SJerry Jelinek break;
376*cb565728SJerry Jelinek
377*cb565728SJerry Jelinek default:
378*cb565728SJerry Jelinek
379*cb565728SJerry Jelinek /* Warn if arguments passed to an object that is not a method */
380*cb565728SJerry Jelinek
381*cb565728SJerry Jelinek if (Info->ParamCount)
382*cb565728SJerry Jelinek {
383*cb565728SJerry Jelinek ACPI_WARNING ((AE_INFO,
384*cb565728SJerry Jelinek "%u arguments were passed to a non-method ACPI object",
385*cb565728SJerry Jelinek Info->ParamCount));
386*cb565728SJerry Jelinek }
387*cb565728SJerry Jelinek break;
388*cb565728SJerry Jelinek }
389*cb565728SJerry Jelinek
390*cb565728SJerry Jelinek #endif
391*cb565728SJerry Jelinek
392*cb565728SJerry Jelinek
393*cb565728SJerry Jelinek /* Now we can evaluate the object */
394ae115bc7Smrj
395ae115bc7Smrj Status = AcpiNsEvaluate (Info);
396ae115bc7Smrj
397ae115bc7Smrj /*
398ae115bc7Smrj * If we are expecting a return value, and all went well above,
399ae115bc7Smrj * copy the return value to an external object.
400ae115bc7Smrj */
401*cb565728SJerry Jelinek if (!ReturnBuffer)
402ae115bc7Smrj {
403*cb565728SJerry Jelinek goto CleanupReturnObject;
404*cb565728SJerry Jelinek }
405*cb565728SJerry Jelinek
406ae115bc7Smrj if (!Info->ReturnObject)
407ae115bc7Smrj {
408ae115bc7Smrj ReturnBuffer->Length = 0;
409*cb565728SJerry Jelinek goto Cleanup;
410ae115bc7Smrj }
411*cb565728SJerry Jelinek
412ae115bc7Smrj if (ACPI_GET_DESCRIPTOR_TYPE (Info->ReturnObject) ==
413ae115bc7Smrj ACPI_DESC_TYPE_NAMED)
414ae115bc7Smrj {
415ae115bc7Smrj /*
416ae115bc7Smrj * If we received a NS Node as a return object, this means that
417ae115bc7Smrj * the object we are evaluating has nothing interesting to
418ae115bc7Smrj * return (such as a mutex, etc.) We return an error because
419ae115bc7Smrj * these types are essentially unsupported by this interface.
420ae115bc7Smrj * We don't check up front because this makes it easier to add
421ae115bc7Smrj * support for various types at a later date if necessary.
422ae115bc7Smrj */
423ae115bc7Smrj Status = AE_TYPE;
424ae115bc7Smrj Info->ReturnObject = NULL; /* No need to delete a NS Node */
425ae115bc7Smrj ReturnBuffer->Length = 0;
426ae115bc7Smrj }
427ae115bc7Smrj
428*cb565728SJerry Jelinek if (ACPI_FAILURE (Status))
429ae115bc7Smrj {
430*cb565728SJerry Jelinek goto CleanupReturnObject;
431*cb565728SJerry Jelinek }
432*cb565728SJerry Jelinek
433db2bae30SDana Myers /* Dereference Index and RefOf references */
434db2bae30SDana Myers
435db2bae30SDana Myers AcpiNsResolveReferences (Info);
436db2bae30SDana Myers
437ae115bc7Smrj /* Get the size of the returned object */
438ae115bc7Smrj
439ae115bc7Smrj Status = AcpiUtGetObjectSize (Info->ReturnObject,
440ae115bc7Smrj &BufferSpaceNeeded);
441ae115bc7Smrj if (ACPI_SUCCESS (Status))
442ae115bc7Smrj {
443ae115bc7Smrj /* Validate/Allocate/Clear caller buffer */
444ae115bc7Smrj
445ae115bc7Smrj Status = AcpiUtInitializeBuffer (ReturnBuffer,
446ae115bc7Smrj BufferSpaceNeeded);
447ae115bc7Smrj if (ACPI_FAILURE (Status))
448ae115bc7Smrj {
449ae115bc7Smrj /*
450ae115bc7Smrj * Caller's buffer is too small or a new one can't
451ae115bc7Smrj * be allocated
452ae115bc7Smrj */
453ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
454ae115bc7Smrj "Needed buffer size %X, %s\n",
455ae115bc7Smrj (UINT32) BufferSpaceNeeded,
456ae115bc7Smrj AcpiFormatException (Status)));
457ae115bc7Smrj }
458ae115bc7Smrj else
459ae115bc7Smrj {
460ae115bc7Smrj /* We have enough space for the object, build it */
461ae115bc7Smrj
462*cb565728SJerry Jelinek Status = AcpiUtCopyIobjectToEobject (
463*cb565728SJerry Jelinek Info->ReturnObject, ReturnBuffer);
464ae115bc7Smrj }
465ae115bc7Smrj }
466*cb565728SJerry Jelinek
467*cb565728SJerry Jelinek CleanupReturnObject:
468ae115bc7Smrj
469ae115bc7Smrj if (Info->ReturnObject)
470ae115bc7Smrj {
471ae115bc7Smrj /*
472ae115bc7Smrj * Delete the internal return object. NOTE: Interpreter must be
473ae115bc7Smrj * locked to avoid race condition.
474ae115bc7Smrj */
475db2bae30SDana Myers AcpiExEnterInterpreter ();
476db2bae30SDana Myers
477ae115bc7Smrj /* Remove one reference on the return object (should delete it) */
478ae115bc7Smrj
479ae115bc7Smrj AcpiUtRemoveReference (Info->ReturnObject);
480ae115bc7Smrj AcpiExExitInterpreter ();
481ae115bc7Smrj }
482ae115bc7Smrj
483ae115bc7Smrj
484ae115bc7Smrj Cleanup:
485ae115bc7Smrj
486ae115bc7Smrj /* Free the input parameter list (if we created one) */
487ae115bc7Smrj
488ae115bc7Smrj if (Info->Parameters)
489ae115bc7Smrj {
490ae115bc7Smrj /* Free the allocated parameter block */
491ae115bc7Smrj
492ae115bc7Smrj AcpiUtDeleteInternalObjectList (Info->Parameters);
493ae115bc7Smrj }
494ae115bc7Smrj
495ae115bc7Smrj ACPI_FREE (Info);
496ae115bc7Smrj return_ACPI_STATUS (Status);
497ae115bc7Smrj }
498ae115bc7Smrj
ACPI_EXPORT_SYMBOL(AcpiEvaluateObject)499ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiEvaluateObject)
500ae115bc7Smrj
501ae115bc7Smrj
502ae115bc7Smrj /*******************************************************************************
503ae115bc7Smrj *
504db2bae30SDana Myers * FUNCTION: AcpiNsResolveReferences
505db2bae30SDana Myers *
506db2bae30SDana Myers * PARAMETERS: Info - Evaluation info block
507db2bae30SDana Myers *
508db2bae30SDana Myers * RETURN: Info->ReturnObject is replaced with the dereferenced object
509db2bae30SDana Myers *
510db2bae30SDana Myers * DESCRIPTION: Dereference certain reference objects. Called before an
511db2bae30SDana Myers * internal return object is converted to an external ACPI_OBJECT.
512db2bae30SDana Myers *
513db2bae30SDana Myers * Performs an automatic dereference of Index and RefOf reference objects.
514db2bae30SDana Myers * These reference objects are not supported by the ACPI_OBJECT, so this is a
515db2bae30SDana Myers * last resort effort to return something useful. Also, provides compatibility
516db2bae30SDana Myers * with other ACPI implementations.
517db2bae30SDana Myers *
518db2bae30SDana Myers * NOTE: does not handle references within returned package objects or nested
519db2bae30SDana Myers * references, but this support could be added later if found to be necessary.
520db2bae30SDana Myers *
521db2bae30SDana Myers ******************************************************************************/
522db2bae30SDana Myers
523db2bae30SDana Myers static void
524db2bae30SDana Myers AcpiNsResolveReferences (
525db2bae30SDana Myers ACPI_EVALUATE_INFO *Info)
526db2bae30SDana Myers {
527db2bae30SDana Myers ACPI_OPERAND_OBJECT *ObjDesc = NULL;
528db2bae30SDana Myers ACPI_NAMESPACE_NODE *Node;
529db2bae30SDana Myers
530db2bae30SDana Myers
531db2bae30SDana Myers /* We are interested in reference objects only */
532db2bae30SDana Myers
533aa2aa9a6SDana Myers if ((Info->ReturnObject)->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
534db2bae30SDana Myers {
535db2bae30SDana Myers return;
536db2bae30SDana Myers }
537db2bae30SDana Myers
538db2bae30SDana Myers /*
539db2bae30SDana Myers * Two types of references are supported - those created by Index and
540db2bae30SDana Myers * RefOf operators. A name reference (AML_NAMEPATH_OP) can be converted
541db2bae30SDana Myers * to an ACPI_OBJECT, so it is not dereferenced here. A DdbHandle
542db2bae30SDana Myers * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
543db2bae30SDana Myers * an ACPI_OBJECT.
544db2bae30SDana Myers */
545db2bae30SDana Myers switch (Info->ReturnObject->Reference.Class)
546db2bae30SDana Myers {
547db2bae30SDana Myers case ACPI_REFCLASS_INDEX:
548db2bae30SDana Myers
549db2bae30SDana Myers ObjDesc = *(Info->ReturnObject->Reference.Where);
550db2bae30SDana Myers break;
551db2bae30SDana Myers
552db2bae30SDana Myers case ACPI_REFCLASS_REFOF:
553db2bae30SDana Myers
554db2bae30SDana Myers Node = Info->ReturnObject->Reference.Object;
555db2bae30SDana Myers if (Node)
556db2bae30SDana Myers {
557db2bae30SDana Myers ObjDesc = Node->Object;
558db2bae30SDana Myers }
559db2bae30SDana Myers break;
560db2bae30SDana Myers
561db2bae30SDana Myers default:
562*cb565728SJerry Jelinek
563db2bae30SDana Myers return;
564db2bae30SDana Myers }
565db2bae30SDana Myers
566db2bae30SDana Myers /* Replace the existing reference object */
567db2bae30SDana Myers
568db2bae30SDana Myers if (ObjDesc)
569db2bae30SDana Myers {
570db2bae30SDana Myers AcpiUtAddReference (ObjDesc);
571db2bae30SDana Myers AcpiUtRemoveReference (Info->ReturnObject);
572db2bae30SDana Myers Info->ReturnObject = ObjDesc;
573db2bae30SDana Myers }
574db2bae30SDana Myers
575db2bae30SDana Myers return;
576db2bae30SDana Myers }
577db2bae30SDana Myers
578db2bae30SDana Myers
579db2bae30SDana Myers /*******************************************************************************
580db2bae30SDana Myers *
581ae115bc7Smrj * FUNCTION: AcpiWalkNamespace
582ae115bc7Smrj *
583ae115bc7Smrj * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
584ae115bc7Smrj * StartObject - Handle in namespace where search begins
585ae115bc7Smrj * MaxDepth - Depth to which search is to reach
586*cb565728SJerry Jelinek * DescendingCallback - Called during tree descent
58757190917SDana Myers * when an object of "Type" is found
588*cb565728SJerry Jelinek * AscendingCallback - Called during tree ascent
58957190917SDana Myers * when an object of "Type" is found
59057190917SDana Myers * Context - Passed to user function(s) above
591ae115bc7Smrj * ReturnValue - Location where return value of
592ae115bc7Smrj * UserFunction is put if terminated early
593ae115bc7Smrj *
594ae115bc7Smrj * RETURNS Return value from the UserFunction if terminated early.
595ae115bc7Smrj * Otherwise, returns NULL.
596ae115bc7Smrj *
597ae115bc7Smrj * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
598ae115bc7Smrj * starting (and ending) at the object specified by StartHandle.
59957190917SDana Myers * The callback function is called whenever an object that matches
60057190917SDana Myers * the type parameter is found. If the callback function returns
601ae115bc7Smrj * a non-zero value, the search is terminated immediately and this
602ae115bc7Smrj * value is returned to the caller.
603ae115bc7Smrj *
604ae115bc7Smrj * The point of this procedure is to provide a generic namespace
605ae115bc7Smrj * walk routine that can be called from multiple places to
60657190917SDana Myers * provide multiple services; the callback function(s) can be
60757190917SDana Myers * tailored to each task, whether it is a print function,
60857190917SDana Myers * a compare function, etc.
609ae115bc7Smrj *
610ae115bc7Smrj ******************************************************************************/
611ae115bc7Smrj
612ae115bc7Smrj ACPI_STATUS
AcpiWalkNamespace(ACPI_OBJECT_TYPE Type,ACPI_HANDLE StartObject,UINT32 MaxDepth,ACPI_WALK_CALLBACK DescendingCallback,ACPI_WALK_CALLBACK AscendingCallback,void * Context,void ** ReturnValue)613ae115bc7Smrj AcpiWalkNamespace (
614ae115bc7Smrj ACPI_OBJECT_TYPE Type,
615ae115bc7Smrj ACPI_HANDLE StartObject,
616ae115bc7Smrj UINT32 MaxDepth,
617*cb565728SJerry Jelinek ACPI_WALK_CALLBACK DescendingCallback,
618*cb565728SJerry Jelinek ACPI_WALK_CALLBACK AscendingCallback,
619ae115bc7Smrj void *Context,
620ae115bc7Smrj void **ReturnValue)
621ae115bc7Smrj {
622ae115bc7Smrj ACPI_STATUS Status;
623ae115bc7Smrj
624ae115bc7Smrj
625ae115bc7Smrj ACPI_FUNCTION_TRACE (AcpiWalkNamespace);
626ae115bc7Smrj
627ae115bc7Smrj
628ae115bc7Smrj /* Parameter validation */
629ae115bc7Smrj
630ae115bc7Smrj if ((Type > ACPI_TYPE_LOCAL_MAX) ||
631ae115bc7Smrj (!MaxDepth) ||
632*cb565728SJerry Jelinek (!DescendingCallback && !AscendingCallback))
633ae115bc7Smrj {
634ae115bc7Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
635ae115bc7Smrj }
636ae115bc7Smrj
637ae115bc7Smrj /*
638aa2aa9a6SDana Myers * Need to acquire the namespace reader lock to prevent interference
639aa2aa9a6SDana Myers * with any concurrent table unloads (which causes the deletion of
640aa2aa9a6SDana Myers * namespace objects). We cannot allow the deletion of a namespace node
641aa2aa9a6SDana Myers * while the user function is using it. The exception to this are the
642aa2aa9a6SDana Myers * nodes created and deleted during control method execution -- these
643aa2aa9a6SDana Myers * nodes are marked as temporary nodes and are ignored by the namespace
644aa2aa9a6SDana Myers * walk. Thus, control methods can be executed while holding the
645aa2aa9a6SDana Myers * namespace deletion lock (and the user function can execute control
646aa2aa9a6SDana Myers * methods.)
647aa2aa9a6SDana Myers */
648aa2aa9a6SDana Myers Status = AcpiUtAcquireReadLock (&AcpiGbl_NamespaceRwLock);
649aa2aa9a6SDana Myers if (ACPI_FAILURE (Status))
650aa2aa9a6SDana Myers {
651*cb565728SJerry Jelinek return_ACPI_STATUS (Status);
652aa2aa9a6SDana Myers }
653aa2aa9a6SDana Myers
654aa2aa9a6SDana Myers /*
655aa2aa9a6SDana Myers * Lock the namespace around the walk. The namespace will be
656aa2aa9a6SDana Myers * unlocked/locked around each call to the user function - since the user
657aa2aa9a6SDana Myers * function must be allowed to make ACPICA calls itself (for example, it
658aa2aa9a6SDana Myers * will typically execute control methods during device enumeration.)
659ae115bc7Smrj */
660ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
661ae115bc7Smrj if (ACPI_FAILURE (Status))
662ae115bc7Smrj {
663aa2aa9a6SDana Myers goto UnlockAndExit;
664ae115bc7Smrj }
665ae115bc7Smrj
666*cb565728SJerry Jelinek /* Now we can validate the starting node */
667ae115bc7Smrj
668*cb565728SJerry Jelinek if (!AcpiNsValidateHandle (StartObject))
669*cb565728SJerry Jelinek {
670*cb565728SJerry Jelinek Status = AE_BAD_PARAMETER;
671*cb565728SJerry Jelinek goto UnlockAndExit2;
672*cb565728SJerry Jelinek }
673*cb565728SJerry Jelinek
674*cb565728SJerry Jelinek Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth,
675*cb565728SJerry Jelinek ACPI_NS_WALK_UNLOCK, DescendingCallback,
676*cb565728SJerry Jelinek AscendingCallback, Context, ReturnValue);
677*cb565728SJerry Jelinek
678*cb565728SJerry Jelinek UnlockAndExit2:
679ae115bc7Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
680aa2aa9a6SDana Myers
681aa2aa9a6SDana Myers UnlockAndExit:
682aa2aa9a6SDana Myers (void) AcpiUtReleaseReadLock (&AcpiGbl_NamespaceRwLock);
683ae115bc7Smrj return_ACPI_STATUS (Status);
684ae115bc7Smrj }
685ae115bc7Smrj
ACPI_EXPORT_SYMBOL(AcpiWalkNamespace)686ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiWalkNamespace)
687ae115bc7Smrj
688ae115bc7Smrj
689ae115bc7Smrj /*******************************************************************************
690ae115bc7Smrj *
691ae115bc7Smrj * FUNCTION: AcpiNsGetDeviceCallback
692ae115bc7Smrj *
693ae115bc7Smrj * PARAMETERS: Callback from AcpiGetDevice
694ae115bc7Smrj *
695ae115bc7Smrj * RETURN: Status
696ae115bc7Smrj *
697ae115bc7Smrj * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
698ae115bc7Smrj * present devices, or if they specified a HID, it filters based
699ae115bc7Smrj * on that.
700ae115bc7Smrj *
701ae115bc7Smrj ******************************************************************************/
702ae115bc7Smrj
703ae115bc7Smrj static ACPI_STATUS
704ae115bc7Smrj AcpiNsGetDeviceCallback (
705ae115bc7Smrj ACPI_HANDLE ObjHandle,
706ae115bc7Smrj UINT32 NestingLevel,
707ae115bc7Smrj void *Context,
708ae115bc7Smrj void **ReturnValue)
709ae115bc7Smrj {
710ae115bc7Smrj ACPI_GET_DEVICES_INFO *Info = Context;
711ae115bc7Smrj ACPI_STATUS Status;
712ae115bc7Smrj ACPI_NAMESPACE_NODE *Node;
713ae115bc7Smrj UINT32 Flags;
714*cb565728SJerry Jelinek ACPI_PNP_DEVICE_ID *Hid;
715*cb565728SJerry Jelinek ACPI_PNP_DEVICE_ID_LIST *Cid;
716db2bae30SDana Myers UINT32 i;
717db2bae30SDana Myers BOOLEAN Found;
71857190917SDana Myers int NoMatch;
719ae115bc7Smrj
720ae115bc7Smrj
721ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
722ae115bc7Smrj if (ACPI_FAILURE (Status))
723ae115bc7Smrj {
724ae115bc7Smrj return (Status);
725ae115bc7Smrj }
726ae115bc7Smrj
72726f3cdf0SGordon Ross Node = AcpiNsValidateHandle (ObjHandle);
728ae115bc7Smrj Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
729ae115bc7Smrj if (ACPI_FAILURE (Status))
730ae115bc7Smrj {
731ae115bc7Smrj return (Status);
732ae115bc7Smrj }
733ae115bc7Smrj
734ae115bc7Smrj if (!Node)
735ae115bc7Smrj {
736ae115bc7Smrj return (AE_BAD_PARAMETER);
737ae115bc7Smrj }
738ae115bc7Smrj
739db2bae30SDana Myers /*
74026f3cdf0SGordon Ross * First, filter based on the device HID and CID.
74126f3cdf0SGordon Ross *
74226f3cdf0SGordon Ross * 01/2010: For this case where a specific HID is requested, we don't
74326f3cdf0SGordon Ross * want to run _STA until we have an actual HID match. Thus, we will
74426f3cdf0SGordon Ross * not unnecessarily execute _STA on devices for which the caller
74526f3cdf0SGordon Ross * doesn't care about. Previously, _STA was executed unconditionally
74626f3cdf0SGordon Ross * on all devices found here.
74726f3cdf0SGordon Ross *
74826f3cdf0SGordon Ross * A side-effect of this change is that now we will continue to search
74926f3cdf0SGordon Ross * for a matching HID even under device trees where the parent device
75026f3cdf0SGordon Ross * would have returned a _STA that indicates it is not present or
75126f3cdf0SGordon Ross * not functioning (thus aborting the search on that branch).
752db2bae30SDana Myers */
753ae115bc7Smrj if (Info->Hid != NULL)
754ae115bc7Smrj {
755ae115bc7Smrj Status = AcpiUtExecute_HID (Node, &Hid);
756ae115bc7Smrj if (Status == AE_NOT_FOUND)
757ae115bc7Smrj {
758ae115bc7Smrj return (AE_OK);
759ae115bc7Smrj }
760ae115bc7Smrj else if (ACPI_FAILURE (Status))
761ae115bc7Smrj {
762ae115bc7Smrj return (AE_CTRL_DEPTH);
763ae115bc7Smrj }
764ae115bc7Smrj
765*cb565728SJerry Jelinek NoMatch = strcmp (Hid->String, Info->Hid);
76657190917SDana Myers ACPI_FREE (Hid);
76757190917SDana Myers
76857190917SDana Myers if (NoMatch)
769ae115bc7Smrj {
770db2bae30SDana Myers /*
771db2bae30SDana Myers * HID does not match, attempt match within the
772db2bae30SDana Myers * list of Compatible IDs (CIDs)
773db2bae30SDana Myers */
774ae115bc7Smrj Status = AcpiUtExecute_CID (Node, &Cid);
775ae115bc7Smrj if (Status == AE_NOT_FOUND)
776ae115bc7Smrj {
777ae115bc7Smrj return (AE_OK);
778ae115bc7Smrj }
779ae115bc7Smrj else if (ACPI_FAILURE (Status))
780ae115bc7Smrj {
781ae115bc7Smrj return (AE_CTRL_DEPTH);
782ae115bc7Smrj }
783ae115bc7Smrj
784ae115bc7Smrj /* Walk the CID list */
785ae115bc7Smrj
786db2bae30SDana Myers Found = FALSE;
787ae115bc7Smrj for (i = 0; i < Cid->Count; i++)
788ae115bc7Smrj {
789*cb565728SJerry Jelinek if (strcmp (Cid->Ids[i].String, Info->Hid) == 0)
790ae115bc7Smrj {
791db2bae30SDana Myers /* Found a matching CID */
792db2bae30SDana Myers
793db2bae30SDana Myers Found = TRUE;
794db2bae30SDana Myers break;
795db2bae30SDana Myers }
796db2bae30SDana Myers }
797db2bae30SDana Myers
798ae115bc7Smrj ACPI_FREE (Cid);
799db2bae30SDana Myers if (!Found)
800db2bae30SDana Myers {
801ae115bc7Smrj return (AE_OK);
802ae115bc7Smrj }
803ae115bc7Smrj }
804ae115bc7Smrj }
805db2bae30SDana Myers
80626f3cdf0SGordon Ross /* Run _STA to determine if device is present */
80726f3cdf0SGordon Ross
80826f3cdf0SGordon Ross Status = AcpiUtExecute_STA (Node, &Flags);
80926f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
81026f3cdf0SGordon Ross {
81126f3cdf0SGordon Ross return (AE_CTRL_DEPTH);
81226f3cdf0SGordon Ross }
81326f3cdf0SGordon Ross
81426f3cdf0SGordon Ross if (!(Flags & ACPI_STA_DEVICE_PRESENT) &&
81526f3cdf0SGordon Ross !(Flags & ACPI_STA_DEVICE_FUNCTIONING))
81626f3cdf0SGordon Ross {
81726f3cdf0SGordon Ross /*
81826f3cdf0SGordon Ross * Don't examine the children of the device only when the
81926f3cdf0SGordon Ross * device is neither present nor functional. See ACPI spec,
82026f3cdf0SGordon Ross * description of _STA for more information.
82126f3cdf0SGordon Ross */
82226f3cdf0SGordon Ross return (AE_CTRL_DEPTH);
82326f3cdf0SGordon Ross }
82426f3cdf0SGordon Ross
825db2bae30SDana Myers /* We have a valid device, invoke the user function */
826ae115bc7Smrj
827*cb565728SJerry Jelinek Status = Info->UserFunction (ObjHandle, NestingLevel,
828*cb565728SJerry Jelinek Info->Context, ReturnValue);
829ae115bc7Smrj return (Status);
830ae115bc7Smrj }
831ae115bc7Smrj
832ae115bc7Smrj
833ae115bc7Smrj /*******************************************************************************
834ae115bc7Smrj *
835ae115bc7Smrj * FUNCTION: AcpiGetDevices
836ae115bc7Smrj *
837ae115bc7Smrj * PARAMETERS: HID - HID to search for. Can be NULL.
838ae115bc7Smrj * UserFunction - Called when a matching object is found
839ae115bc7Smrj * Context - Passed to user function
840ae115bc7Smrj * ReturnValue - Location where return value of
841ae115bc7Smrj * UserFunction is put if terminated early
842ae115bc7Smrj *
843ae115bc7Smrj * RETURNS Return value from the UserFunction if terminated early.
844ae115bc7Smrj * Otherwise, returns NULL.
845ae115bc7Smrj *
846ae115bc7Smrj * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
847ae115bc7Smrj * starting (and ending) at the object specified by StartHandle.
848ae115bc7Smrj * The UserFunction is called whenever an object of type
849ae115bc7Smrj * Device is found. If the user function returns
850ae115bc7Smrj * a non-zero value, the search is terminated immediately and this
851ae115bc7Smrj * value is returned to the caller.
852ae115bc7Smrj *
853ae115bc7Smrj * This is a wrapper for WalkNamespace, but the callback performs
854db2bae30SDana Myers * additional filtering. Please see AcpiNsGetDeviceCallback.
855ae115bc7Smrj *
856ae115bc7Smrj ******************************************************************************/
857ae115bc7Smrj
858ae115bc7Smrj ACPI_STATUS
AcpiGetDevices(char * HID,ACPI_WALK_CALLBACK UserFunction,void * Context,void ** ReturnValue)859ae115bc7Smrj AcpiGetDevices (
860ae115bc7Smrj char *HID,
861ae115bc7Smrj ACPI_WALK_CALLBACK UserFunction,
862ae115bc7Smrj void *Context,
863ae115bc7Smrj void **ReturnValue)
864ae115bc7Smrj {
865ae115bc7Smrj ACPI_STATUS Status;
866ae115bc7Smrj ACPI_GET_DEVICES_INFO Info;
867ae115bc7Smrj
868ae115bc7Smrj
869ae115bc7Smrj ACPI_FUNCTION_TRACE (AcpiGetDevices);
870ae115bc7Smrj
871ae115bc7Smrj
872ae115bc7Smrj /* Parameter validation */
873ae115bc7Smrj
874ae115bc7Smrj if (!UserFunction)
875ae115bc7Smrj {
876ae115bc7Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
877ae115bc7Smrj }
878ae115bc7Smrj
879ae115bc7Smrj /*
880ae115bc7Smrj * We're going to call their callback from OUR callback, so we need
881ae115bc7Smrj * to know what it is, and their context parameter.
882ae115bc7Smrj */
883ae115bc7Smrj Info.Hid = HID;
884ae115bc7Smrj Info.Context = Context;
885ae115bc7Smrj Info.UserFunction = UserFunction;
886ae115bc7Smrj
887ae115bc7Smrj /*
888ae115bc7Smrj * Lock the namespace around the walk.
889ae115bc7Smrj * The namespace will be unlocked/locked around each call
890ae115bc7Smrj * to the user function - since this function
891ae115bc7Smrj * must be allowed to make Acpi calls itself.
892ae115bc7Smrj */
893ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
894ae115bc7Smrj if (ACPI_FAILURE (Status))
895ae115bc7Smrj {
896ae115bc7Smrj return_ACPI_STATUS (Status);
897ae115bc7Smrj }
898ae115bc7Smrj
899ae115bc7Smrj Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
900ae115bc7Smrj ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
90157190917SDana Myers AcpiNsGetDeviceCallback, NULL, &Info, ReturnValue);
902ae115bc7Smrj
903ae115bc7Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
904ae115bc7Smrj return_ACPI_STATUS (Status);
905ae115bc7Smrj }
906ae115bc7Smrj
ACPI_EXPORT_SYMBOL(AcpiGetDevices)907ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetDevices)
908ae115bc7Smrj
909ae115bc7Smrj
910ae115bc7Smrj /*******************************************************************************
911ae115bc7Smrj *
912ae115bc7Smrj * FUNCTION: AcpiAttachData
913ae115bc7Smrj *
914ae115bc7Smrj * PARAMETERS: ObjHandle - Namespace node
915ae115bc7Smrj * Handler - Handler for this attachment
916ae115bc7Smrj * Data - Pointer to data to be attached
917ae115bc7Smrj *
918ae115bc7Smrj * RETURN: Status
919ae115bc7Smrj *
920ae115bc7Smrj * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
921ae115bc7Smrj *
922ae115bc7Smrj ******************************************************************************/
923ae115bc7Smrj
924ae115bc7Smrj ACPI_STATUS
925ae115bc7Smrj AcpiAttachData (
926ae115bc7Smrj ACPI_HANDLE ObjHandle,
927ae115bc7Smrj ACPI_OBJECT_HANDLER Handler,
928ae115bc7Smrj void *Data)
929ae115bc7Smrj {
930ae115bc7Smrj ACPI_NAMESPACE_NODE *Node;
931ae115bc7Smrj ACPI_STATUS Status;
932ae115bc7Smrj
933ae115bc7Smrj
934ae115bc7Smrj /* Parameter validation */
935ae115bc7Smrj
936ae115bc7Smrj if (!ObjHandle ||
937ae115bc7Smrj !Handler ||
938ae115bc7Smrj !Data)
939ae115bc7Smrj {
940ae115bc7Smrj return (AE_BAD_PARAMETER);
941ae115bc7Smrj }
942ae115bc7Smrj
943ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
944ae115bc7Smrj if (ACPI_FAILURE (Status))
945ae115bc7Smrj {
946ae115bc7Smrj return (Status);
947ae115bc7Smrj }
948ae115bc7Smrj
949ae115bc7Smrj /* Convert and validate the handle */
950ae115bc7Smrj
95126f3cdf0SGordon Ross Node = AcpiNsValidateHandle (ObjHandle);
952ae115bc7Smrj if (!Node)
953ae115bc7Smrj {
954ae115bc7Smrj Status = AE_BAD_PARAMETER;
955ae115bc7Smrj goto UnlockAndExit;
956ae115bc7Smrj }
957ae115bc7Smrj
958ae115bc7Smrj Status = AcpiNsAttachData (Node, Handler, Data);
959ae115bc7Smrj
960ae115bc7Smrj UnlockAndExit:
961ae115bc7Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
962ae115bc7Smrj return (Status);
963ae115bc7Smrj }
964ae115bc7Smrj
ACPI_EXPORT_SYMBOL(AcpiAttachData)965ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiAttachData)
966ae115bc7Smrj
967ae115bc7Smrj
968ae115bc7Smrj /*******************************************************************************
969ae115bc7Smrj *
970ae115bc7Smrj * FUNCTION: AcpiDetachData
971ae115bc7Smrj *
972ae115bc7Smrj * PARAMETERS: ObjHandle - Namespace node handle
973ae115bc7Smrj * Handler - Handler used in call to AcpiAttachData
974ae115bc7Smrj *
975ae115bc7Smrj * RETURN: Status
976ae115bc7Smrj *
977ae115bc7Smrj * DESCRIPTION: Remove data that was previously attached to a node.
978ae115bc7Smrj *
979ae115bc7Smrj ******************************************************************************/
980ae115bc7Smrj
981ae115bc7Smrj ACPI_STATUS
982ae115bc7Smrj AcpiDetachData (
983ae115bc7Smrj ACPI_HANDLE ObjHandle,
984ae115bc7Smrj ACPI_OBJECT_HANDLER Handler)
985ae115bc7Smrj {
986ae115bc7Smrj ACPI_NAMESPACE_NODE *Node;
987ae115bc7Smrj ACPI_STATUS Status;
988ae115bc7Smrj
989ae115bc7Smrj
990ae115bc7Smrj /* Parameter validation */
991ae115bc7Smrj
992ae115bc7Smrj if (!ObjHandle ||
993ae115bc7Smrj !Handler)
994ae115bc7Smrj {
995ae115bc7Smrj return (AE_BAD_PARAMETER);
996ae115bc7Smrj }
997ae115bc7Smrj
998ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
999ae115bc7Smrj if (ACPI_FAILURE (Status))
1000ae115bc7Smrj {
1001ae115bc7Smrj return (Status);
1002ae115bc7Smrj }
1003ae115bc7Smrj
1004ae115bc7Smrj /* Convert and validate the handle */
1005ae115bc7Smrj
100626f3cdf0SGordon Ross Node = AcpiNsValidateHandle (ObjHandle);
1007ae115bc7Smrj if (!Node)
1008ae115bc7Smrj {
1009ae115bc7Smrj Status = AE_BAD_PARAMETER;
1010ae115bc7Smrj goto UnlockAndExit;
1011ae115bc7Smrj }
1012ae115bc7Smrj
1013ae115bc7Smrj Status = AcpiNsDetachData (Node, Handler);
1014ae115bc7Smrj
1015ae115bc7Smrj UnlockAndExit:
1016ae115bc7Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1017ae115bc7Smrj return (Status);
1018ae115bc7Smrj }
1019ae115bc7Smrj
ACPI_EXPORT_SYMBOL(AcpiDetachData)1020ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiDetachData)
1021ae115bc7Smrj
1022ae115bc7Smrj
1023ae115bc7Smrj /*******************************************************************************
1024ae115bc7Smrj *
1025ae115bc7Smrj * FUNCTION: AcpiGetData
1026ae115bc7Smrj *
1027ae115bc7Smrj * PARAMETERS: ObjHandle - Namespace node
1028ae115bc7Smrj * Handler - Handler used in call to AttachData
1029ae115bc7Smrj * Data - Where the data is returned
1030ae115bc7Smrj *
1031ae115bc7Smrj * RETURN: Status
1032ae115bc7Smrj *
1033ae115bc7Smrj * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
1034ae115bc7Smrj *
1035ae115bc7Smrj ******************************************************************************/
1036ae115bc7Smrj
1037ae115bc7Smrj ACPI_STATUS
1038ae115bc7Smrj AcpiGetData (
1039ae115bc7Smrj ACPI_HANDLE ObjHandle,
1040ae115bc7Smrj ACPI_OBJECT_HANDLER Handler,
1041ae115bc7Smrj void **Data)
1042ae115bc7Smrj {
1043ae115bc7Smrj ACPI_NAMESPACE_NODE *Node;
1044ae115bc7Smrj ACPI_STATUS Status;
1045ae115bc7Smrj
1046ae115bc7Smrj
1047ae115bc7Smrj /* Parameter validation */
1048ae115bc7Smrj
1049ae115bc7Smrj if (!ObjHandle ||
1050ae115bc7Smrj !Handler ||
1051ae115bc7Smrj !Data)
1052ae115bc7Smrj {
1053ae115bc7Smrj return (AE_BAD_PARAMETER);
1054ae115bc7Smrj }
1055ae115bc7Smrj
1056ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1057ae115bc7Smrj if (ACPI_FAILURE (Status))
1058ae115bc7Smrj {
1059ae115bc7Smrj return (Status);
1060ae115bc7Smrj }
1061ae115bc7Smrj
1062ae115bc7Smrj /* Convert and validate the handle */
1063ae115bc7Smrj
106426f3cdf0SGordon Ross Node = AcpiNsValidateHandle (ObjHandle);
1065ae115bc7Smrj if (!Node)
1066ae115bc7Smrj {
1067ae115bc7Smrj Status = AE_BAD_PARAMETER;
1068ae115bc7Smrj goto UnlockAndExit;
1069ae115bc7Smrj }
1070ae115bc7Smrj
1071ae115bc7Smrj Status = AcpiNsGetAttachedData (Node, Handler, Data);
1072ae115bc7Smrj
1073ae115bc7Smrj UnlockAndExit:
1074ae115bc7Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1075ae115bc7Smrj return (Status);
1076ae115bc7Smrj }
1077ae115bc7Smrj
1078ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetData)
1079