From patchwork Mon Aug 14 13:56:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 135472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2787646vqi; Mon, 14 Aug 2023 07:37:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWqa517EvAI2CFK+Ao3JWsjnFqnLELAl90RRji9Al7iAIq2B6W9fqiXQDwbwWGuLkjbYr3 X-Received: by 2002:a17:902:70c6:b0:1bd:a50a:e2d0 with SMTP id l6-20020a17090270c600b001bda50ae2d0mr8989830plt.66.1692023879449; Mon, 14 Aug 2023 07:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692023879; cv=none; d=google.com; s=arc-20160816; b=L61OgUkNcqWOlm6AQtYYzY70RP5LtLTz0KMrHjb5+HGvyQ3jSvbPqahrqCAaSZs55S tV/+DWYcdVjMvAQ3CNpA/Z3fyZg4H1yc0slMOeW0MHoNmZ78q++z0X4p5nUIUhrQ+JDB DYl35iLH5UEyrsrfroRUWSJTohqjCwRtT9Ap0EFAsSG5qxqBAYiSulygjL9YHya7gHOJ /VXVHCRfaPb2Y9xdHfJFj8ksTpaxzafpUMjEY7lFVhsGnzLtFQbIsVrstM/VBDlb/3Sg 0QXGqYudwEMBgGTM2LwdBeM9mUnkqV4CxjgdlaeGkkbHhSOU1VDkYD6EPnGXxGw2WdM/ 9z0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=gNapfuC3AQKxaICeEHqxjOa3S+vK6zNOHb8B483b/O4=; fh=XsS7fCnS6jyV48OHq4AWazZQaFUKJmjcq7fZaQkmGOY=; b=xPiqFZ5y4PvCLG/JpSXLNEr7wi6STWbqIMGkMt7Fx42cYlAwERni8W3CuPSQGZ43aK jBuZKt1dgbm9OFdl0VoWHQxKO0jI7oytLglKOQOh/6fDZGemW+1LPugWHAhT7TpGGxgv /bcgWCOXbuXtWYDsdHG5My4AP9aV1pHr+E3Xb3k9CjlhfduFou8688tJ6ns1GBLKDdfN ZGjo7TTmOBk/D3x17Vfg4BJoYAdjPg1J7MPZtULtjgTZ+eZBladXUR0LsDcDpAQFm7tf yICG+AP5RKsR7g57vpQIrqlS52rmOKP+Rz/FySQyLtn1Km/O4eGplNTTER3xpSuFnoPm 6znQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fog9q62h; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i2-20020a170902c94200b001bdd58f685fsi3386811pla.85.2023.08.14.07.37.44; Mon, 14 Aug 2023 07:37:59 -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=pass header.i=@kernel.org header.s=k20201202 header.b=Fog9q62h; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231801AbjHNN5b (ORCPT + 99 others); Mon, 14 Aug 2023 09:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbjHNN47 (ORCPT ); Mon, 14 Aug 2023 09:56:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20719E6D for ; Mon, 14 Aug 2023 06:56:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A9314617F7 for ; Mon, 14 Aug 2023 13:56:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9043C433C8; Mon, 14 Aug 2023 13:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692021417; bh=nN7A8aX650BJayqTH47PuZ20wjfgMPZ8NkgLMf28J08=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Fog9q62hsfReC7FGCvqSNnMF1whoWFVhYEG9/nafcBXtHi2+RdzOUOvBe1zfcU0eC 5tBO3GLSKjyZTpIJtWn8TD38IloC6/SirAA63RdpxgtX6Bwpu+UnTyEP9rjzxSYuvk 1LllQgoGyDv/HHI67lH1//CEiywsiAcrvnMZM+we8EYhj5hDwZ9CMWr61GGwFXLPH6 f9q6JqcBiY9wVF3wUVGH8bylZFcEKOnFdAWMCS+1dnd/j1qbavn70n62+yD1ILfrhb VTueLBY1PiJbeUfBFU3ZtIXsm7StVNnalgB8FfUAtpFe41hw/Dt2vrJAMlbLxvkjoA rH5BEpshpnNaA== From: Maxime Ripard Date: Mon, 14 Aug 2023 15:56:23 +0200 Subject: [PATCH RFC 11/13] drm/connector: hdmi: Create Infoframe DebugFS entries MIME-Version: 1.0 Message-Id: <20230814-kms-hdmi-connector-state-v1-11-048054df3654@kernel.org> References: <20230814-kms-hdmi-connector-state-v1-0-048054df3654@kernel.org> In-Reply-To: <20230814-kms-hdmi-connector-state-v1-0-048054df3654@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt Cc: Hans Verkuil , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5070; i=mripard@kernel.org; h=from:subject:message-id; bh=nN7A8aX650BJayqTH47PuZ20wjfgMPZ8NkgLMf28J08=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCm3jNp0zn/at0gv6fEib6aQwIP+0xssXsyVaYh8tTVdO sVbyFiso5SFQYyLQVZMkSVG2HxJ3KlZrzvZ+ObBzGFlAhnCwMUpABMRFWFk+P5fdjrHhG0/JZ9O fZhi6ucwaRrPO/cAYRPFMwqXVDVP7mX4nxhdpP10wV7NyPhm5qvxB1kX170PCZe7wPXtglzz3tL bfAA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774215631443549877 X-GMAIL-MSGID: 1774215631443549877 There has been some discussions recently about the infoframes sent by drivers and if they were properly generated. In parallel, there's been some interest in creating an infoframe-decode tool similar to edid-decode. Both would be much easier if we were to expose the infoframes programmed in the hardware. It won't be perfect since we have no guarantee that it's actually what goes through the wire, but it's the best we can do. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_hdmi_connector.c | 124 +++++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 4 ++ 2 files changed, 128 insertions(+) diff --git a/drivers/gpu/drm/drm_hdmi_connector.c b/drivers/gpu/drm/drm_hdmi_connector.c index 46cafb17def7..dcc45b1080f9 100644 --- a/drivers/gpu/drm/drm_hdmi_connector.c +++ b/drivers/gpu/drm/drm_hdmi_connector.c @@ -907,6 +907,130 @@ void drm_atomic_helper_hdmi_connector_print_state(struct drm_printer *p, } EXPORT_SYMBOL(drm_atomic_helper_hdmi_connector_print_state); +struct debugfs_wrapper { + struct drm_hdmi_connector *hdmi_connector; + union hdmi_infoframe *frame; +}; + +static ssize_t +infoframe_read(struct file *filp, char __user *ubuf, size_t count, loff_t *ppos) +{ + const struct debugfs_wrapper *wrapper = filp->private_data; + struct drm_hdmi_connector *hdmi_connector = wrapper->hdmi_connector; + union hdmi_infoframe *frame = wrapper->frame; + u8 buf[HDMI_MAX_INFOFRAME_SIZE]; + ssize_t len; + + len = hdmi_infoframe_pack(frame, buf, sizeof(buf)); + if (len < 0) + return len; + + mutex_lock(&hdmi_connector->infoframes.lock); + len = simple_read_from_buffer(ubuf, count, ppos, buf, len); + mutex_unlock(&hdmi_connector->infoframes.lock); + + return len; +} + +static const struct file_operations infoframe_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = infoframe_read, +}; + +static int create_debugfs_infoframe_file(struct drm_hdmi_connector *hdmi_connector, + struct dentry *parent, + const char *filename, + union hdmi_infoframe *frame) +{ + struct drm_device *dev = hdmi_connector->base.dev; + struct debugfs_wrapper *wrapper; + struct dentry *file; + + wrapper = drmm_kzalloc(dev, sizeof(*wrapper), GFP_KERNEL); + if (!wrapper) + return -ENOMEM; + + wrapper->hdmi_connector = hdmi_connector; + wrapper->frame = frame; + + file = debugfs_create_file(filename, 0400, parent, wrapper, &infoframe_fops); + if (IS_ERR(file)) + return PTR_ERR(file); + + return 0; +} + +#define CREATE_INFOFRAME_FILE(c, p, i) \ + create_debugfs_infoframe_file(c, p, #i, (union hdmi_infoframe *)&(c)->infoframes.i) + +static int create_debugfs_infoframe_files(struct drm_hdmi_connector *hdmi_connector, + struct dentry *parent) +{ + int ret; + + ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, audio); + if (ret) + return ret; + + ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, avi); + if (ret) + return ret; + + ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, drm); + if (ret) + return ret; + + ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, spd); + if (ret) + return ret; + + ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, vendor); + if (ret) + return ret; + + return 0; +} + +#undef CREATE_INFOFRAME_FILE + +static void remove_debugfs_dir(struct drm_device *dev, void *data) +{ + struct dentry *dir = data; + + debugfs_remove_recursive(dir); +} + +/** + * drm_helper_hdmi_connector_debugfs_init - DebugFS init for HDMI connectors + * @connector: Parent Connector + * @dentry: DebugFS root dentry + * + * Provides a default implementation for + * @drm_connector_helper_funcs.debugfs_init that will create all the + * files relevant for a @drm_hdmi_connector. + */ +void drm_helper_hdmi_connector_debugfs_init(struct drm_connector *connector, + struct dentry *root) +{ + struct drm_hdmi_connector *hdmi_connector = + connector_to_hdmi_connector(connector); + struct drm_device *dev = hdmi_connector->base.dev; + struct dentry *dir; + int ret; + + dir = debugfs_create_dir("infoframes", root); + if (IS_ERR(dir)) + return; + + ret = drmm_add_action_or_reset(dev, remove_debugfs_dir, dir); + if (ret) + return; + + create_debugfs_infoframe_files(hdmi_connector, dir); +} +EXPORT_SYMBOL(drm_helper_hdmi_connector_debugfs_init); + /** * drmm_hdmi_connector_init - Init a preallocated HDMI connector * @dev: DRM device diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 21da6f428101..e5faaeb35a9d 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -2294,6 +2294,10 @@ int drmm_hdmi_connector_init(struct drm_device *dev, struct i2c_adapter *ddc, unsigned int max_bpc); +void drm_helper_hdmi_connector_debugfs_init(struct drm_connector *connector, + struct dentry *root); + + /** * struct drm_tile_group - Tile group metadata * @refcount: reference count