vmwgfx_drv.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  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. spinlock_t hw_lock;
  367. spinlock_t cap_lock;
  368. /*
  369. * VGA registers.
  370. */
  371. struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
  372. uint32_t vga_width;
  373. uint32_t vga_height;
  374. uint32_t vga_bpp;
  375. uint32_t vga_bpl;
  376. uint32_t vga_pitchlock;
  377. uint32_t num_displays;
  378. /*
  379. * Framebuffer info.
  380. */
  381. void *fb_info;
  382. struct vmw_legacy_display *ldu_priv;
  383. struct vmw_screen_object_display *sou_priv;
  384. struct vmw_overlay *overlay_priv;
  385. /*
  386. * Context and surface management.
  387. */
  388. rwlock_t resource_lock;
  389. struct idr res_idr[vmw_res_max];
  390. /*
  391. * Block lastclose from racing with firstopen.
  392. */
  393. struct mutex init_mutex;
  394. /*
  395. * A resource manager for kernel-only surfaces and
  396. * contexts.
  397. */
  398. struct ttm_object_device *tdev;
  399. /*
  400. * Fencing and IRQs.
  401. */
  402. atomic_t marker_seq;
  403. wait_queue_head_t fence_queue;
  404. wait_queue_head_t fifo_queue;
  405. spinlock_t waiter_lock;
  406. int fence_queue_waiters; /* Protected by waiter_lock */
  407. int goal_queue_waiters; /* Protected by waiter_lock */
  408. atomic_t fifo_queue_waiters;
  409. uint32_t last_read_seqno;
  410. spinlock_t irq_lock;
  411. struct vmw_fence_manager *fman;
  412. uint32_t irq_mask;
  413. /*
  414. * Device state
  415. */
  416. uint32_t traces_state;
  417. uint32_t enable_state;
  418. uint32_t config_done_state;
  419. /**
  420. * Execbuf
  421. */
  422. /**
  423. * Protected by the cmdbuf mutex.
  424. */
  425. struct vmw_sw_context ctx;
  426. struct mutex cmdbuf_mutex;
  427. struct mutex binding_mutex;
  428. /**
  429. * Operating mode.
  430. */
  431. bool stealth;
  432. bool enable_fb;
  433. /**
  434. * Master management.
  435. */
  436. struct vmw_master *active_master;
  437. struct vmw_master fbdev_master;
  438. struct notifier_block pm_nb;
  439. bool suspended;
  440. struct mutex release_mutex;
  441. uint32_t num_3d_resources;
  442. /*
  443. * Replace this with an rwsem as soon as we have down_xx_interruptible()
  444. */
  445. struct ttm_lock reservation_sem;
  446. /*
  447. * Query processing. These members
  448. * are protected by the cmdbuf mutex.
  449. */
  450. struct ttm_buffer_object *dummy_query_bo;
  451. struct ttm_buffer_object *pinned_bo;
  452. uint32_t query_cid;
  453. uint32_t query_cid_valid;
  454. bool dummy_query_bo_pinned;
  455. /*
  456. * Surface swapping. The "surface_lru" list is protected by the
  457. * resource lock in order to be able to destroy a surface and take
  458. * it off the lru atomically. "used_memory_size" is currently
  459. * protected by the cmdbuf mutex for simplicity.
  460. */
  461. struct list_head res_lru[vmw_res_max];
  462. uint32_t used_memory_size;
  463. /*
  464. * DMA mapping stuff.
  465. */
  466. enum vmw_dma_map_mode map_mode;
  467. /*
  468. * Guest Backed stuff
  469. */
  470. struct ttm_buffer_object *otable_bo;
  471. struct vmw_otable *otables;
  472. };
  473. static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
  474. {
  475. return container_of(res, struct vmw_surface, res);
  476. }
  477. static inline struct vmw_private *vmw_priv(struct drm_device *dev)
  478. {
  479. return (struct vmw_private *)dev->dev_private;
  480. }
  481. static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
  482. {
  483. return (struct vmw_fpriv *)file_priv->driver_priv;
  484. }
  485. static inline struct vmw_master *vmw_master(struct drm_master *master)
  486. {
  487. return (struct vmw_master *) master->driver_priv;
  488. }
  489. /*
  490. * The locking here is fine-grained, so that it is performed once
  491. * for every read- and write operation. This is of course costly, but we
  492. * don't perform much register access in the timing critical paths anyway.
  493. * Instead we have the extra benefit of being sure that we don't forget
  494. * the hw lock around register accesses.
  495. */
  496. static inline void vmw_write(struct vmw_private *dev_priv,
  497. unsigned int offset, uint32_t value)
  498. {
  499. unsigned long irq_flags;
  500. spin_lock_irqsave(&dev_priv->hw_lock, irq_flags);
  501. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  502. outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
  503. spin_unlock_irqrestore(&dev_priv->hw_lock, irq_flags);
  504. }
  505. static inline uint32_t vmw_read(struct vmw_private *dev_priv,
  506. unsigned int offset)
  507. {
  508. unsigned long irq_flags;
  509. u32 val;
  510. spin_lock_irqsave(&dev_priv->hw_lock, irq_flags);
  511. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  512. val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
  513. spin_unlock_irqrestore(&dev_priv->hw_lock, irq_flags);
  514. return val;
  515. }
  516. int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
  517. void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
  518. /**
  519. * GMR utilities - vmwgfx_gmr.c
  520. */
  521. extern int vmw_gmr_bind(struct vmw_private *dev_priv,
  522. const struct vmw_sg_table *vsgt,
  523. unsigned long num_pages,
  524. int gmr_id);
  525. extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
  526. /**
  527. * Resource utilities - vmwgfx_resource.c
  528. */
  529. struct vmw_user_resource_conv;
  530. extern void vmw_resource_unreference(struct vmw_resource **p_res);
  531. extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
  532. extern struct vmw_resource *
  533. vmw_resource_reference_unless_doomed(struct vmw_resource *res);
  534. extern int vmw_resource_validate(struct vmw_resource *res);
  535. extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup);
  536. extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
  537. extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
  538. struct ttm_object_file *tfile,
  539. uint32_t handle,
  540. struct vmw_surface **out_surf,
  541. struct vmw_dma_buffer **out_buf);
  542. extern int vmw_user_resource_lookup_handle(
  543. struct vmw_private *dev_priv,
  544. struct ttm_object_file *tfile,
  545. uint32_t handle,
  546. const struct vmw_user_resource_conv *converter,
  547. struct vmw_resource **p_res);
  548. extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
  549. extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
  550. struct vmw_dma_buffer *vmw_bo,
  551. size_t size, struct ttm_placement *placement,
  552. bool interuptable,
  553. void (*bo_free) (struct ttm_buffer_object *bo));
  554. extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
  555. struct ttm_object_file *tfile);
  556. extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
  557. struct ttm_object_file *tfile,
  558. uint32_t size,
  559. bool shareable,
  560. uint32_t *handle,
  561. struct vmw_dma_buffer **p_dma_buf);
  562. extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
  563. struct vmw_dma_buffer *dma_buf,
  564. uint32_t *handle);
  565. extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
  566. struct drm_file *file_priv);
  567. extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
  568. struct drm_file *file_priv);
  569. extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
  570. struct drm_file *file_priv);
  571. extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
  572. uint32_t cur_validate_node);
  573. extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
  574. extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
  575. uint32_t id, struct vmw_dma_buffer **out);
  576. extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  577. struct drm_file *file_priv);
  578. extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  579. struct drm_file *file_priv);
  580. extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  581. struct ttm_object_file *tfile,
  582. uint32_t *inout_id,
  583. struct vmw_resource **out);
  584. extern void vmw_resource_unreserve(struct vmw_resource *res,
  585. struct vmw_dma_buffer *new_backup,
  586. unsigned long new_backup_offset);
  587. extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
  588. struct ttm_mem_reg *mem);
  589. extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
  590. struct vmw_fence_obj *fence);
  591. extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
  592. /**
  593. * DMA buffer helper routines - vmwgfx_dmabuf.c
  594. */
  595. extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
  596. struct vmw_dma_buffer *bo,
  597. struct ttm_placement *placement,
  598. bool interruptible);
  599. extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
  600. struct vmw_dma_buffer *buf,
  601. bool pin, bool interruptible);
  602. extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
  603. struct vmw_dma_buffer *buf,
  604. bool pin, bool interruptible);
  605. extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
  606. struct vmw_dma_buffer *bo,
  607. bool pin, bool interruptible);
  608. extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
  609. struct vmw_dma_buffer *bo,
  610. bool interruptible);
  611. extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
  612. SVGAGuestPtr *ptr);
  613. extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
  614. /**
  615. * Misc Ioctl functionality - vmwgfx_ioctl.c
  616. */
  617. extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  618. struct drm_file *file_priv);
  619. extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
  620. struct drm_file *file_priv);
  621. extern int vmw_present_ioctl(struct drm_device *dev, void *data,
  622. struct drm_file *file_priv);
  623. extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
  624. struct drm_file *file_priv);
  625. extern unsigned int vmw_fops_poll(struct file *filp,
  626. struct poll_table_struct *wait);
  627. extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
  628. size_t count, loff_t *offset);
  629. /**
  630. * Fifo utilities - vmwgfx_fifo.c
  631. */
  632. extern int vmw_fifo_init(struct vmw_private *dev_priv,
  633. struct vmw_fifo_state *fifo);
  634. extern void vmw_fifo_release(struct vmw_private *dev_priv,
  635. struct vmw_fifo_state *fifo);
  636. extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
  637. extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
  638. extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
  639. uint32_t *seqno);
  640. extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
  641. extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
  642. extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
  643. extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
  644. extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
  645. uint32_t cid);
  646. /**
  647. * TTM glue - vmwgfx_ttm_glue.c
  648. */
  649. extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
  650. extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
  651. extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
  652. /**
  653. * TTM buffer object driver - vmwgfx_buffer.c
  654. */
  655. extern const size_t vmw_tt_size;
  656. extern struct ttm_placement vmw_vram_placement;
  657. extern struct ttm_placement vmw_vram_ne_placement;
  658. extern struct ttm_placement vmw_vram_sys_placement;
  659. extern struct ttm_placement vmw_vram_gmr_placement;
  660. extern struct ttm_placement vmw_vram_gmr_ne_placement;
  661. extern struct ttm_placement vmw_sys_placement;
  662. extern struct ttm_placement vmw_sys_ne_placement;
  663. extern struct ttm_placement vmw_evictable_placement;
  664. extern struct ttm_placement vmw_srf_placement;
  665. extern struct ttm_placement vmw_mob_placement;
  666. extern struct ttm_bo_driver vmw_bo_driver;
  667. extern int vmw_dma_quiescent(struct drm_device *dev);
  668. extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
  669. extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
  670. extern const struct vmw_sg_table *
  671. vmw_bo_sg_table(struct ttm_buffer_object *bo);
  672. extern void vmw_piter_start(struct vmw_piter *viter,
  673. const struct vmw_sg_table *vsgt,
  674. unsigned long p_offs);
  675. /**
  676. * vmw_piter_next - Advance the iterator one page.
  677. *
  678. * @viter: Pointer to the iterator to advance.
  679. *
  680. * Returns false if past the list of pages, true otherwise.
  681. */
  682. static inline bool vmw_piter_next(struct vmw_piter *viter)
  683. {
  684. return viter->next(viter);
  685. }
  686. /**
  687. * vmw_piter_dma_addr - Return the DMA address of the current page.
  688. *
  689. * @viter: Pointer to the iterator
  690. *
  691. * Returns the DMA address of the page pointed to by @viter.
  692. */
  693. static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
  694. {
  695. return viter->dma_address(viter);
  696. }
  697. /**
  698. * vmw_piter_page - Return a pointer to the current page.
  699. *
  700. * @viter: Pointer to the iterator
  701. *
  702. * Returns the DMA address of the page pointed to by @viter.
  703. */
  704. static inline struct page *vmw_piter_page(struct vmw_piter *viter)
  705. {
  706. return viter->page(viter);
  707. }
  708. /**
  709. * Command submission - vmwgfx_execbuf.c
  710. */
  711. extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
  712. struct drm_file *file_priv);
  713. extern int vmw_execbuf_process(struct drm_file *file_priv,
  714. struct vmw_private *dev_priv,
  715. void __user *user_commands,
  716. void *kernel_commands,
  717. uint32_t command_size,
  718. uint64_t throttle_us,
  719. struct drm_vmw_fence_rep __user
  720. *user_fence_rep,
  721. struct vmw_fence_obj **out_fence);
  722. extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
  723. struct vmw_fence_obj *fence);
  724. extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
  725. extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
  726. struct vmw_private *dev_priv,
  727. struct vmw_fence_obj **p_fence,
  728. uint32_t *p_handle);
  729. extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
  730. struct vmw_fpriv *vmw_fp,
  731. int ret,
  732. struct drm_vmw_fence_rep __user
  733. *user_fence_rep,
  734. struct vmw_fence_obj *fence,
  735. uint32_t fence_handle);
  736. /**
  737. * IRQs and wating - vmwgfx_irq.c
  738. */
  739. extern irqreturn_t vmw_irq_handler(int irq, void *arg);
  740. extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
  741. uint32_t seqno, bool interruptible,
  742. unsigned long timeout);
  743. extern void vmw_irq_preinstall(struct drm_device *dev);
  744. extern int vmw_irq_postinstall(struct drm_device *dev);
  745. extern void vmw_irq_uninstall(struct drm_device *dev);
  746. extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
  747. uint32_t seqno);
  748. extern int vmw_fallback_wait(struct vmw_private *dev_priv,
  749. bool lazy,
  750. bool fifo_idle,
  751. uint32_t seqno,
  752. bool interruptible,
  753. unsigned long timeout);
  754. extern void vmw_update_seqno(struct vmw_private *dev_priv,
  755. struct vmw_fifo_state *fifo_state);
  756. extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
  757. extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
  758. extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
  759. extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
  760. /**
  761. * Rudimentary fence-like objects currently used only for throttling -
  762. * vmwgfx_marker.c
  763. */
  764. extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
  765. extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
  766. extern int vmw_marker_push(struct vmw_marker_queue *queue,
  767. uint32_t seqno);
  768. extern int vmw_marker_pull(struct vmw_marker_queue *queue,
  769. uint32_t signaled_seqno);
  770. extern int vmw_wait_lag(struct vmw_private *dev_priv,
  771. struct vmw_marker_queue *queue, uint32_t us);
  772. /**
  773. * Kernel framebuffer - vmwgfx_fb.c
  774. */
  775. int vmw_fb_init(struct vmw_private *vmw_priv);
  776. int vmw_fb_close(struct vmw_private *dev_priv);
  777. int vmw_fb_off(struct vmw_private *vmw_priv);
  778. int vmw_fb_on(struct vmw_private *vmw_priv);
  779. /**
  780. * Kernel modesetting - vmwgfx_kms.c
  781. */
  782. int vmw_kms_init(struct vmw_private *dev_priv);
  783. int vmw_kms_close(struct vmw_private *dev_priv);
  784. int vmw_kms_save_vga(struct vmw_private *vmw_priv);
  785. int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
  786. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  787. struct drm_file *file_priv);
  788. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
  789. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  790. struct ttm_object_file *tfile,
  791. struct ttm_buffer_object *bo,
  792. SVGA3dCmdHeader *header);
  793. int vmw_kms_write_svga(struct vmw_private *vmw_priv,
  794. unsigned width, unsigned height, unsigned pitch,
  795. unsigned bpp, unsigned depth);
  796. void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
  797. bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
  798. uint32_t pitch,
  799. uint32_t height);
  800. u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
  801. int vmw_enable_vblank(struct drm_device *dev, int crtc);
  802. void vmw_disable_vblank(struct drm_device *dev, int crtc);
  803. int vmw_kms_present(struct vmw_private *dev_priv,
  804. struct drm_file *file_priv,
  805. struct vmw_framebuffer *vfb,
  806. struct vmw_surface *surface,
  807. uint32_t sid, int32_t destX, int32_t destY,
  808. struct drm_vmw_rect *clips,
  809. uint32_t num_clips);
  810. int vmw_kms_readback(struct vmw_private *dev_priv,
  811. struct drm_file *file_priv,
  812. struct vmw_framebuffer *vfb,
  813. struct drm_vmw_fence_rep __user *user_fence_rep,
  814. struct drm_vmw_rect *clips,
  815. uint32_t num_clips);
  816. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  817. struct drm_file *file_priv);
  818. int vmw_dumb_create(struct drm_file *file_priv,
  819. struct drm_device *dev,
  820. struct drm_mode_create_dumb *args);
  821. int vmw_dumb_map_offset(struct drm_file *file_priv,
  822. struct drm_device *dev, uint32_t handle,
  823. uint64_t *offset);
  824. int vmw_dumb_destroy(struct drm_file *file_priv,
  825. struct drm_device *dev,
  826. uint32_t handle);
  827. /**
  828. * Overlay control - vmwgfx_overlay.c
  829. */
  830. int vmw_overlay_init(struct vmw_private *dev_priv);
  831. int vmw_overlay_close(struct vmw_private *dev_priv);
  832. int vmw_overlay_ioctl(struct drm_device *dev, void *data,
  833. struct drm_file *file_priv);
  834. int vmw_overlay_stop_all(struct vmw_private *dev_priv);
  835. int vmw_overlay_resume_all(struct vmw_private *dev_priv);
  836. int vmw_overlay_pause_all(struct vmw_private *dev_priv);
  837. int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
  838. int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
  839. int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
  840. int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  841. /**
  842. * GMR Id manager
  843. */
  844. extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
  845. /**
  846. * Prime - vmwgfx_prime.c
  847. */
  848. extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
  849. extern int vmw_prime_fd_to_handle(struct drm_device *dev,
  850. struct drm_file *file_priv,
  851. int fd, u32 *handle);
  852. extern int vmw_prime_handle_to_fd(struct drm_device *dev,
  853. struct drm_file *file_priv,
  854. uint32_t handle, uint32_t flags,
  855. int *prime_fd);
  856. /*
  857. * MemoryOBject management - vmwgfx_mob.c
  858. */
  859. struct vmw_mob;
  860. extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
  861. const struct vmw_sg_table *vsgt,
  862. unsigned long num_data_pages, int32_t mob_id);
  863. extern void vmw_mob_unbind(struct vmw_private *dev_priv,
  864. struct vmw_mob *mob);
  865. extern void vmw_mob_destroy(struct vmw_mob *mob);
  866. extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
  867. extern int vmw_otables_setup(struct vmw_private *dev_priv);
  868. extern void vmw_otables_takedown(struct vmw_private *dev_priv);
  869. /*
  870. * Context management - vmwgfx_context.c
  871. */
  872. extern const struct vmw_user_resource_conv *user_context_converter;
  873. extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
  874. extern int vmw_context_check(struct vmw_private *dev_priv,
  875. struct ttm_object_file *tfile,
  876. int id,
  877. struct vmw_resource **p_res);
  878. extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
  879. struct drm_file *file_priv);
  880. extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
  881. struct drm_file *file_priv);
  882. extern int vmw_context_binding_add(struct vmw_ctx_binding_state *cbs,
  883. const struct vmw_ctx_bindinfo *ci);
  884. extern void
  885. vmw_context_binding_state_transfer(struct vmw_resource *res,
  886. struct vmw_ctx_binding_state *cbs);
  887. extern void vmw_context_binding_res_list_kill(struct list_head *head);
  888. extern void vmw_context_binding_res_list_scrub(struct list_head *head);
  889. extern int vmw_context_rebind_all(struct vmw_resource *ctx);
  890. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  891. extern struct vmw_cmdbuf_res_manager *
  892. vmw_context_res_man(struct vmw_resource *ctx);
  893. /*
  894. * Surface management - vmwgfx_surface.c
  895. */
  896. extern const struct vmw_user_resource_conv *user_surface_converter;
  897. extern void vmw_surface_res_free(struct vmw_resource *res);
  898. extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
  899. struct drm_file *file_priv);
  900. extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
  901. struct drm_file *file_priv);
  902. extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
  903. struct drm_file *file_priv);
  904. extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
  905. struct drm_file *file_priv);
  906. extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
  907. struct drm_file *file_priv);
  908. extern int vmw_surface_check(struct vmw_private *dev_priv,
  909. struct ttm_object_file *tfile,
  910. uint32_t handle, int *id);
  911. extern int vmw_surface_validate(struct vmw_private *dev_priv,
  912. struct vmw_surface *srf);
  913. /*
  914. * Shader management - vmwgfx_shader.c
  915. */
  916. extern const struct vmw_user_resource_conv *user_shader_converter;
  917. extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
  918. struct drm_file *file_priv);
  919. extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
  920. struct drm_file *file_priv);
  921. extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
  922. struct vmw_cmdbuf_res_manager *man,
  923. u32 user_key, const void *bytecode,
  924. SVGA3dShaderType shader_type,
  925. size_t size,
  926. struct list_head *list);
  927. extern int vmw_compat_shader_remove(struct vmw_cmdbuf_res_manager *man,
  928. u32 user_key, SVGA3dShaderType shader_type,
  929. struct list_head *list);
  930. extern struct vmw_resource *
  931. vmw_compat_shader_lookup(struct vmw_cmdbuf_res_manager *man,
  932. u32 user_key, SVGA3dShaderType shader_type);
  933. /*
  934. * Command buffer managed resources - vmwgfx_cmdbuf_res.c
  935. */
  936. extern struct vmw_cmdbuf_res_manager *
  937. vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
  938. extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
  939. extern size_t vmw_cmdbuf_res_man_size(void);
  940. extern struct vmw_resource *
  941. vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
  942. enum vmw_cmdbuf_res_type res_type,
  943. u32 user_key);
  944. extern void vmw_cmdbuf_res_revert(struct list_head *list);
  945. extern void vmw_cmdbuf_res_commit(struct list_head *list);
  946. extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
  947. enum vmw_cmdbuf_res_type res_type,
  948. u32 user_key,
  949. struct vmw_resource *res,
  950. struct list_head *list);
  951. extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
  952. enum vmw_cmdbuf_res_type res_type,
  953. u32 user_key,
  954. struct list_head *list);
  955. /**
  956. * Inline helper functions
  957. */
  958. static inline void vmw_surface_unreference(struct vmw_surface **srf)
  959. {
  960. struct vmw_surface *tmp_srf = *srf;
  961. struct vmw_resource *res = &tmp_srf->res;
  962. *srf = NULL;
  963. vmw_resource_unreference(&res);
  964. }
  965. static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
  966. {
  967. (void) vmw_resource_reference(&srf->res);
  968. return srf;
  969. }
  970. static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
  971. {
  972. struct vmw_dma_buffer *tmp_buf = *buf;
  973. *buf = NULL;
  974. if (tmp_buf != NULL) {
  975. struct ttm_buffer_object *bo = &tmp_buf->base;
  976. ttm_bo_unref(&bo);
  977. }
  978. }
  979. static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
  980. {
  981. if (ttm_bo_reference(&buf->base))
  982. return buf;
  983. return NULL;
  984. }
  985. static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
  986. {
  987. return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
  988. }
  989. #endif