SpcrParser.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /** @file
  2. SPCR table parser
  3. Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. @par Reference(s):
  6. - Microsoft Serial Port Console Redirection Table
  7. Specification - Version 1.03 - August 10, 2015.
  8. **/
  9. #include <IndustryStandard/Acpi.h>
  10. #include <IndustryStandard/SerialPortConsoleRedirectionTable.h>
  11. #include <Library/UefiLib.h>
  12. #include "AcpiParser.h"
  13. #include "AcpiTableParser.h"
  14. // Local variables
  15. STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
  16. /**
  17. This function validates the Interrupt Type.
  18. @param [in] Ptr Pointer to the start of the field data.
  19. @param [in] Context Pointer to context specific information e.g. this
  20. could be a pointer to the ACPI table header.
  21. **/
  22. STATIC
  23. VOID
  24. EFIAPI
  25. ValidateInterruptType (
  26. IN UINT8 *Ptr,
  27. IN VOID *Context
  28. )
  29. {
  30. #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
  31. UINT8 InterruptType;
  32. InterruptType = *Ptr;
  33. if (InterruptType !=
  34. EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC)
  35. {
  36. IncrementErrorCount ();
  37. Print (
  38. L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
  39. InterruptType
  40. );
  41. }
  42. #endif
  43. }
  44. /**
  45. This function validates the Irq.
  46. @param [in] Ptr Pointer to the start of the field data.
  47. @param [in] Context Pointer to context specific information e.g. this
  48. could be a pointer to the ACPI table header.
  49. **/
  50. STATIC
  51. VOID
  52. EFIAPI
  53. ValidateIrq (
  54. IN UINT8 *Ptr,
  55. IN VOID *Context
  56. )
  57. {
  58. #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
  59. UINT8 Irq;
  60. Irq = *Ptr;
  61. if (Irq != 0) {
  62. IncrementErrorCount ();
  63. Print (
  64. L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
  65. Irq
  66. );
  67. }
  68. #endif
  69. }
  70. /**
  71. An ACPI_PARSER array describing the ACPI SPCR Table.
  72. **/
  73. STATIC CONST ACPI_PARSER SpcrParser[] = {
  74. PARSE_ACPI_HEADER (&AcpiHdrInfo),
  75. { L"Interface Type", 1, 36, L"%d", NULL, NULL, NULL, NULL },
  76. { L"Reserved", 3, 37, L"%x %x %x", Dump3Chars, NULL, NULL, NULL },
  77. { L"Base Address", 12, 40, NULL, DumpGas, NULL, NULL, NULL },
  78. { L"Interrupt Type", 1, 52, L"%d", NULL, NULL, ValidateInterruptType, NULL },
  79. { L"IRQ", 1, 53, L"%d", NULL, NULL, ValidateIrq, NULL },
  80. { L"Global System Interrupt", 4, 54, L"0x%x", NULL, NULL, NULL, NULL },
  81. { L"Baud Rate", 1, 58, L"%d", NULL, NULL, NULL, NULL },
  82. { L"Parity", 1, 59, L"%d", NULL, NULL, NULL, NULL },
  83. { L"Stop Bits", 1, 60, L"%d", NULL, NULL, NULL, NULL },
  84. { L"Flow Control", 1, 61, L"0x%x", NULL, NULL, NULL, NULL },
  85. { L"Terminal Type", 1, 62, L"%d", NULL, NULL, NULL, NULL },
  86. { L"Reserved", 1, 63, L"%x", NULL, NULL, NULL, NULL },
  87. { L"PCI Device ID", 2, 64, L"0x%x", NULL, NULL, NULL, NULL },
  88. { L"PCI Vendor ID", 2, 66, L"0x%x", NULL, NULL, NULL, NULL },
  89. { L"PCI Bus Number", 1, 68, L"0x%x", NULL, NULL, NULL, NULL },
  90. { L"PCI Device Number", 1, 69, L"0x%x", NULL, NULL, NULL, NULL },
  91. { L"PCI Function Number", 1, 70, L"0x%x", NULL, NULL, NULL, NULL },
  92. { L"PCI Flags", 4, 71, L"0x%x", NULL, NULL, NULL, NULL },
  93. { L"PCI Segment", 1, 75, L"0x%x", NULL, NULL, NULL, NULL },
  94. { L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL }
  95. };
  96. /**
  97. This function parses the ACPI SPCR table.
  98. When trace is enabled this function parses the SPCR table and
  99. traces the ACPI table fields.
  100. This function also performs validations of the ACPI table fields.
  101. @param [in] Trace If TRUE, trace the ACPI fields.
  102. @param [in] Ptr Pointer to the start of the buffer.
  103. @param [in] AcpiTableLength Length of the ACPI table.
  104. @param [in] AcpiTableRevision Revision of the ACPI table.
  105. **/
  106. VOID
  107. EFIAPI
  108. ParseAcpiSpcr (
  109. IN BOOLEAN Trace,
  110. IN UINT8 *Ptr,
  111. IN UINT32 AcpiTableLength,
  112. IN UINT8 AcpiTableRevision
  113. )
  114. {
  115. if (!Trace) {
  116. return;
  117. }
  118. // Dump the SPCR
  119. ParseAcpi (
  120. TRUE,
  121. 0,
  122. "SPCR",
  123. Ptr,
  124. AcpiTableLength,
  125. PARSER_PARAMS (SpcrParser)
  126. );
  127. }