blob: 1664fad5e303fd888dfa161b45d63df87e7b001b [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 Moore77848132012-01-12 13:27:23 +08009 * Copyright (C) 2000 - 2012, 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
Paul Gortmaker214f2c92011-10-26 16:22:14 -040045#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acnamesp.h"
Lin Mingb2f7ddc2009-05-21 10:42:09 +080049#include "acparser.h"
50#include "amlcode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040053ACPI_MODULE_NAME("nsxfname")
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Bob Moore15b8dd52009-06-29 13:39:29 +080055/* Local prototypes */
Lv Zheng78e25fe2012-10-31 02:25:24 +000056static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest,
57 struct acpi_pnp_device_id *source,
Bob Moore15b8dd52009-06-29 13:39:29 +080058 char *string_area);
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060/******************************************************************************
61 *
62 * FUNCTION: acpi_get_handle
63 *
Bob Mooreba494be2012-07-12 09:40:10 +080064 * PARAMETERS: parent - Object to search under (search scope).
65 * pathname - Pointer to an asciiz string containing the
Robert Moore44f6c012005-04-18 22:49:35 -040066 * name
67 * ret_handle - Where the return handle is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 *
69 * RETURN: Status
70 *
71 * DESCRIPTION: This routine will search for a caller specified name in the
Bob Moore73a30902012-10-31 02:26:55 +000072 * name space. The caller can restrict the search region by
73 * specifying a non NULL parent. The parent value is itself a
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * namespace handle.
75 *
76 ******************************************************************************/
Bob Moore15b8dd52009-06-29 13:39:29 +080077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040079acpi_get_handle(acpi_handle parent,
80 acpi_string pathname, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Len Brown4be44fc2005-08-05 00:44:28 -040082 acpi_status status;
83 struct acpi_namespace_node *node = NULL;
84 struct acpi_namespace_node *prefix_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Len Brown4be44fc2005-08-05 00:44:28 -040086 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
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 Mooref24b6642009-12-11 14:57:00 +080097 prefix_node = acpi_ns_validate_handle(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (!prefix_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return (AE_BAD_PARAMETER);
100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102
103 /*
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300104 * Valid cases are:
105 * 1) Fully qualified pathname
106 * 2) Parent + Relative pathname
107 *
108 * Error for <null Parent + relative path>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 */
Bob Moore04a81dc2012-12-31 00:05:17 +0000110 if (ACPI_IS_ROOT_PREFIX(pathname[0])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300112 /* 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 Mooref24b6642009-12-11 14:57:00 +0800118 ACPI_CAST_PTR(acpi_handle, acpi_gbl_root_node);
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300119 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 Brown4be44fc2005-08-05 00:44:28 -0400132 if (ACPI_SUCCESS(status)) {
Bob Mooref24b6642009-12-11 14:57:00 +0800133 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
135
136 return (status);
137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Bob Moore83135242006-10-03 00:00:00 -0400139ACPI_EXPORT_SYMBOL(acpi_get_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141/******************************************************************************
142 *
143 * FUNCTION: acpi_get_name
144 *
Bob Mooreba494be2012-07-12 09:40:10 +0800145 * PARAMETERS: handle - Handle to be converted to a pathname
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 * name_type - Full pathname or single segment
Bob Mooreba494be2012-07-12 09:40:10 +0800147 * buffer - Buffer for returned path
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 *
149 * RETURN: Pointer to a string containing the fully qualified Name.
150 *
151 * DESCRIPTION: This routine returns the fully qualified name associated with
Bob Moore73a30902012-10-31 02:26:55 +0000152 * the Handle parameter. This and the acpi_pathname_to_handle are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 * complementary functions.
154 *
155 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400157acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Len Brown4be44fc2005-08-05 00:44:28 -0400159 acpi_status status;
160 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 /* Parameter validation */
163
164 if (name_type > ACPI_NAME_TYPE_MAX) {
165 return (AE_BAD_PARAMETER);
166 }
167
Len Brown4be44fc2005-08-05 00:44:28 -0400168 status = acpi_ut_validate_buffer(buffer);
169 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return (status);
171 }
172
173 if (name_type == ACPI_FULL_PATHNAME) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 /* Get the full pathname (From the namespace root) */
176
Len Brown4be44fc2005-08-05 00:44:28 -0400177 status = acpi_ns_handle_to_pathname(handle, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return (status);
179 }
180
181 /*
182 * Wants the single segment ACPI name.
183 * Validate handle and convert to a namespace Node
184 */
Len Brown4be44fc2005-08-05 00:44:28 -0400185 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
186 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 return (status);
188 }
189
Bob Mooref24b6642009-12-11 14:57:00 +0800190 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if (!node) {
192 status = AE_BAD_PARAMETER;
193 goto unlock_and_exit;
194 }
195
196 /* Validate/Allocate/Clear caller buffer */
197
Len Brown4be44fc2005-08-05 00:44:28 -0400198 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
199 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 goto unlock_and_exit;
201 }
202
203 /* Just copy the ACPI name from the Node and zero terminate it */
204
Bob Mooreeed95252012-10-31 02:28:03 +0000205 ACPI_MOVE_NAME(buffer->pointer, acpi_ut_get_node_name(node));
Len Brown4be44fc2005-08-05 00:44:28 -0400206 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 status = AE_OK;
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Len Brown4be44fc2005-08-05 00:44:28 -0400211 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 return (status);
213}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Bob Moore83135242006-10-03 00:00:00 -0400215ACPI_EXPORT_SYMBOL(acpi_get_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217/******************************************************************************
218 *
Bob Moore15b8dd52009-06-29 13:39:29 +0800219 * FUNCTION: acpi_ns_copy_device_id
220 *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000221 * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID
222 * source - Pointer to the source PNP_DEVICE_ID
Bob Moore15b8dd52009-06-29 13:39:29 +0800223 * string_area - Pointer to where to copy the dest string
224 *
225 * RETURN: Pointer to the next string area
226 *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000227 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
Bob Moore15b8dd52009-06-29 13:39:29 +0800228 *
229 ******************************************************************************/
Lv Zheng78e25fe2012-10-31 02:25:24 +0000230static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest,
231 struct acpi_pnp_device_id *source,
Bob Moore15b8dd52009-06-29 13:39:29 +0800232 char *string_area)
233{
Bob Moore413fc3f2012-10-31 02:28:38 +0000234
Lv Zheng78e25fe2012-10-31 02:25:24 +0000235 /* Create the destination PNP_DEVICE_ID */
Bob Moore15b8dd52009-06-29 13:39:29 +0800236
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 Torvalds1da177e2005-04-16 15:20:36 -0700248 * FUNCTION: acpi_get_object_info
249 *
Bob Mooreba494be2012-07-12 09:40:10 +0800250 * PARAMETERS: handle - Object Handle
Bob Moore15b8dd52009-06-29 13:39:29 +0800251 * return_buffer - Where the info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 *
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 Moore413fc3f2012-10-31 02:28:38 +0000259 * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
260 * _STA, _ADR, _sx_w, and _sx_d methods.
Bob Moore15b8dd52009-06-29 13:39:29 +0800261 *
262 * Note: Allocates the return buffer, must be freed by the caller.
263 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 ******************************************************************************/
Bob Moore15b8dd52009-06-29 13:39:29 +0800265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266acpi_status
Bob Moore15b8dd52009-06-29 13:39:29 +0800267acpi_get_object_info(acpi_handle handle,
268 struct acpi_device_info **return_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Len Brown4be44fc2005-08-05 00:44:28 -0400270 struct acpi_namespace_node *node;
271 struct acpi_device_info *info;
Lv Zheng78e25fe2012-10-31 02:25:24 +0000272 struct acpi_pnp_device_id_list *cid_list = NULL;
273 struct acpi_pnp_device_id *hid = NULL;
274 struct acpi_pnp_device_id *uid = NULL;
Bob Moore413fc3f2012-10-31 02:28:38 +0000275 struct acpi_pnp_device_id *sub = NULL;
Bob Moore15b8dd52009-06-29 13:39:29 +0800276 char *next_id_string;
277 acpi_object_type type;
278 acpi_name name;
279 u8 param_count = 0;
280 u8 valid = 0;
281 u32 info_size;
282 u32 i;
283 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 /* Parameter validation */
286
Bob Moore15b8dd52009-06-29 13:39:29 +0800287 if (!handle || !return_buffer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 return (AE_BAD_PARAMETER);
289 }
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
292 if (ACPI_FAILURE(status)) {
Bob Mooreef0b67f2012-12-19 05:38:36 +0000293 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295
Bob Mooref24b6642009-12-11 14:57:00 +0800296 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400298 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Bob Moore15b8dd52009-06-29 13:39:29 +0800299 return (AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301
Bob Moore15b8dd52009-06-29 13:39:29 +0800302 /* Get the namespace node data while the namespace is locked */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Bob Moore15b8dd52009-06-29 13:39:29 +0800304 info_size = sizeof(struct acpi_device_info);
305 type = node->type;
306 name = node->name.integer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Bob Moore0a1fbf22008-07-04 10:53:58 +0800308 if (node->type == ACPI_TYPE_METHOD) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800309 param_count = node->object->method.param_count;
Bob Moore0a1fbf22008-07-04 10:53:58 +0800310 }
311
Len Brown4be44fc2005-08-05 00:44:28 -0400312 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
313 if (ACPI_FAILURE(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800314 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
Bob Moore15b8dd52009-06-29 13:39:29 +0800317 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 /*
Bob Moore15b8dd52009-06-29 13:39:29 +0800319 * Get extra info for ACPI Device/Processor objects only:
Bob Moore413fc3f2012-10-31 02:28:38 +0000320 * Run the Device _HID, _UID, _SUB, and _CID methods.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 *
322 * Note: none of these methods are required, so they may or may
Bob Moore15b8dd52009-06-29 13:39:29 +0800323 * not be present for this device. The Info->Valid bitfield is used
324 * to indicate which methods were found and run successfully.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 */
326
327 /* Execute the Device._HID method */
328
Bob Moore15b8dd52009-06-29 13:39:29 +0800329 status = acpi_ut_execute_HID(node, &hid);
Len Brown4be44fc2005-08-05 00:44:28 -0400330 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800331 info_size += hid->length;
332 valid |= ACPI_VALID_HID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334
335 /* Execute the Device._UID method */
336
Bob Moore15b8dd52009-06-29 13:39:29 +0800337 status = acpi_ut_execute_UID(node, &uid);
Len Brown4be44fc2005-08-05 00:44:28 -0400338 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800339 info_size += uid->length;
340 valid |= ACPI_VALID_UID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
Bob Moore413fc3f2012-10-31 02:28:38 +0000343 /* Execute the Device._SUB method */
344
345 status = acpi_ut_execute_SUB(node, &sub);
346 if (ACPI_SUCCESS(status)) {
347 info_size += sub->length;
348 valid |= ACPI_VALID_SUB;
349 }
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 /* Execute the Device._CID method */
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 status = acpi_ut_execute_CID(node, &cid_list);
354 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800355
356 /* Add size of CID strings and CID pointer array */
357
358 info_size +=
359 (cid_list->list_size -
Lv Zheng78e25fe2012-10-31 02:25:24 +0000360 sizeof(struct acpi_pnp_device_id_list));
Bob Moore15b8dd52009-06-29 13:39:29 +0800361 valid |= ACPI_VALID_CID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
Bob Moore15b8dd52009-06-29 13:39:29 +0800363 }
364
365 /*
366 * Now that we have the variable-length data, we can allocate the
367 * return buffer
368 */
369 info = ACPI_ALLOCATE_ZEROED(info_size);
370 if (!info) {
371 status = AE_NO_MEMORY;
372 goto cleanup;
373 }
374
375 /* Get the fixed-length data */
376
377 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
378 /*
379 * Get extra info for ACPI Device/Processor objects only:
380 * Run the _STA, _ADR and, sx_w, and _sx_d methods.
381 *
382 * Note: none of these methods are required, so they may or may
383 * not be present for this device. The Info->Valid bitfield is used
384 * to indicate which methods were found and run successfully.
385 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 /* Execute the Device._STA method */
388
Len Brown4be44fc2005-08-05 00:44:28 -0400389 status = acpi_ut_execute_STA(node, &info->current_status);
390 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800391 valid |= ACPI_VALID_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
393
394 /* Execute the Device._ADR method */
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
397 &info->address);
398 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800399 valid |= ACPI_VALID_ADR;
400 }
401
402 /* Execute the Device._sx_w methods */
403
404 status = acpi_ut_execute_power_methods(node,
405 acpi_gbl_lowest_dstate_names,
406 ACPI_NUM_sx_w_METHODS,
407 info->lowest_dstates);
408 if (ACPI_SUCCESS(status)) {
409 valid |= ACPI_VALID_SXWS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411
412 /* Execute the Device._sx_d methods */
413
Bob Moore15b8dd52009-06-29 13:39:29 +0800414 status = acpi_ut_execute_power_methods(node,
415 acpi_gbl_highest_dstate_names,
416 ACPI_NUM_sx_d_METHODS,
417 info->highest_dstates);
Len Brown4be44fc2005-08-05 00:44:28 -0400418 if (ACPI_SUCCESS(status)) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800419 valid |= ACPI_VALID_SXDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
421 }
422
Bob Moore15b8dd52009-06-29 13:39:29 +0800423 /*
424 * Create a pointer to the string area of the return buffer.
425 * Point to the end of the base struct acpi_device_info structure.
426 */
427 next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids);
428 if (cid_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Lv Zheng78e25fe2012-10-31 02:25:24 +0000430 /* Point past the CID PNP_DEVICE_ID array */
Bob Moore15b8dd52009-06-29 13:39:29 +0800431
432 next_id_string +=
433 ((acpi_size) cid_list->count *
Lv Zheng78e25fe2012-10-31 02:25:24 +0000434 sizeof(struct acpi_pnp_device_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
436
Bob Moore15b8dd52009-06-29 13:39:29 +0800437 /*
Bob Moore413fc3f2012-10-31 02:28:38 +0000438 * Copy the HID, UID, SUB, and CIDs to the return buffer.
439 * The variable-length strings are copied to the reserved area
440 * at the end of the buffer.
Bob Moore15b8dd52009-06-29 13:39:29 +0800441 *
442 * For HID and CID, check if the ID is a PCI Root Bridge.
443 */
444 if (hid) {
445 next_id_string = acpi_ns_copy_device_id(&info->hardware_id,
446 hid, next_id_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Bob Moore15b8dd52009-06-29 13:39:29 +0800448 if (acpi_ut_is_pci_root_bridge(hid->string)) {
449 info->flags |= ACPI_PCI_ROOT_BRIDGE;
450 }
451 }
452
453 if (uid) {
454 next_id_string = acpi_ns_copy_device_id(&info->unique_id,
455 uid, next_id_string);
456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Bob Moore413fc3f2012-10-31 02:28:38 +0000458 if (sub) {
459 next_id_string = acpi_ns_copy_device_id(&info->subsystem_id,
460 sub, next_id_string);
461 }
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (cid_list) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800464 info->compatible_id_list.count = cid_list->count;
465 info->compatible_id_list.list_size = cid_list->list_size;
466
467 /* Copy each CID */
468
469 for (i = 0; i < cid_list->count; i++) {
470 next_id_string =
471 acpi_ns_copy_device_id(&info->compatible_id_list.
472 ids[i], &cid_list->ids[i],
473 next_id_string);
474
475 if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) {
476 info->flags |= ACPI_PCI_ROOT_BRIDGE;
477 }
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480
Bob Moore15b8dd52009-06-29 13:39:29 +0800481 /* Copy the fixed-length data */
482
483 info->info_size = info_size;
484 info->type = type;
485 info->name = name;
486 info->param_count = param_count;
487 info->valid = valid;
488
489 *return_buffer = info;
490 status = AE_OK;
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492 cleanup:
Bob Moore15b8dd52009-06-29 13:39:29 +0800493 if (hid) {
494 ACPI_FREE(hid);
495 }
496 if (uid) {
497 ACPI_FREE(uid);
498 }
Bob Moore413fc3f2012-10-31 02:28:38 +0000499 if (sub) {
500 ACPI_FREE(sub);
501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (cid_list) {
Bob Moore83135242006-10-03 00:00:00 -0400503 ACPI_FREE(cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505 return (status);
506}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Bob Moore83135242006-10-03 00:00:00 -0400508ACPI_EXPORT_SYMBOL(acpi_get_object_info)
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800509
510/******************************************************************************
511 *
512 * FUNCTION: acpi_install_method
513 *
Bob Mooreba494be2012-07-12 09:40:10 +0800514 * PARAMETERS: buffer - An ACPI table containing one control method
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800515 *
516 * RETURN: Status
517 *
518 * DESCRIPTION: Install a control method into the namespace. If the method
519 * name already exists in the namespace, it is overwritten. The
520 * input buffer must contain a valid DSDT or SSDT containing a
521 * single control method.
522 *
523 ******************************************************************************/
524acpi_status acpi_install_method(u8 *buffer)
525{
526 struct acpi_table_header *table =
527 ACPI_CAST_PTR(struct acpi_table_header, buffer);
528 u8 *aml_buffer;
529 u8 *aml_start;
530 char *path;
531 struct acpi_namespace_node *node;
532 union acpi_operand_object *method_obj;
533 struct acpi_parse_state parser_state;
534 u32 aml_length;
535 u16 opcode;
536 u8 method_flags;
537 acpi_status status;
538
539 /* Parameter validation */
540
541 if (!buffer) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000542 return (AE_BAD_PARAMETER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800543 }
544
545 /* Table must be a DSDT or SSDT */
546
547 if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) &&
548 !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000549 return (AE_BAD_HEADER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800550 }
551
552 /* First AML opcode in the table must be a control method */
553
554 parser_state.aml = buffer + sizeof(struct acpi_table_header);
555 opcode = acpi_ps_peek_opcode(&parser_state);
556 if (opcode != AML_METHOD_OP) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000557 return (AE_BAD_PARAMETER);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800558 }
559
560 /* Extract method information from the raw AML */
561
562 parser_state.aml += acpi_ps_get_opcode_size(opcode);
563 parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state);
564 path = acpi_ps_get_next_namestring(&parser_state);
565 method_flags = *parser_state.aml++;
566 aml_start = parser_state.aml;
567 aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);
568
569 /*
570 * Allocate resources up-front. We don't want to have to delete a new
571 * node from the namespace if we cannot allocate memory.
572 */
573 aml_buffer = ACPI_ALLOCATE(aml_length);
574 if (!aml_buffer) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000575 return (AE_NO_MEMORY);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800576 }
577
578 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
579 if (!method_obj) {
580 ACPI_FREE(aml_buffer);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000581 return (AE_NO_MEMORY);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800582 }
583
584 /* Lock namespace for acpi_ns_lookup, we may be creating a new node */
585
586 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
587 if (ACPI_FAILURE(status)) {
588 goto error_exit;
589 }
590
591 /* The lookup either returns an existing node or creates a new one */
592
593 status =
594 acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
595 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
596 NULL, &node);
597
598 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
599
600 if (ACPI_FAILURE(status)) { /* ns_lookup */
601 if (status != AE_ALREADY_EXISTS) {
602 goto error_exit;
603 }
604
605 /* Node existed previously, make sure it is a method node */
606
607 if (node->type != ACPI_TYPE_METHOD) {
608 status = AE_TYPE;
609 goto error_exit;
610 }
611 }
612
613 /* Copy the method AML to the local buffer */
614
615 ACPI_MEMCPY(aml_buffer, aml_start, aml_length);
616
617 /* Initialize the method object with the new method's information */
618
619 method_obj->method.aml_start = aml_buffer;
620 method_obj->method.aml_length = aml_length;
621
622 method_obj->method.param_count = (u8)
623 (method_flags & AML_METHOD_ARG_COUNT);
624
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800625 if (method_flags & AML_METHOD_SERIALIZED) {
Lin Ming26294842011-01-12 09:19:43 +0800626 method_obj->method.info_flags = ACPI_METHOD_SERIALIZED;
627
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800628 method_obj->method.sync_level = (u8)
629 ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
630 }
631
632 /*
633 * Now that it is complete, we can attach the new method object to
634 * the method Node (detaches/deletes any existing object)
635 */
636 status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD);
637
638 /*
639 * Flag indicates AML buffer is dynamic, must be deleted later.
640 * Must be set only after attach above.
641 */
642 node->flags |= ANOBJ_ALLOCATED_BUFFER;
643
644 /* Remove local reference to the method object */
645
646 acpi_ut_remove_reference(method_obj);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000647 return (status);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800648
649error_exit:
650
651 ACPI_FREE(aml_buffer);
652 ACPI_FREE(method_obj);
Lv Zheng9c0d7932012-12-19 05:37:21 +0000653 return (status);
Lin Mingb2f7ddc2009-05-21 10:42:09 +0800654}
655ACPI_EXPORT_SYMBOL(acpi_install_method)