162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright 2023 Advanced Micro Devices, Inc. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 1262306a36Sopenharmony_ci * all copies or substantial portions of the Software. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#ifndef KFD_DEBUG_EVENTS_H_INCLUDED 2462306a36Sopenharmony_ci#define KFD_DEBUG_EVENTS_H_INCLUDED 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#include "kfd_priv.h" 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_civoid kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwind_count); 2962306a36Sopenharmony_ciint kfd_dbg_trap_activate(struct kfd_process *target); 3062306a36Sopenharmony_ciint kfd_dbg_ev_query_debug_event(struct kfd_process *process, 3162306a36Sopenharmony_ci unsigned int *queue_id, 3262306a36Sopenharmony_ci unsigned int *gpu_id, 3362306a36Sopenharmony_ci uint64_t exception_clear_mask, 3462306a36Sopenharmony_ci uint64_t *event_status); 3562306a36Sopenharmony_cibool kfd_set_dbg_ev_from_interrupt(struct kfd_node *dev, 3662306a36Sopenharmony_ci unsigned int pasid, 3762306a36Sopenharmony_ci uint32_t doorbell_id, 3862306a36Sopenharmony_ci uint64_t trap_mask, 3962306a36Sopenharmony_ci void *exception_data, 4062306a36Sopenharmony_ci size_t exception_data_size); 4162306a36Sopenharmony_cibool kfd_dbg_ev_raise(uint64_t event_mask, 4262306a36Sopenharmony_ci struct kfd_process *process, struct kfd_node *dev, 4362306a36Sopenharmony_ci unsigned int source_id, bool use_worker, 4462306a36Sopenharmony_ci void *exception_data, 4562306a36Sopenharmony_ci size_t exception_data_size); 4662306a36Sopenharmony_ciint kfd_dbg_trap_disable(struct kfd_process *target); 4762306a36Sopenharmony_ciint kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd, 4862306a36Sopenharmony_ci void __user *runtime_info, 4962306a36Sopenharmony_ci uint32_t *runtime_info_size); 5062306a36Sopenharmony_ciint kfd_dbg_trap_set_wave_launch_override(struct kfd_process *target, 5162306a36Sopenharmony_ci uint32_t trap_override, 5262306a36Sopenharmony_ci uint32_t trap_mask_bits, 5362306a36Sopenharmony_ci uint32_t trap_mask_request, 5462306a36Sopenharmony_ci uint32_t *trap_mask_prev, 5562306a36Sopenharmony_ci uint32_t *trap_mask_supported); 5662306a36Sopenharmony_ciint kfd_dbg_trap_set_wave_launch_mode(struct kfd_process *target, 5762306a36Sopenharmony_ci uint8_t wave_launch_mode); 5862306a36Sopenharmony_ciint kfd_dbg_trap_clear_dev_address_watch(struct kfd_process_device *pdd, 5962306a36Sopenharmony_ci uint32_t watch_id); 6062306a36Sopenharmony_ciint kfd_dbg_trap_set_dev_address_watch(struct kfd_process_device *pdd, 6162306a36Sopenharmony_ci uint64_t watch_address, 6262306a36Sopenharmony_ci uint32_t watch_address_mask, 6362306a36Sopenharmony_ci uint32_t *watch_id, 6462306a36Sopenharmony_ci uint32_t watch_mode); 6562306a36Sopenharmony_ciint kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags); 6662306a36Sopenharmony_ciint kfd_dbg_trap_query_exception_info(struct kfd_process *target, 6762306a36Sopenharmony_ci uint32_t source_id, 6862306a36Sopenharmony_ci uint32_t exception_code, 6962306a36Sopenharmony_ci bool clear_exception, 7062306a36Sopenharmony_ci void __user *info, 7162306a36Sopenharmony_ci uint32_t *info_size); 7262306a36Sopenharmony_ciint kfd_dbg_send_exception_to_runtime(struct kfd_process *p, 7362306a36Sopenharmony_ci unsigned int dev_id, 7462306a36Sopenharmony_ci unsigned int queue_id, 7562306a36Sopenharmony_ci uint64_t error_reason); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_cistatic inline bool kfd_dbg_is_per_vmid_supported(struct kfd_node *dev) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci return (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) || 8062306a36Sopenharmony_ci KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 3) || 8162306a36Sopenharmony_ci KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0)); 8262306a36Sopenharmony_ci} 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_civoid debug_event_write_work_handler(struct work_struct *work); 8562306a36Sopenharmony_ciint kfd_dbg_trap_device_snapshot(struct kfd_process *target, 8662306a36Sopenharmony_ci uint64_t exception_clear_mask, 8762306a36Sopenharmony_ci void __user *user_info, 8862306a36Sopenharmony_ci uint32_t *number_of_device_infos, 8962306a36Sopenharmony_ci uint32_t *entry_size); 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_civoid kfd_dbg_set_enabled_debug_exception_mask(struct kfd_process *target, 9262306a36Sopenharmony_ci uint64_t exception_set_mask); 9362306a36Sopenharmony_ci/* 9462306a36Sopenharmony_ci * If GFX off is enabled, chips that do not support RLC restore for the debug 9562306a36Sopenharmony_ci * registers will disable GFX off temporarily for the entire debug session. 9662306a36Sopenharmony_ci * See disable_on_trap_action_entry and enable_on_trap_action_exit for details. 9762306a36Sopenharmony_ci */ 9862306a36Sopenharmony_cistatic inline bool kfd_dbg_is_rlc_restore_supported(struct kfd_node *dev) 9962306a36Sopenharmony_ci{ 10062306a36Sopenharmony_ci return !(KFD_GC_VERSION(dev) == IP_VERSION(10, 1, 10) || 10162306a36Sopenharmony_ci KFD_GC_VERSION(dev) == IP_VERSION(10, 1, 1)); 10262306a36Sopenharmony_ci} 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_cistatic inline bool kfd_dbg_has_cwsr_workaround(struct kfd_node *dev) 10562306a36Sopenharmony_ci{ 10662306a36Sopenharmony_ci return KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0) && 10762306a36Sopenharmony_ci KFD_GC_VERSION(dev) <= IP_VERSION(11, 0, 3); 10862306a36Sopenharmony_ci} 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cistatic inline bool kfd_dbg_has_gws_support(struct kfd_node *dev) 11162306a36Sopenharmony_ci{ 11262306a36Sopenharmony_ci if ((KFD_GC_VERSION(dev) == IP_VERSION(9, 0, 1) 11362306a36Sopenharmony_ci && dev->kfd->mec2_fw_version < 0x81b6) || 11462306a36Sopenharmony_ci (KFD_GC_VERSION(dev) >= IP_VERSION(9, 1, 0) 11562306a36Sopenharmony_ci && KFD_GC_VERSION(dev) <= IP_VERSION(9, 2, 2) 11662306a36Sopenharmony_ci && dev->kfd->mec2_fw_version < 0x1b6) || 11762306a36Sopenharmony_ci (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0) 11862306a36Sopenharmony_ci && dev->kfd->mec2_fw_version < 0x1b6) || 11962306a36Sopenharmony_ci (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) 12062306a36Sopenharmony_ci && dev->kfd->mec2_fw_version < 0x30) || 12162306a36Sopenharmony_ci (KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0) && 12262306a36Sopenharmony_ci KFD_GC_VERSION(dev) < IP_VERSION(12, 0, 0))) 12362306a36Sopenharmony_ci return false; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci /* Assume debugging and cooperative launch supported otherwise. */ 12662306a36Sopenharmony_ci return true; 12762306a36Sopenharmony_ci} 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ciint kfd_dbg_set_mes_debug_mode(struct kfd_process_device *pdd, bool sq_trap_en); 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_cistatic inline bool kfd_dbg_has_ttmps_always_setup(struct kfd_node *dev) 13262306a36Sopenharmony_ci{ 13362306a36Sopenharmony_ci return (KFD_GC_VERSION(dev) < IP_VERSION(11, 0, 0) && 13462306a36Sopenharmony_ci KFD_GC_VERSION(dev) != IP_VERSION(9, 4, 2)) || 13562306a36Sopenharmony_ci (KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0) && 13662306a36Sopenharmony_ci KFD_GC_VERSION(dev) < IP_VERSION(12, 0, 0) && 13762306a36Sopenharmony_ci (dev->adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >= 70); 13862306a36Sopenharmony_ci} 13962306a36Sopenharmony_ci#endif 140