|
| 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 | +} |
0 commit comments