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>
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
= {
23 .unlocked_ioctl
= drm_ioctl
,
24 .compat_ioctl
= drm_compat_ioctl
,
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
,
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)
88 vkms_device
= kzalloc(sizeof(*vkms_device
), GFP_KERNEL
);
92 ret
= drm_dev_init(&vkms_device
->drm
, &vkms_driver
, NULL
);
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
);
103 vkms_device
->drm
.irq_enabled
= true;
105 ret
= drm_vblank_init(&vkms_device
->drm
, 1);
107 DRM_ERROR("Failed to vblank\n");
111 ret
= vkms_modeset_init(vkms_device
);
115 ret
= drm_dev_register(&vkms_device
->drm
, 0);
122 platform_device_unregister(vkms_device
->platform
);
125 drm_dev_fini(&vkms_device
->drm
);
132 static void __exit
vkms_exit(void)
135 DRM_INFO("vkms_device is NULL.\n");
139 drm_dev_unregister(&vkms_device
->drm
);
140 drm_dev_put(&vkms_device
->drm
);
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");