From patchwork Wed Mar 18 15:49:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 11445669 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B063D90 for ; Wed, 18 Mar 2020 15:50:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 97F9E20674 for ; Wed, 18 Mar 2020 15:50:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 97F9E20674 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9029889221; Wed, 18 Mar 2020 15:50:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7B88B89221; Wed, 18 Mar 2020 15:50:03 +0000 (UTC) IronPort-SDR: 0cd87rGpKZJ0GekNsy+7rGp5d1Y39ull0ZzGiwgLTjT4wQ+T0/0NpU8ptwQ0QrK0qyd/NMQe84 Q52gxkHpozHw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2020 08:50:02 -0700 IronPort-SDR: QB3zw/4Gw8CINhKIL96qyqvkRmaS293ysZjJuQD2N0gwcWRe12F7CjBJwEwphQqcPcYhfg1fRh yER6ciEJi/vg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,568,1574150400"; d="scan'208";a="279778660" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by fmsmga002.fm.intel.com with SMTP; 18 Mar 2020 08:50:00 -0700 Received: by stinkbox (sSMTP sendmail emulation); Wed, 18 Mar 2020 17:49:59 +0200 From: Ville Syrjala To: dri-devel@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 Message-Id: <20200318154959.9017-1-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Ville Syrjälä 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ä --- 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: