From patchwork Thu May 17 08:23:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 8702 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 873EF23EB5 for ; Thu, 17 May 2012 08:23:52 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 577BBA183CD for ; Thu, 17 May 2012 08:23:52 +0000 (UTC) Received: by mail-yw0-f52.google.com with SMTP id p61so1847181yhp.11 for ; Thu, 17 May 2012 01:23:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=YPLbzk5At+EmUi7rt6F5MfNKFX7okq1yQbu5wKguLMU=; b=bQZJ+/GHSo06oUOWMte/TwDxV7eC4Oaxh3gkLak1KvVc7Yo+FkStJHGE+fSLLsZsbh UiS0B/bO9gmx355t37EKQ0UYjUUA3cpGVZzvNr0ild73DuPam5dohQVrAZ7CMDD1lRHg 0RlDnlSei+M6nVfjeh45K92SoWcgHUjvRqXzcORv4C6/CCjsqYB3NDlMGfaRAupcxsGU r+cQ7pTuU0QUcAncMAsxx+nfXcbQF8ST/dx3+qMSmGneeZxctX/II9yd3Y9WQ0mOvnFr Q/i1W3rXVIolyLPxnduf1Vw9dk5I/kivzof46degeGbuth4G2Y95D8HllOc23Ysrf3Wo smEQ== Received: by 10.50.85.163 with SMTP id i3mr4346042igz.57.1337243031849; Thu, 17 May 2012 01:23:51 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp10962ibd; Thu, 17 May 2012 01:23:50 -0700 (PDT) Received: by 10.14.95.207 with SMTP id p55mr1227721eef.40.1337243030115; Thu, 17 May 2012 01:23:50 -0700 (PDT) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by mx.google.com with ESMTPS id 83si6405699wet.50.2012.05.17.01.23.49 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 01:23:50 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.212.172 as permitted sender) client-ip=209.85.212.172; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.212.172 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by wibhj8 with SMTP id hj8so4070992wib.13 for ; Thu, 17 May 2012 01:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=YPLbzk5At+EmUi7rt6F5MfNKFX7okq1yQbu5wKguLMU=; b=jsJwURKT4RD4JBFBnTPiE/U4pYC12K56Z1APOYNx4V+e5tnM3hdzPB9ffFQNvVw8L5 GNL6Ka+YJAFNPbVB9ONd/YXLXSRq/Y/wquXieMJzYYh+N1LiabHGKpGT5CyjTSxzQ5d8 zB+pX0W0vp8Pfg0bZ1ocv+mjeh4LoPm6saUhifigJbl5H6nJuPVcEUGm3Jg4PTdSqSbL 6KTczxSpdntijP9zhPueX5pfEYJhR9RliTE0emq9jOwpcDPGLfsYNPZyG2QZOo99qchj iZ4eRbVm0bOUXSyspGpY09G6DTHK1WwE38mOCaZPIWoETruH7oVDDGscMcqPlnxDoPLP mRzw== Received: by 10.216.135.206 with SMTP id u56mr4125160wei.29.1337243029561; Thu, 17 May 2012 01:23:49 -0700 (PDT) Received: from localhost (host-92-29-250-134.as13285.net. [92.29.250.134]) by mx.google.com with ESMTPS id fl2sm18687157wib.2.2012.05.17.01.23.47 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 01:23:48 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, Paulo Zanoni , Rob Clark Subject: [PATCH 1/2] drm: add bitmask property type Date: Thu, 17 May 2012 02:23:26 -0600 Message-Id: <1337243007-27493-2-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1337243007-27493-1-git-send-email-rob.clark@linaro.org> References: <1337243007-27493-1-git-send-email-rob.clark@linaro.org> X-Gm-Message-State: ALoCoQm32VqQ+rruF4UkIrZXTFOH8g1jELiFF0Zes9ckuACIg0iz+MHjCzjM1MiukxmvwskVdOLA From: Rob Clark A bitmask property is similar to an enum. The enum value is a bit position (0-63), and valid property values consist of a mask of zero or more of (1 << enum_val[n]). Signed-off-by: Rob Clark Reviewed-by: Paulo Zanoni --- v1: original v2: added comments to new fields in drm_plane_funcs and drm_plane drivers/gpu/drm/drm_crtc.c | 47 +++++++++++++++++++++++++++++++++++++++++--- include/drm/drm_crtc.h | 4 ++++ include/drm/drm_mode.h | 1 + 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 75661c8..bf2bb9b 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -2707,6 +2707,34 @@ struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, } EXPORT_SYMBOL(drm_property_create_enum); +struct drm_property *drm_property_create_bitmask(struct drm_device *dev, + int flags, const char *name, + const struct drm_prop_enum_list *props, + int num_values) +{ + struct drm_property *property; + int i, ret; + + flags |= DRM_MODE_PROP_BITMASK; + + property = drm_property_create(dev, flags, name, num_values); + if (!property) + return NULL; + + for (i = 0; i < num_values; i++) { + ret = drm_property_add_enum(property, i, + props[i].type, + props[i].name); + if (ret) { + drm_property_destroy(dev, property); + return NULL; + } + } + + return property; +} +EXPORT_SYMBOL(drm_property_create_bitmask); + struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, const char *name, uint64_t min, uint64_t max) @@ -2731,7 +2759,14 @@ int drm_property_add_enum(struct drm_property *property, int index, { struct drm_property_enum *prop_enum; - if (!(property->flags & DRM_MODE_PROP_ENUM)) + if (!(property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK))) + return -EINVAL; + + /* + * Bitmask enum properties have the additional constraint of values + * from 0 to 63 + */ + if ((property->flags & DRM_MODE_PROP_BITMASK) && (value > 63)) return -EINVAL; if (!list_empty(&property->enum_blob_list)) { @@ -2875,7 +2910,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev, } property = obj_to_property(obj); - if (property->flags & DRM_MODE_PROP_ENUM) { + if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) { list_for_each_entry(prop_enum, &property->enum_blob_list, head) enum_count++; } else if (property->flags & DRM_MODE_PROP_BLOB) { @@ -2900,7 +2935,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev, } out_resp->count_values = value_count; - if (property->flags & DRM_MODE_PROP_ENUM) { + if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) { if ((out_resp->count_enum_blobs >= enum_count) && enum_count) { copied = 0; enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr; @@ -3055,6 +3090,12 @@ static bool drm_property_change_is_valid(struct drm_property *property, if (value < property->values[0] || value > property->values[1]) return false; return true; + } else if (property->flags & DRM_MODE_PROP_BITMASK) { + int i; + __u64 valid_mask = 0; + for (i = 0; i < property->num_values; i++) + valid_mask |= (1LL << property->values[i]); + return !(value & ~valid_mask); } else { int i; for (i = 0; i < property->num_values; i++) diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index e194c78..9b53c14 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -940,6 +940,10 @@ extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int const char *name, const struct drm_prop_enum_list *props, int num_values); +struct drm_property *drm_property_create_bitmask(struct drm_device *dev, + int flags, const char *name, + const struct drm_prop_enum_list *props, + int num_values); struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, const char *name, uint64_t min, uint64_t max); diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h index 326f2be..5581980 100644 --- a/include/drm/drm_mode.h +++ b/include/drm/drm_mode.h @@ -230,6 +230,7 @@ struct drm_mode_get_connector { #define DRM_MODE_PROP_IMMUTABLE (1<<2) #define DRM_MODE_PROP_ENUM (1<<3) /* enumerated type with text strings */ #define DRM_MODE_PROP_BLOB (1<<4) +#define DRM_MODE_PROP_BITMASK (1<<5) /* bitmask of enumerated types */ struct drm_mode_property_enum { __u64 value;