Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7250404rdb; Wed, 3 Jan 2024 09:15:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjT4LD4Df+miXWB4g67aoe2urYDTxvvWg4lFTFoY1xxDUMi+WD6y6kExTOg3sgMm0K0lQt X-Received: by 2002:a50:d492:0:b0:551:f72c:ff4e with SMTP id s18-20020a50d492000000b00551f72cff4emr12142979edi.68.1704302116443; Wed, 03 Jan 2024 09:15:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704302116; cv=none; d=google.com; s=arc-20160816; b=TtIQZXcL4YERtNJ+5/GXOeoPGQxW2daHT47vZgWierhl+2171Eu8MMh1JtF85tIt3A IXU0QwowrNhIxKDeweiD8wGLdZmf3mveqNMDYong+N/3TSTHNi0s+tYuhO2dYtkRQwC6 HNrDtm2JnIAu6J74j5QQjm05+ZvP/oUmSPHEyHZJRaZy4nospWw4cbS2Y/xyr05nKcUD zdgbyPqooVDkY6gkHhXjM5EjePWApZi0QvR1OqrwP3yb/Fyui+k7U0FkeD7oG18mVE9i U2VeT6Coy5QpE+uAPvHV0k89E4h2A7fHNKScynI7eCky0zF6qw+q1W6Z7KlFQMaKSWiB /68A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=v6UmRXAQluppzFow4ZjI3gs+x7tGXMy7iMXQ0B/VSQw=; fh=5jo4rXfVno9C807R7rrm98q063mCJoSXYoaMgGreSho=; b=TiniA3JahSdkD1c/8GYjXHbd7+XDTKTJLaE56/wj8Y3w4qqJEMhoJc4dKYiniEdqKR djvDr5N+IlOjF+hYSaz6MOQca+V8KoB/ENMucVYbq3qq4Vva+4nkMNcqvpE6UfSn6Zv0 2cVhJxjE8ixtLVsTZXYffRPJlvURWSQRywI9gsaIMeeiE3uCd6imSy6lPSDN1Inlv+Lo QrVecQTAZlfdzdm5Xn/QdVZQV4UIeA5tVIGTDRyDchMmN0isCqIg6nR6h8TB6MlamuRY HMy6TemvyjKU2uWlIk6mVlFqcr3UY/m1YNMogKYNzTH1n8Dimo6KoGsl05GCue7zkp9U 9AYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=QEQIfasv; spf=pass (google.com: domain of linux-kernel+bounces-15792-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15792-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y89-20020a50bb62000000b00551583e313bsi11849767ede.653.2024.01.03.09.15.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 09:15:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15792-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=QEQIfasv; spf=pass (google.com: domain of linux-kernel+bounces-15792-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15792-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0A8841F24F5E for ; Wed, 3 Jan 2024 17:15:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D5941C2A9; Wed, 3 Jan 2024 17:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="QEQIfasv" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46F541BDFE for ; Wed, 3 Jan 2024 17:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-db4364ecd6aso5243228276.2 for ; Wed, 03 Jan 2024 09:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1704302103; x=1704906903; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=v6UmRXAQluppzFow4ZjI3gs+x7tGXMy7iMXQ0B/VSQw=; b=QEQIfasvUzTdvtIK/qqUBzTOk3kq/cqKe86n8dmZtRSy2CBlhE6USop4cqO0NSwYYM hJmxFeGnoKge/QrXXNYLDm29dUggBCuuWVKpkl4Sr5OWxuERNsx3/wSFj+MkHSofIFQ4 BOvLLn38zZ8NJF8T/thIBEpF133x5XdHQLSsfIhneIVTJg+j8HCGyMIyV36nVSV2WV8n Z5MJN29U+XjcItbueOqg9WNMnjPbWV8JFn5yPSMYhY48BXh3R8eBMMVFw5gDfXSl+cMM wKK509aGf6aftREkkk8VstGW51s3Zh07MJpDvcQcL1lbHPXOMM+tn0IT8b+Yp7h7L34O dMOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704302103; x=1704906903; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v6UmRXAQluppzFow4ZjI3gs+x7tGXMy7iMXQ0B/VSQw=; b=Dy2HsZandPpqX6GeQ0jk1oOrA+xkkBbisZ7hde5oaO7kXFMVUgYFOrAVQH49/V5SCE rJizCkdsQ75Y4YadRU7+J4w2Z/T+McN1jApTcethpzhXvyoNNz81JAmM/Ok3DxHHBobR FpTgaK5+T2RIFx4Ie9CmwtZzVai0XJKO4ymFsGbi785+zhCJfJT4j7mLWzpJmox5d2zd nByLunqx78zJaKF/+bS96vc+Rfj9JARuL/dJlf75WH+25rJBxdO6dptLX0ohSggbvpJI 6MyRZDTqZ7M24IekMpzdPUQvGrYlsauBHC31IThCiSDLHy0+Z0gKcatkjtCV0wjJIxdm VnRA== X-Gm-Message-State: AOJu0Yxow438dtPq6z3sG2DC0Hfl/mVMhFvty1d0QEonZL3+lYpRqtB/ jXZR4vm7QETb2G0kXEYBkR5rUigCeTFtdky2pwh5HZlv/90Kiw== X-Received: by 2002:a5b:bc2:0:b0:dbe:9d10:a9af with SMTP id c2-20020a5b0bc2000000b00dbe9d10a9afmr994225ybr.33.1704302103097; Wed, 03 Jan 2024 09:15:03 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20220728-rpi-analog-tv-properties-v9-0-24b168e5bcd5@cerno.tech> <20220728-rpi-analog-tv-properties-v9-9-24b168e5bcd5@cerno.tech> In-Reply-To: From: Dave Stevenson Date: Wed, 3 Jan 2024 17:14:46 +0000 Message-ID: Subject: Re: [PATCH v9 09/25] drm/modes: Move named modes parsing to a separate function To: Maxime Ripard Cc: Karol Herbst , Samuel Holland , Joonas Lahtinen , Daniel Vetter , Chen-Yu Tsai , Maarten Lankhorst , Lyude Paul , Thomas Zimmermann , Jani Nikula , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Jernej Skrabec , Dom Cobley , Phil Elwell , Mateusz Kwiatkowski , nouveau@lists.freedesktop.org, Hans de Goede , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?UTF-8?Q?Noralf_Tr=C3=B8nnes?= , Geert Uytterhoeven , linux-sunxi@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 3 Jan 2024 at 14:02, Dave Stevenson wrote: > > Hi Maxime > > On Wed, 3 Jan 2024 at 13:33, Maxime Ripard wrote: > > > > Hi Dave, > > > > Happy new year :) > > And to you. > > > On Tue, Jan 02, 2024 at 03:12:26PM +0000, Dave Stevenson wrote: > > > Hi Maxime > > > > > > On Mon, 14 Nov 2022 at 13:00, Maxime Ripard wrote= : > > > > > > > > The current construction of the named mode parsing doesn't allow to= extend > > > > it easily. Let's move it to a separate function so we can add more > > > > parameters and modes. > > > > > > > > In order for the tests to still pass, some extra checks are needed,= so > > > > it's not a 1:1 move. > > > > > > > > Reviewed-by: Noralf Tr=C3=B8nnes > > > > Tested-by: Mateusz Kwiatkowski > > > > Signed-off-by: Maxime Ripard > > > > > > > > --- > > > > Changes in v7: > > > > - Add Noralf Reviewed-by > > > > > > > > Changes in v6: > > > > - Simplify the test for connection status extras > > > > - Simplify the code path to call drm_mode_parse_cmdline_named_mode > > > > > > > > Changes in v4: > > > > - Fold down all the named mode patches that were split into a singl= e > > > > patch again to maintain bisectability > > > > --- > > > > drivers/gpu/drm/drm_modes.c | 70 +++++++++++++++++++++++++++++++++= ++++-------- > > > > 1 file changed, 58 insertions(+), 12 deletions(-) > > > > > > > > diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_mode= s.c > > > > index 71c050c3ee6b..37542612912b 100644 > > > > --- a/drivers/gpu/drm/drm_modes.c > > > > +++ b/drivers/gpu/drm/drm_modes.c > > > > @@ -2229,6 +2229,51 @@ static const char * const drm_named_modes_wh= itelist[] =3D { > > > > "PAL", > > > > }; > > > > > > > > +static int drm_mode_parse_cmdline_named_mode(const char *name, > > > > + unsigned int name_end, > > > > + struct drm_cmdline_mod= e *cmdline_mode) > > > > +{ > > > > + unsigned int i; > > > > + > > > > + if (!name_end) > > > > + return 0; > > > > + > > > > + /* If the name starts with a digit, it's not a named mode *= / > > > > + if (isdigit(name[0])) > > > > + return 0; > > > > + > > > > + /* > > > > + * If there's an equal sign in the name, the command-line > > > > + * contains only an option and no mode. > > > > + */ > > > > + if (strnchr(name, name_end, '=3D')) > > > > + return 0; > > > > + > > > > + /* The connection status extras can be set without a mode. = */ > > > > + if (name_end =3D=3D 1 && > > > > + (name[0] =3D=3D 'd' || name[0] =3D=3D 'D' || name[0] = =3D=3D 'e')) > > > > + return 0; > > > > + > > > > + /* > > > > + * We're sure we're a named mode at this point, iterate ove= r the > > > > + * list of modes we're aware of. > > > > + */ > > > > + for (i =3D 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i+= +) { > > > > + int ret; > > > > + > > > > + ret =3D str_has_prefix(name, drm_named_modes_whitel= ist[i]); > > > > + if (ret !=3D name_end) > > > > + continue; > > > > + > > > > + strcpy(cmdline_mode->name, drm_named_modes_whitelis= t[i]); > > > > + cmdline_mode->specified =3D true; > > > > + > > > > + return 1; > > > > + } > > > > + > > > > + return -EINVAL; > > > > +} > > > > + > > > > /** > > > > * drm_mode_parse_command_line_for_connector - parse command line = modeline for connector > > > > * @mode_option: optional per connector mode option > > > > @@ -2265,7 +2310,7 @@ bool drm_mode_parse_command_line_for_connecto= r(const char *mode_option, > > > > const char *bpp_ptr =3D NULL, *refresh_ptr =3D NULL, *extra= _ptr =3D NULL; > > > > const char *options_ptr =3D NULL; > > > > char *bpp_end_ptr =3D NULL, *refresh_end_ptr =3D NULL; > > > > - int i, len, ret; > > > > + int len, ret; > > > > > > > > memset(mode, 0, sizeof(*mode)); > > > > mode->panel_orientation =3D DRM_MODE_PANEL_ORIENTATION_UNKN= OWN; > > > > @@ -2306,18 +2351,19 @@ bool drm_mode_parse_command_line_for_connec= tor(const char *mode_option, > > > > parse_extras =3D true; > > > > } > > > > > > > > - /* First check for a named mode */ > > > > - for (i =3D 0; i < ARRAY_SIZE(drm_named_modes_whitelist); i+= +) { > > > > - ret =3D str_has_prefix(name, drm_named_modes_whitel= ist[i]); > > > > - if (ret =3D=3D mode_end) { > > > > - if (refresh_ptr) > > > > - return false; /* named + refresh is= invalid */ > > > > + if (!mode_end) > > > > + return false; > > > > > > I'm chasing down a change in behaviour between 6.1 and 6.6, and this > > > patch seems to be at least part of the cause. > > > > > > Since [1] we've had the emulated framebuffer on Pi being 16bpp to sav= e > > > memory. All good. > > > > > > It used to be possible to use "video=3DHDMI-A-1:-32" on the kernel > > > command line to set it back to 32bpp. > > > > > > After this patch that is no longer possible. "mode_end =3D bpp_off", = and > > > "bpp_off =3D bpp_ptr - name", so with bpp_ptr =3D name we get mode_en= d > > > being 0. That fails this conditional. > > > drm_mode_parse_cmdline_named_mode already aborts early but with no > > > error if name_end / mode_end is 0, so this "if" clause seems > > > redundant, and is a change in behaviour. > > > > > > We do then get a second parsing failure due to the check if (bpp_ptr > > > || refresh_ptr) at [2]. > > > Prior to this patch my video=3D line would get mode->specified set vi= a > > > "if (ret =3D=3D mode_end)" removed above, as ret =3D mode_end =3D 0. = We > > > therefore didn't evaluate the conditional that now fails. > > > > > > So I guess my question is whether my command line is valid or not, an= d > > > therefore is this a regression? > > > > It's a mess :) > > > > Documentation/fb/modedb.rst defines the video parameter syntax as: > > > > x[M][R][-][@][i][m][eDd] > > > > And thus mandates the x and y resolution. I guess that's what I use as = a > > base, and thus -bpp alone would be invalid. > > > > But then it contradicts itself some time later by documenting that > > video=3DHDMI-1:D is ok. > > > > I guess what you experienced was just an oversight: it was not > > documented anywhere that it was valid, so we didn't really tested it > > either. We should add a unit test for it and fix it. > > Does dropping this "if (!mode_end)" check, and at least the check for > bpp_ptr in the "No mode?" block below it, seem reasonable to you? > > I guess there is also the question of whether a refresh rate without a > mode is valid. That one seems less useful, and all uses of > refresh_specified appear to be after some form of checking xres and > yres. > > I can put a couple of patches together to deal with this if you're > happy with the principle. In looking at this in more detail and writing the unit test, it does become a bit of a mess. drm_connector_get_cmdline_mode calls drm_mode_parse_command_line_for_connector, passing in connector->cmdline_mode as the mode to fill. drm_mode_parse_command_line_for_connector fills in bits of the mode as it goes along, so a failure late in the function leaves bits from the parsing in connector->cmdline_mode. My video=3DHDMI-A-1:-32 does fail later on due to drm_mode_parse_cmdline_options, but as it had set bpp and bpp_specified directly in connector->cmdline_mode I got the behaviour I was desiring. It feels like this should be an all or nothing thing. Allocate a struct drm_cmdline_mode on the stack, and only copy it into connector->cmdline_mode if parsing succeeds. The downside is that you take out some command line entries that used to work (like mine). Thoughts? Dave