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