From patchwork Tue Jun 5 18:06:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 9115 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 B50D223E1B for ; Tue, 5 Jun 2012 18:06:51 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 6745AA18357 for ; Tue, 5 Jun 2012 18:06:51 +0000 (UTC) Received: by ggnf1 with SMTP id f1so4785443ggn.11 for ; Tue, 05 Jun 2012 11:06:51 -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=qiNUDzLBs1CBEsENRuOewX4hSIeMcnHjawtdcwSG9Z8=; b=VQ6e0T0HA3fUpEtAMS0jIOIsirOTs7UxZjxS37ymTAuUFFMM3CUJ40Ky+H4hw3s+0V zxtA6vdXfg0AsRaEz4aTj2RYCkvQsPgPvaKlQrcI7KRuiZULJAH9M4vJwu0+zn6BkcB/ UNjdV5YY8xe9XBFGlQQXzZ29tnR56HppHhKgSoHStQTO1v/rIXC2q+RRe8c/GhwtVQ1n VKat8DXmazwaCpYCkULnQ8Q98N/ZkM+P/m0G3MQqTu48O+h9sXvyjl/dogDzI/jmwa88 notpTKuL0ib1k+0KusVryxFn+YKX7M7VhbQtcwWaaZk8SafWGNyokjH90iVOR0QRah0m pTnQ== Received: by 10.50.193.196 with SMTP id hq4mr3777791igc.57.1338919610394; Tue, 05 Jun 2012 11:06:50 -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.24.148 with SMTP id v20csp39689ibb; Tue, 5 Jun 2012 11:06:49 -0700 (PDT) Received: by 10.236.78.105 with SMTP id f69mr12459720yhe.15.1338919609680; Tue, 05 Jun 2012 11:06:49 -0700 (PDT) Received: from mail-gh0-f178.google.com (mail-gh0-f178.google.com [209.85.160.178]) by mx.google.com with ESMTPS id l12si900166anm.53.2012.06.05.11.06.49 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jun 2012 11:06:49 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) client-ip=209.85.160.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by ghbf1 with SMTP id f1so5116173ghb.37 for ; Tue, 05 Jun 2012 11:06: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=qiNUDzLBs1CBEsENRuOewX4hSIeMcnHjawtdcwSG9Z8=; b=H/gTm/gI1V2P35klPtdTEcj56T73fqwkg/SqRlq8xX4GmWxUAX4kOUs/sWIlFRArMh JBbF90N/nl2/N9me0pFNkQ7Xrm++gNGxGhgLOHuuERTDSrxaKpTGDMr3If7Q7CmgP80G BbwOr/XmBhDhaaa5QgJN23099nT/zsiSyyHMwjm17eqw4k8wTQ3Gltn6LHvPOzW1UzL8 bLLCU2XUbcGA2Kq+A/cXjfqbfL/6FTD/RrcR2mL6CDKuYbJMufB7naCDB9w3QXNneDye 40i23nX3KbgV3/b4G9dtjMLpfyhjUhLFRoZin/tdfUySbJ8dhhHC3qDKiUba1u1lxISB LN6A== Received: by 10.60.154.232 with SMTP id vr8mr17176053oeb.49.1338919608849; Tue, 05 Jun 2012 11:06:48 -0700 (PDT) Received: from localhost (ppp-70-253-38-6.dsl.rcsntx.swbell.net. [70.253.38.6]) by mx.google.com with ESMTPS id 6sm1738735obw.2.2012.06.05.11.06.47 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jun 2012 11:06:47 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, Paulo Zanoni Subject: [PATCH libdrm 1/8] Add support for generic object properties IOCTLs Date: Tue, 5 Jun 2012 13:06:27 -0500 Message-Id: <1338919594-25392-2-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1338919594-25392-1-git-send-email-rob.clark@linaro.org> References: <1338919594-25392-1-git-send-email-rob.clark@linaro.org> X-Gm-Message-State: ALoCoQkxLfwd8Z8pd7sg7guQnYTxqZEzaR26x9eqrpLnkF6QQ1SiI/rn6f8PKIqqJbRnUWkj47sn From: Paulo Zanoni New library calls: - drmModeObjectGetProperties - drmModeFreeObjectProperties - drmModeObjectSetProperties Reviewed-by: Eugeni Dodonov Reviewed-by: Rob Clark Signed-off-by: Paulo Zanoni --- include/drm/drm.h | 2 ++ include/drm/drm_mode.h | 24 ++++++++++++++ xf86drmMode.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ xf86drmMode.h | 14 ++++++++ 4 files changed, 123 insertions(+) diff --git a/include/drm/drm.h b/include/drm/drm.h index 753d2fc..5e6cd29 100644 --- a/include/drm/drm.h +++ b/include/drm/drm.h @@ -731,6 +731,8 @@ struct drm_prime_handle { #define DRM_IOCTL_MODE_GETPLANE DRM_IOWR(0xB6, struct drm_mode_get_plane) #define DRM_IOCTL_MODE_SETPLANE DRM_IOWR(0xB7, struct drm_mode_set_plane) #define DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, struct drm_mode_fb_cmd2) +#define DRM_IOCTL_MODE_OBJ_GETPROPERTIES DRM_IOWR(0xB9, struct drm_mode_obj_get_properties) +#define DRM_IOCTL_MODE_OBJ_SETPROPERTY DRM_IOWR(0xBA, struct drm_mode_obj_set_property) /** * Device specific ioctls should only be in their respective headers diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h index f36c61a..f303d94 100644 --- a/include/drm/drm_mode.h +++ b/include/drm/drm_mode.h @@ -250,6 +250,30 @@ struct drm_mode_connector_set_property { __u32 connector_id; }; +#define DRM_MODE_OBJECT_CRTC 0xcccccccc +#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0 +#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0 +#define DRM_MODE_OBJECT_MODE 0xdededede +#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0 +#define DRM_MODE_OBJECT_FB 0xfbfbfbfb +#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb +#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee + +struct drm_mode_obj_get_properties { + __u64 props_ptr; + __u64 prop_values_ptr; + __u32 count_props; + __u32 obj_id; + __u32 obj_type; +}; + +struct drm_mode_obj_set_property { + __u64 value; + __u32 prop_id; + __u32 obj_id; + __u32 obj_type; +}; + struct drm_mode_get_blob { __u32 blob_id; __u32 length; diff --git a/xf86drmMode.c b/xf86drmMode.c index c809c44..a60c7cb 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -974,3 +974,86 @@ void drmModeFreePlaneResources(drmModePlaneResPtr ptr) drmFree(ptr->planes); drmFree(ptr); } + +drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd, + uint32_t object_id, + uint32_t object_type) +{ + struct drm_mode_obj_get_properties properties; + drmModeObjectPropertiesPtr ret = NULL; + uint32_t count; + +retry: + memset(&properties, 0, sizeof(struct drm_mode_obj_get_properties)); + properties.obj_id = object_id; + properties.obj_type = object_type; + + if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties)) + return 0; + + count = properties.count_props; + + if (count) { + properties.props_ptr = VOID2U64(drmMalloc(count * + sizeof(uint32_t))); + if (!properties.props_ptr) + goto err_allocs; + properties.prop_values_ptr = VOID2U64(drmMalloc(count * + sizeof(uint64_t))); + if (!properties.prop_values_ptr) + goto err_allocs; + } + + if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties)) + goto err_allocs; + + if (count < properties.count_props) { + drmFree(U642VOID(properties.props_ptr)); + drmFree(U642VOID(properties.prop_values_ptr)); + goto retry; + } + count = properties.count_props; + + ret = drmMalloc(sizeof(*ret)); + if (!ret) + goto err_allocs; + + ret->count_props = count; + ret->props = drmAllocCpy(U642VOID(properties.props_ptr), + count, sizeof(uint32_t)); + ret->prop_values = drmAllocCpy(U642VOID(properties.prop_values_ptr), + count, sizeof(uint64_t)); + if (ret->count_props && (!ret->props || !ret->prop_values)) { + drmFree(ret->props); + drmFree(ret->prop_values); + drmFree(ret); + ret = NULL; + } + +err_allocs: + drmFree(U642VOID(properties.props_ptr)); + drmFree(U642VOID(properties.prop_values_ptr)); + return ret; +} + +void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr) +{ + if (!ptr) + return; + drmFree(ptr->props); + drmFree(ptr->prop_values); + drmFree(ptr); +} + +int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type, + uint32_t property_id, uint64_t value) +{ + struct drm_mode_obj_set_property prop; + + prop.value = value; + prop.prop_id = property_id; + prop.obj_id = object_id; + prop.obj_type = object_type; + + return DRM_IOCTL(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY, &prop); +} diff --git a/xf86drmMode.h b/xf86drmMode.h index 991e3f9..8e40034 100644 --- a/xf86drmMode.h +++ b/xf86drmMode.h @@ -281,6 +281,12 @@ typedef struct _drmModeConnector { uint32_t *encoders; /**< List of encoder ids */ } drmModeConnector, *drmModeConnectorPtr; +typedef struct _drmModeObjectProperties { + uint32_t count_props; + uint32_t *props; + uint64_t *prop_values; +} drmModeObjectProperties, *drmModeObjectPropertiesPtr; + typedef struct _drmModePlane { uint32_t count_formats; uint32_t *formats; @@ -428,6 +434,14 @@ extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h); +extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd, + uint32_t object_id, + uint32_t object_type); +extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr); +extern int drmModeObjectSetProperty(int fd, uint32_t object_id, + uint32_t object_type, uint32_t property_id, + uint64_t value); + #if defined(__cplusplus) || defined(c_plusplus) } #endif