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