| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#include "acpi.h" |
| 45 |
#include "accommon.h" |
| 46 |
#include "acutils.h" |
| 47 |
#include <stdio.h> |
| 48 |
|
| 49 |
#ifdef WIN32 |
| 50 |
#pragma warning(disable:4115) |
| 51 |
#include <windows.h> |
| 52 |
|
| 53 |
#elif WIN64 |
| 54 |
#include <windowsx.h> |
| 55 |
#endif |
| 56 |
|
| 57 |
#define _COMPONENT ACPI_OS_SERVICES |
| 58 |
ACPI_MODULE_NAME ("oswintbl") |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
static char * |
| 63 |
WindowsFormatException ( |
| 64 |
LONG WinStatus); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
#define LOCAL_BUFFER_SIZE 64 |
| 69 |
|
| 70 |
static char KeyBuffer[LOCAL_BUFFER_SIZE]; |
| 71 |
static char ErrorBuffer[LOCAL_BUFFER_SIZE]; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
UINT32 *Gbl_AvailableTableSignatures; |
| 77 |
UINT32 Gbl_TableCount = 0; |
| 78 |
UINT32 Gbl_SsdtInstance = 0; |
| 79 |
|
| 80 |
BOOLEAN Gbl_TableListInitialized = FALSE; |
| 81 |
|
| 82 |
static ACPI_STATUS |
| 83 |
OslTableInitialize ( |
| 84 |
void); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
static char * |
| 101 |
WindowsFormatException ( |
| 102 |
LONG WinStatus) |
| 103 |
{ |
| 104 |
|
| 105 |
ErrorBuffer[0] = 0; |
| 106 |
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, WinStatus, 0, |
| 107 |
ErrorBuffer, LOCAL_BUFFER_SIZE, NULL); |
| 108 |
|
| 109 |
return (ErrorBuffer); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
ACPI_STATUS |
| 130 |
AcpiOsGetTableByAddress ( |
| 131 |
ACPI_PHYSICAL_ADDRESS Address, |
| 132 |
ACPI_TABLE_HEADER **Table) |
| 133 |
{ |
| 134 |
|
| 135 |
fprintf (stderr, "Get table by address is not supported on Windows\n"); |
| 136 |
return (AE_SUPPORT); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
ACPI_STATUS |
| 165 |
AcpiOsGetTableByIndex ( |
| 166 |
UINT32 Index, |
| 167 |
ACPI_TABLE_HEADER **Table, |
| 168 |
UINT32 *Instance, |
| 169 |
ACPI_PHYSICAL_ADDRESS *Address) |
| 170 |
{ |
| 171 |
ACPI_STATUS Status; |
| 172 |
char *Signature; |
| 173 |
UINT32 CurrentInstance; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
Status = OslTableInitialize (); |
| 179 |
if (ACPI_FAILURE (Status)) |
| 180 |
{ |
| 181 |
return (Status); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
if (Index < Gbl_TableCount) |
| 187 |
{ |
| 188 |
Signature = malloc (ACPI_NAMESEG_SIZE + 1); |
| 189 |
if (!Signature) |
| 190 |
{ |
| 191 |
return (AE_NO_MEMORY); |
| 192 |
} |
| 193 |
|
| 194 |
Signature = memmove (Signature, &Gbl_AvailableTableSignatures[Index], ACPI_NAMESEG_SIZE); |
| 195 |
} |
| 196 |
else |
| 197 |
{ |
| 198 |
return (AE_LIMIT); |
| 199 |
} |
| 200 |
|
| 201 |
if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_SSDT)) |
| 202 |
{ |
| 203 |
CurrentInstance = Gbl_SsdtInstance; |
| 204 |
Gbl_SsdtInstance++; |
| 205 |
} |
| 206 |
else |
| 207 |
{ |
| 208 |
CurrentInstance = 0; |
| 209 |
} |
| 210 |
|
| 211 |
Status = AcpiOsGetTableByName (Signature, CurrentInstance, Table, Address); |
| 212 |
if (ACPI_SUCCESS (Status)) |
| 213 |
{ |
| 214 |
*Instance = CurrentInstance; |
| 215 |
} |
| 216 |
else if (Status == AE_NOT_FOUND && |
| 217 |
ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_SSDT)) |
| 218 |
{ |
| 219 |
|
| 220 |
Status = AE_LIMIT; |
| 221 |
} |
| 222 |
|
| 223 |
free (Signature); |
| 224 |
return (Status); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
static ACPI_STATUS |
| 240 |
OslTableInitialize ( |
| 241 |
void) |
| 242 |
{ |
| 243 |
UINT32 ResultSize; |
| 244 |
UINT32 DataSize; |
| 245 |
|
| 246 |
if (Gbl_TableListInitialized) |
| 247 |
{ |
| 248 |
return (AE_OK); |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
DataSize = EnumSystemFirmwareTables ('ACPI', NULL, 0); |
| 256 |
if (DataSize % ACPI_NAMESEG_SIZE) |
| 257 |
{ |
| 258 |
return (AE_ERROR); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
Gbl_TableCount = 2 + DataSize / ACPI_NAMESEG_SIZE; |
| 266 |
Gbl_AvailableTableSignatures = malloc (Gbl_TableCount * ACPI_NAMESEG_SIZE); |
| 267 |
if (!Gbl_AvailableTableSignatures) |
| 268 |
{ |
| 269 |
return (AE_NO_MEMORY); |
| 270 |
} |
| 271 |
|
| 272 |
ResultSize = EnumSystemFirmwareTables ('ACPI', Gbl_AvailableTableSignatures, DataSize); |
| 273 |
if (ResultSize > DataSize) |
| 274 |
{ |
| 275 |
return (AE_ERROR); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
Gbl_AvailableTableSignatures [Gbl_TableCount - 1] = 'TDSD'; |
| 281 |
Gbl_AvailableTableSignatures [Gbl_TableCount - 2] = 'TDSX'; |
| 282 |
|
| 283 |
Gbl_TableListInitialized = TRUE; |
| 284 |
return (AE_OK); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
static ACPI_STATUS |
| 313 |
WindowsGetTableFromRegistry ( |
| 314 |
char *Signature, |
| 315 |
UINT32 Instance, |
| 316 |
ACPI_TABLE_HEADER **Table, |
| 317 |
ACPI_PHYSICAL_ADDRESS *Address) |
| 318 |
{ |
| 319 |
HKEY Handle = NULL; |
| 320 |
LONG WinStatus; |
| 321 |
ULONG Type; |
| 322 |
ULONG NameSize; |
| 323 |
ULONG DataSize; |
| 324 |
HKEY SubKey; |
| 325 |
ULONG i; |
| 326 |
ACPI_TABLE_HEADER *ReturnTable; |
| 327 |
ACPI_STATUS Status = AE_OK; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
while (1) |
| 333 |
{ |
| 334 |
strcpy(KeyBuffer, "HARDWARE\\ACPI\\"); |
| 335 |
if (AcpiUtSafeStrcat(KeyBuffer, sizeof(KeyBuffer), Signature)) |
| 336 |
{ |
| 337 |
return (AE_BUFFER_OVERFLOW); |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
if (Instance > 0 && ACPI_COMPARE_NAMESEG(Signature, ACPI_SIG_SSDT)) |
| 347 |
{ |
| 348 |
if (Instance < 10) |
| 349 |
{ |
| 350 |
KeyBuffer[strlen(KeyBuffer) - 1] = '0' + (char)Instance; |
| 351 |
} |
| 352 |
else if (Instance < 29) |
| 353 |
{ |
| 354 |
KeyBuffer[strlen(KeyBuffer) - 1] = 'A' + (char)(Instance - 10); |
| 355 |
} |
| 356 |
else |
| 357 |
{ |
| 358 |
return (AE_LIMIT); |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
WinStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyBuffer, |
| 363 |
0L, KEY_READ, &Handle); |
| 364 |
|
| 365 |
if (WinStatus != ERROR_SUCCESS) |
| 366 |
{ |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if (ACPI_COMPARE_NAMESEG(Signature, "FACP")) |
| 376 |
{ |
| 377 |
Signature = "FADT"; |
| 378 |
} |
| 379 |
else if (ACPI_COMPARE_NAMESEG(Signature, "XSDT")) |
| 380 |
{ |
| 381 |
Signature = "RSDT"; |
| 382 |
} |
| 383 |
else if (ACPI_COMPARE_NAMESEG(Signature, ACPI_SIG_SSDT)) |
| 384 |
{ |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
return (AE_NOT_FOUND); |
| 390 |
} |
| 391 |
else |
| 392 |
{ |
| 393 |
fprintf(stderr, |
| 394 |
"Could not find %s in registry at %s: %s (WinStatus=0x%X)\n", |
| 395 |
Signature, KeyBuffer, WindowsFormatException(WinStatus), WinStatus); |
| 396 |
return (AE_NOT_FOUND); |
| 397 |
} |
| 398 |
} |
| 399 |
else |
| 400 |
{ |
| 401 |
break; |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
for (i = 0; ;) |
| 408 |
{ |
| 409 |
WinStatus = RegEnumKey(Handle, i, KeyBuffer, sizeof(KeyBuffer)); |
| 410 |
i++; |
| 411 |
if (WinStatus == ERROR_NO_MORE_ITEMS) |
| 412 |
{ |
| 413 |
break; |
| 414 |
} |
| 415 |
|
| 416 |
WinStatus = RegOpenKey(Handle, KeyBuffer, &SubKey); |
| 417 |
if (WinStatus != ERROR_SUCCESS) |
| 418 |
{ |
| 419 |
fprintf(stderr, "Could not open %s entry: %s\n", |
| 420 |
Signature, WindowsFormatException(WinStatus)); |
| 421 |
Status = AE_ERROR; |
| 422 |
goto Cleanup; |
| 423 |
} |
| 424 |
|
| 425 |
RegCloseKey(Handle); |
| 426 |
Handle = SubKey; |
| 427 |
i = 0; |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
for (i = 0; ; i++) |
| 433 |
{ |
| 434 |
NameSize = sizeof(KeyBuffer); |
| 435 |
WinStatus = RegEnumValue(Handle, i, KeyBuffer, &NameSize, NULL, |
| 436 |
&Type, NULL, 0); |
| 437 |
if (WinStatus != ERROR_SUCCESS) |
| 438 |
{ |
| 439 |
fprintf(stderr, "Could not get %s registry entry: %s\n", |
| 440 |
Signature, WindowsFormatException(WinStatus)); |
| 441 |
Status = AE_ERROR; |
| 442 |
goto Cleanup; |
| 443 |
} |
| 444 |
|
| 445 |
if (Type == REG_BINARY) |
| 446 |
{ |
| 447 |
break; |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
WinStatus = RegQueryValueEx(Handle, KeyBuffer, NULL, NULL, |
| 454 |
NULL, &DataSize); |
| 455 |
if (WinStatus != ERROR_SUCCESS) |
| 456 |
{ |
| 457 |
fprintf(stderr, "Could not read the %s table size: %s\n", |
| 458 |
Signature, WindowsFormatException(WinStatus)); |
| 459 |
Status = AE_ERROR; |
| 460 |
goto Cleanup; |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
ReturnTable = malloc(DataSize); |
| 466 |
if (!ReturnTable) |
| 467 |
{ |
| 468 |
Status = AE_NO_MEMORY; |
| 469 |
goto Cleanup; |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
WinStatus = RegQueryValueEx(Handle, KeyBuffer, NULL, NULL, |
| 475 |
(UCHAR *)ReturnTable, &DataSize); |
| 476 |
|
| 477 |
if (WinStatus != ERROR_SUCCESS) |
| 478 |
{ |
| 479 |
fprintf(stderr, "Could not read %s data: %s\n", |
| 480 |
Signature, WindowsFormatException(WinStatus)); |
| 481 |
free(ReturnTable); |
| 482 |
Status = AE_ERROR; |
| 483 |
goto Cleanup; |
| 484 |
} |
| 485 |
|
| 486 |
*Table = ReturnTable; |
| 487 |
*Address = 0; |
| 488 |
|
| 489 |
Cleanup: |
| 490 |
RegCloseKey(Handle); |
| 491 |
return (Status); |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
ACPI_STATUS |
| 520 |
AcpiOsGetTableByName( |
| 521 |
char *Signature, |
| 522 |
UINT32 Instance, |
| 523 |
ACPI_TABLE_HEADER **Table, |
| 524 |
ACPI_PHYSICAL_ADDRESS *Address) |
| 525 |
{ |
| 526 |
LONG Result; |
| 527 |
ACPI_STATUS Status = AE_OK; |
| 528 |
UINT32 DataSize; |
| 529 |
ACPI_TABLE_HEADER *ReturnTable; |
| 530 |
UINT32 UIntSignature = 0; |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
if (Instance > 0 && !ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_SSDT)) |
| 536 |
{ |
| 537 |
return (AE_LIMIT); |
| 538 |
} |
| 539 |
|
| 540 |
if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_SSDT)) |
| 541 |
{ |
| 542 |
Status = WindowsGetTableFromRegistry ("SSDT", Instance, Table, Address); |
| 543 |
return (Status); |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
UIntSignature = *ACPI_CAST_PTR (UINT32, Signature); |
| 549 |
DataSize = GetSystemFirmwareTable('ACPI', UIntSignature, NULL, 0); |
| 550 |
if (!DataSize) |
| 551 |
{ |
| 552 |
fprintf(stderr, "The table signature %s does not exist.", Signature); |
| 553 |
return (AE_ERROR); |
| 554 |
} |
| 555 |
|
| 556 |
ReturnTable = malloc(DataSize); |
| 557 |
if (!ReturnTable) |
| 558 |
{ |
| 559 |
return (AE_NO_MEMORY); |
| 560 |
} |
| 561 |
|
| 562 |
Result = GetSystemFirmwareTable('ACPI', UIntSignature, ReturnTable, DataSize); |
| 563 |
if (Result > (LONG) DataSize) |
| 564 |
{ |
| 565 |
|
| 566 |
|
| 567 |
fprintf (stderr, "Could not read %s data\n", Signature); |
| 568 |
free (ReturnTable); |
| 569 |
return (AE_ERROR); |
| 570 |
} |
| 571 |
|
| 572 |
*Table = ReturnTable; |
| 573 |
return (Status); |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
#ifdef ACPI_DUMP_APP |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
void * |
| 594 |
AcpiOsMapMemory ( |
| 595 |
ACPI_PHYSICAL_ADDRESS Where, |
| 596 |
ACPI_SIZE Length) |
| 597 |
{ |
| 598 |
|
| 599 |
return (ACPI_TO_POINTER ((ACPI_SIZE) Where)); |
| 600 |
} |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
void |
| 618 |
AcpiOsUnmapMemory ( |
| 619 |
void *Where, |
| 620 |
ACPI_SIZE Length) |
| 621 |
{ |
| 622 |
|
| 623 |
return; |
| 624 |
} |
| 625 |
#endif |