dbfileio.c revision 272444
167754Smsmith/******************************************************************************* 267754Smsmith * 3193267Sjkim * Module Name: dbfileio - Debugger file I/O commands. These can't usually 467754Smsmith * be used when running the debugger in Ring 0 (Kernel mode) 567754Smsmith * 667754Smsmith ******************************************************************************/ 767754Smsmith 8217365Sjkim/* 9272444Sjkim * Copyright (C) 2000 - 2014, Intel Corp. 1070243Smsmith * All rights reserved. 1167754Smsmith * 12217365Sjkim * Redistribution and use in source and binary forms, with or without 13217365Sjkim * modification, are permitted provided that the following conditions 14217365Sjkim * are met: 15217365Sjkim * 1. Redistributions of source code must retain the above copyright 16217365Sjkim * notice, this list of conditions, and the following disclaimer, 17217365Sjkim * without modification. 18217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 20217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 21217365Sjkim * including a substantially similar Disclaimer requirement for further 22217365Sjkim * binary redistribution. 23217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 24217365Sjkim * of any contributors may be used to endorse or promote products derived 25217365Sjkim * from this software without specific prior written permission. 2667754Smsmith * 27217365Sjkim * Alternatively, this software may be distributed under the terms of the 28217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 29217365Sjkim * Software Foundation. 3067754Smsmith * 31217365Sjkim * NO WARRANTY 32217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 43217365Sjkim */ 4467754Smsmith 45193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 46193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 47193341Sjkim#include <contrib/dev/acpica/include/acdebug.h> 48193341Sjkim#include <contrib/dev/acpica/include/actables.h> 4967754Smsmith 50102550Siwasaki#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER) 5167754Smsmith 52102550Siwasaki#define _COMPONENT ACPI_CA_DEBUGGER 5391116Smsmith ACPI_MODULE_NAME ("dbfileio") 5467754Smsmith 55102550Siwasaki#ifdef ACPI_DEBUGGER 56151937Sjkim 5767754Smsmith/******************************************************************************* 5867754Smsmith * 5967754Smsmith * FUNCTION: AcpiDbCloseDebugFile 6067754Smsmith * 6167754Smsmith * PARAMETERS: None 6267754Smsmith * 63151937Sjkim * RETURN: None 6467754Smsmith * 6567754Smsmith * DESCRIPTION: If open, close the current debug output file 6667754Smsmith * 6767754Smsmith ******************************************************************************/ 6867754Smsmith 6967754Smsmithvoid 7067754SmsmithAcpiDbCloseDebugFile ( 7167754Smsmith void) 7267754Smsmith{ 7367754Smsmith 7467754Smsmith#ifdef ACPI_APPLICATION 7567754Smsmith 7683174Smsmith if (AcpiGbl_DebugFile) 7767754Smsmith { 7883174Smsmith fclose (AcpiGbl_DebugFile); 7983174Smsmith AcpiGbl_DebugFile = NULL; 8083174Smsmith AcpiGbl_DbOutputToFile = FALSE; 8183174Smsmith AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename); 8267754Smsmith } 8367754Smsmith#endif 8467754Smsmith} 8567754Smsmith 8667754Smsmith 8767754Smsmith/******************************************************************************* 8867754Smsmith * 8967754Smsmith * FUNCTION: AcpiDbOpenDebugFile 9067754Smsmith * 9167754Smsmith * PARAMETERS: Name - Filename to open 9267754Smsmith * 93151937Sjkim * RETURN: None 9467754Smsmith * 9567754Smsmith * DESCRIPTION: Open a file where debug output will be directed. 9667754Smsmith * 9767754Smsmith ******************************************************************************/ 9867754Smsmith 9967754Smsmithvoid 10067754SmsmithAcpiDbOpenDebugFile ( 101114237Snjl char *Name) 10267754Smsmith{ 10367754Smsmith 10467754Smsmith#ifdef ACPI_APPLICATION 10567754Smsmith 10667754Smsmith AcpiDbCloseDebugFile (); 10783174Smsmith AcpiGbl_DebugFile = fopen (Name, "w+"); 108243347Sjkim if (!AcpiGbl_DebugFile) 10967754Smsmith { 11073561Smsmith AcpiOsPrintf ("Could not open debug file %s\n", Name); 111243347Sjkim return; 11273561Smsmith } 11367754Smsmith 114243347Sjkim AcpiOsPrintf ("Debug output file %s opened\n", Name); 115254745Sjkim ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name, 116254745Sjkim sizeof (AcpiGbl_DbDebugFilename)); 117243347Sjkim AcpiGbl_DbOutputToFile = TRUE; 118243347Sjkim 11967754Smsmith#endif 12067754Smsmith} 121100966Siwasaki#endif 12267754Smsmith 12367754Smsmith 12467754Smsmith#ifdef ACPI_APPLICATION 125272444Sjkim#include <contrib/dev/acpica/include/acapps.h> 126117521Snjl 127117521Snjl/******************************************************************************* 128117521Snjl * 12967754Smsmith * FUNCTION: AeLocalLoadTable 13067754Smsmith * 131114237Snjl * PARAMETERS: Table - pointer to a buffer containing the entire 13267754Smsmith * table to be loaded 13367754Smsmith * 13467754Smsmith * RETURN: Status 13567754Smsmith * 13667754Smsmith * DESCRIPTION: This function is called to load a table from the caller's 137193267Sjkim * buffer. The buffer must contain an entire ACPI Table including 138193267Sjkim * a valid header. The header fields will be verified, and if it 13967754Smsmith * is determined that the table is invalid, the call will fail. 14067754Smsmith * 14167754Smsmith ******************************************************************************/ 14267754Smsmith 143151937Sjkimstatic ACPI_STATUS 14467754SmsmithAeLocalLoadTable ( 145114237Snjl ACPI_TABLE_HEADER *Table) 14667754Smsmith{ 147167802Sjkim ACPI_STATUS Status = AE_OK; 148167802Sjkim/* ACPI_TABLE_DESC TableInfo; */ 14967754Smsmith 15067754Smsmith 151167802Sjkim ACPI_FUNCTION_TRACE (AeLocalLoadTable); 152167802Sjkim#if 0 15367754Smsmith 154114237Snjl 155114237Snjl if (!Table) 15667754Smsmith { 15767754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 15867754Smsmith } 15967754Smsmith 160114237Snjl TableInfo.Pointer = Table; 161114237Snjl Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL); 162100966Siwasaki if (ACPI_FAILURE (Status)) 163100966Siwasaki { 164100966Siwasaki return_ACPI_STATUS (Status); 165100966Siwasaki } 166100966Siwasaki 16767754Smsmith /* Install the new table into the local data structures */ 16867754Smsmith 169272444Sjkim Status = AcpiTbInitTableDescriptor (&TableInfo); 17067754Smsmith if (ACPI_FAILURE (Status)) 17167754Smsmith { 172151937Sjkim if (Status == AE_ALREADY_EXISTS) 173151937Sjkim { 174151937Sjkim /* Table already exists, no error */ 175151937Sjkim 176151937Sjkim Status = AE_OK; 177151937Sjkim } 178151937Sjkim 17967754Smsmith /* Free table allocated by AcpiTbGetTable */ 18067754Smsmith 18167754Smsmith AcpiTbDeleteSingleTable (&TableInfo); 18267754Smsmith return_ACPI_STATUS (Status); 18367754Smsmith } 18467754Smsmith 185114237Snjl#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 18667754Smsmith 18767754Smsmith Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); 18867754Smsmith if (ACPI_FAILURE (Status)) 18967754Smsmith { 19067754Smsmith /* Uninstall table and free the buffer */ 19167754Smsmith 192167802Sjkim AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT); 19367754Smsmith return_ACPI_STATUS (Status); 19467754Smsmith } 19567754Smsmith#endif 196167802Sjkim#endif 19767754Smsmith 19867754Smsmith return_ACPI_STATUS (Status); 19967754Smsmith} 20099146Siwasaki#endif 20167754Smsmith 202107325Siwasaki 20399146Siwasaki/******************************************************************************* 20499146Siwasaki * 205114237Snjl * FUNCTION: AcpiDbGetTableFromFile 20699146Siwasaki * 207151937Sjkim * PARAMETERS: Filename - File where table is located 208151937Sjkim * ReturnTable - Where a pointer to the table is returned 20999146Siwasaki * 21099146Siwasaki * RETURN: Status 21199146Siwasaki * 21299146Siwasaki * DESCRIPTION: Load an ACPI table from a file 21399146Siwasaki * 21499146Siwasaki ******************************************************************************/ 21599146Siwasaki 21699146SiwasakiACPI_STATUS 217114237SnjlAcpiDbGetTableFromFile ( 218114237Snjl char *Filename, 219114237Snjl ACPI_TABLE_HEADER **ReturnTable) 22099146Siwasaki{ 22199146Siwasaki#ifdef ACPI_APPLICATION 22299146Siwasaki ACPI_STATUS Status; 223114237Snjl ACPI_TABLE_HEADER *Table; 224167802Sjkim BOOLEAN IsAmlTable = TRUE; 22599146Siwasaki 22699146Siwasaki 227272444Sjkim Status = AcpiUtReadTableFromFile (Filename, &Table); 22899146Siwasaki if (ACPI_FAILURE (Status)) 22999146Siwasaki { 23099146Siwasaki return (Status); 23199146Siwasaki } 23299146Siwasaki 233167802Sjkim#ifdef ACPI_DATA_TABLE_DISASSEMBLY 234167802Sjkim IsAmlTable = AcpiUtIsAmlTable (Table); 235167802Sjkim#endif 23699146Siwasaki 237167802Sjkim if (IsAmlTable) 23867754Smsmith { 239167802Sjkim /* Attempt to recognize and install the table */ 240167802Sjkim 241167802Sjkim Status = AeLocalLoadTable (Table); 242167802Sjkim if (ACPI_FAILURE (Status)) 24367754Smsmith { 244167802Sjkim if (Status == AE_ALREADY_EXISTS) 245167802Sjkim { 246167802Sjkim AcpiOsPrintf ("Table %4.4s is already installed\n", 247167802Sjkim Table->Signature); 248167802Sjkim } 249167802Sjkim else 250167802Sjkim { 251167802Sjkim AcpiOsPrintf ("Could not install table, %s\n", 252167802Sjkim AcpiFormatException (Status)); 253167802Sjkim } 254167802Sjkim 255167802Sjkim return (Status); 25667754Smsmith } 25780062Smsmith 258272444Sjkim AcpiTbPrintTableHeader (0, Table); 259272444Sjkim 260167802Sjkim fprintf (stderr, 261167802Sjkim "Acpi table [%4.4s] successfully installed and loaded\n", 262167802Sjkim Table->Signature); 26367754Smsmith } 26467754Smsmith 26567754Smsmith AcpiGbl_AcpiHardwarePresent = FALSE; 266114237Snjl if (ReturnTable) 267114237Snjl { 268114237Snjl *ReturnTable = Table; 269114237Snjl } 27067754Smsmith 271114237Snjl 27267754Smsmith#endif /* ACPI_APPLICATION */ 27367754Smsmith return (AE_OK); 27467754Smsmith} 27567754Smsmith 276102550Siwasaki#endif /* ACPI_DEBUGGER */ 277