From patchwork Tue Nov 28 10:24:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 170693 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3814229vqx; Tue, 28 Nov 2023 02:27:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHV68D6hON3P6raly6dmwjwNTu0cfvBs27LLGtu5VUXCgbQ/x2cPNgkZnayY2PBnEbbVlf5 X-Received: by 2002:a05:6808:f09:b0:3b2:e51a:a44d with SMTP id m9-20020a0568080f0900b003b2e51aa44dmr20206439oiw.34.1701167248755; Tue, 28 Nov 2023 02:27:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701167248; cv=none; d=google.com; s=arc-20160816; b=bayuOItxT9/yfLCOa5ZH/JPsyMtuIVIZmdLcGxyMoqzu679JpI3vifrIrjf+60P3FR Wqd/RSYZOu3z6BO5l7TP1jiVX7UQtUF2/gO1SXgClKhDKvmec1fTwJBfUAEKQwfk907y sRgtiJB6n231nLwQyb9VDj3cb2Qm/ZmBEI5GduHhAc2fAQZ/7KafS/K5+wpuhvLwKaGX 8VZfW7mUATz2ZKWQYBNgPwR84jYNm74ntt89+XYv0wPKyyIKRGJmK9f3qAhbNhJfX+pr h6XgZlmo7u/UzYPgF8odixjUfuUR9U/2WdCSYaRWtDXFwrIVO/OyUcvn1DI88eRQb+PQ eCkg== 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=rc9xZTzFlY8XvvxKrrD4AWN1rFAiNqPwDEE1EFh9FyI=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=g5jJcxZn91bL1/RFsmfJBQ4kE9rILLpV5Yx7iH4xFBjqVU1ZN2jU5ZZzszFKibODwh kg0xZLQICOUJqRo/o1aKT7Yb5E+mamNwrvh2aQLts8zzzKQBynPnt52/bGol0bqfLRsE af53ewno0ulue7BHvFog+3nBGl/DiLHNdmQWZk9CD7LfzDOyBp4t8xooNGyTERbXxKS0 ZwpMM5hGWwpbl9JRI4EBRuG+r4oNgDSsdDlM1bvuMY0n6IbZqnFJ80d9Bjn9PC5+bfSB xUSmXn+JRJU6is2ZDjVXVgZtzVbQjPOJoGBund+3MzB4uM7NcGlMUecoYGY4lGvUVGh8 6dKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="kS/CCa+M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bg3-20020a056a02010300b0059b79bf220csi12159098pgb.662.2023.11.28.02.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 02:27:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="kS/CCa+M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id D88C48068228; Tue, 28 Nov 2023 02:27:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344413AbjK1K07 (ORCPT + 99 others); Tue, 28 Nov 2023 05:26:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234855AbjK1KZ7 (ORCPT ); Tue, 28 Nov 2023 05:25:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ECE62127 for ; Tue, 28 Nov 2023 02:25:14 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D74F0C43395; Tue, 28 Nov 2023 10:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701167114; bh=OGo7Z7CQrMjDdXBesBvi73JZcvWD//fEJf0VUCHsCAg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kS/CCa+MWKyYrgfkD9/xrxRtC47wMnlHyeoDK7p107NRlNrhA0+H4x3wT+7DtlWWo gnXq/5YgAqHyIdrI+aH6NjLimLZQruhdu+W+lgOTwQCEdih372cDFhpt5zzzLd0cIy kE5pcH4nXSJvqnlcBq4OJfjnYHyMvUicL1lDWMO8PtZsLIlftza0EG4R3JoqkrXFwZ HKM3Y4MPqP9gAVd/AO6DN78qycxnXDdVa2FqZGqqqHrRoms+mnMO7LTzsJM2/15P6+ TiEP2fknfl1Oi+udrv7SDtN3DoMVZLRwhtvRDQIXE1z3jt2kuT62eN9+8HEg6KKxC7 XMz56o2t0mdzQ== From: Maxime Ripard Date: Tue, 28 Nov 2023 11:24:29 +0100 Subject: [PATCH v4 18/45] drm/connector: hdmi: Create Infoframe DebugFS entries MIME-Version: 1.0 Message-Id: <20231128-kms-hdmi-connector-state-v4-18-c7602158306e@kernel.org> References: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@kernel.org> In-Reply-To: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@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=OGo7Z7CQrMjDdXBesBvi73JZcvWD//fEJf0VUCHsCAg=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmp+y9uupzK/65bSK3zsdsj1yz+45MWNWhEfZzLo+rpu 3fTfvGDHaUsDGJcDLJiiiwxwuZL4k7Net3JxjcPZg4rE8gQBi5OAZjITQ9Ght17L/ziYJ3dkL7a /dR5gUvVgaYciot+9fP3mkSlZNnJeTIydBayiTJNZf1c1ValKZTAJBaT/y3l4POYjfPapB+sn67 EBQA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Tue, 28 Nov 2023 02:27:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783803148940077857 X-GMAIL-MSGID: 1783803148940077857 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 f291fb4b359f..59bf4dd0cbd6 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -524,6 +524,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; @@ -551,6 +659,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); }