Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp2778768rwl; Sat, 5 Nov 2022 11:35:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5PgWZO/EeXZ5p+F6u1w7zoq5iNtkOJPl5XhlcxXI+ujzRl4ojbuZwcqP3/Reat8Gsk9NFx X-Received: by 2002:a17:902:ef89:b0:188:5e9a:c665 with SMTP id iz9-20020a170902ef8900b001885e9ac665mr12101508plb.62.1667673347140; Sat, 05 Nov 2022 11:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667673347; cv=none; d=google.com; s=arc-20160816; b=gJ6DtSCok2Kau4QifCzGcZgLwHwfYQhpRX+1cMRtGSUalVexD9bkxaQySIY5Zv65r9 QafXaFgzbmN+Gotn6gPzzmxPRc2OXxKXzHSlC9WK1zuB7+2SI0aj2MOXSSYeLxf588UG ewH1Uab2yHXq/ogzbrH7CZ83PJbxZ8Fyhqb+TP63wbYnMcRgUTBjEWp99lYz7vnVKGTC Z01V5L7n9uwJpOKeFRcWfjcRYVnPuBxjUSP/kgNU6E/oYiR7aJUDW55ya6dZvAmCuD9z IO40F3nRd3Rc4y4dYqHHMcKIkm9ufGWziwnpR4VktpZSItGWFcx8F9th2TfcYKMZw9D2 937w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=RWDifwBbG878DIYtQ6aTZneSyeLBzoR7LRcwuOd+5Ww=; b=eJ9YHmtedxMvBAGpX48rkEO39gn51d5JSHnpe2C8wAVF2C9sy+SBEXGsCMGIIIxJ/d DAoik5sBTQjKl+57vb5Wt1MClM7AYgk56vuhjzyaFK3Tub3VjpZ6EubWOYdxoNr7cY2F BlaJWGb1E3562DhYsW0vC70lR8JmhvsyFlpOB8jM/YRdX+DtOcE1VJD1wDNaTE1TLoSo 1nTbExH10e4/ZuI53rhhdnojKIZcwoNQiK+2VGZzPbsNvi5yppp2AGWD0u2X8Maa3bqg 9rLDTmwDv42O1CziwJ4k6GYwHUBz466mmDN6GrKfXZGQA7v2W8zB2XwP6O7I5cycLKce WeYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@tronnes.org header.s=ds202112 header.b=FWsFtfq9; 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=fail (p=NONE sp=NONE dis=NONE) header.from=tronnes.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 33-20020a630e61000000b004610dceef13si4347377pgo.336.2022.11.05.11.35.34; Sat, 05 Nov 2022 11:35:47 -0700 (PDT) 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=fail header.i=@tronnes.org header.s=ds202112 header.b=FWsFtfq9; 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=fail (p=NONE sp=NONE dis=NONE) header.from=tronnes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229603AbiKERur (ORCPT + 96 others); Sat, 5 Nov 2022 13:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiKERup (ORCPT ); Sat, 5 Nov 2022 13:50:45 -0400 Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6225DA469 for ; Sat, 5 Nov 2022 10:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org ; s=ds202112; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RWDifwBbG878DIYtQ6aTZneSyeLBzoR7LRcwuOd+5Ww=; b=FWsFtfq9WvhTbfg5xv6opUGWJP TpdfVFbgQbUnOuhkMxKu02lanIGkkuJHwejkyfTvZ9vXmef6GD29nMl00Z5kjteh6g5YHxYR0wJXV RhBcOWn0fsq+qfZB5+SM5gxMXlFWBiAbeHEa9khBdsibTyvX7JDI1lDMJcFIsnQpAYE/IRs2CDWhF Wpuh0IpixW85CIELAnJMKjZ4oe6j72x533EAtzjkeuYRKT74/CKmcO6dU2VI7EBdPFlFgjs+S6nqA ibTXHuv1WPrsHerD7XSZyKfCT/K3Y0rjY7WhCGdsdbJLjTxvSOkzuH9FPE9BNVEhz7NF06MYP3f9F jmmHuJ3Q==; Received: from [2a01:799:95a:cb00:a93e:4a2b:2c13:303] (port=57583) by smtp.domeneshop.no with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1orNJW-0004KI-U5; Sat, 05 Nov 2022 18:50:38 +0100 Message-ID: <0a748a39-a387-5bdb-ffc8-6cc6593b56e7@tronnes.org> Date: Sat, 5 Nov 2022 18:50:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v6 14/23] drm/modes: Properly generate a drm_display_mode from a named mode To: maxime@cerno.tech, 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 , Maxime Ripard , Joonas Lahtinen , Lyude Paul Cc: 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 , =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= References: <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech> <20220728-rpi-analog-tv-properties-v6-14-e7792734108f@cerno.tech> From: =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= In-Reply-To: <20220728-rpi-analog-tv-properties-v6-14-e7792734108f@cerno.tech> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,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 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(). > > The heavy lifting will then be done by the drm_mode_create_from_cmdline_mode() > function. > > 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 mode > we meant. > > Let's modify drm_mode_create_from_cmdline_mode() to properly generate the > drm_display_mode we mean when passing a named mode. > > Signed-off-by: Maxime Ripard > > --- > Changes in v6: > - Fix get_modes to return 0 instead of an error code > - Rename the tests to follow the DRM test naming convention > > 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(-) > > 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(const char *mode_option, > } > EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector); > > +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 = 0; i < ARRAY_SIZE(drm_named_modes); i++) { > + const struct drm_named_mode *named_mode = &drm_named_modes[i]; > + > + if (strcmp(cmd->name, named_mode->name)) > + continue; > + > + if (!named_mode->tv_mode) > + continue; > + > + mode = 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_device *dev, > if (cmd->xres == 0 || cmd->yres == 0) > return NULL; > > - if (cmd->cvt) > + if (strlen(cmd->name)) > + mode = drm_named_mode(dev, cmd); 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. 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. We have this in drm_client_modeset.c:drm_connector_pick_cmdline_mode(): list_for_each_entry(mode, &connector->modes, head) { /* Check (optional) mode name first */ if (!strcmp(mode->name, cmdline_mode->name)) return mode; Here it looks like the named mode thing is a way to choose a mode, not to add one. I couldn't find any documentation on how named modes is supposed to work, have you seen any? Noralf. > + else if (cmd->cvt) > mode = drm_cvt_mode(dev, > cmd->xres, cmd->yres, > cmd->refresh_specified ? cmd->refresh : 60,