diff options
author | Changyeon Lee <cyeon.lee@samsung.com> | 2023-07-13 14:23:34 +0900 |
---|---|---|
committer | Changyeon Lee <cyeon.lee@samsung.com> | 2023-07-13 14:57:51 +0900 |
commit | 368216a46789e7b63bbe9c2ce334825defdf512d (patch) | |
tree | 56509692c2589afa66cab6dd3721681ff54314f3 | |
parent | 228a1ccd8a55e60398b92756b1fb26bb57cbbe80 (diff) | |
download | libtbm-dumb-368216a46789e7b63bbe9c2ce334825defdf512d.tar.gz libtbm-dumb-368216a46789e7b63bbe9c2ce334825defdf512d.tar.bz2 libtbm-dumb-368216a46789e7b63bbe9c2ce334825defdf512d.zip |
Get dma buf when tbm_dumb_bo is created
for reference gem with dma buf when tbm_bufmgr and gbm_device
are used at the same time.
Change-Id: I0285a34ef8a41c9beea869db4b5cc6bd5f87bd63
-rw-r--r-- | src/tbm_backend_dumb.c | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/src/tbm_backend_dumb.c b/src/tbm_backend_dumb.c index 8939de5..2b33a35 100644 --- a/src/tbm_backend_dumb.c +++ b/src/tbm_backend_dumb.c @@ -290,7 +290,6 @@ static hal_tbm_bo_handle _dumb_bo_handle(tbm_dumb_bo *bo_data, int device) { hal_tbm_bo_handle bo_handle; - struct drm_prime_handle prime_handle_arg = {0, }; struct drm_mode_map_dumb map_dumb_arg = {0, }; void *map = NULL; @@ -306,7 +305,7 @@ _dumb_bo_handle(tbm_dumb_bo *bo_data, int device) map_dumb_arg.handle = bo_data->gem; if (drmIoctl(bo_data->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_dumb_arg)) { TBM_BACKEND_ERR("fail to DRM_IOCTL_MODE_MAP_DUMB bo_data:%p gem:%d", - bo_data->gem); + bo_data, bo_data->gem); return (hal_tbm_bo_handle) NULL; } @@ -321,27 +320,10 @@ _dumb_bo_handle(tbm_dumb_bo *bo_data, int device) bo_handle.ptr = (void *)bo_data->pBase; break; case HAL_TBM_DEVICE_3D: - if (bo_data->dmabuf < 0) { - prime_handle_arg.handle = bo_data->gem; - if (drmIoctl(bo_data->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_handle_arg)) { - TBM_BACKEND_ERR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD bo_data:%p gem:%d", - bo_data, bo_data->gem); - return (hal_tbm_bo_handle) NULL; - } - bo_data->dmabuf = prime_handle_arg.fd; - } - - bo_handle.u32 = (uint32_t)bo_data->dmabuf; - break; case HAL_TBM_DEVICE_MM: if (bo_data->dmabuf < 0) { - prime_handle_arg.handle = bo_data->gem; - if (drmIoctl(bo_data->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_handle_arg)) { - TBM_BACKEND_ERR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD bo_data:%p gem:%d", - bo_data, bo_data->gem); - return (hal_tbm_bo_handle) NULL; - } - bo_data->dmabuf = prime_handle_arg.fd; + TBM_BACKEND_ERR("invalid dmabuf bo_data:%p", bo_data); + return (hal_tbm_bo_handle) NULL; } bo_handle.u32 = (uint32_t)bo_data->dmabuf; @@ -644,6 +626,8 @@ tbm_dumb_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size, tbm_dumb_bo *bo_data; unsigned int dumb_flags; struct drm_mode_create_dumb create_dumb_arg = {0, }; + struct drm_prime_handle prime_handle_arg = {0, }; + struct drm_gem_close close_arg = {0, }; if (bufmgr_data == NULL) { TBM_BACKEND_ERR("bufmgr_data is null"); @@ -652,15 +636,6 @@ tbm_dumb_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size, return NULL; } - bo_data = calloc(1, sizeof(struct _tbm_dumb_bo)); - if (!bo_data) { - TBM_BACKEND_ERR("fail to allocate the bo_data private"); - if (error) - *error = HAL_TBM_ERROR_OUT_OF_MEMORY; - return NULL; - } - bo_data->bufmgr_data = bufmgr_data; - dumb_flags = _get_dumb_flag_from_tbm(flags); //as we know only size for new bo set height=1 and bpp=8 and in this case @@ -672,16 +647,36 @@ tbm_dumb_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size, if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb_arg)) { TBM_BACKEND_ERR("fail to DRM_IOCTL_MODE_CREATE_DUMB flag:%x size:%d", create_dumb_arg.flags, (unsigned int)size); - free(bo_data); if (error) *error = HAL_TBM_ERROR_INVALID_OPERATION; return NULL; } + prime_handle_arg.handle = create_dumb_arg.handle; + if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_handle_arg)) { + TBM_BACKEND_ERR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD gem:%d", + create_dumb_arg.handle); + close_arg.handle = create_dumb_arg.handle; + drmIoctl(bufmgr_data->fd, DRM_IOCTL_GEM_CLOSE, &close_arg); + + if (error) + *error = HAL_TBM_ERROR_INVALID_OPERATION; + return NULL; + } + + bo_data = calloc(1, sizeof(struct _tbm_dumb_bo)); + if (!bo_data) { + TBM_BACKEND_ERR("fail to allocate the bo_data private"); + if (error) + *error = HAL_TBM_ERROR_OUT_OF_MEMORY; + return NULL; + } + + bo_data->bufmgr_data = bufmgr_data; bo_data->fd = bufmgr_data->fd; bo_data->gem = create_dumb_arg.handle; bo_data->size = create_dumb_arg.size; - bo_data->dmabuf = -1; + bo_data->dmabuf = prime_handle_arg.fd; bo_data->flags_tbm = flags; bo_data->flags_dumb = dumb_flags; bo_data->name = _get_name(bo_data->fd, bo_data->gem); @@ -790,12 +785,12 @@ tbm_dumb_bufmgr_import_fd(hal_tbm_bufmgr *bufmgr, hal_tbm_fd key, hal_tbm_error *error = HAL_TBM_ERROR_OUT_OF_MEMORY; return NULL; } - bo_data->bufmgr_data = bufmgr_data; + bo_data->bufmgr_data = bufmgr_data; bo_data->fd = bufmgr_data->fd; bo_data->gem = gem; bo_data->size = real_size; - bo_data->dmabuf = -1; + bo_data->dmabuf = dup(key); bo_data->flags_dumb = 0; bo_data->flags_tbm = _get_tbm_flag_from_dumb(bo_data->flags_dumb); bo_data->name = name; @@ -825,6 +820,8 @@ tbm_dumb_bufmgr_import_key(hal_tbm_bufmgr *bufmgr, hal_tbm_key key, hal_tbm_erro tbm_dumb_bufmgr *bufmgr_data = (tbm_dumb_bufmgr *)bufmgr; tbm_dumb_bo *bo_data; struct drm_gem_open open_arg = {0, }; + struct drm_prime_handle prime_handle_arg = {0, }; + struct drm_gem_close close_arg = {0, }; int ret; if (bufmgr_data == NULL) { @@ -849,6 +846,18 @@ tbm_dumb_bufmgr_import_key(hal_tbm_bufmgr *bufmgr, hal_tbm_key key, hal_tbm_erro return NULL; } + prime_handle_arg.handle = open_arg.handle; + if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_handle_arg)) { + TBM_BACKEND_ERR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD gem:%d", + open_arg.handle); + close_arg.handle = open_arg.handle; + drmIoctl(bufmgr_data->fd, DRM_IOCTL_GEM_CLOSE, &close_arg); + + if (error) + *error = HAL_TBM_ERROR_INVALID_OPERATION; + return NULL; + } + bo_data = calloc(1, sizeof(struct _tbm_dumb_bo)); if (!bo_data) { TBM_BACKEND_ERR("fail to allocate the bo_data private"); @@ -856,12 +865,12 @@ tbm_dumb_bufmgr_import_key(hal_tbm_bufmgr *bufmgr, hal_tbm_key key, hal_tbm_erro *error = HAL_TBM_ERROR_OUT_OF_MEMORY; return NULL; } - bo_data->bufmgr_data = bufmgr_data; + bo_data->bufmgr_data = bufmgr_data; bo_data->fd = bufmgr_data->fd; bo_data->gem = open_arg.handle; bo_data->size = open_arg.size; - bo_data->dmabuf = -1; + bo_data->dmabuf = prime_handle_arg.fd; bo_data->flags_dumb = 0; bo_data->name = key; bo_data->flags_tbm = _get_tbm_flag_from_dumb(bo_data->flags_dumb); |