blob: 838e37736ae751355e375f95cebfd407aaa4003f [file] [log] [blame]
Andrew F. Davisc02a81f2019-12-03 17:26:37 +00001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * DMABUF Heaps Allocation Infrastructure
4 *
5 * Copyright (C) 2011 Google, Inc.
6 * Copyright (C) 2019 Linaro Ltd.
7 */
8
9#ifndef _DMA_HEAPS_H
10#define _DMA_HEAPS_H
11
12#include <linux/cdev.h>
13#include <linux/types.h>
14
15struct dma_heap;
16
17/**
18 * struct dma_heap_ops - ops to operate on a given heap
John Stultz349e8362020-08-14 22:42:09 +000019 * @allocate: allocate dmabuf and return struct dma_buf ptr
Andrew F. Davisc02a81f2019-12-03 17:26:37 +000020 *
John Stultz349e8362020-08-14 22:42:09 +000021 * allocate returns dmabuf on success, ERR_PTR(-errno) on error.
Andrew F. Davisc02a81f2019-12-03 17:26:37 +000022 */
23struct dma_heap_ops {
John Stultz349e8362020-08-14 22:42:09 +000024 struct dma_buf *(*allocate)(struct dma_heap *heap,
Andrew F. Davisc02a81f2019-12-03 17:26:37 +000025 unsigned long len,
26 unsigned long fd_flags,
27 unsigned long heap_flags);
28};
29
30/**
31 * struct dma_heap_export_info - information needed to export a new dmabuf heap
32 * @name: used for debugging/device-node name
33 * @ops: ops struct for this heap
34 * @priv: heap exporter private data
35 *
36 * Information needed to export a new dmabuf heap.
37 */
38struct dma_heap_export_info {
39 const char *name;
40 const struct dma_heap_ops *ops;
41 void *priv;
42};
43
44/**
45 * dma_heap_get_drvdata() - get per-heap driver data
46 * @heap: DMA-Heap to retrieve private data for
47 *
48 * Returns:
49 * The per-heap data for the heap.
50 */
51void *dma_heap_get_drvdata(struct dma_heap *heap);
52
53/**
54 * dma_heap_add - adds a heap to dmabuf heaps
55 * @exp_info: information needed to register this heap
56 */
57struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info);
58
John Stultzc700bdd2020-07-25 02:53:27 +000059/**
60 * dma_heap_put - drops a reference to a dmabuf heaps, potentially freeing it
61 * @heap: heap pointer
62 */
63void dma_heap_put(struct dma_heap *heap);
64
Andrew F. Davisc02a81f2019-12-03 17:26:37 +000065#endif /* _DMA_HEAPS_H */