TianoCore EDK2 master
Loading...
Searching...
No Matches
XenAcpiPlatformDxe.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
14
15#include <Protocol/AcpiTable.h>
16#include <Protocol/FdtClient.h>
17
19
33EFIAPI
36 )
37{
39 EFI_STATUS Status;
40 FDT_CLIENT_PROTOCOL *FdtClient;
41 CONST UINT64 *Reg;
42 UINT32 RegSize;
43 UINTN AddressCells, SizeCells;
44 UINT64 RegBase;
45 UINT8 Sum;
46
47 RsdpStructurePtr = NULL;
48 FdtClient = NULL;
49 //
50 // Get the RSDP structure address from DeviceTree
51 //
52 Status = gBS->LocateProtocol (
53 &gFdtClientProtocolGuid,
54 NULL,
55 (VOID **)&FdtClient
56 );
57 ASSERT_EFI_ERROR (Status);
58
59 Status = FdtClient->FindCompatibleNodeReg (
60 FdtClient,
61 "xen,guest-acpi",
62 (CONST VOID **)&Reg,
63 &AddressCells,
64 &SizeCells,
65 &RegSize
66 );
67 if (EFI_ERROR (Status)) {
68 DEBUG ((
69 DEBUG_WARN,
70 "%a: No 'xen,guest-acpi' compatible DT node found\n",
71 __func__
72 ));
73 return EFI_NOT_FOUND;
74 }
75
76 ASSERT (AddressCells == 2);
77 ASSERT (SizeCells == 2);
78 ASSERT (RegSize == 2 * sizeof (UINT64));
79
80 RegBase = SwapBytes64 (Reg[0]);
81 RsdpStructurePtr =
83
84 if (RsdpStructurePtr && (RsdpStructurePtr->Revision >= 2)) {
85 Sum = CalculateSum8 (
86 (CONST UINT8 *)RsdpStructurePtr,
88 );
89 if (Sum != 0) {
90 return EFI_ABORTED;
91 }
92 }
93
94 *RsdpPtr = RsdpStructurePtr;
95 return EFI_SUCCESS;
96}
97
113STATIC
115EFIAPI
117 IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
118 )
119{
120 EFI_STATUS Status;
121 UINTN TableHandle;
122 VOID *CurrentTableEntry;
123 UINTN CurrentTablePointer;
124 EFI_ACPI_DESCRIPTION_HEADER *CurrentTable;
125 UINTN Index;
126 UINTN NumberOfTableEntries;
127 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *XenAcpiRsdpStructurePtr;
132
133 XenAcpiRsdpStructurePtr = NULL;
134 FadtTable = NULL;
135 DsdtTable = NULL;
136 FacsTable = NULL;
137 TableHandle = 0;
138 NumberOfTableEntries = 0;
139
140 //
141 // Try to find Xen ARM ACPI tables
142 //
143 Status = GetXenArmAcpiRsdp (&XenAcpiRsdpStructurePtr);
144 if (EFI_ERROR (Status)) {
145 DEBUG ((DEBUG_INFO, "%a: No RSDP table found\n", __func__));
146 return Status;
147 }
148
149 //
150 // If XSDT table is find, just install its tables.
151 //
152 if (XenAcpiRsdpStructurePtr->XsdtAddress) {
153 //
154 // Retrieve the addresses of XSDT and
155 // calculate the number of its table entries.
156 //
158 XenAcpiRsdpStructurePtr->XsdtAddress;
159 NumberOfTableEntries = (Xsdt->Length -
161 sizeof (UINT64);
162 //
163 // Install ACPI tables found in XSDT.
164 //
165 for (Index = 0; Index < NumberOfTableEntries; Index++) {
166 //
167 // Get the table entry from XSDT
168 //
169 CurrentTableEntry = (VOID *)((UINT8 *)Xsdt +
171 Index * sizeof (UINT64));
172 CurrentTablePointer = (UINTN)*(UINT64 *)CurrentTableEntry;
173 CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *)CurrentTablePointer;
174
175 //
176 // Install the XSDT tables
177 //
178 Status = AcpiProtocol->InstallAcpiTable (
179 AcpiProtocol,
180 CurrentTable,
181 CurrentTable->Length,
182 &TableHandle
183 );
184
185 if (EFI_ERROR (Status)) {
186 return Status;
187 }
188
189 //
190 // Get the FACS and DSDT table address from the table FADT
191 //
192 if (!AsciiStrnCmp ((CHAR8 *)&CurrentTable->Signature, "FACP", 4)) {
194 (UINTN)CurrentTablePointer;
195 DsdtTable = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)FadtTable->Dsdt;
197 (UINTN)FadtTable->FirmwareCtrl;
198 }
199 }
200 }
201
202 //
203 // Install DSDT table.
204 //
205 if (DsdtTable != NULL) {
206 Status = AcpiProtocol->InstallAcpiTable (
207 AcpiProtocol,
208 DsdtTable,
209 DsdtTable->Length,
210 &TableHandle
211 );
212 if (EFI_ERROR (Status)) {
213 return Status;
214 }
215 }
216
217 //
218 // Install FACS table.
219 //
220 if (FacsTable != NULL) {
221 Status = AcpiProtocol->InstallAcpiTable (
222 AcpiProtocol,
223 FacsTable,
224 FacsTable->Length,
225 &TableHandle
226 );
227 if (EFI_ERROR (Status)) {
228 return Status;
229 }
230 }
231
232 return EFI_SUCCESS;
233}
234
235STATIC
238 VOID
239 )
240{
241 EFI_STATUS Status;
242 EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
243
244 AcpiTable = NULL;
245 Status = gBS->LocateProtocol (
246 &gEfiAcpiTableProtocolGuid,
247 NULL,
248 (VOID **)&AcpiTable
249 );
250 ASSERT_EFI_ERROR (Status);
251 return AcpiTable;
252}
253
266EFIAPI
268 IN EFI_HANDLE ImageHandle,
269 IN EFI_SYSTEM_TABLE *SystemTable
270 )
271{
272 EFI_STATUS Status;
273
275 return Status;
276}
UINT64 UINTN
STATIC EFI_ACPI_TABLE_PROTOCOL * FindAcpiTableProtocol(VOID)
Definition: CloudHvAcpi.c:25
UINT8 EFIAPI CalculateSum8(IN CONST UINT8 *Buffer, IN UINTN Length)
Definition: CheckSum.c:33
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
Definition: String.c:872
UINT64 EFIAPI SwapBytes64(IN UINT64 Value)
Definition: SwapBytes64.c:25
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI XenAcpiPlatformEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC EFI_STATUS EFIAPI GetXenArmAcpiRsdp(OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER **RsdpPtr)
STATIC EFI_STATUS EFIAPI InstallXenArmTables(IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol)