dbfileio.c revision 114237
1266692Sgshapiro/******************************************************************************* 238032Speter * 338032Speter * Module Name: dbfileio - Debugger file I/O commands. These can't usually 490792Sgshapiro * be used when running the debugger in Ring 0 (Kernel mode) 590792Sgshapiro * $Revision: 72 $ 690792Sgshapiro * 738032Speter ******************************************************************************/ 838032Speter 938032Speter/****************************************************************************** 1064562Sgshapiro * 1138032Speter * 1. Copyright Notice 1238032Speter * 1338032Speter * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp. 1464562Sgshapiro * All rights reserved. 1564562Sgshapiro * 1664562Sgshapiro * 2. License 1764562Sgshapiro * 1864562Sgshapiro * 2.1. This is your license from Intel Corp. under its intellectual property 1964562Sgshapiro * rights. You may have additional license terms from the party that provided 2064562Sgshapiro * you this software, covering your right to use that party's intellectual 2138032Speter * property rights. 2238032Speter * 2338032Speter * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2464562Sgshapiro * copy of the source code appearing in this file ("Covered Code") an 2538032Speter * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2638032Speter * base code distributed originally by Intel ("Original Intel Code") to copy, 2738032Speter * make derivatives, distribute, use and display any portion of the Covered 2864562Sgshapiro * Code in any form, with the right to sublicense such rights; and 2964562Sgshapiro * 3064562Sgshapiro * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3190792Sgshapiro * license (with the right to sublicense), under only those claims of Intel 3290792Sgshapiro * patents that are infringed by the Original Intel Code, to make, use, sell, 3390792Sgshapiro * offer to sell, and import the Covered Code and derivative works thereof 3490792Sgshapiro * solely to the minimum extent necessary to exercise the above copyright 3590792Sgshapiro * license, and in no event shall the patent license extend to any additions 3690792Sgshapiro * to or modifications of the Original Intel Code. No other license or right 3790792Sgshapiro * is granted directly or by implication, estoppel or otherwise; 3864562Sgshapiro * 3964562Sgshapiro * The above copyright and patent license is granted only if the following 4064562Sgshapiro * conditions are met: 4164562Sgshapiro * 4238032Speter * 3. Conditions 4338032Speter * 4438032Speter * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4564562Sgshapiro * Redistribution of source code of any substantial portion of the Covered 4638032Speter * Code or modification with rights to further distribute source must include 4738032Speter * the above Copyright Notice, the above License, this list of Conditions, 4838032Speter * and the following Disclaimer and Export Compliance provision. In addition, 4938032Speter * 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 119#include "acpi.h" 120#include "acdebug.h" 121#include "acnamesp.h" 122#include "actables.h" 123 124#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER) 125 126#define _COMPONENT ACPI_CA_DEBUGGER 127 ACPI_MODULE_NAME ("dbfileio") 128 129 130/* 131 * NOTE: this is here for lack of a better place. It is used in all 132 * flavors of the debugger, need LCD file 133 */ 134#ifdef ACPI_APPLICATION 135#include <stdio.h> 136FILE *AcpiGbl_DebugFile = NULL; 137#endif 138 139 140#ifdef ACPI_DEBUGGER 141/******************************************************************************* 142 * 143 * FUNCTION: AcpiDbCloseDebugFile 144 * 145 * PARAMETERS: None 146 * 147 * RETURN: Status 148 * 149 * DESCRIPTION: If open, close the current debug output file 150 * 151 ******************************************************************************/ 152 153void 154AcpiDbCloseDebugFile ( 155 void) 156{ 157 158#ifdef ACPI_APPLICATION 159 160 if (AcpiGbl_DebugFile) 161 { 162 fclose (AcpiGbl_DebugFile); 163 AcpiGbl_DebugFile = NULL; 164 AcpiGbl_DbOutputToFile = FALSE; 165 AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename); 166 } 167#endif 168} 169 170 171/******************************************************************************* 172 * 173 * FUNCTION: AcpiDbOpenDebugFile 174 * 175 * PARAMETERS: Name - Filename to open 176 * 177 * RETURN: Status 178 * 179 * DESCRIPTION: Open a file where debug output will be directed. 180 * 181 ******************************************************************************/ 182 183void 184AcpiDbOpenDebugFile ( 185 char *Name) 186{ 187 188#ifdef ACPI_APPLICATION 189 190 AcpiDbCloseDebugFile (); 191 AcpiGbl_DebugFile = fopen (Name, "w+"); 192 if (AcpiGbl_DebugFile) 193 { 194 AcpiOsPrintf ("Debug output file %s opened\n", Name); 195 ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name); 196 AcpiGbl_DbOutputToFile = TRUE; 197 } 198 else 199 { 200 AcpiOsPrintf ("Could not open debug file %s\n", Name); 201 } 202 203#endif 204} 205#endif 206 207 208#ifdef ACPI_APPLICATION 209/******************************************************************************* 210 * 211 * FUNCTION: AcpiDbReadTable 212 * 213 * PARAMETERS: fp - File that contains table 214 * Table - Return value, buffer with table 215 * TableLength - Return value, length of table 216 * 217 * RETURN: Status 218 * 219 * DESCRIPTION: Load the DSDT from the file pointer 220 * 221 ******************************************************************************/ 222 223static ACPI_STATUS 224AcpiDbReadTable ( 225 FILE *fp, 226 ACPI_TABLE_HEADER **Table, 227 UINT32 *TableLength) 228{ 229 ACPI_TABLE_HEADER TableHeader; 230 UINT8 *AmlStart; 231 UINT32 AmlLength; 232 UINT32 Actual; 233 ACPI_STATUS Status; 234 235 236 /* Read the table header */ 237 238 if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != sizeof (ACPI_TABLE_HEADER)) 239 { 240 AcpiOsPrintf ("Couldn't read the table header\n"); 241 return (AE_BAD_SIGNATURE); 242 } 243 244 /* Validate the table header/length */ 245 246 Status = AcpiTbValidateTableHeader (&TableHeader); 247 if ((ACPI_FAILURE (Status)) || 248 (TableHeader.Length > 0x800000)) /* 8 Mbyte should be enough */ 249 { 250 AcpiOsPrintf ("Table header is invalid!\n"); 251 return (AE_ERROR); 252 } 253 254 /* We only support a limited number of table types */ 255 256 if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) && 257 ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) && 258 ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4)) 259 { 260 AcpiOsPrintf ("Table signature is invalid\n"); 261 ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); 262 return (AE_ERROR); 263 } 264 265 /* Allocate a buffer for the table */ 266 267 *TableLength = TableHeader.Length; 268 *Table = AcpiOsAllocate ((size_t) *TableLength); 269 if (!*Table) 270 { 271 AcpiOsPrintf ("Could not allocate memory for ACPI table %4.4s (size=%X)\n", 272 TableHeader.Signature, TableHeader.Length); 273 return (AE_NO_MEMORY); 274 } 275 276 AmlStart = (UINT8 *) *Table + sizeof (TableHeader); 277 AmlLength = *TableLength - sizeof (TableHeader); 278 279 /* Copy the header to the buffer */ 280 281 ACPI_MEMCPY (*Table, &TableHeader, sizeof (TableHeader)); 282 283 /* Get the rest of the table */ 284 285 Actual = fread (AmlStart, 1, (size_t) AmlLength, fp); 286 if (Actual == AmlLength) 287 { 288 /* Now validate the checksum */ 289 290 Status = AcpiTbVerifyTableChecksum (*Table); 291 return (AE_OK); 292 } 293 294 if (Actual > 0) 295 { 296 AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", AmlLength, Actual); 297 return (AE_OK); 298 } 299 300 AcpiOsPrintf ("Error - could not read the table file\n"); 301 AcpiOsFree (*Table); 302 *Table = NULL; 303 *TableLength = 0; 304 305 return (AE_ERROR); 306} 307#endif 308 309 310/******************************************************************************* 311 * 312 * FUNCTION: AeLocalLoadTable 313 * 314 * PARAMETERS: Table - pointer to a buffer containing the entire 315 * table to be loaded 316 * 317 * RETURN: Status 318 * 319 * DESCRIPTION: This function is called to load a table from the caller's 320 * buffer. The buffer must contain an entire ACPI Table including 321 * a valid header. The header fields will be verified, and if it 322 * is determined that the table is invalid, the call will fail. 323 * 324 ******************************************************************************/ 325 326ACPI_STATUS 327AeLocalLoadTable ( 328 ACPI_TABLE_HEADER *Table) 329{ 330 ACPI_STATUS Status; 331 ACPI_TABLE_DESC TableInfo; 332 333 334 ACPI_FUNCTION_TRACE ("AeLocalLoadTable"); 335 336 337 if (!Table) 338 { 339 return_ACPI_STATUS (AE_BAD_PARAMETER); 340 } 341 342 TableInfo.Pointer = Table; 343 Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL); 344 if (ACPI_FAILURE (Status)) 345 { 346 return_ACPI_STATUS (Status); 347 } 348 349 /* Install the new table into the local data structures */ 350 351 Status = AcpiTbInstallTable (&TableInfo); 352 if (ACPI_FAILURE (Status)) 353 { 354 /* Free table allocated by AcpiTbGetTable */ 355 356 AcpiTbDeleteSingleTable (&TableInfo); 357 return_ACPI_STATUS (Status); 358 } 359 360#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 361 362 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); 363 if (ACPI_FAILURE (Status)) 364 { 365 /* Uninstall table and free the buffer */ 366 367 AcpiTbDeleteAcpiTable (ACPI_TABLE_DSDT); 368 return_ACPI_STATUS (Status); 369 } 370#endif 371 372 return_ACPI_STATUS (Status); 373} 374 375 376#ifdef ACPI_APPLICATION 377/******************************************************************************* 378 * 379 * FUNCTION: AcpiDbReadTableFromFile 380 * 381 * PARAMETERS: Filename - File where table is located 382 * Table - Where a pointer to the table is returned 383 * 384 * RETURN: Status 385 * 386 * DESCRIPTION: Get an ACPI table from a file 387 * 388 ******************************************************************************/ 389 390ACPI_STATUS 391AcpiDbReadTableFromFile ( 392 char *Filename, 393 ACPI_TABLE_HEADER **Table) 394{ 395 FILE *fp; 396 UINT32 TableLength; 397 ACPI_STATUS Status; 398 399 400 /* Open the file */ 401 402 fp = fopen (Filename, "rb"); 403 if (!fp) 404 { 405 AcpiOsPrintf ("Could not open input file %s\n", Filename); 406 return (AE_ERROR); 407 } 408 409 /* Get the entire file */ 410 411 fprintf (stderr, "Loading Acpi table from file %s\n", Filename); 412 Status = AcpiDbReadTable (fp, Table, &TableLength); 413 fclose(fp); 414 415 if (ACPI_FAILURE (Status)) 416 { 417 AcpiOsPrintf ("Couldn't get table from the file\n"); 418 return (Status); 419 } 420 421 return (AE_OK); 422 } 423#endif 424 425 426/******************************************************************************* 427 * 428 * FUNCTION: AcpiDbGetTableFromFile 429 * 430 * PARAMETERS: Filename - File where table is located 431 * Table - Where a pointer to the table is returned 432 * 433 * RETURN: Status 434 * 435 * DESCRIPTION: Load an ACPI table from a file 436 * 437 ******************************************************************************/ 438 439ACPI_STATUS 440AcpiDbGetTableFromFile ( 441 char *Filename, 442 ACPI_TABLE_HEADER **ReturnTable) 443{ 444#ifdef ACPI_APPLICATION 445 ACPI_STATUS Status; 446 ACPI_TABLE_HEADER *Table; 447 448 449 Status = AcpiDbReadTableFromFile (Filename, &Table); 450 if (ACPI_FAILURE (Status)) 451 { 452 return (Status); 453 } 454 455 /* Attempt to recognize and install the table */ 456 457 Status = AeLocalLoadTable (Table); 458 if (ACPI_FAILURE (Status)) 459 { 460 if (Status == AE_ALREADY_EXISTS) 461 { 462 AcpiOsPrintf ("Table %4.4s is already installed\n", 463 Table->Signature); 464 } 465 else 466 { 467 AcpiOsPrintf ("Could not install table, %s\n", 468 AcpiFormatException (Status)); 469 } 470 471 return (Status); 472 } 473 474 fprintf (stderr, "Acpi table [%4.4s] successfully installed and loaded\n", 475 Table->Signature); 476 477 AcpiGbl_AcpiHardwarePresent = FALSE; 478 if (ReturnTable) 479 { 480 *ReturnTable = Table; 481 } 482 483 484#endif /* ACPI_APPLICATION */ 485 return (AE_OK); 486} 487 488#endif /* ACPI_DEBUGGER */ 489 490