iPXE
Data Structures | Macros | Functions | Variables
efi_fbcon.c File Reference

EFI frame buffer console. More...

#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include <limits.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/GraphicsOutput.h>
#include <ipxe/efi/Protocol/HiiFont.h>
#include <ipxe/ansicol.h>
#include <ipxe/fbcon.h>
#include <ipxe/console.h>
#include <ipxe/uaccess.h>
#include <ipxe/umalloc.h>
#include <ipxe/rotate.h>
#include <config/console.h>

Go to the source code of this file.

Data Structures

struct  efifb
 An EFI frame buffer. More...
 

Macros

#define CONSOLE_EFIFB   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
 
#define EFIFB_ASCII   128
 Number of ASCII glyphs in cache. More...
 
#define EFIFB_DYNAMIC   32
 Number of dynamic non-ASCII glyphs in cache. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int efifb_draw (unsigned int character, unsigned int index, unsigned int toggle)
 Draw character glyph. More...
 
static int efifb_draw_unknown (unsigned int index)
 Draw "unknown character" glyph. More...
 
static unsigned int efifb_dynamic (unsigned int character)
 Get dynamic glyph index. More...
 
static const uint8_tefifb_glyph (unsigned int character)
 Get character glyph. More...
 
static int efifb_glyphs (void)
 Get character glyphs. More...
 
static int efifb_colour_map_mask (uint32_t mask, uint8_t *scale, uint8_t *lsb)
 Generate colour mapping for a single colour component. More...
 
static int efifb_colour_map (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
 Generate colour mapping. More...
 
static int efifb_select_mode (unsigned int min_width, unsigned int min_height, unsigned int min_bpp)
 Select video mode. More...
 
static int efifb_restore (void)
 Restore video mode. More...
 
static int efifb_init (struct console_configuration *config)
 Initialise EFI frame buffer. More...
 
static void efifb_fini (void)
 Finalise EFI frame buffer. More...
 
static void efifb_putchar (int character)
 Print a character to current cursor position. More...
 
static int efifb_configure (struct console_configuration *config)
 Configure console. More...
 

Variables

struct console_driver efi_console
 
struct console_driver efifb_console __console_driver
 EFI graphics output protocol console driver. More...
 
static struct efifb efifb
 The EFI frame buffer. More...
 

Detailed Description

EFI frame buffer console.

Definition in file efi_fbcon.c.

Macro Definition Documentation

◆ CONSOLE_EFIFB

#define CONSOLE_EFIFB   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )

Definition at line 63 of file efi_fbcon.c.

◆ EFIFB_ASCII

#define EFIFB_ASCII   128

Number of ASCII glyphs in cache.

Definition at line 67 of file efi_fbcon.c.

◆ EFIFB_DYNAMIC

#define EFIFB_DYNAMIC   32

Number of dynamic non-ASCII glyphs in cache.

Definition at line 70 of file efi_fbcon.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efifb_draw()

static int efifb_draw ( unsigned int  character,
unsigned int  index,
unsigned int  toggle 
)
static

Draw character glyph.

Parameters
characterCharacter
indexIndex within glyph cache
toggleBits to toggle in each bitmask
Return values
heightCharacter height, or negative error

Definition at line 113 of file efi_fbcon.c.

114  {
116  EFI_IMAGE_OUTPUT *blt;
118  unsigned int height;
119  unsigned int x;
120  unsigned int y;
121  uint8_t *glyph;
122  uint8_t bitmask;
123  EFI_STATUS efirc;
124  int rc;
125 
126  /* Clear existing glyph */
127  glyph = &efifb.glyphs[ index * efifb.font.height ];
128  memset ( glyph, 0, efifb.font.height );
129 
130  /* Get glyph */
131  blt = NULL;
132  if ( ( efirc = efifb.hiifont->GetGlyph ( efifb.hiifont, character,
133  NULL, &blt, NULL ) ) != 0 ) {
134  rc = -EEFI ( efirc );
135  DBGC ( &efifb, "EFIFB could not get glyph %#02x: %s\n",
136  character, strerror ( rc ) );
137  goto err_get;
138  }
139  assert ( blt != NULL );
140 
141  /* Sanity check */
142  if ( blt->Width > 8 ) {
143  DBGC ( &efifb, "EFIFB glyph %#02x invalid width %d\n",
144  character, blt->Width );
145  rc = -EINVAL;
146  goto err_width;
147  }
148 
149  /* Convert glyph to bitmap */
150  pixel = blt->Image.Bitmap;
151  height = blt->Height;
152  for ( y = 0 ; ( ( y < height ) && ( y < efifb.font.height ) ) ; y++ ) {
153  bitmask = 0;
154  for ( x = 0 ; x < blt->Width ; x++ ) {
155  bitmask = rol8 ( bitmask, 1 );
156  if ( pixel->Blue || pixel->Green || pixel->Red )
157  bitmask |= 0x01;
158  pixel++;
159  }
160  bitmask ^= toggle;
161  *(glyph++) = bitmask;
162  }
163 
164  /* Free glyph */
165  bs->FreePool ( blt );
166 
167  return height;
168 
169  err_width:
170  bs->FreePool ( blt );
171  err_get:
172  return rc;
173 }
unsigned int height
Character height (in pixels)
Definition: fbcon.h:35
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
EFI_HII_GET_GLYPH GetGlyph
Definition: HiiFont.h:460
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
static unsigned int x
Definition: pixbuf.h:62
An EFI frame buffer.
Definition: efi_fbcon.c:76
EFI_GRAPHICS_OUTPUT_BLT_PIXEL * Bitmap
Definition: HiiImage.h:193
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
union _EFI_IMAGE_OUTPUT::@581 Image
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:93
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
unsigned char uint8_t
Definition: stdint.h:10
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1949
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
static unsigned int unsigned int y
Definition: pixbuf.h:62
EFI_SYSTEM_TABLE * efi_systab
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:95
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
EFI_HII_FONT_PROTOCOL * hiifont
EFI HII font protocol.
Definition: efi_fbcon.c:80
Definition of EFI_IMAGE_OUTPUT.
Definition: HiiImage.h:189
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), _EFI_IMAGE_OUTPUT::Bitmap, EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_systab, EINVAL, efifb::font, EFI_BOOT_SERVICES::FreePool, _EFI_HII_FONT_PROTOCOL::GetGlyph, efifb::glyphs, fbcon_font::height, _EFI_IMAGE_OUTPUT::Height, efifb::hiifont, _EFI_IMAGE_OUTPUT::Image, index, memset(), NULL, efifb::pixel, rc, strerror(), _EFI_IMAGE_OUTPUT::Width, x, and y.

