1 | /** @file
|
---|
2 | Install Acpi tables for VirtualBox Hypervisor
|
---|
3 |
|
---|
4 | Copyright (c) 2024, Oracle and/or its affiliates.<BR>
|
---|
5 | Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 | #include <Library/BaseLib.h>
|
---|
11 | #include <Library/MemoryAllocationLib.h>
|
---|
12 | #include <IndustryStandard/Acpi63.h>
|
---|
13 | #include <Protocol/AcpiTable.h>
|
---|
14 | #include <Library/UefiBootServicesTableLib.h>
|
---|
15 | #include <Library/UefiDriverEntryPoint.h>
|
---|
16 | #include <Library/DebugLib.h>
|
---|
17 |
|
---|
18 | #include <Library/VBoxArmPlatformLib.h>
|
---|
19 |
|
---|
20 | /**
|
---|
21 | Find Acpi table Protocol and return it
|
---|
22 |
|
---|
23 | @return AcpiTable Protocol, which is used to handle Acpi Table, on SUCCESS or NULL on FAILURE.
|
---|
24 |
|
---|
25 | **/
|
---|
26 | STATIC
|
---|
27 | EFI_ACPI_TABLE_PROTOCOL *
|
---|
28 | FindAcpiTableProtocol (
|
---|
29 | VOID
|
---|
30 | )
|
---|
31 | {
|
---|
32 | EFI_STATUS Status;
|
---|
33 | EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
|
---|
34 |
|
---|
35 | Status = gBS->LocateProtocol (
|
---|
36 | &gEfiAcpiTableProtocolGuid,
|
---|
37 | NULL,
|
---|
38 | (VOID **)&AcpiTable
|
---|
39 | );
|
---|
40 | ASSERT_EFI_ERROR (Status);
|
---|
41 | return AcpiTable;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /** Install Acpi tables for Cloud Hypervisor
|
---|
45 |
|
---|
46 | @param [in] AcpiProtocol Acpi Protocol which is used to install Acpi tables
|
---|
47 |
|
---|
48 | @return EFI_SUCCESS The table was successfully inserted.
|
---|
49 | @return EFI_INVALID_PARAMETER Either AcpiProtocol, AcpiTablePtr or DsdtPtr is NULL
|
---|
50 | and the size field embedded in the ACPI table pointed
|
---|
51 | by AcpiTablePtr or DsdtPtr are not in sync.
|
---|
52 | @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
|
---|
53 | @return EFI_NOT_FOUND DSDT table not found.
|
---|
54 | **/
|
---|
55 | EFI_STATUS
|
---|
56 | EFIAPI
|
---|
57 | InstallVBoxAcpiTables (
|
---|
58 | IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
|
---|
59 | )
|
---|
60 | {
|
---|
61 | UINTN InstalledKey;
|
---|
62 | UINTN TableSize;
|
---|
63 | UINTN AcpiTableLength;
|
---|
64 | UINT64 RsdpPtr;
|
---|
65 | UINT64 XsdtPtr;
|
---|
66 | UINT64 TableOffset;
|
---|
67 | UINT64 AcpiTablePtr;
|
---|
68 | UINT64 *DsdtPtr;
|
---|
69 | EFI_STATUS Status;
|
---|
70 |
|
---|
71 | if (AcpiProtocol == NULL) {
|
---|
72 | return EFI_INVALID_PARAMETER;
|
---|
73 | }
|
---|
74 |
|
---|
75 | RsdpPtr = (UINTN)VBoxArmPlatformAcpiXsdpStartGetPhysAddr();
|
---|
76 | DEBUG ((DEBUG_ERROR, "%a: RSDP %Lx\n", __func__, RsdpPtr));
|
---|
77 |
|
---|
78 | XsdtPtr = ((EFI_ACPI_6_3_ROOT_SYSTEM_DESCRIPTION_POINTER *)RsdpPtr)->XsdtAddress;
|
---|
79 |
|
---|
80 | DEBUG ((DEBUG_ERROR, "%a: XSDT %Lx\n", __func__, XsdtPtr));
|
---|
81 |
|
---|
82 | AcpiTableLength = ((EFI_ACPI_COMMON_HEADER *)XsdtPtr)->Length;
|
---|
83 | TableOffset = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
|
---|
84 | DsdtPtr = NULL;
|
---|
85 |
|
---|
86 | DEBUG ((DEBUG_ERROR, "%a: XSDT %Lx %d\n", __func__, XsdtPtr, AcpiTableLength));
|
---|
87 |
|
---|
88 | while (TableOffset < AcpiTableLength) {
|
---|
89 | AcpiTablePtr = *(UINT64 *)(XsdtPtr + TableOffset);
|
---|
90 | DEBUG ((DEBUG_ERROR, "%a: Installing table at %Lx\n", __func__, AcpiTablePtr));
|
---|
91 |
|
---|
92 | TableSize = ((EFI_ACPI_COMMON_HEADER *)AcpiTablePtr)->Length;
|
---|
93 |
|
---|
94 | //
|
---|
95 | // Install ACPI tables from XSDT
|
---|
96 | //
|
---|
97 | DEBUG ((DEBUG_ERROR, "%a: Installing table at %Lx %d\n", __func__, AcpiTablePtr, TableSize));
|
---|
98 | Status = AcpiProtocol->InstallAcpiTable (
|
---|
99 | AcpiProtocol,
|
---|
100 | (VOID *)AcpiTablePtr,
|
---|
101 | TableSize,
|
---|
102 | &InstalledKey
|
---|
103 | );
|
---|
104 | if (EFI_ERROR (Status)) {
|
---|
105 | return Status;
|
---|
106 | }
|
---|
107 |
|
---|
108 | //
|
---|
109 | // Get DSDT from FADT
|
---|
110 | //
|
---|
111 | if ((DsdtPtr == NULL) &&
|
---|
112 | (EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE ==
|
---|
113 | ((EFI_ACPI_COMMON_HEADER *)AcpiTablePtr)->Signature))
|
---|
114 | {
|
---|
115 | DsdtPtr = (UINT64 *)((EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE *)AcpiTablePtr)->XDsdt;
|
---|
116 | }
|
---|
117 |
|
---|
118 | TableOffset += sizeof (UINT64);
|
---|
119 | } // while
|
---|
120 |
|
---|
121 | if (DsdtPtr == NULL) {
|
---|
122 | DEBUG ((DEBUG_ERROR, "%a: no DSDT found\n", __func__));
|
---|
123 | return EFI_SUCCESS;
|
---|
124 | }
|
---|
125 |
|
---|
126 | //
|
---|
127 | // Install DSDT table
|
---|
128 | //
|
---|
129 | TableSize = ((EFI_ACPI_COMMON_HEADER *)DsdtPtr)->Length;
|
---|
130 | Status = AcpiProtocol->InstallAcpiTable (
|
---|
131 | AcpiProtocol,
|
---|
132 | DsdtPtr,
|
---|
133 | TableSize,
|
---|
134 | &InstalledKey
|
---|
135 | );
|
---|
136 |
|
---|
137 | return Status;
|
---|
138 | }
|
---|
139 |
|
---|
140 | /** Entry point for VirtualBox ACPI Platform Dxe
|
---|
141 |
|
---|
142 | @param [in] ImageHandle Handle for this image.
|
---|
143 | @param [in] SystemTable Pointer to the EFI system table.
|
---|
144 |
|
---|
145 | @return EFI_SUCCESS The table was successfully inserted.
|
---|
146 | @return EFI_INVALID_PARAMETER Either AcpiProtocol, AcpiTablePtr or DsdtPtr is NULL
|
---|
147 | and the size field embedded in the ACPI table pointed to
|
---|
148 | by AcpiTablePtr or DsdtPtr are not in sync.
|
---|
149 | @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
|
---|
150 | @return EFI_NOT_FOUND DSDT table not found
|
---|
151 | **/
|
---|
152 | EFI_STATUS
|
---|
153 | EFIAPI
|
---|
154 | VBoxAcpiPlatformEntryPoint (
|
---|
155 | IN EFI_HANDLE ImageHandle,
|
---|
156 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
157 | )
|
---|
158 | {
|
---|
159 | EFI_STATUS Status;
|
---|
160 |
|
---|
161 | Status = InstallVBoxAcpiTables (FindAcpiTableProtocol ());
|
---|
162 |
|
---|
163 | if (EFI_ERROR (Status)) {
|
---|
164 | DEBUG ((
|
---|
165 | DEBUG_ERROR,
|
---|
166 | "%a: Fail to install Acpi table: %r\n",
|
---|
167 | __func__,
|
---|
168 | Status
|
---|
169 | ));
|
---|
170 | CpuDeadLoop ();
|
---|
171 | }
|
---|
172 |
|
---|
173 | return EFI_SUCCESS;
|
---|
174 | }
|
---|