Store and instance of struct drm_xfrm_buf in struct ssd130x_device and keep the allocated memory allocated across display updates. Avoid possibly reallocating temporary memory on each display update. Instead preallocate temporary memory during initialization. Releasing the DRM device also releases the xfrm buffer. v2: * reserve storage during probe Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx> --- drivers/gpu/drm/solomon/ssd130x.c | 19 +++++++++++++++---- drivers/gpu/drm/solomon/ssd130x.h | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c index d11079733bc0e..93a5df31d0d9a 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -571,7 +571,6 @@ static int ssd130x_fb_blit_rect(struct drm_plane_state *state, struct ssd130x_device *ssd130x = drm_to_ssd130x(fb->dev); unsigned int page_height = ssd130x->device_info->page_height; struct ssd130x_plane_state *ssd130x_state = to_ssd130x_plane_state(state); - struct drm_xfrm_buf xfrm = DRM_XFRM_BUF_INIT; u8 *buf = ssd130x_state->buffer; struct iosys_map dst; unsigned int dst_pitch; @@ -588,14 +587,12 @@ static int ssd130x_fb_blit_rect(struct drm_plane_state *state, return ret; iosys_map_set_vaddr(&dst, buf); - drm_fb_xrgb8888_to_mono(&dst, &dst_pitch, vmap, fb, rect, &xfrm); + drm_fb_xrgb8888_to_mono(&dst, &dst_pitch, vmap, fb, rect, &ssd130x->xfrm); drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); ssd130x_update_rect(ssd130x, ssd130x_state, rect); - drm_xfrm_buf_release(&xfrm); - return ret; } @@ -1084,6 +1081,8 @@ struct ssd130x_device *ssd130x_probe(struct device *dev, struct regmap *regmap) struct ssd130x_device *ssd130x; struct backlight_device *bl; struct drm_device *drm; + const struct drm_format_info *fi; + void *buf; int ret; ssd130x = devm_drm_dev_alloc(dev, &ssd130x_drm_driver, @@ -1117,6 +1116,18 @@ struct ssd130x_device *ssd130x_probe(struct device *dev, struct regmap *regmap) bl->props.max_brightness = MAX_CONTRAST; ssd130x->bl_dev = bl; + ret = drmm_xfrm_buf_init(drm, &ssd130x->xfrm); + if (ret) + return ERR_PTR(ret); + fi = drm_format_info(DRM_FORMAT_R1); + if (!fi) + return ERR_PTR(-EINVAL); + buf = drm_xfrm_buf_reserve(&ssd130x->xfrm, + drm_format_info_min_pitch(fi, 0, ssd130x->width), + GFP_KERNEL); + if (!buf) + return ERR_PTR(-ENOMEM); + ret = ssd130x_init_modeset(ssd130x); if (ret) return ERR_PTR(ret); diff --git a/drivers/gpu/drm/solomon/ssd130x.h b/drivers/gpu/drm/solomon/ssd130x.h index 87968b3e7fb82..f4e525feb2188 100644 --- a/drivers/gpu/drm/solomon/ssd130x.h +++ b/drivers/gpu/drm/solomon/ssd130x.h @@ -17,6 +17,7 @@ #include <drm/drm_crtc.h> #include <drm/drm_drv.h> #include <drm/drm_encoder.h> +#include <drm/drm_format_helper.h> #include <drm/drm_plane_helper.h> #include <linux/regmap.h> @@ -55,6 +56,8 @@ struct ssd130x_device { struct drm_connector connector; struct i2c_client *client; + struct drm_xfrm_buf xfrm; + struct regmap *regmap; const struct ssd130x_deviceinfo *device_info; -- 2.42.0