GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / include / hmm / hmm_pool.h
1 /*
2  * Support for Medifield PNW Camera Imaging ISP subsystem.
3  *
4  * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
5  *
6  * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License version
10  * 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  *
22  */
23 #ifndef __HMM_POOL_H__
24 #define __HMM_POOL_H__
25
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/list.h>
29 #include <linux/spinlock.h>
30 #include <linux/mutex.h>
31 #include <linux/kref.h>
32 #include "hmm_common.h"
33 #include "hmm/hmm_bo.h"
34
35 #define ALLOC_PAGE_FAIL_NUM             5
36
37 enum hmm_pool_type {
38         HMM_POOL_TYPE_RESERVED,
39         HMM_POOL_TYPE_DYNAMIC,
40 };
41
42 /**
43  * struct hmm_pool_ops  -  memory pool callbacks.
44  *
45  * @pool_init:             initialize the memory pool.
46  * @pool_exit:             uninitialize the memory pool.
47  * @pool_alloc_pages:      allocate pages from memory pool.
48  * @pool_free_pages:       free pages to memory pool.
49  * @pool_inited:           check whether memory pool is initialized.
50  */
51 struct hmm_pool_ops {
52         int (*pool_init)(void **pool, unsigned int pool_size);
53         void (*pool_exit)(void **pool);
54         unsigned int (*pool_alloc_pages)(void *pool,
55                                         struct hmm_page_object *page_obj,
56                                         unsigned int size, bool cached);
57         void (*pool_free_pages)(void *pool,
58                                 struct hmm_page_object *page_obj);
59         int (*pool_inited)(void *pool);
60 };
61
62 struct hmm_pool {
63         struct hmm_pool_ops     *pops;
64
65         void                    *pool_info;
66 };
67
68 /**
69  * struct hmm_reserved_pool_info  - represents reserved pool private data.
70  * @pages:                          a array that store physical pages.
71  *                                  The array is as reserved memory pool.
72  * @index:                          to indicate the first blank page number
73  *                                  in reserved memory pool(pages array).
74  * @pgnr:                           the valid page amount in reserved memory
75  *                                  pool.
76  * @list_lock:                      list lock is used to protect the operation
77  *                                  to reserved memory pool.
78  * @flag:                           reserved memory pool state flag.
79  */
80 struct hmm_reserved_pool_info {
81         struct page             **pages;
82
83         unsigned int            index;
84         unsigned int            pgnr;
85         spinlock_t              list_lock;
86         bool                    initialized;
87 };
88
89 /**
90  * struct hmm_dynamic_pool_info  -  represents dynamic pool private data.
91  * @pages_list:                     a list that store physical pages.
92  *                                  The pages list is as dynamic memory pool.
93  * @list_lock:                      list lock is used to protect the operation
94  *                                  to dynamic memory pool.
95  * @flag:                           dynamic memory pool state flag.
96  * @pgptr_cache:                    struct kmem_cache, manages a cache.
97  */
98 struct hmm_dynamic_pool_info {
99         struct list_head        pages_list;
100
101         /* list lock is used to protect the free pages block lists */
102         spinlock_t              list_lock;
103
104         struct kmem_cache       *pgptr_cache;
105         bool                    initialized;
106
107         unsigned int            pool_size;
108         unsigned int            pgnr;
109 };
110
111 struct hmm_page {
112         struct page             *page;
113         struct list_head        list;
114 };
115
116 extern struct hmm_pool_ops      reserved_pops;
117 extern struct hmm_pool_ops      dynamic_pops;
118
119 #endif