blob: f41d23139a3a768d60fe5a629c71fef0c932d73c [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;
Alex Deucher97b2e202015-04-20 16:51:00 -040091
Chunming Zhou4b559c92015-07-21 15:53:04 +080092#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -040093#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
94#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
95/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
96#define AMDGPU_IB_POOL_SIZE 16
97#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
98#define AMDGPUFB_CONN_LIMIT 4
99#define AMDGPU_BIOS_NUM_SCRATCH 8
100
Alex Deucher97b2e202015-04-20 16:51:00 -0400101/* max number of rings */
102#define AMDGPU_MAX_RINGS 16
103#define AMDGPU_MAX_GFX_RINGS 1
104#define AMDGPU_MAX_COMPUTE_RINGS 8
105#define AMDGPU_MAX_VCE_RINGS 2
106
Jammy Zhou36f523a2015-09-01 12:54:27 +0800107/* max number of IP instances */
108#define AMDGPU_MAX_SDMA_INSTANCES 2
109
Alex Deucher97b2e202015-04-20 16:51:00 -0400110/* hardcode that limit for now */
111#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
112
113/* hard reset data */
114#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
115
116/* reset flags */
117#define AMDGPU_RESET_GFX (1 << 0)
118#define AMDGPU_RESET_COMPUTE (1 << 1)
119#define AMDGPU_RESET_DMA (1 << 2)
120#define AMDGPU_RESET_CP (1 << 3)
121#define AMDGPU_RESET_GRBM (1 << 4)
122#define AMDGPU_RESET_DMA1 (1 << 5)
123#define AMDGPU_RESET_RLC (1 << 6)
124#define AMDGPU_RESET_SEM (1 << 7)
125#define AMDGPU_RESET_IH (1 << 8)
126#define AMDGPU_RESET_VMC (1 << 9)
127#define AMDGPU_RESET_MC (1 << 10)
128#define AMDGPU_RESET_DISPLAY (1 << 11)
129#define AMDGPU_RESET_UVD (1 << 12)
130#define AMDGPU_RESET_VCE (1 << 13)
131#define AMDGPU_RESET_VCE1 (1 << 14)
132
Alex Deucher97b2e202015-04-20 16:51:00 -0400133/* GFX current status */
134#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
135#define AMDGPU_GFX_SAFE_MODE 0x00000001L
136#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
137#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
138#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
139
140/* max cursor sizes (in pixels) */
141#define CIK_CURSOR_WIDTH 128
142#define CIK_CURSOR_HEIGHT 128
143
144struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400145struct amdgpu_ib;
146struct amdgpu_vm;
147struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400148struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800149struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400150struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400151struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400152
153enum amdgpu_cp_irq {
154 AMDGPU_CP_IRQ_GFX_EOP = 0,
155 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
156 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
157 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
158 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
159 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
160 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
161 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
162 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
163
164 AMDGPU_CP_IRQ_LAST
165};
166
167enum amdgpu_sdma_irq {
168 AMDGPU_SDMA_IRQ_TRAP0 = 0,
169 AMDGPU_SDMA_IRQ_TRAP1,
170
171 AMDGPU_SDMA_IRQ_LAST
172};
173
174enum amdgpu_thermal_irq {
175 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
176 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
177
178 AMDGPU_THERMAL_IRQ_LAST
179};
180
Alex Deucher97b2e202015-04-20 16:51:00 -0400181int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400182 enum amd_ip_block_type block_type,
183 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400184int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400185 enum amd_ip_block_type block_type,
186 enum amd_powergating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400187
188struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400189 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400190 u32 major;
191 u32 minor;
192 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400193 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400194};
195
196int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400197 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400198 u32 major, u32 minor);
199
200const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
201 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400202 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400203
204/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
205struct amdgpu_buffer_funcs {
206 /* maximum bytes in a single operation */
207 uint32_t copy_max_bytes;
208
209 /* number of dw to reserve per operation */
210 unsigned copy_num_dw;
211
212 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800213 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400214 /* src addr in bytes */
215 uint64_t src_offset,
216 /* dst addr in bytes */
217 uint64_t dst_offset,
218 /* number of byte to transfer */
219 uint32_t byte_count);
220
221 /* maximum bytes in a single operation */
222 uint32_t fill_max_bytes;
223
224 /* number of dw to reserve per operation */
225 unsigned fill_num_dw;
226
227 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800228 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400229 /* value to write to memory */
230 uint32_t src_data,
231 /* dst addr in bytes */
232 uint64_t dst_offset,
233 /* number of byte to fill */
234 uint32_t byte_count);
235};
236
237/* provided by hw blocks that can write ptes, e.g., sdma */
238struct amdgpu_vm_pte_funcs {
239 /* copy pte entries from GART */
240 void (*copy_pte)(struct amdgpu_ib *ib,
241 uint64_t pe, uint64_t src,
242 unsigned count);
243 /* write pte one entry at a time with addr mapping */
244 void (*write_pte)(struct amdgpu_ib *ib,
Christian Königb07c9d22015-11-30 13:26:07 +0100245 const dma_addr_t *pages_addr, uint64_t pe,
Alex Deucher97b2e202015-04-20 16:51:00 -0400246 uint64_t addr, unsigned count,
247 uint32_t incr, uint32_t flags);
248 /* for linear pte/pde updates without addr mapping */
249 void (*set_pte_pde)(struct amdgpu_ib *ib,
250 uint64_t pe,
251 uint64_t addr, unsigned count,
252 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400253};
254
255/* provided by the gmc block */
256struct amdgpu_gart_funcs {
257 /* flush the vm tlb via mmio */
258 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
259 uint32_t vmid);
260 /* write pte/pde updates using the cpu */
261 int (*set_pte_pde)(struct amdgpu_device *adev,
262 void *cpu_pt_addr, /* cpu addr of page table */
263 uint32_t gpu_page_idx, /* pte/pde to update */
264 uint64_t addr, /* addr to write into pte/pde */
265 uint32_t flags); /* access flags */
266};
267
268/* provided by the ih block */
269struct amdgpu_ih_funcs {
270 /* ring read/write ptr handling, called from interrupt context */
271 u32 (*get_wptr)(struct amdgpu_device *adev);
272 void (*decode_iv)(struct amdgpu_device *adev,
273 struct amdgpu_iv_entry *entry);
274 void (*set_rptr)(struct amdgpu_device *adev);
275};
276
277/* provided by hw blocks that expose a ring buffer for commands */
278struct amdgpu_ring_funcs {
279 /* ring read/write ptr handling */
280 u32 (*get_rptr)(struct amdgpu_ring *ring);
281 u32 (*get_wptr)(struct amdgpu_ring *ring);
282 void (*set_wptr)(struct amdgpu_ring *ring);
283 /* validating and patching of IBs */
284 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
285 /* command emit functions */
286 void (*emit_ib)(struct amdgpu_ring *ring,
Christian Königd88bf582016-05-06 17:50:03 +0200287 struct amdgpu_ib *ib,
288 unsigned vm_id, bool ctx_switch);
Alex Deucher97b2e202015-04-20 16:51:00 -0400289 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800290 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100291 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400292 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
293 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200294 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800295 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400296 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
297 uint32_t gds_base, uint32_t gds_size,
298 uint32_t gws_base, uint32_t gws_size,
299 uint32_t oa_base, uint32_t oa_size);
300 /* testing functions */
301 int (*test_ring)(struct amdgpu_ring *ring);
302 int (*test_ib)(struct amdgpu_ring *ring);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800303 /* insert NOP packets */
304 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100305 /* pad the indirect buffer to the necessary number of dw */
306 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800307 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
308 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Alex Deucher97b2e202015-04-20 16:51:00 -0400309};
310
311/*
312 * BIOS.
313 */
314bool amdgpu_get_bios(struct amdgpu_device *adev);
315bool amdgpu_read_bios(struct amdgpu_device *adev);
316
317/*
318 * Dummy page
319 */
320struct amdgpu_dummy_page {
321 struct page *page;
322 dma_addr_t addr;
323};
324int amdgpu_dummy_page_init(struct amdgpu_device *adev);
325void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
326
327
328/*
329 * Clocks
330 */
331
332#define AMDGPU_MAX_PPLL 3
333
334struct amdgpu_clock {
335 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
336 struct amdgpu_pll spll;
337 struct amdgpu_pll mpll;
338 /* 10 Khz units */
339 uint32_t default_mclk;
340 uint32_t default_sclk;
341 uint32_t default_dispclk;
342 uint32_t current_dispclk;
343 uint32_t dp_extclk;
344 uint32_t max_pixel_clock;
345};
346
347/*
348 * Fences.
349 */
350struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400351 uint64_t gpu_addr;
352 volatile uint32_t *cpu_addr;
353 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100354 uint32_t sync_seq;
355 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400356 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400357 struct amdgpu_irq_src *irq_src;
358 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100359 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100360 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100361 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100362 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400363};
364
365/* some special values for the owner field */
366#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
367#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400368
Chunming Zhou890ee232015-06-01 14:35:03 +0800369#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
370#define AMDGPU_FENCE_FLAG_INT (1 << 1)
371
Alex Deucher97b2e202015-04-20 16:51:00 -0400372int amdgpu_fence_driver_init(struct amdgpu_device *adev);
373void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
374void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
375
Christian Könige6151a02016-03-15 14:52:26 +0100376int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
377 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400378int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
379 struct amdgpu_irq_src *irq_src,
380 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400381void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
382void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100383int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400384void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400385int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
386unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
387
Alex Deucher97b2e202015-04-20 16:51:00 -0400388/*
389 * TTM.
390 */
Christian König29b32592016-04-15 17:19:16 +0200391
392#define AMDGPU_TTM_LRU_SIZE 20
393
394struct amdgpu_mman_lru {
395 struct list_head *lru[TTM_NUM_MEM_TYPES];
396 struct list_head *swap_lru;
397};
398
Alex Deucher97b2e202015-04-20 16:51:00 -0400399struct amdgpu_mman {
400 struct ttm_bo_global_ref bo_global_ref;
401 struct drm_global_reference mem_global_ref;
402 struct ttm_bo_device bdev;
403 bool mem_global_referenced;
404 bool initialized;
405
406#if defined(CONFIG_DEBUG_FS)
407 struct dentry *vram;
408 struct dentry *gtt;
409#endif
410
411 /* buffer handling */
412 const struct amdgpu_buffer_funcs *buffer_funcs;
413 struct amdgpu_ring *buffer_funcs_ring;
Christian König703297c2016-02-10 14:20:50 +0100414 /* Scheduler entity for buffer moves */
415 struct amd_sched_entity entity;
Christian König29b32592016-04-15 17:19:16 +0200416
417 /* custom LRU management */
418 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE];
Alex Deucher97b2e202015-04-20 16:51:00 -0400419};
420
421int amdgpu_copy_buffer(struct amdgpu_ring *ring,
422 uint64_t src_offset,
423 uint64_t dst_offset,
424 uint32_t byte_count,
425 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800426 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400427int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
428
429struct amdgpu_bo_list_entry {
430 struct amdgpu_bo *robj;
431 struct ttm_validate_buffer tv;
432 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400433 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100434 struct page **user_pages;
435 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400436};
437
438struct amdgpu_bo_va_mapping {
439 struct list_head list;
440 struct interval_tree_node it;
441 uint64_t offset;
442 uint32_t flags;
443};
444
445/* bo virtual addresses in a specific vm */
446struct amdgpu_bo_va {
447 /* protected by bo being reserved */
448 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800449 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400450 unsigned ref_count;
451
Christian König7fc11952015-07-30 11:53:42 +0200452 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400453 struct list_head vm_status;
454
Christian König7fc11952015-07-30 11:53:42 +0200455 /* mappings for this bo_va */
456 struct list_head invalids;
457 struct list_head valids;
458
Alex Deucher97b2e202015-04-20 16:51:00 -0400459 /* constant after initialization */
460 struct amdgpu_vm *vm;
461 struct amdgpu_bo *bo;
462};
463
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800464#define AMDGPU_GEM_DOMAIN_MAX 0x3
465
Alex Deucher97b2e202015-04-20 16:51:00 -0400466struct amdgpu_bo {
467 /* Protected by gem.mutex */
468 struct list_head list;
469 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100470 u32 prefered_domains;
471 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800472 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400473 struct ttm_placement placement;
474 struct ttm_buffer_object tbo;
475 struct ttm_bo_kmap_obj kmap;
476 u64 flags;
477 unsigned pin_count;
478 void *kptr;
479 u64 tiling_flags;
480 u64 metadata_flags;
481 void *metadata;
482 u32 metadata_size;
483 /* list of all virtual address to which this bo
484 * is associated to
485 */
486 struct list_head va;
487 /* Constant after initialization */
488 struct amdgpu_device *adev;
489 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100490 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400491
492 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400493 struct amdgpu_mn *mn;
494 struct list_head mn_list;
495};
496#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
497
498void amdgpu_gem_object_free(struct drm_gem_object *obj);
499int amdgpu_gem_object_open(struct drm_gem_object *obj,
500 struct drm_file *file_priv);
501void amdgpu_gem_object_close(struct drm_gem_object *obj,
502 struct drm_file *file_priv);
503unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
504struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200505struct drm_gem_object *
506amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
507 struct dma_buf_attachment *attach,
508 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400509struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
510 struct drm_gem_object *gobj,
511 int flags);
512int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
513void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
514struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
515void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
516void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
517int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
518
519/* sub-allocation manager, it has to be protected by another lock.
520 * By conception this is an helper for other part of the driver
521 * like the indirect buffer or semaphore, which both have their
522 * locking.
523 *
524 * Principe is simple, we keep a list of sub allocation in offset
525 * order (first entry has offset == 0, last entry has the highest
526 * offset).
527 *
528 * When allocating new object we first check if there is room at
529 * the end total_size - (last_object_offset + last_object_size) >=
530 * alloc_size. If so we allocate new object there.
531 *
532 * When there is not enough room at the end, we start waiting for
533 * each sub object until we reach object_offset+object_size >=
534 * alloc_size, this object then become the sub object we return.
535 *
536 * Alignment can't be bigger than page size.
537 *
538 * Hole are not considered for allocation to keep things simple.
539 * Assumption is that there won't be hole (all object on same
540 * alignment).
541 */
Christian König6ba60b82016-03-11 14:50:08 +0100542
543#define AMDGPU_SA_NUM_FENCE_LISTS 32
544
Alex Deucher97b2e202015-04-20 16:51:00 -0400545struct amdgpu_sa_manager {
546 wait_queue_head_t wq;
547 struct amdgpu_bo *bo;
548 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100549 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400550 struct list_head olist;
551 unsigned size;
552 uint64_t gpu_addr;
553 void *cpu_ptr;
554 uint32_t domain;
555 uint32_t align;
556};
557
Alex Deucher97b2e202015-04-20 16:51:00 -0400558/* sub-allocation buffer */
559struct amdgpu_sa_bo {
560 struct list_head olist;
561 struct list_head flist;
562 struct amdgpu_sa_manager *manager;
563 unsigned soffset;
564 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800565 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400566};
567
568/*
569 * GEM objects.
570 */
Christian König418aa0c2016-02-15 16:59:57 +0100571void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400572int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
573 int alignment, u32 initial_domain,
574 u64 flags, bool kernel,
575 struct drm_gem_object **obj);
576
577int amdgpu_mode_dumb_create(struct drm_file *file_priv,
578 struct drm_device *dev,
579 struct drm_mode_create_dumb *args);
580int amdgpu_mode_dumb_mmap(struct drm_file *filp,
581 struct drm_device *dev,
582 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400583/*
584 * Synchronization
585 */
586struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800587 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800588 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400589};
590
591void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200592int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
593 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400594int amdgpu_sync_resv(struct amdgpu_device *adev,
595 struct amdgpu_sync *sync,
596 struct reservation_object *resv,
597 void *owner);
Christian König832a9022016-02-15 12:33:02 +0100598bool amdgpu_sync_is_idle(struct amdgpu_sync *sync);
599int amdgpu_sync_cycle_fences(struct amdgpu_sync *dst, struct amdgpu_sync *src,
600 struct fence *fence);
Christian Könige61235d2015-08-25 11:05:36 +0200601struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian Königf91b3a62015-08-20 14:47:40 +0800602int amdgpu_sync_wait(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100603void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100604int amdgpu_sync_init(void);
605void amdgpu_sync_fini(void);
Rex Zhud573de22016-05-12 13:27:28 +0800606int amdgpu_fence_slab_init(void);
607void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400608
609/*
610 * GART structures, functions & helpers
611 */
612struct amdgpu_mc;
613
614#define AMDGPU_GPU_PAGE_SIZE 4096
615#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
616#define AMDGPU_GPU_PAGE_SHIFT 12
617#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
618
619struct amdgpu_gart {
620 dma_addr_t table_addr;
621 struct amdgpu_bo *robj;
622 void *ptr;
623 unsigned num_gpu_pages;
624 unsigned num_cpu_pages;
625 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200626#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400627 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200628#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400629 bool ready;
630 const struct amdgpu_gart_funcs *gart_funcs;
631};
632
633int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
634void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
635int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
636void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
637int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
638void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
639int amdgpu_gart_init(struct amdgpu_device *adev);
640void amdgpu_gart_fini(struct amdgpu_device *adev);
641void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
642 int pages);
643int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
644 int pages, struct page **pagelist,
645 dma_addr_t *dma_addr, uint32_t flags);
646
647/*
648 * GPU MC structures, functions & helpers
649 */
650struct amdgpu_mc {
651 resource_size_t aper_size;
652 resource_size_t aper_base;
653 resource_size_t agp_base;
654 /* for some chips with <= 32MB we need to lie
655 * about vram size near mc fb location */
656 u64 mc_vram_size;
657 u64 visible_vram_size;
658 u64 gtt_size;
659 u64 gtt_start;
660 u64 gtt_end;
661 u64 vram_start;
662 u64 vram_end;
663 unsigned vram_width;
664 u64 real_vram_size;
665 int vram_mtrr;
666 u64 gtt_base_align;
667 u64 mc_mask;
668 const struct firmware *fw; /* MC firmware */
669 uint32_t fw_version;
670 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800671 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400672};
673
674/*
675 * GPU doorbell structures, functions & helpers
676 */
677typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
678{
679 AMDGPU_DOORBELL_KIQ = 0x000,
680 AMDGPU_DOORBELL_HIQ = 0x001,
681 AMDGPU_DOORBELL_DIQ = 0x002,
682 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
683 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
684 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
685 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
686 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
687 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
688 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
689 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
690 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
691 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
692 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
693 AMDGPU_DOORBELL_IH = 0x1E8,
694 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
695 AMDGPU_DOORBELL_INVALID = 0xFFFF
696} AMDGPU_DOORBELL_ASSIGNMENT;
697
698struct amdgpu_doorbell {
699 /* doorbell mmio */
700 resource_size_t base;
701 resource_size_t size;
702 u32 __iomem *ptr;
703 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
704};
705
706void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
707 phys_addr_t *aperture_base,
708 size_t *aperture_size,
709 size_t *start_offset);
710
711/*
712 * IRQS.
713 */
714
715struct amdgpu_flip_work {
716 struct work_struct flip_work;
717 struct work_struct unpin_work;
718 struct amdgpu_device *adev;
719 int crtc_id;
720 uint64_t base;
721 struct drm_pending_vblank_event *event;
722 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200723 struct fence *excl;
724 unsigned shared_count;
725 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100726 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400727 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400728};
729
730
731/*
732 * CP & rings.
733 */
734
735struct amdgpu_ib {
736 struct amdgpu_sa_bo *sa_bo;
737 uint32_t length_dw;
738 uint64_t gpu_addr;
739 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800740 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400741};
742
743enum amdgpu_ring_type {
744 AMDGPU_RING_TYPE_GFX,
745 AMDGPU_RING_TYPE_COMPUTE,
746 AMDGPU_RING_TYPE_SDMA,
747 AMDGPU_RING_TYPE_UVD,
748 AMDGPU_RING_TYPE_VCE
749};
750
Nils Wallménius62250a92016-04-10 16:30:00 +0200751extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800752
Christian König50838c82016-02-03 13:44:52 +0100753int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800754 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100755int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
756 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800757
Christian König50838c82016-02-03 13:44:52 +0100758void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100759int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100760 struct amd_sched_entity *entity, void *owner,
761 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800762
Alex Deucher97b2e202015-04-20 16:51:00 -0400763struct amdgpu_ring {
764 struct amdgpu_device *adev;
765 const struct amdgpu_ring_funcs *funcs;
766 struct amdgpu_fence_driver fence_drv;
Christian Königedf600d2016-05-03 15:54:54 +0200767 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400768
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800769 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400770 struct amdgpu_bo *ring_obj;
771 volatile uint32_t *ring;
772 unsigned rptr_offs;
773 u64 next_rptr_gpu_addr;
774 volatile u32 *next_rptr_cpu_addr;
775 unsigned wptr;
776 unsigned wptr_old;
777 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100778 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400779 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400780 uint64_t gpu_addr;
781 uint32_t align_mask;
782 uint32_t ptr_mask;
783 bool ready;
784 u32 nop;
785 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400786 u32 me;
787 u32 pipe;
788 u32 queue;
789 struct amdgpu_bo *mqd_obj;
790 u32 doorbell_index;
791 bool use_doorbell;
792 unsigned wptr_offs;
793 unsigned next_rptr_offs;
794 unsigned fence_offs;
Christian Königaa3b73f2016-05-03 15:17:40 +0200795 uint64_t current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400796 enum amdgpu_ring_type type;
797 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800798 unsigned cond_exe_offs;
799 u64 cond_exe_gpu_addr;
800 volatile u32 *cond_exe_cpu_addr;
Monk Liua909c6b2016-06-14 12:02:21 -0400801#if defined(CONFIG_DEBUG_FS)
802 struct dentry *ent;
803#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400804};
805
806/*
807 * VM
808 */
809
810/* maximum number of VMIDs */
811#define AMDGPU_NUM_VM 16
812
813/* number of entries in page table */
814#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
815
816/* PTBs (Page Table Blocks) need to be aligned to 32K */
817#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
818#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
819#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
820
821#define AMDGPU_PTE_VALID (1 << 0)
822#define AMDGPU_PTE_SYSTEM (1 << 1)
823#define AMDGPU_PTE_SNOOPED (1 << 2)
824
825/* VI only */
826#define AMDGPU_PTE_EXECUTABLE (1 << 4)
827
828#define AMDGPU_PTE_READABLE (1 << 5)
829#define AMDGPU_PTE_WRITEABLE (1 << 6)
830
831/* PTE (Page Table Entry) fragment field for different page sizes */
832#define AMDGPU_PTE_FRAG_4KB (0 << 7)
833#define AMDGPU_PTE_FRAG_64KB (4 << 7)
834#define AMDGPU_LOG2_PAGES_PER_FRAG 4
835
Christian Königd9c13152015-09-28 12:31:26 +0200836/* How to programm VM fault handling */
837#define AMDGPU_VM_FAULT_STOP_NEVER 0
838#define AMDGPU_VM_FAULT_STOP_FIRST 1
839#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
840
Alex Deucher97b2e202015-04-20 16:51:00 -0400841struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100842 struct amdgpu_bo_list_entry entry;
843 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400844};
845
Alex Deucher97b2e202015-04-20 16:51:00 -0400846struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100847 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400848 struct rb_root va;
849
Christian König7fc11952015-07-30 11:53:42 +0200850 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400851 spinlock_t status_lock;
852
853 /* BOs moved, but not yet updated in the PT */
854 struct list_head invalidated;
855
Christian König7fc11952015-07-30 11:53:42 +0200856 /* BOs cleared in the PT because of a move */
857 struct list_head cleared;
858
859 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400860 struct list_head freed;
861
862 /* contains the page directory */
863 struct amdgpu_bo *page_directory;
864 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200865 struct fence *page_directory_fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400866
867 /* array of page tables, one for each page directory entry */
868 struct amdgpu_vm_pt *page_tables;
869
870 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100871 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100872
jimqu81d75a32015-12-04 17:17:00 +0800873 /* protecting freed */
874 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100875
876 /* Scheduler entity for page table updates */
877 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800878
879 /* client id */
880 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400881};
882
Christian Königbcb1ba32016-03-08 15:40:11 +0100883struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100884 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100885 struct fence *first;
886 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100887 struct fence *last_flush;
Chunming Zhou68befeb2016-04-14 13:42:32 +0800888 struct amdgpu_ring *last_user;
Christian König0ea54b92016-05-04 10:20:01 +0200889 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100890
Christian Königbcb1ba32016-03-08 15:40:11 +0100891 uint64_t pd_gpu_addr;
892 /* last flushed PD/PT update */
893 struct fence *flushed_updates;
894
Christian König971fe9a92016-03-01 15:09:25 +0100895 uint32_t gds_base;
896 uint32_t gds_size;
897 uint32_t gws_base;
898 uint32_t gws_size;
899 uint32_t oa_base;
900 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100901};
Christian König8d0a7ce2015-11-03 20:58:50 +0100902
Christian Königa9a78b32016-01-21 10:19:11 +0100903struct amdgpu_vm_manager {
904 /* Handling of VMIDs */
905 struct mutex lock;
906 unsigned num_ids;
907 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100908 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100909
Christian König8b4fb002015-11-15 16:04:16 +0100910 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400911 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100912 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400913 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100914 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400915 /* vm pte handling */
916 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100917 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
918 unsigned vm_pte_num_rings;
919 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800920 /* client id counter */
921 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400922};
923
Christian Königa9a78b32016-01-21 10:19:11 +0100924void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100925void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100926int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
927void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100928void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
929 struct list_head *validated,
930 struct amdgpu_bo_list_entry *entry);
Christian Königee1782c2015-12-11 21:01:23 +0100931void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100932void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
933 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100934int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100935 struct amdgpu_sync *sync, struct fence *fence,
936 unsigned *vm_id, uint64_t *vm_pd_addr);
Christian König41d9eb22016-03-01 16:46:18 +0100937int amdgpu_vm_flush(struct amdgpu_ring *ring,
938 unsigned vm_id, uint64_t pd_addr,
939 uint32_t gds_base, uint32_t gds_size,
940 uint32_t gws_base, uint32_t gws_size,
941 uint32_t oa_base, uint32_t oa_size);
Christian König971fe9a92016-03-01 15:09:25 +0100942void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian Königb07c9d22015-11-30 13:26:07 +0100943uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
Christian König8b4fb002015-11-15 16:04:16 +0100944int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
945 struct amdgpu_vm *vm);
946int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
947 struct amdgpu_vm *vm);
948int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
949 struct amdgpu_sync *sync);
950int amdgpu_vm_bo_update(struct amdgpu_device *adev,
951 struct amdgpu_bo_va *bo_va,
952 struct ttm_mem_reg *mem);
953void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
954 struct amdgpu_bo *bo);
955struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
956 struct amdgpu_bo *bo);
957struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
958 struct amdgpu_vm *vm,
959 struct amdgpu_bo *bo);
960int amdgpu_vm_bo_map(struct amdgpu_device *adev,
961 struct amdgpu_bo_va *bo_va,
962 uint64_t addr, uint64_t offset,
963 uint64_t size, uint32_t flags);
964int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
965 struct amdgpu_bo_va *bo_va,
966 uint64_t addr);
967void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
968 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100969
Alex Deucher97b2e202015-04-20 16:51:00 -0400970/*
971 * context related structures
972 */
973
Christian König21c16bf2015-07-07 17:24:49 +0200974struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200975 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800976 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200977 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200978};
979
Alex Deucher97b2e202015-04-20 16:51:00 -0400980struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400981 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800982 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400983 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200984 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800985 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200986 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400987};
988
989struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400990 struct amdgpu_device *adev;
991 struct mutex lock;
992 /* protected by lock */
993 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400994};
995
Alex Deucher0b492a42015-08-16 22:48:26 -0400996struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
997int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
998
Christian König21c16bf2015-07-07 17:24:49 +0200999uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +02001000 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +02001001struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
1002 struct amdgpu_ring *ring, uint64_t seq);
1003
Alex Deucher0b492a42015-08-16 22:48:26 -04001004int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1005 struct drm_file *filp);
1006
Christian Königefd4ccb2015-08-04 16:20:31 +02001007void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1008void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -04001009
Alex Deucher97b2e202015-04-20 16:51:00 -04001010/*
1011 * file private structure
1012 */
1013
1014struct amdgpu_fpriv {
1015 struct amdgpu_vm vm;
1016 struct mutex bo_list_lock;
1017 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001018 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001019};
1020
1021/*
1022 * residency list
1023 */
1024
1025struct amdgpu_bo_list {
1026 struct mutex lock;
1027 struct amdgpu_bo *gds_obj;
1028 struct amdgpu_bo *gws_obj;
1029 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001030 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001031 unsigned num_entries;
1032 struct amdgpu_bo_list_entry *array;
1033};
1034
1035struct amdgpu_bo_list *
1036amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001037void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1038 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001039void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1040void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1041
1042/*
1043 * GFX stuff
1044 */
1045#include "clearstate_defs.h"
1046
Alex Deucher79e54122016-04-08 15:45:13 -04001047struct amdgpu_rlc_funcs {
1048 void (*enter_safe_mode)(struct amdgpu_device *adev);
1049 void (*exit_safe_mode)(struct amdgpu_device *adev);
1050};
1051
Alex Deucher97b2e202015-04-20 16:51:00 -04001052struct amdgpu_rlc {
1053 /* for power gating */
1054 struct amdgpu_bo *save_restore_obj;
1055 uint64_t save_restore_gpu_addr;
1056 volatile uint32_t *sr_ptr;
1057 const u32 *reg_list;
1058 u32 reg_list_size;
1059 /* for clear state */
1060 struct amdgpu_bo *clear_state_obj;
1061 uint64_t clear_state_gpu_addr;
1062 volatile uint32_t *cs_ptr;
1063 const struct cs_section_def *cs_data;
1064 u32 clear_state_size;
1065 /* for cp tables */
1066 struct amdgpu_bo *cp_table_obj;
1067 uint64_t cp_table_gpu_addr;
1068 volatile uint32_t *cp_table_ptr;
1069 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001070
1071 /* safe mode for updating CG/PG state */
1072 bool in_safe_mode;
1073 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001074
1075 /* for firmware data */
1076 u32 save_and_restore_offset;
1077 u32 clear_state_descriptor_offset;
1078 u32 avail_scratch_ram_locations;
1079 u32 reg_restore_list_size;
1080 u32 reg_list_format_start;
1081 u32 reg_list_format_separate_start;
1082 u32 starting_offsets_start;
1083 u32 reg_list_format_size_bytes;
1084 u32 reg_list_size_bytes;
1085
1086 u32 *register_list_format;
1087 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001088};
1089
1090struct amdgpu_mec {
1091 struct amdgpu_bo *hpd_eop_obj;
1092 u64 hpd_eop_gpu_addr;
1093 u32 num_pipe;
1094 u32 num_mec;
1095 u32 num_queue;
1096};
1097
1098/*
1099 * GPU scratch registers structures, functions & helpers
1100 */
1101struct amdgpu_scratch {
1102 unsigned num_reg;
1103 uint32_t reg_base;
1104 bool free[32];
1105 uint32_t reg[32];
1106};
1107
1108/*
1109 * GFX configurations
1110 */
1111struct amdgpu_gca_config {
1112 unsigned max_shader_engines;
1113 unsigned max_tile_pipes;
1114 unsigned max_cu_per_sh;
1115 unsigned max_sh_per_se;
1116 unsigned max_backends_per_se;
1117 unsigned max_texture_channel_caches;
1118 unsigned max_gprs;
1119 unsigned max_gs_threads;
1120 unsigned max_hw_contexts;
1121 unsigned sc_prim_fifo_size_frontend;
1122 unsigned sc_prim_fifo_size_backend;
1123 unsigned sc_hiz_tile_fifo_size;
1124 unsigned sc_earlyz_tile_fifo_size;
1125
1126 unsigned num_tile_pipes;
1127 unsigned backend_enable_mask;
1128 unsigned mem_max_burst_length_bytes;
1129 unsigned mem_row_size_in_kb;
1130 unsigned shader_engine_tile_size;
1131 unsigned num_gpus;
1132 unsigned multi_gpu_tile_size;
1133 unsigned mc_arb_ramcfg;
1134 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001135 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001136
1137 uint32_t tile_mode_array[32];
1138 uint32_t macrotile_mode_array[16];
1139};
1140
Alex Deucher7dae69a2016-05-03 16:25:53 -04001141struct amdgpu_cu_info {
1142 uint32_t number; /* total active CU number */
1143 uint32_t ao_cu_mask;
1144 uint32_t bitmap[4][4];
1145};
1146
Alex Deucher97b2e202015-04-20 16:51:00 -04001147struct amdgpu_gfx {
1148 struct mutex gpu_clock_mutex;
1149 struct amdgpu_gca_config config;
1150 struct amdgpu_rlc rlc;
1151 struct amdgpu_mec mec;
1152 struct amdgpu_scratch scratch;
1153 const struct firmware *me_fw; /* ME firmware */
1154 uint32_t me_fw_version;
1155 const struct firmware *pfp_fw; /* PFP firmware */
1156 uint32_t pfp_fw_version;
1157 const struct firmware *ce_fw; /* CE firmware */
1158 uint32_t ce_fw_version;
1159 const struct firmware *rlc_fw; /* RLC firmware */
1160 uint32_t rlc_fw_version;
1161 const struct firmware *mec_fw; /* MEC firmware */
1162 uint32_t mec_fw_version;
1163 const struct firmware *mec2_fw; /* MEC2 firmware */
1164 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001165 uint32_t me_feature_version;
1166 uint32_t ce_feature_version;
1167 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001168 uint32_t rlc_feature_version;
1169 uint32_t mec_feature_version;
1170 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001171 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1172 unsigned num_gfx_rings;
1173 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1174 unsigned num_compute_rings;
1175 struct amdgpu_irq_src eop_irq;
1176 struct amdgpu_irq_src priv_reg_irq;
1177 struct amdgpu_irq_src priv_inst_irq;
1178 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001179 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001180 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001181 unsigned ce_ram_size;
1182 struct amdgpu_cu_info cu_info;
Alex Deucher97b2e202015-04-20 16:51:00 -04001183};
1184
Christian Königb07c60c2016-01-31 12:29:04 +01001185int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001186 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001187void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1188 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001189int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001190 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001191 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001192int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1193void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1194int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001195int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001196void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001197void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001198void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001199void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001200unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1201 uint32_t **data);
1202int amdgpu_ring_restore(struct amdgpu_ring *ring,
1203 unsigned size, uint32_t *data);
1204int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1205 unsigned ring_size, u32 nop, u32 align_mask,
1206 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1207 enum amdgpu_ring_type ring_type);
1208void amdgpu_ring_fini(struct amdgpu_ring *ring);
1209
1210/*
1211 * CS.
1212 */
1213struct amdgpu_cs_chunk {
1214 uint32_t chunk_id;
1215 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001216 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001217};
1218
1219struct amdgpu_cs_parser {
1220 struct amdgpu_device *adev;
1221 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001222 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001223
Alex Deucher97b2e202015-04-20 16:51:00 -04001224 /* chunks */
1225 unsigned nchunks;
1226 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001227
Christian König50838c82016-02-03 13:44:52 +01001228 /* scheduler job object */
1229 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001230
Christian Königc3cca412015-12-15 14:41:33 +01001231 /* buffer objects */
1232 struct ww_acquire_ctx ticket;
1233 struct amdgpu_bo_list *bo_list;
1234 struct amdgpu_bo_list_entry vm_pd;
1235 struct list_head validated;
1236 struct fence *fence;
1237 uint64_t bytes_moved_threshold;
1238 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001239
1240 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001241 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001242};
1243
Chunming Zhoubb977d32015-08-18 15:16:40 +08001244struct amdgpu_job {
1245 struct amd_sched_job base;
1246 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001247 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001248 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001249 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001250 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001251 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001252 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001253 void *owner;
Christian König92f25092016-05-06 15:57:42 +02001254 uint64_t ctx;
Christian Königd88bf582016-05-06 17:50:03 +02001255 unsigned vm_id;
1256 uint64_t vm_pd_addr;
1257 uint32_t gds_base, gds_size;
1258 uint32_t gws_base, gws_size;
1259 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001260
1261 /* user fence handling */
1262 struct amdgpu_bo *uf_bo;
1263 uint32_t uf_offset;
1264 uint64_t uf_sequence;
1265
Chunming Zhoubb977d32015-08-18 15:16:40 +08001266};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001267#define to_amdgpu_job(sched_job) \
1268 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001269
Christian König7270f832016-01-31 11:00:41 +01001270static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1271 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001272{
Christian König50838c82016-02-03 13:44:52 +01001273 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001274}
1275
Christian König7270f832016-01-31 11:00:41 +01001276static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1277 uint32_t ib_idx, int idx,
1278 uint32_t value)
1279{
Christian König50838c82016-02-03 13:44:52 +01001280 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001281}
1282
Alex Deucher97b2e202015-04-20 16:51:00 -04001283/*
1284 * Writeback
1285 */
1286#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1287
1288struct amdgpu_wb {
1289 struct amdgpu_bo *wb_obj;
1290 volatile uint32_t *wb;
1291 uint64_t gpu_addr;
1292 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1293 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1294};
1295
1296int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1297void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1298
Alex Deucher97b2e202015-04-20 16:51:00 -04001299
Alex Deucher97b2e202015-04-20 16:51:00 -04001300
1301enum amdgpu_int_thermal_type {
1302 THERMAL_TYPE_NONE,
1303 THERMAL_TYPE_EXTERNAL,
1304 THERMAL_TYPE_EXTERNAL_GPIO,
1305 THERMAL_TYPE_RV6XX,
1306 THERMAL_TYPE_RV770,
1307 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1308 THERMAL_TYPE_EVERGREEN,
1309 THERMAL_TYPE_SUMO,
1310 THERMAL_TYPE_NI,
1311 THERMAL_TYPE_SI,
1312 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1313 THERMAL_TYPE_CI,
1314 THERMAL_TYPE_KV,
1315};
1316
1317enum amdgpu_dpm_auto_throttle_src {
1318 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1319 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1320};
1321
1322enum amdgpu_dpm_event_src {
1323 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1324 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1325 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1326 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1327 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1328};
1329
1330#define AMDGPU_MAX_VCE_LEVELS 6
1331
1332enum amdgpu_vce_level {
1333 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1334 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1335 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1336 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1337 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1338 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1339};
1340
1341struct amdgpu_ps {
1342 u32 caps; /* vbios flags */
1343 u32 class; /* vbios flags */
1344 u32 class2; /* vbios flags */
1345 /* UVD clocks */
1346 u32 vclk;
1347 u32 dclk;
1348 /* VCE clocks */
1349 u32 evclk;
1350 u32 ecclk;
1351 bool vce_active;
1352 enum amdgpu_vce_level vce_level;
1353 /* asic priv */
1354 void *ps_priv;
1355};
1356
1357struct amdgpu_dpm_thermal {
1358 /* thermal interrupt work */
1359 struct work_struct work;
1360 /* low temperature threshold */
1361 int min_temp;
1362 /* high temperature threshold */
1363 int max_temp;
1364 /* was last interrupt low to high or high to low */
1365 bool high_to_low;
1366 /* interrupt source */
1367 struct amdgpu_irq_src irq;
1368};
1369
1370enum amdgpu_clk_action
1371{
1372 AMDGPU_SCLK_UP = 1,
1373 AMDGPU_SCLK_DOWN
1374};
1375
1376struct amdgpu_blacklist_clocks
1377{
1378 u32 sclk;
1379 u32 mclk;
1380 enum amdgpu_clk_action action;
1381};
1382
1383struct amdgpu_clock_and_voltage_limits {
1384 u32 sclk;
1385 u32 mclk;
1386 u16 vddc;
1387 u16 vddci;
1388};
1389
1390struct amdgpu_clock_array {
1391 u32 count;
1392 u32 *values;
1393};
1394
1395struct amdgpu_clock_voltage_dependency_entry {
1396 u32 clk;
1397 u16 v;
1398};
1399
1400struct amdgpu_clock_voltage_dependency_table {
1401 u32 count;
1402 struct amdgpu_clock_voltage_dependency_entry *entries;
1403};
1404
1405union amdgpu_cac_leakage_entry {
1406 struct {
1407 u16 vddc;
1408 u32 leakage;
1409 };
1410 struct {
1411 u16 vddc1;
1412 u16 vddc2;
1413 u16 vddc3;
1414 };
1415};
1416
1417struct amdgpu_cac_leakage_table {
1418 u32 count;
1419 union amdgpu_cac_leakage_entry *entries;
1420};
1421
1422struct amdgpu_phase_shedding_limits_entry {
1423 u16 voltage;
1424 u32 sclk;
1425 u32 mclk;
1426};
1427
1428struct amdgpu_phase_shedding_limits_table {
1429 u32 count;
1430 struct amdgpu_phase_shedding_limits_entry *entries;
1431};
1432
1433struct amdgpu_uvd_clock_voltage_dependency_entry {
1434 u32 vclk;
1435 u32 dclk;
1436 u16 v;
1437};
1438
1439struct amdgpu_uvd_clock_voltage_dependency_table {
1440 u8 count;
1441 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1442};
1443
1444struct amdgpu_vce_clock_voltage_dependency_entry {
1445 u32 ecclk;
1446 u32 evclk;
1447 u16 v;
1448};
1449
1450struct amdgpu_vce_clock_voltage_dependency_table {
1451 u8 count;
1452 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1453};
1454
1455struct amdgpu_ppm_table {
1456 u8 ppm_design;
1457 u16 cpu_core_number;
1458 u32 platform_tdp;
1459 u32 small_ac_platform_tdp;
1460 u32 platform_tdc;
1461 u32 small_ac_platform_tdc;
1462 u32 apu_tdp;
1463 u32 dgpu_tdp;
1464 u32 dgpu_ulv_power;
1465 u32 tj_max;
1466};
1467
1468struct amdgpu_cac_tdp_table {
1469 u16 tdp;
1470 u16 configurable_tdp;
1471 u16 tdc;
1472 u16 battery_power_limit;
1473 u16 small_power_limit;
1474 u16 low_cac_leakage;
1475 u16 high_cac_leakage;
1476 u16 maximum_power_delivery_limit;
1477};
1478
1479struct amdgpu_dpm_dynamic_state {
1480 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1481 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1482 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1483 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1484 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1485 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1486 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1487 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1488 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1489 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1490 struct amdgpu_clock_array valid_sclk_values;
1491 struct amdgpu_clock_array valid_mclk_values;
1492 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1493 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1494 u32 mclk_sclk_ratio;
1495 u32 sclk_mclk_delta;
1496 u16 vddc_vddci_delta;
1497 u16 min_vddc_for_pcie_gen2;
1498 struct amdgpu_cac_leakage_table cac_leakage_table;
1499 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1500 struct amdgpu_ppm_table *ppm_table;
1501 struct amdgpu_cac_tdp_table *cac_tdp_table;
1502};
1503
1504struct amdgpu_dpm_fan {
1505 u16 t_min;
1506 u16 t_med;
1507 u16 t_high;
1508 u16 pwm_min;
1509 u16 pwm_med;
1510 u16 pwm_high;
1511 u8 t_hyst;
1512 u32 cycle_delay;
1513 u16 t_max;
1514 u8 control_mode;
1515 u16 default_max_fan_pwm;
1516 u16 default_fan_output_sensitivity;
1517 u16 fan_output_sensitivity;
1518 bool ucode_fan_control;
1519};
1520
1521enum amdgpu_pcie_gen {
1522 AMDGPU_PCIE_GEN1 = 0,
1523 AMDGPU_PCIE_GEN2 = 1,
1524 AMDGPU_PCIE_GEN3 = 2,
1525 AMDGPU_PCIE_GEN_INVALID = 0xffff
1526};
1527
1528enum amdgpu_dpm_forced_level {
1529 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1530 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1531 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001532 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001533};
1534
1535struct amdgpu_vce_state {
1536 /* vce clocks */
1537 u32 evclk;
1538 u32 ecclk;
1539 /* gpu clocks */
1540 u32 sclk;
1541 u32 mclk;
1542 u8 clk_idx;
1543 u8 pstate;
1544};
1545
1546struct amdgpu_dpm_funcs {
1547 int (*get_temperature)(struct amdgpu_device *adev);
1548 int (*pre_set_power_state)(struct amdgpu_device *adev);
1549 int (*set_power_state)(struct amdgpu_device *adev);
1550 void (*post_set_power_state)(struct amdgpu_device *adev);
1551 void (*display_configuration_changed)(struct amdgpu_device *adev);
1552 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1553 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1554 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1555 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1556 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1557 bool (*vblank_too_short)(struct amdgpu_device *adev);
1558 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001559 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001560 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1561 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1562 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1563 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1564 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001565 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1566 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001567 int (*get_sclk_od)(struct amdgpu_device *adev);
1568 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001569 int (*get_mclk_od)(struct amdgpu_device *adev);
1570 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001571};
1572
1573struct amdgpu_dpm {
1574 struct amdgpu_ps *ps;
1575 /* number of valid power states */
1576 int num_ps;
1577 /* current power state that is active */
1578 struct amdgpu_ps *current_ps;
1579 /* requested power state */
1580 struct amdgpu_ps *requested_ps;
1581 /* boot up power state */
1582 struct amdgpu_ps *boot_ps;
1583 /* default uvd power state */
1584 struct amdgpu_ps *uvd_ps;
1585 /* vce requirements */
1586 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1587 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001588 enum amd_pm_state_type state;
1589 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001590 u32 platform_caps;
1591 u32 voltage_response_time;
1592 u32 backbias_response_time;
1593 void *priv;
1594 u32 new_active_crtcs;
1595 int new_active_crtc_count;
1596 u32 current_active_crtcs;
1597 int current_active_crtc_count;
1598 struct amdgpu_dpm_dynamic_state dyn_state;
1599 struct amdgpu_dpm_fan fan;
1600 u32 tdp_limit;
1601 u32 near_tdp_limit;
1602 u32 near_tdp_limit_adjusted;
1603 u32 sq_ramping_threshold;
1604 u32 cac_leakage;
1605 u16 tdp_od_limit;
1606 u32 tdp_adjustment;
1607 u16 load_line_slope;
1608 bool power_control;
1609 bool ac_power;
1610 /* special states active */
1611 bool thermal_active;
1612 bool uvd_active;
1613 bool vce_active;
1614 /* thermal handling */
1615 struct amdgpu_dpm_thermal thermal;
1616 /* forced levels */
1617 enum amdgpu_dpm_forced_level forced_level;
1618};
1619
1620struct amdgpu_pm {
1621 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001622 u32 current_sclk;
1623 u32 current_mclk;
1624 u32 default_sclk;
1625 u32 default_mclk;
1626 struct amdgpu_i2c_chan *i2c_bus;
1627 /* internal thermal controller on rv6xx+ */
1628 enum amdgpu_int_thermal_type int_thermal_type;
1629 struct device *int_hwmon_dev;
1630 /* fan control parameters */
1631 bool no_fan;
1632 u8 fan_pulses_per_revolution;
1633 u8 fan_min_rpm;
1634 u8 fan_max_rpm;
1635 /* dpm */
1636 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001637 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001638 struct amdgpu_dpm dpm;
1639 const struct firmware *fw; /* SMC firmware */
1640 uint32_t fw_version;
1641 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001642 uint32_t pcie_gen_mask;
1643 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001644 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001645};
1646
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001647void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1648
Alex Deucher97b2e202015-04-20 16:51:00 -04001649/*
1650 * UVD
1651 */
Arindam Nathc0365542016-04-12 13:46:15 +02001652#define AMDGPU_DEFAULT_UVD_HANDLES 10
1653#define AMDGPU_MAX_UVD_HANDLES 40
1654#define AMDGPU_UVD_STACK_SIZE (200*1024)
1655#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1656#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1657#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001658
1659struct amdgpu_uvd {
1660 struct amdgpu_bo *vcpu_bo;
1661 void *cpu_addr;
1662 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001663 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001664 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001665 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001666 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1667 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1668 struct delayed_work idle_work;
1669 const struct firmware *fw; /* UVD firmware */
1670 struct amdgpu_ring ring;
1671 struct amdgpu_irq_src irq;
1672 bool address_64_bit;
Christian Königead833e2016-02-10 14:35:19 +01001673 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001674};
1675
1676/*
1677 * VCE
1678 */
1679#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001680#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1681
Alex Deucher6a585772015-07-10 14:16:24 -04001682#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1683#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1684
Alex Deucher97b2e202015-04-20 16:51:00 -04001685struct amdgpu_vce {
1686 struct amdgpu_bo *vcpu_bo;
1687 uint64_t gpu_addr;
1688 unsigned fw_version;
1689 unsigned fb_version;
1690 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1691 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001692 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001693 struct delayed_work idle_work;
1694 const struct firmware *fw; /* VCE firmware */
1695 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1696 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001697 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001698 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001699};
1700
1701/*
1702 * SDMA
1703 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001704struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001705 /* SDMA firmware */
1706 const struct firmware *fw;
1707 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001708 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001709
1710 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001711 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001712};
1713
Alex Deucherc113ea12015-10-08 16:30:37 -04001714struct amdgpu_sdma {
1715 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1716 struct amdgpu_irq_src trap_irq;
1717 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001718 int num_instances;
Alex Deucherc113ea12015-10-08 16:30:37 -04001719};
1720
Alex Deucher97b2e202015-04-20 16:51:00 -04001721/*
1722 * Firmware
1723 */
1724struct amdgpu_firmware {
1725 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1726 bool smu_load;
1727 struct amdgpu_bo *fw_buf;
1728 unsigned int fw_size;
1729};
1730
1731/*
1732 * Benchmarking
1733 */
1734void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1735
1736
1737/*
1738 * Testing
1739 */
1740void amdgpu_test_moves(struct amdgpu_device *adev);
1741void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1742 struct amdgpu_ring *cpA,
1743 struct amdgpu_ring *cpB);
1744void amdgpu_test_syncing(struct amdgpu_device *adev);
1745
1746/*
1747 * MMU Notifier
1748 */
1749#if defined(CONFIG_MMU_NOTIFIER)
1750int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1751void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1752#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001753static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001754{
1755 return -ENODEV;
1756}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001757static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001758#endif
1759
1760/*
1761 * Debugfs
1762 */
1763struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001764 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001765 unsigned num_files;
1766};
1767
1768int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001769 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001770 unsigned nfiles);
1771int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1772
1773#if defined(CONFIG_DEBUG_FS)
1774int amdgpu_debugfs_init(struct drm_minor *minor);
1775void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1776#endif
1777
1778/*
1779 * amdgpu smumgr functions
1780 */
1781struct amdgpu_smumgr_funcs {
1782 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1783 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1784 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1785};
1786
1787/*
1788 * amdgpu smumgr
1789 */
1790struct amdgpu_smumgr {
1791 struct amdgpu_bo *toc_buf;
1792 struct amdgpu_bo *smu_buf;
1793 /* asic priv smu data */
1794 void *priv;
1795 spinlock_t smu_lock;
1796 /* smumgr functions */
1797 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1798 /* ucode loading complete flag */
1799 uint32_t fw_flags;
1800};
1801
1802/*
1803 * ASIC specific register table accessible by UMD
1804 */
1805struct amdgpu_allowed_register_entry {
1806 uint32_t reg_offset;
1807 bool untouched;
1808 bool grbm_indexed;
1809};
1810
Alex Deucher97b2e202015-04-20 16:51:00 -04001811/*
1812 * ASIC specific functions.
1813 */
1814struct amdgpu_asic_funcs {
1815 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001816 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1817 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001818 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1819 u32 sh_num, u32 reg_offset, u32 *value);
1820 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1821 int (*reset)(struct amdgpu_device *adev);
1822 /* wait for mc_idle */
1823 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1824 /* get the reference clock */
1825 u32 (*get_xclk)(struct amdgpu_device *adev);
1826 /* get the gpu clock counter */
1827 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001828 /* MM block clocks */
1829 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1830 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Andres Rodriguez048765a2016-06-11 02:51:32 -04001831 /* query virtual capabilities */
1832 u32 (*get_virtual_caps)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001833};
1834
1835/*
1836 * IOCTL.
1837 */
1838int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1839 struct drm_file *filp);
1840int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1841 struct drm_file *filp);
1842
1843int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1844 struct drm_file *filp);
1845int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1846 struct drm_file *filp);
1847int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1848 struct drm_file *filp);
1849int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1850 struct drm_file *filp);
1851int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1852 struct drm_file *filp);
1853int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1854 struct drm_file *filp);
1855int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1856int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1857
1858int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1859 struct drm_file *filp);
1860
1861/* VRAM scratch page for HDP bug, default vram page */
1862struct amdgpu_vram_scratch {
1863 struct amdgpu_bo *robj;
1864 volatile uint32_t *ptr;
1865 u64 gpu_addr;
1866};
1867
1868/*
1869 * ACPI
1870 */
1871struct amdgpu_atif_notification_cfg {
1872 bool enabled;
1873 int command_code;
1874};
1875
1876struct amdgpu_atif_notifications {
1877 bool display_switch;
1878 bool expansion_mode_change;
1879 bool thermal_state;
1880 bool forced_power_state;
1881 bool system_power_state;
1882 bool display_conf_change;
1883 bool px_gfx_switch;
1884 bool brightness_change;
1885 bool dgpu_display_event;
1886};
1887
1888struct amdgpu_atif_functions {
1889 bool system_params;
1890 bool sbios_requests;
1891 bool select_active_disp;
1892 bool lid_state;
1893 bool get_tv_standard;
1894 bool set_tv_standard;
1895 bool get_panel_expansion_mode;
1896 bool set_panel_expansion_mode;
1897 bool temperature_change;
1898 bool graphics_device_types;
1899};
1900
1901struct amdgpu_atif {
1902 struct amdgpu_atif_notifications notifications;
1903 struct amdgpu_atif_functions functions;
1904 struct amdgpu_atif_notification_cfg notification_cfg;
1905 struct amdgpu_encoder *encoder_for_bl;
1906};
1907
1908struct amdgpu_atcs_functions {
1909 bool get_ext_state;
1910 bool pcie_perf_req;
1911 bool pcie_dev_rdy;
1912 bool pcie_bus_width;
1913};
1914
1915struct amdgpu_atcs {
1916 struct amdgpu_atcs_functions functions;
1917};
1918
Alex Deucher97b2e202015-04-20 16:51:00 -04001919/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001920 * CGS
1921 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001922struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1923void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001924
1925
Alex Deucher7e471e62016-02-01 11:13:04 -05001926/* GPU virtualization */
Andres Rodriguez048765a2016-06-11 02:51:32 -04001927#define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0)
1928#define AMDGPU_VIRT_CAPS_IS_VF (1 << 1)
Alex Deucher7e471e62016-02-01 11:13:04 -05001929struct amdgpu_virtualization {
1930 bool supports_sr_iov;
Andres Rodriguez048765a2016-06-11 02:51:32 -04001931 bool is_virtual;
1932 u32 caps;
Alex Deucher7e471e62016-02-01 11:13:04 -05001933};
1934
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001935/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001936 * Core structure, functions and helpers.
1937 */
1938typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1939typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1940
1941typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1942typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1943
Alex Deucher8faf0e02015-07-28 11:50:31 -04001944struct amdgpu_ip_block_status {
1945 bool valid;
1946 bool sw;
1947 bool hw;
1948};
1949
Alex Deucher97b2e202015-04-20 16:51:00 -04001950struct amdgpu_device {
1951 struct device *dev;
1952 struct drm_device *ddev;
1953 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001954
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001955#ifdef CONFIG_DRM_AMD_ACP
1956 struct amdgpu_acp acp;
1957#endif
1958
Alex Deucher97b2e202015-04-20 16:51:00 -04001959 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001960 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001961 uint32_t family;
1962 uint32_t rev_id;
1963 uint32_t external_rev_id;
1964 unsigned long flags;
1965 int usec_timeout;
1966 const struct amdgpu_asic_funcs *asic_funcs;
1967 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001968 bool need_dma32;
1969 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001970 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001971 struct notifier_block acpi_nb;
1972 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1973 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001974 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001975#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001976 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001977#endif
1978 struct amdgpu_atif atif;
1979 struct amdgpu_atcs atcs;
1980 struct mutex srbm_mutex;
1981 /* GRBM index mutex. Protects concurrent access to GRBM index */
1982 struct mutex grbm_idx_mutex;
1983 struct dev_pm_domain vga_pm_domain;
1984 bool have_disp_power_ref;
1985
1986 /* BIOS */
1987 uint8_t *bios;
1988 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001989 struct amdgpu_bo *stollen_vga_memory;
1990 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1991
1992 /* Register/doorbell mmio */
1993 resource_size_t rmmio_base;
1994 resource_size_t rmmio_size;
1995 void __iomem *rmmio;
1996 /* protects concurrent MM_INDEX/DATA based register access */
1997 spinlock_t mmio_idx_lock;
1998 /* protects concurrent SMC based register access */
1999 spinlock_t smc_idx_lock;
2000 amdgpu_rreg_t smc_rreg;
2001 amdgpu_wreg_t smc_wreg;
2002 /* protects concurrent PCIE register access */
2003 spinlock_t pcie_idx_lock;
2004 amdgpu_rreg_t pcie_rreg;
2005 amdgpu_wreg_t pcie_wreg;
2006 /* protects concurrent UVD register access */
2007 spinlock_t uvd_ctx_idx_lock;
2008 amdgpu_rreg_t uvd_ctx_rreg;
2009 amdgpu_wreg_t uvd_ctx_wreg;
2010 /* protects concurrent DIDT register access */
2011 spinlock_t didt_idx_lock;
2012 amdgpu_rreg_t didt_rreg;
2013 amdgpu_wreg_t didt_wreg;
2014 /* protects concurrent ENDPOINT (audio) register access */
2015 spinlock_t audio_endpt_idx_lock;
2016 amdgpu_block_rreg_t audio_endpt_rreg;
2017 amdgpu_block_wreg_t audio_endpt_wreg;
2018 void __iomem *rio_mem;
2019 resource_size_t rio_mem_size;
2020 struct amdgpu_doorbell doorbell;
2021
2022 /* clock/pll info */
2023 struct amdgpu_clock clock;
2024
2025 /* MC */
2026 struct amdgpu_mc mc;
2027 struct amdgpu_gart gart;
2028 struct amdgpu_dummy_page dummy_page;
2029 struct amdgpu_vm_manager vm_manager;
2030
2031 /* memory management */
2032 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002033 struct amdgpu_vram_scratch vram_scratch;
2034 struct amdgpu_wb wb;
2035 atomic64_t vram_usage;
2036 atomic64_t vram_vis_usage;
2037 atomic64_t gtt_usage;
2038 atomic64_t num_bytes_moved;
Marek Olšákd94aed52015-05-05 21:13:49 +02002039 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002040
2041 /* display */
2042 struct amdgpu_mode_info mode_info;
2043 struct work_struct hotplug_work;
2044 struct amdgpu_irq_src crtc_irq;
2045 struct amdgpu_irq_src pageflip_irq;
2046 struct amdgpu_irq_src hpd_irq;
2047
2048 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02002049 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002050 unsigned num_rings;
2051 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2052 bool ib_pool_ready;
2053 struct amdgpu_sa_manager ring_tmp_bo;
2054
2055 /* interrupts */
2056 struct amdgpu_irq irq;
2057
Alex Deucher1f7371b2015-12-02 17:46:21 -05002058 /* powerplay */
2059 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002060 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002061 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002062
Alex Deucher97b2e202015-04-20 16:51:00 -04002063 /* dpm */
2064 struct amdgpu_pm pm;
2065 u32 cg_flags;
2066 u32 pg_flags;
2067
2068 /* amdgpu smumgr */
2069 struct amdgpu_smumgr smu;
2070
2071 /* gfx */
2072 struct amdgpu_gfx gfx;
2073
2074 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002075 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002076
2077 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002078 struct amdgpu_uvd uvd;
2079
2080 /* vce */
2081 struct amdgpu_vce vce;
2082
2083 /* firmwares */
2084 struct amdgpu_firmware firmware;
2085
2086 /* GDS */
2087 struct amdgpu_gds gds;
2088
2089 const struct amdgpu_ip_block_version *ip_blocks;
2090 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002091 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002092 struct mutex mn_lock;
2093 DECLARE_HASHTABLE(mn_hash, 7);
2094
2095 /* tracking pinned memory */
2096 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002097 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002098 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002099
2100 /* amdkfd interface */
2101 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002102
Alex Deucher7e471e62016-02-01 11:13:04 -05002103 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002104};
2105
2106bool amdgpu_device_is_px(struct drm_device *dev);
2107int amdgpu_device_init(struct amdgpu_device *adev,
2108 struct drm_device *ddev,
2109 struct pci_dev *pdev,
2110 uint32_t flags);
2111void amdgpu_device_fini(struct amdgpu_device *adev);
2112int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2113
2114uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2115 bool always_indirect);
2116void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2117 bool always_indirect);
2118u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2119void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2120
2121u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2122void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2123
2124/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002125 * Registers read & write functions.
2126 */
2127#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2128#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2129#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2130#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2131#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2132#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2133#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2134#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2135#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2136#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2137#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2138#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2139#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2140#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2141#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2142#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2143#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2144#define WREG32_P(reg, val, mask) \
2145 do { \
2146 uint32_t tmp_ = RREG32(reg); \
2147 tmp_ &= (mask); \
2148 tmp_ |= ((val) & ~(mask)); \
2149 WREG32(reg, tmp_); \
2150 } while (0)
2151#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2152#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2153#define WREG32_PLL_P(reg, val, mask) \
2154 do { \
2155 uint32_t tmp_ = RREG32_PLL(reg); \
2156 tmp_ &= (mask); \
2157 tmp_ |= ((val) & ~(mask)); \
2158 WREG32_PLL(reg, tmp_); \
2159 } while (0)
2160#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2161#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2162#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2163
2164#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2165#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2166
2167#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2168#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2169
2170#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2171 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2172 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2173
2174#define REG_GET_FIELD(value, reg, field) \
2175 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2176
2177/*
2178 * BIOS helpers.
2179 */
2180#define RBIOS8(i) (adev->bios[i])
2181#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2182#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2183
2184/*
2185 * RING helpers.
2186 */
2187static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2188{
2189 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002190 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002191 ring->ring[ring->wptr++] = v;
2192 ring->wptr &= ring->ptr_mask;
2193 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002194}
2195
Alex Deucherc113ea12015-10-08 16:30:37 -04002196static inline struct amdgpu_sdma_instance *
2197amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002198{
2199 struct amdgpu_device *adev = ring->adev;
2200 int i;
2201
Alex Deucherc113ea12015-10-08 16:30:37 -04002202 for (i = 0; i < adev->sdma.num_instances; i++)
2203 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002204 break;
2205
2206 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002207 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002208 else
2209 return NULL;
2210}
2211
Alex Deucher97b2e202015-04-20 16:51:00 -04002212/*
2213 * ASICs macro.
2214 */
2215#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2216#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
2217#define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
2218#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2219#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2220#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 -04002221#define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002222#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2223#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002224#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 -04002225#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 -04002226#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2227#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2228#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 +01002229#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 -04002230#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 -04002231#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2232#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2233#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002234#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2235#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2236#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002237#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 +01002238#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002239#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002240#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002241#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 +02002242#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002243#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002244#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002245#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2246#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04002247#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2248#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2249#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2250#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2251#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2252#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2253#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2254#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2255#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2256#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2257#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2258#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2259#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002260#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 -04002261#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2262#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2263#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))
2264#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2265#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002266#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 +08002267#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 -04002268#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2269#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2270#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2271#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002272#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002273#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002274#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Rex Zhu3af76f22015-10-15 17:23:43 +08002275
2276#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002277 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002278 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002279 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002280
2281#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002282 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002283 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002284 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002285
2286#define amdgpu_dpm_get_fan_control_mode(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_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002289 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002290
2291#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
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_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002294 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002295
2296#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
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_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002299 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002300
Rex Zhu1b5708f2015-11-10 18:25:24 -05002301#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002302 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002303 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002304 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002305
2306#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002307 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002308 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002309 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002310
2311
2312#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002313 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002314 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002315 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002316
2317#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002318 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002319 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002320 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002321
2322#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002323 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002324 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002325 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002326
2327#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002328 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002329 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002330 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002331
2332#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002333 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002334
2335#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002336 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002337
Eric Huangf3898ea2015-12-11 16:24:34 -05002338#define amdgpu_dpm_get_pp_num_states(adev, data) \
2339 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2340
2341#define amdgpu_dpm_get_pp_table(adev, table) \
2342 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2343
2344#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2345 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2346
2347#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2348 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2349
2350#define amdgpu_dpm_force_clock_level(adev, type, level) \
2351 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2352
Eric Huang428bafa2016-05-12 14:51:21 -04002353#define amdgpu_dpm_get_sclk_od(adev) \
2354 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2355
2356#define amdgpu_dpm_set_sclk_od(adev, value) \
2357 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2358
Eric Huangf2bdc052016-05-24 15:11:17 -04002359#define amdgpu_dpm_get_mclk_od(adev) \
2360 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2361
2362#define amdgpu_dpm_set_mclk_od(adev, value) \
2363 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2364
Jammy Zhoue61710c2015-11-10 18:31:08 -05002365#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002366 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002367
2368#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2369
2370/* Common functions */
2371int amdgpu_gpu_reset(struct amdgpu_device *adev);
2372void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2373bool amdgpu_card_posted(struct amdgpu_device *adev);
2374void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002375
Alex Deucher97b2e202015-04-20 16:51:00 -04002376int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2377int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2378 u32 ip_instance, u32 ring,
2379 struct amdgpu_ring **out_ring);
2380void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2381bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002382int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002383int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2384 uint32_t flags);
2385bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002386struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002387bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2388 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002389bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2390 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002391bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2392uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2393 struct ttm_mem_reg *mem);
2394void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2395void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2396void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2397void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2398 const u32 *registers,
2399 const u32 array_size);
2400
2401bool amdgpu_device_is_px(struct drm_device *dev);
2402/* atpx handler */
2403#if defined(CONFIG_VGA_SWITCHEROO)
2404void amdgpu_register_atpx_handler(void);
2405void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002406bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002407bool amdgpu_is_atpx_hybrid(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002408#else
2409static inline void amdgpu_register_atpx_handler(void) {}
2410static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002411static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002412static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002413#endif
2414
2415/*
2416 * KMS
2417 */
2418extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002419extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002420
2421int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2422int amdgpu_driver_unload_kms(struct drm_device *dev);
2423void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2424int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2425void amdgpu_driver_postclose_kms(struct drm_device *dev,
2426 struct drm_file *file_priv);
2427void amdgpu_driver_preclose_kms(struct drm_device *dev,
2428 struct drm_file *file_priv);
2429int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2430int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002431u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2432int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2433void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2434int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002435 int *max_error,
2436 struct timeval *vblank_time,
2437 unsigned flags);
2438long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2439 unsigned long arg);
2440
2441/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002442 * functions used by amdgpu_encoder.c
2443 */
2444struct amdgpu_afmt_acr {
2445 u32 clock;
2446
2447 int n_32khz;
2448 int cts_32khz;
2449
2450 int n_44_1khz;
2451 int cts_44_1khz;
2452
2453 int n_48khz;
2454 int cts_48khz;
2455
2456};
2457
2458struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2459
2460/* amdgpu_acpi.c */
2461#if defined(CONFIG_ACPI)
2462int amdgpu_acpi_init(struct amdgpu_device *adev);
2463void amdgpu_acpi_fini(struct amdgpu_device *adev);
2464bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2465int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2466 u8 perf_req, bool advertise);
2467int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2468#else
2469static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2470static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2471#endif
2472
2473struct amdgpu_bo_va_mapping *
2474amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2475 uint64_t addr, struct amdgpu_bo **bo);
2476
2477#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002478#endif