iPXE
Data Structures | Macros | Functions | Variables
fbcon.h File Reference

Frame buffer console. More...

#include <stdint.h>
#include <ipxe/ansiesc.h>
#include <ipxe/utf8.h>
#include <ipxe/console.h>

Go to the source code of this file.

Data Structures

struct  fbcon_font_glyph
 A font glyph. More...
 
struct  fbcon_font
 A font definition. More...
 
struct  fbcon_geometry
 A frame buffer geometry. More...
 
struct  fbcon_margin
 A frame buffer margin. More...
 
struct  fbcon_colour_map
 A frame buffer colour mapping. More...
 
struct  fbcon_text_cell
 A frame buffer text cell. More...
 
struct  fbcon_text
 A frame buffer text array. More...
 
struct  fbcon_picture
 A frame buffer background picture. More...
 
struct  fbcon
 A frame buffer console. More...
 

Macros

#define FBCON_CHAR_WIDTH   9
 Character width, in pixels. More...
 
#define FBCON_BOLD   0x555555
 Bold colour modifier (RGB value) More...
 
#define FBCON_TRANSPARENT   0xffffffff
 Transparent background magic colour (raw colour value) More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
int fbcon_init (struct fbcon *fbcon, void *start, struct fbcon_geometry *pixel, struct fbcon_colour_map *map, struct fbcon_font *font, struct console_configuration *config)
 Initialise frame buffer console. More...
 
void fbcon_fini (struct fbcon *fbcon)
 Finalise frame buffer console. More...
 
void fbcon_putchar (struct fbcon *fbcon, int character)
 Print a character to current cursor position. More...
 

Variables

struct fbcon_font_glyph __attribute__
 

Detailed Description

Frame buffer console.

Definition in file fbcon.h.

Macro Definition Documentation

◆ FBCON_CHAR_WIDTH

#define FBCON_CHAR_WIDTH   9

Character width, in pixels.

Definition at line 19 of file fbcon.h.

◆ FBCON_BOLD

#define FBCON_BOLD   0x555555

Bold colour modifier (RGB value)

Definition at line 22 of file fbcon.h.

◆ FBCON_TRANSPARENT

#define FBCON_TRANSPARENT   0xffffffff

Transparent background magic colour (raw colour value)

Definition at line 25 of file fbcon.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ fbcon_init()

int fbcon_init ( struct fbcon fbcon,
void *  start,
struct fbcon_geometry pixel,
struct fbcon_colour_map map,
struct fbcon_font font,
struct console_configuration config 
)

Initialise frame buffer console.

Parameters
fbconFrame buffer console
startStart address
pixelPixel geometry
mapColour mapping
fontFont definition
configConsole configuration
Return values
rcReturn status code

Definition at line 601 of file fbcon.c.

