17#include <Library/BaseLib.h>
18#include <Library/DebugLib.h>
19#include <Library/MemoryAllocationLib.h>
23#include <Library/PrintLib.h>
24#include <Library/UefiBootServicesTableLib.h>
29 IN OC_GLOBAL_CONFIG *Config,
36 UINT32 TableDataLength;
38 OC_ACPI_ADD_ENTRY *Table;
39 CONST CHAR8 *TablePath;
42 for (Index = 0; Index < Config->Acpi.Add.Count; ++Index) {
43 Table = Config->Acpi.Add.Values[Index];
46 if (!Table->Enabled || (TablePath[0] ==
'\0')) {
47 DEBUG ((DEBUG_INFO,
"OC: Skipping add ACPI %a (%d)\n", TablePath, Table->Enabled));
52 if (EFI_ERROR (Status)) {
55 "OC: Failed to fit ACPI path %s%a",
66 if (TableData == NULL) {
69 "OC: Failed to find ACPI %a\n",
77 if (EFI_ERROR (Status)) {
80 "OC: Failed to add ACPI %a - %r\n",
91 IN OC_GLOBAL_CONFIG *Config,
99 OC_ACPI_DELETE_ENTRY *Table;
101 for (Index = 0; Index < Config->Acpi.Delete.Count; ++Index) {
102 Table = Config->Acpi.Delete.Values[Index];
104 if (!Table->Enabled) {
108 CopyMem (&
Signature, Table->TableSignature, sizeof (Table->TableSignature));
109 CopyMem (&OemTableId, Table->OemTableId, sizeof (Table->OemTableId));
119 if (EFI_ERROR (Status)) {
122 "OC: Failed to drop ACPI %08X %016LX %u (%d) - %r\n",
136 IN OC_GLOBAL_CONFIG *Config,
142 OC_ACPI_PATCH_ENTRY *UserPatch;
143 CONST CHAR8 *Comment;
146 for (Index = 0; Index < Config->Acpi.Patch.Count; ++Index) {
147 UserPatch = Config->Acpi.Patch.Values[Index];
149 if (!UserPatch->Enabled) {
161 if ( (UserPatch->Replace.Size == 0)
162 || ((UserPatch->Find.Size > 0) && (UserPatch->Find.Size != UserPatch->Replace.Size))
163 || ((UserPatch->Find.Size == 0) && (
OC_BLOB_GET (&UserPatch->Base)[0] ==
'\0'))
164 || ((UserPatch->Mask.Size > 0) && (UserPatch->Find.Size != UserPatch->Mask.Size))
165 || ((UserPatch->ReplaceMask.Size > 0) && (UserPatch->Replace.Size != UserPatch->ReplaceMask.Size)))
167 DEBUG ((DEBUG_ERROR,
"OC: ACPI patch (%a) at %u is borked\n", Comment, Index));
171 ZeroMem (&Patch,
sizeof (Patch));
176 if (UserPatch->Mask.Size > 0) {
180 if (UserPatch->ReplaceMask.Size > 0) {
185 Patch.
BaseSkip = UserPatch->BaseSkip;
186 Patch.
Size = UserPatch->Replace.Size;
187 Patch.
Count = UserPatch->Count;
188 Patch.
Skip = UserPatch->Skip;
189 Patch.
Limit = UserPatch->Limit;
192 CopyMem (&Patch.
OemTableId, UserPatch->OemTableId, sizeof (UserPatch->OemTableId));
196 "OC: Applying %u byte ACPI patch (%a) at %u, skip %u, count %u\n",
205 if (EFI_ERROR (Status)) {
206 DEBUG ((DEBUG_WARN,
"OC: ACPI patcher failed (%a) at %u - %r\n", Comment, Index, Status));
214 IN OC_GLOBAL_CONFIG *Config
222 if (EFI_ERROR (Status)) {
223 DEBUG ((DEBUG_ERROR,
"OC: Failed to initialize ACPI support - %r\n", Status));
229 if (Config->Acpi.Quirks.RebaseRegions) {
233 if (Config->Acpi.Quirks.FadtEnableReset) {
237 if (Config->Acpi.Quirks.ResetLogoStatus) {
246 if (Config->Acpi.Quirks.NormalizeHeaders) {
254 if (Config->Acpi.Quirks.RebaseRegions) {
258 if (Config->Acpi.Quirks.SyncTableIds) {
VOID AcpiNormalizeHeaders(IN OUT OC_ACPI_CONTEXT *Context)
EFI_STATUS AcpiApplyContext(IN OUT OC_ACPI_CONTEXT *Context)
EFI_STATUS AcpiFadtEnableReset(IN OUT OC_ACPI_CONTEXT *Context)
EFI_STATUS AcpiDeleteTable(IN OUT OC_ACPI_CONTEXT *Context, IN UINT32 Signature, IN UINT32 Length, IN UINT64 OemTableId, IN BOOLEAN All)
EFI_STATUS AcpiApplyPatch(IN OUT OC_ACPI_CONTEXT *Context, IN OC_ACPI_PATCH *Patch)
VOID AcpiSyncTableIds(IN OUT OC_ACPI_CONTEXT *Context)
VOID AcpiFreeContext(IN OUT OC_ACPI_CONTEXT *Context)
VOID AcpiRelocateRegions(IN OUT OC_ACPI_CONTEXT *Context)
VOID AcpiHandleHardwareSignature(IN OUT OC_ACPI_CONTEXT *Context, IN BOOLEAN Reset)
VOID AcpiResetLogoStatus(IN OUT OC_ACPI_CONTEXT *Context)
EFI_STATUS AcpiInitContext(IN OUT OC_ACPI_CONTEXT *Context)
EFI_STATUS AcpiLoadRegions(IN OUT OC_ACPI_CONTEXT *Context)
EFI_STATUS AcpiInsertTable(IN OUT OC_ACPI_CONTEXT *Context, IN CONST UINT8 *Data, IN UINT32 Length)
#define OPEN_CORE_ACPI_PATH
VOID * OcStorageReadFileUnicode(IN OC_STORAGE_CONTEXT *Context, IN CONST CHAR16 *FilePath, OUT UINT32 *FileSize OPTIONAL)
#define OC_STORAGE_SAFE_PATH_MAX
VOID UnicodeUefiSlashes(IN OUT CHAR16 *String)
EFI_STATUS EFIAPI OcUnicodeSafeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
#define OC_BLOB_GET(Blob)
STATIC VOID OcAcpiDeleteTables(IN OC_GLOBAL_CONFIG *Config, IN OC_ACPI_CONTEXT *Context)
STATIC VOID OcAcpiAddTables(IN OC_GLOBAL_CONFIG *Config, IN OC_STORAGE_CONTEXT *Storage, IN OC_ACPI_CONTEXT *Context)
VOID OcLoadAcpiSupport(IN OC_STORAGE_CONTEXT *Storage, IN OC_GLOBAL_CONFIG *Config)
STATIC VOID OcAcpiPatchTables(IN OC_GLOBAL_CONFIG *Config, IN OC_ACPI_CONTEXT *Context)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
CONST UINT8 * ReplaceMask