Skip to contentSkip to conversation

staging: vboxvideo: Add vboxvideo to drivers/staging

PATCH Superseded Hans de Goede 3 participants 4 messages Jun 26, 2017 – Jun 28, 2017 Staging

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 staging: vboxvideo: Add vboxvideo to drivers/staging

This commit adds the vboxvideo drm/kms driver for the virtual graphics card used in Virtual Box virtual machines to drivers/staging.

Why drivers/staging? This driver is already being patched into the kernel by several distros, thus it is good to get this driver upstream soon, so that work on the driver can be easily shared.

At the same time we want to take our time to get this driver properly cleaned up (mainly converted to the new atomic modesetting APIs) before submitting it as a normal driver under drivers/gpu/drm, putting this driver in staging for now allows both.

Note this driver has already been significantly cleaned up, when I started working on this the files under /usr/src/vboxguest/vboxvideo as installed by Virtual Box 5.1.18 Guest Additions had a total linecount of 52681 lines. The version in this commit has 4874 lines.

---
Changes in v2:
-Add Michael's S-o-b
-Improve Kconfig help text
-Remove .config changes which accidentally got added to the commit

Changes in v3:
-Convert the files shared with the video-driver for other operating-systems
to kernel coding style too
-Remove unused code from these files

Changes in v4:
-Removed some unneeded local variable initializations
-Reworked some code paths to have the straight (error free path) keep the
same indendation by checking for failure + bailing rather then nesting success checks into each other
-Reworked error handling to clean up acquired resources in the failing
init / create function, rather then calling the fini / destroy counterpart on a partly initialized struct / object
-Use devm_kzalloc and friends for simpler error handling and _fini functions

---
 drivers/staging/Kconfig                     |   2 +
 drivers/staging/Makefile                    |   1 +
 drivers/staging/vboxvideo/Kconfig           |  12 +
 drivers/staging/vboxvideo/Makefile          |   7 +
 drivers/staging/vboxvideo/TODO              |   9 +
 drivers/staging/vboxvideo/hgsmi_base.c      | 246 ++++++++
 drivers/staging/vboxvideo/hgsmi_ch_setup.h  |  66 +++
 drivers/staging/vboxvideo/hgsmi_channels.h  |  53 ++
 drivers/staging/vboxvideo/hgsmi_defs.h      |  92 +++
 drivers/staging/vboxvideo/modesetting.c     | 142 +++++
 drivers/staging/vboxvideo/vbox_drv.c        | 287 +++++++++
 drivers/staging/vboxvideo/vbox_drv.h        | 297 ++++++++++
 drivers/staging/vboxvideo/vbox_err.h        |  50 ++
 drivers/staging/vboxvideo/vbox_fb.c         | 426 ++++++++++++++
 drivers/staging/vboxvideo/vbox_hgsmi.c      | 115 ++++
 drivers/staging/vboxvideo/vbox_irq.c        | 197 +++++++
 drivers/staging/vboxvideo/vbox_main.c       | 534 +++++++++++++++++
 drivers/staging/vboxvideo/vbox_mode.c       | 877 ++++++++++++++++++++++++++++
 drivers/staging/vboxvideo/vbox_prime.c      |  74 +++
 drivers/staging/vboxvideo/vbox_ttm.c        | 472 +++++++++++++++
 drivers/staging/vboxvideo/vboxvideo.h       | 491 ++++++++++++++++
 drivers/staging/vboxvideo/vboxvideo_guest.h |  95 +++
 drivers/staging/vboxvideo/vboxvideo_vbe.h   |  84 +++
 drivers/staging/vboxvideo/vbva_base.c       | 233 ++++++++
 24 files changed, 4862 insertions(+)
 create mode 100644 drivers/staging/vboxvideo/Kconfig
 create mode 100644 drivers/staging/vboxvideo/Makefile
 create mode 100644 drivers/staging/vboxvideo/TODO
 create mode 100644 drivers/staging/vboxvideo/hgsmi_base.c
 create mode 100644 drivers/staging/vboxvideo/hgsmi_ch_setup.h
 create mode 100644 drivers/staging/vboxvideo/hgsmi_channels.h
 create mode 100644 drivers/staging/vboxvideo/hgsmi_defs.h
 create mode 100644 drivers/staging/vboxvideo/modesetting.c
 create mode 100644 drivers/staging/vboxvideo/vbox_drv.c
 create mode 100644 drivers/staging/vboxvideo/vbox_drv.h
 create mode 100644 drivers/staging/vboxvideo/vbox_err.h
 create mode 100644 drivers/staging/vboxvideo/vbox_fb.c
 create mode 100644 drivers/staging/vboxvideo/vbox_hgsmi.c
 create mode 100644 drivers/staging/vboxvideo/vbox_irq.c
 create mode 100644 drivers/staging/vboxvideo/vbox_main.c
 create mode 100644 drivers/staging/vboxvideo/vbox_mode.c
 create mode 100644 drivers/staging/vboxvideo/vbox_prime.c
 create mode 100644 drivers/staging/vboxvideo/vbox_ttm.c
 create mode 100644 drivers/staging/vboxvideo/vboxvideo.h
 create mode 100644 drivers/staging/vboxvideo/vboxvideo_guest.h
 create mode 100644 drivers/staging/vboxvideo/vboxvideo_vbe.h
 create mode 100644 drivers/staging/vboxvideo/vbva_base.c
