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 )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efifb_glyph()

static void efifb_glyph ( unsigned int  character,
uint8_t glyph 
)
static

Get character glyph.

Parameters
characterCharacter
glyphCharacter glyph to fill in

Definition at line 100 of file efi_fbcon.c.

100  {
101  size_t offset = ( character * efifb.font.height );
102 
104 }
unsigned int height
Character height (in pixels)
Definition: fbcon.h:35
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
An EFI frame buffer.
Definition: efi_fbcon.c:69
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:86
userptr_t glyphs
Character glyphs.
Definition: efi_fbcon.c:88

References copy_from_user(), efifb::font, efifb::glyphs, fbcon_font::height, 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 111 of file efi_fbcon.c.

111  {
113  EFI_IMAGE_OUTPUT *blt;
115  size_t offset;
116  size_t len;
117  uint8_t bitmask;
118  unsigned int character;
119  unsigned int x;
120  unsigned int y;
121  EFI_STATUS efirc;
122  int rc;
123 
124  /* Get font height. The GetFontInfo() call nominally returns
125  * this information in an EFI_FONT_DISPLAY_INFO structure, but
126  * is known to fail on many UEFI implementations. Instead, we
127  * iterate over all printable characters to find the maximum
128  * height.
129  */
130  efifb.font.height = 0;
131  for ( character = 0 ; character < 256 ; character++ ) {
132 
133  /* Skip non-printable characters */
134  if ( ! isprint ( character ) )
135  continue;
136 
137  /* Get glyph */
138  blt = NULL;
139  if ( ( efirc = efifb.hiifont->GetGlyph ( efifb.hiifont,
140  character, NULL, &blt,
141  NULL ) ) != 0 ) {
142  rc = -EEFI ( efirc );
143  DBGC ( &efifb, "EFIFB could not get glyph %d: %s\n",
144  character, strerror ( rc ) );
145  continue;
146  }
147  assert ( blt != NULL );
148 
149  /* Calculate maximum height */
150  if ( efifb.font.height < blt->Height )
151  efifb.font.height = blt->Height;
152 
153  /* Free glyph */
154  bs->FreePool ( blt );
155  }
156  if ( ! efifb.font.height ) {
157  DBGC ( &efifb, "EFIFB could not get font height\n" );
158  return -ENOENT;
159  }
160 
161  /* Allocate glyph data */
162  len = ( 256 * efifb.font.height * sizeof ( bitmask ) );
163  efifb.glyphs = umalloc ( len );
164  if ( ! efifb.glyphs ) {
165  rc = -ENOMEM;
166  goto err_alloc;
167  }
168  memset_user ( efifb.glyphs, 0, 0, len );
169 
170  /* Get font data */
171  for ( character = 0 ; character < 256 ; character++ ) {
172 
173  /* Skip non-printable characters */
174  if ( ! isprint ( character ) )
175  continue;
176 
177  /* Get glyph */
178  blt = NULL;
179  if ( ( efirc = efifb.hiifont->GetGlyph ( efifb.hiifont,
180  character, NULL, &blt,
181  NULL ) ) != 0 ) {
182  rc = -EEFI ( efirc );
183  DBGC ( &efifb, "EFIFB could not get glyph %d: %s\n",
184  character, strerror ( rc ) );
185  continue;
186  }
187  assert ( blt != NULL );
188 
189  /* Sanity check */
190  if ( blt->Width > 8 ) {
191  DBGC ( &efifb, "EFIFB glyph %d invalid width %d\n",
192  character, blt->Width );
193  continue;
194  }
195  if ( blt->Height > efifb.font.height ) {
196  DBGC ( &efifb, "EFIFB glyph %d invalid height %d\n",
197  character, blt->Height );
198  continue;
199  }
200 
201  /* Convert glyph to bitmap */
202  pixel = blt->Image.Bitmap;
203  offset = ( character * efifb.font.height );
204  for ( y = 0 ; y < blt->Height ; y++ ) {
205  bitmask = 0;
206  for ( x = 0 ; x < blt->Width ; x++ ) {
207  bitmask = rol8 ( bitmask, 1 );
208  if ( pixel->Blue || pixel->Green || pixel->Red )
209  bitmask |= 0x01;
210  pixel++;
211  }
212  copy_to_user ( efifb.glyphs, offset++, &bitmask,
213  sizeof ( bitmask ) );
214  }
215 
216  /* Free glyph */
217  bs->FreePool ( blt );
218  }
219 
221  return 0;
222 
223  ufree ( efifb.glyphs );
224  err_alloc:
225  return rc;
226 }
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:2000
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:100
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:157
EFI_HII_GET_GLYPH GetGlyph
Definition: HiiFont.h:466
#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:42
An EFI frame buffer.
Definition: efi_fbcon.c:69
static int isprint(int character)
Check if character is printable.
Definition: ctype.h:86
EFI_GRAPHICS_OUTPUT_BLT_PIXEL * Bitmap
Definition: HiiImage.h:199
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
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:86
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
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:1855
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
uint32_t len
Length.
Definition: ena.h:14
static __always_inline userptr_t umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:54
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
union _EFI_IMAGE_OUTPUT::@496 Image
userptr_t glyphs
Character glyphs.
Definition: efi_fbcon.c:88
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
EFI_HII_FONT_PROTOCOL * hiifont
EFI HII font protocol.
Definition: efi_fbcon.c:73
Definition of EFI_IMAGE_OUTPUT.
Definition: HiiImage.h:195

