Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: nsxfname - Public interfaces to the ACPI subsystem |
| 5 | * ACPI Namespace oriented interfaces |
| 6 | * |
Bob Moore | da6f832 | 2018-01-04 10:06:38 -0800 | [diff] [blame] | 7 | * Copyright (C) 2000 - 2018, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 9 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 11 | #define EXPORT_ACPI_INTERFACES |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 14 | #include "accommon.h" |
| 15 | #include "acnamesp.h" |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 16 | #include "acparser.h" |
| 17 | #include "amlcode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 20 | ACPI_MODULE_NAME("nsxfname") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 22 | /* Local prototypes */ |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 23 | static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest, |
| 24 | struct acpi_pnp_device_id *source, |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 25 | char *string_area); |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | /****************************************************************************** |
| 28 | * |
| 29 | * FUNCTION: acpi_get_handle |
| 30 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 31 | * PARAMETERS: parent - Object to search under (search scope). |
| 32 | * pathname - Pointer to an asciiz string containing the |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 33 | * name |
| 34 | * ret_handle - Where the return handle is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * |
| 36 | * RETURN: Status |
| 37 | * |
| 38 | * DESCRIPTION: This routine will search for a caller specified name in the |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 39 | * name space. The caller can restrict the search region by |
| 40 | * specifying a non NULL parent. The parent value is itself a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * namespace handle. |
| 42 | * |
| 43 | ******************************************************************************/ |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 46 | acpi_get_handle(acpi_handle parent, |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 47 | acpi_string pathname, acpi_handle *ret_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | acpi_status status; |
| 50 | struct acpi_namespace_node *node = NULL; |
| 51 | struct acpi_namespace_node *prefix_node = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* Parameter Validation */ |
| 56 | |
| 57 | if (!ret_handle || !pathname) { |
| 58 | return (AE_BAD_PARAMETER); |
| 59 | } |
| 60 | |
| 61 | /* Convert a parent handle to a prefix node */ |
| 62 | |
| 63 | if (parent) { |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 64 | prefix_node = acpi_ns_validate_handle(parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | if (!prefix_node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return (AE_BAD_PARAMETER); |
| 67 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /* |
Bob Moore | f1c2b1d | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 71 | * Valid cases are: |
| 72 | * 1) Fully qualified pathname |
| 73 | * 2) Parent + Relative pathname |
| 74 | * |
| 75 | * Error for <null Parent + relative path> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | */ |
Bob Moore | 04a81dc | 2012-12-31 00:05:17 +0000 | [diff] [blame] | 77 | if (ACPI_IS_ROOT_PREFIX(pathname[0])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Bob Moore | f1c2b1d | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 79 | /* Pathname is fully qualified (starts with '\') */ |
| 80 | |
| 81 | /* Special case for root-only, since we can't search for it */ |
| 82 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 83 | if (!strcmp(pathname, ACPI_NS_ROOT_PATH)) { |
Bob Moore | f1c2b1d | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 84 | *ret_handle = |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 85 | ACPI_CAST_PTR(acpi_handle, acpi_gbl_root_node); |
Bob Moore | f1c2b1d | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 86 | return (AE_OK); |
| 87 | } |
| 88 | } else if (!prefix_node) { |
| 89 | |
| 90 | /* Relative path with null prefix is disallowed */ |
| 91 | |
| 92 | return (AE_BAD_PARAMETER); |
| 93 | } |
| 94 | |
| 95 | /* Find the Node and convert to a handle */ |
| 96 | |
| 97 | status = |
| 98 | acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | if (ACPI_SUCCESS(status)) { |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 100 | *ret_handle = ACPI_CAST_PTR(acpi_handle, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | return (status); |
| 104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 106 | ACPI_EXPORT_SYMBOL(acpi_get_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | /****************************************************************************** |
| 109 | * |
| 110 | * FUNCTION: acpi_get_name |
| 111 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 112 | * PARAMETERS: handle - Handle to be converted to a pathname |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * name_type - Full pathname or single segment |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 114 | * buffer - Buffer for returned path |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | * |
| 116 | * RETURN: Pointer to a string containing the fully qualified Name. |
| 117 | * |
| 118 | * DESCRIPTION: This routine returns the fully qualified name associated with |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 119 | * the Handle parameter. This and the acpi_pathname_to_handle are |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | * complementary functions. |
| 121 | * |
| 122 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | acpi_status |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 124 | acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* Parameter validation */ |
| 129 | |
| 130 | if (name_type > ACPI_NAME_TYPE_MAX) { |
| 131 | return (AE_BAD_PARAMETER); |
| 132 | } |
| 133 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | status = acpi_ut_validate_buffer(buffer); |
| 135 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | return (status); |
| 137 | } |
| 138 | |
Lv Zheng | 523db19 | 2016-11-30 15:20:52 +0800 | [diff] [blame] | 139 | /* |
| 140 | * Wants the single segment ACPI name. |
| 141 | * Validate handle and convert to a namespace Node |
| 142 | */ |
| 143 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 144 | if (ACPI_FAILURE(status)) { |
| 145 | return (status); |
| 146 | } |
| 147 | |
Lv Zheng | d1e7ffe | 2015-07-23 12:52:39 +0800 | [diff] [blame] | 148 | if (name_type == ACPI_FULL_PATHNAME || |
| 149 | name_type == ACPI_FULL_PATHNAME_NO_TRAILING) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* Get the full pathname (From the namespace root) */ |
| 152 | |
Lv Zheng | d1e7ffe | 2015-07-23 12:52:39 +0800 | [diff] [blame] | 153 | status = acpi_ns_handle_to_pathname(handle, buffer, |
| 154 | name_type == |
| 155 | ACPI_FULL_PATHNAME ? FALSE : |
| 156 | TRUE); |
Lv Zheng | 523db19 | 2016-11-30 15:20:52 +0800 | [diff] [blame] | 157 | } else { |
| 158 | /* Get the single name */ |
| 159 | |
| 160 | status = acpi_ns_handle_to_name(handle, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | return (status); |
| 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 167 | ACPI_EXPORT_SYMBOL(acpi_get_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | /****************************************************************************** |
| 170 | * |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 171 | * FUNCTION: acpi_ns_copy_device_id |
| 172 | * |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 173 | * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID |
| 174 | * source - Pointer to the source PNP_DEVICE_ID |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 175 | * string_area - Pointer to where to copy the dest string |
| 176 | * |
| 177 | * RETURN: Pointer to the next string area |
| 178 | * |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 179 | * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data. |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 180 | * |
| 181 | ******************************************************************************/ |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 182 | static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest, |
| 183 | struct acpi_pnp_device_id *source, |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 184 | char *string_area) |
| 185 | { |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 186 | /* Create the destination PNP_DEVICE_ID */ |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 187 | |
| 188 | dest->string = string_area; |
| 189 | dest->length = source->length; |
| 190 | |
| 191 | /* Copy actual string and return a pointer to the next string area */ |
| 192 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 193 | memcpy(string_area, source->string, source->length); |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 194 | return (string_area + source->length); |
| 195 | } |
| 196 | |
| 197 | /****************************************************************************** |
| 198 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | * FUNCTION: acpi_get_object_info |
| 200 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 201 | * PARAMETERS: handle - Object Handle |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 202 | * return_buffer - Where the info is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | * |
| 204 | * RETURN: Status |
| 205 | * |
| 206 | * DESCRIPTION: Returns information about an object as gleaned from the |
| 207 | * namespace node and possibly by running several standard |
| 208 | * control methods (Such as in the case of a device.) |
| 209 | * |
Hans de Goede | e7c2c3c | 2018-03-14 16:13:03 -0700 | [diff] [blame] | 210 | * For Device and Processor objects, run the Device _HID, _UID, _CID, |
Bob Moore | 07cb390 | 2015-12-29 13:55:47 +0800 | [diff] [blame] | 211 | * _CLS, _ADR, _sx_w, and _sx_d methods. |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 212 | * |
| 213 | * Note: Allocates the return buffer, must be freed by the caller. |
| 214 | * |
Bob Moore | c6c6069 | 2015-12-29 13:56:14 +0800 | [diff] [blame] | 215 | * Note: This interface is intended to be used during the initial device |
| 216 | * discovery namespace traversal. Therefore, no complex methods can be |
| 217 | * executed, especially those that access operation regions. Therefore, do |
| 218 | * not add any additional methods that could cause problems in this area. |
Hans de Goede | e7c2c3c | 2018-03-14 16:13:03 -0700 | [diff] [blame] | 219 | * Because of this reason support for the following methods has been removed: |
| 220 | * 1) _SUB method was removed (11/2015) |
| 221 | * 2) _STA method was removed (02/2018) |
Bob Moore | c6c6069 | 2015-12-29 13:56:14 +0800 | [diff] [blame] | 222 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | ******************************************************************************/ |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | acpi_status |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 226 | acpi_get_object_info(acpi_handle handle, |
| 227 | struct acpi_device_info **return_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | struct acpi_namespace_node *node; |
| 230 | struct acpi_device_info *info; |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 231 | struct acpi_pnp_device_id_list *cid_list = NULL; |
| 232 | struct acpi_pnp_device_id *hid = NULL; |
| 233 | struct acpi_pnp_device_id *uid = NULL; |
Suravee Suthikulpanit | f65358e | 2015-07-01 14:44:04 +0800 | [diff] [blame] | 234 | struct acpi_pnp_device_id *cls = NULL; |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 235 | char *next_id_string; |
| 236 | acpi_object_type type; |
| 237 | acpi_name name; |
| 238 | u8 param_count = 0; |
Suravee Suthikulpanit | f65358e | 2015-07-01 14:44:04 +0800 | [diff] [blame] | 239 | u16 valid = 0; |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 240 | u32 info_size; |
| 241 | u32 i; |
| 242 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | /* Parameter validation */ |
| 245 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 246 | if (!handle || !return_buffer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return (AE_BAD_PARAMETER); |
| 248 | } |
| 249 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 251 | if (ACPI_FAILURE(status)) { |
Bob Moore | ef0b67f | 2012-12-19 05:38:36 +0000 | [diff] [blame] | 252 | return (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 255 | node = acpi_ns_validate_handle(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (!node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 258 | return (AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 261 | /* Get the namespace node data while the namespace is locked */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 263 | info_size = sizeof(struct acpi_device_info); |
| 264 | type = node->type; |
| 265 | name = node->name.integer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Bob Moore | 0a1fbf2 | 2008-07-04 10:53:58 +0800 | [diff] [blame] | 267 | if (node->type == ACPI_TYPE_METHOD) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 268 | param_count = node->object->method.param_count; |
Bob Moore | 0a1fbf2 | 2008-07-04 10:53:58 +0800 | [diff] [blame] | 269 | } |
| 270 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 272 | if (ACPI_FAILURE(status)) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 273 | return (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 276 | if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /* |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 278 | * Get extra info for ACPI Device/Processor objects only: |
Bob Moore | 07cb390 | 2015-12-29 13:55:47 +0800 | [diff] [blame] | 279 | * Run the Device _HID, _UID, _CLS, and _CID methods. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | * |
| 281 | * Note: none of these methods are required, so they may or may |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 282 | * not be present for this device. The Info->Valid bitfield is used |
| 283 | * to indicate which methods were found and run successfully. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | */ |
| 285 | |
| 286 | /* Execute the Device._HID method */ |
| 287 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 288 | status = acpi_ut_execute_HID(node, &hid); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 290 | info_size += hid->length; |
| 291 | valid |= ACPI_VALID_HID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* Execute the Device._UID method */ |
| 295 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 296 | status = acpi_ut_execute_UID(node, &uid); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 298 | info_size += uid->length; |
| 299 | valid |= ACPI_VALID_UID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* Execute the Device._CID method */ |
| 303 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 304 | status = acpi_ut_execute_CID(node, &cid_list); |
| 305 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 306 | |
| 307 | /* Add size of CID strings and CID pointer array */ |
| 308 | |
| 309 | info_size += |
| 310 | (cid_list->list_size - |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 311 | sizeof(struct acpi_pnp_device_id_list)); |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 312 | valid |= ACPI_VALID_CID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
Suravee Suthikulpanit | f65358e | 2015-07-01 14:44:04 +0800 | [diff] [blame] | 314 | |
| 315 | /* Execute the Device._CLS method */ |
| 316 | |
| 317 | status = acpi_ut_execute_CLS(node, &cls); |
| 318 | if (ACPI_SUCCESS(status)) { |
| 319 | info_size += cls->length; |
| 320 | valid |= ACPI_VALID_CLS; |
| 321 | } |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Now that we have the variable-length data, we can allocate the |
| 326 | * return buffer |
| 327 | */ |
| 328 | info = ACPI_ALLOCATE_ZEROED(info_size); |
| 329 | if (!info) { |
| 330 | status = AE_NO_MEMORY; |
| 331 | goto cleanup; |
| 332 | } |
| 333 | |
| 334 | /* Get the fixed-length data */ |
| 335 | |
| 336 | if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) { |
| 337 | /* |
| 338 | * Get extra info for ACPI Device/Processor objects only: |
Hans de Goede | e7c2c3c | 2018-03-14 16:13:03 -0700 | [diff] [blame] | 339 | * Run the _ADR and, sx_w, and _sx_d methods. |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 340 | * |
Bob Moore | a7d5caf | 2013-07-17 09:48:15 +0800 | [diff] [blame] | 341 | * Notes: none of these methods are required, so they may or may |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 342 | * not be present for this device. The Info->Valid bitfield is used |
| 343 | * to indicate which methods were found and run successfully. |
| 344 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | /* Execute the Device._ADR method */ |
| 347 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node, |
| 349 | &info->address); |
| 350 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 351 | valid |= ACPI_VALID_ADR; |
| 352 | } |
| 353 | |
| 354 | /* Execute the Device._sx_w methods */ |
| 355 | |
| 356 | status = acpi_ut_execute_power_methods(node, |
| 357 | acpi_gbl_lowest_dstate_names, |
| 358 | ACPI_NUM_sx_w_METHODS, |
| 359 | info->lowest_dstates); |
| 360 | if (ACPI_SUCCESS(status)) { |
| 361 | valid |= ACPI_VALID_SXWS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /* Execute the Device._sx_d methods */ |
| 365 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 366 | status = acpi_ut_execute_power_methods(node, |
| 367 | acpi_gbl_highest_dstate_names, |
| 368 | ACPI_NUM_sx_d_METHODS, |
| 369 | info->highest_dstates); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 370 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 371 | valid |= ACPI_VALID_SXDS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 375 | /* |
| 376 | * Create a pointer to the string area of the return buffer. |
| 377 | * Point to the end of the base struct acpi_device_info structure. |
| 378 | */ |
| 379 | next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids); |
| 380 | if (cid_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 382 | /* Point past the CID PNP_DEVICE_ID array */ |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 383 | |
| 384 | next_id_string += |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 385 | ((acpi_size)cid_list->count * |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 386 | sizeof(struct acpi_pnp_device_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 389 | /* |
Bob Moore | 07cb390 | 2015-12-29 13:55:47 +0800 | [diff] [blame] | 390 | * Copy the HID, UID, and CIDs to the return buffer. The variable-length |
| 391 | * strings are copied to the reserved area at the end of the buffer. |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 392 | * |
| 393 | * For HID and CID, check if the ID is a PCI Root Bridge. |
| 394 | */ |
| 395 | if (hid) { |
| 396 | next_id_string = acpi_ns_copy_device_id(&info->hardware_id, |
| 397 | hid, next_id_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 399 | if (acpi_ut_is_pci_root_bridge(hid->string)) { |
| 400 | info->flags |= ACPI_PCI_ROOT_BRIDGE; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | if (uid) { |
| 405 | next_id_string = acpi_ns_copy_device_id(&info->unique_id, |
| 406 | uid, next_id_string); |
| 407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | if (cid_list) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 410 | info->compatible_id_list.count = cid_list->count; |
| 411 | info->compatible_id_list.list_size = cid_list->list_size; |
| 412 | |
| 413 | /* Copy each CID */ |
| 414 | |
| 415 | for (i = 0; i < cid_list->count; i++) { |
| 416 | next_id_string = |
| 417 | acpi_ns_copy_device_id(&info->compatible_id_list. |
| 418 | ids[i], &cid_list->ids[i], |
| 419 | next_id_string); |
| 420 | |
| 421 | if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) { |
| 422 | info->flags |= ACPI_PCI_ROOT_BRIDGE; |
| 423 | } |
| 424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Suravee Suthikulpanit | f65358e | 2015-07-01 14:44:04 +0800 | [diff] [blame] | 427 | if (cls) { |
| 428 | next_id_string = acpi_ns_copy_device_id(&info->class_code, |
| 429 | cls, next_id_string); |
| 430 | } |
| 431 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 432 | /* Copy the fixed-length data */ |
| 433 | |
| 434 | info->info_size = info_size; |
| 435 | info->type = type; |
| 436 | info->name = name; |
| 437 | info->param_count = param_count; |
| 438 | info->valid = valid; |
| 439 | |
| 440 | *return_buffer = info; |
| 441 | status = AE_OK; |
| 442 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 443 | cleanup: |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 444 | if (hid) { |
| 445 | ACPI_FREE(hid); |
| 446 | } |
| 447 | if (uid) { |
| 448 | ACPI_FREE(uid); |
| 449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if (cid_list) { |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 451 | ACPI_FREE(cid_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
Suravee Suthikulpanit | f65358e | 2015-07-01 14:44:04 +0800 | [diff] [blame] | 453 | if (cls) { |
| 454 | ACPI_FREE(cls); |
| 455 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return (status); |
| 457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 459 | ACPI_EXPORT_SYMBOL(acpi_get_object_info) |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 460 | |
| 461 | /****************************************************************************** |
| 462 | * |
| 463 | * FUNCTION: acpi_install_method |
| 464 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 465 | * PARAMETERS: buffer - An ACPI table containing one control method |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 466 | * |
| 467 | * RETURN: Status |
| 468 | * |
| 469 | * DESCRIPTION: Install a control method into the namespace. If the method |
| 470 | * name already exists in the namespace, it is overwritten. The |
| 471 | * input buffer must contain a valid DSDT or SSDT containing a |
| 472 | * single control method. |
| 473 | * |
| 474 | ******************************************************************************/ |
| 475 | acpi_status acpi_install_method(u8 *buffer) |
| 476 | { |
| 477 | struct acpi_table_header *table = |
| 478 | ACPI_CAST_PTR(struct acpi_table_header, buffer); |
| 479 | u8 *aml_buffer; |
| 480 | u8 *aml_start; |
| 481 | char *path; |
| 482 | struct acpi_namespace_node *node; |
| 483 | union acpi_operand_object *method_obj; |
| 484 | struct acpi_parse_state parser_state; |
| 485 | u32 aml_length; |
| 486 | u16 opcode; |
| 487 | u8 method_flags; |
| 488 | acpi_status status; |
| 489 | |
| 490 | /* Parameter validation */ |
| 491 | |
| 492 | if (!buffer) { |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 493 | return (AE_BAD_PARAMETER); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /* Table must be a DSDT or SSDT */ |
| 497 | |
| 498 | if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) && |
| 499 | !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) { |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 500 | return (AE_BAD_HEADER); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* First AML opcode in the table must be a control method */ |
| 504 | |
| 505 | parser_state.aml = buffer + sizeof(struct acpi_table_header); |
| 506 | opcode = acpi_ps_peek_opcode(&parser_state); |
| 507 | if (opcode != AML_METHOD_OP) { |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 508 | return (AE_BAD_PARAMETER); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* Extract method information from the raw AML */ |
| 512 | |
| 513 | parser_state.aml += acpi_ps_get_opcode_size(opcode); |
| 514 | parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state); |
| 515 | path = acpi_ps_get_next_namestring(&parser_state); |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 516 | |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 517 | method_flags = *parser_state.aml++; |
| 518 | aml_start = parser_state.aml; |
| 519 | aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start); |
| 520 | |
| 521 | /* |
| 522 | * Allocate resources up-front. We don't want to have to delete a new |
| 523 | * node from the namespace if we cannot allocate memory. |
| 524 | */ |
| 525 | aml_buffer = ACPI_ALLOCATE(aml_length); |
| 526 | if (!aml_buffer) { |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 527 | return (AE_NO_MEMORY); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD); |
| 531 | if (!method_obj) { |
| 532 | ACPI_FREE(aml_buffer); |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 533 | return (AE_NO_MEMORY); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* Lock namespace for acpi_ns_lookup, we may be creating a new node */ |
| 537 | |
| 538 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 539 | if (ACPI_FAILURE(status)) { |
| 540 | goto error_exit; |
| 541 | } |
| 542 | |
| 543 | /* The lookup either returns an existing node or creates a new one */ |
| 544 | |
| 545 | status = |
| 546 | acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1, |
| 547 | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, |
| 548 | NULL, &node); |
| 549 | |
| 550 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 551 | |
| 552 | if (ACPI_FAILURE(status)) { /* ns_lookup */ |
| 553 | if (status != AE_ALREADY_EXISTS) { |
| 554 | goto error_exit; |
| 555 | } |
| 556 | |
| 557 | /* Node existed previously, make sure it is a method node */ |
| 558 | |
| 559 | if (node->type != ACPI_TYPE_METHOD) { |
| 560 | status = AE_TYPE; |
| 561 | goto error_exit; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | /* Copy the method AML to the local buffer */ |
| 566 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 567 | memcpy(aml_buffer, aml_start, aml_length); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 568 | |
| 569 | /* Initialize the method object with the new method's information */ |
| 570 | |
| 571 | method_obj->method.aml_start = aml_buffer; |
| 572 | method_obj->method.aml_length = aml_length; |
| 573 | |
| 574 | method_obj->method.param_count = (u8) |
| 575 | (method_flags & AML_METHOD_ARG_COUNT); |
| 576 | |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 577 | if (method_flags & AML_METHOD_SERIALIZED) { |
Lin Ming | 2629484 | 2011-01-12 09:19:43 +0800 | [diff] [blame] | 578 | method_obj->method.info_flags = ACPI_METHOD_SERIALIZED; |
| 579 | |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 580 | method_obj->method.sync_level = (u8) |
| 581 | ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4); |
| 582 | } |
| 583 | |
| 584 | /* |
| 585 | * Now that it is complete, we can attach the new method object to |
| 586 | * the method Node (detaches/deletes any existing object) |
| 587 | */ |
| 588 | status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD); |
| 589 | |
| 590 | /* |
| 591 | * Flag indicates AML buffer is dynamic, must be deleted later. |
| 592 | * Must be set only after attach above. |
| 593 | */ |
| 594 | node->flags |= ANOBJ_ALLOCATED_BUFFER; |
| 595 | |
| 596 | /* Remove local reference to the method object */ |
| 597 | |
| 598 | acpi_ut_remove_reference(method_obj); |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 599 | return (status); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 600 | |
| 601 | error_exit: |
| 602 | |
| 603 | ACPI_FREE(aml_buffer); |
| 604 | ACPI_FREE(method_obj); |
Lv Zheng | 9c0d793 | 2012-12-19 05:37:21 +0000 | [diff] [blame] | 605 | return (status); |
Lin Ming | b2f7ddc | 2009-05-21 10:42:09 +0800 | [diff] [blame] | 606 | } |
| 607 | ACPI_EXPORT_SYMBOL(acpi_install_method) |