From patchwork Mon May 14 14:33:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haneen Mohammed X-Patchwork-Id: 10400083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A767E601E9 for ; Tue, 15 May 2018 07:02:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 787FE285EA for ; Tue, 15 May 2018 07:02:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D502285F9; Tue, 15 May 2018 07:02:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 75E9E285EA for ; Tue, 15 May 2018 07:02:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 99C886E170; Tue, 15 May 2018 07:01:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BCDD89CA1 for ; Mon, 14 May 2018 14:33:52 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id v60-v6so12605018wrc.7 for ; Mon, 14 May 2018 07:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=ITtS4G+yELAAZ+79g8X4m3XARphSzjAuEmP7DtTjLQ0=; b=k6VvK/sbZ85U5rgWhOGKTp5yA8E/m+xOkHZNfslnKtWeKbB6gHx58etHYz4hesqchx X5clHxndxEfSsvxk6mNnfOZw+o3DNT8QwVvRNCIUelURWd1ngu+Htxk5w8Zt8q1KODEU azVRJmO7bl3Bex4e+ZrHvr3ukLkBdR1bW5THc7LRwWUzSZvbD1DflqNp6VVKa9Lxf+IU Q+tToCVidE4Xj7GRP+Qu+oRF45E6pQiLsto44jiz0/Q7w12lltZiv6i1nflFa3Lyjt1W 8Oi9vyIhjuFwvi/gOUcJMJQVUGmj9q2kUTeIY+0zLv01cEtUqn9kF/KAr0B/JmM8e71/ V5aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=ITtS4G+yELAAZ+79g8X4m3XARphSzjAuEmP7DtTjLQ0=; b=i47CF5fG7E01BOzac90XDigYbsBMMvJGGIB/QwMCO99gH2ftFXwpR3R+BFcjchDr83 5OujamLZ7ftc+PzaJU9C7N6QW0jrgxq4xXktq0whpm/mbj+yi2ex+en5f2o063sLONCI qrZotUqGeE9HwXRRmsfYOubcY4hWbMzasIp8VN0bjoXZhaAe/UyMRwtJjEuc9rSGSTrj ZLaKPCitkS2RZPBZ7+JOX2jdYHt/tyFEq7k8yQxIhSa8O5CPjrR6WcPffryzI21p9Eqc pnujmjrmyr7j2+Dl362re/iDbHk1TC3D4xWVhdTP+y9rhbXgPngLUUUmvSJPkbHybbpK /J9A== X-Gm-Message-State: ALKqPweJ9GGZn76M798TtTX/fqK87iAeAEwfRLN3OoCEDlaWItxN7oZl 4D0Cf5csUNtwMgjiEGS+SM3rUQ== X-Google-Smtp-Source: AB8JxZq4aFbzwORozVODJIDoezcPaFAauxA5HnP3iWrHDAqLhCEfmmpSFcRTN/TQyna3lM7mw1LXcQ== X-Received: by 2002:adf:c362:: with SMTP id e31-v6mr7098999wrg.257.1526308431025; Mon, 14 May 2018 07:33:51 -0700 (PDT) Received: from haneen-vb ([188.53.191.69]) by smtp.gmail.com with ESMTPSA id b72-v6sm12960465wmf.11.2018.05.14.07.33.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 07:33:50 -0700 (PDT) Date: Mon, 14 May 2018 17:33:46 +0300 From: Haneen Mohammed To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/vkms: Introduce basic VKMS driver Message-ID: <20180514143346.GA21695@haneen-vb> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Mailman-Approved-At: Tue, 15 May 2018 07:01:55 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, rodrigosiqueiramelo@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/gpu/drm/Kconfig | 6 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/vkms/Makefile | 3 + drivers/gpu/drm/vkms/vkms_drv.c | 146 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.h | 13 +++ 5 files changed, 169 insertions(+) create mode 100644 drivers/gpu/drm/vkms/Makefile create mode 100644 drivers/gpu/drm/vkms/vkms_drv.c create mode 100644 drivers/gpu/drm/vkms/vkms_drv.h 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 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" diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index ef9f3dab287f..8873d4769116 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -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/ 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 @@ +vkms-y := vkms_drv.o + +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 @@ +/* + * 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 +#include +#include +#include +#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"); 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 @@ +#ifndef _VKMS_DRV_H_ +#define _VKMS_DRV_H_ + +#include + +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_ */