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/uaccess.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, userptr_t 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  )

◆ fbcon_init()

int fbcon_init ( struct fbcon fbcon,
userptr_t  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 588 of file fbcon.c.

592  {
593  int width;
594  int height;
595  unsigned int xgap;
596  unsigned int ygap;
597  unsigned int left;
598  unsigned int right;
599  unsigned int top;
600  unsigned int bottom;
601  int rc;
602 
603  /* Initialise data structure */
604  memset ( fbcon, 0, sizeof ( *fbcon ) );
605  fbcon->start = start;
606  fbcon->pixel = pixel;
607  assert ( pixel->len <= sizeof ( uint32_t ) );
608  fbcon->map = map;
609  fbcon->font = font;
611  fbcon->show_cursor = 1;
612 
613  /* Derive overall length */
614  fbcon->len = ( pixel->height * pixel->stride );
615  DBGC ( fbcon, "FBCON %p at [%08lx,%08lx)\n", fbcon,
616  user_to_phys ( fbcon->start, 0 ),
617  user_to_phys ( fbcon->start, fbcon->len ) );
618 
619  /* Calculate margin. If the actual screen size is larger than
620  * the requested screen size, then update the margins so that
621  * the margin remains relative to the requested screen size.
622  * (As an exception, if a zero margin was specified then treat
623  * this as meaning "expand to edge of actual screen".)
624  */
625  xgap = ( pixel->width - config->width );
626  ygap = ( pixel->height - config->height );
627  left = ( xgap / 2 );
628  right = ( xgap - left );
629  top = ( ygap / 2 );
630  bottom = ( ygap - top );
631  fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) );
632  fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) );
633  fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) );
634  fbcon->margin.bottom =
635  ( config->bottom + ( config->bottom ? bottom : 0 ) );
636 
637  /* Expand margin to accommodate whole characters */
638  width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
639  height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
640  if ( ( width < FBCON_CHAR_WIDTH ) ||
641  ( height < ( ( int ) font->height ) ) ) {
642  DBGC ( fbcon, "FBCON %p has unusable character area "
643  "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
644  ( pixel->width - fbcon->margin.right ),
645  fbcon->margin.top,
646  ( pixel->height - fbcon->margin.bottom ) );
647  rc = -EINVAL;
648  goto err_margin;
649  }
650  xgap = ( width % FBCON_CHAR_WIDTH );
651  ygap = ( height % font->height );
652  fbcon->margin.left += ( xgap / 2 );
653  fbcon->margin.top += ( ygap / 2 );
654  fbcon->margin.right += ( xgap - ( xgap / 2 ) );
655  fbcon->margin.bottom += ( ygap - ( ygap / 2 ) );
656  fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
657  ( fbcon->margin.left * pixel->len ) );
658 
659  /* Derive character geometry from pixel geometry */
660  fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
661  fbcon->character.height = ( height / font->height );
662  fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
663  fbcon->character.stride = ( pixel->stride * font->height );
664  DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
665  "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
668  ( fbcon->pixel->width - fbcon->margin.right ),
669  fbcon->margin.top,
670  ( fbcon->pixel->height - fbcon->margin.bottom ) );
671 
672  /* Set default colours */
675 
676  /* Allocate and initialise stored character array */
679  sizeof ( struct fbcon_text_cell ) );
680  if ( ! fbcon->text.start ) {
681  rc = -ENOMEM;
682  goto err_text;
683  }
684  fbcon_clear ( fbcon, 0 );
685 
686  /* Set framebuffer to all black (including margins) */
687  memset_user ( fbcon->start, 0, 0, fbcon->len );
688 
689  /* Generate pixel buffer from background image, if applicable */
690  if ( config->pixbuf &&
691  ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
692  goto err_picture;
693 
694  /* Draw background picture (including margins), if applicable */
695  if ( fbcon->picture.start ) {
697  fbcon->len );
698  }
699 
700  /* Update console width and height */
702 
703  return 0;
704 
705  ufree ( fbcon->picture.start );
706  err_picture:
707  ufree ( fbcon->text.start );
708  err_text:
709  err_margin:
710  return rc;
711 }
static void console_set_size(unsigned int width, unsigned int height)
Set console size.
Definition: console.h:201
unsigned int height
Character height (in pixels)
Definition: fbcon.h:36
#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:426
struct ansiesc_handler * handlers
Array of handlers.
Definition: ansiesc.h:79
unsigned int height
Height.
Definition: console.h:28
userptr_t start
Start address.
Definition: fbcon.h:109
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
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
#define DBGC(...)
Definition: compiler.h:505
struct ansiesc_context ctx
ANSI escape sequence context.
Definition: fbcon.h:141
A frame buffer text cell.
Definition: fbcon.h:91
unsigned int width
Width.
Definition: console.h:26
static userptr_t bottom
Bottom of heap (current lowest allocated block)
static void fbcon_clear(struct fbcon *fbcon, unsigned int ypos)
Clear rows of characters.
Definition: fbcon.c:111
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:38
void memset_user(userptr_t userptr, off_t offset, int c, size_t len)
Fill user buffer with a constant byte.
#define ENOMEM
Not enough space.
Definition: errno.h:534
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:99
unsigned int top
Top margin.
Definition: fbcon.h:69
userptr_t start
Stored text cells.
Definition: fbcon.h:103
static userptr_t top
Top of heap.
struct fbcon_margin margin
Margin.
Definition: fbcon.h:123
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
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:19
static int fbcon_picture_init(struct fbcon *fbcon, struct pixel_buffer *pixbuf)
Initialise background picture.
Definition: fbcon.c:506
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 void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
static __always_inline userptr_t umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:54
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:40
unsigned int top
Top margin.
Definition: console.h:36
unsigned int right
Right margin.
Definition: fbcon.h:67
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
userptr_t start
Start address.
Definition: fbcon.h:115
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:87
size_t stride
Stride (offset between vertically adjacent entities)
Definition: fbcon.h:59
void memcpy_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers.
unsigned int left
Left margin.
Definition: console.h:32
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), console_configuration::bottom, bottom, fbcon_margin::bottom, 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_user(), memset(), memset_user(), fbcon::picture, console_configuration::pixbuf, fbcon::pixel, rc, console_configuration::right, fbcon_margin::right, fbcon::show_cursor, start, fbcon_text::start, fbcon_picture::start, fbcon::start, fbcon_geometry::stride, fbcon::text, console_configuration::top, top, fbcon_margin::top, ufree(), umalloc(), user_to_phys(), 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 718 of file fbcon.c.

