hacker1024 / Dell-Inspiron-7586-Hackintosh

An OpenCore configuration for the Dell Inspiron 7586.
Other
5 stars 0 forks source link

DSDT hotpatch to remove the OSID check in SMEE before calling EV13 (brightness key function) #5

Open hacker1024 opened 2 years ago

hacker1024 commented 2 years ago

As the moment, _OSI patching is required to enable the brightness keys (https://github.com/hacker1024/Dell-Inspiron-7586-Hackintosh/commit/00532c7b94a2dcf84b6a37f366b835f796bf7252). This is not recommended by Dortania, due to the problems it can cause with other operating systems.

It would be better if a DSDT hotpatch was implemented to remove the check. Here's the relevant DSDT code:

Method (SMEE, 1, NotSerialized)
{
    Local0 = Arg0
    Local0 = GENS (0x11, Zero, Zero)
    If ((\_SB.OSID () >= 0x20))
    {
        If ((Local0 & 0x04))
        {
            EV13 (One, Zero)
        }

        If ((Local0 & 0x02))
        {
            EV13 (0x02, Zero)
        }
    }

    If ((Local0 & 0x08))
    {
        Local0 = GENS (0x1D, Zero, Zero)
        EV14 (Local0, Zero)
    }
}

The idea is to change If ((\_SB.OSID () >= 0x20)) to If (One), similarly to the existing I2C patch.

Here's what the binary looks like:

   57801:          If ((\_SB.OSID () >= 0x20))

0003E982:  A0 2A 92 95 ............    ".*.."
0003E986:  5C 2E 5F 53 42 5F 4F 53     "\._SB_OS"
0003E98E:  49 44 0A 20 ............    "ID. "

And with If (One):

   57801:          If (One)

0003E982:  A0 1D 01 ...............    "..."

My initial thought was to simply make a find/replace based on these differing binary snippets. Several variants are possible, depending on the positions of NoopOps:

   Find: A02A9295 5C2E5F53425F4F53 49440A20
Replace: A02A01A3 A3A3A3A3A3A3A3A3 A3A3A3A3
   Find: A02A9295 5C2E5F53425F4F53 49440A20
Replace: A3A3A3A3 A3A3A3A3A3A3A3A3 A3A01D01

My experience with this sort of binary code is mainly in the Android field, with Dalvik opcodes. I'm not sure if instruction alignment is as important in ACPI land as it is in Dalvik, but I think it's possible that one of these patches is invalid due to weird A0 IfOp positions. I need to look into the ACPI specification more.

Neither of these hotpatches work at the moment. When enabled, the "System DSDT" view in MaciASL shows what I expect - If (One) and a bunch of NoopOps - but the brightness keys don't work.

I'm probably misunderstanding the way these binary if statements work. I'll look into the ACPI specification and see if I can work out what's going on, just like @al3xtjames did on Reddit for the I2C patch.

(Btw @al3xtjames, if you notice anything immediately fixable with the patches above, I'd really appreciate your input. I haven't tried very hard myself to solve the problem yet though, so no pressure.)

hacker1024 commented 2 years ago

Weird - with the current fix added in https://github.com/hacker1024/Dell-Inspiron-7586-Hackintosh/commit/00532c7b94a2dcf84b6a37f366b835f796bf7252, the brightness keys stop working if the EC fan control is disabled...