aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2016-03-24 11:35:51 +0100
committerGerd Hoffmann <kraxel@redhat.com>2016-03-24 11:35:51 +0100
commit7e1cb7262703c8d873b3838aaf4b5083716b5065 (patch)
tree0630c25626b6e7e45f511d4fc99c9896ec91f026
parent5e68ede72c48aeae3412e31e5633c03d48048deb (diff)
downloadfbida-7e1cb7262703c8d873b3838aaf4b5083716b5065.tar.gz
gfx init and console switching tweaks
-rw-r--r--drmtools.c8
-rw-r--r--fbi.c40
-rw-r--r--fbtools.c25
-rw-r--r--vt.c25
4 files changed, 54 insertions, 44 deletions
diff --git a/drmtools.c b/drmtools.c
index 563aa3b..ebe487a 100644
--- a/drmtools.c
+++ b/drmtools.c
@@ -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));
diff --git a/fbi.c b/fbi.c
index e25453f..b7edd3b 100644
--- a/fbi.c
+++ b/fbi.c
@@ -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();
diff --git a/fbtools.c b/fbtools.c
index 4391022..c10bea2 100644
--- a/fbtools.c
+++ b/fbtools.c
@@ -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) */
diff --git a/vt.c b/vt.c
index da77813..f15d51f 100644
--- a/vt.c
+++ b/vt.c
@@ -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;