fix gralloc qsd8k. we actually don't need to use /pmem/gpu1, since the gpu is now able to use regular PMEM.
this module is now closer to the generic gralloc module, although it will have to evolve in the near future.
This commit is contained in:
parent
2261332f74
commit
173ba48dd3
113
gralloc.cpp
113
gralloc.cpp
@ -43,10 +43,7 @@
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define ALLOCATORREGION_RESERVED_SIZE (3<<20)
|
||||
|
||||
static SimpleBestFitAllocator sAllocator;
|
||||
static SimpleBestFitAllocator sAllocatorGPU(ALLOCATORREGION_RESERVED_SIZE);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@ -110,9 +107,7 @@ struct private_module_t HAL_MODULE_INFO_SYM = {
|
||||
currentBuffer: 0,
|
||||
pmem_master: -1,
|
||||
pmem_master_base: 0,
|
||||
master_phys: 0,
|
||||
gpu: -1,
|
||||
gpu_base: 0
|
||||
master_phys: 0
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -166,6 +161,7 @@ static int gralloc_alloc_framebuffer_locked(alloc_device_t* dev,
|
||||
|
||||
hnd->base = vaddr;
|
||||
hnd->offset = vaddr - intptr_t(m->framebuffer->base);
|
||||
hnd->phys = intptr_t(m->framebuffer->phys) + hnd->offset;
|
||||
*pHandle = hnd;
|
||||
|
||||
return 0;
|
||||
@ -188,7 +184,6 @@ static int init_pmem_area_locked(private_module_t* m)
|
||||
int err = 0;
|
||||
int master_fd = open("/dev/pmem", O_RDWR, 0);
|
||||
if (master_fd >= 0) {
|
||||
|
||||
size_t size;
|
||||
pmem_region region;
|
||||
if (ioctl(master_fd, PMEM_GET_TOTAL_SIZE, ®ion) < 0) {
|
||||
@ -206,6 +201,15 @@ static int init_pmem_area_locked(private_module_t* m)
|
||||
base = 0;
|
||||
close(master_fd);
|
||||
master_fd = -1;
|
||||
} else {
|
||||
// FIXME: get physical address, eventually this will have to go away
|
||||
pmem_region region;
|
||||
err = ioctl(master_fd, PMEM_GET_PHYS, ®ion);
|
||||
if (err < 0) {
|
||||
LOGE("PMEM_GET_PHYS failed (%s)", strerror(-errno));
|
||||
} else {
|
||||
m->master_phys = (unsigned long)region.offset;
|
||||
}
|
||||
}
|
||||
m->pmem_master = master_fd;
|
||||
m->pmem_master_base = base;
|
||||
@ -235,63 +239,6 @@ static int init_pmem_area(private_module_t* m)
|
||||
return err;
|
||||
}
|
||||
|
||||
static int init_gpu_area_locked(private_module_t* m)
|
||||
{
|
||||
int err = 0;
|
||||
int gpu = open("/dev/pmem_gpu1", O_RDWR, 0);
|
||||
LOGE_IF(gpu<0, "could not open /dev/pmem_gpu1 (%s)", strerror(errno));
|
||||
if (gpu >= 0) {
|
||||
size_t size = sAllocatorGPU.size();
|
||||
void* base = mmap(0, size,
|
||||
PROT_READ|PROT_WRITE, MAP_SHARED, gpu, 0);
|
||||
|
||||
if (base == MAP_FAILED) {
|
||||
LOGE("mmap /dev/pmem_gpu1 (%s)", strerror(errno));
|
||||
err = -errno;
|
||||
base = 0;
|
||||
close(gpu);
|
||||
gpu = -1;
|
||||
} else {
|
||||
pmem_region region;
|
||||
err = ioctl(gpu, PMEM_GET_PHYS, ®ion);
|
||||
if(err < 0) {
|
||||
LOGE("init pmem: master ioctl failed %d", -errno);
|
||||
} else {
|
||||
m->master_phys = (unsigned long)region.offset;
|
||||
}
|
||||
}
|
||||
|
||||
m->gpu = gpu;
|
||||
m->gpu_base = base;
|
||||
|
||||
} else {
|
||||
err = -errno;
|
||||
m->gpu = 0;
|
||||
m->gpu_base = 0;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static int init_gpu_area(private_module_t* m)
|
||||
{
|
||||
pthread_mutex_lock(&m->lock);
|
||||
int err = m->gpu;
|
||||
if (err == -1) {
|
||||
// first time, try to initialize gpu
|
||||
err = init_gpu_area_locked(m);
|
||||
if (err) {
|
||||
m->gpu = err;
|
||||
}
|
||||
} else if (err < 0) {
|
||||
// gpu couldn't be initialized, never use it
|
||||
} else {
|
||||
// gpu OK
|
||||
err = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&m->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int gralloc_alloc_buffer(alloc_device_t* dev,
|
||||
size_t size, int usage, buffer_handle_t* pHandle)
|
||||
{
|
||||
@ -299,7 +246,6 @@ static int gralloc_alloc_buffer(alloc_device_t* dev,
|
||||
int flags = 0;
|
||||
|
||||
int fd = -1;
|
||||
int gpu_fd = -1;
|
||||
void* base = 0;
|
||||
int offset = 0;
|
||||
int lockState = 0;
|
||||
@ -323,7 +269,7 @@ try_ashmem:
|
||||
LOGE("couldn't create ashmem (%s)", strerror(errno));
|
||||
err = -errno;
|
||||
}
|
||||
} else if ((usage & GRALLOC_USAGE_HW_RENDER) == 0) {
|
||||
} else {
|
||||
private_module_t* m = reinterpret_cast<private_module_t*>(
|
||||
dev->common.module);
|
||||
|
||||
@ -371,35 +317,6 @@ try_ashmem:
|
||||
LOGE("couldn't open pmem (%s)", strerror(errno));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// looks like we want 3D...
|
||||
flags &= ~private_handle_t::PRIV_FLAGS_USES_PMEM;
|
||||
flags |= private_handle_t::PRIV_FLAGS_USES_GPU;
|
||||
|
||||
private_module_t* m = reinterpret_cast<private_module_t*>(
|
||||
dev->common.module);
|
||||
|
||||
err = init_gpu_area(m);
|
||||
if (err == 0) {
|
||||
// GPU buffers are always mmapped
|
||||
base = m->gpu_base;
|
||||
lockState |= private_handle_t::LOCK_STATE_MAPPED;
|
||||
offset = sAllocatorGPU.allocate(size);
|
||||
if (offset < 0) {
|
||||
// no more pmem memory
|
||||
err = -ENOMEM;
|
||||
} else {
|
||||
LOGD("allocating GPU size=%d, offset=%d", size, offset);
|
||||
fd = open("/dev/null", O_RDONLY); // just so marshalling doesn't fail
|
||||
gpu_fd = m->gpu;
|
||||
memset((char*)base + offset, 0, size);
|
||||
}
|
||||
} else {
|
||||
// not enough memory, try ashmem
|
||||
flags &= ~private_handle_t::PRIV_FLAGS_USES_GPU;
|
||||
err = 0;
|
||||
goto try_ashmem;
|
||||
}
|
||||
}
|
||||
|
||||
if (err == 0) {
|
||||
@ -407,8 +324,7 @@ try_ashmem:
|
||||
hnd->offset = offset;
|
||||
hnd->base = int(base)+offset;
|
||||
hnd->lockState = lockState;
|
||||
hnd->gpu_fd = gpu_fd;
|
||||
if (flags & private_handle_t::PRIV_FLAGS_USES_GPU) {
|
||||
if (flags & private_handle_t::PRIV_FLAGS_USES_PMEM) {
|
||||
private_module_t* m = reinterpret_cast<private_module_t*>(
|
||||
dev->common.module);
|
||||
hnd->phys = m->master_phys + offset;
|
||||
@ -517,9 +433,6 @@ static int gralloc_free(alloc_device_t* dev,
|
||||
sAllocator.deallocate(hnd->offset);
|
||||
}
|
||||
}
|
||||
} else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_GPU) {
|
||||
LOGD("freeing GPU buffer at %d", hnd->offset);
|
||||
sAllocatorGPU.deallocate(hnd->offset);
|
||||
}
|
||||
|
||||
gralloc_module_t* module = reinterpret_cast<gralloc_module_t*>(
|
||||
|
@ -46,8 +46,6 @@ struct private_module_t {
|
||||
int pmem_master;
|
||||
void* pmem_master_base;
|
||||
unsigned long master_phys;
|
||||
int gpu;
|
||||
void* gpu_base;
|
||||
|
||||
struct fb_var_screeninfo info;
|
||||
struct fb_fix_screeninfo finfo;
|
||||
@ -73,7 +71,6 @@ struct private_handle_t {
|
||||
enum {
|
||||
PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
|
||||
PRIV_FLAGS_USES_PMEM = 0x00000002,
|
||||
PRIV_FLAGS_USES_GPU = 0x00000004,
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -104,8 +101,8 @@ struct private_handle_t {
|
||||
static const int sMagic = 'gmsm';
|
||||
|
||||
private_handle_t(int fd, int size, int flags) :
|
||||
fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
|
||||
base(0), lockState(0), writeOwner(0), pid(getpid())
|
||||
fd(fd), magic(sMagic), flags(flags), size(size), offset(0), gpu_fd(-1),
|
||||
base(0), lockState(0), writeOwner(0), phys(0), pid(getpid())
|
||||
{
|
||||
version = sizeof(native_handle);
|
||||
numInts = sNumInts;
|
||||
@ -116,7 +113,7 @@ struct private_handle_t {
|
||||
}
|
||||
|
||||
bool usesPhysicallyContiguousMemory() {
|
||||
return (flags & (PRIV_FLAGS_USES_PMEM|PRIV_FLAGS_USES_GPU)) != 0;
|
||||
return (flags & PRIV_FLAGS_USES_PMEM) != 0;
|
||||
}
|
||||
|
||||
static int validate(const native_handle* h) {
|
||||
|
@ -174,8 +174,6 @@ int terminateBuffer(gralloc_module_t const* module,
|
||||
// (see gralloc_alloc_buffer())
|
||||
gralloc_unmap(module, hnd);
|
||||
}
|
||||
} else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_GPU) {
|
||||
// XXX: for now do nothing here
|
||||
} else {
|
||||
gralloc_unmap(module, hnd);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user