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