nsxfname.c 17.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8
/******************************************************************************
 *
 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
 *                         ACPI Namespace oriented interfaces
 *
 *****************************************************************************/

/*
L
Len Brown 已提交
9
 * Copyright (C) 2000 - 2008, Intel Corp.
L
Linus Torvalds 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
L
Len Brown 已提交
46 47
#include "accommon.h"
#include "acnamesp.h"
48 49
#include "acparser.h"
#include "amlcode.h"
L
Linus Torvalds 已提交
50 51

#define _COMPONENT          ACPI_NAMESPACE
L
Len Brown 已提交
52
ACPI_MODULE_NAME("nsxfname")
L
Linus Torvalds 已提交
53

54 55 56 57 58
/* Local prototypes */
static char *acpi_ns_copy_device_id(struct acpica_device_id *dest,
				    struct acpica_device_id *source,
				    char *string_area);

L
Linus Torvalds 已提交
59 60 61 62 63
/******************************************************************************
 *
 * FUNCTION:    acpi_get_handle
 *
 * PARAMETERS:  Parent          - Object to search under (search scope).
R
Robert Moore 已提交
64 65 66
 *              Pathname        - Pointer to an asciiz string containing the
 *                                name
 *              ret_handle      - Where the return handle is returned
L
Linus Torvalds 已提交
67 68 69 70 71 72 73 74 75
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This routine will search for a caller specified name in the
 *              name space.  The caller can restrict the search region by
 *              specifying a non NULL parent.  The parent value is itself a
 *              namespace handle.
 *
 ******************************************************************************/
76

L
Linus Torvalds 已提交
77
acpi_status
L
Len Brown 已提交
78 79
acpi_get_handle(acpi_handle parent,
		acpi_string pathname, acpi_handle * ret_handle)
L
Linus Torvalds 已提交
80
{
L
Len Brown 已提交
81 82 83
	acpi_status status;
	struct acpi_namespace_node *node = NULL;
	struct acpi_namespace_node *prefix_node = NULL;
L
Linus Torvalds 已提交
84

L
Len Brown 已提交
85
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
86 87 88 89 90 91 92 93 94 95

	/* Parameter Validation */

	if (!ret_handle || !pathname) {
		return (AE_BAD_PARAMETER);
	}

	/* Convert a parent handle to a prefix node */

	if (parent) {
96
		prefix_node = acpi_ns_validate_handle(parent);
L
Linus Torvalds 已提交
97 98 99
		if (!prefix_node) {
			return (AE_BAD_PARAMETER);
		}
100 101 102 103 104 105 106 107 108 109
	}

	/*
	 * Valid cases are:
	 * 1) Fully qualified pathname
	 * 2) Parent + Relative pathname
	 *
	 * Error for <null Parent + relative path>
	 */
	if (acpi_ns_valid_root_prefix(pathname[0])) {
L
Linus Torvalds 已提交
110

111 112 113 114 115 116
		/* Pathname is fully qualified (starts with '\') */

		/* Special case for root-only, since we can't search for it */

		if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
			*ret_handle =
117
			    ACPI_CAST_PTR(acpi_handle, acpi_gbl_root_node);
118
			return (AE_OK);
L
Linus Torvalds 已提交
119
		}
120
	} else if (!prefix_node) {
L
Linus Torvalds 已提交
121

122
		/* Relative path with null prefix is disallowed */
L
Linus Torvalds 已提交
123

124
		return (AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
125 126
	}

127
	/* Find the Node and convert to a handle */
L
Linus Torvalds 已提交
128

129 130
	status =
	    acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
L
Len Brown 已提交
131
	if (ACPI_SUCCESS(status)) {
132
		*ret_handle = ACPI_CAST_PTR(acpi_handle, node);
L
Linus Torvalds 已提交
133 134 135 136 137
	}

	return (status);
}

B
Bob Moore 已提交
138
ACPI_EXPORT_SYMBOL(acpi_get_handle)
L
Linus Torvalds 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

