drm: Fix initializing format info in drm_framebuffer
Subsystems (5)
v2 cover drm: Fix initializing format info in drm_framebuffer
This is v2 of [1], describing in the patch logs the functional issue the patchset fixes based on Tomi's feedback and adding the T-b/A-b/R-b tags.
I would like this patchset to be included in the v6.17-rc1 release, if this is still possible. One way is to merge it to drm-misc-next-fixes, if there won't be pull request from that branch any more, could the maintainers suggest a better way?
Thanks,
Imre
[1] https://lore.kernel.org/all/[email protected]
Imre Deak (3):
drm/omap: Pass along the format info from .fb_create() to
drm_helper_mode_fill_fb_struct()
drm/nouveau: Pass along the format info from .fb_create() to
drm_helper_mode_fill_fb_struct()
drm/radeon: Pass along the format info from .fb_create() to
drm_helper_mode_fill_fb_struct()
drivers/gpu/drm/nouveau/nouveau_display.c | 9 +++------ drivers/gpu/drm/nouveau/nouveau_display.h | 3 +++ drivers/gpu/drm/omapdrm/omap_fb.c | 23 ++++++++++------------- drivers/gpu/drm/omapdrm/omap_fb.h | 2 ++ drivers/gpu/drm/omapdrm/omap_fbdev.c | 5 ++++- drivers/gpu/drm/radeon/radeon_display.c | 5 +++-- drivers/gpu/drm/radeon/radeon_fbdev.c | 11 ++++++----- drivers/gpu/drm/radeon/radeon_mode.h | 2 ++ 8 files changed, 33 insertions(+), 27 deletions(-)
Signature · 1 line
2.49.1
PATCH v2 1/3 drm/omap: Pass along the format info from .fb_create() to drm_helper_mode_fill_fb_struct()
Plumb the format info from .fb_create() all the way to drm_helper_mode_fill_fb_struct() to avoid the redundant lookup.
For the fbdev case a manual drm_get_format_info() lookup is needed.
The patch is based on the driver parts of the patchset at Link:
below, which missed converting the omap driver.
Due to the absence of this change in the patchset at Link:, after the
Fixed: commit below, omap_framebuffer_init() -> drm_helper_mode_fill_fb_struct() set drm_framebuffer::format incorrectly to NULL, which lead to the !fb->format WARN() in drm_framebuffer_init() and causing framebuffer creation to fail. This patch fixes both of these issues.
v2: Amend the commit log mentioning the functional issues the patch
fixes. (Tomi)
--- drivers/gpu/drm/omapdrm/omap_fb.c | 23 ++++++++++------------- drivers/gpu/drm/omapdrm/omap_fb.h | 2 ++ drivers/gpu/drm/omapdrm/omap_fbdev.c | 5 ++++- 3 files changed, 16 insertions(+), 14 deletions(-)
drivers/gpu/drm/omapdrm/omap_fb.c +10 -13
@@ -351,7 +351,7 @@ struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, } } - fb =omap_framebuffer_init (dev, mode_cmd, bos); + fb =omap_framebuffer_init (dev, info, mode_cmd, bos);if (IS_ERR (fb)) goto error;
@@ -365,9 +365,9 @@ struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, }struct drm_framebuffer *omap_framebuffer_init (struct drm_device *dev, +const struct drm_format_info *info,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **bos) { -const struct drm_format_info *format =NULL ;struct omap_framebuffer *omap_fb =NULL ;struct drm_framebuffer *fb =NULL ;unsigned int pitch = mode_cmd->pitches[0 ];
@@ -377,15 +377,12 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, dev, mode_cmd, mode_cmd->width, mode_cmd->height, (char *)&mode_cmd->pixel_format); - format =drm_get_format_info (dev, mode_cmd->pixel_format, - mode_cmd->modifier[0 ]); -for (i =0 ; i <ARRAY_SIZE (formats); i++) {if (formats[i] == mode_cmd->pixel_format)break ; } -if (!format || i ==ARRAY_SIZE (formats)) { +if (i ==ARRAY_SIZE (formats)) {dev_dbg (dev->dev,"unsupported pixel format: %4.4s\n" , (char *)&mode_cmd->pixel_format); ret = -EINVAL ;
@@ -399,7 +396,7 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, } fb = &omap_fb->base; - omap_fb->format = format; + omap_fb->format = info;mutex_init (&omap_fb->lock);/*
@@ -407,23 +404,23 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,* that the two planes of multiplane formats need the same number of * bytes per pixel. */ -if (format->num_planes ==2 && pitch != mode_cmd->pitches[1 ]) { +if (info->num_planes ==2 && pitch != mode_cmd->pitches[1 ]) {dev_dbg (dev->dev,"pitches differ between planes 0 and 1\n" ); ret = -EINVAL ; goto fail; } -if (pitch % format->cpp[0 ]) { +if (pitch % info->cpp[0 ]) {dev_dbg (dev->dev,"buffer pitch (%u bytes) is not a multiple of pixel size (%u bytes)\n" , - pitch, format->cpp[0 ]); + pitch, info->cpp[0 ]); ret = -EINVAL ; goto fail; } -for (i =0 ; i < format->num_planes; i++) { +for (i =0 ; i < info->num_planes; i++) {struct plane *plane = &omap_fb->planes[i]; -unsigned int vsub = i ==0 ?1 : format->vsub; +unsigned int vsub = i ==0 ?1 : info->vsub;unsigned int size; size = pitch * mode_cmd->height / vsub;
@@ -440,7 +437,7 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, plane->dma_addr =0 ; } -drm_helper_mode_fill_fb_struct (dev, fb,NULL , mode_cmd); +drm_helper_mode_fill_fb_struct (dev, fb, info, mode_cmd); ret =drm_framebuffer_init (dev, fb, &omap_framebuffer_funcs);if (ret) {
drivers/gpu/drm/omapdrm/omap_fb.h +2 -0
@@ -13,6 +13,7 @@ struct drm_connector;struct drm_device ;struct drm_file ;struct drm_framebuffer ; +struct drm_format_info ;struct drm_gem_object ;struct drm_mode_fb_cmd2 ;struct drm_plane_state ;
@@ -23,6 +24,7 @@ struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, struct drm_file *file, const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd);struct drm_framebuffer *omap_framebuffer_init (struct drm_device *dev, +const struct drm_format_info *info,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **bos);int omap_framebuffer_pin (struct drm_framebuffer *fb);void omap_framebuffer_unpin (struct drm_framebuffer *fb);
drivers/gpu/drm/omapdrm/omap_fbdev.c +4 -1
@@ -197,7 +197,10 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, goto fail; } - fb =omap_framebuffer_init (dev, &mode_cmd, &bo); + fb =omap_framebuffer_init (dev, +drm_get_format_info (dev, mode_cmd.pixel_format, + mode_cmd.modifier[0 ]), + &mode_cmd, &bo);if (IS_ERR (fb)) {dev_err (dev->dev,"failed to allocate fb\n" );/* note: if fb creation failed, we can't rely on fb destroy
Signature · 1 line
2.49.1
PATCH v2 2/3 drm/nouveau: Pass along the format info from .fb_create() to drm_helper_mode_fill_fb_struct()
In reply to Imre DeakPlumb the format info from .fb_create() all the way to drm_helper_mode_fill_fb_struct() to avoid the redundant lookup.
The patch is based on the driver parts of the patchset at Link:
below, which missed converting the nouveau driver.
Due to the absence of this change in the patchset at Link:, after the
Fixed: commit below, nouveau_framebuffer_new() -> drm_helper_mode_fill_fb_struct() set drm_framebuffer::format incorrectly to NULL, which lead to the !fb->format WARN() in drm_framebuffer_init() and causing framebuffer creation to fail. This patch fixes both of these issues.
v2: Amend the commit log mentioning the functional issues the patch
fixes. (Tomi)
--- drivers/gpu/drm/nouveau/nouveau_display.c | 9 +++------ drivers/gpu/drm/nouveau/nouveau_display.h | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/nouveau/nouveau_display.c +3 -6
@@ -253,6 +253,7 @@ nouveau_check_bl_size(struct nouveau_drm *drm, struct nouveau_bo *nvbo,int nouveau_framebuffer_new (struct drm_device *dev, +const struct drm_format_info *info,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object *gem,struct drm_framebuffer **pfb)
@@ -260,7 +261,6 @@ nouveau_framebuffer_new(struct drm_device *dev,struct nouveau_drm *drm =nouveau_drm (dev);struct nouveau_bo *nvbo =nouveau_gem_object (gem);struct drm_framebuffer *fb; -const struct drm_format_info *info;unsigned int height, i;uint32_t tile_mode;uint8_t kind;
@@ -295,9 +295,6 @@ nouveau_framebuffer_new(struct drm_device *dev, kind = nvbo->kind; } - info =drm_get_format_info (dev, mode_cmd->pixel_format, - mode_cmd->modifier[0 ]); -for (i =0 ; i < info->num_planes; i++) { height = drm_format_info_plane_height(info, mode_cmd->height,
@@ -321,7 +318,7 @@ nouveau_framebuffer_new(struct drm_device *dev,if (!(fb = *pfb =kzalloc (sizeof (*fb),GFP_KERNEL )))return -ENOMEM ; -drm_helper_mode_fill_fb_struct (dev, fb,NULL , mode_cmd); +drm_helper_mode_fill_fb_struct (dev, fb, info, mode_cmd); fb->obj[0 ] = gem; ret =drm_framebuffer_init (dev, fb, &nouveau_framebuffer_funcs);
@@ -344,7 +341,7 @@ nouveau_user_framebuffer_create(struct drm_device *dev,if (!gem)return ERR_PTR (-ENOENT ); - ret =nouveau_framebuffer_new (dev, mode_cmd, gem, &fb); + ret =nouveau_framebuffer_new (dev, info, mode_cmd, gem, &fb);if (ret ==0 )return fb;
drivers/gpu/drm/nouveau/nouveau_display.h +3 -0
@@ -8,8 +8,11 @@#include <drm/drm_framebuffer.h> +struct drm_format_info ; +int nouveau_framebuffer_new (struct drm_device *dev, +const struct drm_format_info *info,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object *gem,struct drm_framebuffer **pfb);
Signature · 1 line
2.49.1
PATCH v2 3/3 drm/radeon: Pass along the format info from .fb_create() to drm_helper_mode_fill_fb_struct()
In reply to Imre DeakPlumb the format info from .fb_create() all the way to drm_helper_mode_fill_fb_struct() to avoid the redundant lookup.
For the fbdev case a manual drm_get_format_info() lookup is needed.
The patch is based on the driver parts of the patchset at Link:
below, which missed converting the radeon driver.
Due to the absence of this change in the patchset at Link:, after the
Fixed: commit below, radeon_framebuffer_init() -> drm_helper_mode_fill_fb_struct() set drm_framebuffer::format incorrectly to NULL, which lead to the !fb->format WARN() in drm_framebuffer_init() and causing framebuffer creation to fail. This patch fixes both of these issues.
v2: Amend the commit log mentioning the functional issues the patch
fixes. (Tomi)
--- drivers/gpu/drm/radeon/radeon_display.c | 5 +++-- drivers/gpu/drm/radeon/radeon_fbdev.c | 11 ++++++----- drivers/gpu/drm/radeon/radeon_mode.h | 2 ++ 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/radeon/radeon_display.c +3 -2
@@ -1297,12 +1297,13 @@ static const struct drm_framebuffer_funcs radeon_fb_funcs = {int radeon_framebuffer_init (struct drm_device *dev,struct drm_framebuffer *fb, +const struct drm_format_info *info,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object *obj) {int ret; fb->obj[0 ] = obj; -drm_helper_mode_fill_fb_struct (dev, fb,NULL , mode_cmd); +drm_helper_mode_fill_fb_struct (dev, fb, info, mode_cmd); ret =drm_framebuffer_init (dev, fb, &radeon_fb_funcs);if (ret) { fb->obj[0 ] =NULL ;
@@ -1341,7 +1342,7 @@ radeon_user_framebuffer_create(struct drm_device *dev,return ERR_PTR (-ENOMEM ); } - ret =radeon_framebuffer_init (dev, fb, mode_cmd, obj); + ret =radeon_framebuffer_init (dev, fb, info, mode_cmd, obj);if (ret) {kfree (fb);drm_gem_object_put (obj);
drivers/gpu/drm/radeon/radeon_fbdev.c +6 -5
@@ -53,10 +53,10 @@ static void radeon_fbdev_destroy_pinned_object(struct drm_gem_object *gobj) }static int radeon_fbdev_create_pinned_object (struct drm_fb_helper *fb_helper, +const struct drm_format_info *info,struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **gobj_p) { -const struct drm_format_info *info;struct radeon_device *rdev = fb_helper->dev->dev_private;struct drm_gem_object *gobj =NULL ;struct radeon_bo *rbo =NULL ;
@@ -67,8 +67,6 @@ static int radeon_fbdev_create_pinned_object(struct drm_fb_helper *fb_helper,int height = mode_cmd->height;u32 cpp; - info =drm_get_format_info (rdev_to_drm (rdev), mode_cmd->pixel_format, - mode_cmd->modifier[0 ]); cpp = info->cpp[0 ];/* need to align pitch with crtc limits */
@@ -206,6 +204,7 @@ int radeon_fbdev_driver_fbdev_probe(struct drm_fb_helper *fb_helper, struct drm_fb_helper_surface_size *sizes) {struct radeon_device *rdev = fb_helper->dev->dev_private; +const struct drm_format_info *format_info;struct drm_mode_fb_cmd2 mode_cmd = { };struct fb_info *info;struct drm_gem_object *gobj;
@@ -224,7 +223,9 @@ int radeon_fbdev_driver_fbdev_probe(struct drm_fb_helper *fb_helper, mode_cmd.pixel_format =drm_mode_legacy_fb_format (sizes->surface_bpp, sizes->surface_depth); - ret =radeon_fbdev_create_pinned_object (fb_helper, &mode_cmd, &gobj); + format_info =drm_get_format_info (rdev_to_drm (rdev), mode_cmd.pixel_format, + mode_cmd.modifier[0 ]); + ret =radeon_fbdev_create_pinned_object (fb_helper, format_info, &mode_cmd, &gobj);if (ret) {DRM_ERROR ("failed to create fbcon object %d\n" , ret);return ret;
@@ -236,7 +237,7 @@ int radeon_fbdev_driver_fbdev_probe(struct drm_fb_helper *fb_helper, ret = -ENOMEM ; goto err_radeon_fbdev_destroy_pinned_object; } - ret =radeon_framebuffer_init (rdev_to_drm (rdev), fb, &mode_cmd, gobj); + ret =radeon_framebuffer_init (rdev_to_drm (rdev), fb, format_info, &mode_cmd, gobj);if (ret) {DRM_ERROR ("failed to initialize framebuffer %d\n" , ret); goto err_kfree;
drivers/gpu/drm/radeon/radeon_mode.h +2 -0
@@ -40,6 +40,7 @@struct drm_fb_helper ;struct drm_fb_helper_surface_size ; +struct drm_format_info ;struct edid ;struct drm_edid ;
@@ -890,6 +891,7 @@ extern void radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on);int radeon_framebuffer_init (struct drm_device *dev,struct drm_framebuffer *rfb, +const struct drm_format_info *info,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object *obj);
Signature · 1 line
2.49.1
Quoted 8 lines · Imre Deak
This is v2 of [1], describing in the patch logs the functional issue the patchset fixes based on Tomi's feedback and adding the T-b/A-b/R-b tags.
I would like this patchset to be included in the v6.17-rc1 release, if this is still possible. One way is to merge it to drm-misc-next-fixes, if there won't be pull request from that branch any more, could the maintainers suggest a better way?
Ok, not sure if there will be a v6.17-rc1 PR from drm-misc-next-fixes, but merging the patchset there makes sense to me in any case, so did that now.
Thanks for the report, testing, acks and reviews.
Quoted 43 lines
Thanks,
Imre[1] https://lore.kernel.org/all/[email protected]
Cc Ville Syrjälä <[email protected]>Cc Mark Brown <[email protected]>Cc Tomi Valkeinen <[email protected]>Cc Lyude Paul <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Alex Deucher <[email protected]>Cc James Jones <[email protected]>Cc Naresh Kamboju <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>Cc Christian König <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Imre Deak (3):
drm/omap: Pass along the format info from .fb_create() to
drm_helper_mode_fill_fb_struct()
drm/nouveau: Pass along the format info from .fb_create() to
drm_helper_mode_fill_fb_struct()
drm/radeon: Pass along the format info from .fb_create() to
drm_helper_mode_fill_fb_struct()drivers/gpu/drm/nouveau/nouveau_display.c | 9 +++------ drivers/gpu/drm/nouveau/nouveau_display.h | 3 +++ drivers/gpu/drm/omapdrm/omap_fb.c | 23 ++++++++++------------- drivers/gpu/drm/omapdrm/omap_fb.h | 2 ++ drivers/gpu/drm/omapdrm/omap_fbdev.c | 5 ++++- drivers/gpu/drm/radeon/radeon_display.c | 5 +++-- drivers/gpu/drm/radeon/radeon_fbdev.c | 11 ++++++----- drivers/gpu/drm/radeon/radeon_mode.h | 2 ++ 8 files changed, 33 insertions(+), 27 deletions(-)Signature · 1 line
2.49.1