From: Varad Gautam <varadgautam@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Stphane Marchesin <marcheu@chromium.org>,
Zach Reizner <zachr@chromium.org>,
Varad Gautam <varad.gautam@collabora.com>
Subject: [PATCH 08/14] drm/cirrus: implement PRIME export for cirrus
Date: Fri, 18 Aug 2017 21:19:13 +0530 [thread overview]
Message-ID: <20170818154919.18607-9-varadgautam@gmail.com> (raw)
In-Reply-To: <20170818154919.18607-1-varadgautam@gmail.com>
From: Zach Reizner <zachr@chromium.org>
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
Signed-off-by: Zach Reizner <zachr@chromium.org>
Signed-off-by: Stphane Marchesin <marcheu@chromium.org>
Signed-off-by: Varad Gautam <varad.gautam@collabora.com>
---
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
diff --git a/drivers/gpu/drm/cirrus/Makefile b/drivers/gpu/drm/cirrus/Makefile
index 919c0a336c97..f6bcc21454c6 100644
--- a/drivers/gpu/drm/cirrus/Makefile
+++ b/drivers/gpu/drm/cirrus/Makefile
@@ -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
diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.c b/drivers/gpu/drm/cirrus/cirrus_drv.c
index dfaeea92d344..dca7a3f4791d 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.c
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.c
@@ -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 = {
diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h
index 8cdf6b0db4a7..29de4f0dbd01 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.h
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.h
@@ -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__ */
diff --git a/drivers/gpu/drm/cirrus/cirrus_prime.c b/drivers/gpu/drm/cirrus/cirrus_prime.c
new file mode 100644
index 000000000000..a7fe6c73bfb6
--- /dev/null
+++ b/drivers/gpu/drm/cirrus/cirrus_prime.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2014 The Chromium OS Authors
+ *
+ * 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.
+ *
+ */
+
+#include <drm/ttm/ttm_page_alloc.h>
+#include <drm/drmP.h>
+#include "cirrus_drv.h"
+
+struct sg_table *cirrus_gem_prime_get_sg_table(struct drm_gem_object *obj)
+{
+ struct cirrus_bo *cirrusbo = gem_to_cirrus_bo(obj);
+ unsigned long npages = cirrusbo->bo.num_pages;
+
+ return drm_prime_pages_to_sg(cirrusbo->bo.ttm->pages, npages);
+}
+
+void *cirrus_gem_prime_vmap(struct drm_gem_object *obj)
+{
+ struct cirrus_bo *cirrusbo = gem_to_cirrus_bo(obj);
+ int ret;
+
+ ret = ttm_bo_kmap(&cirrusbo->bo, 0, cirrusbo->bo.num_pages,
+ &cirrusbo->dma_buf_vmap);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return cirrusbo->dma_buf_vmap.virtual;
+}
+
+void cirrus_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
+{
+ struct cirrus_bo *cirrusbo = gem_to_cirrus_bo(obj);
+
+ ttm_bo_kunmap(&cirrusbo->dma_buf_vmap);
+}
+
+struct drm_gem_object *cirrus_gem_prime_import_sg_table(
+ struct drm_device *dev,
+ struct dma_buf_attachment *attach,
+ struct sg_table *sgt)
+{
+ return NULL;
+}
+
+int cirrus_gem_prime_pin(struct drm_gem_object *obj)
+{
+ struct cirrus_bo *cirrusbo = gem_to_cirrus_bo(obj);
+ int ret = 0;
+
+ ret = cirrus_bo_pin(cirrusbo, TTM_PL_FLAG_SYSTEM, NULL);
+ if (ret)
+ goto out;
+
+ ttm_pool_populate(cirrusbo->bo.ttm);
+
+out:
+ return ret;
+}
--
2.13.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-08-18 15:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-18 15:49 [PATCH 00/14] atomic modesetting for cirrus Varad Gautam
2017-08-18 15:49 ` [PATCH 01/14] drm/cirrus: split out bo unpinning from cirrus_bo_push_sysram Varad Gautam
2017-09-04 10:41 ` Gabriel Krisman Bertazi
2017-09-05 13:04 ` Varad Gautam
2017-08-18 15:49 ` [PATCH 02/14] drm/cirrus: unregister connector on destroy Varad Gautam
2017-08-19 6:10 ` Varad Gautam
2017-08-18 15:49 ` [PATCH 03/14] drm/cirrus: add drm_read to cirrus_driver_fops Varad Gautam
2017-08-18 15:49 ` [PATCH 04/14] drm/cirrus: do not disable outputs on fbdev init for atomic Varad Gautam
2017-08-18 15:49 ` [PATCH 05/14] drm/cirrus: initialize start and size fields Varad Gautam
2017-08-18 15:49 ` [PATCH 06/14] drm/cirrus: Use 32bpp by default Varad Gautam
2017-08-19 8:32 ` Matthew Garrett
2017-08-23 15:40 ` Varad Gautam
2017-08-23 17:38 ` Matthew Garrett
2017-08-18 15:49 ` [PATCH 07/14] drm/cirrus: hardcode vram size Varad Gautam
2017-08-18 15:49 ` Varad Gautam [this message]
2017-08-18 15:49 ` [PATCH 09/14] drm/cirrus: use universal plane interfaces for primary plane Varad Gautam
2017-09-04 11:14 ` Gabriel Krisman Bertazi
2017-08-18 15:49 ` [PATCH 10/14] drm/cirrus: use atomic transition helpers for plane and crtc Varad Gautam
2017-08-18 15:49 ` [PATCH 11/14] drm/cirrus: send vblank on crtc atomic_flush Varad Gautam
2017-08-18 15:49 ` [PATCH 12/14] drm/cirrus: use atomic handlers for plane and crtc Varad Gautam
2017-08-18 15:49 ` [PATCH 13/14] drm/cirrus: implement atomic hardware cursor support Varad Gautam
2017-08-18 15:49 ` [PATCH 14/14] drm/cirrus: advertise DRIVER_ATOMIC Varad Gautam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170818154919.18607-9-varadgautam@gmail.com \
--to=varadgautam@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=marcheu@chromium.org \
--cc=varad.gautam@collabora.com \
--cc=zachr@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox