]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/{i915, xe}/fbdev: deduplicate struct drm_mode_fb_cmd2 init
authorJani Nikula <jani.nikula@intel.com>
Thu, 18 Sep 2025 08:40:54 +0000 (11:40 +0300)
committerJani Nikula <jani.nikula@intel.com>
Fri, 19 Sep 2025 06:32:36 +0000 (09:32 +0300)
Pull struct drm_mode_fb_cmd2 initialization out of the driver dependent
code into shared display code.

v2: Rebase on xe stride alignment change

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://lore.kernel.org/r/e922e47bfd39f9c5777f869ff23c23309ebbb380.1758184771.git.jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
drivers/gpu/drm/i915/display/intel_fbdev.c
drivers/gpu/drm/i915/display/intel_fbdev_fb.c
drivers/gpu/drm/i915/display/intel_fbdev_fb.h
drivers/gpu/drm/xe/display/intel_fbdev_fb.c

index 46c6de5f60888156cd8b5b085c243d32db171506..e46c08762b847d8b6a989fc4fc5745d7f5a2d2b0 100644 (file)
@@ -207,6 +207,35 @@ static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
        .fb_set_suspend = intelfb_set_suspend,
 };
 
+static void intel_fbdev_fill_mode_cmd(struct drm_fb_helper_surface_size *sizes,
+                                     struct drm_mode_fb_cmd2 *mode_cmd)
+{
+       /* we don't do packed 24bpp */
+       if (sizes->surface_bpp == 24)
+               sizes->surface_bpp = 32;
+
+       mode_cmd->width = sizes->surface_width;
+       mode_cmd->height = sizes->surface_height;
+
+       mode_cmd->pitches[0] = ALIGN(mode_cmd->width * DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
+       mode_cmd->pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
+                                                          sizes->surface_depth);
+}
+
+static struct intel_framebuffer *
+__intel_fbdev_fb_alloc(struct intel_display *display,
+                      struct drm_fb_helper_surface_size *sizes)
+{
+       struct drm_mode_fb_cmd2 mode_cmd = {};
+       struct intel_framebuffer *fb;
+
+       intel_fbdev_fill_mode_cmd(sizes, &mode_cmd);
+
+       fb = intel_fbdev_fb_alloc(display->drm, &mode_cmd);
+
+       return fb;
+}
+
 int intel_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
                                   struct drm_fb_helper_surface_size *sizes)
 {
@@ -237,7 +266,8 @@ int intel_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
        if (!fb || drm_WARN_ON(display->drm, !intel_fb_bo(&fb->base))) {
                drm_dbg_kms(display->drm,
                            "no BIOS fb, allocating a new one\n");
-               fb = intel_fbdev_fb_alloc(display->drm, sizes);
+
+               fb = __intel_fbdev_fb_alloc(display, sizes);
                if (IS_ERR(fb))
                        return PTR_ERR(fb);
        } else {
index 4de13d1a4c7a7bddd02937aea3686b342ad2c5d0..685612e6afc53ed5f2b50afa315aef63e2c8802b 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright © 2023 Intel Corporation
  */
 
-#include <drm/drm_fb_helper.h>
+#include <linux/fb.h>
 
 #include "gem/i915_gem_lmem.h"
 
 #include "intel_fbdev_fb.h"
 
 struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_device *drm,
-                                              struct drm_fb_helper_surface_size *sizes)
+                                              struct drm_mode_fb_cmd2 *mode_cmd)
 {
        struct intel_display *display = to_intel_display(drm);
        struct drm_i915_private *dev_priv = to_i915(drm);
        struct drm_framebuffer *fb;
-       struct drm_mode_fb_cmd2 mode_cmd = {};
        struct drm_i915_gem_object *obj;
        int size;
 
-       /* we don't do packed 24bpp */
-       if (sizes->surface_bpp == 24)
-               sizes->surface_bpp = 32;
-
-       mode_cmd.width = sizes->surface_width;
-       mode_cmd.height = sizes->surface_height;
-
-       mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
-                                   DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
-       mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
-                                                         sizes->surface_depth);
-
-       size = mode_cmd.pitches[0] * mode_cmd.height;
+       size = mode_cmd->pitches[0] * mode_cmd->height;
        size = PAGE_ALIGN(size);
 
        obj = ERR_PTR(-ENODEV);
@@ -64,9 +51,9 @@ struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_device *drm,
 
        fb = intel_framebuffer_create(intel_bo_to_drm_bo(obj),
                                      drm_get_format_info(drm,
-                                                         mode_cmd.pixel_format,
-                                                         mode_cmd.modifier[0]),
-                                     &mode_cmd);
+                                                         mode_cmd->pixel_format,
+                                                         mode_cmd->modifier[0]),
+                                     mode_cmd);
        if (IS_ERR(fb)) {
                i915_gem_object_put(obj);
                goto err;
index 668ae355f5e5b8103728dc7279e5307e69b3135a..83454ffbf79cd6aa67406fe2c9a529503d607dd6 100644 (file)
@@ -7,14 +7,14 @@
 #define __INTEL_FBDEV_FB_H__
 
 struct drm_device;
-struct drm_fb_helper_surface_size;
 struct drm_gem_object;
+struct drm_mode_fb_cmd2;
 struct fb_info;
 struct i915_vma;
 struct intel_display;
 
 struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_device *drm,
-                                              struct drm_fb_helper_surface_size *sizes);
+                                              struct drm_mode_fb_cmd2 *mode_cmd);
 int intel_fbdev_fb_fill_info(struct intel_display *display, struct fb_info *info,
                             struct drm_gem_object *obj, struct i915_vma *vma);
 
index b9e855c543040f648b4722010b18becff93c72d5..9c9fb34b34070ec427f90bb2381e236a80f30989 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright © 2023 Intel Corporation
  */
 
-#include <drm/drm_fb_helper.h>
+#include <linux/fb.h>
 
 #include "intel_display_core.h"
 #include "intel_display_types.h"
 #include <generated/xe_wa_oob.h>
 
 struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_device *drm,
-                                              struct drm_fb_helper_surface_size *sizes)
+                                              struct drm_mode_fb_cmd2 *mode_cmd)
 {
        struct drm_framebuffer *fb;
        struct xe_device *xe = to_xe_device(drm);
-       struct drm_mode_fb_cmd2 mode_cmd = {};
        struct xe_bo *obj;
        int size;
 
-       /* we don't do packed 24bpp */
-       if (sizes->surface_bpp == 24)
-               sizes->surface_bpp = 32;
-
-       mode_cmd.width = sizes->surface_width;
-       mode_cmd.height = sizes->surface_height;
-
-       mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
-                                   DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
-       mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
-                                                         sizes->surface_depth);
-
-       size = mode_cmd.pitches[0] * mode_cmd.height;
+       size = mode_cmd->pitches[0] * mode_cmd->height;
        size = PAGE_ALIGN(size);
        obj = ERR_PTR(-ENODEV);
 
@@ -67,9 +54,9 @@ struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_device *drm,
 
        fb = intel_framebuffer_create(&obj->ttm.base,
                                      drm_get_format_info(drm,
-                                                         mode_cmd.pixel_format,
-                                                         mode_cmd.modifier[0]),
-                                     &mode_cmd);
+                                                         mode_cmd->pixel_format,
+                                                         mode_cmd->modifier[0]),
+                                     mode_cmd);
        if (IS_ERR(fb)) {
                xe_bo_unpin_map_no_vm(obj);
                goto err;