.. | .. |
---|
23 | 23 | */ |
---|
24 | 24 | |
---|
25 | 25 | #include <linux/fdtable.h> |
---|
| 26 | +#include <linux/file.h> |
---|
26 | 27 | #include <linux/pid.h> |
---|
| 28 | + |
---|
27 | 29 | #include <drm/amdgpu_drm.h> |
---|
| 30 | + |
---|
28 | 31 | #include "amdgpu.h" |
---|
29 | 32 | |
---|
30 | 33 | #include "amdgpu_vm.h" |
---|
31 | 34 | |
---|
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) |
---|
33 | 37 | { |
---|
34 | 38 | switch (amdgpu_priority) { |
---|
35 | 39 | case AMDGPU_CTX_PRIORITY_VERY_HIGH: |
---|
36 | | - return DRM_SCHED_PRIORITY_HIGH_HW; |
---|
| 40 | + *prio = DRM_SCHED_PRIORITY_HIGH; |
---|
| 41 | + break; |
---|
37 | 42 | case AMDGPU_CTX_PRIORITY_HIGH: |
---|
38 | | - return DRM_SCHED_PRIORITY_HIGH_SW; |
---|
| 43 | + *prio = DRM_SCHED_PRIORITY_HIGH; |
---|
| 44 | + break; |
---|
39 | 45 | case AMDGPU_CTX_PRIORITY_NORMAL: |
---|
40 | | - return DRM_SCHED_PRIORITY_NORMAL; |
---|
| 46 | + *prio = DRM_SCHED_PRIORITY_NORMAL; |
---|
| 47 | + break; |
---|
41 | 48 | case AMDGPU_CTX_PRIORITY_LOW: |
---|
42 | 49 | case AMDGPU_CTX_PRIORITY_VERY_LOW: |
---|
43 | | - return DRM_SCHED_PRIORITY_LOW; |
---|
| 50 | + *prio = DRM_SCHED_PRIORITY_MIN; |
---|
| 51 | + break; |
---|
44 | 52 | case AMDGPU_CTX_PRIORITY_UNSET: |
---|
45 | | - return DRM_SCHED_PRIORITY_UNSET; |
---|
| 53 | + *prio = DRM_SCHED_PRIORITY_UNSET; |
---|
| 54 | + break; |
---|
46 | 55 | default: |
---|
47 | 56 | WARN(1, "Invalid context priority %d\n", amdgpu_priority); |
---|
48 | | - return DRM_SCHED_PRIORITY_INVALID; |
---|
| 57 | + return -EINVAL; |
---|
49 | 58 | } |
---|
| 59 | + |
---|
| 60 | + return 0; |
---|
50 | 61 | } |
---|
51 | 62 | |
---|
52 | 63 | static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, |
---|
53 | 64 | int fd, |
---|
54 | 65 | enum drm_sched_priority priority) |
---|
55 | 66 | { |
---|
56 | | - struct file *filp = fget(fd); |
---|
57 | | - struct drm_file *file; |
---|
| 67 | + struct fd f = fdget(fd); |
---|
58 | 68 | struct amdgpu_fpriv *fpriv; |
---|
59 | 69 | struct amdgpu_ctx *ctx; |
---|
60 | 70 | uint32_t id; |
---|
| 71 | + int r; |
---|
61 | 72 | |
---|
62 | | - if (!filp) |
---|
| 73 | + if (!f.file) |
---|
63 | 74 | return -EINVAL; |
---|
64 | 75 | |
---|
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 | + |
---|
67 | 82 | idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id) |
---|
68 | 83 | amdgpu_ctx_priority_override(ctx, priority); |
---|
69 | 84 | |
---|
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); |
---|
71 | 118 | |
---|
72 | 119 | return 0; |
---|
73 | 120 | } |
---|
.. | .. |
---|
76 | 123 | struct drm_file *filp) |
---|
77 | 124 | { |
---|
78 | 125 | union drm_amdgpu_sched *args = data; |
---|
79 | | - struct amdgpu_device *adev = dev->dev_private; |
---|
| 126 | + struct amdgpu_device *adev = drm_to_adev(dev); |
---|
80 | 127 | enum drm_sched_priority priority; |
---|
81 | 128 | int r; |
---|
82 | 129 | |
---|
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); |
---|
85 | 138 | return -EINVAL; |
---|
| 139 | + } |
---|
| 140 | + |
---|
| 141 | + r = amdgpu_to_sched_priority(args->in.priority, &priority); |
---|
| 142 | + if (r) |
---|
| 143 | + return r; |
---|
86 | 144 | |
---|
87 | 145 | switch (args->in.op) { |
---|
88 | 146 | case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE: |
---|
.. | .. |
---|
90 | 148 | args->in.fd, |
---|
91 | 149 | priority); |
---|
92 | 150 | 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; |
---|
93 | 157 | default: |
---|
94 | | - DRM_ERROR("Invalid sched op specified: %d\n", args->in.op); |
---|
| 158 | + /* Impossible. |
---|
| 159 | + */ |
---|
95 | 160 | r = -EINVAL; |
---|
96 | 161 | break; |
---|
97 | 162 | } |
---|