linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] offb: make the screen properties endian safe
@ 2013-10-30 16:14 Cédric Le Goater
  2013-10-31  2:08 ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 11+ messages in thread
From: Cédric Le Goater @ 2013-10-30 16:14 UTC (permalink / raw)
  To: benh; +Cc: Cédric Le Goater, linuxppc-dev

The "screen" properties : depth, width, height, linebytes need
to be converted to the host endian order when read from the device
tree.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 drivers/video/offb.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 0c4f343..c1cf591 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -536,7 +536,7 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
 	unsigned int flags, rsize, addr_prop = 0;
 	unsigned long max_size = 0;
 	u64 rstart, address = OF_BAD_ADDR;
-	const u32 *pp, *addrp, *up;
+	const __be32 *pp, *addrp, *up;
 	u64 asize;
 	int foreign_endian = 0;
 
@@ -552,25 +552,25 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
 	if (pp == NULL)
 		pp = of_get_property(dp, "depth", &len);
 	if (pp && len == sizeof(u32))
-		depth = *pp;
+		depth = be32_to_cpu(*pp);
 
 	pp = of_get_property(dp, "linux,bootx-width", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "width", &len);
 	if (pp && len == sizeof(u32))
-		width = *pp;
+		width = be32_to_cpu(*pp);
 
 	pp = of_get_property(dp, "linux,bootx-height", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "height", &len);
 	if (pp && len == sizeof(u32))
-		height = *pp;
+		height = be32_to_cpu(*pp);
 
 	pp = of_get_property(dp, "linux,bootx-linebytes", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "linebytes", &len);
 	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
-		pitch = *pp;
+		pitch = be32_to_cpu(*pp);
 	else
 		pitch = width * ((depth + 7) / 8);
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] offb: make the screen properties endian safe
  2013-10-30 16:14 [PATCH] offb: make the screen properties endian safe Cédric Le Goater
@ 2013-10-31  2:08 ` Benjamin Herrenschmidt
  2013-10-31  9:36   ` [PATCH v2] " Cédric Le Goater
  0 siblings, 1 reply; 11+ messages in thread
From: Benjamin Herrenschmidt @ 2013-10-31  2:08 UTC (permalink / raw)
  To: Cédric Le Goater; +Cc: linuxppc-dev

On Wed, 2013-10-30 at 17:14 +0100, Cédric Le Goater wrote:
> @@ -552,25 +552,25 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
>  	if (pp == NULL)
>  		pp = of_get_property(dp, "depth", &len);
>  	if (pp && len == sizeof(u32))
> -		depth = *pp;
> +		depth = be32_to_cpu(*pp);

This is usually written as

		depth = be32_to_cpup(pp);

It used to be that the latter generated better code but that might not
be the case anymore, however it's still a better alternative.

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2] offb: make the screen properties endian safe
  2013-10-31  2:08 ` Benjamin Herrenschmidt
@ 2013-10-31  9:36   ` Cédric Le Goater
  2013-11-20 22:50     ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 11+ messages in thread
From: Cédric Le Goater @ 2013-10-31  9:36 UTC (permalink / raw)
  To: benh; +Cc: Cédric Le Goater, linuxppc-dev

The "screen" properties : depth, width, height, linebytes need
to be converted to the host endian order when read from the device
tree.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

Changes in v2:

 - replaced be32_to_cpu() by be32_to_cpup() 
 - fixed setcolreg ops 

 drivers/video/offb.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 0c4f343..68e8415 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -120,7 +120,7 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 			mask <<= info->var.transp.offset;
 			value |= mask;
 		}
-		pal[regno] = value;
+		pal[regno] = cpu_to_be32(value);
 		return 0;
 	}
 
@@ -536,7 +536,7 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
 	unsigned int flags, rsize, addr_prop = 0;
 	unsigned long max_size = 0;
 	u64 rstart, address = OF_BAD_ADDR;
-	const u32 *pp, *addrp, *up;
+	const __be32 *pp, *addrp, *up;
 	u64 asize;
 	int foreign_endian = 0;
 
@@ -552,25 +552,25 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
 	if (pp == NULL)
 		pp = of_get_property(dp, "depth", &len);
 	if (pp && len == sizeof(u32))
-		depth = *pp;
+		depth = be32_to_cpup(pp);
 
 	pp = of_get_property(dp, "linux,bootx-width", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "width", &len);
 	if (pp && len == sizeof(u32))
-		width = *pp;
+		width = be32_to_cpup(pp);
 
 	pp = of_get_property(dp, "linux,bootx-height", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "height", &len);
 	if (pp && len == sizeof(u32))
