vmwgfx_drv.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009-2016 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include <linux/module.h>
  28. #include <linux/console.h>
  29. #include <drm/drmP.h>
  30. #include "vmwgfx_drv.h"
  31. #include "vmwgfx_binding.h"
  32. #include <drm/ttm/ttm_placement.h>
  33. #include <drm/ttm/ttm_bo_driver.h>
  34. #include <drm/ttm/ttm_object.h>
  35. #include <drm/ttm/ttm_module.h>
  36. #include <linux/dma_remapping.h>
  37. #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
  38. #define VMWGFX_CHIP_SVGAII 0
  39. #define VMW_FB_RESERVATION 0
  40. #define VMW_MIN_INITIAL_WIDTH 800
  41. #define VMW_MIN_INITIAL_HEIGHT 600
  42. #ifndef VMWGFX_GIT_VERSION
  43. #define VMWGFX_GIT_VERSION "Unknown"
  44. #endif
  45. #define VMWGFX_REPO "In Tree"
  46. /**
  47. * Fully encoded drm commands. Might move to vmw_drm.h
  48. */
  49. #define DRM_IOCTL_VMW_GET_PARAM \
  50. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_GET_PARAM, \
  51. struct drm_vmw_getparam_arg)
  52. #define DRM_IOCTL_VMW_ALLOC_DMABUF \
  53. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_ALLOC_DMABUF, \
  54. union drm_vmw_alloc_dmabuf_arg)
  55. #define DRM_IOCTL_VMW_UNREF_DMABUF \
  56. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_DMABUF, \
  57. struct drm_vmw_unref_dmabuf_arg)
  58. #define DRM_IOCTL_VMW_CURSOR_BYPASS \
  59. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_CURSOR_BYPASS, \
  60. struct drm_vmw_cursor_bypass_arg)
  61. #define DRM_IOCTL_VMW_CONTROL_STREAM \
  62. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_CONTROL_STREAM, \
  63. struct drm_vmw_control_stream_arg)
  64. #define DRM_IOCTL_VMW_CLAIM_STREAM \
  65. DRM_IOR(DRM_COMMAND_BASE + DRM_VMW_CLAIM_STREAM, \
  66. struct drm_vmw_stream_arg)
  67. #define DRM_IOCTL_VMW_UNREF_STREAM \
  68. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_STREAM, \
  69. struct drm_vmw_stream_arg)
  70. #define DRM_IOCTL_VMW_CREATE_CONTEXT \
  71. DRM_IOR(DRM_COMMAND_BASE + DRM_VMW_CREATE_CONTEXT, \
  72. struct drm_vmw_context_arg)
  73. #define DRM_IOCTL_VMW_UNREF_CONTEXT \
  74. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_CONTEXT, \
  75. struct drm_vmw_context_arg)
  76. #define DRM_IOCTL_VMW_CREATE_SURFACE \
  77. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_CREATE_SURFACE, \
  78. union drm_vmw_surface_create_arg)
  79. #define DRM_IOCTL_VMW_UNREF_SURFACE \
  80. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_SURFACE, \
  81. struct drm_vmw_surface_arg)
  82. #define DRM_IOCTL_VMW_REF_SURFACE \
  83. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_REF_SURFACE, \
  84. union drm_vmw_surface_reference_arg)
  85. #define DRM_IOCTL_VMW_EXECBUF \
  86. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_EXECBUF, \
  87. struct drm_vmw_execbuf_arg)
  88. #define DRM_IOCTL_VMW_GET_3D_CAP \
  89. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_GET_3D_CAP, \
  90. struct drm_vmw_get_3d_cap_arg)
  91. #define DRM_IOCTL_VMW_FENCE_WAIT \
  92. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_FENCE_WAIT, \
  93. struct drm_vmw_fence_wait_arg)
  94. #define DRM_IOCTL_VMW_FENCE_SIGNALED \
  95. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_FENCE_SIGNALED, \
  96. struct drm_vmw_fence_signaled_arg)
  97. #define DRM_IOCTL_VMW_FENCE_UNREF \
  98. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_FENCE_UNREF, \
  99. struct drm_vmw_fence_arg)
  100. #define DRM_IOCTL_VMW_FENCE_EVENT \
  101. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_FENCE_EVENT, \
  102. struct drm_vmw_fence_event_arg)
  103. #define DRM_IOCTL_VMW_PRESENT \
  104. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT, \
  105. struct drm_vmw_present_arg)
  106. #define DRM_IOCTL_VMW_PRESENT_READBACK \
  107. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT_READBACK, \
  108. struct drm_vmw_present_readback_arg)
  109. #define DRM_IOCTL_VMW_UPDATE_LAYOUT \
  110. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UPDATE_LAYOUT, \
  111. struct drm_vmw_update_layout_arg)
  112. #define DRM_IOCTL_VMW_CREATE_SHADER \
  113. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_CREATE_SHADER, \
  114. struct drm_vmw_shader_create_arg)
  115. #define DRM_IOCTL_VMW_UNREF_SHADER \
  116. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_SHADER, \
  117. struct drm_vmw_shader_arg)
  118. #define DRM_IOCTL_VMW_GB_SURFACE_CREATE \
  119. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_GB_SURFACE_CREATE, \
  120. union drm_vmw_gb_surface_create_arg)
  121. #define DRM_IOCTL_VMW_GB_SURFACE_REF \
  122. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_GB_SURFACE_REF, \
  123. union drm_vmw_gb_surface_reference_arg)
  124. #define DRM_IOCTL_VMW_SYNCCPU \
  125. DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_SYNCCPU, \
  126. struct drm_vmw_synccpu_arg)
  127. #define DRM_IOCTL_VMW_CREATE_EXTENDED_CONTEXT \
  128. DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_CREATE_EXTENDED_CONTEXT, \
  129. struct drm_vmw_context_arg)
  130. /**
  131. * The core DRM version of this macro doesn't account for
  132. * DRM_COMMAND_BASE.
  133. */
  134. #define VMW_IOCTL_DEF(ioctl, func, flags) \
  135. [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {DRM_IOCTL_##ioctl, flags, func}
  136. /**
  137. * Ioctl definitions.
  138. */
  139. static const struct drm_ioctl_desc vmw_ioctls[] = {
  140. VMW_IOCTL_DEF(VMW_GET_PARAM, vmw_getparam_ioctl,
  141. DRM_AUTH | DRM_RENDER_ALLOW),
  142. VMW_IOCTL_DEF(VMW_ALLOC_DMABUF, vmw_dmabuf_alloc_ioctl,
  143. DRM_AUTH | DRM_RENDER_ALLOW),
  144. VMW_IOCTL_DEF(VMW_UNREF_DMABUF, vmw_dmabuf_unref_ioctl,
  145. DRM_RENDER_ALLOW),
  146. VMW_IOCTL_DEF(VMW_CURSOR_BYPASS,
  147. vmw_kms_cursor_bypass_ioctl,
  148. DRM_MASTER | DRM_CONTROL_ALLOW),
  149. VMW_IOCTL_DEF(VMW_CONTROL_STREAM, vmw_overlay_ioctl,
  150. DRM_MASTER | DRM_CONTROL_ALLOW),
  151. VMW_IOCTL_DEF(VMW_CLAIM_STREAM, vmw_stream_claim_ioctl,
  152. DRM_MASTER | DRM_CONTROL_ALLOW),
  153. VMW_IOCTL_DEF(VMW_UNREF_STREAM, vmw_stream_unref_ioctl,
  154. DRM_MASTER | DRM_CONTROL_ALLOW),
  155. VMW_IOCTL_DEF(VMW_CREATE_CONTEXT, vmw_context_define_ioctl,
  156. DRM_AUTH | DRM_RENDER_ALLOW),
  157. VMW_IOCTL_DEF(VMW_UNREF_CONTEXT, vmw_context_destroy_ioctl,
  158. DRM_RENDER_ALLOW),
  159. VMW_IOCTL_DEF(VMW_CREATE_SURFACE, vmw_surface_define_ioctl,
  160. DRM_AUTH | DRM_RENDER_ALLOW),
  161. VMW_IOCTL_DEF(VMW_UNREF_SURFACE, vmw_surface_destroy_ioctl,
  162. DRM_RENDER_ALLOW),
  163. VMW_IOCTL_DEF(VMW_REF_SURFACE, vmw_surface_reference_ioctl,
  164. DRM_AUTH | DRM_RENDER_ALLOW),
  165. VMW_IOCTL_DEF(VMW_EXECBUF, NULL, DRM_AUTH |
  166. DRM_RENDER_ALLOW),
  167. VMW_IOCTL_DEF(VMW_FENCE_WAIT, vmw_fence_obj_wait_ioctl,
  168. DRM_RENDER_ALLOW),
  169. VMW_IOCTL_DEF(VMW_FENCE_SIGNALED,
  170. vmw_fence_obj_signaled_ioctl,
  171. DRM_RENDER_ALLOW),
  172. VMW_IOCTL_DEF(VMW_FENCE_UNREF, vmw_fence_obj_unref_ioctl,
  173. DRM_RENDER_ALLOW),
  174. VMW_IOCTL_DEF(VMW_FENCE_EVENT, vmw_fence_event_ioctl,
  175. DRM_AUTH | DRM_RENDER_ALLOW),
  176. VMW_IOCTL_DEF(VMW_GET_3D_CAP, vmw_get_cap_3d_ioctl,
  177. DRM_AUTH | DRM_RENDER_ALLOW),
  178. /* these allow direct access to the framebuffers mark as master only */
  179. VMW_IOCTL_DEF(VMW_PRESENT, vmw_present_ioctl,
  180. DRM_MASTER | DRM_AUTH),
  181. VMW_IOCTL_DEF(VMW_PRESENT_READBACK,
  182. vmw_present_readback_ioctl,
  183. DRM_MASTER | DRM_AUTH),
  184. /*
  185. * The permissions of the below ioctl are overridden in
  186. * vmw_generic_ioctl(). We require either
  187. * DRM_MASTER or capable(CAP_SYS_ADMIN).
  188. */
  189. VMW_IOCTL_DEF(VMW_UPDATE_LAYOUT,
  190. vmw_kms_update_layout_ioctl,
  191. DRM_RENDER_ALLOW),
  192. VMW_IOCTL_DEF(VMW_CREATE_SHADER,
  193. vmw_shader_define_ioctl,
  194. DRM_AUTH | DRM_RENDER_ALLOW),
  195. VMW_IOCTL_DEF(VMW_UNREF_SHADER,
  196. vmw_shader_destroy_ioctl,
  197. DRM_RENDER_ALLOW),
  198. VMW_IOCTL_DEF(VMW_GB_SURFACE_CREATE,
  199. vmw_gb_surface_define_ioctl,
  200. DRM_AUTH | DRM_RENDER_ALLOW),
  201. VMW_IOCTL_DEF(VMW_GB_SURFACE_REF,
  202. vmw_gb_surface_reference_ioctl,
  203. DRM_AUTH | DRM_RENDER_ALLOW),
  204. VMW_IOCTL_DEF(VMW_SYNCCPU,
  205. vmw_user_dmabuf_synccpu_ioctl,
  206. DRM_RENDER_ALLOW),
  207. VMW_IOCTL_DEF(VMW_CREATE_EXTENDED_CONTEXT,
  208. vmw_extended_context_define_ioctl,
  209. DRM_AUTH | DRM_RENDER_ALLOW),
  210. };
  211. static const struct pci_device_id vmw_pci_id_list[] = {
  212. {0x15ad, 0x0405, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VMWGFX_CHIP_SVGAII},
  213. {0, 0, 0}
  214. };
  215. MODULE_DEVICE_TABLE(pci, vmw_pci_id_list);
  216. static int enable_fbdev = IS_ENABLED(CONFIG_DRM_VMWGFX_FBCON);
  217. static int vmw_force_iommu;
  218. static int vmw_restrict_iommu;
  219. static int vmw_force_coherent;
  220. static int vmw_restrict_dma_mask;
  221. static int vmw_assume_16bpp;
  222. static int vmw_probe(struct pci_dev *, const struct pci_device_id *);
  223. static void vmw_master_init(struct vmw_master *);
  224. static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
  225. void *ptr);
  226. MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev");
  227. module_param_named(enable_fbdev, enable_fbdev, int, 0600);
  228. MODULE_PARM_DESC(force_dma_api, "Force using the DMA API for TTM pages");
  229. module_param_named(force_dma_api, vmw_force_iommu, int, 0600);
  230. MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages");
  231. module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600);
  232. MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages");
  233. module_param_named(force_coherent, vmw_force_coherent, int, 0600);
  234. MODULE_PARM_DESC(restrict_dma_mask, "Restrict DMA mask to 44 bits with IOMMU");
  235. module_param_named(restrict_dma_mask, vmw_restrict_dma_mask, int, 0600);
  236. MODULE_PARM_DESC(assume_16bpp, "Assume 16-bpp when filtering modes");
  237. module_param_named(assume_16bpp, vmw_assume_16bpp, int, 0600);
  238. static void vmw_print_capabilities(uint32_t capabilities)
  239. {
  240. DRM_INFO("Capabilities:\n");
  241. if (capabilities & SVGA_CAP_RECT_COPY)
  242. DRM_INFO(" Rect copy.\n");
  243. if (capabilities & SVGA_CAP_CURSOR)
  244. DRM_INFO(" Cursor.\n");
  245. if (capabilities & SVGA_CAP_CURSOR_BYPASS)
  246. DRM_INFO(" Cursor bypass.\n");
  247. if (capabilities & SVGA_CAP_CURSOR_BYPASS_2)
  248. DRM_INFO(" Cursor bypass 2.\n");
  249. if (capabilities & SVGA_CAP_8BIT_EMULATION)
  250. DRM_INFO(" 8bit emulation.\n");
  251. if (capabilities & SVGA_CAP_ALPHA_CURSOR)
  252. DRM_INFO(" Alpha cursor.\n");
  253. if (capabilities & SVGA_CAP_3D)
  254. DRM_INFO(" 3D.\n");
  255. if (capabilities & SVGA_CAP_EXTENDED_FIFO)
  256. DRM_INFO(" Extended Fifo.\n");
  257. if (capabilities & SVGA_CAP_MULTIMON)
  258. DRM_INFO(" Multimon.\n");
  259. if (capabilities & SVGA_CAP_PITCHLOCK)
  260. DRM_INFO(" Pitchlock.\n");
  261. if (capabilities & SVGA_CAP_IRQMASK)
  262. DRM_INFO(" Irq mask.\n");
  263. if (capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)
  264. DRM_INFO(" Display Topology.\n");
  265. if (capabilities & SVGA_CAP_GMR)
  266. DRM_INFO(" GMR.\n");
  267. if (capabilities & SVGA_CAP_TRACES)
  268. DRM_INFO(" Traces.\n");
  269. if (capabilities & SVGA_CAP_GMR2)
  270. DRM_INFO(" GMR2.\n");
  271. if (capabilities & SVGA_CAP_SCREEN_OBJECT_2)
  272. DRM_INFO(" Screen Object 2.\n");
  273. if (capabilities & SVGA_CAP_COMMAND_BUFFERS)
  274. DRM_INFO(" Command Buffers.\n");
  275. if (capabilities & SVGA_CAP_CMD_BUFFERS_2)
  276. DRM_INFO(" Command Buffers 2.\n");
  277. if (capabilities & SVGA_CAP_GBOBJECTS)
  278. DRM_INFO(" Guest Backed Resources.\n");
  279. if (capabilities & SVGA_CAP_DX)
  280. DRM_INFO(" DX Features.\n");
  281. }
  282. /**
  283. * vmw_dummy_query_bo_create - create a bo to hold a dummy query result
  284. *
  285. * @dev_priv: A device private structure.
  286. *
  287. * This function creates a small buffer object that holds the query
  288. * result for dummy queries emitted as query barriers.
  289. * The function will then map the first page and initialize a pending
  290. * occlusion query result structure, Finally it will unmap the buffer.
  291. * No interruptible waits are done within this function.
  292. *
  293. * Returns an error if bo creation or initialization fails.
  294. */
  295. static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)
  296. {
  297. int ret;
  298. struct vmw_dma_buffer *vbo;
  299. struct ttm_bo_kmap_obj map;
  300. volatile SVGA3dQueryResult *result;
  301. bool dummy;
  302. /*
  303. * Create the vbo as pinned, so that a tryreserve will
  304. * immediately succeed. This is because we're the only
  305. * user of the bo currently.
  306. */
  307. vbo = kzalloc(sizeof(*vbo), GFP_KERNEL);
  308. if (!vbo)
  309. return -ENOMEM;
  310. ret = vmw_dmabuf_init(dev_priv, vbo, PAGE_SIZE,
  311. &vmw_sys_ne_placement, false,
  312. &vmw_dmabuf_bo_free);
  313. if (unlikely(ret != 0))
  314. return ret;
  315. ret = ttm_bo_reserve(&vbo->base, false, true, NULL);
  316. BUG_ON(ret != 0);
  317. vmw_bo_pin_reserved(vbo, true);
  318. ret = ttm_bo_kmap(&vbo->base, 0, 1, &map);
  319. if (likely(ret == 0)) {
  320. result = ttm_kmap_obj_virtual(&map, &dummy);
  321. result->totalSize = sizeof(*result);
  322. result->state = SVGA3D_QUERYSTATE_PENDING;
  323. result->result32 = 0xff;
  324. ttm_bo_kunmap(&map);
  325. }
  326. vmw_bo_pin_reserved(vbo, false);
  327. ttm_bo_unreserve(&vbo->base);
  328. if (unlikely(ret != 0)) {
  329. DRM_ERROR("Dummy query buffer map failed.\n");
  330. vmw_dmabuf_unreference(&vbo);
  331. } else
  332. dev_priv->dummy_query_bo = vbo;
  333. return ret;
  334. }
  335. /**
  336. * vmw_request_device_late - Perform late device setup
  337. *
  338. * @dev_priv: Pointer to device private.
  339. *
  340. * This function performs setup of otables and enables large command
  341. * buffer submission. These tasks are split out to a separate function
  342. * because it reverts vmw_release_device_early and is intended to be used
  343. * by an error path in the hibernation code.
  344. */
  345. static int vmw_request_device_late(struct vmw_private *dev_priv)
  346. {
  347. int ret;
  348. if (dev_priv->has_mob) {
  349. ret = vmw_otables_setup(dev_priv);
  350. if (unlikely(ret != 0)) {
  351. DRM_ERROR("Unable to initialize "
  352. "guest Memory OBjects.\n");
  353. return ret;
  354. }
  355. }
  356. if (dev_priv->cman) {
  357. ret = vmw_cmdbuf_set_pool_size(dev_priv->cman,
  358. 256*4096, 2*4096);
  359. if (ret) {
  360. struct vmw_cmdbuf_man *man = dev_priv->cman;
  361. dev_priv->cman = NULL;
  362. vmw_cmdbuf_man_destroy(man);
  363. }
  364. }
  365. return 0;
  366. }
  367. static int vmw_request_device(struct vmw_private *dev_priv)
  368. {
  369. int ret;
  370. ret = vmw_fifo_init(dev_priv, &dev_priv->fifo);
  371. if (unlikely(ret != 0)) {
  372. DRM_ERROR("Unable to initialize FIFO.\n");
  373. return ret;
  374. }
  375. vmw_fence_fifo_up(dev_priv->fman);
  376. dev_priv->cman = vmw_cmdbuf_man_create(dev_priv);
  377. if (IS_ERR(dev_priv->cman)) {
  378. dev_priv->cman = NULL;
  379. dev_priv->has_dx = false;
  380. }
  381. ret = vmw_request_device_late(dev_priv);
  382. if (ret)
  383. goto out_no_mob;
  384. ret = vmw_dummy_query_bo_create(dev_priv);
  385. if (unlikely(ret != 0))
  386. goto out_no_query_bo;
  387. return 0;
  388. out_no_query_bo:
  389. if (dev_priv->cman)
  390. vmw_cmdbuf_remove_pool(dev_priv->cman);
  391. if (dev_priv->has_mob) {
  392. (void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
  393. vmw_otables_takedown(dev_priv);
  394. }
  395. if (dev_priv->cman)
  396. vmw_cmdbuf_man_destroy(dev_priv->cman);
  397. out_no_mob:
  398. vmw_fence_fifo_down(dev_priv->fman);
  399. vmw_fifo_release(dev_priv, &dev_priv->fifo);
  400. return ret;
  401. }
  402. /**
  403. * vmw_release_device_early - Early part of fifo takedown.
  404. *
  405. * @dev_priv: Pointer to device private struct.
  406. *
  407. * This is the first part of command submission takedown, to be called before
  408. * buffer management is taken down.
  409. */
  410. static void vmw_release_device_early(struct vmw_private *dev_priv)
  411. {
  412. /*
  413. * Previous destructions should've released
  414. * the pinned bo.
  415. */
  416. BUG_ON(dev_priv->pinned_bo != NULL);
  417. vmw_dmabuf_unreference(&dev_priv->dummy_query_bo);
  418. if (dev_priv->cman)
  419. vmw_cmdbuf_remove_pool(dev_priv->cman);
  420. if (dev_priv->has_mob) {
  421. ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
  422. vmw_otables_takedown(dev_priv);
  423. }
  424. }
  425. /**
  426. * vmw_release_device_late - Late part of fifo takedown.
  427. *
  428. * @dev_priv: Pointer to device private struct.
  429. *
  430. * This is the last part of the command submission takedown, to be called when
  431. * command submission is no longer needed. It may wait on pending fences.
  432. */
  433. static void vmw_release_device_late(struct vmw_private *dev_priv)
  434. {
  435. vmw_fence_fifo_down(dev_priv->fman);
  436. if (dev_priv->cman)
  437. vmw_cmdbuf_man_destroy(dev_priv->cman);
  438. vmw_fifo_release(dev_priv, &dev_priv->fifo);
  439. }
  440. /**
  441. * Sets the initial_[width|height] fields on the given vmw_private.
  442. *
  443. * It does so by reading SVGA_REG_[WIDTH|HEIGHT] regs and then
  444. * clamping the value to fb_max_[width|height] fields and the
  445. * VMW_MIN_INITIAL_[WIDTH|HEIGHT].
  446. * If the values appear to be invalid, set them to
  447. * VMW_MIN_INITIAL_[WIDTH|HEIGHT].
  448. */
  449. static void vmw_get_initial_size(struct vmw_private *dev_priv)
  450. {
  451. uint32_t width;
  452. uint32_t height;
  453. width = vmw_read(dev_priv, SVGA_REG_WIDTH);
  454. height = vmw_read(dev_priv, SVGA_REG_HEIGHT);
  455. width = max_t(uint32_t, width, VMW_MIN_INITIAL_WIDTH);
  456. height = max_t(uint32_t, height, VMW_MIN_INITIAL_HEIGHT);
  457. if (width > dev_priv->fb_max_width ||
  458. height > dev_priv->fb_max_height) {
  459. /*
  460. * This is a host error and shouldn't occur.
  461. */
  462. width = VMW_MIN_INITIAL_WIDTH;
  463. height = VMW_MIN_INITIAL_HEIGHT;
  464. }
  465. dev_priv->initial_width = width;
  466. dev_priv->initial_height = height;
  467. }
  468. /**
  469. * vmw_dma_select_mode - Determine how DMA mappings should be set up for this
  470. * system.
  471. *
  472. * @dev_priv: Pointer to a struct vmw_private
  473. *
  474. * This functions tries to determine the IOMMU setup and what actions
  475. * need to be taken by the driver to make system pages visible to the
  476. * device.
  477. * If this function decides that DMA is not possible, it returns -EINVAL.
  478. * The driver may then try to disable features of the device that require
  479. * DMA.
  480. */
  481. static int vmw_dma_select_mode(struct vmw_private *dev_priv)
  482. {
  483. static const char *names[vmw_dma_map_max] = {
  484. [vmw_dma_phys] = "Using physical TTM page addresses.",
  485. [vmw_dma_alloc_coherent] = "Using coherent TTM pages.",
  486. [vmw_dma_map_populate] = "Keeping DMA mappings.",
  487. [vmw_dma_map_bind] = "Giving up DMA mappings early."};
  488. #ifdef CONFIG_X86
  489. const struct dma_map_ops *dma_ops = get_dma_ops(dev_priv->dev->dev);
  490. #ifdef CONFIG_INTEL_IOMMU
  491. if (intel_iommu_enabled) {
  492. dev_priv->map_mode = vmw_dma_map_populate;
  493. goto out_fixup;
  494. }
  495. #endif
  496. if (!(vmw_force_iommu || vmw_force_coherent)) {
  497. dev_priv->map_mode = vmw_dma_phys;
  498. DRM_INFO("DMA map mode: %s\n", names[dev_priv->map_mode]);
  499. return 0;
  500. }
  501. dev_priv->map_mode = vmw_dma_map_populate;
  502. if (dma_ops->sync_single_for_cpu)
  503. dev_priv->map_mode = vmw_dma_alloc_coherent;
  504. #ifdef CONFIG_SWIOTLB
  505. if (swiotlb_nr_tbl() == 0)
  506. dev_priv->map_mode = vmw_dma_map_populate;
  507. #endif
  508. #ifdef CONFIG_INTEL_IOMMU
  509. out_fixup:
  510. #endif
  511. if (dev_priv->map_mode == vmw_dma_map_populate &&
  512. vmw_restrict_iommu)
  513. dev_priv->map_mode = vmw_dma_map_bind;
  514. if (vmw_force_coherent)
  515. dev_priv->map_mode = vmw_dma_alloc_coherent;
  516. #if !defined(CONFIG_SWIOTLB) && !defined(CONFIG_INTEL_IOMMU)
  517. /*
  518. * No coherent page pool
  519. */
  520. if (dev_priv->map_mode == vmw_dma_alloc_coherent)
  521. return -EINVAL;
  522. #endif
  523. #else /* CONFIG_X86 */
  524. dev_priv->map_mode = vmw_dma_map_populate;
  525. #endif /* CONFIG_X86 */
  526. DRM_INFO("DMA map mode: %s\n", names[dev_priv->map_mode]);
  527. return 0;
  528. }
  529. /**
  530. * vmw_dma_masks - set required page- and dma masks
  531. *
  532. * @dev: Pointer to struct drm-device
  533. *
  534. * With 32-bit we can only handle 32 bit PFNs. Optionally set that
  535. * restriction also for 64-bit systems.
  536. */
  537. #ifdef CONFIG_INTEL_IOMMU
  538. static int vmw_dma_masks(struct vmw_private *dev_priv)
  539. {
  540. struct drm_device *dev = dev_priv->dev;
  541. int ret = 0;
  542. ret = dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(64));
  543. if (dev_priv->map_mode != vmw_dma_phys &&
  544. (sizeof(unsigned long) == 4 || vmw_restrict_dma_mask)) {
  545. DRM_INFO("Restricting DMA addresses to 44 bits.\n");
  546. return dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(44));
  547. }
  548. return ret;
  549. }
  550. #else
  551. static int vmw_dma_masks(struct vmw_private *dev_priv)
  552. {
  553. return 0;
  554. }
  555. #endif
  556. static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
  557. {
  558. struct vmw_private *dev_priv;
  559. int ret;
  560. uint32_t svga_id;
  561. enum vmw_res_type i;
  562. bool refuse_dma = false;
  563. char host_log[100] = {0};
  564. dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
  565. if (unlikely(!dev_priv)) {
  566. DRM_ERROR("Failed allocating a device private struct.\n");
  567. return -ENOMEM;
  568. }
  569. pci_set_master(dev->pdev);
  570. dev_priv->dev = dev;
  571. dev_priv->vmw_chipset = chipset;
  572. dev_priv->last_read_seqno = (uint32_t) -100;
  573. mutex_init(&dev_priv->cmdbuf_mutex);
  574. mutex_init(&dev_priv->release_mutex);
  575. mutex_init(&dev_priv->binding_mutex);
  576. mutex_init(&dev_priv->global_kms_state_mutex);
  577. rwlock_init(&dev_priv->resource_lock);
  578. ttm_lock_init(&dev_priv->reservation_sem);
  579. spin_lock_init(&dev_priv->hw_lock);
  580. spin_lock_init(&dev_priv->waiter_lock);
  581. spin_lock_init(&dev_priv->cap_lock);
  582. spin_lock_init(&dev_priv->svga_lock);
  583. spin_lock_init(&dev_priv->cursor_lock);
  584. for (i = vmw_res_context; i < vmw_res_max; ++i) {
  585. idr_init(&dev_priv->res_idr[i]);
  586. INIT_LIST_HEAD(&dev_priv->res_lru[i]);
  587. }
  588. mutex_init(&dev_priv->init_mutex);
  589. init_waitqueue_head(&dev_priv->fence_queue);
  590. init_waitqueue_head(&dev_priv->fifo_queue);
  591. dev_priv->fence_queue_waiters = 0;
  592. dev_priv->fifo_queue_waiters = 0;
  593. dev_priv->used_memory_size = 0;
  594. dev_priv->io_start = pci_resource_start(dev->pdev, 0);
  595. dev_priv->vram_start = pci_resource_start(dev->pdev, 1);
  596. dev_priv->mmio_start = pci_resource_start(dev->pdev, 2);
  597. dev_priv->assume_16bpp = !!vmw_assume_16bpp;
  598. dev_priv->enable_fb = enable_fbdev;
  599. vmw_write(dev_priv, SVGA_REG_ID, SVGA_ID_2);
  600. svga_id = vmw_read(dev_priv, SVGA_REG_ID);
  601. if (svga_id != SVGA_ID_2) {
  602. ret = -ENOSYS;
  603. DRM_ERROR("Unsupported SVGA ID 0x%x\n", svga_id);
  604. goto out_err0;
  605. }
  606. dev_priv->capabilities = vmw_read(dev_priv, SVGA_REG_CAPABILITIES);
  607. ret = vmw_dma_select_mode(dev_priv);
  608. if (unlikely(ret != 0)) {
  609. DRM_INFO("Restricting capabilities due to IOMMU setup.\n");
  610. refuse_dma = true;
  611. }
  612. dev_priv->vram_size = vmw_read(dev_priv, SVGA_REG_VRAM_SIZE);
  613. dev_priv->mmio_size = vmw_read(dev_priv, SVGA_REG_MEM_SIZE);
  614. dev_priv->fb_max_width = vmw_read(dev_priv, SVGA_REG_MAX_WIDTH);
  615. dev_priv->fb_max_height = vmw_read(dev_priv, SVGA_REG_MAX_HEIGHT);
  616. vmw_get_initial_size(dev_priv);
  617. if (dev_priv->capabilities & SVGA_CAP_GMR2) {
  618. dev_priv->max_gmr_ids =
  619. vmw_read(dev_priv, SVGA_REG_GMR_MAX_IDS);
  620. dev_priv->max_gmr_pages =
  621. vmw_read(dev_priv, SVGA_REG_GMRS_MAX_PAGES);
  622. dev_priv->memory_size =
  623. vmw_read(dev_priv, SVGA_REG_MEMORY_SIZE);
  624. dev_priv->memory_size -= dev_priv->vram_size;
  625. } else {
  626. /*
  627. * An arbitrary limit of 512MiB on surface
  628. * memory. But all HWV8 hardware supports GMR2.
  629. */
  630. dev_priv->memory_size = 512*1024*1024;
  631. }
  632. dev_priv->max_mob_pages = 0;
  633. dev_priv->max_mob_size = 0;
  634. if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) {
  635. uint64_t mem_size =
  636. vmw_read(dev_priv,
  637. SVGA_REG_SUGGESTED_GBOBJECT_MEM_SIZE_KB);
  638. /*
  639. * Workaround for low memory 2D VMs to compensate for the
  640. * allocation taken by fbdev
  641. */
  642. if (!(dev_priv->capabilities & SVGA_CAP_3D))
  643. mem_size *= 3;
  644. dev_priv->max_mob_pages = mem_size * 1024 / PAGE_SIZE;
  645. dev_priv->prim_bb_mem =
  646. vmw_read(dev_priv,
  647. SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM);
  648. dev_priv->max_mob_size =
  649. vmw_read(dev_priv, SVGA_REG_MOB_MAX_SIZE);
  650. dev_priv->stdu_max_width =
  651. vmw_read(dev_priv, SVGA_REG_SCREENTARGET_MAX_WIDTH);
  652. dev_priv->stdu_max_height =
  653. vmw_read(dev_priv, SVGA_REG_SCREENTARGET_MAX_HEIGHT);
  654. vmw_write(dev_priv, SVGA_REG_DEV_CAP,
  655. SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH);
  656. dev_priv->texture_max_width = vmw_read(dev_priv,
  657. SVGA_REG_DEV_CAP);
  658. vmw_write(dev_priv, SVGA_REG_DEV_CAP,
  659. SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT);
  660. dev_priv->texture_max_height = vmw_read(dev_priv,
  661. SVGA_REG_DEV_CAP);
  662. } else {
  663. dev_priv->texture_max_width = 8192;
  664. dev_priv->texture_max_height = 8192;
  665. dev_priv->prim_bb_mem = dev_priv->vram_size;
  666. }
  667. vmw_print_capabilities(dev_priv->capabilities);
  668. ret = vmw_dma_masks(dev_priv);
  669. if (unlikely(ret != 0))
  670. goto out_err0;
  671. if (dev_priv->capabilities & SVGA_CAP_GMR2) {
  672. DRM_INFO("Max GMR ids is %u\n",
  673. (unsigned)dev_priv->max_gmr_ids);
  674. DRM_INFO("Max number of GMR pages is %u\n",
  675. (unsigned)dev_priv->max_gmr_pages);
  676. DRM_INFO("Max dedicated hypervisor surface memory is %u kiB\n",
  677. (unsigned)dev_priv->memory_size / 1024);
  678. }
  679. DRM_INFO("Maximum display memory size is %u kiB\n",
  680. dev_priv->prim_bb_mem / 1024);
  681. DRM_INFO("VRAM at 0x%08x size is %u kiB\n",
  682. dev_priv->vram_start, dev_priv->vram_size / 1024);
  683. DRM_INFO("MMIO at 0x%08x size is %u kiB\n",
  684. dev_priv->mmio_start, dev_priv->mmio_size / 1024);
  685. ret = vmw_ttm_global_init(dev_priv);
  686. if (unlikely(ret != 0))
  687. goto out_err0;
  688. vmw_master_init(&dev_priv->fbdev_master);
  689. ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM);
  690. dev_priv->active_master = &dev_priv->fbdev_master;
  691. dev_priv->mmio_virt = memremap(dev_priv->mmio_start,
  692. dev_priv->mmio_size, MEMREMAP_WB);
  693. if (unlikely(dev_priv->mmio_virt == NULL)) {
  694. ret = -ENOMEM;
  695. DRM_ERROR("Failed mapping MMIO.\n");
  696. goto out_err3;
  697. }
  698. /* Need mmio memory to check for fifo pitchlock cap. */
  699. if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY) &&
  700. !(dev_priv->capabilities & SVGA_CAP_PITCHLOCK) &&
  701. !vmw_fifo_have_pitchlock(dev_priv)) {
  702. ret = -ENOSYS;
  703. DRM_ERROR("Hardware has no pitchlock\n");
  704. goto out_err4;
  705. }
  706. dev_priv->tdev = ttm_object_device_init
  707. (dev_priv->mem_global_ref.object, 12, &vmw_prime_dmabuf_ops);
  708. if (unlikely(dev_priv->tdev == NULL)) {
  709. DRM_ERROR("Unable to initialize TTM object management.\n");
  710. ret = -ENOMEM;
  711. goto out_err4;
  712. }
  713. dev->dev_private = dev_priv;
  714. ret = pci_request_regions(dev->pdev, "vmwgfx probe");
  715. dev_priv->stealth = (ret != 0);
  716. if (dev_priv->stealth) {
  717. /**
  718. * Request at least the mmio PCI resource.
  719. */
  720. DRM_INFO("It appears like vesafb is loaded. "
  721. "Ignore above error if any.\n");
  722. ret = pci_request_region(dev->pdev, 2, "vmwgfx stealth probe");
  723. if (unlikely(ret != 0)) {
  724. DRM_ERROR("Failed reserving the SVGA MMIO resource.\n");
  725. goto out_no_device;
  726. }
  727. }
  728. if (dev_priv->capabilities & SVGA_CAP_IRQMASK) {
  729. ret = vmw_irq_install(dev, dev->pdev->irq);
  730. if (ret != 0) {
  731. DRM_ERROR("Failed installing irq: %d\n", ret);
  732. goto out_no_irq;
  733. }
  734. }
  735. dev_priv->fman = vmw_fence_manager_init(dev_priv);
  736. if (unlikely(dev_priv->fman == NULL)) {
  737. ret = -ENOMEM;
  738. goto out_no_fman;
  739. }
  740. ret = ttm_bo_device_init(&dev_priv->bdev,
  741. dev_priv->bo_global_ref.ref.object,
  742. &vmw_bo_driver,
  743. dev->anon_inode->i_mapping,
  744. VMWGFX_FILE_PAGE_OFFSET,
  745. false);
  746. if (unlikely(ret != 0)) {
  747. DRM_ERROR("Failed initializing TTM buffer object driver.\n");
  748. goto out_no_bdev;
  749. }
  750. /*
  751. * Enable VRAM, but initially don't use it until SVGA is enabled and
  752. * unhidden.
  753. */
  754. ret = ttm_bo_init_mm(&dev_priv->bdev, TTM_PL_VRAM,
  755. (dev_priv->vram_size >> PAGE_SHIFT));
  756. if (unlikely(ret != 0)) {
  757. DRM_ERROR("Failed initializing memory manager for VRAM.\n");
  758. goto out_no_vram;
  759. }
  760. dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
  761. dev_priv->has_gmr = true;
  762. if (((dev_priv->capabilities & (SVGA_CAP_GMR | SVGA_CAP_GMR2)) == 0) ||
  763. refuse_dma || ttm_bo_init_mm(&dev_priv->bdev, VMW_PL_GMR,
  764. VMW_PL_GMR) != 0) {
  765. DRM_INFO("No GMR memory available. "
  766. "Graphics memory resources are very limited.\n");
  767. dev_priv->has_gmr = false;
  768. }
  769. if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS) {
  770. dev_priv->has_mob = true;
  771. if (ttm_bo_init_mm(&dev_priv->bdev, VMW_PL_MOB,
  772. VMW_PL_MOB) != 0) {
  773. DRM_INFO("No MOB memory available. "
  774. "3D will be disabled.\n");
  775. dev_priv->has_mob = false;
  776. }
  777. }
  778. if (dev_priv->has_mob) {
  779. spin_lock(&dev_priv->cap_lock);
  780. vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_DX);
  781. dev_priv->has_dx = !!vmw_read(dev_priv, SVGA_REG_DEV_CAP);
  782. spin_unlock(&dev_priv->cap_lock);
  783. }
  784. ret = vmw_kms_init(dev_priv);
  785. if (unlikely(ret != 0))
  786. goto out_no_kms;
  787. vmw_overlay_init(dev_priv);
  788. ret = vmw_request_device(dev_priv);
  789. if (ret)
  790. goto out_no_fifo;
  791. DRM_INFO("DX: %s\n", dev_priv->has_dx ? "yes." : "no.");
  792. DRM_INFO("Atomic: %s\n",
  793. (dev->driver->driver_features & DRIVER_ATOMIC) ? "yes" : "no");
  794. snprintf(host_log, sizeof(host_log), "vmwgfx: %s-%s",
  795. VMWGFX_REPO, VMWGFX_GIT_VERSION);
  796. vmw_host_log(host_log);
  797. memset(host_log, 0, sizeof(host_log));
  798. snprintf(host_log, sizeof(host_log), "vmwgfx: Module Version: %d.%d.%d",
  799. VMWGFX_DRIVER_MAJOR, VMWGFX_DRIVER_MINOR,
  800. VMWGFX_DRIVER_PATCHLEVEL);
  801. vmw_host_log(host_log);
  802. if (dev_priv->enable_fb) {
  803. vmw_fifo_resource_inc(dev_priv);
  804. vmw_svga_enable(dev_priv);
  805. vmw_fb_init(dev_priv);
  806. }
  807. dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier;
  808. register_pm_notifier(&dev_priv->pm_nb);
  809. return 0;
  810. out_no_fifo:
  811. vmw_overlay_close(dev_priv);
  812. vmw_kms_close(dev_priv);
  813. out_no_kms:
  814. if (dev_priv->has_mob)
  815. (void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_MOB);
  816. if (dev_priv->has_gmr)
  817. (void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR);
  818. (void)ttm_bo_clean_mm(&dev_priv->bdev, TTM_PL_VRAM);
  819. out_no_vram:
  820. (void)ttm_bo_device_release(&dev_priv->bdev);
  821. out_no_bdev:
  822. vmw_fence_manager_takedown(dev_priv->fman);
  823. out_no_fman:
  824. if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
  825. vmw_irq_uninstall(dev_priv->dev);
  826. out_no_irq:
  827. if (dev_priv->stealth)
  828. pci_release_region(dev->pdev, 2);
  829. else
  830. pci_release_regions(dev->pdev);
  831. out_no_device:
  832. ttm_object_device_release(&dev_priv->tdev);
  833. out_err4:
  834. memunmap(dev_priv->mmio_virt);
  835. out_err3:
  836. vmw_ttm_global_release(dev_priv);
  837. out_err0:
  838. for (i = vmw_res_context; i < vmw_res_max; ++i)
  839. idr_destroy(&dev_priv->res_idr[i]);
  840. if (dev_priv->ctx.staged_bindings)
  841. vmw_binding_state_free(dev_priv->ctx.staged_bindings);
  842. kfree(dev_priv);
  843. return ret;
  844. }
  845. static void vmw_driver_unload(struct drm_device *dev)
  846. {
  847. struct vmw_private *dev_priv = vmw_priv(dev);
  848. enum vmw_res_type i;
  849. unregister_pm_notifier(&dev_priv->pm_nb);
  850. if (dev_priv->ctx.res_ht_initialized)
  851. drm_ht_remove(&dev_priv->ctx.res_ht);
  852. vfree(dev_priv->ctx.cmd_bounce);
  853. if (dev_priv->enable_fb) {
  854. vmw_fb_off(dev_priv);
  855. vmw_fb_close(dev_priv);
  856. vmw_fifo_resource_dec(dev_priv);
  857. vmw_svga_disable(dev_priv);
  858. }
  859. vmw_kms_close(dev_priv);
  860. vmw_overlay_close(dev_priv);
  861. if (dev_priv->has_gmr)
  862. (void)ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR);
  863. (void)ttm_bo_clean_mm(&dev_priv->bdev, TTM_PL_VRAM);
  864. vmw_release_device_early(dev_priv);
  865. if (dev_priv->has_mob)
  866. (void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_MOB);
  867. (void) ttm_bo_device_release(&dev_priv->bdev);
  868. vmw_release_device_late(dev_priv);
  869. vmw_fence_manager_takedown(dev_priv->fman);
  870. if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
  871. vmw_irq_uninstall(dev_priv->dev);
  872. if (dev_priv->stealth)
  873. pci_release_region(dev->pdev, 2);
  874. else
  875. pci_release_regions(dev->pdev);
  876. ttm_object_device_release(&dev_priv->tdev);
  877. memunmap(dev_priv->mmio_virt);
  878. if (dev_priv->ctx.staged_bindings)
  879. vmw_binding_state_free(dev_priv->ctx.staged_bindings);
  880. vmw_ttm_global_release(dev_priv);
  881. for (i = vmw_res_context; i < vmw_res_max; ++i)
  882. idr_destroy(&dev_priv->res_idr[i]);
  883. kfree(dev_priv);
  884. }
  885. static void vmw_postclose(struct drm_device *dev,
  886. struct drm_file *file_priv)
  887. {
  888. struct vmw_fpriv *vmw_fp;
  889. vmw_fp = vmw_fpriv(file_priv);
  890. if (vmw_fp->locked_master) {
  891. struct vmw_master *vmaster =
  892. vmw_master(vmw_fp->locked_master);
  893. ttm_lock_set_kill(&vmaster->lock, true, SIGTERM);
  894. ttm_vt_unlock(&vmaster->lock);
  895. drm_master_put(&vmw_fp->locked_master);
  896. }
  897. ttm_object_file_release(&vmw_fp->tfile);
  898. kfree(vmw_fp);
  899. }
  900. static int vmw_driver_open(struct drm_device *dev, struct drm_file *file_priv)
  901. {
  902. struct vmw_private *dev_priv = vmw_priv(dev);
  903. struct vmw_fpriv *vmw_fp;
  904. int ret = -ENOMEM;
  905. vmw_fp = kzalloc(sizeof(*vmw_fp), GFP_KERNEL);
  906. if (unlikely(!vmw_fp))
  907. return ret;
  908. vmw_fp->tfile = ttm_object_file_init(dev_priv->tdev, 10);
  909. if (unlikely(vmw_fp->tfile == NULL))
  910. goto out_no_tfile;
  911. file_priv->driver_priv = vmw_fp;
  912. return 0;
  913. out_no_tfile:
  914. kfree(vmw_fp);
  915. return ret;
  916. }
  917. static struct vmw_master *vmw_master_check(struct drm_device *dev,
  918. struct drm_file *file_priv,
  919. unsigned int flags)
  920. {
  921. int ret;
  922. struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
  923. struct vmw_master *vmaster;
  924. if (!drm_is_primary_client(file_priv) || !(flags & DRM_AUTH))
  925. return NULL;
  926. ret = mutex_lock_interruptible(&dev->master_mutex);
  927. if (unlikely(ret != 0))
  928. return ERR_PTR(-ERESTARTSYS);
  929. if (drm_is_current_master(file_priv)) {
  930. mutex_unlock(&dev->master_mutex);
  931. return NULL;
  932. }
  933. /*
  934. * Check if we were previously master, but now dropped. In that
  935. * case, allow at least render node functionality.
  936. */
  937. if (vmw_fp->locked_master) {
  938. mutex_unlock(&dev->master_mutex);
  939. if (flags & DRM_RENDER_ALLOW)
  940. return NULL;
  941. DRM_ERROR("Dropped master trying to access ioctl that "
  942. "requires authentication.\n");
  943. return ERR_PTR(-EACCES);
  944. }
  945. mutex_unlock(&dev->master_mutex);
  946. /*
  947. * Take the TTM lock. Possibly sleep waiting for the authenticating
  948. * master to become master again, or for a SIGTERM if the
  949. * authenticating master exits.
  950. */
  951. vmaster = vmw_master(file_priv->master);
  952. ret = ttm_read_lock(&vmaster->lock, true);
  953. if (unlikely(ret != 0))
  954. vmaster = ERR_PTR(ret);
  955. return vmaster;
  956. }
  957. static long vmw_generic_ioctl(struct file *filp, unsigned int cmd,
  958. unsigned long arg,
  959. long (*ioctl_func)(struct file *, unsigned int,
  960. unsigned long))
  961. {
  962. struct drm_file *file_priv = filp->private_data;
  963. struct drm_device *dev = file_priv->minor->dev;
  964. unsigned int nr = DRM_IOCTL_NR(cmd);
  965. struct vmw_master *vmaster;
  966. unsigned int flags;
  967. long ret;
  968. /*
  969. * Do extra checking on driver private ioctls.
  970. */
  971. if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END)
  972. && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls)) {
  973. const struct drm_ioctl_desc *ioctl =
  974. &vmw_ioctls[nr - DRM_COMMAND_BASE];
  975. if (nr == DRM_COMMAND_BASE + DRM_VMW_EXECBUF) {
  976. ret = (long) drm_ioctl_permit(ioctl->flags, file_priv);
  977. if (unlikely(ret != 0))
  978. return ret;
  979. if (unlikely((cmd & (IOC_IN | IOC_OUT)) != IOC_IN))
  980. goto out_io_encoding;
  981. return (long) vmw_execbuf_ioctl(dev, arg, file_priv,
  982. _IOC_SIZE(cmd));
  983. } else if (nr == DRM_COMMAND_BASE + DRM_VMW_UPDATE_LAYOUT) {
  984. if (!drm_is_current_master(file_priv) &&
  985. !capable(CAP_SYS_ADMIN))
  986. return -EACCES;
  987. }
  988. if (unlikely(ioctl->cmd != cmd))
  989. goto out_io_encoding;
  990. flags = ioctl->flags;
  991. } else if (!drm_ioctl_flags(nr, &flags))
  992. return -EINVAL;
  993. vmaster = vmw_master_check(dev, file_priv, flags);
  994. if (IS_ERR(vmaster)) {
  995. ret = PTR_ERR(vmaster);
  996. if (ret != -ERESTARTSYS)
  997. DRM_INFO("IOCTL ERROR Command %d, Error %ld.\n",
  998. nr, ret);
  999. return ret;
  1000. }
  1001. ret = ioctl_func(filp, cmd, arg);
  1002. if (vmaster)
  1003. ttm_read_unlock(&vmaster->lock);
  1004. return ret;
  1005. out_io_encoding:
  1006. DRM_ERROR("Invalid command format, ioctl %d\n",
  1007. nr - DRM_COMMAND_BASE);
  1008. return -EINVAL;
  1009. }
  1010. static long vmw_unlocked_ioctl(struct file *filp, unsigned int cmd,
  1011. unsigned long arg)
  1012. {
  1013. return vmw_generic_ioctl(filp, cmd, arg, &drm_ioctl);
  1014. }
  1015. #ifdef CONFIG_COMPAT
  1016. static long vmw_compat_ioctl(struct file *filp, unsigned int cmd,
  1017. unsigned long arg)
  1018. {
  1019. return vmw_generic_ioctl(filp, cmd, arg, &drm_compat_ioctl);
  1020. }
  1021. #endif
  1022. static void vmw_lastclose(struct drm_device *dev)
  1023. {
  1024. }
  1025. static void vmw_master_init(struct vmw_master *vmaster)
  1026. {
  1027. ttm_lock_init(&vmaster->lock);
  1028. }
  1029. static int vmw_master_create(struct drm_device *dev,
  1030. struct drm_master *master)
  1031. {
  1032. struct vmw_master *vmaster;
  1033. vmaster = kzalloc(sizeof(*vmaster), GFP_KERNEL);
  1034. if (unlikely(!vmaster))
  1035. return -ENOMEM;
  1036. vmw_master_init(vmaster);
  1037. ttm_lock_set_kill(&vmaster->lock, true, SIGTERM);
  1038. master->driver_priv = vmaster;
  1039. return 0;
  1040. }
  1041. static void vmw_master_destroy(struct drm_device *dev,
  1042. struct drm_master *master)
  1043. {
  1044. struct vmw_master *vmaster = vmw_master(master);
  1045. master->driver_priv = NULL;
  1046. kfree(vmaster);
  1047. }
  1048. static int vmw_master_set(struct drm_device *dev,
  1049. struct drm_file *file_priv,
  1050. bool from_open)
  1051. {
  1052. struct vmw_private *dev_priv = vmw_priv(dev);
  1053. struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
  1054. struct vmw_master *active = dev_priv->active_master;
  1055. struct vmw_master *vmaster = vmw_master(file_priv->master);
  1056. int ret = 0;
  1057. if (active) {
  1058. BUG_ON(active != &dev_priv->fbdev_master);
  1059. ret = ttm_vt_lock(&active->lock, false, vmw_fp->tfile);
  1060. if (unlikely(ret != 0))
  1061. return ret;
  1062. ttm_lock_set_kill(&active->lock, true, SIGTERM);
  1063. dev_priv->active_master = NULL;
  1064. }
  1065. ttm_lock_set_kill(&vmaster->lock, false, SIGTERM);
  1066. if (!from_open) {
  1067. ttm_vt_unlock(&vmaster->lock);
  1068. BUG_ON(vmw_fp->locked_master != file_priv->master);
  1069. drm_master_put(&vmw_fp->locked_master);
  1070. }
  1071. dev_priv->active_master = vmaster;
  1072. /*
  1073. * Inform a new master that the layout may have changed while
  1074. * it was gone.
  1075. */
  1076. if (!from_open)
  1077. drm_sysfs_hotplug_event(dev);
  1078. return 0;
  1079. }
  1080. static void vmw_master_drop(struct drm_device *dev,
  1081. struct drm_file *file_priv)
  1082. {
  1083. struct vmw_private *dev_priv = vmw_priv(dev);
  1084. struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
  1085. struct vmw_master *vmaster = vmw_master(file_priv->master);
  1086. int ret;
  1087. /**
  1088. * Make sure the master doesn't disappear while we have
  1089. * it locked.
  1090. */
  1091. vmw_fp->locked_master = drm_master_get(file_priv->master);
  1092. ret = ttm_vt_lock(&vmaster->lock, false, vmw_fp->tfile);
  1093. vmw_kms_legacy_hotspot_clear(dev_priv);
  1094. if (unlikely((ret != 0))) {
  1095. DRM_ERROR("Unable to lock TTM at VT switch.\n");
  1096. drm_master_put(&vmw_fp->locked_master);
  1097. }
  1098. ttm_lock_set_kill(&vmaster->lock, false, SIGTERM);
  1099. if (!dev_priv->enable_fb)
  1100. vmw_svga_disable(dev_priv);
  1101. dev_priv->active_master = &dev_priv->fbdev_master;
  1102. ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM);
  1103. ttm_vt_unlock(&dev_priv->fbdev_master.lock);
  1104. if (dev_priv->enable_fb)
  1105. vmw_fb_on(dev_priv);
  1106. }
  1107. /**
  1108. * __vmw_svga_enable - Enable SVGA mode, FIFO and use of VRAM.
  1109. *
  1110. * @dev_priv: Pointer to device private struct.
  1111. * Needs the reservation sem to be held in non-exclusive mode.
  1112. */
  1113. static void __vmw_svga_enable(struct vmw_private *dev_priv)
  1114. {
  1115. spin_lock(&dev_priv->svga_lock);
  1116. if (!dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
  1117. vmw_write(dev_priv, SVGA_REG_ENABLE, SVGA_REG_ENABLE);
  1118. dev_priv->bdev.man[TTM_PL_VRAM].use_type = true;
  1119. }
  1120. spin_unlock(&dev_priv->svga_lock);
  1121. }
  1122. /**
  1123. * vmw_svga_enable - Enable SVGA mode, FIFO and use of VRAM.
  1124. *
  1125. * @dev_priv: Pointer to device private struct.
  1126. */
  1127. void vmw_svga_enable(struct vmw_private *dev_priv)
  1128. {
  1129. (void) ttm_read_lock(&dev_priv->reservation_sem, false);
  1130. __vmw_svga_enable(dev_priv);
  1131. ttm_read_unlock(&dev_priv->reservation_sem);
  1132. }
  1133. /**
  1134. * __vmw_svga_disable - Disable SVGA mode and use of VRAM.
  1135. *
  1136. * @dev_priv: Pointer to device private struct.
  1137. * Needs the reservation sem to be held in exclusive mode.
  1138. * Will not empty VRAM. VRAM must be emptied by caller.
  1139. */
  1140. static void __vmw_svga_disable(struct vmw_private *dev_priv)
  1141. {
  1142. spin_lock(&dev_priv->svga_lock);
  1143. if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
  1144. dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
  1145. vmw_write(dev_priv, SVGA_REG_ENABLE,
  1146. SVGA_REG_ENABLE_HIDE |
  1147. SVGA_REG_ENABLE_ENABLE);
  1148. }
  1149. spin_unlock(&dev_priv->svga_lock);
  1150. }
  1151. /**
  1152. * vmw_svga_disable - Disable SVGA_MODE, and use of VRAM. Keep the fifo
  1153. * running.
  1154. *
  1155. * @dev_priv: Pointer to device private struct.
  1156. * Will empty VRAM.
  1157. */
  1158. void vmw_svga_disable(struct vmw_private *dev_priv)
  1159. {
  1160. /*
  1161. * Disabling SVGA will turn off device modesetting capabilities, so
  1162. * notify KMS about that so that it doesn't cache atomic state that
  1163. * isn't valid anymore, for example crtcs turned on.
  1164. * Strictly we'd want to do this under the SVGA lock (or an SVGA mutex),
  1165. * but vmw_kms_lost_device() takes the reservation sem and thus we'll
  1166. * end up with lock order reversal. Thus, a master may actually perform
  1167. * a new modeset just after we call vmw_kms_lost_device() and race with
  1168. * vmw_svga_disable(), but that should at worst cause atomic KMS state
  1169. * to be inconsistent with the device, causing modesetting problems.
  1170. *
  1171. */
  1172. vmw_kms_lost_device(dev_priv->dev);
  1173. ttm_write_lock(&dev_priv->reservation_sem, false);
  1174. spin_lock(&dev_priv->svga_lock);
  1175. if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
  1176. dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
  1177. spin_unlock(&dev_priv->svga_lock);
  1178. if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
  1179. DRM_ERROR("Failed evicting VRAM buffers.\n");
  1180. vmw_write(dev_priv, SVGA_REG_ENABLE,
  1181. SVGA_REG_ENABLE_HIDE |
  1182. SVGA_REG_ENABLE_ENABLE);
  1183. } else
  1184. spin_unlock(&dev_priv->svga_lock);
  1185. ttm_write_unlock(&dev_priv->reservation_sem);
  1186. }
  1187. static void vmw_remove(struct pci_dev *pdev)
  1188. {
  1189. struct drm_device *dev = pci_get_drvdata(pdev);
  1190. pci_disable_device(pdev);
  1191. drm_put_dev(dev);
  1192. }
  1193. static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
  1194. void *ptr)
  1195. {
  1196. struct vmw_private *dev_priv =
  1197. container_of(nb, struct vmw_private, pm_nb);
  1198. switch (val) {
  1199. case PM_HIBERNATION_PREPARE:
  1200. if (dev_priv->enable_fb)
  1201. vmw_fb_off(dev_priv);
  1202. ttm_suspend_lock(&dev_priv->reservation_sem);
  1203. /*
  1204. * This empties VRAM and unbinds all GMR bindings.
  1205. * Buffer contents is moved to swappable memory.
  1206. */
  1207. vmw_execbuf_release_pinned_bo(dev_priv);
  1208. vmw_resource_evict_all(dev_priv);
  1209. vmw_release_device_early(dev_priv);
  1210. ttm_bo_swapout_all(&dev_priv->bdev);
  1211. vmw_fence_fifo_down(dev_priv->fman);
  1212. break;
  1213. case PM_POST_HIBERNATION:
  1214. case PM_POST_RESTORE:
  1215. vmw_fence_fifo_up(dev_priv->fman);
  1216. ttm_suspend_unlock(&dev_priv->reservation_sem);
  1217. if (dev_priv->enable_fb)
  1218. vmw_fb_on(dev_priv);
  1219. break;
  1220. case PM_RESTORE_PREPARE:
  1221. break;
  1222. default:
  1223. break;
  1224. }
  1225. return 0;
  1226. }
  1227. static int vmw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1228. {
  1229. struct drm_device *dev = pci_get_drvdata(pdev);
  1230. struct vmw_private *dev_priv = vmw_priv(dev);
  1231. if (dev_priv->refuse_hibernation)
  1232. return -EBUSY;
  1233. pci_save_state(pdev);
  1234. pci_disable_device(pdev);
  1235. pci_set_power_state(pdev, PCI_D3hot);
  1236. return 0;
  1237. }
  1238. static int vmw_pci_resume(struct pci_dev *pdev)
  1239. {
  1240. pci_set_power_state(pdev, PCI_D0);
  1241. pci_restore_state(pdev);
  1242. return pci_enable_device(pdev);
  1243. }
  1244. static int vmw_pm_suspend(struct device *kdev)
  1245. {
  1246. struct pci_dev *pdev = to_pci_dev(kdev);
  1247. struct pm_message dummy;
  1248. dummy.event = 0;
  1249. return vmw_pci_suspend(pdev, dummy);
  1250. }
  1251. static int vmw_pm_resume(struct device *kdev)
  1252. {
  1253. struct pci_dev *pdev = to_pci_dev(kdev);
  1254. return vmw_pci_resume(pdev);
  1255. }
  1256. static int vmw_pm_freeze(struct device *kdev)
  1257. {
  1258. struct pci_dev *pdev = to_pci_dev(kdev);
  1259. struct drm_device *dev = pci_get_drvdata(pdev);
  1260. struct vmw_private *dev_priv = vmw_priv(dev);
  1261. dev_priv->suspended = true;
  1262. if (dev_priv->enable_fb)
  1263. vmw_fifo_resource_dec(dev_priv);
  1264. if (atomic_read(&dev_priv->num_fifo_resources) != 0) {
  1265. DRM_ERROR("Can't hibernate while 3D resources are active.\n");
  1266. if (dev_priv->enable_fb)
  1267. vmw_fifo_resource_inc(dev_priv);
  1268. WARN_ON(vmw_request_device_late(dev_priv));
  1269. dev_priv->suspended = false;
  1270. return -EBUSY;
  1271. }
  1272. if (dev_priv->enable_fb)
  1273. __vmw_svga_disable(dev_priv);
  1274. vmw_release_device_late(dev_priv);
  1275. return 0;
  1276. }
  1277. static int vmw_pm_restore(struct device *kdev)
  1278. {
  1279. struct pci_dev *pdev = to_pci_dev(kdev);
  1280. struct drm_device *dev = pci_get_drvdata(pdev);
  1281. struct vmw_private *dev_priv = vmw_priv(dev);
  1282. int ret;
  1283. vmw_write(dev_priv, SVGA_REG_ID, SVGA_ID_2);
  1284. (void) vmw_read(dev_priv, SVGA_REG_ID);
  1285. if (dev_priv->enable_fb)
  1286. vmw_fifo_resource_inc(dev_priv);
  1287. ret = vmw_request_device(dev_priv);
  1288. if (ret)
  1289. return ret;
  1290. if (dev_priv->enable_fb)
  1291. __vmw_svga_enable(dev_priv);
  1292. dev_priv->suspended = false;
  1293. return 0;
  1294. }
  1295. static const struct dev_pm_ops vmw_pm_ops = {
  1296. .freeze = vmw_pm_freeze,
  1297. .thaw = vmw_pm_restore,
  1298. .restore = vmw_pm_restore,
  1299. .suspend = vmw_pm_suspend,
  1300. .resume = vmw_pm_resume,
  1301. };
  1302. static const struct file_operations vmwgfx_driver_fops = {
  1303. .owner = THIS_MODULE,
  1304. .open = drm_open,
  1305. .release = drm_release,
  1306. .unlocked_ioctl = vmw_unlocked_ioctl,
  1307. .mmap = vmw_mmap,
  1308. .poll = vmw_fops_poll,
  1309. .read = vmw_fops_read,
  1310. #if defined(CONFIG_COMPAT)
  1311. .compat_ioctl = vmw_compat_ioctl,
  1312. #endif
  1313. .llseek = noop_llseek,
  1314. };
  1315. static struct drm_driver driver = {
  1316. .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
  1317. DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER | DRIVER_ATOMIC,
  1318. .load = vmw_driver_load,
  1319. .unload = vmw_driver_unload,
  1320. .lastclose = vmw_lastclose,
  1321. .get_vblank_counter = vmw_get_vblank_counter,
  1322. .enable_vblank = vmw_enable_vblank,
  1323. .disable_vblank = vmw_disable_vblank,
  1324. .ioctls = vmw_ioctls,
  1325. .num_ioctls = ARRAY_SIZE(vmw_ioctls),
  1326. .master_create = vmw_master_create,
  1327. .master_destroy = vmw_master_destroy,
  1328. .master_set = vmw_master_set,
  1329. .master_drop = vmw_master_drop,
  1330. .open = vmw_driver_open,
  1331. .postclose = vmw_postclose,
  1332. .dumb_create = vmw_dumb_create,
  1333. .dumb_map_offset = vmw_dumb_map_offset,
  1334. .dumb_destroy = vmw_dumb_destroy,
  1335. .prime_fd_to_handle = vmw_prime_fd_to_handle,
  1336. .prime_handle_to_fd = vmw_prime_handle_to_fd,
  1337. .fops = &vmwgfx_driver_fops,
  1338. .name = VMWGFX_DRIVER_NAME,
  1339. .desc = VMWGFX_DRIVER_DESC,
  1340. .date = VMWGFX_DRIVER_DATE,
  1341. .major = VMWGFX_DRIVER_MAJOR,
  1342. .minor = VMWGFX_DRIVER_MINOR,
  1343. .patchlevel = VMWGFX_DRIVER_PATCHLEVEL
  1344. };
  1345. static struct pci_driver vmw_pci_driver = {
  1346. .name = VMWGFX_DRIVER_NAME,
  1347. .id_table = vmw_pci_id_list,
  1348. .probe = vmw_probe,
  1349. .remove = vmw_remove,
  1350. .driver = {
  1351. .pm = &vmw_pm_ops
  1352. }
  1353. };
  1354. static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1355. {
  1356. return drm_get_pci_dev(pdev, ent, &driver);
  1357. }
  1358. static int __init vmwgfx_init(void)
  1359. {
  1360. int ret;
  1361. if (vgacon_text_force())
  1362. return -EINVAL;
  1363. ret = pci_register_driver(&vmw_pci_driver);
  1364. if (ret)
  1365. DRM_ERROR("Failed initializing DRM.\n");
  1366. return ret;
  1367. }
  1368. static void __exit vmwgfx_exit(void)
  1369. {
  1370. pci_unregister_driver(&vmw_pci_driver);
  1371. }
  1372. module_init(vmwgfx_init);
  1373. module_exit(vmwgfx_exit);
  1374. MODULE_AUTHOR("VMware Inc. and others");
  1375. MODULE_DESCRIPTION("Standalone drm driver for the VMware SVGA device");
  1376. MODULE_LICENSE("GPL and additional rights");
  1377. MODULE_VERSION(__stringify(VMWGFX_DRIVER_MAJOR) "."
  1378. __stringify(VMWGFX_DRIVER_MINOR) "."
  1379. __stringify(VMWGFX_DRIVER_PATCHLEVEL) "."
  1380. "0");