10ab2d753SJonathan Kim /* 20ab2d753SJonathan Kim * Copyright 2023 Advanced Micro Devices, Inc. 30ab2d753SJonathan Kim * 40ab2d753SJonathan Kim * Permission is hereby granted, free of charge, to any person obtaining a 50ab2d753SJonathan Kim * copy of this software and associated documentation files (the "Software"), 60ab2d753SJonathan Kim * to deal in the Software without restriction, including without limitation 70ab2d753SJonathan Kim * the rights to use, copy, modify, merge, publish, distribute, sublicense, 80ab2d753SJonathan Kim * and/or sell copies of the Software, and to permit persons to whom the 90ab2d753SJonathan Kim * Software is furnished to do so, subject to the following conditions: 100ab2d753SJonathan Kim * 110ab2d753SJonathan Kim * The above copyright notice and this permission notice shall be included in 120ab2d753SJonathan Kim * all copies or substantial portions of the Software. 130ab2d753SJonathan Kim * 140ab2d753SJonathan Kim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 150ab2d753SJonathan Kim * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 160ab2d753SJonathan Kim * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 170ab2d753SJonathan Kim * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 180ab2d753SJonathan Kim * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 190ab2d753SJonathan Kim * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 200ab2d753SJonathan Kim * OTHER DEALINGS IN THE SOFTWARE. 210ab2d753SJonathan Kim */ 220ab2d753SJonathan Kim 230ab2d753SJonathan Kim #ifndef KFD_DEBUG_EVENTS_H_INCLUDED 240ab2d753SJonathan Kim #define KFD_DEBUG_EVENTS_H_INCLUDED 250ab2d753SJonathan Kim 260ab2d753SJonathan Kim #include "kfd_priv.h" 270ab2d753SJonathan Kim 28455227c4SJonathan Kim void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwind_count); 29455227c4SJonathan Kim int kfd_dbg_trap_activate(struct kfd_process *target); 30*12fb1ad7SJonathan Kim bool kfd_set_dbg_ev_from_interrupt(struct kfd_node *dev, 31*12fb1ad7SJonathan Kim unsigned int pasid, 32*12fb1ad7SJonathan Kim uint32_t doorbell_id, 33*12fb1ad7SJonathan Kim uint64_t trap_mask, 34*12fb1ad7SJonathan Kim void *exception_data, 35*12fb1ad7SJonathan Kim size_t exception_data_size); 3644b87bb0SJonathan Kim bool kfd_dbg_ev_raise(uint64_t event_mask, 3744b87bb0SJonathan Kim struct kfd_process *process, struct kfd_node *dev, 3844b87bb0SJonathan Kim unsigned int source_id, bool use_worker, 3944b87bb0SJonathan Kim void *exception_data, 4044b87bb0SJonathan Kim size_t exception_data_size); 410ab2d753SJonathan Kim int kfd_dbg_trap_disable(struct kfd_process *target); 420ab2d753SJonathan Kim int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd, 430ab2d753SJonathan Kim void __user *runtime_info, 440ab2d753SJonathan Kim uint32_t *runtime_info_size); 45c2d2588cSJonathan Kim 46c2d2588cSJonathan Kim int kfd_dbg_send_exception_to_runtime(struct kfd_process *p, 47c2d2588cSJonathan Kim unsigned int dev_id, 48c2d2588cSJonathan Kim unsigned int queue_id, 49c2d2588cSJonathan Kim uint64_t error_reason); 50c2d2588cSJonathan Kim 510de4ec9aSJonathan Kim static inline bool kfd_dbg_is_per_vmid_supported(struct kfd_node *dev) 520de4ec9aSJonathan Kim { 5369a8c3aeSJonathan Kim return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) || 5469a8c3aeSJonathan Kim KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0); 550de4ec9aSJonathan Kim } 560de4ec9aSJonathan Kim 5744b87bb0SJonathan Kim void debug_event_write_work_handler(struct work_struct *work); 5844b87bb0SJonathan Kim 5921889582SJonathan Kim /* 6021889582SJonathan Kim * If GFX off is enabled, chips that do not support RLC restore for the debug 6121889582SJonathan Kim * registers will disable GFX off temporarily for the entire debug session. 6221889582SJonathan Kim * See disable_on_trap_action_entry and enable_on_trap_action_exit for details. 6321889582SJonathan Kim */ 6421889582SJonathan Kim static inline bool kfd_dbg_is_rlc_restore_supported(struct kfd_node *dev) 6521889582SJonathan Kim { 6621889582SJonathan Kim return !(KFD_GC_VERSION(dev) == IP_VERSION(10, 1, 10) || 6721889582SJonathan Kim KFD_GC_VERSION(dev) == IP_VERSION(10, 1, 1)); 6821889582SJonathan Kim } 6921889582SJonathan Kim 7021889582SJonathan Kim static inline bool kfd_dbg_has_gws_support(struct kfd_node *dev) 7121889582SJonathan Kim { 7221889582SJonathan Kim if ((KFD_GC_VERSION(dev) == IP_VERSION(9, 0, 1) 7321889582SJonathan Kim && dev->kfd->mec2_fw_version < 0x81b6) || 7421889582SJonathan Kim (KFD_GC_VERSION(dev) >= IP_VERSION(9, 1, 0) 7521889582SJonathan Kim && KFD_GC_VERSION(dev) <= IP_VERSION(9, 2, 2) 7621889582SJonathan Kim && dev->kfd->mec2_fw_version < 0x1b6) || 7721889582SJonathan Kim (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0) 7821889582SJonathan Kim && dev->kfd->mec2_fw_version < 0x1b6) || 7921889582SJonathan Kim (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) 8021889582SJonathan Kim && dev->kfd->mec2_fw_version < 0x30) || 8121889582SJonathan Kim (KFD_GC_VERSION(dev) >= IP_VERSION(11, 0, 0) && 8221889582SJonathan Kim KFD_GC_VERSION(dev) < IP_VERSION(12, 0, 0))) 8321889582SJonathan Kim return false; 8421889582SJonathan Kim 8521889582SJonathan Kim /* Assume debugging and cooperative launch supported otherwise. */ 8621889582SJonathan Kim return true; 8721889582SJonathan Kim } 88455227c4SJonathan Kim 89455227c4SJonathan Kim int kfd_dbg_set_mes_debug_mode(struct kfd_process_device *pdd); 900ab2d753SJonathan Kim #endif 91