Merge tag 'm68k-for-v6.4-tag1' of git://git.kernel.org/pub/scm/linux/kernel/git/geert...
[linux-block.git] / drivers / gpu / drm / amd / amdkfd / kfd_module.c
CommitLineData
d87f36a0 1// SPDX-License-Identifier: GPL-2.0 OR MIT
4a488a7a 2/*
d87f36a0 3 * Copyright 2014-2022 Advanced Micro Devices, Inc.
4a488a7a
OG
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
4a488a7a 24#include <linux/sched.h>
4a488a7a
OG
25#include <linux/device.h>
26#include "kfd_priv.h"
2d3d25b6 27#include "amdgpu_amdkfd.h"
4a488a7a 28
04d5e276 29static int kfd_init(void)
4a488a7a
OG
30{
31 int err;
32
31c21fec
BG
33 /* Verify module parameters */
34 if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
35 (sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
79775b62 36 pr_err("sched_policy has invalid value\n");
04d5e276 37 return -EINVAL;
31c21fec
BG
38 }
39
19f6d2a6 40 /* Verify module parameters */
ca400b2a 41 if ((max_num_of_queues_per_device < 1) ||
b8cbab04
OG
42 (max_num_of_queues_per_device >
43 KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
79775b62 44 pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
04d5e276 45 return -EINVAL;
19f6d2a6
OG
46 }
47
4a488a7a
OG
48 err = kfd_chardev_init();
49 if (err < 0)
50 goto err_ioctl;
51
5b5c4e40
EP
52 err = kfd_topology_init();
53 if (err < 0)
54 goto err_topology;
55
1679ae8f
FK
56 err = kfd_process_create_wq();
57 if (err < 0)
58 goto err_create_wq;
19f6d2a6 59
de9f26bb
KR
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
851a645e
FK
65 kfd_debugfs_init();
66
4a488a7a
OG
67 return 0;
68
1679ae8f
FK
69err_create_wq:
70 kfd_topology_shutdown();
5b5c4e40
EP
71err_topology:
72 kfd_chardev_exit();
4a488a7a 73err_ioctl:
c7651b73 74 pr_err("KFD is disabled due to module initialization failure\n");
4a488a7a
OG
75 return err;
76}
77
04d5e276 78static void kfd_exit(void)
4a488a7a 79{
20bc9f76 80 kfd_cleanup_processes();
851a645e 81 kfd_debugfs_fini();
19f6d2a6 82 kfd_process_destroy_wq();
de9f26bb 83 kfd_procfs_shutdown();
5b5c4e40 84 kfd_topology_shutdown();
4a488a7a 85 kfd_chardev_exit();
4a488a7a
OG
86}
87
63617d8b 88int kgd2kfd_init(void)
04d5e276 89{
308176d6 90 return kfd_init();
04d5e276 91}
04d5e276
AL
92
93void kgd2kfd_exit(void)
94{
95 kfd_exit();
96}