Commit b88baab8 authored by Danilo Krummrich's avatar Danilo Krummrich
Browse files

drm/nouveau: implement new VM_BIND uAPI



This commit provides the implementation for the new uapi motivated by the
Vulkan API. It allows user mode drivers (UMDs) to:

1) Initialize a GPU virtual address (VA) space via the new
   DRM_IOCTL_NOUVEAU_VM_INIT ioctl for UMDs to specify the portion of VA
   space managed by the kernel and userspace, respectively.

2) Allocate and free a VA space region as well as bind and unbind memory
   to the GPUs VA space via the new DRM_IOCTL_NOUVEAU_VM_BIND ioctl.
   UMDs can request the named operations to be processed either
   synchronously or asynchronously. It supports DRM syncobjs
   (incl. timelines) as synchronization mechanism. The management of the
   GPU VA mappings is implemented with the DRM GPU VA manager.

3) Execute push buffers with the new DRM_IOCTL_NOUVEAU_EXEC ioctl. The
   execution happens asynchronously. It supports DRM syncobj (incl.
   timelines) as synchronization mechanism. DRM GEM object locking is
   handled with drm_exec.

Both, DRM_IOCTL_NOUVEAU_VM_BIND and DRM_IOCTL_NOUVEAU_EXEC, use the DRM
GPU scheduler for the asynchronous paths.

Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Signed-off-by: default avatarDanilo Krummrich <dakr@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230804182406.5222-12-dakr@redhat.com
parent 6b252cf4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -13,4 +13,7 @@ drm/nouveau uAPI
VM_BIND / EXEC uAPI
-------------------

.. kernel-doc:: drivers/gpu/drm/nouveau/nouveau_exec.c
    :doc: Overview

.. kernel-doc:: include/uapi/drm/nouveau_drm.h
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ nouveau-y += nouveau_prime.o
nouveau-y += nouveau_sgdma.o
nouveau-y += nouveau_ttm.o
nouveau-y += nouveau_vmm.o
nouveau-y += nouveau_exec.o
nouveau-y += nouveau_sched.o
nouveau-y += nouveau_uvmm.o

# DRM - modesetting
nouveau-$(CONFIG_DRM_NOUVEAU_BACKLIGHT) += nouveau_backlight.o
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ config DRM_NOUVEAU
	select DRM_KMS_HELPER
	select DRM_TTM
	select DRM_TTM_HELPER
	select DRM_EXEC
	select DRM_SCHED
	select I2C
	select I2C_ALGOBIT
	select BACKLIGHT_CLASS_DEVICE if DRM_NOUVEAU_BACKLIGHT
+24 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include "nouveau_chan.h"
#include "nouveau_abi16.h"
#include "nouveau_vmm.h"
#include "nouveau_sched.h"

static struct nouveau_abi16 *
nouveau_abi16(struct drm_file *file_priv)
@@ -125,6 +126,17 @@ nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
{
	struct nouveau_abi16_ntfy *ntfy, *temp;

	/* When a client exits without waiting for it's queued up jobs to
	 * finish it might happen that we fault the channel. This is due to
	 * drm_file_free() calling drm_gem_release() before the postclose()
	 * callback. Hence, we can't tear down this scheduler entity before
	 * uvmm mappings are unmapped. Currently, we can't detect this case.
	 *
	 * However, this should be rare and harmless, since the channel isn't
	 * needed anymore.
	 */
	nouveau_sched_entity_fini(&chan->sched_entity);

	/* wait for all activity to stop before cleaning up */
	if (chan->chan)
		nouveau_channel_idle(chan->chan);
@@ -261,6 +273,13 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
	if (!drm->channel)
		return nouveau_abi16_put(abi16, -ENODEV);

	/* If uvmm wasn't initialized until now disable it completely to prevent
	 * userspace from mixing up UAPIs.
	 *
	 * The client lock is already acquired by nouveau_abi16_get().
	 */
	__nouveau_cli_disable_uvmm_noinit(cli);

	device = &abi16->device;
	engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR;

@@ -304,6 +323,11 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
	if (ret)
		goto done;

	ret = nouveau_sched_entity_init(&chan->sched_entity, &drm->sched,
					drm->sched_wq);
	if (ret)
		goto done;

	init->channel = chan->chan->chid;

	if (device->info.family >= NV_DEVICE_INFO_V0_TESLA)
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ struct nouveau_abi16_chan {
	struct nouveau_bo *ntfy;
	struct nouveau_vma *ntfy_vma;
	struct nvkm_mm  heap;
	struct nouveau_sched_entity sched_entity;
};

struct nouveau_abi16 {
Loading