diff options
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index 0dc3a4ebd5d3..bcd332e085f6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | |||
@@ -151,3 +151,33 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, | |||
151 | 151 | ||
152 | return r; | 152 | return r; |
153 | } | 153 | } |
154 | |||
155 | struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id) | ||
156 | { | ||
157 | struct amdgpu_ctx *ctx; | ||
158 | struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr; | ||
159 | |||
160 | mutex_lock(&mgr->lock); | ||
161 | ctx = idr_find(&mgr->ctx_handles, id); | ||
162 | if (ctx) | ||
163 | kref_get(&ctx->refcount); | ||
164 | mutex_unlock(&mgr->lock); | ||
165 | return ctx; | ||
166 | } | ||
167 | |||
168 | int amdgpu_ctx_put(struct amdgpu_ctx *ctx) | ||
169 | { | ||
170 | struct amdgpu_fpriv *fpriv; | ||
171 | struct amdgpu_ctx_mgr *mgr; | ||
172 | |||
173 | if (ctx == NULL) | ||
174 | return -EINVAL; | ||
175 | |||
176 | fpriv = ctx->fpriv; | ||
177 | mgr = &fpriv->ctx_mgr; | ||
178 | mutex_lock(&mgr->lock); | ||
179 | kref_put(&ctx->refcount, amdgpu_ctx_do_release); | ||
180 | mutex_unlock(&mgr->lock); | ||
181 | |||
182 | return 0; | ||
183 | } | ||