Skip to content

Commit 9edbf1f

Browse files
tomeuvdanvet
authored andcommitted
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
1 parent 865afb1 commit 9edbf1f

8 files changed

Lines changed: 555 additions & 3 deletions

File tree

‎Documentation/gpu/drm-uapi.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,9 @@ interfaces. Especially since all hardware-acceleration interfaces to
216216
userspace are driver specific for efficiency and other reasons these
217217
interfaces can be rather substantial. Hence every driver has its own
218218
chapter.
219+
220+
Testing and validation
221+
======================
222+
223+
.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
224+
:doc: CRC ABI

‎drivers/gpu/drm/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \
99
drm_scatter.o drm_pci.o \
1010
drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
1111
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 \
1313
drm_trace_points.o drm_global.o drm_prime.o \
1414
drm_rect.o drm_vma_manager.o drm_flip_work.o \
1515
drm_modeset_lock.o drm_atomic.o drm_bridge.o \
@@ -23,6 +23,7 @@ drm-$(CONFIG_PCI) += ati_pcigart.o
2323
drm-$(CONFIG_DRM_PANEL) += drm_panel.o
2424
drm-$(CONFIG_OF) += drm_of.o
2525
drm-$(CONFIG_AGP) += drm_agpsupport.o
26+
drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
2627

2728
drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
2829
drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <drm/drm_modeset_lock.h>
4141
#include <drm/drm_atomic.h>
4242
#include <drm/drm_auth.h>
43-
#include <drm/drm_framebuffer.h>
43+
#include <drm/drm_debugfs_crc.h>
4444

4545
#include "drm_crtc_internal.h"
4646
#include "drm_internal.h"
@@ -122,6 +122,10 @@ static int drm_crtc_register_all(struct drm_device *dev)
122122
int ret = 0;
123123

124124
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+
125129
if (crtc->funcs->late_register)
126130
ret = crtc->funcs->late_register(crtc);
127131
if (ret)
@@ -138,9 +142,29 @@ static void drm_crtc_unregister_all(struct drm_device *dev)
138142
drm_for_each_crtc(crtc, dev) {
139143
if (crtc->funcs->early_unregister)
140144
crtc->funcs->early_unregister(crtc);
145+
drm_debugfs_crtc_remove(crtc);
141146
}
142147
}
143148

149+
static int drm_crtc_crc_init(struct drm_crtc *crtc)
150+
{
151+
#ifdef CONFIG_DEBUG_FS
152+
spin_lock_init(&crtc->crc.lock);
153+
init_waitqueue_head(&crtc->crc.wq);
154+
crtc->crc.source = kstrdup("auto", GFP_KERNEL);
155+
if (!crtc->crc.source)
156+
return -ENOMEM;
157+
#endif
158+
return 0;
159+
}
160+
161+
static void drm_crtc_crc_fini(struct drm_crtc *crtc)
162+
{
163+
#ifdef CONFIG_DEBUG_FS
164+
kfree(crtc->crc.source);
165+
#endif
166+
}
167+
144168
/**
145169
* drm_crtc_init_with_planes - Initialise a new CRTC object with
146170
* specified primary and cursor planes.
@@ -210,6 +234,12 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
210234
if (cursor)
211235
cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
212236

237+
ret = drm_crtc_crc_init(crtc);
238+
if (ret) {
239+
drm_mode_object_unregister(dev, &crtc->base);
240+
return ret;
241+
}
242+
213243
if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
214244
drm_object_attach_property(&crtc->base, config->prop_active, 0);
215245
drm_object_attach_property(&crtc->base, config->prop_mode_id, 0);
@@ -236,6 +266,8 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)
236266
* the indices on the drm_crtc after us in the crtc_list.
237267
*/
238268

269+
drm_crtc_crc_fini(crtc);
270+
239271
kfree(crtc->gamma_store);
240272
crtc->gamma_store = NULL;
241273

‎drivers/gpu/drm/drm_debugfs.c‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,5 +415,37 @@ void drm_debugfs_connector_remove(struct drm_connector *connector)
415415
connector->debugfs_entry = NULL;
416416
}
417417

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;
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;
419437

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 */

0 commit comments

Comments
 (0)