605  {
606  int width;
607  int height;
608  unsigned int xgap;
609  unsigned int ygap;
610  unsigned int left;
611  unsigned int right;
612  unsigned int top;
613  unsigned int bottom;
614  int rc;
615 
616  /* Initialise data structure */
617  memset ( fbcon, 0, sizeof ( *fbcon ) );
618  fbcon->start = start;
619  fbcon->pixel = pixel;
620  assert ( pixel->len <= sizeof ( uint32_t ) );
621  fbcon->map = map;
622  fbcon->font = font;
624  fbcon->show_cursor = 1;
625 
626  /* Derive overall length */
627  fbcon->len = ( pixel->height * pixel->stride );
628  DBGC ( fbcon, "FBCON %p at [%08lx,%08lx)\n", fbcon,
629  virt_to_phys ( fbcon->start ),
630  ( virt_to_phys ( fbcon->start ) + fbcon->len ) );
631 
632  /* Calculate margin. If the actual screen size is larger than
633  * the requested screen size, then update the margins so that
634  * the margin remains relative to the requested screen size.
635  * (As an exception, if a zero margin was specified then treat
636  * this as meaning "expand to edge of actual screen".)
637  */
638  xgap = ( pixel->width - config->width );
639  ygap = ( pixel->height - config->height );
640  left = ( xgap / 2 );
641  right = ( xgap - left );
642  top = ( ygap / 2 );
643  bottom = ( ygap - top );
644  fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) );
645  fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) );
646  fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) );
647  fbcon->margin.bottom =
648  ( config->bottom + ( config->bottom ? bottom : 0 ) );
649 
650  /* Expand margin to accommodate whole characters */
651  width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
652  height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
653  if ( ( width < FBCON_CHAR_WIDTH ) ||
654  ( height < ( ( int ) font->height ) ) ) {
655  DBGC ( fbcon, "FBCON %p has unusable character area "
656  "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
657  ( pixel->width - fbcon->margin.right ),
658  fbcon->margin.top,
659  ( pixel->height - fbcon->margin.bottom ) );
660  rc = -EINVAL;
661  goto err_margin;
662  }
663  xgap = ( width % FBCON_CHAR_WIDTH );
664  ygap = ( height % font->height );
665  fbcon->margin.left += ( xgap / 2 );
666  fbcon->margin.top += ( ygap / 2 );
667  fbcon->margin.right += ( xgap - ( xgap / 2 ) );
668  fbcon->margin.bottom += ( ygap - ( ygap / 2 ) );
669  fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
670  ( fbcon->margin.left * pixel->len ) );
671 
672  /* Derive character geometry from pixel geometry */
673  fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
674  fbcon->character.height = ( height / font->height );
675  fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
676  fbcon->character.stride = ( pixel->stride * font->height );
677  DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
678  "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
681  ( fbcon->pixel->width - fbcon->margin.right ),
682  fbcon->margin.top,
683  ( fbcon->pixel->height - fbcon->margin.bottom ) );
684 
685  /* Set default colours */
688 
689  /* Allocate and initialise stored character array */
692  sizeof ( fbcon->text.cells[0] ) );
693  if ( ! fbcon->text.cells ) {
694  rc = -ENOMEM;
695  goto err_text;
696  }
697  fbcon_clear ( fbcon, 0 );
698 
699  /* Set framebuffer to all black (including margins) */
700  memset ( fbcon->start, 0, fbcon->len );
701 
702  /* Generate pixel buffer from background image, if applicable */
703  if ( config->pixbuf &&
704  ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
705  goto err_picture;
706 
707  /* Draw background picture (including margins), if applicable */
708  if ( fbcon->picture.start )
710 
711  /* Update console width and height */
713 
714  return 0;
715 
716  ufree ( fbcon->picture.start );
717  err_picture:
718  ufree ( fbcon->text.cells );
719  err_text:
720  err_margin:
721  return rc;
722 }
static void console_set_size(unsigned int width, unsigned int height)
Set console size.
Definition: console.h:202
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:68
unsigned int height
Character height (in pixels)
Definition: fbcon.h:36
#define EINVAL
Invalid argument.
Definition: errno.h:429
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct ansiesc_handler fbcon_ansiesc_handlers[]
ANSI escape sequence handlers.
Definition: fbcon.c:446
struct ansiesc_handler * handlers
Array of handlers.
Definition: ansiesc.h:80
unsigned int height
Height.
Definition: console.h:29
unsigned int bottom
Bottom margin.
Definition: fbcon.h:71
struct fbcon_font * font
Font definition.
Definition: fbcon.h:129
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:53
struct fbcon_geometry character
Character geometry.
Definition: fbcon.h:121
#define DBGC(...)
Definition: compiler.h:505
struct ansiesc_context ctx
ANSI escape sequence context.
Definition: fbcon.h:141
void * start
Start address.
Definition: fbcon.h:109
unsigned int width
Width.
Definition: console.h:27
static void fbcon_clear(struct fbcon *fbcon, unsigned int ypos)
Clear rows of characters.
Definition: fbcon.c:130
struct fbcon_geometry * pixel
Pixel geometry.
Definition: fbcon.h:119
unsigned int left
Left margin.
Definition: fbcon.h:65
uint32_t start
Starting offset.
Definition: netvsc.h:12
unsigned int bottom
Bottom margin.
Definition: console.h:39
#define ENOMEM
Not enough space.
Definition: errno.h:535
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t len
Length of a single entity.
Definition: fbcon.h:57
A frame buffer console.
Definition: fbcon.h:113
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void fbcon_set_default_background(struct fbcon *fbcon)
Set default background colour.
Definition: fbcon.c:101
unsigned int top
Top margin.
Definition: fbcon.h:69
struct fbcon_margin margin
Margin.
Definition: fbcon.h:123
unsigned int right
Right margin.
Definition: console.h:35
unsigned int uint32_t
Definition: stdint.h:12
#define FBCON_CHAR_WIDTH
Character width, in pixels.
Definition: fbcon.h:19
static int fbcon_picture_init(struct fbcon *fbcon, struct pixel_buffer *pixbuf)
Initialise background picture.
Definition: fbcon.c:526
struct fbcon_text_cell * cells
Stored text cells.
Definition: fbcon.h:103
struct fbcon_text text
Text array.
Definition: fbcon.h:145
size_t len
Length of one complete displayed screen.
Definition: fbcon.h:117
static __always_inline int struct dma_mapping * map
Definition: dma.h:184
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:55
struct pixel_buffer * pixbuf
Background picture, if any.
Definition: console.h:41
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:57
unsigned int top
Top margin.
Definition: console.h:37
unsigned int right
Right margin.
Definition: fbcon.h:67
void * start
Start address.
Definition: fbcon.h:115
struct fbcon_picture picture
Background picture.
Definition: fbcon.h:147
size_t indent
Indent to first character (in bytes)
Definition: fbcon.h:125
struct fbcon_colour_map * map
Colour mapping.
Definition: fbcon.h:127
int show_cursor
Display cursor.
Definition: fbcon.h:149
static void fbcon_set_default_foreground(struct fbcon *fbcon)
Set default foreground colour.
Definition: fbcon.c:89
size_t stride
Stride (offset between vertically adjacent entities)
Definition: fbcon.h:59
unsigned int left
Left margin.
Definition: console.h:33
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), console_configuration::bottom, fbcon_margin::bottom, fbcon_text::cells, fbcon::character, console_set_size(), fbcon::ctx, DBGC, EINVAL, ENOMEM, fbcon_ansiesc_handlers, FBCON_CHAR_WIDTH, fbcon_clear(), fbcon_picture_init(), fbcon_set_default_background(), fbcon_set_default_foreground(), fbcon::font, ansiesc_context::handlers, console_configuration::height, fbcon_font::height, fbcon_geometry::height, fbcon::indent, console_configuration::left, fbcon_margin::left, fbcon_geometry::len, fbcon::len, fbcon::map, map, fbcon::margin, memcpy(), memset(), fbcon::picture, console_configuration::pixbuf, fbcon::pixel, rc, console_configuration::right, fbcon_margin::right, fbcon::show_cursor, start, fbcon_picture::start, fbcon::start, fbcon_geometry::stride, fbcon::text, console_configuration::top, fbcon_margin::top, ufree(), umalloc(), console_configuration::width, and fbcon_geometry::width.

