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