Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <BufferAllocator/BufferAllocator.h> |
| 18 | #include <BufferAllocator/BufferAllocatorWrapper.h> |
| 19 | #include <errno.h> |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | extern "C" { |
| 23 | |
| 24 | BufferAllocator* CreateDmabufHeapBufferAllocator() { |
| 25 | return new BufferAllocator(); |
| 26 | } |
| 27 | |
| 28 | void FreeDmabufHeapBufferAllocator(BufferAllocator* buffer_allocator) { |
| 29 | delete buffer_allocator; |
| 30 | }; |
| 31 | |
| 32 | int DmabufHeapAlloc(BufferAllocator* buffer_allocator, const char* heap_name, size_t len, |
Hridya Valsaraju | f7b3d5d | 2021-03-22 14:52:57 -0700 | [diff] [blame] | 33 | unsigned int heap_flags, size_t legacy_align) { |
Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 34 | if (!buffer_allocator) |
| 35 | return -EINVAL; |
Hridya Valsaraju | f7b3d5d | 2021-03-22 14:52:57 -0700 | [diff] [blame] | 36 | return buffer_allocator->Alloc(heap_name, len, heap_flags, legacy_align); |
| 37 | } |
| 38 | |
| 39 | int DmabufHeapAllocSystem(BufferAllocator* buffer_allocator, bool cpu_access, size_t len, |
| 40 | unsigned int heap_flags, size_t legacy_align) { |
| 41 | if (!buffer_allocator) return -EINVAL; |
| 42 | return buffer_allocator->AllocSystem(cpu_access, len, heap_flags, legacy_align); |
Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | int MapDmabufHeapNameToIonHeap(BufferAllocator* buffer_allocator, const char* heap_name, |
| 46 | const char* ion_heap_name, unsigned int ion_heap_flags, |
| 47 | unsigned int legacy_ion_heap_mask, |
| 48 | unsigned int legacy_ion_heap_flags) { |
| 49 | if (!buffer_allocator) |
| 50 | return -EINVAL; |
| 51 | return buffer_allocator->MapNameToIonHeap(heap_name, ion_heap_name, ion_heap_flags, |
| 52 | legacy_ion_heap_mask, legacy_ion_heap_flags); |
| 53 | } |
| 54 | |
| 55 | int DmabufHeapCpuSyncStart(BufferAllocator* buffer_allocator, unsigned int dmabuf_fd, |
Chris Goldsworthy | ec5411c | 2020-08-14 10:14:59 -0700 | [diff] [blame] | 56 | SyncType sync_type, int (*legacy_ion_cpu_sync)(int, int, void *), |
| 57 | void *custom_data) { |
Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 58 | if (!buffer_allocator) |
| 59 | return -EINVAL; |
Chris Goldsworthy | ec5411c | 2020-08-14 10:14:59 -0700 | [diff] [blame] | 60 | return buffer_allocator->CpuSyncStart(dmabuf_fd, sync_type, legacy_ion_cpu_sync, |
| 61 | custom_data); |
Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | int DmabufHeapCpuSyncEnd(BufferAllocator* buffer_allocator, unsigned int dmabuf_fd, |
Hridya Valsaraju | a83c24e | 2021-03-13 15:30:16 -0800 | [diff] [blame] | 65 | SyncType sync_type, int (*legacy_ion_cpu_sync)(int, int, void*), |
| 66 | void* custom_data) { |
Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 67 | if (!buffer_allocator) |
| 68 | return -EINVAL; |
Hridya Valsaraju | a83c24e | 2021-03-13 15:30:16 -0800 | [diff] [blame] | 69 | return buffer_allocator->CpuSyncEnd(dmabuf_fd, sync_type, legacy_ion_cpu_sync, custom_data); |
Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 70 | } |
Hridya Valsaraju | b968e73 | 2021-05-12 16:58:54 -0700 | [diff] [blame] | 71 | |
| 72 | bool CheckIonSupport() { |
| 73 | return BufferAllocator::CheckIonSupport(); |
| 74 | } |
Hridya Valsaraju | 77a3ad6 | 2020-06-22 17:41:16 -0700 | [diff] [blame] | 75 | } |