amdgpu_dm.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 __AMDGPU_DM_H__
  26. #define __AMDGPU_DM_H__
  27. #include <drm/drmP.h>
  28. #include <drm/drm_atomic.h>
  29. /*
  30. * This file contains the definition for amdgpu_display_manager
  31. * and its API for amdgpu driver's use.
  32. * This component provides all the display related functionality
  33. * and this is the only component that calls DAL API.
  34. * The API contained here intended for amdgpu driver use.
  35. * The API that is called directly from KMS framework is located
  36. * in amdgpu_dm_kms.h file
  37. */
  38. #define AMDGPU_DM_MAX_DISPLAY_INDEX 31
  39. /*
  40. #include "include/amdgpu_dal_power_if.h"
  41. #include "amdgpu_dm_irq.h"
  42. */
  43. #include "irq_types.h"
  44. #include "signal_types.h"
  45. /* Forward declarations */
  46. struct amdgpu_device;
  47. struct drm_device;
  48. struct amdgpu_dm_irq_handler_data;
  49. struct dc;
  50. struct common_irq_params {
  51. struct amdgpu_device *adev;
  52. enum dc_irq_source irq_src;
  53. };
  54. struct irq_list_head {
  55. struct list_head head;
  56. /* In case this interrupt needs post-processing, 'work' will be queued*/
  57. struct work_struct work;
  58. };
  59. struct dm_comressor_info {
  60. void *cpu_addr;
  61. struct amdgpu_bo *bo_ptr;
  62. uint64_t gpu_addr;
  63. };
  64. struct amdgpu_display_manager {
  65. struct dc *dc;
  66. struct cgs_device *cgs_device;
  67. struct amdgpu_device *adev; /*AMD base driver*/
  68. struct drm_device *ddev; /*DRM base driver*/
  69. u16 display_indexes_num;
  70. /*
  71. * 'irq_source_handler_table' holds a list of handlers
  72. * per (DAL) IRQ source.
  73. *
  74. * Each IRQ source may need to be handled at different contexts.
  75. * By 'context' we mean, for example:
  76. * - The ISR context, which is the direct interrupt handler.
  77. * - The 'deferred' context - this is the post-processing of the
  78. * interrupt, but at a lower priority.
  79. *
  80. * Note that handlers are called in the same order as they were
  81. * registered (FIFO).
  82. */
  83. struct irq_list_head irq_handler_list_low_tab[DAL_IRQ_SOURCES_NUMBER];
  84. struct list_head irq_handler_list_high_tab[DAL_IRQ_SOURCES_NUMBER];
  85. struct common_irq_params
  86. pflip_params[DC_IRQ_SOURCE_PFLIP_LAST - DC_IRQ_SOURCE_PFLIP_FIRST + 1];
  87. struct common_irq_params
  88. vblank_params[DC_IRQ_SOURCE_VBLANK6 - DC_IRQ_SOURCE_VBLANK1 + 1];
  89. /* this spin lock synchronizes access to 'irq_handler_list_table' */
  90. spinlock_t irq_handler_list_table_lock;
  91. struct backlight_device *backlight_dev;
  92. const struct dc_link *backlight_link;
  93. struct work_struct mst_hotplug_work;
  94. struct mod_freesync *freesync_module;
  95. /**
  96. * Caches device atomic state for suspend/resume
  97. */
  98. struct drm_atomic_state *cached_state;
  99. struct dm_comressor_info compressor;
  100. const struct firmware *fw_dmcu;
  101. uint32_t dmcu_fw_version;
  102. };
  103. struct amdgpu_dm_connector {
  104. struct drm_connector base;
  105. uint32_t connector_id;
  106. /* we need to mind the EDID between detect
  107. and get modes due to analog/digital/tvencoder */
  108. struct edid *edid;
  109. /* shared with amdgpu */
  110. struct amdgpu_hpd hpd;
  111. /* number of modes generated from EDID at 'dc_sink' */
  112. int num_modes;
  113. /* The 'old' sink - before an HPD.
  114. * The 'current' sink is in dc_link->sink. */
  115. struct dc_sink *dc_sink;
  116. struct dc_link *dc_link;
  117. struct dc_sink *dc_em_sink;
  118. /* DM only */
  119. struct drm_dp_mst_topology_mgr mst_mgr;
  120. struct amdgpu_dm_dp_aux dm_dp_aux;
  121. struct drm_dp_mst_port *port;
  122. struct amdgpu_dm_connector *mst_port;
  123. struct amdgpu_encoder *mst_encoder;
  124. /* TODO see if we can merge with ddc_bus or make a dm_connector */
  125. struct amdgpu_i2c_adapter *i2c;
  126. /* Monitor range limits */
  127. int min_vfreq ;
  128. int max_vfreq ;
  129. int pixel_clock_mhz;
  130. struct mutex hpd_lock;
  131. bool fake_enable;
  132. bool mst_connected;
  133. };
  134. #define to_amdgpu_dm_connector(x) container_of(x, struct amdgpu_dm_connector, base)
  135. extern const struct amdgpu_ip_block_version dm_ip_block;
  136. struct amdgpu_framebuffer;
  137. struct amdgpu_display_manager;
  138. struct dc_validation_set;
  139. struct dc_plane_state;
  140. struct dm_plane_state {
  141. struct drm_plane_state base;
  142. struct dc_plane_state *dc_state;
  143. };
  144. struct dm_crtc_state {
  145. struct drm_crtc_state base;
  146. struct dc_stream_state *stream;
  147. int crc_skip_count;
  148. bool crc_enabled;
  149. bool freesync_enabled;
  150. struct dc_crtc_timing_adjust adjust;
  151. struct dc_info_packet vrr_infopacket;
  152. };
  153. #define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base)
  154. struct dm_atomic_state {
  155. struct drm_atomic_state base;
  156. struct dc_state *context;
  157. };
  158. #define to_dm_atomic_state(x) container_of(x, struct dm_atomic_state, base)
  159. struct dm_connector_state {
  160. struct drm_connector_state base;
  161. enum amdgpu_rmx_type scaling;
  162. uint8_t underscan_vborder;
  163. uint8_t underscan_hborder;
  164. bool underscan_enable;
  165. bool freesync_enable;
  166. bool freesync_capable;
  167. };
  168. #define to_dm_connector_state(x)\
  169. container_of((x), struct dm_connector_state, base)
  170. void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector);
  171. struct drm_connector_state *
  172. amdgpu_dm_connector_atomic_duplicate_state(struct drm_connector *connector);
  173. int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector,
  174. struct drm_connector_state *state,
  175. struct drm_property *property,
  176. uint64_t val);
  177. int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector,
  178. const struct drm_connector_state *state,
  179. struct drm_property *property,
  180. uint64_t *val);
  181. int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev);
  182. void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
  183. struct amdgpu_dm_connector *aconnector,
  184. int connector_type,
  185. struct dc_link *link,
  186. int link_index);
  187. enum drm_mode_status amdgpu_dm_connector_mode_valid(struct drm_connector *connector,
  188. struct drm_display_mode *mode);
  189. void dm_restore_drm_connector_state(struct drm_device *dev,
  190. struct drm_connector *connector);
  191. void amdgpu_dm_update_freesync_caps(struct drm_connector *connector,
  192. struct edid *edid);
  193. /* amdgpu_dm_crc.c */
  194. #ifdef CONFIG_DEBUG_FS
  195. int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name,
  196. size_t *values_cnt);
  197. void amdgpu_dm_crtc_handle_crc_irq(struct drm_crtc *crtc);
  198. #else
  199. #define amdgpu_dm_crtc_set_crc_source NULL
  200. #define amdgpu_dm_crtc_handle_crc_irq(x)
  201. #endif
  202. #define MAX_COLOR_LUT_ENTRIES 4096
  203. /* Legacy gamm LUT users such as X doesn't like large LUT sizes */
  204. #define MAX_COLOR_LEGACY_LUT_ENTRIES 256
  205. void amdgpu_dm_init_color_mod(void);
  206. int amdgpu_dm_set_degamma_lut(struct drm_crtc_state *crtc_state,
  207. struct dc_plane_state *dc_plane_state);
  208. void amdgpu_dm_set_ctm(struct dm_crtc_state *crtc);
  209. int amdgpu_dm_set_regamma_lut(struct dm_crtc_state *crtc);
  210. extern const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs;
  211. #endif /* __AMDGPU_DM_H__ */