1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright © 2014-2018 Broadcom
4 * Copyright © 2019 Collabora ltd.
5 */
6#ifndef _PANFROST_DRM_H_
7#define _PANFROST_DRM_H_
8
9#include "drm.h"
10
11#if defined(__cplusplus)
12extern "C" {
13#endif
14
15#define DRM_PANFROST_SUBMIT			0x00
16#define DRM_PANFROST_WAIT_BO			0x01
17#define DRM_PANFROST_CREATE_BO			0x02
18#define DRM_PANFROST_MMAP_BO			0x03
19#define DRM_PANFROST_GET_PARAM			0x04
20#define DRM_PANFROST_GET_BO_OFFSET		0x05
21#define DRM_PANFROST_PERFCNT_ENABLE		0x06
22#define DRM_PANFROST_PERFCNT_DUMP		0x07
23#define DRM_PANFROST_MADVISE			0x08
24
25#define DRM_IOCTL_PANFROST_SUBMIT		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)
26#define DRM_IOCTL_PANFROST_WAIT_BO		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)
27#define DRM_IOCTL_PANFROST_CREATE_BO		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_CREATE_BO, struct drm_panfrost_create_bo)
28#define DRM_IOCTL_PANFROST_MMAP_BO		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MMAP_BO, struct drm_panfrost_mmap_bo)
29#define DRM_IOCTL_PANFROST_GET_PARAM		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param)
30#define DRM_IOCTL_PANFROST_GET_BO_OFFSET	DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset)
31#define DRM_IOCTL_PANFROST_MADVISE		DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise)
32
33/*
34 * Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module
35 * param is set to true.
36 * All these ioctl(s) are subject to deprecation, so please don't rely on
37 * them for anything but debugging purpose.
38 */
39#define DRM_IOCTL_PANFROST_PERFCNT_ENABLE	DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)
40#define DRM_IOCTL_PANFROST_PERFCNT_DUMP		DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)
41
42#define PANFROST_JD_REQ_FS (1 << 0)
43/**
44 * struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D
45 * engine.
46 *
47 * This asks the kernel to have the GPU execute a render command list.
48 */
49struct drm_panfrost_submit {
50
51	/** Address to GPU mapping of job descriptor */
52	__u64 jc;
53
54	/** An optional array of sync objects to wait on before starting this job. */
55	__u64 in_syncs;
56
57	/** Number of sync objects to wait on before starting this job. */
58	__u32 in_sync_count;
59
60	/** An optional sync object to place the completion fence in. */
61	__u32 out_sync;
62
63	/** Pointer to a u32 array of the BOs that are referenced by the job. */
64	__u64 bo_handles;
65
66	/** Number of BO handles passed in (size is that times 4). */
67	__u32 bo_handle_count;
68
69	/** A combination of PANFROST_JD_REQ_* */
70	__u32 requirements;
71};
72
73/**
74 * struct drm_panfrost_wait_bo - ioctl argument for waiting for
75 * completion of the last DRM_PANFROST_SUBMIT on a BO.
76 *
77 * This is useful for cases where multiple processes might be
78 * rendering to a BO and you want to wait for all rendering to be
79 * completed.
80 */
81struct drm_panfrost_wait_bo {
82	__u32 handle;
83	__u32 pad;
84	__s64 timeout_ns;	/* absolute */
85};
86
87#define PANFROST_BO_NOEXEC	1
88#define PANFROST_BO_HEAP	2
89
90/**
91 * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
92 *
93 * There are currently no values for the flags argument, but it may be
94 * used in a future extension.
95 */
96struct drm_panfrost_create_bo {
97	__u32 size;
98	__u32 flags;
99	/** Returned GEM handle for the BO. */
100	__u32 handle;
101	/* Pad, must be zero-filled. */
102	__u32 pad;
103	/**
104	 * Returned offset for the BO in the GPU address space.  This offset
105	 * is private to the DRM fd and is valid for the lifetime of the GEM
106	 * handle.
107	 *
108	 * This offset value will always be nonzero, since various HW
109	 * units treat 0 specially.
110	 */
111	__u64 offset;
112};
113
114/**
115 * struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.
116 *
117 * This doesn't actually perform an mmap.  Instead, it returns the
118 * offset you need to use in an mmap on the DRM device node.  This
119 * means that tools like valgrind end up knowing about the mapped
120 * memory.
121 *
122 * There are currently no values for the flags argument, but it may be
123 * used in a future extension.
124 */
125struct drm_panfrost_mmap_bo {
126	/** Handle for the object being mapped. */
127	__u32 handle;
128	__u32 flags;
129	/** offset into the drm node to use for subsequent mmap call. */
130	__u64 offset;
131};
132
133enum drm_panfrost_param {
134	DRM_PANFROST_PARAM_GPU_PROD_ID,
135	DRM_PANFROST_PARAM_GPU_REVISION,
136	DRM_PANFROST_PARAM_SHADER_PRESENT,
137	DRM_PANFROST_PARAM_TILER_PRESENT,
138	DRM_PANFROST_PARAM_L2_PRESENT,
139	DRM_PANFROST_PARAM_STACK_PRESENT,
140	DRM_PANFROST_PARAM_AS_PRESENT,
141	DRM_PANFROST_PARAM_JS_PRESENT,
142	DRM_PANFROST_PARAM_L2_FEATURES,
143	DRM_PANFROST_PARAM_CORE_FEATURES,
144	DRM_PANFROST_PARAM_TILER_FEATURES,
145	DRM_PANFROST_PARAM_MEM_FEATURES,
146	DRM_PANFROST_PARAM_MMU_FEATURES,
147	DRM_PANFROST_PARAM_THREAD_FEATURES,
148	DRM_PANFROST_PARAM_MAX_THREADS,
149	DRM_PANFROST_PARAM_THREAD_MAX_WORKGROUP_SZ,
150	DRM_PANFROST_PARAM_THREAD_MAX_BARRIER_SZ,
151	DRM_PANFROST_PARAM_COHERENCY_FEATURES,
152	DRM_PANFROST_PARAM_TEXTURE_FEATURES0,
153	DRM_PANFROST_PARAM_TEXTURE_FEATURES1,
154	DRM_PANFROST_PARAM_TEXTURE_FEATURES2,
155	DRM_PANFROST_PARAM_TEXTURE_FEATURES3,
156	DRM_PANFROST_PARAM_JS_FEATURES0,
157	DRM_PANFROST_PARAM_JS_FEATURES1,
158	DRM_PANFROST_PARAM_JS_FEATURES2,
159	DRM_PANFROST_PARAM_JS_FEATURES3,
160	DRM_PANFROST_PARAM_JS_FEATURES4,
161	DRM_PANFROST_PARAM_JS_FEATURES5,
162	DRM_PANFROST_PARAM_JS_FEATURES6,
163	DRM_PANFROST_PARAM_JS_FEATURES7,
164	DRM_PANFROST_PARAM_JS_FEATURES8,
165	DRM_PANFROST_PARAM_JS_FEATURES9,
166	DRM_PANFROST_PARAM_JS_FEATURES10,
167	DRM_PANFROST_PARAM_JS_FEATURES11,
168	DRM_PANFROST_PARAM_JS_FEATURES12,
169	DRM_PANFROST_PARAM_JS_FEATURES13,
170	DRM_PANFROST_PARAM_JS_FEATURES14,
171	DRM_PANFROST_PARAM_JS_FEATURES15,
172	DRM_PANFROST_PARAM_NR_CORE_GROUPS,
173	DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,
174};
175
176struct drm_panfrost_get_param {
177	__u32 param;
178	__u32 pad;
179	__u64 value;
180};
181
182/**
183 * Returns the offset for the BO in the GPU address space for this DRM fd.
184 * This is the same value returned by drm_panfrost_create_bo, if that was called
185 * from this DRM fd.
186 */
187struct drm_panfrost_get_bo_offset {
188	__u32 handle;
189	__u32 pad;
190	__u64 offset;
191};
192
193struct drm_panfrost_perfcnt_enable {
194	__u32 enable;
195	/*
196	 * On bifrost we have 2 sets of counters, this parameter defines the
197	 * one to track.
198	 */
199	__u32 counterset;
200};
201
202struct drm_panfrost_perfcnt_dump {
203	__u64 buf_ptr;
204};
205
206/* madvise provides a way to tell the kernel in case a buffers contents
207 * can be discarded under memory pressure, which is useful for userspace
208 * bo cache where we want to optimistically hold on to buffer allocate
209 * and potential mmap, but allow the pages to be discarded under memory
210 * pressure.
211 *
212 * Typical usage would involve madvise(DONTNEED) when buffer enters BO
213 * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
214 * In the WILLNEED case, 'retained' indicates to userspace whether the
215 * backing pages still exist.
216 */
217#define PANFROST_MADV_WILLNEED 0	/* backing pages are needed, status returned in 'retained' */
218#define PANFROST_MADV_DONTNEED 1	/* backing pages not needed */
219
220struct drm_panfrost_madvise {
221	__u32 handle;         /* in, GEM handle */
222	__u32 madv;           /* in, PANFROST_MADV_x */
223	__u32 retained;       /* out, whether backing store still exists */
224};
225
226#if defined(__cplusplus)
227}
228#endif
229
230#endif /* _PANFROST_DRM_H_ */
231