drivers/staging/Kconfig +2 -0
index 268d4e6ef48a..ef28a1cb64ae 100644
@@ -110,4 +110,6 @@ source "drivers/staging/ccree/Kconfig"
 
 source "drivers/staging/typec/Kconfig"
 
+source "drivers/staging/vboxvideo/Kconfig"
+
 endif # STAGING
drivers/staging/Makefile +1 -0
index b93e6f5f0f6e..2918580bdb9e 100644
@@ -44,3 +44,4 @@ obj-$(CONFIG_KS7010)		+= ks7010/
 obj-$(CONFIG_GREYBUS)		+= greybus/
 obj-$(CONFIG_BCM2835_VCHIQ)	+= vc04_services/
 obj-$(CONFIG_CRYPTO_DEV_CCREE)	+= ccree/
+obj-$(CONFIG_DRM_VBOXVIDEO)	+= vboxvideo/
drivers/staging/vboxvideo/Kconfig new file +12 -0
new file mode 100644
index 000000000000..a52746f9a670
@@ -0,0 +1,12 @@
+config DRM_VBOXVIDEO
+	tristate "Virtual Box Graphics Card"
+	depends on DRM && X86 && PCI
+	select DRM_KMS_HELPER
+	help
+	  This is a KMS driver for the virtual Graphics Card used in
+	  Virtual Box virtual machines.
+
+	  Although it is possible to builtin this module, it is advised
+	  to build this driver as a module, so that it can be updated
+	  independently of the kernel. Select M to built this driver as a
+	  module and add support for these devices via drm/kms interfaces.
drivers/staging/vboxvideo/Makefile new file +7 -0
new file mode 100644
index 000000000000..2d0b3bc7ad73
@@ -0,0 +1,7 @@
+ccflags-y := -Iinclude/drm
+
+vboxvideo-y :=  hgsmi_base.o modesetting.o vbva_base.o \
+		vbox_drv.o vbox_fb.o vbox_hgsmi.o vbox_irq.o vbox_main.o \
+		vbox_mode.o vbox_prime.o vbox_ttm.o
+
+obj-$(CONFIG_DRM_VBOXVIDEO) += vboxvideo.o
drivers/staging/vboxvideo/TODO new file +9 -0
new file mode 100644
index 000000000000..ce764309b079
@@ -0,0 +1,9 @@
+TODO:
+-Move the driver over to the atomic API
+-Stop using old load / unload drm_driver hooks
+-Get a full review from the drm-maintainers on dri-devel done on this driver
+-Extend this TODO with the results of that review
+
+Please send any patches to Greg Kroah-Hartman <[email protected]>,
+Hans de Goede <[email protected]> and
+Michael Thayer <[email protected]>.
drivers/staging/vboxvideo/hgsmi_base.c new file +246 -0