Referenced by efifb_draw_unknown(), efifb_dynamic(), and efifb_glyphs().

◆ efifb_draw_unknown()

static int efifb_draw_unknown ( unsigned int  index)
static

Draw "unknown character" glyph.

Parameters
indexIndex within glyph cache
Return values
rcReturn status code

Definition at line 181 of file efi_fbcon.c.

181  {
182 
183  /* Draw an inverted '?' glyph */
184  return efifb_draw ( '?', index, -1U );
185 }
long index
Definition: bigint.h:62
static int efifb_draw(unsigned int character, unsigned int index, unsigned int toggle)
Draw character glyph.
Definition: efi_fbcon.c:113

References efifb_draw(), and index.

Referenced by efifb_dynamic(), and efifb_glyphs().

◆ efifb_dynamic()

static unsigned int efifb_dynamic ( unsigned int  character)
static

Get dynamic glyph index.

Parameters
characterUnicode character
Return values
indexGlyph cache index

Definition at line 193 of file efi_fbcon.c.

193  {
194  unsigned int dynamic;
195  unsigned int index;
196  unsigned int i;
197  int height;
198 
199  /* Search existing cached entries */
200  for ( i = 0 ; i < EFIFB_DYNAMIC ; i++ ) {
201  if ( character == efifb.dynamic[i] )
202  return ( EFIFB_ASCII + i );
203  }
204 
205  /* Overwrite the oldest cache entry */
206  dynamic = ( efifb.next++ % EFIFB_DYNAMIC );
207  index = ( EFIFB_ASCII + dynamic );
208  DBGC2 ( &efifb, "EFIFB dynamic %#02x is glyph %#02x\n",
209  dynamic, character );
210 
211  /* Draw glyph */
212  height = efifb_draw ( character, index, 0 );
213  if ( height < 0 )
215 
216  /* Record cached character */
217  efifb.dynamic[dynamic] = character;
218 
219  return index;
220 }
#define EFIFB_ASCII
Number of ASCII glyphs in cache.
Definition: efi_fbcon.c:67
long index
Definition: bigint.h:62
An EFI frame buffer.
Definition: efi_fbcon.c:76
unsigned int dynamic[EFIFB_DYNAMIC]
Dynamic characters in cache.
Definition: efi_fbcon.c:97
#define EFIFB_DYNAMIC
Number of dynamic non-ASCII glyphs in cache.
Definition: efi_fbcon.c:70
static int efifb_draw(unsigned int character, unsigned int index, unsigned int toggle)
Draw character glyph.
Definition: efi_fbcon.c:113
static int efifb_draw_unknown(unsigned int index)
Draw "unknown character" glyph.
Definition: efi_fbcon.c:181
unsigned int next
Next dynamic character cache entry to evict.
Definition: efi_fbcon.c:99
#define DBGC2(...)
Definition: compiler.h:522

