GNU Linux-libre 4.14.259-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / include / hmm / hmm_bo_dev.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
24 #ifndef __HMM_BO_DEV_H__
25 #define __HMM_BO_DEV_H__
26
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/list.h>
30 #include <linux/spinlock.h>
31 #include <linux/mutex.h>
32 #include "mmu/isp_mmu.h"
33 #include "hmm/hmm_common.h"
34 #include "hmm/hmm_vm.h"
35 #include "ia_css_types.h"
36
37 #define check_bodev_null_return(bdev, exp)      \
38                 check_null_return(bdev, exp, \
39                         "NULL hmm_bo_device.\n")
40
41 #define check_bodev_null_return_void(bdev)      \
42                 check_null_return_void(bdev, \
43                         "NULL hmm_bo_device.\n")
44
45 #define HMM_BO_DEVICE_INITED    0x1
46
47 #define HMM_BO_CACHE_SIZE       2
48
49
50 struct hmm_buffer_object;
51
52 struct hmm_bo_device {
53         /* isp_mmu provides lock itself */
54         struct isp_mmu          mmu;
55
56         /* hmm_vm provides lock itself */
57         struct hmm_vm           vaddr_space;
58
59         struct list_head        free_bo_list;
60         struct list_head        active_bo_list;
61
62         /* list lock is used to protect both of the buffer object lists */
63         spinlock_t              list_lock;
64 #ifdef CONFIG_ION
65         struct ion_client       *iclient;
66 #endif
67         int                     flag;
68 };
69
70 int hmm_bo_device_init(struct hmm_bo_device *bdev,
71                        struct isp_mmu_client *mmu_driver,
72                        unsigned int vaddr_start, unsigned int size);
73
74 /*
75  * clean up all hmm_bo_device related things.
76  */
77 void hmm_bo_device_exit(struct hmm_bo_device *bdev);
78
79 /*
80  * whether the bo device is inited or not.
81  */
82 int hmm_bo_device_inited(struct hmm_bo_device *bdev);
83
84 /*
85  * find the buffer object with virtual address vaddr.
86  * return NULL if no such buffer object found.
87  */
88 struct hmm_buffer_object *hmm_bo_device_search_start(
89                 struct hmm_bo_device *bdev, ia_css_ptr vaddr);
90
91 /*
92  * find the buffer object with virtual address vaddr.
93  * return NULL if no such buffer object found.
94  */
95 struct hmm_buffer_object *hmm_bo_device_search_in_range(
96                 struct hmm_bo_device *bdev, ia_css_ptr vaddr);
97
98 /*
99  * find the buffer object with kernel virtual address vaddr.
100  * return NULL if no such buffer object found.
101  */
102 struct hmm_buffer_object *hmm_bo_device_search_vmap_start(
103                 struct hmm_bo_device *bdev, const void *vaddr);
104
105 /*
106  * find a buffer object with pgnr pages from free_bo_list and
107  * activate it (remove from free_bo_list and add to
108  * active_bo_list)
109  *
110  * return NULL if no such buffer object found.
111  */
112 struct hmm_buffer_object *hmm_bo_device_get_bo(
113                 struct hmm_bo_device *bdev, unsigned int pgnr);
114
115 /*
116  * destroy all buffer objects in the free_bo_list.
117  */
118 void hmm_bo_device_destroy_free_bo_list(struct hmm_bo_device *bdev);
119 /*
120  * destroy buffer object with start virtual address vaddr.
121  */
122 void hmm_bo_device_destroy_free_bo_addr(struct hmm_bo_device *bdev,
123                 ia_css_ptr vaddr);
124 /*
125  * destroy all buffer objects with pgnr pages.
126  */
127 void hmm_bo_device_destroy_free_bo_size(struct hmm_bo_device *bdev,
128                 unsigned int pgnr);
129
130 #endif