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

Frame buffer console. More...

#include <stdint.h>
#include <ipxe/ansiesc.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 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,
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 583 of file fbcon.c.

587  {
588  int width;
589  int height;
590  unsigned int xgap;
591  unsigned int ygap;
592  unsigned int left;
593  unsigned int right;
594  unsigned int top;
595  unsigned int bottom;
596  int rc;
597 
598  /* Initialise data structure */
599  memset ( fbcon, 0, sizeof ( *fbcon ) );
600  fbcon->start = start;
601  fbcon->pixel = pixel;
602  assert ( pixel->len <= sizeof ( uint32_t ) );
603  fbcon->map = map;
604  fbcon->font = font;
606  fbcon->show_cursor = 1;
607 
608  /* Derive overall length */
609  fbcon->len = ( pixel->height * pixel->stride );
610  DBGC ( fbcon, "FBCON %p at [%08lx,%08lx)\n", fbcon,
611  user_to_phys ( fbcon->start, 0 ),
612  user_to_phys ( fbcon->start, fbcon->len ) );
613 
614  /* Calculate margin. If the actual screen size is larger than
615  * the requested screen size, then update the margins so that
616  * the margin remains relative to the requested screen size.
617  * (As an exception, if a zero margin was specified then treat
618  * this as meaning "expand to edge of actual screen".)
619  */
620  xgap = ( pixel->width - config->width );
621  ygap = ( pixel->height - config->height );
622  left = ( xgap / 2 );
623  right = ( xgap - left );
624  top = ( ygap / 2 );
625  bottom = ( ygap - top );
626  fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) );
627  fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) );
628  fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) );
629  fbcon->margin.bottom =
630  ( config->bottom + ( config->bottom ? bottom : 0 ) );
631 
632  /* Expand margin to accommodate whole characters */
633  width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
634  height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
635  if ( ( width < FBCON_CHAR_WIDTH ) ||
636  ( height < ( ( int ) font->height ) ) ) {
637  DBGC ( fbcon, "FBCON %p has unusable character area "
638  "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
639  ( pixel->width - fbcon->margin.right ),
640  fbcon->margin.top,
641  ( pixel->height - fbcon->margin.bottom ) );
642  rc = -EINVAL;
643  goto err_margin;
644  }
645  xgap = ( width % FBCON_CHAR_WIDTH );
646  ygap = ( height % font->height );
647  fbcon->margin.left += ( xgap / 2 );
648  fbcon->margin.top += ( ygap / 2 );
649  fbcon->margin.right += ( xgap - ( xgap / 2 ) );
650  fbcon->margin.bottom += ( ygap - ( ygap / 2 ) );
651  fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
652  ( fbcon->margin.left * pixel->len ) );
653 
654  /* Derive character geometry from pixel geometry */
655  fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
656  fbcon->character.height = ( height / font->height );
657  fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
658  fbcon->character.stride = ( pixel->stride * font->height );
659  DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
660  "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
663  ( fbcon->pixel->width - fbcon->margin.right ),
664  fbcon->margin.top,
665  ( fbcon->pixel->height - fbcon->margin.bottom ) );
666 
667  /* Set default colours */
670 
671  /* Allocate and initialise stored character array */
674  sizeof ( struct fbcon_text_cell ) );
675  if ( ! fbcon->text.start ) {
676  rc = -ENOMEM;
677  goto err_text;
678  }
679  fbcon_clear ( fbcon, 0 );
680 
681  /* Set framebuffer to all black (including margins) */
682  memset_user ( fbcon->start, 0, 0, fbcon->len );
683 
684  /* Generate pixel buffer from background image, if applicable */
685  if ( config->pixbuf &&
686  ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
687  goto err_picture;
688 
689  /* Draw background picture (including margins), if applicable */
690  if ( fbcon->picture.start ) {
692  fbcon->len );
693  }
694 
695  /* Update console width and height */
697 
698  return 0;
699 
700  ufree ( fbcon->picture.start );
701  err_picture:
702  ufree ( fbcon->text.start );
703  err_text:
704  err_margin:
705  return rc;
706 }
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: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: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:108
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
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:140
A frame buffer text cell.
Definition: fbcon.h:90
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: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
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: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:99
unsigned int top
Top margin.
Definition: fbcon.h:68
userptr_t start
Stored text cells.
Definition: fbcon.h:102
static userptr_t top
Top of heap.
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:501
struct fbcon_text text
Text array.
Definition: fbcon.h:142
size_t len
Length of one complete displayed screen.
Definition: fbcon.h:116
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:54
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:66
struct fbcon_picture picture
Background picture.
Definition: fbcon.h:144
size_t indent
Indent to first character (in bytes)
Definition: fbcon.h:124
struct fbcon_colour_map * map
Colour mapping.
Definition: fbcon.h:126
userptr_t start
Start address.
Definition: fbcon.h:114
int show_cursor
Display cursor.
Definition: fbcon.h:146
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:58
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, 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 713 of file fbcon.c.

713  {
714 
715  ufree ( fbcon->text.start );
716  ufree ( fbcon->picture.start );
717 }
userptr_t start
Start address.
Definition: fbcon.h:108
A frame buffer console.
Definition: fbcon.h:112
userptr_t start
Stored text cells.
Definition: fbcon.h:102
struct fbcon_text text
Text array.
Definition: fbcon.h:142
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
struct fbcon_picture picture
Background picture.
Definition: fbcon.h:144

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  /* Handle control characters */
450  switch ( character ) {
451  case '\r':
452  fbcon_draw_cursor ( fbcon, 0 );
453  fbcon->xpos = 0;
454  break;
455  case '\n':
456  fbcon_draw_cursor ( fbcon, 0 );
457  fbcon->xpos = 0;
458  fbcon->ypos++;
459  break;
460  case '\b':
461  fbcon_draw_cursor ( fbcon, 0 );
462  if ( fbcon->xpos ) {
463  fbcon->xpos--;
464  } else if ( fbcon->ypos ) {
465  fbcon->xpos = ( fbcon->character.width - 1 );
466  fbcon->ypos--;
467  }
468  break;
469  default:
470  /* Print character at current cursor position */
471  cell.foreground = ( fbcon->foreground | fbcon->bold );
472  cell.background = fbcon->background;
473  cell.character = character;
474  fbcon_store ( fbcon, &cell, fbcon->xpos, fbcon->ypos );
475  fbcon_draw ( fbcon, &cell, fbcon->xpos, fbcon->ypos );
476 
477  /* Advance cursor */
478  fbcon->xpos++;
479  if ( fbcon->xpos >= fbcon->character.width ) {
480  fbcon->xpos = 0;
481  fbcon->ypos++;
482  }
483  break;
484  }
485 
486  /* Scroll screen if necessary */
487  if ( fbcon->ypos >= fbcon->character.height )
488  fbcon_scroll ( fbcon );
489 
490  /* Show cursor */
492 }
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: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:267
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:242
uint32_t foreground
Text foreground raw colour.
Definition: fbcon.h:130
A frame buffer console.
Definition: fbcon.h:112
unsigned int character
Character.
Definition: fbcon.h:96
unsigned int xpos
Text cursor X position.
Definition: fbcon.h:136
uint32_t background
Text background raw colour.
Definition: fbcon.h:132
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:54
uint32_t bold
Bold colour modifier raw colour.
Definition: fbcon.h:134
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:146

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_geometry::width, fbcon::xpos, and fbcon::ypos.

Referenced by efifb_putchar(), and vesafb_putchar().

Variable Documentation

◆ __attribute__