162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 OR MIT 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2014-2022 Advanced Micro Devices, Inc. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 662306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 762306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 862306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 962306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 1062306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 1362306a36Sopenharmony_ci * all copies or substantial portions of the Software. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1662306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1762306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1862306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1962306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2062306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2162306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2262306a36Sopenharmony_ci */ 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#include <linux/sched.h> 2562306a36Sopenharmony_ci#include <linux/device.h> 2662306a36Sopenharmony_ci#include "kfd_priv.h" 2762306a36Sopenharmony_ci#include "amdgpu_amdkfd.h" 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cistatic int kfd_init(void) 3062306a36Sopenharmony_ci{ 3162306a36Sopenharmony_ci int err; 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci /* Verify module parameters */ 3462306a36Sopenharmony_ci if ((sched_policy < KFD_SCHED_POLICY_HWS) || 3562306a36Sopenharmony_ci (sched_policy > KFD_SCHED_POLICY_NO_HWS)) { 3662306a36Sopenharmony_ci pr_err("sched_policy has invalid value\n"); 3762306a36Sopenharmony_ci return -EINVAL; 3862306a36Sopenharmony_ci } 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci /* Verify module parameters */ 4162306a36Sopenharmony_ci if ((max_num_of_queues_per_device < 1) || 4262306a36Sopenharmony_ci (max_num_of_queues_per_device > 4362306a36Sopenharmony_ci KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) { 4462306a36Sopenharmony_ci pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n"); 4562306a36Sopenharmony_ci return -EINVAL; 4662306a36Sopenharmony_ci } 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci err = kfd_chardev_init(); 4962306a36Sopenharmony_ci if (err < 0) 5062306a36Sopenharmony_ci goto err_ioctl; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci err = kfd_topology_init(); 5362306a36Sopenharmony_ci if (err < 0) 5462306a36Sopenharmony_ci goto err_topology; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci err = kfd_process_create_wq(); 5762306a36Sopenharmony_ci if (err < 0) 5862306a36Sopenharmony_ci goto err_create_wq; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci /* Ignore the return value, so that we can continue 6162306a36Sopenharmony_ci * to init the KFD, even if procfs isn't craated 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_ci kfd_procfs_init(); 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci kfd_debugfs_init(); 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci return 0; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cierr_create_wq: 7062306a36Sopenharmony_ci kfd_topology_shutdown(); 7162306a36Sopenharmony_cierr_topology: 7262306a36Sopenharmony_ci kfd_chardev_exit(); 7362306a36Sopenharmony_cierr_ioctl: 7462306a36Sopenharmony_ci pr_err("KFD is disabled due to module initialization failure\n"); 7562306a36Sopenharmony_ci return err; 7662306a36Sopenharmony_ci} 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_cistatic void kfd_exit(void) 7962306a36Sopenharmony_ci{ 8062306a36Sopenharmony_ci kfd_cleanup_processes(); 8162306a36Sopenharmony_ci kfd_debugfs_fini(); 8262306a36Sopenharmony_ci kfd_process_destroy_wq(); 8362306a36Sopenharmony_ci kfd_procfs_shutdown(); 8462306a36Sopenharmony_ci kfd_topology_shutdown(); 8562306a36Sopenharmony_ci kfd_chardev_exit(); 8662306a36Sopenharmony_ci} 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciint kgd2kfd_init(void) 8962306a36Sopenharmony_ci{ 9062306a36Sopenharmony_ci return kfd_init(); 9162306a36Sopenharmony_ci} 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_civoid kgd2kfd_exit(void) 9462306a36Sopenharmony_ci{ 9562306a36Sopenharmony_ci kfd_exit(); 9662306a36Sopenharmony_ci} 97