dbfileio.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /*******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: dbfileio - Debugger file I/O commands. These can't usually
4 1.1.1.2.2.2 bouyer * be used when running the debugger in Ring 0 (Kernel mode)
5 1.1.1.2.2.2 bouyer *
6 1.1.1.2.2.2 bouyer ******************************************************************************/
7 1.1.1.2.2.2 bouyer
8 1.1.1.2.2.2 bouyer /*
9 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.2.2 bouyer * All rights reserved.
11 1.1.1.2.2.2 bouyer *
12 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.1.1.2.2.2 bouyer * are met:
15 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.2.2 bouyer * without modification.
18 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.2.2 bouyer * binary redistribution.
23 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
26 1.1.1.2.2.2 bouyer *
27 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.2.2 bouyer * Software Foundation.
30 1.1.1.2.2.2 bouyer *
31 1.1.1.2.2.2 bouyer * NO WARRANTY
32 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.2.2 bouyer */
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer
46 1.1.1.2.2.2 bouyer #include "acpi.h"
47 1.1.1.2.2.2 bouyer #include "accommon.h"
48 1.1.1.2.2.2 bouyer #include "acdebug.h"
49 1.1.1.2.2.2 bouyer
50 1.1.1.2.2.2 bouyer #ifdef ACPI_APPLICATION
51 1.1.1.2.2.2 bouyer #include "actables.h"
52 1.1.1.2.2.2 bouyer #endif
53 1.1.1.2.2.2 bouyer
54 1.1.1.2.2.2 bouyer #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
55 1.1.1.2.2.2 bouyer
56 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_CA_DEBUGGER
57 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("dbfileio")
58 1.1.1.2.2.2 bouyer
59 1.1.1.2.2.2 bouyer /*
60 1.1.1.2.2.2 bouyer * NOTE: this is here for lack of a better place. It is used in all
61 1.1.1.2.2.2 bouyer * flavors of the debugger, need LCD file
62 1.1.1.2.2.2 bouyer */
63 1.1.1.2.2.2 bouyer #ifdef ACPI_APPLICATION
64 1.1.1.2.2.2 bouyer #include <stdio.h>
65 1.1.1.2.2.2 bouyer FILE *AcpiGbl_DebugFile = NULL;
66 1.1.1.2.2.2 bouyer #endif
67 1.1.1.2.2.2 bouyer
68 1.1.1.2.2.2 bouyer
69 1.1.1.2.2.2 bouyer #ifdef ACPI_DEBUGGER
70 1.1.1.2.2.2 bouyer
71 1.1.1.2.2.2 bouyer /* Local prototypes */
72 1.1.1.2.2.2 bouyer
73 1.1.1.2.2.2 bouyer #ifdef ACPI_APPLICATION
74 1.1.1.2.2.2 bouyer
75 1.1.1.2.2.2 bouyer static ACPI_STATUS
76 1.1.1.2.2.2 bouyer AcpiDbCheckTextModeCorruption (
77 1.1.1.2.2.2 bouyer UINT8 *Table,
78 1.1.1.2.2.2 bouyer UINT32 TableLength,
79 1.1.1.2.2.2 bouyer UINT32 FileLength);
80 1.1.1.2.2.2 bouyer
81 1.1.1.2.2.2 bouyer #endif
82 1.1.1.2.2.2 bouyer
83 1.1.1.2.2.2 bouyer /*******************************************************************************
84 1.1.1.2.2.2 bouyer *
85 1.1.1.2.2.2 bouyer * FUNCTION: AcpiDbCloseDebugFile
86 1.1.1.2.2.2 bouyer *
87 1.1.1.2.2.2 bouyer * PARAMETERS: None
88 1.1.1.2.2.2 bouyer *
89 1.1.1.2.2.2 bouyer * RETURN: None
90 1.1.1.2.2.2 bouyer *
91 1.1.1.2.2.2 bouyer * DESCRIPTION: If open, close the current debug output file
92 1.1.1.2.2.2 bouyer *
93 1.1.1.2.2.2 bouyer ******************************************************************************/
94 1.1.1.2.2.2 bouyer
95 1.1.1.2.2.2 bouyer void
96 1.1.1.2.2.2 bouyer AcpiDbCloseDebugFile (
97 1.1.1.2.2.2 bouyer void)
98 1.1.1.2.2.2 bouyer {
99 1.1.1.2.2.2 bouyer
100 1.1.1.2.2.2 bouyer #ifdef ACPI_APPLICATION
101 1.1.1.2.2.2 bouyer
102 1.1.1.2.2.2 bouyer if (AcpiGbl_DebugFile)
103 1.1.1.2.2.2 bouyer {
104 1.1.1.2.2.2 bouyer fclose (AcpiGbl_DebugFile);
105 1.1.1.2.2.2 bouyer AcpiGbl_DebugFile = NULL;
106 1.1.1.2.2.2 bouyer AcpiGbl_DbOutputToFile = FALSE;
107 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
108 1.1.1.2.2.2 bouyer }
109 1.1.1.2.2.2 bouyer #endif
110 1.1.1.2.2.2 bouyer }
111 1.1.1.2.2.2 bouyer
112 1.1.1.2.2.2 bouyer
113 1.1.1.2.2.2 bouyer /*******************************************************************************
114 1.1.1.2.2.2 bouyer *
115 1.1.1.2.2.2 bouyer * FUNCTION: AcpiDbOpenDebugFile
116 1.1.1.2.2.2 bouyer *
117 1.1.1.2.2.2 bouyer * PARAMETERS: Name - Filename to open
118 1.1.1.2.2.2 bouyer *
119 1.1.1.2.2.2 bouyer * RETURN: None
120 1.1.1.2.2.2 bouyer *
121 1.1.1.2.2.2 bouyer * DESCRIPTION: Open a file where debug output will be directed.
122 1.1.1.2.2.2 bouyer *
123 1.1.1.2.2.2 bouyer ******************************************************************************/
124 1.1.1.2.2.2 bouyer
125 1.1.1.2.2.2 bouyer void
126 1.1.1.2.2.2 bouyer AcpiDbOpenDebugFile (
127 1.1.1.2.2.2 bouyer char *Name)
128 1.1.1.2.2.2 bouyer {
129 1.1.1.2.2.2 bouyer
130 1.1.1.2.2.2 bouyer #ifdef ACPI_APPLICATION
131 1.1.1.2.2.2 bouyer
132 1.1.1.2.2.2 bouyer AcpiDbCloseDebugFile ();
133 1.1.1.2.2.2 bouyer AcpiGbl_DebugFile = fopen (Name, "w+");
134 1.1.1.2.2.2 bouyer if (AcpiGbl_DebugFile)
135 1.1.1.2.2.2 bouyer {
136 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Debug output file %s opened\n", Name);
137 1.1.1.2.2.2 bouyer ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
138 1.1.1.2.2.2 bouyer AcpiGbl_DbOutputToFile = TRUE;
139 1.1.1.2.2.2 bouyer }
140 1.1.1.2.2.2 bouyer else
141 1.1.1.2.2.2 bouyer {
142 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not open debug file %s\n", Name);
143 1.1.1.2.2.2 bouyer }
144 1.1.1.2.2.2 bouyer
145 1.1.1.2.2.2 bouyer #endif
146 1.1.1.2.2.2 bouyer }
147 1.1.1.2.2.2 bouyer #endif
148 1.1.1.2.2.2 bouyer
149 1.1.1.2.2.2 bouyer
150 1.1.1.2.2.2 bouyer #ifdef ACPI_APPLICATION
151 1.1.1.2.2.2 bouyer /*******************************************************************************
152 1.1.1.2.2.2 bouyer *
153 1.1.1.2.2.2 bouyer * FUNCTION: AcpiDbCheckTextModeCorruption
154 1.1.1.2.2.2 bouyer *
155 1.1.1.2.2.2 bouyer * PARAMETERS: Table - Table buffer
156 1.1.1.2.2.2 bouyer * TableLength - Length of table from the table header
157 1.1.1.2.2.2 bouyer * FileLength - Length of the file that contains the table
158 1.1.1.2.2.2 bouyer *
159 1.1.1.2.2.2 bouyer * RETURN: Status
160 1.1.1.2.2.2 bouyer *
161 1.1.1.2.2.2 bouyer * DESCRIPTION: Check table for text mode file corruption where all linefeed
162 1.1.1.2.2.2 bouyer * characters (LF) have been replaced by carriage return linefeed
163 1.1.1.2.2.2 bouyer * pairs (CR/LF).
164 1.1.1.2.2.2 bouyer *
165 1.1.1.2.2.2 bouyer ******************************************************************************/
166 1.1.1.2.2.2 bouyer
167 1.1.1.2.2.2 bouyer static ACPI_STATUS
168 1.1.1.2.2.2 bouyer AcpiDbCheckTextModeCorruption (
169 1.1.1.2.2.2 bouyer UINT8 *Table,
170 1.1.1.2.2.2 bouyer UINT32 TableLength,
171 1.1.1.2.2.2 bouyer UINT32 FileLength)
172 1.1.1.2.2.2 bouyer {
173 1.1.1.2.2.2 bouyer UINT32 i;
174 1.1.1.2.2.2 bouyer UINT32 Pairs = 0;
175 1.1.1.2.2.2 bouyer
176 1.1.1.2.2.2 bouyer
177 1.1.1.2.2.2 bouyer if (TableLength != FileLength)
178 1.1.1.2.2.2 bouyer {
179 1.1.1.2.2.2 bouyer ACPI_WARNING ((AE_INFO,
180 1.1.1.2.2.2 bouyer "File length (0x%X) is not the same as the table length (0x%X)",
181 1.1.1.2.2.2 bouyer FileLength, TableLength));
182 1.1.1.2.2.2 bouyer }
183 1.1.1.2.2.2 bouyer
184 1.1.1.2.2.2 bouyer /* Scan entire table to determine if each LF has been prefixed with a CR */
185 1.1.1.2.2.2 bouyer
186 1.1.1.2.2.2 bouyer for (i = 1; i < FileLength; i++)
187 1.1.1.2.2.2 bouyer {
188 1.1.1.2.2.2 bouyer if (Table[i] == 0x0A)
189 1.1.1.2.2.2 bouyer {
190 1.1.1.2.2.2 bouyer if (Table[i - 1] != 0x0D)
191 1.1.1.2.2.2 bouyer {
192 1.1.1.2.2.2 bouyer /* The LF does not have a preceding CR, table not corrupted */
193 1.1.1.2.2.2 bouyer
194 1.1.1.2.2.2 bouyer return (AE_OK);
195 1.1.1.2.2.2 bouyer }
196 1.1.1.2.2.2 bouyer else
197 1.1.1.2.2.2 bouyer {
198 1.1.1.2.2.2 bouyer /* Found a CR/LF pair */
199 1.1.1.2.2.2 bouyer
200 1.1.1.2.2.2 bouyer Pairs++;
201 1.1.1.2.2.2 bouyer }
202 1.1.1.2.2.2 bouyer i++;
203 1.1.1.2.2.2 bouyer }
204 1.1.1.2.2.2 bouyer }
205 1.1.1.2.2.2 bouyer
206 1.1.1.2.2.2 bouyer if (!Pairs)
207 1.1.1.2.2.2 bouyer {
208 1.1.1.2.2.2 bouyer return (AE_OK);
209 1.1.1.2.2.2 bouyer }
210 1.1.1.2.2.2 bouyer
211 1.1.1.2.2.2 bouyer /*
212 1.1.1.2.2.2 bouyer * Entire table scanned, each CR is part of a CR/LF pair --
213 1.1.1.2.2.2 bouyer * meaning that the table was treated as a text file somewhere.
214 1.1.1.2.2.2 bouyer *
215 1.1.1.2.2.2 bouyer * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
216 1.1.1.2.2.2 bouyer * original table are left untouched by the text conversion process --
217 1.1.1.2.2.2 bouyer * meaning that we cannot simply replace CR/LF pairs with LFs.
218 1.1.1.2.2.2 bouyer */
219 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
220 1.1.1.2.2.2 bouyer AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
221 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Table cannot be repaired!\n");
222 1.1.1.2.2.2 bouyer return (AE_BAD_VALUE);
223 1.1.1.2.2.2 bouyer }
224 1.1.1.2.2.2 bouyer
225 1.1.1.2.2.2 bouyer
226 1.1.1.2.2.2 bouyer /*******************************************************************************
227 1.1.1.2.2.2 bouyer *
228 1.1.1.2.2.2 bouyer * FUNCTION: AcpiDbReadTable
229 1.1.1.2.2.2 bouyer *
230 1.1.1.2.2.2 bouyer * PARAMETERS: fp - File that contains table
231 1.1.1.2.2.2 bouyer * Table - Return value, buffer with table
232 1.1.1.2.2.2 bouyer * TableLength - Return value, length of table
233 1.1.1.2.2.2 bouyer *
234 1.1.1.2.2.2 bouyer * RETURN: Status
235 1.1.1.2.2.2 bouyer *
236 1.1.1.2.2.2 bouyer * DESCRIPTION: Load the DSDT from the file pointer
237 1.1.1.2.2.2 bouyer *
238 1.1.1.2.2.2 bouyer ******************************************************************************/
239 1.1.1.2.2.2 bouyer
240 1.1.1.2.2.2 bouyer static ACPI_STATUS
241 1.1.1.2.2.2 bouyer AcpiDbReadTable (
242 1.1.1.2.2.2 bouyer FILE *fp,
243 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER **Table,
244 1.1.1.2.2.2 bouyer UINT32 *TableLength)
245 1.1.1.2.2.2 bouyer {
246 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER TableHeader;
247 1.1.1.2.2.2 bouyer UINT32 Actual;
248 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
249 1.1.1.2.2.2 bouyer UINT32 FileSize;
250 1.1.1.2.2.2 bouyer BOOLEAN StandardHeader = TRUE;
251 1.1.1.2.2.2 bouyer
252 1.1.1.2.2.2 bouyer
253 1.1.1.2.2.2 bouyer /* Get the file size */
254 1.1.1.2.2.2 bouyer
255 1.1.1.2.2.2 bouyer fseek (fp, 0, SEEK_END);
256 1.1.1.2.2.2 bouyer FileSize = (UINT32) ftell (fp);
257 1.1.1.2.2.2 bouyer fseek (fp, 0, SEEK_SET);
258 1.1.1.2.2.2 bouyer
259 1.1.1.2.2.2 bouyer if (FileSize < 4)
260 1.1.1.2.2.2 bouyer {
261 1.1.1.2.2.2 bouyer return (AE_BAD_HEADER);
262 1.1.1.2.2.2 bouyer }
263 1.1.1.2.2.2 bouyer
264 1.1.1.2.2.2 bouyer /* Read the signature */
265 1.1.1.2.2.2 bouyer
266 1.1.1.2.2.2 bouyer if (fread (&TableHeader, 1, 4, fp) != 4)
267 1.1.1.2.2.2 bouyer {
268 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not read the table signature\n");
269 1.1.1.2.2.2 bouyer return (AE_BAD_HEADER);
270 1.1.1.2.2.2 bouyer }
271 1.1.1.2.2.2 bouyer
272 1.1.1.2.2.2 bouyer fseek (fp, 0, SEEK_SET);
273 1.1.1.2.2.2 bouyer
274 1.1.1.2.2.2 bouyer /* The RSDT and FACS tables do not have standard ACPI headers */
275 1.1.1.2.2.2 bouyer
276 1.1.1.2.2.2 bouyer if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
277 1.1.1.2.2.2 bouyer ACPI_COMPARE_NAME (TableHeader.Signature, "FACS"))
278 1.1.1.2.2.2 bouyer {
279 1.1.1.2.2.2 bouyer *TableLength = FileSize;
280 1.1.1.2.2.2 bouyer StandardHeader = FALSE;
281 1.1.1.2.2.2 bouyer }
282 1.1.1.2.2.2 bouyer else
283 1.1.1.2.2.2 bouyer {
284 1.1.1.2.2.2 bouyer /* Read the table header */
285 1.1.1.2.2.2 bouyer
286 1.1.1.2.2.2 bouyer if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
287 1.1.1.2.2.2 bouyer sizeof (ACPI_TABLE_HEADER))
288 1.1.1.2.2.2 bouyer {
289 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not read the table header\n");
290 1.1.1.2.2.2 bouyer return (AE_BAD_HEADER);
291 1.1.1.2.2.2 bouyer }
292 1.1.1.2.2.2 bouyer
293 1.1.1.2.2.2 bouyer #if 0
294 1.1.1.2.2.2 bouyer /* Validate the table header/length */
295 1.1.1.2.2.2 bouyer
296 1.1.1.2.2.2 bouyer Status = AcpiTbValidateTableHeader (&TableHeader);
297 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
298 1.1.1.2.2.2 bouyer {
299 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Table header is invalid!\n");
300 1.1.1.2.2.2 bouyer return (Status);
301 1.1.1.2.2.2 bouyer }
302 1.1.1.2.2.2 bouyer #endif
303 1.1.1.2.2.2 bouyer
304 1.1.1.2.2.2 bouyer /* File size must be at least as long as the Header-specified length */
305 1.1.1.2.2.2 bouyer
306 1.1.1.2.2.2 bouyer if (TableHeader.Length > FileSize)
307 1.1.1.2.2.2 bouyer {
308 1.1.1.2.2.2 bouyer AcpiOsPrintf (
309 1.1.1.2.2.2 bouyer "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
310 1.1.1.2.2.2 bouyer TableHeader.Length, FileSize);
311 1.1.1.2.2.2 bouyer return (AE_BAD_HEADER);
312 1.1.1.2.2.2 bouyer }
313 1.1.1.2.2.2 bouyer
314 1.1.1.2.2.2 bouyer #ifdef ACPI_OBSOLETE_CODE
315 1.1.1.2.2.2 bouyer /* We only support a limited number of table types */
316 1.1.1.2.2.2 bouyer
317 1.1.1.2.2.2 bouyer if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
318 1.1.1.2.2.2 bouyer ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
319 1.1.1.2.2.2 bouyer ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
320 1.1.1.2.2.2 bouyer {
321 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
322 1.1.1.2.2.2 bouyer (char *) TableHeader.Signature);
323 1.1.1.2.2.2 bouyer ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
324 1.1.1.2.2.2 bouyer return (AE_ERROR);
325 1.1.1.2.2.2 bouyer }
326 1.1.1.2.2.2 bouyer #endif
327 1.1.1.2.2.2 bouyer
328 1.1.1.2.2.2 bouyer *TableLength = TableHeader.Length;
329 1.1.1.2.2.2 bouyer }
330 1.1.1.2.2.2 bouyer
331 1.1.1.2.2.2 bouyer /* Allocate a buffer for the table */
332 1.1.1.2.2.2 bouyer
333 1.1.1.2.2.2 bouyer *Table = AcpiOsAllocate ((size_t) FileSize);
334 1.1.1.2.2.2 bouyer if (!*Table)
335 1.1.1.2.2.2 bouyer {
336 1.1.1.2.2.2 bouyer AcpiOsPrintf (
337 1.1.1.2.2.2 bouyer "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
338 1.1.1.2.2.2 bouyer TableHeader.Signature, *TableLength);
339 1.1.1.2.2.2 bouyer return (AE_NO_MEMORY);
340 1.1.1.2.2.2 bouyer }
341 1.1.1.2.2.2 bouyer
342 1.1.1.2.2.2 bouyer /* Get the rest of the table */
343 1.1.1.2.2.2 bouyer
344 1.1.1.2.2.2 bouyer fseek (fp, 0, SEEK_SET);
345 1.1.1.2.2.2 bouyer Actual = fread (*Table, 1, (size_t) FileSize, fp);
346 1.1.1.2.2.2 bouyer if (Actual == FileSize)
347 1.1.1.2.2.2 bouyer {
348 1.1.1.2.2.2 bouyer if (StandardHeader)
349 1.1.1.2.2.2 bouyer {
350 1.1.1.2.2.2 bouyer /* Now validate the checksum */
351 1.1.1.2.2.2 bouyer
352 1.1.1.2.2.2 bouyer Status = AcpiTbVerifyChecksum ((void *) *Table,
353 1.1.1.2.2.2 bouyer ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
354 1.1.1.2.2.2 bouyer
355 1.1.1.2.2.2 bouyer if (Status == AE_BAD_CHECKSUM)
356 1.1.1.2.2.2 bouyer {
357 1.1.1.2.2.2 bouyer Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
358 1.1.1.2.2.2 bouyer FileSize, (*Table)->Length);
359 1.1.1.2.2.2 bouyer return (Status);
360 1.1.1.2.2.2 bouyer }
361 1.1.1.2.2.2 bouyer }
362 1.1.1.2.2.2 bouyer return (AE_OK);
363 1.1.1.2.2.2 bouyer }
364 1.1.1.2.2.2 bouyer
365 1.1.1.2.2.2 bouyer if (Actual > 0)
366 1.1.1.2.2.2 bouyer {
367 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
368 1.1.1.2.2.2 bouyer FileSize, Actual);
369 1.1.1.2.2.2 bouyer return (AE_OK);
370 1.1.1.2.2.2 bouyer }
371 1.1.1.2.2.2 bouyer
372 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Error - could not read the table file\n");
373 1.1.1.2.2.2 bouyer AcpiOsFree (*Table);
374 1.1.1.2.2.2 bouyer *Table = NULL;
375 1.1.1.2.2.2 bouyer *TableLength = 0;
376 1.1.1.2.2.2 bouyer
377 1.1.1.2.2.2 bouyer return (AE_ERROR);
378 1.1.1.2.2.2 bouyer }
379 1.1.1.2.2.2 bouyer
380 1.1.1.2.2.2 bouyer
381 1.1.1.2.2.2 bouyer /*******************************************************************************
382 1.1.1.2.2.2 bouyer *
383 1.1.1.2.2.2 bouyer * FUNCTION: AeLocalLoadTable
384 1.1.1.2.2.2 bouyer *
385 1.1.1.2.2.2 bouyer * PARAMETERS: Table - pointer to a buffer containing the entire
386 1.1.1.2.2.2 bouyer * table to be loaded
387 1.1.1.2.2.2 bouyer *
388 1.1.1.2.2.2 bouyer * RETURN: Status
389 1.1.1.2.2.2 bouyer *
390 1.1.1.2.2.2 bouyer * DESCRIPTION: This function is called to load a table from the caller's
391 1.1.1.2.2.2 bouyer * buffer. The buffer must contain an entire ACPI Table including
392 1.1.1.2.2.2 bouyer * a valid header. The header fields will be verified, and if it
393 1.1.1.2.2.2 bouyer * is determined that the table is invalid, the call will fail.
394 1.1.1.2.2.2 bouyer *
395 1.1.1.2.2.2 bouyer ******************************************************************************/
396 1.1.1.2.2.2 bouyer
397 1.1.1.2.2.2 bouyer static ACPI_STATUS
398 1.1.1.2.2.2 bouyer AeLocalLoadTable (
399 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table)
400 1.1.1.2.2.2 bouyer {
401 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
402 1.1.1.2.2.2 bouyer /* ACPI_TABLE_DESC TableInfo; */
403 1.1.1.2.2.2 bouyer
404 1.1.1.2.2.2 bouyer
405 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (AeLocalLoadTable);
406 1.1.1.2.2.2 bouyer #if 0
407 1.1.1.2.2.2 bouyer
408 1.1.1.2.2.2 bouyer
409 1.1.1.2.2.2 bouyer if (!Table)
410 1.1.1.2.2.2 bouyer {
411 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
412 1.1.1.2.2.2 bouyer }
413 1.1.1.2.2.2 bouyer
414 1.1.1.2.2.2 bouyer TableInfo.Pointer = Table;
415 1.1.1.2.2.2 bouyer Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
416 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
417 1.1.1.2.2.2 bouyer {
418 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
419 1.1.1.2.2.2 bouyer }
420 1.1.1.2.2.2 bouyer
421 1.1.1.2.2.2 bouyer /* Install the new table into the local data structures */
422 1.1.1.2.2.2 bouyer
423 1.1.1.2.2.2 bouyer Status = AcpiTbInstallTable (&TableInfo);
424 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
425 1.1.1.2.2.2 bouyer {
426 1.1.1.2.2.2 bouyer if (Status == AE_ALREADY_EXISTS)
427 1.1.1.2.2.2 bouyer {
428 1.1.1.2.2.2 bouyer /* Table already exists, no error */
429 1.1.1.2.2.2 bouyer
430 1.1.1.2.2.2 bouyer Status = AE_OK;
431 1.1.1.2.2.2 bouyer }
432 1.1.1.2.2.2 bouyer
433 1.1.1.2.2.2 bouyer /* Free table allocated by AcpiTbGetTable */
434 1.1.1.2.2.2 bouyer
435 1.1.1.2.2.2 bouyer AcpiTbDeleteSingleTable (&TableInfo);
436 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
437 1.1.1.2.2.2 bouyer }
438 1.1.1.2.2.2 bouyer
439 1.1.1.2.2.2 bouyer #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
440 1.1.1.2.2.2 bouyer
441 1.1.1.2.2.2 bouyer Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
442 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
443 1.1.1.2.2.2 bouyer {
444 1.1.1.2.2.2 bouyer /* Uninstall table and free the buffer */
445 1.1.1.2.2.2 bouyer
446 1.1.1.2.2.2 bouyer AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
447 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
448 1.1.1.2.2.2 bouyer }
449 1.1.1.2.2.2 bouyer #endif
450 1.1.1.2.2.2 bouyer #endif
451 1.1.1.2.2.2 bouyer
452 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
453 1.1.1.2.2.2 bouyer }
454 1.1.1.2.2.2 bouyer
455 1.1.1.2.2.2 bouyer
456 1.1.1.2.2.2 bouyer /*******************************************************************************
457 1.1.1.2.2.2 bouyer *
458 1.1.1.2.2.2 bouyer * FUNCTION: AcpiDbReadTableFromFile
459 1.1.1.2.2.2 bouyer *
460 1.1.1.2.2.2 bouyer * PARAMETERS: Filename - File where table is located
461 1.1.1.2.2.2 bouyer * Table - Where a pointer to the table is returned
462 1.1.1.2.2.2 bouyer *
463 1.1.1.2.2.2 bouyer * RETURN: Status
464 1.1.1.2.2.2 bouyer *
465 1.1.1.2.2.2 bouyer * DESCRIPTION: Get an ACPI table from a file
466 1.1.1.2.2.2 bouyer *
467 1.1.1.2.2.2 bouyer ******************************************************************************/
468 1.1.1.2.2.2 bouyer
469 1.1.1.2.2.2 bouyer ACPI_STATUS
470 1.1.1.2.2.2 bouyer AcpiDbReadTableFromFile (
471 1.1.1.2.2.2 bouyer char *Filename,
472 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER **Table)
473 1.1.1.2.2.2 bouyer {
474 1.1.1.2.2.2 bouyer FILE *fp;
475 1.1.1.2.2.2 bouyer UINT32 TableLength;
476 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
477 1.1.1.2.2.2 bouyer
478 1.1.1.2.2.2 bouyer
479 1.1.1.2.2.2 bouyer /* Open the file */
480 1.1.1.2.2.2 bouyer
481 1.1.1.2.2.2 bouyer fp = fopen (Filename, "rb");
482 1.1.1.2.2.2 bouyer if (!fp)
483 1.1.1.2.2.2 bouyer {
484 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not open input file %s\n", Filename);
485 1.1.1.2.2.2 bouyer return (AE_ERROR);
486 1.1.1.2.2.2 bouyer }
487 1.1.1.2.2.2 bouyer
488 1.1.1.2.2.2 bouyer /* Get the entire file */
489 1.1.1.2.2.2 bouyer
490 1.1.1.2.2.2 bouyer fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
491 1.1.1.2.2.2 bouyer Status = AcpiDbReadTable (fp, Table, &TableLength);
492 1.1.1.2.2.2 bouyer fclose(fp);
493 1.1.1.2.2.2 bouyer
494 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
495 1.1.1.2.2.2 bouyer {
496 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not get table from the file\n");
497 1.1.1.2.2.2 bouyer return (Status);
498 1.1.1.2.2.2 bouyer }
499 1.1.1.2.2.2 bouyer
500 1.1.1.2.2.2 bouyer return (AE_OK);
501 1.1.1.2.2.2 bouyer }
502 1.1.1.2.2.2 bouyer #endif
503 1.1.1.2.2.2 bouyer
504 1.1.1.2.2.2 bouyer
505 1.1.1.2.2.2 bouyer /*******************************************************************************
506 1.1.1.2.2.2 bouyer *
507 1.1.1.2.2.2 bouyer * FUNCTION: AcpiDbGetTableFromFile
508 1.1.1.2.2.2 bouyer *
509 1.1.1.2.2.2 bouyer * PARAMETERS: Filename - File where table is located
510 1.1.1.2.2.2 bouyer * ReturnTable - Where a pointer to the table is returned
511 1.1.1.2.2.2 bouyer *
512 1.1.1.2.2.2 bouyer * RETURN: Status
513 1.1.1.2.2.2 bouyer *
514 1.1.1.2.2.2 bouyer * DESCRIPTION: Load an ACPI table from a file
515 1.1.1.2.2.2 bouyer *
516 1.1.1.2.2.2 bouyer ******************************************************************************/
517 1.1.1.2.2.2 bouyer
518 1.1.1.2.2.2 bouyer ACPI_STATUS
519 1.1.1.2.2.2 bouyer AcpiDbGetTableFromFile (
520 1.1.1.2.2.2 bouyer char *Filename,
521 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER **ReturnTable)
522 1.1.1.2.2.2 bouyer {
523 1.1.1.2.2.2 bouyer #ifdef ACPI_APPLICATION
524 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
525 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table;
526 1.1.1.2.2.2 bouyer BOOLEAN IsAmlTable = TRUE;
527 1.1.1.2.2.2 bouyer
528 1.1.1.2.2.2 bouyer
529 1.1.1.2.2.2 bouyer Status = AcpiDbReadTableFromFile (Filename, &Table);
530 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
531 1.1.1.2.2.2 bouyer {
532 1.1.1.2.2.2 bouyer return (Status);
533 1.1.1.2.2.2 bouyer }
534 1.1.1.2.2.2 bouyer
535 1.1.1.2.2.2 bouyer #ifdef ACPI_DATA_TABLE_DISASSEMBLY
536 1.1.1.2.2.2 bouyer IsAmlTable = AcpiUtIsAmlTable (Table);
537 1.1.1.2.2.2 bouyer #endif
538 1.1.1.2.2.2 bouyer
539 1.1.1.2.2.2 bouyer if (IsAmlTable)
540 1.1.1.2.2.2 bouyer {
541 1.1.1.2.2.2 bouyer /* Attempt to recognize and install the table */
542 1.1.1.2.2.2 bouyer
543 1.1.1.2.2.2 bouyer Status = AeLocalLoadTable (Table);
544 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
545 1.1.1.2.2.2 bouyer {
546 1.1.1.2.2.2 bouyer if (Status == AE_ALREADY_EXISTS)
547 1.1.1.2.2.2 bouyer {
548 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Table %4.4s is already installed\n",
549 1.1.1.2.2.2 bouyer Table->Signature);
550 1.1.1.2.2.2 bouyer }
551 1.1.1.2.2.2 bouyer else
552 1.1.1.2.2.2 bouyer {
553 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not install table, %s\n",
554 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
555 1.1.1.2.2.2 bouyer }
556 1.1.1.2.2.2 bouyer
557 1.1.1.2.2.2 bouyer return (Status);
558 1.1.1.2.2.2 bouyer }
559 1.1.1.2.2.2 bouyer
560 1.1.1.2.2.2 bouyer fprintf (stderr,
561 1.1.1.2.2.2 bouyer "Acpi table [%4.4s] successfully installed and loaded\n",
562 1.1.1.2.2.2 bouyer Table->Signature);
563 1.1.1.2.2.2 bouyer }
564 1.1.1.2.2.2 bouyer
565 1.1.1.2.2.2 bouyer AcpiGbl_AcpiHardwarePresent = FALSE;
566 1.1.1.2.2.2 bouyer if (ReturnTable)
567 1.1.1.2.2.2 bouyer {
568 1.1.1.2.2.2 bouyer *ReturnTable = Table;
569 1.1.1.2.2.2 bouyer }
570 1.1.1.2.2.2 bouyer
571 1.1.1.2.2.2 bouyer
572 1.1.1.2.2.2 bouyer #endif /* ACPI_APPLICATION */
573 1.1.1.2.2.2 bouyer return (AE_OK);
574 1.1.1.2.2.2 bouyer }
575 1.1.1.2.2.2 bouyer
576 1.1.1.2.2.2 bouyer #endif /* ACPI_DEBUGGER */
577 1.1.1.2.2.2 bouyer
578