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)
 
 FILE_SECBOOT (PERMITTED)
 
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 64 of file efi_fbcon.c.

◆ EFIFB_ASCII

#define EFIFB_ASCII   128

Number of ASCII glyphs in cache.

Definition at line 68 of file efi_fbcon.c.

◆ EFIFB_DYNAMIC

#define EFIFB_DYNAMIC   32

Number of dynamic non-ASCII glyphs in cache.

Definition at line 71 of file efi_fbcon.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

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

115  {
117  EFI_IMAGE_OUTPUT *blt;
119  unsigned int height;
120  unsigned int x;
121  unsigned int y;
122  uint8_t *glyph;
123  uint8_t bitmask;
124  EFI_STATUS efirc;
125  int rc;
126 
127  /* Clear existing glyph */
128  glyph = &efifb.glyphs[ index * efifb.font.height ];
129  memset ( glyph, 0, efifb.font.height );
130 
131  /* Get glyph */
132  blt = NULL;
133  if ( ( efirc = efifb.hiifont->GetGlyph ( efifb.hiifont, character,
134  NULL, &blt, NULL ) ) != 0 ) {
135  rc = -EEFI ( efirc );
136  DBGC ( &efifb, "EFIFB could not get glyph %#02x: %s\n",
137  character, strerror ( rc ) );
138  goto err_get;
139  }
140  assert ( blt != NULL );
141 
142  /* Sanity check */
143  if ( blt->Width > 8 ) {
144  DBGC ( &efifb, "EFIFB glyph %#02x invalid width %d\n",
145  character, blt->Width );
146  rc = -EINVAL;
147  goto err_width;
148  }
149 
150  /* Convert glyph to bitmap */
151  pixel = blt->Image.Bitmap;
152  height = blt->Height;
153  for ( y = 0 ; ( ( y < height ) && ( y < efifb.font.height ) ) ; y++ ) {
154  bitmask = 0;
155  for ( x = 0 ; x < blt->Width ; x++ ) {
156  bitmask = rol8 ( bitmask, 1 );
157  if ( pixel->Blue || pixel->Green || pixel->Red )
158  bitmask |= 0x01;
159  pixel++;
160  }
161  bitmask ^= toggle;
162  *(glyph++) = bitmask;
163  }
164 
165  /* Free glyph */
166  bs->FreePool ( blt );
167 
168  return height;
169 
170  err_width:
171  bs->FreePool ( blt );
172  err_get:
173  return rc;
174 }
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:2099
#define EINVAL
Invalid argument.
Definition: errno.h:429
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:175
EFI_HII_GET_GLYPH GetGlyph
Definition: HiiFont.h:461
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
static unsigned int x
Definition: pixbuf.h:63
An EFI frame buffer.
Definition: efi_fbcon.c:77
EFI_GRAPHICS_OUTPUT_BLT_PIXEL * Bitmap
Definition: HiiImage.h:194
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:94
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
unsigned char uint8_t
Definition: stdint.h:10
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1950
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
static unsigned int unsigned int y
Definition: pixbuf.h:63
EFI_SYSTEM_TABLE * efi_systab
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:96
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
EFI_HII_FONT_PROTOCOL * hiifont
EFI HII font protocol.
Definition: efi_fbcon.c:81
Definition of EFI_IMAGE_OUTPUT.
Definition: HiiImage.h:190
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 182 of file efi_fbcon.c.

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

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

194  {
195  unsigned int dynamic;
196  unsigned int index;
197  unsigned int i;
198  int height;
199 
200  /* Search existing cached entries */
201  for ( i = 0 ; i < EFIFB_DYNAMIC ; i++ ) {
202  if ( character == efifb.dynamic[i] )
203  return ( EFIFB_ASCII + i );
204  }
205 
206  /* Overwrite the oldest cache entry */
207  dynamic = ( efifb.next++ % EFIFB_DYNAMIC );
208  index = ( EFIFB_ASCII + dynamic );
209  DBGC2 ( &efifb, "EFIFB dynamic %#02x is glyph %#02x\n",
210  dynamic, character );
211 
212  /* Draw glyph */
213  height = efifb_draw ( character, index, 0 );
214  if ( height < 0 )
216 
217  /* Record cached character */
218  efifb.dynamic[dynamic] = character;
219 
220  return index;
221 }
#define EFIFB_ASCII
Number of ASCII glyphs in cache.
Definition: efi_fbcon.c:68
long index
Definition: bigint.h:65
An EFI frame buffer.
Definition: efi_fbcon.c:77
unsigned int dynamic[EFIFB_DYNAMIC]
Dynamic characters in cache.
Definition: efi_fbcon.c:98
#define EFIFB_DYNAMIC
Number of dynamic non-ASCII glyphs in cache.
Definition: efi_fbcon.c:71
static int efifb_draw(unsigned int character, unsigned int index, unsigned int toggle)
Draw character glyph.
Definition: efi_fbcon.c:114
static int efifb_draw_unknown(unsigned int index)
Draw "unknown character" glyph.
Definition: efi_fbcon.c:182
unsigned int next
Next dynamic character cache entry to evict.
Definition: efi_fbcon.c:100
#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 229 of file efi_fbcon.c.

