diff options
author | SooChan Lim <sc1.lim@samsung.com> | 2023-01-04 17:29:53 +0900 |
---|---|---|
committer | SooChan Lim <sc1.lim@samsung.com> | 2023-01-04 17:32:04 +0900 |
commit | f01ed42f6366a9715fc51816a5ed0c690ae4f8ad (patch) | |
tree | 2423a91a8d201b185b88d556edf2f8dd03361a26 | |
parent | be94bd6890ebf40662945734e51e69dfb4c064ac (diff) | |
download | libtbm-vc4-f01ed42f6366a9715fc51816a5ed0c690ae4f8ad.tar.gz libtbm-vc4-f01ed42f6366a9715fc51816a5ed0c690ae4f8ad.tar.bz2 libtbm-vc4-f01ed42f6366a9715fc51816a5ed0c690ae4f8ad.zip |
mmap the dmabuf with the gem memory at every tbm_bo.
The vc4 backend has to mmap the dmabuf with the gem handle.
Otherwise, when this dmabuf has been exported to another process,
the process cannot call DRM_IOCTL_MODE_MAP_DUMB with the gem handle
which is imported by dmabuf fd.
Change-Id: Ia96340e72a15e5abe1bf2a72cb6230990cfba32c
-rw-r--r-- | src/tbm_backend_vc4.c | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/src/tbm_backend_vc4.c b/src/tbm_backend_vc4.c index d2f9587..eaaedca 100644 --- a/src/tbm_backend_vc4.c +++ b/src/tbm_backend_vc4.c @@ -807,6 +807,32 @@ _get_render_node(void) } #endif +static int +_bo_mmap(tbm_vc4_bo *bo_data) +{ + struct drm_mode_map_dumb arg = {0,}; + void *map = NULL; + + if (bo_data->pBase) + return 1; + + arg.handle = bo_data->gem; + if (drmIoctl(bo_data->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg)) { + TBM_BACKEND_ERR("Cannot map_vc4 gem=%d\n", bo_data->gem); + return 0; + } + + map = mmap(NULL, bo_data->size, PROT_READ | PROT_WRITE, MAP_SHARED, + bo_data->fd, arg.offset); + if (map == MAP_FAILED) { + TBM_BACKEND_ERR("Cannot usrptr gem=%d\n", bo_data->gem); + return 0; + } + bo_data->pBase = map; + + return 1; +} + static unsigned int _get_name(int fd, unsigned int gem) { @@ -834,23 +860,9 @@ _vc4_bo_handle(tbm_vc4_bo *bo_data, int device) bo_handle.u32 = (uint32_t)bo_data->gem; break; case HAL_TBM_DEVICE_CPU: - if (!bo_data->pBase) { - struct drm_mode_map_dumb arg = {0,}; - void *map = NULL; - - arg.handle = bo_data->gem; - if (drmIoctl(bo_data->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg)) { - TBM_BACKEND_ERR("Cannot map_vc4 gem=%d\n", bo_data->gem); - return (hal_tbm_bo_handle) NULL; - } - - map = mmap(NULL, bo_data->size, PROT_READ | PROT_WRITE, MAP_SHARED, - bo_data->fd, arg.offset); - if (map == MAP_FAILED) { - TBM_BACKEND_ERR("Cannot usrptr gem=%d\n", bo_data->gem); - return (hal_tbm_bo_handle) NULL; - } - bo_data->pBase = map; + if (!_bo_mmap(bo_data)) { + TBM_BACKEND_ERR("_bo_mmap() failed."); + return (hal_tbm_bo_handle) NULL; } bo_handle.ptr = (void *)bo_data->pBase; break; @@ -1524,6 +1536,18 @@ tbm_vc4_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size, pthread_mutex_init(&bo_data->mutex, NULL); + // vc4 backend has to mmap the dmabuf with the gem handle. + // Otherwise, when this dmabuf has been exported to another process, + // the process cannot call DRM_IOCTL_MODE_MAP_DUMB with the gem handle + // which is imported by dmabuf fd. + if (!_bo_mmap(bo_data)) { + TBM_BACKEND_ERR("_bo_mmap() failed.\n"); + free(bo_data); + if (error) + *error = HAL_TBM_ERROR_INVALID_OPERATION; + return NULL; + } + if (bufmgr_data->use_dma_fence && !bo_data->dmabuf) { struct drm_prime_handle arg = {0, }; |