197b2e202SAlex Deucher /* 297b2e202SAlex Deucher * Copyright 2008 Advanced Micro Devices, Inc. 397b2e202SAlex Deucher * Copyright 2008 Red Hat Inc. 497b2e202SAlex Deucher * Copyright 2009 Jerome Glisse. 597b2e202SAlex Deucher * 697b2e202SAlex Deucher * Permission is hereby granted, free of charge, to any person obtaining a 797b2e202SAlex Deucher * copy of this software and associated documentation files (the "Software"), 897b2e202SAlex Deucher * to deal in the Software without restriction, including without limitation 997b2e202SAlex Deucher * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1097b2e202SAlex Deucher * and/or sell copies of the Software, and to permit persons to whom the 1197b2e202SAlex Deucher * Software is furnished to do so, subject to the following conditions: 1297b2e202SAlex Deucher * 1397b2e202SAlex Deucher * The above copyright notice and this permission notice shall be included in 1497b2e202SAlex Deucher * all copies or substantial portions of the Software. 1597b2e202SAlex Deucher * 1697b2e202SAlex Deucher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1797b2e202SAlex Deucher * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1897b2e202SAlex Deucher * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1997b2e202SAlex Deucher * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 2097b2e202SAlex Deucher * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2197b2e202SAlex Deucher * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2297b2e202SAlex Deucher * OTHER DEALINGS IN THE SOFTWARE. 2397b2e202SAlex Deucher * 2497b2e202SAlex Deucher * Authors: Dave Airlie 2597b2e202SAlex Deucher * Alex Deucher 2697b2e202SAlex Deucher * Jerome Glisse 2797b2e202SAlex Deucher */ 2897b2e202SAlex Deucher #ifndef __AMDGPU_H__ 2997b2e202SAlex Deucher #define __AMDGPU_H__ 3097b2e202SAlex Deucher 3197b2e202SAlex Deucher #include <linux/atomic.h> 3297b2e202SAlex Deucher #include <linux/wait.h> 3397b2e202SAlex Deucher #include <linux/list.h> 3497b2e202SAlex Deucher #include <linux/kref.h> 35a9f87f64SChristian König #include <linux/rbtree.h> 3697b2e202SAlex Deucher #include <linux/hashtable.h> 37f54d1867SChris Wilson #include <linux/dma-fence.h> 3897b2e202SAlex Deucher 39248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_api.h> 40248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_driver.h> 41248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_placement.h> 42248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_module.h> 43248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_execbuf_util.h> 4497b2e202SAlex Deucher 45d03846afSChunming Zhou #include <drm/drmP.h> 4697b2e202SAlex Deucher #include <drm/drm_gem.h> 477e5a547fSChunming Zhou #include <drm/amdgpu_drm.h> 481b1f42d8SLucas Stach #include <drm/gpu_scheduler.h> 4997b2e202SAlex Deucher 5078c16834SAndres Rodriguez #include <kgd_kfd_interface.h> 51c79563a3SRex Zhu #include "dm_pp_interface.h" 52c79563a3SRex Zhu #include "kgd_pp_interface.h" 5378c16834SAndres Rodriguez 545fc3aeebSyanyang1 #include "amd_shared.h" 5597b2e202SAlex Deucher #include "amdgpu_mode.h" 5697b2e202SAlex Deucher #include "amdgpu_ih.h" 5797b2e202SAlex Deucher #include "amdgpu_irq.h" 5897b2e202SAlex Deucher #include "amdgpu_ucode.h" 59c632d799SFlora Cui #include "amdgpu_ttm.h" 600e5ca0d1SHuang Rui #include "amdgpu_psp.h" 6197b2e202SAlex Deucher #include "amdgpu_gds.h" 6256113504SChristian König #include "amdgpu_sync.h" 6378023016SChristian König #include "amdgpu_ring.h" 64073440d2SChristian König #include "amdgpu_vm.h" 65cf097881SAlex Deucher #include "amdgpu_dpm.h" 66a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h" 674df654d2SLeo Liu #include "amdgpu_uvd.h" 685e568178SLeo Liu #include "amdgpu_vce.h" 6995aa13f6SLeo Liu #include "amdgpu_vcn.h" 709a189996SChristian König #include "amdgpu_mn.h" 71770d13b1SChristian König #include "amdgpu_gmc.h" 724562236bSHarry Wentland #include "amdgpu_dm.h" 73ceeb50edSMonk Liu #include "amdgpu_virt.h" 743490bdb5SChristian König #include "amdgpu_gart.h" 7575758255SAlex Deucher #include "amdgpu_debugfs.h" 76c79563a3SRex Zhu 7797b2e202SAlex Deucher /* 7897b2e202SAlex Deucher * Modules parameters. 7997b2e202SAlex Deucher */ 8097b2e202SAlex Deucher extern int amdgpu_modeset; 8197b2e202SAlex Deucher extern int amdgpu_vram_limit; 82218b5dcdSJohn Brooks extern int amdgpu_vis_vram_limit; 8383e74db6SAlex Deucher extern int amdgpu_gart_size; 8436d38372SChristian König extern int amdgpu_gtt_size; 8595844d20SMarek Olšák extern int amdgpu_moverate; 8697b2e202SAlex Deucher extern int amdgpu_benchmarking; 8797b2e202SAlex Deucher extern int amdgpu_testing; 8897b2e202SAlex Deucher extern int amdgpu_audio; 8997b2e202SAlex Deucher extern int amdgpu_disp_priority; 9097b2e202SAlex Deucher extern int amdgpu_hw_i2c; 9197b2e202SAlex Deucher extern int amdgpu_pcie_gen2; 9297b2e202SAlex Deucher extern int amdgpu_msi; 9397b2e202SAlex Deucher extern int amdgpu_lockup_timeout; 9497b2e202SAlex Deucher extern int amdgpu_dpm; 95e635ee07SHuang Rui extern int amdgpu_fw_load_type; 9697b2e202SAlex Deucher extern int amdgpu_aspm; 9797b2e202SAlex Deucher extern int amdgpu_runtime_pm; 980b693f0bSRex Zhu extern uint amdgpu_ip_block_mask; 9997b2e202SAlex Deucher extern int amdgpu_bapm; 10097b2e202SAlex Deucher extern int amdgpu_deep_color; 10197b2e202SAlex Deucher extern int amdgpu_vm_size; 10297b2e202SAlex Deucher extern int amdgpu_vm_block_size; 103d07f14beSRoger He extern int amdgpu_vm_fragment_size; 104d9c13156SChristian König extern int amdgpu_vm_fault_stop; 105b495bd3aSChristian König extern int amdgpu_vm_debug; 1069a4b7d4cSHarish Kasiviswanathan extern int amdgpu_vm_update_mode; 1074562236bSHarry Wentland extern int amdgpu_dc; 10802e749dcSHarry Wentland extern int amdgpu_dc_log; 1091333f723SJammy Zhou extern int amdgpu_sched_jobs; 1104afcb303SJammy Zhou extern int amdgpu_sched_hw_submission; 1113ca67300SRex Zhu extern int amdgpu_no_evict; 1123ca67300SRex Zhu extern int amdgpu_direct_gma_size; 1130b693f0bSRex Zhu extern uint amdgpu_pcie_gen_cap; 1140b693f0bSRex Zhu extern uint amdgpu_pcie_lane_cap; 1150b693f0bSRex Zhu extern uint amdgpu_cg_mask; 1160b693f0bSRex Zhu extern uint amdgpu_pg_mask; 1170b693f0bSRex Zhu extern uint amdgpu_sdma_phase_quantum; 1186f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu; 1199accf2fdSEmily Deng extern char *amdgpu_virtual_display; 1200b693f0bSRex Zhu extern uint amdgpu_pp_feature_mask; 1216a7f76e7SChristian König extern int amdgpu_vram_page_split; 122bce23e00SAlex Deucher extern int amdgpu_ngg; 123bce23e00SAlex Deucher extern int amdgpu_prim_buf_per_se; 124bce23e00SAlex Deucher extern int amdgpu_pos_buf_per_se; 125bce23e00SAlex Deucher extern int amdgpu_cntl_sb_buf_per_se; 126bce23e00SAlex Deucher extern int amdgpu_param_buf_per_se; 12765781c78SMonk Liu extern int amdgpu_job_hang_limit; 128e8835e0eSHawking Zhang extern int amdgpu_lbpw; 1294a75aefeSAndres Rodriguez extern int amdgpu_compute_multipipe; 130dcebf026SAndrey Grodzovsky extern int amdgpu_gpu_recovery; 131bfca0289SShaoyun Liu extern int amdgpu_emu_mode; 13297b2e202SAlex Deucher 1336dd13096SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_SI 1346dd13096SFelix Kuehling extern int amdgpu_si_support; 1356dd13096SFelix Kuehling #endif 1367df28986SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_CIK 1377df28986SFelix Kuehling extern int amdgpu_cik_support; 1387df28986SFelix Kuehling #endif 13997b2e202SAlex Deucher 14055ed8cafSChunming Zhou #define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */ 1414b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000 14297b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 14397b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) 14497b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */ 14597b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE 16 14697b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32 14797b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT 4 148a5bde2f9SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH 16 14997b2e202SAlex Deucher 15036f523a7SJammy Zhou /* max number of IP instances */ 15136f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES 2 15236f523a7SJammy Zhou 15397b2e202SAlex Deucher /* hard reset data */ 15497b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b 15597b2e202SAlex Deucher 15697b2e202SAlex Deucher /* reset flags */ 15797b2e202SAlex Deucher #define AMDGPU_RESET_GFX (1 << 0) 15897b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE (1 << 1) 15997b2e202SAlex Deucher #define AMDGPU_RESET_DMA (1 << 2) 16097b2e202SAlex Deucher #define AMDGPU_RESET_CP (1 << 3) 16197b2e202SAlex Deucher #define AMDGPU_RESET_GRBM (1 << 4) 16297b2e202SAlex Deucher #define AMDGPU_RESET_DMA1 (1 << 5) 16397b2e202SAlex Deucher #define AMDGPU_RESET_RLC (1 << 6) 16497b2e202SAlex Deucher #define AMDGPU_RESET_SEM (1 << 7) 16597b2e202SAlex Deucher #define AMDGPU_RESET_IH (1 << 8) 16697b2e202SAlex Deucher #define AMDGPU_RESET_VMC (1 << 9) 16797b2e202SAlex Deucher #define AMDGPU_RESET_MC (1 << 10) 16897b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY (1 << 11) 16997b2e202SAlex Deucher #define AMDGPU_RESET_UVD (1 << 12) 17097b2e202SAlex Deucher #define AMDGPU_RESET_VCE (1 << 13) 17197b2e202SAlex Deucher #define AMDGPU_RESET_VCE1 (1 << 14) 17297b2e202SAlex Deucher 17397b2e202SAlex Deucher /* GFX current status */ 17497b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE 0x00000000L 17597b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE 0x00000001L 17697b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L 17797b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L 17897b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L 17997b2e202SAlex Deucher 18097b2e202SAlex Deucher /* max cursor sizes (in pixels) */ 18197b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128 18297b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128 18397b2e202SAlex Deucher 18497b2e202SAlex Deucher struct amdgpu_device; 18597b2e202SAlex Deucher struct amdgpu_ib; 18697b2e202SAlex Deucher struct amdgpu_cs_parser; 187bb977d37SChunming Zhou struct amdgpu_job; 18897b2e202SAlex Deucher struct amdgpu_irq_src; 1890b492a4cSAlex Deucher struct amdgpu_fpriv; 1909cca0b8eSChristian König struct amdgpu_bo_va_mapping; 19197b2e202SAlex Deucher 19297b2e202SAlex Deucher enum amdgpu_cp_irq { 19397b2e202SAlex Deucher AMDGPU_CP_IRQ_GFX_EOP = 0, 19497b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP, 19597b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP, 19697b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP, 19797b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP, 19897b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP, 19997b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP, 20097b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP, 20197b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP, 20297b2e202SAlex Deucher 20397b2e202SAlex Deucher AMDGPU_CP_IRQ_LAST 20497b2e202SAlex Deucher }; 20597b2e202SAlex Deucher 20697b2e202SAlex Deucher enum amdgpu_sdma_irq { 20797b2e202SAlex Deucher AMDGPU_SDMA_IRQ_TRAP0 = 0, 20897b2e202SAlex Deucher AMDGPU_SDMA_IRQ_TRAP1, 20997b2e202SAlex Deucher 21097b2e202SAlex Deucher AMDGPU_SDMA_IRQ_LAST 21197b2e202SAlex Deucher }; 21297b2e202SAlex Deucher 21397b2e202SAlex Deucher enum amdgpu_thermal_irq { 21497b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0, 21597b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_HIGH_TO_LOW, 21697b2e202SAlex Deucher 21797b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LAST 21897b2e202SAlex Deucher }; 21997b2e202SAlex Deucher 2204e638ae9SXiangliang Yu enum amdgpu_kiq_irq { 2214e638ae9SXiangliang Yu AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0, 2224e638ae9SXiangliang Yu AMDGPU_CP_KIQ_IRQ_LAST 2234e638ae9SXiangliang Yu }; 2244e638ae9SXiangliang Yu 2252990a1fcSAlex Deucher int amdgpu_device_ip_set_clockgating_state(struct amdgpu_device *adev, 2265fc3aeebSyanyang1 enum amd_ip_block_type block_type, 2275fc3aeebSyanyang1 enum amd_clockgating_state state); 2282990a1fcSAlex Deucher int amdgpu_device_ip_set_powergating_state(struct amdgpu_device *adev, 2295fc3aeebSyanyang1 enum amd_ip_block_type block_type, 2305fc3aeebSyanyang1 enum amd_powergating_state state); 2312990a1fcSAlex Deucher void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev, 2322990a1fcSAlex Deucher u32 *flags); 2332990a1fcSAlex Deucher int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev, 2345dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 2352990a1fcSAlex Deucher bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev, 2365dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 23797b2e202SAlex Deucher 238a1255107SAlex Deucher #define AMDGPU_MAX_IP_NUM 16 239a1255107SAlex Deucher 240a1255107SAlex Deucher struct amdgpu_ip_block_status { 241a1255107SAlex Deucher bool valid; 242a1255107SAlex Deucher bool sw; 243a1255107SAlex Deucher bool hw; 244a1255107SAlex Deucher bool late_initialized; 245a1255107SAlex Deucher bool hang; 246a1255107SAlex Deucher }; 247a1255107SAlex Deucher 24897b2e202SAlex Deucher struct amdgpu_ip_block_version { 249a1255107SAlex Deucher const enum amd_ip_block_type type; 250a1255107SAlex Deucher const u32 major; 251a1255107SAlex Deucher const u32 minor; 252a1255107SAlex Deucher const u32 rev; 2535fc3aeebSyanyang1 const struct amd_ip_funcs *funcs; 25497b2e202SAlex Deucher }; 25597b2e202SAlex Deucher 256a1255107SAlex Deucher struct amdgpu_ip_block { 257a1255107SAlex Deucher struct amdgpu_ip_block_status status; 258a1255107SAlex Deucher const struct amdgpu_ip_block_version *version; 259a1255107SAlex Deucher }; 260a1255107SAlex Deucher 2612990a1fcSAlex Deucher int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev, 2625fc3aeebSyanyang1 enum amd_ip_block_type type, 26397b2e202SAlex Deucher u32 major, u32 minor); 26497b2e202SAlex Deucher 2652990a1fcSAlex Deucher struct amdgpu_ip_block * 2662990a1fcSAlex Deucher amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev, 2675fc3aeebSyanyang1 enum amd_ip_block_type type); 26897b2e202SAlex Deucher 2692990a1fcSAlex Deucher int amdgpu_device_ip_block_add(struct amdgpu_device *adev, 270a1255107SAlex Deucher const struct amdgpu_ip_block_version *ip_block_version); 271a1255107SAlex Deucher 27297b2e202SAlex Deucher /* provided by hw blocks that can move/clear data. e.g., gfx or sdma */ 27397b2e202SAlex Deucher struct amdgpu_buffer_funcs { 27497b2e202SAlex Deucher /* maximum bytes in a single operation */ 27597b2e202SAlex Deucher uint32_t copy_max_bytes; 27697b2e202SAlex Deucher 27797b2e202SAlex Deucher /* number of dw to reserve per operation */ 27897b2e202SAlex Deucher unsigned copy_num_dw; 27997b2e202SAlex Deucher 28097b2e202SAlex Deucher /* used for buffer migration */ 281c7ae72c0SChunming Zhou void (*emit_copy_buffer)(struct amdgpu_ib *ib, 28297b2e202SAlex Deucher /* src addr in bytes */ 28397b2e202SAlex Deucher uint64_t src_offset, 28497b2e202SAlex Deucher /* dst addr in bytes */ 28597b2e202SAlex Deucher uint64_t dst_offset, 28697b2e202SAlex Deucher /* number of byte to transfer */ 28797b2e202SAlex Deucher uint32_t byte_count); 28897b2e202SAlex Deucher 28997b2e202SAlex Deucher /* maximum bytes in a single operation */ 29097b2e202SAlex Deucher uint32_t fill_max_bytes; 29197b2e202SAlex Deucher 29297b2e202SAlex Deucher /* number of dw to reserve per operation */ 29397b2e202SAlex Deucher unsigned fill_num_dw; 29497b2e202SAlex Deucher 29597b2e202SAlex Deucher /* used for buffer clearing */ 2966e7a3840SChunming Zhou void (*emit_fill_buffer)(struct amdgpu_ib *ib, 29797b2e202SAlex Deucher /* value to write to memory */ 29897b2e202SAlex Deucher uint32_t src_data, 29997b2e202SAlex Deucher /* dst addr in bytes */ 30097b2e202SAlex Deucher uint64_t dst_offset, 30197b2e202SAlex Deucher /* number of byte to fill */ 30297b2e202SAlex Deucher uint32_t byte_count); 30397b2e202SAlex Deucher }; 30497b2e202SAlex Deucher 30597b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */ 30697b2e202SAlex Deucher struct amdgpu_vm_pte_funcs { 307e6d92197SYong Zhao /* number of dw to reserve per operation */ 308e6d92197SYong Zhao unsigned copy_pte_num_dw; 309e6d92197SYong Zhao 31097b2e202SAlex Deucher /* copy pte entries from GART */ 31197b2e202SAlex Deucher void (*copy_pte)(struct amdgpu_ib *ib, 31297b2e202SAlex Deucher uint64_t pe, uint64_t src, 31397b2e202SAlex Deucher unsigned count); 314e6d92197SYong Zhao 31597b2e202SAlex Deucher /* write pte one entry at a time with addr mapping */ 316de9ea7bdSChristian König void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe, 317de9ea7bdSChristian König uint64_t value, unsigned count, 318de9ea7bdSChristian König uint32_t incr); 31997b2e202SAlex Deucher /* for linear pte/pde updates without addr mapping */ 32097b2e202SAlex Deucher void (*set_pte_pde)(struct amdgpu_ib *ib, 32197b2e202SAlex Deucher uint64_t pe, 32297b2e202SAlex Deucher uint64_t addr, unsigned count, 3236b777607SChunming Zhou uint32_t incr, uint64_t flags); 32497b2e202SAlex Deucher }; 32597b2e202SAlex Deucher 32697b2e202SAlex Deucher /* provided by the ih block */ 32797b2e202SAlex Deucher struct amdgpu_ih_funcs { 32897b2e202SAlex Deucher /* ring read/write ptr handling, called from interrupt context */ 32997b2e202SAlex Deucher u32 (*get_wptr)(struct amdgpu_device *adev); 33000ecd8a2SFelix Kuehling bool (*prescreen_iv)(struct amdgpu_device *adev); 33197b2e202SAlex Deucher void (*decode_iv)(struct amdgpu_device *adev, 33297b2e202SAlex Deucher struct amdgpu_iv_entry *entry); 33397b2e202SAlex Deucher void (*set_rptr)(struct amdgpu_device *adev); 33497b2e202SAlex Deucher }; 33597b2e202SAlex Deucher 33697b2e202SAlex Deucher /* 33797b2e202SAlex Deucher * BIOS. 33897b2e202SAlex Deucher */ 33997b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev); 34097b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev); 34197b2e202SAlex Deucher 34297b2e202SAlex Deucher /* 34397b2e202SAlex Deucher * Clocks 34497b2e202SAlex Deucher */ 34597b2e202SAlex Deucher 34697b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3 34797b2e202SAlex Deucher 34897b2e202SAlex Deucher struct amdgpu_clock { 34997b2e202SAlex Deucher struct amdgpu_pll ppll[AMDGPU_MAX_PPLL]; 35097b2e202SAlex Deucher struct amdgpu_pll spll; 35197b2e202SAlex Deucher struct amdgpu_pll mpll; 35297b2e202SAlex Deucher /* 10 Khz units */ 35397b2e202SAlex Deucher uint32_t default_mclk; 35497b2e202SAlex Deucher uint32_t default_sclk; 35597b2e202SAlex Deucher uint32_t default_dispclk; 35697b2e202SAlex Deucher uint32_t current_dispclk; 35797b2e202SAlex Deucher uint32_t dp_extclk; 35897b2e202SAlex Deucher uint32_t max_pixel_clock; 35997b2e202SAlex Deucher }; 36097b2e202SAlex Deucher 36197b2e202SAlex Deucher /* 3629124a398SChristian König * GEM. 36397b2e202SAlex Deucher */ 36497b2e202SAlex Deucher 3657e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX 0x3 36697b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base) 36797b2e202SAlex Deucher 36897b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj); 36997b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj, 37097b2e202SAlex Deucher struct drm_file *file_priv); 37197b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj, 37297b2e202SAlex Deucher struct drm_file *file_priv); 37397b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns); 37497b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj); 3754d9c514dSChristian König struct drm_gem_object * 3764d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev, 37797b2e202SAlex Deucher struct dma_buf_attachment *attach, 37897b2e202SAlex Deucher struct sg_table *sg); 37997b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev, 38097b2e202SAlex Deucher struct drm_gem_object *gobj, 38197b2e202SAlex Deucher int flags); 38209052fc3SSamuel Li struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev, 38309052fc3SSamuel Li struct dma_buf *dma_buf); 38497b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *); 38597b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj); 38697b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); 387dfced2e4SSamuel Li int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); 38897b2e202SAlex Deucher 38997b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock. 39097b2e202SAlex Deucher * By conception this is an helper for other part of the driver 39197b2e202SAlex Deucher * like the indirect buffer or semaphore, which both have their 39297b2e202SAlex Deucher * locking. 39397b2e202SAlex Deucher * 39497b2e202SAlex Deucher * Principe is simple, we keep a list of sub allocation in offset 39597b2e202SAlex Deucher * order (first entry has offset == 0, last entry has the highest 39697b2e202SAlex Deucher * offset). 39797b2e202SAlex Deucher * 39897b2e202SAlex Deucher * When allocating new object we first check if there is room at 39997b2e202SAlex Deucher * the end total_size - (last_object_offset + last_object_size) >= 40097b2e202SAlex Deucher * alloc_size. If so we allocate new object there. 40197b2e202SAlex Deucher * 40297b2e202SAlex Deucher * When there is not enough room at the end, we start waiting for 40397b2e202SAlex Deucher * each sub object until we reach object_offset+object_size >= 40497b2e202SAlex Deucher * alloc_size, this object then become the sub object we return. 40597b2e202SAlex Deucher * 40697b2e202SAlex Deucher * Alignment can't be bigger than page size. 40797b2e202SAlex Deucher * 40897b2e202SAlex Deucher * Hole are not considered for allocation to keep things simple. 40997b2e202SAlex Deucher * Assumption is that there won't be hole (all object on same 41097b2e202SAlex Deucher * alignment). 41197b2e202SAlex Deucher */ 4126ba60b89SChristian König 4136ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS 32 4146ba60b89SChristian König 41597b2e202SAlex Deucher struct amdgpu_sa_manager { 41697b2e202SAlex Deucher wait_queue_head_t wq; 41797b2e202SAlex Deucher struct amdgpu_bo *bo; 41897b2e202SAlex Deucher struct list_head *hole; 4196ba60b89SChristian König struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS]; 42097b2e202SAlex Deucher struct list_head olist; 42197b2e202SAlex Deucher unsigned size; 42297b2e202SAlex Deucher uint64_t gpu_addr; 42397b2e202SAlex Deucher void *cpu_ptr; 42497b2e202SAlex Deucher uint32_t domain; 42597b2e202SAlex Deucher uint32_t align; 42697b2e202SAlex Deucher }; 42797b2e202SAlex Deucher 42897b2e202SAlex Deucher /* sub-allocation buffer */ 42997b2e202SAlex Deucher struct amdgpu_sa_bo { 43097b2e202SAlex Deucher struct list_head olist; 43197b2e202SAlex Deucher struct list_head flist; 43297b2e202SAlex Deucher struct amdgpu_sa_manager *manager; 43397b2e202SAlex Deucher unsigned soffset; 43497b2e202SAlex Deucher unsigned eoffset; 435f54d1867SChris Wilson struct dma_fence *fence; 43697b2e202SAlex Deucher }; 43797b2e202SAlex Deucher 43897b2e202SAlex Deucher /* 43997b2e202SAlex Deucher * GEM objects. 44097b2e202SAlex Deucher */ 441418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev); 44297b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, 44397b2e202SAlex Deucher int alignment, u32 initial_domain, 444eab3de23SChristian König u64 flags, enum ttm_bo_type type, 445e1eb899bSChristian König struct reservation_object *resv, 44697b2e202SAlex Deucher struct drm_gem_object **obj); 44797b2e202SAlex Deucher 44897b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv, 44997b2e202SAlex Deucher struct drm_device *dev, 45097b2e202SAlex Deucher struct drm_mode_create_dumb *args); 45197b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp, 45297b2e202SAlex Deucher struct drm_device *dev, 45397b2e202SAlex Deucher uint32_t handle, uint64_t *offset_p); 454d573de2dSRex Zhu int amdgpu_fence_slab_init(void); 455d573de2dSRex Zhu void amdgpu_fence_slab_fini(void); 45697b2e202SAlex Deucher 45797b2e202SAlex Deucher /* 45897b2e202SAlex Deucher * GPU doorbell structures, functions & helpers 45997b2e202SAlex Deucher */ 46097b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT 46197b2e202SAlex Deucher { 46297b2e202SAlex Deucher AMDGPU_DOORBELL_KIQ = 0x000, 46397b2e202SAlex Deucher AMDGPU_DOORBELL_HIQ = 0x001, 46497b2e202SAlex Deucher AMDGPU_DOORBELL_DIQ = 0x002, 46597b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING0 = 0x010, 46697b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING1 = 0x011, 46797b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING2 = 0x012, 46897b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING3 = 0x013, 46997b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING4 = 0x014, 47097b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING5 = 0x015, 47197b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING6 = 0x016, 47297b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING7 = 0x017, 47397b2e202SAlex Deucher AMDGPU_DOORBELL_GFX_RING0 = 0x020, 47497b2e202SAlex Deucher AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0, 47597b2e202SAlex Deucher AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1, 47697b2e202SAlex Deucher AMDGPU_DOORBELL_IH = 0x1E8, 47797b2e202SAlex Deucher AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF, 47897b2e202SAlex Deucher AMDGPU_DOORBELL_INVALID = 0xFFFF 47997b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT; 48097b2e202SAlex Deucher 48197b2e202SAlex Deucher struct amdgpu_doorbell { 48297b2e202SAlex Deucher /* doorbell mmio */ 48397b2e202SAlex Deucher resource_size_t base; 48497b2e202SAlex Deucher resource_size_t size; 48597b2e202SAlex Deucher u32 __iomem *ptr; 48697b2e202SAlex Deucher u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */ 48797b2e202SAlex Deucher }; 48897b2e202SAlex Deucher 48939807b93SKen Wang /* 49039807b93SKen Wang * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space 49139807b93SKen Wang */ 49239807b93SKen Wang typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT 49339807b93SKen Wang { 49439807b93SKen Wang /* 49539807b93SKen Wang * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in 49639807b93SKen Wang * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range. 49739807b93SKen Wang * Compute related doorbells are allocated from 0x00 to 0x8a 49839807b93SKen Wang */ 49939807b93SKen Wang 50039807b93SKen Wang 50139807b93SKen Wang /* kernel scheduling */ 50239807b93SKen Wang AMDGPU_DOORBELL64_KIQ = 0x00, 50339807b93SKen Wang 50439807b93SKen Wang /* HSA interface queue and debug queue */ 50539807b93SKen Wang AMDGPU_DOORBELL64_HIQ = 0x01, 50639807b93SKen Wang AMDGPU_DOORBELL64_DIQ = 0x02, 50739807b93SKen Wang 50839807b93SKen Wang /* Compute engines */ 50939807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING0 = 0x03, 51039807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING1 = 0x04, 51139807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING2 = 0x05, 51239807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING3 = 0x06, 51339807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING4 = 0x07, 51439807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING5 = 0x08, 51539807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING6 = 0x09, 51639807b93SKen Wang AMDGPU_DOORBELL64_MEC_RING7 = 0x0a, 51739807b93SKen Wang 51839807b93SKen Wang /* User queue doorbell range (128 doorbells) */ 51939807b93SKen Wang AMDGPU_DOORBELL64_USERQUEUE_START = 0x0b, 52039807b93SKen Wang AMDGPU_DOORBELL64_USERQUEUE_END = 0x8a, 52139807b93SKen Wang 52239807b93SKen Wang /* Graphics engine */ 52339807b93SKen Wang AMDGPU_DOORBELL64_GFX_RING0 = 0x8b, 52439807b93SKen Wang 52539807b93SKen Wang /* 52639807b93SKen Wang * Other graphics doorbells can be allocated here: from 0x8c to 0xef 52739807b93SKen Wang * Graphics voltage island aperture 1 52839807b93SKen Wang * default non-graphics QWORD index is 0xF0 - 0xFF inclusive 52939807b93SKen Wang */ 53039807b93SKen Wang 53139807b93SKen Wang /* sDMA engines */ 53239807b93SKen Wang AMDGPU_DOORBELL64_sDMA_ENGINE0 = 0xF0, 53339807b93SKen Wang AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1, 53439807b93SKen Wang AMDGPU_DOORBELL64_sDMA_ENGINE1 = 0xF2, 53539807b93SKen Wang AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3, 53639807b93SKen Wang 53739807b93SKen Wang /* Interrupt handler */ 53839807b93SKen Wang AMDGPU_DOORBELL64_IH = 0xF4, /* For legacy interrupt ring buffer */ 53939807b93SKen Wang AMDGPU_DOORBELL64_IH_RING1 = 0xF5, /* For page migration request log */ 54039807b93SKen Wang AMDGPU_DOORBELL64_IH_RING2 = 0xF6, /* For page migration translation/invalidation log */ 54139807b93SKen Wang 542e6b3ecb4SMonk Liu /* VCN engine use 32 bits doorbell */ 543e6b3ecb4SMonk Liu AMDGPU_DOORBELL64_VCN0_1 = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */ 544e6b3ecb4SMonk Liu AMDGPU_DOORBELL64_VCN2_3 = 0xF9, 545e6b3ecb4SMonk Liu AMDGPU_DOORBELL64_VCN4_5 = 0xFA, 546e6b3ecb4SMonk Liu AMDGPU_DOORBELL64_VCN6_7 = 0xFB, 547e6b3ecb4SMonk Liu 548e6b3ecb4SMonk Liu /* overlap the doorbell assignment with VCN as they are mutually exclusive 549e6b3ecb4SMonk Liu * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD 550e6b3ecb4SMonk Liu */ 5514ed11d79SFrank Min AMDGPU_DOORBELL64_UVD_RING0_1 = 0xF8, 5524ed11d79SFrank Min AMDGPU_DOORBELL64_UVD_RING2_3 = 0xF9, 5534ed11d79SFrank Min AMDGPU_DOORBELL64_UVD_RING4_5 = 0xFA, 5544ed11d79SFrank Min AMDGPU_DOORBELL64_UVD_RING6_7 = 0xFB, 555e6b3ecb4SMonk Liu 5564ed11d79SFrank Min AMDGPU_DOORBELL64_VCE_RING0_1 = 0xFC, 5574ed11d79SFrank Min AMDGPU_DOORBELL64_VCE_RING2_3 = 0xFD, 5584ed11d79SFrank Min AMDGPU_DOORBELL64_VCE_RING4_5 = 0xFE, 5594ed11d79SFrank Min AMDGPU_DOORBELL64_VCE_RING6_7 = 0xFF, 56039807b93SKen Wang 56139807b93SKen Wang AMDGPU_DOORBELL64_MAX_ASSIGNMENT = 0xFF, 56239807b93SKen Wang AMDGPU_DOORBELL64_INVALID = 0xFFFF 56339807b93SKen Wang } AMDGPU_DOORBELL64_ASSIGNMENT; 56439807b93SKen Wang 56597b2e202SAlex Deucher /* 56697b2e202SAlex Deucher * IRQS. 56797b2e202SAlex Deucher */ 56897b2e202SAlex Deucher 56997b2e202SAlex Deucher struct amdgpu_flip_work { 570325cbba1SMichel Dänzer struct delayed_work flip_work; 57197b2e202SAlex Deucher struct work_struct unpin_work; 57297b2e202SAlex Deucher struct amdgpu_device *adev; 57397b2e202SAlex Deucher int crtc_id; 574325cbba1SMichel Dänzer u32 target_vblank; 57597b2e202SAlex Deucher uint64_t base; 57697b2e202SAlex Deucher struct drm_pending_vblank_event *event; 577765e7fbfSChristian König struct amdgpu_bo *old_abo; 578f54d1867SChris Wilson struct dma_fence *excl; 5791ffd2652SChristian König unsigned shared_count; 580f54d1867SChris Wilson struct dma_fence **shared; 581f54d1867SChris Wilson struct dma_fence_cb cb; 582cb9e59d7SAlex Deucher bool async; 58397b2e202SAlex Deucher }; 58497b2e202SAlex Deucher 58597b2e202SAlex Deucher 58697b2e202SAlex Deucher /* 58797b2e202SAlex Deucher * CP & rings. 58897b2e202SAlex Deucher */ 58997b2e202SAlex Deucher 59097b2e202SAlex Deucher struct amdgpu_ib { 59197b2e202SAlex Deucher struct amdgpu_sa_bo *sa_bo; 59297b2e202SAlex Deucher uint32_t length_dw; 59397b2e202SAlex Deucher uint64_t gpu_addr; 59497b2e202SAlex Deucher uint32_t *ptr; 595de807f81SJammy Zhou uint32_t flags; 59697b2e202SAlex Deucher }; 59797b2e202SAlex Deucher 5981b1f42d8SLucas Stach extern const struct drm_sched_backend_ops amdgpu_sched_ops; 599c1b69ed0SChunming Zhou 60050838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, 601c5637837SMonk Liu struct amdgpu_job **job, struct amdgpu_vm *vm); 602d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size, 603d71518b5SChristian König struct amdgpu_job **job); 604b6723c8dSMonk Liu 605a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job); 60650838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job); 607d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring, 6081b1f42d8SLucas Stach struct drm_sched_entity *entity, void *owner, 609f54d1867SChris Wilson struct dma_fence **f); 6108b4fb00bSChristian König 61197b2e202SAlex Deucher /* 612effd924dSAndres Rodriguez * Queue manager 613effd924dSAndres Rodriguez */ 614effd924dSAndres Rodriguez struct amdgpu_queue_mapper { 615effd924dSAndres Rodriguez int hw_ip; 616effd924dSAndres Rodriguez struct mutex lock; 617effd924dSAndres Rodriguez /* protected by lock */ 618effd924dSAndres Rodriguez struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS]; 619effd924dSAndres Rodriguez }; 620effd924dSAndres Rodriguez 621effd924dSAndres Rodriguez struct amdgpu_queue_mgr { 622effd924dSAndres Rodriguez struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM]; 623effd924dSAndres Rodriguez }; 624effd924dSAndres Rodriguez 625effd924dSAndres Rodriguez int amdgpu_queue_mgr_init(struct amdgpu_device *adev, 626effd924dSAndres Rodriguez struct amdgpu_queue_mgr *mgr); 627effd924dSAndres Rodriguez int amdgpu_queue_mgr_fini(struct amdgpu_device *adev, 628effd924dSAndres Rodriguez struct amdgpu_queue_mgr *mgr); 629effd924dSAndres Rodriguez int amdgpu_queue_mgr_map(struct amdgpu_device *adev, 630effd924dSAndres Rodriguez struct amdgpu_queue_mgr *mgr, 631fa7c7939SMichel Dänzer u32 hw_ip, u32 instance, u32 ring, 632effd924dSAndres Rodriguez struct amdgpu_ring **out_ring); 633effd924dSAndres Rodriguez 634effd924dSAndres Rodriguez /* 63597b2e202SAlex Deucher * context related structures 63697b2e202SAlex Deucher */ 63797b2e202SAlex Deucher 63821c16bf6SChristian König struct amdgpu_ctx_ring { 63921c16bf6SChristian König uint64_t sequence; 640f54d1867SChris Wilson struct dma_fence **fences; 6411b1f42d8SLucas Stach struct drm_sched_entity entity; 64221c16bf6SChristian König }; 64321c16bf6SChristian König 64497b2e202SAlex Deucher struct amdgpu_ctx { 64597b2e202SAlex Deucher struct kref refcount; 6469cb7e5a9SChunming Zhou struct amdgpu_device *adev; 647effd924dSAndres Rodriguez struct amdgpu_queue_mgr queue_mgr; 648d94aed5aSMarek Olšák unsigned reset_counter; 649668ca1b4SMonk Liu unsigned reset_counter_query; 650e55f2b64SChristian König uint32_t vram_lost_counter; 65121c16bf6SChristian König spinlock_t ring_lock; 652f54d1867SChris Wilson struct dma_fence **fences; 65321c16bf6SChristian König struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS]; 654753ad49cSMonk Liu bool preamble_presented; 6551b1f42d8SLucas Stach enum drm_sched_priority init_priority; 6561b1f42d8SLucas Stach enum drm_sched_priority override_priority; 6570ae94444SAndrey Grodzovsky struct mutex lock; 6581102900dSMonk Liu atomic_t guilty; 65997b2e202SAlex Deucher }; 66097b2e202SAlex Deucher 66197b2e202SAlex Deucher struct amdgpu_ctx_mgr { 66297b2e202SAlex Deucher struct amdgpu_device *adev; 6630147ee0fSMarek Olšák struct mutex lock; 6640b492a4cSAlex Deucher /* protected by lock */ 6650b492a4cSAlex Deucher struct idr ctx_handles; 66697b2e202SAlex Deucher }; 66797b2e202SAlex Deucher 6680b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id); 6690b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx); 6700b492a4cSAlex Deucher 671eb01abc7SMonk Liu int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring, 672eb01abc7SMonk Liu struct dma_fence *fence, uint64_t *seq); 673f54d1867SChris Wilson struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, 67421c16bf6SChristian König struct amdgpu_ring *ring, uint64_t seq); 675c23be4aeSAndres Rodriguez void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx, 6761b1f42d8SLucas Stach enum drm_sched_priority priority); 67721c16bf6SChristian König 6780b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, 6790b492a4cSAlex Deucher struct drm_file *filp); 6800b492a4cSAlex Deucher 6810ae94444SAndrey Grodzovsky int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id); 6820ae94444SAndrey Grodzovsky 683efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr); 684efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); 6850b492a4cSAlex Deucher 6860ae94444SAndrey Grodzovsky 68797b2e202SAlex Deucher /* 68897b2e202SAlex Deucher * file private structure 68997b2e202SAlex Deucher */ 69097b2e202SAlex Deucher 69197b2e202SAlex Deucher struct amdgpu_fpriv { 69297b2e202SAlex Deucher struct amdgpu_vm vm; 693b85891bdSJunwei Zhang struct amdgpu_bo_va *prt_va; 6940f4b3c68SChristian König struct amdgpu_bo_va *csa_va; 69597b2e202SAlex Deucher struct mutex bo_list_lock; 69697b2e202SAlex Deucher struct idr bo_list_handles; 69797b2e202SAlex Deucher struct amdgpu_ctx_mgr ctx_mgr; 69897b2e202SAlex Deucher }; 69997b2e202SAlex Deucher 70097b2e202SAlex Deucher /* 70197b2e202SAlex Deucher * residency list 70297b2e202SAlex Deucher */ 7039124a398SChristian König struct amdgpu_bo_list_entry { 7049124a398SChristian König struct amdgpu_bo *robj; 7059124a398SChristian König struct ttm_validate_buffer tv; 7069124a398SChristian König struct amdgpu_bo_va *bo_va; 7079124a398SChristian König uint32_t priority; 7089124a398SChristian König struct page **user_pages; 7099124a398SChristian König int user_invalidated; 7109124a398SChristian König }; 71197b2e202SAlex Deucher 71297b2e202SAlex Deucher struct amdgpu_bo_list { 71397b2e202SAlex Deucher struct mutex lock; 7145ac55629SAlex Xie struct rcu_head rhead; 7155ac55629SAlex Xie struct kref refcount; 71697b2e202SAlex Deucher struct amdgpu_bo *gds_obj; 71797b2e202SAlex Deucher struct amdgpu_bo *gws_obj; 71897b2e202SAlex Deucher struct amdgpu_bo *oa_obj; 719211dff55SChristian König unsigned first_userptr; 72097b2e202SAlex Deucher unsigned num_entries; 72197b2e202SAlex Deucher struct amdgpu_bo_list_entry *array; 72297b2e202SAlex Deucher }; 72397b2e202SAlex Deucher 72497b2e202SAlex Deucher struct amdgpu_bo_list * 72597b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id); 726636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list, 727636ce25cSChristian König struct list_head *validated); 72897b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list); 72997b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list); 73097b2e202SAlex Deucher 73197b2e202SAlex Deucher /* 73297b2e202SAlex Deucher * GFX stuff 73397b2e202SAlex Deucher */ 73497b2e202SAlex Deucher #include "clearstate_defs.h" 73597b2e202SAlex Deucher 73679e5412cSAlex Deucher struct amdgpu_rlc_funcs { 73779e5412cSAlex Deucher void (*enter_safe_mode)(struct amdgpu_device *adev); 73879e5412cSAlex Deucher void (*exit_safe_mode)(struct amdgpu_device *adev); 73979e5412cSAlex Deucher }; 74079e5412cSAlex Deucher 74197b2e202SAlex Deucher struct amdgpu_rlc { 74297b2e202SAlex Deucher /* for power gating */ 74397b2e202SAlex Deucher struct amdgpu_bo *save_restore_obj; 74497b2e202SAlex Deucher uint64_t save_restore_gpu_addr; 74597b2e202SAlex Deucher volatile uint32_t *sr_ptr; 74697b2e202SAlex Deucher const u32 *reg_list; 74797b2e202SAlex Deucher u32 reg_list_size; 74897b2e202SAlex Deucher /* for clear state */ 74997b2e202SAlex Deucher struct amdgpu_bo *clear_state_obj; 75097b2e202SAlex Deucher uint64_t clear_state_gpu_addr; 75197b2e202SAlex Deucher volatile uint32_t *cs_ptr; 75297b2e202SAlex Deucher const struct cs_section_def *cs_data; 75397b2e202SAlex Deucher u32 clear_state_size; 75497b2e202SAlex Deucher /* for cp tables */ 75597b2e202SAlex Deucher struct amdgpu_bo *cp_table_obj; 75697b2e202SAlex Deucher uint64_t cp_table_gpu_addr; 75797b2e202SAlex Deucher volatile uint32_t *cp_table_ptr; 75897b2e202SAlex Deucher u32 cp_table_size; 75979e5412cSAlex Deucher 76079e5412cSAlex Deucher /* safe mode for updating CG/PG state */ 76179e5412cSAlex Deucher bool in_safe_mode; 76279e5412cSAlex Deucher const struct amdgpu_rlc_funcs *funcs; 7632b6cd977SEric Huang 7642b6cd977SEric Huang /* for firmware data */ 7652b6cd977SEric Huang u32 save_and_restore_offset; 7662b6cd977SEric Huang u32 clear_state_descriptor_offset; 7672b6cd977SEric Huang u32 avail_scratch_ram_locations; 7682b6cd977SEric Huang u32 reg_restore_list_size; 7692b6cd977SEric Huang u32 reg_list_format_start; 7702b6cd977SEric Huang u32 reg_list_format_separate_start; 7712b6cd977SEric Huang u32 starting_offsets_start; 7722b6cd977SEric Huang u32 reg_list_format_size_bytes; 7732b6cd977SEric Huang u32 reg_list_size_bytes; 7742b6cd977SEric Huang 7752b6cd977SEric Huang u32 *register_list_format; 7762b6cd977SEric Huang u32 *register_restore; 77797b2e202SAlex Deucher }; 77897b2e202SAlex Deucher 77978c16834SAndres Rodriguez #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES 78078c16834SAndres Rodriguez 78197b2e202SAlex Deucher struct amdgpu_mec { 78297b2e202SAlex Deucher struct amdgpu_bo *hpd_eop_obj; 78397b2e202SAlex Deucher u64 hpd_eop_gpu_addr; 784b1023571SKen Wang struct amdgpu_bo *mec_fw_obj; 785b1023571SKen Wang u64 mec_fw_gpu_addr; 78697b2e202SAlex Deucher u32 num_mec; 78742794b27SAndres Rodriguez u32 num_pipe_per_mec; 78842794b27SAndres Rodriguez u32 num_queue_per_pipe; 78959a82d7dSXiangliang Yu void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1]; 79078c16834SAndres Rodriguez 79178c16834SAndres Rodriguez /* These are the resources for which amdgpu takes ownership */ 79278c16834SAndres Rodriguez DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES); 79397b2e202SAlex Deucher }; 79497b2e202SAlex Deucher 7954e638ae9SXiangliang Yu struct amdgpu_kiq { 7964e638ae9SXiangliang Yu u64 eop_gpu_addr; 7974e638ae9SXiangliang Yu struct amdgpu_bo *eop_obj; 79843ca8efaSpding spinlock_t ring_lock; 7994e638ae9SXiangliang Yu struct amdgpu_ring ring; 8004e638ae9SXiangliang Yu struct amdgpu_irq_src irq; 8014e638ae9SXiangliang Yu }; 8024e638ae9SXiangliang Yu 80397b2e202SAlex Deucher /* 80497b2e202SAlex Deucher * GPU scratch registers structures, functions & helpers 80597b2e202SAlex Deucher */ 80697b2e202SAlex Deucher struct amdgpu_scratch { 80797b2e202SAlex Deucher unsigned num_reg; 80897b2e202SAlex Deucher uint32_t reg_base; 80950261151SNils Wallménius uint32_t free_mask; 81097b2e202SAlex Deucher }; 81197b2e202SAlex Deucher 81297b2e202SAlex Deucher /* 81397b2e202SAlex Deucher * GFX configurations 81497b2e202SAlex Deucher */ 815e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SE 4 816e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SH_PER_SE 2 817e3fa7630SAlex Deucher 818e3fa7630SAlex Deucher struct amdgpu_rb_config { 819e3fa7630SAlex Deucher uint32_t rb_backend_disable; 820e3fa7630SAlex Deucher uint32_t user_rb_backend_disable; 821e3fa7630SAlex Deucher uint32_t raster_config; 822e3fa7630SAlex Deucher uint32_t raster_config_1; 823e3fa7630SAlex Deucher }; 824e3fa7630SAlex Deucher 825d0e95758SAndrey Grodzovsky struct gb_addr_config { 826d0e95758SAndrey Grodzovsky uint16_t pipe_interleave_size; 827d0e95758SAndrey Grodzovsky uint8_t num_pipes; 828d0e95758SAndrey Grodzovsky uint8_t max_compress_frags; 829d0e95758SAndrey Grodzovsky uint8_t num_banks; 830d0e95758SAndrey Grodzovsky uint8_t num_se; 831d0e95758SAndrey Grodzovsky uint8_t num_rb_per_se; 832d0e95758SAndrey Grodzovsky }; 833d0e95758SAndrey Grodzovsky 834ea323f88SJunwei Zhang struct amdgpu_gfx_config { 83597b2e202SAlex Deucher unsigned max_shader_engines; 83697b2e202SAlex Deucher unsigned max_tile_pipes; 83797b2e202SAlex Deucher unsigned max_cu_per_sh; 83897b2e202SAlex Deucher unsigned max_sh_per_se; 83997b2e202SAlex Deucher unsigned max_backends_per_se; 84097b2e202SAlex Deucher unsigned max_texture_channel_caches; 84197b2e202SAlex Deucher unsigned max_gprs; 84297b2e202SAlex Deucher unsigned max_gs_threads; 84397b2e202SAlex Deucher unsigned max_hw_contexts; 84497b2e202SAlex Deucher unsigned sc_prim_fifo_size_frontend; 84597b2e202SAlex Deucher unsigned sc_prim_fifo_size_backend; 84697b2e202SAlex Deucher unsigned sc_hiz_tile_fifo_size; 84797b2e202SAlex Deucher unsigned sc_earlyz_tile_fifo_size; 84897b2e202SAlex Deucher 84997b2e202SAlex Deucher unsigned num_tile_pipes; 85097b2e202SAlex Deucher unsigned backend_enable_mask; 85197b2e202SAlex Deucher unsigned mem_max_burst_length_bytes; 85297b2e202SAlex Deucher unsigned mem_row_size_in_kb; 85397b2e202SAlex Deucher unsigned shader_engine_tile_size; 85497b2e202SAlex Deucher unsigned num_gpus; 85597b2e202SAlex Deucher unsigned multi_gpu_tile_size; 85697b2e202SAlex Deucher unsigned mc_arb_ramcfg; 85797b2e202SAlex Deucher unsigned gb_addr_config; 8588f8e00c1SAlex Deucher unsigned num_rbs; 859408bfe7cSJunwei Zhang unsigned gs_vgt_table_depth; 860408bfe7cSJunwei Zhang unsigned gs_prim_buffer_depth; 86197b2e202SAlex Deucher 86297b2e202SAlex Deucher uint32_t tile_mode_array[32]; 86397b2e202SAlex Deucher uint32_t macrotile_mode_array[16]; 864e3fa7630SAlex Deucher 865d0e95758SAndrey Grodzovsky struct gb_addr_config gb_addr_config_fields; 866e3fa7630SAlex Deucher struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE]; 867df6e2c4aSJunwei Zhang 868df6e2c4aSJunwei Zhang /* gfx configure feature */ 869df6e2c4aSJunwei Zhang uint32_t double_offchip_lds_buf; 87097b2e202SAlex Deucher }; 87197b2e202SAlex Deucher 8727dae69a2SAlex Deucher struct amdgpu_cu_info { 873ebdebf42SFlora Cui uint32_t simd_per_cu; 87451fd0370SHawking Zhang uint32_t max_waves_per_simd; 875408bfe7cSJunwei Zhang uint32_t wave_front_size; 87651fd0370SHawking Zhang uint32_t max_scratch_slots_per_cu; 87751fd0370SHawking Zhang uint32_t lds_size; 878dbfe85eaSFlora Cui 879dbfe85eaSFlora Cui /* total active CU number */ 880dbfe85eaSFlora Cui uint32_t number; 881dbfe85eaSFlora Cui uint32_t ao_cu_mask; 882dbfe85eaSFlora Cui uint32_t ao_cu_bitmap[4][4]; 8837dae69a2SAlex Deucher uint32_t bitmap[4][4]; 8847dae69a2SAlex Deucher }; 8857dae69a2SAlex Deucher 886b95e31fdSAlex Deucher struct amdgpu_gfx_funcs { 887b95e31fdSAlex Deucher /* get the gpu clock counter */ 888b95e31fdSAlex Deucher uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev); 8899559ef5bSTom St Denis void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance); 890472259f0STom St Denis void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields); 891c5a60ce8STom St Denis void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t thread, uint32_t start, uint32_t size, uint32_t *dst); 892c5a60ce8STom St Denis void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst); 893b95e31fdSAlex Deucher }; 894b95e31fdSAlex Deucher 895bce23e00SAlex Deucher struct amdgpu_ngg_buf { 896bce23e00SAlex Deucher struct amdgpu_bo *bo; 897bce23e00SAlex Deucher uint64_t gpu_addr; 898bce23e00SAlex Deucher uint32_t size; 899bce23e00SAlex Deucher uint32_t bo_size; 900bce23e00SAlex Deucher }; 901bce23e00SAlex Deucher 902bce23e00SAlex Deucher enum { 903af8baf15SGuenter Roeck NGG_PRIM = 0, 904af8baf15SGuenter Roeck NGG_POS, 905af8baf15SGuenter Roeck NGG_CNTL, 906af8baf15SGuenter Roeck NGG_PARAM, 907bce23e00SAlex Deucher NGG_BUF_MAX 908bce23e00SAlex Deucher }; 909bce23e00SAlex Deucher 910bce23e00SAlex Deucher struct amdgpu_ngg { 911bce23e00SAlex Deucher struct amdgpu_ngg_buf buf[NGG_BUF_MAX]; 912bce23e00SAlex Deucher uint32_t gds_reserve_addr; 913bce23e00SAlex Deucher uint32_t gds_reserve_size; 914bce23e00SAlex Deucher bool init; 915bce23e00SAlex Deucher }; 916bce23e00SAlex Deucher 91797b2e202SAlex Deucher struct amdgpu_gfx { 91897b2e202SAlex Deucher struct mutex gpu_clock_mutex; 919ea323f88SJunwei Zhang struct amdgpu_gfx_config config; 92097b2e202SAlex Deucher struct amdgpu_rlc rlc; 92197b2e202SAlex Deucher struct amdgpu_mec mec; 9224e638ae9SXiangliang Yu struct amdgpu_kiq kiq; 92397b2e202SAlex Deucher struct amdgpu_scratch scratch; 92497b2e202SAlex Deucher const struct firmware *me_fw; /* ME firmware */ 92597b2e202SAlex Deucher uint32_t me_fw_version; 92697b2e202SAlex Deucher const struct firmware *pfp_fw; /* PFP firmware */ 92797b2e202SAlex Deucher uint32_t pfp_fw_version; 92897b2e202SAlex Deucher const struct firmware *ce_fw; /* CE firmware */ 92997b2e202SAlex Deucher uint32_t ce_fw_version; 93097b2e202SAlex Deucher const struct firmware *rlc_fw; /* RLC firmware */ 93197b2e202SAlex Deucher uint32_t rlc_fw_version; 93297b2e202SAlex Deucher const struct firmware *mec_fw; /* MEC firmware */ 93397b2e202SAlex Deucher uint32_t mec_fw_version; 93497b2e202SAlex Deucher const struct firmware *mec2_fw; /* MEC2 firmware */ 93597b2e202SAlex Deucher uint32_t mec2_fw_version; 93602558a00SKen Wang uint32_t me_feature_version; 93702558a00SKen Wang uint32_t ce_feature_version; 93802558a00SKen Wang uint32_t pfp_feature_version; 939351643d7SJammy Zhou uint32_t rlc_feature_version; 940351643d7SJammy Zhou uint32_t mec_feature_version; 941351643d7SJammy Zhou uint32_t mec2_feature_version; 94297b2e202SAlex Deucher struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS]; 94397b2e202SAlex Deucher unsigned num_gfx_rings; 94497b2e202SAlex Deucher struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS]; 94597b2e202SAlex Deucher unsigned num_compute_rings; 94697b2e202SAlex Deucher struct amdgpu_irq_src eop_irq; 94797b2e202SAlex Deucher struct amdgpu_irq_src priv_reg_irq; 94897b2e202SAlex Deucher struct amdgpu_irq_src priv_inst_irq; 94997b2e202SAlex Deucher /* gfx status */ 95097b2e202SAlex Deucher uint32_t gfx_current_status; 951a101a899SKen Wang /* ce ram size*/ 952a101a899SKen Wang unsigned ce_ram_size; 9537dae69a2SAlex Deucher struct amdgpu_cu_info cu_info; 954b95e31fdSAlex Deucher const struct amdgpu_gfx_funcs *funcs; 9553d7c6384SChunming Zhou 9563d7c6384SChunming Zhou /* reset mask */ 9573d7c6384SChunming Zhou uint32_t grbm_soft_reset; 9583d7c6384SChunming Zhou uint32_t srbm_soft_reset; 959b4e40676SDavid Panariti /* s3/s4 mask */ 960b4e40676SDavid Panariti bool in_suspend; 961bce23e00SAlex Deucher /* NGG */ 962bce23e00SAlex Deucher struct amdgpu_ngg ngg; 963b8866c26SAndres Rodriguez 964b8866c26SAndres Rodriguez /* pipe reservation */ 965b8866c26SAndres Rodriguez struct mutex pipe_reserve_mutex; 966b8866c26SAndres Rodriguez DECLARE_BITMAP (pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES); 96797b2e202SAlex Deucher }; 96897b2e202SAlex Deucher 969b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, 97097b2e202SAlex Deucher unsigned size, struct amdgpu_ib *ib); 9714d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, 972f54d1867SChris Wilson struct dma_fence *f); 973b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, 97450ddc75eSJunwei Zhang struct amdgpu_ib *ibs, struct amdgpu_job *job, 97550ddc75eSJunwei Zhang struct dma_fence **f); 97697b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev); 97797b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev); 97897b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev); 97997b2e202SAlex Deucher 98097b2e202SAlex Deucher /* 98197b2e202SAlex Deucher * CS. 98297b2e202SAlex Deucher */ 98397b2e202SAlex Deucher struct amdgpu_cs_chunk { 98497b2e202SAlex Deucher uint32_t chunk_id; 98597b2e202SAlex Deucher uint32_t length_dw; 986758ac17fSChristian König void *kdata; 98797b2e202SAlex Deucher }; 98897b2e202SAlex Deucher 98997b2e202SAlex Deucher struct amdgpu_cs_parser { 99097b2e202SAlex Deucher struct amdgpu_device *adev; 99197b2e202SAlex Deucher struct drm_file *filp; 9923cb485f3SChristian König struct amdgpu_ctx *ctx; 993c3cca41eSChristian König 99497b2e202SAlex Deucher /* chunks */ 99597b2e202SAlex Deucher unsigned nchunks; 99697b2e202SAlex Deucher struct amdgpu_cs_chunk *chunks; 997c3cca41eSChristian König 99850838c8cSChristian König /* scheduler job object */ 99950838c8cSChristian König struct amdgpu_job *job; 1000c3cca41eSChristian König 1001c3cca41eSChristian König /* buffer objects */ 1002c3cca41eSChristian König struct ww_acquire_ctx ticket; 1003c3cca41eSChristian König struct amdgpu_bo_list *bo_list; 10043fe89771SChristian König struct amdgpu_mn *mn; 100556467ebfSChristian König struct amdgpu_bo_list_entry vm_pd; 100697b2e202SAlex Deucher struct list_head validated; 1007f54d1867SChris Wilson struct dma_fence *fence; 1008f69f90a1SChristian König uint64_t bytes_moved_threshold; 100900f06b24SJohn Brooks uint64_t bytes_moved_vis_threshold; 1010f69f90a1SChristian König uint64_t bytes_moved; 101100f06b24SJohn Brooks uint64_t bytes_moved_vis; 1012662bfa61SChristian König struct amdgpu_bo_list_entry *evictable; 101397b2e202SAlex Deucher 101497b2e202SAlex Deucher /* user fence */ 101591acbeb6SChristian König struct amdgpu_bo_list_entry uf_entry; 1016660e8558SDave Airlie 1017660e8558SDave Airlie unsigned num_post_dep_syncobjs; 1018660e8558SDave Airlie struct drm_syncobj **post_dep_syncobjs; 101997b2e202SAlex Deucher }; 102097b2e202SAlex Deucher 1021753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */ 1022753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */ 1023753ad49cSMonk Liu #define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */ 1024753ad49cSMonk Liu 1025bb977d37SChunming Zhou struct amdgpu_job { 10261b1f42d8SLucas Stach struct drm_sched_job base; 1027bb977d37SChunming Zhou struct amdgpu_device *adev; 1028c5637837SMonk Liu struct amdgpu_vm *vm; 1029b07c60c0SChristian König struct amdgpu_ring *ring; 1030e86f9ceeSChristian König struct amdgpu_sync sync; 1031df83d1ebSChunming Zhou struct amdgpu_sync sched_sync; 1032bb977d37SChunming Zhou struct amdgpu_ib *ibs; 1033f54d1867SChris Wilson struct dma_fence *fence; /* the hw fence */ 1034753ad49cSMonk Liu uint32_t preamble_status; 1035bb977d37SChunming Zhou uint32_t num_ibs; 1036e2840221SChristian König void *owner; 10373aecd24cSMonk Liu uint64_t fence_ctx; /* the fence_context this job uses */ 1038fd53be30SChunming Zhou bool vm_needs_flush; 1039d88bf583SChristian König uint64_t vm_pd_addr; 10405a4633c4SChristian König unsigned vmid; 10415a4633c4SChristian König unsigned pasid; 1042d88bf583SChristian König uint32_t gds_base, gds_size; 1043d88bf583SChristian König uint32_t gws_base, gws_size; 1044d88bf583SChristian König uint32_t oa_base, oa_size; 104514e47f93SChristian König uint32_t vram_lost_counter; 1046758ac17fSChristian König 1047758ac17fSChristian König /* user fence handling */ 1048b5f5acbcSChristian König uint64_t uf_addr; 1049758ac17fSChristian König uint64_t uf_sequence; 1050758ac17fSChristian König 1051bb977d37SChunming Zhou }; 1052a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job) \ 1053a6db8a33SJunwei Zhang container_of((sched_job), struct amdgpu_job, base) 1054bb977d37SChunming Zhou 10557270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, 10567270f839SChristian König uint32_t ib_idx, int idx) 105797b2e202SAlex Deucher { 105850838c8cSChristian König return p->job->ibs[ib_idx].ptr[idx]; 105997b2e202SAlex Deucher } 106097b2e202SAlex Deucher 10617270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p, 10627270f839SChristian König uint32_t ib_idx, int idx, 10637270f839SChristian König uint32_t value) 10647270f839SChristian König { 106550838c8cSChristian König p->job->ibs[ib_idx].ptr[idx] = value; 10667270f839SChristian König } 10677270f839SChristian König 106897b2e202SAlex Deucher /* 106997b2e202SAlex Deucher * Writeback 107097b2e202SAlex Deucher */ 107173469585SMonk Liu #define AMDGPU_MAX_WB 128 /* Reserve at most 128 WB slots for amdgpu-owned rings. */ 107297b2e202SAlex Deucher 107397b2e202SAlex Deucher struct amdgpu_wb { 107497b2e202SAlex Deucher struct amdgpu_bo *wb_obj; 107597b2e202SAlex Deucher volatile uint32_t *wb; 107697b2e202SAlex Deucher uint64_t gpu_addr; 107797b2e202SAlex Deucher u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */ 107897b2e202SAlex Deucher unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)]; 107997b2e202SAlex Deucher }; 108097b2e202SAlex Deucher 1081131b4b36SAlex Deucher int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb); 1082131b4b36SAlex Deucher void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb); 108397b2e202SAlex Deucher 1084041d9d93SAlex Deucher void amdgpu_device_get_pcie_info(struct amdgpu_device *adev); 1085d0dd7f0cSAlex Deucher 108697b2e202SAlex Deucher /* 108797b2e202SAlex Deucher * SDMA 108897b2e202SAlex Deucher */ 1089c113ea1cSAlex Deucher struct amdgpu_sdma_instance { 109097b2e202SAlex Deucher /* SDMA firmware */ 109197b2e202SAlex Deucher const struct firmware *fw; 109297b2e202SAlex Deucher uint32_t fw_version; 1093cfa2104fSJammy Zhou uint32_t feature_version; 109497b2e202SAlex Deucher 109597b2e202SAlex Deucher struct amdgpu_ring ring; 109618111de0SJammy Zhou bool burst_nop; 109797b2e202SAlex Deucher }; 109897b2e202SAlex Deucher 1099c113ea1cSAlex Deucher struct amdgpu_sdma { 1100c113ea1cSAlex Deucher struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES]; 110130d1574fSKen Wang #ifdef CONFIG_DRM_AMDGPU_SI 110230d1574fSKen Wang //SI DMA has a difference trap irq number for the second engine 110330d1574fSKen Wang struct amdgpu_irq_src trap_irq_1; 110430d1574fSKen Wang #endif 1105c113ea1cSAlex Deucher struct amdgpu_irq_src trap_irq; 1106c113ea1cSAlex Deucher struct amdgpu_irq_src illegal_inst_irq; 1107c113ea1cSAlex Deucher int num_instances; 1108e702a680SChunming Zhou uint32_t srbm_soft_reset; 1109c113ea1cSAlex Deucher }; 1110c113ea1cSAlex Deucher 111197b2e202SAlex Deucher /* 111297b2e202SAlex Deucher * Firmware 111397b2e202SAlex Deucher */ 1114e635ee07SHuang Rui enum amdgpu_firmware_load_type { 1115e635ee07SHuang Rui AMDGPU_FW_LOAD_DIRECT = 0, 1116e635ee07SHuang Rui AMDGPU_FW_LOAD_SMU, 1117e635ee07SHuang Rui AMDGPU_FW_LOAD_PSP, 1118e635ee07SHuang Rui }; 1119e635ee07SHuang Rui 112097b2e202SAlex Deucher struct amdgpu_firmware { 112197b2e202SAlex Deucher struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM]; 1122e635ee07SHuang Rui enum amdgpu_firmware_load_type load_type; 112397b2e202SAlex Deucher struct amdgpu_bo *fw_buf; 112497b2e202SAlex Deucher unsigned int fw_size; 11252445b227SHuang Rui unsigned int max_ucodes; 11260e5ca0d1SHuang Rui /* firmwares are loaded by psp instead of smu from vega10 */ 11270e5ca0d1SHuang Rui const struct amdgpu_psp_funcs *funcs; 11280e5ca0d1SHuang Rui struct amdgpu_bo *rbuf; 11290e5ca0d1SHuang Rui struct mutex mutex; 1130ab4fe3e1SHuang Rui 1131ab4fe3e1SHuang Rui /* gpu info firmware data pointer */ 1132ab4fe3e1SHuang Rui const struct firmware *gpu_info_fw; 1133d59c026bSMonk Liu 1134d59c026bSMonk Liu void *fw_buf_ptr; 1135d59c026bSMonk Liu uint64_t fw_buf_mc; 113697b2e202SAlex Deucher }; 113797b2e202SAlex Deucher 113897b2e202SAlex Deucher /* 113997b2e202SAlex Deucher * Benchmarking 114097b2e202SAlex Deucher */ 114197b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number); 114297b2e202SAlex Deucher 114397b2e202SAlex Deucher 114497b2e202SAlex Deucher /* 114597b2e202SAlex Deucher * Testing 114697b2e202SAlex Deucher */ 114797b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev); 114897b2e202SAlex Deucher 114950ab2533SHuang Rui 115097b2e202SAlex Deucher /* 115197b2e202SAlex Deucher * amdgpu smumgr functions 115297b2e202SAlex Deucher */ 115397b2e202SAlex Deucher struct amdgpu_smumgr_funcs { 115497b2e202SAlex Deucher int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype); 115597b2e202SAlex Deucher int (*request_smu_load_fw)(struct amdgpu_device *adev); 115697b2e202SAlex Deucher int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype); 115797b2e202SAlex Deucher }; 115897b2e202SAlex Deucher 115997b2e202SAlex Deucher /* 116097b2e202SAlex Deucher * amdgpu smumgr 116197b2e202SAlex Deucher */ 116297b2e202SAlex Deucher struct amdgpu_smumgr { 116397b2e202SAlex Deucher struct amdgpu_bo *toc_buf; 116497b2e202SAlex Deucher struct amdgpu_bo *smu_buf; 116597b2e202SAlex Deucher /* asic priv smu data */ 116697b2e202SAlex Deucher void *priv; 116797b2e202SAlex Deucher spinlock_t smu_lock; 116897b2e202SAlex Deucher /* smumgr functions */ 116997b2e202SAlex Deucher const struct amdgpu_smumgr_funcs *smumgr_funcs; 117097b2e202SAlex Deucher /* ucode loading complete flag */ 117197b2e202SAlex Deucher uint32_t fw_flags; 117297b2e202SAlex Deucher }; 117397b2e202SAlex Deucher 117497b2e202SAlex Deucher /* 117597b2e202SAlex Deucher * ASIC specific register table accessible by UMD 117697b2e202SAlex Deucher */ 117797b2e202SAlex Deucher struct amdgpu_allowed_register_entry { 117897b2e202SAlex Deucher uint32_t reg_offset; 117997b2e202SAlex Deucher bool grbm_indexed; 118097b2e202SAlex Deucher }; 118197b2e202SAlex Deucher 118297b2e202SAlex Deucher /* 118397b2e202SAlex Deucher * ASIC specific functions. 118497b2e202SAlex Deucher */ 118597b2e202SAlex Deucher struct amdgpu_asic_funcs { 118697b2e202SAlex Deucher bool (*read_disabled_bios)(struct amdgpu_device *adev); 11877946b878SAlex Deucher bool (*read_bios_from_rom)(struct amdgpu_device *adev, 11887946b878SAlex Deucher u8 *bios, u32 length_bytes); 118997b2e202SAlex Deucher int (*read_register)(struct amdgpu_device *adev, u32 se_num, 119097b2e202SAlex Deucher u32 sh_num, u32 reg_offset, u32 *value); 119197b2e202SAlex Deucher void (*set_vga_state)(struct amdgpu_device *adev, bool state); 119297b2e202SAlex Deucher int (*reset)(struct amdgpu_device *adev); 119397b2e202SAlex Deucher /* get the reference clock */ 119497b2e202SAlex Deucher u32 (*get_xclk)(struct amdgpu_device *adev); 119597b2e202SAlex Deucher /* MM block clocks */ 119697b2e202SAlex Deucher int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk); 119797b2e202SAlex Deucher int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk); 1198841686dfSMaruthi Bayyavarapu /* static power management */ 1199841686dfSMaruthi Bayyavarapu int (*get_pcie_lanes)(struct amdgpu_device *adev); 1200841686dfSMaruthi Bayyavarapu void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes); 1201bbf282d8SAlex Deucher /* get config memsize register */ 1202bbf282d8SAlex Deucher u32 (*get_config_memsize)(struct amdgpu_device *adev); 12032df1b8b6SAlex Deucher /* flush hdp write queue */ 120469882565SChristian König void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring); 12052df1b8b6SAlex Deucher /* invalidate hdp read cache */ 120669882565SChristian König void (*invalidate_hdp)(struct amdgpu_device *adev, 120769882565SChristian König struct amdgpu_ring *ring); 120897b2e202SAlex Deucher }; 120997b2e202SAlex Deucher 121097b2e202SAlex Deucher /* 121197b2e202SAlex Deucher * IOCTL. 121297b2e202SAlex Deucher */ 121397b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, 121497b2e202SAlex Deucher struct drm_file *filp); 121597b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, 121697b2e202SAlex Deucher struct drm_file *filp); 121797b2e202SAlex Deucher 121897b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, 121997b2e202SAlex Deucher struct drm_file *filp); 122097b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, 122197b2e202SAlex Deucher struct drm_file *filp); 122297b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data, 122397b2e202SAlex Deucher struct drm_file *filp); 122497b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data, 122597b2e202SAlex Deucher struct drm_file *filp); 122697b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, 122797b2e202SAlex Deucher struct drm_file *filp); 122897b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, 122997b2e202SAlex Deucher struct drm_file *filp); 123097b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 12317ca24cf2SMarek Olšák int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data, 12327ca24cf2SMarek Olšák struct drm_file *filp); 123397b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 1234eef18a82SJunwei Zhang int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, 1235eef18a82SJunwei Zhang struct drm_file *filp); 123697b2e202SAlex Deucher 123797b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data, 123897b2e202SAlex Deucher struct drm_file *filp); 123997b2e202SAlex Deucher 124097b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */ 124197b2e202SAlex Deucher struct amdgpu_vram_scratch { 124297b2e202SAlex Deucher struct amdgpu_bo *robj; 124397b2e202SAlex Deucher volatile uint32_t *ptr; 124497b2e202SAlex Deucher u64 gpu_addr; 124597b2e202SAlex Deucher }; 124697b2e202SAlex Deucher 124797b2e202SAlex Deucher /* 124897b2e202SAlex Deucher * ACPI 124997b2e202SAlex Deucher */ 125097b2e202SAlex Deucher struct amdgpu_atif_notification_cfg { 125197b2e202SAlex Deucher bool enabled; 125297b2e202SAlex Deucher int command_code; 125397b2e202SAlex Deucher }; 125497b2e202SAlex Deucher 125597b2e202SAlex Deucher struct amdgpu_atif_notifications { 125697b2e202SAlex Deucher bool display_switch; 125797b2e202SAlex Deucher bool expansion_mode_change; 125897b2e202SAlex Deucher bool thermal_state; 125997b2e202SAlex Deucher bool forced_power_state; 126097b2e202SAlex Deucher bool system_power_state; 126197b2e202SAlex Deucher bool display_conf_change; 126297b2e202SAlex Deucher bool px_gfx_switch; 126397b2e202SAlex Deucher bool brightness_change; 126497b2e202SAlex Deucher bool dgpu_display_event; 126597b2e202SAlex Deucher }; 126697b2e202SAlex Deucher 126797b2e202SAlex Deucher struct amdgpu_atif_functions { 126897b2e202SAlex Deucher bool system_params; 126997b2e202SAlex Deucher bool sbios_requests; 127097b2e202SAlex Deucher bool select_active_disp; 127197b2e202SAlex Deucher bool lid_state; 127297b2e202SAlex Deucher bool get_tv_standard; 127397b2e202SAlex Deucher bool set_tv_standard; 127497b2e202SAlex Deucher bool get_panel_expansion_mode; 127597b2e202SAlex Deucher bool set_panel_expansion_mode; 127697b2e202SAlex Deucher bool temperature_change; 127797b2e202SAlex Deucher bool graphics_device_types; 127897b2e202SAlex Deucher }; 127997b2e202SAlex Deucher 128097b2e202SAlex Deucher struct amdgpu_atif { 128197b2e202SAlex Deucher struct amdgpu_atif_notifications notifications; 128297b2e202SAlex Deucher struct amdgpu_atif_functions functions; 128397b2e202SAlex Deucher struct amdgpu_atif_notification_cfg notification_cfg; 128497b2e202SAlex Deucher struct amdgpu_encoder *encoder_for_bl; 128597b2e202SAlex Deucher }; 128697b2e202SAlex Deucher 128797b2e202SAlex Deucher struct amdgpu_atcs_functions { 128897b2e202SAlex Deucher bool get_ext_state; 128997b2e202SAlex Deucher bool pcie_perf_req; 129097b2e202SAlex Deucher bool pcie_dev_rdy; 129197b2e202SAlex Deucher bool pcie_bus_width; 129297b2e202SAlex Deucher }; 129397b2e202SAlex Deucher 129497b2e202SAlex Deucher struct amdgpu_atcs { 129597b2e202SAlex Deucher struct amdgpu_atcs_functions functions; 129697b2e202SAlex Deucher }; 129797b2e202SAlex Deucher 129897b2e202SAlex Deucher /* 1299a05502e5SHorace Chen * Firmware VRAM reservation 1300a05502e5SHorace Chen */ 1301a05502e5SHorace Chen struct amdgpu_fw_vram_usage { 1302a05502e5SHorace Chen u64 start_offset; 1303a05502e5SHorace Chen u64 size; 1304a05502e5SHorace Chen struct amdgpu_bo *reserved_bo; 1305a05502e5SHorace Chen void *va; 1306a05502e5SHorace Chen }; 1307a05502e5SHorace Chen 1308a05502e5SHorace Chen /* 1309d03846afSChunming Zhou * CGS 1310d03846afSChunming Zhou */ 1311110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev); 1312110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device); 1313a8fe58ceSMaruthi Bayyavarapu 1314a8fe58ceSMaruthi Bayyavarapu /* 131597b2e202SAlex Deucher * Core structure, functions and helpers. 131697b2e202SAlex Deucher */ 131797b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t); 131897b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 131997b2e202SAlex Deucher 132097b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 132197b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t); 132297b2e202SAlex Deucher 1323946a4d5bSShaoyun Liu 1324946a4d5bSShaoyun Liu /* 1325946a4d5bSShaoyun Liu * amdgpu nbio functions 1326946a4d5bSShaoyun Liu * 1327946a4d5bSShaoyun Liu */ 1328bf383fb6SAlex Deucher struct nbio_hdp_flush_reg { 1329bf383fb6SAlex Deucher u32 ref_and_mask_cp0; 1330bf383fb6SAlex Deucher u32 ref_and_mask_cp1; 1331bf383fb6SAlex Deucher u32 ref_and_mask_cp2; 1332bf383fb6SAlex Deucher u32 ref_and_mask_cp3; 1333bf383fb6SAlex Deucher u32 ref_and_mask_cp4; 1334bf383fb6SAlex Deucher u32 ref_and_mask_cp5; 1335bf383fb6SAlex Deucher u32 ref_and_mask_cp6; 1336bf383fb6SAlex Deucher u32 ref_and_mask_cp7; 1337bf383fb6SAlex Deucher u32 ref_and_mask_cp8; 1338bf383fb6SAlex Deucher u32 ref_and_mask_cp9; 1339bf383fb6SAlex Deucher u32 ref_and_mask_sdma0; 1340bf383fb6SAlex Deucher u32 ref_and_mask_sdma1; 1341bf383fb6SAlex Deucher }; 1342946a4d5bSShaoyun Liu 1343946a4d5bSShaoyun Liu struct amdgpu_nbio_funcs { 1344bf383fb6SAlex Deucher const struct nbio_hdp_flush_reg *hdp_flush_reg; 1345bf383fb6SAlex Deucher u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev); 1346bf383fb6SAlex Deucher u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev); 1347bf383fb6SAlex Deucher u32 (*get_pcie_index_offset)(struct amdgpu_device *adev); 1348bf383fb6SAlex Deucher u32 (*get_pcie_data_offset)(struct amdgpu_device *adev); 1349bf383fb6SAlex Deucher u32 (*get_rev_id)(struct amdgpu_device *adev); 1350bf383fb6SAlex Deucher void (*mc_access_enable)(struct amdgpu_device *adev, bool enable); 135169882565SChristian König void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring); 1352bf383fb6SAlex Deucher u32 (*get_memsize)(struct amdgpu_device *adev); 1353bf383fb6SAlex Deucher void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance, 1354bf383fb6SAlex Deucher bool use_doorbell, int doorbell_index); 1355bf383fb6SAlex Deucher void (*enable_doorbell_aperture)(struct amdgpu_device *adev, 1356bf383fb6SAlex Deucher bool enable); 1357bf383fb6SAlex Deucher void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev, 1358bf383fb6SAlex Deucher bool enable); 1359bf383fb6SAlex Deucher void (*ih_doorbell_range)(struct amdgpu_device *adev, 1360bf383fb6SAlex Deucher bool use_doorbell, int doorbell_index); 1361bf383fb6SAlex Deucher void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev, 1362bf383fb6SAlex Deucher bool enable); 1363bf383fb6SAlex Deucher void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev, 1364bf383fb6SAlex Deucher bool enable); 1365bf383fb6SAlex Deucher void (*get_clockgating_state)(struct amdgpu_device *adev, 1366bf383fb6SAlex Deucher u32 *flags); 1367bf383fb6SAlex Deucher void (*ih_control)(struct amdgpu_device *adev); 1368bf383fb6SAlex Deucher void (*init_registers)(struct amdgpu_device *adev); 1369bf383fb6SAlex Deucher void (*detect_hw_virt)(struct amdgpu_device *adev); 1370946a4d5bSShaoyun Liu }; 1371946a4d5bSShaoyun Liu 1372946a4d5bSShaoyun Liu 13734522824cSShaoyun Liu /* Define the HW IP blocks will be used in driver , add more if necessary */ 13744522824cSShaoyun Liu enum amd_hw_ip_block_type { 13754522824cSShaoyun Liu GC_HWIP = 1, 13764522824cSShaoyun Liu HDP_HWIP, 13774522824cSShaoyun Liu SDMA0_HWIP, 13784522824cSShaoyun Liu SDMA1_HWIP, 13794522824cSShaoyun Liu MMHUB_HWIP, 13804522824cSShaoyun Liu ATHUB_HWIP, 13814522824cSShaoyun Liu NBIO_HWIP, 13824522824cSShaoyun Liu MP0_HWIP, 13834522824cSShaoyun Liu UVD_HWIP, 13844522824cSShaoyun Liu VCN_HWIP = UVD_HWIP, 13854522824cSShaoyun Liu VCE_HWIP, 13864522824cSShaoyun Liu DF_HWIP, 13874522824cSShaoyun Liu DCE_HWIP, 13884522824cSShaoyun Liu OSSSYS_HWIP, 13894522824cSShaoyun Liu SMUIO_HWIP, 13904522824cSShaoyun Liu PWR_HWIP, 13914522824cSShaoyun Liu NBIF_HWIP, 13924522824cSShaoyun Liu MAX_HWIP 13934522824cSShaoyun Liu }; 13944522824cSShaoyun Liu 13954522824cSShaoyun Liu #define HWIP_MAX_INSTANCE 6 13964522824cSShaoyun Liu 139711dc9364SRex Zhu struct amd_powerplay { 139811dc9364SRex Zhu struct cgs_device *cgs_device; 139911dc9364SRex Zhu void *pp_handle; 140011dc9364SRex Zhu const struct amd_ip_funcs *ip_funcs; 140111dc9364SRex Zhu const struct amd_pm_funcs *pp_funcs; 140211dc9364SRex Zhu }; 140311dc9364SRex Zhu 14040c49e0b8SChunming Zhou #define AMDGPU_RESET_MAGIC_NUM 64 140597b2e202SAlex Deucher struct amdgpu_device { 140697b2e202SAlex Deucher struct device *dev; 140797b2e202SAlex Deucher struct drm_device *ddev; 140897b2e202SAlex Deucher struct pci_dev *pdev; 140997b2e202SAlex Deucher 1410a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP 1411a8fe58ceSMaruthi Bayyavarapu struct amdgpu_acp acp; 1412a8fe58ceSMaruthi Bayyavarapu #endif 1413a8fe58ceSMaruthi Bayyavarapu 141497b2e202SAlex Deucher /* ASIC */ 14152f7d10b3SJammy Zhou enum amd_asic_type asic_type; 141697b2e202SAlex Deucher uint32_t family; 141797b2e202SAlex Deucher uint32_t rev_id; 141897b2e202SAlex Deucher uint32_t external_rev_id; 141997b2e202SAlex Deucher unsigned long flags; 142097b2e202SAlex Deucher int usec_timeout; 142197b2e202SAlex Deucher const struct amdgpu_asic_funcs *asic_funcs; 142297b2e202SAlex Deucher bool shutdown; 142397b2e202SAlex Deucher bool need_dma32; 1424fd5fd480SChunming Zhou bool need_swiotlb; 142597b2e202SAlex Deucher bool accel_working; 142697b2e202SAlex Deucher struct work_struct reset_work; 142797b2e202SAlex Deucher struct notifier_block acpi_nb; 142897b2e202SAlex Deucher struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS]; 142997b2e202SAlex Deucher struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 143097b2e202SAlex Deucher unsigned debugfs_count; 143197b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS) 1432adcec288STom St Denis struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 143397b2e202SAlex Deucher #endif 143497b2e202SAlex Deucher struct amdgpu_atif atif; 143597b2e202SAlex Deucher struct amdgpu_atcs atcs; 143697b2e202SAlex Deucher struct mutex srbm_mutex; 143797b2e202SAlex Deucher /* GRBM index mutex. Protects concurrent access to GRBM index */ 143897b2e202SAlex Deucher struct mutex grbm_idx_mutex; 143997b2e202SAlex Deucher struct dev_pm_domain vga_pm_domain; 144097b2e202SAlex Deucher bool have_disp_power_ref; 144197b2e202SAlex Deucher 144297b2e202SAlex Deucher /* BIOS */ 14430cdd5005SAlex Deucher bool is_atom_fw; 144497b2e202SAlex Deucher uint8_t *bios; 1445a9f5db9cSEvan Quan uint32_t bios_size; 14465af2c10dSKent Russell struct amdgpu_bo *stolen_vga_memory; 1447a5bde2f9SAlex Deucher uint32_t bios_scratch_reg_offset; 144897b2e202SAlex Deucher uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH]; 144997b2e202SAlex Deucher 145097b2e202SAlex Deucher /* Register/doorbell mmio */ 145197b2e202SAlex Deucher resource_size_t rmmio_base; 145297b2e202SAlex Deucher resource_size_t rmmio_size; 145397b2e202SAlex Deucher void __iomem *rmmio; 145497b2e202SAlex Deucher /* protects concurrent MM_INDEX/DATA based register access */ 145597b2e202SAlex Deucher spinlock_t mmio_idx_lock; 145697b2e202SAlex Deucher /* protects concurrent SMC based register access */ 145797b2e202SAlex Deucher spinlock_t smc_idx_lock; 145897b2e202SAlex Deucher amdgpu_rreg_t smc_rreg; 145997b2e202SAlex Deucher amdgpu_wreg_t smc_wreg; 146097b2e202SAlex Deucher /* protects concurrent PCIE register access */ 146197b2e202SAlex Deucher spinlock_t pcie_idx_lock; 146297b2e202SAlex Deucher amdgpu_rreg_t pcie_rreg; 146397b2e202SAlex Deucher amdgpu_wreg_t pcie_wreg; 146436b9a952SHuang Rui amdgpu_rreg_t pciep_rreg; 146536b9a952SHuang Rui amdgpu_wreg_t pciep_wreg; 146697b2e202SAlex Deucher /* protects concurrent UVD register access */ 146797b2e202SAlex Deucher spinlock_t uvd_ctx_idx_lock; 146897b2e202SAlex Deucher amdgpu_rreg_t uvd_ctx_rreg; 146997b2e202SAlex Deucher amdgpu_wreg_t uvd_ctx_wreg; 147097b2e202SAlex Deucher /* protects concurrent DIDT register access */ 147197b2e202SAlex Deucher spinlock_t didt_idx_lock; 147297b2e202SAlex Deucher amdgpu_rreg_t didt_rreg; 147397b2e202SAlex Deucher amdgpu_wreg_t didt_wreg; 1474ccdbb20aSRex Zhu /* protects concurrent gc_cac register access */ 1475ccdbb20aSRex Zhu spinlock_t gc_cac_idx_lock; 1476ccdbb20aSRex Zhu amdgpu_rreg_t gc_cac_rreg; 1477ccdbb20aSRex Zhu amdgpu_wreg_t gc_cac_wreg; 147816abb5d2SEvan Quan /* protects concurrent se_cac register access */ 147916abb5d2SEvan Quan spinlock_t se_cac_idx_lock; 148016abb5d2SEvan Quan amdgpu_rreg_t se_cac_rreg; 148116abb5d2SEvan Quan amdgpu_wreg_t se_cac_wreg; 148297b2e202SAlex Deucher /* protects concurrent ENDPOINT (audio) register access */ 148397b2e202SAlex Deucher spinlock_t audio_endpt_idx_lock; 148497b2e202SAlex Deucher amdgpu_block_rreg_t audio_endpt_rreg; 148597b2e202SAlex Deucher amdgpu_block_wreg_t audio_endpt_wreg; 148697b2e202SAlex Deucher void __iomem *rio_mem; 148797b2e202SAlex Deucher resource_size_t rio_mem_size; 148897b2e202SAlex Deucher struct amdgpu_doorbell doorbell; 148997b2e202SAlex Deucher 149097b2e202SAlex Deucher /* clock/pll info */ 149197b2e202SAlex Deucher struct amdgpu_clock clock; 149297b2e202SAlex Deucher 149397b2e202SAlex Deucher /* MC */ 1494770d13b1SChristian König struct amdgpu_gmc gmc; 149597b2e202SAlex Deucher struct amdgpu_gart gart; 149692e71b06SChristian König dma_addr_t dummy_page_addr; 149797b2e202SAlex Deucher struct amdgpu_vm_manager vm_manager; 1498e60f8db5SAlex Xie struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS]; 149997b2e202SAlex Deucher 150097b2e202SAlex Deucher /* memory management */ 150197b2e202SAlex Deucher struct amdgpu_mman mman; 150297b2e202SAlex Deucher struct amdgpu_vram_scratch vram_scratch; 150397b2e202SAlex Deucher struct amdgpu_wb wb; 150497b2e202SAlex Deucher atomic64_t num_bytes_moved; 1505dbd5ed60SChristian König atomic64_t num_evictions; 150668e2c5ffSMarek Olšák atomic64_t num_vram_cpu_page_faults; 1507d94aed5aSMarek Olšák atomic_t gpu_reset_counter; 1508f1892138SChunming Zhou atomic_t vram_lost_counter; 150997b2e202SAlex Deucher 151095844d20SMarek Olšák /* data for buffer migration throttling */ 151195844d20SMarek Olšák struct { 151295844d20SMarek Olšák spinlock_t lock; 151395844d20SMarek Olšák s64 last_update_us; 151495844d20SMarek Olšák s64 accum_us; /* accumulated microseconds */ 151500f06b24SJohn Brooks s64 accum_us_vis; /* for visible VRAM */ 151695844d20SMarek Olšák u32 log2_max_MBps; 151795844d20SMarek Olšák } mm_stats; 151895844d20SMarek Olšák 151997b2e202SAlex Deucher /* display */ 15209accf2fdSEmily Deng bool enable_virtual_display; 152197b2e202SAlex Deucher struct amdgpu_mode_info mode_info; 15224562236bSHarry Wentland /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */ 152397b2e202SAlex Deucher struct work_struct hotplug_work; 152497b2e202SAlex Deucher struct amdgpu_irq_src crtc_irq; 152597b2e202SAlex Deucher struct amdgpu_irq_src pageflip_irq; 152697b2e202SAlex Deucher struct amdgpu_irq_src hpd_irq; 152797b2e202SAlex Deucher 152897b2e202SAlex Deucher /* rings */ 152976bf0db5SChristian König u64 fence_context; 153097b2e202SAlex Deucher unsigned num_rings; 153197b2e202SAlex Deucher struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; 153297b2e202SAlex Deucher bool ib_pool_ready; 153397b2e202SAlex Deucher struct amdgpu_sa_manager ring_tmp_bo; 153497b2e202SAlex Deucher 153597b2e202SAlex Deucher /* interrupts */ 153697b2e202SAlex Deucher struct amdgpu_irq irq; 153797b2e202SAlex Deucher 15381f7371b2SAlex Deucher /* powerplay */ 15391f7371b2SAlex Deucher struct amd_powerplay powerplay; 1540f3898ea1SEric Huang bool pp_force_state_enabled; 15411f7371b2SAlex Deucher 154297b2e202SAlex Deucher /* dpm */ 154397b2e202SAlex Deucher struct amdgpu_pm pm; 154497b2e202SAlex Deucher u32 cg_flags; 154597b2e202SAlex Deucher u32 pg_flags; 154697b2e202SAlex Deucher 154797b2e202SAlex Deucher /* amdgpu smumgr */ 154897b2e202SAlex Deucher struct amdgpu_smumgr smu; 154997b2e202SAlex Deucher 155097b2e202SAlex Deucher /* gfx */ 155197b2e202SAlex Deucher struct amdgpu_gfx gfx; 155297b2e202SAlex Deucher 155397b2e202SAlex Deucher /* sdma */ 1554c113ea1cSAlex Deucher struct amdgpu_sdma sdma; 155597b2e202SAlex Deucher 155697b2e202SAlex Deucher /* uvd */ 155797b2e202SAlex Deucher struct amdgpu_uvd uvd; 155897b2e202SAlex Deucher 155997b2e202SAlex Deucher /* vce */ 156097b2e202SAlex Deucher struct amdgpu_vce vce; 156195d0906fSLeo Liu 156295d0906fSLeo Liu /* vcn */ 156395d0906fSLeo Liu struct amdgpu_vcn vcn; 156497b2e202SAlex Deucher 156597b2e202SAlex Deucher /* firmwares */ 156697b2e202SAlex Deucher struct amdgpu_firmware firmware; 156797b2e202SAlex Deucher 15680e5ca0d1SHuang Rui /* PSP */ 15690e5ca0d1SHuang Rui struct psp_context psp; 15700e5ca0d1SHuang Rui 157197b2e202SAlex Deucher /* GDS */ 157297b2e202SAlex Deucher struct amdgpu_gds gds; 157397b2e202SAlex Deucher 15744562236bSHarry Wentland /* display related functionality */ 15754562236bSHarry Wentland struct amdgpu_display_manager dm; 15764562236bSHarry Wentland 1577a1255107SAlex Deucher struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM]; 157897b2e202SAlex Deucher int num_ip_blocks; 157997b2e202SAlex Deucher struct mutex mn_lock; 158097b2e202SAlex Deucher DECLARE_HASHTABLE(mn_hash, 7); 158197b2e202SAlex Deucher 158297b2e202SAlex Deucher /* tracking pinned memory */ 158397b2e202SAlex Deucher u64 vram_pin_size; 1584e131b914SChunming Zhou u64 invisible_pin_size; 158597b2e202SAlex Deucher u64 gart_pin_size; 1586130e0371SOded Gabbay 1587130e0371SOded Gabbay /* amdkfd interface */ 1588130e0371SOded Gabbay struct kfd_dev *kfd; 158923ca0e4eSChunming Zhou 15904522824cSShaoyun Liu /* soc15 register offset based on ip, instance and segment */ 15914522824cSShaoyun Liu uint32_t *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE]; 15924522824cSShaoyun Liu 1593946a4d5bSShaoyun Liu const struct amdgpu_nbio_funcs *nbio_funcs; 1594946a4d5bSShaoyun Liu 15952dc80b00SShirish S /* delayed work_func for deferring clockgating during resume */ 15962dc80b00SShirish S struct delayed_work late_init_work; 15972dc80b00SShirish S 15985a5099cbSXiangliang Yu struct amdgpu_virt virt; 1599a05502e5SHorace Chen /* firmware VRAM reservation */ 1600a05502e5SHorace Chen struct amdgpu_fw_vram_usage fw_vram_usage; 16010c4e7fa5SChunming Zhou 16020c4e7fa5SChunming Zhou /* link all shadow bo */ 16030c4e7fa5SChunming Zhou struct list_head shadow_list; 16040c4e7fa5SChunming Zhou struct mutex shadow_list_lock; 1605795f2813SAndres Rodriguez /* keep an lru list of rings by HW IP */ 1606795f2813SAndres Rodriguez struct list_head ring_lru_list; 1607795f2813SAndres Rodriguez spinlock_t ring_lru_list_lock; 16085c1354bdSChunming Zhou 1609c836fec5SJim Qu /* record hw reset is performed */ 1610c836fec5SJim Qu bool has_hw_reset; 16110c49e0b8SChunming Zhou u8 reset_magic[AMDGPU_RESET_MAGIC_NUM]; 1612c836fec5SJim Qu 161347ed4e1cSKen Wang /* record last mm index being written through WREG32*/ 161447ed4e1cSKen Wang unsigned long last_mm_index; 161513a752e3SMonk Liu bool in_gpu_reset; 161613a752e3SMonk Liu struct mutex lock_reset; 161797b2e202SAlex Deucher }; 161897b2e202SAlex Deucher 1619a7d64de6SChristian König static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev) 1620a7d64de6SChristian König { 1621a7d64de6SChristian König return container_of(bdev, struct amdgpu_device, mman.bdev); 1622a7d64de6SChristian König } 1623a7d64de6SChristian König 162497b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev, 162597b2e202SAlex Deucher struct drm_device *ddev, 162697b2e202SAlex Deucher struct pci_dev *pdev, 162797b2e202SAlex Deucher uint32_t flags); 162897b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev); 162997b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); 163097b2e202SAlex Deucher 163197b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, 163215d72fd7SMonk Liu uint32_t acc_flags); 163397b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, 163415d72fd7SMonk Liu uint32_t acc_flags); 1635421a2a30SMonk Liu void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value); 1636421a2a30SMonk Liu uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset); 1637421a2a30SMonk Liu 163897b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg); 163997b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v); 164097b2e202SAlex Deucher 164197b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index); 164297b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v); 1643832be404SKen Wang u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index); 1644832be404SKen Wang void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v); 164597b2e202SAlex Deucher 16464562236bSHarry Wentland bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type); 16474562236bSHarry Wentland bool amdgpu_device_has_dc_support(struct amdgpu_device *adev); 16484562236bSHarry Wentland 16499475a943SShaoyun Liu int emu_soc_asic_init(struct amdgpu_device *adev); 16509475a943SShaoyun Liu 165197b2e202SAlex Deucher /* 165297b2e202SAlex Deucher * Registers read & write functions. 165397b2e202SAlex Deucher */ 165415d72fd7SMonk Liu 165515d72fd7SMonk Liu #define AMDGPU_REGS_IDX (1<<0) 165615d72fd7SMonk Liu #define AMDGPU_REGS_NO_KIQ (1<<1) 165715d72fd7SMonk Liu 165815d72fd7SMonk Liu #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ) 165915d72fd7SMonk Liu #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ) 166015d72fd7SMonk Liu 1661421a2a30SMonk Liu #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg)) 1662421a2a30SMonk Liu #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v)) 1663421a2a30SMonk Liu 166415d72fd7SMonk Liu #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0) 166515d72fd7SMonk Liu #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX) 166615d72fd7SMonk Liu #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0)) 166715d72fd7SMonk Liu #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0) 166815d72fd7SMonk Liu #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX) 166997b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 167097b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 167197b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg)) 167297b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v)) 167336b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg)) 167436b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v)) 167597b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg)) 167697b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v)) 167797b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg)) 167897b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v)) 167997b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg)) 168097b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v)) 1681ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg)) 1682ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v)) 168316abb5d2SEvan Quan #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg)) 168416abb5d2SEvan Quan #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v)) 168597b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg)) 168697b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v)) 168797b2e202SAlex Deucher #define WREG32_P(reg, val, mask) \ 168897b2e202SAlex Deucher do { \ 168997b2e202SAlex Deucher uint32_t tmp_ = RREG32(reg); \ 169097b2e202SAlex Deucher tmp_ &= (mask); \ 169197b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 169297b2e202SAlex Deucher WREG32(reg, tmp_); \ 169397b2e202SAlex Deucher } while (0) 169497b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and) 169597b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or)) 169697b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask) \ 169797b2e202SAlex Deucher do { \ 169897b2e202SAlex Deucher uint32_t tmp_ = RREG32_PLL(reg); \ 169997b2e202SAlex Deucher tmp_ &= (mask); \ 170097b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 170197b2e202SAlex Deucher WREG32_PLL(reg, tmp_); \ 170297b2e202SAlex Deucher } while (0) 170397b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false)) 170497b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg)) 170597b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v)) 170697b2e202SAlex Deucher 170797b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index)) 170897b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v)) 1709832be404SKen Wang #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index)) 1710832be404SKen Wang #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v)) 171197b2e202SAlex Deucher 171297b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT 171397b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK 171497b2e202SAlex Deucher 171597b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val) \ 171697b2e202SAlex Deucher (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \ 171797b2e202SAlex Deucher (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) 171897b2e202SAlex Deucher 171997b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field) \ 172097b2e202SAlex Deucher (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field)) 172197b2e202SAlex Deucher 172261cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val) \ 172361cb8cefSTom St Denis WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 172461cb8cefSTom St Denis 1725ccaf3574STom St Denis #define WREG32_FIELD_OFFSET(reg, offset, field, val) \ 1726ccaf3574STom St Denis WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 1727ccaf3574STom St Denis 172897b2e202SAlex Deucher /* 172997b2e202SAlex Deucher * BIOS helpers. 173097b2e202SAlex Deucher */ 173197b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i]) 173297b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8)) 173397b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16)) 173497b2e202SAlex Deucher 1735c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance * 1736c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring) 17374b2f7e2cSJammy Zhou { 17384b2f7e2cSJammy Zhou struct amdgpu_device *adev = ring->adev; 17394b2f7e2cSJammy Zhou int i; 17404b2f7e2cSJammy Zhou 1741c113ea1cSAlex Deucher for (i = 0; i < adev->sdma.num_instances; i++) 1742c113ea1cSAlex Deucher if (&adev->sdma.instance[i].ring == ring) 17434b2f7e2cSJammy Zhou break; 17444b2f7e2cSJammy Zhou 17454b2f7e2cSJammy Zhou if (i < AMDGPU_MAX_SDMA_INSTANCES) 1746c113ea1cSAlex Deucher return &adev->sdma.instance[i]; 17474b2f7e2cSJammy Zhou else 17484b2f7e2cSJammy Zhou return NULL; 17494b2f7e2cSJammy Zhou } 17504b2f7e2cSJammy Zhou 175197b2e202SAlex Deucher /* 175297b2e202SAlex Deucher * ASICs macro. 175397b2e202SAlex Deucher */ 175497b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state)) 175597b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev)) 175697b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev)) 175797b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d)) 175897b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec)) 1759841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev)) 1760841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l)) 1761841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev)) 176297b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev)) 17637946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l)) 176497b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v))) 1765bbf282d8SAlex Deucher #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev)) 176669882565SChristian König #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r)) 176769882565SChristian König #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r)) 1768132f34e4SChristian König #define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid)) 1769c633c00bSChristian König #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr)) 1770c633c00bSChristian König #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid)) 1771132f34e4SChristian König #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags)) 1772132f34e4SChristian König #define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) (adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags)) 1773132f34e4SChristian König #define amdgpu_gmc_get_pte_flags(adev, flags) (adev)->gmc.gmc_funcs->get_vm_pte_flags((adev),(flags)) 177497b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count))) 1775de9ea7bdSChristian König #define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr))) 177697b2e202SAlex Deucher #define amdgpu_vm_set_pte_pde(adev, ib, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->set_pte_pde((ib), (pe), (addr), (count), (incr), (flags))) 177797b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib))) 177897b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r)) 1779bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t)) 178097b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r)) 178197b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r)) 178297b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r)) 1783c4f46f22SChristian König #define amdgpu_ring_emit_ib(r, ib, vmid, c) (r)->funcs->emit_ib((r), (ib), (vmid), (c)) 1784b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r)) 1785c633c00bSChristian König #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr)) 1786890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags)) 178797b2e202SAlex Deucher #define amdgpu_ring_emit_gds_switch(r, v, db, ds, wb, ws, ab, as) (r)->funcs->emit_gds_switch((r), (v), (db), (ds), (wb), (ws), (ab), (as)) 1788d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r)) 1789c2167a65SMonk Liu #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r)) 1790753ad49cSMonk Liu #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d)) 1791b6091c12SXiangliang Yu #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d)) 1792b6091c12SXiangliang Yu #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v)) 1793c1e877daSChristian König #define amdgpu_ring_emit_reg_wait(r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m)) 17943b4d68e9SMonk Liu #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b)) 17959e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib))) 179603ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r)) 179703ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o)) 179897b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev)) 179900ecd8a2SFelix Kuehling #define amdgpu_ih_prescreen_iv(adev) (adev)->irq.ih_funcs->prescreen_iv((adev)) 180097b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv)) 180197b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev)) 180297b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc)) 180397b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l)) 180497b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e)) 180597b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h)) 180697b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h)) 180797b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev)) 180897b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev)) 1809cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async)) 181097b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos)) 181197b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c)) 181297b2e202SAlex Deucher #define amdgpu_display_add_connector(adev, ci, sd, ct, ib, coi, h, r) (adev)->mode_info.funcs->add_connector((adev), (ci), (sd), (ct), (ib), (coi), (h), (r)) 1813c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b)) 18146e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) 1815b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev)) 18169559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance)) 181797b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a)) 18180e5ca0d1SHuang Rui #define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i)) 181997b2e202SAlex Deucher 182097b2e202SAlex Deucher /* Common functions */ 18215f152b5eSAlex Deucher int amdgpu_device_gpu_recover(struct amdgpu_device *adev, 18225f152b5eSAlex Deucher struct amdgpu_job* job, bool force); 18238111c387SAlex Deucher void amdgpu_device_pci_config_reset(struct amdgpu_device *adev); 182439c640c0SAlex Deucher bool amdgpu_device_need_post(struct amdgpu_device *adev); 1825166140fbSSamuel Li void amdgpu_display_update_priority(struct amdgpu_device *adev); 1826d5fc5e82SChunming Zhou 182700f06b24SJohn Brooks void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes, 182800f06b24SJohn Brooks u64 num_vis_bytes); 1829765e7fbfSChristian König void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain); 183097b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo); 18312543e28aSAlex Deucher void amdgpu_device_vram_location(struct amdgpu_device *adev, 1832770d13b1SChristian König struct amdgpu_gmc *mc, u64 base); 18332543e28aSAlex Deucher void amdgpu_device_gart_location(struct amdgpu_device *adev, 1834770d13b1SChristian König struct amdgpu_gmc *mc); 1835d6895ad3SChristian König int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev); 18369c3f2b54SAlex Deucher void amdgpu_device_program_register_sequence(struct amdgpu_device *adev, 183797b2e202SAlex Deucher const u32 *registers, 183897b2e202SAlex Deucher const u32 array_size); 183997b2e202SAlex Deucher 184097b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev); 184197b2e202SAlex Deucher /* atpx handler */ 184297b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO) 184397b2e202SAlex Deucher void amdgpu_register_atpx_handler(void); 184497b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void); 1845a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void); 18462f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void); 1847efc83cf4SAlex Deucher bool amdgpu_atpx_dgpu_req_power_for_displays(void); 1848714f88e0SAlex Xie bool amdgpu_has_atpx(void); 184997b2e202SAlex Deucher #else 185097b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {} 185197b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {} 1852a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; } 18532f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; } 1854efc83cf4SAlex Deucher static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; } 1855714f88e0SAlex Xie static inline bool amdgpu_has_atpx(void) { return false; } 185697b2e202SAlex Deucher #endif 185797b2e202SAlex Deucher 185897b2e202SAlex Deucher /* 185997b2e202SAlex Deucher * KMS 186097b2e202SAlex Deucher */ 186197b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[]; 1862f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl; 186397b2e202SAlex Deucher 186497b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags); 186511b3c20bSGabriel Krisman Bertazi void amdgpu_driver_unload_kms(struct drm_device *dev); 186697b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev); 186797b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv); 186897b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev, 186997b2e202SAlex Deucher struct drm_file *file_priv); 1870cdd61df6SAlex Deucher int amdgpu_device_ip_suspend(struct amdgpu_device *adev); 1871810ddc3aSAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon); 1872810ddc3aSAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon); 187388e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe); 187488e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe); 187588e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe); 187697b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd, 187797b2e202SAlex Deucher unsigned long arg); 187897b2e202SAlex Deucher 187997b2e202SAlex Deucher /* 188097b2e202SAlex Deucher * functions used by amdgpu_encoder.c 188197b2e202SAlex Deucher */ 188297b2e202SAlex Deucher struct amdgpu_afmt_acr { 188397b2e202SAlex Deucher u32 clock; 188497b2e202SAlex Deucher 188597b2e202SAlex Deucher int n_32khz; 188697b2e202SAlex Deucher int cts_32khz; 188797b2e202SAlex Deucher 188897b2e202SAlex Deucher int n_44_1khz; 188997b2e202SAlex Deucher int cts_44_1khz; 189097b2e202SAlex Deucher 189197b2e202SAlex Deucher int n_48khz; 189297b2e202SAlex Deucher int cts_48khz; 189397b2e202SAlex Deucher 189497b2e202SAlex Deucher }; 189597b2e202SAlex Deucher 189697b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock); 189797b2e202SAlex Deucher 189897b2e202SAlex Deucher /* amdgpu_acpi.c */ 189997b2e202SAlex Deucher #if defined(CONFIG_ACPI) 190097b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev); 190197b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev); 190297b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev); 190397b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev, 190497b2e202SAlex Deucher u8 perf_req, bool advertise); 190597b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev); 190697b2e202SAlex Deucher #else 190797b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; } 190897b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { } 190997b2e202SAlex Deucher #endif 191097b2e202SAlex Deucher 19119cca0b8eSChristian König int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser, 19129cca0b8eSChristian König uint64_t addr, struct amdgpu_bo **bo, 19139cca0b8eSChristian König struct amdgpu_bo_va_mapping **mapping); 191497b2e202SAlex Deucher 19154562236bSHarry Wentland #if defined(CONFIG_DRM_AMD_DC) 19164562236bSHarry Wentland int amdgpu_dm_display_resume(struct amdgpu_device *adev ); 19174562236bSHarry Wentland #else 19184562236bSHarry Wentland static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; } 19194562236bSHarry Wentland #endif 19204562236bSHarry Wentland 192197b2e202SAlex Deucher #include "amdgpu_object.h" 192297b2e202SAlex Deucher #endif 1923