tbxface.c revision 91116
1/****************************************************************************** 2 * 3 * Module Name: tbxface - Public interfaces to the ACPI subsystem 4 * ACPI table oriented interfaces 5 * $Revision: 51 $ 6 * 7 *****************************************************************************/ 8 9/****************************************************************************** 10 * 11 * 1. Copyright Notice 12 * 13 * Some or all of this work - Copyright (c) 1999 - 2002, 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 "acpi.h" 121#include "acnamesp.h" 122#include "acinterp.h" 123#include "actables.h" 124 125 126#define _COMPONENT ACPI_TABLES 127 ACPI_MODULE_NAME ("tbxface") 128 129 130/******************************************************************************* 131 * 132 * FUNCTION: AcpiLoadTables 133 * 134 * PARAMETERS: None 135 * 136 * RETURN: Status 137 * 138 * DESCRIPTION: This function is called to load the ACPI tables from the 139 * provided RSDT 140 * 141 ******************************************************************************/ 142 143ACPI_STATUS 144AcpiLoadTables (void) 145{ 146 ACPI_PHYSICAL_ADDRESS RsdpPhysicalAddress; 147 ACPI_STATUS Status; 148 UINT32 NumberOfTables = 0; 149 150 151 ACPI_FUNCTION_TRACE ("AcpiLoadTables"); 152 153 154 /* Get the RSDP */ 155 156 Status = AcpiOsGetRootPointer (ACPI_LOGICAL_ADDRESSING, 157 &RsdpPhysicalAddress); 158 if (ACPI_FAILURE (Status)) 159 { 160 ACPI_REPORT_ERROR (("AcpiLoadTables: Could not get RSDP, %s\n", 161 AcpiFormatException (Status))); 162 goto ErrorExit; 163 } 164 165 /* Map and validate the RSDP */ 166 167 Status = AcpiTbVerifyRsdp (RsdpPhysicalAddress); 168 if (ACPI_FAILURE (Status)) 169 { 170 ACPI_REPORT_ERROR (("AcpiLoadTables: RSDP Failed validation: %s\n", 171 AcpiFormatException (Status))); 172 goto ErrorExit; 173 } 174 175 /* Get the RSDT via the RSDP */ 176 177 Status = AcpiTbGetTableRsdt (&NumberOfTables); 178 if (ACPI_FAILURE (Status)) 179 { 180 ACPI_REPORT_ERROR (("AcpiLoadTables: Could not load RSDT: %s\n", 181 AcpiFormatException (Status))); 182 goto ErrorExit; 183 } 184 185 /* Now get the rest of the tables */ 186 187 Status = AcpiTbGetAllTables (NumberOfTables, NULL); 188 if (ACPI_FAILURE (Status)) 189 { 190 ACPI_REPORT_ERROR (("AcpiLoadTables: Error getting required tables (DSDT/FADT/FACS): %s\n", 191 AcpiFormatException (Status))); 192 goto ErrorExit; 193 } 194 195 ACPI_DEBUG_PRINT ((ACPI_DB_OK, "ACPI Tables successfully loaded\n")); 196 197 198 /* Load the namespace from the tables */ 199 200 Status = AcpiNsLoadNamespace (); 201 if (ACPI_FAILURE (Status)) 202 { 203 ACPI_REPORT_ERROR (("AcpiLoadTables: Could not load namespace: %s\n", 204 AcpiFormatException (Status))); 205 goto ErrorExit; 206 } 207 208 return_ACPI_STATUS (AE_OK); 209 210 211ErrorExit: 212 ACPI_REPORT_ERROR (("AcpiLoadTables: Could not load tables: %s\n", 213 AcpiFormatException (Status))); 214 215 return_ACPI_STATUS (Status); 216} 217 218 219/******************************************************************************* 220 * 221 * FUNCTION: AcpiLoadTable 222 * 223 * PARAMETERS: TablePtr - pointer to a buffer containing the entire 224 * table to be loaded 225 * 226 * RETURN: Status 227 * 228 * DESCRIPTION: This function is called to load a table from the caller's 229 * buffer. The buffer must contain an entire ACPI Table including 230 * a valid header. The header fields will be verified, and if it 231 * is determined that the table is invalid, the call will fail. 232 * 233 ******************************************************************************/ 234 235ACPI_STATUS 236AcpiLoadTable ( 237 ACPI_TABLE_HEADER *TablePtr) 238{ 239 ACPI_STATUS Status; 240 ACPI_TABLE_DESC TableInfo; 241 242 243 ACPI_FUNCTION_TRACE ("AcpiLoadTable"); 244 245 246 if (!TablePtr) 247 { 248 return_ACPI_STATUS (AE_BAD_PARAMETER); 249 } 250 251 /* Copy the table to a local buffer */ 252 253 Status = AcpiTbGetTable (0, TablePtr, &TableInfo); 254 if (ACPI_FAILURE (Status)) 255 { 256 return_ACPI_STATUS (Status); 257 } 258 259 /* Install the new table into the local data structures */ 260 261 Status = AcpiTbInstallTable (NULL, &TableInfo); 262 if (ACPI_FAILURE (Status)) 263 { 264 /* Free table allocated by AcpiTbGetTable */ 265 266 AcpiTbDeleteSingleTable (&TableInfo); 267 return_ACPI_STATUS (Status); 268 } 269 270 /* Convert the table to common format if necessary */ 271 272 switch (TableInfo.Type) 273 { 274 case ACPI_TABLE_FADT: 275 276 Status = AcpiTbConvertTableFadt (); 277 break; 278 279 case ACPI_TABLE_FACS: 280 281 Status = AcpiTbBuildCommonFacs (&TableInfo); 282 break; 283 284 default: 285 /* Load table into namespace if it contains executable AML */ 286 287 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); 288 break; 289 } 290 291 if (ACPI_FAILURE (Status)) 292 { 293 /* Uninstall table and free the buffer */ 294 295 AcpiTbUninstallTable (TableInfo.InstalledDesc); 296 } 297 298 return_ACPI_STATUS (Status); 299} 300 301 302/******************************************************************************* 303 * 304 * FUNCTION: AcpiUnloadTable 305 * 306 * PARAMETERS: TableType - Type of table to be unloaded 307 * 308 * RETURN: Status 309 * 310 * DESCRIPTION: This routine is used to force the unload of a table 311 * 312 ******************************************************************************/ 313 314ACPI_STATUS 315AcpiUnloadTable ( 316 ACPI_TABLE_TYPE TableType) 317{ 318 ACPI_TABLE_DESC *ListHead; 319 320 321 ACPI_FUNCTION_TRACE ("AcpiUnloadTable"); 322 323 324 /* Parameter validation */ 325 326 if (TableType > ACPI_TABLE_MAX) 327 { 328 return_ACPI_STATUS (AE_BAD_PARAMETER); 329 } 330 331 332 /* Find all tables of the requested type */ 333 334 ListHead = &AcpiGbl_AcpiTables[TableType]; 335 do 336 { 337 /* 338 * Delete all namespace entries owned by this table. Note that these 339 * entries can appear anywhere in the namespace by virtue of the AML 340 * "Scope" operator. Thus, we need to track ownership by an ID, not 341 * simply a position within the hierarchy 342 */ 343 AcpiNsDeleteNamespaceByOwner (ListHead->TableId); 344 345 /* Delete (or unmap) the actual table */ 346 347 AcpiTbDeleteAcpiTable (TableType); 348 349 } while (ListHead != &AcpiGbl_AcpiTables[TableType]); 350 351 return_ACPI_STATUS (AE_OK); 352} 353 354 355/******************************************************************************* 356 * 357 * FUNCTION: AcpiGetTableHeader 358 * 359 * PARAMETERS: TableType - one of the defined table types 360 * Instance - the non zero instance of the table, allows 361 * support for multiple tables of the same type 362 * see AcpiGbl_AcpiTableFlag 363 * OutTableHeader - pointer to the ACPI_TABLE_HEADER if successful 364 * 365 * DESCRIPTION: This function is called to get an ACPI table header. The caller 366 * supplies an pointer to a data area sufficient to contain an ACPI 367 * ACPI_TABLE_HEADER structure. 368 * 369 * The header contains a length field that can be used to determine 370 * the size of the buffer needed to contain the entire table. This 371 * function is not valid for the RSD PTR table since it does not 372 * have a standard header and is fixed length. 373 * 374 ******************************************************************************/ 375 376ACPI_STATUS 377AcpiGetTableHeader ( 378 ACPI_TABLE_TYPE TableType, 379 UINT32 Instance, 380 ACPI_TABLE_HEADER *OutTableHeader) 381{ 382 ACPI_TABLE_HEADER *TblPtr; 383 ACPI_STATUS Status; 384 385 386 ACPI_FUNCTION_TRACE ("AcpiGetTableHeader"); 387 388 389 if ((Instance == 0) || 390 (TableType == ACPI_TABLE_RSDP) || 391 (!OutTableHeader)) 392 { 393 return_ACPI_STATUS (AE_BAD_PARAMETER); 394 } 395 396 /* Check the table type and instance */ 397 398 if ((TableType > ACPI_TABLE_MAX) || 399 (ACPI_IS_SINGLE_TABLE (AcpiGbl_AcpiTableData[TableType].Flags) && 400 Instance > 1)) 401 { 402 return_ACPI_STATUS (AE_BAD_PARAMETER); 403 } 404 405 406 /* Get a pointer to the entire table */ 407 408 Status = AcpiTbGetTablePtr (TableType, Instance, &TblPtr); 409 if (ACPI_FAILURE (Status)) 410 { 411 return_ACPI_STATUS (Status); 412 } 413 414 /* 415 * The function will return a NULL pointer if the table is not loaded 416 */ 417 if (TblPtr == NULL) 418 { 419 return_ACPI_STATUS (AE_NOT_EXIST); 420 } 421 422 /* 423 * Copy the header to the caller's buffer 424 */ 425 ACPI_MEMCPY ((void *) OutTableHeader, (void *) TblPtr, 426 sizeof (ACPI_TABLE_HEADER)); 427 428 return_ACPI_STATUS (Status); 429} 430 431 432/******************************************************************************* 433 * 434 * FUNCTION: AcpiGetTable 435 * 436 * PARAMETERS: TableType - one of the defined table types 437 * Instance - the non zero instance of the table, allows 438 * support for multiple tables of the same type 439 * see AcpiGbl_AcpiTableFlag 440 * RetBuffer - pointer to a structure containing a buffer to 441 * receive the table 442 * 443 * RETURN: Status 444 * 445 * DESCRIPTION: This function is called to get an ACPI table. The caller 446 * supplies an OutBuffer large enough to contain the entire ACPI 447 * table. The caller should call the AcpiGetTableHeader function 448 * first to determine the buffer size needed. Upon completion 449 * the OutBuffer->Length field will indicate the number of bytes 450 * copied into the OutBuffer->BufPtr buffer. This table will be 451 * a complete table including the header. 452 * 453 ******************************************************************************/ 454 455ACPI_STATUS 456AcpiGetTable ( 457 ACPI_TABLE_TYPE TableType, 458 UINT32 Instance, 459 ACPI_BUFFER *RetBuffer) 460{ 461 ACPI_TABLE_HEADER *TblPtr; 462 ACPI_STATUS Status; 463 UINT32 TableLength; 464 465 466 ACPI_FUNCTION_TRACE ("AcpiGetTable"); 467 468 469 /* Parameter validation */ 470 471 if (Instance == 0) 472 { 473 return_ACPI_STATUS (AE_BAD_PARAMETER); 474 } 475 476 Status = AcpiUtValidateBuffer (RetBuffer); 477 if (ACPI_FAILURE (Status)) 478 { 479 return_ACPI_STATUS (Status); 480 } 481 482 /* Check the table type and instance */ 483 484 if ((TableType > ACPI_TABLE_MAX) || 485 (ACPI_IS_SINGLE_TABLE (AcpiGbl_AcpiTableData[TableType].Flags) && 486 Instance > 1)) 487 { 488 return_ACPI_STATUS (AE_BAD_PARAMETER); 489 } 490 491 492 /* Get a pointer to the entire table */ 493 494 Status = AcpiTbGetTablePtr (TableType, Instance, &TblPtr); 495 if (ACPI_FAILURE (Status)) 496 { 497 return_ACPI_STATUS (Status); 498 } 499 500 /* 501 * AcpiTbGetTablePtr will return a NULL pointer if the 502 * table is not loaded. 503 */ 504 if (TblPtr == NULL) 505 { 506 return_ACPI_STATUS (AE_NOT_EXIST); 507 } 508 509 /* Get the table length */ 510 511 if (TableType == ACPI_TABLE_RSDP) 512 { 513 /* 514 * RSD PTR is the only "table" without a header 515 */ 516 TableLength = sizeof (RSDP_DESCRIPTOR); 517 } 518 else 519 { 520 TableLength = TblPtr->Length; 521 } 522 523 /* Validate/Allocate/Clear caller buffer */ 524 525 Status = AcpiUtInitializeBuffer (RetBuffer, TableLength); 526 if (ACPI_FAILURE (Status)) 527 { 528 return_ACPI_STATUS (Status); 529 } 530 531 /* Copy the table to the buffer */ 532 533 ACPI_MEMCPY ((void *) RetBuffer->Pointer, (void *) TblPtr, TableLength); 534 return_ACPI_STATUS (AE_OK); 535} 536 537 538