xref: /OK3568_Linux_fs/kernel/include/uapi/gpu/arm/bifrost/jm/mali_kbase_jm_ioctl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2020-2023 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 _UAPI_KBASE_JM_IOCTL_H_
23 #define _UAPI_KBASE_JM_IOCTL_H_
24 
25 #include <asm-generic/ioctl.h>
26 #include <linux/types.h>
27 
28 /*
29  * 11.1:
30  * - Add BASE_MEM_TILER_ALIGN_TOP under base_mem_alloc_flags
31  * 11.2:
32  * - KBASE_MEM_QUERY_FLAGS can return KBASE_REG_PF_GROW and KBASE_REG_PROTECTED,
33  *   which some user-side clients prior to 11.2 might fault if they received
34  *   them
35  * 11.3:
36  * - New ioctls KBASE_IOCTL_STICKY_RESOURCE_MAP and
37  *   KBASE_IOCTL_STICKY_RESOURCE_UNMAP
38  * 11.4:
39  * - New ioctl KBASE_IOCTL_MEM_FIND_GPU_START_AND_OFFSET
40  * 11.5:
41  * - New ioctl: KBASE_IOCTL_MEM_JIT_INIT (old ioctl renamed to _OLD)
42  * 11.6:
43  * - Added flags field to base_jit_alloc_info structure, which can be used to
44  *   specify pseudo chunked tiler alignment for JIT allocations.
45  * 11.7:
46  * - Removed UMP support
47  * 11.8:
48  * - Added BASE_MEM_UNCACHED_GPU under base_mem_alloc_flags
49  * 11.9:
50  * - Added BASE_MEM_PERMANENT_KERNEL_MAPPING and BASE_MEM_FLAGS_KERNEL_ONLY
51  *   under base_mem_alloc_flags
52  * 11.10:
53  * - Enabled the use of nr_extres field of base_jd_atom_v2 structure for
54  *   JIT_ALLOC and JIT_FREE type softjobs to enable multiple JIT allocations
55  *   with one softjob.
56  * 11.11:
57  * - Added BASE_MEM_GPU_VA_SAME_4GB_PAGE under base_mem_alloc_flags
58  * 11.12:
59  * - Removed ioctl: KBASE_IOCTL_GET_PROFILING_CONTROLS
60  * 11.13:
61  * - New ioctl: KBASE_IOCTL_MEM_EXEC_INIT
62  * 11.14:
63  * - Add BASE_MEM_GROUP_ID_MASK, base_mem_group_id_get, base_mem_group_id_set
64  *   under base_mem_alloc_flags
65  * 11.15:
66  * - Added BASEP_CONTEXT_MMU_GROUP_ID_MASK under base_context_create_flags.
67  * - Require KBASE_IOCTL_SET_FLAGS before BASE_MEM_MAP_TRACKING_HANDLE can be
68  *   passed to mmap().
69  * 11.16:
70  * - Extended ioctl KBASE_IOCTL_MEM_SYNC to accept imported dma-buf.
71  * - Modified (backwards compatible) ioctl KBASE_IOCTL_MEM_IMPORT behavior for
72  *   dma-buf. Now, buffers are mapped on GPU when first imported, no longer
73  *   requiring external resource or sticky resource tracking. UNLESS,
74  *   CONFIG_MALI_DMA_BUF_MAP_ON_DEMAND is enabled.
75  * 11.17:
76  * - Added BASE_JD_REQ_JOB_SLOT.
77  * - Reused padding field in base_jd_atom_v2 to pass job slot number.
78  * - New ioctl: KBASE_IOCTL_GET_CPU_GPU_TIMEINFO
79  * 11.18:
80  * - Added BASE_MEM_IMPORT_SYNC_ON_MAP_UNMAP under base_mem_alloc_flags
81  * 11.19:
82  * - Extended base_jd_atom_v2 to allow a renderpass ID to be specified.
83  * 11.20:
84  * - Added new phys_pages member to kbase_ioctl_mem_jit_init for
85  *   KBASE_IOCTL_MEM_JIT_INIT, previous variants of this renamed to use _10_2
86  *   (replacing '_OLD') and _11_5 suffixes
87  * - Replaced compat_core_req (deprecated in 10.3) with jit_id[2] in
88  *   base_jd_atom_v2. It must currently be initialized to zero.
89  * - Added heap_info_gpu_addr to base_jit_alloc_info, and
90  *   BASE_JIT_ALLOC_HEAP_INFO_IS_SIZE allowable in base_jit_alloc_info's
91  *   flags member. Previous variants of this structure are kept and given _10_2
92  *   and _11_5 suffixes.
93  * - The above changes are checked for safe values in usual builds
94  * 11.21:
95  * - v2.0 of mali_trace debugfs file, which now versions the file separately
96  * 11.22:
97  * - Added base_jd_atom (v3), which is seq_nr + base_jd_atom_v2.
98  *   KBASE_IOCTL_JOB_SUBMIT supports both in parallel.
99  * 11.23:
100  * - Modified KBASE_IOCTL_MEM_COMMIT behavior to reject requests to modify
101  *   the physical memory backing of JIT allocations. This was not supposed
102  *   to be a valid use case, but it was allowed by the previous implementation.
103  * 11.24:
104  * - Added a sysfs file 'serialize_jobs' inside a new sub-directory
105  *   'scheduling'.
106  * 11.25:
107  * - Enabled JIT pressure limit in base/kbase by default
108  * 11.26
109  * - Added kinstr_jm API
110  * 11.27
111  * - Backwards compatible extension to HWC ioctl.
112  * 11.28:
113  * - Added kernel side cache ops needed hint
114  * 11.29:
115  * - Reserve ioctl 52
116  * 11.30:
117  * - Add a new priority level BASE_JD_PRIO_REALTIME
118  * - Add ioctl 54: This controls the priority setting.
119  * 11.31:
120  * - Added BASE_JD_REQ_LIMITED_CORE_MASK.
121  * - Added ioctl 55: set_limited_core_count.
122  * 11.32:
123  * - Added new HW performance counters interface to all GPUs.
124  * 11.33:
125  * - Removed Kernel legacy HWC interface
126  * 11.34:
127  * - First release of new HW performance counters interface.
128  * 11.35:
129  * - Dummy model (no mali) backend will now clear HWC values after each sample
130  * 11.36:
131  * - Remove legacy definitions:
132  *   - base_jit_alloc_info_10_2
133  *   - base_jit_alloc_info_11_5
134  *   - kbase_ioctl_mem_jit_init_10_2
135  *   - kbase_ioctl_mem_jit_init_11_5
136  * 11.37:
137  * - Fix kinstr_prfcnt issues:
138  *   - Missing implicit sample for CMD_STOP when HWCNT buffer is full.
139  *   - Race condition when stopping periodic sampling.
140  *   - prfcnt_block_metadata::block_idx gaps.
141  *   - PRFCNT_CONTROL_CMD_SAMPLE_ASYNC is removed.
142  * 11.38:
143  * - Relax the requirement to create a mapping with BASE_MEM_MAP_TRACKING_HANDLE
144  *   before allocating GPU memory for the context.
145  * - CPU mappings of USER_BUFFER imported memory handles must be cached.
146  */
147 #define BASE_UK_VERSION_MAJOR 11
148 #define BASE_UK_VERSION_MINOR 38
149 
150 /**
151  * struct kbase_ioctl_version_check - Check version compatibility between
152  * kernel and userspace
153  *
154  * @major: Major version number
155  * @minor: Minor version number
156  */
157 struct kbase_ioctl_version_check {
158 	__u16 major;
159 	__u16 minor;
160 };
161 
162 #define KBASE_IOCTL_VERSION_CHECK \
163 	_IOWR(KBASE_IOCTL_TYPE, 0, struct kbase_ioctl_version_check)
164 
165 
166 /**
167  * struct kbase_ioctl_job_submit - Submit jobs/atoms to the kernel
168  *
169  * @addr: Memory address of an array of struct base_jd_atom_v2 or v3
170  * @nr_atoms: Number of entries in the array
171  * @stride: sizeof(struct base_jd_atom_v2) or sizeof(struct base_jd_atom)
172  */
173 struct kbase_ioctl_job_submit {
174 	__u64 addr;
175 	__u32 nr_atoms;
176 	__u32 stride;
177 };
178 
179 #define KBASE_IOCTL_JOB_SUBMIT \
180 	_IOW(KBASE_IOCTL_TYPE, 2, struct kbase_ioctl_job_submit)
181 
182 #define KBASE_IOCTL_POST_TERM \
183 	_IO(KBASE_IOCTL_TYPE, 4)
184 
185 /**
186  * struct kbase_ioctl_soft_event_update - Update the status of a soft-event
187  * @event: GPU address of the event which has been updated
188  * @new_status: The new status to set
189  * @flags: Flags for future expansion
190  */
191 struct kbase_ioctl_soft_event_update {
192 	__u64 event;
193 	__u32 new_status;
194 	__u32 flags;
195 };
196 
197 #define KBASE_IOCTL_SOFT_EVENT_UPDATE \
198 	_IOW(KBASE_IOCTL_TYPE, 28, struct kbase_ioctl_soft_event_update)
199 
200 /**
201  * struct kbase_kinstr_jm_fd_out - Explains the compatibility information for
202  * the `struct kbase_kinstr_jm_atom_state_change` structure returned from the
203  * kernel
204  *
205  * @size:    The size of the `struct kbase_kinstr_jm_atom_state_change`
206  * @version: Represents a breaking change in the
207  *           `struct kbase_kinstr_jm_atom_state_change`
208  * @padding: Explicit padding to get the structure up to 64bits. See
209  * https://www.kernel.org/doc/Documentation/ioctl/botching-up-ioctls.rst
210  *
211  * The `struct kbase_kinstr_jm_atom_state_change` may have extra members at the
212  * end of the structure that older user space might not understand. If the
213  * `version` is the same, the structure is still compatible with newer kernels.
214  * The `size` can be used to cast the opaque memory returned from the kernel.
215  */
216 struct kbase_kinstr_jm_fd_out {
217 	__u16 size;
218 	__u8 version;
219 	__u8 padding[5];
220 };
221 
222 /**
223  * struct kbase_kinstr_jm_fd_in - Options when creating the file descriptor
224  *
225  * @count: Number of atom states that can be stored in the kernel circular
226  *         buffer. Must be a power of two
227  * @padding: Explicit padding to get the structure up to 64bits. See
228  * https://www.kernel.org/doc/Documentation/ioctl/botching-up-ioctls.rst
229  */
230 struct kbase_kinstr_jm_fd_in {
231 	__u16 count;
232 	__u8 padding[6];
233 };
234 
235 union kbase_kinstr_jm_fd {
236 	struct kbase_kinstr_jm_fd_in in;
237 	struct kbase_kinstr_jm_fd_out out;
238 };
239 
240 #define KBASE_IOCTL_KINSTR_JM_FD \
241 	_IOWR(KBASE_IOCTL_TYPE, 51, union kbase_kinstr_jm_fd)
242 
243 
244 #define KBASE_IOCTL_VERSION_CHECK_RESERVED \
245 	_IOWR(KBASE_IOCTL_TYPE, 52, struct kbase_ioctl_version_check)
246 
247 #endif /* _UAPI_KBASE_JM_IOCTL_H_ */
248