]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - drivers/gpu/drm/nouveau/nouveau_abi16.c
Merge tag 'kvm-x86-mmu-6.7' of https://github.com/kvm-x86/linux into HEAD
[thirdparty/kernel/stable.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>
a7cf0180 26#include <nvif/fifo.h>
a4e610b5 27#include <nvif/ioctl.h>
fdb751ef 28#include <nvif/class.h>
845f2725 29#include <nvif/cl0002.h>
2621a416 30#include <nvif/unpack.h>
2a259a3d 31
4dc28134 32#include "nouveau_drv.h"
2a259a3d 33#include "nouveau_dma.h"
d59e75ee 34#include "nouveau_exec.h"
ebb945a9
BS
35#include "nouveau_gem.h"
36#include "nouveau_chan.h"
2a259a3d 37#include "nouveau_abi16.h"
24e8375b 38#include "nouveau_vmm.h"
b88baab8 39#include "nouveau_sched.h"
ebb945a9 40
786a57ef
BS
41static struct nouveau_abi16 *
42nouveau_abi16(struct drm_file *file_priv)
ebb945a9
BS
43{
44 struct nouveau_cli *cli = nouveau_cli(file_priv);
ebb945a9
BS
45 if (!cli->abi16) {
46 struct nouveau_abi16 *abi16;
47 cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL);
48 if (cli->abi16) {
586491e6
BS
49 struct nv_device_v0 args = {
50 .device = ~0ULL,
51 };
52
ebb945a9 53 INIT_LIST_HEAD(&abi16->channels);
ebb945a9
BS
54
55 /* allocate device object targeting client's default
56 * device (ie. the one that belongs to the fd it
57 * opened)
58 */
bd21080e
BS
59 if (nvif_device_ctor(&cli->base.object, "abi16Device",
60 0, NV_DEVICE, &args, sizeof(args),
0ad72863 61 &abi16->device) == 0)
ebb945a9
BS
62 return cli->abi16;
63
64 kfree(cli->abi16);
65 cli->abi16 = NULL;
66 }
ebb945a9
BS
67 }
68 return cli->abi16;
69}
70
786a57ef
BS
71struct nouveau_abi16 *
72nouveau_abi16_get(struct drm_file *file_priv)
73{
74 struct nouveau_cli *cli = nouveau_cli(file_priv);
75 mutex_lock(&cli->mutex);
76 if (nouveau_abi16(file_priv))
77 return cli->abi16;
78 mutex_unlock(&cli->mutex);
79 return NULL;
80}
81
ebb945a9
BS
82int
83nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
84{
a01ca78c 85 struct nouveau_cli *cli = (void *)abi16->device.object.client;
ebb945a9
BS
86 mutex_unlock(&cli->mutex);
87 return ret;
88}
89
f58ddf95 90s32
ebb945a9
BS
91nouveau_abi16_swclass(struct nouveau_drm *drm)
92{
1167c6bc 93 switch (drm->client.device.info.family) {
967e7bde 94 case NV_DEVICE_INFO_V0_TNT:
08f7633c 95 return NVIF_CLASS_SW_NV04;
967e7bde
BS
96 case NV_DEVICE_INFO_V0_CELSIUS:
97 case NV_DEVICE_INFO_V0_KELVIN:
98 case NV_DEVICE_INFO_V0_RANKINE:
99 case NV_DEVICE_INFO_V0_CURIE:
08f7633c 100 return NVIF_CLASS_SW_NV10;
967e7bde 101 case NV_DEVICE_INFO_V0_TESLA:
08f7633c 102 return NVIF_CLASS_SW_NV50;
967e7bde
BS
103 case NV_DEVICE_INFO_V0_FERMI:
104 case NV_DEVICE_INFO_V0_KEPLER:
105 case NV_DEVICE_INFO_V0_MAXWELL:
7f53abdb 106 case NV_DEVICE_INFO_V0_PASCAL:
c1f856bb 107 case NV_DEVICE_INFO_V0_VOLTA:
08f7633c 108 return NVIF_CLASS_SW_GF100;
ebb945a9
BS
109 }
110
111 return 0x0000;
112}
113
114static void
115nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan,
116 struct nouveau_abi16_ntfy *ntfy)
117{
9ac596a4 118 nvif_object_dtor(&ntfy->object);
be83cd4e 119 nvkm_mm_free(&chan->heap, &ntfy->node);
ebb945a9
BS
120 list_del(&ntfy->head);
121 kfree(ntfy);
122}
123
124static void
125nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
126 struct nouveau_abi16_chan *chan)
127{
128 struct nouveau_abi16_ntfy *ntfy, *temp;
129
b88baab8
DK
130 /* When a client exits without waiting for it's queued up jobs to
131 * finish it might happen that we fault the channel. This is due to
132 * drm_file_free() calling drm_gem_release() before the postclose()
133 * callback. Hence, we can't tear down this scheduler entity before
134 * uvmm mappings are unmapped. Currently, we can't detect this case.
135 *
136 * However, this should be rare and harmless, since the channel isn't
137 * needed anymore.
138 */
139 nouveau_sched_entity_fini(&chan->sched_entity);
140
7ba01b50
BS
141 /* wait for all activity to stop before cleaning up */
142 if (chan->chan)
2b77c1c0
MS
143 nouveau_channel_idle(chan->chan);
144
ebb945a9
BS
145 /* cleanup notifier state */
146 list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) {
147 nouveau_abi16_ntfy_fini(chan, ntfy);
148 }
149
150 if (chan->ntfy) {
24e8375b 151 nouveau_vma_del(&chan->ntfy_vma);
198c14a0 152 nouveau_bo_unpin(chan->ntfy);
cdc194ce 153 drm_gem_object_put(&chan->ntfy->bo.base);
ebb945a9
BS
154 }
155
156 if (chan->heap.block_size)
be83cd4e 157 nvkm_mm_fini(&chan->heap);
ebb945a9
BS
158
159 /* destroy channel object, all children will be killed too */
160 if (chan->chan) {
40184ece 161 nvif_object_dtor(&chan->ce);
ebb945a9
BS
162 nouveau_channel_del(&chan->chan);
163 }
164
165 list_del(&chan->head);
166 kfree(chan);
167}
168
169void
170nouveau_abi16_fini(struct nouveau_abi16 *abi16)
171{
a01ca78c 172 struct nouveau_cli *cli = (void *)abi16->device.object.client;
ebb945a9
BS
173 struct nouveau_abi16_chan *chan, *temp;
174
175 /* cleanup channels */
176 list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
177 nouveau_abi16_chan_fini(abi16, chan);
178 }
179
180 /* destroy the device object */
bd21080e 181 nvif_device_dtor(&abi16->device);
ebb945a9
BS
182
183 kfree(cli->abi16);
184 cli->abi16 = NULL;
185}
2a259a3d 186
d59e75ee
DK
187static inline int
188getparam_dma_ib_max(struct nvif_device *device)
189{
190 const struct nvif_mclass dmas[] = {
191 { NV03_CHANNEL_DMA, 0 },
192 { NV10_CHANNEL_DMA, 0 },
193 { NV17_CHANNEL_DMA, 0 },
194 { NV40_CHANNEL_DMA, 0 },
195 {}
196 };
197
198 return nvif_mclass(&device->object, dmas) < 0 ? NV50_DMA_IB_MAX : 0;
199}
200
2a259a3d
BS
201int
202nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
203{
fa2bade9 204 struct nouveau_cli *cli = nouveau_cli(file_priv);
ebb945a9 205 struct nouveau_drm *drm = nouveau_drm(dev);
1167c6bc 206 struct nvif_device *device = &drm->client.device;
be83cd4e 207 struct nvkm_gr *gr = nvxx_gr(device);
2a259a3d 208 struct drm_nouveau_getparam *getparam = data;
4c0d42f7 209 struct pci_dev *pdev = to_pci_dev(dev->dev);
2a259a3d
BS
210
211 switch (getparam->param) {
212 case NOUVEAU_GETPARAM_CHIPSET_ID:
967e7bde 213 getparam->value = device->info.chipset;
2a259a3d
BS
214 break;
215 case NOUVEAU_GETPARAM_PCI_VENDOR:
359088d5 216 if (device->info.platform != NV_DEVICE_INFO_V0_SOC)
4c0d42f7 217 getparam->value = pdev->vendor;
420b9469
AC
218 else
219 getparam->value = 0;
2a259a3d
BS
220 break;
221 case NOUVEAU_GETPARAM_PCI_DEVICE:
359088d5 222 if (device->info.platform != NV_DEVICE_INFO_V0_SOC)
4c0d42f7 223 getparam->value = pdev->device;
420b9469
AC
224 else
225 getparam->value = 0;
2a259a3d
BS
226 break;
227 case NOUVEAU_GETPARAM_BUS_TYPE:
359088d5
BS
228 switch (device->info.platform) {
229 case NV_DEVICE_INFO_V0_AGP : getparam->value = 0; break;
230 case NV_DEVICE_INFO_V0_PCI : getparam->value = 1; break;
231 case NV_DEVICE_INFO_V0_PCIE: getparam->value = 2; break;
232 case NV_DEVICE_INFO_V0_SOC : getparam->value = 3; break;
233 case NV_DEVICE_INFO_V0_IGP :
4c0d42f7 234 if (!pci_is_pcie(pdev))
359088d5
BS
235 getparam->value = 1;
236 else
237 getparam->value = 2;
238 break;
239 default:
240 WARN_ON(1);
241 break;
242 }
785cf1ee 243 break;
2a259a3d 244 case NOUVEAU_GETPARAM_FB_SIZE:
ebb945a9 245 getparam->value = drm->gem.vram_available;
2a259a3d
BS
246 break;
247 case NOUVEAU_GETPARAM_AGP_SIZE:
ebb945a9 248 getparam->value = drm->gem.gart_available;
2a259a3d
BS
249 break;
250 case NOUVEAU_GETPARAM_VM_VRAM_BASE:
251 getparam->value = 0; /* deprecated */
252 break;
253 case NOUVEAU_GETPARAM_PTIMER_TIME:
56f67dc1 254 getparam->value = nvif_device_time(device);
2a259a3d
BS
255 break;
256 case NOUVEAU_GETPARAM_HAS_BO_USAGE:
257 getparam->value = 1;
258 break;
259 case NOUVEAU_GETPARAM_HAS_PAGEFLIP:
260 getparam->value = 1;
261 break;
262 case NOUVEAU_GETPARAM_GRAPH_UNITS:
c85ee6ca 263 getparam->value = nvkm_gr_units(gr);
7e22e71e 264 break;
d59e75ee
DK
265 case NOUVEAU_GETPARAM_EXEC_PUSH_MAX: {
266 int ib_max = getparam_dma_ib_max(device);
267
268 getparam->value = nouveau_exec_push_max_from_ib_max(ib_max);
269 break;
270 }
2a259a3d 271 default:
9ad97ede 272 NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param);
2a259a3d
BS
273 return -EINVAL;
274 }
275
276 return 0;
277}
278
2a259a3d
BS
279int
280nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
281{
2a259a3d 282 struct drm_nouveau_channel_alloc *init = data;
ebb945a9
BS
283 struct nouveau_cli *cli = nouveau_cli(file_priv);
284 struct nouveau_drm *drm = nouveau_drm(dev);
09433f24 285 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
ebb945a9 286 struct nouveau_abi16_chan *chan;
967e7bde 287 struct nvif_device *device;
6de12538 288 u64 engine, runm;
2a259a3d
BS
289 int ret;
290
ebb945a9
BS
291 if (unlikely(!abi16))
292 return -ENOMEM;
bf7e438b
MS
293
294 if (!drm->channel)
295 return nouveau_abi16_put(abi16, -ENODEV);
296
b88baab8
DK
297 /* If uvmm wasn't initialized until now disable it completely to prevent
298 * userspace from mixing up UAPIs.
299 *
300 * The client lock is already acquired by nouveau_abi16_get().
301 */
302 __nouveau_cli_disable_uvmm_noinit(cli);
303
967e7bde 304 device = &abi16->device;
6de12538 305 engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR;
ebb945a9 306
49469800 307 /* hack to allow channel engine type specification on kepler */
967e7bde 308 if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
a7cf0180
BS
309 if (init->fb_ctxdma_handle == ~0) {
310 switch (init->tt_ctxdma_handle) {
f8fabd31
BS
311 case 0x01: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR ; break;
312 case 0x02: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPDEC; break;
313 case 0x04: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPPP ; break;
314 case 0x08: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSVLD ; break;
315 case 0x30: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_CE ; break;
a7cf0180
BS
316 default:
317 return nouveau_abi16_put(abi16, -ENOSYS);
318 }
49469800 319
6de12538
BS
320 init->fb_ctxdma_handle = 0;
321 init->tt_ctxdma_handle = 0;
322 }
49469800
BS
323 }
324
6de12538
BS
325 if (engine != NV_DEVICE_HOST_RUNLIST_ENGINES_CE)
326 runm = nvif_fifo_runlist(device, engine);
327 else
328 runm = nvif_fifo_runlist_ce(device);
329
330 if (!runm || init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0)
49469800
BS
331 return nouveau_abi16_put(abi16, -EINVAL);
332
ebb945a9 333 /* allocate "abi16 channel" data and make up a handle for it */
ebb945a9
BS
334 chan = kzalloc(sizeof(*chan), GFP_KERNEL);
335 if (!chan)
336 return nouveau_abi16_put(abi16, -ENOMEM);
337
338 INIT_LIST_HEAD(&chan->notifiers);
339 list_add(&chan->head, &abi16->channels);
2a259a3d 340
ebb945a9 341 /* create channel object and initialise dma and fence management */
6de12538
BS
342 ret = nouveau_channel_new(drm, device, false, runm, init->fb_ctxdma_handle,
343 init->tt_ctxdma_handle, &chan->chan);
2a259a3d 344 if (ret)
ebb945a9
BS
345 goto done;
346
b88baab8
DK
347 ret = nouveau_sched_entity_init(&chan->sched_entity, &drm->sched,
348 drm->sched_wq);
349 if (ret)
350 goto done;
351
fcf3f91c
BS
352 init->channel = chan->chan->chid;
353
967e7bde 354 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA)
ebb945a9
BS
355 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM |
356 NOUVEAU_GEM_DOMAIN_GART;
357 else
d3116756 358 if (chan->chan->push.buffer->bo.resource->mem_type == TTM_PL_VRAM)
2a259a3d 359 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM;
ebb945a9
BS
360 else
361 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART;
2a259a3d 362
967e7bde 363 if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) {
2a259a3d
BS
364 init->subchan[0].handle = 0x00000000;
365 init->subchan[0].grclass = 0x0000;
f45f55c4 366 init->subchan[1].handle = chan->chan->nvsw.handle;
ebb945a9 367 init->subchan[1].grclass = 0x506e;
2a259a3d
BS
368 init->nr_subchan = 2;
369 }
370
40184ece
BS
371 /* Workaround "nvc0" gallium driver using classes it doesn't allocate on
372 * Kepler and above. NVKM no longer always sets CE_CTX_VALID as part of
373 * channel init, now we know what that stuff actually is.
374 *
375 * Doesn't matter for Kepler/Pascal, CE context stored in NV_RAMIN.
376 *
377 * Userspace was fixed prior to adding Ampere support.
378 */
379 switch (device->info.family) {
380 case NV_DEVICE_INFO_V0_VOLTA:
381 ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, VOLTA_DMA_COPY_A,
382 NULL, 0, &chan->ce);
383 if (ret)
384 goto done;
385 break;
386 case NV_DEVICE_INFO_V0_TURING:
387 ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, TURING_DMA_COPY_A,
388 NULL, 0, &chan->ce);
389 if (ret)
390 goto done;
391 break;
392 default:
393 break;
394 }
395
2a259a3d 396 /* Named memory object area */
fc1b0a02 397 ret = nouveau_gem_new(cli, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART,
ebb945a9
BS
398 0, 0, &chan->ntfy);
399 if (ret == 0)
81b61579
CK
400 ret = nouveau_bo_pin(chan->ntfy, NOUVEAU_GEM_DOMAIN_GART,
401 false);
ebb945a9
BS
402 if (ret)
403 goto done;
404
967e7bde 405 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
bfe91afa
BS
406 ret = nouveau_vma_new(chan->ntfy, chan->chan->vmm,
407 &chan->ntfy_vma);
ebb945a9
BS
408 if (ret)
409 goto done;
410 }
411
f8659be8 412 ret = drm_gem_handle_create(file_priv, &chan->ntfy->bo.base,
2a259a3d 413 &init->notifier_handle);
ebb945a9
BS
414 if (ret)
415 goto done;
2a259a3d 416
4d058fab 417 ret = nvkm_mm_init(&chan->heap, 0, 0, PAGE_SIZE, 1);
ebb945a9
BS
418done:
419 if (ret)
420 nouveau_abi16_chan_fini(abi16, chan);
421 return nouveau_abi16_put(abi16, ret);
2a259a3d
BS
422}
423
a4e610b5
BS
424static struct nouveau_abi16_chan *
425nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
426{
427 struct nouveau_abi16_chan *chan;
428
429 list_for_each_entry(chan, &abi16->channels, head) {
fcf3f91c 430 if (chan->chan->chid == channel)
a4e610b5
BS
431 return chan;
432 }
433
434 return NULL;
435}
ebb945a9 436
2621a416
BS
437int
438nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size)
439{
440 union {
441 struct nvif_ioctl_v0 v0;
442 } *args = data;
443 struct nouveau_abi16_chan *chan;
444 struct nouveau_abi16 *abi16;
f01c4e68 445 int ret = -ENOSYS;
2621a416 446
f01c4e68 447 if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
2621a416
BS
448 switch (args->v0.type) {
449 case NVIF_IOCTL_V0_NEW:
450 case NVIF_IOCTL_V0_MTHD:
451 case NVIF_IOCTL_V0_SCLASS:
452 break;
453 default:
454 return -EACCES;
455 }
456 } else
457 return ret;
458
459 if (!(abi16 = nouveau_abi16(file_priv)))
460 return -ENOMEM;
461
462 if (args->v0.token != ~0ULL) {
463 if (!(chan = nouveau_abi16_chan(abi16, args->v0.token)))
464 return -EINVAL;
465 args->v0.object = nvif_handle(&chan->chan->user);
466 args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
467 return 0;
468 }
469
470 args->v0.object = nvif_handle(&abi16->device.object);
471 args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
472 return 0;
473}
474
2a259a3d
BS
475int
476nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
477{
478 struct drm_nouveau_channel_free *req = data;
09433f24 479 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
ebb945a9 480 struct nouveau_abi16_chan *chan;
2a259a3d 481
ebb945a9
BS
482 if (unlikely(!abi16))
483 return -ENOMEM;
2a259a3d 484
a4e610b5
BS
485 chan = nouveau_abi16_chan(abi16, req->channel);
486 if (!chan)
487 return nouveau_abi16_put(abi16, -ENOENT);
488 nouveau_abi16_chan_fini(abi16, chan);
489 return nouveau_abi16_put(abi16, 0);
2a259a3d
BS
490}
491
492int
493nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
494{
495 struct drm_nouveau_grobj_alloc *init = data;
09433f24 496 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
a01ca78c
BS
497 struct nouveau_abi16_chan *chan;
498 struct nouveau_abi16_ntfy *ntfy;
a4e610b5 499 struct nvif_client *client;
41a63406 500 struct nvif_sclass *sclass;
f58ddf95
BS
501 s32 oclass = 0;
502 int ret, i;
2a259a3d 503
ebb945a9
BS
504 if (unlikely(!abi16))
505 return -ENOMEM;
506
2a259a3d 507 if (init->handle == ~0)
ebb945a9 508 return nouveau_abi16_put(abi16, -EINVAL);
a01ca78c 509 client = abi16->device.object.client;
2a259a3d 510
a01ca78c
BS
511 chan = nouveau_abi16_chan(abi16, init->channel);
512 if (!chan)
513 return nouveau_abi16_put(abi16, -ENOENT);
514
41a63406 515 ret = nvif_object_sclass_get(&chan->chan->user, &sclass);
f58ddf95
BS
516 if (ret < 0)
517 return nouveau_abi16_put(abi16, ret);
518
519 if ((init->class & 0x00ff) == 0x006e) {
520 /* nvsw: compatibility with older 0x*6e class identifier */
521 for (i = 0; !oclass && i < ret; i++) {
41a63406 522 switch (sclass[i].oclass) {
08f7633c
BS
523 case NVIF_CLASS_SW_NV04:
524 case NVIF_CLASS_SW_NV10:
525 case NVIF_CLASS_SW_NV50:
526 case NVIF_CLASS_SW_GF100:
41a63406 527 oclass = sclass[i].oclass;
f58ddf95
BS
528 break;
529 default:
530 break;
531 }
532 }
533 } else
534 if ((init->class & 0x00ff) == 0x00b1) {
535 /* msvld: compatibility with incorrect version exposure */
536 for (i = 0; i < ret; i++) {
41a63406
BS
537 if ((sclass[i].oclass & 0x00ff) == 0x00b1) {
538 oclass = sclass[i].oclass;
f58ddf95
BS
539 break;
540 }
541 }
542 } else
543 if ((init->class & 0x00ff) == 0x00b2) { /* mspdec */
544 /* mspdec: compatibility with incorrect version exposure */
545 for (i = 0; i < ret; i++) {
41a63406
BS
546 if ((sclass[i].oclass & 0x00ff) == 0x00b2) {
547 oclass = sclass[i].oclass;
f58ddf95
BS
548 break;
549 }
550 }
551 } else
552 if ((init->class & 0x00ff) == 0x00b3) { /* msppp */
553 /* msppp: compatibility with incorrect version exposure */
554 for (i = 0; i < ret; i++) {
41a63406
BS
555 if ((sclass[i].oclass & 0x00ff) == 0x00b3) {
556 oclass = sclass[i].oclass;
f58ddf95
BS
557 break;
558 }
559 }
560 } else {
561 oclass = init->class;
562 }
563
41a63406 564 nvif_object_sclass_put(&sclass);
f58ddf95
BS
565 if (!oclass)
566 return nouveau_abi16_put(abi16, -EINVAL);
567
a01ca78c
BS
568 ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
569 if (!ntfy)
570 return nouveau_abi16_put(abi16, -ENOMEM);
571
572 list_add(&ntfy->head, &chan->notifiers);
573
574 client->route = NVDRM_OBJECT_ABI16;
9ac596a4
BS
575 ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
576 oclass, NULL, 0, &ntfy->object);
a01ca78c
BS
577 client->route = NVDRM_OBJECT_NVIF;
578
579 if (ret)
580 nouveau_abi16_ntfy_fini(chan, ntfy);
ebb945a9 581 return nouveau_abi16_put(abi16, ret);
2a259a3d
BS
582}
583
584int
585nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
586{
ebb945a9
BS
587 struct drm_nouveau_notifierobj_alloc *info = data;
588 struct nouveau_drm *drm = nouveau_drm(dev);
09433f24 589 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
a4e610b5 590 struct nouveau_abi16_chan *chan;
ebb945a9 591 struct nouveau_abi16_ntfy *ntfy;
967e7bde 592 struct nvif_device *device = &abi16->device;
3bdda04f 593 struct nvif_client *client;
a01ca78c 594 struct nv_dma_v0 args = {};
2a259a3d
BS
595 int ret;
596
ebb945a9
BS
597 if (unlikely(!abi16))
598 return -ENOMEM;
599
2a259a3d 600 /* completely unnecessary for these chipsets... */
967e7bde 601 if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
ebb945a9 602 return nouveau_abi16_put(abi16, -EINVAL);
a01ca78c 603 client = abi16->device.object.client;
2a259a3d 604
a4e610b5 605 chan = nouveau_abi16_chan(abi16, info->channel);
ebb945a9
BS
606 if (!chan)
607 return nouveau_abi16_put(abi16, -ENOENT);
608
609 ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
610 if (!ntfy)
611 return nouveau_abi16_put(abi16, -ENOMEM);
612
613 list_add(&ntfy->head, &chan->notifiers);
ebb945a9 614
be83cd4e
BS
615 ret = nvkm_mm_head(&chan->heap, 0, 1, info->size, info->size, 1,
616 &ntfy->node);
ebb945a9
BS
617 if (ret)
618 goto done;
619
a01ca78c
BS
620 args.start = ntfy->node->offset;
621 args.limit = ntfy->node->offset + ntfy->node->length - 1;
967e7bde 622 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
a01ca78c
BS
623 args.target = NV_DMA_V0_TARGET_VM;
624 args.access = NV_DMA_V0_ACCESS_VM;
24e8375b
BS
625 args.start += chan->ntfy_vma->addr;
626 args.limit += chan->ntfy_vma->addr;
ebb945a9 627 } else
340b0e7c 628 if (drm->agp.bridge) {
a01ca78c
BS
629 args.target = NV_DMA_V0_TARGET_AGP;
630 args.access = NV_DMA_V0_ACCESS_RDWR;
0dc9b286
ND
631 args.start += drm->agp.base + chan->ntfy->offset;
632 args.limit += drm->agp.base + chan->ntfy->offset;
ebb945a9 633 } else {
a01ca78c
BS
634 args.target = NV_DMA_V0_TARGET_VM;
635 args.access = NV_DMA_V0_ACCESS_RDWR;
0dc9b286
ND
636 args.start += chan->ntfy->offset;
637 args.limit += chan->ntfy->offset;
ebb945a9
BS
638 }
639
a01ca78c 640 client->route = NVDRM_OBJECT_ABI16;
9ac596a4 641 ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
a01ca78c
BS
642 NV_DMA_IN_MEMORY, &args, sizeof(args),
643 &ntfy->object);
a01ca78c 644 client->route = NVDRM_OBJECT_NVIF;
ebb945a9
BS
645 if (ret)
646 goto done;
647
c1ccaa64 648 info->offset = ntfy->node->offset;
ebb945a9
BS
649done:
650 if (ret)
651 nouveau_abi16_ntfy_fini(chan, ntfy);
652 return nouveau_abi16_put(abi16, ret);
2a259a3d
BS
653}
654
655int
656nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
657{
ebb945a9 658 struct drm_nouveau_gpuobj_free *fini = data;
09433f24 659 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
a4e610b5 660 struct nouveau_abi16_chan *chan;
ebb945a9 661 struct nouveau_abi16_ntfy *ntfy;
a01ca78c 662 int ret = -ENOENT;
2a259a3d 663
ebb945a9
BS
664 if (unlikely(!abi16))
665 return -ENOMEM;
666
a4e610b5 667 chan = nouveau_abi16_chan(abi16, fini->channel);
ebb945a9 668 if (!chan)
a01ca78c 669 return nouveau_abi16_put(abi16, -EINVAL);
2a259a3d 670
ebb945a9
BS
671 /* synchronize with the user channel and destroy the gpu object */
672 nouveau_channel_idle(chan->chan);
2a259a3d 673
ebb945a9 674 list_for_each_entry(ntfy, &chan->notifiers, head) {
a01ca78c
BS
675 if (ntfy->object.handle == fini->handle) {
676 nouveau_abi16_ntfy_fini(chan, ntfy);
677 ret = 0;
ebb945a9
BS
678 break;
679 }
680 }
681
a01ca78c 682 return nouveau_abi16_put(abi16, ret);
2a259a3d 683}