Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomPciSerialDevice quirk doesn't work with default RegisterStride #2003

Closed
joevt opened this issue May 3, 2022 · 4 comments
Closed

CustomPciSerialDevice quirk doesn't work with default RegisterStride #2003

joevt opened this issue May 3, 2022 · 4 comments

Comments

@joevt
Copy link

joevt commented May 3, 2022

I have updated my iMac14,2 to OpenCore 0.8.0 (config converted from OCLP 0.4.4 to OpenCore 0.8.0). I am attempting to do macOS xnu serial kprintf for the first time from this computer using a PCIe serial port card in a Thunderbolt enclosure.

Issue 1

The first issue is that FindSerialPort.command is not outputting the result. The following change should fix that.
Find:

fi

Replace:

else
  echo "$serial_dev"
fi

FYI, The output for a PCIe Serial Port in a Thunderbolt enclosure looks like this:

/Volumes/EFINVME/OpenCore-0/Utilities/FindSerialPort/FindSerialPort.command
/PCI0@0/RP05@1C,4/UPSB@0/DSB1@3/UPS0@0/pci-bridge@1/pci-bridge@0/pci-bridge@1/pci125b,9100@0
PciRoot(0x0)/Pci(0x1c,0x4)/Pci(0x0,0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)
xxd -p -r <<< "1c 04 00 00 00 00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 FF" | base64

/PCI0@0/RP05@1C,4/UPSB@0/DSB1@3/UPS0@0/pci-bridge@1/pci-bridge@0/pci-bridge@1/pci125b,9100@0,2
PciRoot(0x0)/Pci(0x1c,0x4)/Pci(0x0,0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)/Pci(0x1,0x0)/Pci(0x0,0x2)
xxd -p -r <<< "1c 04 00 00 00 00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 02 00 00 FF" | base64

The PCIe card has two serial ports, so there's two device paths in the result. I am using the first device path. It has 33 bytes which fits in the 40 byte limit. There's an extra pci-bridge since I'm using a Sonnet Echo Express III-D which has 3 slots.

Main Issue

The main issue is that the OpenCore CustomPciSerialDevice quirk doesn't do anything if the RegisterStride is 1. To fix this, make the following changes:

Find in CommonPatches.c:

  if ((mPmioRegisterBase != 0 && mPmioRegisterStride > 1)

Replace with:

  if ((mPmioRegisterBase != 0 && mPmioRegisterStride != 0)

Find in OcConfigurationLib.c:

      if ((RegisterBase != 0 && RegisterStride > 1)
        && RegisterBase != 0x3F8U) {

Replace with:

      if ((RegisterBase != 0 && RegisterStride != 0)
        && (RegisterBase != 0x3F8U || RegisterStride != 1)) {

Other Thunderbolt PCIe serial port notes

Apple's serial port driver Apple16X50Serial.kext doesn't have IOPCITunnelCompatible set to true except for a pair of PCIe cards:
https://pci-ids.ucw.cz/read/PC/1415/c101
https://pci-ids.ucw.cz/read/PC/1d0f 8250
so my PCIe card https://pci-ids.ucw.cz/read/PC/125b/9100 is not automatically enabled while in a Thunderbolt enclosure.

For Thunderbolt, I suppose a code-less kext can be made to enable any PCIe serial port card by defining an IOKit personality that matches the PCIe card using IONameMatch or IOPCIMatch (or any PCIe serial port with IOPCIClassMatch) and sets IOPCITunnelCompatible to true and points to the Apple16X50Serial binary. Add additional matching criteria so that the serial port that is used for xnu serial kprintf is not matched. Or add an IOKit personality that matches the serial port that is used by xnu and make that personality point to IOService instead of Apple16X50Serial binary and make it have a higher probe score (like the PCIeSerialDisable.kext example mentioned in the OpenCore Reference Manual).

PMheart added a commit to acidanthera/OpenCorePkg that referenced this issue May 3, 2022
PMheart added a commit to acidanthera/OpenCorePkg that referenced this issue May 3, 2022
@PMheart
Copy link
Member

PMheart commented May 3, 2022

Hello! Thanks for providing the fixes. I have applied them.

As for the codeless kext, could you please provide a new one? Since I am not familiar with that, I am not sure whether I can follow.

@joevt
Copy link
Author

joevt commented May 3, 2022

I've attached the code-less kexts. PCIeSerial code-less kexts.zip

PCIeSerialThunderboltEnable.kext will enable any PCIe serial port (PCI device class 7, sub-class 0) that is connected with Thunderbolt.

For PCIeSerialDisable.kext, I needed to add a IOPCITunnelCompatible for it to match a PCIe serial port in a Thunderbolt enclosure.

I was unable to use PCIeSerialThunderboltEnable.kext to enable one port for macOS while using PCIeSerialDisable.kext to disable the other port that is used for xnu kernel serial kprintf. The kernel stops printing to the serial port - the problem that PCIeSerialDisable.kext was supposed to prevent. Therefore, it may be necessary to not use PCIeSerialThunderboltEnable.kext if you want xnu to use a Thunderbolt serial port. In that case, PCIeSerialDisable.kext won't be necessary unless you have one of the PCIe serial port cards that works from Thunderbolt without PCIeSerialThunderboltEnable.kext.

Other Thunderbolt PCIe serial port notes part 2

If the Thunderbolt device goes to sleep, it may alter the serial port settings when it wakes so that you can no longer get readable serial data from xnu. In that case, you may want to disable sleep, or find a method that allows sleep without sleeping the Thunderbolt device. If you use PCIeSerialThunderboltEnable.kext without PCIeSerialDisable.kext then a serial program can fix the serial port settings, but you also have to do that every time you boot since Apple16X50Serial stops serial output when it loads. I suppose a kext can be used to reinitialize the serial port after wake, or after boot but allowing sleep/wake of the serial port would make it difficult to use serial kprintf to debug sleep/wake issues.

@PMheart
Copy link
Member

PMheart commented May 9, 2022

Hello! Thanks for the late response. I have added link to your posts here for the new codeless kexts at acidanthera/OpenCorePkg@59fd524. Since it is kind of pointless to repeat your words in Configuration.pdf, I have only written brief introductions and put a link here.

Shall we close this now?

@joevt
Copy link
Author

joevt commented May 10, 2022

Yes, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants