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