2013-07-19 12:59:32 -04:00
/*
* Copyright ( C ) 2013 Red Hat
* Author : Rob Clark < robdclark @ gmail . com >
*
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License for
* more details .
*
* You should have received a copy of the GNU General Public License along with
* this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "msm_ringbuffer.h"
# include "msm_gpu.h"
2017-10-20 11:06:57 -06:00
struct msm_ringbuffer * msm_ringbuffer_new ( struct msm_gpu * gpu , int id ,
void * memptrs , uint64_t memptrs_iova )
2013-07-19 12:59:32 -04:00
{
struct msm_ringbuffer * ring ;
2017-10-20 11:06:57 -06:00
char name [ 32 ] ;
2013-07-19 12:59:32 -04:00
int ret ;
2017-10-20 11:06:57 -06:00
/* We assume everwhere that MSM_GPU_RINGBUFFER_SZ is a power of 2 */
BUILD_BUG_ON ( ! is_power_of_2 ( MSM_GPU_RINGBUFFER_SZ ) ) ;
2013-07-19 12:59:32 -04:00
ring = kzalloc ( sizeof ( * ring ) , GFP_KERNEL ) ;
if ( ! ring ) {
ret = - ENOMEM ;
goto fail ;
}
ring - > gpu = gpu ;
2017-10-20 11:06:57 -06:00
ring - > id = id ;
2017-07-27 10:42:40 -06:00
/* Pass NULL for the iova pointer - we will map it later */
2017-10-20 11:06:57 -06:00
ring - > start = msm_gem_kernel_new ( gpu - > dev , MSM_GPU_RINGBUFFER_SZ ,
MSM_BO_WC , gpu - > aspace , & ring - > bo , NULL ) ;
2017-07-27 10:42:40 -06:00
2016-05-24 18:29:38 -04:00
if ( IS_ERR ( ring - > start ) ) {
ret = PTR_ERR ( ring - > start ) ;
2017-07-27 10:42:40 -06:00
ring - > start = 0 ;
2016-05-24 18:29:38 -04:00
goto fail ;
}
2017-10-20 11:06:57 -06:00
ring - > end = ring - > start + ( MSM_GPU_RINGBUFFER_SZ > > 2 ) ;
2017-10-20 11:06:59 -06:00
ring - > next = ring - > start ;
2013-07-19 12:59:32 -04:00
ring - > cur = ring - > start ;
2017-10-20 11:06:57 -06:00
ring - > memptrs = memptrs ;
ring - > memptrs_iova = memptrs_iova ;
INIT_LIST_HEAD ( & ring - > submits ) ;
snprintf ( name , sizeof ( name ) , " gpu-ring-%d " , ring - > id ) ;
ring - > fctx = msm_fence_context_alloc ( gpu - > dev , name ) ;
2013-07-19 12:59:32 -04:00
return ring ;
fail :
2017-10-20 11:06:57 -06:00
msm_ringbuffer_destroy ( ring ) ;
2013-07-19 12:59:32 -04:00
return ERR_PTR ( ret ) ;
}
void msm_ringbuffer_destroy ( struct msm_ringbuffer * ring )
{
2017-10-20 11:06:57 -06:00
if ( IS_ERR_OR_NULL ( ring ) )
return ;
msm_fence_context_free ( ring - > fctx ) ;
2016-05-26 16:24:35 -04:00
if ( ring - > bo ) {
2017-10-20 11:06:57 -06:00
msm_gem_put_iova ( ring - > bo , ring - > gpu - > aspace ) ;
2016-05-26 16:24:35 -04:00
msm_gem_put_vaddr ( ring - > bo ) ;
2015-05-15 09:19:36 -04:00
drm_gem_object_unreference_unlocked ( ring - > bo ) ;
2016-05-26 16:24:35 -04:00
}
2013-07-19 12:59:32 -04:00
kfree ( ring ) ;
}