From c21d27bafc38fc9573b4ca6b8ae4eaea0237026d Mon Sep 17 00:00:00 2001 From: Mark Yao Date: Fri, 5 May 2017 15:24:43 +0800 Subject: [PATCH] drm: add drm_device_get_by_name support Change-Id: Ifbd0f403ca2302e9329a16d7b69db5ee056cadf7 Signed-off-by: Mark Yao --- drivers/gpu/drm/drm_drv.c | 22 ++++++++++++++++++++++ include/drm/drmP.h | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 54625bcd42e9..63bd9decd4c2 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -417,6 +417,28 @@ void drm_minor_release(struct drm_minor *minor) drm_dev_unref(minor->dev); } +struct drm_device *drm_device_get_by_name(const char *name) +{ + int i; + + for (i = 0; i < 64; i++) { + struct drm_minor *minor; + + minor = drm_minor_acquire(i + DRM_MINOR_CONTROL); + if (IS_ERR(minor)) + continue; + if (!minor->dev || !minor->dev->driver || + !minor->dev->driver->name) + continue; + if (!name) + return minor->dev; + if (!strcmp(name, minor->dev->driver->name)) + return minor->dev; + } + + return NULL; +} + /** * DOC: driver instance overview * diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 24ddc4b798b0..418d5fcd598e 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1127,6 +1127,14 @@ int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...); struct drm_minor *drm_minor_acquire(unsigned int minor_id); void drm_minor_release(struct drm_minor *minor); +#ifdef CONFIG_DRM +struct drm_device *drm_device_get_by_name(const char *name); +#else +static inline struct drm_device *drm_device_get_by_name(const char *name) +{ + return NULL; +} +#endif /*@}*/ -- 2.34.1