2015-04-21 05:31:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Advanced Micro Devices, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* Authors: Christian König <christian.koenig@amd.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include "amdgpu.h"
|
|
|
|
#include "amdgpu_vce.h"
|
|
|
|
#include "vid.h"
|
|
|
|
#include "vce/vce_3_0_d.h"
|
|
|
|
#include "vce/vce_3_0_sh_mask.h"
|
2015-09-04 07:03:11 +08:00
|
|
|
#include "oss/oss_3_0_d.h"
|
|
|
|
#include "oss/oss_3_0_sh_mask.h"
|
2015-05-07 03:20:41 +08:00
|
|
|
#include "gca/gfx_8_0_d.h"
|
2015-07-11 02:16:24 +08:00
|
|
|
#include "smu/smu_7_1_2_d.h"
|
|
|
|
#include "smu/smu_7_1_2_sh_mask.h"
|
2016-07-18 17:38:50 +08:00
|
|
|
#include "gca/gfx_8_0_d.h"
|
|
|
|
#include "gca/gfx_8_0_sh_mask.h"
|
|
|
|
|
2015-05-07 03:20:41 +08:00
|
|
|
|
|
|
|
#define GRBM_GFX_INDEX__VCE_INSTANCE__SHIFT 0x04
|
|
|
|
#define GRBM_GFX_INDEX__VCE_INSTANCE_MASK 0x10
|
2017-01-10 20:03:59 +08:00
|
|
|
#define GRBM_GFX_INDEX__VCE_ALL_PIPE 0x07
|
|
|
|
|
2016-05-03 21:54:54 +08:00
|
|
|
#define mmVCE_LMI_VCPU_CACHE_40BIT_BAR0 0x8616
|
|
|
|
#define mmVCE_LMI_VCPU_CACHE_40BIT_BAR1 0x8617
|
|
|
|
#define mmVCE_LMI_VCPU_CACHE_40BIT_BAR2 0x8618
|
2017-01-10 20:03:59 +08:00
|
|
|
#define mmGRBM_GFX_INDEX_DEFAULT 0xE0000000
|
|
|
|
|
2016-07-15 16:57:28 +08:00
|
|
|
#define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2015-05-07 02:31:27 +08:00
|
|
|
#define VCE_V3_0_FW_SIZE (384 * 1024)
|
|
|
|
#define VCE_V3_0_STACK_SIZE (64 * 1024)
|
|
|
|
#define VCE_V3_0_DATA_SIZE ((16 * 1024 * AMDGPU_MAX_VCE_HANDLES) + (52 * 1024))
|
|
|
|
|
2016-10-25 21:37:37 +08:00
|
|
|
#define FW_52_8_3 ((52 << 24) | (8 << 16) | (3 << 8))
|
|
|
|
|
2017-01-10 20:03:59 +08:00
|
|
|
#define GET_VCE_INSTANCE(i) ((i) << GRBM_GFX_INDEX__VCE_INSTANCE__SHIFT \
|
|
|
|
| GRBM_GFX_INDEX__VCE_ALL_PIPE)
|
|
|
|
|
2015-05-07 03:20:41 +08:00
|
|
|
static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx);
|
2015-04-21 05:31:14 +08:00
|
|
|
static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev);
|
|
|
|
static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev);
|
2016-07-15 16:57:28 +08:00
|
|
|
static int vce_v3_0_wait_for_idle(void *handle);
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* vce_v3_0_ring_get_rptr - get read pointer
|
|
|
|
*
|
|
|
|
* @ring: amdgpu_ring pointer
|
|
|
|
*
|
|
|
|
* Returns the current hardware read pointer
|
|
|
|
*/
|
2016-03-12 09:32:30 +08:00
|
|
|
static uint64_t vce_v3_0_ring_get_rptr(struct amdgpu_ring *ring)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = ring->adev;
|
|
|
|
|
|
|
|
if (ring == &adev->vce.ring[0])
|
|
|
|
return RREG32(mmVCE_RB_RPTR);
|
2016-08-25 05:15:33 +08:00
|
|
|
else if (ring == &adev->vce.ring[1])
|
2015-04-21 05:31:14 +08:00
|
|
|
return RREG32(mmVCE_RB_RPTR2);
|
2016-08-25 05:15:33 +08:00
|
|
|
else
|
|
|
|
return RREG32(mmVCE_RB_RPTR3);
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vce_v3_0_ring_get_wptr - get write pointer
|
|
|
|
*
|
|
|
|
* @ring: amdgpu_ring pointer
|
|
|
|
*
|
|
|
|
* Returns the current hardware write pointer
|
|
|
|
*/
|
2016-03-12 09:32:30 +08:00
|
|
|
static uint64_t vce_v3_0_ring_get_wptr(struct amdgpu_ring *ring)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = ring->adev;
|
|
|
|
|
|
|
|
if (ring == &adev->vce.ring[0])
|
|
|
|
return RREG32(mmVCE_RB_WPTR);
|
2016-08-25 05:15:33 +08:00
|
|
|
else if (ring == &adev->vce.ring[1])
|
2015-04-21 05:31:14 +08:00
|
|
|
return RREG32(mmVCE_RB_WPTR2);
|
2016-08-25 05:15:33 +08:00
|
|
|
else
|
|
|
|
return RREG32(mmVCE_RB_WPTR3);
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vce_v3_0_ring_set_wptr - set write pointer
|
|
|
|
*
|
|
|
|
* @ring: amdgpu_ring pointer
|
|
|
|
*
|
|
|
|
* Commits the write pointer to the hardware
|
|
|
|
*/
|
|
|
|
static void vce_v3_0_ring_set_wptr(struct amdgpu_ring *ring)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = ring->adev;
|
|
|
|
|
|
|
|
if (ring == &adev->vce.ring[0])
|
2016-03-12 09:32:30 +08:00
|
|
|
WREG32(mmVCE_RB_WPTR, lower_32_bits(ring->wptr));
|
2016-08-25 05:15:33 +08:00
|
|
|
else if (ring == &adev->vce.ring[1])
|
2016-03-12 09:32:30 +08:00
|
|
|
WREG32(mmVCE_RB_WPTR2, lower_32_bits(ring->wptr));
|
2016-08-25 05:15:33 +08:00
|
|
|
else
|
2016-03-12 09:32:30 +08:00
|
|
|
WREG32(mmVCE_RB_WPTR3, lower_32_bits(ring->wptr));
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
2015-11-24 05:57:53 +08:00
|
|
|
static void vce_v3_0_override_vce_clock_gating(struct amdgpu_device *adev, bool override)
|
|
|
|
{
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_RB_ARB_CTRL, VCE_CGTT_OVERRIDE, override ? 1 : 0);
|
2015-11-24 05:57:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vce_v3_0_set_vce_sw_clock_gating(struct amdgpu_device *adev,
|
|
|
|
bool gated)
|
|
|
|
{
|
2016-08-11 21:44:53 +08:00
|
|
|
u32 data;
|
2016-08-03 22:14:44 +08:00
|
|
|
|
2015-11-24 05:57:53 +08:00
|
|
|
/* Set Override to disable Clock Gating */
|
|
|
|
vce_v3_0_override_vce_clock_gating(adev, true);
|
|
|
|
|
2016-08-03 22:15:24 +08:00
|
|
|
/* This function enables MGCG which is controlled by firmware.
|
|
|
|
With the clocks in the gated state the core is still
|
|
|
|
accessible but the firmware will throttle the clocks on the
|
|
|
|
fly as necessary.
|
|
|
|
*/
|
2016-11-17 19:59:50 +08:00
|
|
|
if (!gated) {
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_CLOCK_GATING_B);
|
2015-11-24 05:57:53 +08:00
|
|
|
data |= 0x1ff;
|
|
|
|
data &= ~0xef0000;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_CLOCK_GATING_B, data);
|
2015-11-24 05:57:53 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_CLOCK_GATING);
|
2015-11-24 05:57:53 +08:00
|
|
|
data |= 0x3ff000;
|
|
|
|
data &= ~0xffc00000;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_CLOCK_GATING, data);
|
2015-11-24 05:57:53 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_CLOCK_GATING_2);
|
2015-11-24 05:57:53 +08:00
|
|
|
data |= 0x2;
|
2016-08-03 22:15:24 +08:00
|
|
|
data &= ~0x00010000;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_CLOCK_GATING_2, data);
|
2015-11-24 05:57:53 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
|
2015-11-24 05:57:53 +08:00
|
|
|
data |= 0x37f;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_REG_CLOCK_GATING, data);
|
2015-11-24 05:57:53 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);
|
2015-11-24 05:57:53 +08:00
|
|
|
data |= VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK |
|
2016-08-03 22:14:44 +08:00
|
|
|
VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK |
|
|
|
|
VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK |
|
|
|
|
0x8;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);
|
2015-11-24 05:57:53 +08:00
|
|
|
} else {
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_CLOCK_GATING_B);
|
2015-11-24 05:57:53 +08:00
|
|
|
data &= ~0x80010;
|
|
|
|
data |= 0xe70008;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_CLOCK_GATING_B, data);
|
2016-08-03 22:15:24 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_CLOCK_GATING);
|
2015-11-24 05:57:53 +08:00
|
|
|
data |= 0xffc00000;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_CLOCK_GATING, data);
|
2016-08-03 22:15:24 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_CLOCK_GATING_2);
|
2015-11-24 05:57:53 +08:00
|
|
|
data |= 0x10000;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_CLOCK_GATING_2, data);
|
2016-08-03 22:15:24 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);
|
2017-01-10 20:00:40 +08:00
|
|
|
data &= ~0x3ff;
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_REG_CLOCK_GATING, data);
|
2016-08-03 22:15:24 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);
|
2015-11-24 05:57:53 +08:00
|
|
|
data &= ~(VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK |
|
2016-08-03 22:14:44 +08:00
|
|
|
VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK |
|
|
|
|
VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK |
|
|
|
|
0x8);
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);
|
2015-11-24 05:57:53 +08:00
|
|
|
}
|
|
|
|
vce_v3_0_override_vce_clock_gating(adev, false);
|
|
|
|
}
|
|
|
|
|
2016-07-15 16:57:28 +08:00
|
|
|
static int vce_v3_0_firmware_loaded(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; ++i) {
|
|
|
|
for (j = 0; j < 100; ++j) {
|
2016-07-19 14:58:02 +08:00
|
|
|
uint32_t status = RREG32(mmVCE_STATUS);
|
|
|
|
|
2016-07-15 16:57:28 +08:00
|
|
|
if (status & VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK)
|
|
|
|
return 0;
|
|
|
|
mdelay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 1);
|
2016-07-15 16:57:28 +08:00
|
|
|
mdelay(10);
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 0);
|
2016-07-15 16:57:28 +08:00
|
|
|
mdelay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2015-04-21 05:31:14 +08:00
|
|
|
/**
|
|
|
|
* vce_v3_0_start - start VCE block
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Setup and start the VCE block
|
|
|
|
*/
|
|
|
|
static int vce_v3_0_start(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
struct amdgpu_ring *ring;
|
2016-07-15 16:57:28 +08:00
|
|
|
int idx, r;
|
|
|
|
|
|
|
|
ring = &adev->vce.ring[0];
|
2016-03-12 09:32:30 +08:00
|
|
|
WREG32(mmVCE_RB_RPTR, lower_32_bits(ring->wptr));
|
|
|
|
WREG32(mmVCE_RB_WPTR, lower_32_bits(ring->wptr));
|
2016-07-15 16:57:28 +08:00
|
|
|
WREG32(mmVCE_RB_BASE_LO, ring->gpu_addr);
|
|
|
|
WREG32(mmVCE_RB_BASE_HI, upper_32_bits(ring->gpu_addr));
|
|
|
|
WREG32(mmVCE_RB_SIZE, ring->ring_size / 4);
|
|
|
|
|
|
|
|
ring = &adev->vce.ring[1];
|
2016-03-12 09:32:30 +08:00
|
|
|
WREG32(mmVCE_RB_RPTR2, lower_32_bits(ring->wptr));
|
|
|
|
WREG32(mmVCE_RB_WPTR2, lower_32_bits(ring->wptr));
|
2016-07-15 16:57:28 +08:00
|
|
|
WREG32(mmVCE_RB_BASE_LO2, ring->gpu_addr);
|
|
|
|
WREG32(mmVCE_RB_BASE_HI2, upper_32_bits(ring->gpu_addr));
|
|
|
|
WREG32(mmVCE_RB_SIZE2, ring->ring_size / 4);
|
2015-05-07 03:20:41 +08:00
|
|
|
|
2016-08-25 05:15:33 +08:00
|
|
|
ring = &adev->vce.ring[2];
|
2016-03-12 09:32:30 +08:00
|
|
|
WREG32(mmVCE_RB_RPTR3, lower_32_bits(ring->wptr));
|
|
|
|
WREG32(mmVCE_RB_WPTR3, lower_32_bits(ring->wptr));
|
2016-08-25 05:15:33 +08:00
|
|
|
WREG32(mmVCE_RB_BASE_LO3, ring->gpu_addr);
|
|
|
|
WREG32(mmVCE_RB_BASE_HI3, upper_32_bits(ring->gpu_addr));
|
|
|
|
WREG32(mmVCE_RB_SIZE3, ring->ring_size / 4);
|
|
|
|
|
2015-05-07 03:20:41 +08:00
|
|
|
mutex_lock(&adev->grbm_idx_mutex);
|
|
|
|
for (idx = 0; idx < 2; ++idx) {
|
2015-07-11 02:16:24 +08:00
|
|
|
if (adev->vce.harvest_config & (1 << idx))
|
|
|
|
continue;
|
|
|
|
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(idx));
|
2015-05-07 03:20:41 +08:00
|
|
|
vce_v3_0_mc_resume(adev, idx);
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_STATUS, JOB_BUSY, 1);
|
2016-07-15 16:57:28 +08:00
|
|
|
|
2015-11-17 23:25:31 +08:00
|
|
|
if (adev->asic_type >= CHIP_STONEY)
|
|
|
|
WREG32_P(mmVCE_VCPU_CNTL, 1, ~0x200001);
|
|
|
|
else
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_VCPU_CNTL, CLK_EN, 1);
|
2015-05-07 03:20:41 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 0);
|
2016-07-15 16:57:28 +08:00
|
|
|
mdelay(100);
|
|
|
|
|
|
|
|
r = vce_v3_0_firmware_loaded(adev);
|
2015-05-07 03:20:41 +08:00
|
|
|
|
|
|
|
/* clear BUSY flag */
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_STATUS, JOB_BUSY, 0);
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2015-05-07 03:20:41 +08:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("VCE not responding, giving up!!!\n");
|
|
|
|
mutex_unlock(&adev->grbm_idx_mutex);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
|
2015-05-07 03:20:41 +08:00
|
|
|
mutex_unlock(&adev->grbm_idx_mutex);
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2016-07-15 16:57:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2016-07-15 16:57:28 +08:00
|
|
|
static int vce_v3_0_stop(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
mutex_lock(&adev->grbm_idx_mutex);
|
|
|
|
for (idx = 0; idx < 2; ++idx) {
|
|
|
|
if (adev->vce.harvest_config & (1 << idx))
|
|
|
|
continue;
|
|
|
|
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(idx));
|
2016-07-15 16:57:28 +08:00
|
|
|
|
|
|
|
if (adev->asic_type >= CHIP_STONEY)
|
|
|
|
WREG32_P(mmVCE_VCPU_CNTL, 0, ~0x200001);
|
|
|
|
else
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_VCPU_CNTL, CLK_EN, 0);
|
|
|
|
|
2016-07-15 16:57:28 +08:00
|
|
|
/* hold on ECPU */
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 1);
|
2016-07-15 16:57:28 +08:00
|
|
|
|
|
|
|
/* clear BUSY flag */
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_STATUS, JOB_BUSY, 0);
|
2016-07-15 16:57:28 +08:00
|
|
|
|
|
|
|
/* Set Clock-Gating off */
|
|
|
|
if (adev->cg_flags & AMD_CG_SUPPORT_VCE_MGCG)
|
|
|
|
vce_v3_0_set_vce_sw_clock_gating(adev, false);
|
|
|
|
}
|
|
|
|
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
|
2016-07-15 16:57:28 +08:00
|
|
|
mutex_unlock(&adev->grbm_idx_mutex);
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-11 02:16:24 +08:00
|
|
|
#define ixVCE_HARVEST_FUSE_MACRO__ADDRESS 0xC0014074
|
|
|
|
#define VCE_HARVEST_FUSE_MACRO__SHIFT 27
|
|
|
|
#define VCE_HARVEST_FUSE_MACRO__MASK 0x18000000
|
|
|
|
|
|
|
|
static unsigned vce_v3_0_get_harvest_config(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
|
2016-12-15 04:32:28 +08:00
|
|
|
/* Fiji, Stoney, Polaris10, Polaris11, Polaris12 are single pipe */
|
2015-10-09 04:27:55 +08:00
|
|
|
if ((adev->asic_type == CHIP_FIJI) ||
|
2016-03-12 03:33:40 +08:00
|
|
|
(adev->asic_type == CHIP_STONEY) ||
|
2016-03-15 06:33:29 +08:00
|
|
|
(adev->asic_type == CHIP_POLARIS10) ||
|
2016-12-15 04:32:28 +08:00
|
|
|
(adev->asic_type == CHIP_POLARIS11) ||
|
|
|
|
(adev->asic_type == CHIP_POLARIS12))
|
2015-12-15 23:21:46 +08:00
|
|
|
return AMDGPU_VCE_HARVEST_VCE1;
|
2015-07-28 02:24:14 +08:00
|
|
|
|
|
|
|
/* Tonga and CZ are dual or single pipe */
|
2015-07-22 11:29:01 +08:00
|
|
|
if (adev->flags & AMD_IS_APU)
|
2015-07-11 02:16:24 +08:00
|
|
|
tmp = (RREG32_SMC(ixVCE_HARVEST_FUSE_MACRO__ADDRESS) &
|
|
|
|
VCE_HARVEST_FUSE_MACRO__MASK) >>
|
|
|
|
VCE_HARVEST_FUSE_MACRO__SHIFT;
|
|
|
|
else
|
|
|
|
tmp = (RREG32_SMC(ixCC_HARVEST_FUSES) &
|
|
|
|
CC_HARVEST_FUSES__VCE_DISABLE_MASK) >>
|
|
|
|
CC_HARVEST_FUSES__VCE_DISABLE__SHIFT;
|
|
|
|
|
|
|
|
switch (tmp) {
|
|
|
|
case 1:
|
2015-12-15 23:21:46 +08:00
|
|
|
return AMDGPU_VCE_HARVEST_VCE0;
|
2015-07-11 02:16:24 +08:00
|
|
|
case 2:
|
2015-12-15 23:21:46 +08:00
|
|
|
return AMDGPU_VCE_HARVEST_VCE1;
|
2015-07-11 02:16:24 +08:00
|
|
|
case 3:
|
2015-12-15 23:21:46 +08:00
|
|
|
return AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1;
|
2015-07-11 02:16:24 +08:00
|
|
|
default:
|
2015-12-15 23:21:46 +08:00
|
|
|
return 0;
|
2015-07-11 02:16:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_early_init(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
|
|
|
|
2015-07-11 02:16:24 +08:00
|
|
|
adev->vce.harvest_config = vce_v3_0_get_harvest_config(adev);
|
|
|
|
|
|
|
|
if ((adev->vce.harvest_config &
|
|
|
|
(AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1)) ==
|
|
|
|
(AMDGPU_VCE_HARVEST_VCE0 | AMDGPU_VCE_HARVEST_VCE1))
|
|
|
|
return -ENOENT;
|
|
|
|
|
2016-08-25 05:15:33 +08:00
|
|
|
adev->vce.num_rings = 3;
|
2016-08-25 04:56:21 +08:00
|
|
|
|
2015-04-21 05:31:14 +08:00
|
|
|
vce_v3_0_set_ring_funcs(adev);
|
|
|
|
vce_v3_0_set_irq_funcs(adev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_sw_init(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2015-04-21 05:31:14 +08:00
|
|
|
struct amdgpu_ring *ring;
|
2016-08-25 04:56:21 +08:00
|
|
|
int r, i;
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
/* VCE */
|
2016-03-30 06:28:50 +08:00
|
|
|
r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 167, &adev->vce.irq);
|
2015-04-21 05:31:14 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
2015-05-07 02:31:27 +08:00
|
|
|
r = amdgpu_vce_sw_init(adev, VCE_V3_0_FW_SIZE +
|
|
|
|
(VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE) * 2);
|
2015-04-21 05:31:14 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
2016-10-25 21:37:37 +08:00
|
|
|
/* 52.8.3 required for 3 ring support */
|
|
|
|
if (adev->vce.fw_version < FW_52_8_3)
|
|
|
|
adev->vce.num_rings = 2;
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
r = amdgpu_vce_resume(adev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
2016-08-25 04:56:21 +08:00
|
|
|
for (i = 0; i < adev->vce.num_rings; i++) {
|
|
|
|
ring = &adev->vce.ring[i];
|
|
|
|
sprintf(ring->name, "vce%d", i);
|
2016-10-05 22:09:32 +08:00
|
|
|
r = amdgpu_ring_init(adev, ring, 512, &adev->vce.irq, 0);
|
2016-08-25 04:56:21 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_sw_fini(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
int r;
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
r = amdgpu_vce_suspend(adev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = amdgpu_vce_sw_fini(adev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_hw_init(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
2015-12-15 23:55:34 +08:00
|
|
|
int r, i;
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2017-01-26 10:47:00 +08:00
|
|
|
vce_v3_0_override_vce_clock_gating(adev, true);
|
|
|
|
if (!(adev->flags & AMD_IS_APU))
|
|
|
|
amdgpu_asic_set_vce_clocks(adev, 10000, 10000);
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2016-08-25 04:56:21 +08:00
|
|
|
for (i = 0; i < adev->vce.num_rings; i++)
|
|
|
|
adev->vce.ring[i].ready = false;
|
2015-04-21 05:31:14 +08:00
|
|
|
|
2016-08-25 04:56:21 +08:00
|
|
|
for (i = 0; i < adev->vce.num_rings; i++) {
|
2015-12-15 23:55:34 +08:00
|
|
|
r = amdgpu_ring_test_ring(&adev->vce.ring[i]);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
else
|
|
|
|
adev->vce.ring[i].ready = true;
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DRM_INFO("VCE initialized successfully.\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_hw_fini(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
2016-07-15 16:57:28 +08:00
|
|
|
int r;
|
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
|
|
|
|
|
|
|
r = vce_v3_0_wait_for_idle(handle);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return vce_v3_0_stop(adev);
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_suspend(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
int r;
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
r = vce_v3_0_hw_fini(adev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = amdgpu_vce_suspend(adev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_resume(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
int r;
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
r = amdgpu_vce_resume(adev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = vce_v3_0_hw_init(adev);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-05-07 03:20:41 +08:00
|
|
|
static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
uint32_t offset, size;
|
|
|
|
|
|
|
|
WREG32_P(mmVCE_CLOCK_GATING_A, 0, ~(1 << 16));
|
|
|
|
WREG32_P(mmVCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
|
|
|
|
WREG32_P(mmVCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
|
2016-08-03 22:15:24 +08:00
|
|
|
WREG32(mmVCE_CLOCK_GATING_B, 0x1FF);
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
WREG32(mmVCE_LMI_CTRL, 0x00398000);
|
|
|
|
WREG32_P(mmVCE_LMI_CACHE_CTRL, 0x0, ~0x1);
|
|
|
|
WREG32(mmVCE_LMI_SWAP_CNTL, 0);
|
|
|
|
WREG32(mmVCE_LMI_SWAP_CNTL1, 0);
|
|
|
|
WREG32(mmVCE_LMI_VM_CTRL, 0);
|
2017-02-10 05:01:57 +08:00
|
|
|
WREG32_OR(mmVCE_VCPU_CNTL, 0x00100000);
|
|
|
|
|
2015-11-17 23:25:31 +08:00
|
|
|
if (adev->asic_type >= CHIP_STONEY) {
|
|
|
|
WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR0, (adev->vce.gpu_addr >> 8));
|
|
|
|
WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR1, (adev->vce.gpu_addr >> 8));
|
|
|
|
WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR2, (adev->vce.gpu_addr >> 8));
|
|
|
|
} else
|
|
|
|
WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR, (adev->vce.gpu_addr >> 8));
|
2015-04-21 05:31:14 +08:00
|
|
|
offset = AMDGPU_VCE_FIRMWARE_OFFSET;
|
2015-05-07 02:31:27 +08:00
|
|
|
size = VCE_V3_0_FW_SIZE;
|
2015-04-21 05:31:14 +08:00
|
|
|
WREG32(mmVCE_VCPU_CACHE_OFFSET0, offset & 0x7fffffff);
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_SIZE0, size);
|
|
|
|
|
2015-05-07 03:20:41 +08:00
|
|
|
if (idx == 0) {
|
|
|
|
offset += size;
|
|
|
|
size = VCE_V3_0_STACK_SIZE;
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0x7fffffff);
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
|
|
|
|
offset += size;
|
|
|
|
size = VCE_V3_0_DATA_SIZE;
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0x7fffffff);
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
|
|
|
|
} else {
|
|
|
|
offset += size + VCE_V3_0_STACK_SIZE + VCE_V3_0_DATA_SIZE;
|
|
|
|
size = VCE_V3_0_STACK_SIZE;
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_OFFSET1, offset & 0xfffffff);
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_SIZE1, size);
|
|
|
|
offset += size;
|
|
|
|
size = VCE_V3_0_DATA_SIZE;
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_OFFSET2, offset & 0xfffffff);
|
|
|
|
WREG32(mmVCE_VCPU_CACHE_SIZE2, size);
|
|
|
|
}
|
2015-04-21 05:31:14 +08:00
|
|
|
|
|
|
|
WREG32_P(mmVCE_LMI_CTRL2, 0x0, ~0x100);
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_SYS_INT_EN, VCE_SYS_INT_TRAP_INTERRUPT_EN, 1);
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static bool vce_v3_0_is_idle(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2015-09-04 07:03:11 +08:00
|
|
|
u32 mask = 0;
|
|
|
|
|
2016-01-04 23:46:41 +08:00
|
|
|
mask |= (adev->vce.harvest_config & AMDGPU_VCE_HARVEST_VCE0) ? 0 : SRBM_STATUS2__VCE0_BUSY_MASK;
|
|
|
|
mask |= (adev->vce.harvest_config & AMDGPU_VCE_HARVEST_VCE1) ? 0 : SRBM_STATUS2__VCE1_BUSY_MASK;
|
2015-09-04 07:03:11 +08:00
|
|
|
|
|
|
|
return !(RREG32(mmSRBM_STATUS2) & mask);
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_wait_for_idle(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2015-09-04 07:03:11 +08:00
|
|
|
|
2015-12-15 23:35:56 +08:00
|
|
|
for (i = 0; i < adev->usec_timeout; i++)
|
|
|
|
if (vce_v3_0_is_idle(handle))
|
2015-04-21 05:31:14 +08:00
|
|
|
return 0;
|
2015-12-15 23:35:56 +08:00
|
|
|
|
2015-04-21 05:31:14 +08:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2016-08-03 15:10:28 +08:00
|
|
|
#define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK 0x00000008L /* AUTO_BUSY */
|
|
|
|
#define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK 0x00000010L /* RB0_BUSY */
|
|
|
|
#define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK 0x00000020L /* RB1_BUSY */
|
|
|
|
#define AMDGPU_VCE_STATUS_BUSY_MASK (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK | \
|
|
|
|
VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK)
|
2016-07-18 17:38:50 +08:00
|
|
|
|
2016-10-14 04:07:03 +08:00
|
|
|
static bool vce_v3_0_check_soft_reset(void *handle)
|
2016-07-18 17:38:50 +08:00
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
|
|
|
u32 srbm_soft_reset = 0;
|
|
|
|
|
|
|
|
/* According to VCE team , we should use VCE_STATUS instead
|
|
|
|
* SRBM_STATUS.VCE_BUSY bit for busy status checking.
|
|
|
|
* GRBM_GFX_INDEX.INSTANCE_INDEX is used to specify which VCE
|
|
|
|
* instance's registers are accessed
|
|
|
|
* (0 for 1st instance, 10 for 2nd instance).
|
|
|
|
*
|
|
|
|
*VCE_STATUS
|
|
|
|
*|UENC|ACPI|AUTO ACTIVE|RB1 |RB0 |RB2 | |FW_LOADED|JOB |
|
|
|
|
*|----+----+-----------+----+----+----+----------+---------+----|
|
|
|
|
*|bit8|bit7| bit6 |bit5|bit4|bit3| bit2 | bit1 |bit0|
|
|
|
|
*
|
|
|
|
* VCE team suggest use bit 3--bit 6 for busy status check
|
|
|
|
*/
|
2016-08-11 21:55:51 +08:00
|
|
|
mutex_lock(&adev->grbm_idx_mutex);
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(0));
|
2016-07-18 17:38:50 +08:00
|
|
|
if (RREG32(mmVCE_STATUS) & AMDGPU_VCE_STATUS_BUSY_MASK) {
|
|
|
|
srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE0, 1);
|
|
|
|
srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);
|
|
|
|
}
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(1));
|
2016-07-18 17:38:50 +08:00
|
|
|
if (RREG32(mmVCE_STATUS) & AMDGPU_VCE_STATUS_BUSY_MASK) {
|
|
|
|
srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE0, 1);
|
|
|
|
srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);
|
|
|
|
}
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(0));
|
2016-10-14 04:07:03 +08:00
|
|
|
mutex_unlock(&adev->grbm_idx_mutex);
|
2016-07-18 17:38:50 +08:00
|
|
|
|
|
|
|
if (srbm_soft_reset) {
|
|
|
|
adev->vce.srbm_soft_reset = srbm_soft_reset;
|
2016-10-14 04:07:03 +08:00
|
|
|
return true;
|
2016-07-18 17:38:50 +08:00
|
|
|
} else {
|
|
|
|
adev->vce.srbm_soft_reset = 0;
|
2016-10-14 04:07:03 +08:00
|
|
|
return false;
|
2016-07-18 17:38:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_soft_reset(void *handle)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2016-07-18 17:38:50 +08:00
|
|
|
u32 srbm_soft_reset;
|
|
|
|
|
2016-10-14 04:07:03 +08:00
|
|
|
if (!adev->vce.srbm_soft_reset)
|
2016-07-18 17:38:50 +08:00
|
|
|
return 0;
|
|
|
|
srbm_soft_reset = adev->vce.srbm_soft_reset;
|
|
|
|
|
|
|
|
if (srbm_soft_reset) {
|
|
|
|
u32 tmp;
|
2015-09-04 07:03:11 +08:00
|
|
|
|
2016-07-18 17:38:50 +08:00
|
|
|
tmp = RREG32(mmSRBM_SOFT_RESET);
|
|
|
|
tmp |= srbm_soft_reset;
|
|
|
|
dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
|
|
|
|
WREG32(mmSRBM_SOFT_RESET, tmp);
|
|
|
|
tmp = RREG32(mmSRBM_SOFT_RESET);
|
|
|
|
|
|
|
|
udelay(50);
|
|
|
|
|
|
|
|
tmp &= ~srbm_soft_reset;
|
|
|
|
WREG32(mmSRBM_SOFT_RESET, tmp);
|
|
|
|
tmp = RREG32(mmSRBM_SOFT_RESET);
|
|
|
|
|
|
|
|
/* Wait a little for things to settle down */
|
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vce_v3_0_pre_soft_reset(void *handle)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
|
|
|
|
2016-10-14 04:07:03 +08:00
|
|
|
if (!adev->vce.srbm_soft_reset)
|
2016-07-18 17:38:50 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
mdelay(5);
|
|
|
|
|
|
|
|
return vce_v3_0_suspend(adev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int vce_v3_0_post_soft_reset(void *handle)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
|
|
|
|
2016-10-14 04:07:03 +08:00
|
|
|
if (!adev->vce.srbm_soft_reset)
|
2016-07-18 17:38:50 +08:00
|
|
|
return 0;
|
2015-05-23 02:39:35 +08:00
|
|
|
|
2015-04-21 05:31:14 +08:00
|
|
|
mdelay(5);
|
|
|
|
|
2016-07-18 17:38:50 +08:00
|
|
|
return vce_v3_0_resume(adev);
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vce_v3_0_set_interrupt_state(struct amdgpu_device *adev,
|
|
|
|
struct amdgpu_irq_src *source,
|
|
|
|
unsigned type,
|
|
|
|
enum amdgpu_interrupt_state state)
|
|
|
|
{
|
|
|
|
uint32_t val = 0;
|
|
|
|
|
|
|
|
if (state == AMDGPU_IRQ_STATE_ENABLE)
|
|
|
|
val |= VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK;
|
|
|
|
|
|
|
|
WREG32_P(mmVCE_SYS_INT_EN, val, ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vce_v3_0_process_interrupt(struct amdgpu_device *adev,
|
|
|
|
struct amdgpu_irq_src *source,
|
|
|
|
struct amdgpu_iv_entry *entry)
|
|
|
|
{
|
|
|
|
DRM_DEBUG("IH: VCE\n");
|
2015-11-17 22:28:29 +08:00
|
|
|
|
2016-08-11 21:44:53 +08:00
|
|
|
WREG32_FIELD(VCE_SYS_INT_STATUS, VCE_SYS_INT_TRAP_INTERRUPT_INT, 1);
|
2015-11-17 22:28:29 +08:00
|
|
|
|
2015-04-21 05:31:14 +08:00
|
|
|
switch (entry->src_data) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
2016-08-25 05:15:33 +08:00
|
|
|
case 2:
|
2015-12-15 23:42:39 +08:00
|
|
|
amdgpu_fence_process(&adev->vce.ring[entry->src_data]);
|
2015-04-21 05:31:14 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DRM_ERROR("Unhandled interrupt: %d %d\n",
|
|
|
|
entry->src_id, entry->src_data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_set_clockgating_state(void *handle,
|
|
|
|
enum amd_clockgating_state state)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
2015-11-24 05:57:53 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
|
|
|
bool enable = (state == AMD_CG_STATE_GATE) ? true : false;
|
|
|
|
int i;
|
|
|
|
|
2016-02-05 23:56:22 +08:00
|
|
|
if (!(adev->cg_flags & AMD_CG_SUPPORT_VCE_MGCG))
|
2015-11-24 05:57:53 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
mutex_lock(&adev->grbm_idx_mutex);
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
/* Program VCE Instance 0 or 1 if not harvested */
|
|
|
|
if (adev->vce.harvest_config & (1 << i))
|
|
|
|
continue;
|
|
|
|
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, GET_VCE_INSTANCE(i));
|
2015-11-24 05:57:53 +08:00
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
/* initialize VCE_CLOCK_GATING_A: Clock ON/OFF delay */
|
|
|
|
uint32_t data = RREG32(mmVCE_CLOCK_GATING_A);
|
|
|
|
data &= ~(0xf | 0xff0);
|
|
|
|
data |= ((0x0 << 0) | (0x04 << 4));
|
|
|
|
WREG32(mmVCE_CLOCK_GATING_A, data);
|
|
|
|
|
|
|
|
/* initialize VCE_UENC_CLOCK_GATING: Clock ON/OFF delay */
|
|
|
|
data = RREG32(mmVCE_UENC_CLOCK_GATING);
|
|
|
|
data &= ~(0xf | 0xff0);
|
|
|
|
data |= ((0x0 << 0) | (0x04 << 4));
|
|
|
|
WREG32(mmVCE_UENC_CLOCK_GATING, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
vce_v3_0_set_vce_sw_clock_gating(adev, enable);
|
|
|
|
}
|
|
|
|
|
2017-01-10 20:03:59 +08:00
|
|
|
WREG32(mmGRBM_GFX_INDEX, mmGRBM_GFX_INDEX_DEFAULT);
|
2015-11-24 05:57:53 +08:00
|
|
|
mutex_unlock(&adev->grbm_idx_mutex);
|
|
|
|
|
2015-04-21 05:31:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-23 02:39:35 +08:00
|
|
|
static int vce_v3_0_set_powergating_state(void *handle,
|
|
|
|
enum amd_powergating_state state)
|
2015-04-21 05:31:14 +08:00
|
|
|
{
|
|
|
|
/* This doesn't actually powergate the VCE block.
|
|
|
|
* That's done in the dpm code via the SMC. This
|
|
|
|
* just re-inits the block as necessary. The actual
|
|
|
|
* gating still happens in the dpm code. We should
|
|
|
|
* revisit this when there is a cleaner line between
|
|
|
|
* the smc and the hw blocks
|
|
|
|
*/
|
2015-05-23 02:39:35 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
2017-01-05 21:27:31 +08:00
|
|
|
int ret = 0;
|
2015-05-23 02:39:35 +08:00
|
|
|
|
2017-01-05 21:27:31 +08:00
|
|
|
if (state == AMD_PG_STATE_GATE) {
|
2017-01-26 10:47:00 +08:00
|
|
|
ret = vce_v3_0_stop(adev);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2017-01-05 21:27:31 +08:00
|
|
|
} else {
|
|
|
|
ret = vce_v3_0_start(adev);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vce_v3_0_get_clockgating_state(void *handle, u32 *flags)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
|
|
|
|
int data;
|
|
|
|
|
|
|
|
mutex_lock(&adev->pm.mutex);
|
|
|
|
|
2017-02-08 17:17:55 +08:00
|
|
|
if (RREG32_SMC(ixCURRENT_PG_STATUS) &
|
|
|
|
CURRENT_PG_STATUS__VCE_PG_STATUS_MASK) {
|
2017-01-05 21:27:31 +08:00
|
|
|
DRM_INFO("Cannot get clockgating state when VCE is powergated.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, 0);
|
|
|
|
|
|
|
|
/* AMD_CG_SUPPORT_VCE_MGCG */
|
|
|
|
data = RREG32(mmVCE_CLOCK_GATING_A);
|
|
|
|
if (data & (0x04 << 4))
|
|
|
|
*flags |= AMD_CG_SUPPORT_VCE_MGCG;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&adev->pm.mutex);
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
2016-08-30 17:46:36 +08:00
|
|
|
static void vce_v3_0_ring_emit_ib(struct amdgpu_ring *ring,
|
|
|
|
struct amdgpu_ib *ib, unsigned int vm_id, bool ctx_switch)
|
|
|
|
{
|
|
|
|
amdgpu_ring_write(ring, VCE_CMD_IB_VM);
|
|
|
|
amdgpu_ring_write(ring, vm_id);
|
|
|
|
amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr));
|
|
|
|
amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
|
|
|
|
amdgpu_ring_write(ring, ib->length_dw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vce_v3_0_emit_vm_flush(struct amdgpu_ring *ring,
|
|
|
|
unsigned int vm_id, uint64_t pd_addr)
|
|
|
|
{
|
|
|
|
amdgpu_ring_write(ring, VCE_CMD_UPDATE_PTB);
|
|
|
|
amdgpu_ring_write(ring, vm_id);
|
|
|
|
amdgpu_ring_write(ring, pd_addr >> 12);
|
|
|
|
|
|
|
|
amdgpu_ring_write(ring, VCE_CMD_FLUSH_TLB);
|
|
|
|
amdgpu_ring_write(ring, vm_id);
|
|
|
|
amdgpu_ring_write(ring, VCE_CMD_END);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vce_v3_0_emit_pipeline_sync(struct amdgpu_ring *ring)
|
|
|
|
{
|
|
|
|
uint32_t seq = ring->fence_drv.sync_seq;
|
|
|
|
uint64_t addr = ring->fence_drv.gpu_addr;
|
|
|
|
|
|
|
|
amdgpu_ring_write(ring, VCE_CMD_WAIT_GE);
|
|
|
|
amdgpu_ring_write(ring, lower_32_bits(addr));
|
|
|
|
amdgpu_ring_write(ring, upper_32_bits(addr));
|
|
|
|
amdgpu_ring_write(ring, seq);
|
|
|
|
}
|
|
|
|
|
2016-10-14 05:41:13 +08:00
|
|
|
static const struct amd_ip_funcs vce_v3_0_ip_funcs = {
|
2016-05-05 02:28:35 +08:00
|
|
|
.name = "vce_v3_0",
|
2015-04-21 05:31:14 +08:00
|
|
|
.early_init = vce_v3_0_early_init,
|
|
|
|
.late_init = NULL,
|
|
|
|
.sw_init = vce_v3_0_sw_init,
|
|
|
|
.sw_fini = vce_v3_0_sw_fini,
|
|
|
|
.hw_init = vce_v3_0_hw_init,
|
|
|
|
.hw_fini = vce_v3_0_hw_fini,
|
|
|
|
.suspend = vce_v3_0_suspend,
|
|
|
|
.resume = vce_v3_0_resume,
|
|
|
|
.is_idle = vce_v3_0_is_idle,
|
|
|
|
.wait_for_idle = vce_v3_0_wait_for_idle,
|
2016-07-18 17:38:50 +08:00
|
|
|
.check_soft_reset = vce_v3_0_check_soft_reset,
|
|
|
|
.pre_soft_reset = vce_v3_0_pre_soft_reset,
|
2015-04-21 05:31:14 +08:00
|
|
|
.soft_reset = vce_v3_0_soft_reset,
|
2016-07-18 17:38:50 +08:00
|
|
|
.post_soft_reset = vce_v3_0_post_soft_reset,
|
2015-04-21 05:31:14 +08:00
|
|
|
.set_clockgating_state = vce_v3_0_set_clockgating_state,
|
|
|
|
.set_powergating_state = vce_v3_0_set_powergating_state,
|
2017-01-05 21:27:31 +08:00
|
|
|
.get_clockgating_state = vce_v3_0_get_clockgating_state,
|
2015-04-21 05:31:14 +08:00
|
|
|
};
|
|
|
|
|
2016-08-30 17:46:36 +08:00
|
|
|
static const struct amdgpu_ring_funcs vce_v3_0_ring_phys_funcs = {
|
2016-10-05 21:36:39 +08:00
|
|
|
.type = AMDGPU_RING_TYPE_VCE,
|
2016-10-05 22:09:32 +08:00
|
|
|
.align_mask = 0xf,
|
|
|
|
.nop = VCE_CMD_NO_OP,
|
2016-03-12 09:32:30 +08:00
|
|
|
.support_64bit_ptrs = false,
|
2015-04-21 05:31:14 +08:00
|
|
|
.get_rptr = vce_v3_0_ring_get_rptr,
|
|
|
|
.get_wptr = vce_v3_0_ring_get_wptr,
|
|
|
|
.set_wptr = vce_v3_0_ring_set_wptr,
|
|
|
|
.parse_cs = amdgpu_vce_ring_parse_cs,
|
2016-10-05 20:29:38 +08:00
|
|
|
.emit_frame_size =
|
|
|
|
4 + /* vce_v3_0_emit_pipeline_sync */
|
|
|
|
6, /* amdgpu_vce_ring_emit_fence x1 no user fence */
|
|
|
|
.emit_ib_size = 5, /* vce_v3_0_ring_emit_ib */
|
2015-04-21 05:31:14 +08:00
|
|
|
.emit_ib = amdgpu_vce_ring_emit_ib,
|
|
|
|
.emit_fence = amdgpu_vce_ring_emit_fence,
|
|
|
|
.test_ring = amdgpu_vce_ring_test_ring,
|
|
|
|
.test_ib = amdgpu_vce_ring_test_ib,
|
2015-09-01 13:04:08 +08:00
|
|
|
.insert_nop = amdgpu_ring_insert_nop,
|
2016-01-31 19:20:55 +08:00
|
|
|
.pad_ib = amdgpu_ring_generic_pad_ib,
|
2016-07-20 22:53:36 +08:00
|
|
|
.begin_use = amdgpu_vce_ring_begin_use,
|
|
|
|
.end_use = amdgpu_vce_ring_end_use,
|
2015-04-21 05:31:14 +08:00
|
|
|
};
|
|
|
|
|
2016-08-30 17:46:36 +08:00
|
|
|
static const struct amdgpu_ring_funcs vce_v3_0_ring_vm_funcs = {
|
2016-10-05 21:36:39 +08:00
|
|
|
.type = AMDGPU_RING_TYPE_VCE,
|
2016-10-05 22:09:32 +08:00
|
|
|
.align_mask = 0xf,
|
|
|
|
.nop = VCE_CMD_NO_OP,
|
2016-03-12 09:32:30 +08:00
|
|
|
.support_64bit_ptrs = false,
|
2016-08-30 17:46:36 +08:00
|
|
|
.get_rptr = vce_v3_0_ring_get_rptr,
|
|
|
|
.get_wptr = vce_v3_0_ring_get_wptr,
|
|
|
|
.set_wptr = vce_v3_0_ring_set_wptr,
|
2016-10-10 21:23:32 +08:00
|
|
|
.parse_cs = amdgpu_vce_ring_parse_cs_vm,
|
2016-10-05 20:29:38 +08:00
|
|
|
.emit_frame_size =
|
|
|
|
6 + /* vce_v3_0_emit_vm_flush */
|
|
|
|
4 + /* vce_v3_0_emit_pipeline_sync */
|
|
|
|
6 + 6, /* amdgpu_vce_ring_emit_fence x2 vm fence */
|
|
|
|
.emit_ib_size = 4, /* amdgpu_vce_ring_emit_ib */
|
2016-08-30 17:46:36 +08:00
|
|
|
.emit_ib = vce_v3_0_ring_emit_ib,
|
|
|
|
.emit_vm_flush = vce_v3_0_emit_vm_flush,
|
|
|
|
.emit_pipeline_sync = vce_v3_0_emit_pipeline_sync,
|
|
|
|
.emit_fence = amdgpu_vce_ring_emit_fence,
|
|
|
|
.test_ring = amdgpu_vce_ring_test_ring,
|
|
|
|
.test_ib = amdgpu_vce_ring_test_ib,
|
|
|
|
.insert_nop = amdgpu_ring_insert_nop,
|
|
|
|
.pad_ib = amdgpu_ring_generic_pad_ib,
|
|
|
|
.begin_use = amdgpu_vce_ring_begin_use,
|
|
|
|
.end_use = amdgpu_vce_ring_end_use,
|
|
|
|
};
|
|
|
|
|
2015-04-21 05:31:14 +08:00
|
|
|
static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev)
|
|
|
|
{
|
2016-08-25 04:56:21 +08:00
|
|
|
int i;
|
|
|
|
|
2016-08-30 17:46:36 +08:00
|
|
|
if (adev->asic_type >= CHIP_STONEY) {
|
|
|
|
for (i = 0; i < adev->vce.num_rings; i++)
|
|
|
|
adev->vce.ring[i].funcs = &vce_v3_0_ring_vm_funcs;
|
|
|
|
DRM_INFO("VCE enabled in VM mode\n");
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < adev->vce.num_rings; i++)
|
|
|
|
adev->vce.ring[i].funcs = &vce_v3_0_ring_phys_funcs;
|
|
|
|
DRM_INFO("VCE enabled in physical mode\n");
|
|
|
|
}
|
2015-04-21 05:31:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct amdgpu_irq_src_funcs vce_v3_0_irq_funcs = {
|
|
|
|
.set = vce_v3_0_set_interrupt_state,
|
|
|
|
.process = vce_v3_0_process_interrupt,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
adev->vce.irq.num_types = 1;
|
|
|
|
adev->vce.irq.funcs = &vce_v3_0_irq_funcs;
|
|
|
|
};
|
2016-10-14 05:41:13 +08:00
|
|
|
|
|
|
|
const struct amdgpu_ip_block_version vce_v3_0_ip_block =
|
|
|
|
{
|
|
|
|
.type = AMD_IP_BLOCK_TYPE_VCE,
|
|
|
|
.major = 3,
|
|
|
|
.minor = 0,
|
|
|
|
.rev = 0,
|
|
|
|
.funcs = &vce_v3_0_ip_funcs,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct amdgpu_ip_block_version vce_v3_1_ip_block =
|
|
|
|
{
|
|
|
|
.type = AMD_IP_BLOCK_TYPE_VCE,
|
|
|
|
.major = 3,
|
|
|
|
.minor = 1,
|
|
|
|
.rev = 0,
|
|
|
|
.funcs = &vce_v3_0_ip_funcs,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct amdgpu_ip_block_version vce_v3_4_ip_block =
|
|
|
|
{
|
|
|
|
.type = AMD_IP_BLOCK_TYPE_VCE,
|
|
|
|
.major = 3,
|
|
|
|
.minor = 4,
|
|
|
|
.rev = 0,
|
|
|
|
.funcs = &vce_v3_0_ip_funcs,
|
|
|
|
};
|