drm/amdgpu: Add KFD VRAM limit checking
[linux-2.6-microblaze.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_csa.h"
79 #include "amdgpu_gart.h"
80 #include "amdgpu_debugfs.h"
81 #include "amdgpu_job.h"
82 #include "amdgpu_bo_list.h"
83 #include "amdgpu_gem.h"
84 #include "amdgpu_doorbell.h"
85 #include "amdgpu_amdkfd.h"
86
87 #define MAX_GPU_INSTANCE                16
88
89 struct amdgpu_gpu_instance
90 {
91         struct amdgpu_device            *adev;
92         int                             mgpu_fan_enabled;
93 };
94
95 struct amdgpu_mgpu_info
96 {
97         struct amdgpu_gpu_instance      gpu_ins[MAX_GPU_INSTANCE];
98         struct mutex                    mutex;
99         uint32_t                        num_gpu;
100         uint32_t                        num_dgpu;
101         uint32_t                        num_apu;
102 };
103
104 /*
105  * Modules parameters.
106  */
107 extern int amdgpu_modeset;
108 extern int amdgpu_vram_limit;
109 extern int amdgpu_vis_vram_limit;
110 extern int amdgpu_gart_size;
111 extern int amdgpu_gtt_size;
112 extern int amdgpu_moverate;
113 extern int amdgpu_benchmarking;
114 extern int amdgpu_testing;
115 extern int amdgpu_audio;
116 extern int amdgpu_disp_priority;
117 extern int amdgpu_hw_i2c;
118 extern int amdgpu_pcie_gen2;
119 extern int amdgpu_msi;
120 extern int amdgpu_lockup_timeout;
121 extern int amdgpu_dpm;
122 extern int amdgpu_fw_load_type;
123 extern int amdgpu_aspm;
124 extern int amdgpu_runtime_pm;
125 extern uint amdgpu_ip_block_mask;
126 extern int amdgpu_bapm;
127 extern int amdgpu_deep_color;
128 extern int amdgpu_vm_size;
129 extern int amdgpu_vm_block_size;
130 extern int amdgpu_vm_fragment_size;
131 extern int amdgpu_vm_fault_stop;
132 extern int amdgpu_vm_debug;
133 extern int amdgpu_vm_update_mode;
134 extern int amdgpu_dc;
135 extern int amdgpu_sched_jobs;
136 extern int amdgpu_sched_hw_submission;
137 extern uint amdgpu_pcie_gen_cap;
138 extern uint amdgpu_pcie_lane_cap;
139 extern uint amdgpu_cg_mask;
140 extern uint amdgpu_pg_mask;
141 extern uint amdgpu_sdma_phase_quantum;
142 extern char *amdgpu_disable_cu;
143 extern char *amdgpu_virtual_display;
144 extern uint amdgpu_pp_feature_mask;
145 extern int amdgpu_vram_page_split;
146 extern int amdgpu_ngg;
147 extern int amdgpu_prim_buf_per_se;
148 extern int amdgpu_pos_buf_per_se;
149 extern int amdgpu_cntl_sb_buf_per_se;
150 extern int amdgpu_param_buf_per_se;
151 extern int amdgpu_job_hang_limit;
152 extern int amdgpu_lbpw;
153 extern int amdgpu_compute_multipipe;
154 extern int amdgpu_gpu_recovery;
155 extern int amdgpu_emu_mode;
156 extern uint amdgpu_smu_memory_pool_size;
157 extern uint amdgpu_dc_feature_mask;
158 extern struct amdgpu_mgpu_info mgpu_info;
159
160 #ifdef CONFIG_DRM_AMDGPU_SI
161 extern int amdgpu_si_support;
162 #endif
163 #ifdef CONFIG_DRM_AMDGPU_CIK
164 extern int amdgpu_cik_support;
165 #endif
166
167 #define AMDGPU_SG_THRESHOLD                     (256*1024*1024)
168 #define AMDGPU_DEFAULT_GTT_SIZE_MB              3072ULL /* 3GB by default */
169 #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS          3000
170 #define AMDGPU_MAX_USEC_TIMEOUT                 100000  /* 100 ms */
171 #define AMDGPU_FENCE_JIFFIES_TIMEOUT            (HZ / 2)
172 /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
173 #define AMDGPU_IB_POOL_SIZE                     16
174 #define AMDGPU_DEBUGFS_MAX_COMPONENTS           32
175 #define AMDGPUFB_CONN_LIMIT                     4
176 #define AMDGPU_BIOS_NUM_SCRATCH                 16
177
178 /* hard reset data */
179 #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
180
181 /* reset flags */
182 #define AMDGPU_RESET_GFX                        (1 << 0)
183 #define AMDGPU_RESET_COMPUTE                    (1 << 1)
184 #define AMDGPU_RESET_DMA                        (1 << 2)
185 #define AMDGPU_RESET_CP                         (1 << 3)
186 #define AMDGPU_RESET_GRBM                       (1 << 4)
187 #define AMDGPU_RESET_DMA1                       (1 << 5)
188 #define AMDGPU_RESET_RLC                        (1 << 6)
189 #define AMDGPU_RESET_SEM                        (1 << 7)
190 #define AMDGPU_RESET_IH                         (1 << 8)
191 #define AMDGPU_RESET_VMC                        (1 << 9)
192 #define AMDGPU_RESET_MC                         (1 << 10)
193 #define AMDGPU_RESET_DISPLAY                    (1 << 11)
194 #define AMDGPU_RESET_UVD                        (1 << 12)
195 #define AMDGPU_RESET_VCE                        (1 << 13)
196 #define AMDGPU_RESET_VCE1                       (1 << 14)
197
198 /* max cursor sizes (in pixels) */
199 #define CIK_CURSOR_WIDTH 128
200 #define CIK_CURSOR_HEIGHT 128
201
202 struct amdgpu_device;
203 struct amdgpu_ib;
204 struct amdgpu_cs_parser;
205 struct amdgpu_job;
206 struct amdgpu_irq_src;
207 struct amdgpu_fpriv;
208 struct amdgpu_bo_va_mapping;
209 struct amdgpu_atif;
210
211 enum amdgpu_cp_irq {
212         AMDGPU_CP_IRQ_GFX_EOP = 0,
213         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
214         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
215         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
216         AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
217         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
218         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
219         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
220         AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
221
222         AMDGPU_CP_IRQ_LAST
223 };
224
225 enum amdgpu_thermal_irq {
226         AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
227         AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
228
229         AMDGPU_THERMAL_IRQ_LAST
230 };
231
232 enum amdgpu_kiq_irq {
233         AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
234         AMDGPU_CP_KIQ_IRQ_LAST
235 };
236
237 #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
238 #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
239 #define MAX_KIQ_REG_TRY 20
240
241 int amdgpu_device_ip_set_clockgating_state(void *dev,
242                                            enum amd_ip_block_type block_type,
243                                            enum amd_clockgating_state state);
244 int amdgpu_device_ip_set_powergating_state(void *dev,
245                                            enum amd_ip_block_type block_type,
246                                            enum amd_powergating_state state);
247 void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
248                                             u32 *flags);
249 int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
250                                    enum amd_ip_block_type block_type);
251 bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
252                               enum amd_ip_block_type block_type);
253
254 #define AMDGPU_MAX_IP_NUM 16
255
256 struct amdgpu_ip_block_status {
257         bool valid;
258         bool sw;
259         bool hw;
260         bool late_initialized;
261         bool hang;
262 };
263
264 struct amdgpu_ip_block_version {
265         const enum amd_ip_block_type type;
266         const u32 major;
267         const u32 minor;
268         const u32 rev;
269         const struct amd_ip_funcs *funcs;
270 };
271
272 struct amdgpu_ip_block {
273         struct amdgpu_ip_block_status status;
274         const struct amdgpu_ip_block_version *version;
275 };
276
277 int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
278                                        enum amd_ip_block_type type,
279                                        u32 major, u32 minor);
280
281 struct amdgpu_ip_block *
282 amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
283                               enum amd_ip_block_type type);
284
285 int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
286                                const struct amdgpu_ip_block_version *ip_block_version);
287
288 /*
289  * BIOS.
290  */
291 bool amdgpu_get_bios(struct amdgpu_device *adev);
292 bool amdgpu_read_bios(struct amdgpu_device *adev);
293
294 /*
295  * Clocks
296  */
297
298 #define AMDGPU_MAX_PPLL 3
299
300 struct amdgpu_clock {
301         struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
302         struct amdgpu_pll spll;
303         struct amdgpu_pll mpll;
304         /* 10 Khz units */
305         uint32_t default_mclk;
306         uint32_t default_sclk;
307         uint32_t default_dispclk;
308         uint32_t current_dispclk;
309         uint32_t dp_extclk;
310         uint32_t max_pixel_clock;
311 };
312
313 /* sub-allocation manager, it has to be protected by another lock.
314  * By conception this is an helper for other part of the driver
315  * like the indirect buffer or semaphore, which both have their
316  * locking.
317  *
318  * Principe is simple, we keep a list of sub allocation in offset
319  * order (first entry has offset == 0, last entry has the highest
320  * offset).
321  *
322  * When allocating new object we first check if there is room at
323  * the end total_size - (last_object_offset + last_object_size) >=
324  * alloc_size. If so we allocate new object there.
325  *
326  * When there is not enough room at the end, we start waiting for
327  * each sub object until we reach object_offset+object_size >=
328  * alloc_size, this object then become the sub object we return.
329  *
330  * Alignment can't be bigger than page size.
331  *
332  * Hole are not considered for allocation to keep things simple.
333  * Assumption is that there won't be hole (all object on same
334  * alignment).
335  */
336
337 #define AMDGPU_SA_NUM_FENCE_LISTS       32
338
339 struct amdgpu_sa_manager {
340         wait_queue_head_t       wq;
341         struct amdgpu_bo        *bo;
342         struct list_head        *hole;
343         struct list_head        flist[AMDGPU_SA_NUM_FENCE_LISTS];
344         struct list_head        olist;
345         unsigned                size;
346         uint64_t                gpu_addr;
347         void                    *cpu_ptr;
348         uint32_t                domain;
349         uint32_t                align;
350 };
351
352 /* sub-allocation buffer */
353 struct amdgpu_sa_bo {
354         struct list_head                olist;
355         struct list_head                flist;
356         struct amdgpu_sa_manager        *manager;
357         unsigned                        soffset;
358         unsigned                        eoffset;
359         struct dma_fence                *fence;
360 };
361
362 int amdgpu_fence_slab_init(void);
363 void amdgpu_fence_slab_fini(void);
364
365 /*
366  * IRQS.
367  */
368
369 struct amdgpu_flip_work {
370         struct delayed_work             flip_work;
371         struct work_struct              unpin_work;
372         struct amdgpu_device            *adev;
373         int                             crtc_id;
374         u32                             target_vblank;
375         uint64_t                        base;
376         struct drm_pending_vblank_event *event;
377         struct amdgpu_bo                *old_abo;
378         struct dma_fence                *excl;
379         unsigned                        shared_count;
380         struct dma_fence                **shared;
381         struct dma_fence_cb             cb;
382         bool                            async;
383 };
384
385
386 /*
387  * CP & rings.
388  */
389
390 struct amdgpu_ib {
391         struct amdgpu_sa_bo             *sa_bo;
392         uint32_t                        length_dw;
393         uint64_t                        gpu_addr;
394         uint32_t                        *ptr;
395         uint32_t                        flags;
396 };
397
398 extern const struct drm_sched_backend_ops amdgpu_sched_ops;
399
400 /*
401  * file private structure
402  */
403
404 struct amdgpu_fpriv {
405         struct amdgpu_vm        vm;
406         struct amdgpu_bo_va     *prt_va;
407         struct amdgpu_bo_va     *csa_va;
408         struct mutex            bo_list_lock;
409         struct idr              bo_list_handles;
410         struct amdgpu_ctx_mgr   ctx_mgr;
411 };
412
413 int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
414                   unsigned size, struct amdgpu_ib *ib);
415 void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
416                     struct dma_fence *f);
417 int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
418                        struct amdgpu_ib *ibs, struct amdgpu_job *job,
419                        struct dma_fence **f);
420 int amdgpu_ib_pool_init(struct amdgpu_device *adev);
421 void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
422 int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
423
424 /*
425  * CS.
426  */
427 struct amdgpu_cs_chunk {
428         uint32_t                chunk_id;
429         uint32_t                length_dw;
430         void                    *kdata;
431 };
432
433 struct amdgpu_cs_parser {
434         struct amdgpu_device    *adev;
435         struct drm_file         *filp;
436         struct amdgpu_ctx       *ctx;
437
438         /* chunks */
439         unsigned                nchunks;
440         struct amdgpu_cs_chunk  *chunks;
441
442         /* scheduler job object */
443         struct amdgpu_job       *job;
444         struct drm_sched_entity *entity;
445
446         /* buffer objects */
447         struct ww_acquire_ctx           ticket;
448         struct amdgpu_bo_list           *bo_list;
449         struct amdgpu_mn                *mn;
450         struct amdgpu_bo_list_entry     vm_pd;
451         struct list_head                validated;
452         struct dma_fence                *fence;
453         uint64_t                        bytes_moved_threshold;
454         uint64_t                        bytes_moved_vis_threshold;
455         uint64_t                        bytes_moved;
456         uint64_t                        bytes_moved_vis;
457         struct amdgpu_bo_list_entry     *evictable;
458
459         /* user fence */
460         struct amdgpu_bo_list_entry     uf_entry;
461
462         unsigned num_post_dep_syncobjs;
463         struct drm_syncobj **post_dep_syncobjs;
464 };
465
466 static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
467                                       uint32_t ib_idx, int idx)
468 {
469         return p->job->ibs[ib_idx].ptr[idx];
470 }
471
472 static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
473                                        uint32_t ib_idx, int idx,
474                                        uint32_t value)
475 {
476         p->job->ibs[ib_idx].ptr[idx] = value;
477 }
478
479 /*
480  * Writeback
481  */
482 #define AMDGPU_MAX_WB 128       /* Reserve at most 128 WB slots for amdgpu-owned rings. */
483
484 struct amdgpu_wb {
485         struct amdgpu_bo        *wb_obj;
486         volatile uint32_t       *wb;
487         uint64_t                gpu_addr;
488         u32                     num_wb; /* Number of wb slots actually reserved for amdgpu. */
489         unsigned long           used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
490 };
491
492 int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
493 void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
494
495 /*
496  * Benchmarking
497  */
498 void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
499
500
501 /*
502  * Testing
503  */
504 void amdgpu_test_moves(struct amdgpu_device *adev);
505
506 /*
507  * ASIC specific register table accessible by UMD
508  */
509 struct amdgpu_allowed_register_entry {
510         uint32_t reg_offset;
511         bool grbm_indexed;
512 };
513
514 /*
515  * ASIC specific functions.
516  */
517 struct amdgpu_asic_funcs {
518         bool (*read_disabled_bios)(struct amdgpu_device *adev);
519         bool (*read_bios_from_rom)(struct amdgpu_device *adev,
520                                    u8 *bios, u32 length_bytes);
521         int (*read_register)(struct amdgpu_device *adev, u32 se_num,
522                              u32 sh_num, u32 reg_offset, u32 *value);
523         void (*set_vga_state)(struct amdgpu_device *adev, bool state);
524         int (*reset)(struct amdgpu_device *adev);
525         /* get the reference clock */
526         u32 (*get_xclk)(struct amdgpu_device *adev);
527         /* MM block clocks */
528         int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
529         int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
530         /* static power management */
531         int (*get_pcie_lanes)(struct amdgpu_device *adev);
532         void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
533         /* get config memsize register */
534         u32 (*get_config_memsize)(struct amdgpu_device *adev);
535         /* flush hdp write queue */
536         void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
537         /* invalidate hdp read cache */
538         void (*invalidate_hdp)(struct amdgpu_device *adev,
539                                struct amdgpu_ring *ring);
540         /* check if the asic needs a full reset of if soft reset will work */
541         bool (*need_full_reset)(struct amdgpu_device *adev);
542         /* initialize doorbell layout for specific asic*/
543         void (*init_doorbell_index)(struct amdgpu_device *adev);
544 };
545
546 /*
547  * IOCTL.
548  */
549 int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
550                                 struct drm_file *filp);
551
552 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
553 int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
554                                     struct drm_file *filp);
555 int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
556 int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
557                                 struct drm_file *filp);
558
559 /* VRAM scratch page for HDP bug, default vram page */
560 struct amdgpu_vram_scratch {
561         struct amdgpu_bo                *robj;
562         volatile uint32_t               *ptr;
563         u64                             gpu_addr;
564 };
565
566 /*
567  * ACPI
568  */
569 struct amdgpu_atcs_functions {
570         bool get_ext_state;
571         bool pcie_perf_req;
572         bool pcie_dev_rdy;
573         bool pcie_bus_width;
574 };
575
576 struct amdgpu_atcs {
577         struct amdgpu_atcs_functions functions;
578 };
579
580 /*
581  * Firmware VRAM reservation
582  */
583 struct amdgpu_fw_vram_usage {
584         u64 start_offset;
585         u64 size;
586         struct amdgpu_bo *reserved_bo;
587         void *va;
588 };
589
590 /*
591  * CGS
592  */
593 struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
594 void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
595
596 /*
597  * Core structure, functions and helpers.
598  */
599 typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
600 typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
601
602 typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
603 typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
604
605
606 /*
607  * amdgpu nbio functions
608  *
609  */
610 struct nbio_hdp_flush_reg {
611         u32 ref_and_mask_cp0;
612         u32 ref_and_mask_cp1;
613         u32 ref_and_mask_cp2;
614         u32 ref_and_mask_cp3;
615         u32 ref_and_mask_cp4;
616         u32 ref_and_mask_cp5;
617         u32 ref_and_mask_cp6;
618         u32 ref_and_mask_cp7;
619         u32 ref_and_mask_cp8;
620         u32 ref_and_mask_cp9;
621         u32 ref_and_mask_sdma0;
622         u32 ref_and_mask_sdma1;
623 };
624
625 struct amdgpu_nbio_funcs {
626         const struct nbio_hdp_flush_reg *hdp_flush_reg;
627         u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
628         u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
629         u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
630         u32 (*get_pcie_data_offset)(struct amdgpu_device *adev);
631         u32 (*get_rev_id)(struct amdgpu_device *adev);
632         void (*mc_access_enable)(struct amdgpu_device *adev, bool enable);
633         void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
634         u32 (*get_memsize)(struct amdgpu_device *adev);
635         void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
636                                     bool use_doorbell, int doorbell_index);
637         void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
638                                          bool enable);
639         void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
640                                                   bool enable);
641         void (*ih_doorbell_range)(struct amdgpu_device *adev,
642                                   bool use_doorbell, int doorbell_index);
643         void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
644                                                  bool enable);
645         void (*update_medium_grain_light_sleep)(struct amdgpu_device *adev,
646                                                 bool enable);
647         void (*get_clockgating_state)(struct amdgpu_device *adev,
648                                       u32 *flags);
649         void (*ih_control)(struct amdgpu_device *adev);
650         void (*init_registers)(struct amdgpu_device *adev);
651         void (*detect_hw_virt)(struct amdgpu_device *adev);
652 };
653
654 struct amdgpu_df_funcs {
655         void (*init)(struct amdgpu_device *adev);
656         void (*enable_broadcast_mode)(struct amdgpu_device *adev,
657                                       bool enable);
658         u32 (*get_fb_channel_number)(struct amdgpu_device *adev);
659         u32 (*get_hbm_channel_number)(struct amdgpu_device *adev);
660         void (*update_medium_grain_clock_gating)(struct amdgpu_device *adev,
661                                                  bool enable);
662         void (*get_clockgating_state)(struct amdgpu_device *adev,
663                                       u32 *flags);
664         void (*enable_ecc_force_par_wr_rmw)(struct amdgpu_device *adev,
665                                             bool enable);
666 };
667 /* Define the HW IP blocks will be used in driver , add more if necessary */
668 enum amd_hw_ip_block_type {
669         GC_HWIP = 1,
670         HDP_HWIP,
671         SDMA0_HWIP,
672         SDMA1_HWIP,
673         MMHUB_HWIP,
674         ATHUB_HWIP,
675         NBIO_HWIP,
676         MP0_HWIP,
677         MP1_HWIP,
678         UVD_HWIP,
679         VCN_HWIP = UVD_HWIP,
680         VCE_HWIP,
681         DF_HWIP,
682         DCE_HWIP,
683         OSSSYS_HWIP,
684         SMUIO_HWIP,
685         PWR_HWIP,
686         NBIF_HWIP,
687         THM_HWIP,
688         CLK_HWIP,
689         MAX_HWIP
690 };
691
692 #define HWIP_MAX_INSTANCE       6
693
694 struct amd_powerplay {
695         void *pp_handle;
696         const struct amd_pm_funcs *pp_funcs;
697         uint32_t pp_feature;
698 };
699
700 #define AMDGPU_RESET_MAGIC_NUM 64
701 struct amdgpu_device {
702         struct device                   *dev;
703         struct drm_device               *ddev;
704         struct pci_dev                  *pdev;
705
706 #ifdef CONFIG_DRM_AMD_ACP
707         struct amdgpu_acp               acp;
708 #endif
709
710         /* ASIC */
711         enum amd_asic_type              asic_type;
712         uint32_t                        family;
713         uint32_t                        rev_id;
714         uint32_t                        external_rev_id;
715         unsigned long                   flags;
716         int                             usec_timeout;
717         const struct amdgpu_asic_funcs  *asic_funcs;
718         bool                            shutdown;
719         bool                            need_dma32;
720         bool                            need_swiotlb;
721         bool                            accel_working;
722         struct notifier_block           acpi_nb;
723         struct amdgpu_i2c_chan          *i2c_bus[AMDGPU_MAX_I2C_BUS];
724         struct amdgpu_debugfs           debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
725         unsigned                        debugfs_count;
726 #if defined(CONFIG_DEBUG_FS)
727         struct dentry                   *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
728 #endif
729         struct amdgpu_atif              *atif;
730         struct amdgpu_atcs              atcs;
731         struct mutex                    srbm_mutex;
732         /* GRBM index mutex. Protects concurrent access to GRBM index */
733         struct mutex                    grbm_idx_mutex;
734         struct dev_pm_domain            vga_pm_domain;
735         bool                            have_disp_power_ref;
736
737         /* BIOS */
738         bool                            is_atom_fw;
739         uint8_t                         *bios;
740         uint32_t                        bios_size;
741         struct amdgpu_bo                *stolen_vga_memory;
742         uint32_t                        bios_scratch_reg_offset;
743         uint32_t                        bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
744
745         /* Register/doorbell mmio */
746         resource_size_t                 rmmio_base;
747         resource_size_t                 rmmio_size;
748         void __iomem                    *rmmio;
749         /* protects concurrent MM_INDEX/DATA based register access */
750         spinlock_t mmio_idx_lock;
751         /* protects concurrent SMC based register access */
752         spinlock_t smc_idx_lock;
753         amdgpu_rreg_t                   smc_rreg;
754         amdgpu_wreg_t                   smc_wreg;
755         /* protects concurrent PCIE register access */
756         spinlock_t pcie_idx_lock;
757         amdgpu_rreg_t                   pcie_rreg;
758         amdgpu_wreg_t                   pcie_wreg;
759         amdgpu_rreg_t                   pciep_rreg;
760         amdgpu_wreg_t                   pciep_wreg;
761         /* protects concurrent UVD register access */
762         spinlock_t uvd_ctx_idx_lock;
763         amdgpu_rreg_t                   uvd_ctx_rreg;
764         amdgpu_wreg_t                   uvd_ctx_wreg;
765         /* protects concurrent DIDT register access */
766         spinlock_t didt_idx_lock;
767         amdgpu_rreg_t                   didt_rreg;
768         amdgpu_wreg_t                   didt_wreg;
769         /* protects concurrent gc_cac register access */
770         spinlock_t gc_cac_idx_lock;
771         amdgpu_rreg_t                   gc_cac_rreg;
772         amdgpu_wreg_t                   gc_cac_wreg;
773         /* protects concurrent se_cac register access */
774         spinlock_t se_cac_idx_lock;
775         amdgpu_rreg_t                   se_cac_rreg;
776         amdgpu_wreg_t                   se_cac_wreg;
777         /* protects concurrent ENDPOINT (audio) register access */
778         spinlock_t audio_endpt_idx_lock;
779         amdgpu_block_rreg_t             audio_endpt_rreg;
780         amdgpu_block_wreg_t             audio_endpt_wreg;
781         void __iomem                    *rio_mem;
782         resource_size_t                 rio_mem_size;
783         struct amdgpu_doorbell          doorbell;
784
785         /* clock/pll info */
786         struct amdgpu_clock            clock;
787
788         /* MC */
789         struct amdgpu_gmc               gmc;
790         struct amdgpu_gart              gart;
791         dma_addr_t                      dummy_page_addr;
792         struct amdgpu_vm_manager        vm_manager;
793         struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
794
795         /* memory management */
796         struct amdgpu_mman              mman;
797         struct amdgpu_vram_scratch      vram_scratch;
798         struct amdgpu_wb                wb;
799         atomic64_t                      num_bytes_moved;
800         atomic64_t                      num_evictions;
801         atomic64_t                      num_vram_cpu_page_faults;
802         atomic_t                        gpu_reset_counter;
803         atomic_t                        vram_lost_counter;
804
805         /* data for buffer migration throttling */
806         struct {
807                 spinlock_t              lock;
808                 s64                     last_update_us;
809                 s64                     accum_us; /* accumulated microseconds */
810                 s64                     accum_us_vis; /* for visible VRAM */
811                 u32                     log2_max_MBps;
812         } mm_stats;
813
814         /* display */
815         bool                            enable_virtual_display;
816         struct amdgpu_mode_info         mode_info;
817         /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
818         struct work_struct              hotplug_work;
819         struct amdgpu_irq_src           crtc_irq;
820         struct amdgpu_irq_src           pageflip_irq;
821         struct amdgpu_irq_src           hpd_irq;
822
823         /* rings */
824         u64                             fence_context;
825         unsigned                        num_rings;
826         struct amdgpu_ring              *rings[AMDGPU_MAX_RINGS];
827         bool                            ib_pool_ready;
828         struct amdgpu_sa_manager        ring_tmp_bo;
829
830         /* interrupts */
831         struct amdgpu_irq               irq;
832
833         /* powerplay */
834         struct amd_powerplay            powerplay;
835         bool                            pp_force_state_enabled;
836
837         /* dpm */
838         struct amdgpu_pm                pm;
839         u32                             cg_flags;
840         u32                             pg_flags;
841
842         /* gfx */
843         struct amdgpu_gfx               gfx;
844
845         /* sdma */
846         struct amdgpu_sdma              sdma;
847
848         /* uvd */
849         struct amdgpu_uvd               uvd;
850
851         /* vce */
852         struct amdgpu_vce               vce;
853
854         /* vcn */
855         struct amdgpu_vcn               vcn;
856
857         /* firmwares */
858         struct amdgpu_firmware          firmware;
859
860         /* PSP */
861         struct psp_context              psp;
862
863         /* GDS */
864         struct amdgpu_gds               gds;
865
866         /* KFD */
867         struct amdgpu_kfd_dev           kfd;
868
869         /* display related functionality */
870         struct amdgpu_display_manager dm;
871
872         struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
873         int                             num_ip_blocks;
874         struct mutex    mn_lock;
875         DECLARE_HASHTABLE(mn_hash, 7);
876
877         /* tracking pinned memory */
878         atomic64_t vram_pin_size;
879         atomic64_t visible_pin_size;
880         atomic64_t gart_pin_size;
881
882         /* soc15 register offset based on ip, instance and  segment */
883         uint32_t                *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
884
885         const struct amdgpu_nbio_funcs  *nbio_funcs;
886         const struct amdgpu_df_funcs    *df_funcs;
887
888         /* delayed work_func for deferring clockgating during resume */
889         struct delayed_work     late_init_work;
890
891         struct amdgpu_virt      virt;
892         /* firmware VRAM reservation */
893         struct amdgpu_fw_vram_usage fw_vram_usage;
894
895         /* link all shadow bo */
896         struct list_head                shadow_list;
897         struct mutex                    shadow_list_lock;
898         /* keep an lru list of rings by HW IP */
899         struct list_head                ring_lru_list;
900         spinlock_t                      ring_lru_list_lock;
901
902         /* record hw reset is performed */
903         bool has_hw_reset;
904         u8                              reset_magic[AMDGPU_RESET_MAGIC_NUM];
905
906         /* s3/s4 mask */
907         bool                            in_suspend;
908
909         /* record last mm index being written through WREG32*/
910         unsigned long last_mm_index;
911         bool                            in_gpu_reset;
912         struct mutex  lock_reset;
913         struct amdgpu_doorbell_index doorbell_index;
914
915         int asic_reset_res;
916         struct work_struct              xgmi_reset_work;
917 };
918
919 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
920 {
921         return container_of(bdev, struct amdgpu_device, mman.bdev);
922 }
923
924 int amdgpu_device_init(struct amdgpu_device *adev,
925                        struct drm_device *ddev,
926                        struct pci_dev *pdev,
927                        uint32_t flags);
928 void amdgpu_device_fini(struct amdgpu_device *adev);
929 int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
930
931 uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
932                         uint32_t acc_flags);
933 void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
934                     uint32_t acc_flags);
935 void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
936 uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
937
938 u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
939 void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
940
941 bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
942 bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
943
944 int emu_soc_asic_init(struct amdgpu_device *adev);
945
946 /*
947  * Registers read & write functions.
948  */
949
950 #define AMDGPU_REGS_IDX       (1<<0)
951 #define AMDGPU_REGS_NO_KIQ    (1<<1)
952
953 #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
954 #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
955
956 #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
957 #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
958
959 #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
960 #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
961 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
962 #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
963 #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
964 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
965 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
966 #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
967 #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
968 #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
969 #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
970 #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
971 #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
972 #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
973 #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
974 #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
975 #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
976 #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
977 #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
978 #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
979 #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
980 #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
981 #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
982 #define WREG32_P(reg, val, mask)                                \
983         do {                                                    \
984                 uint32_t tmp_ = RREG32(reg);                    \
985                 tmp_ &= (mask);                                 \
986                 tmp_ |= ((val) & ~(mask));                      \
987                 WREG32(reg, tmp_);                              \
988         } while (0)
989 #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
990 #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
991 #define WREG32_PLL_P(reg, val, mask)                            \
992         do {                                                    \
993                 uint32_t tmp_ = RREG32_PLL(reg);                \
994                 tmp_ &= (mask);                                 \
995                 tmp_ |= ((val) & ~(mask));                      \
996                 WREG32_PLL(reg, tmp_);                          \
997         } while (0)
998 #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
999 #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1000 #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1001
1002 #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1003 #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1004
1005 #define REG_SET_FIELD(orig_val, reg, field, field_val)                  \
1006         (((orig_val) & ~REG_FIELD_MASK(reg, field)) |                   \
1007          (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1008
1009 #define REG_GET_FIELD(value, reg, field)                                \
1010         (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1011
1012 #define WREG32_FIELD(reg, field, val)   \
1013         WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1014
1015 #define WREG32_FIELD_OFFSET(reg, offset, field, val)    \
1016         WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1017
1018 /*
1019  * BIOS helpers.
1020  */
1021 #define RBIOS8(i) (adev->bios[i])
1022 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1023 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1024
1025 /*
1026  * ASICs macro.
1027  */
1028 #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1029 #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
1030 #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1031 #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1032 #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
1033 #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1034 #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1035 #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
1036 #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
1037 #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
1038 #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
1039 #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
1040 #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r))
1041 #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))
1042 #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev))
1043 #define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev))
1044
1045 /* Common functions */
1046 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
1047 int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
1048                               struct amdgpu_job* job);
1049 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
1050 bool amdgpu_device_need_post(struct amdgpu_device *adev);
1051
1052 void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
1053                                   u64 num_vis_bytes);
1054 int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
1055 void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
1056                                              const u32 *registers,
1057                                              const u32 array_size);
1058
1059 bool amdgpu_device_is_px(struct drm_device *dev);
1060 /* atpx handler */
1061 #if defined(CONFIG_VGA_SWITCHEROO)
1062 void amdgpu_register_atpx_handler(void);
1063 void amdgpu_unregister_atpx_handler(void);
1064 bool amdgpu_has_atpx_dgpu_power_cntl(void);
1065 bool amdgpu_is_atpx_hybrid(void);
1066 bool amdgpu_atpx_dgpu_req_power_for_displays(void);
1067 bool amdgpu_has_atpx(void);
1068 #else
1069 static inline void amdgpu_register_atpx_handler(void) {}
1070 static inline void amdgpu_unregister_atpx_handler(void) {}
1071 static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
1072 static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
1073 static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
1074 static inline bool amdgpu_has_atpx(void) { return false; }
1075 #endif
1076
1077 #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
1078 void *amdgpu_atpx_get_dhandle(void);
1079 #else
1080 static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
1081 #endif
1082
1083 /*
1084  * KMS
1085  */
1086 extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
1087 extern const int amdgpu_max_kms_ioctl;
1088
1089 int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
1090 void amdgpu_driver_unload_kms(struct drm_device *dev);
1091 void amdgpu_driver_lastclose_kms(struct drm_device *dev);
1092 int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
1093 void amdgpu_driver_postclose_kms(struct drm_device *dev,
1094                                  struct drm_file *file_priv);
1095 int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
1096 int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1097 int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
1098 u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
1099 int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1100 void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
1101 long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
1102                              unsigned long arg);
1103
1104 /*
1105  * functions used by amdgpu_encoder.c
1106  */
1107 struct amdgpu_afmt_acr {
1108         u32 clock;
1109
1110         int n_32khz;
1111         int cts_32khz;
1112
1113         int n_44_1khz;
1114         int cts_44_1khz;
1115
1116         int n_48khz;
1117         int cts_48khz;
1118
1119 };
1120
1121 struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
1122
1123 /* amdgpu_acpi.c */
1124 #if defined(CONFIG_ACPI)
1125 int amdgpu_acpi_init(struct amdgpu_device *adev);
1126 void amdgpu_acpi_fini(struct amdgpu_device *adev);
1127 bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
1128 int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
1129                                                 u8 perf_req, bool advertise);
1130 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
1131
1132 void amdgpu_acpi_get_backlight_caps(struct amdgpu_device *adev,
1133                 struct amdgpu_dm_backlight_caps *caps);
1134 #else
1135 static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
1136 static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
1137 #endif
1138
1139 int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
1140                            uint64_t addr, struct amdgpu_bo **bo,
1141                            struct amdgpu_bo_va_mapping **mapping);
1142
1143 #if defined(CONFIG_DRM_AMD_DC)
1144 int amdgpu_dm_display_resume(struct amdgpu_device *adev );
1145 #else
1146 static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
1147 #endif
1148
1149 #include "amdgpu_object.h"
1150 #endif