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