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