dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: javierm@redhat.com, jfalempe@redhat.com,
	jose.exposito89@gmail.com, arthurgrillo@riseup.net,
	mairacanal@riseup.net, maarten.lankhorst@linux.intel.com,
	mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch,
	noralf@tronnes.org
Cc: Thomas Zimmermann <tzimmermann@suse.de>, dri-devel@lists.freedesktop.org
Subject: [PATCH 8/8] drm/ssd130x: Preallocate xfrm buffer in plane's atomic_check
Date: Wed, 20 Sep 2023 13:10:20 +0200	[thread overview]
Message-ID: <20230920112508.11770-9-tzimmermann@suse.de> (raw)
In-Reply-To: <20230920112508.11770-1-tzimmermann@suse.de>

Preallocate the xfrm buffer's storage in the plane's atomic_check
function if a format conversion will be necessary. Allows the update
to fail if no memory is available. Avoids the same allocation within
atomic_update, which may not fail.

Also inline drm_plane_helper_atomic_check() into the driver and thus
return early for invisible planes. Avoids memory allocation entirely
in this case.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/solomon/ssd130x.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c
index 508588bd2d565..3788d847e50ff 100644
--- a/drivers/gpu/drm/solomon/ssd130x.c
+++ b/drivers/gpu/drm/solomon/ssd130x.c
@@ -601,17 +601,27 @@ static int ssd130x_primary_plane_helper_atomic_check(struct drm_plane *plane,
 {
 	struct drm_device *drm = plane->dev;
 	struct ssd130x_device *ssd130x = drm_to_ssd130x(drm);
-	struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
-	struct ssd130x_plane_state *ssd130x_state = to_ssd130x_plane_state(plane_state);
+	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+	struct ssd130x_plane_state *ssd130x_state = to_ssd130x_plane_state(new_plane_state);
+	struct drm_crtc *new_crtc = new_plane_state->crtc;
+	struct drm_crtc_state *new_crtc_state = NULL;
 	unsigned int page_height = ssd130x->device_info->page_height;
 	unsigned int pages = DIV_ROUND_UP(ssd130x->height, page_height);
 	const struct drm_format_info *fi;
 	unsigned int pitch;
 	int ret;
 
-	ret = drm_plane_helper_atomic_check(plane, state);
+	if (new_crtc)
+		new_crtc_state = drm_atomic_get_new_crtc_state(state, new_crtc);
+
+	ret = drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
+						  DRM_PLANE_NO_SCALING,
+						  DRM_PLANE_NO_SCALING,
+						  false, false);
 	if (ret)
 		return ret;
+	else if (!new_plane_state->visible)
+		return 0;
 
 	fi = drm_format_info(DRM_FORMAT_R1);
 	if (!fi)
@@ -619,6 +629,15 @@ static int ssd130x_primary_plane_helper_atomic_check(struct drm_plane *plane,
 
 	pitch = drm_format_info_min_pitch(fi, 0, ssd130x->width);
 
+	if (new_plane_state->fb->format != fi) {
+		void *buf;
+
+		/* format conversion necessary; reserve buffer */
+		buf = drm_xfrm_buf_reserve(&ssd130x->xfrm, pitch, GFP_KERNEL);
+		if (!buf)
+			return -ENOMEM;
+	}
+
 	ssd130x_state->buffer = kcalloc(pitch, ssd130x->height, GFP_KERNEL);
 	if (!ssd130x_state->buffer)
 		return -ENOMEM;
-- 
2.42.0


  parent reply	other threads:[~2023-09-20 11:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 11:10 [PATCH 0/8] drm: Reuse temporary memory for format conversion Thomas Zimmermann
2023-09-20 11:10 ` [PATCH 1/8] drm/format-helper: Add struct drm_xfrm_buf to cache " Thomas Zimmermann
2023-09-20 11:10 ` [PATCH 2/8] drm/format-helper: Pass xfrm buffer to format-conversion helpers Thomas Zimmermann
2023-09-20 11:40   ` Jani Nikula
2023-09-20 11:10 ` [PATCH 3/8] drm/simpledrm: Store xfrm buffer in device instance Thomas Zimmermann
2023-09-20 11:10 ` [PATCH 4/8] drm/simpledrm: Preallocate xfrm buffer in plane's atomic_check Thomas Zimmermann
2023-09-20 11:10 ` [PATCH 5/8] drm/ofdrm: Store xfrm buffer in device instance Thomas Zimmermann
2023-09-20 11:10 ` [PATCH 6/8] drm/ofdrm: Preallocate xfrm buffer in plane's atomic_check Thomas Zimmermann
2023-09-20 11:10 ` [PATCH 7/8] drm/ssd130x: Store xfrm buffer in device instance Thomas Zimmermann
2023-09-20 11:10 ` Thomas Zimmermann [this message]
2023-09-20 11:30   ` [PATCH 8/8] drm/ssd130x: Preallocate xfrm buffer in plane's atomic_check Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230920112508.11770-9-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@gmail.com \
    --cc=arthurgrillo@riseup.net \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=jfalempe@redhat.com \
    --cc=jose.exposito89@gmail.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mairacanal@riseup.net \
    --cc=mripard@kernel.org \
    --cc=noralf@tronnes.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox