kfd_debug.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2023 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. #ifndef KFD_DEBUG_EVENTS_H_INCLUDED
  23. #define KFD_DEBUG_EVENTS_H_INCLUDED
  24. #include "kfd_priv.h"
  25. void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwind_count);
  26. int kfd_dbg_trap_activate(struct kfd_process *target);
  27. int kfd_dbg_ev_query_debug_event(struct kfd_process *process,
  28. unsigned int *queue_id,
  29. unsigned int *gpu_id,
  30. uint64_t exception_clear_mask,
  31. uint64_t *event_status);
  32. bool kfd_set_dbg_ev_from_interrupt(struct kfd_node *dev,
  33. unsigned int pasid,
  34. uint32_t doorbell_id,
  35. uint64_t trap_mask,
  36. void *exception_data,
  37. size_t exception_data_size);
  38. bool kfd_dbg_ev_raise(uint64_t event_mask,
  39. struct kfd_process *process, struct kfd_node *dev,
  40. unsigned int source_id, bool use_worker,
  41. void *exception_data,
  42. size_t exception_data_size);
  43. int kfd_dbg_trap_disable(struct kfd_process *target);
  44. int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
  45. void __user *runtime_info,
  46. uint32_t *runtime_info_size);
  47. int kfd_dbg_trap_set_wave_launch_override(struct kfd_process *target,
  48. uint32_t trap_override,
  49. uint32_t trap_mask_bits,
  50. uint32_t trap_mask_request,
  51. uint32_t *trap_mask_prev,
  52. uint32_t *trap_mask_supported);
  53. int kfd_dbg_trap_set_wave_launch_mode(struct kfd_process *target,
  54. uint8_t wave_launch_mode);
  55. int kfd_dbg_trap_clear_dev_address_watch(struct kfd_process_device *pdd,
  56. uint32_t watch_id);
  57. int kfd_dbg_trap_set_dev_address_watch(struct kfd_process_device *pdd,
  58. uint64_t watch_address,
  59. uint32_t watch_address_mask,
  60. uint32_t *watch_id,
  61. uint32_t watch_mode);
  62. int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags);
  63. int kfd_dbg_trap_query_exception_info(struct kfd_process *target,
  64. uint32_t source_id,
  65. uint32_t exception_code,
  66. bool clear_exception,
  67. void __user *info,
  68. uint32_t *info_size);
  69. int kfd_dbg_send_exception_to_runtime(struct kfd_process *p,
  70. unsigned int dev_id,
  71. unsigned int queue_id,
  72. uint64_t error_reason);
  73. static inline bool kfd_dbg_is_per_vmid_supported(struct kfd_node *dev)
  74. {
  75. return (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
  76. KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 3) ||
  77. KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 4) ||
  78. KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0));
  79. }
  80. void debug_event_write_work_handler(struct work_struct *work);
  81. int kfd_dbg_trap_device_snapshot(struct kfd_process *target,
  82. uint64_t exception_clear_mask,
  83. void __user *user_info,
  84. uint32_t *number_of_device_infos,
  85. uint32_t *entry_size);
  86. void kfd_dbg_set_enabled_debug_exception_mask(struct kfd_process *target,
  87. uint64_t exception_set_mask);
  88. /*
  89. * If GFX off is enabled, chips that do not support RLC restore for the debug
  90. * registers will disable GFX off temporarily for the entire debug session.
  91. * See disable_on_trap_action_entry and enable_on_trap_action_exit for details.
  92. */
  93. static inline bool kfd_dbg_is_rlc_restore_supported(struct kfd_node *dev)
  94. {
  95. return !(KFD_GC_VERSION(dev) == IP_VERSION(10, 1, 10) ||
  96. KFD_GC_VERSION(dev) == IP_VERSION(10, 1, 1));
  97. }
  98. static inline bool kfd_dbg_has_cwsr_workaround(struct kfd_node *dev)
  99. {
  100. return KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0) &&
  101. KFD_GC_VERSION(dev) <= IP_VERSION(11, 0, 3);
  102. }
  103. static inline bool kfd_dbg_has_gws_support(struct kfd_node *dev)
  104. {
  105. if ((KFD_GC_VERSION(dev) == IP_VERSION(9, 0, 1)
  106. && dev->kfd->mec2_fw_version < 0x81b6) ||
  107. (KFD_GC_VERSION(dev) >= IP_VERSION(9, 1, 0)
  108. && KFD_GC_VERSION(dev) <= IP_VERSION(9, 2, 2)
  109. && dev->kfd->mec2_fw_version < 0x1b6) ||
  110. (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0)
  111. && dev->kfd->mec2_fw_version < 0x1b6) ||
  112. (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1)
  113. && dev->kfd->mec2_fw_version < 0x30) ||
  114. (KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0) &&
  115. KFD_GC_VERSION(dev) < IP_VERSION(12, 0, 0)))
  116. return false;
  117. /* Assume debugging and cooperative launch supported otherwise. */
  118. return true;
  119. }
  120. int kfd_dbg_set_mes_debug_mode(struct kfd_process_device *pdd, bool sq_trap_en);
  121. static inline bool kfd_dbg_has_ttmps_always_setup(struct kfd_node *dev)
  122. {
  123. return (KFD_GC_VERSION(dev) < IP_VERSION(11, 0, 0) &&
  124. KFD_GC_VERSION(dev) != IP_VERSION(9, 4, 2)) ||
  125. (KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0) &&
  126. KFD_GC_VERSION(dev) < IP_VERSION(12, 0, 0) &&
  127. (dev->adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >= 70) ||
  128. (KFD_GC_VERSION(dev) >= IP_VERSION(12, 0, 0));
  129. }
  130. #endif