1b88baab8SDanilo Krummrich // SPDX-License-Identifier: MIT 2b88baab8SDanilo Krummrich 3b88baab8SDanilo Krummrich #include "nouveau_drv.h" 4b88baab8SDanilo Krummrich #include "nouveau_gem.h" 5b88baab8SDanilo Krummrich #include "nouveau_mem.h" 6b88baab8SDanilo Krummrich #include "nouveau_dma.h" 7b88baab8SDanilo Krummrich #include "nouveau_exec.h" 8b88baab8SDanilo Krummrich #include "nouveau_abi16.h" 9b88baab8SDanilo Krummrich #include "nouveau_chan.h" 10b88baab8SDanilo Krummrich #include "nouveau_sched.h" 11b88baab8SDanilo Krummrich #include "nouveau_uvmm.h" 12b88baab8SDanilo Krummrich 13b88baab8SDanilo Krummrich /** 14b88baab8SDanilo Krummrich * DOC: Overview 15b88baab8SDanilo Krummrich * 16b88baab8SDanilo Krummrich * Nouveau's VM_BIND / EXEC UAPI consists of three ioctls: DRM_NOUVEAU_VM_INIT, 17b88baab8SDanilo Krummrich * DRM_NOUVEAU_VM_BIND and DRM_NOUVEAU_EXEC. 18b88baab8SDanilo Krummrich * 19b88baab8SDanilo Krummrich * In order to use the UAPI firstly a user client must initialize the VA space 20b88baab8SDanilo Krummrich * using the DRM_NOUVEAU_VM_INIT ioctl specifying which region of the VA space 21b88baab8SDanilo Krummrich * should be managed by the kernel and which by the UMD. 22b88baab8SDanilo Krummrich * 23b88baab8SDanilo Krummrich * The DRM_NOUVEAU_VM_BIND ioctl provides clients an interface to manage the 24b88baab8SDanilo Krummrich * userspace-managable portion of the VA space. It provides operations to map 25b88baab8SDanilo Krummrich * and unmap memory. Mappings may be flagged as sparse. Sparse mappings are not 26b88baab8SDanilo Krummrich * backed by a GEM object and the kernel will ignore GEM handles provided 27b88baab8SDanilo Krummrich * alongside a sparse mapping. 28b88baab8SDanilo Krummrich * 29b88baab8SDanilo Krummrich * Userspace may request memory backed mappings either within or outside of the 30b88baab8SDanilo Krummrich * bounds (but not crossing those bounds) of a previously mapped sparse 31b88baab8SDanilo Krummrich * mapping. Subsequently requested memory backed mappings within a sparse 32b88baab8SDanilo Krummrich * mapping will take precedence over the corresponding range of the sparse 33b88baab8SDanilo Krummrich * mapping. If such memory backed mappings are unmapped the kernel will make 34b88baab8SDanilo Krummrich * sure that the corresponding sparse mapping will take their place again. 35b88baab8SDanilo Krummrich * Requests to unmap a sparse mapping that still contains memory backed mappings 36b88baab8SDanilo Krummrich * will result in those memory backed mappings being unmapped first. 37b88baab8SDanilo Krummrich * 38b88baab8SDanilo Krummrich * Unmap requests are not bound to the range of existing mappings and can even 39b88baab8SDanilo Krummrich * overlap the bounds of sparse mappings. For such a request the kernel will 40b88baab8SDanilo Krummrich * make sure to unmap all memory backed mappings within the given range, 41b88baab8SDanilo Krummrich * splitting up memory backed mappings which are only partially contained 42b88baab8SDanilo Krummrich * within the given range. Unmap requests with the sparse flag set must match 43b88baab8SDanilo Krummrich * the range of a previously mapped sparse mapping exactly though. 44b88baab8SDanilo Krummrich * 45b88baab8SDanilo Krummrich * While the kernel generally permits arbitrary sequences and ranges of memory 46b88baab8SDanilo Krummrich * backed mappings being mapped and unmapped, either within a single or multiple 47b88baab8SDanilo Krummrich * VM_BIND ioctl calls, there are some restrictions for sparse mappings. 48b88baab8SDanilo Krummrich * 49b88baab8SDanilo Krummrich * The kernel does not permit to: 50b88baab8SDanilo Krummrich * - unmap non-existent sparse mappings 51b88baab8SDanilo Krummrich * - unmap a sparse mapping and map a new sparse mapping overlapping the range 52b88baab8SDanilo Krummrich * of the previously unmapped sparse mapping within the same VM_BIND ioctl 53b88baab8SDanilo Krummrich * - unmap a sparse mapping and map new memory backed mappings overlapping the 54b88baab8SDanilo Krummrich * range of the previously unmapped sparse mapping within the same VM_BIND 55b88baab8SDanilo Krummrich * ioctl 56b88baab8SDanilo Krummrich * 57b88baab8SDanilo Krummrich * When using the VM_BIND ioctl to request the kernel to map memory to a given 58b88baab8SDanilo Krummrich * virtual address in the GPU's VA space there is no guarantee that the actual 59b88baab8SDanilo Krummrich * mappings are created in the GPU's MMU. If the given memory is swapped out 60b88baab8SDanilo Krummrich * at the time the bind operation is executed the kernel will stash the mapping 61b88baab8SDanilo Krummrich * details into it's internal alloctor and create the actual MMU mappings once 62b88baab8SDanilo Krummrich * the memory is swapped back in. While this is transparent for userspace, it is 63b88baab8SDanilo Krummrich * guaranteed that all the backing memory is swapped back in and all the memory 64b88baab8SDanilo Krummrich * mappings, as requested by userspace previously, are actually mapped once the 65b88baab8SDanilo Krummrich * DRM_NOUVEAU_EXEC ioctl is called to submit an exec job. 66b88baab8SDanilo Krummrich * 67b88baab8SDanilo Krummrich * A VM_BIND job can be executed either synchronously or asynchronously. If 68b88baab8SDanilo Krummrich * exectued asynchronously, userspace may provide a list of syncobjs this job 69b88baab8SDanilo Krummrich * will wait for and/or a list of syncobj the kernel will signal once the 70b88baab8SDanilo Krummrich * VM_BIND job finished execution. If executed synchronously the ioctl will 71b88baab8SDanilo Krummrich * block until the bind job is finished. For synchronous jobs the kernel will 72b88baab8SDanilo Krummrich * not permit any syncobjs submitted to the kernel. 73b88baab8SDanilo Krummrich * 74b88baab8SDanilo Krummrich * To execute a push buffer the UAPI provides the DRM_NOUVEAU_EXEC ioctl. EXEC 75b88baab8SDanilo Krummrich * jobs are always executed asynchronously, and, equal to VM_BIND jobs, provide 76b88baab8SDanilo Krummrich * the option to synchronize them with syncobjs. 77b88baab8SDanilo Krummrich * 78b88baab8SDanilo Krummrich * Besides that, EXEC jobs can be scheduled for a specified channel to execute on. 79b88baab8SDanilo Krummrich * 80b88baab8SDanilo Krummrich * Since VM_BIND jobs update the GPU's VA space on job submit, EXEC jobs do have 81b88baab8SDanilo Krummrich * an up to date view of the VA space. However, the actual mappings might still 82b88baab8SDanilo Krummrich * be pending. Hence, EXEC jobs require to have the particular fences - of 83b88baab8SDanilo Krummrich * the corresponding VM_BIND jobs they depent on - attached to them. 84b88baab8SDanilo Krummrich */ 85b88baab8SDanilo Krummrich 86b88baab8SDanilo Krummrich static int 87*014f831aSDanilo Krummrich nouveau_exec_job_submit(struct nouveau_job *job, 88*014f831aSDanilo Krummrich struct drm_gpuvm_exec *vme) 89b88baab8SDanilo Krummrich { 90b88baab8SDanilo Krummrich struct nouveau_exec_job *exec_job = to_nouveau_exec_job(job); 91b88baab8SDanilo Krummrich struct nouveau_cli *cli = job->cli; 92b88baab8SDanilo Krummrich struct nouveau_uvmm *uvmm = nouveau_cli_uvmm(cli); 93b88baab8SDanilo Krummrich int ret; 94b88baab8SDanilo Krummrich 95978474dcSDanilo Krummrich /* Create a new fence, but do not emit yet. */ 96978474dcSDanilo Krummrich ret = nouveau_fence_create(&exec_job->fence, exec_job->chan); 97b88baab8SDanilo Krummrich if (ret) 98b88baab8SDanilo Krummrich return ret; 99b88baab8SDanilo Krummrich 100b88baab8SDanilo Krummrich nouveau_uvmm_lock(uvmm); 101*014f831aSDanilo Krummrich ret = drm_gpuvm_exec_lock(vme); 102*014f831aSDanilo Krummrich if (ret) { 103*014f831aSDanilo Krummrich nouveau_uvmm_unlock(uvmm); 104*014f831aSDanilo Krummrich return ret; 105b88baab8SDanilo Krummrich } 106b88baab8SDanilo Krummrich nouveau_uvmm_unlock(uvmm); 107b88baab8SDanilo Krummrich 108*014f831aSDanilo Krummrich ret = drm_gpuvm_exec_validate(vme); 109*014f831aSDanilo Krummrich if (ret) { 110*014f831aSDanilo Krummrich drm_gpuvm_exec_unlock(vme); 111*014f831aSDanilo Krummrich return ret; 112b88baab8SDanilo Krummrich } 113b88baab8SDanilo Krummrich 114b88baab8SDanilo Krummrich return 0; 115b88baab8SDanilo Krummrich } 116b88baab8SDanilo Krummrich 117b88baab8SDanilo Krummrich static void 118*014f831aSDanilo Krummrich nouveau_exec_job_armed_submit(struct nouveau_job *job, 119*014f831aSDanilo Krummrich struct drm_gpuvm_exec *vme) 120b88baab8SDanilo Krummrich { 121*014f831aSDanilo Krummrich drm_gpuvm_exec_resv_add_fence(vme, job->done_fence, 122*014f831aSDanilo Krummrich job->resv_usage, job->resv_usage); 123*014f831aSDanilo Krummrich drm_gpuvm_exec_unlock(vme); 124b88baab8SDanilo Krummrich } 125b88baab8SDanilo Krummrich 126b88baab8SDanilo Krummrich static struct dma_fence * 127b88baab8SDanilo Krummrich nouveau_exec_job_run(struct nouveau_job *job) 128b88baab8SDanilo Krummrich { 129b88baab8SDanilo Krummrich struct nouveau_exec_job *exec_job = to_nouveau_exec_job(job); 130b88baab8SDanilo Krummrich struct nouveau_channel *chan = exec_job->chan; 131b88baab8SDanilo Krummrich struct nouveau_fence *fence = exec_job->fence; 132b88baab8SDanilo Krummrich int i, ret; 133b88baab8SDanilo Krummrich 134b88baab8SDanilo Krummrich ret = nouveau_dma_wait(chan, exec_job->push.count + 1, 16); 135b88baab8SDanilo Krummrich if (ret) { 136b88baab8SDanilo Krummrich NV_PRINTK(err, job->cli, "nv50cal_space: %d\n", ret); 137b88baab8SDanilo Krummrich return ERR_PTR(ret); 138b88baab8SDanilo Krummrich } 139b88baab8SDanilo Krummrich 140b88baab8SDanilo Krummrich for (i = 0; i < exec_job->push.count; i++) { 141443f9e0bSDanilo Krummrich struct drm_nouveau_exec_push *p = &exec_job->push.s[i]; 142443f9e0bSDanilo Krummrich bool no_prefetch = p->flags & DRM_NOUVEAU_EXEC_PUSH_NO_PREFETCH; 143443f9e0bSDanilo Krummrich 144443f9e0bSDanilo Krummrich nv50_dma_push(chan, p->va, p->va_len, no_prefetch); 145b88baab8SDanilo Krummrich } 146b88baab8SDanilo Krummrich 147978474dcSDanilo Krummrich ret = nouveau_fence_emit(fence); 148b88baab8SDanilo Krummrich if (ret) { 149978474dcSDanilo Krummrich nouveau_fence_unref(&exec_job->fence); 150b88baab8SDanilo Krummrich NV_PRINTK(err, job->cli, "error fencing pushbuf: %d\n", ret); 151b88baab8SDanilo Krummrich WIND_RING(chan); 152b88baab8SDanilo Krummrich return ERR_PTR(ret); 153b88baab8SDanilo Krummrich } 154b88baab8SDanilo Krummrich 155978474dcSDanilo Krummrich /* The fence was emitted successfully, set the job's fence pointer to 156978474dcSDanilo Krummrich * NULL in order to avoid freeing it up when the job is cleaned up. 157978474dcSDanilo Krummrich */ 158b88baab8SDanilo Krummrich exec_job->fence = NULL; 159b88baab8SDanilo Krummrich 160b88baab8SDanilo Krummrich return &fence->base; 161b88baab8SDanilo Krummrich } 162b88baab8SDanilo Krummrich 163b88baab8SDanilo Krummrich static void 164b88baab8SDanilo Krummrich nouveau_exec_job_free(struct nouveau_job *job) 165b88baab8SDanilo Krummrich { 166b88baab8SDanilo Krummrich struct nouveau_exec_job *exec_job = to_nouveau_exec_job(job); 167b88baab8SDanilo Krummrich 168b88baab8SDanilo Krummrich nouveau_job_free(job); 169b88baab8SDanilo Krummrich 170978474dcSDanilo Krummrich kfree(exec_job->fence); 171b88baab8SDanilo Krummrich kfree(exec_job->push.s); 172b88baab8SDanilo Krummrich kfree(exec_job); 173b88baab8SDanilo Krummrich } 174b88baab8SDanilo Krummrich 175b88baab8SDanilo Krummrich static enum drm_gpu_sched_stat 176b88baab8SDanilo Krummrich nouveau_exec_job_timeout(struct nouveau_job *job) 177b88baab8SDanilo Krummrich { 178b88baab8SDanilo Krummrich struct nouveau_exec_job *exec_job = to_nouveau_exec_job(job); 179b88baab8SDanilo Krummrich struct nouveau_channel *chan = exec_job->chan; 180b88baab8SDanilo Krummrich 181b88baab8SDanilo Krummrich if (unlikely(!atomic_read(&chan->killed))) 182b88baab8SDanilo Krummrich nouveau_channel_kill(chan); 183b88baab8SDanilo Krummrich 184b88baab8SDanilo Krummrich NV_PRINTK(warn, job->cli, "job timeout, channel %d killed!\n", 185b88baab8SDanilo Krummrich chan->chid); 186b88baab8SDanilo Krummrich 187b88baab8SDanilo Krummrich nouveau_sched_entity_fini(job->entity); 188b88baab8SDanilo Krummrich 18931499b01SDanilo Krummrich return DRM_GPU_SCHED_STAT_NOMINAL; 190b88baab8SDanilo Krummrich } 191b88baab8SDanilo Krummrich 192b88baab8SDanilo Krummrich static struct nouveau_job_ops nouveau_exec_job_ops = { 193b88baab8SDanilo Krummrich .submit = nouveau_exec_job_submit, 194b88baab8SDanilo Krummrich .armed_submit = nouveau_exec_job_armed_submit, 195b88baab8SDanilo Krummrich .run = nouveau_exec_job_run, 196b88baab8SDanilo Krummrich .free = nouveau_exec_job_free, 197b88baab8SDanilo Krummrich .timeout = nouveau_exec_job_timeout, 198b88baab8SDanilo Krummrich }; 199b88baab8SDanilo Krummrich 200b88baab8SDanilo Krummrich int 201b88baab8SDanilo Krummrich nouveau_exec_job_init(struct nouveau_exec_job **pjob, 202b88baab8SDanilo Krummrich struct nouveau_exec_job_args *__args) 203b88baab8SDanilo Krummrich { 204b88baab8SDanilo Krummrich struct nouveau_exec_job *job; 205b88baab8SDanilo Krummrich struct nouveau_job_args args = {}; 206443f9e0bSDanilo Krummrich int i, ret; 207443f9e0bSDanilo Krummrich 208443f9e0bSDanilo Krummrich for (i = 0; i < __args->push.count; i++) { 209443f9e0bSDanilo Krummrich struct drm_nouveau_exec_push *p = &__args->push.s[i]; 210443f9e0bSDanilo Krummrich 211443f9e0bSDanilo Krummrich if (unlikely(p->va_len > NV50_DMA_PUSH_MAX_LENGTH)) { 212443f9e0bSDanilo Krummrich NV_PRINTK(err, nouveau_cli(__args->file_priv), 213443f9e0bSDanilo Krummrich "pushbuf size exceeds limit: 0x%x max 0x%x\n", 214443f9e0bSDanilo Krummrich p->va_len, NV50_DMA_PUSH_MAX_LENGTH); 215443f9e0bSDanilo Krummrich return -EINVAL; 216443f9e0bSDanilo Krummrich } 217443f9e0bSDanilo Krummrich } 218b88baab8SDanilo Krummrich 219b88baab8SDanilo Krummrich job = *pjob = kzalloc(sizeof(*job), GFP_KERNEL); 220b88baab8SDanilo Krummrich if (!job) 221b88baab8SDanilo Krummrich return -ENOMEM; 222b88baab8SDanilo Krummrich 223b88baab8SDanilo Krummrich job->push.count = __args->push.count; 224b88baab8SDanilo Krummrich if (__args->push.count) { 225b88baab8SDanilo Krummrich job->push.s = kmemdup(__args->push.s, 226b88baab8SDanilo Krummrich sizeof(*__args->push.s) * 227b88baab8SDanilo Krummrich __args->push.count, 228b88baab8SDanilo Krummrich GFP_KERNEL); 229b88baab8SDanilo Krummrich if (!job->push.s) { 230b88baab8SDanilo Krummrich ret = -ENOMEM; 231b88baab8SDanilo Krummrich goto err_free_job; 232b88baab8SDanilo Krummrich } 233b88baab8SDanilo Krummrich } 234b88baab8SDanilo Krummrich 235b88baab8SDanilo Krummrich job->chan = __args->chan; 236b88baab8SDanilo Krummrich 237b88baab8SDanilo Krummrich args.sched_entity = __args->sched_entity; 238b88baab8SDanilo Krummrich args.file_priv = __args->file_priv; 239b88baab8SDanilo Krummrich 240b88baab8SDanilo Krummrich args.in_sync.count = __args->in_sync.count; 241b88baab8SDanilo Krummrich args.in_sync.s = __args->in_sync.s; 242b88baab8SDanilo Krummrich 243b88baab8SDanilo Krummrich args.out_sync.count = __args->out_sync.count; 244b88baab8SDanilo Krummrich args.out_sync.s = __args->out_sync.s; 245b88baab8SDanilo Krummrich 246b88baab8SDanilo Krummrich args.ops = &nouveau_exec_job_ops; 247b88baab8SDanilo Krummrich args.resv_usage = DMA_RESV_USAGE_WRITE; 248b88baab8SDanilo Krummrich 249b88baab8SDanilo Krummrich ret = nouveau_job_init(&job->base, &args); 250b88baab8SDanilo Krummrich if (ret) 251b88baab8SDanilo Krummrich goto err_free_pushs; 252b88baab8SDanilo Krummrich 253b88baab8SDanilo Krummrich return 0; 254b88baab8SDanilo Krummrich 255b88baab8SDanilo Krummrich err_free_pushs: 256b88baab8SDanilo Krummrich kfree(job->push.s); 257b88baab8SDanilo Krummrich err_free_job: 258b88baab8SDanilo Krummrich kfree(job); 259b88baab8SDanilo Krummrich *pjob = NULL; 260b88baab8SDanilo Krummrich 261b88baab8SDanilo Krummrich return ret; 262b88baab8SDanilo Krummrich } 263b88baab8SDanilo Krummrich 264b88baab8SDanilo Krummrich static int 265b88baab8SDanilo Krummrich nouveau_exec(struct nouveau_exec_job_args *args) 266b88baab8SDanilo Krummrich { 267b88baab8SDanilo Krummrich struct nouveau_exec_job *job; 268b88baab8SDanilo Krummrich int ret; 269b88baab8SDanilo Krummrich 270b88baab8SDanilo Krummrich ret = nouveau_exec_job_init(&job, args); 271b88baab8SDanilo Krummrich if (ret) 272b88baab8SDanilo Krummrich return ret; 273b88baab8SDanilo Krummrich 274b88baab8SDanilo Krummrich ret = nouveau_job_submit(&job->base); 275b88baab8SDanilo Krummrich if (ret) 276b88baab8SDanilo Krummrich goto err_job_fini; 277b88baab8SDanilo Krummrich 278b88baab8SDanilo Krummrich return 0; 279b88baab8SDanilo Krummrich 280b88baab8SDanilo Krummrich err_job_fini: 281b88baab8SDanilo Krummrich nouveau_job_fini(&job->base); 282b88baab8SDanilo Krummrich return ret; 283b88baab8SDanilo Krummrich } 284b88baab8SDanilo Krummrich 285b88baab8SDanilo Krummrich static int 286b88baab8SDanilo Krummrich nouveau_exec_ucopy(struct nouveau_exec_job_args *args, 287e39701e3SDanilo Krummrich struct drm_nouveau_exec *req) 288b88baab8SDanilo Krummrich { 289b88baab8SDanilo Krummrich struct drm_nouveau_sync **s; 290b88baab8SDanilo Krummrich u32 inc = req->wait_count; 291b88baab8SDanilo Krummrich u64 ins = req->wait_ptr; 292b88baab8SDanilo Krummrich u32 outc = req->sig_count; 293b88baab8SDanilo Krummrich u64 outs = req->sig_ptr; 294b88baab8SDanilo Krummrich u32 pushc = req->push_count; 295b88baab8SDanilo Krummrich u64 pushs = req->push_ptr; 296b88baab8SDanilo Krummrich int ret; 297b88baab8SDanilo Krummrich 298b88baab8SDanilo Krummrich if (pushc) { 299b88baab8SDanilo Krummrich args->push.count = pushc; 300b88baab8SDanilo Krummrich args->push.s = u_memcpya(pushs, pushc, sizeof(*args->push.s)); 301b88baab8SDanilo Krummrich if (IS_ERR(args->push.s)) 302b88baab8SDanilo Krummrich return PTR_ERR(args->push.s); 303b88baab8SDanilo Krummrich } 304b88baab8SDanilo Krummrich 305b88baab8SDanilo Krummrich if (inc) { 306b88baab8SDanilo Krummrich s = &args->in_sync.s; 307b88baab8SDanilo Krummrich 308b88baab8SDanilo Krummrich args->in_sync.count = inc; 309b88baab8SDanilo Krummrich *s = u_memcpya(ins, inc, sizeof(**s)); 310b88baab8SDanilo Krummrich if (IS_ERR(*s)) { 311b88baab8SDanilo Krummrich ret = PTR_ERR(*s); 312b88baab8SDanilo Krummrich goto err_free_pushs; 313b88baab8SDanilo Krummrich } 314b88baab8SDanilo Krummrich } 315b88baab8SDanilo Krummrich 316b88baab8SDanilo Krummrich if (outc) { 317b88baab8SDanilo Krummrich s = &args->out_sync.s; 318b88baab8SDanilo Krummrich 319b88baab8SDanilo Krummrich args->out_sync.count = outc; 320b88baab8SDanilo Krummrich *s = u_memcpya(outs, outc, sizeof(**s)); 321b88baab8SDanilo Krummrich if (IS_ERR(*s)) { 322b88baab8SDanilo Krummrich ret = PTR_ERR(*s); 323b88baab8SDanilo Krummrich goto err_free_ins; 324b88baab8SDanilo Krummrich } 325b88baab8SDanilo Krummrich } 326b88baab8SDanilo Krummrich 327b88baab8SDanilo Krummrich return 0; 328b88baab8SDanilo Krummrich 329b88baab8SDanilo Krummrich err_free_pushs: 330b88baab8SDanilo Krummrich u_free(args->push.s); 331b88baab8SDanilo Krummrich err_free_ins: 332b88baab8SDanilo Krummrich u_free(args->in_sync.s); 333b88baab8SDanilo Krummrich return ret; 334b88baab8SDanilo Krummrich } 335b88baab8SDanilo Krummrich 336b88baab8SDanilo Krummrich static void 337b88baab8SDanilo Krummrich nouveau_exec_ufree(struct nouveau_exec_job_args *args) 338b88baab8SDanilo Krummrich { 339b88baab8SDanilo Krummrich u_free(args->push.s); 340b88baab8SDanilo Krummrich u_free(args->in_sync.s); 341b88baab8SDanilo Krummrich u_free(args->out_sync.s); 342b88baab8SDanilo Krummrich } 343b88baab8SDanilo Krummrich 344b88baab8SDanilo Krummrich int 345b88baab8SDanilo Krummrich nouveau_exec_ioctl_exec(struct drm_device *dev, 346e39701e3SDanilo Krummrich void *data, 347b88baab8SDanilo Krummrich struct drm_file *file_priv) 348b88baab8SDanilo Krummrich { 349b88baab8SDanilo Krummrich struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv); 350b88baab8SDanilo Krummrich struct nouveau_cli *cli = nouveau_cli(file_priv); 351b88baab8SDanilo Krummrich struct nouveau_abi16_chan *chan16; 352b88baab8SDanilo Krummrich struct nouveau_channel *chan = NULL; 353b88baab8SDanilo Krummrich struct nouveau_exec_job_args args = {}; 354e39701e3SDanilo Krummrich struct drm_nouveau_exec *req = data; 355d59e75eeSDanilo Krummrich int push_max, ret = 0; 356b88baab8SDanilo Krummrich 357b88baab8SDanilo Krummrich if (unlikely(!abi16)) 358b88baab8SDanilo Krummrich return -ENOMEM; 359b88baab8SDanilo Krummrich 360b88baab8SDanilo Krummrich /* abi16 locks already */ 361b88baab8SDanilo Krummrich if (unlikely(!nouveau_cli_uvmm(cli))) 362b88baab8SDanilo Krummrich return nouveau_abi16_put(abi16, -ENOSYS); 363b88baab8SDanilo Krummrich 364b88baab8SDanilo Krummrich list_for_each_entry(chan16, &abi16->channels, head) { 365b88baab8SDanilo Krummrich if (chan16->chan->chid == req->channel) { 366b88baab8SDanilo Krummrich chan = chan16->chan; 367b88baab8SDanilo Krummrich break; 368b88baab8SDanilo Krummrich } 369b88baab8SDanilo Krummrich } 370b88baab8SDanilo Krummrich 371b88baab8SDanilo Krummrich if (!chan) 372b88baab8SDanilo Krummrich return nouveau_abi16_put(abi16, -ENOENT); 373b88baab8SDanilo Krummrich 374b88baab8SDanilo Krummrich if (unlikely(atomic_read(&chan->killed))) 375b88baab8SDanilo Krummrich return nouveau_abi16_put(abi16, -ENODEV); 376b88baab8SDanilo Krummrich 377b88baab8SDanilo Krummrich if (!chan->dma.ib_max) 378b88baab8SDanilo Krummrich return nouveau_abi16_put(abi16, -ENOSYS); 379b88baab8SDanilo Krummrich 380d59e75eeSDanilo Krummrich push_max = nouveau_exec_push_max_from_ib_max(chan->dma.ib_max); 381d59e75eeSDanilo Krummrich if (unlikely(req->push_count > push_max)) { 382b88baab8SDanilo Krummrich NV_PRINTK(err, cli, "pushbuf push count exceeds limit: %d max %d\n", 383d59e75eeSDanilo Krummrich req->push_count, push_max); 384b88baab8SDanilo Krummrich return nouveau_abi16_put(abi16, -EINVAL); 385b88baab8SDanilo Krummrich } 386b88baab8SDanilo Krummrich 387b88baab8SDanilo Krummrich ret = nouveau_exec_ucopy(&args, req); 388b88baab8SDanilo Krummrich if (ret) 389b88baab8SDanilo Krummrich goto out; 390b88baab8SDanilo Krummrich 391b88baab8SDanilo Krummrich args.sched_entity = &chan16->sched_entity; 392b88baab8SDanilo Krummrich args.file_priv = file_priv; 393b88baab8SDanilo Krummrich args.chan = chan; 394b88baab8SDanilo Krummrich 395b88baab8SDanilo Krummrich ret = nouveau_exec(&args); 396b88baab8SDanilo Krummrich if (ret) 397b88baab8SDanilo Krummrich goto out_free_args; 398b88baab8SDanilo Krummrich 399b88baab8SDanilo Krummrich out_free_args: 400b88baab8SDanilo Krummrich nouveau_exec_ufree(&args); 401b88baab8SDanilo Krummrich out: 402b88baab8SDanilo Krummrich return nouveau_abi16_put(abi16, ret); 403b88baab8SDanilo Krummrich } 404