1 /*
2  * Copyright 2015 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  */
24 
25 #ifndef DRIVERS_GPU_DRM_AMD_DC_DEV_DC_INC_RESOURCE_H_
26 #define DRIVERS_GPU_DRM_AMD_DC_DEV_DC_INC_RESOURCE_H_
27 
28 #include "core_types.h"
29 #include "core_status.h"
30 #include "dal_asic_id.h"
31 #include "dm_pp_smu.h"
32 
33 /* TODO unhardcode, 4 for CZ*/
34 #define MEMORY_TYPE_MULTIPLIER 4
35 
36 enum dce_version resource_parse_asic_id(
37 		struct hw_asic_id asic_id);
38 
39 struct resource_caps {
40 	int num_timing_generator;
41 	int num_opp;
42 	int num_video_plane;
43 	int num_audio;
44 	int num_stream_encoder;
45 	int num_pll;
46 	int num_dwb;
47 	int num_ddc;
48 };
49 
50 struct resource_straps {
51 	uint32_t hdmi_disable;
52 	uint32_t dc_pinstraps_audio;
53 	uint32_t audio_stream_number;
54 };
55 
56 struct resource_create_funcs {
57 	void (*read_dce_straps)(
58 			struct dc_context *ctx, struct resource_straps *straps);
59 
60 	struct audio *(*create_audio)(
61 			struct dc_context *ctx, unsigned int inst);
62 
63 	struct stream_encoder *(*create_stream_encoder)(
64 			enum engine_id eng_id, struct dc_context *ctx);
65 
66 	struct dce_hwseq *(*create_hwseq)(
67 			struct dc_context *ctx);
68 };
69 
70 bool resource_construct(
71 	unsigned int num_virtual_links,
72 	struct dc *dc,
73 	struct resource_pool *pool,
74 	const struct resource_create_funcs *create_funcs);
75 
76 struct resource_pool *dc_create_resource_pool(
77 				struct dc *dc,
78 				int num_virtual_links,
79 				enum dce_version dc_version,
80 				struct hw_asic_id asic_id);
81 
82 void dc_destroy_resource_pool(struct dc *dc);
83 
84 enum dc_status resource_map_pool_resources(
85 		const struct dc *dc,
86 		struct dc_state *context,
87 		struct dc_stream_state *stream);
88 
89 bool resource_build_scaling_params(struct pipe_ctx *pipe_ctx);
90 
91 enum dc_status resource_build_scaling_params_for_context(
92 		const struct dc *dc,
93 		struct dc_state *context);
94 
95 void resource_build_info_frame(struct pipe_ctx *pipe_ctx);
96 
97 void resource_unreference_clock_source(
98 		struct resource_context *res_ctx,
99 		const struct resource_pool *pool,
100 		struct clock_source *clock_source);
101 
102 void resource_reference_clock_source(
103 		struct resource_context *res_ctx,
104 		const struct resource_pool *pool,
105 		struct clock_source *clock_source);
106 
107 int resource_get_clock_source_reference(
108 		struct resource_context *res_ctx,
109 		const struct resource_pool *pool,
110 		struct clock_source *clock_source);
111 
112 bool resource_are_streams_timing_synchronizable(
113 		struct dc_stream_state *stream1,
114 		struct dc_stream_state *stream2);
115 
116 struct clock_source *resource_find_used_clk_src_for_sharing(
117 		struct resource_context *res_ctx,
118 		struct pipe_ctx *pipe_ctx);
119 
120 struct clock_source *dc_resource_find_first_free_pll(
121 		struct resource_context *res_ctx,
122 		const struct resource_pool *pool);
123 
124 struct pipe_ctx *resource_get_head_pipe_for_stream(
125 		struct resource_context *res_ctx,
126 		struct dc_stream_state *stream);
127 
128 bool resource_attach_surfaces_to_context(
129 		struct dc_plane_state *const *plane_state,
130 		int surface_count,
131 		struct dc_stream_state *dc_stream,
132 		struct dc_state *context,
133 		const struct resource_pool *pool);
134 
135 struct pipe_ctx *find_idle_secondary_pipe(
136 		struct resource_context *res_ctx,
137 		const struct resource_pool *pool);
138 
139 bool resource_is_stream_unchanged(
140 	struct dc_state *old_context, struct dc_stream_state *stream);
141 
142 bool resource_validate_attach_surfaces(
143 		const struct dc_validation_set set[],
144 		int set_count,
145 		const struct dc_state *old_context,
146 		struct dc_state *context,
147 		const struct resource_pool *pool);
148 
149 void resource_validate_ctx_update_pointer_after_copy(
150 		const struct dc_state *src_ctx,
151 		struct dc_state *dst_ctx);
152 
153 enum dc_status resource_map_clock_resources(
154 		const struct dc *dc,
155 		struct dc_state *context,
156 		struct dc_stream_state *stream);
157 
158 enum dc_status resource_map_phy_clock_resources(
159 		const struct dc *dc,
160 		struct dc_state *context,
161 		struct dc_stream_state *stream);
162 
163 bool pipe_need_reprogram(
164 		struct pipe_ctx *pipe_ctx_old,
165 		struct pipe_ctx *pipe_ctx);
166 
167 void resource_build_bit_depth_reduction_params(struct dc_stream_state *stream,
168 		struct bit_depth_reduction_params *fmt_bit_depth);
169 
170 void update_audio_usage(
171 		struct resource_context *res_ctx,
172 		const struct resource_pool *pool,
173 		struct audio *audio,
174 		bool acquired);
175 
176 unsigned int resource_pixel_format_to_bpp(enum surface_pixel_format format);
177 
178 #endif /* DRIVERS_GPU_DRM_AMD_DC_DEV_DC_INC_RESOURCE_H_ */
179