]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Spcr / SpcrParser.c
1 /** @file
2 SPCR table parser
3
4 Copyright (c) 2016 - 2019, 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 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
37 UINT8 InterruptType;
38
39 InterruptType = *Ptr;
40
41 if (InterruptType !=
42 EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC)
43 {
44 IncrementErrorCount ();
45 Print (
46 L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
47 InterruptType
48 );
49 }
50
51 #endif
52 }
53
54 /**
55 This function validates the Irq.
56
57 @param [in] Ptr Pointer to the start of the field data.
58 @param [in] Context Pointer to context specific information e.g. this
59 could be a pointer to the ACPI table header.
60 **/
61 STATIC
62 VOID
63 EFIAPI
64 ValidateIrq (
65 IN UINT8 *Ptr,
66 IN VOID *Context
67 )
68 {
69 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
70 UINT8 Irq;
71
72 Irq = *Ptr;
73
74 if (Irq != 0) {
75 IncrementErrorCount ();
76 Print (
77 L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
78 Irq
79 );
80 }
81
82 #endif
83 }
84
85 /**
86 An ACPI_PARSER array describing the ACPI SPCR Table.
87 **/
88 STATIC CONST ACPI_PARSER SpcrParser[] = {
89 PARSE_ACPI_HEADER (&AcpiHdrInfo),
90 { L"Interface Type", 1, 36, L"%d", NULL, NULL, NULL, NULL },
91 { L"Reserved", 3, 37, L"%x %x %x", Dump3Chars, NULL, NULL, NULL },
92 { L"Base Address", 12, 40, NULL, DumpGas, NULL, NULL, NULL },
93 { L"Interrupt Type", 1, 52, L"%d", NULL, NULL, ValidateInterruptType, NULL },
94 { L"IRQ", 1, 53, L"%d", NULL, NULL, ValidateIrq, NULL },
95 { L"Global System Interrupt", 4, 54, L"0x%x", NULL, NULL, NULL, NULL },
96 { L"Baud Rate", 1, 58, L"%d", NULL, NULL, NULL, NULL },
97 { L"Parity", 1, 59, L"%d", NULL, NULL, NULL, NULL },
98 { L"Stop Bits", 1, 60, L"%d", NULL, NULL, NULL, NULL },
99 { L"Flow Control", 1, 61, L"0x%x", NULL, NULL, NULL, NULL },
100 { L"Terminal Type", 1, 62, L"%d", NULL, NULL, NULL, NULL },
101 { L"Reserved", 1, 63, L"%x", NULL, NULL, NULL, NULL },
102
103 { L"PCI Device ID", 2, 64, L"0x%x", NULL, NULL, NULL, NULL },
104 { L"PCI Vendor ID", 2, 66, L"0x%x", NULL, NULL, NULL, NULL },
105 { L"PCI Bus Number", 1, 68, L"0x%x", NULL, NULL, NULL, NULL },
106 { L"PCI Device Number", 1, 69, L"0x%x", NULL, NULL, NULL, NULL },
107 { L"PCI Function Number", 1, 70, L"0x%x", NULL, NULL, NULL, NULL },
108 { L"PCI Flags", 4, 71, L"0x%x", NULL, NULL, NULL, NULL },
109 { L"PCI Segment", 1, 75, L"0x%x", NULL, NULL, NULL, NULL },
110 { L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL }
111 };
112
113 /**
114 This function parses the ACPI SPCR table.
115 When trace is enabled this function parses the SPCR table and
116 traces the ACPI table fields.
117
118 This function also performs validations of the ACPI table fields.
119
120 @param [in] Trace If TRUE, trace the ACPI fields.
121 @param [in] Ptr Pointer to the start of the buffer.
122 @param [in] AcpiTableLength Length of the ACPI table.
123 @param [in] AcpiTableRevision Revision of the ACPI table.
124 **/
125 VOID
126 EFIAPI
127 ParseAcpiSpcr (
128 IN BOOLEAN Trace,
129 IN UINT8 *Ptr,
130 IN UINT32 AcpiTableLength,
131 IN UINT8 AcpiTableRevision
132 )
133 {
134 if (!Trace) {
135 return;
136 }
137
138 // Dump the SPCR
139 ParseAcpi (
140 TRUE,
141 0,
142 "SPCR",
143 Ptr,
144 AcpiTableLength,
145 PARSER_PARAMS (SpcrParser)
146 );
147 }