vmwgfx_kms.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /**************************************************************************
  3. *
  4. * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
  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. * @crtc: The crtc for which to build dirty commands.
  49. * @num_hits: Number of clip rect commands for this display unit.
  50. * Cleared by the helper before the first @clip call. Updated by the @clip
  51. * callback.
  52. * @fb_x: Clip rect left side in framebuffer coordinates.
  53. * @fb_y: Clip rect right side in framebuffer coordinates.
  54. * @unit_x1: Clip rect left side in crtc coordinates.
  55. * @unit_y1: Clip rect top side in crtc coordinates.
  56. * @unit_x2: Clip rect right side in crtc coordinates.
  57. * @unit_y2: Clip rect bottom side in crtc coordinates.
  58. *
  59. * The clip rect coordinates are updated by the helper for each @clip call.
  60. * Note that this may be derived from if more info needs to be passed between
  61. * helper caller and helper callbacks.
  62. */
  63. struct vmw_kms_dirty {
  64. void (*fifo_commit)(struct vmw_kms_dirty *);
  65. void (*clip)(struct vmw_kms_dirty *);
  66. size_t fifo_reserve_size;
  67. struct vmw_private *dev_priv;
  68. struct vmw_display_unit *unit;
  69. void *cmd;
  70. struct drm_crtc *crtc;
  71. u32 num_hits;
  72. s32 fb_x;
  73. s32 fb_y;
  74. s32 unit_x1;
  75. s32 unit_y1;
  76. s32 unit_x2;
  77. s32 unit_y2;
  78. };
  79. #define VMWGFX_NUM_DISPLAY_UNITS 8
  80. #define vmw_framebuffer_to_vfb(x) \
  81. container_of(x, struct vmw_framebuffer, base)
  82. #define vmw_framebuffer_to_vfbs(x) \
  83. container_of(x, struct vmw_framebuffer_surface, base.base)
  84. #define vmw_framebuffer_to_vfbd(x) \
  85. container_of(x, struct vmw_framebuffer_bo, base.base)
  86. /**
  87. * Base class for framebuffers
  88. *
  89. * @pin is called the when ever a crtc uses this framebuffer
  90. * @unpin is called
  91. */
  92. struct vmw_framebuffer {
  93. struct drm_framebuffer base;
  94. int (*pin)(struct vmw_framebuffer *fb);
  95. int (*unpin)(struct vmw_framebuffer *fb);
  96. bool bo;
  97. struct ttm_base_object *user_obj;
  98. uint32_t user_handle;
  99. };
  100. /*
  101. * Clip rectangle
  102. */
  103. struct vmw_clip_rect {
  104. int x1, x2, y1, y2;
  105. };
  106. struct vmw_framebuffer_surface {
  107. struct vmw_framebuffer base;
  108. struct vmw_surface *surface;
  109. struct vmw_buffer_object *buffer;
  110. struct list_head head;
  111. bool is_bo_proxy; /* true if this is proxy surface for DMA buf */
  112. };
  113. struct vmw_framebuffer_bo {
  114. struct vmw_framebuffer base;
  115. struct vmw_buffer_object *buffer;
  116. };
  117. static const uint32_t vmw_primary_plane_formats[] = {
  118. DRM_FORMAT_XRGB1555,
  119. DRM_FORMAT_RGB565,
  120. DRM_FORMAT_RGB888,
  121. DRM_FORMAT_XRGB8888,
  122. DRM_FORMAT_ARGB8888,
  123. };
  124. static const uint32_t vmw_cursor_plane_formats[] = {
  125. DRM_FORMAT_ARGB8888,
  126. };
  127. #define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
  128. #define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
  129. #define vmw_connector_state_to_vcs(x) \
  130. container_of(x, struct vmw_connector_state, base)
  131. /**
  132. * Derived class for crtc state object
  133. *
  134. * @base DRM crtc object
  135. */
  136. struct vmw_crtc_state {
  137. struct drm_crtc_state base;
  138. };
  139. /**
  140. * Derived class for plane state object
  141. *
  142. * @base DRM plane object
  143. * @surf Display surface for STDU
  144. * @bo display bo for SOU
  145. * @content_fb_type Used by STDU.
  146. * @bo_size Size of the bo, used by Screen Object Display Unit
  147. * @pinned pin count for STDU display surface
  148. */
  149. struct vmw_plane_state {
  150. struct drm_plane_state base;
  151. struct vmw_surface *surf;
  152. struct vmw_buffer_object *bo;
  153. int content_fb_type;
  154. unsigned long bo_size;
  155. int pinned;
  156. /* For CPU Blit */
  157. unsigned int cpp;
  158. };
  159. /**
  160. * Derived class for connector state object
  161. *
  162. * @base DRM connector object
  163. * @is_implicit connector property
  164. *
  165. */
  166. struct vmw_connector_state {
  167. struct drm_connector_state base;
  168. bool is_implicit;
  169. /**
  170. * @gui_x:
  171. *
  172. * vmwgfx connector property representing the x position of this display
  173. * unit (connector is synonymous to display unit) in overall topology.
  174. * This is what the device expect as xRoot while creating screen.
  175. */
  176. int gui_x;
  177. /**
  178. * @gui_y:
  179. *
  180. * vmwgfx connector property representing the y position of this display
  181. * unit (connector is synonymous to display unit) in overall topology.
  182. * This is what the device expect as yRoot while creating screen.
  183. */
  184. int gui_y;
  185. };
  186. /**
  187. * Base class display unit.
  188. *
  189. * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
  190. * so the display unit is all of them at the same time. This is true for both
  191. * legacy multimon and screen objects.
  192. */
  193. struct vmw_display_unit {
  194. struct drm_crtc crtc;
  195. struct drm_encoder encoder;
  196. struct drm_connector connector;
  197. struct drm_plane primary;
  198. struct drm_plane cursor;
  199. struct vmw_surface *cursor_surface;
  200. struct vmw_buffer_object *cursor_bo;
  201. size_t cursor_age;
  202. int cursor_x;
  203. int cursor_y;
  204. int hotspot_x;
  205. int hotspot_y;
  206. s32 core_hotspot_x;
  207. s32 core_hotspot_y;
  208. unsigned unit;
  209. /*
  210. * Prefered mode tracking.
  211. */
  212. unsigned pref_width;
  213. unsigned pref_height;
  214. bool pref_active;
  215. struct drm_display_mode *pref_mode;
  216. /*
  217. * Gui positioning
  218. */
  219. int gui_x;
  220. int gui_y;
  221. bool is_implicit;
  222. bool active_implicit;
  223. int set_gui_x;
  224. int set_gui_y;
  225. };
  226. struct vmw_validation_ctx {
  227. struct vmw_resource *res;
  228. struct vmw_buffer_object *buf;
  229. };
  230. #define vmw_crtc_to_du(x) \
  231. container_of(x, struct vmw_display_unit, crtc)
  232. #define vmw_connector_to_du(x) \
  233. container_of(x, struct vmw_display_unit, connector)
  234. /*
  235. * Shared display unit functions - vmwgfx_kms.c
  236. */
  237. void vmw_du_cleanup(struct vmw_display_unit *du);
  238. void vmw_du_crtc_save(struct drm_crtc *crtc);
  239. void vmw_du_crtc_restore(struct drm_crtc *crtc);
  240. int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
  241. u16 *r, u16 *g, u16 *b,
  242. uint32_t size,
  243. struct drm_modeset_acquire_ctx *ctx);
  244. int vmw_du_connector_set_property(struct drm_connector *connector,
  245. struct drm_property *property,
  246. uint64_t val);
  247. int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
  248. struct drm_connector_state *state,
  249. struct drm_property *property,
  250. uint64_t val);
  251. int
  252. vmw_du_connector_atomic_get_property(struct drm_connector *connector,
  253. const struct drm_connector_state *state,
  254. struct drm_property *property,
  255. uint64_t *val);
  256. int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
  257. void vmw_du_connector_save(struct drm_connector *connector);
  258. void vmw_du_connector_restore(struct drm_connector *connector);
  259. enum drm_connector_status
  260. vmw_du_connector_detect(struct drm_connector *connector, bool force);
  261. int vmw_du_connector_fill_modes(struct drm_connector *connector,
  262. uint32_t max_width, uint32_t max_height);
  263. int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
  264. struct vmw_framebuffer *framebuffer,
  265. const struct drm_clip_rect *clips,
  266. const struct drm_vmw_rect *vclips,
  267. s32 dest_x, s32 dest_y,
  268. int num_clips,
  269. int increment,
  270. struct vmw_kms_dirty *dirty);
  271. int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
  272. struct vmw_buffer_object *buf,
  273. bool interruptible,
  274. bool validate_as_mob,
  275. bool for_cpu_blit);
  276. void vmw_kms_helper_buffer_revert(struct vmw_buffer_object *buf);
  277. void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
  278. struct drm_file *file_priv,
  279. struct vmw_buffer_object *buf,
  280. struct vmw_fence_obj **out_fence,
  281. struct drm_vmw_fence_rep __user *
  282. user_fence_rep);
  283. int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
  284. bool interruptible,
  285. struct vmw_validation_ctx *ctx);
  286. void vmw_kms_helper_resource_revert(struct vmw_validation_ctx *ctx);
  287. void vmw_kms_helper_resource_finish(struct vmw_validation_ctx *ctx,
  288. struct vmw_fence_obj **out_fence);
  289. int vmw_kms_readback(struct vmw_private *dev_priv,
  290. struct drm_file *file_priv,
  291. struct vmw_framebuffer *vfb,
  292. struct drm_vmw_fence_rep __user *user_fence_rep,
  293. struct drm_vmw_rect *vclips,
  294. uint32_t num_clips);
  295. struct vmw_framebuffer *
  296. vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
  297. struct vmw_buffer_object *bo,
  298. struct vmw_surface *surface,
  299. bool only_2d,
  300. const struct drm_mode_fb_cmd2 *mode_cmd);
  301. int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
  302. unsigned unit,
  303. u32 max_width,
  304. u32 max_height,
  305. struct drm_connector **p_con,
  306. struct drm_crtc **p_crtc,
  307. struct drm_display_mode **p_mode);
  308. void vmw_guess_mode_timing(struct drm_display_mode *mode);
  309. void vmw_kms_del_active(struct vmw_private *dev_priv,
  310. struct vmw_display_unit *du);
  311. void vmw_kms_add_active(struct vmw_private *dev_priv,
  312. struct vmw_display_unit *du,
  313. struct vmw_framebuffer *vfb);
  314. bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
  315. struct drm_crtc *crtc);
  316. void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
  317. struct drm_crtc *crtc);
  318. void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
  319. bool immutable);
  320. /* Universal Plane Helpers */
  321. void vmw_du_primary_plane_destroy(struct drm_plane *plane);
  322. void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
  323. /* Atomic Helpers */
  324. int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
  325. struct drm_plane_state *state);
  326. int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
  327. struct drm_plane_state *state);
  328. void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
  329. struct drm_plane_state *old_state);
  330. int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
  331. struct drm_plane_state *new_state);
  332. void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
  333. struct drm_plane_state *old_state);
  334. void vmw_du_plane_reset(struct drm_plane *plane);
  335. struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
  336. void vmw_du_plane_destroy_state(struct drm_plane *plane,
  337. struct drm_plane_state *state);
  338. void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
  339. bool unreference);
  340. int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
  341. struct drm_crtc_state *state);
  342. void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
  343. struct drm_crtc_state *old_crtc_state);
  344. void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
  345. struct drm_crtc_state *old_crtc_state);
  346. void vmw_du_crtc_reset(struct drm_crtc *crtc);
  347. struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
  348. void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
  349. struct drm_crtc_state *state);
  350. void vmw_du_connector_reset(struct drm_connector *connector);
  351. struct drm_connector_state *
  352. vmw_du_connector_duplicate_state(struct drm_connector *connector);
  353. void vmw_du_connector_destroy_state(struct drm_connector *connector,
  354. struct drm_connector_state *state);
  355. /*
  356. * Legacy display unit functions - vmwgfx_ldu.c
  357. */
  358. int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
  359. int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
  360. int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv,
  361. struct vmw_framebuffer *framebuffer,
  362. unsigned int flags, unsigned int color,
  363. struct drm_clip_rect *clips,
  364. unsigned int num_clips, int increment);
  365. int vmw_kms_update_proxy(struct vmw_resource *res,
  366. const struct drm_clip_rect *clips,
  367. unsigned num_clips,
  368. int increment);
  369. /*
  370. * Screen Objects display functions - vmwgfx_scrn.c
  371. */
  372. int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
  373. int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
  374. struct vmw_framebuffer *framebuffer,
  375. struct drm_clip_rect *clips,
  376. struct drm_vmw_rect *vclips,
  377. struct vmw_resource *srf,
  378. s32 dest_x,
  379. s32 dest_y,
  380. unsigned num_clips, int inc,
  381. struct vmw_fence_obj **out_fence,
  382. struct drm_crtc *crtc);
  383. int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv,
  384. struct vmw_framebuffer *framebuffer,
  385. struct drm_clip_rect *clips,
  386. struct drm_vmw_rect *vclips,
  387. unsigned int num_clips, int increment,
  388. bool interruptible,
  389. struct vmw_fence_obj **out_fence,
  390. struct drm_crtc *crtc);
  391. int vmw_kms_sou_readback(struct vmw_private *dev_priv,
  392. struct drm_file *file_priv,
  393. struct vmw_framebuffer *vfb,
  394. struct drm_vmw_fence_rep __user *user_fence_rep,
  395. struct drm_vmw_rect *vclips,
  396. uint32_t num_clips,
  397. struct drm_crtc *crtc);
  398. /*
  399. * Screen Target Display Unit functions - vmwgfx_stdu.c
  400. */
  401. int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
  402. int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
  403. struct vmw_framebuffer *framebuffer,
  404. struct drm_clip_rect *clips,
  405. struct drm_vmw_rect *vclips,
  406. struct vmw_resource *srf,
  407. s32 dest_x,
  408. s32 dest_y,
  409. unsigned num_clips, int inc,
  410. struct vmw_fence_obj **out_fence,
  411. struct drm_crtc *crtc);
  412. int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
  413. struct drm_file *file_priv,
  414. struct vmw_framebuffer *vfb,
  415. struct drm_vmw_fence_rep __user *user_fence_rep,
  416. struct drm_clip_rect *clips,
  417. struct drm_vmw_rect *vclips,
  418. uint32_t num_clips,
  419. int increment,
  420. bool to_surface,
  421. bool interruptible,
  422. struct drm_crtc *crtc);
  423. int vmw_kms_set_config(struct drm_mode_set *set,
  424. struct drm_modeset_acquire_ctx *ctx);
  425. #endif