Skip to contentSkip to conversation

fbdev: vesafb: Detect VGA compatibility from screen info's VESA attributes

PATCH Superseded Thomas Zimmermann 3 participants 9 messages Jun 13, 2024 – Jun 14, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbdev: vesafb: Detect VGA compatibility from screen info's VESA attributes

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+
---
 drivers/video/fbdev/vesafb.c | 2 +-
 include/linux/screen_info.h  | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/vesafb.c +1 -1
index 8ab64ae4cad3e..5a161750a3aee 100644
@@ -271,7 +271,7 @@ static int vesafb_probe(struct platform_device *dev)
 	if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
 		return -ENODEV;
 
-	vga_compat = (si->capabilities & 2) ? 0 : 1;
+	vga_compat = !__screen_info_vbe_mode_nonvga(si);
 	vesafb_fix.smem_start = si->lfb_base;
 	vesafb_defined.bits_per_pixel = si->lfb_depth;
 	if (15 == vesafb_defined.bits_per_pixel)
include/linux/screen_info.h +5 -0
index 75303c126285a..95f2a339de329 100644
@@ -49,6 +49,11 @@ static inline u64 __screen_info_lfb_size(const struct screen_info *si, unsigned
 	return lfb_size;
 }
 
+static inline bool __screen_info_vbe_mode_nonvga(const struct screen_info *si)
+{
+	return si->vesa_attributes & BIT(5); // VGA if _not_ set
+}
+
 static inline unsigned int __screen_info_video_type(unsigned int type)
 {
 	switch (type) {
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 12 lines

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

Quoted 8 lines

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

How did you find this ?

Quoted 7 lines

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+

---

The patch looks correct to me after your explanation in the commit message and looking at the mentioned commits.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#2 lore raw

Hi Javier

Am 13.06.24 um 11:35 schrieb Javier Martinez Canillas:

Quoted 24 lines

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 12 lines

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

Quoted 8 lines

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Quoted 1 line

How did you find this ?

I was reading through vesafb and found that [1] and [2] look surprisingly similar, which makes no sense. So I started looking where bit 1 came from. The flag signals a 64-bit framebuffer address for EFI (see VIDEO_CAPABILITY_64BIT_BASE <https://elixir.bootlin.com/linux/latest/C/ident/VIDEO_CAPABILITY_64BIT_BASE>). But old VESA framebuffers are usually located within the first 32-bit range. So the bit is mostly 0 and vesafb works as expected.

[1] https://elixir.bootlin.com/linux/latest/source/drivers/video/fbdev/vesafb.c#L274
[2] https://elixir.bootlin.com/linux/latest/source/include/linux/screen_info.h#L26

Quoted 4 lines
Quoted 4 lines

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Quoted 8 lines
Quoted 4 lines
Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+

---

The patch looks correct to me after your explanation in the commit message and looking at the mentioned commits.

Thanks a lot.

Best regards
Thomas

Quoted 1 line
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#3 lore raw
Quoted 37 lines · Thomas Zimmermann

Hi Javier

Am 13.06.24 um 11:35 schrieb Javier Martinez Canillas:

Quoted 24 lines

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 12 lines

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

Quoted 8 lines

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Quoted 1 line

How did you find this ?

I was reading through vesafb and found that [1] and [2] look surprisingly similar, which makes no sense. So I started looking where bit 1 came from. The flag signals a 64-bit framebuffer address for EFI (see VIDEO_CAPABILITY_64BIT_BASE
<https://elixir.bootlin.com/linux/latest/C/ident/VIDEO_CAPABILITY_64BIT_BASE>).
But old VESA framebuffers are usually located within the first 32-bit range. So the bit is mostly 0 and vesafb works as expected.

Quoted 5 lines

[1]
https://elixir.bootlin.com/linux/latest/source/drivers/video/fbdev/vesafb.c#L274
[2]
https://elixir.bootlin.com/linux/latest/source/include/linux/screen_info.h#L26

I see. Thanks a lot for the explanation and references.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
maintainer
#4 lore raw
In reply to Thomas Zimmermann
Quoted 20 lines · Thomas Zimmermann

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Quoted 2 lines

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Nice catch, Thomas!

But do we really need this additional helper?

Quoted 15 lines
Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+
---
  drivers/video/fbdev/vesafb.c | 2 +-
  include/linux/screen_info.h  | 5 +++++
  2 files changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/vesafb.c +0 -0
index 8ab64ae4cad3e..5a161750a3aee 100644

drivers/video/fbdev/vesafb.c static int vesafb_probe(struct platform_device *dev) · line 274

Quoted 5 lines
drivers/video/fbdev/vesafb.c +1 -1
@@ -271,7 +271,7 @@ static int vesafb_probe(struct platform_device *dev)
  	if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
  		return -ENODEV;
 
-	vga_compat = (si->capabilities & 2) ? 0 : 1;
+	vga_compat = !__screen_info_vbe_mode_nonvga(si);

Instead maybe just this: ?
+ /* mode is VGA-compatible if BIT 5 is _NOT_ set */
+ vga_compat = (si->vesa_attributes & BIT(5)) == 0;

I suggest to make patch small, esp. if you ask for backport to v2.6.23+.

Helge

Quoted 19 lines
drivers/video/fbdev/vesafb.c +0 -0
  	vesafb_fix.smem_start = si->lfb_base;
  	vesafb_defined.bits_per_pixel = si->lfb_depth;
  	if (15 == vesafb_defined.bits_per_pixel)
include/linux/screen_info.h +5 -0
index 75303c126285a..95f2a339de329 100644
@@ -49,6 +49,11 @@ static inline u64 __screen_info_lfb_size(const struct screen_info *si, unsigned
  	return lfb_size;
  }
 
+static inline bool __screen_info_vbe_mode_nonvga(const struct screen_info *si)
+{
+	return si->vesa_attributes & BIT(5); // VGA if _not_ set
+}
+
  static inline unsigned int __screen_info_video_type(unsigned int type)
  {
  	switch (type) {
#5 lore raw
Quoted 47 lines · Helge Deller
Quoted 20 lines · Thomas Zimmermann

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Quoted 2 lines

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Nice catch, Thomas!

But do we really need this additional helper?

Quoted 18 lines
Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+
---
  drivers/video/fbdev/vesafb.c | 2 +-
  include/linux/screen_info.h  | 5 +++++
  2 files changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/vesafb.c +0 -0
index 8ab64ae4cad3e..5a161750a3aee 100644
@@ -271,7 +271,7 @@ static int vesafb_probe(struct platform_device *dev)
  	if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
  		return -ENODEV;
 
Quoted 9 lines

drivers/video/fbdev/vesafb.c static int vesafb_probe(struct platform_device *dev) · line 274

Quoted 2 lines
drivers/video/fbdev/vesafb.c +1 -1
-	vga_compat = (si->capabilities & 2) ? 0 : 1;
+	vga_compat = !__screen_info_vbe_mode_nonvga(si);

Instead maybe just this: ?
+ /* mode is VGA-compatible if BIT 5 is _NOT_ set */
+ vga_compat = (si->vesa_attributes & BIT(5)) == 0;

I suggest to make patch small, esp. if you ask for backport to v2.6.23+.

I prefer the helper. It's a static inline anyways and having it as a function makes it much easier to read / understand.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
maintainer
#6 lore raw
Quoted 56 lines · Javier Martinez Canillas
Quoted 54 lines · Helge Deller
Quoted 20 lines · Thomas Zimmermann

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Quoted 2 lines

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Nice catch, Thomas!

But do we really need this additional helper?

Quoted 15 lines
Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+
---
   drivers/video/fbdev/vesafb.c | 2 +-
   include/linux/screen_info.h  | 5 +++++
   2 files changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/vesafb.c +0 -0
index 8ab64ae4cad3e..5a161750a3aee 100644

drivers/video/fbdev/vesafb.c static int vesafb_probe(struct platform_device *dev) · line 274

Quoted 5 lines
drivers/video/fbdev/vesafb.c +1 -1
@@ -271,7 +271,7 @@ static int vesafb_probe(struct platform_device *dev)
   	if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
   		return -ENODEV;
 
-	vga_compat = (si->capabilities & 2) ? 0 : 1;
+	vga_compat = !__screen_info_vbe_mode_nonvga(si);

Instead maybe just this: ?
+ /* mode is VGA-compatible if BIT 5 is _NOT_ set */
+ vga_compat = (si->vesa_attributes & BIT(5)) == 0;

Quoted 5 lines
Quoted 2 lines

I suggest to make patch small, esp. if you ask for backport to v2.6.23+.

I prefer the helper. It's a static inline anyways and having it as a function makes it much easier to read / understand.

Really?

+static inline bool __screen_info_vbe_mode_nonvga(const struct screen_info *si) +{
+ return si->vesa_attributes & BIT(5); // VGA if _not_ set
+}

At least the double negation "!nonvga()" breaks my head and the "//" comment should be converted to /*..*/ IMHO.

Helge

#7 lore raw

Hi

Am 14.06.24 um 00:24 schrieb Helge Deller:

Quoted 24 lines · Javier Martinez Canillas
Quoted 23 lines
Quoted 21 lines · Helge Deller
Quoted 20 lines · Thomas Zimmermann

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Nice catch, Thomas!

But do we really need this additional helper?

Yes, please. Decoding screen_info is a science on it's own. I've added several of these helpers to access because such code was open-coded and duplicated all over the graphics code. And several places got something wrong. The patch here is just one of many such cases.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 17 lines
Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+

---
   drivers/video/fbdev/vesafb.c | 2 +-
   include/linux/screen_info.h  | 5 +++++

   2 files changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/vesafb.c +0 -0
index 8ab64ae4cad3e..5a161750a3aee 100644

drivers/video/fbdev/vesafb.c static int vesafb_probe(struct platform_device · line 275

Quoted 6 lines
drivers/video/fbdev/vesafb.c +1 -1
@@ -271,7 +271,7 @@ static int vesafb_probe(struct platform_device 
 *dev)
        if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
            return -ENODEV;
 
-    vga_compat = (si->capabilities & 2) ? 0 : 1;
+    vga_compat = !__screen_info_vbe_mode_nonvga(si);

Instead maybe just this: ?
   +    /* mode is VGA-compatible if BIT 5 is _NOT_ set */ +    vga_compat = (si->vesa_attributes & BIT(5)) == 0;

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I suggest to make patch small, esp. if you ask for backport to v2.6.23+.

I prefer the helper. It's a static inline anyways and having it as a function makes it much easier to read / understand.

Really?

Yep.

Quoted 9 lines

+static inline bool __screen_info_vbe_mode_nonvga(const struct screen_info *si)

include/linux/screen_info.h +3 -0
+{
+    return si->vesa_attributes & BIT(5); // VGA if _not_ set
+}

At least the double negation "!nonvga()" breaks my head and the "//" comment should be converted to /*..*/ IMHO.

The non-VGA bit is specified by VESA. So the helper does the correct thing. We can make a better comment though.

If we want to simplify usage of this helper, I'd say we should kick vga_compat from vesafb and rework that code.

Best regards
Thomas

Quoted 2 lines

Helge

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
maintainer
#8 lore raw
Quoted 79 lines · Thomas Zimmermann

Hi

Am 14.06.24 um 00:24 schrieb Helge Deller:

Quoted 24 lines · Javier Martinez Canillas
Quoted 23 lines
Quoted 21 lines · Helge Deller
Quoted 20 lines · Thomas Zimmermann

Test the vesa_attributes field in struct screen_info for compatibility with VGA hardware. Vesafb currently tests bit 1 in screen_info's capabilities field, It sets the framebuffer address size and is unrelated to VGA.

Section 4.4 of the Vesa VBE 2.0 specifications defines that bit 5 in the mode's attributes field signals VGA compatibility. The mode is compatible with VGA hardware if the bit is clear. In that case, the driver can access VGA state of the VBE's underlying hardware. The vesafb driver uses this feature to program the color LUT in palette modes. Without, colors might be incorrect.

The problem got introduced in commit 89ec4c238e7a ("[PATCH] vesafb: Fix incorrect logo colors in x86_64"). It incorrectly stores the mode attributes in the screen_info's capabilities field and updates vesafb accordingly. Later, commit 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code") fixed the screen_info, but did not update vesafb. Color output still tends to work, because bit 1 in capabilities is usually 0.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Besides fixing the bug in vesafb, this commit introduces a helper that reads the correct bit from screen_info.

Nice catch, Thomas!

But do we really need this additional helper?

Yes, please. Decoding screen_info is a science on it's own. I've added several of these helpers to access because such code was open-coded and duplicated all over the graphics code. And several places got something wrong. The patch here is just one of many such cases.

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 17 lines
Fixes 5e8ddcbe8692 ("Video mode probing support for the new x86 setup code")
Cc <[email protected]> # v2.6.23+

---
   drivers/video/fbdev/vesafb.c | 2 +-
   include/linux/screen_info.h  | 5 +++++

   2 files changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/vesafb.c +0 -0
index 8ab64ae4cad3e..5a161750a3aee 100644

drivers/video/fbdev/vesafb.c static int vesafb_probe(struct platform_device *dev) · line 274

Quoted 5 lines
drivers/video/fbdev/vesafb.c +1 -1
@@ -271,7 +271,7 @@ static int vesafb_probe(struct platform_device *dev)
        if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
            return -ENODEV;
 
-    vga_compat = (si->capabilities & 2) ? 0 : 1;
+    vga_compat = !__screen_info_vbe_mode_nonvga(si);

Instead maybe just this: ?
   +    /* mode is VGA-compatible if BIT 5 is _NOT_ set */ +    vga_compat = (si->vesa_attributes & BIT(5)) == 0;

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I suggest to make patch small, esp. if you ask for backport to v2.6.23+.

I prefer the helper. It's a static inline anyways and having it as a function makes it much easier to read / understand.

Really?

Yep.

Quoted 6 lines
include/linux/screen_info.h +4 -0
+static inline bool __screen_info_vbe_mode_nonvga(const struct screen_info *si)
+{
+    return si->vesa_attributes & BIT(5); // VGA if _not_ set
+}
Quoted 6 lines
Quoted 2 lines

At least the double negation "!nonvga()" breaks my head and the "//" comment should be converted to /*..*/ IMHO.

The non-VGA bit is specified by VESA. So the helper does the correct thing. We can make a better comment though.

If we want to simplify usage of this helper, I'd say we should kick vga_compat from vesafb and rework that code.

Ok, then I suggest to keep your patch as-is, with just the "//" comment replaced by a /**/ comment.

Helge