Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Pass pixel_format+modifier directly to drm_get_format_info()

Decouple drm_get_format_info() from struct drm_mode_fb_cmd2 and just
pass the pixel format+modifier combo in by hand.

We may want to use drm_get_format_info() outside of the normal
addfb paths where we won't have a struct drm_mode_fb_cmd2, and
creating a temporary one just for this seems silly.

Done with cocci:
@@
identifier dev, mode_cmd;
@@
struct drm_format_info *
drm_get_format_info(struct drm_device *dev,
- const struct drm_mode_fb_cmd2 *mode_cmd
+ u32 pixel_format, u64 modifier
)
{
<...
(
- mode_cmd->pixel_format
+ pixel_format
|
- mode_cmd->modifier[0]
+ modifier
)
...>
}

@@
identifier dev, mode_cmd;
@@
struct drm_format_info *
drm_get_format_info(struct drm_device *dev,
- const struct drm_mode_fb_cmd2 *mode_cmd
+ u32 pixel_format, u64 modifier
);

@@
expression dev, mode_cmd;
@@
- drm_get_format_info(dev, mode_cmd)
+ drm_get_format_info(dev, mode_cmd->pixel_format, mode_cmd->modifier[0])

v2: Fix kernel docs (Laurent)
Drop drm_mode_fb_cmd2 forward declaration (Thomas)

Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Cc: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Dmitry Baryshkov <lumag@kernel.org>
Cc: Sean Paul <sean@poorly.run>
Cc: Marijn Suijten <marijn.suijten@somainline.org>
Cc: Marek Vasut <marex@denx.de>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Andy Yan <andy.yan@rock-chips.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Mikko Perttunen <mperttunen@nvidia.com>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-tegra@vger.kernel.org
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250701090722.13645-3-ville.syrjala@linux.intel.com

