ACPICA: Clarify ACPI_FREE_BUFFER usage.
[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/*
25f044e6 9 * Copyright (C) 2000 - 2013, 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
117 if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
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;
bbe707ed 162 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
175 if (name_type == ACPI_FULL_PATHNAME) {
52fc0b02 176
1da177e4
LT
177 /* Get the full pathname (From the namespace root) */
178
4be44fcd 179 status = acpi_ns_handle_to_pathname(handle, buffer);
1da177e4
LT
180 return (status);
181 }
182
183 /*
184 * Wants the single segment ACPI name.
185 * Validate handle and convert to a namespace Node
186 */
4be44fcd
LB
187 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
188 if (ACPI_FAILURE(status)) {
1da177e4
LT
189 return (status);
190 }
191
f24b664d 192 node = acpi_ns_validate_handle(handle);
1da177e4
LT
193 if (!node) {
194 status = AE_BAD_PARAMETER;
195 goto unlock_and_exit;
196 }
197
198 /* Validate/Allocate/Clear caller buffer */
199
4be44fcd
LB
200 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
201 if (ACPI_FAILURE(status)) {
1da177e4
LT
202 goto unlock_and_exit;
203 }
204
205 /* Just copy the ACPI name from the Node and zero terminate it */
206
bbe707ed
JK
207 node_name = acpi_ut_get_node_name(node);
208 ACPI_MOVE_NAME(buffer->pointer, node_name);
4be44fcd 209 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
1da177e4
LT
210 status = AE_OK;
211
4be44fcd 212 unlock_and_exit:
1da177e4 213
4be44fcd 214 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
215 return (status);
216}
1da177e4 217
8313524a 218ACPI_EXPORT_SYMBOL(acpi_get_name)
1da177e4 219
15b8dd53
BM
220/******************************************************************************
221 *
222 * FUNCTION: acpi_ns_copy_device_id
223 *
78e25fef
LZ
224 * PARAMETERS: dest - Pointer to the destination PNP_DEVICE_ID
225 * source - Pointer to the source PNP_DEVICE_ID
15b8dd53
BM
226 * string_area - Pointer to where to copy the dest string
227 *
228 * RETURN: Pointer to the next string area
229 *
78e25fef 230 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
15b8dd53
BM
231 *
232 ******************************************************************************/
78e25fef
LZ
233static char *acpi_ns_copy_device_id(struct acpi_pnp_device_id *dest,
234 struct acpi_pnp_device_id *source,
15b8dd53
BM
235 char *string_area)
236{
413fc3f5 237
78e25fef 238 /* Create the destination PNP_DEVICE_ID */
15b8dd53
BM
239
240 dest->string = string_area;
241 dest->length = source->length;
242
243 /* Copy actual string and return a pointer to the next string area */
244
245 ACPI_MEMCPY(string_area, source->string, source->length);
246 return (string_area + source->length);
247}
248
1da177e4
LT
249/******************************************************************************
250 *
251 * FUNCTION: acpi_get_object_info
252 *
ba494bee 253 * PARAMETERS: handle - Object Handle
15b8dd53 254 * return_buffer - Where the info is returned
1da177e4
LT
255 *
256 * RETURN: Status
257 *
258 * DESCRIPTION: Returns information about an object as gleaned from the
259 * namespace node and possibly by running several standard
260 * control methods (Such as in the case of a device.)
261 *
413fc3f5
BM
262 * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
263 * _STA, _ADR, _sx_w, and _sx_d methods.
15b8dd53
BM
264 *
265 * Note: Allocates the return buffer, must be freed by the caller.
266 *
1da177e4 267 ******************************************************************************/
15b8dd53 268
1da177e4 269acpi_status
15b8dd53
BM
270acpi_get_object_info(acpi_handle handle,
271 struct acpi_device_info **return_buffer)
1da177e4 272{
4be44fcd
LB
273 struct acpi_namespace_node *node;
274 struct acpi_device_info *info;
78e25fef
LZ
275 struct acpi_pnp_device_id_list *cid_list = NULL;
276 struct acpi_pnp_device_id *hid = NULL;
277 struct acpi_pnp_device_id *uid = NULL;
413fc3f5 278 struct acpi_pnp_device_id *sub = NULL;
15b8dd53
BM
279 char *next_id_string;
280 acpi_object_type type;
281 acpi_name name;
282 u8 param_count = 0;
283 u8 valid = 0;
284 u32 info_size;
285 u32 i;
286 acpi_status status;
1da177e4
LT
287
288 /* Parameter validation */
289
15b8dd53 290 if (!handle || !return_buffer) {
1da177e4
LT
291 return (AE_BAD_PARAMETER);
292 }
293
4be44fcd
LB
294 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
295 if (ACPI_FAILURE(status)) {
ef0b67fe 296 return (status);
1da177e4
LT
297 }
298
f24b664d 299 node = acpi_ns_validate_handle(handle);
1da177e4 300 if (!node) {
4be44fcd 301 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
15b8dd53 302 return (AE_BAD_PARAMETER);
1da177e4
LT
303 }
304
15b8dd53 305 /* Get the namespace node data while the namespace is locked */
1da177e4 306
15b8dd53
BM
307 info_size = sizeof(struct acpi_device_info);
308 type = node->type;
309 name = node->name.integer;
1da177e4 310
0a1fbf2d 311 if (node->type == ACPI_TYPE_METHOD) {
15b8dd53 312 param_count = node->object->method.param_count;
0a1fbf2d
BM
313 }
314
4be44fcd
LB
315 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
316 if (ACPI_FAILURE(status)) {
15b8dd53 317 return (status);
1da177e4
LT
318 }
319
15b8dd53 320 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
1da177e4 321 /*
15b8dd53 322 * Get extra info for ACPI Device/Processor objects only:
413fc3f5 323 * Run the Device _HID, _UID, _SUB, and _CID methods.
1da177e4
LT
324 *
325 * Note: none of these methods are required, so they may or may
15b8dd53
BM
326 * not be present for this device. The Info->Valid bitfield is used
327 * to indicate which methods were found and run successfully.
1da177e4
LT
328 */
329
330 /* Execute the Device._HID method */
331
15b8dd53 332 status = acpi_ut_execute_HID(node, &hid);
4be44fcd 333 if (ACPI_SUCCESS(status)) {
15b8dd53
BM
334 info_size += hid->length;
335 valid |= ACPI_VALID_HID;
1da177e4
LT
336 }
337
338 /* Execute the Device._UID method */
339
15b8dd53 340 status = acpi_ut_execute_UID(node, &uid);
4be44fcd 341 if (ACPI_SUCCESS(status)) {
15b8dd53
BM
342 info_size += uid->length;
343 valid |= ACPI_VALID_UID;
1da177e4
LT
344 }
345
413fc3f5
BM
346 /* Execute the Device._SUB method */
347
348 status = acpi_ut_execute_SUB(node, &sub);
349 if (ACPI_SUCCESS(status)) {
350 info_size += sub->length;
351 valid |= ACPI_VALID_SUB;
352 }
353
1da177e4
LT
354 /* Execute the Device._CID method */
355
4be44fcd
LB
356 status = acpi_ut_execute_CID(node, &cid_list);
357 if (ACPI_SUCCESS(status)) {
15b8dd53
BM
358
359 /* Add size of CID strings and CID pointer array */
360
361 info_size +=
362 (cid_list->list_size -
78e25fef 363 sizeof(struct acpi_pnp_device_id_list));
15b8dd53 364 valid |= ACPI_VALID_CID;
1da177e4 365 }
15b8dd53
BM
366 }
367
368 /*
369 * Now that we have the variable-length data, we can allocate the
370 * return buffer
371 */
372 info = ACPI_ALLOCATE_ZEROED(info_size);
373 if (!info) {
374 status = AE_NO_MEMORY;
375 goto cleanup;
376 }
377
378 /* Get the fixed-length data */
379
380 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
381 /*
382 * Get extra info for ACPI Device/Processor objects only:
383 * Run the _STA, _ADR and, sx_w, and _sx_d methods.
384 *
a7d5caf6 385 * Notes: none of these methods are required, so they may or may
15b8dd53
BM
386 * not be present for this device. The Info->Valid bitfield is used
387 * to indicate which methods were found and run successfully.
a7d5caf6
BM
388 *
389 * For _STA, if the method does not exist, then (as per the ACPI
390 * specification), the returned current_status flags will indicate
391 * that the device is present/functional/enabled. Otherwise, the
392 * current_status flags reflect the value returned from _STA.
15b8dd53 393 */
1da177e4
LT
394
395 /* Execute the Device._STA method */
396
4be44fcd
LB
397 status = acpi_ut_execute_STA(node, &info->current_status);
398 if (ACPI_SUCCESS(status)) {
15b8dd53 399 valid |= ACPI_VALID_STA;
1da177e4
LT
400 }
401
402 /* Execute the Device._ADR method */
403
4be44fcd
LB
404 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
405 &info->address);
406 if (ACPI_SUCCESS(status)) {
15b8dd53
BM
407 valid |= ACPI_VALID_ADR;
408 }
409
410 /* Execute the Device._sx_w methods */
411
412 status = acpi_ut_execute_power_methods(node,
413 acpi_gbl_lowest_dstate_names,
414 ACPI_NUM_sx_w_METHODS,
415 info->lowest_dstates);
416 if (ACPI_SUCCESS(status)) {
417 valid |= ACPI_VALID_SXWS;
1da177e4
LT
418 }
419
420 /* Execute the Device._sx_d methods */
421
15b8dd53
BM
422 status = acpi_ut_execute_power_methods(node,
423 acpi_gbl_highest_dstate_names,
424 ACPI_NUM_sx_d_METHODS,
425 info->highest_dstates);
4be44fcd 426 if (ACPI_SUCCESS(status)) {
15b8dd53 427 valid |= ACPI_VALID_SXDS;
1da177e4
LT
428 }
429 }
430
15b8dd53
BM
431 /*
432 * Create a pointer to the string area of the return buffer.
433 * Point to the end of the base struct acpi_device_info structure.
434 */
435 next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids);
436 if (cid_list) {
1da177e4 437
78e25fef 438 /* Point past the CID PNP_DEVICE_ID array */
15b8dd53
BM
439
440 next_id_string +=
441 ((acpi_size) cid_list->count *
78e25fef 442 sizeof(struct acpi_pnp_device_id));
1da177e4
LT
443 }
444
15b8dd53 445 /*
413fc3f5
BM
446 * Copy the HID, UID, SUB, and CIDs to the return buffer.
447 * The variable-length strings are copied to the reserved area
448 * at the end of the buffer.
15b8dd53
BM
449 *
450 * For HID and CID, check if the ID is a PCI Root Bridge.
451 */
452 if (hid) {
453 next_id_string = acpi_ns_copy_device_id(&info->hardware_id,
454 hid, next_id_string);
455
456 if (acpi_ut_is_pci_root_bridge(hid->string)) {
457 info->flags |= ACPI_PCI_ROOT_BRIDGE;
458 }
459 }
1da177e4 460
15b8dd53
BM
461 if (uid) {
462 next_id_string = acpi_ns_copy_device_id(&info->unique_id,
463 uid, next_id_string);
464 }
1da177e4 465
413fc3f5
BM
466 if (sub) {
467 next_id_string = acpi_ns_copy_device_id(&info->subsystem_id,
468 sub, next_id_string);
469 }
470
1da177e4 471 if (cid_list) {
15b8dd53
BM
472 info->compatible_id_list.count = cid_list->count;
473 info->compatible_id_list.list_size = cid_list->list_size;
474
475 /* Copy each CID */
476
477 for (i = 0; i < cid_list->count; i++) {
478 next_id_string =
479 acpi_ns_copy_device_id(&info->compatible_id_list.
480 ids[i], &cid_list->ids[i],
481 next_id_string);
482
483 if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) {
484 info->flags |= ACPI_PCI_ROOT_BRIDGE;
485 }
486 }
1da177e4
LT
487 }
488
15b8dd53
BM
489 /* Copy the fixed-length data */
490
491 info->info_size = info_size;
492 info->type = type;
493 info->name = name;
494 info->param_count = param_count;
495 info->valid = valid;
496
497 *return_buffer = info;
498 status = AE_OK;
499
4be44fcd 500 cleanup:
15b8dd53
BM
501 if (hid) {
502 ACPI_FREE(hid);
503 }
504 if (uid) {
505 ACPI_FREE(uid);
506 }
413fc3f5
BM
507 if (sub) {
508 ACPI_FREE(sub);
509 }
1da177e4 510 if (cid_list) {
8313524a 511 ACPI_FREE(cid_list);
1da177e4
LT
512 }
513 return (status);
514}
1da177e4 515
8313524a 516ACPI_EXPORT_SYMBOL(acpi_get_object_info)
b2f7ddcf
LM
517
518/******************************************************************************
519 *
520 * FUNCTION: acpi_install_method
521 *
ba494bee 522 * PARAMETERS: buffer - An ACPI table containing one control method
b2f7ddcf
LM
523 *
524 * RETURN: Status
525 *
526 * DESCRIPTION: Install a control method into the namespace. If the method
527 * name already exists in the namespace, it is overwritten. The
528 * input buffer must contain a valid DSDT or SSDT containing a
529 * single control method.
530 *
531 ******************************************************************************/
532acpi_status acpi_install_method(u8 *buffer)
533{
534 struct acpi_table_header *table =
535 ACPI_CAST_PTR(struct acpi_table_header, buffer);
536 u8 *aml_buffer;
537 u8 *aml_start;
538 char *path;
539 struct acpi_namespace_node *node;
540 union acpi_operand_object *method_obj;
541 struct acpi_parse_state parser_state;
542 u32 aml_length;
543 u16 opcode;
544 u8 method_flags;
545 acpi_status status;
546
547 /* Parameter validation */
548
549 if (!buffer) {
9c0d7939 550 return (AE_BAD_PARAMETER);
b2f7ddcf
LM
551 }
552
553 /* Table must be a DSDT or SSDT */
554
555 if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) &&
556 !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
9c0d7939 557 return (AE_BAD_HEADER);
b2f7ddcf
LM
558 }
559
560 /* First AML opcode in the table must be a control method */
561
562 parser_state.aml = buffer + sizeof(struct acpi_table_header);
563 opcode = acpi_ps_peek_opcode(&parser_state);
564 if (opcode != AML_METHOD_OP) {
9c0d7939 565 return (AE_BAD_PARAMETER);
b2f7ddcf
LM
566 }
567
568 /* Extract method information from the raw AML */
569
570 parser_state.aml += acpi_ps_get_opcode_size(opcode);
571 parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state);
572 path = acpi_ps_get_next_namestring(&parser_state);
573 method_flags = *parser_state.aml++;
574 aml_start = parser_state.aml;
575 aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);
576
577 /*
578 * Allocate resources up-front. We don't want to have to delete a new
579 * node from the namespace if we cannot allocate memory.
580 */
581 aml_buffer = ACPI_ALLOCATE(aml_length);
582 if (!aml_buffer) {
9c0d7939 583 return (AE_NO_MEMORY);
b2f7ddcf
LM
584 }
585
586 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
587 if (!method_obj) {
588 ACPI_FREE(aml_buffer);
9c0d7939 589 return (AE_NO_MEMORY);
b2f7ddcf
LM
590 }
591
592 /* Lock namespace for acpi_ns_lookup, we may be creating a new node */
593
594 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
595 if (ACPI_FAILURE(status)) {
596 goto error_exit;
597 }
598
599 /* The lookup either returns an existing node or creates a new one */
600
601 status =
602 acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
603 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
604 NULL, &node);
605
606 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
607
608 if (ACPI_FAILURE(status)) { /* ns_lookup */
609 if (status != AE_ALREADY_EXISTS) {
610 goto error_exit;
611 }
612
613 /* Node existed previously, make sure it is a method node */
614
615 if (node->type != ACPI_TYPE_METHOD) {
616 status = AE_TYPE;
617 goto error_exit;
618 }
619 }
620
621 /* Copy the method AML to the local buffer */
622
623 ACPI_MEMCPY(aml_buffer, aml_start, aml_length);
624
625 /* Initialize the method object with the new method's information */
626
627 method_obj->method.aml_start = aml_buffer;
628 method_obj->method.aml_length = aml_length;
629
630 method_obj->method.param_count = (u8)
631 (method_flags & AML_METHOD_ARG_COUNT);
632
b2f7ddcf 633 if (method_flags & AML_METHOD_SERIALIZED) {
26294842
LM
634 method_obj->method.info_flags = ACPI_METHOD_SERIALIZED;
635
b2f7ddcf
LM
636 method_obj->method.sync_level = (u8)
637 ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
638 }
639
640 /*
641 * Now that it is complete, we can attach the new method object to
642 * the method Node (detaches/deletes any existing object)
643 */
644 status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD);
645
646 /*
647 * Flag indicates AML buffer is dynamic, must be deleted later.
648 * Must be set only after attach above.
649 */
650 node->flags |= ANOBJ_ALLOCATED_BUFFER;
651
652 /* Remove local reference to the method object */
653
654 acpi_ut_remove_reference(method_obj);
9c0d7939 655 return (status);
b2f7ddcf
LM
656
657error_exit:
658
659 ACPI_FREE(aml_buffer);
660 ACPI_FREE(method_obj);
9c0d7939 661 return (status);
b2f7ddcf
LM
662}
663ACPI_EXPORT_SYMBOL(acpi_install_method)
This page took 0.638967 seconds and 5 git commands to generate.