# \[PATCH\] \[efifb\] Fix 16 color palette entry calculation

- Subsystems: EFIFB FRAMEBUFFER DRIVER, FRAMEBUFFER LAYER, THE REST
- Maintainers: Peter Jones, Helge Deller, Linus Torvalds
- List: linux-fbdev
- 7 messages, 5 authors
- Page: https://ratatoskr.run/linux-fbdev/2016/06/4767178/t

## \[PATCH\] \[efifb\] Fix 16 color palette entry calculation

- From: Max Staudt \<hidden\>
- Date: 2016-06-07 13:46:23 
- Message: https://ratatoskr.run/linux-fbdev/2016/06/4767178.md

```text
When using efifb with a 16-bit (5:6:5) visual, fbcon's text is rendered
in the wrong colors - e.g. text gray (#aaaaaa) is rendered as green
(#50bc50) and neighboring pixels have slightly different values
(such as #50bc78).

The reason is that fbcon loads its 16 color palette through
efifb_setcolreg(), which in turn calculates a 32-bit value to write
into memory for each palette index.
Until now, this code could only handle 8-bit visuals and didn't mask
overlapping values when ORing them.

With this patch, fbcon displays the correct colors when a qemu VM is
booted in 16-bit mode (in GRUB: "set gfxpayload€0x600x16").

Signed-off-by: Max Staudt <redacted>
---
 drivers/video/fbdev/efifb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 924bad4..37a37c4 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -50,9 +50,9 @@ static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
 		return 1;
 
 	if (regno < 16) {
-		red   >>= 8;
-		green >>= 8;
-		blue  >>= 8;
+		red   >>= 16 - info->var.red.length;
+		green >>= 16 - info->var.green.length;
+		blue  >>= 16 - info->var.blue.length;
 		((u32 *)(info->pseudo_palette))[regno]  			(red   << info->var.red.offset)   |
 			(green << info->var.green.offset) |
-- 
2.6.6

```

## Re: \[PATCH\] \[efifb\] Fix 16 color palette entry calculation

- From: Greg KH \<gregkh@linuxfoundation.org\>
- Date: 2016-06-07 16:41:53 
- Message: https://ratatoskr.run/linux-fbdev/2016/06/4767388.md

```text
On Tue, Jun 07, 2016 at 03:45:43PM +0200, Max Staudt wrote:
> When using efifb with a 16-bit (5:6:5) visual, fbcon's text is rendered
> in the wrong colors - e.g. text gray (#aaaaaa) is rendered as green
> (#50bc50) and neighboring pixels have slightly different values
> (such as #50bc78).
> 
> The reason is that fbcon loads its 16 color palette through
> efifb_setcolreg(), which in turn calculates a 32-bit value to write
> into memory for each palette index.
> Until now, this code could only handle 8-bit visuals and didn't mask
> overlapping values when ORing them.
> 
> With this patch, fbcon displays the correct colors when a qemu VM is
> booted in 16-bit mode (in GRUB: "set gfxpayload€0x600x16").
> 
> Signed-off-by: Max Staudt <redacted>
> ---
>  drivers/video/fbdev/efifb.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>
```

## Re: \[PATCH\] \[efifb\] Fix 16 color palette entry calculation

- From: Peter Jones \<pjones@redhat.com\>
- Date: 2016-06-07 17:23:14 
- Message: https://ratatoskr.run/linux-fbdev/2016/06/4767422.md

```text
On Tue, Jun 07, 2016 at 03:45:43PM +0200, Max Staudt wrote:
> When using efifb with a 16-bit (5:6:5) visual, fbcon's text is rendered
> in the wrong colors - e.g. text gray (#aaaaaa) is rendered as green
> (#50bc50) and neighboring pixels have slightly different values
> (such as #50bc78).
> 
> The reason is that fbcon loads its 16 color palette through
> efifb_setcolreg(), which in turn calculates a 32-bit value to write
> into memory for each palette index.
> Until now, this code could only handle 8-bit visuals and didn't mask
> overlapping values when ORing them.
> 
> With this patch, fbcon displays the correct colors when a qemu VM is
> booted in 16-bit mode (in GRUB: "set gfxpayload€0x600x16").
> 
> Signed-off-by: Max Staudt <redacted>
> ---
>  drivers/video/fbdev/efifb.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
> index 924bad4..37a37c4 100644
> --- a/drivers/video/fbdev/efifb.c
> +++ b/drivers/video/fbdev/efifb.c
> @@ -50,9 +50,9 @@ static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
>  		return 1;
>  
>  	if (regno < 16) {
> -		red   >>= 8;
> -		green >>= 8;
> -		blue  >>= 8;
> +		red   >>= 16 - info->var.red.length;
> +		green >>= 16 - info->var.green.length;
> +		blue  >>= 16 - info->var.blue.length;
>  		((u32 *)(info->pseudo_palette))[regno] >  			(red   << info->var.red.offset)   |
>  			(green << info->var.green.offset) |
> -- 
> 2.6.6

Looks right to me.

Acked-By: Peter Jones <pjones@redhat.com>

-- 
  Peter
```

