18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#undef TRACE_SYSTEM
38c2ecf20Sopenharmony_ci#define TRACE_SYSTEM v4l2
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#if !defined(_TRACE_V4L2_H) || defined(TRACE_HEADER_MULTI_READ)
68c2ecf20Sopenharmony_ci#define _TRACE_V4L2_H
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/tracepoint.h>
98c2ecf20Sopenharmony_ci#include <media/videobuf2-v4l2.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* Enums require being exported to userspace, for user tool parsing */
128c2ecf20Sopenharmony_ci#undef EM
138c2ecf20Sopenharmony_ci#undef EMe
148c2ecf20Sopenharmony_ci#define EM(a, b)	TRACE_DEFINE_ENUM(a);
158c2ecf20Sopenharmony_ci#define EMe(a, b)	TRACE_DEFINE_ENUM(a);
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define show_type(type)							\
188c2ecf20Sopenharmony_ci	__print_symbolic(type, SHOW_TYPE)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define SHOW_TYPE							\
218c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VIDEO_CAPTURE,	"VIDEO_CAPTURE" )	\
228c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VIDEO_OUTPUT,		"VIDEO_OUTPUT" )	\
238c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VIDEO_OVERLAY,	"VIDEO_OVERLAY" )	\
248c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VBI_CAPTURE,		"VBI_CAPTURE" )		\
258c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VBI_OUTPUT,		"VBI_OUTPUT" )		\
268c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_SLICED_VBI_CAPTURE,   "SLICED_VBI_CAPTURE" )	\
278c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_SLICED_VBI_OUTPUT,    "SLICED_VBI_OUTPUT" )	\
288c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY, "VIDEO_OUTPUT_OVERLAY" ) \
298c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, "VIDEO_CAPTURE_MPLANE" ) \
308c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,  "VIDEO_OUTPUT_MPLANE" )	\
318c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_SDR_CAPTURE,          "SDR_CAPTURE" )		\
328c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_SDR_OUTPUT,           "SDR_OUTPUT" )		\
338c2ecf20Sopenharmony_ci	EM( V4L2_BUF_TYPE_META_CAPTURE,		"META_CAPTURE" )	\
348c2ecf20Sopenharmony_ci	EMe(V4L2_BUF_TYPE_PRIVATE,		"PRIVATE" )
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciSHOW_TYPE
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define show_field(field)						\
398c2ecf20Sopenharmony_ci	__print_symbolic(field, SHOW_FIELD)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define SHOW_FIELD							\
428c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_ANY,		"ANY" )				\
438c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_NONE,		"NONE" )			\
448c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_TOP,		"TOP" )				\
458c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_BOTTOM,		"BOTTOM" )			\
468c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_INTERLACED,	"INTERLACED" )			\
478c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_SEQ_TB,		"SEQ_TB" )			\
488c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_SEQ_BT,		"SEQ_BT" )			\
498c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_ALTERNATE,	"ALTERNATE" )			\
508c2ecf20Sopenharmony_ci	EM( V4L2_FIELD_INTERLACED_TB,	"INTERLACED_TB" )		\
518c2ecf20Sopenharmony_ci	EMe( V4L2_FIELD_INTERLACED_BT,	"INTERLACED_BT" )
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciSHOW_FIELD
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/*
568c2ecf20Sopenharmony_ci * Now redefine the EM() and EMe() macros to map the enums to the strings
578c2ecf20Sopenharmony_ci * that will be printed in the output.
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ci#undef EM
608c2ecf20Sopenharmony_ci#undef EMe
618c2ecf20Sopenharmony_ci#define EM(a, b)	{a, b},
628c2ecf20Sopenharmony_ci#define EMe(a, b)	{a, b}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* V4L2_TC_TYPE_* are macros, not defines, they do not need processing */
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define show_timecode_type(type)					\
678c2ecf20Sopenharmony_ci	__print_symbolic(type,						\
688c2ecf20Sopenharmony_ci		{ V4L2_TC_TYPE_24FPS,		"24FPS" },		\
698c2ecf20Sopenharmony_ci		{ V4L2_TC_TYPE_25FPS,		"25FPS" },		\
708c2ecf20Sopenharmony_ci		{ V4L2_TC_TYPE_30FPS,		"30FPS" },		\
718c2ecf20Sopenharmony_ci		{ V4L2_TC_TYPE_50FPS,		"50FPS" },		\
728c2ecf20Sopenharmony_ci		{ V4L2_TC_TYPE_60FPS,		"60FPS" })
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define show_flags(flags)						      \
758c2ecf20Sopenharmony_ci	__print_flags(flags, "|",					      \
768c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_MAPPED,		     "MAPPED" },	      \
778c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_QUEUED,		     "QUEUED" },	      \
788c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_DONE,		     "DONE" },		      \
798c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_KEYFRAME,	     "KEYFRAME" },	      \
808c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_PFRAME,		     "PFRAME" },	      \
818c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_BFRAME,		     "BFRAME" },	      \
828c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_ERROR,		     "ERROR" },		      \
838c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_TIMECODE,	     "TIMECODE" },	      \
848c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_PREPARED,	     "PREPARED" },	      \
858c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_NO_CACHE_INVALIDATE, "NO_CACHE_INVALIDATE" }, \
868c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_NO_CACHE_CLEAN,	     "NO_CACHE_CLEAN" },      \
878c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_TIMESTAMP_MASK,	     "TIMESTAMP_MASK" },      \
888c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN,   "TIMESTAMP_UNKNOWN" },   \
898c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC, "TIMESTAMP_MONOTONIC" }, \
908c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_TIMESTAMP_COPY,	     "TIMESTAMP_COPY" },      \
918c2ecf20Sopenharmony_ci		{ V4L2_BUF_FLAG_LAST,                "LAST" })
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define show_timecode_flags(flags)					  \
948c2ecf20Sopenharmony_ci	__print_flags(flags, "|",					  \
958c2ecf20Sopenharmony_ci		{ V4L2_TC_FLAG_DROPFRAME,       "DROPFRAME" },		  \
968c2ecf20Sopenharmony_ci		{ V4L2_TC_FLAG_COLORFRAME,      "COLORFRAME" },		  \
978c2ecf20Sopenharmony_ci		{ V4L2_TC_USERBITS_USERDEFINED,	"USERBITS_USERDEFINED" }, \
988c2ecf20Sopenharmony_ci		{ V4L2_TC_USERBITS_8BITCHARS,	"USERBITS_8BITCHARS" })
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(v4l2_event_class,
1018c2ecf20Sopenharmony_ci	TP_PROTO(int minor, struct v4l2_buffer *buf),
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	TP_ARGS(minor, buf),
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
1068c2ecf20Sopenharmony_ci		__field(int, minor)
1078c2ecf20Sopenharmony_ci		__field(u32, index)
1088c2ecf20Sopenharmony_ci		__field(u32, type)
1098c2ecf20Sopenharmony_ci		__field(u32, bytesused)
1108c2ecf20Sopenharmony_ci		__field(u32, flags)
1118c2ecf20Sopenharmony_ci		__field(u32, field)
1128c2ecf20Sopenharmony_ci		__field(s64, timestamp)
1138c2ecf20Sopenharmony_ci		__field(u32, timecode_type)
1148c2ecf20Sopenharmony_ci		__field(u32, timecode_flags)
1158c2ecf20Sopenharmony_ci		__field(u8, timecode_frames)
1168c2ecf20Sopenharmony_ci		__field(u8, timecode_seconds)
1178c2ecf20Sopenharmony_ci		__field(u8, timecode_minutes)
1188c2ecf20Sopenharmony_ci		__field(u8, timecode_hours)
1198c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits0)
1208c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits1)
1218c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits2)
1228c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits3)
1238c2ecf20Sopenharmony_ci		__field(u32, sequence)
1248c2ecf20Sopenharmony_ci	),
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	TP_fast_assign(
1278c2ecf20Sopenharmony_ci		__entry->minor = minor;
1288c2ecf20Sopenharmony_ci		__entry->index = buf->index;
1298c2ecf20Sopenharmony_ci		__entry->type = buf->type;
1308c2ecf20Sopenharmony_ci		__entry->bytesused = buf->bytesused;
1318c2ecf20Sopenharmony_ci		__entry->flags = buf->flags;
1328c2ecf20Sopenharmony_ci		__entry->field = buf->field;
1338c2ecf20Sopenharmony_ci		__entry->timestamp = v4l2_buffer_get_timestamp(buf);
1348c2ecf20Sopenharmony_ci		__entry->timecode_type = buf->timecode.type;
1358c2ecf20Sopenharmony_ci		__entry->timecode_flags = buf->timecode.flags;
1368c2ecf20Sopenharmony_ci		__entry->timecode_frames = buf->timecode.frames;
1378c2ecf20Sopenharmony_ci		__entry->timecode_seconds = buf->timecode.seconds;
1388c2ecf20Sopenharmony_ci		__entry->timecode_minutes = buf->timecode.minutes;
1398c2ecf20Sopenharmony_ci		__entry->timecode_hours = buf->timecode.hours;
1408c2ecf20Sopenharmony_ci		__entry->timecode_userbits0 = buf->timecode.userbits[0];
1418c2ecf20Sopenharmony_ci		__entry->timecode_userbits1 = buf->timecode.userbits[1];
1428c2ecf20Sopenharmony_ci		__entry->timecode_userbits2 = buf->timecode.userbits[2];
1438c2ecf20Sopenharmony_ci		__entry->timecode_userbits3 = buf->timecode.userbits[3];
1448c2ecf20Sopenharmony_ci		__entry->sequence = buf->sequence;
1458c2ecf20Sopenharmony_ci	),
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	TP_printk("minor = %d, index = %u, type = %s, bytesused = %u, "
1488c2ecf20Sopenharmony_ci		  "flags = %s, field = %s, timestamp = %llu, "
1498c2ecf20Sopenharmony_ci		  "timecode = { type = %s, flags = %s, frames = %u, "
1508c2ecf20Sopenharmony_ci		  "seconds = %u, minutes = %u, hours = %u, "
1518c2ecf20Sopenharmony_ci		  "userbits = { %u %u %u %u } }, sequence = %u", __entry->minor,
1528c2ecf20Sopenharmony_ci		  __entry->index, show_type(__entry->type),
1538c2ecf20Sopenharmony_ci		  __entry->bytesused,
1548c2ecf20Sopenharmony_ci		  show_flags(__entry->flags),
1558c2ecf20Sopenharmony_ci		  show_field(__entry->field),
1568c2ecf20Sopenharmony_ci		  __entry->timestamp,
1578c2ecf20Sopenharmony_ci		  show_timecode_type(__entry->timecode_type),
1588c2ecf20Sopenharmony_ci		  show_timecode_flags(__entry->timecode_flags),
1598c2ecf20Sopenharmony_ci		  __entry->timecode_frames,
1608c2ecf20Sopenharmony_ci		  __entry->timecode_seconds,
1618c2ecf20Sopenharmony_ci		  __entry->timecode_minutes,
1628c2ecf20Sopenharmony_ci		  __entry->timecode_hours,
1638c2ecf20Sopenharmony_ci		  __entry->timecode_userbits0,
1648c2ecf20Sopenharmony_ci		  __entry->timecode_userbits1,
1658c2ecf20Sopenharmony_ci		  __entry->timecode_userbits2,
1668c2ecf20Sopenharmony_ci		  __entry->timecode_userbits3,
1678c2ecf20Sopenharmony_ci		  __entry->sequence
1688c2ecf20Sopenharmony_ci	)
1698c2ecf20Sopenharmony_ci)
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ciDEFINE_EVENT(v4l2_event_class, v4l2_dqbuf,
1728c2ecf20Sopenharmony_ci	TP_PROTO(int minor, struct v4l2_buffer *buf),
1738c2ecf20Sopenharmony_ci	TP_ARGS(minor, buf)
1748c2ecf20Sopenharmony_ci);
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ciDEFINE_EVENT(v4l2_event_class, v4l2_qbuf,
1778c2ecf20Sopenharmony_ci	TP_PROTO(int minor, struct v4l2_buffer *buf),
1788c2ecf20Sopenharmony_ci	TP_ARGS(minor, buf)
1798c2ecf20Sopenharmony_ci);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(vb2_v4l2_event_class,
1828c2ecf20Sopenharmony_ci	TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb),
1838c2ecf20Sopenharmony_ci	TP_ARGS(q, vb),
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
1868c2ecf20Sopenharmony_ci		__field(int, minor)
1878c2ecf20Sopenharmony_ci		__field(u32, flags)
1888c2ecf20Sopenharmony_ci		__field(u32, field)
1898c2ecf20Sopenharmony_ci		__field(u64, timestamp)
1908c2ecf20Sopenharmony_ci		__field(u32, timecode_type)
1918c2ecf20Sopenharmony_ci		__field(u32, timecode_flags)
1928c2ecf20Sopenharmony_ci		__field(u8, timecode_frames)
1938c2ecf20Sopenharmony_ci		__field(u8, timecode_seconds)
1948c2ecf20Sopenharmony_ci		__field(u8, timecode_minutes)
1958c2ecf20Sopenharmony_ci		__field(u8, timecode_hours)
1968c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits0)
1978c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits1)
1988c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits2)
1998c2ecf20Sopenharmony_ci		__field(u8, timecode_userbits3)
2008c2ecf20Sopenharmony_ci		__field(u32, sequence)
2018c2ecf20Sopenharmony_ci	),
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	TP_fast_assign(
2048c2ecf20Sopenharmony_ci		struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
2058c2ecf20Sopenharmony_ci		struct v4l2_fh *owner = q->owner;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci		__entry->minor = owner ? owner->vdev->minor : -1;
2088c2ecf20Sopenharmony_ci		__entry->flags = vbuf->flags;
2098c2ecf20Sopenharmony_ci		__entry->field = vbuf->field;
2108c2ecf20Sopenharmony_ci		__entry->timestamp = vb->timestamp;
2118c2ecf20Sopenharmony_ci		__entry->timecode_type = vbuf->timecode.type;
2128c2ecf20Sopenharmony_ci		__entry->timecode_flags = vbuf->timecode.flags;
2138c2ecf20Sopenharmony_ci		__entry->timecode_frames = vbuf->timecode.frames;
2148c2ecf20Sopenharmony_ci		__entry->timecode_seconds = vbuf->timecode.seconds;
2158c2ecf20Sopenharmony_ci		__entry->timecode_minutes = vbuf->timecode.minutes;
2168c2ecf20Sopenharmony_ci		__entry->timecode_hours = vbuf->timecode.hours;
2178c2ecf20Sopenharmony_ci		__entry->timecode_userbits0 = vbuf->timecode.userbits[0];
2188c2ecf20Sopenharmony_ci		__entry->timecode_userbits1 = vbuf->timecode.userbits[1];
2198c2ecf20Sopenharmony_ci		__entry->timecode_userbits2 = vbuf->timecode.userbits[2];
2208c2ecf20Sopenharmony_ci		__entry->timecode_userbits3 = vbuf->timecode.userbits[3];
2218c2ecf20Sopenharmony_ci		__entry->sequence = vbuf->sequence;
2228c2ecf20Sopenharmony_ci	),
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	TP_printk("minor=%d flags = %s, field = %s, "
2258c2ecf20Sopenharmony_ci		  "timestamp = %llu, timecode = { type = %s, flags = %s, "
2268c2ecf20Sopenharmony_ci		  "frames = %u, seconds = %u, minutes = %u, hours = %u, "
2278c2ecf20Sopenharmony_ci		  "userbits = { %u %u %u %u } }, sequence = %u", __entry->minor,
2288c2ecf20Sopenharmony_ci		  show_flags(__entry->flags),
2298c2ecf20Sopenharmony_ci		  show_field(__entry->field),
2308c2ecf20Sopenharmony_ci		  __entry->timestamp,
2318c2ecf20Sopenharmony_ci		  show_timecode_type(__entry->timecode_type),
2328c2ecf20Sopenharmony_ci		  show_timecode_flags(__entry->timecode_flags),
2338c2ecf20Sopenharmony_ci		  __entry->timecode_frames,
2348c2ecf20Sopenharmony_ci		  __entry->timecode_seconds,
2358c2ecf20Sopenharmony_ci		  __entry->timecode_minutes,
2368c2ecf20Sopenharmony_ci		  __entry->timecode_hours,
2378c2ecf20Sopenharmony_ci		  __entry->timecode_userbits0,
2388c2ecf20Sopenharmony_ci		  __entry->timecode_userbits1,
2398c2ecf20Sopenharmony_ci		  __entry->timecode_userbits2,
2408c2ecf20Sopenharmony_ci		  __entry->timecode_userbits3,
2418c2ecf20Sopenharmony_ci		  __entry->sequence
2428c2ecf20Sopenharmony_ci	)
2438c2ecf20Sopenharmony_ci)
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ciDEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_buf_done,
2468c2ecf20Sopenharmony_ci	TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb),
2478c2ecf20Sopenharmony_ci	TP_ARGS(q, vb)
2488c2ecf20Sopenharmony_ci);
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ciDEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_buf_queue,
2518c2ecf20Sopenharmony_ci	TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb),
2528c2ecf20Sopenharmony_ci	TP_ARGS(q, vb)
2538c2ecf20Sopenharmony_ci);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ciDEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_dqbuf,
2568c2ecf20Sopenharmony_ci	TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb),
2578c2ecf20Sopenharmony_ci	TP_ARGS(q, vb)
2588c2ecf20Sopenharmony_ci);
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ciDEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_qbuf,
2618c2ecf20Sopenharmony_ci	TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb),
2628c2ecf20Sopenharmony_ci	TP_ARGS(q, vb)
2638c2ecf20Sopenharmony_ci);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci#endif /* if !defined(_TRACE_V4L2_H) || defined(TRACE_HEADER_MULTI_READ) */
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci/* This part must be outside protection */
2688c2ecf20Sopenharmony_ci#include <trace/define_trace.h>
269