Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89073EE20A0 for ; Fri, 6 Feb 2026 13:35:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E66D610E6E6; Fri, 6 Feb 2026 13:35:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="WvRlgDpz"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="EGtvkqfj"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WvRlgDpz"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="EGtvkqfj"; dkim-atps=neutral Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1A00510E6E6 for ; Fri, 6 Feb 2026 13:35:14 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 1FCC15BCCB; Fri, 6 Feb 2026 13:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1770384903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CW0Pf0nQKxwYs+rEAw/1y0QYQcpJ6MDXe/a9G5zq0U8=; b=WvRlgDpzxD6Vfkrqpyp2M3riRYhBhOtOLXFbkR/xhOOkPV2w5c82NwsWEsAFq+9Gk36LlQ ayvwvmkFXX9JpmMHZyx/0q06EfSNX3a+zZcCc5ytKHH9Hwbvcu55Jxp/K5rztIf62HtovS 0TJYomhjavV8tKVvUcBzL5NT8VjXtEo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1770384903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CW0Pf0nQKxwYs+rEAw/1y0QYQcpJ6MDXe/a9G5zq0U8=; b=EGtvkqfjRt63AWdIo+RGLvHmxqpZK0cnFJuggMtMEnihB9YmI/ynAwGTHDV1J+QyQ4owHH 5YJ04s4qZPwJRYDg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=WvRlgDpz; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=EGtvkqfj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1770384903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CW0Pf0nQKxwYs+rEAw/1y0QYQcpJ6MDXe/a9G5zq0U8=; b=WvRlgDpzxD6Vfkrqpyp2M3riRYhBhOtOLXFbkR/xhOOkPV2w5c82NwsWEsAFq+9Gk36LlQ ayvwvmkFXX9JpmMHZyx/0q06EfSNX3a+zZcCc5ytKHH9Hwbvcu55Jxp/K5rztIf62HtovS 0TJYomhjavV8tKVvUcBzL5NT8VjXtEo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1770384903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CW0Pf0nQKxwYs+rEAw/1y0QYQcpJ6MDXe/a9G5zq0U8=; b=EGtvkqfjRt63AWdIo+RGLvHmxqpZK0cnFJuggMtMEnihB9YmI/ynAwGTHDV1J+QyQ4owHH 5YJ04s4qZPwJRYDg== 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 D39243EA64; Fri, 6 Feb 2026 13:35:02 +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 sL1zMgbuhWnncwAAD6G6ig (envelope-from ); Fri, 06 Feb 2026 13:35:02 +0000 From: Thomas Zimmermann To: patrik.r.jakobsson@gmail.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann Subject: [PATCH 3/5] drm/gma500: fbdev: Calculate buffer geometry with format helpers Date: Fri, 6 Feb 2026 14:21:56 +0100 Message-ID: <20260206133458.226467-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260206133458.226467-1-tzimmermann@suse.de> References: <20260206133458.226467-1-tzimmermann@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-1.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_TO(0.00)[gmail.com,linux.intel.com,kernel.org,ffwll.ch]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:dkim,suse.de:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Rspamd-Queue-Id: 1FCC15BCCB X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Replace the geometry and size calculation in gma500's fbdev emulation with DRM format helpers. This consists of 4CC lookup from the fbdev parameters, format loockup, pitch calculation and size calculation. Then allocate the GEM buffer object for the framebuffer memory from the calculated size. As before, fallback to 16-bit colors if the stolen memory is insufficient for 32-bit colors. But look at the result from psb_gem_create() instead of guessing before the allocation. The new method is more reliable when others allocate from stolen video memory (e.g., cursors). Set up mode_cmd with the calculated values just before allocating the framebuffer. This code will later be replaced with a DRM client buffer. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/gma500/fbdev.c | 60 ++++++++++++++++------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/gma500/fbdev.c b/drivers/gpu/drm/gma500/fbdev.c index f5e60ada6de2..a93c3d2fe0ff 100644 --- a/drivers/gpu/drm/gma500/fbdev.c +++ b/drivers/gpu/drm/gma500/fbdev.c @@ -109,56 +109,52 @@ int psb_fbdev_driver_fbdev_probe(struct drm_fb_helper *fb_helper, struct drm_psb_private *dev_priv = to_drm_psb_private(dev); struct pci_dev *pdev = to_pci_dev(dev->dev); struct fb_info *info = fb_helper->info; + u32 fourcc, pitch; + u64 size; + const struct drm_format_info *format; struct drm_framebuffer *fb; struct drm_mode_fb_cmd2 mode_cmd = { }; - int size; int ret; struct psb_gem_object *backing; struct drm_gem_object *obj; - u32 bpp, depth; /* No 24-bit packed mode */ if (sizes->surface_bpp == 24) { sizes->surface_bpp = 32; sizes->surface_depth = 24; } - bpp = sizes->surface_bpp; - depth = sizes->surface_depth; - /* - * If the mode does not fit in 32 bit then switch to 16 bit to get - * a console on full resolution. The X mode setting server will - * allocate its own 32-bit GEM framebuffer. - */ - size = ALIGN(sizes->surface_width * DIV_ROUND_UP(bpp, 8), 64) * - sizes->surface_height; - size = ALIGN(size, PAGE_SIZE); +try_psb_gem_create: + fourcc = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth); + format = drm_get_format_info(dev, fourcc, DRM_FORMAT_MOD_LINEAR); + pitch = ALIGN(drm_format_info_min_pitch(format, 0, sizes->surface_width), SZ_64); + size = ALIGN(pitch * sizes->surface_height, PAGE_SIZE); - if (size > dev_priv->vram_stolen_size) { - sizes->surface_bpp = 16; - sizes->surface_depth = 16; + /* Allocate the framebuffer in the GTT with stolen page backing */ + backing = psb_gem_create(dev, size, "fb", true, PAGE_SIZE); + if (IS_ERR(backing)) { + ret = PTR_ERR(backing); + if (ret == -EBUSY && sizes->surface_bpp > 16) { + /* + * If the mode does not fit in 32 bit then switch to 16 bit to + * get a console on full resolution. User-space compositors will + * allocate their own 32-bit framebuffers. + */ + sizes->surface_bpp = 16; + sizes->surface_depth = 16; + goto try_psb_gem_create; + } + return ret; } - bpp = sizes->surface_bpp; - depth = sizes->surface_depth; + obj = &backing->base; mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height; - mode_cmd.pitches[0] = ALIGN(mode_cmd.width * DIV_ROUND_UP(bpp, 8), 64); - mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); - - size = mode_cmd.pitches[0] * mode_cmd.height; - size = ALIGN(size, PAGE_SIZE); - - /* Allocate the framebuffer in the GTT with stolen page backing */ - backing = psb_gem_create(dev, size, "fb", true, PAGE_SIZE); - if (IS_ERR(backing)) - return PTR_ERR(backing); - obj = &backing->base; + mode_cmd.pixel_format = fourcc; + mode_cmd.pitches[0] = pitch; + mode_cmd.modifier[0] = DRM_FORMAT_MOD_LINEAR; - fb = psb_framebuffer_create(dev, - drm_get_format_info(dev, mode_cmd.pixel_format, - mode_cmd.modifier[0]), - &mode_cmd, obj); + fb = psb_framebuffer_create(dev, format, &mode_cmd, obj); if (IS_ERR(fb)) { ret = PTR_ERR(fb); goto err_drm_gem_object_put; -- 2.52.0