[SERIAL] Ensure 8250_pci quirks are not marked __devinit
[linux-2.6/verdex.git] / drivers / acpi / namespace / nsxfeval.c
bloba95f636dc35d454e16865732cff8e4c57ab3731f
1 /*******************************************************************************
3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4 * ACPI Object evaluation interfaces
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2006, R. Byron Moore
10 * All rights reserved.
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.
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.
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.
45 #include <linux/module.h>
47 #include <acpi/acpi.h>
48 #include <acpi/acnamesp.h>
49 #include <acpi/acinterp.h>
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME("nsxfeval")
54 /*******************************************************************************
56 * FUNCTION: acpi_evaluate_object_typed
58 * PARAMETERS: Handle - Object handle (optional)
59 * Pathname - Object pathname (optional)
60 * external_params - List of parameters to pass to method,
61 * terminated by NULL. May be NULL
62 * if no parameters are being passed.
63 * return_buffer - Where to put method's return value (if
64 * any). If NULL, no value is returned.
65 * return_type - Expected type of return object
67 * RETURN: Status
69 * DESCRIPTION: Find and evaluate the given object, passing the given
70 * parameters if necessary. One of "Handle" or "Pathname" must
71 * be valid (non-null)
73 ******************************************************************************/
74 #ifdef ACPI_FUTURE_USAGE
75 acpi_status
76 acpi_evaluate_object_typed(acpi_handle handle,
77 acpi_string pathname,
78 struct acpi_object_list *external_params,
79 struct acpi_buffer *return_buffer,
80 acpi_object_type return_type)
82 acpi_status status;
83 u8 must_free = FALSE;
85 ACPI_FUNCTION_TRACE("acpi_evaluate_object_typed");
87 /* Return buffer must be valid */
89 if (!return_buffer) {
90 return_ACPI_STATUS(AE_BAD_PARAMETER);
93 if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
94 must_free = TRUE;
97 /* Evaluate the object */
99 status =
100 acpi_evaluate_object(handle, pathname, external_params,
101 return_buffer);
102 if (ACPI_FAILURE(status)) {
103 return_ACPI_STATUS(status);
106 /* Type ANY means "don't care" */
108 if (return_type == ACPI_TYPE_ANY) {
109 return_ACPI_STATUS(AE_OK);
112 if (return_buffer->length == 0) {
113 /* Error because caller specifically asked for a return value */
115 ACPI_ERROR((AE_INFO, "No return value"));
116 return_ACPI_STATUS(AE_NULL_OBJECT);
119 /* Examine the object type returned from evaluate_object */
121 if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
122 return_ACPI_STATUS(AE_OK);
125 /* Return object type does not match requested type */
127 ACPI_ERROR((AE_INFO,
128 "Incorrect return type [%s] requested [%s]",
129 acpi_ut_get_type_name(((union acpi_object *)return_buffer->
130 pointer)->type),
131 acpi_ut_get_type_name(return_type)));
133 if (must_free) {
134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
136 acpi_os_free(return_buffer->pointer);
137 return_buffer->pointer = NULL;
140 return_buffer->length = 0;
141 return_ACPI_STATUS(AE_TYPE);
143 #endif /* ACPI_FUTURE_USAGE */
145 /*******************************************************************************
147 * FUNCTION: acpi_evaluate_object
149 * PARAMETERS: Handle - Object handle (optional)
150 * Pathname - Object pathname (optional)
151 * external_params - List of parameters to pass to method,
152 * terminated by NULL. May be NULL
153 * if no parameters are being passed.
154 * return_buffer - Where to put method's return value (if
155 * any). If NULL, no value is returned.
157 * RETURN: Status
159 * DESCRIPTION: Find and evaluate the given object, passing the given
160 * parameters if necessary. One of "Handle" or "Pathname" must
161 * be valid (non-null)
163 ******************************************************************************/
165 acpi_status
166 acpi_evaluate_object(acpi_handle handle,
167 acpi_string pathname,
168 struct acpi_object_list *external_params,
169 struct acpi_buffer *return_buffer)
171 acpi_status status;
172 acpi_status status2;
173 struct acpi_parameter_info info;
174 acpi_size buffer_space_needed;
175 u32 i;
177 ACPI_FUNCTION_TRACE("acpi_evaluate_object");
179 info.node = handle;
180 info.parameters = NULL;
181 info.return_object = NULL;
182 info.parameter_type = ACPI_PARAM_ARGS;
185 * If there are parameters to be passed to the object
186 * (which must be a control method), the external objects
187 * must be converted to internal objects
189 if (external_params && external_params->count) {
191 * Allocate a new parameter block for the internal objects
192 * Add 1 to count to allow for null terminated internal list
194 info.parameters = ACPI_MEM_CALLOCATE(((acpi_size)
195 external_params->count +
196 1) * sizeof(void *));
197 if (!info.parameters) {
198 return_ACPI_STATUS(AE_NO_MEMORY);
202 * Convert each external object in the list to an
203 * internal object
205 for (i = 0; i < external_params->count; i++) {
206 status =
207 acpi_ut_copy_eobject_to_iobject(&external_params->
208 pointer[i],
209 &info.
210 parameters[i]);
211 if (ACPI_FAILURE(status)) {
212 acpi_ut_delete_internal_object_list(info.
213 parameters);
214 return_ACPI_STATUS(status);
217 info.parameters[external_params->count] = NULL;
221 * Three major cases:
222 * 1) Fully qualified pathname
223 * 2) No handle, not fully qualified pathname (error)
224 * 3) Valid handle
226 if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
228 * The path is fully qualified, just evaluate by name
230 status = acpi_ns_evaluate_by_name(pathname, &info);
231 } else if (!handle) {
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
237 if (!pathname) {
238 ACPI_ERROR((AE_INFO,
239 "Both Handle and Pathname are NULL"));
240 } else {
241 ACPI_ERROR((AE_INFO,
242 "Handle is NULL and Pathname is relative"));
245 status = AE_BAD_PARAMETER;
246 } else {
248 * We get here if we have a handle -- and if we have a
249 * pathname it is relative. The handle will be validated
250 * in the lower procedures
252 if (!pathname) {
254 * The null pathname case means the handle is for
255 * the actual object to be evaluated
257 status = acpi_ns_evaluate_by_handle(&info);
258 } else {
260 * Both a Handle and a relative Pathname
262 status = acpi_ns_evaluate_relative(pathname, &info);
267 * If we are expecting a return value, and all went well above,
268 * copy the return value to an external object.
270 if (return_buffer) {
271 if (!info.return_object) {
272 return_buffer->length = 0;
273 } else {
274 if (ACPI_GET_DESCRIPTOR_TYPE(info.return_object) ==
275 ACPI_DESC_TYPE_NAMED) {
277 * If we received a NS Node as a return object, this means that
278 * the object we are evaluating has nothing interesting to
279 * return (such as a mutex, etc.) We return an error because
280 * these types are essentially unsupported by this interface.
281 * We don't check up front because this makes it easier to add
282 * support for various types at a later date if necessary.
284 status = AE_TYPE;
285 info.return_object = NULL; /* No need to delete a NS Node */
286 return_buffer->length = 0;
289 if (ACPI_SUCCESS(status)) {
291 * Find out how large a buffer is needed
292 * to contain the returned object
294 status =
295 acpi_ut_get_object_size(info.return_object,
296 &buffer_space_needed);
297 if (ACPI_SUCCESS(status)) {
298 /* Validate/Allocate/Clear caller buffer */
300 status =
301 acpi_ut_initialize_buffer
302 (return_buffer,
303 buffer_space_needed);
304 if (ACPI_FAILURE(status)) {
306 * Caller's buffer is too small or a new one can't be allocated
308 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
309 "Needed buffer size %X, %s\n",
310 (u32)
311 buffer_space_needed,
312 acpi_format_exception
313 (status)));
314 } else {
316 * We have enough space for the object, build it
318 status =
319 acpi_ut_copy_iobject_to_eobject
320 (info.return_object,
321 return_buffer);
328 if (info.return_object) {
330 * Delete the internal return object. NOTE: Interpreter
331 * must be locked to avoid race condition.
333 status2 = acpi_ex_enter_interpreter();
334 if (ACPI_SUCCESS(status2)) {
336 * Delete the internal return object. (Or at least
337 * decrement the reference count by one)
339 acpi_ut_remove_reference(info.return_object);
340 acpi_ex_exit_interpreter();
345 * Free the input parameter list (if we created one),
347 if (info.parameters) {
348 /* Free the allocated parameter block */
350 acpi_ut_delete_internal_object_list(info.parameters);
353 return_ACPI_STATUS(status);
356 EXPORT_SYMBOL(acpi_evaluate_object);
358 /*******************************************************************************
360 * FUNCTION: acpi_walk_namespace
362 * PARAMETERS: Type - acpi_object_type to search for
363 * start_object - Handle in namespace where search begins
364 * max_depth - Depth to which search is to reach
365 * user_function - Called when an object of "Type" is found
366 * Context - Passed to user function
367 * return_value - Location where return value of
368 * user_function is put if terminated early
370 * RETURNS Return value from the user_function if terminated early.
371 * Otherwise, returns NULL.
373 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
374 * starting (and ending) at the object specified by start_handle.
375 * The user_function is called whenever an object that matches
376 * the type parameter is found. If the user function returns
377 * a non-zero value, the search is terminated immediately and this
378 * value is returned to the caller.
380 * The point of this procedure is to provide a generic namespace
381 * walk routine that can be called from multiple places to
382 * provide multiple services; the User Function can be tailored
383 * to each task, whether it is a print function, a compare
384 * function, etc.
386 ******************************************************************************/
388 acpi_status
389 acpi_walk_namespace(acpi_object_type type,
390 acpi_handle start_object,
391 u32 max_depth,
392 acpi_walk_callback user_function,
393 void *context, void **return_value)
395 acpi_status status;
397 ACPI_FUNCTION_TRACE("acpi_walk_namespace");
399 /* Parameter validation */
401 if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) {
402 return_ACPI_STATUS(AE_BAD_PARAMETER);
406 * Lock the namespace around the walk.
407 * The namespace will be unlocked/locked around each call
408 * to the user function - since this function
409 * must be allowed to make Acpi calls itself.
411 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
412 if (ACPI_FAILURE(status)) {
413 return_ACPI_STATUS(status);
416 status = acpi_ns_walk_namespace(type, start_object, max_depth,
417 ACPI_NS_WALK_UNLOCK,
418 user_function, context, return_value);
420 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
421 return_ACPI_STATUS(status);
424 EXPORT_SYMBOL(acpi_walk_namespace);
426 /*******************************************************************************
428 * FUNCTION: acpi_ns_get_device_callback
430 * PARAMETERS: Callback from acpi_get_device
432 * RETURN: Status
434 * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
435 * present devices, or if they specified a HID, it filters based
436 * on that.
438 ******************************************************************************/
440 static acpi_status
441 acpi_ns_get_device_callback(acpi_handle obj_handle,
442 u32 nesting_level,
443 void *context, void **return_value)
445 struct acpi_get_devices_info *info = context;
446 acpi_status status;
447 struct acpi_namespace_node *node;
448 u32 flags;
449 struct acpi_device_id hid;
450 struct acpi_compatible_id_list *cid;
451 acpi_native_uint i;
453 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
454 if (ACPI_FAILURE(status)) {
455 return (status);
458 node = acpi_ns_map_handle_to_node(obj_handle);
459 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
460 if (ACPI_FAILURE(status)) {
461 return (status);
464 if (!node) {
465 return (AE_BAD_PARAMETER);
468 /* Run _STA to determine if device is present */
470 status = acpi_ut_execute_STA(node, &flags);
471 if (ACPI_FAILURE(status)) {
472 return (AE_CTRL_DEPTH);
475 if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
476 /* Don't examine children of the device if not present */
478 return (AE_CTRL_DEPTH);
481 /* Filter based on device HID & CID */
483 if (info->hid != NULL) {
484 status = acpi_ut_execute_HID(node, &hid);
485 if (status == AE_NOT_FOUND) {
486 return (AE_OK);
487 } else if (ACPI_FAILURE(status)) {
488 return (AE_CTRL_DEPTH);
491 if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
492 /* Get the list of Compatible IDs */
494 status = acpi_ut_execute_CID(node, &cid);
495 if (status == AE_NOT_FOUND) {
496 return (AE_OK);
497 } else if (ACPI_FAILURE(status)) {
498 return (AE_CTRL_DEPTH);
501 /* Walk the CID list */
503 for (i = 0; i < cid->count; i++) {
504 if (ACPI_STRNCMP(cid->id[i].value, info->hid,
505 sizeof(struct
506 acpi_compatible_id)) !=
507 0) {
508 ACPI_MEM_FREE(cid);
509 return (AE_OK);
512 ACPI_MEM_FREE(cid);
516 status = info->user_function(obj_handle, nesting_level, info->context,
517 return_value);
518 return (status);
521 /*******************************************************************************
523 * FUNCTION: acpi_get_devices
525 * PARAMETERS: HID - HID to search for. Can be NULL.
526 * user_function - Called when a matching object is found
527 * Context - Passed to user function
528 * return_value - Location where return value of
529 * user_function is put if terminated early
531 * RETURNS Return value from the user_function if terminated early.
532 * Otherwise, returns NULL.
534 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
535 * starting (and ending) at the object specified by start_handle.
536 * The user_function is called whenever an object of type
537 * Device is found. If the user function returns
538 * a non-zero value, the search is terminated immediately and this
539 * value is returned to the caller.
541 * This is a wrapper for walk_namespace, but the callback performs
542 * additional filtering. Please see acpi_get_device_callback.
544 ******************************************************************************/
546 acpi_status
547 acpi_get_devices(char *HID,
548 acpi_walk_callback user_function,
549 void *context, void **return_value)
551 acpi_status status;
552 struct acpi_get_devices_info info;
554 ACPI_FUNCTION_TRACE("acpi_get_devices");
556 /* Parameter validation */
558 if (!user_function) {
559 return_ACPI_STATUS(AE_BAD_PARAMETER);
563 * We're going to call their callback from OUR callback, so we need
564 * to know what it is, and their context parameter.
566 info.context = context;
567 info.user_function = user_function;
568 info.hid = HID;
571 * Lock the namespace around the walk.
572 * The namespace will be unlocked/locked around each call
573 * to the user function - since this function
574 * must be allowed to make Acpi calls itself.
576 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
577 if (ACPI_FAILURE(status)) {
578 return_ACPI_STATUS(status);
581 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE,
582 ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
583 ACPI_NS_WALK_UNLOCK,
584 acpi_ns_get_device_callback, &info,
585 return_value);
587 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
588 return_ACPI_STATUS(status);
591 EXPORT_SYMBOL(acpi_get_devices);
593 /*******************************************************************************
595 * FUNCTION: acpi_attach_data
597 * PARAMETERS: obj_handle - Namespace node
598 * Handler - Handler for this attachment
599 * Data - Pointer to data to be attached
601 * RETURN: Status
603 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
605 ******************************************************************************/
607 acpi_status
608 acpi_attach_data(acpi_handle obj_handle,
609 acpi_object_handler handler, void *data)
611 struct acpi_namespace_node *node;
612 acpi_status status;
614 /* Parameter validation */
616 if (!obj_handle || !handler || !data) {
617 return (AE_BAD_PARAMETER);
620 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
621 if (ACPI_FAILURE(status)) {
622 return (status);
625 /* Convert and validate the handle */
627 node = acpi_ns_map_handle_to_node(obj_handle);
628 if (!node) {
629 status = AE_BAD_PARAMETER;
630 goto unlock_and_exit;
633 status = acpi_ns_attach_data(node, handler, data);
635 unlock_and_exit:
636 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
637 return (status);
640 /*******************************************************************************
642 * FUNCTION: acpi_detach_data
644 * PARAMETERS: obj_handle - Namespace node handle
645 * Handler - Handler used in call to acpi_attach_data
647 * RETURN: Status
649 * DESCRIPTION: Remove data that was previously attached to a node.
651 ******************************************************************************/
653 acpi_status
654 acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
656 struct acpi_namespace_node *node;
657 acpi_status status;
659 /* Parameter validation */
661 if (!obj_handle || !handler) {
662 return (AE_BAD_PARAMETER);
665 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
666 if (ACPI_FAILURE(status)) {
667 return (status);
670 /* Convert and validate the handle */
672 node = acpi_ns_map_handle_to_node(obj_handle);
673 if (!node) {
674 status = AE_BAD_PARAMETER;
675 goto unlock_and_exit;
678 status = acpi_ns_detach_data(node, handler);
680 unlock_and_exit:
681 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
682 return (status);
685 /*******************************************************************************
687 * FUNCTION: acpi_get_data
689 * PARAMETERS: obj_handle - Namespace node
690 * Handler - Handler used in call to attach_data
691 * Data - Where the data is returned
693 * RETURN: Status
695 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
697 ******************************************************************************/
699 acpi_status
700 acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
702 struct acpi_namespace_node *node;
703 acpi_status status;
705 /* Parameter validation */
707 if (!obj_handle || !handler || !data) {
708 return (AE_BAD_PARAMETER);
711 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
712 if (ACPI_FAILURE(status)) {
713 return (status);
716 /* Convert and validate the handle */
718 node = acpi_ns_map_handle_to_node(obj_handle);
719 if (!node) {
720 status = AE_BAD_PARAMETER;
721 goto unlock_and_exit;
724 status = acpi_ns_get_attached_data(node, handler, data);
726 unlock_and_exit:
727 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
728 return (status);