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