718  {
719 
720  ufree ( fbcon->text.start );
721  ufree ( fbcon->picture.start );
722 }
userptr_t start
Start address.
Definition: fbcon.h:109
A frame buffer console.
Definition: fbcon.h:113
userptr_t start
Stored text cells.
Definition: fbcon.h:103
struct fbcon_text text
Text array.
Definition: fbcon.h:145
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
struct fbcon_picture picture
Background picture.
Definition: fbcon.h:147

References fbcon::picture, fbcon_text::start, 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 441 of file fbcon.c.

441  {
442  struct fbcon_text_cell cell;
443 
444  /* Intercept ANSI escape sequences */
446  if ( character < 0 )
447  return;
448 
449  /* Accumulate Unicode characters */
451  if ( character == 0 )
452  return;
453 
454  /* Handle control characters */
455  switch ( character ) {
456  case '\r':
457  fbcon_draw_cursor ( fbcon, 0 );
458  fbcon->xpos = 0;
459  break;
460  case '\n':
461  fbcon_draw_cursor ( fbcon, 0 );
462  fbcon->xpos = 0;
463  fbcon->ypos++;
464  break;
465  case '\b':
466  fbcon_draw_cursor ( fbcon, 0 );
467  if ( fbcon->xpos ) {
468  fbcon->xpos--;
469  } else if ( fbcon->ypos ) {
470  fbcon->xpos = ( fbcon->character.width - 1 );
471  fbcon->ypos--;
472  }
473  break;
474  default:
475  /* Print character at current cursor position */
476  cell.foreground = ( fbcon->foreground | fbcon->bold );
477  cell.background = fbcon->background;
478  cell.character = character;
479  fbcon_store ( fbcon, &cell, fbcon->xpos, fbcon->ypos );
480  fbcon_draw ( fbcon, &cell, fbcon->xpos, fbcon->ypos );
481 
482  /* Advance cursor */
483  fbcon->xpos++;
484  if ( fbcon->xpos >= fbcon->character.width ) {
485  fbcon->xpos = 0;
486  fbcon->ypos++;
487  }
488  break;
489  }
490 
491  /* Scroll screen if necessary */
492  if ( fbcon->ypos >= fbcon->character.height )
493  fbcon_scroll ( fbcon );
494 
495  /* Show cursor */
497 }
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:157
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:267
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:74
static void fbcon_scroll(struct fbcon *fbcon)
Scroll screen.
Definition: fbcon.c:242
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
unsigned int xpos
Text cursor X position.
Definition: fbcon.h:137
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:43
uint32_t bold
Bold colour modifier raw colour.
Definition: fbcon.h:135
static void fbcon_store(struct fbcon *fbcon, struct fbcon_text_cell *cell, unsigned int xpos, unsigned int ypos)
Store character at specified position.
Definition: fbcon.c:139
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_draw(), fbcon_draw_cursor(), fbcon_scroll(), fbcon_store(), 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__