display.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
  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 (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Ke Yu
  25. * Zhiyuan Lv <[email protected]>
  26. *
  27. * Contributors:
  28. * Terrence Xu <[email protected]>
  29. * Changbin Du <[email protected]>
  30. * Bing Niu <[email protected]>
  31. * Zhi Wang <[email protected]>
  32. *
  33. */
  34. #ifndef _GVT_DISPLAY_H_
  35. #define _GVT_DISPLAY_H_
  36. #include <linux/types.h>
  37. #include <linux/hrtimer.h>
  38. struct intel_gvt;
  39. struct intel_vgpu;
  40. #define SBI_REG_MAX 20
  41. #define DPCD_SIZE 0x700
  42. #define intel_vgpu_port(vgpu, port) \
  43. (&(vgpu->display.ports[port]))
  44. #define intel_vgpu_has_monitor_on_port(vgpu, port) \
  45. (intel_vgpu_port(vgpu, port)->edid && \
  46. intel_vgpu_port(vgpu, port)->edid->data_valid)
  47. #define intel_vgpu_port_is_dp(vgpu, port) \
  48. ((intel_vgpu_port(vgpu, port)->type == GVT_DP_A) || \
  49. (intel_vgpu_port(vgpu, port)->type == GVT_DP_B) || \
  50. (intel_vgpu_port(vgpu, port)->type == GVT_DP_C) || \
  51. (intel_vgpu_port(vgpu, port)->type == GVT_DP_D))
  52. #define INTEL_GVT_MAX_UEVENT_VARS 3
  53. /* DPCD start */
  54. #define DPCD_SIZE 0x700
  55. /* DPCD */
  56. #define DP_SET_POWER 0x600
  57. #define DP_SET_POWER_D0 0x1
  58. #define AUX_NATIVE_WRITE 0x8
  59. #define AUX_NATIVE_READ 0x9
  60. #define AUX_NATIVE_REPLY_MASK (0x3 << 4)
  61. #define AUX_NATIVE_REPLY_ACK (0x0 << 4)
  62. #define AUX_NATIVE_REPLY_NAK (0x1 << 4)
  63. #define AUX_NATIVE_REPLY_DEFER (0x2 << 4)
  64. #define AUX_BURST_SIZE 20
  65. /* DPCD addresses */
  66. #define DPCD_REV 0x000
  67. #define DPCD_MAX_LINK_RATE 0x001
  68. #define DPCD_MAX_LANE_COUNT 0x002
  69. #define DPCD_TRAINING_PATTERN_SET 0x102
  70. #define DPCD_SINK_COUNT 0x200
  71. #define DPCD_LANE0_1_STATUS 0x202
  72. #define DPCD_LANE2_3_STATUS 0x203
  73. #define DPCD_LANE_ALIGN_STATUS_UPDATED 0x204
  74. #define DPCD_SINK_STATUS 0x205
  75. /* link training */
  76. #define DPCD_TRAINING_PATTERN_SET_MASK 0x03
  77. #define DPCD_LINK_TRAINING_DISABLED 0x00
  78. #define DPCD_TRAINING_PATTERN_1 0x01
  79. #define DPCD_TRAINING_PATTERN_2 0x02
  80. #define DPCD_CP_READY_MASK (1 << 6)
  81. /* lane status */
  82. #define DPCD_LANES_CR_DONE 0x11
  83. #define DPCD_LANES_EQ_DONE 0x22
  84. #define DPCD_SYMBOL_LOCKED 0x44
  85. #define DPCD_INTERLANE_ALIGN_DONE 0x01
  86. #define DPCD_SINK_IN_SYNC 0x03
  87. /* DPCD end */
  88. #define SBI_RESPONSE_MASK 0x3
  89. #define SBI_RESPONSE_SHIFT 0x1
  90. #define SBI_STAT_MASK 0x1
  91. #define SBI_STAT_SHIFT 0x0
  92. #define SBI_OPCODE_SHIFT 8
  93. #define SBI_OPCODE_MASK (0xff << SBI_OPCODE_SHIFT)
  94. #define SBI_CMD_IORD 2
  95. #define SBI_CMD_IOWR 3
  96. #define SBI_CMD_CRRD 6
  97. #define SBI_CMD_CRWR 7
  98. #define SBI_ADDR_OFFSET_SHIFT 16
  99. #define SBI_ADDR_OFFSET_MASK (0xffff << SBI_ADDR_OFFSET_SHIFT)
  100. struct intel_vgpu_sbi_register {
  101. unsigned int offset;
  102. u32 value;
  103. };
  104. struct intel_vgpu_sbi {
  105. int number;
  106. struct intel_vgpu_sbi_register registers[SBI_REG_MAX];
  107. };
  108. enum intel_gvt_plane_type {
  109. PRIMARY_PLANE = 0,
  110. CURSOR_PLANE,
  111. SPRITE_PLANE,
  112. MAX_PLANE
  113. };
  114. struct intel_vgpu_dpcd_data {
  115. bool data_valid;
  116. u8 data[DPCD_SIZE];
  117. };
  118. enum intel_vgpu_port_type {
  119. GVT_CRT = 0,
  120. GVT_DP_A,
  121. GVT_DP_B,
  122. GVT_DP_C,
  123. GVT_DP_D,
  124. GVT_HDMI_B,
  125. GVT_HDMI_C,
  126. GVT_HDMI_D,
  127. GVT_PORT_MAX
  128. };
  129. enum intel_vgpu_edid {
  130. GVT_EDID_1024_768,
  131. GVT_EDID_1920_1200,
  132. GVT_EDID_NUM,
  133. };
  134. #define GVT_DEFAULT_REFRESH_RATE 60
  135. struct intel_vgpu_port {
  136. /* per display EDID information */
  137. struct intel_vgpu_edid_data *edid;
  138. /* per display DPCD information */
  139. struct intel_vgpu_dpcd_data *dpcd;
  140. int type;
  141. enum intel_vgpu_edid id;
  142. /* x1000 to get accurate 59.94, 24.976, 29.94, etc. in timing std. */
  143. u32 vrefresh_k;
  144. };
  145. struct intel_vgpu_vblank_timer {
  146. struct hrtimer timer;
  147. u32 vrefresh_k;
  148. u64 period;
  149. };
  150. static inline char *vgpu_edid_str(enum intel_vgpu_edid id)
  151. {
  152. switch (id) {
  153. case GVT_EDID_1024_768:
  154. return "1024x768";
  155. case GVT_EDID_1920_1200:
  156. return "1920x1200";
  157. default:
  158. return "";
  159. }
  160. }
  161. static inline unsigned int vgpu_edid_xres(enum intel_vgpu_edid id)
  162. {
  163. switch (id) {
  164. case GVT_EDID_1024_768:
  165. return 1024;
  166. case GVT_EDID_1920_1200:
  167. return 1920;
  168. default:
  169. return 0;
  170. }
  171. }
  172. static inline unsigned int vgpu_edid_yres(enum intel_vgpu_edid id)
  173. {
  174. switch (id) {
  175. case GVT_EDID_1024_768:
  176. return 768;
  177. case GVT_EDID_1920_1200:
  178. return 1200;
  179. default:
  180. return 0;
  181. }
  182. }
  183. void intel_vgpu_emulate_vblank(struct intel_vgpu *vgpu);
  184. void vgpu_update_vblank_emulation(struct intel_vgpu *vgpu, bool turnon);
  185. int intel_vgpu_init_display(struct intel_vgpu *vgpu, u64 resolution);
  186. void intel_vgpu_reset_display(struct intel_vgpu *vgpu);
  187. void intel_vgpu_clean_display(struct intel_vgpu *vgpu);
  188. int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe);
  189. #endif