18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef __AMDGPU_UVD_H__
258c2ecf20Sopenharmony_ci#define __AMDGPU_UVD_H__
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define AMDGPU_DEFAULT_UVD_HANDLES	10
288c2ecf20Sopenharmony_ci#define AMDGPU_MAX_UVD_HANDLES		40
298c2ecf20Sopenharmony_ci#define AMDGPU_UVD_STACK_SIZE		(200*1024)
308c2ecf20Sopenharmony_ci#define AMDGPU_UVD_HEAP_SIZE		(256*1024)
318c2ecf20Sopenharmony_ci#define AMDGPU_UVD_SESSION_SIZE		(50*1024)
328c2ecf20Sopenharmony_ci#define AMDGPU_UVD_FIRMWARE_OFFSET	256
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define AMDGPU_MAX_UVD_INSTANCES			2
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define AMDGPU_UVD_FIRMWARE_SIZE(adev)    \
378c2ecf20Sopenharmony_ci	(AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(((const struct common_firmware_header *)(adev)->uvd.fw->data)->ucode_size_bytes) + \
388c2ecf20Sopenharmony_ci			       8) - AMDGPU_UVD_FIRMWARE_OFFSET)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct amdgpu_uvd_inst {
418c2ecf20Sopenharmony_ci	struct amdgpu_bo	*vcpu_bo;
428c2ecf20Sopenharmony_ci	void			*cpu_addr;
438c2ecf20Sopenharmony_ci	uint64_t		gpu_addr;
448c2ecf20Sopenharmony_ci	void			*saved_bo;
458c2ecf20Sopenharmony_ci	struct amdgpu_ring	ring;
468c2ecf20Sopenharmony_ci	struct amdgpu_ring	ring_enc[AMDGPU_MAX_UVD_ENC_RINGS];
478c2ecf20Sopenharmony_ci	struct amdgpu_irq_src	irq;
488c2ecf20Sopenharmony_ci	uint32_t                srbm_soft_reset;
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define AMDGPU_UVD_HARVEST_UVD0 (1 << 0)
528c2ecf20Sopenharmony_ci#define AMDGPU_UVD_HARVEST_UVD1 (1 << 1)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct amdgpu_uvd {
558c2ecf20Sopenharmony_ci	const struct firmware	*fw;	/* UVD firmware */
568c2ecf20Sopenharmony_ci	unsigned		fw_version;
578c2ecf20Sopenharmony_ci	unsigned		max_handles;
588c2ecf20Sopenharmony_ci	unsigned		num_enc_rings;
598c2ecf20Sopenharmony_ci	uint8_t			num_uvd_inst;
608c2ecf20Sopenharmony_ci	bool			address_64_bit;
618c2ecf20Sopenharmony_ci	bool			use_ctx_buf;
628c2ecf20Sopenharmony_ci	struct amdgpu_uvd_inst	inst[AMDGPU_MAX_UVD_INSTANCES];
638c2ecf20Sopenharmony_ci	struct drm_file		*filp[AMDGPU_MAX_UVD_HANDLES];
648c2ecf20Sopenharmony_ci	atomic_t		handles[AMDGPU_MAX_UVD_HANDLES];
658c2ecf20Sopenharmony_ci	struct drm_sched_entity entity;
668c2ecf20Sopenharmony_ci	struct delayed_work	idle_work;
678c2ecf20Sopenharmony_ci	unsigned		harvest_config;
688c2ecf20Sopenharmony_ci	/* store image width to adjust nb memory state */
698c2ecf20Sopenharmony_ci	unsigned		decode_image_width;
708c2ecf20Sopenharmony_ci	uint32_t                keyselect;
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciint amdgpu_uvd_sw_init(struct amdgpu_device *adev);
748c2ecf20Sopenharmony_ciint amdgpu_uvd_sw_fini(struct amdgpu_device *adev);
758c2ecf20Sopenharmony_ciint amdgpu_uvd_entity_init(struct amdgpu_device *adev);
768c2ecf20Sopenharmony_ciint amdgpu_uvd_suspend(struct amdgpu_device *adev);
778c2ecf20Sopenharmony_ciint amdgpu_uvd_resume(struct amdgpu_device *adev);
788c2ecf20Sopenharmony_ciint amdgpu_uvd_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
798c2ecf20Sopenharmony_ci			      struct dma_fence **fence);
808c2ecf20Sopenharmony_ciint amdgpu_uvd_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
818c2ecf20Sopenharmony_ci			       bool direct, struct dma_fence **fence);
828c2ecf20Sopenharmony_civoid amdgpu_uvd_free_handles(struct amdgpu_device *adev,
838c2ecf20Sopenharmony_ci			     struct drm_file *filp);
848c2ecf20Sopenharmony_ciint amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx);
858c2ecf20Sopenharmony_civoid amdgpu_uvd_ring_begin_use(struct amdgpu_ring *ring);
868c2ecf20Sopenharmony_civoid amdgpu_uvd_ring_end_use(struct amdgpu_ring *ring);
878c2ecf20Sopenharmony_ciint amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout);
888c2ecf20Sopenharmony_ciuint32_t amdgpu_uvd_used_handles(struct amdgpu_device *adev);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#endif
91