/******************************************************************************
 *
 * FUNCTION:    acpi_get_name
 *
 * PARAMETERS:  Handle          - Handle to be converted to a pathname
 *              name_type       - Full pathname or single segment
 *              Buffer          - Buffer for returned path
 *
 * RETURN:      Pointer to a string containing the fully qualified Name.
 *
 * DESCRIPTION: This routine returns the fully qualified name associated with
 *              the Handle parameter.  This and the acpi_pathname_to_handle are
 *              complementary functions.
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
156
acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
L
Linus Torvalds 已提交
157
{
L
Len Brown 已提交
158 159
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
160 161 162 163 164 165 166

	/* Parameter validation */

	if (name_type > ACPI_NAME_TYPE_MAX) {
		return (AE_BAD_PARAMETER);
	}

L
Len Brown 已提交
167 168
	status = acpi_ut_validate_buffer(buffer);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
169 170 171 172
		return (status);
	}

	if (name_type == ACPI_FULL_PATHNAME) {
B
Bob Moore 已提交
173

L
Linus Torvalds 已提交
174 175
		/* Get the full pathname (From the namespace root) */

L
Len Brown 已提交
176
		status = acpi_ns_handle_to_pathname(handle, buffer);
L
Linus Torvalds 已提交
177 178 179 180 181 182 183
		return (status);
	}

	/*
	 * Wants the single segment ACPI name.
	 * Validate handle and convert to a namespace Node
	 */
L
Len Brown 已提交
184 185
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
186 187 188
		return (status);
	}

189
	node = acpi_ns_validate_handle(handle);
L
Linus Torvalds 已提交
190 191 192 193 194 195 196
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Validate/Allocate/Clear caller buffer */

L
Len Brown 已提交
197 198
	status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
199 200 201 202 203
		goto unlock_and_exit;
	}

	/* Just copy the ACPI name from the Node and zero terminate it */

