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

drm/amdgpu: add a generic fb accessing helper function(v3)

add a generic helper function for accessing framebuffer via MMIO

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
Signed-off-by: Tianci.Yin <tianci.yin@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Tianci.Yin and committed by
Alex Deucher
e35e2b11 45cf454e

+33 -11
+2
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 981 981 void amdgpu_device_fini(struct amdgpu_device *adev); 982 982 int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); 983 983 984 + void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos, 985 + uint32_t *buf, size_t size, bool write); 984 986 uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, 985 987 uint32_t acc_flags); 986 988 void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
+30
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
··· 153 153 return false; 154 154 } 155 155 156 + /** 157 + * VRAM access helper functions. 158 + * 159 + * amdgpu_device_vram_access - read/write a buffer in vram 160 + * 161 + * @adev: amdgpu_device pointer 162 + * @pos: offset of the buffer in vram 163 + * @buf: virtual address of the buffer in system memory 164 + * @size: read/write size, sizeof(@buf) must > @size 165 + * @write: true - write to vram, otherwise - read from vram 166 + */ 167 + void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos, 168 + uint32_t *buf, size_t size, bool write) 169 + { 170 + uint64_t last; 171 + unsigned long flags; 172 + 173 + last = size - 4; 174 + for (last += pos; pos <= last; pos += 4) { 175 + spin_lock_irqsave(&adev->mmio_idx_lock, flags); 176 + WREG32_NO_KIQ(mmMM_INDEX, ((uint32_t)pos) | 0x80000000); 177 + WREG32_NO_KIQ(mmMM_INDEX_HI, pos >> 31); 178 + if (write) 179 + WREG32_NO_KIQ(mmMM_DATA, *buf++); 180 + else 181 + *buf++ = RREG32_NO_KIQ(mmMM_DATA); 182 + spin_unlock_irqrestore(&adev->mmio_idx_lock, flags); 183 + } 184 + } 185 + 156 186 /* 157 187 * MMIO register access helper functions. 158 188 */
+1 -11
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
··· 134 134 135 135 static int amdgpu_discovery_read_binary(struct amdgpu_device *adev, uint8_t *binary) 136 136 { 137 - uint32_t *p = (uint32_t *)binary; 138 137 uint64_t vram_size = (uint64_t)RREG32(mmRCC_CONFIG_MEMSIZE) << 20; 139 138 uint64_t pos = vram_size - DISCOVERY_TMR_SIZE; 140 - unsigned long flags; 141 139 142 - while (pos < vram_size) { 143 - spin_lock_irqsave(&adev->mmio_idx_lock, flags); 144 - WREG32_NO_KIQ(mmMM_INDEX, ((uint32_t)pos) | 0x80000000); 145 - WREG32_NO_KIQ(mmMM_INDEX_HI, pos >> 31); 146 - *p++ = RREG32_NO_KIQ(mmMM_DATA); 147 - spin_unlock_irqrestore(&adev->mmio_idx_lock, flags); 148 - pos += 4; 149 - } 150 - 140 + amdgpu_device_vram_access(adev, pos, (uint32_t *)binary, DISCOVERY_TMR_SIZE, false); 151 141 return 0; 152 142 } 153 143