drm: move native byte order quirk to new drm_driver_legacy_fb_format function
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 21 Sep 2018 13:46:59 +0000 (15:46 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Tue, 25 Sep 2018 12:49:49 +0000 (14:49 +0200)
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_driver_legacy_fb_format() function instead which looks at the
mode_config->quirk_addfb_prefer_host_byte_order flag.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20180921134704.12826-2-kraxel@redhat.com
drivers/gpu/drm/drm_fourcc.c
drivers/gpu/drm/drm_framebuffer.c
include/drm/drm_fourcc.h

index be1d6aaef6518f8b88e014c31f1a9c1045fd2ff1..7c6d3922ed400d2cd6d9fd392361836ab3b0838c 100644 (file)
@@ -95,6 +95,36 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 }
 EXPORT_SYMBOL(drm_mode_legacy_fb_format);
 
+/**
+ * drm_driver_legacy_fb_format - 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.
+ * Unlike drm_mode_legacy_fb_format() this looks at the drivers mode_config,
+ * and depending on the quirk_addfb_prefer_host_byte_order flag it returns
+ * little endian byte order or host byte order framebuffer formats.
+ */
+uint32_t drm_driver_legacy_fb_format(struct drm_device *dev,
+                                    uint32_t bpp, uint32_t depth)
+{
+       uint32_t fmt = drm_mode_legacy_fb_format(bpp, depth);
+
+       if (dev->mode_config.quirk_addfb_prefer_host_byte_order) {
+               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_driver_legacy_fb_format);
+
 /**
  * drm_get_format_name - fill a string with a drm fourcc format's name
  * @format: format to compute name of
index 1ee3d6b44280a9b6f9b081185326e214ba732320..1e2126101c18f9cf7913ea8f34f3c834aada7015 100644 (file)
@@ -116,7 +116,7 @@ int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or,
        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_driver_legacy_fb_format(dev, or->bpp, or->depth);
        if (r.pixel_format == DRM_FORMAT_INVALID) {
                DRM_DEBUG("bad {bpp:%d, depth:%d}\n", or->bpp, or->depth);
                return -EINVAL;
@@ -133,17 +133,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;
index fac831c401065c9059190a811b91d32fdf92de98..865ef60c17af385d2eb55db2d8c53a2f08d7ca07 100644 (file)
@@ -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_driver_legacy_fb_format(struct drm_device *dev,
+                                    uint32_t bpp, uint32_t depth);
 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);