Linux 4.19.133
[linux/fpc-iii.git] / drivers / gpu / drm / vkms / vkms_drv.c
blobb1201c18d3ebbfe19caa0b3f8738a4762499b663
1 // SPDX-License-Identifier: GPL-2.0+
3 #include <linux/module.h>
4 #include <drm/drm_gem.h>
5 #include <drm/drm_crtc_helper.h>
6 #include <drm/drm_atomic_helper.h>
7 #include <drm/drm_gem_framebuffer_helper.h>
8 #include <drm/drm_fb_helper.h>
9 #include "vkms_drv.h"
11 #define DRIVER_NAME "vkms"
12 #define DRIVER_DESC "Virtual Kernel Mode Setting"
13 #define DRIVER_DATE "20180514"
14 #define DRIVER_MAJOR 1
15 #define DRIVER_MINOR 0
17 static struct vkms_device *vkms_device;
19 static const struct file_operations vkms_driver_fops = {
20 .owner = THIS_MODULE,
21 .open = drm_open,
22 .mmap = drm_gem_mmap,
23 .unlocked_ioctl = drm_ioctl,
24 .compat_ioctl = drm_compat_ioctl,
25 .poll = drm_poll,
26 .read = drm_read,
27 .llseek = no_llseek,
28 .release = drm_release,
31 static const struct vm_operations_struct vkms_gem_vm_ops = {
32 .fault = vkms_gem_fault,
33 .open = drm_gem_vm_open,
34 .close = drm_gem_vm_close,
37 static void vkms_release(struct drm_device *dev)
39 struct vkms_device *vkms = container_of(dev, struct vkms_device, drm);
41 platform_device_unregister(vkms->platform);
42 drm_atomic_helper_shutdown(&vkms->drm);
43 drm_mode_config_cleanup(&vkms->drm);
44 drm_dev_fini(&vkms->drm);
47 static struct drm_driver vkms_driver = {
48 .driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
49 .release = vkms_release,
50 .fops = &vkms_driver_fops,
51 .dumb_create = vkms_dumb_create,
52 .dumb_map_offset = vkms_dumb_map,
53 .gem_vm_ops = &vkms_gem_vm_ops,
54 .gem_free_object_unlocked = vkms_gem_free_object,
55 .get_vblank_timestamp = vkms_get_vblank_timestamp,
57 .name = DRIVER_NAME,
58 .desc = DRIVER_DESC,
59 .date = DRIVER_DATE,
60 .major = DRIVER_MAJOR,
61 .minor = DRIVER_MINOR,
64 static const struct drm_mode_config_funcs vkms_mode_funcs = {
65 .fb_create = drm_gem_fb_create,
66 .atomic_check = drm_atomic_helper_check,
67 .atomic_commit = drm_atomic_helper_commit,
70 static int vkms_modeset_init(struct vkms_device *vkmsdev)
72 struct drm_device *dev = &vkmsdev->drm;
74 drm_mode_config_init(dev);
75 dev->mode_config.funcs = &vkms_mode_funcs;
76 dev->mode_config.min_width = XRES_MIN;
77 dev->mode_config.min_height = YRES_MIN;
78 dev->mode_config.max_width = XRES_MAX;
79 dev->mode_config.max_height = YRES_MAX;
81 return vkms_output_init(vkmsdev);
84 static int __init vkms_init(void)
86 int ret;
88 vkms_device = kzalloc(sizeof(*vkms_device), GFP_KERNEL);
89 if (!vkms_device)
90 return -ENOMEM;
92 ret = drm_dev_init(&vkms_device->drm, &vkms_driver, NULL);
93 if (ret)
94 goto out_free;
96 vkms_device->platform =
97 platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
98 if (IS_ERR(vkms_device->platform)) {
99 ret = PTR_ERR(vkms_device->platform);
100 goto out_fini;
103 vkms_device->drm.irq_enabled = true;
105 ret = drm_vblank_init(&vkms_device->drm, 1);
106 if (ret) {
107 DRM_ERROR("Failed to vblank\n");
108 goto out_fini;
111 ret = vkms_modeset_init(vkms_device);
112 if (ret)
113 goto out_unregister;
115 ret = drm_dev_register(&vkms_device->drm, 0);
116 if (ret)
117 goto out_unregister;
119 return 0;
121 out_unregister:
122 platform_device_unregister(vkms_device->platform);
124 out_fini:
125 drm_dev_fini(&vkms_device->drm);
127 out_free:
128 kfree(vkms_device);
129 return ret;
132 static void __exit vkms_exit(void)
134 if (!vkms_device) {
135 DRM_INFO("vkms_device is NULL.\n");
136 return;
139 drm_dev_unregister(&vkms_device->drm);
140 drm_dev_put(&vkms_device->drm);
142 kfree(vkms_device);
145 module_init(vkms_init);
146 module_exit(vkms_exit);
148 MODULE_AUTHOR("Haneen Mohammed <hamohammed.sa@gmail.com>");
149 MODULE_AUTHOR("Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>");
150 MODULE_DESCRIPTION(DRIVER_DESC);
151 MODULE_LICENSE("GPL");