1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2018 Intel Corporation */
3 
4 #ifndef __IPU3_UTIL_H
5 #define __IPU3_UTIL_H
6 
7 struct device;
8 struct imgu_device;
9 
10 #define IPU3_CSS_POOL_SIZE		4
11 
12 /**
13  * struct imgu_css_map - store DMA mapping info for buffer
14  *
15  * @size:		size of the buffer in bytes.
16  * @vaddr:		kernel virtual address.
17  * @daddr:		iova dma address to access IPU3.
18  */
19 struct imgu_css_map {
20 	size_t size;
21 	void *vaddr;
22 	dma_addr_t daddr;
23 	struct page **pages;
24 };
25 
26 /**
27  * struct imgu_css_pool - circular buffer pool definition
28  *
29  * @entry:		array with IPU3_CSS_POOL_SIZE elements.
30  * @entry.param:	a &struct imgu_css_map for storing the mem mapping.
31  * @entry.valid:	used to mark if the entry has valid data.
32  * @last:		write pointer, initialized to IPU3_CSS_POOL_SIZE.
33  */
34 struct imgu_css_pool {
35 	struct {
36 		struct imgu_css_map param;
37 		bool valid;
38 	} entry[IPU3_CSS_POOL_SIZE];
39 	u32 last;
40 };
41 
42 int imgu_css_dma_buffer_resize(struct imgu_device *imgu,
43 			       struct imgu_css_map *map, size_t size);
44 void imgu_css_pool_cleanup(struct imgu_device *imgu,
45 			   struct imgu_css_pool *pool);
46 int imgu_css_pool_init(struct imgu_device *imgu, struct imgu_css_pool *pool,
47 		       size_t size);
48 void imgu_css_pool_get(struct imgu_css_pool *pool);
49 void imgu_css_pool_put(struct imgu_css_pool *pool);
50 const struct imgu_css_map *imgu_css_pool_last(struct imgu_css_pool *pool,
51 					      u32 last);
52 
53 #endif
54