2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
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>
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>
46 #include <drm/drm_gem.h>
47 #include <drm/amdgpu_drm.h>
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"
58 #include "gpu_scheduler.h"
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;
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
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
106 /* max number of IP instances */
107 #define AMDGPU_MAX_SDMA_INSTANCES 2
109 /* hardcode that limit for now */
110 #define AMDGPU_VA_RESERVED_SIZE (8 << 20)
112 /* hard reset data */
113 #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
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)
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
139 /* max cursor sizes (in pixels) */
140 #define CIK_CURSOR_WIDTH 128
141 #define CIK_CURSOR_HEIGHT 128
143 struct amdgpu_device;
147 struct amdgpu_cs_parser;
149 struct amdgpu_irq_src;
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,
166 enum amdgpu_sdma_irq {
167 AMDGPU_SDMA_IRQ_TRAP0 = 0,
168 AMDGPU_SDMA_IRQ_TRAP1,
173 enum amdgpu_thermal_irq {
174 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
175 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
177 AMDGPU_THERMAL_IRQ_LAST
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);
187 struct amdgpu_ip_block_version {
188 enum amd_ip_block_type type;
192 const struct amd_ip_funcs *funcs;
195 int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
196 enum amd_ip_block_type type,
197 u32 major, u32 minor);
199 const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
200 struct amdgpu_device *adev,
201 enum amd_ip_block_type type);
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;
208 /* number of dw to reserve per operation */
209 unsigned copy_num_dw;
211 /* used for buffer migration */
212 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
213 /* src addr in bytes */
215 /* dst addr in bytes */
217 /* number of byte to transfer */
218 uint32_t byte_count);
220 /* maximum bytes in a single operation */
221 uint32_t fill_max_bytes;
223 /* number of dw to reserve per operation */
224 unsigned fill_num_dw;
226 /* used for buffer clearing */
227 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
228 /* value to write to memory */
230 /* dst addr in bytes */
232 /* number of byte to fill */
233 uint32_t byte_count);
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,
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,
250 uint64_t addr, unsigned count,
251 uint32_t incr, uint32_t flags);
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,
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 */
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);
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 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
288 uint64_t seq, unsigned flags);
289 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
290 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
292 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
293 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
294 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
295 uint32_t gds_base, uint32_t gds_size,
296 uint32_t gws_base, uint32_t gws_size,
297 uint32_t oa_base, uint32_t oa_size);
298 /* testing functions */
299 int (*test_ring)(struct amdgpu_ring *ring);
300 int (*test_ib)(struct amdgpu_ring *ring);
301 /* insert NOP packets */
302 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
303 /* pad the indirect buffer to the necessary number of dw */
304 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
305 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
306 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
312 bool amdgpu_get_bios(struct amdgpu_device *adev);
313 bool amdgpu_read_bios(struct amdgpu_device *adev);
318 struct amdgpu_dummy_page {
322 int amdgpu_dummy_page_init(struct amdgpu_device *adev);
323 void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
330 #define AMDGPU_MAX_PPLL 3
332 struct amdgpu_clock {
333 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
334 struct amdgpu_pll spll;
335 struct amdgpu_pll mpll;
337 uint32_t default_mclk;
338 uint32_t default_sclk;
339 uint32_t default_dispclk;
340 uint32_t current_dispclk;
342 uint32_t max_pixel_clock;
348 struct amdgpu_fence_driver {
350 volatile uint32_t *cpu_addr;
351 /* sync_seq is protected by ring emission lock */
355 struct amdgpu_irq_src *irq_src;
357 struct timer_list fallback_timer;
358 unsigned num_fences_mask;
360 struct fence **fences;
363 /* some special values for the owner field */
364 #define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
365 #define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
367 #define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
368 #define AMDGPU_FENCE_FLAG_INT (1 << 1)
370 struct amdgpu_user_fence {
372 struct amdgpu_bo *bo;
373 /* write-back address offset to bo start */
377 int amdgpu_fence_driver_init(struct amdgpu_device *adev);
378 void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
379 void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
381 int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
382 unsigned num_hw_submission);
383 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
384 struct amdgpu_irq_src *irq_src,
386 void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
387 void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
388 int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
389 void amdgpu_fence_process(struct amdgpu_ring *ring);
390 int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
391 unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
397 struct ttm_bo_global_ref bo_global_ref;
398 struct drm_global_reference mem_global_ref;
399 struct ttm_bo_device bdev;
400 bool mem_global_referenced;
403 #if defined(CONFIG_DEBUG_FS)
408 /* buffer handling */
409 const struct amdgpu_buffer_funcs *buffer_funcs;
410 struct amdgpu_ring *buffer_funcs_ring;
411 /* Scheduler entity for buffer moves */
412 struct amd_sched_entity entity;
415 int amdgpu_copy_buffer(struct amdgpu_ring *ring,
419 struct reservation_object *resv,
420 struct fence **fence);
421 int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
423 struct amdgpu_bo_list_entry {
424 struct amdgpu_bo *robj;
425 struct ttm_validate_buffer tv;
426 struct amdgpu_bo_va *bo_va;
428 struct page **user_pages;
429 int user_invalidated;
432 struct amdgpu_bo_va_mapping {
433 struct list_head list;
434 struct interval_tree_node it;
439 /* bo virtual addresses in a specific vm */
440 struct amdgpu_bo_va {
441 /* protected by bo being reserved */
442 struct list_head bo_list;
443 struct fence *last_pt_update;
446 /* protected by vm mutex and spinlock */
447 struct list_head vm_status;
449 /* mappings for this bo_va */
450 struct list_head invalids;
451 struct list_head valids;
453 /* constant after initialization */
454 struct amdgpu_vm *vm;
455 struct amdgpu_bo *bo;
458 #define AMDGPU_GEM_DOMAIN_MAX 0x3
461 /* Protected by gem.mutex */
462 struct list_head list;
463 /* Protected by tbo.reserved */
464 u32 prefered_domains;
466 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
467 struct ttm_placement placement;
468 struct ttm_buffer_object tbo;
469 struct ttm_bo_kmap_obj kmap;
477 /* list of all virtual address to which this bo
481 /* Constant after initialization */
482 struct amdgpu_device *adev;
483 struct drm_gem_object gem_base;
484 struct amdgpu_bo *parent;
486 struct ttm_bo_kmap_obj dma_buf_vmap;
487 struct amdgpu_mn *mn;
488 struct list_head mn_list;
490 #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
492 void amdgpu_gem_object_free(struct drm_gem_object *obj);
493 int amdgpu_gem_object_open(struct drm_gem_object *obj,
494 struct drm_file *file_priv);
495 void amdgpu_gem_object_close(struct drm_gem_object *obj,
496 struct drm_file *file_priv);
497 unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
498 struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
499 struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
500 struct dma_buf_attachment *attach,
501 struct sg_table *sg);
502 struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
503 struct drm_gem_object *gobj,
505 int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
506 void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
507 struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
508 void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
509 void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
510 int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
512 /* sub-allocation manager, it has to be protected by another lock.
513 * By conception this is an helper for other part of the driver
514 * like the indirect buffer or semaphore, which both have their
517 * Principe is simple, we keep a list of sub allocation in offset
518 * order (first entry has offset == 0, last entry has the highest
521 * When allocating new object we first check if there is room at
522 * the end total_size - (last_object_offset + last_object_size) >=
523 * alloc_size. If so we allocate new object there.
525 * When there is not enough room at the end, we start waiting for
526 * each sub object until we reach object_offset+object_size >=
527 * alloc_size, this object then become the sub object we return.
529 * Alignment can't be bigger than page size.
531 * Hole are not considered for allocation to keep things simple.
532 * Assumption is that there won't be hole (all object on same
536 #define AMDGPU_SA_NUM_FENCE_LISTS 32
538 struct amdgpu_sa_manager {
539 wait_queue_head_t wq;
540 struct amdgpu_bo *bo;
541 struct list_head *hole;
542 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
543 struct list_head olist;
551 /* sub-allocation buffer */
552 struct amdgpu_sa_bo {
553 struct list_head olist;
554 struct list_head flist;
555 struct amdgpu_sa_manager *manager;
564 void amdgpu_gem_force_release(struct amdgpu_device *adev);
565 int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
566 int alignment, u32 initial_domain,
567 u64 flags, bool kernel,
568 struct drm_gem_object **obj);
570 int amdgpu_mode_dumb_create(struct drm_file *file_priv,
571 struct drm_device *dev,
572 struct drm_mode_create_dumb *args);
573 int amdgpu_mode_dumb_mmap(struct drm_file *filp,
574 struct drm_device *dev,
575 uint32_t handle, uint64_t *offset_p);
580 DECLARE_HASHTABLE(fences, 4);
581 struct fence *last_vm_update;
584 void amdgpu_sync_create(struct amdgpu_sync *sync);
585 int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
587 int amdgpu_sync_resv(struct amdgpu_device *adev,
588 struct amdgpu_sync *sync,
589 struct reservation_object *resv,
591 bool amdgpu_sync_is_idle(struct amdgpu_sync *sync);
592 int amdgpu_sync_cycle_fences(struct amdgpu_sync *dst, struct amdgpu_sync *src,
593 struct fence *fence);
594 struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
595 int amdgpu_sync_wait(struct amdgpu_sync *sync);
596 void amdgpu_sync_free(struct amdgpu_sync *sync);
597 int amdgpu_sync_init(void);
598 void amdgpu_sync_fini(void);
601 * GART structures, functions & helpers
605 #define AMDGPU_GPU_PAGE_SIZE 4096
606 #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
607 #define AMDGPU_GPU_PAGE_SHIFT 12
608 #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
611 dma_addr_t table_addr;
612 struct amdgpu_bo *robj;
614 unsigned num_gpu_pages;
615 unsigned num_cpu_pages;
617 #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
621 const struct amdgpu_gart_funcs *gart_funcs;
624 int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
625 void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
626 int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
627 void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
628 int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
629 void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
630 int amdgpu_gart_init(struct amdgpu_device *adev);
631 void amdgpu_gart_fini(struct amdgpu_device *adev);
632 void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
634 int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
635 int pages, struct page **pagelist,
636 dma_addr_t *dma_addr, uint32_t flags);
639 * GPU MC structures, functions & helpers
642 resource_size_t aper_size;
643 resource_size_t aper_base;
644 resource_size_t agp_base;
645 /* for some chips with <= 32MB we need to lie
646 * about vram size near mc fb location */
648 u64 visible_vram_size;
659 const struct firmware *fw; /* MC firmware */
661 struct amdgpu_irq_src vm_fault;
666 * GPU doorbell structures, functions & helpers
668 typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
670 AMDGPU_DOORBELL_KIQ = 0x000,
671 AMDGPU_DOORBELL_HIQ = 0x001,
672 AMDGPU_DOORBELL_DIQ = 0x002,
673 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
674 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
675 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
676 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
677 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
678 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
679 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
680 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
681 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
682 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
683 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
684 AMDGPU_DOORBELL_IH = 0x1E8,
685 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
686 AMDGPU_DOORBELL_INVALID = 0xFFFF
687 } AMDGPU_DOORBELL_ASSIGNMENT;
689 struct amdgpu_doorbell {
691 resource_size_t base;
692 resource_size_t size;
694 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
697 void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
698 phys_addr_t *aperture_base,
699 size_t *aperture_size,
700 size_t *start_offset);
706 struct amdgpu_flip_work {
707 struct work_struct flip_work;
708 struct work_struct unpin_work;
709 struct amdgpu_device *adev;
712 struct drm_pending_vblank_event *event;
713 struct amdgpu_bo *old_rbo;
715 unsigned shared_count;
716 struct fence **shared;
726 struct amdgpu_sa_bo *sa_bo;
730 struct amdgpu_user_fence *user;
731 struct amdgpu_vm *vm;
734 struct amdgpu_ctx *ctx;
735 uint32_t gds_base, gds_size;
736 uint32_t gws_base, gws_size;
737 uint32_t oa_base, oa_size;
739 /* resulting sequence number */
743 enum amdgpu_ring_type {
744 AMDGPU_RING_TYPE_GFX,
745 AMDGPU_RING_TYPE_COMPUTE,
746 AMDGPU_RING_TYPE_SDMA,
747 AMDGPU_RING_TYPE_UVD,
751 extern struct amd_sched_backend_ops amdgpu_sched_ops;
753 int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
754 struct amdgpu_job **job);
755 int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
756 struct amdgpu_job **job);
758 void amdgpu_job_free(struct amdgpu_job *job);
759 void amdgpu_job_free_func(struct kref *refcount);
760 int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
761 struct amd_sched_entity *entity, void *owner,
763 void amdgpu_job_timeout_func(struct work_struct *work);
766 struct amdgpu_device *adev;
767 const struct amdgpu_ring_funcs *funcs;
768 struct amdgpu_fence_driver fence_drv;
769 struct amd_gpu_scheduler sched;
771 spinlock_t fence_lock;
772 struct amdgpu_bo *ring_obj;
773 volatile uint32_t *ring;
775 u64 next_rptr_gpu_addr;
776 volatile u32 *next_rptr_cpu_addr;
791 struct amdgpu_bo *mqd_obj;
795 unsigned next_rptr_offs;
797 struct amdgpu_ctx *current_ctx;
798 enum amdgpu_ring_type type;
800 unsigned cond_exe_offs;
801 u64 cond_exe_gpu_addr;
802 volatile u32 *cond_exe_cpu_addr;
809 /* maximum number of VMIDs */
810 #define AMDGPU_NUM_VM 16
812 /* number of entries in page table */
813 #define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
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)
820 #define AMDGPU_PTE_VALID (1 << 0)
821 #define AMDGPU_PTE_SYSTEM (1 << 1)
822 #define AMDGPU_PTE_SNOOPED (1 << 2)
825 #define AMDGPU_PTE_EXECUTABLE (1 << 4)
827 #define AMDGPU_PTE_READABLE (1 << 5)
828 #define AMDGPU_PTE_WRITEABLE (1 << 6)
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
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
840 struct amdgpu_vm_pt {
841 struct amdgpu_bo_list_entry entry;
846 /* tree of virtual addresses mapped */
849 /* protecting invalidated */
850 spinlock_t status_lock;
852 /* BOs moved, but not yet updated in the PT */
853 struct list_head invalidated;
855 /* BOs cleared in the PT because of a move */
856 struct list_head cleared;
858 /* BO mappings freed, but not yet updated in the PT */
859 struct list_head freed;
861 /* contains the page directory */
862 struct amdgpu_bo *page_directory;
863 unsigned max_pde_used;
864 struct fence *page_directory_fence;
866 /* array of page tables, one for each page directory entry */
867 struct amdgpu_vm_pt *page_tables;
869 /* for id and flush management per ring */
870 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
872 /* protecting freed */
873 spinlock_t freed_lock;
875 /* Scheduler entity for page table updates */
876 struct amd_sched_entity entity;
879 struct amdgpu_vm_id {
880 struct list_head list;
882 struct amdgpu_sync active;
883 struct fence *last_flush;
886 uint64_t pd_gpu_addr;
887 /* last flushed PD/PT update */
888 struct fence *flushed_updates;
898 struct amdgpu_vm_manager {
899 /* Handling of VMIDs */
902 struct list_head ids_lru;
903 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
906 /* vram base address for page table entry */
907 u64 vram_base_offset;
910 /* vm pte handling */
911 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
912 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
913 unsigned vm_pte_num_rings;
914 atomic_t vm_pte_next_ring;
917 void amdgpu_vm_manager_init(struct amdgpu_device *adev);
918 void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
919 int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
920 void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
921 void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
922 struct list_head *validated,
923 struct amdgpu_bo_list_entry *entry);
924 void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
925 void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
926 struct amdgpu_vm *vm);
927 int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
928 struct amdgpu_sync *sync, struct fence *fence,
929 unsigned *vm_id, uint64_t *vm_pd_addr);
930 int amdgpu_vm_flush(struct amdgpu_ring *ring,
931 unsigned vm_id, uint64_t pd_addr,
932 uint32_t gds_base, uint32_t gds_size,
933 uint32_t gws_base, uint32_t gws_size,
934 uint32_t oa_base, uint32_t oa_size);
935 void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
936 uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
937 int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
938 struct amdgpu_vm *vm);
939 int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
940 struct amdgpu_vm *vm);
941 int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
942 struct amdgpu_sync *sync);
943 int amdgpu_vm_bo_update(struct amdgpu_device *adev,
944 struct amdgpu_bo_va *bo_va,
945 struct ttm_mem_reg *mem);
946 void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
947 struct amdgpu_bo *bo);
948 struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
949 struct amdgpu_bo *bo);
950 struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
951 struct amdgpu_vm *vm,
952 struct amdgpu_bo *bo);
953 int amdgpu_vm_bo_map(struct amdgpu_device *adev,
954 struct amdgpu_bo_va *bo_va,
955 uint64_t addr, uint64_t offset,
956 uint64_t size, uint32_t flags);
957 int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
958 struct amdgpu_bo_va *bo_va,
960 void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
961 struct amdgpu_bo_va *bo_va);
964 * context related structures
967 struct amdgpu_ctx_ring {
969 struct fence **fences;
970 struct amd_sched_entity entity;
974 struct kref refcount;
975 struct amdgpu_device *adev;
976 unsigned reset_counter;
977 spinlock_t ring_lock;
978 struct fence **fences;
979 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
982 struct amdgpu_ctx_mgr {
983 struct amdgpu_device *adev;
985 /* protected by lock */
986 struct idr ctx_handles;
989 struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
990 int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
992 uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
993 struct fence *fence);
994 struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
995 struct amdgpu_ring *ring, uint64_t seq);
997 int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
998 struct drm_file *filp);
1000 void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1001 void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
1004 * file private structure
1007 struct amdgpu_fpriv {
1008 struct amdgpu_vm vm;
1009 struct mutex bo_list_lock;
1010 struct idr bo_list_handles;
1011 struct amdgpu_ctx_mgr ctx_mgr;
1018 struct amdgpu_bo_list {
1020 struct amdgpu_bo *gds_obj;
1021 struct amdgpu_bo *gws_obj;
1022 struct amdgpu_bo *oa_obj;
1023 unsigned first_userptr;
1024 unsigned num_entries;
1025 struct amdgpu_bo_list_entry *array;
1028 struct amdgpu_bo_list *
1029 amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
1030 void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1031 struct list_head *validated);
1032 void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1033 void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1038 #include "clearstate_defs.h"
1041 /* for power gating */
1042 struct amdgpu_bo *save_restore_obj;
1043 uint64_t save_restore_gpu_addr;
1044 volatile uint32_t *sr_ptr;
1045 const u32 *reg_list;
1047 /* for clear state */
1048 struct amdgpu_bo *clear_state_obj;
1049 uint64_t clear_state_gpu_addr;
1050 volatile uint32_t *cs_ptr;
1051 const struct cs_section_def *cs_data;
1052 u32 clear_state_size;
1054 struct amdgpu_bo *cp_table_obj;
1055 uint64_t cp_table_gpu_addr;
1056 volatile uint32_t *cp_table_ptr;
1061 struct amdgpu_bo *hpd_eop_obj;
1062 u64 hpd_eop_gpu_addr;
1069 * GPU scratch registers structures, functions & helpers
1071 struct amdgpu_scratch {
1079 * GFX configurations
1081 struct amdgpu_gca_config {
1082 unsigned max_shader_engines;
1083 unsigned max_tile_pipes;
1084 unsigned max_cu_per_sh;
1085 unsigned max_sh_per_se;
1086 unsigned max_backends_per_se;
1087 unsigned max_texture_channel_caches;
1089 unsigned max_gs_threads;
1090 unsigned max_hw_contexts;
1091 unsigned sc_prim_fifo_size_frontend;
1092 unsigned sc_prim_fifo_size_backend;
1093 unsigned sc_hiz_tile_fifo_size;
1094 unsigned sc_earlyz_tile_fifo_size;
1096 unsigned num_tile_pipes;
1097 unsigned backend_enable_mask;
1098 unsigned mem_max_burst_length_bytes;
1099 unsigned mem_row_size_in_kb;
1100 unsigned shader_engine_tile_size;
1102 unsigned multi_gpu_tile_size;
1103 unsigned mc_arb_ramcfg;
1104 unsigned gb_addr_config;
1107 uint32_t tile_mode_array[32];
1108 uint32_t macrotile_mode_array[16];
1112 struct mutex gpu_clock_mutex;
1113 struct amdgpu_gca_config config;
1114 struct amdgpu_rlc rlc;
1115 struct amdgpu_mec mec;
1116 struct amdgpu_scratch scratch;
1117 const struct firmware *me_fw; /* ME firmware */
1118 uint32_t me_fw_version;
1119 const struct firmware *pfp_fw; /* PFP firmware */
1120 uint32_t pfp_fw_version;
1121 const struct firmware *ce_fw; /* CE firmware */
1122 uint32_t ce_fw_version;
1123 const struct firmware *rlc_fw; /* RLC firmware */
1124 uint32_t rlc_fw_version;
1125 const struct firmware *mec_fw; /* MEC firmware */
1126 uint32_t mec_fw_version;
1127 const struct firmware *mec2_fw; /* MEC2 firmware */
1128 uint32_t mec2_fw_version;
1129 uint32_t me_feature_version;
1130 uint32_t ce_feature_version;
1131 uint32_t pfp_feature_version;
1132 uint32_t rlc_feature_version;
1133 uint32_t mec_feature_version;
1134 uint32_t mec2_feature_version;
1135 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1136 unsigned num_gfx_rings;
1137 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1138 unsigned num_compute_rings;
1139 struct amdgpu_irq_src eop_irq;
1140 struct amdgpu_irq_src priv_reg_irq;
1141 struct amdgpu_irq_src priv_inst_irq;
1143 uint32_t gfx_current_status;
1145 unsigned ce_ram_size;
1148 int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
1149 unsigned size, struct amdgpu_ib *ib);
1150 void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, struct fence *f);
1151 int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
1152 struct amdgpu_ib *ib, struct fence *last_vm_update,
1154 int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1155 void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1156 int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
1157 int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
1158 void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
1159 void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
1160 void amdgpu_ring_commit(struct amdgpu_ring *ring);
1161 void amdgpu_ring_undo(struct amdgpu_ring *ring);
1162 unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1164 int amdgpu_ring_restore(struct amdgpu_ring *ring,
1165 unsigned size, uint32_t *data);
1166 int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1167 unsigned ring_size, u32 nop, u32 align_mask,
1168 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1169 enum amdgpu_ring_type ring_type);
1170 void amdgpu_ring_fini(struct amdgpu_ring *ring);
1175 struct amdgpu_cs_chunk {
1181 struct amdgpu_cs_parser {
1182 struct amdgpu_device *adev;
1183 struct drm_file *filp;
1184 struct amdgpu_ctx *ctx;
1188 struct amdgpu_cs_chunk *chunks;
1190 /* scheduler job object */
1191 struct amdgpu_job *job;
1193 /* buffer objects */
1194 struct ww_acquire_ctx ticket;
1195 struct amdgpu_bo_list *bo_list;
1196 struct amdgpu_bo_list_entry vm_pd;
1197 struct list_head validated;
1198 struct fence *fence;
1199 uint64_t bytes_moved_threshold;
1200 uint64_t bytes_moved;
1203 struct amdgpu_bo_list_entry uf_entry;
1207 struct amd_sched_job base;
1208 struct amdgpu_device *adev;
1209 struct amdgpu_ring *ring;
1210 struct amdgpu_sync sync;
1211 struct amdgpu_ib *ibs;
1212 struct fence *fence; /* the hw fence */
1215 struct amdgpu_user_fence uf;
1217 #define to_amdgpu_job(sched_job) \
1218 container_of((sched_job), struct amdgpu_job, base)
1220 static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1221 uint32_t ib_idx, int idx)
1223 return p->job->ibs[ib_idx].ptr[idx];
1226 static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1227 uint32_t ib_idx, int idx,
1230 p->job->ibs[ib_idx].ptr[idx] = value;
1236 #define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1239 struct amdgpu_bo *wb_obj;
1240 volatile uint32_t *wb;
1242 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1243 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1246 int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1247 void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1251 enum amdgpu_int_thermal_type {
1253 THERMAL_TYPE_EXTERNAL,
1254 THERMAL_TYPE_EXTERNAL_GPIO,
1257 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1258 THERMAL_TYPE_EVERGREEN,
1262 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1267 enum amdgpu_dpm_auto_throttle_src {
1268 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1269 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1272 enum amdgpu_dpm_event_src {
1273 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1274 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1275 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1276 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1277 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1280 #define AMDGPU_MAX_VCE_LEVELS 6
1282 enum amdgpu_vce_level {
1283 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1284 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1285 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1286 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1287 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1288 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1292 u32 caps; /* vbios flags */
1293 u32 class; /* vbios flags */
1294 u32 class2; /* vbios flags */
1302 enum amdgpu_vce_level vce_level;
1307 struct amdgpu_dpm_thermal {
1308 /* thermal interrupt work */
1309 struct work_struct work;
1310 /* low temperature threshold */
1312 /* high temperature threshold */
1314 /* was last interrupt low to high or high to low */
1316 /* interrupt source */
1317 struct amdgpu_irq_src irq;
1320 enum amdgpu_clk_action
1326 struct amdgpu_blacklist_clocks
1330 enum amdgpu_clk_action action;
1333 struct amdgpu_clock_and_voltage_limits {
1340 struct amdgpu_clock_array {
1345 struct amdgpu_clock_voltage_dependency_entry {
1350 struct amdgpu_clock_voltage_dependency_table {
1352 struct amdgpu_clock_voltage_dependency_entry *entries;
1355 union amdgpu_cac_leakage_entry {
1367 struct amdgpu_cac_leakage_table {
1369 union amdgpu_cac_leakage_entry *entries;
1372 struct amdgpu_phase_shedding_limits_entry {
1378 struct amdgpu_phase_shedding_limits_table {
1380 struct amdgpu_phase_shedding_limits_entry *entries;
1383 struct amdgpu_uvd_clock_voltage_dependency_entry {
1389 struct amdgpu_uvd_clock_voltage_dependency_table {
1391 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1394 struct amdgpu_vce_clock_voltage_dependency_entry {
1400 struct amdgpu_vce_clock_voltage_dependency_table {
1402 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1405 struct amdgpu_ppm_table {
1407 u16 cpu_core_number;
1409 u32 small_ac_platform_tdp;
1411 u32 small_ac_platform_tdc;
1418 struct amdgpu_cac_tdp_table {
1420 u16 configurable_tdp;
1422 u16 battery_power_limit;
1423 u16 small_power_limit;
1424 u16 low_cac_leakage;
1425 u16 high_cac_leakage;
1426 u16 maximum_power_delivery_limit;
1429 struct amdgpu_dpm_dynamic_state {
1430 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1431 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1432 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1433 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1434 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1435 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1436 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1437 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1438 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1439 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1440 struct amdgpu_clock_array valid_sclk_values;
1441 struct amdgpu_clock_array valid_mclk_values;
1442 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1443 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1444 u32 mclk_sclk_ratio;
1445 u32 sclk_mclk_delta;
1446 u16 vddc_vddci_delta;
1447 u16 min_vddc_for_pcie_gen2;
1448 struct amdgpu_cac_leakage_table cac_leakage_table;
1449 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1450 struct amdgpu_ppm_table *ppm_table;
1451 struct amdgpu_cac_tdp_table *cac_tdp_table;
1454 struct amdgpu_dpm_fan {
1465 u16 default_max_fan_pwm;
1466 u16 default_fan_output_sensitivity;
1467 u16 fan_output_sensitivity;
1468 bool ucode_fan_control;
1471 enum amdgpu_pcie_gen {
1472 AMDGPU_PCIE_GEN1 = 0,
1473 AMDGPU_PCIE_GEN2 = 1,
1474 AMDGPU_PCIE_GEN3 = 2,
1475 AMDGPU_PCIE_GEN_INVALID = 0xffff
1478 enum amdgpu_dpm_forced_level {
1479 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1480 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1481 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
1482 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
1485 struct amdgpu_vce_state {
1496 struct amdgpu_dpm_funcs {
1497 int (*get_temperature)(struct amdgpu_device *adev);
1498 int (*pre_set_power_state)(struct amdgpu_device *adev);
1499 int (*set_power_state)(struct amdgpu_device *adev);
1500 void (*post_set_power_state)(struct amdgpu_device *adev);
1501 void (*display_configuration_changed)(struct amdgpu_device *adev);
1502 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1503 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1504 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1505 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1506 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1507 bool (*vblank_too_short)(struct amdgpu_device *adev);
1508 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
1509 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
1510 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1511 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1512 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1513 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1514 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1518 struct amdgpu_ps *ps;
1519 /* number of valid power states */
1521 /* current power state that is active */
1522 struct amdgpu_ps *current_ps;
1523 /* requested power state */
1524 struct amdgpu_ps *requested_ps;
1525 /* boot up power state */
1526 struct amdgpu_ps *boot_ps;
1527 /* default uvd power state */
1528 struct amdgpu_ps *uvd_ps;
1529 /* vce requirements */
1530 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1531 enum amdgpu_vce_level vce_level;
1532 enum amd_pm_state_type state;
1533 enum amd_pm_state_type user_state;
1535 u32 voltage_response_time;
1536 u32 backbias_response_time;
1538 u32 new_active_crtcs;
1539 int new_active_crtc_count;
1540 u32 current_active_crtcs;
1541 int current_active_crtc_count;
1542 struct amdgpu_dpm_dynamic_state dyn_state;
1543 struct amdgpu_dpm_fan fan;
1546 u32 near_tdp_limit_adjusted;
1547 u32 sq_ramping_threshold;
1551 u16 load_line_slope;
1554 /* special states active */
1555 bool thermal_active;
1558 /* thermal handling */
1559 struct amdgpu_dpm_thermal thermal;
1561 enum amdgpu_dpm_forced_level forced_level;
1570 struct amdgpu_i2c_chan *i2c_bus;
1571 /* internal thermal controller on rv6xx+ */
1572 enum amdgpu_int_thermal_type int_thermal_type;
1573 struct device *int_hwmon_dev;
1574 /* fan control parameters */
1576 u8 fan_pulses_per_revolution;
1581 bool sysfs_initialized;
1582 struct amdgpu_dpm dpm;
1583 const struct firmware *fw; /* SMC firmware */
1584 uint32_t fw_version;
1585 const struct amdgpu_dpm_funcs *funcs;
1586 uint32_t pcie_gen_mask;
1587 uint32_t pcie_mlw_mask;
1588 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
1591 void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1596 #define AMDGPU_MAX_UVD_HANDLES 10
1597 #define AMDGPU_UVD_STACK_SIZE (1024*1024)
1598 #define AMDGPU_UVD_HEAP_SIZE (1024*1024)
1599 #define AMDGPU_UVD_FIRMWARE_OFFSET 256
1602 struct amdgpu_bo *vcpu_bo;
1606 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1607 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1608 struct delayed_work idle_work;
1609 const struct firmware *fw; /* UVD firmware */
1610 struct amdgpu_ring ring;
1611 struct amdgpu_irq_src irq;
1612 bool address_64_bit;
1613 struct amd_sched_entity entity;
1619 #define AMDGPU_MAX_VCE_HANDLES 16
1620 #define AMDGPU_VCE_FIRMWARE_OFFSET 256
1622 #define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1623 #define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1626 struct amdgpu_bo *vcpu_bo;
1628 unsigned fw_version;
1629 unsigned fb_version;
1630 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1631 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
1632 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
1633 struct delayed_work idle_work;
1634 const struct firmware *fw; /* VCE firmware */
1635 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1636 struct amdgpu_irq_src irq;
1637 unsigned harvest_config;
1638 struct amd_sched_entity entity;
1644 struct amdgpu_sdma_instance {
1646 const struct firmware *fw;
1647 uint32_t fw_version;
1648 uint32_t feature_version;
1650 struct amdgpu_ring ring;
1654 struct amdgpu_sdma {
1655 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1656 struct amdgpu_irq_src trap_irq;
1657 struct amdgpu_irq_src illegal_inst_irq;
1664 struct amdgpu_firmware {
1665 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1667 struct amdgpu_bo *fw_buf;
1668 unsigned int fw_size;
1674 void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1680 void amdgpu_test_moves(struct amdgpu_device *adev);
1681 void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1682 struct amdgpu_ring *cpA,
1683 struct amdgpu_ring *cpB);
1684 void amdgpu_test_syncing(struct amdgpu_device *adev);
1689 #if defined(CONFIG_MMU_NOTIFIER)
1690 int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1691 void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1693 static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
1697 static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
1703 struct amdgpu_debugfs {
1704 struct drm_info_list *files;
1708 int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
1709 struct drm_info_list *files,
1711 int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1713 #if defined(CONFIG_DEBUG_FS)
1714 int amdgpu_debugfs_init(struct drm_minor *minor);
1715 void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1719 * amdgpu smumgr functions
1721 struct amdgpu_smumgr_funcs {
1722 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1723 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1724 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1730 struct amdgpu_smumgr {
1731 struct amdgpu_bo *toc_buf;
1732 struct amdgpu_bo *smu_buf;
1733 /* asic priv smu data */
1735 spinlock_t smu_lock;
1736 /* smumgr functions */
1737 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1738 /* ucode loading complete flag */
1743 * ASIC specific register table accessible by UMD
1745 struct amdgpu_allowed_register_entry {
1746 uint32_t reg_offset;
1751 struct amdgpu_cu_info {
1752 uint32_t number; /* total active CU number */
1753 uint32_t ao_cu_mask;
1754 uint32_t bitmap[4][4];
1759 * ASIC specific functions.
1761 struct amdgpu_asic_funcs {
1762 bool (*read_disabled_bios)(struct amdgpu_device *adev);
1763 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1764 u8 *bios, u32 length_bytes);
1765 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1766 u32 sh_num, u32 reg_offset, u32 *value);
1767 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1768 int (*reset)(struct amdgpu_device *adev);
1769 /* wait for mc_idle */
1770 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1771 /* get the reference clock */
1772 u32 (*get_xclk)(struct amdgpu_device *adev);
1773 /* get the gpu clock counter */
1774 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
1775 int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
1776 /* MM block clocks */
1777 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1778 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1784 int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1785 struct drm_file *filp);
1786 int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1787 struct drm_file *filp);
1789 int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1790 struct drm_file *filp);
1791 int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1792 struct drm_file *filp);
1793 int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1794 struct drm_file *filp);
1795 int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1796 struct drm_file *filp);
1797 int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1798 struct drm_file *filp);
1799 int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1800 struct drm_file *filp);
1801 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1802 int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1804 int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1805 struct drm_file *filp);
1807 /* VRAM scratch page for HDP bug, default vram page */
1808 struct amdgpu_vram_scratch {
1809 struct amdgpu_bo *robj;
1810 volatile uint32_t *ptr;
1817 struct amdgpu_atif_notification_cfg {
1822 struct amdgpu_atif_notifications {
1823 bool display_switch;
1824 bool expansion_mode_change;
1826 bool forced_power_state;
1827 bool system_power_state;
1828 bool display_conf_change;
1830 bool brightness_change;
1831 bool dgpu_display_event;
1834 struct amdgpu_atif_functions {
1836 bool sbios_requests;
1837 bool select_active_disp;
1839 bool get_tv_standard;
1840 bool set_tv_standard;
1841 bool get_panel_expansion_mode;
1842 bool set_panel_expansion_mode;
1843 bool temperature_change;
1844 bool graphics_device_types;
1847 struct amdgpu_atif {
1848 struct amdgpu_atif_notifications notifications;
1849 struct amdgpu_atif_functions functions;
1850 struct amdgpu_atif_notification_cfg notification_cfg;
1851 struct amdgpu_encoder *encoder_for_bl;
1854 struct amdgpu_atcs_functions {
1858 bool pcie_bus_width;
1861 struct amdgpu_atcs {
1862 struct amdgpu_atcs_functions functions;
1868 void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1869 void amdgpu_cgs_destroy_device(void *cgs_device);
1875 void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1876 void amdgpu_cgs_destroy_device(void *cgs_device);
1879 /* GPU virtualization */
1880 struct amdgpu_virtualization {
1881 bool supports_sr_iov;
1885 * Core structure, functions and helpers.
1887 typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1888 typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1890 typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1891 typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1893 struct amdgpu_ip_block_status {
1899 struct amdgpu_device {
1901 struct drm_device *ddev;
1902 struct pci_dev *pdev;
1904 #ifdef CONFIG_DRM_AMD_ACP
1905 struct amdgpu_acp acp;
1909 enum amd_asic_type asic_type;
1912 uint32_t external_rev_id;
1913 unsigned long flags;
1915 const struct amdgpu_asic_funcs *asic_funcs;
1919 struct work_struct reset_work;
1920 struct notifier_block acpi_nb;
1921 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1922 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1923 unsigned debugfs_count;
1924 #if defined(CONFIG_DEBUG_FS)
1925 struct dentry *debugfs_regs;
1927 struct amdgpu_atif atif;
1928 struct amdgpu_atcs atcs;
1929 struct mutex srbm_mutex;
1930 /* GRBM index mutex. Protects concurrent access to GRBM index */
1931 struct mutex grbm_idx_mutex;
1932 struct dev_pm_domain vga_pm_domain;
1933 bool have_disp_power_ref;
1938 struct amdgpu_bo *stollen_vga_memory;
1939 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1941 /* Register/doorbell mmio */
1942 resource_size_t rmmio_base;
1943 resource_size_t rmmio_size;
1944 void __iomem *rmmio;
1945 /* protects concurrent MM_INDEX/DATA based register access */
1946 spinlock_t mmio_idx_lock;
1947 /* protects concurrent SMC based register access */
1948 spinlock_t smc_idx_lock;
1949 amdgpu_rreg_t smc_rreg;
1950 amdgpu_wreg_t smc_wreg;
1951 /* protects concurrent PCIE register access */
1952 spinlock_t pcie_idx_lock;
1953 amdgpu_rreg_t pcie_rreg;
1954 amdgpu_wreg_t pcie_wreg;
1955 /* protects concurrent UVD register access */
1956 spinlock_t uvd_ctx_idx_lock;
1957 amdgpu_rreg_t uvd_ctx_rreg;
1958 amdgpu_wreg_t uvd_ctx_wreg;
1959 /* protects concurrent DIDT register access */
1960 spinlock_t didt_idx_lock;
1961 amdgpu_rreg_t didt_rreg;
1962 amdgpu_wreg_t didt_wreg;
1963 /* protects concurrent ENDPOINT (audio) register access */
1964 spinlock_t audio_endpt_idx_lock;
1965 amdgpu_block_rreg_t audio_endpt_rreg;
1966 amdgpu_block_wreg_t audio_endpt_wreg;
1967 void __iomem *rio_mem;
1968 resource_size_t rio_mem_size;
1969 struct amdgpu_doorbell doorbell;
1971 /* clock/pll info */
1972 struct amdgpu_clock clock;
1975 struct amdgpu_mc mc;
1976 struct amdgpu_gart gart;
1977 struct amdgpu_dummy_page dummy_page;
1978 struct amdgpu_vm_manager vm_manager;
1980 /* memory management */
1981 struct amdgpu_mman mman;
1982 struct amdgpu_vram_scratch vram_scratch;
1983 struct amdgpu_wb wb;
1984 atomic64_t vram_usage;
1985 atomic64_t vram_vis_usage;
1986 atomic64_t gtt_usage;
1987 atomic64_t num_bytes_moved;
1988 atomic_t gpu_reset_counter;
1991 struct amdgpu_mode_info mode_info;
1992 struct work_struct hotplug_work;
1993 struct amdgpu_irq_src crtc_irq;
1994 struct amdgpu_irq_src pageflip_irq;
1995 struct amdgpu_irq_src hpd_irq;
1998 unsigned fence_context;
2000 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2002 struct amdgpu_sa_manager ring_tmp_bo;
2005 struct amdgpu_irq irq;
2008 struct amd_powerplay powerplay;
2010 bool pp_force_state_enabled;
2013 struct amdgpu_pm pm;
2018 struct amdgpu_smumgr smu;
2021 struct amdgpu_gfx gfx;
2024 struct amdgpu_sdma sdma;
2027 struct amdgpu_uvd uvd;
2030 struct amdgpu_vce vce;
2033 struct amdgpu_firmware firmware;
2036 struct amdgpu_gds gds;
2038 const struct amdgpu_ip_block_version *ip_blocks;
2040 struct amdgpu_ip_block_status *ip_block_status;
2041 struct mutex mn_lock;
2042 DECLARE_HASHTABLE(mn_hash, 7);
2044 /* tracking pinned memory */
2048 /* amdkfd interface */
2049 struct kfd_dev *kfd;
2051 struct amdgpu_virtualization virtualization;
2054 bool amdgpu_device_is_px(struct drm_device *dev);
2055 int amdgpu_device_init(struct amdgpu_device *adev,
2056 struct drm_device *ddev,
2057 struct pci_dev *pdev,
2059 void amdgpu_device_fini(struct amdgpu_device *adev);
2060 int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2062 uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2063 bool always_indirect);
2064 void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2065 bool always_indirect);
2066 u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2067 void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2069 u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2070 void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2073 * Registers read & write functions.
2075 #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2076 #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2077 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2078 #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2079 #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2080 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2081 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2082 #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2083 #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2084 #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2085 #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2086 #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2087 #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2088 #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2089 #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2090 #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2091 #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2092 #define WREG32_P(reg, val, mask) \
2094 uint32_t tmp_ = RREG32(reg); \
2096 tmp_ |= ((val) & ~(mask)); \
2097 WREG32(reg, tmp_); \
2099 #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2100 #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2101 #define WREG32_PLL_P(reg, val, mask) \
2103 uint32_t tmp_ = RREG32_PLL(reg); \
2105 tmp_ |= ((val) & ~(mask)); \
2106 WREG32_PLL(reg, tmp_); \
2108 #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2109 #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2110 #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2112 #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2113 #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2115 #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2116 #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2118 #define REG_SET_FIELD(orig_val, reg, field, field_val) \
2119 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2120 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2122 #define REG_GET_FIELD(value, reg, field) \
2123 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2128 #define RBIOS8(i) (adev->bios[i])
2129 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2130 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2135 static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2137 if (ring->count_dw <= 0)
2138 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
2139 ring->ring[ring->wptr++] = v;
2140 ring->wptr &= ring->ptr_mask;
2144 static inline struct amdgpu_sdma_instance *
2145 amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
2147 struct amdgpu_device *adev = ring->adev;
2150 for (i = 0; i < adev->sdma.num_instances; i++)
2151 if (&adev->sdma.instance[i].ring == ring)
2154 if (i < AMDGPU_MAX_SDMA_INSTANCES)
2155 return &adev->sdma.instance[i];
2163 #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2164 #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
2165 #define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
2166 #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2167 #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2168 #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2169 #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2170 #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
2171 #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
2172 #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
2173 #define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
2174 #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2175 #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2176 #define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
2177 #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)))
2178 #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)))
2179 #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2180 #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2181 #define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
2182 #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2183 #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2184 #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2185 #define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
2186 #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
2187 #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
2188 #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
2189 #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))
2190 #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
2191 #define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
2192 #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
2193 #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2194 #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
2195 #define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2196 #define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2197 #define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2198 #define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2199 #define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2200 #define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2201 #define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2202 #define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2203 #define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2204 #define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2205 #define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2206 #define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2207 #define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2208 #define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
2209 #define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2210 #define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2211 #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))
2212 #define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2213 #define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
2214 #define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b))
2215 #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
2216 #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2217 #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2218 #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2219 #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
2220 #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
2221 #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
2222 #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
2224 #define amdgpu_dpm_get_temperature(adev) \
2225 ((adev)->pp_enabled ? \
2226 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
2227 (adev)->pm.funcs->get_temperature((adev)))
2229 #define amdgpu_dpm_set_fan_control_mode(adev, m) \
2230 ((adev)->pp_enabled ? \
2231 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
2232 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
2234 #define amdgpu_dpm_get_fan_control_mode(adev) \
2235 ((adev)->pp_enabled ? \
2236 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
2237 (adev)->pm.funcs->get_fan_control_mode((adev)))
2239 #define amdgpu_dpm_set_fan_speed_percent(adev, s) \
2240 ((adev)->pp_enabled ? \
2241 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
2242 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
2244 #define amdgpu_dpm_get_fan_speed_percent(adev, s) \
2245 ((adev)->pp_enabled ? \
2246 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
2247 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
2249 #define amdgpu_dpm_get_sclk(adev, l) \
2250 ((adev)->pp_enabled ? \
2251 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
2252 (adev)->pm.funcs->get_sclk((adev), (l)))
2254 #define amdgpu_dpm_get_mclk(adev, l) \
2255 ((adev)->pp_enabled ? \
2256 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
2257 (adev)->pm.funcs->get_mclk((adev), (l)))
2260 #define amdgpu_dpm_force_performance_level(adev, l) \
2261 ((adev)->pp_enabled ? \
2262 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
2263 (adev)->pm.funcs->force_performance_level((adev), (l)))
2265 #define amdgpu_dpm_powergate_uvd(adev, g) \
2266 ((adev)->pp_enabled ? \
2267 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
2268 (adev)->pm.funcs->powergate_uvd((adev), (g)))
2270 #define amdgpu_dpm_powergate_vce(adev, g) \
2271 ((adev)->pp_enabled ? \
2272 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
2273 (adev)->pm.funcs->powergate_vce((adev), (g)))
2275 #define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
2276 ((adev)->pp_enabled ? \
2277 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
2278 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
2280 #define amdgpu_dpm_get_current_power_state(adev) \
2281 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
2283 #define amdgpu_dpm_get_performance_level(adev) \
2284 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
2286 #define amdgpu_dpm_get_pp_num_states(adev, data) \
2287 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2289 #define amdgpu_dpm_get_pp_table(adev, table) \
2290 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2292 #define amdgpu_dpm_set_pp_table(adev, buf, size) \
2293 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2295 #define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2296 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2298 #define amdgpu_dpm_force_clock_level(adev, type, level) \
2299 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2301 #define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
2302 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
2304 #define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2306 /* Common functions */
2307 int amdgpu_gpu_reset(struct amdgpu_device *adev);
2308 void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2309 bool amdgpu_card_posted(struct amdgpu_device *adev);
2310 void amdgpu_update_display_priority(struct amdgpu_device *adev);
2312 int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2313 int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2314 u32 ip_instance, u32 ring,
2315 struct amdgpu_ring **out_ring);
2316 void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2317 bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
2318 int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
2319 int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2321 bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
2322 struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
2323 bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2325 bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2326 int *last_invalidated);
2327 bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2328 uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2329 struct ttm_mem_reg *mem);
2330 void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2331 void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2332 void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2333 void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2334 const u32 *registers,
2335 const u32 array_size);
2337 bool amdgpu_device_is_px(struct drm_device *dev);
2339 #if defined(CONFIG_VGA_SWITCHEROO)
2340 void amdgpu_register_atpx_handler(void);
2341 void amdgpu_unregister_atpx_handler(void);
2343 static inline void amdgpu_register_atpx_handler(void) {}
2344 static inline void amdgpu_unregister_atpx_handler(void) {}
2350 extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2351 extern const int amdgpu_max_kms_ioctl;
2353 int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2354 int amdgpu_driver_unload_kms(struct drm_device *dev);
2355 void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2356 int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2357 void amdgpu_driver_postclose_kms(struct drm_device *dev,
2358 struct drm_file *file_priv);
2359 void amdgpu_driver_preclose_kms(struct drm_device *dev,
2360 struct drm_file *file_priv);
2361 int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2362 int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
2363 u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2364 int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2365 void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2366 int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
2368 struct timeval *vblank_time,
2370 long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2374 * functions used by amdgpu_encoder.c
2376 struct amdgpu_afmt_acr {
2390 struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2393 #if defined(CONFIG_ACPI)
2394 int amdgpu_acpi_init(struct amdgpu_device *adev);
2395 void amdgpu_acpi_fini(struct amdgpu_device *adev);
2396 bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2397 int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2398 u8 perf_req, bool advertise);
2399 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2401 static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2402 static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2405 struct amdgpu_bo_va_mapping *
2406 amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2407 uint64_t addr, struct amdgpu_bo **bo);
2409 #include "amdgpu_object.h"