2015-12-09 10:37:40 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Tungsten Graphics
|
|
|
|
* Jakob Bornecrantz <jakob@tungstengraphics.com>
|
|
|
|
* Copyright 2008 Intel Corporation
|
|
|
|
* Jesse Barnes <jesse.barnes@intel.com>
|
|
|
|
*
|
|
|
|
* 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 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This fairly simple test program dumps output in a similar format to the
|
|
|
|
* "xrandr" tool everyone knows & loves. It's necessarily slightly different
|
|
|
|
* since the kernel separates outputs into encoder and connector structures,
|
|
|
|
* each with their own unique ID. The program also allows test testing of the
|
|
|
|
* memory management and mode setting APIs by allowing the user to specify a
|
|
|
|
* connector and mode to use for mode setting. If all works as expected, a
|
|
|
|
* blue background should be painted on the monitor attached to the specified
|
|
|
|
* connector after the selected mode is set.
|
|
|
|
*
|
|
|
|
* TODO: use cairo to write the mode info on the selected output once
|
|
|
|
* the mode has been programmed, along with possible test patterns.
|
|
|
|
*/
|
|
|
|
|
2015-12-09 10:37:45 -07:00
|
|
|
#include <errno.h>
|
2015-12-09 10:37:40 -07:00
|
|
|
#include <stdint.h>
|
2015-12-09 10:37:45 -07:00
|
|
|
#include <stdio.h>
|
2015-12-09 10:37:40 -07:00
|
|
|
#include <stdlib.h>
|
2015-12-09 10:37:45 -07:00
|
|
|
#include <string.h>
|
2015-12-09 10:37:40 -07:00
|
|
|
|
2015-12-09 10:37:45 -07:00
|
|
|
#include "xf86drm.h"
|
2015-12-09 10:37:40 -07:00
|
|
|
#include "xf86drmMode.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
struct type_name {
|
|
|
|
unsigned int type;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *util_lookup_type_name(unsigned int type,
|
|
|
|
const struct type_name *table,
|
|
|
|
unsigned int count)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if (table[i].type == type)
|
|
|
|
return table[i].name;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const 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" },
|
|
|
|
{ DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
|
|
|
|
{ DRM_MODE_ENCODER_DSI, "DSI" },
|
|
|
|
{ DRM_MODE_ENCODER_DPMST, "DPMST" },
|
2017-04-25 12:31:27 -06:00
|
|
|
{ DRM_MODE_ENCODER_DPI, "DPI" },
|
2015-12-09 10:37:40 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *util_lookup_encoder_type_name(unsigned int type)
|
|
|
|
{
|
|
|
|
return util_lookup_type_name(type, encoder_type_names,
|
|
|
|
ARRAY_SIZE(encoder_type_names));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct type_name connector_status_names[] = {
|
|
|
|
{ DRM_MODE_CONNECTED, "connected" },
|
|
|
|
{ DRM_MODE_DISCONNECTED, "disconnected" },
|
|
|
|
{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *util_lookup_connector_status_name(unsigned int status)
|
|
|
|
{
|
|
|
|
return util_lookup_type_name(status, connector_status_names,
|
|
|
|
ARRAY_SIZE(connector_status_names));
|
|
|
|
}
|
|
|
|
|
2015-12-09 10:37:45 -07:00
|
|
|
static const char * const modules[] = {
|
|
|
|
"i915",
|
2016-08-09 01:17:51 -06:00
|
|
|
"amdgpu",
|
2015-12-09 10:37:45 -07:00
|
|
|
"radeon",
|
|
|
|
"nouveau",
|
|
|
|
"vmwgfx",
|
|
|
|
"omapdrm",
|
|
|
|
"exynos",
|
|
|
|
"tilcdc",
|
|
|
|
"msm",
|
|
|
|
"sti",
|
|
|
|
"tegra",
|
|
|
|
"imx-drm",
|
|
|
|
"rockchip",
|
|
|
|
"atmel-hlcdc",
|
2015-12-19 22:52:59 -07:00
|
|
|
"fsl-dcu-drm",
|
2016-01-22 17:37:25 -07:00
|
|
|
"vc4",
|
2016-03-17 15:42:25 -06:00
|
|
|
"virtio_gpu",
|
2016-08-31 19:48:17 -06:00
|
|
|
"mediatek",
|
2017-01-18 06:59:21 -07:00
|
|
|
"meson",
|
2017-04-25 12:29:33 -06:00
|
|
|
"pl111",
|
2018-07-20 05:32:52 -06:00
|
|
|
"stm",
|
2018-09-22 07:28:39 -06:00
|
|
|
"sun4i-drm",
|
2019-03-23 14:23:42 -06:00
|
|
|
"armada-drm",
|
2020-10-16 04:00:15 -06:00
|
|
|
"komeda",
|
2020-03-20 11:27:59 -06:00
|
|
|
"imx-dcss",
|
2020-12-30 11:29:33 -07:00
|
|
|
"mxsfb-drm",
|
2022-06-13 09:07:35 -06:00
|
|
|
"simpledrm",
|
2022-07-08 03:39:14 -06:00
|
|
|
"imx-lcdif",
|
2023-02-01 20:58:12 -07:00
|
|
|
"vkms",
|
2015-12-09 10:37:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
int util_open(const char *device, const char *module)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (module) {
|
|
|
|
fd = drmOpen(module, device);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "failed to open device '%s': %s\n",
|
|
|
|
module, strerror(errno));
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(modules); i++) {
|
|
|
|
printf("trying to open device '%s'...", modules[i]);
|
|
|
|
|
|
|
|
fd = drmOpen(modules[i], device);
|
|
|
|
if (fd < 0) {
|
|
|
|
printf("failed\n");
|
|
|
|
} else {
|
|
|
|
printf("done\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "no device found\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|