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)
 
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 18 of file fbcon.h.

◆ FBCON_BOLD

#define FBCON_BOLD   0x555555

Bold colour modifier (RGB value)

Definition at line 21 of file fbcon.h.

◆ FBCON_TRANSPARENT

#define FBCON_TRANSPARENT   0xffffffff

Transparent background magic colour (raw colour value)

Definition at line 24 of file fbcon.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 600 of file fbcon.c.

604  {
605  int width;
606  int height;
607  unsigned int xgap;
608  unsigned int ygap;
609  unsigned int left;
610  unsigned int right;
611  unsigned int top;
612  unsigned int bottom;
613  int rc;
614 
615  /* Initialise data structure */
616  memset ( fbcon, 0, sizeof ( *fbcon ) );
617  fbcon->start = start;
618  fbcon->pixel = pixel;
619  assert ( pixel->len <= sizeof ( uint32_t ) );
620  fbcon->map = map;
621  fbcon->font = font;
623  fbcon->show_cursor = 1;
624 
625  /* Derive overall length */
626  fbcon->len = ( pixel->height * pixel->stride );
627  DBGC ( fbcon, "FBCON %p at [%08lx,%08lx)\n", fbcon,
628  virt_to_phys ( fbcon->start ),
629  ( virt_to_phys ( fbcon->start ) + fbcon->len ) );
630 
631  /* Calculate margin. If the actual screen size is larger than
632  * the requested screen size, then update the margins so that
633  * the margin remains relative to the requested screen size.
634  * (As an exception, if a zero margin was specified then treat
635  * this as meaning "expand to edge of actual screen".)
636  */
637  xgap = ( pixel->width - config->width );
638  ygap = ( pixel->height - config->height );
639  left = ( xgap / 2 );
640  right = ( xgap - left );
641  top = ( ygap / 2 );
642  bottom = ( ygap - top );
643  fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) );
644  fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) );
645  fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) );
646  fbcon->margin.bottom =
647  ( config->bottom + ( config->bottom ? bottom : 0 ) );
648 
649  /* Expand margin to accommodate whole characters */
650  width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
651  height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
652  if ( ( width < FBCON_CHAR_WIDTH ) ||
653  ( height < ( ( int ) font->height ) ) ) {
654  DBGC ( fbcon, "FBCON %p has unusable character area "
655  "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
656  ( pixel->width - fbcon->margin.right ),
657  fbcon->margin.top,
658  ( pixel->height - fbcon->margin.bottom ) );
659  rc = -EINVAL;
660  goto err_margin;
661  }
662  xgap = ( width % FBCON_CHAR_WIDTH );
663  ygap = ( height % font->height );
664  fbcon->margin.left += ( xgap / 2 );
665  fbcon->margin.top += ( ygap / 2 );
666  fbcon->margin.right += ( xgap - ( xgap / 2 ) );
667  fbcon->margin.bottom += ( ygap - ( ygap / 2 ) );
668  fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
669  ( fbcon->margin.left * pixel->len ) );
670 
671  /* Derive character geometry from pixel geometry */
672  fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
673  fbcon->character.height = ( height / font->height );
674  fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
675  fbcon->character.stride = ( pixel->stride * font->height );
676  DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
677  "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
680  ( fbcon->pixel->width - fbcon->margin.right ),
681  fbcon->margin.top,
682  ( fbcon->pixel->height - fbcon->margin.bottom ) );
683 
684  /* Set default colours */
687 
688  /* Allocate and initialise stored character array */
691  sizeof ( fbcon->text.cells[0] ) );
692  if ( ! fbcon->text.cells ) {
693  rc = -ENOMEM;
694  goto err_text;
695  }
696  fbcon_clear ( fbcon, 0 );
697 
698  /* Set framebuffer to all black (including margins) */
699  memset ( fbcon->start, 0, fbcon->len );
700 
701  /* Generate pixel buffer from background image, if applicable */
702  if ( config->pixbuf &&
703  ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
704  goto err_picture;
705 
706  /* Draw background picture (including margins), if applicable */
707  if ( fbcon->picture.start )
709 
710  /* Update console width and height */
712 
713  return 0;
714 
715  ufree ( fbcon->picture.start );
716  err_picture:
717  ufree ( fbcon->text.cells );
718  err_text:
719  err_margin:
720  return rc;
721 }
static void console_set_size(unsigned int width, unsigned int height)
Set console size.
Definition: console.h:201
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
unsigned int height
Character height (in pixels)
Definition: fbcon.h:35
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct ansiesc_handler fbcon_ansiesc_handlers[]
ANSI escape sequence handlers.
Definition: fbcon.c:445
struct ansiesc_handler * handlers
Array of handlers.
Definition: ansiesc.h:79
unsigned int height
Height.
Definition: console.h:28
unsigned int bottom
Bottom margin.
Definition: fbcon.h:70
struct fbcon_font * font
Font definition.
Definition: fbcon.h:128
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:52
struct fbcon_geometry character
Character geometry.
Definition: fbcon.h:120
#define DBGC(...)
Definition: compiler.h:505
struct ansiesc_context ctx
ANSI escape sequence context.
Definition: fbcon.h:140
void * start
Start address.
Definition: fbcon.h:108
unsigned int width
Width.
Definition: console.h:26
static void fbcon_clear(struct fbcon *fbcon, unsigned int ypos)
Clear rows of characters.
Definition: fbcon.c:129
struct fbcon_geometry * pixel
Pixel geometry.
Definition: fbcon.h:118
unsigned int left
Left margin.
Definition: fbcon.h:64
uint32_t start
Starting offset.
Definition: netvsc.h:12
unsigned int bottom
Bottom margin.
Definition: console.h:38
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t len
Length of a single entity.
Definition: fbcon.h:56
A frame buffer console.
Definition: fbcon.h:112
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:100
unsigned int top
Top margin.
Definition: fbcon.h:68
struct fbcon_margin margin
Margin.
Definition: fbcon.h:122
unsigned int right
Right margin.
Definition: console.h:34
unsigned int uint32_t
Definition: stdint.h:12
#define FBCON_CHAR_WIDTH
Character width, in pixels.
Definition: fbcon.h:18
static int fbcon_picture_init(struct fbcon *fbcon, struct pixel_buffer *pixbuf)
Initialise background picture.
Definition: fbcon.c:525
struct fbcon_text_cell * cells
Stored text cells.
Definition: fbcon.h:102
struct fbcon_text text
Text array.
Definition: fbcon.h:144
size_t len
Length of one complete displayed screen.
Definition: fbcon.h:116
static __always_inline int struct dma_mapping * map
Definition: dma.h:183
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:54
struct pixel_buffer * pixbuf
Background picture, if any.
Definition: console.h:40
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:56
unsigned int top
Top margin.
Definition: console.h:36
unsigned int right
Right margin.
Definition: fbcon.h:66
void * start
Start address.
Definition: fbcon.h:114
struct fbcon_picture picture
Background picture.
Definition: fbcon.h:146
size_t indent
Indent to first character (in bytes)
Definition: fbcon.h:124
struct fbcon_colour_map * map
Colour mapping.
Definition: fbcon.h:126
int show_cursor
Display cursor.
Definition: fbcon.h:148
static void fbcon_set_default_foreground(struct fbcon *fbcon)
Set default foreground colour.
Definition: fbcon.c:88
size_t stride
Stride (offset between vertically adjacent entities)
Definition: fbcon.h:58
unsigned int left
Left margin.
Definition: console.h:32
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 728 of file fbcon.c.

