2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Paulo Zanoni <paulo.r.zanoni@intel.com>
37 #include "xf86drmMode.h"
39 #include "util/common.h"
42 static inline int64_t U642I64(uint64_t val
)
44 return (int64_t)*((int64_t *)&val
);
48 drmModeResPtr res
= NULL
;
50 /* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c */
52 dump_blob(uint32_t blob_id
)
55 unsigned char *blob_data
;
56 drmModePropertyBlobPtr blob
;
58 blob
= drmModeGetPropertyBlob(fd
, blob_id
);
64 blob_data
= blob
->data
;
66 for (i
= 0; i
< blob
->length
; i
++) {
69 printf("%.2hhx", blob_data
[i
]);
73 drmModeFreePropertyBlob(blob
);
77 dump_prop(uint32_t prop_id
, uint64_t value
)
80 drmModePropertyPtr prop
;
82 prop
= drmModeGetProperty(fd
, prop_id
);
84 printf("\t%d", prop_id
);
90 printf(" %s:\n", prop
->name
);
93 if (prop
->flags
& DRM_MODE_PROP_PENDING
)
95 if (prop
->flags
& DRM_MODE_PROP_IMMUTABLE
)
97 if (drm_property_type_is(prop
, DRM_MODE_PROP_SIGNED_RANGE
))
98 printf(" signed range");
99 if (drm_property_type_is(prop
, DRM_MODE_PROP_RANGE
))
101 if (drm_property_type_is(prop
, DRM_MODE_PROP_ENUM
))
103 if (drm_property_type_is(prop
, DRM_MODE_PROP_BITMASK
))
105 if (drm_property_type_is(prop
, DRM_MODE_PROP_BLOB
))
107 if (drm_property_type_is(prop
, DRM_MODE_PROP_OBJECT
))
112 if (drm_property_type_is(prop
, DRM_MODE_PROP_SIGNED_RANGE
)) {
113 printf("\t\tvalues:");
114 for (i
= 0; i
< prop
->count_values
; i
++)
115 printf(" %"PRId64
, U642I64(prop
->values
[i
]));
119 if (drm_property_type_is(prop
, DRM_MODE_PROP_RANGE
)) {
120 printf("\t\tvalues:");
121 for (i
= 0; i
< prop
->count_values
; i
++)
122 printf(" %"PRIu64
, prop
->values
[i
]);
126 if (drm_property_type_is(prop
, DRM_MODE_PROP_ENUM
)) {
127 printf("\t\tenums:");
128 for (i
= 0; i
< prop
->count_enums
; i
++)
129 printf(" %s=%"PRIu64
, prop
->enums
[i
].name
,
130 (uint64_t)prop
->enums
[i
].value
);
132 } else if (drm_property_type_is(prop
, DRM_MODE_PROP_BITMASK
)) {
133 printf("\t\tvalues:");
134 for (i
= 0; i
< prop
->count_enums
; i
++)
135 printf(" %s=0x%llx", prop
->enums
[i
].name
,
136 (1LL << prop
->enums
[i
].value
));
139 assert(prop
->count_enums
== 0);
142 if (drm_property_type_is(prop
, DRM_MODE_PROP_BLOB
)) {
143 printf("\t\tblobs:\n");
144 for (i
= 0; i
< prop
->count_blobs
; i
++)
145 dump_blob(prop
->blob_ids
[i
]);
148 assert(prop
->count_blobs
== 0);
151 printf("\t\tvalue:");
152 if (drm_property_type_is(prop
, DRM_MODE_PROP_BLOB
))
154 else if (drm_property_type_is(prop
, DRM_MODE_PROP_SIGNED_RANGE
))
155 printf(" %"PRId64
"\n", value
);
157 printf(" %"PRIu64
"\n", value
);
159 drmModeFreeProperty(prop
);
162 static void listObjectProperties(uint32_t id
, uint32_t type
)
165 drmModeObjectPropertiesPtr props
;
167 props
= drmModeObjectGetProperties(fd
, id
, type
);
170 printf("\tNo properties: %s.\n", strerror(errno
));
174 for (i
= 0; i
< props
->count_props
; i
++)
175 dump_prop(props
->props
[i
], props
->prop_values
[i
]);
177 drmModeFreeObjectProperties(props
);
180 static void listConnectorProperties(void)
183 drmModeConnectorPtr c
;
185 for (i
= 0; i
< res
->count_connectors
; i
++) {
186 c
= drmModeGetConnector(fd
, res
->connectors
[i
]);
189 fprintf(stderr
, "Could not get connector %u: %s\n",
190 res
->connectors
[i
], strerror(errno
));
194 printf("Connector %u (%s-%u)\n", c
->connector_id
,
195 drmModeGetConnectorTypeName(c
->connector_type
),
196 c
->connector_type_id
);
198 listObjectProperties(c
->connector_id
,
199 DRM_MODE_OBJECT_CONNECTOR
);
201 drmModeFreeConnector(c
);
205 static void listCrtcProperties(void)
210 for (i
= 0; i
< res
->count_crtcs
; i
++) {
211 c
= drmModeGetCrtc(fd
, res
->crtcs
[i
]);
214 fprintf(stderr
, "Could not get crtc %u: %s\n",
215 res
->crtcs
[i
], strerror(errno
));
219 printf("CRTC %u\n", c
->crtc_id
);
221 listObjectProperties(c
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
227 static void listAllProperties(void)
229 listConnectorProperties();
230 listCrtcProperties();
233 static int setProperty(char *argv
[])
235 uint32_t obj_id
, obj_type
, prop_id
;
238 obj_id
= atoi(argv
[0]);
240 if (!strcmp(argv
[1], "connector")) {
241 obj_type
= DRM_MODE_OBJECT_CONNECTOR
;
242 } else if (!strcmp(argv
[1], "crtc")) {
243 obj_type
= DRM_MODE_OBJECT_CRTC
;
245 fprintf(stderr
, "Invalid object type.\n");
249 prop_id
= atoi(argv
[2]);
250 value
= atoll(argv
[3]);
252 return drmModeObjectSetProperty(fd
, obj_id
, obj_type
, prop_id
, value
);
255 static void usage(const char *program
)
259 " %s [options] [obj id] [obj type] [prop id] [value]\n"
262 " -D DEVICE use the given device\n"
263 " -M MODULE use the given driver\n"
265 "The first form just prints all the existing properties. The second one is\n"
266 "used to set the value of a specified property. The object type can be one of\n"
267 "the following strings:\n"
271 " proptest 7 connector 2 1\n"
272 "will set property 2 of connector 7 to 1\n", program
, program
);
275 int main(int argc
, char *argv
[])
277 static const char optstr
[] = "D:M:";
278 int c
, args
, ret
= 0;
282 while ((c
= getopt(argc
, argv
, optstr
)) != -1) {
298 args
= argc
- optind
;
300 fd
= util_open(device
, module
);
304 res
= drmModeGetResources(fd
);
306 fprintf(stderr
, "Failed to get resources: %s\n",
314 } else if (args
== 4) {
315 ret
= setProperty(&argv
[optind
]);
321 drmModeFreeResources(res
);