1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright 2021 Advanced Micro Devices, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: AMD
24  *
25  */
26 
27 #include "resource.h"
28 
29 #include "dcn20_fpu.h"
30 
31 /**
32  * DOC: DCN2x FPU manipulation Overview
33  *
34  * The DCN architecture relies on FPU operations, which require special
35  * compilation flags and the use of kernel_fpu_begin/end functions; ideally, we
36  * want to avoid spreading FPU access across multiple files. With this idea in
37  * mind, this file aims to centralize all DCN20 and DCN2.1 (DCN2x) functions
38  * that require FPU access in a single place. Code in this file follows the
39  * following code pattern:
40  *
41  * 1. Functions that use FPU operations should be isolated in static functions.
42  * 2. The FPU functions should have the noinline attribute to ensure anything
43  *    that deals with FP register is contained within this call.
44  * 3. All function that needs to be accessed outside this file requires a
45  *    public interface that not uses any FPU reference.
46  * 4. Developers **must not** use DC_FP_START/END in this file, but they need
47  *    to ensure that the caller invokes it before access any function available
48  *    in this file. For this reason, public functions in this file must invoke
49  *    dc_assert_fp_enabled();
50  *
51  * Let's expand a little bit more the idea in the code pattern. To fully
52  * isolate FPU operations in a single place, we must avoid situations where
53  * compilers spill FP values to registers due to FP enable in a specific C
54  * file. Note that even if we isolate all FPU functions in a single file and
55  * call its interface from other files, the compiler might enable the use of
56  * FPU before we call DC_FP_START. Nevertheless, it is the programmer's
57  * responsibility to invoke DC_FP_START/END in the correct place. To highlight
58  * situations where developers forgot to use the FP protection before calling
59  * the DC FPU interface functions, we introduce a helper that checks if the
60  * function is invoked under FP protection. If not, it will trigger a kernel
61  * warning.
62  */
63 
64 void dcn20_populate_dml_writeback_from_context(struct dc *dc,
65 					       struct resource_context *res_ctx,
66 					       display_e2e_pipe_params_st *pipes)
67 {
68 	int pipe_cnt, i;
69 
70 	dc_assert_fp_enabled();
71 
72 	for (i = 0, pipe_cnt = 0; i < dc->res_pool->pipe_count; i++) {
73 		struct dc_writeback_info *wb_info = &res_ctx->pipe_ctx[i].stream->writeback_info[0];
74 
75 		if (!res_ctx->pipe_ctx[i].stream)
76 			continue;
77 
78 		/* Set writeback information */
79 		pipes[pipe_cnt].dout.wb_enable = (wb_info->wb_enabled == true) ? 1 : 0;
80 		pipes[pipe_cnt].dout.num_active_wb++;
81 		pipes[pipe_cnt].dout.wb.wb_src_height = wb_info->dwb_params.cnv_params.crop_height;
82 		pipes[pipe_cnt].dout.wb.wb_src_width = wb_info->dwb_params.cnv_params.crop_width;
83 		pipes[pipe_cnt].dout.wb.wb_dst_width = wb_info->dwb_params.dest_width;
84 		pipes[pipe_cnt].dout.wb.wb_dst_height = wb_info->dwb_params.dest_height;
85 		pipes[pipe_cnt].dout.wb.wb_htaps_luma = 1;
86 		pipes[pipe_cnt].dout.wb.wb_vtaps_luma = 1;
87 		pipes[pipe_cnt].dout.wb.wb_htaps_chroma = wb_info->dwb_params.scaler_taps.h_taps_c;
88 		pipes[pipe_cnt].dout.wb.wb_vtaps_chroma = wb_info->dwb_params.scaler_taps.v_taps_c;
89 		pipes[pipe_cnt].dout.wb.wb_hratio = 1.0;
90 		pipes[pipe_cnt].dout.wb.wb_vratio = 1.0;
91 		if (wb_info->dwb_params.out_format == dwb_scaler_mode_yuv420) {
92 			if (wb_info->dwb_params.output_depth == DWB_OUTPUT_PIXEL_DEPTH_8BPC)
93 				pipes[pipe_cnt].dout.wb.wb_pixel_format = dm_420_8;
94 			else
95 				pipes[pipe_cnt].dout.wb.wb_pixel_format = dm_420_10;
96 		} else {
97 			pipes[pipe_cnt].dout.wb.wb_pixel_format = dm_444_32;
98 		}
99 
100 		pipe_cnt++;
101 	}
102 }
103