References assert(), _EFI_IMAGE_OUTPUT::Bitmap, EFI_SYSTEM_TABLE::BootServices, copy_to_user(), DBGC, EEFI, efi_systab, efifb_glyph(), ENOENT, ENOMEM, efifb::font, EFI_BOOT_SERVICES::FreePool, _EFI_HII_FONT_PROTOCOL::GetGlyph, fbcon_font::glyph, efifb::glyphs, fbcon_font::height, _EFI_IMAGE_OUTPUT::Height, efifb::hiifont, _EFI_IMAGE_OUTPUT::Image, isprint(), len, memset_user(), NULL, offset, efifb::pixel, rc, strerror(), ufree(), umalloc(), and _EFI_IMAGE_OUTPUT::Width.

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

237  {
238  uint32_t check;
239 
240  /* Fill in LSB and scale */
241  *lsb = ( mask ? ( ffs ( mask ) - 1 ) : 0 );
242  *scale = ( mask ? ( 8 - ( fls ( mask ) - *lsb ) ) : 8 );
243 
244  /* Check that original mask was contiguous */
245  check = ( ( 0xff >> *scale ) << *lsb );
246  if ( check != mask )
247  return -ENOTSUP;
248 
249  return 0;
250 }
#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 259 of file efi_fbcon.c.

260  {
261  static EFI_PIXEL_BITMASK rgb_mask = {
262  0x000000ffUL, 0x0000ff00UL, 0x00ff0000UL, 0xff000000UL
263  };
264  static EFI_PIXEL_BITMASK bgr_mask = {
265  0x00ff0000UL, 0x0000ff00UL, 0x000000ffUL, 0xff000000UL
266  };
267  EFI_PIXEL_BITMASK *mask;
268  uint8_t reserved_scale;
269  uint8_t reserved_lsb;
270  int rc;
271 
272  /* Determine applicable mask */
273  switch ( info->PixelFormat ) {
275  mask = &rgb_mask;
276  break;
278  mask = &bgr_mask;
279  break;
280  case PixelBitMask:
281  mask = &info->PixelInformation;
282  break;
283  default:
284  DBGC ( &efifb, "EFIFB unrecognised pixel format %d\n",
285  info->PixelFormat );
286  return -ENOTSUP;
287  }
288 
289  /* Map each colour component */
290  if ( ( rc = efifb_colour_map_mask ( mask->RedMask, &map->red_scale,
291  &map->red_lsb ) ) != 0 )
292  return rc;
293  if ( ( rc = efifb_colour_map_mask ( mask->GreenMask, &map->green_scale,
294  &map->green_lsb ) ) != 0 )
295  return rc;
296  if ( ( rc = efifb_colour_map_mask ( mask->BlueMask, &map->blue_scale,
297  &map->blue_lsb ) ) != 0 )
298  return rc;
299  if ( ( rc = efifb_colour_map_mask ( mask->ReservedMask, &reserved_scale,
300  &reserved_lsb ) ) != 0 )
301  return rc;
302 
303  /* Calculate total number of bits per pixel */
304  return ( 32 - ( reserved_scale + map->red_scale + map->green_scale +
305  map->blue_scale ) );
306 }
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
uint8_t green_lsb
Green LSB.
Definition: fbcon.h:84
uint8_t red_lsb
Red LSB.
Definition: fbcon.h:82
#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:69
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
uint8_t red_scale
Red scale (right shift amount from 24-bit RGB)
Definition: fbcon.h:76
uint8_t green_scale
Green scale (right shift amount from 24-bit RGB)
Definition: fbcon.h:78
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:236
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,...
uint8_t blue_scale
Blue scale (right shift amount from 24-bit RGB)
Definition: fbcon.h:80
uint8_t blue_lsb
Blue LSB.
Definition: fbcon.h:86

