GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / ia_css_frame_public.h
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #ifndef __IA_CSS_FRAME_PUBLIC_H
16 #define __IA_CSS_FRAME_PUBLIC_H
17
18 /** @file
19  * This file contains structs to describe various frame-formats supported by the ISP.
20  */
21
22 #include <type_support.h>
23 #include "ia_css_err.h"
24 #include "ia_css_types.h"
25 #include "ia_css_frame_format.h"
26 #include "ia_css_buffer.h"
27
28 /** For RAW input, the bayer order needs to be specified separately. There
29  *  are 4 possible orders. The name is constructed by taking the first two
30  *  colors on the first line and the first two colors from the second line.
31  */
32 enum ia_css_bayer_order {
33         IA_CSS_BAYER_ORDER_GRBG, /**< GRGRGRGRGR .. BGBGBGBGBG */
34         IA_CSS_BAYER_ORDER_RGGB, /**< RGRGRGRGRG .. GBGBGBGBGB */
35         IA_CSS_BAYER_ORDER_BGGR, /**< BGBGBGBGBG .. GRGRGRGRGR */
36         IA_CSS_BAYER_ORDER_GBRG, /**< GBGBGBGBGB .. RGRGRGRGRG */
37 };
38 #define IA_CSS_BAYER_ORDER_NUM (IA_CSS_BAYER_ORDER_GBRG + 1)
39
40 /** Frame plane structure. This describes one plane in an image
41  *  frame buffer.
42  */
43 struct ia_css_frame_plane {
44         unsigned int height; /**< height of a plane in lines */
45         unsigned int width;  /**< width of a line, in DMA elements, note that
46                                   for RGB565 the three subpixels are stored in
47                                   one element. For all other formats this is
48                                   the number of subpixels per line. */
49         unsigned int stride; /**< stride of a line in bytes */
50         unsigned int offset; /**< offset in bytes to start of frame data.
51                                   offset is wrt data field in ia_css_frame */
52 };
53
54 /** Binary "plane". This is used to story binary streams such as jpeg
55  *  images. This is not actually a real plane.
56  */
57 struct ia_css_frame_binary_plane {
58         unsigned int              size; /**< number of bytes in the stream */
59         struct ia_css_frame_plane data; /**< plane */
60 };
61
62 /** Container for planar YUV frames. This contains 3 planes.
63  */
64 struct ia_css_frame_yuv_planes {
65         struct ia_css_frame_plane y; /**< Y plane */
66         struct ia_css_frame_plane u; /**< U plane */
67         struct ia_css_frame_plane v; /**< V plane */
68 };
69
70 /** Container for semi-planar YUV frames.
71   */
72 struct ia_css_frame_nv_planes {
73         struct ia_css_frame_plane y;  /**< Y plane */
74         struct ia_css_frame_plane uv; /**< UV plane */
75 };
76
77 /** Container for planar RGB frames. Each color has its own plane.
78  */
79 struct ia_css_frame_rgb_planes {
80         struct ia_css_frame_plane r; /**< Red plane */
81         struct ia_css_frame_plane g; /**< Green plane */
82         struct ia_css_frame_plane b; /**< Blue plane */
83 };
84
85 /** Container for 6-plane frames. These frames are used internally
86  *  in the advanced ISP only.
87  */
88 struct ia_css_frame_plane6_planes {
89         struct ia_css_frame_plane r;      /**< Red plane */
90         struct ia_css_frame_plane r_at_b; /**< Red at blue plane */
91         struct ia_css_frame_plane gr;     /**< Red-green plane */
92         struct ia_css_frame_plane gb;     /**< Blue-green plane */
93         struct ia_css_frame_plane b;      /**< Blue plane */
94         struct ia_css_frame_plane b_at_r; /**< Blue at red plane */
95 };
96
97 /* Crop info struct - stores the lines to be cropped in isp */
98 struct ia_css_crop_info {
99         /* the final start column and start line
100          * sum of lines to be cropped + bayer offset
101          */
102         unsigned int start_column;
103         unsigned int start_line;
104 };
105
106 /** Frame info struct. This describes the contents of an image frame buffer.
107   */
108 struct ia_css_frame_info {
109         struct ia_css_resolution res; /**< Frame resolution (valid data) */
110         unsigned int padded_width; /**< stride of line in memory (in pixels) */
111         enum ia_css_frame_format format; /**< format of the frame data */
112         unsigned int raw_bit_depth; /**< number of valid bits per pixel,
113                                          only valid for RAW bayer frames */
114         enum ia_css_bayer_order raw_bayer_order; /**< bayer order, only valid
115                                                       for RAW bayer frames */
116         /* the params below are computed based on bayer_order
117          * we can remove the raw_bayer_order if it is redundant
118          * keeping it for now as bxt and fpn code seem to use it
119          */
120         struct ia_css_crop_info crop_info;
121 };
122
123 #define IA_CSS_BINARY_DEFAULT_FRAME_INFO \
124 { \
125         {0,                      /* width */ \
126          0},                     /* height */ \
127         0,                       /* padded_width */ \
128         IA_CSS_FRAME_FORMAT_NUM, /* format */ \
129         0,                       /* raw_bit_depth */ \
130         IA_CSS_BAYER_ORDER_NUM,  /* raw_bayer_order */ \
131         {0,                       /*start col */ \
132          0},                       /*start line */ \
133 }
134
135 /**
136  *  Specifies the DVS loop delay in "frame periods"
137  */
138 enum ia_css_frame_delay {
139         IA_CSS_FRAME_DELAY_0, /**< Frame delay = 0 */
140         IA_CSS_FRAME_DELAY_1, /**< Frame delay = 1 */
141         IA_CSS_FRAME_DELAY_2  /**< Frame delay = 2 */
142 };
143
144 enum ia_css_frame_flash_state {
145         IA_CSS_FRAME_FLASH_STATE_NONE,
146         IA_CSS_FRAME_FLASH_STATE_PARTIAL,
147         IA_CSS_FRAME_FLASH_STATE_FULL
148 };
149
150 /** Frame structure. This structure describes an image buffer or frame.
151  *  This is the main structure used for all input and output images.
152  */
153 struct ia_css_frame {
154         struct ia_css_frame_info info; /**< info struct describing the frame */
155         ia_css_ptr   data;             /**< pointer to start of image data */
156         unsigned int data_bytes;       /**< size of image data in bytes */
157         /* LA: move this to ia_css_buffer */
158         /*
159          * -1 if data address is static during life time of pipeline
160          * >=0 if data address can change per pipeline/frame iteration
161          *     index to dynamic data: ia_css_frame_in, ia_css_frame_out
162          *                            ia_css_frame_out_vf
163          *     index to host-sp queue id: queue_0, queue_1 etc.
164          */
165         int dynamic_queue_id;
166         /*
167          * if it is dynamic frame, buf_type indicates which buffer type it
168          * should use for event generation. we have this because in vf_pp
169          * binary, we use output port, but we expect VF_OUTPUT_DONE event
170          */
171         enum ia_css_buffer_type buf_type;
172         enum ia_css_frame_flash_state flash_state;
173         unsigned int exp_id;
174         /**< exposure id, see ia_css_event_public.h for more detail */
175         uint32_t isp_config_id; /**< Unique ID to track which config was actually applied to a particular frame */
176         bool valid; /**< First video output frame is not valid */
177         bool contiguous; /**< memory is allocated physically contiguously */
178         union {
179                 unsigned int    _initialisation_dummy;
180                 struct ia_css_frame_plane raw;
181                 struct ia_css_frame_plane rgb;
182                 struct ia_css_frame_rgb_planes planar_rgb;
183                 struct ia_css_frame_plane yuyv;
184                 struct ia_css_frame_yuv_planes yuv;
185                 struct ia_css_frame_nv_planes nv;
186                 struct ia_css_frame_plane6_planes plane6;
187                 struct ia_css_frame_binary_plane binary;
188         } planes; /**< frame planes, select the right one based on
189                        info.format */
190 };
191
192 #define DEFAULT_FRAME \
193 { \
194         IA_CSS_BINARY_DEFAULT_FRAME_INFO,       /* info */ \
195         0,                                      /* data */ \
196         0,                                      /* data_bytes */ \
197         SH_CSS_INVALID_QUEUE_ID,                /* dynamic_data_index */ \
198         IA_CSS_BUFFER_TYPE_INVALID,                     /* buf_type */ \
199         IA_CSS_FRAME_FLASH_STATE_NONE,          /* flash_state */ \
200         0,                                      /* exp_id */ \
201         0,                                      /* isp_config_id */ \
202         false,                                  /* valid */ \
203         false,                                  /* contiguous  */ \
204         { 0 }                                   /* planes */ \
205 }
206
207 /** @brief Fill a frame with zeros
208  *
209  * @param       frame           The frame.
210  * @return      None
211  *
212  * Fill a frame with pixel values of zero
213  */
214 void ia_css_frame_zero(struct ia_css_frame *frame);
215
216 /** @brief Allocate a CSS frame structure
217  *
218  * @param       frame           The allocated frame.
219  * @param       width           The width (in pixels) of the frame.
220  * @param       height          The height (in lines) of the frame.
221  * @param       format          The frame format.
222  * @param       stride          The padded stride, in pixels.
223  * @param       raw_bit_depth   The raw bit depth, in bits.
224  * @return                      The error code.
225  *
226  * Allocate a CSS frame structure. The memory for the frame data will be
227  * allocated in the CSS address space.
228  */
229 enum ia_css_err
230 ia_css_frame_allocate(struct ia_css_frame **frame,
231                       unsigned int width,
232                       unsigned int height,
233                       enum ia_css_frame_format format,
234                       unsigned int stride,
235                       unsigned int raw_bit_depth);
236
237 /** @brief Allocate a CSS frame structure using a frame info structure.
238  *
239  * @param       frame   The allocated frame.
240  * @param[in]   info    The frame info structure.
241  * @return              The error code.
242  *
243  * Allocate a frame using the resolution and format from a frame info struct.
244  * This is a convenience function, implemented on top of
245  * ia_css_frame_allocate().
246  */
247 enum ia_css_err
248 ia_css_frame_allocate_from_info(struct ia_css_frame **frame,
249                                 const struct ia_css_frame_info *info);
250 /** @brief Free a CSS frame structure.
251  *
252  * @param[in]   frame   Pointer to the frame.
253  * @return      None
254  *
255  * Free a CSS frame structure. This will free both the frame structure
256  * and the pixel data pointer contained within the frame structure.
257  */
258 void
259 ia_css_frame_free(struct ia_css_frame *frame);
260
261 /** @brief Allocate a contiguous CSS frame structure
262  *
263  * @param       frame           The allocated frame.
264  * @param       width           The width (in pixels) of the frame.
265  * @param       height          The height (in lines) of the frame.
266  * @param       format          The frame format.
267  * @param       stride          The padded stride, in pixels.
268  * @param       raw_bit_depth   The raw bit depth, in bits.
269  * @return                      The error code.
270  *
271  * Contiguous frame allocation, only for FPGA display driver which needs
272  * physically contiguous memory.
273  * Deprecated.
274  */
275 enum ia_css_err
276 ia_css_frame_allocate_contiguous(struct ia_css_frame **frame,
277                                  unsigned int width,
278                                  unsigned int height,
279                                  enum ia_css_frame_format format,
280                                  unsigned int stride,
281                                  unsigned int raw_bit_depth);
282
283 /** @brief Allocate a contiguous CSS frame from a frame info structure.
284  *
285  * @param       frame   The allocated frame.
286  * @param[in]   info    The frame info structure.
287  * @return              The error code.
288  *
289  * Allocate a frame using the resolution and format from a frame info struct.
290  * This is a convenience function, implemented on top of
291  * ia_css_frame_allocate_contiguous().
292  * Only for FPGA display driver which needs physically contiguous memory.
293  * Deprecated.
294  */
295 enum ia_css_err
296 ia_css_frame_allocate_contiguous_from_info(struct ia_css_frame **frame,
297                                           const struct ia_css_frame_info *info);
298
299 /** @brief Allocate a CSS frame structure using a frame info structure.
300  *
301  * @param       frame   The allocated frame.
302  * @param[in]   info    The frame info structure.
303  * @return              The error code.
304  *
305  * Allocate an empty CSS frame with no data buffer using the parameters
306  * in the frame info.
307  */
308 enum ia_css_err
309 ia_css_frame_create_from_info(struct ia_css_frame **frame,
310         const struct ia_css_frame_info *info);
311
312 /** @brief Set a mapped data buffer to a CSS frame
313  *
314  * @param[in]   frame       Valid CSS frame pointer
315  * @param[in]   mapped_data  Mapped data buffer to be assigned to the CSS frame
316  * @param[in]   data_size_bytes  Size of the mapped_data in bytes
317  * @return      The error code.
318  *
319  * Sets a mapped data buffer to this frame. This function can be called multiple
320  * times with different buffers or NULL to reset the data pointer. This API
321  * would not try free the mapped_data and its the callers responsiblity to
322  * free the mapped_data buffer. However if ia_css_frame_free() is called and
323  * the frame had a valid data buffer, it would be freed along with the frame.
324  */
325 enum ia_css_err
326 ia_css_frame_set_data(struct ia_css_frame *frame,
327         const ia_css_ptr   mapped_data,
328         size_t data_size_bytes);
329
330 /** @brief Map an existing frame data pointer to a CSS frame.
331  *
332  * @param       frame           Pointer to the frame to be initialized
333  * @param[in]   info            The frame info.
334  * @param[in]   data            Pointer to the allocated frame data.
335  * @param[in]   attribute       Attributes to be passed to mmgr_mmap.
336  * @param[in]   context         Pointer to the a context to be passed to mmgr_mmap.
337  * @return                      The allocated frame structure.
338  *
339  * This function maps a pre-allocated pointer into a CSS frame. This can be
340  * used when an upper software layer is responsible for allocating the frame
341  * data and it wants to share that frame pointer with the CSS code.
342  * This function will fill the CSS frame structure just like
343  * ia_css_frame_allocate() does, but instead of allocating the memory, it will
344  * map the pre-allocated memory into the CSS address space.
345  */
346 enum ia_css_err
347 ia_css_frame_map(struct ia_css_frame **frame,
348                  const struct ia_css_frame_info *info,
349                  const void *data,
350                  uint16_t attribute,
351                  void *context);
352
353 /** @brief Unmap a CSS frame structure.
354  *
355  * @param[in]   frame   Pointer to the CSS frame.
356  * @return      None
357  *
358  * This function unmaps the frame data pointer within a CSS frame and
359  * then frees the CSS frame structure. Use this for frame pointers created
360  * using ia_css_frame_map().
361  */
362 void
363 ia_css_frame_unmap(struct ia_css_frame *frame);
364
365 #endif /* __IA_CSS_FRAME_PUBLIC_H */