xref: /openbsd/sys/dev/pci/drm/amd/amdgpu/vcn_sw_ring.c (revision f005ef32)
11bb76ff1Sjsg /*
21bb76ff1Sjsg  * Copyright 2022 Advanced Micro Devices, Inc.
31bb76ff1Sjsg  *
41bb76ff1Sjsg  * Permission is hereby granted, free of charge, to any person obtaining a
51bb76ff1Sjsg  * copy of this software and associated documentation files (the "Software"),
61bb76ff1Sjsg  * to deal in the Software without restriction, including without limitation
71bb76ff1Sjsg  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81bb76ff1Sjsg  * and/or sell copies of the Software, and to permit persons to whom the
91bb76ff1Sjsg  * Software is furnished to do so, subject to the following conditions:
101bb76ff1Sjsg  *
111bb76ff1Sjsg  * The above copyright notice and this permission notice shall be included in
121bb76ff1Sjsg  * all copies or substantial portions of the Software.
131bb76ff1Sjsg  *
141bb76ff1Sjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
151bb76ff1Sjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
161bb76ff1Sjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
171bb76ff1Sjsg  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
181bb76ff1Sjsg  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
191bb76ff1Sjsg  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
201bb76ff1Sjsg  * OTHER DEALINGS IN THE SOFTWARE.
211bb76ff1Sjsg  *
221bb76ff1Sjsg  */
231bb76ff1Sjsg 
241bb76ff1Sjsg #include "amdgpu.h"
251bb76ff1Sjsg #include "vcn_sw_ring.h"
261bb76ff1Sjsg 
vcn_dec_sw_ring_emit_fence(struct amdgpu_ring * ring,u64 addr,u64 seq,uint32_t flags)271bb76ff1Sjsg void vcn_dec_sw_ring_emit_fence(struct amdgpu_ring *ring, u64 addr,
281bb76ff1Sjsg 	u64 seq, uint32_t flags)
291bb76ff1Sjsg {
301bb76ff1Sjsg 	WARN_ON(flags & AMDGPU_FENCE_FLAG_64BIT);
311bb76ff1Sjsg 
321bb76ff1Sjsg 	amdgpu_ring_write(ring, VCN_DEC_SW_CMD_FENCE);
331bb76ff1Sjsg 	amdgpu_ring_write(ring, addr);
341bb76ff1Sjsg 	amdgpu_ring_write(ring, upper_32_bits(addr));
351bb76ff1Sjsg 	amdgpu_ring_write(ring, seq);
361bb76ff1Sjsg 	amdgpu_ring_write(ring, VCN_DEC_SW_CMD_TRAP);
371bb76ff1Sjsg }
381bb76ff1Sjsg 
vcn_dec_sw_ring_insert_end(struct amdgpu_ring * ring)391bb76ff1Sjsg void vcn_dec_sw_ring_insert_end(struct amdgpu_ring *ring)
401bb76ff1Sjsg {
411bb76ff1Sjsg 	amdgpu_ring_write(ring, VCN_DEC_SW_CMD_END);
421bb76ff1Sjsg }
431bb76ff1Sjsg 
vcn_dec_sw_ring_emit_ib(struct amdgpu_ring * ring,struct amdgpu_job * job,struct amdgpu_ib * ib,uint32_t flags)441bb76ff1Sjsg void vcn_dec_sw_ring_emit_ib(struct amdgpu_ring *ring, struct amdgpu_job *job,
451bb76ff1Sjsg 	struct amdgpu_ib *ib, uint32_t flags)
461bb76ff1Sjsg {
471bb76ff1Sjsg 	uint32_t vmid = AMDGPU_JOB_GET_VMID(job);
481bb76ff1Sjsg 
491bb76ff1Sjsg 	amdgpu_ring_write(ring, VCN_DEC_SW_CMD_IB);
501bb76ff1Sjsg 	amdgpu_ring_write(ring, vmid);
511bb76ff1Sjsg 	amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr));
521bb76ff1Sjsg 	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
531bb76ff1Sjsg 	amdgpu_ring_write(ring, ib->length_dw);
541bb76ff1Sjsg }
551bb76ff1Sjsg 
vcn_dec_sw_ring_emit_reg_wait(struct amdgpu_ring * ring,uint32_t reg,uint32_t val,uint32_t mask)561bb76ff1Sjsg void vcn_dec_sw_ring_emit_reg_wait(struct amdgpu_ring *ring, uint32_t reg,
571bb76ff1Sjsg 	uint32_t val, uint32_t mask)
581bb76ff1Sjsg {
591bb76ff1Sjsg 	amdgpu_ring_write(ring, VCN_DEC_SW_CMD_REG_WAIT);
601bb76ff1Sjsg 	amdgpu_ring_write(ring, reg << 2);
611bb76ff1Sjsg 	amdgpu_ring_write(ring, mask);
621bb76ff1Sjsg 	amdgpu_ring_write(ring, val);
631bb76ff1Sjsg }
641bb76ff1Sjsg 
vcn_dec_sw_ring_emit_vm_flush(struct amdgpu_ring * ring,uint32_t vmid,uint64_t pd_addr)651bb76ff1Sjsg void vcn_dec_sw_ring_emit_vm_flush(struct amdgpu_ring *ring,
661bb76ff1Sjsg 	uint32_t vmid, uint64_t pd_addr)
671bb76ff1Sjsg {
68*f005ef32Sjsg 	struct amdgpu_vmhub *hub = &ring->adev->vmhub[ring->vm_hub];
691bb76ff1Sjsg 	uint32_t data0, data1, mask;
701bb76ff1Sjsg 
711bb76ff1Sjsg 	pd_addr = amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
721bb76ff1Sjsg 
731bb76ff1Sjsg 	/* wait for register write */
741bb76ff1Sjsg 	data0 = hub->ctx0_ptb_addr_lo32 + vmid * hub->ctx_addr_distance;
751bb76ff1Sjsg 	data1 = lower_32_bits(pd_addr);
761bb76ff1Sjsg 	mask = 0xffffffff;
771bb76ff1Sjsg 	vcn_dec_sw_ring_emit_reg_wait(ring, data0, data1, mask);
781bb76ff1Sjsg }
791bb76ff1Sjsg 
vcn_dec_sw_ring_emit_wreg(struct amdgpu_ring * ring,uint32_t reg,uint32_t val)801bb76ff1Sjsg void vcn_dec_sw_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,
811bb76ff1Sjsg 	uint32_t val)
821bb76ff1Sjsg {
831bb76ff1Sjsg 	amdgpu_ring_write(ring, VCN_DEC_SW_CMD_REG_WRITE);
841bb76ff1Sjsg 	amdgpu_ring_write(ring,	reg << 2);
851bb76ff1Sjsg 	amdgpu_ring_write(ring, val);
861bb76ff1Sjsg }
87