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#include <linux/dma-heap.h>
22
23#undef LOG_TAG
24#define LOG_TAG "dmabufheap"
25
26#ifdef __cplusplus
27#if __cplusplus
28extern "C" {
29#endif /* End of #if __cplusplus */
30#endif /* End of #ifdef __cplusplus */
31
32typedef enum {
33    DMA_BUF_HEAP_BUF_SYNC_RW = DMA_BUF_SYNC_RW,
34    DMA_BUF_HEAP_BUF_SYNC_READ = DMA_BUF_SYNC_READ,
35    DMA_BUF_HEAP_BUF_SYNC_WRITE = DMA_BUF_SYNC_WRITE,
36} DmabufHeapBufferSyncType;
37
38typedef struct {
39    unsigned int fd;
40    size_t size;
41    __u64 heapFlags;
42} DmabufHeapBuffer;
43
44enum DmaHeapFlagOwnerId {
45    DMA_OWNER_DEFAULT,
46    DMA_OWNER_GPU,
47    DMA_OWNER_MEDIA_CODEC,
48    COUNT_DMA_OWNER,
49};
50
51void SetOwnerIdForHeapFlags(DmabufHeapBuffer *buffer, enum DmaHeapFlagOwnerId ownerId);
52
53int DmabufHeapOpen(const char *heapName);
54
55int DmabufHeapClose(unsigned int fd);
56
57int DmabufHeapBufferAlloc(unsigned int heapFd, DmabufHeapBuffer *buffer);
58
59int DmabufHeapBufferFree(DmabufHeapBuffer *buffer);
60
61int DmabufHeapBufferSyncStart(unsigned int bufferFd, DmabufHeapBufferSyncType syncType);
62
63int DmabufHeapBufferSyncEnd(unsigned int bufferFd, DmabufHeapBufferSyncType syncType);
64
65#ifdef __cplusplus
66#if __cplusplus
67}
68#endif /* End of #if __cplusplus */
69#endif /* End of #ifdef __cplusplus */
70
71#endif /* LIB_DMA_BUF_HEAP_H */