From: Zach Reizner <zachr@xxxxxxxxxxxx> 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@xxxxxxxxxxxx> Signed-off-by: Stphane Marchesin <marcheu@xxxxxxxxxxxx> Signed-off-by: Varad Gautam <varad.gautam@xxxxxxxxxxxxx> --- 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 452059780ddc..09461868ed46 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, .fops = &cirrus_driver_fops, @@ -143,6 +143,15 @@ static struct drm_driver driver = { .gem_free_object_unlocked = cirrus_gem_free_object, .dumb_create = cirrus_dumb_create, .dumb_map_offset = cirrus_dumb_mmap_offset, + .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 e16b86dd6c19..8c43cc963027 100644 --- a/drivers/gpu/drm/cirrus/cirrus_drv.h +++ b/drivers/gpu/drm/cirrus/cirrus_drv.h @@ -163,6 +163,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; @@ -256,6 +257,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@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel