15073506cSJonathan Kim /*
25073506cSJonathan Kim * Copyright 2020 Advanced Micro Devices, Inc.
35073506cSJonathan Kim *
45073506cSJonathan Kim * Permission is hereby granted, free of charge, to any person obtaining a
55073506cSJonathan Kim * copy of this software and associated documentation files (the "Software"),
65073506cSJonathan Kim * to deal in the Software without restriction, including without limitation
75073506cSJonathan Kim * the rights to use, copy, modify, merge, publish, distribute, sublicense,
85073506cSJonathan Kim * and/or sell copies of the Software, and to permit persons to whom the
95073506cSJonathan Kim * Software is furnished to do so, subject to the following conditions:
105073506cSJonathan Kim *
115073506cSJonathan Kim * The above copyright notice and this permission notice shall be included in
125073506cSJonathan Kim * all copies or substantial portions of the Software.
135073506cSJonathan Kim *
145073506cSJonathan Kim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
155073506cSJonathan Kim * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
165073506cSJonathan Kim * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
175073506cSJonathan Kim * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
185073506cSJonathan Kim * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
195073506cSJonathan Kim * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
205073506cSJonathan Kim * OTHER DEALINGS IN THE SOFTWARE.
215073506cSJonathan Kim */
225073506cSJonathan Kim #include "amdgpu.h"
235073506cSJonathan Kim #include "amdgpu_amdkfd.h"
245073506cSJonathan Kim #include "amdgpu_amdkfd_arcturus.h"
255073506cSJonathan Kim #include "amdgpu_amdkfd_gfx_v9.h"
26036e348fSEric Huang #include "amdgpu_amdkfd_aldebaran.h"
27be6f9403SJonathan Kim #include "gc/gc_9_4_2_offset.h"
28be6f9403SJonathan Kim #include "gc/gc_9_4_2_sh_mask.h"
29101827e1SJonathan Kim #include <uapi/linux/kfd_ioctl.h>
30be6f9403SJonathan Kim
31be6f9403SJonathan Kim /*
32be6f9403SJonathan Kim * Returns TRAP_EN, EXCP_EN and EXCP_REPLACE.
33be6f9403SJonathan Kim *
34be6f9403SJonathan Kim * restore_dbg_registers is ignored here but is a general interface requirement
35be6f9403SJonathan Kim * for devices that support GFXOFF and where the RLC save/restore list
36be6f9403SJonathan Kim * does not support hw registers for debugging i.e. the driver has to manually
37be6f9403SJonathan Kim * initialize the debug mode registers after it has disabled GFX off during the
38be6f9403SJonathan Kim * debug session.
39be6f9403SJonathan Kim */
kgd_aldebaran_enable_debug_trap(struct amdgpu_device * adev,bool restore_dbg_registers,uint32_t vmid)40036e348fSEric Huang uint32_t kgd_aldebaran_enable_debug_trap(struct amdgpu_device *adev,
41be6f9403SJonathan Kim bool restore_dbg_registers,
42be6f9403SJonathan Kim uint32_t vmid)
43be6f9403SJonathan Kim {
44be6f9403SJonathan Kim uint32_t data = 0;
45be6f9403SJonathan Kim
46be6f9403SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, TRAP_EN, 1);
47be6f9403SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, EXCP_EN, 0);
48be6f9403SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, EXCP_REPLACE, 0);
49be6f9403SJonathan Kim
50be6f9403SJonathan Kim return data;
51be6f9403SJonathan Kim }
52be6f9403SJonathan Kim
53be6f9403SJonathan Kim /* returns TRAP_EN, EXCP_EN and EXCP_REPLACE. */
kgd_aldebaran_disable_debug_trap(struct amdgpu_device * adev,bool keep_trap_enabled,uint32_t vmid)54be6f9403SJonathan Kim static uint32_t kgd_aldebaran_disable_debug_trap(struct amdgpu_device *adev,
55be6f9403SJonathan Kim bool keep_trap_enabled,
56be6f9403SJonathan Kim uint32_t vmid)
57be6f9403SJonathan Kim {
58be6f9403SJonathan Kim uint32_t data = 0;
59be6f9403SJonathan Kim
60be6f9403SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, TRAP_EN, keep_trap_enabled);
61be6f9403SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, EXCP_EN, 0);
62be6f9403SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, EXCP_REPLACE, 0);
63be6f9403SJonathan Kim
64be6f9403SJonathan Kim return data;
65be6f9403SJonathan Kim }
665073506cSJonathan Kim
kgd_aldebaran_validate_trap_override_request(struct amdgpu_device * adev,uint32_t trap_override,uint32_t * trap_mask_supported)67101827e1SJonathan Kim static int kgd_aldebaran_validate_trap_override_request(struct amdgpu_device *adev,
68101827e1SJonathan Kim uint32_t trap_override,
69101827e1SJonathan Kim uint32_t *trap_mask_supported)
70101827e1SJonathan Kim {
71101827e1SJonathan Kim *trap_mask_supported &= KFD_DBG_TRAP_MASK_FP_INVALID |
72101827e1SJonathan Kim KFD_DBG_TRAP_MASK_FP_INPUT_DENORMAL |
73101827e1SJonathan Kim KFD_DBG_TRAP_MASK_FP_DIVIDE_BY_ZERO |
74101827e1SJonathan Kim KFD_DBG_TRAP_MASK_FP_OVERFLOW |
75101827e1SJonathan Kim KFD_DBG_TRAP_MASK_FP_UNDERFLOW |
76101827e1SJonathan Kim KFD_DBG_TRAP_MASK_FP_INEXACT |
77101827e1SJonathan Kim KFD_DBG_TRAP_MASK_INT_DIVIDE_BY_ZERO |
78101827e1SJonathan Kim KFD_DBG_TRAP_MASK_DBG_ADDRESS_WATCH |
79101827e1SJonathan Kim KFD_DBG_TRAP_MASK_DBG_MEMORY_VIOLATION;
80101827e1SJonathan Kim
81101827e1SJonathan Kim if (trap_override != KFD_DBG_TRAP_OVERRIDE_OR &&
82101827e1SJonathan Kim trap_override != KFD_DBG_TRAP_OVERRIDE_REPLACE)
83101827e1SJonathan Kim return -EPERM;
84101827e1SJonathan Kim
85101827e1SJonathan Kim return 0;
86101827e1SJonathan Kim }
87101827e1SJonathan Kim
88101827e1SJonathan Kim /* returns TRAP_EN, EXCP_EN and EXCP_RPLACE. */
kgd_aldebaran_set_wave_launch_trap_override(struct amdgpu_device * adev,uint32_t vmid,uint32_t trap_override,uint32_t trap_mask_bits,uint32_t trap_mask_request,uint32_t * trap_mask_prev,uint32_t kfd_dbg_trap_cntl_prev)89101827e1SJonathan Kim static uint32_t kgd_aldebaran_set_wave_launch_trap_override(struct amdgpu_device *adev,
90101827e1SJonathan Kim uint32_t vmid,
91101827e1SJonathan Kim uint32_t trap_override,
92101827e1SJonathan Kim uint32_t trap_mask_bits,
93101827e1SJonathan Kim uint32_t trap_mask_request,
94101827e1SJonathan Kim uint32_t *trap_mask_prev,
95101827e1SJonathan Kim uint32_t kfd_dbg_trap_cntl_prev)
96101827e1SJonathan Kim
97101827e1SJonathan Kim {
98101827e1SJonathan Kim uint32_t data = 0;
99101827e1SJonathan Kim
100101827e1SJonathan Kim *trap_mask_prev = REG_GET_FIELD(kfd_dbg_trap_cntl_prev, SPI_GDBG_PER_VMID_CNTL, EXCP_EN);
101101827e1SJonathan Kim trap_mask_bits = (trap_mask_bits & trap_mask_request) |
102101827e1SJonathan Kim (*trap_mask_prev & ~trap_mask_request);
103101827e1SJonathan Kim
104101827e1SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, TRAP_EN, 1);
105101827e1SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, EXCP_EN, trap_mask_bits);
106101827e1SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, EXCP_REPLACE, trap_override);
107101827e1SJonathan Kim
108101827e1SJonathan Kim return data;
109101827e1SJonathan Kim }
110101827e1SJonathan Kim
kgd_aldebaran_set_wave_launch_mode(struct amdgpu_device * adev,uint8_t wave_launch_mode,uint32_t vmid)111036e348fSEric Huang uint32_t kgd_aldebaran_set_wave_launch_mode(struct amdgpu_device *adev,
112aea1b473SJonathan Kim uint8_t wave_launch_mode,
113aea1b473SJonathan Kim uint32_t vmid)
114aea1b473SJonathan Kim {
115aea1b473SJonathan Kim uint32_t data = 0;
116aea1b473SJonathan Kim
117aea1b473SJonathan Kim data = REG_SET_FIELD(data, SPI_GDBG_PER_VMID_CNTL, LAUNCH_MODE, wave_launch_mode);
118aea1b473SJonathan Kim
119aea1b473SJonathan Kim return data;
120aea1b473SJonathan Kim }
121aea1b473SJonathan Kim
122e0f85f46SJonathan Kim #define TCP_WATCH_STRIDE (regTCP_WATCH1_ADDR_H - regTCP_WATCH0_ADDR_H)
kgd_gfx_aldebaran_set_address_watch(struct amdgpu_device * adev,uint64_t watch_address,uint32_t watch_address_mask,uint32_t watch_id,uint32_t watch_mode,uint32_t debug_vmid,uint32_t inst)123e0f85f46SJonathan Kim static uint32_t kgd_gfx_aldebaran_set_address_watch(
124e0f85f46SJonathan Kim struct amdgpu_device *adev,
125e0f85f46SJonathan Kim uint64_t watch_address,
126e0f85f46SJonathan Kim uint32_t watch_address_mask,
127e0f85f46SJonathan Kim uint32_t watch_id,
128e0f85f46SJonathan Kim uint32_t watch_mode,
129036e348fSEric Huang uint32_t debug_vmid,
130036e348fSEric Huang uint32_t inst)
131e0f85f46SJonathan Kim {
132e0f85f46SJonathan Kim uint32_t watch_address_high;
133e0f85f46SJonathan Kim uint32_t watch_address_low;
134e0f85f46SJonathan Kim uint32_t watch_address_cntl;
135e0f85f46SJonathan Kim
136e0f85f46SJonathan Kim watch_address_cntl = 0;
137e0f85f46SJonathan Kim watch_address_low = lower_32_bits(watch_address);
138e0f85f46SJonathan Kim watch_address_high = upper_32_bits(watch_address) & 0xffff;
139e0f85f46SJonathan Kim
140e0f85f46SJonathan Kim watch_address_cntl = REG_SET_FIELD(watch_address_cntl,
141e0f85f46SJonathan Kim TCP_WATCH0_CNTL,
142e0f85f46SJonathan Kim MODE,
143e0f85f46SJonathan Kim watch_mode);
144e0f85f46SJonathan Kim
145e0f85f46SJonathan Kim watch_address_cntl = REG_SET_FIELD(watch_address_cntl,
146e0f85f46SJonathan Kim TCP_WATCH0_CNTL,
147e0f85f46SJonathan Kim MASK,
148e0f85f46SJonathan Kim watch_address_mask >> 6);
149e0f85f46SJonathan Kim
150e0f85f46SJonathan Kim watch_address_cntl = REG_SET_FIELD(watch_address_cntl,
151e0f85f46SJonathan Kim TCP_WATCH0_CNTL,
152e0f85f46SJonathan Kim VALID,
153e0f85f46SJonathan Kim 1);
154e0f85f46SJonathan Kim
155e0f85f46SJonathan Kim WREG32_RLC((SOC15_REG_OFFSET(GC, 0, regTCP_WATCH0_ADDR_H) +
156e0f85f46SJonathan Kim (watch_id * TCP_WATCH_STRIDE)),
157e0f85f46SJonathan Kim watch_address_high);
158e0f85f46SJonathan Kim
159e0f85f46SJonathan Kim WREG32_RLC((SOC15_REG_OFFSET(GC, 0, regTCP_WATCH0_ADDR_L) +
160e0f85f46SJonathan Kim (watch_id * TCP_WATCH_STRIDE)),
161e0f85f46SJonathan Kim watch_address_low);
162e0f85f46SJonathan Kim
163e0f85f46SJonathan Kim return watch_address_cntl;
164e0f85f46SJonathan Kim }
165e0f85f46SJonathan Kim
1665073506cSJonathan Kim const struct kfd2kgd_calls aldebaran_kfd2kgd = {
1675073506cSJonathan Kim .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
1685073506cSJonathan Kim .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
1695073506cSJonathan Kim .init_interrupts = kgd_gfx_v9_init_interrupts,
1705073506cSJonathan Kim .hqd_load = kgd_gfx_v9_hqd_load,
1715073506cSJonathan Kim .hiq_mqd_load = kgd_gfx_v9_hiq_mqd_load,
1725073506cSJonathan Kim .hqd_sdma_load = kgd_arcturus_hqd_sdma_load,
1735073506cSJonathan Kim .hqd_dump = kgd_gfx_v9_hqd_dump,
1745073506cSJonathan Kim .hqd_sdma_dump = kgd_arcturus_hqd_sdma_dump,
1755073506cSJonathan Kim .hqd_is_occupied = kgd_gfx_v9_hqd_is_occupied,
1765073506cSJonathan Kim .hqd_sdma_is_occupied = kgd_arcturus_hqd_sdma_is_occupied,
1775073506cSJonathan Kim .hqd_destroy = kgd_gfx_v9_hqd_destroy,
1785073506cSJonathan Kim .hqd_sdma_destroy = kgd_arcturus_hqd_sdma_destroy,
1795073506cSJonathan Kim .wave_control_execute = kgd_gfx_v9_wave_control_execute,
1805073506cSJonathan Kim .get_atc_vmid_pasid_mapping_info =
1815073506cSJonathan Kim kgd_gfx_v9_get_atc_vmid_pasid_mapping_info,
1825073506cSJonathan Kim .set_vm_context_page_table_base = kgd_gfx_v9_set_vm_context_page_table_base,
183b9ab82daSRamesh Errabolu .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy,
184be6f9403SJonathan Kim .enable_debug_trap = kgd_aldebaran_enable_debug_trap,
185be6f9403SJonathan Kim .disable_debug_trap = kgd_aldebaran_disable_debug_trap,
186101827e1SJonathan Kim .validate_trap_override_request = kgd_aldebaran_validate_trap_override_request,
187101827e1SJonathan Kim .set_wave_launch_trap_override = kgd_aldebaran_set_wave_launch_trap_override,
188aea1b473SJonathan Kim .set_wave_launch_mode = kgd_aldebaran_set_wave_launch_mode,
189e0f85f46SJonathan Kim .set_address_watch = kgd_gfx_aldebaran_set_address_watch,
190*3831989dSEric Huang .clear_address_watch = kgd_gfx_v9_clear_address_watch,
1917cee6a68SJonathan Kim .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times,
1927cee6a68SJonathan Kim .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info,
193be6f9403SJonathan Kim .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings,
1945073506cSJonathan Kim };
195