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> 3797b2e202SAlex Deucher #include <linux/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" 5497b2e202SAlex Deucher #include "amdgpu_gds.h" 551f7371b2SAlex Deucher #include "amd_powerplay.h" 56a8fe58ceSMaruthi Bayyavarapu #include "amdgpu_acp.h" 5797b2e202SAlex Deucher 58b80d8475SAlex Deucher #include "gpu_scheduler.h" 59b80d8475SAlex Deucher 6097b2e202SAlex Deucher /* 6197b2e202SAlex Deucher * Modules parameters. 6297b2e202SAlex Deucher */ 6397b2e202SAlex Deucher extern int amdgpu_modeset; 6497b2e202SAlex Deucher extern int amdgpu_vram_limit; 6597b2e202SAlex Deucher extern int amdgpu_gart_size; 6697b2e202SAlex Deucher extern int amdgpu_benchmarking; 6797b2e202SAlex Deucher extern int amdgpu_testing; 6897b2e202SAlex Deucher extern int amdgpu_audio; 6997b2e202SAlex Deucher extern int amdgpu_disp_priority; 7097b2e202SAlex Deucher extern int amdgpu_hw_i2c; 7197b2e202SAlex Deucher extern int amdgpu_pcie_gen2; 7297b2e202SAlex Deucher extern int amdgpu_msi; 7397b2e202SAlex Deucher extern int amdgpu_lockup_timeout; 7497b2e202SAlex Deucher extern int amdgpu_dpm; 7597b2e202SAlex Deucher extern int amdgpu_smc_load_fw; 7697b2e202SAlex Deucher extern int amdgpu_aspm; 7797b2e202SAlex Deucher extern int amdgpu_runtime_pm; 7897b2e202SAlex Deucher extern unsigned amdgpu_ip_block_mask; 7997b2e202SAlex Deucher extern int amdgpu_bapm; 8097b2e202SAlex Deucher extern int amdgpu_deep_color; 8197b2e202SAlex Deucher extern int amdgpu_vm_size; 8297b2e202SAlex Deucher extern int amdgpu_vm_block_size; 83d9c13156SChristian König extern int amdgpu_vm_fault_stop; 84b495bd3aSChristian König extern int amdgpu_vm_debug; 851333f723SJammy Zhou extern int amdgpu_sched_jobs; 864afcb303SJammy Zhou extern int amdgpu_sched_hw_submission; 871f7371b2SAlex Deucher extern int amdgpu_powerplay; 886bb6b297SHuang Rui extern int amdgpu_powercontainment; 89cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_gen_cap; 90cd474ba0SAlex Deucher extern unsigned amdgpu_pcie_lane_cap; 91395d1fb9SNicolai Hähnle extern unsigned amdgpu_cg_mask; 92395d1fb9SNicolai Hähnle extern unsigned amdgpu_pg_mask; 936f8941a2SNicolai Hähnle extern char *amdgpu_disable_cu; 9466bc3f7fSRex Zhu extern int amdgpu_sclk_deep_sleep_en; 959accf2fdSEmily Deng extern char *amdgpu_virtual_display; 9697b2e202SAlex Deucher 974b559c90SChunming Zhou #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000 9897b2e202SAlex Deucher #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 9997b2e202SAlex Deucher #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) 10097b2e202SAlex Deucher /* AMDGPU_IB_POOL_SIZE must be a power of 2 */ 10197b2e202SAlex Deucher #define AMDGPU_IB_POOL_SIZE 16 10297b2e202SAlex Deucher #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32 10397b2e202SAlex Deucher #define AMDGPUFB_CONN_LIMIT 4 10497b2e202SAlex Deucher #define AMDGPU_BIOS_NUM_SCRATCH 8 10597b2e202SAlex Deucher 10697b2e202SAlex Deucher /* max number of rings */ 10797b2e202SAlex Deucher #define AMDGPU_MAX_RINGS 16 10897b2e202SAlex Deucher #define AMDGPU_MAX_GFX_RINGS 1 10997b2e202SAlex Deucher #define AMDGPU_MAX_COMPUTE_RINGS 8 11097b2e202SAlex Deucher #define AMDGPU_MAX_VCE_RINGS 2 11197b2e202SAlex Deucher 11236f523a7SJammy Zhou /* max number of IP instances */ 11336f523a7SJammy Zhou #define AMDGPU_MAX_SDMA_INSTANCES 2 11436f523a7SJammy Zhou 11597b2e202SAlex Deucher /* hardcode that limit for now */ 11697b2e202SAlex Deucher #define AMDGPU_VA_RESERVED_SIZE (8 << 20) 11797b2e202SAlex Deucher 11897b2e202SAlex Deucher /* hard reset data */ 11997b2e202SAlex Deucher #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b 12097b2e202SAlex Deucher 12197b2e202SAlex Deucher /* reset flags */ 12297b2e202SAlex Deucher #define AMDGPU_RESET_GFX (1 << 0) 12397b2e202SAlex Deucher #define AMDGPU_RESET_COMPUTE (1 << 1) 12497b2e202SAlex Deucher #define AMDGPU_RESET_DMA (1 << 2) 12597b2e202SAlex Deucher #define AMDGPU_RESET_CP (1 << 3) 12697b2e202SAlex Deucher #define AMDGPU_RESET_GRBM (1 << 4) 12797b2e202SAlex Deucher #define AMDGPU_RESET_DMA1 (1 << 5) 12897b2e202SAlex Deucher #define AMDGPU_RESET_RLC (1 << 6) 12997b2e202SAlex Deucher #define AMDGPU_RESET_SEM (1 << 7) 13097b2e202SAlex Deucher #define AMDGPU_RESET_IH (1 << 8) 13197b2e202SAlex Deucher #define AMDGPU_RESET_VMC (1 << 9) 13297b2e202SAlex Deucher #define AMDGPU_RESET_MC (1 << 10) 13397b2e202SAlex Deucher #define AMDGPU_RESET_DISPLAY (1 << 11) 13497b2e202SAlex Deucher #define AMDGPU_RESET_UVD (1 << 12) 13597b2e202SAlex Deucher #define AMDGPU_RESET_VCE (1 << 13) 13697b2e202SAlex Deucher #define AMDGPU_RESET_VCE1 (1 << 14) 13797b2e202SAlex Deucher 13897b2e202SAlex Deucher /* GFX current status */ 13997b2e202SAlex Deucher #define AMDGPU_GFX_NORMAL_MODE 0x00000000L 14097b2e202SAlex Deucher #define AMDGPU_GFX_SAFE_MODE 0x00000001L 14197b2e202SAlex Deucher #define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L 14297b2e202SAlex Deucher #define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L 14397b2e202SAlex Deucher #define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L 14497b2e202SAlex Deucher 14597b2e202SAlex Deucher /* max cursor sizes (in pixels) */ 14697b2e202SAlex Deucher #define CIK_CURSOR_WIDTH 128 14797b2e202SAlex Deucher #define CIK_CURSOR_HEIGHT 128 14897b2e202SAlex Deucher 14997b2e202SAlex Deucher struct amdgpu_device; 15097b2e202SAlex Deucher struct amdgpu_ib; 15197b2e202SAlex Deucher struct amdgpu_vm; 15297b2e202SAlex Deucher struct amdgpu_ring; 15397b2e202SAlex Deucher struct amdgpu_cs_parser; 154bb977d37SChunming Zhou struct amdgpu_job; 15597b2e202SAlex Deucher struct amdgpu_irq_src; 1560b492a4cSAlex Deucher struct amdgpu_fpriv; 15797b2e202SAlex Deucher 15897b2e202SAlex Deucher enum amdgpu_cp_irq { 15997b2e202SAlex Deucher AMDGPU_CP_IRQ_GFX_EOP = 0, 16097b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP, 16197b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP, 16297b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP, 16397b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP, 16497b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP, 16597b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP, 16697b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP, 16797b2e202SAlex Deucher AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP, 16897b2e202SAlex Deucher 16997b2e202SAlex Deucher AMDGPU_CP_IRQ_LAST 17097b2e202SAlex Deucher }; 17197b2e202SAlex Deucher 17297b2e202SAlex Deucher enum amdgpu_sdma_irq { 17397b2e202SAlex Deucher AMDGPU_SDMA_IRQ_TRAP0 = 0, 17497b2e202SAlex Deucher AMDGPU_SDMA_IRQ_TRAP1, 17597b2e202SAlex Deucher 17697b2e202SAlex Deucher AMDGPU_SDMA_IRQ_LAST 17797b2e202SAlex Deucher }; 17897b2e202SAlex Deucher 17997b2e202SAlex Deucher enum amdgpu_thermal_irq { 18097b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0, 18197b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_HIGH_TO_LOW, 18297b2e202SAlex Deucher 18397b2e202SAlex Deucher AMDGPU_THERMAL_IRQ_LAST 18497b2e202SAlex Deucher }; 18597b2e202SAlex Deucher 18697b2e202SAlex Deucher int amdgpu_set_clockgating_state(struct amdgpu_device *adev, 1875fc3aeebSyanyang1 enum amd_ip_block_type block_type, 1885fc3aeebSyanyang1 enum amd_clockgating_state state); 18997b2e202SAlex Deucher int amdgpu_set_powergating_state(struct amdgpu_device *adev, 1905fc3aeebSyanyang1 enum amd_ip_block_type block_type, 1915fc3aeebSyanyang1 enum amd_powergating_state state); 1925dbbb60bSAlex Deucher int amdgpu_wait_for_idle(struct amdgpu_device *adev, 1935dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 1945dbbb60bSAlex Deucher bool amdgpu_is_idle(struct amdgpu_device *adev, 1955dbbb60bSAlex Deucher enum amd_ip_block_type block_type); 19697b2e202SAlex Deucher 19797b2e202SAlex Deucher struct amdgpu_ip_block_version { 1985fc3aeebSyanyang1 enum amd_ip_block_type type; 19997b2e202SAlex Deucher u32 major; 20097b2e202SAlex Deucher u32 minor; 20197b2e202SAlex Deucher u32 rev; 2025fc3aeebSyanyang1 const struct amd_ip_funcs *funcs; 20397b2e202SAlex Deucher }; 20497b2e202SAlex Deucher 20597b2e202SAlex Deucher int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev, 2065fc3aeebSyanyang1 enum amd_ip_block_type type, 20797b2e202SAlex Deucher u32 major, u32 minor); 20897b2e202SAlex Deucher 20997b2e202SAlex Deucher const struct amdgpu_ip_block_version * amdgpu_get_ip_block( 21097b2e202SAlex Deucher struct amdgpu_device *adev, 2115fc3aeebSyanyang1 enum amd_ip_block_type type); 21297b2e202SAlex Deucher 21397b2e202SAlex Deucher /* provided by hw blocks that can move/clear data. e.g., gfx or sdma */ 21497b2e202SAlex Deucher struct amdgpu_buffer_funcs { 21597b2e202SAlex Deucher /* maximum bytes in a single operation */ 21697b2e202SAlex Deucher uint32_t copy_max_bytes; 21797b2e202SAlex Deucher 21897b2e202SAlex Deucher /* number of dw to reserve per operation */ 21997b2e202SAlex Deucher unsigned copy_num_dw; 22097b2e202SAlex Deucher 22197b2e202SAlex Deucher /* used for buffer migration */ 222c7ae72c0SChunming Zhou void (*emit_copy_buffer)(struct amdgpu_ib *ib, 22397b2e202SAlex Deucher /* src addr in bytes */ 22497b2e202SAlex Deucher uint64_t src_offset, 22597b2e202SAlex Deucher /* dst addr in bytes */ 22697b2e202SAlex Deucher uint64_t dst_offset, 22797b2e202SAlex Deucher /* number of byte to transfer */ 22897b2e202SAlex Deucher uint32_t byte_count); 22997b2e202SAlex Deucher 23097b2e202SAlex Deucher /* maximum bytes in a single operation */ 23197b2e202SAlex Deucher uint32_t fill_max_bytes; 23297b2e202SAlex Deucher 23397b2e202SAlex Deucher /* number of dw to reserve per operation */ 23497b2e202SAlex Deucher unsigned fill_num_dw; 23597b2e202SAlex Deucher 23697b2e202SAlex Deucher /* used for buffer clearing */ 2376e7a3840SChunming Zhou void (*emit_fill_buffer)(struct amdgpu_ib *ib, 23897b2e202SAlex Deucher /* value to write to memory */ 23997b2e202SAlex Deucher uint32_t src_data, 24097b2e202SAlex Deucher /* dst addr in bytes */ 24197b2e202SAlex Deucher uint64_t dst_offset, 24297b2e202SAlex Deucher /* number of byte to fill */ 24397b2e202SAlex Deucher uint32_t byte_count); 24497b2e202SAlex Deucher }; 24597b2e202SAlex Deucher 24697b2e202SAlex Deucher /* provided by hw blocks that can write ptes, e.g., sdma */ 24797b2e202SAlex Deucher struct amdgpu_vm_pte_funcs { 24897b2e202SAlex Deucher /* copy pte entries from GART */ 24997b2e202SAlex Deucher void (*copy_pte)(struct amdgpu_ib *ib, 25097b2e202SAlex Deucher uint64_t pe, uint64_t src, 25197b2e202SAlex Deucher unsigned count); 25297b2e202SAlex Deucher /* write pte one entry at a time with addr mapping */ 25397b2e202SAlex Deucher void (*write_pte)(struct amdgpu_ib *ib, 254b07c9d2aSChristian König const dma_addr_t *pages_addr, uint64_t pe, 25597b2e202SAlex Deucher uint64_t addr, unsigned count, 25697b2e202SAlex Deucher uint32_t incr, uint32_t flags); 25797b2e202SAlex Deucher /* for linear pte/pde updates without addr mapping */ 25897b2e202SAlex Deucher void (*set_pte_pde)(struct amdgpu_ib *ib, 25997b2e202SAlex Deucher uint64_t pe, 26097b2e202SAlex Deucher uint64_t addr, unsigned count, 26197b2e202SAlex Deucher uint32_t incr, uint32_t flags); 26297b2e202SAlex Deucher }; 26397b2e202SAlex Deucher 26497b2e202SAlex Deucher /* provided by the gmc block */ 26597b2e202SAlex Deucher struct amdgpu_gart_funcs { 26697b2e202SAlex Deucher /* flush the vm tlb via mmio */ 26797b2e202SAlex Deucher void (*flush_gpu_tlb)(struct amdgpu_device *adev, 26897b2e202SAlex Deucher uint32_t vmid); 26997b2e202SAlex Deucher /* write pte/pde updates using the cpu */ 27097b2e202SAlex Deucher int (*set_pte_pde)(struct amdgpu_device *adev, 27197b2e202SAlex Deucher void *cpu_pt_addr, /* cpu addr of page table */ 27297b2e202SAlex Deucher uint32_t gpu_page_idx, /* pte/pde to update */ 27397b2e202SAlex Deucher uint64_t addr, /* addr to write into pte/pde */ 27497b2e202SAlex Deucher uint32_t flags); /* access flags */ 27597b2e202SAlex Deucher }; 27697b2e202SAlex Deucher 27797b2e202SAlex Deucher /* provided by the ih block */ 27897b2e202SAlex Deucher struct amdgpu_ih_funcs { 27997b2e202SAlex Deucher /* ring read/write ptr handling, called from interrupt context */ 28097b2e202SAlex Deucher u32 (*get_wptr)(struct amdgpu_device *adev); 28197b2e202SAlex Deucher void (*decode_iv)(struct amdgpu_device *adev, 28297b2e202SAlex Deucher struct amdgpu_iv_entry *entry); 28397b2e202SAlex Deucher void (*set_rptr)(struct amdgpu_device *adev); 28497b2e202SAlex Deucher }; 28597b2e202SAlex Deucher 28697b2e202SAlex Deucher /* provided by hw blocks that expose a ring buffer for commands */ 28797b2e202SAlex Deucher struct amdgpu_ring_funcs { 28897b2e202SAlex Deucher /* ring read/write ptr handling */ 28997b2e202SAlex Deucher u32 (*get_rptr)(struct amdgpu_ring *ring); 29097b2e202SAlex Deucher u32 (*get_wptr)(struct amdgpu_ring *ring); 29197b2e202SAlex Deucher void (*set_wptr)(struct amdgpu_ring *ring); 29297b2e202SAlex Deucher /* validating and patching of IBs */ 29397b2e202SAlex Deucher int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx); 29497b2e202SAlex Deucher /* command emit functions */ 29597b2e202SAlex Deucher void (*emit_ib)(struct amdgpu_ring *ring, 296d88bf583SChristian König struct amdgpu_ib *ib, 297d88bf583SChristian König unsigned vm_id, bool ctx_switch); 29897b2e202SAlex Deucher void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr, 299890ee23fSChunming Zhou uint64_t seq, unsigned flags); 300b8c7b39eSChristian König void (*emit_pipeline_sync)(struct amdgpu_ring *ring); 30197b2e202SAlex Deucher void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id, 30297b2e202SAlex Deucher uint64_t pd_addr); 303d2edb07bSChristian König void (*emit_hdp_flush)(struct amdgpu_ring *ring); 30411afbde8SChunming Zhou void (*emit_hdp_invalidate)(struct amdgpu_ring *ring); 30597b2e202SAlex Deucher void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid, 30697b2e202SAlex Deucher uint32_t gds_base, uint32_t gds_size, 30797b2e202SAlex Deucher uint32_t gws_base, uint32_t gws_size, 30897b2e202SAlex Deucher uint32_t oa_base, uint32_t oa_size); 30997b2e202SAlex Deucher /* testing functions */ 31097b2e202SAlex Deucher int (*test_ring)(struct amdgpu_ring *ring); 311bbec97aaSChristian König int (*test_ib)(struct amdgpu_ring *ring, long timeout); 312edff0e28SJammy Zhou /* insert NOP packets */ 313edff0e28SJammy Zhou void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count); 3149e5d5309SChristian König /* pad the indirect buffer to the necessary number of dw */ 3159e5d5309SChristian König void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib); 31603ccf481SMonk Liu unsigned (*init_cond_exec)(struct amdgpu_ring *ring); 31703ccf481SMonk Liu void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset); 318f06505b8SChristian König /* note usage for clock and power gating */ 319f06505b8SChristian König void (*begin_use)(struct amdgpu_ring *ring); 320f06505b8SChristian König void (*end_use)(struct amdgpu_ring *ring); 32197b2e202SAlex Deucher }; 32297b2e202SAlex Deucher 32397b2e202SAlex Deucher /* 32497b2e202SAlex Deucher * BIOS. 32597b2e202SAlex Deucher */ 32697b2e202SAlex Deucher bool amdgpu_get_bios(struct amdgpu_device *adev); 32797b2e202SAlex Deucher bool amdgpu_read_bios(struct amdgpu_device *adev); 32897b2e202SAlex Deucher 32997b2e202SAlex Deucher /* 33097b2e202SAlex Deucher * Dummy page 33197b2e202SAlex Deucher */ 33297b2e202SAlex Deucher struct amdgpu_dummy_page { 33397b2e202SAlex Deucher struct page *page; 33497b2e202SAlex Deucher dma_addr_t addr; 33597b2e202SAlex Deucher }; 33697b2e202SAlex Deucher int amdgpu_dummy_page_init(struct amdgpu_device *adev); 33797b2e202SAlex Deucher void amdgpu_dummy_page_fini(struct amdgpu_device *adev); 33897b2e202SAlex Deucher 33997b2e202SAlex Deucher 34097b2e202SAlex Deucher /* 34197b2e202SAlex Deucher * Clocks 34297b2e202SAlex Deucher */ 34397b2e202SAlex Deucher 34497b2e202SAlex Deucher #define AMDGPU_MAX_PPLL 3 34597b2e202SAlex Deucher 34697b2e202SAlex Deucher struct amdgpu_clock { 34797b2e202SAlex Deucher struct amdgpu_pll ppll[AMDGPU_MAX_PPLL]; 34897b2e202SAlex Deucher struct amdgpu_pll spll; 34997b2e202SAlex Deucher struct amdgpu_pll mpll; 35097b2e202SAlex Deucher /* 10 Khz units */ 35197b2e202SAlex Deucher uint32_t default_mclk; 35297b2e202SAlex Deucher uint32_t default_sclk; 35397b2e202SAlex Deucher uint32_t default_dispclk; 35497b2e202SAlex Deucher uint32_t current_dispclk; 35597b2e202SAlex Deucher uint32_t dp_extclk; 35697b2e202SAlex Deucher uint32_t max_pixel_clock; 35797b2e202SAlex Deucher }; 35897b2e202SAlex Deucher 35997b2e202SAlex Deucher /* 36097b2e202SAlex Deucher * Fences. 36197b2e202SAlex Deucher */ 36297b2e202SAlex Deucher struct amdgpu_fence_driver { 36397b2e202SAlex Deucher uint64_t gpu_addr; 36497b2e202SAlex Deucher volatile uint32_t *cpu_addr; 36597b2e202SAlex Deucher /* sync_seq is protected by ring emission lock */ 366742c085fSChristian König uint32_t sync_seq; 367742c085fSChristian König atomic_t last_seq; 36897b2e202SAlex Deucher bool initialized; 36997b2e202SAlex Deucher struct amdgpu_irq_src *irq_src; 37097b2e202SAlex Deucher unsigned irq_type; 371c2776afeSChristian König struct timer_list fallback_timer; 372c89377d1SChristian König unsigned num_fences_mask; 3734a7d74f1SChristian König spinlock_t lock; 374c89377d1SChristian König struct fence **fences; 37597b2e202SAlex Deucher }; 37697b2e202SAlex Deucher 37797b2e202SAlex Deucher /* some special values for the owner field */ 37897b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul) 37997b2e202SAlex Deucher #define AMDGPU_FENCE_OWNER_VM ((void*)1ul) 38097b2e202SAlex Deucher 381890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_64BIT (1 << 0) 382890ee23fSChunming Zhou #define AMDGPU_FENCE_FLAG_INT (1 << 1) 383890ee23fSChunming Zhou 38497b2e202SAlex Deucher int amdgpu_fence_driver_init(struct amdgpu_device *adev); 38597b2e202SAlex Deucher void amdgpu_fence_driver_fini(struct amdgpu_device *adev); 38697b2e202SAlex Deucher void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev); 38797b2e202SAlex Deucher 388e6151a08SChristian König int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, 389e6151a08SChristian König unsigned num_hw_submission); 39097b2e202SAlex Deucher int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, 39197b2e202SAlex Deucher struct amdgpu_irq_src *irq_src, 39297b2e202SAlex Deucher unsigned irq_type); 3935ceb54c6SAlex Deucher void amdgpu_fence_driver_suspend(struct amdgpu_device *adev); 3945ceb54c6SAlex Deucher void amdgpu_fence_driver_resume(struct amdgpu_device *adev); 395364beb2cSChristian König int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence); 39697b2e202SAlex Deucher void amdgpu_fence_process(struct amdgpu_ring *ring); 39797b2e202SAlex Deucher int amdgpu_fence_wait_empty(struct amdgpu_ring *ring); 39897b2e202SAlex Deucher unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring); 39997b2e202SAlex Deucher 40097b2e202SAlex Deucher /* 40197b2e202SAlex Deucher * TTM. 40297b2e202SAlex Deucher */ 40329b3259aSChristian König 40429b3259aSChristian König #define AMDGPU_TTM_LRU_SIZE 20 40529b3259aSChristian König 40629b3259aSChristian König struct amdgpu_mman_lru { 40729b3259aSChristian König struct list_head *lru[TTM_NUM_MEM_TYPES]; 40829b3259aSChristian König struct list_head *swap_lru; 40929b3259aSChristian König }; 41029b3259aSChristian König 41197b2e202SAlex Deucher struct amdgpu_mman { 41297b2e202SAlex Deucher struct ttm_bo_global_ref bo_global_ref; 41397b2e202SAlex Deucher struct drm_global_reference mem_global_ref; 41497b2e202SAlex Deucher struct ttm_bo_device bdev; 41597b2e202SAlex Deucher bool mem_global_referenced; 41697b2e202SAlex Deucher bool initialized; 41797b2e202SAlex Deucher 41897b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS) 41997b2e202SAlex Deucher struct dentry *vram; 42097b2e202SAlex Deucher struct dentry *gtt; 42197b2e202SAlex Deucher #endif 42297b2e202SAlex Deucher 42397b2e202SAlex Deucher /* buffer handling */ 42497b2e202SAlex Deucher const struct amdgpu_buffer_funcs *buffer_funcs; 42597b2e202SAlex Deucher struct amdgpu_ring *buffer_funcs_ring; 426703297c1SChristian König /* Scheduler entity for buffer moves */ 427703297c1SChristian König struct amd_sched_entity entity; 42829b3259aSChristian König 42929b3259aSChristian König /* custom LRU management */ 43029b3259aSChristian König struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE]; 43197b2e202SAlex Deucher }; 43297b2e202SAlex Deucher 43397b2e202SAlex Deucher int amdgpu_copy_buffer(struct amdgpu_ring *ring, 43497b2e202SAlex Deucher uint64_t src_offset, 43597b2e202SAlex Deucher uint64_t dst_offset, 43697b2e202SAlex Deucher uint32_t byte_count, 43797b2e202SAlex Deucher struct reservation_object *resv, 438c7ae72c0SChunming Zhou struct fence **fence); 43959b4a977SFlora Cui int amdgpu_fill_buffer(struct amdgpu_bo *bo, 44059b4a977SFlora Cui uint32_t src_data, 44159b4a977SFlora Cui struct reservation_object *resv, 44259b4a977SFlora Cui struct fence **fence); 44359b4a977SFlora Cui 44497b2e202SAlex Deucher int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma); 44597b2e202SAlex Deucher 44697b2e202SAlex Deucher struct amdgpu_bo_list_entry { 44797b2e202SAlex Deucher struct amdgpu_bo *robj; 44897b2e202SAlex Deucher struct ttm_validate_buffer tv; 44997b2e202SAlex Deucher struct amdgpu_bo_va *bo_va; 45097b2e202SAlex Deucher uint32_t priority; 4512f568dbdSChristian König struct page **user_pages; 4522f568dbdSChristian König int user_invalidated; 45397b2e202SAlex Deucher }; 45497b2e202SAlex Deucher 45597b2e202SAlex Deucher struct amdgpu_bo_va_mapping { 45697b2e202SAlex Deucher struct list_head list; 45797b2e202SAlex Deucher struct interval_tree_node it; 45897b2e202SAlex Deucher uint64_t offset; 45997b2e202SAlex Deucher uint32_t flags; 46097b2e202SAlex Deucher }; 46197b2e202SAlex Deucher 46297b2e202SAlex Deucher /* bo virtual addresses in a specific vm */ 46397b2e202SAlex Deucher struct amdgpu_bo_va { 46497b2e202SAlex Deucher /* protected by bo being reserved */ 46597b2e202SAlex Deucher struct list_head bo_list; 466bb1e38a4SChunming Zhou struct fence *last_pt_update; 46797b2e202SAlex Deucher unsigned ref_count; 46897b2e202SAlex Deucher 4697fc11959SChristian König /* protected by vm mutex and spinlock */ 47097b2e202SAlex Deucher struct list_head vm_status; 47197b2e202SAlex Deucher 4727fc11959SChristian König /* mappings for this bo_va */ 4737fc11959SChristian König struct list_head invalids; 4747fc11959SChristian König struct list_head valids; 4757fc11959SChristian König 47697b2e202SAlex Deucher /* constant after initialization */ 47797b2e202SAlex Deucher struct amdgpu_vm *vm; 47897b2e202SAlex Deucher struct amdgpu_bo *bo; 47997b2e202SAlex Deucher }; 48097b2e202SAlex Deucher 4817e5a547fSChunming Zhou #define AMDGPU_GEM_DOMAIN_MAX 0x3 4827e5a547fSChunming Zhou 48397b2e202SAlex Deucher struct amdgpu_bo { 48497b2e202SAlex Deucher /* Protected by gem.mutex */ 48597b2e202SAlex Deucher struct list_head list; 48697b2e202SAlex Deucher /* Protected by tbo.reserved */ 4871ea863fdSChristian König u32 prefered_domains; 4881ea863fdSChristian König u32 allowed_domains; 4897e5a547fSChunming Zhou struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1]; 49097b2e202SAlex Deucher struct ttm_placement placement; 49197b2e202SAlex Deucher struct ttm_buffer_object tbo; 49297b2e202SAlex Deucher struct ttm_bo_kmap_obj kmap; 49397b2e202SAlex Deucher u64 flags; 49497b2e202SAlex Deucher unsigned pin_count; 49597b2e202SAlex Deucher void *kptr; 49697b2e202SAlex Deucher u64 tiling_flags; 49797b2e202SAlex Deucher u64 metadata_flags; 49897b2e202SAlex Deucher void *metadata; 49997b2e202SAlex Deucher u32 metadata_size; 50097b2e202SAlex Deucher /* list of all virtual address to which this bo 50197b2e202SAlex Deucher * is associated to 50297b2e202SAlex Deucher */ 50397b2e202SAlex Deucher struct list_head va; 50497b2e202SAlex Deucher /* Constant after initialization */ 50597b2e202SAlex Deucher struct amdgpu_device *adev; 50697b2e202SAlex Deucher struct drm_gem_object gem_base; 50782b9c55bSChristian König struct amdgpu_bo *parent; 508e7893c4bSChunming Zhou struct amdgpu_bo *shadow; 50997b2e202SAlex Deucher 51097b2e202SAlex Deucher struct ttm_bo_kmap_obj dma_buf_vmap; 51197b2e202SAlex Deucher struct amdgpu_mn *mn; 51297b2e202SAlex Deucher struct list_head mn_list; 51397b2e202SAlex Deucher }; 51497b2e202SAlex Deucher #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base) 51597b2e202SAlex Deucher 51697b2e202SAlex Deucher void amdgpu_gem_object_free(struct drm_gem_object *obj); 51797b2e202SAlex Deucher int amdgpu_gem_object_open(struct drm_gem_object *obj, 51897b2e202SAlex Deucher struct drm_file *file_priv); 51997b2e202SAlex Deucher void amdgpu_gem_object_close(struct drm_gem_object *obj, 52097b2e202SAlex Deucher struct drm_file *file_priv); 52197b2e202SAlex Deucher unsigned long amdgpu_gem_timeout(uint64_t timeout_ns); 52297b2e202SAlex Deucher struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj); 5234d9c514dSChristian König struct drm_gem_object * 5244d9c514dSChristian König amdgpu_gem_prime_import_sg_table(struct drm_device *dev, 52597b2e202SAlex Deucher struct dma_buf_attachment *attach, 52697b2e202SAlex Deucher struct sg_table *sg); 52797b2e202SAlex Deucher struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev, 52897b2e202SAlex Deucher struct drm_gem_object *gobj, 52997b2e202SAlex Deucher int flags); 53097b2e202SAlex Deucher int amdgpu_gem_prime_pin(struct drm_gem_object *obj); 53197b2e202SAlex Deucher void amdgpu_gem_prime_unpin(struct drm_gem_object *obj); 53297b2e202SAlex Deucher struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *); 53397b2e202SAlex Deucher void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj); 53497b2e202SAlex Deucher void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); 53597b2e202SAlex Deucher int amdgpu_gem_debugfs_init(struct amdgpu_device *adev); 53697b2e202SAlex Deucher 53797b2e202SAlex Deucher /* sub-allocation manager, it has to be protected by another lock. 53897b2e202SAlex Deucher * By conception this is an helper for other part of the driver 53997b2e202SAlex Deucher * like the indirect buffer or semaphore, which both have their 54097b2e202SAlex Deucher * locking. 54197b2e202SAlex Deucher * 54297b2e202SAlex Deucher * Principe is simple, we keep a list of sub allocation in offset 54397b2e202SAlex Deucher * order (first entry has offset == 0, last entry has the highest 54497b2e202SAlex Deucher * offset). 54597b2e202SAlex Deucher * 54697b2e202SAlex Deucher * When allocating new object we first check if there is room at 54797b2e202SAlex Deucher * the end total_size - (last_object_offset + last_object_size) >= 54897b2e202SAlex Deucher * alloc_size. If so we allocate new object there. 54997b2e202SAlex Deucher * 55097b2e202SAlex Deucher * When there is not enough room at the end, we start waiting for 55197b2e202SAlex Deucher * each sub object until we reach object_offset+object_size >= 55297b2e202SAlex Deucher * alloc_size, this object then become the sub object we return. 55397b2e202SAlex Deucher * 55497b2e202SAlex Deucher * Alignment can't be bigger than page size. 55597b2e202SAlex Deucher * 55697b2e202SAlex Deucher * Hole are not considered for allocation to keep things simple. 55797b2e202SAlex Deucher * Assumption is that there won't be hole (all object on same 55897b2e202SAlex Deucher * alignment). 55997b2e202SAlex Deucher */ 5606ba60b89SChristian König 5616ba60b89SChristian König #define AMDGPU_SA_NUM_FENCE_LISTS 32 5626ba60b89SChristian König 56397b2e202SAlex Deucher struct amdgpu_sa_manager { 56497b2e202SAlex Deucher wait_queue_head_t wq; 56597b2e202SAlex Deucher struct amdgpu_bo *bo; 56697b2e202SAlex Deucher struct list_head *hole; 5676ba60b89SChristian König struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS]; 56897b2e202SAlex Deucher struct list_head olist; 56997b2e202SAlex Deucher unsigned size; 57097b2e202SAlex Deucher uint64_t gpu_addr; 57197b2e202SAlex Deucher void *cpu_ptr; 57297b2e202SAlex Deucher uint32_t domain; 57397b2e202SAlex Deucher uint32_t align; 57497b2e202SAlex Deucher }; 57597b2e202SAlex Deucher 57697b2e202SAlex Deucher /* sub-allocation buffer */ 57797b2e202SAlex Deucher struct amdgpu_sa_bo { 57897b2e202SAlex Deucher struct list_head olist; 57997b2e202SAlex Deucher struct list_head flist; 58097b2e202SAlex Deucher struct amdgpu_sa_manager *manager; 58197b2e202SAlex Deucher unsigned soffset; 58297b2e202SAlex Deucher unsigned eoffset; 5834ce9891eSChunming Zhou struct fence *fence; 58497b2e202SAlex Deucher }; 58597b2e202SAlex Deucher 58697b2e202SAlex Deucher /* 58797b2e202SAlex Deucher * GEM objects. 58897b2e202SAlex Deucher */ 589418aa0c2SChristian König void amdgpu_gem_force_release(struct amdgpu_device *adev); 59097b2e202SAlex Deucher int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, 59197b2e202SAlex Deucher int alignment, u32 initial_domain, 59297b2e202SAlex Deucher u64 flags, bool kernel, 59397b2e202SAlex Deucher struct drm_gem_object **obj); 59497b2e202SAlex Deucher 59597b2e202SAlex Deucher int amdgpu_mode_dumb_create(struct drm_file *file_priv, 59697b2e202SAlex Deucher struct drm_device *dev, 59797b2e202SAlex Deucher struct drm_mode_create_dumb *args); 59897b2e202SAlex Deucher int amdgpu_mode_dumb_mmap(struct drm_file *filp, 59997b2e202SAlex Deucher struct drm_device *dev, 60097b2e202SAlex Deucher uint32_t handle, uint64_t *offset_p); 60197b2e202SAlex Deucher /* 60297b2e202SAlex Deucher * Synchronization 60397b2e202SAlex Deucher */ 60497b2e202SAlex Deucher struct amdgpu_sync { 605f91b3a69SChristian König DECLARE_HASHTABLE(fences, 4); 6063c62338cSChunming Zhou struct fence *last_vm_update; 60797b2e202SAlex Deucher }; 60897b2e202SAlex Deucher 60997b2e202SAlex Deucher void amdgpu_sync_create(struct amdgpu_sync *sync); 61091e1a520SChristian König int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, 61191e1a520SChristian König struct fence *f); 61297b2e202SAlex Deucher int amdgpu_sync_resv(struct amdgpu_device *adev, 61397b2e202SAlex Deucher struct amdgpu_sync *sync, 61497b2e202SAlex Deucher struct reservation_object *resv, 61597b2e202SAlex Deucher void *owner); 6161fbb2e92SChristian König struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync, 61735420238SChristian König struct amdgpu_ring *ring); 618e61235dbSChristian König struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync); 6198a8f0b48SChristian König void amdgpu_sync_free(struct amdgpu_sync *sync); 620257bf15aSChristian König int amdgpu_sync_init(void); 621257bf15aSChristian König void amdgpu_sync_fini(void); 622d573de2dSRex Zhu int amdgpu_fence_slab_init(void); 623d573de2dSRex Zhu void amdgpu_fence_slab_fini(void); 62497b2e202SAlex Deucher 62597b2e202SAlex Deucher /* 62697b2e202SAlex Deucher * GART structures, functions & helpers 62797b2e202SAlex Deucher */ 62897b2e202SAlex Deucher struct amdgpu_mc; 62997b2e202SAlex Deucher 63097b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SIZE 4096 63197b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1) 63297b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_SHIFT 12 63397b2e202SAlex Deucher #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK) 63497b2e202SAlex Deucher 63597b2e202SAlex Deucher struct amdgpu_gart { 63697b2e202SAlex Deucher dma_addr_t table_addr; 63797b2e202SAlex Deucher struct amdgpu_bo *robj; 63897b2e202SAlex Deucher void *ptr; 63997b2e202SAlex Deucher unsigned num_gpu_pages; 64097b2e202SAlex Deucher unsigned num_cpu_pages; 64197b2e202SAlex Deucher unsigned table_size; 642a1d29476SChristian König #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS 64397b2e202SAlex Deucher struct page **pages; 644a1d29476SChristian König #endif 64597b2e202SAlex Deucher bool ready; 64697b2e202SAlex Deucher const struct amdgpu_gart_funcs *gart_funcs; 64797b2e202SAlex Deucher }; 64897b2e202SAlex Deucher 64997b2e202SAlex Deucher int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev); 65097b2e202SAlex Deucher void amdgpu_gart_table_ram_free(struct amdgpu_device *adev); 65197b2e202SAlex Deucher int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev); 65297b2e202SAlex Deucher void amdgpu_gart_table_vram_free(struct amdgpu_device *adev); 65397b2e202SAlex Deucher int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev); 65497b2e202SAlex Deucher void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev); 65597b2e202SAlex Deucher int amdgpu_gart_init(struct amdgpu_device *adev); 65697b2e202SAlex Deucher void amdgpu_gart_fini(struct amdgpu_device *adev); 65797b2e202SAlex Deucher void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset, 65897b2e202SAlex Deucher int pages); 65997b2e202SAlex Deucher int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset, 66097b2e202SAlex Deucher int pages, struct page **pagelist, 66197b2e202SAlex Deucher dma_addr_t *dma_addr, uint32_t flags); 66297b2e202SAlex Deucher 66397b2e202SAlex Deucher /* 66497b2e202SAlex Deucher * GPU MC structures, functions & helpers 66597b2e202SAlex Deucher */ 66697b2e202SAlex Deucher struct amdgpu_mc { 66797b2e202SAlex Deucher resource_size_t aper_size; 66897b2e202SAlex Deucher resource_size_t aper_base; 66997b2e202SAlex Deucher resource_size_t agp_base; 67097b2e202SAlex Deucher /* for some chips with <= 32MB we need to lie 67197b2e202SAlex Deucher * about vram size near mc fb location */ 67297b2e202SAlex Deucher u64 mc_vram_size; 67397b2e202SAlex Deucher u64 visible_vram_size; 67497b2e202SAlex Deucher u64 gtt_size; 67597b2e202SAlex Deucher u64 gtt_start; 67697b2e202SAlex Deucher u64 gtt_end; 67797b2e202SAlex Deucher u64 vram_start; 67897b2e202SAlex Deucher u64 vram_end; 67997b2e202SAlex Deucher unsigned vram_width; 68097b2e202SAlex Deucher u64 real_vram_size; 68197b2e202SAlex Deucher int vram_mtrr; 68297b2e202SAlex Deucher u64 gtt_base_align; 68397b2e202SAlex Deucher u64 mc_mask; 68497b2e202SAlex Deucher const struct firmware *fw; /* MC firmware */ 68597b2e202SAlex Deucher uint32_t fw_version; 68697b2e202SAlex Deucher struct amdgpu_irq_src vm_fault; 68781c59f54SKen Wang uint32_t vram_type; 68850b0197aSChunming Zhou uint32_t srbm_soft_reset; 68950b0197aSChunming Zhou struct amdgpu_mode_mc_save save; 69097b2e202SAlex Deucher }; 69197b2e202SAlex Deucher 69297b2e202SAlex Deucher /* 69397b2e202SAlex Deucher * GPU doorbell structures, functions & helpers 69497b2e202SAlex Deucher */ 69597b2e202SAlex Deucher typedef enum _AMDGPU_DOORBELL_ASSIGNMENT 69697b2e202SAlex Deucher { 69797b2e202SAlex Deucher AMDGPU_DOORBELL_KIQ = 0x000, 69897b2e202SAlex Deucher AMDGPU_DOORBELL_HIQ = 0x001, 69997b2e202SAlex Deucher AMDGPU_DOORBELL_DIQ = 0x002, 70097b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING0 = 0x010, 70197b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING1 = 0x011, 70297b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING2 = 0x012, 70397b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING3 = 0x013, 70497b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING4 = 0x014, 70597b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING5 = 0x015, 70697b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING6 = 0x016, 70797b2e202SAlex Deucher AMDGPU_DOORBELL_MEC_RING7 = 0x017, 70897b2e202SAlex Deucher AMDGPU_DOORBELL_GFX_RING0 = 0x020, 70997b2e202SAlex Deucher AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0, 71097b2e202SAlex Deucher AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1, 71197b2e202SAlex Deucher AMDGPU_DOORBELL_IH = 0x1E8, 71297b2e202SAlex Deucher AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF, 71397b2e202SAlex Deucher AMDGPU_DOORBELL_INVALID = 0xFFFF 71497b2e202SAlex Deucher } AMDGPU_DOORBELL_ASSIGNMENT; 71597b2e202SAlex Deucher 71697b2e202SAlex Deucher struct amdgpu_doorbell { 71797b2e202SAlex Deucher /* doorbell mmio */ 71897b2e202SAlex Deucher resource_size_t base; 71997b2e202SAlex Deucher resource_size_t size; 72097b2e202SAlex Deucher u32 __iomem *ptr; 72197b2e202SAlex Deucher u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */ 72297b2e202SAlex Deucher }; 72397b2e202SAlex Deucher 72497b2e202SAlex Deucher void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev, 72597b2e202SAlex Deucher phys_addr_t *aperture_base, 72697b2e202SAlex Deucher size_t *aperture_size, 72797b2e202SAlex Deucher size_t *start_offset); 72897b2e202SAlex Deucher 72997b2e202SAlex Deucher /* 73097b2e202SAlex Deucher * IRQS. 73197b2e202SAlex Deucher */ 73297b2e202SAlex Deucher 73397b2e202SAlex Deucher struct amdgpu_flip_work { 734325cbba1SMichel Dänzer struct delayed_work flip_work; 73597b2e202SAlex Deucher struct work_struct unpin_work; 73697b2e202SAlex Deucher struct amdgpu_device *adev; 73797b2e202SAlex Deucher int crtc_id; 738325cbba1SMichel Dänzer u32 target_vblank; 73997b2e202SAlex Deucher uint64_t base; 74097b2e202SAlex Deucher struct drm_pending_vblank_event *event; 74197b2e202SAlex Deucher struct amdgpu_bo *old_rbo; 7421ffd2652SChristian König struct fence *excl; 7431ffd2652SChristian König unsigned shared_count; 7441ffd2652SChristian König struct fence **shared; 745c3874b75SChristian König struct fence_cb cb; 746cb9e59d7SAlex Deucher bool async; 74797b2e202SAlex Deucher }; 74897b2e202SAlex Deucher 74997b2e202SAlex Deucher 75097b2e202SAlex Deucher /* 75197b2e202SAlex Deucher * CP & rings. 75297b2e202SAlex Deucher */ 75397b2e202SAlex Deucher 75497b2e202SAlex Deucher struct amdgpu_ib { 75597b2e202SAlex Deucher struct amdgpu_sa_bo *sa_bo; 75697b2e202SAlex Deucher uint32_t length_dw; 75797b2e202SAlex Deucher uint64_t gpu_addr; 75897b2e202SAlex Deucher uint32_t *ptr; 759de807f81SJammy Zhou uint32_t flags; 76097b2e202SAlex Deucher }; 76197b2e202SAlex Deucher 76297b2e202SAlex Deucher enum amdgpu_ring_type { 76397b2e202SAlex Deucher AMDGPU_RING_TYPE_GFX, 76497b2e202SAlex Deucher AMDGPU_RING_TYPE_COMPUTE, 76597b2e202SAlex Deucher AMDGPU_RING_TYPE_SDMA, 76697b2e202SAlex Deucher AMDGPU_RING_TYPE_UVD, 76797b2e202SAlex Deucher AMDGPU_RING_TYPE_VCE 76897b2e202SAlex Deucher }; 76997b2e202SAlex Deucher 77062250a91SNils Wallménius extern const struct amd_sched_backend_ops amdgpu_sched_ops; 771c1b69ed0SChunming Zhou 77250838c8cSChristian König int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, 773c5637837SMonk Liu struct amdgpu_job **job, struct amdgpu_vm *vm); 774d71518b5SChristian König int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size, 775d71518b5SChristian König struct amdgpu_job **job); 776b6723c8dSMonk Liu 777a5fb4ec2SChristian König void amdgpu_job_free_resources(struct amdgpu_job *job); 77850838c8cSChristian König void amdgpu_job_free(struct amdgpu_job *job); 779d71518b5SChristian König int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring, 7802bd9ccfaSChristian König struct amd_sched_entity *entity, void *owner, 7812bd9ccfaSChristian König struct fence **f); 7823c704e93SChunming Zhou 78397b2e202SAlex Deucher struct amdgpu_ring { 78497b2e202SAlex Deucher struct amdgpu_device *adev; 78597b2e202SAlex Deucher const struct amdgpu_ring_funcs *funcs; 78697b2e202SAlex Deucher struct amdgpu_fence_driver fence_drv; 7874f839a24SChristian König struct amd_gpu_scheduler sched; 78897b2e202SAlex Deucher 78997b2e202SAlex Deucher struct amdgpu_bo *ring_obj; 79097b2e202SAlex Deucher volatile uint32_t *ring; 79197b2e202SAlex Deucher unsigned rptr_offs; 79297b2e202SAlex Deucher unsigned wptr; 79397b2e202SAlex Deucher unsigned wptr_old; 79497b2e202SAlex Deucher unsigned ring_size; 795c7e6be23SChristian König unsigned max_dw; 79697b2e202SAlex Deucher int count_dw; 79797b2e202SAlex Deucher uint64_t gpu_addr; 79897b2e202SAlex Deucher uint32_t align_mask; 79997b2e202SAlex Deucher uint32_t ptr_mask; 80097b2e202SAlex Deucher bool ready; 80197b2e202SAlex Deucher u32 nop; 80297b2e202SAlex Deucher u32 idx; 80397b2e202SAlex Deucher u32 me; 80497b2e202SAlex Deucher u32 pipe; 80597b2e202SAlex Deucher u32 queue; 80697b2e202SAlex Deucher struct amdgpu_bo *mqd_obj; 80797b2e202SAlex Deucher u32 doorbell_index; 80897b2e202SAlex Deucher bool use_doorbell; 80997b2e202SAlex Deucher unsigned wptr_offs; 81097b2e202SAlex Deucher unsigned fence_offs; 811aa3b73f6SChristian König uint64_t current_ctx; 81297b2e202SAlex Deucher enum amdgpu_ring_type type; 81397b2e202SAlex Deucher char name[16]; 814128cff1aSMonk Liu unsigned cond_exe_offs; 815128cff1aSMonk Liu u64 cond_exe_gpu_addr; 816128cff1aSMonk Liu volatile u32 *cond_exe_cpu_addr; 817a909c6bdSMonk Liu #if defined(CONFIG_DEBUG_FS) 818a909c6bdSMonk Liu struct dentry *ent; 819a909c6bdSMonk Liu #endif 82097b2e202SAlex Deucher }; 82197b2e202SAlex Deucher 82297b2e202SAlex Deucher /* 82397b2e202SAlex Deucher * VM 82497b2e202SAlex Deucher */ 82597b2e202SAlex Deucher 82697b2e202SAlex Deucher /* maximum number of VMIDs */ 82797b2e202SAlex Deucher #define AMDGPU_NUM_VM 16 82897b2e202SAlex Deucher 82997b2e202SAlex Deucher /* number of entries in page table */ 83097b2e202SAlex Deucher #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size) 83197b2e202SAlex Deucher 83297b2e202SAlex Deucher /* PTBs (Page Table Blocks) need to be aligned to 32K */ 83397b2e202SAlex Deucher #define AMDGPU_VM_PTB_ALIGN_SIZE 32768 83497b2e202SAlex Deucher 8351303c73cSChristian König /* LOG2 number of continuous pages for the fragment field */ 8361303c73cSChristian König #define AMDGPU_LOG2_PAGES_PER_FRAG 4 8371303c73cSChristian König 83897b2e202SAlex Deucher #define AMDGPU_PTE_VALID (1 << 0) 83997b2e202SAlex Deucher #define AMDGPU_PTE_SYSTEM (1 << 1) 84097b2e202SAlex Deucher #define AMDGPU_PTE_SNOOPED (1 << 2) 84197b2e202SAlex Deucher 84297b2e202SAlex Deucher /* VI only */ 84397b2e202SAlex Deucher #define AMDGPU_PTE_EXECUTABLE (1 << 4) 84497b2e202SAlex Deucher 84597b2e202SAlex Deucher #define AMDGPU_PTE_READABLE (1 << 5) 84697b2e202SAlex Deucher #define AMDGPU_PTE_WRITEABLE (1 << 6) 84797b2e202SAlex Deucher 8481303c73cSChristian König #define AMDGPU_PTE_FRAG(x) ((x & 0x1f) << 7) 84997b2e202SAlex Deucher 850d9c13156SChristian König /* How to programm VM fault handling */ 851d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_NEVER 0 852d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_FIRST 1 853d9c13156SChristian König #define AMDGPU_VM_FAULT_STOP_ALWAYS 2 854d9c13156SChristian König 85597b2e202SAlex Deucher struct amdgpu_vm_pt { 856ee1782c3SChristian König struct amdgpu_bo_list_entry entry; 85797b2e202SAlex Deucher uint64_t addr; 85897b2e202SAlex Deucher }; 85997b2e202SAlex Deucher 86097b2e202SAlex Deucher struct amdgpu_vm { 86125cfc3c2SChristian König /* tree of virtual addresses mapped */ 86297b2e202SAlex Deucher struct rb_root va; 86397b2e202SAlex Deucher 8647fc11959SChristian König /* protecting invalidated */ 86597b2e202SAlex Deucher spinlock_t status_lock; 86697b2e202SAlex Deucher 86797b2e202SAlex Deucher /* BOs moved, but not yet updated in the PT */ 86897b2e202SAlex Deucher struct list_head invalidated; 86997b2e202SAlex Deucher 8707fc11959SChristian König /* BOs cleared in the PT because of a move */ 8717fc11959SChristian König struct list_head cleared; 8727fc11959SChristian König 8737fc11959SChristian König /* BO mappings freed, but not yet updated in the PT */ 87497b2e202SAlex Deucher struct list_head freed; 87597b2e202SAlex Deucher 87697b2e202SAlex Deucher /* contains the page directory */ 87797b2e202SAlex Deucher struct amdgpu_bo *page_directory; 87897b2e202SAlex Deucher unsigned max_pde_used; 87905906decSBas Nieuwenhuizen struct fence *page_directory_fence; 8805a712a87SChristian König uint64_t last_eviction_counter; 88197b2e202SAlex Deucher 88297b2e202SAlex Deucher /* array of page tables, one for each page directory entry */ 88397b2e202SAlex Deucher struct amdgpu_vm_pt *page_tables; 88497b2e202SAlex Deucher 88597b2e202SAlex Deucher /* for id and flush management per ring */ 886bcb1ba35SChristian König struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS]; 88725cfc3c2SChristian König 88881d75a30Sjimqu /* protecting freed */ 88981d75a30Sjimqu spinlock_t freed_lock; 8902bd9ccfaSChristian König 8912bd9ccfaSChristian König /* Scheduler entity for page table updates */ 8922bd9ccfaSChristian König struct amd_sched_entity entity; 893031e2983SChunming Zhou 894031e2983SChunming Zhou /* client id */ 895031e2983SChunming Zhou u64 client_id; 89697b2e202SAlex Deucher }; 89797b2e202SAlex Deucher 898bcb1ba35SChristian König struct amdgpu_vm_id { 899a9a78b32SChristian König struct list_head list; 900832a902fSChristian König struct fence *first; 901832a902fSChristian König struct amdgpu_sync active; 90241d9eb2cSChristian König struct fence *last_flush; 9030ea54b9bSChristian König atomic64_t owner; 904971fe9a9SChristian König 905bcb1ba35SChristian König uint64_t pd_gpu_addr; 906bcb1ba35SChristian König /* last flushed PD/PT update */ 907bcb1ba35SChristian König struct fence *flushed_updates; 908bcb1ba35SChristian König 9096adb0513SChunming Zhou uint32_t current_gpu_reset_count; 9106adb0513SChunming Zhou 911971fe9a9SChristian König uint32_t gds_base; 912971fe9a9SChristian König uint32_t gds_size; 913971fe9a9SChristian König uint32_t gws_base; 914971fe9a9SChristian König uint32_t gws_size; 915971fe9a9SChristian König uint32_t oa_base; 916971fe9a9SChristian König uint32_t oa_size; 917a9a78b32SChristian König }; 918a9a78b32SChristian König 919a9a78b32SChristian König struct amdgpu_vm_manager { 920a9a78b32SChristian König /* Handling of VMIDs */ 921a9a78b32SChristian König struct mutex lock; 922a9a78b32SChristian König unsigned num_ids; 923a9a78b32SChristian König struct list_head ids_lru; 924bcb1ba35SChristian König struct amdgpu_vm_id ids[AMDGPU_NUM_VM]; 9251c16c0a7SChristian König 9261fbb2e92SChristian König /* Handling of VM fences */ 9271fbb2e92SChristian König u64 fence_context; 9281fbb2e92SChristian König unsigned seqno[AMDGPU_MAX_RINGS]; 9291fbb2e92SChristian König 93097b2e202SAlex Deucher uint32_t max_pfn; 93197b2e202SAlex Deucher /* vram base address for page table entry */ 93297b2e202SAlex Deucher u64 vram_base_offset; 93397b2e202SAlex Deucher /* is vm enabled? */ 93497b2e202SAlex Deucher bool enabled; 93597b2e202SAlex Deucher /* vm pte handling */ 93697b2e202SAlex Deucher const struct amdgpu_vm_pte_funcs *vm_pte_funcs; 9372d55e45aSChristian König struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS]; 9382d55e45aSChristian König unsigned vm_pte_num_rings; 9392d55e45aSChristian König atomic_t vm_pte_next_ring; 940031e2983SChunming Zhou /* client id counter */ 941031e2983SChunming Zhou atomic64_t client_counter; 94297b2e202SAlex Deucher }; 94397b2e202SAlex Deucher 944a9a78b32SChristian König void amdgpu_vm_manager_init(struct amdgpu_device *adev); 945ea89f8c9SChristian König void amdgpu_vm_manager_fini(struct amdgpu_device *adev); 9468b4fb00bSChristian König int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm); 9478b4fb00bSChristian König void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm); 94856467ebfSChristian König void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, 9493c0eea6cSChristian König struct list_head *validated, 95056467ebfSChristian König struct amdgpu_bo_list_entry *entry); 9515a712a87SChristian König void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, 9525a712a87SChristian König struct list_head *duplicates); 953eceb8a15SChristian König void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev, 954eceb8a15SChristian König struct amdgpu_vm *vm); 9558b4fb00bSChristian König int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, 9564ff37a83SChristian König struct amdgpu_sync *sync, struct fence *fence, 957fd53be30SChunming Zhou struct amdgpu_job *job); 958fd53be30SChunming Zhou int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job); 959971fe9a9SChristian König void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id); 960b07c9d2aSChristian König uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr); 9618b4fb00bSChristian König int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, 9628b4fb00bSChristian König struct amdgpu_vm *vm); 9638b4fb00bSChristian König int amdgpu_vm_clear_freed(struct amdgpu_device *adev, 9648b4fb00bSChristian König struct amdgpu_vm *vm); 9658b4fb00bSChristian König int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm, 9668b4fb00bSChristian König struct amdgpu_sync *sync); 9678b4fb00bSChristian König int amdgpu_vm_bo_update(struct amdgpu_device *adev, 9688b4fb00bSChristian König struct amdgpu_bo_va *bo_va, 9698b4fb00bSChristian König struct ttm_mem_reg *mem); 9708b4fb00bSChristian König void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, 9718b4fb00bSChristian König struct amdgpu_bo *bo); 9728b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm, 9738b4fb00bSChristian König struct amdgpu_bo *bo); 9748b4fb00bSChristian König struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, 9758b4fb00bSChristian König struct amdgpu_vm *vm, 9768b4fb00bSChristian König struct amdgpu_bo *bo); 9778b4fb00bSChristian König int amdgpu_vm_bo_map(struct amdgpu_device *adev, 9788b4fb00bSChristian König struct amdgpu_bo_va *bo_va, 9798b4fb00bSChristian König uint64_t addr, uint64_t offset, 9808b4fb00bSChristian König uint64_t size, uint32_t flags); 9818b4fb00bSChristian König int amdgpu_vm_bo_unmap(struct amdgpu_device *adev, 9828b4fb00bSChristian König struct amdgpu_bo_va *bo_va, 9838b4fb00bSChristian König uint64_t addr); 9848b4fb00bSChristian König void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, 9858b4fb00bSChristian König struct amdgpu_bo_va *bo_va); 9868b4fb00bSChristian König 98797b2e202SAlex Deucher /* 98897b2e202SAlex Deucher * context related structures 98997b2e202SAlex Deucher */ 99097b2e202SAlex Deucher 99121c16bf6SChristian König struct amdgpu_ctx_ring { 99221c16bf6SChristian König uint64_t sequence; 99337cd0ca2SChunming Zhou struct fence **fences; 99491404fb2SChristian König struct amd_sched_entity entity; 99521c16bf6SChristian König }; 99621c16bf6SChristian König 99797b2e202SAlex Deucher struct amdgpu_ctx { 99897b2e202SAlex Deucher struct kref refcount; 9999cb7e5a9SChunming Zhou struct amdgpu_device *adev; 1000d94aed5aSMarek Olšák unsigned reset_counter; 100121c16bf6SChristian König spinlock_t ring_lock; 100237cd0ca2SChunming Zhou struct fence **fences; 100321c16bf6SChristian König struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS]; 100497b2e202SAlex Deucher }; 100597b2e202SAlex Deucher 100697b2e202SAlex Deucher struct amdgpu_ctx_mgr { 100797b2e202SAlex Deucher struct amdgpu_device *adev; 10080147ee0fSMarek Olšák struct mutex lock; 10090b492a4cSAlex Deucher /* protected by lock */ 10100b492a4cSAlex Deucher struct idr ctx_handles; 101197b2e202SAlex Deucher }; 101297b2e202SAlex Deucher 10130b492a4cSAlex Deucher struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id); 10140b492a4cSAlex Deucher int amdgpu_ctx_put(struct amdgpu_ctx *ctx); 10150b492a4cSAlex Deucher 101621c16bf6SChristian König uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring, 1017ce882e6dSChristian König struct fence *fence); 101821c16bf6SChristian König struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, 101921c16bf6SChristian König struct amdgpu_ring *ring, uint64_t seq); 102021c16bf6SChristian König 10210b492a4cSAlex Deucher int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, 10220b492a4cSAlex Deucher struct drm_file *filp); 10230b492a4cSAlex Deucher 1024efd4ccb5SChristian König void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr); 1025efd4ccb5SChristian König void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); 10260b492a4cSAlex Deucher 102797b2e202SAlex Deucher /* 102897b2e202SAlex Deucher * file private structure 102997b2e202SAlex Deucher */ 103097b2e202SAlex Deucher 103197b2e202SAlex Deucher struct amdgpu_fpriv { 103297b2e202SAlex Deucher struct amdgpu_vm vm; 103397b2e202SAlex Deucher struct mutex bo_list_lock; 103497b2e202SAlex Deucher struct idr bo_list_handles; 103597b2e202SAlex Deucher struct amdgpu_ctx_mgr ctx_mgr; 103697b2e202SAlex Deucher }; 103797b2e202SAlex Deucher 103897b2e202SAlex Deucher /* 103997b2e202SAlex Deucher * residency list 104097b2e202SAlex Deucher */ 104197b2e202SAlex Deucher 104297b2e202SAlex Deucher struct amdgpu_bo_list { 104397b2e202SAlex Deucher struct mutex lock; 104497b2e202SAlex Deucher struct amdgpu_bo *gds_obj; 104597b2e202SAlex Deucher struct amdgpu_bo *gws_obj; 104697b2e202SAlex Deucher struct amdgpu_bo *oa_obj; 1047211dff55SChristian König unsigned first_userptr; 104897b2e202SAlex Deucher unsigned num_entries; 104997b2e202SAlex Deucher struct amdgpu_bo_list_entry *array; 105097b2e202SAlex Deucher }; 105197b2e202SAlex Deucher 105297b2e202SAlex Deucher struct amdgpu_bo_list * 105397b2e202SAlex Deucher amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id); 1054636ce25cSChristian König void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list, 1055636ce25cSChristian König struct list_head *validated); 105697b2e202SAlex Deucher void amdgpu_bo_list_put(struct amdgpu_bo_list *list); 105797b2e202SAlex Deucher void amdgpu_bo_list_free(struct amdgpu_bo_list *list); 105897b2e202SAlex Deucher 105997b2e202SAlex Deucher /* 106097b2e202SAlex Deucher * GFX stuff 106197b2e202SAlex Deucher */ 106297b2e202SAlex Deucher #include "clearstate_defs.h" 106397b2e202SAlex Deucher 106479e5412cSAlex Deucher struct amdgpu_rlc_funcs { 106579e5412cSAlex Deucher void (*enter_safe_mode)(struct amdgpu_device *adev); 106679e5412cSAlex Deucher void (*exit_safe_mode)(struct amdgpu_device *adev); 106779e5412cSAlex Deucher }; 106879e5412cSAlex Deucher 106997b2e202SAlex Deucher struct amdgpu_rlc { 107097b2e202SAlex Deucher /* for power gating */ 107197b2e202SAlex Deucher struct amdgpu_bo *save_restore_obj; 107297b2e202SAlex Deucher uint64_t save_restore_gpu_addr; 107397b2e202SAlex Deucher volatile uint32_t *sr_ptr; 107497b2e202SAlex Deucher const u32 *reg_list; 107597b2e202SAlex Deucher u32 reg_list_size; 107697b2e202SAlex Deucher /* for clear state */ 107797b2e202SAlex Deucher struct amdgpu_bo *clear_state_obj; 107897b2e202SAlex Deucher uint64_t clear_state_gpu_addr; 107997b2e202SAlex Deucher volatile uint32_t *cs_ptr; 108097b2e202SAlex Deucher const struct cs_section_def *cs_data; 108197b2e202SAlex Deucher u32 clear_state_size; 108297b2e202SAlex Deucher /* for cp tables */ 108397b2e202SAlex Deucher struct amdgpu_bo *cp_table_obj; 108497b2e202SAlex Deucher uint64_t cp_table_gpu_addr; 108597b2e202SAlex Deucher volatile uint32_t *cp_table_ptr; 108697b2e202SAlex Deucher u32 cp_table_size; 108779e5412cSAlex Deucher 108879e5412cSAlex Deucher /* safe mode for updating CG/PG state */ 108979e5412cSAlex Deucher bool in_safe_mode; 109079e5412cSAlex Deucher const struct amdgpu_rlc_funcs *funcs; 10912b6cd977SEric Huang 10922b6cd977SEric Huang /* for firmware data */ 10932b6cd977SEric Huang u32 save_and_restore_offset; 10942b6cd977SEric Huang u32 clear_state_descriptor_offset; 10952b6cd977SEric Huang u32 avail_scratch_ram_locations; 10962b6cd977SEric Huang u32 reg_restore_list_size; 10972b6cd977SEric Huang u32 reg_list_format_start; 10982b6cd977SEric Huang u32 reg_list_format_separate_start; 10992b6cd977SEric Huang u32 starting_offsets_start; 11002b6cd977SEric Huang u32 reg_list_format_size_bytes; 11012b6cd977SEric Huang u32 reg_list_size_bytes; 11022b6cd977SEric Huang 11032b6cd977SEric Huang u32 *register_list_format; 11042b6cd977SEric Huang u32 *register_restore; 110597b2e202SAlex Deucher }; 110697b2e202SAlex Deucher 110797b2e202SAlex Deucher struct amdgpu_mec { 110897b2e202SAlex Deucher struct amdgpu_bo *hpd_eop_obj; 110997b2e202SAlex Deucher u64 hpd_eop_gpu_addr; 111097b2e202SAlex Deucher u32 num_pipe; 111197b2e202SAlex Deucher u32 num_mec; 111297b2e202SAlex Deucher u32 num_queue; 111397b2e202SAlex Deucher }; 111497b2e202SAlex Deucher 111597b2e202SAlex Deucher /* 111697b2e202SAlex Deucher * GPU scratch registers structures, functions & helpers 111797b2e202SAlex Deucher */ 111897b2e202SAlex Deucher struct amdgpu_scratch { 111997b2e202SAlex Deucher unsigned num_reg; 112097b2e202SAlex Deucher uint32_t reg_base; 112197b2e202SAlex Deucher bool free[32]; 112297b2e202SAlex Deucher uint32_t reg[32]; 112397b2e202SAlex Deucher }; 112497b2e202SAlex Deucher 112597b2e202SAlex Deucher /* 112697b2e202SAlex Deucher * GFX configurations 112797b2e202SAlex Deucher */ 112897b2e202SAlex Deucher struct amdgpu_gca_config { 112997b2e202SAlex Deucher unsigned max_shader_engines; 113097b2e202SAlex Deucher unsigned max_tile_pipes; 113197b2e202SAlex Deucher unsigned max_cu_per_sh; 113297b2e202SAlex Deucher unsigned max_sh_per_se; 113397b2e202SAlex Deucher unsigned max_backends_per_se; 113497b2e202SAlex Deucher unsigned max_texture_channel_caches; 113597b2e202SAlex Deucher unsigned max_gprs; 113697b2e202SAlex Deucher unsigned max_gs_threads; 113797b2e202SAlex Deucher unsigned max_hw_contexts; 113897b2e202SAlex Deucher unsigned sc_prim_fifo_size_frontend; 113997b2e202SAlex Deucher unsigned sc_prim_fifo_size_backend; 114097b2e202SAlex Deucher unsigned sc_hiz_tile_fifo_size; 114197b2e202SAlex Deucher unsigned sc_earlyz_tile_fifo_size; 114297b2e202SAlex Deucher 114397b2e202SAlex Deucher unsigned num_tile_pipes; 114497b2e202SAlex Deucher unsigned backend_enable_mask; 114597b2e202SAlex Deucher unsigned mem_max_burst_length_bytes; 114697b2e202SAlex Deucher unsigned mem_row_size_in_kb; 114797b2e202SAlex Deucher unsigned shader_engine_tile_size; 114897b2e202SAlex Deucher unsigned num_gpus; 114997b2e202SAlex Deucher unsigned multi_gpu_tile_size; 115097b2e202SAlex Deucher unsigned mc_arb_ramcfg; 115197b2e202SAlex Deucher unsigned gb_addr_config; 11528f8e00c1SAlex Deucher unsigned num_rbs; 115397b2e202SAlex Deucher 115497b2e202SAlex Deucher uint32_t tile_mode_array[32]; 115597b2e202SAlex Deucher uint32_t macrotile_mode_array[16]; 115697b2e202SAlex Deucher }; 115797b2e202SAlex Deucher 11587dae69a2SAlex Deucher struct amdgpu_cu_info { 11597dae69a2SAlex Deucher uint32_t number; /* total active CU number */ 11607dae69a2SAlex Deucher uint32_t ao_cu_mask; 11617dae69a2SAlex Deucher uint32_t bitmap[4][4]; 11627dae69a2SAlex Deucher }; 11637dae69a2SAlex Deucher 1164b95e31fdSAlex Deucher struct amdgpu_gfx_funcs { 1165b95e31fdSAlex Deucher /* get the gpu clock counter */ 1166b95e31fdSAlex Deucher uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev); 11679559ef5bSTom St Denis void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance); 1168b95e31fdSAlex Deucher }; 1169b95e31fdSAlex Deucher 117097b2e202SAlex Deucher struct amdgpu_gfx { 117197b2e202SAlex Deucher struct mutex gpu_clock_mutex; 117297b2e202SAlex Deucher struct amdgpu_gca_config config; 117397b2e202SAlex Deucher struct amdgpu_rlc rlc; 117497b2e202SAlex Deucher struct amdgpu_mec mec; 117597b2e202SAlex Deucher struct amdgpu_scratch scratch; 117697b2e202SAlex Deucher const struct firmware *me_fw; /* ME firmware */ 117797b2e202SAlex Deucher uint32_t me_fw_version; 117897b2e202SAlex Deucher const struct firmware *pfp_fw; /* PFP firmware */ 117997b2e202SAlex Deucher uint32_t pfp_fw_version; 118097b2e202SAlex Deucher const struct firmware *ce_fw; /* CE firmware */ 118197b2e202SAlex Deucher uint32_t ce_fw_version; 118297b2e202SAlex Deucher const struct firmware *rlc_fw; /* RLC firmware */ 118397b2e202SAlex Deucher uint32_t rlc_fw_version; 118497b2e202SAlex Deucher const struct firmware *mec_fw; /* MEC firmware */ 118597b2e202SAlex Deucher uint32_t mec_fw_version; 118697b2e202SAlex Deucher const struct firmware *mec2_fw; /* MEC2 firmware */ 118797b2e202SAlex Deucher uint32_t mec2_fw_version; 118802558a00SKen Wang uint32_t me_feature_version; 118902558a00SKen Wang uint32_t ce_feature_version; 119002558a00SKen Wang uint32_t pfp_feature_version; 1191351643d7SJammy Zhou uint32_t rlc_feature_version; 1192351643d7SJammy Zhou uint32_t mec_feature_version; 1193351643d7SJammy Zhou uint32_t mec2_feature_version; 119497b2e202SAlex Deucher struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS]; 119597b2e202SAlex Deucher unsigned num_gfx_rings; 119697b2e202SAlex Deucher struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS]; 119797b2e202SAlex Deucher unsigned num_compute_rings; 119897b2e202SAlex Deucher struct amdgpu_irq_src eop_irq; 119997b2e202SAlex Deucher struct amdgpu_irq_src priv_reg_irq; 120097b2e202SAlex Deucher struct amdgpu_irq_src priv_inst_irq; 120197b2e202SAlex Deucher /* gfx status */ 120297b2e202SAlex Deucher uint32_t gfx_current_status; 1203a101a899SKen Wang /* ce ram size*/ 1204a101a899SKen Wang unsigned ce_ram_size; 12057dae69a2SAlex Deucher struct amdgpu_cu_info cu_info; 1206b95e31fdSAlex Deucher const struct amdgpu_gfx_funcs *funcs; 12073d7c6384SChunming Zhou 12083d7c6384SChunming Zhou /* reset mask */ 12093d7c6384SChunming Zhou uint32_t grbm_soft_reset; 12103d7c6384SChunming Zhou uint32_t srbm_soft_reset; 121197b2e202SAlex Deucher }; 121297b2e202SAlex Deucher 1213b07c60c0SChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, 121497b2e202SAlex Deucher unsigned size, struct amdgpu_ib *ib); 12154d9c514dSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, 12164d9c514dSChristian König struct fence *f); 1217b07c60c0SChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, 1218336d1f5eSChristian König struct amdgpu_ib *ib, struct fence *last_vm_update, 1219c5637837SMonk Liu struct amdgpu_job *job, struct fence **f); 122097b2e202SAlex Deucher int amdgpu_ib_pool_init(struct amdgpu_device *adev); 122197b2e202SAlex Deucher void amdgpu_ib_pool_fini(struct amdgpu_device *adev); 122297b2e202SAlex Deucher int amdgpu_ib_ring_tests(struct amdgpu_device *adev); 122397b2e202SAlex Deucher int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw); 1224edff0e28SJammy Zhou void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count); 12259e5d5309SChristian König void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib); 122697b2e202SAlex Deucher void amdgpu_ring_commit(struct amdgpu_ring *ring); 122797b2e202SAlex Deucher void amdgpu_ring_undo(struct amdgpu_ring *ring); 122897b2e202SAlex Deucher int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, 122997b2e202SAlex Deucher unsigned ring_size, u32 nop, u32 align_mask, 123097b2e202SAlex Deucher struct amdgpu_irq_src *irq_src, unsigned irq_type, 123197b2e202SAlex Deucher enum amdgpu_ring_type ring_type); 123297b2e202SAlex Deucher void amdgpu_ring_fini(struct amdgpu_ring *ring); 123397b2e202SAlex Deucher 123497b2e202SAlex Deucher /* 123597b2e202SAlex Deucher * CS. 123697b2e202SAlex Deucher */ 123797b2e202SAlex Deucher struct amdgpu_cs_chunk { 123897b2e202SAlex Deucher uint32_t chunk_id; 123997b2e202SAlex Deucher uint32_t length_dw; 1240758ac17fSChristian König void *kdata; 124197b2e202SAlex Deucher }; 124297b2e202SAlex Deucher 124397b2e202SAlex Deucher struct amdgpu_cs_parser { 124497b2e202SAlex Deucher struct amdgpu_device *adev; 124597b2e202SAlex Deucher struct drm_file *filp; 12463cb485f3SChristian König struct amdgpu_ctx *ctx; 1247c3cca41eSChristian König 124897b2e202SAlex Deucher /* chunks */ 124997b2e202SAlex Deucher unsigned nchunks; 125097b2e202SAlex Deucher struct amdgpu_cs_chunk *chunks; 1251c3cca41eSChristian König 125250838c8cSChristian König /* scheduler job object */ 125350838c8cSChristian König struct amdgpu_job *job; 1254c3cca41eSChristian König 1255c3cca41eSChristian König /* buffer objects */ 1256c3cca41eSChristian König struct ww_acquire_ctx ticket; 1257c3cca41eSChristian König struct amdgpu_bo_list *bo_list; 125856467ebfSChristian König struct amdgpu_bo_list_entry vm_pd; 125997b2e202SAlex Deucher struct list_head validated; 1260984810fcSChristian König struct fence *fence; 1261f69f90a1SChristian König uint64_t bytes_moved_threshold; 1262f69f90a1SChristian König uint64_t bytes_moved; 126397b2e202SAlex Deucher 126497b2e202SAlex Deucher /* user fence */ 126591acbeb6SChristian König struct amdgpu_bo_list_entry uf_entry; 126697b2e202SAlex Deucher }; 126797b2e202SAlex Deucher 1268bb977d37SChunming Zhou struct amdgpu_job { 1269bb977d37SChunming Zhou struct amd_sched_job base; 1270bb977d37SChunming Zhou struct amdgpu_device *adev; 1271c5637837SMonk Liu struct amdgpu_vm *vm; 1272b07c60c0SChristian König struct amdgpu_ring *ring; 1273e86f9ceeSChristian König struct amdgpu_sync sync; 1274bb977d37SChunming Zhou struct amdgpu_ib *ibs; 127573cfa5f5SMonk Liu struct fence *fence; /* the hw fence */ 1276bb977d37SChunming Zhou uint32_t num_ibs; 1277e2840221SChristian König void *owner; 127892f25098SChristian König uint64_t ctx; 1279fd53be30SChunming Zhou bool vm_needs_flush; 1280d88bf583SChristian König unsigned vm_id; 1281d88bf583SChristian König uint64_t vm_pd_addr; 1282d88bf583SChristian König uint32_t gds_base, gds_size; 1283d88bf583SChristian König uint32_t gws_base, gws_size; 1284d88bf583SChristian König uint32_t oa_base, oa_size; 1285758ac17fSChristian König 1286758ac17fSChristian König /* user fence handling */ 1287b5f5acbcSChristian König uint64_t uf_addr; 1288758ac17fSChristian König uint64_t uf_sequence; 1289758ac17fSChristian König 1290bb977d37SChunming Zhou }; 1291a6db8a33SJunwei Zhang #define to_amdgpu_job(sched_job) \ 1292a6db8a33SJunwei Zhang container_of((sched_job), struct amdgpu_job, base) 1293bb977d37SChunming Zhou 12947270f839SChristian König static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, 12957270f839SChristian König uint32_t ib_idx, int idx) 129697b2e202SAlex Deucher { 129750838c8cSChristian König return p->job->ibs[ib_idx].ptr[idx]; 129897b2e202SAlex Deucher } 129997b2e202SAlex Deucher 13007270f839SChristian König static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p, 13017270f839SChristian König uint32_t ib_idx, int idx, 13027270f839SChristian König uint32_t value) 13037270f839SChristian König { 130450838c8cSChristian König p->job->ibs[ib_idx].ptr[idx] = value; 13057270f839SChristian König } 13067270f839SChristian König 130797b2e202SAlex Deucher /* 130897b2e202SAlex Deucher * Writeback 130997b2e202SAlex Deucher */ 131097b2e202SAlex Deucher #define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */ 131197b2e202SAlex Deucher 131297b2e202SAlex Deucher struct amdgpu_wb { 131397b2e202SAlex Deucher struct amdgpu_bo *wb_obj; 131497b2e202SAlex Deucher volatile uint32_t *wb; 131597b2e202SAlex Deucher uint64_t gpu_addr; 131697b2e202SAlex Deucher u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */ 131797b2e202SAlex Deucher unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)]; 131897b2e202SAlex Deucher }; 131997b2e202SAlex Deucher 132097b2e202SAlex Deucher int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb); 132197b2e202SAlex Deucher void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb); 132297b2e202SAlex Deucher 132397b2e202SAlex Deucher 132497b2e202SAlex Deucher 132597b2e202SAlex Deucher enum amdgpu_int_thermal_type { 132697b2e202SAlex Deucher THERMAL_TYPE_NONE, 132797b2e202SAlex Deucher THERMAL_TYPE_EXTERNAL, 132897b2e202SAlex Deucher THERMAL_TYPE_EXTERNAL_GPIO, 132997b2e202SAlex Deucher THERMAL_TYPE_RV6XX, 133097b2e202SAlex Deucher THERMAL_TYPE_RV770, 133197b2e202SAlex Deucher THERMAL_TYPE_ADT7473_WITH_INTERNAL, 133297b2e202SAlex Deucher THERMAL_TYPE_EVERGREEN, 133397b2e202SAlex Deucher THERMAL_TYPE_SUMO, 133497b2e202SAlex Deucher THERMAL_TYPE_NI, 133597b2e202SAlex Deucher THERMAL_TYPE_SI, 133697b2e202SAlex Deucher THERMAL_TYPE_EMC2103_WITH_INTERNAL, 133797b2e202SAlex Deucher THERMAL_TYPE_CI, 133897b2e202SAlex Deucher THERMAL_TYPE_KV, 133997b2e202SAlex Deucher }; 134097b2e202SAlex Deucher 134197b2e202SAlex Deucher enum amdgpu_dpm_auto_throttle_src { 134297b2e202SAlex Deucher AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, 134397b2e202SAlex Deucher AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL 134497b2e202SAlex Deucher }; 134597b2e202SAlex Deucher 134697b2e202SAlex Deucher enum amdgpu_dpm_event_src { 134797b2e202SAlex Deucher AMDGPU_DPM_EVENT_SRC_ANALOG = 0, 134897b2e202SAlex Deucher AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1, 134997b2e202SAlex Deucher AMDGPU_DPM_EVENT_SRC_DIGITAL = 2, 135097b2e202SAlex Deucher AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, 135197b2e202SAlex Deucher AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4 135297b2e202SAlex Deucher }; 135397b2e202SAlex Deucher 135497b2e202SAlex Deucher #define AMDGPU_MAX_VCE_LEVELS 6 135597b2e202SAlex Deucher 135697b2e202SAlex Deucher enum amdgpu_vce_level { 135797b2e202SAlex Deucher AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */ 135897b2e202SAlex Deucher AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */ 135997b2e202SAlex Deucher AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */ 136097b2e202SAlex Deucher AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */ 136197b2e202SAlex Deucher AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */ 136297b2e202SAlex Deucher AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */ 136397b2e202SAlex Deucher }; 136497b2e202SAlex Deucher 136597b2e202SAlex Deucher struct amdgpu_ps { 136697b2e202SAlex Deucher u32 caps; /* vbios flags */ 136797b2e202SAlex Deucher u32 class; /* vbios flags */ 136897b2e202SAlex Deucher u32 class2; /* vbios flags */ 136997b2e202SAlex Deucher /* UVD clocks */ 137097b2e202SAlex Deucher u32 vclk; 137197b2e202SAlex Deucher u32 dclk; 137297b2e202SAlex Deucher /* VCE clocks */ 137397b2e202SAlex Deucher u32 evclk; 137497b2e202SAlex Deucher u32 ecclk; 137597b2e202SAlex Deucher bool vce_active; 137697b2e202SAlex Deucher enum amdgpu_vce_level vce_level; 137797b2e202SAlex Deucher /* asic priv */ 137897b2e202SAlex Deucher void *ps_priv; 137997b2e202SAlex Deucher }; 138097b2e202SAlex Deucher 138197b2e202SAlex Deucher struct amdgpu_dpm_thermal { 138297b2e202SAlex Deucher /* thermal interrupt work */ 138397b2e202SAlex Deucher struct work_struct work; 138497b2e202SAlex Deucher /* low temperature threshold */ 138597b2e202SAlex Deucher int min_temp; 138697b2e202SAlex Deucher /* high temperature threshold */ 138797b2e202SAlex Deucher int max_temp; 138897b2e202SAlex Deucher /* was last interrupt low to high or high to low */ 138997b2e202SAlex Deucher bool high_to_low; 139097b2e202SAlex Deucher /* interrupt source */ 139197b2e202SAlex Deucher struct amdgpu_irq_src irq; 139297b2e202SAlex Deucher }; 139397b2e202SAlex Deucher 139497b2e202SAlex Deucher enum amdgpu_clk_action 139597b2e202SAlex Deucher { 139697b2e202SAlex Deucher AMDGPU_SCLK_UP = 1, 139797b2e202SAlex Deucher AMDGPU_SCLK_DOWN 139897b2e202SAlex Deucher }; 139997b2e202SAlex Deucher 140097b2e202SAlex Deucher struct amdgpu_blacklist_clocks 140197b2e202SAlex Deucher { 140297b2e202SAlex Deucher u32 sclk; 140397b2e202SAlex Deucher u32 mclk; 140497b2e202SAlex Deucher enum amdgpu_clk_action action; 140597b2e202SAlex Deucher }; 140697b2e202SAlex Deucher 140797b2e202SAlex Deucher struct amdgpu_clock_and_voltage_limits { 140897b2e202SAlex Deucher u32 sclk; 140997b2e202SAlex Deucher u32 mclk; 141097b2e202SAlex Deucher u16 vddc; 141197b2e202SAlex Deucher u16 vddci; 141297b2e202SAlex Deucher }; 141397b2e202SAlex Deucher 141497b2e202SAlex Deucher struct amdgpu_clock_array { 141597b2e202SAlex Deucher u32 count; 141697b2e202SAlex Deucher u32 *values; 141797b2e202SAlex Deucher }; 141897b2e202SAlex Deucher 141997b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_entry { 142097b2e202SAlex Deucher u32 clk; 142197b2e202SAlex Deucher u16 v; 142297b2e202SAlex Deucher }; 142397b2e202SAlex Deucher 142497b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table { 142597b2e202SAlex Deucher u32 count; 142697b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_entry *entries; 142797b2e202SAlex Deucher }; 142897b2e202SAlex Deucher 142997b2e202SAlex Deucher union amdgpu_cac_leakage_entry { 143097b2e202SAlex Deucher struct { 143197b2e202SAlex Deucher u16 vddc; 143297b2e202SAlex Deucher u32 leakage; 143397b2e202SAlex Deucher }; 143497b2e202SAlex Deucher struct { 143597b2e202SAlex Deucher u16 vddc1; 143697b2e202SAlex Deucher u16 vddc2; 143797b2e202SAlex Deucher u16 vddc3; 143897b2e202SAlex Deucher }; 143997b2e202SAlex Deucher }; 144097b2e202SAlex Deucher 144197b2e202SAlex Deucher struct amdgpu_cac_leakage_table { 144297b2e202SAlex Deucher u32 count; 144397b2e202SAlex Deucher union amdgpu_cac_leakage_entry *entries; 144497b2e202SAlex Deucher }; 144597b2e202SAlex Deucher 144697b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_entry { 144797b2e202SAlex Deucher u16 voltage; 144897b2e202SAlex Deucher u32 sclk; 144997b2e202SAlex Deucher u32 mclk; 145097b2e202SAlex Deucher }; 145197b2e202SAlex Deucher 145297b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_table { 145397b2e202SAlex Deucher u32 count; 145497b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_entry *entries; 145597b2e202SAlex Deucher }; 145697b2e202SAlex Deucher 145797b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_entry { 145897b2e202SAlex Deucher u32 vclk; 145997b2e202SAlex Deucher u32 dclk; 146097b2e202SAlex Deucher u16 v; 146197b2e202SAlex Deucher }; 146297b2e202SAlex Deucher 146397b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_table { 146497b2e202SAlex Deucher u8 count; 146597b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_entry *entries; 146697b2e202SAlex Deucher }; 146797b2e202SAlex Deucher 146897b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_entry { 146997b2e202SAlex Deucher u32 ecclk; 147097b2e202SAlex Deucher u32 evclk; 147197b2e202SAlex Deucher u16 v; 147297b2e202SAlex Deucher }; 147397b2e202SAlex Deucher 147497b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_table { 147597b2e202SAlex Deucher u8 count; 147697b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_entry *entries; 147797b2e202SAlex Deucher }; 147897b2e202SAlex Deucher 147997b2e202SAlex Deucher struct amdgpu_ppm_table { 148097b2e202SAlex Deucher u8 ppm_design; 148197b2e202SAlex Deucher u16 cpu_core_number; 148297b2e202SAlex Deucher u32 platform_tdp; 148397b2e202SAlex Deucher u32 small_ac_platform_tdp; 148497b2e202SAlex Deucher u32 platform_tdc; 148597b2e202SAlex Deucher u32 small_ac_platform_tdc; 148697b2e202SAlex Deucher u32 apu_tdp; 148797b2e202SAlex Deucher u32 dgpu_tdp; 148897b2e202SAlex Deucher u32 dgpu_ulv_power; 148997b2e202SAlex Deucher u32 tj_max; 149097b2e202SAlex Deucher }; 149197b2e202SAlex Deucher 149297b2e202SAlex Deucher struct amdgpu_cac_tdp_table { 149397b2e202SAlex Deucher u16 tdp; 149497b2e202SAlex Deucher u16 configurable_tdp; 149597b2e202SAlex Deucher u16 tdc; 149697b2e202SAlex Deucher u16 battery_power_limit; 149797b2e202SAlex Deucher u16 small_power_limit; 149897b2e202SAlex Deucher u16 low_cac_leakage; 149997b2e202SAlex Deucher u16 high_cac_leakage; 150097b2e202SAlex Deucher u16 maximum_power_delivery_limit; 150197b2e202SAlex Deucher }; 150297b2e202SAlex Deucher 150397b2e202SAlex Deucher struct amdgpu_dpm_dynamic_state { 150497b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk; 150597b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk; 150697b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk; 150797b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk; 150897b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk; 150997b2e202SAlex Deucher struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table; 151097b2e202SAlex Deucher struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table; 151197b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table; 151297b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table; 151397b2e202SAlex Deucher struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk; 151497b2e202SAlex Deucher struct amdgpu_clock_array valid_sclk_values; 151597b2e202SAlex Deucher struct amdgpu_clock_array valid_mclk_values; 151697b2e202SAlex Deucher struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc; 151797b2e202SAlex Deucher struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac; 151897b2e202SAlex Deucher u32 mclk_sclk_ratio; 151997b2e202SAlex Deucher u32 sclk_mclk_delta; 152097b2e202SAlex Deucher u16 vddc_vddci_delta; 152197b2e202SAlex Deucher u16 min_vddc_for_pcie_gen2; 152297b2e202SAlex Deucher struct amdgpu_cac_leakage_table cac_leakage_table; 152397b2e202SAlex Deucher struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table; 152497b2e202SAlex Deucher struct amdgpu_ppm_table *ppm_table; 152597b2e202SAlex Deucher struct amdgpu_cac_tdp_table *cac_tdp_table; 152697b2e202SAlex Deucher }; 152797b2e202SAlex Deucher 152897b2e202SAlex Deucher struct amdgpu_dpm_fan { 152997b2e202SAlex Deucher u16 t_min; 153097b2e202SAlex Deucher u16 t_med; 153197b2e202SAlex Deucher u16 t_high; 153297b2e202SAlex Deucher u16 pwm_min; 153397b2e202SAlex Deucher u16 pwm_med; 153497b2e202SAlex Deucher u16 pwm_high; 153597b2e202SAlex Deucher u8 t_hyst; 153697b2e202SAlex Deucher u32 cycle_delay; 153797b2e202SAlex Deucher u16 t_max; 153897b2e202SAlex Deucher u8 control_mode; 153997b2e202SAlex Deucher u16 default_max_fan_pwm; 154097b2e202SAlex Deucher u16 default_fan_output_sensitivity; 154197b2e202SAlex Deucher u16 fan_output_sensitivity; 154297b2e202SAlex Deucher bool ucode_fan_control; 154397b2e202SAlex Deucher }; 154497b2e202SAlex Deucher 154597b2e202SAlex Deucher enum amdgpu_pcie_gen { 154697b2e202SAlex Deucher AMDGPU_PCIE_GEN1 = 0, 154797b2e202SAlex Deucher AMDGPU_PCIE_GEN2 = 1, 154897b2e202SAlex Deucher AMDGPU_PCIE_GEN3 = 2, 154997b2e202SAlex Deucher AMDGPU_PCIE_GEN_INVALID = 0xffff 155097b2e202SAlex Deucher }; 155197b2e202SAlex Deucher 155297b2e202SAlex Deucher enum amdgpu_dpm_forced_level { 155397b2e202SAlex Deucher AMDGPU_DPM_FORCED_LEVEL_AUTO = 0, 155497b2e202SAlex Deucher AMDGPU_DPM_FORCED_LEVEL_LOW = 1, 155597b2e202SAlex Deucher AMDGPU_DPM_FORCED_LEVEL_HIGH = 2, 1556f3898ea1SEric Huang AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3, 155797b2e202SAlex Deucher }; 155897b2e202SAlex Deucher 155997b2e202SAlex Deucher struct amdgpu_vce_state { 156097b2e202SAlex Deucher /* vce clocks */ 156197b2e202SAlex Deucher u32 evclk; 156297b2e202SAlex Deucher u32 ecclk; 156397b2e202SAlex Deucher /* gpu clocks */ 156497b2e202SAlex Deucher u32 sclk; 156597b2e202SAlex Deucher u32 mclk; 156697b2e202SAlex Deucher u8 clk_idx; 156797b2e202SAlex Deucher u8 pstate; 156897b2e202SAlex Deucher }; 156997b2e202SAlex Deucher 157097b2e202SAlex Deucher struct amdgpu_dpm_funcs { 157197b2e202SAlex Deucher int (*get_temperature)(struct amdgpu_device *adev); 157297b2e202SAlex Deucher int (*pre_set_power_state)(struct amdgpu_device *adev); 157397b2e202SAlex Deucher int (*set_power_state)(struct amdgpu_device *adev); 157497b2e202SAlex Deucher void (*post_set_power_state)(struct amdgpu_device *adev); 157597b2e202SAlex Deucher void (*display_configuration_changed)(struct amdgpu_device *adev); 157697b2e202SAlex Deucher u32 (*get_sclk)(struct amdgpu_device *adev, bool low); 157797b2e202SAlex Deucher u32 (*get_mclk)(struct amdgpu_device *adev, bool low); 157897b2e202SAlex Deucher void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps); 157997b2e202SAlex Deucher void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m); 158097b2e202SAlex Deucher int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level); 158197b2e202SAlex Deucher bool (*vblank_too_short)(struct amdgpu_device *adev); 158297b2e202SAlex Deucher void (*powergate_uvd)(struct amdgpu_device *adev, bool gate); 1583b7a07769SSonny Jiang void (*powergate_vce)(struct amdgpu_device *adev, bool gate); 158497b2e202SAlex Deucher void (*enable_bapm)(struct amdgpu_device *adev, bool enable); 158597b2e202SAlex Deucher void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode); 158697b2e202SAlex Deucher u32 (*get_fan_control_mode)(struct amdgpu_device *adev); 158797b2e202SAlex Deucher int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed); 158897b2e202SAlex Deucher int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed); 1589c85e299fSEric Huang int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask); 1590c85e299fSEric Huang int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf); 15918b2e574dSEric Huang int (*get_sclk_od)(struct amdgpu_device *adev); 15928b2e574dSEric Huang int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value); 1593f2bdc05fSEric Huang int (*get_mclk_od)(struct amdgpu_device *adev); 1594f2bdc05fSEric Huang int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value); 159597b2e202SAlex Deucher }; 159697b2e202SAlex Deucher 159797b2e202SAlex Deucher struct amdgpu_dpm { 159897b2e202SAlex Deucher struct amdgpu_ps *ps; 159997b2e202SAlex Deucher /* number of valid power states */ 160097b2e202SAlex Deucher int num_ps; 160197b2e202SAlex Deucher /* current power state that is active */ 160297b2e202SAlex Deucher struct amdgpu_ps *current_ps; 160397b2e202SAlex Deucher /* requested power state */ 160497b2e202SAlex Deucher struct amdgpu_ps *requested_ps; 160597b2e202SAlex Deucher /* boot up power state */ 160697b2e202SAlex Deucher struct amdgpu_ps *boot_ps; 160797b2e202SAlex Deucher /* default uvd power state */ 160897b2e202SAlex Deucher struct amdgpu_ps *uvd_ps; 160997b2e202SAlex Deucher /* vce requirements */ 161097b2e202SAlex Deucher struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS]; 161197b2e202SAlex Deucher enum amdgpu_vce_level vce_level; 16123a2c788dSRex Zhu enum amd_pm_state_type state; 16133a2c788dSRex Zhu enum amd_pm_state_type user_state; 161497b2e202SAlex Deucher u32 platform_caps; 161597b2e202SAlex Deucher u32 voltage_response_time; 161697b2e202SAlex Deucher u32 backbias_response_time; 161797b2e202SAlex Deucher void *priv; 161897b2e202SAlex Deucher u32 new_active_crtcs; 161997b2e202SAlex Deucher int new_active_crtc_count; 162097b2e202SAlex Deucher u32 current_active_crtcs; 162197b2e202SAlex Deucher int current_active_crtc_count; 162297b2e202SAlex Deucher struct amdgpu_dpm_dynamic_state dyn_state; 162397b2e202SAlex Deucher struct amdgpu_dpm_fan fan; 162497b2e202SAlex Deucher u32 tdp_limit; 162597b2e202SAlex Deucher u32 near_tdp_limit; 162697b2e202SAlex Deucher u32 near_tdp_limit_adjusted; 162797b2e202SAlex Deucher u32 sq_ramping_threshold; 162897b2e202SAlex Deucher u32 cac_leakage; 162997b2e202SAlex Deucher u16 tdp_od_limit; 163097b2e202SAlex Deucher u32 tdp_adjustment; 163197b2e202SAlex Deucher u16 load_line_slope; 163297b2e202SAlex Deucher bool power_control; 163397b2e202SAlex Deucher bool ac_power; 163497b2e202SAlex Deucher /* special states active */ 163597b2e202SAlex Deucher bool thermal_active; 163697b2e202SAlex Deucher bool uvd_active; 163797b2e202SAlex Deucher bool vce_active; 163897b2e202SAlex Deucher /* thermal handling */ 163997b2e202SAlex Deucher struct amdgpu_dpm_thermal thermal; 164097b2e202SAlex Deucher /* forced levels */ 164197b2e202SAlex Deucher enum amdgpu_dpm_forced_level forced_level; 164297b2e202SAlex Deucher }; 164397b2e202SAlex Deucher 164497b2e202SAlex Deucher struct amdgpu_pm { 164597b2e202SAlex Deucher struct mutex mutex; 164697b2e202SAlex Deucher u32 current_sclk; 164797b2e202SAlex Deucher u32 current_mclk; 164897b2e202SAlex Deucher u32 default_sclk; 164997b2e202SAlex Deucher u32 default_mclk; 165097b2e202SAlex Deucher struct amdgpu_i2c_chan *i2c_bus; 165197b2e202SAlex Deucher /* internal thermal controller on rv6xx+ */ 165297b2e202SAlex Deucher enum amdgpu_int_thermal_type int_thermal_type; 165397b2e202SAlex Deucher struct device *int_hwmon_dev; 165497b2e202SAlex Deucher /* fan control parameters */ 165597b2e202SAlex Deucher bool no_fan; 165697b2e202SAlex Deucher u8 fan_pulses_per_revolution; 165797b2e202SAlex Deucher u8 fan_min_rpm; 165897b2e202SAlex Deucher u8 fan_max_rpm; 165997b2e202SAlex Deucher /* dpm */ 166097b2e202SAlex Deucher bool dpm_enabled; 1661c86f5ebfSAlex Deucher bool sysfs_initialized; 166297b2e202SAlex Deucher struct amdgpu_dpm dpm; 166397b2e202SAlex Deucher const struct firmware *fw; /* SMC firmware */ 166497b2e202SAlex Deucher uint32_t fw_version; 166597b2e202SAlex Deucher const struct amdgpu_dpm_funcs *funcs; 1666d0dd7f0cSAlex Deucher uint32_t pcie_gen_mask; 1667d0dd7f0cSAlex Deucher uint32_t pcie_mlw_mask; 16687fb72a1fSRex Zhu struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */ 166997b2e202SAlex Deucher }; 167097b2e202SAlex Deucher 1671d0dd7f0cSAlex Deucher void amdgpu_get_pcie_info(struct amdgpu_device *adev); 1672d0dd7f0cSAlex Deucher 167397b2e202SAlex Deucher /* 167497b2e202SAlex Deucher * UVD 167597b2e202SAlex Deucher */ 1676c0365541SArindam Nath #define AMDGPU_DEFAULT_UVD_HANDLES 10 1677c0365541SArindam Nath #define AMDGPU_MAX_UVD_HANDLES 40 1678c0365541SArindam Nath #define AMDGPU_UVD_STACK_SIZE (200*1024) 1679c0365541SArindam Nath #define AMDGPU_UVD_HEAP_SIZE (256*1024) 1680c0365541SArindam Nath #define AMDGPU_UVD_SESSION_SIZE (50*1024) 168197b2e202SAlex Deucher #define AMDGPU_UVD_FIRMWARE_OFFSET 256 168297b2e202SAlex Deucher 168397b2e202SAlex Deucher struct amdgpu_uvd { 168497b2e202SAlex Deucher struct amdgpu_bo *vcpu_bo; 168597b2e202SAlex Deucher void *cpu_addr; 168697b2e202SAlex Deucher uint64_t gpu_addr; 1687562e2689SSonny Jiang unsigned fw_version; 16883f99dd81SLeo Liu void *saved_bo; 1689c0365541SArindam Nath unsigned max_handles; 169097b2e202SAlex Deucher atomic_t handles[AMDGPU_MAX_UVD_HANDLES]; 169197b2e202SAlex Deucher struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES]; 169297b2e202SAlex Deucher struct delayed_work idle_work; 169397b2e202SAlex Deucher const struct firmware *fw; /* UVD firmware */ 169497b2e202SAlex Deucher struct amdgpu_ring ring; 169597b2e202SAlex Deucher struct amdgpu_irq_src irq; 169697b2e202SAlex Deucher bool address_64_bit; 16974cb5877cSChristian König bool use_ctx_buf; 1698ead833ecSChristian König struct amd_sched_entity entity; 1699fc0b3b90SChunming Zhou uint32_t srbm_soft_reset; 170097b2e202SAlex Deucher }; 170197b2e202SAlex Deucher 170297b2e202SAlex Deucher /* 170397b2e202SAlex Deucher * VCE 170497b2e202SAlex Deucher */ 170597b2e202SAlex Deucher #define AMDGPU_MAX_VCE_HANDLES 16 170697b2e202SAlex Deucher #define AMDGPU_VCE_FIRMWARE_OFFSET 256 170797b2e202SAlex Deucher 17086a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0) 17096a585777SAlex Deucher #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1) 17106a585777SAlex Deucher 171197b2e202SAlex Deucher struct amdgpu_vce { 171297b2e202SAlex Deucher struct amdgpu_bo *vcpu_bo; 171397b2e202SAlex Deucher uint64_t gpu_addr; 171497b2e202SAlex Deucher unsigned fw_version; 171597b2e202SAlex Deucher unsigned fb_version; 171697b2e202SAlex Deucher atomic_t handles[AMDGPU_MAX_VCE_HANDLES]; 171797b2e202SAlex Deucher struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES]; 1718f1689ec1SChristian König uint32_t img_size[AMDGPU_MAX_VCE_HANDLES]; 171997b2e202SAlex Deucher struct delayed_work idle_work; 1720ebff485eSChristian König struct mutex idle_mutex; 172197b2e202SAlex Deucher const struct firmware *fw; /* VCE firmware */ 172297b2e202SAlex Deucher struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS]; 172397b2e202SAlex Deucher struct amdgpu_irq_src irq; 17246a585777SAlex Deucher unsigned harvest_config; 1725c594989cSChristian König struct amd_sched_entity entity; 1726115933a5SChunming Zhou uint32_t srbm_soft_reset; 172797b2e202SAlex Deucher }; 172897b2e202SAlex Deucher 172997b2e202SAlex Deucher /* 173097b2e202SAlex Deucher * SDMA 173197b2e202SAlex Deucher */ 1732c113ea1cSAlex Deucher struct amdgpu_sdma_instance { 173397b2e202SAlex Deucher /* SDMA firmware */ 173497b2e202SAlex Deucher const struct firmware *fw; 173597b2e202SAlex Deucher uint32_t fw_version; 1736cfa2104fSJammy Zhou uint32_t feature_version; 173797b2e202SAlex Deucher 173897b2e202SAlex Deucher struct amdgpu_ring ring; 173918111de0SJammy Zhou bool burst_nop; 174097b2e202SAlex Deucher }; 174197b2e202SAlex Deucher 1742c113ea1cSAlex Deucher struct amdgpu_sdma { 1743c113ea1cSAlex Deucher struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES]; 1744c113ea1cSAlex Deucher struct amdgpu_irq_src trap_irq; 1745c113ea1cSAlex Deucher struct amdgpu_irq_src illegal_inst_irq; 1746c113ea1cSAlex Deucher int num_instances; 1747e702a680SChunming Zhou uint32_t srbm_soft_reset; 1748c113ea1cSAlex Deucher }; 1749c113ea1cSAlex Deucher 175097b2e202SAlex Deucher /* 175197b2e202SAlex Deucher * Firmware 175297b2e202SAlex Deucher */ 175397b2e202SAlex Deucher struct amdgpu_firmware { 175497b2e202SAlex Deucher struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM]; 175597b2e202SAlex Deucher bool smu_load; 175697b2e202SAlex Deucher struct amdgpu_bo *fw_buf; 175797b2e202SAlex Deucher unsigned int fw_size; 175897b2e202SAlex Deucher }; 175997b2e202SAlex Deucher 176097b2e202SAlex Deucher /* 176197b2e202SAlex Deucher * Benchmarking 176297b2e202SAlex Deucher */ 176397b2e202SAlex Deucher void amdgpu_benchmark(struct amdgpu_device *adev, int test_number); 176497b2e202SAlex Deucher 176597b2e202SAlex Deucher 176697b2e202SAlex Deucher /* 176797b2e202SAlex Deucher * Testing 176897b2e202SAlex Deucher */ 176997b2e202SAlex Deucher void amdgpu_test_moves(struct amdgpu_device *adev); 177097b2e202SAlex Deucher void amdgpu_test_ring_sync(struct amdgpu_device *adev, 177197b2e202SAlex Deucher struct amdgpu_ring *cpA, 177297b2e202SAlex Deucher struct amdgpu_ring *cpB); 177397b2e202SAlex Deucher void amdgpu_test_syncing(struct amdgpu_device *adev); 177497b2e202SAlex Deucher 177597b2e202SAlex Deucher /* 177697b2e202SAlex Deucher * MMU Notifier 177797b2e202SAlex Deucher */ 177897b2e202SAlex Deucher #if defined(CONFIG_MMU_NOTIFIER) 177997b2e202SAlex Deucher int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr); 178097b2e202SAlex Deucher void amdgpu_mn_unregister(struct amdgpu_bo *bo); 178197b2e202SAlex Deucher #else 17821d1106b0SHarry Wentland static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) 178397b2e202SAlex Deucher { 178497b2e202SAlex Deucher return -ENODEV; 178597b2e202SAlex Deucher } 17861d1106b0SHarry Wentland static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {} 178797b2e202SAlex Deucher #endif 178897b2e202SAlex Deucher 178997b2e202SAlex Deucher /* 179097b2e202SAlex Deucher * Debugfs 179197b2e202SAlex Deucher */ 179297b2e202SAlex Deucher struct amdgpu_debugfs { 179306ab6832SNils Wallménius const struct drm_info_list *files; 179497b2e202SAlex Deucher unsigned num_files; 179597b2e202SAlex Deucher }; 179697b2e202SAlex Deucher 179797b2e202SAlex Deucher int amdgpu_debugfs_add_files(struct amdgpu_device *adev, 179806ab6832SNils Wallménius const struct drm_info_list *files, 179997b2e202SAlex Deucher unsigned nfiles); 180097b2e202SAlex Deucher int amdgpu_debugfs_fence_init(struct amdgpu_device *adev); 180197b2e202SAlex Deucher 180297b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS) 180397b2e202SAlex Deucher int amdgpu_debugfs_init(struct drm_minor *minor); 180497b2e202SAlex Deucher void amdgpu_debugfs_cleanup(struct drm_minor *minor); 180597b2e202SAlex Deucher #endif 180697b2e202SAlex Deucher 180750ab2533SHuang Rui int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev); 180850ab2533SHuang Rui 180997b2e202SAlex Deucher /* 181097b2e202SAlex Deucher * amdgpu smumgr functions 181197b2e202SAlex Deucher */ 181297b2e202SAlex Deucher struct amdgpu_smumgr_funcs { 181397b2e202SAlex Deucher int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype); 181497b2e202SAlex Deucher int (*request_smu_load_fw)(struct amdgpu_device *adev); 181597b2e202SAlex Deucher int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype); 181697b2e202SAlex Deucher }; 181797b2e202SAlex Deucher 181897b2e202SAlex Deucher /* 181997b2e202SAlex Deucher * amdgpu smumgr 182097b2e202SAlex Deucher */ 182197b2e202SAlex Deucher struct amdgpu_smumgr { 182297b2e202SAlex Deucher struct amdgpu_bo *toc_buf; 182397b2e202SAlex Deucher struct amdgpu_bo *smu_buf; 182497b2e202SAlex Deucher /* asic priv smu data */ 182597b2e202SAlex Deucher void *priv; 182697b2e202SAlex Deucher spinlock_t smu_lock; 182797b2e202SAlex Deucher /* smumgr functions */ 182897b2e202SAlex Deucher const struct amdgpu_smumgr_funcs *smumgr_funcs; 182997b2e202SAlex Deucher /* ucode loading complete flag */ 183097b2e202SAlex Deucher uint32_t fw_flags; 183197b2e202SAlex Deucher }; 183297b2e202SAlex Deucher 183397b2e202SAlex Deucher /* 183497b2e202SAlex Deucher * ASIC specific register table accessible by UMD 183597b2e202SAlex Deucher */ 183697b2e202SAlex Deucher struct amdgpu_allowed_register_entry { 183797b2e202SAlex Deucher uint32_t reg_offset; 183897b2e202SAlex Deucher bool untouched; 183997b2e202SAlex Deucher bool grbm_indexed; 184097b2e202SAlex Deucher }; 184197b2e202SAlex Deucher 184297b2e202SAlex Deucher /* 184397b2e202SAlex Deucher * ASIC specific functions. 184497b2e202SAlex Deucher */ 184597b2e202SAlex Deucher struct amdgpu_asic_funcs { 184697b2e202SAlex Deucher bool (*read_disabled_bios)(struct amdgpu_device *adev); 18477946b878SAlex Deucher bool (*read_bios_from_rom)(struct amdgpu_device *adev, 18487946b878SAlex Deucher u8 *bios, u32 length_bytes); 184997b2e202SAlex Deucher int (*read_register)(struct amdgpu_device *adev, u32 se_num, 185097b2e202SAlex Deucher u32 sh_num, u32 reg_offset, u32 *value); 185197b2e202SAlex Deucher void (*set_vga_state)(struct amdgpu_device *adev, bool state); 185297b2e202SAlex Deucher int (*reset)(struct amdgpu_device *adev); 185397b2e202SAlex Deucher /* get the reference clock */ 185497b2e202SAlex Deucher u32 (*get_xclk)(struct amdgpu_device *adev); 185597b2e202SAlex Deucher /* MM block clocks */ 185697b2e202SAlex Deucher int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk); 185797b2e202SAlex Deucher int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk); 1858048765adSAndres Rodriguez /* query virtual capabilities */ 1859048765adSAndres Rodriguez u32 (*get_virtual_caps)(struct amdgpu_device *adev); 186097b2e202SAlex Deucher }; 186197b2e202SAlex Deucher 186297b2e202SAlex Deucher /* 186397b2e202SAlex Deucher * IOCTL. 186497b2e202SAlex Deucher */ 186597b2e202SAlex Deucher int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, 186697b2e202SAlex Deucher struct drm_file *filp); 186797b2e202SAlex Deucher int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, 186897b2e202SAlex Deucher struct drm_file *filp); 186997b2e202SAlex Deucher 187097b2e202SAlex Deucher int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, 187197b2e202SAlex Deucher struct drm_file *filp); 187297b2e202SAlex Deucher int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, 187397b2e202SAlex Deucher struct drm_file *filp); 187497b2e202SAlex Deucher int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data, 187597b2e202SAlex Deucher struct drm_file *filp); 187697b2e202SAlex Deucher int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data, 187797b2e202SAlex Deucher struct drm_file *filp); 187897b2e202SAlex Deucher int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, 187997b2e202SAlex Deucher struct drm_file *filp); 188097b2e202SAlex Deucher int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, 188197b2e202SAlex Deucher struct drm_file *filp); 188297b2e202SAlex Deucher int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 188397b2e202SAlex Deucher int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 188497b2e202SAlex Deucher 188597b2e202SAlex Deucher int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data, 188697b2e202SAlex Deucher struct drm_file *filp); 188797b2e202SAlex Deucher 188897b2e202SAlex Deucher /* VRAM scratch page for HDP bug, default vram page */ 188997b2e202SAlex Deucher struct amdgpu_vram_scratch { 189097b2e202SAlex Deucher struct amdgpu_bo *robj; 189197b2e202SAlex Deucher volatile uint32_t *ptr; 189297b2e202SAlex Deucher u64 gpu_addr; 189397b2e202SAlex Deucher }; 189497b2e202SAlex Deucher 189597b2e202SAlex Deucher /* 189697b2e202SAlex Deucher * ACPI 189797b2e202SAlex Deucher */ 189897b2e202SAlex Deucher struct amdgpu_atif_notification_cfg { 189997b2e202SAlex Deucher bool enabled; 190097b2e202SAlex Deucher int command_code; 190197b2e202SAlex Deucher }; 190297b2e202SAlex Deucher 190397b2e202SAlex Deucher struct amdgpu_atif_notifications { 190497b2e202SAlex Deucher bool display_switch; 190597b2e202SAlex Deucher bool expansion_mode_change; 190697b2e202SAlex Deucher bool thermal_state; 190797b2e202SAlex Deucher bool forced_power_state; 190897b2e202SAlex Deucher bool system_power_state; 190997b2e202SAlex Deucher bool display_conf_change; 191097b2e202SAlex Deucher bool px_gfx_switch; 191197b2e202SAlex Deucher bool brightness_change; 191297b2e202SAlex Deucher bool dgpu_display_event; 191397b2e202SAlex Deucher }; 191497b2e202SAlex Deucher 191597b2e202SAlex Deucher struct amdgpu_atif_functions { 191697b2e202SAlex Deucher bool system_params; 191797b2e202SAlex Deucher bool sbios_requests; 191897b2e202SAlex Deucher bool select_active_disp; 191997b2e202SAlex Deucher bool lid_state; 192097b2e202SAlex Deucher bool get_tv_standard; 192197b2e202SAlex Deucher bool set_tv_standard; 192297b2e202SAlex Deucher bool get_panel_expansion_mode; 192397b2e202SAlex Deucher bool set_panel_expansion_mode; 192497b2e202SAlex Deucher bool temperature_change; 192597b2e202SAlex Deucher bool graphics_device_types; 192697b2e202SAlex Deucher }; 192797b2e202SAlex Deucher 192897b2e202SAlex Deucher struct amdgpu_atif { 192997b2e202SAlex Deucher struct amdgpu_atif_notifications notifications; 193097b2e202SAlex Deucher struct amdgpu_atif_functions functions; 193197b2e202SAlex Deucher struct amdgpu_atif_notification_cfg notification_cfg; 193297b2e202SAlex Deucher struct amdgpu_encoder *encoder_for_bl; 193397b2e202SAlex Deucher }; 193497b2e202SAlex Deucher 193597b2e202SAlex Deucher struct amdgpu_atcs_functions { 193697b2e202SAlex Deucher bool get_ext_state; 193797b2e202SAlex Deucher bool pcie_perf_req; 193897b2e202SAlex Deucher bool pcie_dev_rdy; 193997b2e202SAlex Deucher bool pcie_bus_width; 194097b2e202SAlex Deucher }; 194197b2e202SAlex Deucher 194297b2e202SAlex Deucher struct amdgpu_atcs { 194397b2e202SAlex Deucher struct amdgpu_atcs_functions functions; 194497b2e202SAlex Deucher }; 194597b2e202SAlex Deucher 194697b2e202SAlex Deucher /* 1947d03846afSChunming Zhou * CGS 1948d03846afSChunming Zhou */ 1949110e6f26SDave Airlie struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev); 1950110e6f26SDave Airlie void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device); 1951a8fe58ceSMaruthi Bayyavarapu 1952a8fe58ceSMaruthi Bayyavarapu 19537e471e6fSAlex Deucher /* GPU virtualization */ 1954048765adSAndres Rodriguez #define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0) 1955048765adSAndres Rodriguez #define AMDGPU_VIRT_CAPS_IS_VF (1 << 1) 19567e471e6fSAlex Deucher struct amdgpu_virtualization { 19577e471e6fSAlex Deucher bool supports_sr_iov; 1958048765adSAndres Rodriguez bool is_virtual; 1959048765adSAndres Rodriguez u32 caps; 19607e471e6fSAlex Deucher }; 19617e471e6fSAlex Deucher 1962a8fe58ceSMaruthi Bayyavarapu /* 196397b2e202SAlex Deucher * Core structure, functions and helpers. 196497b2e202SAlex Deucher */ 196597b2e202SAlex Deucher typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t); 196697b2e202SAlex Deucher typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 196797b2e202SAlex Deucher 196897b2e202SAlex Deucher typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t); 196997b2e202SAlex Deucher typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t); 197097b2e202SAlex Deucher 19718faf0e08SAlex Deucher struct amdgpu_ip_block_status { 19728faf0e08SAlex Deucher bool valid; 19738faf0e08SAlex Deucher bool sw; 19748faf0e08SAlex Deucher bool hw; 197563fbf42fSChunming Zhou bool hang; 19768faf0e08SAlex Deucher }; 19778faf0e08SAlex Deucher 197897b2e202SAlex Deucher struct amdgpu_device { 197997b2e202SAlex Deucher struct device *dev; 198097b2e202SAlex Deucher struct drm_device *ddev; 198197b2e202SAlex Deucher struct pci_dev *pdev; 198297b2e202SAlex Deucher 1983a8fe58ceSMaruthi Bayyavarapu #ifdef CONFIG_DRM_AMD_ACP 1984a8fe58ceSMaruthi Bayyavarapu struct amdgpu_acp acp; 1985a8fe58ceSMaruthi Bayyavarapu #endif 1986a8fe58ceSMaruthi Bayyavarapu 198797b2e202SAlex Deucher /* ASIC */ 19882f7d10b3SJammy Zhou enum amd_asic_type asic_type; 198997b2e202SAlex Deucher uint32_t family; 199097b2e202SAlex Deucher uint32_t rev_id; 199197b2e202SAlex Deucher uint32_t external_rev_id; 199297b2e202SAlex Deucher unsigned long flags; 199397b2e202SAlex Deucher int usec_timeout; 199497b2e202SAlex Deucher const struct amdgpu_asic_funcs *asic_funcs; 199597b2e202SAlex Deucher bool shutdown; 199697b2e202SAlex Deucher bool need_dma32; 199797b2e202SAlex Deucher bool accel_working; 199897b2e202SAlex Deucher struct work_struct reset_work; 199997b2e202SAlex Deucher struct notifier_block acpi_nb; 200097b2e202SAlex Deucher struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS]; 200197b2e202SAlex Deucher struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 200297b2e202SAlex Deucher unsigned debugfs_count; 200397b2e202SAlex Deucher #if defined(CONFIG_DEBUG_FS) 2004adcec288STom St Denis struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; 200597b2e202SAlex Deucher #endif 200697b2e202SAlex Deucher struct amdgpu_atif atif; 200797b2e202SAlex Deucher struct amdgpu_atcs atcs; 200897b2e202SAlex Deucher struct mutex srbm_mutex; 200997b2e202SAlex Deucher /* GRBM index mutex. Protects concurrent access to GRBM index */ 201097b2e202SAlex Deucher struct mutex grbm_idx_mutex; 201197b2e202SAlex Deucher struct dev_pm_domain vga_pm_domain; 201297b2e202SAlex Deucher bool have_disp_power_ref; 201397b2e202SAlex Deucher 201497b2e202SAlex Deucher /* BIOS */ 201597b2e202SAlex Deucher uint8_t *bios; 201697b2e202SAlex Deucher bool is_atom_bios; 201797b2e202SAlex Deucher struct amdgpu_bo *stollen_vga_memory; 201897b2e202SAlex Deucher uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH]; 201997b2e202SAlex Deucher 202097b2e202SAlex Deucher /* Register/doorbell mmio */ 202197b2e202SAlex Deucher resource_size_t rmmio_base; 202297b2e202SAlex Deucher resource_size_t rmmio_size; 202397b2e202SAlex Deucher void __iomem *rmmio; 202497b2e202SAlex Deucher /* protects concurrent MM_INDEX/DATA based register access */ 202597b2e202SAlex Deucher spinlock_t mmio_idx_lock; 202697b2e202SAlex Deucher /* protects concurrent SMC based register access */ 202797b2e202SAlex Deucher spinlock_t smc_idx_lock; 202897b2e202SAlex Deucher amdgpu_rreg_t smc_rreg; 202997b2e202SAlex Deucher amdgpu_wreg_t smc_wreg; 203097b2e202SAlex Deucher /* protects concurrent PCIE register access */ 203197b2e202SAlex Deucher spinlock_t pcie_idx_lock; 203297b2e202SAlex Deucher amdgpu_rreg_t pcie_rreg; 203397b2e202SAlex Deucher amdgpu_wreg_t pcie_wreg; 203497b2e202SAlex Deucher /* protects concurrent UVD register access */ 203597b2e202SAlex Deucher spinlock_t uvd_ctx_idx_lock; 203697b2e202SAlex Deucher amdgpu_rreg_t uvd_ctx_rreg; 203797b2e202SAlex Deucher amdgpu_wreg_t uvd_ctx_wreg; 203897b2e202SAlex Deucher /* protects concurrent DIDT register access */ 203997b2e202SAlex Deucher spinlock_t didt_idx_lock; 204097b2e202SAlex Deucher amdgpu_rreg_t didt_rreg; 204197b2e202SAlex Deucher amdgpu_wreg_t didt_wreg; 2042ccdbb20aSRex Zhu /* protects concurrent gc_cac register access */ 2043ccdbb20aSRex Zhu spinlock_t gc_cac_idx_lock; 2044ccdbb20aSRex Zhu amdgpu_rreg_t gc_cac_rreg; 2045ccdbb20aSRex Zhu amdgpu_wreg_t gc_cac_wreg; 204697b2e202SAlex Deucher /* protects concurrent ENDPOINT (audio) register access */ 204797b2e202SAlex Deucher spinlock_t audio_endpt_idx_lock; 204897b2e202SAlex Deucher amdgpu_block_rreg_t audio_endpt_rreg; 204997b2e202SAlex Deucher amdgpu_block_wreg_t audio_endpt_wreg; 205097b2e202SAlex Deucher void __iomem *rio_mem; 205197b2e202SAlex Deucher resource_size_t rio_mem_size; 205297b2e202SAlex Deucher struct amdgpu_doorbell doorbell; 205397b2e202SAlex Deucher 205497b2e202SAlex Deucher /* clock/pll info */ 205597b2e202SAlex Deucher struct amdgpu_clock clock; 205697b2e202SAlex Deucher 205797b2e202SAlex Deucher /* MC */ 205897b2e202SAlex Deucher struct amdgpu_mc mc; 205997b2e202SAlex Deucher struct amdgpu_gart gart; 206097b2e202SAlex Deucher struct amdgpu_dummy_page dummy_page; 206197b2e202SAlex Deucher struct amdgpu_vm_manager vm_manager; 206297b2e202SAlex Deucher 206397b2e202SAlex Deucher /* memory management */ 206497b2e202SAlex Deucher struct amdgpu_mman mman; 206597b2e202SAlex Deucher struct amdgpu_vram_scratch vram_scratch; 206697b2e202SAlex Deucher struct amdgpu_wb wb; 206797b2e202SAlex Deucher atomic64_t vram_usage; 206897b2e202SAlex Deucher atomic64_t vram_vis_usage; 206997b2e202SAlex Deucher atomic64_t gtt_usage; 207097b2e202SAlex Deucher atomic64_t num_bytes_moved; 2071dbd5ed60SChristian König atomic64_t num_evictions; 2072d94aed5aSMarek Olšák atomic_t gpu_reset_counter; 207397b2e202SAlex Deucher 207497b2e202SAlex Deucher /* display */ 20759accf2fdSEmily Deng bool enable_virtual_display; 207697b2e202SAlex Deucher struct amdgpu_mode_info mode_info; 207797b2e202SAlex Deucher struct work_struct hotplug_work; 207897b2e202SAlex Deucher struct amdgpu_irq_src crtc_irq; 207997b2e202SAlex Deucher struct amdgpu_irq_src pageflip_irq; 208097b2e202SAlex Deucher struct amdgpu_irq_src hpd_irq; 208197b2e202SAlex Deucher 208297b2e202SAlex Deucher /* rings */ 208376bf0db5SChristian König u64 fence_context; 208497b2e202SAlex Deucher unsigned num_rings; 208597b2e202SAlex Deucher struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; 208697b2e202SAlex Deucher bool ib_pool_ready; 208797b2e202SAlex Deucher struct amdgpu_sa_manager ring_tmp_bo; 208897b2e202SAlex Deucher 208997b2e202SAlex Deucher /* interrupts */ 209097b2e202SAlex Deucher struct amdgpu_irq irq; 209197b2e202SAlex Deucher 20921f7371b2SAlex Deucher /* powerplay */ 20931f7371b2SAlex Deucher struct amd_powerplay powerplay; 2094e61710c5SJammy Zhou bool pp_enabled; 2095f3898ea1SEric Huang bool pp_force_state_enabled; 20961f7371b2SAlex Deucher 209797b2e202SAlex Deucher /* dpm */ 209897b2e202SAlex Deucher struct amdgpu_pm pm; 209997b2e202SAlex Deucher u32 cg_flags; 210097b2e202SAlex Deucher u32 pg_flags; 210197b2e202SAlex Deucher 210297b2e202SAlex Deucher /* amdgpu smumgr */ 210397b2e202SAlex Deucher struct amdgpu_smumgr smu; 210497b2e202SAlex Deucher 210597b2e202SAlex Deucher /* gfx */ 210697b2e202SAlex Deucher struct amdgpu_gfx gfx; 210797b2e202SAlex Deucher 210897b2e202SAlex Deucher /* sdma */ 2109c113ea1cSAlex Deucher struct amdgpu_sdma sdma; 211097b2e202SAlex Deucher 211197b2e202SAlex Deucher /* uvd */ 211297b2e202SAlex Deucher struct amdgpu_uvd uvd; 211397b2e202SAlex Deucher 211497b2e202SAlex Deucher /* vce */ 211597b2e202SAlex Deucher struct amdgpu_vce vce; 211697b2e202SAlex Deucher 211797b2e202SAlex Deucher /* firmwares */ 211897b2e202SAlex Deucher struct amdgpu_firmware firmware; 211997b2e202SAlex Deucher 212097b2e202SAlex Deucher /* GDS */ 212197b2e202SAlex Deucher struct amdgpu_gds gds; 212297b2e202SAlex Deucher 212397b2e202SAlex Deucher const struct amdgpu_ip_block_version *ip_blocks; 212497b2e202SAlex Deucher int num_ip_blocks; 21258faf0e08SAlex Deucher struct amdgpu_ip_block_status *ip_block_status; 212697b2e202SAlex Deucher struct mutex mn_lock; 212797b2e202SAlex Deucher DECLARE_HASHTABLE(mn_hash, 7); 212897b2e202SAlex Deucher 212997b2e202SAlex Deucher /* tracking pinned memory */ 213097b2e202SAlex Deucher u64 vram_pin_size; 2131e131b914SChunming Zhou u64 invisible_pin_size; 213297b2e202SAlex Deucher u64 gart_pin_size; 2133130e0371SOded Gabbay 2134130e0371SOded Gabbay /* amdkfd interface */ 2135130e0371SOded Gabbay struct kfd_dev *kfd; 213623ca0e4eSChunming Zhou 21377e471e6fSAlex Deucher struct amdgpu_virtualization virtualization; 213897b2e202SAlex Deucher }; 213997b2e202SAlex Deucher 214097b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev); 214197b2e202SAlex Deucher int amdgpu_device_init(struct amdgpu_device *adev, 214297b2e202SAlex Deucher struct drm_device *ddev, 214397b2e202SAlex Deucher struct pci_dev *pdev, 214497b2e202SAlex Deucher uint32_t flags); 214597b2e202SAlex Deucher void amdgpu_device_fini(struct amdgpu_device *adev); 214697b2e202SAlex Deucher int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); 214797b2e202SAlex Deucher 214897b2e202SAlex Deucher uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, 214997b2e202SAlex Deucher bool always_indirect); 215097b2e202SAlex Deucher void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, 215197b2e202SAlex Deucher bool always_indirect); 215297b2e202SAlex Deucher u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg); 215397b2e202SAlex Deucher void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v); 215497b2e202SAlex Deucher 215597b2e202SAlex Deucher u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index); 215697b2e202SAlex Deucher void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v); 215797b2e202SAlex Deucher 215897b2e202SAlex Deucher /* 215997b2e202SAlex Deucher * Registers read & write functions. 216097b2e202SAlex Deucher */ 216197b2e202SAlex Deucher #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false) 216297b2e202SAlex Deucher #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true) 216397b2e202SAlex Deucher #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false)) 216497b2e202SAlex Deucher #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false) 216597b2e202SAlex Deucher #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true) 216697b2e202SAlex Deucher #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 216797b2e202SAlex Deucher #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 216897b2e202SAlex Deucher #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg)) 216997b2e202SAlex Deucher #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v)) 217097b2e202SAlex Deucher #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg)) 217197b2e202SAlex Deucher #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v)) 217297b2e202SAlex Deucher #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg)) 217397b2e202SAlex Deucher #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v)) 217497b2e202SAlex Deucher #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg)) 217597b2e202SAlex Deucher #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v)) 2176ccdbb20aSRex Zhu #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg)) 2177ccdbb20aSRex Zhu #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v)) 217897b2e202SAlex Deucher #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg)) 217997b2e202SAlex Deucher #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v)) 218097b2e202SAlex Deucher #define WREG32_P(reg, val, mask) \ 218197b2e202SAlex Deucher do { \ 218297b2e202SAlex Deucher uint32_t tmp_ = RREG32(reg); \ 218397b2e202SAlex Deucher tmp_ &= (mask); \ 218497b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 218597b2e202SAlex Deucher WREG32(reg, tmp_); \ 218697b2e202SAlex Deucher } while (0) 218797b2e202SAlex Deucher #define WREG32_AND(reg, and) WREG32_P(reg, 0, and) 218897b2e202SAlex Deucher #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or)) 218997b2e202SAlex Deucher #define WREG32_PLL_P(reg, val, mask) \ 219097b2e202SAlex Deucher do { \ 219197b2e202SAlex Deucher uint32_t tmp_ = RREG32_PLL(reg); \ 219297b2e202SAlex Deucher tmp_ &= (mask); \ 219397b2e202SAlex Deucher tmp_ |= ((val) & ~(mask)); \ 219497b2e202SAlex Deucher WREG32_PLL(reg, tmp_); \ 219597b2e202SAlex Deucher } while (0) 219697b2e202SAlex Deucher #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false)) 219797b2e202SAlex Deucher #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg)) 219897b2e202SAlex Deucher #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v)) 219997b2e202SAlex Deucher 220097b2e202SAlex Deucher #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index)) 220197b2e202SAlex Deucher #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v)) 220297b2e202SAlex Deucher 220397b2e202SAlex Deucher #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT 220497b2e202SAlex Deucher #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK 220597b2e202SAlex Deucher 220697b2e202SAlex Deucher #define REG_SET_FIELD(orig_val, reg, field, field_val) \ 220797b2e202SAlex Deucher (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \ 220897b2e202SAlex Deucher (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) 220997b2e202SAlex Deucher 221097b2e202SAlex Deucher #define REG_GET_FIELD(value, reg, field) \ 221197b2e202SAlex Deucher (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field)) 221297b2e202SAlex Deucher 221361cb8cefSTom St Denis #define WREG32_FIELD(reg, field, val) \ 221461cb8cefSTom St Denis WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 221561cb8cefSTom St Denis 221697b2e202SAlex Deucher /* 221797b2e202SAlex Deucher * BIOS helpers. 221897b2e202SAlex Deucher */ 221997b2e202SAlex Deucher #define RBIOS8(i) (adev->bios[i]) 222097b2e202SAlex Deucher #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8)) 222197b2e202SAlex Deucher #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16)) 222297b2e202SAlex Deucher 222397b2e202SAlex Deucher /* 222497b2e202SAlex Deucher * RING helpers. 222597b2e202SAlex Deucher */ 222697b2e202SAlex Deucher static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v) 222797b2e202SAlex Deucher { 222897b2e202SAlex Deucher if (ring->count_dw <= 0) 222986c2b790SJammy Zhou DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n"); 223097b2e202SAlex Deucher ring->ring[ring->wptr++] = v; 223197b2e202SAlex Deucher ring->wptr &= ring->ptr_mask; 223297b2e202SAlex Deucher ring->count_dw--; 223397b2e202SAlex Deucher } 223497b2e202SAlex Deucher 2235c113ea1cSAlex Deucher static inline struct amdgpu_sdma_instance * 2236c113ea1cSAlex Deucher amdgpu_get_sdma_instance(struct amdgpu_ring *ring) 22374b2f7e2cSJammy Zhou { 22384b2f7e2cSJammy Zhou struct amdgpu_device *adev = ring->adev; 22394b2f7e2cSJammy Zhou int i; 22404b2f7e2cSJammy Zhou 2241c113ea1cSAlex Deucher for (i = 0; i < adev->sdma.num_instances; i++) 2242c113ea1cSAlex Deucher if (&adev->sdma.instance[i].ring == ring) 22434b2f7e2cSJammy Zhou break; 22444b2f7e2cSJammy Zhou 22454b2f7e2cSJammy Zhou if (i < AMDGPU_MAX_SDMA_INSTANCES) 2246c113ea1cSAlex Deucher return &adev->sdma.instance[i]; 22474b2f7e2cSJammy Zhou else 22484b2f7e2cSJammy Zhou return NULL; 22494b2f7e2cSJammy Zhou } 22504b2f7e2cSJammy Zhou 225197b2e202SAlex Deucher /* 225297b2e202SAlex Deucher * ASICs macro. 225397b2e202SAlex Deucher */ 225497b2e202SAlex Deucher #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state)) 225597b2e202SAlex Deucher #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev)) 225697b2e202SAlex Deucher #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev)) 225797b2e202SAlex Deucher #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d)) 225897b2e202SAlex Deucher #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec)) 2259048765adSAndres Rodriguez #define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev))) 226097b2e202SAlex Deucher #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev)) 22617946b878SAlex Deucher #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l)) 226297b2e202SAlex Deucher #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v))) 226397b2e202SAlex Deucher #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid)) 226497b2e202SAlex Deucher #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags)) 226597b2e202SAlex Deucher #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count))) 2266b07c9d2aSChristian König #define amdgpu_vm_write_pte(adev, ib, pa, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pa), (pe), (addr), (count), (incr), (flags))) 226797b2e202SAlex 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))) 226897b2e202SAlex Deucher #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib))) 226997b2e202SAlex Deucher #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r)) 2270bbec97aaSChristian König #define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t)) 227197b2e202SAlex Deucher #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r)) 227297b2e202SAlex Deucher #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r)) 227397b2e202SAlex Deucher #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r)) 2274d88bf583SChristian König #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c)) 2275b8c7b39eSChristian König #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r)) 227697b2e202SAlex Deucher #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr)) 2277890ee23fSChunming Zhou #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags)) 227897b2e202SAlex 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)) 2279d2edb07bSChristian König #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r)) 228011afbde8SChunming Zhou #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r)) 22819e5d5309SChristian König #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib))) 228203ccf481SMonk Liu #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r)) 228303ccf481SMonk Liu #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o)) 228497b2e202SAlex Deucher #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev)) 228597b2e202SAlex Deucher #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv)) 228697b2e202SAlex Deucher #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev)) 228797b2e202SAlex Deucher #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r)) 228897b2e202SAlex Deucher #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc)) 228997b2e202SAlex Deucher #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc)) 229097b2e202SAlex Deucher #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev)) 229197b2e202SAlex Deucher #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l)) 229297b2e202SAlex Deucher #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e)) 229397b2e202SAlex Deucher #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h)) 229497b2e202SAlex Deucher #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h)) 229597b2e202SAlex Deucher #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev)) 229697b2e202SAlex Deucher #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev)) 2297cb9e59d7SAlex Deucher #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async)) 229897b2e202SAlex Deucher #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos)) 229997b2e202SAlex Deucher #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c)) 230097b2e202SAlex 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)) 230197b2e202SAlex Deucher #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s)) 230297b2e202SAlex Deucher #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s)) 2303c7ae72c0SChunming Zhou #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b)) 23046e7a3840SChunming Zhou #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) 230597b2e202SAlex Deucher #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev)) 230697b2e202SAlex Deucher #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev)) 230797b2e202SAlex Deucher #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev)) 230897b2e202SAlex Deucher #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev)) 230997b2e202SAlex Deucher #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps)) 231097b2e202SAlex Deucher #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev)) 231197b2e202SAlex Deucher #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e)) 2312b95e31fdSAlex Deucher #define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev)) 23139559ef5bSTom St Denis #define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance)) 23143af76f23SRex Zhu 23153af76f23SRex Zhu #define amdgpu_dpm_get_temperature(adev) \ 23164b5ece24SEric Huang ((adev)->pp_enabled ? \ 23173af76f23SRex Zhu (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \ 23184b5ece24SEric Huang (adev)->pm.funcs->get_temperature((adev))) 23193af76f23SRex Zhu 23203af76f23SRex Zhu #define amdgpu_dpm_set_fan_control_mode(adev, m) \ 23214b5ece24SEric Huang ((adev)->pp_enabled ? \ 23223af76f23SRex Zhu (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \ 23234b5ece24SEric Huang (adev)->pm.funcs->set_fan_control_mode((adev), (m))) 23243af76f23SRex Zhu 23253af76f23SRex Zhu #define amdgpu_dpm_get_fan_control_mode(adev) \ 23264b5ece24SEric Huang ((adev)->pp_enabled ? \ 23273af76f23SRex Zhu (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \ 23284b5ece24SEric Huang (adev)->pm.funcs->get_fan_control_mode((adev))) 23293af76f23SRex Zhu 23303af76f23SRex Zhu #define amdgpu_dpm_set_fan_speed_percent(adev, s) \ 23314b5ece24SEric Huang ((adev)->pp_enabled ? \ 23323af76f23SRex Zhu (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \ 23334b5ece24SEric Huang (adev)->pm.funcs->set_fan_speed_percent((adev), (s))) 23343af76f23SRex Zhu 23353af76f23SRex Zhu #define amdgpu_dpm_get_fan_speed_percent(adev, s) \ 23364b5ece24SEric Huang ((adev)->pp_enabled ? \ 23373af76f23SRex Zhu (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \ 23384b5ece24SEric Huang (adev)->pm.funcs->get_fan_speed_percent((adev), (s))) 233997b2e202SAlex Deucher 23401b5708ffSRex Zhu #define amdgpu_dpm_get_sclk(adev, l) \ 23414b5ece24SEric Huang ((adev)->pp_enabled ? \ 23421b5708ffSRex Zhu (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \ 23434b5ece24SEric Huang (adev)->pm.funcs->get_sclk((adev), (l))) 23441b5708ffSRex Zhu 23451b5708ffSRex Zhu #define amdgpu_dpm_get_mclk(adev, l) \ 23464b5ece24SEric Huang ((adev)->pp_enabled ? \ 23471b5708ffSRex Zhu (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \ 23484b5ece24SEric Huang (adev)->pm.funcs->get_mclk((adev), (l))) 23491b5708ffSRex Zhu 23501b5708ffSRex Zhu 23511b5708ffSRex Zhu #define amdgpu_dpm_force_performance_level(adev, l) \ 23524b5ece24SEric Huang ((adev)->pp_enabled ? \ 23531b5708ffSRex Zhu (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \ 23544b5ece24SEric Huang (adev)->pm.funcs->force_performance_level((adev), (l))) 23551b5708ffSRex Zhu 23561b5708ffSRex Zhu #define amdgpu_dpm_powergate_uvd(adev, g) \ 23574b5ece24SEric Huang ((adev)->pp_enabled ? \ 23581b5708ffSRex Zhu (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \ 23594b5ece24SEric Huang (adev)->pm.funcs->powergate_uvd((adev), (g))) 23601b5708ffSRex Zhu 23611b5708ffSRex Zhu #define amdgpu_dpm_powergate_vce(adev, g) \ 23624b5ece24SEric Huang ((adev)->pp_enabled ? \ 23631b5708ffSRex Zhu (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \ 23644b5ece24SEric Huang (adev)->pm.funcs->powergate_vce((adev), (g))) 23651b5708ffSRex Zhu 23661b5708ffSRex Zhu #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \ 23674b5ece24SEric Huang ((adev)->pp_enabled ? \ 23681b5708ffSRex Zhu (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \ 23694b5ece24SEric Huang (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m))) 23701b5708ffSRex Zhu 23711b5708ffSRex Zhu #define amdgpu_dpm_get_current_power_state(adev) \ 23721b5708ffSRex Zhu (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle) 23731b5708ffSRex Zhu 23741b5708ffSRex Zhu #define amdgpu_dpm_get_performance_level(adev) \ 23751b5708ffSRex Zhu (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle) 23761b5708ffSRex Zhu 2377f3898ea1SEric Huang #define amdgpu_dpm_get_pp_num_states(adev, data) \ 2378f3898ea1SEric Huang (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data) 2379f3898ea1SEric Huang 2380f3898ea1SEric Huang #define amdgpu_dpm_get_pp_table(adev, table) \ 2381f3898ea1SEric Huang (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table) 2382f3898ea1SEric Huang 2383f3898ea1SEric Huang #define amdgpu_dpm_set_pp_table(adev, buf, size) \ 2384f3898ea1SEric Huang (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size) 2385f3898ea1SEric Huang 2386f3898ea1SEric Huang #define amdgpu_dpm_print_clock_levels(adev, type, buf) \ 2387f3898ea1SEric Huang (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf) 2388f3898ea1SEric Huang 2389f3898ea1SEric Huang #define amdgpu_dpm_force_clock_level(adev, type, level) \ 2390f3898ea1SEric Huang (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level) 2391f3898ea1SEric Huang 2392428bafa8SEric Huang #define amdgpu_dpm_get_sclk_od(adev) \ 2393428bafa8SEric Huang (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle) 2394428bafa8SEric Huang 2395428bafa8SEric Huang #define amdgpu_dpm_set_sclk_od(adev, value) \ 2396428bafa8SEric Huang (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value) 2397428bafa8SEric Huang 2398f2bdc05fSEric Huang #define amdgpu_dpm_get_mclk_od(adev) \ 2399f2bdc05fSEric Huang ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle)) 2400f2bdc05fSEric Huang 2401f2bdc05fSEric Huang #define amdgpu_dpm_set_mclk_od(adev, value) \ 2402f2bdc05fSEric Huang ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value)) 2403f2bdc05fSEric Huang 24041b5708ffSRex Zhu #define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \ 24051b5708ffSRex Zhu (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output)) 240697b2e202SAlex Deucher 240797b2e202SAlex Deucher #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a)) 240897b2e202SAlex Deucher 240997b2e202SAlex Deucher /* Common functions */ 241097b2e202SAlex Deucher int amdgpu_gpu_reset(struct amdgpu_device *adev); 241197b2e202SAlex Deucher void amdgpu_pci_config_reset(struct amdgpu_device *adev); 241297b2e202SAlex Deucher bool amdgpu_card_posted(struct amdgpu_device *adev); 241397b2e202SAlex Deucher void amdgpu_update_display_priority(struct amdgpu_device *adev); 2414d5fc5e82SChunming Zhou 241597b2e202SAlex Deucher int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data); 241697b2e202SAlex Deucher int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type, 241797b2e202SAlex Deucher u32 ip_instance, u32 ring, 241897b2e202SAlex Deucher struct amdgpu_ring **out_ring); 241997b2e202SAlex Deucher void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain); 242097b2e202SAlex Deucher bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo); 24212f568dbdSChristian König int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages); 242297b2e202SAlex Deucher int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, 242397b2e202SAlex Deucher uint32_t flags); 242497b2e202SAlex Deucher bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm); 2425cc325d19SChristian König struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm); 2426d7006964SChristian König bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start, 2427d7006964SChristian König unsigned long end); 24282f568dbdSChristian König bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm, 24292f568dbdSChristian König int *last_invalidated); 243097b2e202SAlex Deucher bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm); 243197b2e202SAlex Deucher uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, 243297b2e202SAlex Deucher struct ttm_mem_reg *mem); 243397b2e202SAlex Deucher void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base); 243497b2e202SAlex Deucher void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc); 243597b2e202SAlex Deucher void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size); 2436a693e050SKen Wang u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev); 2437a693e050SKen Wang int amdgpu_ttm_global_init(struct amdgpu_device *adev); 243897b2e202SAlex Deucher void amdgpu_program_register_sequence(struct amdgpu_device *adev, 243997b2e202SAlex Deucher const u32 *registers, 244097b2e202SAlex Deucher const u32 array_size); 244197b2e202SAlex Deucher 244297b2e202SAlex Deucher bool amdgpu_device_is_px(struct drm_device *dev); 244397b2e202SAlex Deucher /* atpx handler */ 244497b2e202SAlex Deucher #if defined(CONFIG_VGA_SWITCHEROO) 244597b2e202SAlex Deucher void amdgpu_register_atpx_handler(void); 244697b2e202SAlex Deucher void amdgpu_unregister_atpx_handler(void); 2447a78fe133SAlex Deucher bool amdgpu_has_atpx_dgpu_power_cntl(void); 24482f5af82eSAlex Deucher bool amdgpu_is_atpx_hybrid(void); 244997b2e202SAlex Deucher #else 245097b2e202SAlex Deucher static inline void amdgpu_register_atpx_handler(void) {} 245197b2e202SAlex Deucher static inline void amdgpu_unregister_atpx_handler(void) {} 2452a78fe133SAlex Deucher static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; } 24532f5af82eSAlex Deucher static inline bool amdgpu_is_atpx_hybrid(void) { return false; } 245497b2e202SAlex Deucher #endif 245597b2e202SAlex Deucher 245697b2e202SAlex Deucher /* 245797b2e202SAlex Deucher * KMS 245897b2e202SAlex Deucher */ 245997b2e202SAlex Deucher extern const struct drm_ioctl_desc amdgpu_ioctls_kms[]; 2460f498d9edSNils Wallménius extern const int amdgpu_max_kms_ioctl; 246197b2e202SAlex Deucher 246297b2e202SAlex Deucher int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags); 246397b2e202SAlex Deucher int amdgpu_driver_unload_kms(struct drm_device *dev); 246497b2e202SAlex Deucher void amdgpu_driver_lastclose_kms(struct drm_device *dev); 246597b2e202SAlex Deucher int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv); 246697b2e202SAlex Deucher void amdgpu_driver_postclose_kms(struct drm_device *dev, 246797b2e202SAlex Deucher struct drm_file *file_priv); 246897b2e202SAlex Deucher void amdgpu_driver_preclose_kms(struct drm_device *dev, 246997b2e202SAlex Deucher struct drm_file *file_priv); 247097b2e202SAlex Deucher int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon); 247197b2e202SAlex Deucher int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon); 247288e72717SThierry Reding u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe); 247388e72717SThierry Reding int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe); 247488e72717SThierry Reding void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe); 247588e72717SThierry Reding int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, 247697b2e202SAlex Deucher int *max_error, 247797b2e202SAlex Deucher struct timeval *vblank_time, 247897b2e202SAlex Deucher unsigned flags); 247997b2e202SAlex Deucher long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd, 248097b2e202SAlex Deucher unsigned long arg); 248197b2e202SAlex Deucher 248297b2e202SAlex Deucher /* 248397b2e202SAlex Deucher * functions used by amdgpu_encoder.c 248497b2e202SAlex Deucher */ 248597b2e202SAlex Deucher struct amdgpu_afmt_acr { 248697b2e202SAlex Deucher u32 clock; 248797b2e202SAlex Deucher 248897b2e202SAlex Deucher int n_32khz; 248997b2e202SAlex Deucher int cts_32khz; 249097b2e202SAlex Deucher 249197b2e202SAlex Deucher int n_44_1khz; 249297b2e202SAlex Deucher int cts_44_1khz; 249397b2e202SAlex Deucher 249497b2e202SAlex Deucher int n_48khz; 249597b2e202SAlex Deucher int cts_48khz; 249697b2e202SAlex Deucher 249797b2e202SAlex Deucher }; 249897b2e202SAlex Deucher 249997b2e202SAlex Deucher struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock); 250097b2e202SAlex Deucher 250197b2e202SAlex Deucher /* amdgpu_acpi.c */ 250297b2e202SAlex Deucher #if defined(CONFIG_ACPI) 250397b2e202SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev); 250497b2e202SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev); 250597b2e202SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev); 250697b2e202SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev, 250797b2e202SAlex Deucher u8 perf_req, bool advertise); 250897b2e202SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev); 250997b2e202SAlex Deucher #else 251097b2e202SAlex Deucher static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; } 251197b2e202SAlex Deucher static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { } 251297b2e202SAlex Deucher #endif 251397b2e202SAlex Deucher 251497b2e202SAlex Deucher struct amdgpu_bo_va_mapping * 251597b2e202SAlex Deucher amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser, 251697b2e202SAlex Deucher uint64_t addr, struct amdgpu_bo **bo); 251797b2e202SAlex Deucher 251897b2e202SAlex Deucher #include "amdgpu_object.h" 251997b2e202SAlex Deucher #endif 2520