References DBGC2, efifb::dynamic, EFIFB_ASCII, efifb_draw(), efifb_draw_unknown(), EFIFB_DYNAMIC, index, and efifb::next.

Referenced by efifb_glyph().

◆ efifb_glyph()

static const uint8_t* efifb_glyph ( unsigned int  character)
static

Get character glyph.

Parameters
characterUnicode character
Return values
glyphCharacter glyph to fill in

Definition at line 228 of file efi_fbcon.c.

228  {
229  unsigned int index;
230 
231  /* Identify glyph */
232  if ( character < EFIFB_ASCII ) {
233 
234  /* ASCII character: use fixed cache entry */
235  index = character;
236 
237  } else {
238 
239  /* Non-ASCII character: use dynamic glyph cache */
240  index = efifb_dynamic ( character );
241  }
242 
243  /* Return cached glyph */
244  return &efifb.glyphs[ index * efifb.font.height ];
245 }
unsigned int height
Character height (in pixels)
Definition: fbcon.h:35
#define EFIFB_ASCII
Number of ASCII glyphs in cache.
Definition: efi_fbcon.c:67
long index
Definition: bigint.h:62
static unsigned int efifb_dynamic(unsigned int character)
Get dynamic glyph index.
Definition: efi_fbcon.c:193
An EFI frame buffer.
Definition: efi_fbcon.c:76
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:93
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:95

References EFIFB_ASCII, efifb_dynamic(), efifb::font, efifb::glyphs, fbcon_font::height, and index.

Referenced by efifb_glyphs().

◆ efifb_glyphs()

static int efifb_glyphs ( void  )
static

Get character glyphs.

Return values
rcReturn status code

Definition at line 252 of file efi_fbcon.c.

252  {
253  unsigned int character;
254  int height;
255  int max;
256  size_t len;
257  int rc;
258 
259  /* Get font height. The GetFontInfo() call nominally returns
260  * this information in an EFI_FONT_DISPLAY_INFO structure, but
261  * is known to fail on many UEFI implementations. Instead, we
262  * iterate over all printable characters to find the maximum
263  * height.
264  */
265  efifb.font.height = 0;
266  max = 0;
267  for ( character = 0 ; character < EFIFB_ASCII ; character++ ) {
268 
269  /* Skip non-printable characters */
270  if ( ! isprint ( character ) )
271  continue;
272 
273  /* Get glyph */
274  height = efifb_draw ( character, 0, 0 );
275  if ( height < 0 ) {
276  rc = height;
277  goto err_height;
278  }
279 
280  /* Calculate maximum height */
281  if ( max < height )
282  max = height;
283  }
284  if ( ! max ) {
285  DBGC ( &efifb, "EFIFB could not get font height\n" );
286  return -ENOENT;
287  }
288  efifb.font.height = max;
289 
290  /* Allocate glyph data */
292  efifb.glyphs = umalloc ( len );
293  if ( ! efifb.glyphs ) {
294  rc = -ENOMEM;
295  goto err_alloc;
296  }
297  memset ( efifb.glyphs, 0, len );
298 
299  /* Get font data */
300  for ( character = 0 ; character < EFIFB_ASCII ; character++ ) {
301 
302  /* Skip non-printable characters */
303  if ( ! isprint ( character ) ) {
304  efifb_draw_unknown ( character );
305  continue;
306  }
307 
308  /* Get glyph */
309  height = efifb_draw ( character, character, 0 );
310  if ( height < 0 ) {
311  rc = height;
312  goto err_draw;
313  }
314  }
315 
316  /* Clear dynamic glyph character cache */
317  memset ( efifb.dynamic, 0, sizeof ( efifb.dynamic ) );
318 
320  return 0;
321 
322  err_draw:
323  ufree ( efifb.glyphs );
324  err_alloc:
325  err_height:
326  return rc;
327 }
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
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define max(x, y)
Definition: ath.h:40
#define EFIFB_ASCII
Number of ASCII glyphs in cache.
Definition: efi_fbcon.c:67
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
An EFI frame buffer.
Definition: efi_fbcon.c:76
static int isprint(int character)
Check if character is printable.
Definition: ctype.h:97
#define ENOMEM
Not enough space.
Definition: errno.h:534
unsigned int dynamic[EFIFB_DYNAMIC]
Dynamic characters in cache.
Definition: efi_fbcon.c:97
#define EFIFB_DYNAMIC
Number of dynamic non-ASCII glyphs in cache.
Definition: efi_fbcon.c:70
ring len
Length.
Definition: dwmac.h:231
static int efifb_draw(unsigned int character, unsigned int index, unsigned int toggle)
Draw character glyph.
Definition: efi_fbcon.c:113
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:93
static int efifb_draw_unknown(unsigned int index)
Draw "unknown character" glyph.
Definition: efi_fbcon.c:181
static const uint8_t * efifb_glyph(unsigned int character)
Get character glyph.
Definition: efi_fbcon.c:228
const uint8_t *(* glyph)(unsigned int character)
Get character glyph.
Definition: fbcon.h:42
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:56
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:95
void * memset(void *dest, int character, size_t len) __nonnull

