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.
8 #include <linux/module.h>
9 #include <drm/drm_gem.h>
10 #include <drm/drm_crtc_helper.h>
11 #include <drm/drm_atomic_helper.h>
12 #include <drm/drm_gem_framebuffer_helper.h>
13 #include <drm/drm_fb_helper.h>
16 #define DRIVER_NAME "vkms"
17 #define DRIVER_DESC "Virtual Kernel Mode Setting"
18 #define DRIVER_DATE "20180514"
19 #define DRIVER_MAJOR 1
20 #define DRIVER_MINOR 0
22 static struct vkms_device *vkms_device;
24 static const struct file_operations vkms_driver_fops = {
28 .unlocked_ioctl = drm_ioctl,
29 .compat_ioctl = drm_compat_ioctl,
33 .release = drm_release,
36 static const struct vm_operations_struct vkms_gem_vm_ops = {
37 .fault = vkms_gem_fault,
38 .open = drm_gem_vm_open,
39 .close = drm_gem_vm_close,
42 static void vkms_release(struct drm_device *dev)
44 struct vkms_device *vkms = container_of(dev, struct vkms_device, drm);
46 platform_device_unregister(vkms->platform);
47 drm_atomic_helper_shutdown(&vkms->drm);
48 drm_mode_config_cleanup(&vkms->drm);
49 drm_dev_fini(&vkms->drm);
50 destroy_workqueue(vkms->output.crc_workq);
53 static struct drm_driver vkms_driver = {
54 .driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
55 .release = vkms_release,
56 .fops = &vkms_driver_fops,
57 .dumb_create = vkms_dumb_create,
58 .dumb_map_offset = vkms_dumb_map,
59 .gem_vm_ops = &vkms_gem_vm_ops,
60 .gem_free_object_unlocked = vkms_gem_free_object,
61 .get_vblank_timestamp = vkms_get_vblank_timestamp,
66 .major = DRIVER_MAJOR,
67 .minor = DRIVER_MINOR,
70 static const struct drm_mode_config_funcs vkms_mode_funcs = {
71 .fb_create = drm_gem_fb_create,
72 .atomic_check = drm_atomic_helper_check,
73 .atomic_commit = drm_atomic_helper_commit,
76 static int vkms_modeset_init(struct vkms_device *vkmsdev)
78 struct drm_device *dev = &vkmsdev->drm;
80 drm_mode_config_init(dev);
81 dev->mode_config.funcs = &vkms_mode_funcs;
82 dev->mode_config.min_width = XRES_MIN;
83 dev->mode_config.min_height = YRES_MIN;
84 dev->mode_config.max_width = XRES_MAX;
85 dev->mode_config.max_height = YRES_MAX;
87 return vkms_output_init(vkmsdev);
90 static int __init vkms_init(void)
94 vkms_device = kzalloc(sizeof(*vkms_device), GFP_KERNEL);
98 ret = drm_dev_init(&vkms_device->drm, &vkms_driver, NULL);
102 vkms_device->platform =
103 platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
104 if (IS_ERR(vkms_device->platform)) {
105 ret = PTR_ERR(vkms_device->platform);
109 vkms_device->drm.irq_enabled = true;
111 ret = drm_vblank_init(&vkms_device->drm, 1);
113 DRM_ERROR("Failed to vblank\n");
117 ret = vkms_modeset_init(vkms_device);
121 ret = drm_dev_register(&vkms_device->drm, 0);
128 platform_device_unregister(vkms_device->platform);
131 drm_dev_fini(&vkms_device->drm);
138 static void __exit vkms_exit(void)
141 DRM_INFO("vkms_device is NULL.\n");
145 drm_dev_unregister(&vkms_device->drm);
146 drm_dev_put(&vkms_device->drm);
151 module_init(vkms_init);
152 module_exit(vkms_exit);
154 MODULE_AUTHOR("Haneen Mohammed <hamohammed.sa@gmail.com>");
155 MODULE_AUTHOR("Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>");
156 MODULE_DESCRIPTION(DRIVER_DESC);
157 MODULE_LICENSE("GPL");