OcAppleKernelLib: Added CustomPciSerialDevice quirk#331
Conversation
Docs/Configuration.tex
Outdated
| \texttt{CustomPCISerialDevice}\\ | ||
| \textbf{Type}: \texttt{plist\ boolean}\\ | ||
| \textbf{Failsafe}: \texttt{false}\\ | ||
| \textbf{Requirement}: 10.4\\ |
There was a problem hiding this comment.
I am not sure what the minimum requirement is, though the 10.4 makes sense to me.
|
Please add the port getting/setting code, and add the original patch, while @joevt takes time to explain where to insert it. |
CustomPCISerialDevice quirkCustomPciSerialDevice quirk
|
We are discussing a kernel patch that will make the kernel output to a specific PCIe serial port. Applying the patch will not have any affect unless boot-args is setup to make the kernel do serial port output (usually used by The patch is for PCI cards based on the 16x50 serial controller that have an I/O BAR base address register (such as the StarTech PEX2S953). For a built-in serial port, the I/O base is usually 0x3f8. The patch will change this to the I/O base of a specified PCIe card. BaseSerialPortLib16550.c has code for getting the I/O address from the PCIe card that has path PcdSerialPciDeviceInfo. Function GetSerialRegisterBase in BaseSerialPortLib16550.c does a small amount of validation and initialization to make serial output work. The The last node in the PcdSerialPciDeviceInfo path is for the serial port PCIe device. Function GetSerialRegisterBase uses the first I/O BAR for the SerialRegisterBase. Perhaps The final thing that GetSerialRegisterBase does is enable the I/O of the PCI device and the parent PCI bridges. I don't think we need to worry about parent PCI bridges? Just enable the I/O for the PCI device. I don't think we need to worry about the D0 state (at least in my setup; maybe more modern setups need this). My patch (using Kernel -> Patch) replaces Since we are making a quirk, you can add a bit more safety to the search and replace. I/O addresses are read and written to using the In Hopper.app, you can search for matches using this: Are there any kernels that don't use register dx for the port address, or register al for the value? The instructions are from The reason for this patch:
My serial PCIe card does not support the PCIE_MMIO UART method (and that method doesn't exist before macOS 10.14), and the legacy method doesn't have a boot-arg to change the I/O base. Therefore, this patch. This patch can't work if serial_init chooses option 1 (PCH) but you can get around that by having boot-arg So, what CustomPciSerialDevice will do is redirect kernel legacy serial I/O to a PCIe card. For this to work, you also need to make sure that the Apple16X50PCI0 driver does not attach to the serial port because it will stop the serial output. For this I use a code-less kext as described in acidanthera/bugtracker#1954 |
|
In my opinion, we can assume that the serial ports are the same for simplicity of the interface. For a quirk I am not sure that trying to match out/in will be easily doable with the compiler generating different code. For MMIO I think we need to make our patch automatically replace the mmio address too. All in all there should be decent docs in OC describing all this stuff. |
406841b to
9cb8547
Compare
|
With @vit9696's help, I implemented an initial draft of both the PMIO and MMIO patches. As for the PMIO patch, I believe it is safe enough to match the instruction For MMIO, there is one constant Actually, how about debug kernels? To be honest I did not check carefully, but at a glance Under function |
d78833a to
b93f487
Compare
Ok, so Serial -> Init is for OpenCore serial output.
My comments about
Sounds like fun. macOS has boot-args for changing mmio address for the two MMIO options, but you think it would be better if the values came from the BAR registers of the device specified by
That's for the PCH LPSS UART2 option. It's not used if there's a UART at 0xFE0360xx so that should be the register to look for. It has existed in the xnu source code since at least macOS 10.12.6 (I did not check every version of 10.12). Is the PCH LPSS UART2 option usable by BaseSerialPortLib16550.c? Is the PCH LPSS UART2 a PCI device? It seems to have different registers than the PCIE_MMIO UART option - actually the registers are similar but the access width is 32 bits so maybe it can work. For the PCIE_MMIO UART option, the address to modify is 0xFE4100xx.
But there are other places in the kernel that do serial port output (hibernate? stuff) What does PMIO stand for?
If you want to support both MMIO options (LPSS and PCIE), then you need to be able to differentiate between the two. Perform the LPSS patch if For PMIO, check the |
|
@joevt Why would we initialise serial when Init=false? This sounds borked. It’s not “OC serial output” (that should be determined by Debug->Target) but “init serial port”. PMIO is port-mapped I/O. |
Well, this comment is correct. Serial → Init is literally "init serial port", it has nothing to do to the fact whether OC uses serial or not. Perhaps we should separate |
|
We need to at least call GetSerialRegisterBase to ensure that IO or MMIO is enabled for the PCI device and parent PCI bridges. SerialPortInitialize calls GetSerialRegisterBase. If we're not doing serial output in OpenCore, then calling GetSerialRegisterBase should be sufficient, as xnu has its own code that performs initialization and set baud rate. Should we override baud rate and clock since we are overriding base register? |
|
If these patches are contributed, it is ok to me, but otherwise I would act based on the actual need to. |
|
I temporarily removed the MMIO patch, and will go back to it later. @joevt You are indeed correct that UPDATE - I just created a test in out TextKextInject tool at d18c175, and looks like my patch worked correctly by patching both |
|
I ran some statistics. It seems we need a different patch for Mac OS X versions 10.4 to 10.6. I'll have a look. |
|
Thanks. I took a quick glance at 10.4.11 XNU as well, and indeed a different patch is needed. For 10.9, we can just change the max search distance (currently 32) to a higher value. e.g. 64. |
|
I don't think we can do a simple search/replace for 10.4.11. It has optimizations that make it difficult to find. It moves 0x3fb into ebx which is used for the first |
|
This sounds complex. In my opinion, do not bother with 10.4 for now? |
I'm ok with that. The Mavericks 46 byte gap seems benign. Attached is a list of file offsets for non-zero gaps. |
|
OK, thanks. I just increased the maximum search size to 64. Looks fine now? If so, let's go back to the MMIO patch. |
|
Let me know what you would like me to check or test. |
22df918 to
db80694
Compare
This reverts commit 8c965b6.
|
@dakanji This makes sense. Thanks. Renamed. |
|
Looks good |
|
I have only the following two suggestions:
I think this needs to be reworded so that base is not implied to be a range. Rather, base points to the beginning of a range. Also, the patch also works for non PCI serial ports (these may appear as ACPI devices? I have to boot my hackintosh into macOS to be sure). Maybe something like this:
I think the user should know that this patch is for PMIO but they can use MMIO for OpenCore serial output and that there are boot-args to enable MMIO for XNU (but the addresses are not calculated automatically - they need to enter the correct address in boot-args themselves). Maybe this:
|
|
Note that the docs already includes at least one source code level reference ... something about a Tianocore source file. |
|
We can just mention the other boot-args and then the user can search for the source file themselves to learn how they work and how they differ from each other and from the COM1 PMIO option and what version of macOS they work with. MMIO support exists but is not part of this patch so we can be vague about it. MMIO is fully supported for OpenCore but not XNU except for the boot-args which are sufficient for full capability.
|
|
Thanks. I updated the descriptions at Docs: Update quirk description. |
closes acidanthera/bugtracker#1954
After merging:
IsZeroBufferinstead underPatchSetApfsTrimTimeout(off-topic)