OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcAfterBootCompatLib.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16
17#include <Library/BaseLib.h>
18#include <Library/BaseMemoryLib.h>
20#include <Library/DevicePathLib.h>
21#include <Library/MemoryAllocationLib.h>
24#include <Library/OcMiscLib.h>
25#include <Library/PrintLib.h>
26#include <Library/UefiRuntimeServicesTableLib.h>
27#include <Library/UefiBootServicesTableLib.h>
28
30
31#include "BootCompatInternal.h"
32
41
47
48STATIC
49EFI_STATUS
51 VOID
52 )
53{
54 EFI_STATUS Status;
55 VOID *Interface;
56 EFI_HANDLE Handle;
57
58 Status = gBS->LocateProtocol (
60 NULL,
61 &Interface
62 );
63
64 if (!EFI_ERROR (Status)) {
65 //
66 // Ensure we do not run with AptioMemoryFix.
67 // It also checks for attempts to install this protocol twice.
68 //
69 DEBUG ((DEBUG_WARN, "OCABC: Found legacy AptioMemoryFix driver!\n"));
70 return EFI_ALREADY_STARTED;
71 }
72
73 Handle = NULL;
74 Status = gBS->InstallMultipleProtocolInterfaces (
75 &Handle,
78 NULL
79 );
80
81 if (EFI_ERROR (Status)) {
82 DEBUG ((DEBUG_WARN, "OCABC: protocol install failure - %r\n", Status));
83 return Status;
84 }
85
86 return EFI_SUCCESS;
87}
88
91 VOID
92 )
93{
95}
96
97EFI_STATUS
99 IN OC_ABC_SETTINGS *Settings,
100 IN OC_CPU_INFO *CpuInfo
101 )
102{
103 EFI_STATUS Status;
104 BOOT_COMPAT_CONTEXT *BootCompat;
105 UINTN LowMemory;
106 UINTN TotalMemory;
107
108 Status = InstallAbcProtocol ();
109 if (EFI_ERROR (Status)) {
110 return Status;
111 }
112
113 DEBUG ((
114 DEBUG_INFO,
115 "OCABC: ALRBL %d RTDFRG %d DEVMMIO %d NOSU %d NOVRWR %d NOSB %d FBSIG %d NOHBMAP %d SMSLIDE %d WRUNPROT %d CLRTS %d\n",
116 Settings->AllowRelocationBlock,
117 Settings->AvoidRuntimeDefrag,
118 Settings->DevirtualiseMmio,
119 Settings->DisableSingleUser,
120 Settings->DisableVariableWrite,
121 Settings->ProtectSecureBoot,
122 Settings->ForceBooterSignature,
123 Settings->DiscardHibernateMap,
124 Settings->EnableSafeModeSlide,
125 Settings->EnableWriteUnprotector,
126 Settings->ClearTaskSwitchBit
127 ));
128
129 DEBUG ((
130 DEBUG_INFO,
131 "OCABC: FEXITBS %d PRMRG %d CSLIDE %d MSLIDE %d PRSRV %d RBMAP %d VMAP %d APPLOS %d RTPERMS %d ARBAR %d RBIO %d\n",
132 Settings->ForceExitBootServices,
133 Settings->ProtectMemoryRegions,
134 Settings->ProvideCustomSlide,
135 Settings->ProvideMaxSlide,
136 Settings->ProtectUefiServices,
137 Settings->RebuildAppleMemoryMap,
138 Settings->SetupVirtualMap,
139 Settings->SignalAppleOS,
140 Settings->SyncRuntimePermissions,
141 Settings->ResizeAppleGpuBars,
142 Settings->ResizeUsePciRbIo
143 ));
144
145 DEBUG_CODE_BEGIN ();
146 TotalMemory = OcCountFreePages (&LowMemory);
147 DEBUG ((
148 DEBUG_INFO,
149 "OCABC: Firmware has %Lu free pages (%Lu in lower 4 GB)\n",
150 (UINT64)TotalMemory,
151 (UINT64)LowMemory
152 ));
153 DEBUG_CODE_END ();
154
155 BootCompat = GetBootCompatContext ();
156
157 CopyMem (
158 &BootCompat->Settings,
159 Settings,
160 sizeof (BootCompat->Settings)
161 );
162
163 BootCompat->CpuInfo = CpuInfo;
164
165 InstallServiceOverrides (BootCompat);
166
167 return EFI_SUCCESS;
168}
VOID InstallServiceOverrides(IN OUT BOOT_COMPAT_CONTEXT *BootCompat)
EFI_GUID gOcAfterBootCompatProtocolGuid
#define OC_AFTER_BOOT_COMPAT_PROTOCOL_REVISION
BOOT_COMPAT_CONTEXT * GetBootCompatContext(VOID)
STATIC OC_AFTER_BOOT_COMPAT_PROTOCOL mOcAfterBootCompatProtocol
EFI_STATUS OcAbcInitialize(IN OC_ABC_SETTINGS *Settings, IN OC_CPU_INFO *CpuInfo)
STATIC BOOT_COMPAT_CONTEXT mOcAfterBootCompatContext
STATIC EFI_STATUS InstallAbcProtocol(VOID)
EFI_BOOT_SERVICES * gBS
UINTN OcCountFreePages(OUT UINTN *LowerMemory OPTIONAL)
APPLE_EVENT_HANDLE Handle
Definition OcTypingLib.h:45
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)