Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 OR MIT
0002 /*
0003  * Copyright 2014-2022 Advanced Micro Devices, Inc.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included in
0013  * all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0019  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0021  * OTHER DEALINGS IN THE SOFTWARE.
0022  */
0023 
0024 #include <linux/sched.h>
0025 #include <linux/device.h>
0026 #include "kfd_priv.h"
0027 #include "amdgpu_amdkfd.h"
0028 
0029 static int kfd_init(void)
0030 {
0031     int err;
0032 
0033     /* Verify module parameters */
0034     if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
0035         (sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
0036         pr_err("sched_policy has invalid value\n");
0037         return -EINVAL;
0038     }
0039 
0040     /* Verify module parameters */
0041     if ((max_num_of_queues_per_device < 1) ||
0042         (max_num_of_queues_per_device >
0043             KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
0044         pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
0045         return -EINVAL;
0046     }
0047 
0048     err = kfd_chardev_init();
0049     if (err < 0)
0050         goto err_ioctl;
0051 
0052     err = kfd_topology_init();
0053     if (err < 0)
0054         goto err_topology;
0055 
0056     err = kfd_process_create_wq();
0057     if (err < 0)
0058         goto err_create_wq;
0059 
0060     /* Ignore the return value, so that we can continue
0061      * to init the KFD, even if procfs isn't craated
0062      */
0063     kfd_procfs_init();
0064 
0065     kfd_debugfs_init();
0066 
0067     return 0;
0068 
0069 err_create_wq:
0070     kfd_topology_shutdown();
0071 err_topology:
0072     kfd_chardev_exit();
0073 err_ioctl:
0074     pr_err("KFD is disabled due to module initialization failure\n");
0075     return err;
0076 }
0077 
0078 static void kfd_exit(void)
0079 {
0080     kfd_debugfs_fini();
0081     kfd_process_destroy_wq();
0082     kfd_procfs_shutdown();
0083     kfd_topology_shutdown();
0084     kfd_chardev_exit();
0085 }
0086 
0087 int kgd2kfd_init(void)
0088 {
0089     return kfd_init();
0090 }
0091 
0092 void kgd2kfd_exit(void)
0093 {
0094     kfd_exit();
0095 }