Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1388525rdb; Wed, 20 Sep 2023 07:54:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE85bySQPzC3ztvlrbRQa+dRkdBpz4Q8AIy+Us0LtppqAlvrqt+AwLbqO9geUOFJrwhi+Fx X-Received: by 2002:a05:6a20:7da8:b0:134:70b7:2386 with SMTP id v40-20020a056a207da800b0013470b72386mr7073560pzj.9.1695221676345; Wed, 20 Sep 2023 07:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695221676; cv=none; d=google.com; s=arc-20160816; b=XXGwE4GIIIdxI0cfTJtdZy0o6Z/DMOQduNuFc1ycqQTPgPuS/sAUk/lFnhIJ+gq6EW +ZmcWkPOZ+uzZAsz5q+7zS9IuZzA42QymbRj2wQvOkpZk37l6fK65pTE/m+zVj9s7Y0L wvNMCcatPH21QYmsX48OUc9aPqrJt+30ND0EfqFu+LaDI0nmu6xOg+Ag+jG5KuH7if0m slpUsLvJQcmXDqAHmVX4UDRvmUMklJ8tlHmXSnHFMalnnjcgY1T8qkKWHMh7VpIFnuqL 70/x0yd7PbYS+4Q+9Jh5bcc7QnugLMVJReprSN/GaHRrMsHf/oWGaR5ocXPZjjeA1hKE 8eUA== 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=G2PLDMNDUp6+9Cx0oKFbV1U5FfZoO/YziUYPDfpBk6s=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=XPnWwYVhr7UU/rH05qTIyKXpTIGHCB5QDGEgjPE+SLVtX83tBbyIfw9nbs9PGCW8MT h06YfhtB+rFhmIgECaRRxs7XpTNjONcK3wsponyk5eHbVvGgxp5iWFy4Nyw+3JM6iQiu kWVhLB+LtEO5FJOYpvY/RkBLYOwWl82VliV9PX++kdDJwfMlmauwG8+Td+EzoxfW9Bwl j0AgU1fX2pxXSR9nOaq2jU0q88EzCg4jbY6gsyBxs/C8u6K0FS4NGgK+6++/xYNBER96 G3rGGX3SxW9C3Bn7zf3OepsBmd4jTPlrqbFzqThiq8MYJehciiNwcrKggS9VpFqo1HIP qiGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QMBksauG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a5-20020a655c85000000b00565e9c3a308si2951378pgt.788.2023.09.20.07.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 07:54:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QMBksauG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 39D3F827332D; Wed, 20 Sep 2023 07:36:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236791AbjITOgw (ORCPT + 99 others); Wed, 20 Sep 2023 10:36:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236633AbjITOg0 (ORCPT ); Wed, 20 Sep 2023 10:36:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D812EB; Wed, 20 Sep 2023 07:36:17 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6C5CC4339A; Wed, 20 Sep 2023 14:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695220577; bh=BW2baC+EjniG/ZZH9QzIRlNDubJbbQk6ybbnPB50Z5U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QMBksauG5pswKb5xB6CtFYwYj/cC83Oq2vsnPv8kALZhCI10FuNF5SZpcK4o+5VgO q9YLBerNyF4mOPxy9qIWuJngvp6RlmKFQkpviJCdnITZwa8UStAVgcrUmUUSlZacCp Sa2C2VOhysj9NjsuPS4yy1LVShpmUzrhC6E+OBrVPcQEJWLdOD/GttdkMZpJKx4REu QuZ4oS21epq72qPxBepINbE8FBg4I7pYlVsX0RJLjLS/Sgdc8i89dHjwLMsLYkBE3/ 0d5F8jJR8Bsu+TTGYWGoka4sn5IS4RjCrpj6RCs9rXKkxyslwX2z6JFL1SrDvi602N Fj+2L5zbOPfUA== From: Maxime Ripard Date: Wed, 20 Sep 2023 16:35:27 +0200 Subject: [PATCH RFC v2 12/37] drm/connector: hdmi: Create Infoframe DebugFS entries MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230920-kms-hdmi-connector-state-v2-12-17932daddd7d@kernel.org> References: <20230920-kms-hdmi-connector-state-v2-0-17932daddd7d@kernel.org> In-Reply-To: <20230920-kms-hdmi-connector-state-v2-0-17932daddd7d@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=4166; i=mripard@kernel.org; h=from:subject:message-id; bh=BW2baC+EjniG/ZZH9QzIRlNDubJbbQk6ybbnPB50Z5U=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnczJaRkYxeC5/cu/6kZtIa8yim+905h7sbs8JbZ68TW 772kl1dRykLgxgXg6yYIkuMsPmSuFOzXney8c2DmcPKBDKEgYtTACZyrpaRofn+RoszV7+s+B2n 8H2vhHafnbr/kr5ZHA5rNqXcmLrCfh8jw6nixe+rhGdLvVZnva8SxvgyfN6G03kCOXaM08qlijz WsAIA 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 20 Sep 2023 07:36:54 -0700 (PDT) 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 2de43ff3ce0a..3c65b1d3f926 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -538,6 +538,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, drm); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, spd); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, vendor); + 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_minor *minor = connector->dev->primary; @@ -565,6 +673,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); } -- 2.41.0