xref: /dragonfly/sys/dev/drm/amd/amdgpu/amdgpu_sched.c (revision 78973132)
1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2017 Valve Corporation
3b843c749SSergey Zigachev  *
4b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10b843c749SSergey Zigachev  *
11b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13b843c749SSergey Zigachev  *
14b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21b843c749SSergey Zigachev  *
22b843c749SSergey Zigachev  * Authors: Andres Rodriguez <andresx7@gmail.com>
23b843c749SSergey Zigachev  */
24b843c749SSergey Zigachev 
25b843c749SSergey Zigachev #include <linux/fdtable.h>
26b843c749SSergey Zigachev #include <linux/pid.h>
27b843c749SSergey Zigachev #include <drm/amdgpu_drm.h>
28b843c749SSergey Zigachev #include "amdgpu.h"
29b843c749SSergey Zigachev 
30b843c749SSergey Zigachev #include "amdgpu_vm.h"
31b843c749SSergey Zigachev 
32*78973132SSergey Zigachev enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority);
amdgpu_to_sched_priority(int amdgpu_priority)33b843c749SSergey Zigachev enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
34b843c749SSergey Zigachev {
35b843c749SSergey Zigachev 	switch (amdgpu_priority) {
36b843c749SSergey Zigachev 	case AMDGPU_CTX_PRIORITY_VERY_HIGH:
37b843c749SSergey Zigachev 		return DRM_SCHED_PRIORITY_HIGH_HW;
38b843c749SSergey Zigachev 	case AMDGPU_CTX_PRIORITY_HIGH:
39b843c749SSergey Zigachev 		return DRM_SCHED_PRIORITY_HIGH_SW;
40b843c749SSergey Zigachev 	case AMDGPU_CTX_PRIORITY_NORMAL:
41b843c749SSergey Zigachev 		return DRM_SCHED_PRIORITY_NORMAL;
42b843c749SSergey Zigachev 	case AMDGPU_CTX_PRIORITY_LOW:
43b843c749SSergey Zigachev 	case AMDGPU_CTX_PRIORITY_VERY_LOW:
44b843c749SSergey Zigachev 		return DRM_SCHED_PRIORITY_LOW;
45b843c749SSergey Zigachev 	case AMDGPU_CTX_PRIORITY_UNSET:
46b843c749SSergey Zigachev 		return DRM_SCHED_PRIORITY_UNSET;
47b843c749SSergey Zigachev 	default:
48b843c749SSergey Zigachev 		WARN(1, "Invalid context priority %d\n", amdgpu_priority);
49b843c749SSergey Zigachev 		return DRM_SCHED_PRIORITY_INVALID;
50b843c749SSergey Zigachev 	}
51b843c749SSergey Zigachev }
52b843c749SSergey Zigachev 
amdgpu_sched_process_priority_override(struct amdgpu_device * adev,int fd,enum drm_sched_priority priority)53b843c749SSergey Zigachev static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
54b843c749SSergey Zigachev 						  int fd,
55b843c749SSergey Zigachev 						  enum drm_sched_priority priority)
56b843c749SSergey Zigachev {
57*78973132SSergey Zigachev 	STUB();
58*78973132SSergey Zigachev 	return -ENOSYS;
59*78973132SSergey Zigachev #if 0
60b843c749SSergey Zigachev 	struct file *filp = fget(fd);
61b843c749SSergey Zigachev 	struct drm_file *file;
62b843c749SSergey Zigachev 	struct amdgpu_fpriv *fpriv;
63b843c749SSergey Zigachev 	struct amdgpu_ctx *ctx;
64b843c749SSergey Zigachev 	uint32_t id;
65b843c749SSergey Zigachev 
66b843c749SSergey Zigachev 	if (!filp)
67b843c749SSergey Zigachev 		return -EINVAL;
68b843c749SSergey Zigachev 
69b843c749SSergey Zigachev 	file = filp->private_data;
70b843c749SSergey Zigachev 	fpriv = file->driver_priv;
71b843c749SSergey Zigachev 	idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
72b843c749SSergey Zigachev 		amdgpu_ctx_priority_override(ctx, priority);
73b843c749SSergey Zigachev 
74b843c749SSergey Zigachev 	fput(filp);
75b843c749SSergey Zigachev 
76b843c749SSergey Zigachev 	return 0;
77*78973132SSergey Zigachev #endif
78b843c749SSergey Zigachev }
79b843c749SSergey Zigachev 
80b843c749SSergey Zigachev int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
81*78973132SSergey Zigachev 		       struct drm_file *filp);
amdgpu_sched_ioctl(struct drm_device * dev,void * data,struct drm_file * filp)82*78973132SSergey Zigachev int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
83b843c749SSergey Zigachev 		       struct drm_file *filp)
84b843c749SSergey Zigachev {
85b843c749SSergey Zigachev 	union drm_amdgpu_sched *args = data;
86b843c749SSergey Zigachev 	struct amdgpu_device *adev = dev->dev_private;
87b843c749SSergey Zigachev 	enum drm_sched_priority priority;
88b843c749SSergey Zigachev 	int r;
89b843c749SSergey Zigachev 
90b843c749SSergey Zigachev 	priority = amdgpu_to_sched_priority(args->in.priority);
91b843c749SSergey Zigachev 	if (args->in.flags || priority == DRM_SCHED_PRIORITY_INVALID)
92b843c749SSergey Zigachev 		return -EINVAL;
93b843c749SSergey Zigachev 
94b843c749SSergey Zigachev 	switch (args->in.op) {
95b843c749SSergey Zigachev 	case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
96b843c749SSergey Zigachev 		r = amdgpu_sched_process_priority_override(adev,
97b843c749SSergey Zigachev 							   args->in.fd,
98b843c749SSergey Zigachev 							   priority);
99b843c749SSergey Zigachev 		break;
100b843c749SSergey Zigachev 	default:
101b843c749SSergey Zigachev 		DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
102b843c749SSergey Zigachev 		r = -EINVAL;
103b843c749SSergey Zigachev 		break;
104b843c749SSergey Zigachev 	}
105b843c749SSergey Zigachev 
106b843c749SSergey Zigachev 	return r;
107b843c749SSergey Zigachev }
108