dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ville Syrjala <ville.syrjala@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [PATCH] drm: Reject dumb buffers when driver/device doesn't support modesetting
Date: Wed, 18 Mar 2020 17:49:59 +0200	[thread overview]
Message-ID: <20200318154959.9017-1-ville.syrjala@linux.intel.com> (raw)

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Currently a driver must not provide a .dumb_create() hook in the
drm_driver structure if it wants to declare dumb buffers as not
supported. So if the same driver wants to support both modeset
and non-modeset devices it would require two distinct drm_driver
structures in order to reject the dumb buffer operations on the
non-modeset devices. That's rather tedious, so let's make life
easier for such drivers by also checking for the DRIVER_MODESET
flag before we declare dumb buffers as supported. Now all the
driver has to do is clear the flag for any device that can't
do modesetting.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_client.c        |  2 +-
 drivers/gpu/drm/drm_crtc_internal.h |  1 +
 drivers/gpu/drm/drm_dumb_buffers.c  | 12 +++++++++---
 drivers/gpu/drm/drm_ioctl.c         |  2 +-
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
index 6b0c6ef8b9b3..cf61d87b434d 100644
--- a/drivers/gpu/drm/drm_client.c
+++ b/drivers/gpu/drm/drm_client.c
@@ -80,7 +80,7 @@ int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
 {
 	int ret;
 
-	if (!drm_core_check_feature(dev, DRIVER_MODESET) || !dev->driver->dumb_create)
+	if (!drm_has_dumb_buffers(dev))
 		return -EOPNOTSUPP;
 
 	if (funcs && !try_module_get(funcs->owner))
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index 16f2413403aa..c08ff0b7a509 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -92,6 +92,7 @@ int drm_mode_getresources(struct drm_device *dev,
 
 
 /* drm_dumb_buffers.c */
+bool drm_has_dumb_buffers(struct drm_device *dev);
 int drm_mode_create_dumb(struct drm_device *dev,
 			 struct drm_mode_create_dumb *args,
 			 struct drm_file *file_priv);
diff --git a/drivers/gpu/drm/drm_dumb_buffers.c b/drivers/gpu/drm/drm_dumb_buffers.c
index d18a740fe0f1..9859530362e2 100644
--- a/drivers/gpu/drm/drm_dumb_buffers.c
+++ b/drivers/gpu/drm/drm_dumb_buffers.c
@@ -55,13 +55,19 @@
  * a hardware-specific ioctl to allocate suitable buffer objects.
  */
 
+bool drm_has_dumb_buffers(struct drm_device *dev)
+{
+	return dev->driver->dumb_create &&
+		drm_core_check_feature(dev, DRIVER_MODESET);
+}
+
 int drm_mode_create_dumb(struct drm_device *dev,
 			 struct drm_mode_create_dumb *args,
 			 struct drm_file *file_priv)
 {
 	u32 cpp, stride, size;
 
-	if (!dev->driver->dumb_create)
+	if (!drm_has_dumb_buffers(dev))
 		return -ENOSYS;
 	if (!args->width || !args->height || !args->bpp)
 		return -EINVAL;
@@ -119,7 +125,7 @@ int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
 {
 	struct drm_mode_map_dumb *args = data;
 
-	if (!dev->driver->dumb_create)
+	if (!drm_has_dumb_buffers(dev))
 		return -ENOSYS;
 
 	if (dev->driver->dumb_map_offset)
@@ -134,7 +140,7 @@ int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
 int drm_mode_destroy_dumb(struct drm_device *dev, u32 handle,
 			  struct drm_file *file_priv)
 {
-	if (!dev->driver->dumb_create)
+	if (!drm_has_dumb_buffers(dev))
 		return -ENOSYS;
 
 	if (dev->driver->dumb_destroy)
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 9e41972c4bbc..437f1bee6869 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -262,7 +262,7 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
 
 	switch (req->capability) {
 	case DRM_CAP_DUMB_BUFFER:
-		if (dev->driver->dumb_create)
+		if (drm_has_dumb_buffers(dev))
 			req->value = 1;
 		break;
 	case DRM_CAP_VBLANK_HIGH_CRTC:
-- 
2.24.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

             reply	other threads:[~2020-03-18 15:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18 15:49 Ville Syrjala [this message]
2020-03-18 20:31 ` [PATCH] drm: Reject dumb buffers when driver/device doesn't support modesetting Matt Roper
2020-03-18 20:44   ` Ville Syrjälä

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=20200318154959.9017-1-ville.syrjala@linux.intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.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