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/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 void efifb_glyph (unsigned int character, uint8_t *glyph)
 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 62 of file efi_fbcon.c.

◆ EFIFB_ASCII

#define EFIFB_ASCII   128

Number of ASCII glyphs in cache.

Definition at line 66 of file efi_fbcon.c.

◆ EFIFB_DYNAMIC

#define EFIFB_DYNAMIC   32

Number of dynamic non-ASCII glyphs in cache.

Definition at line 69 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 112 of file efi_fbcon.c.

113  {
115  EFI_IMAGE_OUTPUT *blt;
117  unsigned int height;
118  unsigned int x;
119  unsigned int y;
120  uint8_t bitmask;
121  size_t offset;
122  EFI_STATUS efirc;
123  int rc;
124 
125  /* Clear existing glyph */
126  offset = ( index * efifb.font.height );
128 
129  /* Get glyph */
130  blt = NULL;
131  if ( ( efirc = efifb.hiifont->GetGlyph ( efifb.hiifont, character,
132  NULL, &blt, NULL ) ) != 0 ) {
133  rc = -EEFI ( efirc );
134  DBGC ( &efifb, "EFIFB could not get glyph %#02x: %s\n",
135  character, strerror ( rc ) );
136  goto err_get;
137  }
138  assert ( blt != NULL );
139 
140  /* Sanity check */
141  if ( blt->Width > 8 ) {
142  DBGC ( &efifb, "EFIFB glyph %#02x invalid width %d\n",
143  character, blt->Width );
144  rc = -EINVAL;
145  goto err_width;
146  }
147 
148  /* Convert glyph to bitmap */
149  pixel = blt->Image.Bitmap;
150  height = blt->Height;
151  for ( y = 0 ; ( ( y < height ) && ( y < efifb.font.height ) ) ; y++ ) {
152  bitmask = 0;
153  for ( x = 0 ; x < blt->Width ; x++ ) {
154  bitmask = rol8 ( bitmask, 1 );
155  if ( pixel->Blue || pixel->Green || pixel->Red )
156  bitmask |= 0x01;
157  pixel++;
158  }
159  bitmask ^= toggle;
160  copy_to_user ( efifb.glyphs, offset++, &bitmask,
161  sizeof ( 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:36
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
#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:171
EFI_HII_GET_GLYPH GetGlyph
Definition: HiiFont.h:460
long index
Definition: bigint.h:61
#define DBGC(...)
Definition: compiler.h:505
An EFI frame buffer.
Definition: efi_fbcon.c:75
EFI_GRAPHICS_OUTPUT_BLT_PIXEL * Bitmap
Definition: HiiImage.h:193
union _EFI_IMAGE_OUTPUT::@572 Image
void memset_user(userptr_t userptr, off_t offset, int c, size_t len)
Fill user buffer with a constant byte.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:92
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
static __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
Definition: uaccess.h:324
unsigned char uint8_t
Definition: stdint.h:10
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1936
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
userptr_t glyphs
Character glyph cache.
Definition: efi_fbcon.c:94
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
EFI_HII_FONT_PROTOCOL * hiifont
EFI HII font protocol.
Definition: efi_fbcon.c:79
Definition of EFI_IMAGE_OUTPUT.
Definition: HiiImage.h:189

References assert(), _EFI_IMAGE_OUTPUT::Bitmap, EFI_SYSTEM_TABLE::BootServices, copy_to_user(), 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_user(), NULL, offset, efifb::pixel, rc, strerror(), and _EFI_IMAGE_OUTPUT::Width.

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:61
static int efifb_draw(unsigned int character, unsigned int index, unsigned int toggle)
Draw character glyph.
Definition: efi_fbcon.c:112

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:66
long index
Definition: bigint.h:61
An EFI frame buffer.
Definition: efi_fbcon.c:75
unsigned int dynamic[EFIFB_DYNAMIC]
Dynamic characters in cache.
Definition: efi_fbcon.c:96
#define EFIFB_DYNAMIC
Number of dynamic non-ASCII glyphs in cache.
Definition: efi_fbcon.c:69
static int efifb_draw(unsigned int character, unsigned int index, unsigned int toggle)
Draw character glyph.
Definition: efi_fbcon.c:112
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:98
#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 void efifb_glyph ( unsigned int  character,
uint8_t glyph 
)
static

Get character glyph.

Parameters
characterUnicode character
glyphCharacter glyph to fill in

Definition at line 228 of file efi_fbcon.c.

228  {
229  unsigned int index;
230  size_t offset;
231 
232  /* Identify glyph */
233  if ( character < EFIFB_ASCII ) {
234 
235  /* ASCII character: use fixed cache entry */
236  index = character;
237 
238  } else {
239 
240  /* Non-ASCII character: use dynamic glyph cache */
241  index = efifb_dynamic ( character );
242  }
243 
244  /* Copy cached glyph */
245  offset = ( index * efifb.font.height );
247 }
unsigned int height
Character height (in pixels)
Definition: fbcon.h:36
#define EFIFB_ASCII
Number of ASCII glyphs in cache.
Definition: efi_fbcon.c:66
long index
Definition: bigint.h:61
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
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:75
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:92
userptr_t glyphs
Character glyph cache.
Definition: efi_fbcon.c:94
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

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

Referenced by efifb_glyphs().

◆ efifb_glyphs()

static int efifb_glyphs ( void  )
static

Get character glyphs.

Return values
rcReturn status code

Definition at line 254 of file efi_fbcon.c.

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

340  {
341  uint32_t check;
342 
343  /* Fill in LSB and scale */
344  *lsb = ( mask ? ( ffs ( mask ) - 1 ) : 0 );
345  *scale = ( mask ? ( 8 - ( fls ( mask ) - *lsb ) ) : 8 );
346 
347  /* Check that original mask was contiguous */
348  check = ( ( 0xff >> *scale ) << *lsb );
349  if ( check != mask )
350  return -ENOTSUP;
351 
352  return 0;
353 }
#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 362 of file efi_fbcon.c.

363  {
364  static EFI_PIXEL_BITMASK rgb_mask = {
365  0x000000ffUL, 0x0000ff00UL, 0x00ff0000UL, 0xff000000UL
366  };
367  static EFI_PIXEL_BITMASK bgr_mask = {
368  0x00ff0000UL, 0x0000ff00UL, 0x000000ffUL, 0xff000000UL
369  };
370  EFI_PIXEL_BITMASK *mask;
371  uint8_t reserved_scale;
372  uint8_t reserved_lsb;
373  int rc;
374 
375  /* Determine applicable mask */
376  switch ( info->PixelFormat ) {
378  mask = &rgb_mask;
379  break;
381  mask = &bgr_mask;
382  break;
383  case PixelBitMask:
384  mask = &info->PixelInformation;
385  break;
386  default:
387  DBGC ( &efifb, "EFIFB unrecognised pixel format %d\n",
388  info->PixelFormat );
389  return -ENOTSUP;
390  }
391 
392  /* Map each colour component */
393  if ( ( rc = efifb_colour_map_mask ( mask->RedMask, &map->red_scale,
394  &map->red_lsb ) ) != 0 )
395  return rc;
396  if ( ( rc = efifb_colour_map_mask ( mask->GreenMask, &map->green_scale,
397  &map->green_lsb ) ) != 0 )
398  return rc;
399  if ( ( rc = efifb_colour_map_mask ( mask->BlueMask, &map->blue_scale,
400  &map->blue_lsb ) ) != 0 )
401  return rc;
402  if ( ( rc = efifb_colour_map_mask ( mask->ReservedMask, &reserved_scale,
403  &reserved_lsb ) ) != 0 )
404  return rc;
405 
406  /* Calculate total number of bits per pixel */
407  return ( 32 - ( reserved_scale + map->red_scale + map->green_scale +
408  map->blue_scale ) );
409 }
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:75
#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:339
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:181

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 419 of file efi_fbcon.c.

420  {
422  struct fbcon_colour_map map;
424  int best_mode_number = -ENOENT;
425  unsigned int best_score = INT_MAX;
426  unsigned int score;
427  unsigned int mode;
428  int bpp;
429  UINTN size;
430  EFI_STATUS efirc;
431  int rc;
432 
433  /* Find the best mode */
434  for ( mode = 0 ; mode < efifb.gop->Mode->MaxMode ; mode++ ) {
435 
436  /* Get mode information */
437  if ( ( efirc = efifb.gop->QueryMode ( efifb.gop, mode, &size,
438  &info ) ) != 0 ) {
439  rc = -EEFI ( efirc );
440  DBGC ( &efifb, "EFIFB could not get mode %d "
441  "information: %s\n", mode, strerror ( rc ) );
442  goto err_query;
443  }
444 
445  /* Skip unusable modes */
446  bpp = efifb_colour_map ( info, &map );
447  if ( bpp < 0 ) {
448  rc = bpp;
449  DBGC ( &efifb, "EFIFB could not build colour map for "
450  "mode %d: %s\n", mode, strerror ( rc ) );
451  goto err_map;
452  }
453 
454  /* Skip modes not meeting the requirements */
455  if ( ( info->HorizontalResolution < min_width ) ||
456  ( info->VerticalResolution < min_height ) ||
457  ( ( ( unsigned int ) bpp ) < min_bpp ) ) {
458  goto err_requirements;
459  }
460 
461  /* Select this mode if it has the best (i.e. lowest)
462  * score. We choose the scoring system to favour
463  * modes close to the specified width and height;
464  * within modes of the same width and height we prefer
465  * a higher colour depth.
466  */
467  score = ( ( info->HorizontalResolution *
468  info->VerticalResolution ) - bpp );
469  if ( score < best_score ) {
470  best_mode_number = mode;
471  best_score = score;
472  }
473 
474  err_requirements:
475  err_map:
476  bs->FreePool ( info );
477  err_query:
478  continue;
479  }
480 
481  if ( best_mode_number < 0 )
482  DBGC ( &efifb, "EFIFB found no suitable mode\n" );
483  return best_mode_number;
484 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:171
u32 info
Definition: ar9003_mac.h:67
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
Pointer to EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE data.
#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:75
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:77
EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode
A frame buffer colour mapping.
Definition: fbcon.h:75
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:362
UINT64 UINTN
Unsigned value of native width.
UINT32 MaxMode
The number of modes supported by QueryMode() and SetMode().
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1936
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
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, _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 491 of file efi_fbcon.c.

491  {
492  EFI_STATUS efirc;
493  int rc;
494 
495  /* Restore original mode */
496  if ( ( efirc = efifb.gop->SetMode ( efifb.gop,
497  efifb.saved_mode ) ) != 0 ) {
498  rc = -EEFI ( efirc );
499  DBGC ( &efifb, "EFIFB could not restore mode %d: %s\n",
500  efifb.saved_mode, strerror ( rc ) );
501  return rc;
502  }
503 
504  return 0;
505 }
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:171
#define DBGC(...)
Definition: compiler.h:505
An EFI frame buffer.
Definition: efi_fbcon.c:75
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:77
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:81

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 513 of file efi_fbcon.c.

513  {
516  void *interface;
517  int mode;
518  int bpp;
519  EFI_STATUS efirc;
520  int rc;
521 
522  /* Locate graphics output protocol */
524  NULL, &interface ) ) != 0 ) {
525  rc = -EEFI ( efirc );
526  DBGC ( &efifb, "EFIFB could not locate graphics output "
527  "protocol: %s\n", strerror ( rc ) );
528  goto err_locate_gop;
529  }
530  efifb.gop = interface;
531 
532  /* Locate HII font protocol */
533  if ( ( efirc = bs->LocateProtocol ( &efi_hii_font_protocol_guid,
534  NULL, &interface ) ) != 0 ) {
535  rc = -EEFI ( efirc );
536  DBGC ( &efifb, "EFIFB could not locate HII font protocol: %s\n",
537  strerror ( rc ) );
538  goto err_locate_hiifont;
539  }
541 
542  /* Locate glyphs */
543  if ( ( rc = efifb_glyphs() ) != 0 )
544  goto err_glyphs;
545 
546  /* Save original mode */
548 
549  /* Select mode */
550  if ( ( mode = efifb_select_mode ( config->width, config->height,
551  config->depth ) ) < 0 ) {
552  rc = mode;
553  goto err_select_mode;
554  }
555 
556  /* Set mode */
557  if ( ( efirc = efifb.gop->SetMode ( efifb.gop, mode ) ) != 0 ) {
558  rc = -EEFI ( efirc );
559  DBGC ( &efifb, "EFIFB could not set mode %d: %s\n",
560  mode, strerror ( rc ) );
561  goto err_set_mode;
562  }
563  info = efifb.gop->Mode->Info;
564 
565  /* Populate colour map */
566  bpp = efifb_colour_map ( info, &efifb.map );
567  if ( bpp < 0 ) {
568  rc = bpp;
569  DBGC ( &efifb, "EFIFB could not build colour map for "
570  "mode %d: %s\n", mode, strerror ( rc ) );
571  goto err_map;
572  }
573 
574  /* Populate pixel geometry */
575  efifb.pixel.width = info->HorizontalResolution;
576  efifb.pixel.height = info->VerticalResolution;
577  efifb.pixel.len = ( ( bpp + 7 ) / 8 );
578  efifb.pixel.stride = ( efifb.pixel.len * info->PixelsPerScanLine );
579 
580  /* Populate frame buffer address */
582  DBGC ( &efifb, "EFIFB using mode %d (%dx%d %dbpp at %#08lx)\n",
583  mode, efifb.pixel.width, efifb.pixel.height, bpp, efifb.start );
584 
585  /* Initialise frame buffer console */
586  if ( ( rc = fbcon_init ( &efifb.fbcon, phys_to_user ( efifb.start ),
587  &efifb.pixel, &efifb.map, &efifb.font,
588  config ) ) != 0 )
589  goto err_fbcon_init;
590 
591  return 0;
592 
593  fbcon_fini ( &efifb.fbcon );
594  err_fbcon_init:
595  err_map:
596  efifb_restore();
597  err_set_mode:
598  err_select_mode:
599  ufree ( efifb.glyphs );
600  err_glyphs:
601  err_locate_hiifont:
602  err_locate_gop:
603  return rc;
604 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:195
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
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.
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:1995
EFI_GUID efi_graphics_output_protocol_guid
Graphics output protocol GUID.
Definition: efi_guid.c:187
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:84
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:53
#define DBGC(...)
Definition: compiler.h:505
static int efifb_glyphs(void)
Get character glyphs.
Definition: efi_fbcon.c:254
struct fbcon_geometry pixel
Pixel geometry.
Definition: efi_fbcon.c:88
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
static int efifb_select_mode(unsigned int min_width, unsigned int min_height, unsigned int min_bpp)
Select video mode.
Definition: efi_fbcon.c:419
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:75
struct fbcon_colour_map map
Colour mapping.
Definition: efi_fbcon.c:90
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:77
size_t len
Length of a single entity.
Definition: fbcon.h:57
An object interface.
Definition: interface.h:124
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.
Definition: fbcon.c:588
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:92
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:718
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:362
EFI_PHYSICAL_ADDRESS FrameBufferBase
Base address of graphics linear frame buffer.
UINT32 Mode
Current Mode of the graphics device.
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:55
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
userptr_t glyphs
Character glyph cache.
Definition: efi_fbcon.c:94
EFI_SYSTEM_TABLE * efi_systab
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
size_t stride
Stride (offset between vertically adjacent entities)
Definition: fbcon.h:59
EFI_HII_FONT_PROTOCOL * hiifont
EFI HII font protocol.
Definition: efi_fbcon.c:79
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:491
physaddr_t start
Physical start address.
Definition: efi_fbcon.c:86

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, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE::Mode, _EFI_GRAPHICS_OUTPUT_PROTOCOL::Mode, NULL, phys_to_user(), 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 610 of file efi_fbcon.c.

610  {
611 
612  /* Finalise frame buffer console */
613  fbcon_fini ( &efifb.fbcon );
614 
615  /* Restore saved mode */
616  efifb_restore();
617 
618  /* Free glyphs */
619  ufree ( efifb.glyphs );
620 }
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:84
An EFI frame buffer.
Definition: efi_fbcon.c:75
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:718
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
userptr_t glyphs
Character glyph cache.
Definition: efi_fbcon.c:94
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:491

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 627 of file efi_fbcon.c.

627  {
628 
629  fbcon_putchar ( &efifb.fbcon, character );
630 }
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:84
void fbcon_putchar(struct fbcon *fbcon, int character)
Print a character to current cursor position.
Definition: fbcon.c:441
An EFI frame buffer.
Definition: efi_fbcon.c:75

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 638 of file efi_fbcon.c.

638  {
639  int rc;
640 
641  /* Reset console, if applicable */
642  if ( ! efifb_console.disabled ) {
643  efifb_fini();
646  }
647  efifb_console.disabled = CONSOLE_DISABLED;
648 
649  /* Do nothing more unless we have a usable configuration */
650  if ( ( config == NULL ) ||
651  ( config->width == 0 ) || ( config->height == 0 ) ) {
652  return 0;
653  }
654 
655  /* Initialise EFI frame buffer */
656  if ( ( rc = efifb_init ( config ) ) != 0 )
657  return rc;
658 
659  /* Mark console as enabled */
660  efifb_console.disabled = 0;
662 
663  /* Set magic colour to transparent if we have a background picture */
664  if ( config->pixbuf )
666 
667  return 0;
668 }
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:513
#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:610
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:51
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 51 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:638
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
#define CONSOLE_EFIFB
Definition: efi_fbcon.c:62
static void efifb_putchar(int character)
Print a character to current cursor position.
Definition: efi_fbcon.c:627

EFI graphics output protocol console driver.

Definition at line 72 of file efi_fbcon.c.

◆ efifb

struct efifb efifb
static

The EFI frame buffer.

Definition at line 102 of file efi_fbcon.c.