From patchwork Thu Feb 27 22:14:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 3736491 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DC1D69F2F7 for ; Thu, 27 Feb 2014 22:15:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF8F62021C for ; Thu, 27 Feb 2014 22:15:01 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 737C220237 for ; Thu, 27 Feb 2014 22:15:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 642D8FB97F; Thu, 27 Feb 2014 14:14:53 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 354D7FB96E for ; Thu, 27 Feb 2014 14:14:30 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 27 Feb 2014 14:14:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,557,1389772800"; d="scan'208";a="483170083" Received: from mdroper-hswdev.fm.intel.com (HELO mdroper-hswdev) ([10.1.134.215]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2014 14:14:20 -0800 Received: from mattrope by mdroper-hswdev with local (Exim 4.80) (envelope-from ) id 1WJ9EW-0001Y3-Iq; Thu, 27 Feb 2014 14:15:12 -0800 From: Matt Roper To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/4] drm: Add support for CRTC primary planes Date: Thu, 27 Feb 2014 14:14:40 -0800 Message-Id: <1393539283-5901-2-git-send-email-matthew.d.roper@intel.com> X-Mailer: git-send-email 1.8.5.1 In-Reply-To: <1393539283-5901-1-git-send-email-matthew.d.roper@intel.com> References: <1393539283-5901-1-git-send-email-matthew.d.roper@intel.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Allow drivers to provide a drm_plane structure corresponding to a CRTC's primary plane. These planes will be included in the plane list for any clients setting the DRM_CLIENT_CAP_EXPOSE_PRIMARY_PLANES capability bit. Signed-off-by: Matt Roper --- drivers/gpu/drm/drm_crtc.c | 168 ++++++++++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/drm_ioctl.c | 5 ++ include/drm/drmP.h | 2 + include/drm/drm_crtc.h | 11 +++ include/uapi/drm/drm.h | 8 +++ 5 files changed, 189 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 35ea15d..21c6d4b 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -274,6 +274,74 @@ const char *drm_get_connector_status_name(enum drm_connector_status status) } EXPORT_SYMBOL(drm_get_connector_status_name); +/* + * Default set of pixel formats supported by primary planes. This matches the + * set of formats accepted by the traditional modesetting interfaces; drivers + * need only provide their own format list if it differs from the default. + */ +static const uint32_t default_primary_plane_formats[] = { + DRM_FORMAT_C8, + DRM_FORMAT_RGB332, + DRM_FORMAT_BGR233, + DRM_FORMAT_XRGB4444, + DRM_FORMAT_XBGR4444, + DRM_FORMAT_RGBX4444, + DRM_FORMAT_BGRX4444, + DRM_FORMAT_ARGB4444, + DRM_FORMAT_ABGR4444, + DRM_FORMAT_RGBA4444, + DRM_FORMAT_BGRA4444, + DRM_FORMAT_XRGB1555, + DRM_FORMAT_XBGR1555, + DRM_FORMAT_RGBX5551, + DRM_FORMAT_BGRX5551, + DRM_FORMAT_ARGB1555, + DRM_FORMAT_ABGR1555, + DRM_FORMAT_RGBA5551, + DRM_FORMAT_BGRA5551, + DRM_FORMAT_RGB565, + DRM_FORMAT_BGR565, + DRM_FORMAT_RGB888, + DRM_FORMAT_BGR888, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_XBGR8888, + DRM_FORMAT_RGBX8888, + DRM_FORMAT_BGRX8888, + DRM_FORMAT_ARGB8888, + DRM_FORMAT_ABGR8888, + DRM_FORMAT_RGBA8888, + DRM_FORMAT_BGRA8888, + DRM_FORMAT_XRGB2101010, + DRM_FORMAT_XBGR2101010, + DRM_FORMAT_RGBX1010102, + DRM_FORMAT_BGRX1010102, + DRM_FORMAT_ARGB2101010, + DRM_FORMAT_ABGR2101010, + DRM_FORMAT_RGBA1010102, + DRM_FORMAT_BGRA1010102, + DRM_FORMAT_YUYV, + DRM_FORMAT_YVYU, + DRM_FORMAT_UYVY, + DRM_FORMAT_VYUY, + DRM_FORMAT_AYUV, + DRM_FORMAT_NV12, + DRM_FORMAT_NV21, + DRM_FORMAT_NV16, + DRM_FORMAT_NV61, + DRM_FORMAT_NV24, + DRM_FORMAT_NV42, + DRM_FORMAT_YUV410, + DRM_FORMAT_YVU410, + DRM_FORMAT_YUV411, + DRM_FORMAT_YVU411, + DRM_FORMAT_YUV420, + DRM_FORMAT_YVU420, + DRM_FORMAT_YUV422, + DRM_FORMAT_YVU422, + DRM_FORMAT_YUV444, + DRM_FORMAT_YVU444, +}; + /** * drm_get_subpixel_order_name - return a string for a given subpixel enum * @order: enum of subpixel_order @@ -921,7 +989,7 @@ void drm_encoder_cleanup(struct drm_encoder *encoder) EXPORT_SYMBOL(drm_encoder_cleanup); /** - * drm_plane_init - Initialise a new plane object + * drm_plane_init - Initialise a new sprite plane object * @dev: DRM device * @plane: plane object to init * @possible_crtcs: bitmask of possible CRTCs @@ -930,7 +998,9 @@ EXPORT_SYMBOL(drm_encoder_cleanup); * @format_count: number of elements in @formats * @priv: plane is private (hidden from userspace)? * - * Inits a new object created as base part of a driver plane object. + * Inits a new object created as base part of a driver plane object. This + * function should only be called for traditional sprite/overlay planes. + * Primary planes should be initialized via @drm_plane_set_primary. * * RETURNS: * Zero on success, error code on failure. @@ -984,6 +1054,74 @@ int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, EXPORT_SYMBOL(drm_plane_init); /** + * drm_plane_set_primary - Supply a primary plane for a CRTC + * @dev DRM device + * @plane: plane object representing the primary plane + * @crtc: CRTC this plane is associated with + * @funcs: callbacks for the new plane + * @formats: array of supported formats (%DRM_FORMAT_*). If NULL, the + * default list of formats traditionally supported by modesetting + * API's will be used and @format_count will be ignored. + * @format_count: number of elements in @formats + * + * Provides a drm_plane representing a CRTC's primary plane. This plane will + * only be exposed to clients that set the DRM_CLIENT_CAP_EXPOSE_PRIMARY_PLANES + * capability bit. + * + * RETURNS: + * Zero on success, error code on failure. + */ +int drm_plane_set_primary(struct drm_device *dev, struct drm_plane *plane, + struct drm_crtc *crtc, + const struct drm_plane_funcs *funcs, + const uint32_t *formats, uint32_t format_count) +{ + int ret; + + drm_modeset_lock_all(dev); + + ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); + if (ret) + goto out; + + if (formats == NULL) { + formats = default_primary_plane_formats; + format_count = ARRAY_SIZE(default_primary_plane_formats); + } + + plane->base.properties = &plane->properties; + plane->dev = dev; + plane->funcs = funcs; + plane->format_types = kmalloc(sizeof(uint32_t) * format_count, + GFP_KERNEL); + if (!plane->format_types) { + DRM_DEBUG_KMS("out of memory when setting up primary plane\n"); + drm_mode_object_put(dev, &plane->base); + ret = -ENOMEM; + goto out; + } + + memcpy(plane->format_types, formats, format_count * sizeof(uint32_t)); + plane->format_count = format_count; + plane->possible_crtcs = drm_crtc_mask(crtc); + + /* + * Primary planes are not added to the general plane list, only linked + * to their CRTC. They will only be advertised to userspace clients + * that indicate support. + */ + crtc->primary_plane = plane; + dev->mode_config.num_primary_plane++; + INIT_LIST_HEAD(&plane->head); + + out: + drm_modeset_unlock_all(dev); + + return ret; +} +EXPORT_SYMBOL(drm_plane_set_primary); + +/** * drm_plane_cleanup - Clean up the core plane usage * @plane: plane to cleanup * @@ -1836,8 +1974,10 @@ int drm_mode_getplane_res(struct drm_device *dev, void *data, struct drm_mode_get_plane_res *plane_resp = data; struct drm_mode_config *config; struct drm_plane *plane; + struct drm_crtc *crtc; uint32_t __user *plane_ptr; int copied = 0, ret = 0; + unsigned num_planes; if (!drm_core_check_feature(dev, DRIVER_MODESET)) return -EINVAL; @@ -1845,14 +1985,32 @@ int drm_mode_getplane_res(struct drm_device *dev, void *data, drm_modeset_lock_all(dev); config = &dev->mode_config; + num_planes = config->num_plane; + if (file_priv->expose_primary_planes) + num_planes += config->num_primary_plane; + /* * This ioctl is called twice, once to determine how much space is * needed, and the 2nd time to fill it. */ - if (config->num_plane && - (plane_resp->count_planes >= config->num_plane)) { + if (num_planes && + (plane_resp->count_planes >= num_planes)) { plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr; + if (file_priv->expose_primary_planes) { + list_for_each_entry(crtc, &config->crtc_list, head) { + if (!crtc->primary_plane) + continue; + + if (put_user(crtc->primary_plane->base.id, + plane_ptr + copied)) { + ret = -EFAULT; + goto out; + } + copied++; + } + } + list_for_each_entry(plane, &config->plane_list, head) { if (put_user(plane->base.id, plane_ptr + copied)) { ret = -EFAULT; @@ -1861,7 +2019,7 @@ int drm_mode_getplane_res(struct drm_device *dev, void *data, copied++; } } - plane_resp->count_planes = config->num_plane; + plane_resp->count_planes = num_planes; out: drm_modeset_unlock_all(dev); diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index dffc836..03579d6 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -316,6 +316,11 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv) return -EINVAL; file_priv->stereo_allowed = req->value; break; + case DRM_CLIENT_CAP_EXPOSE_PRIMARY_PLANES: + if (req->value > 1) + return -EINVAL; + file_priv->expose_primary_planes = req->value; + break; default: return -EINVAL; } diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 04a7f31..997fa29 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -437,6 +437,8 @@ struct drm_file { unsigned is_master :1; /* this file private is a master for a minor */ /* true when the client has asked us to expose stereo 3D mode flags */ unsigned stereo_allowed :1; + /* true if client understands CRTC primary planes in the plane list */ + unsigned expose_primary_planes:1; struct pid *pid; kuid_t uid; diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index ce9ee60..33a955b 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -429,6 +429,11 @@ struct drm_crtc { * by drm_mode_set_config_internal to implement correct refcounting. */ struct drm_framebuffer *old_fb; + /* Primary plane to expose to userspace if the client sets the 'expose + * primary planes' cap. + */ + struct drm_plane *primary_plane; + bool enabled; /* Requested mode from modesetting. */ @@ -859,6 +864,7 @@ struct drm_mode_config { int num_plane; struct list_head plane_list; + int num_primary_plane; int num_crtc; struct list_head crtc_list; @@ -984,6 +990,11 @@ extern int drm_plane_init(struct drm_device *dev, const struct drm_plane_funcs *funcs, const uint32_t *formats, uint32_t format_count, bool priv); +extern int drm_plane_set_primary(struct drm_device *dev, + struct drm_plane *plane, struct drm_crtc *crtc, + const struct drm_plane_funcs *funcs, + const uint32_t *formats, + uint32_t format_count); extern void drm_plane_cleanup(struct drm_plane *plane); extern void drm_plane_force_disable(struct drm_plane *plane); diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h index 3c9a833..58a2468 100644 --- a/include/uapi/drm/drm.h +++ b/include/uapi/drm/drm.h @@ -635,6 +635,14 @@ struct drm_get_cap { */ #define DRM_CLIENT_CAP_STEREO_3D 1 +/** + * DRM_CLIENT_CAP_EXPOSE_PRIMARY_PLANES + * + * If set to 1, the DRM core will expose CRTC primary planes along with + * sprite/overlay planes. + */ +#define DRM_CLIENT_CAP_EXPOSE_PRIMARY_PLANES 2 + /** DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */ struct drm_set_client_cap { __u64 capability;