From c8fb3ba8adb89ace5c0f5d62ee52db1bbfc2398c Mon Sep 17 00:00:00 2001 From: Adam Greloch Date: Fri, 4 Oct 2024 14:35:48 +0200 Subject: [PATCH] pc-tty: resize current vt to max fbcon resolution Current vt will now automatically resize from 80x25 to the maximum resolution supported by current graphic mode if fbcon is enabled (i.e. for 1280x800 and 8x16 font it will resize to 160x50) JIRA: RTOS-925 --- tty/pc-tty/ttypc.c | 9 +++++++-- tty/pc-tty/ttypc.h | 5 +++-- tty/pc-tty/ttypc_fbcon.c | 5 ++--- tty/pc-tty/ttypc_vga.c | 24 +++++++++++++++--------- tty/pc-tty/ttypc_vt.c | 31 ++++++++++++++++++++++--------- tty/pc-tty/ttypc_vt.h | 5 +++++ 6 files changed, 54 insertions(+), 25 deletions(-) diff --git a/tty/pc-tty/ttypc.c b/tty/pc-tty/ttypc.c index 6104f393..1d355801 100644 --- a/tty/pc-tty/ttypc.c +++ b/tty/pc-tty/ttypc.c @@ -139,12 +139,12 @@ int main(void) /* Initialize VTs */ for (i = 0; i < NVTS; i++) { - if ((err = ttypc_vt_init(&ttypc_common, _PAGE_SIZE, ttypc_common.vts + i)) < 0) + if ((err = ttypc_vt_init(&ttypc_common, ttypc_common.memsz, ttypc_common.vts + i)) < 0) return err; } /* Enable fbcon in VTs if available */ - if (ttypc_common.fbcols != -1 && ttypc_common.fbrows != -1) { + if (ttypc_common.fbmaxcols != -1 && ttypc_common.fbmaxrows != -1) { for (i = 0; i < NVTS; i++) { ttypc_common.vts[i].fbmode = FBCON_ENABLED; } @@ -154,6 +154,11 @@ int main(void) ttypc_common.vt = ttypc_common.vts; ttypc_common.vt->vram = ttypc_common.vga; + if (ttypc_common.vt->fbmode == FBCON_ENABLED) { + /* Resize active virtual terminal to match fbcon maximum resolution */ + ttypc_vt_resize(ttypc_common.vt, ttypc_common.fbmaxcols, ttypc_common.fbmaxrows); + } + /* Initialize cursor */ if (ttypc_common.vt->fbmode == FBCON_UNSUPPORTED) { /* If fbcon is unsupported, retrieve the cursor so we don't overwrite the tty as diff --git a/tty/pc-tty/ttypc.h b/tty/pc-tty/ttypc.h index 05228e45..e1eb030d 100644 --- a/tty/pc-tty/ttypc.h +++ b/tty/pc-tty/ttypc.h @@ -50,6 +50,7 @@ struct _ttypc_t { /* VGA */ volatile void *vga; /* VGA screen memory */ + uint32_t memsz; /* VGA screen memory size */ void *crtc; /* Video Display Controller (CRTC) */ unsigned color; /* Color support */ @@ -77,8 +78,8 @@ struct _ttypc_t { /* Framebuffer console */ uint16_t fbw; /* Width in pixels */ uint16_t fbh; /* Height in pixels */ - int16_t fbcols; /* Console columns count */ - int16_t fbrows; /* Console rows count */ + int16_t fbmaxcols; /* Maximum console columns count */ + int16_t fbmaxrows; /* Maximum console rows count */ uint16_t fbbpp; /* Bits per pixel */ uint16_t fbpitch; /* Pitch (framebuffer line length)*/ volatile void *fbaddr; /* Framebuffer address */ diff --git a/tty/pc-tty/ttypc_fbcon.c b/tty/pc-tty/ttypc_fbcon.c index 67405434..2fecfd0b 100644 --- a/tty/pc-tty/ttypc_fbcon.c +++ b/tty/pc-tty/ttypc_fbcon.c @@ -150,9 +150,8 @@ int ttypc_fbcon_init(ttypc_t *ttypc) ttypc->fbbpp = pctl.graphmode.bpp; ttypc->fbpitch = pctl.graphmode.pitch; - /* TODO use fbcols, fbrows to operate in higher resolutions than 80x25 in tty/vt */ - ttypc->fbcols = ttypc->fbw / TTYPC_FBFONT_W; - ttypc->fbrows = ttypc->fbh / TTYPC_FBFONT_H; + ttypc->fbmaxcols = ttypc->fbw / TTYPC_FBFONT_W; + ttypc->fbmaxrows = ttypc->fbh / TTYPC_FBFONT_H; return EOK; } diff --git a/tty/pc-tty/ttypc_vga.c b/tty/pc-tty/ttypc_vga.c index b3ba0a7f..ba56ce10 100644 --- a/tty/pc-tty/ttypc_vga.c +++ b/tty/pc-tty/ttypc_vga.c @@ -20,6 +20,8 @@ #include #include +#include + #include "ttypc.h" #include "ttypc_fbcon.h" #include "ttypc_vga.h" @@ -185,6 +187,11 @@ void _ttypc_vga_switch(ttypc_vt_t *vt) /* Set active VT, do it before writes to unlock access to the fb */ ttypc->vt = vt; + if (vt->fbmode != FBCON_UNSUPPORTED) { + /* Resize the virtual terminal to match fbcon maximum resolution */ + ttypc_vt_resize(vt, vt->ttypc->fbmaxcols, vt->ttypc->fbmaxrows); + } + mutexLock(vt->lock); /* VT memory -> VGA memory */ vt->vram = ttypc->vga; @@ -200,7 +207,7 @@ void _ttypc_vga_switch(ttypc_vt_t *vt) /* Returns scrollback capacity in lines */ static unsigned int _ttypc_vga_scrollbackcapacity(ttypc_vt_t *vt) { - return (SCRB_PAGES * (vt->cols * vt->rows + _PAGE_SIZE - 1) & ~(_PAGE_SIZE - 1)) / (vt->cols * CHR_VGA); + return (SCRB_PAGES * vt->buffsz) / (vt->cols * CHR_VGA); } @@ -356,24 +363,23 @@ void _ttypc_vga_togglecursor(ttypc_vt_t *vt, uint8_t state) void ttypc_vga_destroy(ttypc_t *ttypc) { ttypc_fbcon_destroy(ttypc); - munmap((void *)ttypc->vga, _PAGE_SIZE); + munmap((void *)ttypc->vga, ttypc->memsz); } int ttypc_vga_init(ttypc_t *ttypc) { - int memsz; - /* Test monitor type */ ttypc->color = inb((void *)GN_MISCOUTR) & 0x01; ttypc->crtc = (ttypc->color) ? (void *)CRTC_COLOR : (void *)CRTC_MONO; - ttypc->fbcols = -1; - ttypc->fbrows = -1; + ttypc->fbmaxcols = -1; + ttypc->fbmaxrows = -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); + ttypc->memsz = _PAGE_SIZE; + ttypc->vga = mmap(NULL, ttypc->memsz, PROT_READ | PROT_WRITE, MAP_PHYSMEM | MAP_ANONYMOUS, -1, (ttypc->color) ? VGA_COLOR : VGA_MONO); if (ttypc->vga == MAP_FAILED) return -ENOMEM; } @@ -381,8 +387,8 @@ int ttypc_vga_init(ttypc_t *ttypc) /* Map general purpose memory, not video memory. If fbcon is present, then we're * in graphics mode already, so the standard VGA_MONO/VGA_COLOR framebuffers can * be inactive and contain garbage. */ - memsz = (ttypc->fbcols * ttypc->fbrows + _PAGE_SIZE - 1) & ~(_PAGE_SIZE - 1); - ttypc->vga = mmap(NULL, memsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + ttypc->memsz = (ttypc->fbmaxcols * ttypc->fbmaxrows * CHR_VGA + _PAGE_SIZE - 1) & ~(_PAGE_SIZE - 1); + ttypc->vga = mmap(NULL, ttypc->memsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ttypc->vga == MAP_FAILED) { ttypc_fbcon_destroy(ttypc); return -ENOMEM; diff --git a/tty/pc-tty/ttypc_vt.c b/tty/pc-tty/ttypc_vt.c index 31760e22..050ae5b0 100644 --- a/tty/pc-tty/ttypc_vt.c +++ b/tty/pc-tty/ttypc_vt.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -713,6 +714,18 @@ static void _ttypc_vt_signaltxready(void *arg) } +void ttypc_vt_resize(ttypc_vt_t *vt, uint8_t cols, uint8_t rows) +{ + vt->tty.ws.ws_col = cols; + vt->tty.ws.ws_row = rows; + libtty_signal_pgrp(&vt->tty, SIGWINCH); + + vt->cols = cols; + vt->rows = rows; + _ttypc_vtf_str(vt); +} + + int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt) { libtty_callbacks_t cb = { @@ -726,7 +739,7 @@ int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt) if ((err = mutexCreate(&vt->lock)) < 0) return err; - vt->mem = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + vt->mem = mmap(NULL, ttybuffsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (vt->mem == MAP_FAILED) { resourceDestroy(vt->lock); return -ENOMEM; @@ -734,27 +747,27 @@ int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt) vt->vram = vt->mem; if (SCRB_PAGES) { - vt->scro = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + vt->scro = mmap(NULL, ttybuffsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (vt->scro == MAP_FAILED) { resourceDestroy(vt->lock); - munmap(vt->mem, _PAGE_SIZE); + munmap(vt->mem, ttybuffsz); return -ENOMEM; } - vt->scrb = mmap(NULL, SCRB_PAGES * _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + vt->scrb = mmap(NULL, SCRB_PAGES * ttybuffsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (vt->scrb == MAP_FAILED) { resourceDestroy(vt->lock); - munmap(vt->mem, _PAGE_SIZE); - munmap(vt->scro, _PAGE_SIZE); + munmap(vt->mem, ttybuffsz); + munmap(vt->scro, ttybuffsz); return -ENOMEM; } } if ((err = libtty_init(&vt->tty, &cb, ttybuffsz, TTYDEF_SPEED)) < 0) { resourceDestroy(vt->lock); - munmap(vt->mem, _PAGE_SIZE); + munmap(vt->mem, ttybuffsz); if (SCRB_PAGES) { - munmap(vt->scro, _PAGE_SIZE); - munmap(vt->scrb, SCRB_PAGES * _PAGE_SIZE); + munmap(vt->scro, ttybuffsz); + munmap(vt->scrb, SCRB_PAGES * ttybuffsz); } return err; } diff --git a/tty/pc-tty/ttypc_vt.h b/tty/pc-tty/ttypc_vt.h index b68c44df..ec4d6837 100644 --- a/tty/pc-tty/ttypc_vt.h +++ b/tty/pc-tty/ttypc_vt.h @@ -130,6 +130,7 @@ typedef struct { libtty_common_t tty; /* Terminal character processing (using libtty) */ uint8_t fbmode; /* Framebuffer mode: (i.e. enabled, disabled, unsupported) */ + uint32_t buffsz; /* Virtual terminal buffer size */ /* Synchronization */ handle_t lock; /* Access lock */ @@ -160,6 +161,10 @@ extern int ttypc_vt_pollstatus(ttypc_vt_t *vt); extern int ttypc_vt_ioctl(ttypc_vt_t *vt, pid_t pid, unsigned int cmd, const void *idata, const void **odata); +/* Resizes virtual terminal */ +extern void ttypc_vt_resize(ttypc_vt_t *vt, uint8_t cols, uint8_t rows); + + /* Destroys virtual terminal */ extern void ttypc_vt_destroy(ttypc_vt_t *vt);