1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LIB_DMA_BUF_HEAP_H 17 #define LIB_DMA_BUF_HEAP_H 18 19 #include <stdlib.h> 20 #include <linux/dma-buf.h> 21 22 #undef LOG_TAG 23 #define LOG_TAG "dmabufheap" 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif /* End of #if __cplusplus */ 29 #endif /* End of #ifdef __cplusplus */ 30 31 typedef enum { 32 DMA_BUF_HEAP_BUF_SYNC_RW = DMA_BUF_SYNC_RW, 33 DMA_BUF_HEAP_BUF_SYNC_READ = DMA_BUF_SYNC_READ, 34 DMA_BUF_HEAP_BUF_SYNC_WRITE = DMA_BUF_SYNC_WRITE, 35 } DmabufHeapBufferSyncType; 36 37 typedef struct { 38 unsigned int fd; 39 size_t size; 40 } DmabufHeapBuffer; 41 42 int DmabufHeapOpen(const char *heapName); 43 44 int DmabufHeapClose(unsigned int fd); 45 46 int DmabufHeapBufferAlloc(unsigned int heapFd, DmabufHeapBuffer *buffer); 47 48 int DmabufHeapBufferFree(DmabufHeapBuffer *buffer); 49 50 int DmabufHeapBufferSyncStart(unsigned int bufferFd, DmabufHeapBufferSyncType syncType); 51 52 int DmabufHeapBufferSyncEnd(unsigned int bufferFd, DmabufHeapBufferSyncType syncType); 53 54 #ifdef __cplusplus 55 #if __cplusplus 56 } 57 #endif /* End of #if __cplusplus */ 58 #endif /* End of #ifdef __cplusplus */ 59 60 #endif /* LIB_DMA_BUF_HEAP_H */