aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2019-01-31 07:15:47 +0100
committerGerd Hoffmann <kraxel@redhat.com>2019-01-31 07:15:47 +0100
commit6c289d544115c7b5c8ca5ca2e4101d0543dc1564 (patch)
tree55fe11c0b407d8d449c28e4cf90579d6840aa606
parent2764d42d490c13e38ef2cd06b2eb245045d8111e (diff)
downloadfbida-6c289d544115c7b5c8ca5ca2e4101d0543dc1564.tar.gz
udev device enumeration
-rw-r--r--fbcon.c59
-rw-r--r--fbtools.c2
-rw-r--r--fbtools.h2
3 files changed, 51 insertions, 12 deletions
diff --git a/fbcon.c b/fbcon.c
index 5214640..ad586be 100644
--- a/fbcon.c
+++ b/fbcon.c
@@ -33,6 +33,7 @@
/* ---------------------------------------------------------------------- */
+static char *seat_name = "seat0";
static char *font_name = "monospace";
static int font_size = 16;
@@ -283,18 +284,57 @@ static void tmt_callback(tmt_msg_t m, TMT *vt, const void *a, void *p)
int main(int argc, char *argv[])
{
- pid_t child;
- int pty, input;
+ struct udev_enumerate *uenum;
+ struct udev_list_entry *ulist, *uentry;
struct winsize win;
+ const char *drm_node = NULL;
+ const char *fb_node = NULL;
+ int pty, input;
+ pid_t child;
setlocale(LC_ALL,"");
- /* init drm */
- gfx = drm_init(NULL, NULL, NULL, true);
- if (!gfx) {
- fprintf(stderr, "drm init failed\n");
- exit(1);
+ /* look for gfx devices */
+ udev = udev_new();
+ uenum = udev_enumerate_new(udev);
+ udev_enumerate_add_match_subsystem(uenum, "drm");
+ udev_enumerate_add_match_subsystem(uenum, "graphics");
+ udev_enumerate_add_match_tag(uenum, "seat");
+ udev_enumerate_scan_devices(uenum);
+ ulist = udev_enumerate_get_list_entry(uenum);
+ udev_list_entry_foreach(uentry, ulist) {
+ const char *path = udev_list_entry_get_name(uentry);
+ struct udev_device *udevice = udev_device_new_from_syspath(udev, path);
+ const char *node = udev_device_get_devnode(udevice);
+ const char *seat = udev_device_get_property_value(udevice, "ID_SEAT");
+ const char *subsys = udev_device_get_subsystem(udevice);
+ if (!seat)
+ seat = "seat0";
+ if (strcmp(seat, seat_name) != 0)
+ continue;
+ if (!node)
+ continue;
+ if (!drm_node && strcmp(subsys, "drm") == 0)
+ drm_node = node;
+ if (!fb_node && strcmp(subsys, "graphics") == 0)
+ fb_node = node;
}
+
+ /* init graphics */
+ if (drm_node) {
+ gfx = drm_init(drm_node, NULL, NULL, true);
+ if (!gfx)
+ fprintf(stderr, "%s: init failed\n", drm_node);
+ }
+#if 0
+ if (!gfx && fb_node) {
+ gfx = fb_init(fb_node, NULL, 0);
+ if (!gfx)
+ fprintf(stderr, "%s: init failed\n", fb_node);
+ }
+#endif
+ if (!gfx)
+ exit(1);
exit_signals_init();
signal(SIGTSTP,SIG_IGN);
@@ -323,10 +363,9 @@ int main(int argc, char *argv[])
cairo_set_font_size(context2, font_size);
}
- /* init udev + libinput */
- udev = udev_new();
+ /* init libinput */
kbd = libinput_udev_create_context(&interface, NULL, udev);
- libinput_udev_assign_seat(kbd, "seat0");
+ libinput_udev_assign_seat(kbd, seat_name);
input = libinput_get_fd(kbd);
/* init udev + xkbcommon */
diff --git a/fbtools.c b/fbtools.c
index a429775..5c644ff 100644
--- a/fbtools.c
+++ b/fbtools.c
@@ -221,7 +221,7 @@ static void fb_cleanup_display(void)
/* -------------------------------------------------------------------- */
-gfxstate* fb_init(char *device, char *mode, int vt)
+gfxstate* fb_init(const char *device, char *mode, int vt)
{
unsigned long page_mask;
struct stat st;
diff --git a/fbtools.h b/fbtools.h
index 8b8156a..4adb452 100644
--- a/fbtools.h
+++ b/fbtools.h
@@ -1,3 +1,3 @@
#include "gfx.h"
-gfxstate *fb_init(char *device, char *mode, int vt);
+gfxstate *fb_init(const char *device, char *mode, int vt);