kfd_module.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0 OR MIT
  2. /*
  3. * Copyright 2014-2022 Advanced Micro Devices, Inc.
  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. #include <linux/sched.h>
  24. #include <linux/device.h>
  25. #include "kfd_priv.h"
  26. #include "amdgpu_amdkfd.h"
  27. static int kfd_init(void)
  28. {
  29. int err;
  30. /* Verify module parameters */
  31. if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
  32. (sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
  33. pr_err("sched_policy has invalid value\n");
  34. return -EINVAL;
  35. }
  36. /* Verify module parameters */
  37. if ((max_num_of_queues_per_device < 1) ||
  38. (max_num_of_queues_per_device >
  39. KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
  40. pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
  41. return -EINVAL;
  42. }
  43. err = kfd_chardev_init();
  44. if (err < 0)
  45. goto err_ioctl;
  46. err = kfd_topology_init();
  47. if (err < 0)
  48. goto err_topology;
  49. err = kfd_process_create_wq();
  50. if (err < 0)
  51. goto err_create_wq;
  52. /* Ignore the return value, so that we can continue
  53. * to init the KFD, even if procfs isn't craated
  54. */
  55. kfd_procfs_init();
  56. kfd_debugfs_init();
  57. return 0;
  58. err_create_wq:
  59. kfd_topology_shutdown();
  60. err_topology:
  61. kfd_chardev_exit();
  62. err_ioctl:
  63. pr_err("KFD is disabled due to module initialization failure\n");
  64. return err;
  65. }
  66. static void kfd_exit(void)
  67. {
  68. kfd_cleanup_processes();
  69. kfd_process_destroy_wq();
  70. kfd_debugfs_fini();
  71. kfd_procfs_shutdown();
  72. kfd_topology_shutdown();
  73. kfd_chardev_exit();
  74. }
  75. int kgd2kfd_init(void)
  76. {
  77. return kfd_init();
  78. }
  79. void kgd2kfd_exit(void)
  80. {
  81. kfd_exit();
  82. }