vmwgfx_kms.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #ifndef VMWGFX_KMS_H_
  28. #define VMWGFX_KMS_H_
  29. #include <drm/drmP.h>
  30. #include <drm/drm_crtc_helper.h>
  31. #include <drm/drm_encoder.h>
  32. #include "vmwgfx_drv.h"
  33. /**
  34. * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
  35. * function.
  36. *
  37. * @fifo_commit: Callback that is called once for each display unit after
  38. * all clip rects. This function must commit the fifo space reserved by the
  39. * helper. Set up by the caller.
  40. * @clip: Callback that is called for each cliprect on each display unit.
  41. * Set up by the caller.
  42. * @fifo_reserve_size: Fifo size that the helper should try to allocat for
  43. * each display unit. Set up by the caller.
  44. * @dev_priv: Pointer to the device private. Set up by the helper.
  45. * @unit: The current display unit. Set up by the helper before a call to @clip.
  46. * @cmd: The allocated fifo space. Set up by the helper before the first @clip
  47. * call.
  48. * @num_hits: Number of clip rect commands for this display unit.
  49. * Cleared by the helper before the first @clip call. Updated by the @clip
  50. * callback.
  51. * @fb_x: Clip rect left side in framebuffer coordinates.
  52. * @fb_y: Clip rect right side in framebuffer coordinates.
  53. * @unit_x1: Clip rect left side in crtc coordinates.
  54. * @unit_y1: Clip rect top side in crtc coordinates.
  55. * @unit_x2: Clip rect right side in crtc coordinates.
  56. * @unit_y2: Clip rect bottom side in crtc coordinates.
  57. *
  58. * The clip rect coordinates are updated by the helper for each @clip call.
  59. * Note that this may be derived from if more info needs to be passed between
  60. * helper caller and helper callbacks.
  61. */
  62. struct vmw_kms_dirty {
  63. void (*fifo_commit)(struct vmw_kms_dirty *);
  64. void (*clip)(struct vmw_kms_dirty *);
  65. size_t fifo_reserve_size;
  66. struct vmw_private *dev_priv;
  67. struct vmw_display_unit *unit;
  68. void *cmd;
  69. u32 num_hits;
  70. s32 fb_x;
  71. s32 fb_y;
  72. s32 unit_x1;
  73. s32 unit_y1;
  74. s32 unit_x2;
  75. s32 unit_y2;
  76. };
  77. #define VMWGFX_NUM_DISPLAY_UNITS 8
  78. #define vmw_framebuffer_to_vfb(x) \
  79. container_of(x, struct vmw_framebuffer, base)
  80. #define vmw_framebuffer_to_vfbs(x) \
  81. container_of(x, struct vmw_framebuffer_surface, base.base)
  82. #define vmw_framebuffer_to_vfbd(x) \
  83. container_of(x, struct vmw_framebuffer_dmabuf, base.base)
  84. /**
  85. * Base class for framebuffers
  86. *
  87. * @pin is called the when ever a crtc uses this framebuffer
  88. * @unpin is called
  89. */
  90. struct vmw_framebuffer {
  91. struct drm_framebuffer base;
  92. int (*pin)(struct vmw_framebuffer *fb);
  93. int (*unpin)(struct vmw_framebuffer *fb);
  94. bool dmabuf;
  95. struct ttm_base_object *user_obj;
  96. uint32_t user_handle;
  97. };
  98. /*
  99. * Clip rectangle
  100. */
  101. struct vmw_clip_rect {
  102. int x1, x2, y1, y2;
  103. };
  104. struct vmw_framebuffer_surface {
  105. struct vmw_framebuffer base;
  106. struct vmw_surface *surface;
  107. struct vmw_dma_buffer *buffer;
  108. struct list_head head;
  109. bool is_dmabuf_proxy; /* true if this is proxy surface for DMA buf */
  110. };
  111. struct vmw_framebuffer_dmabuf {
  112. struct vmw_framebuffer base;
  113. struct vmw_dma_buffer *buffer;
  114. };
  115. /*
  116. * Basic cursor manipulation
  117. */
  118. int vmw_cursor_update_image(struct vmw_private *dev_priv,
  119. u32 *image, u32 width, u32 height,
  120. u32 hotspotX, u32 hotspotY);
  121. int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv,
  122. struct vmw_dma_buffer *dmabuf,
  123. u32 width, u32 height,
  124. u32 hotspotX, u32 hotspotY);
  125. void vmw_cursor_update_position(struct vmw_private *dev_priv,
  126. bool show, int x, int y);
  127. /**
  128. * Base class display unit.
  129. *
  130. * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
  131. * so the display unit is all of them at the same time. This is true for both
  132. * legacy multimon and screen objects.
  133. */
  134. struct vmw_display_unit {
  135. struct drm_crtc crtc;
  136. struct drm_encoder encoder;
  137. struct drm_connector connector;
  138. struct vmw_surface *cursor_surface;
  139. struct vmw_dma_buffer *cursor_dmabuf;
  140. size_t cursor_age;
  141. int cursor_x;
  142. int cursor_y;
  143. int hotspot_x;
  144. int hotspot_y;
  145. s32 core_hotspot_x;
  146. s32 core_hotspot_y;
  147. unsigned unit;
  148. /*
  149. * Prefered mode tracking.
  150. */
  151. unsigned pref_width;
  152. unsigned pref_height;
  153. bool pref_active;
  154. struct drm_display_mode *pref_mode;
  155. /*
  156. * Gui positioning
  157. */
  158. int gui_x;
  159. int gui_y;
  160. bool is_implicit;
  161. bool active_implicit;
  162. int set_gui_x;
  163. int set_gui_y;
  164. };
  165. #define vmw_crtc_to_du(x) \
  166. container_of(x, struct vmw_display_unit, crtc)
  167. #define vmw_connector_to_du(x) \
  168. container_of(x, struct vmw_display_unit, connector)
  169. /*
  170. * Shared display unit functions - vmwgfx_kms.c
  171. */
  172. void vmw_du_cleanup(struct vmw_display_unit *du);
  173. void vmw_du_crtc_save(struct drm_crtc *crtc);
  174. void vmw_du_crtc_restore(struct drm_crtc *crtc);
  175. int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
  176. u16 *r, u16 *g, u16 *b,
  177. uint32_t size);
  178. int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
  179. uint32_t handle, uint32_t width, uint32_t height,
  180. int32_t hot_x, int32_t hot_y);
  181. int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
  182. int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
  183. void vmw_du_connector_save(struct drm_connector *connector);
  184. void vmw_du_connector_restore(struct drm_connector *connector);
  185. enum drm_connector_status
  186. vmw_du_connector_detect(struct drm_connector *connector, bool force);
  187. int vmw_du_connector_fill_modes(struct drm_connector *connector,
  188. uint32_t max_width, uint32_t max_height);
  189. int vmw_du_connector_set_property(struct drm_connector *connector,
  190. struct drm_property *property,
  191. uint64_t val);
  192. int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
  193. struct vmw_framebuffer *framebuffer,
  194. const struct drm_clip_rect *clips,
  195. const struct drm_vmw_rect *vclips,
  196. s32 dest_x, s32 dest_y,
  197. int num_clips,
  198. int increment,
  199. struct vmw_kms_dirty *dirty);
  200. int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
  201. struct vmw_dma_buffer *buf,
  202. bool interruptible,
  203. bool validate_as_mob);
  204. void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
  205. void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
  206. struct drm_file *file_priv,
  207. struct vmw_dma_buffer *buf,
  208. struct vmw_fence_obj **out_fence,
  209. struct drm_vmw_fence_rep __user *
  210. user_fence_rep);
  211. int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
  212. bool interruptible);
  213. void vmw_kms_helper_resource_revert(struct vmw_resource *res);
  214. void vmw_kms_helper_resource_finish(struct vmw_resource *res,
  215. struct vmw_fence_obj **out_fence);
  216. int vmw_kms_readback(struct vmw_private *dev_priv,
  217. struct drm_file *file_priv,
  218. struct vmw_framebuffer *vfb,
  219. struct drm_vmw_fence_rep __user *user_fence_rep,
  220. struct drm_vmw_rect *vclips,
  221. uint32_t num_clips);
  222. struct vmw_framebuffer *
  223. vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
  224. struct vmw_dma_buffer *dmabuf,
  225. struct vmw_surface *surface,
  226. bool only_2d,
  227. const struct drm_mode_fb_cmd2 *mode_cmd);
  228. int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
  229. unsigned unit,
  230. u32 max_width,
  231. u32 max_height,
  232. struct drm_connector **p_con,
  233. struct drm_crtc **p_crtc,
  234. struct drm_display_mode **p_mode);
  235. void vmw_guess_mode_timing(struct drm_display_mode *mode);
  236. void vmw_kms_del_active(struct vmw_private *dev_priv,
  237. struct vmw_display_unit *du);
  238. void vmw_kms_add_active(struct vmw_private *dev_priv,
  239. struct vmw_display_unit *du,
  240. struct vmw_framebuffer *vfb);
  241. bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
  242. struct drm_crtc *crtc);
  243. void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
  244. struct drm_crtc *crtc);
  245. void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
  246. bool immutable);
  247. /*
  248. * Legacy display unit functions - vmwgfx_ldu.c
  249. */
  250. int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
  251. int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
  252. int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
  253. struct vmw_framebuffer *framebuffer,
  254. unsigned flags, unsigned color,
  255. struct drm_clip_rect *clips,
  256. unsigned num_clips, int increment);
  257. int vmw_kms_update_proxy(struct vmw_resource *res,
  258. const struct drm_clip_rect *clips,
  259. unsigned num_clips,
  260. int increment);
  261. /*
  262. * Screen Objects display functions - vmwgfx_scrn.c
  263. */
  264. int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
  265. int vmw_kms_sou_close_display(struct vmw_private *dev_priv);
  266. int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
  267. struct vmw_framebuffer *framebuffer,
  268. struct drm_clip_rect *clips,
  269. struct drm_vmw_rect *vclips,
  270. struct vmw_resource *srf,
  271. s32 dest_x,
  272. s32 dest_y,
  273. unsigned num_clips, int inc,
  274. struct vmw_fence_obj **out_fence);
  275. int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
  276. struct vmw_framebuffer *framebuffer,
  277. struct drm_clip_rect *clips,
  278. struct drm_vmw_rect *vclips,
  279. unsigned num_clips, int increment,
  280. bool interruptible,
  281. struct vmw_fence_obj **out_fence);
  282. int vmw_kms_sou_readback(struct vmw_private *dev_priv,
  283. struct drm_file *file_priv,
  284. struct vmw_framebuffer *vfb,
  285. struct drm_vmw_fence_rep __user *user_fence_rep,
  286. struct drm_vmw_rect *vclips,
  287. uint32_t num_clips);
  288. /*
  289. * Screen Target Display Unit functions - vmwgfx_stdu.c
  290. */
  291. int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
  292. int vmw_kms_stdu_close_display(struct vmw_private *dev_priv);
  293. int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
  294. struct vmw_framebuffer *framebuffer,
  295. struct drm_clip_rect *clips,
  296. struct drm_vmw_rect *vclips,
  297. struct vmw_resource *srf,
  298. s32 dest_x,
  299. s32 dest_y,
  300. unsigned num_clips, int inc,
  301. struct vmw_fence_obj **out_fence);
  302. int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
  303. struct drm_file *file_priv,
  304. struct vmw_framebuffer *vfb,
  305. struct drm_vmw_fence_rep __user *user_fence_rep,
  306. struct drm_clip_rect *clips,
  307. struct drm_vmw_rect *vclips,
  308. uint32_t num_clips,
  309. int increment,
  310. bool to_surface,
  311. bool interruptible);
  312. #endif