xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_mem_pool_group.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2019-2022 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 #ifndef _KBASE_MEM_POOL_GROUP_H_
23 #define _KBASE_MEM_POOL_GROUP_H_
24 
25 #include <mali_kbase_defs.h>
26 
27 /**
28  * kbase_mem_pool_group_select() - Select the memory pool to use.
29  *
30  * @kbdev:         Device pointer.
31  * @mem_group_id:  Physical memory group ID to use.
32  * @is_small_page: Flag used to select between the small and
33  *                 large memory pool.
34  *
35  * Return: A pointer to the selected memory pool.
36  */
kbase_mem_pool_group_select(struct kbase_device * kbdev,u32 mem_group_id,bool is_small_page)37 static inline struct kbase_mem_pool *kbase_mem_pool_group_select(
38 	struct kbase_device *kbdev, u32 mem_group_id, bool is_small_page)
39 {
40 	if (WARN_ON(unlikely(kbdev == NULL)))
41 		return NULL;
42 
43 	WARN_ON(mem_group_id > BASE_MEM_GROUP_COUNT);
44 
45 	if (is_small_page)
46 		return &kbdev->mem_pools.small[mem_group_id];
47 
48 	return &kbdev->mem_pools.large[mem_group_id];
49 }
50 
51 /**
52  * kbase_mem_pool_group_config_set_max_size - Set the initial configuration for
53  * a set of memory pools
54  *
55  * @configs:  Initial configuration for the set of memory pools
56  * @max_size: Maximum number of free 4 KiB pages each pool can hold
57  *
58  * This function sets the initial configuration for every memory pool so that
59  * the maximum amount of free memory that each pool can hold is identical.
60  * The equivalent number of 2 MiB pages is calculated automatically for the
61  * purpose of configuring the large page pools.
62  */
63 void kbase_mem_pool_group_config_set_max_size(
64 	struct kbase_mem_pool_group_config *configs, size_t max_size);
65 
66 /**
67  * kbase_mem_pool_group_init - Initialize a set of memory pools
68  *
69  * @mem_pools:  Set of memory pools to initialize
70  * @kbdev:      Kbase device where memory is used
71  * @configs:    Initial configuration for the set of memory pools
72  * @next_pools: Set of memory pools from which to allocate memory if there
73  *              is no free memory in one of the @mem_pools
74  *
75  * Initializes a complete set of physical memory pools. Memory pools are used to
76  * allow efficient reallocation of previously-freed physical pages. A pair of
77  * memory pools is initialized for each physical memory group: one for 4 KiB
78  * pages and one for 2 MiB pages.
79  *
80  * If @next_pools is not NULL then a request to allocate memory from an
81  * empty pool in @mem_pools will attempt to allocate from the equivalent pool
82  * in @next_pools before going to the memory group manager. Similarly
83  * pages can spill over to the equivalent pool in @next_pools when a pool
84  * is full in @mem_pools. Pages are zeroed before they spill over to another
85  * pool, to prevent leaking information between applications.
86  *
87  * Return: 0 on success, otherwise a negative error code
88  */
89 int kbase_mem_pool_group_init(struct kbase_mem_pool_group *mem_pools, struct kbase_device *kbdev,
90 			      const struct kbase_mem_pool_group_config *configs,
91 			      struct kbase_mem_pool_group *next_pools);
92 
93 /**
94  * kbase_mem_pool_group_mark_dying - Mark a set of memory pools as dying
95  *
96  * @mem_pools: Set of memory pools to mark
97  *
98  * Marks a complete set of physical memory pools previously initialized by
99  * @kbase_mem_pool_group_init as dying. This will cause any ongoing allocation
100  * operations (eg growing on page fault) to be terminated.
101  */
102 void kbase_mem_pool_group_mark_dying(struct kbase_mem_pool_group *mem_pools);
103 
104 /**
105  * kbase_mem_pool_group_term - Terminate a set of memory pools
106  *
107  * @mem_pools: Set of memory pools to terminate
108  *
109  * Terminates a complete set of physical memory pools previously initialized by
110  * @kbase_mem_pool_group_init.
111  */
112 void kbase_mem_pool_group_term(struct kbase_mem_pool_group *mem_pools);
113 
114 #endif /* _KBASE_MEM_POOL_GROUP_H_ */
115