18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2014 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include <linux/sched.h> 248c2ecf20Sopenharmony_ci#include <linux/device.h> 258c2ecf20Sopenharmony_ci#include "kfd_priv.h" 268c2ecf20Sopenharmony_ci#include "amdgpu_amdkfd.h" 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic int kfd_init(void) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci int err; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci /* Verify module parameters */ 338c2ecf20Sopenharmony_ci if ((sched_policy < KFD_SCHED_POLICY_HWS) || 348c2ecf20Sopenharmony_ci (sched_policy > KFD_SCHED_POLICY_NO_HWS)) { 358c2ecf20Sopenharmony_ci pr_err("sched_policy has invalid value\n"); 368c2ecf20Sopenharmony_ci return -EINVAL; 378c2ecf20Sopenharmony_ci } 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci /* Verify module parameters */ 408c2ecf20Sopenharmony_ci if ((max_num_of_queues_per_device < 1) || 418c2ecf20Sopenharmony_ci (max_num_of_queues_per_device > 428c2ecf20Sopenharmony_ci KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) { 438c2ecf20Sopenharmony_ci pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n"); 448c2ecf20Sopenharmony_ci return -EINVAL; 458c2ecf20Sopenharmony_ci } 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci err = kfd_chardev_init(); 488c2ecf20Sopenharmony_ci if (err < 0) 498c2ecf20Sopenharmony_ci goto err_ioctl; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci err = kfd_topology_init(); 528c2ecf20Sopenharmony_ci if (err < 0) 538c2ecf20Sopenharmony_ci goto err_topology; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci err = kfd_process_create_wq(); 568c2ecf20Sopenharmony_ci if (err < 0) 578c2ecf20Sopenharmony_ci goto err_create_wq; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* Ignore the return value, so that we can continue 608c2ecf20Sopenharmony_ci * to init the KFD, even if procfs isn't craated 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_ci kfd_procfs_init(); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci kfd_debugfs_init(); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci return 0; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cierr_create_wq: 698c2ecf20Sopenharmony_ci kfd_topology_shutdown(); 708c2ecf20Sopenharmony_cierr_topology: 718c2ecf20Sopenharmony_ci kfd_chardev_exit(); 728c2ecf20Sopenharmony_cierr_ioctl: 738c2ecf20Sopenharmony_ci pr_err("KFD is disabled due to module initialization failure\n"); 748c2ecf20Sopenharmony_ci return err; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic void kfd_exit(void) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci kfd_debugfs_fini(); 808c2ecf20Sopenharmony_ci kfd_process_destroy_wq(); 818c2ecf20Sopenharmony_ci kfd_procfs_shutdown(); 828c2ecf20Sopenharmony_ci kfd_topology_shutdown(); 838c2ecf20Sopenharmony_ci kfd_chardev_exit(); 848c2ecf20Sopenharmony_ci} 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ciint kgd2kfd_init(void) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci return kfd_init(); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_civoid kgd2kfd_exit(void) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci kfd_exit(); 948c2ecf20Sopenharmony_ci} 95