2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
9 * DOC: vkms (Virtual Kernel Modesetting)
11 * vkms is a software-only model of a kms driver that is useful for testing,
12 * or for running X (or similar) on headless machines and be able to still
13 * use the GPU. vkms aims to enable a virtual display without the need for
14 * a hardware display capability.
17 #include <linux/module.h>
18 #include <drm/drm_gem.h>
19 #include <drm/drm_atomic_helper.h>
20 #include <drm/drm_gem_framebuffer_helper.h>
21 #include <drm/drm_fb_helper.h>
22 #include <drm/drm_probe_helper.h>
25 #define DRIVER_NAME "vkms"
26 #define DRIVER_DESC "Virtual Kernel Mode Setting"
27 #define DRIVER_DATE "20180514"
28 #define DRIVER_MAJOR 1
29 #define DRIVER_MINOR 0
31 static struct vkms_device
*vkms_device
;
34 module_param_named(enable_cursor
, enable_cursor
, bool, 0444);
35 MODULE_PARM_DESC(enable_cursor
, "Enable/Disable cursor support");
37 static const struct file_operations vkms_driver_fops
= {
41 .unlocked_ioctl
= drm_ioctl
,
42 .compat_ioctl
= drm_compat_ioctl
,
46 .release
= drm_release
,
49 static const struct vm_operations_struct vkms_gem_vm_ops
= {
50 .fault
= vkms_gem_fault
,
51 .open
= drm_gem_vm_open
,
52 .close
= drm_gem_vm_close
,
55 static void vkms_release(struct drm_device
*dev
)
57 struct vkms_device
*vkms
= container_of(dev
, struct vkms_device
, drm
);
59 platform_device_unregister(vkms
->platform
);
60 drm_atomic_helper_shutdown(&vkms
->drm
);
61 drm_mode_config_cleanup(&vkms
->drm
);
62 drm_dev_fini(&vkms
->drm
);
63 destroy_workqueue(vkms
->output
.crc_workq
);
66 static struct drm_driver vkms_driver
= {
67 .driver_features
= DRIVER_MODESET
| DRIVER_ATOMIC
| DRIVER_GEM
,
68 .release
= vkms_release
,
69 .fops
= &vkms_driver_fops
,
70 .dumb_create
= vkms_dumb_create
,
71 .gem_vm_ops
= &vkms_gem_vm_ops
,
72 .gem_free_object_unlocked
= vkms_gem_free_object
,
73 .get_vblank_timestamp
= vkms_get_vblank_timestamp
,
78 .major
= DRIVER_MAJOR
,
79 .minor
= DRIVER_MINOR
,
82 static const struct drm_mode_config_funcs vkms_mode_funcs
= {
83 .fb_create
= drm_gem_fb_create
,
84 .atomic_check
= drm_atomic_helper_check
,
85 .atomic_commit
= drm_atomic_helper_commit
,
88 static int vkms_modeset_init(struct vkms_device
*vkmsdev
)
90 struct drm_device
*dev
= &vkmsdev
->drm
;
92 drm_mode_config_init(dev
);
93 dev
->mode_config
.funcs
= &vkms_mode_funcs
;
94 dev
->mode_config
.min_width
= XRES_MIN
;
95 dev
->mode_config
.min_height
= YRES_MIN
;
96 dev
->mode_config
.max_width
= XRES_MAX
;
97 dev
->mode_config
.max_height
= YRES_MAX
;
98 dev
->mode_config
.preferred_depth
= 24;
100 return vkms_output_init(vkmsdev
);
103 static int __init
vkms_init(void)
107 vkms_device
= kzalloc(sizeof(*vkms_device
), GFP_KERNEL
);
111 vkms_device
->platform
=
112 platform_device_register_simple(DRIVER_NAME
, -1, NULL
, 0);
113 if (IS_ERR(vkms_device
->platform
)) {
114 ret
= PTR_ERR(vkms_device
->platform
);
118 ret
= drm_dev_init(&vkms_device
->drm
, &vkms_driver
,
119 &vkms_device
->platform
->dev
);
123 vkms_device
->drm
.irq_enabled
= true;
125 ret
= drm_vblank_init(&vkms_device
->drm
, 1);
127 DRM_ERROR("Failed to vblank\n");
131 ret
= vkms_modeset_init(vkms_device
);
135 ret
= drm_dev_register(&vkms_device
->drm
, 0);
142 drm_dev_fini(&vkms_device
->drm
);
145 platform_device_unregister(vkms_device
->platform
);
152 static void __exit
vkms_exit(void)
155 DRM_INFO("vkms_device is NULL.\n");
159 drm_dev_unregister(&vkms_device
->drm
);
160 drm_dev_put(&vkms_device
->drm
);
165 module_init(vkms_init
);
166 module_exit(vkms_exit
);
168 MODULE_AUTHOR("Haneen Mohammed <hamohammed.sa@gmail.com>");
169 MODULE_AUTHOR("Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>");
170 MODULE_DESCRIPTION(DRIVER_DESC
);
171 MODULE_LICENSE("GPL");