tbprint.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /******************************************************************************
  2. *
  3. * Module Name: tbprint - Table output utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, 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 (!ACPI_IS_PRINT(*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. ACPI_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. /*
  116. * The reason that the Address is cast to a void pointer is so that we
  117. * can use %p which will work properly on both 32-bit and 64-bit hosts.
  118. */
  119. if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
  120. /* FACS only has signature and length fields */
  121. ACPI_INFO((AE_INFO, "%4.4s %p %05X",
  122. header->signature, ACPI_CAST_PTR(void, address),
  123. header->length));
  124. } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
  125. /* RSDP has no common fields */
  126. ACPI_MEMCPY(local_header.oem_id,
  127. ACPI_CAST_PTR(struct acpi_table_rsdp,
  128. header)->oem_id, ACPI_OEM_ID_SIZE);
  129. acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
  130. ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
  131. ACPI_CAST_PTR(void, address),
  132. (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
  133. revision >
  134. 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
  135. header)->length : 20,
  136. ACPI_CAST_PTR(struct acpi_table_rsdp,
  137. header)->revision,
  138. local_header.oem_id));
  139. } else {
  140. /* Standard ACPI table with full common header */
  141. acpi_tb_cleanup_table_header(&local_header, header);
  142. ACPI_INFO((AE_INFO,
  143. "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
  144. local_header.signature, ACPI_CAST_PTR(void, address),
  145. local_header.length, local_header.revision,
  146. local_header.oem_id, local_header.oem_table_id,
  147. local_header.oem_revision,
  148. local_header.asl_compiler_id,
  149. local_header.asl_compiler_revision));
  150. }
  151. }
  152. /*******************************************************************************
  153. *
  154. * FUNCTION: acpi_tb_validate_checksum
  155. *
  156. * PARAMETERS: table - ACPI table to verify
  157. * length - Length of entire table
  158. *
  159. * RETURN: Status
  160. *
  161. * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
  162. * exception on bad checksum.
  163. *
  164. ******************************************************************************/
  165. acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
  166. {
  167. u8 checksum;
  168. /* Compute the checksum on the table */
  169. checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
  170. /* Checksum ok? (should be zero) */
  171. if (checksum) {
  172. ACPI_BIOS_WARNING((AE_INFO,
  173. "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
  174. "should be 0x%2.2X",
  175. table->signature, table->checksum,
  176. (u8)(table->checksum - checksum)));
  177. #if (ACPI_CHECKSUM_ABORT)
  178. return (AE_BAD_CHECKSUM);
  179. #endif
  180. }
  181. return (AE_OK);
  182. }
  183. /*******************************************************************************
  184. *
  185. * FUNCTION: acpi_tb_checksum
  186. *
  187. * PARAMETERS: buffer - Pointer to memory region to be checked
  188. * length - Length of this memory region
  189. *
  190. * RETURN: Checksum (u8)
  191. *
  192. * DESCRIPTION: Calculates circular checksum of memory region.
  193. *
  194. ******************************************************************************/
  195. u8 acpi_tb_checksum(u8 *buffer, u32 length)
  196. {
  197. u8 sum = 0;
  198. u8 *end = buffer + length;
  199. while (buffer < end) {
  200. sum = (u8)(sum + *(buffer++));
  201. }
  202. return (sum);
  203. }