xref: /openbmc/linux/drivers/gpu/drm/nouveau/nouveau_abi16.c (revision 7b7fd0ac7dc1ffcaf24d9bca0f051b0168e43cd4)
12a259a3dSBen Skeggs /*
22a259a3dSBen Skeggs  * Copyright 2012 Red Hat Inc.
32a259a3dSBen Skeggs  *
42a259a3dSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
52a259a3dSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
62a259a3dSBen Skeggs  * to deal in the Software without restriction, including without limitation
72a259a3dSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
82a259a3dSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
92a259a3dSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
102a259a3dSBen Skeggs  *
112a259a3dSBen Skeggs  * The above copyright notice and this permission notice shall be included in
122a259a3dSBen Skeggs  * all copies or substantial portions of the Software.
132a259a3dSBen Skeggs  *
142a259a3dSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
152a259a3dSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
162a259a3dSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
172a259a3dSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
182a259a3dSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
192a259a3dSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
202a259a3dSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
212a259a3dSBen Skeggs  *
222a259a3dSBen Skeggs  */
232a259a3dSBen Skeggs 
24a4e610b5SBen Skeggs #include <nvif/client.h>
25a4e610b5SBen Skeggs #include <nvif/driver.h>
26a7cf0180SBen Skeggs #include <nvif/fifo.h>
27a4e610b5SBen Skeggs #include <nvif/ioctl.h>
28fdb751efSBen Skeggs #include <nvif/class.h>
29845f2725SBen Skeggs #include <nvif/cl0002.h>
302621a416SBen Skeggs #include <nvif/unpack.h>
312a259a3dSBen Skeggs 
324dc28134SBen Skeggs #include "nouveau_drv.h"
332a259a3dSBen Skeggs #include "nouveau_dma.h"
34d59e75eeSDanilo Krummrich #include "nouveau_exec.h"
35ebb945a9SBen Skeggs #include "nouveau_gem.h"
36ebb945a9SBen Skeggs #include "nouveau_chan.h"
372a259a3dSBen Skeggs #include "nouveau_abi16.h"
3824e8375bSBen Skeggs #include "nouveau_vmm.h"
39b88baab8SDanilo Krummrich #include "nouveau_sched.h"
40ebb945a9SBen Skeggs 
41786a57efSBen Skeggs static struct nouveau_abi16 *
nouveau_abi16(struct drm_file * file_priv)42786a57efSBen Skeggs nouveau_abi16(struct drm_file *file_priv)
43ebb945a9SBen Skeggs {
44ebb945a9SBen Skeggs 	struct nouveau_cli *cli = nouveau_cli(file_priv);
45ebb945a9SBen Skeggs 	if (!cli->abi16) {
46ebb945a9SBen Skeggs 		struct nouveau_abi16 *abi16;
47ebb945a9SBen Skeggs 		cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL);
48ebb945a9SBen Skeggs 		if (cli->abi16) {
49586491e6SBen Skeggs 			struct nv_device_v0 args = {
50586491e6SBen Skeggs 				.device = ~0ULL,
51586491e6SBen Skeggs 			};
52586491e6SBen Skeggs 
53ebb945a9SBen Skeggs 			INIT_LIST_HEAD(&abi16->channels);
54ebb945a9SBen Skeggs 
55ebb945a9SBen Skeggs 			/* allocate device object targeting client's default
56ebb945a9SBen Skeggs 			 * device (ie. the one that belongs to the fd it
57ebb945a9SBen Skeggs 			 * opened)
58ebb945a9SBen Skeggs 			 */
59bd21080eSBen Skeggs 			if (nvif_device_ctor(&cli->base.object, "abi16Device",
60bd21080eSBen Skeggs 					     0, NV_DEVICE, &args, sizeof(args),
610ad72863SBen Skeggs 					     &abi16->device) == 0)
62ebb945a9SBen Skeggs 				return cli->abi16;
63ebb945a9SBen Skeggs 
64ebb945a9SBen Skeggs 			kfree(cli->abi16);
65ebb945a9SBen Skeggs 			cli->abi16 = NULL;
66ebb945a9SBen Skeggs 		}
67ebb945a9SBen Skeggs 	}
68ebb945a9SBen Skeggs 	return cli->abi16;
69ebb945a9SBen Skeggs }
70ebb945a9SBen Skeggs 
71786a57efSBen Skeggs struct nouveau_abi16 *
nouveau_abi16_get(struct drm_file * file_priv)72786a57efSBen Skeggs nouveau_abi16_get(struct drm_file *file_priv)
73786a57efSBen Skeggs {
74786a57efSBen Skeggs 	struct nouveau_cli *cli = nouveau_cli(file_priv);
75786a57efSBen Skeggs 	mutex_lock(&cli->mutex);
76786a57efSBen Skeggs 	if (nouveau_abi16(file_priv))
77786a57efSBen Skeggs 		return cli->abi16;
78786a57efSBen Skeggs 	mutex_unlock(&cli->mutex);
79786a57efSBen Skeggs 	return NULL;
80786a57efSBen Skeggs }
81786a57efSBen Skeggs 
82ebb945a9SBen Skeggs int
nouveau_abi16_put(struct nouveau_abi16 * abi16,int ret)83ebb945a9SBen Skeggs nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret)
84ebb945a9SBen Skeggs {
85a01ca78cSBen Skeggs 	struct nouveau_cli *cli = (void *)abi16->device.object.client;
86ebb945a9SBen Skeggs 	mutex_unlock(&cli->mutex);
87ebb945a9SBen Skeggs 	return ret;
88ebb945a9SBen Skeggs }
89ebb945a9SBen Skeggs 
90f58ddf95SBen Skeggs s32
nouveau_abi16_swclass(struct nouveau_drm * drm)91ebb945a9SBen Skeggs nouveau_abi16_swclass(struct nouveau_drm *drm)
92ebb945a9SBen Skeggs {
931167c6bcSBen Skeggs 	switch (drm->client.device.info.family) {
94967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_TNT:
9508f7633cSBen Skeggs 		return NVIF_CLASS_SW_NV04;
96967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_CELSIUS:
97967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_KELVIN:
98967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_RANKINE:
99967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_CURIE:
10008f7633cSBen Skeggs 		return NVIF_CLASS_SW_NV10;
101967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_TESLA:
10208f7633cSBen Skeggs 		return NVIF_CLASS_SW_NV50;
103967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_FERMI:
104967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_KEPLER:
105967e7bdeSBen Skeggs 	case NV_DEVICE_INFO_V0_MAXWELL:
1067f53abdbSBen Skeggs 	case NV_DEVICE_INFO_V0_PASCAL:
107c1f856bbSBen Skeggs 	case NV_DEVICE_INFO_V0_VOLTA:
10808f7633cSBen Skeggs 		return NVIF_CLASS_SW_GF100;
109ebb945a9SBen Skeggs 	}
110ebb945a9SBen Skeggs 
111ebb945a9SBen Skeggs 	return 0x0000;
112ebb945a9SBen Skeggs }
113ebb945a9SBen Skeggs 
114ebb945a9SBen Skeggs static void
nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan * chan,struct nouveau_abi16_ntfy * ntfy)115ebb945a9SBen Skeggs nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan,
116ebb945a9SBen Skeggs 			struct nouveau_abi16_ntfy *ntfy)
117ebb945a9SBen Skeggs {
1189ac596a4SBen Skeggs 	nvif_object_dtor(&ntfy->object);
119be83cd4eSBen Skeggs 	nvkm_mm_free(&chan->heap, &ntfy->node);
120ebb945a9SBen Skeggs 	list_del(&ntfy->head);
121ebb945a9SBen Skeggs 	kfree(ntfy);
122ebb945a9SBen Skeggs }
123ebb945a9SBen Skeggs 
124ebb945a9SBen Skeggs static void
nouveau_abi16_chan_fini(struct nouveau_abi16 * abi16,struct nouveau_abi16_chan * chan)125ebb945a9SBen Skeggs nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
126ebb945a9SBen Skeggs 			struct nouveau_abi16_chan *chan)
127ebb945a9SBen Skeggs {
128ebb945a9SBen Skeggs 	struct nouveau_abi16_ntfy *ntfy, *temp;
129ebb945a9SBen Skeggs 
130b88baab8SDanilo Krummrich 	/* When a client exits without waiting for it's queued up jobs to
131b88baab8SDanilo Krummrich 	 * finish it might happen that we fault the channel. This is due to
132b88baab8SDanilo Krummrich 	 * drm_file_free() calling drm_gem_release() before the postclose()
133b88baab8SDanilo Krummrich 	 * callback. Hence, we can't tear down this scheduler entity before
134b88baab8SDanilo Krummrich 	 * uvmm mappings are unmapped. Currently, we can't detect this case.
135b88baab8SDanilo Krummrich 	 *
136b88baab8SDanilo Krummrich 	 * However, this should be rare and harmless, since the channel isn't
137b88baab8SDanilo Krummrich 	 * needed anymore.
138b88baab8SDanilo Krummrich 	 */
139b88baab8SDanilo Krummrich 	nouveau_sched_entity_fini(&chan->sched_entity);
140b88baab8SDanilo Krummrich 
1417ba01b50SBen Skeggs 	/* wait for all activity to stop before cleaning up */
1427ba01b50SBen Skeggs 	if (chan->chan)
1432b77c1c0SMarcin Slusarz 		nouveau_channel_idle(chan->chan);
1442b77c1c0SMarcin Slusarz 
145ebb945a9SBen Skeggs 	/* cleanup notifier state */
146ebb945a9SBen Skeggs 	list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) {
147ebb945a9SBen Skeggs 		nouveau_abi16_ntfy_fini(chan, ntfy);
148ebb945a9SBen Skeggs 	}
149ebb945a9SBen Skeggs 
150ebb945a9SBen Skeggs 	if (chan->ntfy) {
15124e8375bSBen Skeggs 		nouveau_vma_del(&chan->ntfy_vma);
152198c14a0SMaarten Lankhorst 		nouveau_bo_unpin(chan->ntfy);
153cdc194ceSEmil Velikov 		drm_gem_object_put(&chan->ntfy->bo.base);
154ebb945a9SBen Skeggs 	}
155ebb945a9SBen Skeggs 
156ebb945a9SBen Skeggs 	if (chan->heap.block_size)
157be83cd4eSBen Skeggs 		nvkm_mm_fini(&chan->heap);
158ebb945a9SBen Skeggs 
159ebb945a9SBen Skeggs 	/* destroy channel object, all children will be killed too */
160ebb945a9SBen Skeggs 	if (chan->chan) {
16140184eceSBen Skeggs 		nvif_object_dtor(&chan->ce);
162ebb945a9SBen Skeggs 		nouveau_channel_del(&chan->chan);
163ebb945a9SBen Skeggs 	}
164ebb945a9SBen Skeggs 
165ebb945a9SBen Skeggs 	list_del(&chan->head);
166ebb945a9SBen Skeggs 	kfree(chan);
167ebb945a9SBen Skeggs }
168ebb945a9SBen Skeggs 
169ebb945a9SBen Skeggs void
nouveau_abi16_fini(struct nouveau_abi16 * abi16)170ebb945a9SBen Skeggs nouveau_abi16_fini(struct nouveau_abi16 *abi16)
171ebb945a9SBen Skeggs {
172a01ca78cSBen Skeggs 	struct nouveau_cli *cli = (void *)abi16->device.object.client;
173ebb945a9SBen Skeggs 	struct nouveau_abi16_chan *chan, *temp;
174ebb945a9SBen Skeggs 
175ebb945a9SBen Skeggs 	/* cleanup channels */
176ebb945a9SBen Skeggs 	list_for_each_entry_safe(chan, temp, &abi16->channels, head) {
177ebb945a9SBen Skeggs 		nouveau_abi16_chan_fini(abi16, chan);
178ebb945a9SBen Skeggs 	}
179ebb945a9SBen Skeggs 
180ebb945a9SBen Skeggs 	/* destroy the device object */
181bd21080eSBen Skeggs 	nvif_device_dtor(&abi16->device);
182ebb945a9SBen Skeggs 
183ebb945a9SBen Skeggs 	kfree(cli->abi16);
184ebb945a9SBen Skeggs 	cli->abi16 = NULL;
185ebb945a9SBen Skeggs }
1862a259a3dSBen Skeggs 
187d59e75eeSDanilo Krummrich static inline int
getparam_dma_ib_max(struct nvif_device * device)188d59e75eeSDanilo Krummrich getparam_dma_ib_max(struct nvif_device *device)
189d59e75eeSDanilo Krummrich {
190d59e75eeSDanilo Krummrich 	const struct nvif_mclass dmas[] = {
191d59e75eeSDanilo Krummrich 		{ NV03_CHANNEL_DMA, 0 },
192d59e75eeSDanilo Krummrich 		{ NV10_CHANNEL_DMA, 0 },
193d59e75eeSDanilo Krummrich 		{ NV17_CHANNEL_DMA, 0 },
194d59e75eeSDanilo Krummrich 		{ NV40_CHANNEL_DMA, 0 },
195d59e75eeSDanilo Krummrich 		{}
196d59e75eeSDanilo Krummrich 	};
197d59e75eeSDanilo Krummrich 
198d59e75eeSDanilo Krummrich 	return nvif_mclass(&device->object, dmas) < 0 ? NV50_DMA_IB_MAX : 0;
199d59e75eeSDanilo Krummrich }
200d59e75eeSDanilo Krummrich 
2012a259a3dSBen Skeggs int
nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)2022a259a3dSBen Skeggs nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
2032a259a3dSBen Skeggs {
204fa2bade9SBen Skeggs 	struct nouveau_cli *cli = nouveau_cli(file_priv);
205ebb945a9SBen Skeggs 	struct nouveau_drm *drm = nouveau_drm(dev);
2061167c6bcSBen Skeggs 	struct nvif_device *device = &drm->client.device;
207929eaf32SDave Airlie 	struct nvkm_device *nvkm_device = nvxx_device(&drm->client.device);
208be83cd4eSBen Skeggs 	struct nvkm_gr *gr = nvxx_gr(device);
2092a259a3dSBen Skeggs 	struct drm_nouveau_getparam *getparam = data;
2104c0d42f7SThomas Zimmermann 	struct pci_dev *pdev = to_pci_dev(dev->dev);
2112a259a3dSBen Skeggs 
2122a259a3dSBen Skeggs 	switch (getparam->param) {
2132a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_CHIPSET_ID:
214967e7bdeSBen Skeggs 		getparam->value = device->info.chipset;
2152a259a3dSBen Skeggs 		break;
2162a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_PCI_VENDOR:
217359088d5SBen Skeggs 		if (device->info.platform != NV_DEVICE_INFO_V0_SOC)
2184c0d42f7SThomas Zimmermann 			getparam->value = pdev->vendor;
219420b9469SAlexandre Courbot 		else
220420b9469SAlexandre Courbot 			getparam->value = 0;
2212a259a3dSBen Skeggs 		break;
2222a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_PCI_DEVICE:
223359088d5SBen Skeggs 		if (device->info.platform != NV_DEVICE_INFO_V0_SOC)
2244c0d42f7SThomas Zimmermann 			getparam->value = pdev->device;
225420b9469SAlexandre Courbot 		else
226420b9469SAlexandre Courbot 			getparam->value = 0;
2272a259a3dSBen Skeggs 		break;
2282a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_BUS_TYPE:
229359088d5SBen Skeggs 		switch (device->info.platform) {
230359088d5SBen Skeggs 		case NV_DEVICE_INFO_V0_AGP : getparam->value = 0; break;
231359088d5SBen Skeggs 		case NV_DEVICE_INFO_V0_PCI : getparam->value = 1; break;
232359088d5SBen Skeggs 		case NV_DEVICE_INFO_V0_PCIE: getparam->value = 2; break;
233359088d5SBen Skeggs 		case NV_DEVICE_INFO_V0_SOC : getparam->value = 3; break;
234359088d5SBen Skeggs 		case NV_DEVICE_INFO_V0_IGP :
2354c0d42f7SThomas Zimmermann 			if (!pci_is_pcie(pdev))
2362a259a3dSBen Skeggs 				getparam->value = 1;
2372a259a3dSBen Skeggs 			else
2382a259a3dSBen Skeggs 				getparam->value = 2;
2392a259a3dSBen Skeggs 			break;
240359088d5SBen Skeggs 		default:
241359088d5SBen Skeggs 			WARN_ON(1);
242359088d5SBen Skeggs 			break;
243359088d5SBen Skeggs 		}
244785cf1eeSColin Ian King 		break;
2452a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_FB_SIZE:
246ebb945a9SBen Skeggs 		getparam->value = drm->gem.vram_available;
2472a259a3dSBen Skeggs 		break;
2482a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_AGP_SIZE:
249ebb945a9SBen Skeggs 		getparam->value = drm->gem.gart_available;
2502a259a3dSBen Skeggs 		break;
2512a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_VM_VRAM_BASE:
2522a259a3dSBen Skeggs 		getparam->value = 0; /* deprecated */
2532a259a3dSBen Skeggs 		break;
2542a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_PTIMER_TIME:
25556f67dc1SBen Skeggs 		getparam->value = nvif_device_time(device);
2562a259a3dSBen Skeggs 		break;
2572a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_HAS_BO_USAGE:
2582a259a3dSBen Skeggs 		getparam->value = 1;
2592a259a3dSBen Skeggs 		break;
2602a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_HAS_PAGEFLIP:
2612a259a3dSBen Skeggs 		getparam->value = 1;
2622a259a3dSBen Skeggs 		break;
2632a259a3dSBen Skeggs 	case NOUVEAU_GETPARAM_GRAPH_UNITS:
264c85ee6caSBen Skeggs 		getparam->value = nvkm_gr_units(gr);
2652a259a3dSBen Skeggs 		break;
266d59e75eeSDanilo Krummrich 	case NOUVEAU_GETPARAM_EXEC_PUSH_MAX: {
267d59e75eeSDanilo Krummrich 		int ib_max = getparam_dma_ib_max(device);
268d59e75eeSDanilo Krummrich 
269d59e75eeSDanilo Krummrich 		getparam->value = nouveau_exec_push_max_from_ib_max(ib_max);
270d59e75eeSDanilo Krummrich 		break;
271d59e75eeSDanilo Krummrich 	}
272929eaf32SDave Airlie 	case NOUVEAU_GETPARAM_VRAM_BAR_SIZE:
273929eaf32SDave Airlie 		getparam->value = nvkm_device->func->resource_size(nvkm_device, 1);
274929eaf32SDave Airlie 		break;
2756446c1caSDave Airlie 	case NOUVEAU_GETPARAM_VRAM_USED: {
2766446c1caSDave Airlie 		struct ttm_resource_manager *vram_mgr = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
277c353aa21SDave Airlie 		getparam->value = (u64)ttm_resource_manager_usage(vram_mgr);
2786446c1caSDave Airlie 		break;
2796446c1caSDave Airlie 	}
2803652ac87SMohamed Ahmed 	case NOUVEAU_GETPARAM_HAS_VMA_TILEMODE:
2813652ac87SMohamed Ahmed 		getparam->value = 1;
2823652ac87SMohamed Ahmed 		break;
2832a259a3dSBen Skeggs 	default:
2849ad97edeSBen Skeggs 		NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param);
2852a259a3dSBen Skeggs 		return -EINVAL;
2862a259a3dSBen Skeggs 	}
2872a259a3dSBen Skeggs 
2882a259a3dSBen Skeggs 	return 0;
2892a259a3dSBen Skeggs }
2902a259a3dSBen Skeggs 
2912a259a3dSBen Skeggs int
nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)2922a259a3dSBen Skeggs nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
2932a259a3dSBen Skeggs {
2942a259a3dSBen Skeggs 	struct drm_nouveau_channel_alloc *init = data;
295ebb945a9SBen Skeggs 	struct nouveau_cli *cli = nouveau_cli(file_priv);
296ebb945a9SBen Skeggs 	struct nouveau_drm *drm = nouveau_drm(dev);
29709433f24SBen Skeggs 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
298ebb945a9SBen Skeggs 	struct nouveau_abi16_chan *chan;
299967e7bdeSBen Skeggs 	struct nvif_device *device;
3006de12538SBen Skeggs 	u64 engine, runm;
3012a259a3dSBen Skeggs 	int ret;
3022a259a3dSBen Skeggs 
303ebb945a9SBen Skeggs 	if (unlikely(!abi16))
304ebb945a9SBen Skeggs 		return -ENOMEM;
305bf7e438bSMarcin Slusarz 
306bf7e438bSMarcin Slusarz 	if (!drm->channel)
307bf7e438bSMarcin Slusarz 		return nouveau_abi16_put(abi16, -ENODEV);
308bf7e438bSMarcin Slusarz 
309b88baab8SDanilo Krummrich 	/* If uvmm wasn't initialized until now disable it completely to prevent
310b88baab8SDanilo Krummrich 	 * userspace from mixing up UAPIs.
311b88baab8SDanilo Krummrich 	 *
312b88baab8SDanilo Krummrich 	 * The client lock is already acquired by nouveau_abi16_get().
313b88baab8SDanilo Krummrich 	 */
314b88baab8SDanilo Krummrich 	__nouveau_cli_disable_uvmm_noinit(cli);
315b88baab8SDanilo Krummrich 
316967e7bdeSBen Skeggs 	device = &abi16->device;
3176de12538SBen Skeggs 	engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR;
318ebb945a9SBen Skeggs 
31949469800SBen Skeggs 	/* hack to allow channel engine type specification on kepler */
320967e7bdeSBen Skeggs 	if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
321a7cf0180SBen Skeggs 		if (init->fb_ctxdma_handle == ~0) {
322a7cf0180SBen Skeggs 			switch (init->tt_ctxdma_handle) {
323f8fabd31SBen Skeggs 			case 0x01: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_GR    ; break;
324f8fabd31SBen Skeggs 			case 0x02: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPDEC; break;
325f8fabd31SBen Skeggs 			case 0x04: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSPPP ; break;
326f8fabd31SBen Skeggs 			case 0x08: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_MSVLD ; break;
327f8fabd31SBen Skeggs 			case 0x30: engine = NV_DEVICE_HOST_RUNLIST_ENGINES_CE    ; break;
328a7cf0180SBen Skeggs 			default:
329a7cf0180SBen Skeggs 				return nouveau_abi16_put(abi16, -ENOSYS);
330a7cf0180SBen Skeggs 			}
3316de12538SBen Skeggs 
3326de12538SBen Skeggs 			init->fb_ctxdma_handle = 0;
3336de12538SBen Skeggs 			init->tt_ctxdma_handle = 0;
3346de12538SBen Skeggs 		}
3351f5ff7f5SBen Skeggs 	}
33649469800SBen Skeggs 
337f8fabd31SBen Skeggs 	if (engine != NV_DEVICE_HOST_RUNLIST_ENGINES_CE)
3386de12538SBen Skeggs 		runm = nvif_fifo_runlist(device, engine);
339a7cf0180SBen Skeggs 	else
3406de12538SBen Skeggs 		runm = nvif_fifo_runlist_ce(device);
34149469800SBen Skeggs 
3426de12538SBen Skeggs 	if (!runm || init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0)
34349469800SBen Skeggs 		return nouveau_abi16_put(abi16, -EINVAL);
34449469800SBen Skeggs 
345ebb945a9SBen Skeggs 	/* allocate "abi16 channel" data and make up a handle for it */
346ebb945a9SBen Skeggs 	chan = kzalloc(sizeof(*chan), GFP_KERNEL);
347ebb945a9SBen Skeggs 	if (!chan)
348ebb945a9SBen Skeggs 		return nouveau_abi16_put(abi16, -ENOMEM);
349ebb945a9SBen Skeggs 
350ebb945a9SBen Skeggs 	INIT_LIST_HEAD(&chan->notifiers);
351ebb945a9SBen Skeggs 	list_add(&chan->head, &abi16->channels);
352ebb945a9SBen Skeggs 
353ebb945a9SBen Skeggs 	/* create channel object and initialise dma and fence management */
354*0aac3fb6SBen Skeggs 	ret = nouveau_channel_new(cli, false, runm, init->fb_ctxdma_handle,
3556de12538SBen Skeggs 				  init->tt_ctxdma_handle, &chan->chan);
3562a259a3dSBen Skeggs 	if (ret)
357ebb945a9SBen Skeggs 		goto done;
3582a259a3dSBen Skeggs 
359b88baab8SDanilo Krummrich 	ret = nouveau_sched_entity_init(&chan->sched_entity, &drm->sched,
360b88baab8SDanilo Krummrich 					drm->sched_wq);
361b88baab8SDanilo Krummrich 	if (ret)
362b88baab8SDanilo Krummrich 		goto done;
363b88baab8SDanilo Krummrich 
364fcf3f91cSBen Skeggs 	init->channel = chan->chan->chid;
365fcf3f91cSBen Skeggs 
366967e7bdeSBen Skeggs 	if (device->info.family >= NV_DEVICE_INFO_V0_TESLA)
3672a259a3dSBen Skeggs 		init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM |
3682a259a3dSBen Skeggs 					NOUVEAU_GEM_DOMAIN_GART;
369ebb945a9SBen Skeggs 	else
370d3116756SChristian König 	if (chan->chan->push.buffer->bo.resource->mem_type == TTM_PL_VRAM)
3712a259a3dSBen Skeggs 		init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM;
3722a259a3dSBen Skeggs 	else
3732a259a3dSBen Skeggs 		init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART;
3742a259a3dSBen Skeggs 
375967e7bdeSBen Skeggs 	if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) {
3762a259a3dSBen Skeggs 		init->subchan[0].handle = 0x00000000;
3772a259a3dSBen Skeggs 		init->subchan[0].grclass = 0x0000;
378f45f55c4SBen Skeggs 		init->subchan[1].handle = chan->chan->nvsw.handle;
379ebb945a9SBen Skeggs 		init->subchan[1].grclass = 0x506e;
3802a259a3dSBen Skeggs 		init->nr_subchan = 2;
3812a259a3dSBen Skeggs 	}
3822a259a3dSBen Skeggs 
38340184eceSBen Skeggs 	/* Workaround "nvc0" gallium driver using classes it doesn't allocate on
38440184eceSBen Skeggs 	 * Kepler and above.  NVKM no longer always sets CE_CTX_VALID as part of
38540184eceSBen Skeggs 	 * channel init, now we know what that stuff actually is.
38640184eceSBen Skeggs 	 *
38740184eceSBen Skeggs 	 * Doesn't matter for Kepler/Pascal, CE context stored in NV_RAMIN.
38840184eceSBen Skeggs 	 *
38940184eceSBen Skeggs 	 * Userspace was fixed prior to adding Ampere support.
39040184eceSBen Skeggs 	 */
39140184eceSBen Skeggs 	switch (device->info.family) {
39240184eceSBen Skeggs 	case NV_DEVICE_INFO_V0_VOLTA:
39340184eceSBen Skeggs 		ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, VOLTA_DMA_COPY_A,
39440184eceSBen Skeggs 				       NULL, 0, &chan->ce);
39540184eceSBen Skeggs 		if (ret)
39640184eceSBen Skeggs 			goto done;
39740184eceSBen Skeggs 		break;
39840184eceSBen Skeggs 	case NV_DEVICE_INFO_V0_TURING:
39940184eceSBen Skeggs 		ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar", 0, TURING_DMA_COPY_A,
40040184eceSBen Skeggs 				       NULL, 0, &chan->ce);
40140184eceSBen Skeggs 		if (ret)
40240184eceSBen Skeggs 			goto done;
40340184eceSBen Skeggs 		break;
40440184eceSBen Skeggs 	default:
40540184eceSBen Skeggs 		break;
40640184eceSBen Skeggs 	}
40740184eceSBen Skeggs 
4082a259a3dSBen Skeggs 	/* Named memory object area */
409fc1b0a02SBen Skeggs 	ret = nouveau_gem_new(cli, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART,
410ebb945a9SBen Skeggs 			      0, 0, &chan->ntfy);
4112a259a3dSBen Skeggs 	if (ret == 0)
41281b61579SChristian König 		ret = nouveau_bo_pin(chan->ntfy, NOUVEAU_GEM_DOMAIN_GART,
41381b61579SChristian König 				     false);
414ebb945a9SBen Skeggs 	if (ret)
415ebb945a9SBen Skeggs 		goto done;
416ebb945a9SBen Skeggs 
417967e7bdeSBen Skeggs 	if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
418bfe91afaSBen Skeggs 		ret = nouveau_vma_new(chan->ntfy, chan->chan->vmm,
419bfe91afaSBen Skeggs 				      &chan->ntfy_vma);
420ebb945a9SBen Skeggs 		if (ret)
421ebb945a9SBen Skeggs 			goto done;
4222a259a3dSBen Skeggs 	}
4232a259a3dSBen Skeggs 
424f8659be8SGerd Hoffmann 	ret = drm_gem_handle_create(file_priv, &chan->ntfy->bo.base,
425ebb945a9SBen Skeggs 				    &init->notifier_handle);
426ebb945a9SBen Skeggs 	if (ret)
427ebb945a9SBen Skeggs 		goto done;
428ebb945a9SBen Skeggs 
4294d058fabSBen Skeggs 	ret = nvkm_mm_init(&chan->heap, 0, 0, PAGE_SIZE, 1);
430ebb945a9SBen Skeggs done:
431ebb945a9SBen Skeggs 	if (ret)
432ebb945a9SBen Skeggs 		nouveau_abi16_chan_fini(abi16, chan);
433ebb945a9SBen Skeggs 	return nouveau_abi16_put(abi16, ret);
434ebb945a9SBen Skeggs }
435ebb945a9SBen Skeggs 
436a4e610b5SBen Skeggs static struct nouveau_abi16_chan *
nouveau_abi16_chan(struct nouveau_abi16 * abi16,int channel)437a4e610b5SBen Skeggs nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel)
438a4e610b5SBen Skeggs {
439a4e610b5SBen Skeggs 	struct nouveau_abi16_chan *chan;
440a4e610b5SBen Skeggs 
441a4e610b5SBen Skeggs 	list_for_each_entry(chan, &abi16->channels, head) {
442fcf3f91cSBen Skeggs 		if (chan->chan->chid == channel)
443a4e610b5SBen Skeggs 			return chan;
444a4e610b5SBen Skeggs 	}
445a4e610b5SBen Skeggs 
446a4e610b5SBen Skeggs 	return NULL;
447a4e610b5SBen Skeggs }
448ebb945a9SBen Skeggs 
4492a259a3dSBen Skeggs int
nouveau_abi16_usif(struct drm_file * file_priv,void * data,u32 size)4502621a416SBen Skeggs nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size)
4512621a416SBen Skeggs {
4522621a416SBen Skeggs 	union {
4532621a416SBen Skeggs 		struct nvif_ioctl_v0 v0;
4542621a416SBen Skeggs 	} *args = data;
4552621a416SBen Skeggs 	struct nouveau_abi16_chan *chan;
4562621a416SBen Skeggs 	struct nouveau_abi16 *abi16;
457f01c4e68SBen Skeggs 	int ret = -ENOSYS;
4582621a416SBen Skeggs 
459f01c4e68SBen Skeggs 	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
4602621a416SBen Skeggs 		switch (args->v0.type) {
4612621a416SBen Skeggs 		case NVIF_IOCTL_V0_NEW:
4622621a416SBen Skeggs 		case NVIF_IOCTL_V0_MTHD:
4632621a416SBen Skeggs 		case NVIF_IOCTL_V0_SCLASS:
4642621a416SBen Skeggs 			break;
4652621a416SBen Skeggs 		default:
4662621a416SBen Skeggs 			return -EACCES;
4672621a416SBen Skeggs 		}
4682621a416SBen Skeggs 	} else
4692621a416SBen Skeggs 		return ret;
4702621a416SBen Skeggs 
4712621a416SBen Skeggs 	if (!(abi16 = nouveau_abi16(file_priv)))
4722621a416SBen Skeggs 		return -ENOMEM;
4732621a416SBen Skeggs 
4742621a416SBen Skeggs 	if (args->v0.token != ~0ULL) {
4752621a416SBen Skeggs 		if (!(chan = nouveau_abi16_chan(abi16, args->v0.token)))
4762621a416SBen Skeggs 			return -EINVAL;
4772621a416SBen Skeggs 		args->v0.object = nvif_handle(&chan->chan->user);
4782621a416SBen Skeggs 		args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
4792621a416SBen Skeggs 		return 0;
4802621a416SBen Skeggs 	}
4812621a416SBen Skeggs 
4822621a416SBen Skeggs 	args->v0.object = nvif_handle(&abi16->device.object);
4832621a416SBen Skeggs 	args->v0.owner  = NVIF_IOCTL_V0_OWNER_ANY;
4842621a416SBen Skeggs 	return 0;
4852621a416SBen Skeggs }
4862621a416SBen Skeggs 
4872621a416SBen Skeggs int
nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)4882a259a3dSBen Skeggs nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS)
4892a259a3dSBen Skeggs {
4902a259a3dSBen Skeggs 	struct drm_nouveau_channel_free *req = data;
49109433f24SBen Skeggs 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
492ebb945a9SBen Skeggs 	struct nouveau_abi16_chan *chan;
4932a259a3dSBen Skeggs 
494ebb945a9SBen Skeggs 	if (unlikely(!abi16))
495ebb945a9SBen Skeggs 		return -ENOMEM;
4962a259a3dSBen Skeggs 
497a4e610b5SBen Skeggs 	chan = nouveau_abi16_chan(abi16, req->channel);
498a4e610b5SBen Skeggs 	if (!chan)
499a4e610b5SBen Skeggs 		return nouveau_abi16_put(abi16, -ENOENT);
500ebb945a9SBen Skeggs 	nouveau_abi16_chan_fini(abi16, chan);
501ebb945a9SBen Skeggs 	return nouveau_abi16_put(abi16, 0);
502ebb945a9SBen Skeggs }
5032a259a3dSBen Skeggs 
5042a259a3dSBen Skeggs int
nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)5052a259a3dSBen Skeggs nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
5062a259a3dSBen Skeggs {
5072a259a3dSBen Skeggs 	struct drm_nouveau_grobj_alloc *init = data;
50809433f24SBen Skeggs 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
509a01ca78cSBen Skeggs 	struct nouveau_abi16_chan *chan;
510a01ca78cSBen Skeggs 	struct nouveau_abi16_ntfy *ntfy;
511a4e610b5SBen Skeggs 	struct nvif_client *client;
51241a63406SBen Skeggs 	struct nvif_sclass *sclass;
513f58ddf95SBen Skeggs 	s32 oclass = 0;
514f58ddf95SBen Skeggs 	int ret, i;
5152a259a3dSBen Skeggs 
516ebb945a9SBen Skeggs 	if (unlikely(!abi16))
517ebb945a9SBen Skeggs 		return -ENOMEM;
518ebb945a9SBen Skeggs 
5192a259a3dSBen Skeggs 	if (init->handle == ~0)
520ebb945a9SBen Skeggs 		return nouveau_abi16_put(abi16, -EINVAL);
521a01ca78cSBen Skeggs 	client = abi16->device.object.client;
5222a259a3dSBen Skeggs 
523a01ca78cSBen Skeggs 	chan = nouveau_abi16_chan(abi16, init->channel);
524a01ca78cSBen Skeggs 	if (!chan)
525a01ca78cSBen Skeggs 		return nouveau_abi16_put(abi16, -ENOENT);
526a01ca78cSBen Skeggs 
52741a63406SBen Skeggs 	ret = nvif_object_sclass_get(&chan->chan->user, &sclass);
528f58ddf95SBen Skeggs 	if (ret < 0)
529f58ddf95SBen Skeggs 		return nouveau_abi16_put(abi16, ret);
530f58ddf95SBen Skeggs 
531f58ddf95SBen Skeggs 	if ((init->class & 0x00ff) == 0x006e) {
532f58ddf95SBen Skeggs 		/* nvsw: compatibility with older 0x*6e class identifier */
533f58ddf95SBen Skeggs 		for (i = 0; !oclass && i < ret; i++) {
53441a63406SBen Skeggs 			switch (sclass[i].oclass) {
53508f7633cSBen Skeggs 			case NVIF_CLASS_SW_NV04:
53608f7633cSBen Skeggs 			case NVIF_CLASS_SW_NV10:
53708f7633cSBen Skeggs 			case NVIF_CLASS_SW_NV50:
53808f7633cSBen Skeggs 			case NVIF_CLASS_SW_GF100:
53941a63406SBen Skeggs 				oclass = sclass[i].oclass;
540f58ddf95SBen Skeggs 				break;
541f58ddf95SBen Skeggs 			default:
542f58ddf95SBen Skeggs 				break;
543f58ddf95SBen Skeggs 			}
544f58ddf95SBen Skeggs 		}
545f58ddf95SBen Skeggs 	} else
546f58ddf95SBen Skeggs 	if ((init->class & 0x00ff) == 0x00b1) {
547f58ddf95SBen Skeggs 		/* msvld: compatibility with incorrect version exposure */
548f58ddf95SBen Skeggs 		for (i = 0; i < ret; i++) {
54941a63406SBen Skeggs 			if ((sclass[i].oclass & 0x00ff) == 0x00b1) {
55041a63406SBen Skeggs 				oclass = sclass[i].oclass;
551f58ddf95SBen Skeggs 				break;
552f58ddf95SBen Skeggs 			}
553f58ddf95SBen Skeggs 		}
554f58ddf95SBen Skeggs 	} else
555f58ddf95SBen Skeggs 	if ((init->class & 0x00ff) == 0x00b2) { /* mspdec */
556f58ddf95SBen Skeggs 		/* mspdec: compatibility with incorrect version exposure */
557f58ddf95SBen Skeggs 		for (i = 0; i < ret; i++) {
55841a63406SBen Skeggs 			if ((sclass[i].oclass & 0x00ff) == 0x00b2) {
55941a63406SBen Skeggs 				oclass = sclass[i].oclass;
560f58ddf95SBen Skeggs 				break;
561f58ddf95SBen Skeggs 			}
562f58ddf95SBen Skeggs 		}
563f58ddf95SBen Skeggs 	} else
564f58ddf95SBen Skeggs 	if ((init->class & 0x00ff) == 0x00b3) { /* msppp */
565f58ddf95SBen Skeggs 		/* msppp: compatibility with incorrect version exposure */
566f58ddf95SBen Skeggs 		for (i = 0; i < ret; i++) {
56741a63406SBen Skeggs 			if ((sclass[i].oclass & 0x00ff) == 0x00b3) {
56841a63406SBen Skeggs 				oclass = sclass[i].oclass;
569f58ddf95SBen Skeggs 				break;
570f58ddf95SBen Skeggs 			}
571f58ddf95SBen Skeggs 		}
572f58ddf95SBen Skeggs 	} else {
573f58ddf95SBen Skeggs 		oclass = init->class;
574f58ddf95SBen Skeggs 	}
575f58ddf95SBen Skeggs 
57641a63406SBen Skeggs 	nvif_object_sclass_put(&sclass);
577f58ddf95SBen Skeggs 	if (!oclass)
578f58ddf95SBen Skeggs 		return nouveau_abi16_put(abi16, -EINVAL);
579f58ddf95SBen Skeggs 
580a01ca78cSBen Skeggs 	ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
581a01ca78cSBen Skeggs 	if (!ntfy)
582a01ca78cSBen Skeggs 		return nouveau_abi16_put(abi16, -ENOMEM);
583a01ca78cSBen Skeggs 
584a01ca78cSBen Skeggs 	list_add(&ntfy->head, &chan->notifiers);
585a01ca78cSBen Skeggs 
586a01ca78cSBen Skeggs 	client->route = NVDRM_OBJECT_ABI16;
5879ac596a4SBen Skeggs 	ret = nvif_object_ctor(&chan->chan->user, "abi16EngObj", init->handle,
5889ac596a4SBen Skeggs 			       oclass, NULL, 0, &ntfy->object);
589a01ca78cSBen Skeggs 	client->route = NVDRM_OBJECT_NVIF;
590a01ca78cSBen Skeggs 
591a01ca78cSBen Skeggs 	if (ret)
592a01ca78cSBen Skeggs 		nouveau_abi16_ntfy_fini(chan, ntfy);
593ebb945a9SBen Skeggs 	return nouveau_abi16_put(abi16, ret);
5942a259a3dSBen Skeggs }
5952a259a3dSBen Skeggs 
5962a259a3dSBen Skeggs int
nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)5972a259a3dSBen Skeggs nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS)
5982a259a3dSBen Skeggs {
599ebb945a9SBen Skeggs 	struct drm_nouveau_notifierobj_alloc *info = data;
600ebb945a9SBen Skeggs 	struct nouveau_drm *drm = nouveau_drm(dev);
60109433f24SBen Skeggs 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
602a4e610b5SBen Skeggs 	struct nouveau_abi16_chan *chan;
603ebb945a9SBen Skeggs 	struct nouveau_abi16_ntfy *ntfy;
604967e7bdeSBen Skeggs 	struct nvif_device *device = &abi16->device;
6053bdda04fSBen Skeggs 	struct nvif_client *client;
606a01ca78cSBen Skeggs 	struct nv_dma_v0 args = {};
6072a259a3dSBen Skeggs 	int ret;
6082a259a3dSBen Skeggs 
609ebb945a9SBen Skeggs 	if (unlikely(!abi16))
610ebb945a9SBen Skeggs 		return -ENOMEM;
611ebb945a9SBen Skeggs 
6122a259a3dSBen Skeggs 	/* completely unnecessary for these chipsets... */
613967e7bdeSBen Skeggs 	if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI))
614ebb945a9SBen Skeggs 		return nouveau_abi16_put(abi16, -EINVAL);
615a01ca78cSBen Skeggs 	client = abi16->device.object.client;
6162a259a3dSBen Skeggs 
617a4e610b5SBen Skeggs 	chan = nouveau_abi16_chan(abi16, info->channel);
618ebb945a9SBen Skeggs 	if (!chan)
619ebb945a9SBen Skeggs 		return nouveau_abi16_put(abi16, -ENOENT);
620ebb945a9SBen Skeggs 
621ebb945a9SBen Skeggs 	ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL);
622ebb945a9SBen Skeggs 	if (!ntfy)
623ebb945a9SBen Skeggs 		return nouveau_abi16_put(abi16, -ENOMEM);
624ebb945a9SBen Skeggs 
625ebb945a9SBen Skeggs 	list_add(&ntfy->head, &chan->notifiers);
626ebb945a9SBen Skeggs 
627be83cd4eSBen Skeggs 	ret = nvkm_mm_head(&chan->heap, 0, 1, info->size, info->size, 1,
628ebb945a9SBen Skeggs 			   &ntfy->node);
629ebb945a9SBen Skeggs 	if (ret)
630ebb945a9SBen Skeggs 		goto done;
631ebb945a9SBen Skeggs 
632a01ca78cSBen Skeggs 	args.start = ntfy->node->offset;
633a01ca78cSBen Skeggs 	args.limit = ntfy->node->offset + ntfy->node->length - 1;
634967e7bdeSBen Skeggs 	if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
635a01ca78cSBen Skeggs 		args.target = NV_DMA_V0_TARGET_VM;
636a01ca78cSBen Skeggs 		args.access = NV_DMA_V0_ACCESS_VM;
63724e8375bSBen Skeggs 		args.start += chan->ntfy_vma->addr;
63824e8375bSBen Skeggs 		args.limit += chan->ntfy_vma->addr;
639ebb945a9SBen Skeggs 	} else
640340b0e7cSBen Skeggs 	if (drm->agp.bridge) {
641a01ca78cSBen Skeggs 		args.target = NV_DMA_V0_TARGET_AGP;
642a01ca78cSBen Skeggs 		args.access = NV_DMA_V0_ACCESS_RDWR;
6430dc9b286SNirmoy Das 		args.start += drm->agp.base + chan->ntfy->offset;
6440dc9b286SNirmoy Das 		args.limit += drm->agp.base + chan->ntfy->offset;
645ebb945a9SBen Skeggs 	} else {
646a01ca78cSBen Skeggs 		args.target = NV_DMA_V0_TARGET_VM;
647a01ca78cSBen Skeggs 		args.access = NV_DMA_V0_ACCESS_RDWR;
6480dc9b286SNirmoy Das 		args.start += chan->ntfy->offset;
6490dc9b286SNirmoy Das 		args.limit += chan->ntfy->offset;
650ebb945a9SBen Skeggs 	}
651ebb945a9SBen Skeggs 
652a01ca78cSBen Skeggs 	client->route = NVDRM_OBJECT_ABI16;
6539ac596a4SBen Skeggs 	ret = nvif_object_ctor(&chan->chan->user, "abi16Ntfy", info->handle,
654a01ca78cSBen Skeggs 			       NV_DMA_IN_MEMORY, &args, sizeof(args),
655a01ca78cSBen Skeggs 			       &ntfy->object);
656a01ca78cSBen Skeggs 	client->route = NVDRM_OBJECT_NVIF;
657ebb945a9SBen Skeggs 	if (ret)
658ebb945a9SBen Skeggs 		goto done;
659ebb945a9SBen Skeggs 
660c1ccaa64SBob Gleitsmann 	info->offset = ntfy->node->offset;
661ebb945a9SBen Skeggs done:
662ebb945a9SBen Skeggs 	if (ret)
663ebb945a9SBen Skeggs 		nouveau_abi16_ntfy_fini(chan, ntfy);
664ebb945a9SBen Skeggs 	return nouveau_abi16_put(abi16, ret);
6652a259a3dSBen Skeggs }
6662a259a3dSBen Skeggs 
6672a259a3dSBen Skeggs int
nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)6682a259a3dSBen Skeggs nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS)
6692a259a3dSBen Skeggs {
670ebb945a9SBen Skeggs 	struct drm_nouveau_gpuobj_free *fini = data;
67109433f24SBen Skeggs 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
672a4e610b5SBen Skeggs 	struct nouveau_abi16_chan *chan;
673ebb945a9SBen Skeggs 	struct nouveau_abi16_ntfy *ntfy;
674a01ca78cSBen Skeggs 	int ret = -ENOENT;
6752a259a3dSBen Skeggs 
676ebb945a9SBen Skeggs 	if (unlikely(!abi16))
677ebb945a9SBen Skeggs 		return -ENOMEM;
6782a259a3dSBen Skeggs 
679a4e610b5SBen Skeggs 	chan = nouveau_abi16_chan(abi16, fini->channel);
680ebb945a9SBen Skeggs 	if (!chan)
681a01ca78cSBen Skeggs 		return nouveau_abi16_put(abi16, -EINVAL);
682ebb945a9SBen Skeggs 
683ebb945a9SBen Skeggs 	/* synchronize with the user channel and destroy the gpu object */
684ebb945a9SBen Skeggs 	nouveau_channel_idle(chan->chan);
685ebb945a9SBen Skeggs 
686ebb945a9SBen Skeggs 	list_for_each_entry(ntfy, &chan->notifiers, head) {
687a01ca78cSBen Skeggs 		if (ntfy->object.handle == fini->handle) {
688a01ca78cSBen Skeggs 			nouveau_abi16_ntfy_fini(chan, ntfy);
689a01ca78cSBen Skeggs 			ret = 0;
690ebb945a9SBen Skeggs 			break;
691ebb945a9SBen Skeggs 		}
692ebb945a9SBen Skeggs 	}
693ebb945a9SBen Skeggs 
694a01ca78cSBen Skeggs 	return nouveau_abi16_put(abi16, ret);
6952a259a3dSBen Skeggs }
696