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_UVD_H__
25d38ceaf9SAlex Deucher #define __AMDGPU_UVD_H__
26d38ceaf9SAlex Deucher 
274df654d2SLeo Liu #define AMDGPU_DEFAULT_UVD_HANDLES	10
284df654d2SLeo Liu #define AMDGPU_MAX_UVD_HANDLES		40
294df654d2SLeo Liu #define AMDGPU_UVD_STACK_SIZE		(200*1024)
304df654d2SLeo Liu #define AMDGPU_UVD_HEAP_SIZE		(256*1024)
314df654d2SLeo Liu #define AMDGPU_UVD_SESSION_SIZE		(50*1024)
324df654d2SLeo Liu #define AMDGPU_UVD_FIRMWARE_OFFSET	256
334df654d2SLeo Liu 
342bb795f5SJames Zhu #define AMDGPU_MAX_UVD_INSTANCES			2
352bb795f5SJames Zhu 
36c1fe75c9SPiotr Redlewski #define AMDGPU_UVD_FIRMWARE_SIZE(adev)    \
37c1fe75c9SPiotr Redlewski 	(AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(((const struct common_firmware_header *)(adev)->uvd.fw->data)->ucode_size_bytes) + \
38c1fe75c9SPiotr Redlewski 			       8) - AMDGPU_UVD_FIRMWARE_OFFSET)
39c1fe75c9SPiotr Redlewski 
402bb795f5SJames Zhu struct amdgpu_uvd_inst {
414df654d2SLeo Liu 	struct amdgpu_bo	*vcpu_bo;
424df654d2SLeo Liu 	void			*cpu_addr;
434df654d2SLeo Liu 	uint64_t		gpu_addr;
444df654d2SLeo Liu 	void			*saved_bo;
454df654d2SLeo Liu 	struct amdgpu_ring	ring;
46f7243053SLeo Liu 	struct amdgpu_ring	ring_enc[AMDGPU_MAX_UVD_ENC_RINGS];
474df654d2SLeo Liu 	struct amdgpu_irq_src	irq;
484df654d2SLeo Liu 	uint32_t                srbm_soft_reset;
492bb795f5SJames Zhu };
502bb795f5SJames Zhu 
51f1e582ebSAlex Deucher #define AMDGPU_UVD_HARVEST_UVD0 (1 << 0)
52f1e582ebSAlex Deucher #define AMDGPU_UVD_HARVEST_UVD1 (1 << 1)
53f1e582ebSAlex Deucher 
542bb795f5SJames Zhu struct amdgpu_uvd {
552bb795f5SJames Zhu 	const struct firmware	*fw;	/* UVD firmware */
562bb795f5SJames Zhu 	unsigned		fw_version;
572bb795f5SJames Zhu 	unsigned		max_handles;
58f7243053SLeo Liu 	unsigned		num_enc_rings;
592bb795f5SJames Zhu 	uint8_t			num_uvd_inst;
602bb795f5SJames Zhu 	bool			address_64_bit;
612bb795f5SJames Zhu 	bool			use_ctx_buf;
622bb795f5SJames Zhu 	struct amdgpu_uvd_inst	inst[AMDGPU_MAX_UVD_INSTANCES];
635c675bf2SChristian König 	struct drm_file		*filp[AMDGPU_MAX_UVD_HANDLES];
645c675bf2SChristian König 	atomic_t		handles[AMDGPU_MAX_UVD_HANDLES];
655c675bf2SChristian König 	struct drm_sched_entity entity;
665c53d19bSJames Zhu 	struct delayed_work	idle_work;
67f1e582ebSAlex Deucher 	unsigned		harvest_config;
688ca606deSGuttula, Suresh 	/* store image width to adjust nb memory state */
698ca606deSGuttula, Suresh 	unsigned		decode_image_width;
704d6a9536SSonny Jiang 	uint32_t                keyselect;
7168331d7cSxinhui pan 	struct amdgpu_bo	*ib_bo;
724df654d2SLeo Liu };
734df654d2SLeo Liu 
74d38ceaf9SAlex Deucher int amdgpu_uvd_sw_init(struct amdgpu_device *adev);
75d38ceaf9SAlex Deucher int amdgpu_uvd_sw_fini(struct amdgpu_device *adev);
76*037b98a2SAlex Deucher int amdgpu_uvd_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring);
77db998890SMario Limonciello int amdgpu_uvd_prepare_suspend(struct amdgpu_device *adev);
78d38ceaf9SAlex Deucher int amdgpu_uvd_suspend(struct amdgpu_device *adev);
79d38ceaf9SAlex Deucher int amdgpu_uvd_resume(struct amdgpu_device *adev);
80d38ceaf9SAlex Deucher int amdgpu_uvd_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
81f54d1867SChris Wilson 			      struct dma_fence **fence);
82d38ceaf9SAlex Deucher int amdgpu_uvd_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
83f54d1867SChris Wilson 			       bool direct, struct dma_fence **fence);
84d38ceaf9SAlex Deucher void amdgpu_uvd_free_handles(struct amdgpu_device *adev,
85d38ceaf9SAlex Deucher 			     struct drm_file *filp);
86cdc7893fSChristian König int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser,
87cdc7893fSChristian König 			     struct amdgpu_job *job,
88cdc7893fSChristian König 			     struct amdgpu_ib *ib);
89c4120d55SChristian König void amdgpu_uvd_ring_begin_use(struct amdgpu_ring *ring);
90c4120d55SChristian König void amdgpu_uvd_ring_end_use(struct amdgpu_ring *ring);
91bbec97aaSChristian König int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout);
9244879b62SArindam Nath uint32_t amdgpu_uvd_used_handles(struct amdgpu_device *adev);
93d38ceaf9SAlex Deucher 
94d38ceaf9SAlex Deucher #endif
95