close_port, kpacket_gen kmalloc oom, formard.c wake_sender/skb receive oom handling...
[cor_2_6_31.git] / drivers / acpi / acpica / nsxfname.c
blobf23593d6add4857f146527e29b130fed13c47ff9
1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2008, Intel Corp.
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 <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acnamesp.h"
48 #include "acparser.h"
49 #include "amlcode.h"
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME("nsxfname")
54 /******************************************************************************
56 * FUNCTION: acpi_get_handle
58 * PARAMETERS: Parent - Object to search under (search scope).
59 * Pathname - Pointer to an asciiz string containing the
60 * name
61 * ret_handle - Where the return handle is returned
63 * RETURN: Status
65 * DESCRIPTION: This routine will search for a caller specified name in the
66 * name space. The caller can restrict the search region by
67 * specifying a non NULL parent. The parent value is itself a
68 * namespace handle.
70 ******************************************************************************/
71 acpi_status
72 acpi_get_handle(acpi_handle parent,
73 acpi_string pathname, acpi_handle * ret_handle)
75 acpi_status status;
76 struct acpi_namespace_node *node = NULL;
77 struct acpi_namespace_node *prefix_node = NULL;
79 ACPI_FUNCTION_ENTRY();
81 /* Parameter Validation */
83 if (!ret_handle || !pathname) {
84 return (AE_BAD_PARAMETER);
87 /* Convert a parent handle to a prefix node */
89 if (parent) {
90 prefix_node = acpi_ns_map_handle_to_node(parent);
91 if (!prefix_node) {
92 return (AE_BAD_PARAMETER);
97 * Valid cases are:
98 * 1) Fully qualified pathname
99 * 2) Parent + Relative pathname
101 * Error for <null Parent + relative path>
103 if (acpi_ns_valid_root_prefix(pathname[0])) {
105 /* Pathname is fully qualified (starts with '\') */
107 /* Special case for root-only, since we can't search for it */
109 if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
110 *ret_handle =
111 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
112 return (AE_OK);
114 } else if (!prefix_node) {
116 /* Relative path with null prefix is disallowed */
118 return (AE_BAD_PARAMETER);
121 /* Find the Node and convert to a handle */
123 status =
124 acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
125 if (ACPI_SUCCESS(status)) {
126 *ret_handle = acpi_ns_convert_entry_to_handle(node);
129 return (status);
132 ACPI_EXPORT_SYMBOL(acpi_get_handle)
134 /******************************************************************************
136 * FUNCTION: acpi_get_name
138 * PARAMETERS: Handle - Handle to be converted to a pathname
139 * name_type - Full pathname or single segment
140 * Buffer - Buffer for returned path
142 * RETURN: Pointer to a string containing the fully qualified Name.
144 * DESCRIPTION: This routine returns the fully qualified name associated with
145 * the Handle parameter. This and the acpi_pathname_to_handle are
146 * complementary functions.
148 ******************************************************************************/
149 acpi_status
150 acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
152 acpi_status status;
153 struct acpi_namespace_node *node;
155 /* Parameter validation */
157 if (name_type > ACPI_NAME_TYPE_MAX) {
158 return (AE_BAD_PARAMETER);
161 status = acpi_ut_validate_buffer(buffer);
162 if (ACPI_FAILURE(status)) {
163 return (status);
166 if (name_type == ACPI_FULL_PATHNAME) {
168 /* Get the full pathname (From the namespace root) */
170 status = acpi_ns_handle_to_pathname(handle, buffer);
171 return (status);
175 * Wants the single segment ACPI name.
176 * Validate handle and convert to a namespace Node
178 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
179 if (ACPI_FAILURE(status)) {
180 return (status);
183 node = acpi_ns_map_handle_to_node(handle);
184 if (!node) {
185 status = AE_BAD_PARAMETER;
186 goto unlock_and_exit;
189 /* Validate/Allocate/Clear caller buffer */
191 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
192 if (ACPI_FAILURE(status)) {
193 goto unlock_and_exit;
196 /* Just copy the ACPI name from the Node and zero terminate it */
198 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
199 ACPI_NAME_SIZE);
200 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
201 status = AE_OK;
203 unlock_and_exit:
205 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
206 return (status);
209 ACPI_EXPORT_SYMBOL(acpi_get_name)
211 /******************************************************************************
213 * FUNCTION: acpi_get_object_info
215 * PARAMETERS: Handle - Object Handle
216 * Buffer - Where the info is returned
218 * RETURN: Status
220 * DESCRIPTION: Returns information about an object as gleaned from the
221 * namespace node and possibly by running several standard
222 * control methods (Such as in the case of a device.)
224 ******************************************************************************/
225 acpi_status
226 acpi_get_object_info(acpi_handle handle, struct acpi_buffer * buffer)
228 acpi_status status;
229 struct acpi_namespace_node *node;
230 struct acpi_device_info *info;
231 struct acpi_device_info *return_info;
232 struct acpi_compatible_id_list *cid_list = NULL;
233 acpi_size size;
235 /* Parameter validation */
237 if (!handle || !buffer) {
238 return (AE_BAD_PARAMETER);
241 status = acpi_ut_validate_buffer(buffer);
242 if (ACPI_FAILURE(status)) {
243 return (status);
246 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_device_info));
247 if (!info) {
248 return (AE_NO_MEMORY);
251 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
252 if (ACPI_FAILURE(status)) {
253 goto cleanup;
256 node = acpi_ns_map_handle_to_node(handle);
257 if (!node) {
258 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
259 status = AE_BAD_PARAMETER;
260 goto cleanup;
263 /* Init return structure */
265 size = sizeof(struct acpi_device_info);
267 info->type = node->type;
268 info->name = node->name.integer;
269 info->valid = 0;
271 if (node->type == ACPI_TYPE_METHOD) {
272 info->param_count = node->object->method.param_count;
275 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
276 if (ACPI_FAILURE(status)) {
277 goto cleanup;
280 /* If not a device, we are all done */
282 if (info->type == ACPI_TYPE_DEVICE) {
284 * Get extra info for ACPI Devices objects only:
285 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
287 * Note: none of these methods are required, so they may or may
288 * not be present for this device. The Info->Valid bitfield is used
289 * to indicate which methods were found and ran successfully.
292 /* Execute the Device._HID method */
294 status = acpi_ut_execute_HID(node, &info->hardware_id);
295 if (ACPI_SUCCESS(status)) {
296 info->valid |= ACPI_VALID_HID;
299 /* Execute the Device._UID method */
301 status = acpi_ut_execute_UID(node, &info->unique_id);
302 if (ACPI_SUCCESS(status)) {
303 info->valid |= ACPI_VALID_UID;
306 /* Execute the Device._CID method */
308 status = acpi_ut_execute_CID(node, &cid_list);
309 if (ACPI_SUCCESS(status)) {
310 size += cid_list->size;
311 info->valid |= ACPI_VALID_CID;
314 /* Execute the Device._STA method */
316 status = acpi_ut_execute_STA(node, &info->current_status);
317 if (ACPI_SUCCESS(status)) {
318 info->valid |= ACPI_VALID_STA;
321 /* Execute the Device._ADR method */
323 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
324 &info->address);
325 if (ACPI_SUCCESS(status)) {
326 info->valid |= ACPI_VALID_ADR;
329 /* Execute the Device._sx_d methods */
331 status = acpi_ut_execute_sxds(node, info->highest_dstates);
332 if (ACPI_SUCCESS(status)) {
333 info->valid |= ACPI_VALID_SXDS;
337 /* Validate/Allocate/Clear caller buffer */
339 status = acpi_ut_initialize_buffer(buffer, size);
340 if (ACPI_FAILURE(status)) {
341 goto cleanup;
344 /* Populate the return buffer */
346 return_info = buffer->pointer;
347 ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
349 if (cid_list) {
350 ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
351 cid_list->size);
354 cleanup:
355 ACPI_FREE(info);
356 if (cid_list) {
357 ACPI_FREE(cid_list);
359 return (status);
362 ACPI_EXPORT_SYMBOL(acpi_get_object_info)
364 /******************************************************************************
366 * FUNCTION: acpi_install_method
368 * PARAMETERS: Buffer - An ACPI table containing one control method
370 * RETURN: Status
372 * DESCRIPTION: Install a control method into the namespace. If the method
373 * name already exists in the namespace, it is overwritten. The
374 * input buffer must contain a valid DSDT or SSDT containing a
375 * single control method.
377 ******************************************************************************/
378 acpi_status acpi_install_method(u8 *buffer)
380 struct acpi_table_header *table =
381 ACPI_CAST_PTR(struct acpi_table_header, buffer);
382 u8 *aml_buffer;
383 u8 *aml_start;
384 char *path;
385 struct acpi_namespace_node *node;
386 union acpi_operand_object *method_obj;
387 struct acpi_parse_state parser_state;
388 u32 aml_length;
389 u16 opcode;
390 u8 method_flags;
391 acpi_status status;
393 /* Parameter validation */
395 if (!buffer) {
396 return AE_BAD_PARAMETER;
399 /* Table must be a DSDT or SSDT */
401 if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) &&
402 !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
403 return AE_BAD_HEADER;
406 /* First AML opcode in the table must be a control method */
408 parser_state.aml = buffer + sizeof(struct acpi_table_header);
409 opcode = acpi_ps_peek_opcode(&parser_state);
410 if (opcode != AML_METHOD_OP) {
411 return AE_BAD_PARAMETER;
414 /* Extract method information from the raw AML */
416 parser_state.aml += acpi_ps_get_opcode_size(opcode);
417 parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state);
418 path = acpi_ps_get_next_namestring(&parser_state);
419 method_flags = *parser_state.aml++;
420 aml_start = parser_state.aml;
421 aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);
424 * Allocate resources up-front. We don't want to have to delete a new
425 * node from the namespace if we cannot allocate memory.
427 aml_buffer = ACPI_ALLOCATE(aml_length);
428 if (!aml_buffer) {
429 return AE_NO_MEMORY;
432 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
433 if (!method_obj) {
434 ACPI_FREE(aml_buffer);
435 return AE_NO_MEMORY;
438 /* Lock namespace for acpi_ns_lookup, we may be creating a new node */
440 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
441 if (ACPI_FAILURE(status)) {
442 goto error_exit;
445 /* The lookup either returns an existing node or creates a new one */
447 status =
448 acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
449 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
450 NULL, &node);
452 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
454 if (ACPI_FAILURE(status)) { /* ns_lookup */
455 if (status != AE_ALREADY_EXISTS) {
456 goto error_exit;
459 /* Node existed previously, make sure it is a method node */
461 if (node->type != ACPI_TYPE_METHOD) {
462 status = AE_TYPE;
463 goto error_exit;
467 /* Copy the method AML to the local buffer */
469 ACPI_MEMCPY(aml_buffer, aml_start, aml_length);
471 /* Initialize the method object with the new method's information */
473 method_obj->method.aml_start = aml_buffer;
474 method_obj->method.aml_length = aml_length;
476 method_obj->method.param_count = (u8)
477 (method_flags & AML_METHOD_ARG_COUNT);
479 method_obj->method.method_flags = (u8)
480 (method_flags & ~AML_METHOD_ARG_COUNT);
482 if (method_flags & AML_METHOD_SERIALIZED) {
483 method_obj->method.sync_level = (u8)
484 ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
488 * Now that it is complete, we can attach the new method object to
489 * the method Node (detaches/deletes any existing object)
491 status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD);
494 * Flag indicates AML buffer is dynamic, must be deleted later.
495 * Must be set only after attach above.
497 node->flags |= ANOBJ_ALLOCATED_BUFFER;
499 /* Remove local reference to the method object */
501 acpi_ut_remove_reference(method_obj);
502 return status;
504 error_exit:
506 ACPI_FREE(aml_buffer);
507 ACPI_FREE(method_obj);
508 return status;
510 ACPI_EXPORT_SYMBOL(acpi_install_method)