From patchwork Tue Jun 5 18:06:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 9117 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 49A2223E1B for ; Tue, 5 Jun 2012 18:06:56 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 02ECEA183B5 for ; Tue, 5 Jun 2012 18:06:55 +0000 (UTC) Received: by ghbz12 with SMTP id z12so4822633ghb.11 for ; Tue, 05 Jun 2012 11:06:55 -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=pwfv5hd+mYEIGtY+tL1L2uMv0tyOjj3+kRZyO6MHt2c=; b=CWpkQtzC6JD3UqYrVTC8imkGZLgyFAhPFXJHXvC22wkQfSeA51dVrdvEuplHqj3ma6 9Cxkb3Pja/urIuIhelrj3dWaYbead/tALeavszTdJpNWX0h8b717IJ85URq9TI/wRr7z wU+Fs9NPiKw651+V/cUAvEVE35uRhjnZEXmZvMfW9IBzkZln6nPWrM9NCRXRbjF0QbbP mXNx3zuZ04NOvReD73LAd0Z+mFxLL9jN6d1c3QyZLFYTWYgIAHBJiLYi/P4T2ou6yHXj dwAD+WyFD5TxTNN5xqOO1cZYHctkXE1DUtmkafYrjkYaZEQRpEJ8fvkNi7zvhJy4sSeO JDQQ== Received: by 10.50.57.167 with SMTP id j7mr3750675igq.53.1338919615206; Tue, 05 Jun 2012 11:06:55 -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 v20csp39693ibb; Tue, 5 Jun 2012 11:06:54 -0700 (PDT) Received: by 10.236.78.200 with SMTP id g48mr12417316yhe.124.1338919614246; Tue, 05 Jun 2012 11:06:54 -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.54 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jun 2012 11:06:54 -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 mail-gh0-f178.google.com with SMTP id f1so5116173ghb.37 for ; Tue, 05 Jun 2012 11:06:54 -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=pwfv5hd+mYEIGtY+tL1L2uMv0tyOjj3+kRZyO6MHt2c=; b=BtzMpArHAuHErs/M8UjsF23JkmRFWcen9JPu1TPII1jdZs4SdwVfVpgki+on+hbplL Iw2SW0NGhYlnEAW0zZh79+W5sF5y8uzs/PcbPlUvbQpWqbHQWJnFiCZlRVbGngnXoqj8 6BPXofJ9Y+Kt+PMyOv/2U3anwn2dPcyhOheHgCedzmFlnk18U/c7yD5K9yWq4iQty3vb 3ktUtxU3Zbotsiy907yYgv9U/jH5FpPcmnLVKyGJPSErrLl8uxwN6DYdxwnQ/SQDfRBN o39NLaOy3fSSD1Zn3H8A9AOoDEW3Z30zuTERftdN4uAfjRHer9fQf6Rvto5q1EAUDn/M qurA== Received: by 10.60.2.131 with SMTP id 3mr17428230oeu.59.1338919613838; Tue, 05 Jun 2012 11:06:53 -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 ig3sm1776996obb.18.2012.06.05.11.06.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jun 2012 11:06:53 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, Paulo Zanoni Subject: [PATCH libdrm 3/8] tests: add proptest Date: Tue, 5 Jun 2012 13:06:29 -0500 Message-Id: <1338919594-25392-4-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: ALoCoQmZacbtOsXn2jCESUhHHp9YUGsdwsoSEw8FE2+Ptdee9w+XyCVT1V3c7oExGIBkvgK6vstf From: Paulo Zanoni A small program that allows us to see and modify properties. Reviewed-by: Rob Clark Signed-off-by: Paulo Zanoni --- configure.ac | 1 + tests/Makefile.am | 2 +- tests/proptest/Makefile.am | 11 ++ tests/proptest/proptest.c | 317 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 tests/proptest/Makefile.am create mode 100644 tests/proptest/proptest.c diff --git a/configure.ac b/configure.ac index e6e9a9f..73558ce 100644 --- a/configure.ac +++ b/configure.ac @@ -329,6 +329,7 @@ AC_CONFIG_FILES([ tests/modeprint/Makefile tests/modetest/Makefile tests/kmstest/Makefile + tests/proptest/Makefile tests/radeon/Makefile tests/vbltest/Makefile include/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index a3a59bd..1442854 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,7 +10,7 @@ check_PROGRAMS = \ dristat \ drmstat -SUBDIRS = modeprint +SUBDIRS = modeprint proptest if HAVE_LIBKMS SUBDIRS += kmstest modetest diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am new file mode 100644 index 0000000..f81a3c0 --- /dev/null +++ b/tests/proptest/Makefile.am @@ -0,0 +1,11 @@ +AM_CFLAGS = \ + -I$(top_srcdir)/include/drm \ + -I$(top_srcdir) + +noinst_PROGRAMS = \ + proptest + +proptest_SOURCES = \ + proptest.c +proptest_LDADD = \ + $(top_builddir)/libdrm.la diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c new file mode 100644 index 0000000..52896fe --- /dev/null +++ b/tests/proptest/proptest.c @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Paulo Zanoni + * + */ + +#include +#include +#include +#include +#include +#include + +#include "xf86drm.h" +#include "xf86drmMode.h" + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +int fd; +drmModeResPtr res = NULL; + +const char *connector_type_str(uint32_t type) +{ + switch (type) { + case DRM_MODE_CONNECTOR_Unknown: + return "Unknown"; + case DRM_MODE_CONNECTOR_VGA: + return "VGA"; + case DRM_MODE_CONNECTOR_DVII: + return "DVI-I"; + case DRM_MODE_CONNECTOR_DVID: + return "DVI-D"; + case DRM_MODE_CONNECTOR_DVIA: + return "DVI-A"; + case DRM_MODE_CONNECTOR_Composite: + return "Composite"; + case DRM_MODE_CONNECTOR_SVIDEO: + return "SVIDEO"; + case DRM_MODE_CONNECTOR_LVDS: + return "LVDS"; + case DRM_MODE_CONNECTOR_Component: + return "Component"; + case DRM_MODE_CONNECTOR_9PinDIN: + return "9PinDin"; + case DRM_MODE_CONNECTOR_DisplayPort: + return "DisplayPort"; + case DRM_MODE_CONNECTOR_HDMIA: + return "HDMI-A"; + case DRM_MODE_CONNECTOR_HDMIB: + return "HDMI-B"; + case DRM_MODE_CONNECTOR_TV: + return "TV"; + case DRM_MODE_CONNECTOR_eDP: + return "eDP"; + default: + return "Invalid"; + } +} + +/* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c */ +static void +dump_blob(uint32_t blob_id) +{ + uint32_t i; + unsigned char *blob_data; + drmModePropertyBlobPtr blob; + + blob = drmModeGetPropertyBlob(fd, blob_id); + if (!blob) + return; + + blob_data = blob->data; + + for (i = 0; i < blob->length; i++) { + if (i % 16 == 0) + printf("\n\t\t\t"); + printf("%.2hhx", blob_data[i]); + } + printf("\n"); + + drmModeFreePropertyBlob(blob); +} + +static void +dump_prop(uint32_t prop_id, uint64_t value) +{ + int i; + drmModePropertyPtr prop; + + prop = drmModeGetProperty(fd, prop_id); + + printf("\t%d", prop_id); + if (!prop) { + printf("\n"); + return; + } + + printf(" %s:\n", prop->name); + + printf("\t\tflags:"); + if (prop->flags & DRM_MODE_PROP_PENDING) + printf(" pending"); + if (prop->flags & DRM_MODE_PROP_RANGE) + printf(" range"); + if (prop->flags & DRM_MODE_PROP_IMMUTABLE) + printf(" immutable"); + if (prop->flags & DRM_MODE_PROP_ENUM) + printf(" enum"); + if (prop->flags & DRM_MODE_PROP_BLOB) + printf(" blob"); + printf("\n"); + + if (prop->flags & DRM_MODE_PROP_RANGE) { + printf("\t\tvalues:"); + for (i = 0; i < prop->count_values; i++) + printf(" %"PRIu64, prop->values[i]); + printf("\n"); + } + + if (prop->flags & DRM_MODE_PROP_ENUM) { + printf("\t\tenums:"); + for (i = 0; i < prop->count_enums; i++) + printf(" %s=%llu", prop->enums[i].name, + prop->enums[i].value); + printf("\n"); + } else { + assert(prop->count_enums == 0); + } + + if (prop->flags & DRM_MODE_PROP_BLOB) { + printf("\t\tblobs:\n"); + for (i = 0; i < prop->count_blobs; i++) + dump_blob(prop->blob_ids[i]); + printf("\n"); + } else { + assert(prop->count_blobs == 0); + } + + printf("\t\tvalue:"); + if (prop->flags & DRM_MODE_PROP_BLOB) + dump_blob(value); + else + printf(" %"PRIu64"\n", value); + + drmModeFreeProperty(prop); +} + +static void listObjectProperties(uint32_t id, uint32_t type) +{ + unsigned int i; + drmModeObjectPropertiesPtr props; + + props = drmModeObjectGetProperties(fd, id, type); + + if (!props) { + printf("\tNo properties: %s.\n", strerror(errno)); + return; + } + + for (i = 0; i < props->count_props; i++) + dump_prop(props->props[i], props->prop_values[i]); + + drmModeFreeObjectProperties(props); +} + +static void listConnectorProperties(void) +{ + int i; + drmModeConnectorPtr c; + + for (i = 0; i < res->count_connectors; i++) { + c = drmModeGetConnector(fd, res->connectors[i]); + + if (!c) { + fprintf(stderr, "Could not get connector %u: %s\n", + res->connectors[i], strerror(errno)); + continue; + } + + printf("Connector %u (%s-%u)\n", c->connector_id, + connector_type_str(c->connector_type), + c->connector_type_id); + + listObjectProperties(c->connector_id, + DRM_MODE_OBJECT_CONNECTOR); + + drmModeFreeConnector(c); + } +} + +static void listCrtcProperties(void) +{ + int i; + drmModeCrtcPtr c; + + for (i = 0; i < res->count_crtcs; i++) { + c = drmModeGetCrtc(fd, res->crtcs[i]); + + if (!c) { + fprintf(stderr, "Could not get crtc %u: %s\n", + res->crtcs[i], strerror(errno)); + continue; + } + + printf("CRTC %u\n", c->crtc_id); + + listObjectProperties(c->crtc_id, DRM_MODE_OBJECT_CRTC); + + drmModeFreeCrtc(c); + } +} + +static void listAllProperties(void) +{ + listConnectorProperties(); + listCrtcProperties(); +} + +static int setProperty(char *argv[]) +{ + uint32_t obj_id, obj_type, prop_id; + uint64_t value; + + obj_id = atoi(argv[1]); + + if (!strcmp(argv[2], "connector")) { + obj_type = DRM_MODE_OBJECT_CONNECTOR; + } else if (!strcmp(argv[2], "crtc")) { + obj_type = DRM_MODE_OBJECT_CRTC; + } else { + fprintf(stderr, "Invalid object type.\n"); + return 1; + } + + prop_id = atoi(argv[3]); + value = atoll(argv[4]); + + return drmModeObjectSetProperty(fd, obj_id, obj_type, prop_id, value); +} + +static void printUsage(void) +{ + printf("Usage:\n" +" proptest\n" +" proptest [obj id] [obj type] [prop id] [value]\n" +"\n" +"The first form just prints all the existing properties. The second one is\n" +"used to set the value of a specified property. The object type can be one of\n" +"the following strings:\n" +" connector crtc\n" +"\n" +"Example:\n" +" proptest 7 connector 2 1\n" +"will set property 2 of connector 7 to 1\n"); +} + +int main(int argc, char *argv[]) +{ + char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm" }; + unsigned int i, ret = 0; + + for (i = 0; i < ARRAY_SIZE(modules); i++){ + fd = drmOpen(modules[i], NULL); + if (fd >= 0) { + printf("Module %s loaded.\n", modules[i]); + break; + } + } + + if (i == ARRAY_SIZE(modules)) { + fprintf(stderr, "Failed to load drm modules.\n"); + return 1; + } + + res = drmModeGetResources(fd); + if (!res) { + fprintf(stderr, "Failed to get resources: %s\n", + strerror(errno)); + ret = 1; + goto done; + } + + if (argc < 2) { + listAllProperties(); + } else if (argc == 5) { + ret = setProperty(argv); + } else { + printUsage(); + ret = 1; + } + + drmModeFreeResources(res); +done: + drmClose(fd); + return ret; +}