tbprint.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: tbprint - Table output utilities
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "actables.h"
  12. #define _COMPONENT ACPI_TABLES
  13. ACPI_MODULE_NAME("tbprint")
  14. /* Local prototypes */
  15. static void acpi_tb_fix_string(char *string, acpi_size length);
  16. static void
  17. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  18. struct acpi_table_header *header);
  19. /*******************************************************************************
  20. *
  21. * FUNCTION: acpi_tb_fix_string
  22. *
  23. * PARAMETERS: string - String to be repaired
  24. * length - Maximum length
  25. *
  26. * RETURN: None
  27. *
  28. * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
  29. * with a question mark '?'.
  30. *
  31. ******************************************************************************/
  32. static void acpi_tb_fix_string(char *string, acpi_size length)
  33. {
  34. while (length && *string) {
  35. if (!isprint((int)*string)) {
  36. *string = '?';
  37. }
  38. string++;
  39. length--;
  40. }
  41. }
  42. /*******************************************************************************
  43. *
  44. * FUNCTION: acpi_tb_cleanup_table_header
  45. *
  46. * PARAMETERS: out_header - Where the cleaned header is returned
  47. * header - Input ACPI table header
  48. *
  49. * RETURN: Returns the cleaned header in out_header
  50. *
  51. * DESCRIPTION: Copy the table header and ensure that all "string" fields in
  52. * the header consist of printable characters.
  53. *
  54. ******************************************************************************/
  55. static void
  56. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  57. struct acpi_table_header *header)
  58. {
  59. memcpy(out_header, header, sizeof(struct acpi_table_header));
  60. acpi_tb_fix_string(out_header->signature, ACPI_NAMESEG_SIZE);
  61. acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
  62. acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
  63. acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAMESEG_SIZE);
  64. }
  65. /*******************************************************************************
  66. *
  67. * FUNCTION: acpi_tb_print_table_header
  68. *
  69. * PARAMETERS: address - Table physical address
  70. * header - Table header
  71. *
  72. * RETURN: None
  73. *
  74. * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
  75. *
  76. ******************************************************************************/
  77. void
  78. acpi_tb_print_table_header(acpi_physical_address address,
  79. struct acpi_table_header *header)
  80. {
  81. struct acpi_table_header local_header;
  82. if (ACPI_COMPARE_NAMESEG(header->signature, ACPI_SIG_FACS)) {
  83. /* FACS only has signature and length fields */
  84. ACPI_INFO(("%-4.4s 0x%8.8X%8.8X %06X",
  85. header->signature, ACPI_FORMAT_UINT64(address),
  86. header->length));
  87. } else if (ACPI_VALIDATE_RSDP_SIG(ACPI_CAST_PTR(struct acpi_table_rsdp,
  88. header)->signature)) {
  89. /* RSDP has no common fields */
  90. memcpy(local_header.oem_id,
  91. ACPI_CAST_PTR(struct acpi_table_rsdp, header)->oem_id,
  92. ACPI_OEM_ID_SIZE);
  93. acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
  94. ACPI_INFO(("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)",
  95. ACPI_FORMAT_UINT64(address),
  96. (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
  97. revision >
  98. 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
  99. header)->length : 20,
  100. ACPI_CAST_PTR(struct acpi_table_rsdp,
  101. header)->revision,
  102. local_header.oem_id));
  103. } else {
  104. /* Standard ACPI table with full common header */
  105. acpi_tb_cleanup_table_header(&local_header, header);
  106. ACPI_INFO(("%-4.4s 0x%8.8X%8.8X"
  107. " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
  108. local_header.signature, ACPI_FORMAT_UINT64(address),
  109. local_header.length, local_header.revision,
  110. local_header.oem_id, local_header.oem_table_id,
  111. local_header.oem_revision,
  112. local_header.asl_compiler_id,
  113. local_header.asl_compiler_revision));
  114. }
  115. }
  116. /*******************************************************************************
  117. *
  118. * FUNCTION: acpi_tb_validate_checksum
  119. *
  120. * PARAMETERS: table - ACPI table to verify
  121. * length - Length of entire table
  122. *
  123. * RETURN: Status
  124. *
  125. * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
  126. * exception on bad checksum.
  127. *
  128. ******************************************************************************/
  129. acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
  130. {
  131. u8 checksum;
  132. /*
  133. * FACS/S3PT:
  134. * They are the odd tables, have no standard ACPI header and no checksum
  135. */
  136. if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_S3PT) ||
  137. ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_FACS)) {
  138. return (AE_OK);
  139. }
  140. /* Compute the checksum on the table */
  141. checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
  142. /* Checksum ok? (should be zero) */
  143. if (checksum) {
  144. ACPI_BIOS_WARNING((AE_INFO,
  145. "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
  146. "should be 0x%2.2X",
  147. table->signature, table->checksum,
  148. (u8)(table->checksum - checksum)));
  149. #if (ACPI_CHECKSUM_ABORT)
  150. return (AE_BAD_CHECKSUM);
  151. #endif
  152. }
  153. return (AE_OK);
  154. }
  155. /*******************************************************************************
  156. *
  157. * FUNCTION: acpi_tb_checksum
  158. *
  159. * PARAMETERS: buffer - Pointer to memory region to be checked
  160. * length - Length of this memory region
  161. *
  162. * RETURN: Checksum (u8)
  163. *
  164. * DESCRIPTION: Calculates circular checksum of memory region.
  165. *
  166. ******************************************************************************/
  167. u8 acpi_tb_checksum(u8 *buffer, u32 length)
  168. {
  169. u8 sum = 0;
  170. u8 *end = buffer + length;
  171. while (buffer < end) {
  172. sum = (u8)(sum + *(buffer++));
  173. }
  174. return (sum);
  175. }