drm: more byteorder fixes
Subsystems (4)
Gerd Hoffmann
maintainerv3 cover drm: more byteorder fixes
Fix fbdev emulation.
Fix bochs-drm and virtio-gpu drivers.
Gerd Hoffmann (5):
drm: move native byte order quirk to new drm_mode_legacy_fb_format2
function
drm: use drm_mode_legacy_fb_format2 in drm_gem_fbdev_fb_create drm/bochs: fix DRM_FORMAT_* handling for big endian machines. drm/bochs: support changing byteorder at mode set time drm/virtio: fix DRM_FORMAT_* handling
drivers/gpu/drm/bochs/bochs.h | 4 +- include/drm/drm_fourcc.h | 2 + drivers/gpu/drm/bochs/bochs_fbdev.c | 18 ++++++-- drivers/gpu/drm/bochs/bochs_hw.c | 64 ++++++++++++++++++++++------ drivers/gpu/drm/bochs/bochs_kms.c | 40 ++++++++++++++++- drivers/gpu/drm/drm_fourcc.c | 28 ++++++++++++ drivers/gpu/drm/drm_framebuffer.c | 15 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 6 ++- drivers/gpu/drm/virtio/virtgpu_display.c | 5 +++ drivers/gpu/drm/virtio/virtgpu_fb.c | 2 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 7 ++- drivers/gpu/drm/virtio/virtgpu_plane.c | 54 +---------------------- 12 files changed, 155 insertions(+), 90 deletions(-)
Signature · 6 lines
2.9.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v3 1/5 drm: move native byte order quirk to new drm_mode_legacy_fb_format2 function
Turns out we need the pixel format fixup not only for the addfb ioctl, but also for fbdev emulation code.
Ideally we would place it in drm_mode_legacy_fb_format(). That would create alot of churn though, and most drivers don't care because they never ever run on a big endian platform. So add a new drm_mode_legacy_fb_format2() function instead.
--- include/drm/drm_fourcc.h | 2 ++ drivers/gpu/drm/drm_fourcc.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/drm_framebuffer.c | 15 +++------------ 3 files changed, 33 insertions(+), 12 deletions(-)
include/drm/drm_fourcc.h +2 -0
@@ -88,6 +88,8 @@ const struct drm_format_info * drm_get_format_info(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd);uint32_t drm_mode_legacy_fb_format (uint32_t bpp,uint32_t depth); +uint32_t drm_mode_legacy_fb_format2 (uint32_t bpp,uint32_t depth, +bool native);int drm_format_num_planes (uint32_t format);int drm_format_plane_cpp (uint32_t format,int plane);int drm_format_horz_chroma_subsampling (uint32_t format);
drivers/gpu/drm/drm_fourcc.c +28 -0
@@ -96,6 +96,34 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)EXPORT_SYMBOL (drm_mode_legacy_fb_format);/** +* drm_mode_legacy_fb_format2 - compute drm fourcc code from legacy description +* @bpp: bits per pixels +* @depth: bit depth per pixel +* @native: use host native byte order +* +* Computes a drm fourcc pixel format code for the given @bpp/@depth values. +* Useful in fbdev emulation code, since that deals in those values. +*/ +uint32_t drm_mode_legacy_fb_format2 (uint32_t bpp,uint32_t depth, +bool native) +{ +uint32_t fmt =drm_mode_legacy_fb_format (bpp, depth); + +if (native) { +if (fmt ==DRM_FORMAT_XRGB8888 ) + fmt =DRM_FORMAT_HOST_XRGB8888 ; +if (fmt ==DRM_FORMAT_ARGB8888 ) + fmt =DRM_FORMAT_HOST_ARGB8888 ; +if (fmt ==DRM_FORMAT_RGB565 ) + fmt =DRM_FORMAT_HOST_RGB565 ; +if (fmt ==DRM_FORMAT_XRGB1555 ) + fmt =DRM_FORMAT_HOST_XRGB1555 ; + } +return fmt; +} +EXPORT_SYMBOL (drm_mode_legacy_fb_format2); + +/** * drm_get_format_name - fill a string with a drm fourcc format's name * @format: format to compute name of * @buf: caller-supplied buffer
drivers/gpu/drm/drm_framebuffer.c +3 -12
@@ -111,12 +111,14 @@ int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or, struct drm_file *file_priv) {struct drm_mode_fb_cmd2 r = {}; +bool native = dev->mode_config.quirk_addfb_prefer_host_byte_order;int ret;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EOPNOTSUPP ; - r.pixel_format =drm_mode_legacy_fb_format (or->bpp, or->depth); + r.pixel_format =drm_mode_legacy_fb_format2 (or->bpp, or->depth, + native);if (r.pixel_format ==DRM_FORMAT_INVALID ) {DRM_DEBUG ("bad {bpp:%d, depth:%d}\n" , or->bpp, or->depth);return -EINVAL ;
@@ -133,17 +135,6 @@ int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or, r.pixel_format == DRM_FORMAT_XRGB2101010) r.pixel_format = DRM_FORMAT_XBGR2101010; -if (dev->mode_config.quirk_addfb_prefer_host_byte_order) { -if (r.pixel_format ==DRM_FORMAT_XRGB8888 ) - r.pixel_format =DRM_FORMAT_HOST_XRGB8888 ; -if (r.pixel_format ==DRM_FORMAT_ARGB8888 ) - r.pixel_format =DRM_FORMAT_HOST_ARGB8888 ; -if (r.pixel_format ==DRM_FORMAT_RGB565 ) - r.pixel_format =DRM_FORMAT_HOST_RGB565 ; -if (r.pixel_format ==DRM_FORMAT_XRGB1555 ) - r.pixel_format =DRM_FORMAT_HOST_XRGB1555 ; - } - ret =drm_mode_addfb2 (dev, &r, file_priv);if (ret)return ret;
Signature · 1 line
2.9.3
Re: [PATCH v3 1/5] drm: move native byte order quirk to new drm_mode_legacy_fb_format2 function
Quoted 36 lines · Gerd Hoffmann
Turns out we need the pixel format fixup not only for the addfb ioctl, but also for fbdev emulation code.
Ideally we would place it in
drm_mode_legacy_fb_format(). That would create alot of churn though, and most drivers don't care because they never ever run on a big endian platform. So add a newdrm_mode_legacy_fb_format2()function instead.Signed-off-by Gerd Hoffmann <[email protected]>--- include/drm/drm_fourcc.h | 2 ++ drivers/gpu/drm/drm_fourcc.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/drm_framebuffer.c | 15 +++------------ 3 files changed, 33 insertions(+), 12 deletions(-)include/drm/drm_fourcc.h +2
-0@@ -88,6 +88,8 @@ const struct drm_format_info * drm_get_format_info(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd);uint32_t drm_mode_legacy_fb_format (uint32_t bpp,uint32_t depth); +uint32_t drm_mode_legacy_fb_format2 (uint32_t bpp,uint32_t depth, +bool native);int drm_format_num_planes (uint32_t format);int drm_format_plane_cpp (uint32_t format,int plane);int drm_format_horz_chroma_subsampling (uint32_t format);drivers/gpu/drm/drm_fourcc.c +0
-0@@ -96,6 +96,34 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)EXPORT_SYMBOL (drm_mode_legacy_fb_format);/**
drivers/gpu/drm/drm_fourcc.c uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) · line 108
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +10
-0+* drm_mode_legacy_fb_format2 - compute drm fourcc code from legacy description +* @bpp: bits per pixels +* @depth: bit depth per pixel +* @native: use host native byte order +* +* Computes a drm fourcc pixel format code for the given @bpp/@depth values. +* Useful in fbdev emulation code, since that deals in those values. +*/ +uint32_t drm_mode_legacy_fb_format2 (uint32_t bpp,uint32_t depth, +bool native)
A _2 function is a bit meh imo. What about legacy_fb_format_native() instead, which unconditionally gives you the native format, and then pulling the if (native) out?
Or slightly more future proof (given that we have the nouveau hack too):
drm_device_legacy_fb_format(drm_device *dev, bpp, depth);
to make it clear that this is the device-specific conversion function. -Daniel
Quoted 66 lines
drivers/gpu/drm/drm_fourcc.c +18
-0+{ +uint32_t fmt =drm_mode_legacy_fb_format (bpp, depth); + +if (native) { +if (fmt ==DRM_FORMAT_XRGB8888 ) + fmt =DRM_FORMAT_HOST_XRGB8888 ; +if (fmt ==DRM_FORMAT_ARGB8888 ) + fmt =DRM_FORMAT_HOST_ARGB8888 ; +if (fmt ==DRM_FORMAT_RGB565 ) + fmt =DRM_FORMAT_HOST_RGB565 ; +if (fmt ==DRM_FORMAT_XRGB1555 ) + fmt =DRM_FORMAT_HOST_XRGB1555 ; + } +return fmt; +} +EXPORT_SYMBOL (drm_mode_legacy_fb_format2); + +/** * drm_get_format_name - fill a string with a drm fourcc format's name * @format: format to compute name of * @buf: caller-supplied buffer drivers/gpu/drm/drm_framebuffer.c +3
-12@@ -111,12 +111,14 @@ int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or, struct drm_file *file_priv) {struct drm_mode_fb_cmd2 r = {}; +bool native = dev->mode_config.quirk_addfb_prefer_host_byte_order;int ret;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EOPNOTSUPP ; - r.pixel_format =drm_mode_legacy_fb_format (or->bpp, or->depth); + r.pixel_format =drm_mode_legacy_fb_format2 (or->bpp, or->depth, + native);if (r.pixel_format ==DRM_FORMAT_INVALID ) {DRM_DEBUG ("bad {bpp:%d, depth:%d}\n" , or->bpp, or->depth);return -EINVAL ;@@ -133,17 +135,6 @@ int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or, r.pixel_format == DRM_FORMAT_XRGB2101010) r.pixel_format = DRM_FORMAT_XBGR2101010; -if (dev->mode_config.quirk_addfb_prefer_host_byte_order) { -if (r.pixel_format ==DRM_FORMAT_XRGB8888 ) - r.pixel_format =DRM_FORMAT_HOST_XRGB8888 ; -if (r.pixel_format ==DRM_FORMAT_ARGB8888 ) - r.pixel_format =DRM_FORMAT_HOST_ARGB8888 ; -if (r.pixel_format ==DRM_FORMAT_RGB565 ) - r.pixel_format =DRM_FORMAT_HOST_RGB565 ; -if (r.pixel_format ==DRM_FORMAT_XRGB1555 ) - r.pixel_format =DRM_FORMAT_HOST_XRGB1555 ; - } - ret =drm_mode_addfb2 (dev, &r, file_priv);if (ret)return ret;Signature · 6 lines
2.9.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Gerd Hoffmann
maintainerPATCH v3 2/5 drm: use drm_mode_legacy_fb_format2 in drm_gem_fbdev_fb_create
In reply to Gerd HoffmannCreating framebuffers for fbdev emulation should use the correct format code too, so switch drm_gem_fbdev_fb_create() over to use the new drm_mode_legacy_fb_format2() function.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4 -2
@@ -308,6 +308,7 @@ drm_gem_fbdev_fb_create(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) {struct drm_mode_fb_cmd2 mode_cmd = {0 }; +bool native = dev->mode_config.quirk_addfb_prefer_host_byte_order; mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height;
@@ -316,8 +317,9 @@ drm_gem_fbdev_fb_create(struct drm_device *dev,if (pitch_align) mode_cmd.pitches[0 ] =roundup (mode_cmd.pitches[0 ], pitch_align); - mode_cmd.pixel_format =drm_mode_legacy_fb_format (sizes->surface_bpp, - sizes->surface_depth); + mode_cmd.pixel_format =drm_mode_legacy_fb_format2 (sizes->surface_bpp, + sizes->surface_depth, + native);if (obj->size < mode_cmd.pitches[0 ] * mode_cmd.height)return ERR_PTR (-EINVAL );
Signature · 6 lines
2.9.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v3 3/5 drm/bochs: fix DRM_FORMAT_* handling for big endian machines.
In reply to Gerd HoffmannUse DRM_FORMAT_HOST_XRGB8888, so we are using the correct format code on bigendian machines. Also set the quirk_addfb_prefer_host_byte_order mode_config bit so drm_mode_addfb() asks for the correct format code.
Create our own plane and use drm_crtc_init_with_planes() instead of depending on the default created by drm_crtc_init(). That way the plane format list is correct on bigendian machines.
Also re-add the framebuffer format check dropped by "df2052cc92 bochs:
convert to drm_fb_helper_fbdev_setup/teardown".
With this patch applied both ADDFB and ADDFB2 ioctls work correctly in the bochs-drm.ko driver on big endian machines. Without the patch only ADDFB (which still seems to be used by the majority of userspace) works correctly.
--- drivers/gpu/drm/bochs/bochs_fbdev.c | 17 +++++++++++++---- drivers/gpu/drm/bochs/bochs_kms.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-)
drivers/gpu/drm/bochs/bochs_fbdev.c +13 -4
@@ -63,9 +63,8 @@ static int bochsfb_create(struct drm_fb_helper *helper, mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height; - mode_cmd.pitches[0 ] = mode_cmd.width * ((sizes->surface_bpp +7 ) /8 ); - mode_cmd.pixel_format =drm_mode_legacy_fb_format (sizes->surface_bpp, - sizes->surface_depth); + mode_cmd.pitches[0 ] = sizes->surface_width *4 ; + mode_cmd.pixel_format =DRM_FORMAT_HOST_XRGB8888 ; size = mode_cmd.pitches[0 ] * mode_cmd.height;/* alloc, pin & map bo */
@@ -137,8 +136,18 @@ static const struct drm_fb_helper_funcs bochs_fb_helper_funcs = { .fb_probe = bochsfb_create, }; +static struct drm_framebuffer * +bochs_gem_fb_create (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) +{ +if (mode_cmd->pixel_format !=DRM_FORMAT_HOST_XRGB8888 ) +return ERR_PTR (-EINVAL ); + +return drm_gem_fb_create (dev, file, mode_cmd); +} +const struct drm_mode_config_funcs bochs_mode_funcs = { - .fb_create = drm_gem_fb_create, + .fb_create = bochs_gem_fb_create, };int bochs_fbdev_init (struct bochs_device *bochs)
drivers/gpu/drm/bochs/bochs_kms.c +33 -1
@@ -126,12 +126,43 @@ static const struct drm_crtc_helper_funcs bochs_helper_funcs = { .commit = bochs_crtc_commit, }; +static const uint32_t bochs_formats[] = { +DRM_FORMAT_HOST_XRGB8888 , +}; + +static struct drm_plane *bochs_primary_plane (struct drm_device *dev) +{ +struct drm_plane *primary; +int ret; + + primary =kzalloc (sizeof (*primary),GFP_KERNEL ); +if (primary ==NULL ) { +DRM_DEBUG_KMS ("Failed to allocate primary plane\n" ); +return NULL ; + } + + ret =drm_universal_plane_init (dev, primary,0 , + &drm_primary_helper_funcs, + bochs_formats, +ARRAY_SIZE (bochs_formats), +NULL , +DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret) { +kfree (primary); + primary =NULL ; + } + +return primary; +} +static void bochs_crtc_init (struct drm_device *dev) {struct bochs_device *bochs = dev->dev_private;struct drm_crtc *crtc = &bochs->crtc; +struct drm_plane *primary =bochs_primary_plane (dev); -drm_crtc_init (dev, crtc, &bochs_crtc_funcs); +drm_crtc_init_with_planes (dev, crtc, primary,NULL , + &bochs_crtc_funcs,NULL );drm_crtc_helper_add (crtc, &bochs_helper_funcs); }
@@ -250,6 +281,7 @@ int bochs_kms_init(struct bochs_device *bochs) bochs->dev->mode_config.fb_base = bochs->fb_base; bochs->dev->mode_config.preferred_depth =24 ; bochs->dev->mode_config.prefer_shadow =0 ; + bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; bochs->dev->mode_config.funcs = &bochs_mode_funcs;
Signature · 1 line
2.9.3
Gerd Hoffmann
maintainerPATCH v3 3/5 drm/bochs: fix DRM_FORMAT_* handling for big endian machines.
In reply to Gerd HoffmannUse DRM_FORMAT_HOST_XRGB8888, so we are using the correct format code on bigendian machines. Also set the quirk_addfb_prefer_host_byte_order mode_config bit so drm_mode_addfb() asks for the correct format code.
Create our own plane and use drm_crtc_init_with_planes() instead of depending on the default created by drm_crtc_init(). That way the plane format list is correct on bigendian machines.
Also re-add the framebuffer format check dropped by "df2052cc92 bochs:
convert to drm_fb_helper_fbdev_setup/teardown".
With this patch applied both ADDFB and ADDFB2 ioctls work correctly in the bochs-drm.ko driver on big endian machines. Without the patch only ADDFB (which still seems to be used by the majority of userspace) works correctly.
--- drivers/gpu/drm/bochs/bochs_fbdev.c | 17 +++++++++++++---- drivers/gpu/drm/bochs/bochs_kms.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-)
drivers/gpu/drm/bochs/bochs_fbdev.c +13 -4
@@ -63,9 +63,8 @@ static int bochsfb_create(struct drm_fb_helper *helper, mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height; - mode_cmd.pitches[0 ] = mode_cmd.width * ((sizes->surface_bpp +7 ) /8 ); - mode_cmd.pixel_format =drm_mode_legacy_fb_format (sizes->surface_bpp, - sizes->surface_depth); + mode_cmd.pitches[0 ] = sizes->surface_width *4 ; + mode_cmd.pixel_format =DRM_FORMAT_HOST_XRGB8888 ; size = mode_cmd.pitches[0 ] * mode_cmd.height;/* alloc, pin & map bo */
@@ -137,8 +136,18 @@ static const struct drm_fb_helper_funcs bochs_fb_helper_funcs = { .fb_probe = bochsfb_create, }; +static struct drm_framebuffer * +bochs_gem_fb_create (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) +{ +if (mode_cmd->pixel_format !=DRM_FORMAT_HOST_XRGB8888 ) +return ERR_PTR (-EINVAL ); + +return drm_gem_fb_create (dev, file, mode_cmd); +} +const struct drm_mode_config_funcs bochs_mode_funcs = { - .fb_create = drm_gem_fb_create, + .fb_create = bochs_gem_fb_create, };int bochs_fbdev_init (struct bochs_device *bochs)
drivers/gpu/drm/bochs/bochs_kms.c +33 -1
@@ -126,12 +126,43 @@ static const struct drm_crtc_helper_funcs bochs_helper_funcs = { .commit = bochs_crtc_commit, }; +static const uint32_t bochs_formats[] = { +DRM_FORMAT_HOST_XRGB8888 , +}; + +static struct drm_plane *bochs_primary_plane (struct drm_device *dev) +{ +struct drm_plane *primary; +int ret; + + primary =kzalloc (sizeof (*primary),GFP_KERNEL ); +if (primary ==NULL ) { +DRM_DEBUG_KMS ("Failed to allocate primary plane\n" ); +return NULL ; + } + + ret =drm_universal_plane_init (dev, primary,0 , + &drm_primary_helper_funcs, + bochs_formats, +ARRAY_SIZE (bochs_formats), +NULL , +DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret) { +kfree (primary); + primary =NULL ; + } + +return primary; +} +static void bochs_crtc_init (struct drm_device *dev) {struct bochs_device *bochs = dev->dev_private;struct drm_crtc *crtc = &bochs->crtc; +struct drm_plane *primary =bochs_primary_plane (dev); -drm_crtc_init (dev, crtc, &bochs_crtc_funcs); +drm_crtc_init_with_planes (dev, crtc, primary,NULL , + &bochs_crtc_funcs,NULL );drm_crtc_helper_add (crtc, &bochs_helper_funcs); }
@@ -250,6 +281,7 @@ int bochs_kms_init(struct bochs_device *bochs) bochs->dev->mode_config.fb_base = bochs->fb_base; bochs->dev->mode_config.preferred_depth =24 ; bochs->dev->mode_config.prefer_shadow =0 ; + bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; bochs->dev->mode_config.funcs = &bochs_mode_funcs;
Signature · 1 line
2.9.3
Gerd Hoffmann
maintainerPATCH v3 4/5 drm/bochs: support changing byteorder at mode set time
In reply to Gerd HoffmannAdd bochs_hw_set_*_endian() helper functions, to set the framebuffer byteorder at mode set time. Support both DRM_FORMAT_XRGB8888 and DRM_FORMAT_BGRX8888 framebuffer formats, no matter what the native machine byte order is.
--- drivers/gpu/drm/bochs/bochs.h | 4 ++- drivers/gpu/drm/bochs/bochs_fbdev.c | 3 +- drivers/gpu/drm/bochs/bochs_hw.c | 64 +++++++++++++++++++++++++++++-------- drivers/gpu/drm/bochs/bochs_kms.c | 8 +++-- 4 files changed, 61 insertions(+), 18 deletions(-)
drivers/gpu/drm/bochs/bochs.h +3 -1
@@ -58,6 +58,7 @@ struct bochs_device {void __iomem *fb_map;unsigned long fb_base;unsigned long fb_size; +unsigned long qext_size;/* mode */ u16 xres;
@@ -121,7 +122,8 @@ int bochs_hw_init(struct drm_device *dev);void bochs_hw_fini (struct drm_device *dev);void bochs_hw_setmode (struct bochs_device *bochs, -struct drm_display_mode *mode); +struct drm_display_mode *mode, +const struct drm_format_info *format);void bochs_hw_setbase (struct bochs_device *bochs,int x,int y,u64 addr);
drivers/gpu/drm/bochs/bochs_fbdev.c +2 -1
@@ -140,7 +140,8 @@ static struct drm_framebuffer * bochs_gem_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - if (mode_cmd->pixel_format != DRM_FORMAT_HOST_XRGB8888) + if (mode_cmd->pixel_format != DRM_FORMAT_XRGB8888 && + mode_cmd->pixel_format != DRM_FORMAT_BGRX8888) return ERR_PTR(-EINVAL); return drm_gem_fb_create(dev, file, mode_cmd);
drivers/gpu/drm/bochs/bochs_hw.c +50 -14
101 lines not on this page · raw message
drivers/gpu/drm/bochs/bochs_kms.c +6 -2
@@ -77,7 +77,10 @@ static int bochs_crtc_mode_set(struct drm_crtc *crtc,struct bochs_device *bochs = container_of(crtc, struct bochs_device, crtc); -bochs_hw_setmode (bochs, mode); +if (WARN_ON (crtc->primary->fb ==NULL )) +return -EINVAL ; + +bochs_hw_setmode (bochs, mode, crtc->primary->fb->format);bochs_crtc_mode_set_base (crtc, x, y, old_fb);return 0 ; }
@@ -127,7 +130,8 @@ static const struct drm_crtc_helper_funcs bochs_helper_funcs = { };static const uint32_t bochs_formats[] = { -DRM_FORMAT_HOST_XRGB8888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_BGRX8888 , };static struct drm_plane *bochs_primary_plane (struct drm_device *dev)
Signature · 1 line
2.9.3
Gerd Hoffmann
maintainerPATCH v3 5/5 drm/virtio: fix DRM_FORMAT_* handling
In reply to Gerd HoffmannUse DRM_FORMAT_HOST_XRGB8888, so we are using the correct format code on bigendian machines. Also set the quirk_addfb_prefer_host_byte_order mode_config bit so drm_mode_addfb() asks for the correct format code.
Both DRM_FORMAT_* and VIRTIO_GPU_FORMAT_* are defined to be little endian, so using a different mapping on bigendian machines is wrong. It's there because of broken drm_mode_addfb() behavior. So with drm_mode_addfb() being fixed we can fix this too.
While wading through the code I've noticed we have a little issue in
virtio: We attach a format to the bo when it is created (DRM_IOCTL_MODE_CREATE_DUMB), not when we map it as framebuffer (DRM_IOCTL_MODE_ADDFB). Easy way out: Support a single format only. Pick DRM_FORMAT_HOST_XRGB8888, it is the only one actually used in practice. Drop unused mappings in virtio_gpu_translate_format().
With this patch applied both ADDFB and ADDFB2 ioctls work correctly in the virtio-gpu.ko driver on big endian machines. Without the patch only ADDFB (which still seems to be used by the majority of userspace) works correctly.
--- drivers/gpu/drm/virtio/virtgpu_display.c | 5 +++ drivers/gpu/drm/virtio/virtgpu_fb.c | 2 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 7 +++-- drivers/gpu/drm/virtio/virtgpu_plane.c | 54 ++------------------------------ 4 files changed, 13 insertions(+), 55 deletions(-)
drivers/gpu/drm/virtio/virtgpu_display.c +5 -0
@@ -307,6 +307,10 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,struct virtio_gpu_framebuffer *virtio_gpu_fb;int ret; +if (mode_cmd->pixel_format !=DRM_FORMAT_HOST_XRGB8888 && + mode_cmd->pixel_format !=DRM_FORMAT_HOST_ARGB8888 ) +return ERR_PTR (-ENOENT ); +/* lookup object associated with res handle */ obj =drm_gem_object_lookup (file_priv, mode_cmd->handles[0 ]);if (!obj)
@@ -355,6 +359,7 @@ int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)int i;drm_mode_config_init (vgdev->ddev); + vgdev->ddev->mode_config.quirk_addfb_prefer_host_byte_order = true; vgdev->ddev->mode_config.funcs = &virtio_gpu_mode_funcs; vgdev->ddev->mode_config.helper_private = &virtio_mode_config_helpers;
drivers/gpu/drm/virtio/virtgpu_fb.c +1 -1
@@ -233,7 +233,7 @@ static int virtio_gpufb_create(struct drm_fb_helper *helper, mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height; mode_cmd.pitches[0 ] = mode_cmd.width *4 ; - mode_cmd.pixel_format =drm_mode_legacy_fb_format (32 ,24 ); + mode_cmd.pixel_format =DRM_FORMAT_HOST_XRGB8888 ; format =virtio_gpu_translate_format (mode_cmd.pixel_format);if (format ==0 )
drivers/gpu/drm/virtio/virtgpu_gem.c +5 -2
@@ -90,7 +90,10 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,uint32_t resid;uint32_t format; - pitch = args->width * ((args->bpp +1 ) /8 ); +if (args->bpp !=32 ) +return -EINVAL ; + + pitch = args->width *4 ; args->size = pitch * args->height; args->size =ALIGN (args->size,PAGE_SIZE );
@@ -99,7 +102,7 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,if (ret) goto fail; - format =virtio_gpu_translate_format (DRM_FORMAT_XRGB8888 ); + format =virtio_gpu_translate_format (DRM_FORMAT_HOST_XRGB8888 );virtio_gpu_resource_id_get (vgdev, &resid);virtio_gpu_cmd_create_resource (vgdev, resid, format, args->width, args->height);
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -52
75 lines not on this page · raw message
Signature · 1 line
2.9.3
Gerd Hoffmann
maintainerPATCH v3 5/5 drm/virtio: fix DRM_FORMAT_* handling
In reply to Gerd HoffmannUse DRM_FORMAT_HOST_XRGB8888, so we are using the correct format code on bigendian machines. Also set the quirk_addfb_prefer_host_byte_order mode_config bit so drm_mode_addfb() asks for the correct format code.
Both DRM_FORMAT_* and VIRTIO_GPU_FORMAT_* are defined to be little endian, so using a different mapping on bigendian machines is wrong. It's there because of broken drm_mode_addfb() behavior. So with drm_mode_addfb() being fixed we can fix this too.
While wading through the code I've noticed we have a little issue in
virtio: We attach a format to the bo when it is created (DRM_IOCTL_MODE_CREATE_DUMB), not when we map it as framebuffer (DRM_IOCTL_MODE_ADDFB). Easy way out: Support a single format only. Pick DRM_FORMAT_HOST_XRGB8888, it is the only one actually used in practice. Drop unused mappings in virtio_gpu_translate_format().
With this patch applied both ADDFB and ADDFB2 ioctls work correctly in the virtio-gpu.ko driver on big endian machines. Without the patch only ADDFB (which still seems to be used by the majority of userspace) works correctly.
--- drivers/gpu/drm/virtio/virtgpu_display.c | 5 +++ drivers/gpu/drm/virtio/virtgpu_fb.c | 2 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 7 +++-- drivers/gpu/drm/virtio/virtgpu_plane.c | 54 ++------------------------------ 4 files changed, 13 insertions(+), 55 deletions(-)
drivers/gpu/drm/virtio/virtgpu_display.c +5 -0
@@ -307,6 +307,10 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,struct virtio_gpu_framebuffer *virtio_gpu_fb;int ret; +if (mode_cmd->pixel_format !=DRM_FORMAT_HOST_XRGB8888 && + mode_cmd->pixel_format !=DRM_FORMAT_HOST_ARGB8888 ) +return ERR_PTR (-ENOENT ); +/* lookup object associated with res handle */ obj =drm_gem_object_lookup (file_priv, mode_cmd->handles[0 ]);if (!obj)
@@ -355,6 +359,7 @@ int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)int i;drm_mode_config_init (vgdev->ddev); + vgdev->ddev->mode_config.quirk_addfb_prefer_host_byte_order = true; vgdev->ddev->mode_config.funcs = &virtio_gpu_mode_funcs; vgdev->ddev->mode_config.helper_private = &virtio_mode_config_helpers;
drivers/gpu/drm/virtio/virtgpu_fb.c +1 -1
@@ -233,7 +233,7 @@ static int virtio_gpufb_create(struct drm_fb_helper *helper, mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height; mode_cmd.pitches[0 ] = mode_cmd.width *4 ; - mode_cmd.pixel_format =drm_mode_legacy_fb_format (32 ,24 ); + mode_cmd.pixel_format =DRM_FORMAT_HOST_XRGB8888 ; format =virtio_gpu_translate_format (mode_cmd.pixel_format);if (format ==0 )
drivers/gpu/drm/virtio/virtgpu_gem.c +5 -2
@@ -90,7 +90,10 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,uint32_t resid;uint32_t format; - pitch = args->width * ((args->bpp +1 ) /8 ); +if (args->bpp !=32 ) +return -EINVAL ; + + pitch = args->width *4 ; args->size = pitch * args->height; args->size =ALIGN (args->size,PAGE_SIZE );
@@ -99,7 +102,7 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,if (ret) goto fail; - format =virtio_gpu_translate_format (DRM_FORMAT_XRGB8888 ); + format =virtio_gpu_translate_format (DRM_FORMAT_HOST_XRGB8888 );virtio_gpu_resource_id_get (vgdev, &resid);virtio_gpu_cmd_create_resource (vgdev, resid, format, args->width, args->height);
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -52
75 lines not on this page · raw message
Signature · 1 line
2.9.3
Quoted 10 lines · Gerd Hoffmann
Fix fbdev emulation.
Fix bochs-drm and virtio-gpu drivers.Gerd Hoffmann (5):
drm: move native byte order quirk to newdrm_mode_legacy_fb_format2
function
drm: usedrm_mode_legacy_fb_format2indrm_gem_fbdev_fb_createdrm/bochs: fix DRM_FORMAT_* handling for big endian machines. drm/bochs: support changing byteorder at mode set time drm/virtio: fix DRM_FORMAT_* handling
Aside from the "naming is hard" nit, series looks good. With the naming figured out somehow, Acked-by: Daniel Vetter <[email protected]> on the entire series.
-Daniel
Quoted 22 lines
drivers/gpu/drm/bochs/bochs.h | 4 +- include/drm/drm_fourcc.h | 2 + drivers/gpu/drm/bochs/bochs_fbdev.c | 18 ++++++-- drivers/gpu/drm/bochs/bochs_hw.c | 64 ++++++++++++++++++++++------ drivers/gpu/drm/bochs/bochs_kms.c | 40 ++++++++++++++++- drivers/gpu/drm/drm_fourcc.c | 28 ++++++++++++ drivers/gpu/drm/drm_framebuffer.c | 15 ++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 6 ++- drivers/gpu/drm/virtio/virtgpu_display.c | 5 +++ drivers/gpu/drm/virtio/virtgpu_fb.c | 2 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 7 ++- drivers/gpu/drm/virtio/virtgpu_plane.c | 54 +---------------------- 12 files changed, 155 insertions(+), 90 deletions(-)Signature · 6 lines
2.9.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel