1 /******************************************************************************* 2 * 3 * Module Name: dbfileio - Debugger file I/O commands. These can't usually 4 * be used when running the debugger in Ring 0 (Kernel mode) 5 * 6 ******************************************************************************/ 7 8 /* 9 * Copyright (C) 2000 - 2015, Intel Corp. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions, and the following disclaimer, 17 * without modification. 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19 * substantially similar to the "NO WARRANTY" disclaimer below 20 * ("Disclaimer") and any redistribution must be conditioned upon 21 * including a substantially similar Disclaimer requirement for further 22 * binary redistribution. 23 * 3. Neither the names of the above-listed copyright holders nor the names 24 * of any contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * Alternatively, this software may be distributed under the terms of the 28 * GNU General Public License ("GPL") version 2 as published by the Free 29 * Software Foundation. 30 * 31 * NO WARRANTY 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 * POSSIBILITY OF SUCH DAMAGES. 43 */ 44 45 #include "acpi.h" 46 #include "accommon.h" 47 #include "acdebug.h" 48 #include "actables.h" 49 50 #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER) 51 52 #define _COMPONENT ACPI_CA_DEBUGGER 53 ACPI_MODULE_NAME ("dbfileio") 54 55 #ifdef ACPI_DEBUGGER 56 57 /******************************************************************************* 58 * 59 * FUNCTION: AcpiDbCloseDebugFile 60 * 61 * PARAMETERS: None 62 * 63 * RETURN: None 64 * 65 * DESCRIPTION: If open, close the current debug output file 66 * 67 ******************************************************************************/ 68 69 void 70 AcpiDbCloseDebugFile ( 71 void) 72 { 73 74 #ifdef ACPI_APPLICATION 75 76 if (AcpiGbl_DebugFile) 77 { 78 fclose (AcpiGbl_DebugFile); 79 AcpiGbl_DebugFile = NULL; 80 AcpiGbl_DbOutputToFile = FALSE; 81 AcpiOsPrintf ("Debug output file %s closed\n", 82 AcpiGbl_DbDebugFilename); 83 } 84 #endif 85 } 86 87 88 /******************************************************************************* 89 * 90 * FUNCTION: AcpiDbOpenDebugFile 91 * 92 * PARAMETERS: Name - Filename to open 93 * 94 * RETURN: None 95 * 96 * DESCRIPTION: Open a file where debug output will be directed. 97 * 98 ******************************************************************************/ 99 100 void 101 AcpiDbOpenDebugFile ( 102 char *Name) 103 { 104 105 #ifdef ACPI_APPLICATION 106 107 AcpiDbCloseDebugFile (); 108 AcpiGbl_DebugFile = fopen (Name, "w+"); 109 if (!AcpiGbl_DebugFile) 110 { 111 AcpiOsPrintf ("Could not open debug file %s\n", Name); 112 return; 113 } 114 115 AcpiOsPrintf ("Debug output file %s opened\n", Name); 116 strncpy (AcpiGbl_DbDebugFilename, Name, 117 sizeof (AcpiGbl_DbDebugFilename)); 118 AcpiGbl_DbOutputToFile = TRUE; 119 120 #endif 121 } 122 #endif 123 124 125 #ifdef ACPI_APPLICATION 126 #include "acapps.h" 127 128 /******************************************************************************* 129 * 130 * FUNCTION: AeLocalLoadTable 131 * 132 * PARAMETERS: Table - pointer to a buffer containing the entire 133 * table to be loaded 134 * 135 * RETURN: Status 136 * 137 * DESCRIPTION: This function is called to load a table from the caller's 138 * buffer. The buffer must contain an entire ACPI Table including 139 * a valid header. The header fields will be verified, and if it 140 * is determined that the table is invalid, the call will fail. 141 * 142 ******************************************************************************/ 143 144 static ACPI_STATUS 145 AeLocalLoadTable ( 146 ACPI_TABLE_HEADER *Table) 147 { 148 ACPI_STATUS Status = AE_OK; 149 150 151 ACPI_FUNCTION_TRACE (AeLocalLoadTable); 152 153 #if 0 154 /* ACPI_TABLE_DESC TableInfo; */ 155 156 if (!Table) 157 { 158 return_ACPI_STATUS (AE_BAD_PARAMETER); 159 } 160 161 TableInfo.Pointer = Table; 162 Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL); 163 if (ACPI_FAILURE (Status)) 164 { 165 return_ACPI_STATUS (Status); 166 } 167 168 /* Install the new table into the local data structures */ 169 170 Status = AcpiTbInitTableDescriptor (&TableInfo); 171 if (ACPI_FAILURE (Status)) 172 { 173 if (Status == AE_ALREADY_EXISTS) 174 { 175 /* Table already exists, no error */ 176 177 Status = AE_OK; 178 } 179 180 /* Free table allocated by AcpiTbGetTable */ 181 182 AcpiTbDeleteSingleTable (&TableInfo); 183 return_ACPI_STATUS (Status); 184 } 185 186 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 187 188 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); 189 if (ACPI_FAILURE (Status)) 190 { 191 /* Uninstall table and free the buffer */ 192 193 AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT); 194 return_ACPI_STATUS (Status); 195 } 196 #endif 197 #endif 198 199 return_ACPI_STATUS (Status); 200 } 201 #endif 202 203 204 /******************************************************************************* 205 * 206 * FUNCTION: AcpiDbGetTableFromFile 207 * 208 * PARAMETERS: Filename - File where table is located 209 * ReturnTable - Where a pointer to the table is returned 210 * 211 * RETURN: Status 212 * 213 * DESCRIPTION: Load an ACPI table from a file 214 * 215 ******************************************************************************/ 216 217 ACPI_STATUS 218 AcpiDbGetTableFromFile ( 219 char *Filename, 220 ACPI_TABLE_HEADER **ReturnTable, 221 BOOLEAN MustBeAmlFile) 222 { 223 #ifdef ACPI_APPLICATION 224 ACPI_STATUS Status; 225 ACPI_TABLE_HEADER *Table; 226 BOOLEAN IsAmlTable = TRUE; 227 228 229 Status = AcpiUtReadTableFromFile (Filename, &Table); 230 if (ACPI_FAILURE (Status)) 231 { 232 return (Status); 233 } 234 235 if (MustBeAmlFile) 236 { 237 IsAmlTable = AcpiUtIsAmlTable (Table); 238 if (!IsAmlTable) 239 { 240 ACPI_EXCEPTION ((AE_INFO, AE_OK, 241 "Input for -e is not an AML table: " 242 "\"%4.4s\" (must be DSDT/SSDT)", 243 Table->Signature)); 244 return (AE_TYPE); 245 } 246 } 247 248 if (IsAmlTable) 249 { 250 /* Attempt to recognize and install the table */ 251 252 Status = AeLocalLoadTable (Table); 253 if (ACPI_FAILURE (Status)) 254 { 255 if (Status == AE_ALREADY_EXISTS) 256 { 257 AcpiOsPrintf ("Table %4.4s is already installed\n", 258 Table->Signature); 259 } 260 else 261 { 262 AcpiOsPrintf ("Could not install table, %s\n", 263 AcpiFormatException (Status)); 264 } 265 266 return (Status); 267 } 268 269 AcpiTbPrintTableHeader (0, Table); 270 271 fprintf (stderr, 272 "Acpi table [%4.4s] successfully installed and loaded\n", 273 Table->Signature); 274 } 275 276 AcpiGbl_AcpiHardwarePresent = FALSE; 277 if (ReturnTable) 278 { 279 *ReturnTable = Table; 280 } 281 282 283 #endif /* ACPI_APPLICATION */ 284 return (AE_OK); 285 } 286 287 #endif /* ACPI_DEBUGGER */ 288