94 lines
2.9 KiB
C
94 lines
2.9 KiB
C
// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
|
|
/*
|
|
* Copyright (C) 2025 Amlogic, Inc. All rights reserved
|
|
*/
|
|
#ifndef DMABUF_H
|
|
#define DMABUF_H
|
|
#if defined (__cplusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define DEVPATH "/dev/dma_heap"
|
|
#define GENERIC_HEAP "heap-codecmm"
|
|
|
|
int dmabuf_dev_open(char *name);
|
|
int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags,
|
|
int *dmabuf_fd);
|
|
void dmabuf_sync(int fd, int start_stop);
|
|
void dmabuf_heap_close(int heap_fd);
|
|
void dmabuf_dev_close(int heap_fd);
|
|
|
|
#if defined (__cplusplus)
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifndef _DMA_BUF_UAPI_H_
|
|
#define _DMA_BUF_UAPI_H_
|
|
|
|
#include <linux/types.h>
|
|
|
|
/* begin/end dma-buf functions used for userspace mmap. */
|
|
struct dma_buf_sync {
|
|
__u64 flags;
|
|
};
|
|
|
|
#define DMA_BUF_SYNC_READ (1 << 0)
|
|
#define DMA_BUF_SYNC_WRITE (2 << 0)
|
|
#define DMA_BUF_SYNC_RW (DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE)
|
|
#define DMA_BUF_SYNC_START (0 << 2)
|
|
#define DMA_BUF_SYNC_END (1 << 2)
|
|
#define DMA_BUF_SYNC_VALID_FLAGS_MASK \
|
|
(DMA_BUF_SYNC_RW | DMA_BUF_SYNC_END)
|
|
|
|
#define DMA_BUF_NAME_LEN 32
|
|
|
|
/**
|
|
* struct dma_buf_export_sync_file - Get a sync_file from a dma-buf
|
|
*
|
|
* Userspace can perform a DMA_BUF_IOCTL_EXPORT_SYNC_FILE to retrieve the
|
|
* current set of fences on a dma-buf file descriptor as a sync_file. CPU
|
|
* waits via poll() or other driver-specific mechanisms typically wait on
|
|
* whatever fences are on the dma-buf at the time the wait begins. This
|
|
* is similar except that it takes a snapshot of the current fences on the
|
|
* dma-buf for waiting later instead of waiting immediately. This is
|
|
* useful for modern graphics APIs such as Vulkan which assume an explicit
|
|
* synchronization model but still need to inter-operate with dma-buf.
|
|
*/
|
|
struct dma_buf_export_sync_file {
|
|
/**
|
|
* @flags: Read/write flags
|
|
*
|
|
* Must be DMA_BUF_SYNC_READ, DMA_BUF_SYNC_WRITE, or both.
|
|
*
|
|
* If DMA_BUF_SYNC_READ is set and DMA_BUF_SYNC_WRITE is not set,
|
|
* the returned sync file waits on any writers of the dma-buf to
|
|
* complete. Waiting on the returned sync file is equivalent to
|
|
* poll() with POLLIN.
|
|
*
|
|
* If DMA_BUF_SYNC_WRITE is set, the returned sync file waits on
|
|
* any users of the dma-buf (read or write) to complete. Waiting
|
|
* on the returned sync file is equivalent to poll() with POLLOUT.
|
|
* If both DMA_BUF_SYNC_WRITE and DMA_BUF_SYNC_READ are set, this
|
|
* is equivalent to just DMA_BUF_SYNC_WRITE.
|
|
*/
|
|
__u32 flags;
|
|
/** @fd: Returned sync file descriptor */
|
|
__s32 fd;
|
|
};
|
|
|
|
#define DMA_BUF_BASE 'b'
|
|
#define DMA_BUF_IOCTL_SYNC _IOW(DMA_BUF_BASE, 0, struct dma_buf_sync)
|
|
|
|
/* 32/64bitness of this uapi was botched in android, there's no difference
|
|
* between them in actual uapi, they're just different numbers.
|
|
*/
|
|
#define DMA_BUF_SET_NAME _IOW(DMA_BUF_BASE, 1, const char *)
|
|
#define DMA_BUF_SET_NAME_A _IOW(DMA_BUF_BASE, 1, u32)
|
|
#define DMA_BUF_SET_NAME_B _IOW(DMA_BUF_BASE, 1, u64)
|
|
#define DMA_BUF_IOCTL_EXPORT_SYNC_FILE _IOWR(DMA_BUF_BASE, 2, struct dma_buf_export_sync_file)
|
|
|
|
#endif
|
|
|