1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, 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
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.
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/export.h>
46 #include <acpi/acpi.h>
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME("nsxfname")
55 /* Local prototypes */
56 static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id
*dest
,
57 struct acpi_pnp_device_id
*source
,
60 /******************************************************************************
62 * FUNCTION: acpi_get_handle
64 * PARAMETERS: parent - Object to search under (search scope).
65 * pathname - Pointer to an asciiz string containing the
67 * ret_handle - Where the return handle is returned
71 * DESCRIPTION: This routine will search for a caller specified name in the
72 * name space. The caller can restrict the search region by
73 * specifying a non NULL parent. The parent value is itself a
76 ******************************************************************************/
79 acpi_get_handle(acpi_handle parent
,
80 acpi_string pathname
, acpi_handle
* ret_handle
)
83 struct acpi_namespace_node
*node
= NULL
;
84 struct acpi_namespace_node
*prefix_node
= NULL
;
86 ACPI_FUNCTION_ENTRY();
88 /* Parameter Validation */
90 if (!ret_handle
|| !pathname
) {
91 return (AE_BAD_PARAMETER
);
94 /* Convert a parent handle to a prefix node */
97 prefix_node
= acpi_ns_validate_handle(parent
);
99 return (AE_BAD_PARAMETER
);
105 * 1) Fully qualified pathname
106 * 2) Parent + Relative pathname
108 * Error for <null Parent + relative path>
110 if (acpi_ns_valid_root_prefix(pathname
[0])) {
112 /* Pathname is fully qualified (starts with '\') */
114 /* Special case for root-only, since we can't search for it */
116 if (!ACPI_STRCMP(pathname
, ACPI_NS_ROOT_PATH
)) {
118 ACPI_CAST_PTR(acpi_handle
, acpi_gbl_root_node
);
121 } else if (!prefix_node
) {
123 /* Relative path with null prefix is disallowed */
125 return (AE_BAD_PARAMETER
);
128 /* Find the Node and convert to a handle */
131 acpi_ns_get_node(prefix_node
, pathname
, ACPI_NS_NO_UPSEARCH
, &node
);
132 if (ACPI_SUCCESS(status
)) {
133 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, node
);
139 ACPI_EXPORT_SYMBOL(acpi_get_handle
)
141 /******************************************************************************
143 * FUNCTION: acpi_get_name
145 * PARAMETERS: handle - Handle to be converted to a pathname
146 * name_type - Full pathname or single segment
147 * buffer - Buffer for returned path
149 * RETURN: Pointer to a string containing the fully qualified Name.
151 * DESCRIPTION: This routine returns the fully qualified name associated with
152 * the Handle parameter. This and the acpi_pathname_to_handle are
153 * complementary functions.
155 ******************************************************************************/
157 acpi_get_name(acpi_handle handle
, u32 name_type
, struct acpi_buffer
* buffer
)
160 struct acpi_namespace_node
*node
;
162 /* Parameter validation */
164 if (name_type
> ACPI_NAME_TYPE_MAX
) {
165 return (AE_BAD_PARAMETER
);
168 status
= acpi_ut_validate_buffer(buffer
);
169 if (ACPI_FAILURE(status
)) {
173 if (name_type
== ACPI_FULL_PATHNAME
) {
175 /* Get the full pathname (From the namespace root) */
177 status
= acpi_ns_handle_to_pathname(handle
, buffer
);
182 * Wants the single segment ACPI name.
183 * Validate handle and convert to a namespace Node
185 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
186 if (ACPI_FAILURE(status
)) {
190 node
= acpi_ns_validate_handle(handle
);
192 status
= AE_BAD_PARAMETER
;
193 goto unlock_and_exit
;
196 /* Validate/Allocate/Clear caller buffer */
198 status
= acpi_ut_initialize_buffer(buffer
, ACPI_PATH_SEGMENT_LENGTH
);
199 if (ACPI_FAILURE(status
)) {
200 goto unlock_and_exit
;
203 /* Just copy the ACPI name from the Node and zero terminate it */
205 ACPI_MOVE_NAME(buffer
->pointer
, acpi_ut_get_node_name(node
));
206 ((char *)buffer
->pointer
)[ACPI_NAME_SIZE
] = 0;
211 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
215 ACPI_EXPORT_SYMBOL(acpi_get_name
)
217 /******************************************************************************
219 * FUNCTION: acpi_ns_copy_device_id
221 * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID
222 * source - Pointer to the source PNP_DEVICE_ID
223 * string_area - Pointer to where to copy the dest string
225 * RETURN: Pointer to the next string area
227 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
229 ******************************************************************************/
230 static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id
*dest
,
231 struct acpi_pnp_device_id
*source
,
235 /* Create the destination PNP_DEVICE_ID */
237 dest
->string
= string_area
;
238 dest
->length
= source
->length
;
240 /* Copy actual string and return a pointer to the next string area */
242 ACPI_MEMCPY(string_area
, source
->string
, source
->length
);
243 return (string_area
+ source
->length
);
246 /******************************************************************************
248 * FUNCTION: acpi_get_object_info
250 * PARAMETERS: handle - Object Handle
251 * return_buffer - Where the info is returned
255 * DESCRIPTION: Returns information about an object as gleaned from the
256 * namespace node and possibly by running several standard
257 * control methods (Such as in the case of a device.)
259 * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
260 * _STA, _ADR, _sx_w, and _sx_d methods.
262 * Note: Allocates the return buffer, must be freed by the caller.
264 ******************************************************************************/
267 acpi_get_object_info(acpi_handle handle
,
268 struct acpi_device_info
**return_buffer
)
270 struct acpi_namespace_node
*node
;
271 struct acpi_device_info
*info
;
272 struct acpi_pnp_device_id_list
*cid_list
= NULL
;
273 struct acpi_pnp_device_id
*hid
= NULL
;
274 struct acpi_pnp_device_id
*uid
= NULL
;
275 struct acpi_pnp_device_id
*sub
= NULL
;
276 char *next_id_string
;
277 acpi_object_type type
;
285 /* Parameter validation */
287 if (!handle
|| !return_buffer
) {
288 return (AE_BAD_PARAMETER
);
291 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
292 if (ACPI_FAILURE(status
)) {
296 node
= acpi_ns_validate_handle(handle
);
298 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
299 return (AE_BAD_PARAMETER
);
302 /* Get the namespace node data while the namespace is locked */
304 info_size
= sizeof(struct acpi_device_info
);
306 name
= node
->name
.integer
;
308 if (node
->type
== ACPI_TYPE_METHOD
) {
309 param_count
= node
->object
->method
.param_count
;
312 status
= acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
313 if (ACPI_FAILURE(status
)) {
317 if ((type
== ACPI_TYPE_DEVICE
) || (type
== ACPI_TYPE_PROCESSOR
)) {
319 * Get extra info for ACPI Device/Processor objects only:
320 * Run the Device _HID, _UID, _SUB, and _CID methods.
322 * Note: none of these methods are required, so they may or may
323 * not be present for this device. The Info->Valid bitfield is used
324 * to indicate which methods were found and run successfully.
327 /* Execute the Device._HID method */
329 status
= acpi_ut_execute_HID(node
, &hid
);
330 if (ACPI_SUCCESS(status
)) {
331 info_size
+= hid
->length
;
332 valid
|= ACPI_VALID_HID
;
335 /* Execute the Device._UID method */
337 status
= acpi_ut_execute_UID(node
, &uid
);
338 if (ACPI_SUCCESS(status
)) {
339 info_size
+= uid
->length
;
340 valid
|= ACPI_VALID_UID
;
343 /* Execute the Device._SUB method */
345 status
= acpi_ut_execute_SUB(node
, &sub
);
346 if (ACPI_SUCCESS(status
)) {
347 info_size
+= sub
->length
;
348 valid
|= ACPI_VALID_SUB
;
351 /* Execute the Device._CID method */
353 status
= acpi_ut_execute_CID(node
, &cid_list
);
354 if (ACPI_SUCCESS(status
)) {
356 /* Add size of CID strings and CID pointer array */
359 (cid_list
->list_size
-
360 sizeof(struct acpi_pnp_device_id_list
));
361 valid
|= ACPI_VALID_CID
;
366 * Now that we have the variable-length data, we can allocate the
369 info
= ACPI_ALLOCATE_ZEROED(info_size
);
371 status
= AE_NO_MEMORY
;
375 /* Get the fixed-length data */
377 if ((type
== ACPI_TYPE_DEVICE
) || (type
== ACPI_TYPE_PROCESSOR
)) {
379 * Get extra info for ACPI Device/Processor objects only:
380 * Run the _STA, _ADR and, sx_w, and _sx_d methods.
382 * Note: none of these methods are required, so they may or may
383 * not be present for this device. The Info->Valid bitfield is used
384 * to indicate which methods were found and run successfully.
387 /* Execute the Device._STA method */
389 status
= acpi_ut_execute_STA(node
, &info
->current_status
);
390 if (ACPI_SUCCESS(status
)) {
391 valid
|= ACPI_VALID_STA
;
394 /* Execute the Device._ADR method */
396 status
= acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR
, node
,
398 if (ACPI_SUCCESS(status
)) {
399 valid
|= ACPI_VALID_ADR
;
402 /* Execute the Device._sx_w methods */
404 status
= acpi_ut_execute_power_methods(node
,
405 acpi_gbl_lowest_dstate_names
,
406 ACPI_NUM_sx_w_METHODS
,
407 info
->lowest_dstates
);
408 if (ACPI_SUCCESS(status
)) {
409 valid
|= ACPI_VALID_SXWS
;
412 /* Execute the Device._sx_d methods */
414 status
= acpi_ut_execute_power_methods(node
,
415 acpi_gbl_highest_dstate_names
,
416 ACPI_NUM_sx_d_METHODS
,
417 info
->highest_dstates
);
418 if (ACPI_SUCCESS(status
)) {
419 valid
|= ACPI_VALID_SXDS
;
424 * Create a pointer to the string area of the return buffer.
425 * Point to the end of the base struct acpi_device_info structure.
427 next_id_string
= ACPI_CAST_PTR(char, info
->compatible_id_list
.ids
);
430 /* Point past the CID PNP_DEVICE_ID array */
433 ((acpi_size
) cid_list
->count
*
434 sizeof(struct acpi_pnp_device_id
));
438 * Copy the HID, UID, SUB, and CIDs to the return buffer.
439 * The variable-length strings are copied to the reserved area
440 * at the end of the buffer.
442 * For HID and CID, check if the ID is a PCI Root Bridge.
445 next_id_string
= acpi_ns_copy_device_id(&info
->hardware_id
,
446 hid
, next_id_string
);
448 if (acpi_ut_is_pci_root_bridge(hid
->string
)) {
449 info
->flags
|= ACPI_PCI_ROOT_BRIDGE
;
454 next_id_string
= acpi_ns_copy_device_id(&info
->unique_id
,
455 uid
, next_id_string
);
459 next_id_string
= acpi_ns_copy_device_id(&info
->subsystem_id
,
460 sub
, next_id_string
);
464 info
->compatible_id_list
.count
= cid_list
->count
;
465 info
->compatible_id_list
.list_size
= cid_list
->list_size
;
469 for (i
= 0; i
< cid_list
->count
; i
++) {
471 acpi_ns_copy_device_id(&info
->compatible_id_list
.
472 ids
[i
], &cid_list
->ids
[i
],
475 if (acpi_ut_is_pci_root_bridge(cid_list
->ids
[i
].string
)) {
476 info
->flags
|= ACPI_PCI_ROOT_BRIDGE
;
481 /* Copy the fixed-length data */
483 info
->info_size
= info_size
;
486 info
->param_count
= param_count
;
489 *return_buffer
= info
;
508 ACPI_EXPORT_SYMBOL(acpi_get_object_info
)
510 /******************************************************************************
512 * FUNCTION: acpi_install_method
514 * PARAMETERS: buffer - An ACPI table containing one control method
518 * DESCRIPTION: Install a control method into the namespace. If the method
519 * name already exists in the namespace, it is overwritten. The
520 * input buffer must contain a valid DSDT or SSDT containing a
521 * single control method.
523 ******************************************************************************/
524 acpi_status
acpi_install_method(u8
*buffer
)
526 struct acpi_table_header
*table
=
527 ACPI_CAST_PTR(struct acpi_table_header
, buffer
);
531 struct acpi_namespace_node
*node
;
532 union acpi_operand_object
*method_obj
;
533 struct acpi_parse_state parser_state
;
539 /* Parameter validation */
542 return (AE_BAD_PARAMETER
);
545 /* Table must be a DSDT or SSDT */
547 if (!ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_DSDT
) &&
548 !ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_SSDT
)) {
549 return (AE_BAD_HEADER
);
552 /* First AML opcode in the table must be a control method */
554 parser_state
.aml
= buffer
+ sizeof(struct acpi_table_header
);
555 opcode
= acpi_ps_peek_opcode(&parser_state
);
556 if (opcode
!= AML_METHOD_OP
) {
557 return (AE_BAD_PARAMETER
);
560 /* Extract method information from the raw AML */
562 parser_state
.aml
+= acpi_ps_get_opcode_size(opcode
);
563 parser_state
.pkg_end
= acpi_ps_get_next_package_end(&parser_state
);
564 path
= acpi_ps_get_next_namestring(&parser_state
);
565 method_flags
= *parser_state
.aml
++;
566 aml_start
= parser_state
.aml
;
567 aml_length
= ACPI_PTR_DIFF(parser_state
.pkg_end
, aml_start
);
570 * Allocate resources up-front. We don't want to have to delete a new
571 * node from the namespace if we cannot allocate memory.
573 aml_buffer
= ACPI_ALLOCATE(aml_length
);
575 return (AE_NO_MEMORY
);
578 method_obj
= acpi_ut_create_internal_object(ACPI_TYPE_METHOD
);
580 ACPI_FREE(aml_buffer
);
581 return (AE_NO_MEMORY
);
584 /* Lock namespace for acpi_ns_lookup, we may be creating a new node */
586 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
587 if (ACPI_FAILURE(status
)) {
591 /* The lookup either returns an existing node or creates a new one */
594 acpi_ns_lookup(NULL
, path
, ACPI_TYPE_METHOD
, ACPI_IMODE_LOAD_PASS1
,
595 ACPI_NS_DONT_OPEN_SCOPE
| ACPI_NS_ERROR_IF_FOUND
,
598 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
600 if (ACPI_FAILURE(status
)) { /* ns_lookup */
601 if (status
!= AE_ALREADY_EXISTS
) {
605 /* Node existed previously, make sure it is a method node */
607 if (node
->type
!= ACPI_TYPE_METHOD
) {
613 /* Copy the method AML to the local buffer */
615 ACPI_MEMCPY(aml_buffer
, aml_start
, aml_length
);
617 /* Initialize the method object with the new method's information */
619 method_obj
->method
.aml_start
= aml_buffer
;
620 method_obj
->method
.aml_length
= aml_length
;
622 method_obj
->method
.param_count
= (u8
)
623 (method_flags
& AML_METHOD_ARG_COUNT
);
625 if (method_flags
& AML_METHOD_SERIALIZED
) {
626 method_obj
->method
.info_flags
= ACPI_METHOD_SERIALIZED
;
628 method_obj
->method
.sync_level
= (u8
)
629 ((method_flags
& AML_METHOD_SYNC_LEVEL
) >> 4);
633 * Now that it is complete, we can attach the new method object to
634 * the method Node (detaches/deletes any existing object)
636 status
= acpi_ns_attach_object(node
, method_obj
, ACPI_TYPE_METHOD
);
639 * Flag indicates AML buffer is dynamic, must be deleted later.
640 * Must be set only after attach above.
642 node
->flags
|= ANOBJ_ALLOCATED_BUFFER
;
644 /* Remove local reference to the method object */
646 acpi_ut_remove_reference(method_obj
);
651 ACPI_FREE(aml_buffer
);
652 ACPI_FREE(method_obj
);
655 ACPI_EXPORT_SYMBOL(acpi_install_method
)