1 1.1 riastrad /* $NetBSD: amdgpu_uvd.h,v 1.3 2021/12/18 23:44:58 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2014 Advanced Micro Devices, Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad */ 25 1.1 riastrad 26 1.1 riastrad #ifndef __AMDGPU_UVD_H__ 27 1.1 riastrad #define __AMDGPU_UVD_H__ 28 1.1 riastrad 29 1.3 riastrad #define AMDGPU_DEFAULT_UVD_HANDLES 10 30 1.3 riastrad #define AMDGPU_MAX_UVD_HANDLES 40 31 1.3 riastrad #define AMDGPU_UVD_STACK_SIZE (200*1024) 32 1.3 riastrad #define AMDGPU_UVD_HEAP_SIZE (256*1024) 33 1.3 riastrad #define AMDGPU_UVD_SESSION_SIZE (50*1024) 34 1.3 riastrad #define AMDGPU_UVD_FIRMWARE_OFFSET 256 35 1.3 riastrad 36 1.3 riastrad #define AMDGPU_MAX_UVD_INSTANCES 2 37 1.3 riastrad 38 1.3 riastrad #define AMDGPU_UVD_FIRMWARE_SIZE(adev) \ 39 1.3 riastrad (AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(((const struct common_firmware_header *)(adev)->uvd.fw->data)->ucode_size_bytes) + \ 40 1.3 riastrad 8) - AMDGPU_UVD_FIRMWARE_OFFSET) 41 1.3 riastrad 42 1.3 riastrad struct amdgpu_uvd_inst { 43 1.3 riastrad struct amdgpu_bo *vcpu_bo; 44 1.3 riastrad void *cpu_addr; 45 1.3 riastrad uint64_t gpu_addr; 46 1.3 riastrad void *saved_bo; 47 1.3 riastrad struct amdgpu_ring ring; 48 1.3 riastrad struct amdgpu_ring ring_enc[AMDGPU_MAX_UVD_ENC_RINGS]; 49 1.3 riastrad struct amdgpu_irq_src irq; 50 1.3 riastrad uint32_t srbm_soft_reset; 51 1.3 riastrad }; 52 1.3 riastrad 53 1.3 riastrad #define AMDGPU_UVD_HARVEST_UVD0 (1 << 0) 54 1.3 riastrad #define AMDGPU_UVD_HARVEST_UVD1 (1 << 1) 55 1.3 riastrad 56 1.3 riastrad struct amdgpu_uvd { 57 1.3 riastrad const struct firmware *fw; /* UVD firmware */ 58 1.3 riastrad unsigned fw_version; 59 1.3 riastrad unsigned max_handles; 60 1.3 riastrad unsigned num_enc_rings; 61 1.3 riastrad uint8_t num_uvd_inst; 62 1.3 riastrad bool address_64_bit; 63 1.3 riastrad bool use_ctx_buf; 64 1.3 riastrad struct amdgpu_uvd_inst inst[AMDGPU_MAX_UVD_INSTANCES]; 65 1.3 riastrad struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES]; 66 1.3 riastrad atomic_t handles[AMDGPU_MAX_UVD_HANDLES]; 67 1.3 riastrad struct drm_sched_entity entity; 68 1.3 riastrad struct delayed_work idle_work; 69 1.3 riastrad unsigned harvest_config; 70 1.3 riastrad /* store image width to adjust nb memory state */ 71 1.3 riastrad unsigned decode_image_width; 72 1.3 riastrad }; 73 1.3 riastrad 74 1.1 riastrad int amdgpu_uvd_sw_init(struct amdgpu_device *adev); 75 1.1 riastrad int amdgpu_uvd_sw_fini(struct amdgpu_device *adev); 76 1.3 riastrad int amdgpu_uvd_entity_init(struct amdgpu_device *adev); 77 1.1 riastrad int amdgpu_uvd_suspend(struct amdgpu_device *adev); 78 1.1 riastrad int amdgpu_uvd_resume(struct amdgpu_device *adev); 79 1.1 riastrad int amdgpu_uvd_get_create_msg(struct amdgpu_ring *ring, uint32_t handle, 80 1.3 riastrad struct dma_fence **fence); 81 1.1 riastrad int amdgpu_uvd_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle, 82 1.3 riastrad bool direct, struct dma_fence **fence); 83 1.1 riastrad void amdgpu_uvd_free_handles(struct amdgpu_device *adev, 84 1.1 riastrad struct drm_file *filp); 85 1.1 riastrad int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx); 86 1.3 riastrad void amdgpu_uvd_ring_begin_use(struct amdgpu_ring *ring); 87 1.3 riastrad void amdgpu_uvd_ring_end_use(struct amdgpu_ring *ring); 88 1.3 riastrad int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout); 89 1.3 riastrad uint32_t amdgpu_uvd_used_handles(struct amdgpu_device *adev); 90 1.1 riastrad 91 1.1 riastrad #endif 92