2 Install Acpi tables for Cloud Hypervisor
4 Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseLib.h>
10 #include <Library/MemoryAllocationLib.h>
11 #include <IndustryStandard/Acpi63.h>
12 #include <Protocol/AcpiTable.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Library/UefiDriverEntryPoint.h>
15 #include <Library/DebugLib.h>
18 Find Acpi table Protocol and return it
20 @return AcpiTable Protocol, which is used to handle Acpi Table, on SUCCESS or NULL on FAILURE.
24 EFI_ACPI_TABLE_PROTOCOL
*
25 FindAcpiTableProtocol (
30 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
32 Status
= gBS
->LocateProtocol (
33 &gEfiAcpiTableProtocolGuid
,
37 ASSERT_EFI_ERROR (Status
);
41 /** Install Acpi tables for Cloud Hypervisor
43 @param [in] AcpiProtocol Acpi Protocol which is used to install Acpi tables
45 @return EFI_SUCCESS The table was successfully inserted.
46 @return EFI_INVALID_PARAMETER Either AcpiProtocol, AcpiTablePtr or DsdtPtr is NULL
47 and the size field embedded in the ACPI table pointed
48 by AcpiTablePtr or DsdtPtr are not in sync.
49 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
50 @return EFI_NOT_FOUND DSDT table not found.
54 InstallCloudHvAcpiTables (
55 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
60 UINTN AcpiTableLength
;
68 if (AcpiProtocol
== NULL
) {
69 return EFI_INVALID_PARAMETER
;
72 RsdpPtr
= PcdGet64 (PcdCloudHvAcpiRsdpBaseAddress
);
73 XsdtPtr
= ((EFI_ACPI_6_3_ROOT_SYSTEM_DESCRIPTION_POINTER
*)RsdpPtr
)->XsdtAddress
;
74 AcpiTableLength
= ((EFI_ACPI_COMMON_HEADER
*)XsdtPtr
)->Length
;
75 TableOffset
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
78 while (TableOffset
< AcpiTableLength
) {
79 AcpiTablePtr
= *(UINT64
*)(XsdtPtr
+ TableOffset
);
80 TableSize
= ((EFI_ACPI_COMMON_HEADER
*)AcpiTablePtr
)->Length
;
83 // Install ACPI tables from XSDT
85 Status
= AcpiProtocol
->InstallAcpiTable (
91 if (EFI_ERROR (Status
)) {
98 if ((DsdtPtr
== NULL
) &&
99 (EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
==
100 ((EFI_ACPI_COMMON_HEADER
*)AcpiTablePtr
)->Signature
))
102 DsdtPtr
= (UINT64
*)((EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE
*)AcpiTablePtr
)->XDsdt
;
105 TableOffset
+= sizeof (UINT64
);
108 if (DsdtPtr
== NULL
) {
109 DEBUG ((DEBUG_ERROR
, "%a: no DSDT found\n", __FUNCTION__
));
110 return EFI_NOT_FOUND
;
114 // Install DSDT table
116 TableSize
= ((EFI_ACPI_COMMON_HEADER
*)DsdtPtr
)->Length
;
117 Status
= AcpiProtocol
->InstallAcpiTable (
127 /** Entry point for Cloud Hypervisor Platform Dxe
129 @param [in] ImageHandle Handle for this image.
130 @param [in] SystemTable Pointer to the EFI system table.
132 @return EFI_SUCCESS The table was successfully inserted.
133 @return EFI_INVALID_PARAMETER Either AcpiProtocol, AcpiTablePtr or DsdtPtr is NULL
134 and the size field embedded in the ACPI table pointed to
135 by AcpiTablePtr or DsdtPtr are not in sync.
136 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
137 @return EFI_NOT_FOUND DSDT table not found
141 CloudHvAcpiPlatformEntryPoint (
142 IN EFI_HANDLE ImageHandle
,
143 IN EFI_SYSTEM_TABLE
*SystemTable
148 Status
= InstallCloudHvAcpiTables (FindAcpiTableProtocol ());
150 if (EFI_ERROR (Status
)) {
153 "%a: Fail to install Acpi table: %r\n",