Skip to content

Commit

Permalink
pc-tty: resize current vt to max fbcon resolution
Browse files Browse the repository at this point in the history
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
  • Loading branch information
adamgreloch committed Oct 21, 2024
1 parent 6d4398b commit c8fb3ba
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 25 deletions.
9 changes: 7 additions & 2 deletions tty/pc-tty/ttypc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tty/pc-tty/ttypc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */
Expand Down
5 changes: 2 additions & 3 deletions tty/pc-tty/ttypc_fbcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 15 additions & 9 deletions tty/pc-tty/ttypc_vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <sys/mman.h>
#include <sys/threads.h>

#include <phoenix/fbcon.h>

#include "ttypc.h"
#include "ttypc_fbcon.h"
#include "ttypc_vga.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}


Expand Down Expand Up @@ -356,33 +363,32 @@ 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;
}
else {
/* 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;
Expand Down
31 changes: 22 additions & 9 deletions tty/pc-tty/ttypc_vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>

#include <sys/mman.h>
#include <sys/threads.h>
Expand Down Expand Up @@ -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 = {
Expand All @@ -726,35 +739,35 @@ 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;
}
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;
}
Expand Down
5 changes: 5 additions & 0 deletions tty/pc-tty/ttypc_vt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c8fb3ba

Please sign in to comment.