xref: /linux/drivers/gpu/drm/amd/display/dc/inc/resource.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
14562236bSHarry Wentland /*
24562236bSHarry Wentland  * Copyright 2015 Advanced Micro Devices, Inc.
34562236bSHarry Wentland  *
44562236bSHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
54562236bSHarry Wentland  * copy of this software and associated documentation files (the "Software"),
64562236bSHarry Wentland  * to deal in the Software without restriction, including without limitation
74562236bSHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
84562236bSHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
94562236bSHarry Wentland  * Software is furnished to do so, subject to the following conditions:
104562236bSHarry Wentland  *
114562236bSHarry Wentland  * The above copyright notice and this permission notice shall be included in
124562236bSHarry Wentland  * all copies or substantial portions of the Software.
134562236bSHarry Wentland  *
144562236bSHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
154562236bSHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164562236bSHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
174562236bSHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
184562236bSHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
194562236bSHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
204562236bSHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
214562236bSHarry Wentland  *
224562236bSHarry Wentland  * Authors: AMD
234562236bSHarry Wentland  */
244562236bSHarry Wentland 
254562236bSHarry Wentland #ifndef DRIVERS_GPU_DRM_AMD_DC_DEV_DC_INC_RESOURCE_H_
264562236bSHarry Wentland #define DRIVERS_GPU_DRM_AMD_DC_DEV_DC_INC_RESOURCE_H_
274562236bSHarry Wentland 
284562236bSHarry Wentland #include "core_types.h"
294562236bSHarry Wentland #include "core_status.h"
304562236bSHarry Wentland #include "dal_asic_id.h"
31a185048cSTony Cheng #include "dm_pp_smu.h"
3200c39110SAurabindo Pillai #include "spl/dc_spl.h"
334562236bSHarry Wentland 
34dc88b4a6SEric Yang #define MEMORY_TYPE_MULTIPLIER_CZ 4
35c46e5df4SCharlene Liu #define MEMORY_TYPE_HBM 2
36c46e5df4SCharlene Liu 
37dc88b4a6SEric Yang 
385f0c7491SMeenakshikumar Somasundaram #define IS_PIPE_SYNCD_VALID(pipe) ((((pipe)->pipe_idx_syncd) & 0x80)?1:0)
395f0c7491SMeenakshikumar Somasundaram #define GET_PIPE_SYNCD_FROM_PIPE(pipe) ((pipe)->pipe_idx_syncd & 0x7F)
405f0c7491SMeenakshikumar Somasundaram #define SET_PIPE_SYNCD_TO_PIPE(pipe, pipe_syncd) ((pipe)->pipe_idx_syncd = (0x80 | pipe_syncd))
415f0c7491SMeenakshikumar Somasundaram 
424562236bSHarry Wentland enum dce_version resource_parse_asic_id(
434562236bSHarry Wentland 		struct hw_asic_id asic_id);
444562236bSHarry Wentland 
454562236bSHarry Wentland struct resource_caps {
464562236bSHarry Wentland 	int num_timing_generator;
47e9522309SEric Bernstein 	int num_opp;
484562236bSHarry Wentland 	int num_video_plane;
494562236bSHarry Wentland 	int num_audio;
504562236bSHarry Wentland 	int num_stream_encoder;
514562236bSHarry Wentland 	int num_pll;
52b1a4eb99SDmytro Laktyushkin 	int num_dwb;
530e8e4fbfSHersen Wu 	int num_ddc;
547ed4e635SHarry Wentland 	int num_vmid;
5597bda032SHarry Wentland 	int num_dsc;
56e1f4328fSJimmy Kizito 	unsigned int num_dig_link_enc; // Total number of DIGs (digital encoders) in DIO (Display Input/Output).
57eabf2019SJimmy Kizito 	unsigned int num_usb4_dpia; // Total number of USB4 DPIA (DisplayPort Input Adapters).
5883228ebbSFangzhi Zuo 	int num_hpo_dp_stream_encoder;
593bc8d921SFangzhi Zuo 	int num_hpo_dp_link_encoder;
605dba4991SBhawanpreet Lakha 	int num_mpc_3dlut;
614562236bSHarry Wentland };
624562236bSHarry Wentland 
634562236bSHarry Wentland struct resource_straps {
644562236bSHarry Wentland 	uint32_t hdmi_disable;
654562236bSHarry Wentland 	uint32_t dc_pinstraps_audio;
664562236bSHarry Wentland 	uint32_t audio_stream_number;
674562236bSHarry Wentland };
684562236bSHarry Wentland 
694562236bSHarry Wentland struct resource_create_funcs {
704562236bSHarry Wentland 	void (*read_dce_straps)(
714562236bSHarry Wentland 			struct dc_context *ctx, struct resource_straps *straps);
724562236bSHarry Wentland 
734562236bSHarry Wentland 	struct audio *(*create_audio)(
744562236bSHarry Wentland 			struct dc_context *ctx, unsigned int inst);
754562236bSHarry Wentland 
764562236bSHarry Wentland 	struct stream_encoder *(*create_stream_encoder)(
774562236bSHarry Wentland 			enum engine_id eng_id, struct dc_context *ctx);
784562236bSHarry Wentland 
7983228ebbSFangzhi Zuo 	struct hpo_dp_stream_encoder *(*create_hpo_dp_stream_encoder)(
8083228ebbSFangzhi Zuo 			enum engine_id eng_id, struct dc_context *ctx);
813bc8d921SFangzhi Zuo 	struct hpo_dp_link_encoder *(*create_hpo_dp_link_encoder)(
823bc8d921SFangzhi Zuo 			uint8_t inst,
833bc8d921SFangzhi Zuo 			struct dc_context *ctx);
844562236bSHarry Wentland 	struct dce_hwseq *(*create_hwseq)(
854562236bSHarry Wentland 			struct dc_context *ctx);
864562236bSHarry Wentland };
874562236bSHarry Wentland 
884562236bSHarry Wentland bool resource_construct(
894562236bSHarry Wentland 	unsigned int num_virtual_links,
90fb3466a4SBhawanpreet Lakha 	struct dc *dc,
914562236bSHarry Wentland 	struct resource_pool *pool,
924562236bSHarry Wentland 	const struct resource_create_funcs *create_funcs);
934562236bSHarry Wentland 
94d9673c92SHarry Wentland struct resource_pool *dc_create_resource_pool(struct dc  *dc,
95d9673c92SHarry Wentland 					      const struct dc_init_data *init_data,
96d9673c92SHarry Wentland 					      enum dce_version dc_version);
974562236bSHarry Wentland 
98fb3466a4SBhawanpreet Lakha void dc_destroy_resource_pool(struct dc *dc);
994562236bSHarry Wentland 
1004562236bSHarry Wentland enum dc_status resource_map_pool_resources(
101fb3466a4SBhawanpreet Lakha 		const struct dc *dc,
102608ac7bbSJerry Zuo 		struct dc_state *context,
1031dc90497SAndrey Grodzovsky 		struct dc_stream_state *stream);
1044562236bSHarry Wentland 
105051d9007SGeorge Shen void resource_build_test_pattern_params(
106051d9007SGeorge Shen 		struct resource_context *res_ctx,
107051d9007SGeorge Shen 		struct pipe_ctx *pipe_ctx);
108051d9007SGeorge Shen 
109b2d0a103SDmytro Laktyushkin bool resource_build_scaling_params(struct pipe_ctx *pipe_ctx);
1104562236bSHarry Wentland 
1114562236bSHarry Wentland enum dc_status resource_build_scaling_params_for_context(
112fb3466a4SBhawanpreet Lakha 		const struct dc *dc,
113608ac7bbSJerry Zuo 		struct dc_state *context);
1144562236bSHarry Wentland 
1154562236bSHarry Wentland void resource_build_info_frame(struct pipe_ctx *pipe_ctx);
1164562236bSHarry Wentland 
11721e67d4dSHarry Wentland void resource_unreference_clock_source(
1184562236bSHarry Wentland 		struct resource_context *res_ctx,
119a2b8659dSTony Cheng 		const struct resource_pool *pool,
1204a629536SHarry Wentland 		struct clock_source *clock_source);
1214562236bSHarry Wentland 
1224562236bSHarry Wentland void resource_reference_clock_source(
1234562236bSHarry Wentland 		struct resource_context *res_ctx,
124a2b8659dSTony Cheng 		const struct resource_pool *pool,
1254562236bSHarry Wentland 		struct clock_source *clock_source);
1264562236bSHarry Wentland 
127ad8960a6SMikita Lipski int resource_get_clock_source_reference(
128ad8960a6SMikita Lipski 		struct resource_context *res_ctx,
129ad8960a6SMikita Lipski 		const struct resource_pool *pool,
130ad8960a6SMikita Lipski 		struct clock_source *clock_source);
131ad8960a6SMikita Lipski 
1324562236bSHarry Wentland bool resource_are_streams_timing_synchronizable(
1330971c40eSHarry Wentland 		struct dc_stream_state *stream1,
1340971c40eSHarry Wentland 		struct dc_stream_state *stream2);
1354562236bSHarry Wentland 
13677a2b726SVladimir Stempen bool resource_are_vblanks_synchronizable(
13777a2b726SVladimir Stempen 		struct dc_stream_state *stream1,
13877a2b726SVladimir Stempen 		struct dc_stream_state *stream2);
13977a2b726SVladimir Stempen 
1404562236bSHarry Wentland struct clock_source *resource_find_used_clk_src_for_sharing(
1414562236bSHarry Wentland 		struct resource_context *res_ctx,
1424562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx);
1434562236bSHarry Wentland 
1444562236bSHarry Wentland struct clock_source *dc_resource_find_first_free_pll(
145a2b8659dSTony Cheng 		struct resource_context *res_ctx,
146a2b8659dSTony Cheng 		const struct resource_pool *pool);
1474562236bSHarry Wentland 
1484562236bSHarry Wentland bool resource_attach_surfaces_to_context(
1493be5262eSHarry Wentland 		struct dc_plane_state *const *plane_state,
1504562236bSHarry Wentland 		int surface_count,
1510971c40eSHarry Wentland 		struct dc_stream_state *dc_stream,
152608ac7bbSJerry Zuo 		struct dc_state *context,
153a2b8659dSTony Cheng 		const struct resource_pool *pool);
1544562236bSHarry Wentland 
15553f32880SWenjing Liu #define FREE_PIPE_INDEX_NOT_FOUND -1
1564562236bSHarry Wentland 
15753f32880SWenjing Liu /*
15853f32880SWenjing Liu  * pipe types are identified based on MUXes in DCN front end that are capable
15953f32880SWenjing Liu  * of taking input from one DCN pipeline to another DCN pipeline. The name is
16053f32880SWenjing Liu  * in a form of XXXX_YYYY, where XXXX is the DCN front end hardware block the
16153f32880SWenjing Liu  * pipeline ends with and YYYY is the rendering role that the pipe is in.
16253f32880SWenjing Liu  *
16353f32880SWenjing Liu  * For instance OTG_MASTER is a pipe ending with OTG hardware block in its
16453f32880SWenjing Liu  * pipeline and it is in a role of a master pipe for timing generation.
16553f32880SWenjing Liu  *
16653f32880SWenjing Liu  * For quick reference a diagram of each pipe type's areas of responsibility
16753f32880SWenjing Liu  * for outputting timings on the screen is shown below:
16853f32880SWenjing Liu  *
16953f32880SWenjing Liu  *       Timing Active for Stream 0
17053f32880SWenjing Liu  *        __________________________________________________
17153f32880SWenjing Liu  *       |OTG master 0 (OPP head 0)|OPP head 2 (DPP pipe 2) |
17253f32880SWenjing Liu  *       |             (DPP pipe 0)|                        |
17353f32880SWenjing Liu  *       | Top Plane 0             |                        |
17453f32880SWenjing Liu  *       |           ______________|____                    |
17553f32880SWenjing Liu  *       |          |DPP pipe 1    |DPP |                   |
17653f32880SWenjing Liu  *       |          |              |pipe|                   |
17753f32880SWenjing Liu  *       |          |  Bottom      |3   |                   |
17853f32880SWenjing Liu  *       |          |  Plane 1     |    |                   |
17953f32880SWenjing Liu  *       |          |              |    |                   |
18053f32880SWenjing Liu  *       |          |______________|____|                   |
18153f32880SWenjing Liu  *       |                         |                        |
18253f32880SWenjing Liu  *       |                         |                        |
18353f32880SWenjing Liu  *       | ODM slice 0             | ODM slice 1            |
18453f32880SWenjing Liu  *       |_________________________|________________________|
18553f32880SWenjing Liu  *
18653f32880SWenjing Liu  *       Timing Active for Stream 1
18753f32880SWenjing Liu  *        __________________________________________________
18853f32880SWenjing Liu  *       |OTG master 4 (OPP head 4)                         |
18953f32880SWenjing Liu  *       |                                                  |
19053f32880SWenjing Liu  *       |                                                  |
19153f32880SWenjing Liu  *       |                                                  |
19253f32880SWenjing Liu  *       |                                                  |
19353f32880SWenjing Liu  *       |                                                  |
19453f32880SWenjing Liu  *       |               Blank Pixel Data                   |
19553f32880SWenjing Liu  *       |              (generated by DPG4)                 |
19653f32880SWenjing Liu  *       |                                                  |
19753f32880SWenjing Liu  *       |                                                  |
19853f32880SWenjing Liu  *       |                                                  |
19953f32880SWenjing Liu  *       |                                                  |
20053f32880SWenjing Liu  *       |                                                  |
20153f32880SWenjing Liu  *       |__________________________________________________|
20253f32880SWenjing Liu  *
20353f32880SWenjing Liu  *       Inter-pipe Relation
20453f32880SWenjing Liu  *        __________________________________________________
20553f32880SWenjing Liu  *       |PIPE IDX|   DPP PIPES   | OPP HEADS | OTG MASTER  |
20653f32880SWenjing Liu  *       |        |  plane 0      | slice 0   |             |
20753f32880SWenjing Liu  *       |   0    | -------------MPC---------ODM----------- |
20853f32880SWenjing Liu  *       |        |  plane 1    | |         | |             |
20953f32880SWenjing Liu  *       |   1    | ------------- |         | |             |
21053f32880SWenjing Liu  *       |        |  plane 0      | slice 1 | |             |
21153f32880SWenjing Liu  *       |   2    | -------------MPC--------- |             |
21253f32880SWenjing Liu  *       |        |  plane 1    | |           |             |
21353f32880SWenjing Liu  *       |   3    | ------------- |           |             |
21453f32880SWenjing Liu  *       |        |               | blank     |             |
21553f32880SWenjing Liu  *       |   4    |               | ----------------------- |
21653f32880SWenjing Liu  *       |        |               |           |             |
21753f32880SWenjing Liu  *       |   5    |  (FREE)       |           |             |
21853f32880SWenjing Liu  *       |________|_______________|___________|_____________|
2197b0c688dSWenjing Liu  *
2207b0c688dSWenjing Liu  * The following is a quick reference of the class relation:
2217b0c688dSWenjing Liu  *
2227b0c688dSWenjing Liu  *	DC state            ---1--------0..N---           streams
2237b0c688dSWenjing Liu  *
2247b0c688dSWenjing Liu  *	stream              ---1-----------1---           OTG Master pipe
2257b0c688dSWenjing Liu  *
2267b0c688dSWenjing Liu  *	OTG Master pipe     ---1--------1..N---           OPP Head pipes
2277b0c688dSWenjing Liu  *
2287b0c688dSWenjing Liu  *	OPP Head pipe       ---1--------0..N---           DPP pipes
2297b0c688dSWenjing Liu  *
2307b0c688dSWenjing Liu  *	stream              ---1--------0..N---           Planes
2317b0c688dSWenjing Liu  *
2327b0c688dSWenjing Liu  *	Plane               ---1--------1..N---           DPP pipes
2337b0c688dSWenjing Liu  *
23453f32880SWenjing Liu  */
23553f32880SWenjing Liu enum pipe_type {
23653f32880SWenjing Liu 	/* free pipe - free pipe is an uninitialized pipe without a stream
23753f32880SWenjing Liu 	 * associated with it. It is a free DCN pipe resource. It can be
23853f32880SWenjing Liu 	 * acquired as any type of pipe.
23953f32880SWenjing Liu 	 */
24053f32880SWenjing Liu 	FREE_PIPE,
24153f32880SWenjing Liu 
24253f32880SWenjing Liu 	/* OTG master pipe - the master pipe of its OPP head pipes with a
24353f32880SWenjing Liu 	 * functional OTG. It merges all its OPP head pipes pixel data in ODM
24453f32880SWenjing Liu 	 * block and output to back end DIG. OTG master pipe is responsible for
24521741810SWenjing Liu 	 * generating entire CRTC timing to back end DIG. An OTG master pipe may
24653f32880SWenjing Liu 	 * or may not have a plane. If it has a plane it blends it as the left
24753f32880SWenjing Liu 	 * most MPC slice of the top most layer. If it doesn't have a plane it
24853f32880SWenjing Liu 	 * can output pixel data from its OPP head pipes' test pattern
24953f32880SWenjing Liu 	 * generators (DPG) such as solid black pixel data to blank the screen.
25053f32880SWenjing Liu 	 */
25153f32880SWenjing Liu 	OTG_MASTER,
25253f32880SWenjing Liu 
25353f32880SWenjing Liu 	/* OPP head pipe - the head pipe of an MPC blending tree with a
25453f32880SWenjing Liu 	 * functional OPP outputting to an OTG. OPP head pipe is responsible for
25553f32880SWenjing Liu 	 * processing output pixels in its own ODM slice. It may or may not have
25653f32880SWenjing Liu 	 * a plane. If it has a plane it blends it as the top most layer within
25753f32880SWenjing Liu 	 * its own ODM slice. If it doesn't have a plane it can output pixel
25853f32880SWenjing Liu 	 * data from its DPG such as solid black pixel data to blank the pixel
25953f32880SWenjing Liu 	 * data in its own ODM slice. OTG master pipe is also an OPP head pipe
26053f32880SWenjing Liu 	 * but with more responsibility.
26153f32880SWenjing Liu 	 */
26253f32880SWenjing Liu 	OPP_HEAD,
26353f32880SWenjing Liu 
26453f32880SWenjing Liu 	/* DPP pipe - the pipe with a functional DPP outputting to an OPP head
26553f32880SWenjing Liu 	 * pipe's MPC. DPP pipe is responsible for processing pixel data from
26653f32880SWenjing Liu 	 * its own MPC slice of a plane. It must be connected to an OPP head
26753f32880SWenjing Liu 	 * pipe and it must have a plane associated with it.
26853f32880SWenjing Liu 	 */
26953f32880SWenjing Liu 	DPP_PIPE,
27053f32880SWenjing Liu };
27153f32880SWenjing Liu 
27253f32880SWenjing Liu /*
27321741810SWenjing Liu  * Determine if the input pipe_ctx is of a pipe type.
27421741810SWenjing Liu  * return - true if pipe_ctx is of the input type.
27553f32880SWenjing Liu  */
27653f32880SWenjing Liu bool resource_is_pipe_type(const struct pipe_ctx *pipe_ctx, enum pipe_type type);
27753f32880SWenjing Liu 
27853f32880SWenjing Liu /*
27921741810SWenjing Liu  * Acquire a pipe as OTG master pipe and allocate pipe resources required to
28021741810SWenjing Liu  * enable stream output.
28153f32880SWenjing Liu  */
28221741810SWenjing Liu enum dc_status resource_add_otg_master_for_stream_output(struct dc_state *new_ctx,
28321741810SWenjing Liu 		const struct resource_pool *pool,
28421741810SWenjing Liu 		struct dc_stream_state *stream);
28521741810SWenjing Liu 
28621741810SWenjing Liu /*
28721741810SWenjing Liu  * Release pipe resources and the OTG master pipe associated with the stream
28821741810SWenjing Liu  * The stream must have all planes removed and ODM/MPC slice counts are reset
28921741810SWenjing Liu  * to 1 before invoking this interface.
29021741810SWenjing Liu  */
29121741810SWenjing Liu void resource_remove_otg_master_for_stream_output(struct dc_state *new_ctx,
29221741810SWenjing Liu 		const struct resource_pool *pool,
29321741810SWenjing Liu 		struct dc_stream_state *stream);
29421741810SWenjing Liu 
29521741810SWenjing Liu /*
29621741810SWenjing Liu  * Add plane to the bottom most layer in plane composition and allocate DPP pipe
29721741810SWenjing Liu  * resources as needed.
29821741810SWenjing Liu  * return - true if plane is added in plane composition, false otherwise.
29921741810SWenjing Liu  */
30021741810SWenjing Liu bool resource_append_dpp_pipes_for_plane_composition(
30121741810SWenjing Liu 		struct dc_state *new_ctx,
30221741810SWenjing Liu 		struct dc_state *cur_ctx,
30321741810SWenjing Liu 		struct resource_pool *pool,
30421741810SWenjing Liu 		struct pipe_ctx *otg_master_pipe,
30521741810SWenjing Liu 		struct dc_plane_state *plane_state);
30621741810SWenjing Liu 
30721741810SWenjing Liu /*
30821741810SWenjing Liu  * Add plane to the bottom most layer in plane composition and allocate DPP pipe
30921741810SWenjing Liu  * resources as needed.
31021741810SWenjing Liu  * return - true if plane is added in plane composition, false otherwise.
31121741810SWenjing Liu  */
31221741810SWenjing Liu void resource_remove_dpp_pipes_for_plane_composition(
31321741810SWenjing Liu 		struct dc_state *context,
31421741810SWenjing Liu 		const struct resource_pool *pool,
31521741810SWenjing Liu 		const struct dc_plane_state *plane_state);
31621741810SWenjing Liu 
31721741810SWenjing Liu /*
31821741810SWenjing Liu  * Update ODM slice count by acquiring or releasing pipes. If new slices need
31921741810SWenjing Liu  * to be added, it is going to add them to the last ODM index. If existing
32021741810SWenjing Liu  * slices need to be removed, it is going to remove them from the last ODM
32121741810SWenjing Liu  * index.
32221741810SWenjing Liu  *
32321741810SWenjing Liu  * return - true if ODM slices are updated and required pipes are acquired. All
32421741810SWenjing Liu  * affected pipe parameters are updated.
32521741810SWenjing Liu  *
32621741810SWenjing Liu  * false if resource fails to complete this update. The function is not designed
32721741810SWenjing Liu  * to recover the creation of invalid topologies. Returning false is typically
32821741810SWenjing Liu  * an indication of insufficient validation in caller's stack. new_ctx will be
32921741810SWenjing Liu  * invalid. Caller may attempt to restore new_ctx by calling this function
33021741810SWenjing Liu  * again with original slice count.
33121741810SWenjing Liu  */
33221741810SWenjing Liu bool resource_update_pipes_for_stream_with_slice_count(
33321741810SWenjing Liu 		struct dc_state *new_ctx,
33421741810SWenjing Liu 		const struct dc_state *cur_ctx,
33521741810SWenjing Liu 		const struct resource_pool *pool,
33621741810SWenjing Liu 		const struct dc_stream_state *stream,
33721741810SWenjing Liu 		int new_slice_count);
33821741810SWenjing Liu 
33921741810SWenjing Liu /*
34021741810SWenjing Liu  * Update MPC slice count by acquiring or releasing DPP pipes. If new slices
34121741810SWenjing Liu  * need to be added it is going to add to the last MPC index. If existing
34221741810SWenjing Liu  * slices need to be removed, it is going to remove them from the last MPC
34321741810SWenjing Liu  * index.
34421741810SWenjing Liu  *
34521741810SWenjing Liu  * @dpp_pipe - top most dpp pipe for MPCC combine.
34621741810SWenjing Liu  *
34721741810SWenjing Liu  * return - true if MPC slices are updated and required pipes are acquired. All
34821741810SWenjing Liu  * affected pipe parameters are updated.
34921741810SWenjing Liu  *
35021741810SWenjing Liu  * false if resource fails to complete this update. The function is not designed
35121741810SWenjing Liu  * to recover the creation of invalid topologies. Returning false is typically
35221741810SWenjing Liu  * an indication of insufficient validation in caller's stack. new_ctx will be
35321741810SWenjing Liu  * invalid. Caller may attempt to restore new_ctx by calling this function
35421741810SWenjing Liu  * again with original slice count.
35521741810SWenjing Liu  */
35621741810SWenjing Liu bool resource_update_pipes_for_plane_with_slice_count(
35721741810SWenjing Liu 		struct dc_state *new_ctx,
35821741810SWenjing Liu 		const struct dc_state *cur_ctx,
35921741810SWenjing Liu 		const struct resource_pool *pool,
36021741810SWenjing Liu 		const struct dc_plane_state *plane,
36121741810SWenjing Liu 		int slice_count);
36221741810SWenjing Liu 
36321741810SWenjing Liu /*
36421741810SWenjing Liu  * Get the OTG master pipe in resource context associated with the stream.
36521741810SWenjing Liu  * return - NULL if not found. Otherwise the OTG master pipe associated with the
36621741810SWenjing Liu  * stream.
36721741810SWenjing Liu  */
36821741810SWenjing Liu struct pipe_ctx *resource_get_otg_master_for_stream(
36921741810SWenjing Liu 		struct resource_context *res_ctx,
37021741810SWenjing Liu 		const struct dc_stream_state *stream);
37121741810SWenjing Liu 
37221741810SWenjing Liu /*
37321741810SWenjing Liu  * Get an array of OPP heads in opp_heads ordered with index low to high for OTG
37421741810SWenjing Liu  * master pipe in res_ctx.
37521741810SWenjing Liu  * return - number of OPP heads in the array. If otg_master passed in is not
37621741810SWenjing Liu  * an OTG master, the function returns 0.
37721741810SWenjing Liu  */
37821741810SWenjing Liu int resource_get_opp_heads_for_otg_master(const struct pipe_ctx *otg_master,
37921741810SWenjing Liu 		struct resource_context *res_ctx,
38021741810SWenjing Liu 		struct pipe_ctx *opp_heads[MAX_PIPES]);
38121741810SWenjing Liu 
38221741810SWenjing Liu /*
38321741810SWenjing Liu  * Get an array of DPP pipes in dpp_pipes ordered with index low to high for OPP
38421741810SWenjing Liu  * head pipe in res_ctx.
38521741810SWenjing Liu  * return - number of DPP pipes in the array. If opp_head passed in is not
38621741810SWenjing Liu  * an OPP pipe, the function returns 0.
38721741810SWenjing Liu  */
38821741810SWenjing Liu int resource_get_dpp_pipes_for_opp_head(const struct pipe_ctx *opp_head,
38921741810SWenjing Liu 		struct resource_context *res_ctx,
39021741810SWenjing Liu 		struct pipe_ctx *dpp_pipes[MAX_PIPES]);
39121741810SWenjing Liu 
39221741810SWenjing Liu /*
39321741810SWenjing Liu  * Get an array of DPP pipes in dpp_pipes ordered with index low to high for
39421741810SWenjing Liu  * plane in res_ctx.
39521741810SWenjing Liu  * return - number of DPP pipes in the array.
39621741810SWenjing Liu  */
39721741810SWenjing Liu int resource_get_dpp_pipes_for_plane(const struct dc_plane_state *plane,
39821741810SWenjing Liu 		struct resource_context *res_ctx,
39921741810SWenjing Liu 		struct pipe_ctx *dpp_pipes[MAX_PIPES]);
40021741810SWenjing Liu 
40121741810SWenjing Liu /*
40221741810SWenjing Liu  * Get the OTG master pipe for the input pipe context.
40321741810SWenjing Liu  * return - the OTG master pipe for the input pipe
40421741810SWenjing Liu  * context.
40521741810SWenjing Liu  */
40621741810SWenjing Liu struct pipe_ctx *resource_get_otg_master(const struct pipe_ctx *pipe_ctx);
40721741810SWenjing Liu 
40821741810SWenjing Liu /*
40921741810SWenjing Liu  * Get the OPP head pipe for the input pipe context.
41021741810SWenjing Liu  * return - the OPP head pipe for the input pipe
41121741810SWenjing Liu  * context.
41221741810SWenjing Liu  */
41321741810SWenjing Liu struct pipe_ctx *resource_get_opp_head(const struct pipe_ctx *pipe_ctx);
41421741810SWenjing Liu 
41521741810SWenjing Liu /*
416173db0c8SWenjing Liu  * Get the DPP pipe allocated for MPC slice 0 and ODM slice 0 of the plane
417173db0c8SWenjing Liu  * associated with dpp_pipe.
418173db0c8SWenjing Liu  */
419173db0c8SWenjing Liu struct pipe_ctx *resource_get_primary_dpp_pipe(const struct pipe_ctx *dpp_pipe);
420173db0c8SWenjing Liu 
421173db0c8SWenjing Liu /*
42221741810SWenjing Liu  * Get the MPC slice index counting from 0 from left most slice
42321741810SWenjing Liu  * For example, if a DPP pipe is used as a secondary pipe in MPCC combine, MPC
42421741810SWenjing Liu  * split index is greater than 0.
42521741810SWenjing Liu  */
42621741810SWenjing Liu int resource_get_mpc_slice_index(const struct pipe_ctx *dpp_pipe);
42721741810SWenjing Liu 
42821741810SWenjing Liu /*
4290a5fd781SWenjing Liu  * Get the number of MPC slices associated with the pipe.
4300a5fd781SWenjing Liu  * The function returns 0 if the pipe is not associated with an MPC combine
4310a5fd781SWenjing Liu  * pipe topology.
43221741810SWenjing Liu  */
4330a5fd781SWenjing Liu int resource_get_mpc_slice_count(const struct pipe_ctx *pipe);
43421741810SWenjing Liu 
43521741810SWenjing Liu /*
4360a5fd781SWenjing Liu  * Get the number of ODM slices associated with the pipe.
4370a5fd781SWenjing Liu  * The function returns 0 if the pipe is not associated with an ODM combine
4380a5fd781SWenjing Liu  * pipe topology.
43921741810SWenjing Liu  */
4400a5fd781SWenjing Liu int resource_get_odm_slice_count(const struct pipe_ctx *pipe);
44121741810SWenjing Liu 
44221741810SWenjing Liu /* Get the ODM slice index counting from 0 from left most slice */
44321741810SWenjing Liu int resource_get_odm_slice_index(const struct pipe_ctx *opp_head);
44453f32880SWenjing Liu 
445d5192c15SWenjing Liu /* Get ODM slice source rect in timing active as input to OPP block */
446d5192c15SWenjing Liu struct rect resource_get_odm_slice_src_rect(struct pipe_ctx *pipe_ctx);
447d5192c15SWenjing Liu 
448d5192c15SWenjing Liu /* Get ODM slice destination rect in timing active as output from OPP block */
449d5192c15SWenjing Liu struct rect resource_get_odm_slice_dst_rect(struct pipe_ctx *pipe_ctx);
450d5192c15SWenjing Liu 
451d5192c15SWenjing Liu /* Get ODM slice destination width in timing active as output from OPP block */
452d5192c15SWenjing Liu int resource_get_odm_slice_dst_width(struct pipe_ctx *otg_master,
453d5192c15SWenjing Liu 		bool is_last_segment);
454d5192c15SWenjing Liu 
455d8bafc2bSWenjing Liu /* determine if pipe topology is changed between state a and state b */
456d8bafc2bSWenjing Liu bool resource_is_pipe_topology_changed(const struct dc_state *state_a,
457d8bafc2bSWenjing Liu 		const struct dc_state *state_b);
458d8bafc2bSWenjing Liu 
459d8494349SWenjing Liu /*
460d8494349SWenjing Liu  * determine if the two OTG master pipes have the same ODM topology
461d8494349SWenjing Liu  * return
462d8494349SWenjing Liu  * false - if pipes passed in are not OTG masters or ODM topology is
463d8494349SWenjing Liu  * changed.
464d8494349SWenjing Liu  * true - otherwise
465d8494349SWenjing Liu  */
466d8494349SWenjing Liu bool resource_is_odm_topology_changed(const struct pipe_ctx *otg_master_a,
467d8494349SWenjing Liu 		const struct pipe_ctx *otg_master_b);
468d8494349SWenjing Liu 
469d8bafc2bSWenjing Liu /* log the pipe topology update in state */
470d8bafc2bSWenjing Liu void resource_log_pipe_topology_update(struct dc *dc, struct dc_state *state);
471d8bafc2bSWenjing Liu 
47253f32880SWenjing Liu /*
4736b8333a5SWenjing Liu  * Look for a free pipe in new resource context that is used as a secondary OPP
4746b8333a5SWenjing Liu  * head by cur_otg_master.
4756b8333a5SWenjing Liu  *
4766b8333a5SWenjing Liu  * return - FREE_PIPE_INDEX_NOT_FOUND if free pipe is not found, otherwise
4776b8333a5SWenjing Liu  * pipe idx of the free pipe
4786b8333a5SWenjing Liu  */
4796b8333a5SWenjing Liu int resource_find_free_pipe_used_as_sec_opp_head_by_cur_otg_master(
4806b8333a5SWenjing Liu 		const struct resource_context *cur_res_ctx,
4816b8333a5SWenjing Liu 		struct resource_context *new_res_ctx,
4826b8333a5SWenjing Liu 		const struct pipe_ctx *cur_otg_master);
4836b8333a5SWenjing Liu 
4846b8333a5SWenjing Liu /*
48553f32880SWenjing Liu  * Look for a free pipe in new resource context that is used as a secondary DPP
48653f32880SWenjing Liu  * pipe in MPC blending tree associated with input OPP head pipe.
48753f32880SWenjing Liu  *
48853f32880SWenjing Liu  * return - FREE_PIPE_INDEX_NOT_FOUND if free pipe is not found, otherwise
48953f32880SWenjing Liu  * pipe idx of the free pipe
49053f32880SWenjing Liu  */
491198f0e89SWenjing Liu int resource_find_free_pipe_used_in_cur_mpc_blending_tree(
492460ea898SWenjing Liu 		const struct resource_context *cur_res_ctx,
493460ea898SWenjing Liu 		struct resource_context *new_res_ctx,
494d8e3fcd3SWenjing Liu 		const struct pipe_ctx *cur_opp_head);
495d8e3fcd3SWenjing Liu 
49653f32880SWenjing Liu /*
49753f32880SWenjing Liu  * Look for a free pipe in new resource context that is not used in current
49853f32880SWenjing Liu  * resource context.
49953f32880SWenjing Liu  *
50053f32880SWenjing Liu  * return - FREE_PIPE_INDEX_NOT_FOUND if free pipe is not found, otherwise
50153f32880SWenjing Liu  * pipe idx of the free pipe
50253f32880SWenjing Liu  */
503198f0e89SWenjing Liu int recource_find_free_pipe_not_used_in_cur_res_ctx(
504d8e3fcd3SWenjing Liu 		const struct resource_context *cur_res_ctx,
505d8e3fcd3SWenjing Liu 		struct resource_context *new_res_ctx,
506d8e3fcd3SWenjing Liu 		const struct resource_pool *pool);
507d8e3fcd3SWenjing Liu 
50853f32880SWenjing Liu /*
509673d6d73SWenjing Liu  * Look for a free pipe in new resource context that is used in current resource
510673d6d73SWenjing Liu  * context as an OTG master pipe.
511673d6d73SWenjing Liu  *
512673d6d73SWenjing Liu  * return - FREE_PIPE_INDEX_NOT_FOUND if free pipe is not found, otherwise
513673d6d73SWenjing Liu  * pipe idx of the free pipe
514673d6d73SWenjing Liu  */
515673d6d73SWenjing Liu int recource_find_free_pipe_used_as_otg_master_in_cur_res_ctx(
516673d6d73SWenjing Liu 		const struct resource_context *cur_res_ctx,
517673d6d73SWenjing Liu 		struct resource_context *new_res_ctx,
518673d6d73SWenjing Liu 		const struct resource_pool *pool);
519673d6d73SWenjing Liu 
520673d6d73SWenjing Liu /*
52153f32880SWenjing Liu  * Look for a free pipe in new resource context that is used as a secondary DPP
52257b1ce83SWenjing Liu  * pipe in current resource context.
52357b1ce83SWenjing Liu  * return - FREE_PIPE_INDEX_NOT_FOUND if free pipe is not found, otherwise
52457b1ce83SWenjing Liu  * pipe idx of the free pipe
52557b1ce83SWenjing Liu  */
52657b1ce83SWenjing Liu int resource_find_free_pipe_used_as_cur_sec_dpp(
52757b1ce83SWenjing Liu 		const struct resource_context *cur_res_ctx,
52857b1ce83SWenjing Liu 		struct resource_context *new_res_ctx,
52957b1ce83SWenjing Liu 		const struct resource_pool *pool);
53057b1ce83SWenjing Liu 
53157b1ce83SWenjing Liu /*
53257b1ce83SWenjing Liu  * Look for a free pipe in new resource context that is used as a secondary DPP
53353f32880SWenjing Liu  * pipe in any MPCC combine in current resource context.
53453f32880SWenjing Liu  * return - FREE_PIPE_INDEX_NOT_FOUND if free pipe is not found, otherwise
53553f32880SWenjing Liu  * pipe idx of the free pipe
53653f32880SWenjing Liu  */
537198f0e89SWenjing Liu int resource_find_free_pipe_used_as_cur_sec_dpp_in_mpcc_combine(
538d8e3fcd3SWenjing Liu 		const struct resource_context *cur_res_ctx,
539d8e3fcd3SWenjing Liu 		struct resource_context *new_res_ctx,
540d8e3fcd3SWenjing Liu 		const struct resource_pool *pool);
541d8e3fcd3SWenjing Liu 
54253f32880SWenjing Liu /*
54353f32880SWenjing Liu  * Look for any free pipe in new resource context.
54453f32880SWenjing Liu  * return - FREE_PIPE_INDEX_NOT_FOUND if free pipe is not found, otherwise
54553f32880SWenjing Liu  * pipe idx of the free pipe
54653f32880SWenjing Liu  */
547198f0e89SWenjing Liu int resource_find_any_free_pipe(struct resource_context *new_res_ctx,
548d8e3fcd3SWenjing Liu 		const struct resource_pool *pool);
549460ea898SWenjing Liu 
55053f32880SWenjing Liu /*
55153f32880SWenjing Liu  * Legacy find free secondary pipe logic deprecated for newer DCNs as it doesn't
55253f32880SWenjing Liu  * find the most optimal free pipe to prevent from time consuming hardware state
55353f32880SWenjing Liu  * transitions.
55453f32880SWenjing Liu  */
55553f32880SWenjing Liu struct pipe_ctx *resource_find_free_secondary_pipe_legacy(
55653f32880SWenjing Liu 		struct resource_context *res_ctx,
55753f32880SWenjing Liu 		const struct resource_pool *pool,
55853f32880SWenjing Liu 		const struct pipe_ctx *primary_pipe);
55953f32880SWenjing Liu 
5604562236bSHarry Wentland bool resource_validate_attach_surfaces(
5614562236bSHarry Wentland 		const struct dc_validation_set set[],
5624562236bSHarry Wentland 		int set_count,
563608ac7bbSJerry Zuo 		const struct dc_state *old_context,
564608ac7bbSJerry Zuo 		struct dc_state *context,
565a2b8659dSTony Cheng 		const struct resource_pool *pool);
5664562236bSHarry Wentland 
5674562236bSHarry Wentland enum dc_status resource_map_clock_resources(
568fb3466a4SBhawanpreet Lakha 		const struct dc *dc,
569608ac7bbSJerry Zuo 		struct dc_state *context,
5701dc90497SAndrey Grodzovsky 		struct dc_stream_state *stream);
5714562236bSHarry Wentland 
5724562236bSHarry Wentland enum dc_status resource_map_phy_clock_resources(
573fb3466a4SBhawanpreet Lakha 		const struct dc *dc,
574608ac7bbSJerry Zuo 		struct dc_state *context,
5751dc90497SAndrey Grodzovsky 		struct dc_stream_state *stream);
5764562236bSHarry Wentland 
5774562236bSHarry Wentland bool pipe_need_reprogram(
5784562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx_old,
5794562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx);
5804562236bSHarry Wentland 
5810971c40eSHarry Wentland void resource_build_bit_depth_reduction_params(struct dc_stream_state *stream,
582529cad0fSDing Wang 		struct bit_depth_reduction_params *fmt_bit_depth);
5834562236bSHarry Wentland 
5844176664bSCharlene Liu void update_audio_usage(
5854176664bSCharlene Liu 		struct resource_context *res_ctx,
5864176664bSCharlene Liu 		const struct resource_pool *pool,
5874176664bSCharlene Liu 		struct audio *audio,
5884176664bSCharlene Liu 		bool acquired);
58974eac5f3SSu Sung Chung 
59074eac5f3SSu Sung Chung unsigned int resource_pixel_format_to_bpp(enum surface_pixel_format format);
59174eac5f3SSu Sung Chung 
5922426d71cSWenjing Liu bool get_temp_dp_link_res(struct dc_link *link,
5932426d71cSWenjing Liu 		struct link_resource *link_res,
5942426d71cSWenjing Liu 		struct dc_link_settings *link_settings);
595f01ee019SFangzhi Zuo 
5965f0c7491SMeenakshikumar Somasundaram void reset_syncd_pipes_from_disabled_pipes(struct dc *dc,
5975f0c7491SMeenakshikumar Somasundaram 	struct dc_state *context);
5985f0c7491SMeenakshikumar Somasundaram 
5995f0c7491SMeenakshikumar Somasundaram void check_syncd_pipes_for_disabled_master_pipe(struct dc *dc,
6005f0c7491SMeenakshikumar Somasundaram 	struct dc_state *context,
6015f0c7491SMeenakshikumar Somasundaram 	uint8_t disabled_master_pipe_idx);
6025f0c7491SMeenakshikumar Somasundaram 
603abffd871SMeenakshikumar Somasundaram void reset_sync_context_for_pipe(const struct dc *dc,
604abffd871SMeenakshikumar Somasundaram 	struct dc_state *context,
605abffd871SMeenakshikumar Somasundaram 	uint8_t pipe_idx);
606abffd871SMeenakshikumar Somasundaram 
607580013b2SWenjing Liu uint8_t resource_transmitter_to_phy_idx(const struct dc *dc, enum transmitter transmitter);
608a896f870SMeenakshikumar Somasundaram 
6092750caffSWenjing Liu const struct link_hwss *get_link_hwss(const struct dc_link *link,
6102750caffSWenjing Liu 		const struct link_resource *link_res);
6112750caffSWenjing Liu 
6126349c738SAlvin Lee bool is_h_timing_divisible_by_2(struct dc_stream_state *stream);
6136349c738SAlvin Lee 
6147b0c688dSWenjing Liu bool dc_resource_acquire_secondary_pipe_for_mpc_odm_legacy(
61520dad381SJun Lei 		const struct dc *dc,
61620dad381SJun Lei 		struct dc_state *state,
61720dad381SJun Lei 		struct pipe_ctx *pri_pipe,
61820dad381SJun Lei 		struct pipe_ctx *sec_pipe,
61920dad381SJun Lei 		bool odm);
6200e8cf83aSWenjing Liu 
6210e8cf83aSWenjing Liu /* A test harness interface that modifies dp encoder resources in the given dc
6220e8cf83aSWenjing Liu  * state and bypasses the need to revalidate. The interface assumes that the
6230e8cf83aSWenjing Liu  * test harness interface is called with pre-validated link config stored in the
6240e8cf83aSWenjing Liu  * pipe_ctx and updates dp encoder resources according to the link config.
6250e8cf83aSWenjing Liu  */
6260e8cf83aSWenjing Liu enum dc_status update_dp_encoder_resources_for_test_harness(const struct dc *dc,
6270e8cf83aSWenjing Liu 		struct dc_state *context,
6280e8cf83aSWenjing Liu 		struct pipe_ctx *pipe_ctx);
629ddd5298cSAlvin Lee 
630ddd5298cSAlvin Lee bool check_subvp_sw_cursor_fallback_req(const struct dc *dc, struct dc_stream_state *stream);
6318cffa89bSDillon Varone 
63200c39110SAurabindo Pillai /* Get hw programming parameters container from pipe context
63300c39110SAurabindo Pillai  * @pipe_ctx: pipe context
63400c39110SAurabindo Pillai  * @dscl_prog_data: struct to hold programmable hw reg values
63500c39110SAurabindo Pillai  */
63600c39110SAurabindo Pillai struct dscl_prog_data *resource_get_dscl_prog_data(struct pipe_ctx *pipe_ctx);
6378cffa89bSDillon Varone /* Setup dc callbacks for dml2
6388cffa89bSDillon Varone  * @dc: the display core structure
6398cffa89bSDillon Varone  * @dml2_options: struct to hold callbacks
6408cffa89bSDillon Varone  */
6418cffa89bSDillon Varone void resource_init_common_dml2_callbacks(struct dc *dc, struct dml2_configuration_options *dml2_options);
6424af0d8ebSAustin Zheng 
6434af0d8ebSAustin Zheng /*
6444af0d8ebSAustin Zheng  *Calculate total DET allocated for all pipes for a given OTG_MASTER pipe
6454af0d8ebSAustin Zheng  */
6464af0d8ebSAustin Zheng int resource_calculate_det_for_stream(struct dc_state *state, struct pipe_ctx *otg_master);
647*9de60462SMichael Strauss 
648*9de60462SMichael Strauss bool resource_is_hpo_acquired(struct dc_state *context);
6494562236bSHarry Wentland #endif /* DRIVERS_GPU_DRM_AMD_DC_DEV_DC_INC_RESOURCE_H_ */
650