kfd_dbgmgr.h 9.2 KB

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