diff options
| author | Haneen Mohammed <hamohammed.sa@gmail.com> | 2018-05-14 10:33:46 -0400 |
|---|---|---|
| committer | Gustavo Padovan <gustavo.padovan@collabora.com> | 2018-07-05 08:45:56 -0400 |
| commit | 1c7c5fd916a0ff66501467f1e8e79d3ff8eca112 (patch) | |
| tree | 9264aebf700137fa512c2725cb38f7a28bb6fab6 /drivers | |
| parent | c51756d56e20a12476e4e192b332fac39c1550ca (diff) | |
drm/vkms: Introduce basic VKMS driver
This patch introduces Virtual Kernel Mode-Setting (VKMS) driver. It
creates a very basic kms driver with 1 crtc/encoder/connector/plane.
VKMS driver would be useful for testing, or for running X (or similar)
on headless machines and be able to still use the GPU. Thus it enables
a virtual display without the need for hardware display capability.
Signed-off-by: Haneen Mohammed <hamohammed.sa@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180514143346.GA21695@haneen-vb
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/gpu/drm/Kconfig | 6 | ||||
| -rw-r--r-- | drivers/gpu/drm/Makefile | 1 | ||||
| -rw-r--r-- | drivers/gpu/drm/vkms/Makefile | 3 | ||||
| -rw-r--r-- | drivers/gpu/drm/vkms/vkms_drv.c | 146 | ||||
| -rw-r--r-- | drivers/gpu/drm/vkms/vkms_drv.h | 13 |
5 files changed, 169 insertions, 0 deletions
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 2a72d2feb76d..7db3d82cbb27 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig | |||
| @@ -213,6 +213,12 @@ config DRM_VGEM | |||
| 213 | as used by Mesa's software renderer for enhanced performance. | 213 | as used by Mesa's software renderer for enhanced performance. |
| 214 | If M is selected the module will be called vgem. | 214 | If M is selected the module will be called vgem. |
| 215 | 215 | ||
| 216 | config DRM_VKMS | ||
| 217 | tristate "Virtual KMS" | ||
| 218 | depends on DRM | ||
| 219 | help | ||
| 220 | Choose this option to get a virtual kernal mode-setting driver. | ||
| 221 | If M is selected the module will be called vkms. | ||
| 216 | 222 | ||
| 217 | source "drivers/gpu/drm/exynos/Kconfig" | 223 | source "drivers/gpu/drm/exynos/Kconfig" |
| 218 | 224 | ||
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 69c13517ea3a..6ae535ca0914 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile | |||
| @@ -69,6 +69,7 @@ obj-$(CONFIG_DRM_SAVAGE)+= savage/ | |||
| 69 | obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/ | 69 | obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/ |
| 70 | obj-$(CONFIG_DRM_VIA) +=via/ | 70 | obj-$(CONFIG_DRM_VIA) +=via/ |
| 71 | obj-$(CONFIG_DRM_VGEM) += vgem/ | 71 | obj-$(CONFIG_DRM_VGEM) += vgem/ |
| 72 | obj-$(CONFIG_DRM_VKMS) += vkms/ | ||
| 72 | obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/ | 73 | obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/ |
| 73 | obj-$(CONFIG_DRM_EXYNOS) +=exynos/ | 74 | obj-$(CONFIG_DRM_EXYNOS) +=exynos/ |
| 74 | obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/ | 75 | obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/ |
diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile new file mode 100644 index 000000000000..2aef948d3a34 --- /dev/null +++ b/drivers/gpu/drm/vkms/Makefile | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | vkms-y := vkms_drv.o | ||
| 2 | |||
| 3 | obj-$(CONFIG_DRM_VKMS) += vkms.o | ||
diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c new file mode 100644 index 000000000000..b1df08ed23a0 --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_drv.c | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | /* | ||
| 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. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <linux/module.h> | ||
| 9 | #include <drm/drmP.h> | ||
| 10 | #include <drm/drm_gem.h> | ||
| 11 | #include <drm/drm_crtc_helper.h> | ||
| 12 | #include "vkms_drv.h" | ||
| 13 | |||
| 14 | #define DRIVER_NAME "vkms" | ||
| 15 | #define DRIVER_DESC "Virtual Kernel Mode Setting" | ||
| 16 | #define DRIVER_DATE "20180514" | ||
| 17 | #define DRIVER_MAJOR 1 | ||
| 18 | #define DRIVER_MINOR 0 | ||
| 19 | |||
| 20 | static struct vkms_device *vkms_device; | ||
| 21 | |||
| 22 | static const struct file_operations vkms_driver_fops = { | ||
| 23 | .owner = THIS_MODULE, | ||
| 24 | .open = drm_open, | ||
| 25 | .mmap = drm_gem_mmap, | ||
| 26 | .unlocked_ioctl = drm_ioctl, | ||
| 27 | .compat_ioctl = drm_compat_ioctl, | ||
| 28 | .poll = drm_poll, | ||
| 29 | .read = drm_read, | ||
| 30 | .llseek = no_llseek, | ||
| 31 | .release = drm_release, | ||
| 32 | }; | ||
| 33 | |||
| 34 | static void vkms_release(struct drm_device *dev) | ||
| 35 | { | ||
| 36 | struct vkms_device *vkms = container_of(dev, struct vkms_device, drm); | ||
| 37 | |||
| 38 | platform_device_unregister(vkms->platform); | ||
| 39 | drm_mode_config_cleanup(&vkms->drm); | ||
| 40 | drm_dev_fini(&vkms->drm); | ||
| 41 | } | ||
| 42 | |||
| 43 | struct drm_driver vkms_driver = { | ||
| 44 | .driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM, | ||
| 45 | .release = vkms_release, | ||
| 46 | .fops = &vkms_driver_fops, | ||
| 47 | |||
| 48 | .name = DRIVER_NAME, | ||
| 49 | .desc = DRIVER_DESC, | ||
| 50 | .date = DRIVER_DATE, | ||
| 51 | .major = DRIVER_MAJOR, | ||
| 52 | .minor = DRIVER_MINOR, | ||
| 53 | }; | ||
| 54 | |||
| 55 | static const u32 vkms_formats[] = { | ||
| 56 | DRM_FORMAT_XRGB8888, | ||
| 57 | }; | ||
| 58 | |||
| 59 | static void vkms_connector_destroy(struct drm_connector *connector) | ||
| 60 | { | ||
| 61 | drm_connector_unregister(connector); | ||
| 62 | drm_connector_cleanup(connector); | ||
| 63 | } | ||
| 64 | |||
| 65 | static const struct drm_connector_funcs vkms_connector_funcs = { | ||
| 66 | .fill_modes = drm_helper_probe_single_connector_modes, | ||
| 67 | .destroy = vkms_connector_destroy, | ||
| 68 | }; | ||
| 69 | |||
| 70 | static int __init vkms_init(void) | ||
| 71 | { | ||
| 72 | int ret; | ||
| 73 | |||
| 74 | vkms_device = kzalloc(sizeof(*vkms_device), GFP_KERNEL); | ||
| 75 | if (!vkms_device) | ||
| 76 | return -ENOMEM; | ||
| 77 | |||
| 78 | ret = drm_dev_init(&vkms_device->drm, &vkms_driver, NULL); | ||
| 79 | if (ret) | ||
| 80 | goto out_free; | ||
| 81 | |||
| 82 | vkms_device->platform = | ||
| 83 | platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); | ||
| 84 | if (IS_ERR(vkms_device->platform)) { | ||
| 85 | ret = PTR_ERR(vkms_device->platform); | ||
| 86 | goto out_fini; | ||
| 87 | } | ||
| 88 | |||
| 89 | drm_mode_config_init(&vkms_device->drm); | ||
| 90 | |||
| 91 | ret = drm_connector_init(&vkms_device->drm, &vkms_device->connector, | ||
| 92 | &vkms_connector_funcs, | ||
| 93 | DRM_MODE_CONNECTOR_VIRTUAL); | ||
| 94 | if (ret < 0) { | ||
| 95 | DRM_ERROR("Failed to init connector\n"); | ||
| 96 | goto out_unregister; | ||
| 97 | } | ||
| 98 | |||
| 99 | ret = drm_simple_display_pipe_init(&vkms_device->drm, | ||
| 100 | &vkms_device->pipe, | ||
| 101 | NULL, | ||
| 102 | vkms_formats, | ||
| 103 | ARRAY_SIZE(vkms_formats), | ||
| 104 | NULL, | ||
| 105 | &vkms_device->connector); | ||
| 106 | if (ret < 0) { | ||
| 107 | DRM_ERROR("Cannot setup simple display pipe\n"); | ||
| 108 | goto out_unregister; | ||
| 109 | } | ||
| 110 | |||
| 111 | ret = drm_dev_register(&vkms_device->drm, 0); | ||
| 112 | if (ret) | ||
| 113 | goto out_unregister; | ||
| 114 | |||
| 115 | drm_connector_register(&vkms_device->connector); | ||
| 116 | |||
| 117 | return 0; | ||
| 118 | |||
| 119 | out_unregister: | ||
| 120 | platform_device_unregister(vkms_device->platform); | ||
| 121 | out_fini: | ||
| 122 | drm_dev_fini(&vkms_device->drm); | ||
| 123 | out_free: | ||
| 124 | kfree(vkms_device); | ||
| 125 | |||
| 126 | return ret; | ||
| 127 | } | ||
| 128 | |||
| 129 | static void __exit vkms_exit(void) | ||
| 130 | { | ||
| 131 | if (!vkms_device) { | ||
| 132 | DRM_INFO("vkms_device is NULL.\n"); | ||
| 133 | return; | ||
| 134 | } | ||
| 135 | |||
| 136 | drm_dev_unregister(&vkms_device->drm); | ||
| 137 | drm_dev_put(&vkms_device->drm); | ||
| 138 | |||
| 139 | kfree(vkms_device); | ||
| 140 | } | ||
| 141 | |||
| 142 | module_init(vkms_init); | ||
| 143 | module_exit(vkms_exit); | ||
| 144 | |||
| 145 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
| 146 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h new file mode 100644 index 000000000000..c77c5bf5032a --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_drv.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #ifndef _VKMS_DRV_H_ | ||
| 2 | #define _VKMS_DRV_H_ | ||
| 3 | |||
| 4 | #include <drm/drm_simple_kms_helper.h> | ||
| 5 | |||
| 6 | struct vkms_device { | ||
| 7 | struct drm_device drm; | ||
| 8 | struct platform_device *platform; | ||
| 9 | struct drm_simple_display_pipe pipe; | ||
| 10 | struct drm_connector connector; | ||
| 11 | }; | ||
| 12 | |||
| 13 | #endif /* _VKMS_DRV_H_ */ | ||
