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