nouveau_abi16.c 16 KB

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