Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp464983lql; Mon, 11 Mar 2024 07:56:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUaPYljOMZ26bq6j2qot7zIQj8C7D4qaOIb4YGRIU2bTZ1YguKP/ClHPJoj6oDi1SICkhy+C8+M15XM8BwtXRM4lGI7La85dH818gxoMQ== X-Google-Smtp-Source: AGHT+IHsDf/Z8gmnZJtp2ik3T45ECl28NuNa7sZionWsNcTHt1dstuwX3re6XIH6dTw1pm6DX2ee X-Received: by 2002:ac2:4a6a:0:b0:513:1e31:ddec with SMTP id q10-20020ac24a6a000000b005131e31ddecmr4241808lfp.40.1710169003882; Mon, 11 Mar 2024 07:56:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710169003; cv=pass; d=google.com; s=arc-20160816; b=mslkeZx8++9UJMAQDAXKpEFucgXULE1v/Y/qKYLIxo51ZUti/UI+EvIXn64iVOthcc nejgOJ6hq7wuOK9OCfb5sEqKG/NJYH1GOKOT2MEVpXEtTbFTvVxIglwfHtKvWzkdbaL8 VFDdZisWGh3t1VVU4PqHtDVHRhLaJc85B/VV1IgJg5R6RKLS92j4oJpqtYAmZCUtZanO PKjiJM5MfS+XYNHXbb7El5q9ZMMl280MIOtAeztuwJyw+D5eckKky6BixS8zO5rAz4mq xej69bSwFub3jqU+ahd3ZDaT4zyCIVAVao0udDHOBtD7xGjaIZF/Eqk4FvWoJmp89wlm +vKQ== 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=KRA9nBpc28Nv+lscodsIfXViYdqGHnidbI/JMxrU8ZE=; fh=7mnR4/DMo6zaWtUGaVI9DND4TR+QGflpVaaXOChu5h0=; b=LljJvko3otxCNVyKz0IQoaWagSVcK0Kktv1v28uvCZLr+0E1UgfVEeEZBEfJYkGTzK IS24EHJYu4DxA8xYSq+iC+2e466rK/BnmVZBewkrNebNYPJH2YaVMgPGdiwHnBRLqSEl DEuPa63oO9WV2y1iDd1gus42yKgNmDvX2b/gHPUT2TOrVFnxW7ZuvgrLz6Uo6d1Ym699 Tn2VmQT6x6BANr6wYvhMhSXzqzSMB9+vf2mPnWgymN7YPE5jKPxjXkyAaXxygrWfCpK3 RSuh0ApOMa4qKfed2L7JDPBoKbHA4mS847IqM+rq+VKLvlnDvn4BwY/eQwP0PavXoHvJ qeEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S6zY0etK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99020-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 ga26-20020a170906b85a00b00a45bf37e112si2558422ejb.808.2024.03.11.07.56.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 07:56:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99020-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=S6zY0etK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99020-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 70CB11F28465 for ; Mon, 11 Mar 2024 14:56:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 282DD58236; Mon, 11 Mar 2024 14:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S6zY0etK" 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 0EE795820A; Mon, 11 Mar 2024 14:51:03 +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=1710168664; cv=none; b=q3ijsA4NGN9rqWMGR+WN2zEY9zjIugmEBO7XxYgq3wLfmGZM2lEICmabtmKZAj7mdPJsgy4cvek446NJoyFnPyrPc9Ah88rarYb7gvWe4dot6oawOCPgZnr9bgH+Fa/lM2XdPgU2UhL120NdPi1tUUWURAS8Eot4OkHEs4P+mcI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710168664; c=relaxed/simple; bh=8/opTRplB5Ku39o1OEl1lg2hR6YKBkFWnOlEJPXB6sg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HEK6KFFwAFoUm8kG/xRqaYCQMaerh7EBA9wGCCxzVQDLn6/oApXGZVFUvLIXoYsslUvPyZ8qDyoqM/tQLzz7B/ITMPGDXKDSiw9E0/PGIgt90hog3Ja+aaVBkvMD+8s49Zuk6HAgMDvL8XkNDcNb1BL1AMMdCUOmE2Sw6oul4gE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S6zY0etK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44321C433F1; Mon, 11 Mar 2024 14:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710168663; bh=8/opTRplB5Ku39o1OEl1lg2hR6YKBkFWnOlEJPXB6sg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=S6zY0etKtkPf6wHL+91qGftBwWEN1RWDX69XX61l+SduvSeEa8CFbqY8j8xW9+baK vi53OeVv3WDDCCjvOEpoMSQH5mr3iiljUAw2Dm0Xm3UL7Id2F9nbnO2gTN7yCekC+/ wOcRA4wBb4pPamfaKTQx+YI0mgvW3ahtiwFIWoQW+lGo4k39GaPetiThOhLYyvzgZs +Z5nZ1ZYCNKxW3ra8E38Yc0Cgrma08dXFm0NMwANdyacmw7GNyd49QpjfyuTnZ3z4k X2WpqPYFkp1rDIP2SgLhI5UqPeeYv9t4B0xFO9mNjoSoYl/WELIFEAPQcV4uWIAzhI 0RAUiIvNDEXIw== From: Maxime Ripard Date: Mon, 11 Mar 2024 15:49:50 +0100 Subject: [PATCH v9 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: <20240311-kms-hdmi-connector-state-v9-22-d45890323344@kernel.org> References: <20240311-kms-hdmi-connector-state-v9-0-d45890323344@kernel.org> In-Reply-To: <20240311-kms-hdmi-connector-state-v9-0-d45890323344@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=4334; i=mripard@kernel.org; h=from:subject:message-id; bh=8/opTRplB5Ku39o1OEl1lg2hR6YKBkFWnOlEJPXB6sg=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnvpYSEzv/evPRD6+GFc9oZmtcbir38K1DE563mUCt15 Ns5jneXO0pZGMS4GGTFFFlihM2XxJ2a9bqTjW8ezBxWJpAhDFycAjCR44WMDLe/6CmauRYoMSg/ e55cHSy63mzHueuTXey5YnY9nX+nip+R4fAKTyOTyWdWlxx7OrVxZ/OZ7MKAy9d9L1dsYk6JjNP oZwYA 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 | 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 @@ -518,10 +518,118 @@ static const struct file_operations drm_connector_fops = { .llseek = seq_lseek, .release = single_release, .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; struct dentry *root; @@ -545,10 +653,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.43.2