| .. | .. |
|---|
| 29 | 29 | #include <linux/circ_buf.h> |
|---|
| 30 | 30 | #include <linux/ctype.h> |
|---|
| 31 | 31 | #include <linux/debugfs.h> |
|---|
| 32 | | -#include <drm/drmP.h> |
|---|
| 32 | +#include <linux/poll.h> |
|---|
| 33 | +#include <linux/uaccess.h> |
|---|
| 34 | + |
|---|
| 35 | +#include <drm/drm_crtc.h> |
|---|
| 36 | +#include <drm/drm_debugfs_crc.h> |
|---|
| 37 | +#include <drm/drm_drv.h> |
|---|
| 38 | +#include <drm/drm_print.h> |
|---|
| 39 | + |
|---|
| 33 | 40 | #include "drm_internal.h" |
|---|
| 34 | 41 | |
|---|
| 35 | 42 | /** |
|---|
| .. | .. |
|---|
| 59 | 66 | * the reported CRCs of frames that should have the same contents. |
|---|
| 60 | 67 | * |
|---|
| 61 | 68 | * On the driver side the implementation effort is minimal, drivers only need to |
|---|
| 62 | | - * implement &drm_crtc_funcs.set_crc_source. The debugfs files are automatically |
|---|
| 63 | | - * set up if that vfunc is set. CRC samples need to be captured in the driver by |
|---|
| 64 | | - * calling drm_crtc_add_crc_entry(). |
|---|
| 69 | + * implement &drm_crtc_funcs.set_crc_source and &drm_crtc_funcs.verify_crc_source. |
|---|
| 70 | + * The debugfs files are automatically set up if those vfuncs are set. CRC samples |
|---|
| 71 | + * need to be captured in the driver by calling drm_crtc_add_crc_entry(). |
|---|
| 72 | + * Depending on the driver and HW requirements, &drm_crtc_funcs.set_crc_source |
|---|
| 73 | + * may result in a commit (even a full modeset). |
|---|
| 74 | + * |
|---|
| 75 | + * CRC results must be reliable across non-full-modeset atomic commits, so if a |
|---|
| 76 | + * commit via DRM_IOCTL_MODE_ATOMIC would disable or otherwise interfere with |
|---|
| 77 | + * CRC generation, then the driver must mark that commit as a full modeset |
|---|
| 78 | + * (drm_atomic_crtc_needs_modeset() should return true). As a result, to ensure |
|---|
| 79 | + * consistent results, generic userspace must re-setup CRC generation after a |
|---|
| 80 | + * legacy SETCRTC or an atomic commit with DRM_MODE_ATOMIC_ALLOW_MODESET. |
|---|
| 65 | 81 | */ |
|---|
| 66 | 82 | |
|---|
| 67 | 83 | static int crc_control_show(struct seq_file *m, void *data) |
|---|
| .. | .. |
|---|
| 128 | 144 | source[len - 1] = '\0'; |
|---|
| 129 | 145 | |
|---|
| 130 | 146 | ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt); |
|---|
| 131 | | - if (ret) |
|---|
| 147 | + if (ret) { |
|---|
| 148 | + kfree(source); |
|---|
| 132 | 149 | return ret; |
|---|
| 150 | + } |
|---|
| 133 | 151 | |
|---|
| 134 | 152 | spin_lock_irq(&crc->lock); |
|---|
| 135 | 153 | |
|---|
| .. | .. |
|---|
| 228 | 246 | if (ret) |
|---|
| 229 | 247 | goto err; |
|---|
| 230 | 248 | |
|---|
| 231 | | - spin_lock_irq(&crc->lock); |
|---|
| 232 | | - /* |
|---|
| 233 | | - * Only return once we got a first frame, so userspace doesn't have to |
|---|
| 234 | | - * guess when this particular piece of HW will be ready to start |
|---|
| 235 | | - * generating CRCs. |
|---|
| 236 | | - */ |
|---|
| 237 | | - ret = wait_event_interruptible_lock_irq(crc->wq, |
|---|
| 238 | | - crtc_crc_data_count(crc), |
|---|
| 239 | | - crc->lock); |
|---|
| 240 | | - spin_unlock_irq(&crc->lock); |
|---|
| 241 | | - |
|---|
| 242 | | - if (ret) |
|---|
| 243 | | - goto err_disable; |
|---|
| 244 | | - |
|---|
| 245 | 249 | return 0; |
|---|
| 246 | 250 | |
|---|
| 247 | | -err_disable: |
|---|
| 248 | | - crtc->funcs->set_crc_source(crtc, NULL); |
|---|
| 249 | 251 | err: |
|---|
| 250 | 252 | spin_lock_irq(&crc->lock); |
|---|
| 251 | 253 | crtc_crc_cleanup(crc); |
|---|
| .. | .. |
|---|
| 257 | 259 | { |
|---|
| 258 | 260 | struct drm_crtc *crtc = filep->f_inode->i_private; |
|---|
| 259 | 261 | struct drm_crtc_crc *crc = &crtc->crc; |
|---|
| 262 | + |
|---|
| 263 | + /* terminate the infinite while loop if 'drm_dp_aux_crc_work' running */ |
|---|
| 264 | + spin_lock_irq(&crc->lock); |
|---|
| 265 | + crc->opened = false; |
|---|
| 266 | + spin_unlock_irq(&crc->lock); |
|---|
| 260 | 267 | |
|---|
| 261 | 268 | crtc->funcs->set_crc_source(crtc, NULL); |
|---|
| 262 | 269 | |
|---|
| .. | .. |
|---|
| 334 | 341 | return LINE_LEN(crc->values_cnt); |
|---|
| 335 | 342 | } |
|---|
| 336 | 343 | |
|---|
| 337 | | -static unsigned int crtc_crc_poll(struct file *file, poll_table *wait) |
|---|
| 344 | +static __poll_t crtc_crc_poll(struct file *file, poll_table *wait) |
|---|
| 338 | 345 | { |
|---|
| 339 | 346 | struct drm_crtc *crtc = file->f_inode->i_private; |
|---|
| 340 | 347 | struct drm_crtc_crc *crc = &crtc->crc; |
|---|
| 341 | | - unsigned ret; |
|---|
| 348 | + __poll_t ret = 0; |
|---|
| 342 | 349 | |
|---|
| 343 | 350 | poll_wait(file, &crc->wq, wait); |
|---|
| 344 | 351 | |
|---|
| 345 | 352 | spin_lock_irq(&crc->lock); |
|---|
| 346 | 353 | if (crc->source && crtc_crc_data_count(crc)) |
|---|
| 347 | | - ret = POLLIN | POLLRDNORM; |
|---|
| 348 | | - else |
|---|
| 349 | | - ret = 0; |
|---|
| 354 | + ret |= EPOLLIN | EPOLLRDNORM; |
|---|
| 350 | 355 | spin_unlock_irq(&crc->lock); |
|---|
| 351 | 356 | |
|---|
| 352 | 357 | return ret; |
|---|
| .. | .. |
|---|
| 360 | 365 | .release = crtc_crc_release, |
|---|
| 361 | 366 | }; |
|---|
| 362 | 367 | |
|---|
| 363 | | -int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc) |
|---|
| 368 | +void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc) |
|---|
| 364 | 369 | { |
|---|
| 365 | | - struct dentry *crc_ent, *ent; |
|---|
| 370 | + struct dentry *crc_ent; |
|---|
| 366 | 371 | |
|---|
| 367 | 372 | if (!crtc->funcs->set_crc_source || !crtc->funcs->verify_crc_source) |
|---|
| 368 | | - return 0; |
|---|
| 373 | + return; |
|---|
| 369 | 374 | |
|---|
| 370 | 375 | crc_ent = debugfs_create_dir("crc", crtc->debugfs_entry); |
|---|
| 371 | | - if (!crc_ent) |
|---|
| 372 | | - return -ENOMEM; |
|---|
| 373 | 376 | |
|---|
| 374 | | - ent = debugfs_create_file("control", S_IRUGO, crc_ent, crtc, |
|---|
| 375 | | - &drm_crtc_crc_control_fops); |
|---|
| 376 | | - if (!ent) |
|---|
| 377 | | - goto error; |
|---|
| 378 | | - |
|---|
| 379 | | - ent = debugfs_create_file("data", S_IRUGO, crc_ent, crtc, |
|---|
| 380 | | - &drm_crtc_crc_data_fops); |
|---|
| 381 | | - if (!ent) |
|---|
| 382 | | - goto error; |
|---|
| 383 | | - |
|---|
| 384 | | - return 0; |
|---|
| 385 | | - |
|---|
| 386 | | -error: |
|---|
| 387 | | - debugfs_remove_recursive(crc_ent); |
|---|
| 388 | | - |
|---|
| 389 | | - return -ENOMEM; |
|---|
| 377 | + debugfs_create_file("control", S_IRUGO | S_IWUSR, crc_ent, crtc, |
|---|
| 378 | + &drm_crtc_crc_control_fops); |
|---|
| 379 | + debugfs_create_file("data", S_IRUGO, crc_ent, crtc, |
|---|
| 380 | + &drm_crtc_crc_data_fops); |
|---|
| 390 | 381 | } |
|---|
| 391 | 382 | |
|---|
| 392 | 383 | /** |
|---|