Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Add API for capturing frame CRCs

Adds files and directories to debugfs for controlling and reading frame
CRCs, per CRTC:

dri/0/crtc-0/crc
dri/0/crtc-0/crc/control
dri/0/crtc-0/crc/data

Drivers can implement the set_crc_source callback() in drm_crtc_funcs to
start and stop generating frame CRCs and can add entries to the output
by calling drm_crtc_add_crc_entry.

v2:
- Lots of good fixes suggested by Thierry.
- Added documentation.
- Changed the debugfs layout.
- Moved to allocate the entries circular queue once when frame
generation gets enabled for the first time.
v3:
- Use the control file just to select the source, and start and stop
capture when the data file is opened and closed, respectively.
- Make variable the number of CRC values per entry, per source.
- Allocate entries queue each time we start capturing as now there
isn't a fixed number of CRC values per entry.
- Store the frame counter in the data file as a 8-digit hex number.
- For sources that cannot provide useful frame numbers, place
XXXXXXXX in the frame field.

v4:
- Build only if CONFIG_DEBUG_FS is enabled.
- Use memdup_user_nul.
- Consolidate calculation of the size of an entry in a helper.
- Add 0x prefix to hex numbers in the data file.
- Remove unnecessary snprintf and strlen usage in read callback.

v5:
- Made the crcs array in drm_crtc_crc_entry fixed-size
- Lots of other smaller improvements suggested by Emil Velikov

v7:
- Move definition of drm_debugfs_crtc_crc_add to drm_internal.h

v8:
- Call debugfs_remove_recursive when we fail to create the minor
device

v9:
- Register the debugfs directory for a crtc from
drm_crtc_register_all()

v10:
- Don't let debugfs failures interrupt CRTC registration (Emil
Velikov)

v11:
- Remove extra brace that broke compilation. Sorry!

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Acked-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1475767268-14379-3-git-send-email-tomeu.vizoso@collabora.com

authored by

Tomeu Vizoso and committed by
Daniel Vetter
9edbf1fa 865afb11

