drm: introduce fb_modifiers_not_supported flag in mode_config
authorTomohito Esaki <etom@igel.co.jp>
Fri, 28 Jan 2022 06:08:34 +0000 (15:08 +0900)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 31 Jan 2022 20:45:23 +0000 (21:45 +0100)
If only linear modifier is advertised, since there are many drivers that
only linear supported, the DRM core should handle this rather than
open-coding in every driver. However, there are legacy drivers such as
radeon that do not support modifiers but infer the actual layout of the
underlying buffer. Therefore, a new flag fb_modifiers_not_supported is
introduced for these legacy drivers, and allow_fb_modifiers is replaced
with this new flag.

v3:
 - change the order as follows:
   1. add fb_modifiers_not_supported flag
   2. add default modifiers
   3. remove allow_fb_modifiers flag
 - add a conditional disable in amdgpu_dm_plane_init()

v4:
 - modify kernel docs

v5:
 - modify kernel docs

Signed-off-by: Tomohito Esaki <etom@igel.co.jp>
Acked-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20220128060836.11216-2-etom@igel.co.jp
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
drivers/gpu/drm/drm_framebuffer.c
drivers/gpu/drm/drm_ioctl.c
drivers/gpu/drm/nouveau/nouveau_display.c
drivers/gpu/drm/radeon/radeon_display.c
include/drm/drm_mode_config.h

index 9a273420a67a50e333feeddc01a74cfe6037360a..4c847f48f276e944b233dee2e7fc5e6c3c823b8a 100644 (file)
@@ -956,7 +956,7 @@ static int amdgpu_display_verify_sizes(struct amdgpu_framebuffer *rfb)
        int ret;
        unsigned int i, block_width, block_height, block_size_log2;
 
