dbfileio.c revision 287168
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/* 9278970Sjkim * Copyright (C) 2000 - 2015, 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 5067754Smsmith 51102550Siwasaki#define _COMPONENT ACPI_CA_DEBUGGER 5291116Smsmith ACPI_MODULE_NAME ("dbfileio") 5367754Smsmith 54287168Sjkim 55102550Siwasaki#ifdef ACPI_DEBUGGER 5667754Smsmith/******************************************************************************* 5767754Smsmith * 5867754Smsmith * FUNCTION: AcpiDbCloseDebugFile 5967754Smsmith * 6067754Smsmith * PARAMETERS: None 6167754Smsmith * 62151937Sjkim * RETURN: None 6367754Smsmith * 6467754Smsmith * DESCRIPTION: If open, close the current debug output file 6567754Smsmith * 6667754Smsmith ******************************************************************************/ 6767754Smsmith 6867754Smsmithvoid 6967754SmsmithAcpiDbCloseDebugFile ( 7067754Smsmith void) 7167754Smsmith{ 7267754Smsmith 7367754Smsmith#ifdef ACPI_APPLICATION 7467754Smsmith 7583174Smsmith if (AcpiGbl_DebugFile) 7667754Smsmith { 7783174Smsmith fclose (AcpiGbl_DebugFile); 7883174Smsmith AcpiGbl_DebugFile = NULL; 7983174Smsmith AcpiGbl_DbOutputToFile = FALSE; 80287168Sjkim AcpiOsPrintf ("Debug output file %s closed\n", 81287168Sjkim 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); 115284583Sjkim 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; 14867754Smsmith 14967754Smsmith 150167802Sjkim ACPI_FUNCTION_TRACE (AeLocalLoadTable); 151287168Sjkim 152167802Sjkim#if 0 153287168Sjkim/* ACPI_TABLE_DESC TableInfo; */ 15467754Smsmith 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, 219283092Sjkim ACPI_TABLE_HEADER **ReturnTable, 220283092Sjkim BOOLEAN MustBeAmlFile) 22199146Siwasaki{ 22299146Siwasaki#ifdef ACPI_APPLICATION 22399146Siwasaki ACPI_STATUS Status; 224114237Snjl ACPI_TABLE_HEADER *Table; 225167802Sjkim BOOLEAN IsAmlTable = TRUE; 22699146Siwasaki 22799146Siwasaki 228272444Sjkim Status = AcpiUtReadTableFromFile (Filename, &Table); 22999146Siwasaki if (ACPI_FAILURE (Status)) 23099146Siwasaki { 23199146Siwasaki return (Status); 23299146Siwasaki } 23399146Siwasaki 234283092Sjkim if (MustBeAmlFile) 235283092Sjkim { 236283092Sjkim IsAmlTable = AcpiUtIsAmlTable (Table); 237283092Sjkim if (!IsAmlTable) 238283092Sjkim { 239283092Sjkim ACPI_EXCEPTION ((AE_INFO, AE_OK, 240283092Sjkim "Input for -e is not an AML table: " 241283092Sjkim "\"%4.4s\" (must be DSDT/SSDT)", 242283092Sjkim Table->Signature)); 243283092Sjkim return (AE_TYPE); 244283092Sjkim } 245283092Sjkim } 24699146Siwasaki 247167802Sjkim if (IsAmlTable) 24867754Smsmith { 249167802Sjkim /* Attempt to recognize and install the table */ 250167802Sjkim 251167802Sjkim Status = AeLocalLoadTable (Table); 252167802Sjkim if (ACPI_FAILURE (Status)) 25367754Smsmith { 254167802Sjkim if (Status == AE_ALREADY_EXISTS) 255167802Sjkim { 256167802Sjkim AcpiOsPrintf ("Table %4.4s is already installed\n", 257167802Sjkim Table->Signature); 258167802Sjkim } 259167802Sjkim else 260167802Sjkim { 261167802Sjkim AcpiOsPrintf ("Could not install table, %s\n", 262167802Sjkim AcpiFormatException (Status)); 263167802Sjkim } 264167802Sjkim 265167802Sjkim return (Status); 26667754Smsmith } 26780062Smsmith 268272444Sjkim AcpiTbPrintTableHeader (0, Table); 269272444Sjkim 270167802Sjkim fprintf (stderr, 271167802Sjkim "Acpi table [%4.4s] successfully installed and loaded\n", 272167802Sjkim Table->Signature); 27367754Smsmith } 27467754Smsmith 27567754Smsmith AcpiGbl_AcpiHardwarePresent = FALSE; 276114237Snjl if (ReturnTable) 277114237Snjl { 278114237Snjl *ReturnTable = Table; 279114237Snjl } 28067754Smsmith 281114237Snjl 28267754Smsmith#endif /* ACPI_APPLICATION */ 28367754Smsmith return (AE_OK); 28467754Smsmith} 285