vmwgfx_drv.h 32 KB

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