Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp518686lqh; Tue, 7 May 2024 06:30:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVX8e4ge76NE3PcvMTzoNVmPk8xsnUpdxWwVc5kwD88U3lfDtRlGkfouWe9kcjpZWdQ1TsjbRid4k9AcBrvdx0qCwuv+rU707AjTzwnwg== X-Google-Smtp-Source: AGHT+IFqEr8TokpEeW/pgMB45J52sPc8Yzs8TzYx5zFNhgdhnkCHnaJlW24r9FNP6QGkAkPJ7Om9 X-Received: by 2002:a17:906:5784:b0:a59:a85d:31c6 with SMTP id k4-20020a170906578400b00a59a85d31c6mr5555371ejq.66.1715088604469; Tue, 07 May 2024 06:30:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715088604; cv=pass; d=google.com; s=arc-20160816; b=B1WxUjP4lJ1AEYtaUvJy5q2eQv09xY3EGrv7OTMeXPr6NMDMGMkRZlBC4Fo0LT/8Hr Hqm5GXJdUv/nunFiDhNRcJPnG/QCUdfrfg9SgiowNtgcWxQtxAA/toRQbL2iv3GyLG42 4jtwwNglqIbLG929vrgEkNCS8u4ltQjUlHUp72jY1JKdU4ezjEYN7kmqeYjOKGAHLAx7 vh9Lk45FPhE1RC2/H+zlOyHeb1Fa0UAcyvgLpbE5QafvBvz7XNvSKhpwvUrdW/raXU9A /WFWYiI8bZkpJjOMUrzdP6vg0xH1bcHdpmdC3sKqwXb5BD/DmlUfE0J1UBF6OLlOIGh8 7Jvw== 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=qMeqZFucr64I7Nv6Icr9j1VB2GE5ExGT+XX4u0bQyKc=; fh=cXjl/YXY5UINzzOsrRmPCeOXLg/YFLu10NI0gaKdyKc=; b=TjWZRz1PPTGStZiR/qehnnr4El2YV+3XS09StGk43iSB1TXl9VTMfTTkmXQZofe2n8 44btyEvIp9kNTNKtoK3DOoee5Bb+SwjugHd0PmpEkJApR7ZqUEctOt/Pe9IdsztsZRfG sIGzHAhw0Xaih37e8l1yRUJHsvVP307QCWYX2AWEaTso685wPhJod+OF1vLbVGIjcw10 ZTMAt93yRlg5zoWmEBmDKjt1u9E7uWuEAZCZYcOk9AdXdOz5oasYytj/iExtSGEqHKUU DuhDjbNmLKFsmLL12+aYy5rkLUQeAH3EC87RXK2SQbPV75HEYaICLBJQTPgylShPycJG YzJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GEH8vOgC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171412-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171412-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id sa14-20020a1709076d0e00b00a59b54ab136si3472566ejc.730.2024.05.07.06.30.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 06:30:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171412-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GEH8vOgC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171412-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171412-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0C4F21F228B9 for ; Tue, 7 May 2024 13:30:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2515D180A66; Tue, 7 May 2024 13:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GEH8vOgC" 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 99419173324; Tue, 7 May 2024 13:18:49 +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=1715087929; cv=none; b=jR7heA8M90wAZocvZ0TOkOj94cYr/R0ohRXISTHq5dHsy9bATCSex2MPX/MTIsEmahl7E6Tn0CQKBxKVZ/iBExCFAvOU2OTAn/H/okQrMjjL6mX8sWxKYwGILnragfR2nqsOuHbBd3VHH7OOwRwkLS71iMJD5unZvXXIrOJPmtw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715087929; c=relaxed/simple; bh=jTBz0ob9iuEpIQKBkFz6nD4R8YQTfSw4yt4sHjlZsdU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C00e/7TqoFlqRGvBZ7XzVJw/64HaI6SBRmnKTM5IwvU+9wRTOQIVNykAoLGY0GMOwdFr5AGFyIK1UFE34stqQsZsV9wJe556kDZ4XGQ3lmI8dOFeb3umzyd+ic/sfKRCxoJcI8w3KMlb+6ltcSw7IzXZ5lq9Pnc3AAq+RXbqRS8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GEH8vOgC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5FC8C3277B; Tue, 7 May 2024 13:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715087929; bh=jTBz0ob9iuEpIQKBkFz6nD4R8YQTfSw4yt4sHjlZsdU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GEH8vOgCJLGrWu7Y08Ks/t+Ekqaihqy2odVwrXdL+O3CW93Kpq1SzeYkNtQxynhi/ 6rEmReyPRJT4I1Ec3yibsUZ0/edgi7eFt2D1HlWP/r/7jWu3p0Rl5apHidqcd+qY4t od8NKYLpRbaF3LR5xsKdXYL9bs7jcQ0HvtdVi/VnT+z8+4rmA7pekILmrdhMOal0/J SheWAXYEf0KDcVNC8OcHNGupMZFqDRUhSlm6b9ij8mBOMYkB3zaiU/Q89jFtz4gmOJ o/QUbEHkxzosvFx7t+8gdqww+4AAPpKB2FrLkT/FYHorJ18EeQvp8dGZayIK8sR6wR +/Q7J21nXF3tA== From: Maxime Ripard Date: Tue, 07 May 2024 15:17:41 +0200 Subject: [PATCH v13 23/28] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240507-kms-hdmi-connector-state-v13-23-8fafc5efe8be@kernel.org> References: <20240507-kms-hdmi-connector-state-v13-0-8fafc5efe8be@kernel.org> In-Reply-To: <20240507-kms-hdmi-connector-state-v13-0-8fafc5efe8be@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 , Andy Yan Cc: Hans Verkuil , Sebastian Wick , =?utf-8?q?Ville_Syrj=C3=A4l=C3=A4?= , 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.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5419; i=mripard@kernel.org; h=from:subject:message-id; bh=jTBz0ob9iuEpIQKBkFz6nD4R8YQTfSw4yt4sHjlZsdU=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGlWmh+bM4T/5s+98i7g9LpCac7kpsykF0V3P1aeFZhlw c+wdJdgx1QWBmFOBlkxRZYnMmGnl7cvrnKwX/kDZg4rE8gQBi5OAZiIRStjvXft0VDRBhvmsvCA aIY5z0S75Zzj618cLrvaGjVtpvEUnUMvT351qjn2onBVZMYSPfvPjA0rTi8Lt9w8x/ilvE55QOn ay+GG+/Xb1iftPdBSMSlh1eekxVMdfFsuteVW7Aora7nqvxQA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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 | 152 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 08fcefd804bc..dd39a5b7a711 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -518,10 +518,160 @@ static const struct file_operations drm_connector_fops = { .llseek = seq_lseek, .release = single_release, .write = connector_write }; +#define HDMI_MAX_INFOFRAME_SIZE 29 + +static ssize_t +audio_infoframe_read(struct file *filp, char __user *ubuf, size_t count, loff_t *ppos) +{ + struct drm_connector_hdmi_infoframe *infoframe; + struct drm_connector *connector; + union hdmi_infoframe *frame; + u8 buf[HDMI_INFOFRAME_SIZE(AUDIO)]; + ssize_t len = 0; + + connector = filp->private_data; + mutex_lock(&connector->hdmi.infoframes.lock); + + infoframe = &connector->hdmi.infoframes.audio; + if (!infoframe->set) + goto out; + + frame = &infoframe->data; + 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 audio_infoframe_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = audio_infoframe_read, +}; + +static int create_hdmi_audio_infoframe_file(struct drm_connector *connector, + struct dentry *parent) +{ + struct dentry *file; + + file = debugfs_create_file("audio", 0400, parent, connector, &audio_infoframe_fops); + if (IS_ERR(file)) + return PTR_ERR(file); + + return 0; +} + +#define DEFINE_INFOFRAME_FILE(_f) \ +static ssize_t _f##_read_infoframe(struct file *filp, \ + char __user *ubuf, \ + size_t count, \ + loff_t *ppos) \ +{ \ + struct drm_connector_hdmi_infoframe *infoframe; \ + struct drm_connector_state *conn_state; \ + struct drm_connector *connector; \ + union hdmi_infoframe *frame; \ + struct drm_device *dev; \ + u8 buf[HDMI_MAX_INFOFRAME_SIZE]; \ + ssize_t len = 0; \ + \ + connector = filp->private_data; \ + dev = connector->dev; \ + \ + drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); \ + \ + conn_state = connector->state; \ + infoframe = &conn_state->hdmi.infoframes._f; \ + if (!infoframe->set) \ + goto out; \ + \ + frame = &infoframe->data; \ + len = hdmi_infoframe_pack(frame, buf, sizeof(buf)); \ + if (len < 0) \ + goto out; \ + \ + len = simple_read_from_buffer(ubuf, count, ppos, buf, len); \ + \ +out: \ + drm_modeset_unlock(&dev->mode_config.connection_mutex); \ + return len; \ +} \ +\ +static const struct file_operations _f##_infoframe_fops = { \ + .owner = THIS_MODULE, \ + .open = simple_open, \ + .read = _f##_read_infoframe, \ +}; \ +\ +static int create_hdmi_## _f ## _infoframe_file (struct drm_connector *connector, \ + struct dentry *parent) \ +{ \ + struct dentry *file; \ + \ + file = debugfs_create_file(#_f, 0400, parent, connector, & _f ## _infoframe_fops); \ + if (IS_ERR(file)) \ + return PTR_ERR(file); \ + \ + return 0; \ +} + +DEFINE_INFOFRAME_FILE(avi); +DEFINE_INFOFRAME_FILE(hdmi); +DEFINE_INFOFRAME_FILE(hdr_drm); +DEFINE_INFOFRAME_FILE(spd); + +static int create_hdmi_infoframe_files(struct drm_connector *connector, + struct dentry *parent) +{ + int ret; + + ret = create_hdmi_audio_infoframe_file(connector, parent); + if (ret) + return ret; + + ret = create_hdmi_avi_infoframe_file(connector, parent); + if (ret) + return ret; + + ret = create_hdmi_hdmi_infoframe_file(connector, parent); + if (ret) + return ret; + + ret = create_hdmi_hdr_drm_infoframe_file(connector, parent); + if (ret) + return ret; + + ret = create_hdmi_spd_infoframe_file(connector, parent); + 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; struct dentry *root; @@ -545,10 +695,12 @@ void drm_debugfs_connector_add(struct drm_connector *connector) /* max bpc */ 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); } void drm_debugfs_connector_remove(struct drm_connector *connector) -- 2.45.0