Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: add amdgpu_jpeg and JPEG tests

It will be used for all versions of JPEG eventually. Previous
JPEG tests will be removed later since they are still used by
JPEG2.x.

Signed-off-by: Leo Liu <leo.liu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Leo Liu and committed by
Alex Deucher
9d9cc9b8 88a1c40a

+141 -2
+3 -2
drivers/gpu/drm/amd/amdgpu/Makefile
··· 147 147 vce_v3_0.o \ 148 148 vce_v4_0.o 149 149 150 - # add VCN block 150 + # add VCN and JPEG block 151 151 amdgpu-y += \ 152 152 amdgpu_vcn.o \ 153 153 vcn_v1_0.o \ 154 154 vcn_v2_0.o \ 155 - vcn_v2_5.o 155 + vcn_v2_5.o \ 156 + amdgpu_jpeg.o 156 157 157 158 # add ATHUB block 158 159 amdgpu-y += \
+135
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
··· 1 + /* 2 + * Copyright 2019 Advanced Micro Devices, Inc. 3 + * All Rights Reserved. 4 + * 5 + * Permission is hereby granted, free of charge, to any person obtaining a 6 + * copy of this software and associated documentation files (the 7 + * "Software"), to deal in the Software without restriction, including 8 + * without limitation the rights to use, copy, modify, merge, publish, 9 + * distribute, sub license, and/or sell copies of the Software, and to 10 + * permit persons to whom the Software is furnished to do so, subject to 11 + * the following conditions: 12 + * 13 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 16 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 17 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 18 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 19 + * USE OR OTHER DEALINGS IN THE SOFTWARE. 20 + * 21 + * The above copyright notice and this permission notice (including the 22 + * next paragraph) shall be included in all copies or substantial portions 23 + * of the Software. 24 + * 25 + */ 26 + 27 + #include "amdgpu.h" 28 + #include "amdgpu_jpeg.h" 29 + #include "soc15d.h" 30 + #include "soc15_common.h" 31 + 32 + int amdgpu_jpeg_dec_ring_test_ring(struct amdgpu_ring *ring) 33 + { 34 + struct amdgpu_device *adev = ring->adev; 35 + uint32_t tmp = 0; 36 + unsigned i; 37 + int r; 38 + 39 + WREG32(adev->jpeg.inst[ring->me].external.jpeg_pitch, 0xCAFEDEAD); 40 + r = amdgpu_ring_alloc(ring, 3); 41 + if (r) 42 + return r; 43 + 44 + amdgpu_ring_write(ring, PACKET0(adev->jpeg.internal.jpeg_pitch, 0)); 45 + amdgpu_ring_write(ring, 0xDEADBEEF); 46 + amdgpu_ring_commit(ring); 47 + 48 + for (i = 0; i < adev->usec_timeout; i++) { 49 + tmp = RREG32(adev->jpeg.inst[ring->me].external.jpeg_pitch); 50 + if (tmp == 0xDEADBEEF) 51 + break; 52 + udelay(1); 53 + } 54 + 55 + if (i >= adev->usec_timeout) 56 + r = -ETIMEDOUT; 57 + 58 + return r; 59 + } 60 + 61 + static int amdgpu_jpeg_dec_set_reg(struct amdgpu_ring *ring, uint32_t handle, 62 + struct dma_fence **fence) 63 + { 64 + struct amdgpu_device *adev = ring->adev; 65 + struct amdgpu_job *job; 66 + struct amdgpu_ib *ib; 67 + struct dma_fence *f = NULL; 68 + const unsigned ib_size_dw = 16; 69 + int i, r; 70 + 71 + r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4, &job); 72 + if (r) 73 + return r; 74 + 75 + ib = &job->ibs[0]; 76 + 77 + ib->ptr[0] = PACKETJ(adev->jpeg.internal.jpeg_pitch, 0, 0, PACKETJ_TYPE0); 78 + ib->ptr[1] = 0xDEADBEEF; 79 + for (i = 2; i < 16; i += 2) { 80 + ib->ptr[i] = PACKETJ(0, 0, 0, PACKETJ_TYPE6); 81 + ib->ptr[i+1] = 0; 82 + } 83 + ib->length_dw = 16; 84 + 85 + r = amdgpu_job_submit_direct(job, ring, &f); 86 + if (r) 87 + goto err; 88 + 89 + if (fence) 90 + *fence = dma_fence_get(f); 91 + dma_fence_put(f); 92 + 93 + return 0; 94 + 95 + err: 96 + amdgpu_job_free(job); 97 + return r; 98 + } 99 + 100 + int amdgpu_jpeg_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout) 101 + { 102 + struct amdgpu_device *adev = ring->adev; 103 + uint32_t tmp = 0; 104 + unsigned i; 105 + struct dma_fence *fence = NULL; 106 + long r = 0; 107 + 108 + r = amdgpu_jpeg_dec_set_reg(ring, 1, &fence); 109 + if (r) 110 + goto error; 111 + 112 + r = dma_fence_wait_timeout(fence, false, timeout); 113 + if (r == 0) { 114 + r = -ETIMEDOUT; 115 + goto error; 116 + } else if (r < 0) { 117 + goto error; 118 + } else { 119 + r = 0; 120 + } 121 + 122 + for (i = 0; i < adev->usec_timeout; i++) { 123 + tmp = RREG32(adev->jpeg.inst[ring->me].external.jpeg_pitch); 124 + if (tmp == 0xDEADBEEF) 125 + break; 126 + udelay(1); 127 + } 128 + 129 + if (i >= adev->usec_timeout) 130 + r = -ETIMEDOUT; 131 + 132 + dma_fence_put(fence); 133 + error: 134 + return r; 135 + }
+3
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.h
··· 43 43 unsigned harvest_config; 44 44 }; 45 45 46 + int amdgpu_jpeg_dec_ring_test_ring(struct amdgpu_ring *ring); 47 + int amdgpu_jpeg_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout); 48 + 46 49 #endif /*__AMDGPU_JPEG_H__*/