2 * Copyright 2017 Valve Corporation
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include <linux/fdtable.h>
26 #include <linux/file.h>
27 #include <linux/pid.h>
29 #include <drm/amdgpu_drm.h>
32 #include "amdgpu_sched.h"
33 #include "amdgpu_vm.h"
35 static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
39 struct fd f = fdget(fd);
40 struct amdgpu_fpriv *fpriv;
41 struct amdgpu_ctx_mgr *mgr;
42 struct amdgpu_ctx *ctx;
49 r = amdgpu_file_to_fpriv(f.file, &fpriv);
55 mgr = &fpriv->ctx_mgr;
56 mutex_lock(&mgr->lock);
57 idr_for_each_entry(&mgr->ctx_handles, ctx, id)
58 amdgpu_ctx_priority_override(ctx, priority);
59 mutex_unlock(&mgr->lock);
65 static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
70 struct fd f = fdget(fd);
71 struct amdgpu_fpriv *fpriv;
72 struct amdgpu_ctx *ctx;
78 r = amdgpu_file_to_fpriv(f.file, &fpriv);
84 ctx = amdgpu_ctx_get(fpriv, ctx_id);
91 amdgpu_ctx_priority_override(ctx, priority);
98 int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
99 struct drm_file *filp)
101 union drm_amdgpu_sched *args = data;
102 struct amdgpu_device *adev = drm_to_adev(dev);
105 /* First check the op, then the op's argument.
107 switch (args->in.op) {
108 case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
109 case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
112 DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
116 if (!amdgpu_ctx_priority_is_valid(args->in.priority)) {
117 WARN(1, "Invalid context priority %d\n", args->in.priority);
121 switch (args->in.op) {
122 case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
123 r = amdgpu_sched_process_priority_override(adev,
127 case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
128 r = amdgpu_sched_context_priority_override(adev,