hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
....@@ -23,51 +23,98 @@
2323 */
2424
2525 #include <linux/fdtable.h>
26
+#include <linux/file.h>
2627 #include <linux/pid.h>
28
+
2729 #include <drm/amdgpu_drm.h>
30
+
2831 #include "amdgpu.h"
2932
3033 #include "amdgpu_vm.h"
3134
32
-enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
35
+int amdgpu_to_sched_priority(int amdgpu_priority,
36
+ enum drm_sched_priority *prio)
3337 {
3438 switch (amdgpu_priority) {
3539 case AMDGPU_CTX_PRIORITY_VERY_HIGH:
36
- return DRM_SCHED_PRIORITY_HIGH_HW;
40
+ *prio = DRM_SCHED_PRIORITY_HIGH;
41
+ break;
3742 case AMDGPU_CTX_PRIORITY_HIGH:
38
- return DRM_SCHED_PRIORITY_HIGH_SW;
43
+ *prio = DRM_SCHED_PRIORITY_HIGH;
44
+ break;
3945 case AMDGPU_CTX_PRIORITY_NORMAL:
40
- return DRM_SCHED_PRIORITY_NORMAL;
46
+ *prio = DRM_SCHED_PRIORITY_NORMAL;
47
+ break;
4148 case AMDGPU_CTX_PRIORITY_LOW:
4249 case AMDGPU_CTX_PRIORITY_VERY_LOW:
43
- return DRM_SCHED_PRIORITY_LOW;
50
+ *prio = DRM_SCHED_PRIORITY_MIN;
51
+ break;
4452 case AMDGPU_CTX_PRIORITY_UNSET:
45
- return DRM_SCHED_PRIORITY_UNSET;
53
+ *prio = DRM_SCHED_PRIORITY_UNSET;
54
+ break;
4655 default:
4756 WARN(1, "Invalid context priority %d\n", amdgpu_priority);
48
- return DRM_SCHED_PRIORITY_INVALID;
57
+ return -EINVAL;
4958 }
59
+
60
+ return 0;
5061 }
5162
5263 static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
5364 int fd,
5465 enum drm_sched_priority priority)
5566 {
56
- struct file *filp = fget(fd);
57
- struct drm_file *file;
67
+ struct fd f = fdget(fd);
5868 struct amdgpu_fpriv *fpriv;
5969 struct amdgpu_ctx *ctx;
6070 uint32_t id;
71
+ int r;
6172
62
- if (!filp)
73
+ if (!f.file)
6374 return -EINVAL;
6475
65
- file = filp->private_data;
66
- fpriv = file->driver_priv;
76
+ r = amdgpu_file_to_fpriv(f.file, &fpriv);
77
+ if (r) {
78
+ fdput(f);
79
+ return r;
80
+ }
81
+
6782 idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
6883 amdgpu_ctx_priority_override(ctx, priority);
6984
70
- fput(filp);
85
+ fdput(f);
86
+ return 0;
87
+}
88
+
89
+static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
90
+ int fd,
91
+ unsigned ctx_id,
92
+ enum drm_sched_priority priority)
93
+{
94
+ struct fd f = fdget(fd);
95
+ struct amdgpu_fpriv *fpriv;
96
+ struct amdgpu_ctx *ctx;
97
+ int r;
98
+
99
+ if (!f.file)
100
+ return -EINVAL;
101
+
102
+ r = amdgpu_file_to_fpriv(f.file, &fpriv);
103
+ if (r) {
104
+ fdput(f);
105
+ return r;
106
+ }
107
+
108
+ ctx = amdgpu_ctx_get(fpriv, ctx_id);
109
+
110
+ if (!ctx) {
111
+ fdput(f);
112
+ return -EINVAL;
113
+ }
114
+
115
+ amdgpu_ctx_priority_override(ctx, priority);
116
+ amdgpu_ctx_put(ctx);
117
+ fdput(f);
71118
72119 return 0;
73120 }
....@@ -76,13 +123,24 @@
76123 struct drm_file *filp)
77124 {
78125 union drm_amdgpu_sched *args = data;
79
- struct amdgpu_device *adev = dev->dev_private;
126
+ struct amdgpu_device *adev = drm_to_adev(dev);
80127 enum drm_sched_priority priority;
81128 int r;
82129
83
- priority = amdgpu_to_sched_priority(args->in.priority);
84
- if (args->in.flags || priority == DRM_SCHED_PRIORITY_INVALID)
130
+ /* First check the op, then the op's argument.
131
+ */
132
+ switch (args->in.op) {
133
+ case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
134
+ case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
135
+ break;
136
+ default:
137
+ DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
85138 return -EINVAL;
139
+ }
140
+
141
+ r = amdgpu_to_sched_priority(args->in.priority, &priority);
142
+ if (r)
143
+ return r;
86144
87145 switch (args->in.op) {
88146 case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
....@@ -90,8 +148,15 @@
90148 args->in.fd,
91149 priority);
92150 break;
151
+ case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
152
+ r = amdgpu_sched_context_priority_override(adev,
153
+ args->in.fd,
154
+ args->in.ctx_id,
155
+ priority);
156
+ break;
93157 default:
94
- DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
158
+ /* Impossible.
159
+ */
95160 r = -EINVAL;
96161 break;
97162 }