kfd_module.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 <linux/printk.h>
  27. #include "kfd_priv.h"
  28. #define KFD_DRIVER_AUTHOR "AMD Inc. and others"
  29. #define KFD_DRIVER_DESC "Standalone HSA driver for AMD's GPUs"
  30. #define KFD_DRIVER_DATE "20150421"
  31. #define KFD_DRIVER_MAJOR 0
  32. #define KFD_DRIVER_MINOR 7
  33. #define KFD_DRIVER_PATCHLEVEL 2
  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. .quiesce_mm = kgd2kfd_quiesce_mm,
  43. .resume_mm = kgd2kfd_resume_mm,
  44. .schedule_evict_and_restore_process =
  45. kgd2kfd_schedule_evict_and_restore_process,
  46. .pre_reset = kgd2kfd_pre_reset,
  47. .post_reset = kgd2kfd_post_reset,
  48. };
  49. int sched_policy = KFD_SCHED_POLICY_HWS;
  50. module_param(sched_policy, int, 0444);
  51. MODULE_PARM_DESC(sched_policy,
  52. "Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
  53. int hws_max_conc_proc = 8;
  54. module_param(hws_max_conc_proc, int, 0444);
  55. MODULE_PARM_DESC(hws_max_conc_proc,
  56. "Max # processes HWS can execute concurrently when sched_policy=0 (0 = no concurrency, #VMIDs for KFD = Maximum(default))");
  57. int cwsr_enable = 1;
  58. module_param(cwsr_enable, int, 0444);
  59. MODULE_PARM_DESC(cwsr_enable, "CWSR enable (0 = off, 1 = on (default))");
  60. int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
  61. module_param(max_num_of_queues_per_device, int, 0444);
  62. MODULE_PARM_DESC(max_num_of_queues_per_device,
  63. "Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
  64. int send_sigterm;
  65. module_param(send_sigterm, int, 0444);
  66. MODULE_PARM_DESC(send_sigterm,
  67. "Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)");
  68. int debug_largebar;
  69. module_param(debug_largebar, int, 0444);
  70. MODULE_PARM_DESC(debug_largebar,
  71. "Debug large-bar flag used to simulate large-bar capability on non-large bar machine (0 = disable, 1 = enable)");
  72. int ignore_crat;
  73. module_param(ignore_crat, int, 0444);
  74. MODULE_PARM_DESC(ignore_crat,
  75. "Ignore CRAT table during KFD initialization (0 = use CRAT (default), 1 = ignore CRAT)");
  76. int noretry;
  77. module_param(noretry, int, 0644);
  78. MODULE_PARM_DESC(noretry,
  79. "Set sh_mem_config.retry_disable on GFXv9+ dGPUs (0 = retry enabled (default), 1 = retry disabled)");
  80. int halt_if_hws_hang;
  81. module_param(halt_if_hws_hang, int, 0644);
  82. MODULE_PARM_DESC(halt_if_hws_hang, "Halt if HWS hang is detected (0 = off (default), 1 = on)");
  83. static int amdkfd_init_completed;
  84. int kgd2kfd_init(unsigned int interface_version,
  85. const struct kgd2kfd_calls **g2f)
  86. {
  87. if (!amdkfd_init_completed)
  88. return -EPROBE_DEFER;
  89. /*
  90. * Only one interface version is supported,
  91. * no kfd/kgd version skew allowed.
  92. */
  93. if (interface_version != KFD_INTERFACE_VERSION)
  94. return -EINVAL;
  95. *g2f = &kgd2kfd;
  96. return 0;
  97. }
  98. EXPORT_SYMBOL(kgd2kfd_init);
  99. void kgd2kfd_exit(void)
  100. {
  101. }
  102. static int __init kfd_module_init(void)
  103. {
  104. int err;
  105. /* Verify module parameters */
  106. if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
  107. (sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
  108. pr_err("sched_policy has invalid value\n");
  109. return -1;
  110. }
  111. /* Verify module parameters */
  112. if ((max_num_of_queues_per_device < 1) ||
  113. (max_num_of_queues_per_device >
  114. KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
  115. pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
  116. return -1;
  117. }
  118. err = kfd_chardev_init();
  119. if (err < 0)
  120. goto err_ioctl;
  121. err = kfd_topology_init();
  122. if (err < 0)
  123. goto err_topology;
  124. err = kfd_process_create_wq();
  125. if (err < 0)
  126. goto err_create_wq;
  127. kfd_debugfs_init();
  128. amdkfd_init_completed = 1;
  129. dev_info(kfd_device, "Initialized module\n");
  130. return 0;
  131. err_create_wq:
  132. kfd_topology_shutdown();
  133. err_topology:
  134. kfd_chardev_exit();
  135. err_ioctl:
  136. return err;
  137. }
  138. static void __exit kfd_module_exit(void)
  139. {
  140. amdkfd_init_completed = 0;
  141. kfd_debugfs_fini();
  142. kfd_process_destroy_wq();
  143. kfd_topology_shutdown();
  144. kfd_chardev_exit();
  145. pr_info("amdkfd: Removed module\n");
  146. }
  147. module_init(kfd_module_init);
  148. module_exit(kfd_module_exit);
  149. MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
  150. MODULE_DESCRIPTION(KFD_DRIVER_DESC);
  151. MODULE_LICENSE("GPL and additional rights");
  152. MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
  153. __stringify(KFD_DRIVER_MINOR) "."
  154. __stringify(KFD_DRIVER_PATCHLEVEL));