From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42FDD606A31E for ; Tue, 24 Nov 2026 07:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=0HKZW/KI; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=RvfUoK8J; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QTL0IBEI; dkim=neutral header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=RvfUoK8J; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QTL0IBEI DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=oOy2yoxFTmtBtmqxddydcBqpF8aGEH7F/iYI6h7X9Aw=; b=0HKZW/KIpME5pD uB+ICI27mmJPPREmtDngqsVumE1jmw6uVCG9i0/5NaqgAkMZhOD9adK22HhMFsu4jhqVPZ5pajB6J qfWcQuAMpIMIUQ2dSeq9b5cMY3i1D0lKZpL+jpljO8Ui8ucqQCNtVYzA5duXNhsj//tf51NuHEacB UhhRE+gGWOtw0QlMsJ1rsrnWJE9xbXC67aM/HkaU+f1SeQLF2MgNG3+jsTQ/oFg0CkK1P/0dImqlq k1Xl6C3rB/VxCAo/YEEZI03Ea26qgB57UkmIFWHSeXYBSGdvpSo47+7sJVYZLAtMLby8r1M03h2u9 pTfT+4RB0yaLy1eLRQkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVlFb-00000005oEG-03R3; Tue, 24 Nov 2026 07:47:39 +0000 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVlFX-00000005oDP-3GOx for linux-arm-kernel@lists.infradead.org; Tue, 24 Nov 2026 07:47:37 +0000 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4B6501FBF8; Tue, 24 Nov 2026 07:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795506451; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=oOy2yoxFTmtBtmqxddydcBqpF8aGEH7F/iYI6h7X9Aw=; b=RvfUoK8JJZe4f5lyx5Lz0+zPMnfXTy8v7njLppBgBVYV9+OYxNUS2W9fcwJGqMCAfkOnF3 aqFG5+egUF2rBiuN8GPJcDMgqd/0M2D6q7Z3iGEPkkh9zp8dMb7YNVpggKpaJ8hF3Ixw0z Fl/etUjMWvJJT4KVfs6pGp6IH1jdFpA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795506451; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=oOy2yoxFTmtBtmqxddydcBqpF8aGEH7F/iYI6h7X9Aw=; b=QTL0IBEIbQT850ndMXYNNwXMSr8MzU9rt2RETzPKXHuYtDSO77baHodckBS+K4wuPZvn+w mwXZhkOS8Gwt32Aw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1795506451; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=oOy2yoxFTmtBtmqxddydcBqpF8aGEH7F/iYI6h7X9Aw=; b=RvfUoK8JJZe4f5lyx5Lz0+zPMnfXTy8v7njLppBgBVYV9+OYxNUS2W9fcwJGqMCAfkOnF3 aqFG5+egUF2rBiuN8GPJcDMgqd/0M2D6q7Z3iGEPkkh9zp8dMb7YNVpggKpaJ8hF3Ixw0z Fl/etUjMWvJJT4KVfs6pGp6IH1jdFpA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1795506451; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=oOy2yoxFTmtBtmqxddydcBqpF8aGEH7F/iYI6h7X9Aw=; b=QTL0IBEIbQT850ndMXYNNwXMSr8MzU9rt2RETzPKXHuYtDSO77baHodckBS+K4wuPZvn+w mwXZhkOS8Gwt32Aw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 744561339F; Tue, 24 Nov 2026 07:47:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id TsLkCRJBBWuHYQAAD6G6ig (envelope-from ); Tue, 24 Nov 2026 07:47:30 +0000 Message-ID: Date: Tue, 24 Nov 2026 08:47:29 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFT v3 1/5] drm: Split framebuffer pixel offset calculation from drm_fb_dma_get_gem_addr() To: Chen-Yu Tsai , Liu Ying , Laurentiu Palcu , Lucas Stach , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maarten Lankhorst , Maxime Ripard Cc: David Airlie , Simona Vetter , linux-sunxi@lists.linux.dev, imx@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261124074041.115251-1-wenst@chromium.org> <20261124074041.115251-2-wenst@chromium.org> Content-Language: en-US From: Thomas Zimmermann Autocrypt: addr=tzimmermann@suse.de; keydata= xsBNBFs50uABCADEHPidWt974CaxBVbrIBwqcq/WURinJ3+2WlIrKWspiP83vfZKaXhFYsdg XH47fDVbPPj+d6tQrw5lPQCyqjwrCPYnq3WlIBnGPJ4/jreTL6V+qfKRDlGLWFjZcsrPJGE0 BeB5BbqP5erN1qylK9i3gPoQjXGhpBpQYwRrEyQyjuvk+Ev0K1Jc5tVDeJAuau3TGNgah4Yc hdHm3bkPjz9EErV85RwvImQ1dptvx6s7xzwXTgGAsaYZsL8WCwDaTuqFa1d1jjlaxg6+tZsB 9GluwvIhSezPgnEmimZDkGnZRRSFiGP8yjqTjjWuf0bSj5rUnTGiyLyRZRNGcXmu6hjlABEB AAHNJ1Rob21hcyBaaW1tZXJtYW5u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uIh7MXkl0fxbRKWE93XeQBhIJHQfnc+YBLprdnxR446Sh8Wn/2D Ya8cavuWf2zrB6cZurs048xe0UbSW5AOSo4V9M0jzYI4nZqTmPxYyXbm30Kvmz0rYVRaitYJ 4kyYYMhuULvrJDMjZRvaNe52tkKAvMevcGdt38H4KSVXAylqyQOW5zvPc4/sq9c= In-Reply-To: <20261124074041.115251-2-wenst@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-13.29 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; RCPT_COUNT_TWELVE(0.00)[17]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCVD_TLS_ALL(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[gmail.com,ffwll.ch,lists.linux.dev,lists.freedesktop.org,lists.infradead.org,vger.kernel.org]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:url,chromium.org:email,suse.de:email] X-Spam-Score: -13.29 X-Spam-Level: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261123_234736_132361_A75E602F X-CRM114-Status: GOOD ( 30.44 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Am 24.11.26 um 08:39 schrieb Chen-Yu Tsai: > Currently drm_fb_dma_get_gem_addr() calculates the offset into the > framebuffer memory for the framebuffer's unclipped source coordinates, > adds that to the framebuffer's backing storage, and returns the result. > > We are about to add a variant that uses the clipped source coordinates, > so there is already some reuse of code. However, calculating the data > offset for a given pixel is not specific to the DMA FB helpers. The > offset is only related to the framebuffer. > > Split out the offset calculation into a new framebuffer helper so that > non-DMA users can also reuse the same code. > > Suggested-by: Thomas Zimmermann > Cc: # dependency for next patch > Signed-off-by: Chen-Yu Tsai Reviewed-by: Thomas Zimmermann This patch is useful on its own and could be merged independently from the others. Best regards Thomas > --- > fb->offsets and fb->pitches are (or should have been) checked by the > driver's .fb_create callback, either in drm_gem_fb_init_with_funcs() > or reimplementing the checks directly. > > Changes since v2: > - Change offset local variable and return type to u64, and use > mul_u32_u32() to avoid 32-bit overflow before widening > Changes since v1: > - New patch > --- > drivers/gpu/drm/drm_fb_dma_helper.c | 28 ++---------------- > drivers/gpu/drm/drm_framebuffer.c | 46 +++++++++++++++++++++++++++++ > include/drm/drm_framebuffer.h | 3 ++ > 3 files changed, 52 insertions(+), 25 deletions(-) > > diff --git a/drivers/gpu/drm/drm_fb_dma_helper.c b/drivers/gpu/drm/drm_fb_dma_helper.c > index fd71969d2fb1..ab0f37d8a5ff 100644 > --- a/drivers/gpu/drm/drm_fb_dma_helper.c > +++ b/drivers/gpu/drm/drm_fb_dma_helper.c > @@ -75,36 +75,14 @@ dma_addr_t drm_fb_dma_get_gem_addr(struct drm_framebuffer *fb, > unsigned int plane) > { > struct drm_gem_dma_object *obj; > - dma_addr_t dma_addr; > - u8 h_div = 1, v_div = 1; > - u32 block_w = drm_format_info_block_width(fb->format, plane); > - u32 block_h = drm_format_info_block_height(fb->format, plane); > - u32 block_size = fb->format->char_per_block[plane]; > - u32 sample_x; > - u32 sample_y; > - u32 block_start_y; > - u32 num_hblocks; > > obj = drm_fb_dma_get_gem_obj(fb, plane); > if (!obj) > return 0; > > - dma_addr = obj->dma_addr + fb->offsets[plane]; > - > - if (plane > 0) { > - h_div = fb->format->hsub; > - v_div = fb->format->vsub; > - } > - > - sample_x = (state->src_x >> 16) / h_div; > - sample_y = (state->src_y >> 16) / v_div; > - block_start_y = (sample_y / block_h) * block_h; > - num_hblocks = sample_x / block_w; > - > - dma_addr += fb->pitches[plane] * block_start_y; > - dma_addr += block_size * num_hblocks; > - > - return dma_addr; > + return obj->dma_addr + drm_framebuffer_get_block_offset(fb, plane, > + state->src_x >> 16, > + state->src_y >> 16); > } > EXPORT_SYMBOL_GPL(drm_fb_dma_get_gem_addr); > > diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c > index d32aceb6ca9b..589619bd8f0b 100644 > --- a/drivers/gpu/drm/drm_framebuffer.c > +++ b/drivers/gpu/drm/drm_framebuffer.c > @@ -21,6 +21,7 @@ > */ > > #include > +#include > #include > > #include > @@ -1208,6 +1209,51 @@ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent, > } > } > > +/** > + * drm_framebuffer_get_block_offset() - Get offset to start of pixel block for > + * the given framebuffer and coordinates. > + * @fb: The framebuffer > + * @plane: Which plane > + * @x: x coordinate for pixel > + * @y: y coordinate for pixel > + * > + * This function will usually be called from the PLANE callback functions, > + * or from one of the helpers that calculates the framebuffer's DMA address. > + * > + * Return: offset from start of framebuffer to start of pixel block > + */ > +u64 drm_framebuffer_get_block_offset(struct drm_framebuffer *fb, unsigned int plane, > + unsigned int x, unsigned int y) > +{ > + u8 h_div = 1, v_div = 1; > + u32 block_w = drm_format_info_block_width(fb->format, plane); > + u32 block_h = drm_format_info_block_height(fb->format, plane); > + u32 block_size = fb->format->char_per_block[plane]; > + u32 sample_x; > + u32 sample_y; > + u32 block_start_y; > + u32 num_hblocks; > + u64 offset; > + > + offset = fb->offsets[plane]; > + > + if (plane > 0) { > + h_div = fb->format->hsub; > + v_div = fb->format->vsub; > + } > + > + sample_x = x / h_div; > + sample_y = y / v_div; > + block_start_y = (sample_y / block_h) * block_h; > + num_hblocks = sample_x / block_w; > + > + offset += mul_u32_u32(fb->pitches[plane], block_start_y); > + offset += mul_u32_u32(block_size, num_hblocks); > + > + return offset; > +} > +EXPORT_SYMBOL(drm_framebuffer_get_block_offset); > + > #ifdef CONFIG_DEBUG_FS > static int drm_framebuffer_info(struct seq_file *m, void *data) > { > diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h > index 38b24fc8978d..6f838b485730 100644 > --- a/include/drm/drm_framebuffer.h > +++ b/include/drm/drm_framebuffer.h > @@ -220,6 +220,9 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb); > void drm_framebuffer_cleanup(struct drm_framebuffer *fb); > void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); > > +u64 drm_framebuffer_get_block_offset(struct drm_framebuffer *fb, unsigned int plane, > + unsigned int x, unsigned int y); > + > /** > * drm_framebuffer_get - acquire a framebuffer reference > * @fb: DRM framebuffer -- -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)