nouveau_abi16.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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 cleaning up */
  117. if (chan->chan)
  118. nouveau_channel_idle(chan->chan);
  119. /* cleanup notifier state */
  120. list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) {
  121. nouveau_abi16_ntfy_fini(chan, ntfy);
  122. }
  123. if (chan->ntfy) {
  124. nouveau_vma_del(&chan->ntfy_vma);
  125. nouveau_bo_unpin(chan->ntfy);
  126. drm_gem_object_put(&chan->ntfy->bo.base);
  127. }
  128. if (chan->heap.block_size)
  129. nvkm_mm_fini(&chan->heap);
  130. /* destroy channel object, all children will be killed too */
  131. if (chan->chan) {
  132. nvif_object_dtor(&chan->ce);
  133. nouveau_channel_del(&chan->chan);
  134. }
  135. list_del(&chan->head);
  136. kfree(chan);
  137. }
  138. void
  139. nouveau_abi16_fini(struct nouveau_abi16 *abi16)
  140. {
  141. struct nouveau_cli *cli = (void *)abi16->device.object.client;
  142. struct nouveau_abi16_chan *chan, *temp;
  143. /* cleanup channels */
  144. list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
  145. nouveau_abi16_chan_fini(abi16, chan);
  146. }
  147. /* destroy the device object */
  148. nvif_device_dtor(&abi16->device);
  149. kfree(cli->abi16);
  150. cli->abi16 = NULL;
  151. }
  152. int
  153. nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
  154. {
  155. struct nouveau_cli *cli = nouveau_cli(file_priv);
  156. struct nouveau_drm *drm = nouveau_drm(dev);
  157. struct nvif_device *device = &drm->client.device;
  158. struct nvkm_gr *gr = nvxx_gr(device);
  159. struct drm_nouveau_getparam *getparam = data;
  160. struct pci_dev *pdev = to_pci_dev(dev->dev);
  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 = 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 = 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(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_HOST_RUNLIST_ENGINES_GR ; break;
  242. case 0x02: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPDEC; break;
  243. case 0x04: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPPP ; break;
  244. case 0x08: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSVLD ; break;
  245. case 0x30: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_CE ; break;
  246. default:
  247. return nouveau_abi16_put(abi16, -ENOSYS);
  248. }
  249. } else {
  250. engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR;
  251. }
  252. if (engine != NV_DEVICE_HOST_RUNLIST_ENGINES_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.resource->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. /* Workaround "nvc0" gallium driver using classes it doesn't allocate on
  289. * Kepler and above. NVKM no longer always sets CE_CTX_VALID as part of
  290. * channel init, now we know what that stuff actually is.
  291. *
  292. * Doesn't matter for Kepler/Pascal, CE context stored in NV_RAMIN.
  293. *
  294. * Userspace was fixed prior to adding Ampere support.
  295. */
  296. switch (device->info.family) {
  297. case NV_DEVICE_INFO_V0_VOLTA:
  298. ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, VOLTA_DMA_COPY_A,
  299. NULL, 0, &chan->ce);
  300. if (ret)
  301. goto done;
  302. break;
  303. case NV_DEVICE_INFO_V0_TURING:
  304. ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, TURING_DMA_COPY_A,
  305. NULL, 0, &chan->ce);
  306. if (ret)
  307. goto done;
  308. break;
  309. default:
  310. break;
  311. }
  312. /* Named memory object area */
  313. ret = nouveau_gem_new(cli, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART,
  314. 0, 0, &chan->ntfy);
  315. if (ret == 0)
  316. ret = nouveau_bo_pin(chan->ntfy, NOUVEAU_GEM_DOMAIN_GART,
  317. false);
  318. if (ret)
  319. goto done;
  320. if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
  321. ret = nouveau_vma_new(chan->ntfy, chan->chan->vmm,
  322. &chan->ntfy_vma);
  323. if (ret)
  324. goto done;
  325. }
  326. ret = drm_gem_handle_create(file_priv, &chan->ntfy->bo.base,
  327. &init->notifier_handle);
  328. if (ret)
  329. goto done;
  330. ret = nvkm_mm_init(&chan->heap, 0, 0, PAGE_SIZE, 1);
  331. done:
  332. if (ret)
  333. nouveau_abi16_chan_fini(abi16, chan);
  334. return nouveau_abi16_put(abi16, ret);
  335. }
  336. static struct nouveau_abi16_chan *
  337. nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
  338. {
  339. struct nouveau_abi16_chan *chan;
  340. list_for_each_entry(chan, &abi16->channels, head) {
  341. if (chan->chan->chid == channel)
  342. return chan;
  343. }
  344. return NULL;
  345. }
  346. int
  347. nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size)
  348. {
  349. union {
  350. struct nvif_ioctl_v0 v0;
  351. } *args = data;
  352. struct nouveau_abi16_chan *chan;
  353. struct nouveau_abi16 *abi16;
  354. int ret = -ENOSYS;
  355. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
  356. switch (args->v0.type) {
  357. case NVIF_IOCTL_V0_NEW:
  358. case NVIF_IOCTL_V0_MTHD:
  359. case NVIF_IOCTL_V0_SCLASS:
  360. break;
  361. default:
  362. return -EACCES;
  363. }
  364. } else
  365. return ret;
  366. if (!(abi16 = nouveau_abi16(file_priv)))
  367. return -ENOMEM;
  368. if (args->v0.token != ~0ULL) {
  369. if (!(chan = nouveau_abi16_chan(abi16, args->v0.token)))
  370. return -EINVAL;
  371. args->v0.object = nvif_handle(&chan->chan->user);
  372. args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
  373. return 0;
  374. }
  375. args->v0.object = nvif_handle(&abi16->device.object);
  376. args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
  377. return 0;
  378. }
  379. int
  380. nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
  381. {
  382. struct drm_nouveau_channel_free *req = data;
  383. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  384. struct nouveau_abi16_chan *chan;
  385. if (unlikely(!abi16))
  386. return -ENOMEM;
  387. chan = nouveau_abi16_chan(abi16, req->channel);
  388. if (!chan)
  389. return nouveau_abi16_put(abi16, -ENOENT);
  390. nouveau_abi16_chan_fini(abi16, chan);
  391. return nouveau_abi16_put(abi16, 0);
  392. }
  393. int
  394. nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
  395. {
  396. struct drm_nouveau_grobj_alloc *init = data;
  397. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  398. struct nouveau_abi16_chan *chan;
  399. struct nouveau_abi16_ntfy *ntfy;
  400. struct nvif_client *client;
  401. struct nvif_sclass *sclass;
  402. s32 oclass = 0;
  403. int ret, i;
  404. if (unlikely(!abi16))
  405. return -ENOMEM;
  406. if (init->handle == ~0)
  407. return nouveau_abi16_put(abi16, -EINVAL);
  408. client = abi16->device.object.client;
  409. chan = nouveau_abi16_chan(abi16, init->channel);
  410. if (!chan)
  411. return nouveau_abi16_put(abi16, -ENOENT);
  412. ret = nvif_object_sclass_get(&chan->chan->user, &sclass);
  413. if (ret < 0)
  414. return nouveau_abi16_put(abi16, ret);
  415. if ((init->class & 0x00ff) == 0x006e) {
  416. /* nvsw: compatibility with older 0x*6e class identifier */
  417. for (i = 0; !oclass && i < ret; i++) {
  418. switch (sclass[i].oclass) {
  419. case NVIF_CLASS_SW_NV04:
  420. case NVIF_CLASS_SW_NV10:
  421. case NVIF_CLASS_SW_NV50:
  422. case NVIF_CLASS_SW_GF100:
  423. oclass = sclass[i].oclass;
  424. break;
  425. default:
  426. break;
  427. }
  428. }
  429. } else
  430. if ((init->class & 0x00ff) == 0x00b1) {
  431. /* msvld: compatibility with incorrect version exposure */
  432. for (i = 0; i < ret; i++) {
  433. if ((sclass[i].oclass & 0x00ff) == 0x00b1) {
  434. oclass = sclass[i].oclass;
  435. break;
  436. }
  437. }
  438. } else
  439. if ((init->class & 0x00ff) == 0x00b2) { /* mspdec */
  440. /* mspdec: compatibility with incorrect version exposure */
  441. for (i = 0; i < ret; i++) {
  442. if ((sclass[i].oclass & 0x00ff) == 0x00b2) {
  443. oclass = sclass[i].oclass;
  444. break;
  445. }
  446. }
  447. } else
  448. if ((init->class & 0x00ff) == 0x00b3) { /* msppp */
  449. /* msppp: compatibility with incorrect version exposure */
  450. for (i = 0; i < ret; i++) {
  451. if ((sclass[i].oclass & 0x00ff) == 0x00b3) {
  452. oclass = sclass[i].oclass;
  453. break;
  454. }
  455. }
  456. } else {
  457. oclass = init->class;
  458. }
  459. nvif_object_sclass_put(&sclass);
  460. if (!oclass)
  461. return nouveau_abi16_put(abi16, -EINVAL);
  462. ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
  463. if (!ntfy)
  464. return nouveau_abi16_put(abi16, -ENOMEM);
  465. list_add(&ntfy->head, &chan->notifiers);
  466. client->route = NVDRM_OBJECT_ABI16;
  467. ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
  468. oclass, NULL, 0, &ntfy->object);
  469. client->route = NVDRM_OBJECT_NVIF;
  470. if (ret)
  471. nouveau_abi16_ntfy_fini(chan, ntfy);
  472. return nouveau_abi16_put(abi16, ret);
  473. }
  474. int
  475. nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
  476. {
  477. struct drm_nouveau_notifierobj_alloc *info = data;
  478. struct nouveau_drm *drm = nouveau_drm(dev);
  479. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  480. struct nouveau_abi16_chan *chan;
  481. struct nouveau_abi16_ntfy *ntfy;
  482. struct nvif_device *device = &abi16->device;
  483. struct nvif_client *client;
  484. struct nv_dma_v0 args = {};
  485. int ret;
  486. if (unlikely(!abi16))
  487. return -ENOMEM;
  488. /* completely unnecessary for these chipsets... */
  489. if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
  490. return nouveau_abi16_put(abi16, -EINVAL);
  491. client = abi16->device.object.client;
  492. chan = nouveau_abi16_chan(abi16, info->channel);
  493. if (!chan)
  494. return nouveau_abi16_put(abi16, -ENOENT);
  495. ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
  496. if (!ntfy)
  497. return nouveau_abi16_put(abi16, -ENOMEM);
  498. list_add(&ntfy->head, &chan->notifiers);
  499. ret = nvkm_mm_head(&chan->heap, 0, 1, info->size, info->size, 1,
  500. &ntfy->node);
  501. if (ret)
  502. goto done;
  503. args.start = ntfy->node->offset;
  504. args.limit = ntfy->node->offset + ntfy->node->length - 1;
  505. if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
  506. args.target = NV_DMA_V0_TARGET_VM;
  507. args.access = NV_DMA_V0_ACCESS_VM;
  508. args.start += chan->ntfy_vma->addr;
  509. args.limit += chan->ntfy_vma->addr;
  510. } else
  511. if (drm->agp.bridge) {
  512. args.target = NV_DMA_V0_TARGET_AGP;
  513. args.access = NV_DMA_V0_ACCESS_RDWR;
  514. args.start += drm->agp.base + chan->ntfy->offset;
  515. args.limit += drm->agp.base + chan->ntfy->offset;
  516. } else {
  517. args.target = NV_DMA_V0_TARGET_VM;
  518. args.access = NV_DMA_V0_ACCESS_RDWR;
  519. args.start += chan->ntfy->offset;
  520. args.limit += chan->ntfy->offset;
  521. }
  522. client->route = NVDRM_OBJECT_ABI16;
  523. ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
  524. NV_DMA_IN_MEMORY, &args, sizeof(args),
  525. &ntfy->object);
  526. client->route = NVDRM_OBJECT_NVIF;
  527. if (ret)
  528. goto done;
  529. info->offset = ntfy->node->offset;
  530. done:
  531. if (ret)
  532. nouveau_abi16_ntfy_fini(chan, ntfy);
  533. return nouveau_abi16_put(abi16, ret);
  534. }
  535. int
  536. nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
  537. {
  538. struct drm_nouveau_gpuobj_free *fini = data;
  539. struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
  540. struct nouveau_abi16_chan *chan;
  541. struct nouveau_abi16_ntfy *ntfy;
  542. int ret = -ENOENT;
  543. if (unlikely(!abi16))
  544. return -ENOMEM;
  545. chan = nouveau_abi16_chan(abi16, fini->channel);
  546. if (!chan)
  547. return nouveau_abi16_put(abi16, -EINVAL);
  548. /* synchronize with the user channel and destroy the gpu object */
  549. nouveau_channel_idle(chan->chan);
  550. list_for_each_entry(ntfy, &chan->notifiers, head) {
  551. if (ntfy->object.handle == fini->handle) {
  552. nouveau_abi16_ntfy_fini(chan, ntfy);
  553. ret = 0;
  554. break;
  555. }
  556. }
  557. return nouveau_abi16_put(abi16, ret);
  558. }