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