dbfileio.c revision 281075
120253Sjoerg/******************************************************************************* 220302Sjoerg * 320302Sjoerg * Module Name: dbfileio - Debugger file I/O commands. These can't usually 420253Sjoerg * be used when running the debugger in Ring 0 (Kernel mode) 520253Sjoerg * 620253Sjoerg ******************************************************************************/ 720253Sjoerg 820253Sjoerg/* 920302Sjoerg * Copyright (C) 2000 - 2015, Intel Corp. 1020253Sjoerg * All rights reserved. 1120253Sjoerg * 1220253Sjoerg * Redistribution and use in source and binary forms, with or without 1320253Sjoerg * modification, are permitted provided that the following conditions 1420302Sjoerg * are met: 1520253Sjoerg * 1. Redistributions of source code must retain the above copyright 1620253Sjoerg * notice, this list of conditions, and the following disclaimer, 1720302Sjoerg * without modification. 1820253Sjoerg * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1920253Sjoerg * substantially similar to the "NO WARRANTY" disclaimer below 2020253Sjoerg * ("Disclaimer") and any redistribution must be conditioned upon 2120253Sjoerg * including a substantially similar Disclaimer requirement for further 2220253Sjoerg * binary redistribution. 2320253Sjoerg * 3. Neither the names of the above-listed copyright holders nor the names 2420253Sjoerg * of any contributors may be used to endorse or promote products derived 2520253Sjoerg * from this software without specific prior written permission. 2650479Speter * 2720253Sjoerg * Alternatively, this software may be distributed under the terms of the 2820253Sjoerg * GNU General Public License ("GPL") version 2 as published by the Free 29287084Sbapt * Software Foundation. 30287084Sbapt * 31268346Sbapt * NO WARRANTY 32287084Sbapt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3320253Sjoerg * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3420253Sjoerg * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3520253Sjoerg * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3644229Sdavidn * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3720253Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3820253Sjoerg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3920253Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4020253Sjoerg * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4120253Sjoerg * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4220253Sjoerg * POSSIBILITY OF SUCH DAMAGES. 4320253Sjoerg */ 4420267Sjoerg 4552512Sdavidn#include <contrib/dev/acpica/include/acpi.h> 4652512Sdavidn#include <contrib/dev/acpica/include/accommon.h> 4720253Sjoerg#include <contrib/dev/acpica/include/acdebug.h> 4820253Sjoerg#include <contrib/dev/acpica/include/actables.h> 4920253Sjoerg 50326849Seugen#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER) 51326849Seugen 52326849Seugen#define _COMPONENT ACPI_CA_DEBUGGER 53326849Seugen ACPI_MODULE_NAME ("dbfileio") 54326849Seugen 55326849Seugen#ifdef ACPI_DEBUGGER 56326849Seugen 57326849Seugen/******************************************************************************* 5820253Sjoerg * 5920253Sjoerg * FUNCTION: AcpiDbCloseDebugFile 6020253Sjoerg * 6120253Sjoerg * PARAMETERS: None 6220253Sjoerg * 6320253Sjoerg * RETURN: None 6420253Sjoerg * 65219408Sjkim * DESCRIPTION: If open, close the current debug output file 6620253Sjoerg * 6720253Sjoerg ******************************************************************************/ 6820253Sjoerg 6920253Sjoergvoid 70287084SbaptAcpiDbCloseDebugFile ( 7120253Sjoerg void) 72287084Sbapt{ 7320253Sjoerg 74287084Sbapt#ifdef ACPI_APPLICATION 75287084Sbapt 76287084Sbapt if (AcpiGbl_DebugFile) 77287084Sbapt { 78287084Sbapt fclose (AcpiGbl_DebugFile); 79287084Sbapt AcpiGbl_DebugFile = NULL; 80287084Sbapt AcpiGbl_DbOutputToFile = FALSE; 81287084Sbapt AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename); 82287084Sbapt } 83287084Sbapt#endif 84287084Sbapt} 85287084Sbapt 86287084Sbapt 87287084Sbapt/******************************************************************************* 88287084Sbapt * 89287084Sbapt * FUNCTION: AcpiDbOpenDebugFile 90285092Sbapt * 91287084Sbapt * PARAMETERS: Name - Filename to open 92287084Sbapt * 9320253Sjoerg * RETURN: None 9421330Sdavidn * 9521330Sdavidn * DESCRIPTION: Open a file where debug output will be directed. 9621330Sdavidn * 9721330Sdavidn ******************************************************************************/ 98287084Sbapt 99287084Sbaptvoid 100287084SbaptAcpiDbOpenDebugFile ( 101287084Sbapt char *Name) 102287084Sbapt{ 10320253Sjoerg 104305750Sasomers#ifdef ACPI_APPLICATION 10520253Sjoerg 10620253Sjoerg AcpiDbCloseDebugFile (); 10720253Sjoerg AcpiGbl_DebugFile = fopen (Name, "w+"); 10879292Skris if (!AcpiGbl_DebugFile) 10920253Sjoerg { 11020253Sjoerg AcpiOsPrintf ("Could not open debug file %s\n", Name); 11120253Sjoerg return; 11220253Sjoerg } 113287084Sbapt 114287084Sbapt AcpiOsPrintf ("Debug output file %s opened\n", Name); 115287084Sbapt ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name, 116 sizeof (AcpiGbl_DbDebugFilename)); 117 AcpiGbl_DbOutputToFile = TRUE; 118 119#endif 120} 121#endif 122 123 124#ifdef ACPI_APPLICATION 125#include <contrib/dev/acpica/include/acapps.h> 126 127/******************************************************************************* 128 * 129 * FUNCTION: AeLocalLoadTable 130 * 131 * PARAMETERS: Table - pointer to a buffer containing the entire 132 * table to be loaded 133 * 134 * RETURN: Status 135 * 136 * DESCRIPTION: This function is called to load a table from the caller's 137 * buffer. The buffer must contain an entire ACPI Table including 138 * a valid header. The header fields will be verified, and if it 139 * is determined that the table is invalid, the call will fail. 140 * 141 ******************************************************************************/ 142 143static ACPI_STATUS 144AeLocalLoadTable ( 145 ACPI_TABLE_HEADER *Table) 146{ 147 ACPI_STATUS Status = AE_OK; 148/* ACPI_TABLE_DESC TableInfo; */ 149 150 151 ACPI_FUNCTION_TRACE (AeLocalLoadTable); 152#if 0 153 154 155 if (!Table) 156 { 157 return_ACPI_STATUS (AE_BAD_PARAMETER); 158 } 159 160 TableInfo.Pointer = Table; 161 Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL); 162 if (ACPI_FAILURE (Status)) 163 { 164 return_ACPI_STATUS (Status); 165 } 166 167 /* Install the new table into the local data structures */ 168 169 Status = AcpiTbInitTableDescriptor (&TableInfo); 170 if (ACPI_FAILURE (Status)) 171 { 172 if (Status == AE_ALREADY_EXISTS) 173 { 174 /* Table already exists, no error */ 175 176 Status = AE_OK; 177 } 178 179 /* Free table allocated by AcpiTbGetTable */ 180 181 AcpiTbDeleteSingleTable (&TableInfo); 182 return_ACPI_STATUS (Status); 183 } 184 185#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 186 187 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); 188 if (ACPI_FAILURE (Status)) 189 { 190 /* Uninstall table and free the buffer */ 191 192 AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT); 193 return_ACPI_STATUS (Status); 194 } 195#endif 196#endif 197 198 return_ACPI_STATUS (Status); 199} 200#endif 201 202 203/******************************************************************************* 204 * 205 * FUNCTION: AcpiDbGetTableFromFile 206 * 207 * PARAMETERS: Filename - File where table is located 208 * ReturnTable - Where a pointer to the table is returned 209 * 210 * RETURN: Status 211 * 212 * DESCRIPTION: Load an ACPI table from a file 213 * 214 ******************************************************************************/ 215 216ACPI_STATUS 217AcpiDbGetTableFromFile ( 218 char *Filename, 219 ACPI_TABLE_HEADER **ReturnTable) 220{ 221#ifdef ACPI_APPLICATION 222 ACPI_STATUS Status; 223 ACPI_TABLE_HEADER *Table; 224 BOOLEAN IsAmlTable = TRUE; 225 226 227 Status = AcpiUtReadTableFromFile (Filename, &Table); 228 if (ACPI_FAILURE (Status)) 229 { 230 return (Status); 231 } 232 233#ifdef ACPI_DATA_TABLE_DISASSEMBLY 234 IsAmlTable = AcpiUtIsAmlTable (Table); 235#endif 236 237 if (IsAmlTable) 238 { 239 /* Attempt to recognize and install the table */ 240 241 Status = AeLocalLoadTable (Table); 242 if (ACPI_FAILURE (Status)) 243 { 244 if (Status == AE_ALREADY_EXISTS) 245 { 246 AcpiOsPrintf ("Table %4.4s is already installed\n", 247 Table->Signature); 248 } 249 else 250 { 251 AcpiOsPrintf ("Could not install table, %s\n", 252 AcpiFormatException (Status)); 253 } 254 255 return (Status); 256 } 257 258 AcpiTbPrintTableHeader (0, Table); 259 260 fprintf (stderr, 261 "Acpi table [%4.4s] successfully installed and loaded\n", 262 Table->Signature); 263 } 264 265 AcpiGbl_AcpiHardwarePresent = FALSE; 266 if (ReturnTable) 267 { 268 *ReturnTable = Table; 269 } 270 271 272#endif /* ACPI_APPLICATION */ 273 return (AE_OK); 274} 275 276#endif /* ACPI_DEBUGGER */ 277