}
#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)
{
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;
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, };