5T33Z0 / OC-Little-Translated

ACPI Hotpatches and Guides for the OpenCore Bootmanager. Enhance and fine-tune your system by adding devices and enabling additional features not covered in the OpenCore Install Guide.
BSD 3-Clause "New" or "Revised" License
504 stars 71 forks source link

Refactor SSDT-PTSWAKTTS.dsl #94

Closed xuanhung1509 closed 7 months ago

xuanhung1509 commented 7 months ago

Eliminate nested If statement, using ChatGPT =))

5T33Z0 commented 7 months ago

In most cases you can't trust ChatGPT when it comes to ACPI. This has to be tested first.

5T33Z0 commented 7 months ago

The table contains errors. And I don't like refactoring just for the sake of refactoring. The way the original table is written is understandable.

Bildschirmfoto 2023-12-10 um 19 36 12

xuanhung1509 commented 7 months ago

Sorry for that, because the nested "If" kinda bothers me when inspecting the code.

Eventually, I decided to drop the DGPU thing (as I already use Dortania Optimus Method to disable dGPU), and all the EXTs that I don't use, and _TTS method that my DSDT doesn't have.

My final version looks like this:

DefinitionBlock ("", "SSDT", 2, "OCLT", "PTSWAK", 0x00000000)
{
    External (ZPTS, MethodObj)    // 1 Arguments
    External (ZWAK, MethodObj)    // 1 Arguments

    Scope (_SB)
    {
        Device (PCI9)
        {
            Name (_ADR, Zero)  // _ADR: Address
            Name (FNOK, Zero)
            Name (MODE, Zero)
            Method (_STA, 0, NotSerialized)  // _STA: Status
            {
                If (_OSI ("Darwin"))
                {
                    Return (0x0F)
                }
                Else
                {
                    Return (Zero)
                }
            }
        }
    }

    Method (_PTS, 1, NotSerialized)  // _PTS: Prepare To Sleep
    {
        If (_OSI ("Darwin"))
        {
            If ((\_SB.PCI9.FNOK == One))
            {
                Arg0 = 0x03
            }
        }

        ZPTS (Arg0)
    }

    Method (_WAK, 1, NotSerialized)  // _WAK: Wake
    {
        If (_OSI ("Darwin"))
        {
            If ((\_SB.PCI9.FNOK == One))
            {
                \_SB.PCI9.FNOK = Zero
                Arg0 = 0x03
            }

            If (((Arg0 < One) || (Arg0 > 0x05)))
            {
                Arg0 = 0x03
            }
        }

        Local0 = ZWAK (Arg0)
        Return (Local0)
    }
}