1 /****************************************************************************** 2 * 3 * Module Name: tbxface - ACPI table oriented external interfaces 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2012, 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 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 *****************************************************************************/ 115 116 #define __TBXFACE_C__ 117 118 #include "acpi.h" 119 #include "accommon.h" 120 #include "actables.h" 121 122 #define _COMPONENT ACPI_TABLES 123 ACPI_MODULE_NAME ("tbxface") 124 125 126 /******************************************************************************* 127 * 128 * FUNCTION: AcpiAllocateRootTable 129 * 130 * PARAMETERS: InitialTableCount - Size of InitialTableArray, in number of 131 * ACPI_TABLE_DESC structures 132 * 133 * RETURN: Status 134 * 135 * DESCRIPTION: Allocate a root table array. Used by iASL compiler and 136 * AcpiInitializeTables. 137 * 138 ******************************************************************************/ 139 140 ACPI_STATUS 141 AcpiAllocateRootTable ( 142 UINT32 InitialTableCount) 143 { 144 145 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount; 146 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ALLOW_RESIZE; 147 148 return (AcpiTbResizeRootTableList ()); 149 } 150 151 152 /******************************************************************************* 153 * 154 * FUNCTION: AcpiInitializeTables 155 * 156 * PARAMETERS: InitialTableArray - Pointer to an array of pre-allocated 157 * ACPI_TABLE_DESC structures. If NULL, the 158 * array is dynamically allocated. 159 * InitialTableCount - Size of InitialTableArray, in number of 160 * ACPI_TABLE_DESC structures 161 * AllowRealloc - Flag to tell Table Manager if resize of 162 * pre-allocated array is allowed. Ignored 163 * if InitialTableArray is NULL. 164 * 165 * RETURN: Status 166 * 167 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT. 168 * 169 * NOTE: Allows static allocation of the initial table array in order 170 * to avoid the use of dynamic memory in confined environments 171 * such as the kernel boot sequence where it may not be available. 172 * 173 * If the host OS memory managers are initialized, use NULL for 174 * InitialTableArray, and the table will be dynamically allocated. 175 * 176 ******************************************************************************/ 177 178 ACPI_STATUS 179 AcpiInitializeTables ( 180 ACPI_TABLE_DESC *InitialTableArray, 181 UINT32 InitialTableCount, 182 BOOLEAN AllowResize) 183 { 184 ACPI_PHYSICAL_ADDRESS RsdpAddress; 185 ACPI_STATUS Status; 186 187 188 ACPI_FUNCTION_TRACE (AcpiInitializeTables); 189 190 191 /* 192 * Set up the Root Table Array 193 * Allocate the table array if requested 194 */ 195 if (!InitialTableArray) 196 { 197 Status = AcpiAllocateRootTable (InitialTableCount); 198 if (ACPI_FAILURE (Status)) 199 { 200 return_ACPI_STATUS (Status); 201 } 202 } 203 else 204 { 205 /* Root Table Array has been statically allocated by the host */ 206 207 ACPI_MEMSET (InitialTableArray, 0, 208 (ACPI_SIZE) InitialTableCount * sizeof (ACPI_TABLE_DESC)); 209 210 AcpiGbl_RootTableList.Tables = InitialTableArray; 211 AcpiGbl_RootTableList.MaxTableCount = InitialTableCount; 212 AcpiGbl_RootTableList.Flags = ACPI_ROOT_ORIGIN_UNKNOWN; 213 if (AllowResize) 214 { 215 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ALLOW_RESIZE; 216 } 217 } 218 219 /* Get the address of the RSDP */ 220 221 RsdpAddress = AcpiOsGetRootPointer (); 222 if (!RsdpAddress) 223 { 224 return_ACPI_STATUS (AE_NOT_FOUND); 225 } 226 227 /* 228 * Get the root table (RSDT or XSDT) and extract all entries to the local 229 * Root Table Array. This array contains the information of the RSDT/XSDT 230 * in a common, more useable format. 231 */ 232 Status = AcpiTbParseRootTable (RsdpAddress); 233 return_ACPI_STATUS (Status); 234 } 235 236 ACPI_EXPORT_SYMBOL (AcpiInitializeTables) 237 238 239 /******************************************************************************* 240 * 241 * FUNCTION: AcpiReallocateRootTable 242 * 243 * PARAMETERS: None 244 * 245 * RETURN: Status 246 * 247 * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the 248 * root list from the previously provided scratch area. Should 249 * be called once dynamic memory allocation is available in the 250 * kernel 251 * 252 ******************************************************************************/ 253 254 ACPI_STATUS 255 AcpiReallocateRootTable ( 256 void) 257 { 258 ACPI_TABLE_DESC *Tables; 259 ACPI_SIZE NewSize; 260 ACPI_SIZE CurrentSize; 261 262 263 ACPI_FUNCTION_TRACE (AcpiReallocateRootTable); 264 265 266 /* 267 * Only reallocate the root table if the host provided a static buffer 268 * for the table array in the call to AcpiInitializeTables. 269 */ 270 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 271 { 272 return_ACPI_STATUS (AE_SUPPORT); 273 } 274 275 /* 276 * Get the current size of the root table and add the default 277 * increment to create the new table size. 278 */ 279 CurrentSize = (ACPI_SIZE) 280 AcpiGbl_RootTableList.CurrentTableCount * sizeof (ACPI_TABLE_DESC); 281 282 NewSize = CurrentSize + 283 (ACPI_ROOT_TABLE_SIZE_INCREMENT * 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, CurrentSize); 294 295 /* 296 * Update the root table descriptor. The new size will be the current 297 * number of tables plus the increment, independent of the reserved 298 * size of the original table list. 299 */ 300 AcpiGbl_RootTableList.Tables = Tables; 301 AcpiGbl_RootTableList.MaxTableCount = 302 AcpiGbl_RootTableList.CurrentTableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT; 303 AcpiGbl_RootTableList.Flags = 304 ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE; 305 306 return_ACPI_STATUS (AE_OK); 307 } 308 309 ACPI_EXPORT_SYMBOL (AcpiReallocateRootTable) 310 311 312 /******************************************************************************* 313 * 314 * FUNCTION: AcpiGetTableHeader 315 * 316 * PARAMETERS: Signature - ACPI signature of needed table 317 * Instance - Which instance (for SSDTs) 318 * OutTableHeader - The pointer to the table header to fill 319 * 320 * RETURN: Status and pointer to mapped table header 321 * 322 * DESCRIPTION: Finds an ACPI table header. 323 * 324 * NOTE: Caller is responsible in unmapping the header with 325 * AcpiOsUnmapMemory 326 * 327 ******************************************************************************/ 328 329 ACPI_STATUS 330 AcpiGetTableHeader ( 331 char *Signature, 332 UINT32 Instance, 333 ACPI_TABLE_HEADER *OutTableHeader) 334 { 335 UINT32 i; 336 UINT32 j; 337 ACPI_TABLE_HEADER *Header; 338 339 340 /* Parameter validation */ 341 342 if (!Signature || !OutTableHeader) 343 { 344 return (AE_BAD_PARAMETER); 345 } 346 347 /* Walk the root table list */ 348 349 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 350 { 351 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature), 352 Signature)) 353 { 354 continue; 355 } 356 357 if (++j < Instance) 358 { 359 continue; 360 } 361 362 if (!AcpiGbl_RootTableList.Tables[i].Pointer) 363 { 364 if ((AcpiGbl_RootTableList.Tables[i].Flags & 365 ACPI_TABLE_ORIGIN_MASK) == 366 ACPI_TABLE_ORIGIN_MAPPED) 367 { 368 Header = AcpiOsMapMemory ( 369 AcpiGbl_RootTableList.Tables[i].Address, 370 sizeof (ACPI_TABLE_HEADER)); 371 if (!Header) 372 { 373 return AE_NO_MEMORY; 374 } 375 376 ACPI_MEMCPY (OutTableHeader, Header, sizeof(ACPI_TABLE_HEADER)); 377 AcpiOsUnmapMemory (Header, sizeof(ACPI_TABLE_HEADER)); 378 } 379 else 380 { 381 return AE_NOT_FOUND; 382 } 383 } 384 else 385 { 386 ACPI_MEMCPY (OutTableHeader, 387 AcpiGbl_RootTableList.Tables[i].Pointer, 388 sizeof(ACPI_TABLE_HEADER)); 389 } 390 391 return (AE_OK); 392 } 393 394 return (AE_NOT_FOUND); 395 } 396 397 ACPI_EXPORT_SYMBOL (AcpiGetTableHeader) 398 399 400 /******************************************************************************* 401 * 402 * FUNCTION: AcpiGetTable 403 * 404 * PARAMETERS: Signature - ACPI signature of needed table 405 * Instance - Which instance (for SSDTs) 406 * OutTable - Where the pointer to the table is returned 407 * 408 * RETURN: Status and pointer to table 409 * 410 * DESCRIPTION: Finds and verifies an ACPI table. 411 * 412 ******************************************************************************/ 413 414 ACPI_STATUS 415 AcpiGetTable ( 416 char *Signature, 417 UINT32 Instance, 418 ACPI_TABLE_HEADER **OutTable) 419 { 420 UINT32 i; 421 UINT32 j; 422 ACPI_STATUS Status; 423 424 425 /* Parameter validation */ 426 427 if (!Signature || !OutTable) 428 { 429 return (AE_BAD_PARAMETER); 430 } 431 432 /* Walk the root table list */ 433 434 for (i = 0, j = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 435 { 436 if (!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature), 437 Signature)) 438 { 439 continue; 440 } 441 442 if (++j < Instance) 443 { 444 continue; 445 } 446 447 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]); 448 if (ACPI_SUCCESS (Status)) 449 { 450 *OutTable = AcpiGbl_RootTableList.Tables[i].Pointer; 451 } 452 453 return (Status); 454 } 455 456 return (AE_NOT_FOUND); 457 } 458 459 ACPI_EXPORT_SYMBOL (AcpiGetTable) 460 461 462 /******************************************************************************* 463 * 464 * FUNCTION: AcpiGetTableByIndex 465 * 466 * PARAMETERS: TableIndex - Table index 467 * Table - Where the pointer to the table is returned 468 * 469 * RETURN: Status and pointer to the table 470 * 471 * DESCRIPTION: Obtain a table by an index into the global table list. 472 * 473 ******************************************************************************/ 474 475 ACPI_STATUS 476 AcpiGetTableByIndex ( 477 UINT32 TableIndex, 478 ACPI_TABLE_HEADER **Table) 479 { 480 ACPI_STATUS Status; 481 482 483 ACPI_FUNCTION_TRACE (AcpiGetTableByIndex); 484 485 486 /* Parameter validation */ 487 488 if (!Table) 489 { 490 return_ACPI_STATUS (AE_BAD_PARAMETER); 491 } 492 493 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 494 495 /* Validate index */ 496 497 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount) 498 { 499 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 500 return_ACPI_STATUS (AE_BAD_PARAMETER); 501 } 502 503 if (!AcpiGbl_RootTableList.Tables[TableIndex].Pointer) 504 { 505 /* Table is not mapped, map it */ 506 507 Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[TableIndex]); 508 if (ACPI_FAILURE (Status)) 509 { 510 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 511 return_ACPI_STATUS (Status); 512 } 513 } 514 515 *Table = AcpiGbl_RootTableList.Tables[TableIndex].Pointer; 516 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 517 return_ACPI_STATUS (AE_OK); 518 } 519 520 ACPI_EXPORT_SYMBOL (AcpiGetTableByIndex) 521 522 523 /******************************************************************************* 524 * 525 * FUNCTION: AcpiInstallTableHandler 526 * 527 * PARAMETERS: Handler - Table event handler 528 * Context - Value passed to the handler on each event 529 * 530 * RETURN: Status 531 * 532 * DESCRIPTION: Install table event handler 533 * 534 ******************************************************************************/ 535 536 ACPI_STATUS 537 AcpiInstallTableHandler ( 538 ACPI_TABLE_HANDLER Handler, 539 void *Context) 540 { 541 ACPI_STATUS Status; 542 543 544 ACPI_FUNCTION_TRACE (AcpiInstallTableHandler); 545 546 547 if (!Handler) 548 { 549 return_ACPI_STATUS (AE_BAD_PARAMETER); 550 } 551 552 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS); 553 if (ACPI_FAILURE (Status)) 554 { 555 return_ACPI_STATUS (Status); 556 } 557 558 /* Don't allow more than one handler */ 559 560 if (AcpiGbl_TableHandler) 561 { 562 Status = AE_ALREADY_EXISTS; 563 goto Cleanup; 564 } 565 566 /* Install the handler */ 567 568 AcpiGbl_TableHandler = Handler; 569 AcpiGbl_TableHandlerContext = Context; 570 571 Cleanup: 572 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS); 573 return_ACPI_STATUS (Status); 574 } 575 576 ACPI_EXPORT_SYMBOL (AcpiInstallTableHandler) 577 578 579 /******************************************************************************* 580 * 581 * FUNCTION: AcpiRemoveTableHandler 582 * 583 * PARAMETERS: Handler - Table event handler that was installed 584 * previously. 585 * 586 * RETURN: Status 587 * 588 * DESCRIPTION: Remove table event handler 589 * 590 ******************************************************************************/ 591 592 ACPI_STATUS 593 AcpiRemoveTableHandler ( 594 ACPI_TABLE_HANDLER Handler) 595 { 596 ACPI_STATUS Status; 597 598 599 ACPI_FUNCTION_TRACE (AcpiRemoveTableHandler); 600 601 602 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS); 603 if (ACPI_FAILURE (Status)) 604 { 605 return_ACPI_STATUS (Status); 606 } 607 608 /* Make sure that the installed handler is the same */ 609 610 if (!Handler || 611 Handler != AcpiGbl_TableHandler) 612 { 613 Status = AE_BAD_PARAMETER; 614 goto Cleanup; 615 } 616 617 /* Remove the handler */ 618 619 AcpiGbl_TableHandler = NULL; 620 621 Cleanup: 622 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS); 623 return_ACPI_STATUS (Status); 624 } 625 626 ACPI_EXPORT_SYMBOL (AcpiRemoveTableHandler) 627 628