162306a36Sopenharmony_ci/* SPDX-License-Identifier: MIT */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright © 2022 Intel Corporation
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci/**
762306a36Sopenharmony_ci * DOC: I915_PARAM_VM_BIND_VERSION
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * VM_BIND feature version supported.
1062306a36Sopenharmony_ci * See typedef drm_i915_getparam_t param.
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * Specifies the VM_BIND feature version supported.
1362306a36Sopenharmony_ci * The following versions of VM_BIND have been defined:
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * 0: No VM_BIND support.
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * 1: In VM_UNBIND calls, the UMD must specify the exact mappings created
1862306a36Sopenharmony_ci *    previously with VM_BIND, the ioctl will not support unbinding multiple
1962306a36Sopenharmony_ci *    mappings or splitting them. Similarly, VM_BIND calls will not replace
2062306a36Sopenharmony_ci *    any existing mappings.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * 2: The restrictions on unbinding partial or multiple mappings is
2362306a36Sopenharmony_ci *    lifted, Similarly, binding will replace any mappings in the given range.
2462306a36Sopenharmony_ci *
2562306a36Sopenharmony_ci * See struct drm_i915_gem_vm_bind and struct drm_i915_gem_vm_unbind.
2662306a36Sopenharmony_ci */
2762306a36Sopenharmony_ci#define I915_PARAM_VM_BIND_VERSION	57
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/**
3062306a36Sopenharmony_ci * DOC: I915_VM_CREATE_FLAGS_USE_VM_BIND
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci * Flag to opt-in for VM_BIND mode of binding during VM creation.
3362306a36Sopenharmony_ci * See struct drm_i915_gem_vm_control flags.
3462306a36Sopenharmony_ci *
3562306a36Sopenharmony_ci * The older execbuf2 ioctl will not support VM_BIND mode of operation.
3662306a36Sopenharmony_ci * For VM_BIND mode, we have new execbuf3 ioctl which will not accept any
3762306a36Sopenharmony_ci * execlist (See struct drm_i915_gem_execbuffer3 for more details).
3862306a36Sopenharmony_ci */
3962306a36Sopenharmony_ci#define I915_VM_CREATE_FLAGS_USE_VM_BIND	(1 << 0)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/* VM_BIND related ioctls */
4262306a36Sopenharmony_ci#define DRM_I915_GEM_VM_BIND		0x3d
4362306a36Sopenharmony_ci#define DRM_I915_GEM_VM_UNBIND		0x3e
4462306a36Sopenharmony_ci#define DRM_I915_GEM_EXECBUFFER3	0x3f
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define DRM_IOCTL_I915_GEM_VM_BIND		DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_BIND, struct drm_i915_gem_vm_bind)
4762306a36Sopenharmony_ci#define DRM_IOCTL_I915_GEM_VM_UNBIND		DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_UNBIND, struct drm_i915_gem_vm_bind)
4862306a36Sopenharmony_ci#define DRM_IOCTL_I915_GEM_EXECBUFFER3		DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER3, struct drm_i915_gem_execbuffer3)
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/**
5162306a36Sopenharmony_ci * struct drm_i915_gem_timeline_fence - An input or output timeline fence.
5262306a36Sopenharmony_ci *
5362306a36Sopenharmony_ci * The operation will wait for input fence to signal.
5462306a36Sopenharmony_ci *
5562306a36Sopenharmony_ci * The returned output fence will be signaled after the completion of the
5662306a36Sopenharmony_ci * operation.
5762306a36Sopenharmony_ci */
5862306a36Sopenharmony_cistruct drm_i915_gem_timeline_fence {
5962306a36Sopenharmony_ci	/** @handle: User's handle for a drm_syncobj to wait on or signal. */
6062306a36Sopenharmony_ci	__u32 handle;
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	/**
6362306a36Sopenharmony_ci	 * @flags: Supported flags are:
6462306a36Sopenharmony_ci	 *
6562306a36Sopenharmony_ci	 * I915_TIMELINE_FENCE_WAIT:
6662306a36Sopenharmony_ci	 * Wait for the input fence before the operation.
6762306a36Sopenharmony_ci	 *
6862306a36Sopenharmony_ci	 * I915_TIMELINE_FENCE_SIGNAL:
6962306a36Sopenharmony_ci	 * Return operation completion fence as output.
7062306a36Sopenharmony_ci	 */
7162306a36Sopenharmony_ci	__u32 flags;
7262306a36Sopenharmony_ci#define I915_TIMELINE_FENCE_WAIT            (1 << 0)
7362306a36Sopenharmony_ci#define I915_TIMELINE_FENCE_SIGNAL          (1 << 1)
7462306a36Sopenharmony_ci#define __I915_TIMELINE_FENCE_UNKNOWN_FLAGS (-(I915_TIMELINE_FENCE_SIGNAL << 1))
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	/**
7762306a36Sopenharmony_ci	 * @value: A point in the timeline.
7862306a36Sopenharmony_ci	 * Value must be 0 for a binary drm_syncobj. A Value of 0 for a
7962306a36Sopenharmony_ci	 * timeline drm_syncobj is invalid as it turns a drm_syncobj into a
8062306a36Sopenharmony_ci	 * binary one.
8162306a36Sopenharmony_ci	 */
8262306a36Sopenharmony_ci	__u64 value;
8362306a36Sopenharmony_ci};
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/**
8662306a36Sopenharmony_ci * struct drm_i915_gem_vm_bind - VA to object mapping to bind.
8762306a36Sopenharmony_ci *
8862306a36Sopenharmony_ci * This structure is passed to VM_BIND ioctl and specifies the mapping of GPU
8962306a36Sopenharmony_ci * virtual address (VA) range to the section of an object that should be bound
9062306a36Sopenharmony_ci * in the device page table of the specified address space (VM).
9162306a36Sopenharmony_ci * The VA range specified must be unique (ie., not currently bound) and can
9262306a36Sopenharmony_ci * be mapped to whole object or a section of the object (partial binding).
9362306a36Sopenharmony_ci * Multiple VA mappings can be created to the same section of the object
9462306a36Sopenharmony_ci * (aliasing).
9562306a36Sopenharmony_ci *
9662306a36Sopenharmony_ci * The @start, @offset and @length must be 4K page aligned. However the DG2
9762306a36Sopenharmony_ci * and XEHPSDV has 64K page size for device local memory and has compact page
9862306a36Sopenharmony_ci * table. On those platforms, for binding device local-memory objects, the
9962306a36Sopenharmony_ci * @start, @offset and @length must be 64K aligned. Also, UMDs should not mix
10062306a36Sopenharmony_ci * the local memory 64K page and the system memory 4K page bindings in the same
10162306a36Sopenharmony_ci * 2M range.
10262306a36Sopenharmony_ci *
10362306a36Sopenharmony_ci * Error code -EINVAL will be returned if @start, @offset and @length are not
10462306a36Sopenharmony_ci * properly aligned. In version 1 (See I915_PARAM_VM_BIND_VERSION), error code
10562306a36Sopenharmony_ci * -ENOSPC will be returned if the VA range specified can't be reserved.
10662306a36Sopenharmony_ci *
10762306a36Sopenharmony_ci * VM_BIND/UNBIND ioctl calls executed on different CPU threads concurrently
10862306a36Sopenharmony_ci * are not ordered. Furthermore, parts of the VM_BIND operation can be done
10962306a36Sopenharmony_ci * asynchronously, if valid @fence is specified.
11062306a36Sopenharmony_ci */
11162306a36Sopenharmony_cistruct drm_i915_gem_vm_bind {
11262306a36Sopenharmony_ci	/** @vm_id: VM (address space) id to bind */
11362306a36Sopenharmony_ci	__u32 vm_id;
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	/** @handle: Object handle */
11662306a36Sopenharmony_ci	__u32 handle;
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	/** @start: Virtual Address start to bind */
11962306a36Sopenharmony_ci	__u64 start;
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci	/** @offset: Offset in object to bind */
12262306a36Sopenharmony_ci	__u64 offset;
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	/** @length: Length of mapping to bind */
12562306a36Sopenharmony_ci	__u64 length;
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	/**
12862306a36Sopenharmony_ci	 * @flags: Supported flags are:
12962306a36Sopenharmony_ci	 *
13062306a36Sopenharmony_ci	 * I915_GEM_VM_BIND_CAPTURE:
13162306a36Sopenharmony_ci	 * Capture this mapping in the dump upon GPU error.
13262306a36Sopenharmony_ci	 *
13362306a36Sopenharmony_ci	 * Note that @fence carries its own flags.
13462306a36Sopenharmony_ci	 */
13562306a36Sopenharmony_ci	__u64 flags;
13662306a36Sopenharmony_ci#define I915_GEM_VM_BIND_CAPTURE	(1 << 0)
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	/**
13962306a36Sopenharmony_ci	 * @fence: Timeline fence for bind completion signaling.
14062306a36Sopenharmony_ci	 *
14162306a36Sopenharmony_ci	 * Timeline fence is of format struct drm_i915_gem_timeline_fence.
14262306a36Sopenharmony_ci	 *
14362306a36Sopenharmony_ci	 * It is an out fence, hence using I915_TIMELINE_FENCE_WAIT flag
14462306a36Sopenharmony_ci	 * is invalid, and an error will be returned.
14562306a36Sopenharmony_ci	 *
14662306a36Sopenharmony_ci	 * If I915_TIMELINE_FENCE_SIGNAL flag is not set, then out fence
14762306a36Sopenharmony_ci	 * is not requested and binding is completed synchronously.
14862306a36Sopenharmony_ci	 */
14962306a36Sopenharmony_ci	struct drm_i915_gem_timeline_fence fence;
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci	/**
15262306a36Sopenharmony_ci	 * @extensions: Zero-terminated chain of extensions.
15362306a36Sopenharmony_ci	 *
15462306a36Sopenharmony_ci	 * For future extensions. See struct i915_user_extension.
15562306a36Sopenharmony_ci	 */
15662306a36Sopenharmony_ci	__u64 extensions;
15762306a36Sopenharmony_ci};
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci/**
16062306a36Sopenharmony_ci * struct drm_i915_gem_vm_unbind - VA to object mapping to unbind.
16162306a36Sopenharmony_ci *
16262306a36Sopenharmony_ci * This structure is passed to VM_UNBIND ioctl and specifies the GPU virtual
16362306a36Sopenharmony_ci * address (VA) range that should be unbound from the device page table of the
16462306a36Sopenharmony_ci * specified address space (VM). VM_UNBIND will force unbind the specified
16562306a36Sopenharmony_ci * range from device page table without waiting for any GPU job to complete.
16662306a36Sopenharmony_ci * It is UMDs responsibility to ensure the mapping is no longer in use before
16762306a36Sopenharmony_ci * calling VM_UNBIND.
16862306a36Sopenharmony_ci *
16962306a36Sopenharmony_ci * If the specified mapping is not found, the ioctl will simply return without
17062306a36Sopenharmony_ci * any error.
17162306a36Sopenharmony_ci *
17262306a36Sopenharmony_ci * VM_BIND/UNBIND ioctl calls executed on different CPU threads concurrently
17362306a36Sopenharmony_ci * are not ordered. Furthermore, parts of the VM_UNBIND operation can be done
17462306a36Sopenharmony_ci * asynchronously, if valid @fence is specified.
17562306a36Sopenharmony_ci */
17662306a36Sopenharmony_cistruct drm_i915_gem_vm_unbind {
17762306a36Sopenharmony_ci	/** @vm_id: VM (address space) id to bind */
17862306a36Sopenharmony_ci	__u32 vm_id;
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci	/** @rsvd: Reserved, MBZ */
18162306a36Sopenharmony_ci	__u32 rsvd;
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	/** @start: Virtual Address start to unbind */
18462306a36Sopenharmony_ci	__u64 start;
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci	/** @length: Length of mapping to unbind */
18762306a36Sopenharmony_ci	__u64 length;
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci	/**
19062306a36Sopenharmony_ci	 * @flags: Currently reserved, MBZ.
19162306a36Sopenharmony_ci	 *
19262306a36Sopenharmony_ci	 * Note that @fence carries its own flags.
19362306a36Sopenharmony_ci	 */
19462306a36Sopenharmony_ci	__u64 flags;
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci	/**
19762306a36Sopenharmony_ci	 * @fence: Timeline fence for unbind completion signaling.
19862306a36Sopenharmony_ci	 *
19962306a36Sopenharmony_ci	 * Timeline fence is of format struct drm_i915_gem_timeline_fence.
20062306a36Sopenharmony_ci	 *
20162306a36Sopenharmony_ci	 * It is an out fence, hence using I915_TIMELINE_FENCE_WAIT flag
20262306a36Sopenharmony_ci	 * is invalid, and an error will be returned.
20362306a36Sopenharmony_ci	 *
20462306a36Sopenharmony_ci	 * If I915_TIMELINE_FENCE_SIGNAL flag is not set, then out fence
20562306a36Sopenharmony_ci	 * is not requested and unbinding is completed synchronously.
20662306a36Sopenharmony_ci	 */
20762306a36Sopenharmony_ci	struct drm_i915_gem_timeline_fence fence;
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci	/**
21062306a36Sopenharmony_ci	 * @extensions: Zero-terminated chain of extensions.
21162306a36Sopenharmony_ci	 *
21262306a36Sopenharmony_ci	 * For future extensions. See struct i915_user_extension.
21362306a36Sopenharmony_ci	 */
21462306a36Sopenharmony_ci	__u64 extensions;
21562306a36Sopenharmony_ci};
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci/**
21862306a36Sopenharmony_ci * struct drm_i915_gem_execbuffer3 - Structure for DRM_I915_GEM_EXECBUFFER3
21962306a36Sopenharmony_ci * ioctl.
22062306a36Sopenharmony_ci *
22162306a36Sopenharmony_ci * DRM_I915_GEM_EXECBUFFER3 ioctl only works in VM_BIND mode and VM_BIND mode
22262306a36Sopenharmony_ci * only works with this ioctl for submission.
22362306a36Sopenharmony_ci * See I915_VM_CREATE_FLAGS_USE_VM_BIND.
22462306a36Sopenharmony_ci */
22562306a36Sopenharmony_cistruct drm_i915_gem_execbuffer3 {
22662306a36Sopenharmony_ci	/**
22762306a36Sopenharmony_ci	 * @ctx_id: Context id
22862306a36Sopenharmony_ci	 *
22962306a36Sopenharmony_ci	 * Only contexts with user engine map are allowed.
23062306a36Sopenharmony_ci	 */
23162306a36Sopenharmony_ci	__u32 ctx_id;
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci	/**
23462306a36Sopenharmony_ci	 * @engine_idx: Engine index
23562306a36Sopenharmony_ci	 *
23662306a36Sopenharmony_ci	 * An index in the user engine map of the context specified by @ctx_id.
23762306a36Sopenharmony_ci	 */
23862306a36Sopenharmony_ci	__u32 engine_idx;
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci	/**
24162306a36Sopenharmony_ci	 * @batch_address: Batch gpu virtual address/es.
24262306a36Sopenharmony_ci	 *
24362306a36Sopenharmony_ci	 * For normal submission, it is the gpu virtual address of the batch
24462306a36Sopenharmony_ci	 * buffer. For parallel submission, it is a pointer to an array of
24562306a36Sopenharmony_ci	 * batch buffer gpu virtual addresses with array size equal to the
24662306a36Sopenharmony_ci	 * number of (parallel) engines involved in that submission (See
24762306a36Sopenharmony_ci	 * struct i915_context_engines_parallel_submit).
24862306a36Sopenharmony_ci	 */
24962306a36Sopenharmony_ci	__u64 batch_address;
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci	/** @flags: Currently reserved, MBZ */
25262306a36Sopenharmony_ci	__u64 flags;
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci	/** @rsvd1: Reserved, MBZ */
25562306a36Sopenharmony_ci	__u32 rsvd1;
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci	/** @fence_count: Number of fences in @timeline_fences array. */
25862306a36Sopenharmony_ci	__u32 fence_count;
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci	/**
26162306a36Sopenharmony_ci	 * @timeline_fences: Pointer to an array of timeline fences.
26262306a36Sopenharmony_ci	 *
26362306a36Sopenharmony_ci	 * Timeline fences are of format struct drm_i915_gem_timeline_fence.
26462306a36Sopenharmony_ci	 */
26562306a36Sopenharmony_ci	__u64 timeline_fences;
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci	/** @rsvd2: Reserved, MBZ */
26862306a36Sopenharmony_ci	__u64 rsvd2;
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci	/**
27162306a36Sopenharmony_ci	 * @extensions: Zero-terminated chain of extensions.
27262306a36Sopenharmony_ci	 *
27362306a36Sopenharmony_ci	 * For future extensions. See struct i915_user_extension.
27462306a36Sopenharmony_ci	 */
27562306a36Sopenharmony_ci	__u64 extensions;
27662306a36Sopenharmony_ci};
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci/**
27962306a36Sopenharmony_ci * struct drm_i915_gem_create_ext_vm_private - Extension to make the object
28062306a36Sopenharmony_ci * private to the specified VM.
28162306a36Sopenharmony_ci *
28262306a36Sopenharmony_ci * See struct drm_i915_gem_create_ext.
28362306a36Sopenharmony_ci */
28462306a36Sopenharmony_cistruct drm_i915_gem_create_ext_vm_private {
28562306a36Sopenharmony_ci#define I915_GEM_CREATE_EXT_VM_PRIVATE		2
28662306a36Sopenharmony_ci	/** @base: Extension link. See struct i915_user_extension. */
28762306a36Sopenharmony_ci	struct i915_user_extension base;
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci	/** @vm_id: Id of the VM to which the object is private */
29062306a36Sopenharmony_ci	__u32 vm_id;
29162306a36Sopenharmony_ci};
292