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