Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp559560lqp; Thu, 21 Mar 2024 08:53:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhx+LDLzq1NcWYBVL0IUTm3GxLLQkuu4g2ARHbbBHlf4TThNQNxrhSGwaG6VZ+4SgpW+0flwi4OELJp33R40IAE0skvqTppTkG6nFSmA== X-Google-Smtp-Source: AGHT+IEslJxiSLHTXNgSsQWjCRhZBKquES5j7RCcffvhrxkfOiXnCZ7KE1/lqW6kZNoZIr8jITHu X-Received: by 2002:a05:6358:6f1d:b0:17b:f109:c7f5 with SMTP id r29-20020a0563586f1d00b0017bf109c7f5mr2678223rwn.23.1711036421115; Thu, 21 Mar 2024 08:53:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711036421; cv=pass; d=google.com; s=arc-20160816; b=GIyssR67d6Y4Se4R0gKzuRF0YRlflbVwJfr7UJGcuOCUJVRAU+5tue8QTezmOGQ5AL ToQFJdn/HL37eZ/oFlP2MLj5bOcE0WvYsNcXaGVU+ghs9CprJg8zSGPZG3gZ2crozPIh 9RBMxvWVG5CJ49IZ9ONT3RqWY2bH3vYmJa1Ovj9F6xQ3SDfySpfp7ZDBAWRba/+6yJk8 YncrGyh3AMi6Njc2HWDlHp5NjSFMivZGcL3eKMuTCuA8dsGbIotI6OvV2aD8neu9paue JKkWV+aUJGF6vgo7yOgbHlvh//kE4JZzCHgKwyL0jwjtuuBPTJ2ytH+qF4XsbJrjl9c2 pz5w== 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=wmBRt1GKGicInBcqkUAERp48+tkz1sI21BBdQ0dgMLs=; fh=7mnR4/DMo6zaWtUGaVI9DND4TR+QGflpVaaXOChu5h0=; b=E13ey8iFtPR2L8z53hjIf7vY+1IkevFOKgsPww0KgL/x4G9WOjxoE0H0B0k3mEB6Am C1WHcW2T1TOULcvXXUOv5uTKyjeM+7QAL2qFOwrhu3SQWv6TNXfr7JSr+nTmpGdTM9yv /LoI0kIyQwE0FmvrtOoYH0ij0FibtWjSzWfgnAIsA+4XLJniP/+1lnMZbC6ZJrFdWJwu AtcUdVgMw9j4laPlns1drNuWTKRkdqpH8MhQWeFhjvk76ncPR7Clkgb54zuWIOT6nh82 GhdoG0QGKc81d3f5+KWMASMatL6KMCED/WV0sPypXJUMfmCqJCY7S4D7U+fjSufLrxhm 7nww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RFyNcgFR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-110244-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j11-20020a65430b000000b005dc85a7bfe6si35547pgq.109.2024.03.21.08.53.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 08:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110244-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RFyNcgFR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-110244-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110244-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 206EFB2147F for ; Thu, 21 Mar 2024 15:36:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C712412BE83; Thu, 21 Mar 2024 15:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RFyNcgFR" 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 AB6A812B16A; Thu, 21 Mar 2024 15:30:29 +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=1711035029; cv=none; b=EtaVp5oogQKSdmh9vJusW3pmCeFIyRk49psDsvhdWTCacJJImI4U3qDlLcd+KiCOasyh5OsIUstXBJJYnKdybk/xf4WFYrzqEZHlK49yeEFR4yUgJ6MpC2BrC4LU89202gNBpM+Fg6YeFB2GiHhKE3sLOnGonAdOGQZbggar2d4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711035029; c=relaxed/simple; bh=yBVGbOn1bf7ryiz3KRf1IjjU0UqAVQczNOu1n0TpvrU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F254WUBDelpgWuZ0tZ8pFVxquO6W78oLqAGYmbU6/kpwTO1kmY4uBcnnMFprjwHEAQ4W6xPWXfsRo+225ujePp2MlPsJigofC2pRQkioHlEPVyoN2+FHZ6JCyZvyrfKP1ZXRmWsYSwuIr5T1IqO6eshRmE96uE45zGzC7eslmNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RFyNcgFR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C780C43390; Thu, 21 Mar 2024 15:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711035029; bh=yBVGbOn1bf7ryiz3KRf1IjjU0UqAVQczNOu1n0TpvrU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RFyNcgFRT/I1JIg2lkSdqik8PjeGe/bte93ip0dilRVCClgIMAA1xD+65MgTOeF3i 52KbGI2zy3B19TwAMB8Wri1xCfzTxxv/0NJOqTTs2ETbI7U6qXxwGHVirRbBzVbf91 jKuomqpXqPXBYwE5FcycAjHiOz+4TgvQYJRraz/COrt1bS5m+RBooOmbs8/ZAySjEe nQfNXcrYyjB3ISzm6HihPJbvMRvqEMe6PSNBhmDvHb0mAuRoQb+b8vORl2DksXXMYR nB4absMU/YamLFaDcdW7lUkJe7/9Z9ePZoQA31FCTZZ5CJh2ykiqL34kys4l/J699l d4CHTEHBSKytw== From: Maxime Ripard Date: Thu, 21 Mar 2024 16:29:18 +0100 Subject: [PATCH v10 22/27] 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: <20240321-kms-hdmi-connector-state-v10-22-e6c178361898@kernel.org> References: <20240321-kms-hdmi-connector-state-v10-0-e6c178361898@kernel.org> In-Reply-To: <20240321-kms-hdmi-connector-state-v10-0-e6c178361898@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?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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5419; i=mripard@kernel.org; h=from:subject:message-id; bh=yBVGbOn1bf7ryiz3KRf1IjjU0UqAVQczNOu1n0TpvrU=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKl/gvz9Y+6eXLVLctrOYOUlt5Ttg6Z28RYvY+oJC7/2/ N2t+MY9HaUsDGJcDLJiiiwxwuZL4k7Net3JxjcPZg4rE8gQBi5OAZhIcgkjQ3e9zDWp7/90VyV4 37F6o2ibujjc8FFko5Sj5zvPedVLbRj+e0Vs38IcULbWoFPq0d7Qgi2vb78WkzoRPfHNwYhpmX+ yOAA= 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.44.0