xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tiler_heap.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_CSF_TILER_HEAP_H_
23 #define _KBASE_CSF_TILER_HEAP_H_
24 
25 #include <mali_kbase.h>
26 /**
27  * kbase_csf_tiler_heap_context_init - Initialize the tiler heaps context for a
28  *                                     GPU address space
29  *
30  * @kctx: Pointer to the kbase context being initialized.
31  *
32  * Return: 0 if successful or a negative error code on failure.
33  */
34 int kbase_csf_tiler_heap_context_init(struct kbase_context *kctx);
35 
36 /**
37  * kbase_csf_tiler_heap_context_term - Terminate the tiler heaps context for a
38  *                                     GPU address space
39  *
40  * @kctx: Pointer to the kbase context being terminated.
41  *
42  * This function deletes any chunked tiler heaps that weren't deleted before
43  * context termination.
44  */
45 void kbase_csf_tiler_heap_context_term(struct kbase_context *kctx);
46 
47 /**
48  * kbase_csf_tiler_heap_init - Initialize a chunked tiler memory heap.
49  *
50  * @kctx: Pointer to the kbase context in which to allocate resources for the
51  *        tiler heap.
52  * @chunk_size: Size of each chunk, in bytes. Must be page-aligned.
53  * @initial_chunks: The initial number of chunks to allocate. Must not be
54  *                  zero or greater than @max_chunks.
55  * @max_chunks: The maximum number of chunks that the heap should be allowed
56  *              to use. Must not be less than @initial_chunks.
57  * @target_in_flight: Number of render-passes that the driver should attempt to
58  *                    keep in flight for which allocation of new chunks is
59  *                    allowed. Must not be zero.
60  * @buf_desc_va: Buffer descriptor GPU virtual address. This is a hint for
61  *               indicating that the caller is intending to perform tiler heap
62  *               chunks reclaim for those that are hoarded with hardware while
63  *               the associated shader activites are suspended and the CSGs are
64  *               off slots. If the referred reclaiming is not desired, can
65  *               set it to 0.
66  * @gpu_heap_va: Where to store the GPU virtual address of the context that was
67  *               set up for the tiler heap.
68  * @first_chunk_va: Where to store the GPU virtual address of the first chunk
69  *                  allocated for the heap. This points to the header of the
70  *                  heap chunk and not to the low address of free memory in it.
71  *
72  * Return: 0 if successful or a negative error code on failure.
73  */
74 int kbase_csf_tiler_heap_init(struct kbase_context *kctx, u32 chunk_size, u32 initial_chunks,
75 			      u32 max_chunks, u16 target_in_flight, u64 const buf_desc_va,
76 			      u64 *gpu_heap_va, u64 *first_chunk_va);
77 
78 /**
79  * kbase_csf_tiler_heap_term - Terminate a chunked tiler memory heap.
80  *
81  * @kctx: Pointer to the kbase context in which the tiler heap was initialized.
82  * @gpu_heap_va: The GPU virtual address of the context that was set up for the
83  *               tiler heap.
84  *
85  * This function will terminate a chunked tiler heap and cause all the chunks
86  * (initial and those added during out-of-memory processing) to be freed.
87  * It is the caller's responsibility to ensure no further operations on this
88  * heap will happen before calling this function.
89  *
90  * Return: 0 if successful or a negative error code on failure.
91  */
92 int kbase_csf_tiler_heap_term(struct kbase_context *kctx, u64 gpu_heap_va);
93 
94 /**
95  * kbase_csf_tiler_heap_alloc_new_chunk - Allocate a new chunk for tiler heap.
96  *
97  * @kctx:               Pointer to the kbase context in which the tiler heap was initialized.
98  * @gpu_heap_va:        GPU virtual address of the heap context.
99  * @nr_in_flight:       Number of render passes that are in-flight, must not be zero.
100  * @pending_frag_count: Number of render passes in-flight with completed vertex/tiler stage.
101  *                      The minimum value is zero but it must be less or equal to
102  *                      the total number of render passes in flight
103  * @new_chunk_ptr:      Where to store the GPU virtual address & size of the new
104  *                      chunk allocated for the heap.
105  *
106  * This function will allocate a new chunk for the chunked tiler heap depending
107  * on the settings provided by userspace when the heap was created and the
108  * heap's statistics (like number of render passes in-flight).
109  * It would return an appropriate error code if a new chunk couldn't be
110  * allocated.
111  *
112  * Return: 0 if a new chunk was allocated otherwise an appropriate negative
113  *         error code (like -EBUSY when a free chunk is expected to be
114  *         available upon completion of a render pass and -EINVAL when
115  *         invalid value was passed for one of the argument).
116  */
117 int kbase_csf_tiler_heap_alloc_new_chunk(struct kbase_context *kctx,
118 	u64 gpu_heap_va, u32 nr_in_flight, u32 pending_frag_count, u64 *new_chunk_ptr);
119 
120 /**
121  * kbase_csf_tiler_heap_scan_kctx_unused_pages - Performs the tiler heap shrinker calim's scan
122  *                                               functionality.
123  *
124  * @kctx:               Pointer to the kbase context for which the tiler heap recalim is to be
125  *                      operated with.
126  * @to_free:            Number of pages suggested for the reclaim scan (free) method to reach.
127  *
128  * Return: the actual number of pages the scan method has freed from the call.
129  */
130 u32 kbase_csf_tiler_heap_scan_kctx_unused_pages(struct kbase_context *kctx, u32 to_free);
131 
132 /**
133  * kbase_csf_tiler_heap_count_kctx_unused_pages - Performs the tiler heap shrinker calim's count
134  *                                                functionality.
135  *
136  * @kctx:               Pointer to the kbase context for which the tiler heap recalim is to be
137  *                      operated with.
138  *
139  * Return: a number of pages that could likely be freed on the subsequent scan method call.
140  */
141 u32 kbase_csf_tiler_heap_count_kctx_unused_pages(struct kbase_context *kctx);
142 #endif
143