1202a77d28ac251545f6f998a974690212309b927Iliyan Malchev/* 2202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * Copyright (C) 2008, The Android Open Source Project 3ccce8eb92266908162dbf92ef1e901204a2b8354Naseer Ahmed * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. 4202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * 5202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * Licensed under the Apache License, Version 2.0 (the "License"); 6202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * you may not use this file except in compliance with the License. 7202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * You may obtain a copy of the License at 8202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * 9202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * http://www.apache.org/licenses/LICENSE-2.0 10202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * 11202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * Unless required by applicable law or agreed to in writing, software 12202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * distributed under the License is distributed on an "AS IS" BASIS, 13202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * See the License for the specific language governing permissions and 15202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * limitations under the License. 16202a77d28ac251545f6f998a974690212309b927Iliyan Malchev */ 17202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 18202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <unistd.h> 19202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <fcntl.h> 20202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 21202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <sys/mman.h> 22202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <sys/stat.h> 23202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <sys/types.h> 24202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <sys/ioctl.h> 25202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <cutils/properties.h> 26202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 27202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <linux/android_pmem.h> 28202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 29202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include "gr.h" 30202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include "gpu.h" 31202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include "memalloc.h" 32202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include "alloc_controller.h" 33202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 34202a77d28ac251545f6f998a974690212309b927Iliyan Malchevusing namespace gralloc; 35202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 36ccce8eb92266908162dbf92ef1e901204a2b8354Naseer Ahmedint fb_device_open(const hw_module_t* module, const char* name, 37ccce8eb92266908162dbf92ef1e901204a2b8354Naseer Ahmed hw_device_t** device); 38ccce8eb92266908162dbf92ef1e901204a2b8354Naseer Ahmed 39202a77d28ac251545f6f998a974690212309b927Iliyan Malchevstatic int gralloc_device_open(const hw_module_t* module, const char* name, 4029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed hw_device_t** device); 41202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 42202a77d28ac251545f6f998a974690212309b927Iliyan Malchevextern int gralloc_lock(gralloc_module_t const* module, 4329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed buffer_handle_t handle, int usage, 4429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int l, int t, int w, int h, 4529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed void** vaddr); 46202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 47277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmedextern int gralloc_lock_ycbcr(gralloc_module_t const* module, 48277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed buffer_handle_t handle, int usage, 49277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed int l, int t, int w, int h, 50277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed struct android_ycbcr *ycbcr); 51277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed 52202a77d28ac251545f6f998a974690212309b927Iliyan Malchevextern int gralloc_unlock(gralloc_module_t const* module, 5329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed buffer_handle_t handle); 54202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 55202a77d28ac251545f6f998a974690212309b927Iliyan Malchevextern int gralloc_register_buffer(gralloc_module_t const* module, 5629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed buffer_handle_t handle); 57202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 58202a77d28ac251545f6f998a974690212309b927Iliyan Malchevextern int gralloc_unregister_buffer(gralloc_module_t const* module, 5929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed buffer_handle_t handle); 60202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 61202a77d28ac251545f6f998a974690212309b927Iliyan Malchevextern int gralloc_perform(struct gralloc_module_t const* module, 6229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed int operation, ... ); 63202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 64202a77d28ac251545f6f998a974690212309b927Iliyan Malchev// HAL module methods 65202a77d28ac251545f6f998a974690212309b927Iliyan Malchevstatic struct hw_module_methods_t gralloc_module_methods = { 66277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed open: gralloc_device_open 67202a77d28ac251545f6f998a974690212309b927Iliyan Malchev}; 68202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 69202a77d28ac251545f6f998a974690212309b927Iliyan Malchev// HAL module initialize 70202a77d28ac251545f6f998a974690212309b927Iliyan Malchevstruct private_module_t HAL_MODULE_INFO_SYM = { 71277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed base: { 72277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed common: { 73277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed tag: HARDWARE_MODULE_TAG, 74277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed module_api_version: GRALLOC_MODULE_API_VERSION_0_2, 75277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed hal_api_version: 0, 76277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed id: GRALLOC_HARDWARE_MODULE_ID, 77277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed name: "Graphics Memory Allocator Module", 78277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed author: "The Android Open Source Project", 79277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed methods: &gralloc_module_methods, 80277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed dso: 0, 81277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed }, 82277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed registerBuffer: gralloc_register_buffer, 83277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed unregisterBuffer: gralloc_unregister_buffer, 84277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed lock: gralloc_lock, 85277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed unlock: gralloc_unlock, 86277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed perform: gralloc_perform, 87277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed lock_ycbcr: gralloc_lock_ycbcr, 88277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed }, 89277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed framebuffer: 0, 90277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed fbFormat: 0, 91277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed flags: 0, 92277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed numBuffers: 0, 93277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed bufferMask: 0, 94277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed lock: PTHREAD_MUTEX_INITIALIZER, 95277b124c636c4bfc891d2481fe939224b93d788eNaseer Ahmed currentBuffer: 0, 96202a77d28ac251545f6f998a974690212309b927Iliyan Malchev}; 97202a77d28ac251545f6f998a974690212309b927Iliyan Malchev 98202a77d28ac251545f6f998a974690212309b927Iliyan Malchev// Open Gralloc device 99202a77d28ac251545f6f998a974690212309b927Iliyan Malchevint gralloc_device_open(const hw_module_t* module, const char* name, 10029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed hw_device_t** device) 101202a77d28ac251545f6f998a974690212309b927Iliyan Malchev{ 102202a77d28ac251545f6f998a974690212309b927Iliyan Malchev int status = -EINVAL; 103202a77d28ac251545f6f998a974690212309b927Iliyan Malchev if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) { 104202a77d28ac251545f6f998a974690212309b927Iliyan Malchev const private_module_t* m = reinterpret_cast<const private_module_t*>( 10529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed module); 106202a77d28ac251545f6f998a974690212309b927Iliyan Malchev gpu_context_t *dev; 10701d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmed IAllocController* alloc_ctrl = IAllocController::getInstance(); 108202a77d28ac251545f6f998a974690212309b927Iliyan Malchev dev = new gpu_context_t(m, alloc_ctrl); 109202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *device = &dev->common; 110202a77d28ac251545f6f998a974690212309b927Iliyan Malchev status = 0; 111ccce8eb92266908162dbf92ef1e901204a2b8354Naseer Ahmed } else { 112ccce8eb92266908162dbf92ef1e901204a2b8354Naseer Ahmed status = fb_device_open(module, name, device); 113202a77d28ac251545f6f998a974690212309b927Iliyan Malchev } 114202a77d28ac251545f6f998a974690212309b927Iliyan Malchev return status; 115202a77d28ac251545f6f998a974690212309b927Iliyan Malchev} 116