1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/fdtable.h>
26#include <linux/pid.h>
27#include <drm/amdgpu_drm.h>
28#include "amdgpu.h"
29
30#include "amdgpu_vm.h"
31
32enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
33{
34 switch (amdgpu_priority) {
35 case AMDGPU_CTX_PRIORITY_VERY_HIGH:
36 return DRM_SCHED_PRIORITY_HIGH_HW;
37 case AMDGPU_CTX_PRIORITY_HIGH:
38 return DRM_SCHED_PRIORITY_HIGH_SW;
39 case AMDGPU_CTX_PRIORITY_NORMAL:
40 return DRM_SCHED_PRIORITY_NORMAL;
41 case AMDGPU_CTX_PRIORITY_LOW:
42 case AMDGPU_CTX_PRIORITY_VERY_LOW:
43 return DRM_SCHED_PRIORITY_LOW;
44 case AMDGPU_CTX_PRIORITY_UNSET:
45 return DRM_SCHED_PRIORITY_UNSET;
46 default:
47 WARN(1, "Invalid context priority %d\n", amdgpu_priority);
48 return DRM_SCHED_PRIORITY_INVALID;
49 }
50}
51
52static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
53 int fd,
54 enum drm_sched_priority priority)
55{
56 struct file *filp = fget(fd);
57 struct drm_file *file;
58 struct amdgpu_fpriv *fpriv;
59 struct amdgpu_ctx *ctx;
60 uint32_t id;
61
62 if (!filp)
63 return -EINVAL;
64
65 file = filp->private_data;
66 fpriv = file->driver_priv;
67 idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
68 amdgpu_ctx_priority_override(ctx, priority);
69
70 fput(filp);
71
72 return 0;
73}
74
75int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
76 struct drm_file *filp)
77{
78 union drm_amdgpu_sched *args = data;
79 struct amdgpu_device *adev = dev->dev_private;
80 enum drm_sched_priority priority;
81 int r;
82
83 priority = amdgpu_to_sched_priority(args->in.priority);
84 if (args->in.flags || priority == DRM_SCHED_PRIORITY_INVALID)
85 return -EINVAL;
86
87 switch (args->in.op) {
88 case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
89 r = amdgpu_sched_process_priority_override(adev,
90 args->in.fd,
91 priority);
92 break;
93 default:
94 DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
95 r = -EINVAL;
96 break;
97 }
98
99 return r;
100}
101