blob: b2915c9cceaf6fe482727d10d8287c8fae7f65bb [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
5 * ACPI Namespace oriented interfaces
6 *
Bob Mooreda6f8322018-01-04 10:06:38 -08007 * Copyright (C) 2000 - 2018, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Erik Schmauss95857632018-03-14 16:13:07 -07009 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Lv Zheng839e9282013-10-29 09:29:51 +080011#define EXPORT_ACPI_INTERFACES
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050014#include "accommon.h"
15#include "acnamesp.h"
Lin Mingb2f7ddc2009-05-21 10:42:09 +080016#include "acparser.h"
17#include "amlcode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040020ACPI_MODULE_NAME("nsxfname")
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Bob Moore15b8dd52009-06-29 13:39:29 +080022/* Local prototypes */
Lv Zheng78e25fe2012-10-31 02:25:24 +000023static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest,
24 struct acpi_pnp_device_id *source,
Bob Moore15b8dd52009-06-29 13:39:29 +080025 char *string_area);
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/******************************************************************************
28 *
29 * FUNCTION: acpi_get_handle
30 *
Bob Mooreba494be2012-07-12 09:40:10 +080031 * PARAMETERS: parent - Object to search under (search scope).
32 * pathname - Pointer to an asciiz string containing the
Robert Moore44f6c012005-04-18 22:49:35 -040033 * name
34 * ret_handle - Where the return handle is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 *
36 * RETURN: Status
37 *
38 * DESCRIPTION: This routine will search for a caller specified name in the
Bob Moore73a30902012-10-31 02:26:55 +000039 * name space. The caller can restrict the search region by
40 * specifying a non NULL parent. The parent value is itself a
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * namespace handle.
42 *
43 ******************************************************************************/
Bob Moore15b8dd52009-06-29 13:39:29 +080044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040046acpi_get_handle(acpi_handle parent,
Lv Zhengf5c1e1c2016-05-05 12:57:53 +080047 acpi_string pathname, acpi_handle *ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Len Brown4be44fc2005-08-05 00:44:28 -040049 acpi_status status;
50 struct acpi_namespace_node *node = NULL;
51 struct acpi_namespace_node *prefix_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Len Brown4be44fc2005-08-05 00:44:28 -040053 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 /* Parameter Validation */
56
57 if (!ret_handle || !pathname) {
58 return (AE_BAD_PARAMETER);
59 }
60
61 /* Convert a parent handle to a prefix node */
62
63 if (parent) {
Bob Mooref24b6642009-12-11 14:57:00 +080064 prefix_node = acpi_ns_validate_handle(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 if (!prefix_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return (AE_BAD_PARAMETER);
67 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 }
69
70 /*
Bob Mooref1c2b1d2007-02-02 19:48:22 +030071 * Valid cases are:
72 * 1) Fully qualified pathname
73 * 2) Parent + Relative pathname
74 *
75 * Error for <null Parent + relative path>
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Bob Moore04a81dc2012-12-31 00:05:17 +000077 if (ACPI_IS_ROOT_PREFIX(pathname[0])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Bob Mooref1c2b1d2007-02-02 19:48:22 +030079 /* Pathname is fully qualified (starts with '\') */
80
81 /* Special case for root-only, since we can't search for it */
82
Bob Moore4fa46162015-07-01 14:45:11 +080083 if (!strcmp(pathname, ACPI_NS_ROOT_PATH)) {
Bob Mooref1c2b1d2007-02-02 19:48:22 +030084 *ret_handle =
Bob Mooref24b6642009-12-11 14:57:00 +080085 ACPI_CAST_PTR(acpi_handle, acpi_gbl_root_node);
Bob Mooref1c2b1d2007-02-02 19:48:22 +030086 return (AE_OK);
87 }
88 } else if (!prefix_node) {
89
90 /* Relative path with null prefix is disallowed */
91
92 return (AE_BAD_PARAMETER);
93 }
94
95 /* Find the Node and convert to a handle */
96
97 status =
98 acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
Len Brown4be44fc2005-08-05 00:44:28 -040099 if (ACPI_SUCCESS(status)) {
Bob Mooref24b6642009-12-11 14:57:00 +0800100 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102
103 return (status);
104}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Bob Moore83135242006-10-03 00:00:00 -0400106ACPI_EXPORT_SYMBOL(acpi_get_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108/******************************************************************************
109 *
110 * FUNCTION: acpi_get_name
111 *
Bob Mooreba494be2012-07-12 09:40:10 +0800112 * PARAMETERS: handle - Handle to be converted to a pathname
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 * name_type - Full pathname or single segment
Bob Mooreba494be2012-07-12 09:40:10 +0800114 * buffer - Buffer for returned path
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 * RETURN: Pointer to a string containing the fully qualified Name.
117 *
118 * DESCRIPTION: This routine returns the fully qualified name associated with
Bob Moore73a30902012-10-31 02:26:55 +0000119 * the Handle parameter. This and the acpi_pathname_to_handle are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * complementary functions.
121 *
122 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800124acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Len Brown4be44fc2005-08-05 00:44:28 -0400126 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /* Parameter validation */
129
130 if (name_type > ACPI_NAME_TYPE_MAX) {
131 return (AE_BAD_PARAMETER);
132 }
133
Len Brown4be44fc2005-08-05 00:44:28 -0400134 status = acpi_ut_validate_buffer(buffer);
135 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return (status);
137 }
138
Lv Zheng523db192016-11-30 15:20:52 +0800139 /*
140 * Wants the single segment ACPI name.
141 * Validate handle and convert to a namespace Node
142 */
143 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
144 if (ACPI_FAILURE(status)) {
145 return (status);
146 }
147
Lv Zhengd1e7ffe2015-07-23 12:52:39 +0800148 if (name_type == ACPI_FULL_PATHNAME ||
149 name_type == ACPI_FULL_PATHNAME_NO_TRAILING) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 /* Get the full pathname (From the namespace root) */
152
Lv Zhengd1e7ffe2015-07-23 12:52:39 +0800153 status = acpi_ns_handle_to_pathname(handle, buffer,
154 name_type ==
155 ACPI_FULL_PATHNAME ? FALSE :
156 TRUE);
Lv Zheng523db192016-11-30 15:20:52 +0800157 } else {
158 /* Get the single name */
159
160 status = acpi_ns_handle_to_name(handle, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
Len Brown4be44fc2005-08-05 00:44:28 -0400163 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 return (status);
165}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Bob Moore83135242006-10-03 00:00:00 -0400167ACPI_EXPORT_SYMBOL(acpi_get_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/******************************************************************************
170 *
Bob Moore15b8dd52009-06-29 13:39:29 +0800171 * FUNCTION: acpi_ns_copy_device_id
172 *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000173 * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID
174 * source - Pointer to the source PNP_DEVICE_ID
Bob Moore15b8dd52009-06-29 13:39:29 +0800175 * string_area - Pointer to where to copy the dest string
176 *
177 * RETURN: Pointer to the next string area
178 *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000179 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
Bob Moore15b8dd52009-06-29 13:39:29 +0800180 *
181 ******************************************************************************/
Lv Zheng78e25fe2012-10-31 02:25:24 +0000182static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest,
183 struct acpi_pnp_device_id *source,
Bob Moore15b8dd52009-06-29 13:39:29 +0800184 char *string_area)
185{
Lv Zheng78e25fe2012-10-31 02:25:24 +0000186 /* Create the destination PNP_DEVICE_ID */
Bob Moore15b8dd52009-06-29 13:39:29 +0800187
188 dest->string = string_area;
189 dest->length = source->length;
190
191 /* Copy actual string and return a pointer to the next string area */
192
Bob Moore4fa46162015-07-01 14:45:11 +0800193 memcpy(string_area, source->string, source->length);
Bob Moore15b8dd52009-06-29 13:39:29 +0800194 return (string_area + source->length);
195}
196
197/******************************************************************************
198 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 * FUNCTION: acpi_get_object_info
200 *
Bob Mooreba494be2012-07-12 09:40:10 +0800201 * PARAMETERS: handle - Object Handle
Bob Moore15b8dd52009-06-29 13:39:29 +0800202 * return_buffer - Where the info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 *
204 * RETURN: Status
205 *
206 * DESCRIPTION: Returns information about an object as gleaned from the
207 * namespace node and possibly by running several standard
208 * control methods (Such as in the case of a device.)
209 *
Hans de Goedee7c2c3c2018-03-14 16:13:03 -0700210 * For Device and Processor objects, run the Device _HID, _UID, _CID,
Bob Moore07cb3902015-12-29 13:55:47 +0800211 * _CLS, _ADR, _sx_w, and _sx_d methods.
Bob Moore15b8dd52009-06-29 13:39:29 +0800212 *
213 * Note: Allocates the return buffer, must be freed by the caller.
214 *
Bob Moorec6c60692015-12-29 13:56:14 +0800215 * Note: This interface is intended to be used during the initial device
216 * discovery namespace traversal. Therefore, no complex methods can be
217 * executed, especially those that access operation regions. Therefore, do
218 * not add any additional methods that could cause problems in this area.
Hans de Goedee7c2c3c2018-03-14 16:13:03 -0700219 * Because of this reason support for the following methods has been removed:
220 * 1) _SUB method was removed (11/2015)
221 * 2) _STA method was removed (02/2018)
Bob Moorec6c60692015-12-29 13:56:14 +0800222 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 ******************************************************************************/
Bob Moore15b8dd52009-06-29 13:39:29 +0800224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225acpi_status
Bob Moore15b8dd52009-06-29 13:39:29 +0800226acpi_get_object_info(acpi_handle handle,
227 struct acpi_device_info **return_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
Len Brown4be44fc2005-08-05 00:44:28 -0400229 struct acpi_namespace_node *node;
230 struct acpi_device_info *info;
Lv Zheng78e25fe2012-10-31 02:25:24 +0000231 struct acpi_pnp_device_id_list *cid_list = NULL;
232 struct acpi_pnp_device_id *hid = NULL;
233 struct acpi_pnp_device_id *uid = NULL;
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800234 struct acpi_pnp_device_id *cls = NULL;
Bob Moore15b8dd52009-06-29 13:39:29 +0800235 char *next_id_string;
236 acpi_object_type type;
237 acpi_name name;
238 u8 param_count = 0;
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800239 u16 valid = 0;
Bob Moore15b8dd52009-06-29 13:39:29 +0800240 u32 info_size;
241 u32 i;
242 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 /* Parameter validation */
245
Bob Moore15b8dd52009-06-29 13:39:29 +0800246 if (!handle || !return_buffer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 return (AE_BAD_PARAMETER);
248 }
249
Len Brown4be44fc2005-08-05 00:44:28 -0400250 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
251 if (ACPI_FAILURE(status)) {
Bob Mooreef0b67f2012-12-19 05:38:36 +0000252 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254
Bob Mooref24b6642009-12-11 14:57:00 +0800255 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400257 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Bob Moore15b8dd52009-06-29 13:39:29 +0800258 return (AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
260
Bob Moore15b8dd52009-06-29 13:39:29 +0800261 /* Get the namespace node data while the namespace is locked */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Bob Moore15b8dd52009-06-29 13:39:29 +0800263 info_size = sizeof(struct acpi_device_info);
264 type = node->type;
265 name = node->name.integer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Bob Moore0a1fbf22008-07-04 10:53:58 +0800267 if (node->type == ACPI_TYPE_METHOD) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800268 param_count = node->object->method.param_count;
Bob Moore0a1fbf22008-07-04 10:53:58 +0800269 }
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
272 if (ACPI_FAILURE(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800273 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275
Bob Moore15b8dd52009-06-29 13:39:29 +0800276 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /*
Bob Moore15b8dd52009-06-29 13:39:29 +0800278 * Get extra info for ACPI Device/Processor objects only:
Bob Moore07cb3902015-12-29 13:55:47 +0800279 * Run the Device _HID, _UID, _CLS, and _CID methods.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 *
281 * Note: none of these methods are required, so they may or may
Bob Moore15b8dd52009-06-29 13:39:29 +0800282 * not be present for this device. The Info->Valid bitfield is used
283 * to indicate which methods were found and run successfully.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 */
285
286 /* Execute the Device._HID method */
287
Bob Moore15b8dd52009-06-29 13:39:29 +0800288 status = acpi_ut_execute_HID(node, &hid);
Len Brown4be44fc2005-08-05 00:44:28 -0400289 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800290 info_size += hid->length;
291 valid |= ACPI_VALID_HID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293
294 /* Execute the Device._UID method */
295
Bob Moore15b8dd52009-06-29 13:39:29 +0800296 status = acpi_ut_execute_UID(node, &uid);
Len Brown4be44fc2005-08-05 00:44:28 -0400297 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800298 info_size += uid->length;
299 valid |= ACPI_VALID_UID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301
302 /* Execute the Device._CID method */
303
Len Brown4be44fc2005-08-05 00:44:28 -0400304 status = acpi_ut_execute_CID(node, &cid_list);
305 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800306
307 /* Add size of CID strings and CID pointer array */
308
309 info_size +=
310 (cid_list->list_size -
Lv Zheng78e25fe2012-10-31 02:25:24 +0000311 sizeof(struct acpi_pnp_device_id_list));
Bob Moore15b8dd52009-06-29 13:39:29 +0800312 valid |= ACPI_VALID_CID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 }
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800314
315 /* Execute the Device._CLS method */
316
317 status = acpi_ut_execute_CLS(node, &cls);
318 if (ACPI_SUCCESS(status)) {
319 info_size += cls->length;
320 valid |= ACPI_VALID_CLS;
321 }
Bob Moore15b8dd52009-06-29 13:39:29 +0800322 }
323
324 /*
325 * Now that we have the variable-length data, we can allocate the
326 * return buffer
327 */
328 info = ACPI_ALLOCATE_ZEROED(info_size);
329 if (!info) {
330 status = AE_NO_MEMORY;
331 goto cleanup;
332 }
333
334 /* Get the fixed-length data */
335
336 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
337 /*
338 * Get extra info for ACPI Device/Processor objects only:
Hans de Goedee7c2c3c2018-03-14 16:13:03 -0700339 * Run the _ADR and, sx_w, and _sx_d methods.
Bob Moore15b8dd52009-06-29 13:39:29 +0800340 *
Bob Moorea7d5caf2013-07-17 09:48:15 +0800341 * Notes: none of these methods are required, so they may or may
Bob Moore15b8dd52009-06-29 13:39:29 +0800342 * not be present for this device. The Info->Valid bitfield is used
343 * to indicate which methods were found and run successfully.
344 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 /* Execute the Device._ADR method */
347
Len Brown4be44fc2005-08-05 00:44:28 -0400348 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
349 &info->address);
350 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800351 valid |= ACPI_VALID_ADR;
352 }
353
354 /* Execute the Device._sx_w methods */
355
356 status = acpi_ut_execute_power_methods(node,
357 acpi_gbl_lowest_dstate_names,
358 ACPI_NUM_sx_w_METHODS,
359 info->lowest_dstates);
360 if (ACPI_SUCCESS(status)) {
361 valid |= ACPI_VALID_SXWS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
363
364 /* Execute the Device._sx_d methods */
365
Bob Moore15b8dd52009-06-29 13:39:29 +0800366 status = acpi_ut_execute_power_methods(node,
367 acpi_gbl_highest_dstate_names,
368 ACPI_NUM_sx_d_METHODS,
369 info->highest_dstates);
Len Brown4be44fc2005-08-05 00:44:28 -0400370 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800371 valid |= ACPI_VALID_SXDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
373 }
374
Bob Moore15b8dd52009-06-29 13:39:29 +0800375 /*
376 * Create a pointer to the string area of the return buffer.
377 * Point to the end of the base struct acpi_device_info structure.
378 */
379 next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids);
380 if (cid_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Lv Zheng78e25fe2012-10-31 02:25:24 +0000382 /* Point past the CID PNP_DEVICE_ID array */
Bob Moore15b8dd52009-06-29 13:39:29 +0800383
384 next_id_string +=
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800385 ((acpi_size)cid_list->count *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000386 sizeof(struct acpi_pnp_device_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388
Bob Moore15b8dd52009-06-29 13:39:29 +0800389 /*
Bob Moore07cb3902015-12-29 13:55:47 +0800390 * Copy the HID, UID, and CIDs to the return buffer. The variable-length
391 * strings are copied to the reserved area at the end of the buffer.
Bob Moore15b8dd52009-06-29 13:39:29 +0800392 *
393 * For HID and CID, check if the ID is a PCI Root Bridge.
394 */
395 if (hid) {
396 next_id_string = acpi_ns_copy_device_id(&info->hardware_id,
397 hid, next_id_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Bob Moore15b8dd52009-06-29 13:39:29 +0800399 if (acpi_ut_is_pci_root_bridge(hid->string)) {
400 info->flags |= ACPI_PCI_ROOT_BRIDGE;
401 }
402 }
403
404 if (uid) {
405 next_id_string = acpi_ns_copy_device_id(&info->unique_id,
406 uid, next_id_string);
407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 if (cid_list) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800410 info->compatible_id_list.count = cid_list->count;
411 info->compatible_id_list.list_size = cid_list->list_size;
412
413 /* Copy each CID */
414
415 for (i = 0; i < cid_list->count; i++) {
416 next_id_string =
417 acpi_ns_copy_device_id(&info->compatible_id_list.
418 ids[i], &cid_list->ids[i],
419 next_id_string);
420
421 if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) {
422 info->flags |= ACPI_PCI_ROOT_BRIDGE;
423 }
424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
426
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800427 if (cls) {
428 next_id_string = acpi_ns_copy_device_id(&info->class_code,
429 cls, next_id_string);
430 }
431
Bob Moore15b8dd52009-06-29 13:39:29 +0800432 /* Copy the fixed-length data */
433
434 info->info_size = info_size;
435 info->type = type;
436 info->name = name;
437 info->param_count = param_count;
438 info->valid = valid;
439
440 *return_buffer = info;
441 status = AE_OK;
442
Lv Zheng10622bf2013-10-29 09:30:02 +0800443cleanup:
Bob Moore15b8dd52009-06-29 13:39:29 +0800444 if (hid) {
445 ACPI_FREE(hid);
446 }
447 if (uid) {
448 ACPI_FREE(uid);
449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (cid_list) {
Bob Moore83135242006-10-03 00:00:00 -0400451 ACPI_FREE(cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
Suravee Suthikulpanitf65358e2015-07-01 14:44:04 +0800453 if (cls) {
454 ACPI_FREE(cls);
455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 return (status);
457}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Bob Moore83135242006-10-03 00:00:00 -0400459ACPI_EXPORT_SYMBOL(acpi_get_object_info)
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800460
461/******************************************************************************
462 *
463 * FUNCTION: acpi_install_method
464 *
Bob Mooreba494be2012-07-12 09:40:10 +0800465 * PARAMETERS: buffer - An ACPI table containing one control method
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800466 *
467 * RETURN: Status
468 *
469 * DESCRIPTION: Install a control method into the namespace. If the method
470 * name already exists in the namespace, it is overwritten. The
471 * input buffer must contain a valid DSDT or SSDT containing a
472 * single control method.
473 *
474 ******************************************************************************/
475acpi_status acpi_install_method(u8 *buffer)
476{
477 struct acpi_table_header *table =
478 ACPI_CAST_PTR(struct acpi_table_header, buffer);
479 u8 *aml_buffer;
480 u8 *aml_start;
481 char *path;
482 struct acpi_namespace_node *node;
483 union acpi_operand_object *method_obj;
484 struct acpi_parse_state parser_state;
485 u32 aml_length;
486 u16 opcode;
487 u8 method_flags;
488 acpi_status status;
489
490 /* Parameter validation */
491
492 if (!buffer) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000493 return (AE_BAD_PARAMETER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800494 }
495
496 /* Table must be a DSDT or SSDT */
497
498 if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) &&
499 !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000500 return (AE_BAD_HEADER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800501 }
502
503 /* First AML opcode in the table must be a control method */
504
505 parser_state.aml = buffer + sizeof(struct acpi_table_header);
506 opcode = acpi_ps_peek_opcode(&parser_state);
507 if (opcode != AML_METHOD_OP) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000508 return (AE_BAD_PARAMETER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800509 }
510
511 /* Extract method information from the raw AML */
512
513 parser_state.aml += acpi_ps_get_opcode_size(opcode);
514 parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state);
515 path = acpi_ps_get_next_namestring(&parser_state);
Bob Moore1fad8732015-12-29 13:54:36 +0800516
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800517 method_flags = *parser_state.aml++;
518 aml_start = parser_state.aml;
519 aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);
520
521 /*
522 * Allocate resources up-front. We don't want to have to delete a new
523 * node from the namespace if we cannot allocate memory.
524 */
525 aml_buffer = ACPI_ALLOCATE(aml_length);
526 if (!aml_buffer) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000527 return (AE_NO_MEMORY);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800528 }
529
530 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
531 if (!method_obj) {
532 ACPI_FREE(aml_buffer);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000533 return (AE_NO_MEMORY);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800534 }
535
536 /* Lock namespace for acpi_ns_lookup, we may be creating a new node */
537
538 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
539 if (ACPI_FAILURE(status)) {
540 goto error_exit;
541 }
542
543 /* The lookup either returns an existing node or creates a new one */
544
545 status =
546 acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
547 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
548 NULL, &node);
549
550 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
551
552 if (ACPI_FAILURE(status)) { /* ns_lookup */
553 if (status != AE_ALREADY_EXISTS) {
554 goto error_exit;
555 }
556
557 /* Node existed previously, make sure it is a method node */
558
559 if (node->type != ACPI_TYPE_METHOD) {
560 status = AE_TYPE;
561 goto error_exit;
562 }
563 }
564
565 /* Copy the method AML to the local buffer */
566
Bob Moore4fa46162015-07-01 14:45:11 +0800567 memcpy(aml_buffer, aml_start, aml_length);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800568
569 /* Initialize the method object with the new method's information */
570
571 method_obj->method.aml_start = aml_buffer;
572 method_obj->method.aml_length = aml_length;
573
574 method_obj->method.param_count = (u8)
575 (method_flags & AML_METHOD_ARG_COUNT);
576
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800577 if (method_flags & AML_METHOD_SERIALIZED) {
Lin Ming26294842011-01-12 09:19:43 +0800578 method_obj->method.info_flags = ACPI_METHOD_SERIALIZED;
579
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800580 method_obj->method.sync_level = (u8)
581 ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
582 }
583
584 /*
585 * Now that it is complete, we can attach the new method object to
586 * the method Node (detaches/deletes any existing object)
587 */
588 status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD);
589
590 /*
591 * Flag indicates AML buffer is dynamic, must be deleted later.
592 * Must be set only after attach above.
593 */
594 node->flags |= ANOBJ_ALLOCATED_BUFFER;
595
596 /* Remove local reference to the method object */
597
598 acpi_ut_remove_reference(method_obj);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000599 return (status);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800600
601error_exit:
602
603 ACPI_FREE(aml_buffer);
604 ACPI_FREE(method_obj);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000605 return (status);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800606}
607ACPI_EXPORT_SYMBOL(acpi_install_method)