summaryrefslogtreecommitdiff
path: root/drivers/gpu/arm/utgard/linux/mali_memory_swap_alloc.h
blob: a393ecce3a006c8aaaf7096fdaa51ab6e37f1d23 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (C) 2013-2015 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __MALI_MEMORY_SWAP_ALLOC_H__
#define __MALI_MEMORY_SWAP_ALLOC_H__

#include "mali_osk.h"
#include "mali_session.h"

#include "mali_memory_types.h"
#include "mali_pp_job.h"

/**
 * Initialize memory swapping module.
 */
_mali_osk_errcode_t mali_mem_swap_init(void);

void mali_mem_swap_term(void);

/**
 * Return global share memory file to other modules.
 */
struct file *mali_mem_swap_get_global_swap_file(void);

/**
 * Unlock the given memory backend and pages in it could be swapped out by kernel.
 */
void mali_mem_swap_unlock_single_mem_backend(mali_mem_backend *mem_bkend);

/**
 * Remove the given memory backend from global swap list.
 */
void mali_memory_swap_list_backend_delete(mali_mem_backend *mem_bkend);

/**
 * Add the given memory backend to global swap list.
 */
void mali_memory_swap_list_backend_add(mali_mem_backend *mem_bkend);

/**
 * Allocate 1 index from bitmap used as page index in global swap file.
 */
u32 mali_mem_swap_idx_alloc(void);

void mali_mem_swap_idx_free(u32 idx);

/**
 * Allocate a new swap item without page index.
 */
struct mali_swap_item *mali_mem_swap_alloc_swap_item(void);

/**
 * Free a swap item, truncate the corresponding space in page cache and free index of page.
 */
void mali_mem_swap_free_swap_item(mali_swap_item *swap_item);

/**
 * Allocate a page node with swap item.
 */
struct mali_page_node *_mali_mem_swap_page_node_allocate(void);

/**
 * Reduce the reference count of given page node and if return 0, just free this page node.
 */
_mali_osk_errcode_t _mali_mem_swap_put_page_node(struct mali_page_node *m_page);

void _mali_mem_swap_page_node_free(struct mali_page_node *m_page);

/**
 * Free a swappable memory backend.
 */
u32 mali_mem_swap_free(mali_mem_swap *swap_mem);

/**
 * Ummap and free.
 */
u32 mali_mem_swap_release(mali_mem_backend *mem_bkend, mali_bool is_mali_mapped);

/**
 * Read in a page from global swap file with the pre-allcated page index.
 */
mali_bool mali_mem_swap_in_page_node(struct mali_page_node *page_node);

int mali_mem_swap_alloc_pages(mali_mem_swap *swap_mem, u32 size, u32 *bkend_idx);

_mali_osk_errcode_t mali_mem_swap_mali_map(mali_mem_swap *swap_mem, struct mali_session_data *session, u32 vaddr, u32 props);

void mali_mem_swap_mali_unmap(mali_mem_allocation *alloc);

/**
 * When pp job created, we need swap in all of memory backend needed by this pp job.
 */
int mali_mem_swap_in_pages(struct mali_pp_job *job);

/**
 * Put all of memory backends used this pp job to the global swap list.
 */
int mali_mem_swap_out_pages(struct mali_pp_job *job);

/**
 * This will be called in page fault to process CPU read&write.
 */
int mali_mem_swap_allocate_page_on_demand(mali_mem_backend *mem_bkend, u32 offset, struct page **pagep) ;

/**
 * Used to process cow on demand for swappable memory backend.
 */
int mali_mem_swap_cow_page_on_demand(mali_mem_backend *mem_bkend, u32 offset, struct page **pagep);

#ifdef MALI_MEM_SWAP_TRACKING
void mali_mem_swap_tracking(u32 *swap_pool_size, u32 *unlock_size);
#endif
#endif /* __MALI_MEMORY_SWAP_ALLOC_H__ */