tbprint.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 - 2025, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "actables.h"
  12. #include "acutils.h"
  13. #define _COMPONENT ACPI_TABLES
  14. ACPI_MODULE_NAME("tbprint")
  15. /* Local prototypes */
  16. static void acpi_tb_fix_string(char *string, acpi_size length);
  17. static void
  18. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  19. struct acpi_table_header *header);
  20. /*******************************************************************************
  21. *
  22. * FUNCTION: acpi_tb_fix_string
  23. *
  24. * PARAMETERS: string - String to be repaired
  25. * length - Maximum length
  26. *
  27. * RETURN: None
  28. *
  29. * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
  30. * with a question mark '?'.
  31. *
  32. ******************************************************************************/
  33. static void acpi_tb_fix_string(char *string, acpi_size length)
  34. {
  35. while (length && *string) {
  36. if (!isprint((int)(u8)*string)) {
  37. *string = '?';
  38. }
  39. string++;
  40. length--;
  41. }
  42. }
  43. /*******************************************************************************
  44. *
  45. * FUNCTION: acpi_tb_cleanup_table_header
  46. *
  47. * PARAMETERS: out_header - Where the cleaned header is returned
  48. * header - Input ACPI table header
  49. *
  50. * RETURN: Returns the cleaned header in out_header
  51. *
  52. * DESCRIPTION: Copy the table header and ensure that all "string" fields in
  53. * the header consist of printable characters.
  54. *
  55. ******************************************************************************/
  56. static void
  57. acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
  58. struct acpi_table_header *header)
  59. {
  60. memcpy(out_header, header, sizeof(struct acpi_table_header));
  61. acpi_tb_fix_string(out_header->signature, ACPI_NAMESEG_SIZE);
  62. acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
  63. acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
  64. acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAMESEG_SIZE);
  65. }
  66. /*******************************************************************************
  67. *
  68. * FUNCTION: acpi_tb_print_table_header
  69. *
  70. * PARAMETERS: address - Table physical address
  71. * header - Table header
  72. *
  73. * RETURN: None
  74. *
  75. * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
  76. *
  77. ******************************************************************************/
  78. void
  79. acpi_tb_print_table_header(acpi_physical_address address,
  80. struct acpi_table_header *header)
  81. {
  82. struct acpi_table_header local_header;
  83. #pragma GCC diagnostic push
  84. #if defined(__GNUC__) && __GNUC__ >= 11
  85. #pragma GCC diagnostic ignored "-Wstringop-overread"
  86. #endif
  87. if (ACPI_COMPARE_NAMESEG(header->signature, ACPI_SIG_FACS)) {
  88. /* FACS only has signature and length fields */
  89. ACPI_INFO(("%-4.4s 0x%8.8X%8.8X %06X",
  90. header->signature, ACPI_FORMAT_UINT64(address),
  91. header->length));
  92. } else if (ACPI_VALIDATE_RSDP_SIG(ACPI_CAST_PTR(struct acpi_table_rsdp,
  93. header)->signature)) {
  94. /* RSDP has no common fields */
  95. memcpy(local_header.oem_id,
  96. ACPI_CAST_PTR(struct acpi_table_rsdp, header)->oem_id,
  97. ACPI_OEM_ID_SIZE);
  98. acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
  99. ACPI_INFO(("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)",
  100. ACPI_FORMAT_UINT64(address),
  101. (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
  102. revision >
  103. 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
  104. header)->length : 20,
  105. ACPI_CAST_PTR(struct acpi_table_rsdp,
  106. header)->revision,
  107. local_header.oem_id));
  108. } else if (acpi_gbl_CDAT && !acpi_ut_valid_nameseg(header->signature)) {
  109. /* CDAT does not use the common ACPI table header */
  110. ACPI_INFO(("%-4.4s 0x%8.8X%8.8X %06X",
  111. ACPI_SIG_CDAT, ACPI_FORMAT_UINT64(address),
  112. ACPI_CAST_PTR(struct acpi_table_cdat,
  113. header)->length));
  114. } else {
  115. /* Standard ACPI table with full common header */
  116. acpi_tb_cleanup_table_header(&local_header, header);
  117. ACPI_INFO(("%-4.4s 0x%8.8X%8.8X"
  118. " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
  119. local_header.signature, ACPI_FORMAT_UINT64(address),
  120. local_header.length, local_header.revision,
  121. local_header.oem_id, local_header.oem_table_id,
  122. local_header.oem_revision,
  123. local_header.asl_compiler_id,
  124. local_header.asl_compiler_revision));
  125. }
  126. #pragma GCC diagnostic pop
  127. }