References DBGC, efifb::dynamic, EFIFB_ASCII, efifb_draw(), efifb_draw_unknown(), EFIFB_DYNAMIC, efifb_glyph(), ENOENT, ENOMEM, efifb::font, fbcon_font::glyph, efifb::glyphs, fbcon_font::height, isprint(), len, max, memset(), rc, ufree(), and umalloc().

Referenced by efifb_init().

◆ efifb_colour_map_mask()

static int efifb_colour_map_mask ( uint32_t  mask,
uint8_t scale,
uint8_t lsb 
)
static

Generate colour mapping for a single colour component.

Parameters
maskMask value
scaleScale value to fill in
lsbLSB value to fill in
Return values
rcReturn status code

Definition at line 337 of file efi_fbcon.c.

338  {
339  uint32_t check;
340 
341  /* Fill in LSB and scale */
342  *lsb = ( mask ? ( ffs ( mask ) - 1 ) : 0 );
343  *scale = ( mask ? ( 8 - ( fls ( mask ) - *lsb ) ) : 8 );
344 
345  /* Check that original mask was contiguous */
346  check = ( ( 0xff >> *scale ) << *lsb );
347  if ( check != mask )
348  return -ENOTSUP;
349 
350  return 0;
351 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
unsigned int uint32_t
Definition: stdint.h:12
#define ffs(x)
Find first (i.e.
Definition: strings.h:140
#define fls(x)
Find last (i.e.
Definition: strings.h:166

References ENOTSUP, ffs, and fls.

Referenced by efifb_colour_map().

◆ efifb_colour_map()

static int efifb_colour_map ( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION info,
struct fbcon_colour_map map 
)
static

Generate colour mapping.

Parameters
infoEFI mode information
mapColour mapping to fill in
Return values
bppNumber of bits per pixel, or negative error

Definition at line 360 of file efi_fbcon.c.

361  {
362  static EFI_PIXEL_BITMASK rgb_mask = {
363  0x000000ffUL, 0x0000ff00UL, 0x00ff0000UL, 0xff000000UL
364  };
365  static EFI_PIXEL_BITMASK bgr_mask = {
366  0x00ff0000UL, 0x0000ff00UL, 0x000000ffUL, 0xff000000UL
367  };
368  EFI_PIXEL_BITMASK *mask;
369  uint8_t reserved_scale;
370  uint8_t reserved_lsb;
371  int rc;
372 
373  /* Determine applicable mask */
374  switch ( info->PixelFormat ) {
376  mask = &rgb_mask;
377  break;
379  mask = &bgr_mask;
380  break;
381  case PixelBitMask:
382  mask = &info->PixelInformation;
383  break;
384  default:
385  DBGC ( &efifb, "EFIFB unrecognised pixel format %d\n",
386  info->PixelFormat );
387  return -ENOTSUP;
388  }
389 
390  /* Map each colour component */
391  if ( ( rc = efifb_colour_map_mask ( mask->RedMask, &map->red_scale,
392  &map->red_lsb ) ) != 0 )
393  return rc;
394  if ( ( rc = efifb_colour_map_mask ( mask->GreenMask, &map->green_scale,
395  &map->green_lsb ) ) != 0 )
396  return rc;
397  if ( ( rc = efifb_colour_map_mask ( mask->BlueMask, &map->blue_scale,
398  &map->blue_lsb ) ) != 0 )
399  return rc;
400  if ( ( rc = efifb_colour_map_mask ( mask->ReservedMask, &reserved_scale,
401  &reserved_lsb ) ) != 0 )
402  return rc;
403 
404  /* Calculate total number of bits per pixel */
405  return ( 32 - ( reserved_scale + map->red_scale + map->green_scale +
406  map->blue_scale ) );
407 }
The Pixel definition of the physical frame buffer.
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
u32 info
Definition: ar9003_mac.h:67
#define DBGC(...)
Definition: compiler.h:505
A pixel is 32-bits and byte zero represents blue, byte one represents green, byte two represents red,...
An EFI frame buffer.
Definition: efi_fbcon.c:76
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static int efifb_colour_map_mask(uint32_t mask, uint8_t *scale, uint8_t *lsb)
Generate colour mapping for a single colour component.
Definition: efi_fbcon.c:337
unsigned char uint8_t
Definition: stdint.h:10
A pixel is 32-bits and byte zero represents red, byte one represents green, byte two represents blue,...
static __always_inline int struct dma_mapping * map
Definition: dma.h:183

References EFI_PIXEL_BITMASK::BlueMask, DBGC, efifb_colour_map_mask(), ENOTSUP, EFI_PIXEL_BITMASK::GreenMask, info, map, PixelBitMask, PixelBlueGreenRedReserved8BitPerColor, PixelRedGreenBlueReserved8BitPerColor, rc, EFI_PIXEL_BITMASK::RedMask, and EFI_PIXEL_BITMASK::ReservedMask.

Referenced by efifb_init(), and efifb_select_mode().

◆ efifb_select_mode()

static int efifb_select_mode ( unsigned int  min_width,
unsigned int  min_height,
unsigned int  min_bpp 
)
static

Select video mode.

Parameters
min_widthMinimum required width (in pixels)
min_heightMinimum required height (in pixels)
min_bppMinimum required colour depth (in bits per pixel)
Return values
mode_numberMode number, or negative error

Definition at line 417 of file efi_fbcon.c.

418  {
420  struct fbcon_colour_map map;
422  int best_mode_number = -ENOENT;
423  unsigned int best_score = INT_MAX;
424  unsigned int score;
425  unsigned int mode;
426  int bpp;
427  UINTN size;
428  EFI_STATUS efirc;
429  int rc;
430 
431  /* Find the best mode */
432  for ( mode = 0 ; mode < efifb.gop->Mode->MaxMode ; mode++ ) {
433 
434  /* Get mode information */
435  if ( ( efirc = efifb.gop->QueryMode ( efifb.gop, mode, &size,
436  &info ) ) != 0 ) {
437  rc = -EEFI ( efirc );
438  DBGC ( &efifb, "EFIFB could not get mode %d "
439  "information: %s\n", mode, strerror ( rc ) );
440  goto err_query;
441  }
442 
443  /* Skip unusable modes */
444  bpp = efifb_colour_map ( info, &map );
445  if ( bpp < 0 ) {
446  rc = bpp;
447  DBGC ( &efifb, "EFIFB could not build colour map for "
448  "mode %d: %s\n", mode, strerror ( rc ) );
449  goto err_map;
450  }
451 
452  /* Skip modes not meeting the requirements */
453  if ( ( info->HorizontalResolution < min_width ) ||
454  ( info->VerticalResolution < min_height ) ||
455  ( ( ( unsigned int ) bpp ) < min_bpp ) ) {
456  goto err_requirements;
457  }
458 
459  /* Select this mode if it has the best (i.e. lowest)
460  * score. We choose the scoring system to favour
461  * modes close to the specified width and height;
462  * within modes of the same width and height we prefer
463  * a higher colour depth.
464  */
465  score = ( ( info->HorizontalResolution *
466  info->VerticalResolution ) - bpp );
467  if ( score < best_score ) {
468  best_mode_number = mode;
469  best_score = score;
470  }
471 
472  err_requirements:
473  err_map:
474  bs->FreePool ( info );
475  err_query:
476  continue;
477  }
478 
479  if ( best_mode_number < 0 )
480  DBGC ( &efifb, "EFIFB found no suitable mode\n" );
481  return best_mode_number;
482 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
u32 info
Definition: ar9003_mac.h:67
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
Pointer to EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE data.
uint16_t mode
Acceleration mode.
Definition: ena.h:26
uint16_t size
Buffer size.
Definition: dwmac.h:14
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
An EFI frame buffer.
Definition: efi_fbcon.c:76
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:78
EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode
A frame buffer colour mapping.
Definition: fbcon.h:74
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:360
UINT64 UINTN
Unsigned value of native width.
UINT32 MaxMode
The number of modes supported by QueryMode() and SetMode().
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1949
static __always_inline int struct dma_mapping * map
Definition: dma.h:183
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
#define INT_MAX
Definition: limits.h:37

References EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_systab, efifb_colour_map(), ENOENT, EFI_BOOT_SERVICES::FreePool, efifb::gop, info, INT_MAX, map, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE::MaxMode, mode, _EFI_GRAPHICS_OUTPUT_PROTOCOL::Mode, _EFI_GRAPHICS_OUTPUT_PROTOCOL::QueryMode, rc, size, and strerror().

Referenced by efifb_init().

◆ efifb_restore()

static int efifb_restore ( void  )
static

Restore video mode.

Parameters
rcReturn status code

Definition at line 489 of file efi_fbcon.c.

489  {
490  EFI_STATUS efirc;
491  int rc;
492 
493  /* Restore original mode */
494  if ( ( efirc = efifb.gop->SetMode ( efifb.gop,
495  efifb.saved_mode ) ) != 0 ) {
496  rc = -EEFI ( efirc );
497  DBGC ( &efifb, "EFIFB could not restore mode %d: %s\n",
498  efifb.saved_mode, strerror ( rc ) );
499  return rc;
500  }
501 
502  return 0;
503 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
#define DBGC(...)
Definition: compiler.h:505
An EFI frame buffer.
Definition: efi_fbcon.c:76
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:78
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:82

References DBGC, EEFI, efifb::gop, rc, efifb::saved_mode, _EFI_GRAPHICS_OUTPUT_PROTOCOL::SetMode, and strerror().

Referenced by efifb_fini(), and efifb_init().

◆ efifb_init()

static int efifb_init ( struct console_configuration config)
static

Initialise EFI frame buffer.

Parameters
configConsole configuration, or NULL to reset
Return values
rcReturn status code

Definition at line 511 of file efi_fbcon.c.

511  {
514  void *interface;
515  int mode;
516  int bpp;
517  EFI_STATUS efirc;
518  int rc;
519 
520  /* Locate graphics output protocol */
522  NULL, &interface ) ) != 0 ) {
523  rc = -EEFI ( efirc );
524  DBGC ( &efifb, "EFIFB could not locate graphics output "
525  "protocol: %s\n", strerror ( rc ) );
526  goto err_locate_gop;
527  }
528  efifb.gop = interface;
529 
530  /* Locate HII font protocol */
531  if ( ( efirc = bs->LocateProtocol ( &efi_hii_font_protocol_guid,
532  NULL, &interface ) ) != 0 ) {
533  rc = -EEFI ( efirc );
534  DBGC ( &efifb, "EFIFB could not locate HII font protocol: %s\n",
535  strerror ( rc ) );
536  goto err_locate_hiifont;
537  }
539 
540  /* Locate glyphs */
541  if ( ( rc = efifb_glyphs() ) != 0 )
542  goto err_glyphs;
543 
544  /* Save original mode */
546 
547  /* Select mode */
548  if ( ( mode = efifb_select_mode ( config->width, config->height,
549  config->depth ) ) < 0 ) {
550  rc = mode;
551  goto err_select_mode;
552  }
553 
554  /* Set mode */
555  if ( ( efirc = efifb.gop->SetMode ( efifb.gop, mode ) ) != 0 ) {
556  rc = -EEFI ( efirc );
557  DBGC ( &efifb, "EFIFB could not set mode %d: %s\n",
558  mode, strerror ( rc ) );
559  goto err_set_mode;
560  }
561  info = efifb.gop->Mode->Info;
562 
563  /* Populate colour map */
564  bpp = efifb_colour_map ( info, &efifb.map );
565  if ( bpp < 0 ) {
566  rc = bpp;
567  DBGC ( &efifb, "EFIFB could not build colour map for "
568  "mode %d: %s\n", mode, strerror ( rc ) );
569  goto err_map;
570  }
571 
572  /* Populate pixel geometry */
573  efifb.pixel.width = info->HorizontalResolution;
574  efifb.pixel.height = info->VerticalResolution;
575  efifb.pixel.len = ( ( bpp + 7 ) / 8 );
576  efifb.pixel.stride = ( efifb.pixel.len * info->PixelsPerScanLine );
577 
578  /* Populate frame buffer address */
580  DBGC ( &efifb, "EFIFB using mode %d (%dx%d %dbpp at %#08lx)\n",
582 
583  /* Initialise frame buffer console */
584  if ( ( rc = fbcon_init ( &efifb.fbcon, phys_to_virt ( efifb.start ),
585  &efifb.pixel, &efifb.map, &efifb.font,
586  config ) ) != 0 )
587  goto err_fbcon_init;
588 
589  return 0;
590 
591  fbcon_fini ( &efifb.fbcon );
592  err_fbcon_init:
593  err_map:
594  efifb_restore();
595  err_set_mode:
596  err_select_mode:
597  ufree ( efifb.glyphs );
598  err_glyphs:
599  err_locate_hiifont:
600  err_locate_gop:
601  return rc;
602 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI_GUID efi_hii_font_protocol_guid
HII font protocol GUID.
Definition: efi_guid.c:224
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
unsigned int height
Height.
Definition: console.h:28
u32 info
Definition: ar9003_mac.h:67
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
Pointer to EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE data.
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.
Definition: fbcon.c:600
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:2008
uint16_t mode
Acceleration mode.
Definition: ena.h:26
EFI_GUID efi_graphics_output_protocol_guid
Graphics output protocol GUID.
Definition: efi_guid.c:216
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:85
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:52
#define DBGC(...)
Definition: compiler.h:505
static int efifb_glyphs(void)
Get character glyphs.
Definition: efi_fbcon.c:252
struct fbcon_geometry pixel
Pixel geometry.
Definition: efi_fbcon.c:89
static int efifb_select_mode(unsigned int min_width, unsigned int min_height, unsigned int min_bpp)
Select video mode.
Definition: efi_fbcon.c:417
unsigned int width
Width.
Definition: console.h:26
unsigned int depth
Colour depth.
Definition: console.h:30
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * Info
Pointer to read-only EFI_GRAPHICS_OUTPUT_MODE_INFORMATION data.
An EFI frame buffer.
Definition: efi_fbcon.c:76
struct fbcon_colour_map map
Colour mapping.
Definition: efi_fbcon.c:91
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:78
size_t len
Length of a single entity.
Definition: fbcon.h:56
An object interface.
Definition: interface.h:124
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:93
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:728
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:360
EFI_PHYSICAL_ADDRESS FrameBufferBase
Base address of graphics linear frame buffer.
UINT32 Mode
Current Mode of the graphics device.
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:54
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:82
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:95
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
size_t stride
Stride (offset between vertically adjacent entities)
Definition: fbcon.h:58
EFI_HII_FONT_PROTOCOL * hiifont
EFI HII font protocol.
Definition: efi_fbcon.c:80
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:489
physaddr_t start
Physical start address.
Definition: efi_fbcon.c:87

References EFI_SYSTEM_TABLE::BootServices, DBGC, console_configuration::depth, EEFI, efi_graphics_output_protocol_guid, efi_hii_font_protocol_guid, efi_systab, efifb_colour_map(), efifb_glyphs(), efifb_restore(), efifb_select_mode(), efifb::fbcon, fbcon_fini(), fbcon_init(), efifb::font, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE::FrameBufferBase, efifb::glyphs, efifb::gop, console_configuration::height, fbcon_geometry::height, efifb::hiifont, info, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE::Info, fbcon_geometry::len, EFI_BOOT_SERVICES::LocateProtocol, efifb::map, mode, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE::Mode, _EFI_GRAPHICS_OUTPUT_PROTOCOL::Mode, NULL, efifb::pixel, rc, efifb::saved_mode, _EFI_GRAPHICS_OUTPUT_PROTOCOL::SetMode, efifb::start, strerror(), fbcon_geometry::stride, ufree(), console_configuration::width, and fbcon_geometry::width.

Referenced by efifb_configure().

◆ efifb_fini()

static void efifb_fini ( void  )
static

Finalise EFI frame buffer.

Definition at line 608 of file efi_fbcon.c.

608  {
609 
610  /* Finalise frame buffer console */
611  fbcon_fini ( &efifb.fbcon );
612 
613  /* Restore saved mode */
614  efifb_restore();
615 
616  /* Free glyphs */
617  ufree ( efifb.glyphs );
618 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:85
An EFI frame buffer.
Definition: efi_fbcon.c:76
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:728
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:95
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:489

References efifb_restore(), efifb::fbcon, fbcon_fini(), efifb::glyphs, and ufree().

Referenced by efifb_configure().

◆ efifb_putchar()

static void efifb_putchar ( int  character)
static

Print a character to current cursor position.

Parameters
characterCharacter

Definition at line 625 of file efi_fbcon.c.

625  {
626 
627  fbcon_putchar ( &efifb.fbcon, character );
628 }
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:85
void fbcon_putchar(struct fbcon *fbcon, int character)
Print a character to current cursor position.
Definition: fbcon.c:460
An EFI frame buffer.
Definition: efi_fbcon.c:76

References efifb::fbcon, and fbcon_putchar().

◆ efifb_configure()

static int efifb_configure ( struct console_configuration config)
static

Configure console.

Parameters
configConsole configuration, or NULL to reset
Return values
rcReturn status code

Definition at line 636 of file efi_fbcon.c.

636  {
637  int rc;
638 
639  /* Reset console, if applicable */
640  if ( ! efifb_console.disabled ) {
641  efifb_fini();
644  }
645  efifb_console.disabled = CONSOLE_DISABLED;
646 
647  /* Do nothing more unless we have a usable configuration */
648  if ( ( config == NULL ) ||
649  ( config->width == 0 ) || ( config->height == 0 ) ) {
650  return 0;
651  }
652 
653  /* Initialise EFI frame buffer */
654  if ( ( rc = efifb_init ( config ) ) != 0 )
655  return rc;
656 
657  /* Mark console as enabled */
658  efifb_console.disabled = 0;
660 
661  /* Set magic colour to transparent if we have a background picture */
662  if ( config->pixbuf )
664 
665  return 0;
666 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int height
Height.
Definition: console.h:28
static int efifb_init(struct console_configuration *config)
Initialise EFI frame buffer.
Definition: efi_fbcon.c:511
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
static void efifb_fini(void)
Finalise EFI frame buffer.
Definition: efi_fbcon.c:608
unsigned int width
Width.
Definition: console.h:26
#define CONSOLE_DISABLED_OUTPUT
Console is disabled for output.
Definition: console.h:108
struct console_driver efi_console
Definition: efi_fbcon.c:52
void ansicol_set_magic_transparent(void)
Set magic colour to transparent.
Definition: ansicoldef.c:189
int disabled
Console disabled flags.
Definition: console.h:62
void ansicol_reset_magic(void)
Reset magic colour.
Definition: ansicoldef.c:179
struct pixel_buffer * pixbuf
Background picture, if any.
Definition: console.h:40
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References ansicol_reset_magic(), ansicol_set_magic_transparent(), CONSOLE_DISABLED, CONSOLE_DISABLED_OUTPUT, console_driver::disabled, efi_console, efifb_fini(), efifb_init(), console_configuration::height, NULL, console_configuration::pixbuf, rc, and console_configuration::width.

Variable Documentation

◆ efi_console

struct console_driver efi_console

Definition at line 52 of file efi_fbcon.c.

Referenced by efifb_configure().

◆ __console_driver

struct console_driver efifb_console __console_driver
Initial value:
= {
.usage = CONSOLE_EFIFB,
.putchar = efifb_putchar,
.configure = efifb_configure,
.disabled = CONSOLE_DISABLED,
}
static int efifb_configure(struct console_configuration *config)
Configure console.
Definition: efi_fbcon.c:636
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
#define CONSOLE_EFIFB
Definition: efi_fbcon.c:63
static void efifb_putchar(int character)
Print a character to current cursor position.
Definition: efi_fbcon.c:625

EFI graphics output protocol console driver.

Definition at line 73 of file efi_fbcon.c.

◆ efifb

struct efifb efifb
static

The EFI frame buffer.

Definition at line 103 of file efi_fbcon.c.