From: Paulo Zanoni paulo.r.zanoni@intel.com
Use unsigned int instead of int: - modetest.c:89:1: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] - modetest.c:97:1: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] - modetest.c:117:1: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] - modetest.c:772:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
The 'fd' variable is global, we don't need to pass it as an argument: - modetest.c:698:40: warning: unused parameter ‘fd’ [-Wunused-parameter]
We don't use the 'modeset' variable: - modetest.c:725:8: warning: variable ‘modeset’ set but not used [-Wunused-but-set-variable]
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- tests/modetest/modetest.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 229ab8a..c0f7ad7 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -70,7 +70,7 @@ struct type_name {
#define type_name_fn(res) \ char * res##_str(int type) { \ - int i; \ + unsigned int i; \ for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \ if (res##_names[i].type == type) \ return res##_names[i].name; \ @@ -695,7 +695,7 @@ void usage(char *name)
#define dump_resource(res) if (res) dump_##res()
-static int page_flipping_supported(int fd) +static int page_flipping_supported(void) { /*FIXME: generic ioctl needed? */ return 1; @@ -722,8 +722,8 @@ int main(int argc, char **argv) int encoders = 0, connectors = 0, crtcs = 0, framebuffers = 0; int test_vsync = 0; char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx" }; - char *modeset = NULL; - int i, count = 0; + unsigned int i; + int count = 0; struct connector con_args[2]; opterr = 0; @@ -748,7 +748,6 @@ int main(int argc, char **argv) test_vsync = 1; break; case 's': - modeset = strdup(optarg); con_args[count].crtc = -1; if (sscanf(optarg, "%d:%64s", &con_args[count].id, @@ -780,7 +779,7 @@ int main(int argc, char **argv) } }
- if (test_vsync && !page_flipping_supported(fd)) { + if (test_vsync && !page_flipping_supported()) { fprintf(stderr, "page flipping not supported by drm.\n"); return -1; }
From: Paulo Zanoni paulo.r.zanoni@intel.com
Don't "continue" without freeing the connector.
192 bytes in 6 blocks are indirectly lost in loss record 6 of 12 at 0x4C2779D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x4E30DD8: drmMalloc (xf86drm.c:147) by 0x4E35024: drmAllocCpy (xf86drmMode.c:73) by 0x4E35D69: drmModeGetConnector (xf86drmMode.c:507) by 0x402F22: dump_connectors (modetest.c:181) by 0x40261B: main (modetest.c:801)
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- tests/modetest/modetest.c | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index c0f7ad7..2779d4f 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -198,17 +198,16 @@ void dump_connectors(void) printf("%s%d", j > 0 ? ", " : "", connector->encoders[j]); printf("\n");
- if (!connector->count_modes) - continue; - - printf(" modes:\n"); - printf(" name refresh (Hz) hdisp hss hse htot vdisp " - "vss vse vtot)\n"); - for (j = 0; j < connector->count_modes; j++) - dump_mode(&connector->modes[j]); - - printf(" props:\n"); - dump_props(connector); + if (connector->count_modes) { + printf(" modes:\n"); + printf(" name refresh (Hz) hdisp hss hse htot vdisp " + "vss vse vtot)\n"); + for (j = 0; j < connector->count_modes; j++) + dump_mode(&connector->modes[j]); + + printf(" props:\n"); + dump_props(connector); + }
drmModeFreeConnector(connector); }
From: Paulo Zanoni paulo.r.zanoni@intel.com
In the future we'll have more than just connector properties, so create a dump_prop function that can handle any property (instead of the current dump_props function that only handles connector properties).
Also, make this function print a lot more information about the existing properties.
Also change the printed indentation of the modes to make the output more readable.
The previous function dump_props also segfaulted when we didn't have enought permissions. The new function does not segfault in this case (by checking for the return value of drmModeGetProperty).
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- tests/modetest/modetest.c | 92 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 83 insertions(+), 9 deletions(-)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 2779d4f..52c81a9 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -43,6 +43,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <inttypes.h> #include <unistd.h> #include <string.h> #include <errno.h> @@ -144,7 +145,7 @@ void dump_encoders(void)
void dump_mode(drmModeModeInfo *mode) { - printf(" %s %d %d %d %d %d %d %d %d %d\n", + printf("\t%s %d %d %d %d %d %d %d %d %d\n", mode->name, mode->vrefresh, mode->hdisplay, @@ -158,16 +159,87 @@ void dump_mode(drmModeModeInfo *mode) }
static void -dump_props(drmModeConnector *connector) +dump_blob(uint32_t blob_id) +{ + uint32_t i; + unsigned char *blob_data; + drmModePropertyBlobPtr blob; + + blob = drmModeGetPropertyBlob(fd, blob_id); + 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) { - drmModePropertyPtr props; 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");
- for (i = 0; i < connector->count_props; i++) { - props = drmModeGetProperty(fd, connector->props[i]); - printf("\t%s, flags %d\n", props->name, props->flags); - drmModeFreeProperty(props); + 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); }
void dump_connectors(void) @@ -200,13 +272,15 @@ void dump_connectors(void)
if (connector->count_modes) { printf(" modes:\n"); - printf(" name refresh (Hz) hdisp hss hse htot vdisp " + printf("\tname refresh (Hz) hdisp hss hse htot vdisp " "vss vse vtot)\n"); for (j = 0; j < connector->count_modes; j++) dump_mode(&connector->modes[j]);
printf(" props:\n"); - dump_props(connector); + for (j = 0; j < connector->count_props; j++) + dump_prop(connector->props[j], + connector->prop_values[j]); }
drmModeFreeConnector(connector);
From: Paulo Zanoni paulo.r.zanoni@intel.com
New library calls: - drmModeCrtcGetProperties - drmModeFreeCrtcProperties - drmModeCrtcSetProperties
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- include/drm/drm.h | 2 + include/drm/drm_mode.h | 13 ++++++++ xf86drmMode.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ xf86drmMode.h | 12 +++++++ 4 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/include/drm/drm.h b/include/drm/drm.h index 8adb9d5..45eef57 100644 --- a/include/drm/drm.h +++ b/include/drm/drm.h @@ -717,6 +717,8 @@ struct drm_get_cap { #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_CRTC_GETPROPERTIES DRM_IOWR(0xB9, struct drm_mode_crtc_get_properties) +#define DRM_IOCTL_MODE_CRTC_SETPROPERTY DRM_IOWR(0xBA, struct drm_mode_crtc_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..2bc6b83 100644 --- a/include/drm/drm_mode.h +++ b/include/drm/drm_mode.h @@ -250,6 +250,19 @@ struct drm_mode_connector_set_property { __u32 connector_id; };
+struct drm_mode_crtc_get_properties { + __u64 props_ptr; + __u64 prop_values_ptr; + __u32 count_props; + __u32 crtc_id; +}; + +struct drm_mode_crtc_set_property { + __u64 value; + __u32 prop_id; + __u32 crtc_id; +}; + struct drm_mode_get_blob { __u32 blob_id; __u32 length; diff --git a/xf86drmMode.c b/xf86drmMode.c index c809c44..67cbc02 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -974,3 +974,82 @@ void drmModeFreePlaneResources(drmModePlaneResPtr ptr) drmFree(ptr->planes); drmFree(ptr); } + +drmModeCrtcPropertiesPtr drmModeCrtcGetProperties(int fd, uint32_t crtc_id) +{ + struct drm_mode_crtc_get_properties properties; + drmModeCrtcPropertiesPtr ret = NULL; + uint32_t count; + +retry: + memset(&properties, 0, sizeof(struct drm_mode_crtc_get_properties)); + properties.crtc_id = crtc_id; + + if (drmIoctl(fd, DRM_IOCTL_MODE_CRTC_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_CRTC_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 drmModeFreeCrtcProperties(drmModeCrtcPropertiesPtr ptr) +{ + if (!ptr) + return; + drmFree(ptr->props); + drmFree(ptr->prop_values); + drmFree(ptr); +} + +int drmModeCrtcSetProperty(int fd, uint32_t crtc_id, uint32_t property_id, + uint64_t value) +{ + struct drm_mode_crtc_set_property prop; + + prop.value = value; + prop.prop_id = property_id; + prop.crtc_id = crtc_id; + + return DRM_IOCTL(fd, DRM_IOCTL_MODE_CRTC_SETPROPERTY, &prop); +} diff --git a/xf86drmMode.h b/xf86drmMode.h index 991e3f9..f2733ec 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 _drmModeCrtcProperties { + uint32_t count_props; + uint32_t *props; + uint64_t *prop_values; +} drmModeCrtcProperties, *drmModeCrtcPropertiesPtr; + typedef struct _drmModePlane { uint32_t count_formats; uint32_t *formats; @@ -428,6 +434,12 @@ 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 drmModeCrtcPropertiesPtr drmModeCrtcGetProperties(int fd, + uint32_t crtc_id); +extern void drmModeFreeCrtcProperties(drmModeCrtcPropertiesPtr ptr); +extern int drmModeCrtcSetProperty(int fd, uint32_t crtc_id, + uint32_t property_id, uint64_t value); + #if defined(__cplusplus) || defined(c_plusplus) } #endif
From: Paulo Zanoni paulo.r.zanoni@intel.com
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- tests/modetest/modetest.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 52c81a9..58bb39e 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -291,7 +291,9 @@ void dump_connectors(void) void dump_crtcs(void) { drmModeCrtc *crtc; + drmModeCrtcPropertiesPtr props; int i; + uint32_t j;
printf("CRTCs:\n"); printf("id\tfb\tpos\tsize\n"); @@ -310,6 +312,17 @@ void dump_crtcs(void) crtc->width, crtc->height); dump_mode(&crtc->mode);
+ printf(" props:\n"); + props = drmModeCrtcGetProperties(fd, crtc->crtc_id); + if (props) { + for (j = 0; j < props->count_props; j++) + dump_prop(props->props[j], + props->prop_values[j]); + drmModeFreeCrtcProperties(props); + } else { + printf("\tcould not get crtc properties\n"); + } + drmModeFreeCrtc(crtc); } printf("\n");
dri-devel@lists.freedesktop.org