-		height = *pp;
+		height = be32_to_cpup(pp);
 
 	pp = of_get_property(dp, "linux,bootx-linebytes", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "linebytes", &len);
 	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
-		pitch = *pp;
+		pitch = be32_to_cpup(pp);
 	else
 		pitch = width * ((depth + 7) / 8);
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] offb: make the screen properties endian safe
  2013-10-31  9:36   ` [PATCH v2] " Cédric Le Goater
@ 2013-11-20 22:50     ` Benjamin Herrenschmidt
  2013-11-21 15:45       ` Cedric Le Goater
  0 siblings, 1 reply; 11+ messages in thread
From: Benjamin Herrenschmidt @ 2013-11-20 22:50 UTC (permalink / raw)
  To: Cédric Le Goater; +Cc: linuxppc-dev

On Thu, 2013-10-31 at 10:36 +0100, Cédric Le Goater wrote:
> The "screen" properties : depth, width, height, linebytes need
> to be converted to the host endian order when read from the device
> tree.
> 
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---

Did you actually test that ? IE, using emulated VGA in qemu for
example ?

I'm asking because there are a few interesting nits here...

 - fbdev *generally* assume native endian framebuffer, but of course
under qemu today, the adapter will use a big endian frame buffer
aperture. You can compile in support for foreign endian but I don't know
how that actually works.

 - The setcolreg fix ... the "value" is used 2 lines above your endian
swap, is that correct ?

Cheers
Ben.


> Changes in v2:
> 
>  - replaced be32_to_cpu() by be32_to_cpup() 
>  - fixed setcolreg ops 
> 
>  drivers/video/offb.c |   12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/video/offb.c b/drivers/video/offb.c
> index 0c4f343..68e8415 100644
> --- a/drivers/video/offb.c
> +++ b/drivers/video/offb.c
> @@ -120,7 +120,7 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
>  			mask <<= info->var.transp.offset;
>  			value |= mask;
>  		}
> -		pal[regno] = value;
> +		pal[regno] = cpu_to_be32(value);
>  		return 0;
>  	}
>  
> @@ -536,7 +536,7 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
>  	unsigned int flags, rsize, addr_prop = 0;
>  	unsigned long max_size = 0;
>  	u64 rstart, address = OF_BAD_ADDR;
> -	const u32 *pp, *addrp, *up;
> +	const __be32 *pp, *addrp, *up;
>  	u64 asize;
>  	int foreign_endian = 0;
>  
> @@ -552,25 +552,25 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
>  	if (pp == NULL)
>  		pp = of_get_property(dp, "depth", &len);
>  	if (pp && len == sizeof(u32))
> -		depth = *pp;
> +		depth = be32_to_cpup(pp);
>  
>  	pp = of_get_property(dp, "linux,bootx-width", &len);
>  	if (pp == NULL)
>  		pp = of_get_property(dp, "width", &len);
>  	if (pp && len == sizeof(u32))
> -		width = *pp;
> +		width = be32_to_cpup(pp);
>  
>  	pp = of_get_property(dp, "linux,bootx-height", &len);
>  	if (pp == NULL)
>  		pp = of_get_property(dp, "height", &len);
>  	if (pp && len == sizeof(u32))
> -		height = *pp;
> +		height = be32_to_cpup(pp);
>  
>  	pp = of_get_property(dp, "linux,bootx-linebytes", &len);
>  	if (pp == NULL)
>  		pp = of_get_property(dp, "linebytes", &len);
>  	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
> -		pitch = *pp;
> +		pitch = be32_to_cpup(pp);
>  	else
>  		pitch = width * ((depth + 7) / 8);
>  

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] offb: make the screen properties endian safe
  2013-11-20 22:50     ` Benjamin Herrenschmidt
