18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright © 2016 Collabora Ltd.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci#ifndef __DRM_DEBUGFS_CRC_H__
238c2ecf20Sopenharmony_ci#define __DRM_DEBUGFS_CRC_H__
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define DRM_MAX_CRC_NR		10
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/**
288c2ecf20Sopenharmony_ci * struct drm_crtc_crc_entry - entry describing a frame's content
298c2ecf20Sopenharmony_ci * @has_frame_counter: whether the source was able to provide a frame number
308c2ecf20Sopenharmony_ci * @frame: number of the frame this CRC is about, if @has_frame_counter is true
318c2ecf20Sopenharmony_ci * @crc: array of values that characterize the frame
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_cistruct drm_crtc_crc_entry {
348c2ecf20Sopenharmony_ci	bool has_frame_counter;
358c2ecf20Sopenharmony_ci	uint32_t frame;
368c2ecf20Sopenharmony_ci	uint32_t crcs[DRM_MAX_CRC_NR];
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define DRM_CRC_ENTRIES_NR	128
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/**
428c2ecf20Sopenharmony_ci * struct drm_crtc_crc - data supporting CRC capture on a given CRTC
438c2ecf20Sopenharmony_ci * @lock: protects the fields in this struct
448c2ecf20Sopenharmony_ci * @source: name of the currently configured source of CRCs
458c2ecf20Sopenharmony_ci * @opened: whether userspace has opened the data file for reading
468c2ecf20Sopenharmony_ci * @overflow: whether an overflow occured.
478c2ecf20Sopenharmony_ci * @entries: array of entries, with size of %DRM_CRC_ENTRIES_NR
488c2ecf20Sopenharmony_ci * @head: head of circular queue
498c2ecf20Sopenharmony_ci * @tail: tail of circular queue
508c2ecf20Sopenharmony_ci * @values_cnt: number of CRC values per entry, up to %DRM_MAX_CRC_NR
518c2ecf20Sopenharmony_ci * @wq: workqueue used to synchronize reading and writing
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_cistruct drm_crtc_crc {
548c2ecf20Sopenharmony_ci	spinlock_t lock;
558c2ecf20Sopenharmony_ci	const char *source;
568c2ecf20Sopenharmony_ci	bool opened, overflow;
578c2ecf20Sopenharmony_ci	struct drm_crtc_crc_entry *entries;
588c2ecf20Sopenharmony_ci	int head, tail;
598c2ecf20Sopenharmony_ci	size_t values_cnt;
608c2ecf20Sopenharmony_ci	wait_queue_head_t wq;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#if defined(CONFIG_DEBUG_FS)
648c2ecf20Sopenharmony_ciint drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame,
658c2ecf20Sopenharmony_ci			   uint32_t frame, uint32_t *crcs);
668c2ecf20Sopenharmony_ci#else
678c2ecf20Sopenharmony_cistatic inline int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame,
688c2ecf20Sopenharmony_ci					 uint32_t frame, uint32_t *crcs)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	return -EINVAL;
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci#endif /* defined(CONFIG_DEBUG_FS) */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#endif /* __DRM_DEBUGFS_CRC_H__ */
75