dm_services.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. irq_handler_idx dm_register_interrupt(
  36. struct dc_context *ctx,
  37. struct dc_interrupt_params *int_params,
  38. interrupt_handler ih,
  39. void *handler_args);
  40. /*
  41. *
  42. * GPU registers access
  43. *
  44. */
  45. /* enable for debugging new code, this adds 50k to the driver size. */
  46. /* #define DM_CHECK_ADDR_0 */
  47. #define dm_read_reg(ctx, address) \
  48. dm_read_reg_func(ctx, address, __func__)
  49. static inline uint32_t dm_read_reg_func(
  50. const struct dc_context *ctx,
  51. uint32_t address,
  52. const char *func_name)
  53. {
  54. uint32_t value;
  55. #ifdef DM_CHECK_ADDR_0
  56. if (address == 0) {
  57. DC_ERR("invalid register read; address = 0\n");
  58. return 0;
  59. }
  60. #endif
  61. value = cgs_read_register(ctx->cgs_device, address);
  62. return value;
  63. }
  64. #define dm_write_reg(ctx, address, value) \
  65. dm_write_reg_func(ctx, address, value, __func__)
  66. static inline void dm_write_reg_func(
  67. const struct dc_context *ctx,
  68. uint32_t address,
  69. uint32_t value,
  70. const char *func_name)
  71. {
  72. #ifdef DM_CHECK_ADDR_0
  73. if (address == 0) {
  74. DC_ERR("invalid register write. address = 0");
  75. return;
  76. }
  77. #endif
  78. cgs_write_register(ctx->cgs_device, address, value);
  79. }
  80. static inline uint32_t dm_read_index_reg(
  81. const struct dc_context *ctx,
  82. enum cgs_ind_reg addr_space,
  83. uint32_t index)
  84. {
  85. return cgs_read_ind_register(ctx->cgs_device, addr_space, index);
  86. }
  87. static inline void dm_write_index_reg(
  88. const struct dc_context *ctx,
  89. enum cgs_ind_reg addr_space,
  90. uint32_t index,
  91. uint32_t value)
  92. {
  93. cgs_write_ind_register(ctx->cgs_device, addr_space, index, value);
  94. }
  95. static inline uint32_t get_reg_field_value_ex(
  96. uint32_t reg_value,
  97. uint32_t mask,
  98. uint8_t shift)
  99. {
  100. return (mask & reg_value) >> shift;
  101. }
  102. #define get_reg_field_value(reg_value, reg_name, reg_field)\
  103. get_reg_field_value_ex(\
  104. (reg_value),\
  105. reg_name ## __ ## reg_field ## _MASK,\
  106. reg_name ## __ ## reg_field ## __SHIFT)
  107. static inline uint32_t set_reg_field_value_ex(
  108. uint32_t reg_value,
  109. uint32_t value,
  110. uint32_t mask,
  111. uint8_t shift)
  112. {
  113. ASSERT(mask != 0);
  114. return (reg_value & ~mask) | (mask & (value << shift));
  115. }
  116. #define set_reg_field_value(reg_value, value, reg_name, reg_field)\
  117. (reg_value) = set_reg_field_value_ex(\
  118. (reg_value),\
  119. (value),\
  120. reg_name ## __ ## reg_field ## _MASK,\
  121. reg_name ## __ ## reg_field ## __SHIFT)
  122. uint32_t generic_reg_update_ex(const struct dc_context *ctx,
  123. uint32_t addr, uint32_t reg_val, int n,
  124. uint8_t shift1, uint32_t mask1, uint32_t field_value1, ...);
  125. #define FD(reg_field) reg_field ## __SHIFT, \
  126. reg_field ## _MASK
  127. /*
  128. * return number of poll before condition is met
  129. * return 0 if condition is not meet after specified time out tries
  130. */
  131. unsigned int generic_reg_wait(const struct dc_context *ctx,
  132. uint32_t addr, uint32_t mask, uint32_t shift, uint32_t condition_value,
  133. unsigned int delay_between_poll_us, unsigned int time_out_num_tries,
  134. const char *func_name, int line);
  135. /* These macros need to be used with soc15 registers in order to retrieve
  136. * the actual offset.
  137. */
  138. #define dm_write_reg_soc15(ctx, reg, inst_offset, value) \
  139. dm_write_reg_func(ctx, reg + DCE_BASE.instance[0].segment[reg##_BASE_IDX] + inst_offset, value, __func__)
  140. #define dm_read_reg_soc15(ctx, reg, inst_offset) \
  141. dm_read_reg_func(ctx, reg + DCE_BASE.instance[0].segment[reg##_BASE_IDX] + inst_offset, __func__)
  142. #define generic_reg_update_soc15(ctx, inst_offset, reg_name, n, ...)\
  143. generic_reg_update_ex(ctx, DCE_BASE.instance[0].segment[mm##reg_name##_BASE_IDX] + mm##reg_name + inst_offset, \
  144. dm_read_reg_func(ctx, mm##reg_name + DCE_BASE.instance[0].segment[mm##reg_name##_BASE_IDX] + inst_offset, __func__), \
  145. n, __VA_ARGS__)
  146. #define generic_reg_set_soc15(ctx, inst_offset, reg_name, n, ...)\
  147. generic_reg_update_ex(ctx, DCE_BASE.instance[0].segment[mm##reg_name##_BASE_IDX] + mm##reg_name + inst_offset, 0, \
  148. n, __VA_ARGS__)
  149. #define get_reg_field_value_soc15(reg_value, block, reg_num, reg_name, reg_field)\
  150. get_reg_field_value_ex(\
  151. (reg_value),\
  152. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## _MASK,\
  153. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## __SHIFT)
  154. #define set_reg_field_value_soc15(reg_value, value, block, reg_num, reg_name, reg_field)\
  155. (reg_value) = set_reg_field_value_ex(\
  156. (reg_value),\
  157. (value),\
  158. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## _MASK,\
  159. block ## reg_num ## _ ## reg_name ## __ ## reg_field ## __SHIFT)
  160. /**************************************
  161. * Power Play (PP) interfaces
  162. **************************************/
  163. /* Gets valid clocks levels from pplib
  164. *
  165. * input: clk_type - display clk / sclk / mem clk
  166. *
  167. * output: array of valid clock levels for given type in ascending order,
  168. * with invalid levels filtered out
  169. *
  170. */
  171. bool dm_pp_get_clock_levels_by_type(
  172. const struct dc_context *ctx,
  173. enum dm_pp_clock_type clk_type,
  174. struct dm_pp_clock_levels *clk_level_info);
  175. bool dm_pp_get_clock_levels_by_type_with_latency(
  176. const struct dc_context *ctx,
  177. enum dm_pp_clock_type clk_type,
  178. struct dm_pp_clock_levels_with_latency *clk_level_info);
  179. bool dm_pp_get_clock_levels_by_type_with_voltage(
  180. const struct dc_context *ctx,
  181. enum dm_pp_clock_type clk_type,
  182. struct dm_pp_clock_levels_with_voltage *clk_level_info);
  183. bool dm_pp_notify_wm_clock_changes(
  184. const struct dc_context *ctx,
  185. struct dm_pp_wm_sets_with_clock_ranges *wm_with_clock_ranges);
  186. void dm_pp_get_funcs_rv(struct dc_context *ctx,
  187. struct pp_smu_funcs_rv *funcs);
  188. /* DAL calls this function to notify PP about completion of Mode Set.
  189. * For PP it means that current DCE clocks are those which were returned
  190. * by dc_service_pp_pre_dce_clock_change(), in the 'output' parameter.
  191. *
  192. * If the clocks are higher than before, then PP does nothing.
  193. *
  194. * If the clocks are lower than before, then PP reduces the voltage.
  195. *
  196. * \returns true - call is successful
  197. * false - call failed
  198. */
  199. bool dm_pp_apply_display_requirements(
  200. const struct dc_context *ctx,
  201. const struct dm_pp_display_configuration *pp_display_cfg);
  202. bool dm_pp_apply_power_level_change_request(
  203. const struct dc_context *ctx,
  204. struct dm_pp_power_level_change_request *level_change_req);
  205. bool dm_pp_apply_clock_for_voltage_request(
  206. const struct dc_context *ctx,
  207. struct dm_pp_clock_for_voltage_req *clock_for_voltage_req);
  208. bool dm_pp_get_static_clocks(
  209. const struct dc_context *ctx,
  210. struct dm_pp_static_clock_info *static_clk_info);
  211. /****** end of PP interfaces ******/
  212. struct persistent_data_flag {
  213. bool save_per_link;
  214. bool save_per_edid;
  215. };
  216. /* Call to write data in registry editor for persistent data storage.
  217. *
  218. * \inputs sink - identify edid/link for registry folder creation
  219. * module name - identify folders for registry
  220. * key name - identify keys within folders for registry
  221. * params - value to write in defined folder/key
  222. * size - size of the input params
  223. * flag - determine whether to save by link or edid
  224. *
  225. * \returns true - call is successful
  226. * false - call failed
  227. *
  228. * sink module key
  229. * -----------------------------------------------------------------------------
  230. * NULL NULL NULL - failure
  231. * NULL NULL - - create key with param value
  232. * under base folder
  233. * NULL - NULL - create module folder under base folder
  234. * - NULL NULL - failure
  235. * NULL - - - create key under module folder
  236. * with no edid/link identification
  237. * - NULL - - create key with param value
  238. * under base folder
  239. * - - NULL - create module folder under base folder
  240. * - - - - create key under module folder
  241. * with edid/link identification
  242. */
  243. bool dm_write_persistent_data(struct dc_context *ctx,
  244. const struct dc_sink *sink,
  245. const char *module_name,
  246. const char *key_name,
  247. void *params,
  248. unsigned int size,
  249. struct persistent_data_flag *flag);
  250. /* Call to read data in registry editor for persistent data storage.
  251. *
  252. * \inputs sink - identify edid/link for registry folder creation
  253. * module name - identify folders for registry
  254. * key name - identify keys within folders for registry
  255. * size - size of the output params
  256. * flag - determine whether it was save by link or edid
  257. *
  258. * \returns params - value read from defined folder/key
  259. * true - call is successful
  260. * false - call failed
  261. *
  262. * sink module key
  263. * -----------------------------------------------------------------------------
  264. * NULL NULL NULL - failure
  265. * NULL NULL - - read key under base folder
  266. * NULL - NULL - failure
  267. * - NULL NULL - failure
  268. * NULL - - - read key under module folder
  269. * with no edid/link identification
  270. * - NULL - - read key under base folder
  271. * - - NULL - failure
  272. * - - - - read key under module folder
  273. * with edid/link identification
  274. */
  275. bool dm_read_persistent_data(struct dc_context *ctx,
  276. const struct dc_sink *sink,
  277. const char *module_name,
  278. const char *key_name,
  279. void *params,
  280. unsigned int size,
  281. struct persistent_data_flag *flag);
  282. bool dm_query_extended_brightness_caps
  283. (struct dc_context *ctx, enum dm_acpi_display_type display,
  284. struct dm_acpi_atif_backlight_caps *pCaps);
  285. bool dm_dmcu_set_pipe(struct dc_context *ctx, unsigned int controller_id);
  286. /*
  287. *
  288. * print-out services
  289. *
  290. */
  291. #define dm_log_to_buffer(buffer, size, fmt, args)\
  292. vsnprintf(buffer, size, fmt, args)
  293. unsigned long long dm_get_timestamp(struct dc_context *ctx);
  294. unsigned long long dm_get_elapse_time_in_ns(struct dc_context *ctx,
  295. unsigned long long current_time_stamp,
  296. unsigned long long last_time_stamp);
  297. /*
  298. * performance tracing
  299. */
  300. void dm_perf_trace_timestamp(const char *func_name, unsigned int line);
  301. #define PERF_TRACE() dm_perf_trace_timestamp(__func__, __LINE__)
  302. /*
  303. * Debug and verification hooks
  304. */
  305. void dm_dtn_log_begin(struct dc_context *ctx);
  306. void dm_dtn_log_append_v(struct dc_context *ctx, const char *msg, ...);
  307. void dm_dtn_log_end(struct dc_context *ctx);
  308. #endif /* __DM_SERVICES_H__ */