Skip to content

Commit

Permalink
efi/gop: Allow specifying mode by <xres>x<yres>
Browse files Browse the repository at this point in the history
Add the ability to choose a video mode using a command-line argument of
the form
	video=efifb:<xres>x<yres>

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Link: https://lore.kernel.org/r/20200320020028.1936003-13-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
  • Loading branch information
Arvind Sankar authored and Ard Biesheuvel committed Apr 23, 2020
1 parent fffb680 commit d9ff032
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Documentation/fb/efifb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ mode=n
The EFI stub will set the mode of the display to mode number n if
possible.

<xres>x<yres>
The EFI stub will search for a display mode that matches the specified
horizontal and vertical resolution, and set the mode of the display to
it if one is found.

Edgar Hucek <gimli@dark-green.com>
84 changes: 83 additions & 1 deletion drivers/firmware/efi/libstub/gop.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* ----------------------------------------------------------------------- */

#include <linux/bitops.h>
#include <linux/ctype.h>
#include <linux/efi.h>
#include <linux/screen_info.h>
#include <linux/string.h>
Expand All @@ -17,11 +18,17 @@
enum efi_cmdline_option {
EFI_CMDLINE_NONE,
EFI_CMDLINE_MODE_NUM,
EFI_CMDLINE_RES
};

static struct {
enum efi_cmdline_option option;
u32 mode;
union {
u32 mode;
struct {
u32 width, height;
} res;
};
} cmdline __efistub_global = { .option = EFI_CMDLINE_NONE };

static bool parse_modenum(char *option, char **next)
Expand All @@ -41,11 +48,33 @@ static bool parse_modenum(char *option, char **next)
return true;
}

static bool parse_res(char *option, char **next)
{
u32 w, h;

if (!isdigit(*option))
return false;
w = simple_strtoull(option, &option, 10);
if (*option++ != 'x' || !isdigit(*option))
return false;
h = simple_strtoull(option, &option, 10);
if (*option && *option++ != ',')
return false;
cmdline.option = EFI_CMDLINE_RES;
cmdline.res.width = w;
cmdline.res.height = h;

*next = option;
return true;
}

void efi_parse_option_graphics(char *option)
{
while (*option) {
if (parse_modenum(option, &option))
continue;
if (parse_res(option, &option))
continue;

while (*option && *option++ != ',')
;
Expand Down Expand Up @@ -94,6 +123,56 @@ static u32 choose_mode_modenum(efi_graphics_output_protocol_t *gop)
return cmdline.mode;
}

static u32 choose_mode_res(efi_graphics_output_protocol_t *gop)
{
efi_status_t status;

efi_graphics_output_protocol_mode_t *mode;
efi_graphics_output_mode_info_t *info;
unsigned long info_size;

u32 max_mode, cur_mode;
int pf;
u32 m, w, h;

mode = efi_table_attr(gop, mode);

cur_mode = efi_table_attr(mode, mode);
info = efi_table_attr(mode, info);
w = info->horizontal_resolution;
h = info->vertical_resolution;

if (w == cmdline.res.width && h == cmdline.res.height)
return cur_mode;

max_mode = efi_table_attr(mode, max_mode);

for (m = 0; m < max_mode; m++) {
if (m == cur_mode)
continue;

status = efi_call_proto(gop, query_mode, m,
&info_size, &info);
if (status != EFI_SUCCESS)
continue;

pf = info->pixel_format;
w = info->horizontal_resolution;
h = info->vertical_resolution;

efi_bs_call(free_pool, info);

if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX)
continue;
if (w == cmdline.res.width && h == cmdline.res.height)
return m;
}

efi_printk("Couldn't find requested mode\n");

return cur_mode;
}

static void set_mode(efi_graphics_output_protocol_t *gop)
{
efi_graphics_output_protocol_mode_t *mode;
Expand All @@ -103,6 +182,9 @@ static void set_mode(efi_graphics_output_protocol_t *gop)
case EFI_CMDLINE_MODE_NUM:
new_mode = choose_mode_modenum(gop);
break;
case EFI_CMDLINE_RES:
new_mode = choose_mode_res(gop);
break;
default:
return;
}
Expand Down

0 comments on commit d9ff032

Please sign in to comment.