OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
AcpiDump.c
Go to the documentation of this file.
1
14#include <Uefi.h>
15
16#include <Library/BaseLib.h>
17#include <Library/BaseMemoryLib.h>
19#include <Library/OcFileLib.h>
20#include <Library/MemoryAllocationLib.h>
21#include <Library/PrintLib.h>
22#include <Library/UefiLib.h>
23#include <Library/UefiBootServicesTableLib.h>
24#include <Library/OcMiscLib.h>
25
26#include <IndustryStandard/AcpiAml.h>
27#include <IndustryStandard/Acpi.h>
28
29#include <Guid/Acpi.h>
30
31#include <Library/OcAcpiLib.h>
32
33STATIC
34EFI_STATUS
36 IN EFI_FILE_PROTOCOL *Root,
37 IN CONST CHAR8 *Name,
38 IN VOID *Data,
39 IN UINTN Size
40 )
41{
42 CHAR16 TempName[16];
43
44 UnicodeSPrint (TempName, sizeof (TempName), L"%a.aml", Name);
45 return OcSetFileData (Root, TempName, Data, (UINT32)Size);
46}
47
48STATIC
49VOID
51 IN EFI_FILE_PROTOCOL *Root,
52 IN EFI_ACPI_COMMON_HEADER *Data,
53 OUT CHAR8 *Name,
54 IN UINTN NameSize
55 )
56{
57 EFI_STATUS Status;
58 CHAR16 TempName[16];
59 CHAR8 *Signature;
60 UINTN Index;
61 EFI_FILE_PROTOCOL *TmpFile;
62
63 ASSERT (NameSize >= 12);
64
65 Signature = (CHAR8 *)&Data->Signature;
66
67 for (Index = 0; Index < sizeof (Data->Signature); ++Index) {
68 if ( ((Signature[Index] >= 'A') && (Signature[Index] <= 'Z'))
69 || ((Signature[Index] >= 'a') && (Signature[Index] <= 'z'))
70 || ((Signature[Index] >= '0') && (Signature[Index] <= '9')))
71 {
72 Name[Index] = Signature[Index];
73 } else {
74 Name[Index] = '_';
75 }
76 }
77
78 Name[Index] = '\0';
79
80 for (Index = 0; Index < 256; ++Index) {
81 UnicodeSPrint (TempName, sizeof (TempName), L"%a-%u.aml", Name, (UINT32)(Index + 1));
82
83 Status = OcSafeFileOpen (
84 Root,
85 &TmpFile,
86 TempName,
87 EFI_FILE_MODE_READ,
88 0
89 );
90
91 if (EFI_ERROR (Status)) {
92 break;
93 }
94
95 TmpFile->Close (TmpFile);
96 }
97
98 AsciiSPrint (&Name[4], NameSize - 4, "-%u", (UINT32)(Index + 1));
99}
100
101EFI_STATUS
103 IN EFI_FILE_PROTOCOL *Root
104 )
105{
106 EFI_STATUS Status;
107 OC_ACPI_CONTEXT Context;
108 UINTN Index;
109 UINTN Length;
110 CHAR8 Name[16];
111
112 Status = AcpiInitContext (&Context);
113
114 if (EFI_ERROR (Status)) {
115 DEBUG ((DEBUG_INFO, "OCA: Failed to init context for dumping - %r\n", Status));
116 return Status;
117 }
118
119 //
120 // The revision of this structure. Larger revision numbers are backward compatible to
121 // lower revision numbers. The ACPI version 1.0 revision number of this table is zero.
122 // The ACPI version 1.0 RSDP Structure only includes the first 20 bytes of this table,
123 // bytes 0 to 19. It does not include the Length field and beyond. The current value
124 // for this field is 2.
125 //
126 if (Context.Rsdp->Revision == 0) {
127 Length = OFFSET_OF (EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER, Length);
128 } else {
129 Length = Context.Rsdp->Length;
130 }
131
132 Status = AcpiDumpTable (Root, "RSDP", Context.Rsdp, Length);
133 DEBUG ((DEBUG_INFO, "OCA: Dumped RSDP (%u bytes) - %r\n", (UINT32)Length, Status));
134
135 Status = AcpiDumpTable (Root, "RSDT", Context.Rsdt, Context.Rsdt->Header.Length);
136 DEBUG ((DEBUG_INFO, "OCA: Dumped RSDT (%u bytes) - %r\n", (UINT32)Context.Rsdt->Header.Length, Status));
137
138 if (Context.Xsdt != NULL) {
139 Status = AcpiDumpTable (Root, "XSDT", Context.Xsdt, Context.Xsdt->Header.Length);
140 DEBUG ((DEBUG_INFO, "OCA: Dumped XSDT (%u bytes) - %r\n", (UINT32)Context.Xsdt->Header.Length, Status));
141 }
142
143 if (Context.Dsdt != NULL) {
144 Status = AcpiDumpTable (Root, "DSDT", Context.Dsdt, Context.Dsdt->Length);
145 DEBUG ((DEBUG_INFO, "OCA: Dumped DSDT (%u bytes) - %r\n", (UINT32)Context.Dsdt->Length, Status));
146 }
147
148 for (Index = 0; Index < Context.NumberOfTables; ++Index) {
149 AcpiGetTableName (Root, Context.Tables[Index], Name, sizeof (Name));
150 Status = AcpiDumpTable (Root, Name, Context.Tables[Index], Context.Tables[Index]->Length);
151 DEBUG ((
152 DEBUG_INFO,
153 "OCA: Dumped table %a %u/%u (%u bytes) - %r\n",
154 Name,
155 (UINT32)(Index + 1),
156 (UINT32)(Context.NumberOfTables),
157 (UINT32)Context.Tables[Index]->Length,
158 Status
159 ));
160 }
161
162 AcpiFreeContext (&Context);
163 return EFI_SUCCESS;
164}
STATIC VOID AcpiGetTableName(IN EFI_FILE_PROTOCOL *Root, IN EFI_ACPI_COMMON_HEADER *Data, OUT CHAR8 *Name, IN UINTN NameSize)
Definition AcpiDump.c:50
EFI_STATUS AcpiDumpTables(IN EFI_FILE_PROTOCOL *Root)
Definition AcpiDump.c:102
STATIC EFI_STATUS AcpiDumpTable(IN EFI_FILE_PROTOCOL *Root, IN CONST CHAR8 *Name, IN VOID *Data, IN UINTN Size)
Definition AcpiDump.c:35
UINT64 Length
UINT8 Signature[8]
Definition BiosId.h:67
VOID AcpiFreeContext(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:884
EFI_STATUS AcpiInitContext(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:738
DMG_SIZE_DEVICE_PATH Size
EFI_STATUS OcSetFileData(IN EFI_FILE_PROTOCOL *WritableFs OPTIONAL, IN CONST CHAR16 *FileName, IN CONST VOID *Buffer, IN UINT32 Size)
EFI_STATUS OcSafeFileOpen(IN CONST EFI_FILE_PROTOCOL *Directory, OUT EFI_FILE_PROTOCOL **NewHandle, IN CONST CHAR16 *FileName, IN CONST UINT64 OpenMode, IN CONST UINT64 Attributes)
Definition OpenFile.c:29
#define ASSERT(x)
Definition coder.h:55
EFI_ACPI_DESCRIPTION_HEADER Header
Definition OcAcpiLib.h:36
EFI_ACPI_DESCRIPTION_HEADER Header
Definition OcAcpiLib.h:31
EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER * Rsdp
Definition OcAcpiLib.h:63
EFI_ACPI_COMMON_HEADER ** Tables
Definition OcAcpiLib.h:83
EFI_ACPI_DESCRIPTION_HEADER * Dsdt
Definition OcAcpiLib.h:79
OC_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE * Xsdt
Definition OcAcpiLib.h:71
OC_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_TABLE * Rsdt
Definition OcAcpiLib.h:67
UINT32 NumberOfTables
Definition OcAcpiLib.h:87