xref: /linux/drivers/gpu/drm/amd/display/dc/inc/hw/mpc.h (revision 176278d8bff2c2be000b9c9509a7fc8120b5278d)
1 /* Copyright 2012-15 Advanced Micro Devices, Inc.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a
4  * copy of this software and associated documentation files (the "Software"),
5  * to deal in the Software without restriction, including without limitation
6  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7  * and/or sell copies of the Software, and to permit persons to whom the
8  * Software is furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
16  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
17  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19  * OTHER DEALINGS IN THE SOFTWARE.
20  *
21  * Authors: AMD
22  *
23  */
24 
25 /**
26  * DOC: overview
27  *
28  * Multiple Pipe/Plane Combiner (MPC) is a component in the hardware pipeline
29  * that performs blending of multiple planes, using global and per-pixel alpha.
30  * It also performs post-blending color correction operations according to the
31  * hardware capabilities, such as color transformation matrix and gamma 1D and
32  * 3D LUT.
33  *
34  * MPC receives output from all DPP pipes and combines them to multiple outputs
35  * supporting "M MPC inputs -> N MPC outputs" flexible composition
36  * architecture. It features:
37  *
38  * - Programmable blending structure to allow software controlled blending and
39  *   cascading;
40  * - Programmable window location of each DPP in active region of display;
41  * - Combining multiple DPP pipes in one active region when a single DPP pipe
42  *   cannot process very large surface;
43  * - Combining multiple DPP from different SLS with blending;
44  * - Stereo formats from single DPP in top-bottom or side-by-side modes;
45  * - Stereo formats from 2 DPPs;
46  * - Alpha blending of multiple layers from different DPP pipes;
47  * - Programmable background color;
48  */
49 
50 #ifndef __DC_MPCC_H__
51 #define __DC_MPCC_H__
52 
53 #include "dc_hw_types.h"
54 #include "hw_shared.h"
55 #include "transform.h"
56 
57 #define MAX_MPCC 6
58 #define MAX_OPP 6
59 
60 #define MAX_DWB		2
61 
62 enum mpc_output_csc_mode {
63 	MPC_OUTPUT_CSC_DISABLE = 0,
64 	MPC_OUTPUT_CSC_COEF_A,
65 	MPC_OUTPUT_CSC_COEF_B
66 };
67 
68 
69 enum mpcc_blend_mode {
70 	MPCC_BLEND_MODE_BYPASS,
71 	MPCC_BLEND_MODE_TOP_LAYER_PASSTHROUGH,
72 	MPCC_BLEND_MODE_TOP_LAYER_ONLY,
73 	MPCC_BLEND_MODE_TOP_BOT_BLENDING
74 };
75 
76 /**
77  * enum mpcc_alpha_blend_mode - define the alpha blend mode regarding pixel
78  * alpha and plane alpha values
79  */
80 enum mpcc_alpha_blend_mode {
81 	/**
82 	 * @MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA: per pixel alpha using DPP
83 	 * alpha value
84 	 */
85 	MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA,
86 	/**
87 	 * @MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN: per
88 	 * pixel alpha using DPP alpha value multiplied by a global gain (plane
89 	 * alpha)
90 	 */
91 	MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN,
92 	/**
93 	 * @MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA: global alpha value, ignores
94 	 * pixel alpha and consider only plane alpha
95 	 */
96 	MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA
97 };
98 
99 enum mpcc_movable_cm_location {
100 	MPCC_MOVABLE_CM_LOCATION_BEFORE,
101 	MPCC_MOVABLE_CM_LOCATION_AFTER,
102 };
103 
104 enum MCM_LUT_XABLE {
105 	MCM_LUT_DISABLE,
106 	MCM_LUT_DISABLED = MCM_LUT_DISABLE,
107 	MCM_LUT_ENABLE,
108 	MCM_LUT_ENABLED = MCM_LUT_ENABLE,
109 };
110 
111 enum MCM_LUT_ID {
112 	MCM_LUT_3DLUT,
113 	MCM_LUT_1DLUT,
114 	MCM_LUT_SHAPER
115 };
116 
117 union mcm_lut_params {
118 	const struct pwl_params *pwl;
119 	const struct tetrahedral_params *lut3d;
120 };
121 
122 /**
123  * struct mpcc_blnd_cfg - MPCC blending configuration
124  */
125 struct mpcc_blnd_cfg {
126 	/**
127 	 * @black_color: background color.
128 	 */
129 	struct tg_color black_color;
130 
131 	/**
132 	 * @alpha_mode: alpha blend mode (MPCC_ALPHA_BLND_MODE).
133 	 */
134 	enum mpcc_alpha_blend_mode alpha_mode;
135 
136 	/**
137 	 * @pre_multiplied_alpha:
138 	 * Whether pixel color values were pre-multiplied by the alpha channel
139 	 * (MPCC_ALPHA_MULTIPLIED_MODE).
140 	 */
141 	bool pre_multiplied_alpha;
142 
143 	/**
144 	 * @global_gain: Used when blend mode considers both pixel alpha and plane.
145 	 */
146 	int global_gain;
147 
148 	/**
149 	 * @global_alpha: Plane alpha value.
150 	 */
151 	int global_alpha;
152 
153 	/**
154 	 * @overlap_only: Whether overlapping of different planes is allowed.
155 	 */
156 	bool overlap_only;
157 
158 	/* MPCC top/bottom gain settings */
159 
160 	/**
161 	 * @bottom_gain_mode: Blend mode for bottom gain setting.
162 	 */
163 	int bottom_gain_mode;
164 
165 	/**
166 	 * @background_color_bpc: Background color for bpc.
167 	 */
168 	int background_color_bpc;
169 
170 	/**
171 	 * @top_gain: Top gain setting.
172 	 */
173 	int top_gain;
174 
175 	/**
176 	 * @bottom_inside_gain: Blend mode for bottom inside.
177 	 */
178 	int bottom_inside_gain;
179 
180 	/**
181 	 * @bottom_outside_gain: Blend mode for bottom outside.
182 	 */
183 	int bottom_outside_gain;
184 };
185 
186 struct mpc_grph_gamut_adjustment {
187 	struct fixed31_32 temperature_matrix[CSC_TEMPERATURE_MATRIX_SIZE];
188 	enum graphics_gamut_adjust_type gamut_adjust_type;
189 	enum mpcc_gamut_remap_id mpcc_gamut_remap_block_id;
190 };
191 
192 struct mpcc_sm_cfg {
193 	bool enable;
194 	/* 0-single plane,2-row subsampling,4-column subsampling,6-checkboard subsampling */
195 	int sm_mode;
196 	/* 0- disable frame alternate, 1- enable frame alternate */
197 	bool frame_alt;
198 	/* 0- disable field alternate, 1- enable field alternate */
199 	bool field_alt;
200 	/* 0-no force,2-force frame polarity from top,3-force frame polarity from bottom */
201 	int force_next_frame_porlarity;
202 	/* 0-no force,2-force field polarity from top,3-force field polarity from bottom */
203 	int force_next_field_polarity;
204 };
205 
206 struct mpc_denorm_clamp {
207 	int clamp_max_r_cr;
208 	int clamp_min_r_cr;
209 	int clamp_max_g_y;
210 	int clamp_min_g_y;
211 	int clamp_max_b_cb;
212 	int clamp_min_b_cb;
213 };
214 
215 struct mpc_dwb_flow_control {
216 	int flow_ctrl_mode;
217 	int flow_ctrl_cnt0;
218 	int flow_ctrl_cnt1;
219 };
220 
221 /**
222  * struct mpcc - MPCC connection and blending configuration for a single MPCC instance.
223  *
224  * This struct is used as a node in an MPC tree.
225  */
226 struct mpcc {
227 	/**
228 	 * @mpcc_id: MPCC physical instance.
229 	 */
230 	int mpcc_id;
231 
232 	/**
233 	 * @dpp_id: DPP input to this MPCC
234 	 */
235 	int dpp_id;
236 
237 	/**
238 	 * @mpcc_bot: Pointer to bottom layer MPCC. NULL when not connected.
239 	 */
240 	struct mpcc *mpcc_bot;
241 
242 	/**
243 	 * @blnd_cfg: The blending configuration for this MPCC.
244 	 */
245 	struct mpcc_blnd_cfg blnd_cfg;
246 
247 	/**
248 	 * @sm_cfg: stereo mix setting for this MPCC
249 	 */
250 	struct mpcc_sm_cfg sm_cfg;
251 
252 	/**
253 	 * @shared_bottom:
254 	 *
255 	 * If MPCC output to both OPP and DWB endpoints, true. Otherwise, false.
256 	 */
257 	bool shared_bottom;
258 };
259 
260 /**
261  * struct mpc_tree - MPC tree represents all MPCC connections for a pipe.
262  *
263  *
264  */
265 struct mpc_tree {
266 	/**
267 	 * @opp_id: The OPP instance that owns this MPC tree.
268 	 */
269 	int opp_id;
270 
271 	/**
272 	 * @opp_list: the top MPCC layer of the MPC tree that outputs to OPP endpoint
273 	 */
274 	struct mpcc *opp_list;
275 };
276 
277 struct mpc {
278 	const struct mpc_funcs *funcs;
279 	struct dc_context *ctx;
280 
281 	struct mpcc mpcc_array[MAX_MPCC];
282 	struct pwl_params blender_params;
283 	bool cm_bypass_mode;
284 };
285 
286 struct mpcc_state {
287 	uint32_t opp_id;
288 	uint32_t dpp_id;
289 	uint32_t bot_mpcc_id;
290 	uint32_t mode;
291 	uint32_t alpha_mode;
292 	uint32_t pre_multiplied_alpha;
293 	uint32_t overlap_only;
294 	uint32_t idle;
295 	uint32_t busy;
296 	uint32_t shaper_lut_mode;
297 	uint32_t lut3d_mode;
298 	uint32_t lut3d_bit_depth;
299 	uint32_t lut3d_size;
300 	uint32_t rgam_mode;
301 	uint32_t rgam_lut;
302 	struct mpc_grph_gamut_adjustment gamut_remap;
303 };
304 
305 /**
306  * struct mpc_funcs - funcs
307  */
308 struct mpc_funcs {
309 	void (*read_mpcc_state)(
310 			struct mpc *mpc,
311 			int mpcc_inst,
312 			struct mpcc_state *s);
313 
314 	/**
315 	 * @insert_plane:
316 	 *
317 	 * Insert DPP into MPC tree based on specified blending position.
318 	 * Only used for planes that are part of blending chain for OPP output
319 	 *
320 	 * Parameters:
321 	 *
322 	 * - [in/out] mpc  - MPC context.
323 	 * - [in/out] tree - MPC tree structure that plane will be added to.
324 	 * - [in] blnd_cfg - MPCC blending configuration for the new blending layer.
325 	 * - [in] sm_cfg   - MPCC stereo mix configuration for the new blending layer.
326 	 *                   stereo mix must disable for the very bottom layer of the tree config.
327 	 * - [in] insert_above_mpcc - Insert new plane above this MPCC.
328 	 *                          If NULL, insert as bottom plane.
329 	 * - [in] dpp_id  - DPP instance for the plane to be added.
330 	 * - [in] mpcc_id - The MPCC physical instance to use for blending.
331 	 *
332 	 * Return:
333 	 *
334 	 * struct mpcc* - MPCC that was added.
335 	 */
336 	struct mpcc* (*insert_plane)(
337 			struct mpc *mpc,
338 			struct mpc_tree *tree,
339 			struct mpcc_blnd_cfg *blnd_cfg,
340 			struct mpcc_sm_cfg *sm_cfg,
341 			struct mpcc *insert_above_mpcc,
342 			int dpp_id,
343 			int mpcc_id);
344 
345 	/**
346 	 * @remove_mpcc:
347 	 *
348 	 * Remove a specified MPCC from the MPC tree.
349 	 *
350 	 * Parameters:
351 	 *
352 	 * - [in/out] mpc   - MPC context.
353 	 * - [in/out] tree  - MPC tree structure that plane will be removed from.
354 	 * - [in/out] mpcc  - MPCC to be removed from tree.
355 	 *
356 	 * Return:
357 	 *
358 	 * void
359 	 */
360 	void (*remove_mpcc)(
361 			struct mpc *mpc,
362 			struct mpc_tree *tree,
363 			struct mpcc *mpcc);
364 
365 	/**
366 	 * @mpc_init:
367 	 *
368 	 * Reset the MPCC HW status by disconnecting all muxes.
369 	 *
370 	 * Parameters:
371 	 *
372 	 * - [in/out] mpc - MPC context.
373 	 *
374 	 * Return:
375 	 *
376 	 * void
377 	 */
378 	void (*mpc_init)(struct mpc *mpc);
379 	void (*mpc_init_single_inst)(
380 			struct mpc *mpc,
381 			unsigned int mpcc_id);
382 
383 	/**
384 	 * @update_blending:
385 	 *
386 	 * Update the blending configuration for a specified MPCC.
387 	 *
388 	 * Parameters:
389 	 *
390 	 * - [in/out] mpc - MPC context.
391 	 * - [in] blnd_cfg - MPCC blending configuration.
392 	 * - [in] mpcc_id  - The MPCC physical instance.
393 	 *
394 	 * Return:
395 	 *
396 	 * void
397 	 */
398 	void (*update_blending)(
399 		struct mpc *mpc,
400 		struct mpcc_blnd_cfg *blnd_cfg,
401 		int mpcc_id);
402 
403 	/**
404 	 * @cursor_lock:
405 	 *
406 	 * Lock cursor updates for the specified OPP. OPP defines the set of
407 	 * MPCC that are locked together for cursor.
408 	 *
409 	 * Parameters:
410 	 *
411 	 * - [in] mpc - MPC context.
412 	 * - [in] opp_id  - The OPP to lock cursor updates on
413 	 * - [in] lock - lock/unlock the OPP
414 	 *
415 	 * Return:
416 	 *
417 	 * void
418 	 */
419 	void (*cursor_lock)(
420 			struct mpc *mpc,
421 			int opp_id,
422 			bool lock);
423 
424 	/**
425 	 * @insert_plane_to_secondary:
426 	 *
427 	 * Add DPP into secondary MPC tree based on specified blending
428 	 * position.  Only used for planes that are part of blending chain for
429 	 * DWB output
430 	 *
431 	 * Parameters:
432 	 *
433 	 * - [in/out] mpc  - MPC context.
434 	 * - [in/out] tree - MPC tree structure that plane will be added to.
435 	 * - [in] blnd_cfg - MPCC blending configuration for the new blending layer.
436 	 * - [in] sm_cfg   - MPCC stereo mix configuration for the new blending layer.
437 	 *	    stereo mix must disable for the very bottom layer of the tree config.
438 	 * - [in] insert_above_mpcc - Insert new plane above this MPCC.  If
439 	 *          NULL, insert as bottom plane.
440 	 * - [in] dpp_id - DPP instance for the plane to be added.
441 	 * - [in] mpcc_id - The MPCC physical instance to use for blending.
442 	 *
443 	 * Return:
444 	 *
445 	 * struct mpcc* - MPCC that was added.
446 	 */
447 	struct mpcc* (*insert_plane_to_secondary)(
448 			struct mpc *mpc,
449 			struct mpc_tree *tree,
450 			struct mpcc_blnd_cfg *blnd_cfg,
451 			struct mpcc_sm_cfg *sm_cfg,
452 			struct mpcc *insert_above_mpcc,
453 			int dpp_id,
454 			int mpcc_id);
455 
456 	/**
457 	 * @remove_mpcc_from_secondary:
458 	 *
459 	 * Remove a specified DPP from the 'secondary' MPC tree.
460 	 *
461 	 * Parameters:
462 	 *
463 	 * - [in/out] mpc  - MPC context.
464 	 * - [in/out] tree - MPC tree structure that plane will be removed from.
465 	 * - [in]     mpcc - MPCC to be removed from tree.
466 	 *
467 	 * Return:
468 	 *
469 	 * void
470 	 */
471 	void (*remove_mpcc_from_secondary)(
472 			struct mpc *mpc,
473 			struct mpc_tree *tree,
474 			struct mpcc *mpcc);
475 
476 	struct mpcc* (*get_mpcc_for_dpp_from_secondary)(
477 			struct mpc_tree *tree,
478 			int dpp_id);
479 
480 	struct mpcc* (*get_mpcc_for_dpp)(
481 			struct mpc_tree *tree,
482 			int dpp_id);
483 
484 	void (*wait_for_idle)(struct mpc *mpc, int id);
485 
486 	void (*assert_mpcc_idle_before_connect)(struct mpc *mpc, int mpcc_id);
487 
488 	void (*init_mpcc_list_from_hw)(
489 		struct mpc *mpc,
490 		struct mpc_tree *tree);
491 
492 	void (*set_denorm)(struct mpc *mpc,
493 			int opp_id,
494 			enum dc_color_depth output_depth);
495 
496 	void (*set_denorm_clamp)(
497 			struct mpc *mpc,
498 			int opp_id,
499 			struct mpc_denorm_clamp denorm_clamp);
500 
501 	void (*set_output_csc)(struct mpc *mpc,
502 			int opp_id,
503 			const uint16_t *regval,
504 			enum mpc_output_csc_mode ocsc_mode);
505 
506 	void (*set_ocsc_default)(struct mpc *mpc,
507 			int opp_id,
508 			enum dc_color_space color_space,
509 			enum mpc_output_csc_mode ocsc_mode);
510 
511 	void (*set_output_gamma)(
512 			struct mpc *mpc,
513 			int mpcc_id,
514 			const struct pwl_params *params);
515 	void (*power_on_mpc_mem_pwr)(
516 			struct mpc *mpc,
517 			int mpcc_id,
518 			bool power_on);
519 	void (*set_dwb_mux)(
520 			struct mpc *mpc,
521 			int dwb_id,
522 			int mpcc_id);
523 
524 	void (*disable_dwb_mux)(
525 		struct mpc *mpc,
526 		int dwb_id);
527 
528 	bool (*is_dwb_idle)(
529 		struct mpc *mpc,
530 		int dwb_id);
531 
532 	void (*set_out_rate_control)(
533 		struct mpc *mpc,
534 		int opp_id,
535 		bool enable,
536 		bool rate_2x_mode,
537 		struct mpc_dwb_flow_control *flow_control);
538 
539 	void (*set_gamut_remap)(
540 			struct mpc *mpc,
541 			int mpcc_id,
542 			const struct mpc_grph_gamut_adjustment *adjust);
543 
544 	bool (*program_1dlut)(
545 			struct mpc *mpc,
546 			const struct pwl_params *params,
547 			uint32_t rmu_idx);
548 
549 	bool (*program_shaper)(
550 			struct mpc *mpc,
551 			const struct pwl_params *params,
552 			uint32_t rmu_idx);
553 
554 	uint32_t (*acquire_rmu)(struct mpc *mpc, int mpcc_id, int rmu_idx);
555 
556 	bool (*program_3dlut)(
557 			struct mpc *mpc,
558 			const struct tetrahedral_params *params,
559 			int rmu_idx);
560 
561 	int (*release_rmu)(struct mpc *mpc, int mpcc_id);
562 
563 	unsigned int (*get_mpc_out_mux)(
564 				struct mpc *mpc,
565 				int opp_id);
566 
567 	void (*set_bg_color)(struct mpc *mpc,
568 			struct tg_color *bg_color,
569 			int mpcc_id);
570 	void (*set_mpc_mem_lp_mode)(struct mpc *mpc);
571 	void (*set_movable_cm_location)(struct mpc *mpc, enum mpcc_movable_cm_location location, int mpcc_id);
572 	void (*update_3dlut_fast_load_select)(struct mpc *mpc, int mpcc_id, int hubp_idx);
573 	void (*get_3dlut_fast_load_status)(struct mpc *mpc, int mpcc_id, uint32_t *done, uint32_t *soft_underflow, uint32_t *hard_underflow);
574 	void (*populate_lut)(struct mpc *mpc, const enum MCM_LUT_ID id, const union mcm_lut_params params,
575 			bool lut_bank_a, int mpcc_id);
576 	void (*program_lut_read_write_control)(struct mpc *mpc, const enum MCM_LUT_ID id, bool lut_bank_a, int mpcc_id);
577 	void (*program_lut_mode)(struct mpc *mpc, const enum MCM_LUT_ID id, const enum MCM_LUT_XABLE xable,
578 			bool lut_bank_a, int mpcc_id);
579 };
580 
581 #endif
582