2019-06-03 12:44:50 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-09-28 22:28:35 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Red Hat
|
|
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2019-08-04 13:55:51 +07:00
|
|
|
#include <linux/dma-buf.h>
|
|
|
|
|
|
|
|
#include <drm/drm_prime.h>
|
|
|
|
|
2013-09-28 22:28:35 +07:00
|
|
|
#include "msm_drv.h"
|
|
|
|
#include "msm_gem.h"
|
|
|
|
|
|
|
|
struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj)
|
|
|
|
{
|
|
|
|
struct msm_gem_object *msm_obj = to_msm_bo(obj);
|
2015-07-24 00:44:56 +07:00
|
|
|
int npages = obj->size >> PAGE_SHIFT;
|
|
|
|
|
|
|
|
if (WARN_ON(!msm_obj->pages)) /* should have already pinned! */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return drm_prime_pages_to_sg(msm_obj->pages, npages);
|
2013-09-28 22:28:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *msm_gem_prime_vmap(struct drm_gem_object *obj)
|
|
|
|
{
|
2016-05-27 03:24:35 +07:00
|
|
|
return msm_gem_get_vaddr(obj);
|
2013-09-28 22:28:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
|
|
|
|
{
|
2016-05-27 03:24:35 +07:00
|
|
|
msm_gem_put_vaddr(obj);
|
2013-09-28 22:28:35 +07:00
|
|
|
}
|
|
|
|
|
2014-11-12 18:38:14 +07:00
|
|
|
int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_gem_mmap_obj(obj, obj->size, vma);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return msm_gem_mmap_obj(vma->vm_private_data, vma);
|
|
|
|
}
|
|
|
|
|
2013-09-28 22:28:35 +07:00
|
|
|
struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
|
2014-01-09 17:03:14 +07:00
|
|
|
struct dma_buf_attachment *attach, struct sg_table *sg)
|
2013-09-28 22:28:35 +07:00
|
|
|
{
|
2016-03-16 23:40:35 +07:00
|
|
|
return msm_gem_import(dev, attach->dmabuf, sg);
|
2013-09-28 22:28:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
int msm_gem_prime_pin(struct drm_gem_object *obj)
|
|
|
|
{
|
|
|
|
if (!obj->import_attach)
|
|
|
|
msm_gem_get_pages(obj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void msm_gem_prime_unpin(struct drm_gem_object *obj)
|
|
|
|
{
|
|
|
|
if (!obj->import_attach)
|
|
|
|
msm_gem_put_pages(obj);
|
|
|
|
}
|