References fbcon_colour_map::blue_lsb, fbcon_colour_map::blue_scale, EFI_PIXEL_BITMASK::BlueMask, DBGC, efifb_colour_map_mask(), ENOTSUP, fbcon_colour_map::green_lsb, fbcon_colour_map::green_scale, EFI_PIXEL_BITMASK::GreenMask, info, efifb::map, PixelBitMask, PixelBlueGreenRedReserved8BitPerColor, PixelRedGreenBlueReserved8BitPerColor, rc, fbcon_colour_map::red_lsb, fbcon_colour_map::red_scale, 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 316 of file efi_fbcon.c.

317  {
319  struct fbcon_colour_map map;
321  int best_mode_number = -ENOENT;
322  unsigned int best_score = INT_MAX;
323  unsigned int score;
324  unsigned int mode;
325  int bpp;
326  UINTN size;
327  EFI_STATUS efirc;
328  int rc;
329 
330  /* Find the best mode */
331  for ( mode = 0 ; mode < efifb.gop->Mode->MaxMode ; mode++ ) {
332 
333  /* Get mode information */
334  if ( ( efirc = efifb.gop->QueryMode ( efifb.gop, mode, &size,
335  &info ) ) != 0 ) {
336  rc = -EEFI ( efirc );
337  DBGC ( &efifb, "EFIFB could not get mode %d "
338  "information: %s\n", mode, strerror ( rc ) );
339  goto err_query;
340  }
341 
342  /* Skip unusable modes */
343  bpp = efifb_colour_map ( info, &map );
344  if ( bpp < 0 ) {
345  rc = bpp;
346  DBGC ( &efifb, "EFIFB could not build colour map for "
347  "mode %d: %s\n", mode, strerror ( rc ) );
348  goto err_map;
349  }
350 
351  /* Skip modes not meeting the requirements */
352  if ( ( info->HorizontalResolution < min_width ) ||
353  ( info->VerticalResolution < min_height ) ||
354  ( ( ( unsigned int ) bpp ) < min_bpp ) ) {
355  goto err_requirements;
356  }
357 
358  /* Select this mode if it has the best (i.e. lowest)
359  * score. We choose the scoring system to favour
360  * modes close to the specified width and height;
361  * within modes of the same width and height we prefer
362  * a higher colour depth.
363  */
364  score = ( ( info->HorizontalResolution *
365  info->VerticalResolution ) - bpp );
366  if ( score < best_score ) {
367  best_mode_number = mode;
368  best_score = score;
369  }
370 
371  err_requirements:
372  err_map:
373  bs->FreePool ( info );
374  err_query:
375  continue;
376  }
377 
378  if ( best_mode_number < 0 )
379  DBGC ( &efifb, "EFIFB found no suitable mode\n" );
380  return best_mode_number;
381 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:157
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:69
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:71
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:1836
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:259
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
UINT32 MaxMode
The number of modes supported by QueryMode() and SetMode().
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
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, 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 388 of file efi_fbcon.c.

388  {
389  EFI_STATUS efirc;
390  int rc;
391 
392  /* Restore original mode */
393  if ( ( efirc = efifb.gop->SetMode ( efifb.gop,
394  efifb.saved_mode ) ) != 0 ) {
395  rc = -EEFI ( efirc );
396  DBGC ( &efifb, "EFIFB could not restore mode %d: %s\n",
397  efifb.saved_mode, strerror ( rc ) );
398  return rc;
399  }
400 
401  return 0;
402 }
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:157
#define DBGC(...)
Definition: compiler.h:505
An EFI frame buffer.
Definition: efi_fbcon.c:69
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:71
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:35
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:75

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

410  {
413  void *interface;
414  int mode;
415  int bpp;
416  EFI_STATUS efirc;
417  int rc;
418 
419  /* Locate graphics output protocol */
421  NULL, &interface ) ) != 0 ) {
422  rc = -EEFI ( efirc );
423  DBGC ( &efifb, "EFIFB could not locate graphics output "
424  "protocol: %s\n", strerror ( rc ) );
425  goto err_locate_gop;
426  }
427  efifb.gop = interface;
428 
429  /* Locate HII font protocol */
430  if ( ( efirc = bs->LocateProtocol ( &efi_hii_font_protocol_guid,
431  NULL, &interface ) ) != 0 ) {
432  rc = -EEFI ( efirc );
433  DBGC ( &efifb, "EFIFB could not locate HII font protocol: %s\n",
434  strerror ( rc ) );
435  goto err_locate_hiifont;
436  }
438 
439  /* Locate glyphs */
440  if ( ( rc = efifb_glyphs() ) != 0 )
441  goto err_glyphs;
442 
443  /* Save original mode */
445 
446  /* Select mode */
447  if ( ( mode = efifb_select_mode ( config->width, config->height,
448  config->depth ) ) < 0 ) {
449  rc = mode;
450  goto err_select_mode;
451  }
452 
453  /* Set mode */
454  if ( ( efirc = efifb.gop->SetMode ( efifb.gop, mode ) ) != 0 ) {
455  rc = -EEFI ( efirc );
456  DBGC ( &efifb, "EFIFB could not set mode %d: %s\n",
457  mode, strerror ( rc ) );
458  goto err_set_mode;
459  }
460  info = efifb.gop->Mode->Info;
461 
462  /* Populate colour map */
463  bpp = efifb_colour_map ( info, &efifb.map );
464  if ( bpp < 0 ) {
465  rc = bpp;
466  DBGC ( &efifb, "EFIFB could not build colour map for "
467  "mode %d: %s\n", mode, strerror ( rc ) );
468  goto err_map;
469  }
470 
471  /* Populate pixel geometry */
472  efifb.pixel.width = info->HorizontalResolution;
473  efifb.pixel.height = info->VerticalResolution;
474  efifb.pixel.len = ( ( bpp + 7 ) / 8 );
475  efifb.pixel.stride = ( efifb.pixel.len * info->PixelsPerScanLine );
476 
477  /* Populate frame buffer address */
479  DBGC ( &efifb, "EFIFB using mode %d (%dx%d %dbpp at %#08lx)\n",
480  mode, efifb.pixel.width, efifb.pixel.height, bpp, efifb.start );
481 
482  /* Initialise frame buffer console */
483  if ( ( rc = fbcon_init ( &efifb.fbcon, phys_to_user ( efifb.start ),
484  &efifb.pixel, &efifb.map, &efifb.font,
485  config ) ) != 0 )
486  goto err_fbcon_init;
487 
488  return 0;
489 
490  fbcon_fini ( &efifb.fbcon );
491  err_fbcon_init:
492  err_map:
493  efifb_restore();
494  err_set_mode:
495  err_select_mode:
496  ufree ( efifb.glyphs );
497  err_glyphs:
498  err_locate_hiifont:
499  err_locate_gop:
500  return rc;
501 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:160
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:157
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:1914
EFI_GUID efi_graphics_output_protocol_guid
Graphics output protocol GUID.
Definition: efi_guid.c:152
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:78
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:111
struct fbcon_geometry pixel
Pixel geometry.
Definition: efi_fbcon.c:82
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:316
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:69
struct fbcon_colour_map map
Colour mapping.
Definition: efi_fbcon.c:84
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
EFI graphics output protocol.
Definition: efi_fbcon.c:71
size_t len
Length of a single entity.
Definition: fbcon.h:56
An object interface.
Definition: interface.h:109
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:583
struct fbcon_font font
Font definition.
Definition: efi_fbcon.c:86
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:259
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:54
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
userptr_t glyphs
Character glyphs.
Definition: efi_fbcon.c:88
EFI_SYSTEM_TABLE * efi_systab
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:75
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
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:73
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:388
physaddr_t start
Physical start address.
Definition: efi_fbcon.c:80

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

