nouveau_abi16.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. #include <nvif/client.h>
  24. #include <nvif/driver.h>
  25. #include <nvif/fifo.h>
  26. #include <nvif/ioctl.h>
  27. #include <nvif/class.h>
  28. #include <nvif/cl0002.h>
  29. #include <nvif/cla06f.h>
  30. #include <nvif/unpack.h>
  31. #include "nouveau_drv.h"
  32. #include "nouveau_dma.h"
  33. #include "nouveau_gem.h"
  34. #include "nouveau_chan.h"
  35. #include "nouveau_abi16.h"
  36. #include "nouveau_vmm.h"
  37. static struct nouveau_abi16 *
  38. nouveau_abi16(struct drm_file *file_priv)
  39. {
  40. struct nouveau_cli *cli = nouveau_cli(file_priv);
  41. if (!cli->abi16) {
  42. struct nouveau_abi16 *abi16;
  43. cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL);
  44. if (cli->abi16) {
  45. struct nv_device_v0 args = {
  46. .device = ~0ULL,
  47. };
  48. INIT_LIST_HEAD(&abi16->channels);
  49. /* allocate device object targeting client's default
  50. * device (ie. the one that belongs to the fd it
  51. * opened)
  52. */
  53. if (nvif_device_ctor(&cli->base.object, "abi16Device",
  54. 0, NV_DEVICE, &args, sizeof(args),
  55. &abi16->device) == 0)
  56. return cli->abi16;
  57. kfree(cli->abi16);
  58. cli->abi16 = NULL;
  59. }
  60. }
  61. return cli->abi16;
  62. }
  63. struct nouveau_abi16 *
  64. nouveau_abi16_get(struct drm_file *file_priv)
  65. {
  66. struct nouveau_cli *cli = nouveau_cli(file_priv);
  67. mutex_lock(&cli->mutex);
  68. if (nouveau_abi16(file_priv))
  69. return cli->abi16;
  70. mutex_unlock(&cli->mutex);
  71. return NULL;
  72. }
  73. int
  74. nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
  75. {
  76. struct nouveau_cli *cli = (void *)abi16->device.object.client;
  77. mutex_unlock(&cli->mutex);
  78. return ret;
  79. }
  80. s32
  81. nouveau_abi16_swclass(struct nouveau_drm *drm)
  82. {
  83. switch (drm->client.device.info.family) {
  84. case NV_DEVICE_INFO_V0_TNT:
  85. return NVIF_CLASS_SW_NV04;
  86. case NV_DEVICE_INFO_V0_CELSIUS:
  87. case NV_DEVICE_INFO_V0_KELVIN:
  88. case NV_DEVICE_INFO_V0_RANKINE:
  89. case NV_DEVICE_INFO_V0_CURIE:
  90. return NVIF_CLASS_SW_NV10;
  91. case NV_DEVICE_INFO_V0_TESLA:
  92. return NVIF_CLASS_SW_NV50;
  93. case NV_DEVICE_INFO_V0_FERMI:
  94. case NV_DEVICE_INFO_V0_KEPLER:
  95. case NV_DEVICE_INFO_V0_MAXWELL:
  96. case NV_DEVICE_INFO_V0_PASCAL:
  97. case NV_DEVICE_INFO_V0_VOLTA:
  98. return NVIF_CLASS_SW_GF100;
  99. }
  100. return 0x0000;
  101. }
  102. static void
  103. nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan,
  104. struct nouveau_abi16_ntfy *ntfy)
  105. {
  106. nvif_object_dtor(&ntfy->object);
  107. nvkm_mm_free(&chan->heap, &ntfy->node);
  108. list_del(&ntfy->head);
  109. kfree(ntfy);
  110. }
  111. static void
  112. nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
  113. struct nouveau_abi16_chan *chan)
  114. {
  115. struct nouveau_abi16_ntfy *ntfy, *temp;
  116. /* wait for all activity to stop before releasing notify object, which
  117. * may be still in use */
  118. if (chan->chan && chan->ntfy)
  119. nouveau_channel_idle(chan->chan);
  120. /* cleanup notifier state */
  121. list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) {
  122. nouveau_abi16_ntfy_fini(chan, ntfy);
  123. }
  124. if (chan->ntfy) {
  125. nouveau_vma_del(&chan->ntfy_vma);
  126. nouveau_bo_unpin(chan->ntfy);
  127. drm_gem_object_put(&chan->ntfy->bo.base);
  128. }
  129. if (chan->heap.block_size)
  130. nvkm_mm_fini(&chan->heap);
  131. /* destroy channel object, all children will be killed too */
  132. if (chan->chan) {
  133. nouveau_channel_idle(chan->chan);
  134. nouveau_channel_del(&chan->chan);
  135. }
  136. list_del(&chan->head);
  137. kfree(chan);
  138. }
  139. void
  140. nouveau_abi16_fini(struct nouveau_abi16 *abi16)
  141. {
  142. struct nouveau_cli *cli = (void *)abi16->device.object.client;
  143. struct nouveau_abi16_chan *chan, *temp;
  144. /* cleanup channels */
  145. list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
  146. nouveau_abi16_chan_fini(abi16, chan);
  147. }
  148. /* destroy the device object */
  149. nvif_device_dtor(&abi16->device);
  150. kfree(cli->abi16);
  151. cli->abi16 = NULL;
  152. }
  153. int
  154. nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
  155. {
  156. struct nouveau_cli *cli = nouveau_cli(file_priv);
  157. struct nouveau_drm *drm = nouveau_drm(dev);
  158. struct nvif_device *device = &drm->client.device;
  159. struct nvkm_gr *gr = nvxx_gr(device);
  160. struct drm_nouveau_getparam *getparam = data;
  161. switch (getparam->param) {
  162. case NOUVEAU_GETPARAM_CHIPSET_ID:
  163. getparam->value = device->info.chipset;
  164. break;
  165. case NOUVEAU_GETPARAM_PCI_VENDOR:
  166. if (device->info.platform != NV_DEVICE_INFO_V0_SOC)
  167. getparam->value = dev->pdev->vendor;
  168. else
  169. getparam->value = 0;
  170. break;
  171. case NOUVEAU_GETPARAM_PCI_DEVICE:
  172. if (device->info.platform != NV_DEVICE_INFO_V0_SOC)
  173. getparam->value = dev->pdev->device;
  174. else
  175. getparam->value = 0;
  176. break;
  177. case NOUVEAU_GETPARAM_BUS_TYPE:
  178. switch (device->info.platform) {
  179. case NV_DEVICE_INFO_V0_AGP : getparam->value = 0; break;
  180. case NV_DEVICE_INFO_V0_PCI : getparam->value = 1; break;
  181. case NV_DEVICE_INFO_V0_PCIE: getparam->value = 2; break;
  182. case NV_DEVICE_INFO_V0_SOC : getparam->value = 3; break;
  183. case NV_DEVICE_INFO_V0_IGP :
  184. if (!pci_is_pcie(dev->pdev))
  185. getparam->value = 1;
  186. else
  187. getparam->value = 2;
  188. break;
  189. default:
  190. WARN_ON(1);
  191. break;
  192. }
  193. break;
  194. case NOUVEAU_GETPARAM_FB_SIZE:
  195. getparam->value = drm->gem.vram_available;
  196. break;
  197. case NOUVEAU_GETPARAM_AGP_SIZE:
  198. getparam->value = drm->gem.gart_available;
  199. break;
  200. case NOUVEAU_GETPARAM_VM_VRAM_BASE:
  201. getparam->value = 0; /* deprecated */
  202. break;
  203. case NOUVEAU_GETPARAM_PTIMER_TIME:
  204. getparam->value = nvif_device_time(device);
  205. break;
  206. case NOUVEAU_GETPARAM_HAS_BO_USAGE:
  207. getparam->value = 1;
  208. break;
  209. case NOUVEAU_GETPARAM_HAS_PAGEFLIP:
  210. getparam->value = 1;
  211. break;
  212. case NOUVEAU_GETPARAM_GRAPH_UNITS:
  213. getparam->value = nvkm_gr_units(gr);
  214. break;
  215. default:
  216. NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param);
  217. return -EINVAL;
  218. }
  219. return 0;
  220. }
  221. int
  222. nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
  223. {
  224. struct drm_nouveau_channel_alloc *init = data;
  225. struct nouveau_cli *cli = nouveau_cli(file_priv);
  226. struct nouveau_drm *drm = nouveau_drm(dev);
  227. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  228. struct nouveau_abi16_chan *chan;
  229. struct nvif_device *device;
  230. u64 engine;
  231. int ret;
  232. if (unlikely(!abi16))
  233. return -ENOMEM;
  234. if (!drm->channel)
  235. return nouveau_abi16_put(abi16, -ENODEV);
  236. device = &abi16->device;
  237. /* hack to allow channel engine type specification on kepler */
  238. if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
  239. if (init->fb_ctxdma_handle == ~0) {
  240. switch (init->tt_ctxdma_handle) {
  241. case 0x01: engine = NV_DEVICE_INFO_ENGINE_GR ; break;
  242. case 0x02: engine = NV_DEVICE_INFO_ENGINE_MSPDEC; break;
  243. case 0x04: engine = NV_DEVICE_INFO_ENGINE_MSPPP ; break;
  244. case 0x08: engine = NV_DEVICE_INFO_ENGINE_MSVLD ; break;
  245. case 0x30: engine = NV_DEVICE_INFO_ENGINE_CE ; break;
  246. default:
  247. return nouveau_abi16_put(abi16, -ENOSYS);
  248. }
  249. } else {
  250. engine = NV_DEVICE_INFO_ENGINE_GR;
  251. }
  252. if (engine != NV_DEVICE_INFO_ENGINE_CE)
  253. engine = nvif_fifo_runlist(device, engine);
  254. else
  255. engine = nvif_fifo_runlist_ce(device);
  256. init->fb_ctxdma_handle = engine;
  257. init->tt_ctxdma_handle = 0;
  258. }
  259. if (init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0)
  260. return nouveau_abi16_put(abi16, -EINVAL);
  261. /* allocate "abi16 channel" data and make up a handle for it */
  262. chan = kzalloc(sizeof(*chan), GFP_KERNEL);
  263. if (!chan)
  264. return nouveau_abi16_put(abi16, -ENOMEM);
  265. INIT_LIST_HEAD(&chan->notifiers);
  266. list_add(&chan->head, &abi16->channels);
  267. /* create channel object and initialise dma and fence management */
  268. ret = nouveau_channel_new(drm, device, init->fb_ctxdma_handle,
  269. init->tt_ctxdma_handle, false, &chan->chan);
  270. if (ret)
  271. goto done;
  272. init->channel = chan->chan->chid;
  273. if (device->info.family >= NV_DEVICE_INFO_V0_TESLA)
  274. init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM |
  275. NOUVEAU_GEM_DOMAIN_GART;
  276. else
  277. if (chan->chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM)
  278. init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM;
  279. else
  280. init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART;
  281. if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) {
  282. init->subchan[0].handle = 0x00000000;
  283. init->subchan[0].grclass = 0x0000;
  284. init->subchan[1].handle = chan->chan->nvsw.handle;
  285. init->subchan[1].grclass = 0x506e;
  286. init->nr_subchan = 2;
  287. }
  288. /* Named memory object area */
  289. ret = nouveau_gem_new(cli, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART,
  290. 0, 0, &chan->ntfy);
  291. if (ret == 0)
  292. ret = nouveau_bo_pin(chan->ntfy, NOUVEAU_GEM_DOMAIN_GART,
  293. false);
  294. if (ret)
  295. goto done;
  296. if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
  297. ret = nouveau_vma_new(chan->ntfy, chan->chan->vmm,
  298. &chan->ntfy_vma);
  299. if (ret)
  300. goto done;
  301. }
  302. ret = drm_gem_handle_create(file_priv, &chan->ntfy->bo.base,
  303. &init->notifier_handle);
  304. if (ret)
  305. goto done;
  306. ret = nvkm_mm_init(&chan->heap, 0, 0, PAGE_SIZE, 1);
  307. done:
  308. if (ret)
  309. nouveau_abi16_chan_fini(abi16, chan);
  310. return nouveau_abi16_put(abi16, ret);
  311. }
  312. static struct nouveau_abi16_chan *
  313. nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
  314. {
  315. struct nouveau_abi16_chan *chan;
  316. list_for_each_entry(chan, &abi16->channels, head) {
  317. if (chan->chan->chid == channel)
  318. return chan;
  319. }
  320. return NULL;
  321. }
  322. int
  323. nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size)
  324. {
  325. union {
  326. struct nvif_ioctl_v0 v0;
  327. } *args = data;
  328. struct nouveau_abi16_chan *chan;
  329. struct nouveau_abi16 *abi16;
  330. int ret = -ENOSYS;
  331. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
  332. switch (args->v0.type) {
  333. case NVIF_IOCTL_V0_NEW:
  334. case NVIF_IOCTL_V0_MTHD:
  335. case NVIF_IOCTL_V0_SCLASS:
  336. break;
  337. default:
  338. return -EACCES;
  339. }
  340. } else
  341. return ret;
  342. if (!(abi16 = nouveau_abi16(file_priv)))
  343. return -ENOMEM;
  344. if (args->v0.token != ~0ULL) {
  345. if (!(chan = nouveau_abi16_chan(abi16, args->v0.token)))
  346. return -EINVAL;
  347. args->v0.object = nvif_handle(&chan->chan->user);
  348. args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
  349. return 0;
  350. }
  351. args->v0.object = nvif_handle(&abi16->device.object);
  352. args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
  353. return 0;
  354. }
  355. int
  356. nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
  357. {
  358. struct drm_nouveau_channel_free *req = data;
  359. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  360. struct nouveau_abi16_chan *chan;
  361. if (unlikely(!abi16))
  362. return -ENOMEM;
  363. chan = nouveau_abi16_chan(abi16, req->channel);
  364. if (!chan)
  365. return nouveau_abi16_put(abi16, -ENOENT);
  366. nouveau_abi16_chan_fini(abi16, chan);
  367. return nouveau_abi16_put(abi16, 0);
  368. }
  369. int
  370. nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
  371. {
  372. struct drm_nouveau_grobj_alloc *init = data;
  373. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  374. struct nouveau_abi16_chan *chan;
  375. struct nouveau_abi16_ntfy *ntfy;
  376. struct nvif_client *client;
  377. struct nvif_sclass *sclass;
  378. s32 oclass = 0;
  379. int ret, i;
  380. if (unlikely(!abi16))
  381. return -ENOMEM;
  382. if (init->handle == ~0)
  383. return nouveau_abi16_put(abi16, -EINVAL);
  384. client = abi16->device.object.client;
  385. chan = nouveau_abi16_chan(abi16, init->channel);
  386. if (!chan)
  387. return nouveau_abi16_put(abi16, -ENOENT);
  388. ret = nvif_object_sclass_get(&chan->chan->user, &sclass);
  389. if (ret < 0)
  390. return nouveau_abi16_put(abi16, ret);
  391. if ((init->class & 0x00ff) == 0x006e) {
  392. /* nvsw: compatibility with older 0x*6e class identifier */
  393. for (i = 0; !oclass && i < ret; i++) {
  394. switch (sclass[i].oclass) {
  395. case NVIF_CLASS_SW_NV04:
  396. case NVIF_CLASS_SW_NV10:
  397. case NVIF_CLASS_SW_NV50:
  398. case NVIF_CLASS_SW_GF100:
  399. oclass = sclass[i].oclass;
  400. break;
  401. default:
  402. break;
  403. }
  404. }
  405. } else
  406. if ((init->class & 0x00ff) == 0x00b1) {
  407. /* msvld: compatibility with incorrect version exposure */
  408. for (i = 0; i < ret; i++) {
  409. if ((sclass[i].oclass & 0x00ff) == 0x00b1) {
  410. oclass = sclass[i].oclass;
  411. break;
  412. }
  413. }
  414. } else
  415. if ((init->class & 0x00ff) == 0x00b2) { /* mspdec */
  416. /* mspdec: compatibility with incorrect version exposure */
  417. for (i = 0; i < ret; i++) {
  418. if ((sclass[i].oclass & 0x00ff) == 0x00b2) {
  419. oclass = sclass[i].oclass;
  420. break;
  421. }
  422. }
  423. } else
  424. if ((init->class & 0x00ff) == 0x00b3) { /* msppp */
  425. /* msppp: compatibility with incorrect version exposure */
  426. for (i = 0; i < ret; i++) {
  427. if ((sclass[i].oclass & 0x00ff) == 0x00b3) {
  428. oclass = sclass[i].oclass;
  429. break;
  430. }
  431. }
  432. } else {
  433. oclass = init->class;
  434. }
  435. nvif_object_sclass_put(&sclass);
  436. if (!oclass)
  437. return nouveau_abi16_put(abi16, -EINVAL);
  438. ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
  439. if (!ntfy)
  440. return nouveau_abi16_put(abi16, -ENOMEM);
  441. list_add(&ntfy->head, &chan->notifiers);
  442. client->route = NVDRM_OBJECT_ABI16;
  443. ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
  444. oclass, NULL, 0, &ntfy->object);
  445. client->route = NVDRM_OBJECT_NVIF;
  446. if (ret)
  447. nouveau_abi16_ntfy_fini(chan, ntfy);
  448. return nouveau_abi16_put(abi16, ret);
  449. }
  450. int
  451. nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  452. {
  453. struct drm_nouveau_notifierobj_alloc *info = data;
  454. struct nouveau_drm *drm = nouveau_drm(dev);
  455. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  456. struct nouveau_abi16_chan *chan;
  457. struct nouveau_abi16_ntfy *ntfy;
  458. struct nvif_device *device = &abi16->device;
  459. struct nvif_client *client;
  460. struct nv_dma_v0 args = {};
  461. int ret;
  462. if (unlikely(!abi16))
  463. return -ENOMEM;
  464. /* completely unnecessary for these chipsets... */
  465. if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
  466. return nouveau_abi16_put(abi16, -EINVAL);
  467. client = abi16->device.object.client;
  468. chan = nouveau_abi16_chan(abi16, info->channel);
  469. if (!chan)
  470. return nouveau_abi16_put(abi16, -ENOENT);
  471. ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
  472. if (!ntfy)
  473. return nouveau_abi16_put(abi16, -ENOMEM);
  474. list_add(&ntfy->head, &chan->notifiers);
  475. ret = nvkm_mm_head(&chan->heap, 0, 1, info->size, info->size, 1,
  476. &ntfy->node);
  477. if (ret)
  478. goto done;
  479. args.start = ntfy->node->offset;
  480. args.limit = ntfy->node->offset + ntfy->node->length - 1;
  481. if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
  482. args.target = NV_DMA_V0_TARGET_VM;
  483. args.access = NV_DMA_V0_ACCESS_VM;
  484. args.start += chan->ntfy_vma->addr;
  485. args.limit += chan->ntfy_vma->addr;
  486. } else
  487. if (drm->agp.bridge) {
  488. args.target = NV_DMA_V0_TARGET_AGP;
  489. args.access = NV_DMA_V0_ACCESS_RDWR;
  490. args.start += drm->agp.base + chan->ntfy->offset;
  491. args.limit += drm->agp.base + chan->ntfy->offset;
  492. } else {
  493. args.target = NV_DMA_V0_TARGET_VM;
  494. args.access = NV_DMA_V0_ACCESS_RDWR;
  495. args.start += chan->ntfy->offset;
  496. args.limit += chan->ntfy->offset;
  497. }
  498. client->route = NVDRM_OBJECT_ABI16;
  499. client->super = true;
  500. ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
  501. NV_DMA_IN_MEMORY, &args, sizeof(args),
  502. &ntfy->object);
  503. client->super = false;
  504. client->route = NVDRM_OBJECT_NVIF;
  505. if (ret)
  506. goto done;
  507. info->offset = ntfy->node->offset;
  508. done:
  509. if (ret)
  510. nouveau_abi16_ntfy_fini(chan, ntfy);
  511. return nouveau_abi16_put(abi16, ret);
  512. }
  513. int
  514. nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
  515. {
  516. struct drm_nouveau_gpuobj_free *fini = data;
  517. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  518. struct nouveau_abi16_chan *chan;
  519. struct nouveau_abi16_ntfy *ntfy;
  520. int ret = -ENOENT;
  521. if (unlikely(!abi16))
  522. return -ENOMEM;
  523. chan = nouveau_abi16_chan(abi16, fini->channel);
  524. if (!chan)
  525. return nouveau_abi16_put(abi16, -EINVAL);
  526. /* synchronize with the user channel and destroy the gpu object */
  527. nouveau_channel_idle(chan->chan);
  528. list_for_each_entry(ntfy, &chan->notifiers, head) {
  529. if (ntfy->object.handle == fini->handle) {
  530. nouveau_abi16_ntfy_fini(chan, ntfy);
  531. ret = 0;
  532. break;
  533. }
  534. }
  535. return nouveau_abi16_put(abi16, ret);
  536. }