]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
64340886fe582440088cb58ed7ea4bc7ad147d12
[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 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 /**
28 This function validates the Interrupt Type.
29
30 @param [in] Ptr Pointer to the start of the field data.
31 @param [in] Context Pointer to context specific information e.g. this
32 could be a pointer to the ACPI table header.
33 **/
34 STATIC
35 VOID
36 EFIAPI
37 ValidateInterruptType (
38 IN UINT8* Ptr,
39 IN VOID* Context
40 );
41
42 /**
43 This function validates the Irq.
44
45 @param [in] Ptr Pointer to the start of the field data.
46 @param [in] Context Pointer to context specific information e.g. this
47 could be a pointer to the ACPI table header.
48 **/
49 STATIC
50 VOID
51 EFIAPI
52 ValidateIrq (
53 IN UINT8* Ptr,
54 IN VOID* Context
55 );
56
57 /**
58 An ACPI_PARSER array describing the ACPI SPCR Table.
59 **/
60 STATIC CONST ACPI_PARSER SpcrParser[] = {
61 PARSE_ACPI_HEADER (&AcpiHdrInfo),
62 {L"Interface Type", 1, 36, L"%d", NULL, NULL, NULL, NULL},
63 {L"Reserved", 3, 37, L"%x %x %x", Dump3Chars, NULL, NULL, NULL},
64 {L"Base Address", 12, 40, NULL, DumpGas, NULL, NULL, NULL},
65 {L"Interrupt Type", 1, 52, L"%d", NULL, NULL, ValidateInterruptType, NULL},
66 {L"IRQ", 1, 53, L"%d", NULL, NULL, ValidateIrq, NULL},
67 {L"Global System Interrupt", 4, 54, L"0x%x", NULL, NULL, NULL, NULL},
68 {L"Baud Rate", 1, 58, L"%d", NULL, NULL, NULL, NULL},
69 {L"Parity", 1, 59, L"%d", NULL, NULL, NULL, NULL},
70 {L"Stop Bits", 1, 60, L"%d", NULL, NULL, NULL, NULL},
71 {L"Flow Control", 1, 61, L"0x%x", NULL, NULL, NULL, NULL},
72 {L"Terminal Type", 1, 62, L"%d", NULL, NULL, NULL, NULL},
73 {L"Reserved", 1, 63, L"%x", NULL, NULL, NULL, NULL},
74
75 {L"PCI Device ID", 2, 64, L"0x%x", NULL, NULL, NULL, NULL},
76 {L"PCI Vendor ID", 2, 66, L"0x%x", NULL, NULL, NULL, NULL},
77 {L"PCI Bus Number", 1, 68, L"0x%x", NULL, NULL, NULL, NULL},
78 {L"PCI Device Number", 1, 69, L"0x%x", NULL, NULL, NULL, NULL},
79 {L"PCI Function Number", 1, 70, L"0x%x", NULL, NULL, NULL, NULL},
80 {L"PCI Flags", 4, 71, L"0x%x", NULL, NULL, NULL, NULL},
81 {L"PCI Segment", 1, 75, L"0x%x", NULL, NULL, NULL, NULL},
82 {L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL}
83 };
84
85 /**
86 This function validates the Interrupt Type.
87
88 @param [in] Ptr Pointer to the start of the field data.
89 @param [in] Context Pointer to context specific information e.g. this
90 could be a pointer to the ACPI table header.
91 **/
92 STATIC
93 VOID
94 EFIAPI
95 ValidateInterruptType (
96 IN UINT8* Ptr,
97 IN VOID* Context
98 )
99 {
100 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
101 UINT8 InterruptType = *Ptr;
102 if (InterruptType !=
103 EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC) {
104 IncrementErrorCount ();
105 Print (
106 L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
107 InterruptType
108 );
109 }
110 #endif
111 }
112
113 /**
114 This function validates the Irq.
115
116 @param [in] Ptr Pointer to the start of the field data.
117 @param [in] Context Pointer to context specific information e.g. this
118 could be a pointer to the ACPI table header.
119 **/
120 STATIC
121 VOID
122 EFIAPI
123 ValidateIrq (
124 IN UINT8* Ptr,
125 IN VOID* Context
126 )
127 {
128 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
129 UINT8 Irq = *Ptr;
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 }