2 * Copyright 2010 Intel Corporation
3 * Jesse Barnes <jesse.barnes@intel.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include "testdisplay.h"
37 static struct udev_monitor *uevent_monitor;
38 static struct udev *udev;
39 static GIOChannel *udevchannel;
41 static gboolean hotplug_event(GIOChannel *source, GIOCondition condition,
44 struct udev_device *dev;
49 dev = udev_monitor_receive_device(uevent_monitor);
53 udev_devnum = udev_device_get_devnum(dev);
56 hotplug = udev_device_get_property_value(dev, "HOTPLUG");
58 if (memcmp(&s.st_rdev, &udev_devnum, sizeof(dev_t)) == 0 &&
59 hotplug && atoi(hotplug) == 1)
62 udev_device_unref(dev);
68 gboolean testdisplay_setup_hotplug(void)
74 igt_warn("failed to create udev object\n");
78 uevent_monitor = udev_monitor_new_from_netlink(udev, "udev");
79 if (!uevent_monitor) {
80 igt_warn("failed to create udev event monitor\n");
84 ret = udev_monitor_filter_add_match_subsystem_devtype(uevent_monitor,
88 igt_warn("failed to filter for drm events\n");
92 ret = udev_monitor_enable_receiving(uevent_monitor);
94 igt_warn("failed to enable udev event reception\n");
99 g_io_channel_unix_new(udev_monitor_get_fd(uevent_monitor));
101 igt_warn("failed to create udev GIO channel\n");
105 ret = g_io_add_watch(udevchannel, G_IO_IN | G_IO_ERR, hotplug_event,
108 igt_warn("failed to add watch on udev GIO channel\n");
115 testdisplay_cleanup_hotplug();
119 void testdisplay_cleanup_hotplug(void)
122 g_io_channel_shutdown(udevchannel, TRUE, NULL);
124 udev_monitor_unref(uevent_monitor);
129 gboolean testdisplay_setup_hotplug(void)
131 igt_warn("no hotplug support on this platform\n");
135 void testdisplay_cleanup_hotplug(void)