]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
ShellPkg: Add acpiview tool to dump ACPI tables
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Spcr / SpcrParser.c
1 /**
2 SPCR table parser
3
4 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 @par Reference(s):
14 - Microsoft Serial Port Console Redirection Table
15 Specification - Version 1.03 - August 10, 2015.
16 **/
17
18 #include <IndustryStandard/Acpi.h>
19 #include <IndustryStandard/SerialPortConsoleRedirectionTable.h>
20 #include <Library/UefiLib.h>
21 #include "AcpiParser.h"
22 #include "AcpiTableParser.h"
23
24 // Local variables
25 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
26
27 /** This function validates the Interrupt Type.
28
29 @param [in] Ptr Pointer to the start of the field data.
30 @param [in] Context Pointer to context specific information e.g. this
31 could be a pointer to the ACPI table header.
32 */
33 STATIC
34 VOID
35 EFIAPI
36 ValidateInterruptType (
37 IN UINT8* Ptr,
38 IN VOID* Context
39 );
40
41 /** This function validates the Irq.
42
43 @param [in] Ptr Pointer to the start of the field data.
44 @param [in] Context Pointer to context specific information e.g. this
45 could be a pointer to the ACPI table header.
46 */
47 STATIC
48 VOID
49 EFIAPI
50 ValidateIrq (
51 IN UINT8* Ptr,
52 IN VOID* Context
53 );
54
55 /** An ACPI_PARSER array describing the ACPI SPCR Table.
56 */
57 STATIC CONST ACPI_PARSER SpcrParser[] = {
58 PARSE_ACPI_HEADER (&AcpiHdrInfo),
59 {L"Interface Type", 1, 36, L"%d", NULL, NULL, NULL, NULL},
60 {L"Reserved", 3, 37, L"%x %x %x", Dump3Chars, NULL, NULL, NULL},
61 {L"Base Address", 12, 40, NULL, DumpGas, NULL, NULL, NULL},
62 {L"Interrupt Type", 1, 52, L"%d", NULL, NULL, ValidateInterruptType, NULL},
63 {L"IRQ", 1, 53, L"%d", NULL, NULL, ValidateIrq, NULL},
64 {L"Global System Interrupt", 4, 54, L"0x%x", NULL, NULL, NULL, NULL},
65 {L"Baud Rate", 1, 58, L"%d", NULL, NULL, NULL, NULL},
66 {L"Parity", 1, 59, L"%d", NULL, NULL, NULL, NULL},
67 {L"Stop Bits", 1, 60, L"%d", NULL, NULL, NULL, NULL},
68 {L"Flow Control", 1, 61, L"0x%x", NULL, NULL, NULL, NULL},
69 {L"Terminal Type", 1, 62, L"%d", NULL, NULL, NULL, NULL},
70 {L"Reserved", 1, 63, L"%x", NULL, NULL, NULL, NULL},
71
72 {L"PCI Device ID", 2, 64, L"0x%x", NULL, NULL, NULL, NULL},
73 {L"PCI Vendor ID", 2, 66, L"0x%x", NULL, NULL, NULL, NULL},
74 {L"PCI Bus Number", 1, 68, L"0x%x", NULL, NULL, NULL, NULL},
75 {L"PCI Device Number", 1, 69, L"0x%x", NULL, NULL, NULL, NULL},
76 {L"PCI Function Number", 1, 70, L"0x%x", NULL, NULL, NULL, NULL},
77 {L"PCI Flags", 4, 71, L"0x%x", NULL, NULL, NULL, NULL},
78 {L"PCI Segment", 1, 75, L"0x%x", NULL, NULL, NULL, NULL},
79 {L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL}
80 };
81
82 /** This function validates the Interrupt Type.
83
84 @param [in] Ptr Pointer to the start of the field data.
85 @param [in] Context Pointer to context specific information e.g. this
86 could be a pointer to the ACPI table header.
87 */
88 STATIC
89 VOID
90 EFIAPI
91 ValidateInterruptType (
92 IN UINT8* Ptr,
93 IN VOID* Context
94 )
95 {
96 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
97 UINT8 InterruptType = *Ptr;
98 if (InterruptType !=
99 EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC) {
100 IncrementErrorCount ();
101 Print (
102 L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
103 InterruptType
104 );
105 }
106 #endif
107 }
108
109 /** This function validates the Irq.
110
111 @param [in] Ptr Pointer to the start of the field data.
112 @param [in] Context Pointer to context specific information e.g. this
113 could be a pointer to the ACPI table header.
114 */
115 STATIC
116 VOID
117 EFIAPI
118 ValidateIrq (
119 IN UINT8* Ptr,
120 IN VOID* Context
121 )
122 {
123 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
124 UINT8 Irq = *Ptr;
125 if (Irq != 0) {
126 IncrementErrorCount ();
127 Print (
128 L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
129 Irq
130 );
131 }
132 #endif
133 }
134
135 /** This function parses the ACPI SPCR table.
136 When trace is enabled this function parses the SPCR table and
137 traces the ACPI table fields.
138
139 This function also performs validations of the ACPI table fields.
140
141 @param [in] Trace If TRUE, trace the ACPI fields.
142 @param [in] Ptr Pointer to the start of the buffer.
143 @param [in] AcpiTableLength Length of the ACPI table.
144 @param [in] AcpiTableRevision Revision of the ACPI table.
145 */
146 VOID
147 EFIAPI
148 ParseAcpiSpcr (
149 IN BOOLEAN Trace,
150 IN UINT8* Ptr,
151 IN UINT32 AcpiTableLength,
152 IN UINT8 AcpiTableRevision
153 )
154 {
155 if (!Trace) {
156 return;
157 }
158
159 // Dump the SPCR
160 ParseAcpi (
161 TRUE,
162 0,
163 "SPCR",
164 Ptr,
165 AcpiTableLength,
166 PARSER_PARAMS (SpcrParser)
167 );
168 }