dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: "Noralf Trønnes" <noralf@tronnes.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC 1/3] drm: Add a way to iterate over minors
Date: Wed, 10 Aug 2016 10:43:19 +0200	[thread overview]
Message-ID: <20160810084319.GP6232@phenom.ffwll.local> (raw)
In-Reply-To: <1470764742-20323-2-git-send-email-noralf@tronnes.org>

On Tue, Aug 09, 2016 at 07:45:40PM +0200, Noralf Trønnes wrote:
> This adds a way for in-kernel users to iterate over the available
> DRM minors. The implementation is oops safe so the panic code
> can safely use it.
> 
> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>

Why iterate over minors? I'd kinda have expected we'd iterate over devices
instead ... And looking ahead, that seems to be what you actually want.
-Daniel

> ---
>  drivers/gpu/drm/drm_drv.c | 30 ++++++++++++++++++++++++++++++
>  include/drm/drmP.h        | 13 +++++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index be27ed3..3b14366 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -292,6 +292,36 @@ void drm_minor_release(struct drm_minor *minor)
>  }
>  
>  /**
> + * drm_minor_lookup - Lookup DRM minor
> + * @minor_id: Minor ID of the DRM-minor
> + *
> + * Looks up the given minor-ID and returns the respective DRM-minor object.
> + * No reference is taken on the underlying device.
> + * See drm_minor_for_each() for iterating over all minors.
> + *
> + * Returns:
> + * Pointer to minor-object or NULL.
> + */
> +struct drm_minor *drm_minor_lookup(unsigned int minor_id)
> +{
> +	struct drm_minor *minor;
> +	unsigned long flags;
> +	int locked = 1;
> +
> +	if (oops_in_progress)
> +		locked = spin_trylock_irqsave(&drm_minor_lock, flags);
> +	else
> +		spin_lock_irqsave(&drm_minor_lock, flags);
> +
> +	minor = idr_find(&drm_minors_idr, minor_id);
> +
> +	if (locked)
> +		spin_unlock_irqrestore(&drm_minor_lock, flags);
> +
> +	return minor;
> +}
> +
> +/**
>   * DOC: driver instance overview
>   *
>   * A device instance for a drm driver is represented by struct &drm_device. This
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index d377865..bc7006e 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -974,6 +974,19 @@ void drm_dev_unregister(struct drm_device *dev);
>  
>  struct drm_minor *drm_minor_acquire(unsigned int minor_id);
>  void drm_minor_release(struct drm_minor *minor);
> +struct drm_minor *drm_minor_lookup(unsigned int minor_id);
> +
> +/**
> + * drm_minor_for_each - Iterate over DRM minors
> + * @minor: DRM minor handle
> + * @type: DRM minor type to iterate over
> + * @id: id handle
> + *
> + * Iterate over the registered DRM minors of a given type.
> + */
> +#define drm_minor_for_each(minor, type, id)  \
> +	for ((id) = 0; (id) < 64; (id)++)  \
> +		if (((minor) = drm_minor_lookup((id) + (type) * 64)))
>  
>  /*@}*/
>  
> -- 
> 2.8.2
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-08-10  8:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09 17:45 [RFC 0/3] drm: Add panic handling Noralf Trønnes
2016-08-09 17:45 ` [RFC 1/3] drm: Add a way to iterate over minors Noralf Trønnes
2016-08-10  8:43   ` Daniel Vetter [this message]
2016-08-10 14:27     ` Noralf Trønnes
2016-08-10 14:34       ` Daniel Vetter
2016-08-24 10:53         ` David Herrmann
2016-08-09 17:45 ` [RFC 2/3] drm: Add panic handling Noralf Trønnes
2016-08-10  9:15   ` Daniel Vetter
2016-08-10  9:18     ` Daniel Vetter
2016-08-11 20:46     ` Noralf Trønnes
2016-08-12  8:31       ` Daniel Vetter
2016-08-09 17:45 ` [RFC 3/3] drm: simpledrm: " Noralf Trønnes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160810084319.GP6232@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=noralf@tronnes.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox