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