1 /****************************************************************************** 2 * 3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes) 4 * $Revision: 1.113 $ 5 * 6 *****************************************************************************/ 7 8 /****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2008, 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 88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 90 * PARTICULAR PURPOSE. 91 * 92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 99 * LIMITED REMEDY. 100 * 101 * 4.3. Licensee shall not export, either directly or indirectly, any of this 102 * software or system incorporating such software without first obtaining any 103 * required license or other approval from the U. S. Department of Commerce or 104 * any other agency or department of the United States Government. In the 105 * event Licensee exports any such software from the United States or 106 * re-exports any such software from a foreign destination, Licensee shall 107 * ensure that the distribution and export/re-export of the software is in 108 * compliance with all laws, regulations, orders, or other restrictions of the 109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 110 * any of its subsidiaries will export/re-export any technical data, process, 111 * software, or service, directly or indirectly, to any country for which the 112 * United States government or any agency thereof requires an export license, 113 * other governmental approval, or letter of assurance, without first obtaining 114 * such license, approval or letter. 115 * 116 *****************************************************************************/ 117 118 #define __EXCONFIG_C__ 119 120 #include "acpi.h" 121 #include "acinterp.h" 122 #include "acnamesp.h" 123 #include "actables.h" 124 #include "acdispat.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 139 /******************************************************************************* 140 * 141 * FUNCTION: AcpiExAddTable 142 * 143 * PARAMETERS: Table - Pointer to raw table 144 * ParentNode - Where to load the table (scope) 145 * DdbHandle - Where to return the table handle. 146 * 147 * RETURN: Status 148 * 149 * DESCRIPTION: Common function to Install and Load an ACPI table with a 150 * returned table handle. 151 * 152 ******************************************************************************/ 153 154 static ACPI_STATUS 155 AcpiExAddTable ( 156 UINT32 TableIndex, 157 ACPI_NAMESPACE_NODE *ParentNode, 158 ACPI_OPERAND_OBJECT **DdbHandle) 159 { 160 ACPI_STATUS Status; 161 ACPI_OPERAND_OBJECT *ObjDesc; 162 163 164 ACPI_FUNCTION_TRACE (ExAddTable); 165 166 167 /* Create an object to be the table handle */ 168 169 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE); 170 if (!ObjDesc) 171 { 172 return_ACPI_STATUS (AE_NO_MEMORY); 173 } 174 175 /* Init the table handle */ 176 177 ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE; 178 *DdbHandle = ObjDesc; 179 180 /* Install the new table into the local data structures */ 181 182 ObjDesc->Reference.Value = TableIndex; 183 184 /* Add the table to the namespace */ 185 186 Status = AcpiNsLoadTable (TableIndex, ParentNode); 187 if (ACPI_FAILURE (Status)) 188 { 189 AcpiUtRemoveReference (ObjDesc); 190 *DdbHandle = NULL; 191 } 192 193 return_ACPI_STATUS (Status); 194 } 195 196 197 /******************************************************************************* 198 * 199 * FUNCTION: AcpiExLoadTableOp 200 * 201 * PARAMETERS: WalkState - Current state with operands 202 * ReturnDesc - Where to store the return object 203 * 204 * RETURN: Status 205 * 206 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT 207 * 208 ******************************************************************************/ 209 210 ACPI_STATUS 211 AcpiExLoadTableOp ( 212 ACPI_WALK_STATE *WalkState, 213 ACPI_OPERAND_OBJECT **ReturnDesc) 214 { 215 ACPI_STATUS Status; 216 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; 217 ACPI_NAMESPACE_NODE *ParentNode; 218 ACPI_NAMESPACE_NODE *StartNode; 219 ACPI_NAMESPACE_NODE *ParameterNode = NULL; 220 ACPI_OPERAND_OBJECT *DdbHandle; 221 ACPI_TABLE_HEADER *Table; 222 UINT32 TableIndex; 223 224 225 ACPI_FUNCTION_TRACE (ExLoadTableOp); 226 227 228 /* Validate lengths for the SignatureString, OEMIDString, OEMTableID */ 229 230 if ((Operand[0]->String.Length > ACPI_NAME_SIZE) || 231 (Operand[1]->String.Length > ACPI_OEM_ID_SIZE) || 232 (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE)) 233 { 234 return_ACPI_STATUS (AE_BAD_PARAMETER); 235 } 236 237 /* Find the ACPI table in the RSDT/XSDT */ 238 239 Status = AcpiTbFindTable (Operand[0]->String.Pointer, 240 Operand[1]->String.Pointer, 241 Operand[2]->String.Pointer, &TableIndex); 242 if (ACPI_FAILURE (Status)) 243 { 244 if (Status != AE_NOT_FOUND) 245 { 246 return_ACPI_STATUS (Status); 247 } 248 249 /* Table not found, return an Integer=0 and AE_OK */ 250 251 DdbHandle = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER); 252 if (!DdbHandle) 253 { 254 return_ACPI_STATUS (AE_NO_MEMORY); 255 } 256 257 DdbHandle->Integer.Value = 0; 258 *ReturnDesc = DdbHandle; 259 260 return_ACPI_STATUS (AE_OK); 261 } 262 263 /* Default nodes */ 264 265 StartNode = WalkState->ScopeInfo->Scope.Node; 266 ParentNode = AcpiGbl_RootNode; 267 268 /* RootPath (optional parameter) */ 269 270 if (Operand[3]->String.Length > 0) 271 { 272 /* 273 * Find the node referenced by the RootPathString. This is the 274 * location within the namespace where the table will be loaded. 275 */ 276 Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer, 277 ACPI_NS_SEARCH_PARENT, &ParentNode); 278 if (ACPI_FAILURE (Status)) 279 { 280 return_ACPI_STATUS (Status); 281 } 282 } 283 284 /* ParameterPath (optional parameter) */ 285 286 if (Operand[4]->String.Length > 0) 287 { 288 if ((Operand[4]->String.Pointer[0] != '\\') && 289 (Operand[4]->String.Pointer[0] != '^')) 290 { 291 /* 292 * Path is not absolute, so it will be relative to the node 293 * referenced by the RootPathString (or the NS root if omitted) 294 */ 295 StartNode = ParentNode; 296 } 297 298 /* Find the node referenced by the ParameterPathString */ 299 300 Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer, 301 ACPI_NS_SEARCH_PARENT, &ParameterNode); 302 if (ACPI_FAILURE (Status)) 303 { 304 return_ACPI_STATUS (Status); 305 } 306 } 307 308 /* Load the table into the namespace */ 309 310 Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle); 311 if (ACPI_FAILURE (Status)) 312 { 313 return_ACPI_STATUS (Status); 314 } 315 316 /* Parameter Data (optional) */ 317 318 if (ParameterNode) 319 { 320 /* Store the parameter data into the optional parameter object */ 321 322 Status = AcpiExStore (Operand[5], 323 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), 324 WalkState); 325 if (ACPI_FAILURE (Status)) 326 { 327 (void) AcpiExUnloadTable (DdbHandle); 328 return_ACPI_STATUS (Status); 329 } 330 } 331 332 Status = AcpiGetTableByIndex (TableIndex, &Table); 333 if (ACPI_SUCCESS (Status)) 334 { 335 ACPI_INFO ((AE_INFO, 336 "Dynamic OEM Table Load - [%.4s] OemId [%.6s] OemTableId [%.8s]", 337 Table->Signature, Table->OemId, Table->OemTableId)); 338 } 339 340 /* Invoke table handler if present */ 341 342 if (AcpiGbl_TableHandler) 343 { 344 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table, 345 AcpiGbl_TableHandlerContext); 346 } 347 348 *ReturnDesc = DdbHandle; 349 return_ACPI_STATUS (Status); 350 } 351 352 353 /******************************************************************************* 354 * 355 * FUNCTION: AcpiExLoadOp 356 * 357 * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be 358 * obtained 359 * Target - Where a handle to the table will be stored 360 * WalkState - Current state 361 * 362 * RETURN: Status 363 * 364 * DESCRIPTION: Load an ACPI table from a field or operation region 365 * 366 * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer 367 * objects before this code is reached. 368 * 369 * If source is an operation region, it must refer to SystemMemory, as 370 * per the ACPI specification. 371 * 372 ******************************************************************************/ 373 374 ACPI_STATUS 375 AcpiExLoadOp ( 376 ACPI_OPERAND_OBJECT *ObjDesc, 377 ACPI_OPERAND_OBJECT *Target, 378 ACPI_WALK_STATE *WalkState) 379 { 380 ACPI_OPERAND_OBJECT *DdbHandle; 381 ACPI_TABLE_HEADER *Table; 382 ACPI_TABLE_DESC TableDesc; 383 UINT32 TableIndex; 384 ACPI_STATUS Status; 385 UINT32 Length; 386 387 388 ACPI_FUNCTION_TRACE (ExLoadOp); 389 390 391 ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC)); 392 393 /* Source Object can be either an OpRegion or a Buffer/Field */ 394 395 switch (ACPI_GET_OBJECT_TYPE (ObjDesc)) 396 { 397 case ACPI_TYPE_REGION: 398 399 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 400 "Load table from Region %p\n", ObjDesc)); 401 402 /* Region must be SystemMemory (from ACPI spec) */ 403 404 if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) 405 { 406 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 407 } 408 409 /* 410 * If the Region Address and Length have not been previously evaluated, 411 * evaluate them now and save the results. 412 */ 413 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)) 414 { 415 Status = AcpiDsGetRegionArguments (ObjDesc); 416 if (ACPI_FAILURE (Status)) 417 { 418 return_ACPI_STATUS (Status); 419 } 420 } 421 422 /* 423 * Map the table header and get the actual table length. The region 424 * length is not guaranteed to be the same as the table length. 425 */ 426 Table = AcpiOsMapMemory (ObjDesc->Region.Address, 427 sizeof (ACPI_TABLE_HEADER)); 428 if (!Table) 429 { 430 return_ACPI_STATUS (AE_NO_MEMORY); 431 } 432 433 Length = Table->Length; 434 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER)); 435 436 /* Must have at least an ACPI table header */ 437 438 if (Length < sizeof (ACPI_TABLE_HEADER)) 439 { 440 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 441 } 442 443 /* 444 * The memory region is not guaranteed to remain stable and we must 445 * copy the table to a local buffer. For example, the memory region 446 * is corrupted after suspend on some machines. Dynamically loaded 447 * tables are usually small, so this overhead is minimal. 448 */ 449 450 /* Allocate a buffer for the table */ 451 452 TableDesc.Pointer = ACPI_ALLOCATE (Length); 453 if (!TableDesc.Pointer) 454 { 455 return_ACPI_STATUS (AE_NO_MEMORY); 456 } 457 458 /* Map the entire table and copy it */ 459 460 Table = AcpiOsMapMemory (ObjDesc->Region.Address, Length); 461 if (!Table) 462 { 463 ACPI_FREE (TableDesc.Pointer); 464 return_ACPI_STATUS (AE_NO_MEMORY); 465 } 466 467 ACPI_MEMCPY (TableDesc.Pointer, Table, Length); 468 AcpiOsUnmapMemory (Table, Length); 469 470 TableDesc.Address = ObjDesc->Region.Address; 471 break; 472 473 474 case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */ 475 476 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 477 "Load table from Buffer or Field %p\n", ObjDesc)); 478 479 /* Must have at least an ACPI table header */ 480 481 if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER)) 482 { 483 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 484 } 485 486 /* Get the actual table length from the table header */ 487 488 Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer); 489 Length = Table->Length; 490 491 /* Table cannot extend beyond the buffer */ 492 493 if (Length > ObjDesc->Buffer.Length) 494 { 495 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); 496 } 497 if (Length < sizeof (ACPI_TABLE_HEADER)) 498 { 499 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 500 } 501 502 /* 503 * Copy the table from the buffer because the buffer could be modified 504 * or even deleted in the future 505 */ 506 TableDesc.Pointer = ACPI_ALLOCATE (Length); 507 if (!TableDesc.Pointer) 508 { 509 return_ACPI_STATUS (AE_NO_MEMORY); 510 } 511 512 ACPI_MEMCPY (TableDesc.Pointer, Table, Length); 513 TableDesc.Address = ACPI_TO_INTEGER (TableDesc.Pointer); 514 break; 515 516 517 default: 518 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 519 } 520 521 /* Validate table checksum (will not get validated in TbAddTable) */ 522 523 Status = AcpiTbVerifyChecksum (TableDesc.Pointer, Length); 524 if (ACPI_FAILURE (Status)) 525 { 526 ACPI_FREE (TableDesc.Pointer); 527 return_ACPI_STATUS (Status); 528 } 529 530 /* Complete the table descriptor */ 531 532 TableDesc.Length = Length; 533 TableDesc.Flags = ACPI_TABLE_ORIGIN_ALLOCATED; 534 535 /* Install the new table into the local data structures */ 536 537 Status = AcpiTbAddTable (&TableDesc, &TableIndex); 538 if (ACPI_FAILURE (Status)) 539 { 540 goto Cleanup; 541 } 542 543 /* 544 * Add the table to the namespace. 545 * 546 * Note: Load the table objects relative to the root of the namespace. 547 * This appears to go against the ACPI specification, but we do it for 548 * compatibility with other ACPI implementations. 549 */ 550 Status = AcpiExAddTable (TableIndex, AcpiGbl_RootNode, &DdbHandle); 551 if (ACPI_FAILURE (Status)) 552 { 553 /* On error, TablePtr was deallocated above */ 554 555 return_ACPI_STATUS (Status); 556 } 557 558 /* Store the DdbHandle into the Target operand */ 559 560 Status = AcpiExStore (DdbHandle, Target, WalkState); 561 if (ACPI_FAILURE (Status)) 562 { 563 (void) AcpiExUnloadTable (DdbHandle); 564 565 /* TablePtr was deallocated above */ 566 567 AcpiUtRemoveReference (DdbHandle); 568 return_ACPI_STATUS (Status); 569 } 570 571 /* Invoke table handler if present */ 572 573 if (AcpiGbl_TableHandler) 574 { 575 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, TableDesc.Pointer, 576 AcpiGbl_TableHandlerContext); 577 } 578 579 Cleanup: 580 if (ACPI_FAILURE (Status)) 581 { 582 /* Delete allocated table buffer */ 583 584 AcpiTbDeleteTable (&TableDesc); 585 } 586 return_ACPI_STATUS (Status); 587 } 588 589 590 /******************************************************************************* 591 * 592 * FUNCTION: AcpiExUnloadTable 593 * 594 * PARAMETERS: DdbHandle - Handle to a previously loaded table 595 * 596 * RETURN: Status 597 * 598 * DESCRIPTION: Unload an ACPI table 599 * 600 ******************************************************************************/ 601 602 ACPI_STATUS 603 AcpiExUnloadTable ( 604 ACPI_OPERAND_OBJECT *DdbHandle) 605 { 606 ACPI_STATUS Status = AE_OK; 607 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle; 608 UINT32 TableIndex; 609 ACPI_TABLE_HEADER *Table; 610 611 612 ACPI_FUNCTION_TRACE (ExUnloadTable); 613 614 615 /* 616 * Validate the handle 617 * Although the handle is partially validated in AcpiExReconfiguration(), 618 * when it calls AcpiExResolveOperands(), the handle is more completely 619 * validated here. 620 */ 621 if ((!DdbHandle) || 622 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) || 623 (ACPI_GET_OBJECT_TYPE (DdbHandle) != ACPI_TYPE_LOCAL_REFERENCE)) 624 { 625 return_ACPI_STATUS (AE_BAD_PARAMETER); 626 } 627 628 /* Get the table index from the DdbHandle */ 629 630 TableIndex = TableDesc->Reference.Value; 631 632 /* Invoke table handler if present */ 633 634 if (AcpiGbl_TableHandler) 635 { 636 Status = AcpiGetTableByIndex (TableIndex, &Table); 637 if (ACPI_SUCCESS (Status)) 638 { 639 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, Table, 640 AcpiGbl_TableHandlerContext); 641 } 642 } 643 644 /* 645 * Delete the entire namespace under this table Node 646 * (Offset contains the TableId) 647 */ 648 AcpiTbDeleteNamespaceByOwner (TableIndex); 649 (void) AcpiTbReleaseOwnerId (TableIndex); 650 651 AcpiTbSetTableLoadedFlag (TableIndex, FALSE); 652 653 /* Table unloaded, remove a reference to the DdbHandle object */ 654 655 AcpiUtRemoveReference (DdbHandle); 656 return_ACPI_STATUS (AE_OK); 657 } 658 659