1 1.1 riastrad /* $NetBSD: kfd_dbgdev.c,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 #include <sys/cdefs.h> 27 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: kfd_dbgdev.c,v 1.3 2021/12/18 23:44:59 riastradh Exp $"); 28 1.1 riastrad 29 1.1 riastrad #include <linux/types.h> 30 1.1 riastrad #include <linux/kernel.h> 31 1.1 riastrad #include <linux/log2.h> 32 1.1 riastrad #include <linux/sched.h> 33 1.1 riastrad #include <linux/slab.h> 34 1.1 riastrad #include <linux/mutex.h> 35 1.1 riastrad #include <linux/device.h> 36 1.1 riastrad 37 1.1 riastrad #include "kfd_pm4_headers.h" 38 1.1 riastrad #include "kfd_pm4_headers_diq.h" 39 1.1 riastrad #include "kfd_kernel_queue.h" 40 1.1 riastrad #include "kfd_priv.h" 41 1.1 riastrad #include "kfd_pm4_opcodes.h" 42 1.1 riastrad #include "cik_regs.h" 43 1.1 riastrad #include "kfd_dbgmgr.h" 44 1.1 riastrad #include "kfd_dbgdev.h" 45 1.1 riastrad #include "kfd_device_queue_manager.h" 46 1.1 riastrad 47 1.1 riastrad static void dbgdev_address_watch_disable_nodiq(struct kfd_dev *dev) 48 1.1 riastrad { 49 1.1 riastrad dev->kfd2kgd->address_watch_disable(dev->kgd); 50 1.1 riastrad } 51 1.1 riastrad 52 1.1 riastrad static int dbgdev_diq_submit_ib(struct kfd_dbgdev *dbgdev, 53 1.1 riastrad unsigned int pasid, uint64_t vmid0_address, 54 1.1 riastrad uint32_t *packet_buff, size_t size_in_bytes) 55 1.1 riastrad { 56 1.1 riastrad struct pm4__release_mem *rm_packet; 57 1.1 riastrad struct pm4__indirect_buffer_pasid *ib_packet; 58 1.1 riastrad struct kfd_mem_obj *mem_obj; 59 1.1 riastrad size_t pq_packets_size_in_bytes; 60 1.1 riastrad union ULARGE_INTEGER *largep; 61 1.1 riastrad union ULARGE_INTEGER addr; 62 1.1 riastrad struct kernel_queue *kq; 63 1.1 riastrad uint64_t *rm_state; 64 1.1 riastrad unsigned int *ib_packet_buff; 65 1.1 riastrad int status; 66 1.1 riastrad 67 1.3 riastrad if (WARN_ON(!size_in_bytes)) 68 1.3 riastrad return -EINVAL; 69 1.1 riastrad 70 1.1 riastrad kq = dbgdev->kq; 71 1.1 riastrad 72 1.1 riastrad pq_packets_size_in_bytes = sizeof(struct pm4__release_mem) + 73 1.1 riastrad sizeof(struct pm4__indirect_buffer_pasid); 74 1.1 riastrad 75 1.1 riastrad /* 76 1.1 riastrad * We acquire a buffer from DIQ 77 1.1 riastrad * The receive packet buff will be sitting on the Indirect Buffer 78 1.1 riastrad * and in the PQ we put the IB packet + sync packet(s). 79 1.1 riastrad */ 80 1.3 riastrad status = kq_acquire_packet_buffer(kq, 81 1.1 riastrad pq_packets_size_in_bytes / sizeof(uint32_t), 82 1.1 riastrad &ib_packet_buff); 83 1.3 riastrad if (status) { 84 1.3 riastrad pr_err("kq_acquire_packet_buffer failed\n"); 85 1.1 riastrad return status; 86 1.1 riastrad } 87 1.1 riastrad 88 1.1 riastrad memset(ib_packet_buff, 0, pq_packets_size_in_bytes); 89 1.1 riastrad 90 1.1 riastrad ib_packet = (struct pm4__indirect_buffer_pasid *) (ib_packet_buff); 91 1.1 riastrad 92 1.1 riastrad ib_packet->header.count = 3; 93 1.1 riastrad ib_packet->header.opcode = IT_INDIRECT_BUFFER_PASID; 94 1.1 riastrad ib_packet->header.type = PM4_TYPE_3; 95 1.1 riastrad 96 1.1 riastrad largep = (union ULARGE_INTEGER *) &vmid0_address; 97 1.1 riastrad 98 1.1 riastrad ib_packet->bitfields2.ib_base_lo = largep->u.low_part >> 2; 99 1.1 riastrad ib_packet->bitfields3.ib_base_hi = largep->u.high_part; 100 1.1 riastrad 101 1.1 riastrad ib_packet->control = (1 << 23) | (1 << 31) | 102 1.3 riastrad ((size_in_bytes / 4) & 0xfffff); 103 1.1 riastrad 104 1.1 riastrad ib_packet->bitfields5.pasid = pasid; 105 1.1 riastrad 106 1.1 riastrad /* 107 1.1 riastrad * for now we use release mem for GPU-CPU synchronization 108 1.1 riastrad * Consider WaitRegMem + WriteData as a better alternative 109 1.1 riastrad * we get a GART allocations ( gpu/cpu mapping), 110 1.1 riastrad * for the sync variable, and wait until: 111 1.1 riastrad * (a) Sync with HW 112 1.1 riastrad * (b) Sync var is written by CP to mem. 113 1.1 riastrad */ 114 1.1 riastrad rm_packet = (struct pm4__release_mem *) (ib_packet_buff + 115 1.1 riastrad (sizeof(struct pm4__indirect_buffer_pasid) / 116 1.1 riastrad sizeof(unsigned int))); 117 1.1 riastrad 118 1.1 riastrad status = kfd_gtt_sa_allocate(dbgdev->dev, sizeof(uint64_t), 119 1.1 riastrad &mem_obj); 120 1.1 riastrad 121 1.3 riastrad if (status) { 122 1.3 riastrad pr_err("Failed to allocate GART memory\n"); 123 1.3 riastrad kq_rollback_packet(kq); 124 1.1 riastrad return status; 125 1.1 riastrad } 126 1.1 riastrad 127 1.1 riastrad rm_state = (uint64_t *) mem_obj->cpu_ptr; 128 1.1 riastrad 129 1.1 riastrad *rm_state = QUEUESTATE__ACTIVE_COMPLETION_PENDING; 130 1.1 riastrad 131 1.1 riastrad rm_packet->header.opcode = IT_RELEASE_MEM; 132 1.1 riastrad rm_packet->header.type = PM4_TYPE_3; 133 1.3 riastrad rm_packet->header.count = sizeof(struct pm4__release_mem) / 4 - 2; 134 1.1 riastrad 135 1.1 riastrad rm_packet->bitfields2.event_type = CACHE_FLUSH_AND_INV_TS_EVENT; 136 1.1 riastrad rm_packet->bitfields2.event_index = 137 1.1 riastrad event_index___release_mem__end_of_pipe; 138 1.1 riastrad 139 1.1 riastrad rm_packet->bitfields2.cache_policy = cache_policy___release_mem__lru; 140 1.1 riastrad rm_packet->bitfields2.atc = 0; 141 1.1 riastrad rm_packet->bitfields2.tc_wb_action_ena = 1; 142 1.1 riastrad 143 1.1 riastrad addr.quad_part = mem_obj->gpu_addr; 144 1.1 riastrad 145 1.1 riastrad rm_packet->bitfields4.address_lo_32b = addr.u.low_part >> 2; 146 1.1 riastrad rm_packet->address_hi = addr.u.high_part; 147 1.1 riastrad 148 1.1 riastrad rm_packet->bitfields3.data_sel = 149 1.1 riastrad data_sel___release_mem__send_64_bit_data; 150 1.1 riastrad 151 1.1 riastrad rm_packet->bitfields3.int_sel = 152 1.1 riastrad int_sel___release_mem__send_data_after_write_confirm; 153 1.1 riastrad 154 1.1 riastrad rm_packet->bitfields3.dst_sel = 155 1.1 riastrad dst_sel___release_mem__memory_controller; 156 1.1 riastrad 157 1.1 riastrad rm_packet->data_lo = QUEUESTATE__ACTIVE; 158 1.1 riastrad 159 1.3 riastrad kq_submit_packet(kq); 160 1.1 riastrad 161 1.1 riastrad /* Wait till CP writes sync code: */ 162 1.1 riastrad status = amdkfd_fence_wait_timeout( 163 1.1 riastrad (unsigned int *) rm_state, 164 1.1 riastrad QUEUESTATE__ACTIVE, 1500); 165 1.1 riastrad 166 1.1 riastrad kfd_gtt_sa_free(dbgdev->dev, mem_obj); 167 1.1 riastrad 168 1.1 riastrad return status; 169 1.1 riastrad } 170 1.1 riastrad 171 1.1 riastrad static int dbgdev_register_nodiq(struct kfd_dbgdev *dbgdev) 172 1.1 riastrad { 173 1.1 riastrad /* 174 1.1 riastrad * no action is needed in this case, 175 1.1 riastrad * just make sure diq will not be used 176 1.1 riastrad */ 177 1.1 riastrad 178 1.1 riastrad dbgdev->kq = NULL; 179 1.1 riastrad 180 1.1 riastrad return 0; 181 1.1 riastrad } 182 1.1 riastrad 183 1.1 riastrad static int dbgdev_register_diq(struct kfd_dbgdev *dbgdev) 184 1.1 riastrad { 185 1.1 riastrad struct queue_properties properties; 186 1.1 riastrad unsigned int qid; 187 1.1 riastrad struct kernel_queue *kq = NULL; 188 1.1 riastrad int status; 189 1.1 riastrad 190 1.3 riastrad properties.type = KFD_QUEUE_TYPE_DIQ; 191 1.1 riastrad 192 1.1 riastrad status = pqm_create_queue(dbgdev->pqm, dbgdev->dev, NULL, 193 1.3 riastrad &properties, &qid, NULL); 194 1.1 riastrad 195 1.1 riastrad if (status) { 196 1.3 riastrad pr_err("Failed to create DIQ\n"); 197 1.1 riastrad return status; 198 1.1 riastrad } 199 1.1 riastrad 200 1.1 riastrad pr_debug("DIQ Created with queue id: %d\n", qid); 201 1.1 riastrad 202 1.1 riastrad kq = pqm_get_kernel_queue(dbgdev->pqm, qid); 203 1.1 riastrad 204 1.3 riastrad if (!kq) { 205 1.3 riastrad pr_err("Error getting DIQ\n"); 206 1.1 riastrad pqm_destroy_queue(dbgdev->pqm, qid); 207 1.1 riastrad return -EFAULT; 208 1.1 riastrad } 209 1.1 riastrad 210 1.1 riastrad dbgdev->kq = kq; 211 1.1 riastrad 212 1.1 riastrad return status; 213 1.1 riastrad } 214 1.1 riastrad 215 1.1 riastrad static int dbgdev_unregister_nodiq(struct kfd_dbgdev *dbgdev) 216 1.1 riastrad { 217 1.1 riastrad /* disable watch address */ 218 1.1 riastrad dbgdev_address_watch_disable_nodiq(dbgdev->dev); 219 1.1 riastrad return 0; 220 1.1 riastrad } 221 1.1 riastrad 222 1.1 riastrad static int dbgdev_unregister_diq(struct kfd_dbgdev *dbgdev) 223 1.1 riastrad { 224 1.1 riastrad /* todo - disable address watch */ 225 1.1 riastrad int status; 226 1.1 riastrad 227 1.1 riastrad status = pqm_destroy_queue(dbgdev->pqm, 228 1.1 riastrad dbgdev->kq->queue->properties.queue_id); 229 1.1 riastrad dbgdev->kq = NULL; 230 1.1 riastrad 231 1.1 riastrad return status; 232 1.1 riastrad } 233 1.1 riastrad 234 1.1 riastrad static void dbgdev_address_watch_set_registers( 235 1.1 riastrad const struct dbg_address_watch_info *adw_info, 236 1.1 riastrad union TCP_WATCH_ADDR_H_BITS *addrHi, 237 1.1 riastrad union TCP_WATCH_ADDR_L_BITS *addrLo, 238 1.1 riastrad union TCP_WATCH_CNTL_BITS *cntl, 239 1.1 riastrad unsigned int index, unsigned int vmid) 240 1.1 riastrad { 241 1.1 riastrad union ULARGE_INTEGER addr; 242 1.1 riastrad 243 1.1 riastrad addr.quad_part = 0; 244 1.1 riastrad addrHi->u32All = 0; 245 1.1 riastrad addrLo->u32All = 0; 246 1.1 riastrad cntl->u32All = 0; 247 1.1 riastrad 248 1.3 riastrad if (adw_info->watch_mask) 249 1.1 riastrad cntl->bitfields.mask = 250 1.1 riastrad (uint32_t) (adw_info->watch_mask[index] & 251 1.1 riastrad ADDRESS_WATCH_REG_CNTL_DEFAULT_MASK); 252 1.1 riastrad else 253 1.1 riastrad cntl->bitfields.mask = ADDRESS_WATCH_REG_CNTL_DEFAULT_MASK; 254 1.1 riastrad 255 1.1 riastrad addr.quad_part = (unsigned long long) adw_info->watch_address[index]; 256 1.1 riastrad 257 1.1 riastrad addrHi->bitfields.addr = addr.u.high_part & 258 1.1 riastrad ADDRESS_WATCH_REG_ADDHIGH_MASK; 259 1.1 riastrad addrLo->bitfields.addr = 260 1.1 riastrad (addr.u.low_part >> ADDRESS_WATCH_REG_ADDLOW_SHIFT); 261 1.1 riastrad 262 1.1 riastrad cntl->bitfields.mode = adw_info->watch_mode[index]; 263 1.1 riastrad cntl->bitfields.vmid = (uint32_t) vmid; 264 1.1 riastrad /* for now assume it is an ATC address */ 265 1.1 riastrad cntl->u32All |= ADDRESS_WATCH_REG_CNTL_ATC_BIT; 266 1.1 riastrad 267 1.1 riastrad pr_debug("\t\t%20s %08x\n", "set reg mask :", cntl->bitfields.mask); 268 1.1 riastrad pr_debug("\t\t%20s %08x\n", "set reg add high :", 269 1.1 riastrad addrHi->bitfields.addr); 270 1.1 riastrad pr_debug("\t\t%20s %08x\n", "set reg add low :", 271 1.1 riastrad addrLo->bitfields.addr); 272 1.1 riastrad } 273 1.1 riastrad 274 1.1 riastrad static int dbgdev_address_watch_nodiq(struct kfd_dbgdev *dbgdev, 275 1.3 riastrad struct dbg_address_watch_info *adw_info) 276 1.1 riastrad { 277 1.1 riastrad union TCP_WATCH_ADDR_H_BITS addrHi; 278 1.1 riastrad union TCP_WATCH_ADDR_L_BITS addrLo; 279 1.1 riastrad union TCP_WATCH_CNTL_BITS cntl; 280 1.1 riastrad struct kfd_process_device *pdd; 281 1.1 riastrad unsigned int i; 282 1.1 riastrad 283 1.1 riastrad /* taking the vmid for that process on the safe way using pdd */ 284 1.1 riastrad pdd = kfd_get_process_device_data(dbgdev->dev, 285 1.1 riastrad adw_info->process); 286 1.1 riastrad if (!pdd) { 287 1.3 riastrad pr_err("Failed to get pdd for wave control no DIQ\n"); 288 1.1 riastrad return -EFAULT; 289 1.1 riastrad } 290 1.1 riastrad 291 1.1 riastrad addrHi.u32All = 0; 292 1.1 riastrad addrLo.u32All = 0; 293 1.1 riastrad cntl.u32All = 0; 294 1.1 riastrad 295 1.1 riastrad if ((adw_info->num_watch_points > MAX_WATCH_ADDRESSES) || 296 1.1 riastrad (adw_info->num_watch_points == 0)) { 297 1.3 riastrad pr_err("num_watch_points is invalid\n"); 298 1.1 riastrad return -EINVAL; 299 1.1 riastrad } 300 1.1 riastrad 301 1.3 riastrad if (!adw_info->watch_mode || !adw_info->watch_address) { 302 1.3 riastrad pr_err("adw_info fields are not valid\n"); 303 1.1 riastrad return -EINVAL; 304 1.1 riastrad } 305 1.1 riastrad 306 1.3 riastrad for (i = 0; i < adw_info->num_watch_points; i++) { 307 1.1 riastrad dbgdev_address_watch_set_registers(adw_info, &addrHi, &addrLo, 308 1.1 riastrad &cntl, i, pdd->qpd.vmid); 309 1.1 riastrad 310 1.1 riastrad pr_debug("\t\t%30s\n", "* * * * * * * * * * * * * * * * * *"); 311 1.1 riastrad pr_debug("\t\t%20s %08x\n", "register index :", i); 312 1.1 riastrad pr_debug("\t\t%20s %08x\n", "vmid is :", pdd->qpd.vmid); 313 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Address Low is :", 314 1.1 riastrad addrLo.bitfields.addr); 315 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Address high is :", 316 1.1 riastrad addrHi.bitfields.addr); 317 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Address high is :", 318 1.1 riastrad addrHi.bitfields.addr); 319 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control Mask is :", 320 1.1 riastrad cntl.bitfields.mask); 321 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control Mode is :", 322 1.1 riastrad cntl.bitfields.mode); 323 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control Vmid is :", 324 1.1 riastrad cntl.bitfields.vmid); 325 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control atc is :", 326 1.1 riastrad cntl.bitfields.atc); 327 1.1 riastrad pr_debug("\t\t%30s\n", "* * * * * * * * * * * * * * * * * *"); 328 1.1 riastrad 329 1.1 riastrad pdd->dev->kfd2kgd->address_watch_execute( 330 1.1 riastrad dbgdev->dev->kgd, 331 1.1 riastrad i, 332 1.1 riastrad cntl.u32All, 333 1.1 riastrad addrHi.u32All, 334 1.1 riastrad addrLo.u32All); 335 1.1 riastrad } 336 1.1 riastrad 337 1.1 riastrad return 0; 338 1.1 riastrad } 339 1.1 riastrad 340 1.1 riastrad static int dbgdev_address_watch_diq(struct kfd_dbgdev *dbgdev, 341 1.3 riastrad struct dbg_address_watch_info *adw_info) 342 1.1 riastrad { 343 1.1 riastrad struct pm4__set_config_reg *packets_vec; 344 1.1 riastrad union TCP_WATCH_ADDR_H_BITS addrHi; 345 1.1 riastrad union TCP_WATCH_ADDR_L_BITS addrLo; 346 1.1 riastrad union TCP_WATCH_CNTL_BITS cntl; 347 1.1 riastrad struct kfd_mem_obj *mem_obj; 348 1.1 riastrad unsigned int aw_reg_add_dword; 349 1.1 riastrad uint32_t *packet_buff_uint; 350 1.1 riastrad unsigned int i; 351 1.1 riastrad int status; 352 1.1 riastrad size_t ib_size = sizeof(struct pm4__set_config_reg) * 4; 353 1.1 riastrad /* we do not control the vmid in DIQ mode, just a place holder */ 354 1.1 riastrad unsigned int vmid = 0; 355 1.1 riastrad 356 1.1 riastrad addrHi.u32All = 0; 357 1.1 riastrad addrLo.u32All = 0; 358 1.1 riastrad cntl.u32All = 0; 359 1.1 riastrad 360 1.1 riastrad if ((adw_info->num_watch_points > MAX_WATCH_ADDRESSES) || 361 1.1 riastrad (adw_info->num_watch_points == 0)) { 362 1.3 riastrad pr_err("num_watch_points is invalid\n"); 363 1.1 riastrad return -EINVAL; 364 1.1 riastrad } 365 1.1 riastrad 366 1.3 riastrad if (!adw_info->watch_mode || !adw_info->watch_address) { 367 1.3 riastrad pr_err("adw_info fields are not valid\n"); 368 1.1 riastrad return -EINVAL; 369 1.1 riastrad } 370 1.1 riastrad 371 1.1 riastrad status = kfd_gtt_sa_allocate(dbgdev->dev, ib_size, &mem_obj); 372 1.1 riastrad 373 1.3 riastrad if (status) { 374 1.3 riastrad pr_err("Failed to allocate GART memory\n"); 375 1.1 riastrad return status; 376 1.1 riastrad } 377 1.1 riastrad 378 1.1 riastrad packet_buff_uint = mem_obj->cpu_ptr; 379 1.1 riastrad 380 1.1 riastrad memset(packet_buff_uint, 0, ib_size); 381 1.1 riastrad 382 1.1 riastrad packets_vec = (struct pm4__set_config_reg *) (packet_buff_uint); 383 1.1 riastrad 384 1.1 riastrad packets_vec[0].header.count = 1; 385 1.1 riastrad packets_vec[0].header.opcode = IT_SET_CONFIG_REG; 386 1.1 riastrad packets_vec[0].header.type = PM4_TYPE_3; 387 1.1 riastrad packets_vec[0].bitfields2.vmid_shift = ADDRESS_WATCH_CNTL_OFFSET; 388 1.1 riastrad packets_vec[0].bitfields2.insert_vmid = 1; 389 1.1 riastrad packets_vec[1].ordinal1 = packets_vec[0].ordinal1; 390 1.1 riastrad packets_vec[1].bitfields2.insert_vmid = 0; 391 1.1 riastrad packets_vec[2].ordinal1 = packets_vec[0].ordinal1; 392 1.1 riastrad packets_vec[2].bitfields2.insert_vmid = 0; 393 1.1 riastrad packets_vec[3].ordinal1 = packets_vec[0].ordinal1; 394 1.1 riastrad packets_vec[3].bitfields2.vmid_shift = ADDRESS_WATCH_CNTL_OFFSET; 395 1.1 riastrad packets_vec[3].bitfields2.insert_vmid = 1; 396 1.1 riastrad 397 1.1 riastrad for (i = 0; i < adw_info->num_watch_points; i++) { 398 1.1 riastrad dbgdev_address_watch_set_registers(adw_info, 399 1.1 riastrad &addrHi, 400 1.1 riastrad &addrLo, 401 1.1 riastrad &cntl, 402 1.1 riastrad i, 403 1.1 riastrad vmid); 404 1.1 riastrad 405 1.1 riastrad pr_debug("\t\t%30s\n", "* * * * * * * * * * * * * * * * * *"); 406 1.1 riastrad pr_debug("\t\t%20s %08x\n", "register index :", i); 407 1.1 riastrad pr_debug("\t\t%20s %08x\n", "vmid is :", vmid); 408 1.1 riastrad pr_debug("\t\t%20s %p\n", "Add ptr is :", 409 1.1 riastrad adw_info->watch_address); 410 1.1 riastrad pr_debug("\t\t%20s %08llx\n", "Add is :", 411 1.1 riastrad adw_info->watch_address[i]); 412 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Address Low is :", 413 1.1 riastrad addrLo.bitfields.addr); 414 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Address high is :", 415 1.1 riastrad addrHi.bitfields.addr); 416 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control Mask is :", 417 1.1 riastrad cntl.bitfields.mask); 418 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control Mode is :", 419 1.1 riastrad cntl.bitfields.mode); 420 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control Vmid is :", 421 1.1 riastrad cntl.bitfields.vmid); 422 1.1 riastrad pr_debug("\t\t%20s %08x\n", "Control atc is :", 423 1.1 riastrad cntl.bitfields.atc); 424 1.1 riastrad pr_debug("\t\t%30s\n", "* * * * * * * * * * * * * * * * * *"); 425 1.1 riastrad 426 1.1 riastrad aw_reg_add_dword = 427 1.1 riastrad dbgdev->dev->kfd2kgd->address_watch_get_offset( 428 1.1 riastrad dbgdev->dev->kgd, 429 1.1 riastrad i, 430 1.1 riastrad ADDRESS_WATCH_REG_CNTL); 431 1.1 riastrad 432 1.1 riastrad packets_vec[0].bitfields2.reg_offset = 433 1.1 riastrad aw_reg_add_dword - AMD_CONFIG_REG_BASE; 434 1.1 riastrad 435 1.1 riastrad packets_vec[0].reg_data[0] = cntl.u32All; 436 1.1 riastrad 437 1.1 riastrad aw_reg_add_dword = 438 1.1 riastrad dbgdev->dev->kfd2kgd->address_watch_get_offset( 439 1.1 riastrad dbgdev->dev->kgd, 440 1.1 riastrad i, 441 1.1 riastrad ADDRESS_WATCH_REG_ADDR_HI); 442 1.1 riastrad 443 1.1 riastrad packets_vec[1].bitfields2.reg_offset = 444 1.1 riastrad aw_reg_add_dword - AMD_CONFIG_REG_BASE; 445 1.1 riastrad packets_vec[1].reg_data[0] = addrHi.u32All; 446 1.1 riastrad 447 1.1 riastrad aw_reg_add_dword = 448 1.1 riastrad dbgdev->dev->kfd2kgd->address_watch_get_offset( 449 1.1 riastrad dbgdev->dev->kgd, 450 1.1 riastrad i, 451 1.1 riastrad ADDRESS_WATCH_REG_ADDR_LO); 452 1.1 riastrad 453 1.1 riastrad packets_vec[2].bitfields2.reg_offset = 454 1.1 riastrad aw_reg_add_dword - AMD_CONFIG_REG_BASE; 455 1.1 riastrad packets_vec[2].reg_data[0] = addrLo.u32All; 456 1.1 riastrad 457 1.1 riastrad /* enable watch flag if address is not zero*/ 458 1.1 riastrad if (adw_info->watch_address[i] > 0) 459 1.1 riastrad cntl.bitfields.valid = 1; 460 1.1 riastrad else 461 1.1 riastrad cntl.bitfields.valid = 0; 462 1.1 riastrad 463 1.1 riastrad aw_reg_add_dword = 464 1.1 riastrad dbgdev->dev->kfd2kgd->address_watch_get_offset( 465 1.1 riastrad dbgdev->dev->kgd, 466 1.1 riastrad i, 467 1.1 riastrad ADDRESS_WATCH_REG_CNTL); 468 1.1 riastrad 469 1.1 riastrad packets_vec[3].bitfields2.reg_offset = 470 1.1 riastrad aw_reg_add_dword - AMD_CONFIG_REG_BASE; 471 1.1 riastrad packets_vec[3].reg_data[0] = cntl.u32All; 472 1.1 riastrad 473 1.1 riastrad status = dbgdev_diq_submit_ib( 474 1.1 riastrad dbgdev, 475 1.1 riastrad adw_info->process->pasid, 476 1.1 riastrad mem_obj->gpu_addr, 477 1.1 riastrad packet_buff_uint, 478 1.1 riastrad ib_size); 479 1.1 riastrad 480 1.3 riastrad if (status) { 481 1.3 riastrad pr_err("Failed to submit IB to DIQ\n"); 482 1.1 riastrad break; 483 1.1 riastrad } 484 1.1 riastrad } 485 1.1 riastrad 486 1.1 riastrad kfd_gtt_sa_free(dbgdev->dev, mem_obj); 487 1.1 riastrad return status; 488 1.1 riastrad } 489 1.1 riastrad 490 1.1 riastrad static int dbgdev_wave_control_set_registers( 491 1.1 riastrad struct dbg_wave_control_info *wac_info, 492 1.1 riastrad union SQ_CMD_BITS *in_reg_sq_cmd, 493 1.1 riastrad union GRBM_GFX_INDEX_BITS *in_reg_gfx_index) 494 1.1 riastrad { 495 1.1 riastrad int status = 0; 496 1.1 riastrad union SQ_CMD_BITS reg_sq_cmd; 497 1.1 riastrad union GRBM_GFX_INDEX_BITS reg_gfx_index; 498 1.1 riastrad struct HsaDbgWaveMsgAMDGen2 *pMsg; 499 1.1 riastrad 500 1.1 riastrad reg_sq_cmd.u32All = 0; 501 1.1 riastrad reg_gfx_index.u32All = 0; 502 1.1 riastrad pMsg = &wac_info->dbgWave_msg.DbgWaveMsg.WaveMsgInfoGen2; 503 1.1 riastrad 504 1.1 riastrad switch (wac_info->mode) { 505 1.1 riastrad /* Send command to single wave */ 506 1.1 riastrad case HSA_DBG_WAVEMODE_SINGLE: 507 1.1 riastrad /* 508 1.1 riastrad * Limit access to the process waves only, 509 1.1 riastrad * by setting vmid check 510 1.1 riastrad */ 511 1.1 riastrad reg_sq_cmd.bits.check_vmid = 1; 512 1.1 riastrad reg_sq_cmd.bits.simd_id = pMsg->ui32.SIMD; 513 1.1 riastrad reg_sq_cmd.bits.wave_id = pMsg->ui32.WaveId; 514 1.1 riastrad reg_sq_cmd.bits.mode = SQ_IND_CMD_MODE_SINGLE; 515 1.1 riastrad 516 1.1 riastrad reg_gfx_index.bits.sh_index = pMsg->ui32.ShaderArray; 517 1.1 riastrad reg_gfx_index.bits.se_index = pMsg->ui32.ShaderEngine; 518 1.1 riastrad reg_gfx_index.bits.instance_index = pMsg->ui32.HSACU; 519 1.1 riastrad 520 1.1 riastrad break; 521 1.1 riastrad 522 1.1 riastrad /* Send command to all waves with matching VMID */ 523 1.1 riastrad case HSA_DBG_WAVEMODE_BROADCAST_PROCESS: 524 1.1 riastrad 525 1.1 riastrad reg_gfx_index.bits.sh_broadcast_writes = 1; 526 1.1 riastrad reg_gfx_index.bits.se_broadcast_writes = 1; 527 1.1 riastrad reg_gfx_index.bits.instance_broadcast_writes = 1; 528 1.1 riastrad 529 1.1 riastrad reg_sq_cmd.bits.mode = SQ_IND_CMD_MODE_BROADCAST; 530 1.1 riastrad 531 1.1 riastrad break; 532 1.1 riastrad 533 1.1 riastrad /* Send command to all CU waves with matching VMID */ 534 1.1 riastrad case HSA_DBG_WAVEMODE_BROADCAST_PROCESS_CU: 535 1.1 riastrad 536 1.1 riastrad reg_sq_cmd.bits.check_vmid = 1; 537 1.1 riastrad reg_sq_cmd.bits.mode = SQ_IND_CMD_MODE_BROADCAST; 538 1.1 riastrad 539 1.1 riastrad reg_gfx_index.bits.sh_index = pMsg->ui32.ShaderArray; 540 1.1 riastrad reg_gfx_index.bits.se_index = pMsg->ui32.ShaderEngine; 541 1.1 riastrad reg_gfx_index.bits.instance_index = pMsg->ui32.HSACU; 542 1.1 riastrad 543 1.1 riastrad break; 544 1.1 riastrad 545 1.1 riastrad default: 546 1.1 riastrad return -EINVAL; 547 1.1 riastrad } 548 1.1 riastrad 549 1.1 riastrad switch (wac_info->operand) { 550 1.1 riastrad case HSA_DBG_WAVEOP_HALT: 551 1.1 riastrad reg_sq_cmd.bits.cmd = SQ_IND_CMD_CMD_HALT; 552 1.1 riastrad break; 553 1.1 riastrad 554 1.1 riastrad case HSA_DBG_WAVEOP_RESUME: 555 1.1 riastrad reg_sq_cmd.bits.cmd = SQ_IND_CMD_CMD_RESUME; 556 1.1 riastrad break; 557 1.1 riastrad 558 1.1 riastrad case HSA_DBG_WAVEOP_KILL: 559 1.1 riastrad reg_sq_cmd.bits.cmd = SQ_IND_CMD_CMD_KILL; 560 1.1 riastrad break; 561 1.1 riastrad 562 1.1 riastrad case HSA_DBG_WAVEOP_DEBUG: 563 1.1 riastrad reg_sq_cmd.bits.cmd = SQ_IND_CMD_CMD_DEBUG; 564 1.1 riastrad break; 565 1.1 riastrad 566 1.1 riastrad case HSA_DBG_WAVEOP_TRAP: 567 1.1 riastrad if (wac_info->trapId < MAX_TRAPID) { 568 1.1 riastrad reg_sq_cmd.bits.cmd = SQ_IND_CMD_CMD_TRAP; 569 1.1 riastrad reg_sq_cmd.bits.trap_id = wac_info->trapId; 570 1.1 riastrad } else { 571 1.1 riastrad status = -EINVAL; 572 1.1 riastrad } 573 1.1 riastrad break; 574 1.1 riastrad 575 1.1 riastrad default: 576 1.1 riastrad status = -EINVAL; 577 1.1 riastrad break; 578 1.1 riastrad } 579 1.1 riastrad 580 1.1 riastrad if (status == 0) { 581 1.1 riastrad *in_reg_sq_cmd = reg_sq_cmd; 582 1.1 riastrad *in_reg_gfx_index = reg_gfx_index; 583 1.1 riastrad } 584 1.1 riastrad 585 1.1 riastrad return status; 586 1.1 riastrad } 587 1.1 riastrad 588 1.1 riastrad static int dbgdev_wave_control_diq(struct kfd_dbgdev *dbgdev, 589 1.1 riastrad struct dbg_wave_control_info *wac_info) 590 1.1 riastrad { 591 1.1 riastrad 592 1.1 riastrad int status; 593 1.1 riastrad union SQ_CMD_BITS reg_sq_cmd; 594 1.1 riastrad union GRBM_GFX_INDEX_BITS reg_gfx_index; 595 1.1 riastrad struct kfd_mem_obj *mem_obj; 596 1.1 riastrad uint32_t *packet_buff_uint; 597 1.1 riastrad struct pm4__set_config_reg *packets_vec; 598 1.1 riastrad size_t ib_size = sizeof(struct pm4__set_config_reg) * 3; 599 1.1 riastrad 600 1.1 riastrad reg_sq_cmd.u32All = 0; 601 1.1 riastrad 602 1.1 riastrad status = dbgdev_wave_control_set_registers(wac_info, ®_sq_cmd, 603 1.1 riastrad ®_gfx_index); 604 1.1 riastrad if (status) { 605 1.3 riastrad pr_err("Failed to set wave control registers\n"); 606 1.1 riastrad return status; 607 1.1 riastrad } 608 1.1 riastrad 609 1.3 riastrad /* we do not control the VMID in DIQ, so reset it to a known value */ 610 1.1 riastrad reg_sq_cmd.bits.vm_id = 0; 611 1.1 riastrad 612 1.1 riastrad pr_debug("\t\t %30s\n", "* * * * * * * * * * * * * * * * * *"); 613 1.1 riastrad 614 1.1 riastrad pr_debug("\t\t mode is: %u\n", wac_info->mode); 615 1.1 riastrad pr_debug("\t\t operand is: %u\n", wac_info->operand); 616 1.1 riastrad pr_debug("\t\t trap id is: %u\n", wac_info->trapId); 617 1.1 riastrad pr_debug("\t\t msg value is: %u\n", 618 1.1 riastrad wac_info->dbgWave_msg.DbgWaveMsg.WaveMsgInfoGen2.Value); 619 1.1 riastrad pr_debug("\t\t vmid is: N/A\n"); 620 1.1 riastrad 621 1.1 riastrad pr_debug("\t\t chk_vmid is : %u\n", reg_sq_cmd.bitfields.check_vmid); 622 1.1 riastrad pr_debug("\t\t command is : %u\n", reg_sq_cmd.bitfields.cmd); 623 1.1 riastrad pr_debug("\t\t queue id is : %u\n", reg_sq_cmd.bitfields.queue_id); 624 1.1 riastrad pr_debug("\t\t simd id is : %u\n", reg_sq_cmd.bitfields.simd_id); 625 1.1 riastrad pr_debug("\t\t mode is : %u\n", reg_sq_cmd.bitfields.mode); 626 1.1 riastrad pr_debug("\t\t vm_id is : %u\n", reg_sq_cmd.bitfields.vm_id); 627 1.1 riastrad pr_debug("\t\t wave_id is : %u\n", reg_sq_cmd.bitfields.wave_id); 628 1.1 riastrad 629 1.1 riastrad pr_debug("\t\t ibw is : %u\n", 630 1.1 riastrad reg_gfx_index.bitfields.instance_broadcast_writes); 631 1.1 riastrad pr_debug("\t\t ii is : %u\n", 632 1.1 riastrad reg_gfx_index.bitfields.instance_index); 633 1.1 riastrad pr_debug("\t\t sebw is : %u\n", 634 1.1 riastrad reg_gfx_index.bitfields.se_broadcast_writes); 635 1.1 riastrad pr_debug("\t\t se_ind is : %u\n", reg_gfx_index.bitfields.se_index); 636 1.1 riastrad pr_debug("\t\t sh_ind is : %u\n", reg_gfx_index.bitfields.sh_index); 637 1.1 riastrad pr_debug("\t\t sbw is : %u\n", 638 1.1 riastrad reg_gfx_index.bitfields.sh_broadcast_writes); 639 1.1 riastrad 640 1.1 riastrad pr_debug("\t\t %30s\n", "* * * * * * * * * * * * * * * * * *"); 641 1.1 riastrad 642 1.1 riastrad status = kfd_gtt_sa_allocate(dbgdev->dev, ib_size, &mem_obj); 643 1.1 riastrad 644 1.1 riastrad if (status != 0) { 645 1.3 riastrad pr_err("Failed to allocate GART memory\n"); 646 1.1 riastrad return status; 647 1.1 riastrad } 648 1.1 riastrad 649 1.1 riastrad packet_buff_uint = mem_obj->cpu_ptr; 650 1.1 riastrad 651 1.1 riastrad memset(packet_buff_uint, 0, ib_size); 652 1.1 riastrad 653 1.1 riastrad packets_vec = (struct pm4__set_config_reg *) packet_buff_uint; 654 1.1 riastrad packets_vec[0].header.count = 1; 655 1.1 riastrad packets_vec[0].header.opcode = IT_SET_UCONFIG_REG; 656 1.1 riastrad packets_vec[0].header.type = PM4_TYPE_3; 657 1.1 riastrad packets_vec[0].bitfields2.reg_offset = 658 1.3 riastrad GRBM_GFX_INDEX / 4 - USERCONFIG_REG_BASE; 659 1.1 riastrad 660 1.1 riastrad packets_vec[0].bitfields2.insert_vmid = 0; 661 1.1 riastrad packets_vec[0].reg_data[0] = reg_gfx_index.u32All; 662 1.1 riastrad 663 1.1 riastrad packets_vec[1].header.count = 1; 664 1.1 riastrad packets_vec[1].header.opcode = IT_SET_CONFIG_REG; 665 1.1 riastrad packets_vec[1].header.type = PM4_TYPE_3; 666 1.3 riastrad packets_vec[1].bitfields2.reg_offset = SQ_CMD / 4 - AMD_CONFIG_REG_BASE; 667 1.1 riastrad 668 1.1 riastrad packets_vec[1].bitfields2.vmid_shift = SQ_CMD_VMID_OFFSET; 669 1.1 riastrad packets_vec[1].bitfields2.insert_vmid = 1; 670 1.1 riastrad packets_vec[1].reg_data[0] = reg_sq_cmd.u32All; 671 1.1 riastrad 672 1.1 riastrad /* Restore the GRBM_GFX_INDEX register */ 673 1.1 riastrad 674 1.1 riastrad reg_gfx_index.u32All = 0; 675 1.1 riastrad reg_gfx_index.bits.sh_broadcast_writes = 1; 676 1.1 riastrad reg_gfx_index.bits.instance_broadcast_writes = 1; 677 1.1 riastrad reg_gfx_index.bits.se_broadcast_writes = 1; 678 1.1 riastrad 679 1.1 riastrad 680 1.1 riastrad packets_vec[2].ordinal1 = packets_vec[0].ordinal1; 681 1.1 riastrad packets_vec[2].bitfields2.reg_offset = 682 1.3 riastrad GRBM_GFX_INDEX / 4 - USERCONFIG_REG_BASE; 683 1.1 riastrad 684 1.1 riastrad packets_vec[2].bitfields2.insert_vmid = 0; 685 1.1 riastrad packets_vec[2].reg_data[0] = reg_gfx_index.u32All; 686 1.1 riastrad 687 1.1 riastrad status = dbgdev_diq_submit_ib( 688 1.1 riastrad dbgdev, 689 1.1 riastrad wac_info->process->pasid, 690 1.1 riastrad mem_obj->gpu_addr, 691 1.1 riastrad packet_buff_uint, 692 1.1 riastrad ib_size); 693 1.1 riastrad 694 1.3 riastrad if (status) 695 1.3 riastrad pr_err("Failed to submit IB to DIQ\n"); 696 1.1 riastrad 697 1.1 riastrad kfd_gtt_sa_free(dbgdev->dev, mem_obj); 698 1.1 riastrad 699 1.1 riastrad return status; 700 1.1 riastrad } 701 1.1 riastrad 702 1.1 riastrad static int dbgdev_wave_control_nodiq(struct kfd_dbgdev *dbgdev, 703 1.1 riastrad struct dbg_wave_control_info *wac_info) 704 1.1 riastrad { 705 1.1 riastrad int status; 706 1.1 riastrad union SQ_CMD_BITS reg_sq_cmd; 707 1.1 riastrad union GRBM_GFX_INDEX_BITS reg_gfx_index; 708 1.1 riastrad struct kfd_process_device *pdd; 709 1.1 riastrad 710 1.1 riastrad reg_sq_cmd.u32All = 0; 711 1.1 riastrad 712 1.1 riastrad /* taking the VMID for that process on the safe way using PDD */ 713 1.1 riastrad pdd = kfd_get_process_device_data(dbgdev->dev, wac_info->process); 714 1.1 riastrad 715 1.1 riastrad if (!pdd) { 716 1.3 riastrad pr_err("Failed to get pdd for wave control no DIQ\n"); 717 1.1 riastrad return -EFAULT; 718 1.1 riastrad } 719 1.1 riastrad status = dbgdev_wave_control_set_registers(wac_info, ®_sq_cmd, 720 1.1 riastrad ®_gfx_index); 721 1.1 riastrad if (status) { 722 1.3 riastrad pr_err("Failed to set wave control registers\n"); 723 1.1 riastrad return status; 724 1.1 riastrad } 725 1.1 riastrad 726 1.1 riastrad /* for non DIQ we need to patch the VMID: */ 727 1.1 riastrad 728 1.1 riastrad reg_sq_cmd.bits.vm_id = pdd->qpd.vmid; 729 1.1 riastrad 730 1.1 riastrad pr_debug("\t\t %30s\n", "* * * * * * * * * * * * * * * * * *"); 731 1.1 riastrad 732 1.1 riastrad pr_debug("\t\t mode is: %u\n", wac_info->mode); 733 1.1 riastrad pr_debug("\t\t operand is: %u\n", wac_info->operand); 734 1.1 riastrad pr_debug("\t\t trap id is: %u\n", wac_info->trapId); 735 1.1 riastrad pr_debug("\t\t msg value is: %u\n", 736 1.1 riastrad wac_info->dbgWave_msg.DbgWaveMsg.WaveMsgInfoGen2.Value); 737 1.1 riastrad pr_debug("\t\t vmid is: %u\n", pdd->qpd.vmid); 738 1.1 riastrad 739 1.1 riastrad pr_debug("\t\t chk_vmid is : %u\n", reg_sq_cmd.bitfields.check_vmid); 740 1.1 riastrad pr_debug("\t\t command is : %u\n", reg_sq_cmd.bitfields.cmd); 741 1.1 riastrad pr_debug("\t\t queue id is : %u\n", reg_sq_cmd.bitfields.queue_id); 742 1.1 riastrad pr_debug("\t\t simd id is : %u\n", reg_sq_cmd.bitfields.simd_id); 743 1.1 riastrad pr_debug("\t\t mode is : %u\n", reg_sq_cmd.bitfields.mode); 744 1.1 riastrad pr_debug("\t\t vm_id is : %u\n", reg_sq_cmd.bitfields.vm_id); 745 1.1 riastrad pr_debug("\t\t wave_id is : %u\n", reg_sq_cmd.bitfields.wave_id); 746 1.1 riastrad 747 1.1 riastrad pr_debug("\t\t ibw is : %u\n", 748 1.1 riastrad reg_gfx_index.bitfields.instance_broadcast_writes); 749 1.1 riastrad pr_debug("\t\t ii is : %u\n", 750 1.1 riastrad reg_gfx_index.bitfields.instance_index); 751 1.1 riastrad pr_debug("\t\t sebw is : %u\n", 752 1.1 riastrad reg_gfx_index.bitfields.se_broadcast_writes); 753 1.1 riastrad pr_debug("\t\t se_ind is : %u\n", reg_gfx_index.bitfields.se_index); 754 1.1 riastrad pr_debug("\t\t sh_ind is : %u\n", reg_gfx_index.bitfields.sh_index); 755 1.1 riastrad pr_debug("\t\t sbw is : %u\n", 756 1.1 riastrad reg_gfx_index.bitfields.sh_broadcast_writes); 757 1.1 riastrad 758 1.1 riastrad pr_debug("\t\t %30s\n", "* * * * * * * * * * * * * * * * * *"); 759 1.1 riastrad 760 1.1 riastrad return dbgdev->dev->kfd2kgd->wave_control_execute(dbgdev->dev->kgd, 761 1.1 riastrad reg_gfx_index.u32All, 762 1.1 riastrad reg_sq_cmd.u32All); 763 1.1 riastrad } 764 1.1 riastrad 765 1.1 riastrad int dbgdev_wave_reset_wavefronts(struct kfd_dev *dev, struct kfd_process *p) 766 1.1 riastrad { 767 1.1 riastrad int status = 0; 768 1.1 riastrad unsigned int vmid; 769 1.3 riastrad uint16_t queried_pasid; 770 1.1 riastrad union SQ_CMD_BITS reg_sq_cmd; 771 1.1 riastrad union GRBM_GFX_INDEX_BITS reg_gfx_index; 772 1.1 riastrad struct kfd_process_device *pdd; 773 1.1 riastrad struct dbg_wave_control_info wac_info; 774 1.3 riastrad int first_vmid_to_scan = dev->vm_info.first_vmid_kfd; 775 1.3 riastrad int last_vmid_to_scan = dev->vm_info.last_vmid_kfd; 776 1.1 riastrad 777 1.1 riastrad reg_sq_cmd.u32All = 0; 778 1.1 riastrad status = 0; 779 1.1 riastrad 780 1.1 riastrad wac_info.mode = HSA_DBG_WAVEMODE_BROADCAST_PROCESS; 781 1.1 riastrad wac_info.operand = HSA_DBG_WAVEOP_KILL; 782 1.1 riastrad 783 1.1 riastrad pr_debug("Killing all process wavefronts\n"); 784 1.1 riastrad 785 1.1 riastrad /* Scan all registers in the range ATC_VMID8_PASID_MAPPING .. 786 1.1 riastrad * ATC_VMID15_PASID_MAPPING 787 1.3 riastrad * to check which VMID the current process is mapped to. 788 1.3 riastrad */ 789 1.1 riastrad 790 1.1 riastrad for (vmid = first_vmid_to_scan; vmid <= last_vmid_to_scan; vmid++) { 791 1.3 riastrad status = dev->kfd2kgd->get_atc_vmid_pasid_mapping_info 792 1.3 riastrad (dev->kgd, vmid, &queried_pasid); 793 1.3 riastrad 794 1.3 riastrad if (status && queried_pasid == p->pasid) { 795 1.3 riastrad pr_debug("Killing wave fronts of vmid %d and pasid 0x%x\n", 796 1.3 riastrad vmid, p->pasid); 797 1.3 riastrad break; 798 1.1 riastrad } 799 1.1 riastrad } 800 1.1 riastrad 801 1.1 riastrad if (vmid > last_vmid_to_scan) { 802 1.3 riastrad pr_err("Didn't find vmid for pasid 0x%x\n", p->pasid); 803 1.1 riastrad return -EFAULT; 804 1.1 riastrad } 805 1.1 riastrad 806 1.1 riastrad /* taking the VMID for that process on the safe way using PDD */ 807 1.1 riastrad pdd = kfd_get_process_device_data(dev, p); 808 1.1 riastrad if (!pdd) 809 1.1 riastrad return -EFAULT; 810 1.1 riastrad 811 1.1 riastrad status = dbgdev_wave_control_set_registers(&wac_info, ®_sq_cmd, 812 1.1 riastrad ®_gfx_index); 813 1.1 riastrad if (status != 0) 814 1.1 riastrad return -EINVAL; 815 1.1 riastrad 816 1.1 riastrad /* for non DIQ we need to patch the VMID: */ 817 1.1 riastrad reg_sq_cmd.bits.vm_id = vmid; 818 1.1 riastrad 819 1.1 riastrad dev->kfd2kgd->wave_control_execute(dev->kgd, 820 1.1 riastrad reg_gfx_index.u32All, 821 1.1 riastrad reg_sq_cmd.u32All); 822 1.1 riastrad 823 1.1 riastrad return 0; 824 1.1 riastrad } 825 1.1 riastrad 826 1.1 riastrad void kfd_dbgdev_init(struct kfd_dbgdev *pdbgdev, struct kfd_dev *pdev, 827 1.1 riastrad enum DBGDEV_TYPE type) 828 1.1 riastrad { 829 1.1 riastrad pdbgdev->dev = pdev; 830 1.1 riastrad pdbgdev->kq = NULL; 831 1.1 riastrad pdbgdev->type = type; 832 1.1 riastrad pdbgdev->pqm = NULL; 833 1.1 riastrad 834 1.1 riastrad switch (type) { 835 1.1 riastrad case DBGDEV_TYPE_NODIQ: 836 1.1 riastrad pdbgdev->dbgdev_register = dbgdev_register_nodiq; 837 1.1 riastrad pdbgdev->dbgdev_unregister = dbgdev_unregister_nodiq; 838 1.1 riastrad pdbgdev->dbgdev_wave_control = dbgdev_wave_control_nodiq; 839 1.1 riastrad pdbgdev->dbgdev_address_watch = dbgdev_address_watch_nodiq; 840 1.1 riastrad break; 841 1.1 riastrad case DBGDEV_TYPE_DIQ: 842 1.1 riastrad default: 843 1.1 riastrad pdbgdev->dbgdev_register = dbgdev_register_diq; 844 1.1 riastrad pdbgdev->dbgdev_unregister = dbgdev_unregister_diq; 845 1.1 riastrad pdbgdev->dbgdev_wave_control = dbgdev_wave_control_diq; 846 1.1 riastrad pdbgdev->dbgdev_address_watch = dbgdev_address_watch_diq; 847 1.1 riastrad break; 848 1.1 riastrad } 849 1.1 riastrad 850 1.1 riastrad } 851