diff options
Diffstat (limited to 'drivers/gpu/drm/nouveau/nouveau_gem.c')
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_gem.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c index 3e1c7010e076..022393777805 100644 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c | |||
@@ -63,20 +63,60 @@ int | |||
63 | nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv) | 63 | nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv) |
64 | { | 64 | { |
65 | struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv); | 65 | struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv); |
66 | struct nouveau_bo *nvbo = nouveau_gem_object(gem); | ||
67 | struct nouveau_vma *vma; | ||
68 | int ret; | ||
66 | 69 | ||
67 | if (!fpriv->vm) | 70 | if (!fpriv->vm) |
68 | return 0; | 71 | return 0; |
69 | 72 | ||
70 | return 0; | 73 | ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0); |
74 | if (ret) | ||
75 | return ret; | ||
76 | |||
77 | vma = nouveau_bo_vma_find(nvbo, fpriv->vm); | ||
78 | if (!vma) { | ||
79 | vma = kzalloc(sizeof(*vma), GFP_KERNEL); | ||
80 | if (!vma) { | ||
81 | ret = -ENOMEM; | ||
82 | goto out; | ||
83 | } | ||
84 | |||
85 | ret = nouveau_bo_vma_add(nvbo, fpriv->vm, vma); | ||
86 | if (ret) { | ||
87 | kfree(vma); | ||
88 | goto out; | ||
89 | } | ||
90 | } else { | ||
91 | vma->refcount++; | ||
92 | } | ||
93 | |||
94 | out: | ||
95 | ttm_bo_unreserve(&nvbo->bo); | ||
96 | return ret; | ||
71 | } | 97 | } |
72 | 98 | ||
73 | void | 99 | void |
74 | nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv) | 100 | nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv) |
75 | { | 101 | { |
76 | struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv); | 102 | struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv); |
103 | struct nouveau_bo *nvbo = nouveau_gem_object(gem); | ||
104 | struct nouveau_vma *vma; | ||
105 | int ret; | ||
77 | 106 | ||
78 | if (!fpriv->vm) | 107 | if (!fpriv->vm) |
79 | return; | 108 | return; |
109 | |||
110 | ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0); | ||
111 | if (ret) | ||
112 | return; | ||
113 | |||
114 | vma = nouveau_bo_vma_find(nvbo, fpriv->vm); | ||
115 | if (vma) { | ||
116 | if (--vma->refcount == 0) | ||
117 | nouveau_bo_vma_del(nvbo, vma); | ||
118 | } | ||
119 | ttm_bo_unreserve(&nvbo->bo); | ||
80 | } | 120 | } |
81 | 121 | ||
82 | int | 122 | int |