blob: d8b0891a141c66ce6bdfef1de48d57bc7f9a3e9a [file] [log] [blame]
Ben Skeggs2a259a32012-05-08 10:24:27 +10001/*
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
Ben Skeggsa4e610b2014-08-10 04:10:23 +100024#include <nvif/client.h>
25#include <nvif/driver.h>
26#include <nvif/ioctl.h>
Ben Skeggsfdb751e2014-08-10 04:10:23 +100027#include <nvif/class.h>
Ben Skeggs2a259a32012-05-08 10:24:27 +100028
Ben Skeggsebb945a2012-07-20 08:17:34 +100029#include "nouveau_drm.h"
Ben Skeggs2a259a32012-05-08 10:24:27 +100030#include "nouveau_dma.h"
Ben Skeggsebb945a2012-07-20 08:17:34 +100031#include "nouveau_gem.h"
32#include "nouveau_chan.h"
Ben Skeggs2a259a32012-05-08 10:24:27 +100033#include "nouveau_abi16.h"
Ben Skeggsebb945a2012-07-20 08:17:34 +100034
35struct nouveau_abi16 *
36nouveau_abi16_get(struct drm_file *file_priv, struct drm_device *dev)
37{
38 struct nouveau_cli *cli = nouveau_cli(file_priv);
39 mutex_lock(&cli->mutex);
40 if (!cli->abi16) {
41 struct nouveau_abi16 *abi16;
42 cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL);
43 if (cli->abi16) {
Ben Skeggs586491e2014-08-10 04:10:24 +100044 struct nv_device_v0 args = {
45 .device = ~0ULL,
46 };
47
Ben Skeggsebb945a2012-07-20 08:17:34 +100048 INIT_LIST_HEAD(&abi16->channels);
Ben Skeggsebb945a2012-07-20 08:17:34 +100049
50 /* allocate device object targeting client's default
51 * device (ie. the one that belongs to the fd it
52 * opened)
53 */
Ben Skeggs0ad72862014-08-10 04:10:22 +100054 if (nvif_device_init(&cli->base.base, NULL,
Ben Skeggsa4e610b2014-08-10 04:10:23 +100055 NOUVEAU_ABI16_DEVICE, NV_DEVICE,
Ben Skeggs586491e2014-08-10 04:10:24 +100056 &args, sizeof(args),
Ben Skeggs0ad72862014-08-10 04:10:22 +100057 &abi16->device) == 0)
Ben Skeggsebb945a2012-07-20 08:17:34 +100058 return cli->abi16;
59
60 kfree(cli->abi16);
61 cli->abi16 = NULL;
62 }
63
64 mutex_unlock(&cli->mutex);
65 }
66 return cli->abi16;
67}
68
69int
70nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
71{
Ben Skeggs0ad72862014-08-10 04:10:22 +100072 struct nouveau_cli *cli = (void *)nvif_client(&abi16->device.base);
Ben Skeggsebb945a2012-07-20 08:17:34 +100073 mutex_unlock(&cli->mutex);
74 return ret;
75}
76
77u16
78nouveau_abi16_swclass(struct nouveau_drm *drm)
79{
Ben Skeggs967e7bd2014-08-10 04:10:22 +100080 switch (drm->device.info.family) {
81 case NV_DEVICE_INFO_V0_TNT:
Ben Skeggsebb945a2012-07-20 08:17:34 +100082 return 0x006e;
Ben Skeggs967e7bd2014-08-10 04:10:22 +100083 case NV_DEVICE_INFO_V0_CELSIUS:
84 case NV_DEVICE_INFO_V0_KELVIN:
85 case NV_DEVICE_INFO_V0_RANKINE:
86 case NV_DEVICE_INFO_V0_CURIE:
Ben Skeggsebb945a2012-07-20 08:17:34 +100087 return 0x016e;
Ben Skeggs967e7bd2014-08-10 04:10:22 +100088 case NV_DEVICE_INFO_V0_TESLA:
Ben Skeggsebb945a2012-07-20 08:17:34 +100089 return 0x506e;
Ben Skeggs967e7bd2014-08-10 04:10:22 +100090 case NV_DEVICE_INFO_V0_FERMI:
91 case NV_DEVICE_INFO_V0_KEPLER:
92 case NV_DEVICE_INFO_V0_MAXWELL:
Ben Skeggsebb945a2012-07-20 08:17:34 +100093 return 0x906e;
94 }
95
96 return 0x0000;
97}
98
99static void
100nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan,
101 struct nouveau_abi16_ntfy *ntfy)
102{
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000103 nvkm_mm_free(&chan->heap, &ntfy->node);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000104 list_del(&ntfy->head);
105 kfree(ntfy);
106}
107
108static void
109nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
110 struct nouveau_abi16_chan *chan)
111{
112 struct nouveau_abi16_ntfy *ntfy, *temp;
113
Marcin Slusarz2b77c1c2013-03-03 18:58:45 +0100114 /* 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
Ben Skeggsebb945a2012-07-20 08:17:34 +1000119 /* cleanup notifier state */
120 list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) {
121 nouveau_abi16_ntfy_fini(chan, ntfy);
122 }
123
124 if (chan->ntfy) {
125 nouveau_bo_vma_del(chan->ntfy, &chan->ntfy_vma);
Maarten Lankhorst198c14a2013-06-27 13:38:20 +0200126 nouveau_bo_unpin(chan->ntfy);
David Herrmann55fb74a2013-10-02 10:15:17 +0200127 drm_gem_object_unreference_unlocked(&chan->ntfy->gem);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000128 }
129
130 if (chan->heap.block_size)
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000131 nvkm_mm_fini(&chan->heap);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000132
133 /* destroy channel object, all children will be killed too */
134 if (chan->chan) {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000135 abi16->handles &= ~(1ULL << (chan->chan->object->handle & 0xffff));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000136 nouveau_channel_del(&chan->chan);
137 }
138
139 list_del(&chan->head);
140 kfree(chan);
141}
142
143void
144nouveau_abi16_fini(struct nouveau_abi16 *abi16)
145{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000146 struct nouveau_cli *cli = (void *)nvif_client(&abi16->device.base);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000147 struct nouveau_abi16_chan *chan, *temp;
148
149 /* cleanup channels */
150 list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
151 nouveau_abi16_chan_fini(abi16, chan);
152 }
153
154 /* destroy the device object */
Ben Skeggs0ad72862014-08-10 04:10:22 +1000155 nvif_device_fini(&abi16->device);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000156
157 kfree(cli->abi16);
158 cli->abi16 = NULL;
159}
Ben Skeggs2a259a32012-05-08 10:24:27 +1000160
161int
162nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
163{
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000164 struct nouveau_cli *cli = nouveau_cli(file_priv);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000165 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000166 struct nvif_device *device = &drm->device;
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000167 struct nvkm_timer *ptimer = nvxx_timer(device);
168 struct nvkm_gr *gr = nvxx_gr(device);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000169 struct drm_nouveau_getparam *getparam = data;
170
171 switch (getparam->param) {
172 case NOUVEAU_GETPARAM_CHIPSET_ID:
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000173 getparam->value = device->info.chipset;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000174 break;
175 case NOUVEAU_GETPARAM_PCI_VENDOR:
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000176 if (nv_device_is_pci(nvxx_device(device)))
Alexandre Courbot420b9462014-02-17 15:17:26 +0900177 getparam->value = dev->pdev->vendor;
178 else
179 getparam->value = 0;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000180 break;
181 case NOUVEAU_GETPARAM_PCI_DEVICE:
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000182 if (nv_device_is_pci(nvxx_device(device)))
Alexandre Courbot420b9462014-02-17 15:17:26 +0900183 getparam->value = dev->pdev->device;
184 else
185 getparam->value = 0;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000186 break;
187 case NOUVEAU_GETPARAM_BUS_TYPE:
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000188 if (!nv_device_is_pci(nvxx_device(device)))
Alexandre Courbot420b9462014-02-17 15:17:26 +0900189 getparam->value = 3;
190 else
Ben Skeggs2a259a32012-05-08 10:24:27 +1000191 if (drm_pci_device_is_agp(dev))
192 getparam->value = 0;
193 else
194 if (!pci_is_pcie(dev->pdev))
195 getparam->value = 1;
196 else
197 getparam->value = 2;
198 break;
199 case NOUVEAU_GETPARAM_FB_SIZE:
Ben Skeggsebb945a2012-07-20 08:17:34 +1000200 getparam->value = drm->gem.vram_available;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000201 break;
202 case NOUVEAU_GETPARAM_AGP_SIZE:
Ben Skeggsebb945a2012-07-20 08:17:34 +1000203 getparam->value = drm->gem.gart_available;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000204 break;
205 case NOUVEAU_GETPARAM_VM_VRAM_BASE:
206 getparam->value = 0; /* deprecated */
207 break;
208 case NOUVEAU_GETPARAM_PTIMER_TIME:
Ben Skeggsebb945a2012-07-20 08:17:34 +1000209 getparam->value = ptimer->read(ptimer);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000210 break;
211 case NOUVEAU_GETPARAM_HAS_BO_USAGE:
212 getparam->value = 1;
213 break;
214 case NOUVEAU_GETPARAM_HAS_PAGEFLIP:
215 getparam->value = 1;
216 break;
217 case NOUVEAU_GETPARAM_GRAPH_UNITS:
Ben Skeggsb8bf04e2015-01-14 12:02:28 +1000218 getparam->value = gr->units ? gr->units(gr) : 0;
Christoph Bumiller7e22e712013-03-27 22:16:54 +0100219 break;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000220 default:
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000221 NV_PRINTK(debug, cli, "unknown parameter %lld\n", getparam->param);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000222 return -EINVAL;
223 }
224
225 return 0;
226}
227
228int
229nouveau_abi16_ioctl_setparam(ABI16_IOCTL_ARGS)
230{
231 return -EINVAL;
232}
233
234int
235nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
236{
Ben Skeggs2a259a32012-05-08 10:24:27 +1000237 struct drm_nouveau_channel_alloc *init = data;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000238 struct nouveau_cli *cli = nouveau_cli(file_priv);
239 struct nouveau_drm *drm = nouveau_drm(dev);
240 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
241 struct nouveau_abi16_chan *chan;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000242 struct nvif_device *device;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000243 int ret;
244
Ben Skeggsebb945a2012-07-20 08:17:34 +1000245 if (unlikely(!abi16))
246 return -ENOMEM;
Marcin Slusarzbf7e4382012-11-11 20:00:09 +0100247
248 if (!drm->channel)
249 return nouveau_abi16_put(abi16, -ENODEV);
250
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000251 device = &abi16->device;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000252
Ben Skeggs49469802012-11-22 13:43:55 +1000253 /* hack to allow channel engine type specification on kepler */
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000254 if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
Ben Skeggs49469802012-11-22 13:43:55 +1000255 if (init->fb_ctxdma_handle != ~0)
Ben Skeggsbbf89062014-08-10 04:10:25 +1000256 init->fb_ctxdma_handle = KEPLER_CHANNEL_GPFIFO_A_V0_ENGINE_GR;
Ben Skeggs49469802012-11-22 13:43:55 +1000257 else
258 init->fb_ctxdma_handle = init->tt_ctxdma_handle;
259
260 /* allow flips to be executed if this is a graphics channel */
261 init->tt_ctxdma_handle = 0;
Ben Skeggsbbf89062014-08-10 04:10:25 +1000262 if (init->fb_ctxdma_handle == KEPLER_CHANNEL_GPFIFO_A_V0_ENGINE_GR)
Ben Skeggs49469802012-11-22 13:43:55 +1000263 init->tt_ctxdma_handle = 1;
264 }
265
266 if (init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0)
267 return nouveau_abi16_put(abi16, -EINVAL);
268
Ben Skeggsebb945a2012-07-20 08:17:34 +1000269 /* allocate "abi16 channel" data and make up a handle for it */
Ilia Mirkin73970c42014-02-09 15:51:24 -0500270 init->channel = __ffs64(~abi16->handles);
271 if (~abi16->handles == 0)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000272 return nouveau_abi16_put(abi16, -ENOSPC);
273
274 chan = kzalloc(sizeof(*chan), GFP_KERNEL);
275 if (!chan)
276 return nouveau_abi16_put(abi16, -ENOMEM);
277
278 INIT_LIST_HEAD(&chan->notifiers);
279 list_add(&chan->head, &abi16->channels);
Ilia Mirkinef98c1f2014-02-09 15:51:25 -0500280 abi16->handles |= (1ULL << init->channel);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000281
282 /* create channel object and initialise dma and fence management */
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000283 ret = nouveau_channel_new(drm, device,
284 NOUVEAU_ABI16_CHAN(init->channel),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000285 init->fb_ctxdma_handle,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000286 init->tt_ctxdma_handle, &chan->chan);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000287 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000288 goto done;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000289
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000290 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000291 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM |
292 NOUVEAU_GEM_DOMAIN_GART;
293 else
294 if (chan->chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM)
Ben Skeggs2a259a32012-05-08 10:24:27 +1000295 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000296 else
297 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000298
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000299 if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) {
Ben Skeggs2a259a32012-05-08 10:24:27 +1000300 init->subchan[0].handle = 0x00000000;
301 init->subchan[0].grclass = 0x0000;
Ben Skeggsf45f55c42014-08-10 04:10:23 +1000302 init->subchan[1].handle = chan->chan->nvsw.handle;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000303 init->subchan[1].grclass = 0x506e;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000304 init->nr_subchan = 2;
305 }
306
307 /* Named memory object area */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000308 ret = nouveau_gem_new(dev, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART,
309 0, 0, &chan->ntfy);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000310 if (ret == 0)
Ben Skeggsad76b3f2014-11-10 11:24:27 +1000311 ret = nouveau_bo_pin(chan->ntfy, TTM_PL_FLAG_TT, false);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000312 if (ret)
313 goto done;
314
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000315 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000316 ret = nouveau_bo_vma_add(chan->ntfy, cli->vm,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000317 &chan->ntfy_vma);
318 if (ret)
319 goto done;
320 }
321
David Herrmann55fb74a2013-10-02 10:15:17 +0200322 ret = drm_gem_handle_create(file_priv, &chan->ntfy->gem,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000323 &init->notifier_handle);
324 if (ret)
325 goto done;
326
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000327 ret = nvkm_mm_init(&chan->heap, 0, PAGE_SIZE, 1);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000328done:
329 if (ret)
330 nouveau_abi16_chan_fini(abi16, chan);
331 return nouveau_abi16_put(abi16, ret);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000332}
333
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000334static struct nouveau_abi16_chan *
335nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
336{
337 struct nouveau_abi16_chan *chan;
338
339 list_for_each_entry(chan, &abi16->channels, head) {
340 if (chan->chan->object->handle == NOUVEAU_ABI16_CHAN(channel))
341 return chan;
342 }
343
344 return NULL;
345}
Ben Skeggsebb945a2012-07-20 08:17:34 +1000346
Ben Skeggs2a259a32012-05-08 10:24:27 +1000347int
348nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
349{
350 struct drm_nouveau_channel_free *req = data;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000351 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
352 struct nouveau_abi16_chan *chan;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000353
Ben Skeggsebb945a2012-07-20 08:17:34 +1000354 if (unlikely(!abi16))
355 return -ENOMEM;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000356
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000357 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);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000362}
363
364int
365nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
366{
367 struct drm_nouveau_grobj_alloc *init = data;
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000368 struct {
369 struct nvif_ioctl_v0 ioctl;
370 struct nvif_ioctl_new_v0 new;
371 } args = {
372 .ioctl.owner = NVIF_IOCTL_V0_OWNER_ANY,
373 .ioctl.type = NVIF_IOCTL_V0_NEW,
374 .ioctl.path_nr = 3,
375 .ioctl.path[2] = NOUVEAU_ABI16_CLIENT,
376 .ioctl.path[1] = NOUVEAU_ABI16_DEVICE,
377 .ioctl.path[0] = NOUVEAU_ABI16_CHAN(init->channel),
378 .new.route = NVDRM_OBJECT_ABI16,
379 .new.handle = init->handle,
380 .new.oclass = init->class,
381 };
Ben Skeggsebb945a2012-07-20 08:17:34 +1000382 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
383 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000384 struct nvif_client *client;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000385 int ret;
386
Ben Skeggsebb945a2012-07-20 08:17:34 +1000387 if (unlikely(!abi16))
388 return -ENOMEM;
389
Ben Skeggs2a259a32012-05-08 10:24:27 +1000390 if (init->handle == ~0)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000391 return nouveau_abi16_put(abi16, -EINVAL);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000392 client = nvif_client(nvif_object(&abi16->device));
Ben Skeggs2a259a32012-05-08 10:24:27 +1000393
394 /* compatibility with userspace that assumes 506e for all chipsets */
395 if (init->class == 0x506e) {
Ben Skeggsebb945a2012-07-20 08:17:34 +1000396 init->class = nouveau_abi16_swclass(drm);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000397 if (init->class == 0x906e)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000398 return nouveau_abi16_put(abi16, 0);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000399 }
400
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000401 ret = nvif_client_ioctl(client, &args, sizeof(args));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000402 return nouveau_abi16_put(abi16, ret);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000403}
404
405int
406nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
407{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000408 struct drm_nouveau_notifierobj_alloc *info = data;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000409 struct {
410 struct nvif_ioctl_v0 ioctl;
411 struct nvif_ioctl_new_v0 new;
Ben Skeggs4acfd702014-08-10 04:10:24 +1000412 struct nv_dma_v0 ctxdma;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000413 } args = {
414 .ioctl.owner = NVIF_IOCTL_V0_OWNER_ANY,
415 .ioctl.type = NVIF_IOCTL_V0_NEW,
416 .ioctl.path_nr = 3,
417 .ioctl.path[2] = NOUVEAU_ABI16_CLIENT,
418 .ioctl.path[1] = NOUVEAU_ABI16_DEVICE,
419 .ioctl.path[0] = NOUVEAU_ABI16_CHAN(info->channel),
420 .new.route = NVDRM_OBJECT_ABI16,
421 .new.handle = info->handle,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000422 .new.oclass = NV_DMA_IN_MEMORY,
Ben Skeggs3bdda042014-08-10 04:10:23 +1000423 };
Ben Skeggsebb945a2012-07-20 08:17:34 +1000424 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000425 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000426 struct nouveau_abi16_chan *chan;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000427 struct nouveau_abi16_ntfy *ntfy;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000428 struct nvif_device *device = &abi16->device;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000429 struct nvif_client *client;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000430 int ret;
431
Ben Skeggsebb945a2012-07-20 08:17:34 +1000432 if (unlikely(!abi16))
433 return -ENOMEM;
434
Ben Skeggs2a259a32012-05-08 10:24:27 +1000435 /* completely unnecessary for these chipsets... */
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000436 if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
Ben Skeggsebb945a2012-07-20 08:17:34 +1000437 return nouveau_abi16_put(abi16, -EINVAL);
Ben Skeggs3bdda042014-08-10 04:10:23 +1000438 client = nvif_client(nvif_object(&abi16->device));
Ben Skeggs2a259a32012-05-08 10:24:27 +1000439
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000440 chan = nouveau_abi16_chan(abi16, info->channel);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000441 if (!chan)
442 return nouveau_abi16_put(abi16, -ENOENT);
443
444 ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
445 if (!ntfy)
446 return nouveau_abi16_put(abi16, -ENOMEM);
447
448 list_add(&ntfy->head, &chan->notifiers);
449 ntfy->handle = info->handle;
450
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000451 ret = nvkm_mm_head(&chan->heap, 0, 1, info->size, info->size, 1,
452 &ntfy->node);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000453 if (ret)
454 goto done;
455
Ben Skeggs3bdda042014-08-10 04:10:23 +1000456 args.ctxdma.start = ntfy->node->offset;
457 args.ctxdma.limit = ntfy->node->offset + ntfy->node->length - 1;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000458 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
Ben Skeggs4acfd702014-08-10 04:10:24 +1000459 args.ctxdma.target = NV_DMA_V0_TARGET_VM;
460 args.ctxdma.access = NV_DMA_V0_ACCESS_VM;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000461 args.ctxdma.start += chan->ntfy_vma.offset;
462 args.ctxdma.limit += chan->ntfy_vma.offset;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000463 } else
464 if (drm->agp.stat == ENABLED) {
Ben Skeggs4acfd702014-08-10 04:10:24 +1000465 args.ctxdma.target = NV_DMA_V0_TARGET_AGP;
466 args.ctxdma.access = NV_DMA_V0_ACCESS_RDWR;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000467 args.ctxdma.start += drm->agp.base + chan->ntfy->bo.offset;
468 args.ctxdma.limit += drm->agp.base + chan->ntfy->bo.offset;
469 client->super = true;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000470 } else {
Ben Skeggs4acfd702014-08-10 04:10:24 +1000471 args.ctxdma.target = NV_DMA_V0_TARGET_VM;
472 args.ctxdma.access = NV_DMA_V0_ACCESS_RDWR;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000473 args.ctxdma.start += chan->ntfy->bo.offset;
474 args.ctxdma.limit += chan->ntfy->bo.offset;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000475 }
476
Ben Skeggs3bdda042014-08-10 04:10:23 +1000477 ret = nvif_client_ioctl(client, &args, sizeof(args));
478 client->super = false;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000479 if (ret)
480 goto done;
481
Bob Gleitsmannc1ccaa62014-01-06 08:59:07 +1000482 info->offset = ntfy->node->offset;
483
Ben Skeggsebb945a2012-07-20 08:17:34 +1000484done:
485 if (ret)
486 nouveau_abi16_ntfy_fini(chan, ntfy);
487 return nouveau_abi16_put(abi16, ret);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000488}
489
490int
491nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
492{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000493 struct drm_nouveau_gpuobj_free *fini = data;
Ben Skeggsaedf43d2014-08-10 04:10:23 +1000494 struct {
495 struct nvif_ioctl_v0 ioctl;
496 struct nvif_ioctl_del del;
497 } args = {
498 .ioctl.owner = NVDRM_OBJECT_ABI16,
499 .ioctl.type = NVIF_IOCTL_V0_DEL,
500 .ioctl.path_nr = 4,
501 .ioctl.path[3] = NOUVEAU_ABI16_CLIENT,
502 .ioctl.path[2] = NOUVEAU_ABI16_DEVICE,
503 .ioctl.path[1] = NOUVEAU_ABI16_CHAN(fini->channel),
504 .ioctl.path[0] = fini->handle,
505 };
Ben Skeggsebb945a2012-07-20 08:17:34 +1000506 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000507 struct nouveau_abi16_chan *chan;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000508 struct nouveau_abi16_ntfy *ntfy;
Ben Skeggsaedf43d2014-08-10 04:10:23 +1000509 struct nvif_client *client;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000510 int ret;
511
Ben Skeggsebb945a2012-07-20 08:17:34 +1000512 if (unlikely(!abi16))
513 return -ENOMEM;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000514
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000515 chan = nouveau_abi16_chan(abi16, fini->channel);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000516 if (!chan)
517 return nouveau_abi16_put(abi16, -ENOENT);
Ben Skeggsaedf43d2014-08-10 04:10:23 +1000518 client = nvif_client(nvif_object(&abi16->device));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000519
520 /* synchronize with the user channel and destroy the gpu object */
521 nouveau_channel_idle(chan->chan);
522
Ben Skeggsaedf43d2014-08-10 04:10:23 +1000523 ret = nvif_client_ioctl(client, &args, sizeof(args));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000524 if (ret)
525 return nouveau_abi16_put(abi16, ret);
526
527 /* cleanup extra state if this object was a notifier */
528 list_for_each_entry(ntfy, &chan->notifiers, head) {
529 if (ntfy->handle == fini->handle) {
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000530 nvkm_mm_free(&chan->heap, &ntfy->node);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000531 list_del(&ntfy->head);
532 break;
533 }
534 }
535
536 return nouveau_abi16_put(abi16, 0);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000537}