]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu.h
Merge branch 'vmwgfx-next' of git://people.freedesktop.org/~thomash/linux into drm...
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu.h
1 /*
2  * Copyright 2008 Advanced Micro Devices, Inc.
3  * Copyright 2008 Red Hat Inc.
4  * Copyright 2009 Jerome Glisse.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: Dave Airlie
25  *          Alex Deucher
26  *          Jerome Glisse
27  */
28 #ifndef __AMDGPU_H__
29 #define __AMDGPU_H__
30
31 #include "amdgpu_ctx.h"
32
33 #include <linux/atomic.h>
34 #include <linux/wait.h>
35 #include <linux/list.h>
36 #include <linux/kref.h>
37 #include <linux/rbtree.h>
38 #include <linux/hashtable.h>
39 #include <linux/dma-fence.h>
40
41 #include <drm/ttm/ttm_bo_api.h>
42 #include <drm/ttm/ttm_bo_driver.h>
43 #include <drm/ttm/ttm_placement.h>
44 #include <drm/ttm/ttm_module.h>
45 #include <drm/ttm/ttm_execbuf_util.h>
46
47 #include <drm/drmP.h>
48 #include <drm/drm_gem.h>
49 #include <drm/amdgpu_drm.h>
50 #include <drm/gpu_scheduler.h>
51
52 #include <kgd_kfd_interface.h>
53 #include "dm_pp_interface.h"
54 #include "kgd_pp_interface.h"
55
56 #include "amd_shared.h"
57 #include "amdgpu_mode.h"
58 #include "amdgpu_ih.h"
59 #include "amdgpu_irq.h"
60 #include "amdgpu_ucode.h"
61 #include "amdgpu_ttm.h"
62 #include "amdgpu_psp.h"
63 #include "amdgpu_gds.h"
64 #include "amdgpu_sync.h"
65 #include "amdgpu_ring.h"
66 #include "amdgpu_vm.h"
67 #include "amdgpu_dpm.h"
68 #include "amdgpu_acp.h"
69 #include "amdgpu_uvd.h"
70 #include "amdgpu_vce.h"
71 #include "amdgpu_vcn.h"
72 #include "amdgpu_mn.h"
73 #include "amdgpu_gmc.h"
74 #include "amdgpu_gfx.h"
75 #include "amdgpu_sdma.h"
76 #include "amdgpu_dm.h"
77 #include "amdgpu_virt.h"
78 #include "amdgpu_gart.h"
79 #include "amdgpu_debugfs.h"
80 #include "amdgpu_job.h"
81 #include "amdgpu_bo_list.h"
82 #include "amdgpu_gem.h"
83
84 /*
85  * Modules parameters.
86  */
87 extern int amdgpu_modeset;
88 extern int amdgpu_vram_limit;
89 extern int amdgpu_vis_vram_limit;
90 extern int amdgpu_gart_size;
91 extern int amdgpu_gtt_size;
92 extern int amdgpu_moverate;
93 extern int amdgpu_benchmarking;
94 extern int amdgpu_testing;
95 extern int amdgpu_audio;
96 extern int amdgpu_disp_priority;
97 extern int amdgpu_hw_i2c;
98 extern int amdgpu_pcie_gen2;
99 extern int amdgpu_msi;
100 extern int amdgpu_lockup_timeout;
101 extern int amdgpu_dpm;
102 extern int amdgpu_fw_load_type;
103 extern int amdgpu_aspm;
104 extern int amdgpu_runtime_pm;
105 extern uint amdgpu_ip_block_mask;
106 extern int amdgpu_bapm;
107 extern int amdgpu_deep_color;
108 extern int amdgpu_vm_size;
109 extern int amdgpu_vm_block_size;
110 extern int amdgpu_vm_fragment_size;
111 extern int amdgpu_vm_fault_stop;
112 extern int amdgpu_vm_debug;
113 extern int amdgpu_vm_update_mode;
114 extern int amdgpu_dc;
115 extern int amdgpu_sched_jobs;
116 extern int amdgpu_sched_hw_submission;
117 extern uint amdgpu_pcie_gen_cap;
118 extern uint amdgpu_pcie_lane_cap;
119 extern uint amdgpu_cg_mask;
120 extern uint amdgpu_pg_mask;
121 extern uint amdgpu_sdma_phase_quantum;
122 extern char *amdgpu_disable_cu;
123 extern char *amdgpu_virtual_display;
124 extern uint amdgpu_pp_feature_mask;
125 extern int amdgpu_vram_page_split;
126 extern int amdgpu_ngg;
127 extern int amdgpu_prim_buf_per_se;
128 extern int amdgpu_pos_buf_per_se;
129 extern int amdgpu_cntl_sb_buf_per_se;
130 extern int amdgpu_param_buf_per_se;
131 extern int amdgpu_job_hang_limit;
132 extern int amdgpu_lbpw;
133 extern int amdgpu_compute_multipipe;
134 extern int amdgpu_gpu_recovery;
135 extern int amdgpu_emu_mode;
136 extern uint amdgpu_smu_memory_pool_size;
137
138 #ifdef CONFIG_DRM_AMDGPU_SI
139 extern int amdgpu_si_support;
140 #endif
141 #ifdef CONFIG_DRM_AMDGPU_CIK
142 extern int amdgpu_cik_support;
143 #endif
144
145 #define AMDGPU_SG_THRESHOLD                     (256*1024*1024)
146 #define AMDGPU_DEFAULT_GTT_SIZE_MB              3072ULL /* 3GB by default */
147 #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS          3000
148 #define AMDGPU_MAX_USEC_TIMEOUT                 100000  /* 100 ms */
149 #define AMDGPU_FENCE_JIFFIES_TIMEOUT            (HZ / 2)
150 /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
151 #define AMDGPU_IB_POOL_SIZE                     16
152 #define AMDGPU_DEBUGFS_MAX_COMPONENTS           32
153 #define AMDGPUFB_CONN_LIMIT                     4
154 #define AMDGPU_BIOS_NUM_SCRATCH                 16
155
156 /* hard reset data */
157 #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
158
159 /* reset flags */
160 #define AMDGPU_RESET_GFX                        (1 << 0)
161 #define AMDGPU_RESET_COMPUTE                    (1 << 1)
162 #define AMDGPU_RESET_DMA                        (1 << 2)
163 #define AMDGPU_RESET_CP                         (1 << 3)
164 #define AMDGPU_RESET_GRBM                       (1 << 4)
165 #define AMDGPU_RESET_DMA1                       (1 << 5)
166 #define AMDGPU_RESET_RLC                        (1 << 6)
167 #define AMDGPU_RESET_SEM                        (1 << 7)
168 #define AMDGPU_RESET_IH                         (1 << 8)
169 #define AMDGPU_RESET_VMC                        (1 << 9)
170 #define AMDGPU_RESET_MC                         (1 << 10)
171 #define AMDGPU_RESET_DISPLAY                    (1 << 11)
172 #define AMDGPU_RESET_UVD                        (1 << 12)
173 #define AMDGPU_RESET_VCE                        (1 << 13)
174 #define AMDGPU_RESET_VCE1                       (1 << 14)
175
176 /* max cursor sizes (in pixels) */
177 #define CIK_CURSOR_WIDTH 128
178 #define CIK_CURSOR_HEIGHT 128
179
180 struct amdgpu_device;
181 struct amdgpu_ib;
182 struct amdgpu_cs_parser;
183 struct amdgpu_job;
184 struct amdgpu_irq_src;
185 struct amdgpu_fpriv;
186 struct amdgpu_bo_va_mapping;
187 struct amdgpu_atif;
188
189 enum amdgpu_cp_irq {
190         AMDGPU_CP_IRQ_GFX_EOP = 0,
191         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
192         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
193         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
194         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
195         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
196         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
197         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
198         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
199
200         AMDGPU_CP_IRQ_LAST
201 };
202
203 enum amdgpu_thermal_irq {
204         AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
205         AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
206
207         AMDGPU_THERMAL_IRQ_LAST
208 };
209
210 enum amdgpu_kiq_irq {
211         AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
212         AMDGPU_CP_KIQ_IRQ_LAST
213 };
214
215 #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
216 #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
217 #define MAX_KIQ_REG_TRY 20
218
219 int amdgpu_device_ip_set_clockgating_state(void *dev,
220                                            enum amd_ip_block_type block_type,
221                                            enum amd_clockgating_state state);
222 int amdgpu_device_ip_set_powergating_state(void *dev,
223                                            enum amd_ip_block_type block_type,
224                                            enum amd_powergating_state state);
225 void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
226                                             u32 *flags);
227 int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
228                                    enum amd_ip_block_type block_type);
229 bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
230                               enum amd_ip_block_type block_type);
231
232 #define AMDGPU_MAX_IP_NUM 16
233
234 struct amdgpu_ip_block_status {
235         bool valid;
236         bool sw;
237         bool hw;
238         bool late_initialized;
239         bool hang;
240 };
241
242 struct amdgpu_ip_block_version {
243         const enum amd_ip_block_type type;
244         const u32 major;
245         const u32 minor;
246         const u32 rev;
247         const struct amd_ip_funcs *funcs;
248 };
249
250 struct amdgpu_ip_block {
251         struct amdgpu_ip_block_status status;
252         const struct amdgpu_ip_block_version *version;
253 };
254
255 int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
256                                        enum amd_ip_block_type type,
257                                        u32 major, u32 minor);
258
259 struct amdgpu_ip_block *
260 amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
261                               enum amd_ip_block_type type);
262
263 int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
264                                const struct amdgpu_ip_block_version *ip_block_version);
265
266 /*
267  * BIOS.
268  */
269 bool amdgpu_get_bios(struct amdgpu_device *adev);
270 bool amdgpu_read_bios(struct amdgpu_device *adev);
271
272 /*
273  * Clocks
274  */
275
276 #define AMDGPU_MAX_PPLL 3
277
278 struct amdgpu_clock {
279         struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
280         struct amdgpu_pll spll;
281         struct amdgpu_pll mpll;
282         /* 10 Khz units */
283         uint32_t default_mclk;
284         uint32_t default_sclk;
285         uint32_t default_dispclk;
286         uint32_t current_dispclk;
287         uint32_t dp_extclk;
288         uint32_t max_pixel_clock;
289 };
290
291 /* sub-allocation manager, it has to be protected by another lock.
292  * By conception this is an helper for other part of the driver
293  * like the indirect buffer or semaphore, which both have their
294  * locking.
295  *
296  * Principe is simple, we keep a list of sub allocation in offset
297  * order (first entry has offset == 0, last entry has the highest
298  * offset).
299  *
300  * When allocating new object we first check if there is room at
301  * the end total_size - (last_object_offset + last_object_size) >=
302  * alloc_size. If so we allocate new object there.
303  *
304  * When there is not enough room at the end, we start waiting for
305  * each sub object until we reach object_offset+object_size >=
306  * alloc_size, this object then become the sub object we return.
307  *
308  * Alignment can't be bigger than page size.
309  *
310  * Hole are not considered for allocation to keep things simple.
311  * Assumption is that there won't be hole (all object on same
312  * alignment).
313  */
314
315 #define AMDGPU_SA_NUM_FENCE_LISTS       32
316
317 struct amdgpu_sa_manager {
318         wait_queue_head_t       wq;
319         struct amdgpu_bo        *bo;
320         struct list_head        *hole;
321         struct list_head        flist[AMDGPU_SA_NUM_FENCE_LISTS];
322         struct list_head        olist;
323         unsigned                size;
324         uint64_t                gpu_addr;
325         void                    *cpu_ptr;
326         uint32_t                domain;
327         uint32_t                align;
328 };
329
330 /* sub-allocation buffer */
331 struct amdgpu_sa_bo {
332         struct list_head                olist;
333         struct list_head                flist;
334         struct amdgpu_sa_manager        *manager;
335         unsigned                        soffset;
336         unsigned                        eoffset;
337         struct dma_fence                *fence;
338 };
339
340 int amdgpu_fence_slab_init(void);
341 void amdgpu_fence_slab_fini(void);
342
343 /*
344  * GPU doorbell structures, functions & helpers
345  */
346 typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
347 {
348         AMDGPU_DOORBELL_KIQ                     = 0x000,
349         AMDGPU_DOORBELL_HIQ                     = 0x001,
350         AMDGPU_DOORBELL_DIQ                     = 0x002,
351         AMDGPU_DOORBELL_MEC_RING0               = 0x010,
352         AMDGPU_DOORBELL_MEC_RING1               = 0x011,
353         AMDGPU_DOORBELL_MEC_RING2               = 0x012,
354         AMDGPU_DOORBELL_MEC_RING3               = 0x013,
355         AMDGPU_DOORBELL_MEC_RING4               = 0x014,
356         AMDGPU_DOORBELL_MEC_RING5               = 0x015,
357         AMDGPU_DOORBELL_MEC_RING6               = 0x016,
358         AMDGPU_DOORBELL_MEC_RING7               = 0x017,
359         AMDGPU_DOORBELL_GFX_RING0               = 0x020,
360         AMDGPU_DOORBELL_sDMA_ENGINE0            = 0x1E0,
361         AMDGPU_DOORBELL_sDMA_ENGINE1            = 0x1E1,
362         AMDGPU_DOORBELL_IH                      = 0x1E8,
363         AMDGPU_DOORBELL_MAX_ASSIGNMENT          = 0x3FF,
364         AMDGPU_DOORBELL_INVALID                 = 0xFFFF
365 } AMDGPU_DOORBELL_ASSIGNMENT;
366
367 struct amdgpu_doorbell {
368         /* doorbell mmio */
369         resource_size_t         base;
370         resource_size_t         size;
371         u32 __iomem             *ptr;
372         u32                     num_doorbells;  /* Number of doorbells actually reserved for amdgpu. */
373 };
374
375 /*
376  * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
377  */
378 typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
379 {
380         /*
381          * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
382          * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
383          *  Compute related doorbells are allocated from 0x00 to 0x8a
384          */
385
386
387         /* kernel scheduling */
388         AMDGPU_DOORBELL64_KIQ                     = 0x00,
389
390         /* HSA interface queue and debug queue */
391         AMDGPU_DOORBELL64_HIQ                     = 0x01,
392         AMDGPU_DOORBELL64_DIQ                     = 0x02,
393
394         /* Compute engines */
395         AMDGPU_DOORBELL64_MEC_RING0               = 0x03,
396         AMDGPU_DOORBELL64_MEC_RING1               = 0x04,
397         AMDGPU_DOORBELL64_MEC_RING2               = 0x05,
398         AMDGPU_DOORBELL64_MEC_RING3               = 0x06,
399         AMDGPU_DOORBELL64_MEC_RING4               = 0x07,
400         AMDGPU_DOORBELL64_MEC_RING5               = 0x08,
401         AMDGPU_DOORBELL64_MEC_RING6               = 0x09,
402         AMDGPU_DOORBELL64_MEC_RING7               = 0x0a,
403
404         /* User queue doorbell range (128 doorbells) */
405         AMDGPU_DOORBELL64_USERQUEUE_START         = 0x0b,
406         AMDGPU_DOORBELL64_USERQUEUE_END           = 0x8a,
407
408         /* Graphics engine */
409         AMDGPU_DOORBELL64_GFX_RING0               = 0x8b,
410
411         /*
412          * Other graphics doorbells can be allocated here: from 0x8c to 0xdf
413          * Graphics voltage island aperture 1
414          * default non-graphics QWORD index is 0xe0 - 0xFF inclusive
415          */
416
417         /* sDMA engines  reserved from 0xe0 -oxef  */
418         AMDGPU_DOORBELL64_sDMA_ENGINE0            = 0xE0,
419         AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0     = 0xE1,
420         AMDGPU_DOORBELL64_sDMA_ENGINE1            = 0xE8,
421         AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1     = 0xE9,
422
423         /* For vega10 sriov, the sdma doorbell must be fixed as follow
424          * to keep the same setting with host driver, or it will
425          * happen conflicts
426          */
427         AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0            = 0xF0,
428         AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE0     = 0xF1,
429         AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1            = 0xF2,
430         AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE1     = 0xF3,
431
432         /* Interrupt handler */
433         AMDGPU_DOORBELL64_IH                      = 0xF4,  /* For legacy interrupt ring buffer */
434         AMDGPU_DOORBELL64_IH_RING1                = 0xF5,  /* For page migration request log */
435         AMDGPU_DOORBELL64_IH_RING2                = 0xF6,  /* For page migration translation/invalidation log */
436
437         /* VCN engine use 32 bits doorbell  */
438         AMDGPU_DOORBELL64_VCN0_1                  = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
439         AMDGPU_DOORBELL64_VCN2_3                  = 0xF9,
440         AMDGPU_DOORBELL64_VCN4_5                  = 0xFA,
441         AMDGPU_DOORBELL64_VCN6_7                  = 0xFB,
442
443         /* overlap the doorbell assignment with VCN as they are  mutually exclusive
444          * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
445          */
446         AMDGPU_DOORBELL64_UVD_RING0_1             = 0xF8,
447         AMDGPU_DOORBELL64_UVD_RING2_3             = 0xF9,
448         AMDGPU_DOORBELL64_UVD_RING4_5             = 0xFA,
449         AMDGPU_DOORBELL64_UVD_RING6_7             = 0xFB,
450
451         AMDGPU_DOORBELL64_VCE_RING0_1             = 0xFC,
452         AMDGPU_DOORBELL64_VCE_RING2_3             = 0xFD,
453         AMDGPU_DOORBELL64_VCE_RING4_5             = 0xFE,
454         AMDGPU_DOORBELL64_VCE_RING6_7             = 0xFF,
455
456         AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
457         AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
458 } AMDGPU_DOORBELL64_ASSIGNMENT;
459
460 /*
461  * IRQS.
462  */
463
464 struct amdgpu_flip_work {
465         struct delayed_work             flip_work;
466         struct work_struct              unpin_work;
467         struct amdgpu_device            *adev;
468         int                             crtc_id;
469         u32                             target_vblank;
470         uint64_t                        base;
471         struct drm_pending_vblank_event *event;
472         struct amdgpu_bo                *old_abo;
473         struct dma_fence                *excl;
474         unsigned                        shared_count;
475         struct dma_fence                **shared;
476         struct dma_fence_cb             cb;
477         bool                            async;
478 };
479
480
481 /*
482  * CP & rings.
483  */
484
485 struct amdgpu_ib {
486         struct amdgpu_sa_bo             *sa_bo;
487         uint32_t                        length_dw;
488         uint64_t                        gpu_addr;
489         uint32_t                        *ptr;
490         uint32_t                        flags;
491 };
492
493 extern const struct drm_sched_backend_ops amdgpu_sched_ops;
494
495 /*
496  * file private structure
497  */
498
499 struct amdgpu_fpriv {
500         struct amdgpu_vm        vm;
501         struct amdgpu_bo_va     *prt_va;
502         struct amdgpu_bo_va     *csa_va;
503         struct mutex            bo_list_lock;
504         struct idr              bo_list_handles;
505         struct amdgpu_ctx_mgr   ctx_mgr;
506 };
507
508 int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
509                   unsigned size, struct amdgpu_ib *ib);
510 void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
511                     struct dma_fence *f);
512 int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
513                        struct amdgpu_ib *ibs, struct amdgpu_job *job,
514                        struct dma_fence **f);
515 int amdgpu_ib_pool_init(struct amdgpu_device *adev);
516 void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
517 int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
518
519 /*
520  * CS.
521  */
522 struct amdgpu_cs_chunk {
523         uint32_t                chunk_id;
524         uint32_t                length_dw;
525         void                    *kdata;
526 };
527
528 struct amdgpu_cs_parser {
529         struct amdgpu_device    *adev;
530         struct drm_file         *filp;
531         struct amdgpu_ctx       *ctx;
532
533         /* chunks */
534         unsigned                nchunks;
535         struct amdgpu_cs_chunk  *chunks;
536
537         /* scheduler job object */
538         struct amdgpu_job       *job;
539         struct drm_sched_entity *entity;
540
541         /* buffer objects */
542         struct ww_acquire_ctx           ticket;
543         struct amdgpu_bo_list           *bo_list;
544         struct amdgpu_mn                *mn;
545         struct amdgpu_bo_list_entry     vm_pd;
546         struct list_head                validated;
547         struct dma_fence                *fence;
548         uint64_t                        bytes_moved_threshold;
549         uint64_t                        bytes_moved_vis_threshold;
550         uint64_t                        bytes_moved;
551         uint64_t                        bytes_moved_vis;
552         struct amdgpu_bo_list_entry     *evictable;
553
554         /* user fence */
555         struct amdgpu_bo_list_entry     uf_entry;
556
557         unsigned num_post_dep_syncobjs;
558         struct drm_syncobj **post_dep_syncobjs;
559 };
560
561 static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
562                                       uint32_t ib_idx, int idx)
563 {
564         return p->job->ibs[ib_idx].ptr[idx];
565 }
566
567 static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
568                                        uint32_t ib_idx, int idx,
569                                        uint32_t value)
570 {
571         p->job->ibs[ib_idx].ptr[idx] = value;
572 }
573
574 /*
575  * Writeback
576  */
577 #define AMDGPU_MAX_WB 128       /* Reserve at most 128 WB slots for amdgpu-owned rings. */
578
579 struct amdgpu_wb {
580         struct amdgpu_bo        *wb_obj;
581         volatile uint32_t       *wb;
582         uint64_t                gpu_addr;
583         u32                     num_wb; /* Number of wb slots actually reserved for amdgpu. */
584         unsigned long           used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
585 };
586
587 int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
588 void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
589
590 /*
591  * Benchmarking
592  */
593 void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
594
595
596 /*
597  * Testing
598  */
599 void amdgpu_test_moves(struct amdgpu_device *adev);
600
601
602 /*
603  * amdgpu smumgr functions
604  */
605 struct amdgpu_smumgr_funcs {
606         int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
607         int (*request_smu_load_fw)(struct amdgpu_device *adev);
608         int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
609 };
610
611 /*
612  * amdgpu smumgr
613  */
614 struct amdgpu_smumgr {
615         struct amdgpu_bo *toc_buf;
616         struct amdgpu_bo *smu_buf;
617         /* asic priv smu data */
618         void *priv;
619         spinlock_t smu_lock;
620         /* smumgr functions */
621         const struct amdgpu_smumgr_funcs *smumgr_funcs;
622         /* ucode loading complete flag */
623         uint32_t fw_flags;
624 };
625
626 /*
627  * ASIC specific register table accessible by UMD
628  */
629 struct amdgpu_allowed_register_entry {
630         uint32_t reg_offset;
631         bool grbm_indexed;
632 };
633
634 /*
635  * ASIC specific functions.
636  */
637 struct amdgpu_asic_funcs {
638         bool (*read_disabled_bios)(struct amdgpu_device *adev);
639         bool (*read_bios_from_rom)(struct amdgpu_device *adev,
640                                    u8 *bios, u32 length_bytes);
641         int (*read_register)(struct amdgpu_device *adev, u32 se_num,
642                              u32 sh_num, u32 reg_offset, u32 *value);
643         void (*set_vga_state)(struct amdgpu_device *adev, bool state);
644         int (*reset)(struct amdgpu_device *adev);
645         /* get the reference clock */
646         u32 (*get_xclk)(struct amdgpu_device *adev);
647         /* MM block clocks */
648         int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
649         int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
650         /* static power management */
651         int (*get_pcie_lanes)(struct amdgpu_device *adev);
652         void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
653         /* get config memsize register */
654         u32 (*get_config_memsize)(struct amdgpu_device *adev);
655         /* flush hdp write queue */
656         void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
657         /* invalidate hdp read cache */
658         void (*invalidate_hdp)(struct amdgpu_device *adev,
659                                struct amdgpu_ring *ring);
660         /* check if the asic needs a full reset of if soft reset will work */
661         bool (*need_full_reset)(struct amdgpu_device *adev);
662 };
663
664 /*
665  * IOCTL.
666  */
667 int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
668                                 struct drm_file *filp);
669
670 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
671 int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
672                                     struct drm_file *filp);
673 int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
674 int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
675                                 struct drm_file *filp);
676
677 /* VRAM scratch page for HDP bug, default vram page */
678 struct amdgpu_vram_scratch {
679         struct amdgpu_bo                *robj;
680         volatile uint32_t               *ptr;
681         u64                             gpu_addr;
682 };
683
684 /*
685  * ACPI
686  */
687 struct amdgpu_atcs_functions {
688         bool get_ext_state;
689         bool pcie_perf_req;
690         bool pcie_dev_rdy;
691         bool pcie_bus_width;
692 };
693
694 struct amdgpu_atcs {
695         struct amdgpu_atcs_functions functions;
696 };
697
698 /*
699  * Firmware VRAM reservation
700  */
701 struct amdgpu_fw_vram_usage {
702         u64 start_offset;
703         u64 size;
704         struct amdgpu_bo *reserved_bo;
705         void *va;
706 };
707
708 /*
709  * CGS
710  */
711 struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
712 void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
713
714 /*
715  * Core structure, functions and helpers.
716  */
717 typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
718 typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
719
720 typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
721 typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
722
723
724 /*
725  * amdgpu nbio functions
726  *
727  */
728 struct nbio_hdp_flush_reg {
729         u32 ref_and_mask_cp0;
730         u32 ref_and_mask_cp1;
731         u32 ref_and_mask_cp2;
732         u32 ref_and_mask_cp3;
733         u32 ref_and_mask_cp4;
734         u32 ref_and_mask_cp5;
735         u32 ref_and_mask_cp6;
736         u32 ref_and_mask_cp7;
737         u32 ref_and_mask_cp8;
738         u32 ref_and_mask_cp9;
739         u32 ref_and_mask_sdma0;
740         u32 ref_and_mask_sdma1;
741 };
742
743 struct amdgpu_nbio_funcs {
744         const struct nbio_hdp_flush_reg *hdp_flush_reg;
745         u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
746         u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
747         u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
748         u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
749         u32 (*get_rev_id)(struct amdgpu_device *adev);
750         void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
751         void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
752         u32 (*get_memsize)(struct amdgpu_device *adev);
753         void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
754                                     bool use_doorbell, int doorbell_index);
755         void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
756                                          bool enable);
757         void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
758                                                   bool enable);
759         void (*ih_doorbell_range)(struct amdgpu_device *adev,
760                                   bool use_doorbell, int doorbell_index);
761         void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
762                                                  bool enable);
763         void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
764                                                 bool enable);
765         void (*get_clockgating_state)(struct amdgpu_device *adev,
766                                       u32 *flags);
767         void (*ih_control)(struct amdgpu_device *adev);
768         void (*init_registers)(struct amdgpu_device *adev);
769         void (*detect_hw_virt)(struct amdgpu_device *adev);
770 };
771
772 struct amdgpu_df_funcs {
773         void (*init)(struct amdgpu_device *adev);
774         void (*enable_broadcast_mode)(struct amdgpu_device *adev,
775                                       bool enable);
776         u32 (*get_fb_channel_number)(struct amdgpu_device *adev);
777         u32 (*get_hbm_channel_number)(struct amdgpu_device *adev);
778         void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
779                                                  bool enable);
780         void (*get_clockgating_state)(struct amdgpu_device *adev,
781                                       u32 *flags);
782         void (*enable_ecc_force_par_wr_rmw)(struct amdgpu_device *adev,
783                                             bool enable);
784 };
785 /* Define the HW IP blocks will be used in driver , add more if necessary */
786 enum amd_hw_ip_block_type {
787         GC_HWIP = 1,
788         HDP_HWIP,
789         SDMA0_HWIP,
790         SDMA1_HWIP,
791         MMHUB_HWIP,
792         ATHUB_HWIP,
793         NBIO_HWIP,
794         MP0_HWIP,
795         MP1_HWIP,
796         UVD_HWIP,
797         VCN_HWIP = UVD_HWIP,
798         VCE_HWIP,
799         DF_HWIP,
800         DCE_HWIP,
801         OSSSYS_HWIP,
802         SMUIO_HWIP,
803         PWR_HWIP,
804         NBIF_HWIP,
805         THM_HWIP,
806         CLK_HWIP,
807         MAX_HWIP
808 };
809
810 #define HWIP_MAX_INSTANCE       6
811
812 struct amd_powerplay {
813         void *pp_handle;
814         const struct amd_pm_funcs *pp_funcs;
815         uint32_t pp_feature;
816 };
817
818 #define AMDGPU_RESET_MAGIC_NUM 64
819 struct amdgpu_device {
820         struct device                   *dev;
821         struct drm_device               *ddev;
822         struct pci_dev                  *pdev;
823
824 #ifdef CONFIG_DRM_AMD_ACP
825         struct amdgpu_acp               acp;
826 #endif
827
828         /* ASIC */
829         enum amd_asic_type              asic_type;
830         uint32_t                        family;
831         uint32_t                        rev_id;
832         uint32_t                        external_rev_id;
833         unsigned long                   flags;
834         int                             usec_timeout;
835         const struct amdgpu_asic_funcs  *asic_funcs;
836         bool                            shutdown;
837         bool                            need_dma32;
838         bool                            need_swiotlb;
839         bool                            accel_working;
840         struct work_struct              reset_work;
841         struct notifier_block           acpi_nb;
842         struct amdgpu_i2c_chan          *i2c_bus[AMDGPU_MAX_I2C_BUS];
843         struct amdgpu_debugfs           debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
844         unsigned                        debugfs_count;
845 #if defined(CONFIG_DEBUG_FS)
846         struct dentry                   *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
847 #endif
848         struct amdgpu_atif              *atif;
849         struct amdgpu_atcs              atcs;
850         struct mutex                    srbm_mutex;
851         /* GRBM index mutex. Protects concurrent access to GRBM index */
852         struct mutex                    grbm_idx_mutex;
853         struct dev_pm_domain            vga_pm_domain;
854         bool                            have_disp_power_ref;
855
856         /* BIOS */
857         bool                            is_atom_fw;
858         uint8_t                         *bios;
859         uint32_t                        bios_size;
860         struct amdgpu_bo                *stolen_vga_memory;
861         uint32_t                        bios_scratch_reg_offset;
862         uint32_t                        bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
863
864         /* Register/doorbell mmio */
865         resource_size_t                 rmmio_base;
866         resource_size_t                 rmmio_size;
867         void __iomem                    *rmmio;
868         /* protects concurrent MM_INDEX/DATA based register access */
869         spinlock_t mmio_idx_lock;
870         /* protects concurrent SMC based register access */
871         spinlock_t smc_idx_lock;
872         amdgpu_rreg_t                   smc_rreg;
873         amdgpu_wreg_t                   smc_wreg;
874         /* protects concurrent PCIE register access */
875         spinlock_t pcie_idx_lock;
876         amdgpu_rreg_t                   pcie_rreg;
877         amdgpu_wreg_t                   pcie_wreg;
878         amdgpu_rreg_t                   pciep_rreg;
879         amdgpu_wreg_t                   pciep_wreg;
880         /* protects concurrent UVD register access */
881         spinlock_t uvd_ctx_idx_lock;
882         amdgpu_rreg_t                   uvd_ctx_rreg;
883         amdgpu_wreg_t                   uvd_ctx_wreg;
884         /* protects concurrent DIDT register access */
885         spinlock_t didt_idx_lock;
886         amdgpu_rreg_t                   didt_rreg;
887         amdgpu_wreg_t                   didt_wreg;
888         /* protects concurrent gc_cac register access */
889         spinlock_t gc_cac_idx_lock;
890         amdgpu_rreg_t                   gc_cac_rreg;
891         amdgpu_wreg_t                   gc_cac_wreg;
892         /* protects concurrent se_cac register access */
893         spinlock_t se_cac_idx_lock;
894         amdgpu_rreg_t                   se_cac_rreg;
895         amdgpu_wreg_t                   se_cac_wreg;
896         /* protects concurrent ENDPOINT (audio) register access */
897         spinlock_t audio_endpt_idx_lock;
898         amdgpu_block_rreg_t             audio_endpt_rreg;
899         amdgpu_block_wreg_t             audio_endpt_wreg;
900         void __iomem                    *rio_mem;
901         resource_size_t                 rio_mem_size;
902         struct amdgpu_doorbell          doorbell;
903
904         /* clock/pll info */
905         struct amdgpu_clock            clock;
906
907         /* MC */
908         struct amdgpu_gmc               gmc;
909         struct amdgpu_gart              gart;
910         dma_addr_t                      dummy_page_addr;
911         struct amdgpu_vm_manager        vm_manager;
912         struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
913
914         /* memory management */
915         struct amdgpu_mman              mman;
916         struct amdgpu_vram_scratch      vram_scratch;
917         struct amdgpu_wb                wb;
918         atomic64_t                      num_bytes_moved;
919         atomic64_t                      num_evictions;
920         atomic64_t                      num_vram_cpu_page_faults;
921         atomic_t                        gpu_reset_counter;
922         atomic_t                        vram_lost_counter;
923
924         /* data for buffer migration throttling */
925         struct {
926                 spinlock_t              lock;
927                 s64                     last_update_us;
928                 s64                     accum_us; /* accumulated microseconds */
929                 s64                     accum_us_vis; /* for visible VRAM */
930                 u32                     log2_max_MBps;
931         } mm_stats;
932
933         /* display */
934         bool                            enable_virtual_display;
935         struct amdgpu_mode_info         mode_info;
936         /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
937         struct work_struct              hotplug_work;
938         struct amdgpu_irq_src           crtc_irq;
939         struct amdgpu_irq_src           pageflip_irq;
940         struct amdgpu_irq_src           hpd_irq;
941
942         /* rings */
943         u64                             fence_context;
944         unsigned                        num_rings;
945         struct amdgpu_ring              *rings[AMDGPU_MAX_RINGS];
946         bool                            ib_pool_ready;
947         struct amdgpu_sa_manager        ring_tmp_bo;
948
949         /* interrupts */
950         struct amdgpu_irq               irq;
951
952         /* powerplay */
953         struct amd_powerplay            powerplay;
954         bool                            pp_force_state_enabled;
955
956         /* dpm */
957         struct amdgpu_pm                pm;
958         u32                             cg_flags;
959         u32                             pg_flags;
960
961         /* amdgpu smumgr */
962         struct amdgpu_smumgr smu;
963
964         /* gfx */
965         struct amdgpu_gfx               gfx;
966
967         /* sdma */
968         struct amdgpu_sdma              sdma;
969
970         /* uvd */
971         struct amdgpu_uvd               uvd;
972
973         /* vce */
974         struct amdgpu_vce               vce;
975
976         /* vcn */
977         struct amdgpu_vcn               vcn;
978
979         /* firmwares */
980         struct amdgpu_firmware          firmware;
981
982         /* PSP */
983         struct psp_context              psp;
984
985         /* GDS */
986         struct amdgpu_gds               gds;
987
988         /* display related functionality */
989         struct amdgpu_display_manager dm;
990
991         struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
992         int                             num_ip_blocks;
993         struct mutex    mn_lock;
994         DECLARE_HASHTABLE(mn_hash, 7);
995
996         /* tracking pinned memory */
997         atomic64_t vram_pin_size;
998         atomic64_t visible_pin_size;
999         atomic64_t gart_pin_size;
1000
1001         /* amdkfd interface */
1002         struct kfd_dev          *kfd;
1003
1004         /* soc15 register offset based on ip, instance and  segment */
1005         uint32_t                *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
1006
1007         const struct amdgpu_nbio_funcs  *nbio_funcs;
1008         const struct amdgpu_df_funcs    *df_funcs;
1009
1010         /* delayed work_func for deferring clockgating during resume */
1011         struct delayed_work     late_init_work;
1012
1013         struct amdgpu_virt      virt;
1014         /* firmware VRAM reservation */
1015         struct amdgpu_fw_vram_usage fw_vram_usage;
1016
1017         /* link all shadow bo */
1018         struct list_head                shadow_list;
1019         struct mutex                    shadow_list_lock;
1020         /* keep an lru list of rings by HW IP */
1021         struct list_head                ring_lru_list;
1022         spinlock_t                      ring_lru_list_lock;
1023
1024         /* record hw reset is performed */
1025         bool has_hw_reset;
1026         u8                              reset_magic[AMDGPU_RESET_MAGIC_NUM];
1027
1028         /* record last mm index being written through WREG32*/
1029         unsigned long last_mm_index;
1030         bool                            in_gpu_reset;
1031         struct mutex  lock_reset;
1032 };
1033
1034 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1035 {
1036         return container_of(bdev, struct amdgpu_device, mman.bdev);
1037 }
1038
1039 int amdgpu_device_init(struct amdgpu_device *adev,
1040                        struct drm_device *ddev,
1041                        struct pci_dev *pdev,
1042                        uint32_t flags);
1043 void amdgpu_device_fini(struct amdgpu_device *adev);
1044 int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1045
1046 uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
1047                         uint32_t acc_flags);
1048 void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
1049                     uint32_t acc_flags);
1050 void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
1051 uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
1052
1053 u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1054 void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1055
1056 u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1057 void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1058 u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1059 void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
1060
1061 bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
1062 bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
1063
1064 int emu_soc_asic_init(struct amdgpu_device *adev);
1065
1066 /*
1067  * Registers read & write functions.
1068  */
1069
1070 #define AMDGPU_REGS_IDX       (1<<0)
1071 #define AMDGPU_REGS_NO_KIQ    (1<<1)
1072
1073 #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
1074 #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
1075
1076 #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
1077 #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
1078
1079 #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
1080 #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
1081 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
1082 #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
1083 #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
1084 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1085 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1086 #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1087 #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
1088 #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
1089 #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
1090 #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
1091 #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
1092 #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
1093 #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
1094 #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
1095 #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
1096 #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1097 #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
1098 #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
1099 #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
1100 #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
1101 #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
1102 #define WREG32_P(reg, val, mask)                                \
1103         do {                                                    \
1104                 uint32_t tmp_ = RREG32(reg);                    \
1105                 tmp_ &= (mask);                                 \
1106                 tmp_ |= ((val) & ~(mask));                      \
1107                 WREG32(reg, tmp_);                              \
1108         } while (0)
1109 #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1110 #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1111 #define WREG32_PLL_P(reg, val, mask)                            \
1112         do {                                                    \
1113                 uint32_t tmp_ = RREG32_PLL(reg);                \
1114                 tmp_ &= (mask);                                 \
1115                 tmp_ |= ((val) & ~(mask));                      \
1116                 WREG32_PLL(reg, tmp_);                          \
1117         } while (0)
1118 #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
1119 #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1120 #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1121
1122 #define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
1123 #define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1124 #define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1125 #define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
1126
1127 #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1128 #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1129
1130 #define REG_SET_FIELD(orig_val, reg, field, field_val)                  \
1131         (((orig_val) & ~REG_FIELD_MASK(reg, field)) |                   \
1132          (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1133
1134 #define REG_GET_FIELD(value, reg, field)                                \
1135         (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1136
1137 #define WREG32_FIELD(reg, field, val)   \
1138         WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1139
1140 #define WREG32_FIELD_OFFSET(reg, offset, field, val)    \
1141         WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1142
1143 /*
1144  * BIOS helpers.
1145  */
1146 #define RBIOS8(i) (adev->bios[i])
1147 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1148 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1149
1150 /*
1151  * ASICs macro.
1152  */
1153 #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1154 #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
1155 #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1156 #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1157 #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1158 #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1159 #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1160 #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
1161 #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
1162 #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
1163 #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1164 #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
1165 #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r))
1166 #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))
1167 #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev))
1168
1169 /* Common functions */
1170 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
1171 int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
1172                               struct amdgpu_job* job);
1173 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
1174 bool amdgpu_device_need_post(struct amdgpu_device *adev);
1175
1176 void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
1177                                   u64 num_vis_bytes);
1178 int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
1179 void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
1180                                              const u32 *registers,
1181                                              const u32 array_size);
1182
1183 bool amdgpu_device_is_px(struct drm_device *dev);
1184 /* atpx handler */
1185 #if defined(CONFIG_VGA_SWITCHEROO)
1186 void amdgpu_register_atpx_handler(void);
1187 void amdgpu_unregister_atpx_handler(void);
1188 bool amdgpu_has_atpx_dgpu_power_cntl(void);
1189 bool amdgpu_is_atpx_hybrid(void);
1190 bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1191 bool amdgpu_has_atpx(void);
1192 #else
1193 static inline void amdgpu_register_atpx_handler(void) {}
1194 static inline void amdgpu_unregister_atpx_handler(void) {}
1195 static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
1196 static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
1197 static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
1198 static inline bool amdgpu_has_atpx(void) { return false; }
1199 #endif
1200
1201 #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
1202 void *amdgpu_atpx_get_dhandle(void);
1203 #else
1204 static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
1205 #endif
1206
1207 /*
1208  * KMS
1209  */
1210 extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1211 extern const int amdgpu_max_kms_ioctl;
1212
1213 int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
1214 void amdgpu_driver_unload_kms(struct drm_device *dev);
1215 void amdgpu_driver_lastclose_kms(struct drm_device *dev);
1216 int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
1217 void amdgpu_driver_postclose_kms(struct drm_device *dev,
1218                                  struct drm_file *file_priv);
1219 int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
1220 int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1221 int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
1222 u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
1223 int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1224 void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1225 long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
1226                              unsigned long arg);
1227
1228
1229 /*
1230  * functions used by amdgpu_xgmi.c
1231  */
1232 int amdgpu_xgmi_add_device(struct amdgpu_device *adev);
1233
1234 /*
1235  * functions used by amdgpu_encoder.c
1236  */
1237 struct amdgpu_afmt_acr {
1238         u32 clock;
1239
1240         int n_32khz;
1241         int cts_32khz;
1242
1243         int n_44_1khz;
1244         int cts_44_1khz;
1245
1246         int n_48khz;
1247         int cts_48khz;
1248
1249 };
1250
1251 struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
1252
1253 /* amdgpu_acpi.c */
1254 #if defined(CONFIG_ACPI)
1255 int amdgpu_acpi_init(struct amdgpu_device *adev);
1256 void amdgpu_acpi_fini(struct amdgpu_device *adev);
1257 bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
1258 int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
1259                                                 u8 perf_req, bool advertise);
1260 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
1261 #else
1262 static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
1263 static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
1264 #endif
1265
1266 int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
1267                            uint64_t addr, struct amdgpu_bo **bo,
1268                            struct amdgpu_bo_va_mapping **mapping);
1269
1270 #if defined(CONFIG_DRM_AMD_DC)
1271 int amdgpu_dm_display_resume(struct amdgpu_device *adev );
1272 #else
1273 static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
1274 #endif
1275
1276 #include "amdgpu_object.h"
1277 #endif
This page took 0.124038 seconds and 4 git commands to generate.