1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#ifndef __DM_SERVICES_H__
31
32#define __DM_SERVICES_H__
33
34#include "amdgpu_dm_trace.h"
35
36
37#include "dm_services_types.h"
38#include "logger_interface.h"
39#include "link_service_types.h"
40
41#undef DEPRECATED
42
43irq_handler_idx dm_register_interrupt(
44 struct dc_context *ctx,
45 struct dc_interrupt_params *int_params,
46 interrupt_handler ih,
47 void *handler_args);
48
49
50
51
52
53
54
55uint32_t dm_read_reg_func(
56 const struct dc_context *ctx,
57 uint32_t address,
58 const char *func_name);
59
60
61
62#define dm_read_reg(ctx, address) \
63 dm_read_reg_func(ctx, address, __func__)
64
65
66
67#define dm_write_reg(ctx, address, value) \
68 dm_write_reg_func(ctx, address, value, __func__)
69
70static inline void dm_write_reg_func(
71 const struct dc_context *ctx,
72 uint32_t address,
73 uint32_t value,
74 const char *func_name)
75{
76#ifdef DM_CHECK_ADDR_0
77 if (address == 0) {
78 DC_ERR("invalid register write. address = 0");
79 return;
80 }
81#endif
82 cgs_write_register(ctx->cgs_device, address, value);
83 trace_amdgpu_dc_wreg(&ctx->perf_trace->write_count, address, value);
84}
85
86static inline uint32_t dm_read_index_reg(
87 const struct dc_context *ctx,
88 enum cgs_ind_reg addr_space,
89 uint32_t index)
90{
91 return cgs_read_ind_register(ctx->cgs_device, addr_space, index);
92}
93
94static inline void dm_write_index_reg(
95 const struct dc_context *ctx,
96 enum cgs_ind_reg addr_space,
97 uint32_t index,
98 uint32_t value)
99{
100 cgs_write_ind_register(ctx->cgs_device, addr_space, index, value);
101}
102
103static inline uint32_t get_reg_field_value_ex(
104 uint32_t reg_value,
105 uint32_t mask,
106 uint8_t shift)
107{
108 return (mask & reg_value) >> shift;
109}
110
111#define get_reg_field_value(reg_value, reg_name, reg_field)\
112 get_reg_field_value_ex(\
113 (reg_value),\
114 reg_name ## __ ## reg_field ## _MASK,\
115 reg_name ## __ ## reg_field ## __SHIFT)
116
117static inline uint32_t set_reg_field_value_ex(
118 uint32_t reg_value,
119 uint32_t value,
120 uint32_t mask,
121 uint8_t shift)
122{
123 ASSERT(mask != 0);
124 return (reg_value & ~mask) | (mask & (value << shift));
125}
126
127#define set_reg_field_value(reg_value, value, reg_name, reg_field)\
128 (reg_value) = set_reg_field_value_ex(\
129 (reg_value),\
130 (value),\
131 reg_name ## __ ## reg_field ## _MASK,\
132 reg_name ## __ ## reg_field ## __SHIFT)
133
134uint32_t generic_reg_set_ex(const struct dc_context *ctx,
135 uint32_t addr, uint32_t reg_val, int n,
136 uint8_t shift1, uint32_t mask1, uint32_t field_value1, ...);
137
138uint32_t generic_reg_update_ex(const struct dc_context *ctx,
139 uint32_t addr, int n,
140 uint8_t shift1, uint32_t mask1, uint32_t field_value1, ...);
141
142#define FD(reg_field) reg_field ## __SHIFT, \
143 reg_field ## _MASK
144
145
146
147
148
149void generic_reg_wait(const struct dc_context *ctx,
150 uint32_t addr, uint32_t mask, uint32_t shift, uint32_t condition_value,
151 unsigned int delay_between_poll_us, unsigned int time_out_num_tries,
152 const char *func_name, int line);
153
154
155
156
157
158#define dm_write_reg_soc15(ctx, reg, inst_offset, value) \
159 dm_write_reg_func(ctx, reg + DCE_BASE.instance[0].segment[reg##_BASE_IDX] + inst_offset, value, __func__)
160
161#define dm_read_reg_soc15(ctx, reg, inst_offset) \
162 dm_read_reg_func(ctx, reg + DCE_BASE.instance[0].segment[reg##_BASE_IDX] + inst_offset, __func__)
163
164#define generic_reg_update_soc15(ctx, inst_offset, reg_name, n, ...)\
165 generic_reg_update_ex(ctx, DCE_BASE.instance[0].segment[mm##reg_name##_BASE_IDX] + mm##reg_name + inst_offset, \
166 n, __VA_ARGS__)
167
168#define generic_reg_set_soc15(ctx, inst_offset, reg_name, n, ...)\
169 generic_reg_set_ex(ctx, DCE_BASE.instance[0].segment[mm##reg_name##_BASE_IDX] + mm##reg_name + inst_offset, 0, \
170 n, __VA_ARGS__)
171
172#define get_reg_field_value_soc15(reg_value, block, reg_num, reg_name, reg_field)\
173 get_reg_field_value_ex(\
174 (reg_value),\
175 block ## reg_num ## _ ## reg_name ## __ ## reg_field ## _MASK,\
176 block ## reg_num ## _ ## reg_name ## __ ## reg_field ## __SHIFT)
177
178#define set_reg_field_value_soc15(reg_value, value, block, reg_num, reg_name, reg_field)\
179 (reg_value) = set_reg_field_value_ex(\
180 (reg_value),\
181 (value),\
182 block ## reg_num ## _ ## reg_name ## __ ## reg_field ## _MASK,\
183 block ## reg_num ## _ ## reg_name ## __ ## reg_field ## __SHIFT)
184
185
186
187
188
189
190
191
192
193
194
195
196
197bool dm_pp_get_clock_levels_by_type(
198 const struct dc_context *ctx,
199 enum dm_pp_clock_type clk_type,
200 struct dm_pp_clock_levels *clk_level_info);
201
202bool dm_pp_get_clock_levels_by_type_with_latency(
203 const struct dc_context *ctx,
204 enum dm_pp_clock_type clk_type,
205 struct dm_pp_clock_levels_with_latency *clk_level_info);
206
207bool dm_pp_get_clock_levels_by_type_with_voltage(
208 const struct dc_context *ctx,
209 enum dm_pp_clock_type clk_type,
210 struct dm_pp_clock_levels_with_voltage *clk_level_info);
211
212bool dm_pp_notify_wm_clock_changes(
213 const struct dc_context *ctx,
214 struct dm_pp_wm_sets_with_clock_ranges *wm_with_clock_ranges);
215
216void dm_pp_get_funcs(struct dc_context *ctx,
217 struct pp_smu_funcs *funcs);
218
219
220
221
222
223
224
225
226
227
228
229
230bool dm_pp_apply_display_requirements(
231 const struct dc_context *ctx,
232 const struct dm_pp_display_configuration *pp_display_cfg);
233
234bool dm_pp_apply_power_level_change_request(
235 const struct dc_context *ctx,
236 struct dm_pp_power_level_change_request *level_change_req);
237
238bool dm_pp_apply_clock_for_voltage_request(
239 const struct dc_context *ctx,
240 struct dm_pp_clock_for_voltage_req *clock_for_voltage_req);
241
242bool dm_pp_get_static_clocks(
243 const struct dc_context *ctx,
244 struct dm_pp_static_clock_info *static_clk_info);
245
246
247
248struct persistent_data_flag {
249 bool save_per_link;
250 bool save_per_edid;
251};
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280bool dm_write_persistent_data(struct dc_context *ctx,
281 const struct dc_sink *sink,
282 const char *module_name,
283 const char *key_name,
284 void *params,
285 unsigned int size,
286 struct persistent_data_flag *flag);
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314bool dm_read_persistent_data(struct dc_context *ctx,
315 const struct dc_sink *sink,
316 const char *module_name,
317 const char *key_name,
318 void *params,
319 unsigned int size,
320 struct persistent_data_flag *flag);
321
322bool dm_query_extended_brightness_caps
323 (struct dc_context *ctx, enum dm_acpi_display_type display,
324 struct dm_acpi_atif_backlight_caps *pCaps);
325
326bool dm_dmcu_set_pipe(struct dc_context *ctx, unsigned int controller_id);
327
328
329
330
331
332
333#define dm_log_to_buffer(buffer, size, fmt, args)\
334 vsnprintf(buffer, size, fmt, args)
335
336static inline unsigned long long dm_get_timestamp(struct dc_context *ctx)
337{
338 return ktime_get_raw_ns();
339}
340
341unsigned long long dm_get_elapse_time_in_ns(struct dc_context *ctx,
342 unsigned long long current_time_stamp,
343 unsigned long long last_time_stamp);
344
345
346
347
348#define PERF_TRACE() trace_amdgpu_dc_performance(CTX->perf_trace->read_count,\
349 CTX->perf_trace->write_count, &CTX->perf_trace->last_entry_read,\
350 &CTX->perf_trace->last_entry_write, __func__, __LINE__)
351#define PERF_TRACE_CTX(__CTX) trace_amdgpu_dc_performance(__CTX->perf_trace->read_count,\
352 __CTX->perf_trace->write_count, &__CTX->perf_trace->last_entry_read,\
353 &__CTX->perf_trace->last_entry_write, __func__, __LINE__)
354
355
356
357
358
359
360void dm_dtn_log_begin(struct dc_context *ctx,
361 struct dc_log_buffer_ctx *log_ctx);
362void dm_dtn_log_append_v(struct dc_context *ctx,
363 struct dc_log_buffer_ctx *log_ctx,
364 const char *msg, ...);
365void dm_dtn_log_end(struct dc_context *ctx,
366 struct dc_log_buffer_ctx *log_ctx);
367
368#endif
369