xref: /OK3568_Linux_fs/kernel/drivers/dma-buf/heaps/page_pool.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * DMA BUF PagePool implementation
4*4882a593Smuzhiyun  * Based on earlier ION code by Google
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2011 Google, Inc.
7*4882a593Smuzhiyun  * Copyright (C) 2020 Linaro Ltd.
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef _DMABUF_PAGE_POOL_H
11*4882a593Smuzhiyun #define _DMABUF_PAGE_POOL_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/device.h>
14*4882a593Smuzhiyun #include <linux/kref.h>
15*4882a593Smuzhiyun #include <linux/mm_types.h>
16*4882a593Smuzhiyun #include <linux/mutex.h>
17*4882a593Smuzhiyun #include <linux/shrinker.h>
18*4882a593Smuzhiyun #include <linux/types.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /* page types we track in the pool */
21*4882a593Smuzhiyun enum {
22*4882a593Smuzhiyun 	POOL_LOWPAGE,      /* Clean lowmem pages */
23*4882a593Smuzhiyun 	POOL_HIGHPAGE,     /* Clean highmem pages */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 	POOL_TYPE_SIZE,
26*4882a593Smuzhiyun };
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /**
29*4882a593Smuzhiyun  * struct dmabuf_page_pool - pagepool struct
30*4882a593Smuzhiyun  * @count[]:		array of number of pages of that type in the pool
31*4882a593Smuzhiyun  * @items[]:		array of list of pages of the specific type
32*4882a593Smuzhiyun  * @mutex:		lock protecting this struct and especially the count
33*4882a593Smuzhiyun  *			item list
34*4882a593Smuzhiyun  * @gfp_mask:		gfp_mask to use from alloc
35*4882a593Smuzhiyun  * @order:		order of pages in the pool
36*4882a593Smuzhiyun  * @list:		list node for list of pools
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  * Allows you to keep a pool of pre allocated pages to use
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun struct dmabuf_page_pool {
41*4882a593Smuzhiyun 	int count[POOL_TYPE_SIZE];
42*4882a593Smuzhiyun 	struct list_head items[POOL_TYPE_SIZE];
43*4882a593Smuzhiyun 	struct mutex mutex; /* No longer used! */
44*4882a593Smuzhiyun 	gfp_t gfp_mask;
45*4882a593Smuzhiyun 	unsigned int order;
46*4882a593Smuzhiyun 	struct list_head list;
47*4882a593Smuzhiyun };
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun struct dmabuf_page_pool *dmabuf_page_pool_create(gfp_t gfp_mask,
50*4882a593Smuzhiyun 						 unsigned int order);
51*4882a593Smuzhiyun void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool);
52*4882a593Smuzhiyun struct page *dmabuf_page_pool_alloc(struct dmabuf_page_pool *pool);
53*4882a593Smuzhiyun void dmabuf_page_pool_free(struct dmabuf_page_pool *pool, struct page *page);
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun #endif /* _DMABUF_PAGE_POOL_H */
56