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