mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-26 17:26:14 +00:00
testdisplay: extract hotplug code
Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
parent
137f4d467e
commit
7f7cafe729
@ -92,6 +92,12 @@ AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
|
|||||||
-I$(srcdir)/../lib
|
-I$(srcdir)/../lib
|
||||||
LDADD = ../lib/libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS)
|
LDADD = ../lib/libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS)
|
||||||
|
|
||||||
|
testdisplay_SOURCES = \
|
||||||
|
testdisplay.c \
|
||||||
|
testdisplay.h \
|
||||||
|
testdisplay_hotplug.c \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
TESTS_progs += testdisplay
|
TESTS_progs += testdisplay
|
||||||
LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS)
|
LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS)
|
||||||
AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS)
|
AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS)
|
||||||
|
@ -50,13 +50,8 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <glib.h>
|
|
||||||
#include <libudev.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -67,13 +62,13 @@
|
|||||||
#include "xf86drmMode.h"
|
#include "xf86drmMode.h"
|
||||||
#include "i915_drm.h"
|
#include "i915_drm.h"
|
||||||
#include "drmtest.h"
|
#include "drmtest.h"
|
||||||
|
#include "testdisplay.h"
|
||||||
|
|
||||||
#if defined(DRM_IOCTL_MODE_ADDFB2) && defined(DRM_I915_SET_SPRITE_COLORKEY)
|
#if defined(DRM_IOCTL_MODE_ADDFB2) && defined(DRM_I915_SET_SPRITE_COLORKEY)
|
||||||
#define TEST_PLANES 1
|
#define TEST_PLANES 1
|
||||||
#include "drm_fourcc.h"
|
#include "drm_fourcc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct udev_monitor *uevent_monitor;
|
|
||||||
drmModeRes *resources;
|
drmModeRes *resources;
|
||||||
int drm_fd, modes;
|
int drm_fd, modes;
|
||||||
int dump_info = 0, test_all_modes =0, test_preferred_mode = 0, force_mode = 0,
|
int dump_info = 0, test_all_modes =0, test_preferred_mode = 0, force_mode = 0,
|
||||||
@ -977,7 +972,7 @@ set_mode(struct connector *c)
|
|||||||
* Each connector has a corresponding encoder, except in the SDVO case
|
* Each connector has a corresponding encoder, except in the SDVO case
|
||||||
* where an encoder may have multiple connectors.
|
* where an encoder may have multiple connectors.
|
||||||
*/
|
*/
|
||||||
static int update_display(void)
|
int update_display(void)
|
||||||
{
|
{
|
||||||
struct connector *connectors;
|
struct connector *connectors;
|
||||||
int c;
|
int c;
|
||||||
@ -1032,32 +1027,6 @@ static void usage(char *name)
|
|||||||
|
|
||||||
#define dump_resource(res) if (res) dump_##res()
|
#define dump_resource(res) if (res) dump_##res()
|
||||||
|
|
||||||
static gboolean hotplug_event(GIOChannel *source, GIOCondition condition,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
struct udev_device *dev;
|
|
||||||
dev_t udev_devnum;
|
|
||||||
struct stat s;
|
|
||||||
const char *hotplug;
|
|
||||||
|
|
||||||
dev = udev_monitor_receive_device(uevent_monitor);
|
|
||||||
if (!dev)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
udev_devnum = udev_device_get_devnum(dev);
|
|
||||||
fstat(drm_fd, &s);
|
|
||||||
|
|
||||||
hotplug = udev_device_get_property_value(dev, "HOTPLUG");
|
|
||||||
|
|
||||||
if (memcmp(&s.st_rdev, &udev_devnum, sizeof(dev_t)) == 0 &&
|
|
||||||
hotplug && atoi(hotplug) == 1)
|
|
||||||
update_display();
|
|
||||||
|
|
||||||
udev_device_unref(dev);
|
|
||||||
out:
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean input_event(GIOChannel *source, GIOCondition condition,
|
static gboolean input_event(GIOChannel *source, GIOCondition condition,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
@ -1093,9 +1062,8 @@ int main(int argc, char **argv)
|
|||||||
int c;
|
int c;
|
||||||
const char *modules[] = { "i915" };
|
const char *modules[] = { "i915" };
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct udev *u;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
GIOChannel *udevchannel, *stdinchannel;
|
GIOChannel *stdinchannel;
|
||||||
GMainLoop *mainloop;
|
GMainLoop *mainloop;
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
@ -1160,90 +1128,49 @@ int main(int argc, char **argv)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
u = udev_new();
|
|
||||||
if (!u) {
|
|
||||||
fprintf(stderr, "failed to create udev object\n");
|
|
||||||
ret = -1;
|
|
||||||
goto out_close;
|
|
||||||
}
|
|
||||||
|
|
||||||
uevent_monitor = udev_monitor_new_from_netlink(u, "udev");
|
|
||||||
if (!uevent_monitor) {
|
|
||||||
fprintf(stderr, "failed to create udev event monitor\n");
|
|
||||||
ret = -1;
|
|
||||||
goto out_udev_unref;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = udev_monitor_filter_add_match_subsystem_devtype(uevent_monitor,
|
|
||||||
"drm",
|
|
||||||
"drm_minor");
|
|
||||||
if (ret < 0) {
|
|
||||||
fprintf(stderr, "failed to filter for drm events\n");
|
|
||||||
goto out_udev_mon_unref;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = udev_monitor_enable_receiving(uevent_monitor);
|
|
||||||
if (ret < 0) {
|
|
||||||
fprintf(stderr, "failed to enable udev event reception\n");
|
|
||||||
goto out_udev_mon_unref;
|
|
||||||
}
|
|
||||||
|
|
||||||
mainloop = g_main_loop_new(NULL, FALSE);
|
mainloop = g_main_loop_new(NULL, FALSE);
|
||||||
if (!mainloop) {
|
if (!mainloop) {
|
||||||
fprintf(stderr, "failed to create glib mainloop\n");
|
fprintf(stderr, "failed to create glib mainloop\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out_mainloop_unref;
|
goto out_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
udevchannel =
|
if (!testdisplay_setup_hotplug()) {
|
||||||
g_io_channel_unix_new(udev_monitor_get_fd(uevent_monitor));
|
fprintf(stderr, "failed to initialize hotplug support\n");
|
||||||
if (!udevchannel) {
|
goto out_mainloop;
|
||||||
fprintf(stderr, "failed to create udev GIO channel\n");
|
|
||||||
goto out_mainloop_unref;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = g_io_add_watch(udevchannel, G_IO_IN | G_IO_ERR, hotplug_event,
|
|
||||||
u);
|
|
||||||
if (ret < 0) {
|
|
||||||
fprintf(stderr, "failed to add watch on udev GIO channel\n");
|
|
||||||
goto out_udev_off;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stdinchannel = g_io_channel_unix_new(0);
|
stdinchannel = g_io_channel_unix_new(0);
|
||||||
if (!stdinchannel) {
|
if (!stdinchannel) {
|
||||||
fprintf(stderr, "failed to create stdin GIO channel\n");
|
fprintf(stderr, "failed to create stdin GIO channel\n");
|
||||||
goto out_udev_off;
|
goto out_hotplug;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event,
|
ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event,
|
||||||
NULL);
|
NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "failed to add watch on stdin GIO channel\n");
|
fprintf(stderr, "failed to add watch on stdin GIO channel\n");
|
||||||
goto out_stdio_off;
|
goto out_stdio;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
if (!update_display()) {
|
if (!update_display()) {
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto out_stdio_off;
|
goto out_stdio;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dump_info || test_all_modes)
|
if (dump_info || test_all_modes)
|
||||||
goto out_stdio_off;
|
goto out_stdio;
|
||||||
|
|
||||||
g_main_loop_run(mainloop);
|
g_main_loop_run(mainloop);
|
||||||
|
|
||||||
out_stdio_off:
|
out_stdio:
|
||||||
g_io_channel_shutdown(stdinchannel, TRUE, NULL);
|
g_io_channel_shutdown(stdinchannel, TRUE, NULL);
|
||||||
out_udev_off:
|
out_hotplug:
|
||||||
g_io_channel_shutdown(udevchannel, TRUE, NULL);
|
testdisplay_cleanup_hotplug();
|
||||||
out_mainloop_unref:
|
out_mainloop:
|
||||||
g_main_loop_unref(mainloop);
|
g_main_loop_unref(mainloop);
|
||||||
out_udev_mon_unref:
|
|
||||||
udev_monitor_unref(uevent_monitor);
|
|
||||||
out_udev_unref:
|
|
||||||
udev_unref(u);
|
|
||||||
out_close:
|
out_close:
|
||||||
if (test_plane)
|
if (test_plane)
|
||||||
disable_planes(drm_fd);
|
disable_planes(drm_fd);
|
||||||
|
35
tests/testdisplay.h
Normal file
35
tests/testdisplay.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
extern int drm_fd;
|
||||||
|
|
||||||
|
gboolean testdisplay_setup_hotplug(void);
|
||||||
|
void testdisplay_cleanup_hotplug(void);
|
||||||
|
|
||||||
|
/* called by the hotplug code */
|
||||||
|
int update_display(void);
|
121
tests/testdisplay_hotplug.c
Normal file
121
tests/testdisplay_hotplug.c
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <libudev.h>
|
||||||
|
|
||||||
|
#include "testdisplay.h"
|
||||||
|
|
||||||
|
static struct udev_monitor *uevent_monitor;
|
||||||
|
static struct udev *udev;
|
||||||
|
static GIOChannel *udevchannel;
|
||||||
|
|
||||||
|
static gboolean hotplug_event(GIOChannel *source, GIOCondition condition,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
struct udev_device *dev;
|
||||||
|
dev_t udev_devnum;
|
||||||
|
struct stat s;
|
||||||
|
const char *hotplug;
|
||||||
|
|
||||||
|
dev = udev_monitor_receive_device(uevent_monitor);
|
||||||
|
if (!dev)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
udev_devnum = udev_device_get_devnum(dev);
|
||||||
|
fstat(drm_fd, &s);
|
||||||
|
|
||||||
|
hotplug = udev_device_get_property_value(dev, "HOTPLUG");
|
||||||
|
|
||||||
|
if (memcmp(&s.st_rdev, &udev_devnum, sizeof(dev_t)) == 0 &&
|
||||||
|
hotplug && atoi(hotplug) == 1)
|
||||||
|
update_display();
|
||||||
|
|
||||||
|
udev_device_unref(dev);
|
||||||
|
out:
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean testdisplay_setup_hotplug(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
udev = udev_new();
|
||||||
|
if (!udev) {
|
||||||
|
fprintf(stderr, "failed to create udev object\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uevent_monitor = udev_monitor_new_from_netlink(udev, "udev");
|
||||||
|
if (!uevent_monitor) {
|
||||||
|
fprintf(stderr, "failed to create udev event monitor\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = udev_monitor_filter_add_match_subsystem_devtype(uevent_monitor,
|
||||||
|
"drm",
|
||||||
|
"drm_minor");
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "failed to filter for drm events\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = udev_monitor_enable_receiving(uevent_monitor);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "failed to enable udev event reception\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
udevchannel =
|
||||||
|
g_io_channel_unix_new(udev_monitor_get_fd(uevent_monitor));
|
||||||
|
if (!udevchannel) {
|
||||||
|
fprintf(stderr, "failed to create udev GIO channel\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = g_io_add_watch(udevchannel, G_IO_IN | G_IO_ERR, hotplug_event,
|
||||||
|
udev);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "failed to add watch on udev GIO channel\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
out:
|
||||||
|
testdisplay_cleanup_hotplug();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testdisplay_cleanup_hotplug(void)
|
||||||
|
{
|
||||||
|
if (udevchannel)
|
||||||
|
g_io_channel_shutdown(udevchannel, TRUE, NULL);
|
||||||
|
if (uevent_monitor)
|
||||||
|
udev_monitor_unref(uevent_monitor);
|
||||||
|
if (udev)
|
||||||
|
udev_unref(udev);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user