Revert "mmap the dmabuf with the gem memory at every tbm_bo." 64/286864/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Thu, 12 Jan 2023 06:48:38 +0000 (15:48 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Mon, 16 Jan 2023 04:42:29 +0000 (13:42 +0900)
This reverts commit f01ed42f6366a9715fc51816a5ed0c690ae4f8ad.

Change-Id: I3f0f9a96b2eadb1a03bd38251ebfbb60f4d60297

src/tbm_backend_vc4.c

index eaaedca..d2f9587 100644 (file)
@@ -807,32 +807,6 @@ _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)
 {
@@ -860,9 +834,23 @@ _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_mmap(bo_data)) {
-                       TBM_BACKEND_ERR("_bo_mmap() failed.");
-                       return (hal_tbm_bo_handle) NULL;
+               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;
                }
                bo_handle.ptr = (void *)bo_data->pBase;
                break;
@@ -1536,18 +1524,6 @@ 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, };