xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2013-2017 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10 
11 #ifndef __MALI_MEMORY_SWAP_ALLOC_H__
12 #define __MALI_MEMORY_SWAP_ALLOC_H__
13 
14 #include "mali_osk.h"
15 #include "mali_session.h"
16 
17 #include "mali_memory_types.h"
18 #include "mali_pp_job.h"
19 
20 /**
21  * Initialize memory swapping module.
22  */
23 _mali_osk_errcode_t mali_mem_swap_init(void);
24 
25 void mali_mem_swap_term(void);
26 
27 /**
28  * Return global share memory file to other modules.
29  */
30 struct file *mali_mem_swap_get_global_swap_file(void);
31 
32 /**
33  * Unlock the given memory backend and pages in it could be swapped out by kernel.
34  */
35 void mali_mem_swap_unlock_single_mem_backend(mali_mem_backend *mem_bkend);
36 
37 /**
38  * Remove the given memory backend from global swap list.
39  */
40 void mali_memory_swap_list_backend_delete(mali_mem_backend *mem_bkend);
41 
42 /**
43  * Add the given memory backend to global swap list.
44  */
45 void mali_memory_swap_list_backend_add(mali_mem_backend *mem_bkend);
46 
47 /**
48  * Allocate 1 index from bitmap used as page index in global swap file.
49  */
50 u32 mali_mem_swap_idx_alloc(void);
51 
52 void mali_mem_swap_idx_free(u32 idx);
53 
54 /**
55  * Allocate a new swap item without page index.
56  */
57 struct mali_swap_item *mali_mem_swap_alloc_swap_item(void);
58 
59 /**
60  * Free a swap item, truncate the corresponding space in page cache and free index of page.
61  */
62 void mali_mem_swap_free_swap_item(mali_swap_item *swap_item);
63 
64 /**
65  * Allocate a page node with swap item.
66  */
67 struct mali_page_node *_mali_mem_swap_page_node_allocate(void);
68 
69 /**
70  * Reduce the reference count of given page node and if return 0, just free this page node.
71  */
72 _mali_osk_errcode_t _mali_mem_swap_put_page_node(struct mali_page_node *m_page);
73 
74 void _mali_mem_swap_page_node_free(struct mali_page_node *m_page);
75 
76 /**
77  * Free a swappable memory backend.
78  */
79 u32 mali_mem_swap_free(mali_mem_swap *swap_mem);
80 
81 /**
82  * Ummap and free.
83  */
84 u32 mali_mem_swap_release(mali_mem_backend *mem_bkend, mali_bool is_mali_mapped);
85 
86 /**
87  * Read in a page from global swap file with the pre-allcated page index.
88  */
89 mali_bool mali_mem_swap_in_page_node(struct mali_page_node *page_node);
90 
91 int mali_mem_swap_alloc_pages(mali_mem_swap *swap_mem, u32 size, u32 *bkend_idx);
92 
93 _mali_osk_errcode_t mali_mem_swap_mali_map(mali_mem_swap *swap_mem, struct mali_session_data *session, u32 vaddr, u32 props);
94 
95 void mali_mem_swap_mali_unmap(mali_mem_allocation *alloc);
96 
97 /**
98  * When pp job created, we need swap in all of memory backend needed by this pp job.
99  */
100 int mali_mem_swap_in_pages(struct mali_pp_job *job);
101 
102 /**
103  * Put all of memory backends used this pp job to the global swap list.
104  */
105 int mali_mem_swap_out_pages(struct mali_pp_job *job);
106 
107 /**
108  * This will be called in page fault to process CPU read&write.
109  */
110 int mali_mem_swap_allocate_page_on_demand(mali_mem_backend *mem_bkend, u32 offset, struct page **pagep) ;
111 
112 /**
113  * Used to process cow on demand for swappable memory backend.
114  */
115 int mali_mem_swap_cow_page_on_demand(mali_mem_backend *mem_bkend, u32 offset, struct page **pagep);
116 
117 #ifdef MALI_MEM_SWAP_TRACKING
118 void mali_mem_swap_tracking(u32 *swap_pool_size, u32 *unlock_size);
119 #endif
120 #endif /* __MALI_MEMORY_SWAP_ALLOC_H__ */
121 
122