Skip to content

Commit

Permalink
Remove EC renames and use OC SSDT-EC-USBX as template
Browse files Browse the repository at this point in the history
  • Loading branch information
benbaker76 committed Apr 4, 2020
1 parent eff889b commit 624699e
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 38 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 = 0336;
CURRENT_PROJECT_VERSION = 0337;
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.6;
MARKETING_VERSION = 3.3.7;
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 = 0336;
CURRENT_PROJECT_VERSION = 0337;
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.6;
MARKETING_VERSION = 3.3.7;
PRODUCT_BUNDLE_IDENTIFIER = com.Headsoft.Hackintool;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Binary file not shown.
166 changes: 132 additions & 34 deletions Hackintool/USB.m
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,58 @@ void injectUSBControllerProperties(AppDelegate *appDelegate, NSMutableDictionary
}
}

bool getECName(AppDelegate *appDelegate, NSString **ecName)
{
io_iterator_t iterator;

kern_return_t kr = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("IOACPIPlatformDevice"), &iterator);

if (kr != KERN_SUCCESS)
return false;

for (io_service_t device; IOIteratorIsValid(iterator) && (device = IOIteratorNext(iterator)); IOObjectRelease(device))
{
io_name_t name {};
kr = IORegistryEntryGetName(device, name);

if (kr != KERN_SUCCESS)
continue;

if ([[NSString stringWithUTF8String:name] isEqualToString:@"EC"])
continue;

CFMutableDictionaryRef propertyDictionaryRef = 0;

kr = IORegistryEntryCreateCFProperties(device, &propertyDictionaryRef, kCFAllocatorDefault, kNilOptions);

if (kr != KERN_SUCCESS)
continue;

NSMutableDictionary *propertyDictionary = (__bridge NSMutableDictionary *)propertyDictionaryRef;

NSData *propertyValue = [propertyDictionary objectForKey:@"name"];

if (propertyValue == nil)
continue;

NSString *nameEntry = [NSString stringWithCString:(const char *)[propertyValue bytes] encoding:NSASCIIStringEncoding];

if ([nameEntry isEqualToString:@"PNP0C09"])
{
*ecName = [NSString stringWithUTF8String:name];

IOObjectRelease(iterator);
IOObjectRelease(device);

return true;
}
}

IOObjectRelease(iterator);

return false;
}

ECType checkEC(AppDelegate *appDelegate)
{
// An EC device is needed so AppleBusPowerController attaches to it and injects
Expand Down Expand Up @@ -726,43 +778,94 @@ void addUSBDictionary(AppDelegate *appDelegate, NSMutableDictionary *ioKitPerson
}
}