728  {
729 
730  ufree ( fbcon->text.cells );
731  ufree ( fbcon->picture.start );
732 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
void * start
Start address.
Definition: fbcon.h:108
A frame buffer console.
Definition: fbcon.h:112
struct fbcon_text_cell * cells
Stored text cells.
Definition: fbcon.h:102
struct fbcon_text text
Text array.
Definition: fbcon.h:144
struct fbcon_picture picture
Background picture.
Definition: fbcon.h:146

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 460 of file fbcon.c.

460  {
461  struct fbcon_text_cell *cell;
462 
463  /* Intercept ANSI escape sequences */
465  if ( character < 0 )
466  return;
467 
468  /* Accumulate Unicode characters */
470  if ( character == 0 )
471  return;
472 
473  /* Handle control characters */
474  switch ( character ) {
475  case '\r':
476  fbcon_draw_cursor ( fbcon, 0 );
477  fbcon->xpos = 0;
478  break;
479  case '\n':
480  fbcon_draw_cursor ( fbcon, 0 );
481  fbcon->xpos = 0;
482  fbcon->ypos++;
483  break;
484  case '\b':
485  fbcon_draw_cursor ( fbcon, 0 );
486  if ( fbcon->xpos ) {
487  fbcon->xpos--;
488  } else if ( fbcon->ypos ) {
489  fbcon->xpos = ( fbcon->character.width - 1 );
490  fbcon->ypos--;
491  }
492  break;
493  default:
494  /* Print character at current cursor position */
495  cell = fbcon_cell ( fbcon, fbcon->xpos, fbcon->ypos );
496  cell->foreground = ( fbcon->foreground | fbcon->bold );
497  cell->background = fbcon->background;
498  cell->character = character;
499  fbcon_draw ( fbcon, cell, fbcon->xpos, fbcon->ypos );
500 
501  /* Advance cursor */
502  fbcon->xpos++;
503  if ( fbcon->xpos >= fbcon->character.width ) {
504  fbcon->xpos = 0;
505  fbcon->ypos++;
506  }
507  break;
508  }
509 
510  /* Scroll screen if necessary */
511  if ( fbcon->ypos >= fbcon->character.height )
512  fbcon_scroll ( fbcon );
513 
514  /* Show cursor */
516 }
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:153
unsigned int ypos
Text cursor Y position.
Definition: fbcon.h:138
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:52
static void fbcon_draw_cursor(struct fbcon *fbcon, int show_cursor)
Draw character at cursor position.
Definition: fbcon.c:285
struct fbcon_geometry character
Character geometry.
Definition: fbcon.h:120
struct ansiesc_context ctx
ANSI escape sequence context.
Definition: fbcon.h:140
A frame buffer text cell.
Definition: fbcon.h:90
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition: ansiesc.c:74
static void fbcon_scroll(struct fbcon *fbcon)
Scroll screen.
Definition: fbcon.c:236
uint32_t background
Background colour.
Definition: fbcon.h:94
uint32_t foreground
Text foreground raw colour.
Definition: fbcon.h:130
A frame buffer console.
Definition: fbcon.h:112
unsigned int character
Unicode character.
Definition: fbcon.h:96
uint32_t foreground
Foreground colour.
Definition: fbcon.h:92
unsigned int xpos
Text cursor X position.
Definition: fbcon.h:136
static struct fbcon_text_cell * fbcon_cell(struct fbcon *fbcon, unsigned int xpos, unsigned int ypos)
Get character cell.
Definition: fbcon.c:114
uint32_t background
Text background raw colour.
Definition: fbcon.h:132
struct utf8_accumulator utf8
UTF-8 accumulator.
Definition: fbcon.h:142
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:54
unsigned int utf8_accumulate(struct utf8_accumulator *utf8, uint8_t byte)
Accumulate Unicode character from UTF-8 byte sequence.
Definition: utf8.c:43
uint32_t bold
Bold colour modifier raw colour.
Definition: fbcon.h:134
int show_cursor
Display cursor.
Definition: fbcon.h:148

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__