xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_mem.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2014, 2017, 2020-2021 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 _KERNEL_UTF_MEM_H_
23 #define _KERNEL_UTF_MEM_H_
24 
25 /* kutf_mem.h
26  * Functions for management of memory pools in the kernel.
27  *
28  * This module implements a memory pool allocator, allowing a test
29  * implementation to allocate linked allocations which can then be freed by a
30  * single free which releases all of the resources held by the entire pool.
31  *
32  * Note that it is not possible to free single resources within the pool once
33  * allocated.
34  */
35 
36 #include <linux/list.h>
37 #include <linux/mutex.h>
38 
39 /**
40  * struct kutf_mempool - the memory pool context management structure
41  * @head:	list head on which the allocations in this context are added to
42  * @lock:	mutex for concurrent allocation from multiple threads
43  *
44  */
45 struct kutf_mempool {
46 	struct list_head head;
47 	struct mutex lock;
48 };
49 
50 /**
51  * kutf_mempool_init() - Initialize a memory pool.
52  * @pool:	Memory pool structure to initialize, provided by the user
53  *
54  * Return:	zero on success
55  */
56 int kutf_mempool_init(struct kutf_mempool *pool);
57 
58 /**
59  * kutf_mempool_alloc() - Allocate memory from a pool
60  * @pool:	Memory pool to allocate from
61  * @size:	Size of memory wanted in number of bytes
62  *
63  * Return:	Pointer to memory on success, NULL on failure.
64  */
65 void *kutf_mempool_alloc(struct kutf_mempool *pool, size_t size);
66 
67 /**
68  * kutf_mempool_destroy() - Destroy a memory pool, freeing all memory within it.
69  * @pool:	The memory pool to free
70  */
71 void kutf_mempool_destroy(struct kutf_mempool *pool);
72 #endif	/* _KERNEL_UTF_MEM_H_ */
73