2 Xen ARM ACPI Platform Driver using Xen ARM multiboot protocol
4 Copyright (C) 2016, Linaro Ltd. All rights reserved.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/UefiDriverEntryPoint.h>
21 #include <Protocol/AcpiTable.h>
22 #include <Protocol/FdtClient.h>
24 #include <IndustryStandard/Acpi.h>
27 Get the address of Xen ACPI Root System Description Pointer (RSDP)
30 @param RsdpStructurePtr Return pointer to RSDP structure
32 @return EFI_SUCCESS Find Xen RSDP structure successfully.
33 @return EFI_NOT_FOUND Don't find Xen RSDP structure.
34 @return EFI_ABORTED Find Xen RSDP structure, but it's not integrated.
41 OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
**RsdpPtr
44 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*RsdpStructurePtr
;
46 FDT_CLIENT_PROTOCOL
*FdtClient
;
49 UINTN AddressCells
, SizeCells
;
53 RsdpStructurePtr
= NULL
;
56 // Get the RSDP structure address from DeviceTree
58 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
60 ASSERT_EFI_ERROR (Status
);
62 Status
= FdtClient
->FindCompatibleNodeReg (FdtClient
, "xen,guest-acpi",
63 (CONST VOID
**)&Reg
, &AddressCells
, &SizeCells
,
65 if (EFI_ERROR (Status
)) {
66 DEBUG ((EFI_D_WARN
, "%a: No 'xen,guest-acpi' compatible DT node found\n",
71 ASSERT (AddressCells
== 2);
72 ASSERT (SizeCells
== 2);
73 ASSERT (RegSize
== 2 * sizeof (UINT64
));
75 RegBase
= SwapBytes64(Reg
[0]);
76 RsdpStructurePtr
= (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*)RegBase
;
78 if (RsdpStructurePtr
&& RsdpStructurePtr
->Revision
>= 2) {
79 Sum
= CalculateSum8 ((CONST UINT8
*)RsdpStructurePtr
,
80 sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
));
86 *RsdpPtr
= RsdpStructurePtr
;
91 Get Xen Acpi tables from the RSDP structure. And installs Xen ACPI tables
92 into the RSDT/XSDT using InstallAcpiTable. Some signature of the installed
93 ACPI tables are: FACP, APIC, GTDT, DSDT.
95 @param AcpiProtocol Protocol instance pointer.
97 @return EFI_SUCCESS The table was successfully inserted.
98 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableHandle is
99 NULL, or AcpiTableBufferSize and the size
100 field embedded in the ACPI table pointed to
101 by AcpiTableBuffer are not in sync.
102 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
108 InstallXenArmTables (
109 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
114 VOID
*CurrentTableEntry
;
115 UINTN CurrentTablePointer
;
116 EFI_ACPI_DESCRIPTION_HEADER
*CurrentTable
;
118 UINTN NumberOfTableEntries
;
119 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*XenAcpiRsdpStructurePtr
;
120 EFI_ACPI_DESCRIPTION_HEADER
*Xsdt
;
121 EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE
*FadtTable
;
122 EFI_ACPI_DESCRIPTION_HEADER
*DsdtTable
;
124 XenAcpiRsdpStructurePtr
= NULL
;
128 NumberOfTableEntries
= 0;
131 // Try to find Xen ARM ACPI tables
133 Status
= GetXenArmAcpiRsdp (&XenAcpiRsdpStructurePtr
);
134 if (EFI_ERROR (Status
)) {
135 DEBUG ((EFI_D_INFO
, "%a: No RSDP table found\n", __FUNCTION__
));
140 // If XSDT table is find, just install its tables.
142 if (XenAcpiRsdpStructurePtr
->XsdtAddress
) {
144 // Retrieve the addresses of XSDT and
145 // calculate the number of its table entries.
147 Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) (UINTN
)
148 XenAcpiRsdpStructurePtr
->XsdtAddress
;
149 NumberOfTableEntries
= (Xsdt
->Length
-
150 sizeof (EFI_ACPI_DESCRIPTION_HEADER
)) /
153 // Install ACPI tables found in XSDT.
155 for (Index
= 0; Index
< NumberOfTableEntries
; Index
++) {
157 // Get the table entry from XSDT
159 CurrentTableEntry
= (VOID
*) ((UINT8
*) Xsdt
+
160 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
161 Index
* sizeof (UINT64
));
162 CurrentTablePointer
= (UINTN
) *(UINT64
*)CurrentTableEntry
;
163 CurrentTable
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTablePointer
;
166 // Install the XSDT tables
168 Status
= AcpiProtocol
->InstallAcpiTable (
171 CurrentTable
->Length
,
175 if (EFI_ERROR (Status
)) {
180 // Get the FACS and DSDT table address from the table FADT
182 if (!AsciiStrnCmp ((CHAR8
*) &CurrentTable
->Signature
, "FACP", 4)) {
183 FadtTable
= (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE
*)
184 (UINTN
) CurrentTablePointer
;
185 DsdtTable
= (EFI_ACPI_DESCRIPTION_HEADER
*) (UINTN
) FadtTable
->Dsdt
;
191 // Install DSDT table.
193 Status
= AcpiProtocol
->InstallAcpiTable (
199 if (EFI_ERROR (Status
)) {
207 EFI_ACPI_TABLE_PROTOCOL
*
208 FindAcpiTableProtocol (
213 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
216 Status
= gBS
->LocateProtocol (
217 &gEfiAcpiTableProtocolGuid
,
221 ASSERT_EFI_ERROR (Status
);
226 Entrypoint of Xen ARM Acpi Platform driver.
232 @return EFI_LOAD_ERROR
233 @return EFI_OUT_OF_RESOURCES
239 XenAcpiPlatformEntryPoint (
240 IN EFI_HANDLE ImageHandle
,
241 IN EFI_SYSTEM_TABLE
*SystemTable
246 Status
= InstallXenArmTables (FindAcpiTableProtocol ());