2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
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.
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
15 #ifndef __IA_CSS_PIPE_PUBLIC_H
16 #define __IA_CSS_PIPE_PUBLIC_H
19 * This file contains the public interface for CSS pipes.
22 #include <type_support.h>
23 #include <ia_css_err.h>
24 #include <ia_css_types.h>
25 #include <ia_css_frame_public.h>
26 #include <ia_css_buffer.h>
28 #include <ia_css_acc_types.h>
31 IA_CSS_PIPE_OUTPUT_STAGE_0 = 0,
32 IA_CSS_PIPE_OUTPUT_STAGE_1,
33 IA_CSS_PIPE_MAX_OUTPUT_STAGE,
36 /* Enumeration of pipe modes. This mode can be used to create
37 * an image pipe for this mode. These pipes can be combined
38 * to configure and run streams on the ISP.
40 * For example, one can create a preview and capture pipe to
41 * create a continuous capture stream.
43 enum ia_css_pipe_mode {
44 IA_CSS_PIPE_MODE_PREVIEW, /** Preview pipe */
45 IA_CSS_PIPE_MODE_VIDEO, /** Video pipe */
46 IA_CSS_PIPE_MODE_CAPTURE, /** Still capture pipe */
47 IA_CSS_PIPE_MODE_ACC, /** Accelerated pipe */
48 IA_CSS_PIPE_MODE_COPY, /** Copy pipe, only used for embedded/image data copying */
49 IA_CSS_PIPE_MODE_YUVPP, /** YUV post processing pipe, used for all use cases with YUV input,
50 for SoC sensor and external ISP */
53 /* Temporary define */
54 #define IA_CSS_PIPE_MODE_NUM (IA_CSS_PIPE_MODE_YUVPP + 1)
57 * Enumeration of pipe versions.
58 * the order should match with definition in sh_css_defs.h
60 enum ia_css_pipe_version {
61 IA_CSS_PIPE_VERSION_1 = 1, /** ISP1.0 pipe */
62 IA_CSS_PIPE_VERSION_2_2 = 2, /** ISP2.2 pipe */
63 IA_CSS_PIPE_VERSION_2_6_1 = 3, /** ISP2.6.1 pipe */
64 IA_CSS_PIPE_VERSION_2_7 = 4 /** ISP2.7 pipe */
68 * Pipe configuration structure.
69 * Resolution properties are filled by Driver, kernel configurations are
72 struct ia_css_pipe_config {
73 enum ia_css_pipe_mode mode;
74 /** mode, indicates which mode the pipe should use. */
75 enum ia_css_pipe_version isp_pipe_version;
76 /** pipe version, indicates which imaging pipeline the pipe should use. */
77 struct ia_css_resolution input_effective_res;
78 /** input effective resolution */
79 struct ia_css_resolution bayer_ds_out_res;
80 /** bayer down scaling */
81 struct ia_css_resolution capt_pp_in_res;
82 /** capture post processing input resolution */
83 struct ia_css_resolution vf_pp_in_res;
85 /** ISP2401: view finder post processing input resolution */
86 struct ia_css_resolution output_system_in_res;
87 /** For IPU3 only: use output_system_in_res to specify what input resolution
88 will OSYS receive, this resolution is equal to the output resolution of GDC
89 if not determined CSS will set output_system_in_res with main osys output pin resolution
90 All other IPUs may ignore this property */
91 struct ia_css_resolution dvs_crop_out_res;
92 /** dvs crop, video only, not in use yet. Use dvs_envelope below. */
93 struct ia_css_frame_info output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE];
94 /** output of YUV scaling */
95 struct ia_css_frame_info vf_output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE];
96 /** output of VF YUV scaling */
97 struct ia_css_fw_info *acc_extension;
98 /** Pipeline extension accelerator */
99 struct ia_css_fw_info **acc_stages;
100 /** Standalone accelerator stages */
102 /** Number of standalone accelerator stages */
103 struct ia_css_capture_config default_capture_config;
104 /** Default capture config for initial capture pipe configuration. */
105 struct ia_css_resolution dvs_envelope; /** temporary */
106 enum ia_css_frame_delay dvs_frame_delay;
107 /** indicates the DVS loop delay in frame periods */
109 /** For acceleration pipes only: determine how many times the pipe
110 should be run. Setting this to -1 means it will run until
113 /** Disabling digital zoom for a pipeline, if this is set to false,
114 then setting a zoom factor will have no effect.
115 In some use cases this provides better performance. */
117 /** Disabling "Defect Pixel Correction" for a pipeline, if this is set
118 to false. In some use cases this provides better performance. */
119 bool enable_vfpp_bci;
120 /** Enabling BCI mode will cause yuv_scale binary to be picked up
121 instead of vf_pp. This only applies to viewfinder post
122 processing stages. */
125 bool enable_luma_only;
126 /** Enabling of monochrome mode for a pipeline. If enabled only luma processing
129 /** Enabling of TNR (temporal noise reduction). This is only applicable to video
130 pipes. Non video-pipes should always set this parameter to false. */
132 struct ia_css_isp_config *p_isp_config;
133 /** Pointer to ISP configuration */
134 struct ia_css_resolution gdc_in_buffer_res;
135 /** GDC in buffer resolution. */
136 struct ia_css_point gdc_in_buffer_offset;
137 /** GDC in buffer offset - indicates the pixel coordinates of the first valid pixel inside the buffer */
140 struct ia_css_coordinate internal_frame_origin_bqs_on_sctbl;
141 /** Origin of internal frame positioned on shading table at shading correction in ISP.
142 NOTE: Shading table is larger than or equal to internal frame.
143 Shading table has shading gains and internal frame has bayer data.
144 The origin of internal frame is used in shading correction in ISP
145 to retrieve shading gains which correspond to bayer data. */
149 * Default settings for newly created pipe configurations.
151 #define DEFAULT_PIPE_CONFIG \
152 (struct ia_css_pipe_config) { \
153 .mode = IA_CSS_PIPE_MODE_PREVIEW, \
154 .isp_pipe_version = 1, \
155 .output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
156 .vf_output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
157 .default_capture_config = DEFAULT_CAPTURE_CONFIG, \
158 .dvs_frame_delay = IA_CSS_FRAME_DELAY_1, \
159 .acc_num_execs = -1, \
162 /* Pipe info, this struct describes properties of a pipe after it's stream has
164 * ~~~** DO NOT ADD NEW FIELD **~~~ This structure will be deprecated.
165 * - On the Behalf of CSS-API Committee.
167 struct ia_css_pipe_info {
168 struct ia_css_frame_info output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE];
169 /** Info about output resolution. This contains the stride which
170 should be used for memory allocation. */
171 struct ia_css_frame_info vf_output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE];
172 /** Info about viewfinder output resolution (optional). This contains
173 the stride that should be used for memory allocation. */
174 struct ia_css_frame_info raw_output_info;
175 /** Raw output resolution. This indicates the resolution of the
176 RAW bayer output for pipes that support this. Currently, only the
177 still capture pipes support this feature. When this resolution is
178 smaller than the input resolution, cropping will be performed by
179 the ISP. The first cropping that will be performed is on the upper
180 left corner where we crop 8 lines and 8 columns to remove the
181 pixels normally used to initialize the ISP filters.
182 This is why the raw output resolution should normally be set to
183 the input resolution - 8x8. */
185 struct ia_css_resolution output_system_in_res_info;
186 /** For IPU3 only. Info about output system in resolution which is considered
187 as gdc out resolution. */
188 struct ia_css_shading_info shading_info;
189 /** After an image pipe is created, this field will contain the info
190 for the shading correction. */
191 struct ia_css_grid_info grid_info;
192 /** After an image pipe is created, this field will contain the grid
193 info for 3A and DVS. */
194 int num_invalid_frames;
195 /** The very first frames in a started stream do not contain valid data.
196 In this field, the CSS-firmware communicates to the host-driver how
197 many initial frames will contain invalid data; this allows the
198 host-driver to discard those initial invalid frames and start it's
199 output at the first valid frame. */
203 * Defaults for ia_css_pipe_info structs.
205 #define DEFAULT_PIPE_INFO \
206 (struct ia_css_pipe_info) { \
207 .output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
208 .vf_output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
209 .raw_output_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
210 .shading_info = DEFAULT_SHADING_INFO, \
211 .grid_info = DEFAULT_GRID_INFO, \
214 /* @brief Load default pipe configuration
215 * @param[out] pipe_config The pipe configuration.
218 * This function will load the default pipe configuration:
220 struct ia_css_pipe_config def_config = {
221 IA_CSS_PIPE_MODE_PREVIEW, // mode
222 1, // isp_pipe_version
223 {0, 0}, // bayer_ds_out_res
224 {0, 0}, // capt_pp_in_res
225 {0, 0}, // vf_pp_in_res
226 {0, 0}, // dvs_crop_out_res
227 {{0, 0}, 0, 0, 0, 0}, // output_info
228 {{0, 0}, 0, 0, 0, 0}, // second_output_info
229 {{0, 0}, 0, 0, 0, 0}, // vf_output_info
230 {{0, 0}, 0, 0, 0, 0}, // second_vf_output_info
231 NULL, // acc_extension
235 IA_CSS_CAPTURE_MODE_RAW, // mode
237 false // enable_raw_output
238 }, // default_capture_config
239 {0, 0}, // dvs_envelope
240 1, // dvs_frame_delay
243 NULL, // p_isp_config
247 void ia_css_pipe_config_defaults(struct ia_css_pipe_config *pipe_config);
249 /* @brief Create a pipe
250 * @param[in] config The pipe configuration.
251 * @param[out] pipe The pipe.
252 * @return IA_CSS_SUCCESS or the error code.
254 * This function will create a pipe with the given
258 ia_css_pipe_create(const struct ia_css_pipe_config *config,
259 struct ia_css_pipe **pipe);
261 /* @brief Destroy a pipe
262 * @param[in] pipe The pipe.
263 * @return IA_CSS_SUCCESS or the error code.
265 * This function will destroy a given pipe.
268 ia_css_pipe_destroy(struct ia_css_pipe *pipe);
270 /* @brief Provides information about a pipe
271 * @param[in] pipe The pipe.
272 * @param[out] pipe_info The pipe information.
273 * @return IA_CSS_SUCCESS or IA_CSS_ERR_INVALID_ARGUMENTS.
275 * This function will provide information about a given pipe.
278 ia_css_pipe_get_info(const struct ia_css_pipe *pipe,
279 struct ia_css_pipe_info *pipe_info);
281 /* @brief Configure a pipe with filter coefficients.
282 * @param[in] pipe The pipe.
283 * @param[in] config The pointer to ISP configuration.
284 * @return IA_CSS_SUCCESS or error code upon error.
286 * This function configures the filter coefficients for an image
290 ia_css_pipe_set_isp_config(struct ia_css_pipe *pipe,
291 struct ia_css_isp_config *config);
293 /* @brief Controls when the Event generator raises an IRQ to the Host.
295 * @param[in] pipe The pipe.
296 * @param[in] or_mask Binary or of enum ia_css_event_irq_mask_type. Each pipe
297 related event that is part of this mask will directly
298 raise an IRQ to the Host when the event occurs in the
300 * @param[in] and_mask Binary or of enum ia_css_event_irq_mask_type. An event
301 IRQ for the Host is only raised after all pipe related
302 events have occurred at least once for all the active
303 pipes. Events are remembered and don't need to occurred
304 at the same moment in time. There is no control over
305 the order of these events. Once an IRQ has been raised
306 all remembered events are reset.
307 * @return IA_CSS_SUCCESS.
309 Controls when the Event generator in the CSS raises an IRQ to the Host.
310 The main purpose of this function is to reduce the amount of interrupts
311 between the CSS and the Host. This will help saving power as it wakes up the
312 Host less often. In case both or_mask and and_mask are
313 IA_CSS_EVENT_TYPE_NONE for all pipes, no event IRQ's will be raised. An
314 exception holds for IA_CSS_EVENT_TYPE_PORT_EOF, for this event an IRQ is always
316 Note that events are still queued and the Host can poll for them. The
317 or_mask and and_mask may be active at the same time\n
319 Default values, for all pipe id's, after ia_css_init:\n
320 or_mask = IA_CSS_EVENT_TYPE_ALL\n
321 and_mask = IA_CSS_EVENT_TYPE_NONE\n
325 ia_css_pipe_set_irq_mask(h_pipe,
326 IA_CSS_EVENT_TYPE_3A_STATISTICS_DONE |
327 IA_CSS_EVENT_TYPE_DIS_STATISTICS_DONE ,
328 IA_CSS_EVENT_TYPE_NONE);
330 The event generator will only raise an interrupt to the Host when there are
331 3A or DIS statistics available from the preview pipe. It will not generate
332 an interrupt for any other event of the preview pipe e.g when there is an
333 output frame available.
336 ia_css_pipe_set_irq_mask(h_pipe_preview,
337 IA_CSS_EVENT_TYPE_NONE,
338 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE |
339 IA_CSS_EVENT_TYPE_3A_STATISTICS_DONE );
341 ia_css_pipe_set_irq_mask(h_pipe_capture,
342 IA_CSS_EVENT_TYPE_NONE,
343 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE );
345 The event generator will only raise an interrupt to the Host when there is
346 both a frame done and 3A event available from the preview pipe AND when there
347 is a frame done available from the capture pipe. Note that these events
348 may occur at different moments in time. Also the order of the events is not
352 ia_css_pipe_set_irq_mask(h_pipe_preview,
353 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE,
354 IA_CSS_EVENT_TYPE_ALL );
356 ia_css_pipe_set_irq_mask(h_pipe_capture,
357 IA_CSS_EVENT_TYPE_OUTPUT_FRAME_DONE,
358 IA_CSS_EVENT_TYPE_ALL );
360 The event generator will only raise an interrupt to the Host when there is an
361 output frame from the preview pipe OR an output frame from the capture pipe.
362 All other events (3A, VF output, pipeline done) will not raise an interrupt
363 to the Host. These events are not lost but always stored in the event queue.
366 ia_css_pipe_set_irq_mask(struct ia_css_pipe *pipe,
367 unsigned int or_mask,
368 unsigned int and_mask);
370 /* @brief Reads the current event IRQ mask from the CSS.
372 * @param[in] pipe The pipe.
373 * @param[out] or_mask Current or_mask. The bits in this mask are a binary or
374 of enum ia_css_event_irq_mask_type. Pointer may be NULL.
375 * @param[out] and_mask Current and_mask.The bits in this mask are a binary or
376 of enum ia_css_event_irq_mask_type. Pointer may be NULL.
377 * @return IA_CSS_SUCCESS.
379 Reads the current event IRQ mask from the CSS. Reading returns the actual
380 values as used by the SP and not any mirrored values stored at the Host.\n
383 SP must be running.\n
387 ia_css_event_get_irq_mask(const struct ia_css_pipe *pipe,
388 unsigned int *or_mask,
389 unsigned int *and_mask);
391 /* @brief Queue a buffer for an image pipe.
393 * @param[in] pipe The pipe that will own the buffer.
394 * @param[in] buffer Pointer to the buffer.
395 * Note that the caller remains owner of the buffer
396 * structure. Only the data pointer within it will
397 * be passed into the internal queues.
398 * @return IA_CSS_INTERNAL_ERROR in case of unexpected errors,
399 * IA_CSS_SUCCESS otherwise.
401 * This function adds a buffer (which has a certain buffer type) to the queue
402 * for this type. This queue is owned by the image pipe. After this function
403 * completes successfully, the buffer is now owned by the image pipe and should
404 * no longer be accessed by any other code until it gets dequeued. The image
405 * pipe will dequeue buffers from this queue, use them and return them to the
406 * host code via an interrupt. Buffers will be consumed in the same order they
407 * get queued, but may be returned to the host out of order.
410 ia_css_pipe_enqueue_buffer(struct ia_css_pipe *pipe,
411 const struct ia_css_buffer *buffer);
413 /* @brief Dequeue a buffer from an image pipe.
415 * @param[in] pipe The pipeline that the buffer queue belongs to.
416 * @param[in,out] buffer The buffer is used to lookup the type which determines
417 * which internal queue to use.
418 * The resulting buffer pointer is written into the dta
420 * @return IA_CSS_ERR_NO_BUFFER if the queue is empty or
421 * IA_CSS_SUCCESS otherwise.
423 * This function dequeues a buffer from a buffer queue. The queue is indicated
424 * by the buffer type argument. This function can be called after an interrupt
425 * has been generated that signalled that a new buffer was available and can
426 * be used in a polling-like situation where the NO_BUFFER return value is used
427 * to determine whether a buffer was available or not.
430 ia_css_pipe_dequeue_buffer(struct ia_css_pipe *pipe,
431 struct ia_css_buffer *buffer);
433 /* @brief Set the state (Enable or Disable) of the Extension stage in the
435 * @param[in] pipe Pipe handle.
436 * @param[in] fw_handle Extension firmware Handle (ia_css_fw_info.handle)
437 * @param[in] enable Enable Flag (1 to enable ; 0 to disable)
440 * IA_CSS_SUCCESS : Success
441 * IA_CSS_ERR_INVALID_ARGUMENTS : Invalid Parameters
442 * IA_CSS_ERR_RESOURCE_NOT_AVAILABLE : Inactive QOS Pipe
443 * (No active stream with this pipe)
445 * This function will request state change (enable or disable) for the Extension
446 * stage (firmware handle) in the given pipe.
449 * 1. Extension can be enabled/disabled only on QOS Extensions
450 * 2. Extension can be enabled/disabled only with an active QOS Pipe
451 * 3. Initial(Default) state of QOS Extensions is Disabled
452 * 4. State change cannot be guaranteed immediately OR on frame boundary
456 ia_css_pipe_set_qos_ext_state(struct ia_css_pipe *pipe,
460 /* @brief Get the state (Enable or Disable) of the Extension stage in the
462 * @param[in] pipe Pipe handle.
463 * @param[in] fw_handle Extension firmware Handle (ia_css_fw_info.handle)
464 * @param[out] *enable Enable Flag
467 * IA_CSS_SUCCESS : Success
468 * IA_CSS_ERR_INVALID_ARGUMENTS : Invalid Parameters
469 * IA_CSS_ERR_RESOURCE_NOT_AVAILABLE : Inactive QOS Pipe
470 * (No active stream with this pipe)
472 * This function will query the state of the Extension stage (firmware handle)
476 * 1. Extension state can be queried only on QOS Extensions
477 * 2. Extension can be enabled/disabled only with an active QOS Pipe
478 * 3. Initial(Default) state of QOS Extensions is Disabled.
482 ia_css_pipe_get_qos_ext_state(struct ia_css_pipe *pipe,
487 /* @brief Update mapped CSS and ISP arguments for QoS pipe during SP runtime.
488 * @param[in] pipe Pipe handle.
489 * @param[in] fw_handle Extension firmware Handle (ia_css_fw_info.handle).
490 * @param[in] css_seg Parameter memory descriptors for CSS segments.
491 * @param[in] isp_seg Parameter memory descriptors for ISP segments.
494 * IA_CSS_SUCCESS : Success
495 * IA_CSS_ERR_INVALID_ARGUMENTS : Invalid Parameters
496 * IA_CSS_ERR_RESOURCE_NOT_AVAILABLE : Inactive QOS Pipe
497 * (No active stream with this pipe)
499 * \deprecated{This interface is used to temporarily support a late-developed,
500 * specific use-case on a specific IPU2 platform. It will not be supported or
501 * maintained on IPU3 or further.}
504 ia_css_pipe_update_qos_ext_mapped_arg(struct ia_css_pipe *pipe,
506 struct ia_css_isp_param_css_segments *css_seg,
507 struct ia_css_isp_param_isp_segments *isp_seg);
509 /* @brief Get selected configuration settings
510 * @param[in] pipe The pipe.
511 * @param[out] config Configuration settings.
515 ia_css_pipe_get_isp_config(struct ia_css_pipe *pipe,
516 struct ia_css_isp_config *config);
518 /* @brief Set the scaler lut on this pipe. A copy of lut is made in the inuit
519 * address space. So the LUT can be freed by caller.
520 * @param[in] pipe Pipe handle.
521 * @param[in] lut Look up tabel
524 * IA_CSS_SUCCESS : Success
525 * IA_CSS_ERR_INVALID_ARGUMENTS : Invalid Parameters
528 * 1) Note that both GDC's are programmed with the same table.
529 * 2) Current implementation ignores the pipe and overrides the
530 * global lut. This will be fixed in the future
531 * 3) This function must be called before stream start
535 ia_css_pipe_set_bci_scaler_lut(struct ia_css_pipe *pipe,
537 /* @brief Checking of DVS statistics ability
538 * @param[in] pipe_info The pipe info.
539 * @return true - has DVS statistics ability
542 bool ia_css_pipe_has_dvs_stats(struct ia_css_pipe_info *pipe_info);
545 /* @brief Override the frameformat set on the output pins.
546 * @param[in] pipe Pipe handle.
547 * @param[in] output_pin Pin index to set the format on
548 * 0 - main output pin
549 * 1 - display output pin
550 * @param[in] format Format to set
553 * IA_CSS_SUCCESS : Success
554 * IA_CSS_ERR_INVALID_ARGUMENTS : Invalid Parameters
555 * IA_CSS_ERR_INTERNAL_ERROR : Pipe misses binary info
558 * 1) This is an optional function to override the formats set in the pipe.
559 * 2) Only overriding with IA_CSS_FRAME_FORMAT_NV12_TILEY is currently allowed.
560 * 3) This function is only to be used on pipes that use the output system.
561 * 4) If this function is used, it MUST be called after ia_css_pipe_create.
562 * 5) If this function is used, this function MUST be called before ia_css_stream_start.
565 ia_css_pipe_override_frame_format(struct ia_css_pipe *pipe,
567 enum ia_css_frame_format format);
569 #endif /* __IA_CSS_PIPE_PUBLIC_H */