blob: 76a1bd4bb0700aa6ff6b129b399ed3ebdd729ba8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
5 *
6 *****************************************************************************/
7
8/*
Bob Moorec8100dc2016-01-15 08:17:03 +08009 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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 Zheng839e9282013-10-29 09:29:51 +080045#define EXPORT_ACPI_INTERFACES
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050048#include "accommon.h"
49#include "acnamesp.h"
Lin Mingb2f7ddc2009-05-21 10:42:09 +080050#include "acparser.h"
51#include "amlcode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040054ACPI_MODULE_NAME("nsxfname")
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Bob Moore15b8dd52009-06-29 13:39:29 +080056/* Local prototypes */
Lv Zheng78e25fe2012-10-31 02:25:24 +000057static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest,
58 struct acpi_pnp_device_id *source,
Bob Moore15b8dd52009-06-29 13:39:29 +080059 char *string_area);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/******************************************************************************
62 *
63 * FUNCTION: acpi_get_handle
64 *
Bob Mooreba494be2012-07-12 09:40:10 +080065 * PARAMETERS: parent - Object to search under (search scope).
66 * pathname - Pointer to an asciiz string containing the
Robert Moore44f6c012005-04-18 22:49:35 -040067 * name
68 * ret_handle - Where the return handle is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 *
70 * RETURN: Status
71 *
72 * DESCRIPTION: This routine will search for a caller specified name in the
Bob Moore73a30902012-10-31 02:26:55 +000073 * name space. The caller can restrict the search region by
74 * specifying a non NULL parent. The parent value is itself a
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 * namespace handle.
76 *
77 ******************************************************************************/
Bob Moore15b8dd52009-06-29 13:39:29 +080078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040080acpi_get_handle(acpi_handle parent,
Lv Zhengf5c1e1c2016-05-05 12:57:53 +080081 acpi_string pathname, acpi_handle *ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Len Brown4be44fc2005-08-05 00:44:28 -040083 acpi_status status;
84 struct acpi_namespace_node *node = NULL;
85 struct acpi_namespace_node *prefix_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Len Brown4be44fc2005-08-05 00:44:28 -040087 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
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 Mooref24b6642009-12-11 14:57:00 +080098 prefix_node = acpi_ns_validate_handle(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (!prefix_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return (AE_BAD_PARAMETER);
101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103
104 /*
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300105 * Valid cases are:
106 * 1) Fully qualified pathname
107 * 2) Parent + Relative pathname
108 *
109 * Error for <null Parent + relative path>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 */
Bob Moore04a81dc2012-12-31 00:05:17 +0000111 if (ACPI_IS_ROOT_PREFIX(pathname[0])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300113 /* Pathname is fully qualified (starts with '\') */
114
115 /* Special case for root-only, since we can't search for it */
116
Bob Moore4fa46162015-07-01 14:45:11 +0800117 if (!strcmp(pathname, ACPI_NS_ROOT_PATH)) {
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300118 *ret_handle =
Bob Mooref24b6642009-12-11 14:57:00 +0800119 ACPI_CAST_PTR(acpi_handle, acpi_gbl_root_node);
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300120 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 Brown4be44fc2005-08-05 00:44:28 -0400133 if (ACPI_SUCCESS(status)) {
Bob Mooref24b6642009-12-11 14:57:00 +0800134 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
137 return (status);
138}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Bob Moore83135242006-10-03 00:00:00 -0400140ACPI_EXPORT_SYMBOL(acpi_get_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142/******************************************************************************
143 *
144 * FUNCTION: acpi_get_name
145 *
Bob Mooreba494be2012-07-12 09:40:10 +0800146 * PARAMETERS: handle - Handle to be converted to a pathname
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 * name_type - Full pathname or single segment
Bob Mooreba494be2012-07-12 09:40:10 +0800148 * buffer - Buffer for returned path
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 *
150 * RETURN: Pointer to a string containing the fully qualified Name.
151 *
152 * DESCRIPTION: This routine returns the fully qualified name associated with
Bob Moore73a30902012-10-31 02:26:55 +0000153 * the Handle parameter. This and the acpi_pathname_to_handle are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 * complementary functions.
155 *
156 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800158acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Len Brown4be44fc2005-08-05 00:44:28 -0400160 acpi_status status;
161 struct acpi_namespace_node *node;
LABBE Corentinc118abc2015-12-29 13:54:04 +0800162 const char *node_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 /* Parameter validation */
165
166 if (name_type > ACPI_NAME_TYPE_MAX) {
167 return (AE_BAD_PARAMETER);
168 }
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170 status = acpi_ut_validate_buffer(buffer);
171 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return (status);
173 }
174
Lv Zhengd1e7ffe2015-07-23 12:52:39 +0800175 if (name_type == ACPI_FULL_PATHNAME ||
176 name_type == ACPI_FULL_PATHNAME_NO_TRAILING) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 /* Get the full pathname (From the namespace root) */
179
Lv Zhengd1e7ffe2015-07-23 12:52:39 +0800180 status = acpi_ns_handle_to_pathname(handle, buffer,
181 name_type ==
182 ACPI_FULL_PATHNAME ? FALSE :
183 TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return (status);
185 }
186
187 /*
188 * Wants the single segment ACPI name.
189 * Validate handle and convert to a namespace Node
190 */
Len Brown4be44fc2005-08-05 00:44:28 -0400191 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
192 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return (status);
194 }
195
Bob Mooref24b6642009-12-11 14:57:00 +0800196 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (!node) {
198 status = AE_BAD_PARAMETER;
199 goto unlock_and_exit;
200 }
201
202 /* Validate/Allocate/Clear caller buffer */
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
205 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 goto unlock_and_exit;
207 }
208
209 /* Just copy the ACPI name from the Node and zero terminate it */
210
Jung-uk Kimbbe707e2013-07-17 09:48:58 +0800211 node_name = acpi_ut_get_node_name(node);
212 ACPI_MOVE_NAME(buffer->pointer, node_name);
Len Brown4be44fc2005-08-05 00:44:28 -0400213 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 status = AE_OK;
215
Lv Zheng10622bf2013-10-29 09:30:02 +0800216unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return (status);
220}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Bob Moore83135242006-10-03 00:00:00 -0400222ACPI_EXPORT_SYMBOL(acpi_get_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224/******************************************************************************
225 *
Bob Moore15b8dd52009-06-29 13:39:29 +0800226 * FUNCTION: acpi_ns_copy_device_id
227 *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000228 * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID
229 * source - Pointer to the source PNP_DEVICE_ID
Bob Moore15b8dd52009-06-29 13:39:29 +0800230 * string_area - Pointer to where to copy the dest string
231 *
232 * RETURN: Pointer to the next string area
233 *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000234 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
Bob Moore15b8dd52009-06-29 13:39:29 +0800235 *
236 ******************************************************************************/
Lv Zheng78e25fe2012-10-31 02:25:24 +0000237static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest,
238 struct acpi_pnp_device_id *source,
Bob Moore15b8dd52009-06-29 13:39:29 +0800239 char *string_area)
240{
Lv Zheng78e25fe2012-10-31 02:25:24 +0000241 /* Create the destination PNP_DEVICE_ID */
Bob Moore15b8dd52009-06-29 13:39:29 +0800242
243 dest->string = string_area;
244 dest->length = source->length;
245
246 /* Copy actual string and return a pointer to the next string area */
247
Bob Moore4fa46162015-07-01 14:45:11 +0800248 memcpy(string_area, source->string, source->length);
Bob Moore15b8dd52009-06-29 13:39:29 +0800249 return (string_area + source->length);
250}
251
252/******************************************************************************
253 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 * FUNCTION: acpi_get_object_info
255 *
Bob Mooreba494be2012-07-12 09:40:10 +0800256 * PARAMETERS: handle - Object Handle
Bob Moore15b8dd52009-06-29 13:39:29 +0800257 * return_buffer - Where the info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 *
259 * RETURN: Status
260 *
261 * DESCRIPTION: Returns information about an object as gleaned from the
262 * namespace node and possibly by running several standard
263 * control methods (Such as in the case of a device.)
264 *
Bob Moore07cb3902015-12-29 13:55:47 +0800265 * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
266 * _CLS, _ADR, _sx_w, and _sx_d methods.
Bob Moore15b8dd52009-06-29 13:39:29 +0800267 *
268 * Note: Allocates the return buffer, must be freed by the caller.
269 *
Bob Moorec6c60692015-12-29 13:56:14 +0800270 * Note: This interface is intended to be used during the initial device
271 * discovery namespace traversal. Therefore, no complex methods can be
272 * executed, especially those that access operation regions. Therefore, do
273 * not add any additional methods that could cause problems in this area.
274 * this was the fate of the _SUB method which was found to cause such
275 * problems and was removed (11/2015).
276 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 ******************************************************************************/
Bob Moore15b8dd52009-06-29 13:39:29 +0800278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279acpi_status
Bob Moore15b8dd52009-06-29 13:39:29 +0800280acpi_get_object_info(acpi_handle handle,
281 struct acpi_device_info **return_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
Len Brown4be44fc2005-08-05 00:44:28 -0400283 struct acpi_namespace_node *node;
284 struct acpi_device_info *info;
Lv Zheng78e25fe2012-10-31 02:25:24 +0000285 struct acpi_pnp_device_id_list *cid_list = NULL;
286 struct acpi_pnp_device_id *hid = NULL;
287 struct acpi_pnp_device_id *uid = NULL;
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800288 struct acpi_pnp_device_id *cls = NULL;
Bob Moore15b8dd52009-06-29 13:39:29 +0800289 char *next_id_string;
290 acpi_object_type type;
291 acpi_name name;
292 u8 param_count = 0;
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800293 u16 valid = 0;
Bob Moore15b8dd52009-06-29 13:39:29 +0800294 u32 info_size;
295 u32 i;
296 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 /* Parameter validation */
299
Bob Moore15b8dd52009-06-29 13:39:29 +0800300 if (!handle || !return_buffer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return (AE_BAD_PARAMETER);
302 }
303
Len Brown4be44fc2005-08-05 00:44:28 -0400304 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
305 if (ACPI_FAILURE(status)) {
Bob Mooreef0b67f2012-12-19 05:38:36 +0000306 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308
Bob Mooref24b6642009-12-11 14:57:00 +0800309 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400311 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Bob Moore15b8dd52009-06-29 13:39:29 +0800312 return (AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 }
314
Bob Moore15b8dd52009-06-29 13:39:29 +0800315 /* Get the namespace node data while the namespace is locked */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Bob Moore15b8dd52009-06-29 13:39:29 +0800317 info_size = sizeof(struct acpi_device_info);
318 type = node->type;
319 name = node->name.integer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Bob Moore0a1fbf22008-07-04 10:53:58 +0800321 if (node->type == ACPI_TYPE_METHOD) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800322 param_count = node->object->method.param_count;
Bob Moore0a1fbf22008-07-04 10:53:58 +0800323 }
324
Len Brown4be44fc2005-08-05 00:44:28 -0400325 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
326 if (ACPI_FAILURE(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800327 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
329
Bob Moore15b8dd52009-06-29 13:39:29 +0800330 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 /*
Bob Moore15b8dd52009-06-29 13:39:29 +0800332 * Get extra info for ACPI Device/Processor objects only:
Bob Moore07cb3902015-12-29 13:55:47 +0800333 * Run the Device _HID, _UID, _CLS, and _CID methods.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 *
335 * Note: none of these methods are required, so they may or may
Bob Moore15b8dd52009-06-29 13:39:29 +0800336 * not be present for this device. The Info->Valid bitfield is used
337 * to indicate which methods were found and run successfully.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 */
339
340 /* Execute the Device._HID method */
341
Bob Moore15b8dd52009-06-29 13:39:29 +0800342 status = acpi_ut_execute_HID(node, &hid);
Len Brown4be44fc2005-08-05 00:44:28 -0400343 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800344 info_size += hid->length;
345 valid |= ACPI_VALID_HID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347
348 /* Execute the Device._UID method */
349
Bob Moore15b8dd52009-06-29 13:39:29 +0800350 status = acpi_ut_execute_UID(node, &uid);
Len Brown4be44fc2005-08-05 00:44:28 -0400351 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800352 info_size += uid->length;
353 valid |= ACPI_VALID_UID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355
356 /* Execute the Device._CID method */
357
Len Brown4be44fc2005-08-05 00:44:28 -0400358 status = acpi_ut_execute_CID(node, &cid_list);
359 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800360
361 /* Add size of CID strings and CID pointer array */
362
363 info_size +=
364 (cid_list->list_size -
Lv Zheng78e25fe2012-10-31 02:25:24 +0000365 sizeof(struct acpi_pnp_device_id_list));
Bob Moore15b8dd52009-06-29 13:39:29 +0800366 valid |= ACPI_VALID_CID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800368
369 /* Execute the Device._CLS method */
370
371 status = acpi_ut_execute_CLS(node, &cls);
372 if (ACPI_SUCCESS(status)) {
373 info_size += cls->length;
374 valid |= ACPI_VALID_CLS;
375 }
Bob Moore15b8dd52009-06-29 13:39:29 +0800376 }
377
378 /*
379 * Now that we have the variable-length data, we can allocate the
380 * return buffer
381 */
382 info = ACPI_ALLOCATE_ZEROED(info_size);
383 if (!info) {
384 status = AE_NO_MEMORY;
385 goto cleanup;
386 }
387
388 /* Get the fixed-length data */
389
390 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
391 /*
392 * Get extra info for ACPI Device/Processor objects only:
393 * Run the _STA, _ADR and, sx_w, and _sx_d methods.
394 *
Bob Moorea7d5caf2013-07-17 09:48:15 +0800395 * Notes: none of these methods are required, so they may or may
Bob Moore15b8dd52009-06-29 13:39:29 +0800396 * not be present for this device. The Info->Valid bitfield is used
397 * to indicate which methods were found and run successfully.
Bob Moorea7d5caf2013-07-17 09:48:15 +0800398 *
399 * For _STA, if the method does not exist, then (as per the ACPI
400 * specification), the returned current_status flags will indicate
401 * that the device is present/functional/enabled. Otherwise, the
402 * current_status flags reflect the value returned from _STA.
Bob Moore15b8dd52009-06-29 13:39:29 +0800403 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 /* Execute the Device._STA method */
406
Len Brown4be44fc2005-08-05 00:44:28 -0400407 status = acpi_ut_execute_STA(node, &info->current_status);
408 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800409 valid |= ACPI_VALID_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411
412 /* Execute the Device._ADR method */
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
415 &info->address);
416 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800417 valid |= ACPI_VALID_ADR;
418 }
419
420 /* Execute the Device._sx_w methods */
421
422 status = acpi_ut_execute_power_methods(node,
423 acpi_gbl_lowest_dstate_names,
424 ACPI_NUM_sx_w_METHODS,
425 info->lowest_dstates);
426 if (ACPI_SUCCESS(status)) {
427 valid |= ACPI_VALID_SXWS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
430 /* Execute the Device._sx_d methods */
431
Bob Moore15b8dd52009-06-29 13:39:29 +0800432 status = acpi_ut_execute_power_methods(node,
433 acpi_gbl_highest_dstate_names,
434 ACPI_NUM_sx_d_METHODS,
435 info->highest_dstates);
Len Brown4be44fc2005-08-05 00:44:28 -0400436 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800437 valid |= ACPI_VALID_SXDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439 }
440
Bob Moore15b8dd52009-06-29 13:39:29 +0800441 /*
442 * Create a pointer to the string area of the return buffer.
443 * Point to the end of the base struct acpi_device_info structure.
444 */
445 next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids);
446 if (cid_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Lv Zheng78e25fe2012-10-31 02:25:24 +0000448 /* Point past the CID PNP_DEVICE_ID array */
Bob Moore15b8dd52009-06-29 13:39:29 +0800449
450 next_id_string +=
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800451 ((acpi_size)cid_list->count *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000452 sizeof(struct acpi_pnp_device_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
Bob Moore15b8dd52009-06-29 13:39:29 +0800455 /*
Bob Moore07cb3902015-12-29 13:55:47 +0800456 * Copy the HID, UID, and CIDs to the return buffer. The variable-length
457 * strings are copied to the reserved area at the end of the buffer.
Bob Moore15b8dd52009-06-29 13:39:29 +0800458 *
459 * For HID and CID, check if the ID is a PCI Root Bridge.
460 */
461 if (hid) {
462 next_id_string = acpi_ns_copy_device_id(&info->hardware_id,
463 hid, next_id_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Bob Moore15b8dd52009-06-29 13:39:29 +0800465 if (acpi_ut_is_pci_root_bridge(hid->string)) {
466 info->flags |= ACPI_PCI_ROOT_BRIDGE;
467 }
468 }
469
470 if (uid) {
471 next_id_string = acpi_ns_copy_device_id(&info->unique_id,
472 uid, next_id_string);
473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 if (cid_list) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800476 info->compatible_id_list.count = cid_list->count;
477 info->compatible_id_list.list_size = cid_list->list_size;
478
479 /* Copy each CID */
480
481 for (i = 0; i < cid_list->count; i++) {
482 next_id_string =
483 acpi_ns_copy_device_id(&info->compatible_id_list.
484 ids[i], &cid_list->ids[i],
485 next_id_string);
486
487 if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) {
488 info->flags |= ACPI_PCI_ROOT_BRIDGE;
489 }
490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800493 if (cls) {
494 next_id_string = acpi_ns_copy_device_id(&info->class_code,
495 cls, next_id_string);
496 }
497
Bob Moore15b8dd52009-06-29 13:39:29 +0800498 /* Copy the fixed-length data */
499
500 info->info_size = info_size;
501 info->type = type;
502 info->name = name;
503 info->param_count = param_count;
504 info->valid = valid;
505
506 *return_buffer = info;
507 status = AE_OK;
508
Lv Zheng10622bf2013-10-29 09:30:02 +0800509cleanup:
Bob Moore15b8dd52009-06-29 13:39:29 +0800510 if (hid) {
511 ACPI_FREE(hid);
512 }
513 if (uid) {
514 ACPI_FREE(uid);
515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (cid_list) {
Bob Moore83135242006-10-03 00:00:00 -0400517 ACPI_FREE(cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800519 if (cls) {
520 ACPI_FREE(cls);
521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 return (status);
523}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Bob Moore83135242006-10-03 00:00:00 -0400525ACPI_EXPORT_SYMBOL(acpi_get_object_info)
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800526
527/******************************************************************************
528 *
529 * FUNCTION: acpi_install_method
530 *
Bob Mooreba494be2012-07-12 09:40:10 +0800531 * PARAMETERS: buffer - An ACPI table containing one control method
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800532 *
533 * RETURN: Status
534 *
535 * DESCRIPTION: Install a control method into the namespace. If the method
536 * name already exists in the namespace, it is overwritten. The
537 * input buffer must contain a valid DSDT or SSDT containing a
538 * single control method.
539 *
540 ******************************************************************************/
541acpi_status acpi_install_method(u8 *buffer)
542{
543 struct acpi_table_header *table =
544 ACPI_CAST_PTR(struct acpi_table_header, buffer);
545 u8 *aml_buffer;
546 u8 *aml_start;
547 char *path;
548 struct acpi_namespace_node *node;
549 union acpi_operand_object *method_obj;
550 struct acpi_parse_state parser_state;
551 u32 aml_length;
552 u16 opcode;
553 u8 method_flags;
554 acpi_status status;
555
556 /* Parameter validation */
557
558 if (!buffer) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000559 return (AE_BAD_PARAMETER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800560 }
561
562 /* Table must be a DSDT or SSDT */
563
564 if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) &&
565 !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000566 return (AE_BAD_HEADER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800567 }
568
569 /* First AML opcode in the table must be a control method */
570
571 parser_state.aml = buffer + sizeof(struct acpi_table_header);
572 opcode = acpi_ps_peek_opcode(&parser_state);
573 if (opcode != AML_METHOD_OP) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000574 return (AE_BAD_PARAMETER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800575 }
576
577 /* Extract method information from the raw AML */
578
579 parser_state.aml += acpi_ps_get_opcode_size(opcode);
580 parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state);
581 path = acpi_ps_get_next_namestring(&parser_state);
Bob Moore1fad8732015-12-29 13:54:36 +0800582
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800583 method_flags = *parser_state.aml++;
584 aml_start = parser_state.aml;
585 aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);
586
587 /*
588 * Allocate resources up-front. We don't want to have to delete a new
589 * node from the namespace if we cannot allocate memory.
590 */
591 aml_buffer = ACPI_ALLOCATE(aml_length);
592 if (!aml_buffer) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000593 return (AE_NO_MEMORY);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800594 }
595
596 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
597 if (!method_obj) {
598 ACPI_FREE(aml_buffer);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000599 return (AE_NO_MEMORY);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800600 }
601
602 /* Lock namespace for acpi_ns_lookup, we may be creating a new node */
603
604 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
605 if (ACPI_FAILURE(status)) {
606 goto error_exit;
607 }
608
609 /* The lookup either returns an existing node or creates a new one */
610
611 status =
612 acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
613 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
614 NULL, &node);
615
616 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
617
618 if (ACPI_FAILURE(status)) { /* ns_lookup */
619 if (status != AE_ALREADY_EXISTS) {
620 goto error_exit;
621 }
622
623 /* Node existed previously, make sure it is a method node */
624
625 if (node->type != ACPI_TYPE_METHOD) {
626 status = AE_TYPE;
627 goto error_exit;
628 }
629 }
630
631 /* Copy the method AML to the local buffer */
632
Bob Moore4fa46162015-07-01 14:45:11 +0800633 memcpy(aml_buffer, aml_start, aml_length);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800634
635 /* Initialize the method object with the new method's information */
636
637 method_obj->method.aml_start = aml_buffer;
638 method_obj->method.aml_length = aml_length;
639
640 method_obj->method.param_count = (u8)
641 (method_flags & AML_METHOD_ARG_COUNT);
642
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800643 if (method_flags & AML_METHOD_SERIALIZED) {
Lin Ming26294842011-01-12 09:19:43 +0800644 method_obj->method.info_flags = ACPI_METHOD_SERIALIZED;
645
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800646 method_obj->method.sync_level = (u8)
647 ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
648 }
649
650 /*
651 * Now that it is complete, we can attach the new method object to
652 * the method Node (detaches/deletes any existing object)
653 */
654 status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD);
655
656 /*
657 * Flag indicates AML buffer is dynamic, must be deleted later.
658 * Must be set only after attach above.
659 */
660 node->flags |= ANOBJ_ALLOCATED_BUFFER;
661
662 /* Remove local reference to the method object */
663
664 acpi_ut_remove_reference(method_obj);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000665 return (status);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800666
667error_exit:
668
669 ACPI_FREE(aml_buffer);
670 ACPI_FREE(method_obj);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000671 return (status);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800672}
673ACPI_EXPORT_SYMBOL(acpi_install_method)