Deleted Added
full compact
dbfileio.c (231844) dbfileio.c (235945)
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 - 2012, 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
46#include <contrib/dev/acpica/include/acpi.h>
47#include <contrib/dev/acpica/include/accommon.h>
48#include <contrib/dev/acpica/include/acdebug.h>
49
50#ifdef ACPI_APPLICATION
51#include <contrib/dev/acpica/include/actables.h>
52#endif
53
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 - 2012, 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
46#include <contrib/dev/acpica/include/acpi.h>
47#include <contrib/dev/acpica/include/accommon.h>
48#include <contrib/dev/acpica/include/acdebug.h>
49
50#ifdef ACPI_APPLICATION
51#include <contrib/dev/acpica/include/actables.h>
52#endif
53
54#ifdef ACPI_ASL_COMPILER
55#include <contrib/dev/acpica/compiler/aslcompiler.h>
56#endif
57
54#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
55
56#define _COMPONENT ACPI_CA_DEBUGGER
57 ACPI_MODULE_NAME ("dbfileio")
58
59/*
60 * NOTE: this is here for lack of a better place. It is used in all
61 * flavors of the debugger, need LCD file
62 */
63#ifdef ACPI_APPLICATION
64#include <stdio.h>
65FILE *AcpiGbl_DebugFile = NULL;
66#endif
67
68
69#ifdef ACPI_DEBUGGER
70
71/* Local prototypes */
72
73#ifdef ACPI_APPLICATION
74
75static ACPI_STATUS
76AcpiDbCheckTextModeCorruption (
77 UINT8 *Table,
78 UINT32 TableLength,
79 UINT32 FileLength);
80
81#endif
82
83/*******************************************************************************
84 *
85 * FUNCTION: AcpiDbCloseDebugFile
86 *
87 * PARAMETERS: None
88 *
89 * RETURN: None
90 *
91 * DESCRIPTION: If open, close the current debug output file
92 *
93 ******************************************************************************/
94
95void
96AcpiDbCloseDebugFile (
97 void)
98{
99
100#ifdef ACPI_APPLICATION
101
102 if (AcpiGbl_DebugFile)
103 {
104 fclose (AcpiGbl_DebugFile);
105 AcpiGbl_DebugFile = NULL;
106 AcpiGbl_DbOutputToFile = FALSE;
107 AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
108 }
109#endif
110}
111
112
113/*******************************************************************************
114 *
115 * FUNCTION: AcpiDbOpenDebugFile
116 *
117 * PARAMETERS: Name - Filename to open
118 *
119 * RETURN: None
120 *
121 * DESCRIPTION: Open a file where debug output will be directed.
122 *
123 ******************************************************************************/
124
125void
126AcpiDbOpenDebugFile (
127 char *Name)
128{
129
130#ifdef ACPI_APPLICATION
131
132 AcpiDbCloseDebugFile ();
133 AcpiGbl_DebugFile = fopen (Name, "w+");
134 if (AcpiGbl_DebugFile)
135 {
136 AcpiOsPrintf ("Debug output file %s opened\n", Name);
137 ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
138 AcpiGbl_DbOutputToFile = TRUE;
139 }
140 else
141 {
142 AcpiOsPrintf ("Could not open debug file %s\n", Name);
143 }
144
145#endif
146}
147#endif
148
149
150#ifdef ACPI_APPLICATION
151/*******************************************************************************
152 *
153 * FUNCTION: AcpiDbCheckTextModeCorruption
154 *
155 * PARAMETERS: Table - Table buffer
156 * TableLength - Length of table from the table header
157 * FileLength - Length of the file that contains the table
158 *
159 * RETURN: Status
160 *
161 * DESCRIPTION: Check table for text mode file corruption where all linefeed
162 * characters (LF) have been replaced by carriage return linefeed
163 * pairs (CR/LF).
164 *
165 ******************************************************************************/
166
167static ACPI_STATUS
168AcpiDbCheckTextModeCorruption (
169 UINT8 *Table,
170 UINT32 TableLength,
171 UINT32 FileLength)
172{
173 UINT32 i;
174 UINT32 Pairs = 0;
175
176
177 if (TableLength != FileLength)
178 {
179 ACPI_WARNING ((AE_INFO,
180 "File length (0x%X) is not the same as the table length (0x%X)",
181 FileLength, TableLength));
182 }
183
184 /* Scan entire table to determine if each LF has been prefixed with a CR */
185
186 for (i = 1; i < FileLength; i++)
187 {
188 if (Table[i] == 0x0A)
189 {
190 if (Table[i - 1] != 0x0D)
191 {
192 /* The LF does not have a preceding CR, table not corrupted */
193
194 return (AE_OK);
195 }
196 else
197 {
198 /* Found a CR/LF pair */
199
200 Pairs++;
201 }
202 i++;
203 }
204 }
205
206 if (!Pairs)
207 {
208 return (AE_OK);
209 }
210
211 /*
212 * Entire table scanned, each CR is part of a CR/LF pair --
213 * meaning that the table was treated as a text file somewhere.
214 *
215 * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
216 * original table are left untouched by the text conversion process --
217 * meaning that we cannot simply replace CR/LF pairs with LFs.
218 */
219 AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
220 AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
221 AcpiOsPrintf ("Table cannot be repaired!\n");
222 return (AE_BAD_VALUE);
223}
224
225
226/*******************************************************************************
227 *
228 * FUNCTION: AcpiDbReadTable
229 *
230 * PARAMETERS: fp - File that contains table
231 * Table - Return value, buffer with table
232 * TableLength - Return value, length of table
233 *
234 * RETURN: Status
235 *
236 * DESCRIPTION: Load the DSDT from the file pointer
237 *
238 ******************************************************************************/
239
240static ACPI_STATUS
241AcpiDbReadTable (
242 FILE *fp,
243 ACPI_TABLE_HEADER **Table,
244 UINT32 *TableLength)
245{
246 ACPI_TABLE_HEADER TableHeader;
247 UINT32 Actual;
248 ACPI_STATUS Status;
249 UINT32 FileSize;
250 BOOLEAN StandardHeader = TRUE;
251
252
253 /* Get the file size */
254
255 fseek (fp, 0, SEEK_END);
256 FileSize = (UINT32) ftell (fp);
257 fseek (fp, 0, SEEK_SET);
258
259 if (FileSize < 4)
260 {
261 return (AE_BAD_HEADER);
262 }
263
264 /* Read the signature */
265
266 if (fread (&TableHeader, 1, 4, fp) != 4)
267 {
268 AcpiOsPrintf ("Could not read the table signature\n");
269 return (AE_BAD_HEADER);
270 }
271
272 fseek (fp, 0, SEEK_SET);
273
274 /* The RSDT, FACS and S3PT tables do not have standard ACPI headers */
275
276 if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
277 ACPI_COMPARE_NAME (TableHeader.Signature, "FACS") ||
278 ACPI_COMPARE_NAME (TableHeader.Signature, "S3PT"))
279 {
280 *TableLength = FileSize;
281 StandardHeader = FALSE;
282 }
283 else
284 {
285 /* Read the table header */
286
287 if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
288 sizeof (ACPI_TABLE_HEADER))
289 {
290 AcpiOsPrintf ("Could not read the table header\n");
291 return (AE_BAD_HEADER);
292 }
293
294#if 0
295 /* Validate the table header/length */
296
297 Status = AcpiTbValidateTableHeader (&TableHeader);
298 if (ACPI_FAILURE (Status))
299 {
300 AcpiOsPrintf ("Table header is invalid!\n");
301 return (Status);
302 }
303#endif
304
305 /* File size must be at least as long as the Header-specified length */
306
307 if (TableHeader.Length > FileSize)
308 {
309 AcpiOsPrintf (
310 "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
311 TableHeader.Length, FileSize);
58#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
59
60#define _COMPONENT ACPI_CA_DEBUGGER
61 ACPI_MODULE_NAME ("dbfileio")
62
63/*
64 * NOTE: this is here for lack of a better place. It is used in all
65 * flavors of the debugger, need LCD file
66 */
67#ifdef ACPI_APPLICATION
68#include <stdio.h>
69FILE *AcpiGbl_DebugFile = NULL;
70#endif
71
72
73#ifdef ACPI_DEBUGGER
74
75/* Local prototypes */
76
77#ifdef ACPI_APPLICATION
78
79static ACPI_STATUS
80AcpiDbCheckTextModeCorruption (
81 UINT8 *Table,
82 UINT32 TableLength,
83 UINT32 FileLength);
84
85#endif
86
87/*******************************************************************************
88 *
89 * FUNCTION: AcpiDbCloseDebugFile
90 *
91 * PARAMETERS: None
92 *
93 * RETURN: None
94 *
95 * DESCRIPTION: If open, close the current debug output file
96 *
97 ******************************************************************************/
98
99void
100AcpiDbCloseDebugFile (
101 void)
102{
103
104#ifdef ACPI_APPLICATION
105
106 if (AcpiGbl_DebugFile)
107 {
108 fclose (AcpiGbl_DebugFile);
109 AcpiGbl_DebugFile = NULL;
110 AcpiGbl_DbOutputToFile = FALSE;
111 AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
112 }
113#endif
114}
115
116
117/*******************************************************************************
118 *
119 * FUNCTION: AcpiDbOpenDebugFile
120 *
121 * PARAMETERS: Name - Filename to open
122 *
123 * RETURN: None
124 *
125 * DESCRIPTION: Open a file where debug output will be directed.
126 *
127 ******************************************************************************/
128
129void
130AcpiDbOpenDebugFile (
131 char *Name)
132{
133
134#ifdef ACPI_APPLICATION
135
136 AcpiDbCloseDebugFile ();
137 AcpiGbl_DebugFile = fopen (Name, "w+");
138 if (AcpiGbl_DebugFile)
139 {
140 AcpiOsPrintf ("Debug output file %s opened\n", Name);
141 ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
142 AcpiGbl_DbOutputToFile = TRUE;
143 }
144 else
145 {
146 AcpiOsPrintf ("Could not open debug file %s\n", Name);
147 }
148
149#endif
150}
151#endif
152
153
154#ifdef ACPI_APPLICATION
155/*******************************************************************************
156 *
157 * FUNCTION: AcpiDbCheckTextModeCorruption
158 *
159 * PARAMETERS: Table - Table buffer
160 * TableLength - Length of table from the table header
161 * FileLength - Length of the file that contains the table
162 *
163 * RETURN: Status
164 *
165 * DESCRIPTION: Check table for text mode file corruption where all linefeed
166 * characters (LF) have been replaced by carriage return linefeed
167 * pairs (CR/LF).
168 *
169 ******************************************************************************/
170
171static ACPI_STATUS
172AcpiDbCheckTextModeCorruption (
173 UINT8 *Table,
174 UINT32 TableLength,
175 UINT32 FileLength)
176{
177 UINT32 i;
178 UINT32 Pairs = 0;
179
180
181 if (TableLength != FileLength)
182 {
183 ACPI_WARNING ((AE_INFO,
184 "File length (0x%X) is not the same as the table length (0x%X)",
185 FileLength, TableLength));
186 }
187
188 /* Scan entire table to determine if each LF has been prefixed with a CR */
189
190 for (i = 1; i < FileLength; i++)
191 {
192 if (Table[i] == 0x0A)
193 {
194 if (Table[i - 1] != 0x0D)
195 {
196 /* The LF does not have a preceding CR, table not corrupted */
197
198 return (AE_OK);
199 }
200 else
201 {
202 /* Found a CR/LF pair */
203
204 Pairs++;
205 }
206 i++;
207 }
208 }
209
210 if (!Pairs)
211 {
212 return (AE_OK);
213 }
214
215 /*
216 * Entire table scanned, each CR is part of a CR/LF pair --
217 * meaning that the table was treated as a text file somewhere.
218 *
219 * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
220 * original table are left untouched by the text conversion process --
221 * meaning that we cannot simply replace CR/LF pairs with LFs.
222 */
223 AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
224 AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
225 AcpiOsPrintf ("Table cannot be repaired!\n");
226 return (AE_BAD_VALUE);
227}
228
229
230/*******************************************************************************
231 *
232 * FUNCTION: AcpiDbReadTable
233 *
234 * PARAMETERS: fp - File that contains table
235 * Table - Return value, buffer with table
236 * TableLength - Return value, length of table
237 *
238 * RETURN: Status
239 *
240 * DESCRIPTION: Load the DSDT from the file pointer
241 *
242 ******************************************************************************/
243
244static ACPI_STATUS
245AcpiDbReadTable (
246 FILE *fp,
247 ACPI_TABLE_HEADER **Table,
248 UINT32 *TableLength)
249{
250 ACPI_TABLE_HEADER TableHeader;
251 UINT32 Actual;
252 ACPI_STATUS Status;
253 UINT32 FileSize;
254 BOOLEAN StandardHeader = TRUE;
255
256
257 /* Get the file size */
258
259 fseek (fp, 0, SEEK_END);
260 FileSize = (UINT32) ftell (fp);
261 fseek (fp, 0, SEEK_SET);
262
263 if (FileSize < 4)
264 {
265 return (AE_BAD_HEADER);
266 }
267
268 /* Read the signature */
269
270 if (fread (&TableHeader, 1, 4, fp) != 4)
271 {
272 AcpiOsPrintf ("Could not read the table signature\n");
273 return (AE_BAD_HEADER);
274 }
275
276 fseek (fp, 0, SEEK_SET);
277
278 /* The RSDT, FACS and S3PT tables do not have standard ACPI headers */
279
280 if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
281 ACPI_COMPARE_NAME (TableHeader.Signature, "FACS") ||
282 ACPI_COMPARE_NAME (TableHeader.Signature, "S3PT"))
283 {
284 *TableLength = FileSize;
285 StandardHeader = FALSE;
286 }
287 else
288 {
289 /* Read the table header */
290
291 if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
292 sizeof (ACPI_TABLE_HEADER))
293 {
294 AcpiOsPrintf ("Could not read the table header\n");
295 return (AE_BAD_HEADER);
296 }
297
298#if 0
299 /* Validate the table header/length */
300
301 Status = AcpiTbValidateTableHeader (&TableHeader);
302 if (ACPI_FAILURE (Status))
303 {
304 AcpiOsPrintf ("Table header is invalid!\n");
305 return (Status);
306 }
307#endif
308
309 /* File size must be at least as long as the Header-specified length */
310
311 if (TableHeader.Length > FileSize)
312 {
313 AcpiOsPrintf (
314 "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
315 TableHeader.Length, FileSize);
316
317#ifdef ACPI_ASL_COMPILER
318 Status = FlCheckForAscii (fp, NULL, FALSE);
319 if (ACPI_SUCCESS (Status))
320 {
321 AcpiOsPrintf ("File appears to be ASCII only, must be binary\n",
322 TableHeader.Length, FileSize);
323 }
324#endif
312 return (AE_BAD_HEADER);
313 }
314
315#ifdef ACPI_OBSOLETE_CODE
316 /* We only support a limited number of table types */
317
318 if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
319 ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
320 ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
321 {
322 AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
323 (char *) TableHeader.Signature);
324 ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
325 return (AE_ERROR);
326 }
327#endif
328
329 *TableLength = TableHeader.Length;
330 }
331
332 /* Allocate a buffer for the table */
333
334 *Table = AcpiOsAllocate ((size_t) FileSize);
335 if (!*Table)
336 {
337 AcpiOsPrintf (
338 "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
339 TableHeader.Signature, *TableLength);
340 return (AE_NO_MEMORY);
341 }
342
343 /* Get the rest of the table */
344
345 fseek (fp, 0, SEEK_SET);
346 Actual = fread (*Table, 1, (size_t) FileSize, fp);
347 if (Actual == FileSize)
348 {
349 if (StandardHeader)
350 {
351 /* Now validate the checksum */
352
353 Status = AcpiTbVerifyChecksum ((void *) *Table,
354 ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
355
356 if (Status == AE_BAD_CHECKSUM)
357 {
358 Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
359 FileSize, (*Table)->Length);
360 return (Status);
361 }
362 }
363 return (AE_OK);
364 }
365
366 if (Actual > 0)
367 {
368 AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
369 FileSize, Actual);
370 return (AE_OK);
371 }
372
373 AcpiOsPrintf ("Error - could not read the table file\n");
374 AcpiOsFree (*Table);
375 *Table = NULL;
376 *TableLength = 0;
377
378 return (AE_ERROR);
379}
380
381
382/*******************************************************************************
383 *
384 * FUNCTION: AeLocalLoadTable
385 *
386 * PARAMETERS: Table - pointer to a buffer containing the entire
387 * table to be loaded
388 *
389 * RETURN: Status
390 *
391 * DESCRIPTION: This function is called to load a table from the caller's
392 * buffer. The buffer must contain an entire ACPI Table including
393 * a valid header. The header fields will be verified, and if it
394 * is determined that the table is invalid, the call will fail.
395 *
396 ******************************************************************************/
397
398static ACPI_STATUS
399AeLocalLoadTable (
400 ACPI_TABLE_HEADER *Table)
401{
402 ACPI_STATUS Status = AE_OK;
403/* ACPI_TABLE_DESC TableInfo; */
404
405
406 ACPI_FUNCTION_TRACE (AeLocalLoadTable);
407#if 0
408
409
410 if (!Table)
411 {
412 return_ACPI_STATUS (AE_BAD_PARAMETER);
413 }
414
415 TableInfo.Pointer = Table;
416 Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
417 if (ACPI_FAILURE (Status))
418 {
419 return_ACPI_STATUS (Status);
420 }
421
422 /* Install the new table into the local data structures */
423
424 Status = AcpiTbInstallTable (&TableInfo);
425 if (ACPI_FAILURE (Status))
426 {
427 if (Status == AE_ALREADY_EXISTS)
428 {
429 /* Table already exists, no error */
430
431 Status = AE_OK;
432 }
433
434 /* Free table allocated by AcpiTbGetTable */
435
436 AcpiTbDeleteSingleTable (&TableInfo);
437 return_ACPI_STATUS (Status);
438 }
439
440#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
441
442 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
443 if (ACPI_FAILURE (Status))
444 {
445 /* Uninstall table and free the buffer */
446
447 AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
448 return_ACPI_STATUS (Status);
449 }
450#endif
451#endif
452
453 return_ACPI_STATUS (Status);
454}
455
456
457/*******************************************************************************
458 *
459 * FUNCTION: AcpiDbReadTableFromFile
460 *
461 * PARAMETERS: Filename - File where table is located
462 * Table - Where a pointer to the table is returned
463 *
464 * RETURN: Status
465 *
466 * DESCRIPTION: Get an ACPI table from a file
467 *
468 ******************************************************************************/
469
470ACPI_STATUS
471AcpiDbReadTableFromFile (
472 char *Filename,
473 ACPI_TABLE_HEADER **Table)
474{
475 FILE *fp;
476 UINT32 TableLength;
477 ACPI_STATUS Status;
478
479
480 /* Open the file */
481
482 fp = fopen (Filename, "rb");
483 if (!fp)
484 {
485 AcpiOsPrintf ("Could not open input file %s\n", Filename);
486 return (AE_ERROR);
487 }
488
489 /* Get the entire file */
490
491 fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
492 Status = AcpiDbReadTable (fp, Table, &TableLength);
493 fclose(fp);
494
495 if (ACPI_FAILURE (Status))
496 {
497 AcpiOsPrintf ("Could not get table from the file\n");
498 return (Status);
499 }
500
501 return (AE_OK);
502 }
503#endif
504
505
506/*******************************************************************************
507 *
508 * FUNCTION: AcpiDbGetTableFromFile
509 *
510 * PARAMETERS: Filename - File where table is located
511 * ReturnTable - Where a pointer to the table is returned
512 *
513 * RETURN: Status
514 *
515 * DESCRIPTION: Load an ACPI table from a file
516 *
517 ******************************************************************************/
518
519ACPI_STATUS
520AcpiDbGetTableFromFile (
521 char *Filename,
522 ACPI_TABLE_HEADER **ReturnTable)
523{
524#ifdef ACPI_APPLICATION
525 ACPI_STATUS Status;
526 ACPI_TABLE_HEADER *Table;
527 BOOLEAN IsAmlTable = TRUE;
528
529
530 Status = AcpiDbReadTableFromFile (Filename, &Table);
531 if (ACPI_FAILURE (Status))
532 {
533 return (Status);
534 }
535
536#ifdef ACPI_DATA_TABLE_DISASSEMBLY
537 IsAmlTable = AcpiUtIsAmlTable (Table);
538#endif
539
540 if (IsAmlTable)
541 {
542 /* Attempt to recognize and install the table */
543
544 Status = AeLocalLoadTable (Table);
545 if (ACPI_FAILURE (Status))
546 {
547 if (Status == AE_ALREADY_EXISTS)
548 {
549 AcpiOsPrintf ("Table %4.4s is already installed\n",
550 Table->Signature);
551 }
552 else
553 {
554 AcpiOsPrintf ("Could not install table, %s\n",
555 AcpiFormatException (Status));
556 }
557
558 return (Status);
559 }
560
561 fprintf (stderr,
562 "Acpi table [%4.4s] successfully installed and loaded\n",
563 Table->Signature);
564 }
565
566 AcpiGbl_AcpiHardwarePresent = FALSE;
567 if (ReturnTable)
568 {
569 *ReturnTable = Table;
570 }
571
572
573#endif /* ACPI_APPLICATION */
574 return (AE_OK);
575}
576
577#endif /* ACPI_DEBUGGER */
578
325 return (AE_BAD_HEADER);
326 }
327
328#ifdef ACPI_OBSOLETE_CODE
329 /* We only support a limited number of table types */
330
331 if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
332 ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
333 ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
334 {
335 AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
336 (char *) TableHeader.Signature);
337 ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
338 return (AE_ERROR);
339 }
340#endif
341
342 *TableLength = TableHeader.Length;
343 }
344
345 /* Allocate a buffer for the table */
346
347 *Table = AcpiOsAllocate ((size_t) FileSize);
348 if (!*Table)
349 {
350 AcpiOsPrintf (
351 "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
352 TableHeader.Signature, *TableLength);
353 return (AE_NO_MEMORY);
354 }
355
356 /* Get the rest of the table */
357
358 fseek (fp, 0, SEEK_SET);
359 Actual = fread (*Table, 1, (size_t) FileSize, fp);
360 if (Actual == FileSize)
361 {
362 if (StandardHeader)
363 {
364 /* Now validate the checksum */
365
366 Status = AcpiTbVerifyChecksum ((void *) *Table,
367 ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
368
369 if (Status == AE_BAD_CHECKSUM)
370 {
371 Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
372 FileSize, (*Table)->Length);
373 return (Status);
374 }
375 }
376 return (AE_OK);
377 }
378
379 if (Actual > 0)
380 {
381 AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
382 FileSize, Actual);
383 return (AE_OK);
384 }
385
386 AcpiOsPrintf ("Error - could not read the table file\n");
387 AcpiOsFree (*Table);
388 *Table = NULL;
389 *TableLength = 0;
390
391 return (AE_ERROR);
392}
393
394
395/*******************************************************************************
396 *
397 * FUNCTION: AeLocalLoadTable
398 *
399 * PARAMETERS: Table - pointer to a buffer containing the entire
400 * table to be loaded
401 *
402 * RETURN: Status
403 *
404 * DESCRIPTION: This function is called to load a table from the caller's
405 * buffer. The buffer must contain an entire ACPI Table including
406 * a valid header. The header fields will be verified, and if it
407 * is determined that the table is invalid, the call will fail.
408 *
409 ******************************************************************************/
410
411static ACPI_STATUS
412AeLocalLoadTable (
413 ACPI_TABLE_HEADER *Table)
414{
415 ACPI_STATUS Status = AE_OK;
416/* ACPI_TABLE_DESC TableInfo; */
417
418
419 ACPI_FUNCTION_TRACE (AeLocalLoadTable);
420#if 0
421
422
423 if (!Table)
424 {
425 return_ACPI_STATUS (AE_BAD_PARAMETER);
426 }
427
428 TableInfo.Pointer = Table;
429 Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
430 if (ACPI_FAILURE (Status))
431 {
432 return_ACPI_STATUS (Status);
433 }
434
435 /* Install the new table into the local data structures */
436
437 Status = AcpiTbInstallTable (&TableInfo);
438 if (ACPI_FAILURE (Status))
439 {
440 if (Status == AE_ALREADY_EXISTS)
441 {
442 /* Table already exists, no error */
443
444 Status = AE_OK;
445 }
446
447 /* Free table allocated by AcpiTbGetTable */
448
449 AcpiTbDeleteSingleTable (&TableInfo);
450 return_ACPI_STATUS (Status);
451 }
452
453#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
454
455 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
456 if (ACPI_FAILURE (Status))
457 {
458 /* Uninstall table and free the buffer */
459
460 AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
461 return_ACPI_STATUS (Status);
462 }
463#endif
464#endif
465
466 return_ACPI_STATUS (Status);
467}
468
469
470/*******************************************************************************
471 *
472 * FUNCTION: AcpiDbReadTableFromFile
473 *
474 * PARAMETERS: Filename - File where table is located
475 * Table - Where a pointer to the table is returned
476 *
477 * RETURN: Status
478 *
479 * DESCRIPTION: Get an ACPI table from a file
480 *
481 ******************************************************************************/
482
483ACPI_STATUS
484AcpiDbReadTableFromFile (
485 char *Filename,
486 ACPI_TABLE_HEADER **Table)
487{
488 FILE *fp;
489 UINT32 TableLength;
490 ACPI_STATUS Status;
491
492
493 /* Open the file */
494
495 fp = fopen (Filename, "rb");
496 if (!fp)
497 {
498 AcpiOsPrintf ("Could not open input file %s\n", Filename);
499 return (AE_ERROR);
500 }
501
502 /* Get the entire file */
503
504 fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
505 Status = AcpiDbReadTable (fp, Table, &TableLength);
506 fclose(fp);
507
508 if (ACPI_FAILURE (Status))
509 {
510 AcpiOsPrintf ("Could not get table from the file\n");
511 return (Status);
512 }
513
514 return (AE_OK);
515 }
516#endif
517
518
519/*******************************************************************************
520 *
521 * FUNCTION: AcpiDbGetTableFromFile
522 *
523 * PARAMETERS: Filename - File where table is located
524 * ReturnTable - Where a pointer to the table is returned
525 *
526 * RETURN: Status
527 *
528 * DESCRIPTION: Load an ACPI table from a file
529 *
530 ******************************************************************************/
531
532ACPI_STATUS
533AcpiDbGetTableFromFile (
534 char *Filename,
535 ACPI_TABLE_HEADER **ReturnTable)
536{
537#ifdef ACPI_APPLICATION
538 ACPI_STATUS Status;
539 ACPI_TABLE_HEADER *Table;
540 BOOLEAN IsAmlTable = TRUE;
541
542
543 Status = AcpiDbReadTableFromFile (Filename, &Table);
544 if (ACPI_FAILURE (Status))
545 {
546 return (Status);
547 }
548
549#ifdef ACPI_DATA_TABLE_DISASSEMBLY
550 IsAmlTable = AcpiUtIsAmlTable (Table);
551#endif
552
553 if (IsAmlTable)
554 {
555 /* Attempt to recognize and install the table */
556
557 Status = AeLocalLoadTable (Table);
558 if (ACPI_FAILURE (Status))
559 {
560 if (Status == AE_ALREADY_EXISTS)
561 {
562 AcpiOsPrintf ("Table %4.4s is already installed\n",
563 Table->Signature);
564 }
565 else
566 {
567 AcpiOsPrintf ("Could not install table, %s\n",
568 AcpiFormatException (Status));
569 }
570
571 return (Status);
572 }
573
574 fprintf (stderr,
575 "Acpi table [%4.4s] successfully installed and loaded\n",
576 Table->Signature);
577 }
578
579 AcpiGbl_AcpiHardwarePresent = FALSE;
580 if (ReturnTable)
581 {
582 *ReturnTable = Table;
583 }
584
585
586#endif /* ACPI_APPLICATION */
587 return (AE_OK);
588}
589
590#endif /* ACPI_DEBUGGER */
591