dm_services.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. /**
  26. * This file defines external dependencies of Display Core.
  27. */
  28. #ifndef __DM_SERVICES_H__
  29. #define __DM_SERVICES_H__
  30. /* TODO: remove when DC is complete. */
  31. #include "dm_services_types.h"
  32. #include "logger_interface.h"
  33. #include "link_service_types.h"
  34. #undef DEPRECATED
  35. struct dmub_srv;
  36. struct dc_dmub_srv;
  37. union dmub_rb_cmd;
  38. irq_handler_idx dm_register_interrupt(
  39. struct dc_context *ctx,
  40. struct dc_interrupt_params *int_params,
  41. interrupt_handler ih,
  42. void *handler_args);
  43. /*
  44. *
  45. * GPU registers access
  46. *
  47. */
  48. uint32_t dm_read_reg_func(const struct dc_context *ctx, uint32_t address,
  49. const char *func_name);
  50. /* enable for debugging new code, this adds 50k to the driver size. */
  51. /* #define DM_CHECK_ADDR_0 */
  52. void dm_write_reg_func(const struct dc_context *ctx, uint32_t address,
  53. uint32_t value, const char *func_name);
  54. #define dm_read_reg(ctx, address) \
  55. dm_read_reg_func(ctx, address, __func__)
  56. #define dm_write_reg(ctx, address, value) \
  57. dm_write_reg_func(ctx, address, value, __func__)
  58. static inline uint32_t dm_read_index_reg(
  59. const struct dc_context *ctx,
  60. enum cgs_ind_reg addr_space,
  61. uint32_t index)
  62. {
  63. return cgs_read_ind_register(ctx->cgs_device, addr_space, index);
  64. }
  65. static inline void dm_write_index_reg(
  66. const struct dc_context *ctx,
  67. enum cgs_ind_reg addr_space,
  68. uint32_t index,
  69. uint32_t value)
  70. {
  71. cgs_write_ind_register(ctx->cgs_device, addr_space, index, value);
  72. }
  73. static inline uint32_t get_reg_field_value_ex(
  74. uint32_t reg_value,
  75. uint32_t mask,
  76. uint8_t shift)
  77. {
  78. return (mask & reg_value) >> shift;
  79. }
  80. #define get_reg_field_value(reg_value, reg_name, reg_field)\
  81. get_reg_field_value_ex(\
  82. (reg_value),\
  83. reg_name ## __ ## reg_field ## _MASK,\
  84. reg_name ## __ ## reg_field ## __SHIFT)
  85. static inline uint32_t set_reg_field_value_ex(
  86. uint32_t reg_value,
  87. uint32_t value,
  88. uint32_t mask,
  89. uint8_t shift)
  90. {
  91. ASSERT(mask != 0);
  92. return (reg_value & ~mask) | (mask & (value << shift));
  93. }
  94. #define set_reg_field_value(reg_value, value, reg_name, reg_field)\
  95. (reg_value) = set_reg_field_value_ex(\
  96. (reg_value),\
  97. (value),\
  98. reg_name ## __ ## reg_field ## _MASK,\
  99. reg_name ## __ ## reg_field ## __SHIFT)
  100. uint32_t generic_reg_set_ex(const struct dc_context *ctx,
  101. uint32_t addr, uint32_t reg_val, int n,
  102. uint8_t shift1, uint32_t mask1, uint32_t field_value1, ...);
  103. uint32_t generic_reg_update_ex(const struct dc_context *ctx,
  104. uint32_t addr, int n,
  105. uint8_t shift1, uint32_t mask1, uint32_t field_value1, ...);
  106. struct dc_dmub_srv *dc_dmub_srv_create(struct dc *dc, struct dmub_srv *dmub);
  107. void dc_dmub_srv_destroy(struct dc_dmub_srv **dmub_srv);
  108. void reg_sequence_start_gather(const struct dc_context *ctx);
  109. void reg_sequence_start_execute(const struct dc_context *ctx);
  110. void reg_sequence_wait_done(const struct dc_context *ctx);
  111. #define FD(reg_field) reg_field ## __SHIFT, \
  112. reg_field ## _MASK
  113. /*
  114. * return number of poll before condition is met
  115. * return 0 if condition is not meet after specified time out tries
  116. */
  117. void generic_reg_wait(const struct dc_context *ctx,
  118. uint32_t addr, uint32_t mask, uint32_t shift, uint32_t condition_value,
  119. unsigned int delay_between_poll_us, unsigned int time_out_num_tries,
  120. const char *func_name, int line);
  121. unsigned int snprintf_count(char *pBuf, unsigned int bufSize, char *fmt, ...);
  122. /* These macros need to be used with soc15 registers in order to retrieve
  123. * the actual offset.
  124. */
  125. #define dm_write_reg_soc15(ctx, reg, inst_offset, value) \
  126. dm_write_reg_func(ctx, reg + DCE_BASE.instance[0].segment[reg##_BASE_IDX] + inst_offset, value, __func__)
  127. #define dm_read_reg_soc15(ctx, reg, inst_offset) \
  128. dm_read_reg_func(ctx, reg + DCE_BASE.instance[0].segment[reg##_BASE_IDX] + inst_offset, __func__)
  129. #define generic_reg_update_soc15(ctx, inst_offset, reg_name, n, ...)\
  130. generic_reg_update_ex(ctx, DCE_BASE.instance[0].segment[mm##reg_name##_BASE_IDX] + mm##reg_name + inst_offset, \
  131. n, __VA_ARGS__)
  132. #define generic_reg_set_soc15(ctx, inst_offset, reg_name, n, ...)\
  133. generic_reg_set_ex(ctx, DCE_BASE.instance[0].segment[mm##reg_name##_BASE_IDX] + mm##reg_name + inst_offset, 0, \
  134. n, __VA_ARGS__)
  135. #define get_reg_field_value_soc15(reg_value, block, reg_num, reg_name, reg_field)\
  136. get_reg_field_value_ex(\
  137. (reg_value),\
  138. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## _MASK,\
  139. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## __SHIFT)
  140. #define set_reg_field_value_soc15(reg_value, value, block, reg_num, reg_name, reg_field)\
  141. (reg_value) = set_reg_field_value_ex(\
  142. (reg_value),\
  143. (value),\
  144. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## _MASK,\
  145. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## __SHIFT)
  146. /**************************************
  147. * Power Play (PP) interfaces
  148. **************************************/
  149. /* Gets valid clocks levels from pplib
  150. *
  151. * input: clk_type - display clk / sclk / mem clk
  152. *
  153. * output: array of valid clock levels for given type in ascending order,
  154. * with invalid levels filtered out
  155. *
  156. */
  157. bool dm_pp_get_clock_levels_by_type(
  158. const struct dc_context *ctx,
  159. enum dm_pp_clock_type clk_type,
  160. struct dm_pp_clock_levels *clk_level_info);
  161. bool dm_pp_get_clock_levels_by_type_with_latency(
  162. const struct dc_context *ctx,
  163. enum dm_pp_clock_type clk_type,
  164. struct dm_pp_clock_levels_with_latency *clk_level_info);
  165. bool dm_pp_get_clock_levels_by_type_with_voltage(
  166. const struct dc_context *ctx,
  167. enum dm_pp_clock_type clk_type,
  168. struct dm_pp_clock_levels_with_voltage *clk_level_info);
  169. bool dm_pp_notify_wm_clock_changes(
  170. const struct dc_context *ctx,
  171. struct dm_pp_wm_sets_with_clock_ranges *wm_with_clock_ranges);
  172. void dm_pp_get_funcs(struct dc_context *ctx,
  173. struct pp_smu_funcs *funcs);
  174. /* DAL calls this function to notify PP about completion of Mode Set.
  175. * For PP it means that current DCE clocks are those which were returned
  176. * by dc_service_pp_pre_dce_clock_change(), in the 'output' parameter.
  177. *
  178. * If the clocks are higher than before, then PP does nothing.
  179. *
  180. * If the clocks are lower than before, then PP reduces the voltage.
  181. *
  182. * \returns true - call is successful
  183. * false - call failed
  184. */
  185. bool dm_pp_apply_display_requirements(
  186. const struct dc_context *ctx,
  187. const struct dm_pp_display_configuration *pp_display_cfg);
  188. bool dm_pp_apply_power_level_change_request(
  189. const struct dc_context *ctx,
  190. struct dm_pp_power_level_change_request *level_change_req);
  191. bool dm_pp_apply_clock_for_voltage_request(
  192. const struct dc_context *ctx,
  193. struct dm_pp_clock_for_voltage_req *clock_for_voltage_req);
  194. bool dm_pp_get_static_clocks(
  195. const struct dc_context *ctx,
  196. struct dm_pp_static_clock_info *static_clk_info);
  197. /****** end of PP interfaces ******/
  198. struct persistent_data_flag {
  199. bool save_per_link;
  200. bool save_per_edid;
  201. };
  202. bool dm_query_extended_brightness_caps
  203. (struct dc_context *ctx, enum dm_acpi_display_type display,
  204. struct dm_acpi_atif_backlight_caps *pCaps);
  205. bool dm_dmcu_set_pipe(struct dc_context *ctx, unsigned int controller_id);
  206. /*
  207. *
  208. * print-out services
  209. *
  210. */
  211. #define dm_log_to_buffer(buffer, size, fmt, args)\
  212. vsnprintf(buffer, size, fmt, args)
  213. static inline unsigned long long dm_get_timestamp(struct dc_context *ctx)
  214. {
  215. return ktime_get_raw_ns();
  216. }
  217. unsigned long long dm_get_elapse_time_in_ns(struct dc_context *ctx,
  218. unsigned long long current_time_stamp,
  219. unsigned long long last_time_stamp);
  220. /*
  221. * performance tracing
  222. */
  223. void dm_perf_trace_timestamp(const char *func_name, unsigned int line, struct dc_context *ctx);
  224. #define PERF_TRACE() dm_perf_trace_timestamp(__func__, __LINE__, CTX)
  225. #define PERF_TRACE_CTX(__CTX) dm_perf_trace_timestamp(__func__, __LINE__, __CTX)
  226. /*
  227. * SMU message tracing
  228. */
  229. void dm_trace_smu_msg(uint32_t msg_id, uint32_t param_in, struct dc_context *ctx);
  230. void dm_trace_smu_delay(uint32_t delay, struct dc_context *ctx);
  231. #define TRACE_SMU_MSG(msg_id, param_in, ctx) dm_trace_smu_msg(msg_id, param_in, ctx)
  232. #define TRACE_SMU_DELAY(response_delay, ctx) dm_trace_smu_delay(response_delay, ctx)
  233. /*
  234. * DMUB Interfaces
  235. */
  236. bool dm_execute_dmub_cmd(const struct dc_context *ctx, union dmub_rb_cmd *cmd, enum dm_dmub_wait_type wait_type);
  237. bool dm_execute_dmub_cmd_list(const struct dc_context *ctx, unsigned int count, union dmub_rb_cmd *cmd, enum dm_dmub_wait_type wait_type);
  238. /*
  239. * Debug and verification hooks
  240. */
  241. void dm_dtn_log_begin(struct dc_context *ctx,
  242. struct dc_log_buffer_ctx *log_ctx);
  243. void dm_dtn_log_append_v(struct dc_context *ctx,
  244. struct dc_log_buffer_ctx *log_ctx,
  245. const char *msg, ...);
  246. void dm_dtn_log_end(struct dc_context *ctx,
  247. struct dc_log_buffer_ctx *log_ctx);
  248. char *dce_version_to_string(const int version);
  249. #endif /* __DM_SERVICES_H__ */