From patchwork Thu Mar 19 04:33:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Stone X-Patchwork-Id: 6045851 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9A09D9FB96 for ; Thu, 19 Mar 2015 04:34:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0C29204D5 for ; Thu, 19 Mar 2015 04:34:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id DD0E5204C9 for ; Thu, 19 Mar 2015 04:34:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ABF9B6E953; Wed, 18 Mar 2015 21:34:02 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [93.93.135.160]) by gabe.freedesktop.org (Postfix) with ESMTP id E0B3C6E961 for ; Wed, 18 Mar 2015 21:34:00 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: daniels) with ESMTPSA id EF4D3600621 From: Daniel Stone To: dri-devel@lists.freedesktop.org Subject: [RFC PATCH 25/37] drm: mode: Allow userspace to fetch mode as blob Date: Thu, 19 Mar 2015 04:33:24 +0000 Message-Id: <1426739616-10635-25-git-send-email-daniels@collabora.com> X-Mailer: git-send-email 2.3.2 In-Reply-To: <1426739616-10635-1-git-send-email-daniels@collabora.com> References: <1426739556-10429-1-git-send-email-daniels@collabora.com> <1426739616-10635-1-git-send-email-daniels@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Overload the getblob ioctl to allow passing in a mode ID, which will return the userspace representation (drm_mode_modeinfo) of that mode. Signed-off-by: Daniel Stone --- drivers/gpu/drm/drm_crtc.c | 26 ++++++++++++++++++++------ include/drm/drm_crtc.h | 8 ++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index af9628b..e50eda2 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -4163,9 +4163,12 @@ int drm_mode_getblob_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_mode_get_blob *out_resp = data; - struct drm_property_blob *blob; + const struct drm_property_blob *blob = NULL; + const struct drm_display_mode *mode = NULL; + void __user *user_ptr = (void __user *)(unsigned long)out_resp->data; + u32 length; + const void *data_src; int ret = 0; - void __user *blob_ptr; if (!drm_core_check_feature(dev, DRIVER_MODESET)) return -EINVAL; @@ -4173,18 +4176,29 @@ int drm_mode_getblob_ioctl(struct drm_device *dev, drm_modeset_lock_all(dev); blob = drm_property_blob_find(dev, out_resp->blob_id); if (!blob) { + /* If we don't find a blob, they might be trying to get a mode + * instead. */ + mode = drm_mode_find(dev, out_resp->blob_id); + } + + if (blob) { + length = blob->length; + data_src = blob->data; + } else if (mode) { + length = sizeof(mode->umode); + data_src = &mode->umode; + } else { ret = -ENOENT; goto done; } - if (out_resp->length == blob->length) { - blob_ptr = (void __user *)(unsigned long)out_resp->data; - if (copy_to_user(blob_ptr, blob->data, blob->length)) { + if (out_resp->length == length) { + if (copy_to_user(user_ptr, data_src, length)) { ret = -EFAULT; goto done; } } - out_resp->length = blob->length; + out_resp->length = length; done: drm_modeset_unlock_all(dev); diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 7683527..3ab70a7 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -1533,6 +1533,14 @@ drm_property_blob_find(struct drm_device *dev, uint32_t id) return mo ? obj_to_blob(mo) : NULL; } +static inline struct drm_display_mode *drm_mode_find(struct drm_device *dev, + uint32_t id) +{ + struct drm_mode_object *mo; + mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_MODE); + return mo ? obj_to_mode(mo) : NULL; +} + /* Plane list iterator for legacy (overlay only) planes. */ #define drm_for_each_legacy_plane(plane, planelist) \ list_for_each_entry(plane, planelist, head) \