1 /* 2 * Copyright 2017 Valve Corporation 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 * Authors: Andres Rodriguez <andresx7@gmail.com> 23 */ 24 25 #include <linux/fdtable.h> 26 #include <linux/file.h> 27 #include <linux/pid.h> 28 29 #include <drm/amdgpu_drm.h> 30 31 #include "amdgpu.h" 32 #include "amdgpu_sched.h" 33 #include "amdgpu_vm.h" 34 35 static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, 36 int fd, 37 int32_t priority) 38 { 39 STUB(); 40 return -ENOSYS; 41 #ifdef notyet 42 struct fd f = fdget(fd); 43 struct amdgpu_fpriv *fpriv; 44 struct amdgpu_ctx_mgr *mgr; 45 struct amdgpu_ctx *ctx; 46 uint32_t id; 47 int r; 48 49 if (!f.file) 50 return -EINVAL; 51 52 r = amdgpu_file_to_fpriv(f.file, &fpriv); 53 if (r) { 54 fdput(f); 55 return r; 56 } 57 58 mgr = &fpriv->ctx_mgr; 59 mutex_lock(&mgr->lock); 60 idr_for_each_entry(&mgr->ctx_handles, ctx, id) 61 amdgpu_ctx_priority_override(ctx, priority); 62 mutex_unlock(&mgr->lock); 63 64 fdput(f); 65 return 0; 66 #endif 67 } 68 69 static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev, 70 int fd, 71 unsigned ctx_id, 72 int32_t priority) 73 { 74 STUB(); 75 return -ENOSYS; 76 #ifdef notyet 77 struct fd f = fdget(fd); 78 struct amdgpu_fpriv *fpriv; 79 struct amdgpu_ctx *ctx; 80 int r; 81 82 if (!f.file) 83 return -EINVAL; 84 85 r = amdgpu_file_to_fpriv(f.file, &fpriv); 86 if (r) { 87 fdput(f); 88 return r; 89 } 90 91 ctx = amdgpu_ctx_get(fpriv, ctx_id); 92 93 if (!ctx) { 94 fdput(f); 95 return -EINVAL; 96 } 97 98 amdgpu_ctx_priority_override(ctx, priority); 99 amdgpu_ctx_put(ctx); 100 fdput(f); 101 102 return 0; 103 #endif 104 } 105 106 int amdgpu_sched_ioctl(struct drm_device *dev, void *data, 107 struct drm_file *filp) 108 { 109 union drm_amdgpu_sched *args = data; 110 struct amdgpu_device *adev = drm_to_adev(dev); 111 int r; 112 113 /* First check the op, then the op's argument. 114 */ 115 switch (args->in.op) { 116 case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE: 117 case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE: 118 break; 119 default: 120 DRM_ERROR("Invalid sched op specified: %d\n", args->in.op); 121 return -EINVAL; 122 } 123 124 if (!amdgpu_ctx_priority_is_valid(args->in.priority)) { 125 WARN(1, "Invalid context priority %d\n", args->in.priority); 126 return -EINVAL; 127 } 128 129 switch (args->in.op) { 130 case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE: 131 r = amdgpu_sched_process_priority_override(adev, 132 args->in.fd, 133 args->in.priority); 134 break; 135 case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE: 136 r = amdgpu_sched_context_priority_override(adev, 137 args->in.fd, 138 args->in.ctx_id, 139 args->in.priority); 140 break; 141 default: 142 /* Impossible. 143 */ 144 r = -EINVAL; 145 break; 146 } 147 148 return r; 149 } 150