Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * Copyright 2009 Jerome Glisse. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Dave Airlie |
| 25 | * Alex Deucher |
| 26 | * Jerome Glisse |
| 27 | */ |
| 28 | #ifndef __AMDGPU_H__ |
| 29 | #define __AMDGPU_H__ |
| 30 | |
| 31 | #include <linux/atomic.h> |
| 32 | #include <linux/wait.h> |
| 33 | #include <linux/list.h> |
| 34 | #include <linux/kref.h> |
| 35 | #include <linux/interval_tree.h> |
| 36 | #include <linux/hashtable.h> |
| 37 | #include <linux/fence.h> |
| 38 | |
| 39 | #include <ttm/ttm_bo_api.h> |
| 40 | #include <ttm/ttm_bo_driver.h> |
| 41 | #include <ttm/ttm_placement.h> |
| 42 | #include <ttm/ttm_module.h> |
| 43 | #include <ttm/ttm_execbuf_util.h> |
| 44 | |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 45 | #include <drm/drmP.h> |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 46 | #include <drm/drm_gem.h> |
Chunming Zhou | 7e5a547 | 2015-04-24 17:37:30 +0800 | [diff] [blame] | 47 | #include <drm/amdgpu_drm.h> |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 48 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 49 | #include "amd_shared.h" |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 50 | #include "amdgpu_mode.h" |
| 51 | #include "amdgpu_ih.h" |
| 52 | #include "amdgpu_irq.h" |
| 53 | #include "amdgpu_ucode.h" |
| 54 | #include "amdgpu_gds.h" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 55 | #include "amd_powerplay.h" |
Maruthi Bayyavarapu | a8fe58c | 2015-09-22 17:05:20 -0400 | [diff] [blame] | 56 | #include "amdgpu_acp.h" |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 57 | |
Alex Deucher | b80d847 | 2015-08-16 22:55:02 -0400 | [diff] [blame] | 58 | #include "gpu_scheduler.h" |
| 59 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 60 | /* |
| 61 | * Modules parameters. |
| 62 | */ |
| 63 | extern int amdgpu_modeset; |
| 64 | extern int amdgpu_vram_limit; |
| 65 | extern int amdgpu_gart_size; |
| 66 | extern int amdgpu_benchmarking; |
| 67 | extern int amdgpu_testing; |
| 68 | extern int amdgpu_audio; |
| 69 | extern int amdgpu_disp_priority; |
| 70 | extern int amdgpu_hw_i2c; |
| 71 | extern int amdgpu_pcie_gen2; |
| 72 | extern int amdgpu_msi; |
| 73 | extern int amdgpu_lockup_timeout; |
| 74 | extern int amdgpu_dpm; |
| 75 | extern int amdgpu_smc_load_fw; |
| 76 | extern int amdgpu_aspm; |
| 77 | extern int amdgpu_runtime_pm; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 78 | extern unsigned amdgpu_ip_block_mask; |
| 79 | extern int amdgpu_bapm; |
| 80 | extern int amdgpu_deep_color; |
| 81 | extern int amdgpu_vm_size; |
| 82 | extern int amdgpu_vm_block_size; |
Christian König | d9c1315 | 2015-09-28 12:31:26 +0200 | [diff] [blame] | 83 | extern int amdgpu_vm_fault_stop; |
Christian König | b495bd3 | 2015-09-10 14:00:35 +0200 | [diff] [blame] | 84 | extern int amdgpu_vm_debug; |
Jammy Zhou | 1333f72 | 2015-07-30 16:36:58 +0800 | [diff] [blame] | 85 | extern int amdgpu_sched_jobs; |
Jammy Zhou | 4afcb30 | 2015-07-30 16:44:05 +0800 | [diff] [blame] | 86 | extern int amdgpu_sched_hw_submission; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 87 | extern int amdgpu_powerplay; |
Huang Rui | 6bb6b29 | 2016-05-24 13:47:05 +0800 | [diff] [blame] | 88 | extern int amdgpu_powercontainment; |
Alex Deucher | cd474ba | 2016-02-04 10:21:23 -0500 | [diff] [blame] | 89 | extern unsigned amdgpu_pcie_gen_cap; |
| 90 | extern unsigned amdgpu_pcie_lane_cap; |
Nicolai Hähnle | 395d1fb | 2016-06-02 12:32:07 +0200 | [diff] [blame] | 91 | extern unsigned amdgpu_cg_mask; |
| 92 | extern unsigned amdgpu_pg_mask; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 93 | |
Chunming Zhou | 4b559c9 | 2015-07-21 15:53:04 +0800 | [diff] [blame] | 94 | #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000 |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 95 | #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */ |
| 96 | #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) |
| 97 | /* AMDGPU_IB_POOL_SIZE must be a power of 2 */ |
| 98 | #define AMDGPU_IB_POOL_SIZE 16 |
| 99 | #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32 |
| 100 | #define AMDGPUFB_CONN_LIMIT 4 |
| 101 | #define AMDGPU_BIOS_NUM_SCRATCH 8 |
| 102 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 103 | /* max number of rings */ |
| 104 | #define AMDGPU_MAX_RINGS 16 |
| 105 | #define AMDGPU_MAX_GFX_RINGS 1 |
| 106 | #define AMDGPU_MAX_COMPUTE_RINGS 8 |
| 107 | #define AMDGPU_MAX_VCE_RINGS 2 |
| 108 | |
Jammy Zhou | 36f523a | 2015-09-01 12:54:27 +0800 | [diff] [blame] | 109 | /* max number of IP instances */ |
| 110 | #define AMDGPU_MAX_SDMA_INSTANCES 2 |
| 111 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 112 | /* hardcode that limit for now */ |
| 113 | #define AMDGPU_VA_RESERVED_SIZE (8 << 20) |
| 114 | |
| 115 | /* hard reset data */ |
| 116 | #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b |
| 117 | |
| 118 | /* reset flags */ |
| 119 | #define AMDGPU_RESET_GFX (1 << 0) |
| 120 | #define AMDGPU_RESET_COMPUTE (1 << 1) |
| 121 | #define AMDGPU_RESET_DMA (1 << 2) |
| 122 | #define AMDGPU_RESET_CP (1 << 3) |
| 123 | #define AMDGPU_RESET_GRBM (1 << 4) |
| 124 | #define AMDGPU_RESET_DMA1 (1 << 5) |
| 125 | #define AMDGPU_RESET_RLC (1 << 6) |
| 126 | #define AMDGPU_RESET_SEM (1 << 7) |
| 127 | #define AMDGPU_RESET_IH (1 << 8) |
| 128 | #define AMDGPU_RESET_VMC (1 << 9) |
| 129 | #define AMDGPU_RESET_MC (1 << 10) |
| 130 | #define AMDGPU_RESET_DISPLAY (1 << 11) |
| 131 | #define AMDGPU_RESET_UVD (1 << 12) |
| 132 | #define AMDGPU_RESET_VCE (1 << 13) |
| 133 | #define AMDGPU_RESET_VCE1 (1 << 14) |
| 134 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 135 | /* GFX current status */ |
| 136 | #define AMDGPU_GFX_NORMAL_MODE 0x00000000L |
| 137 | #define AMDGPU_GFX_SAFE_MODE 0x00000001L |
| 138 | #define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L |
| 139 | #define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L |
| 140 | #define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L |
| 141 | |
| 142 | /* max cursor sizes (in pixels) */ |
| 143 | #define CIK_CURSOR_WIDTH 128 |
| 144 | #define CIK_CURSOR_HEIGHT 128 |
| 145 | |
| 146 | struct amdgpu_device; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 147 | struct amdgpu_ib; |
| 148 | struct amdgpu_vm; |
| 149 | struct amdgpu_ring; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 150 | struct amdgpu_cs_parser; |
Chunming Zhou | bb977d3 | 2015-08-18 15:16:40 +0800 | [diff] [blame] | 151 | struct amdgpu_job; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 152 | struct amdgpu_irq_src; |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 153 | struct amdgpu_fpriv; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 154 | |
| 155 | enum amdgpu_cp_irq { |
| 156 | AMDGPU_CP_IRQ_GFX_EOP = 0, |
| 157 | AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP, |
| 158 | AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP, |
| 159 | AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP, |
| 160 | AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP, |
| 161 | AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP, |
| 162 | AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP, |
| 163 | AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP, |
| 164 | AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP, |
| 165 | |
| 166 | AMDGPU_CP_IRQ_LAST |
| 167 | }; |
| 168 | |
| 169 | enum amdgpu_sdma_irq { |
| 170 | AMDGPU_SDMA_IRQ_TRAP0 = 0, |
| 171 | AMDGPU_SDMA_IRQ_TRAP1, |
| 172 | |
| 173 | AMDGPU_SDMA_IRQ_LAST |
| 174 | }; |
| 175 | |
| 176 | enum amdgpu_thermal_irq { |
| 177 | AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0, |
| 178 | AMDGPU_THERMAL_IRQ_HIGH_TO_LOW, |
| 179 | |
| 180 | AMDGPU_THERMAL_IRQ_LAST |
| 181 | }; |
| 182 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 183 | int amdgpu_set_clockgating_state(struct amdgpu_device *adev, |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 184 | enum amd_ip_block_type block_type, |
| 185 | enum amd_clockgating_state state); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 186 | int amdgpu_set_powergating_state(struct amdgpu_device *adev, |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 187 | enum amd_ip_block_type block_type, |
| 188 | enum amd_powergating_state state); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 189 | |
| 190 | struct amdgpu_ip_block_version { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 191 | enum amd_ip_block_type type; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 192 | u32 major; |
| 193 | u32 minor; |
| 194 | u32 rev; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 195 | const struct amd_ip_funcs *funcs; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev, |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 199 | enum amd_ip_block_type type, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 200 | u32 major, u32 minor); |
| 201 | |
| 202 | const struct amdgpu_ip_block_version * amdgpu_get_ip_block( |
| 203 | struct amdgpu_device *adev, |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 204 | enum amd_ip_block_type type); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 205 | |
| 206 | /* provided by hw blocks that can move/clear data. e.g., gfx or sdma */ |
| 207 | struct amdgpu_buffer_funcs { |
| 208 | /* maximum bytes in a single operation */ |
| 209 | uint32_t copy_max_bytes; |
| 210 | |
| 211 | /* number of dw to reserve per operation */ |
| 212 | unsigned copy_num_dw; |
| 213 | |
| 214 | /* used for buffer migration */ |
Chunming Zhou | c7ae72c | 2015-08-25 17:23:45 +0800 | [diff] [blame] | 215 | void (*emit_copy_buffer)(struct amdgpu_ib *ib, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 216 | /* src addr in bytes */ |
| 217 | uint64_t src_offset, |
| 218 | /* dst addr in bytes */ |
| 219 | uint64_t dst_offset, |
| 220 | /* number of byte to transfer */ |
| 221 | uint32_t byte_count); |
| 222 | |
| 223 | /* maximum bytes in a single operation */ |
| 224 | uint32_t fill_max_bytes; |
| 225 | |
| 226 | /* number of dw to reserve per operation */ |
| 227 | unsigned fill_num_dw; |
| 228 | |
| 229 | /* used for buffer clearing */ |
Chunming Zhou | 6e7a384 | 2015-08-27 13:46:09 +0800 | [diff] [blame] | 230 | void (*emit_fill_buffer)(struct amdgpu_ib *ib, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 231 | /* value to write to memory */ |
| 232 | uint32_t src_data, |
| 233 | /* dst addr in bytes */ |
| 234 | uint64_t dst_offset, |
| 235 | /* number of byte to fill */ |
| 236 | uint32_t byte_count); |
| 237 | }; |
| 238 | |
| 239 | /* provided by hw blocks that can write ptes, e.g., sdma */ |
| 240 | struct amdgpu_vm_pte_funcs { |
| 241 | /* copy pte entries from GART */ |
| 242 | void (*copy_pte)(struct amdgpu_ib *ib, |
| 243 | uint64_t pe, uint64_t src, |
| 244 | unsigned count); |
| 245 | /* write pte one entry at a time with addr mapping */ |
| 246 | void (*write_pte)(struct amdgpu_ib *ib, |
Christian König | b07c9d2 | 2015-11-30 13:26:07 +0100 | [diff] [blame] | 247 | const dma_addr_t *pages_addr, uint64_t pe, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 248 | uint64_t addr, unsigned count, |
| 249 | uint32_t incr, uint32_t flags); |
| 250 | /* for linear pte/pde updates without addr mapping */ |
| 251 | void (*set_pte_pde)(struct amdgpu_ib *ib, |
| 252 | uint64_t pe, |
| 253 | uint64_t addr, unsigned count, |
| 254 | uint32_t incr, uint32_t flags); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | /* provided by the gmc block */ |
| 258 | struct amdgpu_gart_funcs { |
| 259 | /* flush the vm tlb via mmio */ |
| 260 | void (*flush_gpu_tlb)(struct amdgpu_device *adev, |
| 261 | uint32_t vmid); |
| 262 | /* write pte/pde updates using the cpu */ |
| 263 | int (*set_pte_pde)(struct amdgpu_device *adev, |
| 264 | void *cpu_pt_addr, /* cpu addr of page table */ |
| 265 | uint32_t gpu_page_idx, /* pte/pde to update */ |
| 266 | uint64_t addr, /* addr to write into pte/pde */ |
| 267 | uint32_t flags); /* access flags */ |
| 268 | }; |
| 269 | |
| 270 | /* provided by the ih block */ |
| 271 | struct amdgpu_ih_funcs { |
| 272 | /* ring read/write ptr handling, called from interrupt context */ |
| 273 | u32 (*get_wptr)(struct amdgpu_device *adev); |
| 274 | void (*decode_iv)(struct amdgpu_device *adev, |
| 275 | struct amdgpu_iv_entry *entry); |
| 276 | void (*set_rptr)(struct amdgpu_device *adev); |
| 277 | }; |
| 278 | |
| 279 | /* provided by hw blocks that expose a ring buffer for commands */ |
| 280 | struct amdgpu_ring_funcs { |
| 281 | /* ring read/write ptr handling */ |
| 282 | u32 (*get_rptr)(struct amdgpu_ring *ring); |
| 283 | u32 (*get_wptr)(struct amdgpu_ring *ring); |
| 284 | void (*set_wptr)(struct amdgpu_ring *ring); |
| 285 | /* validating and patching of IBs */ |
| 286 | int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx); |
| 287 | /* command emit functions */ |
| 288 | void (*emit_ib)(struct amdgpu_ring *ring, |
Christian König | d88bf58 | 2016-05-06 17:50:03 +0200 | [diff] [blame] | 289 | struct amdgpu_ib *ib, |
| 290 | unsigned vm_id, bool ctx_switch); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 291 | void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr, |
Chunming Zhou | 890ee23 | 2015-06-01 14:35:03 +0800 | [diff] [blame] | 292 | uint64_t seq, unsigned flags); |
Christian König | b8c7b39 | 2016-03-01 15:42:52 +0100 | [diff] [blame] | 293 | void (*emit_pipeline_sync)(struct amdgpu_ring *ring); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 294 | void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id, |
| 295 | uint64_t pd_addr); |
Christian König | d2edb07 | 2015-05-11 14:10:34 +0200 | [diff] [blame] | 296 | void (*emit_hdp_flush)(struct amdgpu_ring *ring); |
Chunming Zhou | 11afbde | 2016-03-03 11:38:48 +0800 | [diff] [blame] | 297 | void (*emit_hdp_invalidate)(struct amdgpu_ring *ring); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 298 | void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid, |
| 299 | uint32_t gds_base, uint32_t gds_size, |
| 300 | uint32_t gws_base, uint32_t gws_size, |
| 301 | uint32_t oa_base, uint32_t oa_size); |
| 302 | /* testing functions */ |
| 303 | int (*test_ring)(struct amdgpu_ring *ring); |
| 304 | int (*test_ib)(struct amdgpu_ring *ring); |
Jammy Zhou | edff0e2 | 2015-09-01 13:04:08 +0800 | [diff] [blame] | 305 | /* insert NOP packets */ |
| 306 | void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count); |
Christian König | 9e5d5309 | 2016-01-31 12:20:55 +0100 | [diff] [blame] | 307 | /* pad the indirect buffer to the necessary number of dw */ |
| 308 | void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib); |
Monk Liu | 03ccf48 | 2016-01-14 19:07:38 +0800 | [diff] [blame] | 309 | unsigned (*init_cond_exec)(struct amdgpu_ring *ring); |
| 310 | void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | /* |
| 314 | * BIOS. |
| 315 | */ |
| 316 | bool amdgpu_get_bios(struct amdgpu_device *adev); |
| 317 | bool amdgpu_read_bios(struct amdgpu_device *adev); |
| 318 | |
| 319 | /* |
| 320 | * Dummy page |
| 321 | */ |
| 322 | struct amdgpu_dummy_page { |
| 323 | struct page *page; |
| 324 | dma_addr_t addr; |
| 325 | }; |
| 326 | int amdgpu_dummy_page_init(struct amdgpu_device *adev); |
| 327 | void amdgpu_dummy_page_fini(struct amdgpu_device *adev); |
| 328 | |
| 329 | |
| 330 | /* |
| 331 | * Clocks |
| 332 | */ |
| 333 | |
| 334 | #define AMDGPU_MAX_PPLL 3 |
| 335 | |
| 336 | struct amdgpu_clock { |
| 337 | struct amdgpu_pll ppll[AMDGPU_MAX_PPLL]; |
| 338 | struct amdgpu_pll spll; |
| 339 | struct amdgpu_pll mpll; |
| 340 | /* 10 Khz units */ |
| 341 | uint32_t default_mclk; |
| 342 | uint32_t default_sclk; |
| 343 | uint32_t default_dispclk; |
| 344 | uint32_t current_dispclk; |
| 345 | uint32_t dp_extclk; |
| 346 | uint32_t max_pixel_clock; |
| 347 | }; |
| 348 | |
| 349 | /* |
| 350 | * Fences. |
| 351 | */ |
| 352 | struct amdgpu_fence_driver { |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 353 | uint64_t gpu_addr; |
| 354 | volatile uint32_t *cpu_addr; |
| 355 | /* sync_seq is protected by ring emission lock */ |
Christian König | 742c085 | 2016-03-14 15:46:06 +0100 | [diff] [blame] | 356 | uint32_t sync_seq; |
| 357 | atomic_t last_seq; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 358 | bool initialized; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 359 | struct amdgpu_irq_src *irq_src; |
| 360 | unsigned irq_type; |
Christian König | c2776af | 2015-11-03 13:27:39 +0100 | [diff] [blame] | 361 | struct timer_list fallback_timer; |
Christian König | c89377d | 2016-03-13 19:19:48 +0100 | [diff] [blame] | 362 | unsigned num_fences_mask; |
Christian König | 4a7d74f | 2016-03-14 14:29:46 +0100 | [diff] [blame] | 363 | spinlock_t lock; |
Christian König | c89377d | 2016-03-13 19:19:48 +0100 | [diff] [blame] | 364 | struct fence **fences; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | /* some special values for the owner field */ |
| 368 | #define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul) |
| 369 | #define AMDGPU_FENCE_OWNER_VM ((void*)1ul) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 370 | |
Chunming Zhou | 890ee23 | 2015-06-01 14:35:03 +0800 | [diff] [blame] | 371 | #define AMDGPU_FENCE_FLAG_64BIT (1 << 0) |
| 372 | #define AMDGPU_FENCE_FLAG_INT (1 << 1) |
| 373 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 374 | int amdgpu_fence_driver_init(struct amdgpu_device *adev); |
| 375 | void amdgpu_fence_driver_fini(struct amdgpu_device *adev); |
| 376 | void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev); |
| 377 | |
Christian König | e6151a0 | 2016-03-15 14:52:26 +0100 | [diff] [blame] | 378 | int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, |
| 379 | unsigned num_hw_submission); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 380 | int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, |
| 381 | struct amdgpu_irq_src *irq_src, |
| 382 | unsigned irq_type); |
Alex Deucher | 5ceb54c | 2015-08-05 12:41:48 -0400 | [diff] [blame] | 383 | void amdgpu_fence_driver_suspend(struct amdgpu_device *adev); |
| 384 | void amdgpu_fence_driver_resume(struct amdgpu_device *adev); |
Christian König | 364beb2 | 2016-02-16 17:39:39 +0100 | [diff] [blame] | 385 | int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 386 | void amdgpu_fence_process(struct amdgpu_ring *ring); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 387 | int amdgpu_fence_wait_empty(struct amdgpu_ring *ring); |
| 388 | unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring); |
| 389 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 390 | /* |
| 391 | * TTM. |
| 392 | */ |
Christian König | 29b3259 | 2016-04-15 17:19:16 +0200 | [diff] [blame] | 393 | |
| 394 | #define AMDGPU_TTM_LRU_SIZE 20 |
| 395 | |
| 396 | struct amdgpu_mman_lru { |
| 397 | struct list_head *lru[TTM_NUM_MEM_TYPES]; |
| 398 | struct list_head *swap_lru; |
| 399 | }; |
| 400 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 401 | struct amdgpu_mman { |
| 402 | struct ttm_bo_global_ref bo_global_ref; |
| 403 | struct drm_global_reference mem_global_ref; |
| 404 | struct ttm_bo_device bdev; |
| 405 | bool mem_global_referenced; |
| 406 | bool initialized; |
| 407 | |
| 408 | #if defined(CONFIG_DEBUG_FS) |
| 409 | struct dentry *vram; |
| 410 | struct dentry *gtt; |
| 411 | #endif |
| 412 | |
| 413 | /* buffer handling */ |
| 414 | const struct amdgpu_buffer_funcs *buffer_funcs; |
| 415 | struct amdgpu_ring *buffer_funcs_ring; |
Christian König | 703297c | 2016-02-10 14:20:50 +0100 | [diff] [blame] | 416 | /* Scheduler entity for buffer moves */ |
| 417 | struct amd_sched_entity entity; |
Christian König | 29b3259 | 2016-04-15 17:19:16 +0200 | [diff] [blame] | 418 | |
| 419 | /* custom LRU management */ |
| 420 | struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE]; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 421 | }; |
| 422 | |
| 423 | int amdgpu_copy_buffer(struct amdgpu_ring *ring, |
| 424 | uint64_t src_offset, |
| 425 | uint64_t dst_offset, |
| 426 | uint32_t byte_count, |
| 427 | struct reservation_object *resv, |
Chunming Zhou | c7ae72c | 2015-08-25 17:23:45 +0800 | [diff] [blame] | 428 | struct fence **fence); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 429 | int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma); |
| 430 | |
| 431 | struct amdgpu_bo_list_entry { |
| 432 | struct amdgpu_bo *robj; |
| 433 | struct ttm_validate_buffer tv; |
| 434 | struct amdgpu_bo_va *bo_va; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 435 | uint32_t priority; |
Christian König | 2f568db | 2016-02-23 12:36:59 +0100 | [diff] [blame] | 436 | struct page **user_pages; |
| 437 | int user_invalidated; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | struct amdgpu_bo_va_mapping { |
| 441 | struct list_head list; |
| 442 | struct interval_tree_node it; |
| 443 | uint64_t offset; |
| 444 | uint32_t flags; |
| 445 | }; |
| 446 | |
| 447 | /* bo virtual addresses in a specific vm */ |
| 448 | struct amdgpu_bo_va { |
| 449 | /* protected by bo being reserved */ |
| 450 | struct list_head bo_list; |
Chunming Zhou | bb1e38a4 | 2015-08-03 18:19:38 +0800 | [diff] [blame] | 451 | struct fence *last_pt_update; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 452 | unsigned ref_count; |
| 453 | |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 454 | /* protected by vm mutex and spinlock */ |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 455 | struct list_head vm_status; |
| 456 | |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 457 | /* mappings for this bo_va */ |
| 458 | struct list_head invalids; |
| 459 | struct list_head valids; |
| 460 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 461 | /* constant after initialization */ |
| 462 | struct amdgpu_vm *vm; |
| 463 | struct amdgpu_bo *bo; |
| 464 | }; |
| 465 | |
Chunming Zhou | 7e5a547 | 2015-04-24 17:37:30 +0800 | [diff] [blame] | 466 | #define AMDGPU_GEM_DOMAIN_MAX 0x3 |
| 467 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 468 | struct amdgpu_bo { |
| 469 | /* Protected by gem.mutex */ |
| 470 | struct list_head list; |
| 471 | /* Protected by tbo.reserved */ |
Christian König | 1ea863f | 2015-12-18 22:13:12 +0100 | [diff] [blame] | 472 | u32 prefered_domains; |
| 473 | u32 allowed_domains; |
Chunming Zhou | 7e5a547 | 2015-04-24 17:37:30 +0800 | [diff] [blame] | 474 | struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1]; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 475 | struct ttm_placement placement; |
| 476 | struct ttm_buffer_object tbo; |
| 477 | struct ttm_bo_kmap_obj kmap; |
| 478 | u64 flags; |
| 479 | unsigned pin_count; |
| 480 | void *kptr; |
| 481 | u64 tiling_flags; |
| 482 | u64 metadata_flags; |
| 483 | void *metadata; |
| 484 | u32 metadata_size; |
| 485 | /* list of all virtual address to which this bo |
| 486 | * is associated to |
| 487 | */ |
| 488 | struct list_head va; |
| 489 | /* Constant after initialization */ |
| 490 | struct amdgpu_device *adev; |
| 491 | struct drm_gem_object gem_base; |
Christian König | 82b9c55 | 2015-11-27 16:49:00 +0100 | [diff] [blame] | 492 | struct amdgpu_bo *parent; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 493 | |
| 494 | struct ttm_bo_kmap_obj dma_buf_vmap; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 495 | struct amdgpu_mn *mn; |
| 496 | struct list_head mn_list; |
| 497 | }; |
| 498 | #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base) |
| 499 | |
| 500 | void amdgpu_gem_object_free(struct drm_gem_object *obj); |
| 501 | int amdgpu_gem_object_open(struct drm_gem_object *obj, |
| 502 | struct drm_file *file_priv); |
| 503 | void amdgpu_gem_object_close(struct drm_gem_object *obj, |
| 504 | struct drm_file *file_priv); |
| 505 | unsigned long amdgpu_gem_timeout(uint64_t timeout_ns); |
| 506 | struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj); |
Christian König | 4d9c514 | 2016-05-03 18:46:19 +0200 | [diff] [blame] | 507 | struct drm_gem_object * |
| 508 | amdgpu_gem_prime_import_sg_table(struct drm_device *dev, |
| 509 | struct dma_buf_attachment *attach, |
| 510 | struct sg_table *sg); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 511 | struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev, |
| 512 | struct drm_gem_object *gobj, |
| 513 | int flags); |
| 514 | int amdgpu_gem_prime_pin(struct drm_gem_object *obj); |
| 515 | void amdgpu_gem_prime_unpin(struct drm_gem_object *obj); |
| 516 | struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *); |
| 517 | void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj); |
| 518 | void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); |
| 519 | int amdgpu_gem_debugfs_init(struct amdgpu_device *adev); |
| 520 | |
| 521 | /* sub-allocation manager, it has to be protected by another lock. |
| 522 | * By conception this is an helper for other part of the driver |
| 523 | * like the indirect buffer or semaphore, which both have their |
| 524 | * locking. |
| 525 | * |
| 526 | * Principe is simple, we keep a list of sub allocation in offset |
| 527 | * order (first entry has offset == 0, last entry has the highest |
| 528 | * offset). |
| 529 | * |
| 530 | * When allocating new object we first check if there is room at |
| 531 | * the end total_size - (last_object_offset + last_object_size) >= |
| 532 | * alloc_size. If so we allocate new object there. |
| 533 | * |
| 534 | * When there is not enough room at the end, we start waiting for |
| 535 | * each sub object until we reach object_offset+object_size >= |
| 536 | * alloc_size, this object then become the sub object we return. |
| 537 | * |
| 538 | * Alignment can't be bigger than page size. |
| 539 | * |
| 540 | * Hole are not considered for allocation to keep things simple. |
| 541 | * Assumption is that there won't be hole (all object on same |
| 542 | * alignment). |
| 543 | */ |
Christian König | 6ba60b8 | 2016-03-11 14:50:08 +0100 | [diff] [blame] | 544 | |
| 545 | #define AMDGPU_SA_NUM_FENCE_LISTS 32 |
| 546 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 547 | struct amdgpu_sa_manager { |
| 548 | wait_queue_head_t wq; |
| 549 | struct amdgpu_bo *bo; |
| 550 | struct list_head *hole; |
Christian König | 6ba60b8 | 2016-03-11 14:50:08 +0100 | [diff] [blame] | 551 | struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS]; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 552 | struct list_head olist; |
| 553 | unsigned size; |
| 554 | uint64_t gpu_addr; |
| 555 | void *cpu_ptr; |
| 556 | uint32_t domain; |
| 557 | uint32_t align; |
| 558 | }; |
| 559 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 560 | /* sub-allocation buffer */ |
| 561 | struct amdgpu_sa_bo { |
| 562 | struct list_head olist; |
| 563 | struct list_head flist; |
| 564 | struct amdgpu_sa_manager *manager; |
| 565 | unsigned soffset; |
| 566 | unsigned eoffset; |
Chunming Zhou | 4ce9891 | 2015-08-19 16:41:19 +0800 | [diff] [blame] | 567 | struct fence *fence; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 568 | }; |
| 569 | |
| 570 | /* |
| 571 | * GEM objects. |
| 572 | */ |
Christian König | 418aa0c | 2016-02-15 16:59:57 +0100 | [diff] [blame] | 573 | void amdgpu_gem_force_release(struct amdgpu_device *adev); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 574 | int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, |
| 575 | int alignment, u32 initial_domain, |
| 576 | u64 flags, bool kernel, |
| 577 | struct drm_gem_object **obj); |
| 578 | |
| 579 | int amdgpu_mode_dumb_create(struct drm_file *file_priv, |
| 580 | struct drm_device *dev, |
| 581 | struct drm_mode_create_dumb *args); |
| 582 | int amdgpu_mode_dumb_mmap(struct drm_file *filp, |
| 583 | struct drm_device *dev, |
| 584 | uint32_t handle, uint64_t *offset_p); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 585 | /* |
| 586 | * Synchronization |
| 587 | */ |
| 588 | struct amdgpu_sync { |
Christian König | f91b3a6 | 2015-08-20 14:47:40 +0800 | [diff] [blame] | 589 | DECLARE_HASHTABLE(fences, 4); |
Chunming Zhou | 3c62338 | 2015-08-20 18:33:59 +0800 | [diff] [blame] | 590 | struct fence *last_vm_update; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 591 | }; |
| 592 | |
| 593 | void amdgpu_sync_create(struct amdgpu_sync *sync); |
Christian König | 91e1a52 | 2015-07-06 22:06:40 +0200 | [diff] [blame] | 594 | int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync, |
| 595 | struct fence *f); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 596 | int amdgpu_sync_resv(struct amdgpu_device *adev, |
| 597 | struct amdgpu_sync *sync, |
| 598 | struct reservation_object *resv, |
| 599 | void *owner); |
Christian König | 1fbb2e9 | 2016-06-01 10:47:36 +0200 | [diff] [blame^] | 600 | struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync, |
| 601 | struct amdgpu_ring *ring); |
Christian König | e61235d | 2015-08-25 11:05:36 +0200 | [diff] [blame] | 602 | struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync); |
Christian König | 8a8f0b4 | 2016-02-03 15:11:39 +0100 | [diff] [blame] | 603 | void amdgpu_sync_free(struct amdgpu_sync *sync); |
Christian König | 257bf15 | 2016-02-16 11:24:58 +0100 | [diff] [blame] | 604 | int amdgpu_sync_init(void); |
| 605 | void amdgpu_sync_fini(void); |
Rex Zhu | d573de2 | 2016-05-12 13:27:28 +0800 | [diff] [blame] | 606 | int amdgpu_fence_slab_init(void); |
| 607 | void amdgpu_fence_slab_fini(void); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 608 | |
| 609 | /* |
| 610 | * GART structures, functions & helpers |
| 611 | */ |
| 612 | struct amdgpu_mc; |
| 613 | |
| 614 | #define AMDGPU_GPU_PAGE_SIZE 4096 |
| 615 | #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1) |
| 616 | #define AMDGPU_GPU_PAGE_SHIFT 12 |
| 617 | #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK) |
| 618 | |
| 619 | struct amdgpu_gart { |
| 620 | dma_addr_t table_addr; |
| 621 | struct amdgpu_bo *robj; |
| 622 | void *ptr; |
| 623 | unsigned num_gpu_pages; |
| 624 | unsigned num_cpu_pages; |
| 625 | unsigned table_size; |
Christian König | a1d2947 | 2016-03-30 14:42:57 +0200 | [diff] [blame] | 626 | #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 627 | struct page **pages; |
Christian König | a1d2947 | 2016-03-30 14:42:57 +0200 | [diff] [blame] | 628 | #endif |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 629 | bool ready; |
| 630 | const struct amdgpu_gart_funcs *gart_funcs; |
| 631 | }; |
| 632 | |
| 633 | int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev); |
| 634 | void amdgpu_gart_table_ram_free(struct amdgpu_device *adev); |
| 635 | int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev); |
| 636 | void amdgpu_gart_table_vram_free(struct amdgpu_device *adev); |
| 637 | int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev); |
| 638 | void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev); |
| 639 | int amdgpu_gart_init(struct amdgpu_device *adev); |
| 640 | void amdgpu_gart_fini(struct amdgpu_device *adev); |
| 641 | void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset, |
| 642 | int pages); |
| 643 | int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset, |
| 644 | int pages, struct page **pagelist, |
| 645 | dma_addr_t *dma_addr, uint32_t flags); |
| 646 | |
| 647 | /* |
| 648 | * GPU MC structures, functions & helpers |
| 649 | */ |
| 650 | struct amdgpu_mc { |
| 651 | resource_size_t aper_size; |
| 652 | resource_size_t aper_base; |
| 653 | resource_size_t agp_base; |
| 654 | /* for some chips with <= 32MB we need to lie |
| 655 | * about vram size near mc fb location */ |
| 656 | u64 mc_vram_size; |
| 657 | u64 visible_vram_size; |
| 658 | u64 gtt_size; |
| 659 | u64 gtt_start; |
| 660 | u64 gtt_end; |
| 661 | u64 vram_start; |
| 662 | u64 vram_end; |
| 663 | unsigned vram_width; |
| 664 | u64 real_vram_size; |
| 665 | int vram_mtrr; |
| 666 | u64 gtt_base_align; |
| 667 | u64 mc_mask; |
| 668 | const struct firmware *fw; /* MC firmware */ |
| 669 | uint32_t fw_version; |
| 670 | struct amdgpu_irq_src vm_fault; |
Ken Wang | 81c59f5 | 2015-06-03 21:02:01 +0800 | [diff] [blame] | 671 | uint32_t vram_type; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 672 | }; |
| 673 | |
| 674 | /* |
| 675 | * GPU doorbell structures, functions & helpers |
| 676 | */ |
| 677 | typedef enum _AMDGPU_DOORBELL_ASSIGNMENT |
| 678 | { |
| 679 | AMDGPU_DOORBELL_KIQ = 0x000, |
| 680 | AMDGPU_DOORBELL_HIQ = 0x001, |
| 681 | AMDGPU_DOORBELL_DIQ = 0x002, |
| 682 | AMDGPU_DOORBELL_MEC_RING0 = 0x010, |
| 683 | AMDGPU_DOORBELL_MEC_RING1 = 0x011, |
| 684 | AMDGPU_DOORBELL_MEC_RING2 = 0x012, |
| 685 | AMDGPU_DOORBELL_MEC_RING3 = 0x013, |
| 686 | AMDGPU_DOORBELL_MEC_RING4 = 0x014, |
| 687 | AMDGPU_DOORBELL_MEC_RING5 = 0x015, |
| 688 | AMDGPU_DOORBELL_MEC_RING6 = 0x016, |
| 689 | AMDGPU_DOORBELL_MEC_RING7 = 0x017, |
| 690 | AMDGPU_DOORBELL_GFX_RING0 = 0x020, |
| 691 | AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0, |
| 692 | AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1, |
| 693 | AMDGPU_DOORBELL_IH = 0x1E8, |
| 694 | AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF, |
| 695 | AMDGPU_DOORBELL_INVALID = 0xFFFF |
| 696 | } AMDGPU_DOORBELL_ASSIGNMENT; |
| 697 | |
| 698 | struct amdgpu_doorbell { |
| 699 | /* doorbell mmio */ |
| 700 | resource_size_t base; |
| 701 | resource_size_t size; |
| 702 | u32 __iomem *ptr; |
| 703 | u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */ |
| 704 | }; |
| 705 | |
| 706 | void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev, |
| 707 | phys_addr_t *aperture_base, |
| 708 | size_t *aperture_size, |
| 709 | size_t *start_offset); |
| 710 | |
| 711 | /* |
| 712 | * IRQS. |
| 713 | */ |
| 714 | |
| 715 | struct amdgpu_flip_work { |
| 716 | struct work_struct flip_work; |
| 717 | struct work_struct unpin_work; |
| 718 | struct amdgpu_device *adev; |
| 719 | int crtc_id; |
| 720 | uint64_t base; |
| 721 | struct drm_pending_vblank_event *event; |
| 722 | struct amdgpu_bo *old_rbo; |
Christian König | 1ffd265 | 2015-08-11 17:29:52 +0200 | [diff] [blame] | 723 | struct fence *excl; |
| 724 | unsigned shared_count; |
| 725 | struct fence **shared; |
Christian König | c3874b7 | 2016-02-11 15:48:30 +0100 | [diff] [blame] | 726 | struct fence_cb cb; |
Alex Deucher | cb9e59d | 2016-05-05 16:03:57 -0400 | [diff] [blame] | 727 | bool async; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 728 | }; |
| 729 | |
| 730 | |
| 731 | /* |
| 732 | * CP & rings. |
| 733 | */ |
| 734 | |
| 735 | struct amdgpu_ib { |
| 736 | struct amdgpu_sa_bo *sa_bo; |
| 737 | uint32_t length_dw; |
| 738 | uint64_t gpu_addr; |
| 739 | uint32_t *ptr; |
Jammy Zhou | de807f8 | 2015-05-11 23:41:41 +0800 | [diff] [blame] | 740 | uint32_t flags; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 741 | }; |
| 742 | |
| 743 | enum amdgpu_ring_type { |
| 744 | AMDGPU_RING_TYPE_GFX, |
| 745 | AMDGPU_RING_TYPE_COMPUTE, |
| 746 | AMDGPU_RING_TYPE_SDMA, |
| 747 | AMDGPU_RING_TYPE_UVD, |
| 748 | AMDGPU_RING_TYPE_VCE |
| 749 | }; |
| 750 | |
Nils Wallménius | 62250a9 | 2016-04-10 16:30:00 +0200 | [diff] [blame] | 751 | extern const struct amd_sched_backend_ops amdgpu_sched_ops; |
Chunming Zhou | c1b69ed | 2015-07-21 13:45:14 +0800 | [diff] [blame] | 752 | |
Christian König | 50838c8 | 2016-02-03 13:44:52 +0100 | [diff] [blame] | 753 | int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, |
Monk Liu | c563783 | 2016-04-19 20:11:32 +0800 | [diff] [blame] | 754 | struct amdgpu_job **job, struct amdgpu_vm *vm); |
Christian König | d71518b | 2016-02-01 12:20:25 +0100 | [diff] [blame] | 755 | int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size, |
| 756 | struct amdgpu_job **job); |
Monk Liu | b6723c8 | 2016-03-10 12:14:44 +0800 | [diff] [blame] | 757 | |
Christian König | 50838c8 | 2016-02-03 13:44:52 +0100 | [diff] [blame] | 758 | void amdgpu_job_free(struct amdgpu_job *job); |
Christian König | d71518b | 2016-02-01 12:20:25 +0100 | [diff] [blame] | 759 | int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring, |
Christian König | 2bd9ccf | 2016-02-01 12:53:58 +0100 | [diff] [blame] | 760 | struct amd_sched_entity *entity, void *owner, |
| 761 | struct fence **f); |
Chunming Zhou | 3c704e9 | 2015-07-29 10:33:14 +0800 | [diff] [blame] | 762 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 763 | struct amdgpu_ring { |
| 764 | struct amdgpu_device *adev; |
| 765 | const struct amdgpu_ring_funcs *funcs; |
| 766 | struct amdgpu_fence_driver fence_drv; |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 767 | struct amd_gpu_scheduler sched; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 768 | |
Chunming Zhou | 176e1ab | 2015-07-24 10:49:47 +0800 | [diff] [blame] | 769 | spinlock_t fence_lock; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 770 | struct amdgpu_bo *ring_obj; |
| 771 | volatile uint32_t *ring; |
| 772 | unsigned rptr_offs; |
| 773 | u64 next_rptr_gpu_addr; |
| 774 | volatile u32 *next_rptr_cpu_addr; |
| 775 | unsigned wptr; |
| 776 | unsigned wptr_old; |
| 777 | unsigned ring_size; |
Christian König | c7e6be2 | 2016-01-21 13:06:05 +0100 | [diff] [blame] | 778 | unsigned max_dw; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 779 | int count_dw; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 780 | uint64_t gpu_addr; |
| 781 | uint32_t align_mask; |
| 782 | uint32_t ptr_mask; |
| 783 | bool ready; |
| 784 | u32 nop; |
| 785 | u32 idx; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 786 | u32 me; |
| 787 | u32 pipe; |
| 788 | u32 queue; |
| 789 | struct amdgpu_bo *mqd_obj; |
| 790 | u32 doorbell_index; |
| 791 | bool use_doorbell; |
| 792 | unsigned wptr_offs; |
| 793 | unsigned next_rptr_offs; |
| 794 | unsigned fence_offs; |
Christian König | aa3b73f | 2016-05-03 15:17:40 +0200 | [diff] [blame] | 795 | uint64_t current_ctx; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 796 | enum amdgpu_ring_type type; |
| 797 | char name[16]; |
Monk Liu | 128cff1 | 2016-01-14 18:08:16 +0800 | [diff] [blame] | 798 | unsigned cond_exe_offs; |
| 799 | u64 cond_exe_gpu_addr; |
| 800 | volatile u32 *cond_exe_cpu_addr; |
Monk Liu | a909c6b | 2016-06-14 12:02:21 -0400 | [diff] [blame] | 801 | #if defined(CONFIG_DEBUG_FS) |
| 802 | struct dentry *ent; |
| 803 | #endif |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 804 | }; |
| 805 | |
| 806 | /* |
| 807 | * VM |
| 808 | */ |
| 809 | |
| 810 | /* maximum number of VMIDs */ |
| 811 | #define AMDGPU_NUM_VM 16 |
| 812 | |
| 813 | /* number of entries in page table */ |
| 814 | #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size) |
| 815 | |
| 816 | /* PTBs (Page Table Blocks) need to be aligned to 32K */ |
| 817 | #define AMDGPU_VM_PTB_ALIGN_SIZE 32768 |
| 818 | #define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1) |
| 819 | #define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK) |
| 820 | |
| 821 | #define AMDGPU_PTE_VALID (1 << 0) |
| 822 | #define AMDGPU_PTE_SYSTEM (1 << 1) |
| 823 | #define AMDGPU_PTE_SNOOPED (1 << 2) |
| 824 | |
| 825 | /* VI only */ |
| 826 | #define AMDGPU_PTE_EXECUTABLE (1 << 4) |
| 827 | |
| 828 | #define AMDGPU_PTE_READABLE (1 << 5) |
| 829 | #define AMDGPU_PTE_WRITEABLE (1 << 6) |
| 830 | |
| 831 | /* PTE (Page Table Entry) fragment field for different page sizes */ |
| 832 | #define AMDGPU_PTE_FRAG_4KB (0 << 7) |
| 833 | #define AMDGPU_PTE_FRAG_64KB (4 << 7) |
| 834 | #define AMDGPU_LOG2_PAGES_PER_FRAG 4 |
| 835 | |
Christian König | d9c1315 | 2015-09-28 12:31:26 +0200 | [diff] [blame] | 836 | /* How to programm VM fault handling */ |
| 837 | #define AMDGPU_VM_FAULT_STOP_NEVER 0 |
| 838 | #define AMDGPU_VM_FAULT_STOP_FIRST 1 |
| 839 | #define AMDGPU_VM_FAULT_STOP_ALWAYS 2 |
| 840 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 841 | struct amdgpu_vm_pt { |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 842 | struct amdgpu_bo_list_entry entry; |
| 843 | uint64_t addr; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 844 | }; |
| 845 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 846 | struct amdgpu_vm { |
Christian König | 25cfc3c | 2015-12-19 19:42:05 +0100 | [diff] [blame] | 847 | /* tree of virtual addresses mapped */ |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 848 | struct rb_root va; |
| 849 | |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 850 | /* protecting invalidated */ |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 851 | spinlock_t status_lock; |
| 852 | |
| 853 | /* BOs moved, but not yet updated in the PT */ |
| 854 | struct list_head invalidated; |
| 855 | |
Christian König | 7fc1195 | 2015-07-30 11:53:42 +0200 | [diff] [blame] | 856 | /* BOs cleared in the PT because of a move */ |
| 857 | struct list_head cleared; |
| 858 | |
| 859 | /* BO mappings freed, but not yet updated in the PT */ |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 860 | struct list_head freed; |
| 861 | |
| 862 | /* contains the page directory */ |
| 863 | struct amdgpu_bo *page_directory; |
| 864 | unsigned max_pde_used; |
Bas Nieuwenhuizen | 05906de | 2015-08-14 20:08:40 +0200 | [diff] [blame] | 865 | struct fence *page_directory_fence; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 866 | |
| 867 | /* array of page tables, one for each page directory entry */ |
| 868 | struct amdgpu_vm_pt *page_tables; |
| 869 | |
| 870 | /* for id and flush management per ring */ |
Christian König | bcb1ba3 | 2016-03-08 15:40:11 +0100 | [diff] [blame] | 871 | struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS]; |
Christian König | 25cfc3c | 2015-12-19 19:42:05 +0100 | [diff] [blame] | 872 | |
jimqu | 81d75a3 | 2015-12-04 17:17:00 +0800 | [diff] [blame] | 873 | /* protecting freed */ |
| 874 | spinlock_t freed_lock; |
Christian König | 2bd9ccf | 2016-02-01 12:53:58 +0100 | [diff] [blame] | 875 | |
| 876 | /* Scheduler entity for page table updates */ |
| 877 | struct amd_sched_entity entity; |
Chunming Zhou | 031e298 | 2016-04-25 10:19:13 +0800 | [diff] [blame] | 878 | |
| 879 | /* client id */ |
| 880 | u64 client_id; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 881 | }; |
| 882 | |
Christian König | bcb1ba3 | 2016-03-08 15:40:11 +0100 | [diff] [blame] | 883 | struct amdgpu_vm_id { |
Christian König | a9a78b3 | 2016-01-21 10:19:11 +0100 | [diff] [blame] | 884 | struct list_head list; |
Christian König | 832a902 | 2016-02-15 12:33:02 +0100 | [diff] [blame] | 885 | struct fence *first; |
| 886 | struct amdgpu_sync active; |
Christian König | 41d9eb2 | 2016-03-01 16:46:18 +0100 | [diff] [blame] | 887 | struct fence *last_flush; |
Chunming Zhou | 68befeb | 2016-04-14 13:42:32 +0800 | [diff] [blame] | 888 | struct amdgpu_ring *last_user; |
Christian König | 0ea54b9 | 2016-05-04 10:20:01 +0200 | [diff] [blame] | 889 | atomic64_t owner; |
Christian König | 971fe9a9 | 2016-03-01 15:09:25 +0100 | [diff] [blame] | 890 | |
Christian König | bcb1ba3 | 2016-03-08 15:40:11 +0100 | [diff] [blame] | 891 | uint64_t pd_gpu_addr; |
| 892 | /* last flushed PD/PT update */ |
| 893 | struct fence *flushed_updates; |
| 894 | |
Christian König | 971fe9a9 | 2016-03-01 15:09:25 +0100 | [diff] [blame] | 895 | uint32_t gds_base; |
| 896 | uint32_t gds_size; |
| 897 | uint32_t gws_base; |
| 898 | uint32_t gws_size; |
| 899 | uint32_t oa_base; |
| 900 | uint32_t oa_size; |
Christian König | a9a78b3 | 2016-01-21 10:19:11 +0100 | [diff] [blame] | 901 | }; |
Christian König | 8d0a7ce | 2015-11-03 20:58:50 +0100 | [diff] [blame] | 902 | |
Christian König | a9a78b3 | 2016-01-21 10:19:11 +0100 | [diff] [blame] | 903 | struct amdgpu_vm_manager { |
| 904 | /* Handling of VMIDs */ |
| 905 | struct mutex lock; |
| 906 | unsigned num_ids; |
| 907 | struct list_head ids_lru; |
Christian König | bcb1ba3 | 2016-03-08 15:40:11 +0100 | [diff] [blame] | 908 | struct amdgpu_vm_id ids[AMDGPU_NUM_VM]; |
Christian König | 1c16c0a | 2015-11-14 21:31:40 +0100 | [diff] [blame] | 909 | |
Christian König | 1fbb2e9 | 2016-06-01 10:47:36 +0200 | [diff] [blame^] | 910 | /* Handling of VM fences */ |
| 911 | u64 fence_context; |
| 912 | unsigned seqno[AMDGPU_MAX_RINGS]; |
| 913 | |
Christian König | 8b4fb00 | 2015-11-15 16:04:16 +0100 | [diff] [blame] | 914 | uint32_t max_pfn; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 915 | /* vram base address for page table entry */ |
Christian König | 8b4fb00 | 2015-11-15 16:04:16 +0100 | [diff] [blame] | 916 | u64 vram_base_offset; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 917 | /* is vm enabled? */ |
Christian König | 8b4fb00 | 2015-11-15 16:04:16 +0100 | [diff] [blame] | 918 | bool enabled; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 919 | /* vm pte handling */ |
| 920 | const struct amdgpu_vm_pte_funcs *vm_pte_funcs; |
Christian König | 2d55e45 | 2016-02-08 17:37:38 +0100 | [diff] [blame] | 921 | struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS]; |
| 922 | unsigned vm_pte_num_rings; |
| 923 | atomic_t vm_pte_next_ring; |
Chunming Zhou | 031e298 | 2016-04-25 10:19:13 +0800 | [diff] [blame] | 924 | /* client id counter */ |
| 925 | atomic64_t client_counter; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 926 | }; |
| 927 | |
Christian König | a9a78b3 | 2016-01-21 10:19:11 +0100 | [diff] [blame] | 928 | void amdgpu_vm_manager_init(struct amdgpu_device *adev); |
Christian König | ea89f8c | 2015-11-15 20:52:06 +0100 | [diff] [blame] | 929 | void amdgpu_vm_manager_fini(struct amdgpu_device *adev); |
Christian König | 8b4fb00 | 2015-11-15 16:04:16 +0100 | [diff] [blame] | 930 | int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm); |
| 931 | void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm); |
Christian König | 56467eb | 2015-12-11 15:16:32 +0100 | [diff] [blame] | 932 | void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, |
| 933 | struct list_head *validated, |
| 934 | struct amdgpu_bo_list_entry *entry); |
Christian König | ee1782c | 2015-12-11 21:01:23 +0100 | [diff] [blame] | 935 | void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates); |
Christian König | eceb8a1 | 2016-01-11 15:35:21 +0100 | [diff] [blame] | 936 | void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev, |
| 937 | struct amdgpu_vm *vm); |
Christian König | 8b4fb00 | 2015-11-15 16:04:16 +0100 | [diff] [blame] | 938 | int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, |
Christian König | 4ff37a8 | 2016-02-26 16:18:26 +0100 | [diff] [blame] | 939 | struct amdgpu_sync *sync, struct fence *fence, |
| 940 | unsigned *vm_id, uint64_t *vm_pd_addr); |
Christian König | 41d9eb2 | 2016-03-01 16:46:18 +0100 | [diff] [blame] | 941 | int amdgpu_vm_flush(struct amdgpu_ring *ring, |
| 942 | unsigned vm_id, uint64_t pd_addr, |
| 943 | uint32_t gds_base, uint32_t gds_size, |
| 944 | uint32_t gws_base, uint32_t gws_size, |
| 945 | uint32_t oa_base, uint32_t oa_size); |
Christian König | 971fe9a9 | 2016-03-01 15:09:25 +0100 | [diff] [blame] | 946 | void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id); |
Christian König | b07c9d2 | 2015-11-30 13:26:07 +0100 | [diff] [blame] | 947 | uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr); |
Christian König | 8b4fb00 | 2015-11-15 16:04:16 +0100 | [diff] [blame] | 948 | int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, |
| 949 | struct amdgpu_vm *vm); |
| 950 | int amdgpu_vm_clear_freed(struct amdgpu_device *adev, |
| 951 | struct amdgpu_vm *vm); |
| 952 | int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm, |
| 953 | struct amdgpu_sync *sync); |
| 954 | int amdgpu_vm_bo_update(struct amdgpu_device *adev, |
| 955 | struct amdgpu_bo_va *bo_va, |
| 956 | struct ttm_mem_reg *mem); |
| 957 | void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, |
| 958 | struct amdgpu_bo *bo); |
| 959 | struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm, |
| 960 | struct amdgpu_bo *bo); |
| 961 | struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, |
| 962 | struct amdgpu_vm *vm, |
| 963 | struct amdgpu_bo *bo); |
| 964 | int amdgpu_vm_bo_map(struct amdgpu_device *adev, |
| 965 | struct amdgpu_bo_va *bo_va, |
| 966 | uint64_t addr, uint64_t offset, |
| 967 | uint64_t size, uint32_t flags); |
| 968 | int amdgpu_vm_bo_unmap(struct amdgpu_device *adev, |
| 969 | struct amdgpu_bo_va *bo_va, |
| 970 | uint64_t addr); |
| 971 | void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, |
| 972 | struct amdgpu_bo_va *bo_va); |
Christian König | 8b4fb00 | 2015-11-15 16:04:16 +0100 | [diff] [blame] | 973 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 974 | /* |
| 975 | * context related structures |
| 976 | */ |
| 977 | |
Christian König | 21c16bf | 2015-07-07 17:24:49 +0200 | [diff] [blame] | 978 | struct amdgpu_ctx_ring { |
Christian König | 91404fb | 2015-08-05 18:33:21 +0200 | [diff] [blame] | 979 | uint64_t sequence; |
Chunming Zhou | 37cd0ca | 2015-12-10 15:45:11 +0800 | [diff] [blame] | 980 | struct fence **fences; |
Christian König | 91404fb | 2015-08-05 18:33:21 +0200 | [diff] [blame] | 981 | struct amd_sched_entity entity; |
Christian König | 21c16bf | 2015-07-07 17:24:49 +0200 | [diff] [blame] | 982 | }; |
| 983 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 984 | struct amdgpu_ctx { |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 985 | struct kref refcount; |
Chunming Zhou | 9cb7e5a | 2015-07-21 13:17:19 +0800 | [diff] [blame] | 986 | struct amdgpu_device *adev; |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 987 | unsigned reset_counter; |
Christian König | 21c16bf | 2015-07-07 17:24:49 +0200 | [diff] [blame] | 988 | spinlock_t ring_lock; |
Chunming Zhou | 37cd0ca | 2015-12-10 15:45:11 +0800 | [diff] [blame] | 989 | struct fence **fences; |
Christian König | 21c16bf | 2015-07-07 17:24:49 +0200 | [diff] [blame] | 990 | struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS]; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 991 | }; |
| 992 | |
| 993 | struct amdgpu_ctx_mgr { |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 994 | struct amdgpu_device *adev; |
| 995 | struct mutex lock; |
| 996 | /* protected by lock */ |
| 997 | struct idr ctx_handles; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 998 | }; |
| 999 | |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 1000 | struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id); |
| 1001 | int amdgpu_ctx_put(struct amdgpu_ctx *ctx); |
| 1002 | |
Christian König | 21c16bf | 2015-07-07 17:24:49 +0200 | [diff] [blame] | 1003 | uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring, |
Christian König | ce882e6 | 2015-08-19 15:00:55 +0200 | [diff] [blame] | 1004 | struct fence *fence); |
Christian König | 21c16bf | 2015-07-07 17:24:49 +0200 | [diff] [blame] | 1005 | struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, |
| 1006 | struct amdgpu_ring *ring, uint64_t seq); |
| 1007 | |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 1008 | int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, |
| 1009 | struct drm_file *filp); |
| 1010 | |
Christian König | efd4ccb | 2015-08-04 16:20:31 +0200 | [diff] [blame] | 1011 | void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr); |
| 1012 | void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 1013 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1014 | /* |
| 1015 | * file private structure |
| 1016 | */ |
| 1017 | |
| 1018 | struct amdgpu_fpriv { |
| 1019 | struct amdgpu_vm vm; |
| 1020 | struct mutex bo_list_lock; |
| 1021 | struct idr bo_list_handles; |
Alex Deucher | 0b492a4 | 2015-08-16 22:48:26 -0400 | [diff] [blame] | 1022 | struct amdgpu_ctx_mgr ctx_mgr; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1023 | }; |
| 1024 | |
| 1025 | /* |
| 1026 | * residency list |
| 1027 | */ |
| 1028 | |
| 1029 | struct amdgpu_bo_list { |
| 1030 | struct mutex lock; |
| 1031 | struct amdgpu_bo *gds_obj; |
| 1032 | struct amdgpu_bo *gws_obj; |
| 1033 | struct amdgpu_bo *oa_obj; |
Christian König | 211dff5 | 2016-02-22 15:40:59 +0100 | [diff] [blame] | 1034 | unsigned first_userptr; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1035 | unsigned num_entries; |
| 1036 | struct amdgpu_bo_list_entry *array; |
| 1037 | }; |
| 1038 | |
| 1039 | struct amdgpu_bo_list * |
| 1040 | amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id); |
Christian König | 636ce25 | 2015-12-18 21:26:47 +0100 | [diff] [blame] | 1041 | void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list, |
| 1042 | struct list_head *validated); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1043 | void amdgpu_bo_list_put(struct amdgpu_bo_list *list); |
| 1044 | void amdgpu_bo_list_free(struct amdgpu_bo_list *list); |
| 1045 | |
| 1046 | /* |
| 1047 | * GFX stuff |
| 1048 | */ |
| 1049 | #include "clearstate_defs.h" |
| 1050 | |
Alex Deucher | 79e5412 | 2016-04-08 15:45:13 -0400 | [diff] [blame] | 1051 | struct amdgpu_rlc_funcs { |
| 1052 | void (*enter_safe_mode)(struct amdgpu_device *adev); |
| 1053 | void (*exit_safe_mode)(struct amdgpu_device *adev); |
| 1054 | }; |
| 1055 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1056 | struct amdgpu_rlc { |
| 1057 | /* for power gating */ |
| 1058 | struct amdgpu_bo *save_restore_obj; |
| 1059 | uint64_t save_restore_gpu_addr; |
| 1060 | volatile uint32_t *sr_ptr; |
| 1061 | const u32 *reg_list; |
| 1062 | u32 reg_list_size; |
| 1063 | /* for clear state */ |
| 1064 | struct amdgpu_bo *clear_state_obj; |
| 1065 | uint64_t clear_state_gpu_addr; |
| 1066 | volatile uint32_t *cs_ptr; |
| 1067 | const struct cs_section_def *cs_data; |
| 1068 | u32 clear_state_size; |
| 1069 | /* for cp tables */ |
| 1070 | struct amdgpu_bo *cp_table_obj; |
| 1071 | uint64_t cp_table_gpu_addr; |
| 1072 | volatile uint32_t *cp_table_ptr; |
| 1073 | u32 cp_table_size; |
Alex Deucher | 79e5412 | 2016-04-08 15:45:13 -0400 | [diff] [blame] | 1074 | |
| 1075 | /* safe mode for updating CG/PG state */ |
| 1076 | bool in_safe_mode; |
| 1077 | const struct amdgpu_rlc_funcs *funcs; |
Eric Huang | 2b6cd97 | 2016-04-14 17:26:07 -0400 | [diff] [blame] | 1078 | |
| 1079 | /* for firmware data */ |
| 1080 | u32 save_and_restore_offset; |
| 1081 | u32 clear_state_descriptor_offset; |
| 1082 | u32 avail_scratch_ram_locations; |
| 1083 | u32 reg_restore_list_size; |
| 1084 | u32 reg_list_format_start; |
| 1085 | u32 reg_list_format_separate_start; |
| 1086 | u32 starting_offsets_start; |
| 1087 | u32 reg_list_format_size_bytes; |
| 1088 | u32 reg_list_size_bytes; |
| 1089 | |
| 1090 | u32 *register_list_format; |
| 1091 | u32 *register_restore; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1092 | }; |
| 1093 | |
| 1094 | struct amdgpu_mec { |
| 1095 | struct amdgpu_bo *hpd_eop_obj; |
| 1096 | u64 hpd_eop_gpu_addr; |
| 1097 | u32 num_pipe; |
| 1098 | u32 num_mec; |
| 1099 | u32 num_queue; |
| 1100 | }; |
| 1101 | |
| 1102 | /* |
| 1103 | * GPU scratch registers structures, functions & helpers |
| 1104 | */ |
| 1105 | struct amdgpu_scratch { |
| 1106 | unsigned num_reg; |
| 1107 | uint32_t reg_base; |
| 1108 | bool free[32]; |
| 1109 | uint32_t reg[32]; |
| 1110 | }; |
| 1111 | |
| 1112 | /* |
| 1113 | * GFX configurations |
| 1114 | */ |
| 1115 | struct amdgpu_gca_config { |
| 1116 | unsigned max_shader_engines; |
| 1117 | unsigned max_tile_pipes; |
| 1118 | unsigned max_cu_per_sh; |
| 1119 | unsigned max_sh_per_se; |
| 1120 | unsigned max_backends_per_se; |
| 1121 | unsigned max_texture_channel_caches; |
| 1122 | unsigned max_gprs; |
| 1123 | unsigned max_gs_threads; |
| 1124 | unsigned max_hw_contexts; |
| 1125 | unsigned sc_prim_fifo_size_frontend; |
| 1126 | unsigned sc_prim_fifo_size_backend; |
| 1127 | unsigned sc_hiz_tile_fifo_size; |
| 1128 | unsigned sc_earlyz_tile_fifo_size; |
| 1129 | |
| 1130 | unsigned num_tile_pipes; |
| 1131 | unsigned backend_enable_mask; |
| 1132 | unsigned mem_max_burst_length_bytes; |
| 1133 | unsigned mem_row_size_in_kb; |
| 1134 | unsigned shader_engine_tile_size; |
| 1135 | unsigned num_gpus; |
| 1136 | unsigned multi_gpu_tile_size; |
| 1137 | unsigned mc_arb_ramcfg; |
| 1138 | unsigned gb_addr_config; |
Alex Deucher | 8f8e00c | 2016-02-12 00:39:13 -0500 | [diff] [blame] | 1139 | unsigned num_rbs; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1140 | |
| 1141 | uint32_t tile_mode_array[32]; |
| 1142 | uint32_t macrotile_mode_array[16]; |
| 1143 | }; |
| 1144 | |
Alex Deucher | 7dae69a | 2016-05-03 16:25:53 -0400 | [diff] [blame] | 1145 | struct amdgpu_cu_info { |
| 1146 | uint32_t number; /* total active CU number */ |
| 1147 | uint32_t ao_cu_mask; |
| 1148 | uint32_t bitmap[4][4]; |
| 1149 | }; |
| 1150 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1151 | struct amdgpu_gfx { |
| 1152 | struct mutex gpu_clock_mutex; |
| 1153 | struct amdgpu_gca_config config; |
| 1154 | struct amdgpu_rlc rlc; |
| 1155 | struct amdgpu_mec mec; |
| 1156 | struct amdgpu_scratch scratch; |
| 1157 | const struct firmware *me_fw; /* ME firmware */ |
| 1158 | uint32_t me_fw_version; |
| 1159 | const struct firmware *pfp_fw; /* PFP firmware */ |
| 1160 | uint32_t pfp_fw_version; |
| 1161 | const struct firmware *ce_fw; /* CE firmware */ |
| 1162 | uint32_t ce_fw_version; |
| 1163 | const struct firmware *rlc_fw; /* RLC firmware */ |
| 1164 | uint32_t rlc_fw_version; |
| 1165 | const struct firmware *mec_fw; /* MEC firmware */ |
| 1166 | uint32_t mec_fw_version; |
| 1167 | const struct firmware *mec2_fw; /* MEC2 firmware */ |
| 1168 | uint32_t mec2_fw_version; |
Ken Wang | 02558a0 | 2015-06-03 19:52:06 +0800 | [diff] [blame] | 1169 | uint32_t me_feature_version; |
| 1170 | uint32_t ce_feature_version; |
| 1171 | uint32_t pfp_feature_version; |
Jammy Zhou | 351643d | 2015-08-04 10:43:50 +0800 | [diff] [blame] | 1172 | uint32_t rlc_feature_version; |
| 1173 | uint32_t mec_feature_version; |
| 1174 | uint32_t mec2_feature_version; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1175 | struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS]; |
| 1176 | unsigned num_gfx_rings; |
| 1177 | struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS]; |
| 1178 | unsigned num_compute_rings; |
| 1179 | struct amdgpu_irq_src eop_irq; |
| 1180 | struct amdgpu_irq_src priv_reg_irq; |
| 1181 | struct amdgpu_irq_src priv_inst_irq; |
| 1182 | /* gfx status */ |
Alex Deucher | 7dae69a | 2016-05-03 16:25:53 -0400 | [diff] [blame] | 1183 | uint32_t gfx_current_status; |
Ken Wang | a101a89 | 2015-06-03 17:47:54 +0800 | [diff] [blame] | 1184 | /* ce ram size*/ |
Alex Deucher | 7dae69a | 2016-05-03 16:25:53 -0400 | [diff] [blame] | 1185 | unsigned ce_ram_size; |
| 1186 | struct amdgpu_cu_info cu_info; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1187 | }; |
| 1188 | |
Christian König | b07c60c | 2016-01-31 12:29:04 +0100 | [diff] [blame] | 1189 | int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1190 | unsigned size, struct amdgpu_ib *ib); |
Christian König | 4d9c514 | 2016-05-03 18:46:19 +0200 | [diff] [blame] | 1191 | void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, |
| 1192 | struct fence *f); |
Christian König | b07c60c | 2016-01-31 12:29:04 +0100 | [diff] [blame] | 1193 | int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, |
Christian König | 336d1f5 | 2016-02-16 10:57:10 +0100 | [diff] [blame] | 1194 | struct amdgpu_ib *ib, struct fence *last_vm_update, |
Monk Liu | c563783 | 2016-04-19 20:11:32 +0800 | [diff] [blame] | 1195 | struct amdgpu_job *job, struct fence **f); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1196 | int amdgpu_ib_pool_init(struct amdgpu_device *adev); |
| 1197 | void amdgpu_ib_pool_fini(struct amdgpu_device *adev); |
| 1198 | int amdgpu_ib_ring_tests(struct amdgpu_device *adev); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1199 | int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw); |
Jammy Zhou | edff0e2 | 2015-09-01 13:04:08 +0800 | [diff] [blame] | 1200 | void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count); |
Christian König | 9e5d5309 | 2016-01-31 12:20:55 +0100 | [diff] [blame] | 1201 | void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1202 | void amdgpu_ring_commit(struct amdgpu_ring *ring); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1203 | void amdgpu_ring_undo(struct amdgpu_ring *ring); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1204 | unsigned amdgpu_ring_backup(struct amdgpu_ring *ring, |
| 1205 | uint32_t **data); |
| 1206 | int amdgpu_ring_restore(struct amdgpu_ring *ring, |
| 1207 | unsigned size, uint32_t *data); |
| 1208 | int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, |
| 1209 | unsigned ring_size, u32 nop, u32 align_mask, |
| 1210 | struct amdgpu_irq_src *irq_src, unsigned irq_type, |
| 1211 | enum amdgpu_ring_type ring_type); |
| 1212 | void amdgpu_ring_fini(struct amdgpu_ring *ring); |
| 1213 | |
| 1214 | /* |
| 1215 | * CS. |
| 1216 | */ |
| 1217 | struct amdgpu_cs_chunk { |
| 1218 | uint32_t chunk_id; |
| 1219 | uint32_t length_dw; |
Christian König | 758ac17 | 2016-05-06 22:14:00 +0200 | [diff] [blame] | 1220 | void *kdata; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1221 | }; |
| 1222 | |
| 1223 | struct amdgpu_cs_parser { |
| 1224 | struct amdgpu_device *adev; |
| 1225 | struct drm_file *filp; |
Christian König | 3cb485f | 2015-05-11 15:34:59 +0200 | [diff] [blame] | 1226 | struct amdgpu_ctx *ctx; |
Christian König | c3cca41 | 2015-12-15 14:41:33 +0100 | [diff] [blame] | 1227 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1228 | /* chunks */ |
| 1229 | unsigned nchunks; |
| 1230 | struct amdgpu_cs_chunk *chunks; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1231 | |
Christian König | 50838c8 | 2016-02-03 13:44:52 +0100 | [diff] [blame] | 1232 | /* scheduler job object */ |
| 1233 | struct amdgpu_job *job; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1234 | |
Christian König | c3cca41 | 2015-12-15 14:41:33 +0100 | [diff] [blame] | 1235 | /* buffer objects */ |
| 1236 | struct ww_acquire_ctx ticket; |
| 1237 | struct amdgpu_bo_list *bo_list; |
| 1238 | struct amdgpu_bo_list_entry vm_pd; |
| 1239 | struct list_head validated; |
| 1240 | struct fence *fence; |
| 1241 | uint64_t bytes_moved_threshold; |
| 1242 | uint64_t bytes_moved; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1243 | |
| 1244 | /* user fence */ |
Christian König | 91acbeb | 2015-12-14 16:42:31 +0100 | [diff] [blame] | 1245 | struct amdgpu_bo_list_entry uf_entry; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1246 | }; |
| 1247 | |
Chunming Zhou | bb977d3 | 2015-08-18 15:16:40 +0800 | [diff] [blame] | 1248 | struct amdgpu_job { |
| 1249 | struct amd_sched_job base; |
| 1250 | struct amdgpu_device *adev; |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 1251 | struct amdgpu_vm *vm; |
Christian König | b07c60c | 2016-01-31 12:29:04 +0100 | [diff] [blame] | 1252 | struct amdgpu_ring *ring; |
Christian König | e86f9ce | 2016-02-08 12:13:05 +0100 | [diff] [blame] | 1253 | struct amdgpu_sync sync; |
Chunming Zhou | bb977d3 | 2015-08-18 15:16:40 +0800 | [diff] [blame] | 1254 | struct amdgpu_ib *ibs; |
Monk Liu | 73cfa5f | 2016-03-17 13:48:13 +0800 | [diff] [blame] | 1255 | struct fence *fence; /* the hw fence */ |
Chunming Zhou | bb977d3 | 2015-08-18 15:16:40 +0800 | [diff] [blame] | 1256 | uint32_t num_ibs; |
Christian König | e284022 | 2015-11-05 19:49:48 +0100 | [diff] [blame] | 1257 | void *owner; |
Christian König | 92f2509 | 2016-05-06 15:57:42 +0200 | [diff] [blame] | 1258 | uint64_t ctx; |
Christian König | d88bf58 | 2016-05-06 17:50:03 +0200 | [diff] [blame] | 1259 | unsigned vm_id; |
| 1260 | uint64_t vm_pd_addr; |
| 1261 | uint32_t gds_base, gds_size; |
| 1262 | uint32_t gws_base, gws_size; |
| 1263 | uint32_t oa_base, oa_size; |
Christian König | 758ac17 | 2016-05-06 22:14:00 +0200 | [diff] [blame] | 1264 | |
| 1265 | /* user fence handling */ |
| 1266 | struct amdgpu_bo *uf_bo; |
| 1267 | uint32_t uf_offset; |
| 1268 | uint64_t uf_sequence; |
| 1269 | |
Chunming Zhou | bb977d3 | 2015-08-18 15:16:40 +0800 | [diff] [blame] | 1270 | }; |
Junwei Zhang | a6db8a3 | 2015-09-09 09:21:19 +0800 | [diff] [blame] | 1271 | #define to_amdgpu_job(sched_job) \ |
| 1272 | container_of((sched_job), struct amdgpu_job, base) |
Chunming Zhou | bb977d3 | 2015-08-18 15:16:40 +0800 | [diff] [blame] | 1273 | |
Christian König | 7270f83 | 2016-01-31 11:00:41 +0100 | [diff] [blame] | 1274 | static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, |
| 1275 | uint32_t ib_idx, int idx) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1276 | { |
Christian König | 50838c8 | 2016-02-03 13:44:52 +0100 | [diff] [blame] | 1277 | return p->job->ibs[ib_idx].ptr[idx]; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
Christian König | 7270f83 | 2016-01-31 11:00:41 +0100 | [diff] [blame] | 1280 | static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p, |
| 1281 | uint32_t ib_idx, int idx, |
| 1282 | uint32_t value) |
| 1283 | { |
Christian König | 50838c8 | 2016-02-03 13:44:52 +0100 | [diff] [blame] | 1284 | p->job->ibs[ib_idx].ptr[idx] = value; |
Christian König | 7270f83 | 2016-01-31 11:00:41 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1287 | /* |
| 1288 | * Writeback |
| 1289 | */ |
| 1290 | #define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */ |
| 1291 | |
| 1292 | struct amdgpu_wb { |
| 1293 | struct amdgpu_bo *wb_obj; |
| 1294 | volatile uint32_t *wb; |
| 1295 | uint64_t gpu_addr; |
| 1296 | u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */ |
| 1297 | unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)]; |
| 1298 | }; |
| 1299 | |
| 1300 | int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb); |
| 1301 | void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb); |
| 1302 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1303 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1304 | |
| 1305 | enum amdgpu_int_thermal_type { |
| 1306 | THERMAL_TYPE_NONE, |
| 1307 | THERMAL_TYPE_EXTERNAL, |
| 1308 | THERMAL_TYPE_EXTERNAL_GPIO, |
| 1309 | THERMAL_TYPE_RV6XX, |
| 1310 | THERMAL_TYPE_RV770, |
| 1311 | THERMAL_TYPE_ADT7473_WITH_INTERNAL, |
| 1312 | THERMAL_TYPE_EVERGREEN, |
| 1313 | THERMAL_TYPE_SUMO, |
| 1314 | THERMAL_TYPE_NI, |
| 1315 | THERMAL_TYPE_SI, |
| 1316 | THERMAL_TYPE_EMC2103_WITH_INTERNAL, |
| 1317 | THERMAL_TYPE_CI, |
| 1318 | THERMAL_TYPE_KV, |
| 1319 | }; |
| 1320 | |
| 1321 | enum amdgpu_dpm_auto_throttle_src { |
| 1322 | AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, |
| 1323 | AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL |
| 1324 | }; |
| 1325 | |
| 1326 | enum amdgpu_dpm_event_src { |
| 1327 | AMDGPU_DPM_EVENT_SRC_ANALOG = 0, |
| 1328 | AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1, |
| 1329 | AMDGPU_DPM_EVENT_SRC_DIGITAL = 2, |
| 1330 | AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, |
| 1331 | AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4 |
| 1332 | }; |
| 1333 | |
| 1334 | #define AMDGPU_MAX_VCE_LEVELS 6 |
| 1335 | |
| 1336 | enum amdgpu_vce_level { |
| 1337 | AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */ |
| 1338 | AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */ |
| 1339 | AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */ |
| 1340 | AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */ |
| 1341 | AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */ |
| 1342 | AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */ |
| 1343 | }; |
| 1344 | |
| 1345 | struct amdgpu_ps { |
| 1346 | u32 caps; /* vbios flags */ |
| 1347 | u32 class; /* vbios flags */ |
| 1348 | u32 class2; /* vbios flags */ |
| 1349 | /* UVD clocks */ |
| 1350 | u32 vclk; |
| 1351 | u32 dclk; |
| 1352 | /* VCE clocks */ |
| 1353 | u32 evclk; |
| 1354 | u32 ecclk; |
| 1355 | bool vce_active; |
| 1356 | enum amdgpu_vce_level vce_level; |
| 1357 | /* asic priv */ |
| 1358 | void *ps_priv; |
| 1359 | }; |
| 1360 | |
| 1361 | struct amdgpu_dpm_thermal { |
| 1362 | /* thermal interrupt work */ |
| 1363 | struct work_struct work; |
| 1364 | /* low temperature threshold */ |
| 1365 | int min_temp; |
| 1366 | /* high temperature threshold */ |
| 1367 | int max_temp; |
| 1368 | /* was last interrupt low to high or high to low */ |
| 1369 | bool high_to_low; |
| 1370 | /* interrupt source */ |
| 1371 | struct amdgpu_irq_src irq; |
| 1372 | }; |
| 1373 | |
| 1374 | enum amdgpu_clk_action |
| 1375 | { |
| 1376 | AMDGPU_SCLK_UP = 1, |
| 1377 | AMDGPU_SCLK_DOWN |
| 1378 | }; |
| 1379 | |
| 1380 | struct amdgpu_blacklist_clocks |
| 1381 | { |
| 1382 | u32 sclk; |
| 1383 | u32 mclk; |
| 1384 | enum amdgpu_clk_action action; |
| 1385 | }; |
| 1386 | |
| 1387 | struct amdgpu_clock_and_voltage_limits { |
| 1388 | u32 sclk; |
| 1389 | u32 mclk; |
| 1390 | u16 vddc; |
| 1391 | u16 vddci; |
| 1392 | }; |
| 1393 | |
| 1394 | struct amdgpu_clock_array { |
| 1395 | u32 count; |
| 1396 | u32 *values; |
| 1397 | }; |
| 1398 | |
| 1399 | struct amdgpu_clock_voltage_dependency_entry { |
| 1400 | u32 clk; |
| 1401 | u16 v; |
| 1402 | }; |
| 1403 | |
| 1404 | struct amdgpu_clock_voltage_dependency_table { |
| 1405 | u32 count; |
| 1406 | struct amdgpu_clock_voltage_dependency_entry *entries; |
| 1407 | }; |
| 1408 | |
| 1409 | union amdgpu_cac_leakage_entry { |
| 1410 | struct { |
| 1411 | u16 vddc; |
| 1412 | u32 leakage; |
| 1413 | }; |
| 1414 | struct { |
| 1415 | u16 vddc1; |
| 1416 | u16 vddc2; |
| 1417 | u16 vddc3; |
| 1418 | }; |
| 1419 | }; |
| 1420 | |
| 1421 | struct amdgpu_cac_leakage_table { |
| 1422 | u32 count; |
| 1423 | union amdgpu_cac_leakage_entry *entries; |
| 1424 | }; |
| 1425 | |
| 1426 | struct amdgpu_phase_shedding_limits_entry { |
| 1427 | u16 voltage; |
| 1428 | u32 sclk; |
| 1429 | u32 mclk; |
| 1430 | }; |
| 1431 | |
| 1432 | struct amdgpu_phase_shedding_limits_table { |
| 1433 | u32 count; |
| 1434 | struct amdgpu_phase_shedding_limits_entry *entries; |
| 1435 | }; |
| 1436 | |
| 1437 | struct amdgpu_uvd_clock_voltage_dependency_entry { |
| 1438 | u32 vclk; |
| 1439 | u32 dclk; |
| 1440 | u16 v; |
| 1441 | }; |
| 1442 | |
| 1443 | struct amdgpu_uvd_clock_voltage_dependency_table { |
| 1444 | u8 count; |
| 1445 | struct amdgpu_uvd_clock_voltage_dependency_entry *entries; |
| 1446 | }; |
| 1447 | |
| 1448 | struct amdgpu_vce_clock_voltage_dependency_entry { |
| 1449 | u32 ecclk; |
| 1450 | u32 evclk; |
| 1451 | u16 v; |
| 1452 | }; |
| 1453 | |
| 1454 | struct amdgpu_vce_clock_voltage_dependency_table { |
| 1455 | u8 count; |
| 1456 | struct amdgpu_vce_clock_voltage_dependency_entry *entries; |
| 1457 | }; |
| 1458 | |
| 1459 | struct amdgpu_ppm_table { |
| 1460 | u8 ppm_design; |
| 1461 | u16 cpu_core_number; |
| 1462 | u32 platform_tdp; |
| 1463 | u32 small_ac_platform_tdp; |
| 1464 | u32 platform_tdc; |
| 1465 | u32 small_ac_platform_tdc; |
| 1466 | u32 apu_tdp; |
| 1467 | u32 dgpu_tdp; |
| 1468 | u32 dgpu_ulv_power; |
| 1469 | u32 tj_max; |
| 1470 | }; |
| 1471 | |
| 1472 | struct amdgpu_cac_tdp_table { |
| 1473 | u16 tdp; |
| 1474 | u16 configurable_tdp; |
| 1475 | u16 tdc; |
| 1476 | u16 battery_power_limit; |
| 1477 | u16 small_power_limit; |
| 1478 | u16 low_cac_leakage; |
| 1479 | u16 high_cac_leakage; |
| 1480 | u16 maximum_power_delivery_limit; |
| 1481 | }; |
| 1482 | |
| 1483 | struct amdgpu_dpm_dynamic_state { |
| 1484 | struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk; |
| 1485 | struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk; |
| 1486 | struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk; |
| 1487 | struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk; |
| 1488 | struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk; |
| 1489 | struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table; |
| 1490 | struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table; |
| 1491 | struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table; |
| 1492 | struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table; |
| 1493 | struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk; |
| 1494 | struct amdgpu_clock_array valid_sclk_values; |
| 1495 | struct amdgpu_clock_array valid_mclk_values; |
| 1496 | struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc; |
| 1497 | struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac; |
| 1498 | u32 mclk_sclk_ratio; |
| 1499 | u32 sclk_mclk_delta; |
| 1500 | u16 vddc_vddci_delta; |
| 1501 | u16 min_vddc_for_pcie_gen2; |
| 1502 | struct amdgpu_cac_leakage_table cac_leakage_table; |
| 1503 | struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table; |
| 1504 | struct amdgpu_ppm_table *ppm_table; |
| 1505 | struct amdgpu_cac_tdp_table *cac_tdp_table; |
| 1506 | }; |
| 1507 | |
| 1508 | struct amdgpu_dpm_fan { |
| 1509 | u16 t_min; |
| 1510 | u16 t_med; |
| 1511 | u16 t_high; |
| 1512 | u16 pwm_min; |
| 1513 | u16 pwm_med; |
| 1514 | u16 pwm_high; |
| 1515 | u8 t_hyst; |
| 1516 | u32 cycle_delay; |
| 1517 | u16 t_max; |
| 1518 | u8 control_mode; |
| 1519 | u16 default_max_fan_pwm; |
| 1520 | u16 default_fan_output_sensitivity; |
| 1521 | u16 fan_output_sensitivity; |
| 1522 | bool ucode_fan_control; |
| 1523 | }; |
| 1524 | |
| 1525 | enum amdgpu_pcie_gen { |
| 1526 | AMDGPU_PCIE_GEN1 = 0, |
| 1527 | AMDGPU_PCIE_GEN2 = 1, |
| 1528 | AMDGPU_PCIE_GEN3 = 2, |
| 1529 | AMDGPU_PCIE_GEN_INVALID = 0xffff |
| 1530 | }; |
| 1531 | |
| 1532 | enum amdgpu_dpm_forced_level { |
| 1533 | AMDGPU_DPM_FORCED_LEVEL_AUTO = 0, |
| 1534 | AMDGPU_DPM_FORCED_LEVEL_LOW = 1, |
| 1535 | AMDGPU_DPM_FORCED_LEVEL_HIGH = 2, |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 1536 | AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1537 | }; |
| 1538 | |
| 1539 | struct amdgpu_vce_state { |
| 1540 | /* vce clocks */ |
| 1541 | u32 evclk; |
| 1542 | u32 ecclk; |
| 1543 | /* gpu clocks */ |
| 1544 | u32 sclk; |
| 1545 | u32 mclk; |
| 1546 | u8 clk_idx; |
| 1547 | u8 pstate; |
| 1548 | }; |
| 1549 | |
| 1550 | struct amdgpu_dpm_funcs { |
| 1551 | int (*get_temperature)(struct amdgpu_device *adev); |
| 1552 | int (*pre_set_power_state)(struct amdgpu_device *adev); |
| 1553 | int (*set_power_state)(struct amdgpu_device *adev); |
| 1554 | void (*post_set_power_state)(struct amdgpu_device *adev); |
| 1555 | void (*display_configuration_changed)(struct amdgpu_device *adev); |
| 1556 | u32 (*get_sclk)(struct amdgpu_device *adev, bool low); |
| 1557 | u32 (*get_mclk)(struct amdgpu_device *adev, bool low); |
| 1558 | void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps); |
| 1559 | void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m); |
| 1560 | int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level); |
| 1561 | bool (*vblank_too_short)(struct amdgpu_device *adev); |
| 1562 | void (*powergate_uvd)(struct amdgpu_device *adev, bool gate); |
Sonny Jiang | b7a0776 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1563 | void (*powergate_vce)(struct amdgpu_device *adev, bool gate); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1564 | void (*enable_bapm)(struct amdgpu_device *adev, bool enable); |
| 1565 | void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode); |
| 1566 | u32 (*get_fan_control_mode)(struct amdgpu_device *adev); |
| 1567 | int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed); |
| 1568 | int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed); |
Eric Huang | c85e299 | 2016-05-19 15:41:25 -0400 | [diff] [blame] | 1569 | int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask); |
| 1570 | int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf); |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 1571 | int (*get_sclk_od)(struct amdgpu_device *adev); |
| 1572 | int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 1573 | int (*get_mclk_od)(struct amdgpu_device *adev); |
| 1574 | int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1575 | }; |
| 1576 | |
| 1577 | struct amdgpu_dpm { |
| 1578 | struct amdgpu_ps *ps; |
| 1579 | /* number of valid power states */ |
| 1580 | int num_ps; |
| 1581 | /* current power state that is active */ |
| 1582 | struct amdgpu_ps *current_ps; |
| 1583 | /* requested power state */ |
| 1584 | struct amdgpu_ps *requested_ps; |
| 1585 | /* boot up power state */ |
| 1586 | struct amdgpu_ps *boot_ps; |
| 1587 | /* default uvd power state */ |
| 1588 | struct amdgpu_ps *uvd_ps; |
| 1589 | /* vce requirements */ |
| 1590 | struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS]; |
| 1591 | enum amdgpu_vce_level vce_level; |
Rex Zhu | 3a2c788 | 2015-08-25 15:57:43 +0800 | [diff] [blame] | 1592 | enum amd_pm_state_type state; |
| 1593 | enum amd_pm_state_type user_state; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1594 | u32 platform_caps; |
| 1595 | u32 voltage_response_time; |
| 1596 | u32 backbias_response_time; |
| 1597 | void *priv; |
| 1598 | u32 new_active_crtcs; |
| 1599 | int new_active_crtc_count; |
| 1600 | u32 current_active_crtcs; |
| 1601 | int current_active_crtc_count; |
| 1602 | struct amdgpu_dpm_dynamic_state dyn_state; |
| 1603 | struct amdgpu_dpm_fan fan; |
| 1604 | u32 tdp_limit; |
| 1605 | u32 near_tdp_limit; |
| 1606 | u32 near_tdp_limit_adjusted; |
| 1607 | u32 sq_ramping_threshold; |
| 1608 | u32 cac_leakage; |
| 1609 | u16 tdp_od_limit; |
| 1610 | u32 tdp_adjustment; |
| 1611 | u16 load_line_slope; |
| 1612 | bool power_control; |
| 1613 | bool ac_power; |
| 1614 | /* special states active */ |
| 1615 | bool thermal_active; |
| 1616 | bool uvd_active; |
| 1617 | bool vce_active; |
| 1618 | /* thermal handling */ |
| 1619 | struct amdgpu_dpm_thermal thermal; |
| 1620 | /* forced levels */ |
| 1621 | enum amdgpu_dpm_forced_level forced_level; |
| 1622 | }; |
| 1623 | |
| 1624 | struct amdgpu_pm { |
| 1625 | struct mutex mutex; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1626 | u32 current_sclk; |
| 1627 | u32 current_mclk; |
| 1628 | u32 default_sclk; |
| 1629 | u32 default_mclk; |
| 1630 | struct amdgpu_i2c_chan *i2c_bus; |
| 1631 | /* internal thermal controller on rv6xx+ */ |
| 1632 | enum amdgpu_int_thermal_type int_thermal_type; |
| 1633 | struct device *int_hwmon_dev; |
| 1634 | /* fan control parameters */ |
| 1635 | bool no_fan; |
| 1636 | u8 fan_pulses_per_revolution; |
| 1637 | u8 fan_min_rpm; |
| 1638 | u8 fan_max_rpm; |
| 1639 | /* dpm */ |
| 1640 | bool dpm_enabled; |
Alex Deucher | c86f5ebf | 2015-10-23 10:45:14 -0400 | [diff] [blame] | 1641 | bool sysfs_initialized; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1642 | struct amdgpu_dpm dpm; |
| 1643 | const struct firmware *fw; /* SMC firmware */ |
| 1644 | uint32_t fw_version; |
| 1645 | const struct amdgpu_dpm_funcs *funcs; |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 1646 | uint32_t pcie_gen_mask; |
| 1647 | uint32_t pcie_mlw_mask; |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1648 | struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */ |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1649 | }; |
| 1650 | |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 1651 | void amdgpu_get_pcie_info(struct amdgpu_device *adev); |
| 1652 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1653 | /* |
| 1654 | * UVD |
| 1655 | */ |
Arindam Nath | c036554 | 2016-04-12 13:46:15 +0200 | [diff] [blame] | 1656 | #define AMDGPU_DEFAULT_UVD_HANDLES 10 |
| 1657 | #define AMDGPU_MAX_UVD_HANDLES 40 |
| 1658 | #define AMDGPU_UVD_STACK_SIZE (200*1024) |
| 1659 | #define AMDGPU_UVD_HEAP_SIZE (256*1024) |
| 1660 | #define AMDGPU_UVD_SESSION_SIZE (50*1024) |
| 1661 | #define AMDGPU_UVD_FIRMWARE_OFFSET 256 |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1662 | |
| 1663 | struct amdgpu_uvd { |
| 1664 | struct amdgpu_bo *vcpu_bo; |
| 1665 | void *cpu_addr; |
| 1666 | uint64_t gpu_addr; |
Sonny Jiang | 562e268 | 2016-04-18 16:05:04 -0400 | [diff] [blame] | 1667 | unsigned fw_version; |
Leo Liu | 3f99dd8 | 2016-04-01 10:36:06 -0400 | [diff] [blame] | 1668 | void *saved_bo; |
Arindam Nath | c036554 | 2016-04-12 13:46:15 +0200 | [diff] [blame] | 1669 | unsigned max_handles; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1670 | atomic_t handles[AMDGPU_MAX_UVD_HANDLES]; |
| 1671 | struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES]; |
| 1672 | struct delayed_work idle_work; |
| 1673 | const struct firmware *fw; /* UVD firmware */ |
| 1674 | struct amdgpu_ring ring; |
| 1675 | struct amdgpu_irq_src irq; |
| 1676 | bool address_64_bit; |
Christian König | ead833e | 2016-02-10 14:35:19 +0100 | [diff] [blame] | 1677 | struct amd_sched_entity entity; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1678 | }; |
| 1679 | |
| 1680 | /* |
| 1681 | * VCE |
| 1682 | */ |
| 1683 | #define AMDGPU_MAX_VCE_HANDLES 16 |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1684 | #define AMDGPU_VCE_FIRMWARE_OFFSET 256 |
| 1685 | |
Alex Deucher | 6a58577 | 2015-07-10 14:16:24 -0400 | [diff] [blame] | 1686 | #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0) |
| 1687 | #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1) |
| 1688 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1689 | struct amdgpu_vce { |
| 1690 | struct amdgpu_bo *vcpu_bo; |
| 1691 | uint64_t gpu_addr; |
| 1692 | unsigned fw_version; |
| 1693 | unsigned fb_version; |
| 1694 | atomic_t handles[AMDGPU_MAX_VCE_HANDLES]; |
| 1695 | struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES]; |
Christian König | f1689ec | 2015-06-11 20:56:18 +0200 | [diff] [blame] | 1696 | uint32_t img_size[AMDGPU_MAX_VCE_HANDLES]; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1697 | struct delayed_work idle_work; |
| 1698 | const struct firmware *fw; /* VCE firmware */ |
| 1699 | struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS]; |
| 1700 | struct amdgpu_irq_src irq; |
Alex Deucher | 6a58577 | 2015-07-10 14:16:24 -0400 | [diff] [blame] | 1701 | unsigned harvest_config; |
Christian König | c594989 | 2016-02-10 17:43:00 +0100 | [diff] [blame] | 1702 | struct amd_sched_entity entity; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1703 | }; |
| 1704 | |
| 1705 | /* |
| 1706 | * SDMA |
| 1707 | */ |
Alex Deucher | c113ea1 | 2015-10-08 16:30:37 -0400 | [diff] [blame] | 1708 | struct amdgpu_sdma_instance { |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1709 | /* SDMA firmware */ |
| 1710 | const struct firmware *fw; |
| 1711 | uint32_t fw_version; |
Jammy Zhou | cfa2104 | 2015-08-04 10:50:47 +0800 | [diff] [blame] | 1712 | uint32_t feature_version; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1713 | |
| 1714 | struct amdgpu_ring ring; |
Jammy Zhou | 18111de | 2015-08-31 14:06:39 +0800 | [diff] [blame] | 1715 | bool burst_nop; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1716 | }; |
| 1717 | |
Alex Deucher | c113ea1 | 2015-10-08 16:30:37 -0400 | [diff] [blame] | 1718 | struct amdgpu_sdma { |
| 1719 | struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES]; |
| 1720 | struct amdgpu_irq_src trap_irq; |
| 1721 | struct amdgpu_irq_src illegal_inst_irq; |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 1722 | int num_instances; |
Alex Deucher | c113ea1 | 2015-10-08 16:30:37 -0400 | [diff] [blame] | 1723 | }; |
| 1724 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1725 | /* |
| 1726 | * Firmware |
| 1727 | */ |
| 1728 | struct amdgpu_firmware { |
| 1729 | struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM]; |
| 1730 | bool smu_load; |
| 1731 | struct amdgpu_bo *fw_buf; |
| 1732 | unsigned int fw_size; |
| 1733 | }; |
| 1734 | |
| 1735 | /* |
| 1736 | * Benchmarking |
| 1737 | */ |
| 1738 | void amdgpu_benchmark(struct amdgpu_device *adev, int test_number); |
| 1739 | |
| 1740 | |
| 1741 | /* |
| 1742 | * Testing |
| 1743 | */ |
| 1744 | void amdgpu_test_moves(struct amdgpu_device *adev); |
| 1745 | void amdgpu_test_ring_sync(struct amdgpu_device *adev, |
| 1746 | struct amdgpu_ring *cpA, |
| 1747 | struct amdgpu_ring *cpB); |
| 1748 | void amdgpu_test_syncing(struct amdgpu_device *adev); |
| 1749 | |
| 1750 | /* |
| 1751 | * MMU Notifier |
| 1752 | */ |
| 1753 | #if defined(CONFIG_MMU_NOTIFIER) |
| 1754 | int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr); |
| 1755 | void amdgpu_mn_unregister(struct amdgpu_bo *bo); |
| 1756 | #else |
Harry Wentland | 1d1106b | 2015-07-15 07:10:41 -0400 | [diff] [blame] | 1757 | static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1758 | { |
| 1759 | return -ENODEV; |
| 1760 | } |
Harry Wentland | 1d1106b | 2015-07-15 07:10:41 -0400 | [diff] [blame] | 1761 | static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {} |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1762 | #endif |
| 1763 | |
| 1764 | /* |
| 1765 | * Debugfs |
| 1766 | */ |
| 1767 | struct amdgpu_debugfs { |
Nils Wallménius | 06ab683 | 2016-05-02 12:46:15 -0400 | [diff] [blame] | 1768 | const struct drm_info_list *files; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1769 | unsigned num_files; |
| 1770 | }; |
| 1771 | |
| 1772 | int amdgpu_debugfs_add_files(struct amdgpu_device *adev, |
Nils Wallménius | 06ab683 | 2016-05-02 12:46:15 -0400 | [diff] [blame] | 1773 | const struct drm_info_list *files, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1774 | unsigned nfiles); |
| 1775 | int amdgpu_debugfs_fence_init(struct amdgpu_device *adev); |
| 1776 | |
| 1777 | #if defined(CONFIG_DEBUG_FS) |
| 1778 | int amdgpu_debugfs_init(struct drm_minor *minor); |
| 1779 | void amdgpu_debugfs_cleanup(struct drm_minor *minor); |
| 1780 | #endif |
| 1781 | |
| 1782 | /* |
| 1783 | * amdgpu smumgr functions |
| 1784 | */ |
| 1785 | struct amdgpu_smumgr_funcs { |
| 1786 | int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype); |
| 1787 | int (*request_smu_load_fw)(struct amdgpu_device *adev); |
| 1788 | int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype); |
| 1789 | }; |
| 1790 | |
| 1791 | /* |
| 1792 | * amdgpu smumgr |
| 1793 | */ |
| 1794 | struct amdgpu_smumgr { |
| 1795 | struct amdgpu_bo *toc_buf; |
| 1796 | struct amdgpu_bo *smu_buf; |
| 1797 | /* asic priv smu data */ |
| 1798 | void *priv; |
| 1799 | spinlock_t smu_lock; |
| 1800 | /* smumgr functions */ |
| 1801 | const struct amdgpu_smumgr_funcs *smumgr_funcs; |
| 1802 | /* ucode loading complete flag */ |
| 1803 | uint32_t fw_flags; |
| 1804 | }; |
| 1805 | |
| 1806 | /* |
| 1807 | * ASIC specific register table accessible by UMD |
| 1808 | */ |
| 1809 | struct amdgpu_allowed_register_entry { |
| 1810 | uint32_t reg_offset; |
| 1811 | bool untouched; |
| 1812 | bool grbm_indexed; |
| 1813 | }; |
| 1814 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1815 | /* |
| 1816 | * ASIC specific functions. |
| 1817 | */ |
| 1818 | struct amdgpu_asic_funcs { |
| 1819 | bool (*read_disabled_bios)(struct amdgpu_device *adev); |
Alex Deucher | 7946b87 | 2015-11-24 10:14:28 -0500 | [diff] [blame] | 1820 | bool (*read_bios_from_rom)(struct amdgpu_device *adev, |
| 1821 | u8 *bios, u32 length_bytes); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1822 | int (*read_register)(struct amdgpu_device *adev, u32 se_num, |
| 1823 | u32 sh_num, u32 reg_offset, u32 *value); |
| 1824 | void (*set_vga_state)(struct amdgpu_device *adev, bool state); |
| 1825 | int (*reset)(struct amdgpu_device *adev); |
| 1826 | /* wait for mc_idle */ |
| 1827 | int (*wait_for_mc_idle)(struct amdgpu_device *adev); |
| 1828 | /* get the reference clock */ |
| 1829 | u32 (*get_xclk)(struct amdgpu_device *adev); |
| 1830 | /* get the gpu clock counter */ |
| 1831 | uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1832 | /* MM block clocks */ |
| 1833 | int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk); |
| 1834 | int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk); |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1835 | /* query virtual capabilities */ |
| 1836 | u32 (*get_virtual_caps)(struct amdgpu_device *adev); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1837 | }; |
| 1838 | |
| 1839 | /* |
| 1840 | * IOCTL. |
| 1841 | */ |
| 1842 | int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, |
| 1843 | struct drm_file *filp); |
| 1844 | int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, |
| 1845 | struct drm_file *filp); |
| 1846 | |
| 1847 | int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, |
| 1848 | struct drm_file *filp); |
| 1849 | int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, |
| 1850 | struct drm_file *filp); |
| 1851 | int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data, |
| 1852 | struct drm_file *filp); |
| 1853 | int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data, |
| 1854 | struct drm_file *filp); |
| 1855 | int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, |
| 1856 | struct drm_file *filp); |
| 1857 | int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, |
| 1858 | struct drm_file *filp); |
| 1859 | int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); |
| 1860 | int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); |
| 1861 | |
| 1862 | int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data, |
| 1863 | struct drm_file *filp); |
| 1864 | |
| 1865 | /* VRAM scratch page for HDP bug, default vram page */ |
| 1866 | struct amdgpu_vram_scratch { |
| 1867 | struct amdgpu_bo *robj; |
| 1868 | volatile uint32_t *ptr; |
| 1869 | u64 gpu_addr; |
| 1870 | }; |
| 1871 | |
| 1872 | /* |
| 1873 | * ACPI |
| 1874 | */ |
| 1875 | struct amdgpu_atif_notification_cfg { |
| 1876 | bool enabled; |
| 1877 | int command_code; |
| 1878 | }; |
| 1879 | |
| 1880 | struct amdgpu_atif_notifications { |
| 1881 | bool display_switch; |
| 1882 | bool expansion_mode_change; |
| 1883 | bool thermal_state; |
| 1884 | bool forced_power_state; |
| 1885 | bool system_power_state; |
| 1886 | bool display_conf_change; |
| 1887 | bool px_gfx_switch; |
| 1888 | bool brightness_change; |
| 1889 | bool dgpu_display_event; |
| 1890 | }; |
| 1891 | |
| 1892 | struct amdgpu_atif_functions { |
| 1893 | bool system_params; |
| 1894 | bool sbios_requests; |
| 1895 | bool select_active_disp; |
| 1896 | bool lid_state; |
| 1897 | bool get_tv_standard; |
| 1898 | bool set_tv_standard; |
| 1899 | bool get_panel_expansion_mode; |
| 1900 | bool set_panel_expansion_mode; |
| 1901 | bool temperature_change; |
| 1902 | bool graphics_device_types; |
| 1903 | }; |
| 1904 | |
| 1905 | struct amdgpu_atif { |
| 1906 | struct amdgpu_atif_notifications notifications; |
| 1907 | struct amdgpu_atif_functions functions; |
| 1908 | struct amdgpu_atif_notification_cfg notification_cfg; |
| 1909 | struct amdgpu_encoder *encoder_for_bl; |
| 1910 | }; |
| 1911 | |
| 1912 | struct amdgpu_atcs_functions { |
| 1913 | bool get_ext_state; |
| 1914 | bool pcie_perf_req; |
| 1915 | bool pcie_dev_rdy; |
| 1916 | bool pcie_bus_width; |
| 1917 | }; |
| 1918 | |
| 1919 | struct amdgpu_atcs { |
| 1920 | struct amdgpu_atcs_functions functions; |
| 1921 | }; |
| 1922 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1923 | /* |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 1924 | * CGS |
| 1925 | */ |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 1926 | struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev); |
| 1927 | void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device); |
Maruthi Bayyavarapu | a8fe58c | 2015-09-22 17:05:20 -0400 | [diff] [blame] | 1928 | |
| 1929 | |
Alex Deucher | 7e471e6 | 2016-02-01 11:13:04 -0500 | [diff] [blame] | 1930 | /* GPU virtualization */ |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1931 | #define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0) |
| 1932 | #define AMDGPU_VIRT_CAPS_IS_VF (1 << 1) |
Alex Deucher | 7e471e6 | 2016-02-01 11:13:04 -0500 | [diff] [blame] | 1933 | struct amdgpu_virtualization { |
| 1934 | bool supports_sr_iov; |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1935 | bool is_virtual; |
| 1936 | u32 caps; |
Alex Deucher | 7e471e6 | 2016-02-01 11:13:04 -0500 | [diff] [blame] | 1937 | }; |
| 1938 | |
Maruthi Bayyavarapu | a8fe58c | 2015-09-22 17:05:20 -0400 | [diff] [blame] | 1939 | /* |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1940 | * Core structure, functions and helpers. |
| 1941 | */ |
| 1942 | typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t); |
| 1943 | typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t); |
| 1944 | |
| 1945 | typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t); |
| 1946 | typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t); |
| 1947 | |
Alex Deucher | 8faf0e0 | 2015-07-28 11:50:31 -0400 | [diff] [blame] | 1948 | struct amdgpu_ip_block_status { |
| 1949 | bool valid; |
| 1950 | bool sw; |
| 1951 | bool hw; |
| 1952 | }; |
| 1953 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1954 | struct amdgpu_device { |
| 1955 | struct device *dev; |
| 1956 | struct drm_device *ddev; |
| 1957 | struct pci_dev *pdev; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1958 | |
Maruthi Bayyavarapu | a8fe58c | 2015-09-22 17:05:20 -0400 | [diff] [blame] | 1959 | #ifdef CONFIG_DRM_AMD_ACP |
| 1960 | struct amdgpu_acp acp; |
| 1961 | #endif |
| 1962 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1963 | /* ASIC */ |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 1964 | enum amd_asic_type asic_type; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1965 | uint32_t family; |
| 1966 | uint32_t rev_id; |
| 1967 | uint32_t external_rev_id; |
| 1968 | unsigned long flags; |
| 1969 | int usec_timeout; |
| 1970 | const struct amdgpu_asic_funcs *asic_funcs; |
| 1971 | bool shutdown; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1972 | bool need_dma32; |
| 1973 | bool accel_working; |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 1974 | struct work_struct reset_work; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1975 | struct notifier_block acpi_nb; |
| 1976 | struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS]; |
| 1977 | struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 1978 | unsigned debugfs_count; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1979 | #if defined(CONFIG_DEBUG_FS) |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 1980 | struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS]; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1981 | #endif |
| 1982 | struct amdgpu_atif atif; |
| 1983 | struct amdgpu_atcs atcs; |
| 1984 | struct mutex srbm_mutex; |
| 1985 | /* GRBM index mutex. Protects concurrent access to GRBM index */ |
| 1986 | struct mutex grbm_idx_mutex; |
| 1987 | struct dev_pm_domain vga_pm_domain; |
| 1988 | bool have_disp_power_ref; |
| 1989 | |
| 1990 | /* BIOS */ |
| 1991 | uint8_t *bios; |
| 1992 | bool is_atom_bios; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 1993 | struct amdgpu_bo *stollen_vga_memory; |
| 1994 | uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH]; |
| 1995 | |
| 1996 | /* Register/doorbell mmio */ |
| 1997 | resource_size_t rmmio_base; |
| 1998 | resource_size_t rmmio_size; |
| 1999 | void __iomem *rmmio; |
| 2000 | /* protects concurrent MM_INDEX/DATA based register access */ |
| 2001 | spinlock_t mmio_idx_lock; |
| 2002 | /* protects concurrent SMC based register access */ |
| 2003 | spinlock_t smc_idx_lock; |
| 2004 | amdgpu_rreg_t smc_rreg; |
| 2005 | amdgpu_wreg_t smc_wreg; |
| 2006 | /* protects concurrent PCIE register access */ |
| 2007 | spinlock_t pcie_idx_lock; |
| 2008 | amdgpu_rreg_t pcie_rreg; |
| 2009 | amdgpu_wreg_t pcie_wreg; |
| 2010 | /* protects concurrent UVD register access */ |
| 2011 | spinlock_t uvd_ctx_idx_lock; |
| 2012 | amdgpu_rreg_t uvd_ctx_rreg; |
| 2013 | amdgpu_wreg_t uvd_ctx_wreg; |
| 2014 | /* protects concurrent DIDT register access */ |
| 2015 | spinlock_t didt_idx_lock; |
| 2016 | amdgpu_rreg_t didt_rreg; |
| 2017 | amdgpu_wreg_t didt_wreg; |
| 2018 | /* protects concurrent ENDPOINT (audio) register access */ |
| 2019 | spinlock_t audio_endpt_idx_lock; |
| 2020 | amdgpu_block_rreg_t audio_endpt_rreg; |
| 2021 | amdgpu_block_wreg_t audio_endpt_wreg; |
| 2022 | void __iomem *rio_mem; |
| 2023 | resource_size_t rio_mem_size; |
| 2024 | struct amdgpu_doorbell doorbell; |
| 2025 | |
| 2026 | /* clock/pll info */ |
| 2027 | struct amdgpu_clock clock; |
| 2028 | |
| 2029 | /* MC */ |
| 2030 | struct amdgpu_mc mc; |
| 2031 | struct amdgpu_gart gart; |
| 2032 | struct amdgpu_dummy_page dummy_page; |
| 2033 | struct amdgpu_vm_manager vm_manager; |
| 2034 | |
| 2035 | /* memory management */ |
| 2036 | struct amdgpu_mman mman; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2037 | struct amdgpu_vram_scratch vram_scratch; |
| 2038 | struct amdgpu_wb wb; |
| 2039 | atomic64_t vram_usage; |
| 2040 | atomic64_t vram_vis_usage; |
| 2041 | atomic64_t gtt_usage; |
| 2042 | atomic64_t num_bytes_moved; |
Marek Olšák | d94aed5 | 2015-05-05 21:13:49 +0200 | [diff] [blame] | 2043 | atomic_t gpu_reset_counter; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2044 | |
| 2045 | /* display */ |
| 2046 | struct amdgpu_mode_info mode_info; |
| 2047 | struct work_struct hotplug_work; |
| 2048 | struct amdgpu_irq_src crtc_irq; |
| 2049 | struct amdgpu_irq_src pageflip_irq; |
| 2050 | struct amdgpu_irq_src hpd_irq; |
| 2051 | |
| 2052 | /* rings */ |
Christian König | 76bf0db | 2016-06-01 15:10:02 +0200 | [diff] [blame] | 2053 | u64 fence_context; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2054 | unsigned num_rings; |
| 2055 | struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; |
| 2056 | bool ib_pool_ready; |
| 2057 | struct amdgpu_sa_manager ring_tmp_bo; |
| 2058 | |
| 2059 | /* interrupts */ |
| 2060 | struct amdgpu_irq irq; |
| 2061 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 2062 | /* powerplay */ |
| 2063 | struct amd_powerplay powerplay; |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2064 | bool pp_enabled; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 2065 | bool pp_force_state_enabled; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 2066 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2067 | /* dpm */ |
| 2068 | struct amdgpu_pm pm; |
| 2069 | u32 cg_flags; |
| 2070 | u32 pg_flags; |
| 2071 | |
| 2072 | /* amdgpu smumgr */ |
| 2073 | struct amdgpu_smumgr smu; |
| 2074 | |
| 2075 | /* gfx */ |
| 2076 | struct amdgpu_gfx gfx; |
| 2077 | |
| 2078 | /* sdma */ |
Alex Deucher | c113ea1 | 2015-10-08 16:30:37 -0400 | [diff] [blame] | 2079 | struct amdgpu_sdma sdma; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2080 | |
| 2081 | /* uvd */ |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2082 | struct amdgpu_uvd uvd; |
| 2083 | |
| 2084 | /* vce */ |
| 2085 | struct amdgpu_vce vce; |
| 2086 | |
| 2087 | /* firmwares */ |
| 2088 | struct amdgpu_firmware firmware; |
| 2089 | |
| 2090 | /* GDS */ |
| 2091 | struct amdgpu_gds gds; |
| 2092 | |
| 2093 | const struct amdgpu_ip_block_version *ip_blocks; |
| 2094 | int num_ip_blocks; |
Alex Deucher | 8faf0e0 | 2015-07-28 11:50:31 -0400 | [diff] [blame] | 2095 | struct amdgpu_ip_block_status *ip_block_status; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2096 | struct mutex mn_lock; |
| 2097 | DECLARE_HASHTABLE(mn_hash, 7); |
| 2098 | |
| 2099 | /* tracking pinned memory */ |
| 2100 | u64 vram_pin_size; |
Chunming Zhou | e131b91 | 2016-04-05 10:48:48 +0800 | [diff] [blame] | 2101 | u64 invisible_pin_size; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2102 | u64 gart_pin_size; |
Oded Gabbay | 130e037 | 2015-06-12 21:35:14 +0300 | [diff] [blame] | 2103 | |
| 2104 | /* amdkfd interface */ |
| 2105 | struct kfd_dev *kfd; |
Chunming Zhou | 23ca0e4 | 2015-07-06 13:42:58 +0800 | [diff] [blame] | 2106 | |
Alex Deucher | 7e471e6 | 2016-02-01 11:13:04 -0500 | [diff] [blame] | 2107 | struct amdgpu_virtualization virtualization; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2108 | }; |
| 2109 | |
| 2110 | bool amdgpu_device_is_px(struct drm_device *dev); |
| 2111 | int amdgpu_device_init(struct amdgpu_device *adev, |
| 2112 | struct drm_device *ddev, |
| 2113 | struct pci_dev *pdev, |
| 2114 | uint32_t flags); |
| 2115 | void amdgpu_device_fini(struct amdgpu_device *adev); |
| 2116 | int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); |
| 2117 | |
| 2118 | uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, |
| 2119 | bool always_indirect); |
| 2120 | void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, |
| 2121 | bool always_indirect); |
| 2122 | u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg); |
| 2123 | void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v); |
| 2124 | |
| 2125 | u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index); |
| 2126 | void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v); |
| 2127 | |
| 2128 | /* |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2129 | * Registers read & write functions. |
| 2130 | */ |
| 2131 | #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false) |
| 2132 | #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true) |
| 2133 | #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false)) |
| 2134 | #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false) |
| 2135 | #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true) |
| 2136 | #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) |
| 2137 | #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) |
| 2138 | #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg)) |
| 2139 | #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v)) |
| 2140 | #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg)) |
| 2141 | #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v)) |
| 2142 | #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg)) |
| 2143 | #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v)) |
| 2144 | #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg)) |
| 2145 | #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v)) |
| 2146 | #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg)) |
| 2147 | #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v)) |
| 2148 | #define WREG32_P(reg, val, mask) \ |
| 2149 | do { \ |
| 2150 | uint32_t tmp_ = RREG32(reg); \ |
| 2151 | tmp_ &= (mask); \ |
| 2152 | tmp_ |= ((val) & ~(mask)); \ |
| 2153 | WREG32(reg, tmp_); \ |
| 2154 | } while (0) |
| 2155 | #define WREG32_AND(reg, and) WREG32_P(reg, 0, and) |
| 2156 | #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or)) |
| 2157 | #define WREG32_PLL_P(reg, val, mask) \ |
| 2158 | do { \ |
| 2159 | uint32_t tmp_ = RREG32_PLL(reg); \ |
| 2160 | tmp_ &= (mask); \ |
| 2161 | tmp_ |= ((val) & ~(mask)); \ |
| 2162 | WREG32_PLL(reg, tmp_); \ |
| 2163 | } while (0) |
| 2164 | #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false)) |
| 2165 | #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg)) |
| 2166 | #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v)) |
| 2167 | |
| 2168 | #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index)) |
| 2169 | #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v)) |
| 2170 | |
| 2171 | #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT |
| 2172 | #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK |
| 2173 | |
| 2174 | #define REG_SET_FIELD(orig_val, reg, field, field_val) \ |
| 2175 | (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \ |
| 2176 | (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) |
| 2177 | |
| 2178 | #define REG_GET_FIELD(value, reg, field) \ |
| 2179 | (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field)) |
| 2180 | |
| 2181 | /* |
| 2182 | * BIOS helpers. |
| 2183 | */ |
| 2184 | #define RBIOS8(i) (adev->bios[i]) |
| 2185 | #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8)) |
| 2186 | #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16)) |
| 2187 | |
| 2188 | /* |
| 2189 | * RING helpers. |
| 2190 | */ |
| 2191 | static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v) |
| 2192 | { |
| 2193 | if (ring->count_dw <= 0) |
Jammy Zhou | 86c2b79 | 2015-05-13 22:52:42 +0800 | [diff] [blame] | 2194 | DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n"); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2195 | ring->ring[ring->wptr++] = v; |
| 2196 | ring->wptr &= ring->ptr_mask; |
| 2197 | ring->count_dw--; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
Alex Deucher | c113ea1 | 2015-10-08 16:30:37 -0400 | [diff] [blame] | 2200 | static inline struct amdgpu_sdma_instance * |
| 2201 | amdgpu_get_sdma_instance(struct amdgpu_ring *ring) |
Jammy Zhou | 4b2f7e2 | 2015-09-01 12:56:17 +0800 | [diff] [blame] | 2202 | { |
| 2203 | struct amdgpu_device *adev = ring->adev; |
| 2204 | int i; |
| 2205 | |
Alex Deucher | c113ea1 | 2015-10-08 16:30:37 -0400 | [diff] [blame] | 2206 | for (i = 0; i < adev->sdma.num_instances; i++) |
| 2207 | if (&adev->sdma.instance[i].ring == ring) |
Jammy Zhou | 4b2f7e2 | 2015-09-01 12:56:17 +0800 | [diff] [blame] | 2208 | break; |
| 2209 | |
| 2210 | if (i < AMDGPU_MAX_SDMA_INSTANCES) |
Alex Deucher | c113ea1 | 2015-10-08 16:30:37 -0400 | [diff] [blame] | 2211 | return &adev->sdma.instance[i]; |
Jammy Zhou | 4b2f7e2 | 2015-09-01 12:56:17 +0800 | [diff] [blame] | 2212 | else |
| 2213 | return NULL; |
| 2214 | } |
| 2215 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2216 | /* |
| 2217 | * ASICs macro. |
| 2218 | */ |
| 2219 | #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state)) |
| 2220 | #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev)) |
| 2221 | #define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev)) |
| 2222 | #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev)) |
| 2223 | #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d)) |
| 2224 | #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec)) |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 2225 | #define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev))) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2226 | #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev)) |
| 2227 | #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev)) |
Alex Deucher | 7946b87 | 2015-11-24 10:14:28 -0500 | [diff] [blame] | 2228 | #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2229 | #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v))) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2230 | #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid)) |
| 2231 | #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags)) |
| 2232 | #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count))) |
Christian König | b07c9d2 | 2015-11-30 13:26:07 +0100 | [diff] [blame] | 2233 | #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))) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2234 | #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))) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2235 | #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib))) |
| 2236 | #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r)) |
| 2237 | #define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2238 | #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r)) |
| 2239 | #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r)) |
| 2240 | #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r)) |
Christian König | d88bf58 | 2016-05-06 17:50:03 +0200 | [diff] [blame] | 2241 | #define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c)) |
Christian König | b8c7b39 | 2016-03-01 15:42:52 +0100 | [diff] [blame] | 2242 | #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2243 | #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr)) |
Chunming Zhou | 890ee23 | 2015-06-01 14:35:03 +0800 | [diff] [blame] | 2244 | #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2245 | #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)) |
Christian König | d2edb07 | 2015-05-11 14:10:34 +0200 | [diff] [blame] | 2246 | #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r)) |
Chunming Zhou | 11afbde | 2016-03-03 11:38:48 +0800 | [diff] [blame] | 2247 | #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r)) |
Christian König | 9e5d5309 | 2016-01-31 12:20:55 +0100 | [diff] [blame] | 2248 | #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib))) |
Monk Liu | 03ccf48 | 2016-01-14 19:07:38 +0800 | [diff] [blame] | 2249 | #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r)) |
| 2250 | #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2251 | #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev)) |
| 2252 | #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv)) |
| 2253 | #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev)) |
| 2254 | #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r)) |
| 2255 | #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc)) |
| 2256 | #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc)) |
| 2257 | #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev)) |
| 2258 | #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l)) |
| 2259 | #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e)) |
| 2260 | #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h)) |
| 2261 | #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h)) |
| 2262 | #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev)) |
| 2263 | #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev)) |
Alex Deucher | cb9e59d | 2016-05-05 16:03:57 -0400 | [diff] [blame] | 2264 | #define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2265 | #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos)) |
| 2266 | #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c)) |
| 2267 | #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)) |
| 2268 | #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s)) |
| 2269 | #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s)) |
Chunming Zhou | c7ae72c | 2015-08-25 17:23:45 +0800 | [diff] [blame] | 2270 | #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b)) |
Chunming Zhou | 6e7a384 | 2015-08-27 13:46:09 +0800 | [diff] [blame] | 2271 | #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2272 | #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev)) |
| 2273 | #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev)) |
| 2274 | #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev)) |
| 2275 | #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2276 | #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2277 | #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2278 | #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e)) |
Rex Zhu | 3af76f2 | 2015-10-15 17:23:43 +0800 | [diff] [blame] | 2279 | |
| 2280 | #define amdgpu_dpm_get_temperature(adev) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2281 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2282 | (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2283 | (adev)->pm.funcs->get_temperature((adev))) |
Rex Zhu | 3af76f2 | 2015-10-15 17:23:43 +0800 | [diff] [blame] | 2284 | |
| 2285 | #define amdgpu_dpm_set_fan_control_mode(adev, m) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2286 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2287 | (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2288 | (adev)->pm.funcs->set_fan_control_mode((adev), (m))) |
Rex Zhu | 3af76f2 | 2015-10-15 17:23:43 +0800 | [diff] [blame] | 2289 | |
| 2290 | #define amdgpu_dpm_get_fan_control_mode(adev) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2291 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2292 | (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2293 | (adev)->pm.funcs->get_fan_control_mode((adev))) |
Rex Zhu | 3af76f2 | 2015-10-15 17:23:43 +0800 | [diff] [blame] | 2294 | |
| 2295 | #define amdgpu_dpm_set_fan_speed_percent(adev, s) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2296 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2297 | (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2298 | (adev)->pm.funcs->set_fan_speed_percent((adev), (s))) |
Rex Zhu | 3af76f2 | 2015-10-15 17:23:43 +0800 | [diff] [blame] | 2299 | |
| 2300 | #define amdgpu_dpm_get_fan_speed_percent(adev, s) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2301 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2302 | (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2303 | (adev)->pm.funcs->get_fan_speed_percent((adev), (s))) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2304 | |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2305 | #define amdgpu_dpm_get_sclk(adev, l) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2306 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2307 | (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2308 | (adev)->pm.funcs->get_sclk((adev), (l))) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2309 | |
| 2310 | #define amdgpu_dpm_get_mclk(adev, l) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2311 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2312 | (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2313 | (adev)->pm.funcs->get_mclk((adev), (l))) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2314 | |
| 2315 | |
| 2316 | #define amdgpu_dpm_force_performance_level(adev, l) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2317 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2318 | (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2319 | (adev)->pm.funcs->force_performance_level((adev), (l))) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2320 | |
| 2321 | #define amdgpu_dpm_powergate_uvd(adev, g) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2322 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2323 | (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2324 | (adev)->pm.funcs->powergate_uvd((adev), (g))) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2325 | |
| 2326 | #define amdgpu_dpm_powergate_vce(adev, g) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2327 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2328 | (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2329 | (adev)->pm.funcs->powergate_vce((adev), (g))) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2330 | |
| 2331 | #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2332 | ((adev)->pp_enabled ? \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2333 | (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \ |
Eric Huang | 4b5ece2 | 2016-01-19 14:28:56 -0500 | [diff] [blame] | 2334 | (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m))) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2335 | |
| 2336 | #define amdgpu_dpm_get_current_power_state(adev) \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2337 | (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2338 | |
| 2339 | #define amdgpu_dpm_get_performance_level(adev) \ |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2340 | (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2341 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 2342 | #define amdgpu_dpm_get_pp_num_states(adev, data) \ |
| 2343 | (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data) |
| 2344 | |
| 2345 | #define amdgpu_dpm_get_pp_table(adev, table) \ |
| 2346 | (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table) |
| 2347 | |
| 2348 | #define amdgpu_dpm_set_pp_table(adev, buf, size) \ |
| 2349 | (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size) |
| 2350 | |
| 2351 | #define amdgpu_dpm_print_clock_levels(adev, type, buf) \ |
| 2352 | (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf) |
| 2353 | |
| 2354 | #define amdgpu_dpm_force_clock_level(adev, type, level) \ |
| 2355 | (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level) |
| 2356 | |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 2357 | #define amdgpu_dpm_get_sclk_od(adev) \ |
| 2358 | (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle) |
| 2359 | |
| 2360 | #define amdgpu_dpm_set_sclk_od(adev, value) \ |
| 2361 | (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value) |
| 2362 | |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 2363 | #define amdgpu_dpm_get_mclk_od(adev) \ |
| 2364 | ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle)) |
| 2365 | |
| 2366 | #define amdgpu_dpm_set_mclk_od(adev, value) \ |
| 2367 | ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value)) |
| 2368 | |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 2369 | #define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \ |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2370 | (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output)) |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2371 | |
| 2372 | #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a)) |
| 2373 | |
| 2374 | /* Common functions */ |
| 2375 | int amdgpu_gpu_reset(struct amdgpu_device *adev); |
| 2376 | void amdgpu_pci_config_reset(struct amdgpu_device *adev); |
| 2377 | bool amdgpu_card_posted(struct amdgpu_device *adev); |
| 2378 | void amdgpu_update_display_priority(struct amdgpu_device *adev); |
Chunming Zhou | d5fc5e8 | 2015-07-21 16:52:10 +0800 | [diff] [blame] | 2379 | |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2380 | int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data); |
| 2381 | int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type, |
| 2382 | u32 ip_instance, u32 ring, |
| 2383 | struct amdgpu_ring **out_ring); |
| 2384 | void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain); |
| 2385 | bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo); |
Christian König | 2f568db | 2016-02-23 12:36:59 +0100 | [diff] [blame] | 2386 | int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2387 | int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, |
| 2388 | uint32_t flags); |
| 2389 | bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm); |
Christian König | cc325d1 | 2016-02-08 11:08:35 +0100 | [diff] [blame] | 2390 | struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm); |
Christian König | d700696 | 2016-02-08 10:57:22 +0100 | [diff] [blame] | 2391 | bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start, |
| 2392 | unsigned long end); |
Christian König | 2f568db | 2016-02-23 12:36:59 +0100 | [diff] [blame] | 2393 | bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm, |
| 2394 | int *last_invalidated); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2395 | bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm); |
| 2396 | uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, |
| 2397 | struct ttm_mem_reg *mem); |
| 2398 | void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base); |
| 2399 | void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc); |
| 2400 | void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size); |
| 2401 | void amdgpu_program_register_sequence(struct amdgpu_device *adev, |
| 2402 | const u32 *registers, |
| 2403 | const u32 array_size); |
| 2404 | |
| 2405 | bool amdgpu_device_is_px(struct drm_device *dev); |
| 2406 | /* atpx handler */ |
| 2407 | #if defined(CONFIG_VGA_SWITCHEROO) |
| 2408 | void amdgpu_register_atpx_handler(void); |
| 2409 | void amdgpu_unregister_atpx_handler(void); |
Alex Deucher | a78fe13 | 2016-06-01 13:08:21 -0400 | [diff] [blame] | 2410 | bool amdgpu_has_atpx_dgpu_power_cntl(void); |
Alex Deucher | 2f5af82 | 2016-06-02 09:04:01 -0400 | [diff] [blame] | 2411 | bool amdgpu_is_atpx_hybrid(void); |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2412 | #else |
| 2413 | static inline void amdgpu_register_atpx_handler(void) {} |
| 2414 | static inline void amdgpu_unregister_atpx_handler(void) {} |
Alex Deucher | a78fe13 | 2016-06-01 13:08:21 -0400 | [diff] [blame] | 2415 | static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; } |
Alex Deucher | 2f5af82 | 2016-06-02 09:04:01 -0400 | [diff] [blame] | 2416 | static inline bool amdgpu_is_atpx_hybrid(void) { return false; } |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2417 | #endif |
| 2418 | |
| 2419 | /* |
| 2420 | * KMS |
| 2421 | */ |
| 2422 | extern const struct drm_ioctl_desc amdgpu_ioctls_kms[]; |
Nils Wallménius | f498d9e | 2016-04-10 16:29:59 +0200 | [diff] [blame] | 2423 | extern const int amdgpu_max_kms_ioctl; |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2424 | |
| 2425 | int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags); |
| 2426 | int amdgpu_driver_unload_kms(struct drm_device *dev); |
| 2427 | void amdgpu_driver_lastclose_kms(struct drm_device *dev); |
| 2428 | int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv); |
| 2429 | void amdgpu_driver_postclose_kms(struct drm_device *dev, |
| 2430 | struct drm_file *file_priv); |
| 2431 | void amdgpu_driver_preclose_kms(struct drm_device *dev, |
| 2432 | struct drm_file *file_priv); |
| 2433 | int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon); |
| 2434 | int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon); |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 2435 | u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe); |
| 2436 | int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe); |
| 2437 | void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe); |
| 2438 | int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2439 | int *max_error, |
| 2440 | struct timeval *vblank_time, |
| 2441 | unsigned flags); |
| 2442 | long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd, |
| 2443 | unsigned long arg); |
| 2444 | |
| 2445 | /* |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2446 | * functions used by amdgpu_encoder.c |
| 2447 | */ |
| 2448 | struct amdgpu_afmt_acr { |
| 2449 | u32 clock; |
| 2450 | |
| 2451 | int n_32khz; |
| 2452 | int cts_32khz; |
| 2453 | |
| 2454 | int n_44_1khz; |
| 2455 | int cts_44_1khz; |
| 2456 | |
| 2457 | int n_48khz; |
| 2458 | int cts_48khz; |
| 2459 | |
| 2460 | }; |
| 2461 | |
| 2462 | struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock); |
| 2463 | |
| 2464 | /* amdgpu_acpi.c */ |
| 2465 | #if defined(CONFIG_ACPI) |
| 2466 | int amdgpu_acpi_init(struct amdgpu_device *adev); |
| 2467 | void amdgpu_acpi_fini(struct amdgpu_device *adev); |
| 2468 | bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev); |
| 2469 | int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev, |
| 2470 | u8 perf_req, bool advertise); |
| 2471 | int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev); |
| 2472 | #else |
| 2473 | static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; } |
| 2474 | static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { } |
| 2475 | #endif |
| 2476 | |
| 2477 | struct amdgpu_bo_va_mapping * |
| 2478 | amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser, |
| 2479 | uint64_t addr, struct amdgpu_bo **bo); |
| 2480 | |
| 2481 | #include "amdgpu_object.h" |
Alex Deucher | 97b2e20 | 2015-04-20 16:51:00 -0400 | [diff] [blame] | 2482 | #endif |