diff options
-rw-r--r-- | drmtools.c | 8 | ||||
-rw-r--r-- | fbi.c | 40 | ||||
-rw-r--r-- | fbtools.c | 25 | ||||
-rw-r--r-- | vt.c | 25 |
4 files changed, 54 insertions, 44 deletions
@@ -42,13 +42,19 @@ static void drm_cleanup_display(void) } } -static int drm_init_dev(const char *dev) +static int drm_init_dev(const char *device) { drmModeRes *res; + char dev[64]; int i, rc; uint64_t has_dumb; /* open device */ + if (device) { + snprintf(dev, sizeof(dev), "%s", device); + } else { + snprintf(dev, sizeof(dev), DRM_DEV_NAME, DRM_DIR_NAME, 0); + } fd = open(dev, O_RDWR); if (fd < 0) { fprintf(stderr, "drm: open %s: %s\n", dev, strerror(errno)); @@ -7,6 +7,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> #include <stddef.h> #include <string.h> #include <unistd.h> @@ -1433,7 +1434,8 @@ int main(int argc, char *argv[]) { int once; int i, arg, key; - char *info, *desc, *filelist, *device; + bool framebuffer = false; + char *info, *desc, *filelist, *device, *mode; char linebuffer[128]; struct flist *fprev = NULL; @@ -1514,17 +1516,39 @@ int main(int argc, char *argv[]) /* gfx device init */ device = cfg_get_str(O_DEVICE); - if (device && strncmp(device, "/dev/dri", 8) == 0) { - gfx = drm_init(device); + mode = cfg_get_str(O_VIDEO_MODE); + if (device) { + /* device specified */ + if (strncmp(device, "/dev/d", 6) == 0) { + gfx = drm_init(device); + } else { + framebuffer = true; + gfx = fb_init(device, mode, GET_VT()); + } } else { - gfx = fb_init(device, - cfg_get_str(O_VIDEO_MODE), - GET_VT()); + /* try drm first, failing that fb */ + gfx = drm_init(NULL); + if (!gfx) { + framebuffer = true; + gfx = fb_init(NULL, mode, GET_VT()); + } + } + if (!gfx) { + fprintf(stderr, "graphics init failed\n"); + exit(1); } exit_signals_init(); - console_switch_init(console_switch_redraw); - shadow_init(gfx); signal(SIGTSTP,SIG_IGN); + if (console_switch_init(console_switch_redraw) < 0) { + fprintf(stderr, "NOTICE: No vt switching available on terminal.\n"); + fprintf(stderr, "NOTICE: Not started from linux console? CONFIG_VT=n?\n"); + if (framebuffer) { + fprintf(stderr, "WARNING: Running on framebuffer and can't manage access.\n"); + fprintf(stderr, "WARNING: Other processes (fbcon too) can write to display.\n"); + fprintf(stderr, "WARNING: Also can't properly cleanup on exit.\n"); + } + } + shadow_init(gfx); /* svga main loop */ tty_raw(); @@ -237,32 +237,11 @@ gfxstate* fb_init(char *device, char *mode, int vt) if (vt != 0) console_set_vt(vt); - if (-1 == ioctl(STDIN_FILENO, VT_GETSTATE, &vts)) { - fprintf(stderr,"ioctl VT_GETSTATE: %s (not a linux console?)\n", - strerror(errno)); - exit(1); - } - if (NULL == device) { device = getenv("FRAMEBUFFER"); if (NULL == device) { - struct fb_con2fbmap c2m; - memset(&c2m, 0, sizeof(c2m)); - if (-1 == (fb = open("/dev/fb0", O_RDWR /* O_WRONLY */, 0))) { - fprintf(stderr, "open /dev/fb0: %s\n", strerror(errno)); - exit(1); - } - c2m.console = vts.v_active; - if (-1 == ioctl(fb, FBIOGET_CON2FBMAP, &c2m)) { - perror("ioctl FBIOGET_CON2FBMAP"); - exit(1); - } - close(fb); - fprintf(stderr,"map: vt%02d => fb%d\n", - c2m.console, c2m.framebuffer); - sprintf(fbdev, "/dev/fb%d", c2m.framebuffer); - device = fbdev; - } + device = "/dev/fb0"; + } } /* get current settings (which we have to restore) */ @@ -77,30 +77,31 @@ int console_switch_init(void (*redraw)(void)) sigaction(SIGUSR1,&act,&old); sigaction(SIGUSR2,&act,&old); + if (-1 == ioctl(STDIN_FILENO, VT_GETMODE, &vt_omode)) { + perror("ioctl VT_GETMODE"); + return -1; + } + if (-1 == ioctl(STDIN_FILENO, KDGETMODE, &kd_mode)) { + perror("ioctl KDGETMODE"); + return -1; + } + if (-1 == ioctl(STDIN_FILENO, VT_GETMODE, &vt_mode)) { perror("ioctl VT_GETMODE"); - exit(1); + return -1; } vt_mode.mode = VT_PROCESS; vt_mode.waitv = 0; vt_mode.relsig = SIGUSR1; vt_mode.acqsig = SIGUSR2; - - if (-1 == ioctl(STDIN_FILENO, VT_GETMODE, &vt_omode)) { - perror("ioctl VT_GETMODE"); - exit(1); - } if (-1 == ioctl(STDIN_FILENO, VT_SETMODE, &vt_mode)) { perror("ioctl VT_SETMODE"); - exit(1); - } - if (-1 == ioctl(STDIN_FILENO, KDGETMODE, &kd_mode)) { - perror("ioctl KDGETMODE"); - exit(1); + return -1; } if (-1 == ioctl(STDIN_FILENO, KDSETMODE, KD_GRAPHICS)) { + ioctl(STDIN_FILENO, VT_SETMODE, &vt_omode); perror("ioctl KDSETMODE"); - exit(1); + return -1; } console_switching_active = true; return 0; |