Skip to content

Commit

Permalink
Use new location for USB sleep in Catalina
Browse files Browse the repository at this point in the history
  • Loading branch information
benbaker76 committed Mar 28, 2020
1 parent 9226c65 commit 7ceccac
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 855 deletions.
8 changes: 4 additions & 4 deletions Hackintool.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0332;
CURRENT_PROJECT_VERSION = 0333;
DEVELOPMENT_TEAM = 5LGHPJM9ZR;
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_STRICT_OBJC_MSGSEND = NO;
Expand All @@ -728,7 +728,7 @@
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
INFOPLIST_FILE = "Hackintool/Hackintool-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks @executable_path/../Frameworks";
MARKETING_VERSION = 3.3.2;
MARKETING_VERSION = 3.3.3;
PRODUCT_BUNDLE_IDENTIFIER = com.Headsoft.Hackintool;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -748,7 +748,7 @@
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0332;
CURRENT_PROJECT_VERSION = 0333;
DEVELOPMENT_TEAM = 5LGHPJM9ZR;
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_STRICT_OBJC_MSGSEND = NO;
Expand All @@ -762,7 +762,7 @@
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
INFOPLIST_FILE = "Hackintool/Hackintool-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks @executable_path/../Frameworks";
MARKETING_VERSION = 3.3.2;
MARKETING_VERSION = 3.3.3;
PRODUCT_BUNDLE_IDENTIFIER = com.Headsoft.Hackintool;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions Hackintool/FBUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool appendFramebufferInfoDSL(AppDelegate *appDelegate, uint32_t tab, NSMutableD

NSString *ioregName = [pciDeviceDictionary objectForKey:@"IORegName"];
NSString *devicePath = [pciDeviceDictionary objectForKey:@"DevicePath"];
NSNumber *address = [pciDeviceDictionary objectForKey:@"Address"];
uint32_t address = [[pciDeviceDictionary objectForKey:@"Address"] unsignedIntValue];
NSString *acpiPath;

if (![appDelegate tryGetACPIPath:ioregName acpiPath:&acpiPath])
Expand All @@ -117,7 +117,7 @@ bool appendFramebufferInfoDSL(AppDelegate *appDelegate, uint32_t tab, NSMutableD
[appDelegate appendDSLString:tab + 0 outputString:*outputString value:[NSString stringWithFormat:@"External (_SB_.%@, DeviceObj)", acpiPath]];
[appDelegate appendDSLString:tab + 0 outputString:*outputString value:[NSString stringWithFormat:@"Device (_SB.%@)", acpiPath]];
[appDelegate appendDSLString:tab + 0 outputString:*outputString value:@"{"];
[appDelegate appendDSLString:tab + 1 outputString:*outputString value:[NSString stringWithFormat:@"Name (_ADR, 0x%08x)", [address unsignedIntValue]]];
[appDelegate appendDSLString:tab + 1 outputString:*outputString value:[NSString stringWithFormat:@"Name (_ADR, 0x%08x)", address]];
[appDelegate appendDSLString:tab + 1 outputString:*outputString value:@"Method (_DSM, 4, NotSerialized)"];
[appDelegate appendDSLString:tab + 1 outputString:*outputString value:@"{"];
[appDelegate appendDSLString:tab + 2 outputString:*outputString value:@"If (LEqual (Arg2, Zero)) { Return (Buffer() { 0x03 } ) }"];
Expand Down
8 changes: 8 additions & 0 deletions Hackintool/USB.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,13 @@ NSString *getUSBConnectorSpeed(uint8_t speed);
void exportUSBPortsKext(AppDelegate *appDelegate);
void exportUSBPortsSSDT(AppDelegate *appDelegate);
void exportUSBPorts(AppDelegate *appDelegate);
bool isControllerLocationXHC(uint32_t usbControllerLocationID);
bool isControllerLocationEH1(uint32_t usbControllerLocationID);
bool isControllerLocationEH2(uint32_t usbControllerLocationID);
bool isControllerNameXHC(NSString *controllerName);
bool isControllerNameEH1(NSString *controllerName);
bool isControllerNameEH2(NSString *controllerName);
bool isPortLocationHUB1(uint32_t locationID);
bool isPortLocationHUB2(uint32_t locationID);

#endif /* USB_hpp */
213 changes: 168 additions & 45 deletions Hackintool/USB.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,47 +272,116 @@ void injectDefaultUSBPowerProperties(NSMutableDictionary *ioProviderMergePropert
[ioProviderMergePropertiesDictionary setObject:@(5100) forKey:@"kUSBWakePowerSupply"];
}

bool injectUSBPowerProperties(AppDelegate *appDelegate, NSMutableDictionary *ioProviderMergePropertiesDictionary)
bool injectUSBPowerProperties(AppDelegate *appDelegate, uint32_t controllerLocationID, bool isHub, NSMutableDictionary *ioProviderMergePropertiesDictionary)
{
/* NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *ioUSBHostPath = @"/System/Library/Extensions/IOUSBHostFamily.kext/Contents/Info.plist";
if (![fileManager fileExistsAtPath:ioUSBHostPath])
return false; */

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *filePath = nil;

if (!(filePath = [mainBundle pathForResource:@"config_patches" ofType:@"plist" inDirectory:@"Clover"]))
return false;

NSDictionary *ioUSBHostInfoDictionary = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSDictionary *ioUSBHostIOKitPersonalities = [ioUSBHostInfoDictionary objectForKey:@"IOKitPersonalities"];
NSString *nearestModelIdentifier = nil;

// If we already have an entry leave it out
if ([[ioUSBHostIOKitPersonalities allKeys] containsObject:appDelegate.modelIdentifier])
return false;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *ioUSBHostPath1 = @"/System/Library/Extensions/IOUSBHostFamily.kext/Contents/PlugIns/AppleUSBHostPlatformProperties.kext/Contents/Info.plist";
NSString *ioUSBHostPath2 = @"/System/Library/Extensions/IOUSBHostFamily.kext/Contents/Info.plist";
NSDictionary *ioUSBHostIOProviderMergePropertiesDictionary = nil;

if ([fileManager fileExistsAtPath:ioUSBHostPath1])
{
NSDictionary *ioUSBHostInfoDictionary = [NSDictionary dictionaryWithContentsOfFile:ioUSBHostPath1];
NSDictionary *ioUSBHostIOKitPersonalities = [ioUSBHostInfoDictionary objectForKey:@"IOKitPersonalities_x86_64"];
NSMutableArray *sortedKeys = [[[ioUSBHostIOKitPersonalities allKeys] mutableCopy] autorelease];
NSDictionary *ioUSBHostIOKitPersonalityDictionary = nil;
NSString *nearestModelIdentifier = nil;
[sortedKeys sortUsingSelector:@selector(compare:)];
sortedKeys = [[[[sortedKeys reverseObjectEnumerator] allObjects] mutableCopy] autorelease];

for (NSString *key in sortedKeys)
{
// iMac13,1
// iMac13,1-EHC1
// iMac13,1-EHC2
// iMac13,1-InternalHub-EHC1
// iMac13,1-InternalHub-EHC1-InternalHub
// iMac13,1-XHC1
NSArray *keyArray = [key componentsSeparatedByString:@"-"];
NSString *model = nil;
NSString *controllerName = nil;
bool isControllerHub = false;

if ([keyArray count] == 1)
model = keyArray[0];
else if ([keyArray count] == 2)
{
model = keyArray[0];
controllerName = keyArray[1];
}
else if ([keyArray count] >= 3)
{
model = keyArray[0];
controllerName = keyArray[2];
isControllerHub = true;
}

bool isHubMatch = (isControllerHub == isHub);
bool isModelMatch = [appDelegate.modelIdentifier isEqualToString:model];

if (controllerName != nil)
{
if (isHubMatch && isModelMatch && isControllerLocationXHC(controllerLocationID) && isControllerNameXHC(controllerName))
{
ioUSBHostIOKitPersonalityDictionary = [ioUSBHostIOKitPersonalities objectForKey:key];
break;
}
else if (isHubMatch && isModelMatch && isControllerLocationEH1(controllerLocationID) && isControllerNameEH1(controllerName))
{
ioUSBHostIOKitPersonalityDictionary = [ioUSBHostIOKitPersonalities objectForKey:key];
break;
}
else if (isHubMatch && isModelMatch && isControllerLocationEH2(controllerLocationID) && isControllerNameEH2(controllerName))
{
ioUSBHostIOKitPersonalityDictionary = [ioUSBHostIOKitPersonalities objectForKey:key];
break;
}
}
else
{
if (isModelMatch)
{
ioUSBHostIOKitPersonalityDictionary = [ioUSBHostIOKitPersonalities objectForKey:key];
break;
}
}
}

if (ioUSBHostIOKitPersonalityDictionary == nil)
{
if ([appDelegate tryGetNearestModel:[ioUSBHostIOKitPersonalities allKeys] modelIdentifier:appDelegate.modelIdentifier nearestModelIdentifier:&nearestModelIdentifier])
ioUSBHostIOKitPersonalityDictionary = [ioUSBHostIOKitPersonalities objectForKey:nearestModelIdentifier];
}

if (ioUSBHostIOKitPersonalityDictionary != nil)
ioUSBHostIOProviderMergePropertiesDictionary = [ioUSBHostIOKitPersonalityDictionary objectForKey:@"IOProviderMergeProperties"];
}
else if ([fileManager fileExistsAtPath:ioUSBHostPath2])
{
NSDictionary *ioUSBHostInfoDictionary = [NSDictionary dictionaryWithContentsOfFile:ioUSBHostPath2];
NSDictionary *ioUSBHostIOKitPersonalities = [ioUSBHostInfoDictionary objectForKey:@"IOKitPersonalities"];
NSString *nearestModelIdentifier = nil;

if ([appDelegate tryGetNearestModel:[ioUSBHostIOKitPersonalities allKeys] modelIdentifier:appDelegate.modelIdentifier nearestModelIdentifier:&nearestModelIdentifier])
{
NSDictionary *ioUSBHostIOKitPersonalityDictionary = [ioUSBHostIOKitPersonalities objectForKey:nearestModelIdentifier];
ioUSBHostIOProviderMergePropertiesDictionary = [ioUSBHostIOKitPersonalityDictionary objectForKey:@"IOProviderMergeProperties"];
}
}

// Get the closest model and use the power entries for it
if (![appDelegate tryGetNearestModel:[ioUSBHostIOKitPersonalities allKeys] modelIdentifier:appDelegate.modelIdentifier nearestModelIdentifier:&nearestModelIdentifier])
if (ioUSBHostIOProviderMergePropertiesDictionary == nil)
return false;

//NSLog(@"nearestModelIdentifier: %@", nearestModelIdentifier);

NSDictionary *ioUSBHostIOKitPersonalityDictionary = [ioUSBHostIOKitPersonalities objectForKey:nearestModelIdentifier];
NSDictionary *ioUSBHostIOProviderMergePropertiesDictionary = [ioUSBHostIOKitPersonalityDictionary objectForKey:@"IOProviderMergeProperties"];


NSNumber *sleepPortCurrentLimit = [ioUSBHostIOProviderMergePropertiesDictionary objectForKey:@"kUSBSleepPortCurrentLimit"];
NSNumber *sleepPowerSupply = [ioUSBHostIOProviderMergePropertiesDictionary objectForKey:@"kUSBSleepPowerSupply"];
NSNumber *wakePortCurrentLimit = [ioUSBHostIOProviderMergePropertiesDictionary objectForKey:@"kUSBWakePortCurrentLimit"];
NSNumber *wakePowerSupply = [ioUSBHostIOProviderMergePropertiesDictionary objectForKey:@"kUSBWakePowerSupply"];

[ioProviderMergePropertiesDictionary setObject:sleepPortCurrentLimit forKey:@"kUSBSleepPortCurrentLimit"];
[ioProviderMergePropertiesDictionary setObject:sleepPowerSupply forKey:@"kUSBSleepPowerSupply"];
[ioProviderMergePropertiesDictionary setObject:wakePortCurrentLimit forKey:@"kUSBWakePortCurrentLimit"];
[ioProviderMergePropertiesDictionary setObject:wakePowerSupply forKey:@"kUSBWakePowerSupply"];

return true;
}

Expand Down Expand Up @@ -558,24 +627,29 @@ void addUSBDictionary(AppDelegate *appDelegate, NSMutableDictionary *ioKitPerson

uint32_t port = propertyToUInt32([usbEntryDictionary objectForKey:@"port"]);
NSString *hubName = [usbEntryDictionary objectForKey:@"HubName"];
bool isHub = (hubName != nil);
NSNumber *hubLocation = [usbEntryDictionary objectForKey:@"HubLocation"];
NSString *modelEntryName = [NSString stringWithFormat:@"%@-%@", appDelegate.modelIdentifier, usbController];
NSString *providerClass = (hubName != nil ? hubName : [usbEntryDictionary objectForKey:@"UsbControllerIOClass"]);
//NSString *providerClass = (hubName != nil ? hubName : ([usbController hasPrefix:@"XH"] ? @"AppleUSBXHCIPCI" : @"AppleUSBEHCIPCI"));
NSString *providerClass = (isHub ? hubName : [usbEntryDictionary objectForKey:@"UsbControllerIOClass"]);

// For hub's we'll append "-internal-hub"
if (hubName != nil)
if (isHub)
modelEntryName = [modelEntryName stringByAppendingString:@"-internal-hub"];

// For unknown controllers we'll append "-VID_PID"
if ([usbController hasPrefix:@"XH"] && usbControllerLocationID != 0x14)
else if (isControllerNameXHC(usbController) && !isControllerLocationXHC(usbControllerLocationID))
modelEntryName = [modelEntryName stringByAppendingFormat:@"-%@", deviceName];

if ([usbController hasPrefix:@"EH"] && usbControllerLocationID != 0x1a && usbControllerLocationID != 0x1d)
else if (isControllerNameEH1(usbController) && !isControllerLocationEH1(usbControllerLocationID))
modelEntryName = [modelEntryName stringByAppendingFormat:@"-%@", deviceName];
else if (isControllerNameEH2(usbController) && !isControllerLocationEH2(usbControllerLocationID))
modelEntryName = [modelEntryName stringByAppendingFormat:@"-%@", deviceName];

if (providerClass == nil)
providerClass = ([usbController hasPrefix:@"XH"] ? @"AppleUSBXHCIPCI" : @"AppleUSBEHCIPCI");
{
if (isControllerNameXHC(usbController))
providerClass = @"AppleUSBXHCIPCI";
else if (isControllerNameEH1(usbController) || isControllerNameEH2(usbController))
providerClass = @"AppleUSBEHCIPCI";
}

NSMutableDictionary *modelEntryDictionary = [ioKitPersonalities objectForKey:modelEntryName];
NSMutableDictionary *ioProviderMergePropertiesDictionary = nil;
Expand All @@ -592,7 +666,7 @@ void addUSBDictionary(AppDelegate *appDelegate, NSMutableDictionary *ioKitPerson
[ioProviderMergePropertiesDictionary setObject:portsDictionary forKey:@"ports"];

// For HUB's
if (hubName != nil)
if (isHub)
{
[modelEntryDictionary setObject:@"com.apple.driver.AppleUSBHostMergeProperties" forKey:@"CFBundleIdentifier"];
[modelEntryDictionary setObject:@"AppleUSBHostMergeProperties" forKey:@"IOClass"];
Expand All @@ -608,7 +682,7 @@ void addUSBDictionary(AppDelegate *appDelegate, NSMutableDictionary *ioKitPerson
}
else
{
if (!injectUSBPowerProperties(appDelegate, ioProviderMergePropertiesDictionary))
if (!injectUSBPowerProperties(appDelegate, usbControllerLocationID, isHub, ioProviderMergePropertiesDictionary))
injectDefaultUSBPowerProperties(ioProviderMergePropertiesDictionary);

[modelEntryDictionary setObject:@"com.apple.driver.AppleUSBMergeNub" forKey:@"CFBundleIdentifier"];
Expand Down Expand Up @@ -832,18 +906,19 @@ void exportUSBPortsSSDT(AppDelegate *appDelegate)
if (usbControllerID != 0)
{
// For unknown controllers we'll append VID/PID
if ([usbController hasPrefix:@"XH"] && usbControllerLocationID != 0x14)
if (isControllerNameXHC(usbController) && !isControllerLocationXHC(usbControllerLocationID))
name = deviceName;

if ([usbController hasPrefix:@"EH"] && usbControllerLocationID != 0x1a && usbControllerLocationID != 0x1d)
else if (isControllerNameEH1(usbController) && !isControllerLocationEH1(usbControllerLocationID))
name = deviceName;
else if (isControllerNameEH2(usbController) && !isControllerLocationEH2(usbControllerLocationID))
name = deviceName;
}

if (locationID != nil)
{
if ([locationID unsignedIntValue] == 0x1D100000)
if (isPortLocationHUB1([locationID unsignedIntValue]))
name = @"HUB1";
else if ([locationID unsignedIntValue] == 0x1A100000)
else if (isPortLocationHUB2([locationID unsignedIntValue]))
name = @"HUB2";
}

Expand All @@ -861,12 +936,14 @@ void exportUSBPortsSSDT(AppDelegate *appDelegate)
{
NSMutableDictionary *usbEntryDictionary = [portsDictionary objectForKey:portKey];

NSString *portName = [usbEntryDictionary objectForKey:@"name"];
NSNumber *portType = [usbEntryDictionary objectForKey:@"portType"];
NSNumber *usbConnector = [usbEntryDictionary objectForKey:@"UsbConnector"];
NSData *port = [usbEntryDictionary objectForKey:@"port"];

[ssdtUIACString appendString:[NSString stringWithFormat:@" \"%@\", Package()\n", portKey]];
[ssdtUIACString appendString:@" {\n"];
[ssdtUIACString appendString:[NSString stringWithFormat:@" \"name\", Buffer() { \"%@\" },\n", portName]];
if (portType != nil)
[ssdtUIACString appendString:[NSString stringWithFormat:@" \"portType\", %d,\n", [portType unsignedIntValue]]];
else if (usbConnector != nil)
Expand Down Expand Up @@ -906,3 +983,49 @@ void exportUSBPorts(AppDelegate *appDelegate)
exportUSBPortsKext(appDelegate);
exportUSBPortsSSDT(appDelegate);
}

bool isControllerLocationXHC(uint32_t usbControllerLocationID)
{
return (usbControllerLocationID == 0x14);
}

bool isControllerLocationEH1(uint32_t usbControllerLocationID)
{
return (usbControllerLocationID == 0x1D);
}

bool isControllerLocationEH2(uint32_t usbControllerLocationID)
{
return (usbControllerLocationID == 0x1A);
}

bool isControllerNameXHC(NSString *controllerName)
{
NSArray *controllerArray = @[@"XHCI", @"XHC1", @"XHC"];

return ([controllerArray indexOfObject:controllerName] != NSNotFound);
}

bool isControllerNameEH1(NSString *controllerName)
{
NSArray *controllerArray = @[@"EHC1", @"EH01"];

return ([controllerArray indexOfObject:controllerName] != NSNotFound);
}

bool isControllerNameEH2(NSString *controllerName)
{
NSArray *controllerArray = @[@"EHC2", @"EH02"];

return ([controllerArray indexOfObject:controllerName] != NSNotFound);
}

bool isPortLocationHUB1(uint32_t locationID)
{
return (locationID == 0x1D100000);
}

bool isPortLocationHUB2(uint32_t locationID)
{
return (locationID == 0x1A100000);
}
Loading

0 comments on commit 7ceccac

Please sign in to comment.