1 /* 2 * Copyright 2012 Red Hat Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 */ 23 24 #include <nvif/client.h> 25 #include <nvif/driver.h> 26 #include <nvif/fifo.h> 27 #include <nvif/ioctl.h> 28 #include <nvif/class.h> 29 #include <nvif/cl0002.h> 30 #include <nvif/unpack.h> 31 32 #include "nouveau_drv.h" 33 #include "nouveau_dma.h" 34 #include "nouveau_exec.h" 35 #include "nouveau_gem.h" 36 #include "nouveau_chan.h" 37 #include "nouveau_abi16.h" 38 #include "nouveau_vmm.h" 39 #include "nouveau_sched.h" 40 41 static struct nouveau_abi16 * 42 nouveau_abi16(struct drm_file *file_priv) 43 { 44 struct nouveau_cli *cli = nouveau_cli(file_priv); 45 if (!cli->abi16) { 46 struct nouveau_abi16 *abi16; 47 cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL); 48 if (cli->abi16) { 49 struct nv_device_v0 args = { 50 .device = ~0ULL, 51 }; 52 53 INIT_LIST_HEAD(&abi16->channels); 54 55 /* allocate device object targeting client's default 56 * device (ie. the one that belongs to the fd it 57 * opened) 58 */ 59 if (nvif_device_ctor(&cli->base.object, "abi16Device", 60 0, NV_DEVICE, &args, sizeof(args), 61 &abi16->device) == 0) 62 return cli->abi16; 63 64 kfree(cli->abi16); 65 cli->abi16 = NULL; 66 } 67 } 68 return cli->abi16; 69 } 70 71 struct nouveau_abi16 * 72 nouveau_abi16_get(struct drm_file *file_priv) 73 { 74 struct nouveau_cli *cli = nouveau_cli(file_priv); 75 mutex_lock(&cli->mutex); 76 if (nouveau_abi16(file_priv)) 77 return cli->abi16; 78 mutex_unlock(&cli->mutex); 79 return NULL; 80 } 81 82 int 83 nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret) 84 { 85 struct nouveau_cli *cli = (void *)abi16->device.object.client; 86 mutex_unlock(&cli->mutex); 87 return ret; 88 } 89 90 s32 91 nouveau_abi16_swclass(struct nouveau_drm *drm) 92 { 93 switch (drm->client.device.info.family) { 94 case NV_DEVICE_INFO_V0_TNT: 95 return NVIF_CLASS_SW_NV04; 96 case NV_DEVICE_INFO_V0_CELSIUS: 97 case NV_DEVICE_INFO_V0_KELVIN: 98 case NV_DEVICE_INFO_V0_RANKINE: 99 case NV_DEVICE_INFO_V0_CURIE: 100 return NVIF_CLASS_SW_NV10; 101 case NV_DEVICE_INFO_V0_TESLA: 102 return NVIF_CLASS_SW_NV50; 103 case NV_DEVICE_INFO_V0_FERMI: 104 case NV_DEVICE_INFO_V0_KEPLER: 105 case NV_DEVICE_INFO_V0_MAXWELL: 106 case NV_DEVICE_INFO_V0_PASCAL: 107 case NV_DEVICE_INFO_V0_VOLTA: 108 return NVIF_CLASS_SW_GF100; 109 } 110 111 return 0x0000; 112 } 113 114 static void 115 nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan, 116 struct nouveau_abi16_ntfy *ntfy) 117 { 118 nvif_object_dtor(&ntfy->object); 119 nvkm_mm_free(&chan->heap, &ntfy->node); 120 list_del(&ntfy->head); 121 kfree(ntfy); 122 } 123 124 static void 125 nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16, 126 struct nouveau_abi16_chan *chan) 127 { 128 struct nouveau_abi16_ntfy *ntfy, *temp; 129 130 /* Cancel all jobs from the entity's queue. */ 131 drm_sched_entity_fini(&chan->sched.entity); 132 133 if (chan->chan) 134 nouveau_channel_idle(chan->chan); 135 136 nouveau_sched_fini(&chan->sched); 137 138 /* cleanup notifier state */ 139 list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) { 140 nouveau_abi16_ntfy_fini(chan, ntfy); 141 } 142 143 if (chan->ntfy) { 144 nouveau_vma_del(&chan->ntfy_vma); 145 nouveau_bo_unpin(chan->ntfy); 146 drm_gem_object_put(&chan->ntfy->bo.base); 147 } 148 149 if (chan->heap.block_size) 150 nvkm_mm_fini(&chan->heap); 151 152 /* destroy channel object, all children will be killed too */ 153 if (chan->chan) { 154 nvif_object_dtor(&chan->ce); 155 nouveau_channel_del(&chan->chan); 156 } 157 158 list_del(&chan->head); 159 kfree(chan); 160 } 161 162 void 163 nouveau_abi16_fini(struct nouveau_abi16 *abi16) 164 { 165 struct nouveau_cli *cli = (void *)abi16->device.object.client; 166 struct nouveau_abi16_chan *chan, *temp; 167 168 /* cleanup channels */ 169 list_for_each_entry_safe(chan, temp, &abi16->channels, head) { 170 nouveau_abi16_chan_fini(abi16, chan); 171 } 172 173 /* destroy the device object */ 174 nvif_device_dtor(&abi16->device); 175 176 kfree(cli->abi16); 177 cli->abi16 = NULL; 178 } 179 180 static inline int 181 getparam_dma_ib_max(struct nvif_device *device) 182 { 183 const struct nvif_mclass dmas[] = { 184 { NV03_CHANNEL_DMA, 0 }, 185 { NV10_CHANNEL_DMA, 0 }, 186 { NV17_CHANNEL_DMA, 0 }, 187 { NV40_CHANNEL_DMA, 0 }, 188 {} 189 }; 190 191 return nvif_mclass(&device->object, dmas) < 0 ? NV50_DMA_IB_MAX : 0; 192 } 193 194 int 195 nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) 196 { 197 struct nouveau_cli *cli = nouveau_cli(file_priv); 198 struct nouveau_drm *drm = nouveau_drm(dev); 199 struct nvif_device *device = &drm->client.device; 200 struct nvkm_gr *gr = nvxx_gr(device); 201 struct drm_nouveau_getparam *getparam = data; 202 struct pci_dev *pdev = to_pci_dev(dev->dev); 203 204 switch (getparam->param) { 205 case NOUVEAU_GETPARAM_CHIPSET_ID: 206 getparam->value = device->info.chipset; 207 break; 208 case NOUVEAU_GETPARAM_PCI_VENDOR: 209 if (device->info.platform != NV_DEVICE_INFO_V0_SOC) 210 getparam->value = pdev->vendor; 211 else 212 getparam->value = 0; 213 break; 214 case NOUVEAU_GETPARAM_PCI_DEVICE: 215 if (device->info.platform != NV_DEVICE_INFO_V0_SOC) 216 getparam->value = pdev->device; 217 else 218 getparam->value = 0; 219 break; 220 case NOUVEAU_GETPARAM_BUS_TYPE: 221 switch (device->info.platform) { 222 case NV_DEVICE_INFO_V0_AGP : getparam->value = 0; break; 223 case NV_DEVICE_INFO_V0_PCI : getparam->value = 1; break; 224 case NV_DEVICE_INFO_V0_PCIE: getparam->value = 2; break; 225 case NV_DEVICE_INFO_V0_SOC : getparam->value = 3; break; 226 case NV_DEVICE_INFO_V0_IGP : 227 if (!pci_is_pcie(pdev)) 228 getparam->value = 1; 229 else 230 getparam->value = 2; 231 break; 232 default: 233 WARN_ON(1); 234 break; 235 } 236 break; 237 case NOUVEAU_GETPARAM_FB_SIZE: 238 getparam->value = drm->gem.vram_available; 239 break; 240 case NOUVEAU_GETPARAM_AGP_SIZE: 241 getparam->value = drm->gem.gart_available; 242 break; 243 case NOUVEAU_GETPARAM_VM_VRAM_BASE: 244 getparam->value = 0; /* deprecated */ 245 break; 246 case NOUVEAU_GETPARAM_PTIMER_TIME: 247 getparam->value = nvif_device_time(device); 248 break; 249 case NOUVEAU_GETPARAM_HAS_BO_USAGE: 250 getparam->value = 1; 251 break; 252 case NOUVEAU_GETPARAM_HAS_PAGEFLIP: 253 getparam->value = 1; 254 break; 255 case NOUVEAU_GETPARAM_GRAPH_UNITS: 256 getparam->value = nvkm_gr_units(gr); 257 break; 258 case NOUVEAU_GETPARAM_EXEC_PUSH_MAX: { 259 int ib_max = getparam_dma_ib_max(device); 260 261 getparam->value = nouveau_exec_push_max_from_ib_max(ib_max); 262 break; 263 } 264 default: 265 NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param); 266 return -EINVAL; 267 } 268 269 return 0; 270 } 271 272 int 273 nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS) 274 { 275 struct drm_nouveau_channel_alloc *init = data; 276 struct nouveau_cli *cli = nouveau_cli(file_priv); 277 struct nouveau_drm *drm = nouveau_drm(dev); 278 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 279 struct nouveau_abi16_chan *chan; 280 struct nvif_device *device; 281 u64 engine, runm; 282 int ret; 283 284 if (unlikely(!abi16)) 285 return -ENOMEM; 286 287 if (!drm->channel) 288 return nouveau_abi16_put(abi16, -ENODEV); 289 290 /* If uvmm wasn't initialized until now disable it completely to prevent 291 * userspace from mixing up UAPIs. 292 * 293 * The client lock is already acquired by nouveau_abi16_get(). 294 */ 295 __nouveau_cli_disable_uvmm_noinit(cli); 296 297 device = &abi16->device; 298 engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR; 299 300 /* hack to allow channel engine type specification on kepler */ 301 if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) { 302 if (init->fb_ctxdma_handle == ~0) { 303 switch (init->tt_ctxdma_handle) { 304 case 0x01: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR ; break; 305 case 0x02: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPDEC; break; 306 case 0x04: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPPP ; break; 307 case 0x08: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSVLD ; break; 308 case 0x30: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_CE ; break; 309 default: 310 return nouveau_abi16_put(abi16, -ENOSYS); 311 } 312 313 init->fb_ctxdma_handle = 0; 314 init->tt_ctxdma_handle = 0; 315 } 316 } 317 318 if (engine != NV_DEVICE_HOST_RUNLIST_ENGINES_CE) 319 runm = nvif_fifo_runlist(device, engine); 320 else 321 runm = nvif_fifo_runlist_ce(device); 322 323 if (!runm || init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0) 324 return nouveau_abi16_put(abi16, -EINVAL); 325 326 /* allocate "abi16 channel" data and make up a handle for it */ 327 chan = kzalloc(sizeof(*chan), GFP_KERNEL); 328 if (!chan) 329 return nouveau_abi16_put(abi16, -ENOMEM); 330 331 INIT_LIST_HEAD(&chan->notifiers); 332 list_add(&chan->head, &abi16->channels); 333 334 /* create channel object and initialise dma and fence management */ 335 ret = nouveau_channel_new(drm, device, false, runm, init->fb_ctxdma_handle, 336 init->tt_ctxdma_handle, &chan->chan); 337 if (ret) 338 goto done; 339 340 ret = nouveau_sched_init(&chan->sched, drm, drm->sched_wq, 341 chan->chan->dma.ib_max); 342 if (ret) 343 goto done; 344 345 init->channel = chan->chan->chid; 346 347 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) 348 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM | 349 NOUVEAU_GEM_DOMAIN_GART; 350 else 351 if (chan->chan->push.buffer->bo.resource->mem_type == TTM_PL_VRAM) 352 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM; 353 else 354 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART; 355 356 if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) { 357 init->subchan[0].handle = 0x00000000; 358 init->subchan[0].grclass = 0x0000; 359 init->subchan[1].handle = chan->chan->nvsw.handle; 360 init->subchan[1].grclass = 0x506e; 361 init->nr_subchan = 2; 362 } 363 364 /* Workaround "nvc0" gallium driver using classes it doesn't allocate on 365 * Kepler and above. NVKM no longer always sets CE_CTX_VALID as part of 366 * channel init, now we know what that stuff actually is. 367 * 368 * Doesn't matter for Kepler/Pascal, CE context stored in NV_RAMIN. 369 * 370 * Userspace was fixed prior to adding Ampere support. 371 */ 372 switch (device->info.family) { 373 case NV_DEVICE_INFO_V0_VOLTA: 374 ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, VOLTA_DMA_COPY_A, 375 NULL, 0, &chan->ce); 376 if (ret) 377 goto done; 378 break; 379 case NV_DEVICE_INFO_V0_TURING: 380 ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, TURING_DMA_COPY_A, 381 NULL, 0, &chan->ce); 382 if (ret) 383 goto done; 384 break; 385 default: 386 break; 387 } 388 389 /* Named memory object area */ 390 ret = nouveau_gem_new(cli, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART, 391 0, 0, &chan->ntfy); 392 if (ret == 0) 393 ret = nouveau_bo_pin(chan->ntfy, NOUVEAU_GEM_DOMAIN_GART, 394 false); 395 if (ret) 396 goto done; 397 398 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { 399 ret = nouveau_vma_new(chan->ntfy, chan->chan->vmm, 400 &chan->ntfy_vma); 401 if (ret) 402 goto done; 403 } 404 405 ret = drm_gem_handle_create(file_priv, &chan->ntfy->bo.base, 406 &init->notifier_handle); 407 if (ret) 408 goto done; 409 410 ret = nvkm_mm_init(&chan->heap, 0, 0, PAGE_SIZE, 1); 411 done: 412 if (ret) 413 nouveau_abi16_chan_fini(abi16, chan); 414 return nouveau_abi16_put(abi16, ret); 415 } 416 417 static struct nouveau_abi16_chan * 418 nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel) 419 { 420 struct nouveau_abi16_chan *chan; 421 422 list_for_each_entry(chan, &abi16->channels, head) { 423 if (chan->chan->chid == channel) 424 return chan; 425 } 426 427 return NULL; 428 } 429 430 int 431 nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size) 432 { 433 union { 434 struct nvif_ioctl_v0 v0; 435 } *args = data; 436 struct nouveau_abi16_chan *chan; 437 struct nouveau_abi16 *abi16; 438 int ret = -ENOSYS; 439 440 if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) { 441 switch (args->v0.type) { 442 case NVIF_IOCTL_V0_NEW: 443 case NVIF_IOCTL_V0_MTHD: 444 case NVIF_IOCTL_V0_SCLASS: 445 break; 446 default: 447 return -EACCES; 448 } 449 } else 450 return ret; 451 452 if (!(abi16 = nouveau_abi16(file_priv))) 453 return -ENOMEM; 454 455 if (args->v0.token != ~0ULL) { 456 if (!(chan = nouveau_abi16_chan(abi16, args->v0.token))) 457 return -EINVAL; 458 args->v0.object = nvif_handle(&chan->chan->user); 459 args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY; 460 return 0; 461 } 462 463 args->v0.object = nvif_handle(&abi16->device.object); 464 args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY; 465 return 0; 466 } 467 468 int 469 nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS) 470 { 471 struct drm_nouveau_channel_free *req = data; 472 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 473 struct nouveau_abi16_chan *chan; 474 475 if (unlikely(!abi16)) 476 return -ENOMEM; 477 478 chan = nouveau_abi16_chan(abi16, req->channel); 479 if (!chan) 480 return nouveau_abi16_put(abi16, -ENOENT); 481 nouveau_abi16_chan_fini(abi16, chan); 482 return nouveau_abi16_put(abi16, 0); 483 } 484 485 int 486 nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS) 487 { 488 struct drm_nouveau_grobj_alloc *init = data; 489 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 490 struct nouveau_abi16_chan *chan; 491 struct nouveau_abi16_ntfy *ntfy; 492 struct nvif_client *client; 493 struct nvif_sclass *sclass; 494 s32 oclass = 0; 495 int ret, i; 496 497 if (unlikely(!abi16)) 498 return -ENOMEM; 499 500 if (init->handle == ~0) 501 return nouveau_abi16_put(abi16, -EINVAL); 502 client = abi16->device.object.client; 503 504 chan = nouveau_abi16_chan(abi16, init->channel); 505 if (!chan) 506 return nouveau_abi16_put(abi16, -ENOENT); 507 508 ret = nvif_object_sclass_get(&chan->chan->user, &sclass); 509 if (ret < 0) 510 return nouveau_abi16_put(abi16, ret); 511 512 if ((init->class & 0x00ff) == 0x006e) { 513 /* nvsw: compatibility with older 0x*6e class identifier */ 514 for (i = 0; !oclass && i < ret; i++) { 515 switch (sclass[i].oclass) { 516 case NVIF_CLASS_SW_NV04: 517 case NVIF_CLASS_SW_NV10: 518 case NVIF_CLASS_SW_NV50: 519 case NVIF_CLASS_SW_GF100: 520 oclass = sclass[i].oclass; 521 break; 522 default: 523 break; 524 } 525 } 526 } else 527 if ((init->class & 0x00ff) == 0x00b1) { 528 /* msvld: compatibility with incorrect version exposure */ 529 for (i = 0; i < ret; i++) { 530 if ((sclass[i].oclass & 0x00ff) == 0x00b1) { 531 oclass = sclass[i].oclass; 532 break; 533 } 534 } 535 } else 536 if ((init->class & 0x00ff) == 0x00b2) { /* mspdec */ 537 /* mspdec: compatibility with incorrect version exposure */ 538 for (i = 0; i < ret; i++) { 539 if ((sclass[i].oclass & 0x00ff) == 0x00b2) { 540 oclass = sclass[i].oclass; 541 break; 542 } 543 } 544 } else 545 if ((init->class & 0x00ff) == 0x00b3) { /* msppp */ 546 /* msppp: compatibility with incorrect version exposure */ 547 for (i = 0; i < ret; i++) { 548 if ((sclass[i].oclass & 0x00ff) == 0x00b3) { 549 oclass = sclass[i].oclass; 550 break; 551 } 552 } 553 } else { 554 oclass = init->class; 555 } 556 557 nvif_object_sclass_put(&sclass); 558 if (!oclass) 559 return nouveau_abi16_put(abi16, -EINVAL); 560 561 ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL); 562 if (!ntfy) 563 return nouveau_abi16_put(abi16, -ENOMEM); 564 565 list_add(&ntfy->head, &chan->notifiers); 566 567 client->route = NVDRM_OBJECT_ABI16; 568 ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle, 569 oclass, NULL, 0, &ntfy->object); 570 client->route = NVDRM_OBJECT_NVIF; 571 572 if (ret) 573 nouveau_abi16_ntfy_fini(chan, ntfy); 574 return nouveau_abi16_put(abi16, ret); 575 } 576 577 int 578 nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS) 579 { 580 struct drm_nouveau_notifierobj_alloc *info = data; 581 struct nouveau_drm *drm = nouveau_drm(dev); 582 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 583 struct nouveau_abi16_chan *chan; 584 struct nouveau_abi16_ntfy *ntfy; 585 struct nvif_device *device = &abi16->device; 586 struct nvif_client *client; 587 struct nv_dma_v0 args = {}; 588 int ret; 589 590 if (unlikely(!abi16)) 591 return -ENOMEM; 592 593 /* completely unnecessary for these chipsets... */ 594 if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI)) 595 return nouveau_abi16_put(abi16, -EINVAL); 596 client = abi16->device.object.client; 597 598 chan = nouveau_abi16_chan(abi16, info->channel); 599 if (!chan) 600 return nouveau_abi16_put(abi16, -ENOENT); 601 602 ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL); 603 if (!ntfy) 604 return nouveau_abi16_put(abi16, -ENOMEM); 605 606 list_add(&ntfy->head, &chan->notifiers); 607 608 ret = nvkm_mm_head(&chan->heap, 0, 1, info->size, info->size, 1, 609 &ntfy->node); 610 if (ret) 611 goto done; 612 613 args.start = ntfy->node->offset; 614 args.limit = ntfy->node->offset + ntfy->node->length - 1; 615 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { 616 args.target = NV_DMA_V0_TARGET_VM; 617 args.access = NV_DMA_V0_ACCESS_VM; 618 args.start += chan->ntfy_vma->addr; 619 args.limit += chan->ntfy_vma->addr; 620 } else 621 if (drm->agp.bridge) { 622 args.target = NV_DMA_V0_TARGET_AGP; 623 args.access = NV_DMA_V0_ACCESS_RDWR; 624 args.start += drm->agp.base + chan->ntfy->offset; 625 args.limit += drm->agp.base + chan->ntfy->offset; 626 } else { 627 args.target = NV_DMA_V0_TARGET_VM; 628 args.access = NV_DMA_V0_ACCESS_RDWR; 629 args.start += chan->ntfy->offset; 630 args.limit += chan->ntfy->offset; 631 } 632 633 client->route = NVDRM_OBJECT_ABI16; 634 ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle, 635 NV_DMA_IN_MEMORY, &args, sizeof(args), 636 &ntfy->object); 637 client->route = NVDRM_OBJECT_NVIF; 638 if (ret) 639 goto done; 640 641 info->offset = ntfy->node->offset; 642 done: 643 if (ret) 644 nouveau_abi16_ntfy_fini(chan, ntfy); 645 return nouveau_abi16_put(abi16, ret); 646 } 647 648 int 649 nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS) 650 { 651 struct drm_nouveau_gpuobj_free *fini = data; 652 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 653 struct nouveau_abi16_chan *chan; 654 struct nouveau_abi16_ntfy *ntfy; 655 int ret = -ENOENT; 656 657 if (unlikely(!abi16)) 658 return -ENOMEM; 659 660 chan = nouveau_abi16_chan(abi16, fini->channel); 661 if (!chan) 662 return nouveau_abi16_put(abi16, -EINVAL); 663 664 /* synchronize with the user channel and destroy the gpu object */ 665 nouveau_channel_idle(chan->chan); 666 667 list_for_each_entry(ntfy, &chan->notifiers, head) { 668 if (ntfy->object.handle == fini->handle) { 669 nouveau_abi16_ntfy_fini(chan, ntfy); 670 ret = 0; 671 break; 672 } 673 } 674 675 return nouveau_abi16_put(abi16, ret); 676 } 677