18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2018 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#ifndef __AMDGPU_SDMA_H__ 258c2ecf20Sopenharmony_ci#define __AMDGPU_SDMA_H__ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* max number of IP instances */ 288c2ecf20Sopenharmony_ci#define AMDGPU_MAX_SDMA_INSTANCES 8 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cienum amdgpu_sdma_irq { 318c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE0 = 0, 328c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE1, 338c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE2, 348c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE3, 358c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE4, 368c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE5, 378c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE6, 388c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_INSTANCE7, 398c2ecf20Sopenharmony_ci AMDGPU_SDMA_IRQ_LAST 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistruct amdgpu_sdma_instance { 438c2ecf20Sopenharmony_ci /* SDMA firmware */ 448c2ecf20Sopenharmony_ci const struct firmware *fw; 458c2ecf20Sopenharmony_ci uint32_t fw_version; 468c2ecf20Sopenharmony_ci uint32_t feature_version; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci struct amdgpu_ring ring; 498c2ecf20Sopenharmony_ci struct amdgpu_ring page; 508c2ecf20Sopenharmony_ci bool burst_nop; 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistruct amdgpu_sdma_ras_funcs { 548c2ecf20Sopenharmony_ci int (*ras_late_init)(struct amdgpu_device *adev, 558c2ecf20Sopenharmony_ci void *ras_ih_info); 568c2ecf20Sopenharmony_ci void (*ras_fini)(struct amdgpu_device *adev); 578c2ecf20Sopenharmony_ci int (*query_ras_error_count)(struct amdgpu_device *adev, 588c2ecf20Sopenharmony_ci uint32_t instance, void *ras_error_status); 598c2ecf20Sopenharmony_ci void (*reset_ras_error_count)(struct amdgpu_device *adev); 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistruct amdgpu_sdma { 638c2ecf20Sopenharmony_ci struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES]; 648c2ecf20Sopenharmony_ci struct amdgpu_irq_src trap_irq; 658c2ecf20Sopenharmony_ci struct amdgpu_irq_src illegal_inst_irq; 668c2ecf20Sopenharmony_ci struct amdgpu_irq_src ecc_irq; 678c2ecf20Sopenharmony_ci int num_instances; 688c2ecf20Sopenharmony_ci uint32_t srbm_soft_reset; 698c2ecf20Sopenharmony_ci bool has_page_queue; 708c2ecf20Sopenharmony_ci struct ras_common_if *ras_if; 718c2ecf20Sopenharmony_ci const struct amdgpu_sdma_ras_funcs *funcs; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* 758c2ecf20Sopenharmony_ci * Provided by hw blocks that can move/clear data. e.g., gfx or sdma 768c2ecf20Sopenharmony_ci * But currently, we use sdma to move data. 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_cistruct amdgpu_buffer_funcs { 798c2ecf20Sopenharmony_ci /* maximum bytes in a single operation */ 808c2ecf20Sopenharmony_ci uint32_t copy_max_bytes; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci /* number of dw to reserve per operation */ 838c2ecf20Sopenharmony_ci unsigned copy_num_dw; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci /* used for buffer migration */ 868c2ecf20Sopenharmony_ci void (*emit_copy_buffer)(struct amdgpu_ib *ib, 878c2ecf20Sopenharmony_ci /* src addr in bytes */ 888c2ecf20Sopenharmony_ci uint64_t src_offset, 898c2ecf20Sopenharmony_ci /* dst addr in bytes */ 908c2ecf20Sopenharmony_ci uint64_t dst_offset, 918c2ecf20Sopenharmony_ci /* number of byte to transfer */ 928c2ecf20Sopenharmony_ci uint32_t byte_count, 938c2ecf20Sopenharmony_ci bool tmz); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci /* maximum bytes in a single operation */ 968c2ecf20Sopenharmony_ci uint32_t fill_max_bytes; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci /* number of dw to reserve per operation */ 998c2ecf20Sopenharmony_ci unsigned fill_num_dw; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci /* used for buffer clearing */ 1028c2ecf20Sopenharmony_ci void (*emit_fill_buffer)(struct amdgpu_ib *ib, 1038c2ecf20Sopenharmony_ci /* value to write to memory */ 1048c2ecf20Sopenharmony_ci uint32_t src_data, 1058c2ecf20Sopenharmony_ci /* dst addr in bytes */ 1068c2ecf20Sopenharmony_ci uint64_t dst_offset, 1078c2ecf20Sopenharmony_ci /* number of byte to fill */ 1088c2ecf20Sopenharmony_ci uint32_t byte_count); 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define amdgpu_emit_copy_buffer(adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t)) 1128c2ecf20Sopenharmony_ci#define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistruct amdgpu_sdma_instance * 1158c2ecf20Sopenharmony_ciamdgpu_sdma_get_instance_from_ring(struct amdgpu_ring *ring); 1168c2ecf20Sopenharmony_ciint amdgpu_sdma_get_index_from_ring(struct amdgpu_ring *ring, uint32_t *index); 1178c2ecf20Sopenharmony_ciuint64_t amdgpu_sdma_get_csa_mc_addr(struct amdgpu_ring *ring, unsigned vmid); 1188c2ecf20Sopenharmony_ciint amdgpu_sdma_ras_late_init(struct amdgpu_device *adev, 1198c2ecf20Sopenharmony_ci void *ras_ih_info); 1208c2ecf20Sopenharmony_civoid amdgpu_sdma_ras_fini(struct amdgpu_device *adev); 1218c2ecf20Sopenharmony_ciint amdgpu_sdma_process_ras_data_cb(struct amdgpu_device *adev, 1228c2ecf20Sopenharmony_ci void *err_data, 1238c2ecf20Sopenharmony_ci struct amdgpu_iv_entry *entry); 1248c2ecf20Sopenharmony_ciint amdgpu_sdma_process_ecc_irq(struct amdgpu_device *adev, 1258c2ecf20Sopenharmony_ci struct amdgpu_irq_src *source, 1268c2ecf20Sopenharmony_ci struct amdgpu_iv_entry *entry); 1278c2ecf20Sopenharmony_ci#endif 128