Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[efi] Add options to set console to native monitor resolution #47

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/hci/commands/console_cmd.c
Expand Up @@ -70,6 +70,10 @@ static struct option_descriptor console_opts[] = {
struct console_options, picture, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument,
struct console_options, keep, parse_flag ),
OPTION_DESC ( "auto", 'a', no_argument,
struct console_options, config.automode, parse_flag ),
OPTION_DESC ( "max-width", 'w', no_argument,
struct console_options, config.maxwidth, parse_flag ),
};

/** "console" command descriptor */
Expand Down
4 changes: 4 additions & 0 deletions src/include/ipxe/console.h
Expand Up @@ -38,6 +38,10 @@ struct console_configuration {
unsigned int bottom;
/** Background picture, if any */
struct pixel_buffer *pixbuf;
/** Automatically choose optimal mode */
int automode;
/** Automatically choose widest mode */
int maxwidth;
};

/**
Expand Down
59 changes: 43 additions & 16 deletions src/interface/efi/efi_fbcon.c
Expand Up @@ -311,10 +311,13 @@ static int efifb_colour_map ( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info,
* @v min_width Minimum required width (in pixels)
* @v min_height Minimum required height (in pixels)
* @v min_bpp Minimum required colour depth (in bits per pixel)
* @v automode Automatically choose optimum mode, ignoring width and height
* @v maxwidth Automatically choose widest mode, ignoring width and height
* @ret mode_number Mode number, or negative error
*/
static int efifb_select_mode ( unsigned int min_width, unsigned int min_height,
unsigned int min_bpp ) {
unsigned int min_bpp, unsigned int automode,
unsigned int maxwidth ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct fbcon_colour_map map;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
Expand Down Expand Up @@ -348,21 +351,43 @@ static int efifb_select_mode ( unsigned int min_width, unsigned int min_height,
goto err_map;
}

/* Skip modes not meeting the requirements */
if ( ( info->HorizontalResolution < min_width ) ||
( info->VerticalResolution < min_height ) ||
( ( ( unsigned int ) bpp ) < min_bpp ) ) {
goto err_requirements;
/* If automode is on, choose first available mode */
if ( automode && !maxwidth ) {
bs->FreePool ( info );
best_mode_number = mode;
break;
}

/* Select this mode if it has the best (i.e. lowest)
* score. We choose the scoring system to favour
* modes close to the specified width and height;
* within modes of the same width and height we prefer
* a higher colour depth.
*/
score = ( ( info->HorizontalResolution *
info->VerticalResolution ) - bpp );
/* If maxwidth is on, choose widest mode */
if ( maxwidth ) {
/* Select this mode if it has the best (i.e. lowest)
* score. We choose the scoring system to favour
* first the widest modes, then the tallest modes, then
* the modes with the largest depth.
*/

score = ( ( 1000000000 / info->HorizontalResolution ) +
( 1000000 / info->VerticalResolution ) +
bpp );

/* Otherwise, choose smallest mode that fits requirements */
} else {
/* Skip modes not meeting the requirements */
if ( ( info->HorizontalResolution < min_width ) ||
( info->VerticalResolution < min_height ) ||
( ( ( unsigned int ) bpp ) < min_bpp ) ) {
goto err_requirements;
}

/* Select this mode if it has the best (i.e. lowest)
* score. We choose the scoring system to favour
* modes close to the specified width and height;
* within modes of the same width and height we prefer
* a higher colour depth.
*/
score = ( ( info->HorizontalResolution *
info->VerticalResolution ) - bpp );
}
if ( score < best_score ) {
best_mode_number = mode;
best_score = score;
Expand Down Expand Up @@ -445,7 +470,8 @@ static int efifb_init ( struct console_configuration *config ) {

/* Select mode */
if ( ( mode = efifb_select_mode ( config->width, config->height,
config->depth ) ) < 0 ) {
config->depth, config->automode,
config->maxwidth ) ) < 0 ) {
rc = mode;
goto err_select_mode;
}
Expand Down Expand Up @@ -545,7 +571,8 @@ static int efifb_configure ( struct console_configuration *config ) {

/* Do nothing more unless we have a usable configuration */
if ( ( config == NULL ) ||
( config->width == 0 ) || ( config->height == 0 ) ) {
( ( ( config->width == 0 ) || ( config->height == 0 ) ) &&
( config->automode == 0 ) && ( config->maxwidth == 0 ) ) ) {
return 0;
}

Expand Down