2019-09-03 11:58:42 +02:00
/*
Slice 2012
*/
2020-10-12 16:49:43 +02:00
# include <Platform.h>
2021-02-06 18:16:46 +01:00
# include "Settings.h"
# include "FixBiosDsdt.h"
# include "../include/VolumeTypes.h"
# include "../include/OSFlags.h"
# include "../include/OSTypes.h"
# include "../include/BootTypes.h"
2021-03-28 22:13:43 +02:00
# include "../include/QuirksCodes.h"
2020-04-11 08:21:06 +02:00
# include "../entry_scan/loader.h"
2021-02-06 18:16:46 +01:00
# include "../Platform/BootLog.h"
# include "../entry_scan/secureboot.h"
# include "../libeg/XTheme.h"
# include "cpu.h"
# include "VersionString.h"
2020-04-16 09:15:26 +02:00
# include "card_vlist.h"
# include "Injectors.h"
2020-04-16 11:09:22 +02:00
# include "../include/Pci.h"
# include "../include/Devices.h"
2021-02-06 18:16:46 +01:00
# include "smbios.h"
2020-10-03 19:02:31 +02:00
# include "Net.h"
2021-02-06 18:16:46 +01:00
# include "Nvram.h"
# include "BootOptions.h"
2021-04-28 20:30:34 +02:00
# include "../Settings/SelfOem.h"
2021-02-06 18:16:46 +01:00
# include "ati_reg.h"
# include "ati.h"
# include "nvidia.h"
# include "gma.h"
# include "Edid.h"
# include "hda.h"
2021-03-15 10:02:34 +01:00
# include "../entry_scan/bootscreen.h"
2021-04-28 20:30:34 +02:00
# include "../Settings/ConfigPlist/ConfigPlistClass.h"
# include "../Settings/ConfigManager.h"
2020-07-15 19:29:27 +02:00
2019-09-03 11:58:42 +02:00
# ifndef DEBUG_ALL
# define DEBUG_SET 1
# else
# define DEBUG_SET DEBUG_ALL
# endif
# if DEBUG_SET == 0
# define DBG(...)
# else
# define DBG(...) DebugLog (DEBUG_SET, __VA_ARGS__)
# endif
//#define DUMP_KERNEL_KEXT_PATCHES 1
2020-04-16 11:09:22 +02:00
# define GEN_PMCON_1 0xA0
2020-04-04 14:27:02 +02:00
INTN OldChosenTheme ;
INTN OldChosenConfig ;
INTN OldChosenDsdt ;
UINTN OldChosenAudio ;
2021-09-28 15:54:31 +02:00
XBool SavePreBootLog ;
2020-04-04 14:27:02 +02:00
UINT8 DefaultAudioVolume ;
INTN LayoutBannerOffset = 64 ;
INTN LayoutTextOffset = 0 ;
INTN LayoutButtonOffset = 0 ;
2019-09-03 11:58:42 +02:00
2021-03-23 20:59:30 +01:00
XObjArray < ACPI_PATCHED_AML > ACPIPatchedAML ;
2023-06-11 21:08:12 +02:00
2019-09-03 11:58:42 +02:00
CHAR16 * IconFormat = NULL ;
SETTINGS_DATA gSettings ;
2021-04-28 20:30:34 +02:00
2019-09-03 11:58:42 +02:00
EFI_EDID_DISCOVERED_PROTOCOL * EdidDiscovered ;
2020-08-31 09:22:11 +02:00
XStringWArray ThemeNameArray ;
2021-09-27 09:05:11 +02:00
XStringWArray ConfigsList ;
2021-09-27 09:18:52 +02:00
XStringWArray DsdtsList ;
2020-08-31 09:07:36 +02:00
XObjArray < HDA_OUTPUTS > AudioList ;
2019-09-03 11:58:42 +02:00
// firmware
2021-09-28 15:54:31 +02:00
XBool gFirmwareClover = false ;
2019-09-03 11:58:42 +02:00
UINTN gEvent ;
UINT16 gBacklightLevel ;
2021-09-28 15:54:31 +02:00
XBool ResumeFromCoreStorage = false ;
2019-09-03 11:58:42 +02:00
2020-04-01 14:57:32 +02:00
//EG_PIXEL SelectionBackgroundPixel = { 0xef, 0xef, 0xef, 0xff }; //define in lib.h
2020-03-29 18:17:27 +02:00
const INTN BCSMargin = 11 ;
2019-09-03 11:58:42 +02:00
2020-04-16 09:15:26 +02:00
//
DRIVERS_FLAGS gDriversFlags ; //the initializer is not needed for global variables
EMU_VARIABLE_CONTROL_PROTOCOL * gEmuVariableControl = NULL ;
2019-09-03 11:58:42 +02:00
// global configuration with default values
2020-08-09 17:55:30 +02:00
REFIT_CONFIG GlobalConfig ;
2019-09-03 11:58:42 +02:00
2021-02-06 18:16:46 +01:00
CONST CHAR8 * AudioOutputNames [ ] = {
" LineOut " ,
" Speaker " ,
" Headphones " ,
" SPDIF " ,
" Garniture " ,
" HDMI " ,
" Other "
} ;
2021-03-23 09:32:57 +01:00
const XString8 defaultInstallTitle = " Install macOS " _XS8 ;
const XString8 defaultRecoveryTitle = " Recovery " _XS8 ;
const XStringW defaultRecoveryImagePath = L " mac " _XSW ;
const XStringW defaultRecoveryDriveImagePath = L " mac " _XSW ;
2021-04-28 20:30:34 +02:00
const SETTINGS_DATA : : SmbiosClass : : SlotDeviceClass SETTINGS_DATA : : SmbiosClass : : SlotDeviceClass : : NullSlotDevice ;
2021-03-22 13:40:01 +01:00
2021-03-23 09:32:57 +01:00
CUSTOM_LOADER_ENTRY : : CUSTOM_LOADER_ENTRY ( const CUSTOM_LOADER_ENTRY_SETTINGS & _settings ) : settings ( _settings )
{
if ( settings . ImageData . notEmpty ( ) ) {
if ( ! EFI_ERROR ( Image . Image . FromPNG ( settings . ImageData . data ( ) , settings . ImageData . size ( ) ) ) ) {
Image . setFilled ( ) ;
}
}
if ( settings . DriveImageData . notEmpty ( ) ) {
if ( ! EFI_ERROR ( DriveImage . Image . FromPNG ( settings . DriveImageData . data ( ) , settings . DriveImageData . size ( ) ) ) ) {
DriveImage . setFilled ( ) ;
}
}
if ( settings . CustomLogoTypeSettings = = CUSTOM_BOOT_USER & & settings . CustomLogoAsXString8 . notEmpty ( ) ) {
CustomLogoImage . LoadXImage ( & self . getSelfVolumeRootDir ( ) , settings . CustomLogoAsXString8 ) ;
if ( CustomLogoImage . isEmpty ( ) ) {
DBG ( " Custom boot logo not found at path '%s'! \n " , settings . CustomLogoAsXString8 . c_str ( ) ) ;
CustomLogoType = CUSTOM_BOOT_DISABLED ;
}
} else if ( settings . CustomLogoTypeSettings = = CUSTOM_BOOT_USER & & settings . CustomLogoAsData . notEmpty ( ) ) {
CustomLogoImage . FromPNG ( settings . CustomLogoAsData . data ( ) , settings . CustomLogoAsData . size ( ) ) ;
if ( CustomLogoImage . isEmpty ( ) ) {
DBG ( " Custom boot logo not decoded from data! \n " ) ;
CustomLogoType = CUSTOM_BOOT_DISABLED ;
}
}
DBG ( " Sub entry custom boot %s (0x%llX) \n " , CustomBootModeToStr ( settings . CustomLogoTypeSettings ) , ( uintptr_t ) & CustomLogoImage ) ;
for ( size_t idx = 0 ; idx < settings . SubEntriesSettings . size ( ) ; + + idx ) {
const CUSTOM_LOADER_SUBENTRY_SETTINGS & CustomEntrySettings = settings . SubEntriesSettings [ idx ] ;
CUSTOM_LOADER_SUBENTRY * entry = new CUSTOM_LOADER_SUBENTRY ( * this , CustomEntrySettings ) ;
SubEntries . AddReference ( entry , true ) ;
}
KernelAndKextPatches = gSettings . KernelAndKextPatches ; // Jief : why do we have a duplicated KernelAndKextPatches var inside CUSTOM_LOADER_ENTRY ?
}
2021-03-22 13:40:01 +01:00
XString8Array CUSTOM_LOADER_SUBENTRY : : getLoadOptions ( ) const
{
2021-03-27 19:53:30 +01:00
if ( settings . _Arguments . isDefined ( ) ) return Split < XString8Array > ( settings . _Arguments . value ( ) , " " ) ;
2021-03-22 13:40:01 +01:00
XString8Array LoadOptions = parent . getLoadOptions ( ) ;
2021-03-27 19:53:30 +01:00
LoadOptions . import ( Split < XString8Array > ( settings . _AddArguments , " " ) ) ;
2021-03-22 13:40:01 +01:00
if ( LoadOptions . isEmpty ( ) & & OSTYPE_IS_WINDOWS ( parent . settings . Type ) ) {
LoadOptions . Add ( " -s " ) ;
LoadOptions . Add ( " -h " ) ;
}
return LoadOptions ;
}
2021-09-28 15:54:31 +02:00
UINT8 CUSTOM_LOADER_SUBENTRY : : getFlags ( XBool NoCachesDefault ) const
2021-03-22 13:40:01 +01:00
{
UINT8 Flags = parent . getFlags ( NoCachesDefault ) ;
2021-03-27 19:53:30 +01:00
if ( settings . _Arguments . isDefined ( ) ) Flags = OSFLAG_SET ( Flags , OSFLAG_NODEFAULTARGS ) ;
if ( settings . _NoCaches . isDefined ( ) ) {
2021-04-06 23:45:58 +02:00
if ( settings . _NoCaches . value ( ) ) {
Flags = OSFLAG_SET ( Flags , OSFLAG_NOCACHES ) ;
} else {
if ( NoCachesDefault ) {
Flags = OSFLAG_SET ( Flags , OSFLAG_NOCACHES ) ;
}
}
2021-03-23 09:32:57 +01:00
}
2021-03-22 13:40:01 +01:00
return Flags ;
}
XString8Array CUSTOM_LOADER_ENTRY : : getLoadOptions ( ) const
{
if ( settings . Arguments . isDefined ( ) ) return Split < XString8Array > ( settings . Arguments . value ( ) , " " ) ;
XString8Array LoadOptions ;
LoadOptions . import ( Split < XString8Array > ( settings . AddArguments , " " ) ) ;
if ( LoadOptions . isEmpty ( ) & & OSTYPE_IS_WINDOWS ( settings . Type ) ) {
LoadOptions . Add ( " -s " ) ;
LoadOptions . Add ( " -h " ) ;
}
return LoadOptions ;
}
const XString8 & CUSTOM_LOADER_SUBENTRY : : getTitle ( ) const {
2021-03-27 19:53:30 +01:00
if ( settings . _Title . isDefined ( ) ) return settings . _Title . value ( ) ;
if ( settings . _FullTitle . isDefined ( ) ) return NullXString8 ;
2021-03-23 09:32:57 +01:00
return parent . settings . dgetTitle ( ) ;
2021-03-22 13:40:01 +01:00
} ;
const XString8 & CUSTOM_LOADER_SUBENTRY : : getFullTitle ( ) const {
2021-03-27 19:53:30 +01:00
if ( settings . _FullTitle . isDefined ( ) ) return settings . _FullTitle . value ( ) ;
if ( settings . _Title . isDefined ( ) ) return NullXString8 ;
2021-03-22 13:40:01 +01:00
return parent . settings . FullTitle ;
} ;
2021-09-28 15:54:31 +02:00
XBool SETTINGS_DATA : : GUIClass : : getDarkEmbedded ( XBool isDaylight ) const {
2021-04-11 07:18:52 +02:00
if ( EmbeddedThemeType . isEqualIC ( " Dark " ) ) return true ;
if ( EmbeddedThemeType . isEqualIC ( " Daytime " ) ) return ! isDaylight ;
2021-03-23 20:59:30 +01:00
return false ;
}
2021-03-22 13:40:01 +01:00
2019-09-03 11:58:42 +02:00
//
// check if this entry corresponds to Boot# variable and then set BootCurrent
//
2020-10-03 19:02:31 +02:00
void
2020-03-10 10:45:17 +01:00
SetBootCurrent ( REFIT_MENU_ITEM_BOOTNUM * Entry )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status ;
BO_BOOT_OPTION BootOption ;
2020-08-09 17:55:30 +02:00
XStringW VarName ;
2019-09-03 11:58:42 +02:00
UINTN VarSize = 0 ;
UINT8 * BootVariable ;
UINTN NameSize ;
UINT8 * Data ;
UINT16 * BootOrder ;
UINT16 * BootOrderNew ;
UINT16 * Ptr ;
UINTN BootOrderSize ;
INTN BootIndex = 0 , Index ;
2020-08-09 17:55:30 +02:00
VarName = SWPrintf ( " Boot%04llX " , Entry - > BootNum ) ;
2022-04-26 00:55:56 +02:00
BootVariable = ( UINT8 * ) GetNvramVariable ( VarName . wc_str ( ) , gEfiGlobalVariableGuid , NULL , & VarSize ) ;
2019-09-03 11:58:42 +02:00
if ( ( BootVariable = = NULL ) | | ( VarSize = = 0 ) ) {
2020-08-09 17:55:30 +02:00
DBG ( " Boot option %ls not found \n " , VarName . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
return ;
}
//decode the variable
BootOption . Variable = BootVariable ;
2020-04-28 14:19:28 +02:00
BootOption . VariableSize = VarSize ;
2019-09-03 11:58:42 +02:00
ParseBootOption ( & BootOption ) ;
if ( ( BootOption . OptionalDataSize = = 0 ) | |
( BootOption . OptionalData = = NULL ) | |
( * ( UINT32 * ) BootOption . OptionalData ! = CLOVER_SIGN ) ) {
DBG ( " BootVariable of the entry is empty \n " ) ;
FreePool ( BootVariable ) ;
return ;
}
Data = BootOption . OptionalData + 4 ;
NameSize = * ( UINT16 * ) Data ;
Data + = 2 ;
2020-08-09 17:55:30 +02:00
if ( StriCmp ( ( CHAR16 * ) Data , Entry - > Volume - > VolName . wc_str ( ) ) ! = 0 ) {
2021-02-06 18:16:46 +01:00
DBG ( " Boot option %llu has other volume name %ls \n " , Entry - > BootNum , ( CHAR16 * ) Data ) ;
2019-09-03 11:58:42 +02:00
FreePool ( BootVariable ) ;
return ;
}
if ( VarSize > NameSize + 6 ) {
Data + = NameSize ;
2020-04-27 11:50:49 +02:00
if ( StriCmp ( ( CHAR16 * ) Data , Basename ( Entry - > LoaderPath . wc_str ( ) ) ) ! = 0 ) {
2020-10-18 05:04:08 +02:00
DBG ( " Boot option %llu has other loader name %ls \n " , Entry - > BootNum , ( CHAR16 * ) Data ) ;
2019-09-03 11:58:42 +02:00
FreePool ( BootVariable ) ;
return ;
}
}
FreePool ( BootVariable ) ;
//all check passed, save the number
Status = SetNvramVariable ( L " BootCurrent " ,
2022-04-26 00:55:56 +02:00
gEfiGlobalVariableGuid ,
2019-09-03 11:58:42 +02:00
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS ,
sizeof ( UINT16 ) ,
& Entry - > BootNum ) ;
if ( EFI_ERROR ( Status ) ) {
2020-08-25 17:35:19 +02:00
DBG ( " Can't save BootCurrent, status=%s \n " , efiStrError ( Status ) ) ;
2019-09-03 11:58:42 +02:00
}
//Next step is rotate BootOrder to set BootNum to first place
2022-04-26 00:55:56 +02:00
BootOrder = ( __typeof__ ( BootOrder ) ) GetNvramVariable ( L " BootOrder " , gEfiGlobalVariableGuid , NULL , & BootOrderSize ) ;
2019-09-03 11:58:42 +02:00
if ( BootOrder = = NULL ) {
return ;
}
VarSize = ( INTN ) BootOrderSize / sizeof ( UINT16 ) ; //reuse variable
for ( Index = 0 ; Index < ( INTN ) VarSize ; Index + + ) {
if ( BootOrder [ Index ] = = Entry - > BootNum ) {
BootIndex = Index ;
break ;
}
}
if ( BootIndex ! = 0 ) {
2019-12-21 01:31:49 +01:00
BootOrderNew = ( __typeof__ ( BootOrderNew ) ) AllocatePool ( BootOrderSize ) ;
2019-09-03 11:58:42 +02:00
Ptr = BootOrderNew ;
for ( Index = 0 ; Index < ( INTN ) VarSize - BootIndex ; Index + + ) {
* Ptr + + = BootOrder [ Index + BootIndex ] ;
}
for ( Index = 0 ; Index < BootIndex ; Index + + ) {
* Ptr + + = BootOrder [ Index ] ;
}
Status = gRT - > SetVariable ( L " BootOrder " ,
2022-04-26 00:55:56 +02:00
gEfiGlobalVariableGuid ,
2019-09-03 11:58:42 +02:00
EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS ,
2021-04-28 20:30:34 +02:00
BootOrderSize ,
BootOrderNew
) ;
if ( EFI_ERROR ( Status ) ) {
DBG ( " Can't save BootOrder, status=%s \n " , efiStrError ( Status ) ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
DBG ( " Set new BootOrder \n " ) ;
PrintBootOrder ( BootOrderNew , VarSize ) ;
FreePool ( BootOrderNew ) ;
}
FreePool ( BootOrder ) ;
2019-09-03 11:58:42 +02:00
2021-04-28 20:30:34 +02:00
}
2020-08-07 10:23:46 +02:00
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
void afterGetUserSettings ( SETTINGS_DATA & settingsData )
2021-04-28 20:30:34 +02:00
{
2020-08-07 10:23:46 +02:00
2021-04-28 20:30:34 +02:00
// Secure boot
/* this parameter, which should be called SecureBootSetupMode, is ignored if :
* it is true
* SecureBoot is already true .
*/
2021-05-08 11:34:17 +02:00
if ( settingsData . Boot . SecureSetting = = 0 ) {
2021-04-28 20:30:34 +02:00
// Only disable setup mode, we want always secure boot
GlobalConfig . SecureBootSetupMode = 0 ;
2021-05-08 11:34:17 +02:00
} else if ( settingsData . Boot . SecureSetting = = 1 & & ! GlobalConfig . SecureBoot ) {
2021-04-28 20:30:34 +02:00
// This mode will force boot policy even when no secure boot or it is disabled
GlobalConfig . SecureBootSetupMode = 1 ;
GlobalConfig . SecureBoot = 1 ;
}
2020-08-07 10:23:46 +02:00
2019-09-03 11:58:42 +02:00
2021-04-28 20:30:34 +02:00
//set to drop
2021-05-08 11:34:17 +02:00
GlobalConfig . DropSSDT = settingsData . ACPI . SSDT . DropSSDTSetting ;
2021-04-28 20:30:34 +02:00
if ( GlobalConfig . ACPIDropTables ) {
2021-05-08 11:34:17 +02:00
for ( size_t idx = 0 ; idx < settingsData . ACPI . ACPIDropTablesArray . size ( ) ; + + idx )
2021-04-28 20:30:34 +02:00
{
ACPI_DROP_TABLE * DropTable = GlobalConfig . ACPIDropTables ;
2021-09-25 12:17:25 +02:00
DBG ( " - [%02zd]: Drop table : %.4s, %16llx : " , idx , ( const char * ) & settingsData . ACPI . ACPIDropTablesArray [ idx ] . Signature , settingsData . ACPI . ACPIDropTablesArray [ idx ] . TableId ) ;
2021-09-28 15:54:31 +02:00
XBool Dropped = false ;
2021-04-28 20:30:34 +02:00
while ( DropTable ) {
2021-05-08 11:34:17 +02:00
if ( ( ( settingsData . ACPI . ACPIDropTablesArray [ idx ] . Signature = = DropTable - > Signature ) & &
( ! settingsData . ACPI . ACPIDropTablesArray [ idx ] . TableId | | ( DropTable - > TableId = = settingsData . ACPI . ACPIDropTablesArray [ idx ] . TableId ) ) & &
( ! settingsData . ACPI . ACPIDropTablesArray [ idx ] . TabLength | | ( DropTable - > Length = = settingsData . ACPI . ACPIDropTablesArray [ idx ] . TabLength ) ) ) | |
( ! settingsData . ACPI . ACPIDropTablesArray [ idx ] . Signature & & ( DropTable - > TableId = = settingsData . ACPI . ACPIDropTablesArray [ idx ] . TableId ) ) ) {
2021-09-28 10:28:45 +02:00
DropTable - > MenuItem . BValue = true ;
2021-05-08 11:34:17 +02:00
DropTable - > OtherOS = settingsData . ACPI . ACPIDropTablesArray [ idx ] . OtherOS ;
2021-09-28 10:28:45 +02:00
GlobalConfig . DropSSDT = false ; // if one item=true then dropAll=false by default
2021-04-28 20:30:34 +02:00
//DBG(" true");
2021-09-28 10:28:45 +02:00
Dropped = true ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
DropTable = DropTable - > Next ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
DBG ( " %s \n " , Dropped ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
}
}
2021-04-28 20:30:34 +02:00
// Whether or not to draw boot screen
2021-05-08 11:34:17 +02:00
GlobalConfig . CustomLogoType = settingsData . Boot . CustomLogoType ;
if ( settingsData . Boot . CustomLogoType = = CUSTOM_BOOT_USER & & settingsData . Boot . CustomLogoAsXString8 . notEmpty ( ) ) {
2021-04-28 20:30:34 +02:00
if ( GlobalConfig . CustomLogo ! = NULL ) {
delete GlobalConfig . CustomLogo ;
}
GlobalConfig . CustomLogo = new XImage ;
2021-05-08 11:34:17 +02:00
GlobalConfig . CustomLogo - > LoadXImage ( & self . getSelfVolumeRootDir ( ) , settingsData . Boot . CustomLogoAsXString8 ) ;
2021-04-28 20:30:34 +02:00
if ( GlobalConfig . CustomLogo - > isEmpty ( ) ) {
2021-05-08 11:34:17 +02:00
DBG ( " Custom boot logo not found at path '%s'! \n " , settingsData . Boot . CustomLogoAsXString8 . c_str ( ) ) ;
2021-04-28 20:30:34 +02:00
GlobalConfig . CustomLogoType = CUSTOM_BOOT_DISABLED ;
}
2021-05-08 11:34:17 +02:00
} else if ( settingsData . Boot . CustomLogoType = = CUSTOM_BOOT_USER & & settingsData . Boot . CustomLogoAsData . notEmpty ( ) ) {
2021-04-28 20:30:34 +02:00
if ( GlobalConfig . CustomLogo ! = NULL ) {
delete GlobalConfig . CustomLogo ;
}
GlobalConfig . CustomLogo = new XImage ;
2021-05-08 11:34:17 +02:00
GlobalConfig . CustomLogo - > FromPNG ( settingsData . Boot . CustomLogoAsData . data ( ) , settingsData . Boot . CustomLogoAsData . size ( ) ) ;
2021-04-28 20:30:34 +02:00
if ( GlobalConfig . CustomLogo - > isEmpty ( ) ) {
DBG ( " Custom boot logo not decoded from data! \n " /*, Prop->getString()->stringValue().c_str()*/ ) ;
GlobalConfig . CustomLogoType = CUSTOM_BOOT_DISABLED ;
2020-11-12 22:25:56 +01:00
}
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
DBG ( " Custom boot %s (0x%llX) \n " , CustomBootModeToStr ( GlobalConfig . CustomLogoType ) , ( uintptr_t ) GlobalConfig . CustomLogo ) ;
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
GlobalConfig . EnableC6 = settingsData . getEnableC6 ( ) ;
GlobalConfig . EnableC4 = settingsData . getEnableC4 ( ) ;
GlobalConfig . EnableC2 = settingsData . getEnableC2 ( ) ;
2021-06-23 20:24:46 +02:00
// GlobalConfig.C3Latency = settingsData.getC3Latency();
// DBG("4: GlobalConfig.C3Latency=%x\n", GlobalConfig.C3Latency);
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
if ( settingsData . CPU . HWPEnable & & ( gCPUStructure . Model > = CPU_MODEL_SKYLAKE_U ) ) {
2021-09-28 10:28:45 +02:00
GlobalConfig . HWP = true ;
2021-04-28 20:30:34 +02:00
AsmWriteMsr64 ( MSR_IA32_PM_ENABLE , 1 ) ;
2021-05-08 11:34:17 +02:00
if ( settingsData . CPU . HWPValue . isDefined ( ) ) {
AsmWriteMsr64 ( MSR_IA32_HWP_REQUEST , settingsData . CPU . HWPValue . value ( ) ) ;
2021-04-28 20:30:34 +02:00
}
2019-09-03 11:58:42 +02:00
}
2021-05-08 11:34:17 +02:00
for ( size_t idx = 0 ; idx < settingsData . GUI . CustomEntriesSettings . size ( ) ; + + idx ) {
const CUSTOM_LOADER_ENTRY_SETTINGS & CustomEntrySettings = settingsData . GUI . CustomEntriesSettings [ idx ] ;
2021-04-28 20:30:34 +02:00
CUSTOM_LOADER_ENTRY * entry = new CUSTOM_LOADER_ENTRY ( CustomEntrySettings ) ;
GlobalConfig . CustomEntries . AddReference ( entry , true ) ;
2019-09-03 11:58:42 +02:00
}
2021-05-08 11:34:17 +02:00
for ( size_t idx = 0 ; idx < settingsData . GUI . CustomLegacySettings . size ( ) ; + + idx ) {
const CUSTOM_LEGACY_ENTRY_SETTINGS & CustomLegacySettings = settingsData . GUI . CustomLegacySettings [ idx ] ;
2021-04-28 20:30:34 +02:00
CUSTOM_LEGACY_ENTRY * entry = new CUSTOM_LEGACY_ENTRY ( CustomLegacySettings , ThemeX . getThemeDir ( ) ) ;
GlobalConfig . CustomLegacyEntries . AddReference ( entry , true ) ;
2019-09-03 11:58:42 +02:00
}
2021-05-08 11:34:17 +02:00
for ( size_t idx = 0 ; idx < settingsData . GUI . CustomToolSettings . size ( ) ; + + idx ) {
const CUSTOM_TOOL_ENTRY_SETTINGS & CustomToolSettings = settingsData . GUI . CustomToolSettings [ idx ] ;
2021-04-28 20:30:34 +02:00
CUSTOM_TOOL_ENTRY * entry = new CUSTOM_TOOL_ENTRY ( CustomToolSettings , ThemeX . getThemeDir ( ) ) ;
GlobalConfig . CustomToolsEntries . AddReference ( entry , true ) ;
2019-09-03 11:58:42 +02:00
}
2021-05-08 11:34:17 +02:00
if ( settingsData . GUI . Theme . notEmpty ( ) )
2021-04-28 20:30:34 +02:00
{
2021-05-08 11:34:17 +02:00
ThemeX . Theme . takeValueFrom ( settingsData . GUI . Theme ) ;
DBG ( " Default theme: %ls \n " , settingsData . GUI . Theme . wc_str ( ) ) ;
2021-04-28 20:30:34 +02:00
OldChosenTheme = 0xFFFF ; //default for embedded
for ( UINTN i = 0 ; i < ThemeNameArray . size ( ) ; i + + ) {
//now comparison is case sensitive
2021-05-08 11:34:17 +02:00
if ( settingsData . GUI . Theme . isEqualIC ( ThemeNameArray [ i ] ) ) {
2021-04-28 20:30:34 +02:00
OldChosenTheme = i ;
break ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
2021-04-28 20:30:34 +02:00
EFI_TIME Now ;
gRT - > GetTime ( & Now , NULL ) ;
2021-05-08 11:34:17 +02:00
if ( settingsData . GUI . Timezone ! = 0xFF ) {
INT32 NowHour = Now . Hour + settingsData . GUI . Timezone ;
2021-04-28 20:30:34 +02:00
if ( NowHour < 0 ) NowHour + = 24 ;
if ( NowHour > = 24 ) NowHour - = 24 ;
ThemeX . Daylight = ( NowHour > 8 ) & & ( NowHour < 20 ) ;
} else {
2021-09-28 10:28:45 +02:00
ThemeX . Daylight = true ;
2019-09-03 11:58:42 +02:00
}
2021-05-08 11:34:17 +02:00
ThemeX . DarkEmbedded = settingsData . GUI . getDarkEmbedded ( ThemeX . Daylight ) ;
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
if ( settingsData . GUI . languageCode = = english ) {
2021-04-28 20:30:34 +02:00
GlobalConfig . Codepage = 0xC0 ;
GlobalConfig . CodepageSize = 0 ;
2021-05-08 11:34:17 +02:00
} else if ( settingsData . GUI . languageCode = = russian ) {
2021-04-28 20:30:34 +02:00
GlobalConfig . Codepage = 0x410 ;
GlobalConfig . CodepageSize = 0x40 ;
2021-05-08 11:34:17 +02:00
} else if ( settingsData . GUI . languageCode = = ukrainian ) {
2021-04-28 20:30:34 +02:00
GlobalConfig . Codepage = 0x400 ;
GlobalConfig . CodepageSize = 0x60 ;
2021-05-08 11:34:17 +02:00
} else if ( settingsData . GUI . languageCode = = chinese ) {
2021-04-28 20:30:34 +02:00
GlobalConfig . Codepage = 0x3400 ;
GlobalConfig . CodepageSize = 0x19C0 ;
2021-05-08 11:34:17 +02:00
} else if ( settingsData . GUI . languageCode = = korean ) {
2021-04-28 20:30:34 +02:00
GlobalConfig . Codepage = 0x1100 ;
GlobalConfig . CodepageSize = 0x100 ;
}
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
if ( settingsData . Graphics . EDID . InjectEDID ) {
2021-04-28 20:30:34 +02:00
//DBG("Inject EDID\n");
2021-05-08 11:34:17 +02:00
if ( settingsData . Graphics . EDID . CustomEDID . size ( ) > 0 & & settingsData . Graphics . EDID . CustomEDID . size ( ) % 128 = = 0 ) {
2021-04-28 20:30:34 +02:00
InitializeEdidOverride ( ) ;
}
}
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
GlobalConfig . KPKernelPm = settingsData . KernelAndKextPatches . _KPKernelPm | | GlobalConfig . NeedPMfix ;
GlobalConfig . KPAppleIntelCPUPM = settingsData . KernelAndKextPatches . _KPAppleIntelCPUPM | | GlobalConfig . NeedPMfix ;
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
if ( settingsData . RtVariables . RtROMAsString . isEqualIC ( " UseMacAddr0 " ) ) {
2021-04-28 20:30:34 +02:00
if ( gConf . LanCardArray . size ( ) > 0 ) GlobalConfig . RtROM . ncpy ( & gConf . LanCardArray [ 0 ] . MacAddress [ 0 ] , 6 ) ;
else GlobalConfig . RtROM . memset ( 0 , 6 ) ;
2021-05-08 11:34:17 +02:00
} else if ( settingsData . RtVariables . RtROMAsString . isEqualIC ( " UseMacAddr1 " ) ) {
2021-04-28 20:30:34 +02:00
if ( gConf . LanCardArray . size ( ) > 1 ) GlobalConfig . RtROM . ncpy ( & gConf . LanCardArray [ 1 ] . MacAddress [ 0 ] , 6 ) ;
else GlobalConfig . RtROM . memset ( 0 , 6 ) ;
} else {
2021-05-08 11:34:17 +02:00
GlobalConfig . RtROM = settingsData . RtVariables . RtROMAsData ;
2021-04-28 20:30:34 +02:00
}
if ( GlobalConfig . RtROM . isEmpty ( ) ) {
2022-04-26 00:55:56 +02:00
GlobalConfig . RtROM . ncpy ( & settingsData . Smbios . SmUUID . Data4 [ 2 ] , 6 ) ;
2021-04-28 20:30:34 +02:00
}
2021-05-08 11:34:17 +02:00
GlobalConfig . RtMLB = settingsData . RtVariables . RtMLBSetting ;
2021-04-28 20:30:34 +02:00
if ( GlobalConfig . RtMLB . isEmpty ( ) ) {
2021-05-08 11:34:17 +02:00
GlobalConfig . RtMLB = settingsData . Smbios . BoardSerialNumber ;
2021-04-28 20:30:34 +02:00
}
2019-09-03 11:58:42 +02:00
2021-04-28 20:30:34 +02:00
for ( size_t idx = 0 ; idx < gConf . GfxPropertiesArrayNonConst . size ( ) ; idx + + ) {
2021-05-08 11:34:17 +02:00
gConf . GfxPropertiesArrayNonConst [ idx ] . LoadVBios = settingsData . Graphics . LoadVBios ; //default
2021-04-28 20:30:34 +02:00
}
2019-09-03 11:58:42 +02:00
2021-05-08 11:34:17 +02:00
if ( settingsData . CPU . TurboDisabled ) {
2021-04-28 20:30:34 +02:00
GlobalConfig . Turbo = false ;
} else {
GlobalConfig . Turbo = gCPUStructure . Turbo ;
}
2019-09-03 11:58:42 +02:00
2021-04-28 20:30:34 +02:00
// Jief : Shouldn't this injection made at StartLoader only ? And only for macOS ?
2021-05-08 11:34:17 +02:00
if ( settingsData . Devices . Properties . propertiesAsString . notEmpty ( ) )
2021-04-28 20:30:34 +02:00
{
2021-05-08 11:34:17 +02:00
size_t binaryPropSize = hex2bin ( settingsData . Devices . Properties . propertiesAsString , NULL , 0 ) ; // check of correct length is supposed to have been done when reading settings.
2021-04-28 20:30:34 +02:00
UINTN nbPages = EFI_SIZE_TO_PAGES ( binaryPropSize ) ;
EFI_PHYSICAL_ADDRESS BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS ; //0xFE000000;
EFI_STATUS Status = gBS - > AllocatePages (
AllocateMaxAddress ,
EfiACPIReclaimMemory ,
nbPages ,
& BufferPtr
) ;
if ( ! EFI_ERROR ( Status ) ) {
cProperties = ( UINT8 * ) ( UINTN ) BufferPtr ;
2021-05-08 11:34:17 +02:00
cPropSize = ( UINT32 ) hex2bin ( settingsData . Devices . Properties . propertiesAsString , cProperties , EFI_PAGES_TO_SIZE ( nbPages ) ) ; // cast should be safe hex2bin return < MAX_UINT32
2021-04-28 20:30:34 +02:00
DBG ( " Injected EFIString of length %d \n " , cPropSize ) ;
} else {
MsgLog ( " AllocatePages failed (%s), Properties not injected " , efiStrError ( Status ) ) ;
}
}
//---------
2021-05-08 11:34:17 +02:00
GlobalConfig . IgPlatform = settingsData . Graphics . _IgPlatform ;
for ( size_t idx = 0 ; idx < settingsData . Devices . ArbitraryArray . size ( ) ; + + idx ) {
const SETTINGS_DATA : : DevicesClass : : ArbitraryPropertyClass & arbitraryProperty = settingsData . Devices . ArbitraryArray [ idx ] ;
2021-04-28 20:30:34 +02:00
for ( size_t jdx = 0 ; jdx < arbitraryProperty . CustomPropertyArray . size ( ) ; + + jdx ) {
const SETTINGS_DATA : : DevicesClass : : SimplePropertyClass & customProperty = arbitraryProperty . CustomPropertyArray [ jdx ] ;
if ( customProperty . Key . contains ( " -platform-id " ) ) {
memcpy ( & GlobalConfig . IgPlatform , customProperty . Key . data ( ) , 4 ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2021-04-28 20:30:34 +02:00
2020-10-03 19:02:31 +02:00
void
2019-09-03 11:58:42 +02:00
SetDevices ( LOADER_ENTRY * Entry )
{
// EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *modeInfo;
EFI_STATUS Status ;
EFI_PCI_IO_PROTOCOL * PciIo ;
PCI_TYPE00 Pci ;
UINTN HandleCount ;
UINTN i , j ;
EFI_HANDLE * HandleBuffer ;
pci_dt_t PCIdevice ;
UINTN Segment ;
UINTN Bus ;
UINTN Device ;
UINTN Function ;
2021-09-28 15:54:31 +02:00
XBool StringDirty = false ;
XBool TmpDirty = false ;
2019-09-03 11:58:42 +02:00
UINT32 Rcba ;
UINT32 Hptc ;
DevPropDevice * device = NULL ;
GetEdidDiscovered ( ) ;
//First make string from Device->Properties
device = NULL ;
if ( ! device_inject_string ) {
device_inject_string = devprop_create_string ( ) ;
}
2021-04-01 10:06:53 +02:00
for ( size_t idx = 0 ; idx < gSettings . Devices . Properties . PropertyArray . size ( ) ; + + idx ) {
const SETTINGS_DATA : : DevicesClass : : PropertiesClass : : PropertyClass & Prop = gSettings . Devices . Properties . PropertyArray [ idx ] ;
// if (Prop->Device != 0) {
// Prop = Prop->Next; //skip CustomProperties
// continue;
// }
EFI_DEVICE_PATH_PROTOCOL * DevicePath = Prop . getDevicePath ( ) ;
if ( DevicePath = = NULL ) {
MsgLog ( " Properties with Label=%ls ignored because getDevicePath() return NULL \n " , Prop . DevicePathAsString . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2022-03-21 19:20:39 +01:00
2021-04-01 10:06:53 +02:00
device = devprop_add_device_pci ( device_inject_string , NULL , DevicePath ) ;
DBG ( " add device: %ls \n " , Prop . DevicePathAsString . wc_str ( ) ) ;
for ( size_t jdx = 0 ; jdx < Prop . propertiesArray . size ( ) ; + + jdx ) {
const SETTINGS_DATA : : DevicesClass : : SimplePropertyClass & Prop2 = Prop . propertiesArray [ jdx ] ;
if ( Prop2 . MenuItem . BValue ) {
if ( Prop2 . Key . contains ( " -platform-id " ) ) {
2021-04-12 14:11:01 +02:00
if ( GlobalConfig . IgPlatform = = 0 & & Prop2 . Value . size ( ) = = sizeof ( GlobalConfig . IgPlatform ) ) {
CopyMem ( ( UINT8 * ) & GlobalConfig . IgPlatform , Prop2 . Value . data ( ) , sizeof ( GlobalConfig . IgPlatform ) ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-12 14:11:01 +02:00
devprop_add_value ( device , Prop2 . Key . c_str ( ) , ( UINT8 * ) & GlobalConfig . IgPlatform , 4 ) ;
2021-04-01 10:06:53 +02:00
DBG ( " Add key=%s valuelen=%zu \n " , Prop2 . Key . c_str ( ) , Prop2 . Value . size ( ) ) ;
} else if ( ( Prop2 . Key . contains ( " override-no-edid " ) | | Prop2 . Key . contains ( " override-no-connect " ) )
2021-03-26 10:43:15 +01:00
& & gSettings . Graphics . EDID . InjectEDID & & gSettings . Graphics . EDID . CustomEDID . notEmpty ( ) ) {
2019-09-03 11:58:42 +02:00
// special case for EDID properties
2021-04-01 10:06:53 +02:00
devprop_add_value ( device , Prop2 . Key . c_str ( ) , gSettings . Graphics . EDID . CustomEDID . data ( ) , 128 ) ;
DBG ( " Add key=%s from custom EDID \n " , Prop2 . Key . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
} else {
2022-10-15 22:20:30 +02:00
devprop_add_value ( device , Prop2 . Key . c_str ( ) , Prop2 . Value . data ( ) , Prop2 . Value . size ( ) ) ;
2021-04-01 10:06:53 +02:00
DBG ( " Add key=%s valuelen=%zu \n " , Prop2 . Key . c_str ( ) , Prop2 . Value . size ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-01 10:06:53 +02:00
} else {
DBG ( " Skip disabled properties with Path=%ls, Key=%s \n " , Prop . DevicePathAsString . wc_str ( ) , Prop2 . Key . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2021-09-28 10:28:45 +02:00
StringDirty = true ;
2019-09-03 11:58:42 +02:00
}
}
devices_number = 1 ; //should initialize for reentering GUI
// Scan PCI handles
Status = gBS - > LocateHandleBuffer (
ByProtocol ,
& gEfiPciIoProtocolGuid ,
NULL ,
& HandleCount ,
& HandleBuffer
) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < HandleCount ; i + + ) {
2020-10-03 19:02:31 +02:00
Status = gBS - > HandleProtocol ( HandleBuffer [ i ] , & gEfiPciIoProtocolGuid , ( void * * ) & PciIo ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
// Read PCI BUS
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint32 , 0 , sizeof ( Pci ) / sizeof ( UINT32 ) , & Pci ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
Status = PciIo - > GetLocation ( PciIo , & Segment , & Bus , & Device , & Function ) ;
PCIdevice . DeviceHandle = HandleBuffer [ i ] ;
PCIdevice . dev . addr = ( UINT32 ) PCIADDR ( Bus , Device , Function ) ;
PCIdevice . vendor_id = Pci . Hdr . VendorId ;
PCIdevice . device_id = Pci . Hdr . DeviceId ;
PCIdevice . revision = Pci . Hdr . RevisionID ;
PCIdevice . subclass = Pci . Hdr . ClassCode [ 0 ] ;
PCIdevice . class_id = * ( ( UINT16 * ) ( Pci . Hdr . ClassCode + 1 ) ) ;
2021-09-28 10:28:45 +02:00
PCIdevice . subsys_id_union . subsys . vendor_id = Pci . Device . SubsystemVendorID ;
PCIdevice . subsys_id_union . subsys . device_id = Pci . Device . SubsystemID ;
PCIdevice . used = false ;
2019-09-03 11:58:42 +02:00
//------------------
device = NULL ;
2023-06-11 21:08:12 +02:00
2021-04-01 10:06:53 +02:00
for ( size_t idx = 0 ; idx < gSettings . Devices . ArbitraryArray . size ( ) ; + + idx ) {
const SETTINGS_DATA : : DevicesClass : : ArbitraryPropertyClass & Prop = gSettings . Devices . ArbitraryArray [ idx ] ;
if ( Prop . Device ! = PCIdevice . dev . addr ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( ! PCIdevice . used ) {
device = devprop_add_device_pci ( device_inject_string , & PCIdevice , NULL ) ;
2021-09-28 10:28:45 +02:00
PCIdevice . used = true ;
2019-09-03 11:58:42 +02:00
}
2021-04-01 10:06:53 +02:00
for ( size_t jdx = 0 ; jdx < Prop . CustomPropertyArray . size ( ) ; + + jdx ) {
const SETTINGS_DATA : : DevicesClass : : SimplePropertyClass & Prop2 = Prop . CustomPropertyArray [ jdx ] ;
2019-09-03 11:58:42 +02:00
//special corrections
2021-04-01 10:06:53 +02:00
if ( Prop2 . MenuItem . BValue ) {
if ( Prop2 . Key . contains ( " -platform-id " ) ) {
2021-04-12 14:11:01 +02:00
devprop_add_value ( device , Prop2 . Key . c_str ( ) , ( UINT8 * ) & GlobalConfig . IgPlatform , sizeof ( GlobalConfig . IgPlatform ) ) ;
2021-04-01 10:06:53 +02:00
} else {
devprop_add_value ( device , Prop2 . Key , Prop2 . Value ) ;
}
2019-09-03 11:58:42 +02:00
}
2021-09-28 10:28:45 +02:00
StringDirty = true ;
2019-09-03 11:58:42 +02:00
}
}
//------------------
if ( PCIdevice . used ) {
2020-04-07 21:48:36 +02:00
DBG ( " custom properties for device %02llX:%02llX.%02llX injected \n " , Bus , Device , Function ) ;
2019-09-03 11:58:42 +02:00
}
//}
// GFX
2023-06-11 21:08:12 +02:00
if (
2019-09-03 11:58:42 +02:00
( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_DISPLAY ) & &
( ( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_DISPLAY_VGA ) | |
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_DISPLAY_OTHER ) ) ) {
switch ( Pci . Hdr . VendorId ) {
case 0x1002 :
2021-03-26 10:43:15 +01:00
if ( gSettings . Graphics . InjectAsDict . InjectATI ) {
2019-09-03 11:58:42 +02:00
//can't do this in one step because of C-conventions
TmpDirty = setup_ati_devprop ( Entry , & PCIdevice ) ;
StringDirty | = TmpDirty ;
} else {
MsgLog ( " ATI injection not set \n " ) ;
}
2021-04-28 20:30:34 +02:00
for ( j = 0 ; j < gConf . GfxPropertiesArrayNonConst . size ( ) ; j + + ) {
if ( gConf . GfxPropertiesArrayNonConst [ j ] . Handle = = PCIdevice . DeviceHandle ) {
if ( gConf . GfxPropertiesArrayNonConst [ j ] . ConnChanged ) {
* ( UINT32 * ) ( gConf . GfxPropertiesArrayNonConst [ j ] . Mmio + RADEON_BIOS_0_SCRATCH ) = gConf . GfxPropertiesArrayNonConst [ j ] . Connectors ;
2019-09-03 11:58:42 +02:00
}
break ;
}
}
2021-03-26 10:43:15 +01:00
if ( gSettings . Graphics . RadeonDeInit ) {
2021-04-28 20:30:34 +02:00
for ( j = 0 ; j < gConf . GfxPropertiesArrayNonConst . size ( ) ; j + + ) {
if ( gConf . GfxPropertiesArrayNonConst [ j ] . Handle = = PCIdevice . DeviceHandle ) {
* ( UINT32 * ) ( gConf . GfxPropertiesArrayNonConst [ j ] . Mmio + 0x6848 ) = 0 ; //EVERGREEN_GRPH_FLIP_CONTROL, 1<<0 SURFACE_UPDATE_H_RETRACE_EN
* ( UINT32 * ) ( gConf . GfxPropertiesArrayNonConst [ j ] . Mmio + 0x681C ) = 0 ; //EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH
* ( UINT32 * ) ( gConf . GfxPropertiesArrayNonConst [ j ] . Mmio + 0x6820 ) = 0 ; //EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH
* ( UINT32 * ) ( gConf . GfxPropertiesArrayNonConst [ j ] . Mmio + 0x6808 ) = 0 ; //EVERGREEN_GRPH_LUT_10BIT_BYPASS_CONTROL, EVERGREEN_LUT_10BIT_BYPASS_EN (1 << 8)
* ( UINT32 * ) ( gConf . GfxPropertiesArrayNonConst [ j ] . Mmio + 0x6800 ) = 1 ; //EVERGREEN_GRPH_ENABLE
* ( UINT32 * ) ( gConf . GfxPropertiesArrayNonConst [ j ] . Mmio + 0x6EF8 ) = 0 ; //EVERGREEN_MASTER_UPDATE_MODE
//*(UINT32*)(gConf.GfxPropertiesArrayNonConst[j].Mmio + R600_BIOS_0_SCRATCH) = 0x00810000;
2020-04-07 21:48:36 +02:00
DBG ( " Device %llu deinited \n " , j ) ;
2019-09-03 11:58:42 +02:00
}
}
}
break ;
case 0x8086 :
2021-03-26 10:43:15 +01:00
if ( gSettings . Graphics . InjectAsDict . InjectIntel ) {
2021-04-28 20:30:34 +02:00
TmpDirty = setup_gma_devprop ( Entry - > macOSVersion , Entry - > BuildVersion , Entry - > Volume - > RootDir , & PCIdevice ) ;
2019-09-03 11:58:42 +02:00
StringDirty | = TmpDirty ;
2020-04-17 15:14:24 +02:00
MsgLog ( " Intel GFX revision = 0x%hhX \n " , PCIdevice . revision ) ;
2019-09-03 11:58:42 +02:00
} else {
MsgLog ( " Intel GFX injection not set \n " ) ;
}
// IntelBacklight reworked by Sherlocks. 2018.10.07
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . IntelBacklight | | gSettings . Devices . IntelMaxBacklight ) {
2019-09-03 11:58:42 +02:00
UINT32 LEV2 = 0 , LEVL = 0 , P0BL = 0 , GRAN = 0 ;
UINT32 LEVW = 0 , LEVX = 0 , LEVD = 0 , PCHL = 0 ;
UINT32 ShiftLEVX = 0 , FBLEVX = 0 ;
UINT32 SYSLEVW = 0x80000000 ;
UINT32 MACLEVW = 0xC0000000 ;
MsgLog ( " Intel GFX IntelBacklight \n " ) ;
// Read LEV2
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x48250 ,
1 ,
& LEV2
) ;
// Read LEVL
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x48254 ,
1 ,
& LEVL
) ;
// Read P0BL -- what is the sense to read if not used?
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x70040 ,
1 ,
& P0BL
) ;
// Read GRAN
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC2000 ,
1 ,
& GRAN
) ;
// Read LEVW
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& LEVW
) ;
// Read LEVX
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8254 ,
1 ,
& LEVX
) ;
ShiftLEVX = LEVX > > 16 ;
// Read LEVD
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8258 ,
1 ,
& LEVD
) ;
// Read PCHL
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xE1180 ,
1 ,
& PCHL
) ;
2020-03-25 19:32:44 +01:00
MsgLog ( " LEV2 = 0x%X, LEVL = 0x%X, P0BL = 0x%X, GRAN = 0x%X \n " , LEV2 , LEVL , P0BL , GRAN ) ;
MsgLog ( " LEVW = 0x%X, LEVX = 0x%X, LEVD = 0x%X, PCHL = 0x%X \n " , LEVW , LEVX , LEVD , PCHL ) ;
2019-09-03 11:58:42 +02:00
// Maximum brightness level of each framebuffers
// Sandy Bridge/Ivy Bridge: 0x0710
// Haswell/Broadwell: 0x056C/0x07A1/0x0AD9/0x1499
// Skylake/KabyLake: 0x056C
// Coffee Lake: 0xFFFF
switch ( Pci . Hdr . DeviceId ) {
case 0x0102 : // "Intel HD Graphics 2000"
case 0x0106 : // "Intel HD Graphics 2000"
case 0x010A : // "Intel HD Graphics P3000"
case 0x0112 : // "Intel HD Graphics 3000"
case 0x0116 : // "Intel HD Graphics 3000"
case 0x0122 : // "Intel HD Graphics 3000"
case 0x0126 : // "Intel HD Graphics 3000"
2021-04-12 14:11:01 +02:00
if ( GlobalConfig . IgPlatform ) {
switch ( GlobalConfig . IgPlatform ) {
2019-09-03 11:58:42 +02:00
case ( UINT32 ) 0x00030010 :
case ( UINT32 ) 0x00050000 :
FBLEVX = 0xFFFF ;
break ;
default :
FBLEVX = 0x0710 ;
break ;
}
} else {
FBLEVX = 0x0710 ;
}
break ;
case 0x0152 : // "Intel HD Graphics 2500"
case 0x0156 : // "Intel HD Graphics 2500"
case 0x015A : // "Intel HD Graphics 2500"
case 0x0162 : // "Intel HD Graphics 4000"
case 0x0166 : // "Intel HD Graphics 4000"
case 0x016A : // "Intel HD Graphics P4000"
FBLEVX = 0x0710 ;
break ;
case 0x0412 : // "Intel HD Graphics 4600"
case 0x0416 : // "Intel HD Graphics 4600"
case 0x041A : // "Intel HD Graphics P4600"
case 0x041E : // "Intel HD Graphics 4400"
case 0x0422 : // "Intel HD Graphics 5000"
case 0x0426 : // "Intel HD Graphics 5000"
case 0x042A : // "Intel HD Graphics 5000"
case 0x0A06 : // "Intel HD Graphics"
case 0x0A16 : // "Intel HD Graphics 4400"
case 0x0A1E : // "Intel HD Graphics 4200"
case 0x0A22 : // "Intel Iris Graphics 5100"
case 0x0A26 : // "Intel HD Graphics 5000"
case 0x0A2A : // "Intel Iris Graphics 5100"
case 0x0A2B : // "Intel Iris Graphics 5100"
case 0x0A2E : // "Intel Iris Graphics 5100"
case 0x0D12 : // "Intel HD Graphics 4600"
case 0x0D16 : // "Intel HD Graphics 4600"
case 0x0D22 : // "Intel Iris Pro Graphics 5200"
case 0x0D26 : // "Intel Iris Pro Graphics 5200"
case 0x0D2A : // "Intel Iris Pro Graphics 5200"
case 0x0D2B : // "Intel Iris Pro Graphics 5200"
case 0x0D2E : // "Intel Iris Pro Graphics 5200"
2021-04-12 14:11:01 +02:00
if ( GlobalConfig . IgPlatform ) {
switch ( GlobalConfig . IgPlatform ) {
2019-09-03 11:58:42 +02:00
case ( UINT32 ) 0x04060000 :
case ( UINT32 ) 0x0c060000 :
case ( UINT32 ) 0x04160000 :
case ( UINT32 ) 0x0c160000 :
case ( UINT32 ) 0x04260000 :
case ( UINT32 ) 0x0c260000 :
case ( UINT32 ) 0x0d260000 :
case ( UINT32 ) 0x0d220003 :
FBLEVX = 0x1499 ;
break ;
case ( UINT32 ) 0x0a160000 :
case ( UINT32 ) 0x0a260000 :
case ( UINT32 ) 0x0a260005 :
case ( UINT32 ) 0x0a260006 :
FBLEVX = 0x0AD9 ;
break ;
case ( UINT32 ) 0x0d260007 :
FBLEVX = 0x07A1 ;
break ;
case ( UINT32 ) 0x04120004 :
case ( UINT32 ) 0x0412000b :
break ;
default :
FBLEVX = 0x056C ;
break ;
}
} else {
switch ( Pci . Hdr . DeviceId ) {
case 0x0406 :
case 0x0C06 :
case 0x0416 :
case 0x0C16 :
case 0x0426 :
case 0x0C26 :
case 0x0D22 :
FBLEVX = 0x1499 ;
break ;
case 0x0A16 :
case 0x0A26 :
FBLEVX = 0x0AD9 ;
break ;
case 0x0D26 :
FBLEVX = 0x07A1 ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
}
break ;
case 0x1612 : // "Intel HD Graphics 5600"
case 0x1616 : // "Intel HD Graphics 5500"
case 0x161E : // "Intel HD Graphics 5300"
case 0x1626 : // "Intel HD Graphics 6000"
case 0x162B : // "Intel Iris Graphics 6100"
case 0x162D : // "Intel Iris Pro Graphics P6300"
case 0x1622 : // "Intel Iris Pro Graphics 6200"
case 0x162A : // "Intel Iris Pro Graphics P6300"
2021-04-12 14:11:01 +02:00
if ( GlobalConfig . IgPlatform ) {
switch ( GlobalConfig . IgPlatform ) {
2019-09-03 11:58:42 +02:00
case ( UINT32 ) 0x16060000 :
case ( UINT32 ) 0x160e0000 :
case ( UINT32 ) 0x16160000 :
case ( UINT32 ) 0x161e0000 :
case ( UINT32 ) 0x16220000 :
case ( UINT32 ) 0x16260000 :
case ( UINT32 ) 0x162b0000 :
case ( UINT32 ) 0x16260004 :
case ( UINT32 ) 0x162b0004 :
case ( UINT32 ) 0x16220007 :
case ( UINT32 ) 0x16260008 :
case ( UINT32 ) 0x162b0008 :
FBLEVX = 0x1499 ;
break ;
case ( UINT32 ) 0x16260005 :
case ( UINT32 ) 0x16260006 :
FBLEVX = 0x0AD9 ;
break ;
case ( UINT32 ) 0x16120003 :
FBLEVX = 0x07A1 ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
} else {
switch ( Pci . Hdr . DeviceId ) {
case 0x1606 :
case 0x160E :
case 0x1616 :
case 0x161E :
case 0x1622 :
FBLEVX = 0x1499 ;
break ;
case 0x1626 :
FBLEVX = 0x0AD9 ;
break ;
case 0x1612 :
FBLEVX = 0x07A1 ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
}
break ;
case 0x1902 : // "Intel HD Graphics 510"
case 0x1906 : // "Intel HD Graphics 510"
case 0x190B : // "Intel HD Graphics 510"
case 0x1912 : // "Intel HD Graphics 530"
case 0x1916 : // "Intel HD Graphics 520"
case 0x191B : // "Intel HD Graphics 530"
case 0x191D : // "Intel HD Graphics P530"
case 0x191E : // "Intel HD Graphics 515"
case 0x1921 : // "Intel HD Graphics 520"
case 0x1923 : // "Intel HD Graphics 535"
case 0x1926 : // "Intel Iris Graphics 540"
case 0x1927 : // "Intel Iris Graphics 550"
case 0x192B : // "Intel Iris Graphics 555"
case 0x192D : // "Intel Iris Graphics P555"
case 0x1932 : // "Intel Iris Pro Graphics 580"
case 0x193A : // "Intel Iris Pro Graphics P580"
case 0x193B : // "Intel Iris Pro Graphics 580"
case 0x193D : // "Intel Iris Pro Graphics P580"
2021-04-12 14:11:01 +02:00
if ( GlobalConfig . IgPlatform ) {
switch ( GlobalConfig . IgPlatform ) {
2019-09-03 11:58:42 +02:00
case ( UINT32 ) 0x19120001 :
FBLEVX = 0xFFFF ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
} else {
FBLEVX = 0x056C ;
}
break ;
case 0x5902 : // "Intel HD Graphics 610"
case 0x5906 : // "Intel HD Graphics 610"
case 0x5912 : // "Intel HD Graphics 630"
case 0x5916 : // "Intel HD Graphics 620"
case 0x591A : // "Intel HD Graphics P630"
case 0x591B : // "Intel HD Graphics 630"
case 0x591D : // "Intel HD Graphics P630"
case 0x591E : // "Intel HD Graphics 615"
case 0x5923 : // "Intel HD Graphics 635"
case 0x5926 : // "Intel Iris Plus Graphics 640"
case 0x5927 : // "Intel Iris Plus Graphics 650"
case 0x5917 : // "Intel UHD Graphics 620"
case 0x591C : // "Intel UHD Graphics 615"
case 0x87C0 : // "Intel UHD Graphics 617"
2019-10-12 13:12:59 +02:00
case 0x87CA : // "Intel UHD Graphics 615"
2019-09-03 11:58:42 +02:00
FBLEVX = 0x056C ;
break ;
case 0x3E90 : // "Intel UHD Graphics 610"
case 0x3E93 : // "Intel UHD Graphics 610"
case 0x3E91 : // "Intel UHD Graphics 630"
case 0x3E92 : // "Intel UHD Graphics 630"
case 0x3E98 : // "Intel UHD Graphics 630"
case 0x3E9B : // "Intel UHD Graphics 630"
case 0x3EA5 : // "Intel Iris Plus Graphics 655"
case 0x3EA0 : // "Intel UHD Graphics 620"
2019-10-12 02:56:20 +02:00
case 0x9B41 : // "Intel UHD Graphics 620"
case 0x9BCA : // "Intel UHD Graphics 620"
2019-09-03 11:58:42 +02:00
FBLEVX = 0xFFFF ;
break ;
default :
FBLEVX = 0xFFFF ;
break ;
}
// Write LEVW
if ( LEVW ! = SYSLEVW ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVW, set System LEVW: 0x%X \n " , SYSLEVW ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& SYSLEVW
) ;
}
switch ( gCPUStructure . Model ) {
case CPU_MODEL_SANDY_BRIDGE :
case CPU_MODEL_IVY_BRIDGE :
case CPU_MODEL_IVY_BRIDGE_E5 :
// if change SYS LEVW to macOS LEVW, the brightness of the pop-up may decrease or increase.
// but the brightness of the monitor will not actually change. so we should not use this.
2020-03-25 19:32:44 +01:00
MsgLog ( " Skip writing macOS LEVW: 0x%X \n " , MACLEVW ) ;
2019-09-03 11:58:42 +02:00
break ;
case CPU_MODEL_HASWELL :
case CPU_MODEL_HASWELL_ULT :
case CPU_MODEL_HASWELL_U5 : // Broadwell
case CPU_MODEL_BROADWELL_HQ :
case CPU_MODEL_BROADWELL_E5 :
case CPU_MODEL_BROADWELL_DE :
// if not change SYS LEVW to macOS LEVW, backlight will be dark and don't work keys for backlight.
// so we should use this.
2020-03-25 19:32:44 +01:00
MsgLog ( " Write macOS LEVW: 0x%X \n " , MACLEVW ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& MACLEVW
) ;
break ;
default :
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . IntelBacklight ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Write macOS LEVW: 0x%X \n " , MACLEVW ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& MACLEVW
) ;
}
break ;
}
switch ( Pci . Hdr . DeviceId ) {
case 0x0042 : // "Intel HD Graphics"
case 0x0046 : // "Intel HD Graphics"
case 0x0102 : // "Intel HD Graphics 2000"
case 0x0106 : // "Intel HD Graphics 2000"
case 0x010A : // "Intel HD Graphics P3000"
case 0x0112 : // "Intel HD Graphics 3000"
case 0x0116 : // "Intel HD Graphics 3000"
case 0x0122 : // "Intel HD Graphics 3000"
case 0x0126 : // "Intel HD Graphics 3000"
case 0x0152 : // "Intel HD Graphics 2500"
case 0x0156 : // "Intel HD Graphics 2500"
case 0x015A : // "Intel HD Graphics 2500"
case 0x0162 : // "Intel HD Graphics 4000"
case 0x0166 : // "Intel HD Graphics 4000"
case 0x016A : // "Intel HD Graphics P4000"
// Write LEVL/LEVX
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . IntelMaxBacklight ) {
2019-09-03 11:58:42 +02:00
if ( ! LEVL ) {
LEVL = FBLEVX ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVL, set LEVL: 0x%X \n " , LEVL ) ;
2019-09-03 11:58:42 +02:00
}
if ( ! LEVX ) {
ShiftLEVX = FBLEVX ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVX, set LEVX: 0x%X \n " , ShiftLEVX ) ;
2019-09-03 11:58:42 +02:00
}
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . IntelMaxValue ) {
FBLEVX = gSettings . Devices . IntelMaxValue ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Read IntelMaxValue: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-03-25 19:32:44 +01:00
MsgLog ( " Read default Framebuffer LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
}
LEVL = ( LEVL * FBLEVX ) / ShiftLEVX ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVL: 0x%X \n " , LEVL ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x48254 ,
1 ,
& LEVL
) ;
LEVX = FBLEVX | FBLEVX < < 16 ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVX: 0x%X \n " , LEVX ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8254 ,
1 ,
& LEVX
) ;
}
break ;
case 0x3E90 : // "Intel UHD Graphics 610"
case 0x3E93 : // "Intel UHD Graphics 610"
case 0x3E91 : // "Intel UHD Graphics 630"
case 0x3E92 : // "Intel UHD Graphics 630"
case 0x3E98 : // "Intel UHD Graphics 630"
case 0x3E9B : // "Intel UHD Graphics 630"
case 0x3EA5 : // "Intel Iris Plus Graphics 655"
case 0x3EA0 : // "Intel UHD Graphics 620"
2019-10-12 02:56:20 +02:00
case 0x9B41 : // "Intel UHD Graphics 620"
case 0x9BCA : // "Intel UHD Graphics 620"
2019-09-03 11:58:42 +02:00
// Write LEVD
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . IntelMaxBacklight ) {
if ( gSettings . Devices . IntelMaxValue ) {
FBLEVX = gSettings . Devices . IntelMaxValue ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Read IntelMaxValue: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-03-25 19:32:44 +01:00
MsgLog ( " Read default Framebuffer LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
}
LEVD = ( UINT32 ) DivU64x32 ( MultU64x32 ( FBLEVX , LEVX ) , 0xFFFF ) ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVD: 0x%X \n " , LEVD ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8258 ,
1 ,
& LEVD
) ;
}
break ;
default :
// Write LEVX
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . IntelMaxBacklight ) {
if ( gSettings . Devices . IntelMaxValue ) {
FBLEVX = gSettings . Devices . IntelMaxValue ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Read IntelMaxValue: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
LEVX = FBLEVX | FBLEVX < < 16 ;
} else if ( ! LEVX ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVX, set LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
LEVX = FBLEVX | FBLEVX < < 16 ;
} else if ( ShiftLEVX ! = FBLEVX ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Read default Framebuffer LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
LEVX = ( ( ( LEVX & 0xFFFF ) * FBLEVX / ShiftLEVX ) | FBLEVX < < 16 ) ;
}
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVX: 0x%X \n " , LEVX ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8254 ,
1 ,
& LEVX
) ;
}
break ;
}
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . FakeID . FakeIntel = = 0x00008086 ) {
2019-09-03 11:58:42 +02:00
UINT32 IntelDisable = 0x03 ;
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint32 , 0x50 , 1 , & IntelDisable ) ;
}
}
break ;
case 0x10de :
2021-03-26 10:43:15 +01:00
if ( gSettings . Graphics . InjectAsDict . InjectNVidia ) {
2019-09-03 11:58:42 +02:00
TmpDirty = setup_nvidia_devprop ( & PCIdevice ) ;
StringDirty | = TmpDirty ;
} else {
MsgLog ( " NVidia GFX injection not set \n " ) ;
}
break ;
default :
break ;
}
}
//LAN
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_NETWORK ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_NETWORK_ETHERNET ) ) {
//MsgLog ("Ethernet device found\n");
TmpDirty = set_eth_props ( & PCIdevice ) ;
StringDirty | = TmpDirty ;
}
//USB
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_SERIAL ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_SERIAL_USB ) ) {
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . USB . USBInjection ) {
2019-09-03 11:58:42 +02:00
TmpDirty = set_usb_props ( & PCIdevice ) ;
StringDirty | = TmpDirty ;
}
}
// HDA
2020-06-05 14:15:31 +02:00
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_MEDIA ) & &
2019-09-03 11:58:42 +02:00
( ( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_MEDIA_HDA ) | |
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_MEDIA_AUDIO ) ) ) {
// HDMI injection inside
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . Audio . HDAInjection ) {
2021-01-31 10:50:23 +01:00
TmpDirty = setup_hda_devprop ( PciIo , & PCIdevice , Entry - > macOSVersion ) ;
2020-06-05 14:15:31 +02:00
StringDirty | = TmpDirty ;
}
2021-03-26 10:43:15 +01:00
if ( gSettings . Devices . Audio . ResetHDA ) {
2020-06-05 14:15:31 +02:00
//PCI_HDA_TCSEL_OFFSET = 0x44
UINT8 Value = 0 ;
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint8 , 0x44 , 1 , & Value ) ;
if ( EFI_ERROR ( Status ) ) {
continue ;
}
Value & = 0xf8 ;
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint8 , 0x44 , 1 , & Value ) ;
}
}
2019-09-03 11:58:42 +02:00
//LPC
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_BRIDGE ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_BRIDGE_ISA ) )
{
2021-04-03 16:42:49 +02:00
// 2021-04 Jief : LpcTune doesn't exist in Settings.cpp. Never set to true.
// if (gSettings.LpcTune) {
// UINT16 PmCon;
// Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, GEN_PMCON_1, 1, &PmCon);
// MsgLog ("Initial PmCon value=%hX\n", PmCon);
//
// if (GlobalConfig.EnableC6) {
// PmCon |= 1 << 11;
// DBG("C6 enabled\n");
// } else {
// PmCon &= ~(1 << 11);
// DBG("C6 disabled\n");
// }
// /*
// if (GlobalConfig.EnableC2) {
// PmCon |= 1 << 10;
// DBG("BIOS_PCIE enabled\n");
// } else {
// PmCon &= ~(1 << 10);
// DBG("BIOS_PCIE disabled\n");
// }
// */
// if (GlobalConfig.EnableC4) {
// PmCon |= 1 << 7;
// DBG("C4 enabled\n");
// } else {
// PmCon &= ~(1 << 7);
// DBG("C4 disabled\n");
// }
//
// if (gSettings.ACPI.SSDT.EnableISS) {
// PmCon |= 1 << 3;
// DBG("SpeedStep enabled\n");
// } else {
// PmCon &= ~(1 << 3);
// DBG("SpeedStep disabled\n");
// }
//
// PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, GEN_PMCON_1, 1, &PmCon);
//
// Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16,GEN_PMCON_1, 1, &PmCon);
// MsgLog ("Set PmCon value=%hX\n", PmCon);
//
// }
2019-09-03 11:58:42 +02:00
Rcba = 0 ;
/* Scan Port */
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint32 , 0xF0 , 1 , & Rcba ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) continue ;
2019-09-03 11:58:42 +02:00
// Rcba &= 0xFFFFC000;
if ( ( Rcba & 0xFFFFC000 ) = = 0 ) {
MsgLog ( " RCBA disabled; cannot use it \n " ) ;
continue ;
}
if ( ( Rcba & 1 ) = = 0 ) {
MsgLog ( " RCBA access disabled; trying to enable \n " ) ;
Rcba | = 1 ;
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint32 , 0xF0 , 1 , & Rcba ) ;
}
Rcba & = 0xFFFFC000 ;
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . ForceHPET ) {
2019-09-03 11:58:42 +02:00
Hptc = REG32 ( ( UINTN ) Rcba , 0x3404 ) ;
if ( ( Hptc & 0x80 ) ! = 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is already enabled \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is disabled, trying to enable... \n " ) ;
2019-09-03 11:58:42 +02:00
REG32 ( ( UINTN ) Rcba , 0x3404 ) = Hptc | 0x80 ;
}
// Re-Check if HPET is enabled.
Hptc = REG32 ( ( UINTN ) Rcba , 0x3404 ) ;
if ( ( Hptc & 0x80 ) = = 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is disabled in HPTC. Cannot enable! \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is enabled \n " ) ;
2019-09-03 11:58:42 +02:00
}
}
2021-03-29 10:50:02 +02:00
if ( gSettings . Devices . DisableFunctions ) {
2019-09-03 11:58:42 +02:00
UINT32 FD = REG32 ( ( UINTN ) Rcba , 0x3418 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Initial value of FD register 0x%X \n " , FD ) ;
2021-03-29 10:50:02 +02:00
FD | = gSettings . Devices . DisableFunctions ;
2019-09-03 11:58:42 +02:00
REG32 ( ( UINTN ) Rcba , 0x3418 ) = FD ;
FD = REG32 ( ( UINTN ) Rcba , 0x3418 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " recheck value after patch 0x%X \n " , FD ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
if ( StringDirty ) {
EFI_PHYSICAL_ADDRESS BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS ; //0xFE000000;
2021-04-01 10:06:53 +02:00
2021-04-08 10:01:20 +02:00
XBuffer < char > newDeviceProperties = devprop_generate_string ( device_inject_string ) ;
2021-04-01 10:06:53 +02:00
size_t binaryPropSize = hex2bin ( newDeviceProperties , NULL , 0 ) ;
if ( binaryPropSize > MAX_UINT32 ) {
MsgLog ( " devprop_generate_string(device_inject_string) is too big " ) ;
newDeviceProperties . setEmpty ( ) ;
2021-03-26 06:32:26 +01:00
} else {
2021-04-08 10:01:20 +02:00
DBG ( " stringlength = %zu \n " , newDeviceProperties . size ( ) ) ;
2021-03-26 06:32:26 +01:00
2021-04-01 10:06:53 +02:00
UINTN nbPages = EFI_SIZE_TO_PAGES ( binaryPropSize ) ;
2021-03-26 06:32:26 +01:00
Status = gBS - > AllocatePages (
AllocateMaxAddress ,
EfiACPIReclaimMemory ,
nbPages ,
& BufferPtr
) ;
if ( ! EFI_ERROR ( Status ) ) {
2021-04-01 10:06:53 +02:00
mProperties = ( UINT8 * ) ( UINTN ) BufferPtr ;
// DBG(gDeviceProperties);
// DBG("\n");
2021-09-28 10:28:45 +02:00
// StringDirty = false;
2021-04-01 10:06:53 +02:00
//-------
mPropSize = ( UINT32 ) hex2bin ( newDeviceProperties , mProperties , EFI_PAGES_TO_SIZE ( nbPages ) ) ; // cast should be safe as hex2bin return <= MAXUINT32
2022-03-21 19:20:39 +01:00
// gDeviceProperties is not used
2021-04-01 10:06:53 +02:00
gDeviceProperties = newDeviceProperties . forgetDataWithoutFreeing ( ) ; // do this AFTER hex2bin
// DBG("Final size of mProperties=%d\n", mPropSize);
//---------
// Status = egSaveFile(&self.getSelfRootDir(), SWPrintf("%ls\\misc\\devprop.bin", self.getCloverDirFullPath().wc_str()).wc_str() , (UINT8*)mProperties, mPropSize);
} else {
MsgLog ( " AllocatePages failed (%s), device_inject_string not injected \n " , efiStrError ( Status ) ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2021-02-06 18:16:46 +01:00
MsgLog ( " CurrentMode: Width=%lld Height=%lld \n " , UGAWidth , UGAHeight ) ;
2019-09-03 11:58:42 +02:00
}
EFI_STATUS
2021-04-28 20:30:34 +02:00
ApplySettings ( )
2019-09-03 11:58:42 +02:00
{
// TODO: SetVariable()..
// here we can apply user settings instead of default one
2021-04-03 16:42:49 +02:00
gMobile = gSettings . Smbios . Mobile ;
2019-09-03 11:58:42 +02:00
2021-03-19 16:35:01 +01:00
if ( ( gSettings . CPU . BusSpeed ! = 0 ) & & ( gSettings . CPU . BusSpeed > 10 * Kilo ) & & ( gSettings . CPU . BusSpeed < 500 * Kilo ) ) {
2019-09-03 11:58:42 +02:00
switch ( gCPUStructure . Model ) {
case CPU_MODEL_PENTIUM_M :
case CPU_MODEL_ATOM : // Atom
case CPU_MODEL_DOTHAN : // Pentium M, Dothan, 90nm
case CPU_MODEL_YONAH : // Core Duo/Solo, Pentium M DC
case CPU_MODEL_MEROM : // Core Xeon, Core 2 Duo, 65nm, Mobile
//case CPU_MODEL_CONROE:// Core Xeon, Core 2 Duo, 65nm, Desktop like Merom but not mobile
case CPU_MODEL_CELERON :
case CPU_MODEL_PENRYN : // Core 2 Duo/Extreme, Xeon, 45nm , Mobile
case CPU_MODEL_NEHALEM : // Core i7 LGA1366, Xeon 5500, "Bloomfield", "Gainstown", 45nm
case CPU_MODEL_FIELDS : // Core i7, i5 LGA1156, "Clarksfield", "Lynnfield", "Jasper", 45nm
case CPU_MODEL_DALES : // Core i7, i5, Nehalem
case CPU_MODEL_CLARKDALE : // Core i7, i5, i3 LGA1156, "Westmere", "Clarkdale", , 32nm
case CPU_MODEL_WESTMERE : // Core i7 LGA1366, Six-core, "Westmere", "Gulftown", 32nm
case CPU_MODEL_NEHALEM_EX : // Core i7, Nehalem-Ex Xeon, "Beckton"
case CPU_MODEL_WESTMERE_EX : // Core i7, Nehalem-Ex Xeon, "Eagleton"
2021-03-19 16:35:01 +01:00
gCPUStructure . ExternalClock = gSettings . CPU . BusSpeed ;
2021-02-06 18:16:46 +01:00
//DBG("Read ExternalClock: %d MHz\n", (INT32)(DivU64x32(gCPUStructure.ExternalClock, Kilo)));
2019-09-03 11:58:42 +02:00
break ;
default :
2021-02-06 18:16:46 +01:00
//DBG("Read ExternalClock: %d MHz\n", (INT32)(DivU64x32(gSettings.BusSpeed, Kilo)));
2019-09-03 11:58:42 +02:00
// for sandy bridge or newer
// to match ExternalClock 25 MHz like real mac, divide BusSpeed by 4
2021-03-19 16:35:01 +01:00
gCPUStructure . ExternalClock = ( gSettings . CPU . BusSpeed + 3 ) / 4 ;
2021-02-06 18:16:46 +01:00
//DBG("Corrected ExternalClock: %d MHz\n", (INT32)(DivU64x32(gCPUStructure.ExternalClock, Kilo)));
2019-09-03 11:58:42 +02:00
break ;
}
2021-03-19 16:35:01 +01:00
gCPUStructure . FSBFrequency = MultU64x64 ( gSettings . CPU . BusSpeed , Kilo ) ; //kHz -> Hz
gCPUStructure . MaxSpeed = ( UINT32 ) ( DivU64x32 ( ( UINT64 ) gSettings . CPU . BusSpeed * gCPUStructure . MaxRatio , 10000 ) ) ; //kHz->MHz
2019-09-03 11:58:42 +02:00
}
2021-03-19 16:35:01 +01:00
if ( ( gSettings . CPU . CpuFreqMHz > 100 ) & & ( gSettings . CPU . CpuFreqMHz < 20000 ) ) {
gCPUStructure . MaxSpeed = gSettings . CPU . CpuFreqMHz ;
2019-09-03 11:58:42 +02:00
}
// to determine the use of Table 132
2021-03-19 16:35:01 +01:00
if ( gSettings . CPU . QPI ) {
2021-09-28 10:28:45 +02:00
GlobalConfig . SetTable132 = true ;
2020-04-23 18:05:21 +02:00
//DBG("QPI: use Table 132\n");
2019-09-03 11:58:42 +02:00
}
else {
switch ( gCPUStructure . Model ) {
case CPU_MODEL_NEHALEM : // Core i7 LGA1366, Xeon 5500, "Bloomfield", "Gainstown", 45nm
case CPU_MODEL_WESTMERE : // Core i7 LGA1366, Six-core, "Westmere", "Gulftown", 32nm
case CPU_MODEL_NEHALEM_EX : // Core i7, Nehalem-Ex Xeon, "Beckton"
case CPU_MODEL_WESTMERE_EX : // Core i7, Nehalem-Ex Xeon, "Eagleton"
2021-09-28 10:28:45 +02:00
GlobalConfig . SetTable132 = true ;
2020-04-23 18:05:21 +02:00
DBG ( " QPI: use Table 132 \n " ) ;
2019-09-03 11:58:42 +02:00
break ;
default :
2020-04-23 18:05:21 +02:00
//DBG("QPI: disable Table 132\n");
2019-09-03 11:58:42 +02:00
break ;
}
}
gCPUStructure . CPUFrequency = MultU64x64 ( gCPUStructure . MaxSpeed , Mega ) ;
return EFI_SUCCESS ;
}
2021-09-28 10:28:45 +02:00
XStringW GetOtherKextsDir ( XBool On )
2019-09-03 11:58:42 +02:00
{
2020-10-05 11:14:35 +02:00
if ( ! selfOem . isKextsDirFound ( ) ) return NullXStringW ;
2020-10-03 19:02:31 +02:00
if ( FileExists ( & selfOem . getKextsDir ( ) , On ? L " Other " : L " Off " ) ) {
return On ? L " Other " _XSW : L " Off " _XSW ;
2019-09-03 11:58:42 +02:00
}
2020-10-03 19:02:31 +02:00
return NullXStringW ;
2019-09-03 11:58:42 +02:00
}
2020-10-17 15:01:33 +02:00
2019-09-03 11:58:42 +02:00
//dmazar
2020-10-17 15:01:33 +02:00
// Jief 2020-10: this is only called by SetFSInjection(). SetFSInjection() doesn't check for return value emptiness.
2020-11-12 22:25:56 +01:00
XStringW GetOSVersionKextsDir ( const MacOsVersion & OSVersion )
2019-09-03 11:58:42 +02:00
{
2020-10-17 15:01:33 +02:00
if ( ! selfOem . isKextsDirFound ( ) ) return NullXStringW ;
2020-11-12 22:25:56 +01:00
XStringW SrcDir = SWPrintf ( " %ls \\ %s " , selfOem . getKextsFullPath ( ) . wc_str ( ) , OSVersion . asString ( 2 ) . c_str ( ) ) ;
2020-10-17 15:01:33 +02:00
if ( FileExists ( & self . getSelfVolumeRootDir ( ) , SrcDir ) ) return SrcDir ;
return NullXStringW ;
2019-09-03 11:58:42 +02:00
}
2020-09-23 15:47:47 +02:00
2022-04-26 00:55:56 +02:00
const EFI_GUID & SETTINGS_DATA : : getUUID ( )
2020-09-23 15:47:47 +02:00
{
2022-04-26 00:55:56 +02:00
if ( SystemParameters . CustomUuid . notNull ( ) ) return SystemParameters . CustomUuid ;
2021-04-03 16:42:49 +02:00
return Smbios . SmUUID ;
2020-09-23 15:47:47 +02:00
}