Add the ability to choose a video mode for the selected gop by using a
command-line argument of the form
video=efifb:mode=<n>
Signed-off-by: Arvind Sankar <[email protected]>
---
Documentation/fb/efifb.rst | 20 +++-
.../firmware/efi/libstub/efi-stub-helper.c | 3 +
drivers/firmware/efi/libstub/efistub.h | 2 +
drivers/firmware/efi/libstub/gop.c | 107 ++++++++++++++++++
4 files changed, 129 insertions(+), 3 deletions(-)
diff --git a/Documentation/fb/efifb.rst b/Documentation/fb/efifb.rst
index 04840331a00e..367fbda2f4da 100644
--- a/Documentation/fb/efifb.rst
+++ b/Documentation/fb/efifb.rst
@@ -2,8 +2,10 @@
What is efifb?
==============
-This is a generic EFI platform driver for Intel based Apple computers.
-efifb is only for EFI booted Intel Macs.
+This is a generic EFI platform driver for systems with UEFI firmware. The
+system must be booted via the EFI stub for this to be usable. efifb supports
+both firmware with Graphics Output Protocol (GOP) displays as well as older
+systems with only Universal Graphics Adapter (UGA) displays.
Supported Hardware
==================
@@ -12,11 +14,14 @@ Supported Hardware
- Macbook
- Macbook Pro 15"/17"
- MacMini
+- ARM/ARM64/X86 systems with UEFI firmware
How to use it?
==============
-efifb does not have any kind of autodetection of your machine.
+For UGA displays, efifb does not have any kind of autodetection of your
+machine.
+
You have to add the following kernel parameters in your elilo.conf::
Macbook :
@@ -28,6 +33,9 @@ You have to add the following kernel parameters in your elilo.conf::
Macbook Pro 17", iMac 20" :
video=efifb:i20
+For GOP displays, efifb can autodetect the display's resolution and framebuffer
+address, so these should work out of the box without any special parameters.
+
Accepted options:
======= ===========================================================
@@ -36,4 +44,10 @@ nowc Don't map the framebuffer write combined. This can be used
when large amounts of console data are written.
======= ===========================================================
+Options for GOP displays:
+
+mode=n
+ The EFI stub will set the mode of the display to mode number n if
+ possible.
+
Edgar Hucek <[email protected]>
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index 9f34c7242939..c6092b6038cf 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -105,6 +105,9 @@ efi_status_t efi_parse_options(char const *cmdline)
efi_disable_pci_dma = true;
if (parse_option_str(val, "no_disable_early_pci_dma"))
efi_disable_pci_dma = false;
+ } else if (!strcmp(param, "video") &&
+ val && strstarts(val, "efifb:")) {
+ efi_parse_option_graphics(val + strlen("efifb:"));
}
}
efi_bs_call(free_pool, buf);
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index c400fd88fe38..4844c3bd40df 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -650,6 +650,8 @@ efi_status_t efi_relocate_kernel(unsigned long *image_addr,
efi_status_t efi_parse_options(char const *cmdline);
+void efi_parse_option_graphics(char *option);
+
efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
unsigned long size);
diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index 2d91699e3061..34b55715d372 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -8,11 +8,115 @@
#include <linux/bitops.h>
#include <linux/efi.h>
#include <linux/screen_info.h>
+#include <linux/string.h>
#include <asm/efi.h>
#include <asm/setup.h>
#include "efistub.h"
+enum efi_cmdline_option {
+ EFI_CMDLINE_NONE,
+ EFI_CMDLINE_MODE_NUM,
+};
+
+static struct {
+ enum efi_cmdline_option option;
+ u32 mode;
+} __efistub_global cmdline = { .option = EFI_CMDLINE_NONE };
+
+static bool parse_modenum(char *option, char **next)
+{
+ u32 m;
+
+ if (!strstarts(option, "mode="))
+ return false;
+ option += strlen("mode=");
+ m = simple_strtoull(option, &option, 0);
+ if (*option && *option++ != ',')
+ return false;
+ cmdline.option = EFI_CMDLINE_MODE_NUM;
+ cmdline.mode = m;
+
+ *next = option;
+ return true;
+}
+
+void efi_parse_option_graphics(char *option)
+{
+ while (*option) {
+ if (parse_modenum(option, &option))
+ continue;
+
+ while (*option && *option++ != ',')
+ ;
+ }
+}
+
+static u32 choose_mode_modenum(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;
+
+ mode = efi_table_attr(gop, mode);
+
+ cur_mode = efi_table_attr(mode, mode);
+ if (cmdline.mode == cur_mode)
+ return cur_mode;
+
+ max_mode = efi_table_attr(mode, max_mode);
+ if (cmdline.mode >= max_mode) {
+ efi_printk("Requested mode is invalid\n");
+ return cur_mode;
+ }
+
+ status = efi_call_proto(gop, query_mode, cmdline.mode,
+ &info_size, &info);
+ if (status != EFI_SUCCESS) {
+ efi_printk("Couldn't get mode information\n");
+ return cur_mode;
+ }
+
+ pf = info->pixel_format;
+
+ efi_bs_call(free_pool, info);
+
+ if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX) {
+ efi_printk("Invalid PixelFormat\n");
+ return cur_mode;
+ }
+
+ return cmdline.mode;
+}
+
+static void set_mode(efi_graphics_output_protocol_t *gop)
+{
+ efi_graphics_output_protocol_mode_t *mode;
+ u32 cur_mode, new_mode;
+
+ switch (cmdline.option) {
+ case EFI_CMDLINE_NONE:
+ return;
+ case EFI_CMDLINE_MODE_NUM:
+ new_mode = choose_mode_modenum(gop);
+ break;
+ }
+
+ mode = efi_table_attr(gop, mode);
+ cur_mode = efi_table_attr(mode, mode);
+
+ if (new_mode == cur_mode)
+ return;
+
+ if (efi_call_proto(gop, set_mode, new_mode) != EFI_SUCCESS)
+ efi_printk("Failed to set requested mode\n");
+}
+
static void find_bits(u32 mask, u8 *pos, u8 *size)
{
if (!mask) {
@@ -124,6 +228,9 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
if (!gop)
return EFI_NOT_FOUND;
+ /* Change mode if requested */
+ set_mode(gop);
+
/* EFI framebuffer */
mode = efi_table_attr(gop, mode);
info = efi_table_attr(mode, info);
--
2.24.1
Hi Arvind,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on efi/next]
[also build test WARNING on next-20200319]
[cannot apply to linux/master linus/master v5.6-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Arvind-Sankar/efi-gop-Refactoring-mode-setting-feature/20200320-044605
base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> drivers/firmware/efi/libstub/gop.c:25:1: warning: 'section' attribute does not apply to types [-Wattributes]
25 | } __efistub_global cmdline = { .option = EFI_CMDLINE_NONE };
| ^
drivers/firmware/efi/libstub/gop.c: In function 'efi_setup_gop':
drivers/firmware/efi/libstub/gop.c:116:21: warning: 'new_mode' may be used uninitialized in this function [-Wmaybe-uninitialized]
116 | if (efi_call_proto(gop, set_mode, new_mode) != EFI_SUCCESS)
| ^~~
drivers/firmware/efi/libstub/gop.c:100:16: note: 'new_mode' was declared here
100 | u32 cur_mode, new_mode;
| ^~~~~~~~
vim +/section +25 drivers/firmware/efi/libstub/gop.c
21
22 static struct {
23 enum efi_cmdline_option option;
24 u32 mode;
> 25 } __efistub_global cmdline = { .option = EFI_CMDLINE_NONE };
26
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Hi Arvind,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on efi/next]
[also build test WARNING on next-20200319]
[cannot apply to linux/master linus/master v5.6-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Arvind-Sankar/efi-gop-Refactoring-mode-setting-feature/20200320-044605
base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
config: arm64-defconfig (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <[email protected]>
Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
All warnings (new ones prefixed by >>):
drivers/firmware/efi/libstub/gop.c: In function 'efi_setup_gop':
>> drivers/firmware/efi/libstub/gop.c:116:21: warning: 'new_mode' may be used uninitialized in this function [-Wmaybe-uninitialized]
116 | if (efi_call_proto(gop, set_mode, new_mode) != EFI_SUCCESS)
| ^~~
drivers/firmware/efi/libstub/gop.c:100:16: note: 'new_mode' was declared here
100 | u32 cur_mode, new_mode;
| ^~~~~~~~
vim +/new_mode +116 drivers/firmware/efi/libstub/gop.c
96
97 static void set_mode(efi_graphics_output_protocol_t *gop)
98 {
99 efi_graphics_output_protocol_mode_t *mode;
100 u32 cur_mode, new_mode;
101
102 switch (cmdline.option) {
103 case EFI_CMDLINE_NONE:
104 return;
105 case EFI_CMDLINE_MODE_NUM:
106 new_mode = choose_mode_modenum(gop);
107 break;
108 }
109
110 mode = efi_table_attr(gop, mode);
111 cur_mode = efi_table_attr(mode, mode);
112
113 if (new_mode == cur_mode)
114 return;
115
> 116 if (efi_call_proto(gop, set_mode, new_mode) != EFI_SUCCESS)
117 efi_printk("Failed to set requested mode\n");
118 }
119
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Hi Arvind,
Thank you for the patch! Perhaps something to improve:
url: https://github.com/0day-ci/linux/commits/Arvind-Sankar/efi-gop-Refactoring-mode-setting-feature/20200320-044605
base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
New smatch warnings:
drivers/firmware/efi/libstub/gop.c:113 set_mode() error: uninitialized symbol 'new_mode'.
# https://github.com/0day-ci/linux/commit/af85e496c9f577df9743784171b1cda94220dd8f
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout af85e496c9f577df9743784171b1cda94220dd8f
vim +/info +85 drivers/firmware/efi/libstub/gop.c
af85e496c9f577 Arvind Sankar 2020-03-19 97 static void set_mode(efi_graphics_output_protocol_t *gop)
af85e496c9f577 Arvind Sankar 2020-03-19 98 {
af85e496c9f577 Arvind Sankar 2020-03-19 99 efi_graphics_output_protocol_mode_t *mode;
af85e496c9f577 Arvind Sankar 2020-03-19 100 u32 cur_mode, new_mode;
af85e496c9f577 Arvind Sankar 2020-03-19 101
af85e496c9f577 Arvind Sankar 2020-03-19 102 switch (cmdline.option) {
af85e496c9f577 Arvind Sankar 2020-03-19 103 case EFI_CMDLINE_NONE:
af85e496c9f577 Arvind Sankar 2020-03-19 104 return;
af85e496c9f577 Arvind Sankar 2020-03-19 105 case EFI_CMDLINE_MODE_NUM:
af85e496c9f577 Arvind Sankar 2020-03-19 106 new_mode = choose_mode_modenum(gop);
af85e496c9f577 Arvind Sankar 2020-03-19 107 break;
No default case?
af85e496c9f577 Arvind Sankar 2020-03-19 108 }
af85e496c9f577 Arvind Sankar 2020-03-19 109
af85e496c9f577 Arvind Sankar 2020-03-19 110 mode = efi_table_attr(gop, mode);
af85e496c9f577 Arvind Sankar 2020-03-19 111 cur_mode = efi_table_attr(mode, mode);
af85e496c9f577 Arvind Sankar 2020-03-19 112
af85e496c9f577 Arvind Sankar 2020-03-19 @113 if (new_mode == cur_mode)
af85e496c9f577 Arvind Sankar 2020-03-19 114 return;
af85e496c9f577 Arvind Sankar 2020-03-19 115
af85e496c9f577 Arvind Sankar 2020-03-19 116 if (efi_call_proto(gop, set_mode, new_mode) != EFI_SUCCESS)
af85e496c9f577 Arvind Sankar 2020-03-19 117 efi_printk("Failed to set requested mode\n");
af85e496c9f577 Arvind Sankar 2020-03-19 118 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
On Fri, Mar 20, 2020 at 05:36:04PM +0300, Dan Carpenter wrote:
> Hi Arvind,
>
> Thank you for the patch! Perhaps something to improve:
>
> url: https://github.com/0day-ci/linux/commits/Arvind-Sankar/efi-gop-Refactoring-mode-setting-feature/20200320-044605
> base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next
>
> If you fix the issue, kindly add following tag
> Reported-by: kbuild test robot <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
>
> New smatch warnings:
> drivers/firmware/efi/libstub/gop.c:113 set_mode() error: uninitialized symbol 'new_mode'.
>
> # https://github.com/0day-ci/linux/commit/af85e496c9f577df9743784171b1cda94220dd8f
> git remote add linux-review https://github.com/0day-ci/linux
> git remote update linux-review
> git checkout af85e496c9f577df9743784171b1cda94220dd8f
> vim +/info +85 drivers/firmware/efi/libstub/gop.c
>
> af85e496c9f577 Arvind Sankar 2020-03-19 97 static void set_mode(efi_graphics_output_protocol_t *gop)
> af85e496c9f577 Arvind Sankar 2020-03-19 98 {
> af85e496c9f577 Arvind Sankar 2020-03-19 99 efi_graphics_output_protocol_mode_t *mode;
> af85e496c9f577 Arvind Sankar 2020-03-19 100 u32 cur_mode, new_mode;
> af85e496c9f577 Arvind Sankar 2020-03-19 101
> af85e496c9f577 Arvind Sankar 2020-03-19 102 switch (cmdline.option) {
> af85e496c9f577 Arvind Sankar 2020-03-19 103 case EFI_CMDLINE_NONE:
> af85e496c9f577 Arvind Sankar 2020-03-19 104 return;
> af85e496c9f577 Arvind Sankar 2020-03-19 105 case EFI_CMDLINE_MODE_NUM:
> af85e496c9f577 Arvind Sankar 2020-03-19 106 new_mode = choose_mode_modenum(gop);
> af85e496c9f577 Arvind Sankar 2020-03-19 107 break;
>
> No default case?
Yeah, it's an enum with the only two values covered by the switch cases,
so it's really a bogus warning. I posted a v2 with a default case
instead anyway to silence it.
>
> af85e496c9f577 Arvind Sankar 2020-03-19 108 }
> af85e496c9f577 Arvind Sankar 2020-03-19 109
> af85e496c9f577 Arvind Sankar 2020-03-19 110 mode = efi_table_attr(gop, mode);
> af85e496c9f577 Arvind Sankar 2020-03-19 111 cur_mode = efi_table_attr(mode, mode);
> af85e496c9f577 Arvind Sankar 2020-03-19 112
> af85e496c9f577 Arvind Sankar 2020-03-19 @113 if (new_mode == cur_mode)
> af85e496c9f577 Arvind Sankar 2020-03-19 114 return;
> af85e496c9f577 Arvind Sankar 2020-03-19 115
> af85e496c9f577 Arvind Sankar 2020-03-19 116 if (efi_call_proto(gop, set_mode, new_mode) != EFI_SUCCESS)
> af85e496c9f577 Arvind Sankar 2020-03-19 117 efi_printk("Failed to set requested mode\n");
> af85e496c9f577 Arvind Sankar 2020-03-19 118 }
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/[email protected]