Handle booter quircks.

This commit is contained in:
jief666 2020-09-09 20:06:34 +03:00
parent 389ec9d17c
commit 232f94f00c
5 changed files with 134 additions and 96 deletions

View File

@ -349,26 +349,26 @@ EFI_KEYBOARD_INFO_PROTOCOL mKeyboardInfo = {
UsbKbGetKeyboardDeviceInfo
};
#define OCQUIRKS_PROTOCOL_REVISION 23
EFI_STATUS
EFIAPI
GetQuirksConfig (IN OCQUIRKS_PROTOCOL *This,
OUT OC_ABC_SETTINGS_4CLOVER *Buffer,
OUT BOOLEAN *GopEnable
)
{
DBG("GetQuirksConfig called\n");
CopyMem(Buffer, &gQuirks, sizeof(OC_ABC_SETTINGS_4CLOVER));
*GopEnable = gProvideConsoleGopEnable;
return EFI_SUCCESS;
}
OCQUIRKS_PROTOCOL mQuirksConfig = {
OCQUIRKS_PROTOCOL_REVISION,
0, //reserved
GetQuirksConfig
};
//#define OCQUIRKS_PROTOCOL_REVISION 23
//
//EFI_STATUS
//EFIAPI
//GetQuirksConfig (IN OCQUIRKS_PROTOCOL *This,
// OUT OC_ABC_SETTINGS_4CLOVER *Buffer,
// OUT BOOLEAN *GopEnable
// )
//{
// DBG("GetQuirksConfig called\n");
// CopyMem(Buffer, &gQuirks, sizeof(OC_ABC_SETTINGS_4CLOVER));
// *GopEnable = gProvideConsoleGopEnable;
// return EFI_SUCCESS;
//}
//
//OCQUIRKS_PROTOCOL mQuirksConfig = {
// OCQUIRKS_PROTOCOL_REVISION,
// 0, //reserved
// GetQuirksConfig
//};
EFI_STATUS
SetPrivateVarProto(VOID)
@ -385,8 +385,8 @@ SetPrivateVarProto(VOID)
&mGraphConfig,
&gEfiKeyboardInfoProtocolGuid,
&mKeyboardInfo,
&gOcQuirksProtocolGuid,
&mQuirksConfig,
// &gOcQuirksProtocolGuid,
// &mQuirksConfig,
NULL
);
//obligatory protocol

View File

@ -17,7 +17,7 @@ extern UINT32 cPropSize;
extern UINT8 *cProperties;
extern XString8 cDeviceProperties;
extern CHAR8 *BootOSName;
extern OC_ABC_SETTINGS_4CLOVER gQuirks;
//extern OC_ABC_SETTINGS_4CLOVER gQuirks;
EFI_STATUS
SetPrivateVarProto (VOID);

View File

