vmwgfx_drv.h 32 KB

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