Skip to contentSkip to conversation

drm/cirrus: rewrite and modernize driver.

PATCH Superseded Gerd Hoffmann 3 participants 17 messages Apr 4, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/cirrus: rewrite and modernize driver.

v2:
- It's a little series now. It moves tinydrm converters to drm_fb_helpers.c first.
- Added support for RG24 and XR24. Without bpp module parameter, instead the driver will convert formats if needed.
- A bunch of little tweaks here and there (embedded struct drm_driver, use more drm helpers, ...)

Gerd Hoffmann (6):
drm: move tinydrm_memcpy() to drm_fb_helper.c
drm: add dstclip parameter to drm_fb_memcpy()
drm: move tinydrm_xrgb8888_to_rgb565() to drm_fb_helper.c
drm: add dstclip parameter to drm_fb_xrgb8888_to_rgb565()
drm: add drm_fb_xrgb8888_to_rgb888() function to drm_fb_helper.c drm/cirrus: rewrite and modernize driver.

 drivers/gpu/drm/cirrus/cirrus_drv.h           | 251 -------
 include/drm/drm_fb_helper.h                   |  11 +
 include/drm/tinydrm/tinydrm-helpers.h         |   5 -
 drivers/gpu/drm/cirrus/cirrus.c               | 621 ++++++++++++++++++
 drivers/gpu/drm/cirrus/cirrus_drv.c           | 161 -----
 drivers/gpu/drm/cirrus/cirrus_fbdev.c         | 309 ---------
 drivers/gpu/drm/cirrus/cirrus_main.c          | 328 ---------
 drivers/gpu/drm/cirrus/cirrus_mode.c          | 617 -----------------
 drivers/gpu/drm/cirrus/cirrus_ttm.c           | 343 ----------
 drivers/gpu/drm/drm_fb_helper.c               | 127 ++++
 .../gpu/drm/tinydrm/core/tinydrm-helpers.c    |  69 --
 drivers/gpu/drm/tinydrm/mipi-dbi.c            |   5 +-
 drivers/gpu/drm/cirrus/Kconfig                |   2 +-
 drivers/gpu/drm/cirrus/Makefile               |   3 -
 14 files changed, 763 insertions(+), 2089 deletions(-)
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.h
 create mode 100644 drivers/gpu/drm/cirrus/cirrus.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_fbdev.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_main.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_mode.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_ttm.c
Signature · 6 lines
2.18.1

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

PATCH v2 1/6 drm: move tinydrm_memcpy() to drm_fb_helper.c

Also rename to drm_fb_memcpy().
Pure code motion, no functional change.

---
 include/drm/drm_fb_helper.h                   |  3 +++
 include/drm/tinydrm/tinydrm-helpers.h         |  2 --
 drivers/gpu/drm/drm_fb_helper.c               | 25 +++++++++++++++++++
 .../gpu/drm/tinydrm/core/tinydrm-helpers.c    | 24 ------------------
 drivers/gpu/drm/tinydrm/mipi-dbi.c            |  3 ++-
 5 files changed, 30 insertions(+), 27 deletions(-)
include/drm/drm_fb_helper.h +3 -0
index 81ae48a0df48..696017b38add 100644
@@ -642,4 +642,7 @@ drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 #endif
 }
 
+void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
+		   struct drm_rect *clip);
+
 #endif
include/drm/tinydrm/tinydrm-helpers.h +0 -2
index ae4a6abc43b5..591ca83330c4 100644
@@ -46,8 +46,6 @@ int tinydrm_display_pipe_init(struct drm_device *drm,
 			      const struct drm_display_mode *mode,
 			      unsigned int rotation);
 
-void tinydrm_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-		    struct drm_rect *clip);
 void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
 		    struct drm_rect *clip);
 void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
drivers/gpu/drm/drm_fb_helper.c +25 -0
index 03749a24e4dd..22d29834bbe9 100644
@@ -3353,3 +3353,28 @@ int __init drm_fb_helper_modinit(void)
 	return 0;
 }
 EXPORT_SYMBOL(drm_fb_helper_modinit);
+
+/**
+ * drm_fb_memcpy - Copy clip buffer
+ * @dst: Destination buffer
+ * @vaddr: Source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ * @dstclip: Clip destination too.
+ */
+void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
+		   struct drm_rect *clip)
+{
+	unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
+	unsigned int pitch = fb->pitches[0];
+	void *src = vaddr + (clip->y1 * pitch) + (clip->x1 * cpp);
+	size_t len = (clip->x2 - clip->x1) * cpp;
+	unsigned int y;
+
+	for (y = clip->y1; y < clip->y2; y++) {
+		memcpy(dst, src, len);
+		src += pitch;
+		dst += len;
+	}
+}
+EXPORT_SYMBOL(drm_fb_memcpy);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -24
index d7b38dfb6438..f5c6f35e6161 100644
@@ -26,30 +26,6 @@ static unsigned int spi_max;
 module_param(spi_max, uint, 0400);
 MODULE_PARM_DESC(spi_max, "Set a lower SPI max transfer size");
 
-/**
- * tinydrm_memcpy - Copy clip buffer
- * @dst: Destination buffer
- * @vaddr: Source buffer
- * @fb: DRM framebuffer
- * @clip: Clip rectangle area to copy
- */
-void tinydrm_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-		    struct drm_rect *clip)
-{
-	unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
-	unsigned int pitch = fb->pitches[0];
-	void *src = vaddr + (clip->y1 * pitch) + (clip->x1 * cpp);
-	size_t len = (clip->x2 - clip->x1) * cpp;
-	unsigned int y;
-
-	for (y = clip->y1; y < clip->y2; y++) {
-		memcpy(dst, src, len);
-		src += pitch;
-		dst += len;
-	}
-}
-EXPORT_SYMBOL(tinydrm_memcpy);
-
 /**
  * tinydrm_swab16 - Swap bytes into clip buffer
  * @dst: RGB565 destination buffer
drivers/gpu/drm/tinydrm/mipi-dbi.c +2 -1
index 869c8f56da3b..fb7e4582e293 100644
@@ -19,6 +19,7 @@
 
 #include <drm/drm_damage_helper.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_fb_helper.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem_cma_helper.h>
 #include <drm/drm_fourcc.h>
@@ -220,7 +221,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
 		if (swap)
 			tinydrm_swab16(dst, src, fb, clip);
 		else
-			tinydrm_memcpy(dst, src, fb, clip);
+			drm_fb_memcpy(dst, src, fb, clip);
 		break;
 	case DRM_FORMAT_XRGB8888:
 		tinydrm_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
Signature · 6 lines
2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 1/6
#2 lore raw

Re: [PATCH v2 1/6] drm: move tinydrm_memcpy() to drm_fb_helper.c

Hi Gerd.

Quoted 46 lines · Gerd Hoffmann

Also rename to drm_fb_memcpy().
Pure code motion, no functional change.

---
 include/drm/drm_fb_helper.h                   |  3 +++
 include/drm/tinydrm/tinydrm-helpers.h         |  2 --
 drivers/gpu/drm/drm_fb_helper.c               | 25 +++++++++++++++++++
 .../gpu/drm/tinydrm/core/tinydrm-helpers.c    | 24 ------------------
 drivers/gpu/drm/tinydrm/mipi-dbi.c            |  3 ++-
 5 files changed, 30 insertions(+), 27 deletions(-)
include/drm/drm_fb_helper.h +3 -0
index 81ae48a0df48..696017b38add 100644
@@ -642,4 +642,7 @@ drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 #endif
 }
 
+void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
+		   struct drm_rect *clip);
+
 #endif
include/drm/tinydrm/tinydrm-helpers.h +0 -2
index ae4a6abc43b5..591ca83330c4 100644
@@ -46,8 +46,6 @@ int tinydrm_display_pipe_init(struct drm_device *drm,
 			      const struct drm_display_mode *mode,
 			      unsigned int rotation);
 
-void tinydrm_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-		    struct drm_rect *clip);
 void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
 		    struct drm_rect *clip);
 void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
drivers/gpu/drm/drm_fb_helper.c +1 -0
index 03749a24e4dd..22d29834bbe9 100644
@@ -3353,3 +3353,28 @@ int __init drm_fb_helper_modinit(void)
 	return 0;
 }
 EXPORT_SYMBOL(drm_fb_helper_modinit);
+

drivers/gpu/drm/drm_fb_helper.c int __init drm_fb_helper_modinit(void) · line 3366

Quoted 10 lines
drivers/gpu/drm/drm_fb_helper.c +10 -0
+/**
+ * drm_fb_memcpy - Copy clip buffer
+ * @dst: Destination buffer
+ * @vaddr: Source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ * @dstclip: Clip destination too.
+ */
+void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
+		   struct drm_rect *clip)

Function has no parameter named @dstclip.

With this fixed:

#3 lore raw

Re: [PATCH v2 1/6] drm: move tinydrm_memcpy() to drm_fb_helper.c

In reply to Gerd Hoffmann

Den 04.04.2019 17.24, skrev Gerd Hoffmann:

Quoted 8 lines

Also rename to drm_fb_memcpy().
Pure code motion, no functional change.

---
 include/drm/drm_fb_helper.h                   |  3 +++
 include/drm/tinydrm/tinydrm-helpers.h         |  2 --
 drivers/gpu/drm/drm_fb_helper.c               | 25 +++++++++++++++++++

drm_fb_helper.c is for fbdev code so not a good place for this code, and it's MIT licensed as well.
Daniel have in two rounds suggested a new drm_framebuffer_helper.c or drm_format_helper.c as possible destinations for these functions.

Noralf.

#4 lore raw

PATCH v2 2/6 drm: add dstclip parameter to drm_fb_memcpy()

In reply to Gerd Hoffmann

When set apply clipping logic to destination too.

---
 include/drm/drm_fb_helper.h        | 2 +-
 drivers/gpu/drm/drm_fb_helper.c    | 6 ++++--
 drivers/gpu/drm/tinydrm/mipi-dbi.c | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
include/drm/drm_fb_helper.h +1 -1
index 696017b38add..a57420f40643 100644
@@ -643,6 +643,6 @@ drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 }
 
 void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-		   struct drm_rect *clip);
+		   struct drm_rect *clip, bool dstclip);
 
 #endif
drivers/gpu/drm/drm_fb_helper.c +4 -2
index 22d29834bbe9..fabeb408dce6 100644
@@ -3363,7 +3363,7 @@ EXPORT_SYMBOL(drm_fb_helper_modinit);
  * @dstclip: Clip destination too.
  */
 void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-		   struct drm_rect *clip)
+		   struct drm_rect *clip, bool dstclip)
 {
 	unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
 	unsigned int pitch = fb->pitches[0];
@@ -3371,10 +3371,12 @@ void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
 	size_t len = (clip->x2 - clip->x1) * cpp;
 	unsigned int y;
 
+	if (dstclip)
+		dst += (clip->y1 * pitch) + (clip->x1 * cpp);
 	for (y = clip->y1; y < clip->y2; y++) {
 		memcpy(dst, src, len);
 		src += pitch;
-		dst += len;
+		dst += dstclip ? pitch : len;
 	}
 }
 EXPORT_SYMBOL(drm_fb_memcpy);
drivers/gpu/drm/tinydrm/mipi-dbi.c +1 -1
index fb7e4582e293..e26fd61360a3 100644
@@ -221,7 +221,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
 		if (swap)
 			tinydrm_swab16(dst, src, fb, clip);
 		else
-			drm_fb_memcpy(dst, src, fb, clip);
+			drm_fb_memcpy(dst, src, fb, clip, false);
 		break;
 	case DRM_FORMAT_XRGB8888:
 		tinydrm_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
Signature · 1 line
2.18.1
#5 lore raw

Re: [PATCH v2 2/6] drm: add dstclip parameter to drm_fb_memcpy()

Hi Gerd.

Good to see these small incremental patches, and I recognize the parameter from PATCH 1.

Quoted 26 lines · Gerd Hoffmann

When set apply clipping logic to destination too.

---
 include/drm/drm_fb_helper.h        | 2 +-
 drivers/gpu/drm/drm_fb_helper.c    | 6 ++++--
 drivers/gpu/drm/tinydrm/mipi-dbi.c | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
include/drm/drm_fb_helper.h +1 -1
index 696017b38add..a57420f40643 100644
@@ -643,6 +643,6 @@ drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 }
 
 void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-		   struct drm_rect *clip);
+		   struct drm_rect *clip, bool dstclip);
 
 #endif
drivers/gpu/drm/drm_fb_helper.c +0 -0
index 22d29834bbe9..fabeb408dce6 100644

drivers/gpu/drm/drm_fb_helper.c EXPORT_SYMBOL(drm_fb_helper_modinit); · line 3366

Quoted 5 lines
drivers/gpu/drm/drm_fb_helper.c +1 -1
@@ -3363,7 +3363,7 @@ EXPORT_SYMBOL(drm_fb_helper_modinit);
  * @dstclip: Clip destination too.
  */
 void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
-		   struct drm_rect *clip)
+		   struct drm_rect *clip, bool dstclip)

Not a huge fan of boolean parameters that decide what a simple helper function should do.
Would have preferred two small helpers despite the small code duplication:

	drm_fb_memcpy()
	drm_fb_dstclip_memcpy()

drivers/gpu/drm/drm_fb_helper.c void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb, · line 3375

Quoted 9 lines
drivers/gpu/drm/drm_fb_helper.c +2 -0
 {
 	unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
 	unsigned int pitch = fb->pitches[0];
@@ -3371,10 +3371,12 @@ void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
 	size_t len = (clip->x2 - clip->x1) * cpp;
 	unsigned int y;
 
+	if (dstclip)
+		dst += (clip->y1 * pitch) + (clip->x1 * cpp);

Add newline?

Quoted 28 lines
drivers/gpu/drm/drm_fb_helper.c +1 -1
 	for (y = clip->y1; y < clip->y2; y++) {
 		memcpy(dst, src, len);
 		src += pitch;
-		dst += len;
+		dst += dstclip ? pitch : len;
 	}
 }
 EXPORT_SYMBOL(drm_fb_memcpy);
drivers/gpu/drm/tinydrm/mipi-dbi.c +1 -1
index fb7e4582e293..e26fd61360a3 100644
@@ -221,7 +221,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
 		if (swap)
 			tinydrm_swab16(dst, src, fb, clip);
 		else
-			drm_fb_memcpy(dst, src, fb, clip);
+			drm_fb_memcpy(dst, src, fb, clip, false);
 		break;
 	case DRM_FORMAT_XRGB8888:
 		tinydrm_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
Signature · 6 lines
2.18.1

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

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

#6 lore raw

PATCH v2 3/6 drm: move tinydrm_xrgb8888_to_rgb565() to drm_fb_helper.c

In reply to Gerd Hoffmann

Also rename to drm_fb_xrgb8888_to_rgb565().
Pure code motion, no functional change.

---
 include/drm/drm_fb_helper.h                   |  3 ++
 include/drm/tinydrm/tinydrm-helpers.h         |  3 --
 drivers/gpu/drm/drm_fb_helper.c               | 45 +++++++++++++++++++
 .../gpu/drm/tinydrm/core/tinydrm-helpers.c    | 45 -------------------
 drivers/gpu/drm/tinydrm/mipi-dbi.c            |  2 +-
 5 files changed, 49 insertions(+), 49 deletions(-)
include/drm/drm_fb_helper.h +3 -0
index a57420f40643..0350c7e9d6ba 100644
@@ -644,5 +644,8 @@ drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 
 void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
 		   struct drm_rect *clip, bool dstclip);
+void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
+			       struct drm_framebuffer *fb,
+			       struct drm_rect *clip, bool swap);
 
 #endif
include/drm/tinydrm/tinydrm-helpers.h +0 -3
index 591ca83330c4..220677107e0c 100644
@@ -48,9 +48,6 @@ int tinydrm_display_pipe_init(struct drm_device *drm,
 
 void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
 		    struct drm_rect *clip);
-void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
-				struct drm_framebuffer *fb,
-				struct drm_rect *clip, bool swap);
 void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
 			       struct drm_rect *clip);
 
drivers/gpu/drm/drm_fb_helper.c +45 -0

48 lines not on this page · raw message

drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -45

51 lines not on this page · raw message

drivers/gpu/drm/tinydrm/mipi-dbi.c +1 -1
index e26fd61360a3..cf8df5fb7494 100644
@@ -224,7 +224,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
 			drm_fb_memcpy(dst, src, fb, clip, false);
 		break;
 	case DRM_FORMAT_XRGB8888:
-		tinydrm_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
+		drm_fb_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
 		break;
 	default:
 		dev_err_once(fb->dev->dev, "Format is not supported: %s\n",
Signature · 6 lines
2.18.1

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

Re: [PATCH v2 3/6] drm: move tinydrm_xrgb8888_to_rgb565() to drm_fb_helper.c

In reply to Gerd Hoffmann

Den 04.04.2019 17.24, skrev Gerd Hoffmann:

Quoted 27 lines

Also rename to drm_fb_xrgb8888_to_rgb565().
Pure code motion, no functional change.

---

drivers/gpu/drm/drm_fb_helper.c +12 -0
index fabeb408dce6..087e49741094 100644
@@ -3380,3 +3380,48 @@ void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
 	}
 }
 EXPORT_SYMBOL(drm_fb_memcpy);
+
+/**
+ * drm_fb_xrgb8888_to_rgb565 - Convert XRGB8888 to RGB565 clip buffer
+ * @dst: RGB565 destination buffer
+ * @vaddr: XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ * @swap: Swap bytes
+ *
+ * Drivers can use this function for RGB565 devices that don't natively
+ * support XRGB8888.
+ */

drivers/gpu/drm/drm_fb_helper.c void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb, · line 3404

Quoted 10 lines
drivers/gpu/drm/drm_fb_helper.c +10 -0
+void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
+			       struct drm_framebuffer *fb,
+			       struct drm_rect *clip, bool swap)
+{
+	size_t len = (clip->x2 - clip->x1) * sizeof(u32);
+	unsigned int x, y;
+	u32 *src, *buf;
+	u16 val16;
+
+	buf = kmalloc(len, GFP_KERNEL);

It's not obvious what purpose this buffer serves and there's no help from the surrounding functions either (tinydrm_swab16() has a comment).

I think we need a comment, something along these lines:

	/*
	 * Write-combined buffers have uncached reads.
	 * Speed up by fetching one line at a time.
	 */

Noralf.

Quoted 93 lines
drivers/gpu/drm/drm_fb_helper.c +23 -0
+	if (!buf)
+		return;
+
+	for (y = clip->y1; y < clip->y2; y++) {
+		src = vaddr + (y * fb->pitches[0]);
+		src += clip->x1;
+		memcpy(buf, src, len);
+		src = buf;
+		for (x = clip->x1; x < clip->x2; x++) {
+			val16 = ((*src & 0x00F80000) >> 8) |
+				((*src & 0x0000FC00) >> 5) |
+				((*src & 0x000000F8) >> 3);
+			src++;
+			if (swap)
+				*dst++ = swab16(val16);
+			else
+				*dst++ = val16;
+		}
+	}
+
+	kfree(buf);
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +0 -45
index f5c6f35e6161..f4b84b15da75 100644
@@ -61,51 +61,6 @@ void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
 }
 EXPORT_SYMBOL(tinydrm_swab16);
 
-/**
- * tinydrm_xrgb8888_to_rgb565 - Convert XRGB8888 to RGB565 clip buffer
- * @dst: RGB565 destination buffer
- * @vaddr: XRGB8888 source buffer
- * @fb: DRM framebuffer
- * @clip: Clip rectangle area to copy
- * @swap: Swap bytes
- *
- * Drivers can use this function for RGB565 devices that don't natively
- * support XRGB8888.
- */
-void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
-				struct drm_framebuffer *fb,
-				struct drm_rect *clip, bool swap)
-{
-	size_t len = (clip->x2 - clip->x1) * sizeof(u32);
-	unsigned int x, y;
-	u32 *src, *buf;
-	u16 val16;
-
-	buf = kmalloc(len, GFP_KERNEL);
-	if (!buf)
-		return;
-
-	for (y = clip->y1; y < clip->y2; y++) {
-		src = vaddr + (y * fb->pitches[0]);
-		src += clip->x1;
-		memcpy(buf, src, len);
-		src = buf;
-		for (x = clip->x1; x < clip->x2; x++) {
-			val16 = ((*src & 0x00F80000) >> 8) |
-				((*src & 0x0000FC00) >> 5) |
-				((*src & 0x000000F8) >> 3);
-			src++;
-			if (swap)
-				*dst++ = swab16(val16);
-			else
-				*dst++ = val16;
-		}
-	}
-
-	kfree(buf);
-}
-EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565);
-
 /**
  * tinydrm_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale
  * @dst: 8-bit grayscale destination buffer
drivers/gpu/drm/tinydrm/mipi-dbi.c +1 -1
index e26fd61360a3..cf8df5fb7494 100644
@@ -224,7 +224,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
 			drm_fb_memcpy(dst, src, fb, clip, false);
 		break;
 	case DRM_FORMAT_XRGB8888:
-		tinydrm_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
+		drm_fb_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
 		break;
 	default:
 		dev_err_once(fb->dev->dev, "Format is not supported: %s\n",
#9 lore raw

PATCH v2 4/6 drm: add dstclip parameter to drm_fb_xrgb8888_to_rgb565()

In reply to Gerd Hoffmann

When set apply clipping logic to destination too.

---
 include/drm/drm_fb_helper.h        | 3 ++-
 drivers/gpu/drm/drm_fb_helper.c    | 8 +++++++-
 drivers/gpu/drm/tinydrm/mipi-dbi.c | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
include/drm/drm_fb_helper.h +2 -1
index 0350c7e9d6ba..1406057e1a93 100644
@@ -646,6 +646,7 @@ void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
 		   struct drm_rect *clip, bool dstclip);
 void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			       struct drm_framebuffer *fb,
-			       struct drm_rect *clip, bool swap);
+			       struct drm_rect *clip,
+			       bool swap, bool dstclip);
 
 #endif
drivers/gpu/drm/drm_fb_helper.c +7 -1
index 087e49741094..2c9286702c3f 100644
@@ -3388,13 +3388,15 @@ EXPORT_SYMBOL(drm_fb_memcpy);
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
  * @swap: Swap bytes
+ * @dstclip: Clip destination too.
  *
  * Drivers can use this function for RGB565 devices that don't natively
  * support XRGB8888.
  */
 void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			       struct drm_framebuffer *fb,
-			       struct drm_rect *clip, bool swap)
+			       struct drm_rect *clip,
+			       bool swap, bool dstclip)
 {
 	size_t len = (clip->x2 - clip->x1) * sizeof(u32);
 	unsigned int x, y;
@@ -3405,6 +3407,8 @@ void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 	if (!buf)
 		return;
 
+	if (dstclip)
+		dst += clip->y1 * fb->width + clip->x1;
 	for (y = clip->y1; y < clip->y2; y++) {
 		src = vaddr + (y * fb->pitches[0]);
 		src += clip->x1;
@@ -3420,6 +3424,8 @@ void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			else
 				*dst++ = val16;
 		}
+		if (dstclip)
+			dst += fb->width - (clip->x2 - clip->x1);
 	}
 
 	kfree(buf);
drivers/gpu/drm/tinydrm/mipi-dbi.c +1 -1
index cf8df5fb7494..b2d74f8707db 100644
@@ -224,7 +224,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
 			drm_fb_memcpy(dst, src, fb, clip, false);
 		break;
 	case DRM_FORMAT_XRGB8888:
-		drm_fb_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
+		drm_fb_xrgb8888_to_rgb565(dst, src, fb, clip, swap, false);
 		break;
 	default:
 		dev_err_once(fb->dev->dev, "Format is not supported: %s\n",
Signature · 1 line
2.18.1
#10 lore raw

Re: [PATCH v2 4/6] drm: add dstclip parameter to drm_fb_xrgb8888_to_rgb565()

Quoted 53 lines · Gerd Hoffmann

When set apply clipping logic to destination too.

---
 include/drm/drm_fb_helper.h        | 3 ++-
 drivers/gpu/drm/drm_fb_helper.c    | 8 +++++++-
 drivers/gpu/drm/tinydrm/mipi-dbi.c | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
include/drm/drm_fb_helper.h +2 -1
index 0350c7e9d6ba..1406057e1a93 100644
@@ -646,6 +646,7 @@ void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
 		   struct drm_rect *clip, bool dstclip);
 void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			       struct drm_framebuffer *fb,
-			       struct drm_rect *clip, bool swap);
+			       struct drm_rect *clip,
+			       bool swap, bool dstclip);
 
 #endif
drivers/gpu/drm/drm_fb_helper.c +5 -1
index 087e49741094..2c9286702c3f 100644
@@ -3388,13 +3388,15 @@ EXPORT_SYMBOL(drm_fb_memcpy);
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
  * @swap: Swap bytes
+ * @dstclip: Clip destination too.
  *
  * Drivers can use this function for RGB565 devices that don't natively
  * support XRGB8888.
  */
 void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			       struct drm_framebuffer *fb,
-			       struct drm_rect *clip, bool swap)
+			       struct drm_rect *clip,
+			       bool swap, bool dstclip)
 {
 	size_t len = (clip->x2 - clip->x1) * sizeof(u32);
 	unsigned int x, y;
@@ -3405,6 +3407,8 @@ void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 	if (!buf)
 		return;
 
+	if (dstclip)
+		dst += clip->y1 * fb->width + clip->x1;
 	for (y = clip->y1; y < clip->y2; y++) {
 		src = vaddr + (y * fb->pitches[0]);
 		src += clip->x1;

drivers/gpu/drm/drm_fb_helper.c void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr, · line 3429

Quoted 6 lines
drivers/gpu/drm/drm_fb_helper.c +2 -0
@@ -3420,6 +3424,8 @@ void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			else
 				*dst++ = val16;
 		}
+		if (dstclip)
+			dst += fb->width - (clip->x2 - clip->x1);
 	}

Same story as before with dstclip and boolean parameters to functions. A small helper and you had two functions with and without clip.

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

#11 lore raw

PATCH v2 5/6 drm: add drm_fb_xrgb8888_to_rgb888() function to drm_fb_helper.c

In reply to Gerd Hoffmann

Like drm_fb_xrgb8888_to_rgb565() but converts to 24bpp (DRM_FORMAT_RGB888).

---
 include/drm/drm_fb_helper.h     |  4 +++
 drivers/gpu/drm/drm_fb_helper.c | 49 +++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
include/drm/drm_fb_helper.h +4 -0
index 1406057e1a93..a6e56fcd948e 100644
@@ -648,5 +648,9 @@ void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			       struct drm_framebuffer *fb,
 			       struct drm_rect *clip,
 			       bool swap, bool dstclip);
+void drm_fb_xrgb8888_to_rgb888(u8 *dst, void *vaddr,
+			       struct drm_framebuffer *fb,
+			       struct drm_rect *clip,
+			       bool dstclip);
 
 #endif
drivers/gpu/drm/drm_fb_helper.c +49 -0

52 lines not on this page · raw message

Signature · 1 line
2.18.1
#12 lore raw

Re: [PATCH v2 5/6] drm: add drm_fb_xrgb8888_to_rgb888() function to drm_fb_helper.c

Hi Gerd.

Quoted 13 lines · Gerd Hoffmann

Like drm_fb_xrgb8888_to_rgb565() but converts to 24bpp (DRM_FORMAT_RGB888).

---
 include/drm/drm_fb_helper.h     |  4 +++
 drivers/gpu/drm/drm_fb_helper.c | 49 +++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
include/drm/drm_fb_helper.h +0 -0
index 1406057e1a93..a6e56fcd948e 100644

include/drm/drm_fb_helper.h void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr, · line 654

Quoted 7 lines
include/drm/drm_fb_helper.h +4 -0
@@ -648,5 +648,9 @@ void drm_fb_xrgb8888_to_rgb565(u16 *dst, void *vaddr,
 			       struct drm_framebuffer *fb,
 			       struct drm_rect *clip,
 			       bool swap, bool dstclip);
+void drm_fb_xrgb8888_to_rgb888(u8 *dst, void *vaddr,
+			       struct drm_framebuffer *fb,
+			       struct drm_rect *clip,
+			       bool dstclip);

We have here three functions that take a *dst parameter:

	void *dst
	u8 *dst
	u16 *dst

My OCD triggers when things like this is not consistent.
But that said I see why the three implementations takes three different types.

Something I noticed, so passed in onwards to you.
Feel free to ignore.

Sam

#13 lore raw

PATCH v2 6/6 drm/cirrus: rewrite and modernize driver.

In reply to Gerd Hoffmann

Time to kill some bad sample code people are copying from ;)

This is a complete rewrite of the cirrus driver. The cirrus_mode_set() function is pretty much the only function which is carried over largely unmodified. Everything else is upside down.

It is a single monster patch. But given that it does some pretty fundamental changes to the drivers workflow and also reduces the code size by roughly 70% I think it'll still be alot easier to review than a longish baby-step patch series.

Changes summary:
- Given the small amout of video memory (4 MB) the cirrus device has the rewritten driver doesn't try to manage buffers there. Instead it will blit (memcpy) the active framebuffer to video memory.
- All gem objects are stored in main memory and are manged using the new shmem helpers. ttm is out.
- It supports RG16, RG24 and XR24 formats. XR24 gets converted to RG24 or RG16 at blit time if needed, to avoid the pitch becoming larger than what the cirrus hardware can handle.
- The simple display pipeline is used.
- The generic fbdev emulation is used.
- It's a atomic driver now.
- It runs wayland.

---
 drivers/gpu/drm/cirrus/cirrus_drv.h   | 251 -----------
 drivers/gpu/drm/cirrus/cirrus.c       | 621 ++++++++++++++++++++++++++
 drivers/gpu/drm/cirrus/cirrus_drv.c   | 161 -------
 drivers/gpu/drm/cirrus/cirrus_fbdev.c | 309 -------------
 drivers/gpu/drm/cirrus/cirrus_main.c  | 328 --------------
 drivers/gpu/drm/cirrus/cirrus_mode.c  | 617 -------------------------
 drivers/gpu/drm/cirrus/cirrus_ttm.c   | 343 --------------
 drivers/gpu/drm/cirrus/Kconfig        |   2 +-
 drivers/gpu/drm/cirrus/Makefile       |   3 -
 9 files changed, 622 insertions(+), 2013 deletions(-)
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.h
 create mode 100644 drivers/gpu/drm/cirrus/cirrus.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_fbdev.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_main.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_mode.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_ttm.c
drivers/gpu/drm/cirrus/cirrus_drv.h deleted +0 -251
deleted file mode 100644
index 828b150cdb20..000000000000
@@ -1,251 +0,0 @@
-/*
- * Copyright 2012 Red Hat
- *
- * This file is subject to the terms and conditions of the GNU General
- * Public License version 2. See the file COPYING in the main
- * directory of this archive for more details.
- *
- * Authors: Matthew Garrett
- *          Dave Airlie
- */
-#ifndef __CIRRUS_DRV_H__
-#define __CIRRUS_DRV_H__
-
-#include <video/vga.h>
-
-#include <drm/drm_encoder.h>
-#include <drm/drm_fb_helper.h>
-
-#include <drm/ttm/ttm_bo_api.h>
-#include <drm/ttm/ttm_bo_driver.h>
-#include <drm/ttm/ttm_placement.h>
-#include <drm/ttm/ttm_memory.h>
-#include <drm/ttm/ttm_module.h>
-
-#include <drm/drm_gem.h>
-
-#define DRIVER_AUTHOR		"Matthew Garrett"
-
-#define DRIVER_NAME		"cirrus"
-#define DRIVER_DESC		"qemu Cirrus emulation"
-#define DRIVER_DATE		"20110418"
-
-#define DRIVER_MAJOR		1
-#define DRIVER_MINOR		0
-#define DRIVER_PATCHLEVEL	0
-
-#define CIRRUSFB_CONN_LIMIT 1
-
-#define RREG8(reg) ioread8(((void __iomem *)cdev->rmmio) + (reg))
-#define WREG8(reg, v) iowrite8(v, ((void __iomem *)cdev->rmmio) + (reg))
-#define RREG32(reg) ioread32(((void __iomem *)cdev->rmmio) + (reg))
-#define WREG32(reg, v) iowrite32(v, ((void __iomem *)cdev->rmmio) + (reg))
-
-#define SEQ_INDEX 4
-#define SEQ_DATA 5
-
-#define WREG_SEQ(reg, v)					\
-	do {							\
-		WREG8(SEQ_INDEX, reg);				\
-		WREG8(SEQ_DATA, v);				\
-	} while (0)						\
-
-#define CRT_INDEX 0x14
-#define CRT_DATA 0x15
-
-#define WREG_CRT(reg, v)					\
-	do {							\
-		WREG8(CRT_INDEX, reg);				\
-		WREG8(CRT_DATA, v);				\
-	} while (0)						\
-
-#define GFX_INDEX 0xe
-#define GFX_DATA 0xf
-
-#define WREG_GFX(reg, v)					\
-	do {							\
-		WREG8(GFX_INDEX, reg);				\
-		WREG8(GFX_DATA, v);				\
-	} while (0)						\
-
-/*
- * Cirrus has a "hidden" DAC register that can be accessed by writing to
- * the pixel mask register to reset the state, then reading from the register
- * four times. The next write will then pass to the DAC
- */
-#define VGA_DAC_MASK 0x6
-
-#define WREG_HDR(v)						\
-	do {							\
-		RREG8(VGA_DAC_MASK);					\
-		RREG8(VGA_DAC_MASK);					\
-		RREG8(VGA_DAC_MASK);					\
-		RREG8(VGA_DAC_MASK);					\
-		WREG8(VGA_DAC_MASK, v);					\
-	} while (0)						\
-
-
-#define CIRRUS_MAX_FB_HEIGHT 4096
-#define CIRRUS_MAX_FB_WIDTH 4096
-
-#define CIRRUS_DPMS_CLEARED (-1)
-
-#define to_cirrus_crtc(x) container_of(x, struct cirrus_crtc, base)
-#define to_cirrus_encoder(x) container_of(x, struct cirrus_encoder, base)
-
-struct cirrus_crtc {
-	struct drm_crtc			base;
-	int				last_dpms;
-	bool				enabled;
-};
-
-struct cirrus_fbdev;
-struct cirrus_mode_info {
-	struct cirrus_crtc		*crtc;
-	/* pointer to fbdev info structure */
-	struct cirrus_fbdev		*gfbdev;
-};
-
-struct cirrus_encoder {
-	struct drm_encoder		base;
-	int				last_dpms;
-};
-
-struct cirrus_connector {
-	struct drm_connector		base;
-};
-
-struct cirrus_mc {
-	resource_size_t			vram_size;
-	resource_size_t			vram_base;
-};
-
-struct cirrus_device {
-	struct drm_device		*dev;
-	unsigned long			flags;
-
-	resource_size_t			rmmio_base;
-	resource_size_t			rmmio_size;
-	void __iomem			*rmmio;
-
-	struct cirrus_mc			mc;
-	struct cirrus_mode_info		mode_info;
-
-	int				num_crtc;
-	int fb_mtrr;
-
-	struct {
-		struct ttm_bo_device bdev;
-	} ttm;
-	bool mm_inited;
-};
-
-
-struct cirrus_fbdev {
-	struct drm_fb_helper helper; /* must be first */
-	struct drm_framebuffer *gfb;
-	void *sysram;
-	int size;
-	int x1, y1, x2, y2; /* dirty rect */
-	spinlock_t dirty_lock;
-};
-
-struct cirrus_bo {
-	struct ttm_buffer_object bo;
-	struct ttm_placement placement;
-	struct ttm_bo_kmap_obj kmap;
-	struct drm_gem_object gem;
-	struct ttm_place placements[3];
-	int pin_count;
-};
-#define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
-
-static inline struct cirrus_bo *
-cirrus_bo(struct ttm_buffer_object *bo)
-{
-	return container_of(bo, struct cirrus_bo, bo);
-}
-
-
-#define to_cirrus_obj(x) container_of(x, struct cirrus_gem_object, base)
-#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
-
-				/* cirrus_main.c */
-int cirrus_device_init(struct cirrus_device *cdev,
-		      struct drm_device *ddev,
-		      struct pci_dev *pdev,
-		      uint32_t flags);
-void cirrus_device_fini(struct cirrus_device *cdev);
-void cirrus_gem_free_object(struct drm_gem_object *obj);
-int cirrus_dumb_mmap_offset(struct drm_file *file,
-			    struct drm_device *dev,
-			    uint32_t handle,
-			    uint64_t *offset);
-int cirrus_gem_create(struct drm_device *dev,
-		   u32 size, bool iskernel,
-		      struct drm_gem_object **obj);
-int cirrus_dumb_create(struct drm_file *file,
-		    struct drm_device *dev,
-		       struct drm_mode_create_dumb *args);
-
-int cirrus_framebuffer_init(struct drm_device *dev,
-			    struct drm_framebuffer *gfb,
-			    const struct drm_mode_fb_cmd2 *mode_cmd,
-			    struct drm_gem_object *obj);
-
-bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height,
-			      int bpp, int pitch);
-
-				/* cirrus_display.c */
-int cirrus_modeset_init(struct cirrus_device *cdev);
-void cirrus_modeset_fini(struct cirrus_device *cdev);
-
-				/* cirrus_fbdev.c */
-int cirrus_fbdev_init(struct cirrus_device *cdev);
-void cirrus_fbdev_fini(struct cirrus_device *cdev);
-
-
-
-				/* cirrus_irq.c */
-void cirrus_driver_irq_preinstall(struct drm_device *dev);
-int cirrus_driver_irq_postinstall(struct drm_device *dev);
-void cirrus_driver_irq_uninstall(struct drm_device *dev);
-irqreturn_t cirrus_driver_irq_handler(int irq, void *arg);
-
-				/* cirrus_kms.c */
-int cirrus_driver_load(struct drm_device *dev, unsigned long flags);
-void cirrus_driver_unload(struct drm_device *dev);
-extern struct drm_ioctl_desc cirrus_ioctls[];
-extern int cirrus_max_ioctl;
-
-int cirrus_mm_init(struct cirrus_device *cirrus);
-void cirrus_mm_fini(struct cirrus_device *cirrus);
-void cirrus_ttm_placement(struct cirrus_bo *bo, int domain);
-int cirrus_bo_create(struct drm_device *dev, int size, int align,
-		     uint32_t flags, struct cirrus_bo **pcirrusbo);
-int cirrus_mmap(struct file *filp, struct vm_area_struct *vma);
-
-static inline int cirrus_bo_reserve(struct cirrus_bo *bo, bool no_wait)
-{
-	int ret;
-
-	ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
-	if (ret) {
-		if (ret != -ERESTARTSYS && ret != -EBUSY)
-			DRM_ERROR("reserve failed %p\n", bo);
-		return ret;
-	}
-	return 0;
-}
-
-static inline void cirrus_bo_unreserve(struct cirrus_bo *bo)
-{
-	ttm_bo_unreserve(&bo->bo);
-}
-
-int cirrus_bo_push_sysram(struct cirrus_bo *bo);
-int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
-
-extern int cirrus_bpp;
-
-#endif				/* __CIRRUS_DRV_H__ */
drivers/gpu/drm/cirrus/cirrus.c new file +621 -0

621 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_drv.c deleted +0 -161

161 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_fbdev.c deleted +0 -309

309 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_main.c deleted +0 -328

328 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_mode.c deleted +0 -617

617 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_ttm.c deleted +0 -343

343 lines not on this page · raw message

drivers/gpu/drm/cirrus/Kconfig +1 -1
index fc78c90ee931..dd4f52a0bc1c 100644
@@ -2,7 +2,7 @@ config DRM_CIRRUS_QEMU
 	tristate "Cirrus driver for QEMU emulated device"
 	depends on DRM && PCI && MMU
 	select DRM_KMS_HELPER
-	select DRM_TTM
+	select DRM_GEM_SHMEM_HELPER
 	help
 	 This is a KMS driver for emulated cirrus device in qemu.
 	 It is *NOT* intended for real cirrus devices. This requires
drivers/gpu/drm/cirrus/Makefile +0 -3
index 919c0a336c97..acf8971d37a1 100644
@@ -1,4 +1 @@
-cirrus-y  := cirrus_main.o cirrus_mode.o \
-	cirrus_drv.o cirrus_fbdev.o cirrus_ttm.o
-
 obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus.o
Signature · 1 line
2.18.1
#14 lore raw

PATCH v2 6/6 drm/cirrus: rewrite and modernize driver.

In reply to Gerd Hoffmann

Time to kill some bad sample code people are copying from ;)

This is a complete rewrite of the cirrus driver. The cirrus_mode_set() function is pretty much the only function which is carried over largely unmodified. Everything else is upside down.

It is a single monster patch. But given that it does some pretty fundamental changes to the drivers workflow and also reduces the code size by roughly 70% I think it'll still be alot easier to review than a longish baby-step patch series.

Changes summary:
- Given the small amout of video memory (4 MB) the cirrus device has the rewritten driver doesn't try to manage buffers there. Instead it will blit (memcpy) the active framebuffer to video memory.
- All gem objects are stored in main memory and are manged using the new shmem helpers. ttm is out.
- It supports RG16, RG24 and XR24 formats. XR24 gets converted to RG24 or RG16 at blit time if needed, to avoid the pitch becoming larger than what the cirrus hardware can handle.
- The simple display pipeline is used.
- The generic fbdev emulation is used.
- It's a atomic driver now.
- It runs wayland.

---
 drivers/gpu/drm/cirrus/cirrus_drv.h   | 251 -----------
 drivers/gpu/drm/cirrus/cirrus.c       | 621 ++++++++++++++++++++++++++
 drivers/gpu/drm/cirrus/cirrus_drv.c   | 161 -------
 drivers/gpu/drm/cirrus/cirrus_fbdev.c | 309 -------------
 drivers/gpu/drm/cirrus/cirrus_main.c  | 328 --------------
 drivers/gpu/drm/cirrus/cirrus_mode.c  | 617 -------------------------
 drivers/gpu/drm/cirrus/cirrus_ttm.c   | 343 --------------
 drivers/gpu/drm/cirrus/Kconfig        |   2 +-
 drivers/gpu/drm/cirrus/Makefile       |   3 -
 9 files changed, 622 insertions(+), 2013 deletions(-)
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.h
 create mode 100644 drivers/gpu/drm/cirrus/cirrus.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_fbdev.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_main.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_mode.c
 delete mode 100644 drivers/gpu/drm/cirrus/cirrus_ttm.c
drivers/gpu/drm/cirrus/cirrus_drv.h deleted +0 -251
deleted file mode 100644
index 828b150cdb20..000000000000
@@ -1,251 +0,0 @@
-/*
- * Copyright 2012 Red Hat
- *
- * This file is subject to the terms and conditions of the GNU General
- * Public License version 2. See the file COPYING in the main
- * directory of this archive for more details.
- *
- * Authors: Matthew Garrett
- *          Dave Airlie
- */
-#ifndef __CIRRUS_DRV_H__
-#define __CIRRUS_DRV_H__
-
-#include <video/vga.h>
-
-#include <drm/drm_encoder.h>
-#include <drm/drm_fb_helper.h>
-
-#include <drm/ttm/ttm_bo_api.h>
-#include <drm/ttm/ttm_bo_driver.h>
-#include <drm/ttm/ttm_placement.h>
-#include <drm/ttm/ttm_memory.h>
-#include <drm/ttm/ttm_module.h>
-
-#include <drm/drm_gem.h>
-
-#define DRIVER_AUTHOR		"Matthew Garrett"
-
-#define DRIVER_NAME		"cirrus"
-#define DRIVER_DESC		"qemu Cirrus emulation"
-#define DRIVER_DATE		"20110418"
-
-#define DRIVER_MAJOR		1
-#define DRIVER_MINOR		0
-#define DRIVER_PATCHLEVEL	0
-
-#define CIRRUSFB_CONN_LIMIT 1
-
-#define RREG8(reg) ioread8(((void __iomem *)cdev->rmmio) + (reg))
-#define WREG8(reg, v) iowrite8(v, ((void __iomem *)cdev->rmmio) + (reg))
-#define RREG32(reg) ioread32(((void __iomem *)cdev->rmmio) + (reg))
-#define WREG32(reg, v) iowrite32(v, ((void __iomem *)cdev->rmmio) + (reg))
-
-#define SEQ_INDEX 4
-#define SEQ_DATA 5
-
-#define WREG_SEQ(reg, v)					\
-	do {							\
-		WREG8(SEQ_INDEX, reg);				\
-		WREG8(SEQ_DATA, v);				\
-	} while (0)						\
-
-#define CRT_INDEX 0x14
-#define CRT_DATA 0x15
-
-#define WREG_CRT(reg, v)					\
-	do {							\
-		WREG8(CRT_INDEX, reg);				\
-		WREG8(CRT_DATA, v);				\
-	} while (0)						\
-
-#define GFX_INDEX 0xe
-#define GFX_DATA 0xf
-
-#define WREG_GFX(reg, v)					\
-	do {							\
-		WREG8(GFX_INDEX, reg);				\
-		WREG8(GFX_DATA, v);				\
-	} while (0)						\
-
-/*
- * Cirrus has a "hidden" DAC register that can be accessed by writing to
- * the pixel mask register to reset the state, then reading from the register
- * four times. The next write will then pass to the DAC
- */
-#define VGA_DAC_MASK 0x6
-
-#define WREG_HDR(v)						\
-	do {							\
-		RREG8(VGA_DAC_MASK);					\
-		RREG8(VGA_DAC_MASK);					\
-		RREG8(VGA_DAC_MASK);					\
-		RREG8(VGA_DAC_MASK);					\
-		WREG8(VGA_DAC_MASK, v);					\
-	} while (0)						\
-
-
-#define CIRRUS_MAX_FB_HEIGHT 4096
-#define CIRRUS_MAX_FB_WIDTH 4096
-
-#define CIRRUS_DPMS_CLEARED (-1)
-
-#define to_cirrus_crtc(x) container_of(x, struct cirrus_crtc, base)
-#define to_cirrus_encoder(x) container_of(x, struct cirrus_encoder, base)
-
-struct cirrus_crtc {
-	struct drm_crtc			base;
-	int				last_dpms;
-	bool				enabled;
-};
-
-struct cirrus_fbdev;
-struct cirrus_mode_info {
-	struct cirrus_crtc		*crtc;
-	/* pointer to fbdev info structure */
-	struct cirrus_fbdev		*gfbdev;
-};
-
-struct cirrus_encoder {
-	struct drm_encoder		base;
-	int				last_dpms;
-};
-
-struct cirrus_connector {
-	struct drm_connector		base;
-};
-
-struct cirrus_mc {
-	resource_size_t			vram_size;
-	resource_size_t			vram_base;
-};
-
-struct cirrus_device {
-	struct drm_device		*dev;
-	unsigned long			flags;
-
-	resource_size_t			rmmio_base;
-	resource_size_t			rmmio_size;
-	void __iomem			*rmmio;
-
-	struct cirrus_mc			mc;
-	struct cirrus_mode_info		mode_info;
-
-	int				num_crtc;
-	int fb_mtrr;
-
-	struct {
-		struct ttm_bo_device bdev;
-	} ttm;
-	bool mm_inited;
-};
-
-
-struct cirrus_fbdev {
-	struct drm_fb_helper helper; /* must be first */
-	struct drm_framebuffer *gfb;
-	void *sysram;
-	int size;
-	int x1, y1, x2, y2; /* dirty rect */
-	spinlock_t dirty_lock;
-};
-
-struct cirrus_bo {
-	struct ttm_buffer_object bo;
-	struct ttm_placement placement;
-	struct ttm_bo_kmap_obj kmap;
-	struct drm_gem_object gem;
-	struct ttm_place placements[3];
-	int pin_count;
-};
-#define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
-
-static inline struct cirrus_bo *
-cirrus_bo(struct ttm_buffer_object *bo)
-{
-	return container_of(bo, struct cirrus_bo, bo);
-}
-
-
-#define to_cirrus_obj(x) container_of(x, struct cirrus_gem_object, base)
-#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
-
-				/* cirrus_main.c */
-int cirrus_device_init(struct cirrus_device *cdev,
-		      struct drm_device *ddev,
-		      struct pci_dev *pdev,
-		      uint32_t flags);
-void cirrus_device_fini(struct cirrus_device *cdev);
-void cirrus_gem_free_object(struct drm_gem_object *obj);
-int cirrus_dumb_mmap_offset(struct drm_file *file,
-			    struct drm_device *dev,
-			    uint32_t handle,
-			    uint64_t *offset);
-int cirrus_gem_create(struct drm_device *dev,
-		   u32 size, bool iskernel,
-		      struct drm_gem_object **obj);
-int cirrus_dumb_create(struct drm_file *file,
-		    struct drm_device *dev,
-		       struct drm_mode_create_dumb *args);
-
-int cirrus_framebuffer_init(struct drm_device *dev,
-			    struct drm_framebuffer *gfb,
-			    const struct drm_mode_fb_cmd2 *mode_cmd,
-			    struct drm_gem_object *obj);
-
-bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height,
-			      int bpp, int pitch);
-
-				/* cirrus_display.c */
-int cirrus_modeset_init(struct cirrus_device *cdev);
-void cirrus_modeset_fini(struct cirrus_device *cdev);
-
-				/* cirrus_fbdev.c */
-int cirrus_fbdev_init(struct cirrus_device *cdev);
-void cirrus_fbdev_fini(struct cirrus_device *cdev);
-
-
-
-				/* cirrus_irq.c */
-void cirrus_driver_irq_preinstall(struct drm_device *dev);
-int cirrus_driver_irq_postinstall(struct drm_device *dev);
-void cirrus_driver_irq_uninstall(struct drm_device *dev);
-irqreturn_t cirrus_driver_irq_handler(int irq, void *arg);
-
-				/* cirrus_kms.c */
-int cirrus_driver_load(struct drm_device *dev, unsigned long flags);
-void cirrus_driver_unload(struct drm_device *dev);
-extern struct drm_ioctl_desc cirrus_ioctls[];
-extern int cirrus_max_ioctl;
-
-int cirrus_mm_init(struct cirrus_device *cirrus);
-void cirrus_mm_fini(struct cirrus_device *cirrus);
-void cirrus_ttm_placement(struct cirrus_bo *bo, int domain);
-int cirrus_bo_create(struct drm_device *dev, int size, int align,
-		     uint32_t flags, struct cirrus_bo **pcirrusbo);
-int cirrus_mmap(struct file *filp, struct vm_area_struct *vma);
-
-static inline int cirrus_bo_reserve(struct cirrus_bo *bo, bool no_wait)
-{
-	int ret;
-
-	ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
-	if (ret) {
-		if (ret != -ERESTARTSYS && ret != -EBUSY)
-			DRM_ERROR("reserve failed %p\n", bo);
-		return ret;
-	}
-	return 0;
-}
-
-static inline void cirrus_bo_unreserve(struct cirrus_bo *bo)
-{
-	ttm_bo_unreserve(&bo->bo);
-}
-
-int cirrus_bo_push_sysram(struct cirrus_bo *bo);
-int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
-
-extern int cirrus_bpp;
-
-#endif				/* __CIRRUS_DRV_H__ */
drivers/gpu/drm/cirrus/cirrus.c new file +621 -0

621 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_drv.c deleted +0 -161

161 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_fbdev.c deleted +0 -309

309 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_main.c deleted +0 -328

328 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_mode.c deleted +0 -617

617 lines not on this page · raw message

drivers/gpu/drm/cirrus/cirrus_ttm.c deleted +0 -343

343 lines not on this page · raw message

drivers/gpu/drm/cirrus/Kconfig +1 -1
index fc78c90ee931..dd4f52a0bc1c 100644
@@ -2,7 +2,7 @@ config DRM_CIRRUS_QEMU
 	tristate "Cirrus driver for QEMU emulated device"
 	depends on DRM && PCI && MMU
 	select DRM_KMS_HELPER
-	select DRM_TTM
+	select DRM_GEM_SHMEM_HELPER
 	help
 	 This is a KMS driver for emulated cirrus device in qemu.
 	 It is *NOT* intended for real cirrus devices. This requires
drivers/gpu/drm/cirrus/Makefile +0 -3
index 919c0a336c97..acf8971d37a1 100644
@@ -1,4 +1 @@
-cirrus-y  := cirrus_main.o cirrus_mode.o \
-	cirrus_drv.o cirrus_fbdev.o cirrus_ttm.o
-
 obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus.o
Signature · 6 lines
2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 6/6
#15 lore raw

Hi Gerd.

Very nice diffstat - good work indeed!

Quoted 2 lines

I think it'll still be alot easier to review than a longish baby-step patch series.

Agreed.

Some random nits below.
With the relevant parts addressed you can add my:

Quoted 11 lines

new file mode 100644
index 000000000000..5060e3d854d3

drivers/gpu/drm/cirrus/cirrus.c new file +6 -0
@@ -0,0 +1,621 @@
+/*
+ * Copyright 2012-2019 Red Hat
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License version 2. See the file COPYING in the main
+ * directory of this archive for more details.

drivers/gpu/drm/cirrus/cirrus.c line 16

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+ *
+ * Authors: Matthew Garrett
+ *	    Dave Airlie
+ *	    Gerd Hoffmann
+ *
+ * Portions of this code derived from cirrusfb.c:
+ * drivers/video/cirrusfb.c - driver for Cirrus Logic chipsets
+ *
+ * Copyright 1999-2001 Jeff Garzik <[email protected]>
+ */

Can we introduce an SPDX identifier?
(I am not good at the license stuff, so I cannot tell)

Quoted 13 lines
drivers/gpu/drm/cirrus/cirrus.c new file +13 -0
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/console.h>
+
+#include <video/vga.h>
+#include <video/cirrus.h>
+
+#include <drm/drm_drv.h>
+#include <drm/drm_file.h>
+#include <drm/drm_ioctl.h>
+#include <drm/drm_vblank.h>
+#include <drm/drm_connector.h>
+

drivers/gpu/drm/cirrus/cirrus.c line 40

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+#include <drm/drm_fourcc.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_simple_kms_helper.h>
+#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_modeset_helper_vtables.h>
+#include <drm/drm_damage_helper.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic_state_helper.h>

Please sort again, you added a few new includes since last time

Quoted 14 lines
drivers/gpu/drm/cirrus/cirrus.c new file +14 -0
+struct cirrus_device {
+	struct drm_device	       dev;
+	struct drm_simple_display_pipe pipe;
+	struct drm_connector	       conn;
+	unsigned int		       cpp;
+	unsigned int		       pitch;
+	void __iomem		       *vram;
+	void __iomem		       *mmio;
+};
+
+/* ------------------------------------------------------------------ */
+/*
+ * The meat of this driver. The core passes us a mode and we have to program
+ * it. The modesetting here is the bare minimum required to satisfy the qemu

drivers/gpu/drm/cirrus/cirrus.c line 74

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+ * emulation of this hardware, and running this against a real device is
+ * likely to result in an inadequately programmed mode. We've already had
+ * the opportunity to modify the mode, so whatever we receive here should
+ * be something that can be correctly programmed and displayed
+ */
+
+#define RREG8(reg) ioread8(((void __iomem *)cirrus->mmio) + (reg))
+#define WREG8(reg, v) iowrite8(v, ((void __iomem *)cirrus->mmio) + (reg))
+#define RREG32(reg) ioread32(((void __iomem *)cirrus->mmio) + (reg))
+#define WREG32(reg, v) iowrite32(v, ((void __iomem *)cirrus->mmio) + (reg))

The cast of cirrus->mmio to (void __iomem *) should not be necessary as this is the type is has in struct cirrus_device

There is not reason to use a define, use can use a static inline function

drivers/gpu/drm/cirrus/cirrus.c line 83

Quoted 9 lines
drivers/gpu/drm/cirrus/cirrus.c new file +9 -0
+
+#define SEQ_INDEX 4
+#define SEQ_DATA 5
+
+#define WREG_SEQ(reg, v)					\
+	do {							\
+		WREG8(SEQ_INDEX, reg);				\
+		WREG8(SEQ_DATA, v);				\
+	} while (0)						\

This is only used once, drop the define?

drivers/gpu/drm/cirrus/cirrus.c line 92

Quoted 8 lines
drivers/gpu/drm/cirrus/cirrus.c new file +8 -0
+#define CRT_INDEX 0x14
+#define CRT_DATA 0x15
+
+#define WREG_CRT(reg, v)					\
+	do {							\
+		WREG8(CRT_INDEX, reg);				\
+		WREG8(CRT_DATA, v);				\
+	} while (0)						\

static inline?

drivers/gpu/drm/cirrus/cirrus.c line 101

Quoted 8 lines
drivers/gpu/drm/cirrus/cirrus.c new file +8 -0
+#define GFX_INDEX 0xe
+#define GFX_DATA 0xf
+
+#define WREG_GFX(reg, v)					\
+	do {							\
+		WREG8(GFX_INDEX, reg);				\
+		WREG8(GFX_DATA, v);				\
+	} while (0)						\

Used twice - drop?

drivers/gpu/drm/cirrus/cirrus.c line 112

Quoted 11 lines
drivers/gpu/drm/cirrus/cirrus.c new file +11 -0
+
+#define VGA_DAC_MASK 0x6
+
+#define WREG_HDR(v)						\
+	do {							\
+		RREG8(VGA_DAC_MASK);				\
+		RREG8(VGA_DAC_MASK);				\
+		RREG8(VGA_DAC_MASK);				\
+		RREG8(VGA_DAC_MASK);				\
+		WREG8(VGA_DAC_MASK, v);				\
+	} while (0)						\

Used once, drop?

Quoted 87 lines
drivers/gpu/drm/cirrus/cirrus.c new file +87 -0
+static int cirrus_convert_to(struct drm_framebuffer *fb)
+{
+	if (fb->format->cpp[0] == 4 && fb->pitches[0] > CIRRUS_MAX_PITCH) {
+		if (fb->width * 3 <= CIRRUS_MAX_PITCH)
+			/* convert from XR24 to RG24 */
+			return 3;
+		else
+			/* convert from XR24 to RG16 */
+			return 2;
+	}
+	return 0;
+}
+
+static int cirrus_cpp(struct drm_framebuffer *fb)
+{
+	int convert_cpp = cirrus_convert_to(fb);
+
+	if (convert_cpp)
+		return convert_cpp;
+	return fb->format->cpp[0];
+}
+
+static int cirrus_pitch(struct drm_framebuffer *fb)
+{
+	int convert_cpp = cirrus_convert_to(fb);
+
+	if (convert_cpp)
+		return convert_cpp * fb->width;
+	return fb->pitches[0];
+}
+
+static int cirrus_mode_set(struct cirrus_device *cirrus,
+			   struct drm_display_mode *mode,
+			   struct drm_framebuffer *fb)
+{
+	int hsyncstart, hsyncend, htotal, hdispend;
+	int vtotal, vdispend;
+	int tmp;
+	int sr07 = 0, hdr = 0;
+
+	htotal = mode->htotal / 8;
+	hsyncend = mode->hsync_end / 8;
+	hsyncstart = mode->hsync_start / 8;
+	hdispend = mode->hdisplay / 8;
+
+	vtotal = mode->vtotal;
+	vdispend = mode->vdisplay;
+
+	vdispend -= 1;
+	vtotal -= 2;
+
+	htotal -= 5;
+	hdispend -= 1;
+	hsyncstart += 1;
+	hsyncend += 1;
+
+	WREG_CRT(VGA_CRTC_V_SYNC_END, 0x20);
+	WREG_CRT(VGA_CRTC_H_TOTAL, htotal);
+	WREG_CRT(VGA_CRTC_H_DISP, hdispend);
+	WREG_CRT(VGA_CRTC_H_SYNC_START, hsyncstart);
+	WREG_CRT(VGA_CRTC_H_SYNC_END, hsyncend);
+	WREG_CRT(VGA_CRTC_V_TOTAL, vtotal & 0xff);
+	WREG_CRT(VGA_CRTC_V_DISP_END, vdispend & 0xff);
+
+	tmp = 0x40;
+	if ((vdispend + 1) & 512)
+		tmp |= 0x20;
+	WREG_CRT(VGA_CRTC_MAX_SCAN, tmp);
+
+	/*
+	 * Overflow bits for values that don't fit in the standard registers
+	 */
+	tmp = 16;
+	if (vtotal & 256)
+		tmp |= 1;
+	if (vdispend & 256)
+		tmp |= 2;
+	if ((vdispend + 1) & 256)
+		tmp |= 8;
+	if (vtotal & 512)
+		tmp |= 32;
+	if (vdispend & 512)
+		tmp |= 64;
+	WREG_CRT(VGA_CRTC_OVERFLOW, tmp);
+
+	tmp = 0;
+

drivers/gpu/drm/cirrus/cirrus.c line 211

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+	/* More overflow bits */
+
+	if ((htotal + 5) & 64)
+		tmp |= 16;
+	if ((htotal + 5) & 128)
+		tmp |= 32;
+	if (vtotal & 256)
+		tmp |= 64;
+	if (vtotal & 512)
+		tmp |= 128;

For bit operations / numbers above consider to hexadecimal numbers to increase readability.

Quoted 70 lines
drivers/gpu/drm/cirrus/cirrus.c new file +70 -0
+
+	WREG_CRT(CL_CRT1A, tmp);
+
+	/* Disable Hercules/CGA compatibility */
+	WREG_CRT(VGA_CRTC_MODE, 0x03);
+
+	WREG8(SEQ_INDEX, 0x7);
+	sr07 = RREG8(SEQ_DATA);
+	sr07 &= 0xe0;
+	hdr = 0;
+
+	cirrus->cpp = cirrus_cpp(fb);
+	switch (cirrus->cpp * 8) {
+	case 8:
+		sr07 |= 0x11;
+		break;
+	case 16:
+		sr07 |= 0x17;
+		hdr = 0xc1;
+		break;
+	case 24:
+		sr07 |= 0x15;
+		hdr = 0xc5;
+		break;
+	case 32:
+		sr07 |= 0x19;
+		hdr = 0xc5;
+		break;
+	default:
+		return -1;
+	}
+
+	WREG_SEQ(0x7, sr07);
+
+	/* Program the pitch */
+	cirrus->pitch = cirrus_pitch(fb);
+	tmp = cirrus->pitch / 8;
+	WREG_CRT(VGA_CRTC_OFFSET, tmp);
+
+	/* Enable extended blanking and pitch bits, and enable full memory */
+	tmp = 0x22;
+	tmp |= (cirrus->pitch >> 7) & 0x10;
+	tmp |= (cirrus->pitch >> 6) & 0x40;
+	WREG_CRT(0x1b, tmp);
+
+	/* Enable high-colour modes */
+	WREG_GFX(VGA_GFX_MODE, 0x40);
+
+	/* And set graphics mode */
+	WREG_GFX(VGA_GFX_MISC, 0x01);
+
+	WREG_HDR(hdr);
+	/* cirrus_crtc_do_set_base(crtc, old_fb, x, y, 0); */
+
+	/* Unblank (needed on S3 resume, vgabios doesn't do it then) */
+	outb(0x20, 0x3c0);
+	return 0;
+}
+
+static void cirrus_pipe_update(struct drm_simple_display_pipe *pipe,
+			       struct drm_plane_state *old_state)
+{
+	struct cirrus_device *cirrus = pipe->crtc.dev->dev_private;
+	struct drm_plane_state *state = pipe->plane.state;
+	struct drm_crtc *crtc = &pipe->crtc;
+	struct drm_rect rect;
+
+	if (pipe->plane.state->fb &&
+	    cirrus->cpp != cirrus_cpp(pipe->plane.state->fb))
+		cirrus_mode_set(cirrus, &crtc->mode,

drivers/gpu/drm/cirrus/cirrus.c

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+				pipe->plane.state->fb);
+
+	if (drm_atomic_helper_damage_merged(old_state, state, &rect))
+		cirrus_fb_blit_rect(pipe->plane.state->fb, &rect);
+
+	if (crtc->state->event) {
+		spin_lock_irq(&crtc->dev->event_lock);
+		drm_crtc_send_vblank_event(crtc, crtc->state->event);
+		spin_unlock_irq(&crtc->dev->event_lock);
+		crtc->state->event = NULL;

Should you set crtc->state->event = NULL; before spin_unlock_irq()?

drivers/gpu/drm/cirrus/cirrus.c line 592

Quoted 6 lines
drivers/gpu/drm/cirrus/cirrus.c new file +6 -0
+
+/* only bind to the cirrus chip in qemu */
+static const struct pci_device_id pciidlist[] = {
+	{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
+	  PCI_SUBVENDOR_ID_REDHAT_QUMRANET, PCI_SUBDEVICE_ID_QEMU,
+	  0, 0, 0 },
	PCI_DEVICE_SUB(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
		       PCI_SUBVENDOR_ID_REDHAT_QUMRANET, PCI_SUBDEVICE_ID_QEMU)

????
Hmm, looks like an alternative way to say the same, that is hardly much improvement?!?

drivers/gpu/drm/cirrus/cirrus.c line 596

Quoted 4 lines
drivers/gpu/drm/cirrus/cirrus.c new file +4 -0
+	{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
+	  PCI_VENDOR_ID_XEN, 0x0001,
+	  0, 0, 0 },
+	{ /* end if list */}

Add space before final }

Reviewed-by on v2 6/6
#16 lore raw
In reply to Gerd Hoffmann

Hi Gerd.

Very nice diffstat - good work indeed!

Quoted 2 lines

I think it'll still be alot easier to review than a longish baby-step patch series.

Agreed.

Some random nits below.
With the relevant parts addressed you can add my:

Quoted 11 lines

new file mode 100644
index 000000000000..5060e3d854d3

drivers/gpu/drm/cirrus/cirrus.c new file +6 -0
@@ -0,0 +1,621 @@
+/*
+ * Copyright 2012-2019 Red Hat
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License version 2. See the file COPYING in the main
+ * directory of this archive for more details.

drivers/gpu/drm/cirrus/cirrus.c line 16

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+ *
+ * Authors: Matthew Garrett
+ *	    Dave Airlie
+ *	    Gerd Hoffmann
+ *
+ * Portions of this code derived from cirrusfb.c:
+ * drivers/video/cirrusfb.c - driver for Cirrus Logic chipsets
+ *
+ * Copyright 1999-2001 Jeff Garzik <[email protected]>
+ */

Can we introduce an SPDX identifier?
(I am not good at the license stuff, so I cannot tell)

Quoted 13 lines
drivers/gpu/drm/cirrus/cirrus.c new file +13 -0
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/console.h>
+
+#include <video/vga.h>
+#include <video/cirrus.h>
+
+#include <drm/drm_drv.h>
+#include <drm/drm_file.h>
+#include <drm/drm_ioctl.h>
+#include <drm/drm_vblank.h>
+#include <drm/drm_connector.h>
+

drivers/gpu/drm/cirrus/cirrus.c line 40

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+#include <drm/drm_fourcc.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_simple_kms_helper.h>
+#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_modeset_helper_vtables.h>
+#include <drm/drm_damage_helper.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic_state_helper.h>

Please sort again, you added a few new includes since last time

Quoted 14 lines
drivers/gpu/drm/cirrus/cirrus.c new file +14 -0
+struct cirrus_device {
+	struct drm_device	       dev;
+	struct drm_simple_display_pipe pipe;
+	struct drm_connector	       conn;
+	unsigned int		       cpp;
+	unsigned int		       pitch;
+	void __iomem		       *vram;
+	void __iomem		       *mmio;
+};
+
+/* ------------------------------------------------------------------ */
+/*
+ * The meat of this driver. The core passes us a mode and we have to program
+ * it. The modesetting here is the bare minimum required to satisfy the qemu

drivers/gpu/drm/cirrus/cirrus.c line 74

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+ * emulation of this hardware, and running this against a real device is
+ * likely to result in an inadequately programmed mode. We've already had
+ * the opportunity to modify the mode, so whatever we receive here should
+ * be something that can be correctly programmed and displayed
+ */
+
+#define RREG8(reg) ioread8(((void __iomem *)cirrus->mmio) + (reg))
+#define WREG8(reg, v) iowrite8(v, ((void __iomem *)cirrus->mmio) + (reg))
+#define RREG32(reg) ioread32(((void __iomem *)cirrus->mmio) + (reg))
+#define WREG32(reg, v) iowrite32(v, ((void __iomem *)cirrus->mmio) + (reg))

The cast of cirrus->mmio to (void __iomem *) should not be necessary as this is the type is has in struct cirrus_device

There is not reason to use a define, use can use a static inline function

drivers/gpu/drm/cirrus/cirrus.c line 83

Quoted 9 lines
drivers/gpu/drm/cirrus/cirrus.c new file +9 -0
+
+#define SEQ_INDEX 4
+#define SEQ_DATA 5
+
+#define WREG_SEQ(reg, v)					\
+	do {							\
+		WREG8(SEQ_INDEX, reg);				\
+		WREG8(SEQ_DATA, v);				\
+	} while (0)						\

This is only used once, drop the define?

drivers/gpu/drm/cirrus/cirrus.c line 92

Quoted 8 lines
drivers/gpu/drm/cirrus/cirrus.c new file +8 -0
+#define CRT_INDEX 0x14
+#define CRT_DATA 0x15
+
+#define WREG_CRT(reg, v)					\
+	do {							\
+		WREG8(CRT_INDEX, reg);				\
+		WREG8(CRT_DATA, v);				\
+	} while (0)						\

static inline?

drivers/gpu/drm/cirrus/cirrus.c line 101

Quoted 8 lines
drivers/gpu/drm/cirrus/cirrus.c new file +8 -0
+#define GFX_INDEX 0xe
+#define GFX_DATA 0xf
+
+#define WREG_GFX(reg, v)					\
+	do {							\
+		WREG8(GFX_INDEX, reg);				\
+		WREG8(GFX_DATA, v);				\
+	} while (0)						\

Used twice - drop?

drivers/gpu/drm/cirrus/cirrus.c line 112

Quoted 11 lines
drivers/gpu/drm/cirrus/cirrus.c new file +11 -0
+
+#define VGA_DAC_MASK 0x6
+
+#define WREG_HDR(v)						\
+	do {							\
+		RREG8(VGA_DAC_MASK);				\
+		RREG8(VGA_DAC_MASK);				\
+		RREG8(VGA_DAC_MASK);				\
+		RREG8(VGA_DAC_MASK);				\
+		WREG8(VGA_DAC_MASK, v);				\
+	} while (0)						\

Used once, drop?

Quoted 87 lines
drivers/gpu/drm/cirrus/cirrus.c new file +87 -0
+static int cirrus_convert_to(struct drm_framebuffer *fb)
+{
+	if (fb->format->cpp[0] == 4 && fb->pitches[0] > CIRRUS_MAX_PITCH) {
+		if (fb->width * 3 <= CIRRUS_MAX_PITCH)
+			/* convert from XR24 to RG24 */
+			return 3;
+		else
+			/* convert from XR24 to RG16 */
+			return 2;
+	}
+	return 0;
+}
+
+static int cirrus_cpp(struct drm_framebuffer *fb)
+{
+	int convert_cpp = cirrus_convert_to(fb);
+
+	if (convert_cpp)
+		return convert_cpp;
+	return fb->format->cpp[0];
+}
+
+static int cirrus_pitch(struct drm_framebuffer *fb)
+{
+	int convert_cpp = cirrus_convert_to(fb);
+
+	if (convert_cpp)
+		return convert_cpp * fb->width;
+	return fb->pitches[0];
+}
+
+static int cirrus_mode_set(struct cirrus_device *cirrus,
+			   struct drm_display_mode *mode,
+			   struct drm_framebuffer *fb)
+{
+	int hsyncstart, hsyncend, htotal, hdispend;
+	int vtotal, vdispend;
+	int tmp;
+	int sr07 = 0, hdr = 0;
+
+	htotal = mode->htotal / 8;
+	hsyncend = mode->hsync_end / 8;
+	hsyncstart = mode->hsync_start / 8;
+	hdispend = mode->hdisplay / 8;
+
+	vtotal = mode->vtotal;
+	vdispend = mode->vdisplay;
+
+	vdispend -= 1;
+	vtotal -= 2;
+
+	htotal -= 5;
+	hdispend -= 1;
+	hsyncstart += 1;
+	hsyncend += 1;
+
+	WREG_CRT(VGA_CRTC_V_SYNC_END, 0x20);
+	WREG_CRT(VGA_CRTC_H_TOTAL, htotal);
+	WREG_CRT(VGA_CRTC_H_DISP, hdispend);
+	WREG_CRT(VGA_CRTC_H_SYNC_START, hsyncstart);
+	WREG_CRT(VGA_CRTC_H_SYNC_END, hsyncend);
+	WREG_CRT(VGA_CRTC_V_TOTAL, vtotal & 0xff);
+	WREG_CRT(VGA_CRTC_V_DISP_END, vdispend & 0xff);
+
+	tmp = 0x40;
+	if ((vdispend + 1) & 512)
+		tmp |= 0x20;
+	WREG_CRT(VGA_CRTC_MAX_SCAN, tmp);
+
+	/*
+	 * Overflow bits for values that don't fit in the standard registers
+	 */
+	tmp = 16;
+	if (vtotal & 256)
+		tmp |= 1;
+	if (vdispend & 256)
+		tmp |= 2;
+	if ((vdispend + 1) & 256)
+		tmp |= 8;
+	if (vtotal & 512)
+		tmp |= 32;
+	if (vdispend & 512)
+		tmp |= 64;
+	WREG_CRT(VGA_CRTC_OVERFLOW, tmp);
+
+	tmp = 0;
+

drivers/gpu/drm/cirrus/cirrus.c line 211

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+	/* More overflow bits */
+
+	if ((htotal + 5) & 64)
+		tmp |= 16;
+	if ((htotal + 5) & 128)
+		tmp |= 32;
+	if (vtotal & 256)
+		tmp |= 64;
+	if (vtotal & 512)
+		tmp |= 128;

For bit operations / numbers above consider to hexadecimal numbers to increase readability.

Quoted 70 lines
drivers/gpu/drm/cirrus/cirrus.c new file +70 -0
+
+	WREG_CRT(CL_CRT1A, tmp);
+
+	/* Disable Hercules/CGA compatibility */
+	WREG_CRT(VGA_CRTC_MODE, 0x03);
+
+	WREG8(SEQ_INDEX, 0x7);
+	sr07 = RREG8(SEQ_DATA);
+	sr07 &= 0xe0;
+	hdr = 0;
+
+	cirrus->cpp = cirrus_cpp(fb);
+	switch (cirrus->cpp * 8) {
+	case 8:
+		sr07 |= 0x11;
+		break;
+	case 16:
+		sr07 |= 0x17;
+		hdr = 0xc1;
+		break;
+	case 24:
+		sr07 |= 0x15;
+		hdr = 0xc5;
+		break;
+	case 32:
+		sr07 |= 0x19;
+		hdr = 0xc5;
+		break;
+	default:
+		return -1;
+	}
+
+	WREG_SEQ(0x7, sr07);
+
+	/* Program the pitch */
+	cirrus->pitch = cirrus_pitch(fb);
+	tmp = cirrus->pitch / 8;
+	WREG_CRT(VGA_CRTC_OFFSET, tmp);
+
+	/* Enable extended blanking and pitch bits, and enable full memory */
+	tmp = 0x22;
+	tmp |= (cirrus->pitch >> 7) & 0x10;
+	tmp |= (cirrus->pitch >> 6) & 0x40;
+	WREG_CRT(0x1b, tmp);
+
+	/* Enable high-colour modes */
+	WREG_GFX(VGA_GFX_MODE, 0x40);
+
+	/* And set graphics mode */
+	WREG_GFX(VGA_GFX_MISC, 0x01);
+
+	WREG_HDR(hdr);
+	/* cirrus_crtc_do_set_base(crtc, old_fb, x, y, 0); */
+
+	/* Unblank (needed on S3 resume, vgabios doesn't do it then) */
+	outb(0x20, 0x3c0);
+	return 0;
+}
+
+static void cirrus_pipe_update(struct drm_simple_display_pipe *pipe,
+			       struct drm_plane_state *old_state)
+{
+	struct cirrus_device *cirrus = pipe->crtc.dev->dev_private;
+	struct drm_plane_state *state = pipe->plane.state;
+	struct drm_crtc *crtc = &pipe->crtc;
+	struct drm_rect rect;
+
+	if (pipe->plane.state->fb &&
+	    cirrus->cpp != cirrus_cpp(pipe->plane.state->fb))
+		cirrus_mode_set(cirrus, &crtc->mode,

drivers/gpu/drm/cirrus/cirrus.c

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus.c new file +10 -0
+				pipe->plane.state->fb);
+
+	if (drm_atomic_helper_damage_merged(old_state, state, &rect))
+		cirrus_fb_blit_rect(pipe->plane.state->fb, &rect);
+
+	if (crtc->state->event) {
+		spin_lock_irq(&crtc->dev->event_lock);
+		drm_crtc_send_vblank_event(crtc, crtc->state->event);
+		spin_unlock_irq(&crtc->dev->event_lock);
+		crtc->state->event = NULL;

Should you set crtc->state->event = NULL; before spin_unlock_irq()?

drivers/gpu/drm/cirrus/cirrus.c line 592

Quoted 6 lines
drivers/gpu/drm/cirrus/cirrus.c new file +6 -0
+
+/* only bind to the cirrus chip in qemu */
+static const struct pci_device_id pciidlist[] = {
+	{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
+	  PCI_SUBVENDOR_ID_REDHAT_QUMRANET, PCI_SUBDEVICE_ID_QEMU,
+	  0, 0, 0 },
	PCI_DEVICE_SUB(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
		       PCI_SUBVENDOR_ID_REDHAT_QUMRANET, PCI_SUBDEVICE_ID_QEMU)

????
Hmm, looks like an alternative way to say the same, that is hardly much improvement?!?

drivers/gpu/drm/cirrus/cirrus.c line 596

Quoted 4 lines
drivers/gpu/drm/cirrus/cirrus.c new file +4 -0
+	{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
+	  PCI_VENDOR_ID_XEN, 0x0001,
+	  0, 0, 0 },
+	{ /* end if list */}

Add space before final }

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