1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2015, 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 #define EXPORT_ACPI_INTERFACES
47 #include <acpi/acpi.h>
53 #define _COMPONENT ACPI_NAMESPACE
54 ACPI_MODULE_NAME("nsxfname")
56 /* Local prototypes */
57 static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id
*dest
,
58 struct acpi_pnp_device_id
*source
,
61 /******************************************************************************
63 * FUNCTION: acpi_get_handle
65 * PARAMETERS: parent - Object to search under (search scope).
66 * pathname - Pointer to an asciiz string containing the
68 * ret_handle - Where the return handle is returned
72 * DESCRIPTION: This routine will search for a caller specified name in the
73 * name space. The caller can restrict the search region by
74 * specifying a non NULL parent. The parent value is itself a
77 ******************************************************************************/
80 acpi_get_handle(acpi_handle parent
,
81 acpi_string pathname
, acpi_handle
* ret_handle
)
84 struct acpi_namespace_node
*node
= NULL
;
85 struct acpi_namespace_node
*prefix_node
= NULL
;
87 ACPI_FUNCTION_ENTRY();
89 /* Parameter Validation */
91 if (!ret_handle
|| !pathname
) {
92 return (AE_BAD_PARAMETER
);
95 /* Convert a parent handle to a prefix node */
98 prefix_node
= acpi_ns_validate_handle(parent
);
100 return (AE_BAD_PARAMETER
);
106 * 1) Fully qualified pathname
107 * 2) Parent + Relative pathname
109 * Error for <null Parent + relative path>
111 if (ACPI_IS_ROOT_PREFIX(pathname
[0])) {
113 /* Pathname is fully qualified (starts with '\') */
115 /* Special case for root-only, since we can't search for it */
117 if (!strcmp(pathname
, ACPI_NS_ROOT_PATH
)) {
119 ACPI_CAST_PTR(acpi_handle
, acpi_gbl_root_node
);
122 } else if (!prefix_node
) {
124 /* Relative path with null prefix is disallowed */
126 return (AE_BAD_PARAMETER
);
129 /* Find the Node and convert to a handle */
132 acpi_ns_get_node(prefix_node
, pathname
, ACPI_NS_NO_UPSEARCH
, &node
);
133 if (ACPI_SUCCESS(status
)) {
134 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, node
);
140 ACPI_EXPORT_SYMBOL(acpi_get_handle
)
142 /******************************************************************************
144 * FUNCTION: acpi_get_name
146 * PARAMETERS: handle - Handle to be converted to a pathname
147 * name_type - Full pathname or single segment
148 * buffer - Buffer for returned path
150 * RETURN: Pointer to a string containing the fully qualified Name.
152 * DESCRIPTION: This routine returns the fully qualified name associated with
153 * the Handle parameter. This and the acpi_pathname_to_handle are
154 * complementary functions.
156 ******************************************************************************/
158 acpi_get_name(acpi_handle handle
, u32 name_type
, struct acpi_buffer
* buffer
)
161 struct acpi_namespace_node
*node
;
164 /* Parameter validation */
166 if (name_type
> ACPI_NAME_TYPE_MAX
) {
167 return (AE_BAD_PARAMETER
);
170 status
= acpi_ut_validate_buffer(buffer
);
171 if (ACPI_FAILURE(status
)) {
175 if (name_type
== ACPI_FULL_PATHNAME
||
176 name_type
== ACPI_FULL_PATHNAME_NO_TRAILING
) {
178 /* Get the full pathname (From the namespace root) */
180 status
= acpi_ns_handle_to_pathname(handle
, buffer
,
182 ACPI_FULL_PATHNAME
? FALSE
:
188 * Wants the single segment ACPI name.
189 * Validate handle and convert to a namespace Node
191 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
192 if (ACPI_FAILURE(status
)) {
196 node
= acpi_ns_validate_handle(handle
);
198 status
= AE_BAD_PARAMETER
;
199 goto unlock_and_exit
;
202 /* Validate/Allocate/Clear caller buffer */
204 status
= acpi_ut_initialize_buffer(buffer
, ACPI_PATH_SEGMENT_LENGTH
);
205 if (ACPI_FAILURE(status
)) {
206 goto unlock_and_exit
;
209 /* Just copy the ACPI name from the Node and zero terminate it */
211 node_name
= acpi_ut_get_node_name(node
);
212 ACPI_MOVE_NAME(buffer
->pointer
, node_name
);
213 ((char *)buffer
->pointer
)[ACPI_NAME_SIZE
] = 0;
218 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
222 ACPI_EXPORT_SYMBOL(acpi_get_name
)
224 /******************************************************************************
226 * FUNCTION: acpi_ns_copy_device_id
228 * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID
229 * source - Pointer to the source PNP_DEVICE_ID
230 * string_area - Pointer to where to copy the dest string
232 * RETURN: Pointer to the next string area
234 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
236 ******************************************************************************/
237 static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id
*dest
,
238 struct acpi_pnp_device_id
*source
,
242 /* Create the destination PNP_DEVICE_ID */
244 dest
->string
= string_area
;
245 dest
->length
= source
->length
;
247 /* Copy actual string and return a pointer to the next string area */
249 memcpy(string_area
, source
->string
, source
->length
);
250 return (string_area
+ source
->length
);
253 /******************************************************************************
255 * FUNCTION: acpi_get_object_info
257 * PARAMETERS: handle - Object Handle
258 * return_buffer - Where the info is returned
262 * DESCRIPTION: Returns information about an object as gleaned from the
263 * namespace node and possibly by running several standard
264 * control methods (Such as in the case of a device.)
266 * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
267 * _CLS, _STA, _ADR, _sx_w, and _sx_d methods.
269 * Note: Allocates the return buffer, must be freed by the caller.
271 ******************************************************************************/
274 acpi_get_object_info(acpi_handle handle
,
275 struct acpi_device_info
**return_buffer
)
277 struct acpi_namespace_node
*node
;
278 struct acpi_device_info
*info
;
279 struct acpi_pnp_device_id_list
*cid_list
= NULL
;
280 struct acpi_pnp_device_id
*hid
= NULL
;
281 struct acpi_pnp_device_id
*uid
= NULL
;
282 struct acpi_pnp_device_id
*sub
= NULL
;
283 struct acpi_pnp_device_id
*cls
= NULL
;
284 char *next_id_string
;
285 acpi_object_type type
;
293 /* Parameter validation */
295 if (!handle
|| !return_buffer
) {
296 return (AE_BAD_PARAMETER
);
299 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
300 if (ACPI_FAILURE(status
)) {
304 node
= acpi_ns_validate_handle(handle
);
306 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
307 return (AE_BAD_PARAMETER
);
310 /* Get the namespace node data while the namespace is locked */
312 info_size
= sizeof(struct acpi_device_info
);
314 name
= node
->name
.integer
;
316 if (node
->type
== ACPI_TYPE_METHOD
) {
317 param_count
= node
->object
->method
.param_count
;
320 status
= acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
321 if (ACPI_FAILURE(status
)) {
325 if ((type
== ACPI_TYPE_DEVICE
) || (type
== ACPI_TYPE_PROCESSOR
)) {
327 * Get extra info for ACPI Device/Processor objects only:
328 * Run the Device _HID, _UID, _SUB, _CID, and _CLS methods.
330 * Note: none of these methods are required, so they may or may
331 * not be present for this device. The Info->Valid bitfield is used
332 * to indicate which methods were found and run successfully.
335 /* Execute the Device._HID method */
337 status
= acpi_ut_execute_HID(node
, &hid
);
338 if (ACPI_SUCCESS(status
)) {
339 info_size
+= hid
->length
;
340 valid
|= ACPI_VALID_HID
;
343 /* Execute the Device._UID method */
345 status
= acpi_ut_execute_UID(node
, &uid
);
346 if (ACPI_SUCCESS(status
)) {
347 info_size
+= uid
->length
;
348 valid
|= ACPI_VALID_UID
;
351 /* Execute the Device._SUB method */
353 status
= acpi_ut_execute_SUB(node
, &sub
);
354 if (ACPI_SUCCESS(status
)) {
355 info_size
+= sub
->length
;
356 valid
|= ACPI_VALID_SUB
;
359 /* Execute the Device._CID method */
361 status
= acpi_ut_execute_CID(node
, &cid_list
);
362 if (ACPI_SUCCESS(status
)) {
364 /* Add size of CID strings and CID pointer array */
367 (cid_list
->list_size
-
368 sizeof(struct acpi_pnp_device_id_list
));
369 valid
|= ACPI_VALID_CID
;
372 /* Execute the Device._CLS method */
374 status
= acpi_ut_execute_CLS(node
, &cls
);
375 if (ACPI_SUCCESS(status
)) {
376 info_size
+= cls
->length
;
377 valid
|= ACPI_VALID_CLS
;
382 * Now that we have the variable-length data, we can allocate the
385 info
= ACPI_ALLOCATE_ZEROED(info_size
);
387 status
= AE_NO_MEMORY
;
391 /* Get the fixed-length data */
393 if ((type
== ACPI_TYPE_DEVICE
) || (type
== ACPI_TYPE_PROCESSOR
)) {
395 * Get extra info for ACPI Device/Processor objects only:
396 * Run the _STA, _ADR and, sx_w, and _sx_d methods.
398 * Notes: none of these methods are required, so they may or may
399 * not be present for this device. The Info->Valid bitfield is used
400 * to indicate which methods were found and run successfully.
402 * For _STA, if the method does not exist, then (as per the ACPI
403 * specification), the returned current_status flags will indicate
404 * that the device is present/functional/enabled. Otherwise, the
405 * current_status flags reflect the value returned from _STA.
408 /* Execute the Device._STA method */
410 status
= acpi_ut_execute_STA(node
, &info
->current_status
);
411 if (ACPI_SUCCESS(status
)) {
412 valid
|= ACPI_VALID_STA
;
415 /* Execute the Device._ADR method */
417 status
= acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR
, node
,
419 if (ACPI_SUCCESS(status
)) {
420 valid
|= ACPI_VALID_ADR
;
423 /* Execute the Device._sx_w methods */
425 status
= acpi_ut_execute_power_methods(node
,
426 acpi_gbl_lowest_dstate_names
,
427 ACPI_NUM_sx_w_METHODS
,
428 info
->lowest_dstates
);
429 if (ACPI_SUCCESS(status
)) {
430 valid
|= ACPI_VALID_SXWS
;
433 /* Execute the Device._sx_d methods */
435 status
= acpi_ut_execute_power_methods(node
,
436 acpi_gbl_highest_dstate_names
,
437 ACPI_NUM_sx_d_METHODS
,
438 info
->highest_dstates
);
439 if (ACPI_SUCCESS(status
)) {
440 valid
|= ACPI_VALID_SXDS
;
445 * Create a pointer to the string area of the return buffer.
446 * Point to the end of the base struct acpi_device_info structure.
448 next_id_string
= ACPI_CAST_PTR(char, info
->compatible_id_list
.ids
);
451 /* Point past the CID PNP_DEVICE_ID array */
454 ((acpi_size
) cid_list
->count
*
455 sizeof(struct acpi_pnp_device_id
));
459 * Copy the HID, UID, SUB, and CIDs to the return buffer.
460 * The variable-length strings are copied to the reserved area
461 * at the end of the buffer.
463 * For HID and CID, check if the ID is a PCI Root Bridge.
466 next_id_string
= acpi_ns_copy_device_id(&info
->hardware_id
,
467 hid
, next_id_string
);
469 if (acpi_ut_is_pci_root_bridge(hid
->string
)) {
470 info
->flags
|= ACPI_PCI_ROOT_BRIDGE
;
475 next_id_string
= acpi_ns_copy_device_id(&info
->unique_id
,
476 uid
, next_id_string
);
480 next_id_string
= acpi_ns_copy_device_id(&info
->subsystem_id
,
481 sub
, next_id_string
);
485 info
->compatible_id_list
.count
= cid_list
->count
;
486 info
->compatible_id_list
.list_size
= cid_list
->list_size
;
490 for (i
= 0; i
< cid_list
->count
; i
++) {
492 acpi_ns_copy_device_id(&info
->compatible_id_list
.
493 ids
[i
], &cid_list
->ids
[i
],
496 if (acpi_ut_is_pci_root_bridge(cid_list
->ids
[i
].string
)) {
497 info
->flags
|= ACPI_PCI_ROOT_BRIDGE
;
503 next_id_string
= acpi_ns_copy_device_id(&info
->class_code
,
504 cls
, next_id_string
);
507 /* Copy the fixed-length data */
509 info
->info_size
= info_size
;
512 info
->param_count
= param_count
;
515 *return_buffer
= info
;
537 ACPI_EXPORT_SYMBOL(acpi_get_object_info
)
539 /******************************************************************************
541 * FUNCTION: acpi_install_method
543 * PARAMETERS: buffer - An ACPI table containing one control method
547 * DESCRIPTION: Install a control method into the namespace. If the method
548 * name already exists in the namespace, it is overwritten. The
549 * input buffer must contain a valid DSDT or SSDT containing a
550 * single control method.
552 ******************************************************************************/
553 acpi_status
acpi_install_method(u8
*buffer
)
555 struct acpi_table_header
*table
=
556 ACPI_CAST_PTR(struct acpi_table_header
, buffer
);
560 struct acpi_namespace_node
*node
;
561 union acpi_operand_object
*method_obj
;
562 struct acpi_parse_state parser_state
;
568 /* Parameter validation */
571 return (AE_BAD_PARAMETER
);
574 /* Table must be a DSDT or SSDT */
576 if (!ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_DSDT
) &&
577 !ACPI_COMPARE_NAME(table
->signature
, ACPI_SIG_SSDT
)) {
578 return (AE_BAD_HEADER
);
581 /* First AML opcode in the table must be a control method */
583 parser_state
.aml
= buffer
+ sizeof(struct acpi_table_header
);
584 opcode
= acpi_ps_peek_opcode(&parser_state
);
585 if (opcode
!= AML_METHOD_OP
) {
586 return (AE_BAD_PARAMETER
);
589 /* Extract method information from the raw AML */
591 parser_state
.aml
+= acpi_ps_get_opcode_size(opcode
);
592 parser_state
.pkg_end
= acpi_ps_get_next_package_end(&parser_state
);
593 path
= acpi_ps_get_next_namestring(&parser_state
);
594 method_flags
= *parser_state
.aml
++;
595 aml_start
= parser_state
.aml
;
596 aml_length
= ACPI_PTR_DIFF(parser_state
.pkg_end
, aml_start
);
599 * Allocate resources up-front. We don't want to have to delete a new
600 * node from the namespace if we cannot allocate memory.
602 aml_buffer
= ACPI_ALLOCATE(aml_length
);
604 return (AE_NO_MEMORY
);
607 method_obj
= acpi_ut_create_internal_object(ACPI_TYPE_METHOD
);
609 ACPI_FREE(aml_buffer
);
610 return (AE_NO_MEMORY
);
613 /* Lock namespace for acpi_ns_lookup, we may be creating a new node */
615 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
616 if (ACPI_FAILURE(status
)) {
620 /* The lookup either returns an existing node or creates a new one */
623 acpi_ns_lookup(NULL
, path
, ACPI_TYPE_METHOD
, ACPI_IMODE_LOAD_PASS1
,
624 ACPI_NS_DONT_OPEN_SCOPE
| ACPI_NS_ERROR_IF_FOUND
,
627 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
629 if (ACPI_FAILURE(status
)) { /* ns_lookup */
630 if (status
!= AE_ALREADY_EXISTS
) {
634 /* Node existed previously, make sure it is a method node */
636 if (node
->type
!= ACPI_TYPE_METHOD
) {
642 /* Copy the method AML to the local buffer */
644 memcpy(aml_buffer
, aml_start
, aml_length
);
646 /* Initialize the method object with the new method's information */
648 method_obj
->method
.aml_start
= aml_buffer
;
649 method_obj
->method
.aml_length
= aml_length
;
651 method_obj
->method
.param_count
= (u8
)
652 (method_flags
& AML_METHOD_ARG_COUNT
);
654 if (method_flags
& AML_METHOD_SERIALIZED
) {
655 method_obj
->method
.info_flags
= ACPI_METHOD_SERIALIZED
;
657 method_obj
->method
.sync_level
= (u8
)
658 ((method_flags
& AML_METHOD_SYNC_LEVEL
) >> 4);
662 * Now that it is complete, we can attach the new method object to
663 * the method Node (detaches/deletes any existing object)
665 status
= acpi_ns_attach_object(node
, method_obj
, ACPI_TYPE_METHOD
);
668 * Flag indicates AML buffer is dynamic, must be deleted later.
669 * Must be set only after attach above.
671 node
->flags
|= ANOBJ_ALLOCATED_BUFFER
;
673 /* Remove local reference to the method object */
675 acpi_ut_remove_reference(method_obj
);
680 ACPI_FREE(aml_buffer
);
681 ACPI_FREE(method_obj
);
684 ACPI_EXPORT_SYMBOL(acpi_install_method
)