@ 2013-11-21 15:45       ` Cedric Le Goater
  2013-11-21 19:57         ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 11+ messages in thread
From: Cedric Le Goater @ 2013-11-21 15:45 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev

Hi,

On 11/20/2013 11:50 PM, Benjamin Herrenschmidt wrote:
> On Thu, 2013-10-31 at 10:36 +0100, Cédric Le Goater wrote:
>> The "screen" properties : depth, width, height, linebytes need
>> to be converted to the host endian order when read from the device
>> tree.
>>
>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>> ---
> 
> Did you actually test that ? IE, using emulated VGA in qemu for
> example ?

Yes, that's how I did. I ran LE and BE guests with "qemu -vga std" and 
different depths.

> I'm asking because there are a few interesting nits here...
> 
>  - fbdev *generally* assume native endian framebuffer, but of course
> under qemu today, the adapter will use a big endian frame buffer
> aperture. You can compile in support for foreign endian but I don't know
> how that actually works.

OK. I will see how I can extend the tests. But, are you suggesting I should
be using the foreign endian framework for the frame buffer ? 
 
>  - The setcolreg fix ... the "value" is used 2 lines above your endian
> swap, is that correct ?

The variables used to calculate "value" are in host endian order. It should
be fine.

Thanks,

C.

 
> Cheers
> Ben.
> 
> 
>> Changes in v2:
>>
>>  - replaced be32_to_cpu() by be32_to_cpup() 
>>  - fixed setcolreg ops 
>>
>>  drivers/video/offb.c |   12 ++++++------
>>  1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/video/offb.c b/drivers/video/offb.c
>> index 0c4f343..68e8415 100644
>> --- a/drivers/video/offb.c
>> +++ b/drivers/video/offb.c
>> @@ -120,7 +120,7 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
>>  			mask <<= info->var.transp.offset;
>>  			value |= mask;
>>  		}
>> -		pal[regno] = value;
>> +		pal[regno] = cpu_to_be32(value);
>>  		return 0;
>>  	}
>>  
>> @@ -536,7 +536,7 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
>>  	unsigned int flags, rsize, addr_prop = 0;
>>  	unsigned long max_size = 0;
>>  	u64 rstart, address = OF_BAD_ADDR;
>> -	const u32 *pp, *addrp, *up;
>> +	const __be32 *pp, *addrp, *up;
>>  	u64 asize;
>>  	int foreign_endian = 0;
>>  
>> @@ -552,25 +552,25 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
>>  	if (pp == NULL)
>>  		pp = of_get_property(dp, "depth", &len);
>>  	if (pp && len == sizeof(u32))
>> -		depth = *pp;
>> +		depth = be32_to_cpup(pp);
>>  
>>  	pp = of_get_property(dp, "linux,bootx-width", &len);
>>  	if (pp == NULL)
>>  		pp = of_get_property(dp, "width", &len);
>>  	if (pp && len == sizeof(u32))
>> -		width = *pp;
>> +		width = be32_to_cpup(pp);
>>  
>>  	pp = of_get_property(dp, "linux,bootx-height", &len);
>>  	if (pp == NULL)
>>  		pp = of_get_property(dp, "height", &len);
>>  	if (pp && len == sizeof(u32))
>> -		height = *pp;
>> +		height = be32_to_cpup(pp);
>>  
>>  	pp = of_get_property(dp, "linux,bootx-linebytes", &len);
>>  	if (pp == NULL)
>>  		pp = of_get_property(dp, "linebytes", &len);
>>  	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
>> -		pitch = *pp;
>> +		pitch = be32_to_cpup(pp);
>>  	else
>>  		pitch = width * ((depth + 7) / 8);
>>  
> 
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] offb: make the screen properties endian safe
  2013-11-21 15:45       ` Cedric Le Goater
@ 2013-11-21 19:57         ` Benjamin Herrenschmidt
  2013-11-23 17:38           ` Cedric Le Goater
  0 siblings, 1 reply; 11+ messages in thread
From: Benjamin Herrenschmidt @ 2013-11-21 19:57 UTC (permalink / raw)
  To: Cedric Le Goater; +Cc: linuxppc-dev

On Thu, 2013-11-21 at 16:45 +0100, Cedric Le Goater wrote:
> >  - fbdev *generally* assume native endian framebuffer, but of course
> > under qemu today, the adapter will use a big endian frame buffer
> > aperture. You can compile in support for foreign endian but I don't know
> > how that actually works.
> 
> OK. I will see how I can extend the tests. But, are you suggesting I should
> be using the foreign endian framework for the frame buffer ? 

Well, if it works ... did you try 16 and 32bpp ?

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] offb: make the screen properties endian safe
  2013-11-21 19:57         ` Benjamin Herrenschmidt
@ 2013-11-23 17:38           ` Cedric Le Goater
  2013-11-23 21:04             ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 11+ messages in thread
From: Cedric Le Goater @ 2013-11-23 17:38 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev

On 11/21/2013 08:57 PM, Benjamin Herrenschmidt wrote:
> On Thu, 2013-11-21 at 16:45 +0100, Cedric Le Goater wrote:
>>>  - fbdev *generally* assume native endian framebuffer, but of course
>>> under qemu today, the adapter will use a big endian frame buffer
>>> aperture. You can compile in support for foreign endian but I don't know
>>> how that actually works.
>>
>> OK. I will see how I can extend the tests. But, are you suggesting I should
>> be using the foreign endian framework for the frame buffer ? 
> 
> Well, if it works ... did you try 16 and 32bpp ?

