exconfig.c revision 151937
1/****************************************************************************** 2 * 3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes) 4 * $Revision: 1.87 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2005, 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 <contrib/dev/acpica/acpi.h> 121#include <contrib/dev/acpica/acinterp.h> 122#include <contrib/dev/acpica/amlcode.h> 123#include <contrib/dev/acpica/acnamesp.h> 124#include <contrib/dev/acpica/acevents.h> 125#include <contrib/dev/acpica/actables.h> 126#include <contrib/dev/acpica/acdispat.h> 127 128 129#define _COMPONENT ACPI_EXECUTER 130 ACPI_MODULE_NAME ("exconfig") 131 132/* Local prototypes */ 133 134static ACPI_STATUS 135AcpiExAddTable ( 136 ACPI_TABLE_HEADER *Table, 137 ACPI_NAMESPACE_NODE *ParentNode, 138 ACPI_OPERAND_OBJECT **DdbHandle); 139 140 141/******************************************************************************* 142 * 143 * FUNCTION: AcpiExAddTable 144 * 145 * PARAMETERS: Table - Pointer to raw table 146 * ParentNode - Where to load the table (scope) 147 * DdbHandle - Where to return the table handle. 148 * 149 * RETURN: Status 150 * 151 * DESCRIPTION: Common function to Install and Load an ACPI table with a 152 * returned table handle. 153 * 154 ******************************************************************************/ 155 156static ACPI_STATUS 157AcpiExAddTable ( 158 ACPI_TABLE_HEADER *Table, 159 ACPI_NAMESPACE_NODE *ParentNode, 160 ACPI_OPERAND_OBJECT **DdbHandle) 161{ 162 ACPI_STATUS Status; 163 ACPI_TABLE_DESC TableInfo; 164 ACPI_OPERAND_OBJECT *ObjDesc; 165 166 167 ACPI_FUNCTION_TRACE ("ExAddTable"); 168 169 170 /* Create an object to be the table handle */ 171 172 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE); 173 if (!ObjDesc) 174 { 175 return_ACPI_STATUS (AE_NO_MEMORY); 176 } 177 178 /* Init the table handle */ 179 180 ObjDesc->Reference.Opcode = AML_LOAD_OP; 181 *DdbHandle = ObjDesc; 182 183 /* Install the new table into the local data structures */ 184 185 ACPI_MEMSET (&TableInfo, 0, sizeof (ACPI_TABLE_DESC)); 186 187 TableInfo.Type = ACPI_TABLE_SSDT; 188 TableInfo.Pointer = Table; 189 TableInfo.Length = (ACPI_SIZE) Table->Length; 190 TableInfo.Allocation = ACPI_MEM_ALLOCATED; 191 192 Status = AcpiTbInstallTable (&TableInfo); 193 ObjDesc->Reference.Object = TableInfo.InstalledDesc; 194 195 if (ACPI_FAILURE (Status)) 196 { 197 if (Status == AE_ALREADY_EXISTS) 198 { 199 /* Table already exists, just return the handle */ 200 201 return_ACPI_STATUS (AE_OK); 202 } 203 goto Cleanup; 204 } 205 206 /* Add the table to the namespace */ 207 208 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, ParentNode); 209 if (ACPI_FAILURE (Status)) 210 { 211 /* Uninstall table on error */ 212 213 (void) AcpiTbUninstallTable (TableInfo.InstalledDesc); 214 goto Cleanup; 215 } 216 217 return_ACPI_STATUS (AE_OK); 218 219 220Cleanup: 221 AcpiUtRemoveReference (ObjDesc); 222 *DdbHandle = NULL; 223 return_ACPI_STATUS (Status); 224} 225 226 227/******************************************************************************* 228 * 229 * FUNCTION: AcpiExLoadTableOp 230 * 231 * PARAMETERS: WalkState - Current state with operands 232 * ReturnDesc - Where to store the return object 233 * 234 * RETURN: Status 235 * 236 * DESCRIPTION: Load an ACPI table 237 * 238 ******************************************************************************/ 239 240ACPI_STATUS 241AcpiExLoadTableOp ( 242 ACPI_WALK_STATE *WalkState, 243 ACPI_OPERAND_OBJECT **ReturnDesc) 244{ 245 ACPI_STATUS Status; 246 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; 247 ACPI_TABLE_HEADER *Table; 248 ACPI_NAMESPACE_NODE *ParentNode; 249 ACPI_NAMESPACE_NODE *StartNode; 250 ACPI_NAMESPACE_NODE *ParameterNode = NULL; 251 ACPI_OPERAND_OBJECT *DdbHandle; 252 253 254 ACPI_FUNCTION_TRACE ("ExLoadTableOp"); 255 256 257#if 0 258 /* 259 * Make sure that the signature does not match one of the tables that 260 * is already loaded. 261 */ 262 Status = AcpiTbMatchSignature (Operand[0]->String.Pointer, NULL); 263 if (Status == AE_OK) 264 { 265 /* Signature matched -- don't allow override */ 266 267 return_ACPI_STATUS (AE_ALREADY_EXISTS); 268 } 269#endif 270 271 /* Find the ACPI table */ 272 273 Status = AcpiTbFindTable (Operand[0]->String.Pointer, 274 Operand[1]->String.Pointer, 275 Operand[2]->String.Pointer, &Table); 276 if (ACPI_FAILURE (Status)) 277 { 278 if (Status != AE_NOT_FOUND) 279 { 280 return_ACPI_STATUS (Status); 281 } 282 283 /* Table not found, return an Integer=0 and AE_OK */ 284 285 DdbHandle = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER); 286 if (!DdbHandle) 287 { 288 return_ACPI_STATUS (AE_NO_MEMORY); 289 } 290 291 DdbHandle->Integer.Value = 0; 292 *ReturnDesc = DdbHandle; 293 294 return_ACPI_STATUS (AE_OK); 295 } 296 297 /* Default nodes */ 298 299 StartNode = WalkState->ScopeInfo->Scope.Node; 300 ParentNode = AcpiGbl_RootNode; 301 302 /* RootPath (optional parameter) */ 303 304 if (Operand[3]->String.Length > 0) 305 { 306 /* 307 * Find the node referenced by the RootPathString. This is the 308 * location within the namespace where the table will be loaded. 309 */ 310 Status = AcpiNsGetNodeByPath (Operand[3]->String.Pointer, StartNode, 311 ACPI_NS_SEARCH_PARENT, &ParentNode); 312 if (ACPI_FAILURE (Status)) 313 { 314 return_ACPI_STATUS (Status); 315 } 316 } 317 318 /* ParameterPath (optional parameter) */ 319 320 if (Operand[4]->String.Length > 0) 321 { 322 if ((Operand[4]->String.Pointer[0] != '\\') && 323 (Operand[4]->String.Pointer[0] != '^')) 324 { 325 /* 326 * Path is not absolute, so it will be relative to the node 327 * referenced by the RootPathString (or the NS root if omitted) 328 */ 329 StartNode = ParentNode; 330 } 331 332 /* Find the node referenced by the ParameterPathString */ 333 334 Status = AcpiNsGetNodeByPath (Operand[4]->String.Pointer, StartNode, 335 ACPI_NS_SEARCH_PARENT, &ParameterNode); 336 if (ACPI_FAILURE (Status)) 337 { 338 return_ACPI_STATUS (Status); 339 } 340 } 341 342 /* Load the table into the namespace */ 343 344 Status = AcpiExAddTable (Table, ParentNode, &DdbHandle); 345 if (ACPI_FAILURE (Status)) 346 { 347 return_ACPI_STATUS (Status); 348 } 349 350 /* Parameter Data (optional) */ 351 352 if (ParameterNode) 353 { 354 /* Store the parameter data into the optional parameter object */ 355 356 Status = AcpiExStore (Operand[5], 357 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), 358 WalkState); 359 if (ACPI_FAILURE (Status)) 360 { 361 (void) AcpiExUnloadTable (DdbHandle); 362 return_ACPI_STATUS (Status); 363 } 364 } 365 366 *ReturnDesc = DdbHandle; 367 return_ACPI_STATUS (Status); 368} 369 370 371/******************************************************************************* 372 * 373 * FUNCTION: AcpiExLoadOp 374 * 375 * PARAMETERS: ObjDesc - Region or Field where the table will be 376 * obtained 377 * Target - Where a handle to the table will be stored 378 * WalkState - Current state 379 * 380 * RETURN: Status 381 * 382 * DESCRIPTION: Load an ACPI table from a field or operation region 383 * 384 ******************************************************************************/ 385 386ACPI_STATUS 387AcpiExLoadOp ( 388 ACPI_OPERAND_OBJECT *ObjDesc, 389 ACPI_OPERAND_OBJECT *Target, 390 ACPI_WALK_STATE *WalkState) 391{ 392 ACPI_STATUS Status; 393 ACPI_OPERAND_OBJECT *DdbHandle; 394 ACPI_OPERAND_OBJECT *BufferDesc = NULL; 395 ACPI_TABLE_HEADER *TablePtr = NULL; 396 ACPI_PHYSICAL_ADDRESS Address; 397 ACPI_TABLE_HEADER TableHeader; 398 UINT32 i; 399 400 ACPI_FUNCTION_TRACE ("ExLoadOp"); 401 402 403 /* Object can be either an OpRegion or a Field */ 404 405 switch (ACPI_GET_OBJECT_TYPE (ObjDesc)) 406 { 407 case ACPI_TYPE_REGION: 408 409 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n", 410 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc))); 411 412 /* 413 * If the Region Address and Length have not been previously evaluated, 414 * evaluate them now and save the results. 415 */ 416 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)) 417 { 418 Status = AcpiDsGetRegionArguments (ObjDesc); 419 if (ACPI_FAILURE (Status)) 420 { 421 return_ACPI_STATUS (Status); 422 } 423 } 424 425 /* Get the base physical address of the region */ 426 427 Address = ObjDesc->Region.Address; 428 429 /* Get the table length from the table header */ 430 431 TableHeader.Length = 0; 432 for (i = 0; i < 8; i++) 433 { 434 Status = AcpiEvAddressSpaceDispatch (ObjDesc, ACPI_READ, 435 (ACPI_PHYSICAL_ADDRESS) (i + Address), 8, 436 ((UINT8 *) &TableHeader) + i); 437 if (ACPI_FAILURE (Status)) 438 { 439 return_ACPI_STATUS (Status); 440 } 441 } 442 443 /* Sanity check the table length */ 444 445 if (TableHeader.Length < sizeof (ACPI_TABLE_HEADER)) 446 { 447 return_ACPI_STATUS (AE_BAD_HEADER); 448 } 449 450 /* Allocate a buffer for the entire table */ 451 452 TablePtr = ACPI_MEM_ALLOCATE (TableHeader.Length); 453 if (!TablePtr) 454 { 455 return_ACPI_STATUS (AE_NO_MEMORY); 456 } 457 458 /* Get the entire table from the op region */ 459 460 for (i = 0; i < TableHeader.Length; i++) 461 { 462 Status = AcpiEvAddressSpaceDispatch (ObjDesc, ACPI_READ, 463 (ACPI_PHYSICAL_ADDRESS) (i + Address), 8, 464 ((UINT8 *) TablePtr + i)); 465 if (ACPI_FAILURE (Status)) 466 { 467 goto Cleanup; 468 } 469 } 470 break; 471 472 473 case ACPI_TYPE_LOCAL_REGION_FIELD: 474 case ACPI_TYPE_LOCAL_BANK_FIELD: 475 case ACPI_TYPE_LOCAL_INDEX_FIELD: 476 477 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Field %p %s\n", 478 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc))); 479 480 /* 481 * The length of the field must be at least as large as the table. 482 * Read the entire field and thus the entire table. Buffer is 483 * allocated during the read. 484 */ 485 Status = AcpiExReadDataFromField (WalkState, ObjDesc, &BufferDesc); 486 if (ACPI_FAILURE (Status)) 487 { 488 return_ACPI_STATUS (Status); 489 } 490 491 TablePtr = ACPI_CAST_PTR (ACPI_TABLE_HEADER, 492 BufferDesc->Buffer.Pointer); 493 494 /* All done with the BufferDesc, delete it */ 495 496 BufferDesc->Buffer.Pointer = NULL; 497 AcpiUtRemoveReference (BufferDesc); 498 499 /* Sanity check the table length */ 500 501 if (TablePtr->Length < sizeof (ACPI_TABLE_HEADER)) 502 { 503 Status = AE_BAD_HEADER; 504 goto Cleanup; 505 } 506 break; 507 508 509 default: 510 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 511 } 512 513 /* The table must be either an SSDT or a PSDT */ 514 515 if ((!ACPI_STRNCMP (TablePtr->Signature, 516 AcpiGbl_TableData[ACPI_TABLE_PSDT].Signature, 517 AcpiGbl_TableData[ACPI_TABLE_PSDT].SigLength)) && 518 (!ACPI_STRNCMP (TablePtr->Signature, 519 AcpiGbl_TableData[ACPI_TABLE_SSDT].Signature, 520 AcpiGbl_TableData[ACPI_TABLE_SSDT].SigLength))) 521 { 522 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 523 "Table has invalid signature [%4.4s], must be SSDT or PSDT\n", 524 TablePtr->Signature)); 525 Status = AE_BAD_SIGNATURE; 526 goto Cleanup; 527 } 528 529 /* Install the new table into the local data structures */ 530 531 Status = AcpiExAddTable (TablePtr, AcpiGbl_RootNode, &DdbHandle); 532 if (ACPI_FAILURE (Status)) 533 { 534 /* On error, TablePtr was deallocated above */ 535 536 return_ACPI_STATUS (Status); 537 } 538 539 /* Store the DdbHandle into the Target operand */ 540 541 Status = AcpiExStore (DdbHandle, Target, WalkState); 542 if (ACPI_FAILURE (Status)) 543 { 544 (void) AcpiExUnloadTable (DdbHandle); 545 546 /* TablePtr was deallocated above */ 547 548 return_ACPI_STATUS (Status); 549 } 550 551Cleanup: 552 if (ACPI_FAILURE (Status)) 553 { 554 ACPI_MEM_FREE (TablePtr); 555 } 556 return_ACPI_STATUS (Status); 557} 558 559 560/******************************************************************************* 561 * 562 * FUNCTION: AcpiExUnloadTable 563 * 564 * PARAMETERS: DdbHandle - Handle to a previously loaded table 565 * 566 * RETURN: Status 567 * 568 * DESCRIPTION: Unload an ACPI table 569 * 570 ******************************************************************************/ 571 572ACPI_STATUS 573AcpiExUnloadTable ( 574 ACPI_OPERAND_OBJECT *DdbHandle) 575{ 576 ACPI_STATUS Status = AE_OK; 577 ACPI_OPERAND_OBJECT *TableDesc = DdbHandle; 578 ACPI_TABLE_DESC *TableInfo; 579 580 581 ACPI_FUNCTION_TRACE ("ExUnloadTable"); 582 583 584 /* 585 * Validate the handle 586 * Although the handle is partially validated in AcpiExReconfiguration(), 587 * when it calls AcpiExResolveOperands(), the handle is more completely 588 * validated here. 589 */ 590 if ((!DdbHandle) || 591 (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) || 592 (ACPI_GET_OBJECT_TYPE (DdbHandle) != ACPI_TYPE_LOCAL_REFERENCE)) 593 { 594 return_ACPI_STATUS (AE_BAD_PARAMETER); 595 } 596 597 /* Get the actual table descriptor from the DdbHandle */ 598 599 TableInfo = (ACPI_TABLE_DESC *) TableDesc->Reference.Object; 600 601 /* 602 * Delete the entire namespace under this table Node 603 * (Offset contains the TableId) 604 */ 605 AcpiNsDeleteNamespaceByOwner (TableInfo->OwnerId); 606 AcpiUtReleaseOwnerId (&TableInfo->OwnerId); 607 608 /* Delete the table itself */ 609 610 (void) AcpiTbUninstallTable (TableInfo->InstalledDesc); 611 612 /* Delete the table descriptor (DdbHandle) */ 613 614 AcpiUtRemoveReference (TableDesc); 615 return_ACPI_STATUS (Status); 616} 617 618