blob: 59bf08b0cf4a7c12c37d77417eb3e822af8f8650 [file] [log] [blame]
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -07001/*
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
22extern "C" {
23
24BufferAllocator* CreateDmabufHeapBufferAllocator() {
25 return new BufferAllocator();
26}
27
28void FreeDmabufHeapBufferAllocator(BufferAllocator* buffer_allocator) {
29 delete buffer_allocator;
30};
31
32int DmabufHeapAlloc(BufferAllocator* buffer_allocator, const char* heap_name, size_t len,
Hridya Valsarajuf7b3d5d2021-03-22 14:52:57 -070033 unsigned int heap_flags, size_t legacy_align) {
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -070034 if (!buffer_allocator)
35 return -EINVAL;
Hridya Valsarajuf7b3d5d2021-03-22 14:52:57 -070036 return buffer_allocator->Alloc(heap_name, len, heap_flags, legacy_align);
37}
38
39int 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 Valsaraju77a3ad62020-06-22 17:41:16 -070043}
44
45int 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
55int DmabufHeapCpuSyncStart(BufferAllocator* buffer_allocator, unsigned int dmabuf_fd,
Chris Goldsworthyec5411c2020-08-14 10:14:59 -070056 SyncType sync_type, int (*legacy_ion_cpu_sync)(int, int, void *),
57 void *custom_data) {
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -070058 if (!buffer_allocator)
59 return -EINVAL;
Chris Goldsworthyec5411c2020-08-14 10:14:59 -070060 return buffer_allocator->CpuSyncStart(dmabuf_fd, sync_type, legacy_ion_cpu_sync,
61 custom_data);
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -070062}
63
64int DmabufHeapCpuSyncEnd(BufferAllocator* buffer_allocator, unsigned int dmabuf_fd,
Hridya Valsarajua83c24e2021-03-13 15:30:16 -080065 SyncType sync_type, int (*legacy_ion_cpu_sync)(int, int, void*),
66 void* custom_data) {
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -070067 if (!buffer_allocator)
68 return -EINVAL;
Hridya Valsarajua83c24e2021-03-13 15:30:16 -080069 return buffer_allocator->CpuSyncEnd(dmabuf_fd, sync_type, legacy_ion_cpu_sync, custom_data);
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -070070}
Hridya Valsarajub968e732021-05-12 16:58:54 -070071
72bool CheckIonSupport() {
73 return BufferAllocator::CheckIonSupport();
74}
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -070075}