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 318290268fSChristian König #include "amdgpu_ctx.h" 328290268fSChristian König 3397b2e202SAlex Deucher #include <linux/atomic.h> 3497b2e202SAlex Deucher #include <linux/wait.h> 3597b2e202SAlex Deucher #include <linux/list.h> 3697b2e202SAlex Deucher #include <linux/kref.h> 37a9f87f64SChristian König #include <linux/rbtree.h> 3897b2e202SAlex Deucher #include <linux/hashtable.h> 39f54d1867SChris Wilson #include <linux/dma-fence.h> 4097b2e202SAlex Deucher 41248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_api.h> 42248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_bo_driver.h> 43248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_placement.h> 44248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_module.h> 45248a1d6fSMasahiro Yamada #include <drm/ttm/ttm_execbuf_util.h> 4697b2e202SAlex Deucher 477e5a547fSChunming Zhou #include <drm/amdgpu_drm.h> 48f867723bSSam Ravnborg #include <drm/drm_gem.h> 49f867723bSSam Ravnborg #include <drm/drm_ioctl.h> 501b1f42d8SLucas Stach #include <drm/gpu_scheduler.h> 5197b2e202SAlex Deucher 5278c16834SAndres Rodriguez #include <kgd_kfd_interface.h> 53c79563a3SRex Zhu #include "dm_pp_interface.h" 54c79563a3SRex Zhu #include "kgd_pp_interface.h" 5578c16834SAndres Rodriguez 565fc3aeebSyanyang1 #include "amd_shared.h" 5797b2e202SAlex Deucher #include "amdgpu_mode.h" 5897b2e202SAlex Deucher #include "amdgpu_ih.h" 5997b2e202SAlex Deucher #include "amdgpu_irq.h" 6097b2e202SAlex Deucher #include "amdgpu_ucode.h" 61c632d799SFlora Cui #include "amdgpu_ttm.h" 620e5ca0d1SHuang Rui #include "amdgpu_psp.h" 6397b2e202SAlex Deucher #include "amdgpu_gds.h" 6456113504SChristian König #include "amdgpu_sync.h" 6578023016SChristian König #include "amdgpu_ring.h" 66073440d2SChristian König #include "amdgpu_vm.h" 67cf097881SAlex Deucher #include "amdgpu_dpm.h" 68a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h" 694df654d2SLeo Liu #include "amdgpu_uvd.h" 705e568178SLeo Liu #include "amdgpu_vce.h" 7195aa13f6SLeo Liu #include "amdgpu_vcn.h" 7288a1c40aSLeo Liu #include "amdgpu_jpeg.h" 739a189996SChristian König #include "amdgpu_mn.h" 74770d13b1SChristian König #include "amdgpu_gmc.h" 75448fe192SHuang Rui #include "amdgpu_gfx.h" 76bb7743bcSHuang Rui #include "amdgpu_sdma.h" 77bebc0762SHawking Zhang #include "amdgpu_nbio.h" 784562236bSHarry Wentland #include "amdgpu_dm.h" 79ceeb50edSMonk Liu #include "amdgpu_virt.h" 807946340fSRex Zhu #include "amdgpu_csa.h" 813490bdb5SChristian König #include "amdgpu_gart.h" 8275758255SAlex Deucher #include "amdgpu_debugfs.h" 83050d9d43SChristian König #include "amdgpu_job.h" 844a8c21a1SChristian König #include "amdgpu_bo_list.h" 852cddc50eSHuang Rui #include "amdgpu_gem.h" 86cde577bdSOak Zeng #include "amdgpu_doorbell.h" 87611736d8SFelix Kuehling #include "amdgpu_amdkfd.h" 88137d63abSHuang Rui #include "amdgpu_smu.h" 89f39f5bb1SXiaojie Yuan #include "amdgpu_discovery.h" 90a538bbe7SJack Xiao #include "amdgpu_mes.h" 919e585a52SHawking Zhang #include "amdgpu_umc.h" 923d093da0STao Zhou #include "amdgpu_mmhub.h" 93bdf84a80SJoseph Greathouse #include "amdgpu_df.h" 94c79563a3SRex Zhu 9562d73fbcSEvan Quan #define MAX_GPU_INSTANCE 16 9662d73fbcSEvan Quan 9762d73fbcSEvan Quan struct amdgpu_gpu_instance 9862d73fbcSEvan Quan { 9962d73fbcSEvan Quan struct amdgpu_device *adev; 10062d73fbcSEvan Quan int mgpu_fan_enabled; 10162d73fbcSEvan Quan }; 10262d73fbcSEvan Quan 10362d73fbcSEvan Quan struct amdgpu_mgpu_info 10462d73fbcSEvan Quan { 10562d73fbcSEvan Quan struct amdgpu_gpu_instance gpu_ins[MAX_GPU_INSTANCE]; 10662d73fbcSEvan Quan struct mutex mutex; 10762d73fbcSEvan Quan uint32_t num_gpu; 10862d73fbcSEvan Quan uint32_t num_dgpu; 10962d73fbcSEvan Quan uint32_t num_apu; 11062d73fbcSEvan Quan }; 11162d73fbcSEvan Quan 112f440ff44SWambui Karuga #define AMDGPU_MAX_TIMEOUT_PARAM_LENGTH 256 11371f98027SAlex Deucher 11497b2e202SAlex Deucher /* 11597b2e202SAlex Deucher * Modules parameters. 11697b2e202SAlex Deucher */ 11797b2e202SAlex Deucher extern int amdgpu_modeset; 11897b2e202SAlex Deucher extern int amdgpu_vram_limit; 119218b5dcdSJohn Brooks extern int amdgpu_vis_vram_limit; 12083e74db6SAlex Deucher extern int amdgpu_gart_size; 12136d38372SChristian König extern int amdgpu_gtt_size; 12295844d20SMarek Olšák extern int amdgpu_moverate; 12397b2e202SAlex Deucher extern int amdgpu_benchmarking; 12497b2e202SAlex Deucher extern int amdgpu_testing; 12597b2e202SAlex Deucher extern int amdgpu_audio; 12697b2e202SAlex Deucher extern int amdgpu_disp_priority; 12797b2e202SAlex Deucher extern int amdgpu_hw_i2c; 12897b2e202SAlex Deucher extern int amdgpu_pcie_gen2; 12997b2e202SAlex Deucher extern int amdgpu_msi; 130f440ff44SWambui Karuga extern char amdgpu_lockup_timeout[AMDGPU_MAX_TIMEOUT_PARAM_LENGTH]; 13197b2e202SAlex Deucher extern int amdgpu_dpm; 132e635ee07SHuang Rui extern int amdgpu_fw_load_type; 13397b2e202SAlex Deucher extern int amdgpu_aspm; 13497b2e202SAlex Deucher extern int amdgpu_runtime_pm; 1350b693f0bSRex Zhu extern uint amdgpu_ip_block_mask; 13697b2e202SAlex Deucher extern int amdgpu_bapm; 13797b2e202SAlex Deucher extern int amdgpu_deep_color; 13897b2e202SAlex Deucher extern int amdgpu_vm_size; 13997b2e202SAlex Deucher extern int amdgpu_vm_block_size; 140d07f14beSRoger He extern int amdgpu_vm_fragment_size; 141d9c13156SChristian König extern int amdgpu_vm_fault_stop; 142b495bd3aSChristian König extern int amdgpu_vm_debug; 1439a4b7d4cSHarish Kasiviswanathan extern int amdgpu_vm_update_mode; 1447e0ff20cSWambui Karuga extern int amdgpu_exp_hw_support; 1454562236bSHarry Wentland extern int amdgpu_dc; 1461333f723SJammy Zhou extern int amdgpu_sched_jobs; 1474afcb303SJammy Zhou extern int amdgpu_sched_hw_submission; 1480b693f0bSRex Zhu extern uint amdgpu_pcie_gen_cap; 1490b693f0bSRex Zhu extern uint amdgpu_pcie_lane_cap; 1500b693f0bSRex Zhu extern uint amdgpu_cg_mask; 1510b693f0bSRex Zhu extern uint amdgpu_pg_mask; 1520b693f0bSRex Zhu extern uint amdgpu_sdma_phase_quantum; 1536f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu; 1549accf2fdSEmily Deng extern char *amdgpu_virtual_display; 1550b693f0bSRex Zhu extern uint amdgpu_pp_feature_mask; 156367039bfSTianci.Yin extern uint amdgpu_force_long_training; 15765781c78SMonk Liu extern int amdgpu_job_hang_limit; 158e8835e0eSHawking Zhang extern int amdgpu_lbpw; 1594a75aefeSAndres Rodriguez extern int amdgpu_compute_multipipe; 160dcebf026SAndrey Grodzovsky extern int amdgpu_gpu_recovery; 161bfca0289SShaoyun Liu extern int amdgpu_emu_mode; 1627951e376SRex Zhu extern uint amdgpu_smu_memory_pool_size; 1637875a226SAlex Deucher extern uint amdgpu_dc_feature_mask; 164ad4de27fSNicholas Kazlauskas extern uint amdgpu_dm_abm_level; 16562d73fbcSEvan Quan extern struct amdgpu_mgpu_info mgpu_info; 1661218252fSxinhui pan extern int amdgpu_ras_enable; 1671218252fSxinhui pan extern uint amdgpu_ras_mask; 16851bcce46SHawking Zhang extern int amdgpu_async_gfx_ring; 169b239c017SJack Xiao extern int amdgpu_mcbp; 170a190d1c7SXiaojie Yuan extern int amdgpu_discovery; 17138487284SJack Xiao extern int amdgpu_mes; 17275ee6487SFelix Kuehling extern int amdgpu_noretry; 1734e66d7d2SYong Zhao extern int amdgpu_force_asic_type; 1748c9f69bcSShirish S #ifdef CONFIG_HSA_AMD 175aa978594SHuang Rui extern int sched_policy; 176a35ad98bSShirish S #else 177a35ad98bSShirish S static const int sched_policy = KFD_SCHED_POLICY_HWS; 1788c9f69bcSShirish S #endif 17997b2e202SAlex Deucher 1806dd13096SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_SI 1816dd13096SFelix Kuehling extern int amdgpu_si_support; 1826dd13096SFelix Kuehling #endif 1837df28986SFelix Kuehling #ifdef CONFIG_DRM_AMDGPU_CIK 1847df28986SFelix Kuehling extern int amdgpu_cik_support; 1857df28986SFelix Kuehling #endif 18697b2e202SAlex Deucher 18708d1bdd4SRex Zhu #define AMDGPU_VM_MAX_NUM_CTX 4096 1886c8d74caSSamuel Li #define AMDGPU_SG_THRESHOLD (256*1024*1024) 18955ed8cafSChunming Zhou #define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */ 1904b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000 19197b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 1928c5e13ecSAndrey Grodzovsky #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) 19397b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */ 19497b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE 16 19597b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32 19697b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT 4 197a5bde2f9SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH 16 19897b2e202SAlex Deucher 19997b2e202SAlex Deucher /* hard reset data */ 20097b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b 20197b2e202SAlex Deucher 20297b2e202SAlex Deucher /* reset flags */ 20397b2e202SAlex Deucher #define AMDGPU_RESET_GFX (1 << 0) 20497b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE (1 << 1) 20597b2e202SAlex Deucher #define AMDGPU_RESET_DMA (1 << 2) 20697b2e202SAlex Deucher #define AMDGPU_RESET_CP (1 << 3) 20797b2e202SAlex Deucher #define AMDGPU_RESET_GRBM (1 << 4) 20897b2e202SAlex Deucher #define AMDGPU_RESET_DMA1 (1 << 5) 20997b2e202SAlex Deucher #define AMDGPU_RESET_RLC (1 << 6) 21097b2e202SAlex Deucher #define AMDGPU_RESET_SEM (1 << 7) 21197b2e202SAlex Deucher #define AMDGPU_RESET_IH (1 << 8) 21297b2e202SAlex Deucher #define AMDGPU_RESET_VMC (1 << 9) 21397b2e202SAlex Deucher #define AMDGPU_RESET_MC (1 << 10) 21497b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY (1 << 11) 21597b2e202SAlex Deucher #define AMDGPU_RESET_UVD (1 << 12) 21697b2e202SAlex Deucher #define AMDGPU_RESET_VCE (1 << 13) 21797b2e202SAlex Deucher #define AMDGPU_RESET_VCE1 (1 << 14) 21897b2e202SAlex Deucher 21997b2e202SAlex Deucher /* max cursor sizes (in pixels) */ 22097b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128 22197b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128 22297b2e202SAlex Deucher 22397b2e202SAlex Deucher struct amdgpu_device; 22497b2e202SAlex Deucher struct amdgpu_ib; 22597b2e202SAlex Deucher struct amdgpu_cs_parser; 226bb977d37SChunming Zhou struct amdgpu_job; 22797b2e202SAlex Deucher struct amdgpu_irq_src; 2280b492a4cSAlex Deucher struct amdgpu_fpriv; 2299cca0b8eSChristian König struct amdgpu_bo_va_mapping; 230102c16a0SLyude Paul struct amdgpu_atif; 231992af942SJonathan Kim struct kfd_vm_fault_info; 23297b2e202SAlex Deucher 23397b2e202SAlex Deucher enum amdgpu_cp_irq { 23453b2fe41SHawking Zhang AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP = 0, 23553b2fe41SHawking Zhang AMDGPU_CP_IRQ_GFX_ME0_PIPE1_EOP, 23697b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP, 23797b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP, 23897b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP, 23997b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP, 24097b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP, 24197b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP, 24297b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP, 24397b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP, 24497b2e202SAlex Deucher 24597b2e202SAlex Deucher AMDGPU_CP_IRQ_LAST 24697b2e202SAlex Deucher }; 24797b2e202SAlex Deucher 24897b2e202SAlex Deucher enum amdgpu_thermal_irq { 24997b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0, 25097b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_HIGH_TO_LOW, 25197b2e202SAlex Deucher 25297b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LAST 25397b2e202SAlex Deucher }; 25497b2e202SAlex Deucher 2554e638ae9SXiangliang Yu enum amdgpu_kiq_irq { 2564e638ae9SXiangliang Yu AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0, 2574e638ae9SXiangliang Yu AMDGPU_CP_KIQ_IRQ_LAST 2584e638ae9SXiangliang Yu }; 2594e638ae9SXiangliang Yu 2603890d111SEmily Deng #define MAX_KIQ_REG_WAIT 5000 /* in usecs, 5ms */ 2613890d111SEmily Deng #define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */ 2624944af67Swentalou #define MAX_KIQ_REG_TRY 80 /* 20 -> 80 */ 2633890d111SEmily Deng 26443fa561fSRex Zhu int amdgpu_device_ip_set_clockgating_state(void *dev, 2655fc3aeebSyanyang1 enum amd_ip_block_type block_type, 2665fc3aeebSyanyang1 enum amd_clockgating_state state); 26743fa561fSRex Zhu int amdgpu_device_ip_set_powergating_state(void *dev, 2685fc3aeebSyanyang1 enum amd_ip_block_type block_type, 2695fc3aeebSyanyang1 enum amd_powergating_state state); 2702990a1fcSAlex Deucher void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev, 2712990a1fcSAlex Deucher u32 *flags); 2722990a1fcSAlex Deucher int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev, 2735dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 2742990a1fcSAlex Deucher bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev, 2755dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 27697b2e202SAlex Deucher 277a1255107SAlex Deucher #define AMDGPU_MAX_IP_NUM 16 278a1255107SAlex Deucher 279a1255107SAlex Deucher struct amdgpu_ip_block_status { 280a1255107SAlex Deucher bool valid; 281a1255107SAlex Deucher bool sw; 282a1255107SAlex Deucher bool hw; 283a1255107SAlex Deucher bool late_initialized; 284a1255107SAlex Deucher bool hang; 285a1255107SAlex Deucher }; 286a1255107SAlex Deucher 28797b2e202SAlex Deucher struct amdgpu_ip_block_version { 288a1255107SAlex Deucher const enum amd_ip_block_type type; 289a1255107SAlex Deucher const u32 major; 290a1255107SAlex Deucher const u32 minor; 291a1255107SAlex Deucher const u32 rev; 2925fc3aeebSyanyang1 const struct amd_ip_funcs *funcs; 29397b2e202SAlex Deucher }; 29497b2e202SAlex Deucher 295efe4f000STianci.Yin #define HW_REV(_Major, _Minor, _Rev) \ 296efe4f000STianci.Yin ((((uint32_t) (_Major)) << 16) | ((uint32_t) (_Minor) << 8) | ((uint32_t) (_Rev))) 297efe4f000STianci.Yin 298a1255107SAlex Deucher struct amdgpu_ip_block { 299a1255107SAlex Deucher struct amdgpu_ip_block_status status; 300a1255107SAlex Deucher const struct amdgpu_ip_block_version *version; 301a1255107SAlex Deucher }; 302a1255107SAlex Deucher 3032990a1fcSAlex Deucher int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev, 3045fc3aeebSyanyang1 enum amd_ip_block_type type, 30597b2e202SAlex Deucher u32 major, u32 minor); 30697b2e202SAlex Deucher 3072990a1fcSAlex Deucher struct amdgpu_ip_block * 3082990a1fcSAlex Deucher amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev, 3095fc3aeebSyanyang1 enum amd_ip_block_type type); 31097b2e202SAlex Deucher 3112990a1fcSAlex Deucher int amdgpu_device_ip_block_add(struct amdgpu_device *adev, 312a1255107SAlex Deucher const struct amdgpu_ip_block_version *ip_block_version); 313a1255107SAlex Deucher 31497b2e202SAlex Deucher /* 31597b2e202SAlex Deucher * BIOS. 31697b2e202SAlex Deucher */ 31797b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev); 31897b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev); 31997b2e202SAlex Deucher 32097b2e202SAlex Deucher /* 32197b2e202SAlex Deucher * Clocks 32297b2e202SAlex Deucher */ 32397b2e202SAlex Deucher 32497b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3 32597b2e202SAlex Deucher 32697b2e202SAlex Deucher struct amdgpu_clock { 32797b2e202SAlex Deucher struct amdgpu_pll ppll[AMDGPU_MAX_PPLL]; 32897b2e202SAlex Deucher struct amdgpu_pll spll; 32997b2e202SAlex Deucher struct amdgpu_pll mpll; 33097b2e202SAlex Deucher /* 10 Khz units */ 33197b2e202SAlex Deucher uint32_t default_mclk; 33297b2e202SAlex Deucher uint32_t default_sclk; 33397b2e202SAlex Deucher uint32_t default_dispclk; 33497b2e202SAlex Deucher uint32_t current_dispclk; 33597b2e202SAlex Deucher uint32_t dp_extclk; 33697b2e202SAlex Deucher uint32_t max_pixel_clock; 33797b2e202SAlex Deucher }; 33897b2e202SAlex Deucher 33997b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock. 34097b2e202SAlex Deucher * By conception this is an helper for other part of the driver 34197b2e202SAlex Deucher * like the indirect buffer or semaphore, which both have their 34297b2e202SAlex Deucher * locking. 34397b2e202SAlex Deucher * 34497b2e202SAlex Deucher * Principe is simple, we keep a list of sub allocation in offset 34597b2e202SAlex Deucher * order (first entry has offset == 0, last entry has the highest 34697b2e202SAlex Deucher * offset). 34797b2e202SAlex Deucher * 34897b2e202SAlex Deucher * When allocating new object we first check if there is room at 34997b2e202SAlex Deucher * the end total_size - (last_object_offset + last_object_size) >= 35097b2e202SAlex Deucher * alloc_size. If so we allocate new object there. 35197b2e202SAlex Deucher * 35297b2e202SAlex Deucher * When there is not enough room at the end, we start waiting for 35397b2e202SAlex Deucher * each sub object until we reach object_offset+object_size >= 35497b2e202SAlex Deucher * alloc_size, this object then become the sub object we return. 35597b2e202SAlex Deucher * 35697b2e202SAlex Deucher * Alignment can't be bigger than page size. 35797b2e202SAlex Deucher * 35897b2e202SAlex Deucher * Hole are not considered for allocation to keep things simple. 35997b2e202SAlex Deucher * Assumption is that there won't be hole (all object on same 36097b2e202SAlex Deucher * alignment). 36197b2e202SAlex Deucher */ 3626ba60b89SChristian König 3636ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS 32 3646ba60b89SChristian König 36597b2e202SAlex Deucher struct amdgpu_sa_manager { 36697b2e202SAlex Deucher wait_queue_head_t wq; 36797b2e202SAlex Deucher struct amdgpu_bo *bo; 36897b2e202SAlex Deucher struct list_head *hole; 3696ba60b89SChristian König struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS]; 37097b2e202SAlex Deucher struct list_head olist; 37197b2e202SAlex Deucher unsigned size; 37297b2e202SAlex Deucher uint64_t gpu_addr; 37397b2e202SAlex Deucher void *cpu_ptr; 37497b2e202SAlex Deucher uint32_t domain; 37597b2e202SAlex Deucher uint32_t align; 37697b2e202SAlex Deucher }; 37797b2e202SAlex Deucher 37897b2e202SAlex Deucher /* sub-allocation buffer */ 37997b2e202SAlex Deucher struct amdgpu_sa_bo { 38097b2e202SAlex Deucher struct list_head olist; 38197b2e202SAlex Deucher struct list_head flist; 38297b2e202SAlex Deucher struct amdgpu_sa_manager *manager; 38397b2e202SAlex Deucher unsigned soffset; 38497b2e202SAlex Deucher unsigned eoffset; 385f54d1867SChris Wilson struct dma_fence *fence; 38697b2e202SAlex Deucher }; 38797b2e202SAlex Deucher 388d573de2dSRex Zhu int amdgpu_fence_slab_init(void); 389d573de2dSRex Zhu void amdgpu_fence_slab_fini(void); 39097b2e202SAlex Deucher 39197b2e202SAlex Deucher /* 39297b2e202SAlex Deucher * IRQS. 39397b2e202SAlex Deucher */ 39497b2e202SAlex Deucher 39597b2e202SAlex Deucher struct amdgpu_flip_work { 396325cbba1SMichel Dänzer struct delayed_work flip_work; 39797b2e202SAlex Deucher struct work_struct unpin_work; 39897b2e202SAlex Deucher struct amdgpu_device *adev; 39997b2e202SAlex Deucher int crtc_id; 400325cbba1SMichel Dänzer u32 target_vblank; 40197b2e202SAlex Deucher uint64_t base; 40297b2e202SAlex Deucher struct drm_pending_vblank_event *event; 403765e7fbfSChristian König struct amdgpu_bo *old_abo; 404f54d1867SChris Wilson struct dma_fence *excl; 4051ffd2652SChristian König unsigned shared_count; 406f54d1867SChris Wilson struct dma_fence **shared; 407f54d1867SChris Wilson struct dma_fence_cb cb; 408cb9e59d7SAlex Deucher bool async; 40997b2e202SAlex Deucher }; 41097b2e202SAlex Deucher 41197b2e202SAlex Deucher 41297b2e202SAlex Deucher /* 41397b2e202SAlex Deucher * CP & rings. 41497b2e202SAlex Deucher */ 41597b2e202SAlex Deucher 41697b2e202SAlex Deucher struct amdgpu_ib { 41797b2e202SAlex Deucher struct amdgpu_sa_bo *sa_bo; 41897b2e202SAlex Deucher uint32_t length_dw; 41997b2e202SAlex Deucher uint64_t gpu_addr; 42097b2e202SAlex Deucher uint32_t *ptr; 421de807f81SJammy Zhou uint32_t flags; 42297b2e202SAlex Deucher }; 42397b2e202SAlex Deucher 4241b1f42d8SLucas Stach extern const struct drm_sched_backend_ops amdgpu_sched_ops; 425c1b69ed0SChunming Zhou 42697b2e202SAlex Deucher /* 42797b2e202SAlex Deucher * file private structure 42897b2e202SAlex Deucher */ 42997b2e202SAlex Deucher 43097b2e202SAlex Deucher struct amdgpu_fpriv { 43197b2e202SAlex Deucher struct amdgpu_vm vm; 432b85891bdSJunwei Zhang struct amdgpu_bo_va *prt_va; 4330f4b3c68SChristian König struct amdgpu_bo_va *csa_va; 43497b2e202SAlex Deucher struct mutex bo_list_lock; 43597b2e202SAlex Deucher struct idr bo_list_handles; 43697b2e202SAlex Deucher struct amdgpu_ctx_mgr ctx_mgr; 43797b2e202SAlex Deucher }; 43897b2e202SAlex Deucher 439021830d2SBas Nieuwenhuizen int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv); 440021830d2SBas Nieuwenhuizen 441b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, 44297b2e202SAlex Deucher unsigned size, struct amdgpu_ib *ib); 4434d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, 444f54d1867SChris Wilson struct dma_fence *f); 445b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, 44650ddc75eSJunwei Zhang struct amdgpu_ib *ibs, struct amdgpu_job *job, 44750ddc75eSJunwei Zhang struct dma_fence **f); 44897b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev); 44997b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev); 45097b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev); 45197b2e202SAlex Deucher 45297b2e202SAlex Deucher /* 45397b2e202SAlex Deucher * CS. 45497b2e202SAlex Deucher */ 45597b2e202SAlex Deucher struct amdgpu_cs_chunk { 45697b2e202SAlex Deucher uint32_t chunk_id; 45797b2e202SAlex Deucher uint32_t length_dw; 458758ac17fSChristian König void *kdata; 45997b2e202SAlex Deucher }; 46097b2e202SAlex Deucher 4612624dd15SChunming Zhou struct amdgpu_cs_post_dep { 4622624dd15SChunming Zhou struct drm_syncobj *syncobj; 4632624dd15SChunming Zhou struct dma_fence_chain *chain; 4642624dd15SChunming Zhou u64 point; 4652624dd15SChunming Zhou }; 4662624dd15SChunming Zhou 46797b2e202SAlex Deucher struct amdgpu_cs_parser { 46897b2e202SAlex Deucher struct amdgpu_device *adev; 46997b2e202SAlex Deucher struct drm_file *filp; 4703cb485f3SChristian König struct amdgpu_ctx *ctx; 471c3cca41eSChristian König 47297b2e202SAlex Deucher /* chunks */ 47397b2e202SAlex Deucher unsigned nchunks; 47497b2e202SAlex Deucher struct amdgpu_cs_chunk *chunks; 475c3cca41eSChristian König 47650838c8cSChristian König /* scheduler job object */ 47750838c8cSChristian König struct amdgpu_job *job; 4780d346a14SChristian König struct drm_sched_entity *entity; 479c3cca41eSChristian König 480c3cca41eSChristian König /* buffer objects */ 481c3cca41eSChristian König struct ww_acquire_ctx ticket; 482c3cca41eSChristian König struct amdgpu_bo_list *bo_list; 4833fe89771SChristian König struct amdgpu_mn *mn; 48456467ebfSChristian König struct amdgpu_bo_list_entry vm_pd; 48597b2e202SAlex Deucher struct list_head validated; 486f54d1867SChris Wilson struct dma_fence *fence; 487f69f90a1SChristian König uint64_t bytes_moved_threshold; 48800f06b24SJohn Brooks uint64_t bytes_moved_vis_threshold; 489f69f90a1SChristian König uint64_t bytes_moved; 49000f06b24SJohn Brooks uint64_t bytes_moved_vis; 49197b2e202SAlex Deucher 49297b2e202SAlex Deucher /* user fence */ 49391acbeb6SChristian König struct amdgpu_bo_list_entry uf_entry; 494660e8558SDave Airlie 4952624dd15SChunming Zhou unsigned num_post_deps; 4962624dd15SChunming Zhou struct amdgpu_cs_post_dep *post_deps; 49797b2e202SAlex Deucher }; 49897b2e202SAlex Deucher 4997270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, 5007270f839SChristian König uint32_t ib_idx, int idx) 50197b2e202SAlex Deucher { 50250838c8cSChristian König return p->job->ibs[ib_idx].ptr[idx]; 50397b2e202SAlex Deucher } 50497b2e202SAlex Deucher 5057270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p, 5067270f839SChristian König uint32_t ib_idx, int idx, 5077270f839SChristian König uint32_t value) 5087270f839SChristian König { 50950838c8cSChristian König p->job->ibs[ib_idx].ptr[idx] = value; 5107270f839SChristian König } 5117270f839SChristian König 51297b2e202SAlex Deucher /* 51397b2e202SAlex Deucher * Writeback 51497b2e202SAlex Deucher */ 51573469585SMonk Liu #define AMDGPU_MAX_WB 128 /* Reserve at most 128 WB slots for amdgpu-owned rings. */ 51697b2e202SAlex Deucher 51797b2e202SAlex Deucher struct amdgpu_wb { 51897b2e202SAlex Deucher struct amdgpu_bo *wb_obj; 51997b2e202SAlex Deucher volatile uint32_t *wb; 52097b2e202SAlex Deucher uint64_t gpu_addr; 52197b2e202SAlex Deucher u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */ 52297b2e202SAlex Deucher unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)]; 52397b2e202SAlex Deucher }; 52497b2e202SAlex Deucher 525131b4b36SAlex Deucher int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb); 526131b4b36SAlex Deucher void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb); 52797b2e202SAlex Deucher 52897b2e202SAlex Deucher /* 52997b2e202SAlex Deucher * Benchmarking 53097b2e202SAlex Deucher */ 53197b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number); 53297b2e202SAlex Deucher 53397b2e202SAlex Deucher 53497b2e202SAlex Deucher /* 53597b2e202SAlex Deucher * Testing 53697b2e202SAlex Deucher */ 53797b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev); 53897b2e202SAlex Deucher 53997b2e202SAlex Deucher /* 54097b2e202SAlex Deucher * ASIC specific register table accessible by UMD 54197b2e202SAlex Deucher */ 54297b2e202SAlex Deucher struct amdgpu_allowed_register_entry { 54397b2e202SAlex Deucher uint32_t reg_offset; 54497b2e202SAlex Deucher bool grbm_indexed; 54597b2e202SAlex Deucher }; 54697b2e202SAlex Deucher 5470cf3c64fSAlex Deucher enum amd_reset_method { 5480cf3c64fSAlex Deucher AMD_RESET_METHOD_LEGACY = 0, 5490cf3c64fSAlex Deucher AMD_RESET_METHOD_MODE0, 5500cf3c64fSAlex Deucher AMD_RESET_METHOD_MODE1, 5510cf3c64fSAlex Deucher AMD_RESET_METHOD_MODE2, 5520cf3c64fSAlex Deucher AMD_RESET_METHOD_BACO 5530cf3c64fSAlex Deucher }; 5540cf3c64fSAlex Deucher 55597b2e202SAlex Deucher /* 55697b2e202SAlex Deucher * ASIC specific functions. 55797b2e202SAlex Deucher */ 55897b2e202SAlex Deucher struct amdgpu_asic_funcs { 55997b2e202SAlex Deucher bool (*read_disabled_bios)(struct amdgpu_device *adev); 5607946b878SAlex Deucher bool (*read_bios_from_rom)(struct amdgpu_device *adev, 5617946b878SAlex Deucher u8 *bios, u32 length_bytes); 56297b2e202SAlex Deucher int (*read_register)(struct amdgpu_device *adev, u32 se_num, 56397b2e202SAlex Deucher u32 sh_num, u32 reg_offset, u32 *value); 56497b2e202SAlex Deucher void (*set_vga_state)(struct amdgpu_device *adev, bool state); 56597b2e202SAlex Deucher int (*reset)(struct amdgpu_device *adev); 5660cf3c64fSAlex Deucher enum amd_reset_method (*reset_method)(struct amdgpu_device *adev); 56797b2e202SAlex Deucher /* get the reference clock */ 56897b2e202SAlex Deucher u32 (*get_xclk)(struct amdgpu_device *adev); 56997b2e202SAlex Deucher /* MM block clocks */ 57097b2e202SAlex Deucher int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk); 57197b2e202SAlex Deucher int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk); 572841686dfSMaruthi Bayyavarapu /* static power management */ 573841686dfSMaruthi Bayyavarapu int (*get_pcie_lanes)(struct amdgpu_device *adev); 574841686dfSMaruthi Bayyavarapu void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes); 575bbf282d8SAlex Deucher /* get config memsize register */ 576bbf282d8SAlex Deucher u32 (*get_config_memsize)(struct amdgpu_device *adev); 5772df1b8b6SAlex Deucher /* flush hdp write queue */ 57869882565SChristian König void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring); 5792df1b8b6SAlex Deucher /* invalidate hdp read cache */ 58069882565SChristian König void (*invalidate_hdp)(struct amdgpu_device *adev, 58169882565SChristian König struct amdgpu_ring *ring); 5824a89ad9bSHawking Zhang void (*reset_hdp_ras_error_count)(struct amdgpu_device *adev); 58369070690SAlex Deucher /* check if the asic needs a full reset of if soft reset will work */ 58469070690SAlex Deucher bool (*need_full_reset)(struct amdgpu_device *adev); 5855253163aSOak Zeng /* initialize doorbell layout for specific asic*/ 5865253163aSOak Zeng void (*init_doorbell_index)(struct amdgpu_device *adev); 587b45e18acSKent Russell /* PCIe bandwidth usage */ 588b45e18acSKent Russell void (*get_pcie_usage)(struct amdgpu_device *adev, uint64_t *count0, 589b45e18acSKent Russell uint64_t *count1); 59044401889SAlex Deucher /* do we need to reset the asic at init time (e.g., kexec) */ 59144401889SAlex Deucher bool (*need_reset_on_init)(struct amdgpu_device *adev); 592dcea6e65SKent Russell /* PCIe replay counter */ 593dcea6e65SKent Russell uint64_t (*get_pcie_replay_count)(struct amdgpu_device *adev); 59469d5436dSAlex Deucher /* device supports BACO */ 59569d5436dSAlex Deucher bool (*supports_baco)(struct amdgpu_device *adev); 59697b2e202SAlex Deucher }; 59797b2e202SAlex Deucher 59897b2e202SAlex Deucher /* 59997b2e202SAlex Deucher * IOCTL. 60097b2e202SAlex Deucher */ 60197b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, 60297b2e202SAlex Deucher struct drm_file *filp); 60397b2e202SAlex Deucher 60497b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 6057ca24cf2SMarek Olšák int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data, 6067ca24cf2SMarek Olšák struct drm_file *filp); 60797b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 608eef18a82SJunwei Zhang int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, 609eef18a82SJunwei Zhang struct drm_file *filp); 61097b2e202SAlex Deucher 61197b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */ 61297b2e202SAlex Deucher struct amdgpu_vram_scratch { 61397b2e202SAlex Deucher struct amdgpu_bo *robj; 61497b2e202SAlex Deucher volatile uint32_t *ptr; 61597b2e202SAlex Deucher u64 gpu_addr; 61697b2e202SAlex Deucher }; 61797b2e202SAlex Deucher 61897b2e202SAlex Deucher /* 61997b2e202SAlex Deucher * ACPI 62097b2e202SAlex Deucher */ 62197b2e202SAlex Deucher struct amdgpu_atcs_functions { 62297b2e202SAlex Deucher bool get_ext_state; 62397b2e202SAlex Deucher bool pcie_perf_req; 62497b2e202SAlex Deucher bool pcie_dev_rdy; 62597b2e202SAlex Deucher bool pcie_bus_width; 62697b2e202SAlex Deucher }; 62797b2e202SAlex Deucher 62897b2e202SAlex Deucher struct amdgpu_atcs { 62997b2e202SAlex Deucher struct amdgpu_atcs_functions functions; 63097b2e202SAlex Deucher }; 63197b2e202SAlex Deucher 63297b2e202SAlex Deucher /* 633a05502e5SHorace Chen * Firmware VRAM reservation 634a05502e5SHorace Chen */ 635a05502e5SHorace Chen struct amdgpu_fw_vram_usage { 636a05502e5SHorace Chen u64 start_offset; 637a05502e5SHorace Chen u64 size; 638a05502e5SHorace Chen struct amdgpu_bo *reserved_bo; 639a05502e5SHorace Chen void *va; 640efe4f000STianci.Yin 6418d40002fSTianci.Yin /* GDDR6 training support flag. 642efe4f000STianci.Yin */ 643efe4f000STianci.Yin bool mem_train_support; 644a05502e5SHorace Chen }; 645a05502e5SHorace Chen 646a05502e5SHorace Chen /* 647d03846afSChunming Zhou * CGS 648d03846afSChunming Zhou */ 649110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev); 650110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device); 651a8fe58ceSMaruthi Bayyavarapu 652a8fe58ceSMaruthi Bayyavarapu /* 65397b2e202SAlex Deucher * Core structure, functions and helpers. 65497b2e202SAlex Deucher */ 65597b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t); 65697b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 65797b2e202SAlex Deucher 6584fa1c6a6STao Zhou typedef uint64_t (*amdgpu_rreg64_t)(struct amdgpu_device*, uint32_t); 6594fa1c6a6STao Zhou typedef void (*amdgpu_wreg64_t)(struct amdgpu_device*, uint32_t, uint64_t); 6604fa1c6a6STao Zhou 66197b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 66297b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t); 66397b2e202SAlex Deucher 66488807dc8SOak Zeng struct amdgpu_mmio_remap { 66588807dc8SOak Zeng u32 reg_offset; 66688807dc8SOak Zeng resource_size_t bus_addr; 66788807dc8SOak Zeng }; 66888807dc8SOak Zeng 6694522824cSShaoyun Liu /* Define the HW IP blocks will be used in driver , add more if necessary */ 6704522824cSShaoyun Liu enum amd_hw_ip_block_type { 6714522824cSShaoyun Liu GC_HWIP = 1, 6724522824cSShaoyun Liu HDP_HWIP, 6734522824cSShaoyun Liu SDMA0_HWIP, 6744522824cSShaoyun Liu SDMA1_HWIP, 675fa5d2e6fSLe Ma SDMA2_HWIP, 676fa5d2e6fSLe Ma SDMA3_HWIP, 677fa5d2e6fSLe Ma SDMA4_HWIP, 678fa5d2e6fSLe Ma SDMA5_HWIP, 679fa5d2e6fSLe Ma SDMA6_HWIP, 680fa5d2e6fSLe Ma SDMA7_HWIP, 6814522824cSShaoyun Liu MMHUB_HWIP, 6824522824cSShaoyun Liu ATHUB_HWIP, 6834522824cSShaoyun Liu NBIO_HWIP, 6844522824cSShaoyun Liu MP0_HWIP, 685e6636ae1SEvan Quan MP1_HWIP, 6864522824cSShaoyun Liu UVD_HWIP, 6874522824cSShaoyun Liu VCN_HWIP = UVD_HWIP, 68888a1c40aSLeo Liu JPEG_HWIP = VCN_HWIP, 6894522824cSShaoyun Liu VCE_HWIP, 6904522824cSShaoyun Liu DF_HWIP, 6914522824cSShaoyun Liu DCE_HWIP, 6924522824cSShaoyun Liu OSSSYS_HWIP, 6934522824cSShaoyun Liu SMUIO_HWIP, 6944522824cSShaoyun Liu PWR_HWIP, 6954522824cSShaoyun Liu NBIF_HWIP, 696e6636ae1SEvan Quan THM_HWIP, 69773b19174SRex Zhu CLK_HWIP, 6986501a771SHawking Zhang UMC_HWIP, 6996501a771SHawking Zhang RSMU_HWIP, 7004522824cSShaoyun Liu MAX_HWIP 7014522824cSShaoyun Liu }; 7024522824cSShaoyun Liu 703113b47e7SLe Ma #define HWIP_MAX_INSTANCE 8 7044522824cSShaoyun Liu 70511dc9364SRex Zhu struct amd_powerplay { 70611dc9364SRex Zhu void *pp_handle; 70711dc9364SRex Zhu const struct amd_pm_funcs *pp_funcs; 70811dc9364SRex Zhu }; 70911dc9364SRex Zhu 7100c49e0b8SChunming Zhou #define AMDGPU_RESET_MAGIC_NUM 64 711e4cf4bf5SJonathan Kim #define AMDGPU_MAX_DF_PERFMONS 4 71297b2e202SAlex Deucher struct amdgpu_device { 71397b2e202SAlex Deucher struct device *dev; 71497b2e202SAlex Deucher struct drm_device *ddev; 71597b2e202SAlex Deucher struct pci_dev *pdev; 71697b2e202SAlex Deucher 717a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP 718a8fe58ceSMaruthi Bayyavarapu struct amdgpu_acp acp; 719a8fe58ceSMaruthi Bayyavarapu #endif 720a8fe58ceSMaruthi Bayyavarapu 72197b2e202SAlex Deucher /* ASIC */ 7222f7d10b3SJammy Zhou enum amd_asic_type asic_type; 72397b2e202SAlex Deucher uint32_t family; 72497b2e202SAlex Deucher uint32_t rev_id; 72597b2e202SAlex Deucher uint32_t external_rev_id; 72697b2e202SAlex Deucher unsigned long flags; 72797b2e202SAlex Deucher int usec_timeout; 72897b2e202SAlex Deucher const struct amdgpu_asic_funcs *asic_funcs; 72997b2e202SAlex Deucher bool shutdown; 730fd5fd480SChunming Zhou bool need_swiotlb; 73197b2e202SAlex Deucher bool accel_working; 73297b2e202SAlex Deucher struct notifier_block acpi_nb; 73397b2e202SAlex Deucher struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS]; 73497b2e202SAlex Deucher struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 73597b2e202SAlex Deucher unsigned debugfs_count; 73697b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS) 7376698a3d0SJack Xiao struct dentry *debugfs_preempt; 738adcec288STom St Denis struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 73997b2e202SAlex Deucher #endif 740102c16a0SLyude Paul struct amdgpu_atif *atif; 74197b2e202SAlex Deucher struct amdgpu_atcs atcs; 74297b2e202SAlex Deucher struct mutex srbm_mutex; 74397b2e202SAlex Deucher /* GRBM index mutex. Protects concurrent access to GRBM index */ 74497b2e202SAlex Deucher struct mutex grbm_idx_mutex; 74597b2e202SAlex Deucher struct dev_pm_domain vga_pm_domain; 74697b2e202SAlex Deucher bool have_disp_power_ref; 747bae17d2aSJack Xiao bool have_atomics_support; 74897b2e202SAlex Deucher 74997b2e202SAlex Deucher /* BIOS */ 7500cdd5005SAlex Deucher bool is_atom_fw; 75197b2e202SAlex Deucher uint8_t *bios; 752a9f5db9cSEvan Quan uint32_t bios_size; 7535af2c10dSKent Russell struct amdgpu_bo *stolen_vga_memory; 7545f6a556fSXiaojie Yuan struct amdgpu_bo *discovery_memory; 755a5bde2f9SAlex Deucher uint32_t bios_scratch_reg_offset; 75697b2e202SAlex Deucher uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH]; 75797b2e202SAlex Deucher 75897b2e202SAlex Deucher /* Register/doorbell mmio */ 75997b2e202SAlex Deucher resource_size_t rmmio_base; 76097b2e202SAlex Deucher resource_size_t rmmio_size; 76197b2e202SAlex Deucher void __iomem *rmmio; 76297b2e202SAlex Deucher /* protects concurrent MM_INDEX/DATA based register access */ 76397b2e202SAlex Deucher spinlock_t mmio_idx_lock; 76488807dc8SOak Zeng struct amdgpu_mmio_remap rmmio_remap; 76597b2e202SAlex Deucher /* protects concurrent SMC based register access */ 76697b2e202SAlex Deucher spinlock_t smc_idx_lock; 76797b2e202SAlex Deucher amdgpu_rreg_t smc_rreg; 76897b2e202SAlex Deucher amdgpu_wreg_t smc_wreg; 76997b2e202SAlex Deucher /* protects concurrent PCIE register access */ 77097b2e202SAlex Deucher spinlock_t pcie_idx_lock; 77197b2e202SAlex Deucher amdgpu_rreg_t pcie_rreg; 77297b2e202SAlex Deucher amdgpu_wreg_t pcie_wreg; 77336b9a952SHuang Rui amdgpu_rreg_t pciep_rreg; 77436b9a952SHuang Rui amdgpu_wreg_t pciep_wreg; 7754fa1c6a6STao Zhou amdgpu_rreg64_t pcie_rreg64; 7764fa1c6a6STao Zhou amdgpu_wreg64_t pcie_wreg64; 77797b2e202SAlex Deucher /* protects concurrent UVD register access */ 77897b2e202SAlex Deucher spinlock_t uvd_ctx_idx_lock; 77997b2e202SAlex Deucher amdgpu_rreg_t uvd_ctx_rreg; 78097b2e202SAlex Deucher amdgpu_wreg_t uvd_ctx_wreg; 78197b2e202SAlex Deucher /* protects concurrent DIDT register access */ 78297b2e202SAlex Deucher spinlock_t didt_idx_lock; 78397b2e202SAlex Deucher amdgpu_rreg_t didt_rreg; 78497b2e202SAlex Deucher amdgpu_wreg_t didt_wreg; 785ccdbb20aSRex Zhu /* protects concurrent gc_cac register access */ 786ccdbb20aSRex Zhu spinlock_t gc_cac_idx_lock; 787ccdbb20aSRex Zhu amdgpu_rreg_t gc_cac_rreg; 788ccdbb20aSRex Zhu amdgpu_wreg_t gc_cac_wreg; 78916abb5d2SEvan Quan /* protects concurrent se_cac register access */ 79016abb5d2SEvan Quan spinlock_t se_cac_idx_lock; 79116abb5d2SEvan Quan amdgpu_rreg_t se_cac_rreg; 79216abb5d2SEvan Quan amdgpu_wreg_t se_cac_wreg; 79397b2e202SAlex Deucher /* protects concurrent ENDPOINT (audio) register access */ 79497b2e202SAlex Deucher spinlock_t audio_endpt_idx_lock; 79597b2e202SAlex Deucher amdgpu_block_rreg_t audio_endpt_rreg; 79697b2e202SAlex Deucher amdgpu_block_wreg_t audio_endpt_wreg; 79797b2e202SAlex Deucher void __iomem *rio_mem; 79897b2e202SAlex Deucher resource_size_t rio_mem_size; 79997b2e202SAlex Deucher struct amdgpu_doorbell doorbell; 80097b2e202SAlex Deucher 80197b2e202SAlex Deucher /* clock/pll info */ 80297b2e202SAlex Deucher struct amdgpu_clock clock; 80397b2e202SAlex Deucher 80497b2e202SAlex Deucher /* MC */ 805770d13b1SChristian König struct amdgpu_gmc gmc; 80697b2e202SAlex Deucher struct amdgpu_gart gart; 80792e71b06SChristian König dma_addr_t dummy_page_addr; 80897b2e202SAlex Deucher struct amdgpu_vm_manager vm_manager; 809e60f8db5SAlex Xie struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS]; 8101daa2bfaSLe Ma unsigned num_vmhubs; 81197b2e202SAlex Deucher 81297b2e202SAlex Deucher /* memory management */ 81397b2e202SAlex Deucher struct amdgpu_mman mman; 81497b2e202SAlex Deucher struct amdgpu_vram_scratch vram_scratch; 81597b2e202SAlex Deucher struct amdgpu_wb wb; 81697b2e202SAlex Deucher atomic64_t num_bytes_moved; 817dbd5ed60SChristian König atomic64_t num_evictions; 81868e2c5ffSMarek Olšák atomic64_t num_vram_cpu_page_faults; 819d94aed5aSMarek Olšák atomic_t gpu_reset_counter; 820f1892138SChunming Zhou atomic_t vram_lost_counter; 82197b2e202SAlex Deucher 82295844d20SMarek Olšák /* data for buffer migration throttling */ 82395844d20SMarek Olšák struct { 82495844d20SMarek Olšák spinlock_t lock; 82595844d20SMarek Olšák s64 last_update_us; 82695844d20SMarek Olšák s64 accum_us; /* accumulated microseconds */ 82700f06b24SJohn Brooks s64 accum_us_vis; /* for visible VRAM */ 82895844d20SMarek Olšák u32 log2_max_MBps; 82995844d20SMarek Olšák } mm_stats; 83095844d20SMarek Olšák 83197b2e202SAlex Deucher /* display */ 8329accf2fdSEmily Deng bool enable_virtual_display; 83397b2e202SAlex Deucher struct amdgpu_mode_info mode_info; 8344562236bSHarry Wentland /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */ 83597b2e202SAlex Deucher struct work_struct hotplug_work; 83697b2e202SAlex Deucher struct amdgpu_irq_src crtc_irq; 837d2574c33SMario Kleiner struct amdgpu_irq_src vupdate_irq; 83897b2e202SAlex Deucher struct amdgpu_irq_src pageflip_irq; 83997b2e202SAlex Deucher struct amdgpu_irq_src hpd_irq; 84097b2e202SAlex Deucher 84197b2e202SAlex Deucher /* rings */ 84276bf0db5SChristian König u64 fence_context; 84397b2e202SAlex Deucher unsigned num_rings; 84497b2e202SAlex Deucher struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; 84597b2e202SAlex Deucher bool ib_pool_ready; 84697b2e202SAlex Deucher struct amdgpu_sa_manager ring_tmp_bo; 84797b2e202SAlex Deucher 84897b2e202SAlex Deucher /* interrupts */ 84997b2e202SAlex Deucher struct amdgpu_irq irq; 85097b2e202SAlex Deucher 8511f7371b2SAlex Deucher /* powerplay */ 8521f7371b2SAlex Deucher struct amd_powerplay powerplay; 853f3898ea1SEric Huang bool pp_force_state_enabled; 8541f7371b2SAlex Deucher 855137d63abSHuang Rui /* smu */ 856137d63abSHuang Rui struct smu_context smu; 857137d63abSHuang Rui 85897b2e202SAlex Deucher /* dpm */ 85997b2e202SAlex Deucher struct amdgpu_pm pm; 86097b2e202SAlex Deucher u32 cg_flags; 86197b2e202SAlex Deucher u32 pg_flags; 86297b2e202SAlex Deucher 863bebc0762SHawking Zhang /* nbio */ 864bebc0762SHawking Zhang struct amdgpu_nbio nbio; 865bebc0762SHawking Zhang 866d3a5a121STao Zhou /* mmhub */ 867d3a5a121STao Zhou struct amdgpu_mmhub mmhub; 868d3a5a121STao Zhou 86997b2e202SAlex Deucher /* gfx */ 87097b2e202SAlex Deucher struct amdgpu_gfx gfx; 87197b2e202SAlex Deucher 87297b2e202SAlex Deucher /* sdma */ 873c113ea1cSAlex Deucher struct amdgpu_sdma sdma; 87497b2e202SAlex Deucher 87597b2e202SAlex Deucher /* uvd */ 87697b2e202SAlex Deucher struct amdgpu_uvd uvd; 87797b2e202SAlex Deucher 87897b2e202SAlex Deucher /* vce */ 87997b2e202SAlex Deucher struct amdgpu_vce vce; 88095d0906fSLeo Liu 88195d0906fSLeo Liu /* vcn */ 88295d0906fSLeo Liu struct amdgpu_vcn vcn; 88397b2e202SAlex Deucher 88488a1c40aSLeo Liu /* jpeg */ 88588a1c40aSLeo Liu struct amdgpu_jpeg jpeg; 88688a1c40aSLeo Liu 88797b2e202SAlex Deucher /* firmwares */ 88897b2e202SAlex Deucher struct amdgpu_firmware firmware; 88997b2e202SAlex Deucher 8900e5ca0d1SHuang Rui /* PSP */ 8910e5ca0d1SHuang Rui struct psp_context psp; 8920e5ca0d1SHuang Rui 89397b2e202SAlex Deucher /* GDS */ 89497b2e202SAlex Deucher struct amdgpu_gds gds; 89597b2e202SAlex Deucher 896611736d8SFelix Kuehling /* KFD */ 897611736d8SFelix Kuehling struct amdgpu_kfd_dev kfd; 898611736d8SFelix Kuehling 899045c0216STao Zhou /* UMC */ 900045c0216STao Zhou struct amdgpu_umc umc; 901045c0216STao Zhou 9024562236bSHarry Wentland /* display related functionality */ 9034562236bSHarry Wentland struct amdgpu_display_manager dm; 9044562236bSHarry Wentland 905f39f5bb1SXiaojie Yuan /* discovery */ 906f39f5bb1SXiaojie Yuan uint8_t *discovery; 907f39f5bb1SXiaojie Yuan 908a538bbe7SJack Xiao /* mes */ 909a538bbe7SJack Xiao bool enable_mes; 910a538bbe7SJack Xiao struct amdgpu_mes mes; 911a538bbe7SJack Xiao 912bdf84a80SJoseph Greathouse /* df */ 913bdf84a80SJoseph Greathouse struct amdgpu_df df; 914bdf84a80SJoseph Greathouse 915a1255107SAlex Deucher struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM]; 91697b2e202SAlex Deucher int num_ip_blocks; 91797b2e202SAlex Deucher struct mutex mn_lock; 91897b2e202SAlex Deucher DECLARE_HASHTABLE(mn_hash, 7); 91997b2e202SAlex Deucher 92097b2e202SAlex Deucher /* tracking pinned memory */ 921a5ccfe5cSMichel Dänzer atomic64_t vram_pin_size; 922a5ccfe5cSMichel Dänzer atomic64_t visible_pin_size; 923a5ccfe5cSMichel Dänzer atomic64_t gart_pin_size; 924130e0371SOded Gabbay 9254522824cSShaoyun Liu /* soc15 register offset based on ip, instance and segment */ 9264522824cSShaoyun Liu uint32_t *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE]; 9274522824cSShaoyun Liu 9282dc80b00SShirish S /* delayed work_func for deferring clockgating during resume */ 929beff74bcSAlex Deucher struct delayed_work delayed_init_work; 9302dc80b00SShirish S 9315a5099cbSXiangliang Yu struct amdgpu_virt virt; 932a05502e5SHorace Chen /* firmware VRAM reservation */ 933a05502e5SHorace Chen struct amdgpu_fw_vram_usage fw_vram_usage; 9340c4e7fa5SChunming Zhou 9350c4e7fa5SChunming Zhou /* link all shadow bo */ 9360c4e7fa5SChunming Zhou struct list_head shadow_list; 9370c4e7fa5SChunming Zhou struct mutex shadow_list_lock; 938795f2813SAndres Rodriguez /* keep an lru list of rings by HW IP */ 939795f2813SAndres Rodriguez struct list_head ring_lru_list; 940795f2813SAndres Rodriguez spinlock_t ring_lru_list_lock; 9415c1354bdSChunming Zhou 942c836fec5SJim Qu /* record hw reset is performed */ 943c836fec5SJim Qu bool has_hw_reset; 9440c49e0b8SChunming Zhou u8 reset_magic[AMDGPU_RESET_MAGIC_NUM]; 945c836fec5SJim Qu 94644779b43SRex Zhu /* s3/s4 mask */ 94744779b43SRex Zhu bool in_suspend; 94844779b43SRex Zhu 94947ed4e1cSKen Wang /* record last mm index being written through WREG32*/ 95047ed4e1cSKen Wang unsigned long last_mm_index; 95113a752e3SMonk Liu bool in_gpu_reset; 952a3a09142SAlex Deucher enum pp_mp1_state mp1_state; 95313a752e3SMonk Liu struct mutex lock_reset; 954409c5191SOak Zeng struct amdgpu_doorbell_index doorbell_index; 955d4535e2cSAndrey Grodzovsky 95662914a99SJason Gunthorpe struct mutex notifier_lock; 95762914a99SJason Gunthorpe 95826bc5340SAndrey Grodzovsky int asic_reset_res; 959d4535e2cSAndrey Grodzovsky struct work_struct xgmi_reset_work; 9609b638f97Sshaoyunl 961912dfc84SEvan Quan long gfx_timeout; 962912dfc84SEvan Quan long sdma_timeout; 963912dfc84SEvan Quan long video_timeout; 964912dfc84SEvan Quan long compute_timeout; 965fb2dbfd2SKent Russell 966fb2dbfd2SKent Russell uint64_t unique_id; 967e4cf4bf5SJonathan Kim uint64_t df_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS]; 9685c5b2ba0SEvan Quan 9695c5b2ba0SEvan Quan /* device pstate */ 9705c5b2ba0SEvan Quan int pstate; 9716ae6c7d4SAlex Deucher /* enable runtime pm on the device */ 9726ae6c7d4SAlex Deucher bool runpm; 973f0f7ddfcSAlex Deucher bool in_runpm; 9747c868b59SYintian Tao 9757c868b59SYintian Tao bool pm_sysfs_en; 9767c868b59SYintian Tao bool ucode_sysfs_en; 97797b2e202SAlex Deucher }; 97897b2e202SAlex Deucher 979a7d64de6SChristian König static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev) 980a7d64de6SChristian König { 981a7d64de6SChristian König return container_of(bdev, struct amdgpu_device, mman.bdev); 982a7d64de6SChristian König } 983a7d64de6SChristian König 98497b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev, 98597b2e202SAlex Deucher struct drm_device *ddev, 98697b2e202SAlex Deucher struct pci_dev *pdev, 98797b2e202SAlex Deucher uint32_t flags); 98897b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev); 98997b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); 99097b2e202SAlex Deucher 991e35e2b11STianci.Yin void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos, 992e35e2b11STianci.Yin uint32_t *buf, size_t size, bool write); 99397b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, 99415d72fd7SMonk Liu uint32_t acc_flags); 99597b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, 99615d72fd7SMonk Liu uint32_t acc_flags); 997421a2a30SMonk Liu void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value); 998421a2a30SMonk Liu uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset); 999421a2a30SMonk Liu 100097b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg); 100197b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v); 100297b2e202SAlex Deucher 10034562236bSHarry Wentland bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type); 10044562236bSHarry Wentland bool amdgpu_device_has_dc_support(struct amdgpu_device *adev); 10054562236bSHarry Wentland 10069475a943SShaoyun Liu int emu_soc_asic_init(struct amdgpu_device *adev); 10079475a943SShaoyun Liu 100897b2e202SAlex Deucher /* 100997b2e202SAlex Deucher * Registers read & write functions. 101097b2e202SAlex Deucher */ 101115d72fd7SMonk Liu 101215d72fd7SMonk Liu #define AMDGPU_REGS_IDX (1<<0) 101315d72fd7SMonk Liu #define AMDGPU_REGS_NO_KIQ (1<<1) 1014c68dbcd8Schen gong #define AMDGPU_REGS_KIQ (1<<2) 101515d72fd7SMonk Liu 101615d72fd7SMonk Liu #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ) 101715d72fd7SMonk Liu #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ) 101815d72fd7SMonk Liu 1019c68dbcd8Schen gong #define RREG32_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_KIQ) 1020c68dbcd8Schen gong #define WREG32_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_KIQ) 1021c68dbcd8Schen gong 1022421a2a30SMonk Liu #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg)) 1023421a2a30SMonk Liu #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v)) 1024421a2a30SMonk Liu 102515d72fd7SMonk Liu #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0) 102615d72fd7SMonk Liu #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX) 102715d72fd7SMonk Liu #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0)) 102815d72fd7SMonk Liu #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0) 102915d72fd7SMonk Liu #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX) 103097b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 103197b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 103297b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg)) 103397b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v)) 103436b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg)) 103536b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v)) 10364fa1c6a6STao Zhou #define RREG64_PCIE(reg) adev->pcie_rreg64(adev, (reg)) 10374fa1c6a6STao Zhou #define WREG64_PCIE(reg, v) adev->pcie_wreg64(adev, (reg), (v)) 103897b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg)) 103997b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v)) 104097b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg)) 104197b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v)) 104297b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg)) 104397b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v)) 1044ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg)) 1045ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v)) 104616abb5d2SEvan Quan #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg)) 104716abb5d2SEvan Quan #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v)) 104897b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg)) 104997b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v)) 105097b2e202SAlex Deucher #define WREG32_P(reg, val, mask) \ 105197b2e202SAlex Deucher do { \ 105297b2e202SAlex Deucher uint32_t tmp_ = RREG32(reg); \ 105397b2e202SAlex Deucher tmp_ &= (mask); \ 105497b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 105597b2e202SAlex Deucher WREG32(reg, tmp_); \ 105697b2e202SAlex Deucher } while (0) 105797b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and) 105897b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or)) 105997b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask) \ 106097b2e202SAlex Deucher do { \ 106197b2e202SAlex Deucher uint32_t tmp_ = RREG32_PLL(reg); \ 106297b2e202SAlex Deucher tmp_ &= (mask); \ 106397b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 106497b2e202SAlex Deucher WREG32_PLL(reg, tmp_); \ 106597b2e202SAlex Deucher } while (0) 106697b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false)) 106797b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg)) 106897b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v)) 106997b2e202SAlex Deucher 107097b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT 107197b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK 107297b2e202SAlex Deucher 107397b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val) \ 107497b2e202SAlex Deucher (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \ 107597b2e202SAlex Deucher (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) 107697b2e202SAlex Deucher 107797b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field) \ 107897b2e202SAlex Deucher (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field)) 107997b2e202SAlex Deucher 108061cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val) \ 108161cb8cefSTom St Denis WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 108261cb8cefSTom St Denis 1083ccaf3574STom St Denis #define WREG32_FIELD_OFFSET(reg, offset, field, val) \ 1084ccaf3574STom St Denis WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 1085ccaf3574STom St Denis 108697b2e202SAlex Deucher /* 108797b2e202SAlex Deucher * BIOS helpers. 108897b2e202SAlex Deucher */ 108997b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i]) 109097b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8)) 109197b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16)) 109297b2e202SAlex Deucher 109397b2e202SAlex Deucher /* 109497b2e202SAlex Deucher * ASICs macro. 109597b2e202SAlex Deucher */ 109697b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state)) 109797b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev)) 10980cf3c64fSAlex Deucher #define amdgpu_asic_reset_method(adev) (adev)->asic_funcs->reset_method((adev)) 109997b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev)) 110097b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d)) 110197b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec)) 1102841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev)) 1103841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l)) 1104841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev)) 110597b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev)) 11067946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l)) 110797b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v))) 1108bbf282d8SAlex Deucher #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev)) 110969882565SChristian König #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r)) 111069882565SChristian König #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r)) 111169070690SAlex Deucher #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev)) 11125253163aSOak Zeng #define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev)) 1113b45e18acSKent Russell #define amdgpu_asic_get_pcie_usage(adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1))) 111444401889SAlex Deucher #define amdgpu_asic_need_reset_on_init(adev) (adev)->asic_funcs->need_reset_on_init((adev)) 1115dcea6e65SKent Russell #define amdgpu_asic_get_pcie_replay_count(adev) ((adev)->asic_funcs->get_pcie_replay_count((adev))) 111669d5436dSAlex Deucher #define amdgpu_asic_supports_baco(adev) (adev)->asic_funcs->supports_baco((adev)) 111769d5436dSAlex Deucher 1118e3526257SMonk Liu #define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter)); 111997b2e202SAlex Deucher 112097b2e202SAlex Deucher /* Common functions */ 112112938fadSChristian König bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev); 11225f152b5eSAlex Deucher int amdgpu_device_gpu_recover(struct amdgpu_device *adev, 112312938fadSChristian König struct amdgpu_job* job); 11248111c387SAlex Deucher void amdgpu_device_pci_config_reset(struct amdgpu_device *adev); 112539c640c0SAlex Deucher bool amdgpu_device_need_post(struct amdgpu_device *adev); 1126d5fc5e82SChunming Zhou 112700f06b24SJohn Brooks void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes, 112800f06b24SJohn Brooks u64 num_vis_bytes); 1129d6895ad3SChristian König int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev); 11309c3f2b54SAlex Deucher void amdgpu_device_program_register_sequence(struct amdgpu_device *adev, 113197b2e202SAlex Deucher const u32 *registers, 113297b2e202SAlex Deucher const u32 array_size); 113397b2e202SAlex Deucher 113431af062aSAlex Deucher bool amdgpu_device_supports_boco(struct drm_device *dev); 1135a69cba42SAlex Deucher bool amdgpu_device_supports_baco(struct drm_device *dev); 1136992af942SJonathan Kim bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev, 1137992af942SJonathan Kim struct amdgpu_device *peer_adev); 1138361dbd01SAlex Deucher int amdgpu_device_baco_enter(struct drm_device *dev); 1139361dbd01SAlex Deucher int amdgpu_device_baco_exit(struct drm_device *dev); 1140992af942SJonathan Kim 114197b2e202SAlex Deucher /* atpx handler */ 114297b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO) 114397b2e202SAlex Deucher void amdgpu_register_atpx_handler(void); 114497b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void); 1145a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void); 11462f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void); 1147efc83cf4SAlex Deucher bool amdgpu_atpx_dgpu_req_power_for_displays(void); 1148714f88e0SAlex Xie bool amdgpu_has_atpx(void); 114997b2e202SAlex Deucher #else 115097b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {} 115197b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {} 1152a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; } 11532f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; } 1154efc83cf4SAlex Deucher static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; } 1155714f88e0SAlex Xie static inline bool amdgpu_has_atpx(void) { return false; } 115697b2e202SAlex Deucher #endif 115797b2e202SAlex Deucher 115824aeefcdSLyude Paul #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI) 115924aeefcdSLyude Paul void *amdgpu_atpx_get_dhandle(void); 116024aeefcdSLyude Paul #else 116124aeefcdSLyude Paul static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; } 116224aeefcdSLyude Paul #endif 116324aeefcdSLyude Paul 116497b2e202SAlex Deucher /* 116597b2e202SAlex Deucher * KMS 116697b2e202SAlex Deucher */ 116797b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[]; 1168f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl; 116997b2e202SAlex Deucher 117097b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags); 117111b3c20bSGabriel Krisman Bertazi void amdgpu_driver_unload_kms(struct drm_device *dev); 117297b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev); 117397b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv); 117497b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev, 117597b2e202SAlex Deucher struct drm_file *file_priv); 1176cdd61df6SAlex Deucher int amdgpu_device_ip_suspend(struct amdgpu_device *adev); 1177de185019SAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool fbcon); 1178de185019SAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool fbcon); 1179e3eff4b5SThomas Zimmermann u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc); 1180e3eff4b5SThomas Zimmermann int amdgpu_enable_vblank_kms(struct drm_crtc *crtc); 1181e3eff4b5SThomas Zimmermann void amdgpu_disable_vblank_kms(struct drm_crtc *crtc); 118297b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd, 118397b2e202SAlex Deucher unsigned long arg); 118497b2e202SAlex Deucher 118597b2e202SAlex Deucher /* 118697b2e202SAlex Deucher * functions used by amdgpu_encoder.c 118797b2e202SAlex Deucher */ 118897b2e202SAlex Deucher struct amdgpu_afmt_acr { 118997b2e202SAlex Deucher u32 clock; 119097b2e202SAlex Deucher 119197b2e202SAlex Deucher int n_32khz; 119297b2e202SAlex Deucher int cts_32khz; 119397b2e202SAlex Deucher 119497b2e202SAlex Deucher int n_44_1khz; 119597b2e202SAlex Deucher int cts_44_1khz; 119697b2e202SAlex Deucher 119797b2e202SAlex Deucher int n_48khz; 119897b2e202SAlex Deucher int cts_48khz; 119997b2e202SAlex Deucher 120097b2e202SAlex Deucher }; 120197b2e202SAlex Deucher 120297b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock); 120397b2e202SAlex Deucher 120497b2e202SAlex Deucher /* amdgpu_acpi.c */ 120597b2e202SAlex Deucher #if defined(CONFIG_ACPI) 120697b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev); 120797b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev); 120897b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev); 120997b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev, 121097b2e202SAlex Deucher u8 perf_req, bool advertise); 121197b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev); 1212206bbafeSDavid Francis 1213206bbafeSDavid Francis void amdgpu_acpi_get_backlight_caps(struct amdgpu_device *adev, 1214206bbafeSDavid Francis struct amdgpu_dm_backlight_caps *caps); 121597b2e202SAlex Deucher #else 121697b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; } 121797b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { } 121897b2e202SAlex Deucher #endif 121997b2e202SAlex Deucher 12209cca0b8eSChristian König int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser, 12219cca0b8eSChristian König uint64_t addr, struct amdgpu_bo **bo, 12229cca0b8eSChristian König struct amdgpu_bo_va_mapping **mapping); 122397b2e202SAlex Deucher 12244562236bSHarry Wentland #if defined(CONFIG_DRM_AMD_DC) 12254562236bSHarry Wentland int amdgpu_dm_display_resume(struct amdgpu_device *adev ); 12264562236bSHarry Wentland #else 12274562236bSHarry Wentland static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; } 12284562236bSHarry Wentland #endif 12294562236bSHarry Wentland 1230fdafb359SEvan Quan 1231fdafb359SEvan Quan void amdgpu_register_gpu_instance(struct amdgpu_device *adev); 1232fdafb359SEvan Quan void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev); 1233fdafb359SEvan Quan 123497b2e202SAlex Deucher #include "amdgpu_object.h" 1235e4cf4bf5SJonathan Kim 1236e4cf4bf5SJonathan Kim /* used by df_v3_6.c and amdgpu_pmu.c */ 1237e4cf4bf5SJonathan Kim #define AMDGPU_PMU_ATTR(_name, _object) \ 1238e4cf4bf5SJonathan Kim static ssize_t \ 1239e4cf4bf5SJonathan Kim _name##_show(struct device *dev, \ 1240e4cf4bf5SJonathan Kim struct device_attribute *attr, \ 1241e4cf4bf5SJonathan Kim char *page) \ 1242e4cf4bf5SJonathan Kim { \ 1243e4cf4bf5SJonathan Kim BUILD_BUG_ON(sizeof(_object) >= PAGE_SIZE - 1); \ 1244e4cf4bf5SJonathan Kim return sprintf(page, _object "\n"); \ 1245e4cf4bf5SJonathan Kim } \ 1246e4cf4bf5SJonathan Kim \ 1247e4cf4bf5SJonathan Kim static struct device_attribute pmu_attr_##_name = __ATTR_RO(_name) 1248e4cf4bf5SJonathan Kim 124997b2e202SAlex Deucher #endif 1250e4cf4bf5SJonathan Kim 1251