nouveau_abi16.c 16 KB

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