229  {
230  unsigned int index;
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  /* Return cached glyph */
245  return &efifb.glyphs[ index * efifb.font.height ];
246 }
unsigned int height
Character height (in pixels)
Definition: fbcon.h:36
#define EFIFB_ASCII
Number of ASCII glyphs in cache.
Definition: efi_fbcon.c:68
long index
Definition: bigint.h:65
static unsigned int efifb_dynamic(unsigned int character)
Get dynamic glyph index.
Definition: efi_fbcon.c:194
An EFI frame buffer.
Definition: efi_fbcon.c:77
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:94
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:96

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

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

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

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

362  {
363  static EFI_PIXEL_BITMASK rgb_mask = {
364  0x000000ffUL, 0x0000ff00UL, 0x00ff0000UL, 0xff000000UL
365  };
366  static EFI_PIXEL_BITMASK bgr_mask = {
367  0x00ff0000UL, 0x0000ff00UL, 0x000000ffUL, 0xff000000UL
368  };
369  EFI_PIXEL_BITMASK *mask;
370  uint8_t reserved_scale;
371  uint8_t reserved_lsb;
372  int rc;
373 
374  /* Determine applicable mask */
375  switch ( info->PixelFormat ) {
377  mask = &rgb_mask;
378  break;
380  mask = &bgr_mask;
381  break;
382  case PixelBitMask:
383  mask = &info->PixelInformation;
384  break;
385  default:
386  DBGC ( &efifb, "EFIFB unrecognised pixel format %d\n",
387  info->PixelFormat );
388  return -ENOTSUP;
389  }
390 
391  /* Map each colour component */
392  if ( ( rc = efifb_colour_map_mask ( mask->RedMask, &map->red_scale,
393  &map->red_lsb ) ) != 0 )
394  return rc;
395  if ( ( rc = efifb_colour_map_mask ( mask->GreenMask, &map->green_scale,
396  &map->green_lsb ) ) != 0 )
397  return rc;
398  if ( ( rc = efifb_colour_map_mask ( mask->BlueMask, &map->blue_scale,
399  &map->blue_lsb ) ) != 0 )
400  return rc;
401  if ( ( rc = efifb_colour_map_mask ( mask->ReservedMask, &reserved_scale,
402  &reserved_lsb ) ) != 0 )
403  return rc;
404 
405  /* Calculate total number of bits per pixel */
406  return ( 32 - ( reserved_scale + map->red_scale + map->green_scale +
407  map->blue_scale ) );
408 }
The Pixel definition of the physical frame buffer.
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
u32 info
Definition: ar9003_mac.h:24
#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:77
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
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:338
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:184

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

