diff mbox series

drm/amd/display: Add pixel encoding info to debugfs

Message ID 20240520210817.9943-1-rinoandrejohnsen@gmail.com (mailing list archive)
State New, archived
Headers show
Series drm/amd/display: Add pixel encoding info to debugfs | expand

Commit Message

Rino André Johnsen May 20, 2024, 9:07 p.m. UTC
[Why]
For debugging and testing purposes.

[How]
Create amdgpu_current_pixelencoding debugfs entry.
Usage: cat /sys/kernel/debug/dri/1/crtc-0/amdgpu_current_pixelencoding

Signed-off-by: Rino Andre Johnsen <rinoandrejohnsen@gmail.com>
---
 .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)

Comments

Mario Limonciello May 21, 2024, 1:35 a.m. UTC | #1
On 5/20/2024 16:07, Rino Andre Johnsen wrote:
> [Why]
> For debugging and testing purposes.
> 
> [How]
> Create amdgpu_current_pixelencoding debugfs entry.
> Usage: cat /sys/kernel/debug/dri/1/crtc-0/amdgpu_current_pixelencoding
> 
> Signed-off-by: Rino Andre Johnsen <rinoandrejohnsen@gmail.com>
> ---
>   .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 47 +++++++++++++++++++
>   1 file changed, 47 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
> index 27d5c6077630..d275e5522335 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
> @@ -1160,6 +1160,51 @@ static int amdgpu_current_colorspace_show(struct seq_file *m, void *data)
>   }
>   DEFINE_SHOW_ATTRIBUTE(amdgpu_current_colorspace);
>   
> +/*
> + * Returns the current pixelencoding for the crtc.
> + * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_pixelencoding
> + */
> +static int amdgpu_current_pixelencoding_show(struct seq_file *m, void *data)
> +{
> +	struct drm_crtc *crtc = m->private;
> +	struct drm_device *dev = crtc->dev;
> +	struct dm_crtc_state *dm_crtc_state = NULL;

There is no need to initialize dm_crtc_state to NULL.  You set it before 
its first use.

> +	int res = -ENODEV;
> +
> +	mutex_lock(&dev->mode_config.mutex);
> +	drm_modeset_lock(&crtc->mutex, NULL);
> +	if (crtc->state == NULL)
> +		goto unlock;
> +
> +	dm_crtc_state = to_dm_crtc_state(crtc->state);
> +	if (dm_crtc_state->stream == NULL)
> +		goto unlock;
> +
> +	switch (dm_crtc_state->stream->timing.pixel_encoding) {
> +	case PIXEL_ENCODING_RGB:
> +		seq_puts(m, "RGB");
> +		break;
> +	case PIXEL_ENCODING_YCBCR422:
> +		seq_puts(m, "YCBCR422");
> +		break;
> +	case PIXEL_ENCODING_YCBCR444:
> +		seq_puts(m, "YCBCR444");
> +		break;
> +	case PIXEL_ENCODING_YCBCR420:
> +		seq_puts(m, "YCBCR420");
> +		break;
> +	default:
> +		goto unlock;
> +	}
> +	res = 0;
> +
> +unlock:
> +	drm_modeset_unlock(&crtc->mutex);
> +	mutex_unlock(&dev->mode_config.mutex);
> +
> +	return res;
> +}
> +DEFINE_SHOW_ATTRIBUTE(amdgpu_current_pixelencoding);
>   
>   /*
>    * Example usage:
> @@ -3688,6 +3733,8 @@ void crtc_debugfs_init(struct drm_crtc *crtc)
>   			    crtc, &amdgpu_current_bpc_fops);
>   	debugfs_create_file("amdgpu_current_colorspace", 0644, crtc->debugfs_entry,
>   			    crtc, &amdgpu_current_colorspace_fops);
> +	debugfs_create_file("amdgpu_current_pixelencoding", 0644, crtc->debugfs_entry,
> +			    crtc, &amdgpu_current_pixelencoding_fops);
>   }
>   
>   /*
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
index 27d5c6077630..d275e5522335 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
@@ -1160,6 +1160,51 @@  static int amdgpu_current_colorspace_show(struct seq_file *m, void *data)
 }
 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_colorspace);
 
+/*
+ * Returns the current pixelencoding for the crtc.
+ * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_pixelencoding
+ */
+static int amdgpu_current_pixelencoding_show(struct seq_file *m, void *data)
+{
+	struct drm_crtc *crtc = m->private;
+	struct drm_device *dev = crtc->dev;
+	struct dm_crtc_state *dm_crtc_state = NULL;
+	int res = -ENODEV;
+
+	mutex_lock(&dev->mode_config.mutex);
+	drm_modeset_lock(&crtc->mutex, NULL);
+	if (crtc->state == NULL)
+		goto unlock;
+
+	dm_crtc_state = to_dm_crtc_state(crtc->state);
+	if (dm_crtc_state->stream == NULL)
+		goto unlock;
+
+	switch (dm_crtc_state->stream->timing.pixel_encoding) {
+	case PIXEL_ENCODING_RGB:
+		seq_puts(m, "RGB");
+		break;
+	case PIXEL_ENCODING_YCBCR422:
+		seq_puts(m, "YCBCR422");
+		break;
+	case PIXEL_ENCODING_YCBCR444:
+		seq_puts(m, "YCBCR444");
+		break;
+	case PIXEL_ENCODING_YCBCR420:
+		seq_puts(m, "YCBCR420");
+		break;
+	default:
+		goto unlock;
+	}
+	res = 0;
+
+unlock:
+	drm_modeset_unlock(&crtc->mutex);
+	mutex_unlock(&dev->mode_config.mutex);
+
+	return res;
+}
+DEFINE_SHOW_ATTRIBUTE(amdgpu_current_pixelencoding);
 
 /*
  * Example usage:
@@ -3688,6 +3733,8 @@  void crtc_debugfs_init(struct drm_crtc *crtc)
 			    crtc, &amdgpu_current_bpc_fops);
 	debugfs_create_file("amdgpu_current_colorspace", 0644, crtc->debugfs_entry,
 			    crtc, &amdgpu_current_colorspace_fops);
+	debugfs_create_file("amdgpu_current_pixelencoding", 0644, crtc->debugfs_entry,
+			    crtc, &amdgpu_current_pixelencoding_fops);
 }
 
 /*