Skip to contentSkip to conversation

drm/vboxvideo: Use generic fbdev and framebuffer

PATCH In review Thomas Zimmermann 3 participants 10 messages Oct 11, 2019 – Oct 28, 2019

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/vboxvideo: Use generic fbdev and framebuffer

The vboxvideo driver provides its own implementation for fbdev emulation and framebuffers. Both can be replaced by DRM's generic code.

All patches have been tested on VirtualBox 6.0.12.

Thomas Zimmermann (3):
drm/vboxvideo: Switch to generic fbdev emulation drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb() drm/vboxvideo: Replace struct vram_framebuffer with generic
implemenation

 drivers/gpu/drm/vboxvideo/Makefile    |   2 +-
 drivers/gpu/drm/vboxvideo/vbox_drv.c  |  14 +--
 drivers/gpu/drm/vboxvideo/vbox_drv.h  |  25 -----
 drivers/gpu/drm/vboxvideo/vbox_fb.c   | 149 --------------------------
 drivers/gpu/drm/vboxvideo/vbox_main.c | 119 +-------------------
 drivers/gpu/drm/vboxvideo/vbox_mode.c |  86 +++++++--------
 6 files changed, 49 insertions(+), 346 deletions(-)
 delete mode 100644 drivers/gpu/drm/vboxvideo/vbox_fb.c

--
2.23.0

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

author maintainer
#1 lore raw

PATCH 1/3 drm/vboxvideo: Switch to generic fbdev emulation

There's nothing special about vboxvideo's fbdev emulation that is not provided by the generic implementation. Switch over and remove the driver's code.

---
 drivers/gpu/drm/vboxvideo/Makefile    |   2 +-
 drivers/gpu/drm/vboxvideo/vbox_drv.c  |  14 +--
 drivers/gpu/drm/vboxvideo/vbox_drv.h  |   7 --
 drivers/gpu/drm/vboxvideo/vbox_fb.c   | 149 --------------------------
 drivers/gpu/drm/vboxvideo/vbox_mode.c |   3 +-
 5 files changed, 6 insertions(+), 169 deletions(-)
 delete mode 100644 drivers/gpu/drm/vboxvideo/vbox_fb.c
drivers/gpu/drm/vboxvideo/Makefile +1 -1
index 55d798c76b21..f2e968b5ffa6 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 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_drv.o vbox_hgsmi.o vbox_irq.o vbox_main.o \
 		vbox_mode.o vbox_ttm.o
 
 obj-$(CONFIG_DRM_VBOXVIDEO) += vboxvideo.o
drivers/gpu/drm/vboxvideo/vbox_drv.c +3 -11
index 862db495d111..6ee308b453da 100644
@@ -14,6 +14,7 @@
 
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_fb_helper.h>
 #include <drm/drm_file.h>
 #include <drm/drm_ioctl.h>
 
@@ -32,10 +33,6 @@ static const struct pci_device_id pciidlist[] = {
 };
 MODULE_DEVICE_TABLE(pci, pciidlist);
 
-static const struct drm_fb_helper_funcs vbox_fb_helper_funcs = {
-	.fb_probe = vboxfb_create,
-};
-
 static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct vbox_private *vbox;
@@ -79,20 +76,16 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (ret)
 		goto err_mode_fini;
 
-	ret = drm_fb_helper_fbdev_setup(&vbox->ddev, &vbox->fb_helper,
-					&vbox_fb_helper_funcs, 32,
-					vbox->num_crtcs);
+	ret = drm_fbdev_generic_setup(&vbox->ddev, 32);
 	if (ret)
 		goto err_irq_fini;
 
 	ret = drm_dev_register(&vbox->ddev, 0);
 	if (ret)
-		goto err_fbdev_fini;
+		goto err_irq_fini;
 
 	return 0;
 
-err_fbdev_fini:
-	vbox_fbdev_fini(vbox);
 err_irq_fini:
 	vbox_irq_fini(vbox);
 err_mode_fini:
@@ -113,7 +106,6 @@ static void vbox_pci_remove(struct pci_dev *pdev)
 	struct vbox_private *vbox = pci_get_drvdata(pdev);
 
 	drm_dev_unregister(&vbox->ddev);
