vmwgfx_drv.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /**************************************************************************
  3. *
  4. * Copyright (c) 2009-2024 Broadcom. All Rights Reserved. The term
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  22. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  23. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  24. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  25. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. **************************************************************************/
  28. #ifndef _VMWGFX_DRV_H_
  29. #define _VMWGFX_DRV_H_
  30. #include <linux/suspend.h>
  31. #include <linux/sync_file.h>
  32. #include <linux/hashtable.h>
  33. #include <drm/drm_auth.h>
  34. #include <drm/drm_device.h>
  35. #include <drm/drm_file.h>
  36. #include <drm/drm_rect.h>
  37. #include <drm/ttm/ttm_execbuf_util.h>
  38. #include <drm/ttm/ttm_tt.h>
  39. #include <drm/ttm/ttm_placement.h>
  40. #include <drm/ttm/ttm_bo.h>
  41. #include "ttm_object.h"
  42. #include "vmwgfx_fence.h"
  43. #include "vmwgfx_reg.h"
  44. #include "vmwgfx_validation.h"
  45. /*
  46. * FIXME: vmwgfx_drm.h needs to be last due to dependencies.
  47. * uapi headers should not depend on header files outside uapi/.
  48. */
  49. #include <drm/vmwgfx_drm.h>
  50. #define VMWGFX_DRIVER_NAME "vmwgfx"
  51. #define VMWGFX_DRIVER_DATE "20211206"
  52. #define VMWGFX_DRIVER_MAJOR 2
  53. #define VMWGFX_DRIVER_MINOR 20
  54. #define VMWGFX_DRIVER_PATCHLEVEL 0
  55. #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
  56. #define VMWGFX_NUM_DISPLAY_UNITS 8
  57. #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
  58. #define VMWGFX_MIN_INITIAL_WIDTH 1280
  59. #define VMWGFX_MIN_INITIAL_HEIGHT 800
  60. #define VMWGFX_PCI_ID_SVGA2 0x0405
  61. #define VMWGFX_PCI_ID_SVGA3 0x0406
  62. /*
  63. * This has to match get_count_order(SVGA_IRQFLAG_MAX)
  64. */
  65. #define VMWGFX_MAX_NUM_IRQS 6
  66. /*
  67. * Perhaps we should have sysfs entries for these.
  68. */
  69. #define VMWGFX_NUM_GB_CONTEXT 256
  70. #define VMWGFX_NUM_GB_SHADER 20000
  71. #define VMWGFX_NUM_GB_SURFACE 32768
  72. #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_NUM_DISPLAY_UNITS
  73. #define VMWGFX_NUM_DXCONTEXT 256
  74. #define VMWGFX_NUM_DXQUERY 512
  75. #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
  76. VMWGFX_NUM_GB_SHADER +\
  77. VMWGFX_NUM_GB_SURFACE +\
  78. VMWGFX_NUM_GB_SCREEN_TARGET)
  79. #define VMW_PL_GMR (TTM_PL_PRIV + 0)
  80. #define VMW_PL_MOB (TTM_PL_PRIV + 1)
  81. #define VMW_PL_SYSTEM (TTM_PL_PRIV + 2)
  82. #define VMW_RES_CONTEXT ttm_driver_type0
  83. #define VMW_RES_SURFACE ttm_driver_type1
  84. #define VMW_RES_STREAM ttm_driver_type2
  85. #define VMW_RES_FENCE ttm_driver_type3
  86. #define VMW_RES_SHADER ttm_driver_type4
  87. #define VMW_RES_HT_ORDER 12
  88. #define VMW_CURSOR_SNOOP_FORMAT SVGA3D_A8R8G8B8
  89. #define VMW_CURSOR_SNOOP_WIDTH 64
  90. #define VMW_CURSOR_SNOOP_HEIGHT 64
  91. #define MKSSTAT_CAPACITY_LOG2 5U
  92. #define MKSSTAT_CAPACITY (1U << MKSSTAT_CAPACITY_LOG2)
  93. struct vmw_fpriv {
  94. struct ttm_object_file *tfile;
  95. bool gb_aware; /* user-space is guest-backed aware */
  96. };
  97. struct vmwgfx_hash_item {
  98. struct hlist_node head;
  99. unsigned long key;
  100. };
  101. struct vmw_res_func;
  102. /**
  103. * struct vmw-resource - base class for hardware resources
  104. *
  105. * @kref: For refcounting.
  106. * @dev_priv: Pointer to the device private for this resource. Immutable.
  107. * @id: Device id. Protected by @dev_priv::resource_lock.
  108. * @guest_memory_size: Guest memory buffer size. Immutable.
  109. * @res_dirty: Resource contains data not yet in the guest memory buffer.
  110. * Protected by resource reserved.
  111. * @guest_memory_dirty: Guest memory buffer contains data not yet in the HW
  112. * resource. Protected by resource reserved.
  113. * @coherent: Emulate coherency by tracking vm accesses.
  114. * @guest_memory_bo: The guest memory buffer if any. Protected by resource
  115. * reserved.
  116. * @guest_memory_offset: Offset into the guest memory buffer if any. Protected
  117. * by resource reserved. Note that only a few resource types can have a
  118. * @guest_memory_offset different from zero.
  119. * @pin_count: The pin count for this resource. A pinned resource has a
  120. * pin-count greater than zero. It is not on the resource LRU lists and its
  121. * guest memory buffer is pinned. Hence it can't be evicted.
  122. * @func: Method vtable for this resource. Immutable.
  123. * @mob_node; Node for the MOB guest memory rbtree. Protected by
  124. * @guest_memory_bo reserved.
  125. * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
  126. * @binding_head: List head for the context binding list. Protected by
  127. * the @dev_priv::binding_mutex
  128. * @res_free: The resource destructor.
  129. * @hw_destroy: Callback to destroy the resource on the device, as part of
  130. * resource destruction.
  131. */
  132. struct vmw_bo;
  133. struct vmw_bo;
  134. struct vmw_resource_dirty;
  135. struct vmw_resource {
  136. struct kref kref;
  137. struct vmw_private *dev_priv;
  138. int id;
  139. u32 used_prio;
  140. unsigned long guest_memory_size;
  141. u32 res_dirty : 1;
  142. u32 guest_memory_dirty : 1;
  143. u32 coherent : 1;
  144. struct vmw_bo *guest_memory_bo;
  145. unsigned long guest_memory_offset;
  146. unsigned long pin_count;
  147. const struct vmw_res_func *func;
  148. struct rb_node mob_node;
  149. struct list_head lru_head;
  150. struct list_head binding_head;
  151. struct vmw_resource_dirty *dirty;
  152. void (*res_free) (struct vmw_resource *res);
  153. void (*hw_destroy) (struct vmw_resource *res);
  154. };
  155. /*
  156. * Resources that are managed using ioctls.
  157. */
  158. enum vmw_res_type {
  159. vmw_res_context,
  160. vmw_res_surface,
  161. vmw_res_stream,
  162. vmw_res_shader,
  163. vmw_res_dx_context,
  164. vmw_res_cotable,
  165. vmw_res_view,
  166. vmw_res_streamoutput,
  167. vmw_res_max
  168. };
  169. /*
  170. * Resources that are managed using command streams.
  171. */
  172. enum vmw_cmdbuf_res_type {
  173. vmw_cmdbuf_res_shader,
  174. vmw_cmdbuf_res_view,
  175. vmw_cmdbuf_res_streamoutput
  176. };
  177. struct vmw_cmdbuf_res_manager;
  178. struct vmw_cursor_snooper {
  179. size_t age;
  180. uint32_t *image;
  181. };
  182. struct vmw_framebuffer;
  183. struct vmw_surface_offset;
  184. /**
  185. * struct vmw_surface_metadata - Metadata describing a surface.
  186. *
  187. * @flags: Device flags.
  188. * @format: Surface SVGA3D_x format.
  189. * @mip_levels: Mip level for each face. For GB first index is used only.
  190. * @multisample_count: Sample count.
  191. * @multisample_pattern: Sample patterns.
  192. * @quality_level: Quality level.
  193. * @autogen_filter: Filter for automatically generated mipmaps.
  194. * @array_size: Number of array elements for a 1D/2D texture. For cubemap
  195. texture number of faces * array_size. This should be 0 for pre
  196. SM4 device.
  197. * @buffer_byte_stride: Buffer byte stride.
  198. * @num_sizes: Size of @sizes. For GB surface this should always be 1.
  199. * @base_size: Surface dimension.
  200. * @sizes: Array representing mip sizes. Legacy only.
  201. * @scanout: Whether this surface will be used for scanout.
  202. *
  203. * This tracks metadata for both legacy and guest backed surface.
  204. */
  205. struct vmw_surface_metadata {
  206. u64 flags;
  207. u32 format;
  208. u32 mip_levels[DRM_VMW_MAX_SURFACE_FACES];
  209. u32 multisample_count;
  210. u32 multisample_pattern;
  211. u32 quality_level;
  212. u32 autogen_filter;
  213. u32 array_size;
  214. u32 num_sizes;
  215. u32 buffer_byte_stride;
  216. struct drm_vmw_size base_size;
  217. struct drm_vmw_size *sizes;
  218. bool scanout;
  219. };
  220. /**
  221. * struct vmw_surface: Resource structure for a surface.
  222. *
  223. * @res: The base resource for this surface.
  224. * @metadata: Metadata for this surface resource.
  225. * @snooper: Cursor data. Legacy surface only.
  226. * @offsets: Legacy surface only.
  227. * @view_list: List of views bound to this surface.
  228. */
  229. struct vmw_surface {
  230. struct vmw_resource res;
  231. struct vmw_surface_metadata metadata;
  232. struct vmw_cursor_snooper snooper;
  233. struct vmw_surface_offset *offsets;
  234. struct list_head view_list;
  235. };
  236. struct vmw_fifo_state {
  237. unsigned long reserved_size;
  238. u32 *dynamic_buffer;
  239. u32 *static_buffer;
  240. unsigned long static_buffer_size;
  241. bool using_bounce_buffer;
  242. uint32_t capabilities;
  243. struct mutex fifo_mutex;
  244. struct rw_semaphore rwsem;
  245. };
  246. /**
  247. * struct vmw_res_cache_entry - resource information cache entry
  248. * @handle: User-space handle of a resource.
  249. * @res: Non-ref-counted pointer to the resource.
  250. * @valid_handle: Whether the @handle member is valid.
  251. * @valid: Whether the entry is valid, which also implies that the execbuf
  252. * code holds a reference to the resource, and it's placed on the
  253. * validation list.
  254. *
  255. * Used to avoid frequent repeated user-space handle lookups of the
  256. * same resource.
  257. */
  258. struct vmw_res_cache_entry {
  259. uint32_t handle;
  260. struct vmw_resource *res;
  261. void *private;
  262. unsigned short valid_handle;
  263. unsigned short valid;
  264. };
  265. /**
  266. * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
  267. */
  268. enum vmw_dma_map_mode {
  269. vmw_dma_alloc_coherent, /* Use TTM coherent pages */
  270. vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
  271. vmw_dma_map_bind, /* Unmap from DMA just before unbind */
  272. vmw_dma_map_max
  273. };
  274. /**
  275. * struct vmw_sg_table - Scatter/gather table for binding, with additional
  276. * device-specific information.
  277. *
  278. * @sgt: Pointer to a struct sg_table with binding information
  279. * @num_regions: Number of regions with device-address contiguous pages
  280. */
  281. struct vmw_sg_table {
  282. enum vmw_dma_map_mode mode;
  283. struct page **pages;
  284. const dma_addr_t *addrs;
  285. struct sg_table *sgt;
  286. unsigned long num_pages;
  287. };
  288. /**
  289. * struct vmw_piter - Page iterator that iterates over a list of pages
  290. * and DMA addresses that could be either a scatter-gather list or
  291. * arrays
  292. *
  293. * @pages: Array of page pointers to the pages.
  294. * @addrs: DMA addresses to the pages if coherent pages are used.
  295. * @iter: Scatter-gather page iterator. Current position in SG list.
  296. * @i: Current position in arrays.
  297. * @num_pages: Number of pages total.
  298. * @next: Function to advance the iterator. Returns false if past the list
  299. * of pages, true otherwise.
  300. * @dma_address: Function to return the DMA address of the current page.
  301. */
  302. struct vmw_piter {
  303. struct page **pages;
  304. const dma_addr_t *addrs;
  305. struct sg_dma_page_iter iter;
  306. unsigned long i;
  307. unsigned long num_pages;
  308. bool (*next)(struct vmw_piter *);
  309. dma_addr_t (*dma_address)(struct vmw_piter *);
  310. };
  311. struct vmw_ttm_tt {
  312. struct ttm_tt dma_ttm;
  313. struct vmw_private *dev_priv;
  314. int gmr_id;
  315. struct vmw_mob *mob;
  316. int mem_type;
  317. struct sg_table sgt;
  318. struct vmw_sg_table vsgt;
  319. bool mapped;
  320. bool bound;
  321. };
  322. /*
  323. * enum vmw_display_unit_type - Describes the display unit
  324. */
  325. enum vmw_display_unit_type {
  326. vmw_du_invalid = 0,
  327. vmw_du_legacy,
  328. vmw_du_screen_object,
  329. vmw_du_screen_target,
  330. vmw_du_max
  331. };
  332. struct vmw_validation_context;
  333. struct vmw_ctx_validation_info;
  334. /**
  335. * struct vmw_sw_context - Command submission context
  336. * @res_ht: Pointer hash table used to find validation duplicates
  337. * @kernel: Whether the command buffer originates from kernel code rather
  338. * than from user-space
  339. * @fp: If @kernel is false, points to the file of the client. Otherwise
  340. * NULL
  341. * @cmd_bounce: Command bounce buffer used for command validation before
  342. * copying to fifo space
  343. * @cmd_bounce_size: Current command bounce buffer size
  344. * @cur_query_bo: Current buffer object used as query result buffer
  345. * @bo_relocations: List of buffer object relocations
  346. * @res_relocations: List of resource relocations
  347. * @buf_start: Pointer to start of memory where command validation takes
  348. * place
  349. * @res_cache: Cache of recently looked up resources
  350. * @last_query_ctx: Last context that submitted a query
  351. * @needs_post_query_barrier: Whether a query barrier is needed after
  352. * command submission
  353. * @staged_bindings: Cached per-context binding tracker
  354. * @staged_bindings_inuse: Whether the cached per-context binding tracker
  355. * is in use
  356. * @staged_cmd_res: List of staged command buffer managed resources in this
  357. * command buffer
  358. * @ctx_list: List of context resources referenced in this command buffer
  359. * @dx_ctx_node: Validation metadata of the current DX context
  360. * @dx_query_mob: The MOB used for DX queries
  361. * @dx_query_ctx: The DX context used for the last DX query
  362. * @man: Pointer to the command buffer managed resource manager
  363. * @ctx: The validation context
  364. */
  365. struct vmw_sw_context{
  366. DECLARE_HASHTABLE(res_ht, VMW_RES_HT_ORDER);
  367. bool kernel;
  368. struct vmw_fpriv *fp;
  369. struct drm_file *filp;
  370. uint32_t *cmd_bounce;
  371. uint32_t cmd_bounce_size;
  372. struct vmw_bo *cur_query_bo;
  373. struct list_head bo_relocations;
  374. struct list_head res_relocations;
  375. uint32_t *buf_start;
  376. struct vmw_res_cache_entry res_cache[vmw_res_max];
  377. struct vmw_resource *last_query_ctx;
  378. bool needs_post_query_barrier;
  379. struct vmw_ctx_binding_state *staged_bindings;
  380. bool staged_bindings_inuse;
  381. struct list_head staged_cmd_res;
  382. struct list_head ctx_list;
  383. struct vmw_ctx_validation_info *dx_ctx_node;
  384. struct vmw_bo *dx_query_mob;
  385. struct vmw_resource *dx_query_ctx;
  386. struct vmw_cmdbuf_res_manager *man;
  387. struct vmw_validation_context *ctx;
  388. };
  389. struct vmw_legacy_display;
  390. struct vmw_overlay;
  391. /*
  392. * struct vmw_otable - Guest Memory OBject table metadata
  393. *
  394. * @size: Size of the table (page-aligned).
  395. * @page_table: Pointer to a struct vmw_mob holding the page table.
  396. */
  397. struct vmw_otable {
  398. unsigned long size;
  399. struct vmw_mob *page_table;
  400. bool enabled;
  401. };
  402. struct vmw_otable_batch {
  403. unsigned num_otables;
  404. struct vmw_otable *otables;
  405. struct vmw_resource *context;
  406. struct vmw_bo *otable_bo;
  407. };
  408. enum {
  409. VMW_IRQTHREAD_FENCE,
  410. VMW_IRQTHREAD_CMDBUF,
  411. VMW_IRQTHREAD_MAX
  412. };
  413. /**
  414. * enum vmw_sm_type - Graphics context capability supported by device.
  415. * @VMW_SM_LEGACY: Pre DX context.
  416. * @VMW_SM_4: Context support upto SM4.
  417. * @VMW_SM_4_1: Context support upto SM4_1.
  418. * @VMW_SM_5: Context support up to SM5.
  419. * @VMW_SM_5_1X: Adds support for sm5_1 and gl43 extensions.
  420. * @VMW_SM_MAX: Should be the last.
  421. */
  422. enum vmw_sm_type {
  423. VMW_SM_LEGACY = 0,
  424. VMW_SM_4,
  425. VMW_SM_4_1,
  426. VMW_SM_5,
  427. VMW_SM_5_1X,
  428. VMW_SM_MAX
  429. };
  430. struct vmw_private {
  431. struct drm_device drm;
  432. struct ttm_device bdev;
  433. u32 pci_id;
  434. resource_size_t io_start;
  435. resource_size_t vram_start;
  436. resource_size_t vram_size;
  437. resource_size_t max_primary_mem;
  438. u32 __iomem *rmmio;
  439. u32 *fifo_mem;
  440. resource_size_t fifo_mem_size;
  441. uint32_t fb_max_width;
  442. uint32_t fb_max_height;
  443. uint32_t texture_max_width;
  444. uint32_t texture_max_height;
  445. uint32_t stdu_max_width;
  446. uint32_t stdu_max_height;
  447. uint32_t initial_width;
  448. uint32_t initial_height;
  449. uint32_t capabilities;
  450. uint32_t capabilities2;
  451. uint32_t max_gmr_ids;
  452. uint32_t max_gmr_pages;
  453. uint32_t max_mob_pages;
  454. uint32_t max_mob_size;
  455. uint32_t memory_size;
  456. bool has_gmr;
  457. bool has_mob;
  458. spinlock_t hw_lock;
  459. bool assume_16bpp;
  460. u32 irqs[VMWGFX_MAX_NUM_IRQS];
  461. u32 num_irq_vectors;
  462. enum vmw_sm_type sm_type;
  463. /*
  464. * Framebuffer info.
  465. */
  466. enum vmw_display_unit_type active_display_unit;
  467. struct vmw_legacy_display *ldu_priv;
  468. struct vmw_overlay *overlay_priv;
  469. struct drm_property *hotplug_mode_update_property;
  470. struct drm_property *implicit_placement_property;
  471. spinlock_t cursor_lock;
  472. struct drm_atomic_state *suspend_state;
  473. /*
  474. * Context and surface management.
  475. */
  476. spinlock_t resource_lock;
  477. struct idr res_idr[vmw_res_max];
  478. /*
  479. * A resource manager for kernel-only surfaces and
  480. * contexts.
  481. */
  482. struct ttm_object_device *tdev;
  483. /*
  484. * Fencing and IRQs.
  485. */
  486. atomic_t marker_seq;
  487. wait_queue_head_t fence_queue;
  488. wait_queue_head_t fifo_queue;
  489. spinlock_t waiter_lock;
  490. int fence_queue_waiters; /* Protected by waiter_lock */
  491. int goal_queue_waiters; /* Protected by waiter_lock */
  492. int cmdbuf_waiters; /* Protected by waiter_lock */
  493. int error_waiters; /* Protected by waiter_lock */
  494. int fifo_queue_waiters; /* Protected by waiter_lock */
  495. uint32_t last_read_seqno;
  496. struct vmw_fence_manager *fman;
  497. uint32_t irq_mask; /* Updates protected by waiter_lock */
  498. /*
  499. * Device state
  500. */
  501. uint32_t traces_state;
  502. uint32_t enable_state;
  503. uint32_t config_done_state;
  504. /**
  505. * Execbuf
  506. */
  507. /**
  508. * Protected by the cmdbuf mutex.
  509. */
  510. struct vmw_sw_context ctx;
  511. struct mutex cmdbuf_mutex;
  512. struct mutex binding_mutex;
  513. /**
  514. * PM management.
  515. */
  516. struct notifier_block pm_nb;
  517. bool refuse_hibernation;
  518. bool suspend_locked;
  519. atomic_t num_fifo_resources;
  520. /*
  521. * Query processing. These members
  522. * are protected by the cmdbuf mutex.
  523. */
  524. struct vmw_bo *dummy_query_bo;
  525. struct vmw_bo *pinned_bo;
  526. uint32_t query_cid;
  527. uint32_t query_cid_valid;
  528. bool dummy_query_bo_pinned;
  529. /*
  530. * Surface swapping. The "surface_lru" list is protected by the
  531. * resource lock in order to be able to destroy a surface and take
  532. * it off the lru atomically. "used_memory_size" is currently
  533. * protected by the cmdbuf mutex for simplicity.
  534. */
  535. struct list_head res_lru[vmw_res_max];
  536. uint32_t used_memory_size;
  537. /*
  538. * DMA mapping stuff.
  539. */
  540. enum vmw_dma_map_mode map_mode;
  541. /*
  542. * Guest Backed stuff
  543. */
  544. struct vmw_otable_batch otable_batch;
  545. struct vmw_fifo_state *fifo;
  546. struct vmw_cmdbuf_man *cman;
  547. DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
  548. uint32 *devcaps;
  549. bool vkms_enabled;
  550. struct workqueue_struct *crc_workq;
  551. /*
  552. * mksGuestStat instance-descriptor and pid arrays
  553. */
  554. struct page *mksstat_user_pages[MKSSTAT_CAPACITY];
  555. atomic_t mksstat_user_pids[MKSSTAT_CAPACITY];
  556. #if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS)
  557. struct page *mksstat_kern_pages[MKSSTAT_CAPACITY];
  558. u8 mksstat_kern_top_timer[MKSSTAT_CAPACITY];
  559. atomic_t mksstat_kern_pids[MKSSTAT_CAPACITY];
  560. #endif
  561. };
  562. static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
  563. {
  564. return container_of(res, struct vmw_surface, res);
  565. }
  566. static inline struct vmw_private *vmw_priv(struct drm_device *dev)
  567. {
  568. return (struct vmw_private *)dev->dev_private;
  569. }
  570. static inline struct vmw_private *vmw_priv_from_ttm(struct ttm_device *bdev)
  571. {
  572. return container_of(bdev, struct vmw_private, bdev);
  573. }
  574. static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
  575. {
  576. return (struct vmw_fpriv *)file_priv->driver_priv;
  577. }
  578. /*
  579. * SVGA v3 has mmio register access and lacks fifo cmds
  580. */
  581. static inline bool vmw_is_svga_v3(const struct vmw_private *dev)
  582. {
  583. return dev->pci_id == VMWGFX_PCI_ID_SVGA3;
  584. }
  585. /*
  586. * The locking here is fine-grained, so that it is performed once
  587. * for every read- and write operation. This is of course costly, but we
  588. * don't perform much register access in the timing critical paths anyway.
  589. * Instead we have the extra benefit of being sure that we don't forget
  590. * the hw lock around register accesses.
  591. */
  592. static inline void vmw_write(struct vmw_private *dev_priv,
  593. unsigned int offset, uint32_t value)
  594. {
  595. if (vmw_is_svga_v3(dev_priv)) {
  596. iowrite32(value, dev_priv->rmmio + offset);
  597. } else {
  598. spin_lock(&dev_priv->hw_lock);
  599. outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
  600. outl(value, dev_priv->io_start + SVGA_VALUE_PORT);
  601. spin_unlock(&dev_priv->hw_lock);
  602. }
  603. }
  604. static inline uint32_t vmw_read(struct vmw_private *dev_priv,
  605. unsigned int offset)
  606. {
  607. u32 val;
  608. if (vmw_is_svga_v3(dev_priv)) {
  609. val = ioread32(dev_priv->rmmio + offset);
  610. } else {
  611. spin_lock(&dev_priv->hw_lock);
  612. outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
  613. val = inl(dev_priv->io_start + SVGA_VALUE_PORT);
  614. spin_unlock(&dev_priv->hw_lock);
  615. }
  616. return val;
  617. }
  618. /**
  619. * has_sm4_context - Does the device support SM4 context.
  620. * @dev_priv: Device private.
  621. *
  622. * Return: Bool value if device support SM4 context or not.
  623. */
  624. static inline bool has_sm4_context(const struct vmw_private *dev_priv)
  625. {
  626. return (dev_priv->sm_type >= VMW_SM_4);
  627. }
  628. /**
  629. * has_sm4_1_context - Does the device support SM4_1 context.
  630. * @dev_priv: Device private.
  631. *
  632. * Return: Bool value if device support SM4_1 context or not.
  633. */
  634. static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
  635. {
  636. return (dev_priv->sm_type >= VMW_SM_4_1);
  637. }
  638. /**
  639. * has_sm5_context - Does the device support SM5 context.
  640. * @dev_priv: Device private.
  641. *
  642. * Return: Bool value if device support SM5 context or not.
  643. */
  644. static inline bool has_sm5_context(const struct vmw_private *dev_priv)
  645. {
  646. return (dev_priv->sm_type >= VMW_SM_5);
  647. }
  648. /**
  649. * has_gl43_context - Does the device support GL43 context.
  650. * @dev_priv: Device private.
  651. *
  652. * Return: Bool value if device support SM5 context or not.
  653. */
  654. static inline bool has_gl43_context(const struct vmw_private *dev_priv)
  655. {
  656. return (dev_priv->sm_type >= VMW_SM_5_1X);
  657. }
  658. static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv)
  659. {
  660. return (has_gl43_context(dev_priv) ?
  661. SVGA3D_DX11_1_MAX_UAVIEWS : SVGA3D_MAX_UAVIEWS);
  662. }
  663. extern void vmw_svga_enable(struct vmw_private *dev_priv);
  664. extern void vmw_svga_disable(struct vmw_private *dev_priv);
  665. bool vmwgfx_supported(struct vmw_private *vmw);
  666. /**
  667. * GMR utilities - vmwgfx_gmr.c
  668. */
  669. extern int vmw_gmr_bind(struct vmw_private *dev_priv,
  670. const struct vmw_sg_table *vsgt,
  671. unsigned long num_pages,
  672. int gmr_id);
  673. extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
  674. /**
  675. * User handles
  676. */
  677. struct vmw_user_object {
  678. struct vmw_surface *surface;
  679. struct vmw_bo *buffer;
  680. };
  681. int vmw_user_object_lookup(struct vmw_private *dev_priv, struct drm_file *filp,
  682. u32 handle, struct vmw_user_object *uo);
  683. struct vmw_user_object *vmw_user_object_ref(struct vmw_user_object *uo);
  684. void vmw_user_object_unref(struct vmw_user_object *uo);
  685. bool vmw_user_object_is_null(struct vmw_user_object *uo);
  686. struct vmw_surface *vmw_user_object_surface(struct vmw_user_object *uo);
  687. struct vmw_bo *vmw_user_object_buffer(struct vmw_user_object *uo);
  688. void *vmw_user_object_map(struct vmw_user_object *uo);
  689. void *vmw_user_object_map_size(struct vmw_user_object *uo, size_t size);
  690. void vmw_user_object_unmap(struct vmw_user_object *uo);
  691. bool vmw_user_object_is_mapped(struct vmw_user_object *uo);
  692. /**
  693. * Resource utilities - vmwgfx_resource.c
  694. */
  695. struct vmw_user_resource_conv;
  696. extern void vmw_resource_unreference(struct vmw_resource **p_res);
  697. extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
  698. extern struct vmw_resource *
  699. vmw_resource_reference_unless_doomed(struct vmw_resource *res);
  700. extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
  701. bool dirtying);
  702. extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
  703. bool no_backup);
  704. extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
  705. extern int vmw_user_resource_lookup_handle(
  706. struct vmw_private *dev_priv,
  707. struct ttm_object_file *tfile,
  708. uint32_t handle,
  709. const struct vmw_user_resource_conv *converter,
  710. struct vmw_resource **p_res);
  711. extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  712. struct drm_file *file_priv);
  713. extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  714. struct drm_file *file_priv);
  715. extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  716. struct ttm_object_file *tfile,
  717. uint32_t *inout_id,
  718. struct vmw_resource **out);
  719. extern void vmw_resource_unreserve(struct vmw_resource *res,
  720. bool dirty_set,
  721. bool dirty,
  722. bool switch_guest_memory,
  723. struct vmw_bo *new_guest_memory,
  724. unsigned long new_guest_memory_offset);
  725. extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
  726. struct ttm_resource *old_mem,
  727. struct ttm_resource *new_mem);
  728. int vmw_query_readback_all(struct vmw_bo *dx_query_mob);
  729. void vmw_resource_evict_all(struct vmw_private *dev_priv);
  730. void vmw_resource_unbind_list(struct vmw_bo *vbo);
  731. void vmw_resource_mob_attach(struct vmw_resource *res);
  732. void vmw_resource_mob_detach(struct vmw_resource *res);
  733. void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
  734. pgoff_t end);
  735. int vmw_resource_clean(struct vmw_resource *res);
  736. int vmw_resources_clean(struct vmw_bo *vbo, pgoff_t start,
  737. pgoff_t end, pgoff_t *num_prefault);
  738. /**
  739. * vmw_resource_mob_attached - Whether a resource currently has a mob attached
  740. * @res: The resource
  741. *
  742. * Return: true if the resource has a mob attached, false otherwise.
  743. */
  744. static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
  745. {
  746. return !RB_EMPTY_NODE(&res->mob_node);
  747. }
  748. /**
  749. * GEM related functionality - vmwgfx_gem.c
  750. */
  751. struct vmw_bo_params;
  752. int vmw_gem_object_create(struct vmw_private *vmw,
  753. struct vmw_bo_params *params,
  754. struct vmw_bo **p_vbo);
  755. extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
  756. struct drm_file *filp,
  757. uint32_t size,
  758. uint32_t *handle,
  759. struct vmw_bo **p_vbo);
  760. extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
  761. struct drm_file *filp);
  762. extern void vmw_debugfs_gem_init(struct vmw_private *vdev);
  763. /**
  764. * Misc Ioctl functionality - vmwgfx_ioctl.c
  765. */
  766. extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  767. struct drm_file *file_priv);
  768. extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
  769. struct drm_file *file_priv);
  770. extern int vmw_present_ioctl(struct drm_device *dev, void *data,
  771. struct drm_file *file_priv);
  772. extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
  773. struct drm_file *file_priv);
  774. /**
  775. * Fifo utilities - vmwgfx_fifo.c
  776. */
  777. extern struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv);
  778. extern void vmw_fifo_destroy(struct vmw_private *dev_priv);
  779. extern bool vmw_cmd_supported(struct vmw_private *vmw);
  780. extern void *
  781. vmw_cmd_ctx_reserve(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
  782. extern void vmw_cmd_commit(struct vmw_private *dev_priv, uint32_t bytes);
  783. extern void vmw_cmd_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
  784. extern int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno);
  785. extern bool vmw_supports_3d(struct vmw_private *dev_priv);
  786. extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
  787. extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
  788. extern int vmw_cmd_emit_dummy_query(struct vmw_private *dev_priv,
  789. uint32_t cid);
  790. extern int vmw_cmd_flush(struct vmw_private *dev_priv,
  791. bool interruptible);
  792. #define VMW_CMD_CTX_RESERVE(__priv, __bytes, __ctx_id) \
  793. ({ \
  794. vmw_cmd_ctx_reserve(__priv, __bytes, __ctx_id) ? : ({ \
  795. DRM_ERROR("FIFO reserve failed at %s for %u bytes\n", \
  796. __func__, (unsigned int) __bytes); \
  797. NULL; \
  798. }); \
  799. })
  800. #define VMW_CMD_RESERVE(__priv, __bytes) \
  801. VMW_CMD_CTX_RESERVE(__priv, __bytes, SVGA3D_INVALID_ID)
  802. /**
  803. * vmw_fifo_caps - Returns the capabilities of the FIFO command
  804. * queue or 0 if fifo memory isn't present.
  805. * @dev_priv: The device private context
  806. */
  807. static inline uint32_t vmw_fifo_caps(const struct vmw_private *dev_priv)
  808. {
  809. if (!dev_priv->fifo_mem || !dev_priv->fifo)
  810. return 0;
  811. return dev_priv->fifo->capabilities;
  812. }
  813. /**
  814. * vmw_is_cursor_bypass3_enabled - Returns TRUE iff Cursor Bypass 3
  815. * is enabled in the FIFO.
  816. * @dev_priv: The device private context
  817. */
  818. static inline bool
  819. vmw_is_cursor_bypass3_enabled(const struct vmw_private *dev_priv)
  820. {
  821. return (vmw_fifo_caps(dev_priv) & SVGA_FIFO_CAP_CURSOR_BYPASS_3) != 0;
  822. }
  823. /**
  824. * TTM buffer object driver - vmwgfx_ttm_buffer.c
  825. */
  826. extern const size_t vmw_tt_size;
  827. extern struct ttm_placement vmw_vram_placement;
  828. extern struct ttm_placement vmw_sys_placement;
  829. extern struct ttm_device_funcs vmw_bo_driver;
  830. extern const struct vmw_sg_table *
  831. vmw_bo_sg_table(struct ttm_buffer_object *bo);
  832. int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
  833. size_t bo_size,
  834. u32 domain,
  835. struct vmw_bo **bo_p);
  836. extern void vmw_piter_start(struct vmw_piter *viter,
  837. const struct vmw_sg_table *vsgt,
  838. unsigned long p_offs);
  839. /**
  840. * vmw_piter_next - Advance the iterator one page.
  841. *
  842. * @viter: Pointer to the iterator to advance.
  843. *
  844. * Returns false if past the list of pages, true otherwise.
  845. */
  846. static inline bool vmw_piter_next(struct vmw_piter *viter)
  847. {
  848. return viter->next(viter);
  849. }
  850. /**
  851. * vmw_piter_dma_addr - Return the DMA address of the current page.
  852. *
  853. * @viter: Pointer to the iterator
  854. *
  855. * Returns the DMA address of the page pointed to by @viter.
  856. */
  857. static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
  858. {
  859. return viter->dma_address(viter);
  860. }
  861. /**
  862. * vmw_piter_page - Return a pointer to the current page.
  863. *
  864. * @viter: Pointer to the iterator
  865. *
  866. * Returns the DMA address of the page pointed to by @viter.
  867. */
  868. static inline struct page *vmw_piter_page(struct vmw_piter *viter)
  869. {
  870. return viter->pages[viter->i];
  871. }
  872. /**
  873. * Command submission - vmwgfx_execbuf.c
  874. */
  875. extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
  876. struct drm_file *file_priv);
  877. extern int vmw_execbuf_process(struct drm_file *file_priv,
  878. struct vmw_private *dev_priv,
  879. void __user *user_commands,
  880. void *kernel_commands,
  881. uint32_t command_size,
  882. uint64_t throttle_us,
  883. uint32_t dx_context_handle,
  884. struct drm_vmw_fence_rep __user
  885. *user_fence_rep,
  886. struct vmw_fence_obj **out_fence,
  887. uint32_t flags);
  888. extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
  889. struct vmw_fence_obj *fence);
  890. extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
  891. extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
  892. struct vmw_private *dev_priv,
  893. struct vmw_fence_obj **p_fence,
  894. uint32_t *p_handle);
  895. extern int vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
  896. struct vmw_fpriv *vmw_fp,
  897. int ret,
  898. struct drm_vmw_fence_rep __user
  899. *user_fence_rep,
  900. struct vmw_fence_obj *fence,
  901. uint32_t fence_handle,
  902. int32_t out_fence_fd);
  903. bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
  904. /**
  905. * IRQs and wating - vmwgfx_irq.c
  906. */
  907. extern int vmw_irq_install(struct vmw_private *dev_priv);
  908. extern void vmw_irq_uninstall(struct drm_device *dev);
  909. extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
  910. uint32_t seqno);
  911. extern int vmw_fallback_wait(struct vmw_private *dev_priv,
  912. bool lazy,
  913. bool fifo_idle,
  914. uint32_t seqno,
  915. bool interruptible,
  916. unsigned long timeout);
  917. extern void vmw_update_seqno(struct vmw_private *dev_priv);
  918. extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
  919. extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
  920. extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
  921. extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
  922. extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
  923. int *waiter_count);
  924. extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
  925. u32 flag, int *waiter_count);
  926. /**
  927. * Kernel modesetting - vmwgfx_kms.c
  928. */
  929. int vmw_kms_init(struct vmw_private *dev_priv);
  930. int vmw_kms_close(struct vmw_private *dev_priv);
  931. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  932. struct drm_file *file_priv);
  933. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
  934. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  935. struct ttm_object_file *tfile,
  936. struct ttm_buffer_object *bo,
  937. SVGA3dCmdHeader *header);
  938. int vmw_kms_write_svga(struct vmw_private *vmw_priv,
  939. unsigned width, unsigned height, unsigned pitch,
  940. unsigned bpp, unsigned depth);
  941. int vmw_kms_present(struct vmw_private *dev_priv,
  942. struct drm_file *file_priv,
  943. struct vmw_framebuffer *vfb,
  944. struct vmw_surface *surface,
  945. uint32_t sid, int32_t destX, int32_t destY,
  946. struct drm_vmw_rect *clips,
  947. uint32_t num_clips);
  948. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  949. struct drm_file *file_priv);
  950. void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
  951. int vmw_kms_suspend(struct drm_device *dev);
  952. int vmw_kms_resume(struct drm_device *dev);
  953. void vmw_kms_lost_device(struct drm_device *dev);
  954. extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
  955. extern void vmw_resource_unpin(struct vmw_resource *res);
  956. extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
  957. /**
  958. * Overlay control - vmwgfx_overlay.c
  959. */
  960. int vmw_overlay_init(struct vmw_private *dev_priv);
  961. int vmw_overlay_close(struct vmw_private *dev_priv);
  962. int vmw_overlay_ioctl(struct drm_device *dev, void *data,
  963. struct drm_file *file_priv);
  964. int vmw_overlay_resume_all(struct vmw_private *dev_priv);
  965. int vmw_overlay_pause_all(struct vmw_private *dev_priv);
  966. int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
  967. int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
  968. int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
  969. int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  970. /**
  971. * GMR Id manager
  972. */
  973. int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
  974. void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type);
  975. /**
  976. * System memory manager
  977. */
  978. int vmw_sys_man_init(struct vmw_private *dev_priv);
  979. void vmw_sys_man_fini(struct vmw_private *dev_priv);
  980. /**
  981. * Prime - vmwgfx_prime.c
  982. */
  983. extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
  984. extern int vmw_prime_fd_to_handle(struct drm_device *dev,
  985. struct drm_file *file_priv,
  986. int fd, u32 *handle);
  987. extern int vmw_prime_handle_to_fd(struct drm_device *dev,
  988. struct drm_file *file_priv,
  989. uint32_t handle, uint32_t flags,
  990. int *prime_fd);
  991. struct drm_gem_object *vmw_prime_import_sg_table(struct drm_device *dev,
  992. struct dma_buf_attachment *attach,
  993. struct sg_table *table);
  994. /*
  995. * MemoryOBject management - vmwgfx_mob.c
  996. */
  997. struct vmw_mob;
  998. extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
  999. const struct vmw_sg_table *vsgt,
  1000. unsigned long num_data_pages, int32_t mob_id);
  1001. extern void vmw_mob_unbind(struct vmw_private *dev_priv,
  1002. struct vmw_mob *mob);
  1003. extern void vmw_mob_destroy(struct vmw_mob *mob);
  1004. extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
  1005. extern int vmw_otables_setup(struct vmw_private *dev_priv);
  1006. extern void vmw_otables_takedown(struct vmw_private *dev_priv);
  1007. /*
  1008. * Context management - vmwgfx_context.c
  1009. */
  1010. extern const struct vmw_user_resource_conv *user_context_converter;
  1011. extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
  1012. struct drm_file *file_priv);
  1013. extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
  1014. struct drm_file *file_priv);
  1015. extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
  1016. struct drm_file *file_priv);
  1017. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  1018. extern struct vmw_cmdbuf_res_manager *
  1019. vmw_context_res_man(struct vmw_resource *ctx);
  1020. extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
  1021. SVGACOTableType cotable_type);
  1022. struct vmw_ctx_binding_state;
  1023. extern struct vmw_ctx_binding_state *
  1024. vmw_context_binding_state(struct vmw_resource *ctx);
  1025. extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
  1026. bool readback);
  1027. extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
  1028. struct vmw_bo *mob);
  1029. extern struct vmw_bo *
  1030. vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
  1031. /*
  1032. * Surface management - vmwgfx_surface.c
  1033. */
  1034. extern const struct vmw_user_resource_conv *user_surface_converter;
  1035. extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
  1036. struct drm_file *file_priv);
  1037. extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
  1038. struct drm_file *file_priv);
  1039. extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
  1040. struct drm_file *file_priv);
  1041. extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
  1042. struct drm_file *file_priv);
  1043. extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
  1044. struct drm_file *file_priv);
  1045. extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
  1046. void *data,
  1047. struct drm_file *file_priv);
  1048. extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
  1049. void *data,
  1050. struct drm_file *file_priv);
  1051. int vmw_gb_surface_define(struct vmw_private *dev_priv,
  1052. const struct vmw_surface_metadata *req,
  1053. struct vmw_surface **srf_out);
  1054. struct vmw_surface *vmw_lookup_surface_for_buffer(struct vmw_private *vmw,
  1055. struct vmw_bo *bo,
  1056. u32 handle);
  1057. u32 vmw_lookup_surface_handle_for_buffer(struct vmw_private *vmw,
  1058. struct vmw_bo *bo,
  1059. u32 handle);
  1060. int vmw_dumb_create(struct drm_file *file_priv,
  1061. struct drm_device *dev,
  1062. struct drm_mode_create_dumb *args);
  1063. /*
  1064. * Shader management - vmwgfx_shader.c
  1065. */
  1066. extern const struct vmw_user_resource_conv *user_shader_converter;
  1067. extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
  1068. struct drm_file *file_priv);
  1069. extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
  1070. struct drm_file *file_priv);
  1071. extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
  1072. struct vmw_cmdbuf_res_manager *man,
  1073. u32 user_key, const void *bytecode,
  1074. SVGA3dShaderType shader_type,
  1075. size_t size,
  1076. struct list_head *list);
  1077. extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
  1078. u32 user_key, SVGA3dShaderType shader_type,
  1079. struct list_head *list);
  1080. extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
  1081. struct vmw_resource *ctx,
  1082. u32 user_key,
  1083. SVGA3dShaderType shader_type,
  1084. struct list_head *list);
  1085. extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
  1086. struct list_head *list,
  1087. bool readback);
  1088. extern struct vmw_resource *
  1089. vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
  1090. u32 user_key, SVGA3dShaderType shader_type);
  1091. /*
  1092. * Streamoutput management
  1093. */
  1094. struct vmw_resource *
  1095. vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man,
  1096. u32 user_key);
  1097. int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
  1098. struct vmw_resource *ctx,
  1099. SVGA3dStreamOutputId user_key,
  1100. struct list_head *list);
  1101. void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size);
  1102. int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man,
  1103. SVGA3dStreamOutputId user_key,
  1104. struct list_head *list);
  1105. void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv,
  1106. struct list_head *list,
  1107. bool readback);
  1108. /*
  1109. * Command buffer managed resources - vmwgfx_cmdbuf_res.c
  1110. */
  1111. extern struct vmw_cmdbuf_res_manager *
  1112. vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
  1113. extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
  1114. extern struct vmw_resource *
  1115. vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
  1116. enum vmw_cmdbuf_res_type res_type,
  1117. u32 user_key);
  1118. extern void vmw_cmdbuf_res_revert(struct list_head *list);
  1119. extern void vmw_cmdbuf_res_commit(struct list_head *list);
  1120. extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
  1121. enum vmw_cmdbuf_res_type res_type,
  1122. u32 user_key,
  1123. struct vmw_resource *res,
  1124. struct list_head *list);
  1125. extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
  1126. enum vmw_cmdbuf_res_type res_type,
  1127. u32 user_key,
  1128. struct list_head *list,
  1129. struct vmw_resource **res);
  1130. /*
  1131. * COTable management - vmwgfx_cotable.c
  1132. */
  1133. extern const SVGACOTableType vmw_cotable_scrub_order[];
  1134. extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
  1135. struct vmw_resource *ctx,
  1136. u32 type);
  1137. extern int vmw_cotable_notify(struct vmw_resource *res, int id);
  1138. extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
  1139. extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
  1140. struct list_head *head);
  1141. /*
  1142. * Command buffer managerment vmwgfx_cmdbuf.c
  1143. */
  1144. struct vmw_cmdbuf_man;
  1145. struct vmw_cmdbuf_header;
  1146. extern struct vmw_cmdbuf_man *
  1147. vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
  1148. extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size);
  1149. extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
  1150. extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
  1151. extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
  1152. unsigned long timeout);
  1153. extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
  1154. int ctx_id, bool interruptible,
  1155. struct vmw_cmdbuf_header *header);
  1156. extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
  1157. struct vmw_cmdbuf_header *header,
  1158. bool flush);
  1159. extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
  1160. size_t size, bool interruptible,
  1161. struct vmw_cmdbuf_header **p_header);
  1162. extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
  1163. extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
  1164. bool interruptible);
  1165. extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
  1166. /* CPU blit utilities - vmwgfx_blit.c */
  1167. /**
  1168. * struct vmw_diff_cpy - CPU blit information structure
  1169. *
  1170. * @rect: The output bounding box rectangle.
  1171. * @line: The current line of the blit.
  1172. * @line_offset: Offset of the current line segment.
  1173. * @cpp: Bytes per pixel (granularity information).
  1174. * @memcpy: Which memcpy function to use.
  1175. */
  1176. struct vmw_diff_cpy {
  1177. struct drm_rect rect;
  1178. size_t line;
  1179. size_t line_offset;
  1180. int cpp;
  1181. void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
  1182. size_t n);
  1183. };
  1184. #define VMW_CPU_BLIT_INITIALIZER { \
  1185. .do_cpy = vmw_memcpy, \
  1186. }
  1187. #define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \
  1188. .line = 0, \
  1189. .line_offset = 0, \
  1190. .rect = { .x1 = INT_MAX/2, \
  1191. .y1 = INT_MAX/2, \
  1192. .x2 = INT_MIN/2, \
  1193. .y2 = INT_MIN/2 \
  1194. }, \
  1195. .cpp = _cpp, \
  1196. .do_cpy = vmw_diff_memcpy, \
  1197. }
  1198. void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
  1199. size_t n);
  1200. void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
  1201. int vmw_bo_cpu_blit(struct vmw_bo *dst,
  1202. u32 dst_offset, u32 dst_stride,
  1203. struct vmw_bo *src,
  1204. u32 src_offset, u32 src_stride,
  1205. u32 w, u32 h,
  1206. struct vmw_diff_cpy *diff);
  1207. /* Host messaging -vmwgfx_msg.c: */
  1208. void vmw_disable_backdoor(void);
  1209. int vmw_host_get_guestinfo(const char *guest_info_param,
  1210. char *buffer, size_t *length);
  1211. __printf(1, 2) int vmw_host_printf(const char *fmt, ...);
  1212. int vmw_msg_ioctl(struct drm_device *dev, void *data,
  1213. struct drm_file *file_priv);
  1214. /* Host mksGuestStats -vmwgfx_msg.c: */
  1215. int vmw_mksstat_get_kern_slot(pid_t pid, struct vmw_private *dev_priv);
  1216. int vmw_mksstat_reset_ioctl(struct drm_device *dev, void *data,
  1217. struct drm_file *file_priv);
  1218. int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
  1219. struct drm_file *file_priv);
  1220. int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
  1221. struct drm_file *file_priv);
  1222. int vmw_mksstat_remove_all(struct vmw_private *dev_priv);
  1223. /* VMW logging */
  1224. /**
  1225. * VMW_DEBUG_USER - Debug output for user-space debugging.
  1226. *
  1227. * @fmt: printf() like format string.
  1228. *
  1229. * This macro is for logging user-space error and debugging messages for e.g.
  1230. * command buffer execution errors due to malformed commands, invalid context,
  1231. * etc.
  1232. */
  1233. #define VMW_DEBUG_USER(fmt, ...) \
  1234. DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
  1235. /* Resource dirtying - vmwgfx_page_dirty.c */
  1236. void vmw_bo_dirty_scan(struct vmw_bo *vbo);
  1237. int vmw_bo_dirty_add(struct vmw_bo *vbo);
  1238. void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
  1239. void vmw_bo_dirty_clear_res(struct vmw_resource *res);
  1240. void vmw_bo_dirty_release(struct vmw_bo *vbo);
  1241. void vmw_bo_dirty_unmap(struct vmw_bo *vbo,
  1242. pgoff_t start, pgoff_t end);
  1243. vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
  1244. vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
  1245. /**
  1246. * VMW_DEBUG_KMS - Debug output for kernel mode-setting
  1247. *
  1248. * This macro is for debugging vmwgfx mode-setting code.
  1249. */
  1250. #define VMW_DEBUG_KMS(fmt, ...) \
  1251. DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
  1252. /**
  1253. * Inline helper functions
  1254. */
  1255. static inline void vmw_surface_unreference(struct vmw_surface **srf)
  1256. {
  1257. struct vmw_surface *tmp_srf = *srf;
  1258. struct vmw_resource *res = &tmp_srf->res;
  1259. *srf = NULL;
  1260. vmw_resource_unreference(&res);
  1261. }
  1262. static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
  1263. {
  1264. (void) vmw_resource_reference(&srf->res);
  1265. return srf;
  1266. }
  1267. static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
  1268. {
  1269. atomic_inc(&dev_priv->num_fifo_resources);
  1270. }
  1271. static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
  1272. {
  1273. atomic_dec(&dev_priv->num_fifo_resources);
  1274. }
  1275. /**
  1276. * vmw_fifo_mem_read - Perform a MMIO read from the fifo memory
  1277. *
  1278. * @fifo_reg: The fifo register to read from
  1279. *
  1280. * This function is intended to be equivalent to ioread32() on
  1281. * memremap'd memory, but without byteswapping.
  1282. */
  1283. static inline u32 vmw_fifo_mem_read(struct vmw_private *vmw, uint32 fifo_reg)
  1284. {
  1285. BUG_ON(vmw_is_svga_v3(vmw));
  1286. return READ_ONCE(*(vmw->fifo_mem + fifo_reg));
  1287. }
  1288. /**
  1289. * vmw_fifo_mem_write - Perform a MMIO write to volatile memory
  1290. *
  1291. * @addr: The fifo register to write to
  1292. *
  1293. * This function is intended to be equivalent to iowrite32 on
  1294. * memremap'd memory, but without byteswapping.
  1295. */
  1296. static inline void vmw_fifo_mem_write(struct vmw_private *vmw, u32 fifo_reg,
  1297. u32 value)
  1298. {
  1299. BUG_ON(vmw_is_svga_v3(vmw));
  1300. WRITE_ONCE(*(vmw->fifo_mem + fifo_reg), value);
  1301. }
  1302. static inline u32 vmw_fence_read(struct vmw_private *dev_priv)
  1303. {
  1304. u32 fence;
  1305. if (vmw_is_svga_v3(dev_priv))
  1306. fence = vmw_read(dev_priv, SVGA_REG_FENCE);
  1307. else
  1308. fence = vmw_fifo_mem_read(dev_priv, SVGA_FIFO_FENCE);
  1309. return fence;
  1310. }
  1311. static inline void vmw_fence_write(struct vmw_private *dev_priv,
  1312. u32 fence)
  1313. {
  1314. BUG_ON(vmw_is_svga_v3(dev_priv));
  1315. vmw_fifo_mem_write(dev_priv, SVGA_FIFO_FENCE, fence);
  1316. }
  1317. static inline u32 vmw_irq_status_read(struct vmw_private *vmw)
  1318. {
  1319. u32 status;
  1320. if (vmw_is_svga_v3(vmw))
  1321. status = vmw_read(vmw, SVGA_REG_IRQ_STATUS);
  1322. else
  1323. status = inl(vmw->io_start + SVGA_IRQSTATUS_PORT);
  1324. return status;
  1325. }
  1326. static inline void vmw_irq_status_write(struct vmw_private *vmw,
  1327. uint32 status)
  1328. {
  1329. if (vmw_is_svga_v3(vmw))
  1330. vmw_write(vmw, SVGA_REG_IRQ_STATUS, status);
  1331. else
  1332. outl(status, vmw->io_start + SVGA_IRQSTATUS_PORT);
  1333. }
  1334. static inline bool vmw_has_fences(struct vmw_private *vmw)
  1335. {
  1336. if ((vmw->capabilities & (SVGA_CAP_COMMAND_BUFFERS |
  1337. SVGA_CAP_CMD_BUFFERS_2)) != 0)
  1338. return true;
  1339. return (vmw_fifo_caps(vmw) & SVGA_FIFO_CAP_FENCE) != 0;
  1340. }
  1341. static inline bool vmw_shadertype_is_valid(enum vmw_sm_type shader_model,
  1342. u32 shader_type)
  1343. {
  1344. SVGA3dShaderType max_allowed = SVGA3D_SHADERTYPE_PREDX_MAX;
  1345. if (shader_model >= VMW_SM_5)
  1346. max_allowed = SVGA3D_SHADERTYPE_MAX;
  1347. else if (shader_model >= VMW_SM_4)
  1348. max_allowed = SVGA3D_SHADERTYPE_DX10_MAX;
  1349. return shader_type >= SVGA3D_SHADERTYPE_MIN && shader_type < max_allowed;
  1350. }
  1351. #endif