kfd_module.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/module.h>
  23. #include <linux/sched.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/device.h>
  26. #include "kfd_priv.h"
  27. #define KFD_DRIVER_AUTHOR "AMD Inc. and others"
  28. #define KFD_DRIVER_DESC "Standalone HSA driver for AMD's GPUs"
  29. #define KFD_DRIVER_DATE "20141113"
  30. #define KFD_DRIVER_MAJOR 0
  31. #define KFD_DRIVER_MINOR 7
  32. #define KFD_DRIVER_PATCHLEVEL 0
  33. const struct kfd2kgd_calls *kfd2kgd;
  34. static const struct kgd2kfd_calls kgd2kfd = {
  35. .exit = kgd2kfd_exit,
  36. .probe = kgd2kfd_probe,
  37. .device_init = kgd2kfd_device_init,
  38. .device_exit = kgd2kfd_device_exit,
  39. .interrupt = kgd2kfd_interrupt,
  40. .suspend = kgd2kfd_suspend,
  41. .resume = kgd2kfd_resume,
  42. };
  43. int sched_policy = KFD_SCHED_POLICY_HWS;
  44. module_param(sched_policy, int, 0444);
  45. MODULE_PARM_DESC(sched_policy,
  46. "Kernel cmdline parameter that defines the amdkfd scheduling policy");
  47. int max_num_of_processes = KFD_MAX_NUM_OF_PROCESSES_DEFAULT;
  48. module_param(max_num_of_processes, int, 0444);
  49. MODULE_PARM_DESC(max_num_of_processes,
  50. "Kernel cmdline parameter that defines the amdkfd maximum number of supported processes");
  51. int max_num_of_queues_per_process = KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT;
  52. module_param(max_num_of_queues_per_process, int, 0444);
  53. MODULE_PARM_DESC(max_num_of_queues_per_process,
  54. "Kernel cmdline parameter that defines the amdkfd maximum number of supported queues per process");
  55. bool kgd2kfd_init(unsigned interface_version,
  56. const struct kfd2kgd_calls *f2g,
  57. const struct kgd2kfd_calls **g2f)
  58. {
  59. /*
  60. * Only one interface version is supported,
  61. * no kfd/kgd version skew allowed.
  62. */
  63. if (interface_version != KFD_INTERFACE_VERSION)
  64. return false;
  65. /* Protection against multiple amd kgd loads */
  66. if (kfd2kgd)
  67. return true;
  68. kfd2kgd = f2g;
  69. *g2f = &kgd2kfd;
  70. return true;
  71. }
  72. EXPORT_SYMBOL(kgd2kfd_init);
  73. void kgd2kfd_exit(void)
  74. {
  75. }
  76. static int __init kfd_module_init(void)
  77. {
  78. int err;
  79. kfd2kgd = NULL;
  80. /* Verify module parameters */
  81. if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
  82. (sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
  83. pr_err("kfd: sched_policy has invalid value\n");
  84. return -1;
  85. }
  86. /* Verify module parameters */
  87. if ((max_num_of_processes < 0) ||
  88. (max_num_of_processes > KFD_MAX_NUM_OF_PROCESSES)) {
  89. pr_err("kfd: max_num_of_processes must be between 0 to KFD_MAX_NUM_OF_PROCESSES\n");
  90. return -1;
  91. }
  92. if ((max_num_of_queues_per_process < 0) ||
  93. (max_num_of_queues_per_process >
  94. KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)) {
  95. pr_err("kfd: max_num_of_queues_per_process must be between 0 to KFD_MAX_NUM_OF_QUEUES_PER_PROCESS\n");
  96. return -1;
  97. }
  98. err = kfd_pasid_init();
  99. if (err < 0)
  100. goto err_pasid;
  101. err = kfd_chardev_init();
  102. if (err < 0)
  103. goto err_ioctl;
  104. err = kfd_topology_init();
  105. if (err < 0)
  106. goto err_topology;
  107. kfd_process_create_wq();
  108. dev_info(kfd_device, "Initialized module\n");
  109. return 0;
  110. err_topology:
  111. kfd_chardev_exit();
  112. err_ioctl:
  113. kfd_pasid_exit();
  114. err_pasid:
  115. return err;
  116. }
  117. static void __exit kfd_module_exit(void)
  118. {
  119. kfd_process_destroy_wq();
  120. kfd_topology_shutdown();
  121. kfd_chardev_exit();
  122. kfd_pasid_exit();
  123. dev_info(kfd_device, "Removed module\n");
  124. }
  125. module_init(kfd_module_init);
  126. module_exit(kfd_module_exit);
  127. MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
  128. MODULE_DESCRIPTION(KFD_DRIVER_DESC);
  129. MODULE_LICENSE("GPL and additional rights");
  130. MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
  131. __stringify(KFD_DRIVER_MINOR) "."
  132. __stringify(KFD_DRIVER_PATCHLEVEL));