hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * DMA BUF PagePool implementation
 * Based on earlier ION code by Google
 *
 * Copyright (C) 2011 Google, Inc.
 * Copyright (C) 2020 Linaro Ltd.
 * Copyright (C) 2022 Rockchip Electronics Co.Ltd
 */
 
#ifndef _LINUX_DMABUF_PAGE_POOL_H
#define _LINUX_DMABUF_PAGE_POOL_H
 
#include <linux/device.h>
#include <linux/kref.h>
#include <linux/mm_types.h>
#include <linux/mutex.h>
#include <linux/shrinker.h>
#include <linux/types.h>
 
/* page types we track in the pool */
enum {
   POOL_LOWPAGE,      /* Clean lowmem pages */
   POOL_HIGHPAGE,     /* Clean highmem pages */
 
   POOL_TYPE_SIZE,
};
 
/**
 * struct dmabuf_page_pool - pagepool struct
 * @count[]:        array of number of pages of that type in the pool
 * @items[]:        array of list of pages of the specific type
 * @mutex:        lock protecting this struct and especially the count
 *            item list
 * @gfp_mask:        gfp_mask to use from alloc
 * @order:        order of pages in the pool
 * @list:        list node for list of pools
 *
 * Allows you to keep a pool of pre allocated pages to use
 */
struct dmabuf_page_pool {
   int count[POOL_TYPE_SIZE];
   struct list_head items[POOL_TYPE_SIZE];
   struct mutex mutex;
   gfp_t gfp_mask;
   unsigned int order;
   struct list_head list;
};
 
#ifdef CONFIG_DMABUF_PAGE_POOL
struct dmabuf_page_pool *dmabuf_page_pool_create(gfp_t gfp_mask,
                        unsigned int order);
void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool);
struct page *dmabuf_page_pool_alloc(struct dmabuf_page_pool *pool);
void dmabuf_page_pool_free(struct dmabuf_page_pool *pool, struct page *page);
 
struct page **
dmabuf_page_pool_alloc_pages_array(struct dmabuf_page_pool *pool, int npages);
 
void dmabuf_page_pool_free_pages_array(struct dmabuf_page_pool *pool,
                      struct page **pages, int npages);
#else
static inline struct dmabuf_page_pool *
dmabuf_page_pool_create(gfp_t gfp_mask, unsigned int order)
{
   return NULL;
}
 
static inline void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool) { }
 
static inline struct page *
dmabuf_page_pool_alloc(struct dmabuf_page_pool *pool)
{
   return NULL;
}
 
static inline void
dmabuf_page_pool_free(struct dmabuf_page_pool *pool, struct page *page) { }
 
static inline struct page **
dmabuf_page_pool_alloc_pages_array(struct dmabuf_page_pool *pool, int npages)
{
   return NULL;
}
 
static inline void
dmabuf_page_pool_free_pages_array(struct dmabuf_page_pool *pool, struct page **pages,
              int npages) { }
 
#endif
 
#endif