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