xref: /dflybsd-src/sys/dev/drm/radeon/vce_v1_0.c (revision a85cb24f18e3804e75ab8bcda7692564d0563317)
1c6f73aabSFrançois Tigeot /*
2c6f73aabSFrançois Tigeot  * Copyright 2013 Advanced Micro Devices, Inc.
3c6f73aabSFrançois Tigeot  * All Rights Reserved.
4c6f73aabSFrançois Tigeot  *
5c6f73aabSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
6c6f73aabSFrançois Tigeot  * copy of this software and associated documentation files (the
7c6f73aabSFrançois Tigeot  * "Software"), to deal in the Software without restriction, including
8c6f73aabSFrançois Tigeot  * without limitation the rights to use, copy, modify, merge, publish,
9c6f73aabSFrançois Tigeot  * distribute, sub license, and/or sell copies of the Software, and to
10c6f73aabSFrançois Tigeot  * permit persons to whom the Software is furnished to do so, subject to
11c6f73aabSFrançois Tigeot  * the following conditions:
12c6f73aabSFrançois Tigeot  *
13c6f73aabSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14c6f73aabSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15c6f73aabSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16c6f73aabSFrançois Tigeot  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17c6f73aabSFrançois Tigeot  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18c6f73aabSFrançois Tigeot  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19c6f73aabSFrançois Tigeot  * USE OR OTHER DEALINGS IN THE SOFTWARE.
20c6f73aabSFrançois Tigeot  *
21c6f73aabSFrançois Tigeot  * The above copyright notice and this permission notice (including the
22c6f73aabSFrançois Tigeot  * next paragraph) shall be included in all copies or substantial portions
23c6f73aabSFrançois Tigeot  * of the Software.
24c6f73aabSFrançois Tigeot  *
25c6f73aabSFrançois Tigeot  * Authors: Christian König <christian.koenig@amd.com>
26c6f73aabSFrançois Tigeot  */
27c6f73aabSFrançois Tigeot 
28c6f73aabSFrançois Tigeot #include <linux/firmware.h>
29c6f73aabSFrançois Tigeot #include <drm/drmP.h>
30c6f73aabSFrançois Tigeot #include "radeon.h"
31c6f73aabSFrançois Tigeot #include "radeon_asic.h"
32c6f73aabSFrançois Tigeot #include "sid.h"
33c6f73aabSFrançois Tigeot 
34c59a5c48SFrançois Tigeot #define VCE_V1_0_FW_SIZE	(256 * 1024)
35c59a5c48SFrançois Tigeot #define VCE_V1_0_STACK_SIZE	(64 * 1024)
36c59a5c48SFrançois Tigeot #define VCE_V1_0_DATA_SIZE	(7808 * (RADEON_MAX_VCE_HANDLES + 1))
37c59a5c48SFrançois Tigeot 
38c59a5c48SFrançois Tigeot struct vce_v1_0_fw_signature
39c59a5c48SFrançois Tigeot {
40c59a5c48SFrançois Tigeot 	int32_t off;
41c59a5c48SFrançois Tigeot 	uint32_t len;
42c59a5c48SFrançois Tigeot 	int32_t num;
43c59a5c48SFrançois Tigeot 	struct {
44c59a5c48SFrançois Tigeot 		uint32_t chip_id;
45c59a5c48SFrançois Tigeot 		uint32_t keyselect;
46c59a5c48SFrançois Tigeot 		uint32_t nonce[4];
47c59a5c48SFrançois Tigeot 		uint32_t sigval[4];
48c59a5c48SFrançois Tigeot 	} val[8];
49c59a5c48SFrançois Tigeot };
50c59a5c48SFrançois Tigeot 
51c6f73aabSFrançois Tigeot /**
52c6f73aabSFrançois Tigeot  * vce_v1_0_get_rptr - get read pointer
53c6f73aabSFrançois Tigeot  *
54c6f73aabSFrançois Tigeot  * @rdev: radeon_device pointer
55c6f73aabSFrançois Tigeot  * @ring: radeon_ring pointer
56c6f73aabSFrançois Tigeot  *
57c6f73aabSFrançois Tigeot  * Returns the current hardware read pointer
58c6f73aabSFrançois Tigeot  */
vce_v1_0_get_rptr(struct radeon_device * rdev,struct radeon_ring * ring)59c6f73aabSFrançois Tigeot uint32_t vce_v1_0_get_rptr(struct radeon_device *rdev,
60c6f73aabSFrançois Tigeot 			   struct radeon_ring *ring)
61c6f73aabSFrançois Tigeot {
62c6f73aabSFrançois Tigeot 	if (ring->idx == TN_RING_TYPE_VCE1_INDEX)
63c6f73aabSFrançois Tigeot 		return RREG32(VCE_RB_RPTR);
64c6f73aabSFrançois Tigeot 	else
65c6f73aabSFrançois Tigeot 		return RREG32(VCE_RB_RPTR2);
66c6f73aabSFrançois Tigeot }
67c6f73aabSFrançois Tigeot 
68c6f73aabSFrançois Tigeot /**
69c6f73aabSFrançois Tigeot  * vce_v1_0_get_wptr - get write pointer
70c6f73aabSFrançois Tigeot  *
71c6f73aabSFrançois Tigeot  * @rdev: radeon_device pointer
72c6f73aabSFrançois Tigeot  * @ring: radeon_ring pointer
73c6f73aabSFrançois Tigeot  *
74c6f73aabSFrançois Tigeot  * Returns the current hardware write pointer
75c6f73aabSFrançois Tigeot  */
vce_v1_0_get_wptr(struct radeon_device * rdev,struct radeon_ring * ring)76c6f73aabSFrançois Tigeot uint32_t vce_v1_0_get_wptr(struct radeon_device *rdev,
77c6f73aabSFrançois Tigeot 			   struct radeon_ring *ring)
78c6f73aabSFrançois Tigeot {
79c6f73aabSFrançois Tigeot 	if (ring->idx == TN_RING_TYPE_VCE1_INDEX)
80c6f73aabSFrançois Tigeot 		return RREG32(VCE_RB_WPTR);
81c6f73aabSFrançois Tigeot 	else
82c6f73aabSFrançois Tigeot 		return RREG32(VCE_RB_WPTR2);
83c6f73aabSFrançois Tigeot }
84c6f73aabSFrançois Tigeot 
85c6f73aabSFrançois Tigeot /**
86c6f73aabSFrançois Tigeot  * vce_v1_0_set_wptr - set write pointer
87c6f73aabSFrançois Tigeot  *
88c6f73aabSFrançois Tigeot  * @rdev: radeon_device pointer
89c6f73aabSFrançois Tigeot  * @ring: radeon_ring pointer
90c6f73aabSFrançois Tigeot  *
91c6f73aabSFrançois Tigeot  * Commits the write pointer to the hardware
92c6f73aabSFrançois Tigeot  */
vce_v1_0_set_wptr(struct radeon_device * rdev,struct radeon_ring * ring)93c6f73aabSFrançois Tigeot void vce_v1_0_set_wptr(struct radeon_device *rdev,
94c6f73aabSFrançois Tigeot 		       struct radeon_ring *ring)
95c6f73aabSFrançois Tigeot {
96c6f73aabSFrançois Tigeot 	if (ring->idx == TN_RING_TYPE_VCE1_INDEX)
97c6f73aabSFrançois Tigeot 		WREG32(VCE_RB_WPTR, ring->wptr);
98c6f73aabSFrançois Tigeot 	else
99c6f73aabSFrançois Tigeot 		WREG32(VCE_RB_WPTR2, ring->wptr);
100c6f73aabSFrançois Tigeot }
101c6f73aabSFrançois Tigeot 
102c59a5c48SFrançois Tigeot void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
vce_v1_0_enable_mgcg(struct radeon_device * rdev,bool enable)103c59a5c48SFrançois Tigeot void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable)
104c59a5c48SFrançois Tigeot {
105c59a5c48SFrançois Tigeot 	u32 tmp;
106c59a5c48SFrançois Tigeot 
107c59a5c48SFrançois Tigeot 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_VCE_MGCG)) {
108c59a5c48SFrançois Tigeot 		tmp = RREG32(VCE_CLOCK_GATING_A);
109c59a5c48SFrançois Tigeot 		tmp |= CGC_DYN_CLOCK_MODE;
110c59a5c48SFrançois Tigeot 		WREG32(VCE_CLOCK_GATING_A, tmp);
111c59a5c48SFrançois Tigeot 
112c59a5c48SFrançois Tigeot 		tmp = RREG32(VCE_UENC_CLOCK_GATING);
113c59a5c48SFrançois Tigeot 		tmp &= ~0x1ff000;
114c59a5c48SFrançois Tigeot 		tmp |= 0xff800000;
115c59a5c48SFrançois Tigeot 		WREG32(VCE_UENC_CLOCK_GATING, tmp);
116c59a5c48SFrançois Tigeot 
117c59a5c48SFrançois Tigeot 		tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
118c59a5c48SFrançois Tigeot 		tmp &= ~0x3ff;
119c59a5c48SFrançois Tigeot 		WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
120c59a5c48SFrançois Tigeot 	} else {
121c59a5c48SFrançois Tigeot 		tmp = RREG32(VCE_CLOCK_GATING_A);
122c59a5c48SFrançois Tigeot 		tmp &= ~CGC_DYN_CLOCK_MODE;
123c59a5c48SFrançois Tigeot 		WREG32(VCE_CLOCK_GATING_A, tmp);
124c59a5c48SFrançois Tigeot 
125c59a5c48SFrançois Tigeot 		tmp = RREG32(VCE_UENC_CLOCK_GATING);
126c59a5c48SFrançois Tigeot 		tmp |= 0x1ff000;
127c59a5c48SFrançois Tigeot 		tmp &= ~0xff800000;
128c59a5c48SFrançois Tigeot 		WREG32(VCE_UENC_CLOCK_GATING, tmp);
129c59a5c48SFrançois Tigeot 
130c59a5c48SFrançois Tigeot 		tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
131c59a5c48SFrançois Tigeot 		tmp |= 0x3ff;
132c59a5c48SFrançois Tigeot 		WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
133c59a5c48SFrançois Tigeot 	}
134c59a5c48SFrançois Tigeot }
135c59a5c48SFrançois Tigeot 
vce_v1_0_init_cg(struct radeon_device * rdev)136c59a5c48SFrançois Tigeot static void vce_v1_0_init_cg(struct radeon_device *rdev)
137c59a5c48SFrançois Tigeot {
138c59a5c48SFrançois Tigeot 	u32 tmp;
139c59a5c48SFrançois Tigeot 
140c59a5c48SFrançois Tigeot 	tmp = RREG32(VCE_CLOCK_GATING_A);
141c59a5c48SFrançois Tigeot 	tmp |= CGC_DYN_CLOCK_MODE;
142c59a5c48SFrançois Tigeot 	WREG32(VCE_CLOCK_GATING_A, tmp);
143c59a5c48SFrançois Tigeot 
144c59a5c48SFrançois Tigeot 	tmp = RREG32(VCE_CLOCK_GATING_B);
145c59a5c48SFrançois Tigeot 	tmp |= 0x1e;
146c59a5c48SFrançois Tigeot 	tmp &= ~0xe100e1;
147c59a5c48SFrançois Tigeot 	WREG32(VCE_CLOCK_GATING_B, tmp);
148c59a5c48SFrançois Tigeot 
149c59a5c48SFrançois Tigeot 	tmp = RREG32(VCE_UENC_CLOCK_GATING);
150c59a5c48SFrançois Tigeot 	tmp &= ~0xff9ff000;
151c59a5c48SFrançois Tigeot 	WREG32(VCE_UENC_CLOCK_GATING, tmp);
152c59a5c48SFrançois Tigeot 
153c59a5c48SFrançois Tigeot 	tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
154c59a5c48SFrançois Tigeot 	tmp &= ~0x3ff;
155c59a5c48SFrançois Tigeot 	WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
156c59a5c48SFrançois Tigeot }
157c59a5c48SFrançois Tigeot 
vce_v1_0_load_fw(struct radeon_device * rdev,uint32_t * data)158c59a5c48SFrançois Tigeot int vce_v1_0_load_fw(struct radeon_device *rdev, uint32_t *data)
159c59a5c48SFrançois Tigeot {
160c59a5c48SFrançois Tigeot 	const struct vce_v1_0_fw_signature *sign = (const void*)rdev->vce_fw->data;
161c59a5c48SFrançois Tigeot 	uint32_t chip_id;
162c59a5c48SFrançois Tigeot 	int i;
163c59a5c48SFrançois Tigeot 
164c59a5c48SFrançois Tigeot 	switch (rdev->family) {
165c59a5c48SFrançois Tigeot 	case CHIP_TAHITI:
166c59a5c48SFrançois Tigeot 		chip_id = 0x01000014;
167c59a5c48SFrançois Tigeot 		break;
168c59a5c48SFrançois Tigeot 	case CHIP_VERDE:
169c59a5c48SFrançois Tigeot 		chip_id = 0x01000015;
170c59a5c48SFrançois Tigeot 		break;
171c59a5c48SFrançois Tigeot 	case CHIP_PITCAIRN:
172c59a5c48SFrançois Tigeot 	case CHIP_OLAND:
173c59a5c48SFrançois Tigeot 		chip_id = 0x01000016;
174c59a5c48SFrançois Tigeot 		break;
175c59a5c48SFrançois Tigeot 	case CHIP_ARUBA:
176c59a5c48SFrançois Tigeot 		chip_id = 0x01000017;
177c59a5c48SFrançois Tigeot 		break;
178c59a5c48SFrançois Tigeot 	default:
179c59a5c48SFrançois Tigeot 		return -EINVAL;
180c59a5c48SFrançois Tigeot 	}
181c59a5c48SFrançois Tigeot 
182c59a5c48SFrançois Tigeot 	for (i = 0; i < le32_to_cpu(sign->num); ++i) {
183c59a5c48SFrançois Tigeot 		if (le32_to_cpu(sign->val[i].chip_id) == chip_id)
184c59a5c48SFrançois Tigeot 			break;
185c59a5c48SFrançois Tigeot 	}
186c59a5c48SFrançois Tigeot 
187c59a5c48SFrançois Tigeot 	if (i == le32_to_cpu(sign->num))
188c59a5c48SFrançois Tigeot 		return -EINVAL;
189c59a5c48SFrançois Tigeot 
190c59a5c48SFrançois Tigeot 	data += (256 - 64) / 4;
191c59a5c48SFrançois Tigeot 	data[0] = sign->val[i].nonce[0];
192c59a5c48SFrançois Tigeot 	data[1] = sign->val[i].nonce[1];
193c59a5c48SFrançois Tigeot 	data[2] = sign->val[i].nonce[2];
194c59a5c48SFrançois Tigeot 	data[3] = sign->val[i].nonce[3];
195c59a5c48SFrançois Tigeot 	data[4] = cpu_to_le32(le32_to_cpu(sign->len) + 64);
196c59a5c48SFrançois Tigeot 
197c59a5c48SFrançois Tigeot 	memset(&data[5], 0, 44);
198c59a5c48SFrançois Tigeot 	memcpy(&data[16], &sign[1], rdev->vce_fw->datasize - sizeof(*sign));
199c59a5c48SFrançois Tigeot 
200*a85cb24fSFrançois Tigeot 	data += (le32_to_cpu(sign->len) + 64) / 4;
201c59a5c48SFrançois Tigeot 	data[0] = sign->val[i].sigval[0];
202c59a5c48SFrançois Tigeot 	data[1] = sign->val[i].sigval[1];
203c59a5c48SFrançois Tigeot 	data[2] = sign->val[i].sigval[2];
204c59a5c48SFrançois Tigeot 	data[3] = sign->val[i].sigval[3];
205c59a5c48SFrançois Tigeot 
206c59a5c48SFrançois Tigeot 	rdev->vce.keyselect = le32_to_cpu(sign->val[i].keyselect);
207c59a5c48SFrançois Tigeot 
208c59a5c48SFrançois Tigeot 	return 0;
209c59a5c48SFrançois Tigeot }
210c59a5c48SFrançois Tigeot 
vce_v1_0_bo_size(struct radeon_device * rdev)211c59a5c48SFrançois Tigeot unsigned vce_v1_0_bo_size(struct radeon_device *rdev)
212c59a5c48SFrançois Tigeot {
213c59a5c48SFrançois Tigeot 	WARN_ON(VCE_V1_0_FW_SIZE < rdev->vce_fw->datasize);
214c59a5c48SFrançois Tigeot 	return VCE_V1_0_FW_SIZE + VCE_V1_0_STACK_SIZE + VCE_V1_0_DATA_SIZE;
215c59a5c48SFrançois Tigeot }
216c59a5c48SFrançois Tigeot 
vce_v1_0_resume(struct radeon_device * rdev)217c59a5c48SFrançois Tigeot int vce_v1_0_resume(struct radeon_device *rdev)
218c59a5c48SFrançois Tigeot {
219c59a5c48SFrançois Tigeot 	uint64_t addr = rdev->vce.gpu_addr;
220c59a5c48SFrançois Tigeot 	uint32_t size;
221c59a5c48SFrançois Tigeot 	int i;
222c59a5c48SFrançois Tigeot 
223c59a5c48SFrançois Tigeot 	WREG32_P(VCE_CLOCK_GATING_A, 0, ~(1 << 16));
224c59a5c48SFrançois Tigeot 	WREG32_P(VCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
225c59a5c48SFrançois Tigeot 	WREG32_P(VCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
226c59a5c48SFrançois Tigeot 	WREG32(VCE_CLOCK_GATING_B, 0);
227c59a5c48SFrançois Tigeot 
228c59a5c48SFrançois Tigeot 	WREG32_P(VCE_LMI_FW_PERIODIC_CTRL, 0x4, ~0x4);
229c59a5c48SFrançois Tigeot 
230c59a5c48SFrançois Tigeot 	WREG32(VCE_LMI_CTRL, 0x00398000);
231c59a5c48SFrançois Tigeot 	WREG32_P(VCE_LMI_CACHE_CTRL, 0x0, ~0x1);
232c59a5c48SFrançois Tigeot 	WREG32(VCE_LMI_SWAP_CNTL, 0);
233c59a5c48SFrançois Tigeot 	WREG32(VCE_LMI_SWAP_CNTL1, 0);
234c59a5c48SFrançois Tigeot 	WREG32(VCE_LMI_VM_CTRL, 0);
235c59a5c48SFrançois Tigeot 
236c59a5c48SFrançois Tigeot 	WREG32(VCE_VCPU_SCRATCH7, RADEON_MAX_VCE_HANDLES);
237c59a5c48SFrançois Tigeot 
238c59a5c48SFrançois Tigeot 	addr += 256;
239c59a5c48SFrançois Tigeot 	size = VCE_V1_0_FW_SIZE;
240c59a5c48SFrançois Tigeot 	WREG32(VCE_VCPU_CACHE_OFFSET0, addr & 0x7fffffff);
241c59a5c48SFrançois Tigeot 	WREG32(VCE_VCPU_CACHE_SIZE0, size);
242c59a5c48SFrançois Tigeot 
243c59a5c48SFrançois Tigeot 	addr += size;
244c59a5c48SFrançois Tigeot 	size = VCE_V1_0_STACK_SIZE;
245c59a5c48SFrançois Tigeot 	WREG32(VCE_VCPU_CACHE_OFFSET1, addr & 0x7fffffff);
246c59a5c48SFrançois Tigeot 	WREG32(VCE_VCPU_CACHE_SIZE1, size);
247c59a5c48SFrançois Tigeot 
248c59a5c48SFrançois Tigeot 	addr += size;
249c59a5c48SFrançois Tigeot 	size = VCE_V1_0_DATA_SIZE;
250c59a5c48SFrançois Tigeot 	WREG32(VCE_VCPU_CACHE_OFFSET2, addr & 0x7fffffff);
251c59a5c48SFrançois Tigeot 	WREG32(VCE_VCPU_CACHE_SIZE2, size);
252c59a5c48SFrançois Tigeot 
253c59a5c48SFrançois Tigeot 	WREG32_P(VCE_LMI_CTRL2, 0x0, ~0x100);
254c59a5c48SFrançois Tigeot 
255c59a5c48SFrançois Tigeot 	WREG32(VCE_LMI_FW_START_KEYSEL, rdev->vce.keyselect);
256c59a5c48SFrançois Tigeot 
257c59a5c48SFrançois Tigeot 	for (i = 0; i < 10; ++i) {
258c59a5c48SFrançois Tigeot 		mdelay(10);
259c59a5c48SFrançois Tigeot 		if (RREG32(VCE_FW_REG_STATUS) & VCE_FW_REG_STATUS_DONE)
260c59a5c48SFrançois Tigeot 			break;
261c59a5c48SFrançois Tigeot 	}
262c59a5c48SFrançois Tigeot 
263c59a5c48SFrançois Tigeot 	if (i == 10)
264c59a5c48SFrançois Tigeot 		return -ETIMEDOUT;
265c59a5c48SFrançois Tigeot 
266c59a5c48SFrançois Tigeot 	if (!(RREG32(VCE_FW_REG_STATUS) & VCE_FW_REG_STATUS_PASS))
267c59a5c48SFrançois Tigeot 		return -EINVAL;
268c59a5c48SFrançois Tigeot 
269c59a5c48SFrançois Tigeot 	for (i = 0; i < 10; ++i) {
270c59a5c48SFrançois Tigeot 		mdelay(10);
271c59a5c48SFrançois Tigeot 		if (!(RREG32(VCE_FW_REG_STATUS) & VCE_FW_REG_STATUS_BUSY))
272c59a5c48SFrançois Tigeot 			break;
273c59a5c48SFrançois Tigeot 	}
274c59a5c48SFrançois Tigeot 
275c59a5c48SFrançois Tigeot 	if (i == 10)
276c59a5c48SFrançois Tigeot 		return -ETIMEDOUT;
277c59a5c48SFrançois Tigeot 
278c59a5c48SFrançois Tigeot 	vce_v1_0_init_cg(rdev);
279c59a5c48SFrançois Tigeot 
280c59a5c48SFrançois Tigeot 	return 0;
281c59a5c48SFrançois Tigeot }
282c59a5c48SFrançois Tigeot 
283c6f73aabSFrançois Tigeot /**
284c6f73aabSFrançois Tigeot  * vce_v1_0_start - start VCE block
285c6f73aabSFrançois Tigeot  *
286c6f73aabSFrançois Tigeot  * @rdev: radeon_device pointer
287c6f73aabSFrançois Tigeot  *
288c6f73aabSFrançois Tigeot  * Setup and start the VCE block
289c6f73aabSFrançois Tigeot  */
vce_v1_0_start(struct radeon_device * rdev)290c6f73aabSFrançois Tigeot int vce_v1_0_start(struct radeon_device *rdev)
291c6f73aabSFrançois Tigeot {
292c6f73aabSFrançois Tigeot 	struct radeon_ring *ring;
293c6f73aabSFrançois Tigeot 	int i, j, r;
294c6f73aabSFrançois Tigeot 
295c6f73aabSFrançois Tigeot 	/* set BUSY flag */
296c6f73aabSFrançois Tigeot 	WREG32_P(VCE_STATUS, 1, ~1);
297c6f73aabSFrançois Tigeot 
298c6f73aabSFrançois Tigeot 	ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
299c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_RPTR, ring->wptr);
300c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_WPTR, ring->wptr);
301c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_BASE_LO, ring->gpu_addr);
302c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_BASE_HI, upper_32_bits(ring->gpu_addr));
303c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_SIZE, ring->ring_size / 4);
304c6f73aabSFrançois Tigeot 
305c6f73aabSFrançois Tigeot 	ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
306c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_RPTR2, ring->wptr);
307c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_WPTR2, ring->wptr);
308c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_BASE_LO2, ring->gpu_addr);
309c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_BASE_HI2, upper_32_bits(ring->gpu_addr));
310c6f73aabSFrançois Tigeot 	WREG32(VCE_RB_SIZE2, ring->ring_size / 4);
311c6f73aabSFrançois Tigeot 
312c6f73aabSFrançois Tigeot 	WREG32_P(VCE_VCPU_CNTL, VCE_CLK_EN, ~VCE_CLK_EN);
313c6f73aabSFrançois Tigeot 
314c6f73aabSFrançois Tigeot 	WREG32_P(VCE_SOFT_RESET,
315c6f73aabSFrançois Tigeot 		 VCE_ECPU_SOFT_RESET |
316c6f73aabSFrançois Tigeot 		 VCE_FME_SOFT_RESET, ~(
317c6f73aabSFrançois Tigeot 		 VCE_ECPU_SOFT_RESET |
318c6f73aabSFrançois Tigeot 		 VCE_FME_SOFT_RESET));
319c6f73aabSFrançois Tigeot 
320c6f73aabSFrançois Tigeot 	mdelay(100);
321c6f73aabSFrançois Tigeot 
322c6f73aabSFrançois Tigeot 	WREG32_P(VCE_SOFT_RESET, 0, ~(
323c6f73aabSFrançois Tigeot 		 VCE_ECPU_SOFT_RESET |
324c6f73aabSFrançois Tigeot 		 VCE_FME_SOFT_RESET));
325c6f73aabSFrançois Tigeot 
326c6f73aabSFrançois Tigeot 	for (i = 0; i < 10; ++i) {
327c6f73aabSFrançois Tigeot 		uint32_t status;
328c6f73aabSFrançois Tigeot 		for (j = 0; j < 100; ++j) {
329c6f73aabSFrançois Tigeot 			status = RREG32(VCE_STATUS);
330c6f73aabSFrançois Tigeot 			if (status & 2)
331c6f73aabSFrançois Tigeot 				break;
332c6f73aabSFrançois Tigeot 			mdelay(10);
333c6f73aabSFrançois Tigeot 		}
334c6f73aabSFrançois Tigeot 		r = 0;
335c6f73aabSFrançois Tigeot 		if (status & 2)
336c6f73aabSFrançois Tigeot 			break;
337c6f73aabSFrançois Tigeot 
338c6f73aabSFrançois Tigeot 		DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");
339c6f73aabSFrançois Tigeot 		WREG32_P(VCE_SOFT_RESET, VCE_ECPU_SOFT_RESET, ~VCE_ECPU_SOFT_RESET);
340c6f73aabSFrançois Tigeot 		mdelay(10);
341c6f73aabSFrançois Tigeot 		WREG32_P(VCE_SOFT_RESET, 0, ~VCE_ECPU_SOFT_RESET);
342c6f73aabSFrançois Tigeot 		mdelay(10);
343c6f73aabSFrançois Tigeot 		r = -1;
344c6f73aabSFrançois Tigeot 	}
345c6f73aabSFrançois Tigeot 
346c6f73aabSFrançois Tigeot 	/* clear BUSY flag */
347c6f73aabSFrançois Tigeot 	WREG32_P(VCE_STATUS, 0, ~1);
348c6f73aabSFrançois Tigeot 
349c6f73aabSFrançois Tigeot 	if (r) {
350c6f73aabSFrançois Tigeot 		DRM_ERROR("VCE not responding, giving up!!!\n");
351c6f73aabSFrançois Tigeot 		return r;
352c6f73aabSFrançois Tigeot 	}
353c6f73aabSFrançois Tigeot 
354c6f73aabSFrançois Tigeot 	return 0;
355c6f73aabSFrançois Tigeot }
356c6f73aabSFrançois Tigeot 
vce_v1_0_init(struct radeon_device * rdev)357c6f73aabSFrançois Tigeot int vce_v1_0_init(struct radeon_device *rdev)
358c6f73aabSFrançois Tigeot {
359c6f73aabSFrançois Tigeot 	struct radeon_ring *ring;
360c6f73aabSFrançois Tigeot 	int r;
361c6f73aabSFrançois Tigeot 
362c6f73aabSFrançois Tigeot 	r = vce_v1_0_start(rdev);
363c6f73aabSFrançois Tigeot 	if (r)
364c6f73aabSFrançois Tigeot 		return r;
365c6f73aabSFrançois Tigeot 
366c6f73aabSFrançois Tigeot 	ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
367c6f73aabSFrançois Tigeot 	ring->ready = true;
368c6f73aabSFrançois Tigeot 	r = radeon_ring_test(rdev, TN_RING_TYPE_VCE1_INDEX, ring);
369c6f73aabSFrançois Tigeot 	if (r) {
370c6f73aabSFrançois Tigeot 		ring->ready = false;
371c6f73aabSFrançois Tigeot 		return r;
372c6f73aabSFrançois Tigeot 	}
373c6f73aabSFrançois Tigeot 
374c6f73aabSFrançois Tigeot 	ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
375c6f73aabSFrançois Tigeot 	ring->ready = true;
376c6f73aabSFrançois Tigeot 	r = radeon_ring_test(rdev, TN_RING_TYPE_VCE2_INDEX, ring);
377c6f73aabSFrançois Tigeot 	if (r) {
378c6f73aabSFrançois Tigeot 		ring->ready = false;
379c6f73aabSFrançois Tigeot 		return r;
380c6f73aabSFrançois Tigeot 	}
381c6f73aabSFrançois Tigeot 
382c6f73aabSFrançois Tigeot 	DRM_INFO("VCE initialized successfully.\n");
383c6f73aabSFrançois Tigeot 
384c6f73aabSFrançois Tigeot 	return 0;
385c6f73aabSFrançois Tigeot }
386