x86/gfx: early boot improvements
v4 cover x86/gfx: early boot improvements
Hello,
The following series contains some fixes and improvements related to graphics usage when booting Xen.
Proposed patches fix some shortcomings when using multiboot2, like the ignoring of the vga= parameter and forcefully switching the console to the maximum supported resolution.
Thanks, Roger.
Roger Pau Monne (3):
multiboot2: parse vga= option when setting GOP mode
multiboot2: do not set StdOut mode unconditionally
cmdline: parse multiple instances of the vga option
xen/arch/x86/boot/cmdline.c | 83 ++++++++++++++++--------------- xen/arch/x86/boot/head.S | 13 ++++- xen/arch/x86/efi/efi-boot.h | 82 ++++++++++++++++++++++++++++-- xen/arch/x86/x86_64/asm-offsets.c | 1 + 4 files changed, 133 insertions(+), 46 deletions(-)
Signature · 1 line
2.41.0
PATCH v4 1/3 multiboot2: parse vga= option when setting GOP mode
Introduce support for passing the command line to the efi_multiboot2() helper, and parse the vga= option if present.
Add support for the 'gfx' and 'current' vga options, ignore the 'keep' option, and print a warning message about other options not being currently implemented.
Note that the multboot2 command line string must always be zero-terminated according to the multiboot2 specification, and hence there's no need to pass the string size to efi_multiboot2().
---
Changes since v3:
- s/last/cur/
- asm style fixes.
- Add note about cmdline always being 0 terminated.
- Also allow \t as valid option separator (as space).
- Expand comment about expected get_option() behavior.
- Always check for valid option terminator.
Changes since v2:
- Do not parse console=.
- Allow width or height to be 0 as long as the gfx- option is well formed.
Changes since v1:
- Do not return the last occurrence of a command line.
- Rearrange the code for assembly processing of the cmdline and use lea.
- Merge patches handling console= and vga= together.
--- xen/arch/x86/boot/head.S | 13 +++++- xen/arch/x86/efi/efi-boot.h | 74 ++++++++++++++++++++++++++++++- xen/arch/x86/x86_64/asm-offsets.c | 1 + 3 files changed, 84 insertions(+), 4 deletions(-)
xen/arch/x86/boot/head.S +11 -2
@@ -237,9 +237,10 @@ __efi64_mb2_start: jmp x86_32_switch .Lefi_multiboot2_proto: - /* Zero EFI SystemTable and EFI ImageHandle addresses. */ + /* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */ xor %esi,%esi xor %edi,%edi + xor %edx,%edx /* Skip Multiboot2 information fixed part. */ lea (MB2_fixed_sizeof+MULTIBOOT2_TAG_ALIGN-1)(%rbx),%ecx
@@ -277,6 +278,13 @@ __efi64_mb2_start: cmove MB2_efi64_ih(%rcx),%rdi je .Lefi_mb2_next_tag + /* Get command line from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_CMDLINE, MB2_tag_type(%rcx) + jne .Lno_cmdline + lea MB2_tag_string(%rcx), %rdx + jmp .Lefi_mb2_next_tag +.Lno_cmdline: + /* Is it the end of Multiboot2 information? */ cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) je .Lrun_bs
@@ -340,7 +348,8 @@ __efi64_mb2_start: /* * efi_multiboot2() is called according to System V AMD64 ABI: - * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable. + * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable, + * %rdx - MB2 cmdline */ call efi_multiboot2
xen/arch/x86/efi/efi-boot.h +72 -2
86 lines not on this page · raw message
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -175,6 +175,7 @@ void __dummy__(void)OFFSET (MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);OFFSET (MB2_efi64_st, multiboot2_tag_efi64_t, pointer);OFFSET (MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer); +OFFSET (MB2_tag_string, multiboot2_tag_string_t, string);BLANK (); OFFSET(DOMAIN_vm_assist, struct domain, vm_assist);
Signature · 1 line
2.41.0
Re: [PATCH v4 1/3] multiboot2: parse vga= option when setting GOP mode
xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 799
Quoted 9 lines · Roger Pau Monne
xen/arch/x86/efi/efi-boot.h +2
-1@@ -795,7 +795,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { } -void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return a pointer to the character after the first occurrence of opt in cmd */ +static const char __init *get_option (const char *cmd,const char *opt)
Nit: __init and * want to change places.
Quoted 20 lines
xen/arch/x86/efi/efi-boot.h +15
-1@@ -816,7 +839,54 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableif ( gop ) { - gop_mode =efi_find_gop_mode (gop,0 ,0 ,0 ); +const char *cur = cmdline; +unsigned int width =0 , height =0 , depth =0 ; +bool keep_current = false; + +while ( (cur =get_option (cur,"vga=" )) !=NULL ) + { +#define VALID_TERMINATOR (c) \ + (*(c) == ' ' || *(c) == '\t' || *(c) == '\0' || *(c) == ',') +if ( !strncmp (cur,"gfx-" ,4 ) ) + { + width =simple_strtoul (cur +4 , &cur,10 ); + +if ( *cur =='x' ) + height =simple_strtoul (cur +1 , &cur,10 ); +else
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 866
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ goto error; + +if ( *cur =='x' ) + depth =simple_strtoul (cur +1 , &cur,10 ); +else + goto error; + +if ( !VALID_TERMINATOR (cur) ) + { +error:
Nit: Labels want to be indented by at least one blank. Here I'm inclined to suggest indenting to the level of the enclosing curly braces.
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 867
Quoted 1 line
xen/arch/x86/efi/efi-boot.h +1
-0+PrintStr (L"Warning: Invalid gfx- option detected.\r\n" );
Maybe better PrintErr() and no trailing full stop?
Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +6
-0+ width = height = depth =0 ; + } + keep_current = false; + } +else if ( !strncmp (cur,"current" ,7 ) &&VALID_TERMINATOR (cur +7 ) ) + keep_current = true;
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 883
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+else if ( !strncmp (cur,"keep" ,4 ) &&VALID_TERMINATOR (cur +4 ) ) + { +/* Ignore, handled in later vga= parsing. */ + } +else + { +/* Fallback to defaults if unimplemented. */ + width = height = depth =0 ; + keep_current = false; +PrintStr (L"Warning: Cannot use selected vga option.\r\n" );
Same here then?
With these addressed (which are all mechanical and hence can probably be done while committing, as long as we can reach agreement)
Jan
Re: [PATCH v4 1/3] multiboot2: parse vga= option when setting GOP mode
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monne
xen/arch/x86/efi/efi-boot.h +0
-0@@ -795,7 +795,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
Quoted 7 lines
xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 799
Quoted 5 lines
xen/arch/x86/efi/efi-boot.h +2
-1static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { } -void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return a pointer to the character after the first occurrence of opt in cmd */ +static const char __init *get_option (const char *cmd,const char *opt)Nit:
__initand * want to change places.
Hm, yes. I assume that placing it before the return type is not OK? (static const __init char ...)
Quoted 35 lines
Quoted 20 lines
xen/arch/x86/efi/efi-boot.h +15
-1@@ -816,7 +839,54 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableif ( gop ) { - gop_mode =efi_find_gop_mode (gop,0 ,0 ,0 ); +const char *cur = cmdline; +unsigned int width =0 , height =0 , depth =0 ; +bool keep_current = false; + +while ( (cur =get_option (cur,"vga=" )) !=NULL ) + { +#define VALID_TERMINATOR (c) \ + (*(c) == ' ' || *(c) == '\t' || *(c) == '\0' || *(c) == ',') +if ( !strncmp (cur,"gfx-" ,4 ) ) + { + width =simple_strtoul (cur +4 , &cur,10 ); + +if ( *cur =='x' ) + height =simple_strtoul (cur +1 , &cur,10 ); +else xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 866
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+ goto error; + +if ( *cur =='x' ) + depth =simple_strtoul (cur +1 , &cur,10 ); +else + goto error; + +if ( !VALID_TERMINATOR (cur) ) + { +error:Nit: Labels want to be indented by at least one blank. Here I'm inclined to suggest indenting to the level of the enclosing curly braces.
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 867
Quoted 1 line
xen/arch/x86/efi/efi-boot.h +1
-0+PrintStr (L"Warning: Invalid gfx- option detected.\r\n" );Maybe better
PrintErr()and no trailing full stop?
Yes, please adjust if you don't mind.
Quoted 18 lines
Quoted 7 lines
xen/arch/x86/efi/efi-boot.h +6
-0+ width = height = depth =0 ; + } + keep_current = false; + } +else if ( !strncmp (cur,"current" ,7 ) &&VALID_TERMINATOR (cur +7 ) ) + keep_current = true;xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable · line 883
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+else if ( !strncmp (cur,"keep" ,4 ) &&VALID_TERMINATOR (cur +4 ) ) + { +/* Ignore, handled in later vga= parsing. */ + } +else + { +/* Fallback to defaults if unimplemented. */ + width = height = depth =0 ; + keep_current = false; +PrintStr (L"Warning: Cannot use selected vga option.\r\n" );
Quoted 5 lines
Same here then?
With these addressed (which are all mechanical and hence can probably be done while committing, as long as we can reach agreement)
Reviewed-by Jan Beulich <[email protected]>
LGTM, please adjust if you don't mind, otherwise I can send an adjusted version.
Thanks, Roger.
Re: [PATCH v4 1/3] multiboot2: parse vga= option when setting GOP mode
Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
xen/arch/x86/efi/efi-boot.h +0
-0@@ -795,7 +795,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { }
Quoted 8 lines
Quoted 5 lines
xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 799
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h +2
-1-void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return a pointer to the character after the first occurrence of opt in cmd */ +static const char __init *get_option (const char *cmd,const char *opt)Nit:
__initand * want to change places.Hm, yes. I assume that placing it before the return type is not OK? (static const
__initchar ...)
That's still in the middle of the return type then. Technically gcc accepts it being placed anywhere, but they reserve the right to change meaning when not placed appropriately. Recall that you may alter both attributes of a function (or variable) and attributes of types. Hence to disambiguate both, proper placement may become necessary down the road. And while it might be that
static __init const char *...
would also be okay-ish (albeit I'm not certain), that's still against how we do things commonly (i.e. a not written down style aspect).
Quoted 4 lines
Quoted 1 line
Quoted 1 line
[...]
LGTM, please adjust if you don't mind, otherwise I can send an adjusted version.
No need to send an update.
Jan
Re: [PATCH v4 1/3] multiboot2: parse vga= option when setting GOP mode
Quoted 25 lines · Jan Beulich
Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
xen/arch/x86/efi/efi-boot.h +0
-0@@ -795,7 +795,30 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)static void __init efi_arch_flush_dcache_area (const void *vaddr,UINTN size) { }Quoted 8 lines
Quoted 5 lines
xen/arch/x86/efi/efi-boot.h static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 799
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h +2
-1-void __init efi_multiboot2 (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable) +/* Return a pointer to the character after the first occurrence of opt in cmd */ +static const char __init *get_option (const char *cmd,const char *opt)Nit:
__initand * want to change places.Hm, yes. I assume that placing it before the return type is not OK? (static const
__initchar ...)That's still in the middle of the return type then. Technically gcc accepts it being placed anywhere, but they reserve the right to change meaning when not placed appropriately. Recall that you may alter both attributes of a function (or variable) and attributes of types. Hence to disambiguate both, proper placement may become necessary down the road. And while it might be that
Quoted 4 lines
static
__initconst char *...would also be okay-ish (albeit I'm not certain), that's still against how we do things commonly (i.e. a not written down style aspect).
Thanks for the explanation.
Roger.
PATCH v4 2/3 multiboot2: do not set StdOut mode unconditionally
In reply to Roger Pau MonneOnly initialize StdOut if the current StdOut mode is unusable. This avoids forcefully switching StdOut to the maximum supported resolution, and thus very likely changing the GOP mode without having first parsed the command line options.
---
Changes since v2:
- Use approach suggested by Jan.
Changes since v1:
- New in this version.
--- xen/arch/x86/efi/efi-boot.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
xen/arch/x86/efi/efi-boot.h +7 -1
@@ -829,7 +829,13 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTableefi_init (ImageHandle, SystemTable); -efi_console_set_mode (); +if ( StdOut->QueryMode (StdOut, StdOut->Mode->Mode, + &cols, &rows) !=EFI_SUCCESS ) +/* +* If active StdOut mode is invalid init ConOut (StdOut) to the max +* supported size. +*/ +efi_console_set_mode ();if ( StdOut->QueryMode (StdOut, StdOut->Mode->Mode, &cols, &rows) ==EFI_SUCCESS )
Signature · 1 line
2.41.0
PATCH v4 3/3 cmdline: parse multiple instances of the vga option
In reply to Roger Pau MonneParse all instances of the vga= option on the command line, in order to always enforce the last selection on the command line.
Note that it's not safe to parse just the last occurrence of the vga= option, as then a command line with vga=current vga=keep would result in current being ignored.
Adjust the command line documentation to describe the new behavior.
---
Changes since v3:
- Remove xen-command-line doc addition.
- Set mode to 'ask' by default.
Changes since v2:
- New in this version.
---
Build tested only, as I don't have a system that does legacy boot and has VGA output I can check.
It's mostly encapsulating the current code inside of a while loop and adding an extra else if for the "ask" option, there's a lot of indentation changes.
--- xen/arch/x86/boot/cmdline.c | 83 +++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 41 deletions(-)
xen/arch/x86/boot/cmdline.c +42 -41
@@ -277,59 +277,60 @@ static u16 rows2vmode(unsigned int rows)static void vga_parse (const char *cmdline,early_boot_opts_t *ebo) { -const char *c; -unsigned int tmp, vesa_depth, vesa_height, vesa_width; - - c =find_opt (cmdline,"vga=" , true); - -if ( !c ) -return ; +const char *c = cmdline; ebo->boot_vid_mode =ASK_VGA ; -if ( !strmaxcmp (c,"current" , delim_chars_comma) ) - ebo->boot_vid_mode =VIDEO_CURRENT_MODE ; -else if ( !strsubcmp (c,"text-80x" ) ) - { - c +=strlen ("text-80x" ); - ebo->boot_vid_mode =rows2vmode (strtoui (c, delim_chars_comma,NULL )); - } -else if ( !strsubcmp (c,"gfx-" ) ) +while ( (c =find_opt (c,"vga=" , true)) !=NULL ) { - vesa_width =strtoui (c +strlen ("gfx-" ),"x" , &c); +unsigned int tmp, vesa_depth, vesa_height, vesa_width; + +if ( !strmaxcmp (c,"current" , delim_chars_comma) ) + ebo->boot_vid_mode =VIDEO_CURRENT_MODE ; +else if ( !strsubcmp (c,"text-80x" ) ) + { + c +=strlen ("text-80x" ); + ebo->boot_vid_mode =rows2vmode (strtoui (c, delim_chars_comma,NULL )); + } +else if ( !strsubcmp (c,"gfx-" ) ) + { + vesa_width =strtoui (c +strlen ("gfx-" ),"x" , &c); -if ( vesa_width >U16_MAX ) -return ; +if ( vesa_width >U16_MAX ) +return ; -/* -* Increment c outside of strtoui() because otherwise some -* compiler may complain with following message: -* warning: operation on 'c' may be undefined. -*/ - ++c; - vesa_height =strtoui (c,"x" , &c); +/* +* Increment c outside of strtoui() because otherwise some +* compiler may complain with following message: +* warning: operation on 'c' may be undefined. +*/ + ++c; + vesa_height =strtoui (c,"x" , &c); -if ( vesa_height >U16_MAX ) -return ; +if ( vesa_height >U16_MAX ) +return ; - vesa_depth =strtoui (++c, delim_chars_comma,NULL ); + vesa_depth =strtoui (++c, delim_chars_comma,NULL ); -if ( vesa_depth >U16_MAX ) -return ; +if ( vesa_depth >U16_MAX ) +return ; - ebo->vesa_width = vesa_width; - ebo->vesa_height = vesa_height; - ebo->vesa_depth = vesa_depth; - ebo->boot_vid_mode =VIDEO_VESA_BY_SIZE ; - } -else if ( !strsubcmp (c,"mode-" ) ) - { - tmp =strtoui (c +strlen ("mode-" ), delim_chars_comma,NULL ); + ebo->vesa_width = vesa_width; + ebo->vesa_height = vesa_height; + ebo->vesa_depth = vesa_depth; + ebo->boot_vid_mode =VIDEO_VESA_BY_SIZE ; + } +else if ( !strsubcmp (c,"mode-" ) ) + { + tmp =strtoui (c +strlen ("mode-" ), delim_chars_comma,NULL ); -if ( tmp >U16_MAX ) -return ; +if ( tmp >U16_MAX ) +return ; - ebo->boot_vid_mode = tmp; + ebo->boot_vid_mode = tmp; + } +else if ( !strmaxcmp (c,"ask" , delim_chars_comma) ) + ebo->boot_vid_mode =ASK_VGA ; } }#endif
Signature · 1 line
2.41.0
Re: [PATCH v4 3/3] cmdline: parse multiple instances of the vga option
Quoted 8 lines · Roger Pau Monne
Parse all instances of the vga= option on the command line, in order to always enforce the last selection on the command line.
Note that it's not safe to parse just the last occurrence of the vga= option, as then a command line with
vga=current vga=keepwould result in current being ignored.Adjust the command line documentation to describe the new behavior.
This was likely meant to be dropped along with ...
Quoted 4 lines
Signed-off-by Roger Pau Monné <[email protected]>---
Changes since v3:
- Remove xen-command-line doc addition.
... this? Beyond that (easy to adjust while committing)
Jan
Re: [PATCH v4 3/3] cmdline: parse multiple instances of the vga option
Quoted 12 lines · Jan Beulich
Quoted 8 lines · Roger Pau Monne
Parse all instances of the vga= option on the command line, in order to always enforce the last selection on the command line.
Note that it's not safe to parse just the last occurrence of the vga= option, as then a command line with
vga=current vga=keepwould result in current being ignored.Adjust the command line documentation to describe the new behavior.
This was likely meant to be dropped along with ...
Quoted 7 lines
Quoted 4 lines
Signed-off-by Roger Pau Monné <[email protected]>---
Changes since v3:
- Remove xen-command-line doc addition.... this? Beyond that (easy to adjust while committing)
Reviewed-by Jan Beulich <[email protected]>
Oh, indeed, I've added the changelog and didn't adjust the commit message.
Thanks, Roger.