From patchwork Thu Dec 7 15:49:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 175246 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4876256vqy; Thu, 7 Dec 2023 07:53:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEAm01RnKLH5uDXhuUAf4AGh0RwfWpGw7h3Xp/h/vWZXzbZ9WRf7rD8TGFzsdD51ubOOOk X-Received: by 2002:a17:90a:e614:b0:286:d1e2:5044 with SMTP id j20-20020a17090ae61400b00286d1e25044mr2517384pjy.9.1701964408050; Thu, 07 Dec 2023 07:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701964408; cv=none; d=google.com; s=arc-20160816; b=hOUmeRPxUyrlfaBYs0n3equgyE/IFx2NvYwNXlLvkiM/2t73zZr26JCKNKoCOrzogZ oWDO0CE1vh8yDVTyNqi2L2nimKevmFxgOImYosc5PqF5bmXm5zdSjYu0m2gNSP8Ns6XC pVoaVu9Cb12U++7oW4plLF9g7cMbBm0oOHJW6J7b77Ub4DDEOf4vmQJqnCDxaeSC09KX lGGDnRODKvCtsmKtiVL62AvQNLj4WAWICncFrAuhIu9jp33s8xEzmZMUVa+FvFllaMi1 pS5lCzd2ifRuC6GBrEThU+I/HqsZY7rqxCcXDOczcHBeTaSi+XnmDBOjAhBa/GPpDVie sl/Q== 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=O/bDHzGELXb/wliPFovzIXpTpux4AD/JZX8weeyzJhk=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=gwQS/Cjv/whFyGHmHTxiBVOIk5omqjSRWXEBNkXvxnRWQK59InCSiMU2VQcYOFql42 0oFVZZkBvAC4zJKnqZ3nLQ05kr7ldCbJUywH5S4ft3RTFIliGBQ6PYWXt6gn+5eukcNT kkg21zbIuPw4inY6OtKZ5y2UQ+8+0JVzDbUeRjfwoN4kq5gC1WTcMQpgMNa/6ZpJdqXs vzg+97JT/1QE6ZiNs1yTQGOGqpf4dcuuJ4IBIXsZV8IZZbC64Ous5myku5VXlKlbhRbP t6TcDuDopr9ayPEprDPGp1/FcLDfzBdWq2WPdFK+T+1J35Utq+92+y4FPD2pD9+2ucuT XRJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ubO4jnhh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id mn24-20020a17090b189800b00286b29bb241si1318429pjb.7.2023.12.07.07.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 07:53:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ubO4jnhh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 025F5826FAA0; Thu, 7 Dec 2023 07:53:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443803AbjLGPxC (ORCPT + 99 others); Thu, 7 Dec 2023 10:53:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443805AbjLGPwd (ORCPT ); Thu, 7 Dec 2023 10:52:33 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD42E19A5 for ; Thu, 7 Dec 2023 07:50:20 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA422C43395; Thu, 7 Dec 2023 15:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701964220; bh=AP/yR0nm23hUUYu4DfkWen6y8gWPLPwthFIRl4vtop8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ubO4jnhht4RrZoAfE/rzpoPdd94AzGO5tEnzAgksjvD6ynUAb6I0hBhDXu/1hBZn5 5EG2L7q/maJwr8mTeh/+gmVPTlI4OOknOerOW71QeC3yQlash+jexxKFZ0U8FDaxEn AC9QUw6fAlJ+svPtH9UjIG+zY+bkORxIKssT0SC/TvgTDV2seHRUKrafNntP7pVPay 6jscGN3eclHo/+AbwD5bXtcEDtKHk7/WQ/E+dMR2B3UQSJ/MGX2bxL34P3qvtXTEgT v3sN8XYMqbw3CBt0vAWc/r7nNfy0X3m+e+h3ZsgMxCx1PM6gEF/DLGWex6u3+utRLm 36gkbq9GojoiA== From: Maxime Ripard Date: Thu, 07 Dec 2023 16:49:40 +0100 Subject: [PATCH v5 17/44] drm/connector: hdmi: Create Infoframe DebugFS entries MIME-Version: 1.0 Message-Id: <20231207-kms-hdmi-connector-state-v5-17-6538e19d634d@kernel.org> References: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@kernel.org> In-Reply-To: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4158; i=mripard@kernel.org; h=from:subject:message-id; bh=AP/yR0nm23hUUYu4DfkWen6y8gWPLPwthFIRl4vtop8=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmFL1uZ63MsX6Qb7FJo8Ha2c5qkclGk/lecsN8e46057 85MnpHfUcrCIMbFICumyBIjbL4k7tSs151sfPNg5rAygQxh4OIUgIlMu8fwV8Y1vvetfPK22W2+ gZZdGue17E20xZb82b4kd62ZzN1nNxj+F3yYm+dtteaU+OPpSjZ/5BQ020RX1y01lUj5mBTr/Se QBQA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 07 Dec 2023 07:53:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784639031073667040 X-GMAIL-MSGID: 1784639031073667040 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_debugfs.c | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 02e7481758c0..dab54f14d313 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -522,6 +522,114 @@ static const struct file_operations drm_connector_fops = { .write = connector_write }; +struct debugfs_wrapper { + struct drm_connector *connector; + struct drm_connector_hdmi_infoframe *frame; +}; + +#define HDMI_MAX_INFOFRAME_SIZE 29 + +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_connector *connector = wrapper->connector; + struct drm_connector_hdmi_infoframe *infoframe = wrapper->frame; + union hdmi_infoframe *frame = &infoframe->data; + u8 buf[HDMI_MAX_INFOFRAME_SIZE]; + ssize_t len = 0; + + mutex_lock(&connector->hdmi.infoframes.lock); + + if (!infoframe->set) + goto out; + + len = hdmi_infoframe_pack(frame, buf, sizeof(buf)); + if (len < 0) + goto out; + + len = simple_read_from_buffer(ubuf, count, ppos, buf, len); + +out: + mutex_unlock(&connector->hdmi.infoframes.lock); + return len; +} + +static const struct file_operations infoframe_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = infoframe_read, +}; + +static int create_hdmi_infoframe_file(struct drm_connector *connector, + struct dentry *parent, + const char *filename, + struct drm_connector_hdmi_infoframe *frame) +{ + struct drm_device *dev = connector->dev; + struct debugfs_wrapper *wrapper; + struct dentry *file; + + wrapper = drmm_kzalloc(dev, sizeof(*wrapper), GFP_KERNEL); + if (!wrapper) + return -ENOMEM; + + wrapper->connector = 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_HDMI_INFOFRAME_FILE(c, p, i) \ + create_hdmi_infoframe_file(c, p, #i, &(c)->hdmi.infoframes.i) + +static int create_hdmi_infoframe_files(struct drm_connector *connector, + struct dentry *parent) +{ + int ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, audio); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, avi); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, hdr_drm); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, spd); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, hdmi); + if (ret) + return ret; + + return 0; +} + +static void hdmi_debugfs_add(struct drm_connector *connector) +{ + struct dentry *dir; + + if (!(connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || + connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) + return; + + dir = debugfs_create_dir("infoframes", connector->debugfs_entry); + if (IS_ERR(dir)) + return; + + create_hdmi_infoframe_files(connector, dir); +} + void drm_debugfs_connector_add(struct drm_connector *connector) { struct drm_device *dev = connector->dev; @@ -549,6 +657,8 @@ void drm_debugfs_connector_add(struct drm_connector *connector) debugfs_create_file("output_bpc", 0444, root, connector, &output_bpc_fops); + hdmi_debugfs_add(connector); + if (connector->funcs->debugfs_init) connector->funcs->debugfs_init(connector, root); }