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.
22 * Authors: Andres Rodriguez <andresx7@gmail.com>
25 #include <linux/fdtable.h>
26 #include <linux/file.h>
27 #include <linux/pid.h>
29 #include <drm/amdgpu_drm.h>
33 #include "amdgpu_vm.h"
35 enum drm_sched_priority
amdgpu_to_sched_priority(int amdgpu_priority
)
37 switch (amdgpu_priority
) {
38 case AMDGPU_CTX_PRIORITY_VERY_HIGH
:
39 return DRM_SCHED_PRIORITY_HIGH_HW
;
40 case AMDGPU_CTX_PRIORITY_HIGH
:
41 return DRM_SCHED_PRIORITY_HIGH_SW
;
42 case AMDGPU_CTX_PRIORITY_NORMAL
:
43 return DRM_SCHED_PRIORITY_NORMAL
;
44 case AMDGPU_CTX_PRIORITY_LOW
:
45 case AMDGPU_CTX_PRIORITY_VERY_LOW
:
46 return DRM_SCHED_PRIORITY_LOW
;
47 case AMDGPU_CTX_PRIORITY_UNSET
:
48 return DRM_SCHED_PRIORITY_UNSET
;
50 WARN(1, "Invalid context priority %d\n", amdgpu_priority
);
51 return DRM_SCHED_PRIORITY_INVALID
;
55 static int amdgpu_sched_process_priority_override(struct amdgpu_device
*adev
,
57 enum drm_sched_priority priority
)
59 struct fd f
= fdget(fd
);
60 struct amdgpu_fpriv
*fpriv
;
61 struct amdgpu_ctx
*ctx
;
68 r
= amdgpu_file_to_fpriv(f
.file
, &fpriv
);
74 idr_for_each_entry(&fpriv
->ctx_mgr
.ctx_handles
, ctx
, id
)
75 amdgpu_ctx_priority_override(ctx
, priority
);
81 static int amdgpu_sched_context_priority_override(struct amdgpu_device
*adev
,
84 enum drm_sched_priority priority
)
86 struct fd f
= fdget(fd
);
87 struct amdgpu_fpriv
*fpriv
;
88 struct amdgpu_ctx
*ctx
;
94 r
= amdgpu_file_to_fpriv(f
.file
, &fpriv
);
100 ctx
= amdgpu_ctx_get(fpriv
, ctx_id
);
107 amdgpu_ctx_priority_override(ctx
, priority
);
114 int amdgpu_sched_ioctl(struct drm_device
*dev
, void *data
,
115 struct drm_file
*filp
)
117 union drm_amdgpu_sched
*args
= data
;
118 struct amdgpu_device
*adev
= dev
->dev_private
;
119 enum drm_sched_priority priority
;
122 priority
= amdgpu_to_sched_priority(args
->in
.priority
);
123 if (priority
== DRM_SCHED_PRIORITY_INVALID
)
126 switch (args
->in
.op
) {
127 case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE
:
128 r
= amdgpu_sched_process_priority_override(adev
,
132 case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE
:
133 r
= amdgpu_sched_context_priority_override(adev
,
139 DRM_ERROR("Invalid sched op specified: %d\n", args
->in
.op
);