18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * DMABUF Heaps helper code 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2011 Google, Inc. 68c2ecf20Sopenharmony_ci * Copyright (C) 2019 Linaro Ltd. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _HEAP_HELPERS_H 108c2ecf20Sopenharmony_ci#define _HEAP_HELPERS_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/dma-heap.h> 138c2ecf20Sopenharmony_ci#include <linux/list.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/** 168c2ecf20Sopenharmony_ci * struct heap_helper_buffer - helper buffer metadata 178c2ecf20Sopenharmony_ci * @heap: back pointer to the heap the buffer came from 188c2ecf20Sopenharmony_ci * @dmabuf: backing dma-buf for this buffer 198c2ecf20Sopenharmony_ci * @size: size of the buffer 208c2ecf20Sopenharmony_ci * @priv_virt pointer to heap specific private value 218c2ecf20Sopenharmony_ci * @lock mutext to protect the data in this structure 228c2ecf20Sopenharmony_ci * @vmap_cnt count of vmap references on the buffer 238c2ecf20Sopenharmony_ci * @vaddr vmap'ed virtual address 248c2ecf20Sopenharmony_ci * @pagecount number of pages in the buffer 258c2ecf20Sopenharmony_ci * @pages list of page pointers 268c2ecf20Sopenharmony_ci * @attachments list of device attachments 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * @free heap callback to free the buffer 298c2ecf20Sopenharmony_ci */ 308c2ecf20Sopenharmony_cistruct heap_helper_buffer { 318c2ecf20Sopenharmony_ci struct dma_heap *heap; 328c2ecf20Sopenharmony_ci struct dma_buf *dmabuf; 338c2ecf20Sopenharmony_ci size_t size; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci void *priv_virt; 368c2ecf20Sopenharmony_ci struct mutex lock; 378c2ecf20Sopenharmony_ci int vmap_cnt; 388c2ecf20Sopenharmony_ci void *vaddr; 398c2ecf20Sopenharmony_ci pgoff_t pagecount; 408c2ecf20Sopenharmony_ci struct page **pages; 418c2ecf20Sopenharmony_ci struct list_head attachments; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci void (*free)(struct heap_helper_buffer *buffer); 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_civoid init_heap_helper_buffer(struct heap_helper_buffer *buffer, 478c2ecf20Sopenharmony_ci void (*free)(struct heap_helper_buffer *)); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct dma_buf *heap_helper_export_dmabuf(struct heap_helper_buffer *buffer, 508c2ecf20Sopenharmony_ci int fd_flags); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciextern const struct dma_buf_ops heap_helper_ops; 538c2ecf20Sopenharmony_ci#endif /* _HEAP_HELPERS_H */ 54