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