1 /****************************************************************************** 2 * 3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem 4 * ACPI Namespace oriented interfaces 5 * 6 *****************************************************************************/ 7 8 /****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 ***************************************************************************** 116 * 117 * Alternatively, you may choose to be licensed under the terms of the 118 * following license: 119 * 120 * Redistribution and use in source and binary forms, with or without 121 * modification, are permitted provided that the following conditions 122 * are met: 123 * 1. Redistributions of source code must retain the above copyright 124 * notice, this list of conditions, and the following disclaimer, 125 * without modification. 126 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 127 * substantially similar to the "NO WARRANTY" disclaimer below 128 * ("Disclaimer") and any redistribution must be conditioned upon 129 * including a substantially similar Disclaimer requirement for further 130 * binary redistribution. 131 * 3. Neither the names of the above-listed copyright holders nor the names 132 * of any contributors may be used to endorse or promote products derived 133 * from this software without specific prior written permission. 134 * 135 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 136 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 137 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 138 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 139 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 140 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 141 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 142 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 143 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 144 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 145 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 146 * 147 * Alternatively, you may choose to be licensed under the terms of the 148 * GNU General Public License ("GPL") version 2 as published by the Free 149 * Software Foundation. 150 * 151 *****************************************************************************/ 152 153 #define EXPORT_ACPI_INTERFACES 154 155 #include <contrib/dev/acpica/include/acpi.h> 156 #include <contrib/dev/acpica/include/accommon.h> 157 #include <contrib/dev/acpica/include/acnamesp.h> 158 #include <contrib/dev/acpica/include/acparser.h> 159 #include <contrib/dev/acpica/include/amlcode.h> 160 161 162 #define _COMPONENT ACPI_NAMESPACE 163 ACPI_MODULE_NAME ("nsxfname") 164 165 /* Local prototypes */ 166 167 static char * 168 AcpiNsCopyDeviceId ( 169 ACPI_PNP_DEVICE_ID *Dest, 170 ACPI_PNP_DEVICE_ID *Source, 171 char *StringArea); 172 173 174 /****************************************************************************** 175 * 176 * FUNCTION: AcpiGetHandle 177 * 178 * PARAMETERS: Parent - Object to search under (search scope). 179 * Pathname - Pointer to an asciiz string containing the 180 * name 181 * RetHandle - Where the return handle is returned 182 * 183 * RETURN: Status 184 * 185 * DESCRIPTION: This routine will search for a caller specified name in the 186 * name space. The caller can restrict the search region by 187 * specifying a non NULL parent. The parent value is itself a 188 * namespace handle. 189 * 190 ******************************************************************************/ 191 192 ACPI_STATUS 193 AcpiGetHandle ( 194 ACPI_HANDLE Parent, 195 ACPI_STRING Pathname, 196 ACPI_HANDLE *RetHandle) 197 { 198 ACPI_STATUS Status; 199 ACPI_NAMESPACE_NODE *Node = NULL; 200 ACPI_NAMESPACE_NODE *PrefixNode = NULL; 201 202 203 ACPI_FUNCTION_ENTRY (); 204 205 206 /* Parameter Validation */ 207 208 if (!RetHandle || !Pathname) 209 { 210 return (AE_BAD_PARAMETER); 211 } 212 213 /* Convert a parent handle to a prefix node */ 214 215 if (Parent) 216 { 217 PrefixNode = AcpiNsValidateHandle (Parent); 218 if (!PrefixNode) 219 { 220 return (AE_BAD_PARAMETER); 221 } 222 } 223 224 /* 225 * Valid cases are: 226 * 1) Fully qualified pathname 227 * 2) Parent + Relative pathname 228 * 229 * Error for <null Parent + relative path> 230 */ 231 if (ACPI_IS_ROOT_PREFIX (Pathname[0])) 232 { 233 /* Pathname is fully qualified (starts with '\') */ 234 235 /* Special case for root-only, since we can't search for it */ 236 237 if (!strcmp (Pathname, ACPI_NS_ROOT_PATH)) 238 { 239 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode); 240 return (AE_OK); 241 } 242 } 243 else if (!PrefixNode) 244 { 245 /* Relative path with null prefix is disallowed */ 246 247 return (AE_BAD_PARAMETER); 248 } 249 250 /* Find the Node and convert to a handle */ 251 252 Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node); 253 if (ACPI_SUCCESS (Status)) 254 { 255 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node); 256 } 257 258 return (Status); 259 } 260 261 ACPI_EXPORT_SYMBOL (AcpiGetHandle) 262 263 264 /****************************************************************************** 265 * 266 * FUNCTION: AcpiGetName 267 * 268 * PARAMETERS: Handle - Handle to be converted to a pathname 269 * NameType - Full pathname or single segment 270 * Buffer - Buffer for returned path 271 * 272 * RETURN: Pointer to a string containing the fully qualified Name. 273 * 274 * DESCRIPTION: This routine returns the fully qualified name associated with 275 * the Handle parameter. This and the AcpiPathnameToHandle are 276 * complementary functions. 277 * 278 ******************************************************************************/ 279 280 ACPI_STATUS 281 AcpiGetName ( 282 ACPI_HANDLE Handle, 283 UINT32 NameType, 284 ACPI_BUFFER *Buffer) 285 { 286 ACPI_STATUS Status; 287 288 289 /* Parameter validation */ 290 291 if (NameType > ACPI_NAME_TYPE_MAX) 292 { 293 return (AE_BAD_PARAMETER); 294 } 295 296 Status = AcpiUtValidateBuffer (Buffer); 297 if (ACPI_FAILURE (Status)) 298 { 299 return (Status); 300 } 301 302 /* 303 * Wants the single segment ACPI name. 304 * Validate handle and convert to a namespace Node 305 */ 306 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 307 if (ACPI_FAILURE (Status)) 308 { 309 return (Status); 310 } 311 312 if (NameType == ACPI_FULL_PATHNAME || 313 NameType == ACPI_FULL_PATHNAME_NO_TRAILING) 314 { 315 /* Get the full pathname (From the namespace root) */ 316 317 Status = AcpiNsHandleToPathname (Handle, Buffer, 318 NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE); 319 } 320 else 321 { 322 /* Get the single name */ 323 324 Status = AcpiNsHandleToName (Handle, Buffer); 325 } 326 327 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 328 return (Status); 329 } 330 331 ACPI_EXPORT_SYMBOL (AcpiGetName) 332 333 334 /****************************************************************************** 335 * 336 * FUNCTION: AcpiNsCopyDeviceId 337 * 338 * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID 339 * Source - Pointer to the source PNP_DEVICE_ID 340 * StringArea - Pointer to where to copy the dest string 341 * 342 * RETURN: Pointer to the next string area 343 * 344 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data. 345 * 346 ******************************************************************************/ 347 348 static char * 349 AcpiNsCopyDeviceId ( 350 ACPI_PNP_DEVICE_ID *Dest, 351 ACPI_PNP_DEVICE_ID *Source, 352 char *StringArea) 353 { 354 /* Create the destination PNP_DEVICE_ID */ 355 356 Dest->String = StringArea; 357 Dest->Length = Source->Length; 358 359 /* Copy actual string and return a pointer to the next string area */ 360 361 memcpy (StringArea, Source->String, Source->Length); 362 return (StringArea + Source->Length); 363 } 364 365 366 /****************************************************************************** 367 * 368 * FUNCTION: AcpiGetObjectInfo 369 * 370 * PARAMETERS: Handle - Object Handle 371 * ReturnBuffer - Where the info is returned 372 * 373 * RETURN: Status 374 * 375 * DESCRIPTION: Returns information about an object as gleaned from the 376 * namespace node and possibly by running several standard 377 * control methods (Such as in the case of a device.) 378 * 379 * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA, 380 * _CLS, _ADR, _SxW, and _SxD methods. 381 * 382 * Note: Allocates the return buffer, must be freed by the caller. 383 * 384 * Note: This interface is intended to be used during the initial device 385 * discovery namespace traversal. Therefore, no complex methods can be 386 * executed, especially those that access operation regions. Therefore, do 387 * not add any additional methods that could cause problems in this area. 388 * this was the fate of the _SUB method which was found to cause such 389 * problems and was removed (11/2015). 390 * 391 ******************************************************************************/ 392 393 ACPI_STATUS 394 AcpiGetObjectInfo ( 395 ACPI_HANDLE Handle, 396 ACPI_DEVICE_INFO **ReturnBuffer) 397 { 398 ACPI_NAMESPACE_NODE *Node; 399 ACPI_DEVICE_INFO *Info; 400 ACPI_PNP_DEVICE_ID_LIST *CidList = NULL; 401 ACPI_PNP_DEVICE_ID *Hid = NULL; 402 ACPI_PNP_DEVICE_ID *Uid = NULL; 403 ACPI_PNP_DEVICE_ID *Cls = NULL; 404 char *NextIdString; 405 ACPI_OBJECT_TYPE Type; 406 ACPI_NAME Name; 407 UINT8 ParamCount= 0; 408 UINT16 Valid = 0; 409 UINT32 InfoSize; 410 UINT32 i; 411 ACPI_STATUS Status; 412 413 414 /* Parameter validation */ 415 416 if (!Handle || !ReturnBuffer) 417 { 418 return (AE_BAD_PARAMETER); 419 } 420 421 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 422 if (ACPI_FAILURE (Status)) 423 { 424 return (Status); 425 } 426 427 Node = AcpiNsValidateHandle (Handle); 428 if (!Node) 429 { 430 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 431 return (AE_BAD_PARAMETER); 432 } 433 434 /* Get the namespace node data while the namespace is locked */ 435 436 InfoSize = sizeof (ACPI_DEVICE_INFO); 437 Type = Node->Type; 438 Name = Node->Name.Integer; 439 440 if (Node->Type == ACPI_TYPE_METHOD) 441 { 442 ParamCount = Node->Object->Method.ParamCount; 443 } 444 445 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 446 if (ACPI_FAILURE (Status)) 447 { 448 return (Status); 449 } 450 451 if ((Type == ACPI_TYPE_DEVICE) || 452 (Type == ACPI_TYPE_PROCESSOR)) 453 { 454 /* 455 * Get extra info for ACPI Device/Processor objects only: 456 * Run the Device _HID, _UID, _CLS, and _CID methods. 457 * 458 * Note: none of these methods are required, so they may or may 459 * not be present for this device. The Info->Valid bitfield is used 460 * to indicate which methods were found and run successfully. 461 */ 462 463 /* Execute the Device._HID method */ 464 465 Status = AcpiUtExecute_HID (Node, &Hid); 466 if (ACPI_SUCCESS (Status)) 467 { 468 InfoSize += Hid->Length; 469 Valid |= ACPI_VALID_HID; 470 } 471 472 /* Execute the Device._UID method */ 473 474 Status = AcpiUtExecute_UID (Node, &Uid); 475 if (ACPI_SUCCESS (Status)) 476 { 477 InfoSize += Uid->Length; 478 Valid |= ACPI_VALID_UID; 479 } 480 481 /* Execute the Device._CID method */ 482 483 Status = AcpiUtExecute_CID (Node, &CidList); 484 if (ACPI_SUCCESS (Status)) 485 { 486 /* Add size of CID strings and CID pointer array */ 487 488 InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST)); 489 Valid |= ACPI_VALID_CID; 490 } 491 492 /* Execute the Device._CLS method */ 493 494 Status = AcpiUtExecute_CLS (Node, &Cls); 495 if (ACPI_SUCCESS (Status)) 496 { 497 InfoSize += Cls->Length; 498 Valid |= ACPI_VALID_CLS; 499 } 500 } 501 502 /* 503 * Now that we have the variable-length data, we can allocate the 504 * return buffer 505 */ 506 Info = ACPI_ALLOCATE_ZEROED (InfoSize); 507 if (!Info) 508 { 509 Status = AE_NO_MEMORY; 510 goto Cleanup; 511 } 512 513 /* Get the fixed-length data */ 514 515 if ((Type == ACPI_TYPE_DEVICE) || 516 (Type == ACPI_TYPE_PROCESSOR)) 517 { 518 /* 519 * Get extra info for ACPI Device/Processor objects only: 520 * Run the _STA, _ADR and, SxW, and _SxD methods. 521 * 522 * Notes: none of these methods are required, so they may or may 523 * not be present for this device. The Info->Valid bitfield is used 524 * to indicate which methods were found and run successfully. 525 * 526 * For _STA, if the method does not exist, then (as per the ACPI 527 * specification), the returned CurrentStatus flags will indicate 528 * that the device is present/functional/enabled. Otherwise, the 529 * CurrentStatus flags reflect the value returned from _STA. 530 */ 531 532 /* Execute the Device._STA method */ 533 534 Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus); 535 if (ACPI_SUCCESS (Status)) 536 { 537 Valid |= ACPI_VALID_STA; 538 } 539 540 /* Execute the Device._ADR method */ 541 542 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node, 543 &Info->Address); 544 if (ACPI_SUCCESS (Status)) 545 { 546 Valid |= ACPI_VALID_ADR; 547 } 548 549 /* Execute the Device._SxW methods */ 550 551 Status = AcpiUtExecutePowerMethods (Node, 552 AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS, 553 Info->LowestDstates); 554 if (ACPI_SUCCESS (Status)) 555 { 556 Valid |= ACPI_VALID_SXWS; 557 } 558 559 /* Execute the Device._SxD methods */ 560 561 Status = AcpiUtExecutePowerMethods (Node, 562 AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS, 563 Info->HighestDstates); 564 if (ACPI_SUCCESS (Status)) 565 { 566 Valid |= ACPI_VALID_SXDS; 567 } 568 } 569 570 /* 571 * Create a pointer to the string area of the return buffer. 572 * Point to the end of the base ACPI_DEVICE_INFO structure. 573 */ 574 NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids); 575 if (CidList) 576 { 577 /* Point past the CID PNP_DEVICE_ID array */ 578 579 NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID)); 580 } 581 582 /* 583 * Copy the HID, UID, and CIDs to the return buffer. The variable-length 584 * strings are copied to the reserved area at the end of the buffer. 585 * 586 * For HID and CID, check if the ID is a PCI Root Bridge. 587 */ 588 if (Hid) 589 { 590 NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId, 591 Hid, NextIdString); 592 593 if (AcpiUtIsPciRootBridge (Hid->String)) 594 { 595 Info->Flags |= ACPI_PCI_ROOT_BRIDGE; 596 } 597 } 598 599 if (Uid) 600 { 601 NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId, 602 Uid, NextIdString); 603 } 604 605 if (CidList) 606 { 607 Info->CompatibleIdList.Count = CidList->Count; 608 Info->CompatibleIdList.ListSize = CidList->ListSize; 609 610 /* Copy each CID */ 611 612 for (i = 0; i < CidList->Count; i++) 613 { 614 NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i], 615 &CidList->Ids[i], NextIdString); 616 617 if (AcpiUtIsPciRootBridge (CidList->Ids[i].String)) 618 { 619 Info->Flags |= ACPI_PCI_ROOT_BRIDGE; 620 } 621 } 622 } 623 624 if (Cls) 625 { 626 NextIdString = AcpiNsCopyDeviceId (&Info->ClassCode, 627 Cls, NextIdString); 628 } 629 630 /* Copy the fixed-length data */ 631 632 Info->InfoSize = InfoSize; 633 Info->Type = Type; 634 Info->Name = Name; 635 Info->ParamCount = ParamCount; 636 Info->Valid = Valid; 637 638 *ReturnBuffer = Info; 639 Status = AE_OK; 640 641 642 Cleanup: 643 if (Hid) 644 { 645 ACPI_FREE (Hid); 646 } 647 if (Uid) 648 { 649 ACPI_FREE (Uid); 650 } 651 if (CidList) 652 { 653 ACPI_FREE (CidList); 654 } 655 if (Cls) 656 { 657 ACPI_FREE (Cls); 658 } 659 return (Status); 660 } 661 662 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo) 663 664 665 /****************************************************************************** 666 * 667 * FUNCTION: AcpiInstallMethod 668 * 669 * PARAMETERS: Buffer - An ACPI table containing one control method 670 * 671 * RETURN: Status 672 * 673 * DESCRIPTION: Install a control method into the namespace. If the method 674 * name already exists in the namespace, it is overwritten. The 675 * input buffer must contain a valid DSDT or SSDT containing a 676 * single control method. 677 * 678 ******************************************************************************/ 679 680 ACPI_STATUS 681 AcpiInstallMethod ( 682 UINT8 *Buffer) 683 { 684 ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer); 685 UINT8 *AmlBuffer; 686 UINT8 *AmlStart; 687 char *Path; 688 ACPI_NAMESPACE_NODE *Node; 689 ACPI_OPERAND_OBJECT *MethodObj; 690 ACPI_PARSE_STATE ParserState; 691 UINT32 AmlLength; 692 UINT16 Opcode; 693 UINT8 MethodFlags; 694 ACPI_STATUS Status; 695 696 697 /* Parameter validation */ 698 699 if (!Buffer) 700 { 701 return (AE_BAD_PARAMETER); 702 } 703 704 /* Table must be a DSDT or SSDT */ 705 706 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) && 707 !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT)) 708 { 709 return (AE_BAD_HEADER); 710 } 711 712 /* First AML opcode in the table must be a control method */ 713 714 ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER); 715 Opcode = AcpiPsPeekOpcode (&ParserState); 716 if (Opcode != AML_METHOD_OP) 717 { 718 return (AE_BAD_PARAMETER); 719 } 720 721 /* Extract method information from the raw AML */ 722 723 ParserState.Aml += AcpiPsGetOpcodeSize (Opcode); 724 ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState); 725 Path = AcpiPsGetNextNamestring (&ParserState); 726 727 MethodFlags = *ParserState.Aml++; 728 AmlStart = ParserState.Aml; 729 AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart); 730 731 /* 732 * Allocate resources up-front. We don't want to have to delete a new 733 * node from the namespace if we cannot allocate memory. 734 */ 735 AmlBuffer = ACPI_ALLOCATE (AmlLength); 736 if (!AmlBuffer) 737 { 738 return (AE_NO_MEMORY); 739 } 740 741 MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD); 742 if (!MethodObj) 743 { 744 ACPI_FREE (AmlBuffer); 745 return (AE_NO_MEMORY); 746 } 747 748 /* Lock namespace for AcpiNsLookup, we may be creating a new node */ 749 750 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 751 if (ACPI_FAILURE (Status)) 752 { 753 goto ErrorExit; 754 } 755 756 /* The lookup either returns an existing node or creates a new one */ 757 758 Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1, 759 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node); 760 761 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 762 763 if (ACPI_FAILURE (Status)) /* NsLookup */ 764 { 765 if (Status != AE_ALREADY_EXISTS) 766 { 767 goto ErrorExit; 768 } 769 770 /* Node existed previously, make sure it is a method node */ 771 772 if (Node->Type != ACPI_TYPE_METHOD) 773 { 774 Status = AE_TYPE; 775 goto ErrorExit; 776 } 777 } 778 779 /* Copy the method AML to the local buffer */ 780 781 memcpy (AmlBuffer, AmlStart, AmlLength); 782 783 /* Initialize the method object with the new method's information */ 784 785 MethodObj->Method.AmlStart = AmlBuffer; 786 MethodObj->Method.AmlLength = AmlLength; 787 788 MethodObj->Method.ParamCount = (UINT8) 789 (MethodFlags & AML_METHOD_ARG_COUNT); 790 791 if (MethodFlags & AML_METHOD_SERIALIZED) 792 { 793 MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED; 794 795 MethodObj->Method.SyncLevel = (UINT8) 796 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4); 797 } 798 799 /* 800 * Now that it is complete, we can attach the new method object to 801 * the method Node (detaches/deletes any existing object) 802 */ 803 Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD); 804 805 /* 806 * Flag indicates AML buffer is dynamic, must be deleted later. 807 * Must be set only after attach above. 808 */ 809 Node->Flags |= ANOBJ_ALLOCATED_BUFFER; 810 811 /* Remove local reference to the method object */ 812 813 AcpiUtRemoveReference (MethodObj); 814 return (Status); 815 816 817 ErrorExit: 818 819 ACPI_FREE (AmlBuffer); 820 ACPI_FREE (MethodObj); 821 return (Status); 822 } 823 824 ACPI_EXPORT_SYMBOL (AcpiInstallMethod) 825