Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 28 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 29 | #include <drm/drmP.h> |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 30 | #include "vmwgfx_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 31 | #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 Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 35 | #include <linux/dma_remapping.h> |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 36 | |
| 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 Bornecrantz | eb4f923 | 2012-02-09 16:56:46 +0100 | [diff] [blame] | 42 | #define VMW_MIN_INITIAL_WIDTH 800 |
| 43 | #define VMW_MIN_INITIAL_HEIGHT 600 |
| 44 | |
| 45 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 46 | /** |
| 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 Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 91 | #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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 94 | #define DRM_IOCTL_VMW_FENCE_WAIT \ |
| 95 | DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_FENCE_WAIT, \ |
| 96 | struct drm_vmw_fence_wait_arg) |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 97 | #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 Hellstrom | 57c5ee7 | 2011-10-10 12:23:26 +0200 | [diff] [blame] | 103 | #define DRM_IOCTL_VMW_FENCE_EVENT \ |
| 104 | DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_FENCE_EVENT, \ |
| 105 | struct drm_vmw_fence_event_arg) |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 106 | #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 Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 112 | #define DRM_IOCTL_VMW_UPDATE_LAYOUT \ |
| 113 | DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UPDATE_LAYOUT, \ |
| 114 | struct drm_vmw_update_layout_arg) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 115 | |
| 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 Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 122 | [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {DRM_##ioctl, flags, func, DRM_IOCTL_##ioctl} |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Ioctl definitions. |
| 126 | */ |
| 127 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 128 | static const struct drm_ioctl_desc vmw_ioctls[] = { |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 129 | VMW_IOCTL_DEF(VMW_GET_PARAM, vmw_getparam_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 130 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 131 | VMW_IOCTL_DEF(VMW_ALLOC_DMABUF, vmw_dmabuf_alloc_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 132 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 133 | VMW_IOCTL_DEF(VMW_UNREF_DMABUF, vmw_dmabuf_unref_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 134 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 135 | VMW_IOCTL_DEF(VMW_CURSOR_BYPASS, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 136 | vmw_kms_cursor_bypass_ioctl, |
| 137 | DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED), |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 138 | |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 139 | VMW_IOCTL_DEF(VMW_CONTROL_STREAM, vmw_overlay_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 140 | DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 141 | VMW_IOCTL_DEF(VMW_CLAIM_STREAM, vmw_stream_claim_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 142 | DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 143 | VMW_IOCTL_DEF(VMW_UNREF_STREAM, vmw_stream_unref_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 144 | DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED), |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 145 | |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 146 | VMW_IOCTL_DEF(VMW_CREATE_CONTEXT, vmw_context_define_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 147 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 148 | VMW_IOCTL_DEF(VMW_UNREF_CONTEXT, vmw_context_destroy_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 149 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 150 | VMW_IOCTL_DEF(VMW_CREATE_SURFACE, vmw_surface_define_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 151 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 152 | VMW_IOCTL_DEF(VMW_UNREF_SURFACE, vmw_surface_destroy_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 153 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 154 | VMW_IOCTL_DEF(VMW_REF_SURFACE, vmw_surface_reference_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 155 | DRM_AUTH | DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 156 | VMW_IOCTL_DEF(VMW_EXECBUF, vmw_execbuf_ioctl, |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 157 | DRM_AUTH | DRM_UNLOCKED), |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 158 | 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 Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 164 | DRM_AUTH | DRM_UNLOCKED), |
Thomas Hellstrom | 57c5ee7 | 2011-10-10 12:23:26 +0200 | [diff] [blame] | 165 | VMW_IOCTL_DEF(VMW_FENCE_EVENT, |
| 166 | vmw_fence_event_ioctl, |
| 167 | DRM_AUTH | DRM_UNLOCKED), |
Thomas Hellstrom | f63f6a5 | 2011-09-01 20:18:41 +0000 | [diff] [blame] | 168 | VMW_IOCTL_DEF(VMW_GET_3D_CAP, vmw_get_cap_3d_ioctl, |
| 169 | DRM_AUTH | DRM_UNLOCKED), |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 170 | |
| 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 Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 177 | VMW_IOCTL_DEF(VMW_UPDATE_LAYOUT, |
| 178 | vmw_kms_update_layout_ioctl, |
| 179 | DRM_MASTER | DRM_UNLOCKED), |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | static 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 Airlie | c490342 | 2012-08-28 21:40:51 -0400 | [diff] [blame] | 186 | MODULE_DEVICE_TABLE(pci, vmw_pci_id_list); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 187 | |
Dave Airlie | 5d2afab | 2012-08-28 21:38:49 -0400 | [diff] [blame] | 188 | static int enable_fbdev = IS_ENABLED(CONFIG_DRM_VMWGFX_FBCON); |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 189 | static int vmw_force_iommu; |
| 190 | static int vmw_restrict_iommu; |
| 191 | static int vmw_force_coherent; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 192 | |
| 193 | static int vmw_probe(struct pci_dev *, const struct pci_device_id *); |
| 194 | static void vmw_master_init(struct vmw_master *); |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 195 | static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val, |
| 196 | void *ptr); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 197 | |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 198 | MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev"); |
| 199 | module_param_named(enable_fbdev, enable_fbdev, int, 0600); |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 200 | MODULE_PARM_DESC(force_dma_api, "Force using the DMA API for TTM pages"); |
| 201 | module_param_named(force_dma_api, vmw_force_iommu, int, 0600); |
| 202 | MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages"); |
| 203 | module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600); |
| 204 | MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages"); |
| 205 | module_param_named(force_coherent, vmw_force_coherent, int, 0600); |
| 206 | |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 207 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 208 | static 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 Hellstrom | dcca286 | 2011-08-31 07:42:51 +0000 | [diff] [blame] | 239 | 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 245 | |
| 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 | */ |
| 259 | static 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 Airlie | 1717c0e | 2011-10-27 18:28:37 +0200 | [diff] [blame] | 270 | ret = ttm_bo_wait(bo, false, false, false); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 271 | 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 | */ |
| 300 | static 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 Slusarz | 0b91c4a | 2012-11-06 21:49:51 +0000 | [diff] [blame] | 306 | 0, false, NULL, |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 307 | &dev_priv->dummy_query_bo); |
| 308 | } |
| 309 | |
| 310 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 311 | static int vmw_request_device(struct vmw_private *dev_priv) |
| 312 | { |
| 313 | int ret; |
| 314 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 315 | 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 Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 320 | vmw_fence_fifo_up(dev_priv->fman); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 321 | 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 325 | |
| 326 | return 0; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 327 | |
| 328 | out_no_query_bo: |
| 329 | vmw_fence_fifo_down(dev_priv->fman); |
| 330 | vmw_fifo_release(dev_priv, &dev_priv->fifo); |
| 331 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static void vmw_release_device(struct vmw_private *dev_priv) |
| 335 | { |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 336 | /* |
| 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 Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 344 | vmw_fence_fifo_down(dev_priv->fman); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 345 | vmw_fifo_release(dev_priv, &dev_priv->fifo); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Thomas Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 348 | /** |
| 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 | */ |
| 354 | int vmw_3d_resource_inc(struct vmw_private *dev_priv, |
| 355 | bool unhide_svga) |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 356 | { |
| 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 Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 364 | } 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 Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 370 | } |
Thomas Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 371 | |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 372 | mutex_unlock(&dev_priv->release_mutex); |
| 373 | return ret; |
| 374 | } |
| 375 | |
Thomas Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 376 | /** |
| 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 | */ |
| 384 | void vmw_3d_resource_dec(struct vmw_private *dev_priv, |
| 385 | bool hide_svga) |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 386 | { |
| 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 Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 392 | 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 Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 400 | n3d = (int32_t) dev_priv->num_3d_resources; |
| 401 | mutex_unlock(&dev_priv->release_mutex); |
| 402 | |
| 403 | BUG_ON(n3d < 0); |
| 404 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 405 | |
Jakob Bornecrantz | eb4f923 | 2012-02-09 16:56:46 +0100 | [diff] [blame] | 406 | /** |
| 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 Hellstrom | 67d4a87 | 2012-02-09 16:56:47 +0100 | [diff] [blame] | 410 | * 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 Bornecrantz | eb4f923 | 2012-02-09 16:56:46 +0100 | [diff] [blame] | 413 | * VMW_MIN_INITIAL_[WIDTH|HEIGHT]. |
| 414 | */ |
| 415 | static 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 Bornecrantz | eb4f923 | 2012-02-09 16:56:46 +0100 | [diff] [blame] | 424 | height = max_t(uint32_t, height, VMW_MIN_INITIAL_HEIGHT); |
Thomas Hellstrom | 67d4a87 | 2012-02-09 16:56:47 +0100 | [diff] [blame] | 425 | |
| 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 Bornecrantz | eb4f923 | 2012-02-09 16:56:46 +0100 | [diff] [blame] | 436 | |
| 437 | dev_priv->initial_width = width; |
| 438 | dev_priv->initial_height = height; |
| 439 | } |
| 440 | |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 441 | /** |
| 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 | */ |
| 454 | static 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 Airlie | 2113694 | 2013-11-08 16:12:42 +1000 | [diff] [blame^] | 485 | #ifdef CONFIG_INTEL_IOMMU |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 486 | out_fixup: |
Dave Airlie | 2113694 | 2013-11-08 16:12:42 +1000 | [diff] [blame^] | 487 | #endif |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 488 | 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 508 | static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) |
| 509 | { |
| 510 | struct vmw_private *dev_priv; |
| 511 | int ret; |
Peter Hanzel | c188660 | 2010-01-30 03:38:07 +0000 | [diff] [blame] | 512 | uint32_t svga_id; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 513 | enum vmw_res_type i; |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 514 | bool refuse_dma = false; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 515 | |
| 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 521 | |
Dave Airlie | 466e69b | 2011-12-19 11:15:29 +0000 | [diff] [blame] | 522 | pci_set_master(dev->pdev); |
| 523 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 524 | dev_priv->dev = dev; |
| 525 | dev_priv->vmw_chipset = chipset; |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 526 | dev_priv->last_read_seqno = (uint32_t) -100; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 527 | mutex_init(&dev_priv->hw_mutex); |
| 528 | mutex_init(&dev_priv->cmdbuf_mutex); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 529 | mutex_init(&dev_priv->release_mutex); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 530 | rwlock_init(&dev_priv->resource_lock); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 531 | |
| 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 537 | mutex_init(&dev_priv->init_mutex); |
| 538 | init_waitqueue_head(&dev_priv->fence_queue); |
| 539 | init_waitqueue_head(&dev_priv->fifo_queue); |
Thomas Hellstrom | 4f73a96 | 2011-09-01 20:18:43 +0000 | [diff] [blame] | 540 | dev_priv->fence_queue_waiters = 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 541 | atomic_set(&dev_priv->fifo_queue_waiters, 0); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 542 | |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 543 | dev_priv->used_memory_size = 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 544 | |
| 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 Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 549 | dev_priv->enable_fb = enable_fbdev; |
| 550 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 551 | mutex_lock(&dev_priv->hw_mutex); |
Peter Hanzel | c188660 | 2010-01-30 03:38:07 +0000 | [diff] [blame] | 552 | |
| 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 Iida | 4962590 | 2012-02-05 22:50:36 +0900 | [diff] [blame] | 557 | DRM_ERROR("Unsupported SVGA ID 0x%x\n", svga_id); |
Peter Hanzel | c188660 | 2010-01-30 03:38:07 +0000 | [diff] [blame] | 558 | mutex_unlock(&dev_priv->hw_mutex); |
| 559 | goto out_err0; |
| 560 | } |
| 561 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 562 | dev_priv->capabilities = vmw_read(dev_priv, SVGA_REG_CAPABILITIES); |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 563 | 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 568 | |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 569 | 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 Bornecrantz | eb4f923 | 2012-02-09 16:56:46 +0100 | [diff] [blame] | 573 | |
| 574 | vmw_get_initial_size(dev_priv); |
| 575 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 576 | 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 Hellstrom | fb17f18 | 2011-08-31 07:42:53 +0000 | [diff] [blame] | 583 | 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 Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 588 | 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 Hellstrom | fb17f18 | 2011-08-31 07:42:53 +0000 | [diff] [blame] | 595 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 596 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 597 | 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 Hellstrom | fb17f18 | 2011-08-31 07:42:53 +0000 | [diff] [blame] | 607 | 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 Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 610 | DRM_INFO("Max dedicated hypervisor surface memory is %u kiB\n", |
| 611 | (unsigned)dev_priv->memory_size / 1024); |
Thomas Hellstrom | fb17f18 | 2011-08-31 07:42:53 +0000 | [diff] [blame] | 612 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 613 | 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 Airlie | a2c06ee | 2011-02-23 14:24:01 +1000 | [diff] [blame] | 627 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 628 | 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 Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 644 | dev_priv->has_gmr = true; |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 645 | 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 Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 648 | DRM_INFO("No GMR memory available. " |
| 649 | "Graphics memory resources are very limited.\n"); |
| 650 | dev_priv->has_gmr = false; |
| 651 | } |
| 652 | |
Andy Lutomirski | 247d36d | 2013-05-13 23:58:41 +0000 | [diff] [blame] | 653 | dev_priv->mmio_mtrr = arch_phys_wc_add(dev_priv->mmio_start, |
| 654 | dev_priv->mmio_size); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 655 | |
| 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 Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 665 | /* 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 674 | 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 685 | 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 Hellstrom | f2d12b8 | 2010-02-15 14:45:22 +0000 | [diff] [blame] | 693 | "Ignore above error if any.\n"); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 694 | 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 699 | } |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 700 | |
Thomas Hellstrom | 506ff75 | 2012-11-09 12:26:14 +0000 | [diff] [blame] | 701 | 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 Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 709 | dev_priv->fman = vmw_fence_manager_init(dev_priv); |
Wei Yongjun | 14bbf20 | 2013-08-26 15:15:37 +0800 | [diff] [blame] | 710 | if (unlikely(dev_priv->fman == NULL)) { |
| 711 | ret = -ENOMEM; |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 712 | goto out_no_fman; |
Wei Yongjun | 14bbf20 | 2013-08-26 15:15:37 +0800 | [diff] [blame] | 713 | } |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 714 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 715 | vmw_kms_save_vga(dev_priv); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 716 | |
| 717 | /* Start kms and overlay systems, needs fifo. */ |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 718 | ret = vmw_kms_init(dev_priv); |
| 719 | if (unlikely(ret != 0)) |
| 720 | goto out_no_kms; |
Thomas Hellstrom | f2d12b8 | 2010-02-15 14:45:22 +0000 | [diff] [blame] | 721 | vmw_overlay_init(dev_priv); |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 722 | |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 723 | if (dev_priv->enable_fb) { |
Thomas Hellstrom | 506ff75 | 2012-11-09 12:26:14 +0000 | [diff] [blame] | 724 | ret = vmw_3d_resource_inc(dev_priv, true); |
| 725 | if (unlikely(ret != 0)) |
| 726 | goto out_no_fifo; |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 727 | vmw_fb_init(dev_priv); |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 728 | } |
| 729 | |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 730 | dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier; |
| 731 | register_pm_notifier(&dev_priv->pm_nb); |
| 732 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 733 | return 0; |
| 734 | |
Thomas Hellstrom | 506ff75 | 2012-11-09 12:26:14 +0000 | [diff] [blame] | 735 | out_no_fifo: |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 736 | vmw_overlay_close(dev_priv); |
| 737 | vmw_kms_close(dev_priv); |
| 738 | out_no_kms: |
Thomas Hellstrom | 506ff75 | 2012-11-09 12:26:14 +0000 | [diff] [blame] | 739 | vmw_kms_restore_vga(dev_priv); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 740 | vmw_fence_manager_takedown(dev_priv->fman); |
| 741 | out_no_fman: |
Thomas Hellstrom | 506ff75 | 2012-11-09 12:26:14 +0000 | [diff] [blame] | 742 | if (dev_priv->capabilities & SVGA_CAP_IRQMASK) |
| 743 | drm_irq_uninstall(dev_priv->dev); |
| 744 | out_no_irq: |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 745 | if (dev_priv->stealth) |
| 746 | pci_release_region(dev->pdev, 2); |
| 747 | else |
| 748 | pci_release_regions(dev->pdev); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 749 | out_no_device: |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 750 | ttm_object_device_release(&dev_priv->tdev); |
| 751 | out_err4: |
| 752 | iounmap(dev_priv->mmio_virt); |
| 753 | out_err3: |
Andy Lutomirski | 247d36d | 2013-05-13 23:58:41 +0000 | [diff] [blame] | 754 | arch_phys_wc_del(dev_priv->mmio_mtrr); |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 755 | if (dev_priv->has_gmr) |
| 756 | (void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 757 | (void)ttm_bo_clean_mm(&dev_priv->bdev, TTM_PL_VRAM); |
| 758 | out_err2: |
| 759 | (void)ttm_bo_device_release(&dev_priv->bdev); |
| 760 | out_err1: |
| 761 | vmw_ttm_global_release(dev_priv); |
| 762 | out_err0: |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 763 | for (i = vmw_res_context; i < vmw_res_max; ++i) |
| 764 | idr_destroy(&dev_priv->res_idr[i]); |
| 765 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 766 | kfree(dev_priv); |
| 767 | return ret; |
| 768 | } |
| 769 | |
| 770 | static int vmw_driver_unload(struct drm_device *dev) |
| 771 | { |
| 772 | struct vmw_private *dev_priv = vmw_priv(dev); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 773 | enum vmw_res_type i; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 774 | |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 775 | unregister_pm_notifier(&dev_priv->pm_nb); |
| 776 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 777 | if (dev_priv->ctx.res_ht_initialized) |
| 778 | drm_ht_remove(&dev_priv->ctx.res_ht); |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 779 | if (dev_priv->ctx.cmd_bounce) |
| 780 | vfree(dev_priv->ctx.cmd_bounce); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 781 | if (dev_priv->enable_fb) { |
| 782 | vmw_fb_close(dev_priv); |
| 783 | vmw_kms_restore_vga(dev_priv); |
Thomas Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 784 | vmw_3d_resource_dec(dev_priv, false); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 785 | } |
Thomas Hellstrom | f2d12b8 | 2010-02-15 14:45:22 +0000 | [diff] [blame] | 786 | vmw_kms_close(dev_priv); |
| 787 | vmw_overlay_close(dev_priv); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 788 | vmw_fence_manager_takedown(dev_priv->fman); |
Thomas Hellstrom | 506ff75 | 2012-11-09 12:26:14 +0000 | [diff] [blame] | 789 | if (dev_priv->capabilities & SVGA_CAP_IRQMASK) |
| 790 | drm_irq_uninstall(dev_priv->dev); |
Thomas Hellstrom | f2d12b8 | 2010-02-15 14:45:22 +0000 | [diff] [blame] | 791 | if (dev_priv->stealth) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 792 | pci_release_region(dev->pdev, 2); |
Thomas Hellstrom | f2d12b8 | 2010-02-15 14:45:22 +0000 | [diff] [blame] | 793 | else |
| 794 | pci_release_regions(dev->pdev); |
| 795 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 796 | ttm_object_device_release(&dev_priv->tdev); |
| 797 | iounmap(dev_priv->mmio_virt); |
Andy Lutomirski | 247d36d | 2013-05-13 23:58:41 +0000 | [diff] [blame] | 798 | arch_phys_wc_del(dev_priv->mmio_mtrr); |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 799 | if (dev_priv->has_gmr) |
| 800 | (void)ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 801 | (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 Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 804 | |
| 805 | for (i = vmw_res_context; i < vmw_res_max; ++i) |
| 806 | idr_destroy(&dev_priv->res_idr[i]); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 807 | |
| 808 | kfree(dev_priv); |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
Thomas Hellstrom | 6b82ef5 | 2012-02-09 16:56:42 +0100 | [diff] [blame] | 813 | static 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 822 | static 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 | |
| 834 | static 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 Hellstrom | 6b82ef5 | 2012-02-09 16:56:42 +0100 | [diff] [blame] | 844 | INIT_LIST_HEAD(&vmw_fp->fence_events); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 845 | 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 Hadzic | 949c4a3 | 2012-05-15 16:40:10 -0400 | [diff] [blame] | 850 | dev_priv->bdev.dev_mapping = dev->dev_mapping; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 851 | |
| 852 | return 0; |
| 853 | |
| 854 | out_no_tfile: |
| 855 | kfree(vmw_fp); |
| 856 | return ret; |
| 857 | } |
| 858 | |
| 859 | static 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 865 | |
| 866 | /* |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 867 | * Do extra checking on driver private ioctls. |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 868 | */ |
| 869 | |
| 870 | if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) |
| 871 | && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls)) { |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 872 | const struct drm_ioctl_desc *ioctl = |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 873 | &vmw_ioctls[nr - DRM_COMMAND_BASE]; |
| 874 | |
Thomas Hellstrom | 2854eed | 2010-09-30 12:18:33 +0200 | [diff] [blame] | 875 | if (unlikely(ioctl->cmd_drv != cmd)) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 876 | DRM_ERROR("Invalid command format, ioctl %d\n", |
| 877 | nr - DRM_COMMAND_BASE); |
| 878 | return -EINVAL; |
| 879 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Thomas Hellstrom | e1f7800 | 2009-12-08 12:57:51 +0100 | [diff] [blame] | 882 | return drm_ioctl(filp, cmd, arg); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 885 | static void vmw_lastclose(struct drm_device *dev) |
| 886 | { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 887 | struct drm_crtc *crtc; |
| 888 | struct drm_mode_set set; |
| 889 | int ret; |
| 890 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 891 | 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 Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 900 | ret = drm_mode_set_config_internal(&set); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 901 | WARN_ON(ret != 0); |
| 902 | } |
| 903 | |
| 904 | } |
| 905 | |
| 906 | static void vmw_master_init(struct vmw_master *vmaster) |
| 907 | { |
| 908 | ttm_lock_init(&vmaster->lock); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 909 | INIT_LIST_HEAD(&vmaster->fb_surf); |
| 910 | mutex_init(&vmaster->fb_surf_mutex); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | static int vmw_master_create(struct drm_device *dev, |
| 914 | struct drm_master *master) |
| 915 | { |
| 916 | struct vmw_master *vmaster; |
| 917 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 918 | vmaster = kzalloc(sizeof(*vmaster), GFP_KERNEL); |
| 919 | if (unlikely(vmaster == NULL)) |
| 920 | return -ENOMEM; |
| 921 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 922 | vmw_master_init(vmaster); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 923 | ttm_lock_set_kill(&vmaster->lock, true, SIGTERM); |
| 924 | master->driver_priv = vmaster; |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | static void vmw_master_destroy(struct drm_device *dev, |
| 930 | struct drm_master *master) |
| 931 | { |
| 932 | struct vmw_master *vmaster = vmw_master(master); |
| 933 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 934 | master->driver_priv = NULL; |
| 935 | kfree(vmaster); |
| 936 | } |
| 937 | |
| 938 | |
| 939 | static 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 Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 949 | if (!dev_priv->enable_fb) { |
Thomas Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 950 | ret = vmw_3d_resource_inc(dev_priv, true); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 951 | 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 959 | 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 | |
| 986 | out_no_active_lock: |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 987 | if (!dev_priv->enable_fb) { |
Thomas Hellstrom | ba723fe8 | 2012-11-09 12:26:11 +0000 | [diff] [blame] | 988 | vmw_kms_restore_vga(dev_priv); |
| 989 | vmw_3d_resource_dec(dev_priv, true); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 990 | mutex_lock(&dev_priv->hw_mutex); |
| 991 | vmw_write(dev_priv, SVGA_REG_TRACES, 1); |
| 992 | mutex_unlock(&dev_priv->hw_mutex); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 993 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 994 | return ret; |
| 995 | } |
| 996 | |
| 997 | static 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1006 | /** |
| 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 Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1013 | vmw_execbuf_release_pinned_bo(dev_priv); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1014 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1015 | 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 Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 1022 | 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 Hellstrom | ba723fe8 | 2012-11-09 12:26:11 +0000 | [diff] [blame] | 1026 | vmw_kms_restore_vga(dev_priv); |
| 1027 | vmw_3d_resource_dec(dev_priv, true); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 1028 | mutex_lock(&dev_priv->hw_mutex); |
| 1029 | vmw_write(dev_priv, SVGA_REG_TRACES, 1); |
| 1030 | mutex_unlock(&dev_priv->hw_mutex); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1033 | 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 Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 1037 | if (dev_priv->enable_fb) |
| 1038 | vmw_fb_on(dev_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | static 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 Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1049 | static 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 Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1065 | vmw_execbuf_release_pinned_bo(dev_priv); |
| 1066 | vmw_resource_evict_all(dev_priv); |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1067 | ttm_bo_swapout_all(&dev_priv->bdev); |
Thomas Hellstrom | 094e0fa | 2010-10-05 12:43:00 +0200 | [diff] [blame] | 1068 | |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1069 | break; |
| 1070 | case PM_POST_HIBERNATION: |
| 1071 | case PM_POST_SUSPEND: |
Thomas Hellstrom | 094e0fa | 2010-10-05 12:43:00 +0200 | [diff] [blame] | 1072 | case PM_POST_RESTORE: |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1073 | ttm_suspend_unlock(&vmaster->lock); |
Thomas Hellstrom | 094e0fa | 2010-10-05 12:43:00 +0200 | [diff] [blame] | 1074 | |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1075 | break; |
| 1076 | case PM_RESTORE_PREPARE: |
| 1077 | break; |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1078 | default: |
| 1079 | break; |
| 1080 | } |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * These might not be needed with the virtual SVGA device. |
| 1086 | */ |
| 1087 | |
Thomas Hellstrom | 7fbd721 | 2010-10-05 12:43:01 +0200 | [diff] [blame] | 1088 | static int vmw_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1089 | { |
Thomas Hellstrom | 094e0fa | 2010-10-05 12:43:00 +0200 | [diff] [blame] | 1090 | 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 Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1099 | pci_save_state(pdev); |
| 1100 | pci_disable_device(pdev); |
| 1101 | pci_set_power_state(pdev, PCI_D3hot); |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
Thomas Hellstrom | 7fbd721 | 2010-10-05 12:43:01 +0200 | [diff] [blame] | 1105 | static int vmw_pci_resume(struct pci_dev *pdev) |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 1106 | { |
| 1107 | pci_set_power_state(pdev, PCI_D0); |
| 1108 | pci_restore_state(pdev); |
| 1109 | return pci_enable_device(pdev); |
| 1110 | } |
| 1111 | |
Thomas Hellstrom | 7fbd721 | 2010-10-05 12:43:01 +0200 | [diff] [blame] | 1112 | static 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 | |
| 1122 | static 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 | |
| 1129 | static 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 Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 1141 | vmw_3d_resource_dec(dev_priv, true); |
Thomas Hellstrom | 7fbd721 | 2010-10-05 12:43:01 +0200 | [diff] [blame] | 1142 | |
| 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 Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 1149 | vmw_3d_resource_inc(dev_priv, true); |
Thomas Hellstrom | 7fbd721 | 2010-10-05 12:43:01 +0200 | [diff] [blame] | 1150 | dev_priv->suspended = false; |
| 1151 | return -EBUSY; |
| 1152 | } |
| 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | static 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 Hellstrom | 95e8f6a | 2012-11-09 10:05:57 +0100 | [diff] [blame] | 1163 | 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 Hellstrom | 7fbd721 | 2010-10-05 12:43:01 +0200 | [diff] [blame] | 1168 | /** |
| 1169 | * Reclaim 3d reference held by fbdev and potentially |
| 1170 | * start fifo. |
| 1171 | */ |
| 1172 | if (dev_priv->enable_fb) |
Thomas Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 1173 | vmw_3d_resource_inc(dev_priv, false); |
Thomas Hellstrom | 7fbd721 | 2010-10-05 12:43:01 +0200 | [diff] [blame] | 1174 | |
| 1175 | dev_priv->suspended = false; |
| 1176 | } |
| 1177 | |
| 1178 | static 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 Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1185 | static 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 Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1193 | #if defined(CONFIG_COMPAT) |
| 1194 | .compat_ioctl = drm_compat_ioctl, |
| 1195 | #endif |
| 1196 | .llseek = noop_llseek, |
| 1197 | }; |
| 1198 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1199 | static 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1204 | .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 Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 1209 | .get_vblank_counter = vmw_get_vblank_counter, |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1210 | .enable_vblank = vmw_enable_vblank, |
| 1211 | .disable_vblank = vmw_disable_vblank, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1212 | .ioctls = vmw_ioctls, |
| 1213 | .num_ioctls = DRM_ARRAY_SIZE(vmw_ioctls), |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1214 | .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 Hellstrom | 6b82ef5 | 2012-02-09 16:56:42 +0100 | [diff] [blame] | 1219 | .preclose = vmw_preclose, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1220 | .postclose = vmw_postclose, |
Dave Airlie | 5e1782d | 2012-08-28 01:53:54 +0000 | [diff] [blame] | 1221 | |
| 1222 | .dumb_create = vmw_dumb_create, |
| 1223 | .dumb_map_offset = vmw_dumb_map_offset, |
| 1224 | .dumb_destroy = vmw_dumb_destroy, |
| 1225 | |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1226 | .fops = &vmwgfx_driver_fops, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1227 | .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 Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 1235 | static 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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1245 | static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1246 | { |
Jordan Crouse | dcdb167 | 2010-05-27 13:40:25 -0600 | [diff] [blame] | 1247 | return drm_get_pci_dev(pdev, ent, &driver); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | static int __init vmwgfx_init(void) |
| 1251 | { |
| 1252 | int ret; |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 1253 | ret = drm_pci_init(&driver, &vmw_pci_driver); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1254 | if (ret) |
| 1255 | DRM_ERROR("Failed initializing DRM.\n"); |
| 1256 | return ret; |
| 1257 | } |
| 1258 | |
| 1259 | static void __exit vmwgfx_exit(void) |
| 1260 | { |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 1261 | drm_pci_exit(&driver, &vmw_pci_driver); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | module_init(vmwgfx_init); |
| 1265 | module_exit(vmwgfx_exit); |
| 1266 | |
| 1267 | MODULE_AUTHOR("VMware Inc. and others"); |
| 1268 | MODULE_DESCRIPTION("Standalone drm driver for the VMware SVGA device"); |
| 1269 | MODULE_LICENSE("GPL and additional rights"); |
Thomas Hellstrom | 73558ea | 2010-10-05 12:43:07 +0200 | [diff] [blame] | 1270 | MODULE_VERSION(__stringify(VMWGFX_DRIVER_MAJOR) "." |
| 1271 | __stringify(VMWGFX_DRIVER_MINOR) "." |
| 1272 | __stringify(VMWGFX_DRIVER_PATCHLEVEL) "." |
| 1273 | "0"); |