L
Len Brown 已提交
204 205 206
	ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
		     ACPI_NAME_SIZE);
	((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
L
Linus Torvalds 已提交
207 208
	status = AE_OK;

L
Len Brown 已提交
209
      unlock_and_exit:
L
Linus Torvalds 已提交
210

L
Len Brown 已提交
211
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
L
Linus Torvalds 已提交
212 213 214
	return (status);
}

B
Bob Moore 已提交
215
ACPI_EXPORT_SYMBOL(acpi_get_name)
L
Linus Torvalds 已提交
216

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
/******************************************************************************
 *
 * FUNCTION:    acpi_ns_copy_device_id
 *
 * PARAMETERS:  Dest                - Pointer to the destination DEVICE_ID
 *              Source              - Pointer to the source DEVICE_ID
 *              string_area         - Pointer to where to copy the dest string
 *
 * RETURN:      Pointer to the next string area
 *
 * DESCRIPTION: Copy a single DEVICE_ID, including the string data.
 *
 ******************************************************************************/
static char *acpi_ns_copy_device_id(struct acpica_device_id *dest,
				    struct acpica_device_id *source,
				    char *string_area)
{
	/* Create the destination DEVICE_ID */

	dest->string = string_area;
	dest->length = source->length;

	/* Copy actual string and return a pointer to the next string area */

	ACPI_MEMCPY(string_area, source->string, source->length);
	return (string_area + source->length);
}

L
Linus Torvalds 已提交
245 246 247 248
/******************************************************************************
 *
 * FUNCTION:    acpi_get_object_info
 *
249 250
 * PARAMETERS:  Handle              - Object Handle
 *              return_buffer       - Where the info is returned
L
Linus Torvalds 已提交
251 252 253 254 255 256 257
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Returns information about an object as gleaned from the
 *              namespace node and possibly by running several standard
 *              control methods (Such as in the case of a device.)
 *
258 259 260 261 262
 * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
 * _ADR, _sx_w, and _sx_d methods.
 *
 * Note: Allocates the return buffer, must be freed by the caller.
 *
L
Linus Torvalds 已提交
263
 ******************************************************************************/
264

L
Linus Torvalds 已提交
265
acpi_status
266 267
acpi_get_object_info(acpi_handle handle,
		     struct acpi_device_info **return_buffer)
L
Linus Torvalds 已提交
268
{
L
Len Brown 已提交
269 270
	struct acpi_namespace_node *node;
	struct acpi_device_info *info;
271 272 273 274 275 276 277 278 279 280 281
	struct acpica_device_id_list *cid_list = NULL;
	struct acpica_device_id *hid = NULL;
	struct acpica_device_id *uid = NULL;
	char *next_id_string;
	acpi_object_type type;
	acpi_name name;
	u8 param_count = 0;
	u8 valid = 0;
	u32 info_size;
	u32 i;
	acpi_status status;
L
Linus Torvalds 已提交
282 283 284

	/* Parameter validation */

285
	if (!handle || !return_buffer) {
L
Linus Torvalds 已提交
286 287 288
		return (AE_BAD_PARAMETER);
	}

L
Len Brown 已提交
289 290
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
291 292 293
		goto cleanup;
	}

294
	node = acpi_ns_validate_handle(handle);
L
Linus Torvalds 已提交
295
	if (!node) {
L
Len Brown 已提交
296
		(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
297
		return (AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
298 299
	}

300
	/* Get the namespace node data while the namespace is locked */
L
Linus Torvalds 已提交
301

302 303 304
	info_size = sizeof(struct acpi_device_info);
	type = node->type;
	name = node->name.integer;
L
Linus Torvalds 已提交
305

306
	if (node->type == ACPI_TYPE_METHOD) {
307
		param_count = node->object->method.param_count;
308 309
	}

L
Len Brown 已提交
310 311
	status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
312
		return (status);
L
Linus Torvalds 已提交
313 314
	}

315
	if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
L
Linus Torvalds 已提交
316
		/*
317 318
		 * Get extra info for ACPI Device/Processor objects only:
		 * Run the Device _HID, _UID, and _CID methods.
L
Linus Torvalds 已提交
319 320
		 *
		 * Note: none of these methods are required, so they may or may
321 322
		 * not be present for this device. The Info->Valid bitfield is used
		 * to indicate which methods were found and run successfully.
L
Linus Torvalds 已提交
323 324 325 326
		 */

		/* Execute the Device._HID method */

327
		status = acpi_ut_execute_HID(node, &hid);
L
Len Brown 已提交
328
		if (ACPI_SUCCESS(status)) {
329 330
			info_size += hid->length;
			valid |= ACPI_VALID_HID;
L
Linus Torvalds 已提交
331 332 333 334
		}

		/* Execute the Device._UID method */

335
		status = acpi_ut_execute_UID(node, &uid);
L
Len Brown 已提交
336
		if (ACPI_SUCCESS(status)) {
337 338
			info_size += uid->length;
			valid |= ACPI_VALID_UID;
L
Linus Torvalds 已提交
339 340 341 342
		}

		/* Execute the Device._CID method */

L
Len Brown 已提交
343 344
		status = acpi_ut_execute_CID(node, &cid_list);
		if (ACPI_SUCCESS(status)) {
345 346 347 348 349 350 351

			/* Add size of CID strings and CID pointer array */

			info_size +=
			    (cid_list->list_size -
			     sizeof(struct acpica_device_id_list));
			valid |= ACPI_VALID_CID;
L
Linus Torvalds 已提交
352
		}
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
	}

	/*
	 * Now that we have the variable-length data, we can allocate the
	 * return buffer
	 */
	info = ACPI_ALLOCATE_ZEROED(info_size);
	if (!info) {
		status = AE_NO_MEMORY;
		goto cleanup;
	}

	/* Get the fixed-length data */

	if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
		/*
		 * Get extra info for ACPI Device/Processor objects only:
		 * Run the _STA, _ADR and, sx_w, and _sx_d methods.
		 *
		 * Note: none of these methods are required, so they may or may
		 * not be present for this device. The Info->Valid bitfield is used
		 * to indicate which methods were found and run successfully.
		 */
L
Linus Torvalds 已提交
376 377 378

		/* Execute the Device._STA method */

L
Len Brown 已提交
379 380
		status = acpi_ut_execute_STA(node, &info->current_status);
		if (ACPI_SUCCESS(status)) {
381
			valid |= ACPI_VALID_STA;
L
Linus Torvalds 已提交
382 383 384 385
		}

		/* Execute the Device._ADR method */

L
Len Brown 已提交
386 387 388
		status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
							 &info->address);
		if (ACPI_SUCCESS(status)) {
389 390 391 392 393 394 395 396 397 398 399
			valid |= ACPI_VALID_ADR;
		}

		/* Execute the Device._sx_w methods */

		status = acpi_ut_execute_power_methods(node,
						       acpi_gbl_lowest_dstate_names,
						       ACPI_NUM_sx_w_METHODS,
						       info->lowest_dstates);
		if (ACPI_SUCCESS(status)) {
			valid |= ACPI_VALID_SXWS;
L
Linus Torvalds 已提交
400 401 402 403
		}

		/* Execute the Device._sx_d methods */

