2 Xen ARM ACPI Platform Driver using Xen ARM multiboot protocol
4 Copyright (C) 2016, Linaro Ltd. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Library/UefiDriverEntryPoint.h>
15 #include <Protocol/AcpiTable.h>
16 #include <Protocol/FdtClient.h>
18 #include <IndustryStandard/Acpi.h>
21 Get the address of Xen ACPI Root System Description Pointer (RSDP)
24 @param RsdpStructurePtr Return pointer to RSDP structure
26 @return EFI_SUCCESS Find Xen RSDP structure successfully.
27 @return EFI_NOT_FOUND Don't find Xen RSDP structure.
28 @return EFI_ABORTED Find Xen RSDP structure, but it's not integrated.
35 OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
**RsdpPtr
38 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*RsdpStructurePtr
;
40 FDT_CLIENT_PROTOCOL
*FdtClient
;
43 UINTN AddressCells
, SizeCells
;
47 RsdpStructurePtr
= NULL
;
50 // Get the RSDP structure address from DeviceTree
52 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
54 ASSERT_EFI_ERROR (Status
);
56 Status
= FdtClient
->FindCompatibleNodeReg (FdtClient
, "xen,guest-acpi",
57 (CONST VOID
**)&Reg
, &AddressCells
, &SizeCells
,
59 if (EFI_ERROR (Status
)) {
60 DEBUG ((EFI_D_WARN
, "%a: No 'xen,guest-acpi' compatible DT node found\n",
65 ASSERT (AddressCells
== 2);
66 ASSERT (SizeCells
== 2);
67 ASSERT (RegSize
== 2 * sizeof (UINT64
));
69 RegBase
= SwapBytes64(Reg
[0]);
71 (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*)(UINTN
)RegBase
;
73 if (RsdpStructurePtr
&& RsdpStructurePtr
->Revision
>= 2) {
74 Sum
= CalculateSum8 ((CONST UINT8
*)RsdpStructurePtr
,
75 sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
));
81 *RsdpPtr
= RsdpStructurePtr
;
86 Get Xen Acpi tables from the RSDP structure. And installs Xen ACPI tables
87 into the RSDT/XSDT using InstallAcpiTable. Some signature of the installed
88 ACPI tables are: FACP, APIC, GTDT, DSDT.
90 @param AcpiProtocol Protocol instance pointer.
92 @return EFI_SUCCESS The table was successfully inserted.
93 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableHandle is
94 NULL, or AcpiTableBufferSize and the size
95 field embedded in the ACPI table pointed to
96 by AcpiTableBuffer are not in sync.
97 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
103 InstallXenArmTables (
104 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
109 VOID
*CurrentTableEntry
;
110 UINTN CurrentTablePointer
;
111 EFI_ACPI_DESCRIPTION_HEADER
*CurrentTable
;
113 UINTN NumberOfTableEntries
;
114 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*XenAcpiRsdpStructurePtr
;
115 EFI_ACPI_DESCRIPTION_HEADER
*Xsdt
;
116 EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE
*FadtTable
;
117 EFI_ACPI_DESCRIPTION_HEADER
*DsdtTable
;
119 XenAcpiRsdpStructurePtr
= NULL
;
123 NumberOfTableEntries
= 0;
126 // Try to find Xen ARM ACPI tables
128 Status
= GetXenArmAcpiRsdp (&XenAcpiRsdpStructurePtr
);
129 if (EFI_ERROR (Status
)) {
130 DEBUG ((EFI_D_INFO
, "%a: No RSDP table found\n", __FUNCTION__
));
135 // If XSDT table is find, just install its tables.
137 if (XenAcpiRsdpStructurePtr
->XsdtAddress
) {
139 // Retrieve the addresses of XSDT and
140 // calculate the number of its table entries.
142 Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) (UINTN
)
143 XenAcpiRsdpStructurePtr
->XsdtAddress
;
144 NumberOfTableEntries
= (Xsdt
->Length
-
145 sizeof (EFI_ACPI_DESCRIPTION_HEADER
)) /
148 // Install ACPI tables found in XSDT.
150 for (Index
= 0; Index
< NumberOfTableEntries
; Index
++) {
152 // Get the table entry from XSDT
154 CurrentTableEntry
= (VOID
*) ((UINT8
*) Xsdt
+
155 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
156 Index
* sizeof (UINT64
));
157 CurrentTablePointer
= (UINTN
) *(UINT64
*)CurrentTableEntry
;
158 CurrentTable
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTablePointer
;
161 // Install the XSDT tables
163 Status
= AcpiProtocol
->InstallAcpiTable (
166 CurrentTable
->Length
,
170 if (EFI_ERROR (Status
)) {
175 // Get the FACS and DSDT table address from the table FADT
177 if (!AsciiStrnCmp ((CHAR8
*) &CurrentTable
->Signature
, "FACP", 4)) {
178 FadtTable
= (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE
*)
179 (UINTN
) CurrentTablePointer
;
180 DsdtTable
= (EFI_ACPI_DESCRIPTION_HEADER
*) (UINTN
) FadtTable
->Dsdt
;
186 // Install DSDT table.
188 Status
= AcpiProtocol
->InstallAcpiTable (
194 if (EFI_ERROR (Status
)) {
202 EFI_ACPI_TABLE_PROTOCOL
*
203 FindAcpiTableProtocol (
208 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
211 Status
= gBS
->LocateProtocol (
212 &gEfiAcpiTableProtocolGuid
,
216 ASSERT_EFI_ERROR (Status
);
221 Entrypoint of Xen ARM Acpi Platform driver.
227 @return EFI_LOAD_ERROR
228 @return EFI_OUT_OF_RESOURCES
234 XenAcpiPlatformEntryPoint (
235 IN EFI_HANDLE ImageHandle
,
236 IN EFI_SYSTEM_TABLE
*SystemTable
241 Status
= InstallXenArmTables (FindAcpiTableProtocol ());