kfd_module.c 2.8 KB

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