Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. acpidtct.c
  6. Abstract:
  7. This module peruses the ACPI tables looking for specific
  8. entries.
  9. Author:
  10. Matt Holle (matth) (shamefully stolen from jakeo's x86 code)
  11. Environment:
  12. Revision History:
  13. --*/
  14. #include "stdlib.h"
  15. #include "string.h"
  16. #include "bldr.h"
  17. #include "acpitabl.h"
  18. extern PVOID AcpiTable;
  19. PDESCRIPTION_HEADER
  20. BlFindACPITable(
  21. IN PCHAR TableName,
  22. IN ULONG TableLength
  23. )
  24. /*++
  25. Routine Description:
  26. Given a table name, finds that table in the ACPI BIOS
  27. Arguments:
  28. TableName - Supplies the table name
  29. TableLength - Supplies the length of the table to map
  30. Return Value:
  31. Pointer to the table if found
  32. NULL if the table is not found
  33. Note:
  34. This function is not capable of returning a pointer to
  35. a table with a signature of DSDT. But that's never necessary
  36. in the loader. If the loader ever incorporates an AML
  37. interpreter, this will have to be enhanced.
  38. --*/
  39. {
  40. ULONG Signature;
  41. PDESCRIPTION_HEADER Header;
  42. ULONG TableCount;
  43. ULONG i;
  44. PXSDT xsdt = NULL;
  45. PRSDP rsdp = (PRSDP)AcpiTable;
  46. char buffer[20] = {0};
  47. //DbgPrint("Hunting for table %s\n", TableName);
  48. //
  49. // Sanity Check.
  50. //
  51. if (rsdp) {
  52. //DbgPrint("Looking through 2.0 RSDP: %p\n", rsdp20);
  53. xsdt = (PVOID)rsdp->XsdtAddress.QuadPart;
  54. if (xsdt->Header.Signature != XSDT_SIGNATURE) {
  55. //
  56. // Found ACPI 2.0 tables, but the signature
  57. // is garbage.
  58. //
  59. return NULL;
  60. }
  61. } else {
  62. //
  63. // Didn't find any tables at all.
  64. //
  65. return NULL;
  66. }
  67. Signature = *((ULONG UNALIGNED *)TableName);
  68. //
  69. // If they want the root table, we've already got that.
  70. //
  71. if (Signature == XSDT_SIGNATURE) {
  72. return(&xsdt->Header);
  73. } else {
  74. TableCount = NumTableEntriesFromXSDTPointer(xsdt);
  75. //DbgPrint("xSDT contains %d tables\n", TableCount);
  76. //
  77. // Sanity check.
  78. //
  79. if( TableCount > 0x100 ) {
  80. return(NULL);
  81. }
  82. //
  83. // Dig.
  84. //
  85. for (i=0;i<TableCount;i++) {
  86. Header = (PDESCRIPTION_HEADER)(xsdt->Tables[i].QuadPart);
  87. if (Header->Signature == Signature) {
  88. //DbgPrint("Table Address: %p\n", Header);
  89. return(Header);
  90. }
  91. }
  92. }
  93. //DbgPrint("Table not found\n");
  94. return(NULL);
  95. }