2019-06-03 07:44:50 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2013-09-28 11:28:35 -04:00
/*
* Copyright ( C ) 2013 Red Hat
* Author : Rob Clark < robdclark @ gmail . com >
*/
2019-08-04 08:55:51 +02:00
# include <linux/dma-buf.h>
# include <drm/drm_prime.h>
2013-09-28 11:28:35 -04: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-23 13:44:56 -04: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 11:28:35 -04:00
}
void * msm_gem_prime_vmap ( struct drm_gem_object * obj )
{
2016-05-26 16:24:35 -04:00
return msm_gem_get_vaddr ( obj ) ;
2013-09-28 11:28:35 -04:00
}
void msm_gem_prime_vunmap ( struct drm_gem_object * obj , void * vaddr )
{
2016-05-26 16:24:35 -04:00
msm_gem_put_vaddr ( obj ) ;
2013-09-28 11:28:35 -04:00
}
2014-11-12 11:38:14 +00: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 11:28:35 -04:00
struct drm_gem_object * msm_gem_prime_import_sg_table ( struct drm_device * dev ,
2014-01-09 11:03:14 +01:00
struct dma_buf_attachment * attach , struct sg_table * sg )
2013-09-28 11:28:35 -04:00
{
2016-03-16 12:40:35 -04:00
return msm_gem_import ( dev , attach - > dmabuf , sg ) ;
2013-09-28 11:28:35 -04: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 ) ;
}