Skip to content

Commit 9b62447

Browse files
committed
drm: apple: iomfb: export property dicts in connector debugfs
Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 50cdd33 commit 9b62447

6 files changed

Lines changed: 168 additions & 16 deletions

File tree

drivers/gpu/drm/apple/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CFLAGS_trace.o = -I$(src)
55
appledrm-y := apple_drv.o
66

77
apple_dcp-y := afk.o dcp.o dcp_backlight.o dptxep.o iomfb.o parser.o systemep.o
8+
apple_dcp-y += connector.o
89
apple_dcp-y += ibootep.o
910
apple_dcp-y += iomfb_v12_3.o
1011
apple_dcp-y += iomfb_v13_3.o

drivers/gpu/drm/apple/apple_drv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ static const struct drm_connector_funcs apple_connector_funcs = {
295295
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
296296
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
297297
.detect = apple_connector_detect,
298+
.debugfs_init = apple_connector_debugfs_init,
298299
};
299300

300301
static const struct drm_connector_helper_funcs apple_connector_helper_funcs = {
@@ -343,6 +344,7 @@ static int apple_probe_per_dcp(struct device *dev,
343344
enc->base.possible_crtcs = drm_crtc_mask(&crtc->base);
344345

345346
connector = kzalloc(sizeof(*connector), GFP_KERNEL);
347+
mutex_init(&connector->chunk_lock);
346348
drm_connector_helper_add(&connector->base,
347349
&apple_connector_helper_funcs);
348350

drivers/gpu/drm/apple/connector.c

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// SPDX-License-Identifier: GPL-2.0+ OR MIT
2+
/*
3+
* Copyright (C) The Asahi Linux Contributors
4+
*/
5+
6+
#include <linux/debugfs.h>
7+
#include <linux/module.h>
8+
#include <linux/seq_file.h>
9+
#include <linux/string_helpers.h>
10+
#include <linux/uaccess.h>
11+
12+
#include <drm/drm_managed.h>
13+
14+
#include "connector.h"
15+
#include "dcp-internal.h"
16+
17+
enum dcp_chunk_type {
18+
DCP_CHUNK_COLOR_ELEMENTS,
19+
DCP_CHUNK_TIMING_ELELMENTS,
20+
DCP_CHUNK_DISPLAY_ATTRIBUTES,
21+
DCP_CHUNK_TRANSPORT,
22+
DCP_CHUNK_NUM_TYPES,
23+
};
24+
25+
static int chunk_show(struct seq_file *m,
26+
enum dcp_chunk_type chunk_type)
27+
{
28+
struct apple_connector *apple_con = m->private;
29+
struct dcp_chunks *chunk = NULL;
30+
31+
mutex_lock(&apple_con->chunk_lock);
32+
33+
switch (chunk_type) {
34+
case DCP_CHUNK_COLOR_ELEMENTS:
35+
chunk = &apple_con->color_elements;
36+
break;
37+
case DCP_CHUNK_TIMING_ELELMENTS:
38+
chunk = &apple_con->timing_elements;
39+
break;
40+
case DCP_CHUNK_DISPLAY_ATTRIBUTES:
41+
chunk = &apple_con->display_attributes;
42+
break;
43+
case DCP_CHUNK_TRANSPORT:
44+
chunk = &apple_con->transport;
45+
break;
46+
default:
47+
break;
48+
}
49+
50+
if (chunk)
51+
seq_write(m, chunk->data, chunk->length);
52+
53+
mutex_unlock(&apple_con->chunk_lock);
54+
55+
return 0;
56+
}
57+
58+
#define CONNECTOR_DEBUGFS_ENTRY(name, type) \
59+
static int chunk_ ## name ## _show(struct seq_file *m, void *data) \
60+
{ \
61+
return chunk_show(m, type); \
62+
} \
63+
static int chunk_ ## name ## _open(struct inode *inode, struct file *file) \
64+
{ \
65+
return single_open(file, chunk_ ## name ## _show, inode->i_private); \
66+
} \
67+
static const struct file_operations chunk_ ## name ## _fops = { \
68+
.owner = THIS_MODULE, \
69+
.open = chunk_ ## name ## _open, \
70+
.read = seq_read, \
71+
.llseek = seq_lseek, \
72+
.release = single_release, \
73+
}
74+
75+
CONNECTOR_DEBUGFS_ENTRY(color, DCP_CHUNK_COLOR_ELEMENTS);
76+
CONNECTOR_DEBUGFS_ENTRY(timing, DCP_CHUNK_TIMING_ELELMENTS);
77+
CONNECTOR_DEBUGFS_ENTRY(display_attribs, DCP_CHUNK_DISPLAY_ATTRIBUTES);
78+
CONNECTOR_DEBUGFS_ENTRY(transport, DCP_CHUNK_TRANSPORT);
79+
80+
void apple_connector_debugfs_init(struct drm_connector *connector, struct dentry *root)
81+
{
82+
struct apple_connector *apple_con = to_apple_connector(connector);
83+
84+
debugfs_create_file("ColorElements", 0444, root, apple_con,
85+
&chunk_color_fops);
86+
debugfs_create_file("TimingElements", 0444, root, apple_con,
87+
&chunk_timing_fops);
88+
debugfs_create_file("DisplayAttributes", 0444, root, apple_con,
89+
&chunk_display_attribs_fops);
90+
debugfs_create_file("Transport", 0444, root, apple_con,
91+
&chunk_transport_fops);
92+
}
93+
EXPORT_SYMBOL(apple_connector_debugfs_init);
94+
95+
static void dcp_connector_set_dict(struct apple_connector *connector,
96+
struct dcp_chunks *dict,
97+
struct dcp_chunks *chunks)
98+
{
99+
if (dict->data)
100+
devm_kfree(&connector->dcp->dev, dict->data);
101+
102+
*dict = *chunks;
103+
}
104+
105+
void dcp_connector_update_dict(struct apple_connector *connector, const char *key,
106+
struct dcp_chunks *chunks)
107+
{
108+
mutex_lock(&connector->chunk_lock);
109+
if (!strcmp(key, "ColorElements"))
110+
dcp_connector_set_dict(connector, &connector->color_elements, chunks);
111+
else if (!strcmp(key, "TimingElements"))
112+
dcp_connector_set_dict(connector, &connector->timing_elements, chunks);
113+
else if (!strcmp(key, "DisplayAttributes"))
114+
dcp_connector_set_dict(connector, &connector->display_attributes, chunks);
115+
else if (!strcmp(key, "Transport"))
116+
dcp_connector_set_dict(connector, &connector->transport, chunks);
117+
118+
chunks->data = NULL;
119+
chunks->length = 0;
120+
121+
mutex_unlock(&connector->chunk_lock);
122+
}

drivers/gpu/drm/apple/connector.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: GPL-2.0-only OR MIT
2+
/* "Copyright" 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io> */
3+
4+
#ifndef __APPLE_CONNECTOR_H__
5+
#define __APPLE_CONNECTOR_H__
6+
7+
#include <linux/workqueue.h>
8+
9+
#include <drm/drm_atomic.h>
10+
#include "drm/drm_connector.h"
11+
12+
#include "dcp-internal.h"
13+
14+
void dcp_hotplug(struct work_struct *work);
15+
16+
struct apple_connector {
17+
struct drm_connector base;
18+
bool connected;
19+
20+
struct platform_device *dcp;
21+
22+
/* Workqueue for sending hotplug events to the associated device */
23+
struct work_struct hotplug_wq;
24+
25+
struct mutex chunk_lock;
26+
27+
struct dcp_chunks color_elements;
28+
struct dcp_chunks timing_elements;
29+
struct dcp_chunks display_attributes;
30+
struct dcp_chunks transport;
31+
};
32+
33+
#define to_apple_connector(x) container_of(x, struct apple_connector, base)
34+
35+
void apple_connector_debugfs_init(struct drm_connector *connector, struct dentry *root);
36+
37+
void dcp_connector_update_dict(struct apple_connector *connector, const char *key,
38+
struct dcp_chunks *chunks);
39+
#endif

drivers/gpu/drm/apple/dcp.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <drm/drm_encoder.h>
99
#include <drm/drm_fourcc.h>
1010

11+
#include "connector.h"
1112
#include "dcp-internal.h"
1213
#include "parser.h"
1314

@@ -22,20 +23,6 @@ struct apple_crtc {
2223

2324
#define to_apple_crtc(x) container_of(x, struct apple_crtc, base)
2425

25-
void dcp_hotplug(struct work_struct *work);
26-
27-
struct apple_connector {
28-
struct drm_connector base;
29-
bool connected;
30-
31-
struct platform_device *dcp;
32-
33-
/* Workqueue for sending hotplug events to the associated device */
34-
struct work_struct hotplug_wq;
35-
};
36-
37-
#define to_apple_connector(x) container_of(x, struct apple_connector, base)
38-
3926
struct apple_encoder {
4027
struct drm_encoder base;
4128
};

drivers/gpu/drm/apple/iomfb_template.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,10 @@ static u8 dcpep_cb_prop_end(struct apple_dcp *dcp,
590590
{
591591
u8 resp = dcpep_process_chunks(dcp, req);
592592

593-
/* Reset for the next transfer */
594-
devm_kfree(dcp->dev, dcp->chunks.data);
593+
/* move chunked data to connector to provide it via debugfs */
594+
dcp_connector_update_dict(dcp->connector, req->key, &dcp->chunks);
595595
dcp->chunks.data = NULL;
596+
dcp->chunks.length = 0;
596597

597598
return resp;
598599
}

0 commit comments

Comments
 (0)