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