tbprint.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /******************************************************************************
  2. *
  3. * Module Name: tbprint - Table output utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "actables.h"
  45. #define _COMPONENT ACPI_TABLES
  46. ACPI_MODULE_NAME("tbprint")
  47. /* Local prototypes */
  48. static void acpi_tb_fix_string(char *string, acpi_size length);
  49. static void
  50. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  51. struct acpi_table_header *header);
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_tb_fix_string
  55. *
  56. * PARAMETERS: string - String to be repaired
  57. * length - Maximum length
  58. *
  59. * RETURN: None
  60. *
  61. * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
  62. * with a question mark '?'.
  63. *
  64. ******************************************************************************/
  65. static void acpi_tb_fix_string(char *string, acpi_size length)
  66. {
  67. while (length && *string) {
  68. if (!isprint((int)*string)) {
  69. *string = '?';
  70. }
  71. string++;
  72. length--;
  73. }
  74. }
  75. /*******************************************************************************
  76. *
  77. * FUNCTION: acpi_tb_cleanup_table_header
  78. *
  79. * PARAMETERS: out_header - Where the cleaned header is returned
  80. * header - Input ACPI table header
  81. *
  82. * RETURN: Returns the cleaned header in out_header
  83. *
  84. * DESCRIPTION: Copy the table header and ensure that all "string" fields in
  85. * the header consist of printable characters.
  86. *
  87. ******************************************************************************/
  88. static void
  89. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  90. struct acpi_table_header *header)
  91. {
  92. memcpy(out_header, header, sizeof(struct acpi_table_header));
  93. acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE);
  94. acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
  95. acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
  96. acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE);
  97. }
  98. /*******************************************************************************
  99. *
  100. * FUNCTION: acpi_tb_print_table_header
  101. *
  102. * PARAMETERS: address - Table physical address
  103. * header - Table header
  104. *
  105. * RETURN: None
  106. *
  107. * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
  108. *
  109. ******************************************************************************/
  110. void
  111. acpi_tb_print_table_header(acpi_physical_address address,
  112. struct acpi_table_header *header)
  113. {
  114. struct acpi_table_header local_header;
  115. if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
  116. /* FACS only has signature and length fields */
  117. ACPI_INFO((AE_INFO, "%-4.4s 0x%8.8X%8.8X %06X",
  118. header->signature, ACPI_FORMAT_UINT64(address),
  119. header->length));
  120. } else if (ACPI_VALIDATE_RSDP_SIG(header->signature)) {
  121. /* RSDP has no common fields */
  122. memcpy(local_header.oem_id,
  123. ACPI_CAST_PTR(struct acpi_table_rsdp, header)->oem_id,
  124. ACPI_OEM_ID_SIZE);
  125. acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
  126. ACPI_INFO((AE_INFO, "RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)",
  127. ACPI_FORMAT_UINT64(address),
  128. (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
  129. revision >
  130. 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
  131. header)->length : 20,
  132. ACPI_CAST_PTR(struct acpi_table_rsdp,
  133. header)->revision,
  134. local_header.oem_id));
  135. } else {
  136. /* Standard ACPI table with full common header */
  137. acpi_tb_cleanup_table_header(&local_header, header);
  138. ACPI_INFO((AE_INFO,
  139. "%-4.4s 0x%8.8X%8.8X"
  140. " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
  141. local_header.signature, ACPI_FORMAT_UINT64(address),
  142. local_header.length, local_header.revision,
  143. local_header.oem_id, local_header.oem_table_id,
  144. local_header.oem_revision,
  145. local_header.asl_compiler_id,
  146. local_header.asl_compiler_revision));
  147. }
  148. }
  149. /*******************************************************************************
  150. *
  151. * FUNCTION: acpi_tb_validate_checksum
  152. *
  153. * PARAMETERS: table - ACPI table to verify
  154. * length - Length of entire table
  155. *
  156. * RETURN: Status
  157. *
  158. * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
  159. * exception on bad checksum.
  160. *
  161. ******************************************************************************/
  162. acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
  163. {
  164. u8 checksum;
  165. /*
  166. * FACS/S3PT:
  167. * They are the odd tables, have no standard ACPI header and no checksum
  168. */
  169. if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_S3PT) ||
  170. ACPI_COMPARE_NAME(table->signature, ACPI_SIG_FACS)) {
  171. return (AE_OK);
  172. }
  173. /* Compute the checksum on the table */
  174. checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
  175. /* Checksum ok? (should be zero) */
  176. if (checksum) {
  177. ACPI_BIOS_WARNING((AE_INFO,
  178. "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
  179. "should be 0x%2.2X",
  180. table->signature, table->checksum,
  181. (u8)(table->checksum - checksum)));
  182. #if (ACPI_CHECKSUM_ABORT)
  183. return (AE_BAD_CHECKSUM);
  184. #endif
  185. }
  186. return (AE_OK);
  187. }
  188. /*******************************************************************************
  189. *
  190. * FUNCTION: acpi_tb_checksum
  191. *
  192. * PARAMETERS: buffer - Pointer to memory region to be checked
  193. * length - Length of this memory region
  194. *
  195. * RETURN: Checksum (u8)
  196. *
  197. * DESCRIPTION: Calculates circular checksum of memory region.
  198. *
  199. ******************************************************************************/
  200. u8 acpi_tb_checksum(u8 *buffer, u32 length)
  201. {
  202. u8 sum = 0;
  203. u8 *end = buffer + length;
  204. while (buffer < end) {
  205. sum = (u8)(sum + *(buffer++));
  206. }
  207. return (sum);
  208. }