corpnewt / USBMap

Python script for mapping USB ports in macOS and creating a custom injector kext.
MIT License
1.06k stars 89 forks source link

ACPI rename not working for not unique controllers #16

Closed boyuanx closed 3 years ago

boyuanx commented 4 years ago

For example, I have:

Current Controllers:

 - XHC@14 @ _SB.PCI0.XHC (Not Unique)
  \-> RHUB @ _SB.PCI0.XHC.RHUB
 -  XHC@0 @ _SB.PCI0.RP13.PXSX.TBDU.XHC (Not Unique)
  \-> RHUB @ _SB.PCI0.RP13.PXSX.TBDU.XHC.RHUB

Neither option A nor H fixes this issue.

corpnewt commented 3 years ago

Options A and H only generate the ACPI source code. That code needs to be compiled, added to the EFI, and added to the config.plist in order to function.

Given the recent move to IOPathMatch over IONameMatch, renaming any non-unique controllers is no longer a requirement.

-CorpNewt

startergo commented 3 years ago
Current Controllers:

 - pci1b21,2142@0 @ _SB.PCI0.IOU1.PXS2
  \-> RHUB @ _SB.PCI0.IOU1.PXS2.APPLEUSBXHCIPCI
 - pci1b21,2142@0 @ Unknown ACPI Path
 -        UHC4@1A @ _SB.PCI0.UHC4
 -      UHC5@1A,1 @ _SB.PCI0.UHC5
 -      UHC6@1A,2 @ _SB.PCI0.UHC6
 -      EHC2@1A,7 @ _SB.PCI0.EHC2 (Needs Rename)
 -        UHC1@1D @ _SB.PCI0.UHC1
 -      UHC2@1D,1 @ _SB.PCI0.UHC2
 -      UHC3@1D,2 @ _SB.PCI0.UHC3
 -      EHC1@1D,7 @ _SB.PCI0.EHC1 (Needs Rename)

D. Discover Ports (Will Ignore Invalid Controllers)
P. Edit & Create USBMap.kext (Must Discover Ports First)
R. Reset All Detected Ports
A. Generate ACPI Renames For Conflicting Controllers
L. Generate Plist Renames For Conflicting Controllers
H. Generate ACPI To Reset RHUBs (May Conflict With Existing SSDT-USB-Reset.aml!)
 #                Discover USB Ports                   #
#######################################################

    ----- pci1b21,2142@0 Controller -----
1. AppleUSB30XHCIPort | 01000000 | 01100000
2. AppleUSB30XHCIPort | 02000000 | 01200000
3. AppleUSB20XHCIPort | 03000000 | 01300000
4. AppleUSB20XHCIPort | 04000000 | 01400000
    - iPad
    ----- pci1b21,2142@0 Controller -----
5. AppleUSB30XHCIPort | 01000000 | 00100000
6. AppleUSB30XHCIPort | 02000000 | 00200000
7. AppleUSB20XHCIPort | 03000000 | 00300000
8. AppleUSB20XHCIPort | 04000000 | 00400000
    ----- UHC4@1A Controller -----
9. AppleUSBUHCIPort | 01000000 | 1a100000
10. AppleUSBUHCIPort | 02000000 | 1a200000
    ----- UHC5@1A,1 Controller -----
11. AppleUSBUHCIPort | 01000000 | 3a100000
12. AppleUSBUHCIPort | 02000000 | 3a200000
    ----- UHC6@1A,2 Controller -----
13. AppleUSBUHCIPort | 01000000 | 5a100000
    - Bluetooth USB Host Controller
14. AppleUSBUHCIPort | 02000000 | 5a200000
    ----- UHC1@1D Controller -----
15. AppleUSBUHCIPort | 01000000 | 1d100000
16. AppleUSBUHCIPort | 02000000 | 1d200000
    ----- UHC2@1D,1 Controller -----
17. AppleUSBUHCIPort | 01000000 | 3d100000
18. AppleUSBUHCIPort | 02000000 | 3d200000
    ----- UHC3@1D,2 Controller -----
19. AppleUSBUHCIPort | 01000000 | 5d100000
20. AppleUSBUHCIPort | 02000000 | 5d200000

Populated:
AppleUSBXHCIPCI: 1, AppleUSBXHCIPCI: 0, UHC4: 0, UHC5: 0, UHC6: 1, UHC1: 0, UHC2: 0, UHC3: 0

