vmwgfx_drv.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009 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_DRV_H_
  28. #define _VMWGFX_DRV_H_
  29. #include "vmwgfx_reg.h"
  30. #include <drm/drmP.h>
  31. #include <drm/vmwgfx_drm.h>
  32. #include <drm/drm_hashtab.h>
  33. #include <linux/suspend.h>
  34. #include <drm/ttm/ttm_bo_driver.h>
  35. #include <drm/ttm/ttm_object.h>
  36. #include <drm/ttm/ttm_lock.h>
  37. #include <drm/ttm/ttm_execbuf_util.h>
  38. #include <drm/ttm/ttm_module.h>
  39. #include "vmwgfx_fence.h"
  40. #define VMWGFX_DRIVER_DATE "20140704"
  41. #define VMWGFX_DRIVER_MAJOR 2
  42. #define VMWGFX_DRIVER_MINOR 6
  43. #define VMWGFX_DRIVER_PATCHLEVEL 1
  44. #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
  45. #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
  46. #define VMWGFX_MAX_RELOCATIONS 2048
  47. #define VMWGFX_MAX_VALIDATIONS 2048
  48. #define VMWGFX_MAX_DISPLAYS 16
  49. #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
  50. #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 0
  51. /*
  52. * Perhaps we should have sysfs entries for these.
  53. */
  54. #define VMWGFX_NUM_GB_CONTEXT 256
  55. #define VMWGFX_NUM_GB_SHADER 20000
  56. #define VMWGFX_NUM_GB_SURFACE 32768
  57. #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
  58. #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
  59. VMWGFX_NUM_GB_SHADER +\
  60. VMWGFX_NUM_GB_SURFACE +\
  61. VMWGFX_NUM_GB_SCREEN_TARGET)
  62. #define VMW_PL_GMR TTM_PL_PRIV0
  63. #define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0
  64. #define VMW_PL_MOB TTM_PL_PRIV1
  65. #define VMW_PL_FLAG_MOB TTM_PL_FLAG_PRIV1
  66. #define VMW_RES_CONTEXT ttm_driver_type0
  67. #define VMW_RES_SURFACE ttm_driver_type1
  68. #define VMW_RES_STREAM ttm_driver_type2
  69. #define VMW_RES_FENCE ttm_driver_type3
  70. #define VMW_RES_SHADER ttm_driver_type4
  71. struct vmw_fpriv {
  72. struct drm_master *locked_master;
  73. struct ttm_object_file *tfile;
  74. struct list_head fence_events;
  75. bool gb_aware;
  76. };
  77. struct vmw_dma_buffer {
  78. struct ttm_buffer_object base;
  79. struct list_head res_list;
  80. };
  81. /**
  82. * struct vmw_validate_buffer - Carries validation info about buffers.
  83. *
  84. * @base: Validation info for TTM.
  85. * @hash: Hash entry for quick lookup of the TTM buffer object.
  86. *
  87. * This structure contains also driver private validation info
  88. * on top of the info needed by TTM.
  89. */
  90. struct vmw_validate_buffer {
  91. struct ttm_validate_buffer base;
  92. struct drm_hash_item hash;
  93. bool validate_as_mob;
  94. };
  95. struct vmw_res_func;
  96. struct vmw_resource {
  97. struct kref kref;
  98. struct vmw_private *dev_priv;
  99. int id;
  100. bool avail;
  101. unsigned long backup_size;
  102. bool res_dirty; /* Protected by backup buffer reserved */
  103. bool backup_dirty; /* Protected by backup buffer reserved */
  104. struct vmw_dma_buffer *backup;
  105. unsigned long backup_offset;
  106. const struct vmw_res_func *func;
  107. struct list_head lru_head; /* Protected by the resource lock */
  108. struct list_head mob_head; /* Protected by @backup reserved */
  109. struct list_head binding_head; /* Protected by binding_mutex */
  110. void (*res_free) (struct vmw_resource *res);
  111. void (*hw_destroy) (struct vmw_resource *res);
  112. };
  113. /*
  114. * Resources that are managed using ioctls.
  115. */
  116. enum vmw_res_type {
  117. vmw_res_context,
  118. vmw_res_surface,
  119. vmw_res_stream,
  120. vmw_res_shader,
  121. vmw_res_max
  122. };
  123. /*
  124. * Resources that are managed using command streams.
  125. */
  126. enum vmw_cmdbuf_res_type {
  127. vmw_cmdbuf_res_compat_shader
  128. };
  129. struct vmw_cmdbuf_res_manager;
  130. struct vmw_cursor_snooper {
  131. struct drm_crtc *crtc;
  132. size_t age;
  133. uint32_t *image;
  134. };
  135. struct vmw_framebuffer;
  136. struct vmw_surface_offset;
  137. struct vmw_surface {
  138. struct vmw_resource res;
  139. uint32_t flags;
  140. uint32_t format;
  141. uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
  142. struct drm_vmw_size base_size;
  143. struct drm_vmw_size *sizes;
  144. uint32_t num_sizes;
  145. bool scanout;
  146. /* TODO so far just a extra pointer */
  147. struct vmw_cursor_snooper snooper;
  148. struct vmw_surface_offset *offsets;
  149. SVGA3dTextureFilter autogen_filter;
  150. uint32_t multisample_count;
  151. };
  152. struct vmw_marker_queue {
  153. struct list_head head;
  154. u64 lag;
  155. u64 lag_time;
  156. spinlock_t lock;
  157. };
  158. struct vmw_fifo_state {
  159. unsigned long reserved_size;
  160. __le32 *dynamic_buffer;
  161. __le32 *static_buffer;
  162. unsigned long static_buffer_size;
  163. bool using_bounce_buffer;
  164. uint32_t capabilities;
  165. struct mutex fifo_mutex;
  166. struct rw_semaphore rwsem;
  167. struct vmw_marker_queue marker_queue;
  168. };
  169. struct vmw_relocation {
  170. SVGAMobId *mob_loc;
  171. SVGAGuestPtr *location;
  172. uint32_t index;
  173. };
  174. /**
  175. * struct vmw_res_cache_entry - resource information cache entry
  176. *
  177. * @valid: Whether the entry is valid, which also implies that the execbuf
  178. * code holds a reference to the resource, and it's placed on the
  179. * validation list.
  180. * @handle: User-space handle of a resource.
  181. * @res: Non-ref-counted pointer to the resource.
  182. *
  183. * Used to avoid frequent repeated user-space handle lookups of the
  184. * same resource.
  185. */
  186. struct vmw_res_cache_entry {
  187. bool valid;
  188. uint32_t handle;
  189. struct vmw_resource *res;
  190. struct vmw_resource_val_node *node;
  191. };
  192. /**
  193. * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
  194. */
  195. enum vmw_dma_map_mode {
  196. vmw_dma_phys, /* Use physical page addresses */
  197. vmw_dma_alloc_coherent, /* Use TTM coherent pages */
  198. vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
  199. vmw_dma_map_bind, /* Unmap from DMA just before unbind */
  200. vmw_dma_map_max
  201. };
  202. /**
  203. * struct vmw_sg_table - Scatter/gather table for binding, with additional
  204. * device-specific information.
  205. *
  206. * @sgt: Pointer to a struct sg_table with binding information
  207. * @num_regions: Number of regions with device-address contigous pages
  208. */
  209. struct vmw_sg_table {
  210. enum vmw_dma_map_mode mode;
  211. struct page **pages;
  212. const dma_addr_t *addrs;
  213. struct sg_table *sgt;
  214. unsigned long num_regions;
  215. unsigned long num_pages;
  216. };
  217. /**
  218. * struct vmw_piter - Page iterator that iterates over a list of pages
  219. * and DMA addresses that could be either a scatter-gather list or
  220. * arrays
  221. *
  222. * @pages: Array of page pointers to the pages.
  223. * @addrs: DMA addresses to the pages if coherent pages are used.
  224. * @iter: Scatter-gather page iterator. Current position in SG list.
  225. * @i: Current position in arrays.
  226. * @num_pages: Number of pages total.
  227. * @next: Function to advance the iterator. Returns false if past the list
  228. * of pages, true otherwise.
  229. * @dma_address: Function to return the DMA address of the current page.
  230. */
  231. struct vmw_piter {
  232. struct page **pages;
  233. const dma_addr_t *addrs;
  234. struct sg_page_iter iter;
  235. unsigned long i;
  236. unsigned long num_pages;
  237. bool (*next)(struct vmw_piter *);
  238. dma_addr_t (*dma_address)(struct vmw_piter *);
  239. struct page *(*page)(struct vmw_piter *);
  240. };
  241. /*
  242. * enum vmw_ctx_binding_type - abstract resource to context binding types
  243. */
  244. enum vmw_ctx_binding_type {
  245. vmw_ctx_binding_shader,
  246. vmw_ctx_binding_rt,
  247. vmw_ctx_binding_tex,
  248. vmw_ctx_binding_max
  249. };
  250. /**
  251. * struct vmw_ctx_bindinfo - structure representing a single context binding
  252. *
  253. * @ctx: Pointer to the context structure. NULL means the binding is not
  254. * active.
  255. * @res: Non ref-counted pointer to the bound resource.
  256. * @bt: The binding type.
  257. * @i1: Union of information needed to unbind.
  258. */
  259. struct vmw_ctx_bindinfo {
  260. struct vmw_resource *ctx;
  261. struct vmw_resource *res;
  262. enum vmw_ctx_binding_type bt;
  263. bool scrubbed;
  264. union {
  265. SVGA3dShaderType shader_type;
  266. SVGA3dRenderTargetType rt_type;
  267. uint32 texture_stage;
  268. } i1;
  269. };
  270. /**
  271. * struct vmw_ctx_binding - structure representing a single context binding
  272. * - suitable for tracking in a context
  273. *
  274. * @ctx_list: List head for context.
  275. * @res_list: List head for bound resource.
  276. * @bi: Binding info
  277. */
  278. struct vmw_ctx_binding {
  279. struct list_head ctx_list;
  280. struct list_head res_list;
  281. struct vmw_ctx_bindinfo bi;
  282. };
  283. /**
  284. * struct vmw_ctx_binding_state - context binding state
  285. *
  286. * @list: linked list of individual bindings.
  287. * @render_targets: Render target bindings.
  288. * @texture_units: Texture units/samplers bindings.
  289. * @shaders: Shader bindings.
  290. *
  291. * Note that this structure also provides storage space for the individual
  292. * struct vmw_ctx_binding objects, so that no dynamic allocation is needed
  293. * for individual bindings.
  294. *
  295. */
  296. struct vmw_ctx_binding_state {
  297. struct list_head list;
  298. struct vmw_ctx_binding render_targets[SVGA3D_RT_MAX];
  299. struct vmw_ctx_binding texture_units[SVGA3D_NUM_TEXTURE_UNITS];
  300. struct vmw_ctx_binding shaders[SVGA3D_SHADERTYPE_MAX];
  301. };
  302. struct vmw_sw_context{
  303. struct drm_open_hash res_ht;
  304. bool res_ht_initialized;
  305. bool kernel; /**< is the called made from the kernel */
  306. struct vmw_fpriv *fp;
  307. struct list_head validate_nodes;
  308. struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
  309. uint32_t cur_reloc;
  310. struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
  311. uint32_t cur_val_buf;
  312. uint32_t *cmd_bounce;
  313. uint32_t cmd_bounce_size;
  314. struct list_head resource_list;
  315. struct ttm_buffer_object *cur_query_bo;
  316. struct list_head res_relocations;
  317. uint32_t *buf_start;
  318. struct vmw_res_cache_entry res_cache[vmw_res_max];
  319. struct vmw_resource *last_query_ctx;
  320. bool needs_post_query_barrier;
  321. struct vmw_resource *error_resource;
  322. struct vmw_ctx_binding_state staged_bindings;
  323. struct list_head staged_cmd_res;
  324. };
  325. struct vmw_legacy_display;
  326. struct vmw_overlay;
  327. struct vmw_master {
  328. struct ttm_lock lock;
  329. struct mutex fb_surf_mutex;
  330. struct list_head fb_surf;
  331. };
  332. struct vmw_vga_topology_state {
  333. uint32_t width;
  334. uint32_t height;
  335. uint32_t primary;
  336. uint32_t pos_x;
  337. uint32_t pos_y;
  338. };
  339. struct vmw_private {
  340. struct ttm_bo_device bdev;
  341. struct ttm_bo_global_ref bo_global_ref;
  342. struct drm_global_reference mem_global_ref;
  343. struct vmw_fifo_state fifo;
  344. struct drm_device *dev;
  345. unsigned long vmw_chipset;
  346. unsigned int io_start;
  347. uint32_t vram_start;
  348. uint32_t vram_size;
  349. uint32_t prim_bb_mem;
  350. uint32_t mmio_start;
  351. uint32_t mmio_size;
  352. uint32_t fb_max_width;
  353. uint32_t fb_max_height;
  354. uint32_t initial_width;
  355. uint32_t initial_height;
  356. __le32 __iomem *mmio_virt;
  357. int mmio_mtrr;
  358. uint32_t capabilities;
  359. uint32_t max_gmr_ids;
  360. uint32_t max_gmr_pages;
  361. uint32_t max_mob_pages;
  362. uint32_t max_mob_size;
  363. uint32_t memory_size;
  364. bool has_gmr;
  365. bool has_mob;
  366. struct mutex hw_mutex;
  367. /*
  368. * VGA registers.
  369. */
  370. struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
  371. uint32_t vga_width;
  372. uint32_t vga_height;
  373. uint32_t vga_bpp;
  374. uint32_t vga_bpl;
  375. uint32_t vga_pitchlock;
  376. uint32_t num_displays;
  377. /*
  378. * Framebuffer info.
  379. */
  380. void *fb_info;
  381. struct vmw_legacy_display *ldu_priv;
  382. struct vmw_screen_object_display *sou_priv;
  383. struct vmw_overlay *overlay_priv;
  384. /*
  385. * Context and surface management.
  386. */
  387. rwlock_t resource_lock;
  388. struct idr res_idr[vmw_res_max];
  389. /*
  390. * Block lastclose from racing with firstopen.
  391. */
  392. struct mutex init_mutex;
  393. /*
  394. * A resource manager for kernel-only surfaces and
  395. * contexts.
  396. */
  397. struct ttm_object_device *tdev;
  398. /*
  399. * Fencing and IRQs.
  400. */
  401. atomic_t marker_seq;
  402. wait_queue_head_t fence_queue;
  403. wait_queue_head_t fifo_queue;
  404. int fence_queue_waiters; /* Protected by hw_mutex */
  405. int goal_queue_waiters; /* Protected by hw_mutex */
  406. atomic_t fifo_queue_waiters;
  407. uint32_t last_read_seqno;
  408. spinlock_t irq_lock;
  409. struct vmw_fence_manager *fman;
  410. uint32_t irq_mask;
  411. /*
  412. * Device state
  413. */
  414. uint32_t traces_state;
  415. uint32_t enable_state;
  416. uint32_t config_done_state;
  417. /**
  418. * Execbuf
  419. */
  420. /**
  421. * Protected by the cmdbuf mutex.
  422. */
  423. struct vmw_sw_context ctx;
  424. struct mutex cmdbuf_mutex;
  425. struct mutex binding_mutex;
  426. /**
  427. * Operating mode.
  428. */
  429. bool stealth;
  430. bool enable_fb;
  431. /**
  432. * Master management.
  433. */
  434. struct vmw_master *active_master;
  435. struct vmw_master fbdev_master;
  436. struct notifier_block pm_nb;
  437. bool suspended;
  438. struct mutex release_mutex;
  439. uint32_t num_3d_resources;
  440. /*
  441. * Replace this with an rwsem as soon as we have down_xx_interruptible()
  442. */
  443. struct ttm_lock reservation_sem;
  444. /*
  445. * Query processing. These members
  446. * are protected by the cmdbuf mutex.
  447. */
  448. struct ttm_buffer_object *dummy_query_bo;
  449. struct ttm_buffer_object *pinned_bo;
  450. uint32_t query_cid;
  451. uint32_t query_cid_valid;
  452. bool dummy_query_bo_pinned;
  453. /*
  454. * Surface swapping. The "surface_lru" list is protected by the
  455. * resource lock in order to be able to destroy a surface and take
  456. * it off the lru atomically. "used_memory_size" is currently
  457. * protected by the cmdbuf mutex for simplicity.
  458. */
  459. struct list_head res_lru[vmw_res_max];
  460. uint32_t used_memory_size;
  461. /*
  462. * DMA mapping stuff.
  463. */
  464. enum vmw_dma_map_mode map_mode;
  465. /*
  466. * Guest Backed stuff
  467. */
  468. struct ttm_buffer_object *otable_bo;
  469. struct vmw_otable *otables;
  470. };
  471. static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
  472. {
  473. return container_of(res, struct vmw_surface, res);
  474. }
  475. static inline struct vmw_private *vmw_priv(struct drm_device *dev)
  476. {
  477. return (struct vmw_private *)dev->dev_private;
  478. }
  479. static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
  480. {
  481. return (struct vmw_fpriv *)file_priv->driver_priv;
  482. }
  483. static inline struct vmw_master *vmw_master(struct drm_master *master)
  484. {
  485. return (struct vmw_master *) master->driver_priv;
  486. }
  487. static inline void vmw_write(struct vmw_private *dev_priv,
  488. unsigned int offset, uint32_t value)
  489. {
  490. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  491. outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
  492. }
  493. static inline uint32_t vmw_read(struct vmw_private *dev_priv,
  494. unsigned int offset)
  495. {
  496. uint32_t val;
  497. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  498. val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
  499. return val;
  500. }
  501. int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
  502. void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
  503. /**
  504. * GMR utilities - vmwgfx_gmr.c
  505. */
  506. extern int vmw_gmr_bind(struct vmw_private *dev_priv,
  507. const struct vmw_sg_table *vsgt,
  508. unsigned long num_pages,
  509. int gmr_id);
  510. extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
  511. /**
  512. * Resource utilities - vmwgfx_resource.c
  513. */
  514. struct vmw_user_resource_conv;
  515. extern void vmw_resource_unreference(struct vmw_resource **p_res);
  516. extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
  517. extern struct vmw_resource *
  518. vmw_resource_reference_unless_doomed(struct vmw_resource *res);
  519. extern int vmw_resource_validate(struct vmw_resource *res);
  520. extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup);
  521. extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
  522. extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
  523. struct ttm_object_file *tfile,
  524. uint32_t handle,
  525. struct vmw_surface **out_surf,
  526. struct vmw_dma_buffer **out_buf);
  527. extern int vmw_user_resource_lookup_handle(
  528. struct vmw_private *dev_priv,
  529. struct ttm_object_file *tfile,
  530. uint32_t handle,
  531. const struct vmw_user_resource_conv *converter,
  532. struct vmw_resource **p_res);
  533. extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
  534. extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
  535. struct vmw_dma_buffer *vmw_bo,
  536. size_t size, struct ttm_placement *placement,
  537. bool interuptable,
  538. void (*bo_free) (struct ttm_buffer_object *bo));
  539. extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
  540. struct ttm_object_file *tfile);
  541. extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
  542. struct ttm_object_file *tfile,
  543. uint32_t size,
  544. bool shareable,
  545. uint32_t *handle,
  546. struct vmw_dma_buffer **p_dma_buf);
  547. extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
  548. struct vmw_dma_buffer *dma_buf,
  549. uint32_t *handle);
  550. extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
  551. struct drm_file *file_priv);
  552. extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
  553. struct drm_file *file_priv);
  554. extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
  555. struct drm_file *file_priv);
  556. extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
  557. uint32_t cur_validate_node);
  558. extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
  559. extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
  560. uint32_t id, struct vmw_dma_buffer **out);
  561. extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  562. struct drm_file *file_priv);
  563. extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  564. struct drm_file *file_priv);
  565. extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  566. struct ttm_object_file *tfile,
  567. uint32_t *inout_id,
  568. struct vmw_resource **out);
  569. extern void vmw_resource_unreserve(struct vmw_resource *res,
  570. struct vmw_dma_buffer *new_backup,
  571. unsigned long new_backup_offset);
  572. extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
  573. struct ttm_mem_reg *mem);
  574. extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
  575. struct vmw_fence_obj *fence);
  576. extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
  577. /**
  578. * DMA buffer helper routines - vmwgfx_dmabuf.c
  579. */
  580. extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
  581. struct vmw_dma_buffer *bo,
  582. struct ttm_placement *placement,
  583. bool interruptible);
  584. extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
  585. struct vmw_dma_buffer *buf,
  586. bool pin, bool interruptible);
  587. extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
  588. struct vmw_dma_buffer *buf,
  589. bool pin, bool interruptible);
  590. extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
  591. struct vmw_dma_buffer *bo,
  592. bool pin, bool interruptible);
  593. extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
  594. struct vmw_dma_buffer *bo,
  595. bool interruptible);
  596. extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
  597. SVGAGuestPtr *ptr);
  598. extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
  599. /**
  600. * Misc Ioctl functionality - vmwgfx_ioctl.c
  601. */
  602. extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  603. struct drm_file *file_priv);
  604. extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
  605. struct drm_file *file_priv);
  606. extern int vmw_present_ioctl(struct drm_device *dev, void *data,
  607. struct drm_file *file_priv);
  608. extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
  609. struct drm_file *file_priv);
  610. extern unsigned int vmw_fops_poll(struct file *filp,
  611. struct poll_table_struct *wait);
  612. extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
  613. size_t count, loff_t *offset);
  614. /**
  615. * Fifo utilities - vmwgfx_fifo.c
  616. */
  617. extern int vmw_fifo_init(struct vmw_private *dev_priv,
  618. struct vmw_fifo_state *fifo);
  619. extern void vmw_fifo_release(struct vmw_private *dev_priv,
  620. struct vmw_fifo_state *fifo);
  621. extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
  622. extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
  623. extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
  624. uint32_t *seqno);
  625. extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
  626. extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
  627. extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
  628. extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
  629. extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
  630. uint32_t cid);
  631. /**
  632. * TTM glue - vmwgfx_ttm_glue.c
  633. */
  634. extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
  635. extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
  636. extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
  637. /**
  638. * TTM buffer object driver - vmwgfx_buffer.c
  639. */
  640. extern const size_t vmw_tt_size;
  641. extern struct ttm_placement vmw_vram_placement;
  642. extern struct ttm_placement vmw_vram_ne_placement;
  643. extern struct ttm_placement vmw_vram_sys_placement;
  644. extern struct ttm_placement vmw_vram_gmr_placement;
  645. extern struct ttm_placement vmw_vram_gmr_ne_placement;
  646. extern struct ttm_placement vmw_sys_placement;
  647. extern struct ttm_placement vmw_sys_ne_placement;
  648. extern struct ttm_placement vmw_evictable_placement;
  649. extern struct ttm_placement vmw_srf_placement;
  650. extern struct ttm_placement vmw_mob_placement;
  651. extern struct ttm_bo_driver vmw_bo_driver;
  652. extern int vmw_dma_quiescent(struct drm_device *dev);
  653. extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
  654. extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
  655. extern const struct vmw_sg_table *
  656. vmw_bo_sg_table(struct ttm_buffer_object *bo);
  657. extern void vmw_piter_start(struct vmw_piter *viter,
  658. const struct vmw_sg_table *vsgt,
  659. unsigned long p_offs);
  660. /**
  661. * vmw_piter_next - Advance the iterator one page.
  662. *
  663. * @viter: Pointer to the iterator to advance.
  664. *
  665. * Returns false if past the list of pages, true otherwise.
  666. */
  667. static inline bool vmw_piter_next(struct vmw_piter *viter)
  668. {
  669. return viter->next(viter);
  670. }
  671. /**
  672. * vmw_piter_dma_addr - Return the DMA address of the current page.
  673. *
  674. * @viter: Pointer to the iterator
  675. *
  676. * Returns the DMA address of the page pointed to by @viter.
  677. */
  678. static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
  679. {
  680. return viter->dma_address(viter);
  681. }
  682. /**
  683. * vmw_piter_page - Return a pointer to the current page.
  684. *
  685. * @viter: Pointer to the iterator
  686. *
  687. * Returns the DMA address of the page pointed to by @viter.
  688. */
  689. static inline struct page *vmw_piter_page(struct vmw_piter *viter)
  690. {
  691. return viter->page(viter);
  692. }
  693. /**
  694. * Command submission - vmwgfx_execbuf.c
  695. */
  696. extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
  697. struct drm_file *file_priv);
  698. extern int vmw_execbuf_process(struct drm_file *file_priv,
  699. struct vmw_private *dev_priv,
  700. void __user *user_commands,
  701. void *kernel_commands,
  702. uint32_t command_size,
  703. uint64_t throttle_us,
  704. struct drm_vmw_fence_rep __user
  705. *user_fence_rep,
  706. struct vmw_fence_obj **out_fence);
  707. extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
  708. struct vmw_fence_obj *fence);
  709. extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
  710. extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
  711. struct vmw_private *dev_priv,
  712. struct vmw_fence_obj **p_fence,
  713. uint32_t *p_handle);
  714. extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
  715. struct vmw_fpriv *vmw_fp,
  716. int ret,
  717. struct drm_vmw_fence_rep __user
  718. *user_fence_rep,
  719. struct vmw_fence_obj *fence,
  720. uint32_t fence_handle);
  721. /**
  722. * IRQs and wating - vmwgfx_irq.c
  723. */
  724. extern irqreturn_t vmw_irq_handler(int irq, void *arg);
  725. extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
  726. uint32_t seqno, bool interruptible,
  727. unsigned long timeout);
  728. extern void vmw_irq_preinstall(struct drm_device *dev);
  729. extern int vmw_irq_postinstall(struct drm_device *dev);
  730. extern void vmw_irq_uninstall(struct drm_device *dev);
  731. extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
  732. uint32_t seqno);
  733. extern int vmw_fallback_wait(struct vmw_private *dev_priv,
  734. bool lazy,
  735. bool fifo_idle,
  736. uint32_t seqno,
  737. bool interruptible,
  738. unsigned long timeout);
  739. extern void vmw_update_seqno(struct vmw_private *dev_priv,
  740. struct vmw_fifo_state *fifo_state);
  741. extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
  742. extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
  743. extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
  744. extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
  745. /**
  746. * Rudimentary fence-like objects currently used only for throttling -
  747. * vmwgfx_marker.c
  748. */
  749. extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
  750. extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
  751. extern int vmw_marker_push(struct vmw_marker_queue *queue,
  752. uint32_t seqno);
  753. extern int vmw_marker_pull(struct vmw_marker_queue *queue,
  754. uint32_t signaled_seqno);
  755. extern int vmw_wait_lag(struct vmw_private *dev_priv,
  756. struct vmw_marker_queue *queue, uint32_t us);
  757. /**
  758. * Kernel framebuffer - vmwgfx_fb.c
  759. */
  760. int vmw_fb_init(struct vmw_private *vmw_priv);
  761. int vmw_fb_close(struct vmw_private *dev_priv);
  762. int vmw_fb_off(struct vmw_private *vmw_priv);
  763. int vmw_fb_on(struct vmw_private *vmw_priv);
  764. /**
  765. * Kernel modesetting - vmwgfx_kms.c
  766. */
  767. int vmw_kms_init(struct vmw_private *dev_priv);
  768. int vmw_kms_close(struct vmw_private *dev_priv);
  769. int vmw_kms_save_vga(struct vmw_private *vmw_priv);
  770. int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
  771. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  772. struct drm_file *file_priv);
  773. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
  774. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  775. struct ttm_object_file *tfile,
  776. struct ttm_buffer_object *bo,
  777. SVGA3dCmdHeader *header);
  778. int vmw_kms_write_svga(struct vmw_private *vmw_priv,
  779. unsigned width, unsigned height, unsigned pitch,
  780. unsigned bpp, unsigned depth);
  781. void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
  782. bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
  783. uint32_t pitch,
  784. uint32_t height);
  785. u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
  786. int vmw_enable_vblank(struct drm_device *dev, int crtc);
  787. void vmw_disable_vblank(struct drm_device *dev, int crtc);
  788. int vmw_kms_present(struct vmw_private *dev_priv,
  789. struct drm_file *file_priv,
  790. struct vmw_framebuffer *vfb,
  791. struct vmw_surface *surface,
  792. uint32_t sid, int32_t destX, int32_t destY,
  793. struct drm_vmw_rect *clips,
  794. uint32_t num_clips);
  795. int vmw_kms_readback(struct vmw_private *dev_priv,
  796. struct drm_file *file_priv,
  797. struct vmw_framebuffer *vfb,
  798. struct drm_vmw_fence_rep __user *user_fence_rep,
  799. struct drm_vmw_rect *clips,
  800. uint32_t num_clips);
  801. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  802. struct drm_file *file_priv);
  803. int vmw_dumb_create(struct drm_file *file_priv,
  804. struct drm_device *dev,
  805. struct drm_mode_create_dumb *args);
  806. int vmw_dumb_map_offset(struct drm_file *file_priv,
  807. struct drm_device *dev, uint32_t handle,
  808. uint64_t *offset);
  809. int vmw_dumb_destroy(struct drm_file *file_priv,
  810. struct drm_device *dev,
  811. uint32_t handle);
  812. /**
  813. * Overlay control - vmwgfx_overlay.c
  814. */
  815. int vmw_overlay_init(struct vmw_private *dev_priv);
  816. int vmw_overlay_close(struct vmw_private *dev_priv);
  817. int vmw_overlay_ioctl(struct drm_device *dev, void *data,
  818. struct drm_file *file_priv);
  819. int vmw_overlay_stop_all(struct vmw_private *dev_priv);
  820. int vmw_overlay_resume_all(struct vmw_private *dev_priv);
  821. int vmw_overlay_pause_all(struct vmw_private *dev_priv);
  822. int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
  823. int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
  824. int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
  825. int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  826. /**
  827. * GMR Id manager
  828. */
  829. extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
  830. /**
  831. * Prime - vmwgfx_prime.c
  832. */
  833. extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
  834. extern int vmw_prime_fd_to_handle(struct drm_device *dev,
  835. struct drm_file *file_priv,
  836. int fd, u32 *handle);
  837. extern int vmw_prime_handle_to_fd(struct drm_device *dev,
  838. struct drm_file *file_priv,
  839. uint32_t handle, uint32_t flags,
  840. int *prime_fd);
  841. /*
  842. * MemoryOBject management - vmwgfx_mob.c
  843. */
  844. struct vmw_mob;
  845. extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
  846. const struct vmw_sg_table *vsgt,
  847. unsigned long num_data_pages, int32_t mob_id);
  848. extern void vmw_mob_unbind(struct vmw_private *dev_priv,
  849. struct vmw_mob *mob);
  850. extern void vmw_mob_destroy(struct vmw_mob *mob);
  851. extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
  852. extern int vmw_otables_setup(struct vmw_private *dev_priv);
  853. extern void vmw_otables_takedown(struct vmw_private *dev_priv);
  854. /*
  855. * Context management - vmwgfx_context.c
  856. */
  857. extern const struct vmw_user_resource_conv *user_context_converter;
  858. extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
  859. extern int vmw_context_check(struct vmw_private *dev_priv,
  860. struct ttm_object_file *tfile,
  861. int id,
  862. struct vmw_resource **p_res);
  863. extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
  864. struct drm_file *file_priv);
  865. extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
  866. struct drm_file *file_priv);
  867. extern int vmw_context_binding_add(struct vmw_ctx_binding_state *cbs,
  868. const struct vmw_ctx_bindinfo *ci);
  869. extern void
  870. vmw_context_binding_state_transfer(struct vmw_resource *res,
  871. struct vmw_ctx_binding_state *cbs);
  872. extern void vmw_context_binding_res_list_kill(struct list_head *head);
  873. extern void vmw_context_binding_res_list_scrub(struct list_head *head);
  874. extern int vmw_context_rebind_all(struct vmw_resource *ctx);
  875. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  876. extern struct vmw_cmdbuf_res_manager *
  877. vmw_context_res_man(struct vmw_resource *ctx);
  878. /*
  879. * Surface management - vmwgfx_surface.c
  880. */
  881. extern const struct vmw_user_resource_conv *user_surface_converter;
  882. extern void vmw_surface_res_free(struct vmw_resource *res);
  883. extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
  884. struct drm_file *file_priv);
  885. extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
  886. struct drm_file *file_priv);
  887. extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
  888. struct drm_file *file_priv);
  889. extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
  890. struct drm_file *file_priv);
  891. extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
  892. struct drm_file *file_priv);
  893. extern int vmw_surface_check(struct vmw_private *dev_priv,
  894. struct ttm_object_file *tfile,
  895. uint32_t handle, int *id);
  896. extern int vmw_surface_validate(struct vmw_private *dev_priv,
  897. struct vmw_surface *srf);
  898. /*
  899. * Shader management - vmwgfx_shader.c
  900. */
  901. extern const struct vmw_user_resource_conv *user_shader_converter;
  902. extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
  903. struct drm_file *file_priv);
  904. extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
  905. struct drm_file *file_priv);
  906. extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
  907. struct vmw_cmdbuf_res_manager *man,
  908. u32 user_key, const void *bytecode,
  909. SVGA3dShaderType shader_type,
  910. size_t size,
  911. struct list_head *list);
  912. extern int vmw_compat_shader_remove(struct vmw_cmdbuf_res_manager *man,
  913. u32 user_key, SVGA3dShaderType shader_type,
  914. struct list_head *list);
  915. extern struct vmw_resource *
  916. vmw_compat_shader_lookup(struct vmw_cmdbuf_res_manager *man,
  917. u32 user_key, SVGA3dShaderType shader_type);
  918. /*
  919. * Command buffer managed resources - vmwgfx_cmdbuf_res.c
  920. */
  921. extern struct vmw_cmdbuf_res_manager *
  922. vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
  923. extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
  924. extern size_t vmw_cmdbuf_res_man_size(void);
  925. extern struct vmw_resource *
  926. vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
  927. enum vmw_cmdbuf_res_type res_type,
  928. u32 user_key);
  929. extern void vmw_cmdbuf_res_revert(struct list_head *list);
  930. extern void vmw_cmdbuf_res_commit(struct list_head *list);
  931. extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
  932. enum vmw_cmdbuf_res_type res_type,
  933. u32 user_key,
  934. struct vmw_resource *res,
  935. struct list_head *list);
  936. extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
  937. enum vmw_cmdbuf_res_type res_type,
  938. u32 user_key,
  939. struct list_head *list);
  940. /**
  941. * Inline helper functions
  942. */
  943. static inline void vmw_surface_unreference(struct vmw_surface **srf)
  944. {
  945. struct vmw_surface *tmp_srf = *srf;
  946. struct vmw_resource *res = &tmp_srf->res;
  947. *srf = NULL;
  948. vmw_resource_unreference(&res);
  949. }
  950. static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
  951. {
  952. (void) vmw_resource_reference(&srf->res);
  953. return srf;
  954. }
  955. static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
  956. {
  957. struct vmw_dma_buffer *tmp_buf = *buf;
  958. *buf = NULL;
  959. if (tmp_buf != NULL) {
  960. struct ttm_buffer_object *bo = &tmp_buf->base;
  961. ttm_bo_unref(&bo);
  962. }
  963. }
  964. static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
  965. {
  966. if (ttm_bo_reference(&buf->base))
  967. return buf;
  968. return NULL;
  969. }
  970. static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
  971. {
  972. return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
  973. }
  974. #endif