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