2 * Copyright 2014 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
29 /* must align with hsakmttypes definition */
33 HSA_DBG_WAVEOP_HALT = 1, /* Halts a wavefront */
34 HSA_DBG_WAVEOP_RESUME = 2, /* Resumes a wavefront */
35 HSA_DBG_WAVEOP_KILL = 3, /* Kills a wavefront */
36 HSA_DBG_WAVEOP_DEBUG = 4, /* Causes wavefront to enter
38 HSA_DBG_WAVEOP_TRAP = 5, /* Causes wavefront to take
40 HSA_DBG_NUM_WAVEOP = 5,
41 HSA_DBG_MAX_WAVEOP = 0xFFFFFFFF
44 enum HSA_DBG_WAVEMODE {
45 /* send command to a single wave */
46 HSA_DBG_WAVEMODE_SINGLE = 0,
48 * Broadcast to all wavefronts of all processes is not
49 * supported for HSA user mode
52 /* send to waves within current process */
53 HSA_DBG_WAVEMODE_BROADCAST_PROCESS = 2,
54 /* send to waves within current process on CU */
55 HSA_DBG_WAVEMODE_BROADCAST_PROCESS_CU = 3,
56 HSA_DBG_NUM_WAVEMODE = 3,
57 HSA_DBG_MAX_WAVEMODE = 0xFFFFFFFF
60 enum HSA_DBG_WAVEMSG_TYPE {
61 HSA_DBG_WAVEMSG_AUTO = 0,
62 HSA_DBG_WAVEMSG_USER = 1,
63 HSA_DBG_WAVEMSG_ERROR = 2,
65 HSA_DBG_MAX_WAVEMSG = 0xFFFFFFFF
68 enum HSA_DBG_WATCH_MODE {
69 HSA_DBG_WATCH_READ = 0, /* Read operations only */
70 HSA_DBG_WATCH_NONREAD = 1, /* Write or Atomic operations only */
71 HSA_DBG_WATCH_ATOMIC = 2, /* Atomic Operations only */
72 HSA_DBG_WATCH_ALL = 3, /* Read, Write or Atomic operations */
74 HSA_DBG_WATCH_SIZE = 0xFFFFFFFF
77 /* This structure is hardware specific and may change in the future */
78 struct HsaDbgWaveMsgAMDGen2 {
81 uint32_t UserData:8; /* user data */
82 uint32_t ShaderArray:1; /* Shader array */
83 uint32_t Priv:1; /* Privileged */
84 uint32_t Reserved0:4; /* This field is reserved,
86 uint32_t WaveId:4; /* wave id */
87 uint32_t SIMD:2; /* SIMD id */
88 uint32_t HSACU:4; /* Compute unit */
89 uint32_t ShaderEngine:2;/* Shader engine */
90 uint32_t MessageType:2; /* see HSA_DBG_WAVEMSG_TYPE */
91 uint32_t Reserved1:4; /* This field is reserved,
99 union HsaDbgWaveMessageAMD {
100 struct HsaDbgWaveMsgAMDGen2 WaveMsgInfoGen2;
101 /* for future HsaDbgWaveMsgAMDGen3; */
104 struct HsaDbgWaveMessage {
105 void *MemoryVA; /* ptr to associated host-accessible data */
106 union HsaDbgWaveMessageAMD DbgWaveMsg;
110 * TODO: This definitions to be MOVED to kfd_event, once it is implemented.
112 * HSA sync primitive, Event and HW Exception notification API definitions.
113 * The API functions allow the runtime to define a so-called sync-primitive,
114 * a SW object combining a user-mode provided "syncvar" and a scheduler event
115 * that can be signaled through a defined GPU interrupt. A syncvar is
116 * a process virtual memory location of a certain size that can be accessed
117 * by CPU and GPU shader code within the process to set and query the content
118 * within that memory. The definition of the content is determined by the HSA
119 * runtime and potentially GPU shader code interfacing with the HSA runtime.
120 * The syncvar values may be commonly written through an PM4 WRITE_DATA packet
121 * in the user mode instruction stream. The OS scheduler event is typically
122 * associated and signaled by an interrupt issued by the GPU, but other HSA
123 * system interrupt conditions from other HW (e.g. IOMMUv2) may be surfaced
124 * by the KFD by this mechanism, too. */
126 /* these are the new definitions for events */
128 HSA_EVENTTYPE_SIGNAL = 0, /* user-mode generated GPU signal */
129 HSA_EVENTTYPE_NODECHANGE = 1, /* HSA node change (attach/detach) */
130 HSA_EVENTTYPE_DEVICESTATECHANGE = 2, /* HSA device state change
132 HSA_EVENTTYPE_HW_EXCEPTION = 3, /* GPU shader exception event */
133 HSA_EVENTTYPE_SYSTEM_EVENT = 4, /* GPU SYSCALL with parameter info */
134 HSA_EVENTTYPE_DEBUG_EVENT = 5, /* GPU signal for debugging */
135 HSA_EVENTTYPE_PROFILE_EVENT = 6,/* GPU signal for profiling */
136 HSA_EVENTTYPE_QUEUE_EVENT = 7, /* GPU signal queue idle state
140 HSA_EVENTTYPE_TYPE_SIZE = 0xFFFFFFFF
143 /* Sub-definitions for various event types: Syncvar */
146 void *UserData; /* pointer to user mode data */
147 uint64_t UserDataPtrValue; /* 64bit compatibility of value */
149 uint64_t SyncVarSize;
152 /* Sub-definitions for various event types: NodeChange */
154 enum HSA_EVENTTYPE_NODECHANGE_FLAGS {
155 HSA_EVENTTYPE_NODECHANGE_ADD = 0,
156 HSA_EVENTTYPE_NODECHANGE_REMOVE = 1,
157 HSA_EVENTTYPE_NODECHANGE_SIZE = 0xFFFFFFFF
160 struct HsaNodeChange {
161 /* HSA node added/removed on the platform */
162 enum HSA_EVENTTYPE_NODECHANGE_FLAGS Flags;
165 /* Sub-definitions for various event types: DeviceStateChange */
166 enum HSA_EVENTTYPE_DEVICESTATECHANGE_FLAGS {
167 /* device started (and available) */
168 HSA_EVENTTYPE_DEVICESTATUSCHANGE_START = 0,
169 /* device stopped (i.e. unavailable) */
170 HSA_EVENTTYPE_DEVICESTATUSCHANGE_STOP = 1,
171 HSA_EVENTTYPE_DEVICESTATUSCHANGE_SIZE = 0xFFFFFFFF
180 struct HsaDeviceStateChange {
181 uint32_t NodeId; /* F-NUMA node that contains the device */
182 enum HSA_DEVICE Device; /* device type: GPU or CPU */
183 enum HSA_EVENTTYPE_DEVICESTATECHANGE_FLAGS Flags; /* event flags */
186 struct HsaEventData {
187 enum HSA_EVENTTYPE EventType; /* event type */
190 * return data associated with HSA_EVENTTYPE_SIGNAL
193 struct HsaSyncVar SyncVar;
195 /* data associated with HSA_EVENTTYPE_NODE_CHANGE */
196 struct HsaNodeChange NodeChangeState;
198 /* data associated with HSA_EVENTTYPE_DEVICE_STATE_CHANGE */
199 struct HsaDeviceStateChange DeviceState;
202 /* the following data entries are internal to the KFD & thunk itself */
204 /* internal thunk store for Event data (OsEventHandle) */
206 /* internal thunk store for Event data (HWAddress) */
208 /* internal thunk store for Event data (HWData) */
212 struct HsaEventDescriptor {
213 /* event type to allocate */
214 enum HSA_EVENTTYPE EventType;
215 /* H-NUMA node containing GPU device that is event source */
217 /* pointer to user mode syncvar data, syncvar->UserDataPtrValue
220 struct HsaSyncVar SyncVar;
225 struct HsaEventData EventData;
231 DBGDEV_TYPE_ILLEGAL = 0,
232 DBGDEV_TYPE_NODIQ = 1,
237 struct dbg_address_watch_info {
238 struct kfd_process *process;
239 enum HSA_DBG_WATCH_MODE *watch_mode;
240 uint64_t *watch_address;
241 uint64_t *watch_mask;
242 struct HsaEvent *watch_event;
243 uint32_t num_watch_points;
246 struct dbg_wave_control_info {
247 struct kfd_process *process;
249 enum HSA_DBG_WAVEOP operand;
250 enum HSA_DBG_WAVEMODE mode;
251 struct HsaDbgWaveMessage dbgWave_msg;
256 /* The device that owns this data. */
259 /* kernel queue for DIQ */
260 struct kernel_queue *kq;
262 /* a pointer to the pqm of the calling process */
263 struct process_queue_manager *pqm;
265 /* type of debug device ( DIQ, non DIQ, etc. ) */
266 enum DBGDEV_TYPE type;
268 /* virtualized function pointers to device dbg */
269 int (*dbgdev_register)(struct kfd_dbgdev *dbgdev);
270 int (*dbgdev_unregister)(struct kfd_dbgdev *dbgdev);
271 int (*dbgdev_address_watch)(struct kfd_dbgdev *dbgdev,
272 struct dbg_address_watch_info *adw_info);
273 int (*dbgdev_wave_control)(struct kfd_dbgdev *dbgdev,
274 struct dbg_wave_control_info *wac_info);
281 struct kfd_dbgdev *dbgdev;
284 /* prototypes for debug manager functions */
285 struct mutex *kfd_get_dbgmgr_mutex(void);
286 void kfd_dbgmgr_destroy(struct kfd_dbgmgr *pmgr);
287 bool kfd_dbgmgr_create(struct kfd_dbgmgr **ppmgr, struct kfd_dev *pdev);
288 long kfd_dbgmgr_register(struct kfd_dbgmgr *pmgr, struct kfd_process *p);
289 long kfd_dbgmgr_unregister(struct kfd_dbgmgr *pmgr, struct kfd_process *p);
290 long kfd_dbgmgr_wave_control(struct kfd_dbgmgr *pmgr,
291 struct dbg_wave_control_info *wac_info);
292 long kfd_dbgmgr_address_watch(struct kfd_dbgmgr *pmgr,
293 struct dbg_address_watch_info *adw_info);
294 #endif /* KFD_DBGMGR_H_ */