1 1.6 riastrad /* $NetBSD: nouveau_abi16.c,v 1.6 2021/12/18 23:45:32 riastradh Exp $ */ 2 1.2 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2012 Red Hat Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad */ 25 1.1 riastrad 26 1.2 riastrad #include <sys/cdefs.h> 27 1.6 riastrad __KERNEL_RCSID(0, "$NetBSD: nouveau_abi16.c,v 1.6 2021/12/18 23:45:32 riastradh Exp $"); 28 1.2 riastrad 29 1.3 riastrad #include <nvif/client.h> 30 1.3 riastrad #include <nvif/driver.h> 31 1.6 riastrad #include <nvif/fifo.h> 32 1.3 riastrad #include <nvif/ioctl.h> 33 1.3 riastrad #include <nvif/class.h> 34 1.6 riastrad #include <nvif/cl0002.h> 35 1.6 riastrad #include <nvif/cla06f.h> 36 1.3 riastrad #include <nvif/unpack.h> 37 1.1 riastrad 38 1.6 riastrad #include "nouveau_drv.h" 39 1.1 riastrad #include "nouveau_dma.h" 40 1.1 riastrad #include "nouveau_gem.h" 41 1.1 riastrad #include "nouveau_chan.h" 42 1.1 riastrad #include "nouveau_abi16.h" 43 1.6 riastrad #include "nouveau_vmm.h" 44 1.1 riastrad 45 1.3 riastrad static struct nouveau_abi16 * 46 1.3 riastrad nouveau_abi16(struct drm_file *file_priv) 47 1.1 riastrad { 48 1.1 riastrad struct nouveau_cli *cli = nouveau_cli(file_priv); 49 1.1 riastrad if (!cli->abi16) { 50 1.1 riastrad struct nouveau_abi16 *abi16; 51 1.1 riastrad cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL); 52 1.1 riastrad if (cli->abi16) { 53 1.3 riastrad struct nv_device_v0 args = { 54 1.3 riastrad .device = ~0ULL, 55 1.3 riastrad }; 56 1.3 riastrad 57 1.1 riastrad INIT_LIST_HEAD(&abi16->channels); 58 1.1 riastrad 59 1.1 riastrad /* allocate device object targeting client's default 60 1.1 riastrad * device (ie. the one that belongs to the fd it 61 1.1 riastrad * opened) 62 1.1 riastrad */ 63 1.3 riastrad if (nvif_device_init(&cli->base.object, 0, NV_DEVICE, 64 1.3 riastrad &args, sizeof(args), 65 1.3 riastrad &abi16->device) == 0) 66 1.1 riastrad return cli->abi16; 67 1.1 riastrad 68 1.1 riastrad kfree(cli->abi16); 69 1.1 riastrad cli->abi16 = NULL; 70 1.1 riastrad } 71 1.1 riastrad } 72 1.1 riastrad return cli->abi16; 73 1.1 riastrad } 74 1.1 riastrad 75 1.3 riastrad struct nouveau_abi16 * 76 1.3 riastrad nouveau_abi16_get(struct drm_file *file_priv) 77 1.3 riastrad { 78 1.3 riastrad struct nouveau_cli *cli = nouveau_cli(file_priv); 79 1.3 riastrad mutex_lock(&cli->mutex); 80 1.3 riastrad if (nouveau_abi16(file_priv)) 81 1.3 riastrad return cli->abi16; 82 1.3 riastrad mutex_unlock(&cli->mutex); 83 1.3 riastrad return NULL; 84 1.3 riastrad } 85 1.3 riastrad 86 1.1 riastrad int 87 1.1 riastrad nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret) 88 1.1 riastrad { 89 1.3 riastrad struct nouveau_cli *cli = (void *)abi16->device.object.client; 90 1.1 riastrad mutex_unlock(&cli->mutex); 91 1.1 riastrad return ret; 92 1.1 riastrad } 93 1.1 riastrad 94 1.3 riastrad s32 95 1.1 riastrad nouveau_abi16_swclass(struct nouveau_drm *drm) 96 1.1 riastrad { 97 1.6 riastrad switch (drm->client.device.info.family) { 98 1.3 riastrad case NV_DEVICE_INFO_V0_TNT: 99 1.6 riastrad return NVIF_CLASS_SW_NV04; 100 1.3 riastrad case NV_DEVICE_INFO_V0_CELSIUS: 101 1.3 riastrad case NV_DEVICE_INFO_V0_KELVIN: 102 1.3 riastrad case NV_DEVICE_INFO_V0_RANKINE: 103 1.3 riastrad case NV_DEVICE_INFO_V0_CURIE: 104 1.6 riastrad return NVIF_CLASS_SW_NV10; 105 1.3 riastrad case NV_DEVICE_INFO_V0_TESLA: 106 1.6 riastrad return NVIF_CLASS_SW_NV50; 107 1.3 riastrad case NV_DEVICE_INFO_V0_FERMI: 108 1.3 riastrad case NV_DEVICE_INFO_V0_KEPLER: 109 1.3 riastrad case NV_DEVICE_INFO_V0_MAXWELL: 110 1.6 riastrad case NV_DEVICE_INFO_V0_PASCAL: 111 1.6 riastrad case NV_DEVICE_INFO_V0_VOLTA: 112 1.6 riastrad return NVIF_CLASS_SW_GF100; 113 1.1 riastrad } 114 1.1 riastrad 115 1.1 riastrad return 0x0000; 116 1.1 riastrad } 117 1.1 riastrad 118 1.1 riastrad static void 119 1.1 riastrad nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan, 120 1.1 riastrad struct nouveau_abi16_ntfy *ntfy) 121 1.1 riastrad { 122 1.3 riastrad nvif_object_fini(&ntfy->object); 123 1.3 riastrad nvkm_mm_free(&chan->heap, &ntfy->node); 124 1.1 riastrad list_del(&ntfy->head); 125 1.1 riastrad kfree(ntfy); 126 1.1 riastrad } 127 1.1 riastrad 128 1.1 riastrad static void 129 1.1 riastrad nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16, 130 1.1 riastrad struct nouveau_abi16_chan *chan) 131 1.1 riastrad { 132 1.1 riastrad struct nouveau_abi16_ntfy *ntfy, *temp; 133 1.1 riastrad 134 1.1 riastrad /* wait for all activity to stop before releasing notify object, which 135 1.1 riastrad * may be still in use */ 136 1.1 riastrad if (chan->chan && chan->ntfy) 137 1.1 riastrad nouveau_channel_idle(chan->chan); 138 1.1 riastrad 139 1.1 riastrad /* cleanup notifier state */ 140 1.1 riastrad list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) { 141 1.1 riastrad nouveau_abi16_ntfy_fini(chan, ntfy); 142 1.1 riastrad } 143 1.1 riastrad 144 1.1 riastrad if (chan->ntfy) { 145 1.6 riastrad nouveau_vma_del(&chan->ntfy_vma); 146 1.1 riastrad nouveau_bo_unpin(chan->ntfy); 147 1.6 riastrad drm_gem_object_put_unlocked(&chan->ntfy->bo.base); 148 1.1 riastrad } 149 1.1 riastrad 150 1.1 riastrad if (chan->heap.block_size) 151 1.3 riastrad nvkm_mm_fini(&chan->heap); 152 1.1 riastrad 153 1.1 riastrad /* destroy channel object, all children will be killed too */ 154 1.1 riastrad if (chan->chan) { 155 1.3 riastrad nouveau_channel_idle(chan->chan); 156 1.1 riastrad nouveau_channel_del(&chan->chan); 157 1.1 riastrad } 158 1.1 riastrad 159 1.1 riastrad list_del(&chan->head); 160 1.1 riastrad kfree(chan); 161 1.1 riastrad } 162 1.1 riastrad 163 1.1 riastrad void 164 1.1 riastrad nouveau_abi16_fini(struct nouveau_abi16 *abi16) 165 1.1 riastrad { 166 1.3 riastrad struct nouveau_cli *cli = (void *)abi16->device.object.client; 167 1.1 riastrad struct nouveau_abi16_chan *chan, *temp; 168 1.1 riastrad 169 1.1 riastrad /* cleanup channels */ 170 1.1 riastrad list_for_each_entry_safe(chan, temp, &abi16->channels, head) { 171 1.1 riastrad nouveau_abi16_chan_fini(abi16, chan); 172 1.1 riastrad } 173 1.1 riastrad 174 1.1 riastrad /* destroy the device object */ 175 1.3 riastrad nvif_device_fini(&abi16->device); 176 1.1 riastrad 177 1.1 riastrad kfree(cli->abi16); 178 1.1 riastrad cli->abi16 = NULL; 179 1.1 riastrad } 180 1.1 riastrad 181 1.1 riastrad int 182 1.1 riastrad nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) 183 1.1 riastrad { 184 1.3 riastrad struct nouveau_cli *cli = nouveau_cli(file_priv); 185 1.1 riastrad struct nouveau_drm *drm = nouveau_drm(dev); 186 1.6 riastrad struct nvif_device *device = &drm->client.device; 187 1.3 riastrad struct nvkm_gr *gr = nvxx_gr(device); 188 1.1 riastrad struct drm_nouveau_getparam *getparam = data; 189 1.1 riastrad 190 1.1 riastrad switch (getparam->param) { 191 1.1 riastrad case NOUVEAU_GETPARAM_CHIPSET_ID: 192 1.3 riastrad getparam->value = device->info.chipset; 193 1.1 riastrad break; 194 1.1 riastrad case NOUVEAU_GETPARAM_PCI_VENDOR: 195 1.6 riastrad if (device->info.platform != NV_DEVICE_INFO_V0_SOC) 196 1.1 riastrad getparam->value = dev->pdev->vendor; 197 1.1 riastrad else 198 1.1 riastrad getparam->value = 0; 199 1.1 riastrad break; 200 1.1 riastrad case NOUVEAU_GETPARAM_PCI_DEVICE: 201 1.6 riastrad if (device->info.platform != NV_DEVICE_INFO_V0_SOC) 202 1.1 riastrad getparam->value = dev->pdev->device; 203 1.1 riastrad else 204 1.1 riastrad getparam->value = 0; 205 1.1 riastrad break; 206 1.1 riastrad case NOUVEAU_GETPARAM_BUS_TYPE: 207 1.6 riastrad switch (device->info.platform) { 208 1.6 riastrad case NV_DEVICE_INFO_V0_AGP : getparam->value = 0; break; 209 1.6 riastrad case NV_DEVICE_INFO_V0_PCI : getparam->value = 1; break; 210 1.6 riastrad case NV_DEVICE_INFO_V0_PCIE: getparam->value = 2; break; 211 1.6 riastrad case NV_DEVICE_INFO_V0_SOC : getparam->value = 3; break; 212 1.6 riastrad case NV_DEVICE_INFO_V0_IGP : 213 1.6 riastrad if (!pci_is_pcie(dev->pdev)) 214 1.6 riastrad getparam->value = 1; 215 1.6 riastrad else 216 1.6 riastrad getparam->value = 2; 217 1.6 riastrad break; 218 1.6 riastrad default: 219 1.6 riastrad WARN_ON(1); 220 1.6 riastrad break; 221 1.6 riastrad } 222 1.1 riastrad break; 223 1.1 riastrad case NOUVEAU_GETPARAM_FB_SIZE: 224 1.1 riastrad getparam->value = drm->gem.vram_available; 225 1.1 riastrad break; 226 1.1 riastrad case NOUVEAU_GETPARAM_AGP_SIZE: 227 1.1 riastrad getparam->value = drm->gem.gart_available; 228 1.1 riastrad break; 229 1.1 riastrad case NOUVEAU_GETPARAM_VM_VRAM_BASE: 230 1.1 riastrad getparam->value = 0; /* deprecated */ 231 1.1 riastrad break; 232 1.1 riastrad case NOUVEAU_GETPARAM_PTIMER_TIME: 233 1.3 riastrad getparam->value = nvif_device_time(device); 234 1.1 riastrad break; 235 1.1 riastrad case NOUVEAU_GETPARAM_HAS_BO_USAGE: 236 1.1 riastrad getparam->value = 1; 237 1.1 riastrad break; 238 1.1 riastrad case NOUVEAU_GETPARAM_HAS_PAGEFLIP: 239 1.1 riastrad getparam->value = 1; 240 1.1 riastrad break; 241 1.1 riastrad case NOUVEAU_GETPARAM_GRAPH_UNITS: 242 1.3 riastrad getparam->value = nvkm_gr_units(gr); 243 1.1 riastrad break; 244 1.1 riastrad default: 245 1.3 riastrad NV_PRINTK(dbg, cli, "unknown parameter %"PRId64"\n", getparam->param); 246 1.1 riastrad return -EINVAL; 247 1.1 riastrad } 248 1.1 riastrad 249 1.1 riastrad return 0; 250 1.1 riastrad } 251 1.1 riastrad 252 1.1 riastrad int 253 1.1 riastrad nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS) 254 1.1 riastrad { 255 1.1 riastrad struct drm_nouveau_channel_alloc *init = data; 256 1.1 riastrad struct nouveau_cli *cli = nouveau_cli(file_priv); 257 1.1 riastrad struct nouveau_drm *drm = nouveau_drm(dev); 258 1.3 riastrad struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 259 1.1 riastrad struct nouveau_abi16_chan *chan; 260 1.3 riastrad struct nvif_device *device; 261 1.6 riastrad u64 engine; 262 1.1 riastrad int ret; 263 1.1 riastrad 264 1.1 riastrad if (unlikely(!abi16)) 265 1.1 riastrad return -ENOMEM; 266 1.1 riastrad 267 1.1 riastrad if (!drm->channel) 268 1.1 riastrad return nouveau_abi16_put(abi16, -ENODEV); 269 1.1 riastrad 270 1.3 riastrad device = &abi16->device; 271 1.1 riastrad 272 1.1 riastrad /* hack to allow channel engine type specification on kepler */ 273 1.3 riastrad if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) { 274 1.6 riastrad if (init->fb_ctxdma_handle == ~0) { 275 1.6 riastrad switch (init->tt_ctxdma_handle) { 276 1.6 riastrad case 0x01: engine = NV_DEVICE_INFO_ENGINE_GR ; break; 277 1.6 riastrad case 0x02: engine = NV_DEVICE_INFO_ENGINE_MSPDEC; break; 278 1.6 riastrad case 0x04: engine = NV_DEVICE_INFO_ENGINE_MSPPP ; break; 279 1.6 riastrad case 0x08: engine = NV_DEVICE_INFO_ENGINE_MSVLD ; break; 280 1.6 riastrad case 0x30: engine = NV_DEVICE_INFO_ENGINE_CE ; break; 281 1.6 riastrad default: 282 1.6 riastrad return nouveau_abi16_put(abi16, -ENOSYS); 283 1.6 riastrad } 284 1.6 riastrad } else { 285 1.6 riastrad engine = NV_DEVICE_INFO_ENGINE_GR; 286 1.6 riastrad } 287 1.6 riastrad 288 1.6 riastrad if (engine != NV_DEVICE_INFO_ENGINE_CE) 289 1.6 riastrad engine = nvif_fifo_runlist(device, engine); 290 1.1 riastrad else 291 1.6 riastrad engine = nvif_fifo_runlist_ce(device); 292 1.6 riastrad init->fb_ctxdma_handle = engine; 293 1.1 riastrad init->tt_ctxdma_handle = 0; 294 1.1 riastrad } 295 1.1 riastrad 296 1.1 riastrad if (init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0) 297 1.1 riastrad return nouveau_abi16_put(abi16, -EINVAL); 298 1.1 riastrad 299 1.1 riastrad /* allocate "abi16 channel" data and make up a handle for it */ 300 1.1 riastrad chan = kzalloc(sizeof(*chan), GFP_KERNEL); 301 1.1 riastrad if (!chan) 302 1.1 riastrad return nouveau_abi16_put(abi16, -ENOMEM); 303 1.1 riastrad 304 1.1 riastrad INIT_LIST_HEAD(&chan->notifiers); 305 1.1 riastrad list_add(&chan->head, &abi16->channels); 306 1.1 riastrad 307 1.1 riastrad /* create channel object and initialise dma and fence management */ 308 1.3 riastrad ret = nouveau_channel_new(drm, device, init->fb_ctxdma_handle, 309 1.6 riastrad init->tt_ctxdma_handle, false, &chan->chan); 310 1.1 riastrad if (ret) 311 1.1 riastrad goto done; 312 1.1 riastrad 313 1.3 riastrad init->channel = chan->chan->chid; 314 1.3 riastrad 315 1.3 riastrad if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) 316 1.1 riastrad init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM | 317 1.1 riastrad NOUVEAU_GEM_DOMAIN_GART; 318 1.1 riastrad else 319 1.1 riastrad if (chan->chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM) 320 1.1 riastrad init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM; 321 1.1 riastrad else 322 1.1 riastrad init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART; 323 1.1 riastrad 324 1.3 riastrad if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) { 325 1.1 riastrad init->subchan[0].handle = 0x00000000; 326 1.1 riastrad init->subchan[0].grclass = 0x0000; 327 1.3 riastrad init->subchan[1].handle = chan->chan->nvsw.handle; 328 1.1 riastrad init->subchan[1].grclass = 0x506e; 329 1.1 riastrad init->nr_subchan = 2; 330 1.1 riastrad } 331 1.1 riastrad 332 1.1 riastrad /* Named memory object area */ 333 1.6 riastrad ret = nouveau_gem_new(cli, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART, 334 1.1 riastrad 0, 0, &chan->ntfy); 335 1.1 riastrad if (ret == 0) 336 1.3 riastrad ret = nouveau_bo_pin(chan->ntfy, TTM_PL_FLAG_TT, false); 337 1.1 riastrad if (ret) 338 1.1 riastrad goto done; 339 1.1 riastrad 340 1.3 riastrad if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { 341 1.6 riastrad ret = nouveau_vma_new(chan->ntfy, chan->chan->vmm, 342 1.6 riastrad &chan->ntfy_vma); 343 1.1 riastrad if (ret) 344 1.1 riastrad goto done; 345 1.1 riastrad } 346 1.1 riastrad 347 1.6 riastrad ret = drm_gem_handle_create(file_priv, &chan->ntfy->bo.base, 348 1.1 riastrad &init->notifier_handle); 349 1.1 riastrad if (ret) 350 1.1 riastrad goto done; 351 1.1 riastrad 352 1.6 riastrad ret = nvkm_mm_init(&chan->heap, 0, 0, PAGE_SIZE, 1); 353 1.1 riastrad done: 354 1.1 riastrad if (ret) 355 1.1 riastrad nouveau_abi16_chan_fini(abi16, chan); 356 1.1 riastrad return nouveau_abi16_put(abi16, ret); 357 1.1 riastrad } 358 1.1 riastrad 359 1.3 riastrad static struct nouveau_abi16_chan * 360 1.3 riastrad nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel) 361 1.3 riastrad { 362 1.3 riastrad struct nouveau_abi16_chan *chan; 363 1.3 riastrad 364 1.3 riastrad list_for_each_entry(chan, &abi16->channels, head) { 365 1.3 riastrad if (chan->chan->chid == channel) 366 1.3 riastrad return chan; 367 1.3 riastrad } 368 1.3 riastrad 369 1.3 riastrad return NULL; 370 1.3 riastrad } 371 1.3 riastrad 372 1.3 riastrad int 373 1.3 riastrad nouveau_abi16_usif(struct drm_file *file_priv, void *data, u32 size) 374 1.3 riastrad { 375 1.3 riastrad union { 376 1.3 riastrad struct nvif_ioctl_v0 v0; 377 1.3 riastrad } *args = data; 378 1.3 riastrad struct nouveau_abi16_chan *chan; 379 1.3 riastrad struct nouveau_abi16 *abi16; 380 1.6 riastrad int ret = -ENOSYS; 381 1.3 riastrad 382 1.6 riastrad if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) { 383 1.3 riastrad switch (args->v0.type) { 384 1.3 riastrad case NVIF_IOCTL_V0_NEW: 385 1.3 riastrad case NVIF_IOCTL_V0_MTHD: 386 1.3 riastrad case NVIF_IOCTL_V0_SCLASS: 387 1.3 riastrad break; 388 1.3 riastrad default: 389 1.3 riastrad return -EACCES; 390 1.3 riastrad } 391 1.3 riastrad } else 392 1.3 riastrad return ret; 393 1.3 riastrad 394 1.3 riastrad if (!(abi16 = nouveau_abi16(file_priv))) 395 1.3 riastrad return -ENOMEM; 396 1.3 riastrad 397 1.3 riastrad if (args->v0.token != ~0ULL) { 398 1.3 riastrad if (!(chan = nouveau_abi16_chan(abi16, args->v0.token))) 399 1.3 riastrad return -EINVAL; 400 1.3 riastrad args->v0.object = nvif_handle(&chan->chan->user); 401 1.3 riastrad args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY; 402 1.3 riastrad return 0; 403 1.3 riastrad } 404 1.3 riastrad 405 1.3 riastrad args->v0.object = nvif_handle(&abi16->device.object); 406 1.3 riastrad args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY; 407 1.3 riastrad return 0; 408 1.3 riastrad } 409 1.1 riastrad 410 1.1 riastrad int 411 1.1 riastrad nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS) 412 1.1 riastrad { 413 1.1 riastrad struct drm_nouveau_channel_free *req = data; 414 1.3 riastrad struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 415 1.1 riastrad struct nouveau_abi16_chan *chan; 416 1.1 riastrad 417 1.1 riastrad if (unlikely(!abi16)) 418 1.1 riastrad return -ENOMEM; 419 1.1 riastrad 420 1.3 riastrad chan = nouveau_abi16_chan(abi16, req->channel); 421 1.3 riastrad if (!chan) 422 1.3 riastrad return nouveau_abi16_put(abi16, -ENOENT); 423 1.3 riastrad nouveau_abi16_chan_fini(abi16, chan); 424 1.3 riastrad return nouveau_abi16_put(abi16, 0); 425 1.1 riastrad } 426 1.1 riastrad 427 1.1 riastrad int 428 1.1 riastrad nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS) 429 1.1 riastrad { 430 1.1 riastrad struct drm_nouveau_grobj_alloc *init = data; 431 1.3 riastrad struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 432 1.3 riastrad struct nouveau_abi16_chan *chan; 433 1.3 riastrad struct nouveau_abi16_ntfy *ntfy; 434 1.3 riastrad struct nvif_client *client; 435 1.3 riastrad struct nvif_sclass *sclass; 436 1.3 riastrad s32 oclass = 0; 437 1.3 riastrad int ret, i; 438 1.1 riastrad 439 1.1 riastrad if (unlikely(!abi16)) 440 1.1 riastrad return -ENOMEM; 441 1.1 riastrad 442 1.1 riastrad if (init->handle == ~0) 443 1.1 riastrad return nouveau_abi16_put(abi16, -EINVAL); 444 1.3 riastrad client = abi16->device.object.client; 445 1.3 riastrad 446 1.3 riastrad chan = nouveau_abi16_chan(abi16, init->channel); 447 1.3 riastrad if (!chan) 448 1.3 riastrad return nouveau_abi16_put(abi16, -ENOENT); 449 1.1 riastrad 450 1.3 riastrad ret = nvif_object_sclass_get(&chan->chan->user, &sclass); 451 1.3 riastrad if (ret < 0) 452 1.3 riastrad return nouveau_abi16_put(abi16, ret); 453 1.3 riastrad 454 1.3 riastrad if ((init->class & 0x00ff) == 0x006e) { 455 1.3 riastrad /* nvsw: compatibility with older 0x*6e class identifier */ 456 1.3 riastrad for (i = 0; !oclass && i < ret; i++) { 457 1.3 riastrad switch (sclass[i].oclass) { 458 1.6 riastrad case NVIF_CLASS_SW_NV04: 459 1.6 riastrad case NVIF_CLASS_SW_NV10: 460 1.6 riastrad case NVIF_CLASS_SW_NV50: 461 1.6 riastrad case NVIF_CLASS_SW_GF100: 462 1.3 riastrad oclass = sclass[i].oclass; 463 1.3 riastrad break; 464 1.3 riastrad default: 465 1.3 riastrad break; 466 1.3 riastrad } 467 1.3 riastrad } 468 1.3 riastrad } else 469 1.3 riastrad if ((init->class & 0x00ff) == 0x00b1) { 470 1.3 riastrad /* msvld: compatibility with incorrect version exposure */ 471 1.3 riastrad for (i = 0; i < ret; i++) { 472 1.3 riastrad if ((sclass[i].oclass & 0x00ff) == 0x00b1) { 473 1.3 riastrad oclass = sclass[i].oclass; 474 1.3 riastrad break; 475 1.3 riastrad } 476 1.3 riastrad } 477 1.3 riastrad } else 478 1.3 riastrad if ((init->class & 0x00ff) == 0x00b2) { /* mspdec */ 479 1.3 riastrad /* mspdec: compatibility with incorrect version exposure */ 480 1.3 riastrad for (i = 0; i < ret; i++) { 481 1.3 riastrad if ((sclass[i].oclass & 0x00ff) == 0x00b2) { 482 1.3 riastrad oclass = sclass[i].oclass; 483 1.3 riastrad break; 484 1.3 riastrad } 485 1.3 riastrad } 486 1.3 riastrad } else 487 1.3 riastrad if ((init->class & 0x00ff) == 0x00b3) { /* msppp */ 488 1.3 riastrad /* msppp: compatibility with incorrect version exposure */ 489 1.3 riastrad for (i = 0; i < ret; i++) { 490 1.3 riastrad if ((sclass[i].oclass & 0x00ff) == 0x00b3) { 491 1.3 riastrad oclass = sclass[i].oclass; 492 1.3 riastrad break; 493 1.3 riastrad } 494 1.3 riastrad } 495 1.3 riastrad } else { 496 1.3 riastrad oclass = init->class; 497 1.1 riastrad } 498 1.1 riastrad 499 1.3 riastrad nvif_object_sclass_put(&sclass); 500 1.3 riastrad if (!oclass) 501 1.3 riastrad return nouveau_abi16_put(abi16, -EINVAL); 502 1.3 riastrad 503 1.3 riastrad ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL); 504 1.3 riastrad if (!ntfy) 505 1.3 riastrad return nouveau_abi16_put(abi16, -ENOMEM); 506 1.3 riastrad 507 1.3 riastrad list_add(&ntfy->head, &chan->notifiers); 508 1.3 riastrad 509 1.3 riastrad client->route = NVDRM_OBJECT_ABI16; 510 1.3 riastrad ret = nvif_object_init(&chan->chan->user, init->handle, oclass, 511 1.3 riastrad NULL, 0, &ntfy->object); 512 1.3 riastrad client->route = NVDRM_OBJECT_NVIF; 513 1.3 riastrad 514 1.3 riastrad if (ret) 515 1.3 riastrad nouveau_abi16_ntfy_fini(chan, ntfy); 516 1.1 riastrad return nouveau_abi16_put(abi16, ret); 517 1.1 riastrad } 518 1.1 riastrad 519 1.1 riastrad int 520 1.1 riastrad nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS) 521 1.1 riastrad { 522 1.1 riastrad struct drm_nouveau_notifierobj_alloc *info = data; 523 1.1 riastrad struct nouveau_drm *drm = nouveau_drm(dev); 524 1.3 riastrad struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 525 1.3 riastrad struct nouveau_abi16_chan *chan; 526 1.1 riastrad struct nouveau_abi16_ntfy *ntfy; 527 1.3 riastrad struct nvif_device *device = &abi16->device; 528 1.3 riastrad struct nvif_client *client; 529 1.5 riastrad struct nv_dma_v0 args = {}; 530 1.1 riastrad int ret; 531 1.1 riastrad 532 1.1 riastrad if (unlikely(!abi16)) 533 1.1 riastrad return -ENOMEM; 534 1.1 riastrad 535 1.1 riastrad /* completely unnecessary for these chipsets... */ 536 1.3 riastrad if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI)) 537 1.1 riastrad return nouveau_abi16_put(abi16, -EINVAL); 538 1.3 riastrad client = abi16->device.object.client; 539 1.1 riastrad 540 1.3 riastrad chan = nouveau_abi16_chan(abi16, info->channel); 541 1.1 riastrad if (!chan) 542 1.1 riastrad return nouveau_abi16_put(abi16, -ENOENT); 543 1.1 riastrad 544 1.1 riastrad ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL); 545 1.1 riastrad if (!ntfy) 546 1.1 riastrad return nouveau_abi16_put(abi16, -ENOMEM); 547 1.1 riastrad 548 1.1 riastrad list_add(&ntfy->head, &chan->notifiers); 549 1.1 riastrad 550 1.3 riastrad ret = nvkm_mm_head(&chan->heap, 0, 1, info->size, info->size, 1, 551 1.3 riastrad &ntfy->node); 552 1.1 riastrad if (ret) 553 1.1 riastrad goto done; 554 1.1 riastrad 555 1.1 riastrad args.start = ntfy->node->offset; 556 1.1 riastrad args.limit = ntfy->node->offset + ntfy->node->length - 1; 557 1.3 riastrad if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { 558 1.3 riastrad args.target = NV_DMA_V0_TARGET_VM; 559 1.3 riastrad args.access = NV_DMA_V0_ACCESS_VM; 560 1.6 riastrad args.start += chan->ntfy_vma->addr; 561 1.6 riastrad args.limit += chan->ntfy_vma->addr; 562 1.1 riastrad } else 563 1.3 riastrad if (drm->agp.bridge) { 564 1.3 riastrad args.target = NV_DMA_V0_TARGET_AGP; 565 1.3 riastrad args.access = NV_DMA_V0_ACCESS_RDWR; 566 1.1 riastrad args.start += drm->agp.base + chan->ntfy->bo.offset; 567 1.1 riastrad args.limit += drm->agp.base + chan->ntfy->bo.offset; 568 1.1 riastrad } else { 569 1.3 riastrad args.target = NV_DMA_V0_TARGET_VM; 570 1.3 riastrad args.access = NV_DMA_V0_ACCESS_RDWR; 571 1.1 riastrad args.start += chan->ntfy->bo.offset; 572 1.1 riastrad args.limit += chan->ntfy->bo.offset; 573 1.1 riastrad } 574 1.1 riastrad 575 1.3 riastrad client->route = NVDRM_OBJECT_ABI16; 576 1.3 riastrad client->super = true; 577 1.3 riastrad ret = nvif_object_init(&chan->chan->user, info->handle, 578 1.3 riastrad NV_DMA_IN_MEMORY, &args, sizeof(args), 579 1.3 riastrad &ntfy->object); 580 1.3 riastrad client->super = false; 581 1.3 riastrad client->route = NVDRM_OBJECT_NVIF; 582 1.1 riastrad if (ret) 583 1.1 riastrad goto done; 584 1.1 riastrad 585 1.1 riastrad info->offset = ntfy->node->offset; 586 1.1 riastrad done: 587 1.1 riastrad if (ret) 588 1.1 riastrad nouveau_abi16_ntfy_fini(chan, ntfy); 589 1.1 riastrad return nouveau_abi16_put(abi16, ret); 590 1.1 riastrad } 591 1.1 riastrad 592 1.1 riastrad int 593 1.1 riastrad nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS) 594 1.1 riastrad { 595 1.1 riastrad struct drm_nouveau_gpuobj_free *fini = data; 596 1.3 riastrad struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 597 1.3 riastrad struct nouveau_abi16_chan *chan; 598 1.1 riastrad struct nouveau_abi16_ntfy *ntfy; 599 1.3 riastrad int ret = -ENOENT; 600 1.1 riastrad 601 1.1 riastrad if (unlikely(!abi16)) 602 1.1 riastrad return -ENOMEM; 603 1.1 riastrad 604 1.3 riastrad chan = nouveau_abi16_chan(abi16, fini->channel); 605 1.1 riastrad if (!chan) 606 1.3 riastrad return nouveau_abi16_put(abi16, -EINVAL); 607 1.1 riastrad 608 1.1 riastrad /* synchronize with the user channel and destroy the gpu object */ 609 1.1 riastrad nouveau_channel_idle(chan->chan); 610 1.1 riastrad 611 1.1 riastrad list_for_each_entry(ntfy, &chan->notifiers, head) { 612 1.3 riastrad if (ntfy->object.handle == fini->handle) { 613 1.3 riastrad nouveau_abi16_ntfy_fini(chan, ntfy); 614 1.3 riastrad ret = 0; 615 1.1 riastrad break; 616 1.1 riastrad } 617 1.1 riastrad } 618 1.1 riastrad 619 1.3 riastrad return nouveau_abi16_put(abi16, ret); 620 1.1 riastrad } 621