struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
struct drm_gem_close req = { bo->handle };
- pthread_mutex_lock(&nvdev->lock);
- if (nvbo->name) {
+ if (nvbo->head.next) {
+ pthread_mutex_lock(&nvdev->lock);
if (atomic_read(&nvbo->refcnt) == 0) {
DRMLISTDEL(&nvbo->head);
/*
}
pthread_mutex_unlock(&nvdev->lock);
} else {
- DRMLISTDEL(&nvbo->head);
- pthread_mutex_unlock(&nvdev->lock);
drmIoctl(bo->device->fd, DRM_IOCTL_GEM_CLOSE, &req);
}
if (bo->map)
uint64_t size, union nouveau_bo_config *config,
struct nouveau_bo **pbo)
{
- struct nouveau_device_priv *nvdev = nouveau_device(dev);
struct nouveau_bo_priv *nvbo = calloc(1, sizeof(*nvbo));
struct nouveau_bo *bo = &nvbo->base;
int ret;
return ret;
}
- pthread_mutex_lock(&nvdev->lock);
- DRMLISTADD(&nvbo->head, &nvdev->bo_list);
- pthread_mutex_unlock(&nvdev->lock);
-
*pbo = bo;
return 0;
}
return -ENOMEM;
}
+static void
+nouveau_bo_make_global(struct nouveau_bo_priv *nvbo)
+{
+ if (!nvbo->head.next) {
+ struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
+ pthread_mutex_lock(&nvdev->lock);
+ if (!nvbo->head.next)
+ DRMLISTADD(&nvbo->head, &nvdev->bo_list);
+ pthread_mutex_unlock(&nvdev->lock);
+ }
+}
+
drm_public int
nouveau_bo_wrap(struct nouveau_device *dev, uint32_t handle,
struct nouveau_bo **pbo)
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
*name = nvbo->name;
- if (!*name || *name == ~0U) {
+ if (!*name) {
int ret = drmIoctl(bo->device->fd, DRM_IOCTL_GEM_FLINK, &req);
+
if (ret) {
*name = 0;
return ret;
}
nvbo->name = *name = req.name;
+
+ nouveau_bo_make_global(nvbo);
}
return 0;
}
ret = drmPrimeFDToHandle(dev->fd, prime_fd, &handle);
if (ret == 0) {
ret = nouveau_bo_wrap_locked(dev, handle, bo, 0);
- if (!ret) {
- struct nouveau_bo_priv *nvbo = nouveau_bo(*bo);
- if (!nvbo->name) {
- /*
- * XXX: Force locked DRM_IOCTL_GEM_CLOSE
- * to rule out race conditions
- */
- nvbo->name = ~0;
- }
- }
}
pthread_mutex_unlock(&nvdev->lock);
return ret;
ret = drmPrimeHandleToFD(bo->device->fd, nvbo->base.handle, DRM_CLOEXEC, prime_fd);
if (ret)
return ret;
- if (!nvbo->name)
- nvbo->name = ~0;
+
+ nouveau_bo_make_global(nvbo);
return 0;
}
if (push && push->channel)
nouveau_pushbuf_kick(push, push->channel);
- if (!nvbo->name && !(nvbo->access & NOUVEAU_BO_WR) &&
- !( access & NOUVEAU_BO_WR))
+ if (!nvbo->head.next && !(nvbo->access & NOUVEAU_BO_WR) &&
+ !(access & NOUVEAU_BO_WR))
return 0;
req.handle = bo->handle;