27 #include <linux/module.h>
36 #define VMWGFX_DRIVER_NAME "vmwgfx"
37 #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
38 #define VMWGFX_CHIP_SVGAII 0
39 #define VMW_FB_RESERVATION 0
41 #define VMW_MIN_INITIAL_WIDTH 800
42 #define VMW_MIN_INITIAL_HEIGHT 600
49 #define DRM_IOCTL_VMW_GET_PARAM \
50 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_GET_PARAM, \
51 struct drm_vmw_getparam_arg)
52 #define DRM_IOCTL_VMW_ALLOC_DMABUF \
53 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_ALLOC_DMABUF, \
54 union drm_vmw_alloc_dmabuf_arg)
55 #define DRM_IOCTL_VMW_UNREF_DMABUF \
56 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_DMABUF, \
57 struct drm_vmw_unref_dmabuf_arg)
58 #define DRM_IOCTL_VMW_CURSOR_BYPASS \
59 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_CURSOR_BYPASS, \
60 struct drm_vmw_cursor_bypass_arg)
62 #define DRM_IOCTL_VMW_CONTROL_STREAM \
63 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_CONTROL_STREAM, \
64 struct drm_vmw_control_stream_arg)
65 #define DRM_IOCTL_VMW_CLAIM_STREAM \
66 DRM_IOR(DRM_COMMAND_BASE + DRM_VMW_CLAIM_STREAM, \
67 struct drm_vmw_stream_arg)
68 #define DRM_IOCTL_VMW_UNREF_STREAM \
69 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_STREAM, \
70 struct drm_vmw_stream_arg)
72 #define DRM_IOCTL_VMW_CREATE_CONTEXT \
73 DRM_IOR(DRM_COMMAND_BASE + DRM_VMW_CREATE_CONTEXT, \
74 struct drm_vmw_context_arg)
75 #define DRM_IOCTL_VMW_UNREF_CONTEXT \
76 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_CONTEXT, \
77 struct drm_vmw_context_arg)
78 #define DRM_IOCTL_VMW_CREATE_SURFACE \
79 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_CREATE_SURFACE, \
80 union drm_vmw_surface_create_arg)
81 #define DRM_IOCTL_VMW_UNREF_SURFACE \
82 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UNREF_SURFACE, \
83 struct drm_vmw_surface_arg)
84 #define DRM_IOCTL_VMW_REF_SURFACE \
85 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_REF_SURFACE, \
86 union drm_vmw_surface_reference_arg)
87 #define DRM_IOCTL_VMW_EXECBUF \
88 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_EXECBUF, \
89 struct drm_vmw_execbuf_arg)
90 #define DRM_IOCTL_VMW_GET_3D_CAP \
91 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_GET_3D_CAP, \
92 struct drm_vmw_get_3d_cap_arg)
93 #define DRM_IOCTL_VMW_FENCE_WAIT \
94 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_FENCE_WAIT, \
95 struct drm_vmw_fence_wait_arg)
96 #define DRM_IOCTL_VMW_FENCE_SIGNALED \
97 DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_FENCE_SIGNALED, \
98 struct drm_vmw_fence_signaled_arg)
99 #define DRM_IOCTL_VMW_FENCE_UNREF \
100 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_FENCE_UNREF, \
101 struct drm_vmw_fence_arg)
102 #define DRM_IOCTL_VMW_FENCE_EVENT \
103 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_FENCE_EVENT, \
104 struct drm_vmw_fence_event_arg)
105 #define DRM_IOCTL_VMW_PRESENT \
106 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT, \
107 struct drm_vmw_present_arg)
108 #define DRM_IOCTL_VMW_PRESENT_READBACK \
109 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT_READBACK, \
110 struct drm_vmw_present_readback_arg)
111 #define DRM_IOCTL_VMW_UPDATE_LAYOUT \
112 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UPDATE_LAYOUT, \
113 struct drm_vmw_update_layout_arg)
120 #define VMW_IOCTL_DEF(ioctl, func, flags) \
121 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {DRM_##ioctl, flags, func, DRM_IOCTL_##ioctl}
127 static struct drm_ioctl_desc vmw_ioctls[] = {
129 DRM_AUTH | DRM_UNLOCKED),
131 DRM_AUTH | DRM_UNLOCKED),
133 DRM_AUTH | DRM_UNLOCKED),
136 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
139 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
141 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
143 DRM_MASTER | DRM_CONTROL_ALLOW | DRM_UNLOCKED),
146 DRM_AUTH | DRM_UNLOCKED),
148 DRM_AUTH | DRM_UNLOCKED),
150 DRM_AUTH | DRM_UNLOCKED),
152 DRM_AUTH | DRM_UNLOCKED),
154 DRM_AUTH | DRM_UNLOCKED),
156 DRM_AUTH | DRM_UNLOCKED),
158 DRM_AUTH | DRM_UNLOCKED),
161 DRM_AUTH | DRM_UNLOCKED),
163 DRM_AUTH | DRM_UNLOCKED),
166 DRM_AUTH | DRM_UNLOCKED),
168 DRM_AUTH | DRM_UNLOCKED),
172 DRM_MASTER | DRM_AUTH | DRM_UNLOCKED),
175 DRM_MASTER | DRM_AUTH | DRM_UNLOCKED),
178 DRM_MASTER | DRM_UNLOCKED),
187 static int enable_fbdev =
IS_ENABLED(CONFIG_DRM_VMWGFX_FBCON);
190 static void vmw_master_init(
struct vmw_master *);
199 DRM_INFO(
"Capabilities:\n");
201 DRM_INFO(
" Rect copy.\n");
203 DRM_INFO(
" Cursor.\n");
205 DRM_INFO(
" Cursor bypass.\n");
207 DRM_INFO(
" Cursor bypass 2.\n");
209 DRM_INFO(
" 8bit emulation.\n");
211 DRM_INFO(
" Alpha cursor.\n");
215 DRM_INFO(
" Extended Fifo.\n");
217 DRM_INFO(
" Multimon.\n");
219 DRM_INFO(
" Pitchlock.\n");
221 DRM_INFO(
" Irq mask.\n");
223 DRM_INFO(
" Display Topology.\n");
227 DRM_INFO(
" Traces.\n");
229 DRM_INFO(
" GMR2.\n");
231 DRM_INFO(
" Screen Object 2.\n");
267 result = ttm_kmap_obj_virtual(&
map, &dummy);
268 result->totalSize =
sizeof(*result);
270 result->result32 = 0xff;
273 DRM_ERROR(
"Dummy query buffer map failed.\n");
289 static int vmw_dummy_query_bo_create(
struct vmw_private *dev_priv)
300 static int vmw_request_device(
struct vmw_private *dev_priv)
306 DRM_ERROR(
"Unable to initialize FIFO.\n");
310 ret = vmw_dummy_query_bo_create(dev_priv);
312 goto out_no_query_bo;
313 vmw_dummy_query_bo_prepare(dev_priv);
323 static void vmw_release_device(
struct vmw_private *dev_priv)
350 ret = vmw_request_device(dev_priv);
353 }
else if (unhide_svga) {
380 vmw_release_device(dev_priv);
381 else if (hide_svga) {
404 static void vmw_get_initial_size(
struct vmw_private *dev_priv)
436 dev_priv = kzalloc(
sizeof(*dev_priv),
GFP_KERNEL);
438 DRM_ERROR(
"Failed allocating a device private struct.\n");
474 DRM_ERROR(
"Unsupported SVGA ID 0x%x\n", svga_id);
486 vmw_get_initial_size(dev_priv);
514 DRM_INFO(
"Max GMR ids is %u\n",
516 DRM_INFO(
"Max GMR descriptors is %u\n",
520 DRM_INFO(
"Max number of GMR pages is %u\n",
522 DRM_INFO(
"Max dedicated hypervisor surface memory is %u kiB\n",
525 DRM_INFO(
"VRAM at 0x%08x size is %u kiB\n",
527 DRM_INFO(
"MMIO at 0x%08x size is %u kiB\n",
545 DRM_ERROR(
"Failed initializing TTM buffer object driver.\n");
552 DRM_ERROR(
"Failed initializing memory manager for VRAM.\n");
559 DRM_INFO(
"No GMR memory available. "
560 "Graphics memory resources are very limited.\n");
572 DRM_ERROR(
"Failed mapping MMIO.\n");
577 if (!(dev_priv->
capabilities & SVGA_CAP_DISPLAY_TOPOLOGY) &&
581 DRM_ERROR(
"Hardware has no pitchlock\n");
589 DRM_ERROR(
"Unable to initialize TTM object management.\n");
594 dev->dev_private = dev_priv;
597 dev_priv->
stealth = (ret != 0);
603 DRM_INFO(
"It appears like vesafb is loaded. "
604 "Ignore above error if any.\n");
607 DRM_ERROR(
"Failed reserving the SVGA MMIO resource.\n");
629 DRM_INFO(
"Detected %sdevice 3D availability.\n",
644 DRM_ERROR(
"Failed installing irq: %d\n", ret);
649 dev_priv->
pm_nb.notifier_call = vmwgfx_pm_notifier;
650 register_pm_notifier(&dev_priv->
pm_nb);
694 static int vmw_driver_unload(
struct drm_device *dev)
698 unregister_pm_notifier(&dev_priv->
pm_nb);
700 if (dev_priv->
ctx.cmd_bounce)
735 static void vmw_preclose(
struct drm_device *dev,
736 struct drm_file *file_priv)
744 static void vmw_postclose(
struct drm_device *dev,
745 struct drm_file *file_priv)
756 static int vmw_driver_open(
struct drm_device *dev,
struct drm_file *file_priv)
762 vmw_fp = kzalloc(
sizeof(*vmw_fp),
GFP_KERNEL);
771 file_priv->driver_priv = vmw_fp;
772 dev_priv->
bdev.dev_mapping = dev->dev_mapping;
781 static long vmw_unlocked_ioctl(
struct file *filp,
unsigned int cmd,
785 struct drm_device *dev = file_priv->minor->dev;
786 unsigned int nr = DRM_IOCTL_NR(cmd);
793 && (nr < DRM_COMMAND_BASE + dev->
driver->num_ioctls)) {
794 struct drm_ioctl_desc *ioctl =
797 if (
unlikely(ioctl->cmd_drv != cmd)) {
798 DRM_ERROR(
"Invalid command format, ioctl %d\n",
807 static int vmw_firstopen(
struct drm_device *dev)
815 static void vmw_lastclose(
struct drm_device *dev)
834 set.connectors =
NULL;
835 set.num_connectors = 0;
839 ret = crtc->
funcs->set_config(&
set);
845 static void vmw_master_init(
struct vmw_master *vmaster)
848 INIT_LIST_HEAD(&vmaster->
fb_surf);
852 static int vmw_master_create(
struct drm_device *dev,
853 struct drm_master *master)
857 vmaster = kzalloc(
sizeof(*vmaster),
GFP_KERNEL);
861 vmw_master_init(vmaster);
863 master->driver_priv = vmaster;
868 static void vmw_master_destroy(
struct drm_device *dev,
869 struct drm_master *master)
873 master->driver_priv =
NULL;
878 static int vmw_master_set(
struct drm_device *dev,
879 struct drm_file *file_priv,
902 goto out_no_active_lock;
907 DRM_ERROR(
"Unable to clean VRAM on "
936 static void vmw_master_drop(
struct drm_device *dev,
937 struct drm_file *file_priv,
955 DRM_ERROR(
"Unable to lock TTM at VT switch.\n");
964 DRM_ERROR(
"Unable to clean VRAM on master drop.\n");
981 static void vmw_remove(
struct pci_dev *pdev)
983 struct drm_device *dev = pci_get_drvdata(pdev);
1028 struct drm_device *dev = pci_get_drvdata(pdev);
1032 DRM_INFO(
"Can't suspend or hibernate "
1033 "while 3D resources are active.\n");
1043 static int vmw_pci_resume(
struct pci_dev *pdev)
1050 static int vmw_pm_suspend(
struct device *kdev)
1057 return vmw_pci_suspend(pdev, dummy);
1060 static int vmw_pm_resume(
struct device *kdev)
1064 return vmw_pci_resume(pdev);
1067 static int vmw_pm_prepare(
struct device *kdev)
1070 struct drm_device *dev = pci_get_drvdata(pdev);
1083 DRM_INFO(
"Can't suspend or hibernate "
1084 "while 3D resources are active.\n");
1095 static void vmw_pm_complete(
struct device *kdev)
1098 struct drm_device *dev = pci_get_drvdata(pdev);
1116 static const struct dev_pm_ops vmw_pm_ops = {
1117 .prepare = vmw_pm_prepare,
1118 .complete = vmw_pm_complete,
1119 .suspend = vmw_pm_suspend,
1120 .resume = vmw_pm_resume,
1127 .unlocked_ioctl = vmw_unlocked_ioctl,
1132 #if defined(CONFIG_COMPAT)
1138 static struct drm_driver
driver = {
1139 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
1141 .load = vmw_driver_load,
1142 .unload = vmw_driver_unload,
1143 .firstopen = vmw_firstopen,
1144 .lastclose = vmw_lastclose,
1152 .ioctls = vmw_ioctls,
1153 .num_ioctls = DRM_ARRAY_SIZE(vmw_ioctls),
1154 .dma_quiescent =
NULL,
1155 .master_create = vmw_master_create,
1156 .master_destroy = vmw_master_destroy,
1157 .master_set = vmw_master_set,
1158 .master_drop = vmw_master_drop,
1159 .open = vmw_driver_open,
1160 .preclose = vmw_preclose,
1161 .postclose = vmw_postclose,
1167 .fops = &vmwgfx_driver_fops,
1178 .id_table = vmw_pci_id_list,
1180 .remove = vmw_remove,
1188 return drm_get_pci_dev(pdev, ent, &driver);
1191 static int __init vmwgfx_init(
void)
1196 DRM_ERROR(
"Failed initializing DRM.\n");
1200 static void __exit vmwgfx_exit(
void)