{
drm_mem_type_manager_t *man;
+ DRM_ASSERT_LOCKED(&bo->dev->struct_mutex);
+ DRM_ASSERT_LOCKED(&bo->mutex);
+
man = &bo->dev->bm.man[bo->pinned_mem_type];
list_add_tail(&bo->pinned_lru, &man->pinned);
}
{
drm_mem_type_manager_t *man;
+ DRM_ASSERT_LOCKED(&bo->dev->struct_mutex);
+
if (!(bo->mem.mask & (DRM_BO_FLAG_NO_MOVE | DRM_BO_FLAG_NO_EVICT))
|| bo->mem.mem_type != bo->pinned_mem_type) {
man = &bo->dev->bm.man[bo->mem.mem_type];
int ret = 0;
bo->ttm = NULL;
+ DRM_ASSERT_LOCKED(&bo->mutex);
+
switch (bo->type) {
case drm_bo_type_dc:
bo->ttm = drm_ttm_init(dev, bo->mem.num_pages << PAGE_SHIFT);
drm_fence_object_t *fence = bo->fence;
int ret;
+ DRM_ASSERT_LOCKED(&bo->mutex);
+
if (fence) {
drm_device_t *dev = bo->dev;
if (drm_fence_object_signaled(dev, fence, bo->fence_type, 0)) {
drm_device_t *dev = bo->dev;
drm_buffer_manager_t *bm = &dev->bm;
+ DRM_ASSERT_LOCKED(&dev->struct_mutex);
+
atomic_inc(&bo->usage);
mutex_unlock(&dev->struct_mutex);
mutex_lock(&bo->mutex);
drm_device_t *dev = bo->dev;
drm_buffer_manager_t *bm = &dev->bm;
+ DRM_ASSERT_LOCKED(&dev->struct_mutex);
+
if (list_empty(&bo->lru) && bo->mem.mm_node == NULL &&
list_empty(&bo->pinned_lru) && bo->pinned_node == NULL &&
list_empty(&bo->ddestroy) && atomic_read(&bo->usage) == 0) {
atomic_dec(&bm->count);
+ BUG_ON(!list_empty(&bo->base.list));
drm_ctl_free(bo, sizeof(*bo), DRM_MEM_BUFOBJ);
return;
void drm_bo_usage_deref_locked(drm_buffer_object_t * bo)
{
+ DRM_ASSERT_LOCKED(&bo->dev->struct_mutex);
+
if (atomic_dec_and_test(&bo->usage)) {
drm_bo_destroy_locked(bo);
}
drm_buffer_object_t *bo =
drm_user_object_entry(uo, drm_buffer_object_t, base);
+ DRM_ASSERT_LOCKED(&bo->dev->struct_mutex);
+
drm_bo_takedown_vm_locked(bo);
drm_bo_usage_deref_locked(bo);
}
uint32_t flags, uint32_t mask, uint32_t hint,
drm_bo_arg_reply_t * rep)
{
+ struct drm_device *dev = priv->head->dev;
drm_buffer_object_t *bo;
int ret;
int no_wait = hint & DRM_BO_HINT_DONT_BLOCK;
+ mutex_lock(&dev->struct_mutex);
bo = drm_lookup_buffer_object(priv, handle, 1);
+ mutex_unlock(&dev->struct_mutex);
if (!bo) {
return -EINVAL;
}
static int drm_bo_handle_info(drm_file_t * priv, uint32_t handle,
drm_bo_arg_reply_t * rep)
{
+ struct drm_device *dev = priv->head->dev;
drm_buffer_object_t *bo;
+ mutex_lock(&dev->struct_mutex);
bo = drm_lookup_buffer_object(priv, handle, 1);
+ mutex_unlock(&dev->struct_mutex);
+
if (!bo) {
return -EINVAL;
}
int no_wait = hint & DRM_BO_HINT_DONT_BLOCK;
int ret;
+ struct drm_device *dev = priv->head->dev;
+ mutex_lock(&dev->struct_mutex);
bo = drm_lookup_buffer_object(priv, handle, 1);
+ mutex_unlock(&dev->struct_mutex);
+
if (!bo) {
return -EINVAL;
}
drm_local_map_t *map;
drm_device_t *dev = bo->dev;
+ DRM_ASSERT_LOCKED(&dev->struct_mutex);
if (list->user_token) {
drm_ht_remove_item(&dev->map_hash, &list->hash);
list->user_token = 0;
drm_local_map_t *map;
drm_device_t *dev = bo->dev;
+ DRM_ASSERT_LOCKED(&dev->struct_mutex);
list->map = drm_ctl_calloc(1, sizeof(*map), DRM_MEM_BUFOBJ);
if (!list->map)
return -ENOMEM;
{
drm_fence_manager_t *fm = &dev->fm;
+ DRM_ASSERT_LOCKED(&dev->struct_mutex);
+
if (atomic_dec_and_test(&fence->usage)) {
drm_fence_unring(dev, &fence->ring);
DRM_DEBUG("Destroyed a fence object 0x%08lx\n",
fence->base.hash.key);
atomic_dec(&fm->count);
+ BUG_ON(!list_empty(&fence->base.list));
drm_ctl_free(fence, sizeof(*fence), DRM_MEM_FENCE);
}
}
if (atomic_read(&fence->usage) == 0) {
drm_fence_unring(dev, &fence->ring);
atomic_dec(&fm->count);
+ BUG_ON(!list_empty(&fence->base.list));
drm_ctl_free(fence, sizeof(*fence), DRM_MEM_FENCE);
}
mutex_unlock(&dev->struct_mutex);
mutex_lock(&dev->struct_mutex);
ret = drm_add_user_object(priv, &fence->base, shareable);
- mutex_unlock(&dev->struct_mutex);
if (ret)
- return ret;
+ goto out;
+ atomic_inc(&fence->usage);
fence->base.type = drm_fence_type;
fence->base.remove = &drm_fence_object_destroy;
DRM_DEBUG("Fence 0x%08lx created\n", fence->base.hash.key);
- return 0;
+out:
+ mutex_unlock(&dev->struct_mutex);
+ return ret;
}
-
EXPORT_SYMBOL(drm_fence_add_user_object);
int drm_fence_object_create(drm_device_t * dev, uint32_t class, uint32_t type,
int ret;
drm_fence_manager_t *fm = &dev->fm;
- fence = drm_ctl_alloc(sizeof(*fence), DRM_MEM_FENCE);
+ fence = drm_ctl_calloc(1, sizeof(*fence), DRM_MEM_FENCE);
if (!fence)
return -ENOMEM;
ret = drm_fence_object_init(dev, class, type, flags, fence);
drm_fence_usage_deref_unlocked(dev, fence);
return ret;
}
-
- /*
- * usage > 0. No need to lock dev->struct_mutex;
- */
-
- atomic_inc(&fence->usage);
arg.handle = fence->base.hash.key;
+
break;
case drm_fence_destroy:
mutex_lock(&dev->struct_mutex);
DRM_FENCE_FLAG_SHAREABLE);
if (ret)
return ret;
- atomic_inc(&fence->usage);
arg.handle = fence->base.hash.key;
break;
default:
drm_device_t *dev = priv->head->dev;
int ret;
+ DRM_ASSERT_LOCKED(&dev->struct_mutex);
+
atomic_set(&item->refcount, 1);
item->shareable = shareable;
item->owner = priv;
int ret;
drm_user_object_t *item;
+ DRM_ASSERT_LOCKED(&dev->struct_mutex);
+
ret = drm_ht_find_item(&dev->object_hash, key, &hash);
if (ret) {
return NULL;
int drm_remove_user_object(drm_file_t * priv, drm_user_object_t * item)
{
+ DRM_ASSERT_LOCKED(&priv->head->dev->struct_mutex);
+
if (item->owner != priv) {
DRM_ERROR("Cannot destroy object not owned by you.\n");
return -EINVAL;
drm_ref_object_t *item;
drm_open_hash_t *ht = &priv->refd_object_hash[ref_action];
+ DRM_ASSERT_LOCKED(&priv->head->dev->struct_mutex);
if (!referenced_object->shareable && priv != referenced_object->owner) {
DRM_ERROR("Not allowed to reference this object\n");
return -EINVAL;
drm_hash_item_t *hash;
int ret;
+ DRM_ASSERT_LOCKED(&priv->head->dev->struct_mutex);
ret = drm_ht_find_item(&priv->refd_object_hash[ref_action],
(unsigned long)referenced_object, &hash);
if (ret)
drm_open_hash_t *ht = &priv->refd_object_hash[item->unref_action];
drm_ref_t unref_action;
+ DRM_ASSERT_LOCKED(&priv->head->dev->struct_mutex);
unref_action = item->unref_action;
if (atomic_dec_and_test(&item->refcount)) {
ret = drm_ht_remove_item(ht, &item->hash);
uint32_t fence_flags,
drm_bo_mem_reg_t * new_mem);
+#ifdef CONFIG_DEBUG_MUTEXES
+#define DRM_ASSERT_LOCKED(_mutex) \
+ BUG_ON(!mutex_is_locked(_mutex) || \
+ ((_mutex)->owner != current_thread_info()))
+#else
+#define DRM_ASSERT_LOCKED(_mutex)
+#endif
+
#endif