-	vbox_fbdev_fini(vbox);
 	vbox_irq_fini(vbox);
 	vbox_mode_fini(vbox);
 	vbox_mm_fini(vbox);
drivers/gpu/drm/vboxvideo/vbox_drv.h +0 -7
index fb436ec760ea..bb0c39fe7911 100644
@@ -16,7 +16,6 @@
 #include <linux/string.h>
 
 #include <drm/drm_encoder.h>
-#include <drm/drm_fb_helper.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_gem_vram_helper.h>
 
@@ -54,8 +53,6 @@ struct vbox_framebuffer {
 struct vbox_private {
 	/* Must be first; or we must define our own release callback */
 	struct drm_device ddev;
-	struct drm_fb_helper fb_helper;
-	struct vbox_framebuffer afb;
 
 	u8 __iomem *guest_heap;
 	u8 __iomem *vbva_buffers;
@@ -155,10 +152,6 @@ int vbox_framebuffer_init(struct vbox_private *vbox,
 			  const struct drm_mode_fb_cmd2 *mode_cmd,
 			  struct drm_gem_object *obj);
 
-int vboxfb_create(struct drm_fb_helper *helper,
-		  struct drm_fb_helper_surface_size *sizes);
-void vbox_fbdev_fini(struct vbox_private *vbox);
-
 int vbox_mm_init(struct vbox_private *vbox);
 void vbox_mm_fini(struct vbox_private *vbox);
 
drivers/gpu/drm/vboxvideo/vbox_fb.c deleted +0 -149

149 lines not on this page · raw message

drivers/gpu/drm/vboxvideo/vbox_mode.c +2 -1
index e1e48ba919eb..dd9ad3fdd919 100644
@@ -13,6 +13,7 @@
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
+#include <drm/drm_fb_helper.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_plane_helper.h>
 #include <drm/drm_probe_helper.h>
@@ -133,7 +134,7 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox)
 
 		if (!fb1) {
 			fb1 = fb;
-			if (to_vbox_framebuffer(fb1) == &vbox->afb)
+			if (fb1 == vbox->ddev.fb_helper->fb)
 				break;
 		} else if (fb != fb1) {
 			single_framebuffer = false;
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#2 lore raw

PATCH 2/3 drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb()

In reply to Thomas Zimmermann

The vboxvideo driver provides struct drm_framebuffer_funcs.dirty_fb from its own implementation. Switch over to drm_atomic_helper_dirty_fb() and handle screen updates in the primary plane's atomic_update function.

With dirty_fb out of the way, we can further replace struct vbox_frammebuffer with generic code.

---
 drivers/gpu/drm/vboxvideo/vbox_drv.h  |  4 --
 drivers/gpu/drm/vboxvideo/vbox_main.c | 61 +--------------------------
 drivers/gpu/drm/vboxvideo/vbox_mode.c | 34 +++++++++++++++
 3 files changed, 36 insertions(+), 63 deletions(-)
drivers/gpu/drm/vboxvideo/vbox_drv.h +0 -4
index bb0c39fe7911..9976554b58cb 100644
@@ -143,10 +143,6 @@ void vbox_mode_fini(struct vbox_private *vbox);
 
 void vbox_report_caps(struct vbox_private *vbox);
 
-void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
-				       struct drm_clip_rect *rects,
-				       unsigned int num_rects);
-
 int vbox_framebuffer_init(struct vbox_private *vbox,
 			  struct vbox_framebuffer *vbox_fb,
 			  const struct drm_mode_fb_cmd2 *mode_cmd,
drivers/gpu/drm/vboxvideo/vbox_main.c +2 -59

75 lines not on this page · raw message

drivers/gpu/drm/vboxvideo/vbox_mode.c +34 -0
index dd9ad3fdd919..70754e9a087e 100644
@@ -284,10 +284,44 @@ static void vbox_primary_atomic_update(struct drm_plane *plane,
 {
 	struct drm_crtc *crtc = plane->state->crtc;
 	struct drm_framebuffer *fb = plane->state->fb;
+	struct vbox_private *vbox = fb->dev->dev_private;
+	struct drm_mode_rect *clips;
+	uint32_t num_clips, i;
 
 	vbox_crtc_set_base_and_mode(crtc, fb,
 				    plane->state->src_x >> 16,
 				    plane->state->src_y >> 16);
+
+	/* Send information about dirty rectangles to VBVA. */
+
+	clips = drm_plane_get_damage_clips(plane->state);
+	num_clips = drm_plane_get_damage_clips_count(plane->state);
+
+	if (!num_clips)
+		return;
+
+	mutex_lock(&vbox->hw_mutex);
+
+	for (i = 0; i < num_clips; ++i, ++clips) {
+
+		struct vbva_cmd_hdr cmd_hdr;
+		unsigned int crtc_id = to_vbox_crtc(crtc)->crtc_id;
+
+		cmd_hdr.x = (s16)clips->x1;
+		cmd_hdr.y = (s16)clips->y1;
+		cmd_hdr.w = (u16)clips->x2 - clips->x1;
+		cmd_hdr.h = (u16)clips->y2 - clips->y1;
+
+		if (!vbva_buffer_begin_update(&vbox->vbva_info[crtc_id],
+					      vbox->guest_pool))
+			continue;
+
+		vbva_write(&vbox->vbva_info[crtc_id], vbox->guest_pool,
+			   &cmd_hdr, sizeof(cmd_hdr));
+		vbva_buffer_end_update(&vbox->vbva_info[crtc_id]);
+	}
+
+	mutex_unlock(&vbox->hw_mutex);
 }
 
 static void vbox_primary_atomic_disable(struct drm_plane *plane,
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#3 lore raw

PATCH 3/3 drm/vboxvideo: Replace struct vram_framebuffer with generic implemenation

In reply to Thomas Zimmermann

The vboxvideo driver's struct vram_framebuffer stores a DRM framebuffer with an assiciated GEM object. This functionality is also provided by generic code. Switch vboxvideo over.

---
 drivers/gpu/drm/vboxvideo/vbox_drv.h  | 14 -------
 drivers/gpu/drm/vboxvideo/vbox_main.c | 60 ---------------------------
 drivers/gpu/drm/vboxvideo/vbox_mode.c | 49 ++++------------------
 3 files changed, 8 insertions(+), 115 deletions(-)
drivers/gpu/drm/vboxvideo/vbox_drv.h +0 -14
index 9976554b58cb..87421903816c 100644
@@ -45,11 +45,6 @@
 				sizeof(struct hgsmi_host_flags))
 #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
 
-struct vbox_framebuffer {
-	struct drm_framebuffer base;
-	struct drm_gem_object *obj;
-};
-
 struct vbox_private {
 	/* Must be first; or we must define our own release callback */
 	struct drm_device ddev;
@@ -132,7 +127,6 @@ struct vbox_encoder {
 #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
 #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
 #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
-#define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
 
 bool vbox_check_supported(u16 id);
 int vbox_hw_init(struct vbox_private *vbox);
@@ -143,17 +137,9 @@ void vbox_mode_fini(struct vbox_private *vbox);
 
 void vbox_report_caps(struct vbox_private *vbox);
 
-int vbox_framebuffer_init(struct vbox_private *vbox,
-			  struct vbox_framebuffer *vbox_fb,
-			  const struct drm_mode_fb_cmd2 *mode_cmd,
-			  struct drm_gem_object *obj);
-
 int vbox_mm_init(struct vbox_private *vbox);
 void vbox_mm_fini(struct vbox_private *vbox);
 
-int vbox_gem_create(struct vbox_private *vbox,
-		    u32 size, bool iskernel, struct drm_gem_object **obj);
-
 /* vbox_irq.c */
 int vbox_irq_init(struct vbox_private *vbox);
 void vbox_irq_fini(struct vbox_private *vbox);
drivers/gpu/drm/vboxvideo/vbox_main.c +0 -60

75 lines not on this page · raw message

drivers/gpu/drm/vboxvideo/vbox_mode.c +8 -41

98 lines not on this page · raw message

Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Acked-by on the v1 series
#4 lore raw
In reply to Thomas Zimmermann

Hi Thomas.

Quoted 11 lines · Thomas Zimmermann

The vboxvideo driver provides its own implementation for fbdev emulation and framebuffers. Both can be replaced by DRM's generic code.

All patches have been tested on VirtualBox 6.0.12.

Thomas Zimmermann (3):
drm/vboxvideo: Switch to generic fbdev emulation drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb() drm/vboxvideo: Replace struct vram_framebuffer with generic
implemenation

Quoted 8 lines
 drivers/gpu/drm/vboxvideo/Makefile    |   2 +-
 drivers/gpu/drm/vboxvideo/vbox_drv.c  |  14 +--
 drivers/gpu/drm/vboxvideo/vbox_drv.h  |  25 -----
 drivers/gpu/drm/vboxvideo/vbox_fb.c   | 149 --------------------------
 drivers/gpu/drm/vboxvideo/vbox_main.c | 119 +-------------------
 drivers/gpu/drm/vboxvideo/vbox_mode.c |  86 +++++++--------
 6 files changed, 49 insertions(+), 346 deletions(-)
 delete mode 100644 drivers/gpu/drm/vboxvideo/vbox_fb.c

Nice work. Browsed through the changes and enjoyed all the deleted code.

You can add my:

to the whole series.

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

author maintainer
#5 lore raw

Hi

Am 12.10.19 um 14:36 schrieb Sam Ravnborg:

Quoted 22 lines

Hi Thomas.

Quoted 11 lines · Thomas Zimmermann

The vboxvideo driver provides its own implementation for fbdev emulation and framebuffers. Both can be replaced by DRM's generic code.

All patches have been tested on VirtualBox 6.0.12.

Thomas Zimmermann (3):
drm/vboxvideo: Switch to generic fbdev emulation drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb() drm/vboxvideo: Replace struct vram_framebuffer with generic
implemenation

Quoted 8 lines
  drivers/gpu/drm/vboxvideo/Makefile    |   2 +-
  drivers/gpu/drm/vboxvideo/vbox_drv.c  |  14 +--
  drivers/gpu/drm/vboxvideo/vbox_drv.h  |  25 -----
  drivers/gpu/drm/vboxvideo/vbox_fb.c   | 149 --------------------------
  drivers/gpu/drm/vboxvideo/vbox_main.c | 119 +-------------------
  drivers/gpu/drm/vboxvideo/vbox_mode.c |  86 +++++++--------
  6 files changed, 49 insertions(+), 346 deletions(-)

delete mode 100644 drivers/gpu/drm/vboxvideo/vbox_fb.c

Quoted 7 lines

Nice work. Browsed through the changes and enjoyed all the deleted code.

You can add my:

to the whole series.

Thanks!

Quoted 7 lines

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

Signature · 9 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
In reply to Thomas Zimmermann

Hi Thomas,

Quoted 10 lines · Thomas Zimmermann

The vboxvideo driver provides its own implementation for fbdev emulation and framebuffers. Both can be replaced by DRM's generic code.

All patches have been tested on VirtualBox 6.0.12.

Thomas Zimmermann (3):
drm/vboxvideo: Switch to generic fbdev emulation drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb() drm/vboxvideo: Replace struct vram_framebuffer with generic
implemenation

Thank you for these nice cleanups, unfortunately there is a small bug in the last patch, you are setting:

.fb_create = drm_gem_fb_create,

But since in the previous patch you switched to drm_atomic_helper_dirty_fb that should be:

.fb_create = drm_gem_fb_create_with_dirty,

The missing with_dirty is causing screenupdates under both plymouth and gnome-shell (with llvmpipe) to gone missing. I'll send a patch fixing this.

Regards,

Hans

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

author maintainer
#7 lore raw

Hi

Am 28.10.19 um 12:26 schrieb Hans de Goede:

Quoted 19 lines

Hi Thomas,

Quoted 10 lines · Thomas Zimmermann

The vboxvideo driver provides its own implementation for fbdev emulation and framebuffers. Both can be replaced by DRM's generic code.

All patches have been tested on VirtualBox 6.0.12.

Thomas Zimmermann (3):
   drm/vboxvideo: Switch to generic fbdev emulation drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb() drm/vboxvideo: Replace struct vram_framebuffer with generic implemenation

Thank you for these nice cleanups, unfortunately there is a small bug in the last patch, you are setting:

    .fb_create = drm_gem_fb_create,

Quoted 8 lines

But since in the previous patch you switched to drm_atomic_helper_dirty_fb that should be:

    .fb_create = drm_gem_fb_create_with_dirty,

The missing with_dirty is causing screenupdates under both plymouth and gnome-shell (with llvmpipe) to gone missing. I'll send a patch fixing this.

You're right. I did test the patchset, but I can't tell why I didn't see this bug. Anyway, thanks a lot for providing the fix.

Best regards
Thomas

Quoted 9 lines

Regards,

Hans

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

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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

#8 lore raw

Hi,

Quoted 25 lines · Thomas Zimmermann

Hi

Am 28.10.19 um 12:26 schrieb Hans de Goede:

Quoted 22 lines

Hi Thomas,

Quoted 10 lines · Thomas Zimmermann

The vboxvideo driver provides its own implementation for fbdev emulation and framebuffers. Both can be replaced by DRM's generic code.

All patches have been tested on VirtualBox 6.0.12.

Thomas Zimmermann (3):
   drm/vboxvideo: Switch to generic fbdev emulation drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb() drm/vboxvideo: Replace struct vram_framebuffer with generic implemenation

Thank you for these nice cleanups, unfortunately there is a small bug in the last patch, you are setting:

    .fb_create = drm_gem_fb_create,

But since in the previous patch you switched to drm_atomic_helper_dirty_fb that should be:

Quoted 8 lines
Quoted 5 lines

    .fb_create = drm_gem_fb_create_with_dirty,

The missing with_dirty is causing screenupdates under both plymouth and gnome-shell (with llvmpipe) to gone missing. I'll send a patch fixing this.

You're right. I did test the patchset, but I can't tell why I didn't see this bug.

I know you tested the patch-set, since you said so above :) You probably are aware of this already, but did you check what vga-card the vm is using? New vbox VMs default to their new vmware-svga card emulation, in which case vboxvideo is not used at all, vboxvideo is only used with the older VboxVGA and VboxSVGA (*) virtual vga-cards.

Quoted 1 line

Anyway, thanks a lot for providing the fix.

You are welcome.

Regards,

Hans

*) Of course once I finally get their driver upstream they deprecate it, grumble.

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

author maintainer
#9 lore raw

Hi

Am 28.10.19 um 13:06 schrieb Hans de Goede:

Quoted 36 lines

Hi,

Quoted 33 lines · Thomas Zimmermann

Hi

Am 28.10.19 um 12:26 schrieb Hans de Goede:

Quoted 29 lines

Hi Thomas,

Quoted 11 lines · Thomas Zimmermann

The vboxvideo driver provides its own implementation for fbdev emulation
and framebuffers. Both can be replaced by DRM's generic code.

All patches have been tested on VirtualBox 6.0.12.

Thomas Zimmermann (3):
    drm/vboxvideo: Switch to generic fbdev emulation drm/vboxvideo: Switch to drm_atomic_helper_dirty_fb() drm/vboxvideo: Replace struct vram_framebuffer with generic implemenation

Thank you for these nice cleanups, unfortunately there is a small bug in the last patch, you are setting:

     .fb_create = drm_gem_fb_create,

But since in the previous patch you switched to
drm_atomic_helper_dirty_fb
that should be:

     .fb_create = drm_gem_fb_create_with_dirty,

The missing with_dirty is causing screenupdates under both plymouth and gnome-shell (with llvmpipe) to gone missing. I'll send a patch fixing this.

Quoted 8 lines
Quoted 2 lines

You're right. I did test the patchset, but I can't tell why I didn't see this bug.

I know you tested the patch-set, since you said so above :)  You probably are aware of this already, but did you check what vga-card the vm is using? New vbox VMs default to their new vmware-svga card emulation, in which case vboxvideo is not used at all, vboxvideo is only used with the older VboxVGA and VboxSVGA (*) virtual vga-cards.

That sounds plausible at least. I'll double-check next time.

Best regards
Thomas

Quoted 14 lines
Quoted 2 lines

Anyway, thanks a lot for providing the fix.

You are welcome.

Regards,

Hans

*) Of course once I finally get their driver upstream they deprecate it, grumble.

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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