-       if (!rfb->base.dev->mode_config.allow_fb_modifiers)
+       if (rfb->base.dev->mode_config.fb_modifiers_not_supported)
                return 0;
 
        for (i = 0; i < format_info->num_planes; ++i) {
@@ -1143,7 +1143,7 @@ int amdgpu_display_framebuffer_init(struct drm_device *dev,
        if (ret)
                return ret;
 
-       if (!dev->mode_config.allow_fb_modifiers) {
+       if (dev->mode_config.fb_modifiers_not_supported) {
                drm_WARN_ONCE(dev, adev->family >= AMDGPU_FAMILY_AI,
                              "GFX9+ requires FB check based on format modifier\n");
                ret = check_tiling_flags_gfx6(rfb);
@@ -1151,7 +1151,7 @@ int amdgpu_display_framebuffer_init(struct drm_device *dev,
                        return ret;
        }
 
-       if (dev->mode_config.allow_fb_modifiers &&
+       if (!dev->mode_config.fb_modifiers_not_supported &&
            !(rfb->base.flags & DRM_MODE_FB_MODIFIERS)) {
                ret = convert_tiling_flags_to_modifier(rfb);
                if (ret) {
index d1570a462a51a95088fbbbde4ad27be74f3b0465..fb61c08141154e69da731ab9c39cf18666006e27 100644 (file)
@@ -2798,6 +2798,8 @@ static int dce_v10_0_sw_init(void *handle)
        adev_to_drm(adev)->mode_config.preferred_depth = 24;
        adev_to_drm(adev)->mode_config.prefer_shadow = 1;
 
+       adev_to_drm(adev)->mode_config.fb_modifiers_not_supported = true;
+
        adev_to_drm(adev)->mode_config.fb_base = adev->gmc.aper_base;
 
        r = amdgpu_display_modeset_create_props(adev);
index 18a7b3bd633b5d06198b129ceb25e7ef3677a3ef..17942a11366d2e1a49c32277b164d748888c6893 100644 (file)
@@ -2916,6 +2916,8 @@ static int dce_v11_0_sw_init(void *handle)
        adev_to_drm(adev)->mode_config.preferred_depth = 24;
        adev_to_drm(adev)->mode_config.prefer_shadow = 1;
 
+       adev_to_drm(adev)->mode_config.fb_modifiers_not_supported = true;
+
        adev_to_drm(adev)->mode_config.fb_base = adev->gmc.aper_base;
 
        r = amdgpu_display_modeset_create_props(adev);
index c7803dc2b2d533d295ec4b0f65db99da92b90f7d..2ec99ec8e1a3409839b7110e24b836f9411babb8 100644 (file)
@@ -2674,6 +2674,7 @@ static int dce_v6_0_sw_init(void *handle)
        adev_to_drm(adev)->mode_config.max_height = 16384;
        adev_to_drm(adev)->mode_config.preferred_depth = 24;
        adev_to_drm(adev)->mode_config.prefer_shadow = 1;
+       adev_to_drm(adev)->mode_config.fb_modifiers_not_supported = true;
        adev_to_drm(adev)->mode_config.fb_base = adev->gmc.aper_base;
 
        r = amdgpu_display_modeset_create_props(adev);
index 8318ee8339f1b9af4165b5f7c5a09590be608585..de11fbe5aba2988beb49e105629c9627f7bb01ab 100644 (file)
@@ -2695,6 +2695,8 @@ static int dce_v8_0_sw_init(void *handle)
        adev_to_drm(adev)->mode_config.preferred_depth = 24;
        adev_to_drm(adev)->mode_config.prefer_shadow = 1;
 
+       adev_to_drm(adev)->mode_config.fb_modifiers_not_supported = true;
+
        adev_to_drm(adev)->mode_config.fb_base = adev->gmc.aper_base;
 
        r = amdgpu_display_modeset_create_props(adev);
index 39812daeb7c5757c51edb2f1b437fa1945b7e0d4..e8a994559b65800af8cb513191cac1f9984667b2 100644 (file)
@@ -7828,6 +7828,9 @@ static int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
        if (res)
                return res;
 
+       if (modifiers == NULL)
+               adev_to_drm(dm->adev)->mode_config.fb_modifiers_not_supported = true;
+
        res = drm_universal_plane_init(adev_to_drm(dm->adev), plane, possible_crtcs,
                                       &dm_plane_funcs, formats, num_formats,
                                       modifiers, plane->type, NULL);
index 07f5abc875e97b96873f246cd3eea293e6978100..4562a8b865792456afa0ff18b7454c2a9fce8f95 100644 (file)
@@ -309,7 +309,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
        }
 
        if (r->flags & DRM_MODE_FB_MODIFIERS &&
-           !dev->mode_config.allow_fb_modifiers) {
+           dev->mode_config.fb_modifiers_not_supported) {
                DRM_DEBUG_KMS("driver does not support fb modifiers\n");
                return ERR_PTR(-EINVAL);
        }
@@ -594,7 +594,7 @@ int drm_mode_getfb2_ioctl(struct drm_device *dev,
        r->pixel_format = fb->format->format;
 
        r->flags = 0;
-       if (dev->mode_config.allow_fb_modifiers)
+       if (!dev->mode_config.fb_modifiers_not_supported)
                r->flags |= DRM_MODE_FB_MODIFIERS;
 
        for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
@@ -607,7 +607,7 @@ int drm_mode_getfb2_ioctl(struct drm_device *dev,
        for (i = 0; i < fb->format->num_planes; i++) {
                r->pitches[i] = fb->pitches[i];
                r->offsets[i] = fb->offsets[i];
-               if (dev->mode_config.allow_fb_modifiers)
+               if (!dev->mode_config.fb_modifiers_not_supported)
                        r->modifier[i] = fb->modifier;
        }
 
index 8b8744dcf69138928ac1a932dc56103822c4c248..51fcf1298023501aed80fd9a188ed21d1d402ac8 100644 (file)
@@ -297,7 +297,7 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
                        req->value = 64;
                break;
        case DRM_CAP_ADDFB2_MODIFIERS:
-               req->value = dev->mode_config.allow_fb_modifiers;
+               req->value = !dev->mode_config.fb_modifiers_not_supported;
                break;
        case DRM_CAP_CRTC_IN_VBLANK_EVENT:
                req->value = 1;
index 2b460835a438c4cac1317e68a85d19bf6d6bd960..2cd0932b3d687f7e624e88efb3f7c058de41ae8d 100644 (file)
@@ -708,10 +708,12 @@ nouveau_display_create(struct drm_device *dev)
                                     &disp->disp);
                if (ret == 0) {
                        nouveau_display_create_properties(dev);
-                       if (disp->disp.object.oclass < NV50_DISP)
+                       if (disp->disp.object.oclass < NV50_DISP) {
+                               dev->mode_config.fb_modifiers_not_supported = true;
                                ret = nv04_display_create(dev);
-                       else
+                       } else {
                                ret = nv50_display_create(dev);
+                       }
                }
        } else {
                ret = 0;
index 573154268d43a44d0f5b65501256a2a9587487af..b9a07677a71e504fd4b4dc18db4cd6f5ddf01b6a 100644 (file)
@@ -1596,6 +1596,8 @@ int radeon_modeset_init(struct radeon_device *rdev)
        rdev->ddev->mode_config.preferred_depth = 24;
        rdev->ddev->mode_config.prefer_shadow = 1;
 
+       rdev->ddev->mode_config.fb_modifiers_not_supported = true;
+
        rdev->ddev->mode_config.fb_base = rdev->mc.aper_base;
 
        ret = radeon_modeset_create_props(rdev);
index 91ca575a78de89d6ca50ca2cf93aeae19af440ef..4a93dac91cf981800cbf8b614c69b5af49019670 100644 (file)
@@ -933,6 +933,16 @@ struct drm_mode_config {
         */
        bool allow_fb_modifiers;
 
+       /**
+        * @fb_modifiers_not_supported:
+        *
+        * When this flag is set, the DRM device will not expose modifier
+        * support to userspace. This is only used by legacy drivers that infer
+        * the buffer layout through heuristics without using modifiers. New
+        * drivers shall not set fhis flag.
+        */
+       bool fb_modifiers_not_supported;
+
        /**
         * @normalize_zpos:
         *