Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/nouveau: use tile_mode and pte_kind for VM_BIND bo allocations

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

authored by

Mohamed Ahmed and committed by
Danilo Krummrich
959314c4 3ce4322b

+29 -25
+3
drivers/gpu/drm/nouveau/nouveau_abi16.c
··· 272 272 getparam->value = (u64)ttm_resource_manager_usage(vram_mgr); 273 273 break; 274 274 } 275 + case NOUVEAU_GETPARAM_HAS_VMA_TILEMODE: 276 + getparam->value = 1; 277 + break; 275 278 default: 276 279 NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param); 277 280 return -EINVAL;
+19 -25
drivers/gpu/drm/nouveau/nouveau_bo.c
··· 241 241 } 242 242 243 243 nvbo->contig = !(tile_flags & NOUVEAU_GEM_TILE_NONCONTIG); 244 - if (!nouveau_cli_uvmm(cli) || internal) { 245 - /* for BO noVM allocs, don't assign kinds */ 246 - if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { 247 - nvbo->kind = (tile_flags & 0x0000ff00) >> 8; 248 - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { 249 - kfree(nvbo); 250 - return ERR_PTR(-EINVAL); 251 - } 252 244 253 - nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; 254 - } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { 255 - nvbo->kind = (tile_flags & 0x00007f00) >> 8; 256 - nvbo->comp = (tile_flags & 0x00030000) >> 16; 257 - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { 258 - kfree(nvbo); 259 - return ERR_PTR(-EINVAL); 260 - } 261 - } else { 262 - nvbo->zeta = (tile_flags & 0x00000007); 245 + if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { 246 + nvbo->kind = (tile_flags & 0x0000ff00) >> 8; 247 + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { 248 + kfree(nvbo); 249 + return ERR_PTR(-EINVAL); 263 250 } 264 - nvbo->mode = tile_mode; 265 251 252 + nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; 253 + } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { 254 + nvbo->kind = (tile_flags & 0x00007f00) >> 8; 255 + nvbo->comp = (tile_flags & 0x00030000) >> 16; 256 + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { 257 + kfree(nvbo); 258 + return ERR_PTR(-EINVAL); 259 + } 260 + } else { 261 + nvbo->zeta = (tile_flags & 0x00000007); 262 + } 263 + nvbo->mode = tile_mode; 264 + 265 + if (!nouveau_cli_uvmm(cli) || internal) { 266 266 /* Determine the desirable target GPU page size for the buffer. */ 267 267 for (i = 0; i < vmm->page_nr; i++) { 268 268 /* Because we cannot currently allow VMM maps to fail ··· 304 304 } 305 305 nvbo->page = vmm->page[pi].shift; 306 306 } else { 307 - /* reject other tile flags when in VM mode. */ 308 - if (tile_mode) 309 - return ERR_PTR(-EINVAL); 310 - if (tile_flags & ~NOUVEAU_GEM_TILE_NONCONTIG) 311 - return ERR_PTR(-EINVAL); 312 - 313 307 /* Determine the desirable target GPU page size for the buffer. */ 314 308 for (i = 0; i < vmm->page_nr; i++) { 315 309 /* Because we cannot currently allow VMM maps to fail
+7
include/uapi/drm/nouveau_drm.h
··· 68 68 */ 69 69 #define NOUVEAU_GETPARAM_VRAM_USED 19 70 70 71 + /* 72 + * NOUVEAU_GETPARAM_HAS_VMA_TILEMODE 73 + * 74 + * Query whether tile mode and PTE kind are accepted with VM allocs or not. 75 + */ 76 + #define NOUVEAU_GETPARAM_HAS_VMA_TILEMODE 20 77 + 71 78 struct drm_nouveau_getparam { 72 79 __u64 param; 73 80 __u64 value;