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

Enhance VoodooI2CDeviceNub #468

Merged
merged 6 commits into from
Sep 7, 2021
Merged

Enhance VoodooI2CDeviceNub #468

merged 6 commits into from
Sep 7, 2021

Conversation

williambj1
Copy link
Contributor

@williambj1 williambj1 commented Aug 11, 2021

Hi developers! This PR includes enhancements for VoodooI2CDeviceNub.

  1. Support reading I2C Serial Bus declaration from _DSM
    Previously, _DSM will not be evaluated if SBFB (aka "I2C Serial Bus declaration") was not returned in _CRS, here is an example from an Acer Laptop

    Method (_CRS, 0, Serialized)  // _CRS: Current Resource Settings
    {
        Local0 = Zero
        Local1 = Zero
        Local1 = DerefOf (DerefOf (TPID [Local0]) [Zero])
        While (((Local1 != 0xFE) && (Local1 != TPDF)))
        {
            Local0++
            If ((Local0 >= SizeOf (TPID)))
            {
                Break
            }
    
            Local1 = DerefOf (DerefOf (TPID [Local0]) [Zero])
        }
    
        ADR0 = DerefOf (DerefOf (TPID [Local0]) [One])
        HID2 = DerefOf (DerefOf (TPID [Local0]) [0x02])
        If ((OSYS < 0x07DC))
        {
            Return (SBFI) // Returned here
        }
    
        If (Ones)
        {
            Return (ConcatenateResTemplate (SBFB, SBFG))
        }
    
        Return (ConcatenateResTemplate (SBFB, SBFI))
    }

    Current implementation in Repo:

    if (crs_parser.found_i2c) {
    use_10bit_addressing = crs_parser.i2c_info.address_mode_10Bit;
    setProperty("addrWidth", use_10bit_addressing ? 10 : 7, 8);
    i2c_address = crs_parser.i2c_info.address;
    setProperty("i2cAddress", i2c_address, 16);
    setProperty("sclHz", crs_parser.i2c_info.bus_speed, 32);
    } else {
    IOLog("%s::%s Could not find an I2C Serial Bus declaration\n", getName(), acpi_device->getName());
    return kIOReturnNotFound;
    }

  2. Refactor VoodooI2CDeviceNub::getDeviceResources()

  3. Clarify skipping APIC Interrupt mode
    This PR does not change the behavior of skipping interrupts (skips setting gpio values). AFAIK there is no way to avoid APIC interrupts in VoodooI2C (and it doesn't make sense to do so, although it can be accomplished by modifying ACPI), please correct me if I'm wrong.

  4. Slightly adjust logs and macro names

    • Data returned from _DSM using the TP7G index doesn't only contain GPIO resources The macro name was adjusted based on docs from Microsoft; the third argument (Arg2) is always called as the "function index".
    • The log that complains about unsupported index is adjusted since it prints whenever _DSM returns useless data. Calls with any uuid or function indexes will end up printing the line if the evaluation above is not satisfied.

CC @zhen-zen

@williambj1
Copy link
Contributor Author

williambj1 commented Aug 11, 2021

I just realized this PR would break the fallback of choosing _DSM if only SBFB was returned from _CRS. I will fix that ASAP.

Fixed in the latest commit

@GZXiaoBai
Copy link

That's great! I've tried this! Everything is working! I hope this can be adopted.

@VoodooI2C VoodooI2C deleted a comment from mat121212 Aug 14, 2021
@kprinssu
Copy link
Collaborator

kprinssu commented Aug 14, 2021

@williambj1 Please give me some time to review this. I am hoping to do so by Monday evening.

@mat121212 Your comment was deleted due to you asking for compiled kexts and not contributing to the development of this PR. Please keep the discussion to the PR at hand.

@williambj1
Copy link
Contributor Author

williambj1 commented Aug 15, 2021

Sample DSDT that benefits from this patch:

HuaweiMateBook14-origin.zip

Device path: _SB.PCI0.I2C1.TPL1

Copy link
Collaborator

@kprinssu kprinssu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Minor comments and will be good to merge if we can add some documentation on the changes.

By documentation, we should add the sample DSDT code to the Github.io pages.

@williambj1
Copy link
Contributor Author

Thank you for taking your precious time to review my changes!

Good work! Minor comments and will be good to merge if we can add some documentation on the changes.

By documentation, we should add the sample DSDT code to the Github.io pages.

I'm not quite sure how to handle this properly to be honest, as the main goal of this PR is to allow more devices to operate properly without ACPI modifications/hacks.

@kprinssu
Copy link
Collaborator

@ben9923 Can you please take a look? Otherwise, this looks to be good to me and I will merge it in on Thursday.

- Support reading I2C Serial Bus declaration from `_DSM`
- Refactor `VoodooI2CDeviceNub::getDeviceResources()`
- Clarify skipping APIC Interrupt mode
- Slightly adjust logs
@zhen-zen
Copy link
Contributor

zhen-zen commented Aug 22, 2021

@williambj1 Just revisited this issue and I'm not in favor of the rename. Function index is everything you put into the Arg2. It will then call the function at specified index. So there's no official definition other than 0, which is a bitmap indicating available functions. Check 9.1.1 _DSM in ACPI spec.

Copy link
Member

@ben9923 ben9923 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, I like the idea!

Added just a couple of notes, sorry it took me a while to review :)

@kprinssu
Copy link
Collaborator

kprinssu commented Sep 2, 2021

@williambj1 I would love to merge this in but I would like you to address @ben9923's comments before I do so.

@williambj1
Copy link
Contributor Author

@williambj1 I would love to merge this in but I would like you to address @ben9923's comments before I do so.

I apologize for not being able to respond in the past two weeks. I will adopt these suggestions on Sep 6.

@williambj1
Copy link
Contributor Author

@ben9923 I apologize again for not being able to resolve those issues earlier. I think I've covered all of the comments, please have a look :)

@kprinssu
Copy link
Collaborator

kprinssu commented Sep 7, 2021

Thanks @williambj1. This looks good and merging it in.

@kprinssu kprinssu merged commit 385c068 into VoodooI2C:master Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants