Skip to contentSkip to conversation

atomic modesetting for cirrus

PATCH In review Varad Gautam 3 participants 22 messages Aug 18, 2017 – Sep 5, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover atomic modesetting for cirrus

Hello,

This series converts drm/cirrus to support atomic modesetting for the emulated CL GD-54xx hw in qemu.

Patches 1-7 are general fixes and improvements, in preparation for atomic. Patch 8 provides dmabuf export for cirrus.
Patch 9-11 add universal primary plane support and rework the driver to use
atomic transition helpers for legacy modesetting.
Patch 12 moves away from legacy modesetting entirely to use atomic handlers. Patch 13 adds atomic cursor plane.
Patch 14 flips on DRIVER_ATOMIC.

I have tested this with igt and chromeos/drm-tests (details in patch 14).

Fun trivia from the GD-54xx TRM, 1996! It boasts 'optimized PCI burst write, which supports PCI writes to the frame buffer at greater than 55 Mbytes per second.'

Dominik Behr (1):
drm/cirrus: initialize start and size fields

Stéphane Marchesin (1):
drm/cirrus: Use 32bpp by default

Varad Gautam (10):
drm/cirrus: split out bo unpinning from cirrus_bo_push_sysram drm/cirrus: unregister connector on destroy drm/cirrus: add drm_read to cirrus_driver_fops drm/cirrus: do not disable outputs on fbdev init for atomic. drm/cirrus: use universal plane interfaces for primary plane drm/cirrus: use atomic transition helpers for plane and crtc drm/cirrus: send vblank on crtc atomic_flush drm/cirrus: use atomic handlers for plane and crtc drm/cirrus: implement atomic hardware cursor support drm/cirrus: advertise DRIVER_ATOMIC

Zach Reizner (2):
drm/cirrus: hardcode vram size
drm/cirrus: implement PRIME export for cirrus

 drivers/gpu/drm/cirrus/Makefile       |   2 +-
 drivers/gpu/drm/cirrus/cirrus_drv.c   |  17 +-
 drivers/gpu/drm/cirrus/cirrus_drv.h   |  25 ++
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |   6 +-
 drivers/gpu/drm/cirrus/cirrus_main.c  |  23 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c  | 681 ++++++++++++++++++++++++++--------
 drivers/gpu/drm/cirrus/cirrus_prime.c |  63 ++++
 drivers/gpu/drm/cirrus/cirrus_ttm.c   |  55 ++-
 8 files changed, 705 insertions(+), 167 deletions(-)
 create mode 100644 drivers/gpu/drm/cirrus/cirrus_prime.c

Thanks,
Varad

Signature · 6 lines
2.13.1

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

PATCH 1/14 drm/cirrus: split out bo unpinning from cirrus_bo_push_sysram

From: Varad Gautam <[email protected]>

add a cirrus_bo_unpin call, and move bo_{reserve,unreserve} operations to bo_{pin,unpin} to ensure correct pinning/unpinning and simplify the call sequence.

---
 drivers/gpu/drm/cirrus/cirrus_drv.h  |  1 +
 drivers/gpu/drm/cirrus/cirrus_mode.c | 14 ++-------
 drivers/gpu/drm/cirrus/cirrus_ttm.c  | 55 +++++++++++++++++++++++++++++-------
 3 files changed, 48 insertions(+), 22 deletions(-)
drivers/gpu/drm/cirrus/cirrus_drv.h +1 -0
index 8690352d96f7..8cdf6b0db4a7 100644
@@ -262,6 +262,7 @@ static inline void cirrus_bo_unreserve(struct cirrus_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);
+int cirrus_bo_unpin(struct cirrus_bo *bo);
 
 extern int cirrus_bpp;
 
drivers/gpu/drm/cirrus/cirrus_mode.c +2 -12
index 53f6f0f84206..21d75e7e4abc 100644
@@ -131,26 +131,17 @@ static int cirrus_crtc_do_set_base(struct drm_crtc *crtc,
 		cirrus_fb = to_cirrus_framebuffer(fb);
 		obj = cirrus_fb->obj;
 		bo = gem_to_cirrus_bo(obj);
-		ret = cirrus_bo_reserve(bo, false);
-		if (ret)
-			return ret;
+		cirrus_bo_unpin(bo);
 		cirrus_bo_push_sysram(bo);
-		cirrus_bo_unreserve(bo);
 	}
 
 	cirrus_fb = to_cirrus_framebuffer(crtc->primary->fb);
 	obj = cirrus_fb->obj;
 	bo = gem_to_cirrus_bo(obj);
 
-	ret = cirrus_bo_reserve(bo, false);
-	if (ret)
-		return ret;
-
 	ret = cirrus_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
-	if (ret) {
-		cirrus_bo_unreserve(bo);
+	if (ret)
 		return ret;
-	}
 
 	if (&cdev->mode_info.gfbdev->gfb == cirrus_fb) {
 		/* if pushing console in kmap it */
@@ -158,7 +149,6 @@ static int cirrus_crtc_do_set_base(struct drm_crtc *crtc,
 		if (ret)
 			DRM_ERROR("failed to kmap fbcon\n");
 	}
-	cirrus_bo_unreserve(bo);
 
 	cirrus_set_start_address(crtc, (u32)gpu_addr);
 	return 0;
drivers/gpu/drm/cirrus/cirrus_ttm.c +45 -10

90 lines not on this page · raw message

Signature · 6 lines
2.13.1

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

Re: [PATCH 01/14] drm/cirrus: split out bo unpinning from cirrus_bo_push_sysram

Quoted 7 lines · Varad Gautam

int cirrus_bo_push_sysram(struct cirrus_bo *bo)
{

drivers/gpu/drm/cirrus/cirrus_ttm.c +3 -1
 	int i, ret;
-	if (!bo->pin_count) {
+
+	ret = cirrus_bo_reserve(bo, false);
+	if (ret)

drivers/gpu/drm/cirrus/cirrus_ttm.c int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr) · line 391

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus_ttm.c +4 -4
+		return ret;
+
+	if (bo->pin_count) {
 		DRM_ERROR("unpin bad %p\n", bo);
-		return 0;
+		goto out;
 	}
-	bo->pin_count--;
-	if (bo->pin_count)
-		return 0;

Can you adjust this to also use your version of cirrus_bo_unpin()?

Also, If I'm not mistaken, this hunk unbalances pin_count, since you no longer decrement it after unpinning.

Quoted 18 lines
drivers/gpu/drm/cirrus/cirrus_ttm.c +5 -2
 	if (bo->kmap.virtual)
 		ttm_bo_kunmap(&bo->kmap);
@@ -400,9 +432,12 @@ int cirrus_bo_push_sysram(struct cirrus_bo *bo)
 	ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
 	if (ret) {
 		DRM_ERROR("pushing to VRAM failed\n");
-		return ret;
+		goto out;
 	}
-	return 0;
+
+out:
+	cirrus_bo_unreserve(bo);
+	return ret;
 }
 
 int cirrus_mmap(struct file *filp, struct vm_area_struct *vma)
Signature · 5 lines
Gabriel Krisman Bertazi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Re: [PATCH 01/14] drm/cirrus: split out bo unpinning from cirrus_bo_push_sysram

Hi Gabriel,

Quoted 23 lines · Gabriel Krisman Bertazi
Quoted 7 lines · Varad Gautam

int cirrus_bo_push_sysram(struct cirrus_bo *bo)

 {
      int i, ret;
drivers/gpu/drm/cirrus/cirrus_ttm.c +3 -1
-     if (!bo->pin_count) {
+
+     ret = cirrus_bo_reserve(bo, false);
+     if (ret)

drivers/gpu/drm/cirrus/cirrus_ttm.c int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr) · line 391

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus_ttm.c +4 -4
+             return ret;
+
+     if (bo->pin_count) {
              DRM_ERROR("unpin bad %p\n", bo);
-             return 0;
+             goto out;
      }
-     bo->pin_count--;
-     if (bo->pin_count)
-             return 0;

Can you adjust this to also use your version of cirrus_bo_unpin()?

Quoted 3 lines

Also, If I'm not mistaken, this hunk unbalances pin_count, since you no longer decrement it after unpinning.

Do you mean we also need to call bo_unpin() from push_sysram?

With this patch, we unpin immediately before calling push_sysram(), and only allow non-pinned bo-s to be moved to sysram (pin_count decrements in cirrus_bo_unpin preserving pinning state). With atomic handlers later (patch 10+), pin-unpin happens from prepare/cleanup_fb, and a later prepare_fb calls push_sysram() on the bo - so the pin_count maintains.

Thanks,
Varad

Quoted 17 lines
Quoted 17 lines
      if (bo->kmap.virtual)
              ttm_bo_kunmap(&bo->kmap);
drivers/gpu/drm/cirrus/cirrus_ttm.c +5 -2
@@ -400,9 +432,12 @@ int cirrus_bo_push_sysram(struct cirrus_bo *bo)
      ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
      if (ret) {
              DRM_ERROR("pushing to VRAM failed\n");
-             return ret;
+             goto out;
      }
-     return 0;
+
+out:
+     cirrus_bo_unreserve(bo);
+     return ret;
 }
 
Quoted 4 lines

drivers/gpu/drm/cirrus/cirrus_ttm.c int cirrus_bo_push_sysram(struct cirrus_bo *bo) · line 443

Quoted 1 line
drivers/gpu/drm/cirrus/cirrus_ttm.c +0 -0
 int cirrus_mmap(struct file *filp, struct vm_area_struct *vma)

--
Gabriel Krisman Bertazi

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

#4 lore raw

PATCH 2/14 drm/cirrus: unregister connector on destroy

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

add missing unregister call on connector destroy.

---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/cirrus/cirrus_mode.c +1 -0
index 21d75e7e4abc..6032978a2797 100644
@@ -492,6 +492,7 @@ static struct drm_encoder *cirrus_connector_best_encoder(struct drm_connector
 
 static void cirrus_connector_destroy(struct drm_connector *connector)
 {
+	drm_connector_unregister(connector);
 	drm_connector_cleanup(connector);
 	kfree(connector);
 }
Signature · 6 lines
2.13.1

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

Re: [PATCH 02/14] drm/cirrus: unregister connector on destroy

Discard this one, not needed in light of [1]:

"drm_dev_unregister unregisters all connectors too. Explicitly calling drm_connector_unregister should only be needed when you
a) screwed up your unload sequence. Get rid of ->unload and make sure you call drm_dev_unregister first to fix this properly
b) hot-unplug. Doesn't apply to cirrus."

[1] http://www.mail-archive.com/[email protected]/msg191644.html

Thanks,
Varad

Quoted 22 lines · Varad Gautam

From: Varad Gautam <[email protected]>

add missing unregister call on connector destroy.

---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/cirrus/cirrus_mode.c +1 -1
index 21d75e7e4abc..6032978a2797 100644
@@ -492,6 +492,7 @@ static struct drm_encoder *cirrus_connector_best_encoder(struct drm_connector
 
 static void cirrus_connector_destroy(struct drm_connector *connector)
 {
+       drm_connector_unregister(connector);
        drm_connector_cleanup(connector);
        kfree(connector);
 }
--
Quoted 2 lines

2.13.1

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

#6 lore raw

PATCH 3/14 drm/cirrus: add drm_read to cirrus_driver_fops

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

allow reading the drm file from userspace.

---
 drivers/gpu/drm/cirrus/cirrus_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/cirrus/cirrus_drv.c +1 -0
index d893ea21a359..bae34f5c2c02 100644
@@ -122,6 +122,7 @@ static int cirrus_pm_resume(struct device *dev)
 static const struct file_operations cirrus_driver_fops = {
 	.owner = THIS_MODULE,
 	.open = drm_open,
+	.read = drm_read,
 	.release = drm_release,
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = cirrus_mmap,
Signature · 6 lines
2.13.1

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

PATCH 4/14 drm/cirrus: do not disable outputs on fbdev init for atomic.

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

drm_helper_disable_unused_functions should not be called by atomic drivers, so disable it for later patches.

---
 drivers/gpu/drm/cirrus/cirrus_fbdev.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/cirrus/cirrus_fbdev.c +0 -3
index 7fa58eeadc9d..ed96dae1c205 100644
@@ -296,9 +296,6 @@ int cirrus_fbdev_init(struct cirrus_device *cdev)
 	if (ret)
 		return ret;
 
-	/* disable all the possible outputs/crtcs before entering KMS mode */
-	drm_helper_disable_unused_functions(cdev->dev);
-
 	return drm_fb_helper_initial_config(&gfbdev->helper, bpp_sel);
 }
 
Signature · 6 lines
2.13.1

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

PATCH 5/14 drm/cirrus: initialize start and size fields

In reply to Varad Gautam

From: Dominik Behr <[email protected]>

initialize start and size fields in fb info so user space drivers like fbdev can map the memory

cherry-pick from 3.14 to 3.18 kernel to let VMtest pass

dmesg now shows proper size and fb start

initially reviewed for chromiumos at:
https://chromium-review.googlesource.com/167396
https://chromium-review.googlesource.com/282933
https://chromium-review.googlesource.com/339092

---
 drivers/gpu/drm/cirrus/cirrus_fbdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/cirrus/cirrus_fbdev.c +3 -0
index ed96dae1c205..4bc7d8f60e97 100644
@@ -232,6 +232,9 @@ static int cirrusfb_create(struct drm_fb_helper *helper,
 	info->screen_base = sysram;
 	info->screen_size = size;
 
+	info->fix.smem_start = cdev->dev->mode_config.fb_base;
+	info->fix.smem_len = size;
+
 	info->fix.mmio_start = 0;
 	info->fix.mmio_len = 0;
 
Signature · 6 lines
2.13.1

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

PATCH 6/14 drm/cirrus: Use 32bpp by default

In reply to Varad Gautam

From: Stéphane Marchesin <[email protected]>

initially reviewed for ChromiumOS at:
https://chromium-review.googlesource.com/339093

---
 drivers/gpu/drm/cirrus/cirrus_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/cirrus/cirrus_drv.c +2 -2
index bae34f5c2c02..dfaeea92d344 100644
@@ -16,11 +16,11 @@
 #include "cirrus_drv.h"
 
 int cirrus_modeset = -1;
-int cirrus_bpp = 24;
+int cirrus_bpp = 32;
 
 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
 module_param_named(modeset, cirrus_modeset, int, 0400);
-MODULE_PARM_DESC(bpp, "Max bits-per-pixel (default:24)");
+MODULE_PARM_DESC(bpp, "Max bits-per-pixel (default:32)");
 module_param_named(bpp, cirrus_bpp, int, 0400);
 
 /*
Signature · 6 lines
2.13.1

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

Re: [PATCH 06/14] drm/cirrus: Use 32bpp by default

Quoted 5 lines · Varad Gautam

From: Stéphane Marchesin <[email protected]>

initially reviewed for ChromiumOS at:
https://chromium-review.googlesource.com/339093

1280x1024x24 fits in 4MB, 1280x1024x32 doesn't. That seems like it's going to be a visible change in behaviour.

Signature · 5 lines
Matthew Garrett | [email protected]
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw

Re: [PATCH 06/14] drm/cirrus: Use 32bpp by default

Hi Matthew,

Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Varad Gautam

From: Stéphane Marchesin <[email protected]>

initially reviewed for ChromiumOS at:
https://chromium-review.googlesource.com/339093

1280x1024x24 fits in 4MB, 1280x1024x32 doesn't. That seems like it's going to be a visible change in behaviour.

Right, 800x600 is the highest we can go for >24bpp, so we now switch to that instead of 1280x1024. fb creation fails in cirrus_check_framebuffer if the w*h*bpp doesn't fit, and plane updates get rejected when atomic is enabled later on.

Regards,
Varad

Quoted 2 lines

--
Matthew Garrett | [email protected]

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

#12 lore raw

Re: [PATCH 06/14] drm/cirrus: Use 32bpp by default

Quoted 10 lines · Varad Gautam

Hi Matthew,

Quoted 7 lines · Matthew Garrett
Quoted 5 lines · Varad Gautam

From: Stéphane Marchesin <[email protected]>

initially reviewed for ChromiumOS at:
https://chromium-review.googlesource.com/339093

Quoted 8 lines
Quoted 3 lines

1280x1024x24 fits in 4MB, 1280x1024x32 doesn't. That seems like it's going to be a visible change in behaviour.

Right, 800x600 is the highest we can go for >24bpp, so we now switch to that instead of 1280x1024. fb creation fails in cirrus_check_framebuffer if the w*h*bpp doesn't fit, and plane updates get rejected when atomic is enabled later on.

So users who want 1280x1024 now have to change their configuration. Is that the intent? It seems odd to change user-visible behaviour for everyone just to fix ChromeOS in a VM.

Signature · 5 lines
Matthew Garrett | [email protected]
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#13 lore raw

PATCH 7/14 drm/cirrus: hardcode vram size

In reply to Varad Gautam

From: Zach Reizner <[email protected]>

There is no reliable way of detecting actual VRAM size, which is important in the case of cirrus because cursor data is always stored in the last 16K of VRAM. Because qemu effectivaly hardcodes 4MB but reports 32MB, we hardcode 4MB in the cirrus driver to ensure the cursor works properly.

initially reviewed at: https://chromium-review.googlesource.com/411344

CC Stéphane Marchesin <[email protected]>
---
 drivers/gpu/drm/cirrus/cirrus_main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/cirrus/cirrus_main.c +6 -1
index e7fc95f63dca..c92ccb00db62 100644
@@ -98,7 +98,12 @@ static int cirrus_vram_init(struct cirrus_device *cdev)
 {
 	/* BAR 0 is VRAM */
 	cdev->mc.vram_base = pci_resource_start(cdev->dev->pdev, 0);
-	cdev->mc.vram_size = pci_resource_len(cdev->dev->pdev, 0);
+
+	/*
+	 * While we can use the entire PCI bar for VRAM, qemu always expects to
+	 * find the cursor data at the 4M - 16K point.
+	 */
+	cdev->mc.vram_size = 4 * 1024 * 1024;
 
 	if (!request_mem_region(cdev->mc.vram_base, cdev->mc.vram_size,
 				"cirrusdrmfb_vram")) {
Signature · 6 lines
2.13.1

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

PATCH 8/14 drm/cirrus: implement PRIME export for cirrus

In reply to Varad Gautam

From: Zach Reizner <[email protected]>

This patch implements PRIME export, but not import for cirrus.

initially reviewed at:
https://chromium-review.googlesource.com/229688
https://chromium-review.googlesource.com/339057

---
 drivers/gpu/drm/cirrus/Makefile       |  2 +-
 drivers/gpu/drm/cirrus/cirrus_drv.c   | 11 +++++-
 drivers/gpu/drm/cirrus/cirrus_drv.h   | 10 ++++++
 drivers/gpu/drm/cirrus/cirrus_prime.c | 63 +++++++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/cirrus/cirrus_prime.c
drivers/gpu/drm/cirrus/Makefile +1 -1
index 919c0a336c97..f6bcc21454c6 100644
@@ -1,4 +1,4 @@
 cirrus-y  := cirrus_main.o cirrus_mode.o \
-	cirrus_drv.o cirrus_fbdev.o cirrus_ttm.o
+	cirrus_drv.o cirrus_fbdev.o cirrus_ttm.o cirrus_prime.o
 
 obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus.o
drivers/gpu/drm/cirrus/cirrus_drv.c +10 -1
index dfaeea92d344..dca7a3f4791d 100644
@@ -130,7 +130,7 @@ static const struct file_operations cirrus_driver_fops = {
 	.compat_ioctl = drm_compat_ioctl,
 };
 static struct drm_driver driver = {
-	.driver_features = DRIVER_MODESET | DRIVER_GEM,
+	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
 	.load = cirrus_driver_load,
 	.unload = cirrus_driver_unload,
 	.set_busid = drm_pci_set_busid,
@@ -145,6 +145,15 @@ static struct drm_driver driver = {
 	.dumb_create = cirrus_dumb_create,
 	.dumb_map_offset = cirrus_dumb_mmap_offset,
 	.dumb_destroy = drm_gem_dumb_destroy,
+	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
+	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+	.gem_prime_export = drm_gem_prime_export,
+	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_pin = cirrus_gem_prime_pin,
+	.gem_prime_get_sg_table = cirrus_gem_prime_get_sg_table,
+	.gem_prime_import_sg_table = cirrus_gem_prime_import_sg_table,
+	.gem_prime_vmap = cirrus_gem_prime_vmap,
+	.gem_prime_vunmap = cirrus_gem_prime_vunmap,
 };
 
 static const struct dev_pm_ops cirrus_pm_ops = {
drivers/gpu/drm/cirrus/cirrus_drv.h +10 -0
index 8cdf6b0db4a7..29de4f0dbd01 100644
@@ -164,6 +164,7 @@ struct cirrus_bo {
 	struct ttm_buffer_object bo;
 	struct ttm_placement placement;
 	struct ttm_bo_kmap_obj kmap;
+	struct ttm_bo_kmap_obj dma_buf_vmap;
 	struct drm_gem_object gem;
 	struct ttm_place placements[3];
 	int pin_count;
@@ -264,6 +265,15 @@ int cirrus_bo_push_sysram(struct cirrus_bo *bo);
 int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
 int cirrus_bo_unpin(struct cirrus_bo *bo);
 
+struct sg_table *cirrus_gem_prime_get_sg_table(struct drm_gem_object *obj);
+void *cirrus_gem_prime_vmap(struct drm_gem_object *obj);
+void cirrus_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
+struct drm_gem_object *cirrus_gem_prime_import_sg_table(
+				struct drm_device *dev,
+				struct dma_buf_attachment *attach,
+				struct sg_table *sgt);
+int cirrus_gem_prime_pin(struct drm_gem_object *obj);
+
 extern int cirrus_bpp;
 
 #endif				/* __CIRRUS_DRV_H__ */
drivers/gpu/drm/cirrus/cirrus_prime.c new file +63 -0

63 lines not on this page · raw message

Signature · 6 lines
2.13.1

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

PATCH 9/14 drm/cirrus: use universal plane interfaces for primary plane

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

cirrus exposes one legacy primary plane tied to the crtc. convert this to use the universal planes interface in preparation for atomic.

---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 44 ++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)
drivers/gpu/drm/cirrus/cirrus_mode.c +42 -2
index 6032978a2797..2994dd391850 100644
@@ -358,12 +358,29 @@ static const struct drm_crtc_helper_funcs cirrus_helper_funcs = {
 	.load_lut = cirrus_crtc_load_lut,
 };
 
+static const uint32_t cirrus_plane_formats[] = {
+	DRM_FORMAT_XRGB8888,
+	DRM_FORMAT_ARGB8888,
+	DRM_FORMAT_RGB888,
+	DRM_FORMAT_RGB565,
+};
+
+static const struct drm_plane_funcs cirrus_plane_funcs = {
+	.update_plane	= drm_primary_helper_update,
+	.disable_plane	= drm_primary_helper_disable,
+	.destroy	= drm_primary_helper_destroy,
+};
+
+static const struct drm_plane_helper_funcs cirrus_plane_helper_funcs = {
+};
+
 /* CRTC setup */
 static void cirrus_crtc_init(struct drm_device *dev)
 {
 	struct cirrus_device *cdev = dev->dev_private;
 	struct cirrus_crtc *cirrus_crtc;
-	int i;
+	struct drm_plane *primary;
+	int i, ret;
 
 	cirrus_crtc = kzalloc(sizeof(struct cirrus_crtc) +
 			      (CIRRUSFB_CONN_LIMIT * sizeof(struct drm_connector *)),
@@ -372,8 +389,23 @@ static void cirrus_crtc_init(struct drm_device *dev)
 	if (cirrus_crtc == NULL)
 		return;
 
-	drm_crtc_init(dev, &cirrus_crtc->base, &cirrus_crtc_funcs);
+	primary = kzalloc(sizeof(*primary), GFP_KERNEL);
+	if (primary == NULL)
+		goto cleanup_crtc;
 
+	drm_plane_helper_add(primary, &cirrus_plane_helper_funcs);
+	ret = drm_universal_plane_init(dev, primary, 1,
+				       &cirrus_plane_funcs,
+				       cirrus_plane_formats,
+				       ARRAY_SIZE(cirrus_plane_formats),
+				       DRM_PLANE_TYPE_PRIMARY, NULL);
+	if (ret)
+		goto cleanup;
+
+	ret = drm_crtc_init_with_planes(dev, &cirrus_crtc->base, primary, NULL,
+					&cirrus_crtc_funcs, NULL);
+	if (ret)
+		goto cleanup;
 	drm_mode_crtc_set_gamma_size(&cirrus_crtc->base, CIRRUS_LUT_SIZE);
 	cdev->mode_info.crtc = cirrus_crtc;
 
@@ -384,6 +416,14 @@ static void cirrus_crtc_init(struct drm_device *dev)
 	}
 
 	drm_crtc_helper_add(&cirrus_crtc->base, &cirrus_helper_funcs);
+	return;
+
+cleanup:
+	drm_plane_cleanup(primary);
+	kfree(primary);
+cleanup_crtc:
+	kfree(cirrus_crtc);
+	return;
 }
 
 /** Sets the color ramps on behalf of fbcon */
Signature · 6 lines
2.13.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 9/14
#16 lore raw

Re: [PATCH 09/14] drm/cirrus: use universal plane interfaces for primary plane

Quoted 52 lines · Varad Gautam

From: Varad Gautam <[email protected]>

cirrus exposes one legacy primary plane tied to the crtc. convert this to use the universal planes interface in preparation for atomic.

---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 44 ++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)
drivers/gpu/drm/cirrus/cirrus_mode.c +20 -2
index 6032978a2797..2994dd391850 100644
@@ -358,12 +358,29 @@ static const struct drm_crtc_helper_funcs cirrus_helper_funcs = {
 	.load_lut = cirrus_crtc_load_lut,
 };
 
+static const uint32_t cirrus_plane_formats[] = {
+	DRM_FORMAT_XRGB8888,
+	DRM_FORMAT_ARGB8888,
+	DRM_FORMAT_RGB888,
+	DRM_FORMAT_RGB565,
+};
+
+static const struct drm_plane_funcs cirrus_plane_funcs = {
+	.update_plane	= drm_primary_helper_update,
+	.disable_plane	= drm_primary_helper_disable,
+	.destroy	= drm_primary_helper_destroy,
+};
+
+static const struct drm_plane_helper_funcs cirrus_plane_helper_funcs = {
+};
+
 /* CRTC setup */
 static void cirrus_crtc_init(struct drm_device *dev)
 {
 	struct cirrus_device *cdev = dev->dev_private;
 	struct cirrus_crtc *cirrus_crtc;
-	int i;
+	struct drm_plane *primary;
+	int i, ret;
 
 	cirrus_crtc = kzalloc(sizeof(struct cirrus_crtc) +
 			      (CIRRUSFB_CONN_LIMIT * sizeof(struct drm_connector *)),
@@ -372,8 +389,23 @@ static void cirrus_crtc_init(struct drm_device *dev)
 	if (cirrus_crtc == NULL)
 		return;
 
-	drm_crtc_init(dev, &cirrus_crtc->base, &cirrus_crtc_funcs);
+	primary = kzalloc(sizeof(*primary), GFP_KERNEL);
+	if (primary == NULL)

drivers/gpu/drm/cirrus/cirrus_mode.c static void cirrus_crtc_init(struct drm_device *dev) · line 403

Quoted 10 lines
drivers/gpu/drm/cirrus/cirrus_mode.c +9 -0
+		goto cleanup_crtc;
 
+	drm_plane_helper_add(primary, &cirrus_plane_helper_funcs);
+	ret = drm_universal_plane_init(dev, primary, 1,
+				       &cirrus_plane_funcs,
+				       cirrus_plane_formats,
+				       ARRAY_SIZE(cirrus_plane_formats),
+				       DRM_PLANE_TYPE_PRIMARY, NULL);
+	if (ret)
+		goto cleanup;

If this fails early enough, you can't call drm_plane_cleanup, otherwise you'll hit an oops.

Otherwise, looks good. with the above change, please add:

Quoted 23 lines
drivers/gpu/drm/cirrus/cirrus_mode.c +13 -0
+
+	ret = drm_crtc_init_with_planes(dev, &cirrus_crtc->base, primary, NULL,
+					&cirrus_crtc_funcs, NULL);
+	if (ret)
+		goto cleanup;
 	drm_mode_crtc_set_gamma_size(&cirrus_crtc->base, CIRRUS_LUT_SIZE);
 	cdev->mode_info.crtc = cirrus_crtc;
 
@@ -384,6 +416,14 @@ static void cirrus_crtc_init(struct drm_device *dev)
 	}
 
 	drm_crtc_helper_add(&cirrus_crtc->base, &cirrus_helper_funcs);
+	return;
+
+cleanup:
+	drm_plane_cleanup(primary);
+	kfree(primary);
+cleanup_crtc:
+	kfree(cirrus_crtc);
+	return;
 }
 
 /** Sets the color ramps on behalf of fbcon */
Signature · 5 lines
Gabriel Krisman Bertazi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#17 lore raw

PATCH 10/14 drm/cirrus: use atomic transition helpers for plane and crtc

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

split the driver to fit into atomic semantics, and switch to using the atomic transition layer helpers for legacy modesetting.

---
 drivers/gpu/drm/cirrus/cirrus_drv.h  |   1 +
 drivers/gpu/drm/cirrus/cirrus_main.c |   3 +
 drivers/gpu/drm/cirrus/cirrus_mode.c | 350 ++++++++++++++++++++++-------------
 3 files changed, 227 insertions(+), 127 deletions(-)
drivers/gpu/drm/cirrus/cirrus_drv.h +1 -0
index 29de4f0dbd01..d680815f23e6 100644
@@ -168,6 +168,7 @@ struct cirrus_bo {
 	struct drm_gem_object gem;
 	struct ttm_place placements[3];
 	int pin_count;
+	u64 gpu_addr;
 };
 #define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
 
drivers/gpu/drm/cirrus/cirrus_main.c +3 -0
index c92ccb00db62..7d0431bbc6e3 100644
@@ -9,6 +9,7 @@
  *          Dave Airlie
  */
 #include <drm/drmP.h>
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc_helper.h>
 
 #include "cirrus_drv.h"
@@ -82,6 +83,8 @@ cirrus_user_framebuffer_create(struct drm_device *dev,
 
 static const struct drm_mode_config_funcs cirrus_mode_funcs = {
 	.fb_create = cirrus_user_framebuffer_create,
+	.atomic_check = drm_atomic_helper_check,
+	.atomic_commit = drm_atomic_helper_commit,
 };
 
 /* Unmap the framebuffer from the core and release the memory */
drivers/gpu/drm/cirrus/cirrus_mode.c +223 -127

419 lines not on this page · raw message

Signature · 6 lines
2.13.1

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

PATCH 11/14 drm/cirrus: send vblank on crtc atomic_flush

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

the hardware does not provide interrupts on vblank, so we just send a fake vblank event on atomic_flush.

---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/gpu/drm/cirrus/cirrus_mode.c +18 -0
index eda3c4d18b37..e777157fe474 100644
@@ -226,6 +226,23 @@ static void cirrus_crtc_destroy(struct drm_crtc *crtc)
 	kfree(cirrus_crtc);
 }
 
+static void cirrus_crtc_atomic_flush(struct drm_crtc *crtc,
+				     struct drm_crtc_state *old_crtc_state)
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_pending_vblank_event *event;
+	unsigned long flags;
+
+	if (crtc->state && crtc->state->event) {
+		event = crtc->state->event;
+		crtc->state->event = NULL;
+
+		spin_lock_irqsave(&dev->event_lock, flags);
+		drm_crtc_send_vblank_event(crtc, event);
+		spin_unlock_irqrestore(&dev->event_lock, flags);
+	}
+}
+
 /* These provide the minimum set of functions required to handle a CRTC */
 static const struct drm_crtc_funcs cirrus_crtc_funcs = {
 	.gamma_set = cirrus_crtc_gamma_set,
@@ -244,6 +261,7 @@ static const struct drm_crtc_helper_funcs cirrus_helper_funcs = {
 	.prepare = cirrus_crtc_prepare,
 	.commit = cirrus_crtc_commit,
 	.load_lut = cirrus_crtc_load_lut,
+	.atomic_flush = cirrus_crtc_atomic_flush,
 };
 
 static int cirrus_plane_update(struct drm_plane *plane,
Signature · 6 lines
2.13.1

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

PATCH 12/14 drm/cirrus: use atomic handlers for plane and crtc

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

move from transition helpers to actual atomic handlers.

---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
drivers/gpu/drm/cirrus/cirrus_mode.c +4 -27
index e777157fe474..39bea39a565e 100644
@@ -179,15 +179,6 @@ static void cirrus_mode_set_nofb(struct drm_crtc *crtc)
 }
 
 /*
- * This is called before a mode is programmed. A typical use might be to
- * enable DPMS during the programming to avoid seeing intermediate stages,
- * but that's not relevant to us
- */
-static void cirrus_crtc_prepare(struct drm_crtc *crtc)
-{
-}
-
-/*
  * This is called after a mode is programmed. It should reverse anything done
  * by the prepare function
  */
@@ -246,8 +237,10 @@ static void cirrus_crtc_atomic_flush(struct drm_crtc *crtc,
 /* These provide the minimum set of functions required to handle a CRTC */
 static const struct drm_crtc_funcs cirrus_crtc_funcs = {
 	.gamma_set = cirrus_crtc_gamma_set,
-	.set_config = drm_crtc_helper_set_config,
+	.set_config = drm_atomic_helper_set_config,
+	.set_property = drm_atomic_helper_crtc_set_property,
 	.destroy = cirrus_crtc_destroy,
+	.page_flip = drm_atomic_helper_page_flip,
 	.reset = drm_atomic_helper_crtc_reset,
 	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
@@ -255,28 +248,12 @@ static const struct drm_crtc_funcs cirrus_crtc_funcs = {
 
 static const struct drm_crtc_helper_funcs cirrus_helper_funcs = {
 	.dpms = cirrus_crtc_dpms,
-	.mode_set = drm_helper_crtc_mode_set,
-	.mode_set_base = drm_helper_crtc_mode_set_base,
 	.mode_set_nofb = cirrus_mode_set_nofb,
-	.prepare = cirrus_crtc_prepare,
 	.commit = cirrus_crtc_commit,
 	.load_lut = cirrus_crtc_load_lut,
 	.atomic_flush = cirrus_crtc_atomic_flush,
 };
 
-static int cirrus_plane_update(struct drm_plane *plane,
-			       struct drm_crtc *crtc,
-			       struct drm_framebuffer *fb, int crtc_x,
-			       int crtc_y, unsigned int crtc_w,
-			       unsigned int crtc_h, uint32_t src_x,
-			       uint32_t src_y, uint32_t src_w, uint32_t src_h,
-			       struct drm_modeset_acquire_ctx *ctx)
-{
-	return drm_plane_helper_update(plane, crtc, fb,
-				       crtc_x, crtc_y, crtc_w,
-				       crtc_h, src_x, src_y, src_w, src_h);
-}
-
 static const uint32_t cirrus_plane_formats[] = {
 	DRM_FORMAT_XRGB8888,
 	DRM_FORMAT_ARGB8888,
@@ -285,7 +262,7 @@ static const uint32_t cirrus_plane_formats[] = {
 };
 
 static const struct drm_plane_funcs cirrus_plane_funcs = {
-	.update_plane	= cirrus_plane_update,
+	.update_plane	= drm_atomic_helper_update_plane,
 	.disable_plane	= drm_primary_helper_disable,
 	.destroy	= drm_primary_helper_destroy,
 	.reset	= drm_atomic_helper_plane_reset,
Signature · 6 lines
2.13.1

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

PATCH 13/14 drm/cirrus: implement atomic hardware cursor support

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

This enables cursor plane on cirrus. It only supports ARGB 8-bit cursors from userspace, and downconverts them to 1-bit black and white with masking, which is all cirrus hardware can support. Only cursors with size 32x32 or 64x64 will work.

initial non-atomic version:
Reviewed-at:
https://chromium-review.googlesource.com/335579
https://chromium-review.googlesource.com/339091

CC Haixia Shi <[email protected]>
CC Stéphane Marchesin <[email protected]>
---
 drivers/gpu/drm/cirrus/cirrus_drv.h  |  13 ++
 drivers/gpu/drm/cirrus/cirrus_main.c |  13 ++
 drivers/gpu/drm/cirrus/cirrus_mode.c | 281 +++++++++++++++++++++++++++++++++--
 3 files changed, 297 insertions(+), 10 deletions(-)
drivers/gpu/drm/cirrus/cirrus_drv.h +13 -0
index d680815f23e6..fbd76c4e6d57 100644
@@ -50,6 +50,17 @@
 		WREG8(SEQ_DATA, v);				\
 	} while (0)						\
 
+#define PAL_ADDR 8
+#define PAL_DATA 9
+
+#define WREG_PAL(addr, r, g, b)				\
+	do {							\
+		WREG8(PAL_ADDR, addr);				\
+		WREG8(PAL_DATA, r);				\
+		WREG8(PAL_DATA, g);				\
+		WREG8(PAL_DATA, b);				\
+	} while (0)						\
+
 #define CRT_INDEX 0x14
 #define CRT_DATA 0x15
 
@@ -137,6 +148,8 @@ struct cirrus_device {
 	void __iomem			*rmmio;
 
 	struct cirrus_mc			mc;
+	resource_size_t			cursor_ram_size;
+	void __iomem			*cursor_iomem;
 	struct cirrus_mode_info		mode_info;
 
 	int				num_crtc;
drivers/gpu/drm/cirrus/cirrus_main.c +13 -0
index 7d0431bbc6e3..20229b13d6d2 100644
@@ -94,6 +94,8 @@ static void cirrus_vram_fini(struct cirrus_device *cdev)
 	cdev->rmmio = NULL;
 	if (cdev->mc.vram_base)
 		release_mem_region(cdev->mc.vram_base, cdev->mc.vram_size);
+	if (cdev->cursor_iomem)
+		iounmap(cdev->cursor_iomem);
 }
 
 /* Map the framebuffer from the card and configure the core */
@@ -107,12 +109,23 @@ static int cirrus_vram_init(struct cirrus_device *cdev)
 	 * find the cursor data at the 4M - 16K point.
 	 */
 	cdev->mc.vram_size = 4 * 1024 * 1024;
+	/* The last 16K of VRAM is for cursor */
+	cdev->cursor_ram_size = 16 * 1024;
 
 	if (!request_mem_region(cdev->mc.vram_base, cdev->mc.vram_size,
 				"cirrusdrmfb_vram")) {
 		DRM_ERROR("can't reserve VRAM\n");
 		return -ENXIO;
 	}
+	cdev->cursor_iomem = ioremap_nocache(cdev->mc.vram_base +
+					     cdev->mc.vram_size -
+					     cdev->cursor_ram_size,
+					     cdev->cursor_ram_size);
+	if (!cdev->cursor_iomem) {
+		release_mem_region(cdev->mc.vram_base, cdev->mc.vram_size);
+		DRM_ERROR("can't ioremap cursor VRAM\n");
+		return -ENXIO;
+	}
 
 	return 0;
 }
drivers/gpu/drm/cirrus/cirrus_mode.c +271 -10

314 lines not on this page · raw message

Signature · 6 lines
2.13.1

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

PATCH 14/14 drm/cirrus: advertise DRIVER_ATOMIC

In reply to Varad Gautam

From: Varad Gautam <[email protected]>

allow userspace to use atomic ioctls.

we now pass the following tests:
igt/kms_atomic_transition:
plane-all-transition
plane-use-after-nonblocking-unbind
plane-all-modeset-transition
plane-toggle-modeset-transition
1x-modeset-transitions
1x-modeset-transitions-nonblocking
igt/kms_atomic:
plane_primary_legacy
test_only
plane_cursor_legacy
plane_invalid_params
crtc_invalid_params
igt/kms_setmode
igt/kms_rmfb
drm-tests/atomictest:
disable_primary
fullscreen_video
overlay_pageflip
primary_pageflip
video_overlay

---
 drivers/gpu/drm/cirrus/cirrus_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/cirrus/cirrus_drv.c +2 -1
index dca7a3f4791d..1e9878103a38 100644
@@ -130,7 +130,8 @@ static const struct file_operations cirrus_driver_fops = {
 	.compat_ioctl = drm_compat_ioctl,
 };
 static struct drm_driver driver = {
-	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
+	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
+			DRIVER_ATOMIC,
 	.load = cirrus_driver_load,
 	.unload = cirrus_driver_unload,
 	.set_busid = drm_pci_set_busid,
Signature · 6 lines
2.13.1

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