kms.c revision 3f012e29
13f012e29Smrg/* 23f012e29Smrg * Copyright 2008 Tungsten Graphics 33f012e29Smrg * Jakob Bornecrantz <jakob@tungstengraphics.com> 43f012e29Smrg * Copyright 2008 Intel Corporation 53f012e29Smrg * Jesse Barnes <jesse.barnes@intel.com> 63f012e29Smrg * 73f012e29Smrg * Permission is hereby granted, free of charge, to any person obtaining a 83f012e29Smrg * copy of this software and associated documentation files (the "Software"), 93f012e29Smrg * to deal in the Software without restriction, including without limitation 103f012e29Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 113f012e29Smrg * and/or sell copies of the Software, and to permit persons to whom the 123f012e29Smrg * Software is furnished to do so, subject to the following conditions: 133f012e29Smrg * 143f012e29Smrg * The above copyright notice and this permission notice shall be included in 153f012e29Smrg * all copies or substantial portions of the Software. 163f012e29Smrg * 173f012e29Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 183f012e29Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 193f012e29Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 203f012e29Smrg * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 213f012e29Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 223f012e29Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 233f012e29Smrg * IN THE SOFTWARE. 243f012e29Smrg */ 253f012e29Smrg 263f012e29Smrg/* 273f012e29Smrg * This fairly simple test program dumps output in a similar format to the 283f012e29Smrg * "xrandr" tool everyone knows & loves. It's necessarily slightly different 293f012e29Smrg * since the kernel separates outputs into encoder and connector structures, 303f012e29Smrg * each with their own unique ID. The program also allows test testing of the 313f012e29Smrg * memory management and mode setting APIs by allowing the user to specify a 323f012e29Smrg * connector and mode to use for mode setting. If all works as expected, a 333f012e29Smrg * blue background should be painted on the monitor attached to the specified 343f012e29Smrg * connector after the selected mode is set. 353f012e29Smrg * 363f012e29Smrg * TODO: use cairo to write the mode info on the selected output once 373f012e29Smrg * the mode has been programmed, along with possible test patterns. 383f012e29Smrg */ 393f012e29Smrg 403f012e29Smrg#ifdef HAVE_CONFIG_H 413f012e29Smrg#include "config.h" 423f012e29Smrg#endif 433f012e29Smrg 443f012e29Smrg#include <errno.h> 453f012e29Smrg#include <stdint.h> 463f012e29Smrg#include <stdio.h> 473f012e29Smrg#include <stdlib.h> 483f012e29Smrg#include <string.h> 493f012e29Smrg 503f012e29Smrg#include "xf86drm.h" 513f012e29Smrg#include "xf86drmMode.h" 523f012e29Smrg 533f012e29Smrg#include "common.h" 543f012e29Smrg 553f012e29Smrgstruct type_name { 563f012e29Smrg unsigned int type; 573f012e29Smrg const char *name; 583f012e29Smrg}; 593f012e29Smrg 603f012e29Smrgstatic const char *util_lookup_type_name(unsigned int type, 613f012e29Smrg const struct type_name *table, 623f012e29Smrg unsigned int count) 633f012e29Smrg{ 643f012e29Smrg unsigned int i; 653f012e29Smrg 663f012e29Smrg for (i = 0; i < count; i++) 673f012e29Smrg if (table[i].type == type) 683f012e29Smrg return table[i].name; 693f012e29Smrg 703f012e29Smrg return NULL; 713f012e29Smrg} 723f012e29Smrg 733f012e29Smrgstatic const struct type_name encoder_type_names[] = { 743f012e29Smrg { DRM_MODE_ENCODER_NONE, "none" }, 753f012e29Smrg { DRM_MODE_ENCODER_DAC, "DAC" }, 763f012e29Smrg { DRM_MODE_ENCODER_TMDS, "TMDS" }, 773f012e29Smrg { DRM_MODE_ENCODER_LVDS, "LVDS" }, 783f012e29Smrg { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, 793f012e29Smrg { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, 803f012e29Smrg { DRM_MODE_ENCODER_DSI, "DSI" }, 813f012e29Smrg { DRM_MODE_ENCODER_DPMST, "DPMST" }, 823f012e29Smrg}; 833f012e29Smrg 843f012e29Smrgconst char *util_lookup_encoder_type_name(unsigned int type) 853f012e29Smrg{ 863f012e29Smrg return util_lookup_type_name(type, encoder_type_names, 873f012e29Smrg ARRAY_SIZE(encoder_type_names)); 883f012e29Smrg} 893f012e29Smrg 903f012e29Smrgstatic const struct type_name connector_status_names[] = { 913f012e29Smrg { DRM_MODE_CONNECTED, "connected" }, 923f012e29Smrg { DRM_MODE_DISCONNECTED, "disconnected" }, 933f012e29Smrg { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, 943f012e29Smrg}; 953f012e29Smrg 963f012e29Smrgconst char *util_lookup_connector_status_name(unsigned int status) 973f012e29Smrg{ 983f012e29Smrg return util_lookup_type_name(status, connector_status_names, 993f012e29Smrg ARRAY_SIZE(connector_status_names)); 1003f012e29Smrg} 1013f012e29Smrg 1023f012e29Smrgstatic const struct type_name connector_type_names[] = { 1033f012e29Smrg { DRM_MODE_CONNECTOR_Unknown, "unknown" }, 1043f012e29Smrg { DRM_MODE_CONNECTOR_VGA, "VGA" }, 1053f012e29Smrg { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, 1063f012e29Smrg { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, 1073f012e29Smrg { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, 1083f012e29Smrg { DRM_MODE_CONNECTOR_Composite, "composite" }, 1093f012e29Smrg { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, 1103f012e29Smrg { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, 1113f012e29Smrg { DRM_MODE_CONNECTOR_Component, "component" }, 1123f012e29Smrg { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, 1133f012e29Smrg { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, 1143f012e29Smrg { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, 1153f012e29Smrg { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, 1163f012e29Smrg { DRM_MODE_CONNECTOR_TV, "TV" }, 1173f012e29Smrg { DRM_MODE_CONNECTOR_eDP, "eDP" }, 1183f012e29Smrg { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, 1193f012e29Smrg { DRM_MODE_CONNECTOR_DSI, "DSI" }, 1203f012e29Smrg}; 1213f012e29Smrg 1223f012e29Smrgconst char *util_lookup_connector_type_name(unsigned int type) 1233f012e29Smrg{ 1243f012e29Smrg return util_lookup_type_name(type, connector_type_names, 1253f012e29Smrg ARRAY_SIZE(connector_type_names)); 1263f012e29Smrg} 1273f012e29Smrg 1283f012e29Smrgstatic const char * const modules[] = { 1293f012e29Smrg "i915", 1303f012e29Smrg "radeon", 1313f012e29Smrg "nouveau", 1323f012e29Smrg "vmwgfx", 1333f012e29Smrg "omapdrm", 1343f012e29Smrg "exynos", 1353f012e29Smrg "tilcdc", 1363f012e29Smrg "msm", 1373f012e29Smrg "sti", 1383f012e29Smrg "tegra", 1393f012e29Smrg "imx-drm", 1403f012e29Smrg "rockchip", 1413f012e29Smrg "atmel-hlcdc", 1423f012e29Smrg "fsl-dcu-drm", 1433f012e29Smrg "vc4", 1443f012e29Smrg "virtio_gpu", 1453f012e29Smrg}; 1463f012e29Smrg 1473f012e29Smrgint util_open(const char *device, const char *module) 1483f012e29Smrg{ 1493f012e29Smrg int fd; 1503f012e29Smrg 1513f012e29Smrg if (module) { 1523f012e29Smrg fd = drmOpen(module, device); 1533f012e29Smrg if (fd < 0) { 1543f012e29Smrg fprintf(stderr, "failed to open device '%s': %s\n", 1553f012e29Smrg module, strerror(errno)); 1563f012e29Smrg return -errno; 1573f012e29Smrg } 1583f012e29Smrg } else { 1593f012e29Smrg unsigned int i; 1603f012e29Smrg 1613f012e29Smrg for (i = 0; i < ARRAY_SIZE(modules); i++) { 1623f012e29Smrg printf("trying to open device '%s'...", modules[i]); 1633f012e29Smrg 1643f012e29Smrg fd = drmOpen(modules[i], device); 1653f012e29Smrg if (fd < 0) { 1663f012e29Smrg printf("failed\n"); 1673f012e29Smrg } else { 1683f012e29Smrg printf("done\n"); 1693f012e29Smrg break; 1703f012e29Smrg } 1713f012e29Smrg } 1723f012e29Smrg 1733f012e29Smrg if (fd < 0) { 1743f012e29Smrg fprintf(stderr, "no device found\n"); 1753f012e29Smrg return -ENODEV; 1763f012e29Smrg } 1773f012e29Smrg } 1783f012e29Smrg 1793f012e29Smrg return fd; 1803f012e29Smrg} 181