blob: 8c48e0ca452ef74070780dde25288589b322ed71 [file] [log] [blame]
Moritz Pflanzer45634b42017-08-30 12:48:18 +01001/*
Alex Gildayc357c472018-03-21 13:54:09 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzer45634b42017-08-30 12:48:18 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_TEST_HWC
25#define ARM_COMPUTE_TEST_HWC
26
27#include "hwc_names.hpp"
28
29#include <errno.h>
30#include <fcntl.h>
31#include <poll.h>
32#include <stddef.h>
33#include <stdint.h>
34#include <stdlib.h>
35#include <string.h>
36#include <sys/ioctl.h>
37#include <sys/mman.h>
38#include <unistd.h>
39
Alex Gildayc357c472018-03-21 13:54:09 +000040#ifndef DOXYGEN_SKIP_THIS
41
Moritz Pflanzer45634b42017-08-30 12:48:18 +010042#if defined(ANDROID) || defined(__ANDROID__)
43/* We use _IOR_BAD/_IOW_BAD rather than _IOR/_IOW otherwise fails to compile with NDK-BUILD because of _IOC_TYPECHECK is defined, not because the paramter is invalid */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +000044#define MALI_IOR(a, b, c) _IOR_BAD(a, b, c)
45#define MALI_IOW(a, b, c) _IOW_BAD(a, b, c)
Moritz Pflanzer45634b42017-08-30 12:48:18 +010046#else /* defined(ANDROID) || defined(__ANDROID__) */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +000047#define MALI_IOR(a, b, c) _IOR(a, b, c)
48#define MALI_IOW(a, b, c) _IOW(a, b, c)
Moritz Pflanzer45634b42017-08-30 12:48:18 +010049#endif /* defined(ANDROID) || defined(__ANDROID__) */
50
51namespace mali_userspace
52{
53union uk_header
54{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +000055 uint32_t id;
56 uint32_t ret;
57 uint64_t sizer;
Moritz Pflanzer45634b42017-08-30 12:48:18 +010058};
59
60#define BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS 3
61#define BASE_MAX_COHERENT_GROUPS 16
62
63struct mali_base_gpu_core_props
64{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +000065 uint32_t product_id;
66 uint16_t version_status;
67 uint16_t minor_revision;
68 uint16_t major_revision;
69 uint16_t padding;
70 uint32_t gpu_speed_mhz;
71 uint32_t gpu_freq_khz_max;
72 uint32_t gpu_freq_khz_min;
73 uint32_t log2_program_counter_size;
74 uint32_t texture_features[BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS];
75 uint64_t gpu_available_memory_size;
Moritz Pflanzer45634b42017-08-30 12:48:18 +010076};
77
78struct mali_base_gpu_l2_cache_props
79{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +000080 uint8_t log2_line_size;
81 uint8_t log2_cache_size;
82 uint8_t num_l2_slices;
83 uint8_t padding[5];
Moritz Pflanzer45634b42017-08-30 12:48:18 +010084};
85
86struct mali_base_gpu_tiler_props
87{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +000088 uint32_t bin_size_bytes;
89 uint32_t max_active_levels;
Moritz Pflanzer45634b42017-08-30 12:48:18 +010090};
91
92struct mali_base_gpu_thread_props
93{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +000094 uint32_t max_threads;
95 uint32_t max_workgroup_size;
96 uint32_t max_barrier_size;
97 uint16_t max_registers;
98 uint8_t max_task_queue;
99 uint8_t max_thread_group_split;
100 uint8_t impl_tech;
101 uint8_t padding[7];
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100102};
103
104struct mali_base_gpu_coherent_group
105{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000106 uint64_t core_mask;
107 uint16_t num_cores;
108 uint16_t padding[3];
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100109};
110
111struct mali_base_gpu_coherent_group_info
112{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000113 uint32_t num_groups;
114 uint32_t num_core_groups;
115 uint32_t coherency;
116 uint32_t padding;
117 mali_base_gpu_coherent_group group[BASE_MAX_COHERENT_GROUPS];
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100118};
119
120#define GPU_MAX_JOB_SLOTS 16
121struct gpu_raw_gpu_props
122{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000123 uint64_t shader_present;
124 uint64_t tiler_present;
125 uint64_t l2_present;
126 uint64_t unused_1;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100127
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000128 uint32_t l2_features;
129 uint32_t suspend_size;
130 uint32_t mem_features;
131 uint32_t mmu_features;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100132
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000133 uint32_t as_present;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100134
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000135 uint32_t js_present;
136 uint32_t js_features[GPU_MAX_JOB_SLOTS];
137 uint32_t tiler_features;
138 uint32_t texture_features[3];
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100139
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000140 uint32_t gpu_id;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100141
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000142 uint32_t thread_max_threads;
143 uint32_t thread_max_workgroup_size;
144 uint32_t thread_max_barrier_size;
145 uint32_t thread_features;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100146
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000147 uint32_t coherency_mode;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100148};
149
150struct mali_base_gpu_props
151{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000152 mali_base_gpu_core_props core_props;
153 mali_base_gpu_l2_cache_props l2_props;
154 uint64_t unused;
155 mali_base_gpu_tiler_props tiler_props;
156 mali_base_gpu_thread_props thread_props;
157 gpu_raw_gpu_props raw_props;
158 mali_base_gpu_coherent_group_info coherency_info;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100159};
160
161struct kbase_uk_gpuprops
162{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000163 uk_header header;
164 mali_base_gpu_props props;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100165};
166
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000167#define KBASE_GPUPROP_VALUE_SIZE_U8 (0x0)
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100168#define KBASE_GPUPROP_VALUE_SIZE_U16 (0x1)
169#define KBASE_GPUPROP_VALUE_SIZE_U32 (0x2)
170#define KBASE_GPUPROP_VALUE_SIZE_U64 (0x3)
171
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000172#define KBASE_GPUPROP_PRODUCT_ID 1
173#define KBASE_GPUPROP_MINOR_REVISION 3
174#define KBASE_GPUPROP_MAJOR_REVISION 4
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100175
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000176#define KBASE_GPUPROP_COHERENCY_NUM_GROUPS 61
177#define KBASE_GPUPROP_COHERENCY_NUM_CORE_GROUPS 62
178#define KBASE_GPUPROP_COHERENCY_GROUP_0 64
179#define KBASE_GPUPROP_COHERENCY_GROUP_1 65
180#define KBASE_GPUPROP_COHERENCY_GROUP_2 66
181#define KBASE_GPUPROP_COHERENCY_GROUP_3 67
182#define KBASE_GPUPROP_COHERENCY_GROUP_4 68
183#define KBASE_GPUPROP_COHERENCY_GROUP_5 69
184#define KBASE_GPUPROP_COHERENCY_GROUP_6 70
185#define KBASE_GPUPROP_COHERENCY_GROUP_7 71
186#define KBASE_GPUPROP_COHERENCY_GROUP_8 72
187#define KBASE_GPUPROP_COHERENCY_GROUP_9 73
188#define KBASE_GPUPROP_COHERENCY_GROUP_10 74
189#define KBASE_GPUPROP_COHERENCY_GROUP_11 75
190#define KBASE_GPUPROP_COHERENCY_GROUP_12 76
191#define KBASE_GPUPROP_COHERENCY_GROUP_13 77
192#define KBASE_GPUPROP_COHERENCY_GROUP_14 78
193#define KBASE_GPUPROP_COHERENCY_GROUP_15 79
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100194
195struct gpu_props
196{
197 uint32_t product_id;
198 uint16_t minor_revision;
199 uint16_t major_revision;
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000200 uint32_t num_groups;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100201 uint32_t num_core_groups;
202 uint64_t core_mask[16];
203};
204
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000205static const struct
206{
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100207 uint32_t type;
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000208 size_t offset;
209 int size;
210} gpu_property_mapping[] =
211{
212#define PROP(name, member) \
213 { \
214 KBASE_GPUPROP_##name, offsetof(struct gpu_props, member), \
215 sizeof(((struct gpu_props *)0)->member) \
216 }
217#define PROP2(name, member, off) \
218 { \
219 KBASE_GPUPROP_##name, offsetof(struct gpu_props, member) + off, \
220 sizeof(((struct gpu_props *)0)->member) \
221 }
222 PROP(PRODUCT_ID, product_id),
223 PROP(MINOR_REVISION, minor_revision),
224 PROP(MAJOR_REVISION, major_revision),
225 PROP(COHERENCY_NUM_GROUPS, num_groups),
226 PROP(COHERENCY_NUM_CORE_GROUPS, num_core_groups),
227 PROP2(COHERENCY_GROUP_0, core_mask, 0),
228 PROP2(COHERENCY_GROUP_1, core_mask, 1),
229 PROP2(COHERENCY_GROUP_2, core_mask, 2),
230 PROP2(COHERENCY_GROUP_3, core_mask, 3),
231 PROP2(COHERENCY_GROUP_4, core_mask, 4),
232 PROP2(COHERENCY_GROUP_5, core_mask, 5),
233 PROP2(COHERENCY_GROUP_6, core_mask, 6),
234 PROP2(COHERENCY_GROUP_7, core_mask, 7),
235 PROP2(COHERENCY_GROUP_8, core_mask, 8),
236 PROP2(COHERENCY_GROUP_9, core_mask, 9),
237 PROP2(COHERENCY_GROUP_10, core_mask, 10),
238 PROP2(COHERENCY_GROUP_11, core_mask, 11),
239 PROP2(COHERENCY_GROUP_12, core_mask, 12),
240 PROP2(COHERENCY_GROUP_13, core_mask, 13),
241 PROP2(COHERENCY_GROUP_14, core_mask, 14),
242 PROP2(COHERENCY_GROUP_15, core_mask, 15),
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100243#undef PROP
244#undef PROP2
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000245 { 0, 0, 0 }
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100246};
247
248struct kbase_hwcnt_reader_metadata
249{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000250 uint64_t timestamp = 0;
251 uint32_t event_id = 0;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100252 uint32_t buffer_idx = 0;
253};
254
255namespace
256{
257/** Message header */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000258union kbase_uk_hwcnt_header
259{
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100260 /* 32-bit number identifying the UK function to be called. */
261 uint32_t id;
262 /* The int return code returned by the called UK function. */
263 uint32_t ret;
264 /* Used to ensure 64-bit alignment of this union. Do not remove. */
265 uint64_t sizer;
266};
267
268/** IOCTL parameters to check version */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000269struct kbase_uk_hwcnt_reader_version_check_args
270{
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100271 union kbase_uk_hwcnt_header header;
272
273 uint16_t major;
274 uint16_t minor;
275 uint8_t padding[4];
276};
277
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000278union kbase_pointer
279{
280 void *value;
281 uint32_t compat_value;
282 uint64_t sizer;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100283};
284
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000285struct kbase_ioctl_get_gpuprops
286{
287 kbase_pointer buffer;
288 uint32_t size;
289 uint32_t flags;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100290};
291
292#define KBASE_IOCTL_TYPE 0x80
293#define KBASE_IOCTL_GET_GPUPROPS MALI_IOW(KBASE_IOCTL_TYPE, 3, struct kbase_ioctl_get_gpuprops)
294
295/** IOCTL parameters to set flags */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000296struct kbase_uk_hwcnt_reader_set_flags
297{
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100298 union kbase_uk_hwcnt_header header;
299
300 uint32_t create_flags;
301 uint32_t padding;
302};
303
304/** IOCTL parameters to configure reader */
305struct kbase_uk_hwcnt_reader_setup
306{
307 union kbase_uk_hwcnt_header header;
308
309 /* IN */
310 uint32_t buffer_count;
311 uint32_t jm_bm;
312 uint32_t shader_bm;
313 uint32_t tiler_bm;
314 uint32_t mmu_l2_bm;
315
316 /* OUT */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000317 int32_t fd;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100318};
319
320static const uint32_t HWCNT_READER_API = 1;
321
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100322struct uku_version_check_args
323{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000324 uk_header header;
325 uint16_t major;
326 uint16_t minor;
327 uint8_t padding[4];
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100328};
329
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000330enum
331{
332 UKP_FUNC_ID_CHECK_VERSION = 0,
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100333 /* Related to mali0 ioctl interface */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000334 LINUX_UK_BASE_MAGIC = 0x80,
335 BASE_CONTEXT_CREATE_KERNEL_FLAGS = 0x2,
336 KBASE_FUNC_HWCNT_UK_FUNC_ID = 512,
337 KBASE_FUNC_GPU_PROPS_REG_DUMP = KBASE_FUNC_HWCNT_UK_FUNC_ID + 14,
338 KBASE_FUNC_HWCNT_READER_SETUP = KBASE_FUNC_HWCNT_UK_FUNC_ID + 36,
339 KBASE_FUNC_HWCNT_DUMP = KBASE_FUNC_HWCNT_UK_FUNC_ID + 11,
340 KBASE_FUNC_HWCNT_CLEAR = KBASE_FUNC_HWCNT_UK_FUNC_ID + 12,
341 KBASE_FUNC_SET_FLAGS = KBASE_FUNC_HWCNT_UK_FUNC_ID + 18,
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100342
343 /* The ids of ioctl commands for the reader interface */
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000344 KBASE_HWCNT_READER = 0xBE,
345 KBASE_HWCNT_READER_GET_HWVER = MALI_IOR(KBASE_HWCNT_READER, 0x00, uint32_t),
346 KBASE_HWCNT_READER_GET_BUFFER_SIZE = MALI_IOR(KBASE_HWCNT_READER, 0x01, uint32_t),
347 KBASE_HWCNT_READER_DUMP = MALI_IOW(KBASE_HWCNT_READER, 0x10, uint32_t),
348 KBASE_HWCNT_READER_CLEAR = MALI_IOW(KBASE_HWCNT_READER, 0x11, uint32_t),
349 KBASE_HWCNT_READER_GET_BUFFER = MALI_IOR(KBASE_HWCNT_READER, 0x20, struct kbase_hwcnt_reader_metadata),
350 KBASE_HWCNT_READER_PUT_BUFFER = MALI_IOW(KBASE_HWCNT_READER, 0x21, struct kbase_hwcnt_reader_metadata),
351 KBASE_HWCNT_READER_SET_INTERVAL = MALI_IOW(KBASE_HWCNT_READER, 0x30, uint32_t),
352 KBASE_HWCNT_READER_ENABLE_EVENT = MALI_IOW(KBASE_HWCNT_READER, 0x40, uint32_t),
353 KBASE_HWCNT_READER_DISABLE_EVENT = MALI_IOW(KBASE_HWCNT_READER, 0x41, uint32_t),
354 KBASE_HWCNT_READER_GET_API_VERSION = MALI_IOW(KBASE_HWCNT_READER, 0xFF, uint32_t)
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100355
356};
357
358enum
359{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000360 PIPE_DESCRIPTOR_IN, /**< The index of a pipe's input descriptor. */
361 PIPE_DESCRIPTOR_OUT, /**< The index of a pipe's output descriptor. */
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100362
363 PIPE_DESCRIPTOR_COUNT /**< The number of descriptors forming a pipe. */
364};
365
366enum
367{
368 POLL_DESCRIPTOR_SIGNAL, /**< The index of the signal descriptor in poll fds array. */
369 POLL_DESCRIPTOR_HWCNT_READER, /**< The index of the hwcnt reader descriptor in poll fds array. */
370
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000371 POLL_DESCRIPTOR_COUNT /**< The number of descriptors poll is waiting for. */
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100372};
373
374/** Write a single byte into the pipe to interrupt the reader thread */
375typedef char poll_data_t;
376}
377
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000378template <typename T>
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100379static inline int mali_ioctl(int fd, T &arg)
380{
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000381 auto *hdr = &arg.header;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100382 const int cmd = _IOC(_IOC_READ | _IOC_WRITE, LINUX_UK_BASE_MAGIC, hdr->id, sizeof(T));
383
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000384 if(ioctl(fd, cmd, &arg))
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100385 return -1;
Anthony Barbier88b8d8c2017-12-22 15:45:00 +0000386 if(hdr->ret)
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100387 return -1;
388
389 return 0;
390}
391} // namespace mali_userspace
Alex Gildayc357c472018-03-21 13:54:09 +0000392
393#endif /* DOXYGEN_SKIP_THIS */
394
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100395#endif /* ARM_COMPUTE_TEST_HWC */