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