vmwgfx_drv.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #ifndef _VMWGFX_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 <drm/drm_auth.h>
  34. #include <linux/suspend.h>
  35. #include <drm/ttm/ttm_bo_driver.h>
  36. #include <drm/ttm/ttm_object.h>
  37. #include <drm/ttm/ttm_lock.h>
  38. #include <drm/ttm/ttm_execbuf_util.h>
  39. #include <drm/ttm/ttm_module.h>
  40. #include "vmwgfx_fence.h"
  41. #include <linux/sync_file.h>
  42. #define VMWGFX_DRIVER_NAME "vmwgfx"
  43. #define VMWGFX_DRIVER_DATE "20170612"
  44. #define VMWGFX_DRIVER_MAJOR 2
  45. #define VMWGFX_DRIVER_MINOR 14
  46. #define VMWGFX_DRIVER_PATCHLEVEL 0
  47. #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
  48. #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
  49. #define VMWGFX_MAX_RELOCATIONS 2048
  50. #define VMWGFX_MAX_VALIDATIONS 2048
  51. #define VMWGFX_MAX_DISPLAYS 16
  52. #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
  53. #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
  54. /*
  55. * Perhaps we should have sysfs entries for these.
  56. */
  57. #define VMWGFX_NUM_GB_CONTEXT 256
  58. #define VMWGFX_NUM_GB_SHADER 20000
  59. #define VMWGFX_NUM_GB_SURFACE 32768
  60. #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
  61. #define VMWGFX_NUM_DXCONTEXT 256
  62. #define VMWGFX_NUM_DXQUERY 512
  63. #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
  64. VMWGFX_NUM_GB_SHADER +\
  65. VMWGFX_NUM_GB_SURFACE +\
  66. VMWGFX_NUM_GB_SCREEN_TARGET)
  67. #define VMW_PL_GMR (TTM_PL_PRIV + 0)
  68. #define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0)
  69. #define VMW_PL_MOB (TTM_PL_PRIV + 1)
  70. #define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1)
  71. #define VMW_RES_CONTEXT ttm_driver_type0
  72. #define VMW_RES_SURFACE ttm_driver_type1
  73. #define VMW_RES_STREAM ttm_driver_type2
  74. #define VMW_RES_FENCE ttm_driver_type3
  75. #define VMW_RES_SHADER ttm_driver_type4
  76. struct vmw_fpriv {
  77. struct drm_master *locked_master;
  78. struct ttm_object_file *tfile;
  79. bool gb_aware;
  80. };
  81. struct vmw_dma_buffer {
  82. struct ttm_buffer_object base;
  83. struct list_head res_list;
  84. s32 pin_count;
  85. /* Not ref-counted. Protected by binding_mutex */
  86. struct vmw_resource *dx_query_ctx;
  87. };
  88. /**
  89. * struct vmw_validate_buffer - Carries validation info about buffers.
  90. *
  91. * @base: Validation info for TTM.
  92. * @hash: Hash entry for quick lookup of the TTM buffer object.
  93. *
  94. * This structure contains also driver private validation info
  95. * on top of the info needed by TTM.
  96. */
  97. struct vmw_validate_buffer {
  98. struct ttm_validate_buffer base;
  99. struct drm_hash_item hash;
  100. bool validate_as_mob;
  101. };
  102. struct vmw_res_func;
  103. struct vmw_resource {
  104. struct kref kref;
  105. struct vmw_private *dev_priv;
  106. int id;
  107. bool avail;
  108. unsigned long backup_size;
  109. bool res_dirty; /* Protected by backup buffer reserved */
  110. bool backup_dirty; /* Protected by backup buffer reserved */
  111. struct vmw_dma_buffer *backup;
  112. unsigned long backup_offset;
  113. unsigned long pin_count; /* Protected by resource reserved */
  114. const struct vmw_res_func *func;
  115. struct list_head lru_head; /* Protected by the resource lock */
  116. struct list_head mob_head; /* Protected by @backup reserved */
  117. struct list_head binding_head; /* Protected by binding_mutex */
  118. void (*res_free) (struct vmw_resource *res);
  119. void (*hw_destroy) (struct vmw_resource *res);
  120. };
  121. /*
  122. * Resources that are managed using ioctls.
  123. */
  124. enum vmw_res_type {
  125. vmw_res_context,
  126. vmw_res_surface,
  127. vmw_res_stream,
  128. vmw_res_shader,
  129. vmw_res_dx_context,
  130. vmw_res_cotable,
  131. vmw_res_view,
  132. vmw_res_max
  133. };
  134. /*
  135. * Resources that are managed using command streams.
  136. */
  137. enum vmw_cmdbuf_res_type {
  138. vmw_cmdbuf_res_shader,
  139. vmw_cmdbuf_res_view
  140. };
  141. struct vmw_cmdbuf_res_manager;
  142. struct vmw_cursor_snooper {
  143. size_t age;
  144. uint32_t *image;
  145. };
  146. struct vmw_framebuffer;
  147. struct vmw_surface_offset;
  148. struct vmw_surface {
  149. struct vmw_resource res;
  150. uint32_t flags;
  151. uint32_t format;
  152. uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
  153. struct drm_vmw_size base_size;
  154. struct drm_vmw_size *sizes;
  155. uint32_t num_sizes;
  156. bool scanout;
  157. uint32_t array_size;
  158. /* TODO so far just a extra pointer */
  159. struct vmw_cursor_snooper snooper;
  160. struct vmw_surface_offset *offsets;
  161. SVGA3dTextureFilter autogen_filter;
  162. uint32_t multisample_count;
  163. struct list_head view_list;
  164. };
  165. struct vmw_marker_queue {
  166. struct list_head head;
  167. u64 lag;
  168. u64 lag_time;
  169. spinlock_t lock;
  170. };
  171. struct vmw_fifo_state {
  172. unsigned long reserved_size;
  173. u32 *dynamic_buffer;
  174. u32 *static_buffer;
  175. unsigned long static_buffer_size;
  176. bool using_bounce_buffer;
  177. uint32_t capabilities;
  178. struct mutex fifo_mutex;
  179. struct rw_semaphore rwsem;
  180. struct vmw_marker_queue marker_queue;
  181. bool dx;
  182. };
  183. struct vmw_relocation {
  184. SVGAMobId *mob_loc;
  185. SVGAGuestPtr *location;
  186. uint32_t index;
  187. };
  188. /**
  189. * struct vmw_res_cache_entry - resource information cache entry
  190. *
  191. * @valid: Whether the entry is valid, which also implies that the execbuf
  192. * code holds a reference to the resource, and it's placed on the
  193. * validation list.
  194. * @handle: User-space handle of a resource.
  195. * @res: Non-ref-counted pointer to the resource.
  196. *
  197. * Used to avoid frequent repeated user-space handle lookups of the
  198. * same resource.
  199. */
  200. struct vmw_res_cache_entry {
  201. bool valid;
  202. uint32_t handle;
  203. struct vmw_resource *res;
  204. struct vmw_resource_val_node *node;
  205. };
  206. /**
  207. * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
  208. */
  209. enum vmw_dma_map_mode {
  210. vmw_dma_phys, /* Use physical page addresses */
  211. vmw_dma_alloc_coherent, /* Use TTM coherent pages */
  212. vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
  213. vmw_dma_map_bind, /* Unmap from DMA just before unbind */
  214. vmw_dma_map_max
  215. };
  216. /**
  217. * struct vmw_sg_table - Scatter/gather table for binding, with additional
  218. * device-specific information.
  219. *
  220. * @sgt: Pointer to a struct sg_table with binding information
  221. * @num_regions: Number of regions with device-address contiguous pages
  222. */
  223. struct vmw_sg_table {
  224. enum vmw_dma_map_mode mode;
  225. struct page **pages;
  226. const dma_addr_t *addrs;
  227. struct sg_table *sgt;
  228. unsigned long num_regions;
  229. unsigned long num_pages;
  230. };
  231. /**
  232. * struct vmw_piter - Page iterator that iterates over a list of pages
  233. * and DMA addresses that could be either a scatter-gather list or
  234. * arrays
  235. *
  236. * @pages: Array of page pointers to the pages.
  237. * @addrs: DMA addresses to the pages if coherent pages are used.
  238. * @iter: Scatter-gather page iterator. Current position in SG list.
  239. * @i: Current position in arrays.
  240. * @num_pages: Number of pages total.
  241. * @next: Function to advance the iterator. Returns false if past the list
  242. * of pages, true otherwise.
  243. * @dma_address: Function to return the DMA address of the current page.
  244. */
  245. struct vmw_piter {
  246. struct page **pages;
  247. const dma_addr_t *addrs;
  248. struct sg_page_iter iter;
  249. unsigned long i;
  250. unsigned long num_pages;
  251. bool (*next)(struct vmw_piter *);
  252. dma_addr_t (*dma_address)(struct vmw_piter *);
  253. struct page *(*page)(struct vmw_piter *);
  254. };
  255. /*
  256. * enum vmw_display_unit_type - Describes the display unit
  257. */
  258. enum vmw_display_unit_type {
  259. vmw_du_invalid = 0,
  260. vmw_du_legacy,
  261. vmw_du_screen_object,
  262. vmw_du_screen_target
  263. };
  264. struct vmw_sw_context{
  265. struct drm_open_hash res_ht;
  266. bool res_ht_initialized;
  267. bool kernel; /**< is the called made from the kernel */
  268. struct vmw_fpriv *fp;
  269. struct list_head validate_nodes;
  270. struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
  271. uint32_t cur_reloc;
  272. struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
  273. uint32_t cur_val_buf;
  274. uint32_t *cmd_bounce;
  275. uint32_t cmd_bounce_size;
  276. struct list_head resource_list;
  277. struct list_head ctx_resource_list; /* For contexts and cotables */
  278. struct vmw_dma_buffer *cur_query_bo;
  279. struct list_head res_relocations;
  280. uint32_t *buf_start;
  281. struct vmw_res_cache_entry res_cache[vmw_res_max];
  282. struct vmw_resource *last_query_ctx;
  283. bool needs_post_query_barrier;
  284. struct vmw_resource *error_resource;
  285. struct vmw_ctx_binding_state *staged_bindings;
  286. bool staged_bindings_inuse;
  287. struct list_head staged_cmd_res;
  288. struct vmw_resource_val_node *dx_ctx_node;
  289. struct vmw_dma_buffer *dx_query_mob;
  290. struct vmw_resource *dx_query_ctx;
  291. struct vmw_cmdbuf_res_manager *man;
  292. };
  293. struct vmw_legacy_display;
  294. struct vmw_overlay;
  295. struct vmw_master {
  296. struct ttm_lock lock;
  297. };
  298. struct vmw_vga_topology_state {
  299. uint32_t width;
  300. uint32_t height;
  301. uint32_t primary;
  302. uint32_t pos_x;
  303. uint32_t pos_y;
  304. };
  305. /*
  306. * struct vmw_otable - Guest Memory OBject table metadata
  307. *
  308. * @size: Size of the table (page-aligned).
  309. * @page_table: Pointer to a struct vmw_mob holding the page table.
  310. */
  311. struct vmw_otable {
  312. unsigned long size;
  313. struct vmw_mob *page_table;
  314. bool enabled;
  315. };
  316. struct vmw_otable_batch {
  317. unsigned num_otables;
  318. struct vmw_otable *otables;
  319. struct vmw_resource *context;
  320. struct ttm_buffer_object *otable_bo;
  321. };
  322. enum {
  323. VMW_IRQTHREAD_FENCE,
  324. VMW_IRQTHREAD_CMDBUF,
  325. VMW_IRQTHREAD_MAX
  326. };
  327. struct vmw_private {
  328. struct ttm_bo_device bdev;
  329. struct ttm_bo_global_ref bo_global_ref;
  330. struct drm_global_reference mem_global_ref;
  331. struct vmw_fifo_state fifo;
  332. struct drm_device *dev;
  333. unsigned long vmw_chipset;
  334. unsigned int io_start;
  335. uint32_t vram_start;
  336. uint32_t vram_size;
  337. uint32_t prim_bb_mem;
  338. uint32_t mmio_start;
  339. uint32_t mmio_size;
  340. uint32_t fb_max_width;
  341. uint32_t fb_max_height;
  342. uint32_t texture_max_width;
  343. uint32_t texture_max_height;
  344. uint32_t stdu_max_width;
  345. uint32_t stdu_max_height;
  346. uint32_t initial_width;
  347. uint32_t initial_height;
  348. u32 *mmio_virt;
  349. uint32_t capabilities;
  350. uint32_t max_gmr_ids;
  351. uint32_t max_gmr_pages;
  352. uint32_t max_mob_pages;
  353. uint32_t max_mob_size;
  354. uint32_t memory_size;
  355. bool has_gmr;
  356. bool has_mob;
  357. spinlock_t hw_lock;
  358. spinlock_t cap_lock;
  359. bool has_dx;
  360. bool assume_16bpp;
  361. /*
  362. * VGA registers.
  363. */
  364. struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
  365. uint32_t vga_width;
  366. uint32_t vga_height;
  367. uint32_t vga_bpp;
  368. uint32_t vga_bpl;
  369. uint32_t vga_pitchlock;
  370. uint32_t num_displays;
  371. /*
  372. * Framebuffer info.
  373. */
  374. void *fb_info;
  375. enum vmw_display_unit_type active_display_unit;
  376. struct vmw_legacy_display *ldu_priv;
  377. struct vmw_overlay *overlay_priv;
  378. struct drm_property *hotplug_mode_update_property;
  379. struct drm_property *implicit_placement_property;
  380. unsigned num_implicit;
  381. struct vmw_framebuffer *implicit_fb;
  382. struct mutex global_kms_state_mutex;
  383. spinlock_t cursor_lock;
  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. spinlock_t waiter_lock;
  405. int fence_queue_waiters; /* Protected by waiter_lock */
  406. int goal_queue_waiters; /* Protected by waiter_lock */
  407. int cmdbuf_waiters; /* Protected by waiter_lock */
  408. int error_waiters; /* Protected by waiter_lock */
  409. int fifo_queue_waiters; /* Protected by waiter_lock */
  410. uint32_t last_read_seqno;
  411. struct vmw_fence_manager *fman;
  412. uint32_t irq_mask; /* Updates protected by waiter_lock */
  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. spinlock_t svga_lock;
  434. /**
  435. * Master management.
  436. */
  437. struct vmw_master *active_master;
  438. struct vmw_master fbdev_master;
  439. struct notifier_block pm_nb;
  440. bool suspended;
  441. bool refuse_hibernation;
  442. struct mutex release_mutex;
  443. atomic_t num_fifo_resources;
  444. /*
  445. * Replace this with an rwsem as soon as we have down_xx_interruptible()
  446. */
  447. struct ttm_lock reservation_sem;
  448. /*
  449. * Query processing. These members
  450. * are protected by the cmdbuf mutex.
  451. */
  452. struct vmw_dma_buffer *dummy_query_bo;
  453. struct vmw_dma_buffer *pinned_bo;
  454. uint32_t query_cid;
  455. uint32_t query_cid_valid;
  456. bool dummy_query_bo_pinned;
  457. /*
  458. * Surface swapping. The "surface_lru" list is protected by the
  459. * resource lock in order to be able to destroy a surface and take
  460. * it off the lru atomically. "used_memory_size" is currently
  461. * protected by the cmdbuf mutex for simplicity.
  462. */
  463. struct list_head res_lru[vmw_res_max];
  464. uint32_t used_memory_size;
  465. /*
  466. * DMA mapping stuff.
  467. */
  468. enum vmw_dma_map_mode map_mode;
  469. /*
  470. * Guest Backed stuff
  471. */
  472. struct vmw_otable_batch otable_batch;
  473. struct vmw_cmdbuf_man *cman;
  474. DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
  475. };
  476. static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
  477. {
  478. return container_of(res, struct vmw_surface, res);
  479. }
  480. static inline struct vmw_private *vmw_priv(struct drm_device *dev)
  481. {
  482. return (struct vmw_private *)dev->dev_private;
  483. }
  484. static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
  485. {
  486. return (struct vmw_fpriv *)file_priv->driver_priv;
  487. }
  488. static inline struct vmw_master *vmw_master(struct drm_master *master)
  489. {
  490. return (struct vmw_master *) master->driver_priv;
  491. }
  492. /*
  493. * The locking here is fine-grained, so that it is performed once
  494. * for every read- and write operation. This is of course costly, but we
  495. * don't perform much register access in the timing critical paths anyway.
  496. * Instead we have the extra benefit of being sure that we don't forget
  497. * the hw lock around register accesses.
  498. */
  499. static inline void vmw_write(struct vmw_private *dev_priv,
  500. unsigned int offset, uint32_t value)
  501. {
  502. spin_lock(&dev_priv->hw_lock);
  503. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  504. outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
  505. spin_unlock(&dev_priv->hw_lock);
  506. }
  507. static inline uint32_t vmw_read(struct vmw_private *dev_priv,
  508. unsigned int offset)
  509. {
  510. u32 val;
  511. spin_lock(&dev_priv->hw_lock);
  512. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  513. val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
  514. spin_unlock(&dev_priv->hw_lock);
  515. return val;
  516. }
  517. extern void vmw_svga_enable(struct vmw_private *dev_priv);
  518. extern void vmw_svga_disable(struct vmw_private *dev_priv);
  519. /**
  520. * GMR utilities - vmwgfx_gmr.c
  521. */
  522. extern int vmw_gmr_bind(struct vmw_private *dev_priv,
  523. const struct vmw_sg_table *vsgt,
  524. unsigned long num_pages,
  525. int gmr_id);
  526. extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
  527. /**
  528. * Resource utilities - vmwgfx_resource.c
  529. */
  530. struct vmw_user_resource_conv;
  531. extern void vmw_resource_unreference(struct vmw_resource **p_res);
  532. extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
  533. extern struct vmw_resource *
  534. vmw_resource_reference_unless_doomed(struct vmw_resource *res);
  535. extern int vmw_resource_validate(struct vmw_resource *res);
  536. extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
  537. bool no_backup);
  538. extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
  539. extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
  540. struct ttm_object_file *tfile,
  541. uint32_t handle,
  542. struct vmw_surface **out_surf,
  543. struct vmw_dma_buffer **out_buf);
  544. extern int vmw_user_resource_lookup_handle(
  545. struct vmw_private *dev_priv,
  546. struct ttm_object_file *tfile,
  547. uint32_t handle,
  548. const struct vmw_user_resource_conv *converter,
  549. struct vmw_resource **p_res);
  550. extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
  551. extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
  552. struct vmw_dma_buffer *vmw_bo,
  553. size_t size, struct ttm_placement *placement,
  554. bool interuptable,
  555. void (*bo_free) (struct ttm_buffer_object *bo));
  556. extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
  557. struct ttm_object_file *tfile);
  558. extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
  559. struct ttm_object_file *tfile,
  560. uint32_t size,
  561. bool shareable,
  562. uint32_t *handle,
  563. struct vmw_dma_buffer **p_dma_buf,
  564. struct ttm_base_object **p_base);
  565. extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
  566. struct vmw_dma_buffer *dma_buf,
  567. uint32_t *handle);
  568. extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
  569. struct drm_file *file_priv);
  570. extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
  571. struct drm_file *file_priv);
  572. extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
  573. struct drm_file *file_priv);
  574. extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
  575. uint32_t cur_validate_node);
  576. extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
  577. extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
  578. uint32_t id, struct vmw_dma_buffer **out,
  579. struct ttm_base_object **base);
  580. extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  581. struct drm_file *file_priv);
  582. extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  583. struct drm_file *file_priv);
  584. extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  585. struct ttm_object_file *tfile,
  586. uint32_t *inout_id,
  587. struct vmw_resource **out);
  588. extern void vmw_resource_unreserve(struct vmw_resource *res,
  589. bool switch_backup,
  590. struct vmw_dma_buffer *new_backup,
  591. unsigned long new_backup_offset);
  592. extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
  593. struct ttm_mem_reg *mem);
  594. extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
  595. struct ttm_mem_reg *mem);
  596. extern int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob);
  597. extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
  598. struct vmw_fence_obj *fence);
  599. extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
  600. /**
  601. * DMA buffer helper routines - vmwgfx_dmabuf.c
  602. */
  603. extern int vmw_dmabuf_pin_in_placement(struct vmw_private *vmw_priv,
  604. struct vmw_dma_buffer *bo,
  605. struct ttm_placement *placement,
  606. bool interruptible);
  607. extern int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv,
  608. struct vmw_dma_buffer *buf,
  609. bool interruptible);
  610. extern int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
  611. struct vmw_dma_buffer *buf,
  612. bool interruptible);
  613. extern int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *vmw_priv,
  614. struct vmw_dma_buffer *bo,
  615. bool interruptible);
  616. extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
  617. struct vmw_dma_buffer *bo,
  618. bool interruptible);
  619. extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
  620. SVGAGuestPtr *ptr);
  621. extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin);
  622. /**
  623. * Misc Ioctl functionality - vmwgfx_ioctl.c
  624. */
  625. extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  626. struct drm_file *file_priv);
  627. extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
  628. struct drm_file *file_priv);
  629. extern int vmw_present_ioctl(struct drm_device *dev, void *data,
  630. struct drm_file *file_priv);
  631. extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
  632. struct drm_file *file_priv);
  633. extern unsigned int vmw_fops_poll(struct file *filp,
  634. struct poll_table_struct *wait);
  635. extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
  636. size_t count, loff_t *offset);
  637. /**
  638. * Fifo utilities - vmwgfx_fifo.c
  639. */
  640. extern int vmw_fifo_init(struct vmw_private *dev_priv,
  641. struct vmw_fifo_state *fifo);
  642. extern void vmw_fifo_release(struct vmw_private *dev_priv,
  643. struct vmw_fifo_state *fifo);
  644. extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
  645. extern void *
  646. vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
  647. extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
  648. extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
  649. extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
  650. uint32_t *seqno);
  651. extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
  652. extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
  653. extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
  654. extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
  655. extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
  656. uint32_t cid);
  657. extern int vmw_fifo_flush(struct vmw_private *dev_priv,
  658. bool interruptible);
  659. /**
  660. * TTM glue - vmwgfx_ttm_glue.c
  661. */
  662. extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
  663. extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
  664. extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
  665. /**
  666. * TTM buffer object driver - vmwgfx_buffer.c
  667. */
  668. extern const size_t vmw_tt_size;
  669. extern struct ttm_placement vmw_vram_placement;
  670. extern struct ttm_placement vmw_vram_ne_placement;
  671. extern struct ttm_placement vmw_vram_sys_placement;
  672. extern struct ttm_placement vmw_vram_gmr_placement;
  673. extern struct ttm_placement vmw_vram_gmr_ne_placement;
  674. extern struct ttm_placement vmw_sys_placement;
  675. extern struct ttm_placement vmw_sys_ne_placement;
  676. extern struct ttm_placement vmw_evictable_placement;
  677. extern struct ttm_placement vmw_srf_placement;
  678. extern struct ttm_placement vmw_mob_placement;
  679. extern struct ttm_placement vmw_mob_ne_placement;
  680. extern struct ttm_bo_driver vmw_bo_driver;
  681. extern int vmw_dma_quiescent(struct drm_device *dev);
  682. extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
  683. extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
  684. extern const struct vmw_sg_table *
  685. vmw_bo_sg_table(struct ttm_buffer_object *bo);
  686. extern void vmw_piter_start(struct vmw_piter *viter,
  687. const struct vmw_sg_table *vsgt,
  688. unsigned long p_offs);
  689. /**
  690. * vmw_piter_next - Advance the iterator one page.
  691. *
  692. * @viter: Pointer to the iterator to advance.
  693. *
  694. * Returns false if past the list of pages, true otherwise.
  695. */
  696. static inline bool vmw_piter_next(struct vmw_piter *viter)
  697. {
  698. return viter->next(viter);
  699. }
  700. /**
  701. * vmw_piter_dma_addr - Return the DMA address of the current page.
  702. *
  703. * @viter: Pointer to the iterator
  704. *
  705. * Returns the DMA address of the page pointed to by @viter.
  706. */
  707. static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
  708. {
  709. return viter->dma_address(viter);
  710. }
  711. /**
  712. * vmw_piter_page - Return a pointer to the current page.
  713. *
  714. * @viter: Pointer to the iterator
  715. *
  716. * Returns the DMA address of the page pointed to by @viter.
  717. */
  718. static inline struct page *vmw_piter_page(struct vmw_piter *viter)
  719. {
  720. return viter->page(viter);
  721. }
  722. /**
  723. * Command submission - vmwgfx_execbuf.c
  724. */
  725. extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
  726. struct drm_file *file_priv, size_t size);
  727. extern int vmw_execbuf_process(struct drm_file *file_priv,
  728. struct vmw_private *dev_priv,
  729. void __user *user_commands,
  730. void *kernel_commands,
  731. uint32_t command_size,
  732. uint64_t throttle_us,
  733. uint32_t dx_context_handle,
  734. struct drm_vmw_fence_rep __user
  735. *user_fence_rep,
  736. struct vmw_fence_obj **out_fence,
  737. uint32_t flags);
  738. extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
  739. struct vmw_fence_obj *fence);
  740. extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
  741. extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
  742. struct vmw_private *dev_priv,
  743. struct vmw_fence_obj **p_fence,
  744. uint32_t *p_handle);
  745. extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
  746. struct vmw_fpriv *vmw_fp,
  747. int ret,
  748. struct drm_vmw_fence_rep __user
  749. *user_fence_rep,
  750. struct vmw_fence_obj *fence,
  751. uint32_t fence_handle,
  752. int32_t out_fence_fd,
  753. struct sync_file *sync_file);
  754. extern int vmw_validate_single_buffer(struct vmw_private *dev_priv,
  755. struct ttm_buffer_object *bo,
  756. bool interruptible,
  757. bool validate_as_mob);
  758. bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
  759. /**
  760. * IRQs and wating - vmwgfx_irq.c
  761. */
  762. extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
  763. uint32_t seqno, bool interruptible,
  764. unsigned long timeout);
  765. extern int vmw_irq_install(struct drm_device *dev, int irq);
  766. extern void vmw_irq_uninstall(struct drm_device *dev);
  767. extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
  768. uint32_t seqno);
  769. extern int vmw_fallback_wait(struct vmw_private *dev_priv,
  770. bool lazy,
  771. bool fifo_idle,
  772. uint32_t seqno,
  773. bool interruptible,
  774. unsigned long timeout);
  775. extern void vmw_update_seqno(struct vmw_private *dev_priv,
  776. struct vmw_fifo_state *fifo_state);
  777. extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
  778. extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
  779. extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
  780. extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
  781. extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
  782. int *waiter_count);
  783. extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
  784. u32 flag, int *waiter_count);
  785. /**
  786. * Rudimentary fence-like objects currently used only for throttling -
  787. * vmwgfx_marker.c
  788. */
  789. extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
  790. extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
  791. extern int vmw_marker_push(struct vmw_marker_queue *queue,
  792. uint32_t seqno);
  793. extern int vmw_marker_pull(struct vmw_marker_queue *queue,
  794. uint32_t signaled_seqno);
  795. extern int vmw_wait_lag(struct vmw_private *dev_priv,
  796. struct vmw_marker_queue *queue, uint32_t us);
  797. /**
  798. * Kernel framebuffer - vmwgfx_fb.c
  799. */
  800. int vmw_fb_init(struct vmw_private *vmw_priv);
  801. int vmw_fb_close(struct vmw_private *dev_priv);
  802. int vmw_fb_off(struct vmw_private *vmw_priv);
  803. int vmw_fb_on(struct vmw_private *vmw_priv);
  804. /**
  805. * Kernel modesetting - vmwgfx_kms.c
  806. */
  807. int vmw_kms_init(struct vmw_private *dev_priv);
  808. int vmw_kms_close(struct vmw_private *dev_priv);
  809. int vmw_kms_save_vga(struct vmw_private *vmw_priv);
  810. int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
  811. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  812. struct drm_file *file_priv);
  813. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
  814. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  815. struct ttm_object_file *tfile,
  816. struct ttm_buffer_object *bo,
  817. SVGA3dCmdHeader *header);
  818. int vmw_kms_write_svga(struct vmw_private *vmw_priv,
  819. unsigned width, unsigned height, unsigned pitch,
  820. unsigned bpp, unsigned depth);
  821. void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
  822. bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
  823. uint32_t pitch,
  824. uint32_t height);
  825. u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
  826. int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe);
  827. void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe);
  828. int vmw_kms_present(struct vmw_private *dev_priv,
  829. struct drm_file *file_priv,
  830. struct vmw_framebuffer *vfb,
  831. struct vmw_surface *surface,
  832. uint32_t sid, int32_t destX, int32_t destY,
  833. struct drm_vmw_rect *clips,
  834. uint32_t num_clips);
  835. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  836. struct drm_file *file_priv);
  837. void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
  838. void vmw_kms_lost_device(struct drm_device *dev);
  839. int vmw_dumb_create(struct drm_file *file_priv,
  840. struct drm_device *dev,
  841. struct drm_mode_create_dumb *args);
  842. int vmw_dumb_map_offset(struct drm_file *file_priv,
  843. struct drm_device *dev, uint32_t handle,
  844. uint64_t *offset);
  845. int vmw_dumb_destroy(struct drm_file *file_priv,
  846. struct drm_device *dev,
  847. uint32_t handle);
  848. extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
  849. extern void vmw_resource_unpin(struct vmw_resource *res);
  850. extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
  851. /**
  852. * Overlay control - vmwgfx_overlay.c
  853. */
  854. int vmw_overlay_init(struct vmw_private *dev_priv);
  855. int vmw_overlay_close(struct vmw_private *dev_priv);
  856. int vmw_overlay_ioctl(struct drm_device *dev, void *data,
  857. struct drm_file *file_priv);
  858. int vmw_overlay_stop_all(struct vmw_private *dev_priv);
  859. int vmw_overlay_resume_all(struct vmw_private *dev_priv);
  860. int vmw_overlay_pause_all(struct vmw_private *dev_priv);
  861. int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
  862. int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
  863. int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
  864. int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  865. /**
  866. * GMR Id manager
  867. */
  868. extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
  869. /**
  870. * Prime - vmwgfx_prime.c
  871. */
  872. extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
  873. extern int vmw_prime_fd_to_handle(struct drm_device *dev,
  874. struct drm_file *file_priv,
  875. int fd, u32 *handle);
  876. extern int vmw_prime_handle_to_fd(struct drm_device *dev,
  877. struct drm_file *file_priv,
  878. uint32_t handle, uint32_t flags,
  879. int *prime_fd);
  880. /*
  881. * MemoryOBject management - vmwgfx_mob.c
  882. */
  883. struct vmw_mob;
  884. extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
  885. const struct vmw_sg_table *vsgt,
  886. unsigned long num_data_pages, int32_t mob_id);
  887. extern void vmw_mob_unbind(struct vmw_private *dev_priv,
  888. struct vmw_mob *mob);
  889. extern void vmw_mob_destroy(struct vmw_mob *mob);
  890. extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
  891. extern int vmw_otables_setup(struct vmw_private *dev_priv);
  892. extern void vmw_otables_takedown(struct vmw_private *dev_priv);
  893. /*
  894. * Context management - vmwgfx_context.c
  895. */
  896. extern const struct vmw_user_resource_conv *user_context_converter;
  897. extern int vmw_context_check(struct vmw_private *dev_priv,
  898. struct ttm_object_file *tfile,
  899. int id,
  900. struct vmw_resource **p_res);
  901. extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
  902. struct drm_file *file_priv);
  903. extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
  904. struct drm_file *file_priv);
  905. extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
  906. struct drm_file *file_priv);
  907. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  908. extern struct vmw_cmdbuf_res_manager *
  909. vmw_context_res_man(struct vmw_resource *ctx);
  910. extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
  911. SVGACOTableType cotable_type);
  912. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  913. struct vmw_ctx_binding_state;
  914. extern struct vmw_ctx_binding_state *
  915. vmw_context_binding_state(struct vmw_resource *ctx);
  916. extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
  917. bool readback);
  918. extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
  919. struct vmw_dma_buffer *mob);
  920. extern struct vmw_dma_buffer *
  921. vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
  922. /*
  923. * Surface management - vmwgfx_surface.c
  924. */
  925. extern const struct vmw_user_resource_conv *user_surface_converter;
  926. extern void vmw_surface_res_free(struct vmw_resource *res);
  927. extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
  928. struct drm_file *file_priv);
  929. extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
  930. struct drm_file *file_priv);
  931. extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
  932. struct drm_file *file_priv);
  933. extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
  934. struct drm_file *file_priv);
  935. extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
  936. struct drm_file *file_priv);
  937. extern int vmw_surface_check(struct vmw_private *dev_priv,
  938. struct ttm_object_file *tfile,
  939. uint32_t handle, int *id);
  940. extern int vmw_surface_validate(struct vmw_private *dev_priv,
  941. struct vmw_surface *srf);
  942. int vmw_surface_gb_priv_define(struct drm_device *dev,
  943. uint32_t user_accounting_size,
  944. uint32_t svga3d_flags,
  945. SVGA3dSurfaceFormat format,
  946. bool for_scanout,
  947. uint32_t num_mip_levels,
  948. uint32_t multisample_count,
  949. uint32_t array_size,
  950. struct drm_vmw_size size,
  951. struct vmw_surface **srf_out);
  952. /*
  953. * Shader management - vmwgfx_shader.c
  954. */
  955. extern const struct vmw_user_resource_conv *user_shader_converter;
  956. extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
  957. struct drm_file *file_priv);
  958. extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
  959. struct drm_file *file_priv);
  960. extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
  961. struct vmw_cmdbuf_res_manager *man,
  962. u32 user_key, const void *bytecode,
  963. SVGA3dShaderType shader_type,
  964. size_t size,
  965. struct list_head *list);
  966. extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
  967. u32 user_key, SVGA3dShaderType shader_type,
  968. struct list_head *list);
  969. extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
  970. struct vmw_resource *ctx,
  971. u32 user_key,
  972. SVGA3dShaderType shader_type,
  973. struct list_head *list);
  974. extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
  975. struct list_head *list,
  976. bool readback);
  977. extern struct vmw_resource *
  978. vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
  979. u32 user_key, SVGA3dShaderType shader_type);
  980. /*
  981. * Command buffer managed resources - vmwgfx_cmdbuf_res.c
  982. */
  983. extern struct vmw_cmdbuf_res_manager *
  984. vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
  985. extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
  986. extern size_t vmw_cmdbuf_res_man_size(void);
  987. extern struct vmw_resource *
  988. vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
  989. enum vmw_cmdbuf_res_type res_type,
  990. u32 user_key);
  991. extern void vmw_cmdbuf_res_revert(struct list_head *list);
  992. extern void vmw_cmdbuf_res_commit(struct list_head *list);
  993. extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
  994. enum vmw_cmdbuf_res_type res_type,
  995. u32 user_key,
  996. struct vmw_resource *res,
  997. struct list_head *list);
  998. extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
  999. enum vmw_cmdbuf_res_type res_type,
  1000. u32 user_key,
  1001. struct list_head *list,
  1002. struct vmw_resource **res);
  1003. /*
  1004. * COTable management - vmwgfx_cotable.c
  1005. */
  1006. extern const SVGACOTableType vmw_cotable_scrub_order[];
  1007. extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
  1008. struct vmw_resource *ctx,
  1009. u32 type);
  1010. extern int vmw_cotable_notify(struct vmw_resource *res, int id);
  1011. extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
  1012. extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
  1013. struct list_head *head);
  1014. /*
  1015. * Command buffer managerment vmwgfx_cmdbuf.c
  1016. */
  1017. struct vmw_cmdbuf_man;
  1018. struct vmw_cmdbuf_header;
  1019. extern struct vmw_cmdbuf_man *
  1020. vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
  1021. extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
  1022. size_t size, size_t default_size);
  1023. extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
  1024. extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
  1025. extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
  1026. unsigned long timeout);
  1027. extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
  1028. int ctx_id, bool interruptible,
  1029. struct vmw_cmdbuf_header *header);
  1030. extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
  1031. struct vmw_cmdbuf_header *header,
  1032. bool flush);
  1033. extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
  1034. size_t size, bool interruptible,
  1035. struct vmw_cmdbuf_header **p_header);
  1036. extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
  1037. extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
  1038. bool interruptible);
  1039. extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
  1040. /**
  1041. * Inline helper functions
  1042. */
  1043. static inline void vmw_surface_unreference(struct vmw_surface **srf)
  1044. {
  1045. struct vmw_surface *tmp_srf = *srf;
  1046. struct vmw_resource *res = &tmp_srf->res;
  1047. *srf = NULL;
  1048. vmw_resource_unreference(&res);
  1049. }
  1050. static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
  1051. {
  1052. (void) vmw_resource_reference(&srf->res);
  1053. return srf;
  1054. }
  1055. static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
  1056. {
  1057. struct vmw_dma_buffer *tmp_buf = *buf;
  1058. *buf = NULL;
  1059. if (tmp_buf != NULL) {
  1060. struct ttm_buffer_object *bo = &tmp_buf->base;
  1061. ttm_bo_unref(&bo);
  1062. }
  1063. }
  1064. static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
  1065. {
  1066. if (ttm_bo_reference(&buf->base))
  1067. return buf;
  1068. return NULL;
  1069. }
  1070. static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
  1071. {
  1072. return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
  1073. }
  1074. static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
  1075. {
  1076. atomic_inc(&dev_priv->num_fifo_resources);
  1077. }
  1078. static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
  1079. {
  1080. atomic_dec(&dev_priv->num_fifo_resources);
  1081. }
  1082. /**
  1083. * vmw_mmio_read - Perform a MMIO read from volatile memory
  1084. *
  1085. * @addr: The address to read from
  1086. *
  1087. * This function is intended to be equivalent to ioread32() on
  1088. * memremap'd memory, but without byteswapping.
  1089. */
  1090. static inline u32 vmw_mmio_read(u32 *addr)
  1091. {
  1092. return READ_ONCE(*addr);
  1093. }
  1094. /**
  1095. * vmw_mmio_write - Perform a MMIO write to volatile memory
  1096. *
  1097. * @addr: The address to write to
  1098. *
  1099. * This function is intended to be equivalent to iowrite32 on
  1100. * memremap'd memory, but without byteswapping.
  1101. */
  1102. static inline void vmw_mmio_write(u32 value, u32 *addr)
  1103. {
  1104. WRITE_ONCE(*addr, value);
  1105. }
  1106. /**
  1107. * Add vmw_msg module function
  1108. */
  1109. extern int vmw_host_log(const char *log);
  1110. #endif