vmwgfx_kms.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. static const uint32_t vmw_primary_plane_formats[] = {
  116. DRM_FORMAT_XRGB1555,
  117. DRM_FORMAT_RGB565,
  118. DRM_FORMAT_RGB888,
  119. DRM_FORMAT_XRGB8888,
  120. DRM_FORMAT_ARGB8888,
  121. };
  122. static const uint32_t vmw_cursor_plane_formats[] = {
  123. DRM_FORMAT_ARGB8888,
  124. };
  125. #define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
  126. #define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
  127. #define vmw_connector_state_to_vcs(x) \
  128. container_of(x, struct vmw_connector_state, base)
  129. /**
  130. * Derived class for crtc state object
  131. *
  132. * @base DRM crtc object
  133. */
  134. struct vmw_crtc_state {
  135. struct drm_crtc_state base;
  136. };
  137. /**
  138. * Derived class for plane state object
  139. *
  140. * @base DRM plane object
  141. * @surf Display surface for STDU
  142. * @dmabuf display dmabuf for SOU
  143. * @content_fb_type Used by STDU.
  144. * @dmabuf_size Size of the dmabuf, used by Screen Object Display Unit
  145. * @pinned pin count for STDU display surface
  146. */
  147. struct vmw_plane_state {
  148. struct drm_plane_state base;
  149. struct vmw_surface *surf;
  150. struct vmw_dma_buffer *dmabuf;
  151. int content_fb_type;
  152. unsigned long dmabuf_size;
  153. int pinned;
  154. /* For CPU Blit */
  155. struct ttm_bo_kmap_obj host_map;
  156. unsigned int cpp;
  157. };
  158. /**
  159. * Derived class for connector state object
  160. *
  161. * @base DRM connector object
  162. * @is_implicit connector property
  163. *
  164. */
  165. struct vmw_connector_state {
  166. struct drm_connector_state base;
  167. bool is_implicit;
  168. };
  169. /**
  170. * Base class display unit.
  171. *
  172. * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
  173. * so the display unit is all of them at the same time. This is true for both
  174. * legacy multimon and screen objects.
  175. */
  176. struct vmw_display_unit {
  177. struct drm_crtc crtc;
  178. struct drm_encoder encoder;
  179. struct drm_connector connector;
  180. struct drm_plane primary;
  181. struct drm_plane cursor;
  182. struct vmw_surface *cursor_surface;
  183. struct vmw_dma_buffer *cursor_dmabuf;
  184. size_t cursor_age;
  185. int cursor_x;
  186. int cursor_y;
  187. int hotspot_x;
  188. int hotspot_y;
  189. s32 core_hotspot_x;
  190. s32 core_hotspot_y;
  191. unsigned unit;
  192. /*
  193. * Prefered mode tracking.
  194. */
  195. unsigned pref_width;
  196. unsigned pref_height;
  197. bool pref_active;
  198. struct drm_display_mode *pref_mode;
  199. /*
  200. * Gui positioning
  201. */
  202. int gui_x;
  203. int gui_y;
  204. bool is_implicit;
  205. bool active_implicit;
  206. int set_gui_x;
  207. int set_gui_y;
  208. };
  209. struct vmw_validation_ctx {
  210. struct vmw_resource *res;
  211. struct vmw_dma_buffer *buf;
  212. };
  213. #define vmw_crtc_to_du(x) \
  214. container_of(x, struct vmw_display_unit, crtc)
  215. #define vmw_connector_to_du(x) \
  216. container_of(x, struct vmw_display_unit, connector)
  217. /*
  218. * Shared display unit functions - vmwgfx_kms.c
  219. */
  220. void vmw_du_cleanup(struct vmw_display_unit *du);
  221. void vmw_du_crtc_save(struct drm_crtc *crtc);
  222. void vmw_du_crtc_restore(struct drm_crtc *crtc);
  223. int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
  224. u16 *r, u16 *g, u16 *b,
  225. uint32_t size,
  226. struct drm_modeset_acquire_ctx *ctx);
  227. int vmw_du_connector_set_property(struct drm_connector *connector,
  228. struct drm_property *property,
  229. uint64_t val);
  230. int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
  231. struct drm_connector_state *state,
  232. struct drm_property *property,
  233. uint64_t val);
  234. int
  235. vmw_du_connector_atomic_get_property(struct drm_connector *connector,
  236. const struct drm_connector_state *state,
  237. struct drm_property *property,
  238. uint64_t *val);
  239. int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
  240. void vmw_du_connector_save(struct drm_connector *connector);
  241. void vmw_du_connector_restore(struct drm_connector *connector);
  242. enum drm_connector_status
  243. vmw_du_connector_detect(struct drm_connector *connector, bool force);
  244. int vmw_du_connector_fill_modes(struct drm_connector *connector,
  245. uint32_t max_width, uint32_t max_height);
  246. int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
  247. struct vmw_framebuffer *framebuffer,
  248. const struct drm_clip_rect *clips,
  249. const struct drm_vmw_rect *vclips,
  250. s32 dest_x, s32 dest_y,
  251. int num_clips,
  252. int increment,
  253. struct vmw_kms_dirty *dirty);
  254. int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
  255. struct vmw_dma_buffer *buf,
  256. bool interruptible,
  257. bool validate_as_mob);
  258. void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
  259. void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
  260. struct drm_file *file_priv,
  261. struct vmw_dma_buffer *buf,
  262. struct vmw_fence_obj **out_fence,
  263. struct drm_vmw_fence_rep __user *
  264. user_fence_rep);
  265. int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
  266. bool interruptible,
  267. struct vmw_validation_ctx *ctx);
  268. void vmw_kms_helper_resource_revert(struct vmw_validation_ctx *ctx);
  269. void vmw_kms_helper_resource_finish(struct vmw_validation_ctx *ctx,
  270. struct vmw_fence_obj **out_fence);
  271. int vmw_kms_readback(struct vmw_private *dev_priv,
  272. struct drm_file *file_priv,
  273. struct vmw_framebuffer *vfb,
  274. struct drm_vmw_fence_rep __user *user_fence_rep,
  275. struct drm_vmw_rect *vclips,
  276. uint32_t num_clips);
  277. struct vmw_framebuffer *
  278. vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
  279. struct vmw_dma_buffer *dmabuf,
  280. struct vmw_surface *surface,
  281. bool only_2d,
  282. const struct drm_mode_fb_cmd2 *mode_cmd);
  283. int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
  284. unsigned unit,
  285. u32 max_width,
  286. u32 max_height,
  287. struct drm_connector **p_con,
  288. struct drm_crtc **p_crtc,
  289. struct drm_display_mode **p_mode);
  290. void vmw_guess_mode_timing(struct drm_display_mode *mode);
  291. void vmw_kms_del_active(struct vmw_private *dev_priv,
  292. struct vmw_display_unit *du);
  293. void vmw_kms_add_active(struct vmw_private *dev_priv,
  294. struct vmw_display_unit *du,
  295. struct vmw_framebuffer *vfb);
  296. bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
  297. struct drm_crtc *crtc);
  298. void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
  299. struct drm_crtc *crtc);
  300. void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
  301. bool immutable);
  302. /* Universal Plane Helpers */
  303. void vmw_du_primary_plane_destroy(struct drm_plane *plane);
  304. void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
  305. /* Atomic Helpers */
  306. int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
  307. struct drm_plane_state *state);
  308. int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
  309. struct drm_plane_state *state);
  310. void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
  311. struct drm_plane_state *old_state);
  312. int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
  313. struct drm_plane_state *new_state);
  314. void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
  315. struct drm_plane_state *old_state);
  316. void vmw_du_plane_reset(struct drm_plane *plane);
  317. struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
  318. void vmw_du_plane_destroy_state(struct drm_plane *plane,
  319. struct drm_plane_state *state);
  320. void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
  321. bool unreference);
  322. int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
  323. struct drm_crtc_state *state);
  324. void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
  325. struct drm_crtc_state *old_crtc_state);
  326. void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
  327. struct drm_crtc_state *old_crtc_state);
  328. void vmw_du_crtc_reset(struct drm_crtc *crtc);
  329. struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
  330. void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
  331. struct drm_crtc_state *state);
  332. void vmw_du_connector_reset(struct drm_connector *connector);
  333. struct drm_connector_state *
  334. vmw_du_connector_duplicate_state(struct drm_connector *connector);
  335. void vmw_du_connector_destroy_state(struct drm_connector *connector,
  336. struct drm_connector_state *state);
  337. /*
  338. * Legacy display unit functions - vmwgfx_ldu.c
  339. */
  340. int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
  341. int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
  342. int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
  343. struct vmw_framebuffer *framebuffer,
  344. unsigned flags, unsigned color,
  345. struct drm_clip_rect *clips,
  346. unsigned num_clips, int increment);
  347. int vmw_kms_update_proxy(struct vmw_resource *res,
  348. const struct drm_clip_rect *clips,
  349. unsigned num_clips,
  350. int increment);
  351. /*
  352. * Screen Objects display functions - vmwgfx_scrn.c
  353. */
  354. int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
  355. int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
  356. struct vmw_framebuffer *framebuffer,
  357. struct drm_clip_rect *clips,
  358. struct drm_vmw_rect *vclips,
  359. struct vmw_resource *srf,
  360. s32 dest_x,
  361. s32 dest_y,
  362. unsigned num_clips, int inc,
  363. struct vmw_fence_obj **out_fence);
  364. int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
  365. struct vmw_framebuffer *framebuffer,
  366. struct drm_clip_rect *clips,
  367. struct drm_vmw_rect *vclips,
  368. unsigned num_clips, int increment,
  369. bool interruptible,
  370. struct vmw_fence_obj **out_fence);
  371. int vmw_kms_sou_readback(struct vmw_private *dev_priv,
  372. struct drm_file *file_priv,
  373. struct vmw_framebuffer *vfb,
  374. struct drm_vmw_fence_rep __user *user_fence_rep,
  375. struct drm_vmw_rect *vclips,
  376. uint32_t num_clips);
  377. /*
  378. * Screen Target Display Unit functions - vmwgfx_stdu.c
  379. */
  380. int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
  381. int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
  382. struct vmw_framebuffer *framebuffer,
  383. struct drm_clip_rect *clips,
  384. struct drm_vmw_rect *vclips,
  385. struct vmw_resource *srf,
  386. s32 dest_x,
  387. s32 dest_y,
  388. unsigned num_clips, int inc,
  389. struct vmw_fence_obj **out_fence);
  390. int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
  391. struct drm_file *file_priv,
  392. struct vmw_framebuffer *vfb,
  393. struct drm_vmw_fence_rep __user *user_fence_rep,
  394. struct drm_clip_rect *clips,
  395. struct drm_vmw_rect *vclips,
  396. uint32_t num_clips,
  397. int increment,
  398. bool to_surface,
  399. bool interruptible);
  400. int vmw_kms_set_config(struct drm_mode_set *set,
  401. struct drm_modeset_acquire_ctx *ctx);
  402. #endif