nsxfname.c revision 241973
10Sstevel@tonic-gate/****************************************************************************** 20Sstevel@tonic-gate * 30Sstevel@tonic-gate * Module Name: nsxfname - Public interfaces to the ACPI subsystem 40Sstevel@tonic-gate * ACPI Namespace oriented interfaces 53524Srobj * 63524Srobj *****************************************************************************/ 70Sstevel@tonic-gate 80Sstevel@tonic-gate/* 90Sstevel@tonic-gate * Copyright (C) 2000 - 2012, Intel Corp. 100Sstevel@tonic-gate * All rights reserved. 110Sstevel@tonic-gate * 120Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 130Sstevel@tonic-gate * modification, are permitted provided that the following conditions 140Sstevel@tonic-gate * are met: 150Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 160Sstevel@tonic-gate * notice, this list of conditions, and the following disclaimer, 170Sstevel@tonic-gate * without modification. 180Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce at minimum a disclaimer 190Sstevel@tonic-gate * substantially similar to the "NO WARRANTY" disclaimer below 200Sstevel@tonic-gate * ("Disclaimer") and any redistribution must be conditioned upon 210Sstevel@tonic-gate * including a substantially similar Disclaimer requirement for further 223524Srobj * binary redistribution. 230Sstevel@tonic-gate * 3. Neither the names of the above-listed copyright holders nor the names 240Sstevel@tonic-gate * of any contributors may be used to endorse or promote products derived 250Sstevel@tonic-gate * from this software without specific prior written permission. 260Sstevel@tonic-gate * 270Sstevel@tonic-gate * Alternatively, this software may be distributed under the terms of the 280Sstevel@tonic-gate * GNU General Public License ("GPL") version 2 as published by the Free 290Sstevel@tonic-gate * Software Foundation. 300Sstevel@tonic-gate * 310Sstevel@tonic-gate * NO WARRANTY 320Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 330Sstevel@tonic-gate * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 340Sstevel@tonic-gate * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 350Sstevel@tonic-gate * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 360Sstevel@tonic-gate * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 370Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 380Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 390Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 400Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 415433Saf * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 420Sstevel@tonic-gate * POSSIBILITY OF SUCH DAMAGES. 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate 450Sstevel@tonic-gate#define __NSXFNAME_C__ 460Sstevel@tonic-gate 470Sstevel@tonic-gate#include <contrib/dev/acpica/include/acpi.h> 480Sstevel@tonic-gate#include <contrib/dev/acpica/include/accommon.h> 490Sstevel@tonic-gate#include <contrib/dev/acpica/include/acnamesp.h> 500Sstevel@tonic-gate#include <contrib/dev/acpica/include/acparser.h> 510Sstevel@tonic-gate#include <contrib/dev/acpica/include/amlcode.h> 520Sstevel@tonic-gate 530Sstevel@tonic-gate 540Sstevel@tonic-gate#define _COMPONENT ACPI_NAMESPACE 550Sstevel@tonic-gate ACPI_MODULE_NAME ("nsxfname") 560Sstevel@tonic-gate 570Sstevel@tonic-gate/* Local prototypes */ 580Sstevel@tonic-gate 590Sstevel@tonic-gatestatic char * 600Sstevel@tonic-gateAcpiNsCopyDeviceId ( 610Sstevel@tonic-gate ACPI_PNP_DEVICE_ID *Dest, 620Sstevel@tonic-gate ACPI_PNP_DEVICE_ID *Source, 630Sstevel@tonic-gate char *StringArea); 640Sstevel@tonic-gate 650Sstevel@tonic-gate 660Sstevel@tonic-gate/****************************************************************************** 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * FUNCTION: AcpiGetHandle 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * PARAMETERS: Parent - Object to search under (search scope). 710Sstevel@tonic-gate * Pathname - Pointer to an asciiz string containing the 720Sstevel@tonic-gate * name 730Sstevel@tonic-gate * RetHandle - Where the return handle is returned 740Sstevel@tonic-gate * 750Sstevel@tonic-gate * RETURN: Status 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * DESCRIPTION: This routine will search for a caller specified name in the 780Sstevel@tonic-gate * name space. The caller can restrict the search region by 790Sstevel@tonic-gate * specifying a non NULL parent. The parent value is itself a 800Sstevel@tonic-gate * namespace handle. 813524Srobj * 820Sstevel@tonic-gate ******************************************************************************/ 833524Srobj 843524SrobjACPI_STATUS 853524SrobjAcpiGetHandle ( 863524Srobj ACPI_HANDLE Parent, 873524Srobj ACPI_STRING Pathname, 883524Srobj ACPI_HANDLE *RetHandle) 893524Srobj{ 903524Srobj ACPI_STATUS Status; 913524Srobj ACPI_NAMESPACE_NODE *Node = NULL; 923524Srobj ACPI_NAMESPACE_NODE *PrefixNode = NULL; 933524Srobj 943524Srobj 953524Srobj ACPI_FUNCTION_ENTRY (); 963524Srobj 973524Srobj 983524Srobj /* Parameter Validation */ 993524Srobj 1003524Srobj if (!RetHandle || !Pathname) 1013524Srobj { 1020Sstevel@tonic-gate return (AE_BAD_PARAMETER); 1030Sstevel@tonic-gate } 1043524Srobj 1053524Srobj /* Convert a parent handle to a prefix node */ 1063524Srobj 1073524Srobj if (Parent) 1083524Srobj { 1093524Srobj PrefixNode = AcpiNsValidateHandle (Parent); 1103524Srobj if (!PrefixNode) 1110Sstevel@tonic-gate { 1120Sstevel@tonic-gate return (AE_BAD_PARAMETER); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * Valid cases are: 1180Sstevel@tonic-gate * 1) Fully qualified pathname 1190Sstevel@tonic-gate * 2) Parent + Relative pathname 1200Sstevel@tonic-gate * 1210Sstevel@tonic-gate * Error for <null Parent + relative path> 1223524Srobj */ 1233524Srobj if (AcpiNsValidRootPrefix (Pathname[0])) 1243524Srobj { 1253524Srobj /* Pathname is fully qualified (starts with '\') */ 1263524Srobj 1270Sstevel@tonic-gate /* Special case for root-only, since we can't search for it */ 1283524Srobj 1293524Srobj if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH)) 1303524Srobj { 1313524Srobj *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode); 1323524Srobj return (AE_OK); 1333524Srobj } 1343524Srobj } 1353524Srobj else if (!PrefixNode) 1360Sstevel@tonic-gate { 1370Sstevel@tonic-gate /* Relative path with null prefix is disallowed */ 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate return (AE_BAD_PARAMETER); 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* Find the Node and convert to a handle */ 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node); 1453524Srobj if (ACPI_SUCCESS (Status)) 1463524Srobj { 1473524Srobj *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node); 1483524Srobj } 1493524Srobj 1500Sstevel@tonic-gate return (Status); 1513524Srobj} 1523524Srobj 1533524SrobjACPI_EXPORT_SYMBOL (AcpiGetHandle) 1543524Srobj 1553524Srobj 1563524Srobj/****************************************************************************** 1573524Srobj * 1583524Srobj * FUNCTION: AcpiGetName 1590Sstevel@tonic-gate * 1600Sstevel@tonic-gate * PARAMETERS: Handle - Handle to be converted to a pathname 1610Sstevel@tonic-gate * NameType - Full pathname or single segment 1620Sstevel@tonic-gate * Buffer - Buffer for returned path 1630Sstevel@tonic-gate * 1640Sstevel@tonic-gate * RETURN: Pointer to a string containing the fully qualified Name. 1650Sstevel@tonic-gate * 1660Sstevel@tonic-gate * DESCRIPTION: This routine returns the fully qualified name associated with 1673524Srobj * the Handle parameter. This and the AcpiPathnameToHandle are 1683524Srobj * complementary functions. 1693524Srobj * 1703524Srobj ******************************************************************************/ 1713524Srobj 1723524SrobjACPI_STATUS 1733524SrobjAcpiGetName ( 1743524Srobj ACPI_HANDLE Handle, 1753524Srobj UINT32 NameType, 1763524Srobj ACPI_BUFFER *Buffer) 1773524Srobj{ 1783524Srobj ACPI_STATUS Status; 1793524Srobj ACPI_NAMESPACE_NODE *Node; 1803524Srobj 1813524Srobj 1823524Srobj /* Parameter validation */ 1833524Srobj 1843524Srobj if (NameType > ACPI_NAME_TYPE_MAX) 1853524Srobj { 1863524Srobj return (AE_BAD_PARAMETER); 1873524Srobj } 1883524Srobj 1893524Srobj Status = AcpiUtValidateBuffer (Buffer); 1903524Srobj if (ACPI_FAILURE (Status)) 1913524Srobj { 1923524Srobj return (Status); 1933524Srobj } 1943524Srobj 1953524Srobj if (NameType == ACPI_FULL_PATHNAME) 1963524Srobj { 1973524Srobj /* Get the full pathname (From the namespace root) */ 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate Status = AcpiNsHandleToPathname (Handle, Buffer); 2000Sstevel@tonic-gate return (Status); 2010Sstevel@tonic-gate } 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * Wants the single segment ACPI name. 2050Sstevel@tonic-gate * Validate handle and convert to a namespace Node 2060Sstevel@tonic-gate */ 2073524Srobj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 2083524Srobj if (ACPI_FAILURE (Status)) 2093524Srobj { 2103524Srobj return (Status); 2113524Srobj } 2123524Srobj 2133524Srobj Node = AcpiNsValidateHandle (Handle); 2143524Srobj if (!Node) 2153524Srobj { 2163524Srobj Status = AE_BAD_PARAMETER; 2173524Srobj goto UnlockAndExit; 2183524Srobj } 2193524Srobj 2203524Srobj /* Validate/Allocate/Clear caller buffer */ 2213524Srobj 2223524Srobj Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH); 2233524Srobj if (ACPI_FAILURE (Status)) 2243524Srobj { 2253524Srobj goto UnlockAndExit; 2263524Srobj } 2273524Srobj 2283524Srobj /* Just copy the ACPI name from the Node and zero terminate it */ 2293524Srobj 2303524Srobj ACPI_MOVE_NAME (Buffer->Pointer, AcpiUtGetNodeName (Node)); 2313524Srobj ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0; 2323524Srobj Status = AE_OK; 2333524Srobj 2343524Srobj 2353524SrobjUnlockAndExit: 2363524Srobj 2373524Srobj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 2383524Srobj return (Status); 2393524Srobj} 2403524Srobj 2413524SrobjACPI_EXPORT_SYMBOL (AcpiGetName) 2423524Srobj 2433524Srobj 2443524Srobj/****************************************************************************** 2453524Srobj * 2460Sstevel@tonic-gate * FUNCTION: AcpiNsCopyDeviceId 2470Sstevel@tonic-gate * 248 * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID 249 * Source - Pointer to the source PNP_DEVICE_ID 250 * StringArea - Pointer to where to copy the dest string 251 * 252 * RETURN: Pointer to the next string area 253 * 254 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data. 255 * 256 ******************************************************************************/ 257 258static char * 259AcpiNsCopyDeviceId ( 260 ACPI_PNP_DEVICE_ID *Dest, 261 ACPI_PNP_DEVICE_ID *Source, 262 char *StringArea) 263{ 264 265 /* Create the destination PNP_DEVICE_ID */ 266 267 Dest->String = StringArea; 268 Dest->Length = Source->Length; 269 270 /* Copy actual string and return a pointer to the next string area */ 271 272 ACPI_MEMCPY (StringArea, Source->String, Source->Length); 273 return (StringArea + Source->Length); 274} 275 276 277/****************************************************************************** 278 * 279 * FUNCTION: AcpiGetObjectInfo 280 * 281 * PARAMETERS: Handle - Object Handle 282 * ReturnBuffer - Where the info is returned 283 * 284 * RETURN: Status 285 * 286 * DESCRIPTION: Returns information about an object as gleaned from the 287 * namespace node and possibly by running several standard 288 * control methods (Such as in the case of a device.) 289 * 290 * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB, 291 * _STA, _ADR, _SxW, and _SxD methods. 292 * 293 * Note: Allocates the return buffer, must be freed by the caller. 294 * 295 ******************************************************************************/ 296 297ACPI_STATUS 298AcpiGetObjectInfo ( 299 ACPI_HANDLE Handle, 300 ACPI_DEVICE_INFO **ReturnBuffer) 301{ 302 ACPI_NAMESPACE_NODE *Node; 303 ACPI_DEVICE_INFO *Info; 304 ACPI_PNP_DEVICE_ID_LIST *CidList = NULL; 305 ACPI_PNP_DEVICE_ID *Hid = NULL; 306 ACPI_PNP_DEVICE_ID *Uid = NULL; 307 ACPI_PNP_DEVICE_ID *Sub = NULL; 308 char *NextIdString; 309 ACPI_OBJECT_TYPE Type; 310 ACPI_NAME Name; 311 UINT8 ParamCount= 0; 312 UINT8 Valid = 0; 313 UINT32 InfoSize; 314 UINT32 i; 315 ACPI_STATUS Status; 316 317 318 /* Parameter validation */ 319 320 if (!Handle || !ReturnBuffer) 321 { 322 return (AE_BAD_PARAMETER); 323 } 324 325 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 326 if (ACPI_FAILURE (Status)) 327 { 328 goto Cleanup; 329 } 330 331 Node = AcpiNsValidateHandle (Handle); 332 if (!Node) 333 { 334 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 335 return (AE_BAD_PARAMETER); 336 } 337 338 /* Get the namespace node data while the namespace is locked */ 339 340 InfoSize = sizeof (ACPI_DEVICE_INFO); 341 Type = Node->Type; 342 Name = Node->Name.Integer; 343 344 if (Node->Type == ACPI_TYPE_METHOD) 345 { 346 ParamCount = Node->Object->Method.ParamCount; 347 } 348 349 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 350 if (ACPI_FAILURE (Status)) 351 { 352 return (Status); 353 } 354 355 if ((Type == ACPI_TYPE_DEVICE) || 356 (Type == ACPI_TYPE_PROCESSOR)) 357 { 358 /* 359 * Get extra info for ACPI Device/Processor objects only: 360 * Run the Device _HID, _UID, _SUB, and _CID methods. 361 * 362 * Note: none of these methods are required, so they may or may 363 * not be present for this device. The Info->Valid bitfield is used 364 * to indicate which methods were found and run successfully. 365 */ 366 367 /* Execute the Device._HID method */ 368 369 Status = AcpiUtExecute_HID (Node, &Hid); 370 if (ACPI_SUCCESS (Status)) 371 { 372 InfoSize += Hid->Length; 373 Valid |= ACPI_VALID_HID; 374 } 375 376 /* Execute the Device._UID method */ 377 378 Status = AcpiUtExecute_UID (Node, &Uid); 379 if (ACPI_SUCCESS (Status)) 380 { 381 InfoSize += Uid->Length; 382 Valid |= ACPI_VALID_UID; 383 } 384 385 /* Execute the Device._SUB method */ 386 387 Status = AcpiUtExecute_SUB (Node, &Sub); 388 if (ACPI_SUCCESS (Status)) 389 { 390 InfoSize += Sub->Length; 391 Valid |= ACPI_VALID_SUB; 392 } 393 394 /* Execute the Device._CID method */ 395 396 Status = AcpiUtExecute_CID (Node, &CidList); 397 if (ACPI_SUCCESS (Status)) 398 { 399 /* Add size of CID strings and CID pointer array */ 400 401 InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST)); 402 Valid |= ACPI_VALID_CID; 403 } 404 } 405 406 /* 407 * Now that we have the variable-length data, we can allocate the 408 * return buffer 409 */ 410 Info = ACPI_ALLOCATE_ZEROED (InfoSize); 411 if (!Info) 412 { 413 Status = AE_NO_MEMORY; 414 goto Cleanup; 415 } 416 417 /* Get the fixed-length data */ 418 419 if ((Type == ACPI_TYPE_DEVICE) || 420 (Type == ACPI_TYPE_PROCESSOR)) 421 { 422 /* 423 * Get extra info for ACPI Device/Processor objects only: 424 * Run the _STA, _ADR and, SxW, and _SxD methods. 425 * 426 * Note: none of these methods are required, so they may or may 427 * not be present for this device. The Info->Valid bitfield is used 428 * to indicate which methods were found and run successfully. 429 */ 430 431 /* Execute the Device._STA method */ 432 433 Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus); 434 if (ACPI_SUCCESS (Status)) 435 { 436 Valid |= ACPI_VALID_STA; 437 } 438 439 /* Execute the Device._ADR method */ 440 441 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node, 442 &Info->Address); 443 if (ACPI_SUCCESS (Status)) 444 { 445 Valid |= ACPI_VALID_ADR; 446 } 447 448 /* Execute the Device._SxW methods */ 449 450 Status = AcpiUtExecutePowerMethods (Node, 451 AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS, 452 Info->LowestDstates); 453 if (ACPI_SUCCESS (Status)) 454 { 455 Valid |= ACPI_VALID_SXWS; 456 } 457 458 /* Execute the Device._SxD methods */ 459 460 Status = AcpiUtExecutePowerMethods (Node, 461 AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS, 462 Info->HighestDstates); 463 if (ACPI_SUCCESS (Status)) 464 { 465 Valid |= ACPI_VALID_SXDS; 466 } 467 } 468 469 /* 470 * Create a pointer to the string area of the return buffer. 471 * Point to the end of the base ACPI_DEVICE_INFO structure. 472 */ 473 NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids); 474 if (CidList) 475 { 476 /* Point past the CID PNP_DEVICE_ID array */ 477 478 NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID)); 479 } 480 481 /* 482 * Copy the HID, UID, SUB, and CIDs to the return buffer. 483 * The variable-length strings are copied to the reserved area 484 * at the end of the buffer. 485 * 486 * For HID and CID, check if the ID is a PCI Root Bridge. 487 */ 488 if (Hid) 489 { 490 NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId, 491 Hid, NextIdString); 492 493 if (AcpiUtIsPciRootBridge (Hid->String)) 494 { 495 Info->Flags |= ACPI_PCI_ROOT_BRIDGE; 496 } 497 } 498 499 if (Uid) 500 { 501 NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId, 502 Uid, NextIdString); 503 } 504 505 if (Sub) 506 { 507 NextIdString = AcpiNsCopyDeviceId (&Info->SubsystemId, 508 Sub, NextIdString); 509 } 510 511 if (CidList) 512 { 513 Info->CompatibleIdList.Count = CidList->Count; 514 Info->CompatibleIdList.ListSize = CidList->ListSize; 515 516 /* Copy each CID */ 517 518 for (i = 0; i < CidList->Count; i++) 519 { 520 NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i], 521 &CidList->Ids[i], NextIdString); 522 523 if (AcpiUtIsPciRootBridge (CidList->Ids[i].String)) 524 { 525 Info->Flags |= ACPI_PCI_ROOT_BRIDGE; 526 } 527 } 528 } 529 530 /* Copy the fixed-length data */ 531 532 Info->InfoSize = InfoSize; 533 Info->Type = Type; 534 Info->Name = Name; 535 Info->ParamCount = ParamCount; 536 Info->Valid = Valid; 537 538 *ReturnBuffer = Info; 539 Status = AE_OK; 540 541 542Cleanup: 543 if (Hid) 544 { 545 ACPI_FREE (Hid); 546 } 547 if (Uid) 548 { 549 ACPI_FREE (Uid); 550 } 551 if (Sub) 552 { 553 ACPI_FREE (Sub); 554 } 555 if (CidList) 556 { 557 ACPI_FREE (CidList); 558 } 559 return (Status); 560} 561 562ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo) 563 564 565/****************************************************************************** 566 * 567 * FUNCTION: AcpiInstallMethod 568 * 569 * PARAMETERS: Buffer - An ACPI table containing one control method 570 * 571 * RETURN: Status 572 * 573 * DESCRIPTION: Install a control method into the namespace. If the method 574 * name already exists in the namespace, it is overwritten. The 575 * input buffer must contain a valid DSDT or SSDT containing a 576 * single control method. 577 * 578 ******************************************************************************/ 579 580ACPI_STATUS 581AcpiInstallMethod ( 582 UINT8 *Buffer) 583{ 584 ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer); 585 UINT8 *AmlBuffer; 586 UINT8 *AmlStart; 587 char *Path; 588 ACPI_NAMESPACE_NODE *Node; 589 ACPI_OPERAND_OBJECT *MethodObj; 590 ACPI_PARSE_STATE ParserState; 591 UINT32 AmlLength; 592 UINT16 Opcode; 593 UINT8 MethodFlags; 594 ACPI_STATUS Status; 595 596 597 /* Parameter validation */ 598 599 if (!Buffer) 600 { 601 return (AE_BAD_PARAMETER); 602 } 603 604 /* Table must be a DSDT or SSDT */ 605 606 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) && 607 !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT)) 608 { 609 return (AE_BAD_HEADER); 610 } 611 612 /* First AML opcode in the table must be a control method */ 613 614 ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER); 615 Opcode = AcpiPsPeekOpcode (&ParserState); 616 if (Opcode != AML_METHOD_OP) 617 { 618 return (AE_BAD_PARAMETER); 619 } 620 621 /* Extract method information from the raw AML */ 622 623 ParserState.Aml += AcpiPsGetOpcodeSize (Opcode); 624 ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState); 625 Path = AcpiPsGetNextNamestring (&ParserState); 626 MethodFlags = *ParserState.Aml++; 627 AmlStart = ParserState.Aml; 628 AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart); 629 630 /* 631 * Allocate resources up-front. We don't want to have to delete a new 632 * node from the namespace if we cannot allocate memory. 633 */ 634 AmlBuffer = ACPI_ALLOCATE (AmlLength); 635 if (!AmlBuffer) 636 { 637 return (AE_NO_MEMORY); 638 } 639 640 MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD); 641 if (!MethodObj) 642 { 643 ACPI_FREE (AmlBuffer); 644 return (AE_NO_MEMORY); 645 } 646 647 /* Lock namespace for AcpiNsLookup, we may be creating a new node */ 648 649 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 650 if (ACPI_FAILURE (Status)) 651 { 652 goto ErrorExit; 653 } 654 655 /* The lookup either returns an existing node or creates a new one */ 656 657 Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1, 658 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node); 659 660 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 661 662 if (ACPI_FAILURE (Status)) /* NsLookup */ 663 { 664 if (Status != AE_ALREADY_EXISTS) 665 { 666 goto ErrorExit; 667 } 668 669 /* Node existed previously, make sure it is a method node */ 670 671 if (Node->Type != ACPI_TYPE_METHOD) 672 { 673 Status = AE_TYPE; 674 goto ErrorExit; 675 } 676 } 677 678 /* Copy the method AML to the local buffer */ 679 680 ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength); 681 682 /* Initialize the method object with the new method's information */ 683 684 MethodObj->Method.AmlStart = AmlBuffer; 685 MethodObj->Method.AmlLength = AmlLength; 686 687 MethodObj->Method.ParamCount = (UINT8) 688 (MethodFlags & AML_METHOD_ARG_COUNT); 689 690 if (MethodFlags & AML_METHOD_SERIALIZED) 691 { 692 MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED; 693 694 MethodObj->Method.SyncLevel = (UINT8) 695 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4); 696 } 697 698 /* 699 * Now that it is complete, we can attach the new method object to 700 * the method Node (detaches/deletes any existing object) 701 */ 702 Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD); 703 704 /* 705 * Flag indicates AML buffer is dynamic, must be deleted later. 706 * Must be set only after attach above. 707 */ 708 Node->Flags |= ANOBJ_ALLOCATED_BUFFER; 709 710 /* Remove local reference to the method object */ 711 712 AcpiUtRemoveReference (MethodObj); 713 return (Status); 714 715 716ErrorExit: 717 718 ACPI_FREE (AmlBuffer); 719 ACPI_FREE (MethodObj); 720 return (Status); 721} 722 723ACPI_EXPORT_SYMBOL (AcpiInstallMethod) 724