Skip to content

Commit

Permalink
drm/vkms: Introduce basic VKMS driver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Haneen Mohammed authored and Gustavo Padovan committed Jul 5, 2018
1 parent c51756d commit 1c7c5fd
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/gpu/drm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ config DRM_VGEM
as used by Mesa's software renderer for enhanced performance.
If M is selected the module will be called vgem.

config DRM_VKMS
tristate "Virtual KMS"
depends on DRM
help
Choose this option to get a virtual kernal mode-setting driver.
If M is selected the module will be called vkms.

source "drivers/gpu/drm/exynos/Kconfig"

Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ obj-$(CONFIG_DRM_SAVAGE)+= savage/
obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
obj-$(CONFIG_DRM_VIA) +=via/
obj-$(CONFIG_DRM_VGEM) += vgem/
obj-$(CONFIG_DRM_VKMS) += vkms/
obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
obj-$(CONFIG_DRM_EXYNOS) +=exynos/
obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/vkms/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vkms-y := vkms_drv.o

obj-$(CONFIG_DRM_VKMS) += vkms.o
146 changes: 146 additions & 0 deletions drivers/gpu/drm/vkms/vkms_drv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/

#include <linux/module.h>
#include <drm/drmP.h>
#include <drm/drm_gem.h>
#include <drm/drm_crtc_helper.h>
#include "vkms_drv.h"

#define DRIVER_NAME "vkms"
#define DRIVER_DESC "Virtual Kernel Mode Setting"
#define DRIVER_DATE "20180514"
#define DRIVER_MAJOR 1
#define DRIVER_MINOR 0

static struct vkms_device *vkms_device;

static const struct file_operations vkms_driver_fops = {
.owner = THIS_MODULE,
.open = drm_open,
.mmap = drm_gem_mmap,
.unlocked_ioctl = drm_ioctl,
.compat_ioctl = drm_compat_ioctl,
.poll = drm_poll,
.read = drm_read,
.llseek = no_llseek,
.release = drm_release,
};

static void vkms_release(struct drm_device *dev)
{
struct vkms_device *vkms = container_of(dev, struct vkms_device, drm);

platform_device_unregister(vkms->platform);
drm_mode_config_cleanup(&vkms->drm);
drm_dev_fini(&vkms->drm);
}

struct drm_driver vkms_driver = {
.driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
.release = vkms_release,
.fops = &vkms_driver_fops,

.name = DRIVER_NAME,
.desc = DRIVER_DESC,
.date = DRIVER_DATE,
.major = DRIVER_MAJOR,
.minor = DRIVER_MINOR,
};

static const u32 vkms_formats[] = {
DRM_FORMAT_XRGB8888,
};

static void vkms_connector_destroy(struct drm_connector *connector)
{
drm_connector_unregister(connector);
drm_connector_cleanup(connector);
}

static const struct drm_connector_funcs vkms_connector_funcs = {
.fill_modes = drm_helper_probe_single_connector_modes,
.destroy = vkms_connector_destroy,
};

static int __init vkms_init(void)
{
int ret;

vkms_device = kzalloc(sizeof(*vkms_device), GFP_KERNEL);
if (!vkms_device)
return -ENOMEM;

ret = drm_dev_init(&vkms_device->drm, &vkms_driver, NULL);
if (ret)
goto out_free;

vkms_device->platform =
platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
if (IS_ERR(vkms_device->platform)) {
ret = PTR_ERR(vkms_device->platform);
goto out_fini;
}

drm_mode_config_init(&vkms_device->drm);

ret = drm_connector_init(&vkms_device->drm, &vkms_device->connector,
&vkms_connector_funcs,
DRM_MODE_CONNECTOR_VIRTUAL);
if (ret < 0) {
DRM_ERROR("Failed to init connector\n");
goto out_unregister;
}

ret = drm_simple_display_pipe_init(&vkms_device->drm,
&vkms_device->pipe,
NULL,
vkms_formats,
ARRAY_SIZE(vkms_formats),
NULL,
&vkms_device->connector);
if (ret < 0) {
DRM_ERROR("Cannot setup simple display pipe\n");
goto out_unregister;
}

ret = drm_dev_register(&vkms_device->drm, 0);
if (ret)
goto out_unregister;

drm_connector_register(&vkms_device->connector);

return 0;

out_unregister:
platform_device_unregister(vkms_device->platform);
out_fini:
drm_dev_fini(&vkms_device->drm);
out_free:
kfree(vkms_device);

return ret;
}

static void __exit vkms_exit(void)
{
if (!vkms_device) {
DRM_INFO("vkms_device is NULL.\n");
return;
}

drm_dev_unregister(&vkms_device->drm);
drm_dev_put(&vkms_device->drm);

kfree(vkms_device);
}

module_init(vkms_init);
module_exit(vkms_exit);

MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");
13 changes: 13 additions & 0 deletions drivers/gpu/drm/vkms/vkms_drv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _VKMS_DRV_H_
#define _VKMS_DRV_H_

#include <drm/drm_simple_kms_helper.h>

struct vkms_device {
struct drm_device drm;
struct platform_device *platform;
struct drm_simple_display_pipe pipe;
struct drm_connector connector;
};

#endif /* _VKMS_DRV_H_ */

0 comments on commit 1c7c5fd

Please sign in to comment.