Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Advanced Micro Devices, Inc. |
| 3 | * |
| 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: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 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. |
| 21 | * |
| 22 | * Authors: Alex Deucher |
| 23 | */ |
| 24 | #include <linux/firmware.h> |
| 25 | #include <drm/drmP.h> |
| 26 | #include "amdgpu.h" |
| 27 | #include "amdgpu_ucode.h" |
| 28 | #include "amdgpu_trace.h" |
| 29 | #include "vi.h" |
| 30 | #include "vid.h" |
| 31 | |
| 32 | #include "oss/oss_2_4_d.h" |
| 33 | #include "oss/oss_2_4_sh_mask.h" |
| 34 | |
| 35 | #include "gmc/gmc_8_1_d.h" |
| 36 | #include "gmc/gmc_8_1_sh_mask.h" |
| 37 | |
| 38 | #include "gca/gfx_8_0_d.h" |
Jack Xiao | 74a5d16 | 2015-05-08 14:46:49 +0800 | [diff] [blame] | 39 | #include "gca/gfx_8_0_enum.h" |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 40 | #include "gca/gfx_8_0_sh_mask.h" |
| 41 | |
| 42 | #include "bif/bif_5_0_d.h" |
| 43 | #include "bif/bif_5_0_sh_mask.h" |
| 44 | |
| 45 | #include "iceland_sdma_pkt_open.h" |
| 46 | |
| 47 | static void sdma_v2_4_set_ring_funcs(struct amdgpu_device *adev); |
| 48 | static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev); |
| 49 | static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev); |
| 50 | static void sdma_v2_4_set_irq_funcs(struct amdgpu_device *adev); |
| 51 | |
Jammy Zhou | c65444f | 2015-05-13 22:49:04 +0800 | [diff] [blame] | 52 | MODULE_FIRMWARE("amdgpu/topaz_sdma.bin"); |
| 53 | MODULE_FIRMWARE("amdgpu/topaz_sdma1.bin"); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 54 | |
| 55 | static const u32 sdma_offsets[SDMA_MAX_INSTANCE] = |
| 56 | { |
| 57 | SDMA0_REGISTER_OFFSET, |
| 58 | SDMA1_REGISTER_OFFSET |
| 59 | }; |
| 60 | |
| 61 | static const u32 golden_settings_iceland_a11[] = |
| 62 | { |
| 63 | mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007, |
| 64 | mmSDMA0_CLK_CTRL, 0xff000fff, 0x00000000, |
| 65 | mmSDMA1_CHICKEN_BITS, 0xfc910007, 0x00810007, |
| 66 | mmSDMA1_CLK_CTRL, 0xff000fff, 0x00000000, |
| 67 | }; |
| 68 | |
| 69 | static const u32 iceland_mgcg_cgcg_init[] = |
| 70 | { |
| 71 | mmSDMA0_CLK_CTRL, 0xff000ff0, 0x00000100, |
| 72 | mmSDMA1_CLK_CTRL, 0xff000ff0, 0x00000100 |
| 73 | }; |
| 74 | |
| 75 | /* |
| 76 | * sDMA - System DMA |
| 77 | * Starting with CIK, the GPU has new asynchronous |
| 78 | * DMA engines. These engines are used for compute |
| 79 | * and gfx. There are two DMA engines (SDMA0, SDMA1) |
| 80 | * and each one supports 1 ring buffer used for gfx |
| 81 | * and 2 queues used for compute. |
| 82 | * |
| 83 | * The programming model is very similar to the CP |
| 84 | * (ring buffer, IBs, etc.), but sDMA has it's own |
| 85 | * packet format that is different from the PM4 format |
| 86 | * used by the CP. sDMA supports copying data, writing |
| 87 | * embedded data, solid fills, and a number of other |
| 88 | * things. It also has support for tiling/detiling of |
| 89 | * buffers. |
| 90 | */ |
| 91 | |
| 92 | static void sdma_v2_4_init_golden_registers(struct amdgpu_device *adev) |
| 93 | { |
| 94 | switch (adev->asic_type) { |
| 95 | case CHIP_TOPAZ: |
| 96 | amdgpu_program_register_sequence(adev, |
| 97 | iceland_mgcg_cgcg_init, |
| 98 | (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init)); |
| 99 | amdgpu_program_register_sequence(adev, |
| 100 | golden_settings_iceland_a11, |
| 101 | (const u32)ARRAY_SIZE(golden_settings_iceland_a11)); |
| 102 | break; |
| 103 | default: |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * sdma_v2_4_init_microcode - load ucode images from disk |
| 110 | * |
| 111 | * @adev: amdgpu_device pointer |
| 112 | * |
| 113 | * Use the firmware interface to load the ucode images into |
| 114 | * the driver (not loaded into hw). |
| 115 | * Returns 0 on success, error on failure. |
| 116 | */ |
| 117 | static int sdma_v2_4_init_microcode(struct amdgpu_device *adev) |
| 118 | { |
| 119 | const char *chip_name; |
| 120 | char fw_name[30]; |
| 121 | int err, i; |
| 122 | struct amdgpu_firmware_info *info = NULL; |
| 123 | const struct common_firmware_header *header = NULL; |
Jammy Zhou | 595fd01 | 2015-08-04 11:44:19 +0800 | [diff] [blame] | 124 | const struct sdma_firmware_header_v1_0 *hdr; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 125 | |
| 126 | DRM_DEBUG("\n"); |
| 127 | |
| 128 | switch (adev->asic_type) { |
| 129 | case CHIP_TOPAZ: |
| 130 | chip_name = "topaz"; |
| 131 | break; |
| 132 | default: BUG(); |
| 133 | } |
| 134 | |
| 135 | for (i = 0; i < SDMA_MAX_INSTANCE; i++) { |
| 136 | if (i == 0) |
Jammy Zhou | c65444f | 2015-05-13 22:49:04 +0800 | [diff] [blame] | 137 | snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma.bin", chip_name); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 138 | else |
Jammy Zhou | c65444f | 2015-05-13 22:49:04 +0800 | [diff] [blame] | 139 | snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma1.bin", chip_name); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 140 | err = request_firmware(&adev->sdma[i].fw, fw_name, adev->dev); |
| 141 | if (err) |
| 142 | goto out; |
| 143 | err = amdgpu_ucode_validate(adev->sdma[i].fw); |
| 144 | if (err) |
| 145 | goto out; |
Jammy Zhou | 595fd01 | 2015-08-04 11:44:19 +0800 | [diff] [blame] | 146 | hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma[i].fw->data; |
| 147 | adev->sdma[i].fw_version = le32_to_cpu(hdr->header.ucode_version); |
| 148 | adev->sdma[i].feature_version = le32_to_cpu(hdr->ucode_feature_version); |
Jammy Zhou | 18111de | 2015-08-31 14:06:39 +0800 | [diff] [blame^] | 149 | if (adev->sdma[i].feature_version >= 20) |
| 150 | adev->sdma[i].burst_nop = true; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 151 | |
| 152 | if (adev->firmware.smu_load) { |
| 153 | info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i]; |
| 154 | info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i; |
| 155 | info->fw = adev->sdma[i].fw; |
| 156 | header = (const struct common_firmware_header *)info->fw->data; |
| 157 | adev->firmware.fw_size += |
| 158 | ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | out: |
| 163 | if (err) { |
| 164 | printk(KERN_ERR |
| 165 | "sdma_v2_4: Failed to load firmware \"%s\"\n", |
| 166 | fw_name); |
| 167 | for (i = 0; i < SDMA_MAX_INSTANCE; i++) { |
| 168 | release_firmware(adev->sdma[i].fw); |
| 169 | adev->sdma[i].fw = NULL; |
| 170 | } |
| 171 | } |
| 172 | return err; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * sdma_v2_4_ring_get_rptr - get the current read pointer |
| 177 | * |
| 178 | * @ring: amdgpu ring pointer |
| 179 | * |
| 180 | * Get the current rptr from the hardware (VI+). |
| 181 | */ |
| 182 | static uint32_t sdma_v2_4_ring_get_rptr(struct amdgpu_ring *ring) |
| 183 | { |
| 184 | u32 rptr; |
| 185 | |
| 186 | /* XXX check if swapping is necessary on BE */ |
| 187 | rptr = ring->adev->wb.wb[ring->rptr_offs] >> 2; |
| 188 | |
| 189 | return rptr; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * sdma_v2_4_ring_get_wptr - get the current write pointer |
| 194 | * |
| 195 | * @ring: amdgpu ring pointer |
| 196 | * |
| 197 | * Get the current wptr from the hardware (VI+). |
| 198 | */ |
| 199 | static uint32_t sdma_v2_4_ring_get_wptr(struct amdgpu_ring *ring) |
| 200 | { |
| 201 | struct amdgpu_device *adev = ring->adev; |
| 202 | int me = (ring == &ring->adev->sdma[0].ring) ? 0 : 1; |
| 203 | u32 wptr = RREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[me]) >> 2; |
| 204 | |
| 205 | return wptr; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * sdma_v2_4_ring_set_wptr - commit the write pointer |
| 210 | * |
| 211 | * @ring: amdgpu ring pointer |
| 212 | * |
| 213 | * Write the wptr back to the hardware (VI+). |
| 214 | */ |
| 215 | static void sdma_v2_4_ring_set_wptr(struct amdgpu_ring *ring) |
| 216 | { |
| 217 | struct amdgpu_device *adev = ring->adev; |
| 218 | int me = (ring == &ring->adev->sdma[0].ring) ? 0 : 1; |
| 219 | |
| 220 | WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[me], ring->wptr << 2); |
| 221 | } |
| 222 | |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 223 | /** |
| 224 | * sdma_v2_4_ring_emit_ib - Schedule an IB on the DMA engine |
| 225 | * |
| 226 | * @ring: amdgpu ring pointer |
| 227 | * @ib: IB object to schedule |
| 228 | * |
| 229 | * Schedule an IB in the DMA ring (VI). |
| 230 | */ |
| 231 | static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring, |
| 232 | struct amdgpu_ib *ib) |
| 233 | { |
| 234 | u32 vmid = (ib->vm ? ib->vm->ids[ring->idx].id : 0) & 0xf; |
| 235 | u32 next_rptr = ring->wptr + 5; |
| 236 | |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 237 | while ((next_rptr & 7) != 2) |
| 238 | next_rptr++; |
| 239 | |
| 240 | next_rptr += 6; |
| 241 | |
| 242 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) | |
| 243 | SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR)); |
| 244 | amdgpu_ring_write(ring, lower_32_bits(ring->next_rptr_gpu_addr) & 0xfffffffc); |
| 245 | amdgpu_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr)); |
| 246 | amdgpu_ring_write(ring, SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(1)); |
| 247 | amdgpu_ring_write(ring, next_rptr); |
| 248 | |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 249 | /* IB packet must end on a 8 DW boundary */ |
| 250 | while ((ring->wptr & 7) != 2) |
| 251 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_NOP)); |
| 252 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_INDIRECT) | |
| 253 | SDMA_PKT_INDIRECT_HEADER_VMID(vmid)); |
| 254 | /* base must be 32 byte aligned */ |
| 255 | amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr) & 0xffffffe0); |
| 256 | amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr)); |
| 257 | amdgpu_ring_write(ring, ib->length_dw); |
| 258 | amdgpu_ring_write(ring, 0); |
| 259 | amdgpu_ring_write(ring, 0); |
| 260 | |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * sdma_v2_4_hdp_flush_ring_emit - emit an hdp flush on the DMA ring |
| 265 | * |
| 266 | * @ring: amdgpu ring pointer |
| 267 | * |
| 268 | * Emit an hdp flush packet on the requested DMA ring. |
| 269 | */ |
Christian König | d2edb07 | 2015-05-11 14:10:34 +0200 | [diff] [blame] | 270 | static void sdma_v2_4_ring_emit_hdp_flush(struct amdgpu_ring *ring) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 271 | { |
| 272 | u32 ref_and_mask = 0; |
| 273 | |
| 274 | if (ring == &ring->adev->sdma[0].ring) |
| 275 | ref_and_mask = REG_SET_FIELD(ref_and_mask, GPU_HDP_FLUSH_DONE, SDMA0, 1); |
| 276 | else |
| 277 | ref_and_mask = REG_SET_FIELD(ref_and_mask, GPU_HDP_FLUSH_DONE, SDMA1, 1); |
| 278 | |
| 279 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) | |
| 280 | SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(1) | |
| 281 | SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3)); /* == */ |
| 282 | amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE << 2); |
| 283 | amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ << 2); |
| 284 | amdgpu_ring_write(ring, ref_and_mask); /* reference */ |
| 285 | amdgpu_ring_write(ring, ref_and_mask); /* mask */ |
| 286 | amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) | |
| 287 | SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10)); /* retry count, poll interval */ |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * sdma_v2_4_ring_emit_fence - emit a fence on the DMA ring |
| 292 | * |
| 293 | * @ring: amdgpu ring pointer |
| 294 | * @fence: amdgpu fence object |
| 295 | * |
| 296 | * Add a DMA fence packet to the ring to write |
| 297 | * the fence seq number and DMA trap packet to generate |
| 298 | * an interrupt if needed (VI). |
| 299 | */ |
| 300 | static void sdma_v2_4_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq, |
Chunming Zhou | 890ee23 | 2015-06-01 14:35:03 +0800 | [diff] [blame] | 301 | unsigned flags) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 302 | { |
Chunming Zhou | 890ee23 | 2015-06-01 14:35:03 +0800 | [diff] [blame] | 303 | bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 304 | /* write the fence */ |
| 305 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE)); |
| 306 | amdgpu_ring_write(ring, lower_32_bits(addr)); |
| 307 | amdgpu_ring_write(ring, upper_32_bits(addr)); |
| 308 | amdgpu_ring_write(ring, lower_32_bits(seq)); |
| 309 | |
| 310 | /* optionally write high bits as well */ |
Chunming Zhou | 890ee23 | 2015-06-01 14:35:03 +0800 | [diff] [blame] | 311 | if (write64bit) { |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 312 | addr += 4; |
| 313 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE)); |
| 314 | amdgpu_ring_write(ring, lower_32_bits(addr)); |
| 315 | amdgpu_ring_write(ring, upper_32_bits(addr)); |
| 316 | amdgpu_ring_write(ring, upper_32_bits(seq)); |
| 317 | } |
| 318 | |
| 319 | /* generate an interrupt */ |
| 320 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_TRAP)); |
| 321 | amdgpu_ring_write(ring, SDMA_PKT_TRAP_INT_CONTEXT_INT_CONTEXT(0)); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * sdma_v2_4_ring_emit_semaphore - emit a semaphore on the dma ring |
| 326 | * |
| 327 | * @ring: amdgpu_ring structure holding ring information |
| 328 | * @semaphore: amdgpu semaphore object |
| 329 | * @emit_wait: wait or signal semaphore |
| 330 | * |
| 331 | * Add a DMA semaphore packet to the ring wait on or signal |
| 332 | * other rings (VI). |
| 333 | */ |
| 334 | static bool sdma_v2_4_ring_emit_semaphore(struct amdgpu_ring *ring, |
| 335 | struct amdgpu_semaphore *semaphore, |
| 336 | bool emit_wait) |
| 337 | { |
| 338 | u64 addr = semaphore->gpu_addr; |
| 339 | u32 sig = emit_wait ? 0 : 1; |
| 340 | |
| 341 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SEM) | |
| 342 | SDMA_PKT_SEMAPHORE_HEADER_SIGNAL(sig)); |
| 343 | amdgpu_ring_write(ring, lower_32_bits(addr) & 0xfffffff8); |
| 344 | amdgpu_ring_write(ring, upper_32_bits(addr)); |
| 345 | |
| 346 | return true; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * sdma_v2_4_gfx_stop - stop the gfx async dma engines |
| 351 | * |
| 352 | * @adev: amdgpu_device pointer |
| 353 | * |
| 354 | * Stop the gfx async dma ring buffers (VI). |
| 355 | */ |
| 356 | static void sdma_v2_4_gfx_stop(struct amdgpu_device *adev) |
| 357 | { |
| 358 | struct amdgpu_ring *sdma0 = &adev->sdma[0].ring; |
| 359 | struct amdgpu_ring *sdma1 = &adev->sdma[1].ring; |
| 360 | u32 rb_cntl, ib_cntl; |
| 361 | int i; |
| 362 | |
| 363 | if ((adev->mman.buffer_funcs_ring == sdma0) || |
| 364 | (adev->mman.buffer_funcs_ring == sdma1)) |
| 365 | amdgpu_ttm_set_active_vram_size(adev, adev->mc.visible_vram_size); |
| 366 | |
| 367 | for (i = 0; i < SDMA_MAX_INSTANCE; i++) { |
| 368 | rb_cntl = RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]); |
| 369 | rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0); |
| 370 | WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl); |
| 371 | ib_cntl = RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]); |
| 372 | ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0); |
| 373 | WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl); |
| 374 | } |
| 375 | sdma0->ready = false; |
| 376 | sdma1->ready = false; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * sdma_v2_4_rlc_stop - stop the compute async dma engines |
| 381 | * |
| 382 | * @adev: amdgpu_device pointer |
| 383 | * |
| 384 | * Stop the compute async dma queues (VI). |
| 385 | */ |
| 386 | static void sdma_v2_4_rlc_stop(struct amdgpu_device *adev) |
| 387 | { |
| 388 | /* XXX todo */ |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * sdma_v2_4_enable - stop the async dma engines |
| 393 | * |
| 394 | * @adev: amdgpu_device pointer |
| 395 | * @enable: enable/disable the DMA MEs. |
| 396 | * |
| 397 | * Halt or unhalt the async dma engines (VI). |
| 398 | */ |
| 399 | static void sdma_v2_4_enable(struct amdgpu_device *adev, bool enable) |
| 400 | { |
| 401 | u32 f32_cntl; |
| 402 | int i; |
| 403 | |
| 404 | if (enable == false) { |
| 405 | sdma_v2_4_gfx_stop(adev); |
| 406 | sdma_v2_4_rlc_stop(adev); |
| 407 | } |
| 408 | |
| 409 | for (i = 0; i < SDMA_MAX_INSTANCE; i++) { |
| 410 | f32_cntl = RREG32(mmSDMA0_F32_CNTL + sdma_offsets[i]); |
| 411 | if (enable) |
| 412 | f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 0); |
| 413 | else |
| 414 | f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 1); |
| 415 | WREG32(mmSDMA0_F32_CNTL + sdma_offsets[i], f32_cntl); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * sdma_v2_4_gfx_resume - setup and start the async dma engines |
| 421 | * |
| 422 | * @adev: amdgpu_device pointer |
| 423 | * |
| 424 | * Set up the gfx DMA ring buffers and enable them (VI). |
| 425 | * Returns 0 for success, error for failure. |
| 426 | */ |
| 427 | static int sdma_v2_4_gfx_resume(struct amdgpu_device *adev) |
| 428 | { |
| 429 | struct amdgpu_ring *ring; |
| 430 | u32 rb_cntl, ib_cntl; |
| 431 | u32 rb_bufsz; |
| 432 | u32 wb_offset; |
| 433 | int i, j, r; |
| 434 | |
| 435 | for (i = 0; i < SDMA_MAX_INSTANCE; i++) { |
| 436 | ring = &adev->sdma[i].ring; |
| 437 | wb_offset = (ring->rptr_offs * 4); |
| 438 | |
| 439 | mutex_lock(&adev->srbm_mutex); |
| 440 | for (j = 0; j < 16; j++) { |
| 441 | vi_srbm_select(adev, 0, 0, 0, j); |
| 442 | /* SDMA GFX */ |
| 443 | WREG32(mmSDMA0_GFX_VIRTUAL_ADDR + sdma_offsets[i], 0); |
| 444 | WREG32(mmSDMA0_GFX_APE1_CNTL + sdma_offsets[i], 0); |
| 445 | } |
| 446 | vi_srbm_select(adev, 0, 0, 0, 0); |
| 447 | mutex_unlock(&adev->srbm_mutex); |
| 448 | |
| 449 | WREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL + sdma_offsets[i], 0); |
| 450 | |
| 451 | /* Set ring buffer size in dwords */ |
| 452 | rb_bufsz = order_base_2(ring->ring_size / 4); |
| 453 | rb_cntl = RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i]); |
| 454 | rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SIZE, rb_bufsz); |
| 455 | #ifdef __BIG_ENDIAN |
| 456 | rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SWAP_ENABLE, 1); |
| 457 | rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, |
| 458 | RPTR_WRITEBACK_SWAP_ENABLE, 1); |
| 459 | #endif |
| 460 | WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl); |
| 461 | |
| 462 | /* Initialize the ring buffer's read and write pointers */ |
| 463 | WREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i], 0); |
| 464 | WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], 0); |
| 465 | |
| 466 | /* set the wb address whether it's enabled or not */ |
| 467 | WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i], |
| 468 | upper_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFF); |
| 469 | WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO + sdma_offsets[i], |
| 470 | lower_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC); |
| 471 | |
| 472 | rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RPTR_WRITEBACK_ENABLE, 1); |
| 473 | |
| 474 | WREG32(mmSDMA0_GFX_RB_BASE + sdma_offsets[i], ring->gpu_addr >> 8); |
| 475 | WREG32(mmSDMA0_GFX_RB_BASE_HI + sdma_offsets[i], ring->gpu_addr >> 40); |
| 476 | |
| 477 | ring->wptr = 0; |
| 478 | WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], ring->wptr << 2); |
| 479 | |
| 480 | /* enable DMA RB */ |
| 481 | rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 1); |
| 482 | WREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i], rb_cntl); |
| 483 | |
| 484 | ib_cntl = RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i]); |
| 485 | ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 1); |
| 486 | #ifdef __BIG_ENDIAN |
| 487 | ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_SWAP_ENABLE, 1); |
| 488 | #endif |
| 489 | /* enable DMA IBs */ |
| 490 | WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl); |
| 491 | |
| 492 | ring->ready = true; |
| 493 | |
| 494 | r = amdgpu_ring_test_ring(ring); |
| 495 | if (r) { |
| 496 | ring->ready = false; |
| 497 | return r; |
| 498 | } |
| 499 | |
| 500 | if (adev->mman.buffer_funcs_ring == ring) |
| 501 | amdgpu_ttm_set_active_vram_size(adev, adev->mc.real_vram_size); |
| 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * sdma_v2_4_rlc_resume - setup and start the async dma engines |
| 509 | * |
| 510 | * @adev: amdgpu_device pointer |
| 511 | * |
| 512 | * Set up the compute DMA queues and enable them (VI). |
| 513 | * Returns 0 for success, error for failure. |
| 514 | */ |
| 515 | static int sdma_v2_4_rlc_resume(struct amdgpu_device *adev) |
| 516 | { |
| 517 | /* XXX todo */ |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * sdma_v2_4_load_microcode - load the sDMA ME ucode |
| 523 | * |
| 524 | * @adev: amdgpu_device pointer |
| 525 | * |
| 526 | * Loads the sDMA0/1 ucode. |
| 527 | * Returns 0 for success, -EINVAL if the ucode is not available. |
| 528 | */ |
| 529 | static int sdma_v2_4_load_microcode(struct amdgpu_device *adev) |
| 530 | { |
| 531 | const struct sdma_firmware_header_v1_0 *hdr; |
| 532 | const __le32 *fw_data; |
| 533 | u32 fw_size; |
| 534 | int i, j; |
| 535 | bool smc_loads_fw = false; /* XXX fix me */ |
| 536 | |
| 537 | if (!adev->sdma[0].fw || !adev->sdma[1].fw) |
| 538 | return -EINVAL; |
| 539 | |
| 540 | /* halt the MEs */ |
| 541 | sdma_v2_4_enable(adev, false); |
| 542 | |
| 543 | if (smc_loads_fw) { |
| 544 | /* XXX query SMC for fw load complete */ |
| 545 | } else { |
| 546 | for (i = 0; i < SDMA_MAX_INSTANCE; i++) { |
| 547 | hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma[i].fw->data; |
| 548 | amdgpu_ucode_print_sdma_hdr(&hdr->header); |
| 549 | fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 550 | fw_data = (const __le32 *) |
| 551 | (adev->sdma[i].fw->data + |
| 552 | le32_to_cpu(hdr->header.ucode_array_offset_bytes)); |
| 553 | WREG32(mmSDMA0_UCODE_ADDR + sdma_offsets[i], 0); |
| 554 | for (j = 0; j < fw_size; j++) |
| 555 | WREG32(mmSDMA0_UCODE_DATA + sdma_offsets[i], le32_to_cpup(fw_data++)); |
| 556 | WREG32(mmSDMA0_UCODE_ADDR + sdma_offsets[i], adev->sdma[i].fw_version); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * sdma_v2_4_start - setup and start the async dma engines |
| 565 | * |
| 566 | * @adev: amdgpu_device pointer |
| 567 | * |
| 568 | * Set up the DMA engines and enable them (VI). |
| 569 | * Returns 0 for success, error for failure. |
| 570 | */ |
| 571 | static int sdma_v2_4_start(struct amdgpu_device *adev) |
| 572 | { |
| 573 | int r; |
| 574 | |
| 575 | if (!adev->firmware.smu_load) { |
| 576 | r = sdma_v2_4_load_microcode(adev); |
| 577 | if (r) |
| 578 | return r; |
| 579 | } else { |
| 580 | r = adev->smu.smumgr_funcs->check_fw_load_finish(adev, |
| 581 | AMDGPU_UCODE_ID_SDMA0); |
| 582 | if (r) |
| 583 | return -EINVAL; |
| 584 | r = adev->smu.smumgr_funcs->check_fw_load_finish(adev, |
| 585 | AMDGPU_UCODE_ID_SDMA1); |
| 586 | if (r) |
| 587 | return -EINVAL; |
| 588 | } |
| 589 | |
| 590 | /* unhalt the MEs */ |
| 591 | sdma_v2_4_enable(adev, true); |
| 592 | |
| 593 | /* start the gfx rings and rlc compute queues */ |
| 594 | r = sdma_v2_4_gfx_resume(adev); |
| 595 | if (r) |
| 596 | return r; |
| 597 | r = sdma_v2_4_rlc_resume(adev); |
| 598 | if (r) |
| 599 | return r; |
| 600 | |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * sdma_v2_4_ring_test_ring - simple async dma engine test |
| 606 | * |
| 607 | * @ring: amdgpu_ring structure holding ring information |
| 608 | * |
| 609 | * Test the DMA engine by writing using it to write an |
| 610 | * value to memory. (VI). |
| 611 | * Returns 0 for success, error for failure. |
| 612 | */ |
| 613 | static int sdma_v2_4_ring_test_ring(struct amdgpu_ring *ring) |
| 614 | { |
| 615 | struct amdgpu_device *adev = ring->adev; |
| 616 | unsigned i; |
| 617 | unsigned index; |
| 618 | int r; |
| 619 | u32 tmp; |
| 620 | u64 gpu_addr; |
| 621 | |
| 622 | r = amdgpu_wb_get(adev, &index); |
| 623 | if (r) { |
| 624 | dev_err(adev->dev, "(%d) failed to allocate wb slot\n", r); |
| 625 | return r; |
| 626 | } |
| 627 | |
| 628 | gpu_addr = adev->wb.gpu_addr + (index * 4); |
| 629 | tmp = 0xCAFEDEAD; |
| 630 | adev->wb.wb[index] = cpu_to_le32(tmp); |
| 631 | |
| 632 | r = amdgpu_ring_lock(ring, 5); |
| 633 | if (r) { |
| 634 | DRM_ERROR("amdgpu: dma failed to lock ring %d (%d).\n", ring->idx, r); |
| 635 | amdgpu_wb_free(adev, index); |
| 636 | return r; |
| 637 | } |
| 638 | |
| 639 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) | |
| 640 | SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR)); |
| 641 | amdgpu_ring_write(ring, lower_32_bits(gpu_addr)); |
| 642 | amdgpu_ring_write(ring, upper_32_bits(gpu_addr)); |
| 643 | amdgpu_ring_write(ring, SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(1)); |
| 644 | amdgpu_ring_write(ring, 0xDEADBEEF); |
| 645 | amdgpu_ring_unlock_commit(ring); |
| 646 | |
| 647 | for (i = 0; i < adev->usec_timeout; i++) { |
| 648 | tmp = le32_to_cpu(adev->wb.wb[index]); |
| 649 | if (tmp == 0xDEADBEEF) |
| 650 | break; |
| 651 | DRM_UDELAY(1); |
| 652 | } |
| 653 | |
| 654 | if (i < adev->usec_timeout) { |
| 655 | DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i); |
| 656 | } else { |
| 657 | DRM_ERROR("amdgpu: ring %d test failed (0x%08X)\n", |
| 658 | ring->idx, tmp); |
| 659 | r = -EINVAL; |
| 660 | } |
| 661 | amdgpu_wb_free(adev, index); |
| 662 | |
| 663 | return r; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * sdma_v2_4_ring_test_ib - test an IB on the DMA engine |
| 668 | * |
| 669 | * @ring: amdgpu_ring structure holding ring information |
| 670 | * |
| 671 | * Test a simple IB in the DMA ring (VI). |
| 672 | * Returns 0 on success, error on failure. |
| 673 | */ |
| 674 | static int sdma_v2_4_ring_test_ib(struct amdgpu_ring *ring) |
| 675 | { |
| 676 | struct amdgpu_device *adev = ring->adev; |
| 677 | struct amdgpu_ib ib; |
Chunming Zhou | 1763552 | 2015-08-03 11:43:19 +0800 | [diff] [blame] | 678 | struct fence *f = NULL; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 679 | unsigned i; |
| 680 | unsigned index; |
| 681 | int r; |
| 682 | u32 tmp = 0; |
| 683 | u64 gpu_addr; |
| 684 | |
| 685 | r = amdgpu_wb_get(adev, &index); |
| 686 | if (r) { |
| 687 | dev_err(adev->dev, "(%d) failed to allocate wb slot\n", r); |
| 688 | return r; |
| 689 | } |
| 690 | |
| 691 | gpu_addr = adev->wb.gpu_addr + (index * 4); |
| 692 | tmp = 0xCAFEDEAD; |
| 693 | adev->wb.wb[index] = cpu_to_le32(tmp); |
Christian König | b203dd9 | 2015-08-18 18:23:16 +0200 | [diff] [blame] | 694 | memset(&ib, 0, sizeof(ib)); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 695 | r = amdgpu_ib_get(ring, NULL, 256, &ib); |
| 696 | if (r) { |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 697 | DRM_ERROR("amdgpu: failed to get ib (%d).\n", r); |
Chunming Zhou | 0011fda | 2015-06-01 15:33:20 +0800 | [diff] [blame] | 698 | goto err0; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | ib.ptr[0] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) | |
| 702 | SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR); |
| 703 | ib.ptr[1] = lower_32_bits(gpu_addr); |
| 704 | ib.ptr[2] = upper_32_bits(gpu_addr); |
| 705 | ib.ptr[3] = SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(1); |
| 706 | ib.ptr[4] = 0xDEADBEEF; |
| 707 | ib.ptr[5] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP); |
| 708 | ib.ptr[6] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP); |
| 709 | ib.ptr[7] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP); |
| 710 | ib.length_dw = 8; |
| 711 | |
Chunming Zhou | 0011fda | 2015-06-01 15:33:20 +0800 | [diff] [blame] | 712 | r = amdgpu_sched_ib_submit_kernel_helper(adev, ring, &ib, 1, NULL, |
Chunming Zhou | 1763552 | 2015-08-03 11:43:19 +0800 | [diff] [blame] | 713 | AMDGPU_FENCE_OWNER_UNDEFINED, |
| 714 | &f); |
Chunming Zhou | 0011fda | 2015-06-01 15:33:20 +0800 | [diff] [blame] | 715 | if (r) |
| 716 | goto err1; |
| 717 | |
Chunming Zhou | 1763552 | 2015-08-03 11:43:19 +0800 | [diff] [blame] | 718 | r = fence_wait(f, false); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 719 | if (r) { |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 720 | DRM_ERROR("amdgpu: fence wait failed (%d).\n", r); |
Chunming Zhou | 0011fda | 2015-06-01 15:33:20 +0800 | [diff] [blame] | 721 | goto err1; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 722 | } |
| 723 | for (i = 0; i < adev->usec_timeout; i++) { |
| 724 | tmp = le32_to_cpu(adev->wb.wb[index]); |
| 725 | if (tmp == 0xDEADBEEF) |
| 726 | break; |
| 727 | DRM_UDELAY(1); |
| 728 | } |
| 729 | if (i < adev->usec_timeout) { |
| 730 | DRM_INFO("ib test on ring %d succeeded in %u usecs\n", |
Chunming Zhou | 0011fda | 2015-06-01 15:33:20 +0800 | [diff] [blame] | 731 | ring->idx, i); |
| 732 | goto err1; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 733 | } else { |
| 734 | DRM_ERROR("amdgpu: ib test failed (0x%08X)\n", tmp); |
| 735 | r = -EINVAL; |
| 736 | } |
Chunming Zhou | 0011fda | 2015-06-01 15:33:20 +0800 | [diff] [blame] | 737 | |
| 738 | err1: |
Chunming Zhou | 281b422 | 2015-08-12 12:58:31 +0800 | [diff] [blame] | 739 | fence_put(f); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 740 | amdgpu_ib_free(adev, &ib); |
Chunming Zhou | 0011fda | 2015-06-01 15:33:20 +0800 | [diff] [blame] | 741 | err0: |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 742 | amdgpu_wb_free(adev, index); |
| 743 | return r; |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * sdma_v2_4_vm_copy_pte - update PTEs by copying them from the GART |
| 748 | * |
| 749 | * @ib: indirect buffer to fill with commands |
| 750 | * @pe: addr of the page entry |
| 751 | * @src: src addr to copy from |
| 752 | * @count: number of page entries to update |
| 753 | * |
| 754 | * Update PTEs by copying them from the GART using sDMA (CIK). |
| 755 | */ |
| 756 | static void sdma_v2_4_vm_copy_pte(struct amdgpu_ib *ib, |
| 757 | uint64_t pe, uint64_t src, |
| 758 | unsigned count) |
| 759 | { |
| 760 | while (count) { |
| 761 | unsigned bytes = count * 8; |
| 762 | if (bytes > 0x1FFFF8) |
| 763 | bytes = 0x1FFFF8; |
| 764 | |
| 765 | ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) | |
| 766 | SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR); |
| 767 | ib->ptr[ib->length_dw++] = bytes; |
| 768 | ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */ |
| 769 | ib->ptr[ib->length_dw++] = lower_32_bits(src); |
| 770 | ib->ptr[ib->length_dw++] = upper_32_bits(src); |
| 771 | ib->ptr[ib->length_dw++] = lower_32_bits(pe); |
| 772 | ib->ptr[ib->length_dw++] = upper_32_bits(pe); |
| 773 | |
| 774 | pe += bytes; |
| 775 | src += bytes; |
| 776 | count -= bytes / 8; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * sdma_v2_4_vm_write_pte - update PTEs by writing them manually |
| 782 | * |
| 783 | * @ib: indirect buffer to fill with commands |
| 784 | * @pe: addr of the page entry |
| 785 | * @addr: dst addr to write into pe |
| 786 | * @count: number of page entries to update |
| 787 | * @incr: increase next addr by incr bytes |
| 788 | * @flags: access flags |
| 789 | * |
| 790 | * Update PTEs by writing them manually using sDMA (CIK). |
| 791 | */ |
| 792 | static void sdma_v2_4_vm_write_pte(struct amdgpu_ib *ib, |
| 793 | uint64_t pe, |
| 794 | uint64_t addr, unsigned count, |
| 795 | uint32_t incr, uint32_t flags) |
| 796 | { |
| 797 | uint64_t value; |
| 798 | unsigned ndw; |
| 799 | |
| 800 | while (count) { |
| 801 | ndw = count * 2; |
| 802 | if (ndw > 0xFFFFE) |
| 803 | ndw = 0xFFFFE; |
| 804 | |
| 805 | /* for non-physically contiguous pages (system) */ |
| 806 | ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) | |
| 807 | SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR); |
| 808 | ib->ptr[ib->length_dw++] = pe; |
| 809 | ib->ptr[ib->length_dw++] = upper_32_bits(pe); |
| 810 | ib->ptr[ib->length_dw++] = ndw; |
| 811 | for (; ndw > 0; ndw -= 2, --count, pe += 8) { |
| 812 | if (flags & AMDGPU_PTE_SYSTEM) { |
| 813 | value = amdgpu_vm_map_gart(ib->ring->adev, addr); |
| 814 | value &= 0xFFFFFFFFFFFFF000ULL; |
| 815 | } else if (flags & AMDGPU_PTE_VALID) { |
| 816 | value = addr; |
| 817 | } else { |
| 818 | value = 0; |
| 819 | } |
| 820 | addr += incr; |
| 821 | value |= flags; |
| 822 | ib->ptr[ib->length_dw++] = value; |
| 823 | ib->ptr[ib->length_dw++] = upper_32_bits(value); |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | /** |
| 829 | * sdma_v2_4_vm_set_pte_pde - update the page tables using sDMA |
| 830 | * |
| 831 | * @ib: indirect buffer to fill with commands |
| 832 | * @pe: addr of the page entry |
| 833 | * @addr: dst addr to write into pe |
| 834 | * @count: number of page entries to update |
| 835 | * @incr: increase next addr by incr bytes |
| 836 | * @flags: access flags |
| 837 | * |
| 838 | * Update the page tables using sDMA (CIK). |
| 839 | */ |
| 840 | static void sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib *ib, |
| 841 | uint64_t pe, |
| 842 | uint64_t addr, unsigned count, |
| 843 | uint32_t incr, uint32_t flags) |
| 844 | { |
| 845 | uint64_t value; |
| 846 | unsigned ndw; |
| 847 | |
| 848 | while (count) { |
| 849 | ndw = count; |
| 850 | if (ndw > 0x7FFFF) |
| 851 | ndw = 0x7FFFF; |
| 852 | |
| 853 | if (flags & AMDGPU_PTE_VALID) |
| 854 | value = addr; |
| 855 | else |
| 856 | value = 0; |
| 857 | |
| 858 | /* for physically contiguous pages (vram) */ |
| 859 | ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE); |
| 860 | ib->ptr[ib->length_dw++] = pe; /* dst addr */ |
| 861 | ib->ptr[ib->length_dw++] = upper_32_bits(pe); |
| 862 | ib->ptr[ib->length_dw++] = flags; /* mask */ |
| 863 | ib->ptr[ib->length_dw++] = 0; |
| 864 | ib->ptr[ib->length_dw++] = value; /* value */ |
| 865 | ib->ptr[ib->length_dw++] = upper_32_bits(value); |
| 866 | ib->ptr[ib->length_dw++] = incr; /* increment size */ |
| 867 | ib->ptr[ib->length_dw++] = 0; |
| 868 | ib->ptr[ib->length_dw++] = ndw; /* number of entries */ |
| 869 | |
| 870 | pe += ndw * 8; |
| 871 | addr += ndw * incr; |
| 872 | count -= ndw; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * sdma_v2_4_vm_pad_ib - pad the IB to the required number of dw |
| 878 | * |
| 879 | * @ib: indirect buffer to fill with padding |
| 880 | * |
| 881 | */ |
| 882 | static void sdma_v2_4_vm_pad_ib(struct amdgpu_ib *ib) |
| 883 | { |
| 884 | while (ib->length_dw & 0x7) |
| 885 | ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_NOP); |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * sdma_v2_4_ring_emit_vm_flush - cik vm flush using sDMA |
| 890 | * |
| 891 | * @ring: amdgpu_ring pointer |
| 892 | * @vm: amdgpu_vm pointer |
| 893 | * |
| 894 | * Update the page table base and flush the VM TLB |
| 895 | * using sDMA (VI). |
| 896 | */ |
| 897 | static void sdma_v2_4_ring_emit_vm_flush(struct amdgpu_ring *ring, |
| 898 | unsigned vm_id, uint64_t pd_addr) |
| 899 | { |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 900 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) | |
| 901 | SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf)); |
| 902 | if (vm_id < 8) { |
| 903 | amdgpu_ring_write(ring, (mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR + vm_id)); |
| 904 | } else { |
| 905 | amdgpu_ring_write(ring, (mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR + vm_id - 8)); |
| 906 | } |
| 907 | amdgpu_ring_write(ring, pd_addr >> 12); |
| 908 | |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 909 | /* flush TLB */ |
| 910 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) | |
| 911 | SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf)); |
| 912 | amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST); |
| 913 | amdgpu_ring_write(ring, 1 << vm_id); |
| 914 | |
| 915 | /* wait for flush */ |
| 916 | amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) | |
| 917 | SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) | |
| 918 | SDMA_PKT_POLL_REGMEM_HEADER_FUNC(0)); /* always */ |
| 919 | amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST << 2); |
| 920 | amdgpu_ring_write(ring, 0); |
| 921 | amdgpu_ring_write(ring, 0); /* reference */ |
| 922 | amdgpu_ring_write(ring, 0); /* mask */ |
| 923 | amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) | |
| 924 | SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(10)); /* retry count, poll interval */ |
| 925 | } |
| 926 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 927 | static int sdma_v2_4_early_init(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 928 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 929 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 930 | |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 931 | sdma_v2_4_set_ring_funcs(adev); |
| 932 | sdma_v2_4_set_buffer_funcs(adev); |
| 933 | sdma_v2_4_set_vm_pte_funcs(adev); |
| 934 | sdma_v2_4_set_irq_funcs(adev); |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 939 | static int sdma_v2_4_sw_init(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 940 | { |
| 941 | struct amdgpu_ring *ring; |
| 942 | int r; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 943 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 944 | |
| 945 | /* SDMA trap event */ |
| 946 | r = amdgpu_irq_add_id(adev, 224, &adev->sdma_trap_irq); |
| 947 | if (r) |
| 948 | return r; |
| 949 | |
| 950 | /* SDMA Privileged inst */ |
| 951 | r = amdgpu_irq_add_id(adev, 241, &adev->sdma_illegal_inst_irq); |
| 952 | if (r) |
| 953 | return r; |
| 954 | |
| 955 | /* SDMA Privileged inst */ |
| 956 | r = amdgpu_irq_add_id(adev, 247, &adev->sdma_illegal_inst_irq); |
| 957 | if (r) |
| 958 | return r; |
| 959 | |
| 960 | r = sdma_v2_4_init_microcode(adev); |
| 961 | if (r) { |
| 962 | DRM_ERROR("Failed to load sdma firmware!\n"); |
| 963 | return r; |
| 964 | } |
| 965 | |
| 966 | ring = &adev->sdma[0].ring; |
| 967 | ring->ring_obj = NULL; |
| 968 | ring->use_doorbell = false; |
| 969 | |
| 970 | ring = &adev->sdma[1].ring; |
| 971 | ring->ring_obj = NULL; |
| 972 | ring->use_doorbell = false; |
| 973 | |
| 974 | ring = &adev->sdma[0].ring; |
| 975 | sprintf(ring->name, "sdma0"); |
| 976 | r = amdgpu_ring_init(adev, ring, 256 * 1024, |
| 977 | SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP), 0xf, |
| 978 | &adev->sdma_trap_irq, AMDGPU_SDMA_IRQ_TRAP0, |
| 979 | AMDGPU_RING_TYPE_SDMA); |
| 980 | if (r) |
| 981 | return r; |
| 982 | |
| 983 | ring = &adev->sdma[1].ring; |
| 984 | sprintf(ring->name, "sdma1"); |
| 985 | r = amdgpu_ring_init(adev, ring, 256 * 1024, |
| 986 | SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP), 0xf, |
| 987 | &adev->sdma_trap_irq, AMDGPU_SDMA_IRQ_TRAP1, |
| 988 | AMDGPU_RING_TYPE_SDMA); |
| 989 | if (r) |
| 990 | return r; |
| 991 | |
| 992 | return r; |
| 993 | } |
| 994 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 995 | static int sdma_v2_4_sw_fini(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 996 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 997 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 998 | |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 999 | amdgpu_ring_fini(&adev->sdma[0].ring); |
| 1000 | amdgpu_ring_fini(&adev->sdma[1].ring); |
| 1001 | |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1005 | static int sdma_v2_4_hw_init(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1006 | { |
| 1007 | int r; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1008 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1009 | |
| 1010 | sdma_v2_4_init_golden_registers(adev); |
| 1011 | |
| 1012 | r = sdma_v2_4_start(adev); |
| 1013 | if (r) |
| 1014 | return r; |
| 1015 | |
| 1016 | return r; |
| 1017 | } |
| 1018 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1019 | static int sdma_v2_4_hw_fini(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1020 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1021 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1022 | |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1023 | sdma_v2_4_enable(adev, false); |
| 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1028 | static int sdma_v2_4_suspend(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1029 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1030 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1031 | |
| 1032 | return sdma_v2_4_hw_fini(adev); |
| 1033 | } |
| 1034 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1035 | static int sdma_v2_4_resume(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1036 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1037 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1038 | |
| 1039 | return sdma_v2_4_hw_init(adev); |
| 1040 | } |
| 1041 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1042 | static bool sdma_v2_4_is_idle(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1043 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1044 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1045 | u32 tmp = RREG32(mmSRBM_STATUS2); |
| 1046 | |
| 1047 | if (tmp & (SRBM_STATUS2__SDMA_BUSY_MASK | |
| 1048 | SRBM_STATUS2__SDMA1_BUSY_MASK)) |
| 1049 | return false; |
| 1050 | |
| 1051 | return true; |
| 1052 | } |
| 1053 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1054 | static int sdma_v2_4_wait_for_idle(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1055 | { |
| 1056 | unsigned i; |
| 1057 | u32 tmp; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1058 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1059 | |
| 1060 | for (i = 0; i < adev->usec_timeout; i++) { |
| 1061 | tmp = RREG32(mmSRBM_STATUS2) & (SRBM_STATUS2__SDMA_BUSY_MASK | |
| 1062 | SRBM_STATUS2__SDMA1_BUSY_MASK); |
| 1063 | |
| 1064 | if (!tmp) |
| 1065 | return 0; |
| 1066 | udelay(1); |
| 1067 | } |
| 1068 | return -ETIMEDOUT; |
| 1069 | } |
| 1070 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1071 | static void sdma_v2_4_print_status(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1072 | { |
| 1073 | int i, j; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1074 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1075 | |
| 1076 | dev_info(adev->dev, "VI SDMA registers\n"); |
| 1077 | dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n", |
| 1078 | RREG32(mmSRBM_STATUS2)); |
| 1079 | for (i = 0; i < SDMA_MAX_INSTANCE; i++) { |
| 1080 | dev_info(adev->dev, " SDMA%d_STATUS_REG=0x%08X\n", |
| 1081 | i, RREG32(mmSDMA0_STATUS_REG + sdma_offsets[i])); |
| 1082 | dev_info(adev->dev, " SDMA%d_F32_CNTL=0x%08X\n", |
| 1083 | i, RREG32(mmSDMA0_F32_CNTL + sdma_offsets[i])); |
| 1084 | dev_info(adev->dev, " SDMA%d_CNTL=0x%08X\n", |
| 1085 | i, RREG32(mmSDMA0_CNTL + sdma_offsets[i])); |
| 1086 | dev_info(adev->dev, " SDMA%d_SEM_WAIT_FAIL_TIMER_CNTL=0x%08X\n", |
| 1087 | i, RREG32(mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL + sdma_offsets[i])); |
| 1088 | dev_info(adev->dev, " SDMA%d_GFX_IB_CNTL=0x%08X\n", |
| 1089 | i, RREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i])); |
| 1090 | dev_info(adev->dev, " SDMA%d_GFX_RB_CNTL=0x%08X\n", |
| 1091 | i, RREG32(mmSDMA0_GFX_RB_CNTL + sdma_offsets[i])); |
| 1092 | dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR=0x%08X\n", |
| 1093 | i, RREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i])); |
| 1094 | dev_info(adev->dev, " SDMA%d_GFX_RB_WPTR=0x%08X\n", |
| 1095 | i, RREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i])); |
| 1096 | dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_HI=0x%08X\n", |
| 1097 | i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i])); |
| 1098 | dev_info(adev->dev, " SDMA%d_GFX_RB_RPTR_ADDR_LO=0x%08X\n", |
| 1099 | i, RREG32(mmSDMA0_GFX_RB_RPTR_ADDR_LO + sdma_offsets[i])); |
| 1100 | dev_info(adev->dev, " SDMA%d_GFX_RB_BASE=0x%08X\n", |
| 1101 | i, RREG32(mmSDMA0_GFX_RB_BASE + sdma_offsets[i])); |
| 1102 | dev_info(adev->dev, " SDMA%d_GFX_RB_BASE_HI=0x%08X\n", |
| 1103 | i, RREG32(mmSDMA0_GFX_RB_BASE_HI + sdma_offsets[i])); |
| 1104 | mutex_lock(&adev->srbm_mutex); |
| 1105 | for (j = 0; j < 16; j++) { |
| 1106 | vi_srbm_select(adev, 0, 0, 0, j); |
| 1107 | dev_info(adev->dev, " VM %d:\n", j); |
| 1108 | dev_info(adev->dev, " SDMA%d_GFX_VIRTUAL_ADDR=0x%08X\n", |
| 1109 | i, RREG32(mmSDMA0_GFX_VIRTUAL_ADDR + sdma_offsets[i])); |
| 1110 | dev_info(adev->dev, " SDMA%d_GFX_APE1_CNTL=0x%08X\n", |
| 1111 | i, RREG32(mmSDMA0_GFX_APE1_CNTL + sdma_offsets[i])); |
| 1112 | } |
| 1113 | vi_srbm_select(adev, 0, 0, 0, 0); |
| 1114 | mutex_unlock(&adev->srbm_mutex); |
| 1115 | } |
| 1116 | } |
| 1117 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1118 | static int sdma_v2_4_soft_reset(void *handle) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1119 | { |
| 1120 | u32 srbm_soft_reset = 0; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1121 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1122 | u32 tmp = RREG32(mmSRBM_STATUS2); |
| 1123 | |
| 1124 | if (tmp & SRBM_STATUS2__SDMA_BUSY_MASK) { |
| 1125 | /* sdma0 */ |
| 1126 | tmp = RREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET); |
| 1127 | tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 0); |
| 1128 | WREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET, tmp); |
| 1129 | srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA_MASK; |
| 1130 | } |
| 1131 | if (tmp & SRBM_STATUS2__SDMA1_BUSY_MASK) { |
| 1132 | /* sdma1 */ |
| 1133 | tmp = RREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET); |
| 1134 | tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 0); |
| 1135 | WREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET, tmp); |
| 1136 | srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA1_MASK; |
| 1137 | } |
| 1138 | |
| 1139 | if (srbm_soft_reset) { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1140 | sdma_v2_4_print_status((void *)adev); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1141 | |
| 1142 | tmp = RREG32(mmSRBM_SOFT_RESET); |
| 1143 | tmp |= srbm_soft_reset; |
| 1144 | dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); |
| 1145 | WREG32(mmSRBM_SOFT_RESET, tmp); |
| 1146 | tmp = RREG32(mmSRBM_SOFT_RESET); |
| 1147 | |
| 1148 | udelay(50); |
| 1149 | |
| 1150 | tmp &= ~srbm_soft_reset; |
| 1151 | WREG32(mmSRBM_SOFT_RESET, tmp); |
| 1152 | tmp = RREG32(mmSRBM_SOFT_RESET); |
| 1153 | |
| 1154 | /* Wait a little for things to settle down */ |
| 1155 | udelay(50); |
| 1156 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1157 | sdma_v2_4_print_status((void *)adev); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
| 1163 | static int sdma_v2_4_set_trap_irq_state(struct amdgpu_device *adev, |
| 1164 | struct amdgpu_irq_src *src, |
| 1165 | unsigned type, |
| 1166 | enum amdgpu_interrupt_state state) |
| 1167 | { |
| 1168 | u32 sdma_cntl; |
| 1169 | |
| 1170 | switch (type) { |
| 1171 | case AMDGPU_SDMA_IRQ_TRAP0: |
| 1172 | switch (state) { |
| 1173 | case AMDGPU_IRQ_STATE_DISABLE: |
| 1174 | sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET); |
| 1175 | sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 0); |
| 1176 | WREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET, sdma_cntl); |
| 1177 | break; |
| 1178 | case AMDGPU_IRQ_STATE_ENABLE: |
| 1179 | sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET); |
| 1180 | sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 1); |
| 1181 | WREG32(mmSDMA0_CNTL + SDMA0_REGISTER_OFFSET, sdma_cntl); |
| 1182 | break; |
| 1183 | default: |
| 1184 | break; |
| 1185 | } |
| 1186 | break; |
| 1187 | case AMDGPU_SDMA_IRQ_TRAP1: |
| 1188 | switch (state) { |
| 1189 | case AMDGPU_IRQ_STATE_DISABLE: |
| 1190 | sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET); |
| 1191 | sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 0); |
| 1192 | WREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET, sdma_cntl); |
| 1193 | break; |
| 1194 | case AMDGPU_IRQ_STATE_ENABLE: |
| 1195 | sdma_cntl = RREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET); |
| 1196 | sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE, 1); |
| 1197 | WREG32(mmSDMA0_CNTL + SDMA1_REGISTER_OFFSET, sdma_cntl); |
| 1198 | break; |
| 1199 | default: |
| 1200 | break; |
| 1201 | } |
| 1202 | break; |
| 1203 | default: |
| 1204 | break; |
| 1205 | } |
| 1206 | return 0; |
| 1207 | } |
| 1208 | |
| 1209 | static int sdma_v2_4_process_trap_irq(struct amdgpu_device *adev, |
| 1210 | struct amdgpu_irq_src *source, |
| 1211 | struct amdgpu_iv_entry *entry) |
| 1212 | { |
| 1213 | u8 instance_id, queue_id; |
| 1214 | |
| 1215 | instance_id = (entry->ring_id & 0x3) >> 0; |
| 1216 | queue_id = (entry->ring_id & 0xc) >> 2; |
| 1217 | DRM_DEBUG("IH: SDMA trap\n"); |
| 1218 | switch (instance_id) { |
| 1219 | case 0: |
| 1220 | switch (queue_id) { |
| 1221 | case 0: |
| 1222 | amdgpu_fence_process(&adev->sdma[0].ring); |
| 1223 | break; |
| 1224 | case 1: |
| 1225 | /* XXX compute */ |
| 1226 | break; |
| 1227 | case 2: |
| 1228 | /* XXX compute */ |
| 1229 | break; |
| 1230 | } |
| 1231 | break; |
| 1232 | case 1: |
| 1233 | switch (queue_id) { |
| 1234 | case 0: |
| 1235 | amdgpu_fence_process(&adev->sdma[1].ring); |
| 1236 | break; |
| 1237 | case 1: |
| 1238 | /* XXX compute */ |
| 1239 | break; |
| 1240 | case 2: |
| 1241 | /* XXX compute */ |
| 1242 | break; |
| 1243 | } |
| 1244 | break; |
| 1245 | } |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static int sdma_v2_4_process_illegal_inst_irq(struct amdgpu_device *adev, |
| 1250 | struct amdgpu_irq_src *source, |
| 1251 | struct amdgpu_iv_entry *entry) |
| 1252 | { |
| 1253 | DRM_ERROR("Illegal instruction in SDMA command stream\n"); |
| 1254 | schedule_work(&adev->reset_work); |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1258 | static int sdma_v2_4_set_clockgating_state(void *handle, |
| 1259 | enum amd_clockgating_state state) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1260 | { |
| 1261 | /* XXX handled via the smc on VI */ |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1262 | return 0; |
| 1263 | } |
| 1264 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1265 | static int sdma_v2_4_set_powergating_state(void *handle, |
| 1266 | enum amd_powergating_state state) |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1267 | { |
| 1268 | return 0; |
| 1269 | } |
| 1270 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1271 | const struct amd_ip_funcs sdma_v2_4_ip_funcs = { |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1272 | .early_init = sdma_v2_4_early_init, |
| 1273 | .late_init = NULL, |
| 1274 | .sw_init = sdma_v2_4_sw_init, |
| 1275 | .sw_fini = sdma_v2_4_sw_fini, |
| 1276 | .hw_init = sdma_v2_4_hw_init, |
| 1277 | .hw_fini = sdma_v2_4_hw_fini, |
| 1278 | .suspend = sdma_v2_4_suspend, |
| 1279 | .resume = sdma_v2_4_resume, |
| 1280 | .is_idle = sdma_v2_4_is_idle, |
| 1281 | .wait_for_idle = sdma_v2_4_wait_for_idle, |
| 1282 | .soft_reset = sdma_v2_4_soft_reset, |
| 1283 | .print_status = sdma_v2_4_print_status, |
| 1284 | .set_clockgating_state = sdma_v2_4_set_clockgating_state, |
| 1285 | .set_powergating_state = sdma_v2_4_set_powergating_state, |
| 1286 | }; |
| 1287 | |
| 1288 | /** |
| 1289 | * sdma_v2_4_ring_is_lockup - Check if the DMA engine is locked up |
| 1290 | * |
| 1291 | * @ring: amdgpu_ring structure holding ring information |
| 1292 | * |
| 1293 | * Check if the async DMA engine is locked up (VI). |
| 1294 | * Returns true if the engine appears to be locked up, false if not. |
| 1295 | */ |
| 1296 | static bool sdma_v2_4_ring_is_lockup(struct amdgpu_ring *ring) |
| 1297 | { |
| 1298 | |
| 1299 | if (sdma_v2_4_is_idle(ring->adev)) { |
| 1300 | amdgpu_ring_lockup_update(ring); |
| 1301 | return false; |
| 1302 | } |
| 1303 | return amdgpu_ring_test_lockup(ring); |
| 1304 | } |
| 1305 | |
| 1306 | static const struct amdgpu_ring_funcs sdma_v2_4_ring_funcs = { |
| 1307 | .get_rptr = sdma_v2_4_ring_get_rptr, |
| 1308 | .get_wptr = sdma_v2_4_ring_get_wptr, |
| 1309 | .set_wptr = sdma_v2_4_ring_set_wptr, |
| 1310 | .parse_cs = NULL, |
| 1311 | .emit_ib = sdma_v2_4_ring_emit_ib, |
| 1312 | .emit_fence = sdma_v2_4_ring_emit_fence, |
| 1313 | .emit_semaphore = sdma_v2_4_ring_emit_semaphore, |
| 1314 | .emit_vm_flush = sdma_v2_4_ring_emit_vm_flush, |
Christian König | d2edb07 | 2015-05-11 14:10:34 +0200 | [diff] [blame] | 1315 | .emit_hdp_flush = sdma_v2_4_ring_emit_hdp_flush, |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1316 | .test_ring = sdma_v2_4_ring_test_ring, |
| 1317 | .test_ib = sdma_v2_4_ring_test_ib, |
| 1318 | .is_lockup = sdma_v2_4_ring_is_lockup, |
| 1319 | }; |
| 1320 | |
| 1321 | static void sdma_v2_4_set_ring_funcs(struct amdgpu_device *adev) |
| 1322 | { |
| 1323 | adev->sdma[0].ring.funcs = &sdma_v2_4_ring_funcs; |
| 1324 | adev->sdma[1].ring.funcs = &sdma_v2_4_ring_funcs; |
| 1325 | } |
| 1326 | |
| 1327 | static const struct amdgpu_irq_src_funcs sdma_v2_4_trap_irq_funcs = { |
| 1328 | .set = sdma_v2_4_set_trap_irq_state, |
| 1329 | .process = sdma_v2_4_process_trap_irq, |
| 1330 | }; |
| 1331 | |
| 1332 | static const struct amdgpu_irq_src_funcs sdma_v2_4_illegal_inst_irq_funcs = { |
| 1333 | .process = sdma_v2_4_process_illegal_inst_irq, |
| 1334 | }; |
| 1335 | |
| 1336 | static void sdma_v2_4_set_irq_funcs(struct amdgpu_device *adev) |
| 1337 | { |
| 1338 | adev->sdma_trap_irq.num_types = AMDGPU_SDMA_IRQ_LAST; |
| 1339 | adev->sdma_trap_irq.funcs = &sdma_v2_4_trap_irq_funcs; |
| 1340 | adev->sdma_illegal_inst_irq.funcs = &sdma_v2_4_illegal_inst_irq_funcs; |
| 1341 | } |
| 1342 | |
| 1343 | /** |
| 1344 | * sdma_v2_4_emit_copy_buffer - copy buffer using the sDMA engine |
| 1345 | * |
| 1346 | * @ring: amdgpu_ring structure holding ring information |
| 1347 | * @src_offset: src GPU address |
| 1348 | * @dst_offset: dst GPU address |
| 1349 | * @byte_count: number of bytes to xfer |
| 1350 | * |
| 1351 | * Copy GPU buffers using the DMA engine (VI). |
| 1352 | * Used by the amdgpu ttm implementation to move pages if |
| 1353 | * registered as the asic copy callback. |
| 1354 | */ |
Chunming Zhou | c7ae72c | 2015-08-25 17:23:45 +0800 | [diff] [blame] | 1355 | static void sdma_v2_4_emit_copy_buffer(struct amdgpu_ib *ib, |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1356 | uint64_t src_offset, |
| 1357 | uint64_t dst_offset, |
| 1358 | uint32_t byte_count) |
| 1359 | { |
Chunming Zhou | c7ae72c | 2015-08-25 17:23:45 +0800 | [diff] [blame] | 1360 | ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) | |
| 1361 | SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR); |
| 1362 | ib->ptr[ib->length_dw++] = byte_count; |
| 1363 | ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */ |
| 1364 | ib->ptr[ib->length_dw++] = lower_32_bits(src_offset); |
| 1365 | ib->ptr[ib->length_dw++] = upper_32_bits(src_offset); |
| 1366 | ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset); |
| 1367 | ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset); |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /** |
| 1371 | * sdma_v2_4_emit_fill_buffer - fill buffer using the sDMA engine |
| 1372 | * |
| 1373 | * @ring: amdgpu_ring structure holding ring information |
| 1374 | * @src_data: value to write to buffer |
| 1375 | * @dst_offset: dst GPU address |
| 1376 | * @byte_count: number of bytes to xfer |
| 1377 | * |
| 1378 | * Fill GPU buffers using the DMA engine (VI). |
| 1379 | */ |
Chunming Zhou | 6e7a384 | 2015-08-27 13:46:09 +0800 | [diff] [blame] | 1380 | static void sdma_v2_4_emit_fill_buffer(struct amdgpu_ib *ib, |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1381 | uint32_t src_data, |
| 1382 | uint64_t dst_offset, |
| 1383 | uint32_t byte_count) |
| 1384 | { |
Chunming Zhou | 6e7a384 | 2015-08-27 13:46:09 +0800 | [diff] [blame] | 1385 | ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL); |
| 1386 | ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset); |
| 1387 | ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset); |
| 1388 | ib->ptr[ib->length_dw++] = src_data; |
| 1389 | ib->ptr[ib->length_dw++] = byte_count; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static const struct amdgpu_buffer_funcs sdma_v2_4_buffer_funcs = { |
| 1393 | .copy_max_bytes = 0x1fffff, |
| 1394 | .copy_num_dw = 7, |
| 1395 | .emit_copy_buffer = sdma_v2_4_emit_copy_buffer, |
| 1396 | |
| 1397 | .fill_max_bytes = 0x1fffff, |
| 1398 | .fill_num_dw = 7, |
| 1399 | .emit_fill_buffer = sdma_v2_4_emit_fill_buffer, |
| 1400 | }; |
| 1401 | |
| 1402 | static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev) |
| 1403 | { |
| 1404 | if (adev->mman.buffer_funcs == NULL) { |
| 1405 | adev->mman.buffer_funcs = &sdma_v2_4_buffer_funcs; |
| 1406 | adev->mman.buffer_funcs_ring = &adev->sdma[0].ring; |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = { |
| 1411 | .copy_pte = sdma_v2_4_vm_copy_pte, |
| 1412 | .write_pte = sdma_v2_4_vm_write_pte, |
| 1413 | .set_pte_pde = sdma_v2_4_vm_set_pte_pde, |
| 1414 | .pad_ib = sdma_v2_4_vm_pad_ib, |
| 1415 | }; |
| 1416 | |
| 1417 | static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev) |
| 1418 | { |
| 1419 | if (adev->vm_manager.vm_pte_funcs == NULL) { |
| 1420 | adev->vm_manager.vm_pte_funcs = &sdma_v2_4_vm_pte_funcs; |
| 1421 | adev->vm_manager.vm_pte_funcs_ring = &adev->sdma[0].ring; |
Chunming Zhou | 4274f5d | 2015-07-21 16:04:39 +0800 | [diff] [blame] | 1422 | adev->vm_manager.vm_pte_funcs_ring->is_pte_ring = true; |
Alex Deucher | aaa36a976 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1423 | } |
| 1424 | } |