<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 3, 2023 at 11:53 AM Danilo Krummrich <<a href="mailto:dakr@redhat.com">dakr@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This commit provides the interfaces for the new UAPI motivated by the<br>
Vulkan API. It allows user mode drivers (UMDs) to:<br>
<br>
1) Initialize a GPU virtual address (VA) space via the new<br>
DRM_IOCTL_NOUVEAU_VM_INIT ioctl. UMDs can provide a kernel reserved<br>
VA area.<br>
<br>
2) Bind and unbind GPU VA space mappings via the new<br>
DRM_IOCTL_NOUVEAU_VM_BIND ioctl.<br>
<br>
3) Execute push buffers with the new DRM_IOCTL_NOUVEAU_EXEC ioctl.<br>
<br>
Both, DRM_IOCTL_NOUVEAU_VM_BIND and DRM_IOCTL_NOUVEAU_EXEC support<br>
asynchronous processing with DRM syncobjs as synchronization mechanism.<br>
<br>
The default DRM_IOCTL_NOUVEAU_VM_BIND is synchronous processing,<br>
DRM_IOCTL_NOUVEAU_EXEC supports asynchronous processing only.<br>
<br>
Co-authored-by: Dave Airlie <<a href="mailto:airlied@redhat.com" target="_blank">airlied@redhat.com</a>><br>
Signed-off-by: Danilo Krummrich <<a href="mailto:dakr@redhat.com" target="_blank">dakr@redhat.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Faith Ekstrand <<a href="mailto:faith.ekstrand@collabora.com">faith.ekstrand@collabora.com</a>></div><div><br></div><div>Userspace is also reviewed and sitting here: <a href="https://gitlab.freedesktop.org/nouveau/mesa/-/merge_requests/150">https://gitlab.freedesktop.org/nouveau/mesa/-/merge_requests/150</a></div><div><br></div><div>I'll rev it all on top of the latest header here in a few minutes but I think the only header change was the rename for VM_INIT which shouldn't be a real problem.</div><div><br></div><div>~Faith<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
Documentation/gpu/driver-uapi.rst | 8 ++<br>
include/uapi/drm/nouveau_drm.h | 217 ++++++++++++++++++++++++++++++<br>
2 files changed, 225 insertions(+)<br>
<br>
diff --git a/Documentation/gpu/driver-uapi.rst b/Documentation/gpu/driver-uapi.rst<br>
index 4411e6919a3d..9c7ca6e33a68 100644<br>
--- a/Documentation/gpu/driver-uapi.rst<br>
+++ b/Documentation/gpu/driver-uapi.rst<br>
@@ -6,3 +6,11 @@ drm/i915 uAPI<br>
=============<br>
<br>
.. kernel-doc:: include/uapi/drm/i915_drm.h<br>
+<br>
+drm/nouveau uAPI<br>
+================<br>
+<br>
+VM_BIND / EXEC uAPI<br>
+-------------------<br>
+<br>
+.. kernel-doc:: include/uapi/drm/nouveau_drm.h<br>
diff --git a/include/uapi/drm/nouveau_drm.h b/include/uapi/drm/nouveau_drm.h<br>
index 853a327433d3..b567892c128d 100644<br>
--- a/include/uapi/drm/nouveau_drm.h<br>
+++ b/include/uapi/drm/nouveau_drm.h<br>
@@ -38,6 +38,8 @@ extern "C" {<br>
#define NOUVEAU_GEM_DOMAIN_GART (1 << 2)<br>
#define NOUVEAU_GEM_DOMAIN_MAPPABLE (1 << 3)<br>
#define NOUVEAU_GEM_DOMAIN_COHERENT (1 << 4)<br>
+/* The BO will never be shared via import or export. */<br>
+#define NOUVEAU_GEM_DOMAIN_NO_SHARE (1 << 5)<br>
<br>
#define NOUVEAU_GEM_TILE_COMP 0x00030000 /* nv50-only */<br>
#define NOUVEAU_GEM_TILE_LAYOUT_MASK 0x0000ff00<br>
@@ -126,6 +128,215 @@ struct drm_nouveau_gem_cpu_fini {<br>
__u32 handle;<br>
};<br>
<br>
+/**<br>
+ * struct drm_nouveau_sync - sync object<br>
+ *<br>
+ * This structure serves as synchronization mechanism for (potentially)<br>
+ * asynchronous operations such as EXEC or VM_BIND.<br>
+ */<br>
+struct drm_nouveau_sync {<br>
+ /**<br>
+ * @flags: the flags for a sync object<br>
+ *<br>
+ * The first 8 bits are used to determine the type of the sync object.<br>
+ */<br>
+ __u32 flags;<br>
+#define DRM_NOUVEAU_SYNC_SYNCOBJ 0x0<br>
+#define DRM_NOUVEAU_SYNC_TIMELINE_SYNCOBJ 0x1<br>
+#define DRM_NOUVEAU_SYNC_TYPE_MASK 0xf<br>
+ /**<br>
+ * @handle: the handle of the sync object<br>
+ */<br>
+ __u32 handle;<br>
+ /**<br>
+ * @timeline_value:<br>
+ *<br>
+ * The timeline point of the sync object in case the syncobj is of<br>
+ * type DRM_NOUVEAU_SYNC_TIMELINE_SYNCOBJ.<br>
+ */<br>
+ __u64 timeline_value;<br>
+};<br>
+<br>
+/**<br>
+ * struct drm_nouveau_vm_init - GPU VA space init structure<br>
+ *<br>
+ * Used to initialize the GPU's VA space for a user client, telling the kernel<br>
+ * which portion of the VA space is managed by the UMD and kernel respectively.<br>
+ *<br>
+ * For the UMD to use the VM_BIND uAPI, this must be called before any BOs or<br>
+ * channels are created; if called afterwards DRM_IOCTL_NOUVEAU_VM_INIT fails<br>
+ * with -ENOSYS.<br>
+ */<br>
+struct drm_nouveau_vm_init {<br>
+ /**<br>
+ * @kernel_managed_addr: start address of the kernel managed VA space<br>
+ * region<br>
+ */<br>
+ __u64 kernel_managed_addr;<br>
+ /**<br>
+ * @kernel_managed_size: size of the kernel managed VA space region in<br>
+ * bytes<br>
+ */<br>
+ __u64 kernel_managed_size;<br>
+};<br>
+<br>
+/**<br>
+ * struct drm_nouveau_vm_bind_op - VM_BIND operation<br>
+ *<br>
+ * This structure represents a single VM_BIND operation. UMDs should pass<br>
+ * an array of this structure via struct drm_nouveau_vm_bind's &op_ptr field.<br>
+ */<br>
+struct drm_nouveau_vm_bind_op {<br>
+ /**<br>
+ * @op: the operation type<br>
+ */<br>
+ __u32 op;<br>
+/**<br>
+ * @DRM_NOUVEAU_VM_BIND_OP_MAP:<br>
+ *<br>
+ * Map a GEM object to the GPU's VA space. Optionally, the<br>
+ * &DRM_NOUVEAU_VM_BIND_SPARSE flag can be passed to instruct the kernel to<br>
+ * create sparse mappings for the given range.<br>
+ */<br>
+#define DRM_NOUVEAU_VM_BIND_OP_MAP 0x0<br>
+/**<br>
+ * @DRM_NOUVEAU_VM_BIND_OP_UNMAP:<br>
+ *<br>
+ * Unmap an existing mapping in the GPU's VA space. If the region the mapping<br>
+ * is located in is a sparse region, new sparse mappings are created where the<br>
+ * unmapped (memory backed) mapping was mapped previously. To remove a sparse<br>
+ * region the &DRM_NOUVEAU_VM_BIND_SPARSE must be set.<br>
+ */<br>
+#define DRM_NOUVEAU_VM_BIND_OP_UNMAP 0x1<br>
+ /**<br>
+ * @flags: the flags for a &drm_nouveau_vm_bind_op<br>
+ */<br>
+ __u32 flags;<br>
+/**<br>
+ * @DRM_NOUVEAU_VM_BIND_SPARSE:<br>
+ *<br>
+ * Indicates that an allocated VA space region should be sparse.<br>
+ */<br>
+#define DRM_NOUVEAU_VM_BIND_SPARSE (1 << 8)<br>
+ /**<br>
+ * @handle: the handle of the DRM GEM object to map<br>
+ */<br>
+ __u32 handle;<br>
+ /**<br>
+ * @pad: 32 bit padding, should be 0<br>
+ */<br>
+ __u32 pad;<br>
+ /**<br>
+ * @addr:<br>
+ *<br>
+ * the address the VA space region or (memory backed) mapping should be mapped to<br>
+ */<br>
+ __u64 addr;<br>
+ /**<br>
+ * @bo_offset: the offset within the BO backing the mapping<br>
+ */<br>
+ __u64 bo_offset;<br>
+ /**<br>
+ * @range: the size of the requested mapping in bytes<br>
+ */<br>
+ __u64 range;<br>
+};<br>
+<br>
+/**<br>
+ * struct drm_nouveau_vm_bind - structure for DRM_IOCTL_NOUVEAU_VM_BIND<br>
+ */<br>
+struct drm_nouveau_vm_bind {<br>
+ /**<br>
+ * @op_count: the number of &drm_nouveau_vm_bind_op<br>
+ */<br>
+ __u32 op_count;<br>
+ /**<br>
+ * @flags: the flags for a &drm_nouveau_vm_bind ioctl<br>
+ */<br>
+ __u32 flags;<br>
+/**<br>
+ * @DRM_NOUVEAU_VM_BIND_RUN_ASYNC:<br>
+ *<br>
+ * Indicates that the given VM_BIND operation should be executed asynchronously<br>
+ * by the kernel.<br>
+ *<br>
+ * If this flag is not supplied the kernel executes the associated operations<br>
+ * synchronously and doesn't accept any &drm_nouveau_sync objects.<br>
+ */<br>
+#define DRM_NOUVEAU_VM_BIND_RUN_ASYNC 0x1<br>
+ /**<br>
+ * @wait_count: the number of wait &drm_nouveau_syncs<br>
+ */<br>
+ __u32 wait_count;<br>
+ /**<br>
+ * @sig_count: the number of &drm_nouveau_syncs to signal when finished<br>
+ */<br>
+ __u32 sig_count;<br>
+ /**<br>
+ * @wait_ptr: pointer to &drm_nouveau_syncs to wait for<br>
+ */<br>
+ __u64 wait_ptr;<br>
+ /**<br>
+ * @sig_ptr: pointer to &drm_nouveau_syncs to signal when finished<br>
+ */<br>
+ __u64 sig_ptr;<br>
+ /**<br>
+ * @op_ptr: pointer to the &drm_nouveau_vm_bind_ops to execute<br>
+ */<br>
+ __u64 op_ptr;<br>
+};<br>
+<br>
+/**<br>
+ * struct drm_nouveau_exec_push - EXEC push operation<br>
+ *<br>
+ * This structure represents a single EXEC push operation. UMDs should pass an<br>
+ * array of this structure via struct drm_nouveau_exec's &push_ptr field.<br>
+ */<br>
+struct drm_nouveau_exec_push {<br>
+ /**<br>
+ * @va: the virtual address of the push buffer mapping<br>
+ */<br>
+ __u64 va;<br>
+ /**<br>
+ * @va_len: the length of the push buffer mapping<br>
+ */<br>
+ __u64 va_len;<br>
+};<br>
+<br>
+/**<br>
+ * struct drm_nouveau_exec - structure for DRM_IOCTL_NOUVEAU_EXEC<br>
+ */<br>
+struct drm_nouveau_exec {<br>
+ /**<br>
+ * @channel: the channel to execute the push buffer in<br>
+ */<br>
+ __u32 channel;<br>
+ /**<br>
+ * @push_count: the number of &drm_nouveau_exec_push ops<br>
+ */<br>
+ __u32 push_count;<br>
+ /**<br>
+ * @wait_count: the number of wait &drm_nouveau_syncs<br>
+ */<br>
+ __u32 wait_count;<br>
+ /**<br>
+ * @sig_count: the number of &drm_nouveau_syncs to signal when finished<br>
+ */<br>
+ __u32 sig_count;<br>
+ /**<br>
+ * @wait_ptr: pointer to &drm_nouveau_syncs to wait for<br>
+ */<br>
+ __u64 wait_ptr;<br>
+ /**<br>
+ * @sig_ptr: pointer to &drm_nouveau_syncs to signal when finished<br>
+ */<br>
+ __u64 sig_ptr;<br>
+ /**<br>
+ * @push_ptr: pointer to &drm_nouveau_exec_push ops<br>
+ */<br>
+ __u64 push_ptr;<br>
+};<br>
+<br>
#define DRM_NOUVEAU_GETPARAM 0x00 /* deprecated */<br>
#define DRM_NOUVEAU_SETPARAM 0x01 /* deprecated */<br>
#define DRM_NOUVEAU_CHANNEL_ALLOC 0x02 /* deprecated */<br>
@@ -136,6 +347,9 @@ struct drm_nouveau_gem_cpu_fini {<br>
#define DRM_NOUVEAU_NVIF 0x07<br>
#define DRM_NOUVEAU_SVM_INIT 0x08<br>
#define DRM_NOUVEAU_SVM_BIND 0x09<br>
+#define DRM_NOUVEAU_VM_INIT 0x10<br>
+#define DRM_NOUVEAU_VM_BIND 0x11<br>
+#define DRM_NOUVEAU_EXEC 0x12<br>
#define DRM_NOUVEAU_GEM_NEW 0x40<br>
#define DRM_NOUVEAU_GEM_PUSHBUF 0x41<br>
#define DRM_NOUVEAU_GEM_CPU_PREP 0x42<br>
@@ -197,6 +411,9 @@ struct drm_nouveau_svm_bind {<br>
#define DRM_IOCTL_NOUVEAU_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_CPU_FINI, struct drm_nouveau_gem_cpu_fini)<br>
#define DRM_IOCTL_NOUVEAU_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_INFO, struct drm_nouveau_gem_info)<br>
<br>
+#define DRM_IOCTL_NOUVEAU_VM_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_INIT, struct drm_nouveau_vm_init)<br>
+#define DRM_IOCTL_NOUVEAU_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_BIND, struct drm_nouveau_vm_bind)<br>
+#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec)<br>
#if defined(__cplusplus)<br>
}<br>
#endif<br>
-- <br>
2.41.0<br>
<br>
</blockquote></div></div>