xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/amdkfd/kfd_module.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: kfd_module.c,v 1.3 2021/12/18 23:44:59 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2014 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #include <sys/cdefs.h>
26 __KERNEL_RCSID(0, "$NetBSD: kfd_module.c,v 1.3 2021/12/18 23:44:59 riastradh Exp $");
27 
28 #include <linux/sched.h>
29 #include <linux/device.h>
30 #include "kfd_priv.h"
31 #include "amdgpu_amdkfd.h"
32 
kfd_init(void)33 static int kfd_init(void)
34 {
35 	int err;
36 
37 	/* Verify module parameters */
38 	if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
39 		(sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
40 		pr_err("sched_policy has invalid value\n");
41 		return -EINVAL;
42 	}
43 
44 	/* Verify module parameters */
45 	if ((max_num_of_queues_per_device < 1) ||
46 		(max_num_of_queues_per_device >
47 			KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
48 		pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
49 		return -EINVAL;
50 	}
51 
52 	err = kfd_chardev_init();
53 	if (err < 0)
54 		goto err_ioctl;
55 
56 	err = kfd_topology_init();
57 	if (err < 0)
58 		goto err_topology;
59 
60 	err = kfd_process_create_wq();
61 	if (err < 0)
62 		goto err_create_wq;
63 
64 	/* Ignore the return value, so that we can continue
65 	 * to init the KFD, even if procfs isn't craated
66 	 */
67 	kfd_procfs_init();
68 
69 	kfd_debugfs_init();
70 
71 	return 0;
72 
73 err_create_wq:
74 	kfd_topology_shutdown();
75 err_topology:
76 	kfd_chardev_exit();
77 err_ioctl:
78 	return err;
79 }
80 
kfd_exit(void)81 static void kfd_exit(void)
82 {
83 	kfd_debugfs_fini();
84 	kfd_process_destroy_wq();
85 	kfd_procfs_shutdown();
86 	kfd_topology_shutdown();
87 	kfd_chardev_exit();
88 }
89 
kgd2kfd_init(void)90 int kgd2kfd_init(void)
91 {
92 	return kfd_init();
93 }
94 
kgd2kfd_exit(void)95 void kgd2kfd_exit(void)
96 {
97 	kfd_exit();
98 }
99