VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/edk2.patch-mem_acpi@ 33071

Last change on this file since 33071 was 33071, checked in by vboxsync, 14 years ago

EFI: manual patch file editing is a bad idea

File size: 6.5 KB
Line 
1Index: ../edk2/MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatform.c
2===================================================================
3--- ../edk2/MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatform.c (revision 9332)
4+++ ../edk2/MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatform.c (working copy)
5@@ -10,7 +10,7 @@
6 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
7 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
8
9-**/
10+**/
11
12 #include <PiDxe.h>
13
14@@ -153,7 +153,137 @@
15 Buffer[ChecksumOffset] = CalculateCheckSum8(Buffer, Size);
16 }
17
18+#ifdef VBOX
19
20+#define ACPI_RSD_PTR SIGNATURE_64('R', 'S', 'D', ' ', 'P', 'T', 'R', ' ')
21+#define EBDA_BASE (0x9FC0 << 4)
22+
23+VOID *
24+FindAcpiRsdPtr (
25+ VOID
26+ )
27+{
28+ UINTN Address;
29+ UINTN Index;
30+
31+ //
32+ // First Search 0x0e0000 - 0x0fffff for RSD Ptr
33+ //
34+ for (Address = 0xe0000; Address < 0xfffff; Address += 0x10) {
35+ if (*(UINT64 *)(Address) == ACPI_RSD_PTR) {
36+ return (VOID *)Address;
37+ }
38+ }
39+
40+ //
41+ // Search EBDA
42+ //
43+
44+ Address = EBDA_BASE;
45+ for (Index = 0; Index < 0x400 ; Index += 16) {
46+ if (*(UINT64 *)(Address + Index) == ACPI_RSD_PTR) {
47+ return (VOID *)Address;
48+ }
49+ }
50+ return NULL;
51+}
52+
53+VOID* FindSignature(VOID* Start, UINT32 Signature, BOOLEAN NoChecksum)
54+{
55+ UINT8* Ptr = (UINT8*)Start;
56+ UINT32 Count = 0x10000; // 16 pages
57+
58+ while (Count-- > 0)
59+ {
60+ if ( *(UINT32*)Ptr == Signature
61+ && ((EFI_ACPI_DESCRIPTION_HEADER *)Ptr)->Length <= Count
62+ && (NoChecksum ||
63+ CalculateCheckSum8(Ptr, ((EFI_ACPI_DESCRIPTION_HEADER *)Ptr)->Length) == 0
64+ ))
65+ {
66+ return Ptr;
67+ }
68+
69+ Ptr++;
70+ }
71+ return NULL;
72+}
73+
74+VOID
75+FillSysTablesInfo(VOID** Tables, UINT32 TablesSize)
76+{
77+ UINT32 Table = 0;
78+ EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER* RsdPtr;
79+ VOID* TablesPage;
80+#define FLAG_OPTIONAL 1<<0
81+#define FLAG_NO_CHECKSUM 1<<1
82+ static struct {
83+ UINT32 Signature;
84+ UINT32 Flags;
85+ CHAR8* Name;
86+ } TableInfo[] = {
87+ // MADT, optional
88+ { SIGNATURE_32('A', 'P', 'I', 'C'), FLAG_OPTIONAL, "MADT"},
89+ // FACP (also called FADT)
90+ { SIGNATURE_32('F', 'A', 'C', 'P'), 0, "FADT"},
91+ // FACS, according 5.2.9 of ACPI v2. spec FACS doesn't have checksum field
92+ { SIGNATURE_32('F', 'A', 'C', 'S'), FLAG_NO_CHECKSUM, "FACS"},
93+ // DSDT
94+ { SIGNATURE_32('D', 'S', 'D', 'T'), 0, "DSDT"},
95+ // SSDT
96+ { SIGNATURE_32('S', 'S', 'D', 'T'), FLAG_OPTIONAL, "SSDT"},
97+ // HPET
98+ { SIGNATURE_32('H', 'P', 'E', 'T'), FLAG_OPTIONAL, "HPET"},
99+ // MCFG
100+ { SIGNATURE_32('M', 'C', 'F', 'G'), FLAG_OPTIONAL, "MCFG"}
101+ };
102+ UINT32 Index;
103+
104+ RsdPtr = (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER*)FindAcpiRsdPtr();
105+ ASSERT(RsdPtr != NULL);
106+ TablesPage = (VOID*)(UINTN)((RsdPtr->RsdtAddress) & ~0xfff);
107+
108+ for (Index = 0; Index < sizeof TableInfo / sizeof TableInfo[0]; Index++)
109+ {
110+ VOID* Ptr = FindSignature(TablesPage, TableInfo[Index].Signature,
111+ (BOOLEAN)((TableInfo[Index].Flags & FLAG_NO_CHECKSUM) != 0));
112+ if (TableInfo[Index].Signature == SIGNATURE_32('F', 'A', 'C', 'P'))
113+ {
114+ // we actually have 2 FADTs, see https://xtracker.innotek.de/index.php?bug=4082
115+ Ptr = FindSignature((UINT8*)Ptr+32, SIGNATURE_32('F', 'A', 'C', 'P'), FALSE);
116+ }
117+ if (!(TableInfo[Index].Flags & FLAG_OPTIONAL))
118+ ASSERT(Ptr != NULL);
119+ DEBUG ((EFI_D_ERROR, "%a: %p\n", TableInfo[Index].Name, Ptr));
120+ if (Ptr)
121+ Tables[Table++] = Ptr;
122+ }
123+
124+#if 0
125+ // RSDT
126+ ASSERT(Table < TablesSize);
127+ Tables[Table] = FindSignature(TablesPage, SIGNATURE_32('R', 'S', 'D', 'T'));
128+ DEBUG ((EFI_D_ERROR, "RSDT: %p\n", Tables[Table]));
129+ ASSERT(Tables[Table] != NULL);
130+ Table++;
131+
132+ // XSDT
133+ ASSERT(Table < TablesSize);
134+ Tables[Table] = FindSignature(TablesPage, SIGNATURE_32('X', 'S', 'D', 'T'));
135+ DEBUG ((EFI_D_ERROR, "XSDT: %p\n", Tables[Table]));
136+ ASSERT(Tables[Table] != NULL);
137+ Table++;
138+#endif
139+
140+ DEBUG((DEBUG_INFO, "We found %d tables from %d\n", Table, TablesSize));
141+ Tables[Table] = NULL;
142+}
143+#endif
144+
145+#ifdef VBOX
146+#define USE_MEM_TABLES 1
147+#endif
148+
149 /**
150 Entrypoint of Acpi Platform driver.
151
152@@ -174,14 +304,21 @@
153 {
154 EFI_STATUS Status;
155 EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
156+#if USE_MEM_TABLES
157+ VOID *VBoxTables[10];
158+#else
159 EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;
160+#endif
161 INTN Instance;
162 EFI_ACPI_COMMON_HEADER *CurrentTable;
163 UINTN TableHandle;
164+#if !USE_MEM_TABLES
165 UINT32 FvStatus;
166+#endif
167 UINTN TableSize;
168 UINTN Size;
169
170+ Size = 0;
171 Instance = 0;
172 CurrentTable = NULL;
173 TableHandle = 0;
174@@ -194,6 +331,18 @@
175 return EFI_ABORTED;
176 }
177
178+#if USE_MEM_TABLES
179+ /* VBOX already has tables prepared in memory - just reuse it */
180+ FillSysTablesInfo(VBoxTables, sizeof(VBoxTables)/sizeof(VBoxTables[0]));
181+ while (Status == EFI_SUCCESS) {
182+ CurrentTable = (EFI_ACPI_COMMON_HEADER*)VBoxTables[Instance];
183+ Status = (CurrentTable == NULL) ? EFI_NOT_FOUND : EFI_SUCCESS;
184+ if (CurrentTable)
185+ {
186+ Size = CurrentTable->Length;
187+ DEBUG ((EFI_D_ERROR, "adding %p %d\n", CurrentTable, Size));
188+ }
189+#else
190 //
191 // Locate the firmware volume protocol
192 //
193@@ -205,7 +354,6 @@
194 // Read tables from the storage file.
195 //
196 while (Status == EFI_SUCCESS) {
197-
198 Status = FwVol->ReadSection (
199 FwVol,
200 (EFI_GUID*)FixedPcdGetPtr (PcdAcpiTableStorageFile),
201@@ -215,6 +363,7 @@
202 &Size,
203 &FvStatus
204 );
205+#endif
206 if (!EFI_ERROR(Status)) {
207 //
208 // Add the table
209@@ -222,6 +371,7 @@
210 TableHandle = 0;
211
212 TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length;
213+ DEBUG((DEBUG_INFO, "Size:%d, TableSize:%d\n", Size, TableSize));
214 ASSERT (Size >= TableSize);
215
216 //
217@@ -252,4 +402,3 @@
218
219 return EFI_SUCCESS;
220 }
221-
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette