1a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev/* 2a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * Copyright (C) 2008, The Android Open Source Project 35070c694011ddc30673ec68a9d1d74dc713c49f2Duy Truong * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. 4a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * 5a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * Licensed under the Apache License, Version 2.0 (the "License"); 6a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * you may not use this file except in compliance with the License. 7a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * You may obtain a copy of the License at 8a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * 9a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * http://www.apache.org/licenses/LICENSE-2.0 10a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * 11a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * Unless required by applicable law or agreed to in writing, software 12a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * distributed under the License is distributed on an "AS IS" BASIS, 13a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * See the License for the specific language governing permissions and 15a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev * limitations under the License. 16a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev */ 17a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 18a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include <unistd.h> 19a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include <fcntl.h> 20a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 21a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include <sys/mman.h> 22a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include <sys/stat.h> 23a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include <sys/types.h> 24a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include <sys/ioctl.h> 25a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include <cutils/properties.h> 26a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 27a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include "gr.h" 28a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include "gpu.h" 29a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include "memalloc.h" 30a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev#include "alloc_controller.h" 31a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 32a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevusing namespace gralloc; 33a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 34a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevint fb_device_open(const hw_module_t* module, const char* name, 35befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed hw_device_t** device); 36a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 37a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevstatic int gralloc_device_open(const hw_module_t* module, const char* name, 38befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed hw_device_t** device); 39a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 40a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevextern int gralloc_lock(gralloc_module_t const* module, 41befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed buffer_handle_t handle, int usage, 42befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed int l, int t, int w, int h, 43befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed void** vaddr); 44a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 45cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmedextern int gralloc_lock_ycbcr(gralloc_module_t const* module, 46cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed buffer_handle_t handle, int usage, 47cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed int l, int t, int w, int h, 48cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed struct android_ycbcr *ycbcr); 49cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed 50a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevextern int gralloc_unlock(gralloc_module_t const* module, 51befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed buffer_handle_t handle); 52a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 53a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevextern int gralloc_register_buffer(gralloc_module_t const* module, 54befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed buffer_handle_t handle); 55a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 56a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevextern int gralloc_unregister_buffer(gralloc_module_t const* module, 57befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed buffer_handle_t handle); 58a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 59a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevextern int gralloc_perform(struct gralloc_module_t const* module, 60befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed int operation, ... ); 61a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 62a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev// HAL module methods 63a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevstatic struct hw_module_methods_t gralloc_module_methods = { 64cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed open: gralloc_device_open 65a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev}; 66a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 67a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev// HAL module initialize 68a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevstruct private_module_t HAL_MODULE_INFO_SYM = { 69cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed base: { 70cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed common: { 71cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed tag: HARDWARE_MODULE_TAG, 72cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed version_major: 1, 73cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed version_minor: 0, 74cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed id: GRALLOC_HARDWARE_MODULE_ID, 75cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed name: "Graphics Memory Allocator Module", 76cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed author: "The Android Open Source Project", 77cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed methods: &gralloc_module_methods, 78cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed dso: 0, 79cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed reserved: {0}, 80cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed }, 81cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed registerBuffer: gralloc_register_buffer, 82cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed unregisterBuffer: gralloc_unregister_buffer, 83cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed lock: gralloc_lock, 84cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed unlock: gralloc_unlock, 85cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed perform: gralloc_perform, 86cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed lock_ycbcr: gralloc_lock_ycbcr, 87cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed }, 88cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed framebuffer: 0, 89cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed fbFormat: 0, 90cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed flags: 0, 91cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed numBuffers: 0, 92cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed bufferMask: 0, 93cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed lock: PTHREAD_MUTEX_INITIALIZER, 94cbc630614b5f9a3299bfde07377b991b4a87ae16Naseer Ahmed currentBuffer: 0, 95a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev}; 96a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev 97a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev// Open Gralloc device 98a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchevint gralloc_device_open(const hw_module_t* module, const char* name, 99befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed hw_device_t** device) 100a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev{ 101a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev int status = -EINVAL; 102a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) { 103a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev const private_module_t* m = reinterpret_cast<const private_module_t*>( 104befc466069680cb8a65b1f22ad44723d949128c8Naseer Ahmed module); 105a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev gpu_context_t *dev; 106be2e1bb9057c8d0666de057743eeb898c78f34b0Naseer Ahmed IAllocController* alloc_ctrl = IAllocController::getInstance(); 107a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev dev = new gpu_context_t(m, alloc_ctrl); 108a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev *device = &dev->common; 109a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev status = 0; 110a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev } else { 111a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev status = fb_device_open(module, name, device); 112a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev } 113a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev return status; 114a19f21d925628239ef52c8ce392fa4ada91df6fcIliyan Malchev} 115