dm_services.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. /* DAL calls this function to notify PP about clocks it needs for the Mode Set.
  164. * This is done *before* it changes DCE clock.
  165. *
  166. * If required clock is higher than current, then PP will increase the voltage.
  167. *
  168. * If required clock is lower than current, then PP will defer reduction of
  169. * voltage until the call to dc_service_pp_post_dce_clock_change().
  170. *
  171. * \input - Contains clocks needed for Mode Set.
  172. *
  173. * \output - Contains clocks adjusted by PP which DAL should use for Mode Set.
  174. * Valid only if function returns zero.
  175. *
  176. * \returns true - call is successful
  177. * false - call failed
  178. */
  179. bool dm_pp_pre_dce_clock_change(
  180. struct dc_context *ctx,
  181. struct dm_pp_gpu_clock_range *requested_state,
  182. struct dm_pp_gpu_clock_range *actual_state);
  183. /* The returned clocks range are 'static' system clocks which will be used for
  184. * mode validation purposes.
  185. *
  186. * \returns true - call is successful
  187. * false - call failed
  188. */
  189. bool dc_service_get_system_clocks_range(
  190. const struct dc_context *ctx,
  191. struct dm_pp_gpu_clock_range *sys_clks);
  192. /* Gets valid clocks levels from pplib
  193. *
  194. * input: clk_type - display clk / sclk / mem clk
  195. *
  196. * output: array of valid clock levels for given type in ascending order,
  197. * with invalid levels filtered out
  198. *
  199. */
  200. bool dm_pp_get_clock_levels_by_type(
  201. const struct dc_context *ctx,
  202. enum dm_pp_clock_type clk_type,
  203. struct dm_pp_clock_levels *clk_level_info);
  204. bool dm_pp_get_clock_levels_by_type_with_latency(
  205. const struct dc_context *ctx,
  206. enum dm_pp_clock_type clk_type,
  207. struct dm_pp_clock_levels_with_latency *clk_level_info);
  208. bool dm_pp_get_clock_levels_by_type_with_voltage(
  209. const struct dc_context *ctx,
  210. enum dm_pp_clock_type clk_type,
  211. struct dm_pp_clock_levels_with_voltage *clk_level_info);
  212. bool 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. void dm_pp_get_funcs_rv(struct dc_context *ctx,
  216. struct pp_smu_funcs_rv *funcs);
  217. /* DAL calls this function to notify PP about completion of Mode Set.
  218. * For PP it means that current DCE clocks are those which were returned
  219. * by dc_service_pp_pre_dce_clock_change(), in the 'output' parameter.
  220. *
  221. * If the clocks are higher than before, then PP does nothing.
  222. *
  223. * If the clocks are lower than before, then PP reduces the voltage.
  224. *
  225. * \returns true - call is successful
  226. * false - call failed
  227. */
  228. bool dm_pp_apply_display_requirements(
  229. const struct dc_context *ctx,
  230. const struct dm_pp_display_configuration *pp_display_cfg);
  231. bool dm_pp_apply_power_level_change_request(
  232. const struct dc_context *ctx,
  233. struct dm_pp_power_level_change_request *level_change_req);
  234. bool dm_pp_apply_clock_for_voltage_request(
  235. const struct dc_context *ctx,
  236. struct dm_pp_clock_for_voltage_req *clock_for_voltage_req);
  237. bool dm_pp_get_static_clocks(
  238. const struct dc_context *ctx,
  239. struct dm_pp_static_clock_info *static_clk_info);
  240. /****** end of PP interfaces ******/
  241. struct persistent_data_flag {
  242. bool save_per_link;
  243. bool save_per_edid;
  244. };
  245. /* Call to write data in registry editor for persistent data storage.
  246. *
  247. * \inputs sink - identify edid/link for registry folder creation
  248. * module name - identify folders for registry
  249. * key name - identify keys within folders for registry
  250. * params - value to write in defined folder/key
  251. * size - size of the input params
  252. * flag - determine whether to save by link or edid
  253. *
  254. * \returns true - call is successful
  255. * false - call failed
  256. *
  257. * sink module key
  258. * -----------------------------------------------------------------------------
  259. * NULL NULL NULL - failure
  260. * NULL NULL - - create key with param value
  261. * under base folder
  262. * NULL - NULL - create module folder under base folder
  263. * - NULL NULL - failure
  264. * NULL - - - create key under module folder
  265. * with no edid/link identification
  266. * - NULL - - create key with param value
  267. * under base folder
  268. * - - NULL - create module folder under base folder
  269. * - - - - create key under module folder
  270. * with edid/link identification
  271. */
  272. bool dm_write_persistent_data(struct dc_context *ctx,
  273. const struct dc_sink *sink,
  274. const char *module_name,
  275. const char *key_name,
  276. void *params,
  277. unsigned int size,
  278. struct persistent_data_flag *flag);
  279. /* Call to read data in registry editor for persistent data storage.
  280. *
  281. * \inputs sink - identify edid/link for registry folder creation
  282. * module name - identify folders for registry
  283. * key name - identify keys within folders for registry
  284. * size - size of the output params
  285. * flag - determine whether it was save by link or edid
  286. *
  287. * \returns params - value read from defined folder/key
  288. * true - call is successful
  289. * false - call failed
  290. *
  291. * sink module key
  292. * -----------------------------------------------------------------------------
  293. * NULL NULL NULL - failure
  294. * NULL NULL - - read key under base folder
  295. * NULL - NULL - failure
  296. * - NULL NULL - failure
  297. * NULL - - - read key under module folder
  298. * with no edid/link identification
  299. * - NULL - - read key under base folder
  300. * - - NULL - failure
  301. * - - - - read key under module folder
  302. * with edid/link identification
  303. */
  304. bool dm_read_persistent_data(struct dc_context *ctx,
  305. const struct dc_sink *sink,
  306. const char *module_name,
  307. const char *key_name,
  308. void *params,
  309. unsigned int size,
  310. struct persistent_data_flag *flag);
  311. bool dm_query_extended_brightness_caps
  312. (struct dc_context *ctx, enum dm_acpi_display_type display,
  313. struct dm_acpi_atif_backlight_caps *pCaps);
  314. bool dm_dmcu_set_pipe(struct dc_context *ctx, unsigned int controller_id);
  315. /*
  316. *
  317. * print-out services
  318. *
  319. */
  320. #define dm_log_to_buffer(buffer, size, fmt, args)\
  321. vsnprintf(buffer, size, fmt, args)
  322. unsigned long long dm_get_timestamp(struct dc_context *ctx);
  323. /*
  324. * performance tracing
  325. */
  326. void dm_perf_trace_timestamp(const char *func_name, unsigned int line);
  327. #define PERF_TRACE() dm_perf_trace_timestamp(__func__, __LINE__)
  328. /*
  329. * Debug and verification hooks
  330. */
  331. bool dm_helpers_dc_conn_log(
  332. struct dc_context *ctx,
  333. struct log_entry *entry,
  334. enum dc_log_type event);
  335. void dm_dtn_log_begin(struct dc_context *ctx);
  336. void dm_dtn_log_append_v(struct dc_context *ctx, const char *msg, ...);
  337. void dm_dtn_log_end(struct dc_context *ctx);
  338. #endif /* __DM_SERVICES_H__ */