tbxface.c revision 167802
1/****************************************************************************** 2 * 3 * Module Name: tbxface - Public interfaces to the ACPI subsystem 4 * ACPI table oriented interfaces 5 * $Revision: 1.86 $ 6 * 7 *****************************************************************************/ 8 9/****************************************************************************** 10 * 11 * 1. Copyright Notice 12 * 13 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp. 14 * All rights reserved. 15 * 16 * 2. License 17 * 18 * 2.1. This is your license from Intel Corp. under its intellectual property 19 * rights. You may have additional license terms from the party that provided 20 * you this software, covering your right to use that party's intellectual 21 * property rights. 22 * 23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 24 * copy of the source code appearing in this file ("Covered Code") an 25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 26 * base code distributed originally by Intel ("Original Intel Code") to copy, 27 * make derivatives, distribute, use and display any portion of the Covered 28 * Code in any form, with the right to sublicense such rights; and 29 * 30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 31 * license (with the right to sublicense), under only those claims of Intel 32 * patents that are infringed by the Original Intel Code, to make, use, sell, 33 * offer to sell, and import the Covered Code and derivative works thereof 34 * solely to the minimum extent necessary to exercise the above copyright 35 * license, and in no event shall the patent license extend to any additions 36 * to or modifications of the Original Intel Code. No other license or right 37 * is granted directly or by implication, estoppel or otherwise; 38 * 39 * The above copyright and patent license is granted only if the following 40 * conditions are met: 41 * 42 * 3. Conditions 43 * 44 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 45 * Redistribution of source code of any substantial portion of the Covered 46 * Code or modification with rights to further distribute source must include 47 * the above Copyright Notice, the above License, this list of Conditions, 48 * and the following Disclaimer and Export Compliance provision. In addition, 49 * Licensee must cause all Covered Code to which Licensee contributes to 50 * contain a file documenting the changes Licensee made to create that Covered 51 * Code and the date of any change. Licensee must include in that file the 52 * documentation of any changes made by any predecessor Licensee. Licensee 53 * must include a prominent statement that the modification is derived, 54 * directly or indirectly, from Original Intel Code. 55 * 56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 57 * Redistribution of source code of any substantial portion of the Covered 58 * Code or modification without rights to further distribute source must 59 * include the following Disclaimer and Export Compliance provision in the 60 * documentation and/or other materials provided with distribution. In 61 * addition, Licensee may not authorize further sublicense of source of any 62 * portion of the Covered Code, and must include terms to the effect that the 63 * license from Licensee to its licensee is limited to the intellectual 64 * property embodied in the software Licensee provides to its licensee, and 65 * not to intellectual property embodied in modifications its licensee may 66 * make. 67 * 68 * 3.3. Redistribution of Executable. Redistribution in executable form of any 69 * substantial portion of the Covered Code or modification must reproduce the 70 * above Copyright Notice, and the following Disclaimer and Export Compliance 71 * provision in the documentation and/or other materials provided with the 72 * distribution. 73 * 74 * 3.4. Intel retains all right, title, and interest in and to the Original 75 * Intel Code. 76 * 77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 78 * Intel shall be used in advertising or otherwise to promote the sale, use or 79 * other dealings in products derived from or relating to the Covered Code 80 * without prior written authorization from Intel. 81 * 82 * 4. Disclaimer and Export Compliance 83 * 84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 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 __TBXFACE_C__ 119 120#include <contrib/dev/acpica/acpi.h> 121#include <contrib/dev/acpica/acnamesp.h> 122#include <contrib/dev/acpica/actables.h> 123 124#define _COMPONENT ACPI_TABLES 125 ACPI_MODULE_NAME ("tbxface") 126 127/* Local prototypes */ 128 129static ACPI_STATUS 130AcpiTbLoadNamespace ( 131 void); 132 133 134/******************************************************************************* 135 * 136 * FUNCTION: AcpiAllocateRootTable 137 * 138 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of 139 * ACPI_TABLE_DESC structures 140 * 141 * RETURN: Status 142 * 143 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and 144 * AcpiInitializeTables. 145 * 146 ******************************************************************************/ 147 148ACPI_STATUS 149AcpiAllocateRootTable ( 150 UINT32 InitialTableCount) 151{ 152 153 AcpiGbl_RootTableList.Size = InitialTableCount; 154 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE; 155 156 return (AcpiTbResizeRootTableList ()); 157} 158 159 160/******************************************************************************* 161 * 162 * FUNCTION: AcpiInitializeTables 163 * 164 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated 165 * ACPI_TABLE_DESC structures. If NULL, the 166 * array is dynamically allocated. 167 * InitialTableCount - Size of InitialTableArray, in number of 168 * ACPI_TABLE_DESC structures 169 * AllowRealloc - Flag to tell Table Manager if resize of 170 * pre-allocated array is allowed. Ignored 171 * if InitialTableArray is NULL. 172 * 173 * RETURN: Status 174 * 175 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT. 176 * 177 * NOTE: Allows static allocation of the initial table array in order 178 * to avoid the use of dynamic memory in confined environments 179 * such as the kernel boot sequence where it may not be available. 180 * 181 * If the host OS memory managers are initialized, use NULL for 182 * InitialTableArray, and the table will be dynamically allocated. 183 * 184 ******************************************************************************/ 185 186ACPI_STATUS 187AcpiInitializeTables ( 188 ACPI_TABLE_DESC *InitialTableArray, 189 UINT32 InitialTableCount, 190 BOOLEAN AllowResize) 191{ 192 ACPI_PHYSICAL_ADDRESS RsdpAddress; 193 ACPI_STATUS Status; 194 195 196 ACPI_FUNCTION_TRACE (AcpiInitializeTables); 197 198 199 /* 200 * Set up the Root Table Array 201 * Allocate the table array if requested 202 */ 203 if (!InitialTableArray) 204 { 205 Status = AcpiAllocateRootTable (InitialTableCount); 206 if (ACPI_FAILURE (Status)) 207 { 208 return_ACPI_STATUS (Status); 209 } 210 } 211 else 212 { 213 /* Root Table Array has been statically allocated by the host */ 214 215 ACPI_MEMSET (InitialTableArray, 0, 216 InitialTableCount * sizeof (ACPI_TABLE_DESC)); 217 218 AcpiGbl_RootTableList.Tables = InitialTableArray; 219 AcpiGbl_RootTableList.Size = InitialTableCount; 220 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN; 221 if (AllowResize) 222 { 223 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE; 224 } 225 } 226 227 /* Get the address of the RSDP */ 228 229 RsdpAddress = AcpiOsGetRootPointer (); 230 if (!RsdpAddress) 231 { 232 return_ACPI_STATUS (AE_NOT_FOUND); 233 } 234 235 /* 236 * Get the root table (RSDT or XSDT) and extract all entries to the local 237 * Root Table Array. This array contains the information of the RSDT/XSDT 238 * in a common, more useable format. 239 */ 240 Status = AcpiTbParseRootTable (RsdpAddress, ACPI_TABLE_ORIGIN_MAPPED); 241 return_ACPI_STATUS (Status); 242} 243 244ACPI_EXPORT_SYMBOL (AcpiInitializeTables) 245 246 247/******************************************************************************* 248 * 249 * FUNCTION: AcpiReallocateRootTable 250 * 251 * PARAMETERS: None 252 * 253 * RETURN: Status 254 * 255 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the 256 * root list from the previously provided scratch area. Should 257 * be called once dynamic memory allocation is available in the 258 * kernel 259 * 260 ******************************************************************************/ 261 262ACPI_STATUS 263AcpiReallocateRootTable ( 264 void) 265{ 266 ACPI_TABLE_DESC *Tables; 267 ACPI_SIZE NewSize; 268 269 270 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable); 271 272 273 /* 274 * Only reallocate the root table if the host provided a static buffer 275 * for the table array in the call to AcpiInitializeTables. 276 */ 277 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 278 { 279 return_ACPI_STATUS (AE_SUPPORT); 280 } 281 282 NewSize = (AcpiGbl_RootTableList.Count + ACPI_ROOT_TABLE_SIZE_INCREMENT) * 283 sizeof (ACPI_TABLE_DESC); 284 285 /* Create new array and copy the old array */ 286 287 Tables = ACPI_ALLOCATE_ZEROED (NewSize); 288 if (!Tables) 289 { 290 return_ACPI_STATUS (AE_NO_MEMORY); 291 } 292 293 ACPI_MEMCPY (Tables, AcpiGbl_RootTableList.Tables, NewSize); 294 295 AcpiGbl_RootTableList.Size = AcpiGbl_RootTableList.Count; 296 AcpiGbl_RootTableList.Tables = Tables; 297 AcpiGbl_RootTableList.Flags = 298 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE; 299 300 return_ACPI_STATUS (AE_OK); 301} 302 303ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable) 304 305 306/****************************************************************************** 307 * 308 * FUNCTION: AcpiGetTableHeader 309 * 310 * PARAMETERS: Signature - ACPI signature of needed table 311 * Instance - Which instance (for SSDTs) 312 * OutTableHeader - The pointer to the table header to fill 313 * 314 * RETURN: Status and pointer to mapped table header 315 * 316 * DESCRIPTION: Finds an ACPI table header. 317 * 318 * NOTE: Caller is responsible in unmapping the header with 319 * AcpiOsUnmapMemory 320 * 321 *****************************************************************************/ 322 323ACPI_STATUS 324AcpiGetTableHeader ( 325 char *Signature, 326 ACPI_NATIVE_UINT Instance, 327 ACPI_TABLE_HEADER *OutTableHeader) 328{ 329 ACPI_NATIVE_UINT i; 330 ACPI_NATIVE_UINT j; 331 ACPI_TABLE_HEADER *Header; 332 333 334 /* Parameter validation */ 335 336 if (!Signature || !OutTableHeader) 337 { 338 return (AE_BAD_PARAMETER); 339 } 340 341 /* 342 * Walk the root table list 343 */ 344 for (i = 0, j = 0; i < AcpiGbl_RootTableList.Count; i++) 345 { 346 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature), 347 Signature)) 348 { 349 continue; 350 } 351 352 if (++j < Instance) 353 { 354 continue; 355 } 356 357 if (!AcpiGbl_RootTableList.Tables[i].Pointer) 358 { 359 if ((AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_ORIGIN_MASK) == 360 ACPI_TABLE_ORIGIN_MAPPED) 361 { 362 Header = AcpiOsMapMemory (AcpiGbl_RootTableList.Tables[i].Address, 363 sizeof (ACPI_TABLE_HEADER)); 364 if (!Header) 365 { 366 return AE_NO_MEMORY; 367 } 368 369 ACPI_MEMCPY (OutTableHeader, Header, sizeof(ACPI_TABLE_HEADER)); 370 AcpiOsUnmapMemory (Header, sizeof(ACPI_TABLE_HEADER)); 371 } 372 373 else 374 { 375 return AE_NOT_FOUND; 376 } 377 } 378 379 else 380 { 381 ACPI_MEMCPY (OutTableHeader, AcpiGbl_RootTableList.Tables[i].Pointer, 382 sizeof(ACPI_TABLE_HEADER)); 383 } 384 385 return (AE_OK); 386 } 387 388 return (AE_NOT_FOUND); 389} 390 391ACPI_EXPORT_SYMBOL (AcpiGetTableHeader) 392 393 394/****************************************************************************** 395 * 396 * FUNCTION: AcpiGetTable 397 * 398 * PARAMETERS: Signature - ACPI signature of needed table 399 * Instance - Which instance (for SSDTs) 400 * OutTable - Where the pointer to the table is returned 401 * 402 * RETURN: Status and pointer to table 403 * 404 * DESCRIPTION: Finds and verifies an ACPI table. 405 * 406 *****************************************************************************/ 407 408ACPI_STATUS 409AcpiGetTable ( 410 char *Signature, 411 ACPI_NATIVE_UINT Instance, 412 ACPI_TABLE_HEADER **OutTable) 413{ 414 ACPI_NATIVE_UINT i; 415 ACPI_NATIVE_UINT j; 416 ACPI_STATUS Status; 417 418 419 /* Parameter validation */ 420 421 if (!Signature || !OutTable) 422 { 423 return (AE_BAD_PARAMETER); 424 } 425 426 /* 427 * Walk the root table list 428 */ 429 for (i = 0, j = 0; i < AcpiGbl_RootTableList.Count; i++) 430 { 431 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature), 432 Signature)) 433 { 434 continue; 435 } 436 437 if (++j < Instance) 438 { 439 continue; 440 } 441 442 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]); 443 if (ACPI_SUCCESS (Status)) 444 { 445 *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer; 446 } 447 448 return (Status); 449 } 450 451 return (AE_NOT_FOUND); 452} 453 454ACPI_EXPORT_SYMBOL (AcpiGetTable) 455 456 457/******************************************************************************* 458 * 459 * FUNCTION: AcpiGetTableByIndex 460 * 461 * PARAMETERS: TableIndex - Table index 462 * Table - Where the pointer to the table is returned 463 * 464 * RETURN: Status and pointer to the table 465 * 466 * DESCRIPTION: Obtain a table by an index into the global table list. 467 * 468 ******************************************************************************/ 469 470ACPI_STATUS 471AcpiGetTableByIndex ( 472 ACPI_NATIVE_UINT TableIndex, 473 ACPI_TABLE_HEADER **Table) 474{ 475 ACPI_STATUS Status; 476 477 478 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex); 479 480 481 /* Parameter validation */ 482 483 if (!Table) 484 { 485 return_ACPI_STATUS (AE_BAD_PARAMETER); 486 } 487 488 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 489 490 /* Validate index */ 491 492 if (TableIndex >= AcpiGbl_RootTableList.Count) 493 { 494 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 495 return_ACPI_STATUS (AE_BAD_PARAMETER); 496 } 497 498 if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer) 499 { 500 /* Table is not mapped, map it */ 501 502 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]); 503 if (ACPI_FAILURE (Status)) 504 { 505 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 506 return_ACPI_STATUS (Status); 507 } 508 } 509 510 *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer; 511 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 512 return_ACPI_STATUS (AE_OK); 513} 514 515ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex) 516 517 518/******************************************************************************* 519 * 520 * FUNCTION: AcpiTbLoadNamespace 521 * 522 * PARAMETERS: None 523 * 524 * RETURN: Status 525 * 526 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in 527 * the RSDT/XSDT. 528 * 529 ******************************************************************************/ 530 531static ACPI_STATUS 532AcpiTbLoadNamespace ( 533 void) 534{ 535 ACPI_STATUS Status; 536 ACPI_TABLE_HEADER *Table; 537 ACPI_NATIVE_UINT i; 538 539 540 ACPI_FUNCTION_TRACE (TbLoadNamespace); 541 542 543 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 544 545 /* 546 * Load the namespace. The DSDT is required, but any SSDT and PSDT tables 547 * are optional. 548 */ 549 if (!AcpiGbl_RootTableList.Count || 550 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Signature), 551 ACPI_SIG_DSDT) || 552 ACPI_FAILURE (AcpiTbVerifyTable(&AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT]))) 553 { 554 Status = AE_NO_ACPI_TABLES; 555 goto UnlockAndExit; 556 } 557 558 /* 559 * Find DSDT table 560 */ 561 Status = AcpiOsTableOverride ( 562 AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Pointer, &Table); 563 if (ACPI_SUCCESS (Status) && Table) 564 { 565 /* 566 * DSDT table has been found 567 */ 568 AcpiTbDeleteTable (&AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT]); 569 AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Pointer = Table; 570 AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Length = Table->Length; 571 AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Flags = ACPI_TABLE_ORIGIN_UNKNOWN; 572 573 ACPI_INFO ((AE_INFO, "Table DSDT replaced by host OS")); 574 AcpiTbPrintTableHeader (0, Table); 575 } 576 577 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT]); 578 if (ACPI_FAILURE (Status)) 579 { 580 /* A valid DSDT is required */ 581 582 Status = AE_NO_ACPI_TABLES; 583 goto UnlockAndExit; 584 } 585 586 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 587 588 /* 589 * Load and parse tables. 590 */ 591 Status = AcpiNsLoadTable (ACPI_TABLE_INDEX_DSDT, AcpiGbl_RootNode); 592 if (ACPI_FAILURE (Status)) 593 { 594 return_ACPI_STATUS (Status); 595 } 596 597 /* 598 * Load any SSDT or PSDT tables. Note: Loop leaves tables locked 599 */ 600 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 601 for (i = 0; i < AcpiGbl_RootTableList.Count; ++i) 602 { 603 if ((!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature), 604 ACPI_SIG_SSDT) && 605 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature), 606 ACPI_SIG_PSDT)) || 607 ACPI_FAILURE (AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]))) 608 { 609 continue; 610 } 611 612 /* Ignore errors while loading tables, get as many as possible */ 613 614 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 615 (void) AcpiNsLoadTable (i, AcpiGbl_RootNode); 616 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 617 } 618 619 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); 620 621UnlockAndExit: 622 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 623 return_ACPI_STATUS (Status); 624} 625 626 627/******************************************************************************* 628 * 629 * FUNCTION: AcpiLoadTables 630 * 631 * PARAMETERS: None 632 * 633 * RETURN: Status 634 * 635 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT 636 * 637 ******************************************************************************/ 638 639ACPI_STATUS 640AcpiLoadTables ( 641 void) 642{ 643 ACPI_STATUS Status; 644 645 646 ACPI_FUNCTION_TRACE (AcpiLoadTables); 647 648 649 /* 650 * Load the namespace from the tables 651 */ 652 Status = AcpiTbLoadNamespace (); 653 if (ACPI_FAILURE (Status)) 654 { 655 ACPI_EXCEPTION ((AE_INFO, Status, "While loading namespace from ACPI tables")); 656 } 657 658 return_ACPI_STATUS (Status); 659} 660 661ACPI_EXPORT_SYMBOL (AcpiLoadTables) 662 663