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_FRAME_PUBLIC_H
8 #define __IA_CSS_FRAME_PUBLIC_H
9
10 /* @file
11 * This file contains structs to describe various frame-formats supported by the ISP.
12 */
13
14 #include <media/videobuf2-v4l2.h>
15 #include <type_support.h>
16 #include "ia_css_err.h"
17 #include "ia_css_types.h"
18 #include "ia_css_frame_format.h"
19 #include "ia_css_buffer.h"
20
21 /* For RAW input, the bayer order needs to be specified separately. There
22 * are 4 possible orders. The name is constructed by taking the first two
23 * colors on the first line and the first two colors from the second line.
24 */
25 enum ia_css_bayer_order {
26 IA_CSS_BAYER_ORDER_GRBG, /** GRGRGRGRGR .. BGBGBGBGBG */
27 IA_CSS_BAYER_ORDER_RGGB, /** RGRGRGRGRG .. GBGBGBGBGB */
28 IA_CSS_BAYER_ORDER_BGGR, /** BGBGBGBGBG .. GRGRGRGRGR */
29 IA_CSS_BAYER_ORDER_GBRG, /** GBGBGBGBGB .. RGRGRGRGRG */
30 };
31
32 #define IA_CSS_BAYER_ORDER_NUM (IA_CSS_BAYER_ORDER_GBRG + 1)
33
34 /* Frame plane structure. This describes one plane in an image
35 * frame buffer.
36 */
37 struct ia_css_frame_plane {
38 unsigned int height; /** height of a plane in lines */
39 unsigned int width; /** width of a line, in DMA elements, note that
40 for RGB565 the three subpixels are stored in
41 one element. For all other formats this is
42 the number of subpixels per line. */
43 unsigned int stride; /** stride of a line in bytes */
44 unsigned int offset; /** offset in bytes to start of frame data.
45 offset is wrt data field in ia_css_frame */
46 };
47
48 /* Binary "plane". This is used to story binary streams such as jpeg
49 * images. This is not actually a real plane.
50 */
51 struct ia_css_frame_binary_plane {
52 unsigned int size; /** number of bytes in the stream */
53 struct ia_css_frame_plane data; /** plane */
54 };
55
56 /* Container for planar YUV frames. This contains 3 planes.
57 */
58 struct ia_css_frame_yuv_planes {
59 struct ia_css_frame_plane y; /** Y plane */
60 struct ia_css_frame_plane u; /** U plane */
61 struct ia_css_frame_plane v; /** V plane */
62 };
63
64 /* Container for semi-planar YUV frames.
65 */
66 struct ia_css_frame_nv_planes {
67 struct ia_css_frame_plane y; /** Y plane */
68 struct ia_css_frame_plane uv; /** UV plane */
69 };
70
71 /* Container for planar RGB frames. Each color has its own plane.
72 */
73 struct ia_css_frame_rgb_planes {
74 struct ia_css_frame_plane r; /** Red plane */
75 struct ia_css_frame_plane g; /** Green plane */
76 struct ia_css_frame_plane b; /** Blue plane */
77 };
78
79 /* Container for 6-plane frames. These frames are used internally
80 * in the advanced ISP only.
81 */
82 struct ia_css_frame_plane6_planes {
83 struct ia_css_frame_plane r; /** Red plane */
84 struct ia_css_frame_plane r_at_b; /** Red at blue plane */
85 struct ia_css_frame_plane gr; /** Red-green plane */
86 struct ia_css_frame_plane gb; /** Blue-green plane */
87 struct ia_css_frame_plane b; /** Blue plane */
88 struct ia_css_frame_plane b_at_r; /** Blue at red plane */
89 };
90
91 /* Crop info struct - stores the lines to be cropped in isp */
92 struct ia_css_crop_info {
93 /* the final start column and start line
94 * sum of lines to be cropped + bayer offset
95 */
96 unsigned int start_column;
97 unsigned int start_line;
98 };
99
100 /* Frame info struct. This describes the contents of an image frame buffer.
101 */
102 struct ia_css_frame_info {
103 struct ia_css_resolution res; /** Frame resolution (valid data) */
104 unsigned int padded_width; /** stride of line in memory (in pixels) */
105 enum ia_css_frame_format format; /** format of the frame data */
106 unsigned int raw_bit_depth; /** number of valid bits per pixel,
107 only valid for RAW bayer frames */
108 enum ia_css_bayer_order raw_bayer_order; /** bayer order, only valid
109 for RAW bayer frames */
110 /* the params below are computed based on bayer_order
111 * we can remove the raw_bayer_order if it is redundant
112 * keeping it for now as bxt and fpn code seem to use it
113 */
114 struct ia_css_crop_info crop_info;
115 };
116
117 #define IA_CSS_BINARY_DEFAULT_FRAME_INFO { \
118 .format = IA_CSS_FRAME_FORMAT_NUM, \
119 .raw_bayer_order = IA_CSS_BAYER_ORDER_NUM, \
120 }
121
122 /**
123 * Specifies the DVS loop delay in "frame periods"
124 */
125 enum ia_css_frame_delay {
126 IA_CSS_FRAME_DELAY_0, /** Frame delay = 0 */
127 IA_CSS_FRAME_DELAY_1, /** Frame delay = 1 */
128 IA_CSS_FRAME_DELAY_2 /** Frame delay = 2 */
129 };
130
131 /* Frame structure. This structure describes an image buffer or frame.
132 * This is the main structure used for all input and output images.
133 */
134 struct ia_css_frame {
135 /*
136 * The videobuf2 core will allocate buffers including room for private
137 * data (the rest of struct ia_css_frame). The vb2_v4l2_buffer must
138 * be the first member for this to work!
139 * Note the atomisp code also uses ia_css_frame-s which are not used
140 * as v4l2-buffers in some places. In this case the vb2 member will
141 * be unused.
142 */
143 struct vb2_v4l2_buffer vb;
144 /* List-head for linking into the activeq or buffers_waiting_for_param list */
145 struct list_head queue;
146 struct ia_css_frame_info frame_info; /** info struct describing the frame */
147 ia_css_ptr data; /** pointer to start of image data */
148 unsigned int data_bytes; /** size of image data in bytes */
149 /* LA: move this to ia_css_buffer */
150 /*
151 * -1 if data address is static during life time of pipeline
152 * >=0 if data address can change per pipeline/frame iteration
153 * index to dynamic data: ia_css_frame_in, ia_css_frame_out
154 * ia_css_frame_out_vf
155 * index to host-sp queue id: queue_0, queue_1 etc.
156 */
157 int dynamic_queue_id;
158 /*
159 * if it is dynamic frame, buf_type indicates which buffer type it
160 * should use for event generation. we have this because in vf_pp
161 * binary, we use output port, but we expect VF_OUTPUT_DONE event
162 */
163 enum ia_css_buffer_type buf_type;
164 unsigned int exp_id;
165 /** exposure id, see ia_css_event_public.h for more detail */
166 u32 isp_config_id; /** Unique ID to track which config was actually applied to a particular frame */
167 bool valid; /** First video output frame is not valid */
168 union {
169 unsigned int _initialisation_dummy;
170 struct ia_css_frame_plane raw;
171 struct ia_css_frame_plane rgb;
172 struct ia_css_frame_rgb_planes planar_rgb;
173 struct ia_css_frame_plane yuyv;
174 struct ia_css_frame_yuv_planes yuv;
175 struct ia_css_frame_nv_planes nv;
176 struct ia_css_frame_plane6_planes plane6;
177 struct ia_css_frame_binary_plane binary;
178 } planes; /** frame planes, select the right one based on
179 info.format */
180 };
181
182 #define vb_to_frame(vb2) \
183 container_of(to_vb2_v4l2_buffer(vb2), struct ia_css_frame, vb)
184
185 #define DEFAULT_FRAME { \
186 .frame_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
187 .dynamic_queue_id = SH_CSS_INVALID_QUEUE_ID, \
188 .buf_type = IA_CSS_BUFFER_TYPE_INVALID, \
189 }
190
191 /* @brief Allocate a CSS frame structure
192 *
193 * @param frame The allocated frame.
194 * @param width The width (in pixels) of the frame.
195 * @param height The height (in lines) of the frame.
196 * @param format The frame format.
197 * @param stride The padded stride, in pixels.
198 * @param raw_bit_depth The raw bit depth, in bits.
199 * @return The error code.
200 *
201 * Allocate a CSS frame structure. The memory for the frame data will be
202 * allocated in the CSS address space.
203 */
204 int
205 ia_css_frame_allocate(struct ia_css_frame **frame,
206 unsigned int width,
207 unsigned int height,
208 enum ia_css_frame_format format,
209 unsigned int stride,
210 unsigned int raw_bit_depth);
211
212 /* @brief Initialize a CSS frame structure using a frame info structure.
213 *
214 * @param frame The allocated frame.
215 * @param[in] info The frame info structure.
216 * @return The error code.
217 *
218 * Initialize a frame using the resolution and format from a frame info struct.
219 */
220 int ia_css_frame_init_from_info(struct ia_css_frame *frame,
221 const struct ia_css_frame_info *info);
222
223 /* @brief Allocate a CSS frame structure using a frame info structure.
224 *
225 * @param frame The allocated frame.
226 * @param[in] info The frame info structure.
227 * @return The error code.
228 *
229 * Allocate a frame using the resolution and format from a frame info struct.
230 * This is a convenience function, implemented on top of
231 * ia_css_frame_allocate().
232 */
233 int
234 ia_css_frame_allocate_from_info(struct ia_css_frame **frame,
235 const struct ia_css_frame_info *info);
236 /* @brief Free a CSS frame structure.
237 *
238 * @param[in] frame Pointer to the frame.
239 * @return None
240 *
241 * Free a CSS frame structure. This will free both the frame structure
242 * and the pixel data pointer contained within the frame structure.
243 */
244 void
245 ia_css_frame_free(struct ia_css_frame *frame);
246
247 static inline const struct ia_css_frame_info *
ia_css_frame_get_info(const struct ia_css_frame * frame)248 ia_css_frame_get_info(const struct ia_css_frame *frame)
249 {
250 return frame ? &frame->frame_info : NULL;
251 }
252
253 #endif /* __IA_CSS_FRAME_PUBLIC_H */
254