1*f005ef32Sjsg /* 2*f005ef32Sjsg * Copyright 2022 Advanced Micro Devices, Inc. 3*f005ef32Sjsg * 4*f005ef32Sjsg * Permission is hereby granted, free of charge, to any person obtaining a 5*f005ef32Sjsg * copy of this software and associated documentation files (the "Software"), 6*f005ef32Sjsg * to deal in the Software without restriction, including without limitation 7*f005ef32Sjsg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*f005ef32Sjsg * and/or sell copies of the Software, and to permit persons to whom the 9*f005ef32Sjsg * Software is furnished to do so, subject to the following conditions: 10*f005ef32Sjsg * 11*f005ef32Sjsg * The above copyright notice and this permission notice shall be included in 12*f005ef32Sjsg * all copies or substantial portions of the Software. 13*f005ef32Sjsg * 14*f005ef32Sjsg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*f005ef32Sjsg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*f005ef32Sjsg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17*f005ef32Sjsg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18*f005ef32Sjsg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19*f005ef32Sjsg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20*f005ef32Sjsg * OTHER DEALINGS IN THE SOFTWARE. 21*f005ef32Sjsg * 22*f005ef32Sjsg */ 23*f005ef32Sjsg 24*f005ef32Sjsg #ifndef __AMDGPU_RING_MUX__ 25*f005ef32Sjsg #define __AMDGPU_RING_MUX__ 26*f005ef32Sjsg 27*f005ef32Sjsg #include <linux/timer.h> 28*f005ef32Sjsg #include <linux/spinlock.h> 29*f005ef32Sjsg #include "amdgpu_ring.h" 30*f005ef32Sjsg 31*f005ef32Sjsg struct amdgpu_ring; 32*f005ef32Sjsg 33*f005ef32Sjsg /** 34*f005ef32Sjsg * struct amdgpu_mux_entry - the entry recording software rings copying information. 35*f005ef32Sjsg * @ring: the pointer to the software ring. 36*f005ef32Sjsg * @start_ptr_in_hw_ring: last start location copied to in the hardware ring. 37*f005ef32Sjsg * @end_ptr_in_hw_ring: last end location copied to in the hardware ring. 38*f005ef32Sjsg * @sw_cptr: the position of the copy pointer in the sw ring. 39*f005ef32Sjsg * @sw_rptr: the read pointer in software ring. 40*f005ef32Sjsg * @sw_wptr: the write pointer in software ring. 41*f005ef32Sjsg * @list: list head for amdgpu_mux_chunk 42*f005ef32Sjsg */ 43*f005ef32Sjsg struct amdgpu_mux_entry { 44*f005ef32Sjsg struct amdgpu_ring *ring; 45*f005ef32Sjsg u64 start_ptr_in_hw_ring; 46*f005ef32Sjsg u64 end_ptr_in_hw_ring; 47*f005ef32Sjsg u64 sw_cptr; 48*f005ef32Sjsg u64 sw_rptr; 49*f005ef32Sjsg u64 sw_wptr; 50*f005ef32Sjsg struct list_head list; 51*f005ef32Sjsg }; 52*f005ef32Sjsg 53*f005ef32Sjsg enum amdgpu_ring_mux_offset_type { 54*f005ef32Sjsg AMDGPU_MUX_OFFSET_TYPE_CONTROL, 55*f005ef32Sjsg AMDGPU_MUX_OFFSET_TYPE_DE, 56*f005ef32Sjsg AMDGPU_MUX_OFFSET_TYPE_CE, 57*f005ef32Sjsg }; 58*f005ef32Sjsg 59*f005ef32Sjsg enum ib_complete_status { 60*f005ef32Sjsg /* IB not started/reset value, default value. */ 61*f005ef32Sjsg IB_COMPLETION_STATUS_DEFAULT = 0, 62*f005ef32Sjsg /* IB preempted, started but not completed. */ 63*f005ef32Sjsg IB_COMPLETION_STATUS_PREEMPTED = 1, 64*f005ef32Sjsg /* IB completed. */ 65*f005ef32Sjsg IB_COMPLETION_STATUS_COMPLETED = 2, 66*f005ef32Sjsg }; 67*f005ef32Sjsg 68*f005ef32Sjsg struct amdgpu_ring_mux { 69*f005ef32Sjsg struct amdgpu_ring *real_ring; 70*f005ef32Sjsg 71*f005ef32Sjsg struct amdgpu_mux_entry *ring_entry; 72*f005ef32Sjsg unsigned int num_ring_entries; 73*f005ef32Sjsg unsigned int ring_entry_size; 74*f005ef32Sjsg /*the lock for copy data from different software rings*/ 75*f005ef32Sjsg spinlock_t lock; 76*f005ef32Sjsg bool s_resubmit; 77*f005ef32Sjsg uint32_t seqno_to_resubmit; 78*f005ef32Sjsg u64 wptr_resubmit; 79*f005ef32Sjsg struct timeout resubmit_timer; 80*f005ef32Sjsg 81*f005ef32Sjsg bool pending_trailing_fence_signaled; 82*f005ef32Sjsg }; 83*f005ef32Sjsg 84*f005ef32Sjsg /** 85*f005ef32Sjsg * struct amdgpu_mux_chunk - save the location of indirect buffer's package on softare rings. 86*f005ef32Sjsg * @entry: the list entry. 87*f005ef32Sjsg * @sync_seq: the fence seqno related with the saved IB. 88*f005ef32Sjsg * @start:- start location on the software ring. 89*f005ef32Sjsg * @end:- end location on the software ring. 90*f005ef32Sjsg * @control_offset:- the PRE_RESUME bit position used for resubmission. 91*f005ef32Sjsg * @de_offset:- the anchor in write_data for de meta of resubmission. 92*f005ef32Sjsg * @ce_offset:- the anchor in write_data for ce meta of resubmission. 93*f005ef32Sjsg */ 94*f005ef32Sjsg struct amdgpu_mux_chunk { 95*f005ef32Sjsg struct list_head entry; 96*f005ef32Sjsg uint32_t sync_seq; 97*f005ef32Sjsg u64 start; 98*f005ef32Sjsg u64 end; 99*f005ef32Sjsg u64 cntl_offset; 100*f005ef32Sjsg u64 de_offset; 101*f005ef32Sjsg u64 ce_offset; 102*f005ef32Sjsg }; 103*f005ef32Sjsg 104*f005ef32Sjsg int amdgpu_ring_mux_init(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring, 105*f005ef32Sjsg unsigned int entry_size); 106*f005ef32Sjsg void amdgpu_ring_mux_fini(struct amdgpu_ring_mux *mux); 107*f005ef32Sjsg int amdgpu_ring_mux_add_sw_ring(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring); 108*f005ef32Sjsg void amdgpu_ring_mux_set_wptr(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring, u64 wptr); 109*f005ef32Sjsg u64 amdgpu_ring_mux_get_wptr(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring); 110*f005ef32Sjsg u64 amdgpu_ring_mux_get_rptr(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring); 111*f005ef32Sjsg void amdgpu_ring_mux_start_ib(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring); 112*f005ef32Sjsg void amdgpu_ring_mux_end_ib(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring); 113*f005ef32Sjsg void amdgpu_ring_mux_ib_mark_offset(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring, 114*f005ef32Sjsg u64 offset, enum amdgpu_ring_mux_offset_type type); 115*f005ef32Sjsg bool amdgpu_mcbp_handle_trailing_fence_irq(struct amdgpu_ring_mux *mux); 116*f005ef32Sjsg 117*f005ef32Sjsg u64 amdgpu_sw_ring_get_rptr_gfx(struct amdgpu_ring *ring); 118*f005ef32Sjsg u64 amdgpu_sw_ring_get_wptr_gfx(struct amdgpu_ring *ring); 119*f005ef32Sjsg void amdgpu_sw_ring_set_wptr_gfx(struct amdgpu_ring *ring); 120*f005ef32Sjsg void amdgpu_sw_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count); 121*f005ef32Sjsg void amdgpu_sw_ring_ib_begin(struct amdgpu_ring *ring); 122*f005ef32Sjsg void amdgpu_sw_ring_ib_end(struct amdgpu_ring *ring); 123*f005ef32Sjsg void amdgpu_sw_ring_ib_mark_offset(struct amdgpu_ring *ring, enum amdgpu_ring_mux_offset_type type); 124*f005ef32Sjsg const char *amdgpu_sw_ring_name(int idx); 125*f005ef32Sjsg unsigned int amdgpu_sw_ring_priority(int idx); 126*f005ef32Sjsg 127*f005ef32Sjsg #endif 128