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
;
48 UINT32 RegElemSize
, RegSize
;
52 RsdpStructurePtr
= NULL
;
55 // Get the RSDP structure address from DeviceTree
57 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
59 ASSERT_EFI_ERROR (Status
);
61 Status
= FdtClient
->FindCompatibleNodeReg (FdtClient
, "xen,guest-acpi",
62 (CONST VOID
**)&Reg
, &RegElemSize
, &RegSize
);
63 if (EFI_ERROR (Status
)) {
64 DEBUG ((EFI_D_WARN
, "%a: No 'xen,guest-acpi' compatible DT node found\n",
69 ASSERT (RegSize
== 2 * sizeof (UINT64
));
71 RegBase
= SwapBytes64(Reg
[0]);
72 RsdpStructurePtr
= (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*)RegBase
;
74 if (RsdpStructurePtr
&& RsdpStructurePtr
->Revision
>= 2) {
75 Sum
= CalculateSum8 ((CONST UINT8
*)RsdpStructurePtr
,
76 sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
));
82 *RsdpPtr
= RsdpStructurePtr
;
87 Get Xen Acpi tables from the RSDP structure. And installs Xen ACPI tables
88 into the RSDT/XSDT using InstallAcpiTable. Some signature of the installed
89 ACPI tables are: FACP, APIC, GTDT, DSDT.
91 @param AcpiProtocol Protocol instance pointer.
93 @return EFI_SUCCESS The table was successfully inserted.
94 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableHandle is
95 NULL, or AcpiTableBufferSize and the size
96 field embedded in the ACPI table pointed to
97 by AcpiTableBuffer are not in sync.
98 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
104 InstallXenArmTables (
105 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
110 VOID
*CurrentTableEntry
;
111 UINTN CurrentTablePointer
;
112 EFI_ACPI_DESCRIPTION_HEADER
*CurrentTable
;
114 UINTN NumberOfTableEntries
;
115 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*XenAcpiRsdpStructurePtr
;
116 EFI_ACPI_DESCRIPTION_HEADER
*Xsdt
;
117 EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE
*FadtTable
;
118 EFI_ACPI_DESCRIPTION_HEADER
*DsdtTable
;
120 XenAcpiRsdpStructurePtr
= NULL
;
124 NumberOfTableEntries
= 0;
127 // Try to find Xen ARM ACPI tables
129 Status
= GetXenArmAcpiRsdp (&XenAcpiRsdpStructurePtr
);
130 if (EFI_ERROR (Status
)) {
131 DEBUG ((EFI_D_INFO
, "%a: No RSDP table found\n", __FUNCTION__
));
136 // If XSDT table is find, just install its tables.
138 if (XenAcpiRsdpStructurePtr
->XsdtAddress
) {
140 // Retrieve the addresses of XSDT and
141 // calculate the number of its table entries.
143 Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) (UINTN
)
144 XenAcpiRsdpStructurePtr
->XsdtAddress
;
145 NumberOfTableEntries
= (Xsdt
->Length
-
146 sizeof (EFI_ACPI_DESCRIPTION_HEADER
)) /
149 // Install ACPI tables found in XSDT.
151 for (Index
= 0; Index
< NumberOfTableEntries
; Index
++) {
153 // Get the table entry from XSDT
155 CurrentTableEntry
= (VOID
*) ((UINT8
*) Xsdt
+
156 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
157 Index
* sizeof (UINT64
));
158 CurrentTablePointer
= (UINTN
) *(UINT64
*)CurrentTableEntry
;
159 CurrentTable
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTablePointer
;
162 // Install the XSDT tables
164 Status
= AcpiProtocol
->InstallAcpiTable (
167 CurrentTable
->Length
,
171 if (EFI_ERROR (Status
)) {
176 // Get the FACS and DSDT table address from the table FADT
178 if (!AsciiStrnCmp ((CHAR8
*) &CurrentTable
->Signature
, "FACP", 4)) {
179 FadtTable
= (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE
*)
180 (UINTN
) CurrentTablePointer
;
181 DsdtTable
= (EFI_ACPI_DESCRIPTION_HEADER
*) (UINTN
) FadtTable
->Dsdt
;
187 // Install DSDT table.
189 Status
= AcpiProtocol
->InstallAcpiTable (
195 if (EFI_ERROR (Status
)) {
203 EFI_ACPI_TABLE_PROTOCOL
*
204 FindAcpiTableProtocol (
209 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
212 Status
= gBS
->LocateProtocol (
213 &gEfiAcpiTableProtocolGuid
,
217 ASSERT_EFI_ERROR (Status
);
222 Entrypoint of Xen ARM Acpi Platform driver.
228 @return EFI_LOAD_ERROR
229 @return EFI_OUT_OF_RESOURCES
235 XenAcpiPlatformEntryPoint (
236 IN EFI_HANDLE ImageHandle
,
237 IN EFI_SYSTEM_TABLE
*SystemTable
242 Status
= InstallXenArmTables (FindAcpiTableProtocol ());