gbm_gralloc icon indicating copy to clipboard operation
gbm_gralloc copied to clipboard

Add feature to search for KMS DRI card

Open matviizorin opened this issue 4 years ago • 8 comments

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).

matviizorin avatar Jul 23 '20 07:07 matviizorin

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.

rsglobal avatar Jul 30 '20 07:07 rsglobal

Here is my uevent rules:

/dev/dri/card0                                         0660    system       graphics
/dev/dri/card1                                         0660    system       graphics
/dev/dri/renderD128                                    0666    system       graphics

rsglobal avatar Jul 30 '20 10:07 rsglobal

@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 avatar Aug 08 '20 12:08 matviizorin

@matviizorin ,

Works fine for me. Thanks.

rsglobal avatar Oct 17 '20 14:10 rsglobal

@robherring ,

Could you merge this please?

rsglobal avatar Oct 26 '20 11:10 rsglobal

This apparently breaks AMD gpus (tested with drmDropMaster)

erfanoabdi avatar Sep 30 '21 04:09 erfanoabdi

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 avatar Sep 30 '21 09:09 rsglobal

@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.

MarijnS95 avatar Sep 30 '21 09:09 MarijnS95