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