1 |
1275 |
phoenix |
/*******************************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Module Name: nsxfeval - Public interfaces to the ACPI subsystem
|
4 |
|
|
* ACPI Object evaluation interfaces
|
5 |
|
|
*
|
6 |
|
|
******************************************************************************/
|
7 |
|
|
|
8 |
|
|
/*
|
9 |
|
|
* Copyright (C) 2000 - 2004, R. Byron Moore
|
10 |
|
|
* All rights reserved.
|
11 |
|
|
*
|
12 |
|
|
* Redistribution and use in source and binary forms, with or without
|
13 |
|
|
* modification, are permitted provided that the following conditions
|
14 |
|
|
* are met:
|
15 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
16 |
|
|
* notice, this list of conditions, and the following disclaimer,
|
17 |
|
|
* without modification.
|
18 |
|
|
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
19 |
|
|
* substantially similar to the "NO WARRANTY" disclaimer below
|
20 |
|
|
* ("Disclaimer") and any redistribution must be conditioned upon
|
21 |
|
|
* including a substantially similar Disclaimer requirement for further
|
22 |
|
|
* binary redistribution.
|
23 |
|
|
* 3. Neither the names of the above-listed copyright holders nor the names
|
24 |
|
|
* of any contributors may be used to endorse or promote products derived
|
25 |
|
|
* from this software without specific prior written permission.
|
26 |
|
|
*
|
27 |
|
|
* Alternatively, this software may be distributed under the terms of the
|
28 |
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
29 |
|
|
* Software Foundation.
|
30 |
|
|
*
|
31 |
|
|
* NO WARRANTY
|
32 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
33 |
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
34 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
|
35 |
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
36 |
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
37 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
38 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
39 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
40 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
41 |
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
42 |
|
|
* POSSIBILITY OF SUCH DAMAGES.
|
43 |
|
|
*/
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
#include <acpi/acpi.h>
|
47 |
|
|
#include <acpi/acnamesp.h>
|
48 |
|
|
#include <acpi/acinterp.h>
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
#define _COMPONENT ACPI_NAMESPACE
|
52 |
|
|
ACPI_MODULE_NAME ("nsxfeval")
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
/*******************************************************************************
|
56 |
|
|
*
|
57 |
|
|
* FUNCTION: acpi_evaluate_object_typed
|
58 |
|
|
*
|
59 |
|
|
* PARAMETERS: Handle - Object handle (optional)
|
60 |
|
|
* *Pathname - Object pathname (optional)
|
61 |
|
|
* **external_params - List of parameters to pass to method,
|
62 |
|
|
* terminated by NULL. May be NULL
|
63 |
|
|
* if no parameters are being passed.
|
64 |
|
|
* *return_buffer - Where to put method's return value (if
|
65 |
|
|
* any). If NULL, no value is returned.
|
66 |
|
|
* return_type - Expected type of return object
|
67 |
|
|
*
|
68 |
|
|
* RETURN: Status
|
69 |
|
|
*
|
70 |
|
|
* DESCRIPTION: Find and evaluate the given object, passing the given
|
71 |
|
|
* parameters if necessary. One of "Handle" or "Pathname" must
|
72 |
|
|
* be valid (non-null)
|
73 |
|
|
*
|
74 |
|
|
******************************************************************************/
|
75 |
|
|
|
76 |
|
|
acpi_status
|
77 |
|
|
acpi_evaluate_object_typed (
|
78 |
|
|
acpi_handle handle,
|
79 |
|
|
acpi_string pathname,
|
80 |
|
|
struct acpi_object_list *external_params,
|
81 |
|
|
struct acpi_buffer *return_buffer,
|
82 |
|
|
acpi_object_type return_type)
|
83 |
|
|
{
|
84 |
|
|
acpi_status status;
|
85 |
|
|
u8 must_free = FALSE;
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
ACPI_FUNCTION_TRACE ("acpi_evaluate_object_typed");
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
/* Return buffer must be valid */
|
92 |
|
|
|
93 |
|
|
if (!return_buffer) {
|
94 |
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
|
98 |
|
|
must_free = TRUE;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
/* Evaluate the object */
|
102 |
|
|
|
103 |
|
|
status = acpi_evaluate_object (handle, pathname, external_params, return_buffer);
|
104 |
|
|
if (ACPI_FAILURE (status)) {
|
105 |
|
|
return_ACPI_STATUS (status);
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
/* Type ANY means "don't care" */
|
109 |
|
|
|
110 |
|
|
if (return_type == ACPI_TYPE_ANY) {
|
111 |
|
|
return_ACPI_STATUS (AE_OK);
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
if (return_buffer->length == 0) {
|
115 |
|
|
/* Error because caller specifically asked for a return value */
|
116 |
|
|
|
117 |
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
|
118 |
|
|
"No return value\n"));
|
119 |
|
|
|
120 |
|
|
return_ACPI_STATUS (AE_NULL_OBJECT);
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
/* Examine the object type returned from evaluate_object */
|
124 |
|
|
|
125 |
|
|
if (((union acpi_object *) return_buffer->pointer)->type == return_type) {
|
126 |
|
|
return_ACPI_STATUS (AE_OK);
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
/* Return object type does not match requested type */
|
130 |
|
|
|
131 |
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
|
132 |
|
|
"Incorrect return type [%s] requested [%s]\n",
|
133 |
|
|
acpi_ut_get_type_name (((union acpi_object *) return_buffer->pointer)->type),
|
134 |
|
|
acpi_ut_get_type_name (return_type)));
|
135 |
|
|
|
136 |
|
|
if (must_free) {
|
137 |
|
|
/* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
|
138 |
|
|
|
139 |
|
|
acpi_os_free (return_buffer->pointer);
|
140 |
|
|
return_buffer->pointer = NULL;
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
return_buffer->length = 0;
|
144 |
|
|
return_ACPI_STATUS (AE_TYPE);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
/*******************************************************************************
|
149 |
|
|
*
|
150 |
|
|
* FUNCTION: acpi_evaluate_object
|
151 |
|
|
*
|
152 |
|
|
* PARAMETERS: Handle - Object handle (optional)
|
153 |
|
|
* Pathname - Object pathname (optional)
|
154 |
|
|
* external_params - List of parameters to pass to method,
|
155 |
|
|
* terminated by NULL. May be NULL
|
156 |
|
|
* if no parameters are being passed.
|
157 |
|
|
* return_buffer - Where to put method's return value (if
|
158 |
|
|
* any). If NULL, no value is returned.
|
159 |
|
|
*
|
160 |
|
|
* RETURN: Status
|
161 |
|
|
*
|
162 |
|
|
* DESCRIPTION: Find and evaluate the given object, passing the given
|
163 |
|
|
* parameters if necessary. One of "Handle" or "Pathname" must
|
164 |
|
|
* be valid (non-null)
|
165 |
|
|
*
|
166 |
|
|
******************************************************************************/
|
167 |
|
|
|
168 |
|
|
acpi_status
|
169 |
|
|
acpi_evaluate_object (
|
170 |
|
|
acpi_handle handle,
|
171 |
|
|
acpi_string pathname,
|
172 |
|
|
struct acpi_object_list *external_params,
|
173 |
|
|
struct acpi_buffer *return_buffer)
|
174 |
|
|
{
|
175 |
|
|
acpi_status status;
|
176 |
|
|
acpi_status status2;
|
177 |
|
|
union acpi_operand_object **internal_params = NULL;
|
178 |
|
|
union acpi_operand_object *internal_return_obj = NULL;
|
179 |
|
|
acpi_size buffer_space_needed;
|
180 |
|
|
u32 i;
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
ACPI_FUNCTION_TRACE ("acpi_evaluate_object");
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
/*
|
187 |
|
|
* If there are parameters to be passed to the object
|
188 |
|
|
* (which must be a control method), the external objects
|
189 |
|
|
* must be converted to internal objects
|
190 |
|
|
*/
|
191 |
|
|
if (external_params && external_params->count) {
|
192 |
|
|
/*
|
193 |
|
|
* Allocate a new parameter block for the internal objects
|
194 |
|
|
* Add 1 to count to allow for null terminated internal list
|
195 |
|
|
*/
|
196 |
|
|
internal_params = ACPI_MEM_CALLOCATE (((acpi_size) external_params->count + 1) *
|
197 |
|
|
sizeof (void *));
|
198 |
|
|
if (!internal_params) {
|
199 |
|
|
return_ACPI_STATUS (AE_NO_MEMORY);
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
/*
|
203 |
|
|
* Convert each external object in the list to an
|
204 |
|
|
* internal object
|
205 |
|
|
*/
|
206 |
|
|
for (i = 0; i < external_params->count; i++) {
|
207 |
|
|
status = acpi_ut_copy_eobject_to_iobject (&external_params->pointer[i],
|
208 |
|
|
&internal_params[i]);
|
209 |
|
|
if (ACPI_FAILURE (status)) {
|
210 |
|
|
acpi_ut_delete_internal_object_list (internal_params);
|
211 |
|
|
return_ACPI_STATUS (status);
|
212 |
|
|
}
|
213 |
|
|
}
|
214 |
|
|
internal_params[external_params->count] = NULL;
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
/*
|
218 |
|
|
* Three major cases:
|
219 |
|
|
* 1) Fully qualified pathname
|
220 |
|
|
* 2) No handle, not fully qualified pathname (error)
|
221 |
|
|
* 3) Valid handle
|
222 |
|
|
*/
|
223 |
|
|
if ((pathname) &&
|
224 |
|
|
(acpi_ns_valid_root_prefix (pathname[0]))) {
|
225 |
|
|
/*
|
226 |
|
|
* The path is fully qualified, just evaluate by name
|
227 |
|
|
*/
|
228 |
|
|
status = acpi_ns_evaluate_by_name (pathname, internal_params,
|
229 |
|
|
&internal_return_obj);
|
230 |
|
|
}
|
231 |
|
|
else if (!handle) {
|
232 |
|
|
/*
|
233 |
|
|
* A handle is optional iff a fully qualified pathname
|
234 |
|
|
* is specified. Since we've already handled fully
|
235 |
|
|
* qualified names above, this is an error
|
236 |
|
|
*/
|
237 |
|
|
if (!pathname) {
|
238 |
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
|
239 |
|
|
"Both Handle and Pathname are NULL\n"));
|
240 |
|
|
}
|
241 |
|
|
else {
|
242 |
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
|
243 |
|
|
"Handle is NULL and Pathname is relative\n"));
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
status = AE_BAD_PARAMETER;
|
247 |
|
|
}
|
248 |
|
|
else {
|
249 |
|
|
/*
|
250 |
|
|
* We get here if we have a handle -- and if we have a
|
251 |
|
|
* pathname it is relative. The handle will be validated
|
252 |
|
|
* in the lower procedures
|
253 |
|
|
*/
|
254 |
|
|
if (!pathname) {
|
255 |
|
|
/*
|
256 |
|
|
* The null pathname case means the handle is for
|
257 |
|
|
* the actual object to be evaluated
|
258 |
|
|
*/
|
259 |
|
|
status = acpi_ns_evaluate_by_handle (handle, internal_params,
|
260 |
|
|
&internal_return_obj);
|
261 |
|
|
}
|
262 |
|
|
else {
|
263 |
|
|
/*
|
264 |
|
|
* Both a Handle and a relative Pathname
|
265 |
|
|
*/
|
266 |
|
|
status = acpi_ns_evaluate_relative (handle, pathname, internal_params,
|
267 |
|
|
&internal_return_obj);
|
268 |
|
|
}
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
/*
|
273 |
|
|
* If we are expecting a return value, and all went well above,
|
274 |
|
|
* copy the return value to an external object.
|
275 |
|
|
*/
|
276 |
|
|
if (return_buffer) {
|
277 |
|
|
if (!internal_return_obj) {
|
278 |
|
|
return_buffer->length = 0;
|
279 |
|
|
}
|
280 |
|
|
else {
|
281 |
|
|
if (ACPI_GET_DESCRIPTOR_TYPE (internal_return_obj) == ACPI_DESC_TYPE_NAMED) {
|
282 |
|
|
/*
|
283 |
|
|
* If we received a NS Node as a return object, this means that
|
284 |
|
|
* the object we are evaluating has nothing interesting to
|
285 |
|
|
* return (such as a mutex, etc.) We return an error because
|
286 |
|
|
* these types are essentially unsupported by this interface.
|
287 |
|
|
* We don't check up front because this makes it easier to add
|
288 |
|
|
* support for various types at a later date if necessary.
|
289 |
|
|
*/
|
290 |
|
|
status = AE_TYPE;
|
291 |
|
|
internal_return_obj = NULL; /* No need to delete a NS Node */
|
292 |
|
|
return_buffer->length = 0;
|
293 |
|
|
}
|
294 |
|
|
|
295 |
|
|
if (ACPI_SUCCESS (status)) {
|
296 |
|
|
/*
|
297 |
|
|
* Find out how large a buffer is needed
|
298 |
|
|
* to contain the returned object
|
299 |
|
|
*/
|
300 |
|
|
status = acpi_ut_get_object_size (internal_return_obj,
|
301 |
|
|
&buffer_space_needed);
|
302 |
|
|
if (ACPI_SUCCESS (status)) {
|
303 |
|
|
/* Validate/Allocate/Clear caller buffer */
|
304 |
|
|
|
305 |
|
|
status = acpi_ut_initialize_buffer (return_buffer, buffer_space_needed);
|
306 |
|
|
if (ACPI_FAILURE (status)) {
|
307 |
|
|
/*
|
308 |
|
|
* Caller's buffer is too small or a new one can't be allocated
|
309 |
|
|
*/
|
310 |
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
|
311 |
|
|
"Needed buffer size %X, %s\n",
|
312 |
|
|
(u32) buffer_space_needed, acpi_format_exception (status)));
|
313 |
|
|
}
|
314 |
|
|
else {
|
315 |
|
|
/*
|
316 |
|
|
* We have enough space for the object, build it
|
317 |
|
|
*/
|
318 |
|
|
status = acpi_ut_copy_iobject_to_eobject (internal_return_obj,
|
319 |
|
|
return_buffer);
|
320 |
|
|
}
|
321 |
|
|
}
|
322 |
|
|
}
|
323 |
|
|
}
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
if (internal_return_obj) {
|
327 |
|
|
/*
|
328 |
|
|
* Delete the internal return object. NOTE: Interpreter
|
329 |
|
|
* must be locked to avoid race condition.
|
330 |
|
|
*/
|
331 |
|
|
status2 = acpi_ex_enter_interpreter ();
|
332 |
|
|
if (ACPI_SUCCESS (status2)) {
|
333 |
|
|
/*
|
334 |
|
|
* Delete the internal return object. (Or at least
|
335 |
|
|
* decrement the reference count by one)
|
336 |
|
|
*/
|
337 |
|
|
acpi_ut_remove_reference (internal_return_obj);
|
338 |
|
|
acpi_ex_exit_interpreter ();
|
339 |
|
|
}
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
/*
|
343 |
|
|
* Free the input parameter list (if we created one),
|
344 |
|
|
*/
|
345 |
|
|
if (internal_params) {
|
346 |
|
|
/* Free the allocated parameter block */
|
347 |
|
|
|
348 |
|
|
acpi_ut_delete_internal_object_list (internal_params);
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
return_ACPI_STATUS (status);
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
/*******************************************************************************
|
356 |
|
|
*
|
357 |
|
|
* FUNCTION: acpi_walk_namespace
|
358 |
|
|
*
|
359 |
|
|
* PARAMETERS: Type - acpi_object_type to search for
|
360 |
|
|
* start_object - Handle in namespace where search begins
|
361 |
|
|
* max_depth - Depth to which search is to reach
|
362 |
|
|
* user_function - Called when an object of "Type" is found
|
363 |
|
|
* Context - Passed to user function
|
364 |
|
|
* return_value - Location where return value of
|
365 |
|
|
* user_function is put if terminated early
|
366 |
|
|
*
|
367 |
|
|
* RETURNS Return value from the user_function if terminated early.
|
368 |
|
|
* Otherwise, returns NULL.
|
369 |
|
|
*
|
370 |
|
|
* DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
|
371 |
|
|
* starting (and ending) at the object specified by start_handle.
|
372 |
|
|
* The user_function is called whenever an object that matches
|
373 |
|
|
* the type parameter is found. If the user function returns
|
374 |
|
|
* a non-zero value, the search is terminated immediately and this
|
375 |
|
|
* value is returned to the caller.
|
376 |
|
|
*
|
377 |
|
|
* The point of this procedure is to provide a generic namespace
|
378 |
|
|
* walk routine that can be called from multiple places to
|
379 |
|
|
* provide multiple services; the User Function can be tailored
|
380 |
|
|
* to each task, whether it is a print function, a compare
|
381 |
|
|
* function, etc.
|
382 |
|
|
*
|
383 |
|
|
******************************************************************************/
|
384 |
|
|
|
385 |
|
|
acpi_status
|
386 |
|
|
acpi_walk_namespace (
|
387 |
|
|
acpi_object_type type,
|
388 |
|
|
acpi_handle start_object,
|
389 |
|
|
u32 max_depth,
|
390 |
|
|
acpi_walk_callback user_function,
|
391 |
|
|
void *context,
|
392 |
|
|
void **return_value)
|
393 |
|
|
{
|
394 |
|
|
acpi_status status;
|
395 |
|
|
|
396 |
|
|
|
397 |
|
|
ACPI_FUNCTION_TRACE ("acpi_walk_namespace");
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
/* Parameter validation */
|
401 |
|
|
|
402 |
|
|
if ((type > ACPI_TYPE_EXTERNAL_MAX) ||
|
403 |
|
|
(!max_depth) ||
|
404 |
|
|
(!user_function)) {
|
405 |
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
406 |
|
|
}
|
407 |
|
|
|
408 |
|
|
/*
|
409 |
|
|
* Lock the namespace around the walk.
|
410 |
|
|
* The namespace will be unlocked/locked around each call
|
411 |
|
|
* to the user function - since this function
|
412 |
|
|
* must be allowed to make Acpi calls itself.
|
413 |
|
|
*/
|
414 |
|
|
status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
|
415 |
|
|
if (ACPI_FAILURE (status)) {
|
416 |
|
|
return_ACPI_STATUS (status);
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
status = acpi_ns_walk_namespace (type, start_object, max_depth, ACPI_NS_WALK_UNLOCK,
|
420 |
|
|
user_function, context, return_value);
|
421 |
|
|
|
422 |
|
|
(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
|
423 |
|
|
return_ACPI_STATUS (status);
|
424 |
|
|
}
|
425 |
|
|
|
426 |
|
|
|
427 |
|
|
/*******************************************************************************
|
428 |
|
|
*
|
429 |
|
|
* FUNCTION: acpi_ns_get_device_callback
|
430 |
|
|
*
|
431 |
|
|
* PARAMETERS: Callback from acpi_get_device
|
432 |
|
|
*
|
433 |
|
|
* RETURN: Status
|
434 |
|
|
*
|
435 |
|
|
* DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
|
436 |
|
|
* present devices, or if they specified a HID, it filters based
|
437 |
|
|
* on that.
|
438 |
|
|
*
|
439 |
|
|
******************************************************************************/
|
440 |
|
|
|
441 |
|
|
static acpi_status
|
442 |
|
|
acpi_ns_get_device_callback (
|
443 |
|
|
acpi_handle obj_handle,
|
444 |
|
|
u32 nesting_level,
|
445 |
|
|
void *context,
|
446 |
|
|
void **return_value)
|
447 |
|
|
{
|
448 |
|
|
struct acpi_get_devices_info *info = context;
|
449 |
|
|
acpi_status status;
|
450 |
|
|
struct acpi_namespace_node *node;
|
451 |
|
|
u32 flags;
|
452 |
|
|
struct acpi_device_id hid;
|
453 |
|
|
struct acpi_compatible_id_list *cid;
|
454 |
|
|
acpi_native_uint i;
|
455 |
|
|
|
456 |
|
|
|
457 |
|
|
status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
|
458 |
|
|
if (ACPI_FAILURE (status)) {
|
459 |
|
|
return (status);
|
460 |
|
|
}
|
461 |
|
|
|
462 |
|
|
node = acpi_ns_map_handle_to_node (obj_handle);
|
463 |
|
|
status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
|
464 |
|
|
if (ACPI_FAILURE (status)) {
|
465 |
|
|
return (status);
|
466 |
|
|
}
|
467 |
|
|
|
468 |
|
|
if (!node) {
|
469 |
|
|
return (AE_BAD_PARAMETER);
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
/* Run _STA to determine if device is present */
|
473 |
|
|
|
474 |
|
|
status = acpi_ut_execute_STA (node, &flags);
|
475 |
|
|
if (ACPI_FAILURE (status)) {
|
476 |
|
|
return (AE_CTRL_DEPTH);
|
477 |
|
|
}
|
478 |
|
|
|
479 |
|
|
if (!(flags & 0x01)) {
|
480 |
|
|
/* Don't return at the device or children of the device if not there */
|
481 |
|
|
|
482 |
|
|
return (AE_CTRL_DEPTH);
|
483 |
|
|
}
|
484 |
|
|
|
485 |
|
|
/* Filter based on device HID & CID */
|
486 |
|
|
|
487 |
|
|
if (info->hid != NULL) {
|
488 |
|
|
status = acpi_ut_execute_HID (node, &hid);
|
489 |
|
|
if (status == AE_NOT_FOUND) {
|
490 |
|
|
return (AE_OK);
|
491 |
|
|
}
|
492 |
|
|
else if (ACPI_FAILURE (status)) {
|
493 |
|
|
return (AE_CTRL_DEPTH);
|
494 |
|
|
}
|
495 |
|
|
|
496 |
|
|
if (ACPI_STRNCMP (hid.value, info->hid, sizeof (hid.value)) != 0) {
|
497 |
|
|
/* Get the list of Compatible IDs */
|
498 |
|
|
|
499 |
|
|
status = acpi_ut_execute_CID (node, &cid);
|
500 |
|
|
if (status == AE_NOT_FOUND) {
|
501 |
|
|
return (AE_OK);
|
502 |
|
|
}
|
503 |
|
|
else if (ACPI_FAILURE (status)) {
|
504 |
|
|
return (AE_CTRL_DEPTH);
|
505 |
|
|
}
|
506 |
|
|
|
507 |
|
|
/* Walk the CID list */
|
508 |
|
|
|
509 |
|
|
for (i = 0; i < cid->count; i++) {
|
510 |
|
|
if (ACPI_STRNCMP (cid->id[i].value, info->hid,
|
511 |
|
|
sizeof (struct acpi_compatible_id)) != 0) {
|
512 |
|
|
ACPI_MEM_FREE (cid);
|
513 |
|
|
return (AE_OK);
|
514 |
|
|
}
|
515 |
|
|
}
|
516 |
|
|
ACPI_MEM_FREE (cid);
|
517 |
|
|
}
|
518 |
|
|
}
|
519 |
|
|
|
520 |
|
|
status = info->user_function (obj_handle, nesting_level, info->context, return_value);
|
521 |
|
|
return (status);
|
522 |
|
|
}
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
/*******************************************************************************
|
526 |
|
|
*
|
527 |
|
|
* FUNCTION: acpi_get_devices
|
528 |
|
|
*
|
529 |
|
|
* PARAMETERS: HID - HID to search for. Can be NULL.
|
530 |
|
|
* user_function - Called when a matching object is found
|
531 |
|
|
* Context - Passed to user function
|
532 |
|
|
* return_value - Location where return value of
|
533 |
|
|
* user_function is put if terminated early
|
534 |
|
|
*
|
535 |
|
|
* RETURNS Return value from the user_function if terminated early.
|
536 |
|
|
* Otherwise, returns NULL.
|
537 |
|
|
*
|
538 |
|
|
* DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
|
539 |
|
|
* starting (and ending) at the object specified by start_handle.
|
540 |
|
|
* The user_function is called whenever an object of type
|
541 |
|
|
* Device is found. If the user function returns
|
542 |
|
|
* a non-zero value, the search is terminated immediately and this
|
543 |
|
|
* value is returned to the caller.
|
544 |
|
|
*
|
545 |
|
|
* This is a wrapper for walk_namespace, but the callback performs
|
546 |
|
|
* additional filtering. Please see acpi_get_device_callback.
|
547 |
|
|
*
|
548 |
|
|
******************************************************************************/
|
549 |
|
|
|
550 |
|
|
acpi_status
|
551 |
|
|
acpi_get_devices (
|
552 |
|
|
char *HID,
|
553 |
|
|
acpi_walk_callback user_function,
|
554 |
|
|
void *context,
|
555 |
|
|
void **return_value)
|
556 |
|
|
{
|
557 |
|
|
acpi_status status;
|
558 |
|
|
struct acpi_get_devices_info info;
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
ACPI_FUNCTION_TRACE ("acpi_get_devices");
|
562 |
|
|
|
563 |
|
|
|
564 |
|
|
/* Parameter validation */
|
565 |
|
|
|
566 |
|
|
if (!user_function) {
|
567 |
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
568 |
|
|
}
|
569 |
|
|
|
570 |
|
|
/*
|
571 |
|
|
* We're going to call their callback from OUR callback, so we need
|
572 |
|
|
* to know what it is, and their context parameter.
|
573 |
|
|
*/
|
574 |
|
|
info.context = context;
|
575 |
|
|
info.user_function = user_function;
|
576 |
|
|
info.hid = HID;
|
577 |
|
|
|
578 |
|
|
/*
|
579 |
|
|
* Lock the namespace around the walk.
|
580 |
|
|
* The namespace will be unlocked/locked around each call
|
581 |
|
|
* to the user function - since this function
|
582 |
|
|
* must be allowed to make Acpi calls itself.
|
583 |
|
|
*/
|
584 |
|
|
status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
|
585 |
|
|
if (ACPI_FAILURE (status)) {
|
586 |
|
|
return_ACPI_STATUS (status);
|
587 |
|
|
}
|
588 |
|
|
|
589 |
|
|
status = acpi_ns_walk_namespace (ACPI_TYPE_DEVICE,
|
590 |
|
|
ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
|
591 |
|
|
ACPI_NS_WALK_UNLOCK,
|
592 |
|
|
acpi_ns_get_device_callback, &info,
|
593 |
|
|
return_value);
|
594 |
|
|
|
595 |
|
|
(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
|
596 |
|
|
return_ACPI_STATUS (status);
|
597 |
|
|
}
|
598 |
|
|
|
599 |
|
|
|
600 |
|
|
/*******************************************************************************
|
601 |
|
|
*
|
602 |
|
|
* FUNCTION: acpi_attach_data
|
603 |
|
|
*
|
604 |
|
|
* PARAMETERS: obj_handle - Namespace node
|
605 |
|
|
* Handler - Handler for this attachment
|
606 |
|
|
* Data - Pointer to data to be attached
|
607 |
|
|
*
|
608 |
|
|
* RETURN: Status
|
609 |
|
|
*
|
610 |
|
|
* DESCRIPTION: Attach arbitrary data and handler to a namespace node.
|
611 |
|
|
*
|
612 |
|
|
******************************************************************************/
|
613 |
|
|
|
614 |
|
|
acpi_status
|
615 |
|
|
acpi_attach_data (
|
616 |
|
|
acpi_handle obj_handle,
|
617 |
|
|
acpi_object_handler handler,
|
618 |
|
|
void *data)
|
619 |
|
|
{
|
620 |
|
|
struct acpi_namespace_node *node;
|
621 |
|
|
acpi_status status;
|
622 |
|
|
|
623 |
|
|
|
624 |
|
|
/* Parameter validation */
|
625 |
|
|
|
626 |
|
|
if (!obj_handle ||
|
627 |
|
|
!handler ||
|
628 |
|
|
!data) {
|
629 |
|
|
return (AE_BAD_PARAMETER);
|
630 |
|
|
}
|
631 |
|
|
|
632 |
|
|
status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
|
633 |
|
|
if (ACPI_FAILURE (status)) {
|
634 |
|
|
return (status);
|
635 |
|
|
}
|
636 |
|
|
|
637 |
|
|
/* Convert and validate the handle */
|
638 |
|
|
|
639 |
|
|
node = acpi_ns_map_handle_to_node (obj_handle);
|
640 |
|
|
if (!node) {
|
641 |
|
|
status = AE_BAD_PARAMETER;
|
642 |
|
|
goto unlock_and_exit;
|
643 |
|
|
}
|
644 |
|
|
|
645 |
|
|
status = acpi_ns_attach_data (node, handler, data);
|
646 |
|
|
|
647 |
|
|
unlock_and_exit:
|
648 |
|
|
(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
|
649 |
|
|
return (status);
|
650 |
|
|
}
|
651 |
|
|
|
652 |
|
|
|
653 |
|
|
/*******************************************************************************
|
654 |
|
|
*
|
655 |
|
|
* FUNCTION: acpi_detach_data
|
656 |
|
|
*
|
657 |
|
|
* PARAMETERS: obj_handle - Namespace node handle
|
658 |
|
|
* Handler - Handler used in call to acpi_attach_data
|
659 |
|
|
*
|
660 |
|
|
* RETURN: Status
|
661 |
|
|
*
|
662 |
|
|
* DESCRIPTION: Remove data that was previously attached to a node.
|
663 |
|
|
*
|
664 |
|
|
******************************************************************************/
|
665 |
|
|
|
666 |
|
|
acpi_status
|
667 |
|
|
acpi_detach_data (
|
668 |
|
|
acpi_handle obj_handle,
|
669 |
|
|
acpi_object_handler handler)
|
670 |
|
|
{
|
671 |
|
|
struct acpi_namespace_node *node;
|
672 |
|
|
acpi_status status;
|
673 |
|
|
|
674 |
|
|
|
675 |
|
|
/* Parameter validation */
|
676 |
|
|
|
677 |
|
|
if (!obj_handle ||
|
678 |
|
|
!handler) {
|
679 |
|
|
return (AE_BAD_PARAMETER);
|
680 |
|
|
}
|
681 |
|
|
|
682 |
|
|
status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
|
683 |
|
|
if (ACPI_FAILURE (status)) {
|
684 |
|
|
return (status);
|
685 |
|
|
}
|
686 |
|
|
|
687 |
|
|
/* Convert and validate the handle */
|
688 |
|
|
|
689 |
|
|
node = acpi_ns_map_handle_to_node (obj_handle);
|
690 |
|
|
if (!node) {
|
691 |
|
|
status = AE_BAD_PARAMETER;
|
692 |
|
|
goto unlock_and_exit;
|
693 |
|
|
}
|
694 |
|
|
|
695 |
|
|
status = acpi_ns_detach_data (node, handler);
|
696 |
|
|
|
697 |
|
|
unlock_and_exit:
|
698 |
|
|
(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
|
699 |
|
|
return (status);
|
700 |
|
|
}
|
701 |
|
|
|
702 |
|
|
|
703 |
|
|
/*******************************************************************************
|
704 |
|
|
*
|
705 |
|
|
* FUNCTION: acpi_get_data
|
706 |
|
|
*
|
707 |
|
|
* PARAMETERS: obj_handle - Namespace node
|
708 |
|
|
* Handler - Handler used in call to attach_data
|
709 |
|
|
* Data - Where the data is returned
|
710 |
|
|
*
|
711 |
|
|
* RETURN: Status
|
712 |
|
|
*
|
713 |
|
|
* DESCRIPTION: Retrieve data that was previously attached to a namespace node.
|
714 |
|
|
*
|
715 |
|
|
******************************************************************************/
|
716 |
|
|
|
717 |
|
|
acpi_status
|
718 |
|
|
acpi_get_data (
|
719 |
|
|
acpi_handle obj_handle,
|
720 |
|
|
acpi_object_handler handler,
|
721 |
|
|
void **data)
|
722 |
|
|
{
|
723 |
|
|
struct acpi_namespace_node *node;
|
724 |
|
|
acpi_status status;
|
725 |
|
|
|
726 |
|
|
|
727 |
|
|
/* Parameter validation */
|
728 |
|
|
|
729 |
|
|
if (!obj_handle ||
|
730 |
|
|
!handler ||
|
731 |
|
|
!data) {
|
732 |
|
|
return (AE_BAD_PARAMETER);
|
733 |
|
|
}
|
734 |
|
|
|
735 |
|
|
status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
|
736 |
|
|
if (ACPI_FAILURE (status)) {
|
737 |
|
|
return (status);
|
738 |
|
|
}
|
739 |
|
|
|
740 |
|
|
/* Convert and validate the handle */
|
741 |
|
|
|
742 |
|
|
node = acpi_ns_map_handle_to_node (obj_handle);
|
743 |
|
|
if (!node) {
|
744 |
|
|
status = AE_BAD_PARAMETER;
|
745 |
|
|
goto unlock_and_exit;
|
746 |
|
|
}
|
747 |
|
|
|
748 |
|
|
status = acpi_ns_get_attached_data (node, handler, data);
|
749 |
|
|
|
750 |
|
|
unlock_and_exit:
|
751 |
|
|
(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
|
752 |
|
|
return (status);
|
753 |
|
|
}
|
754 |
|
|
|
755 |
|
|
|