1bb7743bcSHuang Rui /* 2bb7743bcSHuang Rui * Copyright 2018 Advanced Micro Devices, Inc. 3bb7743bcSHuang Rui * 4bb7743bcSHuang Rui * Permission is hereby granted, free of charge, to any person obtaining a 5bb7743bcSHuang Rui * copy of this software and associated documentation files (the "Software"), 6bb7743bcSHuang Rui * to deal in the Software without restriction, including without limitation 7bb7743bcSHuang Rui * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bb7743bcSHuang Rui * and/or sell copies of the Software, and to permit persons to whom the 9bb7743bcSHuang Rui * Software is furnished to do so, subject to the following conditions: 10bb7743bcSHuang Rui * 11bb7743bcSHuang Rui * The above copyright notice and this permission notice shall be included in 12bb7743bcSHuang Rui * all copies or substantial portions of the Software. 13bb7743bcSHuang Rui * 14bb7743bcSHuang Rui * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bb7743bcSHuang Rui * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bb7743bcSHuang Rui * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17bb7743bcSHuang Rui * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18bb7743bcSHuang Rui * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19bb7743bcSHuang Rui * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20bb7743bcSHuang Rui * OTHER DEALINGS IN THE SOFTWARE. 21bb7743bcSHuang Rui * 22bb7743bcSHuang Rui */ 23bb7743bcSHuang Rui 24bb7743bcSHuang Rui #ifndef __AMDGPU_SDMA_H__ 25bb7743bcSHuang Rui #define __AMDGPU_SDMA_H__ 26bdc4292bSyipechai #include "amdgpu_ras.h" 27bb7743bcSHuang Rui 28bb7743bcSHuang Rui /* max number of IP instances */ 29386ea27cSLe Ma #define AMDGPU_MAX_SDMA_INSTANCES 16 30bb7743bcSHuang Rui 31bb7743bcSHuang Rui enum amdgpu_sdma_irq { 32af67772dSEmily Deng AMDGPU_SDMA_IRQ_INSTANCE0 = 0, 33af67772dSEmily Deng AMDGPU_SDMA_IRQ_INSTANCE1, 34667a4822SLe Ma AMDGPU_SDMA_IRQ_INSTANCE2, 35667a4822SLe Ma AMDGPU_SDMA_IRQ_INSTANCE3, 36667a4822SLe Ma AMDGPU_SDMA_IRQ_INSTANCE4, 37667a4822SLe Ma AMDGPU_SDMA_IRQ_INSTANCE5, 38667a4822SLe Ma AMDGPU_SDMA_IRQ_INSTANCE6, 39667a4822SLe Ma AMDGPU_SDMA_IRQ_INSTANCE7, 40f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE8, 41f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE9, 42f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE10, 43f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE11, 44f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE12, 45f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE13, 46f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE14, 47f786b1d4SLe Ma AMDGPU_SDMA_IRQ_INSTANCE15, 48bb7743bcSHuang Rui AMDGPU_SDMA_IRQ_LAST 49bb7743bcSHuang Rui }; 50bb7743bcSHuang Rui 514db6f200SLijo Lazar #define NUM_SDMA(x) hweight32(x) 524db6f200SLijo Lazar 53bb7743bcSHuang Rui struct amdgpu_sdma_instance { 54bb7743bcSHuang Rui /* SDMA firmware */ 55bb7743bcSHuang Rui const struct firmware *fw; 56bb7743bcSHuang Rui uint32_t fw_version; 57bb7743bcSHuang Rui uint32_t feature_version; 58bb7743bcSHuang Rui 59bb7743bcSHuang Rui struct amdgpu_ring ring; 609194a339SChristian König struct amdgpu_ring page; 61bb7743bcSHuang Rui bool burst_nop; 62386ea27cSLe Ma uint32_t aid_id; 63bb7743bcSHuang Rui }; 64bb7743bcSHuang Rui 65*dc37a919SHawking Zhang enum amdgpu_sdma_ras_memory_id { 66*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF0 = 1, 67*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF1 = 2, 68*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF2 = 3, 69*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF3 = 4, 70*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF4 = 5, 71*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF5 = 6, 72*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF6 = 7, 73*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF7 = 8, 74*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF8 = 9, 75*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF9 = 10, 76*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF10 = 11, 77*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF11 = 12, 78*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF12 = 13, 79*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF13 = 14, 80*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF14 = 15, 81*dc37a919SHawking Zhang AMDGPU_SDMA_MBANK_DATA_BUF15 = 16, 82*dc37a919SHawking Zhang AMDGPU_SDMA_UCODE_BUF = 17, 83*dc37a919SHawking Zhang AMDGPU_SDMA_RB_CMD_BUF = 18, 84*dc37a919SHawking Zhang AMDGPU_SDMA_IB_CMD_BUF = 19, 85*dc37a919SHawking Zhang AMDGPU_SDMA_UTCL1_RD_FIFO = 20, 86*dc37a919SHawking Zhang AMDGPU_SDMA_UTCL1_RDBST_FIFO = 21, 87*dc37a919SHawking Zhang AMDGPU_SDMA_UTCL1_WR_FIFO = 22, 88*dc37a919SHawking Zhang AMDGPU_SDMA_DATA_LUT_FIFO = 23, 89*dc37a919SHawking Zhang AMDGPU_SDMA_SPLIT_DAT_BUF = 24, 90*dc37a919SHawking Zhang AMDGPU_SDMA_MEMORY_BLOCK_LAST, 91*dc37a919SHawking Zhang }; 92*dc37a919SHawking Zhang 93bdc4292bSyipechai struct amdgpu_sdma_ras { 94bdc4292bSyipechai struct amdgpu_ras_block_object ras_block; 9593070debSHawking Zhang }; 9693070debSHawking Zhang 97bb7743bcSHuang Rui struct amdgpu_sdma { 98bb7743bcSHuang Rui struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES]; 99bb7743bcSHuang Rui struct amdgpu_irq_src trap_irq; 100bb7743bcSHuang Rui struct amdgpu_irq_src illegal_inst_irq; 1018cf12507Sxinhui pan struct amdgpu_irq_src ecc_irq; 1028f211fe8SFeifei Xu struct amdgpu_irq_src vm_hole_irq; 1038f211fe8SFeifei Xu struct amdgpu_irq_src doorbell_invalid_irq; 1048f211fe8SFeifei Xu struct amdgpu_irq_src pool_timeout_irq; 1058f211fe8SFeifei Xu struct amdgpu_irq_src srbm_write_irq; 1068f211fe8SFeifei Xu 107bb7743bcSHuang Rui int num_instances; 1084db6f200SLijo Lazar uint32_t sdma_mask; 109386ea27cSLe Ma int num_inst_per_aid; 110bb7743bcSHuang Rui uint32_t srbm_soft_reset; 1112a85e816SAlex Deucher bool has_page_queue; 1128cf12507Sxinhui pan struct ras_common_if *ras_if; 113bdc4292bSyipechai struct amdgpu_sdma_ras *ras; 114bb7743bcSHuang Rui }; 115bb7743bcSHuang Rui 116bb7743bcSHuang Rui /* 117bb7743bcSHuang Rui * Provided by hw blocks that can move/clear data. e.g., gfx or sdma 118bb7743bcSHuang Rui * But currently, we use sdma to move data. 119bb7743bcSHuang Rui */ 120bb7743bcSHuang Rui struct amdgpu_buffer_funcs { 121bb7743bcSHuang Rui /* maximum bytes in a single operation */ 122bb7743bcSHuang Rui uint32_t copy_max_bytes; 123bb7743bcSHuang Rui 124bb7743bcSHuang Rui /* number of dw to reserve per operation */ 125bb7743bcSHuang Rui unsigned copy_num_dw; 126bb7743bcSHuang Rui 127bb7743bcSHuang Rui /* used for buffer migration */ 128bb7743bcSHuang Rui void (*emit_copy_buffer)(struct amdgpu_ib *ib, 129bb7743bcSHuang Rui /* src addr in bytes */ 130bb7743bcSHuang Rui uint64_t src_offset, 131bb7743bcSHuang Rui /* dst addr in bytes */ 132bb7743bcSHuang Rui uint64_t dst_offset, 133bb7743bcSHuang Rui /* number of byte to transfer */ 134be7538ffSAaron Liu uint32_t byte_count, 135be7538ffSAaron Liu bool tmz); 136bb7743bcSHuang Rui 137bb7743bcSHuang Rui /* maximum bytes in a single operation */ 138bb7743bcSHuang Rui uint32_t fill_max_bytes; 139bb7743bcSHuang Rui 140bb7743bcSHuang Rui /* number of dw to reserve per operation */ 141bb7743bcSHuang Rui unsigned fill_num_dw; 142bb7743bcSHuang Rui 143bb7743bcSHuang Rui /* used for buffer clearing */ 144bb7743bcSHuang Rui void (*emit_fill_buffer)(struct amdgpu_ib *ib, 145bb7743bcSHuang Rui /* value to write to memory */ 146bb7743bcSHuang Rui uint32_t src_data, 147bb7743bcSHuang Rui /* dst addr in bytes */ 148bb7743bcSHuang Rui uint64_t dst_offset, 149bb7743bcSHuang Rui /* number of byte to fill */ 150bb7743bcSHuang Rui uint32_t byte_count); 151bb7743bcSHuang Rui }; 152bb7743bcSHuang Rui 153be7538ffSAaron Liu #define amdgpu_emit_copy_buffer(adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t)) 154bb7743bcSHuang Rui #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) 155bb7743bcSHuang Rui 156bb7743bcSHuang Rui struct amdgpu_sdma_instance * 157ccf191f8SRex Zhu amdgpu_sdma_get_instance_from_ring(struct amdgpu_ring *ring); 158f6cffc0dSRex Zhu int amdgpu_sdma_get_index_from_ring(struct amdgpu_ring *ring, uint32_t *index); 159ca1eb732SJack Xiao uint64_t amdgpu_sdma_get_csa_mc_addr(struct amdgpu_ring *ring, unsigned vmid); 160bfcf62c2SHawking Zhang int amdgpu_sdma_ras_late_init(struct amdgpu_device *adev, 1614e9b1fa5Syipechai struct ras_common_if *ras_block); 1624c65dd10STao Zhou int amdgpu_sdma_process_ras_data_cb(struct amdgpu_device *adev, 1634c65dd10STao Zhou void *err_data, 1644c65dd10STao Zhou struct amdgpu_iv_entry *entry); 1654c65dd10STao Zhou int amdgpu_sdma_process_ecc_irq(struct amdgpu_device *adev, 1664c65dd10STao Zhou struct amdgpu_irq_src *source, 1674c65dd10STao Zhou struct amdgpu_iv_entry *entry); 1681336b4e7SMario Limonciello int amdgpu_sdma_init_microcode(struct amdgpu_device *adev, u32 instance, 1691336b4e7SMario Limonciello bool duplicate); 17015aa1305SLikun Gao void amdgpu_sdma_destroy_inst_ctx(struct amdgpu_device *adev, 17115aa1305SLikun Gao bool duplicate); 172571c0536SAlex Deucher void amdgpu_sdma_unset_buffer_funcs_helper(struct amdgpu_device *adev); 173a57b24e1SYiPeng Chai int amdgpu_sdma_ras_sw_init(struct amdgpu_device *adev); 174571c0536SAlex Deucher 175bb7743bcSHuang Rui #endif 176