1 1.1 riastrad /* $NetBSD: kfd_dbgmgr.h,v 1.3 2021/12/18 23:44:59 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2014 Advanced Micro Devices, Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad */ 25 1.1 riastrad 26 1.1 riastrad #ifndef KFD_DBGMGR_H_ 27 1.1 riastrad #define KFD_DBGMGR_H_ 28 1.1 riastrad 29 1.1 riastrad #include "kfd_priv.h" 30 1.1 riastrad 31 1.1 riastrad /* must align with hsakmttypes definition */ 32 1.1 riastrad #pragma pack(push, 4) 33 1.1 riastrad 34 1.1 riastrad enum HSA_DBG_WAVEOP { 35 1.3 riastrad HSA_DBG_WAVEOP_HALT = 1, /* Halts a wavefront */ 36 1.3 riastrad HSA_DBG_WAVEOP_RESUME = 2, /* Resumes a wavefront */ 37 1.3 riastrad HSA_DBG_WAVEOP_KILL = 3, /* Kills a wavefront */ 38 1.3 riastrad HSA_DBG_WAVEOP_DEBUG = 4, /* Causes wavefront to enter dbg mode */ 39 1.3 riastrad HSA_DBG_WAVEOP_TRAP = 5, /* Causes wavefront to take a trap */ 40 1.1 riastrad HSA_DBG_NUM_WAVEOP = 5, 41 1.1 riastrad HSA_DBG_MAX_WAVEOP = 0xFFFFFFFF 42 1.1 riastrad }; 43 1.1 riastrad 44 1.1 riastrad enum HSA_DBG_WAVEMODE { 45 1.1 riastrad /* send command to a single wave */ 46 1.1 riastrad HSA_DBG_WAVEMODE_SINGLE = 0, 47 1.1 riastrad /* 48 1.1 riastrad * Broadcast to all wavefronts of all processes is not 49 1.1 riastrad * supported for HSA user mode 50 1.1 riastrad */ 51 1.1 riastrad 52 1.1 riastrad /* send to waves within current process */ 53 1.1 riastrad HSA_DBG_WAVEMODE_BROADCAST_PROCESS = 2, 54 1.1 riastrad /* send to waves within current process on CU */ 55 1.1 riastrad HSA_DBG_WAVEMODE_BROADCAST_PROCESS_CU = 3, 56 1.1 riastrad HSA_DBG_NUM_WAVEMODE = 3, 57 1.1 riastrad HSA_DBG_MAX_WAVEMODE = 0xFFFFFFFF 58 1.1 riastrad }; 59 1.1 riastrad 60 1.1 riastrad enum HSA_DBG_WAVEMSG_TYPE { 61 1.1 riastrad HSA_DBG_WAVEMSG_AUTO = 0, 62 1.1 riastrad HSA_DBG_WAVEMSG_USER = 1, 63 1.1 riastrad HSA_DBG_WAVEMSG_ERROR = 2, 64 1.1 riastrad HSA_DBG_NUM_WAVEMSG, 65 1.1 riastrad HSA_DBG_MAX_WAVEMSG = 0xFFFFFFFF 66 1.1 riastrad }; 67 1.1 riastrad 68 1.1 riastrad enum HSA_DBG_WATCH_MODE { 69 1.1 riastrad HSA_DBG_WATCH_READ = 0, /* Read operations only */ 70 1.1 riastrad HSA_DBG_WATCH_NONREAD = 1, /* Write or Atomic operations only */ 71 1.1 riastrad HSA_DBG_WATCH_ATOMIC = 2, /* Atomic Operations only */ 72 1.1 riastrad HSA_DBG_WATCH_ALL = 3, /* Read, Write or Atomic operations */ 73 1.1 riastrad HSA_DBG_WATCH_NUM, 74 1.1 riastrad HSA_DBG_WATCH_SIZE = 0xFFFFFFFF 75 1.1 riastrad }; 76 1.1 riastrad 77 1.1 riastrad /* This structure is hardware specific and may change in the future */ 78 1.1 riastrad struct HsaDbgWaveMsgAMDGen2 { 79 1.1 riastrad union { 80 1.1 riastrad struct ui32 { 81 1.1 riastrad uint32_t UserData:8; /* user data */ 82 1.1 riastrad uint32_t ShaderArray:1; /* Shader array */ 83 1.1 riastrad uint32_t Priv:1; /* Privileged */ 84 1.3 riastrad uint32_t Reserved0:4; /* Reserved, should be 0 */ 85 1.1 riastrad uint32_t WaveId:4; /* wave id */ 86 1.1 riastrad uint32_t SIMD:2; /* SIMD id */ 87 1.1 riastrad uint32_t HSACU:4; /* Compute unit */ 88 1.1 riastrad uint32_t ShaderEngine:2;/* Shader engine */ 89 1.1 riastrad uint32_t MessageType:2; /* see HSA_DBG_WAVEMSG_TYPE */ 90 1.3 riastrad uint32_t Reserved1:4; /* Reserved, should be 0 */ 91 1.1 riastrad } ui32; 92 1.1 riastrad uint32_t Value; 93 1.1 riastrad }; 94 1.1 riastrad uint32_t Reserved2; 95 1.1 riastrad }; 96 1.1 riastrad 97 1.1 riastrad union HsaDbgWaveMessageAMD { 98 1.1 riastrad struct HsaDbgWaveMsgAMDGen2 WaveMsgInfoGen2; 99 1.1 riastrad /* for future HsaDbgWaveMsgAMDGen3; */ 100 1.1 riastrad }; 101 1.1 riastrad 102 1.1 riastrad struct HsaDbgWaveMessage { 103 1.1 riastrad void *MemoryVA; /* ptr to associated host-accessible data */ 104 1.1 riastrad union HsaDbgWaveMessageAMD DbgWaveMsg; 105 1.1 riastrad }; 106 1.1 riastrad 107 1.1 riastrad /* 108 1.1 riastrad * TODO: This definitions to be MOVED to kfd_event, once it is implemented. 109 1.1 riastrad * 110 1.1 riastrad * HSA sync primitive, Event and HW Exception notification API definitions. 111 1.1 riastrad * The API functions allow the runtime to define a so-called sync-primitive, 112 1.1 riastrad * a SW object combining a user-mode provided "syncvar" and a scheduler event 113 1.1 riastrad * that can be signaled through a defined GPU interrupt. A syncvar is 114 1.1 riastrad * a process virtual memory location of a certain size that can be accessed 115 1.1 riastrad * by CPU and GPU shader code within the process to set and query the content 116 1.1 riastrad * within that memory. The definition of the content is determined by the HSA 117 1.1 riastrad * runtime and potentially GPU shader code interfacing with the HSA runtime. 118 1.1 riastrad * The syncvar values may be commonly written through an PM4 WRITE_DATA packet 119 1.1 riastrad * in the user mode instruction stream. The OS scheduler event is typically 120 1.1 riastrad * associated and signaled by an interrupt issued by the GPU, but other HSA 121 1.1 riastrad * system interrupt conditions from other HW (e.g. IOMMUv2) may be surfaced 122 1.3 riastrad * by the KFD by this mechanism, too. 123 1.3 riastrad */ 124 1.1 riastrad 125 1.1 riastrad /* these are the new definitions for events */ 126 1.1 riastrad enum HSA_EVENTTYPE { 127 1.1 riastrad HSA_EVENTTYPE_SIGNAL = 0, /* user-mode generated GPU signal */ 128 1.1 riastrad HSA_EVENTTYPE_NODECHANGE = 1, /* HSA node change (attach/detach) */ 129 1.1 riastrad HSA_EVENTTYPE_DEVICESTATECHANGE = 2, /* HSA device state change 130 1.3 riastrad * (start/stop) 131 1.3 riastrad */ 132 1.1 riastrad HSA_EVENTTYPE_HW_EXCEPTION = 3, /* GPU shader exception event */ 133 1.1 riastrad HSA_EVENTTYPE_SYSTEM_EVENT = 4, /* GPU SYSCALL with parameter info */ 134 1.1 riastrad HSA_EVENTTYPE_DEBUG_EVENT = 5, /* GPU signal for debugging */ 135 1.1 riastrad HSA_EVENTTYPE_PROFILE_EVENT = 6,/* GPU signal for profiling */ 136 1.1 riastrad HSA_EVENTTYPE_QUEUE_EVENT = 7, /* GPU signal queue idle state 137 1.3 riastrad * (EOP pm4) 138 1.3 riastrad */ 139 1.1 riastrad /* ... */ 140 1.1 riastrad HSA_EVENTTYPE_MAXID, 141 1.1 riastrad HSA_EVENTTYPE_TYPE_SIZE = 0xFFFFFFFF 142 1.1 riastrad }; 143 1.1 riastrad 144 1.1 riastrad /* Sub-definitions for various event types: Syncvar */ 145 1.1 riastrad struct HsaSyncVar { 146 1.1 riastrad union SyncVar { 147 1.1 riastrad void *UserData; /* pointer to user mode data */ 148 1.1 riastrad uint64_t UserDataPtrValue; /* 64bit compatibility of value */ 149 1.1 riastrad } SyncVar; 150 1.1 riastrad uint64_t SyncVarSize; 151 1.1 riastrad }; 152 1.1 riastrad 153 1.1 riastrad /* Sub-definitions for various event types: NodeChange */ 154 1.1 riastrad 155 1.1 riastrad enum HSA_EVENTTYPE_NODECHANGE_FLAGS { 156 1.1 riastrad HSA_EVENTTYPE_NODECHANGE_ADD = 0, 157 1.1 riastrad HSA_EVENTTYPE_NODECHANGE_REMOVE = 1, 158 1.1 riastrad HSA_EVENTTYPE_NODECHANGE_SIZE = 0xFFFFFFFF 159 1.1 riastrad }; 160 1.1 riastrad 161 1.1 riastrad struct HsaNodeChange { 162 1.1 riastrad /* HSA node added/removed on the platform */ 163 1.1 riastrad enum HSA_EVENTTYPE_NODECHANGE_FLAGS Flags; 164 1.1 riastrad }; 165 1.1 riastrad 166 1.1 riastrad /* Sub-definitions for various event types: DeviceStateChange */ 167 1.1 riastrad enum HSA_EVENTTYPE_DEVICESTATECHANGE_FLAGS { 168 1.1 riastrad /* device started (and available) */ 169 1.1 riastrad HSA_EVENTTYPE_DEVICESTATUSCHANGE_START = 0, 170 1.1 riastrad /* device stopped (i.e. unavailable) */ 171 1.1 riastrad HSA_EVENTTYPE_DEVICESTATUSCHANGE_STOP = 1, 172 1.1 riastrad HSA_EVENTTYPE_DEVICESTATUSCHANGE_SIZE = 0xFFFFFFFF 173 1.1 riastrad }; 174 1.1 riastrad 175 1.1 riastrad enum HSA_DEVICE { 176 1.1 riastrad HSA_DEVICE_CPU = 0, 177 1.1 riastrad HSA_DEVICE_GPU = 1, 178 1.1 riastrad MAX_HSA_DEVICE = 2 179 1.1 riastrad }; 180 1.1 riastrad 181 1.1 riastrad struct HsaDeviceStateChange { 182 1.1 riastrad uint32_t NodeId; /* F-NUMA node that contains the device */ 183 1.1 riastrad enum HSA_DEVICE Device; /* device type: GPU or CPU */ 184 1.1 riastrad enum HSA_EVENTTYPE_DEVICESTATECHANGE_FLAGS Flags; /* event flags */ 185 1.1 riastrad }; 186 1.1 riastrad 187 1.1 riastrad struct HsaEventData { 188 1.1 riastrad enum HSA_EVENTTYPE EventType; /* event type */ 189 1.1 riastrad union EventData { 190 1.1 riastrad /* 191 1.1 riastrad * return data associated with HSA_EVENTTYPE_SIGNAL 192 1.1 riastrad * and other events 193 1.1 riastrad */ 194 1.1 riastrad struct HsaSyncVar SyncVar; 195 1.1 riastrad 196 1.1 riastrad /* data associated with HSA_EVENTTYPE_NODE_CHANGE */ 197 1.1 riastrad struct HsaNodeChange NodeChangeState; 198 1.1 riastrad 199 1.1 riastrad /* data associated with HSA_EVENTTYPE_DEVICE_STATE_CHANGE */ 200 1.1 riastrad struct HsaDeviceStateChange DeviceState; 201 1.1 riastrad } EventData; 202 1.1 riastrad 203 1.1 riastrad /* the following data entries are internal to the KFD & thunk itself */ 204 1.1 riastrad 205 1.1 riastrad /* internal thunk store for Event data (OsEventHandle) */ 206 1.1 riastrad uint64_t HWData1; 207 1.1 riastrad /* internal thunk store for Event data (HWAddress) */ 208 1.1 riastrad uint64_t HWData2; 209 1.1 riastrad /* internal thunk store for Event data (HWData) */ 210 1.1 riastrad uint32_t HWData3; 211 1.1 riastrad }; 212 1.1 riastrad 213 1.1 riastrad struct HsaEventDescriptor { 214 1.1 riastrad /* event type to allocate */ 215 1.1 riastrad enum HSA_EVENTTYPE EventType; 216 1.1 riastrad /* H-NUMA node containing GPU device that is event source */ 217 1.1 riastrad uint32_t NodeId; 218 1.1 riastrad /* pointer to user mode syncvar data, syncvar->UserDataPtrValue 219 1.1 riastrad * may be NULL 220 1.1 riastrad */ 221 1.1 riastrad struct HsaSyncVar SyncVar; 222 1.1 riastrad }; 223 1.1 riastrad 224 1.1 riastrad struct HsaEvent { 225 1.1 riastrad uint32_t EventId; 226 1.1 riastrad struct HsaEventData EventData; 227 1.1 riastrad }; 228 1.1 riastrad 229 1.1 riastrad #pragma pack(pop) 230 1.1 riastrad 231 1.1 riastrad enum DBGDEV_TYPE { 232 1.1 riastrad DBGDEV_TYPE_ILLEGAL = 0, 233 1.1 riastrad DBGDEV_TYPE_NODIQ = 1, 234 1.1 riastrad DBGDEV_TYPE_DIQ = 2, 235 1.1 riastrad DBGDEV_TYPE_TEST = 3 236 1.1 riastrad }; 237 1.1 riastrad 238 1.1 riastrad struct dbg_address_watch_info { 239 1.1 riastrad struct kfd_process *process; 240 1.1 riastrad enum HSA_DBG_WATCH_MODE *watch_mode; 241 1.1 riastrad uint64_t *watch_address; 242 1.1 riastrad uint64_t *watch_mask; 243 1.1 riastrad struct HsaEvent *watch_event; 244 1.1 riastrad uint32_t num_watch_points; 245 1.1 riastrad }; 246 1.1 riastrad 247 1.1 riastrad struct dbg_wave_control_info { 248 1.1 riastrad struct kfd_process *process; 249 1.1 riastrad uint32_t trapId; 250 1.1 riastrad enum HSA_DBG_WAVEOP operand; 251 1.1 riastrad enum HSA_DBG_WAVEMODE mode; 252 1.1 riastrad struct HsaDbgWaveMessage dbgWave_msg; 253 1.1 riastrad }; 254 1.1 riastrad 255 1.1 riastrad struct kfd_dbgdev { 256 1.1 riastrad 257 1.1 riastrad /* The device that owns this data. */ 258 1.1 riastrad struct kfd_dev *dev; 259 1.1 riastrad 260 1.1 riastrad /* kernel queue for DIQ */ 261 1.1 riastrad struct kernel_queue *kq; 262 1.1 riastrad 263 1.1 riastrad /* a pointer to the pqm of the calling process */ 264 1.1 riastrad struct process_queue_manager *pqm; 265 1.1 riastrad 266 1.1 riastrad /* type of debug device ( DIQ, non DIQ, etc. ) */ 267 1.1 riastrad enum DBGDEV_TYPE type; 268 1.1 riastrad 269 1.1 riastrad /* virtualized function pointers to device dbg */ 270 1.1 riastrad int (*dbgdev_register)(struct kfd_dbgdev *dbgdev); 271 1.1 riastrad int (*dbgdev_unregister)(struct kfd_dbgdev *dbgdev); 272 1.1 riastrad int (*dbgdev_address_watch)(struct kfd_dbgdev *dbgdev, 273 1.1 riastrad struct dbg_address_watch_info *adw_info); 274 1.1 riastrad int (*dbgdev_wave_control)(struct kfd_dbgdev *dbgdev, 275 1.1 riastrad struct dbg_wave_control_info *wac_info); 276 1.1 riastrad 277 1.1 riastrad }; 278 1.1 riastrad 279 1.1 riastrad struct kfd_dbgmgr { 280 1.1 riastrad unsigned int pasid; 281 1.1 riastrad struct kfd_dev *dev; 282 1.1 riastrad struct kfd_dbgdev *dbgdev; 283 1.1 riastrad }; 284 1.1 riastrad 285 1.1 riastrad /* prototypes for debug manager functions */ 286 1.1 riastrad struct mutex *kfd_get_dbgmgr_mutex(void); 287 1.1 riastrad void kfd_dbgmgr_destroy(struct kfd_dbgmgr *pmgr); 288 1.1 riastrad bool kfd_dbgmgr_create(struct kfd_dbgmgr **ppmgr, struct kfd_dev *pdev); 289 1.1 riastrad long kfd_dbgmgr_register(struct kfd_dbgmgr *pmgr, struct kfd_process *p); 290 1.1 riastrad long kfd_dbgmgr_unregister(struct kfd_dbgmgr *pmgr, struct kfd_process *p); 291 1.1 riastrad long kfd_dbgmgr_wave_control(struct kfd_dbgmgr *pmgr, 292 1.1 riastrad struct dbg_wave_control_info *wac_info); 293 1.1 riastrad long kfd_dbgmgr_address_watch(struct kfd_dbgmgr *pmgr, 294 1.1 riastrad struct dbg_address_watch_info *adw_info); 295 1.1 riastrad #endif /* KFD_DBGMGR_H_ */ 296