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_PIPE_H__
17 #define __IA_CSS_PIPE_H__
18 
19 #include <type_support.h>
20 #include "ia_css_stream.h"
21 #include "ia_css_frame.h"
22 #include "ia_css_pipeline.h"
23 #include "ia_css_binary.h"
24 #include "sh_css_legacy.h"
25 
26 #define PIPE_ENTRY_EMPTY_TOKEN                (~0U)
27 #define PIPE_ENTRY_RESERVED_TOKEN             (0x1)
28 
29 struct ia_css_preview_settings {
30 	struct ia_css_binary copy_binary;
31 	struct ia_css_binary preview_binary;
32 	struct ia_css_binary vf_pp_binary;
33 
34 	/* 2401 only for these two - do we in fact use them for anything real */
35 	struct ia_css_frame *delay_frames[MAX_NUM_VIDEO_DELAY_FRAMES];
36 	struct ia_css_frame *tnr_frames[NUM_VIDEO_TNR_FRAMES];
37 
38 	struct ia_css_pipe *copy_pipe;
39 	struct ia_css_pipe *capture_pipe;
40 };
41 
42 #define IA_CSS_DEFAULT_PREVIEW_SETTINGS { \
43 	.copy_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
44 	.preview_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
45 	.vf_pp_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
46 }
47 
48 struct ia_css_capture_settings {
49 	struct ia_css_binary copy_binary;
50 	/* we extend primary binary to multiple stages because in ISP2.6.1
51 	 * the computation load is too high to fit in one single binary. */
52 	struct ia_css_binary primary_binary[MAX_NUM_PRIMARY_STAGES];
53 	unsigned int num_primary_stage;
54 	struct ia_css_binary pre_isp_binary;
55 	struct ia_css_binary anr_gdc_binary;
56 	struct ia_css_binary post_isp_binary;
57 	struct ia_css_binary capture_pp_binary;
58 	struct ia_css_binary vf_pp_binary;
59 	struct ia_css_binary capture_ldc_binary;
60 	struct ia_css_binary *yuv_scaler_binary;
61 	struct ia_css_frame *delay_frames[MAX_NUM_VIDEO_DELAY_FRAMES];
62 	bool *is_output_stage;
63 	unsigned int num_yuv_scaler;
64 };
65 
66 #define IA_CSS_DEFAULT_CAPTURE_SETTINGS { \
67 	.copy_binary		= IA_CSS_BINARY_DEFAULT_SETTINGS, \
68 	.primary_binary		= {IA_CSS_BINARY_DEFAULT_SETTINGS}, \
69 	.pre_isp_binary		= IA_CSS_BINARY_DEFAULT_SETTINGS, \
70 	.anr_gdc_binary		= IA_CSS_BINARY_DEFAULT_SETTINGS, \
71 	.post_isp_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
72 	.capture_pp_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
73 	.vf_pp_binary		= IA_CSS_BINARY_DEFAULT_SETTINGS, \
74 	.capture_ldc_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
75 }
76 
77 struct ia_css_video_settings {
78 	struct ia_css_binary copy_binary;
79 	struct ia_css_binary video_binary;
80 	struct ia_css_binary vf_pp_binary;
81 	struct ia_css_binary *yuv_scaler_binary;
82 	struct ia_css_frame *delay_frames[MAX_NUM_VIDEO_DELAY_FRAMES];
83 	struct ia_css_frame *tnr_frames[NUM_VIDEO_TNR_FRAMES];
84 	struct ia_css_frame *vf_pp_in_frame;
85 	struct ia_css_pipe *copy_pipe;
86 	struct ia_css_pipe *capture_pipe;
87 	bool *is_output_stage;
88 	unsigned int num_yuv_scaler;
89 };
90 
91 #define IA_CSS_DEFAULT_VIDEO_SETTINGS { \
92 	.copy_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
93 	.video_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
94 	.vf_pp_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
95 }
96 
97 struct ia_css_yuvpp_settings {
98 	struct ia_css_binary copy_binary;
99 	struct ia_css_binary *yuv_scaler_binary;
100 	struct ia_css_binary *vf_pp_binary;
101 	bool *is_output_stage;
102 	unsigned int num_yuv_scaler;
103 	unsigned int num_vf_pp;
104 	unsigned int num_output;
105 };
106 
107 #define IA_CSS_DEFAULT_YUVPP_SETTINGS { \
108 	.copy_binary	= IA_CSS_BINARY_DEFAULT_SETTINGS, \
109 }
110 
111 struct osys_object;
112 
113 struct ia_css_pipe {
114 	/* TODO: Remove stop_requested and use stop_requested in the pipeline */
115 	bool                            stop_requested;
116 	struct ia_css_pipe_config       config;
117 	struct ia_css_pipe_extra_config extra_config;
118 	struct ia_css_pipe_info         info;
119 	enum ia_css_pipe_id		mode;
120 	struct ia_css_shading_table	*shading_table;
121 	struct ia_css_pipeline		pipeline;
122 	struct ia_css_frame_info	output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE];
123 	struct ia_css_frame_info	bds_output_info;
124 	struct ia_css_frame_info	vf_output_info[IA_CSS_PIPE_MAX_OUTPUT_STAGE];
125 	struct ia_css_frame_info	out_yuv_ds_input_info;
126 	struct ia_css_frame_info	vf_yuv_ds_input_info;
127 	struct ia_css_fw_info		*output_stage;	/* extra output stage */
128 	struct ia_css_fw_info		*vf_stage;	/* extra vf_stage */
129 	unsigned int			required_bds_factor;
130 	unsigned int			dvs_frame_delay;
131 	int				num_invalid_frames;
132 	bool				enable_viewfinder[IA_CSS_PIPE_MAX_OUTPUT_STAGE];
133 	struct ia_css_stream		*stream;
134 	struct ia_css_frame		in_frame_struct;
135 	struct ia_css_frame		out_frame_struct;
136 	struct ia_css_frame		vf_frame_struct;
137 	struct ia_css_frame		*continuous_frames[NUM_CONTINUOUS_FRAMES];
138 	struct ia_css_metadata	*cont_md_buffers[NUM_CONTINUOUS_FRAMES];
139 	union {
140 		struct ia_css_preview_settings preview;
141 		struct ia_css_video_settings   video;
142 		struct ia_css_capture_settings capture;
143 		struct ia_css_yuvpp_settings yuvpp;
144 	} pipe_settings;
145 	ia_css_ptr scaler_pp_lut;
146 	struct osys_object *osys_obj;
147 
148 	/* This number is unique per pipe each instance of css. This number is
149 	 * reused as pipeline number also. There is a 1-1 mapping between pipe_num
150 	 * and sp thread id. Current logic limits pipe_num to
151 	 * SH_CSS_MAX_SP_THREADS */
152 	unsigned int pipe_num;
153 };
154 
155 #define IA_CSS_DEFAULT_PIPE { \
156 	.config			= DEFAULT_PIPE_CONFIG, \
157 	.info			= DEFAULT_PIPE_INFO, \
158 	.mode			= IA_CSS_PIPE_ID_VIDEO, /* (pipe_id) */ \
159 	.pipeline		= DEFAULT_PIPELINE, \
160 	.output_info		= {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
161 	.bds_output_info	= IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
162 	.vf_output_info		= {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
163 	.out_yuv_ds_input_info	= IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
164 	.vf_yuv_ds_input_info	= IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
165 	.required_bds_factor	= SH_CSS_BDS_FACTOR_1_00, \
166 	.dvs_frame_delay	= 1, \
167 	.enable_viewfinder	= {true}, \
168 	.in_frame_struct	= DEFAULT_FRAME, \
169 	.out_frame_struct	= DEFAULT_FRAME, \
170 	.vf_frame_struct	= DEFAULT_FRAME, \
171 	.pipe_settings		= { \
172 		.preview = IA_CSS_DEFAULT_PREVIEW_SETTINGS \
173 	}, \
174 	.pipe_num		= PIPE_ENTRY_EMPTY_TOKEN, \
175 }
176 
177 void ia_css_pipe_map_queue(struct ia_css_pipe *pipe, bool map);
178 
179 int
180 sh_css_param_update_isp_params(struct ia_css_pipe *curr_pipe,
181 			       struct ia_css_isp_parameters *params,
182 			       bool commit, struct ia_css_pipe *pipe);
183 
184 #endif /* __IA_CSS_PIPE_H__ */
185