1 /****************************************************************************** 2 * 3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes) 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 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 #include "acpi.h" 118 #include "accommon.h" 119 #include "acinterp.h" 120 #include "acnamesp.h" 121 #include "actables.h" 122 #include "acdispat.h" 123 #include "acevents.h" 124 #include "amlcode.h" 125 126 127 #define _COMPONENT ACPI_EXECUTER 128 ACPI_MODULE_NAME ("exconfig") 129 130 /* Local prototypes */ 131 132 static ACPI_STATUS 133 AcpiExAddTable ( 134 UINT32 TableIndex, 135 ACPI_NAMESPACE_NODE *ParentNode, 136 ACPI_OPERAND_OBJECT **DdbHandle); 137 138 static ACPI_STATUS 139 AcpiExRegionRead ( 140 ACPI_OPERAND_OBJECT *ObjDesc, 141 UINT32 Length, 142 UINT8 *Buffer); 143 144 145 /******************************************************************************* 146 * 147 * FUNCTION: AcpiExAddTable 148 * 149 * PARAMETERS: Table - Pointer to raw table 150 * ParentNode - Where to load the table (scope) 151 * DdbHandle - Where to return the table handle. 152 * 153 * RETURN: Status 154 * 155 * DESCRIPTION: Common function to Install and Load an ACPI table with a 156 * returned table handle. 157 * 158 ******************************************************************************/ 159 160 static ACPI_STATUS 161 AcpiExAddTable ( 162 UINT32 TableIndex, 163 ACPI_NAMESPACE_NODE *ParentNode, 164 ACPI_OPERAND_OBJECT **DdbHandle) 165 { 166 ACPI_OPERAND_OBJECT *ObjDesc; 167 ACPI_STATUS Status; 168 ACPI_OWNER_ID OwnerId; 169 170 171 ACPI_FUNCTION_TRACE (ExAddTable); 172 173 174 /* Create an object to be the table handle */ 175 176 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE); 177 if (!ObjDesc) 178 { 179 return_ACPI_STATUS (AE_NO_MEMORY); 180 } 181 182 /* Init the table handle */ 183 184 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID; 185 ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE; 186 *DdbHandle = ObjDesc; 187 188 /* Install the new table into the local data structures */ 189 190 ObjDesc->Reference.Value = TableIndex; 191 192 /* Add the table to the namespace */ 193 194 Status = AcpiNsLoadTable (TableIndex, ParentNode); 195 if (ACPI_FAILURE (Status)) 196 { 197 AcpiUtRemoveReference (ObjDesc); 198 *DdbHandle = NULL; 199 return_ACPI_STATUS (Status); 200 } 201 202 /* Execute any module-level code that was found in the table */ 203 204 AcpiExExitInterpreter (); 205 AcpiNsExecModuleCodeList (); 206 AcpiExEnterInterpreter (); 207 208 /* 209 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is 210 * responsible for discovering any new wake GPEs by running _PRW methods 211 * that may have been loaded by this table. 212 */ 213 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId); 214 if (ACPI_SUCCESS (Status)) 215 { 216 AcpiEvUpdateGpes (OwnerId); 217 } 218 219 return_ACPI_STATUS (AE_OK); 220 } 221 222 223 /******************************************************************************* 224 * 225 * FUNCTION: AcpiExLoadTableOp 226 * 227 * PARAMETERS: WalkState - Current state with operands 228 * ReturnDesc - Where to store the return object 229 * 230 * RETURN: Status 231 * 232 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT 233 * 234 ******************************************************************************/ 235 236 ACPI_STATUS 237 AcpiExLoadTableOp ( 238 ACPI_WALK_STATE *WalkState, 239 ACPI_OPERAND_OBJECT **ReturnDesc) 240 { 241 ACPI_STATUS Status; 242 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; 243 ACPI_NAMESPACE_NODE *ParentNode; 244 ACPI_NAMESPACE_NODE *StartNode; 245 ACPI_NAMESPACE_NODE *ParameterNode = NULL; 246 ACPI_OPERAND_OBJECT *DdbHandle; 247 ACPI_TABLE_HEADER *Table; 248 UINT32 TableIndex; 249 250 251 ACPI_FUNCTION_TRACE (ExLoadTableOp); 252 253 254 /* Find the ACPI table in the RSDT/XSDT */ 255 256 Status = AcpiTbFindTable ( 257 Operand[0]->String.Pointer, 258 Operand[1]->String.Pointer, 259 Operand[2]->String.Pointer, &TableIndex); 260 if (ACPI_FAILURE (Status)) 261 { 262 if (Status != AE_NOT_FOUND) 263 { 264 return_ACPI_STATUS (Status); 265 } 266 267 /* Table not found, return an Integer=0 and AE_OK */ 268 269 DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0); 270 if (!DdbHandle) 271 { 272 return_ACPI_STATUS (AE_NO_MEMORY); 273 } 274 275 *ReturnDesc = DdbHandle; 276 return_ACPI_STATUS (AE_OK); 277 } 278 279 /* Default nodes */ 280 281 StartNode = WalkState->ScopeInfo->Scope.Node; 282 ParentNode = AcpiGbl_RootNode; 283 284 /* RootPath (optional parameter) */ 285 286 if (Operand[3]->String.Length > 0) 287 { 288 /* 289 * Find the node referenced by the RootPathString. This is the 290 * location within the namespace where the table will be loaded. 291 */ 292 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer, 293 ACPI_NS_SEARCH_PARENT, &ParentNode); 294 if (ACPI_FAILURE (Status)) 295 { 296 return_ACPI_STATUS (Status); 297 } 298 } 299 300 /* ParameterPath (optional parameter) */ 301 302 if (Operand[4]->String.Length > 0) 303 { 304 if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) && 305 (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX)) 306 { 307 /* 308 * Path is not absolute, so it will be relative to the node 309 * referenced by the RootPathString (or the NS root if omitted) 310 */ 311 StartNode = ParentNode; 312 } 313 314 /* Find the node referenced by the ParameterPathString */ 315 316 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer, 317 ACPI_NS_SEARCH_PARENT, &ParameterNode); 318 if (ACPI_FAILURE (Status)) 319 { 320 return_ACPI_STATUS (Status); 321 } 322 } 323 324 /* Load the table into the namespace */ 325 326 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle); 327 if (ACPI_FAILURE (Status)) 328 { 329 return_ACPI_STATUS (Status); 330 } 331 332 /* Parameter Data (optional) */ 333 334 if (ParameterNode) 335 { 336 /* Store the parameter data into the optional parameter object */ 337 338 Status = AcpiExStore (Operand[5], 339 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState); 340 if (ACPI_FAILURE (Status)) 341 { 342 (void) AcpiExUnloadTable (DdbHandle); 343 344 AcpiUtRemoveReference (DdbHandle); 345 return_ACPI_STATUS (Status); 346 } 347 } 348 349 Status = AcpiGetTableByIndex (TableIndex, &Table); 350 if (ACPI_SUCCESS (Status)) 351 { 352 ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:")); 353 AcpiTbPrintTableHeader (0, Table); 354 } 355 356 /* Invoke table handler if present */ 357 358 if (AcpiGbl_TableHandler) 359 { 360 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table, 361 AcpiGbl_TableHandlerContext); 362 } 363 364 *ReturnDesc = DdbHandle; 365 return_ACPI_STATUS (Status); 366 } 367 368 369 /******************************************************************************* 370 * 371 * FUNCTION: AcpiExRegionRead 372 * 373 * PARAMETERS: ObjDesc - Region descriptor 374 * Length - Number of bytes to read 375 * Buffer - Pointer to where to put the data 376 * 377 * RETURN: Status 378 * 379 * DESCRIPTION: Read data from an operation region. The read starts from the 380 * beginning of the region. 381 * 382 ******************************************************************************/ 383 384 static ACPI_STATUS 385 AcpiExRegionRead ( 386 ACPI_OPERAND_OBJECT *ObjDesc, 387 UINT32 Length, 388 UINT8 *Buffer) 389 { 390 ACPI_STATUS Status; 391 UINT64 Value; 392 UINT32 RegionOffset = 0; 393 UINT32 i; 394 395 396 /* Bytewise reads */ 397 398 for (i = 0; i < Length; i++) 399 { 400 Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ, 401 RegionOffset, 8, &Value); 402 if (ACPI_FAILURE (Status)) 403 { 404 return (Status); 405 } 406 407 *Buffer = (UINT8) Value; 408 Buffer++; 409 RegionOffset++; 410 } 411 412 return (AE_OK); 413 } 414 415 416 /******************************************************************************* 417 * 418 * FUNCTION: AcpiExLoadOp 419 * 420 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be 421 * obtained 422 * Target - Where a handle to the table will be stored 423 * WalkState - Current state 424 * 425 * RETURN: Status 426 * 427 * DESCRIPTION: Load an ACPI table from a field or operation region 428 * 429 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer 430 * objects before this code is reached. 431 * 432 * If source is an operation region, it must refer to SystemMemory, as 433 * per the ACPI specification. 434 * 435 ******************************************************************************/ 436 437 ACPI_STATUS 438 AcpiExLoadOp ( 439 ACPI_OPERAND_OBJECT *ObjDesc, 440 ACPI_OPERAND_OBJECT *Target, 441 ACPI_WALK_STATE *WalkState) 442 { 443 ACPI_OPERAND_OBJECT *DdbHandle; 444 ACPI_TABLE_HEADER *TableHeader; 445 ACPI_TABLE_HEADER *Table; 446 UINT32 TableIndex; 447 ACPI_STATUS Status; 448 UINT32 Length; 449 450 451 ACPI_FUNCTION_TRACE (ExLoadOp); 452 453 454 /* Source Object can be either an OpRegion or a Buffer/Field */ 455 456 switch (ObjDesc->Common.Type) 457 { 458 case ACPI_TYPE_REGION: 459 460 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 461 "Load table from Region %p\n", ObjDesc)); 462 463 /* Region must be SystemMemory (from ACPI spec) */ 464 465 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) 466 { 467 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 468 } 469 470 /* 471 * If the Region Address and Length have not been previously 472 * evaluated, evaluate them now and save the results. 473 */ 474 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)) 475 { 476 Status = AcpiDsGetRegionArguments (ObjDesc); 477 if (ACPI_FAILURE (Status)) 478 { 479 return_ACPI_STATUS (Status); 480 } 481 } 482 483 /* Get the table header first so we can get the table length */ 484 485 TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER)); 486 if (!TableHeader) 487 { 488 return_ACPI_STATUS (AE_NO_MEMORY); 489 } 490 491 Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER), 492 ACPI_CAST_PTR (UINT8, TableHeader)); 493 Length = TableHeader->Length; 494 ACPI_FREE (TableHeader); 495 496 if (ACPI_FAILURE (Status)) 497 { 498 return_ACPI_STATUS (Status); 499 } 500 501 /* Must have at least an ACPI table header */ 502 503 if (Length < sizeof (ACPI_TABLE_HEADER)) 504 { 505 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 506 } 507 508 /* 509 * The original implementation simply mapped the table, with no copy. 510 * However, the memory region is not guaranteed to remain stable and 511 * we must copy the table to a local buffer. For example, the memory 512 * region is corrupted after suspend on some machines. Dynamically 513 * loaded tables are usually small, so this overhead is minimal. 514 * 515 * The latest implementation (5/2009) does not use a mapping at all. 516 * We use the low-level operation region interface to read the table 517 * instead of the obvious optimization of using a direct mapping. 518 * This maintains a consistent use of operation regions across the 519 * entire subsystem. This is important if additional processing must 520 * be performed in the (possibly user-installed) operation region 521 * handler. For example, AcpiExec and ASLTS depend on this. 522 */ 523 524 /* Allocate a buffer for the table */ 525 526 Table = ACPI_ALLOCATE (Length); 527 if (!Table) 528 { 529 return_ACPI_STATUS (AE_NO_MEMORY); 530 } 531 532 /* Read the entire table */ 533 534 Status = AcpiExRegionRead (ObjDesc, Length, 535 ACPI_CAST_PTR (UINT8, Table)); 536 if (ACPI_FAILURE (Status)) 537 { 538 ACPI_FREE (Table); 539 return_ACPI_STATUS (Status); 540 } 541 break; 542 543 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */ 544 545 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 546 "Load table from Buffer or Field %p\n", ObjDesc)); 547 548 /* Must have at least an ACPI table header */ 549 550 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER)) 551 { 552 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 553 } 554 555 /* Get the actual table length from the table header */ 556 557 TableHeader = ACPI_CAST_PTR ( 558 ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer); 559 Length = TableHeader->Length; 560 561 /* Table cannot extend beyond the buffer */ 562 563 if (Length > ObjDesc->Buffer.Length) 564 { 565 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); 566 } 567 if (Length < sizeof (ACPI_TABLE_HEADER)) 568 { 569 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 570 } 571 572 /* 573 * Copy the table from the buffer because the buffer could be 574 * modified or even deleted in the future 575 */ 576 Table = ACPI_ALLOCATE (Length); 577 if (!Table) 578 { 579 return_ACPI_STATUS (AE_NO_MEMORY); 580 } 581 582 memcpy (Table, TableHeader, Length); 583 break; 584 585 default: 586 587 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 588 } 589 590 /* Install the new table into the local data structures */ 591 592 ACPI_INFO ((AE_INFO, "Dynamic OEM Table Load:")); 593 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 594 595 Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table), 596 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, TRUE, 597 &TableIndex); 598 599 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 600 if (ACPI_FAILURE (Status)) 601 { 602 /* Delete allocated table buffer */ 603 604 ACPI_FREE (Table); 605 return_ACPI_STATUS (Status); 606 } 607 608 /* 609 * Note: Now table is "INSTALLED", it must be validated before 610 * loading. 611 */ 612 Status = AcpiTbValidateTable ( 613 &AcpiGbl_RootTableList.Tables[TableIndex]); 614 if (ACPI_FAILURE (Status)) 615 { 616 return_ACPI_STATUS (Status); 617 } 618 619 /* 620 * Add the table to the namespace. 621 * 622 * Note: Load the table objects relative to the root of the namespace. 623 * This appears to go against the ACPI specification, but we do it for 624 * compatibility with other ACPI implementations. 625 */ 626 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle); 627 if (ACPI_FAILURE (Status)) 628 { 629 /* On error, TablePtr was deallocated above */ 630 631 return_ACPI_STATUS (Status); 632 } 633 634 /* Store the DdbHandle into the Target operand */ 635 636 Status = AcpiExStore (DdbHandle, Target, WalkState); 637 if (ACPI_FAILURE (Status)) 638 { 639 (void) AcpiExUnloadTable (DdbHandle); 640 641 /* TablePtr was deallocated above */ 642 643 AcpiUtRemoveReference (DdbHandle); 644 return_ACPI_STATUS (Status); 645 } 646 647 /* Remove the reference by added by AcpiExStore above */ 648 649 AcpiUtRemoveReference (DdbHandle); 650 651 /* Invoke table handler if present */ 652 653 if (AcpiGbl_TableHandler) 654 { 655 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table, 656 AcpiGbl_TableHandlerContext); 657 } 658 659 return_ACPI_STATUS (Status); 660 } 661 662 663 /******************************************************************************* 664 * 665 * FUNCTION: AcpiExUnloadTable 666 * 667 * PARAMETERS: DdbHandle - Handle to a previously loaded table 668 * 669 * RETURN: Status 670 * 671 * DESCRIPTION: Unload an ACPI table 672 * 673 ******************************************************************************/ 674 675 ACPI_STATUS 676 AcpiExUnloadTable ( 677 ACPI_OPERAND_OBJECT *DdbHandle) 678 { 679 ACPI_STATUS Status = AE_OK; 680 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle; 681 UINT32 TableIndex; 682 ACPI_TABLE_HEADER *Table; 683 684 685 ACPI_FUNCTION_TRACE (ExUnloadTable); 686 687 688 /* 689 * Temporarily emit a warning so that the ASL for the machine can be 690 * hopefully obtained. This is to say that the Unload() operator is 691 * extremely rare if not completely unused. 692 */ 693 ACPI_WARNING ((AE_INFO, 694 "Received request to unload an ACPI table")); 695 696 /* 697 * Validate the handle 698 * Although the handle is partially validated in AcpiExReconfiguration() 699 * when it calls AcpiExResolveOperands(), the handle is more completely 700 * validated here. 701 * 702 * Handle must be a valid operand object of type reference. Also, the 703 * DdbHandle must still be marked valid (table has not been previously 704 * unloaded) 705 */ 706 if ((!DdbHandle) || 707 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) || 708 (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) || 709 (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID))) 710 { 711 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 712 } 713 714 /* Get the table index from the DdbHandle */ 715 716 TableIndex = TableDesc->Reference.Value; 717 718 /* Ensure the table is still loaded */ 719 720 if (!AcpiTbIsTableLoaded (TableIndex)) 721 { 722 return_ACPI_STATUS (AE_NOT_EXIST); 723 } 724 725 /* Invoke table handler if present */ 726 727 if (AcpiGbl_TableHandler) 728 { 729 Status = AcpiGetTableByIndex (TableIndex, &Table); 730 if (ACPI_SUCCESS (Status)) 731 { 732 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table, 733 AcpiGbl_TableHandlerContext); 734 } 735 } 736 737 /* Delete the portion of the namespace owned by this table */ 738 739 Status = AcpiTbDeleteNamespaceByOwner (TableIndex); 740 if (ACPI_FAILURE (Status)) 741 { 742 return_ACPI_STATUS (Status); 743 } 744 745 (void) AcpiTbReleaseOwnerId (TableIndex); 746 AcpiTbSetTableLoadedFlag (TableIndex, FALSE); 747 748 /* 749 * Invalidate the handle. We do this because the handle may be stored 750 * in a named object and may not be actually deleted until much later. 751 */ 752 DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID; 753 return_ACPI_STATUS (AE_OK); 754 } 755