From f6e8023e03278731db38dcc0c429025f36817c65 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 5 Jun 2007 12:26:18 +1000 Subject: take the lock earlier in ttmtest --- tests/ttmtest/src/ttmtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/ttmtest/src/ttmtest.c b/tests/ttmtest/src/ttmtest.c index 606fb0cb..052947b1 100644 --- a/tests/ttmtest/src/ttmtest.c +++ b/tests/ttmtest/src/ttmtest.c @@ -176,7 +176,7 @@ benchmarkBuffer(TinyDRIContext * ctx, unsigned long size, /* * Test system memory objects. */ - + BM_CKFATAL(drmGetLock(ctx->drmFD, ctx->hwContext, 0)); oldTime = fastrdtsc(); BM_CKFATAL(drmBOCreate(ctx->drmFD, 0, size, 0, NULL, drm_bo_type_dc, @@ -216,7 +216,7 @@ benchmarkBuffer(TinyDRIContext * ctx, unsigned long size, * Test TT bound buffer objects. */ - BM_CKFATAL(drmGetLock(ctx->drmFD, ctx->hwContext, 0)); + // BM_CKFATAL(drmGetLock(ctx->drmFD, ctx->hwContext, 0)); oldTime = fastrdtsc(); BM_CKFATAL(drmBOValidate(ctx->drmFD, &buf, DRM_BO_FLAG_MEM_TT, DRM_BO_MASK_MEM, DRM_BO_HINT_DONT_FENCE)); -- cgit v1.2.3 From 2a2d02bbc500140a861380df52ce66abcac39312 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 24 Sep 2007 14:53:10 +0200 Subject: Added small modesetting test --- tests/mode/Makefile | 11 ++ tests/mode/modetest.c | 337 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/mode/test | 1 + 3 files changed, 349 insertions(+) create mode 100644 tests/mode/Makefile create mode 100644 tests/mode/modetest.c create mode 100755 tests/mode/test (limited to 'tests') diff --git a/tests/mode/Makefile b/tests/mode/Makefile new file mode 100644 index 00000000..205c2ba1 --- /dev/null +++ b/tests/mode/Makefile @@ -0,0 +1,11 @@ + +all: modetest + +#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ +# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ + +modetest: modetest.c + @gcc -o modetest -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c + +clean: + @rm -f modetest diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c new file mode 100644 index 00000000..bf1a5169 --- /dev/null +++ b/tests/mode/modetest.c @@ -0,0 +1,337 @@ + +#include +#include +#include +#include + +#include "xf86drm.h" +#include "xf86drmMode.h" + +const char* getConnectionText(drmModeConnection conn) +{ + switch (conn) { + case DRM_MODE_CONNECTED: + return "connected"; + case DRM_MODE_DISCONNECTED: + return "disconnected"; + default: + return "unknown"; + } + +} + +struct drm_mode_modeinfo* findMode(drmModeResPtr res, uint32_t id) +{ + int i; + for (i = 0; i < res->count_modes; i++) { + if (res->modes[i].id == id) + return &res->modes[i]; + } + + return 0; +} + +int printMode(struct drm_mode_modeinfo *mode) +{ +#if 0 + printf("Mode: %s\n", mode->name); + printf("\tclock : %i\n", mode->clock); + printf("\thdisplay : %i\n", mode->hdisplay); + printf("\thsync_start : %i\n", mode->hsync_start); + printf("\thsync_end : %i\n", mode->hsync_end); + printf("\thtotal : %i\n", mode->htotal); + printf("\thskew : %i\n", mode->hskew); + printf("\tvdisplay : %i\n", mode->vdisplay); + printf("\tvsync_start : %i\n", mode->vsync_start); + printf("\tvsync_end : %i\n", mode->vsync_end); + printf("\tvtotal : %i\n", mode->vtotal); + printf("\tvscan : %i\n", mode->vscan); + printf("\tvrefresh : %i\n", mode->vrefresh); + printf("\tflags : %i\n", mode->flags); +#else + printf("Mode: %i \"%s\" %ix%i %.0f\n", mode->id, mode->name, + mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0); +#endif + return 0; +} + +int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) +{ + int i = 0; + struct drm_mode_modeinfo *mode = NULL; + + printf("Output: %s\n", output->name); + printf("\tid : %i\n", id); + printf("\tcrtc id : %i\n", output->crtc); + printf("\tconn : %s\n", getConnectionText(output->connection)); + printf("\tsize : %ix%i (mm)\n", output->mmWidth, output->mmHeight); + printf("\tcount_crtcs : %i\n", output->count_crtcs); + printf("\tcrtcs : %i\n", output->crtcs); + printf("\tcount_clones : %i\n", output->count_clones); + printf("\tclones : %i\n", output->clones); + printf("\tcount_modes : %i\n", output->count_modes); + + for (i = 0; i < output->count_modes; i++) { + mode = findMode(res, output->modes[i]); + + if (mode) + printf("\t\tmode: %i \"%s\" %ix%i %.0f\n", mode->id, mode->name, + mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0); + else + printf("\t\tmode: Invalid mode %i\n", output->modes[i]); + } + + return 0; +} + +int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) +{ + printf("Crtc\n"); + printf("\tid : %i\n", id); + printf("\tx : %i\n", crtc->x); + printf("\ty : %i\n", crtc->y); + printf("\twidth : %i\n", crtc->width); + printf("\theight : %i\n", crtc->height); + printf("\tmode : %i\n", crtc->mode); + printf("\tnum outputs : %i\n", crtc->count_outputs); + printf("\toutputs : %i\n", crtc->outputs); + printf("\tnum possible : %i\n", crtc->count_possibles); + printf("\tpossibles : %i\n", crtc->possibles); + + return 0; +} + +int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb) +{ + printf("Framebuffer\n"); + printf("\thandle : %i\n", fb->handle); + printf("\twidth : %i\n", fb->width); + printf("\theight : %i\n", fb->height); + printf("\tpitch : %i\n", fb->pitch);; + printf("\tbpp : %i\n", fb->bpp); + printf("\tdepth : %i\n", fb->depth); + printf("\tbuffer_id : %i\n", fb->buffer_id); + + return 0; +} + +int printRes(int fd, drmModeResPtr res) +{ + int i; + drmModeOutputPtr output; + drmModeCrtcPtr crtc; + drmModeFBPtr fb; + + for (i = 0; i < res->count_modes; i++) { + printMode(&res->modes[i]); + } + + for (i = 0; i < res->count_outputs; i++) { + output = drmModeGetOutput(fd, res->outputs[i]); + + if (!output) + printf("Could not get output %i\n", i); + else { + printOutput(fd, res, output, res->outputs[i]); + drmModeFreeOutput(output); + } + } + + for (i = 0; i < res->count_crtcs; i++) { + crtc = drmModeGetCrtc(fd, res->crtcs[i]); + + if (!crtc) + printf("Could not get crtc %i\n", i); + else { + printCrtc(fd, res, crtc, res->crtcs[i]); + drmModeFreeCrtc(crtc); + } + } + + for (i = 0; i < res->count_fbs; i++) { + fb = drmModeGetFB(fd, res->fbs[i]); + + if (!fb) + printf("Could not get fb %i\n", res->fbs[i]); + else { + printFrameBuffer(fd, res, fb); + drmModeFreeFB(fb); + } + } + + return 0; +} + +static struct drm_mode_modeinfo mode = { + .name = "Test mode", + .clock = 25200, + .hdisplay = 640, + .hsync_start = 656, + .hsync_end = 752, + .htotal = 800, + .hskew = 0, + .vdisplay = 480, + .vsync_start = 490, + .vsync_end = 492, + .vtotal = 525, + .vscan = 0, + .vrefresh = 60000, /* vertical refresh * 1000 */ + .flags = 10, +}; + +int testMode(int fd, drmModeResPtr res) +{ + uint32_t output = res->outputs[0]; + uint32_t newMode = 0; + int ret = 0; + int error = 0; + + printf("Test: adding mode to output %i\n", output); + + /* printMode(&mode); */ + + printf("\tAdding mode\n"); + newMode = drmModeAddMode(fd, &mode); + if (!newMode) + goto err; + + printf("\tAttaching mode %i to output %i\n", newMode, output); + + ret = drmModeAttachMode(fd, output, newMode); + + if (ret) + goto err_mode; + + printf("\tDetaching mode %i from output %i\n", newMode, output); + ret = drmModeDetachMode(fd, output, newMode); + + if (ret) + goto err_mode; + + printf("\tRemoveing new mode %i\n", newMode); + ret = drmModeRmMode(fd, newMode); + if (ret) + goto err; + + return 0; + +err_mode: + error = drmModeRmMode(fd, newMode); + +err: + printf("\tFailed\n"); + + if (error) + printf("\tFailed to delete mode %i\n", newMode); + + return 1; +} + +/* +int testFrameBufferGet(int fd, uint32_t fb) +{ + drmModeFBPtr frame; + + printf("Test: get framebuffer %i\n", fb); + + frame = drmModeGetFB(fd, fb); + + if (!frame) { + printf("\tFailed\n"); + } else { + printFrameBuffer(fd, frame); + drmModeFreeFB(frame); + } + + return 0; +} +*/ + +int testFrameBufferAdd(int fd, drmModeResPtr res) +{ + uint32_t fb = 0; + int ret = 0; + drmModeFBPtr frame = 0; + drmBO bo; + + printf("Test: adding framebuffer\n"); + + printf("\tCreating BO\n"); + + /* TODO */ + ret = 1; + if (ret) + goto err; + + printf("\tAdding FB\n"); + ret = drmModeAddFB(fd, 640, 480, 32, 8, 0, &bo, &fb); + if (ret) + goto err_bo; + + frame = drmModeGetFB(fd, fb); + + if (!frame) { + printf("Couldn't retrive created framebuffer\n"); + } else { + printFrameBuffer(fd, res, frame); + drmModeFreeFB(frame); + } + + printf("\tRemoveing FB\n"); + + ret = drmModeRmFB(fd, fb); + + if (ret) { + printf("\tFailed this shouldn't happen!\n"); + goto err_bo; + } + + printf("\tRemoveing BO\n"); + + ret = drmBODestroy(fb, &bo); + + return 0; + +err_bo: + drmBODestroy(fd, &bo); + +err: + printf("\tFailed\n"); + + return 1; +} + + +int main(int argc, char **argv) +{ + int fd; + const char *driver = "i915"; /* hardcoded for now */ + drmModeResPtr res; + + printf("Starting test\n"); + + fd = drmOpen(driver, NULL); + + if (fd < 0) { + printf("Failed to open the card fb\n"); + return 1; + } + + res = drmModeGetResources(fd); + if (res == 0) { + printf("Failed to get resources from card\n"); + drmClose(fd); + return 1; + } + + printRes(fd, res); + + testMode(fd, res); + + testFrameBufferAdd(fd, res); + + drmModeFreeResources(res); + printf("Ok\n"); + + return 0; +} diff --git a/tests/mode/test b/tests/mode/test new file mode 100755 index 00000000..fa155f4e --- /dev/null +++ b/tests/mode/test @@ -0,0 +1 @@ +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./modetest -- cgit v1.2.3 From d275bb8fb87d8dc23e9a62c5f82627e36c8dc589 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 15 Nov 2007 16:51:15 +1100 Subject: tests: update for new drm interface --- tests/mode/modetest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index bf1a5169..8f151758 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -288,12 +288,12 @@ int testFrameBufferAdd(int fd, drmModeResPtr res) printf("\tRemoveing BO\n"); - ret = drmBODestroy(fb, &bo); + ret = drmBOUnreference(fb, &bo); return 0; err_bo: - drmBODestroy(fd, &bo); + drmBOUnreference(fd, &bo); err: printf("\tFailed\n"); -- cgit v1.2.3 From b3af2b59a77a6916ea7151236d3da9bde6a537fc Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 27 Nov 2007 14:31:02 +1000 Subject: drm/modesetting: add initial gettable properites code. This allow the user to retrieve a list of properties for an output. Properties can either be 32-bit values or an enum with an associated name. Range properties are to be supported. This API is probably not all correct, I may make properties part of the general resource get when I think about it some more. So basically you can create properties and attached them to whatever outputs you want, so it should be possible to create some generics and just attach them to every output. --- tests/mode/modetest.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 8f151758..50271af9 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -57,8 +57,10 @@ int printMode(struct drm_mode_modeinfo *mode) int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) { - int i = 0; + int i = 0, j; struct drm_mode_modeinfo *mode = NULL; + drmModePropertyPtr props; + unsigned char *name = NULL; printf("Output: %s\n", output->name); printf("\tid : %i\n", id); @@ -70,6 +72,36 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) printf("\tcount_clones : %i\n", output->count_clones); printf("\tclones : %i\n", output->clones); printf("\tcount_modes : %i\n", output->count_modes); + printf("\tcount_props : %i\n", output->count_props); + + for (i = 0; i < output->count_props; i++) { + props = drmModeGetProperty(fd, output->props[i]); + name = NULL; + if (props) { + printf("Property: %s\n", props->name); + printf("\tid: %i\n", props->prop_id); + printf("\tflags: %i\n", props->flags); + printf("\tvalues %d: ", props->count_values); + for (j = 0; j < props->count_values; j++) + printf("%d ", props->values[j]); + + printf("\n\tenums %d: \n", props->count_enums); + + for (j = 0; j < props->count_enums; j++) { + if (output->prop_values[i] == props->enums[j].value) + name = props->enums[j].name; + printf("\t\t%d = %s\n", props->enums[j].value, props->enums[j].name); + } + + if (props->count_enums && name) { + printf("\toutput property name %s %s\n", props->name, name); + } else { + printf("\toutput property id %s %i\n", props->name, output->prop_values[i]); + } + + drmModeFreeProperty(props); + } + } for (i = 0; i < output->count_modes; i++) { mode = findMode(res, output->modes[i]); -- cgit v1.2.3 From 91cd3e3c097d581ea75ec4bcbc1ba8d23b471a2e Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 28 Nov 2007 15:18:25 +1000 Subject: modesetting API change for removing mode ids and making modes per output. so really want to get a list of modes per output not the global hammer list. also we remove the mode ids and let the user pass back the full mode description need to fix up add/remove mode for user modes now --- tests/mode/modetest.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 50271af9..2871fde4 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -20,20 +20,9 @@ const char* getConnectionText(drmModeConnection conn) } -struct drm_mode_modeinfo* findMode(drmModeResPtr res, uint32_t id) -{ - int i; - for (i = 0; i < res->count_modes; i++) { - if (res->modes[i].id == id) - return &res->modes[i]; - } - - return 0; -} - int printMode(struct drm_mode_modeinfo *mode) { -#if 0 +#if 1 printf("Mode: %s\n", mode->name); printf("\tclock : %i\n", mode->clock); printf("\thdisplay : %i\n", mode->hdisplay); @@ -49,7 +38,7 @@ int printMode(struct drm_mode_modeinfo *mode) printf("\tvrefresh : %i\n", mode->vrefresh); printf("\tflags : %i\n", mode->flags); #else - printf("Mode: %i \"%s\" %ix%i %.0f\n", mode->id, mode->name, + printf("Mode: \"%s\" %ix%i %.0f\n", mode->name, mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0); #endif return 0; @@ -104,11 +93,9 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) } for (i = 0; i < output->count_modes; i++) { - mode = findMode(res, output->modes[i]); - + mode = &output->modes[i]; if (mode) - printf("\t\tmode: %i \"%s\" %ix%i %.0f\n", mode->id, mode->name, - mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0); + printMode(mode); else printf("\t\tmode: Invalid mode %i\n", output->modes[i]); } @@ -154,10 +141,6 @@ int printRes(int fd, drmModeResPtr res) drmModeCrtcPtr crtc; drmModeFBPtr fb; - for (i = 0; i < res->count_modes; i++) { - printMode(&res->modes[i]); - } - for (i = 0; i < res->count_outputs; i++) { output = drmModeGetOutput(fd, res->outputs[i]); @@ -218,6 +201,7 @@ int testMode(int fd, drmModeResPtr res) int ret = 0; int error = 0; +#if 0 printf("Test: adding mode to output %i\n", output); /* printMode(&mode); */ @@ -255,7 +239,7 @@ err: if (error) printf("\tFailed to delete mode %i\n", newMode); - +#endif return 1; } -- cgit v1.2.3 From 96df9b11ad8974d7a2a0a589114cbbb04a584f18 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 3 Dec 2007 13:42:32 +1000 Subject: finish of mode add/remove, just have attach/detach modes --- tests/mode/modetest.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 2871fde4..1d5002b0 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -201,45 +201,30 @@ int testMode(int fd, drmModeResPtr res) int ret = 0; int error = 0; -#if 0 printf("Test: adding mode to output %i\n", output); /* printMode(&mode); */ - printf("\tAdding mode\n"); - newMode = drmModeAddMode(fd, &mode); - if (!newMode) - goto err; - printf("\tAttaching mode %i to output %i\n", newMode, output); - ret = drmModeAttachMode(fd, output, newMode); + ret = drmModeAttachMode(fd, output, &mode); if (ret) goto err_mode; printf("\tDetaching mode %i from output %i\n", newMode, output); - ret = drmModeDetachMode(fd, output, newMode); + ret = drmModeDetachMode(fd, output, &mode); if (ret) goto err_mode; - - printf("\tRemoveing new mode %i\n", newMode); - ret = drmModeRmMode(fd, newMode); - if (ret) - goto err; - return 0; err_mode: - error = drmModeRmMode(fd, newMode); -err: printf("\tFailed\n"); if (error) printf("\tFailed to delete mode %i\n", newMode); -#endif return 1; } -- cgit v1.2.3 From 1a6c95ef711fce807659ab5e4fe480d65ac233b6 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Dec 2007 16:03:05 +1000 Subject: arrgggh.. make all ioctl structs 32/64-bit compatible hopefully. This also starts to add blob property support. someone needs to check this work for other things like ppc/x86 alignment diffs --- tests/mode/modetest.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 1d5002b0..46f88d82 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -76,16 +76,21 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) printf("\n\tenums %d: \n", props->count_enums); - for (j = 0; j < props->count_enums; j++) { - if (output->prop_values[i] == props->enums[j].value) - name = props->enums[j].name; - printf("\t\t%d = %s\n", props->enums[j].value, props->enums[j].name); - } + if (prop->flags & DRM_MODE_PROP_BLOB) { + - if (props->count_enums && name) { - printf("\toutput property name %s %s\n", props->name, name); } else { - printf("\toutput property id %s %i\n", props->name, output->prop_values[i]); + for (j = 0; j < props->count_enums; j++) { + if (output->prop_values[i] == props->enums[j].value) + name = props->enums[j].name; + printf("\t\t%d = %s\n", props->enums[j].value, props->enums[j].name); + } + + if (props->count_enums && name) { + printf("\toutput property name %s %s\n", props->name, name); + } else { + printf("\toutput property id %s %i\n", props->name, output->prop_values[i]); + } } drmModeFreeProperty(props); -- cgit v1.2.3 From 67f6eb1eb8d3dc5bb5fdb097655d3da326f637c1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 6 Dec 2007 10:44:51 +1000 Subject: add property blobs and edid reporting support --- tests/mode/modetest.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 46f88d82..c396da41 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -75,9 +75,14 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) printf("%d ", props->values[j]); printf("\n\tenums %d: \n", props->count_enums); + + if (props->flags & DRM_MODE_PROP_BLOB) { + drmModePropertyBlobPtr blob; - if (prop->flags & DRM_MODE_PROP_BLOB) { - + blob = drmModeGetPropertyBlob(fd, output->prop_values[i]); + + printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); + drmModeFreePropertyBlob(blob); } else { for (j = 0; j < props->count_enums; j++) { -- cgit v1.2.3 From 3b6786e3e6523b1ceca3645ea4c6081f170d2134 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 11 Dec 2007 14:46:51 +1000 Subject: modesetting: add dpms property and initial settable property ioctl --- tests/mode/Makefile | 2 +- tests/mode/modetest.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/mode/Makefile b/tests/mode/Makefile index 205c2ba1..a3d3b49a 100644 --- a/tests/mode/Makefile +++ b/tests/mode/Makefile @@ -5,7 +5,7 @@ all: modetest # -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ modetest: modetest.c - @gcc -o modetest -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c + @gcc $(CFLAGS) -o modetest -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c clean: @rm -f modetest diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index c396da41..4a8c6a17 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -80,15 +80,17 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) drmModePropertyBlobPtr blob; blob = drmModeGetPropertyBlob(fd, output->prop_values[i]); - - printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); - drmModeFreePropertyBlob(blob); + if (blob) { + printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); + drmModeFreePropertyBlob(blob); + } } else { for (j = 0; j < props->count_enums; j++) { + printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name); if (output->prop_values[i] == props->enums[j].value) name = props->enums[j].name; - printf("\t\t%d = %s\n", props->enums[j].value, props->enums[j].name); + } if (props->count_enums && name) { -- cgit v1.2.3 From f99dea7db00dd46aa96eaed3a61dff9c956fd86f Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 11 Dec 2007 15:56:48 +1000 Subject: modesetting: fixup property setting and add connector property --- tests/mode/modetest.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 4a8c6a17..f1fe64df 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -3,10 +3,13 @@ #include #include #include +#include +#include #include "xf86drm.h" #include "xf86drmMode.h" +int dpms_prop_id = 0; const char* getConnectionText(drmModeConnection conn) { switch (conn) { @@ -72,7 +75,7 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) printf("\tflags: %i\n", props->flags); printf("\tvalues %d: ", props->count_values); for (j = 0; j < props->count_values; j++) - printf("%d ", props->values[j]); + printf("%lld ", props->values[j]); printf("\n\tenums %d: \n", props->count_enums); @@ -86,6 +89,9 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) } } else { + if (!strncmp(props->name, "DPMS", 4)) + dpms_prop_id = props->prop_id; + for (j = 0; j < props->count_enums; j++) { printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name); if (output->prop_values[i] == props->enums[j].value) @@ -96,7 +102,7 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) if (props->count_enums && name) { printf("\toutput property name %s %s\n", props->name, name); } else { - printf("\toutput property id %s %i\n", props->name, output->prop_values[i]); + printf("\toutput property id %s %lli\n", props->name, output->prop_values[i]); } } @@ -109,7 +115,7 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) if (mode) printMode(mode); else - printf("\t\tmode: Invalid mode %i\n", output->modes[i]); + printf("\t\tmode: Invalid mode %p\n", &output->modes[i]); } return 0; @@ -123,7 +129,7 @@ int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) printf("\ty : %i\n", crtc->y); printf("\twidth : %i\n", crtc->width); printf("\theight : %i\n", crtc->height); - printf("\tmode : %i\n", crtc->mode); + printf("\tmode : %p\n", &crtc->mode); printf("\tnum outputs : %i\n", crtc->count_outputs); printf("\toutputs : %i\n", crtc->outputs); printf("\tnum possible : %i\n", crtc->count_possibles); @@ -314,6 +320,21 @@ err: return 1; } +int testDPMS(int fd, drmModeResPtr res) +{ + int output_id; + int i; + + for (i = 0; i < res->count_outputs; i++) { + output_id = res->outputs[i]; + /* turn output off */ + drmModeOutputSetProperty(fd, output_id, dpms_prop_id, 3); + sleep(2); + drmModeOutputSetProperty(fd, output_id, dpms_prop_id, 0); + } + return 1; + +} int main(int argc, char **argv) { @@ -343,6 +364,8 @@ int main(int argc, char **argv) testFrameBufferAdd(fd, res); + /* try dpms test */ + testDPMS(fd, res); drmModeFreeResources(res); printf("Ok\n"); -- cgit v1.2.3 From b13dc383df85d75cb1ea422f4d13efc2a4a8a732 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 18 Dec 2007 17:41:20 +1100 Subject: remove output names --- tests/mode/modetest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index f1fe64df..bd8372dc 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -54,7 +54,7 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) drmModePropertyPtr props; unsigned char *name = NULL; - printf("Output: %s\n", output->name); + printf("Output: %d-%d\n", output->output_type, output->output_type_id); printf("\tid : %i\n", id); printf("\tcrtc id : %i\n", output->crtc); printf("\tconn : %s\n", getConnectionText(output->connection)); -- cgit v1.2.3 From 73bf5e867089b58b2c4baaa833d15a2b1fb268a4 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 9 Jan 2008 16:44:31 +1100 Subject: add internals for opening a control node --- tests/dristat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dristat.c b/tests/dristat.c index 89853164..48c3b51b 100644 --- a/tests/dristat.c +++ b/tests/dristat.c @@ -263,7 +263,7 @@ int main(int argc, char **argv) for (i = 0; i < 16; i++) if (!minor || i == minor) { sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i); - fd = drmOpenMinor(i, 1); + fd = drmOpenMinor(i, 1, DRM_NODE_RENDER); if (fd >= 0) { printf("%s\n", buf); if (mask & DRM_BUSID) getbusid(fd); -- cgit v1.2.3 From 0a4df3372aec219298e3787f6f377941bc51bfcb Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 10 Jan 2008 05:03:13 +0100 Subject: Updated test mode and added modedemo --- tests/mode/Makefile | 11 +++-- tests/mode/modetest.c | 10 +++- tests/mode/test | 2 +- tests/modedemo/Makefile | 14 ++++++ tests/modedemo/demo.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/modedemo/test | 1 + 6 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 tests/modedemo/Makefile create mode 100644 tests/modedemo/demo.c create mode 100755 tests/modedemo/test (limited to 'tests') diff --git a/tests/mode/Makefile b/tests/mode/Makefile index a3d3b49a..7a9c3c24 100644 --- a/tests/mode/Makefile +++ b/tests/mode/Makefile @@ -1,11 +1,14 @@ -all: modetest +all: app #CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ # -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ -modetest: modetest.c - @gcc $(CFLAGS) -o modetest -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c +app: modetest.c + @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c clean: - @rm -f modetest + @rm -f app + +run: app + @sudo ./test diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index bd8372dc..c1f291b2 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -278,7 +278,15 @@ int testFrameBufferAdd(int fd, drmModeResPtr res) printf("\tCreating BO\n"); /* TODO */ - ret = 1; + ret = drmBOCreate(fd, 800 * 600 * 4, 0, 0, + DRM_BO_FLAG_READ | + DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_MEM_TT | + DRM_BO_FLAG_MEM_VRAM | + DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, &bo); + + printf("\tgot %i\n", ret); if (ret) goto err; diff --git a/tests/mode/test b/tests/mode/test index fa155f4e..f98e3708 100755 --- a/tests/mode/test +++ b/tests/mode/test @@ -1 +1 @@ -LD_PRELOAD=../../libdrm/.libs/libdrm.so ./modetest +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app diff --git a/tests/modedemo/Makefile b/tests/modedemo/Makefile new file mode 100644 index 00000000..467fb11a --- /dev/null +++ b/tests/modedemo/Makefile @@ -0,0 +1,14 @@ + +all: app + +#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ +# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ + +app: demo.c + @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm demo.c + +clean: + @rm -f app + +run: app + sudo ./test diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c new file mode 100644 index 00000000..ea71fd1d --- /dev/null +++ b/tests/modedemo/demo.c @@ -0,0 +1,119 @@ + +#include +#include +#include +#include +#include +#include + +#include "xf86drm.h" +#include "xf86drmMode.h" +static struct drm_mode_modeinfo mode = { + .name = "Test mode", + .clock = 25200, + .hdisplay = 640, + .hsync_start = 656, + .hsync_end = 752, + .htotal = 800, + .hskew = 0, + .vdisplay = 480, + .vsync_start = 490, + .vsync_end = 492, + .vtotal = 525, + .vscan = 0, + .vrefresh = 60000, /* vertical refresh * 1000 */ + .flags = 10, +}; + +drmModeFBPtr createFB(int fd, drmModeResPtr res); +int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out); +drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res); + +int main(int argc, char **argv) +{ + int fd; + const char *driver = "i915"; /* hardcoded for now */ + drmModeResPtr res; + drmModeFBPtr framebuffer; + int numOutputs; + drmModeOutputPtr out[8]; + drmModeCrtcPtr crtc; + + printf("Starting test\n"); + + fd = drmOpen(driver, NULL); + + if (fd < 0) { + printf("Failed to open the card fb\n"); + return 1; + } + + res = drmModeGetResources(fd); + if (res == 0) { + printf("Failed to get resources from card\n"); + drmClose(fd); + return 1; + } + + framebuffer = createFB(fd, res); + if (framebuffer == NULL) { + printf("Failed to create framebuffer\n"); + return 1; + } + + numOutputs = findConnectedOutputs(fd, res, out); + if (numOutputs < 1) { + printf("Failed to find connected outputs\n"); + return 1; + } + + crtc = findFreeCrtc(fd, res); + if (numOutputs < 1) { + printf("Couldn't find a free crtc\n"); + return 1; + } + + + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 0, &out[0]->output_id, 1, &mode); + sleep(2); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 500, &out[0]->output_id, 1, &mode); + sleep(2); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 500, 0, &out[0]->output_id, 1, &mode); + sleep(2); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 500, 500, &out[0]->output_id, 1, &mode); + + drmModeFreeResources(res); + printf("Ok\n"); + + return 0; +} + +drmModeFBPtr createFB(int fd, drmModeResPtr res) +{ + /* Haveing problems getting drmBOCreate to work with me. */ + return drmModeGetFB(fd, res->fbs[1]); +} + +int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out) +{ + int count = 0; + int i; + + drmModeOutputPtr output; + + for (i = 0; i < res->count_outputs; i++) { + output = drmModeGetOutput(fd, res->outputs[i]); + + if (!output || output->connection != DRM_MODE_CONNECTED) + continue; + + out[count++] = output; + } + + return count; +} + +drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res) +{ + return drmModeGetCrtc(fd, res->crtcs[0]); +} diff --git a/tests/modedemo/test b/tests/modedemo/test new file mode 100755 index 00000000..f98e3708 --- /dev/null +++ b/tests/modedemo/test @@ -0,0 +1 @@ +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app -- cgit v1.2.3 From 0b69c1d1d6a09d55d3367296dfdf23269f2721ea Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 11 Jan 2008 02:55:00 +0100 Subject: Added fixed misc framebuffer problems --- tests/mode/modetest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index c1f291b2..eeb4b258 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -291,7 +291,7 @@ int testFrameBufferAdd(int fd, drmModeResPtr res) goto err; printf("\tAdding FB\n"); - ret = drmModeAddFB(fd, 640, 480, 32, 8, 0, &bo, &fb); + ret = drmModeAddFB(fd, 800, 600, 32, 8, 0, &bo, &fb); if (ret) goto err_bo; -- cgit v1.2.3 From 12a47cd136803883231c9763f2007216236ec3b2 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 11 Jan 2008 04:23:32 +0100 Subject: Updated the modedemo test --- tests/modedemo/demo.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index ea71fd1d..44ebacd3 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -8,6 +8,11 @@ #include "xf86drm.h" #include "xf86drmMode.h" + +/* setting this to 2024 gets the pitch wrong check it */ +#define SIZE_X 2048 +#define SIZE_Y 2048 + static struct drm_mode_modeinfo mode = { .name = "Test mode", .clock = 25200, @@ -28,6 +33,7 @@ static struct drm_mode_modeinfo mode = { drmModeFBPtr createFB(int fd, drmModeResPtr res); int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out); drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res); +void prettyColors(int fd, unsigned int handle); int main(int argc, char **argv) { @@ -73,14 +79,26 @@ int main(int argc, char **argv) return 1; } + prettyColors(fd, framebuffer->handle); + + printf("0 0\n"); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 0, &out[1]->output_id, 1, &mode); + sleep(2); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 0, &out[0]->output_id, 1, &mode); + printf("0 100\n"); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 100, &out[1]->output_id, 1, &mode); sleep(2); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 500, &out[0]->output_id, 1, &mode); + + printf("100 0\n"); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 0, &out[1]->output_id, 1, &mode); sleep(2); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 500, 0, &out[0]->output_id, 1, &mode); + + printf("100 100\n"); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 100, &out[1]->output_id, 1, &mode); sleep(2); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 500, 500, &out[0]->output_id, 1, &mode); + + /* turn the crtc off just in case */ + drmModeSetCrtc(fd, crtc->crtc_id, 0, 0, 0, 0, 0, 0); drmModeFreeResources(res); printf("Ok\n"); @@ -90,8 +108,40 @@ int main(int argc, char **argv) drmModeFBPtr createFB(int fd, drmModeResPtr res) { - /* Haveing problems getting drmBOCreate to work with me. */ - return drmModeGetFB(fd, res->fbs[1]); + drmModeFBPtr frame; + unsigned int fb = 0; + int ret = 0; + drmBO bo; + + ret = drmBOCreate(fd, SIZE_X * SIZE_Y * 4, 0, 0, + DRM_BO_FLAG_READ | + DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_MEM_TT | + DRM_BO_FLAG_MEM_VRAM | + DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, &bo); + + if (ret) + goto err; + + ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, SIZE_X*4, &bo, &fb); + + if (ret) + goto err_bo; + + frame = drmModeGetFB(fd, fb); + + if (!frame) + goto err_bo; + + return frame; + +err_bo: + drmBOUnreference(fd, &bo); +err: + printf("Something went wrong when creating a fb, using one of the predefined ones\n"); + + return drmModeGetFB(fd, res->fbs[0]); } int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out) @@ -115,5 +165,37 @@ int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out) drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res) { - return drmModeGetCrtc(fd, res->crtcs[0]); + return drmModeGetCrtc(fd, res->crtcs[1]); +} + +void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr) +{ + int i, j; + + for (i = x; i < x + w; i++) + for(j = y; j < y + h; j++) + ptr[(i * SIZE_X) + j] = v; + +} + +void prettyColors(int fd, unsigned int handle) +{ + drmBO bo; + unsigned int *ptr; + int i, j; + + drmBOReference(fd, handle, &bo); + drmBOMap(fd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr); + + for (i = 0; i < (SIZE_X*SIZE_Y); i++) + ptr[i] = 0xFFFFFFFF; + + for (i = 0; i < 8; i++) + draw(i*40, i*40, 40, 40, 0, ptr); + + + draw(200, 100, 40, 40, 0xff00ff, ptr); + draw(100, 200, 40, 40, 0xff00ff, ptr); + + drmBOUnmap(fd, &bo); } -- cgit v1.2.3 From f07942f74a08e4c65e3b5e5c46f543686ae30c2b Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 11 Jan 2008 17:13:48 +0100 Subject: Panning now works without modeset --- tests/modedemo/demo.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 44ebacd3..594d60db 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -9,9 +9,10 @@ #include "xf86drm.h" #include "xf86drmMode.h" -/* setting this to 2024 gets the pitch wrong check it */ #define SIZE_X 2048 #define SIZE_Y 2048 +/* Pitch needs to be power of two */ +#define PITCH 2048 static struct drm_mode_modeinfo mode = { .name = "Test mode", @@ -82,19 +83,19 @@ int main(int argc, char **argv) prettyColors(fd, framebuffer->handle); printf("0 0\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 0, &out[1]->output_id, 1, &mode); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 0, &out[0]->output_id, 1, &mode); sleep(2); printf("0 100\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 100, &out[1]->output_id, 1, &mode); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 100, &out[0]->output_id, 1, &mode); sleep(2); printf("100 0\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 0, &out[1]->output_id, 1, &mode); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 0, &out[0]->output_id, 1, &mode); sleep(2); printf("100 100\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 100, &out[1]->output_id, 1, &mode); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 100, &out[0]->output_id, 1, &mode); sleep(2); /* turn the crtc off just in case */ @@ -124,7 +125,7 @@ drmModeFBPtr createFB(int fd, drmModeResPtr res) if (ret) goto err; - ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, SIZE_X*4, &bo, &fb); + ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, PITCH * 4, &bo, &fb); if (ret) goto err_bo; @@ -165,7 +166,7 @@ int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out) drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res) { - return drmModeGetCrtc(fd, res->crtcs[1]); + return drmModeGetCrtc(fd, res->crtcs[0]); } void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr) @@ -174,7 +175,7 @@ void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsign for (i = x; i < x + w; i++) for(j = y; j < y + h; j++) - ptr[(i * SIZE_X) + j] = v; + ptr[(i * PITCH) + j] = v; } @@ -182,7 +183,7 @@ void prettyColors(int fd, unsigned int handle) { drmBO bo; unsigned int *ptr; - int i, j; + int i; drmBOReference(fd, handle, &bo); drmBOMap(fd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr); @@ -191,7 +192,7 @@ void prettyColors(int fd, unsigned int handle) ptr[i] = 0xFFFFFFFF; for (i = 0; i < 8; i++) - draw(i*40, i*40, 40, 40, 0, ptr); + draw(i * 40, i * 40, 40, 40, 0, ptr); draw(200, 100, 40, 40, 0xff00ff, ptr); -- cgit v1.2.3 From a2254c5a9670a3e865f0eb5acd46e905c9b146ce Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 28 Jan 2008 03:12:29 +0100 Subject: Added cursor support --- tests/modedemo/demo.c | 47 +++++++++++++++- tests/modefb/Makefile | 14 +++++ tests/modefb/demo.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/modefb/test | 1 + 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 tests/modefb/Makefile create mode 100644 tests/modefb/demo.c create mode 100755 tests/modefb/test (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 594d60db..1efeb272 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -34,7 +34,9 @@ static struct drm_mode_modeinfo mode = { drmModeFBPtr createFB(int fd, drmModeResPtr res); int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out); drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res); +void testCursor(int fd, uint32_t crtc); void prettyColors(int fd, unsigned int handle); +void prettyCursor(int fd, unsigned int handle); int main(int argc, char **argv) { @@ -98,6 +100,11 @@ int main(int argc, char **argv) drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 100, &out[0]->output_id, 1, &mode); sleep(2); + printf("0 0\n"); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 1, 1, &out[0]->output_id, 1, &mode); + + testCursor(fd, crtc->crtc_id); + /* turn the crtc off just in case */ drmModeSetCrtc(fd, crtc->crtc_id, 0, 0, 0, 0, 0, 0); @@ -166,7 +173,7 @@ int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out) drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res) { - return drmModeGetCrtc(fd, res->crtcs[0]); + return drmModeGetCrtc(fd, res->crtcs[1]); } void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr) @@ -200,3 +207,41 @@ void prettyColors(int fd, unsigned int handle) drmBOUnmap(fd, &bo); } + +void testCursor(int fd, uint32_t crtc) +{ + drmBO bo; + int ret; + ret = drmBOCreate(fd, 64 * 64 * 4, 0, 0, + DRM_BO_FLAG_READ | + DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_MEM_VRAM | + DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, &bo); + + prettyCursor(fd, bo.handle); + + printf("set cursor\n"); + drmModeSetCursor(fd, crtc, &bo, 64, 64); + printf("move cursor 0, 0\n"); + drmModeMoveCursor(fd, crtc, 0, 0); + sleep(2); + printf("move cursor 40, 40\n"); + drmModeMoveCursor(fd, crtc, 40, 40); + sleep(2); +} + +void prettyCursor(int fd, unsigned int handle) +{ + drmBO bo; + unsigned int *ptr; + int i; + + drmBOReference(fd, handle, &bo); + drmBOMap(fd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr); + + for (i = 0; i < (64 * 64); i++) + ptr[i] = 0xFFFF00FF; + + drmBOUnmap(fd, &bo); +} diff --git a/tests/modefb/Makefile b/tests/modefb/Makefile new file mode 100644 index 00000000..84c6c86a --- /dev/null +++ b/tests/modefb/Makefile @@ -0,0 +1,14 @@ + +all: app + +#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ +# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ + +app: demo.c + @gcc $(CFLAGS) -o app -Wall demo.c + +clean: + @rm -f app + +run: app + sudo ./test diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c new file mode 100644 index 00000000..0dbf01c7 --- /dev/null +++ b/tests/modefb/demo.c @@ -0,0 +1,150 @@ +#include +#include +#include +#include +#include +#include "linux/fb.h" +#include "sys/ioctl.h" + + +void setMode(struct fb_var_screeninfo *var); +void pan(int fd, struct fb_var_screeninfo *var, int x, int y); +void cursor(int fd); + +int main(int argc, char **argv) +{ + struct fb_var_screeninfo var; + struct fb_fix_screeninfo fix; + const char* name = "/dev/fb0"; + + int fd = open(name, O_RDONLY); + + if (fd == -1) { + printf("open %s : %s\n", name, strerror(errno)); + return 1; + } + + memset(&var, 0, sizeof(struct fb_var_screeninfo)); + memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); + + if (ioctl(fd, FBIOGET_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); + if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)) + printf("fix %s\n", strerror(errno)); + + setMode(&var); + printf("pan: 0, 0\n"); + pan(fd, &var, 0, 0); + sleep(2); + printf("pan: 100, 0\n"); + pan(fd, &var, 100, 0); + sleep(2); + printf("pan: 0, 100\n"); + pan(fd, &var, 0, 100); + sleep(2); + printf("pan: 100, 100\n"); + pan(fd, &var, 100, 100); + sleep(2); + printf("pan: 0, 0\n"); + pan(fd, &var, 0, 0); + sleep(2); + + printf("cursor\n"); + cursor(fd); + return 0; +} + +void pan(int fd, struct fb_var_screeninfo *var, int x, int y) +{ + var->xoffset = x; + var->yoffset = y; + + var->activate = FB_ACTIVATE_NOW; + + if (ioctl(fd, FBIOPUT_VSCREENINFO, var)) + printf("pan error: %s\n", strerror(errno)); +} + +/* + * Currently isn't supported in the driver + */ +void cursor(int fd) +{ + struct fb_cursor cur; + void *data = malloc(64 * 64 * 4); + memset(&cur, 0, sizeof(cur)); + + cur.set = FB_CUR_SETIMAGE | FB_CUR_SETPOS | FB_CUR_SETSIZE; + cur.enable = 1; + cur.image.dx = 1; + cur.image.dy = 1; + cur.image.width = 2; + cur.image.height = 2; + cur.image.depth = 32; + cur.image.data = data; + + if (ioctl(fd, FBIO_CURSOR, &cur)) + printf("cursor error: %s\n", strerror(errno)); + + sleep(2); + + memset(&cur, 0, sizeof(cur)); + cur.set = FB_CUR_SETPOS; + cur.enable = 0; + cur.image.dx = 100; + cur.image.dy = 100; + + if (ioctl(fd, FBIO_CURSOR, &cur)) + printf("cursor error: %s\n", strerror(errno)); + + free(data); +} + +struct drm_mode +{ + int clock; + int hdisplay; + int hsync_start; + int hsync_end; + int htotal; + int hskew; + int vdisplay; + int vsync_start; + int vsync_end; + int vtotal; + int vscan; + int vrefresh; + int flags; +}; + +struct drm_mode mode = +{ + .clock = 25200, + .hdisplay = 640, + .hsync_start = 656, + .hsync_end = 752, + .htotal = 800, + .hskew = 0, + .vdisplay = 480, + .vsync_start = 490, + .vsync_end = 492, + .vtotal = 525, + .vscan = 0, + .vrefresh = 60000, /* vertical refresh * 1000 */ + .flags = 10, +}; + +void setMode(struct fb_var_screeninfo *var) { + var->activate = FB_ACTIVATE_NOW; + var->xres = mode.hdisplay; + var->right_margin = mode.hsync_start - mode.hdisplay; + var->hsync_len = mode.hsync_end - mode.hsync_start; + var->left_margin = mode.htotal - mode.hsync_end; + var->yres = mode.vdisplay; + var->lower_margin = mode.vsync_start - mode.vdisplay; + var->vsync_len = mode.vsync_end - mode.vsync_start; + var->upper_margin = mode.vtotal - mode.vsync_end; + var->pixclock = 10000000 / mode.htotal * 1000 / mode.vtotal * 100; + /* avoid overflow */ + var->pixclock = var->pixclock * 1000 / mode.vrefresh; +} diff --git a/tests/modefb/test b/tests/modefb/test new file mode 100755 index 00000000..f98e3708 --- /dev/null +++ b/tests/modefb/test @@ -0,0 +1 @@ +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app -- cgit v1.2.3 From 841ef9eb8da8058d6495e9f8e1b14af2709dfaa1 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 30 Jan 2008 15:47:26 +0100 Subject: ModeFB demo now display cursor --- tests/modedemo/demo.c | 1 + tests/modefb/Makefile | 2 +- tests/modefb/demo.c | 82 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 56 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 1efeb272..b399aec1 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -244,4 +244,5 @@ void prettyCursor(int fd, unsigned int handle) ptr[i] = 0xFFFF00FF; drmBOUnmap(fd, &bo); + drmBOUnreference(fd, &bo); } diff --git a/tests/modefb/Makefile b/tests/modefb/Makefile index 84c6c86a..467fb11a 100644 --- a/tests/modefb/Makefile +++ b/tests/modefb/Makefile @@ -5,7 +5,7 @@ all: app # -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ app: demo.c - @gcc $(CFLAGS) -o app -Wall demo.c + @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm demo.c clean: @rm -f app diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index 0dbf01c7..9af369c2 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -5,25 +5,37 @@ #include #include "linux/fb.h" #include "sys/ioctl.h" +#include "xf86drm.h" +#include "xf86drmMode.h" - +void pretty(int fd); void setMode(struct fb_var_screeninfo *var); void pan(int fd, struct fb_var_screeninfo *var, int x, int y); -void cursor(int fd); +void cursor(int fd, int drmfd); +void prettyCursor(int fd, unsigned int handle, unsigned int color); + +extern void sleep(int); int main(int argc, char **argv) { struct fb_var_screeninfo var; struct fb_fix_screeninfo fix; + const char* driver = "i915"; const char* name = "/dev/fb0"; int fd = open(name, O_RDONLY); + int drmfd = drmOpen(driver, NULL); if (fd == -1) { printf("open %s : %s\n", name, strerror(errno)); return 1; } + if (drmfd < 0) { + printf("drmOpen failed\n"); + return 1; + } + memset(&var, 0, sizeof(struct fb_var_screeninfo)); memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); @@ -50,7 +62,7 @@ int main(int argc, char **argv) sleep(2); printf("cursor\n"); - cursor(fd); + cursor(fd, drmfd); return 0; } @@ -66,38 +78,52 @@ void pan(int fd, struct fb_var_screeninfo *var, int x, int y) } /* - * Currently isn't supported in the driver + * Cursor support removed from the fb kernel interface + * using drm instead. */ -void cursor(int fd) +void cursor(int fd, int drmfd) { - struct fb_cursor cur; - void *data = malloc(64 * 64 * 4); - memset(&cur, 0, sizeof(cur)); - - cur.set = FB_CUR_SETIMAGE | FB_CUR_SETPOS | FB_CUR_SETSIZE; - cur.enable = 1; - cur.image.dx = 1; - cur.image.dy = 1; - cur.image.width = 2; - cur.image.height = 2; - cur.image.depth = 32; - cur.image.data = data; - - if (ioctl(fd, FBIO_CURSOR, &cur)) - printf("cursor error: %s\n", strerror(errno)); + drmModeResPtr res = drmModeGetResources(drmfd); + uint32_t crtc = res->crtcs[1]; /* select crtc here */ + drmBO bo; + int ret; + ret = drmBOCreate(drmfd, 64 * 64 * 4, 0, 0, + DRM_BO_FLAG_READ | + DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_MEM_VRAM | + DRM_BO_FLAG_NO_EVICT, + DRM_BO_HINT_DONT_FENCE, &bo); + + if (ret) { + printf("failed to create buffer: %s\n", strerror(ret)); + return; + } + prettyCursor(drmfd, bo.handle, 0xFFFF00FF); + drmModeSetCursor(drmfd, crtc, &bo, 64, 64); + drmModeMoveCursor(drmfd, crtc, 0, 0); + sleep(2); + drmModeMoveCursor(drmfd, crtc, 40, 40); + prettyCursor(drmfd, bo.handle, 0xFFFF0000); sleep(2); + drmModeSetCursor(drmfd, crtc, 0, 0, 0); + drmBOUnreference(drmfd, &bo); +} + +void prettyCursor(int drmfd, unsigned int handle, unsigned int color) +{ + drmBO bo; + unsigned int *ptr; + int i; - memset(&cur, 0, sizeof(cur)); - cur.set = FB_CUR_SETPOS; - cur.enable = 0; - cur.image.dx = 100; - cur.image.dy = 100; + drmBOReference(drmfd, handle, &bo); + drmBOMap(drmfd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr); - if (ioctl(fd, FBIO_CURSOR, &cur)) - printf("cursor error: %s\n", strerror(errno)); + for (i = 0; i < (64 * 64); i++) + ptr[i] = color; - free(data); + drmBOUnmap(drmfd, &bo); + drmBOUnreference(drmfd, &bo); } struct drm_mode -- cgit v1.2.3 From d8bbd02a6086ebe302859cec22c503d32ed77dc6 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 4 Feb 2008 20:51:59 +0100 Subject: Modedemo now uses two crtc and output pairs --- tests/modedemo/demo.c | 345 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 261 insertions(+), 84 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index b399aec1..de31e7a6 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -14,6 +14,60 @@ /* Pitch needs to be power of two */ #define PITCH 2048 +/* old functions to be replaced */ +drmModeFBPtr createFB(int fd, drmModeResPtr res); +void testCursor(int fd, uint32_t crtc); +void prettyColors(int fd, unsigned int handle); +void prettyCursor(int fd, unsigned int handle); + +/* structs for the demo_driver */ + +struct demo_driver; + +struct demo_screen +{ + /* drm stuff */ + drmBO buffer; + drmModeFBPtr fb; + drmModeCrtcPtr crtc; + drmModeOutputPtr output; + + struct drm_mode_modeinfo *mode; + + /* virtual buffer */ + uint32_t virt_x; + uint32_t virt_y; + uint32_t pitch; + + /* parent */ + struct demo_driver *driver; +}; + +#define DEMO_MAX_SCREENS 4 +#define MAX_FIND_OUTPUTS 8 + +struct demo_driver +{ + /* drm stuff */ + int fd; + drmModeResPtr res; + + /* screens */ + size_t numScreens; + struct demo_screen screens[DEMO_MAX_SCREENS]; +}; + +struct demo_driver* demoCreateDriver(const char *name); +void demoUpdateRes(struct demo_driver *driver); +int demoCreateScreens(struct demo_driver *driver); +void demoTakeDownScreen(struct demo_screen *screen); +int demoFindConnectedOutputs(struct demo_driver *driver, drmModeOutputPtr *out, size_t max_out); +drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr output); +void demoPanScreen(struct demo_screen *screen, uint16_t x, uint16_t y); +/* yet to be implemented */ +void demoMouseActivate(struct demo_screen *screen); +void demoMouseMove(struct demo_screen *screen, uint16_t x, uint16_t y); + static struct drm_mode_modeinfo mode = { .name = "Test mode", .clock = 25200, @@ -31,87 +85,232 @@ static struct drm_mode_modeinfo mode = { .flags = 10, }; -drmModeFBPtr createFB(int fd, drmModeResPtr res); -int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out); -drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res); -void testCursor(int fd, uint32_t crtc); -void prettyColors(int fd, unsigned int handle); -void prettyCursor(int fd, unsigned int handle); - int main(int argc, char **argv) { - int fd; - const char *driver = "i915"; /* hardcoded for now */ - drmModeResPtr res; - drmModeFBPtr framebuffer; - int numOutputs; - drmModeOutputPtr out[8]; - drmModeCrtcPtr crtc; + const char *driver_name = "i915"; /* hardcoded for now */ + struct demo_driver *driver; + int num; + int i; - printf("Starting test\n"); + printf("starting demo\n"); - fd = drmOpen(driver, NULL); + driver = demoCreateDriver(driver_name); - if (fd < 0) { - printf("Failed to open the card fb\n"); + if (!driver) { + printf("failed to create driver\n"); return 1; } - res = drmModeGetResources(fd); - if (res == 0) { - printf("Failed to get resources from card\n"); - drmClose(fd); + num = demoCreateScreens(driver); + if (num < 1) { + printf("no screens attached or an error occured\n"); return 1; } + printf("created %i screens\n", num); - framebuffer = createFB(fd, res); - if (framebuffer == NULL) { - printf("Failed to create framebuffer\n"); - return 1; + for (i = 0; i < num; i++) { + prettyColors(driver->fd, driver->screens[i].fb->handle); } + sleep(1); - numOutputs = findConnectedOutputs(fd, res, out); - if (numOutputs < 1) { - printf("Failed to find connected outputs\n"); - return 1; + for (i = 0; i < num; i++) { + printf("%i: 100 0\n", i); + demoPanScreen(&driver->screens[i], 100, 0); + sleep(1); + + printf("%i: 0 100\n", i); + demoPanScreen(&driver->screens[i], 0, 100); + sleep(1); + + printf("%i: 100 100\n", i); + demoPanScreen(&driver->screens[i], 100, 100); + sleep(1); + + printf("%i: 0 0\n", i); + demoPanScreen(&driver->screens[i], 0, 1); + sleep(1); + testCursor(driver->fd, driver->screens[i].crtc->crtc_id); } - crtc = findFreeCrtc(fd, res); - if (numOutputs < 1) { - printf("Couldn't find a free crtc\n"); - return 1; + sleep(2); + printf("ok\n"); + return 0; +} + +int demoCreateScreens(struct demo_driver *driver) +{ + drmModeOutputPtr out[MAX_FIND_OUTPUTS]; + int num; + int num_screens = 0; + struct demo_screen *screen; + int ret = 0; + int i; + + num = demoFindConnectedOutputs(driver, out, MAX_FIND_OUTPUTS); + if (num < 0) + return 0; + + printf("found %i connected outputs\n", num); + + for (i = 0; i < num; i++) { + screen = &driver->screens[i]; + + screen->crtc = demoFindFreeCrtc(driver, out[i]); + if (!screen->crtc) { + printf("found no free crtc for output\n"); + drmModeFreeOutput(out[i]); + continue; + } + + screen->fb = createFB(driver->fd, driver->res); + if (!screen->fb) { + drmModeFreeOutput(out[i]); + drmModeFreeCrtc(screen->crtc); + screen->crtc = 0; + printf("could not create framebuffer\n"); + continue; + } + + screen->virt_x = SIZE_X; + screen->virt_y = SIZE_Y; + screen->pitch = PITCH; + + screen->output = out[i]; + screen->mode = &mode; + screen->driver = driver; + + ret = drmModeSetCrtc( + driver->fd, + screen->crtc->crtc_id, + screen->fb->buffer_id, + 0, 0, + &screen->output->output_id, 1, + screen->mode); + + if (ret) { + printf("failed to set mode\n"); + demoTakeDownScreen(screen); + } else { + num_screens++; + } + + demoUpdateRes(driver); } - prettyColors(fd, framebuffer->handle); + return num_screens; +} - printf("0 0\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 0, &out[0]->output_id, 1, &mode); - sleep(2); +void demoTakeDownScreen(struct demo_screen *screen) +{ + /* TODO Unrefence the BO */ + /* TODO Destroy FB */ + /* TODO take down the mode */ - printf("0 100\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 0, 100, &out[0]->output_id, 1, &mode); - sleep(2); + drmModeFreeOutput(screen->output); + drmModeFreeCrtc(screen->crtc); +} - printf("100 0\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 0, &out[0]->output_id, 1, &mode); - sleep(2); +drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr output) +{ + drmModeCrtcPtr crtc; + int i, j, used = 0; + drmModeResPtr res = driver->res; - printf("100 100\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 100, &out[0]->output_id, 1, &mode); - sleep(2); - printf("0 0\n"); - drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 1, 1, &out[0]->output_id, 1, &mode); + for (i = 0; i < res->count_crtcs; i++) { + used = 0; + for (j = 0; j < DEMO_MAX_SCREENS; j++) { + crtc = driver->screens[j].crtc; - testCursor(fd, crtc->crtc_id); + if (crtc && crtc->crtc_id == res->crtcs[i]) + used = 1; + } - /* turn the crtc off just in case */ - drmModeSetCrtc(fd, crtc->crtc_id, 0, 0, 0, 0, 0, 0); + if (!used) { + crtc = drmModeGetCrtc(driver->fd, res->crtcs[i]); + break; + } else { + crtc = 0; + } + } - drmModeFreeResources(res); - printf("Ok\n"); + return crtc; +} - return 0; +struct demo_driver* demoCreateDriver(const char *name) +{ + struct demo_driver* driver = malloc(sizeof(struct demo_driver)); + + memset(driver, 0, sizeof(struct demo_driver)); + + driver->fd = drmOpen(name, NULL); + + if (driver->fd < 0) { + printf("Failed to open the card fb\n"); + goto err_driver; + } + + demoUpdateRes(driver); + if (!driver->res) { + printf("could not retrive resources\n"); + goto err_res; + } + + return driver; + +err_res: + drmClose(driver->fd); +err_driver: + free(driver); + return NULL; +} + +void demoUpdateRes(struct demo_driver *driver) +{ + if (driver->res) + drmModeFreeResources(driver->res); + + driver->res = drmModeGetResources(driver->fd); + + if (!driver->res) + printf("failed to get resources from kernel\n"); +} + +int demoFindConnectedOutputs(struct demo_driver *driver, drmModeOutputPtr *out, size_t max_out) +{ + int count = 0; + int i; + int fd = driver->fd; + drmModeResPtr res = driver->res; + + drmModeOutputPtr output; + + for (i = 0; i < res->count_outputs && count < max_out; i++) { + output = drmModeGetOutput(fd, res->outputs[i]); + + if (!output) + continue; + + if (output->connection != DRM_MODE_CONNECTED) { + drmModeFreeOutput(output); + continue; + } + + out[count++] = output; + } + + return count; +} + +void demoPanScreen(struct demo_screen *screen, uint16_t x, uint16_t y) +{ + drmModeSetCrtc( + screen->driver->fd, + screen->crtc->crtc_id, + screen->fb->buffer_id, + x, y, + &screen->output->output_id, 1, + screen->mode); } drmModeFBPtr createFB(int fd, drmModeResPtr res) @@ -147,33 +346,7 @@ drmModeFBPtr createFB(int fd, drmModeResPtr res) err_bo: drmBOUnreference(fd, &bo); err: - printf("Something went wrong when creating a fb, using one of the predefined ones\n"); - - return drmModeGetFB(fd, res->fbs[0]); -} - -int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out) -{ - int count = 0; - int i; - - drmModeOutputPtr output; - - for (i = 0; i < res->count_outputs; i++) { - output = drmModeGetOutput(fd, res->outputs[i]); - - if (!output || output->connection != DRM_MODE_CONNECTED) - continue; - - out[count++] = output; - } - - return count; -} - -drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res) -{ - return drmModeGetCrtc(fd, res->crtcs[1]); + return 0; } void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr) @@ -225,10 +398,14 @@ void testCursor(int fd, uint32_t crtc) drmModeSetCursor(fd, crtc, &bo, 64, 64); printf("move cursor 0, 0\n"); drmModeMoveCursor(fd, crtc, 0, 0); - sleep(2); + sleep(1); printf("move cursor 40, 40\n"); drmModeMoveCursor(fd, crtc, 40, 40); - sleep(2); + sleep(1); + printf("move cursor 100, 100\n"); + drmModeMoveCursor(fd, crtc, 100, 100); + sleep(1); + drmModeSetCursor(fd, crtc, NULL, 0, 0); } void prettyCursor(int fd, unsigned int handle) -- cgit v1.2.3 From 936e32b08c05c9658cc51cd8fe118e0342733a79 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Tue, 5 Feb 2008 15:18:05 +0000 Subject: make modefb/modedemo match each others test output. --- tests/mode/modetest.c | 5 ++-- tests/modedemo/demo.c | 23 +++++++------- tests/modefb/demo.c | 83 +++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 82 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index eeb4b258..ab0cdc9c 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -347,15 +347,14 @@ int testDPMS(int fd, drmModeResPtr res) int main(int argc, char **argv) { int fd; - const char *driver = "i915"; /* hardcoded for now */ drmModeResPtr res; printf("Starting test\n"); - fd = drmOpen(driver, NULL); + fd = drmOpenControl(0); if (fd < 0) { - printf("Failed to open the card fb\n"); + printf("Failed to open the card fb (%d)\n",fd); return 1; } diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index de31e7a6..48a4f1f1 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -18,7 +18,7 @@ drmModeFBPtr createFB(int fd, drmModeResPtr res); void testCursor(int fd, uint32_t crtc); void prettyColors(int fd, unsigned int handle); -void prettyCursor(int fd, unsigned int handle); +void prettyCursor(int fd, unsigned int handle, unsigned int color); /* structs for the demo_driver */ @@ -57,7 +57,7 @@ struct demo_driver struct demo_screen screens[DEMO_MAX_SCREENS]; }; -struct demo_driver* demoCreateDriver(const char *name); +struct demo_driver* demoCreateDriver(void); void demoUpdateRes(struct demo_driver *driver); int demoCreateScreens(struct demo_driver *driver); void demoTakeDownScreen(struct demo_screen *screen); @@ -87,14 +87,13 @@ static struct drm_mode_modeinfo mode = { int main(int argc, char **argv) { - const char *driver_name = "i915"; /* hardcoded for now */ struct demo_driver *driver; int num; int i; printf("starting demo\n"); - driver = demoCreateDriver(driver_name); + driver = demoCreateDriver(); if (!driver) { printf("failed to create driver\n"); @@ -237,13 +236,13 @@ drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr out return crtc; } -struct demo_driver* demoCreateDriver(const char *name) +struct demo_driver* demoCreateDriver(void) { struct demo_driver* driver = malloc(sizeof(struct demo_driver)); memset(driver, 0, sizeof(struct demo_driver)); - driver->fd = drmOpen(name, NULL); + driver->fd = drmOpenControl(0); if (driver->fd < 0) { printf("Failed to open the card fb\n"); @@ -328,8 +327,10 @@ drmModeFBPtr createFB(int fd, drmModeResPtr res) DRM_BO_FLAG_NO_EVICT, DRM_BO_HINT_DONT_FENCE, &bo); - if (ret) + if (ret) { + printf("failed to create framebuffer (ret %d)\n",ret); goto err; + } ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, PITCH * 4, &bo, &fb); @@ -392,13 +393,13 @@ void testCursor(int fd, uint32_t crtc) DRM_BO_FLAG_NO_EVICT, DRM_BO_HINT_DONT_FENCE, &bo); - prettyCursor(fd, bo.handle); - + prettyCursor(fd, bo.handle, 0xFFFF00FF); printf("set cursor\n"); drmModeSetCursor(fd, crtc, &bo, 64, 64); printf("move cursor 0, 0\n"); drmModeMoveCursor(fd, crtc, 0, 0); sleep(1); + prettyCursor(fd, bo.handle, 0xFFFF0000); printf("move cursor 40, 40\n"); drmModeMoveCursor(fd, crtc, 40, 40); sleep(1); @@ -408,7 +409,7 @@ void testCursor(int fd, uint32_t crtc) drmModeSetCursor(fd, crtc, NULL, 0, 0); } -void prettyCursor(int fd, unsigned int handle) +void prettyCursor(int fd, unsigned int handle, unsigned int color) { drmBO bo; unsigned int *ptr; @@ -418,7 +419,7 @@ void prettyCursor(int fd, unsigned int handle) drmBOMap(fd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr); for (i = 0; i < (64 * 64); i++) - ptr[i] = 0xFFFF00FF; + ptr[i] = color; drmBOUnmap(fd, &bo); drmBOUnreference(fd, &bo); diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index 9af369c2..f80753cf 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -4,6 +4,7 @@ #include #include #include "linux/fb.h" +#include #include "sys/ioctl.h" #include "xf86drm.h" #include "xf86drmMode.h" @@ -12,19 +13,20 @@ void pretty(int fd); void setMode(struct fb_var_screeninfo *var); void pan(int fd, struct fb_var_screeninfo *var, int x, int y); void cursor(int fd, int drmfd); +void prettyColors(int fd); void prettyCursor(int fd, unsigned int handle, unsigned int color); extern void sleep(int); +struct fb_var_screeninfo var; +struct fb_fix_screeninfo fix; + int main(int argc, char **argv) { - struct fb_var_screeninfo var; - struct fb_fix_screeninfo fix; - const char* driver = "i915"; - const char* name = "/dev/fb0"; - - int fd = open(name, O_RDONLY); - int drmfd = drmOpen(driver, NULL); + const char* name = "/dev/fb1"; + int i; + int fd = open(name, O_RDWR); + int drmfd = drmOpenControl(0); if (fd == -1) { printf("open %s : %s\n", name, strerror(errno)); @@ -32,7 +34,7 @@ int main(int argc, char **argv) } if (drmfd < 0) { - printf("drmOpen failed\n"); + printf("drmOpenControl failed\n"); return 1; } @@ -45,6 +47,15 @@ int main(int argc, char **argv) printf("fix %s\n", strerror(errno)); setMode(&var); + + if (ioctl(fd, FBIOPUT_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); + + for (i = 0; i < 1; i++) { + prettyColors(fd); + } + sleep(1); + printf("pan: 0, 0\n"); pan(fd, &var, 0, 0); sleep(2); @@ -71,12 +82,51 @@ void pan(int fd, struct fb_var_screeninfo *var, int x, int y) var->xoffset = x; var->yoffset = y; - var->activate = FB_ACTIVATE_NOW; - - if (ioctl(fd, FBIOPUT_VSCREENINFO, var)) + if (ioctl(fd, FBIOPAN_DISPLAY, var)) printf("pan error: %s\n", strerror(errno)); } +void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr) +{ + int i, j; + + for (i = x; i < x + w; i++) + for(j = y; j < y + h; j++) + ptr[(i * var.xres_virtual) + j] = v; +} + +void prettyColors(int fd) +{ + unsigned int *ptr, *newptr; + int i,w,h; + int size = var.xres * var.yres * var.bits_per_pixel; + + ptr = (unsigned int *)mmap(NULL, size, + PROT_READ|PROT_WRITE, MAP_SHARED, fd, + 0); + if (ptr < 0) { + printf("FAILED MMAP %d\n",errno); + exit(1); + } + + newptr = ptr; + for (h = 0; h < var.yres; h++) { + for (w = 0; w < var.xres; w++) { + newptr[w] = 0xFFFFFFFF; + } + newptr += var.xres_virtual; + } + + for (i = 0; i < 8; i++) + draw(i * 40, i * 40, 40, 40, 0, ptr); + + + draw(200, 100, 40, 40, 0xff00ff, ptr); + draw(100, 200, 40, 40, 0xff00ff, ptr); + + munmap(ptr, size); +} + /* * Cursor support removed from the fb kernel interface * using drm instead. @@ -102,11 +152,13 @@ void cursor(int fd, int drmfd) prettyCursor(drmfd, bo.handle, 0xFFFF00FF); drmModeSetCursor(drmfd, crtc, &bo, 64, 64); drmModeMoveCursor(drmfd, crtc, 0, 0); - sleep(2); - drmModeMoveCursor(drmfd, crtc, 40, 40); + sleep(1); prettyCursor(drmfd, bo.handle, 0xFFFF0000); - sleep(2); - drmModeSetCursor(drmfd, crtc, 0, 0, 0); + drmModeMoveCursor(drmfd, crtc, 40, 40); + sleep(1); + drmModeMoveCursor(drmfd, crtc, 100, 100); + sleep(1); + drmModeSetCursor(drmfd, crtc, NULL, 0, 0); drmBOUnreference(drmfd, &bo); } @@ -173,4 +225,5 @@ void setMode(struct fb_var_screeninfo *var) { var->pixclock = 10000000 / mode.htotal * 1000 / mode.vtotal * 100; /* avoid overflow */ var->pixclock = var->pixclock * 1000 / mode.vrefresh; + var->bits_per_pixel = 32; } -- cgit v1.2.3 From 127cb1ff9a7bbb7af73cc418a7adc30d68c454d2 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Tue, 5 Feb 2008 15:24:29 +0000 Subject: tweak it --- tests/modefb/demo.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index f80753cf..ef2b6585 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -97,8 +97,8 @@ void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsign void prettyColors(int fd) { - unsigned int *ptr, *newptr; - int i,w,h; + unsigned int *ptr; + int i; int size = var.xres * var.yres * var.bits_per_pixel; ptr = (unsigned int *)mmap(NULL, size, @@ -109,13 +109,7 @@ void prettyColors(int fd) exit(1); } - newptr = ptr; - for (h = 0; h < var.yres; h++) { - for (w = 0; w < var.xres; w++) { - newptr[w] = 0xFFFFFFFF; - } - newptr += var.xres_virtual; - } + memset(ptr, 0xFF, size); for (i = 0; i < 8; i++) draw(i * 40, i * 40, 40, 40, 0, ptr); -- cgit v1.2.3 From 516c7a7b28ebf4bba797eaa718450b51aa772c6e Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Tue, 5 Feb 2008 15:30:28 +0000 Subject: update app to cycle through 4 fbdev's --- tests/modefb/demo.c | 102 +++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 48 deletions(-) (limited to 'tests') diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index ef2b6585..7fa3b93f 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -23,57 +23,63 @@ struct fb_fix_screeninfo fix; int main(int argc, char **argv) { - const char* name = "/dev/fb1"; - int i; - int fd = open(name, O_RDWR); + char name[100]; + int i,d; + int fd; int drmfd = drmOpenControl(0); - if (fd == -1) { - printf("open %s : %s\n", name, strerror(errno)); - return 1; - } - - if (drmfd < 0) { - printf("drmOpenControl failed\n"); - return 1; + /* try four devices */ + for (d = 0; d < 4; d++) { + snprintf(name, 100, "/dev/fb%d", d); + fd = open(name, O_RDWR); + + if (fd == -1) { + printf("open %s : %s\n", name, strerror(errno)); + return 1; + } + + if (drmfd < 0) { + printf("drmOpenControl failed\n"); + return 1; + } + + memset(&var, 0, sizeof(struct fb_var_screeninfo)); + memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); + + if (ioctl(fd, FBIOGET_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); + if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)) + printf("fix %s\n", strerror(errno)); + + setMode(&var); + + if (ioctl(fd, FBIOPUT_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); + + for (i = 0; i < 1; i++) { + prettyColors(fd); + } + sleep(1); + + printf("pan: 0, 0\n"); + pan(fd, &var, 0, 0); + sleep(2); + printf("pan: 100, 0\n"); + pan(fd, &var, 100, 0); + sleep(2); + printf("pan: 0, 100\n"); + pan(fd, &var, 0, 100); + sleep(2); + printf("pan: 100, 100\n"); + pan(fd, &var, 100, 100); + sleep(2); + printf("pan: 0, 0\n"); + pan(fd, &var, 0, 0); + sleep(2); + + printf("cursor (may show up on wrong CRTC - fixme)\n"); + cursor(fd, drmfd); } - - memset(&var, 0, sizeof(struct fb_var_screeninfo)); - memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); - - if (ioctl(fd, FBIOGET_VSCREENINFO, &var)) - printf("var %s\n", strerror(errno)); - if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)) - printf("fix %s\n", strerror(errno)); - - setMode(&var); - - if (ioctl(fd, FBIOPUT_VSCREENINFO, &var)) - printf("var %s\n", strerror(errno)); - - for (i = 0; i < 1; i++) { - prettyColors(fd); - } - sleep(1); - - printf("pan: 0, 0\n"); - pan(fd, &var, 0, 0); - sleep(2); - printf("pan: 100, 0\n"); - pan(fd, &var, 100, 0); - sleep(2); - printf("pan: 0, 100\n"); - pan(fd, &var, 0, 100); - sleep(2); - printf("pan: 100, 100\n"); - pan(fd, &var, 100, 100); - sleep(2); - printf("pan: 0, 0\n"); - pan(fd, &var, 0, 0); - sleep(2); - - printf("cursor\n"); - cursor(fd, drmfd); return 0; } -- cgit v1.2.3 From 87d5f9cb2d2812c1da726e38965f0eb78c2b8dfa Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 7 Feb 2008 19:22:38 +0100 Subject: Small update to modedemo --- tests/modedemo/demo.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 48a4f1f1..0882fc91 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -201,12 +201,30 @@ int demoCreateScreens(struct demo_driver *driver) void demoTakeDownScreen(struct demo_screen *screen) { - /* TODO Unrefence the BO */ - /* TODO Destroy FB */ - /* TODO take down the mode */ + int fd = screen->driver->fd; + drmBO bo; + + if (screen->crtc) + drmModeSetCrtc(fd, screen->crtc->crtc_id, 0, 0, 0, 0, 0, 0); + + if (screen->fb) + drmModeRmFB(fd, screen->fb->buffer_id); + + /* maybe we should keep a pointer to the bo on the screen */ + if (screen->fb && !drmBOReference(fd, screen->fb->handle, &bo)) { + drmBOUnreference(fd, &bo); + drmBOUnreference(fd, &bo); + } else { + printf("bo error\n"); + } drmModeFreeOutput(screen->output); drmModeFreeCrtc(screen->crtc); + drmModeFreeFB(screen->fb); + + screen->output = NULL; + screen->crtc = NULL; + screen->fb = NULL; } drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr output) -- cgit v1.2.3 From c8b45e9362aa16fed08540996af6d0b1e2e730d0 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 7 Feb 2008 19:25:52 +0100 Subject: Added userspace part of hotplug ioctl and demo --- tests/modehotplug/Makefile | 14 ++++ tests/modehotplug/demo.c | 157 +++++++++++++++++++++++++++++++++++++++++++++ tests/modehotplug/test | 1 + 3 files changed, 172 insertions(+) create mode 100644 tests/modehotplug/Makefile create mode 100644 tests/modehotplug/demo.c create mode 100755 tests/modehotplug/test (limited to 'tests') diff --git a/tests/modehotplug/Makefile b/tests/modehotplug/Makefile new file mode 100644 index 00000000..467fb11a --- /dev/null +++ b/tests/modehotplug/Makefile @@ -0,0 +1,14 @@ + +all: app + +#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ +# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ + +app: demo.c + @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm demo.c + +clean: + @rm -f app + +run: app + sudo ./test diff --git a/tests/modehotplug/demo.c b/tests/modehotplug/demo.c new file mode 100644 index 00000000..4ef2e386 --- /dev/null +++ b/tests/modehotplug/demo.c @@ -0,0 +1,157 @@ + +#include +#include +#include +#include +#include +#include + +#include "xf86drm.h" +#include "xf86drmMode.h" + +/* structs for the demo_driver */ + +#define DEMO_MAX_OUTPUTS 8 + +struct demo_driver +{ + /* drm stuff */ + int fd; + drmModeResPtr res; + uint32_t counter; + + drmModeOutputPtr outputs[DEMO_MAX_OUTPUTS]; +}; + +struct demo_driver* demoCreateDriver(void); +void demoUpdateRes(struct demo_driver *driver); + +void demoPopulateOutputs(struct demo_driver *driver); +void demoHotplug(struct demo_driver *driver); + +const char* demoGetStatus(drmModeOutputPtr out); + +int main(int argc, char **argv) +{ + struct demo_driver *driver; + uint32_t temp; + int i; + + printf("starting demo\n"); + + driver = demoCreateDriver(); + + if (!driver) { + printf("failed to create driver\n"); + return 1; + } + + driver->counter = drmModeGetHotplug(driver->fd); + demoPopulateOutputs(driver); + while (driver->counter != (temp = drmModeGetHotplug(driver->fd))) { + demoPopulateOutputs(driver); + driver->counter = temp; + } + + for (i = 0; i < driver->res->count_outputs && i < DEMO_MAX_OUTPUTS; i++) { + printf("Output %u is %s\n", + driver->outputs[i]->output_id, + demoGetStatus(driver->outputs[i])); + } + + while(1) { + usleep(100000); + temp = drmModeGetHotplug(driver->fd); + if (temp == driver->counter) + continue; + + demoHotplug(driver); + driver->counter = temp; + } + + return 0; +} + +const char* demoGetStatus(drmModeOutputPtr output) +{ + switch (output->connection) { + case DRM_MODE_CONNECTED: + return "connected"; + case DRM_MODE_DISCONNECTED: + return "disconnected"; + default: + return "unknown"; + } +} + +void demoHotplug(struct demo_driver *driver) +{ + drmModeResPtr res = driver->res; + int i; + drmModeOutputPtr temp, current; + + for (i = 0; i < res->count_outputs && i < DEMO_MAX_OUTPUTS; i++) { + temp = drmModeGetOutput(driver->fd, res->outputs[i]); + current = driver->outputs[i]; + + if (temp->connection != current->connection) { + printf("Output %u became %s was %s\n", + temp->output_id, + demoGetStatus(temp), + demoGetStatus(current)); + } + + drmModeFreeOutput(current); + driver->outputs[i] = temp; + } +} + +void demoPopulateOutputs(struct demo_driver *driver) +{ + drmModeResPtr res = driver->res; + int i; + + for (i = 0; i < res->count_outputs && i < DEMO_MAX_OUTPUTS; i++) { + drmModeFreeOutput(driver->outputs[i]); + driver->outputs[i] = drmModeGetOutput(driver->fd, res->outputs[i]); + } +} + +struct demo_driver* demoCreateDriver(void) +{ + struct demo_driver* driver = malloc(sizeof(struct demo_driver)); + + memset(driver, 0, sizeof(struct demo_driver)); + + driver->fd = drmOpen("i915", NULL); + + if (driver->fd < 0) { + printf("Failed to open the card fb\n"); + goto err_driver; + } + + demoUpdateRes(driver); + if (!driver->res) { + printf("could not retrive resources\n"); + goto err_res; + } + + return driver; + +err_res: + drmClose(driver->fd); +err_driver: + free(driver); + return NULL; +} + +void demoUpdateRes(struct demo_driver *driver) +{ + if (driver->res) + drmModeFreeResources(driver->res); + + driver->res = drmModeGetResources(driver->fd); + + if (!driver->res) + printf("failed to get resources from kernel\n"); +} diff --git a/tests/modehotplug/test b/tests/modehotplug/test new file mode 100755 index 00000000..f98e3708 --- /dev/null +++ b/tests/modehotplug/test @@ -0,0 +1 @@ +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app -- cgit v1.2.3 From 2ceafcccb77723a464abd51d07e664933e117b6e Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 7 Feb 2008 19:32:20 +0100 Subject: Wrong open call --- tests/modehotplug/demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/modehotplug/demo.c b/tests/modehotplug/demo.c index 4ef2e386..1518e84c 100644 --- a/tests/modehotplug/demo.c +++ b/tests/modehotplug/demo.c @@ -123,7 +123,7 @@ struct demo_driver* demoCreateDriver(void) memset(driver, 0, sizeof(struct demo_driver)); - driver->fd = drmOpen("i915", NULL); + driver->fd = drmOpenControl(0); if (driver->fd < 0) { printf("Failed to open the card fb\n"); -- cgit v1.2.3 From f51dc37d75b0b1b8e5636f8f2c201e29986517ea Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 7 Feb 2008 22:21:50 +0000 Subject: After the previous revert fix libdrm to start at minor 1 and fixup the demos --- tests/mode/modetest.c | 2 +- tests/modedemo/demo.c | 39 +++++++++++++++++++++++++++++++++------ tests/modefb/demo.c | 2 +- 3 files changed, 35 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index ab0cdc9c..caa3d970 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -351,7 +351,7 @@ int main(int argc, char **argv) printf("Starting test\n"); - fd = drmOpenControl(0); + fd = drmOpen("i915", NULL); if (fd < 0) { printf("Failed to open the card fb (%d)\n",fd); diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 0882fc91..6b6997ad 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -1,11 +1,16 @@ - +#define CLEAN_FBDEV #include #include #include #include #include #include - +#ifdef CLEAN_FBDEV +#include +#include +#include +#include +#endif #include "xf86drm.h" #include "xf86drmMode.h" @@ -20,6 +25,11 @@ void testCursor(int fd, uint32_t crtc); void prettyColors(int fd, unsigned int handle); void prettyCursor(int fd, unsigned int handle, unsigned int color); +#ifdef CLEAN_FBDEV +struct fb_var_screeninfo var; +struct fb_fix_screeninfo fix; +#endif + /* structs for the demo_driver */ struct demo_driver; @@ -90,6 +100,19 @@ int main(int argc, char **argv) struct demo_driver *driver; int num; int i; +#ifdef CLEAN_FBDEV + int fbdev_fd; + + fbdev_fd = open("/dev/fb0", O_RDWR); + + memset(&var, 0, sizeof(struct fb_var_screeninfo)); + memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); + + if (ioctl(fbdev_fd, FBIOGET_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); + if (ioctl(fbdev_fd, FBIOGET_FSCREENINFO, &fix)) + printf("fix %s\n", strerror(errno)); +#endif printf("starting demo\n"); @@ -131,9 +154,13 @@ int main(int argc, char **argv) testCursor(driver->fd, driver->screens[i].crtc->crtc_id); } - sleep(2); - printf("ok\n"); - return 0; +#ifdef CLEAN_FBDEV + if (ioctl(fbdev_fd, FBIOPUT_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); +#endif + + printf("ok\n"); + return 0; } int demoCreateScreens(struct demo_driver *driver) @@ -260,7 +287,7 @@ struct demo_driver* demoCreateDriver(void) memset(driver, 0, sizeof(struct demo_driver)); - driver->fd = drmOpenControl(0); + driver->fd = drmOpen("i915", NULL); if (driver->fd < 0) { printf("Failed to open the card fb\n"); diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index 7fa3b93f..4d81e511 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -26,7 +26,7 @@ int main(int argc, char **argv) char name[100]; int i,d; int fd; - int drmfd = drmOpenControl(0); + int drmfd = drmOpen("i915", NULL); /* try four devices */ for (d = 0; d < 4; d++) { -- cgit v1.2.3 From db2a1a223b94a5da9c5483b7963660c70052f025 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 7 Feb 2008 23:32:59 +0100 Subject: Added you can now clone displays in modedemo --- tests/modedemo/demo.c | 119 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 105 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 6b6997ad..9eef9022 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -1,4 +1,16 @@ +/* + * Some defines to define the behavior of the program + */ + #define CLEAN_FBDEV +#undef DEMO_CLONE + +#define SIZE_X 2048 +#define SIZE_Y 2048 +/* Pitch needs to be power of two */ +#define PITCH 2048 + + #include #include #include @@ -14,11 +26,6 @@ #include "xf86drm.h" #include "xf86drmMode.h" -#define SIZE_X 2048 -#define SIZE_Y 2048 -/* Pitch needs to be power of two */ -#define PITCH 2048 - /* old functions to be replaced */ drmModeFBPtr createFB(int fd, drmModeResPtr res); void testCursor(int fd, uint32_t crtc); @@ -40,7 +47,10 @@ struct demo_screen drmBO buffer; drmModeFBPtr fb; drmModeCrtcPtr crtc; - drmModeOutputPtr output; + + size_t num_outputs; + uint32_t outputs_id[8]; + drmModeOutputPtr outputs[8]; struct drm_mode_modeinfo *mode; @@ -70,6 +80,7 @@ struct demo_driver struct demo_driver* demoCreateDriver(void); void demoUpdateRes(struct demo_driver *driver); int demoCreateScreens(struct demo_driver *driver); +int demoCreateScreenCloned(struct demo_driver *driver); void demoTakeDownScreen(struct demo_screen *screen); int demoFindConnectedOutputs(struct demo_driver *driver, drmModeOutputPtr *out, size_t max_out); drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr output); @@ -123,7 +134,12 @@ int main(int argc, char **argv) return 1; } +#ifndef DEMO_CLONE num = demoCreateScreens(driver); +#else + num = demoCreateScreenCloned(driver); +#endif + if (num < 1) { printf("no screens attached or an error occured\n"); return 1; @@ -154,13 +170,19 @@ int main(int argc, char **argv) testCursor(driver->fd, driver->screens[i].crtc->crtc_id); } + sleep(2); + printf("taking down screens\n"); + for (i = 0; i < num; i++) { + demoTakeDownScreen(&driver->screens[i]); + } + #ifdef CLEAN_FBDEV if (ioctl(fbdev_fd, FBIOPUT_VSCREENINFO, &var)) printf("var %s\n", strerror(errno)); #endif - printf("ok\n"); - return 0; + printf("ok\n"); + return 0; } int demoCreateScreens(struct demo_driver *driver) @@ -201,7 +223,10 @@ int demoCreateScreens(struct demo_driver *driver) screen->virt_y = SIZE_Y; screen->pitch = PITCH; - screen->output = out[i]; + screen->outputs[0] = out[i]; + screen->outputs_id[0] = out[i]->output_id; + screen->num_outputs = 1; + screen->mode = &mode; screen->driver = driver; @@ -210,7 +235,7 @@ int demoCreateScreens(struct demo_driver *driver) screen->crtc->crtc_id, screen->fb->buffer_id, 0, 0, - &screen->output->output_id, 1, + screen->outputs_id, screen->num_outputs, screen->mode); if (ret) { @@ -226,9 +251,73 @@ int demoCreateScreens(struct demo_driver *driver) return num_screens; } +int demoCreateScreenCloned(struct demo_driver *driver) +{ + drmModeOutputPtr out[MAX_FIND_OUTPUTS]; + int num; + struct demo_screen *screen; + int ret = 0; + int i; + + num = demoFindConnectedOutputs(driver, out, MAX_FIND_OUTPUTS); + if (num < 0) + return 0; + + printf("found %i connected outputs\n", num); + + screen = &driver->screens[0]; + + screen->fb = createFB(driver->fd, driver->res); + if (!screen->fb) { + printf("could not create framebuffer\n"); + return 0; + } + + screen->mode = &mode; + screen->driver = driver; + + screen->virt_x = SIZE_X; + screen->virt_y = SIZE_Y; + screen->pitch = PITCH; + + screen->num_outputs = 0; + for (i = 0; i < num; i++) { + screen->crtc = demoFindFreeCrtc(driver, out[i]); + if (!screen->crtc) { + printf("found no free crtc for output\n"); + drmModeFreeOutput(out[i]); + continue; + } + + screen->outputs[screen->num_outputs] = out[i]; + screen->outputs_id[screen->num_outputs] = out[i]->output_id; + screen->num_outputs++; + printf("%u, %u\n", out[i]->output_id, screen->num_outputs); + } + + ret = drmModeSetCrtc( + driver->fd, + screen->crtc->crtc_id, + screen->fb->buffer_id, + 0, 0, + screen->outputs_id, screen->num_outputs, + screen->mode); + + if (ret) { + printf("failed to set mode\n"); + demoTakeDownScreen(screen); + return 0; + } + + demoUpdateRes(driver); + + return 1; +} + void demoTakeDownScreen(struct demo_screen *screen) { int fd = screen->driver->fd; + int i; drmBO bo; if (screen->crtc) @@ -245,11 +334,14 @@ void demoTakeDownScreen(struct demo_screen *screen) printf("bo error\n"); } - drmModeFreeOutput(screen->output); + for (i = 0; i < screen->num_outputs; i++) { + drmModeFreeOutput(screen->outputs[i]); + screen->outputs[i] = NULL; + } + drmModeFreeCrtc(screen->crtc); drmModeFreeFB(screen->fb); - screen->output = NULL; screen->crtc = NULL; screen->fb = NULL; } @@ -260,7 +352,6 @@ drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr out int i, j, used = 0; drmModeResPtr res = driver->res; - for (i = 0; i < res->count_crtcs; i++) { used = 0; for (j = 0; j < DEMO_MAX_SCREENS; j++) { @@ -353,7 +444,7 @@ void demoPanScreen(struct demo_screen *screen, uint16_t x, uint16_t y) screen->crtc->crtc_id, screen->fb->buffer_id, x, y, - &screen->output->output_id, 1, + screen->outputs_id, screen->num_outputs, screen->mode); } -- cgit v1.2.3 From db85ed25afc616acfaadb21facf6066354f9d490 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 13 Feb 2008 12:20:02 +1000 Subject: Revert "After the previous revert fix libdrm to start at minor 1" This reverts commit f51dc37d75b0b1b8e5636f8f2c201e29986517ea. Conflicts: tests/modedemo/demo.c --- tests/mode/modetest.c | 2 +- tests/modedemo/demo.c | 28 ++-------------------------- tests/modefb/demo.c | 2 +- 3 files changed, 4 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index caa3d970..ab0cdc9c 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -351,7 +351,7 @@ int main(int argc, char **argv) printf("Starting test\n"); - fd = drmOpen("i915", NULL); + fd = drmOpenControl(0); if (fd < 0) { printf("Failed to open the card fb (%d)\n",fd); diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 9eef9022..474f04a5 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -10,19 +10,13 @@ /* Pitch needs to be power of two */ #define PITCH 2048 - #include #include #include #include #include #include -#ifdef CLEAN_FBDEV -#include -#include -#include -#include -#endif + #include "xf86drm.h" #include "xf86drmMode.h" @@ -32,11 +26,6 @@ void testCursor(int fd, uint32_t crtc); void prettyColors(int fd, unsigned int handle); void prettyCursor(int fd, unsigned int handle, unsigned int color); -#ifdef CLEAN_FBDEV -struct fb_var_screeninfo var; -struct fb_fix_screeninfo fix; -#endif - /* structs for the demo_driver */ struct demo_driver; @@ -111,19 +100,6 @@ int main(int argc, char **argv) struct demo_driver *driver; int num; int i; -#ifdef CLEAN_FBDEV - int fbdev_fd; - - fbdev_fd = open("/dev/fb0", O_RDWR); - - memset(&var, 0, sizeof(struct fb_var_screeninfo)); - memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); - - if (ioctl(fbdev_fd, FBIOGET_VSCREENINFO, &var)) - printf("var %s\n", strerror(errno)); - if (ioctl(fbdev_fd, FBIOGET_FSCREENINFO, &fix)) - printf("fix %s\n", strerror(errno)); -#endif printf("starting demo\n"); @@ -378,7 +354,7 @@ struct demo_driver* demoCreateDriver(void) memset(driver, 0, sizeof(struct demo_driver)); - driver->fd = drmOpen("i915", NULL); + driver->fd = drmOpenControl(0); if (driver->fd < 0) { printf("Failed to open the card fb\n"); diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index 4d81e511..7fa3b93f 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -26,7 +26,7 @@ int main(int argc, char **argv) char name[100]; int i,d; int fd; - int drmfd = drmOpen("i915", NULL); + int drmfd = drmOpenControl(0); /* try four devices */ for (d = 0; d < 4; d++) { -- cgit v1.2.3 From 88cb873045b76bf947f45fb127baa96f055ad32c Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Wed, 20 Feb 2008 19:54:36 +0000 Subject: minor test fixes --- tests/modedemo/demo.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- tests/modefb/demo.c | 14 ++++++++------ tests/modehotplug/demo.c | 2 +- 3 files changed, 51 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 474f04a5..db51cd66 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -16,6 +16,12 @@ #include #include #include +#ifdef CLEAN_FBDEV +#include +#include +#include +#include +#endif #include "xf86drm.h" #include "xf86drmMode.h" @@ -26,6 +32,11 @@ void testCursor(int fd, uint32_t crtc); void prettyColors(int fd, unsigned int handle); void prettyCursor(int fd, unsigned int handle, unsigned int color); +#ifdef CLEAN_FBDEV +struct fb_var_screeninfo var; +struct fb_fix_screeninfo fix; +#endif + /* structs for the demo_driver */ struct demo_driver; @@ -101,6 +112,20 @@ int main(int argc, char **argv) int num; int i; +#ifdef CLEAN_FBDEV + int fbdev_fd; + + fbdev_fd = open("/dev/fb0", O_RDWR); + + memset(&var, 0, sizeof(struct fb_var_screeninfo)); + memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); + + if (ioctl(fbdev_fd, FBIOGET_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); + if (ioctl(fbdev_fd, FBIOGET_FSCREENINFO, &fix)) + printf("fix %s\n", strerror(errno)); +#endif + printf("starting demo\n"); driver = demoCreateDriver(); @@ -155,10 +180,12 @@ int main(int argc, char **argv) #ifdef CLEAN_FBDEV if (ioctl(fbdev_fd, FBIOPUT_VSCREENINFO, &var)) printf("var %s\n", strerror(errno)); + + close(fbdev_fd); #endif - printf("ok\n"); - return 0; + printf("ok\n"); + return 0; } int demoCreateScreens(struct demo_driver *driver) @@ -296,8 +323,20 @@ void demoTakeDownScreen(struct demo_screen *screen) int i; drmBO bo; +#if 0 + /* This can bust the fbdev arrangement as it basically unhooks + * the outputs and the fbdev backend doesn't know how to put things + * back on track. Realistically, it's up to the crtc owner to restore + * things..... + * + * So if you are mixing API's make sure the modesetting owner puts + * back the original CRTC arrangement so fbdev can continue... + * + * Ho-hum.. + */ if (screen->crtc) drmModeSetCrtc(fd, screen->crtc->crtc_id, 0, 0, 0, 0, 0, 0); +#endif if (screen->fb) drmModeRmFB(fd, screen->fb->buffer_id); @@ -354,7 +393,7 @@ struct demo_driver* demoCreateDriver(void) memset(driver, 0, sizeof(struct demo_driver)); - driver->fd = drmOpenControl(0); + driver->fd = drmOpen("i915",NULL); if (driver->fd < 0) { printf("Failed to open the card fb\n"); diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index 7fa3b93f..b6d1f65b 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -26,7 +26,12 @@ int main(int argc, char **argv) char name[100]; int i,d; int fd; - int drmfd = drmOpenControl(0); + int drmfd = drmOpen("i915", NULL); + + if (drmfd < 0) { + printf("drmOpenControl failed\n"); + return 1; + } /* try four devices */ for (d = 0; d < 4; d++) { @@ -38,11 +43,6 @@ int main(int argc, char **argv) return 1; } - if (drmfd < 0) { - printf("drmOpenControl failed\n"); - return 1; - } - memset(&var, 0, sizeof(struct fb_var_screeninfo)); memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); @@ -79,6 +79,8 @@ int main(int argc, char **argv) printf("cursor (may show up on wrong CRTC - fixme)\n"); cursor(fd, drmfd); + + close(fd); } return 0; } diff --git a/tests/modehotplug/demo.c b/tests/modehotplug/demo.c index 1518e84c..4ef2e386 100644 --- a/tests/modehotplug/demo.c +++ b/tests/modehotplug/demo.c @@ -123,7 +123,7 @@ struct demo_driver* demoCreateDriver(void) memset(driver, 0, sizeof(struct demo_driver)); - driver->fd = drmOpenControl(0); + driver->fd = drmOpen("i915", NULL); if (driver->fd < 0) { printf("Failed to open the card fb\n"); -- cgit v1.2.3 From 0e72819629741339af46d0e303f33482acdf0972 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 29 Feb 2008 14:07:29 +1000 Subject: drm: change fb api to take a bo handle not the bo pointer. --- tests/mode/modetest.c | 2 +- tests/modedemo/demo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index ab0cdc9c..a50b0cc5 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -291,7 +291,7 @@ int testFrameBufferAdd(int fd, drmModeResPtr res) goto err; printf("\tAdding FB\n"); - ret = drmModeAddFB(fd, 800, 600, 32, 8, 0, &bo, &fb); + ret = drmModeAddFB(fd, 800, 600, 32, 8, 0, bo->handle, &fb); if (ret) goto err_bo; diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index db51cd66..00020bde 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -483,7 +483,7 @@ drmModeFBPtr createFB(int fd, drmModeResPtr res) goto err; } - ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, PITCH * 4, &bo, &fb); + ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, PITCH * 4, bo->handle, &fb); if (ret) goto err_bo; -- cgit v1.2.3 From b87c7ff79ee88ec39a285bc17bd2996252b9fd48 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Wed, 5 Mar 2008 10:33:16 +0000 Subject: Add property info. fix bo handle --- tests/modedemo/demo.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 00020bde..83a33aa6 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -429,7 +429,7 @@ void demoUpdateRes(struct demo_driver *driver) int demoFindConnectedOutputs(struct demo_driver *driver, drmModeOutputPtr *out, size_t max_out) { int count = 0; - int i; + int i,j; int fd = driver->fd; drmModeResPtr res = driver->res; @@ -441,10 +441,20 @@ int demoFindConnectedOutputs(struct demo_driver *driver, drmModeOutputPtr *out, if (!output) continue; - if (output->connection != DRM_MODE_CONNECTED) { + if (output->connection == DRM_MODE_DISCONNECTED) { drmModeFreeOutput(output); continue; } + + for (j = 0; j < output->count_props; j++) { + drmModePropertyPtr prop; + + prop = drmModeGetProperty(fd, output->props[j]); + + printf("Property: %s\n",prop->name); + if (prop->count_enums) + printf("%s\n",prop->enums[output->prop_values[j]].name); + } out[count++] = output; } @@ -483,7 +493,7 @@ drmModeFBPtr createFB(int fd, drmModeResPtr res) goto err; } - ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, PITCH * 4, bo->handle, &fb); + ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, PITCH * 4, bo.handle, &fb); if (ret) goto err_bo; -- cgit v1.2.3 From 7f04dd06e6003dd492ae5ddc876121a686f49157 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Wed, 12 Mar 2008 09:47:52 +0000 Subject: Add sample code to test hotplug events --- tests/modedemo/demo.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests') diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 83a33aa6..3fad984d 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -22,6 +22,7 @@ #include #include #endif +#include #include "xf86drm.h" #include "xf86drmMode.h" @@ -387,9 +388,28 @@ drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr out return crtc; } +static int driverfd; + +static void +hotplugSIGNAL(int sig, siginfo_t *si, void *d) +{ + union drm_wait_hotplug hw; + int ret; + + printf("GOT HOTPLUG EVENT!\n"); + + /* ask for another hotplug event ! */ + memset(&hw, 0, sizeof(hw)); + hw.request.type = _DRM_HOTPLUG_SIGNAL; + hw.request.signal = SIGUSR1; + ret = ioctl(driverfd, DRM_IOCTL_WAIT_HOTPLUG, &hw); +} + struct demo_driver* demoCreateDriver(void) { struct demo_driver* driver = malloc(sizeof(struct demo_driver)); + union drm_wait_hotplug hw; + int ret = 0; memset(driver, 0, sizeof(struct demo_driver)); @@ -400,6 +420,33 @@ struct demo_driver* demoCreateDriver(void) goto err_driver; } +#if 0 + /* ioctl wait for hotplug */ + do { + memset(&hw, 0, sizeof(hw)); + ret = ioctl(driver->fd, DRM_IOCTL_WAIT_HOTPLUG, &hw); + printf("HOTPLUG %d %d %d\n",ret,errno,hw.reply.counter); + } while (ret && errno == EBUSY); +#else + /* signal for hotplug */ + { + struct sigaction sa; + struct sigaction osa; + + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = hotplugSIGNAL; + sigaction(SIGUSR1, &sa, &osa); + + driverfd = driver->fd; + + memset(&hw, 0, sizeof(hw)); + hw.request.type = _DRM_HOTPLUG_SIGNAL; + hw.request.signal = SIGUSR1; + ret = ioctl(driver->fd, DRM_IOCTL_WAIT_HOTPLUG, &hw); + } +#endif + demoUpdateRes(driver); if (!driver->res) { printf("could not retrive resources\n"); -- cgit v1.2.3 From 7317e774b5cddb7218c1416fa4d9ee98756e4890 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 9 May 2008 09:26:17 +0100 Subject: Fix test applications for recent DRM changes --- tests/mode/modetest.c | 2 +- tests/modedemo/demo.c | 4 ++-- tests/modefb/demo.c | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index a50b0cc5..1fab0406 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -291,7 +291,7 @@ int testFrameBufferAdd(int fd, drmModeResPtr res) goto err; printf("\tAdding FB\n"); - ret = drmModeAddFB(fd, 800, 600, 32, 8, 0, bo->handle, &fb); + ret = drmModeAddFB(fd, 800, 600, 32, 8, 0, bo.handle, &fb); if (ret) goto err_bo; diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 3fad984d..72d69405 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -603,7 +603,7 @@ void testCursor(int fd, uint32_t crtc) prettyCursor(fd, bo.handle, 0xFFFF00FF); printf("set cursor\n"); - drmModeSetCursor(fd, crtc, &bo, 64, 64); + drmModeSetCursor(fd, crtc, bo.handle, 64, 64); printf("move cursor 0, 0\n"); drmModeMoveCursor(fd, crtc, 0, 0); sleep(1); @@ -614,7 +614,7 @@ void testCursor(int fd, uint32_t crtc) printf("move cursor 100, 100\n"); drmModeMoveCursor(fd, crtc, 100, 100); sleep(1); - drmModeSetCursor(fd, crtc, NULL, 0, 0); + drmModeSetCursor(fd, crtc, 0, 0, 0); } void prettyCursor(int fd, unsigned int handle, unsigned int color) diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c index b6d1f65b..ead53334 100644 --- a/tests/modefb/demo.c +++ b/tests/modefb/demo.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -16,8 +17,6 @@ void cursor(int fd, int drmfd); void prettyColors(int fd); void prettyCursor(int fd, unsigned int handle, unsigned int color); -extern void sleep(int); - struct fb_var_screeninfo var; struct fb_fix_screeninfo fix; @@ -152,7 +151,7 @@ void cursor(int fd, int drmfd) } prettyCursor(drmfd, bo.handle, 0xFFFF00FF); - drmModeSetCursor(drmfd, crtc, &bo, 64, 64); + drmModeSetCursor(drmfd, crtc, bo.handle, 64, 64); drmModeMoveCursor(drmfd, crtc, 0, 0); sleep(1); prettyCursor(drmfd, bo.handle, 0xFFFF0000); @@ -160,7 +159,7 @@ void cursor(int fd, int drmfd) sleep(1); drmModeMoveCursor(drmfd, crtc, 100, 100); sleep(1); - drmModeSetCursor(drmfd, crtc, NULL, 0, 0); + drmModeSetCursor(drmfd, crtc, 0, 0, 0); drmBOUnreference(drmfd, &bo); } -- cgit v1.2.3 From eeff906aa0f64da12a0154c66d99e8492dd95107 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 9 May 2008 16:36:28 +0100 Subject: Fix build problems --- tests/mode/modetest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 1fab0406..99238d5a 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -351,7 +351,7 @@ int main(int argc, char **argv) printf("Starting test\n"); - fd = drmOpenControl(0); + fd = drmOpen("i915", NULL); if (fd < 0) { printf("Failed to open the card fb (%d)\n",fd); -- cgit v1.2.3 From 4403c59b76c55c9c430decac8bc76e4230a253ab Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 13:22:51 +1000 Subject: tests: add basic encoder reading to test --- tests/mode/modetest.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 99238d5a..eba072ee 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -52,6 +52,7 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) int i = 0, j; struct drm_mode_modeinfo *mode = NULL; drmModePropertyPtr props; + drmModeEncoderPtr enc; unsigned char *name = NULL; printf("Output: %d-%d\n", output->output_type, output->output_type_id); @@ -65,6 +66,14 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) printf("\tclones : %i\n", output->clones); printf("\tcount_modes : %i\n", output->count_modes); printf("\tcount_props : %i\n", output->count_props); + printf("\tcount_encs : %i\n", output->count_encoders); + + for (i = 0; i < output->count_encoders; i++) { + enc = drmModeGetEncoder(fd, output->encoders[i]); + if (enc) { + printf("Encoder: %d %d %d %d\n", enc->encoder_id, enc->encoder_type, enc->crtcs, enc->clones); + } + } for (i = 0; i < output->count_props; i++) { props = drmModeGetProperty(fd, output->props[i]); @@ -121,6 +130,16 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) return 0; } +int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id) +{ + printf("Encoder\n"); + printf("\tid :%i\n", id); + printf("\ttype :%d\n", encoder->encoder_type); + printf("\tcrtcs :%d\n", encoder->crtcs); + printf("\tclones :%d\n", encoder->clones); + return 0; +} + int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) { printf("Crtc\n"); @@ -158,6 +177,7 @@ int printRes(int fd, drmModeResPtr res) drmModeOutputPtr output; drmModeCrtcPtr crtc; drmModeFBPtr fb; + drmModeEncoderPtr encoder; for (i = 0; i < res->count_outputs; i++) { output = drmModeGetOutput(fd, res->outputs[i]); @@ -170,6 +190,18 @@ int printRes(int fd, drmModeResPtr res) } } + for (i = 0; i < res->count_encoders; i++) { + encoder = drmModeGetEncoder(fd, res->encoders[i]); + + if (!encoder) + printf("Could not get encoder %i\n", i); + else { + printEncoder(fd, res, encoder, res->encoders[i]); + drmModeFreeEncoder(encoder); + } + } + + for (i = 0; i < res->count_crtcs; i++) { crtc = drmModeGetCrtc(fd, res->crtcs[i]); -- cgit v1.2.3 From 9d38448ed33aaff324cc4bbe1e0878593e97d07d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 15:03:12 +1000 Subject: modesetting: the great renaming. Okay we have crtc, encoder and connectors. No more outputs exposed beyond driver internals I've broken intel tv connector stuff. Really for TV we should have one TV connector, with a sub property for the type of signal been driven over it --- tests/mode/modetest.c | 90 +++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index eba072ee..3ff78f96 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -47,7 +47,7 @@ int printMode(struct drm_mode_modeinfo *mode) return 0; } -int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) +int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id) { int i = 0, j; struct drm_mode_modeinfo *mode = NULL; @@ -55,28 +55,28 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) drmModeEncoderPtr enc; unsigned char *name = NULL; - printf("Output: %d-%d\n", output->output_type, output->output_type_id); + printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id); printf("\tid : %i\n", id); - printf("\tcrtc id : %i\n", output->crtc); - printf("\tconn : %s\n", getConnectionText(output->connection)); - printf("\tsize : %ix%i (mm)\n", output->mmWidth, output->mmHeight); - printf("\tcount_crtcs : %i\n", output->count_crtcs); - printf("\tcrtcs : %i\n", output->crtcs); - printf("\tcount_clones : %i\n", output->count_clones); - printf("\tclones : %i\n", output->clones); - printf("\tcount_modes : %i\n", output->count_modes); - printf("\tcount_props : %i\n", output->count_props); - printf("\tcount_encs : %i\n", output->count_encoders); - - for (i = 0; i < output->count_encoders; i++) { - enc = drmModeGetEncoder(fd, output->encoders[i]); + printf("\tcrtc id : %i\n", connector->crtc); + printf("\tconn : %s\n", getConnectionText(connector->connection)); + printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight); + printf("\tcount_crtcs : %i\n", connector->count_crtcs); + printf("\tcrtcs : %i\n", connector->crtcs); + printf("\tcount_clones : %i\n", connector->count_clones); + printf("\tclones : %i\n", connector->clones); + printf("\tcount_modes : %i\n", connector->count_modes); + printf("\tcount_props : %i\n", connector->count_props); + printf("\tcount_encs : %i\n", connector->count_encoders); + + for (i = 0; i < connector->count_encoders; i++) { + enc = drmModeGetEncoder(fd, connector->encoders[i]); if (enc) { printf("Encoder: %d %d %d %d\n", enc->encoder_id, enc->encoder_type, enc->crtcs, enc->clones); } } - for (i = 0; i < output->count_props; i++) { - props = drmModeGetProperty(fd, output->props[i]); + for (i = 0; i < connector->count_props; i++) { + props = drmModeGetProperty(fd, connector->props[i]); name = NULL; if (props) { printf("Property: %s\n", props->name); @@ -91,7 +91,7 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) if (props->flags & DRM_MODE_PROP_BLOB) { drmModePropertyBlobPtr blob; - blob = drmModeGetPropertyBlob(fd, output->prop_values[i]); + blob = drmModeGetPropertyBlob(fd, connector->prop_values[i]); if (blob) { printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); drmModeFreePropertyBlob(blob); @@ -103,15 +103,15 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) for (j = 0; j < props->count_enums; j++) { printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name); - if (output->prop_values[i] == props->enums[j].value) + if (connector->prop_values[i] == props->enums[j].value) name = props->enums[j].name; } if (props->count_enums && name) { - printf("\toutput property name %s %s\n", props->name, name); + printf("\tconnector property name %s %s\n", props->name, name); } else { - printf("\toutput property id %s %lli\n", props->name, output->prop_values[i]); + printf("\tconnector property id %s %lli\n", props->name, connector->prop_values[i]); } } @@ -119,12 +119,12 @@ int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id) } } - for (i = 0; i < output->count_modes; i++) { - mode = &output->modes[i]; + for (i = 0; i < connector->count_modes; i++) { + mode = &connector->modes[i]; if (mode) printMode(mode); else - printf("\t\tmode: Invalid mode %p\n", &output->modes[i]); + printf("\t\tmode: Invalid mode %p\n", &connector->modes[i]); } return 0; @@ -149,8 +149,8 @@ int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) printf("\twidth : %i\n", crtc->width); printf("\theight : %i\n", crtc->height); printf("\tmode : %p\n", &crtc->mode); - printf("\tnum outputs : %i\n", crtc->count_outputs); - printf("\toutputs : %i\n", crtc->outputs); + printf("\tnum connectors : %i\n", crtc->count_connectors); + printf("\tconnectors : %i\n", crtc->connectors); printf("\tnum possible : %i\n", crtc->count_possibles); printf("\tpossibles : %i\n", crtc->possibles); @@ -174,19 +174,19 @@ int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb) int printRes(int fd, drmModeResPtr res) { int i; - drmModeOutputPtr output; + drmModeConnectorPtr connector; drmModeCrtcPtr crtc; drmModeFBPtr fb; drmModeEncoderPtr encoder; - for (i = 0; i < res->count_outputs; i++) { - output = drmModeGetOutput(fd, res->outputs[i]); + for (i = 0; i < res->count_connectors; i++) { + connector = drmModeGetConnector(fd, res->connectors[i]); - if (!output) - printf("Could not get output %i\n", i); + if (!connector) + printf("Could not get connector %i\n", i); else { - printOutput(fd, res, output, res->outputs[i]); - drmModeFreeOutput(output); + printConnector(fd, res, connector, res->connectors[i]); + drmModeFreeConnector(connector); } } @@ -246,24 +246,24 @@ static struct drm_mode_modeinfo mode = { int testMode(int fd, drmModeResPtr res) { - uint32_t output = res->outputs[0]; + uint32_t connector = res->connectors[0]; uint32_t newMode = 0; int ret = 0; int error = 0; - printf("Test: adding mode to output %i\n", output); + printf("Test: adding mode to connector %i\n", connector); /* printMode(&mode); */ - printf("\tAttaching mode %i to output %i\n", newMode, output); + printf("\tAttaching mode %i to connector %i\n", newMode, connector); - ret = drmModeAttachMode(fd, output, &mode); + ret = drmModeAttachMode(fd, connector, &mode); if (ret) goto err_mode; - printf("\tDetaching mode %i from output %i\n", newMode, output); - ret = drmModeDetachMode(fd, output, &mode); + printf("\tDetaching mode %i from connector %i\n", newMode, connector); + ret = drmModeDetachMode(fd, connector, &mode); if (ret) goto err_mode; @@ -362,15 +362,15 @@ err: int testDPMS(int fd, drmModeResPtr res) { - int output_id; + int connector_id; int i; - for (i = 0; i < res->count_outputs; i++) { - output_id = res->outputs[i]; - /* turn output off */ - drmModeOutputSetProperty(fd, output_id, dpms_prop_id, 3); + for (i = 0; i < res->count_connectors; i++) { + connector_id = res->connectors[i]; + /* turn connector off */ + drmModeConnectorSetProperty(fd, connector_id, dpms_prop_id, 3); sleep(2); - drmModeOutputSetProperty(fd, output_id, dpms_prop_id, 0); + drmModeConnectorSetProperty(fd, connector_id, dpms_prop_id, 0); } return 1; -- cgit v1.2.3 From 30fc88fdf9084ffcb9e76acbdee95d9691ac4ba4 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 30 May 2008 15:18:07 +1000 Subject: modesetting: drop crtcs/clones from the connectors --- tests/mode/modetest.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 3ff78f96..382cba65 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -60,10 +60,6 @@ int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uin printf("\tcrtc id : %i\n", connector->crtc); printf("\tconn : %s\n", getConnectionText(connector->connection)); printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight); - printf("\tcount_crtcs : %i\n", connector->count_crtcs); - printf("\tcrtcs : %i\n", connector->crtcs); - printf("\tcount_clones : %i\n", connector->count_clones); - printf("\tclones : %i\n", connector->clones); printf("\tcount_modes : %i\n", connector->count_modes); printf("\tcount_props : %i\n", connector->count_props); printf("\tcount_encs : %i\n", connector->count_encoders); -- cgit v1.2.3 From dba95ec34315d62934ff0e493e085aa6a03cde7c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 2 Jun 2008 10:41:12 +1000 Subject: drm: fixup some interfaces so test code works again --- tests/mode/modetest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index 382cba65..bd1e8000 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -57,7 +57,7 @@ int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uin printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id); printf("\tid : %i\n", id); - printf("\tcrtc id : %i\n", connector->crtc); + printf("\tencoder id : %i\n", connector->encoder); printf("\tconn : %s\n", getConnectionText(connector->connection)); printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight); printf("\tcount_modes : %i\n", connector->count_modes); @@ -67,7 +67,7 @@ int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uin for (i = 0; i < connector->count_encoders; i++) { enc = drmModeGetEncoder(fd, connector->encoders[i]); if (enc) { - printf("Encoder: %d %d %d %d\n", enc->encoder_id, enc->encoder_type, enc->crtcs, enc->clones); + printf("Encoder: %d %d %d %d %d\n", enc->crtc, enc->encoder_id, enc->encoder_type, enc->crtcs, enc->clones); } } -- cgit v1.2.3 From 4e7b24639808e5e1e2c05143028db1a3bc2812e9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 2 Jun 2008 14:04:41 +1000 Subject: drm: add functions to get/set gamma ramps --- tests/mode/modetest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c index bd1e8000..bb91e832 100644 --- a/tests/mode/modetest.c +++ b/tests/mode/modetest.c @@ -145,6 +145,7 @@ int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) printf("\twidth : %i\n", crtc->width); printf("\theight : %i\n", crtc->height); printf("\tmode : %p\n", &crtc->mode); + printf("\tgamma size : %d\n", crtc->gamma_size); printf("\tnum connectors : %i\n", crtc->count_connectors); printf("\tconnectors : %i\n", crtc->connectors); printf("\tnum possible : %i\n", crtc->count_possibles); -- cgit v1.2.3 From b28d309210475b6f671af7617c779bd1d7a6810a Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 2 Jul 2008 13:59:19 +0200 Subject: tests: Improved and renamed the mode app to modeprint --- tests/mode/Makefile | 14 -- tests/mode/modetest.c | 409 --------------------------------------------- tests/mode/test | 1 - tests/modeprint/Makefile | 14 ++ tests/modeprint/modetest.c | 352 ++++++++++++++++++++++++++++++++++++++ tests/modeprint/test | 1 + 6 files changed, 367 insertions(+), 424 deletions(-) delete mode 100644 tests/mode/Makefile delete mode 100644 tests/mode/modetest.c delete mode 100755 tests/mode/test create mode 100644 tests/modeprint/Makefile create mode 100644 tests/modeprint/modetest.c create mode 100755 tests/modeprint/test (limited to 'tests') diff --git a/tests/mode/Makefile b/tests/mode/Makefile deleted file mode 100644 index 7a9c3c24..00000000 --- a/tests/mode/Makefile +++ /dev/null @@ -1,14 +0,0 @@ - -all: app - -#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ -# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ - -app: modetest.c - @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c - -clean: - @rm -f app - -run: app - @sudo ./test diff --git a/tests/mode/modetest.c b/tests/mode/modetest.c deleted file mode 100644 index bb91e832..00000000 --- a/tests/mode/modetest.c +++ /dev/null @@ -1,409 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include "xf86drm.h" -#include "xf86drmMode.h" - -int dpms_prop_id = 0; -const char* getConnectionText(drmModeConnection conn) -{ - switch (conn) { - case DRM_MODE_CONNECTED: - return "connected"; - case DRM_MODE_DISCONNECTED: - return "disconnected"; - default: - return "unknown"; - } - -} - -int printMode(struct drm_mode_modeinfo *mode) -{ -#if 1 - printf("Mode: %s\n", mode->name); - printf("\tclock : %i\n", mode->clock); - printf("\thdisplay : %i\n", mode->hdisplay); - printf("\thsync_start : %i\n", mode->hsync_start); - printf("\thsync_end : %i\n", mode->hsync_end); - printf("\thtotal : %i\n", mode->htotal); - printf("\thskew : %i\n", mode->hskew); - printf("\tvdisplay : %i\n", mode->vdisplay); - printf("\tvsync_start : %i\n", mode->vsync_start); - printf("\tvsync_end : %i\n", mode->vsync_end); - printf("\tvtotal : %i\n", mode->vtotal); - printf("\tvscan : %i\n", mode->vscan); - printf("\tvrefresh : %i\n", mode->vrefresh); - printf("\tflags : %i\n", mode->flags); -#else - printf("Mode: \"%s\" %ix%i %.0f\n", mode->name, - mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0); -#endif - return 0; -} - -int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id) -{ - int i = 0, j; - struct drm_mode_modeinfo *mode = NULL; - drmModePropertyPtr props; - drmModeEncoderPtr enc; - unsigned char *name = NULL; - - printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id); - printf("\tid : %i\n", id); - printf("\tencoder id : %i\n", connector->encoder); - printf("\tconn : %s\n", getConnectionText(connector->connection)); - printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight); - printf("\tcount_modes : %i\n", connector->count_modes); - printf("\tcount_props : %i\n", connector->count_props); - printf("\tcount_encs : %i\n", connector->count_encoders); - - for (i = 0; i < connector->count_encoders; i++) { - enc = drmModeGetEncoder(fd, connector->encoders[i]); - if (enc) { - printf("Encoder: %d %d %d %d %d\n", enc->crtc, enc->encoder_id, enc->encoder_type, enc->crtcs, enc->clones); - } - } - - for (i = 0; i < connector->count_props; i++) { - props = drmModeGetProperty(fd, connector->props[i]); - name = NULL; - if (props) { - printf("Property: %s\n", props->name); - printf("\tid: %i\n", props->prop_id); - printf("\tflags: %i\n", props->flags); - printf("\tvalues %d: ", props->count_values); - for (j = 0; j < props->count_values; j++) - printf("%lld ", props->values[j]); - - printf("\n\tenums %d: \n", props->count_enums); - - if (props->flags & DRM_MODE_PROP_BLOB) { - drmModePropertyBlobPtr blob; - - blob = drmModeGetPropertyBlob(fd, connector->prop_values[i]); - if (blob) { - printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); - drmModeFreePropertyBlob(blob); - } - - } else { - if (!strncmp(props->name, "DPMS", 4)) - dpms_prop_id = props->prop_id; - - for (j = 0; j < props->count_enums; j++) { - printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name); - if (connector->prop_values[i] == props->enums[j].value) - name = props->enums[j].name; - - } - - if (props->count_enums && name) { - printf("\tconnector property name %s %s\n", props->name, name); - } else { - printf("\tconnector property id %s %lli\n", props->name, connector->prop_values[i]); - } - } - - drmModeFreeProperty(props); - } - } - - for (i = 0; i < connector->count_modes; i++) { - mode = &connector->modes[i]; - if (mode) - printMode(mode); - else - printf("\t\tmode: Invalid mode %p\n", &connector->modes[i]); - } - - return 0; -} - -int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id) -{ - printf("Encoder\n"); - printf("\tid :%i\n", id); - printf("\ttype :%d\n", encoder->encoder_type); - printf("\tcrtcs :%d\n", encoder->crtcs); - printf("\tclones :%d\n", encoder->clones); - return 0; -} - -int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) -{ - printf("Crtc\n"); - printf("\tid : %i\n", id); - printf("\tx : %i\n", crtc->x); - printf("\ty : %i\n", crtc->y); - printf("\twidth : %i\n", crtc->width); - printf("\theight : %i\n", crtc->height); - printf("\tmode : %p\n", &crtc->mode); - printf("\tgamma size : %d\n", crtc->gamma_size); - printf("\tnum connectors : %i\n", crtc->count_connectors); - printf("\tconnectors : %i\n", crtc->connectors); - printf("\tnum possible : %i\n", crtc->count_possibles); - printf("\tpossibles : %i\n", crtc->possibles); - - return 0; -} - -int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb) -{ - printf("Framebuffer\n"); - printf("\thandle : %i\n", fb->handle); - printf("\twidth : %i\n", fb->width); - printf("\theight : %i\n", fb->height); - printf("\tpitch : %i\n", fb->pitch);; - printf("\tbpp : %i\n", fb->bpp); - printf("\tdepth : %i\n", fb->depth); - printf("\tbuffer_id : %i\n", fb->buffer_id); - - return 0; -} - -int printRes(int fd, drmModeResPtr res) -{ - int i; - drmModeConnectorPtr connector; - drmModeCrtcPtr crtc; - drmModeFBPtr fb; - drmModeEncoderPtr encoder; - - for (i = 0; i < res->count_connectors; i++) { - connector = drmModeGetConnector(fd, res->connectors[i]); - - if (!connector) - printf("Could not get connector %i\n", i); - else { - printConnector(fd, res, connector, res->connectors[i]); - drmModeFreeConnector(connector); - } - } - - for (i = 0; i < res->count_encoders; i++) { - encoder = drmModeGetEncoder(fd, res->encoders[i]); - - if (!encoder) - printf("Could not get encoder %i\n", i); - else { - printEncoder(fd, res, encoder, res->encoders[i]); - drmModeFreeEncoder(encoder); - } - } - - - for (i = 0; i < res->count_crtcs; i++) { - crtc = drmModeGetCrtc(fd, res->crtcs[i]); - - if (!crtc) - printf("Could not get crtc %i\n", i); - else { - printCrtc(fd, res, crtc, res->crtcs[i]); - drmModeFreeCrtc(crtc); - } - } - - for (i = 0; i < res->count_fbs; i++) { - fb = drmModeGetFB(fd, res->fbs[i]); - - if (!fb) - printf("Could not get fb %i\n", res->fbs[i]); - else { - printFrameBuffer(fd, res, fb); - drmModeFreeFB(fb); - } - } - - return 0; -} - -static struct drm_mode_modeinfo mode = { - .name = "Test mode", - .clock = 25200, - .hdisplay = 640, - .hsync_start = 656, - .hsync_end = 752, - .htotal = 800, - .hskew = 0, - .vdisplay = 480, - .vsync_start = 490, - .vsync_end = 492, - .vtotal = 525, - .vscan = 0, - .vrefresh = 60000, /* vertical refresh * 1000 */ - .flags = 10, -}; - -int testMode(int fd, drmModeResPtr res) -{ - uint32_t connector = res->connectors[0]; - uint32_t newMode = 0; - int ret = 0; - int error = 0; - - printf("Test: adding mode to connector %i\n", connector); - - /* printMode(&mode); */ - - printf("\tAttaching mode %i to connector %i\n", newMode, connector); - - ret = drmModeAttachMode(fd, connector, &mode); - - if (ret) - goto err_mode; - - printf("\tDetaching mode %i from connector %i\n", newMode, connector); - ret = drmModeDetachMode(fd, connector, &mode); - - if (ret) - goto err_mode; - return 0; - -err_mode: - - printf("\tFailed\n"); - - if (error) - printf("\tFailed to delete mode %i\n", newMode); - return 1; -} - -/* -int testFrameBufferGet(int fd, uint32_t fb) -{ - drmModeFBPtr frame; - - printf("Test: get framebuffer %i\n", fb); - - frame = drmModeGetFB(fd, fb); - - if (!frame) { - printf("\tFailed\n"); - } else { - printFrameBuffer(fd, frame); - drmModeFreeFB(frame); - } - - return 0; -} -*/ - -int testFrameBufferAdd(int fd, drmModeResPtr res) -{ - uint32_t fb = 0; - int ret = 0; - drmModeFBPtr frame = 0; - drmBO bo; - - printf("Test: adding framebuffer\n"); - - printf("\tCreating BO\n"); - - /* TODO */ - ret = drmBOCreate(fd, 800 * 600 * 4, 0, 0, - DRM_BO_FLAG_READ | - DRM_BO_FLAG_WRITE | - DRM_BO_FLAG_MEM_TT | - DRM_BO_FLAG_MEM_VRAM | - DRM_BO_FLAG_NO_EVICT, - DRM_BO_HINT_DONT_FENCE, &bo); - - printf("\tgot %i\n", ret); - if (ret) - goto err; - - printf("\tAdding FB\n"); - ret = drmModeAddFB(fd, 800, 600, 32, 8, 0, bo.handle, &fb); - if (ret) - goto err_bo; - - frame = drmModeGetFB(fd, fb); - - if (!frame) { - printf("Couldn't retrive created framebuffer\n"); - } else { - printFrameBuffer(fd, res, frame); - drmModeFreeFB(frame); - } - - printf("\tRemoveing FB\n"); - - ret = drmModeRmFB(fd, fb); - - if (ret) { - printf("\tFailed this shouldn't happen!\n"); - goto err_bo; - } - - printf("\tRemoveing BO\n"); - - ret = drmBOUnreference(fb, &bo); - - return 0; - -err_bo: - drmBOUnreference(fd, &bo); - -err: - printf("\tFailed\n"); - - return 1; -} - -int testDPMS(int fd, drmModeResPtr res) -{ - int connector_id; - int i; - - for (i = 0; i < res->count_connectors; i++) { - connector_id = res->connectors[i]; - /* turn connector off */ - drmModeConnectorSetProperty(fd, connector_id, dpms_prop_id, 3); - sleep(2); - drmModeConnectorSetProperty(fd, connector_id, dpms_prop_id, 0); - } - return 1; - -} - -int main(int argc, char **argv) -{ - int fd; - drmModeResPtr res; - - printf("Starting test\n"); - - fd = drmOpen("i915", NULL); - - if (fd < 0) { - printf("Failed to open the card fb (%d)\n",fd); - return 1; - } - - res = drmModeGetResources(fd); - if (res == 0) { - printf("Failed to get resources from card\n"); - drmClose(fd); - return 1; - } - - printRes(fd, res); - - testMode(fd, res); - - testFrameBufferAdd(fd, res); - - /* try dpms test */ - testDPMS(fd, res); - drmModeFreeResources(res); - printf("Ok\n"); - - return 0; -} diff --git a/tests/mode/test b/tests/mode/test deleted file mode 100755 index f98e3708..00000000 --- a/tests/mode/test +++ /dev/null @@ -1 +0,0 @@ -LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app diff --git a/tests/modeprint/Makefile b/tests/modeprint/Makefile new file mode 100644 index 00000000..7a9c3c24 --- /dev/null +++ b/tests/modeprint/Makefile @@ -0,0 +1,14 @@ + +all: app + +#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ +# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ + +app: modetest.c + @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c + +clean: + @rm -f app + +run: app + @sudo ./test diff --git a/tests/modeprint/modetest.c b/tests/modeprint/modetest.c new file mode 100644 index 00000000..36925a0b --- /dev/null +++ b/tests/modeprint/modetest.c @@ -0,0 +1,352 @@ + +#include +#include +#include +#include +#include +#include + +#include "xf86drm.h" +#include "xf86drmMode.h" + +int connectors; +int full_props; +int edid; +int modes; +int full_modes; +int encoders; +int crtcs; +int fbs; + +const char* getConnectionText(drmModeConnection conn) +{ + switch (conn) { + case DRM_MODE_CONNECTED: + return "connected"; + case DRM_MODE_DISCONNECTED: + return "disconnected"; + default: + return "unknown"; + } + +} + +int printMode(struct drm_mode_modeinfo *mode) +{ + if (full_modes) { + printf("Mode: %s\n", mode->name); + printf("\tclock : %i\n", mode->clock); + printf("\thdisplay : %i\n", mode->hdisplay); + printf("\thsync_start : %i\n", mode->hsync_start); + printf("\thsync_end : %i\n", mode->hsync_end); + printf("\thtotal : %i\n", mode->htotal); + printf("\thskew : %i\n", mode->hskew); + printf("\tvdisplay : %i\n", mode->vdisplay); + printf("\tvsync_start : %i\n", mode->vsync_start); + printf("\tvsync_end : %i\n", mode->vsync_end); + printf("\tvtotal : %i\n", mode->vtotal); + printf("\tvscan : %i\n", mode->vscan); + printf("\tvrefresh : %i\n", mode->vrefresh); + printf("\tflags : %i\n", mode->flags); + } else { + printf("Mode: \"%s\" %ix%i %.0f\n", mode->name, + mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0); + } + return 0; +} + +int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id) +{ + int i = 0, j; + struct drm_mode_modeinfo *mode = NULL; + drmModePropertyPtr props; + unsigned char *name = NULL; + + printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id); + printf("\tid : %i\n", id); + printf("\tencoder id : %i\n", connector->encoder); + printf("\tconn : %s\n", getConnectionText(connector->connection)); + printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight); + printf("\tcount_modes : %i\n", connector->count_modes); + printf("\tcount_props : %i\n", connector->count_props); + printf("\tcount_encoders : %i\n", connector->count_encoders); + + if (connector->count_encoders) { + printf("\t\tencoders"); + for (i = 0; i < connector->count_encoders; i++) + printf(" %i", connector->encoders[i]); + printf("\n"); + } + + if (full_props) { + for (i = 0; i < connector->count_props; i++) { + props = drmModeGetProperty(fd, connector->props[i]); + name = NULL; + if (props) { + printf("Property: %s\n", props->name); + printf("\tid: %i\n", props->prop_id); + printf("\tflags: %i\n", props->flags); + printf("\tvalues %d: ", props->count_values); + for (j = 0; j < props->count_values; j++) + printf("%lld ", props->values[j]); + + printf("\n\tenums %d: \n", props->count_enums); + + if (props->flags & DRM_MODE_PROP_BLOB) { + drmModePropertyBlobPtr blob; + + blob = drmModeGetPropertyBlob(fd, connector->prop_values[i]); + if (blob) { + printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); + drmModeFreePropertyBlob(blob); + } + + } else { + if (!strncmp(props->name, "DPMS", 4)) + ; + + for (j = 0; j < props->count_enums; j++) { + printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name); + if (connector->prop_values[i] == props->enums[j].value) + name = props->enums[j].name; + + } + + if (props->count_enums && name) { + printf("\tconnector property name %s %s\n", props->name, name); + } else { + printf("\tconnector property id %s %lli\n", props->name, connector->prop_values[i]); + } + } + + drmModeFreeProperty(props); + } + } + } else { + if (connector->count_props) { + printf("\t\tprops"); + for (i = 0; i < connector->count_props; i++) + printf(" %i", connector->props[i]); + printf("\n"); + } + } + + if (modes) { + for (i = 0; i < connector->count_modes; i++) { + mode = &connector->modes[i]; + printMode(mode); + } + } + + return 0; +} + +int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id) +{ + printf("Encoder\n"); + printf("\tid :%i\n", id); + printf("\tcrtc :%d\n", encoder->crtc); + printf("\ttype :%d\n", encoder->encoder_type); + printf("\tcrtcs :%d\n", encoder->crtcs); + printf("\tclones :%d\n", encoder->clones); + return 0; +} + +int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) +{ + printf("Crtc\n"); + printf("\tid : %i\n", id); + printf("\tx : %i\n", crtc->x); + printf("\ty : %i\n", crtc->y); + printf("\twidth : %i\n", crtc->width); + printf("\theight : %i\n", crtc->height); + printf("\tmode : %p\n", &crtc->mode); + printf("\tgamma size : %d\n", crtc->gamma_size); + printf("\tnum connectors : %i\n", crtc->count_connectors); + printf("\tconnectors : %i\n", crtc->connectors); + printf("\tnum possible : %i\n", crtc->count_possibles); + printf("\tpossibles : %i\n", crtc->possibles); + + return 0; +} + +int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb) +{ + printf("Framebuffer\n"); + printf("\thandle : %i\n", fb->handle); + printf("\twidth : %i\n", fb->width); + printf("\theight : %i\n", fb->height); + printf("\tpitch : %i\n", fb->pitch);; + printf("\tbpp : %i\n", fb->bpp); + printf("\tdepth : %i\n", fb->depth); + printf("\tbuffer_id : %i\n", fb->buffer_id); + + return 0; +} + +int printRes(int fd, drmModeResPtr res) +{ + int i; + drmModeFBPtr fb; + drmModeCrtcPtr crtc; + drmModeEncoderPtr encoder; + drmModeConnectorPtr connector; + + printf("Resources\n\n"); + + printf("count_connectors : %i\n", res->count_connectors); + printf("count_encoders : %i\n", res->count_encoders); + printf("count_crtcs : %i\n", res->count_crtcs); + printf("count_fbs : %i\n", res->count_fbs); + + printf("\n"); + + if (connectors) { + for (i = 0; i < res->count_connectors; i++) { + connector = drmModeGetConnector(fd, res->connectors[i]); + + if (!connector) + printf("Could not get connector %i\n", i); + else { + printConnector(fd, res, connector, res->connectors[i]); + drmModeFreeConnector(connector); + } + } + printf("\n"); + } + + + if (encoders) { + for (i = 0; i < res->count_encoders; i++) { + encoder = drmModeGetEncoder(fd, res->encoders[i]); + + if (!encoder) + printf("Could not get encoder %i\n", i); + else { + printEncoder(fd, res, encoder, res->encoders[i]); + drmModeFreeEncoder(encoder); + } + } + printf("\n"); + } + + if (crtcs) { + for (i = 0; i < res->count_crtcs; i++) { + crtc = drmModeGetCrtc(fd, res->crtcs[i]); + + if (!crtc) + printf("Could not get crtc %i\n", i); + else { + printCrtc(fd, res, crtc, res->crtcs[i]); + drmModeFreeCrtc(crtc); + } + } + printf("\n"); + } + + if (fbs) { + for (i = 0; i < res->count_fbs; i++) { + fb = drmModeGetFB(fd, res->fbs[i]); + + if (!fb) + printf("Could not get fb %i\n", res->fbs[i]); + else { + printFrameBuffer(fd, res, fb); + drmModeFreeFB(fb); + } + } + } + + return 0; +} + +void args(int argc, char **argv) +{ + int i; + + fbs = 0; + edid = 0; + crtcs = 0; + modes = 0; + encoders = 0; + full_modes = 0; + full_props = 0; + connectors = 0; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-fb") == 0) { + fbs = 1; + } else if (strcmp(argv[i], "-crtcs") == 0) { + crtcs = 1; + } else if (strcmp(argv[i], "-cons") == 0) { + connectors = 1; + modes = 1; + } else if (strcmp(argv[i], "-modes") == 0) { + connectors = 1; + modes = 1; + } else if (strcmp(argv[i], "-full") == 0) { + connectors = 1; + modes = 1; + full_modes = 1; + } else if (strcmp(argv[i], "-props") == 0) { + connectors = 1; + full_props = 1; + } else if (strcmp(argv[i], "-edids") == 0) { + connectors = 1; + edid = 1; + } else if (strcmp(argv[i], "-encoders") == 0) { + encoders = 1; + } else if (strcmp(argv[i], "-v") == 0) { + fbs = 1; + edid = 1; + crtcs = 1; + modes = 1; + encoders = 1; + full_modes = 1; + full_props = 1; + connectors = 1; + } + } + + if (argc == 1) { + fbs = 1; + modes = 1; + full_modes = 0; + encoders = 1; + connectors = 1; + crtcs = 1; + full_props = 0; + edid = 1; + } +} +int main(int argc, char **argv) +{ + int fd; + drmModeResPtr res; + + args(argc, argv); + + printf("Starting test\n"); + + fd = drmOpen("i915", NULL); + + if (fd < 0) { + printf("Failed to open the card fb (%d)\n",fd); + return 1; + } + + res = drmModeGetResources(fd); + if (res == 0) { + printf("Failed to get resources from card\n"); + drmClose(fd); + return 1; + } + + printRes(fd, res); + + drmModeFreeResources(res); + + printf("Ok\n"); + + return 0; +} diff --git a/tests/modeprint/test b/tests/modeprint/test new file mode 100755 index 00000000..bd1952cc --- /dev/null +++ b/tests/modeprint/test @@ -0,0 +1 @@ +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app $@ -- cgit v1.2.3 From 4f233ce61858b94e0c1bd36e331b36d1b59512e5 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 2 Jul 2008 22:46:44 +0200 Subject: tests: Updated modeprint --- tests/modeprint/modetest.c | 132 +++++++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 59 deletions(-) (limited to 'tests') diff --git a/tests/modeprint/modetest.c b/tests/modeprint/modetest.c index 36925a0b..3f00922f 100644 --- a/tests/modeprint/modetest.c +++ b/tests/modeprint/modetest.c @@ -55,12 +55,63 @@ int printMode(struct drm_mode_modeinfo *mode) return 0; } +int printProperty(int fd, drmModeResPtr res, drmModePropertyPtr props, uint64_t value) +{ + const unsigned char *name = NULL; + int j; + + printf("Property: %s\n", props->name); + printf("\tid : %i\n", props->prop_id); + printf("\tflags : %i\n", props->flags); + printf("\tcount_values : %d\n", props->count_values); + + + if (props->count_values) { + printf("\tvalues :"); + for (j = 0; j < props->count_values; j++) + printf(" %lld", props->values[j]); + printf("\n"); + } + + + printf("\tcount_enums : %d\n", props->count_enums); + + if (props->flags & DRM_MODE_PROP_BLOB) { + drmModePropertyBlobPtr blob; + + blob = drmModeGetPropertyBlob(fd, value); + if (blob) { + printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); + drmModeFreePropertyBlob(blob); + } else { + printf("error getting blob %lld\n", value); + } + + } else { + if (!strncmp(props->name, "DPMS", 4)) + ; + + for (j = 0; j < props->count_enums; j++) { + printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name); + if (props->enums[j].value == value) + name = props->enums[j].name; + } + + if (props->count_enums && name) { + printf("\tcon_value : %s\n", name); + } else { + printf("\tcon_value : %lld\n", value); + } + } + + return 0; +} + int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id) { - int i = 0, j; + int i = 0; struct drm_mode_modeinfo *mode = NULL; drmModePropertyPtr props; - unsigned char *name = NULL; printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id); printf("\tid : %i\n", id); @@ -69,73 +120,36 @@ int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uin printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight); printf("\tcount_modes : %i\n", connector->count_modes); printf("\tcount_props : %i\n", connector->count_props); - printf("\tcount_encoders : %i\n", connector->count_encoders); + if (connector->count_props) { + printf("\tprops :"); + for (i = 0; i < connector->count_props; i++) + printf(" %i", connector->props[i]); + printf("\n"); + } + printf("\tcount_encoders : %i\n", connector->count_encoders); if (connector->count_encoders) { - printf("\t\tencoders"); + printf("\tencoders :"); for (i = 0; i < connector->count_encoders; i++) printf(" %i", connector->encoders[i]); printf("\n"); } + if (modes) { + for (i = 0; i < connector->count_modes; i++) { + mode = &connector->modes[i]; + printMode(mode); + } + } + if (full_props) { for (i = 0; i < connector->count_props; i++) { props = drmModeGetProperty(fd, connector->props[i]); - name = NULL; if (props) { - printf("Property: %s\n", props->name); - printf("\tid: %i\n", props->prop_id); - printf("\tflags: %i\n", props->flags); - printf("\tvalues %d: ", props->count_values); - for (j = 0; j < props->count_values; j++) - printf("%lld ", props->values[j]); - - printf("\n\tenums %d: \n", props->count_enums); - - if (props->flags & DRM_MODE_PROP_BLOB) { - drmModePropertyBlobPtr blob; - - blob = drmModeGetPropertyBlob(fd, connector->prop_values[i]); - if (blob) { - printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data); - drmModeFreePropertyBlob(blob); - } - - } else { - if (!strncmp(props->name, "DPMS", 4)) - ; - - for (j = 0; j < props->count_enums; j++) { - printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name); - if (connector->prop_values[i] == props->enums[j].value) - name = props->enums[j].name; - - } - - if (props->count_enums && name) { - printf("\tconnector property name %s %s\n", props->name, name); - } else { - printf("\tconnector property id %s %lli\n", props->name, connector->prop_values[i]); - } - } - + printProperty(fd, res, props, connector->prop_values[i]); drmModeFreeProperty(props); } } - } else { - if (connector->count_props) { - printf("\t\tprops"); - for (i = 0; i < connector->count_props; i++) - printf(" %i", connector->props[i]); - printf("\n"); - } - } - - if (modes) { - for (i = 0; i < connector->count_modes; i++) { - mode = &connector->modes[i]; - printMode(mode); - } } return 0; @@ -310,13 +324,13 @@ void args(int argc, char **argv) if (argc == 1) { fbs = 1; + edid = 1; + crtcs = 1; modes = 1; - full_modes = 0; encoders = 1; - connectors = 1; - crtcs = 1; + full_modes = 0; full_props = 0; - edid = 1; + connectors = 1; } } int main(int argc, char **argv) -- cgit v1.2.3 From 49e1fa1d503bb66949d825c41c1d97c83cf86361 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 2 Jul 2008 23:12:33 +0200 Subject: tests: modeprint s/fb/fd/ --- tests/modeprint/modetest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/modeprint/modetest.c b/tests/modeprint/modetest.c index 3f00922f..d8a94709 100644 --- a/tests/modeprint/modetest.c +++ b/tests/modeprint/modetest.c @@ -345,7 +345,7 @@ int main(int argc, char **argv) fd = drmOpen("i915", NULL); if (fd < 0) { - printf("Failed to open the card fb (%d)\n",fd); + printf("Failed to open the card fd (%d)\n",fd); return 1; } -- cgit v1.2.3 From aa2d3cfc168481b7637d935af990ce447012ebfe Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 3 Jul 2008 00:03:48 +0200 Subject: tests: Fix faulty error messages in modeprint --- tests/modeprint/modetest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/modeprint/modetest.c b/tests/modeprint/modetest.c index d8a94709..f0f8abd4 100644 --- a/tests/modeprint/modetest.c +++ b/tests/modeprint/modetest.c @@ -220,7 +220,7 @@ int printRes(int fd, drmModeResPtr res) connector = drmModeGetConnector(fd, res->connectors[i]); if (!connector) - printf("Could not get connector %i\n", i); + printf("Could not get connector %i\n", res->connectors[i]); else { printConnector(fd, res, connector, res->connectors[i]); drmModeFreeConnector(connector); @@ -235,7 +235,7 @@ int printRes(int fd, drmModeResPtr res) encoder = drmModeGetEncoder(fd, res->encoders[i]); if (!encoder) - printf("Could not get encoder %i\n", i); + printf("Could not get encoder %i\n", res->encoders[i]); else { printEncoder(fd, res, encoder, res->encoders[i]); drmModeFreeEncoder(encoder); @@ -249,7 +249,7 @@ int printRes(int fd, drmModeResPtr res) crtc = drmModeGetCrtc(fd, res->crtcs[i]); if (!crtc) - printf("Could not get crtc %i\n", i); + printf("Could not get crtc %i\n", res->crtcs[i]); else { printCrtc(fd, res, crtc, res->crtcs[i]); drmModeFreeCrtc(crtc); -- cgit v1.2.3 From 94cf07bff1bf9a42ba6360f8feaa441b763b337f Mon Sep 17 00:00:00 2001 From: Maarten Maathuis Date: Thu, 3 Jul 2008 00:30:00 +0200 Subject: Forgot to fix the modeprint test. --- tests/modeprint/modetest.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/modeprint/modetest.c b/tests/modeprint/modetest.c index f0f8abd4..d5cbbc56 100644 --- a/tests/modeprint/modetest.c +++ b/tests/modeprint/modetest.c @@ -176,10 +176,6 @@ int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id) printf("\theight : %i\n", crtc->height); printf("\tmode : %p\n", &crtc->mode); printf("\tgamma size : %d\n", crtc->gamma_size); - printf("\tnum connectors : %i\n", crtc->count_connectors); - printf("\tconnectors : %i\n", crtc->connectors); - printf("\tnum possible : %i\n", crtc->count_possibles); - printf("\tpossibles : %i\n", crtc->possibles); return 0; } -- cgit v1.2.3 From 7cbc5f6145046f3775e3b3ca2862bfb71831ec44 Mon Sep 17 00:00:00 2001 From: Maarten Maathuis Date: Sat, 5 Jul 2008 12:04:07 +0200 Subject: modesetting-101: Make the interface variable names a little more consistent + modeprint changes. - All things are now called _id when they are id's. - modeprint now accepts driver name as first argument. --- tests/modeprint/modetest.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/modeprint/modetest.c b/tests/modeprint/modetest.c index d5cbbc56..cefa5262 100644 --- a/tests/modeprint/modetest.c +++ b/tests/modeprint/modetest.c @@ -17,6 +17,7 @@ int full_modes; int encoders; int crtcs; int fbs; +char *module_name; const char* getConnectionText(drmModeConnection conn) { @@ -115,7 +116,7 @@ int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uin printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id); printf("\tid : %i\n", id); - printf("\tencoder id : %i\n", connector->encoder); + printf("\tencoder id : %i\n", connector->encoder_id); printf("\tconn : %s\n", getConnectionText(connector->connection)); printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight); printf("\tcount_modes : %i\n", connector->count_modes); @@ -159,10 +160,10 @@ int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t { printf("Encoder\n"); printf("\tid :%i\n", id); - printf("\tcrtc :%d\n", encoder->crtc); + printf("\tcrtc_id :%d\n", encoder->crtc_id); printf("\ttype :%d\n", encoder->encoder_type); - printf("\tcrtcs :%d\n", encoder->crtcs); - printf("\tclones :%d\n", encoder->clones); + printf("\tpossible_crtcs :%d\n", encoder->possible_crtcs); + printf("\tpossible_clones :%d\n", encoder->possible_clones); return 0; } @@ -283,7 +284,9 @@ void args(int argc, char **argv) full_props = 0; connectors = 0; - for (i = 1; i < argc; i++) { + module_name = argv[1]; + + for (i = 2; i < argc; i++) { if (strcmp(argv[i], "-fb") == 0) { fbs = 1; } else if (strcmp(argv[i], "-crtcs") == 0) { @@ -316,9 +319,9 @@ void args(int argc, char **argv) full_props = 1; connectors = 1; } - } + } - if (argc == 1) { + if (argc == 2) { fbs = 1; edid = 1; crtcs = 1; @@ -329,16 +332,22 @@ void args(int argc, char **argv) connectors = 1; } } + int main(int argc, char **argv) { int fd; drmModeResPtr res; + if (argc == 1) { + printf("Please add modulename as first argument\n"); + return 1; + } + args(argc, argv); printf("Starting test\n"); - fd = drmOpen("i915", NULL); + fd = drmOpen(module_name, NULL); if (fd < 0) { printf("Failed to open the card fd (%d)\n",fd); -- cgit v1.2.3 From 0443d2a32ab791867cb0ce361a3905357d6a87d9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 26 Jul 2008 08:56:43 +1000 Subject: tests: add some basic radeon gem tests --- tests/Makefile.am | 4 +- tests/radeon_gem_basic.c | 114 ++++++++++++++++++++++++++++++++++++++++ tests/radeon_gem_mmap.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 tests/radeon_gem_basic.c create mode 100644 tests/radeon_gem_mmap.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 718cc436..a5f9967b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,7 +25,9 @@ TESTS = auth \ updatedraw \ gem_basic \ gem_readwrite \ - gem_mmap + gem_mmap \ + radeon_gem_mmap \ + radeon_gem_basic EXTRA_PROGRAMS = $(TESTS) CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) diff --git a/tests/radeon_gem_basic.c b/tests/radeon_gem_basic.c new file mode 100644 index 00000000..d8231879 --- /dev/null +++ b/tests/radeon_gem_basic.c @@ -0,0 +1,114 @@ +/* + * Copyright © 2008 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: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" +#include "radeon_drm.h" + +static void +test_bad_close(int fd) +{ + struct drm_gem_close close; + int ret; + + printf("Testing error return on bad close ioctl.\n"); + + close.handle = 0x10101010; + ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close); + + assert(ret == -1 && errno == EINVAL); +} + +static void +test_create_close(int fd) +{ + struct drm_radeon_gem_create create; + struct drm_gem_close close; + int ret; + + printf("Testing creating and closing an object.\n"); + + memset(&create, 0, sizeof(create)); + create.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create); + assert(ret == 0); + + close.handle = create.handle; + ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close); +} + +static void +test_create_fd_close(int fd) +{ + struct drm_radeon_gem_create create; + int ret; + + printf("Testing closing with an object allocated.\n"); + + memset(&create, 0, sizeof(create)); + create.size = 16 * 1024; + ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create); + assert(ret == 0); + + close(fd); +} + +int test_gem_info(int fd) +{ + struct drm_radeon_gem_info info; + int ret; + + ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_INFO, &info); + assert(ret == 0); + + fprintf(stderr,"%lld %lld %lld %lld %lld\n", + info.gtt_start, info.gtt_size, + info.vram_start, info.vram_size, + info.vram_visible); + +} + +int main(int argc, char **argv) +{ + int fd; + + fd = drm_open_any(); + + test_gem_info(fd); + test_bad_close(fd); + test_create_close(fd); + test_create_fd_close(fd); + + return 0; +} diff --git a/tests/radeon_gem_mmap.c b/tests/radeon_gem_mmap.c new file mode 100644 index 00000000..aa7b0196 --- /dev/null +++ b/tests/radeon_gem_mmap.c @@ -0,0 +1,132 @@ +/* + * Copyright © 2008 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: + * Eric Anholt + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "drm.h" +#include "radeon_drm.h" + +#define OBJECT_SIZE 16384 + +int do_read(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_radeon_gem_pread read; + + /* Ensure that we don't have any convenient data in buf in case + * we fail. + */ + memset(buf, 0xd0, size); + + memset(&read, 0, sizeof(read)); + read.handle = handle; + read.data_ptr = (uintptr_t)buf; + read.size = size; + read.offset = offset; + + return ioctl(fd, DRM_IOCTL_RADEON_GEM_PREAD, &read); +} + +int do_write(int fd, int handle, void *buf, int offset, int size) +{ + struct drm_radeon_gem_pwrite write; + + memset(&write, 0, sizeof(write)); + write.handle = handle; + write.data_ptr = (uintptr_t)buf; + write.size = size; + write.offset = offset; + + return ioctl(fd, DRM_IOCTL_RADEON_GEM_PWRITE, &write); +} + +int main(int argc, char **argv) +{ + int fd; + struct drm_radeon_gem_create create; + struct drm_radeon_gem_mmap mmap; + struct drm_gem_close unref; + uint8_t expected[OBJECT_SIZE]; + uint8_t buf[OBJECT_SIZE]; + uint8_t *addr; + int ret; + int handle; + + fd = drm_open_any(); + + memset(&mmap, 0, sizeof(mmap)); + mmap.handle = 0x10101010; + mmap.offset = 0; + mmap.size = 4096; + printf("Testing mmaping of bad object.\n"); + ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_MMAP, &mmap); + assert(ret == -1 && errno == EINVAL); + + memset(&create, 0, sizeof(create)); + create.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create); + assert(ret == 0); + handle = create.handle; + + printf("Testing mmaping of newly created object.\n"); + mmap.handle = handle; + mmap.offset = 0; + mmap.size = OBJECT_SIZE; + ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_MMAP, &mmap); + assert(ret == 0); + addr = (uint8_t *)(uintptr_t)mmap.addr_ptr; + + printf("Testing contents of newly created object.\n"); + memset(expected, 0, sizeof(expected)); + assert(memcmp(addr, expected, sizeof(expected)) == 0); + + printf("Testing coherency of writes and mmap reads.\n"); + memset(buf, 0, sizeof(buf)); + memset(buf + 1024, 0x01, 1024); + memset(expected + 1024, 0x01, 1024); + ret = do_write(fd, handle, buf, 0, OBJECT_SIZE); + assert(ret == 0); + assert(memcmp(buf, addr, sizeof(buf)) == 0); + + printf("Testing that mapping stays after close\n"); + unref.handle = handle; + ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &unref); + assert(ret == 0); + assert(memcmp(buf, addr, sizeof(buf)) == 0); + + printf("Testing unmapping\n"); + munmap(addr, OBJECT_SIZE); + + close(fd); + + return 0; +} -- cgit v1.2.3 From 8f5d8ba97e82072b2403bff0bf836a09640108a6 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Wed, 19 Nov 2008 10:54:11 -0800 Subject: Update modetest --- tests/modetest/Makefile | 14 ++ tests/modetest/modetest.c | 410 ++++++++++++++++++++++++++++++++++++++++++++++ tests/modetest/test | 2 + 3 files changed, 426 insertions(+) create mode 100644 tests/modetest/Makefile create mode 100644 tests/modetest/modetest.c create mode 100755 tests/modetest/test (limited to 'tests') diff --git a/tests/modetest/Makefile b/tests/modetest/Makefile new file mode 100644 index 00000000..8583ae82 --- /dev/null +++ b/tests/modetest/Makefile @@ -0,0 +1,14 @@ + +all: app + +#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ +# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ + +app: modetest.c + gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../libdrm/intel -I../../shared-core -L../../libdrm/.libs -L../../libdrm/intel/.libs -ldrm -ldrm_intel modetest.c + +clean: + @rm -f app + +run: app + sudo ./test diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c new file mode 100644 index 00000000..66c7f9cd --- /dev/null +++ b/tests/modetest/modetest.c @@ -0,0 +1,410 @@ +/* + * DRM based mode setting test program + * Copyright 2008 Tungsten Graphics + * Jakob Bornecrantz + * Copyright 2008 Intel Corporation + * Jesse Barnes + */ +#include +#include +#include +#include +#include +#include +#include + +#include "xf86drm.h" +#include "xf86drmMode.h" +#include "intel_bufmgr.h" + +drmModeRes *resources; +int fd, modes; + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +struct type_name { + int type; + char *name; +}; + +#define type_name_fn(res) \ +char * res##_str(int type) { \ + int i; \ + for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \ + if (res##_names[i].type == type) \ + return res##_names[i].name; \ + } \ + return "(invalid)"; \ +} + +struct type_name encoder_type_names[] = { + { DRM_MODE_ENCODER_NONE, "none" }, + { DRM_MODE_ENCODER_DAC, "DAC" }, + { DRM_MODE_ENCODER_TMDS, "TMDS" }, + { DRM_MODE_ENCODER_LVDS, "LVDS" }, + { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, +}; + +type_name_fn(encoder_type) + +struct type_name connector_status_names[] = { + { DRM_MODE_CONNECTED, "connected" }, + { DRM_MODE_DISCONNECTED, "disconnected" }, + { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, +}; + +type_name_fn(connector_status) + +struct type_name connector_type_names[] = { + { DRM_MODE_CONNECTOR_Unknown, "unknown" }, + { DRM_MODE_CONNECTOR_VGA, "VGA" }, + { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, + { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, + { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, + { DRM_MODE_CONNECTOR_Composite, "composite" }, + { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, + { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, + { DRM_MODE_CONNECTOR_Component, "component" }, + { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, + { DRM_MODE_CONNECTOR_DisplayPort, "displayport" }, + { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, + { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, +}; + +type_name_fn(connector_type) + +void dump_encoders(void) +{ + drmModeEncoder *encoder; + int i; + + printf("Encoders:\n"); + printf("id\tcrtc\ttype\tpossible crtcs\tpossible clones\t\n"); + for (i = 0; i < resources->count_encoders; i++) { + encoder = drmModeGetEncoder(fd, resources->encoders[i]); + + if (!encoder) { + fprintf(stderr, "could not get encoder %i: %s\n", + resources->encoders[i], strerror(errno)); + continue; + } + printf("%d\t%d\t%s\t0x%08x\t0x%08x\n", + encoder->encoder_id, + encoder->crtc_id, + encoder_type_str(encoder->encoder_type), + encoder->possible_crtcs, + encoder->possible_clones); + drmModeFreeEncoder(encoder); + } +} + +void dump_connectors(void) +{ + drmModeConnector *connector; + int i, j; + + printf("Connectors:\n"); + printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n"); + for (i = 0; i < resources->count_connectors; i++) { + connector = drmModeGetConnector(fd, resources->connectors[i]); + + if (!connector) { + fprintf(stderr, "could not get connector %i: %s\n", + resources->connectors[i], strerror(errno)); + continue; + } + + printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n", + connector->connector_id, + connector->encoder_id, + connector_status_str(connector->connection), + connector_type_str(connector->connector_type), + connector->mmWidth, connector->mmHeight, + connector->count_modes); + + 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++) { + struct drm_mode_modeinfo *mode; + + mode = &connector->modes[j]; + printf(" %s %.02f %d %d %d %d %d %d %d %d\n", + mode->name, + (float)mode->vrefresh / 1000, + mode->hdisplay, + mode->hsync_start, + mode->hsync_end, + mode->htotal, + mode->vdisplay, + mode->vsync_start, + mode->vsync_end, + mode->vtotal); + } + drmModeFreeConnector(connector); + } +} + +void dump_crtcs(void) +{ + drmModeCrtc *crtc; + int i; + + for (i = 0; i < resources->count_crtcs; i++) { + crtc = drmModeGetCrtc(fd, resources->crtcs[i]); + + if (!crtc) { + fprintf(stderr, "could not get crtc %i: %s\n", + resources->crtcs[i], strerror(errno)); + continue; + } + drmModeFreeCrtc(crtc); + } +} + +void dump_framebuffers(void) +{ + drmModeFB *fb; + int i; + + for (i = 0; i < resources->count_fbs; i++) { + fb = drmModeGetFB(fd, resources->fbs[i]); + + if (!fb) { + fprintf(stderr, "could not get fb %i: %s\n", + resources->fbs[i], strerror(errno)); + continue; + } + drmModeFreeFB(fb); + } +} + +void set_mode(int connector_id, char *mode_str) +{ + drmModeConnector *connector; + drmModeEncoder *encoder = NULL; + struct drm_mode_modeinfo *mode = NULL; + drm_intel_bufmgr *bufmgr; + drm_intel_bo *bo; + unsigned int fb_id, *fb_ptr; + int i, j, size, ret, width, height; + + /* First, find the connector & mode */ + for (i = 0; i < resources->count_connectors; i++) { + connector = drmModeGetConnector(fd, resources->connectors[i]); + + if (!connector) { + fprintf(stderr, "could not get connector %i: %s\n", + resources->connectors[i], strerror(errno)); + drmModeFreeConnector(connector); + continue; + } + + if (!connector->count_modes) { + drmModeFreeConnector(connector); + continue; + } + + if (connector->connector_id != connector_id) { + drmModeFreeConnector(connector); + continue; + } + + for (j = 0; j < connector->count_modes; j++) { + mode = &connector->modes[j]; + if (!strcmp(mode->name, mode_str)) + break; + } + + /* Found it, break out */ + if (mode) + break; + + drmModeFreeConnector(connector); + } + + if (!mode) { + fprintf(stderr, "failed to find mode \"%s\"\n", mode_str); + return; + } + + width = mode->hdisplay; + height = mode->vdisplay; + + /* Now get the encoder */ + for (i = 0; i < resources->count_encoders; i++) { + encoder = drmModeGetEncoder(fd, resources->encoders[i]); + + if (!encoder) { + fprintf(stderr, "could not get encoder %i: %s\n", + resources->encoders[i], strerror(errno)); + drmModeFreeEncoder(encoder); + continue; + } + + if (encoder->encoder_id == connector->encoder_id) + break; + + drmModeFreeEncoder(encoder); + } + + bufmgr = drm_intel_bufmgr_gem_init(fd, 2<<20); + if (!bufmgr) { + fprintf(stderr, "failed to init bufmgr: %s\n", strerror(errno)); + return; + } + + /* Mode size at 32 bpp */ + size = width * height * 4; + + bo = drm_intel_bo_alloc(bufmgr, "frontbuffer", size, 4096); + if (!bo) { + fprintf(stderr, "failed to alloc buffer: %s\n", + strerror(errno)); + return; + } + + ret = drm_intel_bo_pin(bo, 4096); + if (ret) { + fprintf(stderr, "failed to pin buffer: %s\n", strerror(errno)); + return; + } + + ret = drm_intel_gem_bo_map_gtt(bo); + if (ret) { + fprintf(stderr, "failed to GTT map buffer: %s\n", + strerror(errno)); + return; + } + + fb_ptr = bo->virtual; + + /* paint the buffer blue */ + for (i = 0; i < width * height; i++) + fb_ptr[i] = 0xff; + + ret = drmModeAddFB(fd, width, height, 32, 32, width * 4, bo->handle, + &fb_id); + if (ret) { + fprintf(stderr, "failed to add fb: %s\n", strerror(errno)); + return; + } + + ret = drmModeSetCrtc(fd, encoder->crtc_id, fb_id, 0, 0, + &connector->connector_id, 1, mode); + if (ret) { + fprintf(stderr, "failed to set mode: %s\n", strerror(errno)); + return; + } +} + +extern char *optarg; +extern int optind, opterr, optopt; +static char optstr[] = "ecpmfs:"; + +void usage(char *name) +{ + fprintf(stderr, "usage: %s [-ecpmf]\n", name); + fprintf(stderr, "\t-e\tlist encoders\n"); + fprintf(stderr, "\t-c\tlist connectors\n"); + fprintf(stderr, "\t-p\tlist CRTCs (pipes)\n"); + fprintf(stderr, "\t-m\tlist modes\n"); + fprintf(stderr, "\t-f\tlist framebuffers\n"); + fprintf(stderr, "\t-s :\tset a mode\n"); + fprintf(stderr, "\n\tDefault is to dump all info.\n"); + exit(0); +} + +#define dump_resource(res) if (res) dump_##res() + +int main(int argc, char **argv) +{ + int c; + int encoders = 0, connectors = 0, crtcs = 0, framebuffers = 0; + char *modules[] = { "i915", "radeon" }; + char *modeset = NULL, *mode, *connector; + int i, connector_id; + + opterr = 0; + while ((c = getopt(argc, argv, optstr)) != -1) { + switch (c) { + case 'e': + encoders = 1; + break; + case 'c': + connectors = 1; + break; + case 'p': + crtcs = 1; + break; + case 'm': + modes = 1; + break; + case 'f': + framebuffers = 1; + break; + case 's': + modeset = strdup(optarg); + break; + default: + usage(argv[0]); + break; + } + } + + if (argc == 1) + encoders = connectors = crtcs = modes = framebuffers = 1; + + for (i = 0; i < ARRAY_SIZE(modules); i++) { + printf("trying to load module %s...", modules[i]); + fd = drmOpen(modules[i], NULL); + if (fd < 0) { + printf("failed.\n"); + } else { + printf("success.\n"); + break; + } + } + + if (i == ARRAY_SIZE(modules)) { + fprintf(stderr, "failed to load any modules, aborting.\n"); + return -1; + } + + resources = drmModeGetResources(fd); + if (!resources) { + fprintf(stderr, "drmModeGetResources failed: %s\n", + strerror(errno)); + drmClose(fd); + return 1; + } + + dump_resource(encoders); + dump_resource(connectors); + dump_resource(crtcs); + dump_resource(framebuffers); + + if (modeset) { + connector = strtok(modeset, ":"); + if (!connector) + usage(argv[0]); + connector_id = atoi(connector); + + mode = strtok(NULL, ":"); + if (!mode) + usage(argv[0]); + printf("setting connector %d to mode %s\n", connector_id, + mode); + set_mode(connector_id, mode); + sleep(3); + } + + sleep(3); + + drmModeFreeResources(resources); + + return 0; +} diff --git a/tests/modetest/test b/tests/modetest/test new file mode 100755 index 00000000..5bb552ef --- /dev/null +++ b/tests/modetest/test @@ -0,0 +1,2 @@ +export LD_LIBRARY_PATH=../../libdrm/.libs:../../libdrm/intel/.libs +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app $@ -- cgit v1.2.3