blob: ba1f8f1c6d5d23f37e801503e5337d37ef71094c [file] [log] [blame]
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001/**************************************************************************
2 *
3 * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
Paul Gortmakere0cd3602011-08-30 11:04:30 -040027#include <linux/module.h>
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000028
David Howells760285e2012-10-02 18:01:07 +010029#include <drm/drmP.h>
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000030#include "vmwgfx_drv.h"
David Howells760285e2012-10-02 18:01:07 +010031#include <drm/ttm/ttm_placement.h>
32#include <drm/ttm/ttm_bo_driver.h>
33#include <drm/ttm/ttm_object.h>
34#include <drm/ttm/ttm_module.h>
Thomas Hellstromd92d9852013-10-24 01:49:26 -070035#include <linux/dma_remapping.h>
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000036
37#define VMWGFX_DRIVER_NAME "vmwgfx"
38#define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
39#define VMWGFX_CHIP_SVGAII 0
40#define VMW_FB_RESERVATION 0
41
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +010042#define VMW_MIN_INITIAL_WIDTH 800
43#define VMW_MIN_INITIAL_HEIGHT 600
44
45
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000046/**
47 * Fully encoded drm commands. Might move to vmw_drm.h
48 */
49
50#define DRM_IOCTL_VMW_GET_PARAM \
51 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_GET_PARAM, \
52 struct drm_vmw_getparam_arg)
53#define DRM_IOCTL_VMW_ALLOC_DMABUF \
54 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_ALLOC_DMABUF, \
55 union drm_vmw_alloc_dmabuf_arg)
56#define DRM_IOCTL_VMW_UNREF_DMABUF \
57 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_DMABUF, \
58 struct drm_vmw_unref_dmabuf_arg)
59#define DRM_IOCTL_VMW_CURSOR_BYPASS \
60 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_CURSOR_BYPASS, \
61 struct drm_vmw_cursor_bypass_arg)
62
63#define DRM_IOCTL_VMW_CONTROL_STREAM \
64 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_CONTROL_STREAM, \
65 struct drm_vmw_control_stream_arg)
66#define DRM_IOCTL_VMW_CLAIM_STREAM \
67 DRM_IOR(DRM_COMMAND_BASE + DRM_VMW_CLAIM_STREAM, \
68 struct drm_vmw_stream_arg)
69#define DRM_IOCTL_VMW_UNREF_STREAM \
70 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_STREAM, \
71 struct drm_vmw_stream_arg)
72
73#define DRM_IOCTL_VMW_CREATE_CONTEXT \
74 DRM_IOR(DRM_COMMAND_BASE + DRM_VMW_CREATE_CONTEXT, \
75 struct drm_vmw_context_arg)
76#define DRM_IOCTL_VMW_UNREF_CONTEXT \
77 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_CONTEXT, \
78 struct drm_vmw_context_arg)
79#define DRM_IOCTL_VMW_CREATE_SURFACE \
80 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_CREATE_SURFACE, \
81 union drm_vmw_surface_create_arg)
82#define DRM_IOCTL_VMW_UNREF_SURFACE \
83 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_SURFACE, \
84 struct drm_vmw_surface_arg)
85#define DRM_IOCTL_VMW_REF_SURFACE \
86 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_REF_SURFACE, \
87 union drm_vmw_surface_reference_arg)
88#define DRM_IOCTL_VMW_EXECBUF \
89 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_EXECBUF, \
90 struct drm_vmw_execbuf_arg)
Thomas Hellstromae2a1042011-09-01 20:18:44 +000091#define DRM_IOCTL_VMW_GET_3D_CAP \
92 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_GET_3D_CAP, \
93 struct drm_vmw_get_3d_cap_arg)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000094#define DRM_IOCTL_VMW_FENCE_WAIT \
95 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_FENCE_WAIT, \
96 struct drm_vmw_fence_wait_arg)
Thomas Hellstromae2a1042011-09-01 20:18:44 +000097#define DRM_IOCTL_VMW_FENCE_SIGNALED \
98 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_FENCE_SIGNALED, \
99 struct drm_vmw_fence_signaled_arg)
100#define DRM_IOCTL_VMW_FENCE_UNREF \
101 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_FENCE_UNREF, \
102 struct drm_vmw_fence_arg)
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +0200103#define DRM_IOCTL_VMW_FENCE_EVENT \
104 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_FENCE_EVENT, \
105 struct drm_vmw_fence_event_arg)
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200106#define DRM_IOCTL_VMW_PRESENT \
107 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT, \
108 struct drm_vmw_present_arg)
109#define DRM_IOCTL_VMW_PRESENT_READBACK \
110 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT_READBACK, \
111 struct drm_vmw_present_readback_arg)
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200112#define DRM_IOCTL_VMW_UPDATE_LAYOUT \
113 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UPDATE_LAYOUT, \
114 struct drm_vmw_update_layout_arg)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000115
116/**
117 * The core DRM version of this macro doesn't account for
118 * DRM_COMMAND_BASE.
119 */
120
121#define VMW_IOCTL_DEF(ioctl, func, flags) \
Dave Airlie1b2f1482010-08-14 20:20:34 +1000122 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {DRM_##ioctl, flags, func, DRM_IOCTL_##ioctl}
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000123
124/**
125 * Ioctl definitions.
126 */
127
Rob Clarkbaa70942013-08-02 13:27:49 -0400128static const struct drm_ioctl_desc vmw_ioctls[] = {
Dave Airlie1b2f1482010-08-14 20:20:34 +1000129 VMW_IOCTL_DEF(VMW_GET_PARAM, vmw_getparam_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100130 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000131 VMW_IOCTL_DEF(VMW_ALLOC_DMABUF, vmw_dmabuf_alloc_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100132 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000133 VMW_IOCTL_DEF(VMW_UNREF_DMABUF, vmw_dmabuf_unref_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100134 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000135 VMW_IOCTL_DEF(VMW_CURSOR_BYPASS,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100136 vmw_kms_cursor_bypass_ioctl,
137 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000138
Dave Airlie1b2f1482010-08-14 20:20:34 +1000139 VMW_IOCTL_DEF(VMW_CONTROL_STREAM, vmw_overlay_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100140 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000141 VMW_IOCTL_DEF(VMW_CLAIM_STREAM, vmw_stream_claim_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100142 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000143 VMW_IOCTL_DEF(VMW_UNREF_STREAM, vmw_stream_unref_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100144 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000145
Dave Airlie1b2f1482010-08-14 20:20:34 +1000146 VMW_IOCTL_DEF(VMW_CREATE_CONTEXT, vmw_context_define_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100147 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000148 VMW_IOCTL_DEF(VMW_UNREF_CONTEXT, vmw_context_destroy_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100149 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000150 VMW_IOCTL_DEF(VMW_CREATE_SURFACE, vmw_surface_define_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100151 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000152 VMW_IOCTL_DEF(VMW_UNREF_SURFACE, vmw_surface_destroy_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100153 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000154 VMW_IOCTL_DEF(VMW_REF_SURFACE, vmw_surface_reference_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100155 DRM_AUTH | DRM_UNLOCKED),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000156 VMW_IOCTL_DEF(VMW_EXECBUF, vmw_execbuf_ioctl,
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100157 DRM_AUTH | DRM_UNLOCKED),
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000158 VMW_IOCTL_DEF(VMW_FENCE_WAIT, vmw_fence_obj_wait_ioctl,
159 DRM_AUTH | DRM_UNLOCKED),
160 VMW_IOCTL_DEF(VMW_FENCE_SIGNALED,
161 vmw_fence_obj_signaled_ioctl,
162 DRM_AUTH | DRM_UNLOCKED),
163 VMW_IOCTL_DEF(VMW_FENCE_UNREF, vmw_fence_obj_unref_ioctl,
Jakob Bornecrantzd8bd19d2010-06-01 11:54:20 +0200164 DRM_AUTH | DRM_UNLOCKED),
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +0200165 VMW_IOCTL_DEF(VMW_FENCE_EVENT,
166 vmw_fence_event_ioctl,
167 DRM_AUTH | DRM_UNLOCKED),
Thomas Hellstromf63f6a52011-09-01 20:18:41 +0000168 VMW_IOCTL_DEF(VMW_GET_3D_CAP, vmw_get_cap_3d_ioctl,
169 DRM_AUTH | DRM_UNLOCKED),
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200170
171 /* these allow direct access to the framebuffers mark as master only */
172 VMW_IOCTL_DEF(VMW_PRESENT, vmw_present_ioctl,
173 DRM_MASTER | DRM_AUTH | DRM_UNLOCKED),
174 VMW_IOCTL_DEF(VMW_PRESENT_READBACK,
175 vmw_present_readback_ioctl,
176 DRM_MASTER | DRM_AUTH | DRM_UNLOCKED),
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200177 VMW_IOCTL_DEF(VMW_UPDATE_LAYOUT,
178 vmw_kms_update_layout_ioctl,
179 DRM_MASTER | DRM_UNLOCKED),
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000180};
181
182static struct pci_device_id vmw_pci_id_list[] = {
183 {0x15ad, 0x0405, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VMWGFX_CHIP_SVGAII},
184 {0, 0, 0}
185};
Dave Airliec4903422012-08-28 21:40:51 -0400186MODULE_DEVICE_TABLE(pci, vmw_pci_id_list);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000187
Dave Airlie5d2afab2012-08-28 21:38:49 -0400188static int enable_fbdev = IS_ENABLED(CONFIG_DRM_VMWGFX_FBCON);
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700189static int vmw_force_iommu;
190static int vmw_restrict_iommu;
191static int vmw_force_coherent;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000192
193static int vmw_probe(struct pci_dev *, const struct pci_device_id *);
194static void vmw_master_init(struct vmw_master *);
Thomas Hellstromd9f36a02010-01-13 22:28:43 +0100195static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
196 void *ptr);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000197
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200198MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev");
199module_param_named(enable_fbdev, enable_fbdev, int, 0600);
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700200MODULE_PARM_DESC(force_dma_api, "Force using the DMA API for TTM pages");
201module_param_named(force_dma_api, vmw_force_iommu, int, 0600);
202MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages");
203module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600);
204MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages");
205module_param_named(force_coherent, vmw_force_coherent, int, 0600);
206
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200207
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000208static void vmw_print_capabilities(uint32_t capabilities)
209{
210 DRM_INFO("Capabilities:\n");
211 if (capabilities & SVGA_CAP_RECT_COPY)
212 DRM_INFO(" Rect copy.\n");
213 if (capabilities & SVGA_CAP_CURSOR)
214 DRM_INFO(" Cursor.\n");
215 if (capabilities & SVGA_CAP_CURSOR_BYPASS)
216 DRM_INFO(" Cursor bypass.\n");
217 if (capabilities & SVGA_CAP_CURSOR_BYPASS_2)
218 DRM_INFO(" Cursor bypass 2.\n");
219 if (capabilities & SVGA_CAP_8BIT_EMULATION)
220 DRM_INFO(" 8bit emulation.\n");
221 if (capabilities & SVGA_CAP_ALPHA_CURSOR)
222 DRM_INFO(" Alpha cursor.\n");
223 if (capabilities & SVGA_CAP_3D)
224 DRM_INFO(" 3D.\n");
225 if (capabilities & SVGA_CAP_EXTENDED_FIFO)
226 DRM_INFO(" Extended Fifo.\n");
227 if (capabilities & SVGA_CAP_MULTIMON)
228 DRM_INFO(" Multimon.\n");
229 if (capabilities & SVGA_CAP_PITCHLOCK)
230 DRM_INFO(" Pitchlock.\n");
231 if (capabilities & SVGA_CAP_IRQMASK)
232 DRM_INFO(" Irq mask.\n");
233 if (capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)
234 DRM_INFO(" Display Topology.\n");
235 if (capabilities & SVGA_CAP_GMR)
236 DRM_INFO(" GMR.\n");
237 if (capabilities & SVGA_CAP_TRACES)
238 DRM_INFO(" Traces.\n");
Thomas Hellstromdcca2862011-08-31 07:42:51 +0000239 if (capabilities & SVGA_CAP_GMR2)
240 DRM_INFO(" GMR2.\n");
241 if (capabilities & SVGA_CAP_SCREEN_OBJECT_2)
242 DRM_INFO(" Screen Object 2.\n");
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000243}
244
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200245
246/**
247 * vmw_execbuf_prepare_dummy_query - Initialize a query result structure at
248 * the start of a buffer object.
249 *
250 * @dev_priv: The device private structure.
251 *
252 * This function will idle the buffer using an uninterruptible wait, then
253 * map the first page and initialize a pending occlusion query result structure,
254 * Finally it will unmap the buffer.
255 *
256 * TODO: Since we're only mapping a single page, we should optimize the map
257 * to use kmap_atomic / iomap_atomic.
258 */
259static void vmw_dummy_query_bo_prepare(struct vmw_private *dev_priv)
260{
261 struct ttm_bo_kmap_obj map;
262 volatile SVGA3dQueryResult *result;
263 bool dummy;
264 int ret;
265 struct ttm_bo_device *bdev = &dev_priv->bdev;
266 struct ttm_buffer_object *bo = dev_priv->dummy_query_bo;
267
268 ttm_bo_reserve(bo, false, false, false, 0);
269 spin_lock(&bdev->fence_lock);
Dave Airlie1717c0e2011-10-27 18:28:37 +0200270 ret = ttm_bo_wait(bo, false, false, false);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200271 spin_unlock(&bdev->fence_lock);
272 if (unlikely(ret != 0))
273 (void) vmw_fallback_wait(dev_priv, false, true, 0, false,
274 10*HZ);
275
276 ret = ttm_bo_kmap(bo, 0, 1, &map);
277 if (likely(ret == 0)) {
278 result = ttm_kmap_obj_virtual(&map, &dummy);
279 result->totalSize = sizeof(*result);
280 result->state = SVGA3D_QUERYSTATE_PENDING;
281 result->result32 = 0xff;
282 ttm_bo_kunmap(&map);
283 } else
284 DRM_ERROR("Dummy query buffer map failed.\n");
285 ttm_bo_unreserve(bo);
286}
287
288
289/**
290 * vmw_dummy_query_bo_create - create a bo to hold a dummy query result
291 *
292 * @dev_priv: A device private structure.
293 *
294 * This function creates a small buffer object that holds the query
295 * result for dummy queries emitted as query barriers.
296 * No interruptible waits are done within this function.
297 *
298 * Returns an error if bo creation fails.
299 */
300static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)
301{
302 return ttm_bo_create(&dev_priv->bdev,
303 PAGE_SIZE,
304 ttm_bo_type_device,
305 &vmw_vram_sys_placement,
Marcin Slusarz0b91c4a2012-11-06 21:49:51 +0000306 0, false, NULL,
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200307 &dev_priv->dummy_query_bo);
308}
309
310
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000311static int vmw_request_device(struct vmw_private *dev_priv)
312{
313 int ret;
314
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000315 ret = vmw_fifo_init(dev_priv, &dev_priv->fifo);
316 if (unlikely(ret != 0)) {
317 DRM_ERROR("Unable to initialize FIFO.\n");
318 return ret;
319 }
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000320 vmw_fence_fifo_up(dev_priv->fman);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200321 ret = vmw_dummy_query_bo_create(dev_priv);
322 if (unlikely(ret != 0))
323 goto out_no_query_bo;
324 vmw_dummy_query_bo_prepare(dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000325
326 return 0;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200327
328out_no_query_bo:
329 vmw_fence_fifo_down(dev_priv->fman);
330 vmw_fifo_release(dev_priv, &dev_priv->fifo);
331 return ret;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000332}
333
334static void vmw_release_device(struct vmw_private *dev_priv)
335{
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200336 /*
337 * Previous destructions should've released
338 * the pinned bo.
339 */
340
341 BUG_ON(dev_priv->pinned_bo != NULL);
342
343 ttm_bo_unref(&dev_priv->dummy_query_bo);
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000344 vmw_fence_fifo_down(dev_priv->fman);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000345 vmw_fifo_release(dev_priv, &dev_priv->fifo);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000346}
347
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000348/**
349 * Increase the 3d resource refcount.
350 * If the count was prevously zero, initialize the fifo, switching to svga
351 * mode. Note that the master holds a ref as well, and may request an
352 * explicit switch to svga mode if fb is not running, using @unhide_svga.
353 */
354int vmw_3d_resource_inc(struct vmw_private *dev_priv,
355 bool unhide_svga)
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200356{
357 int ret = 0;
358
359 mutex_lock(&dev_priv->release_mutex);
360 if (unlikely(dev_priv->num_3d_resources++ == 0)) {
361 ret = vmw_request_device(dev_priv);
362 if (unlikely(ret != 0))
363 --dev_priv->num_3d_resources;
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000364 } else if (unhide_svga) {
365 mutex_lock(&dev_priv->hw_mutex);
366 vmw_write(dev_priv, SVGA_REG_ENABLE,
367 vmw_read(dev_priv, SVGA_REG_ENABLE) &
368 ~SVGA_REG_ENABLE_HIDE);
369 mutex_unlock(&dev_priv->hw_mutex);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200370 }
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000371
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200372 mutex_unlock(&dev_priv->release_mutex);
373 return ret;
374}
375
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000376/**
377 * Decrease the 3d resource refcount.
378 * If the count reaches zero, disable the fifo, switching to vga mode.
379 * Note that the master holds a refcount as well, and may request an
380 * explicit switch to vga mode when it releases its refcount to account
381 * for the situation of an X server vt switch to VGA with 3d resources
382 * active.
383 */
384void vmw_3d_resource_dec(struct vmw_private *dev_priv,
385 bool hide_svga)
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200386{
387 int32_t n3d;
388
389 mutex_lock(&dev_priv->release_mutex);
390 if (unlikely(--dev_priv->num_3d_resources == 0))
391 vmw_release_device(dev_priv);
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000392 else if (hide_svga) {
393 mutex_lock(&dev_priv->hw_mutex);
394 vmw_write(dev_priv, SVGA_REG_ENABLE,
395 vmw_read(dev_priv, SVGA_REG_ENABLE) |
396 SVGA_REG_ENABLE_HIDE);
397 mutex_unlock(&dev_priv->hw_mutex);
398 }
399
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200400 n3d = (int32_t) dev_priv->num_3d_resources;
401 mutex_unlock(&dev_priv->release_mutex);
402
403 BUG_ON(n3d < 0);
404}
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000405
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100406/**
407 * Sets the initial_[width|height] fields on the given vmw_private.
408 *
409 * It does so by reading SVGA_REG_[WIDTH|HEIGHT] regs and then
Thomas Hellstrom67d4a872012-02-09 16:56:47 +0100410 * clamping the value to fb_max_[width|height] fields and the
411 * VMW_MIN_INITIAL_[WIDTH|HEIGHT].
412 * If the values appear to be invalid, set them to
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100413 * VMW_MIN_INITIAL_[WIDTH|HEIGHT].
414 */
415static void vmw_get_initial_size(struct vmw_private *dev_priv)
416{
417 uint32_t width;
418 uint32_t height;
419
420 width = vmw_read(dev_priv, SVGA_REG_WIDTH);
421 height = vmw_read(dev_priv, SVGA_REG_HEIGHT);
422
423 width = max_t(uint32_t, width, VMW_MIN_INITIAL_WIDTH);
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100424 height = max_t(uint32_t, height, VMW_MIN_INITIAL_HEIGHT);
Thomas Hellstrom67d4a872012-02-09 16:56:47 +0100425
426 if (width > dev_priv->fb_max_width ||
427 height > dev_priv->fb_max_height) {
428
429 /*
430 * This is a host error and shouldn't occur.
431 */
432
433 width = VMW_MIN_INITIAL_WIDTH;
434 height = VMW_MIN_INITIAL_HEIGHT;
435 }
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100436
437 dev_priv->initial_width = width;
438 dev_priv->initial_height = height;
439}
440
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700441/**
442 * vmw_dma_select_mode - Determine how DMA mappings should be set up for this
443 * system.
444 *
445 * @dev_priv: Pointer to a struct vmw_private
446 *
447 * This functions tries to determine the IOMMU setup and what actions
448 * need to be taken by the driver to make system pages visible to the
449 * device.
450 * If this function decides that DMA is not possible, it returns -EINVAL.
451 * The driver may then try to disable features of the device that require
452 * DMA.
453 */
454static int vmw_dma_select_mode(struct vmw_private *dev_priv)
455{
456 const struct dma_map_ops *dma_ops = get_dma_ops(dev_priv->dev->dev);
457 static const char *names[vmw_dma_map_max] = {
458 [vmw_dma_phys] = "Using physical TTM page addresses.",
459 [vmw_dma_alloc_coherent] = "Using coherent TTM pages.",
460 [vmw_dma_map_populate] = "Keeping DMA mappings.",
461 [vmw_dma_map_bind] = "Giving up DMA mappings early."};
462
463#ifdef CONFIG_INTEL_IOMMU
464 if (intel_iommu_enabled) {
465 dev_priv->map_mode = vmw_dma_map_populate;
466 goto out_fixup;
467 }
468#endif
469
470 if (!(vmw_force_iommu || vmw_force_coherent)) {
471 dev_priv->map_mode = vmw_dma_phys;
472 DRM_INFO("DMA map mode: %s\n", names[dev_priv->map_mode]);
473 return 0;
474 }
475
476 dev_priv->map_mode = vmw_dma_map_populate;
477
478 if (dma_ops->sync_single_for_cpu)
479 dev_priv->map_mode = vmw_dma_alloc_coherent;
480#ifdef CONFIG_SWIOTLB
481 if (swiotlb_nr_tbl() == 0)
482 dev_priv->map_mode = vmw_dma_map_populate;
483#endif
484
Dave Airlie21136942013-11-08 16:12:42 +1000485#ifdef CONFIG_INTEL_IOMMU
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700486out_fixup:
Dave Airlie21136942013-11-08 16:12:42 +1000487#endif
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700488 if (dev_priv->map_mode == vmw_dma_map_populate &&
489 vmw_restrict_iommu)
490 dev_priv->map_mode = vmw_dma_map_bind;
491
492 if (vmw_force_coherent)
493 dev_priv->map_mode = vmw_dma_alloc_coherent;
494
495#if !defined(CONFIG_SWIOTLB) && !defined(CONFIG_INTEL_IOMMU)
496 /*
497 * No coherent page pool
498 */
499 if (dev_priv->map_mode == vmw_dma_alloc_coherent)
500 return -EINVAL;
501#endif
502
503 DRM_INFO("DMA map mode: %s\n", names[dev_priv->map_mode]);
504
505 return 0;
506}
507
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000508static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
509{
510 struct vmw_private *dev_priv;
511 int ret;
Peter Hanzelc1886602010-01-30 03:38:07 +0000512 uint32_t svga_id;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000513 enum vmw_res_type i;
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700514 bool refuse_dma = false;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000515
516 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
517 if (unlikely(dev_priv == NULL)) {
518 DRM_ERROR("Failed allocating a device private struct.\n");
519 return -ENOMEM;
520 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000521
Dave Airlie466e69b2011-12-19 11:15:29 +0000522 pci_set_master(dev->pdev);
523
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000524 dev_priv->dev = dev;
525 dev_priv->vmw_chipset = chipset;
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000526 dev_priv->last_read_seqno = (uint32_t) -100;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000527 mutex_init(&dev_priv->hw_mutex);
528 mutex_init(&dev_priv->cmdbuf_mutex);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200529 mutex_init(&dev_priv->release_mutex);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000530 rwlock_init(&dev_priv->resource_lock);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000531
532 for (i = vmw_res_context; i < vmw_res_max; ++i) {
533 idr_init(&dev_priv->res_idr[i]);
534 INIT_LIST_HEAD(&dev_priv->res_lru[i]);
535 }
536
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000537 mutex_init(&dev_priv->init_mutex);
538 init_waitqueue_head(&dev_priv->fence_queue);
539 init_waitqueue_head(&dev_priv->fifo_queue);
Thomas Hellstrom4f73a962011-09-01 20:18:43 +0000540 dev_priv->fence_queue_waiters = 0;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000541 atomic_set(&dev_priv->fifo_queue_waiters, 0);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000542
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200543 dev_priv->used_memory_size = 0;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000544
545 dev_priv->io_start = pci_resource_start(dev->pdev, 0);
546 dev_priv->vram_start = pci_resource_start(dev->pdev, 1);
547 dev_priv->mmio_start = pci_resource_start(dev->pdev, 2);
548
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200549 dev_priv->enable_fb = enable_fbdev;
550
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000551 mutex_lock(&dev_priv->hw_mutex);
Peter Hanzelc1886602010-01-30 03:38:07 +0000552
553 vmw_write(dev_priv, SVGA_REG_ID, SVGA_ID_2);
554 svga_id = vmw_read(dev_priv, SVGA_REG_ID);
555 if (svga_id != SVGA_ID_2) {
556 ret = -ENOSYS;
Masanari Iida49625902012-02-05 22:50:36 +0900557 DRM_ERROR("Unsupported SVGA ID 0x%x\n", svga_id);
Peter Hanzelc1886602010-01-30 03:38:07 +0000558 mutex_unlock(&dev_priv->hw_mutex);
559 goto out_err0;
560 }
561
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000562 dev_priv->capabilities = vmw_read(dev_priv, SVGA_REG_CAPABILITIES);
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700563 ret = vmw_dma_select_mode(dev_priv);
564 if (unlikely(ret != 0)) {
565 DRM_INFO("Restricting capabilities due to IOMMU setup.\n");
566 refuse_dma = true;
567 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000568
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200569 dev_priv->vram_size = vmw_read(dev_priv, SVGA_REG_VRAM_SIZE);
570 dev_priv->mmio_size = vmw_read(dev_priv, SVGA_REG_MEM_SIZE);
571 dev_priv->fb_max_width = vmw_read(dev_priv, SVGA_REG_MAX_WIDTH);
572 dev_priv->fb_max_height = vmw_read(dev_priv, SVGA_REG_MAX_HEIGHT);
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100573
574 vmw_get_initial_size(dev_priv);
575
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000576 if (dev_priv->capabilities & SVGA_CAP_GMR) {
577 dev_priv->max_gmr_descriptors =
578 vmw_read(dev_priv,
579 SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH);
580 dev_priv->max_gmr_ids =
581 vmw_read(dev_priv, SVGA_REG_GMR_MAX_IDS);
582 }
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000583 if (dev_priv->capabilities & SVGA_CAP_GMR2) {
584 dev_priv->max_gmr_pages =
585 vmw_read(dev_priv, SVGA_REG_GMRS_MAX_PAGES);
586 dev_priv->memory_size =
587 vmw_read(dev_priv, SVGA_REG_MEMORY_SIZE);
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200588 dev_priv->memory_size -= dev_priv->vram_size;
589 } else {
590 /*
591 * An arbitrary limit of 512MiB on surface
592 * memory. But all HWV8 hardware supports GMR2.
593 */
594 dev_priv->memory_size = 512*1024*1024;
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000595 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000596
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000597 mutex_unlock(&dev_priv->hw_mutex);
598
599 vmw_print_capabilities(dev_priv->capabilities);
600
601 if (dev_priv->capabilities & SVGA_CAP_GMR) {
602 DRM_INFO("Max GMR ids is %u\n",
603 (unsigned)dev_priv->max_gmr_ids);
604 DRM_INFO("Max GMR descriptors is %u\n",
605 (unsigned)dev_priv->max_gmr_descriptors);
606 }
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000607 if (dev_priv->capabilities & SVGA_CAP_GMR2) {
608 DRM_INFO("Max number of GMR pages is %u\n",
609 (unsigned)dev_priv->max_gmr_pages);
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200610 DRM_INFO("Max dedicated hypervisor surface memory is %u kiB\n",
611 (unsigned)dev_priv->memory_size / 1024);
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000612 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000613 DRM_INFO("VRAM at 0x%08x size is %u kiB\n",
614 dev_priv->vram_start, dev_priv->vram_size / 1024);
615 DRM_INFO("MMIO at 0x%08x size is %u kiB\n",
616 dev_priv->mmio_start, dev_priv->mmio_size / 1024);
617
618 ret = vmw_ttm_global_init(dev_priv);
619 if (unlikely(ret != 0))
620 goto out_err0;
621
622
623 vmw_master_init(&dev_priv->fbdev_master);
624 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM);
625 dev_priv->active_master = &dev_priv->fbdev_master;
626
Dave Airliea2c06ee2011-02-23 14:24:01 +1000627
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000628 ret = ttm_bo_device_init(&dev_priv->bdev,
629 dev_priv->bo_global_ref.ref.object,
630 &vmw_bo_driver, VMWGFX_FILE_PAGE_OFFSET,
631 false);
632 if (unlikely(ret != 0)) {
633 DRM_ERROR("Failed initializing TTM buffer object driver.\n");
634 goto out_err1;
635 }
636
637 ret = ttm_bo_init_mm(&dev_priv->bdev, TTM_PL_VRAM,
638 (dev_priv->vram_size >> PAGE_SHIFT));
639 if (unlikely(ret != 0)) {
640 DRM_ERROR("Failed initializing memory manager for VRAM.\n");
641 goto out_err2;
642 }
643
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200644 dev_priv->has_gmr = true;
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700645 if (((dev_priv->capabilities & (SVGA_CAP_GMR | SVGA_CAP_GMR2)) == 0) ||
646 refuse_dma || ttm_bo_init_mm(&dev_priv->bdev, VMW_PL_GMR,
647 dev_priv->max_gmr_ids) != 0) {
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200648 DRM_INFO("No GMR memory available. "
649 "Graphics memory resources are very limited.\n");
650 dev_priv->has_gmr = false;
651 }
652
Andy Lutomirski247d36d2013-05-13 23:58:41 +0000653 dev_priv->mmio_mtrr = arch_phys_wc_add(dev_priv->mmio_start,
654 dev_priv->mmio_size);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000655
656 dev_priv->mmio_virt = ioremap_wc(dev_priv->mmio_start,
657 dev_priv->mmio_size);
658
659 if (unlikely(dev_priv->mmio_virt == NULL)) {
660 ret = -ENOMEM;
661 DRM_ERROR("Failed mapping MMIO.\n");
662 goto out_err3;
663 }
664
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200665 /* Need mmio memory to check for fifo pitchlock cap. */
666 if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY) &&
667 !(dev_priv->capabilities & SVGA_CAP_PITCHLOCK) &&
668 !vmw_fifo_have_pitchlock(dev_priv)) {
669 ret = -ENOSYS;
670 DRM_ERROR("Hardware has no pitchlock\n");
671 goto out_err4;
672 }
673
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000674 dev_priv->tdev = ttm_object_device_init
675 (dev_priv->mem_global_ref.object, 12);
676
677 if (unlikely(dev_priv->tdev == NULL)) {
678 DRM_ERROR("Unable to initialize TTM object management.\n");
679 ret = -ENOMEM;
680 goto out_err4;
681 }
682
683 dev->dev_private = dev_priv;
684
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000685 ret = pci_request_regions(dev->pdev, "vmwgfx probe");
686 dev_priv->stealth = (ret != 0);
687 if (dev_priv->stealth) {
688 /**
689 * Request at least the mmio PCI resource.
690 */
691
692 DRM_INFO("It appears like vesafb is loaded. "
Thomas Hellstromf2d12b82010-02-15 14:45:22 +0000693 "Ignore above error if any.\n");
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000694 ret = pci_request_region(dev->pdev, 2, "vmwgfx stealth probe");
695 if (unlikely(ret != 0)) {
696 DRM_ERROR("Failed reserving the SVGA MMIO resource.\n");
697 goto out_no_device;
698 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000699 }
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000700
Thomas Hellstrom506ff752012-11-09 12:26:14 +0000701 if (dev_priv->capabilities & SVGA_CAP_IRQMASK) {
702 ret = drm_irq_install(dev);
703 if (ret != 0) {
704 DRM_ERROR("Failed installing irq: %d\n", ret);
705 goto out_no_irq;
706 }
707 }
708
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000709 dev_priv->fman = vmw_fence_manager_init(dev_priv);
Wei Yongjun14bbf202013-08-26 15:15:37 +0800710 if (unlikely(dev_priv->fman == NULL)) {
711 ret = -ENOMEM;
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000712 goto out_no_fman;
Wei Yongjun14bbf202013-08-26 15:15:37 +0800713 }
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200714
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200715 vmw_kms_save_vga(dev_priv);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200716
717 /* Start kms and overlay systems, needs fifo. */
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200718 ret = vmw_kms_init(dev_priv);
719 if (unlikely(ret != 0))
720 goto out_no_kms;
Thomas Hellstromf2d12b82010-02-15 14:45:22 +0000721 vmw_overlay_init(dev_priv);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200722
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200723 if (dev_priv->enable_fb) {
Thomas Hellstrom506ff752012-11-09 12:26:14 +0000724 ret = vmw_3d_resource_inc(dev_priv, true);
725 if (unlikely(ret != 0))
726 goto out_no_fifo;
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200727 vmw_fb_init(dev_priv);
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200728 }
729
Thomas Hellstromd9f36a02010-01-13 22:28:43 +0100730 dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier;
731 register_pm_notifier(&dev_priv->pm_nb);
732
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000733 return 0;
734
Thomas Hellstrom506ff752012-11-09 12:26:14 +0000735out_no_fifo:
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200736 vmw_overlay_close(dev_priv);
737 vmw_kms_close(dev_priv);
738out_no_kms:
Thomas Hellstrom506ff752012-11-09 12:26:14 +0000739 vmw_kms_restore_vga(dev_priv);
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000740 vmw_fence_manager_takedown(dev_priv->fman);
741out_no_fman:
Thomas Hellstrom506ff752012-11-09 12:26:14 +0000742 if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
743 drm_irq_uninstall(dev_priv->dev);
744out_no_irq:
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200745 if (dev_priv->stealth)
746 pci_release_region(dev->pdev, 2);
747 else
748 pci_release_regions(dev->pdev);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000749out_no_device:
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000750 ttm_object_device_release(&dev_priv->tdev);
751out_err4:
752 iounmap(dev_priv->mmio_virt);
753out_err3:
Andy Lutomirski247d36d2013-05-13 23:58:41 +0000754 arch_phys_wc_del(dev_priv->mmio_mtrr);
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200755 if (dev_priv->has_gmr)
756 (void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000757 (void)ttm_bo_clean_mm(&dev_priv->bdev, TTM_PL_VRAM);
758out_err2:
759 (void)ttm_bo_device_release(&dev_priv->bdev);
760out_err1:
761 vmw_ttm_global_release(dev_priv);
762out_err0:
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000763 for (i = vmw_res_context; i < vmw_res_max; ++i)
764 idr_destroy(&dev_priv->res_idr[i]);
765
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000766 kfree(dev_priv);
767 return ret;
768}
769
770static int vmw_driver_unload(struct drm_device *dev)
771{
772 struct vmw_private *dev_priv = vmw_priv(dev);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000773 enum vmw_res_type i;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000774
Thomas Hellstromd9f36a02010-01-13 22:28:43 +0100775 unregister_pm_notifier(&dev_priv->pm_nb);
776
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000777 if (dev_priv->ctx.res_ht_initialized)
778 drm_ht_remove(&dev_priv->ctx.res_ht);
Thomas Hellstrombe38ab62011-08-31 07:42:54 +0000779 if (dev_priv->ctx.cmd_bounce)
780 vfree(dev_priv->ctx.cmd_bounce);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200781 if (dev_priv->enable_fb) {
782 vmw_fb_close(dev_priv);
783 vmw_kms_restore_vga(dev_priv);
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000784 vmw_3d_resource_dec(dev_priv, false);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200785 }
Thomas Hellstromf2d12b82010-02-15 14:45:22 +0000786 vmw_kms_close(dev_priv);
787 vmw_overlay_close(dev_priv);
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000788 vmw_fence_manager_takedown(dev_priv->fman);
Thomas Hellstrom506ff752012-11-09 12:26:14 +0000789 if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
790 drm_irq_uninstall(dev_priv->dev);
Thomas Hellstromf2d12b82010-02-15 14:45:22 +0000791 if (dev_priv->stealth)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000792 pci_release_region(dev->pdev, 2);
Thomas Hellstromf2d12b82010-02-15 14:45:22 +0000793 else
794 pci_release_regions(dev->pdev);
795
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000796 ttm_object_device_release(&dev_priv->tdev);
797 iounmap(dev_priv->mmio_virt);
Andy Lutomirski247d36d2013-05-13 23:58:41 +0000798 arch_phys_wc_del(dev_priv->mmio_mtrr);
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200799 if (dev_priv->has_gmr)
800 (void)ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000801 (void)ttm_bo_clean_mm(&dev_priv->bdev, TTM_PL_VRAM);
802 (void)ttm_bo_device_release(&dev_priv->bdev);
803 vmw_ttm_global_release(dev_priv);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000804
805 for (i = vmw_res_context; i < vmw_res_max; ++i)
806 idr_destroy(&dev_priv->res_idr[i]);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000807
808 kfree(dev_priv);
809
810 return 0;
811}
812
Thomas Hellstrom6b82ef52012-02-09 16:56:42 +0100813static void vmw_preclose(struct drm_device *dev,
814 struct drm_file *file_priv)
815{
816 struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
817 struct vmw_private *dev_priv = vmw_priv(dev);
818
819 vmw_event_fence_fpriv_gone(dev_priv->fman, &vmw_fp->fence_events);
820}
821
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000822static void vmw_postclose(struct drm_device *dev,
823 struct drm_file *file_priv)
824{
825 struct vmw_fpriv *vmw_fp;
826
827 vmw_fp = vmw_fpriv(file_priv);
828 ttm_object_file_release(&vmw_fp->tfile);
829 if (vmw_fp->locked_master)
830 drm_master_put(&vmw_fp->locked_master);
831 kfree(vmw_fp);
832}
833
834static int vmw_driver_open(struct drm_device *dev, struct drm_file *file_priv)
835{
836 struct vmw_private *dev_priv = vmw_priv(dev);
837 struct vmw_fpriv *vmw_fp;
838 int ret = -ENOMEM;
839
840 vmw_fp = kzalloc(sizeof(*vmw_fp), GFP_KERNEL);
841 if (unlikely(vmw_fp == NULL))
842 return ret;
843
Thomas Hellstrom6b82ef52012-02-09 16:56:42 +0100844 INIT_LIST_HEAD(&vmw_fp->fence_events);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000845 vmw_fp->tfile = ttm_object_file_init(dev_priv->tdev, 10);
846 if (unlikely(vmw_fp->tfile == NULL))
847 goto out_no_tfile;
848
849 file_priv->driver_priv = vmw_fp;
Ilija Hadzic949c4a32012-05-15 16:40:10 -0400850 dev_priv->bdev.dev_mapping = dev->dev_mapping;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000851
852 return 0;
853
854out_no_tfile:
855 kfree(vmw_fp);
856 return ret;
857}
858
859static long vmw_unlocked_ioctl(struct file *filp, unsigned int cmd,
860 unsigned long arg)
861{
862 struct drm_file *file_priv = filp->private_data;
863 struct drm_device *dev = file_priv->minor->dev;
864 unsigned int nr = DRM_IOCTL_NR(cmd);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000865
866 /*
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100867 * Do extra checking on driver private ioctls.
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000868 */
869
870 if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END)
871 && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls)) {
Rob Clarkbaa70942013-08-02 13:27:49 -0400872 const struct drm_ioctl_desc *ioctl =
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000873 &vmw_ioctls[nr - DRM_COMMAND_BASE];
874
Thomas Hellstrom2854eed2010-09-30 12:18:33 +0200875 if (unlikely(ioctl->cmd_drv != cmd)) {
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000876 DRM_ERROR("Invalid command format, ioctl %d\n",
877 nr - DRM_COMMAND_BASE);
878 return -EINVAL;
879 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000880 }
881
Thomas Hellstrome1f78002009-12-08 12:57:51 +0100882 return drm_ioctl(filp, cmd, arg);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000883}
884
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000885static void vmw_lastclose(struct drm_device *dev)
886{
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000887 struct drm_crtc *crtc;
888 struct drm_mode_set set;
889 int ret;
890
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000891 set.x = 0;
892 set.y = 0;
893 set.fb = NULL;
894 set.mode = NULL;
895 set.connectors = NULL;
896 set.num_connectors = 0;
897
898 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
899 set.crtc = crtc;
Daniel Vetter2d13b672012-12-11 13:47:23 +0100900 ret = drm_mode_set_config_internal(&set);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000901 WARN_ON(ret != 0);
902 }
903
904}
905
906static void vmw_master_init(struct vmw_master *vmaster)
907{
908 ttm_lock_init(&vmaster->lock);
Thomas Hellstrom3a939a52010-10-05 12:43:03 +0200909 INIT_LIST_HEAD(&vmaster->fb_surf);
910 mutex_init(&vmaster->fb_surf_mutex);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000911}
912
913static int vmw_master_create(struct drm_device *dev,
914 struct drm_master *master)
915{
916 struct vmw_master *vmaster;
917
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000918 vmaster = kzalloc(sizeof(*vmaster), GFP_KERNEL);
919 if (unlikely(vmaster == NULL))
920 return -ENOMEM;
921
Thomas Hellstrom3a939a52010-10-05 12:43:03 +0200922 vmw_master_init(vmaster);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000923 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM);
924 master->driver_priv = vmaster;
925
926 return 0;
927}
928
929static void vmw_master_destroy(struct drm_device *dev,
930 struct drm_master *master)
931{
932 struct vmw_master *vmaster = vmw_master(master);
933
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000934 master->driver_priv = NULL;
935 kfree(vmaster);
936}
937
938
939static int vmw_master_set(struct drm_device *dev,
940 struct drm_file *file_priv,
941 bool from_open)
942{
943 struct vmw_private *dev_priv = vmw_priv(dev);
944 struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
945 struct vmw_master *active = dev_priv->active_master;
946 struct vmw_master *vmaster = vmw_master(file_priv->master);
947 int ret = 0;
948
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200949 if (!dev_priv->enable_fb) {
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000950 ret = vmw_3d_resource_inc(dev_priv, true);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200951 if (unlikely(ret != 0))
952 return ret;
953 vmw_kms_save_vga(dev_priv);
954 mutex_lock(&dev_priv->hw_mutex);
955 vmw_write(dev_priv, SVGA_REG_TRACES, 0);
956 mutex_unlock(&dev_priv->hw_mutex);
957 }
958
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000959 if (active) {
960 BUG_ON(active != &dev_priv->fbdev_master);
961 ret = ttm_vt_lock(&active->lock, false, vmw_fp->tfile);
962 if (unlikely(ret != 0))
963 goto out_no_active_lock;
964
965 ttm_lock_set_kill(&active->lock, true, SIGTERM);
966 ret = ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM);
967 if (unlikely(ret != 0)) {
968 DRM_ERROR("Unable to clean VRAM on "
969 "master drop.\n");
970 }
971
972 dev_priv->active_master = NULL;
973 }
974
975 ttm_lock_set_kill(&vmaster->lock, false, SIGTERM);
976 if (!from_open) {
977 ttm_vt_unlock(&vmaster->lock);
978 BUG_ON(vmw_fp->locked_master != file_priv->master);
979 drm_master_put(&vmw_fp->locked_master);
980 }
981
982 dev_priv->active_master = vmaster;
983
984 return 0;
985
986out_no_active_lock:
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200987 if (!dev_priv->enable_fb) {
Thomas Hellstromba723fe82012-11-09 12:26:11 +0000988 vmw_kms_restore_vga(dev_priv);
989 vmw_3d_resource_dec(dev_priv, true);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200990 mutex_lock(&dev_priv->hw_mutex);
991 vmw_write(dev_priv, SVGA_REG_TRACES, 1);
992 mutex_unlock(&dev_priv->hw_mutex);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200993 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000994 return ret;
995}
996
997static void vmw_master_drop(struct drm_device *dev,
998 struct drm_file *file_priv,
999 bool from_release)
1000{
1001 struct vmw_private *dev_priv = vmw_priv(dev);
1002 struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
1003 struct vmw_master *vmaster = vmw_master(file_priv->master);
1004 int ret;
1005
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001006 /**
1007 * Make sure the master doesn't disappear while we have
1008 * it locked.
1009 */
1010
1011 vmw_fp->locked_master = drm_master_get(file_priv->master);
1012 ret = ttm_vt_lock(&vmaster->lock, false, vmw_fp->tfile);
Thomas Hellstromc0951b72012-11-20 12:19:35 +00001013 vmw_execbuf_release_pinned_bo(dev_priv);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +02001014
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001015 if (unlikely((ret != 0))) {
1016 DRM_ERROR("Unable to lock TTM at VT switch.\n");
1017 drm_master_put(&vmw_fp->locked_master);
1018 }
1019
1020 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM);
1021
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +02001022 if (!dev_priv->enable_fb) {
1023 ret = ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM);
1024 if (unlikely(ret != 0))
1025 DRM_ERROR("Unable to clean VRAM on master drop.\n");
Thomas Hellstromba723fe82012-11-09 12:26:11 +00001026 vmw_kms_restore_vga(dev_priv);
1027 vmw_3d_resource_dec(dev_priv, true);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +02001028 mutex_lock(&dev_priv->hw_mutex);
1029 vmw_write(dev_priv, SVGA_REG_TRACES, 1);
1030 mutex_unlock(&dev_priv->hw_mutex);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +02001031 }
1032
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001033 dev_priv->active_master = &dev_priv->fbdev_master;
1034 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM);
1035 ttm_vt_unlock(&dev_priv->fbdev_master.lock);
1036
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +02001037 if (dev_priv->enable_fb)
1038 vmw_fb_on(dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001039}
1040
1041
1042static void vmw_remove(struct pci_dev *pdev)
1043{
1044 struct drm_device *dev = pci_get_drvdata(pdev);
1045
1046 drm_put_dev(dev);
1047}
1048
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001049static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
1050 void *ptr)
1051{
1052 struct vmw_private *dev_priv =
1053 container_of(nb, struct vmw_private, pm_nb);
1054 struct vmw_master *vmaster = dev_priv->active_master;
1055
1056 switch (val) {
1057 case PM_HIBERNATION_PREPARE:
1058 case PM_SUSPEND_PREPARE:
1059 ttm_suspend_lock(&vmaster->lock);
1060
1061 /**
1062 * This empties VRAM and unbinds all GMR bindings.
1063 * Buffer contents is moved to swappable memory.
1064 */
Thomas Hellstromc0951b72012-11-20 12:19:35 +00001065 vmw_execbuf_release_pinned_bo(dev_priv);
1066 vmw_resource_evict_all(dev_priv);
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001067 ttm_bo_swapout_all(&dev_priv->bdev);
Thomas Hellstrom094e0fa2010-10-05 12:43:00 +02001068
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001069 break;
1070 case PM_POST_HIBERNATION:
1071 case PM_POST_SUSPEND:
Thomas Hellstrom094e0fa2010-10-05 12:43:00 +02001072 case PM_POST_RESTORE:
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001073 ttm_suspend_unlock(&vmaster->lock);
Thomas Hellstrom094e0fa2010-10-05 12:43:00 +02001074
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001075 break;
1076 case PM_RESTORE_PREPARE:
1077 break;
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001078 default:
1079 break;
1080 }
1081 return 0;
1082}
1083
1084/**
1085 * These might not be needed with the virtual SVGA device.
1086 */
1087
Thomas Hellstrom7fbd7212010-10-05 12:43:01 +02001088static int vmw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001089{
Thomas Hellstrom094e0fa2010-10-05 12:43:00 +02001090 struct drm_device *dev = pci_get_drvdata(pdev);
1091 struct vmw_private *dev_priv = vmw_priv(dev);
1092
1093 if (dev_priv->num_3d_resources != 0) {
1094 DRM_INFO("Can't suspend or hibernate "
1095 "while 3D resources are active.\n");
1096 return -EBUSY;
1097 }
1098
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001099 pci_save_state(pdev);
1100 pci_disable_device(pdev);
1101 pci_set_power_state(pdev, PCI_D3hot);
1102 return 0;
1103}
1104
Thomas Hellstrom7fbd7212010-10-05 12:43:01 +02001105static int vmw_pci_resume(struct pci_dev *pdev)
Thomas Hellstromd9f36a02010-01-13 22:28:43 +01001106{
1107 pci_set_power_state(pdev, PCI_D0);
1108 pci_restore_state(pdev);
1109 return pci_enable_device(pdev);
1110}
1111
Thomas Hellstrom7fbd7212010-10-05 12:43:01 +02001112static int vmw_pm_suspend(struct device *kdev)
1113{
1114 struct pci_dev *pdev = to_pci_dev(kdev);
1115 struct pm_message dummy;
1116
1117 dummy.event = 0;
1118
1119 return vmw_pci_suspend(pdev, dummy);
1120}
1121
1122static int vmw_pm_resume(struct device *kdev)
1123{
1124 struct pci_dev *pdev = to_pci_dev(kdev);
1125
1126 return vmw_pci_resume(pdev);
1127}
1128
1129static int vmw_pm_prepare(struct device *kdev)
1130{
1131 struct pci_dev *pdev = to_pci_dev(kdev);
1132 struct drm_device *dev = pci_get_drvdata(pdev);
1133 struct vmw_private *dev_priv = vmw_priv(dev);
1134
1135 /**
1136 * Release 3d reference held by fbdev and potentially
1137 * stop fifo.
1138 */
1139 dev_priv->suspended = true;
1140 if (dev_priv->enable_fb)
Thomas Hellstrom05730b32011-08-31 07:42:52 +00001141 vmw_3d_resource_dec(dev_priv, true);
Thomas Hellstrom7fbd7212010-10-05 12:43:01 +02001142
1143 if (dev_priv->num_3d_resources != 0) {
1144
1145 DRM_INFO("Can't suspend or hibernate "
1146 "while 3D resources are active.\n");
1147
1148 if (dev_priv->enable_fb)
Thomas Hellstrom05730b32011-08-31 07:42:52 +00001149 vmw_3d_resource_inc(dev_priv, true);
Thomas Hellstrom7fbd7212010-10-05 12:43:01 +02001150 dev_priv->suspended = false;
1151 return -EBUSY;
1152 }
1153
1154 return 0;
1155}
1156
1157static void vmw_pm_complete(struct device *kdev)
1158{
1159 struct pci_dev *pdev = to_pci_dev(kdev);
1160 struct drm_device *dev = pci_get_drvdata(pdev);
1161 struct vmw_private *dev_priv = vmw_priv(dev);
1162
Thomas Hellstrom95e8f6a2012-11-09 10:05:57 +01001163 mutex_lock(&dev_priv->hw_mutex);
1164 vmw_write(dev_priv, SVGA_REG_ID, SVGA_ID_2);
1165 (void) vmw_read(dev_priv, SVGA_REG_ID);
1166 mutex_unlock(&dev_priv->hw_mutex);
1167
Thomas Hellstrom7fbd7212010-10-05 12:43:01 +02001168 /**
1169 * Reclaim 3d reference held by fbdev and potentially
1170 * start fifo.
1171 */
1172 if (dev_priv->enable_fb)
Thomas Hellstrom05730b32011-08-31 07:42:52 +00001173 vmw_3d_resource_inc(dev_priv, false);
Thomas Hellstrom7fbd7212010-10-05 12:43:01 +02001174
1175 dev_priv->suspended = false;
1176}
1177
1178static const struct dev_pm_ops vmw_pm_ops = {
1179 .prepare = vmw_pm_prepare,
1180 .complete = vmw_pm_complete,
1181 .suspend = vmw_pm_suspend,
1182 .resume = vmw_pm_resume,
1183};
1184
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001185static const struct file_operations vmwgfx_driver_fops = {
1186 .owner = THIS_MODULE,
1187 .open = drm_open,
1188 .release = drm_release,
1189 .unlocked_ioctl = vmw_unlocked_ioctl,
1190 .mmap = vmw_mmap,
1191 .poll = vmw_fops_poll,
1192 .read = vmw_fops_read,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001193#if defined(CONFIG_COMPAT)
1194 .compat_ioctl = drm_compat_ioctl,
1195#endif
1196 .llseek = noop_llseek,
1197};
1198
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001199static struct drm_driver driver = {
1200 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
1201 DRIVER_MODESET,
1202 .load = vmw_driver_load,
1203 .unload = vmw_driver_unload,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001204 .lastclose = vmw_lastclose,
1205 .irq_preinstall = vmw_irq_preinstall,
1206 .irq_postinstall = vmw_irq_postinstall,
1207 .irq_uninstall = vmw_irq_uninstall,
1208 .irq_handler = vmw_irq_handler,
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +02001209 .get_vblank_counter = vmw_get_vblank_counter,
Jakob Bornecrantz1c482ab2011-10-17 11:59:45 +02001210 .enable_vblank = vmw_enable_vblank,
1211 .disable_vblank = vmw_disable_vblank,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001212 .ioctls = vmw_ioctls,
1213 .num_ioctls = DRM_ARRAY_SIZE(vmw_ioctls),
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001214 .master_create = vmw_master_create,
1215 .master_destroy = vmw_master_destroy,
1216 .master_set = vmw_master_set,
1217 .master_drop = vmw_master_drop,
1218 .open = vmw_driver_open,
Thomas Hellstrom6b82ef52012-02-09 16:56:42 +01001219 .preclose = vmw_preclose,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001220 .postclose = vmw_postclose,
Dave Airlie5e1782d2012-08-28 01:53:54 +00001221
1222 .dumb_create = vmw_dumb_create,
1223 .dumb_map_offset = vmw_dumb_map_offset,
1224 .dumb_destroy = vmw_dumb_destroy,
1225
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001226 .fops = &vmwgfx_driver_fops,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001227 .name = VMWGFX_DRIVER_NAME,
1228 .desc = VMWGFX_DRIVER_DESC,
1229 .date = VMWGFX_DRIVER_DATE,
1230 .major = VMWGFX_DRIVER_MAJOR,
1231 .minor = VMWGFX_DRIVER_MINOR,
1232 .patchlevel = VMWGFX_DRIVER_PATCHLEVEL
1233};
1234
Dave Airlie8410ea32010-12-15 03:16:38 +10001235static struct pci_driver vmw_pci_driver = {
1236 .name = VMWGFX_DRIVER_NAME,
1237 .id_table = vmw_pci_id_list,
1238 .probe = vmw_probe,
1239 .remove = vmw_remove,
1240 .driver = {
1241 .pm = &vmw_pm_ops
1242 }
1243};
1244
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001245static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1246{
Jordan Crousedcdb1672010-05-27 13:40:25 -06001247 return drm_get_pci_dev(pdev, ent, &driver);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001248}
1249
1250static int __init vmwgfx_init(void)
1251{
1252 int ret;
Dave Airlie8410ea32010-12-15 03:16:38 +10001253 ret = drm_pci_init(&driver, &vmw_pci_driver);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001254 if (ret)
1255 DRM_ERROR("Failed initializing DRM.\n");
1256 return ret;
1257}
1258
1259static void __exit vmwgfx_exit(void)
1260{
Dave Airlie8410ea32010-12-15 03:16:38 +10001261 drm_pci_exit(&driver, &vmw_pci_driver);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001262}
1263
1264module_init(vmwgfx_init);
1265module_exit(vmwgfx_exit);
1266
1267MODULE_AUTHOR("VMware Inc. and others");
1268MODULE_DESCRIPTION("Standalone drm driver for the VMware SVGA device");
1269MODULE_LICENSE("GPL and additional rights");
Thomas Hellstrom73558ea2010-10-05 12:43:07 +02001270MODULE_VERSION(__stringify(VMWGFX_DRIVER_MAJOR) "."
1271 __stringify(VMWGFX_DRIVER_MINOR) "."
1272 __stringify(VMWGFX_DRIVER_PATCHLEVEL) "."
1273 "0");