Referenced by efifb_init(), and vesafb_init().

◆ fbcon_fini()

void fbcon_fini ( struct fbcon fbcon)

Finalise frame buffer console.

Parameters
fbconFrame buffer console

Definition at line 729 of file fbcon.c.

729  {
730 
731  ufree ( fbcon->text.cells );
732  ufree ( fbcon->picture.start );
733 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:68
void * start
Start address.
Definition: fbcon.h:109
A frame buffer console.
Definition: fbcon.h:113
struct fbcon_text_cell * cells
Stored text cells.
Definition: fbcon.h:103
struct fbcon_text text
Text array.
Definition: fbcon.h:145
struct fbcon_picture picture
Background picture.
Definition: fbcon.h:147

References fbcon_text::cells, fbcon::picture, fbcon_picture::start, fbcon::text, and ufree().

Referenced by efifb_fini(), efifb_init(), vesafb_fini(), and vesafb_init().

◆ fbcon_putchar()

void fbcon_putchar ( struct fbcon fbcon,
int  character 
)

Print a character to current cursor position.

Parameters
fbconFrame buffer console
characterCharacter

Definition at line 461 of file fbcon.c.

461  {
462  struct fbcon_text_cell *cell;
463 
464  /* Intercept ANSI escape sequences */
466  if ( character < 0 )
467  return;
468 
469  /* Accumulate Unicode characters */
471  if ( character == 0 )
472  return;
473 
474  /* Handle control characters */
475  switch ( character ) {
476  case '\r':
477  fbcon_draw_cursor ( fbcon, 0 );
478  fbcon->xpos = 0;
479  break;
480  case '\n':
481  fbcon_draw_cursor ( fbcon, 0 );
482  fbcon->xpos = 0;
483  fbcon->ypos++;
484  break;
485  case '\b':
486  fbcon_draw_cursor ( fbcon, 0 );
487  if ( fbcon->xpos ) {
488  fbcon->xpos--;
489  } else if ( fbcon->ypos ) {
490  fbcon->xpos = ( fbcon->character.width - 1 );
491  fbcon->ypos--;
492  }
493  break;
494  default:
495  /* Print character at current cursor position */
496  cell = fbcon_cell ( fbcon, fbcon->xpos, fbcon->ypos );
497  cell->foreground = ( fbcon->foreground | fbcon->bold );
498  cell->background = fbcon->background;
499  cell->character = character;
500  fbcon_draw ( fbcon, cell, fbcon->xpos, fbcon->ypos );
501 
502  /* Advance cursor */
503  fbcon->xpos++;
504  if ( fbcon->xpos >= fbcon->character.width ) {
505  fbcon->xpos = 0;
506  fbcon->ypos++;
507  }
508  break;
509  }
510 
511  /* Scroll screen if necessary */
512  if ( fbcon->ypos >= fbcon->character.height )
513  fbcon_scroll ( fbcon );
514 
515  /* Show cursor */
517 }
static void fbcon_draw(struct fbcon *fbcon, struct fbcon_text_cell *cell, unsigned int xpos, unsigned int ypos)
Draw character at specified position.
Definition: fbcon.c:154
unsigned int ypos
Text cursor Y position.
Definition: fbcon.h:139
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:53
static void fbcon_draw_cursor(struct fbcon *fbcon, int show_cursor)
Draw character at cursor position.
Definition: fbcon.c:286
struct fbcon_geometry character
Character geometry.
Definition: fbcon.h:121
struct ansiesc_context ctx
ANSI escape sequence context.
Definition: fbcon.h:141
A frame buffer text cell.
Definition: fbcon.h:91
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition: ansiesc.c:75
static void fbcon_scroll(struct fbcon *fbcon)
Scroll screen.
Definition: fbcon.c:237
uint32_t background
Background colour.
Definition: fbcon.h:95
uint32_t foreground
Text foreground raw colour.
Definition: fbcon.h:131
A frame buffer console.
Definition: fbcon.h:113
unsigned int character
Unicode character.
Definition: fbcon.h:97
uint32_t foreground
Foreground colour.
Definition: fbcon.h:93
unsigned int xpos
Text cursor X position.
Definition: fbcon.h:137
static struct fbcon_text_cell * fbcon_cell(struct fbcon *fbcon, unsigned int xpos, unsigned int ypos)
Get character cell.
Definition: fbcon.c:115
uint32_t background
Text background raw colour.
Definition: fbcon.h:133
struct utf8_accumulator utf8
UTF-8 accumulator.
Definition: fbcon.h:143
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:55
unsigned int utf8_accumulate(struct utf8_accumulator *utf8, uint8_t byte)
Accumulate Unicode character from UTF-8 byte sequence.
Definition: utf8.c:44
uint32_t bold
Bold colour modifier raw colour.
Definition: fbcon.h:135
int show_cursor
Display cursor.
Definition: fbcon.h:149

References ansiesc_process(), fbcon_text_cell::background, fbcon::background, fbcon::bold, fbcon_text_cell::character, fbcon::character, fbcon::ctx, fbcon_cell(), fbcon_draw(), fbcon_draw_cursor(), fbcon_scroll(), fbcon_text_cell::foreground, fbcon::foreground, fbcon_geometry::height, fbcon::show_cursor, fbcon::utf8, utf8_accumulate(), fbcon_geometry::width, fbcon::xpos, and fbcon::ypos.

Referenced by efifb_putchar(), and vesafb_putchar().

Variable Documentation

◆ __attribute__