1 /*
2  * Copyright 2014 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #include <linux/sched.h>
24 #include <linux/device.h>
25 #include "kfd_priv.h"
26 
27 static const struct kgd2kfd_calls kgd2kfd = {
28 	.exit		= kgd2kfd_exit,
29 	.probe		= kgd2kfd_probe,
30 	.device_init	= kgd2kfd_device_init,
31 	.device_exit	= kgd2kfd_device_exit,
32 	.interrupt	= kgd2kfd_interrupt,
33 	.suspend	= kgd2kfd_suspend,
34 	.resume		= kgd2kfd_resume,
35 	.quiesce_mm	= kgd2kfd_quiesce_mm,
36 	.resume_mm	= kgd2kfd_resume_mm,
37 	.schedule_evict_and_restore_process =
38 			  kgd2kfd_schedule_evict_and_restore_process,
39 	.pre_reset	= kgd2kfd_pre_reset,
40 	.post_reset	= kgd2kfd_post_reset,
41 };
42 
43 static int kfd_init(void)
44 {
45 	int err;
46 
47 	/* Verify module parameters */
48 	if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
49 		(sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
50 		pr_err("sched_policy has invalid value\n");
51 		return -EINVAL;
52 	}
53 
54 	/* Verify module parameters */
55 	if ((max_num_of_queues_per_device < 1) ||
56 		(max_num_of_queues_per_device >
57 			KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
58 		pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
59 		return -EINVAL;
60 	}
61 
62 	err = kfd_chardev_init();
63 	if (err < 0)
64 		goto err_ioctl;
65 
66 	err = kfd_topology_init();
67 	if (err < 0)
68 		goto err_topology;
69 
70 	err = kfd_process_create_wq();
71 	if (err < 0)
72 		goto err_create_wq;
73 
74 	kfd_debugfs_init();
75 
76 	return 0;
77 
78 err_create_wq:
79 	kfd_topology_shutdown();
80 err_topology:
81 	kfd_chardev_exit();
82 err_ioctl:
83 	return err;
84 }
85 
86 static void kfd_exit(void)
87 {
88 	kfd_debugfs_fini();
89 	kfd_process_destroy_wq();
90 	kfd_topology_shutdown();
91 	kfd_chardev_exit();
92 }
93 
94 int kgd2kfd_init(unsigned int interface_version,
95 		const struct kgd2kfd_calls **g2f)
96 {
97 	int err;
98 
99 	err = kfd_init();
100 	if (err)
101 		return err;
102 
103 	*g2f = &kgd2kfd;
104 
105 	return 0;
106 }
107 EXPORT_SYMBOL(kgd2kfd_init);
108 
109 void kgd2kfd_exit(void)
110 {
111 	kfd_exit();
112 }
113