1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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/rbtree.h>
36#include <linux/hashtable.h>
37#include <linux/dma-fence.h>
38
39#include <drm/ttm/ttm_bo_api.h>
40#include <drm/ttm/ttm_bo_driver.h>
41#include <drm/ttm/ttm_placement.h>
42#include <drm/ttm/ttm_module.h>
43#include <drm/ttm/ttm_execbuf_util.h>
44
45#include <drm/drmP.h>
46#include <drm/drm_gem.h>
47#include <drm/amdgpu_drm.h>
48#include <drm/gpu_scheduler.h>
49
50#include <kgd_kfd_interface.h>
51#include "dm_pp_interface.h"
52#include "kgd_pp_interface.h"
53
54#include "amd_shared.h"
55#include "amdgpu_mode.h"
56#include "amdgpu_ih.h"
57#include "amdgpu_irq.h"
58#include "amdgpu_ucode.h"
59#include "amdgpu_ttm.h"
60#include "amdgpu_psp.h"
61#include "amdgpu_gds.h"
62#include "amdgpu_sync.h"
63#include "amdgpu_ring.h"
64#include "amdgpu_vm.h"
65#include "amdgpu_dpm.h"
66#include "amdgpu_acp.h"
67#include "amdgpu_uvd.h"
68#include "amdgpu_vce.h"
69#include "amdgpu_vcn.h"
70#include "amdgpu_mn.h"
71#include "amdgpu_gmc.h"
72#include "amdgpu_dm.h"
73#include "amdgpu_virt.h"
74#include "amdgpu_gart.h"
75#include "amdgpu_debugfs.h"
76
77
78
79
80extern int amdgpu_modeset;
81extern int amdgpu_vram_limit;
82extern int amdgpu_vis_vram_limit;
83extern int amdgpu_gart_size;
84extern int amdgpu_gtt_size;
85extern int amdgpu_moverate;
86extern int amdgpu_benchmarking;
87extern int amdgpu_testing;
88extern int amdgpu_audio;
89extern int amdgpu_disp_priority;
90extern int amdgpu_hw_i2c;
91extern int amdgpu_pcie_gen2;
92extern int amdgpu_msi;
93extern int amdgpu_lockup_timeout;
94extern int amdgpu_dpm;
95extern int amdgpu_fw_load_type;
96extern int amdgpu_aspm;
97extern int amdgpu_runtime_pm;
98extern uint amdgpu_ip_block_mask;
99extern int amdgpu_bapm;
100extern int amdgpu_deep_color;
101extern int amdgpu_vm_size;
102extern int amdgpu_vm_block_size;
103extern int amdgpu_vm_fragment_size;
104extern int amdgpu_vm_fault_stop;
105extern int amdgpu_vm_debug;
106extern int amdgpu_vm_update_mode;
107extern int amdgpu_dc;
108extern int amdgpu_dc_log;
109extern int amdgpu_sched_jobs;
110extern int amdgpu_sched_hw_submission;
111extern int amdgpu_no_evict;
112extern int amdgpu_direct_gma_size;
113extern uint amdgpu_pcie_gen_cap;
114extern uint amdgpu_pcie_lane_cap;
115extern uint amdgpu_cg_mask;
116extern uint amdgpu_pg_mask;
117extern uint amdgpu_sdma_phase_quantum;
118extern char *amdgpu_disable_cu;
119extern char *amdgpu_virtual_display;
120extern uint amdgpu_pp_feature_mask;
121extern int amdgpu_vram_page_split;
122extern int amdgpu_ngg;
123extern int amdgpu_prim_buf_per_se;
124extern int amdgpu_pos_buf_per_se;
125extern int amdgpu_cntl_sb_buf_per_se;
126extern int amdgpu_param_buf_per_se;
127extern int amdgpu_job_hang_limit;
128extern int amdgpu_lbpw;
129extern int amdgpu_compute_multipipe;
130extern int amdgpu_gpu_recovery;
131extern int amdgpu_emu_mode;
132
133#ifdef CONFIG_DRM_AMDGPU_SI
134extern int amdgpu_si_support;
135#endif
136#ifdef CONFIG_DRM_AMDGPU_CIK
137extern int amdgpu_cik_support;
138#endif
139
140#define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL
141#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
142#define AMDGPU_MAX_USEC_TIMEOUT 100000
143#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
144
145#define AMDGPU_IB_POOL_SIZE 16
146#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
147#define AMDGPUFB_CONN_LIMIT 4
148#define AMDGPU_BIOS_NUM_SCRATCH 16
149
150
151#define AMDGPU_MAX_SDMA_INSTANCES 2
152
153
154#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
155
156
157#define AMDGPU_RESET_GFX (1 << 0)
158#define AMDGPU_RESET_COMPUTE (1 << 1)
159#define AMDGPU_RESET_DMA (1 << 2)
160#define AMDGPU_RESET_CP (1 << 3)
161#define AMDGPU_RESET_GRBM (1 << 4)
162#define AMDGPU_RESET_DMA1 (1 << 5)
163#define AMDGPU_RESET_RLC (1 << 6)
164#define AMDGPU_RESET_SEM (1 << 7)
165#define AMDGPU_RESET_IH (1 << 8)
166#define AMDGPU_RESET_VMC (1 << 9)
167#define AMDGPU_RESET_MC (1 << 10)
168#define AMDGPU_RESET_DISPLAY (1 << 11)
169#define AMDGPU_RESET_UVD (1 << 12)
170#define AMDGPU_RESET_VCE (1 << 13)
171#define AMDGPU_RESET_VCE1 (1 << 14)
172
173
174#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
175#define AMDGPU_GFX_SAFE_MODE 0x00000001L
176#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
177#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
178#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
179
180
181#define CIK_CURSOR_WIDTH 128
182#define CIK_CURSOR_HEIGHT 128
183
184struct amdgpu_device;
185struct amdgpu_ib;
186struct amdgpu_cs_parser;
187struct amdgpu_job;
188struct amdgpu_irq_src;
189struct amdgpu_fpriv;
190struct amdgpu_bo_va_mapping;
191struct amdgpu_atif;
192
193enum amdgpu_cp_irq {
194 AMDGPU_CP_IRQ_GFX_EOP = 0,
195 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
196 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
197 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
198 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
199 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
200 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
201 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
202 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
203
204 AMDGPU_CP_IRQ_LAST
205};
206
207enum amdgpu_sdma_irq {
208 AMDGPU_SDMA_IRQ_TRAP0 = 0,
209 AMDGPU_SDMA_IRQ_TRAP1,
210
211 AMDGPU_SDMA_IRQ_LAST
212};
213
214enum amdgpu_thermal_irq {
215 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
216 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
217
218 AMDGPU_THERMAL_IRQ_LAST
219};
220
221enum amdgpu_kiq_irq {
222 AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
223 AMDGPU_CP_KIQ_IRQ_LAST
224};
225
226int amdgpu_device_ip_set_clockgating_state(struct amdgpu_device *adev,
227 enum amd_ip_block_type block_type,
228 enum amd_clockgating_state state);
229int amdgpu_device_ip_set_powergating_state(struct amdgpu_device *adev,
230 enum amd_ip_block_type block_type,
231 enum amd_powergating_state state);
232void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
233 u32 *flags);
234int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
235 enum amd_ip_block_type block_type);
236bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
237 enum amd_ip_block_type block_type);
238
239#define AMDGPU_MAX_IP_NUM 16
240
241struct amdgpu_ip_block_status {
242 bool valid;
243 bool sw;
244 bool hw;
245 bool late_initialized;
246 bool hang;
247};
248
249struct amdgpu_ip_block_version {
250 const enum amd_ip_block_type type;
251 const u32 major;
252 const u32 minor;
253 const u32 rev;
254 const struct amd_ip_funcs *funcs;
255};
256
257struct amdgpu_ip_block {
258 struct amdgpu_ip_block_status status;
259 const struct amdgpu_ip_block_version *version;
260};
261
262int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
263 enum amd_ip_block_type type,
264 u32 major, u32 minor);
265
266struct amdgpu_ip_block *
267amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
268 enum amd_ip_block_type type);
269
270int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
271 const struct amdgpu_ip_block_version *ip_block_version);
272
273
274struct amdgpu_buffer_funcs {
275
276 uint32_t copy_max_bytes;
277
278
279 unsigned copy_num_dw;
280
281
282 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
283
284 uint64_t src_offset,
285
286 uint64_t dst_offset,
287
288 uint32_t byte_count);
289
290
291 uint32_t fill_max_bytes;
292
293
294 unsigned fill_num_dw;
295
296
297 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
298
299 uint32_t src_data,
300
301 uint64_t dst_offset,
302
303 uint32_t byte_count);
304};
305
306
307struct amdgpu_vm_pte_funcs {
308
309 unsigned copy_pte_num_dw;
310
311
312 void (*copy_pte)(struct amdgpu_ib *ib,
313 uint64_t pe, uint64_t src,
314 unsigned count);
315
316
317 void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
318 uint64_t value, unsigned count,
319 uint32_t incr);
320
321 void (*set_pte_pde)(struct amdgpu_ib *ib,
322 uint64_t pe,
323 uint64_t addr, unsigned count,
324 uint32_t incr, uint64_t flags);
325};
326
327
328struct amdgpu_ih_funcs {
329
330 u32 (*get_wptr)(struct amdgpu_device *adev);
331 bool (*prescreen_iv)(struct amdgpu_device *adev);
332 void (*decode_iv)(struct amdgpu_device *adev,
333 struct amdgpu_iv_entry *entry);
334 void (*set_rptr)(struct amdgpu_device *adev);
335};
336
337
338
339
340bool amdgpu_get_bios(struct amdgpu_device *adev);
341bool amdgpu_read_bios(struct amdgpu_device *adev);
342
343
344
345
346
347#define AMDGPU_MAX_PPLL 3
348
349struct amdgpu_clock {
350 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
351 struct amdgpu_pll spll;
352 struct amdgpu_pll mpll;
353
354 uint32_t default_mclk;
355 uint32_t default_sclk;
356 uint32_t default_dispclk;
357 uint32_t current_dispclk;
358 uint32_t dp_extclk;
359 uint32_t max_pixel_clock;
360};
361
362
363
364
365
366#define AMDGPU_GEM_DOMAIN_MAX 0x3
367#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
368
369void amdgpu_gem_object_free(struct drm_gem_object *obj);
370int amdgpu_gem_object_open(struct drm_gem_object *obj,
371 struct drm_file *file_priv);
372void amdgpu_gem_object_close(struct drm_gem_object *obj,
373 struct drm_file *file_priv);
374unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
375struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
376struct drm_gem_object *
377amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
378 struct dma_buf_attachment *attach,
379 struct sg_table *sg);
380struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
381 struct drm_gem_object *gobj,
382 int flags);
383struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
384 struct dma_buf *dma_buf);
385struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
386void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
387void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
388int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414#define AMDGPU_SA_NUM_FENCE_LISTS 32
415
416struct amdgpu_sa_manager {
417 wait_queue_head_t wq;
418 struct amdgpu_bo *bo;
419 struct list_head *hole;
420 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
421 struct list_head olist;
422 unsigned size;
423 uint64_t gpu_addr;
424 void *cpu_ptr;
425 uint32_t domain;
426 uint32_t align;
427};
428
429
430struct amdgpu_sa_bo {
431 struct list_head olist;
432 struct list_head flist;
433 struct amdgpu_sa_manager *manager;
434 unsigned soffset;
435 unsigned eoffset;
436 struct dma_fence *fence;
437};
438
439
440
441
442void amdgpu_gem_force_release(struct amdgpu_device *adev);
443int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
444 int alignment, u32 initial_domain,
445 u64 flags, enum ttm_bo_type type,
446 struct reservation_object *resv,
447 struct drm_gem_object **obj);
448
449int amdgpu_mode_dumb_create(struct drm_file *file_priv,
450 struct drm_device *dev,
451 struct drm_mode_create_dumb *args);
452int amdgpu_mode_dumb_mmap(struct drm_file *filp,
453 struct drm_device *dev,
454 uint32_t handle, uint64_t *offset_p);
455int amdgpu_fence_slab_init(void);
456void amdgpu_fence_slab_fini(void);
457
458
459
460
461typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
462{
463 AMDGPU_DOORBELL_KIQ = 0x000,
464 AMDGPU_DOORBELL_HIQ = 0x001,
465 AMDGPU_DOORBELL_DIQ = 0x002,
466 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
467 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
468 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
469 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
470 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
471 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
472 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
473 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
474 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
475 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
476 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
477 AMDGPU_DOORBELL_IH = 0x1E8,
478 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
479 AMDGPU_DOORBELL_INVALID = 0xFFFF
480} AMDGPU_DOORBELL_ASSIGNMENT;
481
482struct amdgpu_doorbell {
483
484 resource_size_t base;
485 resource_size_t size;
486 u32 __iomem *ptr;
487 u32 num_doorbells;
488};
489
490
491
492
493typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
494{
495
496
497
498
499
500
501
502
503 AMDGPU_DOORBELL64_KIQ = 0x00,
504
505
506 AMDGPU_DOORBELL64_HIQ = 0x01,
507 AMDGPU_DOORBELL64_DIQ = 0x02,
508
509
510 AMDGPU_DOORBELL64_MEC_RING0 = 0x03,
511 AMDGPU_DOORBELL64_MEC_RING1 = 0x04,
512 AMDGPU_DOORBELL64_MEC_RING2 = 0x05,
513 AMDGPU_DOORBELL64_MEC_RING3 = 0x06,
514 AMDGPU_DOORBELL64_MEC_RING4 = 0x07,
515 AMDGPU_DOORBELL64_MEC_RING5 = 0x08,
516 AMDGPU_DOORBELL64_MEC_RING6 = 0x09,
517 AMDGPU_DOORBELL64_MEC_RING7 = 0x0a,
518
519
520 AMDGPU_DOORBELL64_USERQUEUE_START = 0x0b,
521 AMDGPU_DOORBELL64_USERQUEUE_END = 0x8a,
522
523
524 AMDGPU_DOORBELL64_GFX_RING0 = 0x8b,
525
526
527
528
529
530
531
532
533 AMDGPU_DOORBELL64_sDMA_ENGINE0 = 0xF0,
534 AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
535 AMDGPU_DOORBELL64_sDMA_ENGINE1 = 0xF2,
536 AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
537
538
539 AMDGPU_DOORBELL64_IH = 0xF4,
540 AMDGPU_DOORBELL64_IH_RING1 = 0xF5,
541 AMDGPU_DOORBELL64_IH_RING2 = 0xF6,
542
543
544 AMDGPU_DOORBELL64_VCN0_1 = 0xF8,
545 AMDGPU_DOORBELL64_VCN2_3 = 0xF9,
546 AMDGPU_DOORBELL64_VCN4_5 = 0xFA,
547 AMDGPU_DOORBELL64_VCN6_7 = 0xFB,
548
549
550
551
552 AMDGPU_DOORBELL64_UVD_RING0_1 = 0xF8,
553 AMDGPU_DOORBELL64_UVD_RING2_3 = 0xF9,
554 AMDGPU_DOORBELL64_UVD_RING4_5 = 0xFA,
555 AMDGPU_DOORBELL64_UVD_RING6_7 = 0xFB,
556
557 AMDGPU_DOORBELL64_VCE_RING0_1 = 0xFC,
558 AMDGPU_DOORBELL64_VCE_RING2_3 = 0xFD,
559 AMDGPU_DOORBELL64_VCE_RING4_5 = 0xFE,
560 AMDGPU_DOORBELL64_VCE_RING6_7 = 0xFF,
561
562 AMDGPU_DOORBELL64_MAX_ASSIGNMENT = 0xFF,
563 AMDGPU_DOORBELL64_INVALID = 0xFFFF
564} AMDGPU_DOORBELL64_ASSIGNMENT;
565
566
567
568
569
570struct amdgpu_flip_work {
571 struct delayed_work flip_work;
572 struct work_struct unpin_work;
573 struct amdgpu_device *adev;
574 int crtc_id;
575 u32 target_vblank;
576 uint64_t base;
577 struct drm_pending_vblank_event *event;
578 struct amdgpu_bo *old_abo;
579 struct dma_fence *excl;
580 unsigned shared_count;
581 struct dma_fence **shared;
582 struct dma_fence_cb cb;
583 bool async;
584};
585
586
587
588
589
590
591struct amdgpu_ib {
592 struct amdgpu_sa_bo *sa_bo;
593 uint32_t length_dw;
594 uint64_t gpu_addr;
595 uint32_t *ptr;
596 uint32_t flags;
597};
598
599extern const struct drm_sched_backend_ops amdgpu_sched_ops;
600
601int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
602 struct amdgpu_job **job, struct amdgpu_vm *vm);
603int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
604 struct amdgpu_job **job);
605
606void amdgpu_job_free_resources(struct amdgpu_job *job);
607void amdgpu_job_free(struct amdgpu_job *job);
608int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
609 struct drm_sched_entity *entity, void *owner,
610 struct dma_fence **f);
611
612
613
614
615struct amdgpu_queue_mapper {
616 int hw_ip;
617 struct mutex lock;
618
619 struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
620};
621
622struct amdgpu_queue_mgr {
623 struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
624};
625
626int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
627 struct amdgpu_queue_mgr *mgr);
628int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
629 struct amdgpu_queue_mgr *mgr);
630int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
631 struct amdgpu_queue_mgr *mgr,
632 u32 hw_ip, u32 instance, u32 ring,
633 struct amdgpu_ring **out_ring);
634
635
636
637
638
639struct amdgpu_ctx_ring {
640 uint64_t sequence;
641 struct dma_fence **fences;
642 struct drm_sched_entity entity;
643};
644
645struct amdgpu_ctx {
646 struct kref refcount;
647 struct amdgpu_device *adev;
648 struct amdgpu_queue_mgr queue_mgr;
649 unsigned reset_counter;
650 unsigned reset_counter_query;
651 uint32_t vram_lost_counter;
652 spinlock_t ring_lock;
653 struct dma_fence **fences;
654 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
655 bool preamble_presented;
656 enum drm_sched_priority init_priority;
657 enum drm_sched_priority override_priority;
658 struct mutex lock;
659 atomic_t guilty;
660};
661
662struct amdgpu_ctx_mgr {
663 struct amdgpu_device *adev;
664 struct mutex lock;
665
666 struct idr ctx_handles;
667};
668
669struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
670int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
671
672int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
673 struct dma_fence *fence, uint64_t *seq);
674struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
675 struct amdgpu_ring *ring, uint64_t seq);
676void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
677 enum drm_sched_priority priority);
678
679int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
680 struct drm_file *filp);
681
682int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id);
683
684void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
685void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
686
687
688
689
690
691
692struct amdgpu_fpriv {
693 struct amdgpu_vm vm;
694 struct amdgpu_bo_va *prt_va;
695 struct amdgpu_bo_va *csa_va;
696 struct mutex bo_list_lock;
697 struct idr bo_list_handles;
698 struct amdgpu_ctx_mgr ctx_mgr;
699};
700
701
702
703
704struct amdgpu_bo_list_entry {
705 struct amdgpu_bo *robj;
706 struct ttm_validate_buffer tv;
707 struct amdgpu_bo_va *bo_va;
708 uint32_t priority;
709 struct page **user_pages;
710 int user_invalidated;
711};
712
713struct amdgpu_bo_list {
714 struct mutex lock;
715 struct rcu_head rhead;
716 struct kref refcount;
717 struct amdgpu_bo *gds_obj;
718 struct amdgpu_bo *gws_obj;
719 struct amdgpu_bo *oa_obj;
720 unsigned first_userptr;
721 unsigned num_entries;
722 struct amdgpu_bo_list_entry *array;
723};
724
725struct amdgpu_bo_list *
726amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
727void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
728 struct list_head *validated);
729void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
730void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
731
732
733
734
735#include "clearstate_defs.h"
736
737struct amdgpu_rlc_funcs {
738 void (*enter_safe_mode)(struct amdgpu_device *adev);
739 void (*exit_safe_mode)(struct amdgpu_device *adev);
740};
741
742struct amdgpu_rlc {
743
744 struct amdgpu_bo *save_restore_obj;
745 uint64_t save_restore_gpu_addr;
746 volatile uint32_t *sr_ptr;
747 const u32 *reg_list;
748 u32 reg_list_size;
749
750 struct amdgpu_bo *clear_state_obj;
751 uint64_t clear_state_gpu_addr;
752 volatile uint32_t *cs_ptr;
753 const struct cs_section_def *cs_data;
754 u32 clear_state_size;
755
756 struct amdgpu_bo *cp_table_obj;
757 uint64_t cp_table_gpu_addr;
758 volatile uint32_t *cp_table_ptr;
759 u32 cp_table_size;
760
761
762 bool in_safe_mode;
763 const struct amdgpu_rlc_funcs *funcs;
764
765
766 u32 save_and_restore_offset;
767 u32 clear_state_descriptor_offset;
768 u32 avail_scratch_ram_locations;
769 u32 reg_restore_list_size;
770 u32 reg_list_format_start;
771 u32 reg_list_format_separate_start;
772 u32 starting_offsets_start;
773 u32 reg_list_format_size_bytes;
774 u32 reg_list_size_bytes;
775
776 u32 *register_list_format;
777 u32 *register_restore;
778};
779
780#define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
781
782struct amdgpu_mec {
783 struct amdgpu_bo *hpd_eop_obj;
784 u64 hpd_eop_gpu_addr;
785 struct amdgpu_bo *mec_fw_obj;
786 u64 mec_fw_gpu_addr;
787 u32 num_mec;
788 u32 num_pipe_per_mec;
789 u32 num_queue_per_pipe;
790 void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
791
792
793 DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
794};
795
796struct amdgpu_kiq {
797 u64 eop_gpu_addr;
798 struct amdgpu_bo *eop_obj;
799 spinlock_t ring_lock;
800 struct amdgpu_ring ring;
801 struct amdgpu_irq_src irq;
802};
803
804
805
806
807struct amdgpu_scratch {
808 unsigned num_reg;
809 uint32_t reg_base;
810 uint32_t free_mask;
811};
812
813
814
815
816#define AMDGPU_GFX_MAX_SE 4
817#define AMDGPU_GFX_MAX_SH_PER_SE 2
818
819struct amdgpu_rb_config {
820 uint32_t rb_backend_disable;
821 uint32_t user_rb_backend_disable;
822 uint32_t raster_config;
823 uint32_t raster_config_1;
824};
825
826struct gb_addr_config {
827 uint16_t pipe_interleave_size;
828 uint8_t num_pipes;
829 uint8_t max_compress_frags;
830 uint8_t num_banks;
831 uint8_t num_se;
832 uint8_t num_rb_per_se;
833};
834
835struct amdgpu_gfx_config {
836 unsigned max_shader_engines;
837 unsigned max_tile_pipes;
838 unsigned max_cu_per_sh;
839 unsigned max_sh_per_se;
840 unsigned max_backends_per_se;
841 unsigned max_texture_channel_caches;
842 unsigned max_gprs;
843 unsigned max_gs_threads;
844 unsigned max_hw_contexts;
845 unsigned sc_prim_fifo_size_frontend;
846 unsigned sc_prim_fifo_size_backend;
847 unsigned sc_hiz_tile_fifo_size;
848 unsigned sc_earlyz_tile_fifo_size;
849
850 unsigned num_tile_pipes;
851 unsigned backend_enable_mask;
852 unsigned mem_max_burst_length_bytes;
853 unsigned mem_row_size_in_kb;
854 unsigned shader_engine_tile_size;
855 unsigned num_gpus;
856 unsigned multi_gpu_tile_size;
857 unsigned mc_arb_ramcfg;
858 unsigned gb_addr_config;
859 unsigned num_rbs;
860 unsigned gs_vgt_table_depth;
861 unsigned gs_prim_buffer_depth;
862
863 uint32_t tile_mode_array[32];
864 uint32_t macrotile_mode_array[16];
865
866 struct gb_addr_config gb_addr_config_fields;
867 struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
868
869
870 uint32_t double_offchip_lds_buf;
871};
872
873struct amdgpu_cu_info {
874 uint32_t simd_per_cu;
875 uint32_t max_waves_per_simd;
876 uint32_t wave_front_size;
877 uint32_t max_scratch_slots_per_cu;
878 uint32_t lds_size;
879
880
881 uint32_t number;
882 uint32_t ao_cu_mask;
883 uint32_t ao_cu_bitmap[4][4];
884 uint32_t bitmap[4][4];
885};
886
887struct amdgpu_gfx_funcs {
888
889 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
890 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
891 void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);
892 void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t thread, uint32_t start, uint32_t size, uint32_t *dst);
893 void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst);
894 void (*select_me_pipe_q)(struct amdgpu_device *adev, u32 me, u32 pipe, u32 queue);
895};
896
897struct amdgpu_ngg_buf {
898 struct amdgpu_bo *bo;
899 uint64_t gpu_addr;
900 uint32_t size;
901 uint32_t bo_size;
902};
903
904enum {
905 NGG_PRIM = 0,
906 NGG_POS,
907 NGG_CNTL,
908 NGG_PARAM,
909 NGG_BUF_MAX
910};
911
912struct amdgpu_ngg {
913 struct amdgpu_ngg_buf buf[NGG_BUF_MAX];
914 uint32_t gds_reserve_addr;
915 uint32_t gds_reserve_size;
916 bool init;
917};
918
919struct amdgpu_gfx {
920 struct mutex gpu_clock_mutex;
921 struct amdgpu_gfx_config config;
922 struct amdgpu_rlc rlc;
923 struct amdgpu_mec mec;
924 struct amdgpu_kiq kiq;
925 struct amdgpu_scratch scratch;
926 const struct firmware *me_fw;
927 uint32_t me_fw_version;
928 const struct firmware *pfp_fw;
929 uint32_t pfp_fw_version;
930 const struct firmware *ce_fw;
931 uint32_t ce_fw_version;
932 const struct firmware *rlc_fw;
933 uint32_t rlc_fw_version;
934 const struct firmware *mec_fw;
935 uint32_t mec_fw_version;
936 const struct firmware *mec2_fw;
937 uint32_t mec2_fw_version;
938 uint32_t me_feature_version;
939 uint32_t ce_feature_version;
940 uint32_t pfp_feature_version;
941 uint32_t rlc_feature_version;
942 uint32_t mec_feature_version;
943 uint32_t mec2_feature_version;
944 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
945 unsigned num_gfx_rings;
946 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
947 unsigned num_compute_rings;
948 struct amdgpu_irq_src eop_irq;
949 struct amdgpu_irq_src priv_reg_irq;
950 struct amdgpu_irq_src priv_inst_irq;
951
952 uint32_t gfx_current_status;
953
954 unsigned ce_ram_size;
955 struct amdgpu_cu_info cu_info;
956 const struct amdgpu_gfx_funcs *funcs;
957
958
959 uint32_t grbm_soft_reset;
960 uint32_t srbm_soft_reset;
961
962 bool in_suspend;
963
964 struct amdgpu_ngg ngg;
965
966
967 struct mutex pipe_reserve_mutex;
968 DECLARE_BITMAP (pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
969};
970
971int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
972 unsigned size, struct amdgpu_ib *ib);
973void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
974 struct dma_fence *f);
975int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
976 struct amdgpu_ib *ibs, struct amdgpu_job *job,
977 struct dma_fence **f);
978int amdgpu_ib_pool_init(struct amdgpu_device *adev);
979void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
980int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
981
982
983
984
985struct amdgpu_cs_chunk {
986 uint32_t chunk_id;
987 uint32_t length_dw;
988 void *kdata;
989};
990
991struct amdgpu_cs_parser {
992 struct amdgpu_device *adev;
993 struct drm_file *filp;
994 struct amdgpu_ctx *ctx;
995
996
997 unsigned nchunks;
998 struct amdgpu_cs_chunk *chunks;
999
1000
1001 struct amdgpu_job *job;
1002
1003
1004 struct ww_acquire_ctx ticket;
1005 struct amdgpu_bo_list *bo_list;
1006 struct amdgpu_mn *mn;
1007 struct amdgpu_bo_list_entry vm_pd;
1008 struct list_head validated;
1009 struct dma_fence *fence;
1010 uint64_t bytes_moved_threshold;
1011 uint64_t bytes_moved_vis_threshold;
1012 uint64_t bytes_moved;
1013 uint64_t bytes_moved_vis;
1014 struct amdgpu_bo_list_entry *evictable;
1015
1016
1017 struct amdgpu_bo_list_entry uf_entry;
1018
1019 unsigned num_post_dep_syncobjs;
1020 struct drm_syncobj **post_dep_syncobjs;
1021};
1022
1023#define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0)
1024#define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1)
1025#define AMDGPU_HAVE_CTX_SWITCH (1 << 2)
1026
1027struct amdgpu_job {
1028 struct drm_sched_job base;
1029 struct amdgpu_device *adev;
1030 struct amdgpu_vm *vm;
1031 struct amdgpu_ring *ring;
1032 struct amdgpu_sync sync;
1033 struct amdgpu_sync sched_sync;
1034 struct amdgpu_ib *ibs;
1035 struct dma_fence *fence;
1036 uint32_t preamble_status;
1037 uint32_t num_ibs;
1038 void *owner;
1039 uint64_t fence_ctx;
1040 bool vm_needs_flush;
1041 uint64_t vm_pd_addr;
1042 unsigned vmid;
1043 unsigned pasid;
1044 uint32_t gds_base, gds_size;
1045 uint32_t gws_base, gws_size;
1046 uint32_t oa_base, oa_size;
1047 uint32_t vram_lost_counter;
1048
1049
1050 uint64_t uf_addr;
1051 uint64_t uf_sequence;
1052
1053};
1054#define to_amdgpu_job(sched_job) \
1055 container_of((sched_job), struct amdgpu_job, base)
1056
1057static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1058 uint32_t ib_idx, int idx)
1059{
1060 return p->job->ibs[ib_idx].ptr[idx];
1061}
1062
1063static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1064 uint32_t ib_idx, int idx,
1065 uint32_t value)
1066{
1067 p->job->ibs[ib_idx].ptr[idx] = value;
1068}
1069
1070
1071
1072
1073#define AMDGPU_MAX_WB 128
1074
1075struct amdgpu_wb {
1076 struct amdgpu_bo *wb_obj;
1077 volatile uint32_t *wb;
1078 uint64_t gpu_addr;
1079 u32 num_wb;
1080 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1081};
1082
1083int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
1084void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
1085
1086
1087
1088
1089struct amdgpu_sdma_instance {
1090
1091 const struct firmware *fw;
1092 uint32_t fw_version;
1093 uint32_t feature_version;
1094
1095 struct amdgpu_ring ring;
1096 bool burst_nop;
1097};
1098
1099struct amdgpu_sdma {
1100 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1101#ifdef CONFIG_DRM_AMDGPU_SI
1102
1103 struct amdgpu_irq_src trap_irq_1;
1104#endif
1105 struct amdgpu_irq_src trap_irq;
1106 struct amdgpu_irq_src illegal_inst_irq;
1107 int num_instances;
1108 uint32_t srbm_soft_reset;
1109};
1110
1111
1112
1113
1114enum amdgpu_firmware_load_type {
1115 AMDGPU_FW_LOAD_DIRECT = 0,
1116 AMDGPU_FW_LOAD_SMU,
1117 AMDGPU_FW_LOAD_PSP,
1118};
1119
1120struct amdgpu_firmware {
1121 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1122 enum amdgpu_firmware_load_type load_type;
1123 struct amdgpu_bo *fw_buf;
1124 unsigned int fw_size;
1125 unsigned int max_ucodes;
1126
1127 const struct amdgpu_psp_funcs *funcs;
1128 struct amdgpu_bo *rbuf;
1129 struct mutex mutex;
1130
1131
1132 const struct firmware *gpu_info_fw;
1133
1134 void *fw_buf_ptr;
1135 uint64_t fw_buf_mc;
1136};
1137
1138
1139
1140
1141void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1142
1143
1144
1145
1146
1147void amdgpu_test_moves(struct amdgpu_device *adev);
1148
1149
1150
1151
1152
1153struct amdgpu_smumgr_funcs {
1154 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1155 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1156 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1157};
1158
1159
1160
1161
1162struct amdgpu_smumgr {
1163 struct amdgpu_bo *toc_buf;
1164 struct amdgpu_bo *smu_buf;
1165
1166 void *priv;
1167 spinlock_t smu_lock;
1168
1169 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1170
1171 uint32_t fw_flags;
1172};
1173
1174
1175
1176
1177struct amdgpu_allowed_register_entry {
1178 uint32_t reg_offset;
1179 bool grbm_indexed;
1180};
1181
1182
1183
1184
1185struct amdgpu_asic_funcs {
1186 bool (*read_disabled_bios)(struct amdgpu_device *adev);
1187 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1188 u8 *bios, u32 length_bytes);
1189 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1190 u32 sh_num, u32 reg_offset, u32 *value);
1191 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1192 int (*reset)(struct amdgpu_device *adev);
1193
1194 u32 (*get_xclk)(struct amdgpu_device *adev);
1195
1196 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1197 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1198
1199 int (*get_pcie_lanes)(struct amdgpu_device *adev);
1200 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
1201
1202 u32 (*get_config_memsize)(struct amdgpu_device *adev);
1203
1204 void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
1205
1206 void (*invalidate_hdp)(struct amdgpu_device *adev,
1207 struct amdgpu_ring *ring);
1208};
1209
1210
1211
1212
1213int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1214 struct drm_file *filp);
1215int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1216 struct drm_file *filp);
1217
1218int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1219 struct drm_file *filp);
1220int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1221 struct drm_file *filp);
1222int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1223 struct drm_file *filp);
1224int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1225 struct drm_file *filp);
1226int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1227 struct drm_file *filp);
1228int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1229 struct drm_file *filp);
1230int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1231int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
1232 struct drm_file *filp);
1233int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1234int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
1235 struct drm_file *filp);
1236
1237int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1238 struct drm_file *filp);
1239
1240
1241struct amdgpu_vram_scratch {
1242 struct amdgpu_bo *robj;
1243 volatile uint32_t *ptr;
1244 u64 gpu_addr;
1245};
1246
1247
1248
1249
1250struct amdgpu_atcs_functions {
1251 bool get_ext_state;
1252 bool pcie_perf_req;
1253 bool pcie_dev_rdy;
1254 bool pcie_bus_width;
1255};
1256
1257struct amdgpu_atcs {
1258 struct amdgpu_atcs_functions functions;
1259};
1260
1261
1262
1263
1264struct amdgpu_fw_vram_usage {
1265 u64 start_offset;
1266 u64 size;
1267 struct amdgpu_bo *reserved_bo;
1268 void *va;
1269};
1270
1271
1272
1273
1274struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1275void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
1276
1277
1278
1279
1280typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1281typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1282
1283typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1284typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1285
1286
1287
1288
1289
1290
1291struct nbio_hdp_flush_reg {
1292 u32 ref_and_mask_cp0;
1293 u32 ref_and_mask_cp1;
1294 u32 ref_and_mask_cp2;
1295 u32 ref_and_mask_cp3;
1296 u32 ref_and_mask_cp4;
1297 u32 ref_and_mask_cp5;
1298 u32 ref_and_mask_cp6;
1299 u32 ref_and_mask_cp7;
1300 u32 ref_and_mask_cp8;
1301 u32 ref_and_mask_cp9;
1302 u32 ref_and_mask_sdma0;
1303 u32 ref_and_mask_sdma1;
1304};
1305
1306struct amdgpu_nbio_funcs {
1307 const struct nbio_hdp_flush_reg *hdp_flush_reg;
1308 u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
1309 u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
1310 u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
1311 u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
1312 u32 (*get_rev_id)(struct amdgpu_device *adev);
1313 void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
1314 void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
1315 u32 (*get_memsize)(struct amdgpu_device *adev);
1316 void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
1317 bool use_doorbell, int doorbell_index);
1318 void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
1319 bool enable);
1320 void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
1321 bool enable);
1322 void (*ih_doorbell_range)(struct amdgpu_device *adev,
1323 bool use_doorbell, int doorbell_index);
1324 void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
1325 bool enable);
1326 void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
1327 bool enable);
1328 void (*get_clockgating_state)(struct amdgpu_device *adev,
1329 u32 *flags);
1330 void (*ih_control)(struct amdgpu_device *adev);
1331 void (*init_registers)(struct amdgpu_device *adev);
1332 void (*detect_hw_virt)(struct amdgpu_device *adev);
1333};
1334
1335
1336
1337enum amd_hw_ip_block_type {
1338 GC_HWIP = 1,
1339 HDP_HWIP,
1340 SDMA0_HWIP,
1341 SDMA1_HWIP,
1342 MMHUB_HWIP,
1343 ATHUB_HWIP,
1344 NBIO_HWIP,
1345 MP0_HWIP,
1346 MP1_HWIP,
1347 UVD_HWIP,
1348 VCN_HWIP = UVD_HWIP,
1349 VCE_HWIP,
1350 DF_HWIP,
1351 DCE_HWIP,
1352 OSSSYS_HWIP,
1353 SMUIO_HWIP,
1354 PWR_HWIP,
1355 NBIF_HWIP,
1356 THM_HWIP,
1357 MAX_HWIP
1358};
1359
1360#define HWIP_MAX_INSTANCE 6
1361
1362struct amd_powerplay {
1363 void *pp_handle;
1364 const struct amd_pm_funcs *pp_funcs;
1365};
1366
1367#define AMDGPU_RESET_MAGIC_NUM 64
1368struct amdgpu_device {
1369 struct device *dev;
1370 struct drm_device *ddev;
1371 struct pci_dev *pdev;
1372
1373#ifdef CONFIG_DRM_AMD_ACP
1374 struct amdgpu_acp acp;
1375#endif
1376
1377
1378 enum amd_asic_type asic_type;
1379 uint32_t family;
1380 uint32_t rev_id;
1381 uint32_t external_rev_id;
1382 unsigned long flags;
1383 int usec_timeout;
1384 const struct amdgpu_asic_funcs *asic_funcs;
1385 bool shutdown;
1386 bool need_dma32;
1387 bool need_swiotlb;
1388 bool accel_working;
1389 struct work_struct reset_work;
1390 struct notifier_block acpi_nb;
1391 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1392 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1393 unsigned debugfs_count;
1394#if defined(CONFIG_DEBUG_FS)
1395 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1396#endif
1397 struct amdgpu_atif *atif;
1398 struct amdgpu_atcs atcs;
1399 struct mutex srbm_mutex;
1400
1401 struct mutex grbm_idx_mutex;
1402 struct dev_pm_domain vga_pm_domain;
1403 bool have_disp_power_ref;
1404
1405
1406 bool is_atom_fw;
1407 uint8_t *bios;
1408 uint32_t bios_size;
1409 struct amdgpu_bo *stolen_vga_memory;
1410 uint32_t bios_scratch_reg_offset;
1411 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1412
1413
1414 resource_size_t rmmio_base;
1415 resource_size_t rmmio_size;
1416 void __iomem *rmmio;
1417
1418 spinlock_t mmio_idx_lock;
1419
1420 spinlock_t smc_idx_lock;
1421 amdgpu_rreg_t smc_rreg;
1422 amdgpu_wreg_t smc_wreg;
1423
1424 spinlock_t pcie_idx_lock;
1425 amdgpu_rreg_t pcie_rreg;
1426 amdgpu_wreg_t pcie_wreg;
1427 amdgpu_rreg_t pciep_rreg;
1428 amdgpu_wreg_t pciep_wreg;
1429
1430 spinlock_t uvd_ctx_idx_lock;
1431 amdgpu_rreg_t uvd_ctx_rreg;
1432 amdgpu_wreg_t uvd_ctx_wreg;
1433
1434 spinlock_t didt_idx_lock;
1435 amdgpu_rreg_t didt_rreg;
1436 amdgpu_wreg_t didt_wreg;
1437
1438 spinlock_t gc_cac_idx_lock;
1439 amdgpu_rreg_t gc_cac_rreg;
1440 amdgpu_wreg_t gc_cac_wreg;
1441
1442 spinlock_t se_cac_idx_lock;
1443 amdgpu_rreg_t se_cac_rreg;
1444 amdgpu_wreg_t se_cac_wreg;
1445
1446 spinlock_t audio_endpt_idx_lock;
1447 amdgpu_block_rreg_t audio_endpt_rreg;
1448 amdgpu_block_wreg_t audio_endpt_wreg;
1449 void __iomem *rio_mem;
1450 resource_size_t rio_mem_size;
1451 struct amdgpu_doorbell doorbell;
1452
1453
1454 struct amdgpu_clock clock;
1455
1456
1457 struct amdgpu_gmc gmc;
1458 struct amdgpu_gart gart;
1459 dma_addr_t dummy_page_addr;
1460 struct amdgpu_vm_manager vm_manager;
1461 struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS];
1462
1463
1464 struct amdgpu_mman mman;
1465 struct amdgpu_vram_scratch vram_scratch;
1466 struct amdgpu_wb wb;
1467 atomic64_t num_bytes_moved;
1468 atomic64_t num_evictions;
1469 atomic64_t num_vram_cpu_page_faults;
1470 atomic_t gpu_reset_counter;
1471 atomic_t vram_lost_counter;
1472
1473
1474 struct {
1475 spinlock_t lock;
1476 s64 last_update_us;
1477 s64 accum_us;
1478 s64 accum_us_vis;
1479 u32 log2_max_MBps;
1480 } mm_stats;
1481
1482
1483 bool enable_virtual_display;
1484 struct amdgpu_mode_info mode_info;
1485
1486 struct work_struct hotplug_work;
1487 struct amdgpu_irq_src crtc_irq;
1488 struct amdgpu_irq_src pageflip_irq;
1489 struct amdgpu_irq_src hpd_irq;
1490
1491
1492 u64 fence_context;
1493 unsigned num_rings;
1494 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1495 bool ib_pool_ready;
1496 struct amdgpu_sa_manager ring_tmp_bo;
1497
1498
1499 struct amdgpu_irq irq;
1500
1501
1502 struct amd_powerplay powerplay;
1503 bool pp_force_state_enabled;
1504
1505
1506 struct amdgpu_pm pm;
1507 u32 cg_flags;
1508 u32 pg_flags;
1509
1510
1511 struct amdgpu_smumgr smu;
1512
1513
1514 struct amdgpu_gfx gfx;
1515
1516
1517 struct amdgpu_sdma sdma;
1518
1519
1520 struct amdgpu_uvd uvd;
1521
1522
1523 struct amdgpu_vce vce;
1524
1525
1526 struct amdgpu_vcn vcn;
1527
1528
1529 struct amdgpu_firmware firmware;
1530
1531
1532 struct psp_context psp;
1533
1534
1535 struct amdgpu_gds gds;
1536
1537
1538 struct amdgpu_display_manager dm;
1539
1540 struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM];
1541 int num_ip_blocks;
1542 struct mutex mn_lock;
1543 DECLARE_HASHTABLE(mn_hash, 7);
1544
1545
1546 u64 vram_pin_size;
1547 u64 invisible_pin_size;
1548 u64 gart_pin_size;
1549
1550
1551 struct kfd_dev *kfd;
1552
1553
1554 uint32_t *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
1555
1556 const struct amdgpu_nbio_funcs *nbio_funcs;
1557
1558
1559 struct delayed_work late_init_work;
1560
1561 struct amdgpu_virt virt;
1562
1563 struct amdgpu_fw_vram_usage fw_vram_usage;
1564
1565
1566 struct list_head shadow_list;
1567 struct mutex shadow_list_lock;
1568
1569 struct list_head ring_lru_list;
1570 spinlock_t ring_lru_list_lock;
1571
1572
1573 bool has_hw_reset;
1574 u8 reset_magic[AMDGPU_RESET_MAGIC_NUM];
1575
1576
1577 unsigned long last_mm_index;
1578 bool in_gpu_reset;
1579 struct mutex lock_reset;
1580};
1581
1582static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1583{
1584 return container_of(bdev, struct amdgpu_device, mman.bdev);
1585}
1586
1587int amdgpu_device_init(struct amdgpu_device *adev,
1588 struct drm_device *ddev,
1589 struct pci_dev *pdev,
1590 uint32_t flags);
1591void amdgpu_device_fini(struct amdgpu_device *adev);
1592int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1593
1594uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
1595 uint32_t acc_flags);
1596void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
1597 uint32_t acc_flags);
1598void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
1599uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
1600
1601u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1602void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1603
1604u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1605void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1606u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1607void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
1608
1609bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
1610bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
1611
1612int emu_soc_asic_init(struct amdgpu_device *adev);
1613
1614
1615
1616
1617
1618#define AMDGPU_REGS_IDX (1<<0)
1619#define AMDGPU_REGS_NO_KIQ (1<<1)
1620
1621#define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
1622#define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
1623
1624#define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
1625#define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
1626
1627#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
1628#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
1629#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
1630#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
1631#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
1632#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1633#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1634#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1635#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
1636#define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
1637#define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
1638#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
1639#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
1640#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
1641#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
1642#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
1643#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
1644#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1645#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
1646#define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
1647#define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
1648#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
1649#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
1650#define WREG32_P(reg, val, mask) \
1651 do { \
1652 uint32_t tmp_ = RREG32(reg); \
1653 tmp_ &= (mask); \
1654 tmp_ |= ((val) & ~(mask)); \
1655 WREG32(reg, tmp_); \
1656 } while (0)
1657#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1658#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1659#define WREG32_PLL_P(reg, val, mask) \
1660 do { \
1661 uint32_t tmp_ = RREG32_PLL(reg); \
1662 tmp_ &= (mask); \
1663 tmp_ |= ((val) & ~(mask)); \
1664 WREG32_PLL(reg, tmp_); \
1665 } while (0)
1666#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
1667#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1668#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1669
1670#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
1671#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1672#define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1673#define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
1674
1675#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1676#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1677
1678#define REG_SET_FIELD(orig_val, reg, field, field_val) \
1679 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
1680 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1681
1682#define REG_GET_FIELD(value, reg, field) \
1683 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1684
1685#define WREG32_FIELD(reg, field, val) \
1686 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1687
1688#define WREG32_FIELD_OFFSET(reg, offset, field, val) \
1689 WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1690
1691
1692
1693
1694#define RBIOS8(i) (adev->bios[i])
1695#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1696#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1697
1698static inline struct amdgpu_sdma_instance *
1699amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
1700{
1701 struct amdgpu_device *adev = ring->adev;
1702 int i;
1703
1704 for (i = 0; i < adev->sdma.num_instances; i++)
1705 if (&adev->sdma.instance[i].ring == ring)
1706 break;
1707
1708 if (i < AMDGPU_MAX_SDMA_INSTANCES)
1709 return &adev->sdma.instance[i];
1710 else
1711 return NULL;
1712}
1713
1714
1715
1716
1717#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1718#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
1719#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1720#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1721#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1722#define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1723#define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1724#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
1725#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
1726#define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
1727#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1728#define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
1729#define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r))
1730#define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))
1731#define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
1732#define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
1733#define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
1734#define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
1735#define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) (adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags))
1736#define amdgpu_gmc_get_pte_flags(adev, flags) (adev)->gmc.gmc_funcs->get_vm_pte_flags((adev),(flags))
1737#define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
1738#define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
1739#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)))
1740#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
1741#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
1742#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
1743#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
1744#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
1745#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
1746#define amdgpu_ring_emit_ib(r, ib, vmid, c) (r)->funcs->emit_ib((r), (ib), (vmid), (c))
1747#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
1748#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
1749#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
1750#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))
1751#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
1752#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
1753#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
1754#define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
1755#define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
1756#define amdgpu_ring_emit_reg_wait(r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m))
1757#define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
1758#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
1759#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
1760#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
1761#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
1762#define amdgpu_ih_prescreen_iv(adev) (adev)->irq.ih_funcs->prescreen_iv((adev))
1763#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
1764#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
1765#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
1766#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
1767#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
1768#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
1769#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
1770#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
1771#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
1772#define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
1773#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
1774#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
1775#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))
1776#define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b))
1777#define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
1778#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
1779#define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
1780#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
1781#define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
1782#define amdgpu_gfx_select_me_pipe_q(adev, me, pipe, q) (adev)->gfx.funcs->select_me_pipe_q((adev), (me), (pipe), (q))
1783
1784
1785int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
1786 struct amdgpu_job* job, bool force);
1787void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
1788bool amdgpu_device_need_post(struct amdgpu_device *adev);
1789void amdgpu_display_update_priority(struct amdgpu_device *adev);
1790
1791void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
1792 u64 num_vis_bytes);
1793void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
1794bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
1795void amdgpu_device_vram_location(struct amdgpu_device *adev,
1796 struct amdgpu_gmc *mc, u64 base);
1797void amdgpu_device_gart_location(struct amdgpu_device *adev,
1798 struct amdgpu_gmc *mc);
1799int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
1800void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
1801 const u32 *registers,
1802 const u32 array_size);
1803
1804bool amdgpu_device_is_px(struct drm_device *dev);
1805
1806#if defined(CONFIG_VGA_SWITCHEROO)
1807void amdgpu_register_atpx_handler(void);
1808void amdgpu_unregister_atpx_handler(void);
1809bool amdgpu_has_atpx_dgpu_power_cntl(void);
1810bool amdgpu_is_atpx_hybrid(void);
1811bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1812bool amdgpu_has_atpx(void);
1813#else
1814static inline void amdgpu_register_atpx_handler(void) {}
1815static inline void amdgpu_unregister_atpx_handler(void) {}
1816static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
1817static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
1818static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
1819static inline bool amdgpu_has_atpx(void) { return false; }
1820#endif
1821
1822#if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
1823void *amdgpu_atpx_get_dhandle(void);
1824#else
1825static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
1826#endif
1827
1828
1829
1830
1831extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1832extern const int amdgpu_max_kms_ioctl;
1833
1834int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
1835void amdgpu_driver_unload_kms(struct drm_device *dev);
1836void amdgpu_driver_lastclose_kms(struct drm_device *dev);
1837int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
1838void amdgpu_driver_postclose_kms(struct drm_device *dev,
1839 struct drm_file *file_priv);
1840int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
1841int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1842int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
1843u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
1844int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1845void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1846long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
1847 unsigned long arg);
1848
1849
1850
1851
1852struct amdgpu_afmt_acr {
1853 u32 clock;
1854
1855 int n_32khz;
1856 int cts_32khz;
1857
1858 int n_44_1khz;
1859 int cts_44_1khz;
1860
1861 int n_48khz;
1862 int cts_48khz;
1863
1864};
1865
1866struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
1867
1868
1869#if defined(CONFIG_ACPI)
1870int amdgpu_acpi_init(struct amdgpu_device *adev);
1871void amdgpu_acpi_fini(struct amdgpu_device *adev);
1872bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
1873int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
1874 u8 perf_req, bool advertise);
1875int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
1876#else
1877static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
1878static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
1879#endif
1880
1881int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
1882 uint64_t addr, struct amdgpu_bo **bo,
1883 struct amdgpu_bo_va_mapping **mapping);
1884
1885#if defined(CONFIG_DRM_AMD_DC)
1886int amdgpu_dm_display_resume(struct amdgpu_device *adev );
1887#else
1888static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
1889#endif
1890
1891#include "amdgpu_object.h"
1892#endif
1893