2019-06-03 07:44:50 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2013-07-19 12:59:32 -04:00
/*
* Copyright ( C ) 2013 Red Hat
* Author : Rob Clark < robdclark @ gmail . com >
*/
# 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 ;
2018-11-07 15:35:54 -07:00
2017-10-20 11:06:57 -06:00
ring - > start = msm_gem_kernel_new ( gpu - > dev , MSM_GPU_RINGBUFFER_SZ ,
2020-09-03 20:03:11 -06:00
check_apriv ( gpu , MSM_BO_WC | MSM_BO_GPU_READONLY ) ,
gpu - > aspace , & ring - > bo , & ring - > iova ) ;
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 ;
}
2018-11-07 15:35:52 -07:00
msm_gem_object_set_name ( ring - > bo , " ring%d " , id ) ;
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 ) ;
2020-10-23 09:51:16 -07:00
spin_lock_init ( & ring - > submit_lock ) ;
2020-10-23 09:51:15 -07:00
spin_lock_init ( & ring - > preempt_lock ) ;
2017-10-20 11:06:57 -06:00
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 ) ;
2018-11-07 15:35:46 -07:00
msm_gem_kernel_put ( ring - > bo , ring - > gpu - > aspace , false ) ;
2013-07-19 12:59:32 -04:00
kfree ( ring ) ;
}