vmwgfx_drv.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /**************************************************************************
  3. *
  4. * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
  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_validation.h"
  30. #include "vmwgfx_reg.h"
  31. #include <drm/drmP.h>
  32. #include <drm/vmwgfx_drm.h>
  33. #include <drm/drm_hashtab.h>
  34. #include <drm/drm_auth.h>
  35. #include <linux/suspend.h>
  36. #include <drm/ttm/ttm_bo_driver.h>
  37. #include <drm/ttm/ttm_execbuf_util.h>
  38. #include <drm/ttm/ttm_module.h>
  39. #include "vmwgfx_fence.h"
  40. #include "ttm_object.h"
  41. #include "ttm_lock.h"
  42. #include <linux/sync_file.h>
  43. #define VMWGFX_DRIVER_NAME "vmwgfx"
  44. #define VMWGFX_DRIVER_DATE "20180704"
  45. #define VMWGFX_DRIVER_MAJOR 2
  46. #define VMWGFX_DRIVER_MINOR 15
  47. #define VMWGFX_DRIVER_PATCHLEVEL 0
  48. #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
  49. #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
  50. #define VMWGFX_MAX_RELOCATIONS 2048
  51. #define VMWGFX_MAX_VALIDATIONS 2048
  52. #define VMWGFX_MAX_DISPLAYS 16
  53. #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
  54. #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
  55. /*
  56. * Perhaps we should have sysfs entries for these.
  57. */
  58. #define VMWGFX_NUM_GB_CONTEXT 256
  59. #define VMWGFX_NUM_GB_SHADER 20000
  60. #define VMWGFX_NUM_GB_SURFACE 32768
  61. #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
  62. #define VMWGFX_NUM_DXCONTEXT 256
  63. #define VMWGFX_NUM_DXQUERY 512
  64. #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
  65. VMWGFX_NUM_GB_SHADER +\
  66. VMWGFX_NUM_GB_SURFACE +\
  67. VMWGFX_NUM_GB_SCREEN_TARGET)
  68. #define VMW_PL_GMR (TTM_PL_PRIV + 0)
  69. #define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0)
  70. #define VMW_PL_MOB (TTM_PL_PRIV + 1)
  71. #define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1)
  72. #define VMW_RES_CONTEXT ttm_driver_type0
  73. #define VMW_RES_SURFACE ttm_driver_type1
  74. #define VMW_RES_STREAM ttm_driver_type2
  75. #define VMW_RES_FENCE ttm_driver_type3
  76. #define VMW_RES_SHADER ttm_driver_type4
  77. struct vmw_fpriv {
  78. struct drm_master *locked_master;
  79. struct ttm_object_file *tfile;
  80. bool gb_aware; /* user-space is guest-backed aware */
  81. };
  82. struct vmw_buffer_object {
  83. struct ttm_buffer_object base;
  84. struct list_head res_list;
  85. s32 pin_count;
  86. /* Not ref-counted. Protected by binding_mutex */
  87. struct vmw_resource *dx_query_ctx;
  88. /* Protected by reservation */
  89. struct ttm_bo_kmap_obj map;
  90. };
  91. /**
  92. * struct vmw_validate_buffer - Carries validation info about buffers.
  93. *
  94. * @base: Validation info for TTM.
  95. * @hash: Hash entry for quick lookup of the TTM buffer object.
  96. *
  97. * This structure contains also driver private validation info
  98. * on top of the info needed by TTM.
  99. */
  100. struct vmw_validate_buffer {
  101. struct ttm_validate_buffer base;
  102. struct drm_hash_item hash;
  103. bool validate_as_mob;
  104. };
  105. struct vmw_res_func;
  106. /**
  107. * struct vmw-resource - base class for hardware resources
  108. *
  109. * @kref: For refcounting.
  110. * @dev_priv: Pointer to the device private for this resource. Immutable.
  111. * @id: Device id. Protected by @dev_priv::resource_lock.
  112. * @backup_size: Backup buffer size. Immutable.
  113. * @res_dirty: Resource contains data not yet in the backup buffer. Protected
  114. * by resource reserved.
  115. * @backup_dirty: Backup buffer contains data not yet in the HW resource.
  116. * Protecte by resource reserved.
  117. * @backup: The backup buffer if any. Protected by resource reserved.
  118. * @backup_offset: Offset into the backup buffer if any. Protected by resource
  119. * reserved. Note that only a few resource types can have a @backup_offset
  120. * different from zero.
  121. * @pin_count: The pin count for this resource. A pinned resource has a
  122. * pin-count greater than zero. It is not on the resource LRU lists and its
  123. * backup buffer is pinned. Hence it can't be evicted.
  124. * @func: Method vtable for this resource. Immutable.
  125. * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
  126. * @mob_head: List head for the MOB backup list. Protected by @backup reserved.
  127. * @binding_head: List head for the context binding list. Protected by
  128. * the @dev_priv::binding_mutex
  129. * @res_free: The resource destructor.
  130. * @hw_destroy: Callback to destroy the resource on the device, as part of
  131. * resource destruction.
  132. */
  133. struct vmw_resource {
  134. struct kref kref;
  135. struct vmw_private *dev_priv;
  136. int id;
  137. unsigned long backup_size;
  138. bool res_dirty;
  139. bool backup_dirty;
  140. struct vmw_buffer_object *backup;
  141. unsigned long backup_offset;
  142. unsigned long pin_count;
  143. const struct vmw_res_func *func;
  144. struct list_head lru_head;
  145. struct list_head mob_head;
  146. struct list_head binding_head;
  147. void (*res_free) (struct vmw_resource *res);
  148. void (*hw_destroy) (struct vmw_resource *res);
  149. };
  150. /*
  151. * Resources that are managed using ioctls.
  152. */
  153. enum vmw_res_type {
  154. vmw_res_context,
  155. vmw_res_surface,
  156. vmw_res_stream,
  157. vmw_res_shader,
  158. vmw_res_dx_context,
  159. vmw_res_cotable,
  160. vmw_res_view,
  161. vmw_res_max
  162. };
  163. /*
  164. * Resources that are managed using command streams.
  165. */
  166. enum vmw_cmdbuf_res_type {
  167. vmw_cmdbuf_res_shader,
  168. vmw_cmdbuf_res_view
  169. };
  170. struct vmw_cmdbuf_res_manager;
  171. struct vmw_cursor_snooper {
  172. size_t age;
  173. uint32_t *image;
  174. };
  175. struct vmw_framebuffer;
  176. struct vmw_surface_offset;
  177. struct vmw_surface {
  178. struct vmw_resource res;
  179. SVGA3dSurfaceAllFlags flags;
  180. uint32_t format;
  181. uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
  182. struct drm_vmw_size base_size;
  183. struct drm_vmw_size *sizes;
  184. uint32_t num_sizes;
  185. bool scanout;
  186. uint32_t array_size;
  187. /* TODO so far just a extra pointer */
  188. struct vmw_cursor_snooper snooper;
  189. struct vmw_surface_offset *offsets;
  190. SVGA3dTextureFilter autogen_filter;
  191. uint32_t multisample_count;
  192. struct list_head view_list;
  193. SVGA3dMSPattern multisample_pattern;
  194. SVGA3dMSQualityLevel quality_level;
  195. };
  196. struct vmw_marker_queue {
  197. struct list_head head;
  198. u64 lag;
  199. u64 lag_time;
  200. spinlock_t lock;
  201. };
  202. struct vmw_fifo_state {
  203. unsigned long reserved_size;
  204. u32 *dynamic_buffer;
  205. u32 *static_buffer;
  206. unsigned long static_buffer_size;
  207. bool using_bounce_buffer;
  208. uint32_t capabilities;
  209. struct mutex fifo_mutex;
  210. struct rw_semaphore rwsem;
  211. struct vmw_marker_queue marker_queue;
  212. bool dx;
  213. };
  214. /**
  215. * struct vmw_res_cache_entry - resource information cache entry
  216. * @handle: User-space handle of a resource.
  217. * @res: Non-ref-counted pointer to the resource.
  218. * @valid_handle: Whether the @handle member is valid.
  219. * @valid: Whether the entry is valid, which also implies that the execbuf
  220. * code holds a reference to the resource, and it's placed on the
  221. * validation list.
  222. *
  223. * Used to avoid frequent repeated user-space handle lookups of the
  224. * same resource.
  225. */
  226. struct vmw_res_cache_entry {
  227. uint32_t handle;
  228. struct vmw_resource *res;
  229. void *private;
  230. unsigned short valid_handle;
  231. unsigned short valid;
  232. };
  233. /**
  234. * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
  235. */
  236. enum vmw_dma_map_mode {
  237. vmw_dma_phys, /* Use physical page addresses */
  238. vmw_dma_alloc_coherent, /* Use TTM coherent pages */
  239. vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
  240. vmw_dma_map_bind, /* Unmap from DMA just before unbind */
  241. vmw_dma_map_max
  242. };
  243. /**
  244. * struct vmw_sg_table - Scatter/gather table for binding, with additional
  245. * device-specific information.
  246. *
  247. * @sgt: Pointer to a struct sg_table with binding information
  248. * @num_regions: Number of regions with device-address contiguous pages
  249. */
  250. struct vmw_sg_table {
  251. enum vmw_dma_map_mode mode;
  252. struct page **pages;
  253. const dma_addr_t *addrs;
  254. struct sg_table *sgt;
  255. unsigned long num_regions;
  256. unsigned long num_pages;
  257. };
  258. /**
  259. * struct vmw_piter - Page iterator that iterates over a list of pages
  260. * and DMA addresses that could be either a scatter-gather list or
  261. * arrays
  262. *
  263. * @pages: Array of page pointers to the pages.
  264. * @addrs: DMA addresses to the pages if coherent pages are used.
  265. * @iter: Scatter-gather page iterator. Current position in SG list.
  266. * @i: Current position in arrays.
  267. * @num_pages: Number of pages total.
  268. * @next: Function to advance the iterator. Returns false if past the list
  269. * of pages, true otherwise.
  270. * @dma_address: Function to return the DMA address of the current page.
  271. */
  272. struct vmw_piter {
  273. struct page **pages;
  274. const dma_addr_t *addrs;
  275. struct sg_page_iter iter;
  276. unsigned long i;
  277. unsigned long num_pages;
  278. bool (*next)(struct vmw_piter *);
  279. dma_addr_t (*dma_address)(struct vmw_piter *);
  280. struct page *(*page)(struct vmw_piter *);
  281. };
  282. /*
  283. * enum vmw_display_unit_type - Describes the display unit
  284. */
  285. enum vmw_display_unit_type {
  286. vmw_du_invalid = 0,
  287. vmw_du_legacy,
  288. vmw_du_screen_object,
  289. vmw_du_screen_target
  290. };
  291. struct vmw_validation_context;
  292. struct vmw_ctx_validation_info;
  293. /**
  294. * struct vmw_sw_context - Command submission context
  295. * @res_ht: Pointer hash table used to find validation duplicates
  296. * @kernel: Whether the command buffer originates from kernel code rather
  297. * than from user-space
  298. * @fp: If @kernel is false, points to the file of the client. Otherwise
  299. * NULL
  300. * @cmd_bounce: Command bounce buffer used for command validation before
  301. * copying to fifo space
  302. * @cmd_bounce_size: Current command bounce buffer size
  303. * @cur_query_bo: Current buffer object used as query result buffer
  304. * @bo_relocations: List of buffer object relocations
  305. * @res_relocations: List of resource relocations
  306. * @buf_start: Pointer to start of memory where command validation takes
  307. * place
  308. * @res_cache: Cache of recently looked up resources
  309. * @last_query_ctx: Last context that submitted a query
  310. * @needs_post_query_barrier: Whether a query barrier is needed after
  311. * command submission
  312. * @staged_bindings: Cached per-context binding tracker
  313. * @staged_bindings_inuse: Whether the cached per-context binding tracker
  314. * is in use
  315. * @staged_cmd_res: List of staged command buffer managed resources in this
  316. * command buffer
  317. * @ctx_list: List of context resources referenced in this command buffer
  318. * @dx_ctx_node: Validation metadata of the current DX context
  319. * @dx_query_mob: The MOB used for DX queries
  320. * @dx_query_ctx: The DX context used for the last DX query
  321. * @man: Pointer to the command buffer managed resource manager
  322. * @ctx: The validation context
  323. */
  324. struct vmw_sw_context{
  325. struct drm_open_hash res_ht;
  326. bool res_ht_initialized;
  327. bool kernel;
  328. struct vmw_fpriv *fp;
  329. uint32_t *cmd_bounce;
  330. uint32_t cmd_bounce_size;
  331. struct vmw_buffer_object *cur_query_bo;
  332. struct list_head bo_relocations;
  333. struct list_head res_relocations;
  334. uint32_t *buf_start;
  335. struct vmw_res_cache_entry res_cache[vmw_res_max];
  336. struct vmw_resource *last_query_ctx;
  337. bool needs_post_query_barrier;
  338. struct vmw_ctx_binding_state *staged_bindings;
  339. bool staged_bindings_inuse;
  340. struct list_head staged_cmd_res;
  341. struct list_head ctx_list;
  342. struct vmw_ctx_validation_info *dx_ctx_node;
  343. struct vmw_buffer_object *dx_query_mob;
  344. struct vmw_resource *dx_query_ctx;
  345. struct vmw_cmdbuf_res_manager *man;
  346. struct vmw_validation_context *ctx;
  347. };
  348. struct vmw_legacy_display;
  349. struct vmw_overlay;
  350. struct vmw_master {
  351. struct ttm_lock lock;
  352. };
  353. struct vmw_vga_topology_state {
  354. uint32_t width;
  355. uint32_t height;
  356. uint32_t primary;
  357. uint32_t pos_x;
  358. uint32_t pos_y;
  359. };
  360. /*
  361. * struct vmw_otable - Guest Memory OBject table metadata
  362. *
  363. * @size: Size of the table (page-aligned).
  364. * @page_table: Pointer to a struct vmw_mob holding the page table.
  365. */
  366. struct vmw_otable {
  367. unsigned long size;
  368. struct vmw_mob *page_table;
  369. bool enabled;
  370. };
  371. struct vmw_otable_batch {
  372. unsigned num_otables;
  373. struct vmw_otable *otables;
  374. struct vmw_resource *context;
  375. struct ttm_buffer_object *otable_bo;
  376. };
  377. enum {
  378. VMW_IRQTHREAD_FENCE,
  379. VMW_IRQTHREAD_CMDBUF,
  380. VMW_IRQTHREAD_MAX
  381. };
  382. struct vmw_private {
  383. struct ttm_bo_device bdev;
  384. struct ttm_bo_global_ref bo_global_ref;
  385. struct drm_global_reference mem_global_ref;
  386. struct vmw_fifo_state fifo;
  387. struct drm_device *dev;
  388. unsigned long vmw_chipset;
  389. unsigned int io_start;
  390. uint32_t vram_start;
  391. uint32_t vram_size;
  392. uint32_t prim_bb_mem;
  393. uint32_t mmio_start;
  394. uint32_t mmio_size;
  395. uint32_t fb_max_width;
  396. uint32_t fb_max_height;
  397. uint32_t texture_max_width;
  398. uint32_t texture_max_height;
  399. uint32_t stdu_max_width;
  400. uint32_t stdu_max_height;
  401. uint32_t initial_width;
  402. uint32_t initial_height;
  403. u32 *mmio_virt;
  404. uint32_t capabilities;
  405. uint32_t capabilities2;
  406. uint32_t max_gmr_ids;
  407. uint32_t max_gmr_pages;
  408. uint32_t max_mob_pages;
  409. uint32_t max_mob_size;
  410. uint32_t memory_size;
  411. bool has_gmr;
  412. bool has_mob;
  413. spinlock_t hw_lock;
  414. spinlock_t cap_lock;
  415. bool has_dx;
  416. bool assume_16bpp;
  417. bool has_sm4_1;
  418. /*
  419. * VGA registers.
  420. */
  421. struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
  422. uint32_t vga_width;
  423. uint32_t vga_height;
  424. uint32_t vga_bpp;
  425. uint32_t vga_bpl;
  426. uint32_t vga_pitchlock;
  427. uint32_t num_displays;
  428. /*
  429. * Currently requested_layout_mutex is used to protect the gui
  430. * positionig state in display unit. With that use case currently this
  431. * mutex is only taken during layout ioctl and atomic check_modeset.
  432. * Other display unit state can be protected with this mutex but that
  433. * needs careful consideration.
  434. */
  435. struct mutex requested_layout_mutex;
  436. /*
  437. * Framebuffer info.
  438. */
  439. void *fb_info;
  440. enum vmw_display_unit_type active_display_unit;
  441. struct vmw_legacy_display *ldu_priv;
  442. struct vmw_overlay *overlay_priv;
  443. struct drm_property *hotplug_mode_update_property;
  444. struct drm_property *implicit_placement_property;
  445. unsigned num_implicit;
  446. struct vmw_framebuffer *implicit_fb;
  447. struct mutex global_kms_state_mutex;
  448. spinlock_t cursor_lock;
  449. struct drm_atomic_state *suspend_state;
  450. /*
  451. * Context and surface management.
  452. */
  453. spinlock_t resource_lock;
  454. struct idr res_idr[vmw_res_max];
  455. /*
  456. * Block lastclose from racing with firstopen.
  457. */
  458. struct mutex init_mutex;
  459. /*
  460. * A resource manager for kernel-only surfaces and
  461. * contexts.
  462. */
  463. struct ttm_object_device *tdev;
  464. /*
  465. * Fencing and IRQs.
  466. */
  467. atomic_t marker_seq;
  468. wait_queue_head_t fence_queue;
  469. wait_queue_head_t fifo_queue;
  470. spinlock_t waiter_lock;
  471. int fence_queue_waiters; /* Protected by waiter_lock */
  472. int goal_queue_waiters; /* Protected by waiter_lock */
  473. int cmdbuf_waiters; /* Protected by waiter_lock */
  474. int error_waiters; /* Protected by waiter_lock */
  475. int fifo_queue_waiters; /* Protected by waiter_lock */
  476. uint32_t last_read_seqno;
  477. struct vmw_fence_manager *fman;
  478. uint32_t irq_mask; /* Updates protected by waiter_lock */
  479. /*
  480. * Device state
  481. */
  482. uint32_t traces_state;
  483. uint32_t enable_state;
  484. uint32_t config_done_state;
  485. /**
  486. * Execbuf
  487. */
  488. /**
  489. * Protected by the cmdbuf mutex.
  490. */
  491. struct vmw_sw_context ctx;
  492. struct mutex cmdbuf_mutex;
  493. struct mutex binding_mutex;
  494. /**
  495. * Operating mode.
  496. */
  497. bool stealth;
  498. bool enable_fb;
  499. spinlock_t svga_lock;
  500. /**
  501. * Master management.
  502. */
  503. struct vmw_master *active_master;
  504. struct vmw_master fbdev_master;
  505. struct notifier_block pm_nb;
  506. bool refuse_hibernation;
  507. bool suspend_locked;
  508. struct mutex release_mutex;
  509. atomic_t num_fifo_resources;
  510. /*
  511. * Replace this with an rwsem as soon as we have down_xx_interruptible()
  512. */
  513. struct ttm_lock reservation_sem;
  514. /*
  515. * Query processing. These members
  516. * are protected by the cmdbuf mutex.
  517. */
  518. struct vmw_buffer_object *dummy_query_bo;
  519. struct vmw_buffer_object *pinned_bo;
  520. uint32_t query_cid;
  521. uint32_t query_cid_valid;
  522. bool dummy_query_bo_pinned;
  523. /*
  524. * Surface swapping. The "surface_lru" list is protected by the
  525. * resource lock in order to be able to destroy a surface and take
  526. * it off the lru atomically. "used_memory_size" is currently
  527. * protected by the cmdbuf mutex for simplicity.
  528. */
  529. struct list_head res_lru[vmw_res_max];
  530. uint32_t used_memory_size;
  531. /*
  532. * DMA mapping stuff.
  533. */
  534. enum vmw_dma_map_mode map_mode;
  535. /*
  536. * Guest Backed stuff
  537. */
  538. struct vmw_otable_batch otable_batch;
  539. struct vmw_cmdbuf_man *cman;
  540. DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
  541. /* Validation memory reservation */
  542. struct vmw_validation_mem vvm;
  543. };
  544. static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
  545. {
  546. return container_of(res, struct vmw_surface, res);
  547. }
  548. static inline struct vmw_private *vmw_priv(struct drm_device *dev)
  549. {
  550. return (struct vmw_private *)dev->dev_private;
  551. }
  552. static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
  553. {
  554. return (struct vmw_fpriv *)file_priv->driver_priv;
  555. }
  556. static inline struct vmw_master *vmw_master(struct drm_master *master)
  557. {
  558. return (struct vmw_master *) master->driver_priv;
  559. }
  560. /*
  561. * The locking here is fine-grained, so that it is performed once
  562. * for every read- and write operation. This is of course costly, but we
  563. * don't perform much register access in the timing critical paths anyway.
  564. * Instead we have the extra benefit of being sure that we don't forget
  565. * the hw lock around register accesses.
  566. */
  567. static inline void vmw_write(struct vmw_private *dev_priv,
  568. unsigned int offset, uint32_t value)
  569. {
  570. spin_lock(&dev_priv->hw_lock);
  571. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  572. outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
  573. spin_unlock(&dev_priv->hw_lock);
  574. }
  575. static inline uint32_t vmw_read(struct vmw_private *dev_priv,
  576. unsigned int offset)
  577. {
  578. u32 val;
  579. spin_lock(&dev_priv->hw_lock);
  580. outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  581. val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
  582. spin_unlock(&dev_priv->hw_lock);
  583. return val;
  584. }
  585. extern void vmw_svga_enable(struct vmw_private *dev_priv);
  586. extern void vmw_svga_disable(struct vmw_private *dev_priv);
  587. /**
  588. * GMR utilities - vmwgfx_gmr.c
  589. */
  590. extern int vmw_gmr_bind(struct vmw_private *dev_priv,
  591. const struct vmw_sg_table *vsgt,
  592. unsigned long num_pages,
  593. int gmr_id);
  594. extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
  595. /**
  596. * Resource utilities - vmwgfx_resource.c
  597. */
  598. struct vmw_user_resource_conv;
  599. extern void vmw_resource_unreference(struct vmw_resource **p_res);
  600. extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
  601. extern struct vmw_resource *
  602. vmw_resource_reference_unless_doomed(struct vmw_resource *res);
  603. extern int vmw_resource_validate(struct vmw_resource *res, bool intr);
  604. extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
  605. bool no_backup);
  606. extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
  607. extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
  608. struct ttm_object_file *tfile,
  609. uint32_t handle,
  610. struct vmw_surface **out_surf,
  611. struct vmw_buffer_object **out_buf);
  612. extern int vmw_user_resource_lookup_handle(
  613. struct vmw_private *dev_priv,
  614. struct ttm_object_file *tfile,
  615. uint32_t handle,
  616. const struct vmw_user_resource_conv *converter,
  617. struct vmw_resource **p_res);
  618. extern struct vmw_resource *
  619. vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv,
  620. struct ttm_object_file *tfile,
  621. uint32_t handle,
  622. const struct vmw_user_resource_conv *
  623. converter);
  624. extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  625. struct drm_file *file_priv);
  626. extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  627. struct drm_file *file_priv);
  628. extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  629. struct ttm_object_file *tfile,
  630. uint32_t *inout_id,
  631. struct vmw_resource **out);
  632. extern void vmw_resource_unreserve(struct vmw_resource *res,
  633. bool switch_backup,
  634. struct vmw_buffer_object *new_backup,
  635. unsigned long new_backup_offset);
  636. extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
  637. struct ttm_mem_reg *mem);
  638. extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);
  639. extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
  640. extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
  641. /**
  642. * vmw_user_resource_noref_release - release a user resource pointer looked up
  643. * without reference
  644. */
  645. static inline void vmw_user_resource_noref_release(void)
  646. {
  647. ttm_base_object_noref_release();
  648. }
  649. /**
  650. * Buffer object helper functions - vmwgfx_bo.c
  651. */
  652. extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv,
  653. struct vmw_buffer_object *bo,
  654. struct ttm_placement *placement,
  655. bool interruptible);
  656. extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
  657. struct vmw_buffer_object *buf,
  658. bool interruptible);
  659. extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
  660. struct vmw_buffer_object *buf,
  661. bool interruptible);
  662. extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv,
  663. struct vmw_buffer_object *bo,
  664. bool interruptible);
  665. extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
  666. struct vmw_buffer_object *bo,
  667. bool interruptible);
  668. extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
  669. SVGAGuestPtr *ptr);
  670. extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
  671. extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
  672. extern int vmw_bo_init(struct vmw_private *dev_priv,
  673. struct vmw_buffer_object *vmw_bo,
  674. size_t size, struct ttm_placement *placement,
  675. bool interuptable,
  676. void (*bo_free)(struct ttm_buffer_object *bo));
  677. extern int vmw_user_bo_verify_access(struct ttm_buffer_object *bo,
  678. struct ttm_object_file *tfile);
  679. extern int vmw_user_bo_alloc(struct vmw_private *dev_priv,
  680. struct ttm_object_file *tfile,
  681. uint32_t size,
  682. bool shareable,
  683. uint32_t *handle,
  684. struct vmw_buffer_object **p_dma_buf,
  685. struct ttm_base_object **p_base);
  686. extern int vmw_user_bo_reference(struct ttm_object_file *tfile,
  687. struct vmw_buffer_object *dma_buf,
  688. uint32_t *handle);
  689. extern int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data,
  690. struct drm_file *file_priv);
  691. extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
  692. struct drm_file *file_priv);
  693. extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
  694. struct drm_file *file_priv);
  695. extern int vmw_user_bo_lookup(struct ttm_object_file *tfile,
  696. uint32_t id, struct vmw_buffer_object **out,
  697. struct ttm_base_object **base);
  698. extern void vmw_bo_fence_single(struct ttm_buffer_object *bo,
  699. struct vmw_fence_obj *fence);
  700. extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo);
  701. extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
  702. extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
  703. struct ttm_mem_reg *mem);
  704. extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
  705. extern struct vmw_buffer_object *
  706. vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle);
  707. /**
  708. * vmw_user_bo_noref_release - release a buffer object pointer looked up
  709. * without reference
  710. */
  711. static inline void vmw_user_bo_noref_release(void)
  712. {
  713. ttm_base_object_noref_release();
  714. }
  715. /**
  716. * Misc Ioctl functionality - vmwgfx_ioctl.c
  717. */
  718. extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  719. struct drm_file *file_priv);
  720. extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
  721. struct drm_file *file_priv);
  722. extern int vmw_present_ioctl(struct drm_device *dev, void *data,
  723. struct drm_file *file_priv);
  724. extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
  725. struct drm_file *file_priv);
  726. extern __poll_t vmw_fops_poll(struct file *filp,
  727. struct poll_table_struct *wait);
  728. extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
  729. size_t count, loff_t *offset);
  730. /**
  731. * Fifo utilities - vmwgfx_fifo.c
  732. */
  733. extern int vmw_fifo_init(struct vmw_private *dev_priv,
  734. struct vmw_fifo_state *fifo);
  735. extern void vmw_fifo_release(struct vmw_private *dev_priv,
  736. struct vmw_fifo_state *fifo);
  737. extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
  738. extern void *
  739. vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
  740. extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
  741. extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
  742. extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
  743. uint32_t *seqno);
  744. extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
  745. extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
  746. extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
  747. extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
  748. extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
  749. uint32_t cid);
  750. extern int vmw_fifo_flush(struct vmw_private *dev_priv,
  751. bool interruptible);
  752. /**
  753. * TTM glue - vmwgfx_ttm_glue.c
  754. */
  755. extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
  756. extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
  757. extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
  758. extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv,
  759. size_t gran);
  760. /**
  761. * TTM buffer object driver - vmwgfx_ttm_buffer.c
  762. */
  763. extern const size_t vmw_tt_size;
  764. extern struct ttm_placement vmw_vram_placement;
  765. extern struct ttm_placement vmw_vram_ne_placement;
  766. extern struct ttm_placement vmw_vram_sys_placement;
  767. extern struct ttm_placement vmw_vram_gmr_placement;
  768. extern struct ttm_placement vmw_vram_gmr_ne_placement;
  769. extern struct ttm_placement vmw_sys_placement;
  770. extern struct ttm_placement vmw_sys_ne_placement;
  771. extern struct ttm_placement vmw_evictable_placement;
  772. extern struct ttm_placement vmw_srf_placement;
  773. extern struct ttm_placement vmw_mob_placement;
  774. extern struct ttm_placement vmw_mob_ne_placement;
  775. extern struct ttm_placement vmw_nonfixed_placement;
  776. extern struct ttm_bo_driver vmw_bo_driver;
  777. extern int vmw_dma_quiescent(struct drm_device *dev);
  778. extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
  779. extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
  780. extern const struct vmw_sg_table *
  781. vmw_bo_sg_table(struct ttm_buffer_object *bo);
  782. extern void vmw_piter_start(struct vmw_piter *viter,
  783. const struct vmw_sg_table *vsgt,
  784. unsigned long p_offs);
  785. /**
  786. * vmw_piter_next - Advance the iterator one page.
  787. *
  788. * @viter: Pointer to the iterator to advance.
  789. *
  790. * Returns false if past the list of pages, true otherwise.
  791. */
  792. static inline bool vmw_piter_next(struct vmw_piter *viter)
  793. {
  794. return viter->next(viter);
  795. }
  796. /**
  797. * vmw_piter_dma_addr - Return the DMA address of the current page.
  798. *
  799. * @viter: Pointer to the iterator
  800. *
  801. * Returns the DMA address of the page pointed to by @viter.
  802. */
  803. static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
  804. {
  805. return viter->dma_address(viter);
  806. }
  807. /**
  808. * vmw_piter_page - Return a pointer to the current page.
  809. *
  810. * @viter: Pointer to the iterator
  811. *
  812. * Returns the DMA address of the page pointed to by @viter.
  813. */
  814. static inline struct page *vmw_piter_page(struct vmw_piter *viter)
  815. {
  816. return viter->page(viter);
  817. }
  818. /**
  819. * Command submission - vmwgfx_execbuf.c
  820. */
  821. extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
  822. struct drm_file *file_priv, size_t size);
  823. extern int vmw_execbuf_process(struct drm_file *file_priv,
  824. struct vmw_private *dev_priv,
  825. void __user *user_commands,
  826. void *kernel_commands,
  827. uint32_t command_size,
  828. uint64_t throttle_us,
  829. uint32_t dx_context_handle,
  830. struct drm_vmw_fence_rep __user
  831. *user_fence_rep,
  832. struct vmw_fence_obj **out_fence,
  833. uint32_t flags);
  834. extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
  835. struct vmw_fence_obj *fence);
  836. extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
  837. extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
  838. struct vmw_private *dev_priv,
  839. struct vmw_fence_obj **p_fence,
  840. uint32_t *p_handle);
  841. extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
  842. struct vmw_fpriv *vmw_fp,
  843. int ret,
  844. struct drm_vmw_fence_rep __user
  845. *user_fence_rep,
  846. struct vmw_fence_obj *fence,
  847. uint32_t fence_handle,
  848. int32_t out_fence_fd,
  849. struct sync_file *sync_file);
  850. bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
  851. /**
  852. * IRQs and wating - vmwgfx_irq.c
  853. */
  854. extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
  855. uint32_t seqno, bool interruptible,
  856. unsigned long timeout);
  857. extern int vmw_irq_install(struct drm_device *dev, int irq);
  858. extern void vmw_irq_uninstall(struct drm_device *dev);
  859. extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
  860. uint32_t seqno);
  861. extern int vmw_fallback_wait(struct vmw_private *dev_priv,
  862. bool lazy,
  863. bool fifo_idle,
  864. uint32_t seqno,
  865. bool interruptible,
  866. unsigned long timeout);
  867. extern void vmw_update_seqno(struct vmw_private *dev_priv,
  868. struct vmw_fifo_state *fifo_state);
  869. extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
  870. extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
  871. extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
  872. extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
  873. extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
  874. int *waiter_count);
  875. extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
  876. u32 flag, int *waiter_count);
  877. /**
  878. * Rudimentary fence-like objects currently used only for throttling -
  879. * vmwgfx_marker.c
  880. */
  881. extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
  882. extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
  883. extern int vmw_marker_push(struct vmw_marker_queue *queue,
  884. uint32_t seqno);
  885. extern int vmw_marker_pull(struct vmw_marker_queue *queue,
  886. uint32_t signaled_seqno);
  887. extern int vmw_wait_lag(struct vmw_private *dev_priv,
  888. struct vmw_marker_queue *queue, uint32_t us);
  889. /**
  890. * Kernel framebuffer - vmwgfx_fb.c
  891. */
  892. int vmw_fb_init(struct vmw_private *vmw_priv);
  893. int vmw_fb_close(struct vmw_private *dev_priv);
  894. int vmw_fb_off(struct vmw_private *vmw_priv);
  895. int vmw_fb_on(struct vmw_private *vmw_priv);
  896. /**
  897. * Kernel modesetting - vmwgfx_kms.c
  898. */
  899. int vmw_kms_init(struct vmw_private *dev_priv);
  900. int vmw_kms_close(struct vmw_private *dev_priv);
  901. int vmw_kms_save_vga(struct vmw_private *vmw_priv);
  902. int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
  903. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  904. struct drm_file *file_priv);
  905. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
  906. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  907. struct ttm_object_file *tfile,
  908. struct ttm_buffer_object *bo,
  909. SVGA3dCmdHeader *header);
  910. int vmw_kms_write_svga(struct vmw_private *vmw_priv,
  911. unsigned width, unsigned height, unsigned pitch,
  912. unsigned bpp, unsigned depth);
  913. void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
  914. bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
  915. uint32_t pitch,
  916. uint32_t height);
  917. u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
  918. int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe);
  919. void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe);
  920. int vmw_kms_present(struct vmw_private *dev_priv,
  921. struct drm_file *file_priv,
  922. struct vmw_framebuffer *vfb,
  923. struct vmw_surface *surface,
  924. uint32_t sid, int32_t destX, int32_t destY,
  925. struct drm_vmw_rect *clips,
  926. uint32_t num_clips);
  927. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  928. struct drm_file *file_priv);
  929. void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
  930. int vmw_kms_suspend(struct drm_device *dev);
  931. int vmw_kms_resume(struct drm_device *dev);
  932. void vmw_kms_lost_device(struct drm_device *dev);
  933. int vmw_dumb_create(struct drm_file *file_priv,
  934. struct drm_device *dev,
  935. struct drm_mode_create_dumb *args);
  936. int vmw_dumb_map_offset(struct drm_file *file_priv,
  937. struct drm_device *dev, uint32_t handle,
  938. uint64_t *offset);
  939. int vmw_dumb_destroy(struct drm_file *file_priv,
  940. struct drm_device *dev,
  941. uint32_t handle);
  942. extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
  943. extern void vmw_resource_unpin(struct vmw_resource *res);
  944. extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
  945. /**
  946. * Overlay control - vmwgfx_overlay.c
  947. */
  948. int vmw_overlay_init(struct vmw_private *dev_priv);
  949. int vmw_overlay_close(struct vmw_private *dev_priv);
  950. int vmw_overlay_ioctl(struct drm_device *dev, void *data,
  951. struct drm_file *file_priv);
  952. int vmw_overlay_stop_all(struct vmw_private *dev_priv);
  953. int vmw_overlay_resume_all(struct vmw_private *dev_priv);
  954. int vmw_overlay_pause_all(struct vmw_private *dev_priv);
  955. int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
  956. int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
  957. int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
  958. int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  959. /**
  960. * GMR Id manager
  961. */
  962. extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
  963. /**
  964. * Prime - vmwgfx_prime.c
  965. */
  966. extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
  967. extern int vmw_prime_fd_to_handle(struct drm_device *dev,
  968. struct drm_file *file_priv,
  969. int fd, u32 *handle);
  970. extern int vmw_prime_handle_to_fd(struct drm_device *dev,
  971. struct drm_file *file_priv,
  972. uint32_t handle, uint32_t flags,
  973. int *prime_fd);
  974. /*
  975. * MemoryOBject management - vmwgfx_mob.c
  976. */
  977. struct vmw_mob;
  978. extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
  979. const struct vmw_sg_table *vsgt,
  980. unsigned long num_data_pages, int32_t mob_id);
  981. extern void vmw_mob_unbind(struct vmw_private *dev_priv,
  982. struct vmw_mob *mob);
  983. extern void vmw_mob_destroy(struct vmw_mob *mob);
  984. extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
  985. extern int vmw_otables_setup(struct vmw_private *dev_priv);
  986. extern void vmw_otables_takedown(struct vmw_private *dev_priv);
  987. /*
  988. * Context management - vmwgfx_context.c
  989. */
  990. extern const struct vmw_user_resource_conv *user_context_converter;
  991. extern int vmw_context_check(struct vmw_private *dev_priv,
  992. struct ttm_object_file *tfile,
  993. int id,
  994. struct vmw_resource **p_res);
  995. extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
  996. struct drm_file *file_priv);
  997. extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
  998. struct drm_file *file_priv);
  999. extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
  1000. struct drm_file *file_priv);
  1001. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  1002. extern struct vmw_cmdbuf_res_manager *
  1003. vmw_context_res_man(struct vmw_resource *ctx);
  1004. extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
  1005. SVGACOTableType cotable_type);
  1006. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  1007. struct vmw_ctx_binding_state;
  1008. extern struct vmw_ctx_binding_state *
  1009. vmw_context_binding_state(struct vmw_resource *ctx);
  1010. extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
  1011. bool readback);
  1012. extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
  1013. struct vmw_buffer_object *mob);
  1014. extern struct vmw_buffer_object *
  1015. vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
  1016. /*
  1017. * Surface management - vmwgfx_surface.c
  1018. */
  1019. extern const struct vmw_user_resource_conv *user_surface_converter;
  1020. extern void vmw_surface_res_free(struct vmw_resource *res);
  1021. extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
  1022. struct drm_file *file_priv);
  1023. extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
  1024. struct drm_file *file_priv);
  1025. extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
  1026. struct drm_file *file_priv);
  1027. extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
  1028. struct drm_file *file_priv);
  1029. extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
  1030. struct drm_file *file_priv);
  1031. extern int vmw_surface_check(struct vmw_private *dev_priv,
  1032. struct ttm_object_file *tfile,
  1033. uint32_t handle, int *id);
  1034. extern int vmw_surface_validate(struct vmw_private *dev_priv,
  1035. struct vmw_surface *srf);
  1036. int vmw_surface_gb_priv_define(struct drm_device *dev,
  1037. uint32_t user_accounting_size,
  1038. SVGA3dSurfaceAllFlags svga3d_flags,
  1039. SVGA3dSurfaceFormat format,
  1040. bool for_scanout,
  1041. uint32_t num_mip_levels,
  1042. uint32_t multisample_count,
  1043. uint32_t array_size,
  1044. struct drm_vmw_size size,
  1045. SVGA3dMSPattern multisample_pattern,
  1046. SVGA3dMSQualityLevel quality_level,
  1047. struct vmw_surface **srf_out);
  1048. extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
  1049. void *data,
  1050. struct drm_file *file_priv);
  1051. extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
  1052. void *data,
  1053. struct drm_file *file_priv);
  1054. /*
  1055. * Shader management - vmwgfx_shader.c
  1056. */
  1057. extern const struct vmw_user_resource_conv *user_shader_converter;
  1058. extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
  1059. struct drm_file *file_priv);
  1060. extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
  1061. struct drm_file *file_priv);
  1062. extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
  1063. struct vmw_cmdbuf_res_manager *man,
  1064. u32 user_key, const void *bytecode,
  1065. SVGA3dShaderType shader_type,
  1066. size_t size,
  1067. struct list_head *list);
  1068. extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
  1069. u32 user_key, SVGA3dShaderType shader_type,
  1070. struct list_head *list);
  1071. extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
  1072. struct vmw_resource *ctx,
  1073. u32 user_key,
  1074. SVGA3dShaderType shader_type,
  1075. struct list_head *list);
  1076. extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
  1077. struct list_head *list,
  1078. bool readback);
  1079. extern struct vmw_resource *
  1080. vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
  1081. u32 user_key, SVGA3dShaderType shader_type);
  1082. /*
  1083. * Command buffer managed resources - vmwgfx_cmdbuf_res.c
  1084. */
  1085. extern struct vmw_cmdbuf_res_manager *
  1086. vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
  1087. extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
  1088. extern size_t vmw_cmdbuf_res_man_size(void);
  1089. extern struct vmw_resource *
  1090. vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
  1091. enum vmw_cmdbuf_res_type res_type,
  1092. u32 user_key);
  1093. extern void vmw_cmdbuf_res_revert(struct list_head *list);
  1094. extern void vmw_cmdbuf_res_commit(struct list_head *list);
  1095. extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
  1096. enum vmw_cmdbuf_res_type res_type,
  1097. u32 user_key,
  1098. struct vmw_resource *res,
  1099. struct list_head *list);
  1100. extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
  1101. enum vmw_cmdbuf_res_type res_type,
  1102. u32 user_key,
  1103. struct list_head *list,
  1104. struct vmw_resource **res);
  1105. /*
  1106. * COTable management - vmwgfx_cotable.c
  1107. */
  1108. extern const SVGACOTableType vmw_cotable_scrub_order[];
  1109. extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
  1110. struct vmw_resource *ctx,
  1111. u32 type);
  1112. extern int vmw_cotable_notify(struct vmw_resource *res, int id);
  1113. extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
  1114. extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
  1115. struct list_head *head);
  1116. /*
  1117. * Command buffer managerment vmwgfx_cmdbuf.c
  1118. */
  1119. struct vmw_cmdbuf_man;
  1120. struct vmw_cmdbuf_header;
  1121. extern struct vmw_cmdbuf_man *
  1122. vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
  1123. extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
  1124. size_t size, size_t default_size);
  1125. extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
  1126. extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
  1127. extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
  1128. unsigned long timeout);
  1129. extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
  1130. int ctx_id, bool interruptible,
  1131. struct vmw_cmdbuf_header *header);
  1132. extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
  1133. struct vmw_cmdbuf_header *header,
  1134. bool flush);
  1135. extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
  1136. size_t size, bool interruptible,
  1137. struct vmw_cmdbuf_header **p_header);
  1138. extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
  1139. extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
  1140. bool interruptible);
  1141. extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
  1142. /* CPU blit utilities - vmwgfx_blit.c */
  1143. /**
  1144. * struct vmw_diff_cpy - CPU blit information structure
  1145. *
  1146. * @rect: The output bounding box rectangle.
  1147. * @line: The current line of the blit.
  1148. * @line_offset: Offset of the current line segment.
  1149. * @cpp: Bytes per pixel (granularity information).
  1150. * @memcpy: Which memcpy function to use.
  1151. */
  1152. struct vmw_diff_cpy {
  1153. struct drm_rect rect;
  1154. size_t line;
  1155. size_t line_offset;
  1156. int cpp;
  1157. void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
  1158. size_t n);
  1159. };
  1160. #define VMW_CPU_BLIT_INITIALIZER { \
  1161. .do_cpy = vmw_memcpy, \
  1162. }
  1163. #define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \
  1164. .line = 0, \
  1165. .line_offset = 0, \
  1166. .rect = { .x1 = INT_MAX/2, \
  1167. .y1 = INT_MAX/2, \
  1168. .x2 = INT_MIN/2, \
  1169. .y2 = INT_MIN/2 \
  1170. }, \
  1171. .cpp = _cpp, \
  1172. .do_cpy = vmw_diff_memcpy, \
  1173. }
  1174. void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
  1175. size_t n);
  1176. void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
  1177. int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
  1178. u32 dst_offset, u32 dst_stride,
  1179. struct ttm_buffer_object *src,
  1180. u32 src_offset, u32 src_stride,
  1181. u32 w, u32 h,
  1182. struct vmw_diff_cpy *diff);
  1183. /* Host messaging -vmwgfx_msg.c: */
  1184. int vmw_host_get_guestinfo(const char *guest_info_param,
  1185. char *buffer, size_t *length);
  1186. int vmw_host_log(const char *log);
  1187. /**
  1188. * Inline helper functions
  1189. */
  1190. static inline void vmw_surface_unreference(struct vmw_surface **srf)
  1191. {
  1192. struct vmw_surface *tmp_srf = *srf;
  1193. struct vmw_resource *res = &tmp_srf->res;
  1194. *srf = NULL;
  1195. vmw_resource_unreference(&res);
  1196. }
  1197. static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
  1198. {
  1199. (void) vmw_resource_reference(&srf->res);
  1200. return srf;
  1201. }
  1202. static inline void vmw_bo_unreference(struct vmw_buffer_object **buf)
  1203. {
  1204. struct vmw_buffer_object *tmp_buf = *buf;
  1205. *buf = NULL;
  1206. if (tmp_buf != NULL) {
  1207. struct ttm_buffer_object *bo = &tmp_buf->base;
  1208. ttm_bo_unref(&bo);
  1209. }
  1210. }
  1211. static inline struct vmw_buffer_object *
  1212. vmw_bo_reference(struct vmw_buffer_object *buf)
  1213. {
  1214. if (ttm_bo_reference(&buf->base))
  1215. return buf;
  1216. return NULL;
  1217. }
  1218. static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
  1219. {
  1220. return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
  1221. }
  1222. static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
  1223. {
  1224. atomic_inc(&dev_priv->num_fifo_resources);
  1225. }
  1226. static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
  1227. {
  1228. atomic_dec(&dev_priv->num_fifo_resources);
  1229. }
  1230. /**
  1231. * vmw_mmio_read - Perform a MMIO read from volatile memory
  1232. *
  1233. * @addr: The address to read from
  1234. *
  1235. * This function is intended to be equivalent to ioread32() on
  1236. * memremap'd memory, but without byteswapping.
  1237. */
  1238. static inline u32 vmw_mmio_read(u32 *addr)
  1239. {
  1240. return READ_ONCE(*addr);
  1241. }
  1242. /**
  1243. * vmw_mmio_write - Perform a MMIO write to volatile memory
  1244. *
  1245. * @addr: The address to write to
  1246. *
  1247. * This function is intended to be equivalent to iowrite32 on
  1248. * memremap'd memory, but without byteswapping.
  1249. */
  1250. static inline void vmw_mmio_write(u32 value, u32 *addr)
  1251. {
  1252. WRITE_ONCE(*addr, value);
  1253. }
  1254. #endif