drm/nouveau: use tile_mode and pte_kind for VM_BIND bo allocations
authorMohamed Ahmed <mohamedahmedegypt2001@gmail.com>
Thu, 9 May 2024 20:43:52 +0000 (23:43 +0300)
committerDanilo Krummrich <dakr@redhat.com>
Mon, 13 May 2024 20:17:58 +0000 (22:17 +0200)
Allow PTE kind and tile mode on BO create with VM_BIND, and add a
GETPARAM to indicate this change. This is needed to support modifiers in
NVK and ensure correctness when dealing with the nouveau GL driver.

The userspace modifiers implementation this is for can be found here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24795

Fixes: b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")
Signed-off-by: Mohamed Ahmed <mohamedahmedegypt2001@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Signed-off-by: Danilo Krummrich <dakr@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240509204352.7597-1-mohamedahmedegypt2001@gmail.com
drivers/gpu/drm/nouveau/nouveau_abi16.c
drivers/gpu/drm/nouveau/nouveau_bo.c
include/uapi/drm/nouveau_drm.h

index 80f74ee0fc78677f8f890e8cc5daf8f363817b34..47e53e17b4e586e2f158d8cf627e7686b89d6d8f 100644 (file)
@@ -272,6 +272,9 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
                getparam->value = (u64)ttm_resource_manager_usage(vram_mgr);
                break;
        }
+       case NOUVEAU_GETPARAM_HAS_VMA_TILEMODE:
+               getparam->value = 1;
+               break;
        default:
                NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param);
                return -EINVAL;
index db8cbf6151129d63fd24e42626dfd10e4c84bb33..186add400ea5ffc8aeb760e9561523693e6c89de 100644 (file)
@@ -241,28 +241,28 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain,
        }
 
        nvbo->contig = !(tile_flags & NOUVEAU_GEM_TILE_NONCONTIG);
-       if (!nouveau_cli_uvmm(cli) || internal) {
-               /* for BO noVM allocs, don't assign kinds */
-               if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) {
-                       nvbo->kind = (tile_flags & 0x0000ff00) >> 8;
-                       if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) {
-                               kfree(nvbo);
-                               return ERR_PTR(-EINVAL);
-                       }
 
-                       nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind;
-               } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
-                       nvbo->kind = (tile_flags & 0x00007f00) >> 8;
-                       nvbo->comp = (tile_flags & 0x00030000) >> 16;
-                       if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) {
-                               kfree(nvbo);
-                               return ERR_PTR(-EINVAL);
-                       }
-               } else {
-                       nvbo->zeta = (tile_flags & 0x00000007);
+       if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) {
+               nvbo->kind = (tile_flags & 0x0000ff00) >> 8;
+               if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) {
+                       kfree(nvbo);
+                       return ERR_PTR(-EINVAL);
+               }
+
+               nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind;
+       } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
+               nvbo->kind = (tile_flags & 0x00007f00) >> 8;
+               nvbo->comp = (tile_flags & 0x00030000) >> 16;
+               if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) {
+                       kfree(nvbo);
+                       return ERR_PTR(-EINVAL);
                }
-               nvbo->mode = tile_mode;
+       } else {
+               nvbo->zeta = (tile_flags & 0x00000007);
+       }
+       nvbo->mode = tile_mode;
 
+       if (!nouveau_cli_uvmm(cli) || internal) {
                /* Determine the desirable target GPU page size for the buffer. */
                for (i = 0; i < vmm->page_nr; i++) {
                        /* Because we cannot currently allow VMM maps to fail
@@ -304,12 +304,6 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain,
                }
                nvbo->page = vmm->page[pi].shift;
        } else {
-               /* reject other tile flags when in VM mode. */
-               if (tile_mode)
-                       return ERR_PTR(-EINVAL);
-               if (tile_flags & ~NOUVEAU_GEM_TILE_NONCONTIG)
-                       return ERR_PTR(-EINVAL);
-
                /* Determine the desirable target GPU page size for the buffer. */
                for (i = 0; i < vmm->page_nr; i++) {
                        /* Because we cannot currently allow VMM maps to fail
index cd84227f1b42ff53e21427de90d0dee1b4ffebbd..5402f77ee8594869fe99ee5a018ac28d92dfd7f0 100644 (file)
@@ -68,6 +68,13 @@ extern "C" {
  */
 #define NOUVEAU_GETPARAM_VRAM_USED 19
 
+/*
+ * NOUVEAU_GETPARAM_HAS_VMA_TILEMODE
+ *
+ * Query whether tile mode and PTE kind are accepted with VM allocs or not.
+ */
+#define NOUVEAU_GETPARAM_HAS_VMA_TILEMODE 20
+
 struct drm_nouveau_getparam {
        __u64 param;
        __u64 value;