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> 3597b2e202SAlex Deucher #include <linux/interval_tree.h> 3697b2e202SAlex Deucher #include <linux/hashtable.h> 37f54d1867SChris Wilson #include <linux/dma-fence.h> 3897b2e202SAlex Deucher 3997b2e202SAlex Deucher #include <ttm/ttm_bo_api.h> 4097b2e202SAlex Deucher #include <ttm/ttm_bo_driver.h> 4197b2e202SAlex Deucher #include <ttm/ttm_placement.h> 4297b2e202SAlex Deucher #include <ttm/ttm_module.h> 4397b2e202SAlex Deucher #include <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> 4897b2e202SAlex Deucher 495fc3aeebSyanyang1 #include "amd_shared.h" 5097b2e202SAlex Deucher #include "amdgpu_mode.h" 5197b2e202SAlex Deucher #include "amdgpu_ih.h" 5297b2e202SAlex Deucher #include "amdgpu_irq.h" 5397b2e202SAlex Deucher #include "amdgpu_ucode.h" 54c632d799SFlora Cui #include "amdgpu_ttm.h" 5597b2e202SAlex Deucher #include "amdgpu_gds.h" 5656113504SChristian König #include "amdgpu_sync.h" 5778023016SChristian König #include "amdgpu_ring.h" 58073440d2SChristian König #include "amdgpu_vm.h" 591f7371b2SAlex Deucher #include "amd_powerplay.h" 60cf097881SAlex Deucher #include "amdgpu_dpm.h" 61a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h" 6297b2e202SAlex Deucher 63b80d8475SAlex Deucher #include "gpu_scheduler.h" 64ceeb50edSMonk Liu #include "amdgpu_virt.h" 65b80d8475SAlex Deucher 6697b2e202SAlex Deucher /* 6797b2e202SAlex Deucher * Modules parameters. 6897b2e202SAlex Deucher */ 6997b2e202SAlex Deucher extern int amdgpu_modeset; 7097b2e202SAlex Deucher extern int amdgpu_vram_limit; 7197b2e202SAlex Deucher extern int amdgpu_gart_size; 7295844d20SMarek Olšák extern int amdgpu_moverate; 7397b2e202SAlex Deucher extern int amdgpu_benchmarking; 7497b2e202SAlex Deucher extern int amdgpu_testing; 7597b2e202SAlex Deucher extern int amdgpu_audio; 7697b2e202SAlex Deucher extern int amdgpu_disp_priority; 7797b2e202SAlex Deucher extern int amdgpu_hw_i2c; 7897b2e202SAlex Deucher extern int amdgpu_pcie_gen2; 7997b2e202SAlex Deucher extern int amdgpu_msi; 8097b2e202SAlex Deucher extern int amdgpu_lockup_timeout; 8197b2e202SAlex Deucher extern int amdgpu_dpm; 8297b2e202SAlex Deucher extern int amdgpu_smc_load_fw; 8397b2e202SAlex Deucher extern int amdgpu_aspm; 8497b2e202SAlex Deucher extern int amdgpu_runtime_pm; 8597b2e202SAlex Deucher extern unsigned amdgpu_ip_block_mask; 8697b2e202SAlex Deucher extern int amdgpu_bapm; 8797b2e202SAlex Deucher extern int amdgpu_deep_color; 8897b2e202SAlex Deucher extern int amdgpu_vm_size; 8997b2e202SAlex Deucher extern int amdgpu_vm_block_size; 90d9c13156SChristian König extern int amdgpu_vm_fault_stop; 91b495bd3aSChristian König extern int amdgpu_vm_debug; 921333f723SJammy Zhou extern int amdgpu_sched_jobs; 934afcb303SJammy Zhou extern int amdgpu_sched_hw_submission; 941f7371b2SAlex Deucher extern int amdgpu_powerplay; 953ca67300SRex Zhu extern int amdgpu_no_evict; 963ca67300SRex Zhu extern int amdgpu_direct_gma_size; 97cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_gen_cap; 98cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_lane_cap; 99395d1fb9SNicolai Hähnle extern unsigned amdgpu_cg_mask; 100395d1fb9SNicolai Hähnle extern unsigned amdgpu_pg_mask; 1016f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu; 1029accf2fdSEmily Deng extern char *amdgpu_virtual_display; 1035141e9d2SRex Zhu extern unsigned amdgpu_pp_feature_mask; 1046a7f76e7SChristian König extern int amdgpu_vram_page_split; 10597b2e202SAlex Deucher 1064b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000 10797b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 10897b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) 10997b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */ 11097b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE 16 11197b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32 11297b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT 4 11397b2e202SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH 8 11497b2e202SAlex Deucher 11536f523a7SJammy Zhou /* max number of IP instances */ 11636f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES 2 11736f523a7SJammy Zhou 11897b2e202SAlex Deucher /* hardcode that limit for now */ 11997b2e202SAlex Deucher #define AMDGPU_VA_RESERVED_SIZE (8 << 20) 12097b2e202SAlex Deucher 12197b2e202SAlex Deucher /* hard reset data */ 12297b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b 12397b2e202SAlex Deucher 12497b2e202SAlex Deucher /* reset flags */ 12597b2e202SAlex Deucher #define AMDGPU_RESET_GFX (1 << 0) 12697b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE (1 << 1) 12797b2e202SAlex Deucher #define AMDGPU_RESET_DMA (1 << 2) 12897b2e202SAlex Deucher #define AMDGPU_RESET_CP (1 << 3) 12997b2e202SAlex Deucher #define AMDGPU_RESET_GRBM (1 << 4) 13097b2e202SAlex Deucher #define AMDGPU_RESET_DMA1 (1 << 5) 13197b2e202SAlex Deucher #define AMDGPU_RESET_RLC (1 << 6) 13297b2e202SAlex Deucher #define AMDGPU_RESET_SEM (1 << 7) 13397b2e202SAlex Deucher #define AMDGPU_RESET_IH (1 << 8) 13497b2e202SAlex Deucher #define AMDGPU_RESET_VMC (1 << 9) 13597b2e202SAlex Deucher #define AMDGPU_RESET_MC (1 << 10) 13697b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY (1 << 11) 13797b2e202SAlex Deucher #define AMDGPU_RESET_UVD (1 << 12) 13897b2e202SAlex Deucher #define AMDGPU_RESET_VCE (1 << 13) 13997b2e202SAlex Deucher #define AMDGPU_RESET_VCE1 (1 << 14) 14097b2e202SAlex Deucher 14197b2e202SAlex Deucher /* GFX current status */ 14297b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE 0x00000000L 14397b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE 0x00000001L 14497b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L 14597b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L 14697b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L 14797b2e202SAlex Deucher 14897b2e202SAlex Deucher /* max cursor sizes (in pixels) */ 14997b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128 15097b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128 15197b2e202SAlex Deucher 15297b2e202SAlex Deucher struct amdgpu_device; 15397b2e202SAlex Deucher struct amdgpu_ib; 15497b2e202SAlex Deucher struct amdgpu_cs_parser; 155bb977d37SChunming Zhou struct amdgpu_job; 15697b2e202SAlex Deucher struct amdgpu_irq_src; 1570b492a4cSAlex Deucher struct amdgpu_fpriv; 15897b2e202SAlex Deucher 15997b2e202SAlex Deucher enum amdgpu_cp_irq { 16097b2e202SAlex Deucher AMDGPU_CP_IRQ_GFX_EOP = 0, 16197b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP, 16297b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP, 16397b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP, 16497b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP, 16597b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP, 16697b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP, 16797b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP, 16897b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP, 16997b2e202SAlex Deucher 17097b2e202SAlex Deucher AMDGPU_CP_IRQ_LAST 17197b2e202SAlex Deucher }; 17297b2e202SAlex Deucher 17397b2e202SAlex Deucher enum amdgpu_sdma_irq { 17497b2e202SAlex Deucher AMDGPU_SDMA_IRQ_TRAP0 = 0, 17597b2e202SAlex Deucher AMDGPU_SDMA_IRQ_TRAP1, 17697b2e202SAlex Deucher 17797b2e202SAlex Deucher AMDGPU_SDMA_IRQ_LAST 17897b2e202SAlex Deucher }; 17997b2e202SAlex Deucher 18097b2e202SAlex Deucher enum amdgpu_thermal_irq { 18197b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0, 18297b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_HIGH_TO_LOW, 18397b2e202SAlex Deucher 18497b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LAST 18597b2e202SAlex Deucher }; 18697b2e202SAlex Deucher 18797b2e202SAlex Deucher int amdgpu_set_clockgating_state(struct amdgpu_device *adev, 1885fc3aeebSyanyang1 enum amd_ip_block_type block_type, 1895fc3aeebSyanyang1 enum amd_clockgating_state state); 19097b2e202SAlex Deucher int amdgpu_set_powergating_state(struct amdgpu_device *adev, 1915fc3aeebSyanyang1 enum amd_ip_block_type block_type, 1925fc3aeebSyanyang1 enum amd_powergating_state state); 1935dbbb60bSAlex Deucher int amdgpu_wait_for_idle(struct amdgpu_device *adev, 1945dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 1955dbbb60bSAlex Deucher bool amdgpu_is_idle(struct amdgpu_device *adev, 1965dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 19797b2e202SAlex Deucher 198a1255107SAlex Deucher #define AMDGPU_MAX_IP_NUM 16 199a1255107SAlex Deucher 200a1255107SAlex Deucher struct amdgpu_ip_block_status { 201a1255107SAlex Deucher bool valid; 202a1255107SAlex Deucher bool sw; 203a1255107SAlex Deucher bool hw; 204a1255107SAlex Deucher bool late_initialized; 205a1255107SAlex Deucher bool hang; 206a1255107SAlex Deucher }; 207a1255107SAlex Deucher 20897b2e202SAlex Deucher struct amdgpu_ip_block_version { 209a1255107SAlex Deucher const enum amd_ip_block_type type; 210a1255107SAlex Deucher const u32 major; 211a1255107SAlex Deucher const u32 minor; 212a1255107SAlex Deucher const u32 rev; 2135fc3aeebSyanyang1 const struct amd_ip_funcs *funcs; 21497b2e202SAlex Deucher }; 21597b2e202SAlex Deucher 216a1255107SAlex Deucher struct amdgpu_ip_block { 217a1255107SAlex Deucher struct amdgpu_ip_block_status status; 218a1255107SAlex Deucher const struct amdgpu_ip_block_version *version; 219a1255107SAlex Deucher }; 220a1255107SAlex Deucher 22197b2e202SAlex Deucher int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev, 2225fc3aeebSyanyang1 enum amd_ip_block_type type, 22397b2e202SAlex Deucher u32 major, u32 minor); 22497b2e202SAlex Deucher 225a1255107SAlex Deucher struct amdgpu_ip_block * amdgpu_get_ip_block(struct amdgpu_device *adev, 2265fc3aeebSyanyang1 enum amd_ip_block_type type); 22797b2e202SAlex Deucher 228a1255107SAlex Deucher int amdgpu_ip_block_add(struct amdgpu_device *adev, 229a1255107SAlex Deucher const struct amdgpu_ip_block_version *ip_block_version); 230a1255107SAlex Deucher 23197b2e202SAlex Deucher /* provided by hw blocks that can move/clear data. e.g., gfx or sdma */ 23297b2e202SAlex Deucher struct amdgpu_buffer_funcs { 23397b2e202SAlex Deucher /* maximum bytes in a single operation */ 23497b2e202SAlex Deucher uint32_t copy_max_bytes; 23597b2e202SAlex Deucher 23697b2e202SAlex Deucher /* number of dw to reserve per operation */ 23797b2e202SAlex Deucher unsigned copy_num_dw; 23897b2e202SAlex Deucher 23997b2e202SAlex Deucher /* used for buffer migration */ 240c7ae72c0SChunming Zhou void (*emit_copy_buffer)(struct amdgpu_ib *ib, 24197b2e202SAlex Deucher /* src addr in bytes */ 24297b2e202SAlex Deucher uint64_t src_offset, 24397b2e202SAlex Deucher /* dst addr in bytes */ 24497b2e202SAlex Deucher uint64_t dst_offset, 24597b2e202SAlex Deucher /* number of byte to transfer */ 24697b2e202SAlex Deucher uint32_t byte_count); 24797b2e202SAlex Deucher 24897b2e202SAlex Deucher /* maximum bytes in a single operation */ 24997b2e202SAlex Deucher uint32_t fill_max_bytes; 25097b2e202SAlex Deucher 25197b2e202SAlex Deucher /* number of dw to reserve per operation */ 25297b2e202SAlex Deucher unsigned fill_num_dw; 25397b2e202SAlex Deucher 25497b2e202SAlex Deucher /* used for buffer clearing */ 2556e7a3840SChunming Zhou void (*emit_fill_buffer)(struct amdgpu_ib *ib, 25697b2e202SAlex Deucher /* value to write to memory */ 25797b2e202SAlex Deucher uint32_t src_data, 25897b2e202SAlex Deucher /* dst addr in bytes */ 25997b2e202SAlex Deucher uint64_t dst_offset, 26097b2e202SAlex Deucher /* number of byte to fill */ 26197b2e202SAlex Deucher uint32_t byte_count); 26297b2e202SAlex Deucher }; 26397b2e202SAlex Deucher 26497b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */ 26597b2e202SAlex Deucher struct amdgpu_vm_pte_funcs { 26697b2e202SAlex Deucher /* copy pte entries from GART */ 26797b2e202SAlex Deucher void (*copy_pte)(struct amdgpu_ib *ib, 26897b2e202SAlex Deucher uint64_t pe, uint64_t src, 26997b2e202SAlex Deucher unsigned count); 27097b2e202SAlex Deucher /* write pte one entry at a time with addr mapping */ 271de9ea7bdSChristian König void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe, 272de9ea7bdSChristian König uint64_t value, unsigned count, 273de9ea7bdSChristian König uint32_t incr); 27497b2e202SAlex Deucher /* for linear pte/pde updates without addr mapping */ 27597b2e202SAlex Deucher void (*set_pte_pde)(struct amdgpu_ib *ib, 27697b2e202SAlex Deucher uint64_t pe, 27797b2e202SAlex Deucher uint64_t addr, unsigned count, 27897b2e202SAlex Deucher uint32_t incr, uint32_t flags); 27997b2e202SAlex Deucher }; 28097b2e202SAlex Deucher 28197b2e202SAlex Deucher /* provided by the gmc block */ 28297b2e202SAlex Deucher struct amdgpu_gart_funcs { 28397b2e202SAlex Deucher /* flush the vm tlb via mmio */ 28497b2e202SAlex Deucher void (*flush_gpu_tlb)(struct amdgpu_device *adev, 28597b2e202SAlex Deucher uint32_t vmid); 28697b2e202SAlex Deucher /* write pte/pde updates using the cpu */ 28797b2e202SAlex Deucher int (*set_pte_pde)(struct amdgpu_device *adev, 28897b2e202SAlex Deucher void *cpu_pt_addr, /* cpu addr of page table */ 28997b2e202SAlex Deucher uint32_t gpu_page_idx, /* pte/pde to update */ 29097b2e202SAlex Deucher uint64_t addr, /* addr to write into pte/pde */ 29197b2e202SAlex Deucher uint32_t flags); /* access flags */ 29297b2e202SAlex Deucher }; 29397b2e202SAlex Deucher 29497b2e202SAlex Deucher /* provided by the ih block */ 29597b2e202SAlex Deucher struct amdgpu_ih_funcs { 29697b2e202SAlex Deucher /* ring read/write ptr handling, called from interrupt context */ 29797b2e202SAlex Deucher u32 (*get_wptr)(struct amdgpu_device *adev); 29897b2e202SAlex Deucher void (*decode_iv)(struct amdgpu_device *adev, 29997b2e202SAlex Deucher struct amdgpu_iv_entry *entry); 30097b2e202SAlex Deucher void (*set_rptr)(struct amdgpu_device *adev); 30197b2e202SAlex Deucher }; 30297b2e202SAlex Deucher 30397b2e202SAlex Deucher /* 30497b2e202SAlex Deucher * BIOS. 30597b2e202SAlex Deucher */ 30697b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev); 30797b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev); 30897b2e202SAlex Deucher 30997b2e202SAlex Deucher /* 31097b2e202SAlex Deucher * Dummy page 31197b2e202SAlex Deucher */ 31297b2e202SAlex Deucher struct amdgpu_dummy_page { 31397b2e202SAlex Deucher struct page *page; 31497b2e202SAlex Deucher dma_addr_t addr; 31597b2e202SAlex Deucher }; 31697b2e202SAlex Deucher int amdgpu_dummy_page_init(struct amdgpu_device *adev); 31797b2e202SAlex Deucher void amdgpu_dummy_page_fini(struct amdgpu_device *adev); 31897b2e202SAlex Deucher 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 /* 340c632d799SFlora Cui * BO. 34197b2e202SAlex Deucher */ 34297b2e202SAlex Deucher struct amdgpu_bo_list_entry { 34397b2e202SAlex Deucher struct amdgpu_bo *robj; 34497b2e202SAlex Deucher struct ttm_validate_buffer tv; 34597b2e202SAlex Deucher struct amdgpu_bo_va *bo_va; 34697b2e202SAlex Deucher uint32_t priority; 3472f568dbdSChristian König struct page **user_pages; 3482f568dbdSChristian König int user_invalidated; 34997b2e202SAlex Deucher }; 35097b2e202SAlex Deucher 35197b2e202SAlex Deucher struct amdgpu_bo_va_mapping { 35297b2e202SAlex Deucher struct list_head list; 35397b2e202SAlex Deucher struct interval_tree_node it; 35497b2e202SAlex Deucher uint64_t offset; 35597b2e202SAlex Deucher uint32_t flags; 35697b2e202SAlex Deucher }; 35797b2e202SAlex Deucher 35897b2e202SAlex Deucher /* bo virtual addresses in a specific vm */ 35997b2e202SAlex Deucher struct amdgpu_bo_va { 36097b2e202SAlex Deucher /* protected by bo being reserved */ 36197b2e202SAlex Deucher struct list_head bo_list; 362f54d1867SChris Wilson struct dma_fence *last_pt_update; 36397b2e202SAlex Deucher unsigned ref_count; 36497b2e202SAlex Deucher 3657fc11959SChristian König /* protected by vm mutex and spinlock */ 36697b2e202SAlex Deucher struct list_head vm_status; 36797b2e202SAlex Deucher 3687fc11959SChristian König /* mappings for this bo_va */ 3697fc11959SChristian König struct list_head invalids; 3707fc11959SChristian König struct list_head valids; 3717fc11959SChristian König 37297b2e202SAlex Deucher /* constant after initialization */ 37397b2e202SAlex Deucher struct amdgpu_vm *vm; 37497b2e202SAlex Deucher struct amdgpu_bo *bo; 37597b2e202SAlex Deucher }; 37697b2e202SAlex Deucher 3777e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX 0x3 3787e5a547fSChunming Zhou 37997b2e202SAlex Deucher struct amdgpu_bo { 38097b2e202SAlex Deucher /* Protected by tbo.reserved */ 3811ea863fdSChristian König u32 prefered_domains; 3821ea863fdSChristian König u32 allowed_domains; 3837e5a547fSChunming Zhou struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1]; 38497b2e202SAlex Deucher struct ttm_placement placement; 38597b2e202SAlex Deucher struct ttm_buffer_object tbo; 38697b2e202SAlex Deucher struct ttm_bo_kmap_obj kmap; 38797b2e202SAlex Deucher u64 flags; 38897b2e202SAlex Deucher unsigned pin_count; 38997b2e202SAlex Deucher void *kptr; 39097b2e202SAlex Deucher u64 tiling_flags; 39197b2e202SAlex Deucher u64 metadata_flags; 39297b2e202SAlex Deucher void *metadata; 39397b2e202SAlex Deucher u32 metadata_size; 39497b2e202SAlex Deucher /* list of all virtual address to which this bo 39597b2e202SAlex Deucher * is associated to 39697b2e202SAlex Deucher */ 39797b2e202SAlex Deucher struct list_head va; 39897b2e202SAlex Deucher /* Constant after initialization */ 39997b2e202SAlex Deucher struct drm_gem_object gem_base; 40082b9c55bSChristian König struct amdgpu_bo *parent; 401e7893c4bSChunming Zhou struct amdgpu_bo *shadow; 40297b2e202SAlex Deucher 40397b2e202SAlex Deucher struct ttm_bo_kmap_obj dma_buf_vmap; 40497b2e202SAlex Deucher struct amdgpu_mn *mn; 40597b2e202SAlex Deucher struct list_head mn_list; 4060c4e7fa5SChunming Zhou struct list_head shadow_list; 40797b2e202SAlex Deucher }; 40897b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base) 40997b2e202SAlex Deucher 41097b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj); 41197b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj, 41297b2e202SAlex Deucher struct drm_file *file_priv); 41397b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj, 41497b2e202SAlex Deucher struct drm_file *file_priv); 41597b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns); 41697b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj); 4174d9c514dSChristian König struct drm_gem_object * 4184d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev, 41997b2e202SAlex Deucher struct dma_buf_attachment *attach, 42097b2e202SAlex Deucher struct sg_table *sg); 42197b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev, 42297b2e202SAlex Deucher struct drm_gem_object *gobj, 42397b2e202SAlex Deucher int flags); 42497b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj); 42597b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj); 42697b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *); 42797b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj); 42897b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); 42997b2e202SAlex Deucher int amdgpu_gem_debugfs_init(struct amdgpu_device *adev); 43097b2e202SAlex Deucher 43197b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock. 43297b2e202SAlex Deucher * By conception this is an helper for other part of the driver 43397b2e202SAlex Deucher * like the indirect buffer or semaphore, which both have their 43497b2e202SAlex Deucher * locking. 43597b2e202SAlex Deucher * 43697b2e202SAlex Deucher * Principe is simple, we keep a list of sub allocation in offset 43797b2e202SAlex Deucher * order (first entry has offset == 0, last entry has the highest 43897b2e202SAlex Deucher * offset). 43997b2e202SAlex Deucher * 44097b2e202SAlex Deucher * When allocating new object we first check if there is room at 44197b2e202SAlex Deucher * the end total_size - (last_object_offset + last_object_size) >= 44297b2e202SAlex Deucher * alloc_size. If so we allocate new object there. 44397b2e202SAlex Deucher * 44497b2e202SAlex Deucher * When there is not enough room at the end, we start waiting for 44597b2e202SAlex Deucher * each sub object until we reach object_offset+object_size >= 44697b2e202SAlex Deucher * alloc_size, this object then become the sub object we return. 44797b2e202SAlex Deucher * 44897b2e202SAlex Deucher * Alignment can't be bigger than page size. 44997b2e202SAlex Deucher * 45097b2e202SAlex Deucher * Hole are not considered for allocation to keep things simple. 45197b2e202SAlex Deucher * Assumption is that there won't be hole (all object on same 45297b2e202SAlex Deucher * alignment). 45397b2e202SAlex Deucher */ 4546ba60b89SChristian König 4556ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS 32 4566ba60b89SChristian König 45797b2e202SAlex Deucher struct amdgpu_sa_manager { 45897b2e202SAlex Deucher wait_queue_head_t wq; 45997b2e202SAlex Deucher struct amdgpu_bo *bo; 46097b2e202SAlex Deucher struct list_head *hole; 4616ba60b89SChristian König struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS]; 46297b2e202SAlex Deucher struct list_head olist; 46397b2e202SAlex Deucher unsigned size; 46497b2e202SAlex Deucher uint64_t gpu_addr; 46597b2e202SAlex Deucher void *cpu_ptr; 46697b2e202SAlex Deucher uint32_t domain; 46797b2e202SAlex Deucher uint32_t align; 46897b2e202SAlex Deucher }; 46997b2e202SAlex Deucher 47097b2e202SAlex Deucher /* sub-allocation buffer */ 47197b2e202SAlex Deucher struct amdgpu_sa_bo { 47297b2e202SAlex Deucher struct list_head olist; 47397b2e202SAlex Deucher struct list_head flist; 47497b2e202SAlex Deucher struct amdgpu_sa_manager *manager; 47597b2e202SAlex Deucher unsigned soffset; 47697b2e202SAlex Deucher unsigned eoffset; 477f54d1867SChris Wilson struct dma_fence *fence; 47897b2e202SAlex Deucher }; 47997b2e202SAlex Deucher 48097b2e202SAlex Deucher /* 48197b2e202SAlex Deucher * GEM objects. 48297b2e202SAlex Deucher */ 483418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev); 48497b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, 48597b2e202SAlex Deucher int alignment, u32 initial_domain, 48697b2e202SAlex Deucher u64 flags, bool kernel, 48797b2e202SAlex Deucher struct drm_gem_object **obj); 48897b2e202SAlex Deucher 48997b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv, 49097b2e202SAlex Deucher struct drm_device *dev, 49197b2e202SAlex Deucher struct drm_mode_create_dumb *args); 49297b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp, 49397b2e202SAlex Deucher struct drm_device *dev, 49497b2e202SAlex Deucher uint32_t handle, uint64_t *offset_p); 495d573de2dSRex Zhu int amdgpu_fence_slab_init(void); 496d573de2dSRex Zhu void amdgpu_fence_slab_fini(void); 49797b2e202SAlex Deucher 49897b2e202SAlex Deucher /* 49997b2e202SAlex Deucher * GART structures, functions & helpers 50097b2e202SAlex Deucher */ 50197b2e202SAlex Deucher struct amdgpu_mc; 50297b2e202SAlex Deucher 50397b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SIZE 4096 50497b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1) 50597b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SHIFT 12 50697b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK) 50797b2e202SAlex Deucher 50897b2e202SAlex Deucher struct amdgpu_gart { 50997b2e202SAlex Deucher dma_addr_t table_addr; 51097b2e202SAlex Deucher struct amdgpu_bo *robj; 51197b2e202SAlex Deucher void *ptr; 51297b2e202SAlex Deucher unsigned num_gpu_pages; 51397b2e202SAlex Deucher unsigned num_cpu_pages; 51497b2e202SAlex Deucher unsigned table_size; 515a1d29476SChristian König #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS 51697b2e202SAlex Deucher struct page **pages; 517a1d29476SChristian König #endif 51897b2e202SAlex Deucher bool ready; 51997b2e202SAlex Deucher const struct amdgpu_gart_funcs *gart_funcs; 52097b2e202SAlex Deucher }; 52197b2e202SAlex Deucher 52297b2e202SAlex Deucher int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev); 52397b2e202SAlex Deucher void amdgpu_gart_table_ram_free(struct amdgpu_device *adev); 52497b2e202SAlex Deucher int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev); 52597b2e202SAlex Deucher void amdgpu_gart_table_vram_free(struct amdgpu_device *adev); 52697b2e202SAlex Deucher int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev); 52797b2e202SAlex Deucher void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev); 52897b2e202SAlex Deucher int amdgpu_gart_init(struct amdgpu_device *adev); 52997b2e202SAlex Deucher void amdgpu_gart_fini(struct amdgpu_device *adev); 530cab0b8d5SFelix Kuehling void amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset, 53197b2e202SAlex Deucher int pages); 532cab0b8d5SFelix Kuehling int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset, 53397b2e202SAlex Deucher int pages, struct page **pagelist, 53497b2e202SAlex Deucher dma_addr_t *dma_addr, uint32_t flags); 5352c0d7318SChunming Zhou int amdgpu_ttm_recover_gart(struct amdgpu_device *adev); 53697b2e202SAlex Deucher 53797b2e202SAlex Deucher /* 53897b2e202SAlex Deucher * GPU MC structures, functions & helpers 53997b2e202SAlex Deucher */ 54097b2e202SAlex Deucher struct amdgpu_mc { 54197b2e202SAlex Deucher resource_size_t aper_size; 54297b2e202SAlex Deucher resource_size_t aper_base; 54397b2e202SAlex Deucher resource_size_t agp_base; 54497b2e202SAlex Deucher /* for some chips with <= 32MB we need to lie 54597b2e202SAlex Deucher * about vram size near mc fb location */ 54697b2e202SAlex Deucher u64 mc_vram_size; 54797b2e202SAlex Deucher u64 visible_vram_size; 54897b2e202SAlex Deucher u64 gtt_size; 54997b2e202SAlex Deucher u64 gtt_start; 55097b2e202SAlex Deucher u64 gtt_end; 55197b2e202SAlex Deucher u64 vram_start; 55297b2e202SAlex Deucher u64 vram_end; 55397b2e202SAlex Deucher unsigned vram_width; 55497b2e202SAlex Deucher u64 real_vram_size; 55597b2e202SAlex Deucher int vram_mtrr; 55697b2e202SAlex Deucher u64 gtt_base_align; 55797b2e202SAlex Deucher u64 mc_mask; 55897b2e202SAlex Deucher const struct firmware *fw; /* MC firmware */ 55997b2e202SAlex Deucher uint32_t fw_version; 56097b2e202SAlex Deucher struct amdgpu_irq_src vm_fault; 56181c59f54SKen Wang uint32_t vram_type; 56250b0197aSChunming Zhou uint32_t srbm_soft_reset; 56350b0197aSChunming Zhou struct amdgpu_mode_mc_save save; 56497b2e202SAlex Deucher }; 56597b2e202SAlex Deucher 56697b2e202SAlex Deucher /* 56797b2e202SAlex Deucher * GPU doorbell structures, functions & helpers 56897b2e202SAlex Deucher */ 56997b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT 57097b2e202SAlex Deucher { 57197b2e202SAlex Deucher AMDGPU_DOORBELL_KIQ = 0x000, 57297b2e202SAlex Deucher AMDGPU_DOORBELL_HIQ = 0x001, 57397b2e202SAlex Deucher AMDGPU_DOORBELL_DIQ = 0x002, 57497b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING0 = 0x010, 57597b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING1 = 0x011, 57697b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING2 = 0x012, 57797b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING3 = 0x013, 57897b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING4 = 0x014, 57997b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING5 = 0x015, 58097b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING6 = 0x016, 58197b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING7 = 0x017, 58297b2e202SAlex Deucher AMDGPU_DOORBELL_GFX_RING0 = 0x020, 58397b2e202SAlex Deucher AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0, 58497b2e202SAlex Deucher AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1, 58597b2e202SAlex Deucher AMDGPU_DOORBELL_IH = 0x1E8, 58697b2e202SAlex Deucher AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF, 58797b2e202SAlex Deucher AMDGPU_DOORBELL_INVALID = 0xFFFF 58897b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT; 58997b2e202SAlex Deucher 59097b2e202SAlex Deucher struct amdgpu_doorbell { 59197b2e202SAlex Deucher /* doorbell mmio */ 59297b2e202SAlex Deucher resource_size_t base; 59397b2e202SAlex Deucher resource_size_t size; 59497b2e202SAlex Deucher u32 __iomem *ptr; 59597b2e202SAlex Deucher u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */ 59697b2e202SAlex Deucher }; 59797b2e202SAlex Deucher 59897b2e202SAlex Deucher void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev, 59997b2e202SAlex Deucher phys_addr_t *aperture_base, 60097b2e202SAlex Deucher size_t *aperture_size, 60197b2e202SAlex Deucher size_t *start_offset); 60297b2e202SAlex Deucher 60397b2e202SAlex Deucher /* 60497b2e202SAlex Deucher * IRQS. 60597b2e202SAlex Deucher */ 60697b2e202SAlex Deucher 60797b2e202SAlex Deucher struct amdgpu_flip_work { 608325cbba1SMichel Dänzer struct delayed_work flip_work; 60997b2e202SAlex Deucher struct work_struct unpin_work; 61097b2e202SAlex Deucher struct amdgpu_device *adev; 61197b2e202SAlex Deucher int crtc_id; 612325cbba1SMichel Dänzer u32 target_vblank; 61397b2e202SAlex Deucher uint64_t base; 61497b2e202SAlex Deucher struct drm_pending_vblank_event *event; 615765e7fbfSChristian König struct amdgpu_bo *old_abo; 616f54d1867SChris Wilson struct dma_fence *excl; 6171ffd2652SChristian König unsigned shared_count; 618f54d1867SChris Wilson struct dma_fence **shared; 619f54d1867SChris Wilson struct dma_fence_cb cb; 620cb9e59d7SAlex Deucher bool async; 62197b2e202SAlex Deucher }; 62297b2e202SAlex Deucher 62397b2e202SAlex Deucher 62497b2e202SAlex Deucher /* 62597b2e202SAlex Deucher * CP & rings. 62697b2e202SAlex Deucher */ 62797b2e202SAlex Deucher 62897b2e202SAlex Deucher struct amdgpu_ib { 62997b2e202SAlex Deucher struct amdgpu_sa_bo *sa_bo; 63097b2e202SAlex Deucher uint32_t length_dw; 63197b2e202SAlex Deucher uint64_t gpu_addr; 63297b2e202SAlex Deucher uint32_t *ptr; 633de807f81SJammy Zhou uint32_t flags; 63497b2e202SAlex Deucher }; 63597b2e202SAlex Deucher 63662250a91SNils Wallménius extern const struct amd_sched_backend_ops amdgpu_sched_ops; 637c1b69ed0SChunming Zhou 63850838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, 639c5637837SMonk Liu struct amdgpu_job **job, struct amdgpu_vm *vm); 640d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size, 641d71518b5SChristian König struct amdgpu_job **job); 642b6723c8dSMonk Liu 643a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job); 64450838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job); 645d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring, 6462bd9ccfaSChristian König struct amd_sched_entity *entity, void *owner, 647f54d1867SChris Wilson struct dma_fence **f); 6483c704e93SChunming Zhou 64997b2e202SAlex Deucher /* 65097b2e202SAlex Deucher * context related structures 65197b2e202SAlex Deucher */ 65297b2e202SAlex Deucher 65321c16bf6SChristian König struct amdgpu_ctx_ring { 65421c16bf6SChristian König uint64_t sequence; 655f54d1867SChris Wilson struct dma_fence **fences; 65691404fb2SChristian König struct amd_sched_entity entity; 65721c16bf6SChristian König }; 65821c16bf6SChristian König 65997b2e202SAlex Deucher struct amdgpu_ctx { 66097b2e202SAlex Deucher struct kref refcount; 6619cb7e5a9SChunming Zhou struct amdgpu_device *adev; 662d94aed5aSMarek Olšák unsigned reset_counter; 66321c16bf6SChristian König spinlock_t ring_lock; 664f54d1867SChris Wilson struct dma_fence **fences; 66521c16bf6SChristian König struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS]; 666753ad49cSMonk Liu bool preamble_presented; 66797b2e202SAlex Deucher }; 66897b2e202SAlex Deucher 66997b2e202SAlex Deucher struct amdgpu_ctx_mgr { 67097b2e202SAlex Deucher struct amdgpu_device *adev; 6710147ee0fSMarek Olšák struct mutex lock; 6720b492a4cSAlex Deucher /* protected by lock */ 6730b492a4cSAlex Deucher struct idr ctx_handles; 67497b2e202SAlex Deucher }; 67597b2e202SAlex Deucher 6760b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id); 6770b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx); 6780b492a4cSAlex Deucher 67921c16bf6SChristian König uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring, 680f54d1867SChris Wilson struct dma_fence *fence); 681f54d1867SChris Wilson struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, 68221c16bf6SChristian König struct amdgpu_ring *ring, uint64_t seq); 68321c16bf6SChristian König 6840b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, 6850b492a4cSAlex Deucher struct drm_file *filp); 6860b492a4cSAlex Deucher 687efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr); 688efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); 6890b492a4cSAlex Deucher 69097b2e202SAlex Deucher /* 69197b2e202SAlex Deucher * file private structure 69297b2e202SAlex Deucher */ 69397b2e202SAlex Deucher 69497b2e202SAlex Deucher struct amdgpu_fpriv { 69597b2e202SAlex Deucher struct amdgpu_vm vm; 69697b2e202SAlex Deucher struct mutex bo_list_lock; 69797b2e202SAlex Deucher struct idr bo_list_handles; 69897b2e202SAlex Deucher struct amdgpu_ctx_mgr ctx_mgr; 69997b2e202SAlex Deucher }; 70097b2e202SAlex Deucher 70197b2e202SAlex Deucher /* 70297b2e202SAlex Deucher * residency list 70397b2e202SAlex Deucher */ 70497b2e202SAlex Deucher 70597b2e202SAlex Deucher struct amdgpu_bo_list { 70697b2e202SAlex Deucher struct mutex lock; 70797b2e202SAlex Deucher struct amdgpu_bo *gds_obj; 70897b2e202SAlex Deucher struct amdgpu_bo *gws_obj; 70997b2e202SAlex Deucher struct amdgpu_bo *oa_obj; 710211dff55SChristian König unsigned first_userptr; 71197b2e202SAlex Deucher unsigned num_entries; 71297b2e202SAlex Deucher struct amdgpu_bo_list_entry *array; 71397b2e202SAlex Deucher }; 71497b2e202SAlex Deucher 71597b2e202SAlex Deucher struct amdgpu_bo_list * 71697b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id); 717636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list, 718636ce25cSChristian König struct list_head *validated); 71997b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list); 72097b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list); 72197b2e202SAlex Deucher 72297b2e202SAlex Deucher /* 72397b2e202SAlex Deucher * GFX stuff 72497b2e202SAlex Deucher */ 72597b2e202SAlex Deucher #include "clearstate_defs.h" 72697b2e202SAlex Deucher 72779e5412cSAlex Deucher struct amdgpu_rlc_funcs { 72879e5412cSAlex Deucher void (*enter_safe_mode)(struct amdgpu_device *adev); 72979e5412cSAlex Deucher void (*exit_safe_mode)(struct amdgpu_device *adev); 73079e5412cSAlex Deucher }; 73179e5412cSAlex Deucher 73297b2e202SAlex Deucher struct amdgpu_rlc { 73397b2e202SAlex Deucher /* for power gating */ 73497b2e202SAlex Deucher struct amdgpu_bo *save_restore_obj; 73597b2e202SAlex Deucher uint64_t save_restore_gpu_addr; 73697b2e202SAlex Deucher volatile uint32_t *sr_ptr; 73797b2e202SAlex Deucher const u32 *reg_list; 73897b2e202SAlex Deucher u32 reg_list_size; 73997b2e202SAlex Deucher /* for clear state */ 74097b2e202SAlex Deucher struct amdgpu_bo *clear_state_obj; 74197b2e202SAlex Deucher uint64_t clear_state_gpu_addr; 74297b2e202SAlex Deucher volatile uint32_t *cs_ptr; 74397b2e202SAlex Deucher const struct cs_section_def *cs_data; 74497b2e202SAlex Deucher u32 clear_state_size; 74597b2e202SAlex Deucher /* for cp tables */ 74697b2e202SAlex Deucher struct amdgpu_bo *cp_table_obj; 74797b2e202SAlex Deucher uint64_t cp_table_gpu_addr; 74897b2e202SAlex Deucher volatile uint32_t *cp_table_ptr; 74997b2e202SAlex Deucher u32 cp_table_size; 75079e5412cSAlex Deucher 75179e5412cSAlex Deucher /* safe mode for updating CG/PG state */ 75279e5412cSAlex Deucher bool in_safe_mode; 75379e5412cSAlex Deucher const struct amdgpu_rlc_funcs *funcs; 7542b6cd977SEric Huang 7552b6cd977SEric Huang /* for firmware data */ 7562b6cd977SEric Huang u32 save_and_restore_offset; 7572b6cd977SEric Huang u32 clear_state_descriptor_offset; 7582b6cd977SEric Huang u32 avail_scratch_ram_locations; 7592b6cd977SEric Huang u32 reg_restore_list_size; 7602b6cd977SEric Huang u32 reg_list_format_start; 7612b6cd977SEric Huang u32 reg_list_format_separate_start; 7622b6cd977SEric Huang u32 starting_offsets_start; 7632b6cd977SEric Huang u32 reg_list_format_size_bytes; 7642b6cd977SEric Huang u32 reg_list_size_bytes; 7652b6cd977SEric Huang 7662b6cd977SEric Huang u32 *register_list_format; 7672b6cd977SEric Huang u32 *register_restore; 76897b2e202SAlex Deucher }; 76997b2e202SAlex Deucher 77097b2e202SAlex Deucher struct amdgpu_mec { 77197b2e202SAlex Deucher struct amdgpu_bo *hpd_eop_obj; 77297b2e202SAlex Deucher u64 hpd_eop_gpu_addr; 77397b2e202SAlex Deucher u32 num_pipe; 77497b2e202SAlex Deucher u32 num_mec; 77597b2e202SAlex Deucher u32 num_queue; 77697b2e202SAlex Deucher }; 77797b2e202SAlex Deucher 77897b2e202SAlex Deucher /* 77997b2e202SAlex Deucher * GPU scratch registers structures, functions & helpers 78097b2e202SAlex Deucher */ 78197b2e202SAlex Deucher struct amdgpu_scratch { 78297b2e202SAlex Deucher unsigned num_reg; 78397b2e202SAlex Deucher uint32_t reg_base; 78497b2e202SAlex Deucher bool free[32]; 78597b2e202SAlex Deucher uint32_t reg[32]; 78697b2e202SAlex Deucher }; 78797b2e202SAlex Deucher 78897b2e202SAlex Deucher /* 78997b2e202SAlex Deucher * GFX configurations 79097b2e202SAlex Deucher */ 791e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SE 4 792e3fa7630SAlex Deucher #define AMDGPU_GFX_MAX_SH_PER_SE 2 793e3fa7630SAlex Deucher 794e3fa7630SAlex Deucher struct amdgpu_rb_config { 795e3fa7630SAlex Deucher uint32_t rb_backend_disable; 796e3fa7630SAlex Deucher uint32_t user_rb_backend_disable; 797e3fa7630SAlex Deucher uint32_t raster_config; 798e3fa7630SAlex Deucher uint32_t raster_config_1; 799e3fa7630SAlex Deucher }; 800e3fa7630SAlex Deucher 80197b2e202SAlex Deucher struct amdgpu_gca_config { 80297b2e202SAlex Deucher unsigned max_shader_engines; 80397b2e202SAlex Deucher unsigned max_tile_pipes; 80497b2e202SAlex Deucher unsigned max_cu_per_sh; 80597b2e202SAlex Deucher unsigned max_sh_per_se; 80697b2e202SAlex Deucher unsigned max_backends_per_se; 80797b2e202SAlex Deucher unsigned max_texture_channel_caches; 80897b2e202SAlex Deucher unsigned max_gprs; 80997b2e202SAlex Deucher unsigned max_gs_threads; 81097b2e202SAlex Deucher unsigned max_hw_contexts; 81197b2e202SAlex Deucher unsigned sc_prim_fifo_size_frontend; 81297b2e202SAlex Deucher unsigned sc_prim_fifo_size_backend; 81397b2e202SAlex Deucher unsigned sc_hiz_tile_fifo_size; 81497b2e202SAlex Deucher unsigned sc_earlyz_tile_fifo_size; 81597b2e202SAlex Deucher 81697b2e202SAlex Deucher unsigned num_tile_pipes; 81797b2e202SAlex Deucher unsigned backend_enable_mask; 81897b2e202SAlex Deucher unsigned mem_max_burst_length_bytes; 81997b2e202SAlex Deucher unsigned mem_row_size_in_kb; 82097b2e202SAlex Deucher unsigned shader_engine_tile_size; 82197b2e202SAlex Deucher unsigned num_gpus; 82297b2e202SAlex Deucher unsigned multi_gpu_tile_size; 82397b2e202SAlex Deucher unsigned mc_arb_ramcfg; 82497b2e202SAlex Deucher unsigned gb_addr_config; 8258f8e00c1SAlex Deucher unsigned num_rbs; 82697b2e202SAlex Deucher 82797b2e202SAlex Deucher uint32_t tile_mode_array[32]; 82897b2e202SAlex Deucher uint32_t macrotile_mode_array[16]; 829e3fa7630SAlex Deucher 830e3fa7630SAlex Deucher struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE]; 83197b2e202SAlex Deucher }; 83297b2e202SAlex Deucher 8337dae69a2SAlex Deucher struct amdgpu_cu_info { 8347dae69a2SAlex Deucher uint32_t number; /* total active CU number */ 8357dae69a2SAlex Deucher uint32_t ao_cu_mask; 8367dae69a2SAlex Deucher uint32_t bitmap[4][4]; 8377dae69a2SAlex Deucher }; 8387dae69a2SAlex Deucher 839b95e31fdSAlex Deucher struct amdgpu_gfx_funcs { 840b95e31fdSAlex Deucher /* get the gpu clock counter */ 841b95e31fdSAlex Deucher uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev); 8429559ef5bSTom St Denis void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance); 843472259f0STom St Denis void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields); 844b95e31fdSAlex Deucher }; 845b95e31fdSAlex Deucher 84697b2e202SAlex Deucher struct amdgpu_gfx { 84797b2e202SAlex Deucher struct mutex gpu_clock_mutex; 84897b2e202SAlex Deucher struct amdgpu_gca_config config; 84997b2e202SAlex Deucher struct amdgpu_rlc rlc; 85097b2e202SAlex Deucher struct amdgpu_mec mec; 85197b2e202SAlex Deucher struct amdgpu_scratch scratch; 85297b2e202SAlex Deucher const struct firmware *me_fw; /* ME firmware */ 85397b2e202SAlex Deucher uint32_t me_fw_version; 85497b2e202SAlex Deucher const struct firmware *pfp_fw; /* PFP firmware */ 85597b2e202SAlex Deucher uint32_t pfp_fw_version; 85697b2e202SAlex Deucher const struct firmware *ce_fw; /* CE firmware */ 85797b2e202SAlex Deucher uint32_t ce_fw_version; 85897b2e202SAlex Deucher const struct firmware *rlc_fw; /* RLC firmware */ 85997b2e202SAlex Deucher uint32_t rlc_fw_version; 86097b2e202SAlex Deucher const struct firmware *mec_fw; /* MEC firmware */ 86197b2e202SAlex Deucher uint32_t mec_fw_version; 86297b2e202SAlex Deucher const struct firmware *mec2_fw; /* MEC2 firmware */ 86397b2e202SAlex Deucher uint32_t mec2_fw_version; 86402558a00SKen Wang uint32_t me_feature_version; 86502558a00SKen Wang uint32_t ce_feature_version; 86602558a00SKen Wang uint32_t pfp_feature_version; 867351643d7SJammy Zhou uint32_t rlc_feature_version; 868351643d7SJammy Zhou uint32_t mec_feature_version; 869351643d7SJammy Zhou uint32_t mec2_feature_version; 87097b2e202SAlex Deucher struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS]; 87197b2e202SAlex Deucher unsigned num_gfx_rings; 87297b2e202SAlex Deucher struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS]; 87397b2e202SAlex Deucher unsigned num_compute_rings; 87497b2e202SAlex Deucher struct amdgpu_irq_src eop_irq; 87597b2e202SAlex Deucher struct amdgpu_irq_src priv_reg_irq; 87697b2e202SAlex Deucher struct amdgpu_irq_src priv_inst_irq; 87797b2e202SAlex Deucher /* gfx status */ 87897b2e202SAlex Deucher uint32_t gfx_current_status; 879a101a899SKen Wang /* ce ram size*/ 880a101a899SKen Wang unsigned ce_ram_size; 8817dae69a2SAlex Deucher struct amdgpu_cu_info cu_info; 882b95e31fdSAlex Deucher const struct amdgpu_gfx_funcs *funcs; 8833d7c6384SChunming Zhou 8843d7c6384SChunming Zhou /* reset mask */ 8853d7c6384SChunming Zhou uint32_t grbm_soft_reset; 8863d7c6384SChunming Zhou uint32_t srbm_soft_reset; 88797b2e202SAlex Deucher }; 88897b2e202SAlex Deucher 889b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, 89097b2e202SAlex Deucher unsigned size, struct amdgpu_ib *ib); 8914d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, 892f54d1867SChris Wilson struct dma_fence *f); 893b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, 894f54d1867SChris Wilson struct amdgpu_ib *ib, struct dma_fence *last_vm_update, 895f54d1867SChris Wilson struct amdgpu_job *job, struct dma_fence **f); 89697b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev); 89797b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev); 89897b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev); 89997b2e202SAlex Deucher 90097b2e202SAlex Deucher /* 90197b2e202SAlex Deucher * CS. 90297b2e202SAlex Deucher */ 90397b2e202SAlex Deucher struct amdgpu_cs_chunk { 90497b2e202SAlex Deucher uint32_t chunk_id; 90597b2e202SAlex Deucher uint32_t length_dw; 906758ac17fSChristian König void *kdata; 90797b2e202SAlex Deucher }; 90897b2e202SAlex Deucher 90997b2e202SAlex Deucher struct amdgpu_cs_parser { 91097b2e202SAlex Deucher struct amdgpu_device *adev; 91197b2e202SAlex Deucher struct drm_file *filp; 9123cb485f3SChristian König struct amdgpu_ctx *ctx; 913c3cca41eSChristian König 91497b2e202SAlex Deucher /* chunks */ 91597b2e202SAlex Deucher unsigned nchunks; 91697b2e202SAlex Deucher struct amdgpu_cs_chunk *chunks; 917c3cca41eSChristian König 91850838c8cSChristian König /* scheduler job object */ 91950838c8cSChristian König struct amdgpu_job *job; 920c3cca41eSChristian König 921c3cca41eSChristian König /* buffer objects */ 922c3cca41eSChristian König struct ww_acquire_ctx ticket; 923c3cca41eSChristian König struct amdgpu_bo_list *bo_list; 92456467ebfSChristian König struct amdgpu_bo_list_entry vm_pd; 92597b2e202SAlex Deucher struct list_head validated; 926f54d1867SChris Wilson struct dma_fence *fence; 927f69f90a1SChristian König uint64_t bytes_moved_threshold; 928f69f90a1SChristian König uint64_t bytes_moved; 929662bfa61SChristian König struct amdgpu_bo_list_entry *evictable; 93097b2e202SAlex Deucher 93197b2e202SAlex Deucher /* user fence */ 93291acbeb6SChristian König struct amdgpu_bo_list_entry uf_entry; 93397b2e202SAlex Deucher }; 93497b2e202SAlex Deucher 935753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */ 936753ad49cSMonk Liu #define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */ 937753ad49cSMonk Liu #define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */ 938753ad49cSMonk Liu 939bb977d37SChunming Zhou struct amdgpu_job { 940bb977d37SChunming Zhou struct amd_sched_job base; 941bb977d37SChunming Zhou struct amdgpu_device *adev; 942c5637837SMonk Liu struct amdgpu_vm *vm; 943b07c60c0SChristian König struct amdgpu_ring *ring; 944e86f9ceeSChristian König struct amdgpu_sync sync; 945bb977d37SChunming Zhou struct amdgpu_ib *ibs; 946f54d1867SChris Wilson struct dma_fence *fence; /* the hw fence */ 947753ad49cSMonk Liu uint32_t preamble_status; 948bb977d37SChunming Zhou uint32_t num_ibs; 949e2840221SChristian König void *owner; 9503aecd24cSMonk Liu uint64_t fence_ctx; /* the fence_context this job uses */ 951fd53be30SChunming Zhou bool vm_needs_flush; 952d88bf583SChristian König unsigned vm_id; 953d88bf583SChristian König uint64_t vm_pd_addr; 954d88bf583SChristian König uint32_t gds_base, gds_size; 955d88bf583SChristian König uint32_t gws_base, gws_size; 956d88bf583SChristian König uint32_t oa_base, oa_size; 957758ac17fSChristian König 958758ac17fSChristian König /* user fence handling */ 959b5f5acbcSChristian König uint64_t uf_addr; 960758ac17fSChristian König uint64_t uf_sequence; 961758ac17fSChristian König 962bb977d37SChunming Zhou }; 963a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job) \ 964a6db8a33SJunwei Zhang container_of((sched_job), struct amdgpu_job, base) 965bb977d37SChunming Zhou 9667270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, 9677270f839SChristian König uint32_t ib_idx, int idx) 96897b2e202SAlex Deucher { 96950838c8cSChristian König return p->job->ibs[ib_idx].ptr[idx]; 97097b2e202SAlex Deucher } 97197b2e202SAlex Deucher 9727270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p, 9737270f839SChristian König uint32_t ib_idx, int idx, 9747270f839SChristian König uint32_t value) 9757270f839SChristian König { 97650838c8cSChristian König p->job->ibs[ib_idx].ptr[idx] = value; 9777270f839SChristian König } 9787270f839SChristian König 97997b2e202SAlex Deucher /* 98097b2e202SAlex Deucher * Writeback 98197b2e202SAlex Deucher */ 98297b2e202SAlex Deucher #define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */ 98397b2e202SAlex Deucher 98497b2e202SAlex Deucher struct amdgpu_wb { 98597b2e202SAlex Deucher struct amdgpu_bo *wb_obj; 98697b2e202SAlex Deucher volatile uint32_t *wb; 98797b2e202SAlex Deucher uint64_t gpu_addr; 98897b2e202SAlex Deucher u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */ 98997b2e202SAlex Deucher unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)]; 99097b2e202SAlex Deucher }; 99197b2e202SAlex Deucher 99297b2e202SAlex Deucher int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb); 99397b2e202SAlex Deucher void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb); 99497b2e202SAlex Deucher 995d0dd7f0cSAlex Deucher void amdgpu_get_pcie_info(struct amdgpu_device *adev); 996d0dd7f0cSAlex Deucher 99797b2e202SAlex Deucher /* 99897b2e202SAlex Deucher * UVD 99997b2e202SAlex Deucher */ 1000c0365541SArindam Nath #define AMDGPU_DEFAULT_UVD_HANDLES 10 1001c0365541SArindam Nath #define AMDGPU_MAX_UVD_HANDLES 40 1002c0365541SArindam Nath #define AMDGPU_UVD_STACK_SIZE (200*1024) 1003c0365541SArindam Nath #define AMDGPU_UVD_HEAP_SIZE (256*1024) 1004c0365541SArindam Nath #define AMDGPU_UVD_SESSION_SIZE (50*1024) 100597b2e202SAlex Deucher #define AMDGPU_UVD_FIRMWARE_OFFSET 256 100697b2e202SAlex Deucher 100797b2e202SAlex Deucher struct amdgpu_uvd { 100897b2e202SAlex Deucher struct amdgpu_bo *vcpu_bo; 100997b2e202SAlex Deucher void *cpu_addr; 101097b2e202SAlex Deucher uint64_t gpu_addr; 1011562e2689SSonny Jiang unsigned fw_version; 10123f99dd81SLeo Liu void *saved_bo; 1013c0365541SArindam Nath unsigned max_handles; 101497b2e202SAlex Deucher atomic_t handles[AMDGPU_MAX_UVD_HANDLES]; 101597b2e202SAlex Deucher struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES]; 101697b2e202SAlex Deucher struct delayed_work idle_work; 101797b2e202SAlex Deucher const struct firmware *fw; /* UVD firmware */ 101897b2e202SAlex Deucher struct amdgpu_ring ring; 101997b2e202SAlex Deucher struct amdgpu_irq_src irq; 102097b2e202SAlex Deucher bool address_64_bit; 10214cb5877cSChristian König bool use_ctx_buf; 1022ead833ecSChristian König struct amd_sched_entity entity; 1023fc0b3b90SChunming Zhou uint32_t srbm_soft_reset; 102497b2e202SAlex Deucher }; 102597b2e202SAlex Deucher 102697b2e202SAlex Deucher /* 102797b2e202SAlex Deucher * VCE 102897b2e202SAlex Deucher */ 102997b2e202SAlex Deucher #define AMDGPU_MAX_VCE_HANDLES 16 103097b2e202SAlex Deucher #define AMDGPU_VCE_FIRMWARE_OFFSET 256 103197b2e202SAlex Deucher 10326a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0) 10336a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1) 10346a585777SAlex Deucher 103597b2e202SAlex Deucher struct amdgpu_vce { 103697b2e202SAlex Deucher struct amdgpu_bo *vcpu_bo; 103797b2e202SAlex Deucher uint64_t gpu_addr; 103897b2e202SAlex Deucher unsigned fw_version; 103997b2e202SAlex Deucher unsigned fb_version; 104097b2e202SAlex Deucher atomic_t handles[AMDGPU_MAX_VCE_HANDLES]; 104197b2e202SAlex Deucher struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES]; 1042f1689ec1SChristian König uint32_t img_size[AMDGPU_MAX_VCE_HANDLES]; 104397b2e202SAlex Deucher struct delayed_work idle_work; 1044ebff485eSChristian König struct mutex idle_mutex; 104597b2e202SAlex Deucher const struct firmware *fw; /* VCE firmware */ 104697b2e202SAlex Deucher struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS]; 104797b2e202SAlex Deucher struct amdgpu_irq_src irq; 10486a585777SAlex Deucher unsigned harvest_config; 1049c594989cSChristian König struct amd_sched_entity entity; 1050115933a5SChunming Zhou uint32_t srbm_soft_reset; 105175c65480SAlex Deucher unsigned num_rings; 105297b2e202SAlex Deucher }; 105397b2e202SAlex Deucher 105497b2e202SAlex Deucher /* 105597b2e202SAlex Deucher * SDMA 105697b2e202SAlex Deucher */ 1057c113ea1cSAlex Deucher struct amdgpu_sdma_instance { 105897b2e202SAlex Deucher /* SDMA firmware */ 105997b2e202SAlex Deucher const struct firmware *fw; 106097b2e202SAlex Deucher uint32_t fw_version; 1061cfa2104fSJammy Zhou uint32_t feature_version; 106297b2e202SAlex Deucher 106397b2e202SAlex Deucher struct amdgpu_ring ring; 106418111de0SJammy Zhou bool burst_nop; 106597b2e202SAlex Deucher }; 106697b2e202SAlex Deucher 1067c113ea1cSAlex Deucher struct amdgpu_sdma { 1068c113ea1cSAlex Deucher struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES]; 106930d1574fSKen Wang #ifdef CONFIG_DRM_AMDGPU_SI 107030d1574fSKen Wang //SI DMA has a difference trap irq number for the second engine 107130d1574fSKen Wang struct amdgpu_irq_src trap_irq_1; 107230d1574fSKen Wang #endif 1073c113ea1cSAlex Deucher struct amdgpu_irq_src trap_irq; 1074c113ea1cSAlex Deucher struct amdgpu_irq_src illegal_inst_irq; 1075c113ea1cSAlex Deucher int num_instances; 1076e702a680SChunming Zhou uint32_t srbm_soft_reset; 1077c113ea1cSAlex Deucher }; 1078c113ea1cSAlex Deucher 107997b2e202SAlex Deucher /* 108097b2e202SAlex Deucher * Firmware 108197b2e202SAlex Deucher */ 108297b2e202SAlex Deucher struct amdgpu_firmware { 108397b2e202SAlex Deucher struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM]; 108497b2e202SAlex Deucher bool smu_load; 108597b2e202SAlex Deucher struct amdgpu_bo *fw_buf; 108697b2e202SAlex Deucher unsigned int fw_size; 108797b2e202SAlex Deucher }; 108897b2e202SAlex Deucher 108997b2e202SAlex Deucher /* 109097b2e202SAlex Deucher * Benchmarking 109197b2e202SAlex Deucher */ 109297b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number); 109397b2e202SAlex Deucher 109497b2e202SAlex Deucher 109597b2e202SAlex Deucher /* 109697b2e202SAlex Deucher * Testing 109797b2e202SAlex Deucher */ 109897b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev); 109997b2e202SAlex Deucher void amdgpu_test_ring_sync(struct amdgpu_device *adev, 110097b2e202SAlex Deucher struct amdgpu_ring *cpA, 110197b2e202SAlex Deucher struct amdgpu_ring *cpB); 110297b2e202SAlex Deucher void amdgpu_test_syncing(struct amdgpu_device *adev); 110397b2e202SAlex Deucher 110497b2e202SAlex Deucher /* 110597b2e202SAlex Deucher * MMU Notifier 110697b2e202SAlex Deucher */ 110797b2e202SAlex Deucher #if defined(CONFIG_MMU_NOTIFIER) 110897b2e202SAlex Deucher int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr); 110997b2e202SAlex Deucher void amdgpu_mn_unregister(struct amdgpu_bo *bo); 111097b2e202SAlex Deucher #else 11111d1106b0SHarry Wentland static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) 111297b2e202SAlex Deucher { 111397b2e202SAlex Deucher return -ENODEV; 111497b2e202SAlex Deucher } 11151d1106b0SHarry Wentland static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {} 111697b2e202SAlex Deucher #endif 111797b2e202SAlex Deucher 111897b2e202SAlex Deucher /* 111997b2e202SAlex Deucher * Debugfs 112097b2e202SAlex Deucher */ 112197b2e202SAlex Deucher struct amdgpu_debugfs { 112206ab6832SNils Wallménius const struct drm_info_list *files; 112397b2e202SAlex Deucher unsigned num_files; 112497b2e202SAlex Deucher }; 112597b2e202SAlex Deucher 112697b2e202SAlex Deucher int amdgpu_debugfs_add_files(struct amdgpu_device *adev, 112706ab6832SNils Wallménius const struct drm_info_list *files, 112897b2e202SAlex Deucher unsigned nfiles); 112997b2e202SAlex Deucher int amdgpu_debugfs_fence_init(struct amdgpu_device *adev); 113097b2e202SAlex Deucher 113197b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS) 113297b2e202SAlex Deucher int amdgpu_debugfs_init(struct drm_minor *minor); 113397b2e202SAlex Deucher void amdgpu_debugfs_cleanup(struct drm_minor *minor); 113497b2e202SAlex Deucher #endif 113597b2e202SAlex Deucher 113650ab2533SHuang Rui int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev); 113750ab2533SHuang Rui 113897b2e202SAlex Deucher /* 113997b2e202SAlex Deucher * amdgpu smumgr functions 114097b2e202SAlex Deucher */ 114197b2e202SAlex Deucher struct amdgpu_smumgr_funcs { 114297b2e202SAlex Deucher int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype); 114397b2e202SAlex Deucher int (*request_smu_load_fw)(struct amdgpu_device *adev); 114497b2e202SAlex Deucher int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype); 114597b2e202SAlex Deucher }; 114697b2e202SAlex Deucher 114797b2e202SAlex Deucher /* 114897b2e202SAlex Deucher * amdgpu smumgr 114997b2e202SAlex Deucher */ 115097b2e202SAlex Deucher struct amdgpu_smumgr { 115197b2e202SAlex Deucher struct amdgpu_bo *toc_buf; 115297b2e202SAlex Deucher struct amdgpu_bo *smu_buf; 115397b2e202SAlex Deucher /* asic priv smu data */ 115497b2e202SAlex Deucher void *priv; 115597b2e202SAlex Deucher spinlock_t smu_lock; 115697b2e202SAlex Deucher /* smumgr functions */ 115797b2e202SAlex Deucher const struct amdgpu_smumgr_funcs *smumgr_funcs; 115897b2e202SAlex Deucher /* ucode loading complete flag */ 115997b2e202SAlex Deucher uint32_t fw_flags; 116097b2e202SAlex Deucher }; 116197b2e202SAlex Deucher 116297b2e202SAlex Deucher /* 116397b2e202SAlex Deucher * ASIC specific register table accessible by UMD 116497b2e202SAlex Deucher */ 116597b2e202SAlex Deucher struct amdgpu_allowed_register_entry { 116697b2e202SAlex Deucher uint32_t reg_offset; 116797b2e202SAlex Deucher bool untouched; 116897b2e202SAlex Deucher bool grbm_indexed; 116997b2e202SAlex Deucher }; 117097b2e202SAlex Deucher 117197b2e202SAlex Deucher /* 117297b2e202SAlex Deucher * ASIC specific functions. 117397b2e202SAlex Deucher */ 117497b2e202SAlex Deucher struct amdgpu_asic_funcs { 117597b2e202SAlex Deucher bool (*read_disabled_bios)(struct amdgpu_device *adev); 11767946b878SAlex Deucher bool (*read_bios_from_rom)(struct amdgpu_device *adev, 11777946b878SAlex Deucher u8 *bios, u32 length_bytes); 11784e99a44eSMonk Liu void (*detect_hw_virtualization) (struct amdgpu_device *adev); 117997b2e202SAlex Deucher int (*read_register)(struct amdgpu_device *adev, u32 se_num, 118097b2e202SAlex Deucher u32 sh_num, u32 reg_offset, u32 *value); 118197b2e202SAlex Deucher void (*set_vga_state)(struct amdgpu_device *adev, bool state); 118297b2e202SAlex Deucher int (*reset)(struct amdgpu_device *adev); 118397b2e202SAlex Deucher /* get the reference clock */ 118497b2e202SAlex Deucher u32 (*get_xclk)(struct amdgpu_device *adev); 118597b2e202SAlex Deucher /* MM block clocks */ 118697b2e202SAlex Deucher int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk); 118797b2e202SAlex Deucher int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk); 1188841686dfSMaruthi Bayyavarapu /* static power management */ 1189841686dfSMaruthi Bayyavarapu int (*get_pcie_lanes)(struct amdgpu_device *adev); 1190841686dfSMaruthi Bayyavarapu void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes); 119197b2e202SAlex Deucher }; 119297b2e202SAlex Deucher 119397b2e202SAlex Deucher /* 119497b2e202SAlex Deucher * IOCTL. 119597b2e202SAlex Deucher */ 119697b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, 119797b2e202SAlex Deucher struct drm_file *filp); 119897b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, 119997b2e202SAlex Deucher struct drm_file *filp); 120097b2e202SAlex Deucher 120197b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, 120297b2e202SAlex Deucher struct drm_file *filp); 120397b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, 120497b2e202SAlex Deucher struct drm_file *filp); 120597b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data, 120697b2e202SAlex Deucher struct drm_file *filp); 120797b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data, 120897b2e202SAlex Deucher struct drm_file *filp); 120997b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, 121097b2e202SAlex Deucher struct drm_file *filp); 121197b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, 121297b2e202SAlex Deucher struct drm_file *filp); 121397b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 121497b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 1215eef18a82SJunwei Zhang int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, 1216eef18a82SJunwei Zhang struct drm_file *filp); 121797b2e202SAlex Deucher 121897b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data, 121997b2e202SAlex Deucher struct drm_file *filp); 122097b2e202SAlex Deucher 122197b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */ 122297b2e202SAlex Deucher struct amdgpu_vram_scratch { 122397b2e202SAlex Deucher struct amdgpu_bo *robj; 122497b2e202SAlex Deucher volatile uint32_t *ptr; 122597b2e202SAlex Deucher u64 gpu_addr; 122697b2e202SAlex Deucher }; 122797b2e202SAlex Deucher 122897b2e202SAlex Deucher /* 122997b2e202SAlex Deucher * ACPI 123097b2e202SAlex Deucher */ 123197b2e202SAlex Deucher struct amdgpu_atif_notification_cfg { 123297b2e202SAlex Deucher bool enabled; 123397b2e202SAlex Deucher int command_code; 123497b2e202SAlex Deucher }; 123597b2e202SAlex Deucher 123697b2e202SAlex Deucher struct amdgpu_atif_notifications { 123797b2e202SAlex Deucher bool display_switch; 123897b2e202SAlex Deucher bool expansion_mode_change; 123997b2e202SAlex Deucher bool thermal_state; 124097b2e202SAlex Deucher bool forced_power_state; 124197b2e202SAlex Deucher bool system_power_state; 124297b2e202SAlex Deucher bool display_conf_change; 124397b2e202SAlex Deucher bool px_gfx_switch; 124497b2e202SAlex Deucher bool brightness_change; 124597b2e202SAlex Deucher bool dgpu_display_event; 124697b2e202SAlex Deucher }; 124797b2e202SAlex Deucher 124897b2e202SAlex Deucher struct amdgpu_atif_functions { 124997b2e202SAlex Deucher bool system_params; 125097b2e202SAlex Deucher bool sbios_requests; 125197b2e202SAlex Deucher bool select_active_disp; 125297b2e202SAlex Deucher bool lid_state; 125397b2e202SAlex Deucher bool get_tv_standard; 125497b2e202SAlex Deucher bool set_tv_standard; 125597b2e202SAlex Deucher bool get_panel_expansion_mode; 125697b2e202SAlex Deucher bool set_panel_expansion_mode; 125797b2e202SAlex Deucher bool temperature_change; 125897b2e202SAlex Deucher bool graphics_device_types; 125997b2e202SAlex Deucher }; 126097b2e202SAlex Deucher 126197b2e202SAlex Deucher struct amdgpu_atif { 126297b2e202SAlex Deucher struct amdgpu_atif_notifications notifications; 126397b2e202SAlex Deucher struct amdgpu_atif_functions functions; 126497b2e202SAlex Deucher struct amdgpu_atif_notification_cfg notification_cfg; 126597b2e202SAlex Deucher struct amdgpu_encoder *encoder_for_bl; 126697b2e202SAlex Deucher }; 126797b2e202SAlex Deucher 126897b2e202SAlex Deucher struct amdgpu_atcs_functions { 126997b2e202SAlex Deucher bool get_ext_state; 127097b2e202SAlex Deucher bool pcie_perf_req; 127197b2e202SAlex Deucher bool pcie_dev_rdy; 127297b2e202SAlex Deucher bool pcie_bus_width; 127397b2e202SAlex Deucher }; 127497b2e202SAlex Deucher 127597b2e202SAlex Deucher struct amdgpu_atcs { 127697b2e202SAlex Deucher struct amdgpu_atcs_functions functions; 127797b2e202SAlex Deucher }; 127897b2e202SAlex Deucher 127997b2e202SAlex Deucher /* 1280d03846afSChunming Zhou * CGS 1281d03846afSChunming Zhou */ 1282110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev); 1283110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device); 1284a8fe58ceSMaruthi Bayyavarapu 1285a8fe58ceSMaruthi Bayyavarapu /* 128697b2e202SAlex Deucher * Core structure, functions and helpers. 128797b2e202SAlex Deucher */ 128897b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t); 128997b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 129097b2e202SAlex Deucher 129197b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 129297b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t); 129397b2e202SAlex Deucher 129497b2e202SAlex Deucher struct amdgpu_device { 129597b2e202SAlex Deucher struct device *dev; 129697b2e202SAlex Deucher struct drm_device *ddev; 129797b2e202SAlex Deucher struct pci_dev *pdev; 129897b2e202SAlex Deucher 1299a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP 1300a8fe58ceSMaruthi Bayyavarapu struct amdgpu_acp acp; 1301a8fe58ceSMaruthi Bayyavarapu #endif 1302a8fe58ceSMaruthi Bayyavarapu 130397b2e202SAlex Deucher /* ASIC */ 13042f7d10b3SJammy Zhou enum amd_asic_type asic_type; 130597b2e202SAlex Deucher uint32_t family; 130697b2e202SAlex Deucher uint32_t rev_id; 130797b2e202SAlex Deucher uint32_t external_rev_id; 130897b2e202SAlex Deucher unsigned long flags; 130997b2e202SAlex Deucher int usec_timeout; 131097b2e202SAlex Deucher const struct amdgpu_asic_funcs *asic_funcs; 131197b2e202SAlex Deucher bool shutdown; 131297b2e202SAlex Deucher bool need_dma32; 131397b2e202SAlex Deucher bool accel_working; 131497b2e202SAlex Deucher struct work_struct reset_work; 131597b2e202SAlex Deucher struct notifier_block acpi_nb; 131697b2e202SAlex Deucher struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS]; 131797b2e202SAlex Deucher struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 131897b2e202SAlex Deucher unsigned debugfs_count; 131997b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS) 1320adcec288STom St Denis struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 132197b2e202SAlex Deucher #endif 132297b2e202SAlex Deucher struct amdgpu_atif atif; 132397b2e202SAlex Deucher struct amdgpu_atcs atcs; 132497b2e202SAlex Deucher struct mutex srbm_mutex; 132597b2e202SAlex Deucher /* GRBM index mutex. Protects concurrent access to GRBM index */ 132697b2e202SAlex Deucher struct mutex grbm_idx_mutex; 132797b2e202SAlex Deucher struct dev_pm_domain vga_pm_domain; 132897b2e202SAlex Deucher bool have_disp_power_ref; 132997b2e202SAlex Deucher 133097b2e202SAlex Deucher /* BIOS */ 133197b2e202SAlex Deucher uint8_t *bios; 133297b2e202SAlex Deucher bool is_atom_bios; 133397b2e202SAlex Deucher struct amdgpu_bo *stollen_vga_memory; 133497b2e202SAlex Deucher uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH]; 133597b2e202SAlex Deucher 133697b2e202SAlex Deucher /* Register/doorbell mmio */ 133797b2e202SAlex Deucher resource_size_t rmmio_base; 133897b2e202SAlex Deucher resource_size_t rmmio_size; 133997b2e202SAlex Deucher void __iomem *rmmio; 134097b2e202SAlex Deucher /* protects concurrent MM_INDEX/DATA based register access */ 134197b2e202SAlex Deucher spinlock_t mmio_idx_lock; 134297b2e202SAlex Deucher /* protects concurrent SMC based register access */ 134397b2e202SAlex Deucher spinlock_t smc_idx_lock; 134497b2e202SAlex Deucher amdgpu_rreg_t smc_rreg; 134597b2e202SAlex Deucher amdgpu_wreg_t smc_wreg; 134697b2e202SAlex Deucher /* protects concurrent PCIE register access */ 134797b2e202SAlex Deucher spinlock_t pcie_idx_lock; 134897b2e202SAlex Deucher amdgpu_rreg_t pcie_rreg; 134997b2e202SAlex Deucher amdgpu_wreg_t pcie_wreg; 135036b9a952SHuang Rui amdgpu_rreg_t pciep_rreg; 135136b9a952SHuang Rui amdgpu_wreg_t pciep_wreg; 135297b2e202SAlex Deucher /* protects concurrent UVD register access */ 135397b2e202SAlex Deucher spinlock_t uvd_ctx_idx_lock; 135497b2e202SAlex Deucher amdgpu_rreg_t uvd_ctx_rreg; 135597b2e202SAlex Deucher amdgpu_wreg_t uvd_ctx_wreg; 135697b2e202SAlex Deucher /* protects concurrent DIDT register access */ 135797b2e202SAlex Deucher spinlock_t didt_idx_lock; 135897b2e202SAlex Deucher amdgpu_rreg_t didt_rreg; 135997b2e202SAlex Deucher amdgpu_wreg_t didt_wreg; 1360ccdbb20aSRex Zhu /* protects concurrent gc_cac register access */ 1361ccdbb20aSRex Zhu spinlock_t gc_cac_idx_lock; 1362ccdbb20aSRex Zhu amdgpu_rreg_t gc_cac_rreg; 1363ccdbb20aSRex Zhu amdgpu_wreg_t gc_cac_wreg; 136497b2e202SAlex Deucher /* protects concurrent ENDPOINT (audio) register access */ 136597b2e202SAlex Deucher spinlock_t audio_endpt_idx_lock; 136697b2e202SAlex Deucher amdgpu_block_rreg_t audio_endpt_rreg; 136797b2e202SAlex Deucher amdgpu_block_wreg_t audio_endpt_wreg; 136897b2e202SAlex Deucher void __iomem *rio_mem; 136997b2e202SAlex Deucher resource_size_t rio_mem_size; 137097b2e202SAlex Deucher struct amdgpu_doorbell doorbell; 137197b2e202SAlex Deucher 137297b2e202SAlex Deucher /* clock/pll info */ 137397b2e202SAlex Deucher struct amdgpu_clock clock; 137497b2e202SAlex Deucher 137597b2e202SAlex Deucher /* MC */ 137697b2e202SAlex Deucher struct amdgpu_mc mc; 137797b2e202SAlex Deucher struct amdgpu_gart gart; 137897b2e202SAlex Deucher struct amdgpu_dummy_page dummy_page; 137997b2e202SAlex Deucher struct amdgpu_vm_manager vm_manager; 138097b2e202SAlex Deucher 138197b2e202SAlex Deucher /* memory management */ 138297b2e202SAlex Deucher struct amdgpu_mman mman; 138397b2e202SAlex Deucher struct amdgpu_vram_scratch vram_scratch; 138497b2e202SAlex Deucher struct amdgpu_wb wb; 138597b2e202SAlex Deucher atomic64_t vram_usage; 138697b2e202SAlex Deucher atomic64_t vram_vis_usage; 138797b2e202SAlex Deucher atomic64_t gtt_usage; 138897b2e202SAlex Deucher atomic64_t num_bytes_moved; 1389dbd5ed60SChristian König atomic64_t num_evictions; 1390d94aed5aSMarek Olšák atomic_t gpu_reset_counter; 139197b2e202SAlex Deucher 139295844d20SMarek Olšák /* data for buffer migration throttling */ 139395844d20SMarek Olšák struct { 139495844d20SMarek Olšák spinlock_t lock; 139595844d20SMarek Olšák s64 last_update_us; 139695844d20SMarek Olšák s64 accum_us; /* accumulated microseconds */ 139795844d20SMarek Olšák u32 log2_max_MBps; 139895844d20SMarek Olšák } mm_stats; 139995844d20SMarek Olšák 140097b2e202SAlex Deucher /* display */ 14019accf2fdSEmily Deng bool enable_virtual_display; 140297b2e202SAlex Deucher struct amdgpu_mode_info mode_info; 140397b2e202SAlex Deucher struct work_struct hotplug_work; 140497b2e202SAlex Deucher struct amdgpu_irq_src crtc_irq; 140597b2e202SAlex Deucher struct amdgpu_irq_src pageflip_irq; 140697b2e202SAlex Deucher struct amdgpu_irq_src hpd_irq; 140797b2e202SAlex Deucher 140897b2e202SAlex Deucher /* rings */ 140976bf0db5SChristian König u64 fence_context; 141097b2e202SAlex Deucher unsigned num_rings; 141197b2e202SAlex Deucher struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; 141297b2e202SAlex Deucher bool ib_pool_ready; 141397b2e202SAlex Deucher struct amdgpu_sa_manager ring_tmp_bo; 141497b2e202SAlex Deucher 141597b2e202SAlex Deucher /* interrupts */ 141697b2e202SAlex Deucher struct amdgpu_irq irq; 141797b2e202SAlex Deucher 14181f7371b2SAlex Deucher /* powerplay */ 14191f7371b2SAlex Deucher struct amd_powerplay powerplay; 1420e61710c5SJammy Zhou bool pp_enabled; 1421f3898ea1SEric Huang bool pp_force_state_enabled; 14221f7371b2SAlex Deucher 142397b2e202SAlex Deucher /* dpm */ 142497b2e202SAlex Deucher struct amdgpu_pm pm; 142597b2e202SAlex Deucher u32 cg_flags; 142697b2e202SAlex Deucher u32 pg_flags; 142797b2e202SAlex Deucher 142897b2e202SAlex Deucher /* amdgpu smumgr */ 142997b2e202SAlex Deucher struct amdgpu_smumgr smu; 143097b2e202SAlex Deucher 143197b2e202SAlex Deucher /* gfx */ 143297b2e202SAlex Deucher struct amdgpu_gfx gfx; 143397b2e202SAlex Deucher 143497b2e202SAlex Deucher /* sdma */ 1435c113ea1cSAlex Deucher struct amdgpu_sdma sdma; 143697b2e202SAlex Deucher 143797b2e202SAlex Deucher /* uvd */ 143897b2e202SAlex Deucher struct amdgpu_uvd uvd; 143997b2e202SAlex Deucher 144097b2e202SAlex Deucher /* vce */ 144197b2e202SAlex Deucher struct amdgpu_vce vce; 144297b2e202SAlex Deucher 144397b2e202SAlex Deucher /* firmwares */ 144497b2e202SAlex Deucher struct amdgpu_firmware firmware; 144597b2e202SAlex Deucher 144697b2e202SAlex Deucher /* GDS */ 144797b2e202SAlex Deucher struct amdgpu_gds gds; 144897b2e202SAlex Deucher 1449a1255107SAlex Deucher struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM]; 145097b2e202SAlex Deucher int num_ip_blocks; 145197b2e202SAlex Deucher struct mutex mn_lock; 145297b2e202SAlex Deucher DECLARE_HASHTABLE(mn_hash, 7); 145397b2e202SAlex Deucher 145497b2e202SAlex Deucher /* tracking pinned memory */ 145597b2e202SAlex Deucher u64 vram_pin_size; 1456e131b914SChunming Zhou u64 invisible_pin_size; 145797b2e202SAlex Deucher u64 gart_pin_size; 1458130e0371SOded Gabbay 1459130e0371SOded Gabbay /* amdkfd interface */ 1460130e0371SOded Gabbay struct kfd_dev *kfd; 146123ca0e4eSChunming Zhou 14627e471e6fSAlex Deucher struct amdgpu_virtualization virtualization; 14630c4e7fa5SChunming Zhou 14640c4e7fa5SChunming Zhou /* link all shadow bo */ 14650c4e7fa5SChunming Zhou struct list_head shadow_list; 14660c4e7fa5SChunming Zhou struct mutex shadow_list_lock; 14675c1354bdSChunming Zhou /* link all gtt */ 14685c1354bdSChunming Zhou spinlock_t gtt_list_lock; 14695c1354bdSChunming Zhou struct list_head gtt_list; 14705c1354bdSChunming Zhou 147197b2e202SAlex Deucher }; 147297b2e202SAlex Deucher 1473a7d64de6SChristian König static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev) 1474a7d64de6SChristian König { 1475a7d64de6SChristian König return container_of(bdev, struct amdgpu_device, mman.bdev); 1476a7d64de6SChristian König } 1477a7d64de6SChristian König 147897b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev); 147997b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev, 148097b2e202SAlex Deucher struct drm_device *ddev, 148197b2e202SAlex Deucher struct pci_dev *pdev, 148297b2e202SAlex Deucher uint32_t flags); 148397b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev); 148497b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); 148597b2e202SAlex Deucher 148697b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, 148797b2e202SAlex Deucher bool always_indirect); 148897b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, 148997b2e202SAlex Deucher bool always_indirect); 149097b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg); 149197b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v); 149297b2e202SAlex Deucher 149397b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index); 149497b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v); 149597b2e202SAlex Deucher 149697b2e202SAlex Deucher /* 149797b2e202SAlex Deucher * Registers read & write functions. 149897b2e202SAlex Deucher */ 149997b2e202SAlex Deucher #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false) 150097b2e202SAlex Deucher #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true) 150197b2e202SAlex Deucher #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false)) 150297b2e202SAlex Deucher #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false) 150397b2e202SAlex Deucher #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true) 150497b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 150597b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 150697b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg)) 150797b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v)) 150836b9a952SHuang Rui #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg)) 150936b9a952SHuang Rui #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v)) 151097b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg)) 151197b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v)) 151297b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg)) 151397b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v)) 151497b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg)) 151597b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v)) 1516ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg)) 1517ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v)) 151897b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg)) 151997b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v)) 152097b2e202SAlex Deucher #define WREG32_P(reg, val, mask) \ 152197b2e202SAlex Deucher do { \ 152297b2e202SAlex Deucher uint32_t tmp_ = RREG32(reg); \ 152397b2e202SAlex Deucher tmp_ &= (mask); \ 152497b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 152597b2e202SAlex Deucher WREG32(reg, tmp_); \ 152697b2e202SAlex Deucher } while (0) 152797b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and) 152897b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or)) 152997b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask) \ 153097b2e202SAlex Deucher do { \ 153197b2e202SAlex Deucher uint32_t tmp_ = RREG32_PLL(reg); \ 153297b2e202SAlex Deucher tmp_ &= (mask); \ 153397b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 153497b2e202SAlex Deucher WREG32_PLL(reg, tmp_); \ 153597b2e202SAlex Deucher } while (0) 153697b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false)) 153797b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg)) 153897b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v)) 153997b2e202SAlex Deucher 154097b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index)) 154197b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v)) 154297b2e202SAlex Deucher 154397b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT 154497b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK 154597b2e202SAlex Deucher 154697b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val) \ 154797b2e202SAlex Deucher (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \ 154897b2e202SAlex Deucher (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) 154997b2e202SAlex Deucher 155097b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field) \ 155197b2e202SAlex Deucher (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field)) 155297b2e202SAlex Deucher 155361cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val) \ 155461cb8cefSTom St Denis WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 155561cb8cefSTom St Denis 155697b2e202SAlex Deucher /* 155797b2e202SAlex Deucher * BIOS helpers. 155897b2e202SAlex Deucher */ 155997b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i]) 156097b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8)) 156197b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16)) 156297b2e202SAlex Deucher 156397b2e202SAlex Deucher /* 156497b2e202SAlex Deucher * RING helpers. 156597b2e202SAlex Deucher */ 156697b2e202SAlex Deucher static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v) 156797b2e202SAlex Deucher { 156897b2e202SAlex Deucher if (ring->count_dw <= 0) 156986c2b790SJammy Zhou DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n"); 157097b2e202SAlex Deucher ring->ring[ring->wptr++] = v; 157197b2e202SAlex Deucher ring->wptr &= ring->ptr_mask; 157297b2e202SAlex Deucher ring->count_dw--; 157397b2e202SAlex Deucher } 157497b2e202SAlex Deucher 1575c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance * 1576c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring) 15774b2f7e2cSJammy Zhou { 15784b2f7e2cSJammy Zhou struct amdgpu_device *adev = ring->adev; 15794b2f7e2cSJammy Zhou int i; 15804b2f7e2cSJammy Zhou 1581c113ea1cSAlex Deucher for (i = 0; i < adev->sdma.num_instances; i++) 1582c113ea1cSAlex Deucher if (&adev->sdma.instance[i].ring == ring) 15834b2f7e2cSJammy Zhou break; 15844b2f7e2cSJammy Zhou 15854b2f7e2cSJammy Zhou if (i < AMDGPU_MAX_SDMA_INSTANCES) 1586c113ea1cSAlex Deucher return &adev->sdma.instance[i]; 15874b2f7e2cSJammy Zhou else 15884b2f7e2cSJammy Zhou return NULL; 15894b2f7e2cSJammy Zhou } 15904b2f7e2cSJammy Zhou 159197b2e202SAlex Deucher /* 159297b2e202SAlex Deucher * ASICs macro. 159397b2e202SAlex Deucher */ 159497b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state)) 159597b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev)) 159697b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev)) 159797b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d)) 159897b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec)) 1599841686dfSMaruthi Bayyavarapu #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev)) 1600841686dfSMaruthi Bayyavarapu #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l)) 1601841686dfSMaruthi Bayyavarapu #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev)) 160297b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev)) 16037946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l)) 16044e99a44eSMonk Liu #define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev)) 160597b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v))) 160697b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid)) 160797b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags)) 160897b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count))) 1609de9ea7bdSChristian 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))) 161097b2e202SAlex 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))) 161197b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib))) 161297b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r)) 1613bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t)) 161497b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r)) 161597b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r)) 161697b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r)) 1617d88bf583SChristian König #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c)) 1618b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r)) 161997b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr)) 1620890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags)) 162197b2e202SAlex 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)) 1622d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r)) 162311afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r)) 1624c2167a65SMonk Liu #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r)) 1625753ad49cSMonk Liu #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d)) 16269e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib))) 162703ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r)) 162803ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o)) 162997b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev)) 163097b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv)) 163197b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev)) 163297b2e202SAlex Deucher #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r)) 163397b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc)) 163497b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc)) 163597b2e202SAlex Deucher #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev)) 163697b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l)) 163797b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e)) 163897b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h)) 163997b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h)) 164097b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev)) 164197b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev)) 1642cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async)) 164397b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos)) 164497b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c)) 164597b2e202SAlex 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)) 164697b2e202SAlex Deucher #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s)) 164797b2e202SAlex Deucher #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s)) 1648c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b)) 16496e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) 1650b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev)) 16519559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance)) 165297b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a)) 165397b2e202SAlex Deucher 165497b2e202SAlex Deucher /* Common functions */ 165597b2e202SAlex Deucher int amdgpu_gpu_reset(struct amdgpu_device *adev); 16563ad81f16SChunming Zhou bool amdgpu_need_backup(struct amdgpu_device *adev); 165797b2e202SAlex Deucher void amdgpu_pci_config_reset(struct amdgpu_device *adev); 165897b2e202SAlex Deucher bool amdgpu_card_posted(struct amdgpu_device *adev); 165997b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev); 1660d5fc5e82SChunming Zhou 166197b2e202SAlex Deucher int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data); 166297b2e202SAlex Deucher int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type, 166397b2e202SAlex Deucher u32 ip_instance, u32 ring, 166497b2e202SAlex Deucher struct amdgpu_ring **out_ring); 1665765e7fbfSChristian König void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain); 166697b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo); 16672f568dbdSChristian König int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages); 166897b2e202SAlex Deucher int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, 166997b2e202SAlex Deucher uint32_t flags); 167097b2e202SAlex Deucher bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm); 1671cc325d19SChristian König struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm); 1672d7006964SChristian König bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start, 1673d7006964SChristian König unsigned long end); 16742f568dbdSChristian König bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm, 16752f568dbdSChristian König int *last_invalidated); 167697b2e202SAlex Deucher bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm); 167797b2e202SAlex Deucher uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, 167897b2e202SAlex Deucher struct ttm_mem_reg *mem); 167997b2e202SAlex Deucher void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base); 168097b2e202SAlex Deucher void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc); 168197b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size); 1682a693e050SKen Wang u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev); 1683a693e050SKen Wang int amdgpu_ttm_global_init(struct amdgpu_device *adev); 16849f31a0b0SBaoyou Xie int amdgpu_ttm_init(struct amdgpu_device *adev); 16859f31a0b0SBaoyou Xie void amdgpu_ttm_fini(struct amdgpu_device *adev); 168697b2e202SAlex Deucher void amdgpu_program_register_sequence(struct amdgpu_device *adev, 168797b2e202SAlex Deucher const u32 *registers, 168897b2e202SAlex Deucher const u32 array_size); 168997b2e202SAlex Deucher 169097b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev); 169197b2e202SAlex Deucher /* atpx handler */ 169297b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO) 169397b2e202SAlex Deucher void amdgpu_register_atpx_handler(void); 169497b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void); 1695a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void); 16962f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void); 1697efc83cf4SAlex Deucher bool amdgpu_atpx_dgpu_req_power_for_displays(void); 169897b2e202SAlex Deucher #else 169997b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {} 170097b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {} 1701a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; } 17022f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; } 1703efc83cf4SAlex Deucher static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; } 170497b2e202SAlex Deucher #endif 170597b2e202SAlex Deucher 170697b2e202SAlex Deucher /* 170797b2e202SAlex Deucher * KMS 170897b2e202SAlex Deucher */ 170997b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[]; 1710f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl; 171197b2e202SAlex Deucher 171297b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags); 171397b2e202SAlex Deucher int amdgpu_driver_unload_kms(struct drm_device *dev); 171497b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev); 171597b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv); 171697b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev, 171797b2e202SAlex Deucher struct drm_file *file_priv); 171897b2e202SAlex Deucher void amdgpu_driver_preclose_kms(struct drm_device *dev, 171997b2e202SAlex Deucher struct drm_file *file_priv); 1720810ddc3aSAlex Deucher int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon); 1721810ddc3aSAlex Deucher int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon); 172288e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe); 172388e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe); 172488e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe); 172588e72717SThierry Reding int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, 172697b2e202SAlex Deucher int *max_error, 172797b2e202SAlex Deucher struct timeval *vblank_time, 172897b2e202SAlex Deucher unsigned flags); 172997b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd, 173097b2e202SAlex Deucher unsigned long arg); 173197b2e202SAlex Deucher 173297b2e202SAlex Deucher /* 173397b2e202SAlex Deucher * functions used by amdgpu_encoder.c 173497b2e202SAlex Deucher */ 173597b2e202SAlex Deucher struct amdgpu_afmt_acr { 173697b2e202SAlex Deucher u32 clock; 173797b2e202SAlex Deucher 173897b2e202SAlex Deucher int n_32khz; 173997b2e202SAlex Deucher int cts_32khz; 174097b2e202SAlex Deucher 174197b2e202SAlex Deucher int n_44_1khz; 174297b2e202SAlex Deucher int cts_44_1khz; 174397b2e202SAlex Deucher 174497b2e202SAlex Deucher int n_48khz; 174597b2e202SAlex Deucher int cts_48khz; 174697b2e202SAlex Deucher 174797b2e202SAlex Deucher }; 174897b2e202SAlex Deucher 174997b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock); 175097b2e202SAlex Deucher 175197b2e202SAlex Deucher /* amdgpu_acpi.c */ 175297b2e202SAlex Deucher #if defined(CONFIG_ACPI) 175397b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev); 175497b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev); 175597b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev); 175697b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev, 175797b2e202SAlex Deucher u8 perf_req, bool advertise); 175897b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev); 175997b2e202SAlex Deucher #else 176097b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; } 176197b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { } 176297b2e202SAlex Deucher #endif 176397b2e202SAlex Deucher 176497b2e202SAlex Deucher struct amdgpu_bo_va_mapping * 176597b2e202SAlex Deucher amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser, 176697b2e202SAlex Deucher uint64_t addr, struct amdgpu_bo **bo); 1767c855e250SChristian König int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser); 176897b2e202SAlex Deucher 176997b2e202SAlex Deucher #include "amdgpu_object.h" 177097b2e202SAlex Deucher #endif 1771