alltables.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <acpi.h>
  12. #include <accommon.h>
  13. #include <actables.h>
  14. #include <acutils.h>
  15. extern void *ACPIRootPointer;
  16. extern int ACPITableSize;
  17. extern UINT32 AcpiDbgLevel;
  18. /******************************************************************************
  19. *
  20. * FUNCTION: ApGetTableLength
  21. *
  22. * PARAMETERS: Table - Pointer to the table
  23. *
  24. * RETURN: Table length
  25. *
  26. * DESCRIPTION: Obtain table length according to table signature.
  27. *
  28. ******************************************************************************/
  29. /******************************************************************************
  30. *
  31. * FUNCTION: ApIsValidHeader
  32. *
  33. * PARAMETERS: Table - Pointer to table to be validated
  34. *
  35. * RETURN: TRUE if the header appears to be valid. FALSE otherwise
  36. *
  37. * DESCRIPTION: Check for a valid ACPI table header
  38. *
  39. ******************************************************************************/
  40. BOOLEAN
  41. ApIsValidHeader (
  42. ACPI_TABLE_HEADER *Table)
  43. {
  44. if (!ACPI_VALIDATE_RSDP_SIG (Table->Signature))
  45. {
  46. /* Make sure signature is all ASCII and a valid ACPI name */
  47. if (!AcpiUtValidNameseg (Table->Signature))
  48. {
  49. AcpiLogError ("Table signature (0x%8.8X) is invalid\n",
  50. *(UINT32 *) Table->Signature);
  51. return (FALSE);
  52. }
  53. /* Check for minimum table length */
  54. if (Table->Length < sizeof (ACPI_TABLE_HEADER))
  55. {
  56. AcpiLogError ("Table length (0x%8.8X) is invalid\n",
  57. Table->Length);
  58. return (FALSE);
  59. }
  60. }
  61. return (TRUE);
  62. }
  63. UINT32
  64. ApGetTableLength (
  65. ACPI_TABLE_HEADER *Table)
  66. {
  67. ACPI_TABLE_RSDP *Rsdp;
  68. /* Check if table is valid */
  69. if (!ApIsValidHeader (Table))
  70. {
  71. return (0);
  72. }
  73. if (ACPI_VALIDATE_RSDP_SIG (Table->Signature))
  74. {
  75. Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
  76. return (AcpiTbGetRsdpLength (Rsdp));
  77. }
  78. /* Normal ACPI table */
  79. return (Table->Length);
  80. }
  81. void
  82. main(int argc, char *argv[])
  83. {
  84. ACPI_STATUS status;
  85. AcpiDbgLevel = ACPI_LV_VERBOSITY1;
  86. print("hi\n");
  87. status = AcpiInitializeSubsystem();
  88. if (ACPI_FAILURE(status)) {
  89. sysfatal("Error %d\n", status);
  90. }
  91. status = AcpiInitializeTables(NULL, 2048, FALSE);
  92. if (ACPI_FAILURE(status))
  93. sysfatal("can't set up acpi tables: %d", status);
  94. ACPI_TABLE_HEADER *Table;
  95. UINT32 Instance = 0;
  96. ACPI_PHYSICAL_ADDRESS Address;
  97. ACPI_STATUS Status;
  98. int TableStatus;
  99. UINT32 i;
  100. /* Get and dump all available ACPI tables */
  101. for (i = 0; i < 255; i++)
  102. {
  103. Status = AcpiOsGetTableByIndex (i, &Table, &Instance, &Address);
  104. if (ACPI_FAILURE (Status))
  105. {
  106. /* AE_LIMIT means that no more tables are available */
  107. if (Status == AE_LIMIT)
  108. {
  109. break;
  110. }
  111. else if (i == 0)
  112. {
  113. AcpiLogError ("Could not get ACPI tables, %s\n",
  114. AcpiFormatException (Status));
  115. break;
  116. }
  117. else
  118. {
  119. AcpiLogError ("Could not get ACPI table at index %u, %s\n",
  120. i, AcpiFormatException (Status));
  121. continue;
  122. }
  123. }
  124. UINT32 TableLength;
  125. TableLength = ApGetTableLength (Table);
  126. AcpiTbPrintTableHeader (Address, Table);
  127. AcpiUtFilePrintf (1, "%4.4s @ 0x%8.8X%8.8X\n",
  128. Table->Signature, ACPI_FORMAT_UINT64 (Address));
  129. AcpiUtDumpBufferToFile (1,
  130. ACPI_CAST_PTR (UINT8, Table), TableLength,
  131. DB_BYTE_DISPLAY, 0);
  132. AcpiUtFilePrintf (1, "\n");
  133. ACPI_FREE (Table);
  134. if (TableStatus)
  135. {
  136. break;
  137. }
  138. }
  139. #if 0
  140. print("initit dables\n");
  141. status = AcpiLoadTables();
  142. if (ACPI_FAILURE(status))
  143. sysfatal("Can't load ACPI tables: %d", status);
  144. sysfatal("LOADED TABLES. Hi the any key to continue\n"); getchar();
  145. status = AcpiEnableSubsystem(0);
  146. if (ACPI_FAILURE(status))
  147. sysfatal("Can't enable ACPI subsystem");
  148. status = AcpiInitializeObjects(0);
  149. if (ACPI_FAILURE(status))
  150. sysfatal("Can't Initialize ACPI objects");
  151. status = AcpiInitializeDebugger();
  152. if (ACPI_FAILURE(status)) {
  153. sysfatal("Error %d\n", status);
  154. }
  155. print("OK on init.\n");
  156. #endif
  157. exits(0);
  158. }