From patchwork Thu Feb 22 18:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 204972 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp129393dyb; Thu, 22 Feb 2024 10:28:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUD7Rfhcz3XyeOSBX6pC6cKDH2zqzgMGuPRKWIvgDCbUirZ60e+kYvjPVPv2z7wZ/VD+N+PacKRUSWAyjzn6crMj06+zQ== X-Google-Smtp-Source: AGHT+IHPk+iifXcQce6oNYxWSvZkMlFo6GatIyLrU48UfaVp31cZGA7FoQ7tTYH3Bbfb0+247VOt X-Received: by 2002:a67:f54a:0:b0:470:394e:a9da with SMTP id z10-20020a67f54a000000b00470394ea9damr15266704vsn.1.1708626530732; Thu, 22 Feb 2024 10:28:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626530; cv=pass; d=google.com; s=arc-20160816; b=shqsC4FtmjqsxZyksfmIE2AqOYLhZ9Y+cmfWpRZxoQFTigFsDcbaWJBpUo9+gn680B 74KrsKhYgd1NlQKJ8FTTTv04Acda7JBRpxrC47Us+YFdZmasOpap1vXsIaDDCNbicOoB YDcoUe/7lqaR27VCOFARoORU4qnbVwvVXHhelRUQswgISzkSEOrsOh/aJ1/eJIxKcG13 yNQJdA+motUAD0olb8YVdQvOzfcUtKkk/ACnqEfnCQ901H1egLPdlzfj33Cm0tU5Rl22 sbzgv0gV9990PNvpVd0mNJxC8cKDkd8i9m7KYkSc/tSVasKE47BppUk8ll9t0ExU7khh 2Clw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=Cf09Iq4HiZ3EOyznZSUk/exgMTxGJiIsCE+GxsVCLEU=; fh=7mnR4/DMo6zaWtUGaVI9DND4TR+QGflpVaaXOChu5h0=; b=BSZhYxSOU8gfSetfkVVGsUUrO3sAENOdekqtZa544rsO8sNWapXAD8uc6Sn0c/LBNv Jro1Qf2qbFtB23FC2hXMSuBLMRRlCm2YgqMLtcfzxQy37T2GgPT2NhYUmu0gN/5demcr pkJfErGU71peLsT6NmmiObJlf5Qkk8L8JkFXS57qHvzTu10GNaW7GScGy9J5SstR/HrS JT2dLgP8SpbUDHigd/8NEuoPk/+/fb3nC7Nk4tWMJKTGhU5Pspn2q8VbzGjKvXUoL/j9 TUvwYQe2ISaiNKanYEUXNcO/Zv7kFtgaG6VAY8DLwOnli+VydoyicaRlleXPV062yDWN qBSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ar769At6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77106-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bu12-20020a056102524c00b00470575ec043si1419247vsb.552.2024.02.22.10.28.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:28:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ar769At6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77106-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 72ED71C2265B for ; Thu, 22 Feb 2024 18:28:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 463CE1493AF; Thu, 22 Feb 2024 18:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ar769At6" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DE98143C7A; Thu, 22 Feb 2024 18:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625744; cv=none; b=Wssel2ml61TvhhSWq5SYvtfcAZP/HlUAyUhgpyR2IxaP/PHbuPJfpqI/TPJ5u+/4zWykFdy9jQivn0FtUE2NoilXZODjbgKH/l/NrcsPIEgAOTxoIy4Oy2/NQBkamjXlfrd3yJKGyqLXaTYQBYga+Eo5Vz4CqdD6+K1HCFCEoK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625744; c=relaxed/simple; bh=17MI7dQ+HBQcuA6TivP0AEo+xZ/MsQzhUdSykOh5KZ8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L/xsU72jXqd0GyE1+I2vHm4/tKUltLpiKe1i8y8TM8hXMLVlzrUf+ZwzcU3KB4OtmWft24BmTcldorGCHxSGa3MYTtMBNxDV5nzizmbJmi9SfGJy6AW3OFj4Xp7iEFKYwvk0ZJTWDg6hfcMCUmcnIhcOW4NAXr/rfF43EmoNr7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ar769At6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC992C433C7; Thu, 22 Feb 2024 18:15:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708625744; bh=17MI7dQ+HBQcuA6TivP0AEo+xZ/MsQzhUdSykOh5KZ8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ar769At6wc/cUyEx3NLI78/IZ+lvnKjMdfYHO32ToD2YhPbI69AuSCFCaBHLRGiC2 J9DMIbirDcyMLjidUpzMTl+tulYhHyALWgig3imTvPAVtCEEynUQtbfnJGOm6iiHYq FyIvLZb/suBrqlGfgK1EQkZx4IGnNPev6WxWKBQr9veW5KL+kv10vG6QgDL9yO1WHA arqcINQoq9xeNTwFc8OrO72Wr0MXMXO9ROk7NffpP0AhJchhsMBEHT3u3BH19xiF0w zx96UiRWdXNgj09hQcyy5jMhXwts/sfW4hcGxQAo9Rwd33l10lDh+xL4lyD/g5FaWf wJjPDwDZq6luA== From: Maxime Ripard Date: Thu, 22 Feb 2024 19:14:13 +0100 Subject: [PATCH v7 27/36] drm/connector: hdmi: Create Infoframe DebugFS entries Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240222-kms-hdmi-connector-state-v7-27-8f4af575fce2@kernel.org> References: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> In-Reply-To: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , Sebastian Wick , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , 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=17MI7dQ+HBQcuA6TivP0AEo+xZ/MsQzhUdSykOh5KZ8=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnX+36xFpzweVVlbvQnKCrJdqr7Qo7UO2mfH4u9/tolY PuIoSyho5SFQYyLQVZMkSVG2HxJ3KlZrzvZ+ObBzGFlAhnCwMUpABO5lcrwzzbFs3nSo2iJSafM j5x8ov6+I1md9U/z/huqf/iLZjst9WJkmHcq3stBL/GmbOkWs4vCrDEzdhjMjVzB/dz33swZ5w6 cYAIA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791624773091852864 X-GMAIL-MSGID: 1791624773091852864 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 08fcefd804bc..160389f3d84b 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -520,6 +520,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; @@ -547,6 +655,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); }