Press Q then [enter] to stop
Checking EHC2@fa000000...
 - EHCI device
 - ACPI Path: _SB.PCI0.EHC2
 --> ACPI Parent Path: _SB.PCI0
 - ACPI _ADR: Zero
 - Gathering unique name...
 --> Got EH01
Checking EHC1@fd000000...
 - EHCI device
 - ACPI Path: _SB.PCI0.EHC1
 --> ACPI Parent Path: _SB.PCI0
 - ACPI _ADR: Zero
 - Gathering unique name...
 --> Got EH02
Building SSDT-USB-Reset.dsl...
Saving to SSDT-USB-Reset.dsl...

Done.
  #######################################################
 #                    Reset RHUBs                      #
#######################################################

Building SSDT-RHUB-Reset.dsl...
Resetting _SB.PCI0.IOU1.PXS2.APPLEUSBXHCIPCI...
Saving to SSDT-RHUB-Reset.dsl...

Done.

Press [enter] to return to the menu...

Well done! Now the code works all the way. Lets see if it operates as designed.

startergo commented 3 years ago

As before the generated SSDT cannot compile as it is:

//
// SSDT to reset RHUB devices on XHCI controllers to force hardware querying of ports
//
// WARNING: May conflict with existing SSDT-USB-Reset!  Verify names and paths before
//          merging!
//
DefinitionBlock ("", "SSDT", 2, "CORP", "RHBReset", 0x00001000)
{
    /*
     * Start copying here if you're adding this info to an existing SSDT-USB-Reset!
     */

    External (_SB.PCI0.IOU1.PXS2.APPLEUSBXHCIPCI, DeviceObj)

    Scope(_SB.PCI0.IOU1.PXS2.APPLEUSBXHCIPCI)
    {
        Method (_STA, 0, NotSerialized)  // _STA: Status
        {
            If (_OSI ("Darwin"))
            {
                Return (Zero)
            }
            Else
            {
                Return (0x0F)
            }
        }
    }

    /*
     * End copying here if you're adding this info to an SSDT-USB-Reset!
     */
}
startergo commented 3 years ago

This compiles:

//
// SSDT to reset RHUB devices on XHCI controllers to force hardware querying of ports
//
// WARNING: May conflict with existing SSDT-USB-Reset!  Verify names and paths before
//          merging!
//
DefinitionBlock ("", "SSDT", 2, "CORP", "RHBReset", 0x00001000)
{
    /*
     * Start copying here if you're adding this info to an existing SSDT-USB-Reset!
     */

    External (_SB.PCI0.IOU1.PXS2.RHUB, DeviceObj)

    Scope(_SB.PCI0.IOU1.PXS2.RHUB)
    {
        Method (_STA, 0, NotSerialized)  // _STA: Status
        {
            If (_OSI ("Darwin"))
            {
                Return (Zero)
            }
            Else
            {
                Return (0x0F)
            }
        }
    }

    /*
     * End copying here if you're adding this info to an SSDT-USB-Reset!
     */
}
startergo commented 3 years ago

Compiler does not like more than 4 characters in the path.

corpnewt commented 3 years ago

Correct - is there a reason you're trying to reset that RHUB? In my experience, if the device is displayed using pciXXXX,YYYY@ addressing, and the RHUB is shown as the USB class, then the RHUB and device likely aren't defined in ACPI at all (or very minimally) - meaning a reset won't do anything for them, as there's nothing to reset.

-CorpNewt

startergo commented 3 years ago

Ok so we don't need the USB and RHUB reset SSDT's anymore? Just the compiled kext?

corpnewt commented 3 years ago

It depends entirely on the situation. If your USB controller and RHUB are defined in ACPI, but lack complete information (some ports not defined, dead ports defined, etc) then resetting the RHUB forces the OS to query the controller directly for which ports it has. You can also now generate config.plist renames for controllers to avoid matching built-in injectors (EHC1, EHC2, XHC1, etc).

-CorpNewt

startergo commented 3 years ago

I am on a cMP5,1. RHUB is not even defined in ACPI. Instead I have PCI0: image

corpnewt commented 3 years ago

With it not being defined in ACPI, the hardware should already be queried directly, rendering a reset unnecessary.

-CorpNewt