Skip to content

Commit

Permalink
drm/connector: hdmi: Create Infoframe DebugFS entries
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240527-kms-hdmi-connector-state-v15-24-c5af16c3aae2@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>
  • Loading branch information
Maxime Ripard committed May 28, 2024
1 parent 4fa04f4 commit c602e49
Showing 1 changed file with 152 additions and 0 deletions.
152 changes: 152 additions & 0 deletions drivers/gpu/drm/drm_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,156 @@ static const struct file_operations drm_connector_fops = {
.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;
Expand Down Expand Up @@ -547,6 +697,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);
}
Expand Down

0 comments on commit c602e49

Please sign in to comment.