Skip to content

Commit d9ff032

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/gop: Allow specifying mode by <xres>x<yres>
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent fffb680 commit d9ff032

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

Documentation/fb/efifb.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ mode=n
5050
The EFI stub will set the mode of the display to mode number n if
5151
possible.
5252

53+
<xres>x<yres>
54+
The EFI stub will search for a display mode that matches the specified
55+
horizontal and vertical resolution, and set the mode of the display to
56+
it if one is found.
57+
5358
Edgar Hucek <[email protected]>

drivers/firmware/efi/libstub/gop.c

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* ----------------------------------------------------------------------- */
77

88
#include <linux/bitops.h>
9+
#include <linux/ctype.h>
910
#include <linux/efi.h>
1011
#include <linux/screen_info.h>
1112
#include <linux/string.h>
@@ -17,11 +18,17 @@
1718
enum efi_cmdline_option {
1819
EFI_CMDLINE_NONE,
1920
EFI_CMDLINE_MODE_NUM,
21+
EFI_CMDLINE_RES
2022
};
2123

2224
static struct {
2325
enum efi_cmdline_option option;
24-
u32 mode;
26+
union {
27+
u32 mode;
28+
struct {
29+
u32 width, height;
30+
} res;
31+
};
2532
} cmdline __efistub_global = { .option = EFI_CMDLINE_NONE };
2633

2734
static bool parse_modenum(char *option, char **next)
@@ -41,11 +48,33 @@ static bool parse_modenum(char *option, char **next)
4148
return true;
4249
}
4350

51+
static bool parse_res(char *option, char **next)
52+
{
53+
u32 w, h;
54+
55+
if (!isdigit(*option))
56+
return false;
57+
w = simple_strtoull(option, &option, 10);
58+
if (*option++ != 'x' || !isdigit(*option))
59+
return false;
60+
h = simple_strtoull(option, &option, 10);
61+
if (*option && *option++ != ',')
62+
return false;
63+
cmdline.option = EFI_CMDLINE_RES;
64+
cmdline.res.width = w;
65+
cmdline.res.height = h;
66+
67+
*next = option;
68+
return true;
69+
}
70+
4471
void efi_parse_option_graphics(char *option)
4572
{
4673
while (*option) {
4774
if (parse_modenum(option, &option))
4875
continue;
76+
if (parse_res(option, &option))
77+
continue;
4978

5079
while (*option && *option++ != ',')
5180
;
@@ -94,6 +123,56 @@ static u32 choose_mode_modenum(efi_graphics_output_protocol_t *gop)
94123
return cmdline.mode;
95124
}
96125

126+
static u32 choose_mode_res(efi_graphics_output_protocol_t *gop)
127+
{
128+
efi_status_t status;
129+
130+
efi_graphics_output_protocol_mode_t *mode;
131+
efi_graphics_output_mode_info_t *info;
132+
unsigned long info_size;
133+
134+
u32 max_mode, cur_mode;
135+
int pf;
136+
u32 m, w, h;
137+
138+
mode = efi_table_attr(gop, mode);
139+
140+
cur_mode = efi_table_attr(mode, mode);
141+
info = efi_table_attr(mode, info);
142+
w = info->horizontal_resolution;
143+
h = info->vertical_resolution;
144+
145+
if (w == cmdline.res.width && h == cmdline.res.height)
146+
return cur_mode;
147+
148+
max_mode = efi_table_attr(mode, max_mode);
149+
150+
for (m = 0; m < max_mode; m++) {
151+
if (m == cur_mode)
152+
continue;
153+
154+
status = efi_call_proto(gop, query_mode, m,
155+
&info_size, &info);
156+
if (status != EFI_SUCCESS)
157+
continue;
158+
159+
pf = info->pixel_format;
160+
w = info->horizontal_resolution;
161+
h = info->vertical_resolution;
162+
163+
efi_bs_call(free_pool, info);
164+
165+
if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX)
166+
continue;
167+
if (w == cmdline.res.width && h == cmdline.res.height)
168+
return m;
169+
}
170+
171+
efi_printk("Couldn't find requested mode\n");
172+
173+
return cur_mode;
174+
}
175+
97176
static void set_mode(efi_graphics_output_protocol_t *gop)
98177
{
99178
efi_graphics_output_protocol_mode_t *mode;
@@ -103,6 +182,9 @@ static void set_mode(efi_graphics_output_protocol_t *gop)
103182
case EFI_CMDLINE_MODE_NUM:
104183
new_mode = choose_mode_modenum(gop);
105184
break;
185+
case EFI_CMDLINE_RES:
186+
new_mode = choose_mode_res(gop);
187+
break;
106188
default:
107189
return;
108190
}

0 commit comments

Comments
 (0)