gbm_gralloc
gbm_gralloc copied to clipboard
Add feature to search for KMS DRI card
Most modern SOCs have separate IP cores for GPU and Display Unit (KMS). To work properly mesa requires initialize gbm interface using KMS card. Mesa uses it to allocate buffers with SCANOUT flag and does not require fd or pathname explicitly specified for GPU. Mesa will search for GPU and load the proper driver.
Also, there is no warranty that the KMS card will always have /dev/dri/card0 path and GPU - /dev/dri/card1. Order can depend on many factors. For example: on the rpi4 board, it was observed that enabling the WIFI kernel module swapping the card order. Therefore searching for the KMS card is the only efficient solution.
The has_kms_dev function returns true when the libdrm function is returned resources and the target device has at least one CTRC, connector, and encoder. The open_first_kms_dev function returns opened file descriptor on success using the previous function to check for each device. It also returns zeroed value for the case of KMS absence, or the -EINVAL on glob function error.
In the case of absence of the "hwc.drm.device" system property the first KMS device or the default path /dev/dri/renderD128 will be used to open.
A similar solution has been created and merged for drm-hwcomposer (MR#108).
Thank you for this feature. I have an issue with it: When there is no access to /dev/dri/card0 device probably due to different user/group client (not system/graphics) then memory allocation fails.
Here is my uevent rules:
/dev/dri/card0 0660 system graphics
/dev/dri/card1 0660 system graphics
/dev/dri/renderD128 0666 system graphics
@rsglobal, I've updated the PR. As for now, I handle the case if one of the paths is opened with an access error the search will be continued. Also, I extended the log prints. Could you review this solution?
@matviizorin ,
Works fine for me. Thanks.
@robherring ,
Could you merge this please?
This apparently breaks AMD gpus (tested with drmDropMaster)
This contribution was a part of GloDroid development activity. At this particular moment we almost switched to minigbm's gbm backend, where a little different logic is implemented. In a few words KMS card node is opened only if rendernode with "lima,panfrost,etnaviv,freedreno,v3d,vc4" found. Otherwise it opens render node. (this logic used by mesa3d build system to enable kms entrypoints)
@matviizorin, Are there any plans to finish this? If not, consider closing it down so you don't mislead people.
@rsglobal Thanks for the info - I assumed as much given the date and silence of this PR, but thought to comment this anyway in case anyone feels like reviewing/merging.