offb: make the screen properties endian safe
PATCH 1/1 offb: make the screen properties endian safe
The "screen" properties : depth, width, height, linebytes need to be converted to the host endian order when read from the device tree.
--- drivers/video/offb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/video/offb.c +5 -5
@@ -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 );
Signature · 1 line
1.7.10.4
drivers/video/offb.c static void __init offb_init_nodriver(struct device_node *dp, int no_real_node) · line 555
Quoted 6 lines · Cédric Le Goater
drivers/video/offb.c +1
-1@@ -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.
PATCH v2 1/1 offb: make the screen properties endian safe
The "screen" properties : depth, width, height, linebytes need to be converted to the host endian order when read from the device tree.
---
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(-)
drivers/video/offb.c +6 -6
@@ -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 );
Signature · 1 line
1.7.10.4
Quoted 6 lines · Cédric Le Goater
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 <[email protected]>---
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.
Quoted 60 lines
Changes in v2:
- replaced
be32_to_cpu()bybe32_to_cpup()
- fixed setcolreg opsdrivers/video/offb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/video/offb.c +6
-6@@ -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 );
Hi,
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Cédric Le Goater
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 <[email protected]>---
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.
Quoted 6 lines
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 ?
Quoted 2 lines
- 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.
Quoted 66 lines
Cheers
Ben.Quoted 60 lines
Changes in v2:
- replaced
be32_to_cpu()bybe32_to_cpup()
- fixed setcolreg opsdrivers/video/offb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/video/offb.c +6
-6@@ -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 );
Quoted 7 lines · Cedric Le Goater
Quoted 4 lines
- 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.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines · Cedric Le Goater
Quoted 4 lines
- 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.
Quoted 7 lines · Cedric Le Goater
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.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines · Cedric Le Goater
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.
PATCH v3 2/2 offb: add palette hack for little endian
In reply to Cédric Le GoaterThe 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.
---
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(-)
drivers/video/offb.c +10 -1
@@ -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 ; }
Signature · 1 line
1.7.10.4
PATCH v3 1/2 offb: little endian fixes
In reply to Benjamin HerrenschmidtThe "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.
---
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(-)
drivers/video/offb.c +11 -7
@@ -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 );
Signature · 1 line
1.7.10.4