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: 13483688 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 249EBC10F07 for ; Thu, 7 Dec 2023 17:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l74+6OwkaTH5gNACLrqsgCp2Y6jApryfNh3ynMNi1MY=; b=S6NEQ9PDUn1pj6 +iUDjqnSzUz+GkFIW3xZf7dYwOLVMxRWhbu5HwPd9YZHJTvSh6rY915WdIG67/BlQHwbY/Hw2SyNN v0YngMB283vQNPOr0Uv9ZVKER8S+rilaCv6PuoZuM908sIYB+wzD72Q/TMLlf98/Sd72+GwnVlHsG lIyBEQ401QN+OqeIzFxP+1SDCpDiVjnINiGLW8ItCHQWyjkdFnJDW5VkKhe++BVDBo+lvZBpOc/+q aFx0RCCk63h171/LHIvb/toNdOLnjF+YefB+vO8rUtYJMb9qoc3LZNqJWh5o8f4BE8DAsy9Kj6zSg yiw1NvtkU4i8To2TCFWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBHk6-00DT7U-0D; Thu, 07 Dec 2023 17:00:54 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBGdq-00DGod-1Y; Thu, 07 Dec 2023 15:50:37 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A40FBCE1FC9; Thu, 7 Dec 2023 15:50:20 +0000 (UTC) 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_075022_903126_B0BEAD25 X-CRM114-Status: GOOD ( 15.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); }