@ -140,7 +140,7 @@ EFI_GUID gUuid;
EMU_VARIABLE_CONTROL_PROTOCOL *gEmuVariableControl = NULL;
extern BOOLEAN NeedPMfix;
OC_ABC_SETTINGS_4CLOVER gQuirks;
//OC_ABC_SETTINGS_4CLOVER gQuirks;
BOOLEAN gProvideConsoleGopEnable;
//extern INTN OldChosenAudio;
@ -2900,61 +2900,65 @@ GetEarlyUserSettings (
}
}
const TagDict* DictPointer = CfgDict->dictPropertyForKey("Quirks");
const TagDict* DictPointer = CfgDict->dictPropertyForKey("OcBooter");
if (DictPointer != NULL) {
const TagStruct* Prop;
Prop = DictPointer->propertyForKey( "AvoidRuntimeDefrag");
gQuirks.OcAbcSettings.AvoidRuntimeDefrag = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.AvoidRuntimeDefrag? QUIRK_DEFRAG:0;
Prop = DictPointer->propertyForKey( "DevirtualiseMmio");
gQuirks.OcAbcSettings.DevirtualiseMmio = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.DevirtualiseMmio? QUIRK_MMIO:0;
Prop = DictPointer->propertyForKey( "DisableSingleUser");
gQuirks.OcAbcSettings.DisableSingleUser = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.DisableSingleUser? QUIRK_SU:0;
Prop = DictPointer->propertyForKey( "DisableVariableWrite");
gQuirks.OcAbcSettings.DisableVariableWrite = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.DisableVariableWrite? QUIRK_VAR:0;
Prop = DictPointer->propertyForKey( "DiscardHibernateMap");
gQuirks.OcAbcSettings.DiscardHibernateMap = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.DiscardHibernateMap? QUIRK_HIBER:0;
Prop = DictPointer->propertyForKey( "EnableSafeModeSlide");
gQuirks.OcAbcSettings.EnableSafeModeSlide = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.EnableSafeModeSlide? QUIRK_SAFE:0;
Prop = DictPointer->propertyForKey( "EnableWriteUnprotector");
gQuirks.OcAbcSettings.EnableWriteUnprotector = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.EnableWriteUnprotector? QUIRK_UNPROT:0;
Prop = DictPointer->propertyForKey( "ForceExitBootServices");
gQuirks.OcAbcSettings.ForceExitBootServices = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.ForceExitBootServices? QUIRK_EXIT:0;
Prop = DictPointer->propertyForKey( "ProtectMemoryRegions");
gQuirks.OcAbcSettings.ProtectMemoryRegions = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.ProtectMemoryRegions? QUIRK_REGION:0;
Prop = DictPointer->propertyForKey( "ProtectSecureBoot");
gQuirks.OcAbcSettings.ProtectSecureBoot = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.ProtectMemoryRegions? QUIRK_SECURE:0;
Prop = DictPointer->propertyForKey( "ProtectUefiServices");
gQuirks.OcAbcSettings.ProtectUefiServices = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.ProtectUefiServices? QUIRK_UEFI:0;
Prop = DictPointer->propertyForKey( "ProvideConsoleGopEnable");
gProvideConsoleGopEnable = IsPropertyNotNullAndTrue(Prop);
Prop = DictPointer->propertyForKey( "ProvideCustomSlide");
gQuirks.OcAbcSettings.ProvideCustomSlide = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.ProvideCustomSlide? QUIRK_CUSTOM:0;
Prop = DictPointer->propertyForKey( "ProvideMaxSlide");
gQuirks.OcAbcSettings.ProvideMaxSlide = GetPropertyAsInteger(Prop, 0);
Prop = DictPointer->propertyForKey( "RebuildAppleMemoryMap");
gQuirks.OcAbcSettings.RebuildAppleMemoryMap = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.RebuildAppleMemoryMap? QUIRK_MAP:0;
Prop = DictPointer->propertyForKey( "SetupVirtualMap");
gQuirks.OcAbcSettings.SetupVirtualMap = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.SetupVirtualMap? QUIRK_VIRT:0;
Prop = DictPointer->propertyForKey( "SignalAppleOS");
gQuirks.OcAbcSettings.SignalAppleOS = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.SignalAppleOS? QUIRK_OS:0;
Prop = DictPointer->propertyForKey( "SyncRuntimePermissions");
gQuirks.OcAbcSettings.SyncRuntimePermissions = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gQuirks.OcAbcSettings.SyncRuntimePermissions? QUIRK_PERM:0;
const TagDict* OcQuirksDict = DictPointer->dictPropertyForKey("Quirks");
if (OcQuirksDict != NULL) {
const TagStruct* Prop;
Prop = OcQuirksDict->propertyForKey( "AvoidRuntimeDefrag");
gSettings.ocBooterQuirks.AvoidRuntimeDefrag = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.AvoidRuntimeDefrag? QUIRK_DEFRAG:0;
Prop = OcQuirksDict->propertyForKey( "DevirtualiseMmio");
gSettings.ocBooterQuirks.DevirtualiseMmio = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.DevirtualiseMmio? QUIRK_MMIO:0;
Prop = OcQuirksDict->propertyForKey( "DisableSingleUser");
gSettings.ocBooterQuirks.DisableSingleUser = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.DisableSingleUser? QUIRK_SU:0;
Prop = OcQuirksDict->propertyForKey( "DisableVariableWrite");
gSettings.ocBooterQuirks.DisableVariableWrite = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.DisableVariableWrite? QUIRK_VAR:0;
Prop = OcQuirksDict->propertyForKey( "DiscardHibernateMap");
gSettings.ocBooterQuirks.DiscardHibernateMap = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.DiscardHibernateMap? QUIRK_HIBER:0;
Prop = OcQuirksDict->propertyForKey( "EnableSafeModeSlide");
gSettings.ocBooterQuirks.EnableSafeModeSlide = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.EnableSafeModeSlide? QUIRK_SAFE:0;
Prop = OcQuirksDict->propertyForKey( "EnableWriteUnprotector");
gSettings.ocBooterQuirks.EnableWriteUnprotector = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.EnableWriteUnprotector? QUIRK_UNPROT:0;
Prop = OcQuirksDict->propertyForKey( "ForceExitBootServices");
gSettings.ocBooterQuirks.ForceExitBootServices = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.ForceExitBootServices? QUIRK_EXIT:0;
Prop = OcQuirksDict->propertyForKey( "ProtectMemoryRegions");
gSettings.ocBooterQuirks.ProtectMemoryRegions = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.ProtectMemoryRegions? QUIRK_REGION:0;
Prop = OcQuirksDict->propertyForKey( "ProtectSecureBoot");
gSettings.ocBooterQuirks.ProtectSecureBoot = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.ProtectMemoryRegions? QUIRK_SECURE:0;
Prop = OcQuirksDict->propertyForKey( "ProtectUefiServices");
gSettings.ocBooterQuirks.ProtectUefiServices = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.ProtectUefiServices? QUIRK_UEFI:0;
Prop = OcQuirksDict->propertyForKey( "ProvideConsoleGopEnable");
gProvideConsoleGopEnable = IsPropertyNotNullAndTrue(Prop);
Prop = OcQuirksDict->propertyForKey( "ProvideCustomSlide");
gSettings.ocBooterQuirks.ProvideCustomSlide = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.ProvideCustomSlide? QUIRK_CUSTOM:0;
Prop = OcQuirksDict->propertyForKey( "ProvideMaxSlide");
gSettings.ocBooterQuirks.ProvideMaxSlide = GetPropertyAsInteger(Prop, 0);
Prop = OcQuirksDict->propertyForKey( "RebuildAppleMemoryMap");
gSettings.ocBooterQuirks.RebuildAppleMemoryMap = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.RebuildAppleMemoryMap? QUIRK_MAP:0;
Prop = OcQuirksDict->propertyForKey( "SetupVirtualMap");
gSettings.ocBooterQuirks.SetupVirtualMap = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.SetupVirtualMap? QUIRK_VIRT:0;
Prop = OcQuirksDict->propertyForKey( "SignalAppleOS");
gSettings.ocBooterQuirks.SignalAppleOS = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.SignalAppleOS? QUIRK_OS:0;
Prop = OcQuirksDict->propertyForKey( "SyncRuntimePermissions");
gSettings.ocBooterQuirks.SyncRuntimePermissions = IsPropertyNotNullAndTrue(Prop);
gSettings.QuirksMask |= gSettings.ocBooterQuirks.SyncRuntimePermissions? QUIRK_PERM:0;
}
gSettings.mmioWhiteListArray.setEmpty();
const TagArray* Dict2 = DictPointer->arrayPropertyForKey("MmioWhitelist"); // array of dict
if (Dict2 != NULL) {
INTN Count = Dict2->arrayContent().size();
@ -2962,29 +2966,26 @@ GetEarlyUserSettings (
//OC_SCHEMA_STRING_IN ("Comment", OC_MMIO_WL_STRUCT, Comment),
//OC_SCHEMA_BOOLEAN_IN ("Enabled", OC_MMIO_WL_STRUCT, Enabled),
if (Count > 0) {
gQuirks.MmioWhitelistLabels = (__typeof__(gQuirks.MmioWhitelistLabels))AllocatePool(sizeof(char*) * Count);
gQuirks.OcAbcSettings.MmioWhitelist = (__typeof__(gQuirks.OcAbcSettings.MmioWhitelist))AllocatePool(sizeof(*gQuirks.OcAbcSettings.MmioWhitelist) * Count);
gQuirks.MmioWhitelistEnabled = (__typeof__(gQuirks.MmioWhitelistEnabled))AllocatePool(sizeof(BOOLEAN) * Count);
gQuirks.OcAbcSettings.MmioWhitelistSize = 0;
for (INTN i = 0; i < Count; i++) {
for (INTN i = 0; i < Count; i++)
{
const TagDict* Dict3 = Dict2->dictElementAt(i, "MmioWhitelist"_XS8);
MMIOWhiteList* mmioWhiteListPtr = new MMIOWhiteList();
MMIOWhiteList& mmioWhiteList = *mmioWhiteListPtr;
gQuirks.MmioWhitelistLabels[gQuirks.OcAbcSettings.MmioWhitelistSize] = (__typeof__(char *))AllocateZeroPool(256);
const TagStruct* Prop2 = Dict3->propertyForKey("Comment");
if (Prop2 != NULL && (Prop2->isString()) && Prop2->getString()->stringValue().notEmpty()) {
snprintf(gQuirks.MmioWhitelistLabels[gQuirks.OcAbcSettings.MmioWhitelistSize], 255, "%s", Prop2->getString()->stringValue().c_str());
if (Prop2 != NULL && Prop2->isString() && Prop2->getString()->stringValue().notEmpty()) {
mmioWhiteList.comment = Prop2->getString()->stringValue();
} else {
snprintf(gQuirks.MmioWhitelistLabels[gQuirks.OcAbcSettings.MmioWhitelistSize], 255, " (NoLabel)");
mmioWhiteList.comment = " (NoLabel)"_XS8;
}
Prop2 = Dict3->propertyForKey("Address");
if (Prop2 != 0) {
gQuirks.OcAbcSettings.MmioWhitelist[gQuirks.OcAbcSettings.MmioWhitelistSize] = GetPropertyAsInteger(Prop2, 0);
mmioWhiteList.address = GetPropertyAsInteger(Prop2, 0);
Prop2 = Dict3->propertyForKey("Enabled");
gQuirks.MmioWhitelistEnabled[gQuirks.OcAbcSettings.MmioWhitelistSize] = IsPropertyNotNullAndTrue(Prop2);
mmioWhiteList.enabled = IsPropertyNotNullAndTrue(Prop2);
}
gQuirks.OcAbcSettings.MmioWhitelistSize++;
gSettings.mmioWhiteListArray.AddReference(mmioWhiteListPtr, true);
}
}
}

View File

@ -222,8 +222,22 @@ public :
DSDT_Patch() : PatchDsdtFind(), PatchDsdtReplace(), PatchDsdtLabel(), PatchDsdtTgt(), PatchDsdtMenuItem() { }
// Not sure if default are valid. Delete them. If needed, proper ones can be created
DSDT_Patch(const DEV_PROPERTY&) = delete;
DSDT_Patch& operator=(const DEV_PROPERTY&) = delete;
DSDT_Patch(const DSDT_Patch&) = delete;
DSDT_Patch& operator=(const DSDT_Patch&) = delete;
};
class MMIOWhiteList
{
public :
UINTN address;
XString8 comment;
bool enabled;
MMIOWhiteList() : address(0), comment(), enabled(false) { }
// Not sure if default are valid. Delete them. If needed, proper ones can be created
MMIOWhiteList(const MMIOWhiteList&) = delete;
MMIOWhiteList& operator=(const MMIOWhiteList&) = delete;
};
class SETTINGS_DATA {
@ -591,6 +605,9 @@ public:
UINT8 pad38[4];
UINTN MaxSlide;
OC_BOOTER_QUIRKS ocBooterQuirks;
XObjArray<MMIOWhiteList> mmioWhiteListArray;
SETTINGS_DATA() : VendorName(), RomVersion(), EfiVersion(), ReleaseDate(), ManufactureName(), ProductName(), VersionNr(), SerialNr(), SmUUID({0,0,0,{0}}),
SmUUIDConfig(0), pad0{0}, FamilyName(), OEMProduct(), OEMVendor(), BoardManufactureName(), BoardSerialNumber(), BoardNumber(), LocationInChassis(),
@ -618,7 +635,7 @@ public:
AFGLowPowerState(0), PNLF_UID(0), ACPIDropTables(0), DisableEntryScan(0), DisableToolScan(0), KernelScan(0), LinuxScan(0), CustomEntries(0),
CustomLegacy(0), CustomTool(0), NrAddProperties(0), AddProperties(0), BlockKexts{0}, SortedACPICount(0), SortedACPI(0), DisabledAMLCount(0), DisabledAML(0),
IntelMaxValue(0), OptionsBits(0), FlagsBits(0), UIScale(0), EFILoginHiDPI(0), flagstate{0},
ArbProperties(0), QuirksMask(0), MaxSlide(0)
ArbProperties(0), QuirksMask(0), MaxSlide(0), ocBooterQuirks{0}, mmioWhiteListArray()
{};
SETTINGS_DATA(const SETTINGS_DATA& other) = delete; // Can be defined if needed
const SETTINGS_DATA& operator = ( const SETTINGS_DATA & ) = delete; // Can be defined if needed

View File

@ -1184,7 +1184,7 @@ VOID LOADER_ENTRY::StartLoader11()
// DBG("SetDevices\n");
SetDevices(this);
// DBG("SetFSInjection\n");
SetFSInjection();
//SetFSInjection();
//PauseForKey(L"SetFSInjection");
// DBG("SetVariablesForOSX\n");
SetVariablesForOSX(this);
@ -1255,6 +1255,8 @@ VOID LOADER_ENTRY::StartLoader11()
// }
//
memset(&mOpenCoreConfiguration, 0, sizeof(mOpenCoreConfiguration));
UINT64 CPUFrequencyFromART;
InternalCalculateARTFrequencyIntel(&CPUFrequencyFromART, NULL, 1);
@ -1273,6 +1275,23 @@ VOID LOADER_ENTRY::StartLoader11()
);
DEBUG ((DEBUG_INFO, "OC: Log initialized...\n"));
OcAppleDebugLogInstallProtocol(0);
mOpenCoreConfiguration.Booter.MmioWhitelist.Count = gSettings.mmioWhiteListArray.size();
mOpenCoreConfiguration.Booter.MmioWhitelist.AllocCount = mOpenCoreConfiguration.Booter.MmioWhitelist.Count;
mOpenCoreConfiguration.Booter.MmioWhitelist.ValueSize = sizeof(__typeof_am__(**mOpenCoreConfiguration.Booter.MmioWhitelist.Values)); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
mOpenCoreConfiguration.Booter.MmioWhitelist.Values = (OC_BOOTER_WL_ENTRY**)AllocatePool(mOpenCoreConfiguration.Booter.MmioWhitelist.AllocCount*sizeof(*mOpenCoreConfiguration.Booter.MmioWhitelist.Values)); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
for ( size_t idx = 0 ; idx < gSettings.mmioWhiteListArray.size() ; idx++ ) {
const MMIOWhiteList& entry = gSettings.mmioWhiteListArray[idx];
DBG("Bridge mmioWhiteList[%zu] to OC : comment=%s\n", idx, entry.comment.c_str());
mOpenCoreConfiguration.Booter.MmioWhitelist.Values[idx] = (__typeof_am__(*mOpenCoreConfiguration.Booter.MmioWhitelist.Values))AllocatePool(mOpenCoreConfiguration.Booter.MmioWhitelist.ValueSize);
mOpenCoreConfiguration.Booter.MmioWhitelist.Values[idx]->Address = entry.address;
OC_STRING_ASSIGN(mOpenCoreConfiguration.Booter.MmioWhitelist.Values[idx]->Comment, entry.comment.c_str());
mOpenCoreConfiguration.Booter.MmioWhitelist.Values[idx]->Enabled = entry.enabled;
}
memcpy(&mOpenCoreConfiguration.Booter.Quirks, &gSettings.ocBooterQuirks, sizeof(mOpenCoreConfiguration.Booter.Quirks));
OcLoadBooterUefiSupport(&mOpenCoreConfiguration);
OcLoadKernelSupport(&mOpenCoreStorage, &mOpenCoreConfiguration, &mOpenCoreCpuInfo);
OcImageLoaderInit ();
@ -1282,7 +1301,8 @@ VOID LOADER_ENTRY::StartLoader11()
AddKextsInArray(LStringW(L"Kexts\\11"), LStringW(L"11"), CPU_TYPE_X86_64, &kextArray);
}
memset(&mOpenCoreConfiguration, 0, sizeof(mOpenCoreConfiguration));
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Scheme.KernelCache, "Auto");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Misc.Security.SecureBootModel, "Default");
mOpenCoreConfiguration.Kernel.Scheme.FuzzyMatch = gSettings.KernelAndKextPatches.FuzzyMatch;