246 lines not on this page · raw message

drivers/staging/vboxvideo/hgsmi_ch_setup.h new file +66 -0

66 lines not on this page · raw message

drivers/staging/vboxvideo/hgsmi_channels.h new file +53 -0

53 lines not on this page · raw message

drivers/staging/vboxvideo/hgsmi_defs.h new file +92 -0

92 lines not on this page · raw message

drivers/staging/vboxvideo/modesetting.c new file +142 -0

142 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_drv.c new file +287 -0

287 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_drv.h new file +297 -0

297 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_err.h new file +50 -0

50 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_fb.c new file +426 -0

426 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_hgsmi.c new file +115 -0

115 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_irq.c new file +197 -0

197 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_main.c new file +534 -0

534 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_mode.c new file +877 -0

457 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_prime.c new file +74 -0

74 lines not on this page · raw message

drivers/staging/vboxvideo/vbox_ttm.c new file +472 -0

472 lines not on this page · raw message

drivers/staging/vboxvideo/vboxvideo.h new file +491 -0

491 lines not on this page · raw message

drivers/staging/vboxvideo/vboxvideo_guest.h new file +95 -0

95 lines not on this page · raw message

drivers/staging/vboxvideo/vboxvideo_vbe.h new file +84 -0

84 lines not on this page · raw message

drivers/staging/vboxvideo/vbva_base.c new file +233 -0

233 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
2.13.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Part of the diff is not shown here. View the raw message.

#1 lore raw
url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/staging-vboxvideo-Add-vboxvideo-to-drivers-staging/20170627-035353 config: x86_64-randconfig-n0-06270721 (attached as .config) compiler…

Hi Hans,

[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.12-rc7 next-20170626]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/staging-vboxvideo-Add-vboxvideo-to-drivers-staging/20170627-035353
config: x86_64-randconfig-n0-06270721 (attached as .config)
compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

>> ERROR: "framebuffer_release" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
>> ERROR: "fb_set_suspend" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
>> ERROR: "fb_dealloc_cmap" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
>> ERROR: "unregister_framebuffer" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#2 lore raw

Hi Michael,

Quoted 6 lines · kbuild test robot

Hi Hans,

[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.12-rc7 next-20170626]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

Quoted 13 lines

url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/staging-vboxvideo-Add-vboxvideo-to-drivers-staging/20170627-035353
config: x86_64-randconfig-n0-06270721 (attached as .config)
compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce:

         # save the attached .config to linux build tree
         make ARCH=x86_64

All errors (new ones prefixed by >>):

Quoted 4 lines
Quoted 4 lines

ERROR: "framebuffer_release" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
ERROR: "fb_set_suspend" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
ERROR: "fb_dealloc_cmap" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
ERROR: "unregister_framebuffer" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!

Hmm, this is likely caused by building with a Kconfig with FBDEV disabled.

The attached patch should fix this. I will send out a v5 with this squashed in later today.

Regards,

Hans

Quoted 1 line

From 6bdabcb9945fcd7bfe8424c60f506a147348e6be Mon Sep 17 00:00:00 2001

From: Hans de Goede <[email protected]>
Date: Wed, 28 Jun 2017 14:40:58 +0200
Subject: [PATCH] staging/vboxvideo: Use various drm_fb_helper funcs instead of
DIY code

Besides being a nice cleanup, this fixes vobxvideo not building when fbdev support is disabled in the Kconfig.

---
 drivers/staging/vboxvideo/vbox_drv.c | 13 ++++++-------
 drivers/staging/vboxvideo/vbox_drv.h |  1 -
 drivers/staging/vboxvideo/vbox_fb.c  | 16 +---------------
 3 files changed, 7 insertions(+), 23 deletions(-)
