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