507  {
508 
509  /* Finalise frame buffer console */
510  fbcon_fini ( &efifb.fbcon );
511 
512  /* Restore saved mode */
513  efifb_restore();
514 
515  /* Free glyphs */
516  ufree ( efifb.glyphs );
517 }
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:78
An EFI frame buffer.
Definition: efi_fbcon.c:69
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:713
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
userptr_t glyphs
Character glyphs.
Definition: efi_fbcon.c:88
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:388

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

524  {
525 
526  fbcon_putchar ( &efifb.fbcon, character );
527 }
struct fbcon fbcon
Frame buffer console.
Definition: efi_fbcon.c:78
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:69

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

535  {
536  int rc;
537 
538  /* Reset console, if applicable */
539  if ( ! efifb_console.disabled ) {
540  efifb_fini();
543  }
544  efifb_console.disabled = CONSOLE_DISABLED;
545 
546  /* Do nothing more unless we have a usable configuration */
547  if ( ( config == NULL ) ||
548  ( config->width == 0 ) || ( config->height == 0 ) ) {
549  return 0;
550  }
551 
552  /* Initialise EFI frame buffer */
553  if ( ( rc = efifb_init ( config ) ) != 0 )
554  return rc;
555 
556  /* Mark console as enabled */
557  efifb_console.disabled = 0;
559 
560  /* Set magic colour to transparent if we have a background picture */
561  if ( config->pixbuf )
563 
564  return 0;
565 }
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:410
#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:507
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:362

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:535
#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:524

EFI graphics output protocol console driver.

Definition at line 66 of file efi_fbcon.c.

◆ efifb

struct efifb efifb
static

The EFI frame buffer.

Definition at line 92 of file efi_fbcon.c.