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