blob: 4021c8a97fc7197489368c3786034a65d3c632c7 [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
137/* CG block flags */
138#define AMDGPU_CG_BLOCK_GFX (1 << 0)
139#define AMDGPU_CG_BLOCK_MC (1 << 1)
140#define AMDGPU_CG_BLOCK_SDMA (1 << 2)
141#define AMDGPU_CG_BLOCK_UVD (1 << 3)
142#define AMDGPU_CG_BLOCK_VCE (1 << 4)
143#define AMDGPU_CG_BLOCK_HDP (1 << 5)
144#define AMDGPU_CG_BLOCK_BIF (1 << 6)
145
146/* CG flags */
147#define AMDGPU_CG_SUPPORT_GFX_MGCG (1 << 0)
148#define AMDGPU_CG_SUPPORT_GFX_MGLS (1 << 1)
149#define AMDGPU_CG_SUPPORT_GFX_CGCG (1 << 2)
150#define AMDGPU_CG_SUPPORT_GFX_CGLS (1 << 3)
151#define AMDGPU_CG_SUPPORT_GFX_CGTS (1 << 4)
152#define AMDGPU_CG_SUPPORT_GFX_CGTS_LS (1 << 5)
153#define AMDGPU_CG_SUPPORT_GFX_CP_LS (1 << 6)
154#define AMDGPU_CG_SUPPORT_GFX_RLC_LS (1 << 7)
155#define AMDGPU_CG_SUPPORT_MC_LS (1 << 8)
156#define AMDGPU_CG_SUPPORT_MC_MGCG (1 << 9)
157#define AMDGPU_CG_SUPPORT_SDMA_LS (1 << 10)
158#define AMDGPU_CG_SUPPORT_SDMA_MGCG (1 << 11)
159#define AMDGPU_CG_SUPPORT_BIF_LS (1 << 12)
160#define AMDGPU_CG_SUPPORT_UVD_MGCG (1 << 13)
161#define AMDGPU_CG_SUPPORT_VCE_MGCG (1 << 14)
162#define AMDGPU_CG_SUPPORT_HDP_LS (1 << 15)
163#define AMDGPU_CG_SUPPORT_HDP_MGCG (1 << 16)
164
165/* PG flags */
166#define AMDGPU_PG_SUPPORT_GFX_PG (1 << 0)
167#define AMDGPU_PG_SUPPORT_GFX_SMG (1 << 1)
168#define AMDGPU_PG_SUPPORT_GFX_DMG (1 << 2)
169#define AMDGPU_PG_SUPPORT_UVD (1 << 3)
170#define AMDGPU_PG_SUPPORT_VCE (1 << 4)
171#define AMDGPU_PG_SUPPORT_CP (1 << 5)
172#define AMDGPU_PG_SUPPORT_GDS (1 << 6)
173#define AMDGPU_PG_SUPPORT_RLC_SMU_HS (1 << 7)
174#define AMDGPU_PG_SUPPORT_SDMA (1 << 8)
175#define AMDGPU_PG_SUPPORT_ACP (1 << 9)
176#define AMDGPU_PG_SUPPORT_SAMU (1 << 10)
177
178/* GFX current status */
179#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
180#define AMDGPU_GFX_SAFE_MODE 0x00000001L
181#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
182#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
183#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
184
185/* max cursor sizes (in pixels) */
186#define CIK_CURSOR_WIDTH 128
187#define CIK_CURSOR_HEIGHT 128
188
189struct amdgpu_device;
190struct amdgpu_fence;
191struct amdgpu_ib;
192struct amdgpu_vm;
193struct amdgpu_ring;
194struct amdgpu_semaphore;
195struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800196struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400197struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400198struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400199
200enum amdgpu_cp_irq {
201 AMDGPU_CP_IRQ_GFX_EOP = 0,
202 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
203 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
204 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
205 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
206 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
207 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
208 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
209 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
210
211 AMDGPU_CP_IRQ_LAST
212};
213
214enum amdgpu_sdma_irq {
215 AMDGPU_SDMA_IRQ_TRAP0 = 0,
216 AMDGPU_SDMA_IRQ_TRAP1,
217
218 AMDGPU_SDMA_IRQ_LAST
219};
220
221enum amdgpu_thermal_irq {
222 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
223 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
224
225 AMDGPU_THERMAL_IRQ_LAST
226};
227
Alex Deucher97b2e202015-04-20 16:51:00 -0400228int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400229 enum amd_ip_block_type block_type,
230 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400231int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400232 enum amd_ip_block_type block_type,
233 enum amd_powergating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400234
235struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400236 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400237 u32 major;
238 u32 minor;
239 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400240 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400241};
242
243int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400244 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400245 u32 major, u32 minor);
246
247const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
248 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400249 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400250
251/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
252struct amdgpu_buffer_funcs {
253 /* maximum bytes in a single operation */
254 uint32_t copy_max_bytes;
255
256 /* number of dw to reserve per operation */
257 unsigned copy_num_dw;
258
259 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800260 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400261 /* src addr in bytes */
262 uint64_t src_offset,
263 /* dst addr in bytes */
264 uint64_t dst_offset,
265 /* number of byte to transfer */
266 uint32_t byte_count);
267
268 /* maximum bytes in a single operation */
269 uint32_t fill_max_bytes;
270
271 /* number of dw to reserve per operation */
272 unsigned fill_num_dw;
273
274 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800275 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400276 /* value to write to memory */
277 uint32_t src_data,
278 /* dst addr in bytes */
279 uint64_t dst_offset,
280 /* number of byte to fill */
281 uint32_t byte_count);
282};
283
284/* provided by hw blocks that can write ptes, e.g., sdma */
285struct amdgpu_vm_pte_funcs {
286 /* copy pte entries from GART */
287 void (*copy_pte)(struct amdgpu_ib *ib,
288 uint64_t pe, uint64_t src,
289 unsigned count);
290 /* write pte one entry at a time with addr mapping */
291 void (*write_pte)(struct amdgpu_ib *ib,
292 uint64_t pe,
293 uint64_t addr, unsigned count,
294 uint32_t incr, uint32_t flags);
295 /* for linear pte/pde updates without addr mapping */
296 void (*set_pte_pde)(struct amdgpu_ib *ib,
297 uint64_t pe,
298 uint64_t addr, unsigned count,
299 uint32_t incr, uint32_t flags);
300 /* pad the indirect buffer to the necessary number of dw */
301 void (*pad_ib)(struct amdgpu_ib *ib);
302};
303
304/* provided by the gmc block */
305struct amdgpu_gart_funcs {
306 /* flush the vm tlb via mmio */
307 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
308 uint32_t vmid);
309 /* write pte/pde updates using the cpu */
310 int (*set_pte_pde)(struct amdgpu_device *adev,
311 void *cpu_pt_addr, /* cpu addr of page table */
312 uint32_t gpu_page_idx, /* pte/pde to update */
313 uint64_t addr, /* addr to write into pte/pde */
314 uint32_t flags); /* access flags */
315};
316
317/* provided by the ih block */
318struct amdgpu_ih_funcs {
319 /* ring read/write ptr handling, called from interrupt context */
320 u32 (*get_wptr)(struct amdgpu_device *adev);
321 void (*decode_iv)(struct amdgpu_device *adev,
322 struct amdgpu_iv_entry *entry);
323 void (*set_rptr)(struct amdgpu_device *adev);
324};
325
326/* provided by hw blocks that expose a ring buffer for commands */
327struct amdgpu_ring_funcs {
328 /* ring read/write ptr handling */
329 u32 (*get_rptr)(struct amdgpu_ring *ring);
330 u32 (*get_wptr)(struct amdgpu_ring *ring);
331 void (*set_wptr)(struct amdgpu_ring *ring);
332 /* validating and patching of IBs */
333 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
334 /* command emit functions */
335 void (*emit_ib)(struct amdgpu_ring *ring,
336 struct amdgpu_ib *ib);
337 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800338 uint64_t seq, unsigned flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400339 bool (*emit_semaphore)(struct amdgpu_ring *ring,
340 struct amdgpu_semaphore *semaphore,
341 bool emit_wait);
342 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
343 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200344 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400345 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
346 uint32_t gds_base, uint32_t gds_size,
347 uint32_t gws_base, uint32_t gws_size,
348 uint32_t oa_base, uint32_t oa_size);
349 /* testing functions */
350 int (*test_ring)(struct amdgpu_ring *ring);
351 int (*test_ib)(struct amdgpu_ring *ring);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800352 /* insert NOP packets */
353 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Alex Deucher97b2e202015-04-20 16:51:00 -0400354};
355
356/*
357 * BIOS.
358 */
359bool amdgpu_get_bios(struct amdgpu_device *adev);
360bool amdgpu_read_bios(struct amdgpu_device *adev);
361
362/*
363 * Dummy page
364 */
365struct amdgpu_dummy_page {
366 struct page *page;
367 dma_addr_t addr;
368};
369int amdgpu_dummy_page_init(struct amdgpu_device *adev);
370void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
371
372
373/*
374 * Clocks
375 */
376
377#define AMDGPU_MAX_PPLL 3
378
379struct amdgpu_clock {
380 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
381 struct amdgpu_pll spll;
382 struct amdgpu_pll mpll;
383 /* 10 Khz units */
384 uint32_t default_mclk;
385 uint32_t default_sclk;
386 uint32_t default_dispclk;
387 uint32_t current_dispclk;
388 uint32_t dp_extclk;
389 uint32_t max_pixel_clock;
390};
391
392/*
393 * Fences.
394 */
395struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400396 uint64_t gpu_addr;
397 volatile uint32_t *cpu_addr;
398 /* sync_seq is protected by ring emission lock */
399 uint64_t sync_seq[AMDGPU_MAX_RINGS];
400 atomic64_t last_seq;
401 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400402 struct amdgpu_irq_src *irq_src;
403 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100404 struct timer_list fallback_timer;
monk.liu7f06c232015-07-30 18:28:12 +0800405 wait_queue_head_t fence_queue;
Alex Deucher97b2e202015-04-20 16:51:00 -0400406};
407
408/* some special values for the owner field */
409#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
410#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400411
Chunming Zhou890ee232015-06-01 14:35:03 +0800412#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
413#define AMDGPU_FENCE_FLAG_INT (1 << 1)
414
Alex Deucher97b2e202015-04-20 16:51:00 -0400415struct amdgpu_fence {
416 struct fence base;
Chunming Zhou4cef9262015-08-05 19:52:14 +0800417
Alex Deucher97b2e202015-04-20 16:51:00 -0400418 /* RB, DMA, etc. */
419 struct amdgpu_ring *ring;
420 uint64_t seq;
421
422 /* filp or special value for fence creator */
423 void *owner;
424
425 wait_queue_t fence_wake;
426};
427
428struct amdgpu_user_fence {
429 /* write-back bo */
430 struct amdgpu_bo *bo;
431 /* write-back address offset to bo start */
432 uint32_t offset;
433};
434
435int amdgpu_fence_driver_init(struct amdgpu_device *adev);
436void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
437void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
438
Christian König4f839a22015-09-08 20:22:31 +0200439int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400440int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
441 struct amdgpu_irq_src *irq_src,
442 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400443void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
444void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400445int amdgpu_fence_emit(struct amdgpu_ring *ring, void *owner,
446 struct amdgpu_fence **fence);
447void amdgpu_fence_process(struct amdgpu_ring *ring);
448int amdgpu_fence_wait_next(struct amdgpu_ring *ring);
449int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
450unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
451
Alex Deucher97b2e202015-04-20 16:51:00 -0400452bool amdgpu_fence_need_sync(struct amdgpu_fence *fence,
453 struct amdgpu_ring *ring);
454void amdgpu_fence_note_sync(struct amdgpu_fence *fence,
455 struct amdgpu_ring *ring);
456
Alex Deucher97b2e202015-04-20 16:51:00 -0400457/*
458 * TTM.
459 */
460struct amdgpu_mman {
461 struct ttm_bo_global_ref bo_global_ref;
462 struct drm_global_reference mem_global_ref;
463 struct ttm_bo_device bdev;
464 bool mem_global_referenced;
465 bool initialized;
466
467#if defined(CONFIG_DEBUG_FS)
468 struct dentry *vram;
469 struct dentry *gtt;
470#endif
471
472 /* buffer handling */
473 const struct amdgpu_buffer_funcs *buffer_funcs;
474 struct amdgpu_ring *buffer_funcs_ring;
475};
476
477int amdgpu_copy_buffer(struct amdgpu_ring *ring,
478 uint64_t src_offset,
479 uint64_t dst_offset,
480 uint32_t byte_count,
481 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800482 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400483int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
484
485struct amdgpu_bo_list_entry {
486 struct amdgpu_bo *robj;
487 struct ttm_validate_buffer tv;
488 struct amdgpu_bo_va *bo_va;
489 unsigned prefered_domains;
490 unsigned allowed_domains;
491 uint32_t priority;
492};
493
494struct amdgpu_bo_va_mapping {
495 struct list_head list;
496 struct interval_tree_node it;
497 uint64_t offset;
498 uint32_t flags;
499};
500
501/* bo virtual addresses in a specific vm */
502struct amdgpu_bo_va {
Chunming Zhou69b576a2015-11-18 11:17:39 +0800503 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -0400504 /* protected by bo being reserved */
505 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800506 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400507 unsigned ref_count;
508
Christian König7fc11952015-07-30 11:53:42 +0200509 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400510 struct list_head vm_status;
511
Christian König7fc11952015-07-30 11:53:42 +0200512 /* mappings for this bo_va */
513 struct list_head invalids;
514 struct list_head valids;
515
Alex Deucher97b2e202015-04-20 16:51:00 -0400516 /* constant after initialization */
517 struct amdgpu_vm *vm;
518 struct amdgpu_bo *bo;
519};
520
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800521#define AMDGPU_GEM_DOMAIN_MAX 0x3
522
Alex Deucher97b2e202015-04-20 16:51:00 -0400523struct amdgpu_bo {
524 /* Protected by gem.mutex */
525 struct list_head list;
526 /* Protected by tbo.reserved */
527 u32 initial_domain;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800528 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400529 struct ttm_placement placement;
530 struct ttm_buffer_object tbo;
531 struct ttm_bo_kmap_obj kmap;
532 u64 flags;
533 unsigned pin_count;
534 void *kptr;
535 u64 tiling_flags;
536 u64 metadata_flags;
537 void *metadata;
538 u32 metadata_size;
539 /* list of all virtual address to which this bo
540 * is associated to
541 */
542 struct list_head va;
543 /* Constant after initialization */
544 struct amdgpu_device *adev;
545 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100546 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400547
548 struct ttm_bo_kmap_obj dma_buf_vmap;
549 pid_t pid;
550 struct amdgpu_mn *mn;
551 struct list_head mn_list;
552};
553#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
554
555void amdgpu_gem_object_free(struct drm_gem_object *obj);
556int amdgpu_gem_object_open(struct drm_gem_object *obj,
557 struct drm_file *file_priv);
558void amdgpu_gem_object_close(struct drm_gem_object *obj,
559 struct drm_file *file_priv);
560unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
561struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
562struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
563 struct dma_buf_attachment *attach,
564 struct sg_table *sg);
565struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
566 struct drm_gem_object *gobj,
567 int flags);
568int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
569void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
570struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
571void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
572void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
573int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
574
575/* sub-allocation manager, it has to be protected by another lock.
576 * By conception this is an helper for other part of the driver
577 * like the indirect buffer or semaphore, which both have their
578 * locking.
579 *
580 * Principe is simple, we keep a list of sub allocation in offset
581 * order (first entry has offset == 0, last entry has the highest
582 * offset).
583 *
584 * When allocating new object we first check if there is room at
585 * the end total_size - (last_object_offset + last_object_size) >=
586 * alloc_size. If so we allocate new object there.
587 *
588 * When there is not enough room at the end, we start waiting for
589 * each sub object until we reach object_offset+object_size >=
590 * alloc_size, this object then become the sub object we return.
591 *
592 * Alignment can't be bigger than page size.
593 *
594 * Hole are not considered for allocation to keep things simple.
595 * Assumption is that there won't be hole (all object on same
596 * alignment).
597 */
598struct amdgpu_sa_manager {
599 wait_queue_head_t wq;
600 struct amdgpu_bo *bo;
601 struct list_head *hole;
602 struct list_head flist[AMDGPU_MAX_RINGS];
603 struct list_head olist;
604 unsigned size;
605 uint64_t gpu_addr;
606 void *cpu_ptr;
607 uint32_t domain;
608 uint32_t align;
609};
610
611struct amdgpu_sa_bo;
612
613/* sub-allocation buffer */
614struct amdgpu_sa_bo {
615 struct list_head olist;
616 struct list_head flist;
617 struct amdgpu_sa_manager *manager;
618 unsigned soffset;
619 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800620 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400621};
622
623/*
624 * GEM objects.
625 */
626struct amdgpu_gem {
627 struct mutex mutex;
628 struct list_head objects;
629};
630
631int amdgpu_gem_init(struct amdgpu_device *adev);
632void amdgpu_gem_fini(struct amdgpu_device *adev);
633int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
634 int alignment, u32 initial_domain,
635 u64 flags, bool kernel,
636 struct drm_gem_object **obj);
637
638int amdgpu_mode_dumb_create(struct drm_file *file_priv,
639 struct drm_device *dev,
640 struct drm_mode_create_dumb *args);
641int amdgpu_mode_dumb_mmap(struct drm_file *filp,
642 struct drm_device *dev,
643 uint32_t handle, uint64_t *offset_p);
644
645/*
646 * Semaphores.
647 */
648struct amdgpu_semaphore {
649 struct amdgpu_sa_bo *sa_bo;
650 signed waiters;
651 uint64_t gpu_addr;
652};
653
654int amdgpu_semaphore_create(struct amdgpu_device *adev,
655 struct amdgpu_semaphore **semaphore);
656bool amdgpu_semaphore_emit_signal(struct amdgpu_ring *ring,
657 struct amdgpu_semaphore *semaphore);
658bool amdgpu_semaphore_emit_wait(struct amdgpu_ring *ring,
659 struct amdgpu_semaphore *semaphore);
660void amdgpu_semaphore_free(struct amdgpu_device *adev,
661 struct amdgpu_semaphore **semaphore,
Chunming Zhou4ce98912015-08-19 16:41:19 +0800662 struct fence *fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400663
664/*
665 * Synchronization
666 */
667struct amdgpu_sync {
668 struct amdgpu_semaphore *semaphores[AMDGPU_NUM_SYNCS];
Christian König16545c32015-10-22 15:04:50 +0200669 struct fence *sync_to[AMDGPU_MAX_RINGS];
Christian Königf91b3a62015-08-20 14:47:40 +0800670 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800671 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400672};
673
674void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200675int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
676 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400677int amdgpu_sync_resv(struct amdgpu_device *adev,
678 struct amdgpu_sync *sync,
679 struct reservation_object *resv,
680 void *owner);
681int amdgpu_sync_rings(struct amdgpu_sync *sync,
682 struct amdgpu_ring *ring);
Christian Könige61235d2015-08-25 11:05:36 +0200683struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian Königf91b3a62015-08-20 14:47:40 +0800684int amdgpu_sync_wait(struct amdgpu_sync *sync);
Alex Deucher97b2e202015-04-20 16:51:00 -0400685void amdgpu_sync_free(struct amdgpu_device *adev, struct amdgpu_sync *sync,
Chunming Zhou4ce98912015-08-19 16:41:19 +0800686 struct fence *fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400687
688/*
689 * GART structures, functions & helpers
690 */
691struct amdgpu_mc;
692
693#define AMDGPU_GPU_PAGE_SIZE 4096
694#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
695#define AMDGPU_GPU_PAGE_SHIFT 12
696#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
697
698struct amdgpu_gart {
699 dma_addr_t table_addr;
700 struct amdgpu_bo *robj;
701 void *ptr;
702 unsigned num_gpu_pages;
703 unsigned num_cpu_pages;
704 unsigned table_size;
705 struct page **pages;
706 dma_addr_t *pages_addr;
707 bool ready;
708 const struct amdgpu_gart_funcs *gart_funcs;
709};
710
711int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
712void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
713int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
714void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
715int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
716void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
717int amdgpu_gart_init(struct amdgpu_device *adev);
718void amdgpu_gart_fini(struct amdgpu_device *adev);
719void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
720 int pages);
721int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
722 int pages, struct page **pagelist,
723 dma_addr_t *dma_addr, uint32_t flags);
724
725/*
726 * GPU MC structures, functions & helpers
727 */
728struct amdgpu_mc {
729 resource_size_t aper_size;
730 resource_size_t aper_base;
731 resource_size_t agp_base;
732 /* for some chips with <= 32MB we need to lie
733 * about vram size near mc fb location */
734 u64 mc_vram_size;
735 u64 visible_vram_size;
736 u64 gtt_size;
737 u64 gtt_start;
738 u64 gtt_end;
739 u64 vram_start;
740 u64 vram_end;
741 unsigned vram_width;
742 u64 real_vram_size;
743 int vram_mtrr;
744 u64 gtt_base_align;
745 u64 mc_mask;
746 const struct firmware *fw; /* MC firmware */
747 uint32_t fw_version;
748 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800749 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400750};
751
752/*
753 * GPU doorbell structures, functions & helpers
754 */
755typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
756{
757 AMDGPU_DOORBELL_KIQ = 0x000,
758 AMDGPU_DOORBELL_HIQ = 0x001,
759 AMDGPU_DOORBELL_DIQ = 0x002,
760 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
761 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
762 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
763 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
764 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
765 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
766 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
767 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
768 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
769 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
770 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
771 AMDGPU_DOORBELL_IH = 0x1E8,
772 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
773 AMDGPU_DOORBELL_INVALID = 0xFFFF
774} AMDGPU_DOORBELL_ASSIGNMENT;
775
776struct amdgpu_doorbell {
777 /* doorbell mmio */
778 resource_size_t base;
779 resource_size_t size;
780 u32 __iomem *ptr;
781 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
782};
783
784void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
785 phys_addr_t *aperture_base,
786 size_t *aperture_size,
787 size_t *start_offset);
788
789/*
790 * IRQS.
791 */
792
793struct amdgpu_flip_work {
794 struct work_struct flip_work;
795 struct work_struct unpin_work;
796 struct amdgpu_device *adev;
797 int crtc_id;
798 uint64_t base;
799 struct drm_pending_vblank_event *event;
800 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200801 struct fence *excl;
802 unsigned shared_count;
803 struct fence **shared;
Alex Deucher97b2e202015-04-20 16:51:00 -0400804};
805
806
807/*
808 * CP & rings.
809 */
810
811struct amdgpu_ib {
812 struct amdgpu_sa_bo *sa_bo;
813 uint32_t length_dw;
814 uint64_t gpu_addr;
815 uint32_t *ptr;
816 struct amdgpu_ring *ring;
817 struct amdgpu_fence *fence;
818 struct amdgpu_user_fence *user;
819 struct amdgpu_vm *vm;
Christian König3cb485f2015-05-11 15:34:59 +0200820 struct amdgpu_ctx *ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400821 struct amdgpu_sync sync;
Alex Deucher97b2e202015-04-20 16:51:00 -0400822 uint32_t gds_base, gds_size;
823 uint32_t gws_base, gws_size;
824 uint32_t oa_base, oa_size;
Jammy Zhoude807f82015-05-11 23:41:41 +0800825 uint32_t flags;
Christian König5430a3f2015-07-21 18:02:21 +0200826 /* resulting sequence number */
827 uint64_t sequence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400828};
829
830enum amdgpu_ring_type {
831 AMDGPU_RING_TYPE_GFX,
832 AMDGPU_RING_TYPE_COMPUTE,
833 AMDGPU_RING_TYPE_SDMA,
834 AMDGPU_RING_TYPE_UVD,
835 AMDGPU_RING_TYPE_VCE
836};
837
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800838extern struct amd_sched_backend_ops amdgpu_sched_ops;
839
Chunming Zhou3c704e92015-07-29 10:33:14 +0800840int amdgpu_sched_ib_submit_kernel_helper(struct amdgpu_device *adev,
841 struct amdgpu_ring *ring,
842 struct amdgpu_ib *ibs,
843 unsigned num_ibs,
Chunming Zhoubb977d32015-08-18 15:16:40 +0800844 int (*free_job)(struct amdgpu_job *),
Chunming Zhou17635522015-08-03 11:43:19 +0800845 void *owner,
846 struct fence **fence);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800847
Alex Deucher97b2e202015-04-20 16:51:00 -0400848struct amdgpu_ring {
849 struct amdgpu_device *adev;
850 const struct amdgpu_ring_funcs *funcs;
851 struct amdgpu_fence_driver fence_drv;
Christian König4f839a22015-09-08 20:22:31 +0200852 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400853
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800854 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400855 struct mutex *ring_lock;
856 struct amdgpu_bo *ring_obj;
857 volatile uint32_t *ring;
858 unsigned rptr_offs;
859 u64 next_rptr_gpu_addr;
860 volatile u32 *next_rptr_cpu_addr;
861 unsigned wptr;
862 unsigned wptr_old;
863 unsigned ring_size;
864 unsigned ring_free_dw;
865 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400866 uint64_t gpu_addr;
867 uint32_t align_mask;
868 uint32_t ptr_mask;
869 bool ready;
870 u32 nop;
871 u32 idx;
872 u64 last_semaphore_signal_addr;
873 u64 last_semaphore_wait_addr;
874 u32 me;
875 u32 pipe;
876 u32 queue;
877 struct amdgpu_bo *mqd_obj;
878 u32 doorbell_index;
879 bool use_doorbell;
880 unsigned wptr_offs;
881 unsigned next_rptr_offs;
882 unsigned fence_offs;
Christian König3cb485f2015-05-11 15:34:59 +0200883 struct amdgpu_ctx *current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400884 enum amdgpu_ring_type type;
885 char name[16];
Chunming Zhou4274f5d2015-07-21 16:04:39 +0800886 bool is_pte_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400887};
888
889/*
890 * VM
891 */
892
893/* maximum number of VMIDs */
894#define AMDGPU_NUM_VM 16
895
896/* number of entries in page table */
897#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
898
899/* PTBs (Page Table Blocks) need to be aligned to 32K */
900#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
901#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
902#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
903
904#define AMDGPU_PTE_VALID (1 << 0)
905#define AMDGPU_PTE_SYSTEM (1 << 1)
906#define AMDGPU_PTE_SNOOPED (1 << 2)
907
908/* VI only */
909#define AMDGPU_PTE_EXECUTABLE (1 << 4)
910
911#define AMDGPU_PTE_READABLE (1 << 5)
912#define AMDGPU_PTE_WRITEABLE (1 << 6)
913
914/* PTE (Page Table Entry) fragment field for different page sizes */
915#define AMDGPU_PTE_FRAG_4KB (0 << 7)
916#define AMDGPU_PTE_FRAG_64KB (4 << 7)
917#define AMDGPU_LOG2_PAGES_PER_FRAG 4
918
Christian Königd9c13152015-09-28 12:31:26 +0200919/* How to programm VM fault handling */
920#define AMDGPU_VM_FAULT_STOP_NEVER 0
921#define AMDGPU_VM_FAULT_STOP_FIRST 1
922#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
923
Alex Deucher97b2e202015-04-20 16:51:00 -0400924struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100925 struct amdgpu_bo_list_entry entry;
926 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400927};
928
929struct amdgpu_vm_id {
930 unsigned id;
931 uint64_t pd_gpu_addr;
932 /* last flushed PD/PT update */
Chunming Zhou3c623382015-08-20 18:33:59 +0800933 struct fence *flushed_updates;
Alex Deucher97b2e202015-04-20 16:51:00 -0400934};
935
936struct amdgpu_vm {
Alex Deucher97b2e202015-04-20 16:51:00 -0400937 struct rb_root va;
938
Christian König7fc11952015-07-30 11:53:42 +0200939 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400940 spinlock_t status_lock;
941
942 /* BOs moved, but not yet updated in the PT */
943 struct list_head invalidated;
944
Christian König7fc11952015-07-30 11:53:42 +0200945 /* BOs cleared in the PT because of a move */
946 struct list_head cleared;
947
948 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400949 struct list_head freed;
950
951 /* contains the page directory */
952 struct amdgpu_bo *page_directory;
953 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200954 struct fence *page_directory_fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400955
956 /* array of page tables, one for each page directory entry */
957 struct amdgpu_vm_pt *page_tables;
958
959 /* for id and flush management per ring */
960 struct amdgpu_vm_id ids[AMDGPU_MAX_RINGS];
Chunming Zhouc25867d2015-11-13 13:32:01 +0800961 /* for interval tree */
962 spinlock_t it_lock;
jimqu81d75a32015-12-04 17:17:00 +0800963 /* protecting freed */
964 spinlock_t freed_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400965};
966
967struct amdgpu_vm_manager {
Christian König1c16c0a2015-11-14 21:31:40 +0100968 struct {
969 struct fence *active;
970 atomic_long_t owner;
971 } ids[AMDGPU_NUM_VM];
972
Christian König8b4fb002015-11-15 16:04:16 +0100973 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400974 /* number of VMIDs */
Christian König8b4fb002015-11-15 16:04:16 +0100975 unsigned nvm;
Alex Deucher97b2e202015-04-20 16:51:00 -0400976 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100977 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400978 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100979 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400980 /* vm pte handling */
981 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
982 struct amdgpu_ring *vm_pte_funcs_ring;
983};
984
Christian Königea89f8c2015-11-15 20:52:06 +0100985void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100986int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
987void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100988void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
989 struct list_head *validated,
990 struct amdgpu_bo_list_entry *entry);
Christian Königee1782c2015-12-11 21:01:23 +0100991void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100992void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
993 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100994int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
995 struct amdgpu_sync *sync);
996void amdgpu_vm_flush(struct amdgpu_ring *ring,
997 struct amdgpu_vm *vm,
998 struct fence *updates);
999void amdgpu_vm_fence(struct amdgpu_device *adev,
1000 struct amdgpu_vm *vm,
1001 struct fence *fence);
1002uint64_t amdgpu_vm_map_gart(struct amdgpu_device *adev, uint64_t addr);
1003int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
1004 struct amdgpu_vm *vm);
1005int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
1006 struct amdgpu_vm *vm);
1007int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
1008 struct amdgpu_sync *sync);
1009int amdgpu_vm_bo_update(struct amdgpu_device *adev,
1010 struct amdgpu_bo_va *bo_va,
1011 struct ttm_mem_reg *mem);
1012void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
1013 struct amdgpu_bo *bo);
1014struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
1015 struct amdgpu_bo *bo);
1016struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
1017 struct amdgpu_vm *vm,
1018 struct amdgpu_bo *bo);
1019int amdgpu_vm_bo_map(struct amdgpu_device *adev,
1020 struct amdgpu_bo_va *bo_va,
1021 uint64_t addr, uint64_t offset,
1022 uint64_t size, uint32_t flags);
1023int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
1024 struct amdgpu_bo_va *bo_va,
1025 uint64_t addr);
1026void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
1027 struct amdgpu_bo_va *bo_va);
1028int amdgpu_vm_free_job(struct amdgpu_job *job);
1029
Alex Deucher97b2e202015-04-20 16:51:00 -04001030/*
1031 * context related structures
1032 */
1033
Christian König21c16bf2015-07-07 17:24:49 +02001034struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +02001035 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +08001036 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +02001037 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +02001038};
1039
Alex Deucher97b2e202015-04-20 16:51:00 -04001040struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -04001041 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +08001042 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -04001043 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +02001044 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +08001045 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +02001046 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001047};
1048
1049struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -04001050 struct amdgpu_device *adev;
1051 struct mutex lock;
1052 /* protected by lock */
1053 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001054};
1055
Chunming Zhoud033a6d2015-11-05 15:23:09 +08001056int amdgpu_ctx_init(struct amdgpu_device *adev, enum amd_sched_priority pri,
Christian König47f38502015-08-04 17:51:05 +02001057 struct amdgpu_ctx *ctx);
1058void amdgpu_ctx_fini(struct amdgpu_ctx *ctx);
Alex Deucher0b492a42015-08-16 22:48:26 -04001059
Alex Deucher0b492a42015-08-16 22:48:26 -04001060struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
1061int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
1062
Christian König21c16bf2015-07-07 17:24:49 +02001063uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +02001064 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +02001065struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
1066 struct amdgpu_ring *ring, uint64_t seq);
1067
Alex Deucher0b492a42015-08-16 22:48:26 -04001068int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1069 struct drm_file *filp);
1070
Christian Königefd4ccb2015-08-04 16:20:31 +02001071void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1072void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -04001073
Alex Deucher97b2e202015-04-20 16:51:00 -04001074/*
1075 * file private structure
1076 */
1077
1078struct amdgpu_fpriv {
1079 struct amdgpu_vm vm;
1080 struct mutex bo_list_lock;
1081 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001082 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001083};
1084
1085/*
1086 * residency list
1087 */
1088
1089struct amdgpu_bo_list {
1090 struct mutex lock;
1091 struct amdgpu_bo *gds_obj;
1092 struct amdgpu_bo *gws_obj;
1093 struct amdgpu_bo *oa_obj;
1094 bool has_userptr;
1095 unsigned num_entries;
1096 struct amdgpu_bo_list_entry *array;
1097};
1098
1099struct amdgpu_bo_list *
1100amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
1101void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1102void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1103
1104/*
1105 * GFX stuff
1106 */
1107#include "clearstate_defs.h"
1108
1109struct amdgpu_rlc {
1110 /* for power gating */
1111 struct amdgpu_bo *save_restore_obj;
1112 uint64_t save_restore_gpu_addr;
1113 volatile uint32_t *sr_ptr;
1114 const u32 *reg_list;
1115 u32 reg_list_size;
1116 /* for clear state */
1117 struct amdgpu_bo *clear_state_obj;
1118 uint64_t clear_state_gpu_addr;
1119 volatile uint32_t *cs_ptr;
1120 const struct cs_section_def *cs_data;
1121 u32 clear_state_size;
1122 /* for cp tables */
1123 struct amdgpu_bo *cp_table_obj;
1124 uint64_t cp_table_gpu_addr;
1125 volatile uint32_t *cp_table_ptr;
1126 u32 cp_table_size;
1127};
1128
1129struct amdgpu_mec {
1130 struct amdgpu_bo *hpd_eop_obj;
1131 u64 hpd_eop_gpu_addr;
1132 u32 num_pipe;
1133 u32 num_mec;
1134 u32 num_queue;
1135};
1136
1137/*
1138 * GPU scratch registers structures, functions & helpers
1139 */
1140struct amdgpu_scratch {
1141 unsigned num_reg;
1142 uint32_t reg_base;
1143 bool free[32];
1144 uint32_t reg[32];
1145};
1146
1147/*
1148 * GFX configurations
1149 */
1150struct amdgpu_gca_config {
1151 unsigned max_shader_engines;
1152 unsigned max_tile_pipes;
1153 unsigned max_cu_per_sh;
1154 unsigned max_sh_per_se;
1155 unsigned max_backends_per_se;
1156 unsigned max_texture_channel_caches;
1157 unsigned max_gprs;
1158 unsigned max_gs_threads;
1159 unsigned max_hw_contexts;
1160 unsigned sc_prim_fifo_size_frontend;
1161 unsigned sc_prim_fifo_size_backend;
1162 unsigned sc_hiz_tile_fifo_size;
1163 unsigned sc_earlyz_tile_fifo_size;
1164
1165 unsigned num_tile_pipes;
1166 unsigned backend_enable_mask;
1167 unsigned mem_max_burst_length_bytes;
1168 unsigned mem_row_size_in_kb;
1169 unsigned shader_engine_tile_size;
1170 unsigned num_gpus;
1171 unsigned multi_gpu_tile_size;
1172 unsigned mc_arb_ramcfg;
1173 unsigned gb_addr_config;
1174
1175 uint32_t tile_mode_array[32];
1176 uint32_t macrotile_mode_array[16];
1177};
1178
1179struct amdgpu_gfx {
1180 struct mutex gpu_clock_mutex;
1181 struct amdgpu_gca_config config;
1182 struct amdgpu_rlc rlc;
1183 struct amdgpu_mec mec;
1184 struct amdgpu_scratch scratch;
1185 const struct firmware *me_fw; /* ME firmware */
1186 uint32_t me_fw_version;
1187 const struct firmware *pfp_fw; /* PFP firmware */
1188 uint32_t pfp_fw_version;
1189 const struct firmware *ce_fw; /* CE firmware */
1190 uint32_t ce_fw_version;
1191 const struct firmware *rlc_fw; /* RLC firmware */
1192 uint32_t rlc_fw_version;
1193 const struct firmware *mec_fw; /* MEC firmware */
1194 uint32_t mec_fw_version;
1195 const struct firmware *mec2_fw; /* MEC2 firmware */
1196 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001197 uint32_t me_feature_version;
1198 uint32_t ce_feature_version;
1199 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001200 uint32_t rlc_feature_version;
1201 uint32_t mec_feature_version;
1202 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001203 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1204 unsigned num_gfx_rings;
1205 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1206 unsigned num_compute_rings;
1207 struct amdgpu_irq_src eop_irq;
1208 struct amdgpu_irq_src priv_reg_irq;
1209 struct amdgpu_irq_src priv_inst_irq;
1210 /* gfx status */
1211 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001212 /* ce ram size*/
1213 unsigned ce_ram_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001214};
1215
1216int amdgpu_ib_get(struct amdgpu_ring *ring, struct amdgpu_vm *vm,
1217 unsigned size, struct amdgpu_ib *ib);
1218void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib);
1219int amdgpu_ib_schedule(struct amdgpu_device *adev, unsigned num_ibs,
1220 struct amdgpu_ib *ib, void *owner);
1221int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1222void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1223int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
1224/* Ring access between begin & end cannot sleep */
1225void amdgpu_ring_free_size(struct amdgpu_ring *ring);
1226int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
1227int amdgpu_ring_lock(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001228void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Alex Deucher97b2e202015-04-20 16:51:00 -04001229void amdgpu_ring_commit(struct amdgpu_ring *ring);
1230void amdgpu_ring_unlock_commit(struct amdgpu_ring *ring);
1231void amdgpu_ring_undo(struct amdgpu_ring *ring);
1232void amdgpu_ring_unlock_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001233unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1234 uint32_t **data);
1235int amdgpu_ring_restore(struct amdgpu_ring *ring,
1236 unsigned size, uint32_t *data);
1237int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1238 unsigned ring_size, u32 nop, u32 align_mask,
1239 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1240 enum amdgpu_ring_type ring_type);
1241void amdgpu_ring_fini(struct amdgpu_ring *ring);
Christian König8120b612015-10-22 11:29:33 +02001242struct amdgpu_ring *amdgpu_ring_from_fence(struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001243
1244/*
1245 * CS.
1246 */
1247struct amdgpu_cs_chunk {
1248 uint32_t chunk_id;
1249 uint32_t length_dw;
1250 uint32_t *kdata;
1251 void __user *user_ptr;
1252};
1253
1254struct amdgpu_cs_parser {
1255 struct amdgpu_device *adev;
1256 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001257 struct amdgpu_ctx *ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -04001258 struct amdgpu_bo_list *bo_list;
1259 /* chunks */
1260 unsigned nchunks;
1261 struct amdgpu_cs_chunk *chunks;
1262 /* relocations */
Christian König56467eb2015-12-11 15:16:32 +01001263 struct amdgpu_bo_list_entry vm_pd;
Alex Deucher97b2e202015-04-20 16:51:00 -04001264 struct list_head validated;
Christian König984810f2015-11-14 21:05:35 +01001265 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -04001266
1267 struct amdgpu_ib *ibs;
1268 uint32_t num_ibs;
1269
1270 struct ww_acquire_ctx ticket;
1271
1272 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001273 struct amdgpu_user_fence uf;
1274 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001275};
1276
Chunming Zhoubb977d32015-08-18 15:16:40 +08001277struct amdgpu_job {
1278 struct amd_sched_job base;
1279 struct amdgpu_device *adev;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001280 struct amdgpu_ib *ibs;
1281 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001282 void *owner;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001283 struct amdgpu_user_fence uf;
Junwei Zhang4c7eb912015-09-09 09:05:55 +08001284 int (*free_job)(struct amdgpu_job *job);
Chunming Zhoubb977d32015-08-18 15:16:40 +08001285};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001286#define to_amdgpu_job(sched_job) \
1287 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001288
Alex Deucher97b2e202015-04-20 16:51:00 -04001289static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, uint32_t ib_idx, int idx)
1290{
1291 return p->ibs[ib_idx].ptr[idx];
1292}
1293
1294/*
1295 * Writeback
1296 */
1297#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1298
1299struct amdgpu_wb {
1300 struct amdgpu_bo *wb_obj;
1301 volatile uint32_t *wb;
1302 uint64_t gpu_addr;
1303 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1304 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1305};
1306
1307int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1308void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1309
Alex Deucher97b2e202015-04-20 16:51:00 -04001310
Alex Deucher97b2e202015-04-20 16:51:00 -04001311
1312enum amdgpu_int_thermal_type {
1313 THERMAL_TYPE_NONE,
1314 THERMAL_TYPE_EXTERNAL,
1315 THERMAL_TYPE_EXTERNAL_GPIO,
1316 THERMAL_TYPE_RV6XX,
1317 THERMAL_TYPE_RV770,
1318 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1319 THERMAL_TYPE_EVERGREEN,
1320 THERMAL_TYPE_SUMO,
1321 THERMAL_TYPE_NI,
1322 THERMAL_TYPE_SI,
1323 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1324 THERMAL_TYPE_CI,
1325 THERMAL_TYPE_KV,
1326};
1327
1328enum amdgpu_dpm_auto_throttle_src {
1329 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1330 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1331};
1332
1333enum amdgpu_dpm_event_src {
1334 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1335 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1336 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1337 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1338 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1339};
1340
1341#define AMDGPU_MAX_VCE_LEVELS 6
1342
1343enum amdgpu_vce_level {
1344 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1345 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1346 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1347 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1348 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1349 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1350};
1351
1352struct amdgpu_ps {
1353 u32 caps; /* vbios flags */
1354 u32 class; /* vbios flags */
1355 u32 class2; /* vbios flags */
1356 /* UVD clocks */
1357 u32 vclk;
1358 u32 dclk;
1359 /* VCE clocks */
1360 u32 evclk;
1361 u32 ecclk;
1362 bool vce_active;
1363 enum amdgpu_vce_level vce_level;
1364 /* asic priv */
1365 void *ps_priv;
1366};
1367
1368struct amdgpu_dpm_thermal {
1369 /* thermal interrupt work */
1370 struct work_struct work;
1371 /* low temperature threshold */
1372 int min_temp;
1373 /* high temperature threshold */
1374 int max_temp;
1375 /* was last interrupt low to high or high to low */
1376 bool high_to_low;
1377 /* interrupt source */
1378 struct amdgpu_irq_src irq;
1379};
1380
1381enum amdgpu_clk_action
1382{
1383 AMDGPU_SCLK_UP = 1,
1384 AMDGPU_SCLK_DOWN
1385};
1386
1387struct amdgpu_blacklist_clocks
1388{
1389 u32 sclk;
1390 u32 mclk;
1391 enum amdgpu_clk_action action;
1392};
1393
1394struct amdgpu_clock_and_voltage_limits {
1395 u32 sclk;
1396 u32 mclk;
1397 u16 vddc;
1398 u16 vddci;
1399};
1400
1401struct amdgpu_clock_array {
1402 u32 count;
1403 u32 *values;
1404};
1405
1406struct amdgpu_clock_voltage_dependency_entry {
1407 u32 clk;
1408 u16 v;
1409};
1410
1411struct amdgpu_clock_voltage_dependency_table {
1412 u32 count;
1413 struct amdgpu_clock_voltage_dependency_entry *entries;
1414};
1415
1416union amdgpu_cac_leakage_entry {
1417 struct {
1418 u16 vddc;
1419 u32 leakage;
1420 };
1421 struct {
1422 u16 vddc1;
1423 u16 vddc2;
1424 u16 vddc3;
1425 };
1426};
1427
1428struct amdgpu_cac_leakage_table {
1429 u32 count;
1430 union amdgpu_cac_leakage_entry *entries;
1431};
1432
1433struct amdgpu_phase_shedding_limits_entry {
1434 u16 voltage;
1435 u32 sclk;
1436 u32 mclk;
1437};
1438
1439struct amdgpu_phase_shedding_limits_table {
1440 u32 count;
1441 struct amdgpu_phase_shedding_limits_entry *entries;
1442};
1443
1444struct amdgpu_uvd_clock_voltage_dependency_entry {
1445 u32 vclk;
1446 u32 dclk;
1447 u16 v;
1448};
1449
1450struct amdgpu_uvd_clock_voltage_dependency_table {
1451 u8 count;
1452 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1453};
1454
1455struct amdgpu_vce_clock_voltage_dependency_entry {
1456 u32 ecclk;
1457 u32 evclk;
1458 u16 v;
1459};
1460
1461struct amdgpu_vce_clock_voltage_dependency_table {
1462 u8 count;
1463 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1464};
1465
1466struct amdgpu_ppm_table {
1467 u8 ppm_design;
1468 u16 cpu_core_number;
1469 u32 platform_tdp;
1470 u32 small_ac_platform_tdp;
1471 u32 platform_tdc;
1472 u32 small_ac_platform_tdc;
1473 u32 apu_tdp;
1474 u32 dgpu_tdp;
1475 u32 dgpu_ulv_power;
1476 u32 tj_max;
1477};
1478
1479struct amdgpu_cac_tdp_table {
1480 u16 tdp;
1481 u16 configurable_tdp;
1482 u16 tdc;
1483 u16 battery_power_limit;
1484 u16 small_power_limit;
1485 u16 low_cac_leakage;
1486 u16 high_cac_leakage;
1487 u16 maximum_power_delivery_limit;
1488};
1489
1490struct amdgpu_dpm_dynamic_state {
1491 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1492 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1493 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1494 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1495 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1496 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1497 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1498 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1499 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1500 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1501 struct amdgpu_clock_array valid_sclk_values;
1502 struct amdgpu_clock_array valid_mclk_values;
1503 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1504 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1505 u32 mclk_sclk_ratio;
1506 u32 sclk_mclk_delta;
1507 u16 vddc_vddci_delta;
1508 u16 min_vddc_for_pcie_gen2;
1509 struct amdgpu_cac_leakage_table cac_leakage_table;
1510 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1511 struct amdgpu_ppm_table *ppm_table;
1512 struct amdgpu_cac_tdp_table *cac_tdp_table;
1513};
1514
1515struct amdgpu_dpm_fan {
1516 u16 t_min;
1517 u16 t_med;
1518 u16 t_high;
1519 u16 pwm_min;
1520 u16 pwm_med;
1521 u16 pwm_high;
1522 u8 t_hyst;
1523 u32 cycle_delay;
1524 u16 t_max;
1525 u8 control_mode;
1526 u16 default_max_fan_pwm;
1527 u16 default_fan_output_sensitivity;
1528 u16 fan_output_sensitivity;
1529 bool ucode_fan_control;
1530};
1531
1532enum amdgpu_pcie_gen {
1533 AMDGPU_PCIE_GEN1 = 0,
1534 AMDGPU_PCIE_GEN2 = 1,
1535 AMDGPU_PCIE_GEN3 = 2,
1536 AMDGPU_PCIE_GEN_INVALID = 0xffff
1537};
1538
1539enum amdgpu_dpm_forced_level {
1540 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1541 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1542 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
1543};
1544
1545struct amdgpu_vce_state {
1546 /* vce clocks */
1547 u32 evclk;
1548 u32 ecclk;
1549 /* gpu clocks */
1550 u32 sclk;
1551 u32 mclk;
1552 u8 clk_idx;
1553 u8 pstate;
1554};
1555
1556struct amdgpu_dpm_funcs {
1557 int (*get_temperature)(struct amdgpu_device *adev);
1558 int (*pre_set_power_state)(struct amdgpu_device *adev);
1559 int (*set_power_state)(struct amdgpu_device *adev);
1560 void (*post_set_power_state)(struct amdgpu_device *adev);
1561 void (*display_configuration_changed)(struct amdgpu_device *adev);
1562 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1563 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1564 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1565 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1566 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1567 bool (*vblank_too_short)(struct amdgpu_device *adev);
1568 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001569 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001570 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1571 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1572 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1573 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1574 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1575};
1576
1577struct amdgpu_dpm {
1578 struct amdgpu_ps *ps;
1579 /* number of valid power states */
1580 int num_ps;
1581 /* current power state that is active */
1582 struct amdgpu_ps *current_ps;
1583 /* requested power state */
1584 struct amdgpu_ps *requested_ps;
1585 /* boot up power state */
1586 struct amdgpu_ps *boot_ps;
1587 /* default uvd power state */
1588 struct amdgpu_ps *uvd_ps;
1589 /* vce requirements */
1590 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1591 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001592 enum amd_pm_state_type state;
1593 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001594 u32 platform_caps;
1595 u32 voltage_response_time;
1596 u32 backbias_response_time;
1597 void *priv;
1598 u32 new_active_crtcs;
1599 int new_active_crtc_count;
1600 u32 current_active_crtcs;
1601 int current_active_crtc_count;
1602 struct amdgpu_dpm_dynamic_state dyn_state;
1603 struct amdgpu_dpm_fan fan;
1604 u32 tdp_limit;
1605 u32 near_tdp_limit;
1606 u32 near_tdp_limit_adjusted;
1607 u32 sq_ramping_threshold;
1608 u32 cac_leakage;
1609 u16 tdp_od_limit;
1610 u32 tdp_adjustment;
1611 u16 load_line_slope;
1612 bool power_control;
1613 bool ac_power;
1614 /* special states active */
1615 bool thermal_active;
1616 bool uvd_active;
1617 bool vce_active;
1618 /* thermal handling */
1619 struct amdgpu_dpm_thermal thermal;
1620 /* forced levels */
1621 enum amdgpu_dpm_forced_level forced_level;
1622};
1623
1624struct amdgpu_pm {
1625 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001626 u32 current_sclk;
1627 u32 current_mclk;
1628 u32 default_sclk;
1629 u32 default_mclk;
1630 struct amdgpu_i2c_chan *i2c_bus;
1631 /* internal thermal controller on rv6xx+ */
1632 enum amdgpu_int_thermal_type int_thermal_type;
1633 struct device *int_hwmon_dev;
1634 /* fan control parameters */
1635 bool no_fan;
1636 u8 fan_pulses_per_revolution;
1637 u8 fan_min_rpm;
1638 u8 fan_max_rpm;
1639 /* dpm */
1640 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001641 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001642 struct amdgpu_dpm dpm;
1643 const struct firmware *fw; /* SMC firmware */
1644 uint32_t fw_version;
1645 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001646 uint32_t pcie_gen_mask;
1647 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001648 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001649};
1650
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001651void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1652
Alex Deucher97b2e202015-04-20 16:51:00 -04001653/*
1654 * UVD
1655 */
1656#define AMDGPU_MAX_UVD_HANDLES 10
1657#define AMDGPU_UVD_STACK_SIZE (1024*1024)
1658#define AMDGPU_UVD_HEAP_SIZE (1024*1024)
1659#define AMDGPU_UVD_FIRMWARE_OFFSET 256
1660
1661struct amdgpu_uvd {
1662 struct amdgpu_bo *vcpu_bo;
1663 void *cpu_addr;
1664 uint64_t gpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001665 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1666 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1667 struct delayed_work idle_work;
1668 const struct firmware *fw; /* UVD firmware */
1669 struct amdgpu_ring ring;
1670 struct amdgpu_irq_src irq;
1671 bool address_64_bit;
1672};
1673
1674/*
1675 * VCE
1676 */
1677#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001678#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1679
Alex Deucher6a585772015-07-10 14:16:24 -04001680#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1681#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1682
Alex Deucher97b2e202015-04-20 16:51:00 -04001683struct amdgpu_vce {
1684 struct amdgpu_bo *vcpu_bo;
1685 uint64_t gpu_addr;
1686 unsigned fw_version;
1687 unsigned fb_version;
1688 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1689 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001690 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001691 struct delayed_work idle_work;
1692 const struct firmware *fw; /* VCE firmware */
1693 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1694 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001695 unsigned harvest_config;
Alex Deucher97b2e202015-04-20 16:51:00 -04001696};
1697
1698/*
1699 * SDMA
1700 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001701struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001702 /* SDMA firmware */
1703 const struct firmware *fw;
1704 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001705 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001706
1707 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001708 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001709};
1710
Alex Deucherc113ea12015-10-08 16:30:37 -04001711struct amdgpu_sdma {
1712 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1713 struct amdgpu_irq_src trap_irq;
1714 struct amdgpu_irq_src illegal_inst_irq;
1715 int num_instances;
1716};
1717
Alex Deucher97b2e202015-04-20 16:51:00 -04001718/*
1719 * Firmware
1720 */
1721struct amdgpu_firmware {
1722 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1723 bool smu_load;
1724 struct amdgpu_bo *fw_buf;
1725 unsigned int fw_size;
1726};
1727
1728/*
1729 * Benchmarking
1730 */
1731void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1732
1733
1734/*
1735 * Testing
1736 */
1737void amdgpu_test_moves(struct amdgpu_device *adev);
1738void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1739 struct amdgpu_ring *cpA,
1740 struct amdgpu_ring *cpB);
1741void amdgpu_test_syncing(struct amdgpu_device *adev);
1742
1743/*
1744 * MMU Notifier
1745 */
1746#if defined(CONFIG_MMU_NOTIFIER)
1747int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1748void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1749#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001750static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001751{
1752 return -ENODEV;
1753}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001754static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001755#endif
1756
1757/*
1758 * Debugfs
1759 */
1760struct amdgpu_debugfs {
1761 struct drm_info_list *files;
1762 unsigned num_files;
1763};
1764
1765int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
1766 struct drm_info_list *files,
1767 unsigned nfiles);
1768int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1769
1770#if defined(CONFIG_DEBUG_FS)
1771int amdgpu_debugfs_init(struct drm_minor *minor);
1772void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1773#endif
1774
1775/*
1776 * amdgpu smumgr functions
1777 */
1778struct amdgpu_smumgr_funcs {
1779 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1780 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1781 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1782};
1783
1784/*
1785 * amdgpu smumgr
1786 */
1787struct amdgpu_smumgr {
1788 struct amdgpu_bo *toc_buf;
1789 struct amdgpu_bo *smu_buf;
1790 /* asic priv smu data */
1791 void *priv;
1792 spinlock_t smu_lock;
1793 /* smumgr functions */
1794 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1795 /* ucode loading complete flag */
1796 uint32_t fw_flags;
1797};
1798
1799/*
1800 * ASIC specific register table accessible by UMD
1801 */
1802struct amdgpu_allowed_register_entry {
1803 uint32_t reg_offset;
1804 bool untouched;
1805 bool grbm_indexed;
1806};
1807
1808struct amdgpu_cu_info {
1809 uint32_t number; /* total active CU number */
1810 uint32_t ao_cu_mask;
1811 uint32_t bitmap[4][4];
1812};
1813
1814
1815/*
1816 * ASIC specific functions.
1817 */
1818struct amdgpu_asic_funcs {
1819 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001820 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1821 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001822 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1823 u32 sh_num, u32 reg_offset, u32 *value);
1824 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1825 int (*reset)(struct amdgpu_device *adev);
1826 /* wait for mc_idle */
1827 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1828 /* get the reference clock */
1829 u32 (*get_xclk)(struct amdgpu_device *adev);
1830 /* get the gpu clock counter */
1831 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
1832 int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
1833 /* MM block clocks */
1834 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1835 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1836};
1837
1838/*
1839 * IOCTL.
1840 */
1841int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1842 struct drm_file *filp);
1843int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1844 struct drm_file *filp);
1845
1846int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1847 struct drm_file *filp);
1848int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1849 struct drm_file *filp);
1850int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1851 struct drm_file *filp);
1852int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1853 struct drm_file *filp);
1854int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1855 struct drm_file *filp);
1856int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1857 struct drm_file *filp);
1858int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1859int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1860
1861int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1862 struct drm_file *filp);
1863
1864/* VRAM scratch page for HDP bug, default vram page */
1865struct amdgpu_vram_scratch {
1866 struct amdgpu_bo *robj;
1867 volatile uint32_t *ptr;
1868 u64 gpu_addr;
1869};
1870
1871/*
1872 * ACPI
1873 */
1874struct amdgpu_atif_notification_cfg {
1875 bool enabled;
1876 int command_code;
1877};
1878
1879struct amdgpu_atif_notifications {
1880 bool display_switch;
1881 bool expansion_mode_change;
1882 bool thermal_state;
1883 bool forced_power_state;
1884 bool system_power_state;
1885 bool display_conf_change;
1886 bool px_gfx_switch;
1887 bool brightness_change;
1888 bool dgpu_display_event;
1889};
1890
1891struct amdgpu_atif_functions {
1892 bool system_params;
1893 bool sbios_requests;
1894 bool select_active_disp;
1895 bool lid_state;
1896 bool get_tv_standard;
1897 bool set_tv_standard;
1898 bool get_panel_expansion_mode;
1899 bool set_panel_expansion_mode;
1900 bool temperature_change;
1901 bool graphics_device_types;
1902};
1903
1904struct amdgpu_atif {
1905 struct amdgpu_atif_notifications notifications;
1906 struct amdgpu_atif_functions functions;
1907 struct amdgpu_atif_notification_cfg notification_cfg;
1908 struct amdgpu_encoder *encoder_for_bl;
1909};
1910
1911struct amdgpu_atcs_functions {
1912 bool get_ext_state;
1913 bool pcie_perf_req;
1914 bool pcie_dev_rdy;
1915 bool pcie_bus_width;
1916};
1917
1918struct amdgpu_atcs {
1919 struct amdgpu_atcs_functions functions;
1920};
1921
Alex Deucher97b2e202015-04-20 16:51:00 -04001922/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001923 * CGS
1924 */
1925void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1926void amdgpu_cgs_destroy_device(void *cgs_device);
1927
1928
1929/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001930 * Core structure, functions and helpers.
1931 */
1932typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1933typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1934
1935typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1936typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1937
Alex Deucher8faf0e02015-07-28 11:50:31 -04001938struct amdgpu_ip_block_status {
1939 bool valid;
1940 bool sw;
1941 bool hw;
1942};
1943
Alex Deucher97b2e202015-04-20 16:51:00 -04001944struct amdgpu_device {
1945 struct device *dev;
1946 struct drm_device *ddev;
1947 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001948
1949 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001950 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001951 uint32_t family;
1952 uint32_t rev_id;
1953 uint32_t external_rev_id;
1954 unsigned long flags;
1955 int usec_timeout;
1956 const struct amdgpu_asic_funcs *asic_funcs;
1957 bool shutdown;
1958 bool suspend;
1959 bool need_dma32;
1960 bool accel_working;
Alex Deucher97b2e202015-04-20 16:51:00 -04001961 struct work_struct reset_work;
1962 struct notifier_block acpi_nb;
1963 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1964 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1965 unsigned debugfs_count;
1966#if defined(CONFIG_DEBUG_FS)
1967 struct dentry *debugfs_regs;
1968#endif
1969 struct amdgpu_atif atif;
1970 struct amdgpu_atcs atcs;
1971 struct mutex srbm_mutex;
1972 /* GRBM index mutex. Protects concurrent access to GRBM index */
1973 struct mutex grbm_idx_mutex;
1974 struct dev_pm_domain vga_pm_domain;
1975 bool have_disp_power_ref;
1976
1977 /* BIOS */
1978 uint8_t *bios;
1979 bool is_atom_bios;
1980 uint16_t bios_header_start;
1981 struct amdgpu_bo *stollen_vga_memory;
1982 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1983
1984 /* Register/doorbell mmio */
1985 resource_size_t rmmio_base;
1986 resource_size_t rmmio_size;
1987 void __iomem *rmmio;
1988 /* protects concurrent MM_INDEX/DATA based register access */
1989 spinlock_t mmio_idx_lock;
1990 /* protects concurrent SMC based register access */
1991 spinlock_t smc_idx_lock;
1992 amdgpu_rreg_t smc_rreg;
1993 amdgpu_wreg_t smc_wreg;
1994 /* protects concurrent PCIE register access */
1995 spinlock_t pcie_idx_lock;
1996 amdgpu_rreg_t pcie_rreg;
1997 amdgpu_wreg_t pcie_wreg;
1998 /* protects concurrent UVD register access */
1999 spinlock_t uvd_ctx_idx_lock;
2000 amdgpu_rreg_t uvd_ctx_rreg;
2001 amdgpu_wreg_t uvd_ctx_wreg;
2002 /* protects concurrent DIDT register access */
2003 spinlock_t didt_idx_lock;
2004 amdgpu_rreg_t didt_rreg;
2005 amdgpu_wreg_t didt_wreg;
2006 /* protects concurrent ENDPOINT (audio) register access */
2007 spinlock_t audio_endpt_idx_lock;
2008 amdgpu_block_rreg_t audio_endpt_rreg;
2009 amdgpu_block_wreg_t audio_endpt_wreg;
2010 void __iomem *rio_mem;
2011 resource_size_t rio_mem_size;
2012 struct amdgpu_doorbell doorbell;
2013
2014 /* clock/pll info */
2015 struct amdgpu_clock clock;
2016
2017 /* MC */
2018 struct amdgpu_mc mc;
2019 struct amdgpu_gart gart;
2020 struct amdgpu_dummy_page dummy_page;
2021 struct amdgpu_vm_manager vm_manager;
2022
2023 /* memory management */
2024 struct amdgpu_mman mman;
2025 struct amdgpu_gem gem;
2026 struct amdgpu_vram_scratch vram_scratch;
2027 struct amdgpu_wb wb;
2028 atomic64_t vram_usage;
2029 atomic64_t vram_vis_usage;
2030 atomic64_t gtt_usage;
2031 atomic64_t num_bytes_moved;
Marek Olšákd94aed52015-05-05 21:13:49 +02002032 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002033
2034 /* display */
2035 struct amdgpu_mode_info mode_info;
2036 struct work_struct hotplug_work;
2037 struct amdgpu_irq_src crtc_irq;
2038 struct amdgpu_irq_src pageflip_irq;
2039 struct amdgpu_irq_src hpd_irq;
2040
2041 /* rings */
Alex Deucher97b2e202015-04-20 16:51:00 -04002042 unsigned fence_context;
2043 struct mutex ring_lock;
2044 unsigned num_rings;
2045 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2046 bool ib_pool_ready;
2047 struct amdgpu_sa_manager ring_tmp_bo;
2048
2049 /* interrupts */
2050 struct amdgpu_irq irq;
2051
Alex Deucher1f7371b2015-12-02 17:46:21 -05002052 /* powerplay */
2053 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002054 bool pp_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002055
Alex Deucher97b2e202015-04-20 16:51:00 -04002056 /* dpm */
2057 struct amdgpu_pm pm;
2058 u32 cg_flags;
2059 u32 pg_flags;
2060
2061 /* amdgpu smumgr */
2062 struct amdgpu_smumgr smu;
2063
2064 /* gfx */
2065 struct amdgpu_gfx gfx;
2066
2067 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002068 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002069
2070 /* uvd */
2071 bool has_uvd;
2072 struct amdgpu_uvd uvd;
2073
2074 /* vce */
2075 struct amdgpu_vce vce;
2076
2077 /* firmwares */
2078 struct amdgpu_firmware firmware;
2079
2080 /* GDS */
2081 struct amdgpu_gds gds;
2082
2083 const struct amdgpu_ip_block_version *ip_blocks;
2084 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002085 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002086 struct mutex mn_lock;
2087 DECLARE_HASHTABLE(mn_hash, 7);
2088
2089 /* tracking pinned memory */
2090 u64 vram_pin_size;
2091 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002092
2093 /* amdkfd interface */
2094 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002095
2096 /* kernel conext for IB submission */
Christian König47f38502015-08-04 17:51:05 +02002097 struct amdgpu_ctx kernel_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -04002098};
2099
2100bool amdgpu_device_is_px(struct drm_device *dev);
2101int amdgpu_device_init(struct amdgpu_device *adev,
2102 struct drm_device *ddev,
2103 struct pci_dev *pdev,
2104 uint32_t flags);
2105void amdgpu_device_fini(struct amdgpu_device *adev);
2106int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2107
2108uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2109 bool always_indirect);
2110void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2111 bool always_indirect);
2112u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2113void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2114
2115u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2116void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2117
2118/*
2119 * Cast helper
2120 */
2121extern const struct fence_ops amdgpu_fence_ops;
2122static inline struct amdgpu_fence *to_amdgpu_fence(struct fence *f)
2123{
2124 struct amdgpu_fence *__f = container_of(f, struct amdgpu_fence, base);
2125
2126 if (__f->base.ops == &amdgpu_fence_ops)
2127 return __f;
2128
2129 return NULL;
2130}
2131
2132/*
2133 * Registers read & write functions.
2134 */
2135#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2136#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2137#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2138#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2139#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2140#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2141#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2142#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2143#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2144#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2145#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2146#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2147#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2148#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2149#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2150#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2151#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2152#define WREG32_P(reg, val, mask) \
2153 do { \
2154 uint32_t tmp_ = RREG32(reg); \
2155 tmp_ &= (mask); \
2156 tmp_ |= ((val) & ~(mask)); \
2157 WREG32(reg, tmp_); \
2158 } while (0)
2159#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2160#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2161#define WREG32_PLL_P(reg, val, mask) \
2162 do { \
2163 uint32_t tmp_ = RREG32_PLL(reg); \
2164 tmp_ &= (mask); \
2165 tmp_ |= ((val) & ~(mask)); \
2166 WREG32_PLL(reg, tmp_); \
2167 } while (0)
2168#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2169#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2170#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2171
2172#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2173#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2174
2175#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2176#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2177
2178#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2179 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2180 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2181
2182#define REG_GET_FIELD(value, reg, field) \
2183 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2184
2185/*
2186 * BIOS helpers.
2187 */
2188#define RBIOS8(i) (adev->bios[i])
2189#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2190#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2191
2192/*
2193 * RING helpers.
2194 */
2195static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2196{
2197 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002198 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002199 ring->ring[ring->wptr++] = v;
2200 ring->wptr &= ring->ptr_mask;
2201 ring->count_dw--;
2202 ring->ring_free_dw--;
2203}
2204
Alex Deucherc113ea12015-10-08 16:30:37 -04002205static inline struct amdgpu_sdma_instance *
2206amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002207{
2208 struct amdgpu_device *adev = ring->adev;
2209 int i;
2210
Alex Deucherc113ea12015-10-08 16:30:37 -04002211 for (i = 0; i < adev->sdma.num_instances; i++)
2212 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002213 break;
2214
2215 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002216 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002217 else
2218 return NULL;
2219}
2220
Alex Deucher97b2e202015-04-20 16:51:00 -04002221/*
2222 * ASICs macro.
2223 */
2224#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2225#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
2226#define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
2227#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2228#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2229#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2230#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2231#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002232#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 -04002233#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
2234#define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
2235#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2236#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2237#define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
2238#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)))
2239#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)))
2240#define amdgpu_vm_pad_ib(adev, ib) ((adev)->vm_manager.vm_pte_funcs->pad_ib((ib)))
2241#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2242#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2243#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002244#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2245#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2246#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2247#define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
2248#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002249#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002250#define amdgpu_ring_emit_semaphore(r, semaphore, emit_wait) (r)->funcs->emit_semaphore((r), (semaphore), (emit_wait))
2251#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 +02002252#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002253#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2254#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2255#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2256#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2257#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2258#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2259#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2260#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2261#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2262#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2263#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2264#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2265#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2266#define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
2267#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2268#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2269#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))
2270#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2271#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002272#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 +08002273#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 -04002274#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2275#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2276#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2277#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002278#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002279#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002280#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Rex Zhu3af76f22015-10-15 17:23:43 +08002281
2282#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002283 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002284 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002285 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002286
2287#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002288 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002289 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002290 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002291
2292#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002293 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002294 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002295 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002296
2297#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002298 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002299 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002300 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002301
2302#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002303 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002304 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002305 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002306
Rex Zhu1b5708f2015-11-10 18:25:24 -05002307#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002308 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002309 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002310 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002311
2312#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002313 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002314 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002315 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002316
2317
2318#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002319 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002320 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002321 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002322
2323#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002324 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002325 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002326 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002327
2328#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002329 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002330 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002331 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002332
2333#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002334 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002335 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002336 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002337
2338#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002339 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002340
2341#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002342 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002343
Jammy Zhoue61710c2015-11-10 18:31:08 -05002344#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002345 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002346
2347#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2348
2349/* Common functions */
2350int amdgpu_gpu_reset(struct amdgpu_device *adev);
2351void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2352bool amdgpu_card_posted(struct amdgpu_device *adev);
2353void amdgpu_update_display_priority(struct amdgpu_device *adev);
2354bool amdgpu_boot_test_post_card(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002355
Alex Deucher97b2e202015-04-20 16:51:00 -04002356int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2357int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2358 u32 ip_instance, u32 ring,
2359 struct amdgpu_ring **out_ring);
2360void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2361bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
2362int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2363 uint32_t flags);
2364bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
2365bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2366uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2367 struct ttm_mem_reg *mem);
2368void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2369void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2370void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2371void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2372 const u32 *registers,
2373 const u32 array_size);
2374
2375bool amdgpu_device_is_px(struct drm_device *dev);
2376/* atpx handler */
2377#if defined(CONFIG_VGA_SWITCHEROO)
2378void amdgpu_register_atpx_handler(void);
2379void amdgpu_unregister_atpx_handler(void);
2380#else
2381static inline void amdgpu_register_atpx_handler(void) {}
2382static inline void amdgpu_unregister_atpx_handler(void) {}
2383#endif
2384
2385/*
2386 * KMS
2387 */
2388extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2389extern int amdgpu_max_kms_ioctl;
2390
2391int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2392int amdgpu_driver_unload_kms(struct drm_device *dev);
2393void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2394int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2395void amdgpu_driver_postclose_kms(struct drm_device *dev,
2396 struct drm_file *file_priv);
2397void amdgpu_driver_preclose_kms(struct drm_device *dev,
2398 struct drm_file *file_priv);
2399int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2400int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002401u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2402int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2403void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2404int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002405 int *max_error,
2406 struct timeval *vblank_time,
2407 unsigned flags);
2408long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2409 unsigned long arg);
2410
2411/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002412 * functions used by amdgpu_encoder.c
2413 */
2414struct amdgpu_afmt_acr {
2415 u32 clock;
2416
2417 int n_32khz;
2418 int cts_32khz;
2419
2420 int n_44_1khz;
2421 int cts_44_1khz;
2422
2423 int n_48khz;
2424 int cts_48khz;
2425
2426};
2427
2428struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2429
2430/* amdgpu_acpi.c */
2431#if defined(CONFIG_ACPI)
2432int amdgpu_acpi_init(struct amdgpu_device *adev);
2433void amdgpu_acpi_fini(struct amdgpu_device *adev);
2434bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2435int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2436 u8 perf_req, bool advertise);
2437int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2438#else
2439static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2440static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2441#endif
2442
2443struct amdgpu_bo_va_mapping *
2444amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2445 uint64_t addr, struct amdgpu_bo **bo);
2446
2447#include "amdgpu_object.h"
2448
2449#endif