hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpu/drm/drm_debugfs_crc.c
....@@ -29,7 +29,14 @@
2929 #include <linux/circ_buf.h>
3030 #include <linux/ctype.h>
3131 #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
+
3340 #include "drm_internal.h"
3441
3542 /**
....@@ -59,9 +66,18 @@
5966 * the reported CRCs of frames that should have the same contents.
6067 *
6168 * 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.
6581 */
6682
6783 static int crc_control_show(struct seq_file *m, void *data)
....@@ -128,8 +144,10 @@
128144 source[len - 1] = '\0';
129145
130146 ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt);
131
- if (ret)
147
+ if (ret) {
148
+ kfree(source);
132149 return ret;
150
+ }
133151
134152 spin_lock_irq(&crc->lock);
135153
....@@ -228,24 +246,8 @@
228246 if (ret)
229247 goto err;
230248
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
-
245249 return 0;
246250
247
-err_disable:
248
- crtc->funcs->set_crc_source(crtc, NULL);
249251 err:
250252 spin_lock_irq(&crc->lock);
251253 crtc_crc_cleanup(crc);
....@@ -257,6 +259,11 @@
257259 {
258260 struct drm_crtc *crtc = filep->f_inode->i_private;
259261 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);
260267
261268 crtc->funcs->set_crc_source(crtc, NULL);
262269
....@@ -334,19 +341,17 @@
334341 return LINE_LEN(crc->values_cnt);
335342 }
336343
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)
338345 {
339346 struct drm_crtc *crtc = file->f_inode->i_private;
340347 struct drm_crtc_crc *crc = &crtc->crc;
341
- unsigned ret;
348
+ __poll_t ret = 0;
342349
343350 poll_wait(file, &crc->wq, wait);
344351
345352 spin_lock_irq(&crc->lock);
346353 if (crc->source && crtc_crc_data_count(crc))
347
- ret = POLLIN | POLLRDNORM;
348
- else
349
- ret = 0;
354
+ ret |= EPOLLIN | EPOLLRDNORM;
350355 spin_unlock_irq(&crc->lock);
351356
352357 return ret;
....@@ -360,33 +365,19 @@
360365 .release = crtc_crc_release,
361366 };
362367
363
-int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
368
+void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
364369 {
365
- struct dentry *crc_ent, *ent;
370
+ struct dentry *crc_ent;
366371
367372 if (!crtc->funcs->set_crc_source || !crtc->funcs->verify_crc_source)
368
- return 0;
373
+ return;
369374
370375 crc_ent = debugfs_create_dir("crc", crtc->debugfs_entry);
371
- if (!crc_ent)
372
- return -ENOMEM;
373376
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);
390381 }
391382
392383 /**