From: "Peter Hanzel" Subject: Re: vmwgfx + VMWare 7.0 -> libdrm modetest.c Date: Wed, 10 Feb 2010 11:39:42 +0100 Message-ID: <8C0E997DB5B44EA6905C512E490529D3@avitech.sk> References: <59ad55d31002090614j2e188666p9237ad3b5f1317ad@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0057_01CAAA45.BCC96120" Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.sourceforge.net To: =?utf-8?Q?Kristian_H=C3=B8gsberg?= Cc: dri-devel@lists.sourceforge.net List-Id: dri-devel@lists.freedesktop.org This is a multi-part message in MIME format. ------=_NextPart_000_0057_01CAAA45.BCC96120 Content-Type: text/plain; format=flowed; charset="utf-8"; reply-type=original Content-Transfer-Encoding: 8bit Hello. I don't have a patch, as I can't still make it run on VMWare. But tests on other graphic card can be good. I have attached the file. There is no Cairo code, no page_flip and I have also added drmModeDirtyFB, as Jakob from vmware suggested to make it work under vmwgfx. Regards. ----- Original Message ----- From: "Kristian Høgsberg" To: "Peter Hanzel" Cc: Sent: Tuesday, February 09, 2010 3:14 PM Subject: Re: vmwgfx + VMWare 7.0 -> libdrm modetest.c > On Tue, Feb 9, 2010 at 8:05 AM, Peter Hanzel > wrote: >> Hello. >> >> I have a question about libdrm/libkms and test/modetest/modetest.c. >> I am now working with vmwgfx + VMWare 7.0, where vmwgfx had correctly >> initialized framebuffer and also now using fbcon. >> Now I want to test it woth modetest.c >> This program is only for intel so i recoded it to use libkms functions. > > Could you send the changes to make modetest.c use libkms as a patch? > It's a good idea. > > cheers, > Kristian > ------=_NextPart_000_0057_01CAAA45.BCC96120 Content-Type: text/plain; format=flowed; name="modetest.c"; reply-type=original Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="modetest.c" /*=0A= * DRM based mode setting test program=0A= * Copyright 2008 Tungsten Graphics=0A= * Jakob Bornecrantz =0A= * Copyright 2008 Intel Corporation=0A= * Jesse Barnes =0A= *=0A= * Permission is hereby granted, free of charge, to any person obtaining = a=0A= * copy of this software and associated documentation files (the = "Software"),=0A= * to deal in the Software without restriction, including without = limitation=0A= * the rights to use, copy, modify, merge, publish, distribute, = sublicense,=0A= * and/or sell copies of the Software, and to permit persons to whom the=0A= * Software is furnished to do so, subject to the following conditions:=0A= *=0A= * The above copyright notice and this permission notice shall be = included in=0A= * all copies or substantial portions of the Software.=0A= *=0A= * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, = EXPRESS OR=0A= * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF = MERCHANTABILITY,=0A= * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT = SHALL THE=0A= * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER=0A= * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, = ARISING=0A= * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER = DEALINGS=0A= * IN THE SOFTWARE.=0A= */=0A= =0A= /*=0A= * This fairly simple test program dumps output in a similar format to = the=0A= * "xrandr" tool everyone knows & loves. It's necessarily slightly = different=0A= * since the kernel separates outputs into encoder and connector = structures,=0A= * each with their own unique ID. The program also allows test testing = of the=0A= * memory management and mode setting APIs by allowing the user to = specify a=0A= * connector and mode to use for mode setting. If all works as = expected, a=0A= * blue background should be painted on the monitor attached to the = specified=0A= * connector after the selected mode is set.=0A= *=0A= * TODO: use cairo to write the mode info on the selected output once=0A= * the mode has been programmed, along with possible test patterns.=0A= */=0A= #include "config.h"=0A= =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= =0A= #include "xf86drm.h"=0A= #include "xf86drmMode.h"=0A= #include "libkms/libkms.h"=0A= =0A= struct kms_bo=0A= {=0A= struct kms_driver *kms;=0A= void *ptr;=0A= size_t size;=0A= size_t offset;=0A= size_t pitch;=0A= unsigned handle;=0A= };=0A= =0A= =0A= drmModeRes *resources;=0A= int fd, modes;=0A= =0A= #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))=0A= =0A= struct type_name {=0A= int type;=0A= char *name;=0A= };=0A= =0A= #define type_name_fn(res) \=0A= char * res##_str(int type) { \=0A= int i; \=0A= for (i =3D 0; i < ARRAY_SIZE(res##_names); i++) { \=0A= if (res##_names[i].type =3D=3D type) \=0A= return res##_names[i].name; \=0A= } \=0A= return "(invalid)"; \=0A= }=0A= =0A= struct type_name encoder_type_names[] =3D {=0A= { DRM_MODE_ENCODER_NONE, "none" },=0A= { DRM_MODE_ENCODER_DAC, "DAC" },=0A= { DRM_MODE_ENCODER_TMDS, "TMDS" },=0A= { DRM_MODE_ENCODER_LVDS, "LVDS" },=0A= { DRM_MODE_ENCODER_TVDAC, "TVDAC" },=0A= };=0A= =0A= type_name_fn(encoder_type)=0A= =0A= struct type_name connector_status_names[] =3D {=0A= { DRM_MODE_CONNECTED, "connected" },=0A= { DRM_MODE_DISCONNECTED, "disconnected" },=0A= { DRM_MODE_UNKNOWNCONNECTION, "unknown" },=0A= };=0A= =0A= type_name_fn(connector_status)=0A= =0A= struct type_name connector_type_names[] =3D {=0A= { DRM_MODE_CONNECTOR_Unknown, "unknown" },=0A= { DRM_MODE_CONNECTOR_VGA, "VGA" },=0A= { DRM_MODE_CONNECTOR_DVII, "DVI-I" },=0A= { DRM_MODE_CONNECTOR_DVID, "DVI-D" },=0A= { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },=0A= { DRM_MODE_CONNECTOR_Composite, "composite" },=0A= { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },=0A= { DRM_MODE_CONNECTOR_LVDS, "LVDS" },=0A= { DRM_MODE_CONNECTOR_Component, "component" },=0A= { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },=0A= { DRM_MODE_CONNECTOR_DisplayPort, "displayport" },=0A= { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },=0A= { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },=0A= };=0A= =0A= type_name_fn(connector_type)=0A= =0A= void dump_encoders(void)=0A= {=0A= drmModeEncoder *encoder;=0A= int i;=0A= =0A= printf("Encoders:\n");=0A= printf("id\tcrtc\ttype\tpossible crtcs\tpossible clones\t\n");=0A= for (i =3D 0; i < resources->count_encoders; i++) {=0A= encoder =3D drmModeGetEncoder(fd, resources->encoders[i]);=0A= =0A= if (!encoder) {=0A= fprintf(stderr, "could not get encoder %i: %s\n",=0A= resources->encoders[i], strerror(errno));=0A= continue;=0A= }=0A= printf("%d\t%d\t%s\t0x%08x\t0x%08x\n",=0A= encoder->encoder_id,=0A= encoder->crtc_id,=0A= encoder_type_str(encoder->encoder_type),=0A= encoder->possible_crtcs,=0A= encoder->possible_clones);=0A= drmModeFreeEncoder(encoder);=0A= }=0A= printf("\n");=0A= }=0A= =0A= void dump_mode(drmModeModeInfo *mode)=0A= {=0A= printf(" %s %.02f %d %d %d %d %d %d %d %d\n",=0A= mode->name,=0A= (float)mode->vrefresh / 1000,=0A= mode->hdisplay,=0A= mode->hsync_start,=0A= mode->hsync_end,=0A= mode->htotal,=0A= mode->vdisplay,=0A= mode->vsync_start,=0A= mode->vsync_end,=0A= mode->vtotal);=0A= }=0A= =0A= static void=0A= dump_props(drmModeConnector *connector)=0A= {=0A= drmModePropertyPtr props;=0A= int i;=0A= =0A= for (i =3D 0; i < connector->count_props; i++) {=0A= props =3D drmModeGetProperty(fd, connector->props[i]);=0A= //printf("\t%s, flags %d\n", props->name, props->flags);=0A= drmModeFreeProperty(props);=0A= }=0A= }=0A= =0A= void dump_connectors(void)=0A= {=0A= drmModeConnector *connector;=0A= int i, j;=0A= =0A= printf("Connectors:\n");=0A= printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");=0A= for (i =3D 0; i < resources->count_connectors; i++) {=0A= connector =3D drmModeGetConnector(fd, resources->connectors[i]);=0A= =0A= if (!connector) {=0A= fprintf(stderr, "could not get connector %i: %s\n",=0A= resources->connectors[i], strerror(errno));=0A= continue;=0A= }=0A= =0A= printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t",=0A= connector->connector_id,=0A= connector->encoder_id,=0A= connector_status_str(connector->connection),=0A= connector_type_str(connector->connector_type),=0A= connector->mmWidth, connector->mmHeight,=0A= connector->count_modes);=0A= =0A= for (j =3D 0; j < connector->count_encoders; j++)=0A= printf("%s%d", j > 0 ? ", " : "", connector->encoders[j]);=0A= printf("\n");=0A= =0A= if (!connector->count_modes)=0A= continue;=0A= =0A= printf(" modes:\n");=0A= printf(" name refresh (Hz) hdisp hss hse htot vdisp "=0A= "vss vse vtot)\n");=0A= for (j =3D 0; j < connector->count_modes; j++)=0A= dump_mode(&connector->modes[j]);=0A= =0A= drmModeFreeConnector(connector);=0A= =0A= printf(" props:\n");=0A= dump_props(connector);=0A= }=0A= printf("\n");=0A= }=0A= =0A= void dump_crtcs(void)=0A= {=0A= drmModeCrtc *crtc;=0A= int i;=0A= =0A= printf("CRTCs:\n");=0A= printf("id\tfb\tpos\tsize\n");=0A= for (i =3D 0; i < resources->count_crtcs; i++) {=0A= crtc =3D drmModeGetCrtc(fd, resources->crtcs[i]);=0A= =0A= if (!crtc) {=0A= fprintf(stderr, "could not get crtc %i: %s\n",=0A= resources->crtcs[i], strerror(errno));=0A= continue;=0A= }=0A= printf("%d\t%d\t(%d,%d)\t(%dx%d)\n",=0A= crtc->crtc_id,=0A= crtc->buffer_id,=0A= crtc->x, crtc->y,=0A= crtc->width, crtc->height);=0A= dump_mode(&crtc->mode);=0A= =0A= drmModeFreeCrtc(crtc);=0A= }=0A= printf("\n");=0A= }=0A= =0A= void dump_framebuffers(void)=0A= {=0A= drmModeFB *fb;=0A= int i;=0A= =0A= printf("Frame buffers:\n");=0A= printf("id\tsize\tpitch\n");=0A= for (i =3D 0; i < resources->count_fbs; i++) {=0A= fb =3D drmModeGetFB(fd, resources->fbs[i]);=0A= =0A= if (!fb) {=0A= fprintf(stderr, "could not get fb %i: %s\n",=0A= resources->fbs[i], strerror(errno));=0A= continue;=0A= }=0A= printf("%d\t(%dx%d)\t%d\n",=0A= fb->fb_id,=0A= fb->width, fb->height);=0A= =0A= drmModeFreeFB(fb);=0A= }=0A= printf("\n");=0A= }=0A= =0A= /*=0A= * Mode setting with the kernel interfaces is a bit of a chore.=0A= * First you have to find the connector in question and make sure the=0A= * requested mode is available.=0A= * Then you need to find the encoder attached to that connector so you=0A= * can bind it with a free crtc.=0A= */=0A= struct connector {=0A= int id;=0A= char mode_str[64];=0A= drmModeModeInfo *mode;=0A= drmModeEncoder *encoder;=0A= int crtc;=0A= unsigned int fb_id[2], current_fb_id;=0A= struct timeval start;=0A= =0A= int swap_count;=0A= }; =0A= =0A= static void=0A= connector_find_mode(struct connector *c)=0A= {=0A= drmModeConnector *connector;=0A= int i, j, size, ret, width, height;=0A= =0A= /* First, find the connector & mode */=0A= c->mode =3D NULL;=0A= for (i =3D 0; i < resources->count_connectors; i++) {=0A= connector =3D drmModeGetConnector(fd, resources->connectors[i]);=0A= =0A= if (!connector) {=0A= fprintf(stderr, "could not get connector %i: %s\n",=0A= resources->connectors[i], strerror(errno));=0A= drmModeFreeConnector(connector);=0A= continue;=0A= }=0A= =0A= if (!connector->count_modes) {=0A= drmModeFreeConnector(connector);=0A= continue;=0A= }=0A= =0A= if (connector->connector_id !=3D c->id) {=0A= drmModeFreeConnector(connector);=0A= continue;=0A= }=0A= =0A= for (j =3D 0; j < connector->count_modes; j++) {=0A= c->mode =3D &connector->modes[j];=0A= if (!strcmp(c->mode->name, c->mode_str))=0A= break;=0A= }=0A= =0A= /* Found it, break out */=0A= if (c->mode)=0A= break;=0A= =0A= drmModeFreeConnector(connector);=0A= }=0A= =0A= if (!c->mode) {=0A= fprintf(stderr, "failed to find mode \"%s\"\n", c->mode_str);=0A= return;=0A= }=0A= =0A= /* Now get the encoder */=0A= for (i =3D 0; i < resources->count_encoders; i++) {=0A= c->encoder =3D drmModeGetEncoder(fd, resources->encoders[i]);=0A= =0A= if (!c->encoder) {=0A= fprintf(stderr, "could not get encoder %i: %s\n",=0A= resources->encoders[i], strerror(errno));=0A= drmModeFreeEncoder(c->encoder);=0A= continue;=0A= }=0A= =0A= if (c->encoder->encoder_id =3D=3D connector->encoder_id)=0A= break;=0A= =0A= drmModeFreeEncoder(c->encoder);=0A= }=0A= =0A= if (c->crtc =3D=3D -1)=0A= c->crtc =3D c->encoder->crtc_id;=0A= }=0A= =0A= static int=0A= create_test_buffer(struct kms_driver *driver,=0A= int width, int height, int *stride_out, struct kms_bo **bo_out)=0A= {=0A= struct kms_bo *bo;=0A= uint32_t *fb_ptr;=0A= int size, ret, i, stride;=0A= div_t d;=0A= void *ptr;=0A= =0A= /* Mode size at 32 bpp */=0A= stride =3D width * 4;=0A= size =3D stride * height;=0A= =0A= unsigned attrs[7] =3D {=0A= KMS_WIDTH, width,=0A= KMS_HEIGHT, height,=0A= KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8,=0A= KMS_TERMINATE_PROP_LIST,=0A= };=0A= =0A= =0A= if (kms_bo_create(driver, attrs, &bo)<0) {=0A= fprintf(stderr, "failed to alloc buffer: %s\n",=0A= strerror(errno));=0A= return -1;=0A= }=0A= =0A= if (kms_bo_map(bo, &ptr)<0) {=0A= fprintf(stderr, "failed to GTT map buffer: %s\n",=0A= strerror(errno));=0A= return -1;=0A= }=0A= fb_ptr =3D ptr;=0A= fprintf(stderr, "fb_ptr is %p\n", fb_ptr);=0A= =0A= /* paint the buffer with colored tiles */=0A= for (i =3D 0; i < width * height; i++) {=0A= d =3D div(i, width);=0A= //fb_ptr[i] =3D 0x00130502 * (d.quot >> 6) + 0x000a1120 * (d.rem >> 6);=0A= fb_ptr[i] =3D 0xffffffff;=0A= }=0A= =0A= kms_bo_unmap(bo);=0A= =0A= *bo_out =3D bo;=0A= *stride_out =3D stride;=0A= =0A= return 0;=0A= }=0A= =0A= static void=0A= set_mode(struct connector *c, int count, int page_flip)=0A= {=0A= drmModeConnector *connector;=0A= drmModeEncoder *encoder =3D NULL;=0A= struct drm_mode_modeinfo *mode =3D NULL;=0A= struct kms_driver *driver;=0A= struct kms_bo *bo, *other_bo;=0A= unsigned int fb_id, other_fb_id;=0A= int i, j, ret, width, height, x, stride;=0A= drmEventContext evctx;=0A= =0A= width =3D 0;=0A= height =3D 0;=0A= for (i =3D 0; i < count; i++) {=0A= connector_find_mode(&c[i]);=0A= if (c[i].mode =3D=3D NULL)=0A= continue;=0A= width +=3D c[i].mode->hdisplay;=0A= if (height < c[i].mode->vdisplay)=0A= height =3D c[i].mode->vdisplay;=0A= }=0A= =0A= if (kms_create(fd, &driver)<0) {=0A= fprintf(stderr, "failed to init bufmgr: %s\n", strerror(errno));=0A= return;=0A= }=0A= =0A= if (create_test_buffer(driver, width, height, &stride, &bo))=0A= return;=0A= =0A= fprintf(stderr, "pitch is: %d\n", bo->pitch);=0A= ret =3D drmModeAddFB(fd, width, height, 32, 32, bo->pitch, bo->handle,=0A= &fb_id);=0A= if (ret) {=0A= fprintf(stderr, "failed to add fb: %s\n", strerror(errno));=0A= return;=0A= }=0A= =0A= fprintf(stderr, "fb_id is :%08X\n", fb_id);=0A= =0A= x =3D 0;=0A= for (i =3D 0; i < count; i++) {=0A= if (c[i].mode =3D=3D NULL)=0A= continue;=0A= =0A= printf("setting mode %s on connector %d, crtc %d\n",=0A= c[i].mode_str, c[i].id, c[i].crtc);=0A= =0A= ret =3D drmModeSetCrtc(fd, c[i].crtc, fb_id, x, 0,=0A= &c[i].id, 1, c[i].mode);=0A= =0A= drmModeDirtyFB(fd, fb_id, NULL, 0);=0A= =0A= x +=3D c[i].mode->hdisplay;=0A= =0A= if (ret) {=0A= fprintf(stderr, "failed to set mode: %s\n", strerror(errno));=0A= return;=0A= }=0A= }=0A= =0A= return;=0A= }=0A= =0A= extern char *optarg;=0A= extern int optind, opterr, optopt;=0A= static char optstr[] =3D "ecpmfs:v";=0A= =0A= void usage(char *name)=0A= {=0A= fprintf(stderr, "usage: %s [-ecpmf]\n", name);=0A= fprintf(stderr, "\t-e\tlist encoders\n");=0A= fprintf(stderr, "\t-c\tlist connectors\n");=0A= fprintf(stderr, "\t-p\tlist CRTCs (pipes)\n");=0A= fprintf(stderr, "\t-m\tlist modes\n");=0A= fprintf(stderr, "\t-f\tlist framebuffers\n");=0A= fprintf(stderr, "\t-v\ttest vsynced page flipping\n");=0A= fprintf(stderr, "\t-s :\tset a mode\n");=0A= fprintf(stderr, "\t-s @:\tset a mode\n");=0A= fprintf(stderr, "\n\tDefault is to dump all info.\n");=0A= exit(0);=0A= }=0A= =0A= #define dump_resource(res) if (res) dump_##res()=0A= =0A= =0A= int main(int argc, char **argv)=0A= {=0A= int c;=0A= int encoders =3D 0, connectors =3D 0, crtcs =3D 0, framebuffers =3D 0;=0A= int test_vsync =3D 0;=0A= char *modules[] =3D { "vmwgfx", "i915", "radeon" };=0A= char *modeset =3D NULL, *mode, *connector;=0A= int i, connector_id, count =3D 0;=0A= struct connector con_args[2];=0A= =0A= opterr =3D 0;=0A= while ((c =3D getopt(argc, argv, optstr)) !=3D -1) {=0A= switch (c) {=0A= case 'e':=0A= encoders =3D 1;=0A= break;=0A= case 'c':=0A= connectors =3D 1;=0A= break;=0A= case 'p':=0A= crtcs =3D 1;=0A= break;=0A= case 'm':=0A= modes =3D 1;=0A= break;=0A= case 'f':=0A= framebuffers =3D 1;=0A= break;=0A= case 'v':=0A= test_vsync =3D 1;=0A= break;=0A= case 's':=0A= modeset =3D strdup(optarg);=0A= con_args[count].crtc =3D -1;=0A= if (sscanf(optarg, "%d:%64s",=0A= &con_args[count].id,=0A= &con_args[count].mode_str) !=3D 2 &&=0A= sscanf(optarg, "%d@%d:%64s",=0A= &con_args[count].id,=0A= &con_args[count].crtc,=0A= &con_args[count].mode_str) !=3D 3)=0A= usage(argv[0]);=0A= count++; =0A= break;=0A= default:=0A= usage(argv[0]);=0A= break;=0A= }=0A= }=0A= =0A= if (argc =3D=3D 1)=0A= encoders =3D connectors =3D crtcs =3D modes =3D framebuffers =3D 1;=0A= =0A= for (i =3D 0; i < ARRAY_SIZE(modules); i++) {=0A= printf("trying to load module %s...", modules[i]);=0A= fd =3D drmOpen(modules[i], NULL);=0A= if (fd < 0) {=0A= printf("failed.\n");=0A= } else {=0A= printf("success.\n");=0A= break;=0A= }=0A= }=0A= =0A= if (test_vsync && 1) {=0A= fprintf(stderr, "page flipping not supported by drm.\n");=0A= return -1;=0A= }=0A= =0A= if (i =3D=3D ARRAY_SIZE(modules)) {=0A= fprintf(stderr, "failed to load any modules, aborting.\n");=0A= return -1;=0A= }=0A= =0A= resources =3D drmModeGetResources(fd);=0A= if (!resources) {=0A= fprintf(stderr, "drmModeGetResources failed: %s\n",=0A= strerror(errno));=0A= drmClose(fd);=0A= return 1;=0A= }=0A= =0A= dump_resource(encoders);=0A= dump_resource(connectors);=0A= dump_resource(crtcs);=0A= dump_resource(framebuffers);=0A= =0A= if (count > 0) {=0A= set_mode(con_args, count, test_vsync);=0A= getchar();=0A= }=0A= =0A= drmModeFreeResources(resources);=0A= =0A= return 0;=0A= }=0A= ------=_NextPart_000_0057_01CAAA45.BCC96120 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev ------=_NextPart_000_0057_01CAAA45.BCC96120 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- _______________________________________________ Dri-devel mailing list Dri-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dri-devel ------=_NextPart_000_0057_01CAAA45.BCC96120--