diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-01-29 04:49:19 -0500 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2014-03-16 07:25:17 -0400 |
commit | 1616c525b98deb34b8f4b02eccf0ae3a1310fa27 (patch) | |
tree | d28625fe2ae686919c757df8ec6b8940e0d46d22 /drivers/gpu/drm/drm_stub.c | |
parent | 099d1c290e2ebc3b798961a6c177c3aef5f0b789 (diff) |
drm: add minor-lookup/release helpers
Instead of accessing drm_minors_idr directly, this adds a small helper to
hide the internals. This will help us later to remove the drm_global_mutex
requirement for minor-lookup.
Furthermore, this also makes sure that minor->dev is always valid and
takes a reference-count to the device as long as the minor is used in an
open-file. This way, "struct file*"->private_data->dev is guaranteed to be
valid (which it has to, as we cannot reset it).
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/gpu/drm/drm_stub.c')
-rw-r--r-- | drivers/gpu/drm/drm_stub.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c index f2f0249304b7..269048215e82 100644 --- a/drivers/gpu/drm/drm_stub.c +++ b/drivers/gpu/drm/drm_stub.c | |||
@@ -356,6 +356,45 @@ static void drm_unplug_minor(struct drm_minor *minor) | |||
356 | } | 356 | } |
357 | 357 | ||
358 | /** | 358 | /** |
359 | * drm_minor_acquire - Acquire a DRM minor | ||
360 | * @minor_id: Minor ID of the DRM-minor | ||
361 | * | ||
362 | * Looks up the given minor-ID and returns the respective DRM-minor object. The | ||
363 | * refence-count of the underlying device is increased so you must release this | ||
364 | * object with drm_minor_release(). | ||
365 | * | ||
366 | * As long as you hold this minor, it is guaranteed that the object and the | ||
367 | * minor->dev pointer will stay valid! However, the device may get unplugged and | ||
368 | * unregistered while you hold the minor. | ||
369 | * | ||
370 | * Returns: | ||
371 | * Pointer to minor-object with increased device-refcount, or PTR_ERR on | ||
372 | * failure. | ||
373 | */ | ||
374 | struct drm_minor *drm_minor_acquire(unsigned int minor_id) | ||
375 | { | ||
376 | struct drm_minor *minor; | ||
377 | |||
378 | minor = idr_find(&drm_minors_idr, minor_id); | ||
379 | if (!minor) | ||
380 | return ERR_PTR(-ENODEV); | ||
381 | |||
382 | drm_dev_ref(minor->dev); | ||
383 | return minor; | ||
384 | } | ||
385 | |||
386 | /** | ||
387 | * drm_minor_release - Release DRM minor | ||
388 | * @minor: Pointer to DRM minor object | ||
389 | * | ||
390 | * Release a minor that was previously acquired via drm_minor_acquire(). | ||
391 | */ | ||
392 | void drm_minor_release(struct drm_minor *minor) | ||
393 | { | ||
394 | drm_dev_unref(minor->dev); | ||
395 | } | ||
396 | |||
397 | /** | ||
359 | * drm_put_minor - Destroy DRM minor | 398 | * drm_put_minor - Destroy DRM minor |
360 | * @minor: Minor to destroy | 399 | * @minor: Minor to destroy |
361 | * | 400 | * |