So, 32bpp "works" but 16 is broken ... I guess my palette fix is just a lucky
hack and I need to dig deeper in fb code to have a better understanding of
the color map. 

I should have provided you two patches in the first place. Do you want the 
device tree data fixes for the frame buffer screen properties ? It helps to 
have a display for little endian guests even if the colors are wrong.

Thanks,

C.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] offb: make the screen properties endian safe
  2013-11-23 17:38           ` Cedric Le Goater
@ 2013-11-23 21:04             ` Benjamin Herrenschmidt
  2013-12-04 16:47               ` Cedric Le Goater
                                 ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Benjamin Herrenschmidt @ 2013-11-23 21:04 UTC (permalink / raw)
  To: Cedric Le Goater; +Cc: linuxppc-dev

On Sat, 2013-11-23 at 18:38 +0100, Cedric Le Goater wrote:
> So, 32bpp "works" but 16 is broken ... I guess my palette fix is just a lucky
> hack and I need to dig deeper in fb code to have a better understanding of
> the color map. 
> 
> I should have provided you two patches in the first place. Do you want the 
> device tree data fixes for the frame buffer screen properties ? It helps to 
> have a display for little endian guests even if the colors are wrong.

Before you pull your hair out, check if it works in BE :-)

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2] offb: make the screen properties endian safe
  2013-11-23 21:04             ` Benjamin Herrenschmidt
@ 2013-12-04 16:47               ` Cedric Le Goater
  2013-12-04 16:49               ` [PATCH v3 1/2] offb: little endian fixes Cédric Le Goater
  2013-12-04 16:49               ` [PATCH v3 2/2] offb: add palette hack for little endian Cédric Le Goater
  2 siblings, 0 replies; 11+ messages in thread
From: Cedric Le Goater @ 2013-12-04 16:47 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev

On 11/23/2013 10:04 PM, Benjamin Herrenschmidt wrote:
> On Sat, 2013-11-23 at 18:38 +0100, Cedric Le Goater wrote:
>> So, 32bpp "works" but 16 is broken ... I guess my palette fix is just a lucky
>> hack and I need to dig deeper in fb code to have a better understanding of
>> the color map. 
>>
>> I should have provided you two patches in the first place. Do you want the 
>> device tree data fixes for the frame buffer screen properties ? It helps to 
>> have a display for little endian guests even if the colors are wrong.
> 
> Before you pull your hair out, check if it works in BE :-)

I spent some more time on this topic and I have a few more patches to 
send you.

The first patch is straight forward. It fixes host endian order issues 
in the offb code when accessing the OF device tree properties. 

The following patch is more of an attempt to fix the pseudo-palette 
entries on little endian. Hopefully this is the good direction. If not, 
I still have some hair to pull out :)

Cheers,

C.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/2] offb: little endian fixes
  2013-11-23 21:04             ` Benjamin Herrenschmidt
  2013-12-04 16:47               ` Cedric Le Goater
@ 2013-12-04 16:49               ` Cédric Le Goater
  2013-12-04 16:49               ` [PATCH v3 2/2] offb: add palette hack for little endian Cédric Le Goater
  2 siblings, 0 replies; 11+ messages in thread
From: Cédric Le Goater @ 2013-12-04 16:49 UTC (permalink / raw)
  To: benh; +Cc: Cédric Le Goater, linuxppc-dev

The "screen" properties : depth, width, height, linebytes need
to be converted to the host endian order when read from the device
tree.

The offb_init_palette_hacks() routine also made assumption on the
host endian order.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

Changes in v3:

 - fixed offb_init_palette_hacks()

Changes in v2:

 - replaced be32_to_cpu() by be32_to_cpup()

 drivers/video/offb.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 9dbea2223401..43a0a52fc527 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -301,7 +301,7 @@ static struct fb_ops offb_ops = {
 static void __iomem *offb_map_reg(struct device_node *np, int index,
 				  unsigned long offset, unsigned long size)
 {
-	const u32 *addrp;
+	const __be32 *addrp;
 	u64 asize, taddr;
 	unsigned int flags;
 
@@ -369,7 +369,11 @@ static void offb_init_palette_hacks(struct fb_info *info, struct device_node *dp
 		}
 		of_node_put(pciparent);
 	} else if (dp && of_device_is_compatible(dp, "qemu,std-vga")) {
-		const u32 io_of_addr[3] = { 0x01000000, 0x0, 0x0 };
+#ifdef __BIG_ENDIAN
+		const __be32 io_of_addr[3] = { 0x01000000, 0x0, 0x0 };
+#else
+		const __be32 io_of_addr[3] = { 0x00000001, 0x0, 0x0 };
+#endif
 		u64 io_addr = of_translate_address(dp, io_of_addr);
 		if (io_addr != OF_BAD_ADDR) {
 			par->cmap_adr = ioremap(io_addr + 0x3c8, 2);
@@ -535,7 +539,7 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
 	unsigned int flags, rsize, addr_prop = 0;
 	unsigned long max_size = 0;
 	u64 rstart, address = OF_BAD_ADDR;
-	const u32 *pp, *addrp, *up;
+	const __be32 *pp, *addrp, *up;
 	u64 asize;
 	int foreign_endian = 0;
 
@@ -551,25 +555,25 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
 	if (pp == NULL)
 		pp = of_get_property(dp, "depth", &len);
 	if (pp && len == sizeof(u32))
-		depth = *pp;
+		depth = be32_to_cpup(pp);
 
 	pp = of_get_property(dp, "linux,bootx-width", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "width", &len);
 	if (pp && len == sizeof(u32))
-		width = *pp;
+		width = be32_to_cpup(pp);
 
 	pp = of_get_property(dp, "linux,bootx-height", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "height", &len);
 	if (pp && len == sizeof(u32))
-		height = *pp;
+		height = be32_to_cpup(pp);
 
 	pp = of_get_property(dp, "linux,bootx-linebytes", &len);
 	if (pp == NULL)
 		pp = of_get_property(dp, "linebytes", &len);
 	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
-		pitch = *pp;
+		pitch = be32_to_cpup(pp);
 	else
 		pitch = width * ((depth + 7) / 8);
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/2] offb: add palette hack for little endian
  2013-11-23 21:04             ` Benjamin Herrenschmidt
  2013-12-04 16:47               ` Cedric Le Goater
  2013-12-04 16:49               ` [PATCH v3 1/2] offb: little endian fixes Cédric Le Goater
