blob: 1a7e05da470e09f737fa0b14fd483dc5364b007e [file] [log] [blame]
Alex Deucher97b2e202015-04-20 16:51:00 -04001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#ifndef __AMDGPU_H__
29#define __AMDGPU_H__
30
31#include <linux/atomic.h>
32#include <linux/wait.h>
33#include <linux/list.h>
34#include <linux/kref.h>
35#include <linux/interval_tree.h>
36#include <linux/hashtable.h>
37#include <linux/fence.h>
38
39#include <ttm/ttm_bo_api.h>
40#include <ttm/ttm_bo_driver.h>
41#include <ttm/ttm_placement.h>
42#include <ttm/ttm_module.h>
43#include <ttm/ttm_execbuf_util.h>
44
Chunming Zhoud03846a2015-07-28 14:20:03 -040045#include <drm/drmP.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040046#include <drm/drm_gem.h>
Chunming Zhou7e5a5472015-04-24 17:37:30 +080047#include <drm/amdgpu_drm.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040048
yanyang15fc3aee2015-05-22 14:39:35 -040049#include "amd_shared.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040050#include "amdgpu_mode.h"
51#include "amdgpu_ih.h"
52#include "amdgpu_irq.h"
53#include "amdgpu_ucode.h"
54#include "amdgpu_gds.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050055#include "amd_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040056#include "amdgpu_acp.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040057
Alex Deucherb80d8472015-08-16 22:55:02 -040058#include "gpu_scheduler.h"
59
Alex Deucher97b2e202015-04-20 16:51:00 -040060/*
61 * Modules parameters.
62 */
63extern int amdgpu_modeset;
64extern int amdgpu_vram_limit;
65extern int amdgpu_gart_size;
66extern int amdgpu_benchmarking;
67extern int amdgpu_testing;
68extern int amdgpu_audio;
69extern int amdgpu_disp_priority;
70extern int amdgpu_hw_i2c;
71extern int amdgpu_pcie_gen2;
72extern int amdgpu_msi;
73extern int amdgpu_lockup_timeout;
74extern int amdgpu_dpm;
75extern int amdgpu_smc_load_fw;
76extern int amdgpu_aspm;
77extern int amdgpu_runtime_pm;
Alex Deucher97b2e202015-04-20 16:51:00 -040078extern unsigned amdgpu_ip_block_mask;
79extern int amdgpu_bapm;
80extern int amdgpu_deep_color;
81extern int amdgpu_vm_size;
82extern int amdgpu_vm_block_size;
Christian Königd9c13152015-09-28 12:31:26 +020083extern int amdgpu_vm_fault_stop;
Christian Königb495bd32015-09-10 14:00:35 +020084extern int amdgpu_vm_debug;
Jammy Zhou1333f722015-07-30 16:36:58 +080085extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080086extern int amdgpu_sched_hw_submission;
Alex Deucher1f7371b2015-12-02 17:46:21 -050087extern int amdgpu_powerplay;
Huang Rui6bb6b292016-05-24 13:47:05 +080088extern int amdgpu_powercontainment;
Alex Deuchercd474ba2016-02-04 10:21:23 -050089extern unsigned amdgpu_pcie_gen_cap;
90extern unsigned amdgpu_pcie_lane_cap;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +020091extern unsigned amdgpu_cg_mask;
92extern unsigned amdgpu_pg_mask;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +020093extern char *amdgpu_disable_cu;
Rex Zhu66bc3f72016-07-28 17:36:35 +080094extern int amdgpu_sclk_deep_sleep_en;
Emily Deng9accf2f2016-08-10 16:01:25 +080095extern char *amdgpu_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -040096
Chunming Zhou4b559c92015-07-21 15:53:04 +080097#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -040098#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
99#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
100/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
101#define AMDGPU_IB_POOL_SIZE 16
102#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
103#define AMDGPUFB_CONN_LIMIT 4
104#define AMDGPU_BIOS_NUM_SCRATCH 8
105
Alex Deucher97b2e202015-04-20 16:51:00 -0400106/* max number of rings */
107#define AMDGPU_MAX_RINGS 16
108#define AMDGPU_MAX_GFX_RINGS 1
109#define AMDGPU_MAX_COMPUTE_RINGS 8
110#define AMDGPU_MAX_VCE_RINGS 2
111
Jammy Zhou36f523a2015-09-01 12:54:27 +0800112/* max number of IP instances */
113#define AMDGPU_MAX_SDMA_INSTANCES 2
114
Alex Deucher97b2e202015-04-20 16:51:00 -0400115/* hardcode that limit for now */
116#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
117
118/* hard reset data */
119#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
120
121/* reset flags */
122#define AMDGPU_RESET_GFX (1 << 0)
123#define AMDGPU_RESET_COMPUTE (1 << 1)
124#define AMDGPU_RESET_DMA (1 << 2)
125#define AMDGPU_RESET_CP (1 << 3)
126#define AMDGPU_RESET_GRBM (1 << 4)
127#define AMDGPU_RESET_DMA1 (1 << 5)
128#define AMDGPU_RESET_RLC (1 << 6)
129#define AMDGPU_RESET_SEM (1 << 7)
130#define AMDGPU_RESET_IH (1 << 8)
131#define AMDGPU_RESET_VMC (1 << 9)
132#define AMDGPU_RESET_MC (1 << 10)
133#define AMDGPU_RESET_DISPLAY (1 << 11)
134#define AMDGPU_RESET_UVD (1 << 12)
135#define AMDGPU_RESET_VCE (1 << 13)
136#define AMDGPU_RESET_VCE1 (1 << 14)
137
Alex Deucher97b2e202015-04-20 16:51:00 -0400138/* GFX current status */
139#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
140#define AMDGPU_GFX_SAFE_MODE 0x00000001L
141#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
142#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
143#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
144
145/* max cursor sizes (in pixels) */
146#define CIK_CURSOR_WIDTH 128
147#define CIK_CURSOR_HEIGHT 128
148
149struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400150struct amdgpu_ib;
151struct amdgpu_vm;
152struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400153struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800154struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400155struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400156struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400157
158enum amdgpu_cp_irq {
159 AMDGPU_CP_IRQ_GFX_EOP = 0,
160 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
161 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
162 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
163 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
164 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
165 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
166 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
167 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
168
169 AMDGPU_CP_IRQ_LAST
170};
171
172enum amdgpu_sdma_irq {
173 AMDGPU_SDMA_IRQ_TRAP0 = 0,
174 AMDGPU_SDMA_IRQ_TRAP1,
175
176 AMDGPU_SDMA_IRQ_LAST
177};
178
179enum amdgpu_thermal_irq {
180 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
181 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
182
183 AMDGPU_THERMAL_IRQ_LAST
184};
185
Alex Deucher97b2e202015-04-20 16:51:00 -0400186int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400187 enum amd_ip_block_type block_type,
188 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400189int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400190 enum amd_ip_block_type block_type,
191 enum amd_powergating_state state);
Alex Deucher5dbbb602016-06-23 11:41:04 -0400192int amdgpu_wait_for_idle(struct amdgpu_device *adev,
193 enum amd_ip_block_type block_type);
194bool amdgpu_is_idle(struct amdgpu_device *adev,
195 enum amd_ip_block_type block_type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400196
197struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400198 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400199 u32 major;
200 u32 minor;
201 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400202 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400203};
204
205int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400206 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400207 u32 major, u32 minor);
208
209const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
210 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400211 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400212
213/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
214struct amdgpu_buffer_funcs {
215 /* maximum bytes in a single operation */
216 uint32_t copy_max_bytes;
217
218 /* number of dw to reserve per operation */
219 unsigned copy_num_dw;
220
221 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800222 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400223 /* src addr in bytes */
224 uint64_t src_offset,
225 /* dst addr in bytes */
226 uint64_t dst_offset,
227 /* number of byte to transfer */
228 uint32_t byte_count);
229
230 /* maximum bytes in a single operation */
231 uint32_t fill_max_bytes;
232
233 /* number of dw to reserve per operation */
234 unsigned fill_num_dw;
235
236 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800237 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400238 /* value to write to memory */
239 uint32_t src_data,
240 /* dst addr in bytes */
241 uint64_t dst_offset,
242 /* number of byte to fill */
243 uint32_t byte_count);
244};
245
246/* provided by hw blocks that can write ptes, e.g., sdma */
247struct amdgpu_vm_pte_funcs {
248 /* copy pte entries from GART */
249 void (*copy_pte)(struct amdgpu_ib *ib,
250 uint64_t pe, uint64_t src,
251 unsigned count);
252 /* write pte one entry at a time with addr mapping */
Christian Königde9ea7b2016-08-12 11:33:30 +0200253 void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
254 uint64_t value, unsigned count,
255 uint32_t incr);
Alex Deucher97b2e202015-04-20 16:51:00 -0400256 /* for linear pte/pde updates without addr mapping */
257 void (*set_pte_pde)(struct amdgpu_ib *ib,
258 uint64_t pe,
259 uint64_t addr, unsigned count,
260 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400261};
262
263/* provided by the gmc block */
264struct amdgpu_gart_funcs {
265 /* flush the vm tlb via mmio */
266 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
267 uint32_t vmid);
268 /* write pte/pde updates using the cpu */
269 int (*set_pte_pde)(struct amdgpu_device *adev,
270 void *cpu_pt_addr, /* cpu addr of page table */
271 uint32_t gpu_page_idx, /* pte/pde to update */
272 uint64_t addr, /* addr to write into pte/pde */
273 uint32_t flags); /* access flags */
274};
275
276/* provided by the ih block */
277struct amdgpu_ih_funcs {
278 /* ring read/write ptr handling, called from interrupt context */
279 u32 (*get_wptr)(struct amdgpu_device *adev);
280 void (*decode_iv)(struct amdgpu_device *adev,
281 struct amdgpu_iv_entry *entry);
282 void (*set_rptr)(struct amdgpu_device *adev);
283};
284
285/* provided by hw blocks that expose a ring buffer for commands */
286struct amdgpu_ring_funcs {
287 /* ring read/write ptr handling */
288 u32 (*get_rptr)(struct amdgpu_ring *ring);
289 u32 (*get_wptr)(struct amdgpu_ring *ring);
290 void (*set_wptr)(struct amdgpu_ring *ring);
291 /* validating and patching of IBs */
292 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
293 /* command emit functions */
294 void (*emit_ib)(struct amdgpu_ring *ring,
Christian Königd88bf582016-05-06 17:50:03 +0200295 struct amdgpu_ib *ib,
296 unsigned vm_id, bool ctx_switch);
Alex Deucher97b2e202015-04-20 16:51:00 -0400297 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800298 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100299 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400300 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
301 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200302 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800303 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400304 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
305 uint32_t gds_base, uint32_t gds_size,
306 uint32_t gws_base, uint32_t gws_size,
307 uint32_t oa_base, uint32_t oa_size);
308 /* testing functions */
309 int (*test_ring)(struct amdgpu_ring *ring);
Christian Königbbec97a2016-07-05 21:07:17 +0200310 int (*test_ib)(struct amdgpu_ring *ring, long timeout);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800311 /* insert NOP packets */
312 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100313 /* pad the indirect buffer to the necessary number of dw */
314 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800315 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
316 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Christian Königf06505b2016-07-20 13:49:34 +0200317 /* note usage for clock and power gating */
318 void (*begin_use)(struct amdgpu_ring *ring);
319 void (*end_use)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400320};
321
322/*
323 * BIOS.
324 */
325bool amdgpu_get_bios(struct amdgpu_device *adev);
326bool amdgpu_read_bios(struct amdgpu_device *adev);
327
328/*
329 * Dummy page
330 */
331struct amdgpu_dummy_page {
332 struct page *page;
333 dma_addr_t addr;
334};
335int amdgpu_dummy_page_init(struct amdgpu_device *adev);
336void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
337
338
339/*
340 * Clocks
341 */
342
343#define AMDGPU_MAX_PPLL 3
344
345struct amdgpu_clock {
346 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
347 struct amdgpu_pll spll;
348 struct amdgpu_pll mpll;
349 /* 10 Khz units */
350 uint32_t default_mclk;
351 uint32_t default_sclk;
352 uint32_t default_dispclk;
353 uint32_t current_dispclk;
354 uint32_t dp_extclk;
355 uint32_t max_pixel_clock;
356};
357
358/*
359 * Fences.
360 */
361struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400362 uint64_t gpu_addr;
363 volatile uint32_t *cpu_addr;
364 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100365 uint32_t sync_seq;
366 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400367 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400368 struct amdgpu_irq_src *irq_src;
369 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100370 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100371 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100372 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100373 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400374};
375
376/* some special values for the owner field */
377#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
378#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400379
Chunming Zhou890ee232015-06-01 14:35:03 +0800380#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
381#define AMDGPU_FENCE_FLAG_INT (1 << 1)
382
Alex Deucher97b2e202015-04-20 16:51:00 -0400383int amdgpu_fence_driver_init(struct amdgpu_device *adev);
384void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
385void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
386
Christian Könige6151a02016-03-15 14:52:26 +0100387int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
388 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400389int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
390 struct amdgpu_irq_src *irq_src,
391 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400392void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
393void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100394int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400395void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400396int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
397unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
398
Alex Deucher97b2e202015-04-20 16:51:00 -0400399/*
400 * TTM.
401 */
Christian König29b32592016-04-15 17:19:16 +0200402
403#define AMDGPU_TTM_LRU_SIZE 20
404
405struct amdgpu_mman_lru {
406 struct list_head *lru[TTM_NUM_MEM_TYPES];
407 struct list_head *swap_lru;
408};
409
Alex Deucher97b2e202015-04-20 16:51:00 -0400410struct amdgpu_mman {
411 struct ttm_bo_global_ref bo_global_ref;
412 struct drm_global_reference mem_global_ref;
413 struct ttm_bo_device bdev;
414 bool mem_global_referenced;
415 bool initialized;
416
417#if defined(CONFIG_DEBUG_FS)
418 struct dentry *vram;
419 struct dentry *gtt;
420#endif
421
422 /* buffer handling */
423 const struct amdgpu_buffer_funcs *buffer_funcs;
424 struct amdgpu_ring *buffer_funcs_ring;
Christian König703297c2016-02-10 14:20:50 +0100425 /* Scheduler entity for buffer moves */
426 struct amd_sched_entity entity;
Christian König29b32592016-04-15 17:19:16 +0200427
428 /* custom LRU management */
429 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE];
Alex Deucher97b2e202015-04-20 16:51:00 -0400430};
431
432int amdgpu_copy_buffer(struct amdgpu_ring *ring,
433 uint64_t src_offset,
434 uint64_t dst_offset,
435 uint32_t byte_count,
436 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800437 struct fence **fence);
Flora Cui59b4a972016-07-19 16:48:22 +0800438int amdgpu_fill_buffer(struct amdgpu_bo *bo,
439 uint32_t src_data,
440 struct reservation_object *resv,
441 struct fence **fence);
442
Alex Deucher97b2e202015-04-20 16:51:00 -0400443int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
444
445struct amdgpu_bo_list_entry {
446 struct amdgpu_bo *robj;
447 struct ttm_validate_buffer tv;
448 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400449 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100450 struct page **user_pages;
451 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400452};
453
454struct amdgpu_bo_va_mapping {
455 struct list_head list;
456 struct interval_tree_node it;
457 uint64_t offset;
458 uint32_t flags;
459};
460
461/* bo virtual addresses in a specific vm */
462struct amdgpu_bo_va {
463 /* protected by bo being reserved */
464 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800465 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400466 unsigned ref_count;
467
Christian König7fc11952015-07-30 11:53:42 +0200468 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400469 struct list_head vm_status;
470
Christian König7fc11952015-07-30 11:53:42 +0200471 /* mappings for this bo_va */
472 struct list_head invalids;
473 struct list_head valids;
474
Alex Deucher97b2e202015-04-20 16:51:00 -0400475 /* constant after initialization */
476 struct amdgpu_vm *vm;
477 struct amdgpu_bo *bo;
478};
479
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800480#define AMDGPU_GEM_DOMAIN_MAX 0x3
481
Chunming Zhou478feaf2016-08-04 15:47:50 +0800482enum amdgpu_bo_shadow {
483 AMDGPU_BO_SHADOW_TO_NONE = 0,
484 AMDGPU_BO_SHADOW_TO_PARENT,
485 AMDGPU_BO_SHADOW_TO_SHADOW,
486};
487
Alex Deucher97b2e202015-04-20 16:51:00 -0400488struct amdgpu_bo {
489 /* Protected by gem.mutex */
490 struct list_head list;
491 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100492 u32 prefered_domains;
493 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800494 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400495 struct ttm_placement placement;
496 struct ttm_buffer_object tbo;
497 struct ttm_bo_kmap_obj kmap;
498 u64 flags;
499 unsigned pin_count;
500 void *kptr;
501 u64 tiling_flags;
502 u64 metadata_flags;
503 void *metadata;
504 u32 metadata_size;
505 /* list of all virtual address to which this bo
506 * is associated to
507 */
508 struct list_head va;
509 /* Constant after initialization */
510 struct amdgpu_device *adev;
511 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100512 struct amdgpu_bo *parent;
Chunming Zhoue7893c42016-07-26 14:13:21 +0800513 struct amdgpu_bo *shadow;
Chunming Zhou478feaf2016-08-04 15:47:50 +0800514 /* indicate if need to sync between bo and shadow */
515 enum amdgpu_bo_shadow backup_shadow;
Alex Deucher97b2e202015-04-20 16:51:00 -0400516
517 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400518 struct amdgpu_mn *mn;
519 struct list_head mn_list;
520};
521#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
522
523void amdgpu_gem_object_free(struct drm_gem_object *obj);
524int amdgpu_gem_object_open(struct drm_gem_object *obj,
525 struct drm_file *file_priv);
526void amdgpu_gem_object_close(struct drm_gem_object *obj,
527 struct drm_file *file_priv);
528unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
529struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200530struct drm_gem_object *
531amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
532 struct dma_buf_attachment *attach,
533 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400534struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
535 struct drm_gem_object *gobj,
536 int flags);
537int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
538void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
539struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
540void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
541void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
542int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
543
544/* sub-allocation manager, it has to be protected by another lock.
545 * By conception this is an helper for other part of the driver
546 * like the indirect buffer or semaphore, which both have their
547 * locking.
548 *
549 * Principe is simple, we keep a list of sub allocation in offset
550 * order (first entry has offset == 0, last entry has the highest
551 * offset).
552 *
553 * When allocating new object we first check if there is room at
554 * the end total_size - (last_object_offset + last_object_size) >=
555 * alloc_size. If so we allocate new object there.
556 *
557 * When there is not enough room at the end, we start waiting for
558 * each sub object until we reach object_offset+object_size >=
559 * alloc_size, this object then become the sub object we return.
560 *
561 * Alignment can't be bigger than page size.
562 *
563 * Hole are not considered for allocation to keep things simple.
564 * Assumption is that there won't be hole (all object on same
565 * alignment).
566 */
Christian König6ba60b82016-03-11 14:50:08 +0100567
568#define AMDGPU_SA_NUM_FENCE_LISTS 32
569
Alex Deucher97b2e202015-04-20 16:51:00 -0400570struct amdgpu_sa_manager {
571 wait_queue_head_t wq;
572 struct amdgpu_bo *bo;
573 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100574 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400575 struct list_head olist;
576 unsigned size;
577 uint64_t gpu_addr;
578 void *cpu_ptr;
579 uint32_t domain;
580 uint32_t align;
581};
582
Alex Deucher97b2e202015-04-20 16:51:00 -0400583/* sub-allocation buffer */
584struct amdgpu_sa_bo {
585 struct list_head olist;
586 struct list_head flist;
587 struct amdgpu_sa_manager *manager;
588 unsigned soffset;
589 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800590 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400591};
592
593/*
594 * GEM objects.
595 */
Christian König418aa0c2016-02-15 16:59:57 +0100596void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400597int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
598 int alignment, u32 initial_domain,
599 u64 flags, bool kernel,
600 struct drm_gem_object **obj);
601
602int amdgpu_mode_dumb_create(struct drm_file *file_priv,
603 struct drm_device *dev,
604 struct drm_mode_create_dumb *args);
605int amdgpu_mode_dumb_mmap(struct drm_file *filp,
606 struct drm_device *dev,
607 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400608/*
609 * Synchronization
610 */
611struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800612 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800613 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400614};
615
616void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200617int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
618 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400619int amdgpu_sync_resv(struct amdgpu_device *adev,
620 struct amdgpu_sync *sync,
621 struct reservation_object *resv,
622 void *owner);
Christian König1fbb2e92016-06-01 10:47:36 +0200623struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
624 struct amdgpu_ring *ring);
Christian Könige61235d2015-08-25 11:05:36 +0200625struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100626void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100627int amdgpu_sync_init(void);
628void amdgpu_sync_fini(void);
Rex Zhud573de22016-05-12 13:27:28 +0800629int amdgpu_fence_slab_init(void);
630void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400631
632/*
633 * GART structures, functions & helpers
634 */
635struct amdgpu_mc;
636
637#define AMDGPU_GPU_PAGE_SIZE 4096
638#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
639#define AMDGPU_GPU_PAGE_SHIFT 12
640#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
641
642struct amdgpu_gart {
643 dma_addr_t table_addr;
644 struct amdgpu_bo *robj;
645 void *ptr;
646 unsigned num_gpu_pages;
647 unsigned num_cpu_pages;
648 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200649#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400650 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200651#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400652 bool ready;
653 const struct amdgpu_gart_funcs *gart_funcs;
654};
655
656int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
657void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
658int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
659void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
660int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
661void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
662int amdgpu_gart_init(struct amdgpu_device *adev);
663void amdgpu_gart_fini(struct amdgpu_device *adev);
664void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
665 int pages);
666int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
667 int pages, struct page **pagelist,
668 dma_addr_t *dma_addr, uint32_t flags);
669
670/*
671 * GPU MC structures, functions & helpers
672 */
673struct amdgpu_mc {
674 resource_size_t aper_size;
675 resource_size_t aper_base;
676 resource_size_t agp_base;
677 /* for some chips with <= 32MB we need to lie
678 * about vram size near mc fb location */
679 u64 mc_vram_size;
680 u64 visible_vram_size;
681 u64 gtt_size;
682 u64 gtt_start;
683 u64 gtt_end;
684 u64 vram_start;
685 u64 vram_end;
686 unsigned vram_width;
687 u64 real_vram_size;
688 int vram_mtrr;
689 u64 gtt_base_align;
690 u64 mc_mask;
691 const struct firmware *fw; /* MC firmware */
692 uint32_t fw_version;
693 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800694 uint32_t vram_type;
Chunming Zhou50b01972016-07-18 16:59:24 +0800695 uint32_t srbm_soft_reset;
696 struct amdgpu_mode_mc_save save;
Alex Deucher97b2e202015-04-20 16:51:00 -0400697};
698
699/*
700 * GPU doorbell structures, functions & helpers
701 */
702typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
703{
704 AMDGPU_DOORBELL_KIQ = 0x000,
705 AMDGPU_DOORBELL_HIQ = 0x001,
706 AMDGPU_DOORBELL_DIQ = 0x002,
707 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
708 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
709 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
710 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
711 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
712 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
713 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
714 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
715 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
716 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
717 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
718 AMDGPU_DOORBELL_IH = 0x1E8,
719 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
720 AMDGPU_DOORBELL_INVALID = 0xFFFF
721} AMDGPU_DOORBELL_ASSIGNMENT;
722
723struct amdgpu_doorbell {
724 /* doorbell mmio */
725 resource_size_t base;
726 resource_size_t size;
727 u32 __iomem *ptr;
728 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
729};
730
731void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
732 phys_addr_t *aperture_base,
733 size_t *aperture_size,
734 size_t *start_offset);
735
736/*
737 * IRQS.
738 */
739
740struct amdgpu_flip_work {
Michel Dänzer325cbba2016-08-04 12:39:37 +0900741 struct delayed_work flip_work;
Alex Deucher97b2e202015-04-20 16:51:00 -0400742 struct work_struct unpin_work;
743 struct amdgpu_device *adev;
744 int crtc_id;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900745 u32 target_vblank;
Alex Deucher97b2e202015-04-20 16:51:00 -0400746 uint64_t base;
747 struct drm_pending_vblank_event *event;
748 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200749 struct fence *excl;
750 unsigned shared_count;
751 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100752 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400753 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400754};
755
756
757/*
758 * CP & rings.
759 */
760
761struct amdgpu_ib {
762 struct amdgpu_sa_bo *sa_bo;
763 uint32_t length_dw;
764 uint64_t gpu_addr;
765 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800766 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400767};
768
769enum amdgpu_ring_type {
770 AMDGPU_RING_TYPE_GFX,
771 AMDGPU_RING_TYPE_COMPUTE,
772 AMDGPU_RING_TYPE_SDMA,
773 AMDGPU_RING_TYPE_UVD,
774 AMDGPU_RING_TYPE_VCE
775};
776
Nils Wallménius62250a92016-04-10 16:30:00 +0200777extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800778
Christian König50838c82016-02-03 13:44:52 +0100779int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800780 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100781int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
782 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800783
Christian Königa5fb4ec2016-06-29 15:10:31 +0200784void amdgpu_job_free_resources(struct amdgpu_job *job);
Christian König50838c82016-02-03 13:44:52 +0100785void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100786int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100787 struct amd_sched_entity *entity, void *owner,
788 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800789
Alex Deucher97b2e202015-04-20 16:51:00 -0400790struct amdgpu_ring {
791 struct amdgpu_device *adev;
792 const struct amdgpu_ring_funcs *funcs;
793 struct amdgpu_fence_driver fence_drv;
Christian Königedf600d2016-05-03 15:54:54 +0200794 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400795
Alex Deucher97b2e202015-04-20 16:51:00 -0400796 struct amdgpu_bo *ring_obj;
797 volatile uint32_t *ring;
798 unsigned rptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400799 unsigned wptr;
800 unsigned wptr_old;
801 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100802 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400803 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400804 uint64_t gpu_addr;
805 uint32_t align_mask;
806 uint32_t ptr_mask;
807 bool ready;
808 u32 nop;
809 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400810 u32 me;
811 u32 pipe;
812 u32 queue;
813 struct amdgpu_bo *mqd_obj;
814 u32 doorbell_index;
815 bool use_doorbell;
816 unsigned wptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400817 unsigned fence_offs;
Christian Königaa3b73f2016-05-03 15:17:40 +0200818 uint64_t current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400819 enum amdgpu_ring_type type;
820 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800821 unsigned cond_exe_offs;
Christian König92c023c2016-07-19 14:34:17 +0200822 u64 cond_exe_gpu_addr;
823 volatile u32 *cond_exe_cpu_addr;
Monk Liua909c6b2016-06-14 12:02:21 -0400824#if defined(CONFIG_DEBUG_FS)
825 struct dentry *ent;
826#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400827};
828
829/*
830 * VM
831 */
832
833/* maximum number of VMIDs */
834#define AMDGPU_NUM_VM 16
835
Christian König96105e52016-08-12 12:59:59 +0200836/* Maximum number of PTEs the hardware can write with one command */
837#define AMDGPU_VM_MAX_UPDATE_SIZE 0x3FFFF
838
Alex Deucher97b2e202015-04-20 16:51:00 -0400839/* number of entries in page table */
840#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
841
842/* PTBs (Page Table Blocks) need to be aligned to 32K */
843#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
Alex Deucher97b2e202015-04-20 16:51:00 -0400844
Christian König1303c732016-08-03 17:46:42 +0200845/* LOG2 number of continuous pages for the fragment field */
846#define AMDGPU_LOG2_PAGES_PER_FRAG 4
847
Alex Deucher97b2e202015-04-20 16:51:00 -0400848#define AMDGPU_PTE_VALID (1 << 0)
849#define AMDGPU_PTE_SYSTEM (1 << 1)
850#define AMDGPU_PTE_SNOOPED (1 << 2)
851
852/* VI only */
853#define AMDGPU_PTE_EXECUTABLE (1 << 4)
854
855#define AMDGPU_PTE_READABLE (1 << 5)
856#define AMDGPU_PTE_WRITEABLE (1 << 6)
857
Christian König1303c732016-08-03 17:46:42 +0200858#define AMDGPU_PTE_FRAG(x) ((x & 0x1f) << 7)
Alex Deucher97b2e202015-04-20 16:51:00 -0400859
Christian Königd9c13152015-09-28 12:31:26 +0200860/* How to programm VM fault handling */
861#define AMDGPU_VM_FAULT_STOP_NEVER 0
862#define AMDGPU_VM_FAULT_STOP_FIRST 1
863#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
864
Alex Deucher97b2e202015-04-20 16:51:00 -0400865struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100866 struct amdgpu_bo_list_entry entry;
867 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400868};
869
Alex Deucher97b2e202015-04-20 16:51:00 -0400870struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100871 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400872 struct rb_root va;
873
Christian König7fc11952015-07-30 11:53:42 +0200874 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400875 spinlock_t status_lock;
876
877 /* BOs moved, but not yet updated in the PT */
878 struct list_head invalidated;
879
Christian König7fc11952015-07-30 11:53:42 +0200880 /* BOs cleared in the PT because of a move */
881 struct list_head cleared;
882
883 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400884 struct list_head freed;
885
886 /* contains the page directory */
887 struct amdgpu_bo *page_directory;
888 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200889 struct fence *page_directory_fence;
Christian König5a712a82016-06-21 16:28:15 +0200890 uint64_t last_eviction_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400891
892 /* array of page tables, one for each page directory entry */
893 struct amdgpu_vm_pt *page_tables;
894
895 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100896 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100897
jimqu81d75a32015-12-04 17:17:00 +0800898 /* protecting freed */
899 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100900
901 /* Scheduler entity for page table updates */
902 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800903
904 /* client id */
905 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400906};
907
Christian Königbcb1ba32016-03-08 15:40:11 +0100908struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100909 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100910 struct fence *first;
911 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100912 struct fence *last_flush;
Christian König0ea54b92016-05-04 10:20:01 +0200913 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100914
Christian Königbcb1ba32016-03-08 15:40:11 +0100915 uint64_t pd_gpu_addr;
916 /* last flushed PD/PT update */
917 struct fence *flushed_updates;
918
Chunming Zhou6adb0512016-06-27 17:06:01 +0800919 uint32_t current_gpu_reset_count;
920
Christian König971fe9a92016-03-01 15:09:25 +0100921 uint32_t gds_base;
922 uint32_t gds_size;
923 uint32_t gws_base;
924 uint32_t gws_size;
925 uint32_t oa_base;
926 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100927};
Christian König8d0a7ce2015-11-03 20:58:50 +0100928
Christian Königa9a78b32016-01-21 10:19:11 +0100929struct amdgpu_vm_manager {
930 /* Handling of VMIDs */
931 struct mutex lock;
932 unsigned num_ids;
933 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100934 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100935
Christian König1fbb2e92016-06-01 10:47:36 +0200936 /* Handling of VM fences */
937 u64 fence_context;
938 unsigned seqno[AMDGPU_MAX_RINGS];
939
Christian König8b4fb002015-11-15 16:04:16 +0100940 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400941 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100942 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400943 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100944 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400945 /* vm pte handling */
946 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100947 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
948 unsigned vm_pte_num_rings;
949 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800950 /* client id counter */
951 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400952};
953
Christian Königa9a78b32016-01-21 10:19:11 +0100954void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100955void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100956int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
957void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100958void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
959 struct list_head *validated,
960 struct amdgpu_bo_list_entry *entry);
Christian König5a712a82016-06-21 16:28:15 +0200961void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
962 struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100963void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
964 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100965int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100966 struct amdgpu_sync *sync, struct fence *fence,
Chunming Zhoufd53be32016-07-01 17:59:01 +0800967 struct amdgpu_job *job);
968int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
Christian König971fe9a92016-03-01 15:09:25 +0100969void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian König8b4fb002015-11-15 16:04:16 +0100970int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
971 struct amdgpu_vm *vm);
972int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
973 struct amdgpu_vm *vm);
974int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
975 struct amdgpu_sync *sync);
976int amdgpu_vm_bo_update(struct amdgpu_device *adev,
977 struct amdgpu_bo_va *bo_va,
978 struct ttm_mem_reg *mem);
979void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
980 struct amdgpu_bo *bo);
981struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
982 struct amdgpu_bo *bo);
983struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
984 struct amdgpu_vm *vm,
985 struct amdgpu_bo *bo);
986int amdgpu_vm_bo_map(struct amdgpu_device *adev,
987 struct amdgpu_bo_va *bo_va,
988 uint64_t addr, uint64_t offset,
989 uint64_t size, uint32_t flags);
990int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
991 struct amdgpu_bo_va *bo_va,
992 uint64_t addr);
993void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
994 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100995
Alex Deucher97b2e202015-04-20 16:51:00 -0400996/*
997 * context related structures
998 */
999
Christian König21c16bf2015-07-07 17:24:49 +02001000struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +02001001 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +08001002 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +02001003 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +02001004};
1005
Alex Deucher97b2e202015-04-20 16:51:00 -04001006struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -04001007 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +08001008 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -04001009 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +02001010 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +08001011 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +02001012 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001013};
1014
1015struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -04001016 struct amdgpu_device *adev;
1017 struct mutex lock;
1018 /* protected by lock */
1019 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001020};
1021
Alex Deucher0b492a42015-08-16 22:48:26 -04001022struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
1023int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
1024
Christian König21c16bf2015-07-07 17:24:49 +02001025uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +02001026 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +02001027struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
1028 struct amdgpu_ring *ring, uint64_t seq);
1029
Alex Deucher0b492a42015-08-16 22:48:26 -04001030int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1031 struct drm_file *filp);
1032
Christian Königefd4ccb2015-08-04 16:20:31 +02001033void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1034void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -04001035
Alex Deucher97b2e202015-04-20 16:51:00 -04001036/*
1037 * file private structure
1038 */
1039
1040struct amdgpu_fpriv {
1041 struct amdgpu_vm vm;
1042 struct mutex bo_list_lock;
1043 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001044 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001045};
1046
1047/*
1048 * residency list
1049 */
1050
1051struct amdgpu_bo_list {
1052 struct mutex lock;
1053 struct amdgpu_bo *gds_obj;
1054 struct amdgpu_bo *gws_obj;
1055 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001056 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001057 unsigned num_entries;
1058 struct amdgpu_bo_list_entry *array;
1059};
1060
1061struct amdgpu_bo_list *
1062amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001063void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1064 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001065void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1066void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1067
1068/*
1069 * GFX stuff
1070 */
1071#include "clearstate_defs.h"
1072
Alex Deucher79e54122016-04-08 15:45:13 -04001073struct amdgpu_rlc_funcs {
1074 void (*enter_safe_mode)(struct amdgpu_device *adev);
1075 void (*exit_safe_mode)(struct amdgpu_device *adev);
1076};
1077
Alex Deucher97b2e202015-04-20 16:51:00 -04001078struct amdgpu_rlc {
1079 /* for power gating */
1080 struct amdgpu_bo *save_restore_obj;
1081 uint64_t save_restore_gpu_addr;
1082 volatile uint32_t *sr_ptr;
1083 const u32 *reg_list;
1084 u32 reg_list_size;
1085 /* for clear state */
1086 struct amdgpu_bo *clear_state_obj;
1087 uint64_t clear_state_gpu_addr;
1088 volatile uint32_t *cs_ptr;
1089 const struct cs_section_def *cs_data;
1090 u32 clear_state_size;
1091 /* for cp tables */
1092 struct amdgpu_bo *cp_table_obj;
1093 uint64_t cp_table_gpu_addr;
1094 volatile uint32_t *cp_table_ptr;
1095 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001096
1097 /* safe mode for updating CG/PG state */
1098 bool in_safe_mode;
1099 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001100
1101 /* for firmware data */
1102 u32 save_and_restore_offset;
1103 u32 clear_state_descriptor_offset;
1104 u32 avail_scratch_ram_locations;
1105 u32 reg_restore_list_size;
1106 u32 reg_list_format_start;
1107 u32 reg_list_format_separate_start;
1108 u32 starting_offsets_start;
1109 u32 reg_list_format_size_bytes;
1110 u32 reg_list_size_bytes;
1111
1112 u32 *register_list_format;
1113 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001114};
1115
1116struct amdgpu_mec {
1117 struct amdgpu_bo *hpd_eop_obj;
1118 u64 hpd_eop_gpu_addr;
1119 u32 num_pipe;
1120 u32 num_mec;
1121 u32 num_queue;
1122};
1123
1124/*
1125 * GPU scratch registers structures, functions & helpers
1126 */
1127struct amdgpu_scratch {
1128 unsigned num_reg;
1129 uint32_t reg_base;
1130 bool free[32];
1131 uint32_t reg[32];
1132};
1133
1134/*
1135 * GFX configurations
1136 */
1137struct amdgpu_gca_config {
1138 unsigned max_shader_engines;
1139 unsigned max_tile_pipes;
1140 unsigned max_cu_per_sh;
1141 unsigned max_sh_per_se;
1142 unsigned max_backends_per_se;
1143 unsigned max_texture_channel_caches;
1144 unsigned max_gprs;
1145 unsigned max_gs_threads;
1146 unsigned max_hw_contexts;
1147 unsigned sc_prim_fifo_size_frontend;
1148 unsigned sc_prim_fifo_size_backend;
1149 unsigned sc_hiz_tile_fifo_size;
1150 unsigned sc_earlyz_tile_fifo_size;
1151
1152 unsigned num_tile_pipes;
1153 unsigned backend_enable_mask;
1154 unsigned mem_max_burst_length_bytes;
1155 unsigned mem_row_size_in_kb;
1156 unsigned shader_engine_tile_size;
1157 unsigned num_gpus;
1158 unsigned multi_gpu_tile_size;
1159 unsigned mc_arb_ramcfg;
1160 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001161 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001162
1163 uint32_t tile_mode_array[32];
1164 uint32_t macrotile_mode_array[16];
1165};
1166
Alex Deucher7dae69a2016-05-03 16:25:53 -04001167struct amdgpu_cu_info {
1168 uint32_t number; /* total active CU number */
1169 uint32_t ao_cu_mask;
1170 uint32_t bitmap[4][4];
1171};
1172
Alex Deucherb95e31f2016-07-07 15:01:42 -04001173struct amdgpu_gfx_funcs {
1174 /* get the gpu clock counter */
1175 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -04001176 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Alex Deucherb95e31f2016-07-07 15:01:42 -04001177};
1178
Alex Deucher97b2e202015-04-20 16:51:00 -04001179struct 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 */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001211 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001212 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001213 unsigned ce_ram_size;
1214 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001215 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +08001216
1217 /* reset mask */
1218 uint32_t grbm_soft_reset;
1219 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001220};
1221
Christian Königb07c60c2016-01-31 12:29:04 +01001222int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001223 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001224void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1225 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001226int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001227 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001228 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001229int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1230void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1231int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001232int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001233void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001234void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001235void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001236void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001237int 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);
1242
1243/*
1244 * CS.
1245 */
1246struct amdgpu_cs_chunk {
1247 uint32_t chunk_id;
1248 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001249 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001250};
1251
1252struct amdgpu_cs_parser {
1253 struct amdgpu_device *adev;
1254 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001255 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001256
Alex Deucher97b2e202015-04-20 16:51:00 -04001257 /* chunks */
1258 unsigned nchunks;
1259 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001260
Christian König50838c82016-02-03 13:44:52 +01001261 /* scheduler job object */
1262 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001263
Christian Königc3cca412015-12-15 14:41:33 +01001264 /* buffer objects */
1265 struct ww_acquire_ctx ticket;
1266 struct amdgpu_bo_list *bo_list;
1267 struct amdgpu_bo_list_entry vm_pd;
1268 struct list_head validated;
1269 struct fence *fence;
1270 uint64_t bytes_moved_threshold;
1271 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001272
1273 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001274 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;
Christian Königedf600d2016-05-03 15:54:54 +02001280 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001281 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001282 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001283 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001284 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001285 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001286 void *owner;
Christian König92f25092016-05-06 15:57:42 +02001287 uint64_t ctx;
Chunming Zhoufd53be32016-07-01 17:59:01 +08001288 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +02001289 unsigned vm_id;
1290 uint64_t vm_pd_addr;
1291 uint32_t gds_base, gds_size;
1292 uint32_t gws_base, gws_size;
1293 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001294
1295 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +02001296 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +02001297 uint64_t uf_sequence;
1298
Chunming Zhoubb977d32015-08-18 15:16:40 +08001299};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001300#define to_amdgpu_job(sched_job) \
1301 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001302
Christian König7270f832016-01-31 11:00:41 +01001303static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1304 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001305{
Christian König50838c82016-02-03 13:44:52 +01001306 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001307}
1308
Christian König7270f832016-01-31 11:00:41 +01001309static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1310 uint32_t ib_idx, int idx,
1311 uint32_t value)
1312{
Christian König50838c82016-02-03 13:44:52 +01001313 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001314}
1315
Alex Deucher97b2e202015-04-20 16:51:00 -04001316/*
1317 * Writeback
1318 */
1319#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1320
1321struct amdgpu_wb {
1322 struct amdgpu_bo *wb_obj;
1323 volatile uint32_t *wb;
1324 uint64_t gpu_addr;
1325 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1326 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1327};
1328
1329int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1330void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1331
Alex Deucher97b2e202015-04-20 16:51:00 -04001332
Alex Deucher97b2e202015-04-20 16:51:00 -04001333
1334enum amdgpu_int_thermal_type {
1335 THERMAL_TYPE_NONE,
1336 THERMAL_TYPE_EXTERNAL,
1337 THERMAL_TYPE_EXTERNAL_GPIO,
1338 THERMAL_TYPE_RV6XX,
1339 THERMAL_TYPE_RV770,
1340 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1341 THERMAL_TYPE_EVERGREEN,
1342 THERMAL_TYPE_SUMO,
1343 THERMAL_TYPE_NI,
1344 THERMAL_TYPE_SI,
1345 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1346 THERMAL_TYPE_CI,
1347 THERMAL_TYPE_KV,
1348};
1349
1350enum amdgpu_dpm_auto_throttle_src {
1351 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1352 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1353};
1354
1355enum amdgpu_dpm_event_src {
1356 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1357 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1358 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1359 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1360 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1361};
1362
1363#define AMDGPU_MAX_VCE_LEVELS 6
1364
1365enum amdgpu_vce_level {
1366 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1367 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1368 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1369 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1370 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1371 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1372};
1373
1374struct amdgpu_ps {
1375 u32 caps; /* vbios flags */
1376 u32 class; /* vbios flags */
1377 u32 class2; /* vbios flags */
1378 /* UVD clocks */
1379 u32 vclk;
1380 u32 dclk;
1381 /* VCE clocks */
1382 u32 evclk;
1383 u32 ecclk;
1384 bool vce_active;
1385 enum amdgpu_vce_level vce_level;
1386 /* asic priv */
1387 void *ps_priv;
1388};
1389
1390struct amdgpu_dpm_thermal {
1391 /* thermal interrupt work */
1392 struct work_struct work;
1393 /* low temperature threshold */
1394 int min_temp;
1395 /* high temperature threshold */
1396 int max_temp;
1397 /* was last interrupt low to high or high to low */
1398 bool high_to_low;
1399 /* interrupt source */
1400 struct amdgpu_irq_src irq;
1401};
1402
1403enum amdgpu_clk_action
1404{
1405 AMDGPU_SCLK_UP = 1,
1406 AMDGPU_SCLK_DOWN
1407};
1408
1409struct amdgpu_blacklist_clocks
1410{
1411 u32 sclk;
1412 u32 mclk;
1413 enum amdgpu_clk_action action;
1414};
1415
1416struct amdgpu_clock_and_voltage_limits {
1417 u32 sclk;
1418 u32 mclk;
1419 u16 vddc;
1420 u16 vddci;
1421};
1422
1423struct amdgpu_clock_array {
1424 u32 count;
1425 u32 *values;
1426};
1427
1428struct amdgpu_clock_voltage_dependency_entry {
1429 u32 clk;
1430 u16 v;
1431};
1432
1433struct amdgpu_clock_voltage_dependency_table {
1434 u32 count;
1435 struct amdgpu_clock_voltage_dependency_entry *entries;
1436};
1437
1438union amdgpu_cac_leakage_entry {
1439 struct {
1440 u16 vddc;
1441 u32 leakage;
1442 };
1443 struct {
1444 u16 vddc1;
1445 u16 vddc2;
1446 u16 vddc3;
1447 };
1448};
1449
1450struct amdgpu_cac_leakage_table {
1451 u32 count;
1452 union amdgpu_cac_leakage_entry *entries;
1453};
1454
1455struct amdgpu_phase_shedding_limits_entry {
1456 u16 voltage;
1457 u32 sclk;
1458 u32 mclk;
1459};
1460
1461struct amdgpu_phase_shedding_limits_table {
1462 u32 count;
1463 struct amdgpu_phase_shedding_limits_entry *entries;
1464};
1465
1466struct amdgpu_uvd_clock_voltage_dependency_entry {
1467 u32 vclk;
1468 u32 dclk;
1469 u16 v;
1470};
1471
1472struct amdgpu_uvd_clock_voltage_dependency_table {
1473 u8 count;
1474 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1475};
1476
1477struct amdgpu_vce_clock_voltage_dependency_entry {
1478 u32 ecclk;
1479 u32 evclk;
1480 u16 v;
1481};
1482
1483struct amdgpu_vce_clock_voltage_dependency_table {
1484 u8 count;
1485 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1486};
1487
1488struct amdgpu_ppm_table {
1489 u8 ppm_design;
1490 u16 cpu_core_number;
1491 u32 platform_tdp;
1492 u32 small_ac_platform_tdp;
1493 u32 platform_tdc;
1494 u32 small_ac_platform_tdc;
1495 u32 apu_tdp;
1496 u32 dgpu_tdp;
1497 u32 dgpu_ulv_power;
1498 u32 tj_max;
1499};
1500
1501struct amdgpu_cac_tdp_table {
1502 u16 tdp;
1503 u16 configurable_tdp;
1504 u16 tdc;
1505 u16 battery_power_limit;
1506 u16 small_power_limit;
1507 u16 low_cac_leakage;
1508 u16 high_cac_leakage;
1509 u16 maximum_power_delivery_limit;
1510};
1511
1512struct amdgpu_dpm_dynamic_state {
1513 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1514 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1515 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1516 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1517 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1518 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1519 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1520 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1521 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1522 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1523 struct amdgpu_clock_array valid_sclk_values;
1524 struct amdgpu_clock_array valid_mclk_values;
1525 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1526 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1527 u32 mclk_sclk_ratio;
1528 u32 sclk_mclk_delta;
1529 u16 vddc_vddci_delta;
1530 u16 min_vddc_for_pcie_gen2;
1531 struct amdgpu_cac_leakage_table cac_leakage_table;
1532 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1533 struct amdgpu_ppm_table *ppm_table;
1534 struct amdgpu_cac_tdp_table *cac_tdp_table;
1535};
1536
1537struct amdgpu_dpm_fan {
1538 u16 t_min;
1539 u16 t_med;
1540 u16 t_high;
1541 u16 pwm_min;
1542 u16 pwm_med;
1543 u16 pwm_high;
1544 u8 t_hyst;
1545 u32 cycle_delay;
1546 u16 t_max;
1547 u8 control_mode;
1548 u16 default_max_fan_pwm;
1549 u16 default_fan_output_sensitivity;
1550 u16 fan_output_sensitivity;
1551 bool ucode_fan_control;
1552};
1553
1554enum amdgpu_pcie_gen {
1555 AMDGPU_PCIE_GEN1 = 0,
1556 AMDGPU_PCIE_GEN2 = 1,
1557 AMDGPU_PCIE_GEN3 = 2,
1558 AMDGPU_PCIE_GEN_INVALID = 0xffff
1559};
1560
1561enum amdgpu_dpm_forced_level {
1562 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1563 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1564 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001565 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001566};
1567
1568struct amdgpu_vce_state {
1569 /* vce clocks */
1570 u32 evclk;
1571 u32 ecclk;
1572 /* gpu clocks */
1573 u32 sclk;
1574 u32 mclk;
1575 u8 clk_idx;
1576 u8 pstate;
1577};
1578
1579struct amdgpu_dpm_funcs {
1580 int (*get_temperature)(struct amdgpu_device *adev);
1581 int (*pre_set_power_state)(struct amdgpu_device *adev);
1582 int (*set_power_state)(struct amdgpu_device *adev);
1583 void (*post_set_power_state)(struct amdgpu_device *adev);
1584 void (*display_configuration_changed)(struct amdgpu_device *adev);
1585 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1586 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1587 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1588 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1589 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1590 bool (*vblank_too_short)(struct amdgpu_device *adev);
1591 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001592 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001593 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1594 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1595 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1596 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1597 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001598 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1599 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001600 int (*get_sclk_od)(struct amdgpu_device *adev);
1601 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001602 int (*get_mclk_od)(struct amdgpu_device *adev);
1603 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001604};
1605
1606struct amdgpu_dpm {
1607 struct amdgpu_ps *ps;
1608 /* number of valid power states */
1609 int num_ps;
1610 /* current power state that is active */
1611 struct amdgpu_ps *current_ps;
1612 /* requested power state */
1613 struct amdgpu_ps *requested_ps;
1614 /* boot up power state */
1615 struct amdgpu_ps *boot_ps;
1616 /* default uvd power state */
1617 struct amdgpu_ps *uvd_ps;
1618 /* vce requirements */
1619 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1620 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001621 enum amd_pm_state_type state;
1622 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001623 u32 platform_caps;
1624 u32 voltage_response_time;
1625 u32 backbias_response_time;
1626 void *priv;
1627 u32 new_active_crtcs;
1628 int new_active_crtc_count;
1629 u32 current_active_crtcs;
1630 int current_active_crtc_count;
1631 struct amdgpu_dpm_dynamic_state dyn_state;
1632 struct amdgpu_dpm_fan fan;
1633 u32 tdp_limit;
1634 u32 near_tdp_limit;
1635 u32 near_tdp_limit_adjusted;
1636 u32 sq_ramping_threshold;
1637 u32 cac_leakage;
1638 u16 tdp_od_limit;
1639 u32 tdp_adjustment;
1640 u16 load_line_slope;
1641 bool power_control;
1642 bool ac_power;
1643 /* special states active */
1644 bool thermal_active;
1645 bool uvd_active;
1646 bool vce_active;
1647 /* thermal handling */
1648 struct amdgpu_dpm_thermal thermal;
1649 /* forced levels */
1650 enum amdgpu_dpm_forced_level forced_level;
1651};
1652
1653struct amdgpu_pm {
1654 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001655 u32 current_sclk;
1656 u32 current_mclk;
1657 u32 default_sclk;
1658 u32 default_mclk;
1659 struct amdgpu_i2c_chan *i2c_bus;
1660 /* internal thermal controller on rv6xx+ */
1661 enum amdgpu_int_thermal_type int_thermal_type;
1662 struct device *int_hwmon_dev;
1663 /* fan control parameters */
1664 bool no_fan;
1665 u8 fan_pulses_per_revolution;
1666 u8 fan_min_rpm;
1667 u8 fan_max_rpm;
1668 /* dpm */
1669 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001670 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001671 struct amdgpu_dpm dpm;
1672 const struct firmware *fw; /* SMC firmware */
1673 uint32_t fw_version;
1674 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001675 uint32_t pcie_gen_mask;
1676 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001677 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001678};
1679
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001680void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1681
Alex Deucher97b2e202015-04-20 16:51:00 -04001682/*
1683 * UVD
1684 */
Arindam Nathc0365542016-04-12 13:46:15 +02001685#define AMDGPU_DEFAULT_UVD_HANDLES 10
1686#define AMDGPU_MAX_UVD_HANDLES 40
1687#define AMDGPU_UVD_STACK_SIZE (200*1024)
1688#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1689#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1690#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001691
1692struct amdgpu_uvd {
1693 struct amdgpu_bo *vcpu_bo;
1694 void *cpu_addr;
1695 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001696 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001697 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001698 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001699 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1700 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1701 struct delayed_work idle_work;
1702 const struct firmware *fw; /* UVD firmware */
1703 struct amdgpu_ring ring;
1704 struct amdgpu_irq_src irq;
1705 bool address_64_bit;
Christian König4cb5877c2016-07-26 12:05:40 +02001706 bool use_ctx_buf;
Christian Königead833e2016-02-10 14:35:19 +01001707 struct amd_sched_entity entity;
Chunming Zhoufc0b3b92016-07-18 17:18:01 +08001708 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001709};
1710
1711/*
1712 * VCE
1713 */
1714#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001715#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1716
Alex Deucher6a585772015-07-10 14:16:24 -04001717#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1718#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1719
Alex Deucher97b2e202015-04-20 16:51:00 -04001720struct amdgpu_vce {
1721 struct amdgpu_bo *vcpu_bo;
1722 uint64_t gpu_addr;
1723 unsigned fw_version;
1724 unsigned fb_version;
1725 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1726 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001727 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001728 struct delayed_work idle_work;
Christian Königebff4852016-07-20 16:53:36 +02001729 struct mutex idle_mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001730 const struct firmware *fw; /* VCE firmware */
1731 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1732 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001733 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001734 struct amd_sched_entity entity;
Chunming Zhou115933a2016-07-18 17:38:50 +08001735 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001736};
1737
1738/*
1739 * SDMA
1740 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001741struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001742 /* SDMA firmware */
1743 const struct firmware *fw;
1744 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001745 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001746
1747 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001748 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001749};
1750
Alex Deucherc113ea12015-10-08 16:30:37 -04001751struct amdgpu_sdma {
1752 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1753 struct amdgpu_irq_src trap_irq;
1754 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001755 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001756 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001757};
1758
Alex Deucher97b2e202015-04-20 16:51:00 -04001759/*
1760 * Firmware
1761 */
1762struct amdgpu_firmware {
1763 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1764 bool smu_load;
1765 struct amdgpu_bo *fw_buf;
1766 unsigned int fw_size;
1767};
1768
1769/*
1770 * Benchmarking
1771 */
1772void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1773
1774
1775/*
1776 * Testing
1777 */
1778void amdgpu_test_moves(struct amdgpu_device *adev);
1779void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1780 struct amdgpu_ring *cpA,
1781 struct amdgpu_ring *cpB);
1782void amdgpu_test_syncing(struct amdgpu_device *adev);
1783
1784/*
1785 * MMU Notifier
1786 */
1787#if defined(CONFIG_MMU_NOTIFIER)
1788int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1789void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1790#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001791static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001792{
1793 return -ENODEV;
1794}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001795static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001796#endif
1797
1798/*
1799 * Debugfs
1800 */
1801struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001802 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001803 unsigned num_files;
1804};
1805
1806int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001807 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001808 unsigned nfiles);
1809int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1810
1811#if defined(CONFIG_DEBUG_FS)
1812int amdgpu_debugfs_init(struct drm_minor *minor);
1813void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1814#endif
1815
Huang Rui50ab2532016-06-12 15:51:09 +08001816int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1817
Alex Deucher97b2e202015-04-20 16:51:00 -04001818/*
1819 * amdgpu smumgr functions
1820 */
1821struct amdgpu_smumgr_funcs {
1822 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1823 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1824 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1825};
1826
1827/*
1828 * amdgpu smumgr
1829 */
1830struct amdgpu_smumgr {
1831 struct amdgpu_bo *toc_buf;
1832 struct amdgpu_bo *smu_buf;
1833 /* asic priv smu data */
1834 void *priv;
1835 spinlock_t smu_lock;
1836 /* smumgr functions */
1837 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1838 /* ucode loading complete flag */
1839 uint32_t fw_flags;
1840};
1841
1842/*
1843 * ASIC specific register table accessible by UMD
1844 */
1845struct amdgpu_allowed_register_entry {
1846 uint32_t reg_offset;
1847 bool untouched;
1848 bool grbm_indexed;
1849};
1850
Alex Deucher97b2e202015-04-20 16:51:00 -04001851/*
1852 * ASIC specific functions.
1853 */
1854struct amdgpu_asic_funcs {
1855 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001856 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1857 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001858 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1859 u32 sh_num, u32 reg_offset, u32 *value);
1860 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1861 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001862 /* get the reference clock */
1863 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001864 /* MM block clocks */
1865 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1866 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Andres Rodriguez048765a2016-06-11 02:51:32 -04001867 /* query virtual capabilities */
1868 u32 (*get_virtual_caps)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001869};
1870
1871/*
1872 * IOCTL.
1873 */
1874int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1875 struct drm_file *filp);
1876int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1877 struct drm_file *filp);
1878
1879int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1880 struct drm_file *filp);
1881int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1882 struct drm_file *filp);
1883int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1884 struct drm_file *filp);
1885int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1886 struct drm_file *filp);
1887int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1888 struct drm_file *filp);
1889int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1890 struct drm_file *filp);
1891int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1892int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1893
1894int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1895 struct drm_file *filp);
1896
1897/* VRAM scratch page for HDP bug, default vram page */
1898struct amdgpu_vram_scratch {
1899 struct amdgpu_bo *robj;
1900 volatile uint32_t *ptr;
1901 u64 gpu_addr;
1902};
1903
1904/*
1905 * ACPI
1906 */
1907struct amdgpu_atif_notification_cfg {
1908 bool enabled;
1909 int command_code;
1910};
1911
1912struct amdgpu_atif_notifications {
1913 bool display_switch;
1914 bool expansion_mode_change;
1915 bool thermal_state;
1916 bool forced_power_state;
1917 bool system_power_state;
1918 bool display_conf_change;
1919 bool px_gfx_switch;
1920 bool brightness_change;
1921 bool dgpu_display_event;
1922};
1923
1924struct amdgpu_atif_functions {
1925 bool system_params;
1926 bool sbios_requests;
1927 bool select_active_disp;
1928 bool lid_state;
1929 bool get_tv_standard;
1930 bool set_tv_standard;
1931 bool get_panel_expansion_mode;
1932 bool set_panel_expansion_mode;
1933 bool temperature_change;
1934 bool graphics_device_types;
1935};
1936
1937struct amdgpu_atif {
1938 struct amdgpu_atif_notifications notifications;
1939 struct amdgpu_atif_functions functions;
1940 struct amdgpu_atif_notification_cfg notification_cfg;
1941 struct amdgpu_encoder *encoder_for_bl;
1942};
1943
1944struct amdgpu_atcs_functions {
1945 bool get_ext_state;
1946 bool pcie_perf_req;
1947 bool pcie_dev_rdy;
1948 bool pcie_bus_width;
1949};
1950
1951struct amdgpu_atcs {
1952 struct amdgpu_atcs_functions functions;
1953};
1954
Alex Deucher97b2e202015-04-20 16:51:00 -04001955/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001956 * CGS
1957 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001958struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1959void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001960
1961
Alex Deucher7e471e62016-02-01 11:13:04 -05001962/* GPU virtualization */
Andres Rodriguez048765a2016-06-11 02:51:32 -04001963#define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0)
1964#define AMDGPU_VIRT_CAPS_IS_VF (1 << 1)
Alex Deucher7e471e62016-02-01 11:13:04 -05001965struct amdgpu_virtualization {
1966 bool supports_sr_iov;
Andres Rodriguez048765a2016-06-11 02:51:32 -04001967 bool is_virtual;
1968 u32 caps;
Alex Deucher7e471e62016-02-01 11:13:04 -05001969};
1970
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001971/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001972 * Core structure, functions and helpers.
1973 */
1974typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1975typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1976
1977typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1978typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1979
Alex Deucher8faf0e02015-07-28 11:50:31 -04001980struct amdgpu_ip_block_status {
1981 bool valid;
1982 bool sw;
1983 bool hw;
Chunming Zhou63fbf422016-07-15 11:19:20 +08001984 bool hang;
Alex Deucher8faf0e02015-07-28 11:50:31 -04001985};
1986
Alex Deucher97b2e202015-04-20 16:51:00 -04001987struct amdgpu_device {
1988 struct device *dev;
1989 struct drm_device *ddev;
1990 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001991
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001992#ifdef CONFIG_DRM_AMD_ACP
1993 struct amdgpu_acp acp;
1994#endif
1995
Alex Deucher97b2e202015-04-20 16:51:00 -04001996 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001997 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001998 uint32_t family;
1999 uint32_t rev_id;
2000 uint32_t external_rev_id;
2001 unsigned long flags;
2002 int usec_timeout;
2003 const struct amdgpu_asic_funcs *asic_funcs;
2004 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04002005 bool need_dma32;
2006 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02002007 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04002008 struct notifier_block acpi_nb;
2009 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
2010 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02002011 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04002012#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04002013 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04002014#endif
2015 struct amdgpu_atif atif;
2016 struct amdgpu_atcs atcs;
2017 struct mutex srbm_mutex;
2018 /* GRBM index mutex. Protects concurrent access to GRBM index */
2019 struct mutex grbm_idx_mutex;
2020 struct dev_pm_domain vga_pm_domain;
2021 bool have_disp_power_ref;
2022
2023 /* BIOS */
2024 uint8_t *bios;
2025 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04002026 struct amdgpu_bo *stollen_vga_memory;
2027 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
2028
2029 /* Register/doorbell mmio */
2030 resource_size_t rmmio_base;
2031 resource_size_t rmmio_size;
2032 void __iomem *rmmio;
2033 /* protects concurrent MM_INDEX/DATA based register access */
2034 spinlock_t mmio_idx_lock;
2035 /* protects concurrent SMC based register access */
2036 spinlock_t smc_idx_lock;
2037 amdgpu_rreg_t smc_rreg;
2038 amdgpu_wreg_t smc_wreg;
2039 /* protects concurrent PCIE register access */
2040 spinlock_t pcie_idx_lock;
2041 amdgpu_rreg_t pcie_rreg;
2042 amdgpu_wreg_t pcie_wreg;
2043 /* protects concurrent UVD register access */
2044 spinlock_t uvd_ctx_idx_lock;
2045 amdgpu_rreg_t uvd_ctx_rreg;
2046 amdgpu_wreg_t uvd_ctx_wreg;
2047 /* protects concurrent DIDT register access */
2048 spinlock_t didt_idx_lock;
2049 amdgpu_rreg_t didt_rreg;
2050 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08002051 /* protects concurrent gc_cac register access */
2052 spinlock_t gc_cac_idx_lock;
2053 amdgpu_rreg_t gc_cac_rreg;
2054 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04002055 /* protects concurrent ENDPOINT (audio) register access */
2056 spinlock_t audio_endpt_idx_lock;
2057 amdgpu_block_rreg_t audio_endpt_rreg;
2058 amdgpu_block_wreg_t audio_endpt_wreg;
2059 void __iomem *rio_mem;
2060 resource_size_t rio_mem_size;
2061 struct amdgpu_doorbell doorbell;
2062
2063 /* clock/pll info */
2064 struct amdgpu_clock clock;
2065
2066 /* MC */
2067 struct amdgpu_mc mc;
2068 struct amdgpu_gart gart;
2069 struct amdgpu_dummy_page dummy_page;
2070 struct amdgpu_vm_manager vm_manager;
2071
2072 /* memory management */
2073 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002074 struct amdgpu_vram_scratch vram_scratch;
2075 struct amdgpu_wb wb;
2076 atomic64_t vram_usage;
2077 atomic64_t vram_vis_usage;
2078 atomic64_t gtt_usage;
2079 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02002080 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02002081 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002082
2083 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08002084 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04002085 struct amdgpu_mode_info mode_info;
2086 struct work_struct hotplug_work;
2087 struct amdgpu_irq_src crtc_irq;
2088 struct amdgpu_irq_src pageflip_irq;
2089 struct amdgpu_irq_src hpd_irq;
2090
2091 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02002092 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002093 unsigned num_rings;
2094 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2095 bool ib_pool_ready;
2096 struct amdgpu_sa_manager ring_tmp_bo;
2097
2098 /* interrupts */
2099 struct amdgpu_irq irq;
2100
Alex Deucher1f7371b2015-12-02 17:46:21 -05002101 /* powerplay */
2102 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002103 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002104 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002105
Alex Deucher97b2e202015-04-20 16:51:00 -04002106 /* dpm */
2107 struct amdgpu_pm pm;
2108 u32 cg_flags;
2109 u32 pg_flags;
2110
2111 /* amdgpu smumgr */
2112 struct amdgpu_smumgr smu;
2113
2114 /* gfx */
2115 struct amdgpu_gfx gfx;
2116
2117 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002118 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002119
2120 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002121 struct amdgpu_uvd uvd;
2122
2123 /* vce */
2124 struct amdgpu_vce vce;
2125
2126 /* firmwares */
2127 struct amdgpu_firmware firmware;
2128
2129 /* GDS */
2130 struct amdgpu_gds gds;
2131
2132 const struct amdgpu_ip_block_version *ip_blocks;
2133 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002134 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002135 struct mutex mn_lock;
2136 DECLARE_HASHTABLE(mn_hash, 7);
2137
2138 /* tracking pinned memory */
2139 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002140 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002141 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002142
2143 /* amdkfd interface */
2144 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002145
Alex Deucher7e471e62016-02-01 11:13:04 -05002146 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002147};
2148
2149bool amdgpu_device_is_px(struct drm_device *dev);
2150int amdgpu_device_init(struct amdgpu_device *adev,
2151 struct drm_device *ddev,
2152 struct pci_dev *pdev,
2153 uint32_t flags);
2154void amdgpu_device_fini(struct amdgpu_device *adev);
2155int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2156
2157uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2158 bool always_indirect);
2159void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2160 bool always_indirect);
2161u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2162void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2163
2164u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2165void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2166
2167/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002168 * Registers read & write functions.
2169 */
2170#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2171#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2172#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2173#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2174#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2175#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2176#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2177#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2178#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2179#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2180#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2181#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2182#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2183#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2184#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08002185#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
2186#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04002187#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2188#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2189#define WREG32_P(reg, val, mask) \
2190 do { \
2191 uint32_t tmp_ = RREG32(reg); \
2192 tmp_ &= (mask); \
2193 tmp_ |= ((val) & ~(mask)); \
2194 WREG32(reg, tmp_); \
2195 } while (0)
2196#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2197#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2198#define WREG32_PLL_P(reg, val, mask) \
2199 do { \
2200 uint32_t tmp_ = RREG32_PLL(reg); \
2201 tmp_ &= (mask); \
2202 tmp_ |= ((val) & ~(mask)); \
2203 WREG32_PLL(reg, tmp_); \
2204 } while (0)
2205#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2206#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2207#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2208
2209#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2210#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2211
2212#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2213#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2214
2215#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2216 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2217 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2218
2219#define REG_GET_FIELD(value, reg, field) \
2220 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2221
Tom St Denis61cb8ce2016-08-09 10:13:21 -04002222#define WREG32_FIELD(reg, field, val) \
2223 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
2224
Alex Deucher97b2e202015-04-20 16:51:00 -04002225/*
2226 * BIOS helpers.
2227 */
2228#define RBIOS8(i) (adev->bios[i])
2229#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2230#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2231
2232/*
2233 * RING helpers.
2234 */
2235static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2236{
2237 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002238 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002239 ring->ring[ring->wptr++] = v;
2240 ring->wptr &= ring->ptr_mask;
2241 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002242}
2243
Alex Deucherc113ea12015-10-08 16:30:37 -04002244static inline struct amdgpu_sdma_instance *
2245amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002246{
2247 struct amdgpu_device *adev = ring->adev;
2248 int i;
2249
Alex Deucherc113ea12015-10-08 16:30:37 -04002250 for (i = 0; i < adev->sdma.num_instances; i++)
2251 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002252 break;
2253
2254 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002255 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002256 else
2257 return NULL;
2258}
2259
Alex Deucher97b2e202015-04-20 16:51:00 -04002260/*
2261 * ASICs macro.
2262 */
2263#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2264#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002265#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2266#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2267#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
Andres Rodriguez048765a2016-06-11 02:51:32 -04002268#define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002269#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002270#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 -04002271#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002272#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2273#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2274#define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Christian Königde9ea7b2016-08-12 11:33:30 +02002275#define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002276#define amdgpu_vm_set_pte_pde(adev, ib, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->set_pte_pde((ib), (pe), (addr), (count), (incr), (flags)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002277#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2278#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02002279#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04002280#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2281#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2282#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002283#define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
Christian Königb8c7b392016-03-01 15:42:52 +01002284#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002285#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002286#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002287#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 +02002288#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002289#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002290#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002291#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2292#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04002293#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2294#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2295#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2296#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2297#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2298#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2299#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2300#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2301#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2302#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2303#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2304#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2305#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002306#define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
Alex Deucher97b2e202015-04-20 16:51:00 -04002307#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2308#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2309#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))
2310#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2311#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002312#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 +08002313#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 -04002314#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2315#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2316#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2317#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002318#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002319#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002320#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04002321#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04002322#define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
Rex Zhu3af76f22015-10-15 17:23:43 +08002323
2324#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002325 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002326 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002327 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002328
2329#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002330 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002331 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002332 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002333
2334#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002335 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002336 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002337 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002338
2339#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002340 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002341 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002342 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002343
2344#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002345 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002346 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002347 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002348
Rex Zhu1b5708f2015-11-10 18:25:24 -05002349#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002350 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002351 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002352 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002353
2354#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002355 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002356 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002357 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002358
2359
2360#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002361 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002362 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002363 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002364
2365#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002366 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002367 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002368 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002369
2370#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002371 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002372 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002373 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002374
2375#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002376 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002377 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002378 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002379
2380#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002381 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002382
2383#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002384 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002385
Eric Huangf3898ea2015-12-11 16:24:34 -05002386#define amdgpu_dpm_get_pp_num_states(adev, data) \
2387 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2388
2389#define amdgpu_dpm_get_pp_table(adev, table) \
2390 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2391
2392#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2393 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2394
2395#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2396 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2397
2398#define amdgpu_dpm_force_clock_level(adev, type, level) \
2399 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2400
Eric Huang428bafa2016-05-12 14:51:21 -04002401#define amdgpu_dpm_get_sclk_od(adev) \
2402 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2403
2404#define amdgpu_dpm_set_sclk_od(adev, value) \
2405 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2406
Eric Huangf2bdc052016-05-24 15:11:17 -04002407#define amdgpu_dpm_get_mclk_od(adev) \
2408 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2409
2410#define amdgpu_dpm_set_mclk_od(adev, value) \
2411 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2412
Jammy Zhoue61710c2015-11-10 18:31:08 -05002413#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002414 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002415
2416#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2417
2418/* Common functions */
2419int amdgpu_gpu_reset(struct amdgpu_device *adev);
2420void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2421bool amdgpu_card_posted(struct amdgpu_device *adev);
2422void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002423
Alex Deucher97b2e202015-04-20 16:51:00 -04002424int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2425int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2426 u32 ip_instance, u32 ring,
2427 struct amdgpu_ring **out_ring);
2428void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2429bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002430int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002431int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2432 uint32_t flags);
2433bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002434struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002435bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2436 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002437bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2438 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002439bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2440uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2441 struct ttm_mem_reg *mem);
2442void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2443void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2444void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Ken Wanga693e052016-07-27 19:18:01 +08002445u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2446int amdgpu_ttm_global_init(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002447void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2448 const u32 *registers,
2449 const u32 array_size);
2450
2451bool amdgpu_device_is_px(struct drm_device *dev);
2452/* atpx handler */
2453#if defined(CONFIG_VGA_SWITCHEROO)
2454void amdgpu_register_atpx_handler(void);
2455void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002456bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002457bool amdgpu_is_atpx_hybrid(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002458#else
2459static inline void amdgpu_register_atpx_handler(void) {}
2460static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002461static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002462static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002463#endif
2464
2465/*
2466 * KMS
2467 */
2468extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002469extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002470
2471int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2472int amdgpu_driver_unload_kms(struct drm_device *dev);
2473void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2474int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2475void amdgpu_driver_postclose_kms(struct drm_device *dev,
2476 struct drm_file *file_priv);
2477void amdgpu_driver_preclose_kms(struct drm_device *dev,
2478 struct drm_file *file_priv);
2479int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2480int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002481u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2482int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2483void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2484int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002485 int *max_error,
2486 struct timeval *vblank_time,
2487 unsigned flags);
2488long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2489 unsigned long arg);
2490
2491/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002492 * functions used by amdgpu_encoder.c
2493 */
2494struct amdgpu_afmt_acr {
2495 u32 clock;
2496
2497 int n_32khz;
2498 int cts_32khz;
2499
2500 int n_44_1khz;
2501 int cts_44_1khz;
2502
2503 int n_48khz;
2504 int cts_48khz;
2505
2506};
2507
2508struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2509
2510/* amdgpu_acpi.c */
2511#if defined(CONFIG_ACPI)
2512int amdgpu_acpi_init(struct amdgpu_device *adev);
2513void amdgpu_acpi_fini(struct amdgpu_device *adev);
2514bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2515int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2516 u8 perf_req, bool advertise);
2517int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2518#else
2519static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2520static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2521#endif
2522
2523struct amdgpu_bo_va_mapping *
2524amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2525 uint64_t addr, struct amdgpu_bo **bo);
2526
2527#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002528#endif