OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcAcpiLib.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/MemoryAllocationLib.h>
20#include <Library/UefiLib.h>
21#include <Library/UefiBootServicesTableLib.h>
22#include <Library/OcMemoryLib.h>
23#include <Library/OcMiscLib.h>
24#include <Library/PciLib.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
33#define PCI_VENDOR_NVIDIA 0x10DE
34
40STATIC
41EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *
43 VOID
44 )
45{
46 EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
47
48 UINTN Address;
49 UINTN Index;
50
51 //
52 // First Search 0x0E0000 - 0x0FFFFF for RSD_PTR
53 //
54
55 Rsdp = NULL;
56
57 for (Address = 0x0E0000; Address < 0x0FFFFF; Address += 16) {
58 if (*(UINT64 *)Address == EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE) {
59 Rsdp = (EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *)Address;
60 }
61 }
62
63 //
64 // Then Search EBDA 0x40E - 0x800
65 //
66
67 if (Rsdp == NULL) {
68 Address = ((UINTN)(*(UINT16 *)0x040E) << 4U);
69
70 for (Index = 0; Index < 0x0400; Index += 16) {
71 if (*(UINT64 *)(Address + Index) == EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE) {
72 Rsdp = (EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *)Address;
73 }
74 }
75 }
76
77 return Rsdp;
78}
79
85STATIC
86EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *
88 VOID
89 )
90{
91 EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
92 UINTN Index;
93
94 Rsdp = NULL;
95
96 //
97 // Find ACPI table RSD_PTR from system table
98 //
99
100 for (Index = 0; Index < gST->NumberOfTableEntries; ++Index) {
101 //
102 // Prefer ACPI 2.0
103 //
104 if (CompareGuid (&gST->ConfigurationTable[Index].VendorGuid, &gEfiAcpi20TableGuid)) {
105 Rsdp = (EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *)gST->ConfigurationTable[Index].VendorTable;
106 DEBUG ((DEBUG_VERBOSE, "OCA: Found ACPI 2.0 RSDP table %p\n", Rsdp));
107 break;
108 }
109
110 //
111 // Otherwise use ACPI 1.0, but do search for ACPI 2.0.
112 //
113 if (CompareGuid (&gST->ConfigurationTable[Index].VendorGuid, &gEfiAcpi10TableGuid)) {
114 Rsdp = (EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *)gST->ConfigurationTable[Index].VendorTable;
115 DEBUG ((DEBUG_VERBOSE, "OCA: Found ACPI 1.0 RSDP table %p\n", Rsdp));
116 }
117 }
118
119 //
120 // Try to use legacy search as a last resort.
121 //
122 if (Rsdp == NULL) {
123 Rsdp = AcpiFindLegacyRsdp ();
124 if (Rsdp != NULL) {
125 DEBUG ((DEBUG_VERBOSE, "OCA: Found ACPI legacy RSDP table %p\n", Rsdp));
126 }
127 }
128
129 if (Rsdp == NULL) {
130 DEBUG ((DEBUG_WARN, "OCA: Failed to find ACPI RSDP table\n"));
131 }
132
133 return Rsdp;
134}
135
143STATIC
144UINT32
146 IN CONST EFI_ACPI_COMMON_HEADER *Common
147 )
148{
149 UINT32 Result;
150 CHAR8 *Walker;
151 UINT32 Index;
152
153 Result = Common->Signature;
154
155 Walker = (CHAR8 *)&Result;
156 for (Index = 0; Index < sizeof (Common->Signature); Index++) {
157 if (!IsAsciiPrint (Walker[Index])) {
158 Walker[Index] = '?';
159 }
160 }
161
162 return Result;
163}
164
172STATIC
173UINT64
175 IN CONST EFI_ACPI_COMMON_HEADER *Common
176 )
177{
178 if (Common->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
179 return 0;
180 }
181
182 return ((EFI_ACPI_DESCRIPTION_HEADER *)Common)->OemTableId;
183}
184
194STATIC
195BOOLEAN
197 IN CONST UINT8 *Data,
198 OUT CHAR8 *Name,
199 OUT UINT32 *NameOffset OPTIONAL
200 )
201{
202 UINT32 Index;
203 UINT32 Off;
204
205 //
206 // Skip \ in \NAME.
207 //
208 Off = Data[0] == '\\' ? 1 : 0;
209
210 for (Index = Off; Index < Off + OC_ACPI_NAME_SIZE; ++Index) {
211 if ( (Data[Index] < '/')
212 || ((Data[Index] > '9') && (Data[Index] < 'A'))
213 || ((Data[Index] > 'Z') && (Data[Index] != '_')))
214 {
215 return FALSE;
216 }
217
218 Name[Index - Off] = Data[Index];
219 }
220
221 Name[OC_ACPI_NAME_SIZE] = 0;
222
223 if (NameOffset != NULL) {
224 *NameOffset = Off;
225 }
226
227 return TRUE;
228}
229
239STATIC
240UINT32
242 IN CONST UINT8 *Data,
243 IN UINT32 Length,
244 IN CONST CHAR8 *Name
245 )
246{
247 UINT32 Index;
248
249 //
250 // Lookup from offset 1 and after.
251 //
252 if (Length < OC_ACPI_NAME_SIZE + 1) {
253 return 0;
254 }
255
256 for (Index = 0; Index < Length - OC_ACPI_NAME_SIZE; ++Index) {
257 if ( (Data[Index] == AML_NAME_OP)
258 && (Data[Index+1] == Name[0])
259 && (Data[Index+2] == Name[1])
260 && (Data[Index+3] == Name[2])
261 && (Data[Index+4] == Name[3]))
262 {
263 return Index+1;
264 }
265 }
266
267 return 0;
268}
269
270STATIC
271VOID
273 IN EFI_ACPI_DESCRIPTION_HEADER *Table
274 )
275{
276 UINT32 TablePrintSignature;
277
278 TablePrintSignature = AcpiReadSignature ((EFI_ACPI_COMMON_HEADER *)Table);
279 Table->Checksum = 0;
280 Table->Checksum = CalculateCheckSum8 ((UINT8 *)Table, Table->Length);
281
282 DEBUG ((
283 DEBUG_INFO,
284 "OCA: Refreshed %.4a checksum to %02x\n",
285 (CHAR8 *)&TablePrintSignature,
286 Table->Checksum
287 ));
288}
289
290STATIC
291BOOLEAN
293 IN EFI_ACPI_COMMON_HEADER *Table
294 )
295{
296 UINT32 LengthOriginal;
297
298 LengthOriginal = Table->Length;
299 (*(volatile UINT32 *)&Table->Length)++;
300
301 if (LengthOriginal == *(volatile UINT32 *)&Table->Length) {
302 return FALSE;
303 }
304
305 Table->Length = LengthOriginal;
306 return TRUE;
307}
308
309STATIC
310EFI_STATUS
312 IN EFI_ACPI_COMMON_HEADER *Table,
313 IN UINT32 NewSize OPTIONAL,
314 OUT EFI_ACPI_COMMON_HEADER **NewTable
315 )
316{
317 EFI_STATUS Status;
318 UINT32 TablePrintSignature;
319 EFI_PHYSICAL_ADDRESS NewTableAddress;
320
321 if (NewSize < Table->Length) {
322 NewSize = Table->Length;
323 }
324
325 TablePrintSignature = AcpiReadSignature (Table);
326
327 NewTableAddress = BASE_4GB - 1;
328 Status = gBS->AllocatePages (
329 AllocateMaxAddress,
330 EfiACPIMemoryNVS,
331 EFI_SIZE_TO_PAGES (NewSize),
332 &NewTableAddress
333 );
334 if (EFI_ERROR (Status)) {
335 DEBUG ((
336 DEBUG_WARN,
337 "OCA: Failed to allocate %u bytes for table %.4a\n",
338 NewSize,
339 (CHAR8 *)&TablePrintSignature
340 ));
341 return Status;
342 }
343
344 *NewTable = (EFI_ACPI_COMMON_HEADER *)(UINTN)NewTableAddress;
345
346 DEBUG ((
347 DEBUG_INFO,
348 "OCA: Allocated new table %.4a at %p\n",
349 (CHAR8 *)&TablePrintSignature,
350 *NewTable
351 ));
352
353 CopyMem (*NewTable, Table, Table->Length);
354 ZeroMem (((UINT8 *)*NewTable) + Table->Length, EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (NewSize)) - Table->Length);
355 (*NewTable)->Length = NewSize;
356
357 return EFI_SUCCESS;
358}
359
360STATIC
361EFI_STATUS
363 IN OUT OC_ACPI_CONTEXT *Context,
364 IN UINT32 NewSize
365 )
366{
367 EFI_STATUS Status;
368 EFI_ACPI_COMMON_HEADER *NewFadt;
369 UINT32 Index;
370
371 Status = AcpiAllocateCopyTable (
372 (EFI_ACPI_COMMON_HEADER *)Context->Fadt,
373 NewSize,
374 &NewFadt
375 );
376 if (EFI_ERROR (Status)) {
377 return Status;
378 }
379
380 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
381 //
382 // There is a possibility for multiple FADT tables.
383 //
384 if (Context->Tables[Index]->Signature == EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
385 Context->Tables[Index] = NewFadt;
386 }
387 }
388
389 Context->Fadt = (EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE *)NewFadt;
390
391 return EFI_SUCCESS;
392}
393
394STATIC
395EFI_STATUS
397 IN OUT OC_ACPI_CONTEXT *Context,
398 IN EFI_ACPI_DESCRIPTION_HEADER *NewDsdt OPTIONAL
399 )
400{
401 EFI_STATUS Status;
402 EFI_ACPI_COMMON_HEADER *AllocatedDsdt;
403
404 Status = AcpiAllocateCopyTable (
405 (EFI_ACPI_COMMON_HEADER *)(NewDsdt != NULL ? NewDsdt : Context->Dsdt),
406 0,
407 &AllocatedDsdt
408 );
409 if (EFI_ERROR (Status)) {
410 return Status;
411 }
412
413 //
414 // Reallocate FADT if needed.
415 //
416 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Fadt)) {
417 Status = AcpiAllocateCopyFadt (Context, 0);
418 if (EFI_ERROR (Status)) {
419 FreePool (AllocatedDsdt);
420 return Status;
421 }
422 }
423
424 if (Context->Fadt->Header.Length >= OFFSET_OF (EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE, XDsdt) + sizeof (Context->Fadt->XDsdt)) {
425 Context->Fadt->XDsdt = (UINT64)(UINTN)AllocatedDsdt;
426 }
427
428 Context->Fadt->Dsdt = (UINT32)(UINTN)AllocatedDsdt;
429 AcpiRefreshTableChecksum ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Fadt);
430
431 Context->Dsdt = (EFI_ACPI_DESCRIPTION_HEADER *)AllocatedDsdt;
432
433 return EFI_SUCCESS;
434}
435
444STATIC
445EFI_STATUS
447 IN OUT OC_ACPI_CONTEXT *Context,
448 IN EFI_ACPI_COMMON_HEADER *Table
449 )
450{
451 UINT32 Index;
452 UINT32 Index2;
453 UINT32 NameOffset;
454 UINT8 *Buffer;
455 UINT32 BufferLen;
456 CHAR8 Name[OC_ACPI_NAME_SIZE+1];
457 CHAR8 NameAddr[OC_ACPI_NAME_SIZE+1];
458 OC_ACPI_REGION *NewRegions;
459 UINT32 Address;
460
461 Buffer = (UINT8 *)Table;
462 BufferLen = Table->Length;
463
464 if (BufferLen < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
465 return EFI_SUCCESS;
466 }
467
468 for (Index = sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < BufferLen - 0xF; ++Index) {
469 if ( (Buffer[Index] == AML_EXT_OP)
470 && (Buffer[Index+1] == AML_EXT_REGION_OP)
471 && AcpiReadName (&Buffer[Index+2], &Name[0], &NameOffset)
472 && (Buffer[Index+OC_ACPI_NAME_SIZE+2+NameOffset] == EFI_ACPI_6_2_SYSTEM_MEMORY))
473 {
474 //
475 // This is SystemMemory region. Try to save it.
476 //
477 Address = 0;
478 if (Buffer[Index+OC_ACPI_NAME_SIZE+3+NameOffset] == AML_DWORD_PREFIX) {
479 CopyMem (&Address, &Buffer[Index+OC_ACPI_NAME_SIZE+4+NameOffset], sizeof (UINT32));
480 } else if (Buffer[Index+OC_ACPI_NAME_SIZE+3+NameOffset] == AML_WORD_PREFIX) {
481 CopyMem (&Address, &Buffer[Index+OC_ACPI_NAME_SIZE+4+NameOffset], sizeof (UINT16));
482 } else if (AcpiReadName (&Buffer[Index+OC_ACPI_NAME_SIZE+3+NameOffset], &NameAddr[0], NULL)) {
483 Index2 = AcpiFindName (Buffer, BufferLen, &NameAddr[0]);
484 if ((Index2 > 0) && (Index2 < BufferLen - 0xF)) {
485 if (Buffer[Index2+OC_ACPI_NAME_SIZE] == AML_DWORD_PREFIX) {
486 CopyMem (&Address, &Buffer[Index2+OC_ACPI_NAME_SIZE+1], sizeof (UINT32));
487 } else if (Buffer[Index2+OC_ACPI_NAME_SIZE] == AML_WORD_PREFIX) {
488 CopyMem (&Address, &Buffer[Index2+OC_ACPI_NAME_SIZE+1], sizeof (UINT16));
489 }
490 }
491 }
492
493 for (Index2 = 0; Index2 < Context->NumberOfRegions; ++Index2) {
494 if (Context->Regions[Index2].Address == Address) {
495 Address = 0;
496 break;
497 }
498 }
499
500 if (Address != 0) {
501 if (Context->AllocatedRegions == Context->NumberOfRegions) {
502 NewRegions = AllocatePool ((Context->AllocatedRegions + 2) * sizeof (Context->Regions[0]));
503 if (NewRegions == NULL) {
504 DEBUG ((DEBUG_WARN, "OCA: Failed to allocate memory for %u regions\n", Context->AllocatedRegions+2));
505 return EFI_OUT_OF_RESOURCES;
506 }
507
508 CopyMem (NewRegions, Context->Regions, Context->NumberOfRegions * sizeof (Context->Regions[0]));
509 FreePool (Context->Regions);
510
511 Context->Regions = NewRegions;
512 Context->AllocatedRegions += 2;
513 }
514
515 DEBUG ((DEBUG_INFO, "OCA: Found OperationRegion %a at %08X\n", Name, Address));
516 Context->Regions[Context->NumberOfRegions].Address = Address;
517 CopyMem (&Context->Regions[Context->NumberOfRegions].Name[0], &Name[0], sizeof (Name));
518 ++Context->NumberOfRegions;
519 }
520 }
521 }
522
523 return EFI_SUCCESS;
524}
525
532STATIC
533VOID
535 IN OUT OC_ACPI_CONTEXT *Context,
536 IN EFI_ACPI_COMMON_HEADER *Table
537 )
538{
539 UINT32 Index;
540 UINT32 Index2;
541 UINT32 RegionIndex;
542 UINT32 NameOffset;
543 UINT8 *Buffer;
544 UINT32 BufferLen;
545 CHAR8 Name[OC_ACPI_NAME_SIZE+1];
546 CHAR8 NameAddr[OC_ACPI_NAME_SIZE+1];
547 UINT32 OldAddress;
548 BOOLEAN Modified;
549
550 Buffer = (UINT8 *)Table;
551 BufferLen = Table->Length;
552 Modified = FALSE;
553
554 if (BufferLen < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
555 return;
556 }
557
558 for (Index = sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < BufferLen - 0xF; ++Index) {
559 if ( (Buffer[Index] == AML_EXT_OP)
560 && (Buffer[Index+1] == AML_EXT_REGION_OP)
561 && AcpiReadName (&Buffer[Index+2], &Name[0], &NameOffset)
562 && (Buffer[Index+OC_ACPI_NAME_SIZE+2+NameOffset] == EFI_ACPI_6_2_SYSTEM_MEMORY))
563 {
564 //
565 // This is region. Compare to current BIOS tables and relocate.
566 //
567 for (RegionIndex = 0; RegionIndex < Context->NumberOfRegions; ++RegionIndex) {
568 if (AsciiStrCmp (Context->Regions[RegionIndex].Name, Name) == 0) {
569 OldAddress = 0;
570 if (Buffer[Index+OC_ACPI_NAME_SIZE+3+NameOffset] == AML_DWORD_PREFIX) {
571 CopyMem (&OldAddress, &Buffer[Index+OC_ACPI_NAME_SIZE+4+NameOffset], sizeof (UINT32));
572 CopyMem (&Buffer[Index+OC_ACPI_NAME_SIZE+4+NameOffset], &Context->Regions[RegionIndex].Address, sizeof (UINT32));
573 Modified = TRUE;
574 } else if (Buffer[Index+OC_ACPI_NAME_SIZE+3+NameOffset] == AML_WORD_PREFIX) {
575 CopyMem (&OldAddress, &Buffer[Index+OC_ACPI_NAME_SIZE+4+NameOffset], sizeof (UINT16));
576 CopyMem (&Buffer[Index+OC_ACPI_NAME_SIZE+4+NameOffset], &Context->Regions[RegionIndex].Address, sizeof (UINT16));
577 Modified = TRUE;
578 } else if (AcpiReadName (&Buffer[Index+OC_ACPI_NAME_SIZE+3+NameOffset], &NameAddr[0], NULL)) {
579 Index2 = AcpiFindName (Buffer, BufferLen, &NameAddr[0]);
580 if ((Index2 > 0) && (Index2 < BufferLen - 0xF)) {
581 if (Buffer[Index2+OC_ACPI_NAME_SIZE] == AML_DWORD_PREFIX) {
582 CopyMem (&OldAddress, &Buffer[Index2+OC_ACPI_NAME_SIZE+1], sizeof (UINT32));
583 CopyMem (&Buffer[Index2+OC_ACPI_NAME_SIZE+1], &Context->Regions[RegionIndex].Address, sizeof (UINT32));
584 Modified = TRUE;
585 } else if (Buffer[Index2+OC_ACPI_NAME_SIZE] == AML_WORD_PREFIX) {
586 CopyMem (&OldAddress, &Buffer[Index2+OC_ACPI_NAME_SIZE+1], sizeof (UINT16));
587 CopyMem (&Buffer[Index2+OC_ACPI_NAME_SIZE+1], &Context->Regions[RegionIndex].Address, sizeof (UINT16));
588 Modified = TRUE;
589 }
590 }
591 }
592
593 if (Modified && (OldAddress != Context->Regions[RegionIndex].Address)) {
594 DEBUG ((
595 DEBUG_INFO,
596 "OCA: Region %a address relocated from %08X to %08X\n",
597 Context->Regions[RegionIndex].Name,
598 OldAddress,
599 Context->Regions[RegionIndex].Address
600 ));
601 }
602
603 break;
604 }
605 }
606 }
607 }
608
609 //
610 // Update checksum
611 //
612 if (Modified) {
613 ((EFI_ACPI_DESCRIPTION_HEADER *)Table)->Checksum = 0;
614 ((EFI_ACPI_DESCRIPTION_HEADER *)Table)->Checksum = CalculateCheckSum8 (
615 (UINT8 *)Table,
616 Table->Length
617 );
618 }
619}
620
627STATIC
628BOOLEAN
630 IN EFI_ACPI_DESCRIPTION_HEADER *Table
631 )
632{
633 BOOLEAN Modified;
634 CHAR8 *Walker;
635 UINT32 Index;
636
637 if (Table->Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
638 return FALSE;
639 }
640
641 Modified = FALSE;
642
643 Walker = (CHAR8 *)&Table->Signature;
644 for (Index = 0; Index < sizeof (Table->Signature); ++Index) {
645 if (!IsAsciiPrint (Walker[Index])) {
646 Walker[Index] = '?';
647 Modified = TRUE;
648 }
649 }
650
651 Walker = (CHAR8 *)&Table->OemId;
652 for (Index = 0; Index < sizeof (Table->OemId); ++Index) {
653 if (!IsAsciiPrint (Walker[Index])) {
654 Walker[Index] = '?';
655 Modified = TRUE;
656 }
657 }
658
659 Walker = (CHAR8 *)&Table->OemTableId;
660 for (Index = 0; Index < sizeof (Table->OemTableId); ++Index) {
661 if (!IsAsciiPrint (Walker[Index])) {
662 Walker[Index] = '?';
663 Modified = TRUE;
664 }
665 }
666
667 Walker = (CHAR8 *)&Table->CreatorId;
668 for (Index = 0; Index < sizeof (Table->CreatorId); ++Index) {
669 if (!IsAsciiPrint (Walker[Index])) {
670 Walker[Index] = '?';
671 Modified = TRUE;
672 }
673 }
674
675 if (Modified) {
676 Table->Checksum = 0;
677 Table->Checksum = CalculateCheckSum8 (
678 (UINT8 *)Table,
679 Table->Length
680 );
681 }
682
683 return Modified;
684}
685
693STATIC
694BOOLEAN
696 IN EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp,
697 IN BOOLEAN HasXsdt
698 )
699{
700 BOOLEAN Modified;
701 CHAR8 *Walker;
702 UINT32 Index;
703
704 Modified = FALSE;
705
706 Walker = (CHAR8 *)&Rsdp->OemId;
707 for (Index = 0; Index < sizeof (Rsdp->OemId); ++Index) {
708 if (!IsAsciiPrint (Walker[Index])) {
709 Walker[Index] = '?';
710 Modified = TRUE;
711 }
712 }
713
714 if (Modified) {
715 //
716 // Checksum is to be the first 0-19 bytes of RSDP.
717 // ExtendedChecksum is the entire table, only if newer than ACPI 1.0.
718 //
719 Rsdp->Checksum = 0;
720 Rsdp->Checksum = CalculateCheckSum8 (
721 (UINT8 *)Rsdp,
722 20
723 );
724
725 if (HasXsdt) {
726 Rsdp->ExtendedChecksum = 0;
727 Rsdp->ExtendedChecksum = CalculateCheckSum8 (
728 (UINT8 *)Rsdp,
729 Rsdp->Length
730 );
731 }
732 }
733
734 return Modified;
735}
736
737EFI_STATUS
739 IN OUT OC_ACPI_CONTEXT *Context
740 )
741{
742 UINT32 Index;
743 UINT32 DstIndex;
744 UINT32 TablePrintSignature;
745
746 ZeroMem (Context, sizeof (*Context));
747
748 Context->Rsdp = AcpiFindRsdp ();
749
750 if (Context->Rsdp == NULL) {
751 return EFI_NOT_FOUND;
752 }
753
754 //
755 // Support RSDT on ACPI 1.0 and newer.
756 //
757 Context->Rsdt = (OC_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_TABLE *)(UINTN)Context->Rsdp->RsdtAddress;
758 DEBUG ((DEBUG_VERBOSE, "OCA: Found ACPI RSDT table %p", Context->Rsdt));
759
760 //
761 // ACPI 2.0 and newer have XSDT as well.
762 //
763 if (Context->Rsdp->Revision > 0) {
764 Context->Xsdt = (OC_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE *)(UINTN)Context->Rsdp->XsdtAddress;
765 DEBUG ((DEBUG_VERBOSE, "OCA: Found ACPI XSDT table %p", Context->Xsdt));
766 }
767
768 if ((Context->Rsdt == NULL) && (Context->Xsdt == NULL)) {
769 DEBUG ((DEBUG_WARN, "OCA: Failed to find ACPI RSDT or XSDT tables\n"));
770 return EFI_NOT_FOUND;
771 }
772
773 if (Context->Xsdt != NULL) {
774 Context->NumberOfTables = (Context->Xsdt->Header.Length - sizeof (Context->Xsdt->Header))
775 / sizeof (Context->Xsdt->Tables[0]);
776 } else {
777 Context->NumberOfTables = (Context->Rsdt->Header.Length - sizeof (Context->Rsdt->Header))
778 / sizeof (Context->Rsdt->Tables[0]);
779 }
780
781 DEBUG ((DEBUG_INFO, "OCA: Found %u ACPI tables\n", Context->NumberOfTables));
782
783 if (Context->NumberOfTables == 0) {
784 DEBUG ((DEBUG_WARN, "OCA: No ACPI tables are available\n"));
785 return EFI_INVALID_PARAMETER;
786 }
787
788 Context->Tables = AllocatePool (Context->NumberOfTables * sizeof (Context->Tables[0]));
789 if (Context->Tables == NULL) {
790 DEBUG ((DEBUG_WARN, "OCA: Cannot allocate space for %u ACPI tables\n", Context->NumberOfTables));
791 return EFI_OUT_OF_RESOURCES;
792 }
793
794 Context->AllocatedTables = Context->NumberOfTables;
795
796 for (DstIndex = 0, Index = 0; Index < Context->NumberOfTables; ++Index) {
797 Context->Tables[DstIndex] = (EFI_ACPI_COMMON_HEADER *)(Context->Xsdt != NULL
798 ? (UINTN)Context->Xsdt->Tables[Index] : (UINTN)Context->Rsdt->Tables[Index]);
799
800 //
801 // Skip NULL table entries, DSDT, and RSDP if any.
802 //
803 if ( (Context->Tables[DstIndex] == NULL)
804 || (Context->Tables[DstIndex]->Signature == EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE)
805 || (*(UINT64 *)Context->Tables[DstIndex] == EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE))
806 {
807 continue;
808 }
809
810 TablePrintSignature = AcpiReadSignature (Context->Tables[DstIndex]);
811
812 DEBUG ((
813 DEBUG_INFO,
814 "OCA: Detected table %.4a (%08x) (OEM %016Lx) at %p of %u bytes at index %u\n",
815 (CHAR8 *)&TablePrintSignature,
816 Context->Tables[DstIndex]->Signature,
817 AcpiReadOemTableId (Context->Tables[DstIndex]),
818 Context->Tables[DstIndex],
819 Context->Tables[DstIndex]->Length,
820 Index
821 ));
822
823 //
824 // Unlock table if in lower memory.
825 //
826 if ((UINTN)Context->Tables[DstIndex] < BASE_1MB) {
827 DEBUG ((
828 DEBUG_INFO,
829 "OCA: Unlocking table %.4a (%08x) at %p\n",
830 (CHAR8 *)&TablePrintSignature,
831 Context->Tables[DstIndex]->Signature,
832 Context->Tables[DstIndex]
833 ));
834 LegacyRegionUnlock ((UINT32)(UINTN)Context->Tables[DstIndex], Context->Tables[DstIndex]->Length);
835 }
836
837 if (Context->Tables[DstIndex]->Signature == EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
838 Context->Fadt = (EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE *)Context->Tables[DstIndex];
839
840 if (Context->Fadt->Header.Length >= OFFSET_OF (EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE, XDsdt) + sizeof (Context->Fadt->XDsdt)) {
841 Context->Dsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Context->Fadt->XDsdt;
842 } else {
843 Context->Dsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Context->Fadt->Dsdt;
844 }
845
846 DEBUG ((
847 DEBUG_INFO,
848 "OCA: Detected DSDT at %p of %u bytes at index %u\n",
849 Context->Dsdt,
850 Context->Dsdt->Length,
851 Index
852 ));
853
854 if ((UINTN)Context->Dsdt < BASE_1MB) {
855 DEBUG ((
856 DEBUG_INFO,
857 "OCA: Unlocking DSDT at %p\n",
858 Context->Dsdt
859 ));
860 LegacyRegionUnlock ((UINT32)(UINTN)Context->Tables[DstIndex], Context->Tables[DstIndex]->Length);
861 }
862 }
863
864 ++DstIndex;
865 }
866
867 if (Context->NumberOfTables != DstIndex) {
868 DEBUG ((DEBUG_INFO, "OCA: Only %u ACPI tables out of %u were valid\n", DstIndex, Context->NumberOfTables));
869 Context->NumberOfTables = DstIndex;
870 }
871
872 if (Context->Fadt == NULL) {
873 DEBUG ((DEBUG_WARN, "OCA: Failed to find ACPI FADT table\n"));
874 }
875
876 if (Context->Dsdt == NULL) {
877 DEBUG ((DEBUG_WARN, "OCA: Failed to find ACPI DSDT table\n"));
878 }
879
880 return EFI_SUCCESS;
881}
882
883VOID
885 IN OUT OC_ACPI_CONTEXT *Context
886 )
887{
888 if (Context->Tables != NULL) {
889 FreePool (Context->Tables);
890 Context->Tables = NULL;
891 }
892
893 if (Context->Regions != NULL) {
894 FreePool (Context->Regions);
895 Context->Regions = NULL;
896 }
897}
898
899EFI_STATUS
901 IN OUT OC_ACPI_CONTEXT *Context
902 )
903{
904 EFI_STATUS Status;
905 UINT32 XsdtSize;
906 UINT32 RsdtSize;
907 UINT32 Index;
908 UINT32 Size;
909 EFI_PHYSICAL_ADDRESS Table;
910 UINT32 TablePrintSignature;
911
912 XsdtSize = Context->Xsdt == NULL ? 0 : sizeof (*Context->Xsdt) + sizeof (Context->Xsdt->Tables[0]) * Context->NumberOfTables;
913 RsdtSize = Context->Rsdt == NULL ? 0 : sizeof (*Context->Rsdt) + sizeof (Context->Rsdt->Tables[0]) * Context->NumberOfTables;
914 Size = ALIGN_VALUE (XsdtSize, sizeof (UINT64)) + ALIGN_VALUE (RsdtSize, sizeof (UINT64));
915
916 Table = BASE_4GB - 1;
917 Status = gBS->AllocatePages (
918 AllocateMaxAddress,
919 EfiACPIMemoryNVS,
920 EFI_SIZE_TO_PAGES (Size),
921 &Table
922 );
923
924 if (EFI_ERROR (Status)) {
925 DEBUG ((DEBUG_WARN, "OCA: Failed to allocate %u bytes for ACPI system tables\n", Size));
926 return Status;
927 }
928
929 if (Context->Xsdt != NULL) {
930 CopyMem ((VOID *)(UINTN)Table, Context->Xsdt, sizeof (*Context->Xsdt));
931 Context->Xsdt = (OC_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE *)(UINTN)Table;
932 Context->Xsdt->Header.Length = XsdtSize;
933
934 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
935 Context->Xsdt->Tables[Index] = (UINT64)(UINTN)Context->Tables[Index];
936
937 TablePrintSignature = AcpiReadSignature (Context->Tables[Index]);
938
939 DEBUG ((
940 DEBUG_INFO,
941 "OCA: Exposing XSDT table table %.4a (%08x) (OEM %016Lx) at %p of %u bytes at index %u\n",
942 (CHAR8 *)&TablePrintSignature,
943 Context->Tables[Index]->Signature,
944 AcpiReadOemTableId (Context->Tables[Index]),
945 Context->Tables[Index],
946 Context->Tables[Index]->Length,
947 Index
948 ));
949 }
950
951 Context->Xsdt->Header.Checksum = 0;
952 Context->Xsdt->Header.Checksum = CalculateCheckSum8 (
953 (UINT8 *)Context->Xsdt,
954 Context->Xsdt->Header.Length
955 );
956
957 Context->Rsdp->XsdtAddress = (UINT64)Table;
958 Table += ALIGN_VALUE (XsdtSize, sizeof (UINT64));
959 }
960
961 if (Context->Rsdt != NULL) {
962 CopyMem ((VOID *)(UINTN)Table, Context->Rsdt, sizeof (*Context->Rsdt));
963 Context->Rsdt = (OC_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_TABLE *)(UINTN)Table;
964 Context->Rsdt->Header.Length = RsdtSize;
965
966 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
967 Context->Rsdt->Tables[Index] = (UINT32)(UINTN)Context->Tables[Index];
968
969 TablePrintSignature = AcpiReadSignature (Context->Tables[Index]);
970
971 DEBUG ((
972 Context->Xsdt != NULL ? DEBUG_BULK_INFO : DEBUG_INFO,
973 "OCA: Exposing RSDT table table %.4a (%08x) (OEM %016Lx) at %p of %u bytes at index %u\n",
974 (CHAR8 *)&TablePrintSignature,
975 Context->Tables[Index]->Signature,
976 AcpiReadOemTableId (Context->Tables[Index]),
977 Context->Tables[Index],
978 Context->Tables[Index]->Length,
979 Index
980 ));
981 }
982
983 Context->Rsdt->Header.Checksum = 0;
984 Context->Rsdt->Header.Checksum = CalculateCheckSum8 (
985 (UINT8 *)Context->Rsdt,
986 Context->Rsdt->Header.Length
987 );
988
989 Context->Rsdp->RsdtAddress = (UINT32)Table;
990 Table += ALIGN_VALUE (RsdtSize, sizeof (UINT64));
991 }
992
993 //
994 // Checksum is to be the first 0-19 bytes of RSDP.
995 // ExtendedChecksum is the entire table, only if newer than ACPI 1.0.
996 //
997 Context->Rsdp->Checksum = 0;
998 Context->Rsdp->Checksum = CalculateCheckSum8 (
999 (UINT8 *)Context->Rsdp,
1000 20
1001 );
1002
1003 if (Context->Xsdt != NULL) {
1004 Context->Rsdp->ExtendedChecksum = 0;
1005 Context->Rsdp->ExtendedChecksum = CalculateCheckSum8 (
1006 (UINT8 *)Context->Rsdp,
1007 Context->Rsdp->Length
1008 );
1009 }
1010
1011 return EFI_SUCCESS;
1012}
1013
1014EFI_STATUS
1016 IN OUT OC_ACPI_CONTEXT *Context,
1017 IN UINT32 Signature,
1018 IN UINT32 Length,
1019 IN UINT64 OemTableId,
1020 IN BOOLEAN All
1021 )
1022{
1023 UINT32 Index;
1024 UINT64 CurrOemTableId;
1025 BOOLEAN Found;
1026 UINT32 TablePrintSignature;
1027
1028 Index = 0;
1029 Found = FALSE;
1030
1031 while (Index < Context->NumberOfTables) {
1032 if ( ((Signature == 0) || (Context->Tables[Index]->Signature == Signature))
1033 && ((Length == 0) || (Context->Tables[Index]->Length == Length)))
1034 {
1035 if (Context->Tables[Index]->Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
1036 CurrOemTableId = ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Tables[Index])->OemTableId;
1037 } else {
1038 CurrOemTableId = 0;
1039 }
1040
1041 if ((OemTableId == 0) || (CurrOemTableId == OemTableId)) {
1042 TablePrintSignature = AcpiReadSignature (Context->Tables[Index]);
1043
1044 DEBUG ((
1045 DEBUG_INFO,
1046 "OCA: Deleting table %.4a (%08x) (OEM %016Lx) of %u bytes with %016Lx ID at index %u\n",
1047 (CHAR8 *)&TablePrintSignature,
1048 Context->Tables[Index]->Signature,
1049 AcpiReadOemTableId (Context->Tables[Index]),
1050 Context->Tables[Index]->Length,
1051 CurrOemTableId,
1052 Index
1053 ));
1054
1055 CopyMem (
1056 &Context->Tables[Index],
1057 &Context->Tables[Index+1],
1058 (Context->NumberOfTables - Index - 1) * sizeof (Context->Tables[0])
1059 );
1060 --Context->NumberOfTables;
1061
1062 if (All) {
1063 Found = TRUE;
1064 continue;
1065 } else {
1066 return EFI_SUCCESS;
1067 }
1068 }
1069 }
1070
1071 ++Index;
1072 }
1073
1074 if (Found) {
1075 return EFI_SUCCESS;
1076 }
1077
1078 return EFI_NOT_FOUND;
1079}
1080
1081EFI_STATUS
1083 IN OUT OC_ACPI_CONTEXT *Context,
1084 IN CONST UINT8 *Data,
1085 IN UINT32 Length
1086 )
1087{
1088 EFI_ACPI_COMMON_HEADER *Common;
1089 EFI_STATUS Status;
1090 EFI_ACPI_COMMON_HEADER *NewTable;
1091 EFI_ACPI_COMMON_HEADER **NewTables;
1092 BOOLEAN ReplaceDsdt;
1093 UINT32 TablePrintSignature;
1094
1095 if (Length < sizeof (EFI_ACPI_COMMON_HEADER)) {
1096 DEBUG ((DEBUG_WARN, "OCA: Inserted ACPI table is only %u bytes, ignoring\n", Length));
1097 return EFI_INVALID_PARAMETER;
1098 }
1099
1100 Common = (EFI_ACPI_COMMON_HEADER *)Data;
1101 if (Common->Length != Length) {
1102 DEBUG ((DEBUG_WARN, "OCA: Inserted ACPI table has length mismatch %u vs %u, ignoring\n", Length, Common->Length));
1103 return EFI_INVALID_PARAMETER;
1104 }
1105
1106 ReplaceDsdt = Common->Signature == EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
1107
1108 if (ReplaceDsdt && ((Context->Dsdt == NULL) || (Context->Fadt == NULL))) {
1109 DEBUG ((DEBUG_WARN, "OCA: We do not have DSDT to replace\n"));
1110 return EFI_INVALID_PARAMETER;
1111 }
1112
1113 if (!ReplaceDsdt && (Context->NumberOfTables == Context->AllocatedTables)) {
1114 NewTables = AllocatePool ((Context->NumberOfTables + 2) * sizeof (Context->Tables[0]));
1115 if (NewTables == NULL) {
1116 DEBUG ((DEBUG_WARN, "OCA: Cannot allocate space for new %u ACPI tables\n", Context->NumberOfTables+2));
1117 return EFI_OUT_OF_RESOURCES;
1118 }
1119
1120 CopyMem (NewTables, Context->Tables, Context->NumberOfTables * sizeof (Context->Tables[0]));
1121 FreePool (Context->Tables);
1122
1123 Context->Tables = NewTables;
1124 Context->AllocatedTables += 2;
1125 }
1126
1127 if (ReplaceDsdt) {
1128 DEBUG ((
1129 DEBUG_INFO,
1130 "OCA: Replaced DSDT of %u bytes into ACPI\n",
1131 Common->Length
1132 ));
1133
1134 Status = AcpiAllocateCopyDsdt (Context, (EFI_ACPI_DESCRIPTION_HEADER *)Data);
1135 if (EFI_ERROR (Status)) {
1136 return Status;
1137 }
1138 } else {
1139 Status = AcpiAllocateCopyTable ((EFI_ACPI_COMMON_HEADER *)Data, 0, &NewTable);
1140 if (EFI_ERROR (Status)) {
1141 return Status;
1142 }
1143
1144 TablePrintSignature = AcpiReadSignature (NewTable);
1145
1146 DEBUG ((
1147 DEBUG_INFO,
1148 "OCA: Inserted table %.4a (%08x) (OEM %016Lx) of %u bytes into ACPI at index %u\n",
1149 (CHAR8 *)&TablePrintSignature,
1150 NewTable->Signature,
1151 AcpiReadOemTableId (NewTable),
1152 NewTable->Length,
1153 Context->NumberOfTables
1154 ));
1155
1156 Context->Tables[Context->NumberOfTables] = NewTable;
1157 ++Context->NumberOfTables;
1158 }
1159
1160 return EFI_SUCCESS;
1161}
1162
1163VOID
1165 IN OUT OC_ACPI_CONTEXT *Context
1166 )
1167{
1168 EFI_STATUS Status;
1169 UINT32 Index;
1170 EFI_ACPI_COMMON_HEADER *NewTable;
1171 UINT32 TablePrintSignature;
1172
1173 if (AcpiNormalizeRsdp (Context->Rsdp, (Context->Xsdt != NULL))) {
1174 DEBUG ((DEBUG_INFO, "OCA: Normalized RSDP\n"));
1175 }
1176
1177 if (Context->Xsdt != NULL) {
1178 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Xsdt)) {
1179 Status = AcpiAllocateCopyTable ((EFI_ACPI_COMMON_HEADER *)Context->Xsdt, 0, &NewTable);
1180 if (EFI_ERROR (Status)) {
1181 return;
1182 }
1183
1184 Context->Xsdt = (OC_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE *)NewTable;
1185 }
1186
1187 if (AcpiNormalizeTableHeaders ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Xsdt)) {
1188 DEBUG ((DEBUG_INFO, "OCA: Normalized XSDT of %u bytes headers\n", Context->Xsdt->Header.Length));
1189 }
1190 }
1191
1192 if (Context->Rsdt != NULL) {
1193 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Rsdt)) {
1194 Status = AcpiAllocateCopyTable ((EFI_ACPI_COMMON_HEADER *)Context->Rsdt, 0, &NewTable);
1195 if (EFI_ERROR (Status)) {
1196 return;
1197 }
1198
1199 Context->Rsdt = (OC_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_TABLE *)NewTable;
1200 }
1201
1202 if (AcpiNormalizeTableHeaders ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Rsdt)) {
1203 DEBUG ((DEBUG_INFO, "OCA: Normalized RSDT of %u bytes headers\n", Context->Rsdt->Header.Length));
1204 }
1205 }
1206
1207 if (Context->Dsdt != NULL) {
1208 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Dsdt)) {
1209 Status = AcpiAllocateCopyDsdt (Context, NULL);
1210 if (EFI_ERROR (Status)) {
1211 return;
1212 }
1213 }
1214
1215 if (AcpiNormalizeTableHeaders (Context->Dsdt)) {
1216 DEBUG ((DEBUG_INFO, "OCA: Normalized DSDT of %u bytes headers\n", Context->Dsdt->Length));
1217 }
1218 }
1219
1220 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
1221 if (!AcpiIsTableWritable (Context->Tables[Index])) {
1222 Status = AcpiAllocateCopyTable (Context->Tables[Index], 0, &NewTable);
1223 if (EFI_ERROR (Status)) {
1224 return;
1225 }
1226
1227 Context->Tables[Index] = NewTable;
1228 }
1229
1230 if (AcpiNormalizeTableHeaders ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Tables[Index])) {
1231 TablePrintSignature = AcpiReadSignature (Context->Tables[Index]);
1232
1233 DEBUG ((
1234 DEBUG_INFO,
1235 "OCA: Normalized %.4a (%08x) (OEM %016Lx) of %u bytes headers at index %u\n",
1236 (CHAR8 *)&TablePrintSignature,
1237 Context->Tables[Index]->Signature,
1238 AcpiReadOemTableId (Context->Tables[Index]),
1239 Context->Tables[Index]->Length,
1240 Index
1241 ));
1242 }
1243 }
1244}
1245
1246EFI_STATUS
1248 IN OUT OC_ACPI_CONTEXT *Context,
1249 IN OC_ACPI_PATCH *Patch
1250 )
1251{
1252 EFI_STATUS Status;
1253 EFI_ACPI_COMMON_HEADER *NewTable;
1254 UINT32 Index;
1255 UINT32 BaseOffset;
1256 UINT64 CurrOemTableId;
1257 UINT32 ReplaceCount;
1258 UINT32 ReplaceLimit;
1259 UINT32 TablePrintSignature;
1260
1261 if ( (Context->Dsdt != NULL)
1262 && ((Patch->TableSignature == 0) || (Patch->TableSignature == EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE))
1263 && ((Patch->TableLength == 0) || (Context->Dsdt->Length == Patch->TableLength))
1264 && ((Patch->OemTableId == 0) || (Context->Dsdt->OemTableId == Patch->OemTableId)))
1265 {
1266 ReplaceLimit = Context->Dsdt->Length;
1267 if (Patch->Limit > 0) {
1268 ReplaceLimit = MIN (ReplaceLimit, Patch->Limit);
1269 }
1270
1271 BaseOffset = 0;
1272
1273 if ((Patch->Base != NULL) && (Patch->Base[0] != '\0')) {
1274 Status = AcpiFindEntryInMemory (
1275 (VOID *)Context->Dsdt,
1276 Patch->Base,
1277 (UINT8)(Patch->BaseSkip + 1),
1278 &BaseOffset,
1279 Context->Dsdt->Length
1280 );
1281 if (!EFI_ERROR (Status)) {
1282 ReplaceLimit = MIN (ReplaceLimit, Context->Dsdt->Length - BaseOffset);
1283 } else {
1284 DEBUG ((
1285 DEBUG_INFO,
1286 "OCA: Patching DSDT of %u bytes failed to find base %a\n",
1287 Context->Dsdt->Length,
1288 Patch->Base
1289 ));
1290 }
1291 } else {
1292 Status = EFI_SUCCESS;
1293 }
1294
1295 if (!EFI_ERROR (Status)) {
1296 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Dsdt)) {
1297 Status = AcpiAllocateCopyDsdt (Context, NULL);
1298 if (EFI_ERROR (Status)) {
1299 return Status;
1300 }
1301 }
1302
1303 ReplaceCount = ApplyPatch (
1304 Patch->Find,
1305 Patch->Mask,
1306 Patch->Size,
1307 Patch->Replace,
1308 Patch->ReplaceMask,
1309 (UINT8 *)Context->Dsdt + BaseOffset,
1310 ReplaceLimit,
1311 Patch->Count,
1312 Patch->Skip
1313 );
1314
1315 DEBUG ((
1316 ReplaceCount > 0 ? DEBUG_INFO : DEBUG_BULK_INFO,
1317 "OCA: Patching DSDT of %u bytes with %016Lx ID replaced %u of %u\n",
1318 ReplaceLimit,
1319 Patch->OemTableId,
1320 ReplaceCount,
1321 Patch->Count
1322 ));
1323
1324 if (ReplaceCount > 0) {
1325 AcpiRefreshTableChecksum (Context->Dsdt);
1326 }
1327 }
1328 }
1329
1330 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
1331 if ( ((Patch->TableSignature == 0) || (Context->Tables[Index]->Signature == Patch->TableSignature))
1332 && ((Patch->TableLength == 0) || (Context->Tables[Index]->Length == Patch->TableLength)))
1333 {
1334 if (Context->Tables[Index]->Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
1335 CurrOemTableId = ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Tables[Index])->OemTableId;
1336 } else {
1337 CurrOemTableId = 0;
1338 }
1339
1340 if ((Patch->OemTableId != 0) && (CurrOemTableId != Patch->OemTableId)) {
1341 continue;
1342 }
1343
1344 ReplaceLimit = Context->Tables[Index]->Length;
1345 if (Patch->Limit > 0) {
1346 ReplaceLimit = MIN (ReplaceLimit, Patch->Limit);
1347 }
1348
1349 TablePrintSignature = AcpiReadSignature (Context->Tables[Index]);
1350
1351 BaseOffset = 0;
1352 if ((Patch->Base != NULL) && (Patch->Base[0] != '\0')) {
1353 Status = AcpiFindEntryInMemory (
1354 (VOID *)Context->Tables[Index],
1355 Patch->Base,
1356 (UINT8)(Patch->BaseSkip + 1),
1357 &BaseOffset,
1358 Context->Tables[Index]->Length
1359 );
1360 if (EFI_ERROR (Status)) {
1361 DEBUG ((
1362 DEBUG_INFO,
1363 "OCA: Patching %.4a (%08x) (OEM %016Lx) of %u bytes with %016Lx ID failed to find base %a\n",
1364 (CHAR8 *)&TablePrintSignature,
1365 Context->Tables[Index]->Signature,
1366 AcpiReadOemTableId (Context->Tables[Index]),
1367 Context->Tables[Index]->Length,
1368 CurrOemTableId,
1369 Patch->Base
1370 ));
1371 continue;
1372 }
1373
1374 ReplaceLimit = MIN (ReplaceLimit, Context->Tables[Index]->Length - BaseOffset);
1375 }
1376
1377 if (!AcpiIsTableWritable (Context->Tables[Index])) {
1378 Status = AcpiAllocateCopyTable (Context->Tables[Index], 0, &NewTable);
1379 if (EFI_ERROR (Status)) {
1380 return Status;
1381 }
1382
1383 Context->Tables[Index] = NewTable;
1384 }
1385
1386 ReplaceCount = ApplyPatch (
1387 Patch->Find,
1388 Patch->Mask,
1389 Patch->Size,
1390 Patch->Replace,
1391 Patch->ReplaceMask,
1392 (UINT8 *)Context->Tables[Index] + BaseOffset,
1393 ReplaceLimit,
1394 Patch->Count,
1395 Patch->Skip
1396 );
1397
1398 DEBUG ((
1399 ReplaceCount > 0 ? DEBUG_INFO : DEBUG_BULK_INFO,
1400 "OCA: Patching %.4a (%08x) (OEM %016Lx) of %u bytes with %016Lx ID at %u replaced %u of %u\n",
1401 (CHAR8 *)&TablePrintSignature,
1402 Context->Tables[Index]->Signature,
1403 AcpiReadOemTableId (Context->Tables[Index]),
1404 Context->Tables[Index]->Length,
1405 CurrOemTableId,
1406 Index,
1407 ReplaceCount,
1408 Patch->Count
1409 ));
1410
1411 if ((ReplaceCount > 0) && (Context->Tables[Index]->Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER))) {
1412 AcpiRefreshTableChecksum ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Tables[Index]);
1413 }
1414 }
1415 }
1416
1417 return EFI_SUCCESS;
1418}
1419
1420EFI_STATUS
1422 IN OUT OC_ACPI_CONTEXT *Context
1423 )
1424{
1425 EFI_STATUS Status;
1426 UINT32 Index;
1427
1428 //
1429 // Should not be called twice, but just in case.
1430 //
1431 ASSERT (Context->Regions == NULL);
1432
1433 //
1434 // Allocate something reasonably large by default.
1435 //
1436 Context->NumberOfRegions = 0;
1437 Context->AllocatedRegions = 8;
1438 Context->Regions = AllocatePool (sizeof (Context->Regions[0]) * Context->AllocatedRegions);
1439
1440 if (Context->Regions == NULL) {
1441 DEBUG ((DEBUG_WARN, "OCA: Failed to allocate memory for %u regions\n", Context->NumberOfRegions));
1442 return EFI_OUT_OF_RESOURCES;
1443 }
1444
1445 if (Context->Dsdt != NULL) {
1446 Status = AcpiLoadTableRegions (Context, (EFI_ACPI_COMMON_HEADER *)Context->Dsdt);
1447 if (EFI_ERROR (Status)) {
1448 return Status;
1449 }
1450 }
1451
1452 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
1453 if (Context->Tables[Index]->Signature == EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
1454 Status = AcpiLoadTableRegions (Context, Context->Tables[Index]);
1455 if (EFI_ERROR (Status)) {
1456 return Status;
1457 }
1458 }
1459 }
1460
1461 return EFI_SUCCESS;
1462}
1463
1464VOID
1466 IN OUT OC_ACPI_CONTEXT *Context
1467 )
1468{
1469 EFI_STATUS Status;
1470 UINT32 Index;
1471 EFI_ACPI_COMMON_HEADER *NewTable;
1472
1473 //
1474 // Should not be called before AcpiLoadRegions, but just in case.
1475 //
1476 ASSERT (Context->Regions != NULL);
1477
1478 if (Context->NumberOfRegions == 0) {
1479 return;
1480 }
1481
1482 if (Context->Dsdt != NULL) {
1483 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Dsdt)) {
1484 Status = AcpiAllocateCopyDsdt (Context, NULL);
1485 if (EFI_ERROR (Status)) {
1486 return;
1487 }
1488 }
1489
1490 AcpiRelocateTableRegions (Context, (EFI_ACPI_COMMON_HEADER *)Context->Dsdt);
1491 }
1492
1493 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
1494 if (Context->Tables[Index]->Signature == EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
1495 if (!AcpiIsTableWritable (Context->Tables[Index])) {
1496 Status = AcpiAllocateCopyTable (Context->Tables[Index], 0, &NewTable);
1497 if (EFI_ERROR (Status)) {
1498 return;
1499 }
1500
1501 Context->Tables[Index] = NewTable;
1502 }
1503
1504 AcpiRelocateTableRegions (Context, Context->Tables[Index]);
1505 }
1506 }
1507}
1508
1509EFI_STATUS
1511 IN OUT OC_ACPI_CONTEXT *Context
1512 )
1513{
1514 EFI_STATUS Status;
1515 UINT32 OldSize;
1516 UINT32 RequiredSize;
1517
1518 if (Context->Fadt == NULL) {
1519 return EFI_NOT_FOUND;
1520 }
1521
1522 OldSize = Context->Fadt->Header.Length;
1523 RequiredSize = OFFSET_OF (EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE, ArmBootArch);
1524
1525 DEBUG ((DEBUG_INFO, "OCA: FADT reset got %u need %u\n", OldSize, RequiredSize));
1526
1527 //
1528 // One some types of firmware, the table is too small and does not include
1529 // Reset Register area. We will reallocate in this case.
1530 // Interestingly EFI_ACPI_6_2_RESET_REG_SUP may be set.
1531 //
1532 // REF: https://github.com/acidanthera/bugtracker/issues/897
1533 //
1534
1535 if ((OldSize < RequiredSize) || !AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Fadt)) {
1536 Status = AcpiAllocateCopyFadt (Context, OldSize < RequiredSize ? RequiredSize : 0);
1537 if (EFI_ERROR (Status)) {
1538 return Status;
1539 }
1540 } else if (!( ((Context->Fadt->Flags & EFI_ACPI_6_2_RESET_REG_SUP) == 0)
1541 || ((Context->Fadt->Flags & EFI_ACPI_6_2_SLP_BUTTON) == 0)
1542 || ((Context->Fadt->Flags & EFI_ACPI_6_2_PWR_BUTTON) != 0)
1543 || (Context->Fadt->ResetReg.Address == 0)
1544 || (Context->Fadt->ResetReg.Address == 0x64)
1545 || (Context->Fadt->ResetReg.RegisterBitWidth != 8)))
1546 {
1547 return EFI_SUCCESS;
1548 }
1549
1550 //
1551 // Enable sleep button, but disable power button actions.
1552 // This resolves power button action in macOS on some models.
1553 //
1554 Context->Fadt->Flags |= EFI_ACPI_6_2_SLP_BUTTON | EFI_ACPI_6_2_RESET_REG_SUP;
1555 Context->Fadt->Flags &= ~EFI_ACPI_6_2_PWR_BUTTON;
1556
1557 //
1558 // We also change keyboard controller reset (0xFE to 0x64) to 0xCF9 reset
1559 // as it is known to work incorrectly at least on Dell Latitude E6410
1560 // when the NVIDIA GPU is attached.
1561 //
1562 if ( (Context->Fadt->ResetReg.Address == 0)
1563 || (Context->Fadt->ResetReg.Address == 0x64)
1564 || (Context->Fadt->ResetReg.RegisterBitWidth != 8))
1565 {
1566 //
1567 // Resetting through port 0xCF9 is universal on Intel and AMD.
1568 // But may not be the case on e.g. Dell laptops and desktops, which use 0xB2.
1569 //
1570 if (PciRead16 (0) == PCI_VENDOR_NVIDIA) {
1571 //
1572 // Use 0x64 / 0xFE on NVIDIA chipset platforms.
1573 //
1574 Context->Fadt->ResetReg.Address = 0x64;
1575 Context->Fadt->ResetValue = 0xFE;
1576 } else {
1577 //
1578 // Use mostly universal default of 0xCF9.
1579 //
1580 Context->Fadt->ResetReg.Address = 0xCF9;
1581 Context->Fadt->ResetValue = 6;
1582 }
1583
1584 Context->Fadt->ResetReg.AddressSpaceId = EFI_ACPI_6_2_SYSTEM_IO;
1585 Context->Fadt->ResetReg.RegisterBitWidth = 8;
1586 Context->Fadt->ResetReg.RegisterBitOffset = 0;
1587 Context->Fadt->ResetReg.AccessSize = EFI_ACPI_6_2_BYTE;
1588 }
1589
1590 AcpiRefreshTableChecksum ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Fadt);
1591
1592 return EFI_SUCCESS;
1593}
1594
1595VOID
1597 IN OUT OC_ACPI_CONTEXT *Context
1598 )
1599{
1600 EFI_STATUS Status;
1601 UINT32 Index;
1602
1603 EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE *Bgrt;
1604 EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE *BgrtNew;
1605
1606 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
1607 if (Context->Tables[Index]->Signature == EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE) {
1608 if (Context->Tables[Index]->Length >= sizeof (EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE)) {
1609 Bgrt = (EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE *)Context->Tables[Index];
1610
1611 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Bgrt)) {
1612 Status = AcpiAllocateCopyTable (
1613 (EFI_ACPI_COMMON_HEADER *)Bgrt,
1614 0,
1615 (EFI_ACPI_COMMON_HEADER **)&BgrtNew
1616 );
1617
1618 if (EFI_ERROR (Status)) {
1619 return;
1620 }
1621
1622 Context->Tables[Index] = (EFI_ACPI_COMMON_HEADER *)BgrtNew;
1623 Bgrt = BgrtNew;
1624 }
1625
1626 Bgrt->Status &= ~EFI_ACPI_6_2_BGRT_STATUS_DISPLAYED;
1627 Bgrt->Header.Checksum = 0;
1628 Bgrt->Header.Checksum = CalculateCheckSum8 (
1629 (UINT8 *)Bgrt,
1630 Bgrt->Header.Length
1631 );
1632 }
1633
1634 break;
1635 }
1636 }
1637}
1638
1639VOID
1641 IN OUT OC_ACPI_CONTEXT *Context
1642 )
1643{
1644 EFI_ACPI_DESCRIPTION_HEADER *Slic;
1645 UINT32 Index;
1646
1647 Slic = NULL;
1648 for (Index = 0; Index < Context->NumberOfTables; ++Index) {
1649 if (Context->Tables[Index]->Signature == EFI_ACPI_6_2_SOFTWARE_LICENSING_TABLE_SIGNATURE) {
1650 Slic = (VOID *)Context->Tables[Index];
1651 break;
1652 }
1653 }
1654
1655 if (Slic == NULL) {
1656 DEBUG ((DEBUG_INFO, "OCA: SLIC table is not found\n"));
1657 return;
1658 }
1659
1660 //
1661 // SLIC identifiers must match RSDT and FADT, also doing XSDT for newer EFI just in case.
1662 // REF: https://bugzilla.redhat.com/show_bug.cgi?id=1248758
1663 //
1664
1665 if (Context->Rsdt != NULL) {
1666 CopyMem (&Context->Rsdt->Header.OemId, &Slic->OemId, sizeof (Context->Rsdt->Header.OemId));
1667 Context->Rsdt->Header.OemTableId = Slic->OemTableId;
1668 Context->Rsdt->Header.Checksum = 0;
1669 Context->Rsdt->Header.Checksum = CalculateCheckSum8 (
1670 (UINT8 *)Context->Rsdt,
1671 Context->Rsdt->Header.Length
1672 );
1673 DEBUG ((DEBUG_INFO, "OCA: SLIC table IDs fixed in RSDT\n"));
1674 }
1675
1676 if (Context->Xsdt != NULL) {
1677 CopyMem (&Context->Xsdt->Header.OemId, &Slic->OemId, sizeof (Context->Xsdt->Header.OemId));
1678 Context->Xsdt->Header.OemTableId = Slic->OemTableId;
1679 Context->Xsdt->Header.Checksum = 0;
1680 Context->Xsdt->Header.Checksum = CalculateCheckSum8 (
1681 (UINT8 *)Context->Xsdt,
1682 Context->Xsdt->Header.Length
1683 );
1684 DEBUG ((DEBUG_INFO, "OCA: SLIC table IDs fixed in XSDT\n"));
1685 }
1686
1687 if (Context->Fadt != NULL) {
1688 CopyMem (&Context->Fadt->Header.OemId, &Slic->OemId, sizeof (Context->Fadt->Header.OemId));
1689 Context->Fadt->Header.OemTableId = Slic->OemTableId;
1690 Context->Fadt->Header.Checksum = 0;
1691 Context->Fadt->Header.Checksum = CalculateCheckSum8 (
1692 (UINT8 *)Context->Fadt,
1693 Context->Fadt->Header.Length
1694 );
1695 DEBUG ((DEBUG_INFO, "OCA: SLIC table IDs fixed in FADT\n"));
1696 }
1697}
1698
1699VOID
1701 IN OUT OC_ACPI_CONTEXT *Context,
1702 IN BOOLEAN Reset
1703 )
1704{
1705 EFI_STATUS Status;
1706 BOOLEAN IsXFirmwareCtrl;
1707
1708 EFI_ACPI_6_2_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs;
1709 EFI_ACPI_6_2_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsNew;
1710
1711 if (Context->Fadt == NULL) {
1712 return;
1713 }
1714
1715 if (Context->Fadt->Header.Length >= OFFSET_OF (EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE, XFirmwareCtrl) + sizeof (Context->Fadt->XFirmwareCtrl)) {
1716 Facs = (EFI_ACPI_6_2_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Context->Fadt->XFirmwareCtrl;
1717 IsXFirmwareCtrl = TRUE;
1718 } else {
1719 Facs = NULL;
1720 IsXFirmwareCtrl = FALSE;
1721 }
1722
1723 if ((Facs == NULL) && (Context->Fadt->Header.Length >= OFFSET_OF (EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE, FirmwareCtrl) + sizeof (Context->Fadt->FirmwareCtrl))) {
1724 Facs = (EFI_ACPI_6_2_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Context->Fadt->FirmwareCtrl;
1725 }
1726
1727 if ((Facs != NULL) && (Facs->Length >= OFFSET_OF (EFI_ACPI_6_2_FIRMWARE_ACPI_CONTROL_STRUCTURE, Flags) + sizeof (Facs->HardwareSignature))) {
1728 DEBUG ((DEBUG_INFO, "OCA: FACS signature is %X (%d)\n", Facs->Flags, Reset));
1729
1730 if (Reset) {
1731 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Facs)) {
1732 Status = AcpiAllocateCopyTable (
1733 (EFI_ACPI_COMMON_HEADER *)Facs,
1734 0,
1735 (EFI_ACPI_COMMON_HEADER **)&FacsNew
1736 );
1737 if (EFI_ERROR (Status)) {
1738 return;
1739 }
1740
1741 //
1742 // Reallocate FADT if needed.
1743 //
1744 if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *)Context->Fadt)) {
1745 Status = AcpiAllocateCopyFadt (Context, 0);
1746 if (EFI_ERROR (Status)) {
1747 FreePool (FacsNew);
1748 return;
1749 }
1750 }
1751
1752 if (IsXFirmwareCtrl) {
1753 Context->Fadt->XFirmwareCtrl = (UINT64)(UINTN)FacsNew;
1754 } else {
1755 Context->Fadt->FirmwareCtrl = (UINT32)(UINTN)FacsNew;
1756 }
1757
1758 AcpiRefreshTableChecksum ((EFI_ACPI_DESCRIPTION_HEADER *)Context->Fadt);
1759
1760 Facs = FacsNew;
1761 }
1762
1763 //
1764 // TODO: We might also want to unset S4BIOS_F flag in Facs->Flags.
1765 //
1766 Facs->HardwareSignature = 0x0;
1767 }
1768 } else {
1769 //
1770 // For macOS this is just fine.
1771 //
1772 DEBUG ((
1773 DEBUG_INFO,
1774 "OCA: FACS signature is too far %d / %u\n",
1775 Facs != NULL,
1776 Facs != NULL ? Facs->Length : 0
1777 ));
1778 }
1779}
UINT64 Length
UINT8 Signature[8]
Definition BiosId.h:67
STATIC UINT32 AcpiFindName(IN CONST UINT8 *Data, IN UINT32 Length, IN CONST CHAR8 *Name)
Definition OcAcpiLib.c:241
STATIC EFI_STATUS AcpiAllocateCopyFadt(IN OUT OC_ACPI_CONTEXT *Context, IN UINT32 NewSize)
Definition OcAcpiLib.c:362
STATIC UINT64 AcpiReadOemTableId(IN CONST EFI_ACPI_COMMON_HEADER *Common)
Definition OcAcpiLib.c:174
STATIC VOID AcpiRelocateTableRegions(IN OUT OC_ACPI_CONTEXT *Context, IN EFI_ACPI_COMMON_HEADER *Table)
Definition OcAcpiLib.c:534
VOID AcpiNormalizeHeaders(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:1164
EFI_STATUS AcpiApplyContext(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:900
EFI_STATUS AcpiFadtEnableReset(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:1510
STATIC EFI_STATUS AcpiAllocateCopyTable(IN EFI_ACPI_COMMON_HEADER *Table, IN UINT32 NewSize OPTIONAL, OUT EFI_ACPI_COMMON_HEADER **NewTable)
Definition OcAcpiLib.c:311
STATIC EFI_STATUS AcpiLoadTableRegions(IN OUT OC_ACPI_CONTEXT *Context, IN EFI_ACPI_COMMON_HEADER *Table)
Definition OcAcpiLib.c:446
STATIC EFI_STATUS AcpiAllocateCopyDsdt(IN OUT OC_ACPI_CONTEXT *Context, IN EFI_ACPI_DESCRIPTION_HEADER *NewDsdt OPTIONAL)
Definition OcAcpiLib.c:396
EFI_STATUS AcpiDeleteTable(IN OUT OC_ACPI_CONTEXT *Context, IN UINT32 Signature, IN UINT32 Length, IN UINT64 OemTableId, IN BOOLEAN All)
Definition OcAcpiLib.c:1015
EFI_STATUS AcpiApplyPatch(IN OUT OC_ACPI_CONTEXT *Context, IN OC_ACPI_PATCH *Patch)
Definition OcAcpiLib.c:1247
VOID AcpiSyncTableIds(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:1640
VOID AcpiFreeContext(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:884
STATIC UINT32 AcpiReadSignature(IN CONST EFI_ACPI_COMMON_HEADER *Common)
Definition OcAcpiLib.c:145
VOID AcpiRelocateRegions(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:1465
VOID AcpiHandleHardwareSignature(IN OUT OC_ACPI_CONTEXT *Context, IN BOOLEAN Reset)
Definition OcAcpiLib.c:1700
STATIC VOID AcpiRefreshTableChecksum(IN EFI_ACPI_DESCRIPTION_HEADER *Table)
Definition OcAcpiLib.c:272
STATIC BOOLEAN AcpiIsTableWritable(IN EFI_ACPI_COMMON_HEADER *Table)
Definition OcAcpiLib.c:292
VOID AcpiResetLogoStatus(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:1596
STATIC EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER * AcpiFindLegacyRsdp(VOID)
Definition OcAcpiLib.c:42
STATIC BOOLEAN AcpiReadName(IN CONST UINT8 *Data, OUT CHAR8 *Name, OUT UINT32 *NameOffset OPTIONAL)
Definition OcAcpiLib.c:196
STATIC EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER * AcpiFindRsdp(VOID)
Definition OcAcpiLib.c:87
STATIC BOOLEAN AcpiNormalizeTableHeaders(IN EFI_ACPI_DESCRIPTION_HEADER *Table)
Definition OcAcpiLib.c:629
#define PCI_VENDOR_NVIDIA
Definition OcAcpiLib.c:33
EFI_STATUS AcpiInitContext(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:738
EFI_STATUS AcpiLoadRegions(IN OUT OC_ACPI_CONTEXT *Context)
Definition OcAcpiLib.c:1421
EFI_STATUS AcpiInsertTable(IN OUT OC_ACPI_CONTEXT *Context, IN CONST UINT8 *Data, IN UINT32 Length)
Definition OcAcpiLib.c:1082
STATIC BOOLEAN AcpiNormalizeRsdp(IN EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp, IN BOOLEAN HasXsdt)
Definition OcAcpiLib.c:695
EFI_STATUS AcpiFindEntryInMemory(IN UINT8 *Table, IN CONST CHAR8 *PathString, IN UINT8 Entry, OUT UINT32 *Offset, IN UINT32 TableLength OPTIONAL)
#define OC_ACPI_NAME_SIZE
Definition OcAcpiLib.h:21
DMG_SIZE_DEVICE_PATH Size
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
#define DEBUG_BULK_INFO
EFI_STATUS LegacyRegionUnlock(IN UINT32 LegacyAddress, IN UINT32 LegacyLength)
UINT32 ApplyPatch(IN CONST UINT8 *Pattern, IN CONST UINT8 *PatternMask OPTIONAL, IN CONST UINT32 PatternSize, IN CONST UINT8 *Replace, IN CONST UINT8 *ReplaceMask OPTIONAL, IN UINT8 *Data, IN UINT32 DataSize, IN UINT32 Count, IN UINT32 Skip)
BOOLEAN IsAsciiPrint(IN CHAR8 Char)
Definition OcAsciiLib.c:33
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define ASSERT(x)
Definition coder.h:55
#define MIN(a, b)
Definition deflate.c:1673