2012-05-20 10:00:36 +00:00
/*
* Copyright ( C ) 2010 ARM Limited . All rights reserved .
*
* Portions of this code have been modified from the original .
* These modifications are :
* * includes
* * enums
* * gralloc_device_open ( )
* * gralloc_register_buffer ( )
* * gralloc_unregister_buffer ( )
* * gralloc_lock ( )
* * gralloc_unlock ( )
* * gralloc_module_methods
* * HAL_MODULE_INFO_SYM
*
* Copyright ( C ) 2008 The Android Open Source Project
*
* Licensed under the Apache License , Version 2.0 ( the " License " ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an " AS IS " BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*/
2017-10-12 11:16:34 +00:00
//#define LOG_NDEBUG 0
2012-05-20 10:00:36 +00:00
# include <errno.h>
# include <pthread.h>
2018-03-02 17:56:54 +00:00
# include <stdlib.h>
2018-08-13 20:39:50 +00:00
# include <string.h>
2012-05-20 10:00:36 +00:00
2014-11-20 22:38:34 +00:00
# include <stdlib.h>
2012-05-20 10:00:36 +00:00
# include <sys/mman.h>
# include <cutils/log.h>
# include <cutils/atomic.h>
2014-11-20 22:38:34 +00:00
# include <cutils/properties.h>
2012-05-20 10:00:36 +00:00
# include <hardware/hardware.h>
# include <hardware/gralloc.h>
# include <fcntl.h>
2017-10-12 11:16:34 +00:00
# include <gralloc1-adapter.h>
2012-05-20 10:00:36 +00:00
# include "gralloc_priv.h"
# include "alloc_device.h"
# include "framebuffer_device.h"
# include "ump.h"
# include "ump_ref_drv.h"
2014-11-20 22:35:51 +00:00
# include "secion.h"
2012-05-20 10:00:36 +00:00
# include "s5p_fimc.h"
# include "exynos_mem.h"
2017-03-14 12:58:05 +00:00
# include "graphics.h"
2012-05-20 10:00:36 +00:00
static pthread_mutex_t s_map_lock = PTHREAD_MUTEX_INITIALIZER ;
static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER ;
2014-11-20 22:38:34 +00:00
static int gSdkVersion = 0 ;
2012-05-20 10:00:36 +00:00
static int s_ump_is_open = 0 ;
2014-11-20 22:38:34 +00:00
2012-05-20 10:00:36 +00:00
# define PFX_NODE_MEM " / dev / exynos-mem"
/* we need this for now because pmem cannot mmap at an offset */
# define PMEM_HACK 1
2014-11-20 22:38:34 +00:00
int get_bpp ( int format )
{
int bpp = 0 ;
switch ( format ) {
case HAL_PIXEL_FORMAT_RGBA_8888 :
case HAL_PIXEL_FORMAT_RGBX_8888 :
case HAL_PIXEL_FORMAT_BGRA_8888 :
bpp = 4 ;
break ;
case HAL_PIXEL_FORMAT_RGB_888 :
bpp = 3 ;
break ;
case HAL_PIXEL_FORMAT_RGB_565 :
case HAL_PIXEL_FORMAT_RGBA_5551 :
case HAL_PIXEL_FORMAT_RGBA_4444 :
bpp = 2 ;
break ;
default :
bpp = 0 ;
}
ALOGD_IF ( debug_level > 0 , " %s bpp=%d " , __func__ , bpp ) ;
return bpp ;
}
2012-05-20 10:00:36 +00:00
# ifdef USE_PARTIAL_FLUSH
2018-12-28 23:22:46 +00:00
static struct private_handle_rect * rect_list ;
2014-11-20 22:38:34 +00:00
static pthread_mutex_t s_rect_lock = PTHREAD_MUTEX_INITIALIZER ;
2012-05-20 10:00:36 +00:00
private_handle_rect * find_rect ( int secure_id )
{
2014-11-20 22:38:34 +00:00
private_handle_rect * psRect = NULL ;
ALOGD_IF ( debug_level > 0 , " %s secure_id=%d " , __func__ , secure_id ) ;
pthread_mutex_lock ( & s_rect_lock ) ;
2012-05-20 10:00:36 +00:00
for ( psRect = rect_list ; psRect ; psRect = psRect - > next )
if ( psRect - > handle = = secure_id )
break ;
2014-11-20 22:38:34 +00:00
pthread_mutex_unlock ( & s_rect_lock ) ;
2012-05-20 10:00:36 +00:00
return psRect ;
}
2018-12-28 23:22:46 +00:00
void insert_rect_first ( private_handle_rect * new_rect ) {
int secure_id = new_rect - > handle ;
private_handle_rect * psRect = NULL ;
private_handle_rect * psFRect = NULL ;
ALOGD_IF ( debug_level > 0 , " %s secure_id=%d " , __func__ , secure_id ) ;
pthread_mutex_lock ( & s_rect_lock ) ;
if ( rect_list = = NULL ) {
rect_list = ( private_handle_rect * ) calloc ( 1 , sizeof ( private_handle_rect ) ) ;
rect_list - > next = new_rect ;
} else {
for ( psRect = rect_list ; psRect ; psRect = psRect - > next ) {
if ( psRect - > handle = = secure_id ) {
// Inserts rect before existing
psFRect - > next = new_rect ;
new_rect - > next = psRect ;
pthread_mutex_unlock ( & s_rect_lock ) ;
return ;
}
psFRect = psRect ;
}
// No match found, just append it
psFRect - > next = new_rect ;
}
pthread_mutex_unlock ( & s_rect_lock ) ;
}
void insert_rect_last ( private_handle_rect * new_rect ) {
int secure_id = new_rect - > handle ;
private_handle_rect * psRect = NULL ;
private_handle_rect * psFRect = NULL ;
private_handle_rect * psMatchRect = NULL ;
ALOGD_IF ( debug_level > 0 , " %s secure_id=%d " , __func__ , secure_id ) ;
pthread_mutex_lock ( & s_rect_lock ) ;
if ( rect_list = = NULL ) {
rect_list = ( private_handle_rect * ) calloc ( 1 , sizeof ( private_handle_rect ) ) ;
rect_list - > next = new_rect ;
} else {
for ( psRect = rect_list ; psRect ; psRect = psRect - > next ) {
if ( psRect - > handle = = secure_id ) {
psMatchRect = psRect ;
} else if ( psMatchRect ) {
psMatchRect - > next = new_rect ;
new_rect - > next = psRect ;
pthread_mutex_unlock ( & s_rect_lock ) ;
return ;
}
psFRect = psRect ;
}
// No match found, just append it
psFRect - > next = new_rect ;
}
pthread_mutex_unlock ( & s_rect_lock ) ;
}
2012-05-20 10:00:36 +00:00
private_handle_rect * find_last_rect ( int secure_id )
{
2014-12-17 00:11:58 +00:00
private_handle_rect * psRect = NULL ;
2014-11-20 22:38:34 +00:00
private_handle_rect * psFRect = NULL ;
2018-12-28 23:22:46 +00:00
ALOGD_IF ( debug_level > 0 , " %s secure_id=%d " , __func__ , secure_id ) ;
2012-05-20 10:00:36 +00:00
2014-11-20 22:38:34 +00:00
pthread_mutex_lock ( & s_rect_lock ) ;
2012-05-20 10:00:36 +00:00
if ( rect_list = = NULL ) {
rect_list = ( private_handle_rect * ) calloc ( 1 , sizeof ( private_handle_rect ) ) ;
2014-11-20 22:38:34 +00:00
psFRect = rect_list ;
} else {
for ( psRect = rect_list ; psRect ; psRect = psRect - > next ) {
2014-12-17 00:11:58 +00:00
psFRect = psRect ;
2014-11-20 22:38:34 +00:00
if ( psRect - > handle = = secure_id )
break ;
}
2012-05-20 10:00:36 +00:00
}
2014-11-20 22:38:34 +00:00
pthread_mutex_unlock ( & s_rect_lock ) ;
2012-05-20 10:00:36 +00:00
return psFRect ;
}
2018-12-28 23:22:46 +00:00
int count_rect ( int secure_id ) {
private_handle_rect * psRect ;
private_handle_rect * next ;
int count = 0 ;
pthread_mutex_lock ( & s_rect_lock ) ;
for ( psRect = rect_list ; psRect ; psRect = psRect - > next ) {
next = psRect - > next ;
if ( next & & next - > handle = = secure_id ) {
count + + ;
}
}
pthread_mutex_unlock ( & s_rect_lock ) ;
return count ;
}
void dump_rect ( ) {
private_handle_rect * psRect ;
private_handle_rect * next ;
pthread_mutex_lock ( & s_rect_lock ) ;
for ( psRect = rect_list ; psRect ; psRect = psRect - > next ) {
ALOGD_IF ( debug_partial_flush > 0 , " %s:PARTIAL_FLUSH handle/ump_id:%d w:%d h:%d stride:%d, psRect:%08x " , __func__ , psRect - > handle , psRect - > w , psRect - > h , psRect - > stride , psRect ) ;
next = psRect - > next ;
}
pthread_mutex_unlock ( & s_rect_lock ) ;
}
2012-05-20 10:00:36 +00:00
int release_rect ( int secure_id )
{
2014-11-20 22:38:34 +00:00
int rc = 0 ;
2012-05-20 10:00:36 +00:00
private_handle_rect * psRect ;
private_handle_rect * psTRect ;
2014-11-20 22:38:34 +00:00
private_handle_rect * next ;
2012-05-20 10:00:36 +00:00
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s secure_id=%d " , __func__ , secure_id ) ;
pthread_mutex_lock ( & s_rect_lock ) ;
2012-05-20 10:00:36 +00:00
for ( psRect = rect_list ; psRect ; psRect = psRect - > next ) {
2014-11-20 22:38:34 +00:00
next = psRect - > next ;
if ( next & & next - > handle = = secure_id ) {
psTRect = next - > next ;
free ( next ) ;
psRect - > next = psTRect ;
rc = 1 ;
break ;
2012-05-20 10:00:36 +00:00
}
}
2014-11-20 22:38:34 +00:00
pthread_mutex_unlock ( & s_rect_lock ) ;
return rc ;
2012-05-20 10:00:36 +00:00
}
# endif
2018-08-13 20:39:50 +00:00
static int gralloc_map ( gralloc_module_t const * module __unused ,
2012-05-20 10:00:36 +00:00
buffer_handle_t handle , void * * vaddr )
{
private_handle_t * hnd = ( private_handle_t * ) handle ;
if ( ! ( hnd - > flags & private_handle_t : : PRIV_FLAGS_FRAMEBUFFER ) ) {
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_IOCTL ) {
size_t size = FIMC1_RESERVED_SIZE * 1024 ;
void * mappedAddress = mmap ( 0 , size ,
PROT_READ | PROT_WRITE , MAP_SHARED , gMemfd , ( hnd - > paddr - hnd - > offset ) ) ;
if ( mappedAddress = = MAP_FAILED ) {
2012-07-22 13:45:33 +00:00
ALOGE ( " Could not mmap %s fd(%d) " , strerror ( errno ) , hnd - > fd ) ;
2012-05-20 10:00:36 +00:00
return - errno ;
}
hnd - > base = intptr_t ( mappedAddress ) + hnd - > offset ;
} else if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_ION ) {
size_t size = hnd - > size ;
hnd - > ion_client = ion_client_create ( ) ;
void * mappedAddress = ion_map ( hnd - > fd , size , 0 ) ;
if ( mappedAddress = = MAP_FAILED ) {
2012-07-22 13:45:33 +00:00
ALOGE ( " Could not ion_map %s fd(%d) " , strerror ( errno ) , hnd - > fd ) ;
2012-05-20 10:00:36 +00:00
return - errno ;
}
hnd - > base = intptr_t ( mappedAddress ) + hnd - > offset ;
} else {
size_t size = hnd - > size ;
# if PMEM_HACK
size + = hnd - > offset ;
# endif
void * mappedAddress = mmap ( 0 , size ,
PROT_READ | PROT_WRITE , MAP_SHARED , hnd - > fd , 0 ) ;
if ( mappedAddress = = MAP_FAILED ) {
2012-07-22 13:45:33 +00:00
ALOGE ( " Could not mmap %s fd(%d) " , strerror ( errno ) , hnd - > fd ) ;
2012-05-20 10:00:36 +00:00
return - errno ;
}
hnd - > base = intptr_t ( mappedAddress ) + hnd - > offset ;
}
}
* vaddr = ( void * ) hnd - > base ;
return 0 ;
}
2018-08-13 20:39:50 +00:00
static int gralloc_unmap ( gralloc_module_t const * module __unused ,
2012-05-20 10:00:36 +00:00
buffer_handle_t handle )
{
private_handle_t * hnd = ( private_handle_t * ) handle ;
if ( ! ( hnd - > flags & private_handle_t : : PRIV_FLAGS_FRAMEBUFFER ) ) {
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_IOCTL ) {
void * base = ( void * ) ( intptr_t ( hnd - > base ) - hnd - > offset ) ;
size_t size = FIMC1_RESERVED_SIZE * 1024 ;
if ( munmap ( base , size ) < 0 )
2012-07-22 13:45:33 +00:00
ALOGE ( " Could not unmap %s " , strerror ( errno ) ) ;
2012-05-20 10:00:36 +00:00
} else if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_ION ) {
void * base = ( void * ) hnd - > base ;
size_t size = hnd - > size ;
if ( ion_unmap ( base , size ) < 0 )
2012-07-22 13:45:33 +00:00
ALOGE ( " Could not ion_unmap %s " , strerror ( errno ) ) ;
2012-05-20 10:00:36 +00:00
ion_client_destroy ( hnd - > ion_client ) ;
} else {
void * base = ( void * ) hnd - > base ;
size_t size = hnd - > size ;
# if PMEM_HACK
base = ( void * ) ( intptr_t ( base ) - hnd - > offset ) ;
size + = hnd - > offset ;
# endif
if ( munmap ( base , size ) < 0 )
2012-07-22 13:45:33 +00:00
ALOGE ( " Could not unmap %s " , strerror ( errno ) ) ;
2012-05-20 10:00:36 +00:00
}
}
hnd - > base = 0 ;
return 0 ;
}
static int gralloc_device_open ( const hw_module_t * module , const char * name , hw_device_t * * device )
{
int status = - EINVAL ;
2014-11-20 22:38:34 +00:00
char property [ PROPERTY_VALUE_MAX ] ;
2012-05-20 10:00:36 +00:00
2017-10-12 11:16:34 +00:00
# ifdef ADVERTISE_GRALLOC1
if ( ! strcmp ( name , GRALLOC_HARDWARE_MODULE_ID ) ) {
return gralloc1_adapter_device_open ( module , name , device ) ;
}
# endif
2012-05-20 10:00:36 +00:00
if ( ! strcmp ( name , GRALLOC_HARDWARE_GPU0 ) )
status = alloc_device_open ( module , name , device ) ;
else if ( ! strcmp ( name , GRALLOC_HARDWARE_FB0 ) )
status = framebuffer_device_open ( module , name , device ) ;
2014-11-20 22:38:34 +00:00
property_get ( " ro.build.version.sdk " , property , 0 ) ;
gSdkVersion = atoi ( property ) ;
2012-05-20 10:00:36 +00:00
return status ;
}
static int gralloc_register_buffer ( gralloc_module_t const * module , buffer_handle_t handle )
{
int err = 0 ;
int retval = - EINVAL ;
void * vaddr ;
2014-11-20 22:38:34 +00:00
bool cacheable = false ;
int rc = 0 ;
2012-05-20 10:00:36 +00:00
if ( private_handle_t : : validate ( handle ) < 0 ) {
2014-11-20 22:38:34 +00:00
ALOGE ( " %s Registering invalid buffer, returning error " , __func__ ) ;
2012-05-20 10:00:36 +00:00
return - EINVAL ;
}
/* if this handle was created in this process, then we keep it as is. */
private_handle_t * hnd = ( private_handle_t * ) handle ;
2018-12-24 22:50:16 +00:00
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d " , __func__ , hnd - > ump_id ) ;
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s flags=%x " , __func__ , hnd - > flags ) ;
2017-10-12 11:16:34 +00:00
2012-05-20 10:00:36 +00:00
# ifdef USE_PARTIAL_FLUSH
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_UMP ) {
2018-12-28 23:22:46 +00:00
ALOGD_IF ( debug_partial_flush > 0 ,
" %s: PARTIAL_FLUSH ump_id:%d === BEGIN === ump_mem_handle:%08x flags=%x usage=%x count:%d backingstore:%d " ,
__func__ , hnd - > ump_id , hnd - > ump_mem_handle , hnd - > flags , hnd - > usage , count_rect ( hnd - > ump_id ) , hnd - > backing_store ) ;
if ( debug_partial_flush > 0 )
dump_rect ( ) ;
2012-05-20 10:00:36 +00:00
private_handle_rect * psRect ;
psRect = ( private_handle_rect * ) calloc ( 1 , sizeof ( private_handle_rect ) ) ;
psRect - > handle = ( int ) hnd - > ump_id ;
2018-12-28 23:22:46 +00:00
psRect - > stride = ( int ) ( hnd - > stride * get_bpp ( hnd - > format ) ) ;
ALOGD_IF ( debug_partial_flush > 0 ,
" %s: PARTIAL_FLUSH ump_id:%d === insert_rect_last === ump_mem_handle:%08x flags=%x usage=%x count:%d backingstore:%d " ,
__func__ , hnd - > ump_id , hnd - > ump_mem_handle , hnd - > flags , hnd - > usage , count_rect ( hnd - > ump_id ) , hnd - > backing_store ) ;
insert_rect_last ( psRect ) ;
if ( debug_partial_flush > 0 )
dump_rect ( ) ;
ALOGD_IF ( debug_partial_flush > 0 ,
" %s: PARTIAL_FLUSH ump_id:%d === END === ump_mem_handle:%08x flags=%x usage=%x count:%d backingstore:%d " ,
__func__ , hnd - > ump_id , hnd - > ump_mem_handle , hnd - > flags , hnd - > usage , count_rect ( hnd - > ump_id ) , hnd - > backing_store ) ;
2012-05-20 10:00:36 +00:00
}
# endif
2014-11-20 22:38:34 +00:00
/* not in stock
// wjj, when WFD, use GRALLOC_USAGE_HW_VIDEO_ENCODER,
// ANW pid is same as SF pid, but need to create ump handle because WFD's BQ is in different pid.
// gSdkVersion <= 17 means JB4.2, BQ always created by SF.
if ( ( gSdkVersion < = 17 ) & & ( hnd - > pid = = getpid ( ) ) & & ( 0 = = ( hnd - > usage & GRALLOC_USAGE_HW_VIDEO_ENCODER ) ) )
{
ALOGE ( " Unable to register handle 0x%x coming from different process: %d " , ( unsigned int ) hnd , hnd - > pid ) ;
return 0 ;
}
2018-08-25 18:18:15 +00:00
sd
2012-05-20 10:00:36 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_ION )
2014-11-20 22:38:34 +00:00
err = gralloc_map ( module , handle , & vaddr ) ; */
2012-05-20 10:00:36 +00:00
2018-08-25 18:18:15 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_FRAMEBUFFER ) {
return 0 ;
}
2012-05-20 10:00:36 +00:00
pthread_mutex_lock ( & s_map_lock ) ;
if ( ! s_ump_is_open ) {
ump_result res = ump_open ( ) ; /* TODO: Fix a ump_close() somewhere??? */
if ( res ! = UMP_OK ) {
pthread_mutex_unlock ( & s_map_lock ) ;
2014-11-20 22:38:34 +00:00
ALOGE ( " %s Failed to open UMP library " , __func__ ) ;
2012-05-20 10:00:36 +00:00
return retval ;
}
s_ump_is_open = 1 ;
}
2014-11-20 22:38:34 +00:00
hnd - > pid = getpid ( ) ; /* not in stock */
2014-01-02 15:50:59 +00:00
2018-08-25 18:18:15 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_UMP ) {
2018-12-24 22:50:16 +00:00
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d ump_mem_handle:%08x " , __func__ , hnd - > ump_id , hnd - > ump_mem_handle ) ;
2012-05-20 10:00:36 +00:00
hnd - > ump_mem_handle = ( int ) ump_handle_create_from_secure_id ( hnd - > ump_id ) ;
2018-12-28 23:22:46 +00:00
ALOGD_IF ( debug_partial_flush > 0 , " %s: PARTIAL_FLUSH ump_id:%d ump_mem_handle:%08x flags=%x usage=%x count:%d backing_store:%d " , __func__ , hnd - > ump_id , hnd - > ump_mem_handle , hnd - > flags , hnd - > usage , count_rect ( hnd - > ump_id ) , hnd - > backing_store ) ;
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s PRIV_FLAGS_USES_UMP hnd->ump_mem_handle=%d(%x) " , __func__ , hnd - > ump_mem_handle , hnd - > ump_mem_handle ) ;
2012-05-20 10:00:36 +00:00
if ( UMP_INVALID_MEMORY_HANDLE ! = ( ump_handle ) hnd - > ump_mem_handle ) {
hnd - > base = ( int ) ump_mapped_pointer_get ( ( ump_handle ) hnd - > ump_mem_handle ) ;
if ( 0 ! = hnd - > base ) {
2014-11-20 22:38:34 +00:00
/* hnd->lockState = private_handle_t::LOCK_STATE_MAPPED; not in stock */
2012-05-20 10:00:36 +00:00
hnd - > writeOwner = 0 ;
hnd - > lockState = 0 ;
pthread_mutex_unlock ( & s_map_lock ) ;
return 0 ;
} else {
2014-11-20 22:38:34 +00:00
ALOGE ( " %s Failed to map UMP handle " , __func__ ) ;
2012-05-20 10:00:36 +00:00
}
ump_reference_release ( ( ump_handle ) hnd - > ump_mem_handle ) ;
} else {
2014-11-20 22:38:34 +00:00
ALOGE ( " %s Failed to create UMP handle " , __func__ ) ;
2012-05-20 10:00:36 +00:00
}
2014-11-20 22:38:34 +00:00
2012-05-20 10:00:36 +00:00
} else if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_PMEM ) {
2014-11-20 22:38:34 +00:00
ALOGE ( " %s PRIV_FLAGS_USES_PMEM mapping: base:%08x " , __func__ , hnd - > base ) ;
2012-05-20 10:00:36 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
return 0 ;
2014-11-20 22:38:34 +00:00
} else if ( hnd - > flags & ( private_handle_t : : PRIV_FLAGS_USES_IOCTL | private_handle_t : : PRIV_FLAGS_USES_HDMI ) ) {
2012-05-20 10:00:36 +00:00
if ( gMemfd = = 0 ) {
gMemfd = open ( PFX_NODE_MEM , O_RDWR ) ;
if ( gMemfd < 0 ) {
2012-07-22 13:45:33 +00:00
ALOGE ( " %s:: %s exynos-mem open error \n " , __func__ , PFX_NODE_MEM ) ;
2014-11-20 22:38:34 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
return 0 ;
2012-05-20 10:00:36 +00:00
}
}
2014-11-20 22:38:34 +00:00
cacheable = true ;
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_NONE_CACHED )
cacheable = false ;
ALOGD_IF ( debug_level > 0 , " %s cacheable=%d " , __func__ , cacheable ) ;
rc = ioctl ( gMemfd , EXYNOS_MEM_SET_CACHEABLE , & cacheable ) ;
if ( rc < 0 )
ALOGE ( " %s: Unable to set EXYNOS_MEM_SET_CACHEABLE to %d " , __func__ , cacheable ) ;
2012-05-20 10:00:36 +00:00
2014-11-20 22:38:34 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_FRAMEBUFFER ) {
pthread_mutex_unlock ( & s_map_lock ) ;
return 0 ;
}
if ( hnd - > flags & ( private_handle_t : : PRIV_FLAGS_USES_IOCTL | private_handle_t : : PRIV_FLAGS_USES_HDMI ) ) {
vaddr = mmap ( 0 , hnd - > yaddr * 1024 , PROT_READ | PROT_WRITE , MAP_SHARED , gMemfd , ( hnd - > paddr - hnd - > offset ) ) ;
if ( vaddr = = MAP_FAILED ) {
ALOGE ( " Could not mmap %s fd(%d) " , strerror ( errno ) , hnd - > fd ) ;
2012-05-20 10:00:36 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
2014-11-20 22:38:34 +00:00
return - errno ;
2012-05-20 10:00:36 +00:00
}
} else {
2014-11-20 22:38:34 +00:00
vaddr = mmap ( 0 , hnd - > size + hnd - > offset , PROT_READ | PROT_WRITE , MAP_SHARED , hnd - > fd , 0 ) ;
if ( vaddr = = MAP_FAILED ) {
ALOGE ( " Could not mmap %s fd(%d) " , strerror ( errno ) , hnd - > fd ) ;
pthread_mutex_unlock ( & s_map_lock ) ;
return - errno ;
}
2012-05-20 10:00:36 +00:00
}
2014-11-20 22:38:34 +00:00
} else {
ALOGE ( " %s registering non-UMP buffer not supported " , __func__ ) ;
2012-05-20 10:00:36 +00:00
}
2018-12-13 20:41:09 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_GRAPHICBUFFER ) {
ALOGD_IF ( debug_level > 0 , " ump_id:%d %s: GraphicBuffer (ump_id:%d): ump_mem_handle:%08x (ump_reference_release) " , hnd - > ump_id , __func__ , hnd - > ump_id , hnd - > ump_mem_handle ) ;
ump_reference_release ( ( ump_handle ) hnd - > ump_mem_handle ) ;
}
2012-05-20 10:00:36 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
return retval ;
}
2018-12-24 21:12:38 +00:00
static int unregister_buffer ( private_handle_t * hnd ) {
2018-12-24 22:50:16 +00:00
if ( private_handle_t : : validate ( hnd ) < 0 ) {
ALOGE ( " %s Unregistering invalid buffer, returning error " , __func__ ) ;
return - EINVAL ;
}
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d " , __func__ , hnd - > ump_id ) ;
2018-08-25 18:18:15 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_FRAMEBUFFER ) {
hnd - > base = 0 ;
return 0 ;
}
2012-05-20 10:00:36 +00:00
# ifdef USE_PARTIAL_FLUSH
2018-12-28 23:22:46 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_UMP ) {
ALOGD_IF ( debug_partial_flush > 0 ,
" %s: PARTIAL_FLUSH ump_id:%d === BEGIN === ump_mem_handle:%08x flags=%x usage=%x count:%d backingstore:%d " ,
__func__ , hnd - > ump_id , hnd - > ump_mem_handle , hnd - > flags , hnd - > usage , count_rect ( hnd - > ump_id ) , hnd - > backing_store ) ;
if ( debug_partial_flush > 0 )
dump_rect ( ) ;
ALOGD_IF ( debug_partial_flush > 0 ,
" %s: PARTIAL_FLUSH ump_id:%d === release_rect === ump_mem_handle:%08x flags=%x usage=%x count:%d backingstore:%d " ,
__func__ , hnd - > ump_id , hnd - > ump_mem_handle , hnd - > flags , hnd - > usage , count_rect ( hnd - > ump_id ) , hnd - > backing_store ) ;
2012-05-20 10:00:36 +00:00
if ( ! release_rect ( ( int ) hnd - > ump_id ) )
2018-12-28 23:22:46 +00:00
ALOGE ( " %s: PARTIAL_FLUSH ump_id:%d, release error " , __func__ , ( int ) hnd - > ump_id ) ;
if ( debug_partial_flush > 0 )
dump_rect ( ) ;
ALOGD_IF ( debug_partial_flush > 0 ,
" %s: PARTIAL_FLUSH ump_id:%d === END === ump_mem_handle:%08x flags=%x usage=%x count:%d backingstore:%d " ,
__func__ , hnd - > ump_id , hnd - > ump_mem_handle , hnd - > flags , hnd - > usage , count_rect ( hnd - > ump_id ) , hnd - > backing_store ) ;
}
2012-05-20 10:00:36 +00:00
# endif
2012-07-22 13:45:33 +00:00
ALOGE_IF ( hnd - > lockState & private_handle_t : : LOCK_STATE_READ_MASK ,
2014-11-20 22:38:34 +00:00
" %s [unregister] handle %p still locked (state=%08x) " , __func__ , hnd , hnd - > lockState ) ;
2012-05-20 10:00:36 +00:00
2014-01-02 15:50:59 +00:00
/* never unmap buffers that were not registered in this process */
2014-11-20 22:38:34 +00:00
/* if (hnd->pid == getpid()) { not in stock */
2012-05-20 10:00:36 +00:00
2014-11-20 22:38:34 +00:00
pthread_mutex_lock ( & s_map_lock ) ;
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_UMP ) {
2018-12-24 22:50:16 +00:00
if ( UMP_INVALID_MEMORY_HANDLE ! = ( ump_handle ) hnd - > ump_mem_handle ) {
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d ump_mem_handle:%08x " , __func__ , hnd - > ump_id , hnd - > ump_mem_handle ) ;
ump_mapped_pointer_release ( ( ump_handle ) hnd - > ump_mem_handle ) ;
hnd - > base = 0 ;
ump_reference_release ( ( ump_handle ) hnd - > ump_mem_handle ) ;
hnd - > ump_mem_handle = ( int ) UMP_INVALID_MEMORY_HANDLE ;
hnd - > lockState = 0 ;
hnd - > writeOwner = 0 ;
} else {
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d SKIPPED ump_mem_handle:%08x " , __func__ , hnd - > ump_id , hnd - > ump_mem_handle ) ;
}
2014-11-20 22:38:34 +00:00
} else if ( hnd - > flags & ( private_handle_t : : PRIV_FLAGS_USES_IOCTL | private_handle_t : : PRIV_FLAGS_USES_HDMI ) ) {
if ( hnd - > base = = 0 ) {
2014-01-02 15:48:30 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
return 0 ;
2014-11-20 22:38:34 +00:00
}
2014-01-02 15:48:30 +00:00
2014-11-20 22:38:34 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_FRAMEBUFFER ) {
2014-01-02 15:48:30 +00:00
hnd - > base = 0 ;
2014-11-20 22:38:34 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
return 0 ;
}
if ( hnd - > flags & ( private_handle_t : : PRIV_FLAGS_USES_IOCTL | private_handle_t : : PRIV_FLAGS_USES_HDMI ) ) {
if ( munmap ( ( void * ) ( hnd - > base - hnd - > offset ) , hnd - > yaddr * 1024 ) < 0 ) {
ALOGE ( " %s could not unmap %s " , __func__ , strerror ( errno ) ) ;
}
2014-01-02 15:48:30 +00:00
} else {
2014-11-20 22:38:34 +00:00
if ( munmap ( ( void * ) ( hnd - > base - hnd - > offset ) , hnd - > offset + hnd - > size ) < 0 ) {
ALOGE ( " %s could not unmap %s " , __func__ , strerror ( errno ) ) ;
}
2013-10-27 19:51:25 +00:00
}
2012-05-20 10:00:36 +00:00
2014-11-20 22:38:34 +00:00
hnd - > base = 0 ;
2014-01-02 15:48:30 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
2014-11-20 22:38:34 +00:00
return 0 ;
} else {
ALOGE ( " %s unregistering non-UMP buffer not supported " , __func__ ) ;
2014-01-02 15:48:30 +00:00
}
2013-10-27 19:51:25 +00:00
2014-11-20 22:38:34 +00:00
pthread_mutex_unlock ( & s_map_lock ) ;
/*} not in stock */
2012-05-20 10:00:36 +00:00
return 0 ;
}
2018-12-24 22:50:16 +00:00
void * gralloc_unregister_buffer_thread ( void * data ) {
private_handle_t * hnd = ( private_handle_t * ) data ;
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d START " , __func__ , hnd - > ump_id ) ;
usleep ( 1000000 ) ; // 1000ms
unregister_buffer ( hnd ) ;
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d END " , __func__ , hnd - > ump_id ) ;
2018-12-29 23:00:47 +00:00
delete hnd ;
2018-12-24 22:50:16 +00:00
return NULL ;
}
2018-12-24 21:12:38 +00:00
2018-12-29 23:00:47 +00:00
static private_handle_t * clone_private_handle ( private_handle_t * hnd ) {
private_handle_t * result = new private_handle_t (
hnd - > flags ,
hnd - > size ,
hnd - > base ,
hnd - > lockState ,
( ump_secure_id ) hnd - > ump_id ,
( ump_handle ) hnd - > ump_mem_handle ,
hnd - > fd ,
hnd - > offset ,
hnd - > paddr ) ;
result - > magic = hnd - > magic ;
result - > base = hnd - > base ;
result - > writeOwner = hnd - > writeOwner ;
result - > pid = hnd - > pid ;
result - > format = hnd - > format ;
result - > usage = hnd - > usage ;
result - > width = hnd - > width ;
result - > height = hnd - > height ;
result - > bpp = hnd - > bpp ;
result - > stride = hnd - > stride ;
result - > yaddr = hnd - > yaddr ;
result - > uoffset = hnd - > uoffset ;
result - > voffset = hnd - > voffset ;
result - > ion_client = hnd - > ion_client ;
result - > ion_memory = hnd - > ion_memory ;
result - > backing_store = hnd - > backing_store ;
result - > producer_usage = hnd - > producer_usage ;
result - > consumer_usage = hnd - > consumer_usage ;
return result ;
}
2018-12-24 21:12:38 +00:00
static int gralloc_unregister_buffer ( gralloc_module_t const * module , buffer_handle_t handle )
{
if ( private_handle_t : : validate ( handle ) < 0 ) {
ALOGE ( " %s unregistering invalid buffer, returning error " , __func__ ) ;
return - EINVAL ;
}
private_handle_t * hnd = ( private_handle_t * ) handle ;
2018-12-24 22:50:16 +00:00
ALOGD_IF ( debug_level > 1 , " %s: ump_id:%d " , __func__ , hnd - > ump_id ) ;
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_GRAPHICBUFFER ) {
pthread_attr_t thread_attr ;
pthread_t unreg_buffer_thread ;
pthread_attr_init ( & thread_attr ) ;
pthread_attr_setdetachstate ( & thread_attr , PTHREAD_CREATE_DETACHED ) ;
int rc = pthread_create ( & unreg_buffer_thread , & thread_attr ,
2018-12-29 23:00:47 +00:00
gralloc_unregister_buffer_thread , ( void * ) clone_private_handle ( hnd ) ) ;
2018-12-24 22:50:16 +00:00
if ( rc < 0 ) {
ALOGE ( " %s: Unable to create thread " , __func__ ) ;
return - 1 ;
}
return 0 ;
}
2018-12-24 21:12:38 +00:00
return unregister_buffer ( hnd ) ;
}
2018-08-13 20:39:50 +00:00
static int gralloc_lock ( gralloc_module_t const * module __unused , buffer_handle_t handle ,
int usage , int l __unused , int t __unused , int w __unused ,
int h __unused , void * * vaddr )
2012-05-20 10:00:36 +00:00
{
if ( private_handle_t : : validate ( handle ) < 0 ) {
2012-07-22 13:45:33 +00:00
ALOGE ( " Locking invalid buffer, returning error " ) ;
2012-05-20 10:00:36 +00:00
return - EINVAL ;
}
private_handle_t * hnd = ( private_handle_t * ) handle ;
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s hnd->flags=0x%x usage=0x%x l=%d t=%d w=%d h=%d " , __func__ , hnd - > flags , usage , l , t , w , h ) ;
2012-05-20 10:00:36 +00:00
# ifdef SAMSUNG_EXYNOS_CACHE_UMP
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_UMP ) {
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s private_handle_t::PRIV_FLAGS_USES_UMP hnd->ump_id=%d " , __func__ , hnd - > ump_id ) ;
2012-05-20 10:00:36 +00:00
# ifdef USE_PARTIAL_FLUSH
private_handle_rect * psRect ;
psRect = find_rect ( ( int ) hnd - > ump_id ) ;
2014-11-20 22:38:34 +00:00
if ( psRect ) {
psRect - > l = l ;
psRect - > t = t ;
psRect - > w = w ;
psRect - > h = h ;
psRect - > locked = 1 ;
}
2012-05-20 10:00:36 +00:00
# endif
2014-11-20 22:38:34 +00:00
hnd - > writeOwner = usage & GRALLOC_USAGE_SW_WRITE_MASK ;
2014-12-18 14:33:24 +00:00
if ( ( usage & GRALLOC_USAGE_SW_READ_MASK ) = = GRALLOC_USAGE_SW_READ_OFTEN )
ump_cpu_msync_now ( ( ump_handle ) hnd - > ump_mem_handle , UMP_MSYNC_CLEAN_AND_INVALIDATE , NULL , 0 ) ;
2012-05-20 10:00:36 +00:00
}
# endif
if ( usage & GRALLOC_USAGE_YUV_ADDR ) {
2018-03-02 17:56:54 +00:00
// Create pointer to 3 pointers for YUV addresses
void * * pAddr = ( void * * ) malloc ( 3 * sizeof ( void * ) ) ;
pAddr [ 0 ] = ( void * ) hnd - > base ;
pAddr [ 1 ] = ( void * ) ( hnd - > base + hnd - > uoffset ) ;
pAddr [ 2 ] = ( void * ) ( hnd - > base + hnd - > uoffset + hnd - > voffset ) ;
* vaddr = pAddr ;
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s vaddr[0]=%x vaddr[1]=%x vaddr[2]=%x " , __func__ , vaddr [ 0 ] , vaddr [ 1 ] , vaddr [ 2 ] ) ;
} else {
if ( ( usage & ( GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK ) ) | | ( usage = = 0 ) )
* vaddr = ( void * ) hnd - > base ;
ALOGD_IF ( debug_level > 0 , " %s vaddr=%x hnd->base=%x " , __func__ , * vaddr , hnd - > base ) ;
2012-05-20 10:00:36 +00:00
}
2014-11-20 22:38:34 +00:00
return 0 ;
2012-05-20 10:00:36 +00:00
}
static int gralloc_unlock ( gralloc_module_t const * module , buffer_handle_t handle )
{
2014-11-20 22:38:34 +00:00
ump_cpu_msync_op ump_op = UMP_MSYNC_CLEAN ;
int ret ;
exynos_mem_flush_range mem ;
2012-05-20 10:00:36 +00:00
if ( private_handle_t : : validate ( handle ) < 0 ) {
2014-11-20 22:38:34 +00:00
ALOGE ( " %s Unlocking invalid buffer, returning error " , __func__ ) ;
2012-05-20 10:00:36 +00:00
return - EINVAL ;
}
private_handle_t * hnd = ( private_handle_t * ) handle ;
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s hnd->flags=%x " , __func__ , hnd - > flags ) ;
2012-05-20 10:00:36 +00:00
# ifdef SAMSUNG_EXYNOS_CACHE_UMP
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_UMP ) {
2014-11-20 22:38:34 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_ION ) {
if ( ! ( hnd - > flags & private_handle_t : : PRIV_FLAGS_NONE_CACHED ) ) {
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_HDMI )
ump_op = UMP_MSYNC_CLEAN_AND_INVALIDATE ;
ump_cpu_msync_now ( ( ump_handle ) hnd - > ump_mem_handle , ump_op , ( void * ) hnd - > base , hnd - > size ) ;
}
} else {
2012-05-20 10:00:36 +00:00
# ifdef USE_PARTIAL_FLUSH
2014-11-20 22:38:34 +00:00
private_handle_rect * psRect ;
psRect = find_rect ( ( int ) hnd - > ump_id ) ;
if ( psRect ) {
ALOGD_IF ( debug_level > 0 , " %s rect found hnd->base=%x (psRect->stride(%d) * psRect->t(%d))=%d psRect->stride * psRect->h(%d)=%d " , __func__ , hnd - > base , psRect - > stride , psRect - > t , ( psRect - > stride * psRect - > t ) , psRect - > h , ( psRect - > stride * psRect - > h ) ) ;
2014-12-18 14:33:24 +00:00
ump_cpu_msync_now ( ( ump_handle ) hnd - > ump_mem_handle , UMP_MSYNC_CLEAN_AND_INVALIDATE ,
2014-11-20 22:38:34 +00:00
( void * ) ( hnd - > base + ( psRect - > stride * psRect - > t ) ) , psRect - > stride * psRect - > h ) ;
} else {
2014-12-18 14:33:24 +00:00
ump_cpu_msync_now ( ( ump_handle ) hnd - > ump_mem_handle , UMP_MSYNC_CLEAN_AND_INVALIDATE , NULL , 0 ) ;
2014-11-20 22:38:34 +00:00
}
2012-05-20 10:00:36 +00:00
# endif
2014-11-20 22:38:34 +00:00
}
return 0 ;
2012-05-20 10:00:36 +00:00
}
# endif
2014-11-20 22:38:34 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_NONE_CACHED )
return 0 ;
2012-05-20 10:00:36 +00:00
if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_IOCTL ) {
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s private_handle_t::PRIV_FLAGS_USES_IOCTL mem.start=%x mem.length=%x " , __func__ , hnd - > paddr , hnd - > size ) ;
mem . start = hnd - > paddr ;
mem . length = hnd - > size ;
ret = ioctl ( gMemfd , EXYNOS_MEM_PADDR_CACHE_CLEAN , & mem ) ;
if ( ret < 0 ) {
ALOGE ( " %s Error in exynos-mem : EXYNOS_MEM_PADDR_CACHE_CLEAN (%d) \n " , __func__ , ret ) ;
}
} else if ( hnd - > flags & private_handle_t : : PRIV_FLAGS_USES_HDMI ) {
ALOGD_IF ( debug_level > 0 , " %s private_handle_t::PRIV_FLAGS_USES_HDMI mem.start=%x mem.length=%x " , __func__ , hnd - > paddr , hnd - > size ) ;
2012-05-20 10:00:36 +00:00
mem . start = hnd - > paddr ;
mem . length = hnd - > size ;
ret = ioctl ( gMemfd , EXYNOS_MEM_PADDR_CACHE_FLUSH , & mem ) ;
if ( ret < 0 ) {
2014-11-20 22:38:34 +00:00
ALOGE ( " %s Error in exynos-mem : EXYNOS_MEM_PADDR_CACHE_FLUSH (%d) \n " , __func__ , ret ) ;
2012-05-20 10:00:36 +00:00
}
2014-11-20 22:38:34 +00:00
} else
return 1 ;
2012-05-20 10:00:36 +00:00
return 0 ;
}
2017-10-12 11:16:34 +00:00
static int gralloc_perform ( struct gralloc_module_t const * module ,
int operation , . . . )
{
int res = - EINVAL ;
va_list args ;
if ( ! module )
return res ;
va_start ( args , operation ) ;
switch ( operation ) {
case GRALLOC1_ADAPTER_PERFORM_GET_REAL_MODULE_API_VERSION_MINOR :
{
auto outMinorVersion = va_arg ( args , int * ) ;
* outMinorVersion = 0 ;
ALOGV ( " %s: GRALLOC1_ADAPTER_PERFORM_GET_REAL_MODULE_API_VERSION_MINOR %d " ,
__func__ , * outMinorVersion ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_SET_USAGES :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto producerUsage = va_arg ( args , uint64_t ) ;
auto consumerUsage = va_arg ( args , uint64_t ) ;
hnd - > producer_usage = producerUsage ;
hnd - > consumer_usage = consumerUsage ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_SET_USAGES p:0x%08x c:0x%08x " , __func__ ,
hnd , producerUsage , consumerUsage ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_GET_DIMENSIONS :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto outWidth = va_arg ( args , int * ) ;
auto outHeight = va_arg ( args , int * ) ;
* outWidth = hnd - > width ;
* outHeight = hnd - > height ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_DIMENSIONS %d x %d " , __func__ ,
hnd , * outWidth , * outHeight ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_GET_FORMAT :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto outFormat = va_arg ( args , int * ) ;
* outFormat = hnd - > format ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_FORMAT %d " , __func__ ,
hnd , * outFormat ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_GET_PRODUCER_USAGE :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto outUsage = va_arg ( args , uint64_t * ) ;
* outUsage = hnd - > producer_usage ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_PRODUCER_USAGE 0x%08x " , __func__ ,
hnd , hnd - > producer_usage ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_GET_CONSUMER_USAGE :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto outUsage = va_arg ( args , uint64_t * ) ;
* outUsage = hnd - > consumer_usage ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_CONSUMER_USAGE 0x%08x " , __func__ ,
hnd , hnd - > consumer_usage ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_GET_BACKING_STORE :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto outBackingStore = va_arg ( args , uint64_t * ) ;
* outBackingStore = hnd - > backing_store ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_BACKING_STORE %llu " , __func__ ,
hnd , * outBackingStore ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_GET_NUM_FLEX_PLANES :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto outNumFlexPlanes = va_arg ( args , int * ) ;
( void ) hnd ;
// for simpilicity
* outNumFlexPlanes = 4 ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_NUM_FLEX_PLANES %d " , __func__ ,
hnd , * outNumFlexPlanes ) ;
} break ;
case GRALLOC1_ADAPTER_PERFORM_GET_STRIDE :
{
auto hnd = va_arg ( args , private_handle_t * ) ;
auto outStride = va_arg ( args , int * ) ;
* outStride = hnd - > width ;
ALOGV ( " %s: (%p) GRALLOC1_ADAPTER_PERFORM_GET_STRIDE %d " , __func__ ,
hnd , * outStride ) ;
} break ;
default :
ALOGE ( " %s: NOT IMPLEMENTED %d " , __func__ , operation ) ;
break ;
}
va_end ( args ) ;
return res ;
}
2012-05-20 10:00:36 +00:00
static int gralloc_getphys ( gralloc_module_t const * module , buffer_handle_t handle , void * * paddr )
{
private_handle_t * hnd = ( private_handle_t * ) handle ;
paddr [ 0 ] = ( void * ) hnd - > paddr ;
2014-11-20 22:38:34 +00:00
ALOGD_IF ( debug_level > 0 , " %s paddr[0]=0x%x paddr[1]=0x%x paddr[2]=0x%x " , __func__ , paddr [ 0 ] , paddr [ 1 ] , paddr [ 2 ] ) ;
2012-05-20 10:00:36 +00:00
return 0 ;
}
/* There is one global instance of the module */
static struct hw_module_methods_t gralloc_module_methods =
{
open : gralloc_device_open
} ;
struct private_module_t HAL_MODULE_INFO_SYM =
{
base :
{
common :
{
tag : HARDWARE_MODULE_TAG ,
2017-10-12 11:16:34 +00:00
# ifdef ADVERTISE_GRALLOC1
version_major : GRALLOC1_ADAPTER_MODULE_API_VERSION_1_0 ,
# else
2012-05-20 10:00:36 +00:00
version_major : 1 ,
2017-10-12 11:16:34 +00:00
# endif
2012-05-20 10:00:36 +00:00
version_minor : 0 ,
id : GRALLOC_HARDWARE_MODULE_ID ,
name : " Graphics Memory Allocator Module " ,
author : " ARM Ltd. " ,
methods : & gralloc_module_methods ,
dso : NULL ,
2014-11-20 22:38:34 +00:00
reserved : { 0 , } ,
2012-05-20 10:00:36 +00:00
} ,
registerBuffer : gralloc_register_buffer ,
unregisterBuffer : gralloc_unregister_buffer ,
lock : gralloc_lock ,
unlock : gralloc_unlock ,
2017-11-07 06:42:05 +00:00
// getphys: gralloc_getphys,
2017-10-12 11:16:34 +00:00
perform : gralloc_perform ,
2014-11-20 22:38:34 +00:00
lock_ycbcr : NULL ,
2012-05-20 10:00:36 +00:00
} ,
framebuffer : NULL ,
flags : 0 ,
numBuffers : 0 ,
bufferMask : 0 ,
lock : PTHREAD_MUTEX_INITIALIZER ,
currentBuffer : NULL ,
2014-11-20 22:38:34 +00:00
ion_client : - 1 ,
2012-05-20 10:00:36 +00:00
} ;