tbxfroot.c revision 80062
190792Sgshapiro/****************************************************************************** 2261194Sgshapiro * 390792Sgshapiro * Module Name: tbxfroot - Find the root ACPI table (RSDT) 490792Sgshapiro * $Revision: 46 $ 590792Sgshapiro * 690792Sgshapiro *****************************************************************************/ 790792Sgshapiro 890792Sgshapiro/****************************************************************************** 990792Sgshapiro * 1090792Sgshapiro * 1. Copyright Notice 11266527Sgshapiro * 1290792Sgshapiro * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 1390792Sgshapiro * All rights reserved. 1490792Sgshapiro * 1590792Sgshapiro * 2. License 1690792Sgshapiro * 1790792Sgshapiro * 2.1. This is your license from Intel Corp. under its intellectual property 1890792Sgshapiro * rights. You may have additional license terms from the party that provided 1990792Sgshapiro * you this software, covering your right to use that party's intellectual 2090792Sgshapiro * property rights. 2190792Sgshapiro * 2290792Sgshapiro * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2390792Sgshapiro * copy of the source code appearing in this file ("Covered Code") an 2490792Sgshapiro * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2590792Sgshapiro * base code distributed originally by Intel ("Original Intel Code") to copy, 2690792Sgshapiro * make derivatives, distribute, use and display any portion of the Covered 2790792Sgshapiro * Code in any form, with the right to sublicense such rights; and 2890792Sgshapiro * 2990792Sgshapiro * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3090792Sgshapiro * license (with the right to sublicense), under only those claims of Intel 3190792Sgshapiro * patents that are infringed by the Original Intel Code, to make, use, sell, 3290792Sgshapiro * offer to sell, and import the Covered Code and derivative works thereof 3390792Sgshapiro * solely to the minimum extent necessary to exercise the above copyright 3490792Sgshapiro * license, and in no event shall the patent license extend to any additions 3590792Sgshapiro * to or modifications of the Original Intel Code. No other license or right 3690792Sgshapiro * is granted directly or by implication, estoppel or otherwise; 3790792Sgshapiro * 3890792Sgshapiro * The above copyright and patent license is granted only if the following 3990792Sgshapiro * conditions are met: 4090792Sgshapiro * 4190792Sgshapiro * 3. Conditions 4290792Sgshapiro * 4390792Sgshapiro * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4490792Sgshapiro * Redistribution of source code of any substantial portion of the Covered 4590792Sgshapiro * Code or modification with rights to further distribute source must include 4690792Sgshapiro * the above Copyright Notice, the above License, this list of Conditions, 4790792Sgshapiro * and the following Disclaimer and Export Compliance provision. In addition, 4890792Sgshapiro * Licensee must cause all Covered Code to which Licensee contributes to 4990792Sgshapiro * contain a file documenting the changes Licensee made to create that Covered 5090792Sgshapiro * Code and the date of any change. Licensee must include in that file the 5190792Sgshapiro * documentation of any changes made by any predecessor Licensee. Licensee 5290792Sgshapiro * must include a prominent statement that the modification is derived, 5390792Sgshapiro * directly or indirectly, from Original Intel Code. 5490792Sgshapiro * 5590792Sgshapiro * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5690792Sgshapiro * Redistribution of source code of any substantial portion of the Covered 5790792Sgshapiro * Code or modification without rights to further distribute source must 5890792Sgshapiro * include the following Disclaimer and Export Compliance provision in the 5990792Sgshapiro * documentation and/or other materials provided with distribution. In 6090792Sgshapiro * addition, Licensee may not authorize further sublicense of source of any 6190792Sgshapiro * portion of the Covered Code, and must include terms to the effect that the 6290792Sgshapiro * license from Licensee to its licensee is limited to the intellectual 6390792Sgshapiro * property embodied in the software Licensee provides to its licensee, and 6490792Sgshapiro * 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 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117#define __TBXFROOT_C__ 118 119#include "acpi.h" 120#include "achware.h" 121#include "actables.h" 122 123 124#define _COMPONENT ACPI_TABLES 125 MODULE_NAME ("tbxfroot") 126 127#define RSDP_CHECKSUM_LENGTH 20 128 129 130/******************************************************************************* 131 * 132 * FUNCTION: AcpiFindRootPointer 133 * 134 * PARAMETERS: **RsdpPhysicalAddress - Where to place the RSDP address 135 * Flags - Logical/Physical addressing 136 * 137 * RETURN: Status, Physical address of the RSDP 138 * 139 * DESCRIPTION: Find the RSDP 140 * 141 ******************************************************************************/ 142 143ACPI_STATUS 144AcpiFindRootPointer ( 145 UINT32 Flags, 146 ACPI_PHYSICAL_ADDRESS *RsdpPhysicalAddress) 147{ 148 ACPI_TABLE_DESC TableInfo; 149 ACPI_STATUS Status; 150 151 152 FUNCTION_TRACE ("AcpiFindRootPointer"); 153 154 155 /* Get the RSDP */ 156 157 Status = AcpiTbFindRsdp (&TableInfo, Flags); 158 if (ACPI_FAILURE (Status)) 159 { 160 DEBUG_PRINTP (ACPI_ERROR, ("RSDP structure not found\n")); 161 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 162 } 163 164 *RsdpPhysicalAddress = TableInfo.PhysicalAddress; 165 166 return_ACPI_STATUS (AE_OK); 167} 168 169 170/******************************************************************************* 171 * 172 * FUNCTION: AcpiTbScanMemoryForRsdp 173 * 174 * PARAMETERS: StartAddress - Starting pointer for search 175 * Length - Maximum length to search 176 * 177 * RETURN: Pointer to the RSDP if found, otherwise NULL. 178 * 179 * DESCRIPTION: Search a block of memory for the RSDP signature 180 * 181 ******************************************************************************/ 182 183UINT8 * 184AcpiTbScanMemoryForRsdp ( 185 UINT8 *StartAddress, 186 UINT32 Length) 187{ 188 UINT32 Offset; 189 UINT8 *MemRover; 190 191 192 FUNCTION_TRACE ("TbScanMemoryForRsdp"); 193 194 /* Search from given start addr for the requested length */ 195 196 for (Offset = 0, MemRover = StartAddress; 197 Offset < Length; 198 Offset += RSDP_SCAN_STEP, MemRover += RSDP_SCAN_STEP) 199 { 200 201 /* The signature and checksum must both be correct */ 202 203 if (STRNCMP ((NATIVE_CHAR *) MemRover, 204 RSDP_SIG, sizeof (RSDP_SIG)-1) == 0 && 205 AcpiTbChecksum (MemRover, RSDP_CHECKSUM_LENGTH) == 0) 206 { 207 /* If so, we have found the RSDP */ 208 209 DEBUG_PRINTP (ACPI_INFO, 210 ("RSDP located at physical address %p\n",MemRover)); 211 return_PTR (MemRover); 212 } 213 } 214 215 /* Searched entire block, no RSDP was found */ 216 DEBUG_PRINTP (ACPI_INFO,("Searched entire block, no RSDP was found.\n")); 217 218 return_PTR (NULL); 219} 220 221 222/******************************************************************************* 223 * 224 * FUNCTION: AcpiTbFindRsdp 225 * 226 * PARAMETERS: *TableInfo - Where the table info is returned 227 * Flags - Current memory mode (logical vs. 228 * physical addressing) 229 * 230 * RETURN: Status 231 * 232 * DESCRIPTION: Search lower 1Mbyte of memory for the root system descriptor 233 * pointer structure. If it is found, set *RSDP to point to it. 234 * 235 * NOTE: The RSDP must be either in the first 1K of the Extended 236 * BIOS Data Area or between E0000 and FFFFF (ACPI 1.0 section 237 * 5.2.2; assertion #421). 238 * 239 ******************************************************************************/ 240 241ACPI_STATUS 242AcpiTbFindRsdp ( 243 ACPI_TABLE_DESC *TableInfo, 244 UINT32 Flags) 245{ 246 UINT8 *TablePtr; 247 UINT8 *MemRover; 248 UINT64 PhysAddr; 249 ACPI_STATUS Status = AE_OK; 250 251 252 FUNCTION_TRACE ("TbFindRsdp"); 253 254 255 /* 256 * Scan supports either 1) Logical addressing or 2) Physical addressing 257 */ 258 if ((Flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) 259 { 260 /* 261 * 1) Search EBDA (low memory) paragraphs 262 */ 263 Status = AcpiOsMapMemory (LO_RSDP_WINDOW_BASE, LO_RSDP_WINDOW_SIZE, 264 (void **) &TablePtr); 265 if (ACPI_FAILURE (Status)) 266 { 267 return_ACPI_STATUS (Status); 268 } 269 270 MemRover = AcpiTbScanMemoryForRsdp (TablePtr, LO_RSDP_WINDOW_SIZE); 271 AcpiOsUnmapMemory (TablePtr, LO_RSDP_WINDOW_SIZE); 272 273 if (MemRover) 274 { 275 /* Found it, return the physical address */ 276 277 PhysAddr = LO_RSDP_WINDOW_BASE; 278 PhysAddr += (MemRover - TablePtr); 279 280 TableInfo->PhysicalAddress = PhysAddr; 281 282 return_ACPI_STATUS (AE_OK); 283 } 284 285 /* 286 * 2) Search upper memory: 16-byte boundaries in E0000h-F0000h 287 */ 288 Status = AcpiOsMapMemory (HI_RSDP_WINDOW_BASE, HI_RSDP_WINDOW_SIZE, 289 (void **) &TablePtr); 290 if (ACPI_FAILURE (Status)) 291 { 292 return_ACPI_STATUS (Status); 293 } 294 295 MemRover = AcpiTbScanMemoryForRsdp (TablePtr, HI_RSDP_WINDOW_SIZE); 296 AcpiOsUnmapMemory (TablePtr, HI_RSDP_WINDOW_SIZE); 297 298 if (MemRover) 299 { 300 /* Found it, return the physical address */ 301 302 PhysAddr = HI_RSDP_WINDOW_BASE; 303 PhysAddr += (MemRover - TablePtr); 304 305 TableInfo->PhysicalAddress = PhysAddr; 306 307 return_ACPI_STATUS (AE_OK); 308 } 309 } 310 311 312 /* 313 * Physical addressing 314 */ 315 else 316 { 317 /* 318 * 1) Search EBDA (low memory) paragraphs 319 */ 320 MemRover = AcpiTbScanMemoryForRsdp ((UINT8 *) LO_RSDP_WINDOW_BASE, 321 LO_RSDP_WINDOW_SIZE); 322 if (MemRover) 323 { 324 /* Found it, return the physical address */ 325 326 TableInfo->PhysicalAddress = (ACPI_TBLPTR) MemRover; 327 return_ACPI_STATUS (AE_OK); 328 } 329 330 /* 331 * 2) Search upper memory: 16-byte boundaries in E0000h-F0000h 332 */ 333 MemRover = AcpiTbScanMemoryForRsdp ((UINT8 *) HI_RSDP_WINDOW_BASE, 334 HI_RSDP_WINDOW_SIZE); 335 if (MemRover) 336 { 337 /* Found it, return the physical address */ 338 339 TableInfo->PhysicalAddress = (ACPI_TBLPTR) MemRover; 340 return_ACPI_STATUS (AE_OK); 341 } 342 } 343 344 345 /* RSDP signature was not found */ 346 347 return_ACPI_STATUS (AE_NOT_FOUND); 348} 349 350 351/******************************************************************************* 352 * 353 * FUNCTION: AcpiGetFirmwareTable 354 * 355 * PARAMETERS: Signature - Any ACPI table signature 356 * Instance - the non zero instance of the table, allows 357 * support for multiple tables of the same type 358 * Flags - 0: Physical/Virtual support 359 * RetBuffer - pointer to a structure containing a buffer to 360 * receive the table 361 * 362 * RETURN: Status 363 * 364 * DESCRIPTION: This function is called to get an ACPI table. The caller 365 * supplies an OutBuffer large enough to contain the entire ACPI 366 * table. Upon completion 367 * the OutBuffer->Length field will indicate the number of bytes 368 * copied into the OutBuffer->BufPtr buffer. This table will be 369 * a complete table including the header. 370 * 371 ******************************************************************************/ 372 373ACPI_STATUS 374AcpiGetFirmwareTable ( 375 ACPI_STRING Signature, 376 UINT32 Instance, 377 UINT32 Flags, 378 ACPI_TABLE_HEADER **TablePointer) 379{ 380 ACPI_PHYSICAL_ADDRESS PhysicalAddress; 381 ACPI_TABLE_HEADER *RsdtPtr; 382 ACPI_TABLE_HEADER *TablePtr; 383 ACPI_STATUS Status; 384 UINT32 RsdtSize; 385 UINT32 TableSize; 386 UINT32 TableCount; 387 UINT32 i; 388 UINT32 j; 389 390 391 FUNCTION_TRACE ("AcpiGetFirmwareTable"); 392 393 394 /* 395 * Ensure that at least the table manager is initialized. We don't 396 * require that the entire ACPI subsystem is up for this interface 397 */ 398 399 400 /* 401 * If we have a buffer, we must have a length too 402 */ 403 if ((Instance == 0) || 404 (!Signature) || 405 (!TablePointer)) 406 { 407 return_ACPI_STATUS (AE_BAD_PARAMETER); 408 } 409 410 /* Get the RSDP */ 411 412 Status = AcpiOsGetRootPointer (Flags, &PhysicalAddress); 413 if (ACPI_FAILURE (Status)) 414 { 415 DEBUG_PRINTP (ACPI_INFO, ("RSDP not found\n")); 416 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 417 } 418 419 AcpiGbl_RSDP = (RSDP_DESCRIPTOR *) (ACPI_TBLPTR) PhysicalAddress; 420 421 DEBUG_PRINTP (ACPI_INFO, 422 ("RSDP located at %p, RSDT physical=%8.8lX%8.8lX \n", 423 AcpiGbl_RSDP, HIDWORD(AcpiGbl_RSDP->RsdtPhysicalAddress), 424 LODWORD(AcpiGbl_RSDP->RsdtPhysicalAddress))); 425 426 427 /* Get the RSDT and validate it */ 428 429 PhysicalAddress = AcpiTbGetRsdtAddress (); 430 Status = AcpiTbGetTablePointer (PhysicalAddress, Flags, &RsdtSize, &RsdtPtr); 431 if (ACPI_FAILURE (Status)) 432 { 433 return_ACPI_STATUS (Status); 434 } 435 436 Status = AcpiTbValidateRsdt (RsdtPtr); 437 if (ACPI_FAILURE (Status)) 438 { 439 goto Cleanup; 440 } 441 442 443 /* Get the number of table pointers within the RSDT */ 444 445 TableCount = AcpiTbGetTableCount (AcpiGbl_RSDP, RsdtPtr); 446 447 448 /* 449 * Search the RSDT/XSDT for the correct instance of the 450 * requested table 451 */ 452 for (i = 0, j = 0; i < TableCount; i++) 453 { 454 /* Get the next table pointer */ 455 456 if (AcpiGbl_RSDP->Revision < 2) 457 { 458 PhysicalAddress = ((RSDT_DESCRIPTOR *) RsdtPtr)->TableOffsetEntry[i]; 459 } 460 else 461 { 462 PhysicalAddress = (ACPI_PHYSICAL_ADDRESS) 463 ACPI_GET_ADDRESS (((XSDT_DESCRIPTOR *) RsdtPtr)->TableOffsetEntry[i]); 464 } 465 466 /* Get addressibility if necessary */ 467 468 Status = AcpiTbGetTablePointer (PhysicalAddress, Flags, &TableSize, &TablePtr); 469 if (ACPI_FAILURE (Status)) 470 { 471 goto Cleanup; 472 } 473 474 /* Compare table signatures and table instance */ 475 476 if (!STRNCMP ((char *) TablePtr, Signature, STRLEN (Signature))) 477 { 478 /* An instance of the table was found */ 479 480 j++; 481 if (j >= Instance) 482 { 483 /* Found the correct instance */ 484 485 *TablePointer = TablePtr; 486 goto Cleanup; 487 } 488 } 489 490 /* Delete table mapping if using virtual addressing */ 491 492 if (TableSize) 493 { 494 AcpiOsUnmapMemory (TablePtr, TableSize); 495 } 496 } 497 498 /* Did not find the table */ 499 500 Status = AE_NOT_EXIST; 501 502 503Cleanup: 504 if (RsdtSize) 505 { 506 AcpiOsUnmapMemory (RsdtPtr, RsdtSize); 507 } 508 return_ACPI_STATUS (Status); 509} 510 511 512