vmwgfx_kms.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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/drm_encoder.h>
  30. #include <drm/drm_probe_helper.h>
  31. #include "vmwgfx_drv.h"
  32. /**
  33. * struct vmw_du_update_plane - Closure structure for vmw_du_helper_plane_update
  34. * @plane: Plane which is being updated.
  35. * @old_state: Old state of plane.
  36. * @dev_priv: Device private.
  37. * @du: Display unit on which to update the plane.
  38. * @vfb: Framebuffer which is blitted to display unit.
  39. * @out_fence: Out fence for resource finish.
  40. * @mutex: The mutex used to protect resource reservation.
  41. * @cpu_blit: True if need cpu blit.
  42. * @intr: Whether to perform waits interruptible if possible.
  43. *
  44. * This structure loosely represent the set of operations needed to perform a
  45. * plane update on a display unit. Implementer will define that functionality
  46. * according to the function callbacks for this structure. In brief it involves
  47. * surface/buffer object validation, populate FIFO commands and command
  48. * submission to the device.
  49. */
  50. struct vmw_du_update_plane {
  51. /**
  52. * @calc_fifo_size: Calculate fifo size.
  53. *
  54. * Determine fifo size for the commands needed for update. The number of
  55. * damage clips on display unit @num_hits will be passed to allocate
  56. * sufficient fifo space.
  57. *
  58. * Return: Fifo size needed
  59. */
  60. uint32_t (*calc_fifo_size)(struct vmw_du_update_plane *update,
  61. uint32_t num_hits);
  62. /**
  63. * @post_prepare: Populate fifo for resource preparation.
  64. *
  65. * Some surface resource or buffer object need some extra cmd submission
  66. * like update GB image for proxy surface and define a GMRFB for screen
  67. * object. That should should be done here as this callback will be
  68. * called after FIFO allocation with the address of command buufer.
  69. *
  70. * This callback is optional.
  71. *
  72. * Return: Size of commands populated to command buffer.
  73. */
  74. uint32_t (*post_prepare)(struct vmw_du_update_plane *update, void *cmd);
  75. /**
  76. * @pre_clip: Populate fifo before clip.
  77. *
  78. * This is where pre clip related command should be populated like
  79. * surface copy/DMA, etc.
  80. *
  81. * This callback is optional.
  82. *
  83. * Return: Size of commands populated to command buffer.
  84. */
  85. uint32_t (*pre_clip)(struct vmw_du_update_plane *update, void *cmd,
  86. uint32_t num_hits);
  87. /**
  88. * @clip: Populate fifo for clip.
  89. *
  90. * This is where to populate clips for surface copy/dma or blit commands
  91. * if needed. This will be called times have damage in display unit,
  92. * which is one if doing full update. @clip is the damage in destination
  93. * coordinates which is crtc/DU and @src_x, @src_y is damage clip src in
  94. * framebuffer coordinate.
  95. *
  96. * This callback is optional.
  97. *
  98. * Return: Size of commands populated to command buffer.
  99. */
  100. uint32_t (*clip)(struct vmw_du_update_plane *update, void *cmd,
  101. struct drm_rect *clip, uint32_t src_x, uint32_t src_y);
  102. /**
  103. * @post_clip: Populate fifo after clip.
  104. *
  105. * This is where to populate display unit update commands or blit
  106. * commands.
  107. *
  108. * Return: Size of commands populated to command buffer.
  109. */
  110. uint32_t (*post_clip)(struct vmw_du_update_plane *update, void *cmd,
  111. struct drm_rect *bb);
  112. struct drm_plane *plane;
  113. struct drm_plane_state *old_state;
  114. struct vmw_private *dev_priv;
  115. struct vmw_display_unit *du;
  116. struct vmw_framebuffer *vfb;
  117. struct vmw_fence_obj **out_fence;
  118. struct mutex *mutex;
  119. bool cpu_blit;
  120. bool intr;
  121. };
  122. /**
  123. * struct vmw_du_update_plane_surface - closure structure for surface
  124. * @base: base closure structure.
  125. * @cmd_start: FIFO command start address (used by SOU only).
  126. */
  127. struct vmw_du_update_plane_surface {
  128. struct vmw_du_update_plane base;
  129. /* This member is to handle special case SOU surface update */
  130. void *cmd_start;
  131. };
  132. /**
  133. * struct vmw_du_update_plane_buffer - Closure structure for buffer object
  134. * @base: Base closure structure.
  135. * @fb_left: x1 for fb damage bounding box.
  136. * @fb_top: y1 for fb damage bounding box.
  137. */
  138. struct vmw_du_update_plane_buffer {
  139. struct vmw_du_update_plane base;
  140. int fb_left, fb_top;
  141. };
  142. /**
  143. * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
  144. * function.
  145. *
  146. * @fifo_commit: Callback that is called once for each display unit after
  147. * all clip rects. This function must commit the fifo space reserved by the
  148. * helper. Set up by the caller.
  149. * @clip: Callback that is called for each cliprect on each display unit.
  150. * Set up by the caller.
  151. * @fifo_reserve_size: Fifo size that the helper should try to allocat for
  152. * each display unit. Set up by the caller.
  153. * @dev_priv: Pointer to the device private. Set up by the helper.
  154. * @unit: The current display unit. Set up by the helper before a call to @clip.
  155. * @cmd: The allocated fifo space. Set up by the helper before the first @clip
  156. * call.
  157. * @crtc: The crtc for which to build dirty commands.
  158. * @num_hits: Number of clip rect commands for this display unit.
  159. * Cleared by the helper before the first @clip call. Updated by the @clip
  160. * callback.
  161. * @fb_x: Clip rect left side in framebuffer coordinates.
  162. * @fb_y: Clip rect right side in framebuffer coordinates.
  163. * @unit_x1: Clip rect left side in crtc coordinates.
  164. * @unit_y1: Clip rect top side in crtc coordinates.
  165. * @unit_x2: Clip rect right side in crtc coordinates.
  166. * @unit_y2: Clip rect bottom side in crtc coordinates.
  167. *
  168. * The clip rect coordinates are updated by the helper for each @clip call.
  169. * Note that this may be derived from if more info needs to be passed between
  170. * helper caller and helper callbacks.
  171. */
  172. struct vmw_kms_dirty {
  173. void (*fifo_commit)(struct vmw_kms_dirty *);
  174. void (*clip)(struct vmw_kms_dirty *);
  175. size_t fifo_reserve_size;
  176. struct vmw_private *dev_priv;
  177. struct vmw_display_unit *unit;
  178. void *cmd;
  179. struct drm_crtc *crtc;
  180. u32 num_hits;
  181. s32 fb_x;
  182. s32 fb_y;
  183. s32 unit_x1;
  184. s32 unit_y1;
  185. s32 unit_x2;
  186. s32 unit_y2;
  187. };
  188. #define VMWGFX_NUM_DISPLAY_UNITS 8
  189. #define vmw_framebuffer_to_vfb(x) \
  190. container_of(x, struct vmw_framebuffer, base)
  191. #define vmw_framebuffer_to_vfbs(x) \
  192. container_of(x, struct vmw_framebuffer_surface, base.base)
  193. #define vmw_framebuffer_to_vfbd(x) \
  194. container_of(x, struct vmw_framebuffer_bo, base.base)
  195. /**
  196. * Base class for framebuffers
  197. *
  198. * @pin is called the when ever a crtc uses this framebuffer
  199. * @unpin is called
  200. */
  201. struct vmw_framebuffer {
  202. struct drm_framebuffer base;
  203. int (*pin)(struct vmw_framebuffer *fb);
  204. int (*unpin)(struct vmw_framebuffer *fb);
  205. bool bo;
  206. struct ttm_base_object *user_obj;
  207. uint32_t user_handle;
  208. };
  209. /*
  210. * Clip rectangle
  211. */
  212. struct vmw_clip_rect {
  213. int x1, x2, y1, y2;
  214. };
  215. struct vmw_framebuffer_surface {
  216. struct vmw_framebuffer base;
  217. struct vmw_surface *surface;
  218. struct vmw_buffer_object *buffer;
  219. struct list_head head;
  220. bool is_bo_proxy; /* true if this is proxy surface for DMA buf */
  221. };
  222. struct vmw_framebuffer_bo {
  223. struct vmw_framebuffer base;
  224. struct vmw_buffer_object *buffer;
  225. };
  226. static const uint32_t vmw_primary_plane_formats[] = {
  227. DRM_FORMAT_XRGB1555,
  228. DRM_FORMAT_RGB565,
  229. DRM_FORMAT_RGB888,
  230. DRM_FORMAT_XRGB8888,
  231. DRM_FORMAT_ARGB8888,
  232. };
  233. static const uint32_t vmw_cursor_plane_formats[] = {
  234. DRM_FORMAT_ARGB8888,
  235. };
  236. #define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
  237. #define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
  238. #define vmw_connector_state_to_vcs(x) \
  239. container_of(x, struct vmw_connector_state, base)
  240. /**
  241. * Derived class for crtc state object
  242. *
  243. * @base DRM crtc object
  244. */
  245. struct vmw_crtc_state {
  246. struct drm_crtc_state base;
  247. };
  248. /**
  249. * Derived class for plane state object
  250. *
  251. * @base DRM plane object
  252. * @surf Display surface for STDU
  253. * @bo display bo for SOU
  254. * @content_fb_type Used by STDU.
  255. * @bo_size Size of the bo, used by Screen Object Display Unit
  256. * @pinned pin count for STDU display surface
  257. */
  258. struct vmw_plane_state {
  259. struct drm_plane_state base;
  260. struct vmw_surface *surf;
  261. struct vmw_buffer_object *bo;
  262. int content_fb_type;
  263. unsigned long bo_size;
  264. int pinned;
  265. /* For CPU Blit */
  266. unsigned int cpp;
  267. };
  268. /**
  269. * Derived class for connector state object
  270. *
  271. * @base DRM connector object
  272. * @is_implicit connector property
  273. *
  274. */
  275. struct vmw_connector_state {
  276. struct drm_connector_state base;
  277. /**
  278. * @gui_x:
  279. *
  280. * vmwgfx connector property representing the x position of this display
  281. * unit (connector is synonymous to display unit) in overall topology.
  282. * This is what the device expect as xRoot while creating screen.
  283. */
  284. int gui_x;
  285. /**
  286. * @gui_y:
  287. *
  288. * vmwgfx connector property representing the y position of this display
  289. * unit (connector is synonymous to display unit) in overall topology.
  290. * This is what the device expect as yRoot while creating screen.
  291. */
  292. int gui_y;
  293. };
  294. /**
  295. * Base class display unit.
  296. *
  297. * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
  298. * so the display unit is all of them at the same time. This is true for both
  299. * legacy multimon and screen objects.
  300. */
  301. struct vmw_display_unit {
  302. struct drm_crtc crtc;
  303. struct drm_encoder encoder;
  304. struct drm_connector connector;
  305. struct drm_plane primary;
  306. struct drm_plane cursor;
  307. struct vmw_surface *cursor_surface;
  308. struct vmw_buffer_object *cursor_bo;
  309. size_t cursor_age;
  310. int cursor_x;
  311. int cursor_y;
  312. int hotspot_x;
  313. int hotspot_y;
  314. s32 core_hotspot_x;
  315. s32 core_hotspot_y;
  316. unsigned unit;
  317. /*
  318. * Prefered mode tracking.
  319. */
  320. unsigned pref_width;
  321. unsigned pref_height;
  322. bool pref_active;
  323. struct drm_display_mode *pref_mode;
  324. /*
  325. * Gui positioning
  326. */
  327. int gui_x;
  328. int gui_y;
  329. bool is_implicit;
  330. int set_gui_x;
  331. int set_gui_y;
  332. };
  333. struct vmw_validation_ctx {
  334. struct vmw_resource *res;
  335. struct vmw_buffer_object *buf;
  336. };
  337. #define vmw_crtc_to_du(x) \
  338. container_of(x, struct vmw_display_unit, crtc)
  339. #define vmw_connector_to_du(x) \
  340. container_of(x, struct vmw_display_unit, connector)
  341. /*
  342. * Shared display unit functions - vmwgfx_kms.c
  343. */
  344. void vmw_du_cleanup(struct vmw_display_unit *du);
  345. void vmw_du_crtc_save(struct drm_crtc *crtc);
  346. void vmw_du_crtc_restore(struct drm_crtc *crtc);
  347. int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
  348. u16 *r, u16 *g, u16 *b,
  349. uint32_t size,
  350. struct drm_modeset_acquire_ctx *ctx);
  351. int vmw_du_connector_set_property(struct drm_connector *connector,
  352. struct drm_property *property,
  353. uint64_t val);
  354. int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
  355. struct drm_connector_state *state,
  356. struct drm_property *property,
  357. uint64_t val);
  358. int
  359. vmw_du_connector_atomic_get_property(struct drm_connector *connector,
  360. const struct drm_connector_state *state,
  361. struct drm_property *property,
  362. uint64_t *val);
  363. int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
  364. void vmw_du_connector_save(struct drm_connector *connector);
  365. void vmw_du_connector_restore(struct drm_connector *connector);
  366. enum drm_connector_status
  367. vmw_du_connector_detect(struct drm_connector *connector, bool force);
  368. int vmw_du_connector_fill_modes(struct drm_connector *connector,
  369. uint32_t max_width, uint32_t max_height);
  370. int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
  371. struct vmw_framebuffer *framebuffer,
  372. const struct drm_clip_rect *clips,
  373. const struct drm_vmw_rect *vclips,
  374. s32 dest_x, s32 dest_y,
  375. int num_clips,
  376. int increment,
  377. struct vmw_kms_dirty *dirty);
  378. void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
  379. struct drm_file *file_priv,
  380. struct vmw_validation_context *ctx,
  381. struct vmw_fence_obj **out_fence,
  382. struct drm_vmw_fence_rep __user *
  383. user_fence_rep);
  384. int vmw_kms_readback(struct vmw_private *dev_priv,
  385. struct drm_file *file_priv,
  386. struct vmw_framebuffer *vfb,
  387. struct drm_vmw_fence_rep __user *user_fence_rep,
  388. struct drm_vmw_rect *vclips,
  389. uint32_t num_clips);
  390. struct vmw_framebuffer *
  391. vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
  392. struct vmw_buffer_object *bo,
  393. struct vmw_surface *surface,
  394. bool only_2d,
  395. const struct drm_mode_fb_cmd2 *mode_cmd);
  396. int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
  397. unsigned unit,
  398. u32 max_width,
  399. u32 max_height,
  400. struct drm_connector **p_con,
  401. struct drm_crtc **p_crtc,
  402. struct drm_display_mode **p_mode);
  403. void vmw_guess_mode_timing(struct drm_display_mode *mode);
  404. void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv);
  405. void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv);
  406. /* Universal Plane Helpers */
  407. void vmw_du_primary_plane_destroy(struct drm_plane *plane);
  408. void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
  409. /* Atomic Helpers */
  410. int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
  411. struct drm_plane_state *state);
  412. int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
  413. struct drm_plane_state *state);
  414. void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
  415. struct drm_plane_state *old_state);
  416. int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
  417. struct drm_plane_state *new_state);
  418. void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
  419. struct drm_plane_state *old_state);
  420. void vmw_du_plane_reset(struct drm_plane *plane);
  421. struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
  422. void vmw_du_plane_destroy_state(struct drm_plane *plane,
  423. struct drm_plane_state *state);
  424. void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
  425. bool unreference);
  426. int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
  427. struct drm_crtc_state *state);
  428. void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
  429. struct drm_crtc_state *old_crtc_state);
  430. void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
  431. struct drm_crtc_state *old_crtc_state);
  432. void vmw_du_crtc_reset(struct drm_crtc *crtc);
  433. struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
  434. void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
  435. struct drm_crtc_state *state);
  436. void vmw_du_connector_reset(struct drm_connector *connector);
  437. struct drm_connector_state *
  438. vmw_du_connector_duplicate_state(struct drm_connector *connector);
  439. void vmw_du_connector_destroy_state(struct drm_connector *connector,
  440. struct drm_connector_state *state);
  441. /*
  442. * Legacy display unit functions - vmwgfx_ldu.c
  443. */
  444. int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
  445. int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
  446. int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv,
  447. struct vmw_framebuffer *framebuffer,
  448. unsigned int flags, unsigned int color,
  449. struct drm_clip_rect *clips,
  450. unsigned int num_clips, int increment);
  451. int vmw_kms_update_proxy(struct vmw_resource *res,
  452. const struct drm_clip_rect *clips,
  453. unsigned num_clips,
  454. int increment);
  455. /*
  456. * Screen Objects display functions - vmwgfx_scrn.c
  457. */
  458. int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
  459. int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
  460. struct vmw_framebuffer *framebuffer,
  461. struct drm_clip_rect *clips,
  462. struct drm_vmw_rect *vclips,
  463. struct vmw_resource *srf,
  464. s32 dest_x,
  465. s32 dest_y,
  466. unsigned num_clips, int inc,
  467. struct vmw_fence_obj **out_fence,
  468. struct drm_crtc *crtc);
  469. int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv,
  470. struct vmw_framebuffer *framebuffer,
  471. struct drm_clip_rect *clips,
  472. struct drm_vmw_rect *vclips,
  473. unsigned int num_clips, int increment,
  474. bool interruptible,
  475. struct vmw_fence_obj **out_fence,
  476. struct drm_crtc *crtc);
  477. int vmw_kms_sou_readback(struct vmw_private *dev_priv,
  478. struct drm_file *file_priv,
  479. struct vmw_framebuffer *vfb,
  480. struct drm_vmw_fence_rep __user *user_fence_rep,
  481. struct drm_vmw_rect *vclips,
  482. uint32_t num_clips,
  483. struct drm_crtc *crtc);
  484. /*
  485. * Screen Target Display Unit functions - vmwgfx_stdu.c
  486. */
  487. int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
  488. int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
  489. struct vmw_framebuffer *framebuffer,
  490. struct drm_clip_rect *clips,
  491. struct drm_vmw_rect *vclips,
  492. struct vmw_resource *srf,
  493. s32 dest_x,
  494. s32 dest_y,
  495. unsigned num_clips, int inc,
  496. struct vmw_fence_obj **out_fence,
  497. struct drm_crtc *crtc);
  498. int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
  499. struct drm_file *file_priv,
  500. struct vmw_framebuffer *vfb,
  501. struct drm_vmw_fence_rep __user *user_fence_rep,
  502. struct drm_clip_rect *clips,
  503. struct drm_vmw_rect *vclips,
  504. uint32_t num_clips,
  505. int increment,
  506. bool to_surface,
  507. bool interruptible,
  508. struct drm_crtc *crtc);
  509. int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
  510. /**
  511. * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
  512. * @state: Plane state.
  513. * @r: Rectangle to translate.
  514. */
  515. static inline void vmw_du_translate_to_crtc(struct drm_plane_state *state,
  516. struct drm_rect *r)
  517. {
  518. int translate_crtc_x = -((state->src_x >> 16) - state->crtc_x);
  519. int translate_crtc_y = -((state->src_y >> 16) - state->crtc_y);
  520. drm_rect_translate(r, translate_crtc_x, translate_crtc_y);
  521. }
  522. #endif