@ 2013-12-04 16:49               ` Cédric Le Goater
  2 siblings, 0 replies; 11+ messages in thread
From: Cédric Le Goater @ 2013-12-04 16:49 UTC (permalink / raw)
  To: benh; +Cc: Cédric Le Goater, linuxppc-dev

The pseudo palette color entries need to be ajusted for little
endian.

This patch byteswaps the values in the pseudo palette depending
on the host endian order and the screen depth.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---

Tested on powerpc, little endian and big endian, for 8, 15, 16 and 32 
bpp using the qemu std vga device, with and without foreign endian 
support. I did pull my hair out :) 

The foreign endian support needs some more work to be sure the logic 
behind fb_be_math() is not broken. 

The palette used for the logo would need a similar fix.

Thanks,




 drivers/video/offb.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 43a0a52fc527..7d44d669d5b6 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -91,6 +91,15 @@ extern boot_infos_t *boot_infos;
 #define AVIVO_DC_LUTB_WHITE_OFFSET_GREEN        0x6cd4
 #define AVIVO_DC_LUTB_WHITE_OFFSET_RED          0x6cd8
 
+#define FB_RIGHT_POS(p, bpp)         (fb_be_math(p) ? 0 : (32 - (bpp)))
+
+static inline u32 offb_cmap_byteswap(struct fb_info *info, u32 value)
+{
+	u32 bpp = info->var.bits_per_pixel;
+
+	return cpu_to_be32(value) >> FB_RIGHT_POS(info, bpp);
+}
+
     /*
      *  Set a single color register. The values supplied are already
      *  rounded down to the hardware's capabilities (according to the
@@ -120,7 +129,7 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 			mask <<= info->var.transp.offset;
 			value |= mask;
 		}
-		pal[regno] = value;
+		pal[regno] = offb_cmap_byteswap(info, value);
 		return 0;
 	}
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-12-04 16:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-30 16:14 [PATCH] offb: make the screen properties endian safe Cédric Le Goater
2013-10-31  2:08 ` Benjamin Herrenschmidt
2013-10-31  9:36   ` [PATCH v2] " Cédric Le Goater
2013-11-20 22:50     ` Benjamin Herrenschmidt
2013-11-21 15:45       ` Cedric Le Goater
2013-11-21 19:57         ` Benjamin Herrenschmidt
2013-11-23 17:38           ` Cedric Le Goater
2013-11-23 21:04             ` Benjamin Herrenschmidt
2013-12-04 16:47               ` Cedric Le Goater
2013-12-04 16:49               ` [PATCH v3 1/2] offb: little endian fixes Cédric Le Goater
2013-12-04 16:49               ` [PATCH v3 2/2] offb: add palette hack for little endian Cédric Le Goater

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).