blob: 49adb451c3bc54c8fd5c17821f8a62e845dab9d7 [file] [log] [blame]
Alex Deucher97b2e202015-04-20 16:51:00 -04001/*
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
Chunming Zhoud03846a2015-07-28 14:20:03 -040045#include <drm/drmP.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040046#include <drm/drm_gem.h>
Chunming Zhou7e5a5472015-04-24 17:37:30 +080047#include <drm/amdgpu_drm.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040048
yanyang15fc3aee2015-05-22 14:39:35 -040049#include "amd_shared.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040050#include "amdgpu_mode.h"
51#include "amdgpu_ih.h"
52#include "amdgpu_irq.h"
53#include "amdgpu_ucode.h"
54#include "amdgpu_gds.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050055#include "amd_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040056#include "amdgpu_acp.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040057
Alex Deucherb80d8472015-08-16 22:55:02 -040058#include "gpu_scheduler.h"
59
Alex Deucher97b2e202015-04-20 16:51:00 -040060/*
61 * Modules parameters.
62 */
63extern int amdgpu_modeset;
64extern int amdgpu_vram_limit;
65extern int amdgpu_gart_size;
66extern int amdgpu_benchmarking;
67extern int amdgpu_testing;
68extern int amdgpu_audio;
69extern int amdgpu_disp_priority;
70extern int amdgpu_hw_i2c;
71extern int amdgpu_pcie_gen2;
72extern int amdgpu_msi;
73extern int amdgpu_lockup_timeout;
74extern int amdgpu_dpm;
75extern int amdgpu_smc_load_fw;
76extern int amdgpu_aspm;
77extern int amdgpu_runtime_pm;
Alex Deucher97b2e202015-04-20 16:51:00 -040078extern unsigned amdgpu_ip_block_mask;
79extern int amdgpu_bapm;
80extern int amdgpu_deep_color;
81extern int amdgpu_vm_size;
82extern int amdgpu_vm_block_size;
Christian Königd9c13152015-09-28 12:31:26 +020083extern int amdgpu_vm_fault_stop;
Christian Königb495bd32015-09-10 14:00:35 +020084extern int amdgpu_vm_debug;
Jammy Zhou1333f722015-07-30 16:36:58 +080085extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080086extern int amdgpu_sched_hw_submission;
Alex Deucher1f7371b2015-12-02 17:46:21 -050087extern int amdgpu_powerplay;
Alex Deuchercd474ba2016-02-04 10:21:23 -050088extern unsigned amdgpu_pcie_gen_cap;
89extern unsigned amdgpu_pcie_lane_cap;
Alex Deucher97b2e202015-04-20 16:51:00 -040090
Chunming Zhou4b559c92015-07-21 15:53:04 +080091#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -040092#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
93#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
94/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
95#define AMDGPU_IB_POOL_SIZE 16
96#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
97#define AMDGPUFB_CONN_LIMIT 4
98#define AMDGPU_BIOS_NUM_SCRATCH 8
99
Alex Deucher97b2e202015-04-20 16:51:00 -0400100/* max number of rings */
101#define AMDGPU_MAX_RINGS 16
102#define AMDGPU_MAX_GFX_RINGS 1
103#define AMDGPU_MAX_COMPUTE_RINGS 8
104#define AMDGPU_MAX_VCE_RINGS 2
105
Jammy Zhou36f523a2015-09-01 12:54:27 +0800106/* max number of IP instances */
107#define AMDGPU_MAX_SDMA_INSTANCES 2
108
Alex Deucher97b2e202015-04-20 16:51:00 -0400109/* hardcode that limit for now */
110#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
111
112/* hard reset data */
113#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
114
115/* reset flags */
116#define AMDGPU_RESET_GFX (1 << 0)
117#define AMDGPU_RESET_COMPUTE (1 << 1)
118#define AMDGPU_RESET_DMA (1 << 2)
119#define AMDGPU_RESET_CP (1 << 3)
120#define AMDGPU_RESET_GRBM (1 << 4)
121#define AMDGPU_RESET_DMA1 (1 << 5)
122#define AMDGPU_RESET_RLC (1 << 6)
123#define AMDGPU_RESET_SEM (1 << 7)
124#define AMDGPU_RESET_IH (1 << 8)
125#define AMDGPU_RESET_VMC (1 << 9)
126#define AMDGPU_RESET_MC (1 << 10)
127#define AMDGPU_RESET_DISPLAY (1 << 11)
128#define AMDGPU_RESET_UVD (1 << 12)
129#define AMDGPU_RESET_VCE (1 << 13)
130#define AMDGPU_RESET_VCE1 (1 << 14)
131
Alex Deucher97b2e202015-04-20 16:51:00 -0400132/* GFX current status */
133#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
134#define AMDGPU_GFX_SAFE_MODE 0x00000001L
135#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
136#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
137#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
138
139/* max cursor sizes (in pixels) */
140#define CIK_CURSOR_WIDTH 128
141#define CIK_CURSOR_HEIGHT 128
142
143struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400144struct amdgpu_ib;
145struct amdgpu_vm;
146struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400147struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800148struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400149struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400150struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400151
152enum amdgpu_cp_irq {
153 AMDGPU_CP_IRQ_GFX_EOP = 0,
154 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
155 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
156 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
157 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
158 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
159 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
160 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
161 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
162
163 AMDGPU_CP_IRQ_LAST
164};
165
166enum amdgpu_sdma_irq {
167 AMDGPU_SDMA_IRQ_TRAP0 = 0,
168 AMDGPU_SDMA_IRQ_TRAP1,
169
170 AMDGPU_SDMA_IRQ_LAST
171};
172
173enum amdgpu_thermal_irq {
174 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
175 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
176
177 AMDGPU_THERMAL_IRQ_LAST
178};
179
Alex Deucher97b2e202015-04-20 16:51:00 -0400180int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400181 enum amd_ip_block_type block_type,
182 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400183int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400184 enum amd_ip_block_type block_type,
185 enum amd_powergating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400186
187struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400188 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400189 u32 major;
190 u32 minor;
191 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400192 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400193};
194
195int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400196 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400197 u32 major, u32 minor);
198
199const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
200 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400201 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400202
203/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
204struct amdgpu_buffer_funcs {
205 /* maximum bytes in a single operation */
206 uint32_t copy_max_bytes;
207
208 /* number of dw to reserve per operation */
209 unsigned copy_num_dw;
210
211 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800212 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400213 /* src addr in bytes */
214 uint64_t src_offset,
215 /* dst addr in bytes */
216 uint64_t dst_offset,
217 /* number of byte to transfer */
218 uint32_t byte_count);
219
220 /* maximum bytes in a single operation */
221 uint32_t fill_max_bytes;
222
223 /* number of dw to reserve per operation */
224 unsigned fill_num_dw;
225
226 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800227 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400228 /* value to write to memory */
229 uint32_t src_data,
230 /* dst addr in bytes */
231 uint64_t dst_offset,
232 /* number of byte to fill */
233 uint32_t byte_count);
234};
235
236/* provided by hw blocks that can write ptes, e.g., sdma */
237struct amdgpu_vm_pte_funcs {
238 /* copy pte entries from GART */
239 void (*copy_pte)(struct amdgpu_ib *ib,
240 uint64_t pe, uint64_t src,
241 unsigned count);
242 /* write pte one entry at a time with addr mapping */
243 void (*write_pte)(struct amdgpu_ib *ib,
Christian Königb07c9d22015-11-30 13:26:07 +0100244 const dma_addr_t *pages_addr, uint64_t pe,
Alex Deucher97b2e202015-04-20 16:51:00 -0400245 uint64_t addr, unsigned count,
246 uint32_t incr, uint32_t flags);
247 /* for linear pte/pde updates without addr mapping */
248 void (*set_pte_pde)(struct amdgpu_ib *ib,
249 uint64_t pe,
250 uint64_t addr, unsigned count,
251 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400252};
253
254/* provided by the gmc block */
255struct amdgpu_gart_funcs {
256 /* flush the vm tlb via mmio */
257 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
258 uint32_t vmid);
259 /* write pte/pde updates using the cpu */
260 int (*set_pte_pde)(struct amdgpu_device *adev,
261 void *cpu_pt_addr, /* cpu addr of page table */
262 uint32_t gpu_page_idx, /* pte/pde to update */
263 uint64_t addr, /* addr to write into pte/pde */
264 uint32_t flags); /* access flags */
265};
266
267/* provided by the ih block */
268struct amdgpu_ih_funcs {
269 /* ring read/write ptr handling, called from interrupt context */
270 u32 (*get_wptr)(struct amdgpu_device *adev);
271 void (*decode_iv)(struct amdgpu_device *adev,
272 struct amdgpu_iv_entry *entry);
273 void (*set_rptr)(struct amdgpu_device *adev);
274};
275
276/* provided by hw blocks that expose a ring buffer for commands */
277struct amdgpu_ring_funcs {
278 /* ring read/write ptr handling */
279 u32 (*get_rptr)(struct amdgpu_ring *ring);
280 u32 (*get_wptr)(struct amdgpu_ring *ring);
281 void (*set_wptr)(struct amdgpu_ring *ring);
282 /* validating and patching of IBs */
283 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
284 /* command emit functions */
285 void (*emit_ib)(struct amdgpu_ring *ring,
286 struct amdgpu_ib *ib);
287 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800288 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100289 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400290 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
291 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200292 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800293 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400294 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
295 uint32_t gds_base, uint32_t gds_size,
296 uint32_t gws_base, uint32_t gws_size,
297 uint32_t oa_base, uint32_t oa_size);
298 /* testing functions */
299 int (*test_ring)(struct amdgpu_ring *ring);
300 int (*test_ib)(struct amdgpu_ring *ring);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800301 /* insert NOP packets */
302 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100303 /* pad the indirect buffer to the necessary number of dw */
304 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -0400305};
306
307/*
308 * BIOS.
309 */
310bool amdgpu_get_bios(struct amdgpu_device *adev);
311bool amdgpu_read_bios(struct amdgpu_device *adev);
312
313/*
314 * Dummy page
315 */
316struct amdgpu_dummy_page {
317 struct page *page;
318 dma_addr_t addr;
319};
320int amdgpu_dummy_page_init(struct amdgpu_device *adev);
321void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
322
323
324/*
325 * Clocks
326 */
327
328#define AMDGPU_MAX_PPLL 3
329
330struct amdgpu_clock {
331 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
332 struct amdgpu_pll spll;
333 struct amdgpu_pll mpll;
334 /* 10 Khz units */
335 uint32_t default_mclk;
336 uint32_t default_sclk;
337 uint32_t default_dispclk;
338 uint32_t current_dispclk;
339 uint32_t dp_extclk;
340 uint32_t max_pixel_clock;
341};
342
343/*
344 * Fences.
345 */
346struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400347 uint64_t gpu_addr;
348 volatile uint32_t *cpu_addr;
349 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100350 uint32_t sync_seq;
351 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400352 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400353 struct amdgpu_irq_src *irq_src;
354 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100355 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100356 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100357 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100358 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400359};
360
361/* some special values for the owner field */
362#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
363#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400364
Chunming Zhou890ee232015-06-01 14:35:03 +0800365#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
366#define AMDGPU_FENCE_FLAG_INT (1 << 1)
367
Alex Deucher97b2e202015-04-20 16:51:00 -0400368struct amdgpu_user_fence {
369 /* write-back bo */
370 struct amdgpu_bo *bo;
371 /* write-back address offset to bo start */
372 uint32_t offset;
373};
374
375int amdgpu_fence_driver_init(struct amdgpu_device *adev);
376void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
377void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
378
Christian Könige6151a02016-03-15 14:52:26 +0100379int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
380 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400381int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
382 struct amdgpu_irq_src *irq_src,
383 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400384void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
385void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100386int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400387void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400388int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
389unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
390
Alex Deucher97b2e202015-04-20 16:51:00 -0400391/*
392 * TTM.
393 */
394struct amdgpu_mman {
395 struct ttm_bo_global_ref bo_global_ref;
396 struct drm_global_reference mem_global_ref;
397 struct ttm_bo_device bdev;
398 bool mem_global_referenced;
399 bool initialized;
400
401#if defined(CONFIG_DEBUG_FS)
402 struct dentry *vram;
403 struct dentry *gtt;
404#endif
405
406 /* buffer handling */
407 const struct amdgpu_buffer_funcs *buffer_funcs;
408 struct amdgpu_ring *buffer_funcs_ring;
Christian König703297c2016-02-10 14:20:50 +0100409 /* Scheduler entity for buffer moves */
410 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -0400411};
412
413int amdgpu_copy_buffer(struct amdgpu_ring *ring,
414 uint64_t src_offset,
415 uint64_t dst_offset,
416 uint32_t byte_count,
417 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800418 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400419int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
420
421struct amdgpu_bo_list_entry {
422 struct amdgpu_bo *robj;
423 struct ttm_validate_buffer tv;
424 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400425 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100426 struct page **user_pages;
427 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400428};
429
430struct amdgpu_bo_va_mapping {
431 struct list_head list;
432 struct interval_tree_node it;
433 uint64_t offset;
434 uint32_t flags;
435};
436
437/* bo virtual addresses in a specific vm */
438struct amdgpu_bo_va {
439 /* protected by bo being reserved */
440 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800441 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400442 unsigned ref_count;
443
Christian König7fc11952015-07-30 11:53:42 +0200444 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400445 struct list_head vm_status;
446
Christian König7fc11952015-07-30 11:53:42 +0200447 /* mappings for this bo_va */
448 struct list_head invalids;
449 struct list_head valids;
450
Alex Deucher97b2e202015-04-20 16:51:00 -0400451 /* constant after initialization */
452 struct amdgpu_vm *vm;
453 struct amdgpu_bo *bo;
454};
455
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800456#define AMDGPU_GEM_DOMAIN_MAX 0x3
457
Alex Deucher97b2e202015-04-20 16:51:00 -0400458struct amdgpu_bo {
459 /* Protected by gem.mutex */
460 struct list_head list;
461 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100462 u32 prefered_domains;
463 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800464 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400465 struct ttm_placement placement;
466 struct ttm_buffer_object tbo;
467 struct ttm_bo_kmap_obj kmap;
468 u64 flags;
469 unsigned pin_count;
470 void *kptr;
471 u64 tiling_flags;
472 u64 metadata_flags;
473 void *metadata;
474 u32 metadata_size;
475 /* list of all virtual address to which this bo
476 * is associated to
477 */
478 struct list_head va;
479 /* Constant after initialization */
480 struct amdgpu_device *adev;
481 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100482 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400483
484 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400485 struct amdgpu_mn *mn;
486 struct list_head mn_list;
487};
488#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
489
490void amdgpu_gem_object_free(struct drm_gem_object *obj);
491int amdgpu_gem_object_open(struct drm_gem_object *obj,
492 struct drm_file *file_priv);
493void amdgpu_gem_object_close(struct drm_gem_object *obj,
494 struct drm_file *file_priv);
495unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
496struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
497struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
498 struct dma_buf_attachment *attach,
499 struct sg_table *sg);
500struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
501 struct drm_gem_object *gobj,
502 int flags);
503int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
504void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
505struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
506void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
507void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
508int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
509
510/* sub-allocation manager, it has to be protected by another lock.
511 * By conception this is an helper for other part of the driver
512 * like the indirect buffer or semaphore, which both have their
513 * locking.
514 *
515 * Principe is simple, we keep a list of sub allocation in offset
516 * order (first entry has offset == 0, last entry has the highest
517 * offset).
518 *
519 * When allocating new object we first check if there is room at
520 * the end total_size - (last_object_offset + last_object_size) >=
521 * alloc_size. If so we allocate new object there.
522 *
523 * When there is not enough room at the end, we start waiting for
524 * each sub object until we reach object_offset+object_size >=
525 * alloc_size, this object then become the sub object we return.
526 *
527 * Alignment can't be bigger than page size.
528 *
529 * Hole are not considered for allocation to keep things simple.
530 * Assumption is that there won't be hole (all object on same
531 * alignment).
532 */
Christian König6ba60b82016-03-11 14:50:08 +0100533
534#define AMDGPU_SA_NUM_FENCE_LISTS 32
535
Alex Deucher97b2e202015-04-20 16:51:00 -0400536struct amdgpu_sa_manager {
537 wait_queue_head_t wq;
538 struct amdgpu_bo *bo;
539 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100540 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400541 struct list_head olist;
542 unsigned size;
543 uint64_t gpu_addr;
544 void *cpu_ptr;
545 uint32_t domain;
546 uint32_t align;
547};
548
Alex Deucher97b2e202015-04-20 16:51:00 -0400549/* sub-allocation buffer */
550struct amdgpu_sa_bo {
551 struct list_head olist;
552 struct list_head flist;
553 struct amdgpu_sa_manager *manager;
554 unsigned soffset;
555 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800556 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400557};
558
559/*
560 * GEM objects.
561 */
Christian König418aa0c2016-02-15 16:59:57 +0100562void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400563int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
564 int alignment, u32 initial_domain,
565 u64 flags, bool kernel,
566 struct drm_gem_object **obj);
567
568int amdgpu_mode_dumb_create(struct drm_file *file_priv,
569 struct drm_device *dev,
570 struct drm_mode_create_dumb *args);
571int amdgpu_mode_dumb_mmap(struct drm_file *filp,
572 struct drm_device *dev,
573 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400574/*
575 * Synchronization
576 */
577struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800578 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800579 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400580};
581
582void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200583int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
584 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400585int amdgpu_sync_resv(struct amdgpu_device *adev,
586 struct amdgpu_sync *sync,
587 struct reservation_object *resv,
588 void *owner);
Christian Könige61235d2015-08-25 11:05:36 +0200589struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian Königf91b3a62015-08-20 14:47:40 +0800590int amdgpu_sync_wait(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100591void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100592int amdgpu_sync_init(void);
593void amdgpu_sync_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400594
595/*
596 * GART structures, functions & helpers
597 */
598struct amdgpu_mc;
599
600#define AMDGPU_GPU_PAGE_SIZE 4096
601#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
602#define AMDGPU_GPU_PAGE_SHIFT 12
603#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
604
605struct amdgpu_gart {
606 dma_addr_t table_addr;
607 struct amdgpu_bo *robj;
608 void *ptr;
609 unsigned num_gpu_pages;
610 unsigned num_cpu_pages;
611 unsigned table_size;
612 struct page **pages;
613 dma_addr_t *pages_addr;
614 bool ready;
615 const struct amdgpu_gart_funcs *gart_funcs;
616};
617
618int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
619void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
620int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
621void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
622int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
623void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
624int amdgpu_gart_init(struct amdgpu_device *adev);
625void amdgpu_gart_fini(struct amdgpu_device *adev);
626void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
627 int pages);
628int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
629 int pages, struct page **pagelist,
630 dma_addr_t *dma_addr, uint32_t flags);
631
632/*
633 * GPU MC structures, functions & helpers
634 */
635struct amdgpu_mc {
636 resource_size_t aper_size;
637 resource_size_t aper_base;
638 resource_size_t agp_base;
639 /* for some chips with <= 32MB we need to lie
640 * about vram size near mc fb location */
641 u64 mc_vram_size;
642 u64 visible_vram_size;
643 u64 gtt_size;
644 u64 gtt_start;
645 u64 gtt_end;
646 u64 vram_start;
647 u64 vram_end;
648 unsigned vram_width;
649 u64 real_vram_size;
650 int vram_mtrr;
651 u64 gtt_base_align;
652 u64 mc_mask;
653 const struct firmware *fw; /* MC firmware */
654 uint32_t fw_version;
655 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800656 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400657};
658
659/*
660 * GPU doorbell structures, functions & helpers
661 */
662typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
663{
664 AMDGPU_DOORBELL_KIQ = 0x000,
665 AMDGPU_DOORBELL_HIQ = 0x001,
666 AMDGPU_DOORBELL_DIQ = 0x002,
667 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
668 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
669 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
670 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
671 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
672 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
673 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
674 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
675 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
676 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
677 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
678 AMDGPU_DOORBELL_IH = 0x1E8,
679 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
680 AMDGPU_DOORBELL_INVALID = 0xFFFF
681} AMDGPU_DOORBELL_ASSIGNMENT;
682
683struct amdgpu_doorbell {
684 /* doorbell mmio */
685 resource_size_t base;
686 resource_size_t size;
687 u32 __iomem *ptr;
688 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
689};
690
691void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
692 phys_addr_t *aperture_base,
693 size_t *aperture_size,
694 size_t *start_offset);
695
696/*
697 * IRQS.
698 */
699
700struct amdgpu_flip_work {
701 struct work_struct flip_work;
702 struct work_struct unpin_work;
703 struct amdgpu_device *adev;
704 int crtc_id;
705 uint64_t base;
706 struct drm_pending_vblank_event *event;
707 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200708 struct fence *excl;
709 unsigned shared_count;
710 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100711 struct fence_cb cb;
Alex Deucher97b2e202015-04-20 16:51:00 -0400712};
713
714
715/*
716 * CP & rings.
717 */
718
719struct amdgpu_ib {
720 struct amdgpu_sa_bo *sa_bo;
721 uint32_t length_dw;
722 uint64_t gpu_addr;
723 uint32_t *ptr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400724 struct amdgpu_user_fence *user;
725 struct amdgpu_vm *vm;
Christian König4ff37a82016-02-26 16:18:26 +0100726 unsigned vm_id;
727 uint64_t vm_pd_addr;
Christian König3cb485f2015-05-11 15:34:59 +0200728 struct amdgpu_ctx *ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400729 uint32_t gds_base, gds_size;
730 uint32_t gws_base, gws_size;
731 uint32_t oa_base, oa_size;
Jammy Zhoude807f82015-05-11 23:41:41 +0800732 uint32_t flags;
Christian König5430a3f2015-07-21 18:02:21 +0200733 /* resulting sequence number */
734 uint64_t sequence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400735};
736
737enum amdgpu_ring_type {
738 AMDGPU_RING_TYPE_GFX,
739 AMDGPU_RING_TYPE_COMPUTE,
740 AMDGPU_RING_TYPE_SDMA,
741 AMDGPU_RING_TYPE_UVD,
742 AMDGPU_RING_TYPE_VCE
743};
744
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800745extern struct amd_sched_backend_ops amdgpu_sched_ops;
746
Christian König50838c82016-02-03 13:44:52 +0100747int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
748 struct amdgpu_job **job);
Christian Königd71518b2016-02-01 12:20:25 +0100749int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
750 struct amdgpu_job **job);
Christian König50838c82016-02-03 13:44:52 +0100751void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100752int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100753 struct amd_sched_entity *entity, void *owner,
754 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800755
Alex Deucher97b2e202015-04-20 16:51:00 -0400756struct amdgpu_ring {
757 struct amdgpu_device *adev;
758 const struct amdgpu_ring_funcs *funcs;
759 struct amdgpu_fence_driver fence_drv;
Christian König4f839a22015-09-08 20:22:31 +0200760 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400761
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800762 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400763 struct amdgpu_bo *ring_obj;
764 volatile uint32_t *ring;
765 unsigned rptr_offs;
766 u64 next_rptr_gpu_addr;
767 volatile u32 *next_rptr_cpu_addr;
768 unsigned wptr;
769 unsigned wptr_old;
770 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100771 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400772 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400773 uint64_t gpu_addr;
774 uint32_t align_mask;
775 uint32_t ptr_mask;
776 bool ready;
777 u32 nop;
778 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400779 u32 me;
780 u32 pipe;
781 u32 queue;
782 struct amdgpu_bo *mqd_obj;
783 u32 doorbell_index;
784 bool use_doorbell;
785 unsigned wptr_offs;
786 unsigned next_rptr_offs;
787 unsigned fence_offs;
Christian König3cb485f2015-05-11 15:34:59 +0200788 struct amdgpu_ctx *current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400789 enum amdgpu_ring_type type;
790 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800791 unsigned cond_exe_offs;
792 u64 cond_exe_gpu_addr;
793 volatile u32 *cond_exe_cpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400794};
795
796/*
797 * VM
798 */
799
800/* maximum number of VMIDs */
801#define AMDGPU_NUM_VM 16
802
803/* number of entries in page table */
804#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
805
806/* PTBs (Page Table Blocks) need to be aligned to 32K */
807#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
808#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
809#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
810
811#define AMDGPU_PTE_VALID (1 << 0)
812#define AMDGPU_PTE_SYSTEM (1 << 1)
813#define AMDGPU_PTE_SNOOPED (1 << 2)
814
815/* VI only */
816#define AMDGPU_PTE_EXECUTABLE (1 << 4)
817
818#define AMDGPU_PTE_READABLE (1 << 5)
819#define AMDGPU_PTE_WRITEABLE (1 << 6)
820
821/* PTE (Page Table Entry) fragment field for different page sizes */
822#define AMDGPU_PTE_FRAG_4KB (0 << 7)
823#define AMDGPU_PTE_FRAG_64KB (4 << 7)
824#define AMDGPU_LOG2_PAGES_PER_FRAG 4
825
Christian Königd9c13152015-09-28 12:31:26 +0200826/* How to programm VM fault handling */
827#define AMDGPU_VM_FAULT_STOP_NEVER 0
828#define AMDGPU_VM_FAULT_STOP_FIRST 1
829#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
830
Alex Deucher97b2e202015-04-20 16:51:00 -0400831struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100832 struct amdgpu_bo_list_entry entry;
833 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400834};
835
836struct amdgpu_vm_id {
Christian König4ff37a82016-02-26 16:18:26 +0100837 struct amdgpu_vm_manager_id *mgr_id;
838 uint64_t pd_gpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400839 /* last flushed PD/PT update */
Christian König4ff37a82016-02-26 16:18:26 +0100840 struct fence *flushed_updates;
Alex Deucher97b2e202015-04-20 16:51:00 -0400841};
842
843struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100844 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400845 struct rb_root va;
846
Christian König7fc11952015-07-30 11:53:42 +0200847 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400848 spinlock_t status_lock;
849
850 /* BOs moved, but not yet updated in the PT */
851 struct list_head invalidated;
852
Christian König7fc11952015-07-30 11:53:42 +0200853 /* BOs cleared in the PT because of a move */
854 struct list_head cleared;
855
856 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400857 struct list_head freed;
858
859 /* contains the page directory */
860 struct amdgpu_bo *page_directory;
861 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200862 struct fence *page_directory_fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400863
864 /* array of page tables, one for each page directory entry */
865 struct amdgpu_vm_pt *page_tables;
866
867 /* for id and flush management per ring */
868 struct amdgpu_vm_id ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100869
jimqu81d75a32015-12-04 17:17:00 +0800870 /* protecting freed */
871 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100872
873 /* Scheduler entity for page table updates */
874 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -0400875};
876
Christian Königa9a78b32016-01-21 10:19:11 +0100877struct amdgpu_vm_manager_id {
878 struct list_head list;
879 struct fence *active;
880 atomic_long_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100881
882 uint32_t gds_base;
883 uint32_t gds_size;
884 uint32_t gws_base;
885 uint32_t gws_size;
886 uint32_t oa_base;
887 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100888};
Christian König8d0a7ce2015-11-03 20:58:50 +0100889
Christian Königa9a78b32016-01-21 10:19:11 +0100890struct amdgpu_vm_manager {
891 /* Handling of VMIDs */
892 struct mutex lock;
893 unsigned num_ids;
894 struct list_head ids_lru;
895 struct amdgpu_vm_manager_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100896
Christian König8b4fb002015-11-15 16:04:16 +0100897 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400898 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100899 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400900 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100901 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400902 /* vm pte handling */
903 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100904 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
905 unsigned vm_pte_num_rings;
906 atomic_t vm_pte_next_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400907};
908
Christian Königa9a78b32016-01-21 10:19:11 +0100909void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100910void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100911int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
912void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100913void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
914 struct list_head *validated,
915 struct amdgpu_bo_list_entry *entry);
Christian Königee1782c2015-12-11 21:01:23 +0100916void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100917void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
918 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100919int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100920 struct amdgpu_sync *sync, struct fence *fence,
921 unsigned *vm_id, uint64_t *vm_pd_addr);
Christian König8b4fb002015-11-15 16:04:16 +0100922void amdgpu_vm_flush(struct amdgpu_ring *ring,
Christian Königcffadc82016-03-01 13:34:49 +0100923 unsigned vm_id, uint64_t pd_addr,
924 uint32_t gds_base, uint32_t gds_size,
925 uint32_t gws_base, uint32_t gws_size,
926 uint32_t oa_base, uint32_t oa_size);
Christian König971fe9a92016-03-01 15:09:25 +0100927void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian Königb07c9d22015-11-30 13:26:07 +0100928uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
Christian König8b4fb002015-11-15 16:04:16 +0100929int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
930 struct amdgpu_vm *vm);
931int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
932 struct amdgpu_vm *vm);
933int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
934 struct amdgpu_sync *sync);
935int amdgpu_vm_bo_update(struct amdgpu_device *adev,
936 struct amdgpu_bo_va *bo_va,
937 struct ttm_mem_reg *mem);
938void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
939 struct amdgpu_bo *bo);
940struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
941 struct amdgpu_bo *bo);
942struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
943 struct amdgpu_vm *vm,
944 struct amdgpu_bo *bo);
945int amdgpu_vm_bo_map(struct amdgpu_device *adev,
946 struct amdgpu_bo_va *bo_va,
947 uint64_t addr, uint64_t offset,
948 uint64_t size, uint32_t flags);
949int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
950 struct amdgpu_bo_va *bo_va,
951 uint64_t addr);
952void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
953 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100954
Alex Deucher97b2e202015-04-20 16:51:00 -0400955/*
956 * context related structures
957 */
958
Christian König21c16bf2015-07-07 17:24:49 +0200959struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200960 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800961 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200962 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200963};
964
Alex Deucher97b2e202015-04-20 16:51:00 -0400965struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400966 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800967 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400968 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200969 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800970 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200971 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400972};
973
974struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400975 struct amdgpu_device *adev;
976 struct mutex lock;
977 /* protected by lock */
978 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400979};
980
Alex Deucher0b492a42015-08-16 22:48:26 -0400981struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
982int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
983
Christian König21c16bf2015-07-07 17:24:49 +0200984uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200985 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200986struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
987 struct amdgpu_ring *ring, uint64_t seq);
988
Alex Deucher0b492a42015-08-16 22:48:26 -0400989int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
990 struct drm_file *filp);
991
Christian Königefd4ccb2015-08-04 16:20:31 +0200992void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
993void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400994
Alex Deucher97b2e202015-04-20 16:51:00 -0400995/*
996 * file private structure
997 */
998
999struct amdgpu_fpriv {
1000 struct amdgpu_vm vm;
1001 struct mutex bo_list_lock;
1002 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001003 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001004};
1005
1006/*
1007 * residency list
1008 */
1009
1010struct amdgpu_bo_list {
1011 struct mutex lock;
1012 struct amdgpu_bo *gds_obj;
1013 struct amdgpu_bo *gws_obj;
1014 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001015 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001016 unsigned num_entries;
1017 struct amdgpu_bo_list_entry *array;
1018};
1019
1020struct amdgpu_bo_list *
1021amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001022void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1023 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001024void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1025void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1026
1027/*
1028 * GFX stuff
1029 */
1030#include "clearstate_defs.h"
1031
1032struct amdgpu_rlc {
1033 /* for power gating */
1034 struct amdgpu_bo *save_restore_obj;
1035 uint64_t save_restore_gpu_addr;
1036 volatile uint32_t *sr_ptr;
1037 const u32 *reg_list;
1038 u32 reg_list_size;
1039 /* for clear state */
1040 struct amdgpu_bo *clear_state_obj;
1041 uint64_t clear_state_gpu_addr;
1042 volatile uint32_t *cs_ptr;
1043 const struct cs_section_def *cs_data;
1044 u32 clear_state_size;
1045 /* for cp tables */
1046 struct amdgpu_bo *cp_table_obj;
1047 uint64_t cp_table_gpu_addr;
1048 volatile uint32_t *cp_table_ptr;
1049 u32 cp_table_size;
1050};
1051
1052struct amdgpu_mec {
1053 struct amdgpu_bo *hpd_eop_obj;
1054 u64 hpd_eop_gpu_addr;
1055 u32 num_pipe;
1056 u32 num_mec;
1057 u32 num_queue;
1058};
1059
1060/*
1061 * GPU scratch registers structures, functions & helpers
1062 */
1063struct amdgpu_scratch {
1064 unsigned num_reg;
1065 uint32_t reg_base;
1066 bool free[32];
1067 uint32_t reg[32];
1068};
1069
1070/*
1071 * GFX configurations
1072 */
1073struct amdgpu_gca_config {
1074 unsigned max_shader_engines;
1075 unsigned max_tile_pipes;
1076 unsigned max_cu_per_sh;
1077 unsigned max_sh_per_se;
1078 unsigned max_backends_per_se;
1079 unsigned max_texture_channel_caches;
1080 unsigned max_gprs;
1081 unsigned max_gs_threads;
1082 unsigned max_hw_contexts;
1083 unsigned sc_prim_fifo_size_frontend;
1084 unsigned sc_prim_fifo_size_backend;
1085 unsigned sc_hiz_tile_fifo_size;
1086 unsigned sc_earlyz_tile_fifo_size;
1087
1088 unsigned num_tile_pipes;
1089 unsigned backend_enable_mask;
1090 unsigned mem_max_burst_length_bytes;
1091 unsigned mem_row_size_in_kb;
1092 unsigned shader_engine_tile_size;
1093 unsigned num_gpus;
1094 unsigned multi_gpu_tile_size;
1095 unsigned mc_arb_ramcfg;
1096 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001097 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001098
1099 uint32_t tile_mode_array[32];
1100 uint32_t macrotile_mode_array[16];
1101};
1102
1103struct amdgpu_gfx {
1104 struct mutex gpu_clock_mutex;
1105 struct amdgpu_gca_config config;
1106 struct amdgpu_rlc rlc;
1107 struct amdgpu_mec mec;
1108 struct amdgpu_scratch scratch;
1109 const struct firmware *me_fw; /* ME firmware */
1110 uint32_t me_fw_version;
1111 const struct firmware *pfp_fw; /* PFP firmware */
1112 uint32_t pfp_fw_version;
1113 const struct firmware *ce_fw; /* CE firmware */
1114 uint32_t ce_fw_version;
1115 const struct firmware *rlc_fw; /* RLC firmware */
1116 uint32_t rlc_fw_version;
1117 const struct firmware *mec_fw; /* MEC firmware */
1118 uint32_t mec_fw_version;
1119 const struct firmware *mec2_fw; /* MEC2 firmware */
1120 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001121 uint32_t me_feature_version;
1122 uint32_t ce_feature_version;
1123 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001124 uint32_t rlc_feature_version;
1125 uint32_t mec_feature_version;
1126 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001127 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1128 unsigned num_gfx_rings;
1129 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1130 unsigned num_compute_rings;
1131 struct amdgpu_irq_src eop_irq;
1132 struct amdgpu_irq_src priv_reg_irq;
1133 struct amdgpu_irq_src priv_inst_irq;
1134 /* gfx status */
1135 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001136 /* ce ram size*/
1137 unsigned ce_ram_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001138};
1139
Christian Königb07c60c2016-01-31 12:29:04 +01001140int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001141 unsigned size, struct amdgpu_ib *ib);
Monk Liucc55c452016-03-17 10:47:07 +08001142void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001143int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001144 struct amdgpu_ib *ib, struct fence *last_vm_update,
Christian Königec72b802016-02-01 11:56:35 +01001145 struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001146int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1147void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1148int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001149int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001150void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001151void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001152void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001153void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001154unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1155 uint32_t **data);
1156int amdgpu_ring_restore(struct amdgpu_ring *ring,
1157 unsigned size, uint32_t *data);
1158int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1159 unsigned ring_size, u32 nop, u32 align_mask,
1160 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1161 enum amdgpu_ring_type ring_type);
1162void amdgpu_ring_fini(struct amdgpu_ring *ring);
1163
1164/*
1165 * CS.
1166 */
1167struct amdgpu_cs_chunk {
1168 uint32_t chunk_id;
1169 uint32_t length_dw;
1170 uint32_t *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001171};
1172
1173struct amdgpu_cs_parser {
1174 struct amdgpu_device *adev;
1175 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001176 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001177
Alex Deucher97b2e202015-04-20 16:51:00 -04001178 /* chunks */
1179 unsigned nchunks;
1180 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001181
Christian König50838c82016-02-03 13:44:52 +01001182 /* scheduler job object */
1183 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001184
Christian Königc3cca412015-12-15 14:41:33 +01001185 /* buffer objects */
1186 struct ww_acquire_ctx ticket;
1187 struct amdgpu_bo_list *bo_list;
1188 struct amdgpu_bo_list_entry vm_pd;
1189 struct list_head validated;
1190 struct fence *fence;
1191 uint64_t bytes_moved_threshold;
1192 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001193
1194 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001195 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001196};
1197
Chunming Zhoubb977d32015-08-18 15:16:40 +08001198struct amdgpu_job {
1199 struct amd_sched_job base;
1200 struct amdgpu_device *adev;
Christian Königb07c60c2016-01-31 12:29:04 +01001201 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001202 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001203 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001204 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001205 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001206 void *owner;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001207 struct amdgpu_user_fence uf;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001208};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001209#define to_amdgpu_job(sched_job) \
1210 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001211
Christian König7270f832016-01-31 11:00:41 +01001212static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1213 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001214{
Christian König50838c82016-02-03 13:44:52 +01001215 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001216}
1217
Christian König7270f832016-01-31 11:00:41 +01001218static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1219 uint32_t ib_idx, int idx,
1220 uint32_t value)
1221{
Christian König50838c82016-02-03 13:44:52 +01001222 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001223}
1224
Alex Deucher97b2e202015-04-20 16:51:00 -04001225/*
1226 * Writeback
1227 */
1228#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1229
1230struct amdgpu_wb {
1231 struct amdgpu_bo *wb_obj;
1232 volatile uint32_t *wb;
1233 uint64_t gpu_addr;
1234 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1235 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1236};
1237
1238int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1239void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1240
Alex Deucher97b2e202015-04-20 16:51:00 -04001241
Alex Deucher97b2e202015-04-20 16:51:00 -04001242
1243enum amdgpu_int_thermal_type {
1244 THERMAL_TYPE_NONE,
1245 THERMAL_TYPE_EXTERNAL,
1246 THERMAL_TYPE_EXTERNAL_GPIO,
1247 THERMAL_TYPE_RV6XX,
1248 THERMAL_TYPE_RV770,
1249 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1250 THERMAL_TYPE_EVERGREEN,
1251 THERMAL_TYPE_SUMO,
1252 THERMAL_TYPE_NI,
1253 THERMAL_TYPE_SI,
1254 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1255 THERMAL_TYPE_CI,
1256 THERMAL_TYPE_KV,
1257};
1258
1259enum amdgpu_dpm_auto_throttle_src {
1260 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1261 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1262};
1263
1264enum amdgpu_dpm_event_src {
1265 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1266 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1267 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1268 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1269 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1270};
1271
1272#define AMDGPU_MAX_VCE_LEVELS 6
1273
1274enum amdgpu_vce_level {
1275 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1276 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1277 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1278 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1279 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1280 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1281};
1282
1283struct amdgpu_ps {
1284 u32 caps; /* vbios flags */
1285 u32 class; /* vbios flags */
1286 u32 class2; /* vbios flags */
1287 /* UVD clocks */
1288 u32 vclk;
1289 u32 dclk;
1290 /* VCE clocks */
1291 u32 evclk;
1292 u32 ecclk;
1293 bool vce_active;
1294 enum amdgpu_vce_level vce_level;
1295 /* asic priv */
1296 void *ps_priv;
1297};
1298
1299struct amdgpu_dpm_thermal {
1300 /* thermal interrupt work */
1301 struct work_struct work;
1302 /* low temperature threshold */
1303 int min_temp;
1304 /* high temperature threshold */
1305 int max_temp;
1306 /* was last interrupt low to high or high to low */
1307 bool high_to_low;
1308 /* interrupt source */
1309 struct amdgpu_irq_src irq;
1310};
1311
1312enum amdgpu_clk_action
1313{
1314 AMDGPU_SCLK_UP = 1,
1315 AMDGPU_SCLK_DOWN
1316};
1317
1318struct amdgpu_blacklist_clocks
1319{
1320 u32 sclk;
1321 u32 mclk;
1322 enum amdgpu_clk_action action;
1323};
1324
1325struct amdgpu_clock_and_voltage_limits {
1326 u32 sclk;
1327 u32 mclk;
1328 u16 vddc;
1329 u16 vddci;
1330};
1331
1332struct amdgpu_clock_array {
1333 u32 count;
1334 u32 *values;
1335};
1336
1337struct amdgpu_clock_voltage_dependency_entry {
1338 u32 clk;
1339 u16 v;
1340};
1341
1342struct amdgpu_clock_voltage_dependency_table {
1343 u32 count;
1344 struct amdgpu_clock_voltage_dependency_entry *entries;
1345};
1346
1347union amdgpu_cac_leakage_entry {
1348 struct {
1349 u16 vddc;
1350 u32 leakage;
1351 };
1352 struct {
1353 u16 vddc1;
1354 u16 vddc2;
1355 u16 vddc3;
1356 };
1357};
1358
1359struct amdgpu_cac_leakage_table {
1360 u32 count;
1361 union amdgpu_cac_leakage_entry *entries;
1362};
1363
1364struct amdgpu_phase_shedding_limits_entry {
1365 u16 voltage;
1366 u32 sclk;
1367 u32 mclk;
1368};
1369
1370struct amdgpu_phase_shedding_limits_table {
1371 u32 count;
1372 struct amdgpu_phase_shedding_limits_entry *entries;
1373};
1374
1375struct amdgpu_uvd_clock_voltage_dependency_entry {
1376 u32 vclk;
1377 u32 dclk;
1378 u16 v;
1379};
1380
1381struct amdgpu_uvd_clock_voltage_dependency_table {
1382 u8 count;
1383 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1384};
1385
1386struct amdgpu_vce_clock_voltage_dependency_entry {
1387 u32 ecclk;
1388 u32 evclk;
1389 u16 v;
1390};
1391
1392struct amdgpu_vce_clock_voltage_dependency_table {
1393 u8 count;
1394 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1395};
1396
1397struct amdgpu_ppm_table {
1398 u8 ppm_design;
1399 u16 cpu_core_number;
1400 u32 platform_tdp;
1401 u32 small_ac_platform_tdp;
1402 u32 platform_tdc;
1403 u32 small_ac_platform_tdc;
1404 u32 apu_tdp;
1405 u32 dgpu_tdp;
1406 u32 dgpu_ulv_power;
1407 u32 tj_max;
1408};
1409
1410struct amdgpu_cac_tdp_table {
1411 u16 tdp;
1412 u16 configurable_tdp;
1413 u16 tdc;
1414 u16 battery_power_limit;
1415 u16 small_power_limit;
1416 u16 low_cac_leakage;
1417 u16 high_cac_leakage;
1418 u16 maximum_power_delivery_limit;
1419};
1420
1421struct amdgpu_dpm_dynamic_state {
1422 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1423 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1424 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1425 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1426 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1427 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1428 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1429 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1430 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1431 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1432 struct amdgpu_clock_array valid_sclk_values;
1433 struct amdgpu_clock_array valid_mclk_values;
1434 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1435 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1436 u32 mclk_sclk_ratio;
1437 u32 sclk_mclk_delta;
1438 u16 vddc_vddci_delta;
1439 u16 min_vddc_for_pcie_gen2;
1440 struct amdgpu_cac_leakage_table cac_leakage_table;
1441 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1442 struct amdgpu_ppm_table *ppm_table;
1443 struct amdgpu_cac_tdp_table *cac_tdp_table;
1444};
1445
1446struct amdgpu_dpm_fan {
1447 u16 t_min;
1448 u16 t_med;
1449 u16 t_high;
1450 u16 pwm_min;
1451 u16 pwm_med;
1452 u16 pwm_high;
1453 u8 t_hyst;
1454 u32 cycle_delay;
1455 u16 t_max;
1456 u8 control_mode;
1457 u16 default_max_fan_pwm;
1458 u16 default_fan_output_sensitivity;
1459 u16 fan_output_sensitivity;
1460 bool ucode_fan_control;
1461};
1462
1463enum amdgpu_pcie_gen {
1464 AMDGPU_PCIE_GEN1 = 0,
1465 AMDGPU_PCIE_GEN2 = 1,
1466 AMDGPU_PCIE_GEN3 = 2,
1467 AMDGPU_PCIE_GEN_INVALID = 0xffff
1468};
1469
1470enum amdgpu_dpm_forced_level {
1471 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1472 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1473 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001474 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001475};
1476
1477struct amdgpu_vce_state {
1478 /* vce clocks */
1479 u32 evclk;
1480 u32 ecclk;
1481 /* gpu clocks */
1482 u32 sclk;
1483 u32 mclk;
1484 u8 clk_idx;
1485 u8 pstate;
1486};
1487
1488struct amdgpu_dpm_funcs {
1489 int (*get_temperature)(struct amdgpu_device *adev);
1490 int (*pre_set_power_state)(struct amdgpu_device *adev);
1491 int (*set_power_state)(struct amdgpu_device *adev);
1492 void (*post_set_power_state)(struct amdgpu_device *adev);
1493 void (*display_configuration_changed)(struct amdgpu_device *adev);
1494 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1495 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1496 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1497 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1498 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1499 bool (*vblank_too_short)(struct amdgpu_device *adev);
1500 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001501 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001502 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1503 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1504 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1505 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1506 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1507};
1508
1509struct amdgpu_dpm {
1510 struct amdgpu_ps *ps;
1511 /* number of valid power states */
1512 int num_ps;
1513 /* current power state that is active */
1514 struct amdgpu_ps *current_ps;
1515 /* requested power state */
1516 struct amdgpu_ps *requested_ps;
1517 /* boot up power state */
1518 struct amdgpu_ps *boot_ps;
1519 /* default uvd power state */
1520 struct amdgpu_ps *uvd_ps;
1521 /* vce requirements */
1522 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1523 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001524 enum amd_pm_state_type state;
1525 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001526 u32 platform_caps;
1527 u32 voltage_response_time;
1528 u32 backbias_response_time;
1529 void *priv;
1530 u32 new_active_crtcs;
1531 int new_active_crtc_count;
1532 u32 current_active_crtcs;
1533 int current_active_crtc_count;
1534 struct amdgpu_dpm_dynamic_state dyn_state;
1535 struct amdgpu_dpm_fan fan;
1536 u32 tdp_limit;
1537 u32 near_tdp_limit;
1538 u32 near_tdp_limit_adjusted;
1539 u32 sq_ramping_threshold;
1540 u32 cac_leakage;
1541 u16 tdp_od_limit;
1542 u32 tdp_adjustment;
1543 u16 load_line_slope;
1544 bool power_control;
1545 bool ac_power;
1546 /* special states active */
1547 bool thermal_active;
1548 bool uvd_active;
1549 bool vce_active;
1550 /* thermal handling */
1551 struct amdgpu_dpm_thermal thermal;
1552 /* forced levels */
1553 enum amdgpu_dpm_forced_level forced_level;
1554};
1555
1556struct amdgpu_pm {
1557 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001558 u32 current_sclk;
1559 u32 current_mclk;
1560 u32 default_sclk;
1561 u32 default_mclk;
1562 struct amdgpu_i2c_chan *i2c_bus;
1563 /* internal thermal controller on rv6xx+ */
1564 enum amdgpu_int_thermal_type int_thermal_type;
1565 struct device *int_hwmon_dev;
1566 /* fan control parameters */
1567 bool no_fan;
1568 u8 fan_pulses_per_revolution;
1569 u8 fan_min_rpm;
1570 u8 fan_max_rpm;
1571 /* dpm */
1572 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001573 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001574 struct amdgpu_dpm dpm;
1575 const struct firmware *fw; /* SMC firmware */
1576 uint32_t fw_version;
1577 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001578 uint32_t pcie_gen_mask;
1579 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001580 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001581};
1582
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001583void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1584
Alex Deucher97b2e202015-04-20 16:51:00 -04001585/*
1586 * UVD
1587 */
1588#define AMDGPU_MAX_UVD_HANDLES 10
1589#define AMDGPU_UVD_STACK_SIZE (1024*1024)
1590#define AMDGPU_UVD_HEAP_SIZE (1024*1024)
1591#define AMDGPU_UVD_FIRMWARE_OFFSET 256
1592
1593struct amdgpu_uvd {
1594 struct amdgpu_bo *vcpu_bo;
1595 void *cpu_addr;
1596 uint64_t gpu_addr;
Leo Liu3f99dd82016-04-01 10:36:06 -04001597 void *saved_bo;
Alex Deucher97b2e202015-04-20 16:51:00 -04001598 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1599 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1600 struct delayed_work idle_work;
1601 const struct firmware *fw; /* UVD firmware */
1602 struct amdgpu_ring ring;
1603 struct amdgpu_irq_src irq;
1604 bool address_64_bit;
Christian Königead833e2016-02-10 14:35:19 +01001605 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001606};
1607
1608/*
1609 * VCE
1610 */
1611#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001612#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1613
Alex Deucher6a585772015-07-10 14:16:24 -04001614#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1615#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1616
Alex Deucher97b2e202015-04-20 16:51:00 -04001617struct amdgpu_vce {
1618 struct amdgpu_bo *vcpu_bo;
1619 uint64_t gpu_addr;
1620 unsigned fw_version;
1621 unsigned fb_version;
1622 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1623 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001624 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001625 struct delayed_work idle_work;
1626 const struct firmware *fw; /* VCE firmware */
1627 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1628 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001629 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001630 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001631};
1632
1633/*
1634 * SDMA
1635 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001636struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001637 /* SDMA firmware */
1638 const struct firmware *fw;
1639 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001640 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001641
1642 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001643 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001644};
1645
Alex Deucherc113ea12015-10-08 16:30:37 -04001646struct amdgpu_sdma {
1647 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1648 struct amdgpu_irq_src trap_irq;
1649 struct amdgpu_irq_src illegal_inst_irq;
1650 int num_instances;
1651};
1652
Alex Deucher97b2e202015-04-20 16:51:00 -04001653/*
1654 * Firmware
1655 */
1656struct amdgpu_firmware {
1657 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1658 bool smu_load;
1659 struct amdgpu_bo *fw_buf;
1660 unsigned int fw_size;
1661};
1662
1663/*
1664 * Benchmarking
1665 */
1666void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1667
1668
1669/*
1670 * Testing
1671 */
1672void amdgpu_test_moves(struct amdgpu_device *adev);
1673void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1674 struct amdgpu_ring *cpA,
1675 struct amdgpu_ring *cpB);
1676void amdgpu_test_syncing(struct amdgpu_device *adev);
1677
1678/*
1679 * MMU Notifier
1680 */
1681#if defined(CONFIG_MMU_NOTIFIER)
1682int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1683void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1684#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001685static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001686{
1687 return -ENODEV;
1688}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001689static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001690#endif
1691
1692/*
1693 * Debugfs
1694 */
1695struct amdgpu_debugfs {
1696 struct drm_info_list *files;
1697 unsigned num_files;
1698};
1699
1700int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
1701 struct drm_info_list *files,
1702 unsigned nfiles);
1703int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1704
1705#if defined(CONFIG_DEBUG_FS)
1706int amdgpu_debugfs_init(struct drm_minor *minor);
1707void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1708#endif
1709
1710/*
1711 * amdgpu smumgr functions
1712 */
1713struct amdgpu_smumgr_funcs {
1714 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1715 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1716 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1717};
1718
1719/*
1720 * amdgpu smumgr
1721 */
1722struct amdgpu_smumgr {
1723 struct amdgpu_bo *toc_buf;
1724 struct amdgpu_bo *smu_buf;
1725 /* asic priv smu data */
1726 void *priv;
1727 spinlock_t smu_lock;
1728 /* smumgr functions */
1729 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1730 /* ucode loading complete flag */
1731 uint32_t fw_flags;
1732};
1733
1734/*
1735 * ASIC specific register table accessible by UMD
1736 */
1737struct amdgpu_allowed_register_entry {
1738 uint32_t reg_offset;
1739 bool untouched;
1740 bool grbm_indexed;
1741};
1742
1743struct amdgpu_cu_info {
1744 uint32_t number; /* total active CU number */
1745 uint32_t ao_cu_mask;
1746 uint32_t bitmap[4][4];
1747};
1748
1749
1750/*
1751 * ASIC specific functions.
1752 */
1753struct amdgpu_asic_funcs {
1754 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001755 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1756 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001757 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1758 u32 sh_num, u32 reg_offset, u32 *value);
1759 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1760 int (*reset)(struct amdgpu_device *adev);
1761 /* wait for mc_idle */
1762 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1763 /* get the reference clock */
1764 u32 (*get_xclk)(struct amdgpu_device *adev);
1765 /* get the gpu clock counter */
1766 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
1767 int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
1768 /* MM block clocks */
1769 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1770 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1771};
1772
1773/*
1774 * IOCTL.
1775 */
1776int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1777 struct drm_file *filp);
1778int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1779 struct drm_file *filp);
1780
1781int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1782 struct drm_file *filp);
1783int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1784 struct drm_file *filp);
1785int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1786 struct drm_file *filp);
1787int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1788 struct drm_file *filp);
1789int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1790 struct drm_file *filp);
1791int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1792 struct drm_file *filp);
1793int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1794int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1795
1796int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1797 struct drm_file *filp);
1798
1799/* VRAM scratch page for HDP bug, default vram page */
1800struct amdgpu_vram_scratch {
1801 struct amdgpu_bo *robj;
1802 volatile uint32_t *ptr;
1803 u64 gpu_addr;
1804};
1805
1806/*
1807 * ACPI
1808 */
1809struct amdgpu_atif_notification_cfg {
1810 bool enabled;
1811 int command_code;
1812};
1813
1814struct amdgpu_atif_notifications {
1815 bool display_switch;
1816 bool expansion_mode_change;
1817 bool thermal_state;
1818 bool forced_power_state;
1819 bool system_power_state;
1820 bool display_conf_change;
1821 bool px_gfx_switch;
1822 bool brightness_change;
1823 bool dgpu_display_event;
1824};
1825
1826struct amdgpu_atif_functions {
1827 bool system_params;
1828 bool sbios_requests;
1829 bool select_active_disp;
1830 bool lid_state;
1831 bool get_tv_standard;
1832 bool set_tv_standard;
1833 bool get_panel_expansion_mode;
1834 bool set_panel_expansion_mode;
1835 bool temperature_change;
1836 bool graphics_device_types;
1837};
1838
1839struct amdgpu_atif {
1840 struct amdgpu_atif_notifications notifications;
1841 struct amdgpu_atif_functions functions;
1842 struct amdgpu_atif_notification_cfg notification_cfg;
1843 struct amdgpu_encoder *encoder_for_bl;
1844};
1845
1846struct amdgpu_atcs_functions {
1847 bool get_ext_state;
1848 bool pcie_perf_req;
1849 bool pcie_dev_rdy;
1850 bool pcie_bus_width;
1851};
1852
1853struct amdgpu_atcs {
1854 struct amdgpu_atcs_functions functions;
1855};
1856
Alex Deucher97b2e202015-04-20 16:51:00 -04001857/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001858 * CGS
1859 */
1860void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1861void amdgpu_cgs_destroy_device(void *cgs_device);
1862
1863
1864/*
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001865 * CGS
1866 */
1867void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1868void amdgpu_cgs_destroy_device(void *cgs_device);
1869
1870
Alex Deucher7e471e62016-02-01 11:13:04 -05001871/* GPU virtualization */
1872struct amdgpu_virtualization {
1873 bool supports_sr_iov;
1874};
1875
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001876/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001877 * Core structure, functions and helpers.
1878 */
1879typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1880typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1881
1882typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1883typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1884
Alex Deucher8faf0e02015-07-28 11:50:31 -04001885struct amdgpu_ip_block_status {
1886 bool valid;
1887 bool sw;
1888 bool hw;
1889};
1890
Alex Deucher97b2e202015-04-20 16:51:00 -04001891struct amdgpu_device {
1892 struct device *dev;
1893 struct drm_device *ddev;
1894 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001895
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001896#ifdef CONFIG_DRM_AMD_ACP
1897 struct amdgpu_acp acp;
1898#endif
1899
Alex Deucher97b2e202015-04-20 16:51:00 -04001900 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001901 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001902 uint32_t family;
1903 uint32_t rev_id;
1904 uint32_t external_rev_id;
1905 unsigned long flags;
1906 int usec_timeout;
1907 const struct amdgpu_asic_funcs *asic_funcs;
1908 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001909 bool need_dma32;
1910 bool accel_working;
Alex Deucher97b2e202015-04-20 16:51:00 -04001911 struct work_struct reset_work;
1912 struct notifier_block acpi_nb;
1913 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1914 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1915 unsigned debugfs_count;
1916#if defined(CONFIG_DEBUG_FS)
1917 struct dentry *debugfs_regs;
1918#endif
1919 struct amdgpu_atif atif;
1920 struct amdgpu_atcs atcs;
1921 struct mutex srbm_mutex;
1922 /* GRBM index mutex. Protects concurrent access to GRBM index */
1923 struct mutex grbm_idx_mutex;
1924 struct dev_pm_domain vga_pm_domain;
1925 bool have_disp_power_ref;
1926
1927 /* BIOS */
1928 uint8_t *bios;
1929 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001930 struct amdgpu_bo *stollen_vga_memory;
1931 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1932
1933 /* Register/doorbell mmio */
1934 resource_size_t rmmio_base;
1935 resource_size_t rmmio_size;
1936 void __iomem *rmmio;
1937 /* protects concurrent MM_INDEX/DATA based register access */
1938 spinlock_t mmio_idx_lock;
1939 /* protects concurrent SMC based register access */
1940 spinlock_t smc_idx_lock;
1941 amdgpu_rreg_t smc_rreg;
1942 amdgpu_wreg_t smc_wreg;
1943 /* protects concurrent PCIE register access */
1944 spinlock_t pcie_idx_lock;
1945 amdgpu_rreg_t pcie_rreg;
1946 amdgpu_wreg_t pcie_wreg;
1947 /* protects concurrent UVD register access */
1948 spinlock_t uvd_ctx_idx_lock;
1949 amdgpu_rreg_t uvd_ctx_rreg;
1950 amdgpu_wreg_t uvd_ctx_wreg;
1951 /* protects concurrent DIDT register access */
1952 spinlock_t didt_idx_lock;
1953 amdgpu_rreg_t didt_rreg;
1954 amdgpu_wreg_t didt_wreg;
1955 /* protects concurrent ENDPOINT (audio) register access */
1956 spinlock_t audio_endpt_idx_lock;
1957 amdgpu_block_rreg_t audio_endpt_rreg;
1958 amdgpu_block_wreg_t audio_endpt_wreg;
1959 void __iomem *rio_mem;
1960 resource_size_t rio_mem_size;
1961 struct amdgpu_doorbell doorbell;
1962
1963 /* clock/pll info */
1964 struct amdgpu_clock clock;
1965
1966 /* MC */
1967 struct amdgpu_mc mc;
1968 struct amdgpu_gart gart;
1969 struct amdgpu_dummy_page dummy_page;
1970 struct amdgpu_vm_manager vm_manager;
1971
1972 /* memory management */
1973 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04001974 struct amdgpu_vram_scratch vram_scratch;
1975 struct amdgpu_wb wb;
1976 atomic64_t vram_usage;
1977 atomic64_t vram_vis_usage;
1978 atomic64_t gtt_usage;
1979 atomic64_t num_bytes_moved;
Marek Olšákd94aed52015-05-05 21:13:49 +02001980 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04001981
1982 /* display */
1983 struct amdgpu_mode_info mode_info;
1984 struct work_struct hotplug_work;
1985 struct amdgpu_irq_src crtc_irq;
1986 struct amdgpu_irq_src pageflip_irq;
1987 struct amdgpu_irq_src hpd_irq;
1988
1989 /* rings */
Alex Deucher97b2e202015-04-20 16:51:00 -04001990 unsigned fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04001991 unsigned num_rings;
1992 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1993 bool ib_pool_ready;
1994 struct amdgpu_sa_manager ring_tmp_bo;
1995
1996 /* interrupts */
1997 struct amdgpu_irq irq;
1998
Alex Deucher1f7371b2015-12-02 17:46:21 -05001999 /* powerplay */
2000 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002001 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002002 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002003
Alex Deucher97b2e202015-04-20 16:51:00 -04002004 /* dpm */
2005 struct amdgpu_pm pm;
2006 u32 cg_flags;
2007 u32 pg_flags;
2008
2009 /* amdgpu smumgr */
2010 struct amdgpu_smumgr smu;
2011
2012 /* gfx */
2013 struct amdgpu_gfx gfx;
2014
2015 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002016 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002017
2018 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002019 struct amdgpu_uvd uvd;
2020
2021 /* vce */
2022 struct amdgpu_vce vce;
2023
2024 /* firmwares */
2025 struct amdgpu_firmware firmware;
2026
2027 /* GDS */
2028 struct amdgpu_gds gds;
2029
2030 const struct amdgpu_ip_block_version *ip_blocks;
2031 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002032 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002033 struct mutex mn_lock;
2034 DECLARE_HASHTABLE(mn_hash, 7);
2035
2036 /* tracking pinned memory */
2037 u64 vram_pin_size;
2038 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002039
2040 /* amdkfd interface */
2041 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002042
Alex Deucher7e471e62016-02-01 11:13:04 -05002043 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002044};
2045
2046bool amdgpu_device_is_px(struct drm_device *dev);
2047int amdgpu_device_init(struct amdgpu_device *adev,
2048 struct drm_device *ddev,
2049 struct pci_dev *pdev,
2050 uint32_t flags);
2051void amdgpu_device_fini(struct amdgpu_device *adev);
2052int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2053
2054uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2055 bool always_indirect);
2056void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2057 bool always_indirect);
2058u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2059void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2060
2061u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2062void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2063
2064/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002065 * Registers read & write functions.
2066 */
2067#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2068#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2069#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2070#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2071#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2072#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2073#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2074#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2075#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2076#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2077#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2078#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2079#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2080#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2081#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2082#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2083#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2084#define WREG32_P(reg, val, mask) \
2085 do { \
2086 uint32_t tmp_ = RREG32(reg); \
2087 tmp_ &= (mask); \
2088 tmp_ |= ((val) & ~(mask)); \
2089 WREG32(reg, tmp_); \
2090 } while (0)
2091#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2092#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2093#define WREG32_PLL_P(reg, val, mask) \
2094 do { \
2095 uint32_t tmp_ = RREG32_PLL(reg); \
2096 tmp_ &= (mask); \
2097 tmp_ |= ((val) & ~(mask)); \
2098 WREG32_PLL(reg, tmp_); \
2099 } while (0)
2100#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2101#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2102#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2103
2104#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2105#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2106
2107#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2108#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2109
2110#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2111 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2112 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2113
2114#define REG_GET_FIELD(value, reg, field) \
2115 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2116
2117/*
2118 * BIOS helpers.
2119 */
2120#define RBIOS8(i) (adev->bios[i])
2121#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2122#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2123
2124/*
2125 * RING helpers.
2126 */
2127static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2128{
2129 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002130 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002131 ring->ring[ring->wptr++] = v;
2132 ring->wptr &= ring->ptr_mask;
2133 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002134}
2135
Alex Deucherc113ea12015-10-08 16:30:37 -04002136static inline struct amdgpu_sdma_instance *
2137amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002138{
2139 struct amdgpu_device *adev = ring->adev;
2140 int i;
2141
Alex Deucherc113ea12015-10-08 16:30:37 -04002142 for (i = 0; i < adev->sdma.num_instances; i++)
2143 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002144 break;
2145
2146 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002147 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002148 else
2149 return NULL;
2150}
2151
Alex Deucher97b2e202015-04-20 16:51:00 -04002152/*
2153 * ASICs macro.
2154 */
2155#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2156#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
2157#define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
2158#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2159#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2160#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2161#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2162#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002163#define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
Alex Deucher97b2e202015-04-20 16:51:00 -04002164#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
2165#define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
2166#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2167#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2168#define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Christian Königb07c9d22015-11-30 13:26:07 +01002169#define amdgpu_vm_write_pte(adev, ib, pa, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pa), (pe), (addr), (count), (incr), (flags)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002170#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)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002171#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2172#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2173#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002174#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2175#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2176#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2177#define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
Christian Königb8c7b392016-03-01 15:42:52 +01002178#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002179#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002180#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002181#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))
Christian Königd2edb072015-05-11 14:10:34 +02002182#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002183#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002184#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002185#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2186#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2187#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2188#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2189#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2190#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2191#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2192#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2193#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2194#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2195#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2196#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2197#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2198#define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
2199#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2200#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2201#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))
2202#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2203#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002204#define amdgpu_emit_copy_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b))
Chunming Zhou6e7a3842015-08-27 13:46:09 +08002205#define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
Alex Deucher97b2e202015-04-20 16:51:00 -04002206#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2207#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2208#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2209#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002210#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002211#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002212#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Rex Zhu3af76f22015-10-15 17:23:43 +08002213
2214#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002215 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002216 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002217 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002218
2219#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002220 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002221 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002222 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002223
2224#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002225 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002226 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002227 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002228
2229#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002230 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002231 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002232 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002233
2234#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002235 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002236 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002237 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002238
Rex Zhu1b5708f2015-11-10 18:25:24 -05002239#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002240 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002241 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002242 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002243
2244#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002245 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002246 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002247 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002248
2249
2250#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002251 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002252 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002253 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002254
2255#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002256 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002257 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002258 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002259
2260#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002261 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002262 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002263 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002264
2265#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002266 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002267 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002268 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002269
2270#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002271 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002272
2273#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002274 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002275
Eric Huangf3898ea2015-12-11 16:24:34 -05002276#define amdgpu_dpm_get_pp_num_states(adev, data) \
2277 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2278
2279#define amdgpu_dpm_get_pp_table(adev, table) \
2280 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2281
2282#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2283 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2284
2285#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2286 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2287
2288#define amdgpu_dpm_force_clock_level(adev, type, level) \
2289 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2290
Jammy Zhoue61710c2015-11-10 18:31:08 -05002291#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002292 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002293
2294#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2295
2296/* Common functions */
2297int amdgpu_gpu_reset(struct amdgpu_device *adev);
2298void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2299bool amdgpu_card_posted(struct amdgpu_device *adev);
2300void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002301
Alex Deucher97b2e202015-04-20 16:51:00 -04002302int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2303int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2304 u32 ip_instance, u32 ring,
2305 struct amdgpu_ring **out_ring);
2306void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2307bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002308int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002309int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2310 uint32_t flags);
2311bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002312struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002313bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2314 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002315bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2316 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002317bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2318uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2319 struct ttm_mem_reg *mem);
2320void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2321void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2322void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2323void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2324 const u32 *registers,
2325 const u32 array_size);
2326
2327bool amdgpu_device_is_px(struct drm_device *dev);
2328/* atpx handler */
2329#if defined(CONFIG_VGA_SWITCHEROO)
2330void amdgpu_register_atpx_handler(void);
2331void amdgpu_unregister_atpx_handler(void);
2332#else
2333static inline void amdgpu_register_atpx_handler(void) {}
2334static inline void amdgpu_unregister_atpx_handler(void) {}
2335#endif
2336
2337/*
2338 * KMS
2339 */
2340extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2341extern int amdgpu_max_kms_ioctl;
2342
2343int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2344int amdgpu_driver_unload_kms(struct drm_device *dev);
2345void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2346int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2347void amdgpu_driver_postclose_kms(struct drm_device *dev,
2348 struct drm_file *file_priv);
2349void amdgpu_driver_preclose_kms(struct drm_device *dev,
2350 struct drm_file *file_priv);
2351int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2352int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002353u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2354int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2355void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2356int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002357 int *max_error,
2358 struct timeval *vblank_time,
2359 unsigned flags);
2360long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2361 unsigned long arg);
2362
2363/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002364 * functions used by amdgpu_encoder.c
2365 */
2366struct amdgpu_afmt_acr {
2367 u32 clock;
2368
2369 int n_32khz;
2370 int cts_32khz;
2371
2372 int n_44_1khz;
2373 int cts_44_1khz;
2374
2375 int n_48khz;
2376 int cts_48khz;
2377
2378};
2379
2380struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2381
2382/* amdgpu_acpi.c */
2383#if defined(CONFIG_ACPI)
2384int amdgpu_acpi_init(struct amdgpu_device *adev);
2385void amdgpu_acpi_fini(struct amdgpu_device *adev);
2386bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2387int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2388 u8 perf_req, bool advertise);
2389int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2390#else
2391static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2392static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2393#endif
2394
2395struct amdgpu_bo_va_mapping *
2396amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2397 uint64_t addr, struct amdgpu_bo **bo);
2398
2399#include "amdgpu_object.h"
2400
2401#endif