Fix AMD GPU i2c bus PCI ID detection on Linux (sysfs path traversal)#90
Open
AlexJawhari wants to merge 1 commit into
Open
Conversation
On newer kernels with the amdgpu driver, i2c bus symlinks in /sys/bus/i2c/devices/ resolve to paths like: /sys/devices/pci.../0000:03:00.0/i2c-4 The previous code appended '/..' and relied on sysfs path traversal to reach the parent PCI device directory. This is unreliable and causes 'Failed to read i2c device PCI device ID' errors for all AMDGPU i2c buses. Fix: after resolving the symlink with realpath(), truncate at the last '/' to directly obtain the parent PCI device directory path. Also handle DT_UNKNOWN d_type which some kernels return for sysfs symlink entries instead of DT_LNK. This allows OpenRGB to correctly register AMDGPU i2c buses with their proper vendor/device/subsystem PCI IDs, which is a prerequisite for any GPU RGB controller detection on AMD hardware under Linux. Tested on Linux Mint with ASRock Radeon RX 7700 XT (1002:747E, subsystem 1849:5323) and kernel 6.x.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On newer kernels with the amdgpu driver, all AMDGPU i2c buses fail
to read their PCI device IDs, producing repeated errors like:
[i2c_smbus_linux] Failed to read i2c device PCI device ID
This happens because AMDGPU i2c bus symlinks in /sys/bus/i2c/devices/
resolve to paths inside the PCI device directory, e.g.:
/sys/devices/pci.../0000:03:00.0/i2c-4
The old code appended '/..' to the resolved path and relied on sysfs
path traversal to reach the parent PCI device. This is unreliable on
newer kernels and causes all AMDGPU buses to register with zeroed PCI
IDs (0000:0000), making GPU RGB detection impossible.
Fix
After resolving the symlink with realpath(), truncate the path at the
last '/' to directly obtain the parent PCI device directory. Also
handle DT_UNKNOWN d_type, which some kernels return for sysfs symlink
entries instead of DT_LNK.
Result
Before: all AMDGPU i2c buses show Device 0000:0000 Subsystem: 0000:0000
After:
AMDGPU SMU 0 (/dev/i2c-4) Device 1002:747E Subsystem: 1849:5323
AMDGPU DM i2c hw bus 0 (/dev/i2c-6) Device 1002:747E Subsystem: 1849:5323
AMDGPU DM i2c OEM bus (/dev/i2c-10) Device 1002:747E Subsystem: 1849:5323
(etc.)
Tested on