From: Changyeon Lee Date: Fri, 13 Jan 2023 06:44:58 +0000 (+0900) Subject: mmap with the dmabuf fd X-Git-Tag: accepted/tizen/unified/20230117.140526~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef58d165ba069f16fc84f68e31d3c31fe77d8ba6;p=platform%2Fadaptation%2Fbroadcom%2Flibtbm-vc4.git mmap with the dmabuf fd DRM_IOCTL_MODE_MAP_DUMB support only handle which is created with DRM_IOCTL_MODE_CREATE_DUMB (not support imported handle(DRM_IOCTL_PRIME_FD_TO_HANDLE) in other process) vc4 backend mmap with the dma buf fd and O_RDWR flag is added in DRM_IOCTL_PRIME_HANDLE_TO_FD Change-Id: Ieafb1bfbbbdcd6e3911859a4ee8d8d99c61e7caf --- diff --git a/src/tbm_backend_vc4.c b/src/tbm_backend_vc4.c index f3b6afa..0b09253 100644 --- a/src/tbm_backend_vc4.c +++ b/src/tbm_backend_vc4.c @@ -268,6 +268,7 @@ _get_dmabuf(int fd, unsigned int gem) struct drm_prime_handle prime_arg = {0, }; prime_arg.handle = gem; + prime_arg.flags = O_RDWR; if (drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_arg)) { TBM_BACKEND_ERR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD gem:%d (%m)", gem); return -1; @@ -305,21 +306,14 @@ _close_gem(int fd, unsigned int gem) } static void * -_mmap_gem(int fd, unsigned int gem, unsigned int size) +_mmap_dmabuf(int dmabuf, unsigned int size) { - struct drm_mode_map_dumb map_arg = {0,}; void *map; - map_arg.handle = gem; - if (drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg)) { - TBM_BACKEND_ERR("fail to DRM_IOCTL_MAP_DUMB gem:%d (%m)", gem); - return NULL; - } - map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, map_arg.offset); + dmabuf, 0); if (map == MAP_FAILED) { - TBM_BACKEND_ERR("Cannot usrptr gem:%d size:%d", gem, size); + TBM_BACKEND_ERR("fail to mmap dmabuf:%d size:%d (%m)", dmabuf, size); return NULL; } @@ -391,10 +385,18 @@ _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->dmabuf) { + bo_data->dmabuf = _get_dmabuf(bo_data->fd, bo_data->gem); + if (!bo_data->dmabuf) { + TBM_BACKEND_ERR("fail to get dmabuf from gem:%d", bo_data->gem); + return (hal_tbm_bo_handle) NULL; + } + } + if (!bo_data->pBase) { - bo_data->pBase = _mmap_gem(bo_data->fd, bo_data->gem, bo_data->size); + bo_data->pBase = _mmap_dmabuf(bo_data->dmabuf, bo_data->size); if (!bo_data->pBase) { - TBM_BACKEND_ERR("fail to mmap gem:%d", bo_data->gem); + TBM_BACKEND_ERR("fail to mmap dmabuf:%d", bo_data->dmabuf); return (hal_tbm_bo_handle) NULL; } }