| .. | .. |
|---|
| 20 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 21 | 21 | * |
|---|
| 22 | 22 | */ |
|---|
| 23 | | -#include <drm/drmP.h> |
|---|
| 23 | + |
|---|
| 24 | +#include <linux/pci.h> |
|---|
| 25 | + |
|---|
| 24 | 26 | #include "amdgpu.h" |
|---|
| 25 | 27 | #include "amdgpu_ih.h" |
|---|
| 26 | 28 | #include "vid.h" |
|---|
| .. | .. |
|---|
| 103 | 105 | */ |
|---|
| 104 | 106 | static int iceland_ih_irq_init(struct amdgpu_device *adev) |
|---|
| 105 | 107 | { |
|---|
| 108 | + struct amdgpu_ih_ring *ih = &adev->irq.ih; |
|---|
| 106 | 109 | int rb_bufsz; |
|---|
| 107 | 110 | u32 interrupt_cntl, ih_cntl, ih_rb_cntl; |
|---|
| 108 | | - u64 wptr_off; |
|---|
| 109 | 111 | |
|---|
| 110 | 112 | /* disable irqs */ |
|---|
| 111 | 113 | iceland_ih_disable_interrupts(adev); |
|---|
| .. | .. |
|---|
| 133 | 135 | ih_rb_cntl = REG_SET_FIELD(ih_rb_cntl, IH_RB_CNTL, WPTR_WRITEBACK_ENABLE, 1); |
|---|
| 134 | 136 | |
|---|
| 135 | 137 | /* set the writeback address whether it's enabled or not */ |
|---|
| 136 | | - wptr_off = adev->wb.gpu_addr + (adev->irq.ih.wptr_offs * 4); |
|---|
| 137 | | - WREG32(mmIH_RB_WPTR_ADDR_LO, lower_32_bits(wptr_off)); |
|---|
| 138 | | - WREG32(mmIH_RB_WPTR_ADDR_HI, upper_32_bits(wptr_off) & 0xFF); |
|---|
| 138 | + WREG32(mmIH_RB_WPTR_ADDR_LO, lower_32_bits(ih->wptr_addr)); |
|---|
| 139 | + WREG32(mmIH_RB_WPTR_ADDR_HI, upper_32_bits(ih->wptr_addr) & 0xFF); |
|---|
| 139 | 140 | |
|---|
| 140 | 141 | WREG32(mmIH_RB_CNTL, ih_rb_cntl); |
|---|
| 141 | 142 | |
|---|
| .. | .. |
|---|
| 185 | 186 | * Used by cz_irq_process(VI). |
|---|
| 186 | 187 | * Returns the value of the wptr. |
|---|
| 187 | 188 | */ |
|---|
| 188 | | -static u32 iceland_ih_get_wptr(struct amdgpu_device *adev) |
|---|
| 189 | +static u32 iceland_ih_get_wptr(struct amdgpu_device *adev, |
|---|
| 190 | + struct amdgpu_ih_ring *ih) |
|---|
| 189 | 191 | { |
|---|
| 190 | 192 | u32 wptr, tmp; |
|---|
| 191 | 193 | |
|---|
| 192 | | - wptr = le32_to_cpu(adev->wb.wb[adev->irq.ih.wptr_offs]); |
|---|
| 194 | + wptr = le32_to_cpu(*ih->wptr_cpu); |
|---|
| 193 | 195 | |
|---|
| 194 | | - if (REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW)) { |
|---|
| 195 | | - wptr = REG_SET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW, 0); |
|---|
| 196 | | - /* When a ring buffer overflow happen start parsing interrupt |
|---|
| 197 | | - * from the last not overwritten vector (wptr + 16). Hopefully |
|---|
| 198 | | - * this should allow us to catchup. |
|---|
| 199 | | - */ |
|---|
| 200 | | - dev_warn(adev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n", |
|---|
| 201 | | - wptr, adev->irq.ih.rptr, (wptr + 16) & adev->irq.ih.ptr_mask); |
|---|
| 202 | | - adev->irq.ih.rptr = (wptr + 16) & adev->irq.ih.ptr_mask; |
|---|
| 203 | | - tmp = RREG32(mmIH_RB_CNTL); |
|---|
| 204 | | - tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1); |
|---|
| 205 | | - WREG32(mmIH_RB_CNTL, tmp); |
|---|
| 206 | | - } |
|---|
| 207 | | - return (wptr & adev->irq.ih.ptr_mask); |
|---|
| 208 | | -} |
|---|
| 196 | + if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW)) |
|---|
| 197 | + goto out; |
|---|
| 209 | 198 | |
|---|
| 210 | | -/** |
|---|
| 211 | | - * iceland_ih_prescreen_iv - prescreen an interrupt vector |
|---|
| 212 | | - * |
|---|
| 213 | | - * @adev: amdgpu_device pointer |
|---|
| 214 | | - * |
|---|
| 215 | | - * Returns true if the interrupt vector should be further processed. |
|---|
| 216 | | - */ |
|---|
| 217 | | -static bool iceland_ih_prescreen_iv(struct amdgpu_device *adev) |
|---|
| 218 | | -{ |
|---|
| 219 | | - u32 ring_index = adev->irq.ih.rptr >> 2; |
|---|
| 220 | | - u16 pasid; |
|---|
| 199 | + /* Double check that the overflow wasn't already cleared. */ |
|---|
| 200 | + wptr = RREG32(mmIH_RB_WPTR); |
|---|
| 221 | 201 | |
|---|
| 222 | | - switch (le32_to_cpu(adev->irq.ih.ring[ring_index]) & 0xff) { |
|---|
| 223 | | - case 146: |
|---|
| 224 | | - case 147: |
|---|
| 225 | | - pasid = le32_to_cpu(adev->irq.ih.ring[ring_index + 2]) >> 16; |
|---|
| 226 | | - if (!pasid || amdgpu_vm_pasid_fault_credit(adev, pasid)) |
|---|
| 227 | | - return true; |
|---|
| 228 | | - break; |
|---|
| 229 | | - default: |
|---|
| 230 | | - /* Not a VM fault */ |
|---|
| 231 | | - return true; |
|---|
| 232 | | - } |
|---|
| 202 | + if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW)) |
|---|
| 203 | + goto out; |
|---|
| 233 | 204 | |
|---|
| 234 | | - adev->irq.ih.rptr += 16; |
|---|
| 235 | | - return false; |
|---|
| 205 | + wptr = REG_SET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW, 0); |
|---|
| 206 | + /* When a ring buffer overflow happen start parsing interrupt |
|---|
| 207 | + * from the last not overwritten vector (wptr + 16). Hopefully |
|---|
| 208 | + * this should allow us to catchup. |
|---|
| 209 | + */ |
|---|
| 210 | + dev_warn(adev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n", |
|---|
| 211 | + wptr, ih->rptr, (wptr + 16) & ih->ptr_mask); |
|---|
| 212 | + ih->rptr = (wptr + 16) & ih->ptr_mask; |
|---|
| 213 | + tmp = RREG32(mmIH_RB_CNTL); |
|---|
| 214 | + tmp = REG_SET_FIELD(tmp, IH_RB_CNTL, WPTR_OVERFLOW_CLEAR, 1); |
|---|
| 215 | + WREG32(mmIH_RB_CNTL, tmp); |
|---|
| 216 | + |
|---|
| 217 | + |
|---|
| 218 | +out: |
|---|
| 219 | + return (wptr & ih->ptr_mask); |
|---|
| 236 | 220 | } |
|---|
| 237 | 221 | |
|---|
| 238 | 222 | /** |
|---|
| .. | .. |
|---|
| 244 | 228 | * position and also advance the position. |
|---|
| 245 | 229 | */ |
|---|
| 246 | 230 | static void iceland_ih_decode_iv(struct amdgpu_device *adev, |
|---|
| 231 | + struct amdgpu_ih_ring *ih, |
|---|
| 247 | 232 | struct amdgpu_iv_entry *entry) |
|---|
| 248 | 233 | { |
|---|
| 249 | 234 | /* wptr/rptr are in bytes! */ |
|---|
| 250 | | - u32 ring_index = adev->irq.ih.rptr >> 2; |
|---|
| 235 | + u32 ring_index = ih->rptr >> 2; |
|---|
| 251 | 236 | uint32_t dw[4]; |
|---|
| 252 | 237 | |
|---|
| 253 | | - dw[0] = le32_to_cpu(adev->irq.ih.ring[ring_index + 0]); |
|---|
| 254 | | - dw[1] = le32_to_cpu(adev->irq.ih.ring[ring_index + 1]); |
|---|
| 255 | | - dw[2] = le32_to_cpu(adev->irq.ih.ring[ring_index + 2]); |
|---|
| 256 | | - dw[3] = le32_to_cpu(adev->irq.ih.ring[ring_index + 3]); |
|---|
| 238 | + dw[0] = le32_to_cpu(ih->ring[ring_index + 0]); |
|---|
| 239 | + dw[1] = le32_to_cpu(ih->ring[ring_index + 1]); |
|---|
| 240 | + dw[2] = le32_to_cpu(ih->ring[ring_index + 2]); |
|---|
| 241 | + dw[3] = le32_to_cpu(ih->ring[ring_index + 3]); |
|---|
| 257 | 242 | |
|---|
| 258 | | - entry->client_id = AMDGPU_IH_CLIENTID_LEGACY; |
|---|
| 243 | + entry->client_id = AMDGPU_IRQ_CLIENTID_LEGACY; |
|---|
| 259 | 244 | entry->src_id = dw[0] & 0xff; |
|---|
| 260 | 245 | entry->src_data[0] = dw[1] & 0xfffffff; |
|---|
| 261 | 246 | entry->ring_id = dw[2] & 0xff; |
|---|
| .. | .. |
|---|
| 263 | 248 | entry->pasid = (dw[2] >> 16) & 0xffff; |
|---|
| 264 | 249 | |
|---|
| 265 | 250 | /* wptr/rptr are in bytes! */ |
|---|
| 266 | | - adev->irq.ih.rptr += 16; |
|---|
| 251 | + ih->rptr += 16; |
|---|
| 267 | 252 | } |
|---|
| 268 | 253 | |
|---|
| 269 | 254 | /** |
|---|
| .. | .. |
|---|
| 273 | 258 | * |
|---|
| 274 | 259 | * Set the IH ring buffer rptr. |
|---|
| 275 | 260 | */ |
|---|
| 276 | | -static void iceland_ih_set_rptr(struct amdgpu_device *adev) |
|---|
| 261 | +static void iceland_ih_set_rptr(struct amdgpu_device *adev, |
|---|
| 262 | + struct amdgpu_ih_ring *ih) |
|---|
| 277 | 263 | { |
|---|
| 278 | | - WREG32(mmIH_RB_RPTR, adev->irq.ih.rptr); |
|---|
| 264 | + WREG32(mmIH_RB_RPTR, ih->rptr); |
|---|
| 279 | 265 | } |
|---|
| 280 | 266 | |
|---|
| 281 | 267 | static int iceland_ih_early_init(void *handle) |
|---|
| .. | .. |
|---|
| 297 | 283 | int r; |
|---|
| 298 | 284 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
|---|
| 299 | 285 | |
|---|
| 300 | | - r = amdgpu_ih_ring_init(adev, 64 * 1024, false); |
|---|
| 286 | + r = amdgpu_ih_ring_init(adev, &adev->irq.ih, 64 * 1024, false); |
|---|
| 301 | 287 | if (r) |
|---|
| 302 | 288 | return r; |
|---|
| 303 | 289 | |
|---|
| .. | .. |
|---|
| 311 | 297 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
|---|
| 312 | 298 | |
|---|
| 313 | 299 | amdgpu_irq_fini(adev); |
|---|
| 314 | | - amdgpu_ih_ring_fini(adev); |
|---|
| 300 | + amdgpu_ih_ring_fini(adev, &adev->irq.ih); |
|---|
| 315 | 301 | amdgpu_irq_remove_domain(adev); |
|---|
| 316 | 302 | |
|---|
| 317 | 303 | return 0; |
|---|
| .. | .. |
|---|
| 440 | 426 | |
|---|
| 441 | 427 | static const struct amdgpu_ih_funcs iceland_ih_funcs = { |
|---|
| 442 | 428 | .get_wptr = iceland_ih_get_wptr, |
|---|
| 443 | | - .prescreen_iv = iceland_ih_prescreen_iv, |
|---|
| 444 | 429 | .decode_iv = iceland_ih_decode_iv, |
|---|
| 445 | 430 | .set_rptr = iceland_ih_set_rptr |
|---|
| 446 | 431 | }; |
|---|
| 447 | 432 | |
|---|
| 448 | 433 | static void iceland_ih_set_interrupt_funcs(struct amdgpu_device *adev) |
|---|
| 449 | 434 | { |
|---|
| 450 | | - if (adev->irq.ih_funcs == NULL) |
|---|
| 451 | | - adev->irq.ih_funcs = &iceland_ih_funcs; |
|---|
| 435 | + adev->irq.ih_funcs = &iceland_ih_funcs; |
|---|
| 452 | 436 | } |
|---|
| 453 | 437 | |
|---|
| 454 | 438 | const struct amdgpu_ip_block_version iceland_ih_ip_block = |
|---|