419  {
421  struct fbcon_colour_map map;
423  int best_mode_number = -ENOENT;
424  unsigned int best_score = INT_MAX;
425  unsigned int score;
426  unsigned int mode;
427  int bpp;
428  UINTN size;
429  EFI_STATUS efirc;
430  int rc;
431 
432  /* Find the best mode */
433  for ( mode = 0 ; mode < efifb.gop->Mode->MaxMode ; mode++ ) {
434 
435  /* Get mode information */
436  if ( ( efirc = efifb.gop->QueryMode ( efifb.gop, mode, &size,
437  &info ) ) != 0 ) {
438  rc = -EEFI ( efirc );
439  DBGC ( &efifb, "EFIFB could not get mode %d "
440  "information: %s\n", mode, strerror ( rc ) );
441  goto err_query;
442  }
443 
444  /* Skip unusable modes */
445  bpp = efifb_colour_map ( info, &map );
446  if ( bpp < 0 ) {
447  rc = bpp;
448  DBGC ( &efifb, "EFIFB could not build colour map for "
449  "mode %d: %s\n", mode, strerror ( rc ) );
450  goto err_map;
451  }
452 
453  /* Skip modes not meeting the requirements */
454  if ( ( info->HorizontalResolution < min_width ) ||
455  ( info->VerticalResolution < min_height ) ||
456  ( ( ( unsigned int ) bpp ) < min_bpp ) ) {
457  goto err_requirements;
458  }
459 
460  /* Select this mode if it has the best (i.e. lowest)
461  * score. We choose the scoring system to favour
462  * modes close to the specified width and height;
463  * within modes of the same width and height we prefer
464  * a higher colour depth.
465  */
466  score = ( ( info->HorizontalResolution *
467  info->VerticalResolution ) - bpp );
468  if ( score < best_score ) {
469  best_mode_number = mode;
470  best_score = score;
471  }
472 
473  err_requirements:
474  err_map:
475  bs->FreePool ( info );
476  err_query:
477  continue;
478  }
479 
480  if ( best_mode_number < 0 )
481  DBGC ( &efifb, "EFIFB found no suitable mode\n" );
482  return best_mode_number;
483 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
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:175
u32 info
Definition: ar9003_mac.h:24
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:515
An EFI frame buffer.
Definition: efi_fbcon.c:77
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:79
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:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:361
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:1950
static __always_inline int struct dma_mapping * map
Definition: dma.h:184
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
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 490 of file efi_fbcon.c.

490  {
491  EFI_STATUS efirc;
492  int rc;
493 
494  /* Restore original mode */
495  if ( ( efirc = efifb.gop->SetMode ( efifb.gop,
496  efifb.saved_mode ) ) != 0 ) {
497  rc = -EEFI ( efirc );
498  DBGC ( &efifb, "EFIFB could not restore mode %d: %s\n",
499  efifb.saved_mode, strerror ( rc ) );
500  return rc;
501  }
502 
503  return 0;
504 }
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:175
#define DBGC(...)
Definition: compiler.h:505
An EFI frame buffer.
Definition: efi_fbcon.c:77
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:79
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:83

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

512  {
515  void *interface;
516  int mode;
517  int bpp;
518  EFI_STATUS efirc;
519  int rc;
520 
521  /* Locate graphics output protocol */
523  NULL, &interface ) ) != 0 ) {
524  rc = -EEFI ( efirc );
525  DBGC ( &efifb, "EFIFB could not locate graphics output "
526  "protocol: %s\n", strerror ( rc ) );
527  goto err_locate_gop;
528  }
529  efifb.gop = interface;
530 
531  /* Locate HII font protocol */
532  if ( ( efirc = bs->LocateProtocol ( &efi_hii_font_protocol_guid,
533  NULL, &interface ) ) != 0 ) {
534  rc = -EEFI ( efirc );
535  DBGC ( &efifb, "EFIFB could not locate HII font protocol: %s\n",
536  strerror ( rc ) );
537  goto err_locate_hiifont;
538  }
540 
541  /* Locate glyphs */
542  if ( ( rc = efifb_glyphs() ) != 0 )
543  goto err_glyphs;
544 
545  /* Save original mode */
547 
548  /* Select mode */
549  if ( ( mode = efifb_select_mode ( config->width, config->height,
550  config->depth ) ) < 0 ) {
551  rc = mode;
552  goto err_select_mode;
553  }
554 
555  /* Set mode */
556  if ( ( efirc = efifb.gop->SetMode ( efifb.gop, mode ) ) != 0 ) {
557  rc = -EEFI ( efirc );
558  DBGC ( &efifb, "EFIFB could not set mode %d: %s\n",
559  mode, strerror ( rc ) );
560  goto err_set_mode;
561  }
562  info = efifb.gop->Mode->Info;
563 
564  /* Populate colour map */
565  bpp = efifb_colour_map ( info, &efifb.map );
566  if ( bpp < 0 ) {
567  rc = bpp;
568  DBGC ( &efifb, "EFIFB could not build colour map for "
569  "mode %d: %s\n", mode, strerror ( rc ) );
570  goto err_map;
571  }
572 
573  /* Populate pixel geometry */
574  efifb.pixel.width = info->HorizontalResolution;
575  efifb.pixel.height = info->VerticalResolution;
576  efifb.pixel.len = ( ( bpp + 7 ) / 8 );
577  efifb.pixel.stride = ( efifb.pixel.len * info->PixelsPerScanLine );
578 
579  /* Populate frame buffer address */
581  DBGC ( &efifb, "EFIFB using mode %d (%dx%d %dbpp at %#08lx)\n",
583 
584  /* Initialise frame buffer console */
585  if ( ( rc = fbcon_init ( &efifb.fbcon, phys_to_virt ( efifb.start ),
586  &efifb.pixel, &efifb.map, &efifb.font,
587  config ) ) != 0 )
588  goto err_fbcon_init;
589 
590  return 0;
591 
592  fbcon_fini ( &efifb.fbcon );
593  err_fbcon_init:
594  err_map:
595  efifb_restore();
596  err_set_mode:
597  err_select_mode:
598  ufree ( efifb.glyphs );
599  err_glyphs:
600  err_locate_hiifont:
601  err_locate_gop:
602  return rc;
603 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:68
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
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:225
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
unsigned int height
Height.
Definition: console.h:29
u32 info
Definition: ar9003_mac.h:24
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:601
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:2009
uint16_t mode
Acceleration mode.
Definition: ena.h:26
EFI_GUID efi_graphics_output_protocol_guid
Graphics output protocol GUID.
Definition: efi_guid.c:217
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:86
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:253
struct fbcon_geometry pixel
Pixel geometry.
Definition: efi_fbcon.c:90
static int efifb_select_mode(unsigned int min_width, unsigned int min_height, unsigned int min_bpp)
Select video mode.
Definition: efi_fbcon.c:418
unsigned int width
Width.
Definition: console.h:27
unsigned int depth
Colour depth.
Definition: console.h:31
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * Info
Pointer to read-only EFI_GRAPHICS_OUTPUT_MODE_INFORMATION data.
An EFI frame buffer.
Definition: efi_fbcon.c:77
struct fbcon_colour_map map
Colour mapping.
Definition: efi_fbcon.c:92
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:79
size_t len
Length of a single entity.
Definition: fbcon.h:57
An object interface.
Definition: interface.h:125
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:94
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:729
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:361
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:55
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
EFI_SYSTEM_TABLE * efi_systab
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:83
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:96
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
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:81
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:490
physaddr_t start
Physical start address.
Definition: efi_fbcon.c:88

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

609  {
610 
611  /* Finalise frame buffer console */
612  fbcon_fini ( &efifb.fbcon );
613 
614  /* Restore saved mode */
615  efifb_restore();
616 
617  /* Free glyphs */
618  ufree ( efifb.glyphs );
619 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:68
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:86
An EFI frame buffer.
Definition: efi_fbcon.c:77
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:729
uint8_t * glyphs
Character glyph cache.
Definition: efi_fbcon.c:96
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:490

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

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

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

637  {
638  int rc;
639 
640  /* Reset console, if applicable */
641  if ( ! efifb_console.disabled ) {
642  efifb_fini();
645  }
646  efifb_console.disabled = CONSOLE_DISABLED;
647 
648  /* Do nothing more unless we have a usable configuration */
649  if ( ( config == NULL ) ||
650  ( config->width == 0 ) || ( config->height == 0 ) ) {
651  return 0;
652  }
653 
654  /* Initialise EFI frame buffer */
655  if ( ( rc = efifb_init ( config ) ) != 0 )
656  return rc;
657 
658  /* Mark console as enabled */
659  efifb_console.disabled = 0;
661 
662  /* Set magic colour to transparent if we have a background picture */
663  if ( config->pixbuf )
665 
666  return 0;
667 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int height
Height.
Definition: console.h:29
static int efifb_init(struct console_configuration *config)
Initialise EFI frame buffer.
Definition: efi_fbcon.c:512
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:112
static void efifb_fini(void)
Finalise EFI frame buffer.
Definition: efi_fbcon.c:609
unsigned int width
Width.
Definition: console.h:27
#define CONSOLE_DISABLED_OUTPUT
Console is disabled for output.
Definition: console.h:109
struct console_driver efi_console
Definition: efi_fbcon.c:53
void ansicol_set_magic_transparent(void)
Set magic colour to transparent.
Definition: ansicoldef.c:190
int disabled
Console disabled flags.
Definition: console.h:63
void ansicol_reset_magic(void)
Reset magic colour.
Definition: ansicoldef.c:180
struct pixel_buffer * pixbuf
Background picture, if any.
Definition: console.h:41
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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 53 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:637
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:112
#define CONSOLE_EFIFB
Definition: efi_fbcon.c:64
static void efifb_putchar(int character)
Print a character to current cursor position.
Definition: efi_fbcon.c:626

EFI graphics output protocol console driver.

Definition at line 74 of file efi_fbcon.c.

◆ efifb

struct efifb efifb
static

The EFI frame buffer.

Definition at line 104 of file efi_fbcon.c.