1d38ceaf9SAlex Deucher /*
2d38ceaf9SAlex Deucher  * Copyright 2014 Advanced Micro Devices, Inc.
3d38ceaf9SAlex Deucher  *
4d38ceaf9SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
5d38ceaf9SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
6d38ceaf9SAlex Deucher  * to deal in the Software without restriction, including without limitation
7d38ceaf9SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d38ceaf9SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
9d38ceaf9SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
10d38ceaf9SAlex Deucher  *
11d38ceaf9SAlex Deucher  * The above copyright notice and this permission notice shall be included in
12d38ceaf9SAlex Deucher  * all copies or substantial portions of the Software.
13d38ceaf9SAlex Deucher  *
14d38ceaf9SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d38ceaf9SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d38ceaf9SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17d38ceaf9SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d38ceaf9SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d38ceaf9SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d38ceaf9SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
21d38ceaf9SAlex Deucher  *
22d38ceaf9SAlex Deucher  */
23d38ceaf9SAlex Deucher 
24d38ceaf9SAlex Deucher #ifndef __AMDGPU_VCE_H__
25d38ceaf9SAlex Deucher #define __AMDGPU_VCE_H__
26d38ceaf9SAlex Deucher 
275e568178SLeo Liu #define AMDGPU_MAX_VCE_HANDLES	16
285e568178SLeo Liu #define AMDGPU_VCE_FIRMWARE_OFFSET 256
295e568178SLeo Liu 
305e568178SLeo Liu #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
315e568178SLeo Liu #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
325e568178SLeo Liu 
336b034e25SChristian König #define AMDGPU_VCE_FW_53_45	((53 << 24) | (45 << 16))
346b034e25SChristian König 
355e568178SLeo Liu struct amdgpu_vce {
365e568178SLeo Liu 	struct amdgpu_bo	*vcpu_bo;
375e568178SLeo Liu 	uint64_t		gpu_addr;
3891415a09SLeo Liu 	void			*cpu_addr;
39a107ebf6SLeo Liu 	void			*saved_bo;
405e568178SLeo Liu 	unsigned		fw_version;
415e568178SLeo Liu 	unsigned		fb_version;
425e568178SLeo Liu 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
435e568178SLeo Liu 	struct drm_file		*filp[AMDGPU_MAX_VCE_HANDLES];
445e568178SLeo Liu 	uint32_t		img_size[AMDGPU_MAX_VCE_HANDLES];
455e568178SLeo Liu 	struct delayed_work	idle_work;
465e568178SLeo Liu 	struct mutex		idle_mutex;
475e568178SLeo Liu 	const struct firmware	*fw;	/* VCE firmware */
485e568178SLeo Liu 	struct amdgpu_ring	ring[AMDGPU_MAX_VCE_RINGS];
495e568178SLeo Liu 	struct amdgpu_irq_src	irq;
505e568178SLeo Liu 	unsigned		harvest_config;
511b1f42d8SLucas Stach 	struct drm_sched_entity	entity;
525e568178SLeo Liu 	uint32_t                srbm_soft_reset;
535e568178SLeo Liu 	unsigned		num_rings;
545e568178SLeo Liu };
555e568178SLeo Liu 
56e9822622SLeo Liu int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size);
57d38ceaf9SAlex Deucher int amdgpu_vce_sw_fini(struct amdgpu_device *adev);
58*037b98a2SAlex Deucher int amdgpu_vce_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring);
59d38ceaf9SAlex Deucher int amdgpu_vce_suspend(struct amdgpu_device *adev);
60d38ceaf9SAlex Deucher int amdgpu_vce_resume(struct amdgpu_device *adev);
61d38ceaf9SAlex Deucher void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp);
62cdc7893fSChristian König int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
63cdc7893fSChristian König 			     struct amdgpu_ib *ib);
64cdc7893fSChristian König int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p,
65cdc7893fSChristian König 				struct amdgpu_job *job,
66cdc7893fSChristian König 				struct amdgpu_ib *ib);
6734955e03SRex Zhu void amdgpu_vce_ring_emit_ib(struct amdgpu_ring *ring, struct amdgpu_job *job,
68c4c905ecSJack Xiao 				struct amdgpu_ib *ib, uint32_t flags);
69d38ceaf9SAlex Deucher void amdgpu_vce_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
70890ee23fSChunming Zhou 				unsigned flags);
71d38ceaf9SAlex Deucher int amdgpu_vce_ring_test_ring(struct amdgpu_ring *ring);
72bbec97aaSChristian König int amdgpu_vce_ring_test_ib(struct amdgpu_ring *ring, long timeout);
73ebff485eSChristian König void amdgpu_vce_ring_begin_use(struct amdgpu_ring *ring);
74ebff485eSChristian König void amdgpu_vce_ring_end_use(struct amdgpu_ring *ring);
75a6f8d728SAlex Deucher unsigned amdgpu_vce_ring_get_emit_ib_size(struct amdgpu_ring *ring);
76a6f8d728SAlex Deucher unsigned amdgpu_vce_ring_get_dma_frame_size(struct amdgpu_ring *ring);
77080e613cSSatyajit Sahu enum amdgpu_ring_priority_level amdgpu_vce_get_ring_prio(int ring);
78d38ceaf9SAlex Deucher 
79d38ceaf9SAlex Deucher #endif
80