drivers/staging/vboxvideo/vbox_drv.c +6 -7
index 05c973db77a4..92ae1560a16d 100644
@@ -63,25 +63,24 @@ static void vbox_pci_remove(struct pci_dev *pdev)
 
 static int vbox_drm_freeze(struct drm_device *dev)
 {
+	struct vbox_private *vbox = dev->dev_private;
+
 	drm_kms_helper_poll_disable(dev);
 
 	pci_save_state(dev->pdev);
 
-	console_lock();
-	vbox_fbdev_set_suspend(dev, 1);
-	console_unlock();
+	drm_fb_helper_set_suspend_unlocked(&vbox->fbdev->helper, true);
 
 	return 0;
 }
 
 static int vbox_drm_thaw(struct drm_device *dev)
 {
+	struct vbox_private *vbox = dev->dev_private;
+
 	drm_mode_config_reset(dev);
 	drm_helper_resume_force_mode(dev);
-
-	console_lock();
-	vbox_fbdev_set_suspend(dev, 0);
-	console_unlock();
+	drm_fb_helper_set_suspend_unlocked(&vbox->fbdev->helper, false);
 
 	return 0;
 }
drivers/staging/vboxvideo/vbox_drv.h +0 -1
index 10da2232079b..4b9302703b36 100644
@@ -198,7 +198,6 @@ int vbox_framebuffer_init(struct drm_device *dev,
 
 int vbox_fbdev_init(struct drm_device *dev);
 void vbox_fbdev_fini(struct drm_device *dev);
-void vbox_fbdev_set_suspend(struct drm_device *dev, int state);
 void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr);
 
 struct vbox_bo {
drivers/staging/vboxvideo/vbox_fb.c +1 -15
index 3b2657d3b29c..35f6d9f8c203 100644
@@ -341,15 +341,8 @@ void vbox_fbdev_fini(struct drm_device *dev)
 	struct vbox_private *vbox = dev->dev_private;
 	struct vbox_fbdev *fbdev = vbox->fbdev;
 	struct vbox_framebuffer *afb = &fbdev->afb;
-	struct fb_info *info;
 
-	if (fbdev->helper.fbdev) {
-		info = fbdev->helper.fbdev;
-		unregister_framebuffer(info);
-		if (info->cmap.len)
-			fb_dealloc_cmap(&info->cmap);
-		framebuffer_release(info);
-	}
+	drm_fb_helper_unregister_fbi(&fbdev->helper);
 
 	if (afb->obj) {
 		struct vbox_bo *bo = gem_to_vbox_bo(afb->obj);
@@ -410,13 +403,6 @@ int vbox_fbdev_init(struct drm_device *dev)
 	return ret;
 }
 
-void vbox_fbdev_set_suspend(struct drm_device *dev, int state)
-{
-	struct vbox_private *vbox = dev->dev_private;
-
-	fb_set_suspend(vbox->fbdev->helper.fbdev, state);
-}
-
 void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr)
 {
 	struct fb_info *fbdev = vbox->fbdev->helper.fbdev;
Signature · 1 line
2.13.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 29 lines · Hans de Goede
Quoted 13 lines · kbuild test robot

Hi Hans,

[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.12-rc7 next-20170626]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:
https://github.com/0day-ci/linux/commits/Hans-de-Goede/staging-vboxvideo-Add-vboxvideo-to-drivers-staging/20170627-035353
config: x86_64-randconfig-n0-06270721 (attached as .config)
compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce:

Quoted 13 lines
         # save the attached .config to linux build tree
         make ARCH=x86_64

All errors (new ones prefixed by >>):

Quoted 8 lines
Quoted 8 lines

ERROR: "framebuffer_release" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
ERROR: "fb_set_suspend" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
ERROR: "fb_dealloc_cmap" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!
ERROR: "unregister_framebuffer" [drivers/staging/vboxvideo/vboxvideo.ko] undefined!

Quoted 5 lines

Hmm, this is likely caused by building with a Kconfig with FBDEV disabled.

The attached patch should fix this. I will send out a v5 with this squashed in later
today.

If you use the drm fbdev helper library (all of it) then this should all Just Work. Calling any fb core function from a drm driver directly is a bug most likely.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel