Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1826170rwb; Mon, 7 Nov 2022 06:17:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM5N5sLQIdalhoDbjjcOI5oUFNk2kBvAvdskQKpypcXD1UuZymzyiaMmZalTYfq/FI/J5KjE X-Received: by 2002:aa7:df08:0:b0:461:d9a2:b247 with SMTP id c8-20020aa7df08000000b00461d9a2b247mr50893560edy.54.1667830659518; Mon, 07 Nov 2022 06:17:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830659; cv=none; d=google.com; s=arc-20160816; b=Cb/7Q7HmFm8+1CDUDb9X0BegWNY2jopJpby0PV8fsf8J5ML09/YTWCdosLsyEH4QWz JIaS6bqEA9zebbYNtU/6pjL6LhV59p2aMyetZ53aXynUNcXPwdtqInZkPZMos+KIQVWc ehYKUgkwgFfuRi/LX+PH8xnLiXwz5iC/Q53t8nlFVSAGiRGmjY6zajFA/PkET5g6mFRS 5BArRwrxHRnPkfX8bOQUHqcvdtt/fm4WNH2uSIHPefsz3A7nTf5Pc4dTCs/JOvFLSxmr YRLczLIJsJ6SW6SLkZbwrB2+4/Ga+QpEAMz33ljzGJaEtCy546fNp8YPfHiaIGOSrMTG /1Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=euMdwanfMkOYDEpc4wB0uixBbNEYF5sJFd9/UJyNdCY=; b=PT+L0JUYE5wYP23C2QY5+Xc6tJgqRryecs8SInNkq8Wc27TrBI5njBlcyBlFO4bLaE WIpi4siGRZCf0px7CFvTGrHP2jBzwivl5awTonqL2tvr1sruGWsZ6oUTFLDsboMoOvU7 0Ki8F7TD2aEj+muzbazsuhH40bm02hc0mTAljBOYOu6NO23DbuMuZpi+WaySfA61+WF9 5fH82g6h395Luc3CZzRGysIJdb8pGJs4V7uLvcOOP3b5nNX6w0dmfQdewEw90OzcT7/A uw8xRZi/UInLnAv+6EvPzwhmX5QHeAZgXp3W0WmL7ltcufA+z339x4MNfCRDZu6RGgIS RbtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b="bkw76/u5"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="kid7A/lF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn21-20020a05640222f500b00463153e5b14si8814152edb.517.2022.11.07.06.17.16; Mon, 07 Nov 2022 06:17:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b="bkw76/u5"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="kid7A/lF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbiKGNei (ORCPT + 93 others); Mon, 7 Nov 2022 08:34:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbiKGNed (ORCPT ); Mon, 7 Nov 2022 08:34:33 -0500 Received: from wnew2-smtp.messagingengine.com (wnew2-smtp.messagingengine.com [64.147.123.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D873B15813 for ; Mon, 7 Nov 2022 05:34:32 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailnew.west.internal (Postfix) with ESMTP id 2E60E2B06702; Mon, 7 Nov 2022 08:34:27 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 07 Nov 2022 08:34:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1667828066; x=1667835266; bh=euMdwanfMk OYDEpc4wB0uixBbNEYF5sJFd9/UJyNdCY=; b=bkw76/u5ZYZbQahAvsPYoo8IQG LcHGuGHIXi8HCjhw4OYcAWT30Ol0Wn+jYP1l44qbVRmgLwmDnhosZ3uA6uNjhQjL ioJEgtTKYzh1M+2NZq1JoCcj1onDGF0TH5WP7U+0cjtS0kzx+hvVlia8GUf72U0x RvMmk31Q77Uivz75wkgFhyZZj7ohYiKbQZ2hREYhZrAck2nWG1zN5Ru1+EVS5g97 LxqEj6CfzUGm3f65dYFQx/JwcNnpdTNQpi+AWw7niXI7QyVGf6ZY38U7zb6EHj4G GBx5vTA5xL45elayXVZ1ZMvRHECSvQwahmDrw23tM/fPWMNrMQsB2AzMrs4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1667828066; x=1667835266; bh=euMdwanfMkOYDEpc4wB0uixBbNEY F5sJFd9/UJyNdCY=; b=kid7A/lFEMRYdSlRHUAbP10h3b5B6GqzIFwJ7s6gbB0t WpjUg1oMTN9uu/L46ufdrj+GmDdd9IqH4CvLqUeljmmEBdP+YJhMQVxPUCS2BnpI v4Ru9CamYJCnCPTr3hMquRyY/NJTD+xAHKkQ2W2WFuBatXgmHRCkSTLKmFSd75/2 k01ShiWOfm0j3nYPSCuBrawztOfFU2j0A7YozMiucrP1nq/04sJkP45VwqUc5QZW ukdMDjH1cPbLpZpr2mHDntcosTrtF9zvvVRlx/Jj+JmdokRLh6qtGk+yhakRF9C7 8zrz3V0g8NseHrHsKPA6rjSIGYDr71WT7ky/u694rw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrvdekgdehfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddunecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepieehffffvefgiedthfeiieeutdfgffekhfehgfehgfeiuddutdfftdekffeh heevnecuffhomhgrihhnpegsohhothhlihhnrdgtohhmnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvggt hh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 7 Nov 2022 08:34:25 -0500 (EST) Date: Mon, 7 Nov 2022 14:34:23 +0100 From: Maxime Ripard To: Noralf =?utf-8?Q?Tr=C3=B8nnes?= Cc: Karol Herbst , Emma Anholt , Ben Skeggs , Chen-Yu Tsai , Rodrigo Vivi , Maarten Lankhorst , Jani Nikula , Daniel Vetter , Thomas Zimmermann , Tvrtko Ursulin , Samuel Holland , Jernej Skrabec , David Airlie , Joonas Lahtinen , Lyude Paul , linux-sunxi@lists.linux.dev, intel-gfx@lists.freedesktop.org, Phil Elwell , linux-arm-kernel@lists.infradead.org, nouveau@lists.freedesktop.org, Hans de Goede , Dom Cobley , Mateusz Kwiatkowski , dri-devel@lists.freedesktop.org, Dave Stevenson , linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: Re: [PATCH v6 14/23] drm/modes: Properly generate a drm_display_mode from a named mode Message-ID: <20221107133423.o344y4cb5zxpyrm4@houat> References: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech> <20220728-rpi-analog-tv-properties-v6-14-e7792734108f@cerno.tech> <0a748a39-a387-5bdb-ffc8-6cc6593b56e7@tronnes.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="skctp4fj6rxepcpb" Content-Disposition: inline In-Reply-To: <0a748a39-a387-5bdb-ffc8-6cc6593b56e7@tronnes.org> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --skctp4fj6rxepcpb Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 05, 2022 at 06:50:30PM +0100, Noralf Tr=F8nnes wrote: > Den 26.10.2022 17.33, skrev maxime@cerno.tech: > > The framework will get the drm_display_mode from the drm_cmdline_mode it > > got by parsing the video command line argument by calling > > drm_connector_pick_cmdline_mode(). > >=20 > > The heavy lifting will then be done by the drm_mode_create_from_cmdline= _mode() > > function. > >=20 > > In the case of the named modes though, there's no real code to make that > > translation and we rely on the drivers to guess which actual display mo= de > > we meant. > >=20 > > Let's modify drm_mode_create_from_cmdline_mode() to properly generate t= he > > drm_display_mode we mean when passing a named mode. > >=20 > > Signed-off-by: Maxime Ripard > >=20 > > --- > > Changes in v6: > > - Fix get_modes to return 0 instead of an error code > > - Rename the tests to follow the DRM test naming convention > >=20 > > Changes in v5: > > - Switched to KUNIT_ASSERT_NOT_NULL > > --- > > drivers/gpu/drm/drm_modes.c | 34 ++++++++++- > > drivers/gpu/drm/tests/drm_client_modeset_test.c | 77 +++++++++++++++++= +++++++- > > 2 files changed, 109 insertions(+), 2 deletions(-) > >=20 > > diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c > > index dc037f7ceb37..85aa9898c229 100644 > > --- a/drivers/gpu/drm/drm_modes.c > > +++ b/drivers/gpu/drm/drm_modes.c > > @@ -2497,6 +2497,36 @@ bool drm_mode_parse_command_line_for_connector(c= onst char *mode_option, > > } > > EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector); > > =20 > > +static struct drm_display_mode *drm_named_mode(struct drm_device *dev, > > + struct drm_cmdline_mode *cmd) > > +{ > > + struct drm_display_mode *mode; > > + unsigned int i; > > + > > + for (i =3D 0; i < ARRAY_SIZE(drm_named_modes); i++) { > > + const struct drm_named_mode *named_mode =3D &drm_named_modes[i]; > > + > > + if (strcmp(cmd->name, named_mode->name)) > > + continue; > > + > > + if (!named_mode->tv_mode) > > + continue; > > + > > + mode =3D drm_analog_tv_mode(dev, > > + named_mode->tv_mode, > > + named_mode->pixel_clock_khz * 1000, > > + named_mode->xres, > > + named_mode->yres, > > + named_mode->flags & DRM_MODE_FLAG_INTERLACE); > > + if (!mode) > > + return NULL; > > + > > + return mode; > > + } > > + > > + return NULL; > > +} > > + > > /** > > * drm_mode_create_from_cmdline_mode - convert a command line modeline= into a DRM display mode > > * @dev: DRM device to create the new mode for > > @@ -2514,7 +2544,9 @@ drm_mode_create_from_cmdline_mode(struct drm_devi= ce *dev, > > if (cmd->xres =3D=3D 0 || cmd->yres =3D=3D 0) > > return NULL; > > =20 > > - if (cmd->cvt) > > + if (strlen(cmd->name)) > > + mode =3D drm_named_mode(dev, cmd); >=20 > I'm trying to track how this generated mode fits into to it all and > AFAICS if the connector already supports a mode with the same xres/yres > as the named mode, the named mode will never be created because of the > check at the beginning of drm_helper_probe_add_cmdline_mode(). It will > just mark the existing mode with USERDEF and return. Yep, you're right > If the connector doesn't already support a mode with such a resolution > it will be created, but should we do that? If the driver supported such > a mode it would certainly already have added it to the mode list, > wouldn't it? After all it's just 2 variants NTSC and PAL. I wasn't so sure about this part. I think it's still benefitial because some users (Geert at least has expressed that need) might want a smaller mode than 480i/576i, whereas the driver is realistically only going to register those two. So creating that mode if it isn't declared seems to have value to some. > We have this in drm_client_modeset.c:drm_connector_pick_cmdline_mode(): >=20 > list_for_each_entry(mode, &connector->modes, head) { > /* Check (optional) mode name first */ > if (!strcmp(mode->name, cmdline_mode->name)) > return mode; >=20 > Here it looks like the named mode thing is a way to choose a mode, not > to add one. >=20 > I couldn't find any documentation on how named modes is supposed to > work, have you seen any? Eh, I guess I'm to blame for that :) Named modes are really only about the command-line name. The way it was initially introduced was pretty much to only pass down the name to drivers for them to figure it out, like we've been doing in sun4i: https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/sun4i/sun4i_= tv.c#L292 It wasn't really working, especially because the userspace pretty much ignores it. One of the point of this series is to create a proper mode (and state, really) from the name passed on the command line so that drivers don't have to behave any different from usual, and userspace can be involved there too. Maxime --skctp4fj6rxepcpb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCY2kJXwAKCRDj7w1vZxhR xXK+AQDbZjS2J5WC2ceGRjMPlRP+aZSBzWDC5fwiCGIaR3oGigEA5D4seApvXZv1 QLznHu/XaZfYUQXUOM6K43F6nknfDQI= =HyxE -----END PGP SIGNATURE----- --skctp4fj6rxepcpb--