Skip to content

Commit

Permalink
pc-tty: add enabling/disabling fbcon via ioctl
Browse files Browse the repository at this point in the history
Graphical apps can now disable console drawing via ioctl/TTYSETMODE to
ensure uninterrupted drawing (otherwise app and console would draw
to the framebuffer in the same time, causing mess)

JIRA: RTOS-925
  • Loading branch information
adamgreloch committed Nov 22, 2024
1 parent 621b845 commit 325c30b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
25 changes: 21 additions & 4 deletions tty/pc-tty/ttypc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <libklog.h>
#include <posix/utils.h>
#include <phoenix/fbcon.h>

#include "ttypc.h"
#include "ttypc_bioskbd.h"
Expand Down Expand Up @@ -132,22 +133,38 @@ int main(void)
if ((err = mutexCreate(&ttypc_common.lock)) < 0)
return err;

/* Initialize VGA display */
err = ttypc_vga_init(&ttypc_common);
if (err < 0) {
return err;
}

/* Initialize VTs */
for (i = 0; i < NVTS; i++) {
if ((err = ttypc_vt_init(&ttypc_common, _PAGE_SIZE, ttypc_common.vts + i)) < 0)
return err;
}

/* Initialize VGA display */
if ((err = ttypc_vga_init(&ttypc_common)) < 0)
return err;
/* Enable fbcon in VTs if available */
if ((ttypc_common.fbcols != -1) && (ttypc_common.fbrows != -1)) {
for (i = 0; i < NVTS; i++) {
ttypc_common.vts[i].fbmode = FBCON_ENABLED;
}
}

/* Set active virtual terminal */
ttypc_common.vt = ttypc_common.vts;
ttypc_common.vt->vram = ttypc_common.vga;

/* Initialize cursor */
_ttypc_vga_getcursor(ttypc_common.vt);
if (ttypc_common.vt->fbmode == FBCON_UNSUPPORTED) {
/* If fbcon is unsupported, retrieve the cursor so we don't overwrite the tty as
* some earlier component might have written something to the text mode buffer (i.e. plo) */
_ttypc_vga_getcursor(ttypc_common.vt);
}
/* else: In case of fbcon, we don't care about the text mode buffer, because we're
* in the graphic mode already and the text mode buffer may contain garbage */

/* Set default cursor color */
_ttypc_vga_set(ttypc_common.vt, ttypc_common.vt->vram + ttypc_common.vt->cpos, FG_LIGHTGREY << 8, ttypc_common.vt->rows * ttypc_common.vt->cols - ttypc_common.vt->cpos);

Expand Down
5 changes: 3 additions & 2 deletions tty/pc-tty/ttypc_fbcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "ttypc_fbfont.h"
#include <sys/platform.h>
#include <phoenix/arch/ia32/ia32.h>
#include <phoenix/fbcon.h>


typedef struct {
Expand Down Expand Up @@ -108,8 +109,8 @@ void _ttypc_fbcon_drawChar(ttypc_vt_t *vt, uint16_t col, uint16_t row, uint16_t
uint8_t *data = ttypc_fbcon_fbfont + (TTYPC_FBFONT_BYTES_PER_GLYPH * c);
uint16_t x = col * TTYPC_FBFONT_W, y = row * TTYPC_FBFONT_H;

if (vt->ttypc->vt != vt || vt->ttypc->fbaddr == NULL) {
/* this vt is not a current vt or the fbcon is unavailable, don't draw anything */
if ((vt->ttypc->vt != vt) || (vt->fbmode != FBCON_ENABLED)) {
/* if this vt is not the current vt or the fbcon is disabled/unsupported, don't draw anything */
return;
}

Expand Down
7 changes: 3 additions & 4 deletions tty/pc-tty/ttypc_vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,15 @@ int ttypc_vga_init(ttypc_t *ttypc)
ttypc->color = inb((void *)GN_MISCOUTR) & 0x01;
ttypc->crtc = (ttypc->color) ? (void *)CRTC_COLOR : (void *)CRTC_MONO;

ttypc->fbcols = -1;
ttypc->fbrows = -1;

if (ttypc_fbcon_init(ttypc) < 0) {
/* Map video memory */
ttypc->vga = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PHYSMEM | MAP_ANONYMOUS, -1, (ttypc->color) ? VGA_COLOR : VGA_MONO);
if (ttypc->vga == MAP_FAILED) {
return -ENOMEM;
}

ttypc->fbaddr = NULL;
ttypc->fbcols = -1;
ttypc->fbrows = -1;
}
else {
/* Map general purpose memory, not video memory. If fbcon is present, then we're
Expand Down
29 changes: 28 additions & 1 deletion tty/pc-tty/ttypc_vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <sys/mman.h>
#include <sys/threads.h>

#include <phoenix/fbcon.h>

#include "ttypc_vga.h"
#include "ttypc_fbcon.h"
#include "ttypc_vt.h"
Expand Down Expand Up @@ -649,7 +651,30 @@ int ttypc_vt_pollstatus(ttypc_vt_t *vt)

int ttypc_vt_ioctl(ttypc_vt_t *vt, pid_t pid, unsigned int cmd, const void *idata, const void **odata)
{
return libtty_ioctl(&vt->tty, pid, cmd, idata, odata);
int mode;
int ret = EOK;

switch (cmd) {
case FBCONSETMODE:
if (vt->fbmode == FBCON_UNSUPPORTED) {
ret = -ENODEV;
break;
}
mode = (int)idata;
if ((mode != FBCON_ENABLED) && (mode != FBCON_DISABLED)) {
ret = -EINVAL;
break;
}
vt->fbmode = mode;
break;
case FBCONGETMODE:
*odata = (const void *)&vt->fbmode;
break;
default:
ret = libtty_ioctl(&vt->tty, pid, cmd, idata, odata);
break;
}
return ret;
}


Expand Down Expand Up @@ -734,6 +759,8 @@ int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt)
return err;
}

vt->fbmode = FBCON_UNSUPPORTED;

/* Disable default libtty tab expansion */
vt->tty.term.c_oflag &= ~(XTABS);

Expand Down
2 changes: 2 additions & 0 deletions tty/pc-tty/ttypc_vt.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ typedef struct {
char tabs[MAXTABS]; /* Table of active tab stops */
libtty_common_t tty; /* Terminal character processing (using libtty) */

uint8_t fbmode; /* Framebuffer mode: (i.e. enabled, disabled, unsupported) */

/* Synchronization */
handle_t lock; /* Access lock */
} ttypc_vt_t;
Expand Down

0 comments on commit 325c30b

Please sign in to comment.