blob: 9ddc624d264915179bf1276b1a633a6a9b2c4859 [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) {
44 INIT_LIST_HEAD(&abi16->channels);
Ben Skeggsebb945a2012-07-20 08:17:34 +100045
46 /* allocate device object targeting client's default
47 * device (ie. the one that belongs to the fd it
48 * opened)
49 */
Ben Skeggs0ad72862014-08-10 04:10:22 +100050 if (nvif_device_init(&cli->base.base, NULL,
Ben Skeggsa4e610b2014-08-10 04:10:23 +100051 NOUVEAU_ABI16_DEVICE, NV_DEVICE,
Ben Skeggs0ad72862014-08-10 04:10:22 +100052 &(struct nv_device_class) {
Ben Skeggsebb945a2012-07-20 08:17:34 +100053 .device = ~0ULL,
Ben Skeggs0ad72862014-08-10 04:10:22 +100054 }, sizeof(struct nv_device_class),
55 &abi16->device) == 0)
Ben Skeggsebb945a2012-07-20 08:17:34 +100056 return cli->abi16;
57
58 kfree(cli->abi16);
59 cli->abi16 = NULL;
60 }
61
62 mutex_unlock(&cli->mutex);
63 }
64 return cli->abi16;
65}
66
67int
68nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
69{
Ben Skeggs0ad72862014-08-10 04:10:22 +100070 struct nouveau_cli *cli = (void *)nvif_client(&abi16->device.base);
Ben Skeggsebb945a2012-07-20 08:17:34 +100071 mutex_unlock(&cli->mutex);
72 return ret;
73}
74
75u16
76nouveau_abi16_swclass(struct nouveau_drm *drm)
77{
Ben Skeggs967e7bd2014-08-10 04:10:22 +100078 switch (drm->device.info.family) {
79 case NV_DEVICE_INFO_V0_TNT:
Ben Skeggsebb945a2012-07-20 08:17:34 +100080 return 0x006e;
Ben Skeggs967e7bd2014-08-10 04:10:22 +100081 case NV_DEVICE_INFO_V0_CELSIUS:
82 case NV_DEVICE_INFO_V0_KELVIN:
83 case NV_DEVICE_INFO_V0_RANKINE:
84 case NV_DEVICE_INFO_V0_CURIE:
Ben Skeggsebb945a2012-07-20 08:17:34 +100085 return 0x016e;
Ben Skeggs967e7bd2014-08-10 04:10:22 +100086 case NV_DEVICE_INFO_V0_TESLA:
Ben Skeggsebb945a2012-07-20 08:17:34 +100087 return 0x506e;
Ben Skeggs967e7bd2014-08-10 04:10:22 +100088 case NV_DEVICE_INFO_V0_FERMI:
89 case NV_DEVICE_INFO_V0_KEPLER:
90 case NV_DEVICE_INFO_V0_MAXWELL:
Ben Skeggsebb945a2012-07-20 08:17:34 +100091 return 0x906e;
92 }
93
94 return 0x0000;
95}
96
97static void
98nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan,
99 struct nouveau_abi16_ntfy *ntfy)
100{
101 nouveau_mm_free(&chan->heap, &ntfy->node);
102 list_del(&ntfy->head);
103 kfree(ntfy);
104}
105
106static void
107nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
108 struct nouveau_abi16_chan *chan)
109{
110 struct nouveau_abi16_ntfy *ntfy, *temp;
111
Marcin Slusarz2b77c1c2013-03-03 18:58:45 +0100112 /* wait for all activity to stop before releasing notify object, which
113 * may be still in use */
114 if (chan->chan && chan->ntfy)
115 nouveau_channel_idle(chan->chan);
116
Ben Skeggsebb945a2012-07-20 08:17:34 +1000117 /* cleanup notifier state */
118 list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) {
119 nouveau_abi16_ntfy_fini(chan, ntfy);
120 }
121
122 if (chan->ntfy) {
123 nouveau_bo_vma_del(chan->ntfy, &chan->ntfy_vma);
Maarten Lankhorst198c14a2013-06-27 13:38:20 +0200124 nouveau_bo_unpin(chan->ntfy);
David Herrmann55fb74a2013-10-02 10:15:17 +0200125 drm_gem_object_unreference_unlocked(&chan->ntfy->gem);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000126 }
127
128 if (chan->heap.block_size)
129 nouveau_mm_fini(&chan->heap);
130
131 /* destroy channel object, all children will be killed too */
132 if (chan->chan) {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000133 abi16->handles &= ~(1ULL << (chan->chan->object->handle & 0xffff));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000134 nouveau_channel_del(&chan->chan);
135 }
136
137 list_del(&chan->head);
138 kfree(chan);
139}
140
141void
142nouveau_abi16_fini(struct nouveau_abi16 *abi16)
143{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000144 struct nouveau_cli *cli = (void *)nvif_client(&abi16->device.base);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000145 struct nouveau_abi16_chan *chan, *temp;
146
147 /* cleanup channels */
148 list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
149 nouveau_abi16_chan_fini(abi16, chan);
150 }
151
152 /* destroy the device object */
Ben Skeggs0ad72862014-08-10 04:10:22 +1000153 nvif_device_fini(&abi16->device);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000154
155 kfree(cli->abi16);
156 cli->abi16 = NULL;
157}
Ben Skeggs2a259a32012-05-08 10:24:27 +1000158
159int
160nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
161{
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000162 struct nouveau_cli *cli = nouveau_cli(file_priv);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000163 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000164 struct nvif_device *device = &drm->device;
165 struct nouveau_timer *ptimer = nvkm_timer(device);
166 struct nouveau_graph *graph = nvkm_gr(device);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000167 struct drm_nouveau_getparam *getparam = data;
168
169 switch (getparam->param) {
170 case NOUVEAU_GETPARAM_CHIPSET_ID:
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000171 getparam->value = device->info.chipset;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000172 break;
173 case NOUVEAU_GETPARAM_PCI_VENDOR:
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000174 if (nv_device_is_pci(nvkm_device(device)))
Alexandre Courbot420b9462014-02-17 15:17:26 +0900175 getparam->value = dev->pdev->vendor;
176 else
177 getparam->value = 0;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000178 break;
179 case NOUVEAU_GETPARAM_PCI_DEVICE:
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000180 if (nv_device_is_pci(nvkm_device(device)))
Alexandre Courbot420b9462014-02-17 15:17:26 +0900181 getparam->value = dev->pdev->device;
182 else
183 getparam->value = 0;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000184 break;
185 case NOUVEAU_GETPARAM_BUS_TYPE:
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000186 if (!nv_device_is_pci(nvkm_device(device)))
Alexandre Courbot420b9462014-02-17 15:17:26 +0900187 getparam->value = 3;
188 else
Ben Skeggs2a259a32012-05-08 10:24:27 +1000189 if (drm_pci_device_is_agp(dev))
190 getparam->value = 0;
191 else
192 if (!pci_is_pcie(dev->pdev))
193 getparam->value = 1;
194 else
195 getparam->value = 2;
196 break;
197 case NOUVEAU_GETPARAM_FB_SIZE:
Ben Skeggsebb945a2012-07-20 08:17:34 +1000198 getparam->value = drm->gem.vram_available;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000199 break;
200 case NOUVEAU_GETPARAM_AGP_SIZE:
Ben Skeggsebb945a2012-07-20 08:17:34 +1000201 getparam->value = drm->gem.gart_available;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000202 break;
203 case NOUVEAU_GETPARAM_VM_VRAM_BASE:
204 getparam->value = 0; /* deprecated */
205 break;
206 case NOUVEAU_GETPARAM_PTIMER_TIME:
Ben Skeggsebb945a2012-07-20 08:17:34 +1000207 getparam->value = ptimer->read(ptimer);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000208 break;
209 case NOUVEAU_GETPARAM_HAS_BO_USAGE:
210 getparam->value = 1;
211 break;
212 case NOUVEAU_GETPARAM_HAS_PAGEFLIP:
213 getparam->value = 1;
214 break;
215 case NOUVEAU_GETPARAM_GRAPH_UNITS:
Christoph Bumiller7e22e712013-03-27 22:16:54 +0100216 getparam->value = graph->units ? graph->units(graph) : 0;
217 break;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000218 default:
Ben Skeggsfa2bade2014-08-10 04:10:22 +1000219 NV_PRINTK(debug, cli, "unknown parameter %lld\n", getparam->param);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000220 return -EINVAL;
221 }
222
223 return 0;
224}
225
226int
227nouveau_abi16_ioctl_setparam(ABI16_IOCTL_ARGS)
228{
229 return -EINVAL;
230}
231
232int
233nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
234{
Ben Skeggs2a259a32012-05-08 10:24:27 +1000235 struct drm_nouveau_channel_alloc *init = data;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000236 struct nouveau_cli *cli = nouveau_cli(file_priv);
237 struct nouveau_drm *drm = nouveau_drm(dev);
238 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
239 struct nouveau_abi16_chan *chan;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000240 struct nvif_device *device;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000241 struct nouveau_instmem *imem;
242 struct nouveau_fb *pfb;
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;
252 imem = nvkm_instmem(device);
253 pfb = nvkm_fb(device);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000254
Ben Skeggs49469802012-11-22 13:43:55 +1000255 /* hack to allow channel engine type specification on kepler */
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000256 if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
Ben Skeggs49469802012-11-22 13:43:55 +1000257 if (init->fb_ctxdma_handle != ~0)
258 init->fb_ctxdma_handle = NVE0_CHANNEL_IND_ENGINE_GR;
259 else
260 init->fb_ctxdma_handle = init->tt_ctxdma_handle;
261
262 /* allow flips to be executed if this is a graphics channel */
263 init->tt_ctxdma_handle = 0;
264 if (init->fb_ctxdma_handle == NVE0_CHANNEL_IND_ENGINE_GR)
265 init->tt_ctxdma_handle = 1;
266 }
267
268 if (init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0)
269 return nouveau_abi16_put(abi16, -EINVAL);
270
Ben Skeggsebb945a2012-07-20 08:17:34 +1000271 /* allocate "abi16 channel" data and make up a handle for it */
Ilia Mirkin73970c42014-02-09 15:51:24 -0500272 init->channel = __ffs64(~abi16->handles);
273 if (~abi16->handles == 0)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000274 return nouveau_abi16_put(abi16, -ENOSPC);
275
276 chan = kzalloc(sizeof(*chan), GFP_KERNEL);
277 if (!chan)
278 return nouveau_abi16_put(abi16, -ENOMEM);
279
280 INIT_LIST_HEAD(&chan->notifiers);
281 list_add(&chan->head, &abi16->channels);
Ilia Mirkinef98c1f2014-02-09 15:51:25 -0500282 abi16->handles |= (1ULL << init->channel);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000283
284 /* create channel object and initialise dma and fence management */
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000285 ret = nouveau_channel_new(drm, device,
286 NOUVEAU_ABI16_CHAN(init->channel),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000287 init->fb_ctxdma_handle,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000288 init->tt_ctxdma_handle, &chan->chan);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000289 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000290 goto done;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000291
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000292 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000293 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM |
294 NOUVEAU_GEM_DOMAIN_GART;
295 else
296 if (chan->chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM)
Ben Skeggs2a259a32012-05-08 10:24:27 +1000297 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000298 else
299 init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000300
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000301 if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) {
Ben Skeggs2a259a32012-05-08 10:24:27 +1000302 init->subchan[0].handle = 0x00000000;
303 init->subchan[0].grclass = 0x0000;
Ben Skeggsf45f55c42014-08-10 04:10:23 +1000304 init->subchan[1].handle = chan->chan->nvsw.handle;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000305 init->subchan[1].grclass = 0x506e;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000306 init->nr_subchan = 2;
307 }
308
309 /* Named memory object area */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000310 ret = nouveau_gem_new(dev, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART,
311 0, 0, &chan->ntfy);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000312 if (ret == 0)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000313 ret = nouveau_bo_pin(chan->ntfy, TTM_PL_FLAG_TT);
314 if (ret)
315 goto done;
316
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000317 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000318 ret = nouveau_bo_vma_add(chan->ntfy, cli->vm,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000319 &chan->ntfy_vma);
320 if (ret)
321 goto done;
322 }
323
David Herrmann55fb74a2013-10-02 10:15:17 +0200324 ret = drm_gem_handle_create(file_priv, &chan->ntfy->gem,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000325 &init->notifier_handle);
326 if (ret)
327 goto done;
328
329 ret = nouveau_mm_init(&chan->heap, 0, PAGE_SIZE, 1);
330done:
331 if (ret)
332 nouveau_abi16_chan_fini(abi16, chan);
333 return nouveau_abi16_put(abi16, ret);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000334}
335
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000336static struct nouveau_abi16_chan *
337nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
338{
339 struct nouveau_abi16_chan *chan;
340
341 list_for_each_entry(chan, &abi16->channels, head) {
342 if (chan->chan->object->handle == NOUVEAU_ABI16_CHAN(channel))
343 return chan;
344 }
345
346 return NULL;
347}
Ben Skeggsebb945a2012-07-20 08:17:34 +1000348
Ben Skeggs2a259a32012-05-08 10:24:27 +1000349int
350nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
351{
352 struct drm_nouveau_channel_free *req = data;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000353 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
354 struct nouveau_abi16_chan *chan;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000355
Ben Skeggsebb945a2012-07-20 08:17:34 +1000356 if (unlikely(!abi16))
357 return -ENOMEM;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000358
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000359 chan = nouveau_abi16_chan(abi16, req->channel);
360 if (!chan)
361 return nouveau_abi16_put(abi16, -ENOENT);
362 nouveau_abi16_chan_fini(abi16, chan);
363 return nouveau_abi16_put(abi16, 0);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000364}
365
366int
367nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
368{
369 struct drm_nouveau_grobj_alloc *init = data;
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000370 struct {
371 struct nvif_ioctl_v0 ioctl;
372 struct nvif_ioctl_new_v0 new;
373 } args = {
374 .ioctl.owner = NVIF_IOCTL_V0_OWNER_ANY,
375 .ioctl.type = NVIF_IOCTL_V0_NEW,
376 .ioctl.path_nr = 3,
377 .ioctl.path[2] = NOUVEAU_ABI16_CLIENT,
378 .ioctl.path[1] = NOUVEAU_ABI16_DEVICE,
379 .ioctl.path[0] = NOUVEAU_ABI16_CHAN(init->channel),
380 .new.route = NVDRM_OBJECT_ABI16,
381 .new.handle = init->handle,
382 .new.oclass = init->class,
383 };
Ben Skeggsebb945a2012-07-20 08:17:34 +1000384 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
385 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000386 struct nvif_client *client;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000387 int ret;
388
Ben Skeggsebb945a2012-07-20 08:17:34 +1000389 if (unlikely(!abi16))
390 return -ENOMEM;
391
Ben Skeggs2a259a32012-05-08 10:24:27 +1000392 if (init->handle == ~0)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000393 return nouveau_abi16_put(abi16, -EINVAL);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000394 client = nvif_client(nvif_object(&abi16->device));
Ben Skeggs2a259a32012-05-08 10:24:27 +1000395
396 /* compatibility with userspace that assumes 506e for all chipsets */
397 if (init->class == 0x506e) {
Ben Skeggsebb945a2012-07-20 08:17:34 +1000398 init->class = nouveau_abi16_swclass(drm);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000399 if (init->class == 0x906e)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000400 return nouveau_abi16_put(abi16, 0);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000401 }
402
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000403 ret = nvif_client_ioctl(client, &args, sizeof(args));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000404 return nouveau_abi16_put(abi16, ret);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000405}
406
407int
408nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
409{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000410 struct drm_nouveau_notifierobj_alloc *info = data;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000411 struct {
412 struct nvif_ioctl_v0 ioctl;
413 struct nvif_ioctl_new_v0 new;
414 struct nv_dma_class ctxdma;
415 } args = {
416 .ioctl.owner = NVIF_IOCTL_V0_OWNER_ANY,
417 .ioctl.type = NVIF_IOCTL_V0_NEW,
418 .ioctl.path_nr = 3,
419 .ioctl.path[2] = NOUVEAU_ABI16_CLIENT,
420 .ioctl.path[1] = NOUVEAU_ABI16_DEVICE,
421 .ioctl.path[0] = NOUVEAU_ABI16_CHAN(info->channel),
422 .new.route = NVDRM_OBJECT_ABI16,
423 .new.handle = info->handle,
424 .new.oclass = NV_DMA_IN_MEMORY_CLASS,
425 };
Ben Skeggsebb945a2012-07-20 08:17:34 +1000426 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000427 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000428 struct nouveau_abi16_chan *chan;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000429 struct nouveau_abi16_ntfy *ntfy;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000430 struct nvif_device *device = &abi16->device;
Ben Skeggs3bdda042014-08-10 04:10:23 +1000431 struct nvif_client *client;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000432 int ret;
433
Ben Skeggsebb945a2012-07-20 08:17:34 +1000434 if (unlikely(!abi16))
435 return -ENOMEM;
436
Ben Skeggs2a259a32012-05-08 10:24:27 +1000437 /* completely unnecessary for these chipsets... */
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000438 if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
Ben Skeggsebb945a2012-07-20 08:17:34 +1000439 return nouveau_abi16_put(abi16, -EINVAL);
Ben Skeggs3bdda042014-08-10 04:10:23 +1000440 client = nvif_client(nvif_object(&abi16->device));
Ben Skeggs2a259a32012-05-08 10:24:27 +1000441
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000442 chan = nouveau_abi16_chan(abi16, info->channel);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000443 if (!chan)
444 return nouveau_abi16_put(abi16, -ENOENT);
445
446 ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
447 if (!ntfy)
448 return nouveau_abi16_put(abi16, -ENOMEM);
449
450 list_add(&ntfy->head, &chan->notifiers);
451 ntfy->handle = info->handle;
452
453 ret = nouveau_mm_head(&chan->heap, 1, info->size, info->size, 1,
454 &ntfy->node);
455 if (ret)
456 goto done;
457
Ben Skeggs3bdda042014-08-10 04:10:23 +1000458 args.ctxdma.start = ntfy->node->offset;
459 args.ctxdma.limit = ntfy->node->offset + ntfy->node->length - 1;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000460 if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
Ben Skeggs3bdda042014-08-10 04:10:23 +1000461 args.ctxdma.flags = NV_DMA_TARGET_VM | NV_DMA_ACCESS_VM;
462 args.ctxdma.start += chan->ntfy_vma.offset;
463 args.ctxdma.limit += chan->ntfy_vma.offset;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000464 } else
465 if (drm->agp.stat == ENABLED) {
Ben Skeggs3bdda042014-08-10 04:10:23 +1000466 args.ctxdma.flags = NV_DMA_TARGET_AGP | NV_DMA_ACCESS_RDWR;
467 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 Skeggs3bdda042014-08-10 04:10:23 +1000471 args.ctxdma.flags = NV_DMA_TARGET_VM | NV_DMA_ACCESS_RDWR;
472 args.ctxdma.start += chan->ntfy->bo.offset;
473 args.ctxdma.limit += chan->ntfy->bo.offset;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000474 }
475
Ben Skeggs3bdda042014-08-10 04:10:23 +1000476 ret = nvif_client_ioctl(client, &args, sizeof(args));
477 client->super = false;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000478 if (ret)
479 goto done;
480
Bob Gleitsmannc1ccaa62014-01-06 08:59:07 +1000481 info->offset = ntfy->node->offset;
482
Ben Skeggsebb945a2012-07-20 08:17:34 +1000483done:
484 if (ret)
485 nouveau_abi16_ntfy_fini(chan, ntfy);
486 return nouveau_abi16_put(abi16, ret);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000487}
488
489int
490nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
491{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000492 struct drm_nouveau_gpuobj_free *fini = data;
493 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000494 struct nouveau_abi16_chan *chan;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000495 struct nouveau_abi16_ntfy *ntfy;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000496 int ret;
497
Ben Skeggsebb945a2012-07-20 08:17:34 +1000498 if (unlikely(!abi16))
499 return -ENOMEM;
Ben Skeggs2a259a32012-05-08 10:24:27 +1000500
Ben Skeggsa4e610b2014-08-10 04:10:23 +1000501 chan = nouveau_abi16_chan(abi16, fini->channel);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000502 if (!chan)
503 return nouveau_abi16_put(abi16, -ENOENT);
504
505 /* synchronize with the user channel and destroy the gpu object */
506 nouveau_channel_idle(chan->chan);
507
Ben Skeggs0ad72862014-08-10 04:10:22 +1000508 /*XXX*/
509 ret = nouveau_object_del(nv_object(nvkm_client(&abi16->device.base)),
510 chan->chan->object->handle, fini->handle);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000511 if (ret)
512 return nouveau_abi16_put(abi16, ret);
513
514 /* cleanup extra state if this object was a notifier */
515 list_for_each_entry(ntfy, &chan->notifiers, head) {
516 if (ntfy->handle == fini->handle) {
517 nouveau_mm_free(&chan->heap, &ntfy->node);
518 list_del(&ntfy->head);
519 break;
520 }
521 }
522
523 return nouveau_abi16_put(abi16, 0);
Ben Skeggs2a259a32012-05-08 10:24:27 +1000524}