void exportUSBPowerSSDT(AppDelegate *appDelegate, NSMutableDictionary *ioProviderMergePropertiesDictionary)
void exportUSBPowerSSDT(AppDelegate *appDelegate)
{
NSMutableString *ssdtUSBXString = [NSMutableString string];

NSNumber *sleepPortCurrentLimit = [ioProviderMergePropertiesDictionary objectForKey:@"kUSBSleepPortCurrentLimit"];
NSNumber *sleepPowerSupply = [ioProviderMergePropertiesDictionary objectForKey:@"kUSBSleepPowerSupply"];
NSNumber *wakePortCurrentLimit = [ioProviderMergePropertiesDictionary objectForKey:@"kUSBWakePortCurrentLimit"];
NSNumber *wakePowerSupply = [ioProviderMergePropertiesDictionary objectForKey:@"kUSBWakePowerSupply"];
[ssdtUSBXString appendString:@"DefinitionBlock (\"\", \"SSDT\", 2, \"ACDT\", \"SsdtEC\", 0)\n"];
[ssdtUSBXString appendString:@"{\n"];
[ssdtUSBXString appendString:@" External (_SB_.PCI0.LPCB, DeviceObj)\n"];

if (sleepPortCurrentLimit == nil || sleepPowerSupply == nil || wakePortCurrentLimit == nil || wakePowerSupply == nil)
return;
NSString *ecName = nil;

[ssdtUSBXString appendString:@"DefinitionBlock (\"\", \"SSDT\", 2, \"hack\", \"_USBX\", 0)\n"];
[ssdtUSBXString appendString:@"{\n"];
[ssdtUSBXString appendString:@" Device(_SB.USBX)\n"];
if (getECName(appDelegate, &ecName))
{
[ssdtUSBXString appendFormat:@" External (_SB_.PCI0.LPCB.%@, DeviceObj)\n", ecName];
[ssdtUSBXString appendString:@"\n"];
[ssdtUSBXString appendFormat:@" Scope (\\_SB.PCI0.LPCB.%@)\n", ecName];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Method (_STA, 0, NotSerialized) // _STA: Status\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" If (_OSI (\"Darwin\"))\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Return (0)\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" Else\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Return (0x0F)\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" }\n"];
}

[ssdtUSBXString appendString:@"\n"];
[ssdtUSBXString appendString:@" Scope (\\_SB)\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Name(_ADR, 0)\n"];
[ssdtUSBXString appendString:@" Method (_DSM, 4)\n"];

[ssdtUSBXString appendString:@" Device (USBX)\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Name (_ADR, Zero) // _ADR: Address\n"];
[ssdtUSBXString appendString:@" Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" If ((Arg2 == Zero))\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Return (Buffer (One)\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" 0x03 // .\n"];
[ssdtUSBXString appendString:@" })\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@"\n"];
[ssdtUSBXString appendString:@" Return (Package (0x08)\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" \"kUSBSleepPowerSupply\",\n"];
[ssdtUSBXString appendString:@" 0x13EC,\n"];
[ssdtUSBXString appendString:@" \"kUSBSleepPortCurrentLimit\",\n"];
[ssdtUSBXString appendString:@" 0x0834,\n"];
[ssdtUSBXString appendString:@" \"kUSBWakePowerSupply\",\n"];
[ssdtUSBXString appendString:@" 0x13EC,\n"];
[ssdtUSBXString appendString:@" \"kUSBWakePortCurrentLimit\",\n"];
[ssdtUSBXString appendString:@" 0x0834\n"];
[ssdtUSBXString appendString:@" })\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" }\n"];

[ssdtUSBXString appendString:@"\n"];
[ssdtUSBXString appendString:@" Scope (\\_SB.PCI0.LPCB)\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" If (!Arg2) { Return (Buffer() { 0x03 } ) }\n"];
[ssdtUSBXString appendString:@" Return (Package()\n"];
[ssdtUSBXString appendString:@" Device (EC)\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:[NSString stringWithFormat:@" \"kUSBSleepPortCurrentLimit\", %d,\n", [sleepPortCurrentLimit unsignedIntValue]]];
[ssdtUSBXString appendString:[NSString stringWithFormat:@" \"kUSBSleepPowerSupply\", %d,\n", [sleepPowerSupply unsignedIntValue]]];
[ssdtUSBXString appendString:[NSString stringWithFormat:@" \"kUSBWakePortCurrentLimit\", %d,\n", [wakePortCurrentLimit unsignedIntValue]]];
[ssdtUSBXString appendString:[NSString stringWithFormat:@" \"kUSBWakePowerSupply\", %d,\n", [wakePowerSupply unsignedIntValue]]];
[ssdtUSBXString appendString:@" })\n"];
[ssdtUSBXString appendString:@" Name (_HID, \"ACID0001\") // _HID: Hardware ID\n"];
[ssdtUSBXString appendString:@" Method (_STA, 0, NotSerialized) // _STA: Status\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" If (_OSI (\"Darwin\"))\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Return (0x0F)\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" Else\n"];
[ssdtUSBXString appendString:@" {\n"];
[ssdtUSBXString appendString:@" Return (Zero)\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@" }\n"];
[ssdtUSBXString appendString:@"}\n"];

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *iaslPath = [mainBundle pathForResource:@"iasl" ofType:@"" inDirectory:@"Utilities"];
NSString *desktopPath = [NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *tempPath = getTempPath();
NSString *tempFilePath = [NSString stringWithFormat:@"%@/SSDT-USBX.dsl", tempPath];
NSString *outputFilePath = [NSString stringWithFormat:@"%@/SSDT-USBX.aml", desktopPath];
NSString *tempFilePath = [NSString stringWithFormat:@"%@/SSDT-EC-USBX.dsl", desktopPath];
NSString *outputFilePath = [NSString stringWithFormat:@"%@/SSDT-EC-USBX.aml", desktopPath];
NSString *stdoutString = nil;

if ([[NSFileManager defaultManager] fileExistsAtPath:tempFilePath])
Expand All @@ -773,7 +876,6 @@ void exportUSBPowerSSDT(AppDelegate *appDelegate, NSMutableDictionary *ioProvide
[ssdtUSBXString writeToFile:tempFilePath atomically:YES encoding:NSUTF8StringEncoding error:&error];

launchCommand(iaslPath, @[@"-p", outputFilePath, tempFilePath], &stdoutString);
//NSLog(@"%@", stdoutString);

NSArray *fileURLs = [NSArray arrayWithObjects:[NSURL fileURLWithPath:outputFilePath], nil];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
Expand Down Expand Up @@ -842,7 +944,7 @@ void exportUSBPortsKext(AppDelegate *appDelegate)
[usbEntryDictionary removeObjectForKey:@"HubName"];
[usbEntryDictionary removeObjectForKey:@"HubLocation"];
[usbEntryDictionary removeObjectForKey:@"DevSpeed"];
[usbEntryDictionary removeObjectForKey:@"Comment"];
//[usbEntryDictionary removeObjectForKey:@"Comment"];
}
}

Expand All @@ -866,13 +968,12 @@ void exportUSBPortsKext(AppDelegate *appDelegate)

void exportUSBPortsSSDT(AppDelegate *appDelegate)
{
bool hasExportedUSBPowerSSDT = NO;
NSMutableDictionary *ioKitPersonalities = [NSMutableDictionary dictionary];
NSMutableString *ssdtUIACString = [NSMutableString string];

addUSBDictionary(appDelegate, ioKitPersonalities);

[ssdtUIACString appendString:@"DefinitionBlock (\"\", \"SSDT\", 2, \"hack\", \"_UIAC\", 0)\n"];
[ssdtUIACString appendString:@"DefinitionBlock (\"\", \"SSDT\", 2, \"ACDT\", \"_UIAC\", 0)\n"];
[ssdtUIACString appendString:@"{\n"];
[ssdtUIACString appendString:@" Device(UIAC)\n"];
[ssdtUIACString appendString:@" {\n"];
Expand Down Expand Up @@ -900,13 +1001,6 @@ void exportUSBPortsSSDT(AppDelegate *appDelegate)
NSData *portCount = [ioProviderMergePropertiesDictionary objectForKey:@"port-count"];
NSMutableDictionary *portsDictionary = [ioProviderMergePropertiesDictionary objectForKey:@"ports"];

if (!hasExportedUSBPowerSSDT)
{
exportUSBPowerSSDT(appDelegate, ioProviderMergePropertiesDictionary);

hasExportedUSBPowerSSDT = YES;
}

if (usbControllerID != 0)
{
// For unknown controllers we'll append VID/PID
Expand Down Expand Up @@ -944,6 +1038,7 @@ void exportUSBPortsSSDT(AppDelegate *appDelegate)
NSNumber *portType = [usbEntryDictionary objectForKey:@"portType"];
NSNumber *usbConnector = [usbEntryDictionary objectForKey:@"UsbConnector"];
NSData *port = [usbEntryDictionary objectForKey:@"port"];
NSString *comment = [usbEntryDictionary objectForKey:@"Comment"];

[ssdtUIACString appendString:[NSString stringWithFormat:@" \"%@\", Package()\n", portKey]];
[ssdtUIACString appendString:@" {\n"];
Expand All @@ -953,6 +1048,8 @@ void exportUSBPortsSSDT(AppDelegate *appDelegate)
else if (usbConnector != nil)
[ssdtUIACString appendString:[NSString stringWithFormat:@" \"UsbConnector\", %d,\n", [usbConnector unsignedIntValue]]];
[ssdtUIACString appendString:[NSString stringWithFormat:@" \"port\", Buffer() { %@ },\n", getByteString(port)]];
if (comment != nil)
[ssdtUIACString appendString:[NSString stringWithFormat:@" \"Comment\", Buffer() { \"%@\" },\n", comment]];
[ssdtUIACString appendString:@" },\n"];
}

Expand Down Expand Up @@ -983,9 +1080,10 @@ void exportUSBPortsSSDT(AppDelegate *appDelegate)

void exportUSBPorts(AppDelegate *appDelegate)
{
validateUSBPower(appDelegate);
//validateUSBPower(appDelegate);
exportUSBPortsKext(appDelegate);
exportUSBPortsSSDT(appDelegate);
exportUSBPowerSSDT(appDelegate);
}

bool isControllerLocationXHC(uint32_t usbControllerLocationID)
Expand Down
Empty file modified Resources/ACPI/SSDT-USBX.dsl
100755 → 100644
Empty file.

0 comments on commit 624699e

Please sign in to comment.