+555 -3
+6
Documentation/gpu/drm-uapi.rst
··· 216 216 userspace are driver specific for efficiency and other reasons these 217 217 interfaces can be rather substantial. Hence every driver has its own 218 218 chapter. 219 + 220 + Testing and validation 221 + ====================== 222 + 223 + .. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c 224 + :doc: CRC ABI
+2 -1
drivers/gpu/drm/Makefile
··· 9 9 drm_scatter.o drm_pci.o \ 10 10 drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \ 11 11 drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \ 12 - drm_info.o drm_debugfs.o drm_encoder_slave.o \ 12 + drm_info.o drm_encoder_slave.o \ 13 13 drm_trace_points.o drm_global.o drm_prime.o \ 14 14 drm_rect.o drm_vma_manager.o drm_flip_work.o \ 15 15 drm_modeset_lock.o drm_atomic.o drm_bridge.o \ ··· 23 23 drm-$(CONFIG_DRM_PANEL) += drm_panel.o 24 24 drm-$(CONFIG_OF) += drm_of.o 25 25 drm-$(CONFIG_AGP) += drm_agpsupport.o 26 + drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o 26 27 27 28 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \ 28 29 drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
+33 -1
drivers/gpu/drm/drm_crtc.c
··· 40 40 #include <drm/drm_modeset_lock.h> 41 41 #include <drm/drm_atomic.h> 42 42 #include <drm/drm_auth.h> 43 - #include <drm/drm_framebuffer.h> 43 + #include <drm/drm_debugfs_crc.h> 44 44 45 45 #include "drm_crtc_internal.h" 46 46 #include "drm_internal.h" ··· 122 122 int ret = 0; 123 123 124 124 drm_for_each_crtc(crtc, dev) { 125 + if (drm_debugfs_crtc_add(crtc)) 126 + DRM_ERROR("Failed to initialize debugfs entry for CRTC '%s'.\n", 127 + crtc->name); 128 + 125 129 if (crtc->funcs->late_register) 126 130 ret = crtc->funcs->late_register(crtc); 127 131 if (ret) ··· 142 138 drm_for_each_crtc(crtc, dev) { 143 139 if (crtc->funcs->early_unregister) 144 140 crtc->funcs->early_unregister(crtc); 141 + drm_debugfs_crtc_remove(crtc); 145 142 } 143 + } 144 + 145 + static int drm_crtc_crc_init(struct drm_crtc *crtc) 146 + { 147 + #ifdef CONFIG_DEBUG_FS 148 + spin_lock_init(&crtc->crc.lock); 149 + init_waitqueue_head(&crtc->crc.wq); 150 + crtc->crc.source = kstrdup("auto", GFP_KERNEL); 151 + if (!crtc->crc.source) 152 + return -ENOMEM; 153 + #endif 154 + return 0; 155 + } 156 + 157 + static void drm_crtc_crc_fini(struct drm_crtc *crtc) 158 + { 159 + #ifdef CONFIG_DEBUG_FS 160 + kfree(crtc->crc.source); 161 + #endif 146 162 } 147 163 148 164 /** ··· 234 210 if (cursor) 235 211 cursor->possible_crtcs = 1 << drm_crtc_index(crtc); 236 212 213 + ret = drm_crtc_crc_init(crtc); 214 + if (ret) { 215 + drm_mode_object_unregister(dev, &crtc->base); 216 + return ret; 217 + } 218 + 237 219 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 238 220 drm_object_attach_property(&crtc->base, config->prop_active, 0); 239 221 drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); ··· 265 235 * remove the drm_crtc at runtime we would have to decrement all 266 236 * the indices on the drm_crtc after us in the crtc_list. 267 237 */ 238 + 239 + drm_crtc_crc_fini(crtc); 268 240 269 241 kfree(crtc->gamma_store); 270 242 crtc->gamma_store = NULL;
+33 -1
drivers/gpu/drm/drm_debugfs.c
··· 415 415 connector->debugfs_entry = NULL; 416 416 } 417 417 418 - #endif /* CONFIG_DEBUG_FS */ 418 + int drm_debugfs_crtc_add(struct drm_crtc *crtc) 419 + { 420 + struct drm_minor *minor = crtc->dev->primary; 421 + struct dentry *root; 422 + char *name; 419 423 424 + name = kasprintf(GFP_KERNEL, "crtc-%d", crtc->index); 425 + if (!name) 426 + return -ENOMEM; 427 + 428 + root = debugfs_create_dir(name, minor->debugfs_root); 429 + kfree(name); 430 + if (!root) 431 + return -ENOMEM; 432 + 433 + crtc->debugfs_entry = root; 434 + 435 + if (drm_debugfs_crtc_crc_add(crtc)) 436 + goto error; 437 + 438 + return 0; 439 + 440 + error: 441 + drm_debugfs_crtc_remove(crtc); 442 + return -ENOMEM; 443 + } 444 + 445 + void drm_debugfs_crtc_remove(struct drm_crtc *crtc) 446 + { 447 + debugfs_remove_recursive(crtc->debugfs_entry); 448 + crtc->debugfs_entry = NULL; 449 + } 450 + 451 + #endif /* CONFIG_DEBUG_FS */
+351
drivers/gpu/drm/drm_debugfs_crc.c
··· 1 + /* 2 + * Copyright © 2008 Intel Corporation 3 + * Copyright © 2016 Collabora Ltd 4 + * 5 + * Permission is hereby granted, free of charge, to any person obtaining a 6 + * copy of this software and associated documentation files (the "Software"), 7 + * to deal in the Software without restriction, including without limitation 8 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 + * and/or sell copies of the Software, and to permit persons to whom the 10 + * Software is furnished to do so, subject to the following conditions: 11 + * 12 + * The above copyright notice and this permission notice (including the next 13 + * paragraph) shall be included in all copies or substantial portions of the 14 + * Software. 15 + * 16 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 + * IN THE SOFTWARE. 23 + * 24 + * Based on code from the i915 driver. 25 + * Original author: Damien Lespiau <damien.lespiau@intel.com> 26 + * 27 + */ 28 + 29 + #include <linux/circ_buf.h> 30 + #include <linux/ctype.h> 31 + #include <linux/debugfs.h> 32 + #include <drm/drmP.h> 33 + 34 + /** 35 + * DOC: CRC ABI 36 + * 37 + * DRM device drivers can provide to userspace CRC information of each frame as 38 + * it reached a given hardware component (a "source"). 39 + * 40 + * Userspace can control generation of CRCs in a given CRTC by writing to the 41 + * file dri/0/crtc-N/crc/control in debugfs, with N being the index of the CRTC. 42 + * Accepted values are source names (which are driver-specific) and the "auto" 43 + * keyword, which will let the driver select a default source of frame CRCs 44 + * for this CRTC. 45 + * 46 + * Once frame CRC generation is enabled, userspace can capture them by reading 47 + * the dri/0/crtc-N/crc/data file. Each line in that file contains the frame 48 + * number in the first field and then a number of unsigned integer fields 49 + * containing the CRC data. Fields are separated by a single space and the number 50 + * of CRC fields is source-specific. 51 + * 52 + * Note that though in some cases the CRC is computed in a specified way and on 53 + * the frame contents as supplied by userspace (eDP 1.3), in general the CRC 54 + * computation is performed in an unspecified way and on frame contents that have 55 + * been already processed in also an unspecified way and thus userspace cannot 56 + * rely on being able to generate matching CRC values for the frame contents that 57 + * it submits. In this general case, the maximum userspace can do is to compare 58 + * the reported CRCs of frames that should have the same contents. 59 + */ 60 + 61 + static int crc_control_show(struct seq_file *m, void *data) 62 + { 63 + struct drm_crtc *crtc = m->private; 64 + 65 + seq_printf(m, "%s\n", crtc->crc.source); 66 + 67 + return 0; 68 + } 69 + 70 + static int crc_control_open(struct inode *inode, struct file *file) 71 + { 72 + struct drm_crtc *crtc = inode->i_private; 73 + 74 + return single_open(file, crc_control_show, crtc); 75 + } 76 + 77 + static ssize_t crc_control_write(struct file *file, const char __user *ubuf, 78 + size_t len, loff_t *offp) 79 + { 80 + struct seq_file *m = file->private_data; 81 + struct drm_crtc *crtc = m->private; 82 + struct drm_crtc_crc *crc = &crtc->crc; 83 + char *source; 84 + 85 + if (len == 0) 86 + return 0; 87 + 88 + if (len > PAGE_SIZE - 1) { 89 + DRM_DEBUG_KMS("Expected < %lu bytes into crtc crc control\n", 90 + PAGE_SIZE); 91 + return -E2BIG; 92 + } 93 + 94 + source = memdup_user_nul(ubuf, len); 95 + if (IS_ERR(source)) 96 + return PTR_ERR(source); 97 + 98 + if (source[len] == '\n') 99 + source[len] = '\0'; 100 + 101 + spin_lock_irq(&crc->lock); 102 + 103 + if (crc->opened) { 104 + spin_unlock_irq(&crc->lock); 105 + kfree(source); 106 + return -EBUSY; 107 + } 108 + 109 + kfree(crc->source); 110 + crc->source = source; 111 + 112 + spin_unlock_irq(&crc->lock); 113 + 114 + *offp += len; 115 + return len; 116 + } 117 + 118 + const struct file_operations drm_crtc_crc_control_fops = { 119 + .owner = THIS_MODULE, 120 + .open = crc_control_open, 121 + .read = seq_read, 122 + .llseek = seq_lseek, 123 + .release = single_release, 124 + .write = crc_control_write 125 + }; 126 + 127 + static int crtc_crc_open(struct inode *inode, struct file *filep) 128 + { 129 + struct drm_crtc *crtc = inode->i_private; 130 + struct drm_crtc_crc *crc = &crtc->crc; 131 + struct drm_crtc_crc_entry *entries = NULL; 132 + size_t values_cnt; 133 + int ret; 134 + 135 + if (crc->opened) 136 + return -EBUSY; 137 + 138 + ret = crtc->funcs->set_crc_source(crtc, crc->source, &values_cnt); 139 + if (ret) 140 + return ret; 141 + 142 + if (WARN_ON(values_cnt > DRM_MAX_CRC_NR)) { 143 + ret = -EINVAL; 144 + goto err_disable; 145 + } 146 + 147 + if (WARN_ON(values_cnt == 0)) { 148 + ret = -EINVAL; 149 + goto err_disable; 150 + } 151 + 152 + entries = kcalloc(DRM_CRC_ENTRIES_NR, sizeof(*entries), GFP_KERNEL); 153 + if (!entries) { 154 + ret = -ENOMEM; 155 + goto err_disable; 156 + } 157 + 158 + spin_lock_irq(&crc->lock); 159 + crc->entries = entries; 160 + crc->values_cnt = values_cnt; 161 + crc->opened = true; 162 + spin_unlock_irq(&crc->lock); 163 + 164 + return 0; 165 + 166 + err_disable: 167 + crtc->funcs->set_crc_source(crtc, NULL, &values_cnt); 168 + return ret; 169 + } 170 + 171 + static int crtc_crc_release(struct inode *inode, struct file *filep) 172 + { 173 + struct drm_crtc *crtc = filep->f_inode->i_private; 174 + struct drm_crtc_crc *crc = &crtc->crc; 175 + size_t values_cnt; 176 + 177 + spin_lock_irq(&crc->lock); 178 + kfree(crc->entries); 179 + crc->entries = NULL; 180 + crc->head = 0; 181 + crc->tail = 0; 182 + crc->values_cnt = 0; 183 + crc->opened = false; 184 + spin_unlock_irq(&crc->lock); 185 + 186 + crtc->funcs->set_crc_source(crtc, NULL, &values_cnt); 187 + 188 + return 0; 189 + } 190 + 191 + static int crtc_crc_data_count(struct drm_crtc_crc *crc) 192 + { 193 + assert_spin_locked(&crc->lock); 194 + return CIRC_CNT(crc->head, crc->tail, DRM_CRC_ENTRIES_NR); 195 + } 196 + 197 + /* 198 + * 1 frame field of 10 chars plus a number of CRC fields of 10 chars each, space 199 + * separated, with a newline at the end and null-terminated. 200 + */ 201 + #define LINE_LEN(values_cnt) (10 + 11 * values_cnt + 1 + 1) 202 + #define MAX_LINE_LEN (LINE_LEN(DRM_MAX_CRC_NR)) 203 + 204 + static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf, 205 + size_t count, loff_t *pos) 206 + { 207 + struct drm_crtc *crtc = filep->f_inode->i_private; 208 + struct drm_crtc_crc *crc = &crtc->crc; 209 + struct drm_crtc_crc_entry *entry; 210 + char buf[MAX_LINE_LEN]; 211 + int ret, i; 212 + 213 + spin_lock_irq(&crc->lock); 214 + 215 + if (!crc->source) { 216 + spin_unlock_irq(&crc->lock); 217 + return 0; 218 + } 219 + 220 + /* Nothing to read? */ 221 + while (crtc_crc_data_count(crc) == 0) { 222 + if (filep->f_flags & O_NONBLOCK) { 223 + spin_unlock_irq(&crc->lock); 224 + return -EAGAIN; 225 + } 226 + 227 + ret = wait_event_interruptible_lock_irq(crc->wq, 228 + crtc_crc_data_count(crc), 229 + crc->lock); 230 + if (ret) { 231 + spin_unlock_irq(&crc->lock); 232 + return ret; 233 + } 234 + } 235 + 236 + /* We know we have an entry to be read */ 237 + entry = &crc->entries[crc->tail]; 238 + 239 + if (count < LINE_LEN(crc->values_cnt)) { 240 + spin_unlock_irq(&crc->lock); 241 + return -EINVAL; 242 + } 243 + 244 + BUILD_BUG_ON_NOT_POWER_OF_2(DRM_CRC_ENTRIES_NR); 245 + crc->tail = (crc->tail + 1) & (DRM_CRC_ENTRIES_NR - 1); 246 + 247 + spin_unlock_irq(&crc->lock); 248 + 249 + if (entry->has_frame_counter) 250 + sprintf(buf, "0x%08x", entry->frame); 251 + else 252 + sprintf(buf, "XXXXXXXXXX"); 253 + 254 + for (i = 0; i < crc->values_cnt; i++) 255 + sprintf(buf + 10 + i * 11, " 0x%08x", entry->crcs[i]); 256 + sprintf(buf + 10 + crc->values_cnt * 11, "\n"); 257 + 258 + if (copy_to_user(user_buf, buf, LINE_LEN(crc->values_cnt))) 259 + return -EFAULT; 260 + 261 + return LINE_LEN(crc->values_cnt); 262 + } 263 + 264 + const struct file_operations drm_crtc_crc_data_fops = { 265 + .owner = THIS_MODULE, 266 + .open = crtc_crc_open, 267 + .read = crtc_crc_read, 268 + .release = crtc_crc_release, 269 + }; 270 + 271 + /** 272 + * drm_debugfs_crtc_crc_add - Add files to debugfs for capture of frame CRCs 273 + * @crtc: CRTC to whom the frames will belong 274 + * 275 + * Adds files to debugfs directory that allows userspace to control the 276 + * generation of frame CRCs and to read them. 277 + * 278 + * Returns: 279 + * Zero on success, error code on failure. 280 + */ 281 + int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc) 282 + { 283 + struct dentry *crc_ent, *ent; 284 + 285 + if (!crtc->funcs->set_crc_source) 286 + return 0; 287 + 288 + crc_ent = debugfs_create_dir("crc", crtc->debugfs_entry); 289 + if (!crc_ent) 290 + return -ENOMEM; 291 + 292 + ent = debugfs_create_file("control", S_IRUGO, crc_ent, crtc, 293 + &drm_crtc_crc_control_fops); 294 + if (!ent) 295 + goto error; 296 + 297 + ent = debugfs_create_file("data", S_IRUGO, crc_ent, crtc, 298 + &drm_crtc_crc_data_fops); 299 + if (!ent) 300 + goto error; 301 + 302 + return 0; 303 + 304 + error: 305 + debugfs_remove_recursive(crc_ent); 306 + 307 + return -ENOMEM; 308 + } 309 + 310 + /** 311 + * drm_crtc_add_crc_entry - Add entry with CRC information for a frame 312 + * @crtc: CRTC to which the frame belongs 313 + * @has_frame: whether this entry has a frame number to go with 314 + * @frame: number of the frame these CRCs are about 315 + * @crcs: array of CRC values, with length matching #drm_crtc_crc.values_cnt 316 + * 317 + * For each frame, the driver polls the source of CRCs for new data and calls 318 + * this function to add them to the buffer from where userspace reads. 319 + */ 320 + int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame, 321 + uint32_t frame, uint32_t *crcs) 322 + { 323 + struct drm_crtc_crc *crc = &crtc->crc; 324 + struct drm_crtc_crc_entry *entry; 325 + int head, tail; 326 + 327 + assert_spin_locked(&crc->lock); 328 + 329 + /* Caller may not have noticed yet that userspace has stopped reading */ 330 + if (!crc->opened) 331 + return -EINVAL; 332 + 333 + head = crc->head; 334 + tail = crc->tail; 335 + 336 + if (CIRC_SPACE(head, tail, DRM_CRC_ENTRIES_NR) < 1) { 337 + DRM_ERROR("Overflow of CRC buffer, userspace reads too slow.\n"); 338 + return -ENOBUFS; 339 + } 340 + 341 + entry = &crc->entries[head]; 342 + entry->frame = frame; 343 + entry->has_frame_counter = has_frame; 344 + memcpy(&entry->crcs, crcs, sizeof(*crcs) * crc->values_cnt); 345 + 346 + head = (head + 1) & (DRM_CRC_ENTRIES_NR - 1); 347 + crc->head = head; 348 + 349 + return 0; 350 + } 351 + EXPORT_SYMBOL_GPL(drm_crtc_add_crc_entry);
+16
drivers/gpu/drm/drm_internal.h
··· 100 100 int drm_debugfs_cleanup(struct drm_minor *minor); 101 101 int drm_debugfs_connector_add(struct drm_connector *connector); 102 102 void drm_debugfs_connector_remove(struct drm_connector *connector); 103 + int drm_debugfs_crtc_add(struct drm_crtc *crtc); 104 + void drm_debugfs_crtc_remove(struct drm_crtc *crtc); 105 + int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc); 103 106 #else 104 107 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id, 105 108 struct dentry *root) ··· 121 118 } 122 119 static inline void drm_debugfs_connector_remove(struct drm_connector *connector) 123 120 { 121 + } 122 + 123 + static inline int drm_debugfs_crtc_add(struct drm_crtc *crtc) 124 + { 125 + return 0; 126 + } 127 + static inline void drm_debugfs_crtc_remove(struct drm_crtc *crtc) 128 + { 129 + } 130 + 131 + static inline int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc) 132 + { 133 + return 0; 124 134 } 125 135 #endif
+41
include/drm/drm_crtc.h
··· 47 47 #include <drm/drm_plane.h> 48 48 #include <drm/drm_blend.h> 49 49 #include <drm/drm_color_mgmt.h> 50 + #include <drm/drm_debugfs_crc.h> 50 51 51 52 struct drm_device; 52 53 struct drm_mode_set; ··· 570 569 * before data structures are torndown. 571 570 */ 572 571 void (*early_unregister)(struct drm_crtc *crtc); 572 + 573 + /** 574 + * @set_crc_source: 575 + * 576 + * Changes the source of CRC checksums of frames at the request of 577 + * userspace, typically for testing purposes. The sources available are 578 + * specific of each driver and a %NULL value indicates that CRC 579 + * generation is to be switched off. 580 + * 581 + * When CRC generation is enabled, the driver should call 582 + * drm_crtc_add_crc_entry() at each frame, providing any information 583 + * that characterizes the frame contents in the crcN arguments, as 584 + * provided from the configured source. Drivers must accept a "auto" 585 + * source name that will select a default source for this CRTC. 586 + * 587 + * This callback is optional if the driver does not support any CRC 588 + * generation functionality. 589 + * 590 + * RETURNS: 591 + * 592 + * 0 on success or a negative error code on failure. 593 + */ 594 + int (*set_crc_source)(struct drm_crtc *crtc, const char *source, 595 + size_t *values_cnt); 573 596 }; 574 597 575 598 /** ··· 710 685 * context. 711 686 */ 712 687 struct drm_modeset_acquire_ctx *acquire_ctx; 688 + 689 + #ifdef CONFIG_DEBUG_FS 690 + /** 691 + * @debugfs_entry: 692 + * 693 + * Debugfs directory for this CRTC. 694 + */ 695 + struct dentry *debugfs_entry; 696 + 697 + /** 698 + * @crc: 699 + * 700 + * Configuration settings of CRC capture. 701 + */ 702 + struct drm_crtc_crc crc; 703 + #endif 713 704 }; 714 705 715 706 /**
+73
include/drm/drm_debugfs_crc.h
··· 1 + /* 2 + * Copyright © 2016 Collabora Ltd. 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a 5 + * copy of this software and associated documentation files (the "Software"), 6 + * to deal in the Software without restriction, including without limitation 7 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 + * and/or sell copies of the Software, and to permit persons to whom the 9 + * Software is furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 + * OTHER DEALINGS IN THE SOFTWARE. 21 + */ 22 + #ifndef __DRM_DEBUGFS_CRC_H__ 23 + #define __DRM_DEBUGFS_CRC_H__ 24 + 25 + #define DRM_MAX_CRC_NR 10 26 + 27 + /** 28 + * struct drm_crtc_crc_entry - entry describing a frame's content 29 + * @has_frame_counter: whether the source was able to provide a frame number 30 + * @frame: number of the frame this CRC is about, if @has_frame_counter is true 31 + * @crc: array of values that characterize the frame 32 + */ 33 + struct drm_crtc_crc_entry { 34 + bool has_frame_counter; 35 + uint32_t frame; 36 + uint32_t crcs[DRM_MAX_CRC_NR]; 37 + }; 38 + 39 + #define DRM_CRC_ENTRIES_NR 128 40 + 41 + /** 42 + * struct drm_crtc_crc - data supporting CRC capture on a given CRTC 43 + * @lock: protects the fields in this struct 44 + * @source: name of the currently configured source of CRCs 45 + * @opened: whether userspace has opened the data file for reading 46 + * @entries: array of entries, with size of %DRM_CRC_ENTRIES_NR 47 + * @head: head of circular queue 48 + * @tail: tail of circular queue 49 + * @values_cnt: number of CRC values per entry, up to %DRM_MAX_CRC_NR 50 + * @wq: workqueue used to synchronize reading and writing 51 + */ 52 + struct drm_crtc_crc { 53 + spinlock_t lock; 54 + const char *source; 55 + bool opened; 56 + struct drm_crtc_crc_entry *entries; 57 + int head, tail; 58 + size_t values_cnt; 59 + wait_queue_head_t wq; 60 + }; 61 + 62 + #if defined(CONFIG_DEBUG_FS) 63 + int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame, 64 + uint32_t frame, uint32_t *crcs); 65 + #else 66 + static inline int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame, 67 + uint32_t frame, uint32_t *crcs) 68 + { 69 + return -EINVAL; 70 + } 71 + #endif /* defined(CONFIG_DEBUG_FS) */ 72 + 73 + #endif /* __DRM_DEBUGFS_CRC_H__ */