## Re: \[PATCH\] \[efifb\] Fix 16 color palette entry calculation

- From: Matt Fleming \<hidden\>
- Date: 2016-06-08 12:43:54 
- Message: https://ratatoskr.run/linux-fbdev/2016/06/4768382.md

```text
On Tue, 07 Jun, at 01:23:05PM, Peter Jones wrote:
> 
> Looks right to me.
> 
> Acked-By: Peter Jones <pjones@redhat.com>

Tomi, are you OK to take this one or would you like me to take it
through the EFI tree?
```

## Re: \[PATCH\] \[efifb\] Fix 16 color palette entry calculation

- From: Tomi Valkeinen \<hidden\>
- Date: 2016-06-10 11:33:30 
- Message: https://ratatoskr.run/linux-fbdev/2016/06/4770337.md

```text
On 08/06/16 15:43, Matt Fleming wrote:
> On Tue, 07 Jun, at 01:23:05PM, Peter Jones wrote:
>>
>> Looks right to me.
>>
>> Acked-By: Peter Jones <pjones@redhat.com>
> 
> Tomi, are you OK to take this one or would you like me to take it
> through the EFI tree?

I can pick this up, but as Greg said, this is not valid for stable.

Max, please resend with correct stable reference.

 Tomi

```

## \[PATCH RESEND\] fbdev/efifb: Fix 16 color palette entry calculation

- From: Max Staudt \<hidden\>
- Date: 2016-06-13 17:16:16 
- Message: https://ratatoskr.run/linux-fbdev/2016/06/4772172.md

```text
When using efifb with a 16-bit (5:6:5) visual, fbcon's text is rendered
in the wrong colors - e.g. text gray (#aaaaaa) is rendered as green
(#50bc50) and neighboring pixels have slightly different values
(such as #50bc78).

The reason is that fbcon loads its 16 color palette through
efifb_setcolreg(), which in turn calculates a 32-bit value to write
into memory for each palette index.
Until now, this code could only handle 8-bit visuals and didn't mask
overlapping values when ORing them.

With this patch, fbcon displays the correct colors when a qemu VM is
booted in 16-bit mode (in GRUB: "set gfxpayload€0x600x16").

Fixes: 7c83172b98e5 ("x86_64 EFI boot support: EFI frame buffer driver")  # v2.6.24+
Signed-off-by: Max Staudt <redacted>
Acked-By: Peter Jones <pjones@redhat.com>
Cc: <redacted>
---
 drivers/video/fbdev/efifb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 924bad4..37a37c4 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -50,9 +50,9 @@ static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
 		return 1;
 
 	if (regno < 16) {
-		red   >>= 8;
-		green >>= 8;
-		blue  >>= 8;
+		red   >>= 16 - info->var.red.length;
+		green >>= 16 - info->var.green.length;
+		blue  >>= 16 - info->var.blue.length;
 		((u32 *)(info->pseudo_palette))[regno]  			(red   << info->var.red.offset)   |
 			(green << info->var.green.offset) |
-- 
2.6.6

```

## Re: \[PATCH RESEND\] fbdev/efifb: Fix 16 color palette entry calculation

- From: Tomi Valkeinen \<hidden\>
- Date: 2016-08-10 19:02:56 
- Message: https://ratatoskr.run/linux-fbdev/2016/08/4811400.md

```text


On 13/06/16 20:15, Max Staudt wrote:
> When using efifb with a 16-bit (5:6:5) visual, fbcon's text is rendered
> in the wrong colors - e.g. text gray (#aaaaaa) is rendered as green
> (#50bc50) and neighboring pixels have slightly different values
> (such as #50bc78).
> 
> The reason is that fbcon loads its 16 color palette through
> efifb_setcolreg(), which in turn calculates a 32-bit value to write
> into memory for each palette index.
> Until now, this code could only handle 8-bit visuals and didn't mask
> overlapping values when ORing them.
> 
> With this patch, fbcon displays the correct colors when a qemu VM is
> booted in 16-bit mode (in GRUB: "set gfxpayload=800x600x16").
> 
> Fixes: 7c83172b98e5 ("x86_64 EFI boot support: EFI frame buffer driver")  # v2.6.24+
> Signed-off-by: Max Staudt <redacted>
> Acked-By: Peter Jones <pjones@redhat.com>
> Cc: <redacted>
> ---
>  drivers/video/fbdev/efifb.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Thanks, queued for v4.9.

 Tomi


```
