blob: 73a72eee4dc3d55053144dac0100d96422cfb605 [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"
Alex Deucher97b2e202015-04-20 16:51:00 -040056
Alex Deucherb80d8472015-08-16 22:55:02 -040057#include "gpu_scheduler.h"
58
Alex Deucher97b2e202015-04-20 16:51:00 -040059/*
60 * Modules parameters.
61 */
62extern int amdgpu_modeset;
63extern int amdgpu_vram_limit;
64extern int amdgpu_gart_size;
65extern int amdgpu_benchmarking;
66extern int amdgpu_testing;
67extern int amdgpu_audio;
68extern int amdgpu_disp_priority;
69extern int amdgpu_hw_i2c;
70extern int amdgpu_pcie_gen2;
71extern int amdgpu_msi;
72extern int amdgpu_lockup_timeout;
73extern int amdgpu_dpm;
74extern int amdgpu_smc_load_fw;
75extern int amdgpu_aspm;
76extern int amdgpu_runtime_pm;
77extern int amdgpu_hard_reset;
78extern 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;
Alex Deucherb80d8472015-08-16 22:55:02 -040085extern int amdgpu_enable_scheduler;
Jammy Zhou1333f722015-07-30 16:36:58 +080086extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080087extern int amdgpu_sched_hw_submission;
Christian König3daea9e3d2015-09-05 11:12:27 +020088extern int amdgpu_enable_semaphores;
Alex Deucher1f7371b2015-12-02 17:46:21 -050089extern int amdgpu_powerplay;
Alex Deuchercd474ba2016-02-04 10:21:23 -050090extern unsigned amdgpu_pcie_gen_cap;
91extern unsigned amdgpu_pcie_lane_cap;
Alex Deucher97b2e202015-04-20 16:51:00 -040092
Chunming Zhou4b559c92015-07-21 15:53:04 +080093#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -040094#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
95#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
96/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
97#define AMDGPU_IB_POOL_SIZE 16
98#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
99#define AMDGPUFB_CONN_LIMIT 4
100#define AMDGPU_BIOS_NUM_SCRATCH 8
101
Alex Deucher97b2e202015-04-20 16:51:00 -0400102/* max number of rings */
103#define AMDGPU_MAX_RINGS 16
104#define AMDGPU_MAX_GFX_RINGS 1
105#define AMDGPU_MAX_COMPUTE_RINGS 8
106#define AMDGPU_MAX_VCE_RINGS 2
107
Jammy Zhou36f523a2015-09-01 12:54:27 +0800108/* max number of IP instances */
109#define AMDGPU_MAX_SDMA_INSTANCES 2
110
Alex Deucher97b2e202015-04-20 16:51:00 -0400111/* number of hw syncs before falling back on blocking */
112#define AMDGPU_NUM_SYNCS 4
113
114/* hardcode that limit for now */
115#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
116
117/* hard reset data */
118#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
119
120/* reset flags */
121#define AMDGPU_RESET_GFX (1 << 0)
122#define AMDGPU_RESET_COMPUTE (1 << 1)
123#define AMDGPU_RESET_DMA (1 << 2)
124#define AMDGPU_RESET_CP (1 << 3)
125#define AMDGPU_RESET_GRBM (1 << 4)
126#define AMDGPU_RESET_DMA1 (1 << 5)
127#define AMDGPU_RESET_RLC (1 << 6)
128#define AMDGPU_RESET_SEM (1 << 7)
129#define AMDGPU_RESET_IH (1 << 8)
130#define AMDGPU_RESET_VMC (1 << 9)
131#define AMDGPU_RESET_MC (1 << 10)
132#define AMDGPU_RESET_DISPLAY (1 << 11)
133#define AMDGPU_RESET_UVD (1 << 12)
134#define AMDGPU_RESET_VCE (1 << 13)
135#define AMDGPU_RESET_VCE1 (1 << 14)
136
Alex Deucher97b2e202015-04-20 16:51:00 -0400137/* CG flags */
138#define AMDGPU_CG_SUPPORT_GFX_MGCG (1 << 0)
139#define AMDGPU_CG_SUPPORT_GFX_MGLS (1 << 1)
140#define AMDGPU_CG_SUPPORT_GFX_CGCG (1 << 2)
141#define AMDGPU_CG_SUPPORT_GFX_CGLS (1 << 3)
142#define AMDGPU_CG_SUPPORT_GFX_CGTS (1 << 4)
143#define AMDGPU_CG_SUPPORT_GFX_CGTS_LS (1 << 5)
144#define AMDGPU_CG_SUPPORT_GFX_CP_LS (1 << 6)
145#define AMDGPU_CG_SUPPORT_GFX_RLC_LS (1 << 7)
146#define AMDGPU_CG_SUPPORT_MC_LS (1 << 8)
147#define AMDGPU_CG_SUPPORT_MC_MGCG (1 << 9)
148#define AMDGPU_CG_SUPPORT_SDMA_LS (1 << 10)
149#define AMDGPU_CG_SUPPORT_SDMA_MGCG (1 << 11)
150#define AMDGPU_CG_SUPPORT_BIF_LS (1 << 12)
151#define AMDGPU_CG_SUPPORT_UVD_MGCG (1 << 13)
152#define AMDGPU_CG_SUPPORT_VCE_MGCG (1 << 14)
153#define AMDGPU_CG_SUPPORT_HDP_LS (1 << 15)
154#define AMDGPU_CG_SUPPORT_HDP_MGCG (1 << 16)
155
156/* PG flags */
157#define AMDGPU_PG_SUPPORT_GFX_PG (1 << 0)
158#define AMDGPU_PG_SUPPORT_GFX_SMG (1 << 1)
159#define AMDGPU_PG_SUPPORT_GFX_DMG (1 << 2)
160#define AMDGPU_PG_SUPPORT_UVD (1 << 3)
161#define AMDGPU_PG_SUPPORT_VCE (1 << 4)
162#define AMDGPU_PG_SUPPORT_CP (1 << 5)
163#define AMDGPU_PG_SUPPORT_GDS (1 << 6)
164#define AMDGPU_PG_SUPPORT_RLC_SMU_HS (1 << 7)
165#define AMDGPU_PG_SUPPORT_SDMA (1 << 8)
166#define AMDGPU_PG_SUPPORT_ACP (1 << 9)
167#define AMDGPU_PG_SUPPORT_SAMU (1 << 10)
168
169/* GFX current status */
170#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
171#define AMDGPU_GFX_SAFE_MODE 0x00000001L
172#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
173#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
174#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
175
176/* max cursor sizes (in pixels) */
177#define CIK_CURSOR_WIDTH 128
178#define CIK_CURSOR_HEIGHT 128
179
180struct amdgpu_device;
181struct amdgpu_fence;
182struct amdgpu_ib;
183struct amdgpu_vm;
184struct amdgpu_ring;
185struct amdgpu_semaphore;
186struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800187struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400188struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400189struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400190
191enum amdgpu_cp_irq {
192 AMDGPU_CP_IRQ_GFX_EOP = 0,
193 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
194 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
195 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
196 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
197 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
198 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
199 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
200 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
201
202 AMDGPU_CP_IRQ_LAST
203};
204
205enum amdgpu_sdma_irq {
206 AMDGPU_SDMA_IRQ_TRAP0 = 0,
207 AMDGPU_SDMA_IRQ_TRAP1,
208
209 AMDGPU_SDMA_IRQ_LAST
210};
211
212enum amdgpu_thermal_irq {
213 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
214 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
215
216 AMDGPU_THERMAL_IRQ_LAST
217};
218
Alex Deucher97b2e202015-04-20 16:51:00 -0400219int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400220 enum amd_ip_block_type block_type,
221 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400222int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400223 enum amd_ip_block_type block_type,
224 enum amd_powergating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400225
226struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400227 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400228 u32 major;
229 u32 minor;
230 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400231 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400232};
233
234int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400235 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400236 u32 major, u32 minor);
237
238const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
239 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400240 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400241
242/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
243struct amdgpu_buffer_funcs {
244 /* maximum bytes in a single operation */
245 uint32_t copy_max_bytes;
246
247 /* number of dw to reserve per operation */
248 unsigned copy_num_dw;
249
250 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800251 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400252 /* src addr in bytes */
253 uint64_t src_offset,
254 /* dst addr in bytes */
255 uint64_t dst_offset,
256 /* number of byte to transfer */
257 uint32_t byte_count);
258
259 /* maximum bytes in a single operation */
260 uint32_t fill_max_bytes;
261
262 /* number of dw to reserve per operation */
263 unsigned fill_num_dw;
264
265 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800266 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400267 /* value to write to memory */
268 uint32_t src_data,
269 /* dst addr in bytes */
270 uint64_t dst_offset,
271 /* number of byte to fill */
272 uint32_t byte_count);
273};
274
275/* provided by hw blocks that can write ptes, e.g., sdma */
276struct amdgpu_vm_pte_funcs {
277 /* copy pte entries from GART */
278 void (*copy_pte)(struct amdgpu_ib *ib,
279 uint64_t pe, uint64_t src,
280 unsigned count);
281 /* write pte one entry at a time with addr mapping */
282 void (*write_pte)(struct amdgpu_ib *ib,
283 uint64_t pe,
284 uint64_t addr, unsigned count,
285 uint32_t incr, uint32_t flags);
286 /* for linear pte/pde updates without addr mapping */
287 void (*set_pte_pde)(struct amdgpu_ib *ib,
288 uint64_t pe,
289 uint64_t addr, unsigned count,
290 uint32_t incr, uint32_t flags);
291 /* pad the indirect buffer to the necessary number of dw */
292 void (*pad_ib)(struct amdgpu_ib *ib);
293};
294
295/* provided by the gmc block */
296struct amdgpu_gart_funcs {
297 /* flush the vm tlb via mmio */
298 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
299 uint32_t vmid);
300 /* write pte/pde updates using the cpu */
301 int (*set_pte_pde)(struct amdgpu_device *adev,
302 void *cpu_pt_addr, /* cpu addr of page table */
303 uint32_t gpu_page_idx, /* pte/pde to update */
304 uint64_t addr, /* addr to write into pte/pde */
305 uint32_t flags); /* access flags */
306};
307
308/* provided by the ih block */
309struct amdgpu_ih_funcs {
310 /* ring read/write ptr handling, called from interrupt context */
311 u32 (*get_wptr)(struct amdgpu_device *adev);
312 void (*decode_iv)(struct amdgpu_device *adev,
313 struct amdgpu_iv_entry *entry);
314 void (*set_rptr)(struct amdgpu_device *adev);
315};
316
317/* provided by hw blocks that expose a ring buffer for commands */
318struct amdgpu_ring_funcs {
319 /* ring read/write ptr handling */
320 u32 (*get_rptr)(struct amdgpu_ring *ring);
321 u32 (*get_wptr)(struct amdgpu_ring *ring);
322 void (*set_wptr)(struct amdgpu_ring *ring);
323 /* validating and patching of IBs */
324 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
325 /* command emit functions */
326 void (*emit_ib)(struct amdgpu_ring *ring,
327 struct amdgpu_ib *ib);
328 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800329 uint64_t seq, unsigned flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400330 bool (*emit_semaphore)(struct amdgpu_ring *ring,
331 struct amdgpu_semaphore *semaphore,
332 bool emit_wait);
333 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
334 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200335 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400336 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
337 uint32_t gds_base, uint32_t gds_size,
338 uint32_t gws_base, uint32_t gws_size,
339 uint32_t oa_base, uint32_t oa_size);
340 /* testing functions */
341 int (*test_ring)(struct amdgpu_ring *ring);
342 int (*test_ib)(struct amdgpu_ring *ring);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800343 /* insert NOP packets */
344 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Alex Deucher97b2e202015-04-20 16:51:00 -0400345};
346
347/*
348 * BIOS.
349 */
350bool amdgpu_get_bios(struct amdgpu_device *adev);
351bool amdgpu_read_bios(struct amdgpu_device *adev);
352
353/*
354 * Dummy page
355 */
356struct amdgpu_dummy_page {
357 struct page *page;
358 dma_addr_t addr;
359};
360int amdgpu_dummy_page_init(struct amdgpu_device *adev);
361void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
362
363
364/*
365 * Clocks
366 */
367
368#define AMDGPU_MAX_PPLL 3
369
370struct amdgpu_clock {
371 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
372 struct amdgpu_pll spll;
373 struct amdgpu_pll mpll;
374 /* 10 Khz units */
375 uint32_t default_mclk;
376 uint32_t default_sclk;
377 uint32_t default_dispclk;
378 uint32_t current_dispclk;
379 uint32_t dp_extclk;
380 uint32_t max_pixel_clock;
381};
382
383/*
384 * Fences.
385 */
386struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400387 uint64_t gpu_addr;
388 volatile uint32_t *cpu_addr;
389 /* sync_seq is protected by ring emission lock */
390 uint64_t sync_seq[AMDGPU_MAX_RINGS];
391 atomic64_t last_seq;
392 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400393 struct amdgpu_irq_src *irq_src;
394 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100395 struct timer_list fallback_timer;
monk.liu7f06c232015-07-30 18:28:12 +0800396 wait_queue_head_t fence_queue;
Alex Deucher97b2e202015-04-20 16:51:00 -0400397};
398
399/* some special values for the owner field */
400#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
401#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400402
Chunming Zhou890ee232015-06-01 14:35:03 +0800403#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
404#define AMDGPU_FENCE_FLAG_INT (1 << 1)
405
Alex Deucher97b2e202015-04-20 16:51:00 -0400406struct amdgpu_fence {
407 struct fence base;
Chunming Zhou4cef9262015-08-05 19:52:14 +0800408
Alex Deucher97b2e202015-04-20 16:51:00 -0400409 /* RB, DMA, etc. */
410 struct amdgpu_ring *ring;
411 uint64_t seq;
412
413 /* filp or special value for fence creator */
414 void *owner;
415
416 wait_queue_t fence_wake;
417};
418
419struct amdgpu_user_fence {
420 /* write-back bo */
421 struct amdgpu_bo *bo;
422 /* write-back address offset to bo start */
423 uint32_t offset;
424};
425
426int amdgpu_fence_driver_init(struct amdgpu_device *adev);
427void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
428void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
429
Christian König4f839a22015-09-08 20:22:31 +0200430int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400431int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
432 struct amdgpu_irq_src *irq_src,
433 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400434void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
435void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400436int amdgpu_fence_emit(struct amdgpu_ring *ring, void *owner,
437 struct amdgpu_fence **fence);
438void amdgpu_fence_process(struct amdgpu_ring *ring);
439int amdgpu_fence_wait_next(struct amdgpu_ring *ring);
440int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
441unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
442
Alex Deucher97b2e202015-04-20 16:51:00 -0400443bool amdgpu_fence_need_sync(struct amdgpu_fence *fence,
444 struct amdgpu_ring *ring);
445void amdgpu_fence_note_sync(struct amdgpu_fence *fence,
446 struct amdgpu_ring *ring);
447
Alex Deucher97b2e202015-04-20 16:51:00 -0400448/*
449 * TTM.
450 */
451struct amdgpu_mman {
452 struct ttm_bo_global_ref bo_global_ref;
453 struct drm_global_reference mem_global_ref;
454 struct ttm_bo_device bdev;
455 bool mem_global_referenced;
456 bool initialized;
457
458#if defined(CONFIG_DEBUG_FS)
459 struct dentry *vram;
460 struct dentry *gtt;
461#endif
462
463 /* buffer handling */
464 const struct amdgpu_buffer_funcs *buffer_funcs;
465 struct amdgpu_ring *buffer_funcs_ring;
466};
467
468int amdgpu_copy_buffer(struct amdgpu_ring *ring,
469 uint64_t src_offset,
470 uint64_t dst_offset,
471 uint32_t byte_count,
472 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800473 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400474int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
475
476struct amdgpu_bo_list_entry {
477 struct amdgpu_bo *robj;
478 struct ttm_validate_buffer tv;
479 struct amdgpu_bo_va *bo_va;
480 unsigned prefered_domains;
481 unsigned allowed_domains;
482 uint32_t priority;
483};
484
485struct amdgpu_bo_va_mapping {
486 struct list_head list;
487 struct interval_tree_node it;
488 uint64_t offset;
489 uint32_t flags;
490};
491
492/* bo virtual addresses in a specific vm */
493struct amdgpu_bo_va {
Chunming Zhou69b576a2015-11-18 11:17:39 +0800494 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -0400495 /* protected by bo being reserved */
496 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800497 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400498 unsigned ref_count;
499
Christian König7fc11952015-07-30 11:53:42 +0200500 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400501 struct list_head vm_status;
502
Christian König7fc11952015-07-30 11:53:42 +0200503 /* mappings for this bo_va */
504 struct list_head invalids;
505 struct list_head valids;
506
Alex Deucher97b2e202015-04-20 16:51:00 -0400507 /* constant after initialization */
508 struct amdgpu_vm *vm;
509 struct amdgpu_bo *bo;
510};
511
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800512#define AMDGPU_GEM_DOMAIN_MAX 0x3
513
Alex Deucher97b2e202015-04-20 16:51:00 -0400514struct amdgpu_bo {
515 /* Protected by gem.mutex */
516 struct list_head list;
517 /* Protected by tbo.reserved */
518 u32 initial_domain;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800519 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400520 struct ttm_placement placement;
521 struct ttm_buffer_object tbo;
522 struct ttm_bo_kmap_obj kmap;
523 u64 flags;
524 unsigned pin_count;
525 void *kptr;
526 u64 tiling_flags;
527 u64 metadata_flags;
528 void *metadata;
529 u32 metadata_size;
530 /* list of all virtual address to which this bo
531 * is associated to
532 */
533 struct list_head va;
534 /* Constant after initialization */
535 struct amdgpu_device *adev;
536 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100537 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400538
539 struct ttm_bo_kmap_obj dma_buf_vmap;
540 pid_t pid;
541 struct amdgpu_mn *mn;
542 struct list_head mn_list;
543};
544#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
545
546void amdgpu_gem_object_free(struct drm_gem_object *obj);
547int amdgpu_gem_object_open(struct drm_gem_object *obj,
548 struct drm_file *file_priv);
549void amdgpu_gem_object_close(struct drm_gem_object *obj,
550 struct drm_file *file_priv);
551unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
552struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
553struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
554 struct dma_buf_attachment *attach,
555 struct sg_table *sg);
556struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
557 struct drm_gem_object *gobj,
558 int flags);
559int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
560void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
561struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
562void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
563void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
564int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
565
566/* sub-allocation manager, it has to be protected by another lock.
567 * By conception this is an helper for other part of the driver
568 * like the indirect buffer or semaphore, which both have their
569 * locking.
570 *
571 * Principe is simple, we keep a list of sub allocation in offset
572 * order (first entry has offset == 0, last entry has the highest
573 * offset).
574 *
575 * When allocating new object we first check if there is room at
576 * the end total_size - (last_object_offset + last_object_size) >=
577 * alloc_size. If so we allocate new object there.
578 *
579 * When there is not enough room at the end, we start waiting for
580 * each sub object until we reach object_offset+object_size >=
581 * alloc_size, this object then become the sub object we return.
582 *
583 * Alignment can't be bigger than page size.
584 *
585 * Hole are not considered for allocation to keep things simple.
586 * Assumption is that there won't be hole (all object on same
587 * alignment).
588 */
589struct amdgpu_sa_manager {
590 wait_queue_head_t wq;
591 struct amdgpu_bo *bo;
592 struct list_head *hole;
593 struct list_head flist[AMDGPU_MAX_RINGS];
594 struct list_head olist;
595 unsigned size;
596 uint64_t gpu_addr;
597 void *cpu_ptr;
598 uint32_t domain;
599 uint32_t align;
600};
601
602struct amdgpu_sa_bo;
603
604/* sub-allocation buffer */
605struct amdgpu_sa_bo {
606 struct list_head olist;
607 struct list_head flist;
608 struct amdgpu_sa_manager *manager;
609 unsigned soffset;
610 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800611 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400612};
613
614/*
615 * GEM objects.
616 */
617struct amdgpu_gem {
618 struct mutex mutex;
619 struct list_head objects;
620};
621
622int amdgpu_gem_init(struct amdgpu_device *adev);
623void amdgpu_gem_fini(struct amdgpu_device *adev);
624int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
625 int alignment, u32 initial_domain,
626 u64 flags, bool kernel,
627 struct drm_gem_object **obj);
628
629int amdgpu_mode_dumb_create(struct drm_file *file_priv,
630 struct drm_device *dev,
631 struct drm_mode_create_dumb *args);
632int amdgpu_mode_dumb_mmap(struct drm_file *filp,
633 struct drm_device *dev,
634 uint32_t handle, uint64_t *offset_p);
635
636/*
637 * Semaphores.
638 */
639struct amdgpu_semaphore {
640 struct amdgpu_sa_bo *sa_bo;
641 signed waiters;
642 uint64_t gpu_addr;
643};
644
645int amdgpu_semaphore_create(struct amdgpu_device *adev,
646 struct amdgpu_semaphore **semaphore);
647bool amdgpu_semaphore_emit_signal(struct amdgpu_ring *ring,
648 struct amdgpu_semaphore *semaphore);
649bool amdgpu_semaphore_emit_wait(struct amdgpu_ring *ring,
650 struct amdgpu_semaphore *semaphore);
651void amdgpu_semaphore_free(struct amdgpu_device *adev,
652 struct amdgpu_semaphore **semaphore,
Chunming Zhou4ce98912015-08-19 16:41:19 +0800653 struct fence *fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400654
655/*
656 * Synchronization
657 */
658struct amdgpu_sync {
659 struct amdgpu_semaphore *semaphores[AMDGPU_NUM_SYNCS];
Christian König16545c32015-10-22 15:04:50 +0200660 struct fence *sync_to[AMDGPU_MAX_RINGS];
Christian Königf91b3a62015-08-20 14:47:40 +0800661 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800662 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400663};
664
665void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200666int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
667 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400668int amdgpu_sync_resv(struct amdgpu_device *adev,
669 struct amdgpu_sync *sync,
670 struct reservation_object *resv,
671 void *owner);
672int amdgpu_sync_rings(struct amdgpu_sync *sync,
673 struct amdgpu_ring *ring);
Christian Könige61235d2015-08-25 11:05:36 +0200674struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian Königf91b3a62015-08-20 14:47:40 +0800675int amdgpu_sync_wait(struct amdgpu_sync *sync);
Alex Deucher97b2e202015-04-20 16:51:00 -0400676void amdgpu_sync_free(struct amdgpu_device *adev, struct amdgpu_sync *sync,
Chunming Zhou4ce98912015-08-19 16:41:19 +0800677 struct fence *fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400678
679/*
680 * GART structures, functions & helpers
681 */
682struct amdgpu_mc;
683
684#define AMDGPU_GPU_PAGE_SIZE 4096
685#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
686#define AMDGPU_GPU_PAGE_SHIFT 12
687#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
688
689struct amdgpu_gart {
690 dma_addr_t table_addr;
691 struct amdgpu_bo *robj;
692 void *ptr;
693 unsigned num_gpu_pages;
694 unsigned num_cpu_pages;
695 unsigned table_size;
696 struct page **pages;
697 dma_addr_t *pages_addr;
698 bool ready;
699 const struct amdgpu_gart_funcs *gart_funcs;
700};
701
702int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
703void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
704int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
705void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
706int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
707void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
708int amdgpu_gart_init(struct amdgpu_device *adev);
709void amdgpu_gart_fini(struct amdgpu_device *adev);
710void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
711 int pages);
712int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
713 int pages, struct page **pagelist,
714 dma_addr_t *dma_addr, uint32_t flags);
715
716/*
717 * GPU MC structures, functions & helpers
718 */
719struct amdgpu_mc {
720 resource_size_t aper_size;
721 resource_size_t aper_base;
722 resource_size_t agp_base;
723 /* for some chips with <= 32MB we need to lie
724 * about vram size near mc fb location */
725 u64 mc_vram_size;
726 u64 visible_vram_size;
727 u64 gtt_size;
728 u64 gtt_start;
729 u64 gtt_end;
730 u64 vram_start;
731 u64 vram_end;
732 unsigned vram_width;
733 u64 real_vram_size;
734 int vram_mtrr;
735 u64 gtt_base_align;
736 u64 mc_mask;
737 const struct firmware *fw; /* MC firmware */
738 uint32_t fw_version;
739 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800740 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400741};
742
743/*
744 * GPU doorbell structures, functions & helpers
745 */
746typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
747{
748 AMDGPU_DOORBELL_KIQ = 0x000,
749 AMDGPU_DOORBELL_HIQ = 0x001,
750 AMDGPU_DOORBELL_DIQ = 0x002,
751 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
752 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
753 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
754 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
755 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
756 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
757 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
758 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
759 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
760 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
761 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
762 AMDGPU_DOORBELL_IH = 0x1E8,
763 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
764 AMDGPU_DOORBELL_INVALID = 0xFFFF
765} AMDGPU_DOORBELL_ASSIGNMENT;
766
767struct amdgpu_doorbell {
768 /* doorbell mmio */
769 resource_size_t base;
770 resource_size_t size;
771 u32 __iomem *ptr;
772 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
773};
774
775void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
776 phys_addr_t *aperture_base,
777 size_t *aperture_size,
778 size_t *start_offset);
779
780/*
781 * IRQS.
782 */
783
784struct amdgpu_flip_work {
785 struct work_struct flip_work;
786 struct work_struct unpin_work;
787 struct amdgpu_device *adev;
788 int crtc_id;
789 uint64_t base;
790 struct drm_pending_vblank_event *event;
791 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200792 struct fence *excl;
793 unsigned shared_count;
794 struct fence **shared;
Alex Deucher97b2e202015-04-20 16:51:00 -0400795};
796
797
798/*
799 * CP & rings.
800 */
801
802struct amdgpu_ib {
803 struct amdgpu_sa_bo *sa_bo;
804 uint32_t length_dw;
805 uint64_t gpu_addr;
806 uint32_t *ptr;
807 struct amdgpu_ring *ring;
808 struct amdgpu_fence *fence;
809 struct amdgpu_user_fence *user;
810 struct amdgpu_vm *vm;
Christian König3cb485f2015-05-11 15:34:59 +0200811 struct amdgpu_ctx *ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400812 struct amdgpu_sync sync;
Alex Deucher97b2e202015-04-20 16:51:00 -0400813 uint32_t gds_base, gds_size;
814 uint32_t gws_base, gws_size;
815 uint32_t oa_base, oa_size;
Jammy Zhoude807f82015-05-11 23:41:41 +0800816 uint32_t flags;
Christian König5430a3f2015-07-21 18:02:21 +0200817 /* resulting sequence number */
818 uint64_t sequence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400819};
820
821enum amdgpu_ring_type {
822 AMDGPU_RING_TYPE_GFX,
823 AMDGPU_RING_TYPE_COMPUTE,
824 AMDGPU_RING_TYPE_SDMA,
825 AMDGPU_RING_TYPE_UVD,
826 AMDGPU_RING_TYPE_VCE
827};
828
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800829extern struct amd_sched_backend_ops amdgpu_sched_ops;
830
Chunming Zhou3c704e92015-07-29 10:33:14 +0800831int amdgpu_sched_ib_submit_kernel_helper(struct amdgpu_device *adev,
832 struct amdgpu_ring *ring,
833 struct amdgpu_ib *ibs,
834 unsigned num_ibs,
Chunming Zhoubb977d32015-08-18 15:16:40 +0800835 int (*free_job)(struct amdgpu_job *),
Chunming Zhou17635522015-08-03 11:43:19 +0800836 void *owner,
837 struct fence **fence);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800838
Alex Deucher97b2e202015-04-20 16:51:00 -0400839struct amdgpu_ring {
840 struct amdgpu_device *adev;
841 const struct amdgpu_ring_funcs *funcs;
842 struct amdgpu_fence_driver fence_drv;
Christian König4f839a22015-09-08 20:22:31 +0200843 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400844
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800845 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400846 struct mutex *ring_lock;
847 struct amdgpu_bo *ring_obj;
848 volatile uint32_t *ring;
849 unsigned rptr_offs;
850 u64 next_rptr_gpu_addr;
851 volatile u32 *next_rptr_cpu_addr;
852 unsigned wptr;
853 unsigned wptr_old;
854 unsigned ring_size;
855 unsigned ring_free_dw;
856 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400857 uint64_t gpu_addr;
858 uint32_t align_mask;
859 uint32_t ptr_mask;
860 bool ready;
861 u32 nop;
862 u32 idx;
863 u64 last_semaphore_signal_addr;
864 u64 last_semaphore_wait_addr;
865 u32 me;
866 u32 pipe;
867 u32 queue;
868 struct amdgpu_bo *mqd_obj;
869 u32 doorbell_index;
870 bool use_doorbell;
871 unsigned wptr_offs;
872 unsigned next_rptr_offs;
873 unsigned fence_offs;
Christian König3cb485f2015-05-11 15:34:59 +0200874 struct amdgpu_ctx *current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400875 enum amdgpu_ring_type type;
876 char name[16];
Chunming Zhou4274f5d2015-07-21 16:04:39 +0800877 bool is_pte_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400878};
879
880/*
881 * VM
882 */
883
884/* maximum number of VMIDs */
885#define AMDGPU_NUM_VM 16
886
887/* number of entries in page table */
888#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
889
890/* PTBs (Page Table Blocks) need to be aligned to 32K */
891#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
892#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
893#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
894
895#define AMDGPU_PTE_VALID (1 << 0)
896#define AMDGPU_PTE_SYSTEM (1 << 1)
897#define AMDGPU_PTE_SNOOPED (1 << 2)
898
899/* VI only */
900#define AMDGPU_PTE_EXECUTABLE (1 << 4)
901
902#define AMDGPU_PTE_READABLE (1 << 5)
903#define AMDGPU_PTE_WRITEABLE (1 << 6)
904
905/* PTE (Page Table Entry) fragment field for different page sizes */
906#define AMDGPU_PTE_FRAG_4KB (0 << 7)
907#define AMDGPU_PTE_FRAG_64KB (4 << 7)
908#define AMDGPU_LOG2_PAGES_PER_FRAG 4
909
Christian Königd9c13152015-09-28 12:31:26 +0200910/* How to programm VM fault handling */
911#define AMDGPU_VM_FAULT_STOP_NEVER 0
912#define AMDGPU_VM_FAULT_STOP_FIRST 1
913#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
914
Alex Deucher97b2e202015-04-20 16:51:00 -0400915struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100916 struct amdgpu_bo_list_entry entry;
917 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400918};
919
920struct amdgpu_vm_id {
921 unsigned id;
922 uint64_t pd_gpu_addr;
923 /* last flushed PD/PT update */
Chunming Zhou3c623382015-08-20 18:33:59 +0800924 struct fence *flushed_updates;
Alex Deucher97b2e202015-04-20 16:51:00 -0400925};
926
927struct amdgpu_vm {
Alex Deucher97b2e202015-04-20 16:51:00 -0400928 struct rb_root va;
929
Christian König7fc11952015-07-30 11:53:42 +0200930 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400931 spinlock_t status_lock;
932
933 /* BOs moved, but not yet updated in the PT */
934 struct list_head invalidated;
935
Christian König7fc11952015-07-30 11:53:42 +0200936 /* BOs cleared in the PT because of a move */
937 struct list_head cleared;
938
939 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400940 struct list_head freed;
941
942 /* contains the page directory */
943 struct amdgpu_bo *page_directory;
944 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200945 struct fence *page_directory_fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400946
947 /* array of page tables, one for each page directory entry */
948 struct amdgpu_vm_pt *page_tables;
949
950 /* for id and flush management per ring */
951 struct amdgpu_vm_id ids[AMDGPU_MAX_RINGS];
Chunming Zhouc25867d2015-11-13 13:32:01 +0800952 /* for interval tree */
953 spinlock_t it_lock;
jimqu81d75a32015-12-04 17:17:00 +0800954 /* protecting freed */
955 spinlock_t freed_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400956};
957
958struct amdgpu_vm_manager {
Christian König1c16c0a2015-11-14 21:31:40 +0100959 struct {
960 struct fence *active;
961 atomic_long_t owner;
962 } ids[AMDGPU_NUM_VM];
963
Christian König8b4fb002015-11-15 16:04:16 +0100964 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400965 /* number of VMIDs */
Christian König8b4fb002015-11-15 16:04:16 +0100966 unsigned nvm;
Alex Deucher97b2e202015-04-20 16:51:00 -0400967 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100968 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400969 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100970 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400971 /* vm pte handling */
972 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
973 struct amdgpu_ring *vm_pte_funcs_ring;
974};
975
Christian Königea89f8c2015-11-15 20:52:06 +0100976void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100977int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
978void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100979void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
980 struct list_head *validated,
981 struct amdgpu_bo_list_entry *entry);
Christian Königee1782c2015-12-11 21:01:23 +0100982void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100983void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
984 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100985int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
986 struct amdgpu_sync *sync);
987void amdgpu_vm_flush(struct amdgpu_ring *ring,
988 struct amdgpu_vm *vm,
989 struct fence *updates);
990void amdgpu_vm_fence(struct amdgpu_device *adev,
991 struct amdgpu_vm *vm,
992 struct fence *fence);
993uint64_t amdgpu_vm_map_gart(struct amdgpu_device *adev, uint64_t addr);
994int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
995 struct amdgpu_vm *vm);
996int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
997 struct amdgpu_vm *vm);
998int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
999 struct amdgpu_sync *sync);
1000int amdgpu_vm_bo_update(struct amdgpu_device *adev,
1001 struct amdgpu_bo_va *bo_va,
1002 struct ttm_mem_reg *mem);
1003void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
1004 struct amdgpu_bo *bo);
1005struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
1006 struct amdgpu_bo *bo);
1007struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
1008 struct amdgpu_vm *vm,
1009 struct amdgpu_bo *bo);
1010int amdgpu_vm_bo_map(struct amdgpu_device *adev,
1011 struct amdgpu_bo_va *bo_va,
1012 uint64_t addr, uint64_t offset,
1013 uint64_t size, uint32_t flags);
1014int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
1015 struct amdgpu_bo_va *bo_va,
1016 uint64_t addr);
1017void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
1018 struct amdgpu_bo_va *bo_va);
1019int amdgpu_vm_free_job(struct amdgpu_job *job);
1020
Alex Deucher97b2e202015-04-20 16:51:00 -04001021/*
1022 * context related structures
1023 */
1024
Christian König21c16bf2015-07-07 17:24:49 +02001025struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +02001026 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +08001027 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +02001028 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +02001029};
1030
Alex Deucher97b2e202015-04-20 16:51:00 -04001031struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -04001032 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +08001033 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -04001034 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +02001035 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +08001036 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +02001037 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001038};
1039
1040struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -04001041 struct amdgpu_device *adev;
1042 struct mutex lock;
1043 /* protected by lock */
1044 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001045};
1046
Chunming Zhoud033a6d2015-11-05 15:23:09 +08001047int amdgpu_ctx_init(struct amdgpu_device *adev, enum amd_sched_priority pri,
Christian König47f38502015-08-04 17:51:05 +02001048 struct amdgpu_ctx *ctx);
1049void amdgpu_ctx_fini(struct amdgpu_ctx *ctx);
Alex Deucher0b492a42015-08-16 22:48:26 -04001050
Alex Deucher0b492a42015-08-16 22:48:26 -04001051struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
1052int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
1053
Christian König21c16bf2015-07-07 17:24:49 +02001054uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +02001055 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +02001056struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
1057 struct amdgpu_ring *ring, uint64_t seq);
1058
Alex Deucher0b492a42015-08-16 22:48:26 -04001059int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1060 struct drm_file *filp);
1061
Christian Königefd4ccb2015-08-04 16:20:31 +02001062void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1063void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -04001064
Alex Deucher97b2e202015-04-20 16:51:00 -04001065/*
1066 * file private structure
1067 */
1068
1069struct amdgpu_fpriv {
1070 struct amdgpu_vm vm;
1071 struct mutex bo_list_lock;
1072 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001073 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001074};
1075
1076/*
1077 * residency list
1078 */
1079
1080struct amdgpu_bo_list {
1081 struct mutex lock;
1082 struct amdgpu_bo *gds_obj;
1083 struct amdgpu_bo *gws_obj;
1084 struct amdgpu_bo *oa_obj;
1085 bool has_userptr;
1086 unsigned num_entries;
1087 struct amdgpu_bo_list_entry *array;
1088};
1089
1090struct amdgpu_bo_list *
1091amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
1092void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1093void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1094
1095/*
1096 * GFX stuff
1097 */
1098#include "clearstate_defs.h"
1099
1100struct amdgpu_rlc {
1101 /* for power gating */
1102 struct amdgpu_bo *save_restore_obj;
1103 uint64_t save_restore_gpu_addr;
1104 volatile uint32_t *sr_ptr;
1105 const u32 *reg_list;
1106 u32 reg_list_size;
1107 /* for clear state */
1108 struct amdgpu_bo *clear_state_obj;
1109 uint64_t clear_state_gpu_addr;
1110 volatile uint32_t *cs_ptr;
1111 const struct cs_section_def *cs_data;
1112 u32 clear_state_size;
1113 /* for cp tables */
1114 struct amdgpu_bo *cp_table_obj;
1115 uint64_t cp_table_gpu_addr;
1116 volatile uint32_t *cp_table_ptr;
1117 u32 cp_table_size;
1118};
1119
1120struct amdgpu_mec {
1121 struct amdgpu_bo *hpd_eop_obj;
1122 u64 hpd_eop_gpu_addr;
1123 u32 num_pipe;
1124 u32 num_mec;
1125 u32 num_queue;
1126};
1127
1128/*
1129 * GPU scratch registers structures, functions & helpers
1130 */
1131struct amdgpu_scratch {
1132 unsigned num_reg;
1133 uint32_t reg_base;
1134 bool free[32];
1135 uint32_t reg[32];
1136};
1137
1138/*
1139 * GFX configurations
1140 */
1141struct amdgpu_gca_config {
1142 unsigned max_shader_engines;
1143 unsigned max_tile_pipes;
1144 unsigned max_cu_per_sh;
1145 unsigned max_sh_per_se;
1146 unsigned max_backends_per_se;
1147 unsigned max_texture_channel_caches;
1148 unsigned max_gprs;
1149 unsigned max_gs_threads;
1150 unsigned max_hw_contexts;
1151 unsigned sc_prim_fifo_size_frontend;
1152 unsigned sc_prim_fifo_size_backend;
1153 unsigned sc_hiz_tile_fifo_size;
1154 unsigned sc_earlyz_tile_fifo_size;
1155
1156 unsigned num_tile_pipes;
1157 unsigned backend_enable_mask;
1158 unsigned mem_max_burst_length_bytes;
1159 unsigned mem_row_size_in_kb;
1160 unsigned shader_engine_tile_size;
1161 unsigned num_gpus;
1162 unsigned multi_gpu_tile_size;
1163 unsigned mc_arb_ramcfg;
1164 unsigned gb_addr_config;
1165
1166 uint32_t tile_mode_array[32];
1167 uint32_t macrotile_mode_array[16];
1168};
1169
1170struct amdgpu_gfx {
1171 struct mutex gpu_clock_mutex;
1172 struct amdgpu_gca_config config;
1173 struct amdgpu_rlc rlc;
1174 struct amdgpu_mec mec;
1175 struct amdgpu_scratch scratch;
1176 const struct firmware *me_fw; /* ME firmware */
1177 uint32_t me_fw_version;
1178 const struct firmware *pfp_fw; /* PFP firmware */
1179 uint32_t pfp_fw_version;
1180 const struct firmware *ce_fw; /* CE firmware */
1181 uint32_t ce_fw_version;
1182 const struct firmware *rlc_fw; /* RLC firmware */
1183 uint32_t rlc_fw_version;
1184 const struct firmware *mec_fw; /* MEC firmware */
1185 uint32_t mec_fw_version;
1186 const struct firmware *mec2_fw; /* MEC2 firmware */
1187 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001188 uint32_t me_feature_version;
1189 uint32_t ce_feature_version;
1190 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001191 uint32_t rlc_feature_version;
1192 uint32_t mec_feature_version;
1193 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001194 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1195 unsigned num_gfx_rings;
1196 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1197 unsigned num_compute_rings;
1198 struct amdgpu_irq_src eop_irq;
1199 struct amdgpu_irq_src priv_reg_irq;
1200 struct amdgpu_irq_src priv_inst_irq;
1201 /* gfx status */
1202 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001203 /* ce ram size*/
1204 unsigned ce_ram_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001205};
1206
1207int amdgpu_ib_get(struct amdgpu_ring *ring, struct amdgpu_vm *vm,
1208 unsigned size, struct amdgpu_ib *ib);
1209void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib);
1210int amdgpu_ib_schedule(struct amdgpu_device *adev, unsigned num_ibs,
1211 struct amdgpu_ib *ib, void *owner);
1212int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1213void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1214int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
1215/* Ring access between begin & end cannot sleep */
1216void amdgpu_ring_free_size(struct amdgpu_ring *ring);
1217int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
1218int amdgpu_ring_lock(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001219void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Alex Deucher97b2e202015-04-20 16:51:00 -04001220void amdgpu_ring_commit(struct amdgpu_ring *ring);
1221void amdgpu_ring_unlock_commit(struct amdgpu_ring *ring);
1222void amdgpu_ring_undo(struct amdgpu_ring *ring);
1223void amdgpu_ring_unlock_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001224unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1225 uint32_t **data);
1226int amdgpu_ring_restore(struct amdgpu_ring *ring,
1227 unsigned size, uint32_t *data);
1228int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1229 unsigned ring_size, u32 nop, u32 align_mask,
1230 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1231 enum amdgpu_ring_type ring_type);
1232void amdgpu_ring_fini(struct amdgpu_ring *ring);
Christian König8120b612015-10-22 11:29:33 +02001233struct amdgpu_ring *amdgpu_ring_from_fence(struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001234
1235/*
1236 * CS.
1237 */
1238struct amdgpu_cs_chunk {
1239 uint32_t chunk_id;
1240 uint32_t length_dw;
1241 uint32_t *kdata;
1242 void __user *user_ptr;
1243};
1244
1245struct amdgpu_cs_parser {
1246 struct amdgpu_device *adev;
1247 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001248 struct amdgpu_ctx *ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -04001249 struct amdgpu_bo_list *bo_list;
1250 /* chunks */
1251 unsigned nchunks;
1252 struct amdgpu_cs_chunk *chunks;
1253 /* relocations */
Christian König56467eb2015-12-11 15:16:32 +01001254 struct amdgpu_bo_list_entry vm_pd;
Alex Deucher97b2e202015-04-20 16:51:00 -04001255 struct list_head validated;
Christian König984810f2015-11-14 21:05:35 +01001256 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -04001257
1258 struct amdgpu_ib *ibs;
1259 uint32_t num_ibs;
1260
1261 struct ww_acquire_ctx ticket;
1262
1263 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001264 struct amdgpu_user_fence uf;
1265 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001266};
1267
Chunming Zhoubb977d32015-08-18 15:16:40 +08001268struct amdgpu_job {
1269 struct amd_sched_job base;
1270 struct amdgpu_device *adev;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001271 struct amdgpu_ib *ibs;
1272 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001273 void *owner;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001274 struct amdgpu_user_fence uf;
Junwei Zhang4c7eb912015-09-09 09:05:55 +08001275 int (*free_job)(struct amdgpu_job *job);
Chunming Zhoubb977d32015-08-18 15:16:40 +08001276};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001277#define to_amdgpu_job(sched_job) \
1278 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001279
Alex Deucher97b2e202015-04-20 16:51:00 -04001280static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, uint32_t ib_idx, int idx)
1281{
1282 return p->ibs[ib_idx].ptr[idx];
1283}
1284
1285/*
1286 * Writeback
1287 */
1288#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1289
1290struct amdgpu_wb {
1291 struct amdgpu_bo *wb_obj;
1292 volatile uint32_t *wb;
1293 uint64_t gpu_addr;
1294 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1295 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1296};
1297
1298int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1299void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1300
Alex Deucher97b2e202015-04-20 16:51:00 -04001301
Alex Deucher97b2e202015-04-20 16:51:00 -04001302
1303enum amdgpu_int_thermal_type {
1304 THERMAL_TYPE_NONE,
1305 THERMAL_TYPE_EXTERNAL,
1306 THERMAL_TYPE_EXTERNAL_GPIO,
1307 THERMAL_TYPE_RV6XX,
1308 THERMAL_TYPE_RV770,
1309 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1310 THERMAL_TYPE_EVERGREEN,
1311 THERMAL_TYPE_SUMO,
1312 THERMAL_TYPE_NI,
1313 THERMAL_TYPE_SI,
1314 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1315 THERMAL_TYPE_CI,
1316 THERMAL_TYPE_KV,
1317};
1318
1319enum amdgpu_dpm_auto_throttle_src {
1320 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1321 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1322};
1323
1324enum amdgpu_dpm_event_src {
1325 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1326 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1327 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1328 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1329 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1330};
1331
1332#define AMDGPU_MAX_VCE_LEVELS 6
1333
1334enum amdgpu_vce_level {
1335 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1336 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1337 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1338 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1339 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1340 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1341};
1342
1343struct amdgpu_ps {
1344 u32 caps; /* vbios flags */
1345 u32 class; /* vbios flags */
1346 u32 class2; /* vbios flags */
1347 /* UVD clocks */
1348 u32 vclk;
1349 u32 dclk;
1350 /* VCE clocks */
1351 u32 evclk;
1352 u32 ecclk;
1353 bool vce_active;
1354 enum amdgpu_vce_level vce_level;
1355 /* asic priv */
1356 void *ps_priv;
1357};
1358
1359struct amdgpu_dpm_thermal {
1360 /* thermal interrupt work */
1361 struct work_struct work;
1362 /* low temperature threshold */
1363 int min_temp;
1364 /* high temperature threshold */
1365 int max_temp;
1366 /* was last interrupt low to high or high to low */
1367 bool high_to_low;
1368 /* interrupt source */
1369 struct amdgpu_irq_src irq;
1370};
1371
1372enum amdgpu_clk_action
1373{
1374 AMDGPU_SCLK_UP = 1,
1375 AMDGPU_SCLK_DOWN
1376};
1377
1378struct amdgpu_blacklist_clocks
1379{
1380 u32 sclk;
1381 u32 mclk;
1382 enum amdgpu_clk_action action;
1383};
1384
1385struct amdgpu_clock_and_voltage_limits {
1386 u32 sclk;
1387 u32 mclk;
1388 u16 vddc;
1389 u16 vddci;
1390};
1391
1392struct amdgpu_clock_array {
1393 u32 count;
1394 u32 *values;
1395};
1396
1397struct amdgpu_clock_voltage_dependency_entry {
1398 u32 clk;
1399 u16 v;
1400};
1401
1402struct amdgpu_clock_voltage_dependency_table {
1403 u32 count;
1404 struct amdgpu_clock_voltage_dependency_entry *entries;
1405};
1406
1407union amdgpu_cac_leakage_entry {
1408 struct {
1409 u16 vddc;
1410 u32 leakage;
1411 };
1412 struct {
1413 u16 vddc1;
1414 u16 vddc2;
1415 u16 vddc3;
1416 };
1417};
1418
1419struct amdgpu_cac_leakage_table {
1420 u32 count;
1421 union amdgpu_cac_leakage_entry *entries;
1422};
1423
1424struct amdgpu_phase_shedding_limits_entry {
1425 u16 voltage;
1426 u32 sclk;
1427 u32 mclk;
1428};
1429
1430struct amdgpu_phase_shedding_limits_table {
1431 u32 count;
1432 struct amdgpu_phase_shedding_limits_entry *entries;
1433};
1434
1435struct amdgpu_uvd_clock_voltage_dependency_entry {
1436 u32 vclk;
1437 u32 dclk;
1438 u16 v;
1439};
1440
1441struct amdgpu_uvd_clock_voltage_dependency_table {
1442 u8 count;
1443 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1444};
1445
1446struct amdgpu_vce_clock_voltage_dependency_entry {
1447 u32 ecclk;
1448 u32 evclk;
1449 u16 v;
1450};
1451
1452struct amdgpu_vce_clock_voltage_dependency_table {
1453 u8 count;
1454 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1455};
1456
1457struct amdgpu_ppm_table {
1458 u8 ppm_design;
1459 u16 cpu_core_number;
1460 u32 platform_tdp;
1461 u32 small_ac_platform_tdp;
1462 u32 platform_tdc;
1463 u32 small_ac_platform_tdc;
1464 u32 apu_tdp;
1465 u32 dgpu_tdp;
1466 u32 dgpu_ulv_power;
1467 u32 tj_max;
1468};
1469
1470struct amdgpu_cac_tdp_table {
1471 u16 tdp;
1472 u16 configurable_tdp;
1473 u16 tdc;
1474 u16 battery_power_limit;
1475 u16 small_power_limit;
1476 u16 low_cac_leakage;
1477 u16 high_cac_leakage;
1478 u16 maximum_power_delivery_limit;
1479};
1480
1481struct amdgpu_dpm_dynamic_state {
1482 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1483 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1484 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1485 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1486 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1487 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1488 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1489 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1490 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1491 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1492 struct amdgpu_clock_array valid_sclk_values;
1493 struct amdgpu_clock_array valid_mclk_values;
1494 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1495 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1496 u32 mclk_sclk_ratio;
1497 u32 sclk_mclk_delta;
1498 u16 vddc_vddci_delta;
1499 u16 min_vddc_for_pcie_gen2;
1500 struct amdgpu_cac_leakage_table cac_leakage_table;
1501 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1502 struct amdgpu_ppm_table *ppm_table;
1503 struct amdgpu_cac_tdp_table *cac_tdp_table;
1504};
1505
1506struct amdgpu_dpm_fan {
1507 u16 t_min;
1508 u16 t_med;
1509 u16 t_high;
1510 u16 pwm_min;
1511 u16 pwm_med;
1512 u16 pwm_high;
1513 u8 t_hyst;
1514 u32 cycle_delay;
1515 u16 t_max;
1516 u8 control_mode;
1517 u16 default_max_fan_pwm;
1518 u16 default_fan_output_sensitivity;
1519 u16 fan_output_sensitivity;
1520 bool ucode_fan_control;
1521};
1522
1523enum amdgpu_pcie_gen {
1524 AMDGPU_PCIE_GEN1 = 0,
1525 AMDGPU_PCIE_GEN2 = 1,
1526 AMDGPU_PCIE_GEN3 = 2,
1527 AMDGPU_PCIE_GEN_INVALID = 0xffff
1528};
1529
1530enum amdgpu_dpm_forced_level {
1531 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1532 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1533 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
1534};
1535
1536struct amdgpu_vce_state {
1537 /* vce clocks */
1538 u32 evclk;
1539 u32 ecclk;
1540 /* gpu clocks */
1541 u32 sclk;
1542 u32 mclk;
1543 u8 clk_idx;
1544 u8 pstate;
1545};
1546
1547struct amdgpu_dpm_funcs {
1548 int (*get_temperature)(struct amdgpu_device *adev);
1549 int (*pre_set_power_state)(struct amdgpu_device *adev);
1550 int (*set_power_state)(struct amdgpu_device *adev);
1551 void (*post_set_power_state)(struct amdgpu_device *adev);
1552 void (*display_configuration_changed)(struct amdgpu_device *adev);
1553 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1554 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1555 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1556 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1557 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1558 bool (*vblank_too_short)(struct amdgpu_device *adev);
1559 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a077692015-05-28 15:47:53 -04001560 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001561 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1562 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1563 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1564 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1565 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1566};
1567
1568struct amdgpu_dpm {
1569 struct amdgpu_ps *ps;
1570 /* number of valid power states */
1571 int num_ps;
1572 /* current power state that is active */
1573 struct amdgpu_ps *current_ps;
1574 /* requested power state */
1575 struct amdgpu_ps *requested_ps;
1576 /* boot up power state */
1577 struct amdgpu_ps *boot_ps;
1578 /* default uvd power state */
1579 struct amdgpu_ps *uvd_ps;
1580 /* vce requirements */
1581 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1582 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001583 enum amd_pm_state_type state;
1584 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001585 u32 platform_caps;
1586 u32 voltage_response_time;
1587 u32 backbias_response_time;
1588 void *priv;
1589 u32 new_active_crtcs;
1590 int new_active_crtc_count;
1591 u32 current_active_crtcs;
1592 int current_active_crtc_count;
1593 struct amdgpu_dpm_dynamic_state dyn_state;
1594 struct amdgpu_dpm_fan fan;
1595 u32 tdp_limit;
1596 u32 near_tdp_limit;
1597 u32 near_tdp_limit_adjusted;
1598 u32 sq_ramping_threshold;
1599 u32 cac_leakage;
1600 u16 tdp_od_limit;
1601 u32 tdp_adjustment;
1602 u16 load_line_slope;
1603 bool power_control;
1604 bool ac_power;
1605 /* special states active */
1606 bool thermal_active;
1607 bool uvd_active;
1608 bool vce_active;
1609 /* thermal handling */
1610 struct amdgpu_dpm_thermal thermal;
1611 /* forced levels */
1612 enum amdgpu_dpm_forced_level forced_level;
1613};
1614
1615struct amdgpu_pm {
1616 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001617 u32 current_sclk;
1618 u32 current_mclk;
1619 u32 default_sclk;
1620 u32 default_mclk;
1621 struct amdgpu_i2c_chan *i2c_bus;
1622 /* internal thermal controller on rv6xx+ */
1623 enum amdgpu_int_thermal_type int_thermal_type;
1624 struct device *int_hwmon_dev;
1625 /* fan control parameters */
1626 bool no_fan;
1627 u8 fan_pulses_per_revolution;
1628 u8 fan_min_rpm;
1629 u8 fan_max_rpm;
1630 /* dpm */
1631 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001632 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001633 struct amdgpu_dpm dpm;
1634 const struct firmware *fw; /* SMC firmware */
1635 uint32_t fw_version;
1636 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001637 uint32_t pcie_gen_mask;
1638 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001639 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001640};
1641
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001642void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1643
Alex Deucher97b2e202015-04-20 16:51:00 -04001644/*
1645 * UVD
1646 */
1647#define AMDGPU_MAX_UVD_HANDLES 10
1648#define AMDGPU_UVD_STACK_SIZE (1024*1024)
1649#define AMDGPU_UVD_HEAP_SIZE (1024*1024)
1650#define AMDGPU_UVD_FIRMWARE_OFFSET 256
1651
1652struct amdgpu_uvd {
1653 struct amdgpu_bo *vcpu_bo;
1654 void *cpu_addr;
1655 uint64_t gpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001656 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1657 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1658 struct delayed_work idle_work;
1659 const struct firmware *fw; /* UVD firmware */
1660 struct amdgpu_ring ring;
1661 struct amdgpu_irq_src irq;
1662 bool address_64_bit;
1663};
1664
1665/*
1666 * VCE
1667 */
1668#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001669#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1670
Alex Deucher6a585772015-07-10 14:16:24 -04001671#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1672#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1673
Alex Deucher97b2e202015-04-20 16:51:00 -04001674struct amdgpu_vce {
1675 struct amdgpu_bo *vcpu_bo;
1676 uint64_t gpu_addr;
1677 unsigned fw_version;
1678 unsigned fb_version;
1679 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1680 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001681 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001682 struct delayed_work idle_work;
1683 const struct firmware *fw; /* VCE firmware */
1684 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1685 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001686 unsigned harvest_config;
Alex Deucher97b2e202015-04-20 16:51:00 -04001687};
1688
1689/*
1690 * SDMA
1691 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001692struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001693 /* SDMA firmware */
1694 const struct firmware *fw;
1695 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001696 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001697
1698 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001699 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001700};
1701
Alex Deucherc113ea12015-10-08 16:30:37 -04001702struct amdgpu_sdma {
1703 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1704 struct amdgpu_irq_src trap_irq;
1705 struct amdgpu_irq_src illegal_inst_irq;
1706 int num_instances;
1707};
1708
Alex Deucher97b2e202015-04-20 16:51:00 -04001709/*
1710 * Firmware
1711 */
1712struct amdgpu_firmware {
1713 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1714 bool smu_load;
1715 struct amdgpu_bo *fw_buf;
1716 unsigned int fw_size;
1717};
1718
1719/*
1720 * Benchmarking
1721 */
1722void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1723
1724
1725/*
1726 * Testing
1727 */
1728void amdgpu_test_moves(struct amdgpu_device *adev);
1729void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1730 struct amdgpu_ring *cpA,
1731 struct amdgpu_ring *cpB);
1732void amdgpu_test_syncing(struct amdgpu_device *adev);
1733
1734/*
1735 * MMU Notifier
1736 */
1737#if defined(CONFIG_MMU_NOTIFIER)
1738int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1739void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1740#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001741static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001742{
1743 return -ENODEV;
1744}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001745static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001746#endif
1747
1748/*
1749 * Debugfs
1750 */
1751struct amdgpu_debugfs {
1752 struct drm_info_list *files;
1753 unsigned num_files;
1754};
1755
1756int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
1757 struct drm_info_list *files,
1758 unsigned nfiles);
1759int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1760
1761#if defined(CONFIG_DEBUG_FS)
1762int amdgpu_debugfs_init(struct drm_minor *minor);
1763void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1764#endif
1765
1766/*
1767 * amdgpu smumgr functions
1768 */
1769struct amdgpu_smumgr_funcs {
1770 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1771 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1772 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1773};
1774
1775/*
1776 * amdgpu smumgr
1777 */
1778struct amdgpu_smumgr {
1779 struct amdgpu_bo *toc_buf;
1780 struct amdgpu_bo *smu_buf;
1781 /* asic priv smu data */
1782 void *priv;
1783 spinlock_t smu_lock;
1784 /* smumgr functions */
1785 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1786 /* ucode loading complete flag */
1787 uint32_t fw_flags;
1788};
1789
1790/*
1791 * ASIC specific register table accessible by UMD
1792 */
1793struct amdgpu_allowed_register_entry {
1794 uint32_t reg_offset;
1795 bool untouched;
1796 bool grbm_indexed;
1797};
1798
1799struct amdgpu_cu_info {
1800 uint32_t number; /* total active CU number */
1801 uint32_t ao_cu_mask;
1802 uint32_t bitmap[4][4];
1803};
1804
1805
1806/*
1807 * ASIC specific functions.
1808 */
1809struct amdgpu_asic_funcs {
1810 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001811 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1812 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001813 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1814 u32 sh_num, u32 reg_offset, u32 *value);
1815 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1816 int (*reset)(struct amdgpu_device *adev);
1817 /* wait for mc_idle */
1818 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1819 /* get the reference clock */
1820 u32 (*get_xclk)(struct amdgpu_device *adev);
1821 /* get the gpu clock counter */
1822 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
1823 int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
1824 /* MM block clocks */
1825 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1826 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1827};
1828
1829/*
1830 * IOCTL.
1831 */
1832int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1833 struct drm_file *filp);
1834int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1835 struct drm_file *filp);
1836
1837int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1838 struct drm_file *filp);
1839int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1840 struct drm_file *filp);
1841int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1842 struct drm_file *filp);
1843int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1844 struct drm_file *filp);
1845int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1846 struct drm_file *filp);
1847int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1848 struct drm_file *filp);
1849int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1850int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1851
1852int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1853 struct drm_file *filp);
1854
1855/* VRAM scratch page for HDP bug, default vram page */
1856struct amdgpu_vram_scratch {
1857 struct amdgpu_bo *robj;
1858 volatile uint32_t *ptr;
1859 u64 gpu_addr;
1860};
1861
1862/*
1863 * ACPI
1864 */
1865struct amdgpu_atif_notification_cfg {
1866 bool enabled;
1867 int command_code;
1868};
1869
1870struct amdgpu_atif_notifications {
1871 bool display_switch;
1872 bool expansion_mode_change;
1873 bool thermal_state;
1874 bool forced_power_state;
1875 bool system_power_state;
1876 bool display_conf_change;
1877 bool px_gfx_switch;
1878 bool brightness_change;
1879 bool dgpu_display_event;
1880};
1881
1882struct amdgpu_atif_functions {
1883 bool system_params;
1884 bool sbios_requests;
1885 bool select_active_disp;
1886 bool lid_state;
1887 bool get_tv_standard;
1888 bool set_tv_standard;
1889 bool get_panel_expansion_mode;
1890 bool set_panel_expansion_mode;
1891 bool temperature_change;
1892 bool graphics_device_types;
1893};
1894
1895struct amdgpu_atif {
1896 struct amdgpu_atif_notifications notifications;
1897 struct amdgpu_atif_functions functions;
1898 struct amdgpu_atif_notification_cfg notification_cfg;
1899 struct amdgpu_encoder *encoder_for_bl;
1900};
1901
1902struct amdgpu_atcs_functions {
1903 bool get_ext_state;
1904 bool pcie_perf_req;
1905 bool pcie_dev_rdy;
1906 bool pcie_bus_width;
1907};
1908
1909struct amdgpu_atcs {
1910 struct amdgpu_atcs_functions functions;
1911};
1912
Alex Deucher97b2e202015-04-20 16:51:00 -04001913/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001914 * CGS
1915 */
1916void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1917void amdgpu_cgs_destroy_device(void *cgs_device);
1918
1919
1920/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001921 * Core structure, functions and helpers.
1922 */
1923typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1924typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1925
1926typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1927typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1928
Alex Deucher8faf0e082015-07-28 11:50:31 -04001929struct amdgpu_ip_block_status {
1930 bool valid;
1931 bool sw;
1932 bool hw;
1933};
1934
Alex Deucher97b2e202015-04-20 16:51:00 -04001935struct amdgpu_device {
1936 struct device *dev;
1937 struct drm_device *ddev;
1938 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001939
1940 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001941 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001942 uint32_t family;
1943 uint32_t rev_id;
1944 uint32_t external_rev_id;
1945 unsigned long flags;
1946 int usec_timeout;
1947 const struct amdgpu_asic_funcs *asic_funcs;
1948 bool shutdown;
1949 bool suspend;
1950 bool need_dma32;
1951 bool accel_working;
Alex Deucher97b2e202015-04-20 16:51:00 -04001952 struct work_struct reset_work;
1953 struct notifier_block acpi_nb;
1954 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1955 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1956 unsigned debugfs_count;
1957#if defined(CONFIG_DEBUG_FS)
1958 struct dentry *debugfs_regs;
1959#endif
1960 struct amdgpu_atif atif;
1961 struct amdgpu_atcs atcs;
1962 struct mutex srbm_mutex;
1963 /* GRBM index mutex. Protects concurrent access to GRBM index */
1964 struct mutex grbm_idx_mutex;
1965 struct dev_pm_domain vga_pm_domain;
1966 bool have_disp_power_ref;
1967
1968 /* BIOS */
1969 uint8_t *bios;
1970 bool is_atom_bios;
1971 uint16_t bios_header_start;
1972 struct amdgpu_bo *stollen_vga_memory;
1973 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1974
1975 /* Register/doorbell mmio */
1976 resource_size_t rmmio_base;
1977 resource_size_t rmmio_size;
1978 void __iomem *rmmio;
1979 /* protects concurrent MM_INDEX/DATA based register access */
1980 spinlock_t mmio_idx_lock;
1981 /* protects concurrent SMC based register access */
1982 spinlock_t smc_idx_lock;
1983 amdgpu_rreg_t smc_rreg;
1984 amdgpu_wreg_t smc_wreg;
1985 /* protects concurrent PCIE register access */
1986 spinlock_t pcie_idx_lock;
1987 amdgpu_rreg_t pcie_rreg;
1988 amdgpu_wreg_t pcie_wreg;
1989 /* protects concurrent UVD register access */
1990 spinlock_t uvd_ctx_idx_lock;
1991 amdgpu_rreg_t uvd_ctx_rreg;
1992 amdgpu_wreg_t uvd_ctx_wreg;
1993 /* protects concurrent DIDT register access */
1994 spinlock_t didt_idx_lock;
1995 amdgpu_rreg_t didt_rreg;
1996 amdgpu_wreg_t didt_wreg;
1997 /* protects concurrent ENDPOINT (audio) register access */
1998 spinlock_t audio_endpt_idx_lock;
1999 amdgpu_block_rreg_t audio_endpt_rreg;
2000 amdgpu_block_wreg_t audio_endpt_wreg;
2001 void __iomem *rio_mem;
2002 resource_size_t rio_mem_size;
2003 struct amdgpu_doorbell doorbell;
2004
2005 /* clock/pll info */
2006 struct amdgpu_clock clock;
2007
2008 /* MC */
2009 struct amdgpu_mc mc;
2010 struct amdgpu_gart gart;
2011 struct amdgpu_dummy_page dummy_page;
2012 struct amdgpu_vm_manager vm_manager;
2013
2014 /* memory management */
2015 struct amdgpu_mman mman;
2016 struct amdgpu_gem gem;
2017 struct amdgpu_vram_scratch vram_scratch;
2018 struct amdgpu_wb wb;
2019 atomic64_t vram_usage;
2020 atomic64_t vram_vis_usage;
2021 atomic64_t gtt_usage;
2022 atomic64_t num_bytes_moved;
Marek Olšákd94aed52015-05-05 21:13:49 +02002023 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002024
2025 /* display */
2026 struct amdgpu_mode_info mode_info;
2027 struct work_struct hotplug_work;
2028 struct amdgpu_irq_src crtc_irq;
2029 struct amdgpu_irq_src pageflip_irq;
2030 struct amdgpu_irq_src hpd_irq;
2031
2032 /* rings */
Alex Deucher97b2e202015-04-20 16:51:00 -04002033 unsigned fence_context;
2034 struct mutex ring_lock;
2035 unsigned num_rings;
2036 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2037 bool ib_pool_ready;
2038 struct amdgpu_sa_manager ring_tmp_bo;
2039
2040 /* interrupts */
2041 struct amdgpu_irq irq;
2042
Alex Deucher1f7371b2015-12-02 17:46:21 -05002043 /* powerplay */
2044 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002045 bool pp_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002046
Alex Deucher97b2e202015-04-20 16:51:00 -04002047 /* dpm */
2048 struct amdgpu_pm pm;
2049 u32 cg_flags;
2050 u32 pg_flags;
2051
2052 /* amdgpu smumgr */
2053 struct amdgpu_smumgr smu;
2054
2055 /* gfx */
2056 struct amdgpu_gfx gfx;
2057
2058 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002059 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002060
2061 /* uvd */
2062 bool has_uvd;
2063 struct amdgpu_uvd uvd;
2064
2065 /* vce */
2066 struct amdgpu_vce vce;
2067
2068 /* firmwares */
2069 struct amdgpu_firmware firmware;
2070
2071 /* GDS */
2072 struct amdgpu_gds gds;
2073
2074 const struct amdgpu_ip_block_version *ip_blocks;
2075 int num_ip_blocks;
Alex Deucher8faf0e082015-07-28 11:50:31 -04002076 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002077 struct mutex mn_lock;
2078 DECLARE_HASHTABLE(mn_hash, 7);
2079
2080 /* tracking pinned memory */
2081 u64 vram_pin_size;
2082 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002083
2084 /* amdkfd interface */
2085 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002086
2087 /* kernel conext for IB submission */
Christian König47f38502015-08-04 17:51:05 +02002088 struct amdgpu_ctx kernel_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -04002089};
2090
2091bool amdgpu_device_is_px(struct drm_device *dev);
2092int amdgpu_device_init(struct amdgpu_device *adev,
2093 struct drm_device *ddev,
2094 struct pci_dev *pdev,
2095 uint32_t flags);
2096void amdgpu_device_fini(struct amdgpu_device *adev);
2097int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2098
2099uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2100 bool always_indirect);
2101void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2102 bool always_indirect);
2103u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2104void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2105
2106u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2107void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2108
2109/*
2110 * Cast helper
2111 */
2112extern const struct fence_ops amdgpu_fence_ops;
2113static inline struct amdgpu_fence *to_amdgpu_fence(struct fence *f)
2114{
2115 struct amdgpu_fence *__f = container_of(f, struct amdgpu_fence, base);
2116
2117 if (__f->base.ops == &amdgpu_fence_ops)
2118 return __f;
2119
2120 return NULL;
2121}
2122
2123/*
2124 * Registers read & write functions.
2125 */
2126#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2127#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2128#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2129#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2130#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2131#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2132#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2133#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2134#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2135#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2136#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2137#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2138#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2139#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2140#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2141#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2142#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2143#define WREG32_P(reg, val, mask) \
2144 do { \
2145 uint32_t tmp_ = RREG32(reg); \
2146 tmp_ &= (mask); \
2147 tmp_ |= ((val) & ~(mask)); \
2148 WREG32(reg, tmp_); \
2149 } while (0)
2150#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2151#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2152#define WREG32_PLL_P(reg, val, mask) \
2153 do { \
2154 uint32_t tmp_ = RREG32_PLL(reg); \
2155 tmp_ &= (mask); \
2156 tmp_ |= ((val) & ~(mask)); \
2157 WREG32_PLL(reg, tmp_); \
2158 } while (0)
2159#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2160#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2161#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2162
2163#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2164#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2165
2166#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2167#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2168
2169#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2170 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2171 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2172
2173#define REG_GET_FIELD(value, reg, field) \
2174 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2175
2176/*
2177 * BIOS helpers.
2178 */
2179#define RBIOS8(i) (adev->bios[i])
2180#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2181#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2182
2183/*
2184 * RING helpers.
2185 */
2186static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2187{
2188 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002189 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002190 ring->ring[ring->wptr++] = v;
2191 ring->wptr &= ring->ptr_mask;
2192 ring->count_dw--;
2193 ring->ring_free_dw--;
2194}
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))
2221#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2222#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002223#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 -04002224#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
2225#define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
2226#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)))
2229#define amdgpu_vm_write_pte(adev, ib, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (addr), (count), (incr), (flags)))
2230#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)))
2231#define amdgpu_vm_pad_ib(adev, ib) ((adev)->vm_manager.vm_pte_funcs->pad_ib((ib)))
2232#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2233#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2234#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002235#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2236#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2237#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2238#define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
2239#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_semaphore(r, semaphore, emit_wait) (r)->funcs->emit_semaphore((r), (semaphore), (emit_wait))
2242#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 +02002243#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002244#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2245#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2246#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2247#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2248#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2249#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2250#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2251#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2252#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2253#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2254#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2255#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2256#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2257#define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
2258#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2259#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2260#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))
2261#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2262#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002263#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 +08002264#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 -04002265#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2266#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2267#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2268#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002269#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002270#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002271#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Rex Zhu3af76f22015-10-15 17:23:43 +08002272
2273#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002274 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002275 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002276 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002277
2278#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002279 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002280 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002281 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002282
2283#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002284 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002285 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002286 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002287
2288#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002289 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002290 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002291 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002292
2293#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002294 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002295 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002296 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002297
Rex Zhu1b5708f2015-11-10 18:25:24 -05002298#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002299 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002300 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002301 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002302
2303#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002304 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002305 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002306 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002307
2308
2309#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002310 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002311 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002312 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002313
2314#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002315 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002316 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002317 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002318
2319#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002320 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002321 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002322 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002323
2324#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002325 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002326 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002327 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002328
2329#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002330 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002331
2332#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002333 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002334
Jammy Zhoue61710c2015-11-10 18:31:08 -05002335#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002336 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002337
2338#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2339
2340/* Common functions */
2341int amdgpu_gpu_reset(struct amdgpu_device *adev);
2342void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2343bool amdgpu_card_posted(struct amdgpu_device *adev);
2344void amdgpu_update_display_priority(struct amdgpu_device *adev);
2345bool amdgpu_boot_test_post_card(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002346
Alex Deucher97b2e202015-04-20 16:51:00 -04002347int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2348int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2349 u32 ip_instance, u32 ring,
2350 struct amdgpu_ring **out_ring);
2351void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2352bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
2353int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2354 uint32_t flags);
2355bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
2356bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2357uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2358 struct ttm_mem_reg *mem);
2359void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2360void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2361void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2362void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2363 const u32 *registers,
2364 const u32 array_size);
2365
2366bool amdgpu_device_is_px(struct drm_device *dev);
2367/* atpx handler */
2368#if defined(CONFIG_VGA_SWITCHEROO)
2369void amdgpu_register_atpx_handler(void);
2370void amdgpu_unregister_atpx_handler(void);
2371#else
2372static inline void amdgpu_register_atpx_handler(void) {}
2373static inline void amdgpu_unregister_atpx_handler(void) {}
2374#endif
2375
2376/*
2377 * KMS
2378 */
2379extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2380extern int amdgpu_max_kms_ioctl;
2381
2382int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2383int amdgpu_driver_unload_kms(struct drm_device *dev);
2384void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2385int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2386void amdgpu_driver_postclose_kms(struct drm_device *dev,
2387 struct drm_file *file_priv);
2388void amdgpu_driver_preclose_kms(struct drm_device *dev,
2389 struct drm_file *file_priv);
2390int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2391int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002392u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2393int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2394void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2395int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002396 int *max_error,
2397 struct timeval *vblank_time,
2398 unsigned flags);
2399long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2400 unsigned long arg);
2401
2402/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002403 * functions used by amdgpu_encoder.c
2404 */
2405struct amdgpu_afmt_acr {
2406 u32 clock;
2407
2408 int n_32khz;
2409 int cts_32khz;
2410
2411 int n_44_1khz;
2412 int cts_44_1khz;
2413
2414 int n_48khz;
2415 int cts_48khz;
2416
2417};
2418
2419struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2420
2421/* amdgpu_acpi.c */
2422#if defined(CONFIG_ACPI)
2423int amdgpu_acpi_init(struct amdgpu_device *adev);
2424void amdgpu_acpi_fini(struct amdgpu_device *adev);
2425bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2426int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2427 u8 perf_req, bool advertise);
2428int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2429#else
2430static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2431static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2432#endif
2433
2434struct amdgpu_bo_va_mapping *
2435amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2436 uint64_t addr, struct amdgpu_bo **bo);
2437
2438#include "amdgpu_object.h"
2439
2440#endif