404 405 406 407
		status = acpi_ut_execute_power_methods(node,
						       acpi_gbl_highest_dstate_names,
						       ACPI_NUM_sx_d_METHODS,
						       info->highest_dstates);
L
Len Brown 已提交
408
		if (ACPI_SUCCESS(status)) {
409
			valid |= ACPI_VALID_SXDS;
L
Linus Torvalds 已提交
410 411 412
		}
	}

413 414 415 416 417 418
	/*
	 * Create a pointer to the string area of the return buffer.
	 * Point to the end of the base struct acpi_device_info structure.
	 */
	next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids);
	if (cid_list) {
L
Linus Torvalds 已提交
419

420 421 422 423 424
		/* Point past the CID DEVICE_ID array */

		next_id_string +=
		    ((acpi_size) cid_list->count *
		     sizeof(struct acpica_device_id));
L
Linus Torvalds 已提交
425 426
	}

427 428 429 430 431 432 433 434 435 436 437 438 439 440
	/*
	 * Copy the HID, UID, and CIDs to the return buffer. The variable-length
	 * strings are copied to the reserved area at the end of the buffer.
	 *
	 * For HID and CID, check if the ID is a PCI Root Bridge.
	 */
	if (hid) {
		next_id_string = acpi_ns_copy_device_id(&info->hardware_id,
							hid, next_id_string);

		if (acpi_ut_is_pci_root_bridge(hid->string)) {
			info->flags |= ACPI_PCI_ROOT_BRIDGE;
		}
	}
L
Linus Torvalds 已提交
441

442 443 444 445
	if (uid) {
		next_id_string = acpi_ns_copy_device_id(&info->unique_id,
							uid, next_id_string);
	}
L
Linus Torvalds 已提交
446 447

	if (cid_list) {
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
		info->compatible_id_list.count = cid_list->count;
		info->compatible_id_list.list_size = cid_list->list_size;

		/* Copy each CID */

		for (i = 0; i < cid_list->count; i++) {
			next_id_string =
			    acpi_ns_copy_device_id(&info->compatible_id_list.
						   ids[i], &cid_list->ids[i],
						   next_id_string);

			if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) {
				info->flags |= ACPI_PCI_ROOT_BRIDGE;
			}
		}
L
Linus Torvalds 已提交
463 464
	}

465 466 467 468 469 470 471 472 473 474 475
	/* Copy the fixed-length data */

	info->info_size = info_size;
	info->type = type;
	info->name = name;
	info->param_count = param_count;
	info->valid = valid;

	*return_buffer = info;
	status = AE_OK;

L
Len Brown 已提交
476
      cleanup:
477 478 479 480 481 482
	if (hid) {
		ACPI_FREE(hid);
	}
	if (uid) {
		ACPI_FREE(uid);
	}
L
Linus Torvalds 已提交
483
	if (cid_list) {
B
Bob Moore 已提交
484
		ACPI_FREE(cid_list);
L
Linus Torvalds 已提交
485 486 487 488
	}
	return (status);
}

