kfd_dbgmgr.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. */
  23. #ifndef KFD_DBGMGR_H_
  24. #define KFD_DBGMGR_H_
  25. #include "kfd_priv.h"
  26. /* must align with hsakmttypes definition */
  27. #pragma pack(push, 4)
  28. enum HSA_DBG_WAVEOP {
  29. HSA_DBG_WAVEOP_HALT = 1, /* Halts a wavefront */
  30. HSA_DBG_WAVEOP_RESUME = 2, /* Resumes a wavefront */
  31. HSA_DBG_WAVEOP_KILL = 3, /* Kills a wavefront */
  32. HSA_DBG_WAVEOP_DEBUG = 4, /* Causes wavefront to enter dbg mode */
  33. HSA_DBG_WAVEOP_TRAP = 5, /* Causes wavefront to take a trap */
  34. HSA_DBG_NUM_WAVEOP = 5,
  35. HSA_DBG_MAX_WAVEOP = 0xFFFFFFFF
  36. };
  37. enum HSA_DBG_WAVEMODE {
  38. /* send command to a single wave */
  39. HSA_DBG_WAVEMODE_SINGLE = 0,
  40. /*
  41. * Broadcast to all wavefronts of all processes is not
  42. * supported for HSA user mode
  43. */
  44. /* send to waves within current process */
  45. HSA_DBG_WAVEMODE_BROADCAST_PROCESS = 2,
  46. /* send to waves within current process on CU */
  47. HSA_DBG_WAVEMODE_BROADCAST_PROCESS_CU = 3,
  48. HSA_DBG_NUM_WAVEMODE = 3,
  49. HSA_DBG_MAX_WAVEMODE = 0xFFFFFFFF
  50. };
  51. enum HSA_DBG_WAVEMSG_TYPE {
  52. HSA_DBG_WAVEMSG_AUTO = 0,
  53. HSA_DBG_WAVEMSG_USER = 1,
  54. HSA_DBG_WAVEMSG_ERROR = 2,
  55. HSA_DBG_NUM_WAVEMSG,
  56. HSA_DBG_MAX_WAVEMSG = 0xFFFFFFFF
  57. };
  58. enum HSA_DBG_WATCH_MODE {
  59. HSA_DBG_WATCH_READ = 0, /* Read operations only */
  60. HSA_DBG_WATCH_NONREAD = 1, /* Write or Atomic operations only */
  61. HSA_DBG_WATCH_ATOMIC = 2, /* Atomic Operations only */
  62. HSA_DBG_WATCH_ALL = 3, /* Read, Write or Atomic operations */
  63. HSA_DBG_WATCH_NUM,
  64. HSA_DBG_WATCH_SIZE = 0xFFFFFFFF
  65. };
  66. /* This structure is hardware specific and may change in the future */
  67. struct HsaDbgWaveMsgAMDGen2 {
  68. union {
  69. struct ui32 {
  70. uint32_t UserData:8; /* user data */
  71. uint32_t ShaderArray:1; /* Shader array */
  72. uint32_t Priv:1; /* Privileged */
  73. uint32_t Reserved0:4; /* Reserved, should be 0 */
  74. uint32_t WaveId:4; /* wave id */
  75. uint32_t SIMD:2; /* SIMD id */
  76. uint32_t HSACU:4; /* Compute unit */
  77. uint32_t ShaderEngine:2;/* Shader engine */
  78. uint32_t MessageType:2; /* see HSA_DBG_WAVEMSG_TYPE */
  79. uint32_t Reserved1:4; /* Reserved, should be 0 */
  80. } ui32;
  81. uint32_t Value;
  82. };
  83. uint32_t Reserved2;
  84. };
  85. union HsaDbgWaveMessageAMD {
  86. struct HsaDbgWaveMsgAMDGen2 WaveMsgInfoGen2;
  87. /* for future HsaDbgWaveMsgAMDGen3; */
  88. };
  89. struct HsaDbgWaveMessage {
  90. void *MemoryVA; /* ptr to associated host-accessible data */
  91. union HsaDbgWaveMessageAMD DbgWaveMsg;
  92. };
  93. /*
  94. * TODO: This definitions to be MOVED to kfd_event, once it is implemented.
  95. *
  96. * HSA sync primitive, Event and HW Exception notification API definitions.
  97. * The API functions allow the runtime to define a so-called sync-primitive,
  98. * a SW object combining a user-mode provided "syncvar" and a scheduler event
  99. * that can be signaled through a defined GPU interrupt. A syncvar is
  100. * a process virtual memory location of a certain size that can be accessed
  101. * by CPU and GPU shader code within the process to set and query the content
  102. * within that memory. The definition of the content is determined by the HSA
  103. * runtime and potentially GPU shader code interfacing with the HSA runtime.
  104. * The syncvar values may be commonly written through an PM4 WRITE_DATA packet
  105. * in the user mode instruction stream. The OS scheduler event is typically
  106. * associated and signaled by an interrupt issued by the GPU, but other HSA
  107. * system interrupt conditions from other HW (e.g. IOMMUv2) may be surfaced
  108. * by the KFD by this mechanism, too.
  109. */
  110. /* these are the new definitions for events */
  111. enum HSA_EVENTTYPE {
  112. HSA_EVENTTYPE_SIGNAL = 0, /* user-mode generated GPU signal */
  113. HSA_EVENTTYPE_NODECHANGE = 1, /* HSA node change (attach/detach) */
  114. HSA_EVENTTYPE_DEVICESTATECHANGE = 2, /* HSA device state change
  115. * (start/stop)
  116. */
  117. HSA_EVENTTYPE_HW_EXCEPTION = 3, /* GPU shader exception event */
  118. HSA_EVENTTYPE_SYSTEM_EVENT = 4, /* GPU SYSCALL with parameter info */
  119. HSA_EVENTTYPE_DEBUG_EVENT = 5, /* GPU signal for debugging */
  120. HSA_EVENTTYPE_PROFILE_EVENT = 6,/* GPU signal for profiling */
  121. HSA_EVENTTYPE_QUEUE_EVENT = 7, /* GPU signal queue idle state
  122. * (EOP pm4)
  123. */
  124. /* ... */
  125. HSA_EVENTTYPE_MAXID,
  126. HSA_EVENTTYPE_TYPE_SIZE = 0xFFFFFFFF
  127. };
  128. /* Sub-definitions for various event types: Syncvar */
  129. struct HsaSyncVar {
  130. union SyncVar {
  131. void *UserData; /* pointer to user mode data */
  132. uint64_t UserDataPtrValue; /* 64bit compatibility of value */
  133. } SyncVar;
  134. uint64_t SyncVarSize;
  135. };
  136. /* Sub-definitions for various event types: NodeChange */
  137. enum HSA_EVENTTYPE_NODECHANGE_FLAGS {
  138. HSA_EVENTTYPE_NODECHANGE_ADD = 0,
  139. HSA_EVENTTYPE_NODECHANGE_REMOVE = 1,
  140. HSA_EVENTTYPE_NODECHANGE_SIZE = 0xFFFFFFFF
  141. };
  142. struct HsaNodeChange {
  143. /* HSA node added/removed on the platform */
  144. enum HSA_EVENTTYPE_NODECHANGE_FLAGS Flags;
  145. };
  146. /* Sub-definitions for various event types: DeviceStateChange */
  147. enum HSA_EVENTTYPE_DEVICESTATECHANGE_FLAGS {
  148. /* device started (and available) */
  149. HSA_EVENTTYPE_DEVICESTATUSCHANGE_START = 0,
  150. /* device stopped (i.e. unavailable) */
  151. HSA_EVENTTYPE_DEVICESTATUSCHANGE_STOP = 1,
  152. HSA_EVENTTYPE_DEVICESTATUSCHANGE_SIZE = 0xFFFFFFFF
  153. };
  154. enum HSA_DEVICE {
  155. HSA_DEVICE_CPU = 0,
  156. HSA_DEVICE_GPU = 1,
  157. MAX_HSA_DEVICE = 2
  158. };
  159. struct HsaDeviceStateChange {
  160. uint32_t NodeId; /* F-NUMA node that contains the device */
  161. enum HSA_DEVICE Device; /* device type: GPU or CPU */
  162. enum HSA_EVENTTYPE_DEVICESTATECHANGE_FLAGS Flags; /* event flags */
  163. };
  164. struct HsaEventData {
  165. enum HSA_EVENTTYPE EventType; /* event type */
  166. union EventData {
  167. /*
  168. * return data associated with HSA_EVENTTYPE_SIGNAL
  169. * and other events
  170. */
  171. struct HsaSyncVar SyncVar;
  172. /* data associated with HSA_EVENTTYPE_NODE_CHANGE */
  173. struct HsaNodeChange NodeChangeState;
  174. /* data associated with HSA_EVENTTYPE_DEVICE_STATE_CHANGE */
  175. struct HsaDeviceStateChange DeviceState;
  176. } EventData;
  177. /* the following data entries are internal to the KFD & thunk itself */
  178. /* internal thunk store for Event data (OsEventHandle) */
  179. uint64_t HWData1;
  180. /* internal thunk store for Event data (HWAddress) */
  181. uint64_t HWData2;
  182. /* internal thunk store for Event data (HWData) */
  183. uint32_t HWData3;
  184. };
  185. struct HsaEventDescriptor {
  186. /* event type to allocate */
  187. enum HSA_EVENTTYPE EventType;
  188. /* H-NUMA node containing GPU device that is event source */
  189. uint32_t NodeId;
  190. /* pointer to user mode syncvar data, syncvar->UserDataPtrValue
  191. * may be NULL
  192. */
  193. struct HsaSyncVar SyncVar;
  194. };
  195. struct HsaEvent {
  196. uint32_t EventId;
  197. struct HsaEventData EventData;
  198. };
  199. #pragma pack(pop)
  200. enum DBGDEV_TYPE {
  201. DBGDEV_TYPE_ILLEGAL = 0,
  202. DBGDEV_TYPE_NODIQ = 1,
  203. DBGDEV_TYPE_DIQ = 2,
  204. DBGDEV_TYPE_TEST = 3
  205. };
  206. struct dbg_address_watch_info {
  207. struct kfd_process *process;
  208. enum HSA_DBG_WATCH_MODE *watch_mode;
  209. uint64_t *watch_address;
  210. uint64_t *watch_mask;
  211. struct HsaEvent *watch_event;
  212. uint32_t num_watch_points;
  213. };
  214. struct dbg_wave_control_info {
  215. struct kfd_process *process;
  216. uint32_t trapId;
  217. enum HSA_DBG_WAVEOP operand;
  218. enum HSA_DBG_WAVEMODE mode;
  219. struct HsaDbgWaveMessage dbgWave_msg;
  220. };
  221. struct kfd_dbgdev {
  222. /* The device that owns this data. */
  223. struct kfd_dev *dev;
  224. /* kernel queue for DIQ */
  225. struct kernel_queue *kq;
  226. /* a pointer to the pqm of the calling process */
  227. struct process_queue_manager *pqm;
  228. /* type of debug device ( DIQ, non DIQ, etc. ) */
  229. enum DBGDEV_TYPE type;
  230. /* virtualized function pointers to device dbg */
  231. int (*dbgdev_register)(struct kfd_dbgdev *dbgdev);
  232. int (*dbgdev_unregister)(struct kfd_dbgdev *dbgdev);
  233. int (*dbgdev_address_watch)(struct kfd_dbgdev *dbgdev,
  234. struct dbg_address_watch_info *adw_info);
  235. int (*dbgdev_wave_control)(struct kfd_dbgdev *dbgdev,
  236. struct dbg_wave_control_info *wac_info);
  237. };
  238. struct kfd_dbgmgr {
  239. unsigned int pasid;
  240. struct kfd_dev *dev;
  241. struct kfd_dbgdev *dbgdev;
  242. };
  243. /* prototypes for debug manager functions */
  244. struct mutex *kfd_get_dbgmgr_mutex(void);
  245. void kfd_dbgmgr_destroy(struct kfd_dbgmgr *pmgr);
  246. bool kfd_dbgmgr_create(struct kfd_dbgmgr **ppmgr, struct kfd_dev *pdev);
  247. long kfd_dbgmgr_register(struct kfd_dbgmgr *pmgr, struct kfd_process *p);
  248. long kfd_dbgmgr_unregister(struct kfd_dbgmgr *pmgr, struct kfd_process *p);
  249. long kfd_dbgmgr_wave_control(struct kfd_dbgmgr *pmgr,
  250. struct dbg_wave_control_info *wac_info);
  251. long kfd_dbgmgr_address_watch(struct kfd_dbgmgr *pmgr,
  252. struct dbg_address_watch_info *adw_info);
  253. #endif /* KFD_DBGMGR_H_ */