+48 -26
+2 -1
drivers/gpu/drm/arm/malidp_drv.c
··· 325 325 return false; 326 326 } 327 327 328 - info = drm_get_format_info(dev, mode_cmd); 328 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 329 + mode_cmd->modifier[0]); 329 330 330 331 n_superblocks = (mode_cmd->width / afbc_superblock_width) * 331 332 (mode_cmd->height / afbc_superblock_height);
+3 -1
drivers/gpu/drm/armada/armada_fb.c
··· 86 86 struct drm_framebuffer *armada_fb_create(struct drm_device *dev, 87 87 struct drm_file *dfile, const struct drm_mode_fb_cmd2 *mode) 88 88 { 89 - const struct drm_format_info *info = drm_get_format_info(dev, mode); 89 + const struct drm_format_info *info = drm_get_format_info(dev, 90 + mode->pixel_format, 91 + mode->modifier[0]); 90 92 struct armada_gem_object *obj; 91 93 struct armada_framebuffer *dfb; 92 94 int ret;
+6 -5
drivers/gpu/drm/drm_fourcc.c
··· 417 417 /** 418 418 * drm_get_format_info - query information for a given framebuffer configuration 419 419 * @dev: DRM device 420 - * @mode_cmd: metadata from the userspace fb creation request 420 + * @pixel_format: pixel format (DRM_FORMAT_*) 421 + * @modifier: modifier 421 422 * 422 423 * Returns: 423 424 * The instance of struct drm_format_info that describes the pixel format, or ··· 426 425 */ 427 426 const struct drm_format_info * 428 427 drm_get_format_info(struct drm_device *dev, 429 - const struct drm_mode_fb_cmd2 *mode_cmd) 428 + u32 pixel_format, u64 modifier) 430 429 { 431 430 const struct drm_format_info *info = NULL; 432 431 433 432 if (dev->mode_config.funcs->get_format_info) 434 - info = dev->mode_config.funcs->get_format_info(mode_cmd->pixel_format, 435 - mode_cmd->modifier[0]); 433 + info = dev->mode_config.funcs->get_format_info(pixel_format, 434 + modifier); 436 435 437 436 if (!info) 438 - info = drm_format_info(mode_cmd->pixel_format); 437 + info = drm_format_info(pixel_format); 439 438 440 439 return info; 441 440 }
+1 -1
drivers/gpu/drm/drm_framebuffer.c
··· 176 176 } 177 177 178 178 /* now let the driver pick its own format info */ 179 - info = drm_get_format_info(dev, r); 179 + info = drm_get_format_info(dev, r->pixel_format, r->modifier[0]); 180 180 181 181 for (i = 0; i < info->num_planes; i++) { 182 182 unsigned int width = drm_format_info_plane_width(info, r->width, i);
+6 -3
drivers/gpu/drm/drm_gem_framebuffer_helper.c
··· 160 160 unsigned int i; 161 161 int ret; 162 162 163 - info = drm_get_format_info(dev, mode_cmd); 163 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 164 + mode_cmd->modifier[0]); 164 165 if (!info) { 165 166 drm_dbg_kms(dev, "Failed to get FB format info\n"); 166 167 return -EINVAL; ··· 503 502 { 504 503 const struct drm_format_info *info; 505 504 506 - info = drm_get_format_info(dev, mode_cmd); 505 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 506 + mode_cmd->modifier[0]); 507 507 508 508 switch (info->format) { 509 509 case DRM_FORMAT_YUV420_8BIT: ··· 602 600 int ret; 603 601 604 602 objs = afbc_fb->base.obj; 605 - info = drm_get_format_info(dev, mode_cmd); 603 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 604 + mode_cmd->modifier[0]); 606 605 if (!info) 607 606 return -EINVAL; 608 607
+2 -1
drivers/gpu/drm/drm_modeset_helper.c
··· 86 86 int i; 87 87 88 88 fb->dev = dev; 89 - fb->format = drm_get_format_info(dev, mode_cmd); 89 + fb->format = drm_get_format_info(dev, mode_cmd->pixel_format, 90 + mode_cmd->modifier[0]); 90 91 fb->width = mode_cmd->width; 91 92 fb->height = mode_cmd->height; 92 93 for (i = 0; i < 4; i++) {
+3 -1
drivers/gpu/drm/exynos/exynos_drm_fb.c
··· 96 96 exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, 97 97 const struct drm_mode_fb_cmd2 *mode_cmd) 98 98 { 99 - const struct drm_format_info *info = drm_get_format_info(dev, mode_cmd); 99 + const struct drm_format_info *info = drm_get_format_info(dev, 100 + mode_cmd->pixel_format, 101 + mode_cmd->modifier[0]); 100 102 struct exynos_drm_gem *exynos_gem[MAX_FB_BUFFER]; 101 103 struct drm_framebuffer *fb; 102 104 int i;
+2 -1
drivers/gpu/drm/gma500/framebuffer.c
··· 39 39 * Reject unknown formats, YUV formats, and formats with more than 40 40 * 4 bytes per pixel. 41 41 */ 42 - info = drm_get_format_info(dev, mode_cmd); 42 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 43 + mode_cmd->modifier[0]); 43 44 if (!info || !info->depth || info->cpp[0] > 4) 44 45 return -EINVAL; 45 46
+3 -1
drivers/gpu/drm/mediatek/mtk_drm_drv.c
··· 45 45 struct drm_file *file, 46 46 const struct drm_mode_fb_cmd2 *cmd) 47 47 { 48 - const struct drm_format_info *info = drm_get_format_info(dev, cmd); 48 + const struct drm_format_info *info = drm_get_format_info(dev, 49 + cmd->pixel_format, 50 + cmd->modifier[0]); 49 51 50 52 if (info->num_planes != 1) 51 53 return ERR_PTR(-EINVAL);
+4 -2
drivers/gpu/drm/msm/msm_fb.c
··· 142 142 struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) 143 143 { 144 144 const struct drm_format_info *info = drm_get_format_info(dev, 145 - mode_cmd); 145 + mode_cmd->pixel_format, 146 + mode_cmd->modifier[0]); 146 147 struct drm_gem_object *bos[4] = {0}; 147 148 struct drm_framebuffer *fb; 148 149 int ret, i, n = info->num_planes; ··· 174 173 const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) 175 174 { 176 175 const struct drm_format_info *info = drm_get_format_info(dev, 177 - mode_cmd); 176 + mode_cmd->pixel_format, 177 + mode_cmd->modifier[0]); 178 178 struct msm_drm_private *priv = dev->dev_private; 179 179 struct msm_kms *kms = priv->kms; 180 180 struct msm_framebuffer *msm_fb = NULL;
+2 -1
drivers/gpu/drm/mxsfb/mxsfb_drv.c
··· 95 95 { 96 96 const struct drm_format_info *info; 97 97 98 - info = drm_get_format_info(dev, mode_cmd); 98 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 99 + mode_cmd->modifier[0]); 99 100 if (!info) 100 101 return ERR_PTR(-EINVAL); 101 102
+2 -1
drivers/gpu/drm/nouveau/nouveau_display.c
··· 295 295 kind = nvbo->kind; 296 296 } 297 297 298 - info = drm_get_format_info(dev, mode_cmd); 298 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 299 + mode_cmd->modifier[0]); 299 300 300 301 for (i = 0; i < info->num_planes; i++) { 301 302 height = drm_format_info_plane_height(info,
+4 -2
drivers/gpu/drm/omapdrm/omap_fb.c
··· 338 338 struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) 339 339 { 340 340 const struct drm_format_info *info = drm_get_format_info(dev, 341 - mode_cmd); 341 + mode_cmd->pixel_format, 342 + mode_cmd->modifier[0]); 342 343 unsigned int num_planes = info->num_planes; 343 344 struct drm_gem_object *bos[4]; 344 345 struct drm_framebuffer *fb; ··· 379 378 dev, mode_cmd, mode_cmd->width, mode_cmd->height, 380 379 (char *)&mode_cmd->pixel_format); 381 380 382 - format = drm_get_format_info(dev, mode_cmd); 381 + format = drm_get_format_info(dev, mode_cmd->pixel_format, 382 + mode_cmd->modifier[0]); 383 383 384 384 for (i = 0; i < ARRAY_SIZE(formats); i++) { 385 385 if (formats[i] == mode_cmd->pixel_format)
+2 -1
drivers/gpu/drm/radeon/radeon_fbdev.c
··· 67 67 int height = mode_cmd->height; 68 68 u32 cpp; 69 69 70 - info = drm_get_format_info(rdev_to_drm(rdev), mode_cmd); 70 + info = drm_get_format_info(rdev_to_drm(rdev), mode_cmd->pixel_format, 71 + mode_cmd->modifier[0]); 71 72 cpp = info->cpp[0]; 72 73 73 74 /* need to align pitch with crtc limits */
+2 -1
drivers/gpu/drm/rockchip/rockchip_drm_fb.c
··· 36 36 const struct drm_format_info *info; 37 37 int ret; 38 38 39 - info = drm_get_format_info(dev, mode_cmd); 39 + info = drm_get_format_info(dev, mode_cmd->pixel_format, 40 + mode_cmd->modifier[0]); 40 41 if (!info) 41 42 return ERR_PTR(-ENOMEM); 42 43
+3 -1
drivers/gpu/drm/tegra/fb.c
··· 134 134 struct drm_file *file, 135 135 const struct drm_mode_fb_cmd2 *cmd) 136 136 { 137 - const struct drm_format_info *info = drm_get_format_info(drm, cmd); 137 + const struct drm_format_info *info = drm_get_format_info(drm, 138 + cmd->pixel_format, 139 + cmd->modifier[0]); 138 140 struct tegra_bo *planes[4]; 139 141 struct drm_gem_object *gem; 140 142 struct drm_framebuffer *fb;
+1 -2
include/drm/drm_fourcc.h
··· 54 54 #endif 55 55 56 56 struct drm_device; 57 - struct drm_mode_fb_cmd2; 58 57 59 58 /** 60 59 * struct drm_format_info - information about a DRM format ··· 308 309 const struct drm_format_info *drm_format_info(u32 format); 309 310 const struct drm_format_info * 310 311 drm_get_format_info(struct drm_device *dev, 311 - const struct drm_mode_fb_cmd2 *mode_cmd); 312 + u32 pixel_format, u64 modifier); 312 313 uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); 313 314 uint32_t drm_driver_legacy_fb_format(struct drm_device *dev, 314 315 uint32_t bpp, uint32_t depth);