B
Bob Moore 已提交
489
ACPI_EXPORT_SYMBOL(acpi_get_object_info)
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637

/******************************************************************************
 *
 * FUNCTION:    acpi_install_method
 *
 * PARAMETERS:  Buffer         - An ACPI table containing one control method
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Install a control method into the namespace. If the method
 *              name already exists in the namespace, it is overwritten. The
 *              input buffer must contain a valid DSDT or SSDT containing a
 *              single control method.
 *
 ******************************************************************************/
acpi_status acpi_install_method(u8 *buffer)
{
	struct acpi_table_header *table =
	    ACPI_CAST_PTR(struct acpi_table_header, buffer);
	u8 *aml_buffer;
	u8 *aml_start;
	char *path;
	struct acpi_namespace_node *node;
	union acpi_operand_object *method_obj;
	struct acpi_parse_state parser_state;
	u32 aml_length;
	u16 opcode;
	u8 method_flags;
	acpi_status status;

	/* Parameter validation */

	if (!buffer) {
		return AE_BAD_PARAMETER;
	}

	/* Table must be a DSDT or SSDT */

	if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) &&
	    !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
		return AE_BAD_HEADER;
	}

	/* First AML opcode in the table must be a control method */

	parser_state.aml = buffer + sizeof(struct acpi_table_header);
	opcode = acpi_ps_peek_opcode(&parser_state);
	if (opcode != AML_METHOD_OP) {
		return AE_BAD_PARAMETER;
	}

	/* Extract method information from the raw AML */

	parser_state.aml += acpi_ps_get_opcode_size(opcode);
	parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state);
	path = acpi_ps_get_next_namestring(&parser_state);
	method_flags = *parser_state.aml++;
	aml_start = parser_state.aml;
	aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);

	/*
	 * Allocate resources up-front. We don't want to have to delete a new
	 * node from the namespace if we cannot allocate memory.
	 */
	aml_buffer = ACPI_ALLOCATE(aml_length);
	if (!aml_buffer) {
		return AE_NO_MEMORY;
	}

	method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
	if (!method_obj) {
		ACPI_FREE(aml_buffer);
		return AE_NO_MEMORY;
	}

	/* Lock namespace for acpi_ns_lookup, we may be creating a new node */

	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
		goto error_exit;
	}

	/* The lookup either returns an existing node or creates a new one */

	status =
	    acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
			   ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
			   NULL, &node);

	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);

	if (ACPI_FAILURE(status)) {	/* ns_lookup */
		if (status != AE_ALREADY_EXISTS) {
			goto error_exit;
		}

		/* Node existed previously, make sure it is a method node */

		if (node->type != ACPI_TYPE_METHOD) {
			status = AE_TYPE;
			goto error_exit;
		}
	}

	/* Copy the method AML to the local buffer */

	ACPI_MEMCPY(aml_buffer, aml_start, aml_length);

	/* Initialize the method object with the new method's information */

	method_obj->method.aml_start = aml_buffer;
	method_obj->method.aml_length = aml_length;

	method_obj->method.param_count = (u8)
	    (method_flags & AML_METHOD_ARG_COUNT);

	method_obj->method.method_flags = (u8)
	    (method_flags & ~AML_METHOD_ARG_COUNT);

	if (method_flags & AML_METHOD_SERIALIZED) {
		method_obj->method.sync_level = (u8)
		    ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
	}

	/*
	 * Now that it is complete, we can attach the new method object to
	 * the method Node (detaches/deletes any existing object)
	 */
	status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD);

	/*
	 * Flag indicates AML buffer is dynamic, must be deleted later.
	 * Must be set only after attach above.
	 */
	node->flags |= ANOBJ_ALLOCATED_BUFFER;

	/* Remove local reference to the method object */

	acpi_ut_remove_reference(method_obj);
	return status;

error_exit:

	ACPI_FREE(aml_buffer);
	ACPI_FREE(method_obj);
	return status;
}
ACPI_EXPORT_SYMBOL(acpi_install_method)