iPXE
efi_fbcon.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /**
27  * @file
28  *
29  * EFI frame buffer console
30  *
31  */
32 
33 #include <string.h>
34 #include <strings.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <assert.h>
38 #include <limits.h>
39 #include <ipxe/efi/efi.h>
42 #include <ipxe/ansicol.h>
43 #include <ipxe/fbcon.h>
44 #include <ipxe/console.h>
45 #include <ipxe/umalloc.h>
46 #include <ipxe/rotate.h>
47 #include <config/console.h>
48 
49 /* Avoid dragging in EFI console if not otherwise used */
50 extern struct console_driver efi_console;
52 
53 /* Set default console usage if applicable
54  *
55  * We accept either CONSOLE_FRAMEBUFFER or CONSOLE_EFIFB.
56  */
57 #if ( defined ( CONSOLE_FRAMEBUFFER ) && ! defined ( CONSOLE_EFIFB ) )
58 #define CONSOLE_EFIFB CONSOLE_FRAMEBUFFER
59 #endif
60 #if ! ( defined ( CONSOLE_EFIFB ) && CONSOLE_EXPLICIT ( CONSOLE_EFIFB ) )
61 #undef CONSOLE_EFIFB
62 #define CONSOLE_EFIFB ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
63 #endif
64 
65 /** Number of ASCII glyphs in cache */
66 #define EFIFB_ASCII 128
67 
68 /** Number of dynamic non-ASCII glyphs in cache */
69 #define EFIFB_DYNAMIC 32
70 
71 /* Forward declaration */
72 struct console_driver efifb_console __console_driver;
73 
74 /** An EFI frame buffer */
75 struct efifb {
76  /** EFI graphics output protocol */
78  /** EFI HII font protocol */
80  /** Saved mode */
82 
83  /** Frame buffer console */
84  struct fbcon fbcon;
85  /** Physical start address */
87  /** Pixel geometry */
89  /** Colour mapping */
91  /** Font definition */
92  struct fbcon_font font;
93  /** Character glyph cache */
95  /** Dynamic characters in cache */
96  unsigned int dynamic[EFIFB_DYNAMIC];
97  /** Next dynamic character cache entry to evict */
98  unsigned int next;
99 };
100 
101 /** The EFI frame buffer */
102 static struct efifb efifb;
103 
104 /**
105  * Draw character glyph
106  *
107  * @v character Character
108  * @v index Index within glyph cache
109  * @v toggle Bits to toggle in each bitmask
110  * @ret height Character height, or negative error
111  */
112 static int efifb_draw ( unsigned int character, unsigned int index,
113  unsigned int toggle ) {
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 }
174 
175 /**
176  * Draw "unknown character" glyph
177  *
178  * @v index Index within glyph cache
179  * @ret rc Return status code
180  */
181 static int efifb_draw_unknown ( unsigned int index ) {
182 
183  /* Draw an inverted '?' glyph */
184  return efifb_draw ( '?', index, -1U );
185 }
186 
187 /**
188  * Get dynamic glyph index
189  *
190  * @v character Unicode character
191  * @ret index Glyph cache index
192  */
193 static unsigned int efifb_dynamic ( unsigned int character ) {
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 }
221 
222 /**
223  * Get character glyph
224  *
225  * @v character Unicode character
226  * @v glyph Character glyph to fill in
227  */
228 static void efifb_glyph ( unsigned int character, uint8_t *glyph ) {
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 }
248 
249 /**
250  * Get character glyphs
251  *
252  * @ret rc Return status code
253  */
254 static int efifb_glyphs ( void ) {
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 }
330 
331 /**
332  * Generate colour mapping for a single colour component
333  *
334  * @v mask Mask value
335  * @v scale Scale value to fill in
336  * @v lsb LSB value to fill in
337  * @ret rc Return status code
338  */
339 static int efifb_colour_map_mask ( uint32_t mask, uint8_t *scale,
340  uint8_t *lsb ) {
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 }
354 
355 /**
356  * Generate colour mapping
357  *
358  * @v info EFI mode information
359  * @v map Colour mapping to fill in
360  * @ret bpp Number of bits per pixel, or negative error
361  */
363  struct fbcon_colour_map *map ) {
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 }
410 
411 /**
412  * Select video mode
413  *
414  * @v min_width Minimum required width (in pixels)
415  * @v min_height Minimum required height (in pixels)
416  * @v min_bpp Minimum required colour depth (in bits per pixel)
417  * @ret mode_number Mode number, or negative error
418  */
419 static int efifb_select_mode ( unsigned int min_width, unsigned int min_height,
420  unsigned int min_bpp ) {
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 }
485 
486 /**
487  * Restore video mode
488  *
489  * @v rc Return status code
490  */
491 static int efifb_restore ( void ) {
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 }
506 
507 /**
508  * Initialise EFI frame buffer
509  *
510  * @v config Console configuration, or NULL to reset
511  * @ret rc Return status code
512  */
513 static int efifb_init ( struct console_configuration *config ) {
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 }
605 
606 /**
607  * Finalise EFI frame buffer
608  *
609  */
610 static void efifb_fini ( void ) {
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 }
621 
622 /**
623  * Print a character to current cursor position
624  *
625  * @v character Character
626  */
627 static void efifb_putchar ( int character ) {
628 
629  fbcon_putchar ( &efifb.fbcon, character );
630 }
631 
632 /**
633  * Configure console
634  *
635  * @v config Console configuration, or NULL to reset
636  * @ret rc Return status code
637  */
638 static int efifb_configure ( struct console_configuration *config ) {
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 }
669 
670 /** EFI graphics output protocol console driver */
671 struct console_driver efifb_console __console_driver = {
672  .usage = CONSOLE_EFIFB,
673  .putchar = efifb_putchar,
674  .configure = efifb_configure,
675  .disabled = CONSOLE_DISABLED,
676 };
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
The Pixel definition of the physical frame buffer.
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A frame buffer geometry.
Definition: fbcon.h:51
static void efifb_glyph(unsigned int character, uint8_t *glyph)
Get character glyph.
Definition: efi_fbcon.c:228
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.
static int efifb_init(struct console_configuration *config)
Initialise EFI frame buffer.
Definition: efi_fbcon.c:513
#define max(x, y)
Definition: ath.h:39
#define EFIFB_ASCII
Number of ASCII glyphs in cache.
Definition: efi_fbcon.c:66
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:1995
Frame buffer console.
Error codes.
EFI_HII_GET_GLYPH GetGlyph
Definition: HiiFont.h:460
static int efifb_configure(struct console_configuration *config)
Configure console.
Definition: efi_fbcon.c:638
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 CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
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:411
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
#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
static void efifb_fini(void)
Finalise EFI frame buffer.
Definition: efi_fbcon.c:610
long index
Definition: bigint.h:62
#define ENOENT
No such file or directory.
Definition: errno.h:514
unsigned int UINT32
Definition: ProcessorBind.h:98
void fbcon_putchar(struct fbcon *fbcon, int character)
Print a character to current cursor position.
Definition: fbcon.c:441
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
void(* glyph)(unsigned int character, uint8_t *glyph)
Get character glyph.
Definition: fbcon.h:43
Character types.
static unsigned int efifb_dynamic(unsigned int character)
Get dynamic glyph index.
Definition: efi_fbcon.c:193
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.
A pixel is 32-bits and byte zero represents blue, byte one represents green, byte two represents red,...
A console configuration.
Definition: console.h:24
An EFI frame buffer.
Definition: efi_fbcon.c:75
int usage
Console usage bitmask.
Definition: console.h:101
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static int isprint(int character)
Check if character is printable.
Definition: ctype.h:97
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
EFI_GRAPHICS_OUTPUT_BLT_PIXEL * Bitmap
Definition: HiiImage.h:193
#define CONSOLE_DISABLED_OUTPUT
Console is disabled for output.
Definition: console.h:108
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.
EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode
#define ENOMEM
Not enough space.
Definition: errno.h:534
Provides a basic abstraction to set video modes and copy pixels to and from the graphics controller's...
uint32_t userptr_t
A pointer to a user buffer.
Definition: libkir.h:159
size_t len
Length of a single entity.
Definition: fbcon.h:57
Assertions.
A frame buffer console.
Definition: fbcon.h:113
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct console_driver efifb_console __console_driver
EFI graphics output protocol console driver.
Definition: efi_fbcon.c:72
An object interface.
Definition: interface.h:124
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
A frame buffer colour mapping.
Definition: fbcon.h:75
A 16-bit general register.
Definition: registers.h:24
static int efifb_draw(unsigned int character, unsigned int index, unsigned int toggle)
Draw character glyph.
Definition: efi_fbcon.c:112
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
struct console_driver efi_console
Definition: efi_fbcon.c:51
User interaction.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:718
static int efifb_draw_unknown(unsigned int index)
Draw "unknown character" glyph.
Definition: efi_fbcon.c:181
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
unsigned int next
Next dynamic character cache entry to evict.
Definition: efi_fbcon.c:98
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
static int efifb_colour_map(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, struct fbcon_colour_map *map)
Generate colour mapping.
Definition: efi_fbcon.c:362
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:398
User memory allocation.
unsigned char uint8_t
Definition: stdint.h:10
UINT64 UINTN
Unsigned value of native width.
A pixel is 32-bits and byte zero represents red, byte one represents green, byte two represents blue,...
UINT32 MaxMode
The number of modes supported by QueryMode() and SetMode().
EFI_PHYSICAL_ADDRESS FrameBufferBase
Base address of graphics linear frame buffer.
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
void ansicol_set_magic_transparent(void)
Set magic colour to transparent.
Definition: ansicoldef.c:189
unsigned int uint32_t
Definition: stdint.h:12
#define CONSOLE_EFIFB
Definition: efi_fbcon.c:62
#define ffs(x)
Find first (i.e.
Definition: strings.h:140
A font definition.
Definition: fbcon.h:34
Console configuration.
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1936
static void efifb_putchar(int character)
Print a character to current cursor position.
Definition: efi_fbcon.c:627
EFI API.
UINT32 Mode
Current Mode of the graphics device.
unsigned long physaddr_t
Definition: stdint.h:20
Graphics Output Protocol from the UEFI 2.0 specification.
int disabled
Console disabled flags.
Definition: console.h:62
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
#define DBGC2(...)
Definition: compiler.h:522
void ansicol_reset_magic(void)
Reset magic colour.
Definition: ansicoldef.c:179
The protocol provides the service to retrieve the font informations.
Definition: HiiFont.h:457
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
struct pixel_buffer * pixbuf
Background picture, if any.
Definition: console.h:40
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
A console driver.
Definition: console.h:55
#define INT_MAX
Definition: limits.h:37
#define fls(x)
Find last (i.e.
Definition: strings.h:166
UINT32 saved_mode
Saved mode.
Definition: efi_fbcon.c:81
The file provides services to retrieve font information.
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
String functions.
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
ANSI colours.
Definition of EFI_IMAGE_OUTPUT.
Definition: HiiImage.h:189
static int efifb_restore(void)
Restore video mode.
Definition: efi_fbcon.c:491
String functions.
Bit operations.
void * memset(void *dest, int character, size_t len) __nonnull
physaddr_t start
Physical start address.
Definition: efi_fbcon.c:86