blob: 04696ad2720f849ff42da4c50328309f5a2cbb31 [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;
Huang Rui6bb6b292016-05-24 13:47:05 +080088extern int amdgpu_powercontainment;
Alex Deuchercd474ba2016-02-04 10:21:23 -050089extern unsigned amdgpu_pcie_gen_cap;
90extern unsigned amdgpu_pcie_lane_cap;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +020091extern unsigned amdgpu_cg_mask;
92extern unsigned amdgpu_pg_mask;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +020093extern char *amdgpu_disable_cu;
Alex Deucher97b2e202015-04-20 16:51:00 -040094
Chunming Zhou4b559c92015-07-21 15:53:04 +080095#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -040096#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
97#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
98/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
99#define AMDGPU_IB_POOL_SIZE 16
100#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
101#define AMDGPUFB_CONN_LIMIT 4
102#define AMDGPU_BIOS_NUM_SCRATCH 8
103
Alex Deucher97b2e202015-04-20 16:51:00 -0400104/* max number of rings */
105#define AMDGPU_MAX_RINGS 16
106#define AMDGPU_MAX_GFX_RINGS 1
107#define AMDGPU_MAX_COMPUTE_RINGS 8
108#define AMDGPU_MAX_VCE_RINGS 2
109
Jammy Zhou36f523a2015-09-01 12:54:27 +0800110/* max number of IP instances */
111#define AMDGPU_MAX_SDMA_INSTANCES 2
112
Alex Deucher97b2e202015-04-20 16:51:00 -0400113/* hardcode that limit for now */
114#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
115
116/* hard reset data */
117#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
118
119/* reset flags */
120#define AMDGPU_RESET_GFX (1 << 0)
121#define AMDGPU_RESET_COMPUTE (1 << 1)
122#define AMDGPU_RESET_DMA (1 << 2)
123#define AMDGPU_RESET_CP (1 << 3)
124#define AMDGPU_RESET_GRBM (1 << 4)
125#define AMDGPU_RESET_DMA1 (1 << 5)
126#define AMDGPU_RESET_RLC (1 << 6)
127#define AMDGPU_RESET_SEM (1 << 7)
128#define AMDGPU_RESET_IH (1 << 8)
129#define AMDGPU_RESET_VMC (1 << 9)
130#define AMDGPU_RESET_MC (1 << 10)
131#define AMDGPU_RESET_DISPLAY (1 << 11)
132#define AMDGPU_RESET_UVD (1 << 12)
133#define AMDGPU_RESET_VCE (1 << 13)
134#define AMDGPU_RESET_VCE1 (1 << 14)
135
Alex Deucher97b2e202015-04-20 16:51:00 -0400136/* GFX current status */
137#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
138#define AMDGPU_GFX_SAFE_MODE 0x00000001L
139#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
140#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
141#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
142
143/* max cursor sizes (in pixels) */
144#define CIK_CURSOR_WIDTH 128
145#define CIK_CURSOR_HEIGHT 128
146
147struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400148struct amdgpu_ib;
149struct amdgpu_vm;
150struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400151struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800152struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400153struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400154struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400155
156enum amdgpu_cp_irq {
157 AMDGPU_CP_IRQ_GFX_EOP = 0,
158 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
159 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
160 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
161 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
162 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
163 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
164 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
165 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
166
167 AMDGPU_CP_IRQ_LAST
168};
169
170enum amdgpu_sdma_irq {
171 AMDGPU_SDMA_IRQ_TRAP0 = 0,
172 AMDGPU_SDMA_IRQ_TRAP1,
173
174 AMDGPU_SDMA_IRQ_LAST
175};
176
177enum amdgpu_thermal_irq {
178 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
179 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
180
181 AMDGPU_THERMAL_IRQ_LAST
182};
183
Alex Deucher97b2e202015-04-20 16:51:00 -0400184int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400185 enum amd_ip_block_type block_type,
186 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400187int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400188 enum amd_ip_block_type block_type,
189 enum amd_powergating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400190
191struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400192 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400193 u32 major;
194 u32 minor;
195 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400196 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400197};
198
199int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400200 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400201 u32 major, u32 minor);
202
203const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
204 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400205 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400206
207/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
208struct amdgpu_buffer_funcs {
209 /* maximum bytes in a single operation */
210 uint32_t copy_max_bytes;
211
212 /* number of dw to reserve per operation */
213 unsigned copy_num_dw;
214
215 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800216 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400217 /* src addr in bytes */
218 uint64_t src_offset,
219 /* dst addr in bytes */
220 uint64_t dst_offset,
221 /* number of byte to transfer */
222 uint32_t byte_count);
223
224 /* maximum bytes in a single operation */
225 uint32_t fill_max_bytes;
226
227 /* number of dw to reserve per operation */
228 unsigned fill_num_dw;
229
230 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800231 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400232 /* value to write to memory */
233 uint32_t src_data,
234 /* dst addr in bytes */
235 uint64_t dst_offset,
236 /* number of byte to fill */
237 uint32_t byte_count);
238};
239
240/* provided by hw blocks that can write ptes, e.g., sdma */
241struct amdgpu_vm_pte_funcs {
242 /* copy pte entries from GART */
243 void (*copy_pte)(struct amdgpu_ib *ib,
244 uint64_t pe, uint64_t src,
245 unsigned count);
246 /* write pte one entry at a time with addr mapping */
247 void (*write_pte)(struct amdgpu_ib *ib,
Christian Königb07c9d22015-11-30 13:26:07 +0100248 const dma_addr_t *pages_addr, uint64_t pe,
Alex Deucher97b2e202015-04-20 16:51:00 -0400249 uint64_t addr, unsigned count,
250 uint32_t incr, uint32_t flags);
251 /* for linear pte/pde updates without addr mapping */
252 void (*set_pte_pde)(struct amdgpu_ib *ib,
253 uint64_t pe,
254 uint64_t addr, unsigned count,
255 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400256};
257
258/* provided by the gmc block */
259struct amdgpu_gart_funcs {
260 /* flush the vm tlb via mmio */
261 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
262 uint32_t vmid);
263 /* write pte/pde updates using the cpu */
264 int (*set_pte_pde)(struct amdgpu_device *adev,
265 void *cpu_pt_addr, /* cpu addr of page table */
266 uint32_t gpu_page_idx, /* pte/pde to update */
267 uint64_t addr, /* addr to write into pte/pde */
268 uint32_t flags); /* access flags */
269};
270
271/* provided by the ih block */
272struct amdgpu_ih_funcs {
273 /* ring read/write ptr handling, called from interrupt context */
274 u32 (*get_wptr)(struct amdgpu_device *adev);
275 void (*decode_iv)(struct amdgpu_device *adev,
276 struct amdgpu_iv_entry *entry);
277 void (*set_rptr)(struct amdgpu_device *adev);
278};
279
280/* provided by hw blocks that expose a ring buffer for commands */
281struct amdgpu_ring_funcs {
282 /* ring read/write ptr handling */
283 u32 (*get_rptr)(struct amdgpu_ring *ring);
284 u32 (*get_wptr)(struct amdgpu_ring *ring);
285 void (*set_wptr)(struct amdgpu_ring *ring);
286 /* validating and patching of IBs */
287 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
288 /* command emit functions */
289 void (*emit_ib)(struct amdgpu_ring *ring,
Christian Königd88bf582016-05-06 17:50:03 +0200290 struct amdgpu_ib *ib,
291 unsigned vm_id, bool ctx_switch);
Alex Deucher97b2e202015-04-20 16:51:00 -0400292 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800293 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100294 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400295 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
296 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200297 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800298 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400299 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
300 uint32_t gds_base, uint32_t gds_size,
301 uint32_t gws_base, uint32_t gws_size,
302 uint32_t oa_base, uint32_t oa_size);
303 /* testing functions */
304 int (*test_ring)(struct amdgpu_ring *ring);
305 int (*test_ib)(struct amdgpu_ring *ring);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800306 /* insert NOP packets */
307 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100308 /* pad the indirect buffer to the necessary number of dw */
309 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800310 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
311 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Alex Deucher97b2e202015-04-20 16:51:00 -0400312};
313
314/*
315 * BIOS.
316 */
317bool amdgpu_get_bios(struct amdgpu_device *adev);
318bool amdgpu_read_bios(struct amdgpu_device *adev);
319
320/*
321 * Dummy page
322 */
323struct amdgpu_dummy_page {
324 struct page *page;
325 dma_addr_t addr;
326};
327int amdgpu_dummy_page_init(struct amdgpu_device *adev);
328void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
329
330
331/*
332 * Clocks
333 */
334
335#define AMDGPU_MAX_PPLL 3
336
337struct amdgpu_clock {
338 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
339 struct amdgpu_pll spll;
340 struct amdgpu_pll mpll;
341 /* 10 Khz units */
342 uint32_t default_mclk;
343 uint32_t default_sclk;
344 uint32_t default_dispclk;
345 uint32_t current_dispclk;
346 uint32_t dp_extclk;
347 uint32_t max_pixel_clock;
348};
349
350/*
351 * Fences.
352 */
353struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400354 uint64_t gpu_addr;
355 volatile uint32_t *cpu_addr;
356 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100357 uint32_t sync_seq;
358 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400359 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400360 struct amdgpu_irq_src *irq_src;
361 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100362 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100363 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100364 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100365 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400366};
367
368/* some special values for the owner field */
369#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
370#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400371
Chunming Zhou890ee232015-06-01 14:35:03 +0800372#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
373#define AMDGPU_FENCE_FLAG_INT (1 << 1)
374
Alex Deucher97b2e202015-04-20 16:51:00 -0400375int 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 */
Christian König29b32592016-04-15 17:19:16 +0200394
395#define AMDGPU_TTM_LRU_SIZE 20
396
397struct amdgpu_mman_lru {
398 struct list_head *lru[TTM_NUM_MEM_TYPES];
399 struct list_head *swap_lru;
400};
401
Alex Deucher97b2e202015-04-20 16:51:00 -0400402struct amdgpu_mman {
403 struct ttm_bo_global_ref bo_global_ref;
404 struct drm_global_reference mem_global_ref;
405 struct ttm_bo_device bdev;
406 bool mem_global_referenced;
407 bool initialized;
408
409#if defined(CONFIG_DEBUG_FS)
410 struct dentry *vram;
411 struct dentry *gtt;
412#endif
413
414 /* buffer handling */
415 const struct amdgpu_buffer_funcs *buffer_funcs;
416 struct amdgpu_ring *buffer_funcs_ring;
Christian König703297c2016-02-10 14:20:50 +0100417 /* Scheduler entity for buffer moves */
418 struct amd_sched_entity entity;
Christian König29b32592016-04-15 17:19:16 +0200419
420 /* custom LRU management */
421 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE];
Alex Deucher97b2e202015-04-20 16:51:00 -0400422};
423
424int amdgpu_copy_buffer(struct amdgpu_ring *ring,
425 uint64_t src_offset,
426 uint64_t dst_offset,
427 uint32_t byte_count,
428 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800429 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400430int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
431
432struct amdgpu_bo_list_entry {
433 struct amdgpu_bo *robj;
434 struct ttm_validate_buffer tv;
435 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400436 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100437 struct page **user_pages;
438 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400439};
440
441struct amdgpu_bo_va_mapping {
442 struct list_head list;
443 struct interval_tree_node it;
444 uint64_t offset;
445 uint32_t flags;
446};
447
448/* bo virtual addresses in a specific vm */
449struct amdgpu_bo_va {
450 /* protected by bo being reserved */
451 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800452 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400453 unsigned ref_count;
454
Christian König7fc11952015-07-30 11:53:42 +0200455 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400456 struct list_head vm_status;
457
Christian König7fc11952015-07-30 11:53:42 +0200458 /* mappings for this bo_va */
459 struct list_head invalids;
460 struct list_head valids;
461
Alex Deucher97b2e202015-04-20 16:51:00 -0400462 /* constant after initialization */
463 struct amdgpu_vm *vm;
464 struct amdgpu_bo *bo;
465};
466
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800467#define AMDGPU_GEM_DOMAIN_MAX 0x3
468
Alex Deucher97b2e202015-04-20 16:51:00 -0400469struct amdgpu_bo {
470 /* Protected by gem.mutex */
471 struct list_head list;
472 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100473 u32 prefered_domains;
474 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800475 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400476 struct ttm_placement placement;
477 struct ttm_buffer_object tbo;
478 struct ttm_bo_kmap_obj kmap;
479 u64 flags;
480 unsigned pin_count;
481 void *kptr;
482 u64 tiling_flags;
483 u64 metadata_flags;
484 void *metadata;
485 u32 metadata_size;
486 /* list of all virtual address to which this bo
487 * is associated to
488 */
489 struct list_head va;
490 /* Constant after initialization */
491 struct amdgpu_device *adev;
492 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100493 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400494
495 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400496 struct amdgpu_mn *mn;
497 struct list_head mn_list;
498};
499#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
500
501void amdgpu_gem_object_free(struct drm_gem_object *obj);
502int amdgpu_gem_object_open(struct drm_gem_object *obj,
503 struct drm_file *file_priv);
504void amdgpu_gem_object_close(struct drm_gem_object *obj,
505 struct drm_file *file_priv);
506unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
507struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200508struct drm_gem_object *
509amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
510 struct dma_buf_attachment *attach,
511 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400512struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
513 struct drm_gem_object *gobj,
514 int flags);
515int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
516void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
517struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
518void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
519void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
520int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
521
522/* sub-allocation manager, it has to be protected by another lock.
523 * By conception this is an helper for other part of the driver
524 * like the indirect buffer or semaphore, which both have their
525 * locking.
526 *
527 * Principe is simple, we keep a list of sub allocation in offset
528 * order (first entry has offset == 0, last entry has the highest
529 * offset).
530 *
531 * When allocating new object we first check if there is room at
532 * the end total_size - (last_object_offset + last_object_size) >=
533 * alloc_size. If so we allocate new object there.
534 *
535 * When there is not enough room at the end, we start waiting for
536 * each sub object until we reach object_offset+object_size >=
537 * alloc_size, this object then become the sub object we return.
538 *
539 * Alignment can't be bigger than page size.
540 *
541 * Hole are not considered for allocation to keep things simple.
542 * Assumption is that there won't be hole (all object on same
543 * alignment).
544 */
Christian König6ba60b82016-03-11 14:50:08 +0100545
546#define AMDGPU_SA_NUM_FENCE_LISTS 32
547
Alex Deucher97b2e202015-04-20 16:51:00 -0400548struct amdgpu_sa_manager {
549 wait_queue_head_t wq;
550 struct amdgpu_bo *bo;
551 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100552 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400553 struct list_head olist;
554 unsigned size;
555 uint64_t gpu_addr;
556 void *cpu_ptr;
557 uint32_t domain;
558 uint32_t align;
559};
560
Alex Deucher97b2e202015-04-20 16:51:00 -0400561/* sub-allocation buffer */
562struct amdgpu_sa_bo {
563 struct list_head olist;
564 struct list_head flist;
565 struct amdgpu_sa_manager *manager;
566 unsigned soffset;
567 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800568 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400569};
570
571/*
572 * GEM objects.
573 */
Christian König418aa0c2016-02-15 16:59:57 +0100574void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400575int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
576 int alignment, u32 initial_domain,
577 u64 flags, bool kernel,
578 struct drm_gem_object **obj);
579
580int amdgpu_mode_dumb_create(struct drm_file *file_priv,
581 struct drm_device *dev,
582 struct drm_mode_create_dumb *args);
583int amdgpu_mode_dumb_mmap(struct drm_file *filp,
584 struct drm_device *dev,
585 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400586/*
587 * Synchronization
588 */
589struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800590 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800591 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400592};
593
594void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200595int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
596 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400597int amdgpu_sync_resv(struct amdgpu_device *adev,
598 struct amdgpu_sync *sync,
599 struct reservation_object *resv,
600 void *owner);
Christian König1fbb2e92016-06-01 10:47:36 +0200601struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
602 struct amdgpu_ring *ring);
Christian Könige61235d2015-08-25 11:05:36 +0200603struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100604void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100605int amdgpu_sync_init(void);
606void amdgpu_sync_fini(void);
Rex Zhud573de22016-05-12 13:27:28 +0800607int amdgpu_fence_slab_init(void);
608void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400609
610/*
611 * GART structures, functions & helpers
612 */
613struct amdgpu_mc;
614
615#define AMDGPU_GPU_PAGE_SIZE 4096
616#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
617#define AMDGPU_GPU_PAGE_SHIFT 12
618#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
619
620struct amdgpu_gart {
621 dma_addr_t table_addr;
622 struct amdgpu_bo *robj;
623 void *ptr;
624 unsigned num_gpu_pages;
625 unsigned num_cpu_pages;
626 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200627#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400628 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200629#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400630 bool ready;
631 const struct amdgpu_gart_funcs *gart_funcs;
632};
633
634int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
635void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
636int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
637void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
638int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
639void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
640int amdgpu_gart_init(struct amdgpu_device *adev);
641void amdgpu_gart_fini(struct amdgpu_device *adev);
642void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
643 int pages);
644int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
645 int pages, struct page **pagelist,
646 dma_addr_t *dma_addr, uint32_t flags);
647
648/*
649 * GPU MC structures, functions & helpers
650 */
651struct amdgpu_mc {
652 resource_size_t aper_size;
653 resource_size_t aper_base;
654 resource_size_t agp_base;
655 /* for some chips with <= 32MB we need to lie
656 * about vram size near mc fb location */
657 u64 mc_vram_size;
658 u64 visible_vram_size;
659 u64 gtt_size;
660 u64 gtt_start;
661 u64 gtt_end;
662 u64 vram_start;
663 u64 vram_end;
664 unsigned vram_width;
665 u64 real_vram_size;
666 int vram_mtrr;
667 u64 gtt_base_align;
668 u64 mc_mask;
669 const struct firmware *fw; /* MC firmware */
670 uint32_t fw_version;
671 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800672 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400673};
674
675/*
676 * GPU doorbell structures, functions & helpers
677 */
678typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
679{
680 AMDGPU_DOORBELL_KIQ = 0x000,
681 AMDGPU_DOORBELL_HIQ = 0x001,
682 AMDGPU_DOORBELL_DIQ = 0x002,
683 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
684 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
685 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
686 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
687 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
688 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
689 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
690 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
691 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
692 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
693 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
694 AMDGPU_DOORBELL_IH = 0x1E8,
695 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
696 AMDGPU_DOORBELL_INVALID = 0xFFFF
697} AMDGPU_DOORBELL_ASSIGNMENT;
698
699struct amdgpu_doorbell {
700 /* doorbell mmio */
701 resource_size_t base;
702 resource_size_t size;
703 u32 __iomem *ptr;
704 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
705};
706
707void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
708 phys_addr_t *aperture_base,
709 size_t *aperture_size,
710 size_t *start_offset);
711
712/*
713 * IRQS.
714 */
715
716struct amdgpu_flip_work {
717 struct work_struct flip_work;
718 struct work_struct unpin_work;
719 struct amdgpu_device *adev;
720 int crtc_id;
721 uint64_t base;
722 struct drm_pending_vblank_event *event;
723 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200724 struct fence *excl;
725 unsigned shared_count;
726 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100727 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400728 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400729};
730
731
732/*
733 * CP & rings.
734 */
735
736struct amdgpu_ib {
737 struct amdgpu_sa_bo *sa_bo;
738 uint32_t length_dw;
739 uint64_t gpu_addr;
740 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800741 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400742};
743
744enum amdgpu_ring_type {
745 AMDGPU_RING_TYPE_GFX,
746 AMDGPU_RING_TYPE_COMPUTE,
747 AMDGPU_RING_TYPE_SDMA,
748 AMDGPU_RING_TYPE_UVD,
749 AMDGPU_RING_TYPE_VCE
750};
751
Nils Wallménius62250a92016-04-10 16:30:00 +0200752extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800753
Christian König50838c82016-02-03 13:44:52 +0100754int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800755 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100756int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
757 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800758
Christian König50838c82016-02-03 13:44:52 +0100759void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100760int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100761 struct amd_sched_entity *entity, void *owner,
762 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800763
Alex Deucher97b2e202015-04-20 16:51:00 -0400764struct amdgpu_ring {
765 struct amdgpu_device *adev;
766 const struct amdgpu_ring_funcs *funcs;
767 struct amdgpu_fence_driver fence_drv;
Christian Königedf600d2016-05-03 15:54:54 +0200768 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400769
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800770 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400771 struct amdgpu_bo *ring_obj;
772 volatile uint32_t *ring;
773 unsigned rptr_offs;
774 u64 next_rptr_gpu_addr;
775 volatile u32 *next_rptr_cpu_addr;
776 unsigned wptr;
777 unsigned wptr_old;
778 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100779 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400780 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400781 uint64_t gpu_addr;
782 uint32_t align_mask;
783 uint32_t ptr_mask;
784 bool ready;
785 u32 nop;
786 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400787 u32 me;
788 u32 pipe;
789 u32 queue;
790 struct amdgpu_bo *mqd_obj;
791 u32 doorbell_index;
792 bool use_doorbell;
793 unsigned wptr_offs;
794 unsigned next_rptr_offs;
795 unsigned fence_offs;
Christian Königaa3b73f2016-05-03 15:17:40 +0200796 uint64_t current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400797 enum amdgpu_ring_type type;
798 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800799 unsigned cond_exe_offs;
800 u64 cond_exe_gpu_addr;
801 volatile u32 *cond_exe_cpu_addr;
Monk Liua909c6b2016-06-14 12:02:21 -0400802#if defined(CONFIG_DEBUG_FS)
803 struct dentry *ent;
804#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400805};
806
807/*
808 * VM
809 */
810
811/* maximum number of VMIDs */
812#define AMDGPU_NUM_VM 16
813
814/* number of entries in page table */
815#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
816
817/* PTBs (Page Table Blocks) need to be aligned to 32K */
818#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
819#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
820#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
821
822#define AMDGPU_PTE_VALID (1 << 0)
823#define AMDGPU_PTE_SYSTEM (1 << 1)
824#define AMDGPU_PTE_SNOOPED (1 << 2)
825
826/* VI only */
827#define AMDGPU_PTE_EXECUTABLE (1 << 4)
828
829#define AMDGPU_PTE_READABLE (1 << 5)
830#define AMDGPU_PTE_WRITEABLE (1 << 6)
831
832/* PTE (Page Table Entry) fragment field for different page sizes */
833#define AMDGPU_PTE_FRAG_4KB (0 << 7)
834#define AMDGPU_PTE_FRAG_64KB (4 << 7)
835#define AMDGPU_LOG2_PAGES_PER_FRAG 4
836
Christian Königd9c13152015-09-28 12:31:26 +0200837/* How to programm VM fault handling */
838#define AMDGPU_VM_FAULT_STOP_NEVER 0
839#define AMDGPU_VM_FAULT_STOP_FIRST 1
840#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
841
Alex Deucher97b2e202015-04-20 16:51:00 -0400842struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100843 struct amdgpu_bo_list_entry entry;
844 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400845};
846
Alex Deucher97b2e202015-04-20 16:51:00 -0400847struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100848 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400849 struct rb_root va;
850
Christian König7fc11952015-07-30 11:53:42 +0200851 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400852 spinlock_t status_lock;
853
854 /* BOs moved, but not yet updated in the PT */
855 struct list_head invalidated;
856
Christian König7fc11952015-07-30 11:53:42 +0200857 /* BOs cleared in the PT because of a move */
858 struct list_head cleared;
859
860 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400861 struct list_head freed;
862
863 /* contains the page directory */
864 struct amdgpu_bo *page_directory;
865 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200866 struct fence *page_directory_fence;
Christian König5a712a82016-06-21 16:28:15 +0200867 uint64_t last_eviction_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400868
869 /* array of page tables, one for each page directory entry */
870 struct amdgpu_vm_pt *page_tables;
871
872 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100873 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100874
jimqu81d75a32015-12-04 17:17:00 +0800875 /* protecting freed */
876 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100877
878 /* Scheduler entity for page table updates */
879 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800880
881 /* client id */
882 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400883};
884
Christian Königbcb1ba32016-03-08 15:40:11 +0100885struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100886 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100887 struct fence *first;
888 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100889 struct fence *last_flush;
Christian König0ea54b92016-05-04 10:20:01 +0200890 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100891
Christian Königbcb1ba32016-03-08 15:40:11 +0100892 uint64_t pd_gpu_addr;
893 /* last flushed PD/PT update */
894 struct fence *flushed_updates;
895
Christian König971fe9a92016-03-01 15:09:25 +0100896 uint32_t gds_base;
897 uint32_t gds_size;
898 uint32_t gws_base;
899 uint32_t gws_size;
900 uint32_t oa_base;
901 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100902};
Christian König8d0a7ce2015-11-03 20:58:50 +0100903
Christian Königa9a78b32016-01-21 10:19:11 +0100904struct amdgpu_vm_manager {
905 /* Handling of VMIDs */
906 struct mutex lock;
907 unsigned num_ids;
908 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100909 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100910
Christian König1fbb2e92016-06-01 10:47:36 +0200911 /* Handling of VM fences */
912 u64 fence_context;
913 unsigned seqno[AMDGPU_MAX_RINGS];
914
Christian König8b4fb002015-11-15 16:04:16 +0100915 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400916 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100917 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400918 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100919 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400920 /* vm pte handling */
921 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100922 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
923 unsigned vm_pte_num_rings;
924 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800925 /* client id counter */
926 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400927};
928
Christian Königa9a78b32016-01-21 10:19:11 +0100929void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100930void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100931int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
932void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100933void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
934 struct list_head *validated,
935 struct amdgpu_bo_list_entry *entry);
Christian König5a712a82016-06-21 16:28:15 +0200936void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
937 struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100938void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
939 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100940int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100941 struct amdgpu_sync *sync, struct fence *fence,
942 unsigned *vm_id, uint64_t *vm_pd_addr);
Christian König41d9eb22016-03-01 16:46:18 +0100943int amdgpu_vm_flush(struct amdgpu_ring *ring,
944 unsigned vm_id, uint64_t pd_addr,
945 uint32_t gds_base, uint32_t gds_size,
946 uint32_t gws_base, uint32_t gws_size,
947 uint32_t oa_base, uint32_t oa_size);
Christian König971fe9a92016-03-01 15:09:25 +0100948void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian Königb07c9d22015-11-30 13:26:07 +0100949uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
Christian König8b4fb002015-11-15 16:04:16 +0100950int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
951 struct amdgpu_vm *vm);
952int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
953 struct amdgpu_vm *vm);
954int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
955 struct amdgpu_sync *sync);
956int amdgpu_vm_bo_update(struct amdgpu_device *adev,
957 struct amdgpu_bo_va *bo_va,
958 struct ttm_mem_reg *mem);
959void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
960 struct amdgpu_bo *bo);
961struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
962 struct amdgpu_bo *bo);
963struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
964 struct amdgpu_vm *vm,
965 struct amdgpu_bo *bo);
966int amdgpu_vm_bo_map(struct amdgpu_device *adev,
967 struct amdgpu_bo_va *bo_va,
968 uint64_t addr, uint64_t offset,
969 uint64_t size, uint32_t flags);
970int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
971 struct amdgpu_bo_va *bo_va,
972 uint64_t addr);
973void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
974 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100975
Alex Deucher97b2e202015-04-20 16:51:00 -0400976/*
977 * context related structures
978 */
979
Christian König21c16bf2015-07-07 17:24:49 +0200980struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200981 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800982 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200983 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200984};
985
Alex Deucher97b2e202015-04-20 16:51:00 -0400986struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400987 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800988 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400989 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200990 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800991 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200992 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400993};
994
995struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400996 struct amdgpu_device *adev;
997 struct mutex lock;
998 /* protected by lock */
999 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001000};
1001
Alex Deucher0b492a42015-08-16 22:48:26 -04001002struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
1003int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
1004
Christian König21c16bf2015-07-07 17:24:49 +02001005uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +02001006 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +02001007struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
1008 struct amdgpu_ring *ring, uint64_t seq);
1009
Alex Deucher0b492a42015-08-16 22:48:26 -04001010int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1011 struct drm_file *filp);
1012
Christian Königefd4ccb2015-08-04 16:20:31 +02001013void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1014void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -04001015
Alex Deucher97b2e202015-04-20 16:51:00 -04001016/*
1017 * file private structure
1018 */
1019
1020struct amdgpu_fpriv {
1021 struct amdgpu_vm vm;
1022 struct mutex bo_list_lock;
1023 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001024 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001025};
1026
1027/*
1028 * residency list
1029 */
1030
1031struct amdgpu_bo_list {
1032 struct mutex lock;
1033 struct amdgpu_bo *gds_obj;
1034 struct amdgpu_bo *gws_obj;
1035 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001036 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001037 unsigned num_entries;
1038 struct amdgpu_bo_list_entry *array;
1039};
1040
1041struct amdgpu_bo_list *
1042amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001043void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1044 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001045void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1046void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1047
1048/*
1049 * GFX stuff
1050 */
1051#include "clearstate_defs.h"
1052
Alex Deucher79e54122016-04-08 15:45:13 -04001053struct amdgpu_rlc_funcs {
1054 void (*enter_safe_mode)(struct amdgpu_device *adev);
1055 void (*exit_safe_mode)(struct amdgpu_device *adev);
1056};
1057
Alex Deucher97b2e202015-04-20 16:51:00 -04001058struct amdgpu_rlc {
1059 /* for power gating */
1060 struct amdgpu_bo *save_restore_obj;
1061 uint64_t save_restore_gpu_addr;
1062 volatile uint32_t *sr_ptr;
1063 const u32 *reg_list;
1064 u32 reg_list_size;
1065 /* for clear state */
1066 struct amdgpu_bo *clear_state_obj;
1067 uint64_t clear_state_gpu_addr;
1068 volatile uint32_t *cs_ptr;
1069 const struct cs_section_def *cs_data;
1070 u32 clear_state_size;
1071 /* for cp tables */
1072 struct amdgpu_bo *cp_table_obj;
1073 uint64_t cp_table_gpu_addr;
1074 volatile uint32_t *cp_table_ptr;
1075 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001076
1077 /* safe mode for updating CG/PG state */
1078 bool in_safe_mode;
1079 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001080
1081 /* for firmware data */
1082 u32 save_and_restore_offset;
1083 u32 clear_state_descriptor_offset;
1084 u32 avail_scratch_ram_locations;
1085 u32 reg_restore_list_size;
1086 u32 reg_list_format_start;
1087 u32 reg_list_format_separate_start;
1088 u32 starting_offsets_start;
1089 u32 reg_list_format_size_bytes;
1090 u32 reg_list_size_bytes;
1091
1092 u32 *register_list_format;
1093 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001094};
1095
1096struct amdgpu_mec {
1097 struct amdgpu_bo *hpd_eop_obj;
1098 u64 hpd_eop_gpu_addr;
1099 u32 num_pipe;
1100 u32 num_mec;
1101 u32 num_queue;
1102};
1103
1104/*
1105 * GPU scratch registers structures, functions & helpers
1106 */
1107struct amdgpu_scratch {
1108 unsigned num_reg;
1109 uint32_t reg_base;
1110 bool free[32];
1111 uint32_t reg[32];
1112};
1113
1114/*
1115 * GFX configurations
1116 */
1117struct amdgpu_gca_config {
1118 unsigned max_shader_engines;
1119 unsigned max_tile_pipes;
1120 unsigned max_cu_per_sh;
1121 unsigned max_sh_per_se;
1122 unsigned max_backends_per_se;
1123 unsigned max_texture_channel_caches;
1124 unsigned max_gprs;
1125 unsigned max_gs_threads;
1126 unsigned max_hw_contexts;
1127 unsigned sc_prim_fifo_size_frontend;
1128 unsigned sc_prim_fifo_size_backend;
1129 unsigned sc_hiz_tile_fifo_size;
1130 unsigned sc_earlyz_tile_fifo_size;
1131
1132 unsigned num_tile_pipes;
1133 unsigned backend_enable_mask;
1134 unsigned mem_max_burst_length_bytes;
1135 unsigned mem_row_size_in_kb;
1136 unsigned shader_engine_tile_size;
1137 unsigned num_gpus;
1138 unsigned multi_gpu_tile_size;
1139 unsigned mc_arb_ramcfg;
1140 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001141 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001142
1143 uint32_t tile_mode_array[32];
1144 uint32_t macrotile_mode_array[16];
1145};
1146
Alex Deucher7dae69a2016-05-03 16:25:53 -04001147struct amdgpu_cu_info {
1148 uint32_t number; /* total active CU number */
1149 uint32_t ao_cu_mask;
1150 uint32_t bitmap[4][4];
1151};
1152
Alex Deucherb95e31f2016-07-07 15:01:42 -04001153struct amdgpu_gfx_funcs {
1154 /* get the gpu clock counter */
1155 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
1156};
1157
Alex Deucher97b2e202015-04-20 16:51:00 -04001158struct amdgpu_gfx {
1159 struct mutex gpu_clock_mutex;
1160 struct amdgpu_gca_config config;
1161 struct amdgpu_rlc rlc;
1162 struct amdgpu_mec mec;
1163 struct amdgpu_scratch scratch;
1164 const struct firmware *me_fw; /* ME firmware */
1165 uint32_t me_fw_version;
1166 const struct firmware *pfp_fw; /* PFP firmware */
1167 uint32_t pfp_fw_version;
1168 const struct firmware *ce_fw; /* CE firmware */
1169 uint32_t ce_fw_version;
1170 const struct firmware *rlc_fw; /* RLC firmware */
1171 uint32_t rlc_fw_version;
1172 const struct firmware *mec_fw; /* MEC firmware */
1173 uint32_t mec_fw_version;
1174 const struct firmware *mec2_fw; /* MEC2 firmware */
1175 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001176 uint32_t me_feature_version;
1177 uint32_t ce_feature_version;
1178 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001179 uint32_t rlc_feature_version;
1180 uint32_t mec_feature_version;
1181 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001182 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1183 unsigned num_gfx_rings;
1184 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1185 unsigned num_compute_rings;
1186 struct amdgpu_irq_src eop_irq;
1187 struct amdgpu_irq_src priv_reg_irq;
1188 struct amdgpu_irq_src priv_inst_irq;
1189 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001190 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001191 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001192 unsigned ce_ram_size;
1193 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001194 const struct amdgpu_gfx_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001195};
1196
Christian Königb07c60c2016-01-31 12:29:04 +01001197int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001198 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001199void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1200 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001201int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001202 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001203 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001204int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1205void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1206int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001207int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001208void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001209void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001210void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001211void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001212unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1213 uint32_t **data);
1214int amdgpu_ring_restore(struct amdgpu_ring *ring,
1215 unsigned size, uint32_t *data);
1216int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1217 unsigned ring_size, u32 nop, u32 align_mask,
1218 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1219 enum amdgpu_ring_type ring_type);
1220void amdgpu_ring_fini(struct amdgpu_ring *ring);
1221
1222/*
1223 * CS.
1224 */
1225struct amdgpu_cs_chunk {
1226 uint32_t chunk_id;
1227 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001228 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001229};
1230
1231struct amdgpu_cs_parser {
1232 struct amdgpu_device *adev;
1233 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001234 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001235
Alex Deucher97b2e202015-04-20 16:51:00 -04001236 /* chunks */
1237 unsigned nchunks;
1238 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001239
Christian König50838c82016-02-03 13:44:52 +01001240 /* scheduler job object */
1241 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001242
Christian Königc3cca412015-12-15 14:41:33 +01001243 /* buffer objects */
1244 struct ww_acquire_ctx ticket;
1245 struct amdgpu_bo_list *bo_list;
1246 struct amdgpu_bo_list_entry vm_pd;
1247 struct list_head validated;
1248 struct fence *fence;
1249 uint64_t bytes_moved_threshold;
1250 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001251
1252 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001253 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001254};
1255
Chunming Zhoubb977d32015-08-18 15:16:40 +08001256struct amdgpu_job {
1257 struct amd_sched_job base;
1258 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001259 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001260 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001261 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001262 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001263 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001264 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001265 void *owner;
Christian König92f25092016-05-06 15:57:42 +02001266 uint64_t ctx;
Christian Königd88bf582016-05-06 17:50:03 +02001267 unsigned vm_id;
1268 uint64_t vm_pd_addr;
1269 uint32_t gds_base, gds_size;
1270 uint32_t gws_base, gws_size;
1271 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001272
1273 /* user fence handling */
1274 struct amdgpu_bo *uf_bo;
1275 uint32_t uf_offset;
1276 uint64_t uf_sequence;
1277
Chunming Zhoubb977d32015-08-18 15:16:40 +08001278};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001279#define to_amdgpu_job(sched_job) \
1280 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001281
Christian König7270f832016-01-31 11:00:41 +01001282static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1283 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001284{
Christian König50838c82016-02-03 13:44:52 +01001285 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001286}
1287
Christian König7270f832016-01-31 11:00:41 +01001288static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1289 uint32_t ib_idx, int idx,
1290 uint32_t value)
1291{
Christian König50838c82016-02-03 13:44:52 +01001292 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001293}
1294
Alex Deucher97b2e202015-04-20 16:51:00 -04001295/*
1296 * Writeback
1297 */
1298#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1299
1300struct amdgpu_wb {
1301 struct amdgpu_bo *wb_obj;
1302 volatile uint32_t *wb;
1303 uint64_t gpu_addr;
1304 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1305 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1306};
1307
1308int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1309void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1310
Alex Deucher97b2e202015-04-20 16:51:00 -04001311
Alex Deucher97b2e202015-04-20 16:51:00 -04001312
1313enum amdgpu_int_thermal_type {
1314 THERMAL_TYPE_NONE,
1315 THERMAL_TYPE_EXTERNAL,
1316 THERMAL_TYPE_EXTERNAL_GPIO,
1317 THERMAL_TYPE_RV6XX,
1318 THERMAL_TYPE_RV770,
1319 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1320 THERMAL_TYPE_EVERGREEN,
1321 THERMAL_TYPE_SUMO,
1322 THERMAL_TYPE_NI,
1323 THERMAL_TYPE_SI,
1324 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1325 THERMAL_TYPE_CI,
1326 THERMAL_TYPE_KV,
1327};
1328
1329enum amdgpu_dpm_auto_throttle_src {
1330 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1331 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1332};
1333
1334enum amdgpu_dpm_event_src {
1335 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1336 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1337 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1338 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1339 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1340};
1341
1342#define AMDGPU_MAX_VCE_LEVELS 6
1343
1344enum amdgpu_vce_level {
1345 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1346 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1347 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1348 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1349 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1350 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1351};
1352
1353struct amdgpu_ps {
1354 u32 caps; /* vbios flags */
1355 u32 class; /* vbios flags */
1356 u32 class2; /* vbios flags */
1357 /* UVD clocks */
1358 u32 vclk;
1359 u32 dclk;
1360 /* VCE clocks */
1361 u32 evclk;
1362 u32 ecclk;
1363 bool vce_active;
1364 enum amdgpu_vce_level vce_level;
1365 /* asic priv */
1366 void *ps_priv;
1367};
1368
1369struct amdgpu_dpm_thermal {
1370 /* thermal interrupt work */
1371 struct work_struct work;
1372 /* low temperature threshold */
1373 int min_temp;
1374 /* high temperature threshold */
1375 int max_temp;
1376 /* was last interrupt low to high or high to low */
1377 bool high_to_low;
1378 /* interrupt source */
1379 struct amdgpu_irq_src irq;
1380};
1381
1382enum amdgpu_clk_action
1383{
1384 AMDGPU_SCLK_UP = 1,
1385 AMDGPU_SCLK_DOWN
1386};
1387
1388struct amdgpu_blacklist_clocks
1389{
1390 u32 sclk;
1391 u32 mclk;
1392 enum amdgpu_clk_action action;
1393};
1394
1395struct amdgpu_clock_and_voltage_limits {
1396 u32 sclk;
1397 u32 mclk;
1398 u16 vddc;
1399 u16 vddci;
1400};
1401
1402struct amdgpu_clock_array {
1403 u32 count;
1404 u32 *values;
1405};
1406
1407struct amdgpu_clock_voltage_dependency_entry {
1408 u32 clk;
1409 u16 v;
1410};
1411
1412struct amdgpu_clock_voltage_dependency_table {
1413 u32 count;
1414 struct amdgpu_clock_voltage_dependency_entry *entries;
1415};
1416
1417union amdgpu_cac_leakage_entry {
1418 struct {
1419 u16 vddc;
1420 u32 leakage;
1421 };
1422 struct {
1423 u16 vddc1;
1424 u16 vddc2;
1425 u16 vddc3;
1426 };
1427};
1428
1429struct amdgpu_cac_leakage_table {
1430 u32 count;
1431 union amdgpu_cac_leakage_entry *entries;
1432};
1433
1434struct amdgpu_phase_shedding_limits_entry {
1435 u16 voltage;
1436 u32 sclk;
1437 u32 mclk;
1438};
1439
1440struct amdgpu_phase_shedding_limits_table {
1441 u32 count;
1442 struct amdgpu_phase_shedding_limits_entry *entries;
1443};
1444
1445struct amdgpu_uvd_clock_voltage_dependency_entry {
1446 u32 vclk;
1447 u32 dclk;
1448 u16 v;
1449};
1450
1451struct amdgpu_uvd_clock_voltage_dependency_table {
1452 u8 count;
1453 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1454};
1455
1456struct amdgpu_vce_clock_voltage_dependency_entry {
1457 u32 ecclk;
1458 u32 evclk;
1459 u16 v;
1460};
1461
1462struct amdgpu_vce_clock_voltage_dependency_table {
1463 u8 count;
1464 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1465};
1466
1467struct amdgpu_ppm_table {
1468 u8 ppm_design;
1469 u16 cpu_core_number;
1470 u32 platform_tdp;
1471 u32 small_ac_platform_tdp;
1472 u32 platform_tdc;
1473 u32 small_ac_platform_tdc;
1474 u32 apu_tdp;
1475 u32 dgpu_tdp;
1476 u32 dgpu_ulv_power;
1477 u32 tj_max;
1478};
1479
1480struct amdgpu_cac_tdp_table {
1481 u16 tdp;
1482 u16 configurable_tdp;
1483 u16 tdc;
1484 u16 battery_power_limit;
1485 u16 small_power_limit;
1486 u16 low_cac_leakage;
1487 u16 high_cac_leakage;
1488 u16 maximum_power_delivery_limit;
1489};
1490
1491struct amdgpu_dpm_dynamic_state {
1492 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1493 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1494 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1495 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1496 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1497 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1498 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1499 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1500 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1501 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1502 struct amdgpu_clock_array valid_sclk_values;
1503 struct amdgpu_clock_array valid_mclk_values;
1504 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1505 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1506 u32 mclk_sclk_ratio;
1507 u32 sclk_mclk_delta;
1508 u16 vddc_vddci_delta;
1509 u16 min_vddc_for_pcie_gen2;
1510 struct amdgpu_cac_leakage_table cac_leakage_table;
1511 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1512 struct amdgpu_ppm_table *ppm_table;
1513 struct amdgpu_cac_tdp_table *cac_tdp_table;
1514};
1515
1516struct amdgpu_dpm_fan {
1517 u16 t_min;
1518 u16 t_med;
1519 u16 t_high;
1520 u16 pwm_min;
1521 u16 pwm_med;
1522 u16 pwm_high;
1523 u8 t_hyst;
1524 u32 cycle_delay;
1525 u16 t_max;
1526 u8 control_mode;
1527 u16 default_max_fan_pwm;
1528 u16 default_fan_output_sensitivity;
1529 u16 fan_output_sensitivity;
1530 bool ucode_fan_control;
1531};
1532
1533enum amdgpu_pcie_gen {
1534 AMDGPU_PCIE_GEN1 = 0,
1535 AMDGPU_PCIE_GEN2 = 1,
1536 AMDGPU_PCIE_GEN3 = 2,
1537 AMDGPU_PCIE_GEN_INVALID = 0xffff
1538};
1539
1540enum amdgpu_dpm_forced_level {
1541 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1542 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1543 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001544 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001545};
1546
1547struct amdgpu_vce_state {
1548 /* vce clocks */
1549 u32 evclk;
1550 u32 ecclk;
1551 /* gpu clocks */
1552 u32 sclk;
1553 u32 mclk;
1554 u8 clk_idx;
1555 u8 pstate;
1556};
1557
1558struct amdgpu_dpm_funcs {
1559 int (*get_temperature)(struct amdgpu_device *adev);
1560 int (*pre_set_power_state)(struct amdgpu_device *adev);
1561 int (*set_power_state)(struct amdgpu_device *adev);
1562 void (*post_set_power_state)(struct amdgpu_device *adev);
1563 void (*display_configuration_changed)(struct amdgpu_device *adev);
1564 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1565 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1566 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1567 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1568 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1569 bool (*vblank_too_short)(struct amdgpu_device *adev);
1570 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001571 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001572 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1573 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1574 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1575 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1576 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001577 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1578 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001579 int (*get_sclk_od)(struct amdgpu_device *adev);
1580 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001581 int (*get_mclk_od)(struct amdgpu_device *adev);
1582 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001583};
1584
1585struct amdgpu_dpm {
1586 struct amdgpu_ps *ps;
1587 /* number of valid power states */
1588 int num_ps;
1589 /* current power state that is active */
1590 struct amdgpu_ps *current_ps;
1591 /* requested power state */
1592 struct amdgpu_ps *requested_ps;
1593 /* boot up power state */
1594 struct amdgpu_ps *boot_ps;
1595 /* default uvd power state */
1596 struct amdgpu_ps *uvd_ps;
1597 /* vce requirements */
1598 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1599 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001600 enum amd_pm_state_type state;
1601 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001602 u32 platform_caps;
1603 u32 voltage_response_time;
1604 u32 backbias_response_time;
1605 void *priv;
1606 u32 new_active_crtcs;
1607 int new_active_crtc_count;
1608 u32 current_active_crtcs;
1609 int current_active_crtc_count;
1610 struct amdgpu_dpm_dynamic_state dyn_state;
1611 struct amdgpu_dpm_fan fan;
1612 u32 tdp_limit;
1613 u32 near_tdp_limit;
1614 u32 near_tdp_limit_adjusted;
1615 u32 sq_ramping_threshold;
1616 u32 cac_leakage;
1617 u16 tdp_od_limit;
1618 u32 tdp_adjustment;
1619 u16 load_line_slope;
1620 bool power_control;
1621 bool ac_power;
1622 /* special states active */
1623 bool thermal_active;
1624 bool uvd_active;
1625 bool vce_active;
1626 /* thermal handling */
1627 struct amdgpu_dpm_thermal thermal;
1628 /* forced levels */
1629 enum amdgpu_dpm_forced_level forced_level;
1630};
1631
1632struct amdgpu_pm {
1633 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001634 u32 current_sclk;
1635 u32 current_mclk;
1636 u32 default_sclk;
1637 u32 default_mclk;
1638 struct amdgpu_i2c_chan *i2c_bus;
1639 /* internal thermal controller on rv6xx+ */
1640 enum amdgpu_int_thermal_type int_thermal_type;
1641 struct device *int_hwmon_dev;
1642 /* fan control parameters */
1643 bool no_fan;
1644 u8 fan_pulses_per_revolution;
1645 u8 fan_min_rpm;
1646 u8 fan_max_rpm;
1647 /* dpm */
1648 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001649 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001650 struct amdgpu_dpm dpm;
1651 const struct firmware *fw; /* SMC firmware */
1652 uint32_t fw_version;
1653 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001654 uint32_t pcie_gen_mask;
1655 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001656 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001657};
1658
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001659void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1660
Alex Deucher97b2e202015-04-20 16:51:00 -04001661/*
1662 * UVD
1663 */
Arindam Nathc0365542016-04-12 13:46:15 +02001664#define AMDGPU_DEFAULT_UVD_HANDLES 10
1665#define AMDGPU_MAX_UVD_HANDLES 40
1666#define AMDGPU_UVD_STACK_SIZE (200*1024)
1667#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1668#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1669#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001670
1671struct amdgpu_uvd {
1672 struct amdgpu_bo *vcpu_bo;
1673 void *cpu_addr;
1674 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001675 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001676 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001677 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001678 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1679 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1680 struct delayed_work idle_work;
1681 const struct firmware *fw; /* UVD firmware */
1682 struct amdgpu_ring ring;
1683 struct amdgpu_irq_src irq;
1684 bool address_64_bit;
Christian Königead833e2016-02-10 14:35:19 +01001685 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001686};
1687
1688/*
1689 * VCE
1690 */
1691#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001692#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1693
Alex Deucher6a585772015-07-10 14:16:24 -04001694#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1695#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1696
Alex Deucher97b2e202015-04-20 16:51:00 -04001697struct amdgpu_vce {
1698 struct amdgpu_bo *vcpu_bo;
1699 uint64_t gpu_addr;
1700 unsigned fw_version;
1701 unsigned fb_version;
1702 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1703 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001704 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001705 struct delayed_work idle_work;
1706 const struct firmware *fw; /* VCE firmware */
1707 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1708 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001709 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001710 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001711};
1712
1713/*
1714 * SDMA
1715 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001716struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001717 /* SDMA firmware */
1718 const struct firmware *fw;
1719 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001720 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001721
1722 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001723 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001724};
1725
Alex Deucherc113ea12015-10-08 16:30:37 -04001726struct amdgpu_sdma {
1727 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1728 struct amdgpu_irq_src trap_irq;
1729 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001730 int num_instances;
Alex Deucherc113ea12015-10-08 16:30:37 -04001731};
1732
Alex Deucher97b2e202015-04-20 16:51:00 -04001733/*
1734 * Firmware
1735 */
1736struct amdgpu_firmware {
1737 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1738 bool smu_load;
1739 struct amdgpu_bo *fw_buf;
1740 unsigned int fw_size;
1741};
1742
1743/*
1744 * Benchmarking
1745 */
1746void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1747
1748
1749/*
1750 * Testing
1751 */
1752void amdgpu_test_moves(struct amdgpu_device *adev);
1753void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1754 struct amdgpu_ring *cpA,
1755 struct amdgpu_ring *cpB);
1756void amdgpu_test_syncing(struct amdgpu_device *adev);
1757
1758/*
1759 * MMU Notifier
1760 */
1761#if defined(CONFIG_MMU_NOTIFIER)
1762int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1763void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1764#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001765static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001766{
1767 return -ENODEV;
1768}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001769static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001770#endif
1771
1772/*
1773 * Debugfs
1774 */
1775struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001776 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001777 unsigned num_files;
1778};
1779
1780int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001781 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001782 unsigned nfiles);
1783int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1784
1785#if defined(CONFIG_DEBUG_FS)
1786int amdgpu_debugfs_init(struct drm_minor *minor);
1787void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1788#endif
1789
Huang Rui50ab2532016-06-12 15:51:09 +08001790int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1791
Alex Deucher97b2e202015-04-20 16:51:00 -04001792/*
1793 * amdgpu smumgr functions
1794 */
1795struct amdgpu_smumgr_funcs {
1796 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1797 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1798 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1799};
1800
1801/*
1802 * amdgpu smumgr
1803 */
1804struct amdgpu_smumgr {
1805 struct amdgpu_bo *toc_buf;
1806 struct amdgpu_bo *smu_buf;
1807 /* asic priv smu data */
1808 void *priv;
1809 spinlock_t smu_lock;
1810 /* smumgr functions */
1811 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1812 /* ucode loading complete flag */
1813 uint32_t fw_flags;
1814};
1815
1816/*
1817 * ASIC specific register table accessible by UMD
1818 */
1819struct amdgpu_allowed_register_entry {
1820 uint32_t reg_offset;
1821 bool untouched;
1822 bool grbm_indexed;
1823};
1824
Alex Deucher97b2e202015-04-20 16:51:00 -04001825/*
1826 * ASIC specific functions.
1827 */
1828struct amdgpu_asic_funcs {
1829 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001830 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1831 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001832 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1833 u32 sh_num, u32 reg_offset, u32 *value);
1834 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1835 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001836 /* get the reference clock */
1837 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001838 /* MM block clocks */
1839 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1840 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Andres Rodriguez048765a2016-06-11 02:51:32 -04001841 /* query virtual capabilities */
1842 u32 (*get_virtual_caps)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001843};
1844
1845/*
1846 * IOCTL.
1847 */
1848int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1849 struct drm_file *filp);
1850int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1851 struct drm_file *filp);
1852
1853int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1854 struct drm_file *filp);
1855int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1856 struct drm_file *filp);
1857int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1858 struct drm_file *filp);
1859int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1860 struct drm_file *filp);
1861int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1862 struct drm_file *filp);
1863int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1864 struct drm_file *filp);
1865int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1866int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1867
1868int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1869 struct drm_file *filp);
1870
1871/* VRAM scratch page for HDP bug, default vram page */
1872struct amdgpu_vram_scratch {
1873 struct amdgpu_bo *robj;
1874 volatile uint32_t *ptr;
1875 u64 gpu_addr;
1876};
1877
1878/*
1879 * ACPI
1880 */
1881struct amdgpu_atif_notification_cfg {
1882 bool enabled;
1883 int command_code;
1884};
1885
1886struct amdgpu_atif_notifications {
1887 bool display_switch;
1888 bool expansion_mode_change;
1889 bool thermal_state;
1890 bool forced_power_state;
1891 bool system_power_state;
1892 bool display_conf_change;
1893 bool px_gfx_switch;
1894 bool brightness_change;
1895 bool dgpu_display_event;
1896};
1897
1898struct amdgpu_atif_functions {
1899 bool system_params;
1900 bool sbios_requests;
1901 bool select_active_disp;
1902 bool lid_state;
1903 bool get_tv_standard;
1904 bool set_tv_standard;
1905 bool get_panel_expansion_mode;
1906 bool set_panel_expansion_mode;
1907 bool temperature_change;
1908 bool graphics_device_types;
1909};
1910
1911struct amdgpu_atif {
1912 struct amdgpu_atif_notifications notifications;
1913 struct amdgpu_atif_functions functions;
1914 struct amdgpu_atif_notification_cfg notification_cfg;
1915 struct amdgpu_encoder *encoder_for_bl;
1916};
1917
1918struct amdgpu_atcs_functions {
1919 bool get_ext_state;
1920 bool pcie_perf_req;
1921 bool pcie_dev_rdy;
1922 bool pcie_bus_width;
1923};
1924
1925struct amdgpu_atcs {
1926 struct amdgpu_atcs_functions functions;
1927};
1928
Alex Deucher97b2e202015-04-20 16:51:00 -04001929/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001930 * CGS
1931 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001932struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1933void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001934
1935
Alex Deucher7e471e62016-02-01 11:13:04 -05001936/* GPU virtualization */
Andres Rodriguez048765a2016-06-11 02:51:32 -04001937#define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0)
1938#define AMDGPU_VIRT_CAPS_IS_VF (1 << 1)
Alex Deucher7e471e62016-02-01 11:13:04 -05001939struct amdgpu_virtualization {
1940 bool supports_sr_iov;
Andres Rodriguez048765a2016-06-11 02:51:32 -04001941 bool is_virtual;
1942 u32 caps;
Alex Deucher7e471e62016-02-01 11:13:04 -05001943};
1944
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001945/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001946 * Core structure, functions and helpers.
1947 */
1948typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1949typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1950
1951typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1952typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1953
Alex Deucher8faf0e02015-07-28 11:50:31 -04001954struct amdgpu_ip_block_status {
1955 bool valid;
1956 bool sw;
1957 bool hw;
1958};
1959
Alex Deucher97b2e202015-04-20 16:51:00 -04001960struct amdgpu_device {
1961 struct device *dev;
1962 struct drm_device *ddev;
1963 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001964
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001965#ifdef CONFIG_DRM_AMD_ACP
1966 struct amdgpu_acp acp;
1967#endif
1968
Alex Deucher97b2e202015-04-20 16:51:00 -04001969 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001970 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001971 uint32_t family;
1972 uint32_t rev_id;
1973 uint32_t external_rev_id;
1974 unsigned long flags;
1975 int usec_timeout;
1976 const struct amdgpu_asic_funcs *asic_funcs;
1977 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001978 bool need_dma32;
1979 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001980 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001981 struct notifier_block acpi_nb;
1982 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1983 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001984 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001985#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001986 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001987#endif
1988 struct amdgpu_atif atif;
1989 struct amdgpu_atcs atcs;
1990 struct mutex srbm_mutex;
1991 /* GRBM index mutex. Protects concurrent access to GRBM index */
1992 struct mutex grbm_idx_mutex;
1993 struct dev_pm_domain vga_pm_domain;
1994 bool have_disp_power_ref;
1995
1996 /* BIOS */
1997 uint8_t *bios;
1998 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001999 struct amdgpu_bo *stollen_vga_memory;
2000 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
2001
2002 /* Register/doorbell mmio */
2003 resource_size_t rmmio_base;
2004 resource_size_t rmmio_size;
2005 void __iomem *rmmio;
2006 /* protects concurrent MM_INDEX/DATA based register access */
2007 spinlock_t mmio_idx_lock;
2008 /* protects concurrent SMC based register access */
2009 spinlock_t smc_idx_lock;
2010 amdgpu_rreg_t smc_rreg;
2011 amdgpu_wreg_t smc_wreg;
2012 /* protects concurrent PCIE register access */
2013 spinlock_t pcie_idx_lock;
2014 amdgpu_rreg_t pcie_rreg;
2015 amdgpu_wreg_t pcie_wreg;
2016 /* protects concurrent UVD register access */
2017 spinlock_t uvd_ctx_idx_lock;
2018 amdgpu_rreg_t uvd_ctx_rreg;
2019 amdgpu_wreg_t uvd_ctx_wreg;
2020 /* protects concurrent DIDT register access */
2021 spinlock_t didt_idx_lock;
2022 amdgpu_rreg_t didt_rreg;
2023 amdgpu_wreg_t didt_wreg;
2024 /* protects concurrent ENDPOINT (audio) register access */
2025 spinlock_t audio_endpt_idx_lock;
2026 amdgpu_block_rreg_t audio_endpt_rreg;
2027 amdgpu_block_wreg_t audio_endpt_wreg;
2028 void __iomem *rio_mem;
2029 resource_size_t rio_mem_size;
2030 struct amdgpu_doorbell doorbell;
2031
2032 /* clock/pll info */
2033 struct amdgpu_clock clock;
2034
2035 /* MC */
2036 struct amdgpu_mc mc;
2037 struct amdgpu_gart gart;
2038 struct amdgpu_dummy_page dummy_page;
2039 struct amdgpu_vm_manager vm_manager;
2040
2041 /* memory management */
2042 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002043 struct amdgpu_vram_scratch vram_scratch;
2044 struct amdgpu_wb wb;
2045 atomic64_t vram_usage;
2046 atomic64_t vram_vis_usage;
2047 atomic64_t gtt_usage;
2048 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02002049 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02002050 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002051
2052 /* display */
2053 struct amdgpu_mode_info mode_info;
2054 struct work_struct hotplug_work;
2055 struct amdgpu_irq_src crtc_irq;
2056 struct amdgpu_irq_src pageflip_irq;
2057 struct amdgpu_irq_src hpd_irq;
2058
2059 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02002060 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002061 unsigned num_rings;
2062 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2063 bool ib_pool_ready;
2064 struct amdgpu_sa_manager ring_tmp_bo;
2065
2066 /* interrupts */
2067 struct amdgpu_irq irq;
2068
Alex Deucher1f7371b2015-12-02 17:46:21 -05002069 /* powerplay */
2070 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002071 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002072 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002073
Alex Deucher97b2e202015-04-20 16:51:00 -04002074 /* dpm */
2075 struct amdgpu_pm pm;
2076 u32 cg_flags;
2077 u32 pg_flags;
2078
2079 /* amdgpu smumgr */
2080 struct amdgpu_smumgr smu;
2081
2082 /* gfx */
2083 struct amdgpu_gfx gfx;
2084
2085 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002086 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002087
2088 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002089 struct amdgpu_uvd uvd;
2090
2091 /* vce */
2092 struct amdgpu_vce vce;
2093
2094 /* firmwares */
2095 struct amdgpu_firmware firmware;
2096
2097 /* GDS */
2098 struct amdgpu_gds gds;
2099
2100 const struct amdgpu_ip_block_version *ip_blocks;
2101 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002102 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002103 struct mutex mn_lock;
2104 DECLARE_HASHTABLE(mn_hash, 7);
2105
2106 /* tracking pinned memory */
2107 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002108 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002109 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002110
2111 /* amdkfd interface */
2112 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002113
Alex Deucher7e471e62016-02-01 11:13:04 -05002114 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002115};
2116
2117bool amdgpu_device_is_px(struct drm_device *dev);
2118int amdgpu_device_init(struct amdgpu_device *adev,
2119 struct drm_device *ddev,
2120 struct pci_dev *pdev,
2121 uint32_t flags);
2122void amdgpu_device_fini(struct amdgpu_device *adev);
2123int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2124
2125uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2126 bool always_indirect);
2127void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2128 bool always_indirect);
2129u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2130void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2131
2132u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2133void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2134
2135/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002136 * Registers read & write functions.
2137 */
2138#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2139#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2140#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2141#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2142#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2143#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2144#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2145#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2146#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2147#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2148#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2149#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2150#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2151#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2152#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2153#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2154#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2155#define WREG32_P(reg, val, mask) \
2156 do { \
2157 uint32_t tmp_ = RREG32(reg); \
2158 tmp_ &= (mask); \
2159 tmp_ |= ((val) & ~(mask)); \
2160 WREG32(reg, tmp_); \
2161 } while (0)
2162#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2163#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2164#define WREG32_PLL_P(reg, val, mask) \
2165 do { \
2166 uint32_t tmp_ = RREG32_PLL(reg); \
2167 tmp_ &= (mask); \
2168 tmp_ |= ((val) & ~(mask)); \
2169 WREG32_PLL(reg, tmp_); \
2170 } while (0)
2171#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2172#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2173#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2174
2175#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2176#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2177
2178#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2179#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2180
2181#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2182 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2183 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2184
2185#define REG_GET_FIELD(value, reg, field) \
2186 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2187
2188/*
2189 * BIOS helpers.
2190 */
2191#define RBIOS8(i) (adev->bios[i])
2192#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2193#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2194
2195/*
2196 * RING helpers.
2197 */
2198static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2199{
2200 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002201 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002202 ring->ring[ring->wptr++] = v;
2203 ring->wptr &= ring->ptr_mask;
2204 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002205}
2206
Alex Deucherc113ea12015-10-08 16:30:37 -04002207static inline struct amdgpu_sdma_instance *
2208amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002209{
2210 struct amdgpu_device *adev = ring->adev;
2211 int i;
2212
Alex Deucherc113ea12015-10-08 16:30:37 -04002213 for (i = 0; i < adev->sdma.num_instances; i++)
2214 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002215 break;
2216
2217 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002218 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002219 else
2220 return NULL;
2221}
2222
Alex Deucher97b2e202015-04-20 16:51:00 -04002223/*
2224 * ASICs macro.
2225 */
2226#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2227#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002228#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2229#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2230#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
Andres Rodriguez048765a2016-06-11 02:51:32 -04002231#define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002232#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002233#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 -04002234#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002235#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2236#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2237#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 +01002238#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 -04002239#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 -04002240#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2241#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2242#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002243#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2244#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2245#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002246#define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
Christian Königb8c7b392016-03-01 15:42:52 +01002247#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002248#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002249#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002250#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 +02002251#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002252#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002253#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002254#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2255#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04002256#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2257#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2258#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2259#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2260#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2261#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2262#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2263#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2264#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2265#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2266#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2267#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2268#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002269#define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
Alex Deucher97b2e202015-04-20 16:51:00 -04002270#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2271#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2272#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))
2273#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2274#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002275#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 +08002276#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 -04002277#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2278#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2279#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2280#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002281#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002282#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002283#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04002284#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Rex Zhu3af76f22015-10-15 17:23:43 +08002285
2286#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002287 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002288 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002289 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002290
2291#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002292 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002293 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002294 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002295
2296#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002297 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002298 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002299 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002300
2301#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002302 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002303 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002304 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002305
2306#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002307 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002308 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002309 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002310
Rex Zhu1b5708f2015-11-10 18:25:24 -05002311#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002312 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002313 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002314 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002315
2316#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002317 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002318 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002319 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002320
2321
2322#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002323 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002324 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002325 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002326
2327#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002328 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002329 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002330 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002331
2332#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002333 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002334 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002335 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002336
2337#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002338 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002339 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002340 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002341
2342#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002343 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002344
2345#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002346 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002347
Eric Huangf3898ea2015-12-11 16:24:34 -05002348#define amdgpu_dpm_get_pp_num_states(adev, data) \
2349 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2350
2351#define amdgpu_dpm_get_pp_table(adev, table) \
2352 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2353
2354#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2355 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2356
2357#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2358 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2359
2360#define amdgpu_dpm_force_clock_level(adev, type, level) \
2361 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2362
Eric Huang428bafa2016-05-12 14:51:21 -04002363#define amdgpu_dpm_get_sclk_od(adev) \
2364 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2365
2366#define amdgpu_dpm_set_sclk_od(adev, value) \
2367 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2368
Eric Huangf2bdc052016-05-24 15:11:17 -04002369#define amdgpu_dpm_get_mclk_od(adev) \
2370 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2371
2372#define amdgpu_dpm_set_mclk_od(adev, value) \
2373 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2374
Jammy Zhoue61710c2015-11-10 18:31:08 -05002375#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002376 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002377
2378#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2379
2380/* Common functions */
2381int amdgpu_gpu_reset(struct amdgpu_device *adev);
2382void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2383bool amdgpu_card_posted(struct amdgpu_device *adev);
2384void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002385
Alex Deucher97b2e202015-04-20 16:51:00 -04002386int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2387int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2388 u32 ip_instance, u32 ring,
2389 struct amdgpu_ring **out_ring);
2390void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2391bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002392int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002393int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2394 uint32_t flags);
2395bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002396struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002397bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2398 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002399bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2400 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002401bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2402uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2403 struct ttm_mem_reg *mem);
2404void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2405void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2406void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2407void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2408 const u32 *registers,
2409 const u32 array_size);
2410
2411bool amdgpu_device_is_px(struct drm_device *dev);
2412/* atpx handler */
2413#if defined(CONFIG_VGA_SWITCHEROO)
2414void amdgpu_register_atpx_handler(void);
2415void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002416bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002417bool amdgpu_is_atpx_hybrid(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002418#else
2419static inline void amdgpu_register_atpx_handler(void) {}
2420static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002421static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002422static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002423#endif
2424
2425/*
2426 * KMS
2427 */
2428extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002429extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002430
2431int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2432int amdgpu_driver_unload_kms(struct drm_device *dev);
2433void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2434int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2435void amdgpu_driver_postclose_kms(struct drm_device *dev,
2436 struct drm_file *file_priv);
2437void amdgpu_driver_preclose_kms(struct drm_device *dev,
2438 struct drm_file *file_priv);
2439int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2440int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002441u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2442int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2443void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2444int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002445 int *max_error,
2446 struct timeval *vblank_time,
2447 unsigned flags);
2448long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2449 unsigned long arg);
2450
2451/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002452 * functions used by amdgpu_encoder.c
2453 */
2454struct amdgpu_afmt_acr {
2455 u32 clock;
2456
2457 int n_32khz;
2458 int cts_32khz;
2459
2460 int n_44_1khz;
2461 int cts_44_1khz;
2462
2463 int n_48khz;
2464 int cts_48khz;
2465
2466};
2467
2468struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2469
2470/* amdgpu_acpi.c */
2471#if defined(CONFIG_ACPI)
2472int amdgpu_acpi_init(struct amdgpu_device *adev);
2473void amdgpu_acpi_fini(struct amdgpu_device *adev);
2474bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2475int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2476 u8 perf_req, bool advertise);
2477int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2478#else
2479static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2480static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2481#endif
2482
2483struct amdgpu_bo_va_mapping *
2484amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2485 uint64_t addr, struct amdgpu_bo **bo);
2486
2487#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002488#endif