1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  */
6 
7 #ifndef __IA_CSS_EVENT_PUBLIC_H
8 #define __IA_CSS_EVENT_PUBLIC_H
9 
10 /* @file
11  * This file contains CSS-API events functionality
12  */
13 
14 #include <type_support.h>	/* uint8_t */
15 #include <ia_css_err.h>		/* ia_css_err */
16 #include <ia_css_types.h>	/* ia_css_pipe */
17 #include <ia_css_timer.h>	/* ia_css_timer */
18 #include <linux/bits.h>
19 
20 /* The event type, distinguishes the kind of events that
21  * can are generated by the CSS system.
22  *
23  * !!!IMPORTANT!!! KEEP THE FOLLOWING IN SYNC:
24  * 1) "enum ia_css_event_type"					(ia_css_event_public.h)
25  * 2) "enum sh_css_sp_event_type"				(sh_css_internal.h)
26  * 3) "enum ia_css_event_type event_id_2_event_mask"		(event_handler.sp.c)
27  * 4) "enum ia_css_event_type convert_event_sp_to_host_domain"	(sh_css.c)
28  */
29 enum ia_css_event_type {
30 	IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE		= BIT(0),
31 	/** Output frame ready. */
32 	IA_CSS_EVENT_TYPE_SECOND_OUTPUT_FRAME_DONE	= BIT(1),
33 	/** Second output frame ready. */
34 	IA_CSS_EVENT_TYPE_VF_OUTPUT_FRAME_DONE		= BIT(2),
35 	/** Viewfinder Output frame ready. */
36 	IA_CSS_EVENT_TYPE_SECOND_VF_OUTPUT_FRAME_DONE	= BIT(3),
37 	/** Second viewfinder Output frame ready. */
38 	IA_CSS_EVENT_TYPE_3A_STATISTICS_DONE		= BIT(4),
39 	/** Indication that 3A statistics are available. */
40 	IA_CSS_EVENT_TYPE_DIS_STATISTICS_DONE		= BIT(5),
41 	/** Indication that DIS statistics are available. */
42 	IA_CSS_EVENT_TYPE_PIPELINE_DONE			= BIT(6),
43 	/** Pipeline Done event, sent after last pipeline stage. */
44 	IA_CSS_EVENT_TYPE_FRAME_TAGGED			= BIT(7),
45 	/** Frame tagged. */
46 	IA_CSS_EVENT_TYPE_INPUT_FRAME_DONE		= BIT(8),
47 	/** Input frame ready. */
48 	IA_CSS_EVENT_TYPE_METADATA_DONE			= BIT(9),
49 	/** Metadata ready. */
50 	IA_CSS_EVENT_TYPE_LACE_STATISTICS_DONE		= BIT(10),
51 	/** Indication that LACE statistics are available. */
52 	IA_CSS_EVENT_TYPE_ACC_STAGE_COMPLETE		= BIT(11),
53 	/** Extension stage complete. */
54 	IA_CSS_EVENT_TYPE_TIMER				= BIT(12),
55 	/** Timer event for measuring the SP side latencies. It contains the
56 	     32-bit timer value from the SP */
57 	IA_CSS_EVENT_TYPE_PORT_EOF			= BIT(13),
58 	/** End Of Frame event, sent when in buffered sensor mode. */
59 	IA_CSS_EVENT_TYPE_FW_WARNING			= BIT(14),
60 	/** Performance warning encounter by FW */
61 	IA_CSS_EVENT_TYPE_FW_ASSERT			= BIT(15),
62 	/** Assertion hit by FW */
63 };
64 
65 #define IA_CSS_EVENT_TYPE_NONE 0
66 
67 /* IA_CSS_EVENT_TYPE_ALL is a mask for all pipe related events.
68  * The other events (such as PORT_EOF) cannot be enabled/disabled
69  * and are hence excluded from this macro.
70  */
71 #define IA_CSS_EVENT_TYPE_ALL \
72 	(IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE		| \
73 	 IA_CSS_EVENT_TYPE_SECOND_OUTPUT_FRAME_DONE	| \
74 	 IA_CSS_EVENT_TYPE_VF_OUTPUT_FRAME_DONE		| \
75 	 IA_CSS_EVENT_TYPE_SECOND_VF_OUTPUT_FRAME_DONE	| \
76 	 IA_CSS_EVENT_TYPE_3A_STATISTICS_DONE		| \
77 	 IA_CSS_EVENT_TYPE_DIS_STATISTICS_DONE		| \
78 	 IA_CSS_EVENT_TYPE_PIPELINE_DONE		| \
79 	 IA_CSS_EVENT_TYPE_FRAME_TAGGED			| \
80 	 IA_CSS_EVENT_TYPE_INPUT_FRAME_DONE		| \
81 	 IA_CSS_EVENT_TYPE_METADATA_DONE		| \
82 	 IA_CSS_EVENT_TYPE_LACE_STATISTICS_DONE		| \
83 	 IA_CSS_EVENT_TYPE_ACC_STAGE_COMPLETE)
84 
85 /* The event struct, container for the event type and its related values.
86  * Depending on the event type, either pipe or port will be filled.
87  * Pipeline related events (like buffer/frame events) will return a valid and filled pipe handle.
88  * For non pipeline related events (but i.e. stream specific, like EOF event), the port will be
89  * filled.
90  */
91 struct ia_css_event {
92 	struct ia_css_pipe    *pipe;
93 	/** Pipe handle on which event happened, NULL for non pipe related
94 	     events. */
95 	enum ia_css_event_type type;
96 	/** Type of Event, always valid/filled. */
97 	u8                port;
98 	/** Port number for EOF event (not valid for other events). */
99 	u8                exp_id;
100 	/** Exposure id for EOF/FRAME_TAGGED/FW_WARNING event (not valid for other events)
101 	     The exposure ID is unique only within a logical stream and it is
102 	     only generated on systems that have an input system (such as 2400
103 	     and 2401).
104 	     Most outputs produced by the CSS are tagged with an exposure ID.
105 	     This allows users of the CSS API to keep track of which buffer
106 	     was generated from which sensor output frame. This includes:
107 	     EOF event, output frames, 3A statistics, DVS statistics and
108 	     sensor metadata.
109 	     Exposure IDs start at IA_CSS_MIN_EXPOSURE_ID, increment by one
110 	     until IA_CSS_MAX_EXPOSURE_ID is reached, after that they wrap
111 	     around to IA_CSS_MIN_EXPOSURE_ID again.
112 	     Note that in case frames are dropped, this will not be reflected
113 	     in the exposure IDs. Therefor applications should not use this
114 	     to detect frame drops. */
115 	u32               fw_handle;
116 	/** Firmware Handle for ACC_STAGE_COMPLETE event (not valid for other
117 	     events). */
118 	enum ia_css_fw_warning fw_warning;
119 	/** Firmware warning code, only for WARNING events. */
120 	u8                fw_assert_module_id;
121 	/** Firmware module id, only for ASSERT events, should be logged by driver. */
122 	u16               fw_assert_line_no;
123 	/** Firmware line number, only for ASSERT events, should be logged by driver. */
124 	clock_value_t	       timer_data;
125 	/** For storing the full 32-bit of the timer value. Valid only for TIMER
126 	     event */
127 	u8                timer_code;
128 	/** For storing the code of the TIMER event. Valid only for
129 	     TIMER event */
130 	u8                timer_subcode;
131 	/** For storing the subcode of the TIMER event. Valid only
132 	     for TIMER event */
133 };
134 
135 /* @brief Dequeue a PSYS event from the CSS system.
136  *
137  * @param[out]	event   Pointer to the event struct which will be filled by
138  *                      this function if an event is available.
139  * @return		-ENODATA if no events are
140  *			available or
141  *			0 otherwise.
142  *
143  * This function dequeues an event from the PSYS event queue. The queue is
144  * between the Host CPU and the CSS system. This function can be
145  * called after an interrupt has been generated that signalled that a new event
146  * was available and can be used in a polling-like situation where the NO_EVENT
147  * return value is used to determine whether an event was available or not.
148  */
149 int
150 ia_css_dequeue_psys_event(struct ia_css_event *event);
151 
152 /* @brief Dequeue an ISYS event from the CSS system.
153  *
154  * @param[out]	event   Pointer to the event struct which will be filled by
155  *                      this function if an event is available.
156  * @return		-ENODATA if no events are
157  *			available or
158  *			0 otherwise.
159  *
160  * This function dequeues an event from the ISYS event queue. The queue is
161  * between host and the CSS system.
162  * Unlike the ia_css_dequeue_psys_event() function, this function can be called
163  * directly from an interrupt service routine (ISR) and it is safe to call
164  * this function in parallel with other CSS API functions (but only one
165  * call to this function should be in flight at any point in time).
166  *
167  * The reason for having the ISYS events separate is to prevent them from
168  * incurring additional latency due to locks being held by other CSS API
169  * functions.
170  */
171 int
172 ia_css_dequeue_isys_event(struct ia_css_event *event);
173 
174 #endif /* __IA_CSS_EVENT_PUBLIC_H */
175