blob: 2a009c398dcb539b91507e8bad3297c35d8a3eba [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;
Alex Deuchercd474ba2016-02-04 10:21:23 -050088extern unsigned amdgpu_pcie_gen_cap;
89extern unsigned amdgpu_pcie_lane_cap;
Alex Deucher97b2e202015-04-20 16:51:00 -040090
Chunming Zhou4b559c92015-07-21 15:53:04 +080091#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -040092#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
93#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
94/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
95#define AMDGPU_IB_POOL_SIZE 16
96#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
97#define AMDGPUFB_CONN_LIMIT 4
98#define AMDGPU_BIOS_NUM_SCRATCH 8
99
Alex Deucher97b2e202015-04-20 16:51:00 -0400100/* max number of rings */
101#define AMDGPU_MAX_RINGS 16
102#define AMDGPU_MAX_GFX_RINGS 1
103#define AMDGPU_MAX_COMPUTE_RINGS 8
104#define AMDGPU_MAX_VCE_RINGS 2
105
Jammy Zhou36f523a2015-09-01 12:54:27 +0800106/* max number of IP instances */
107#define AMDGPU_MAX_SDMA_INSTANCES 2
108
Alex Deucher97b2e202015-04-20 16:51:00 -0400109/* hardcode that limit for now */
110#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
111
112/* hard reset data */
113#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
114
115/* reset flags */
116#define AMDGPU_RESET_GFX (1 << 0)
117#define AMDGPU_RESET_COMPUTE (1 << 1)
118#define AMDGPU_RESET_DMA (1 << 2)
119#define AMDGPU_RESET_CP (1 << 3)
120#define AMDGPU_RESET_GRBM (1 << 4)
121#define AMDGPU_RESET_DMA1 (1 << 5)
122#define AMDGPU_RESET_RLC (1 << 6)
123#define AMDGPU_RESET_SEM (1 << 7)
124#define AMDGPU_RESET_IH (1 << 8)
125#define AMDGPU_RESET_VMC (1 << 9)
126#define AMDGPU_RESET_MC (1 << 10)
127#define AMDGPU_RESET_DISPLAY (1 << 11)
128#define AMDGPU_RESET_UVD (1 << 12)
129#define AMDGPU_RESET_VCE (1 << 13)
130#define AMDGPU_RESET_VCE1 (1 << 14)
131
Alex Deucher97b2e202015-04-20 16:51:00 -0400132/* GFX current status */
133#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
134#define AMDGPU_GFX_SAFE_MODE 0x00000001L
135#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
136#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
137#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
138
139/* max cursor sizes (in pixels) */
140#define CIK_CURSOR_WIDTH 128
141#define CIK_CURSOR_HEIGHT 128
142
143struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400144struct amdgpu_ib;
145struct amdgpu_vm;
146struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400147struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800148struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400149struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400150struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400151
152enum amdgpu_cp_irq {
153 AMDGPU_CP_IRQ_GFX_EOP = 0,
154 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
155 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
156 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
157 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
158 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
159 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
160 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
161 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
162
163 AMDGPU_CP_IRQ_LAST
164};
165
166enum amdgpu_sdma_irq {
167 AMDGPU_SDMA_IRQ_TRAP0 = 0,
168 AMDGPU_SDMA_IRQ_TRAP1,
169
170 AMDGPU_SDMA_IRQ_LAST
171};
172
173enum amdgpu_thermal_irq {
174 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
175 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
176
177 AMDGPU_THERMAL_IRQ_LAST
178};
179
Alex Deucher97b2e202015-04-20 16:51:00 -0400180int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400181 enum amd_ip_block_type block_type,
182 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400183int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400184 enum amd_ip_block_type block_type,
185 enum amd_powergating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400186
187struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400188 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400189 u32 major;
190 u32 minor;
191 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400192 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400193};
194
195int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400196 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400197 u32 major, u32 minor);
198
199const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
200 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400201 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400202
203/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
204struct amdgpu_buffer_funcs {
205 /* maximum bytes in a single operation */
206 uint32_t copy_max_bytes;
207
208 /* number of dw to reserve per operation */
209 unsigned copy_num_dw;
210
211 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800212 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400213 /* src addr in bytes */
214 uint64_t src_offset,
215 /* dst addr in bytes */
216 uint64_t dst_offset,
217 /* number of byte to transfer */
218 uint32_t byte_count);
219
220 /* maximum bytes in a single operation */
221 uint32_t fill_max_bytes;
222
223 /* number of dw to reserve per operation */
224 unsigned fill_num_dw;
225
226 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800227 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400228 /* value to write to memory */
229 uint32_t src_data,
230 /* dst addr in bytes */
231 uint64_t dst_offset,
232 /* number of byte to fill */
233 uint32_t byte_count);
234};
235
236/* provided by hw blocks that can write ptes, e.g., sdma */
237struct amdgpu_vm_pte_funcs {
238 /* copy pte entries from GART */
239 void (*copy_pte)(struct amdgpu_ib *ib,
240 uint64_t pe, uint64_t src,
241 unsigned count);
242 /* write pte one entry at a time with addr mapping */
243 void (*write_pte)(struct amdgpu_ib *ib,
Christian Königb07c9d22015-11-30 13:26:07 +0100244 const dma_addr_t *pages_addr, uint64_t pe,
Alex Deucher97b2e202015-04-20 16:51:00 -0400245 uint64_t addr, unsigned count,
246 uint32_t incr, uint32_t flags);
247 /* for linear pte/pde updates without addr mapping */
248 void (*set_pte_pde)(struct amdgpu_ib *ib,
249 uint64_t pe,
250 uint64_t addr, unsigned count,
251 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400252};
253
254/* provided by the gmc block */
255struct amdgpu_gart_funcs {
256 /* flush the vm tlb via mmio */
257 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
258 uint32_t vmid);
259 /* write pte/pde updates using the cpu */
260 int (*set_pte_pde)(struct amdgpu_device *adev,
261 void *cpu_pt_addr, /* cpu addr of page table */
262 uint32_t gpu_page_idx, /* pte/pde to update */
263 uint64_t addr, /* addr to write into pte/pde */
264 uint32_t flags); /* access flags */
265};
266
267/* provided by the ih block */
268struct amdgpu_ih_funcs {
269 /* ring read/write ptr handling, called from interrupt context */
270 u32 (*get_wptr)(struct amdgpu_device *adev);
271 void (*decode_iv)(struct amdgpu_device *adev,
272 struct amdgpu_iv_entry *entry);
273 void (*set_rptr)(struct amdgpu_device *adev);
274};
275
276/* provided by hw blocks that expose a ring buffer for commands */
277struct amdgpu_ring_funcs {
278 /* ring read/write ptr handling */
279 u32 (*get_rptr)(struct amdgpu_ring *ring);
280 u32 (*get_wptr)(struct amdgpu_ring *ring);
281 void (*set_wptr)(struct amdgpu_ring *ring);
282 /* validating and patching of IBs */
283 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
284 /* command emit functions */
285 void (*emit_ib)(struct amdgpu_ring *ring,
Christian Königd88bf582016-05-06 17:50:03 +0200286 struct amdgpu_ib *ib,
287 unsigned vm_id, bool ctx_switch);
Alex Deucher97b2e202015-04-20 16:51:00 -0400288 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800289 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100290 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400291 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
292 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200293 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800294 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400295 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
296 uint32_t gds_base, uint32_t gds_size,
297 uint32_t gws_base, uint32_t gws_size,
298 uint32_t oa_base, uint32_t oa_size);
299 /* testing functions */
300 int (*test_ring)(struct amdgpu_ring *ring);
301 int (*test_ib)(struct amdgpu_ring *ring);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800302 /* insert NOP packets */
303 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100304 /* pad the indirect buffer to the necessary number of dw */
305 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800306 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
307 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Alex Deucher97b2e202015-04-20 16:51:00 -0400308};
309
310/*
311 * BIOS.
312 */
313bool amdgpu_get_bios(struct amdgpu_device *adev);
314bool amdgpu_read_bios(struct amdgpu_device *adev);
315
316/*
317 * Dummy page
318 */
319struct amdgpu_dummy_page {
320 struct page *page;
321 dma_addr_t addr;
322};
323int amdgpu_dummy_page_init(struct amdgpu_device *adev);
324void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
325
326
327/*
328 * Clocks
329 */
330
331#define AMDGPU_MAX_PPLL 3
332
333struct amdgpu_clock {
334 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
335 struct amdgpu_pll spll;
336 struct amdgpu_pll mpll;
337 /* 10 Khz units */
338 uint32_t default_mclk;
339 uint32_t default_sclk;
340 uint32_t default_dispclk;
341 uint32_t current_dispclk;
342 uint32_t dp_extclk;
343 uint32_t max_pixel_clock;
344};
345
346/*
347 * Fences.
348 */
349struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400350 uint64_t gpu_addr;
351 volatile uint32_t *cpu_addr;
352 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100353 uint32_t sync_seq;
354 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400355 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400356 struct amdgpu_irq_src *irq_src;
357 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100358 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100359 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100360 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100361 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400362};
363
364/* some special values for the owner field */
365#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
366#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400367
Chunming Zhou890ee232015-06-01 14:35:03 +0800368#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
369#define AMDGPU_FENCE_FLAG_INT (1 << 1)
370
Alex Deucher97b2e202015-04-20 16:51:00 -0400371int amdgpu_fence_driver_init(struct amdgpu_device *adev);
372void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
373void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
374
Christian Könige6151a02016-03-15 14:52:26 +0100375int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
376 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400377int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
378 struct amdgpu_irq_src *irq_src,
379 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400380void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
381void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100382int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400383void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400384int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
385unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
386
Alex Deucher97b2e202015-04-20 16:51:00 -0400387/*
388 * TTM.
389 */
Christian König29b32592016-04-15 17:19:16 +0200390
391#define AMDGPU_TTM_LRU_SIZE 20
392
393struct amdgpu_mman_lru {
394 struct list_head *lru[TTM_NUM_MEM_TYPES];
395 struct list_head *swap_lru;
396};
397
Alex Deucher97b2e202015-04-20 16:51:00 -0400398struct amdgpu_mman {
399 struct ttm_bo_global_ref bo_global_ref;
400 struct drm_global_reference mem_global_ref;
401 struct ttm_bo_device bdev;
402 bool mem_global_referenced;
403 bool initialized;
404
405#if defined(CONFIG_DEBUG_FS)
406 struct dentry *vram;
407 struct dentry *gtt;
408#endif
409
410 /* buffer handling */
411 const struct amdgpu_buffer_funcs *buffer_funcs;
412 struct amdgpu_ring *buffer_funcs_ring;
Christian König703297c2016-02-10 14:20:50 +0100413 /* Scheduler entity for buffer moves */
414 struct amd_sched_entity entity;
Christian König29b32592016-04-15 17:19:16 +0200415
416 /* custom LRU management */
417 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE];
Alex Deucher97b2e202015-04-20 16:51:00 -0400418};
419
420int amdgpu_copy_buffer(struct amdgpu_ring *ring,
421 uint64_t src_offset,
422 uint64_t dst_offset,
423 uint32_t byte_count,
424 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800425 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400426int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
427
428struct amdgpu_bo_list_entry {
429 struct amdgpu_bo *robj;
430 struct ttm_validate_buffer tv;
431 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400432 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100433 struct page **user_pages;
434 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400435};
436
437struct amdgpu_bo_va_mapping {
438 struct list_head list;
439 struct interval_tree_node it;
440 uint64_t offset;
441 uint32_t flags;
442};
443
444/* bo virtual addresses in a specific vm */
445struct amdgpu_bo_va {
446 /* protected by bo being reserved */
447 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800448 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400449 unsigned ref_count;
450
Christian König7fc11952015-07-30 11:53:42 +0200451 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400452 struct list_head vm_status;
453
Christian König7fc11952015-07-30 11:53:42 +0200454 /* mappings for this bo_va */
455 struct list_head invalids;
456 struct list_head valids;
457
Alex Deucher97b2e202015-04-20 16:51:00 -0400458 /* constant after initialization */
459 struct amdgpu_vm *vm;
460 struct amdgpu_bo *bo;
461};
462
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800463#define AMDGPU_GEM_DOMAIN_MAX 0x3
464
Alex Deucher97b2e202015-04-20 16:51:00 -0400465struct amdgpu_bo {
466 /* Protected by gem.mutex */
467 struct list_head list;
468 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100469 u32 prefered_domains;
470 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800471 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400472 struct ttm_placement placement;
473 struct ttm_buffer_object tbo;
474 struct ttm_bo_kmap_obj kmap;
475 u64 flags;
476 unsigned pin_count;
477 void *kptr;
478 u64 tiling_flags;
479 u64 metadata_flags;
480 void *metadata;
481 u32 metadata_size;
482 /* list of all virtual address to which this bo
483 * is associated to
484 */
485 struct list_head va;
486 /* Constant after initialization */
487 struct amdgpu_device *adev;
488 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100489 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400490
491 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400492 struct amdgpu_mn *mn;
493 struct list_head mn_list;
494};
495#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
496
497void amdgpu_gem_object_free(struct drm_gem_object *obj);
498int amdgpu_gem_object_open(struct drm_gem_object *obj,
499 struct drm_file *file_priv);
500void amdgpu_gem_object_close(struct drm_gem_object *obj,
501 struct drm_file *file_priv);
502unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
503struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200504struct drm_gem_object *
505amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
506 struct dma_buf_attachment *attach,
507 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400508struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
509 struct drm_gem_object *gobj,
510 int flags);
511int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
512void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
513struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
514void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
515void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
516int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
517
518/* sub-allocation manager, it has to be protected by another lock.
519 * By conception this is an helper for other part of the driver
520 * like the indirect buffer or semaphore, which both have their
521 * locking.
522 *
523 * Principe is simple, we keep a list of sub allocation in offset
524 * order (first entry has offset == 0, last entry has the highest
525 * offset).
526 *
527 * When allocating new object we first check if there is room at
528 * the end total_size - (last_object_offset + last_object_size) >=
529 * alloc_size. If so we allocate new object there.
530 *
531 * When there is not enough room at the end, we start waiting for
532 * each sub object until we reach object_offset+object_size >=
533 * alloc_size, this object then become the sub object we return.
534 *
535 * Alignment can't be bigger than page size.
536 *
537 * Hole are not considered for allocation to keep things simple.
538 * Assumption is that there won't be hole (all object on same
539 * alignment).
540 */
Christian König6ba60b82016-03-11 14:50:08 +0100541
542#define AMDGPU_SA_NUM_FENCE_LISTS 32
543
Alex Deucher97b2e202015-04-20 16:51:00 -0400544struct amdgpu_sa_manager {
545 wait_queue_head_t wq;
546 struct amdgpu_bo *bo;
547 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100548 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400549 struct list_head olist;
550 unsigned size;
551 uint64_t gpu_addr;
552 void *cpu_ptr;
553 uint32_t domain;
554 uint32_t align;
555};
556
Alex Deucher97b2e202015-04-20 16:51:00 -0400557/* sub-allocation buffer */
558struct amdgpu_sa_bo {
559 struct list_head olist;
560 struct list_head flist;
561 struct amdgpu_sa_manager *manager;
562 unsigned soffset;
563 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800564 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400565};
566
567/*
568 * GEM objects.
569 */
Christian König418aa0c2016-02-15 16:59:57 +0100570void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400571int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
572 int alignment, u32 initial_domain,
573 u64 flags, bool kernel,
574 struct drm_gem_object **obj);
575
576int amdgpu_mode_dumb_create(struct drm_file *file_priv,
577 struct drm_device *dev,
578 struct drm_mode_create_dumb *args);
579int amdgpu_mode_dumb_mmap(struct drm_file *filp,
580 struct drm_device *dev,
581 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400582/*
583 * Synchronization
584 */
585struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800586 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800587 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400588};
589
590void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200591int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
592 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400593int amdgpu_sync_resv(struct amdgpu_device *adev,
594 struct amdgpu_sync *sync,
595 struct reservation_object *resv,
596 void *owner);
Christian König832a9022016-02-15 12:33:02 +0100597bool amdgpu_sync_is_idle(struct amdgpu_sync *sync);
598int amdgpu_sync_cycle_fences(struct amdgpu_sync *dst, struct amdgpu_sync *src,
599 struct fence *fence);
Christian Könige61235d2015-08-25 11:05:36 +0200600struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian Königf91b3a62015-08-20 14:47:40 +0800601int amdgpu_sync_wait(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100602void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100603int amdgpu_sync_init(void);
604void amdgpu_sync_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400605
606/*
607 * GART structures, functions & helpers
608 */
609struct amdgpu_mc;
610
611#define AMDGPU_GPU_PAGE_SIZE 4096
612#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
613#define AMDGPU_GPU_PAGE_SHIFT 12
614#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
615
616struct amdgpu_gart {
617 dma_addr_t table_addr;
618 struct amdgpu_bo *robj;
619 void *ptr;
620 unsigned num_gpu_pages;
621 unsigned num_cpu_pages;
622 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200623#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400624 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200625#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400626 bool ready;
627 const struct amdgpu_gart_funcs *gart_funcs;
628};
629
630int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
631void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
632int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
633void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
634int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
635void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
636int amdgpu_gart_init(struct amdgpu_device *adev);
637void amdgpu_gart_fini(struct amdgpu_device *adev);
638void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
639 int pages);
640int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
641 int pages, struct page **pagelist,
642 dma_addr_t *dma_addr, uint32_t flags);
643
644/*
645 * GPU MC structures, functions & helpers
646 */
647struct amdgpu_mc {
648 resource_size_t aper_size;
649 resource_size_t aper_base;
650 resource_size_t agp_base;
651 /* for some chips with <= 32MB we need to lie
652 * about vram size near mc fb location */
653 u64 mc_vram_size;
654 u64 visible_vram_size;
655 u64 gtt_size;
656 u64 gtt_start;
657 u64 gtt_end;
658 u64 vram_start;
659 u64 vram_end;
660 unsigned vram_width;
661 u64 real_vram_size;
662 int vram_mtrr;
663 u64 gtt_base_align;
664 u64 mc_mask;
665 const struct firmware *fw; /* MC firmware */
666 uint32_t fw_version;
667 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800668 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400669};
670
671/*
672 * GPU doorbell structures, functions & helpers
673 */
674typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
675{
676 AMDGPU_DOORBELL_KIQ = 0x000,
677 AMDGPU_DOORBELL_HIQ = 0x001,
678 AMDGPU_DOORBELL_DIQ = 0x002,
679 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
680 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
681 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
682 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
683 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
684 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
685 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
686 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
687 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
688 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
689 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
690 AMDGPU_DOORBELL_IH = 0x1E8,
691 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
692 AMDGPU_DOORBELL_INVALID = 0xFFFF
693} AMDGPU_DOORBELL_ASSIGNMENT;
694
695struct amdgpu_doorbell {
696 /* doorbell mmio */
697 resource_size_t base;
698 resource_size_t size;
699 u32 __iomem *ptr;
700 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
701};
702
703void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
704 phys_addr_t *aperture_base,
705 size_t *aperture_size,
706 size_t *start_offset);
707
708/*
709 * IRQS.
710 */
711
712struct amdgpu_flip_work {
713 struct work_struct flip_work;
714 struct work_struct unpin_work;
715 struct amdgpu_device *adev;
716 int crtc_id;
717 uint64_t base;
718 struct drm_pending_vblank_event *event;
719 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200720 struct fence *excl;
721 unsigned shared_count;
722 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100723 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400724 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400725};
726
727
728/*
729 * CP & rings.
730 */
731
732struct amdgpu_ib {
733 struct amdgpu_sa_bo *sa_bo;
734 uint32_t length_dw;
735 uint64_t gpu_addr;
736 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800737 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400738};
739
740enum amdgpu_ring_type {
741 AMDGPU_RING_TYPE_GFX,
742 AMDGPU_RING_TYPE_COMPUTE,
743 AMDGPU_RING_TYPE_SDMA,
744 AMDGPU_RING_TYPE_UVD,
745 AMDGPU_RING_TYPE_VCE
746};
747
Nils Wallménius62250a92016-04-10 16:30:00 +0200748extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800749
Christian König50838c82016-02-03 13:44:52 +0100750int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800751 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100752int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
753 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800754
Christian König50838c82016-02-03 13:44:52 +0100755void amdgpu_job_free(struct amdgpu_job *job);
Monk Liub6723c82016-03-10 12:14:44 +0800756void amdgpu_job_free_func(struct kref *refcount);
Christian Königd71518b2016-02-01 12:20:25 +0100757int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100758 struct amd_sched_entity *entity, void *owner,
759 struct fence **f);
Monk Liu0de24792016-03-04 18:51:02 +0800760void amdgpu_job_timeout_func(struct work_struct *work);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800761
Alex Deucher97b2e202015-04-20 16:51:00 -0400762struct amdgpu_ring {
763 struct amdgpu_device *adev;
764 const struct amdgpu_ring_funcs *funcs;
765 struct amdgpu_fence_driver fence_drv;
Christian Königedf600d2016-05-03 15:54:54 +0200766 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400767
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800768 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400769 struct amdgpu_bo *ring_obj;
770 volatile uint32_t *ring;
771 unsigned rptr_offs;
772 u64 next_rptr_gpu_addr;
773 volatile u32 *next_rptr_cpu_addr;
774 unsigned wptr;
775 unsigned wptr_old;
776 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100777 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400778 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400779 uint64_t gpu_addr;
780 uint32_t align_mask;
781 uint32_t ptr_mask;
782 bool ready;
783 u32 nop;
784 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400785 u32 me;
786 u32 pipe;
787 u32 queue;
788 struct amdgpu_bo *mqd_obj;
789 u32 doorbell_index;
790 bool use_doorbell;
791 unsigned wptr_offs;
792 unsigned next_rptr_offs;
793 unsigned fence_offs;
Christian Königaa3b73f2016-05-03 15:17:40 +0200794 uint64_t current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400795 enum amdgpu_ring_type type;
796 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800797 unsigned cond_exe_offs;
798 u64 cond_exe_gpu_addr;
799 volatile u32 *cond_exe_cpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400800};
801
802/*
803 * VM
804 */
805
806/* maximum number of VMIDs */
807#define AMDGPU_NUM_VM 16
808
809/* number of entries in page table */
810#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
811
812/* PTBs (Page Table Blocks) need to be aligned to 32K */
813#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
814#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
815#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
816
817#define AMDGPU_PTE_VALID (1 << 0)
818#define AMDGPU_PTE_SYSTEM (1 << 1)
819#define AMDGPU_PTE_SNOOPED (1 << 2)
820
821/* VI only */
822#define AMDGPU_PTE_EXECUTABLE (1 << 4)
823
824#define AMDGPU_PTE_READABLE (1 << 5)
825#define AMDGPU_PTE_WRITEABLE (1 << 6)
826
827/* PTE (Page Table Entry) fragment field for different page sizes */
828#define AMDGPU_PTE_FRAG_4KB (0 << 7)
829#define AMDGPU_PTE_FRAG_64KB (4 << 7)
830#define AMDGPU_LOG2_PAGES_PER_FRAG 4
831
Christian Königd9c13152015-09-28 12:31:26 +0200832/* How to programm VM fault handling */
833#define AMDGPU_VM_FAULT_STOP_NEVER 0
834#define AMDGPU_VM_FAULT_STOP_FIRST 1
835#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
836
Alex Deucher97b2e202015-04-20 16:51:00 -0400837struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100838 struct amdgpu_bo_list_entry entry;
839 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400840};
841
Alex Deucher97b2e202015-04-20 16:51:00 -0400842struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100843 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400844 struct rb_root va;
845
Christian König7fc11952015-07-30 11:53:42 +0200846 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400847 spinlock_t status_lock;
848
849 /* BOs moved, but not yet updated in the PT */
850 struct list_head invalidated;
851
Christian König7fc11952015-07-30 11:53:42 +0200852 /* BOs cleared in the PT because of a move */
853 struct list_head cleared;
854
855 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400856 struct list_head freed;
857
858 /* contains the page directory */
859 struct amdgpu_bo *page_directory;
860 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200861 struct fence *page_directory_fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400862
863 /* array of page tables, one for each page directory entry */
864 struct amdgpu_vm_pt *page_tables;
865
866 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100867 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100868
jimqu81d75a32015-12-04 17:17:00 +0800869 /* protecting freed */
870 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100871
872 /* Scheduler entity for page table updates */
873 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800874
875 /* client id */
876 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400877};
878
Christian Königbcb1ba32016-03-08 15:40:11 +0100879struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100880 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100881 struct fence *first;
882 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100883 struct fence *last_flush;
Chunming Zhou68befeb2016-04-14 13:42:32 +0800884 struct amdgpu_ring *last_user;
Christian König0ea54b92016-05-04 10:20:01 +0200885 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100886
Christian Königbcb1ba32016-03-08 15:40:11 +0100887 uint64_t pd_gpu_addr;
888 /* last flushed PD/PT update */
889 struct fence *flushed_updates;
890
Christian König971fe9a92016-03-01 15:09:25 +0100891 uint32_t gds_base;
892 uint32_t gds_size;
893 uint32_t gws_base;
894 uint32_t gws_size;
895 uint32_t oa_base;
896 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100897};
Christian König8d0a7ce2015-11-03 20:58:50 +0100898
Christian Königa9a78b32016-01-21 10:19:11 +0100899struct amdgpu_vm_manager {
900 /* Handling of VMIDs */
901 struct mutex lock;
902 unsigned num_ids;
903 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100904 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100905
Christian König8b4fb002015-11-15 16:04:16 +0100906 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400907 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100908 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400909 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100910 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400911 /* vm pte handling */
912 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100913 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
914 unsigned vm_pte_num_rings;
915 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800916 /* client id counter */
917 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400918};
919
Christian Königa9a78b32016-01-21 10:19:11 +0100920void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100921void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100922int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
923void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100924void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
925 struct list_head *validated,
926 struct amdgpu_bo_list_entry *entry);
Christian Königee1782c2015-12-11 21:01:23 +0100927void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100928void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
929 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100930int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100931 struct amdgpu_sync *sync, struct fence *fence,
932 unsigned *vm_id, uint64_t *vm_pd_addr);
Christian König41d9eb22016-03-01 16:46:18 +0100933int amdgpu_vm_flush(struct amdgpu_ring *ring,
934 unsigned vm_id, uint64_t pd_addr,
935 uint32_t gds_base, uint32_t gds_size,
936 uint32_t gws_base, uint32_t gws_size,
937 uint32_t oa_base, uint32_t oa_size);
Christian König971fe9a92016-03-01 15:09:25 +0100938void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian Königb07c9d22015-11-30 13:26:07 +0100939uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
Christian König8b4fb002015-11-15 16:04:16 +0100940int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
941 struct amdgpu_vm *vm);
942int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
943 struct amdgpu_vm *vm);
944int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
945 struct amdgpu_sync *sync);
946int amdgpu_vm_bo_update(struct amdgpu_device *adev,
947 struct amdgpu_bo_va *bo_va,
948 struct ttm_mem_reg *mem);
949void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
950 struct amdgpu_bo *bo);
951struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
952 struct amdgpu_bo *bo);
953struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
954 struct amdgpu_vm *vm,
955 struct amdgpu_bo *bo);
956int amdgpu_vm_bo_map(struct amdgpu_device *adev,
957 struct amdgpu_bo_va *bo_va,
958 uint64_t addr, uint64_t offset,
959 uint64_t size, uint32_t flags);
960int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
961 struct amdgpu_bo_va *bo_va,
962 uint64_t addr);
963void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
964 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100965
Alex Deucher97b2e202015-04-20 16:51:00 -0400966/*
967 * context related structures
968 */
969
Christian König21c16bf2015-07-07 17:24:49 +0200970struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200971 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800972 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200973 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200974};
975
Alex Deucher97b2e202015-04-20 16:51:00 -0400976struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400977 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800978 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400979 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200980 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800981 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200982 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400983};
984
985struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400986 struct amdgpu_device *adev;
987 struct mutex lock;
988 /* protected by lock */
989 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400990};
991
Alex Deucher0b492a42015-08-16 22:48:26 -0400992struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
993int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
994
Christian König21c16bf2015-07-07 17:24:49 +0200995uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200996 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200997struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
998 struct amdgpu_ring *ring, uint64_t seq);
999
Alex Deucher0b492a42015-08-16 22:48:26 -04001000int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1001 struct drm_file *filp);
1002
Christian Königefd4ccb2015-08-04 16:20:31 +02001003void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1004void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -04001005
Alex Deucher97b2e202015-04-20 16:51:00 -04001006/*
1007 * file private structure
1008 */
1009
1010struct amdgpu_fpriv {
1011 struct amdgpu_vm vm;
1012 struct mutex bo_list_lock;
1013 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001014 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001015};
1016
1017/*
1018 * residency list
1019 */
1020
1021struct amdgpu_bo_list {
1022 struct mutex lock;
1023 struct amdgpu_bo *gds_obj;
1024 struct amdgpu_bo *gws_obj;
1025 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001026 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001027 unsigned num_entries;
1028 struct amdgpu_bo_list_entry *array;
1029};
1030
1031struct amdgpu_bo_list *
1032amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001033void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1034 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001035void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1036void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1037
1038/*
1039 * GFX stuff
1040 */
1041#include "clearstate_defs.h"
1042
Alex Deucher79e54122016-04-08 15:45:13 -04001043struct amdgpu_rlc_funcs {
1044 void (*enter_safe_mode)(struct amdgpu_device *adev);
1045 void (*exit_safe_mode)(struct amdgpu_device *adev);
1046};
1047
Alex Deucher97b2e202015-04-20 16:51:00 -04001048struct amdgpu_rlc {
1049 /* for power gating */
1050 struct amdgpu_bo *save_restore_obj;
1051 uint64_t save_restore_gpu_addr;
1052 volatile uint32_t *sr_ptr;
1053 const u32 *reg_list;
1054 u32 reg_list_size;
1055 /* for clear state */
1056 struct amdgpu_bo *clear_state_obj;
1057 uint64_t clear_state_gpu_addr;
1058 volatile uint32_t *cs_ptr;
1059 const struct cs_section_def *cs_data;
1060 u32 clear_state_size;
1061 /* for cp tables */
1062 struct amdgpu_bo *cp_table_obj;
1063 uint64_t cp_table_gpu_addr;
1064 volatile uint32_t *cp_table_ptr;
1065 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001066
1067 /* safe mode for updating CG/PG state */
1068 bool in_safe_mode;
1069 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001070
1071 /* for firmware data */
1072 u32 save_and_restore_offset;
1073 u32 clear_state_descriptor_offset;
1074 u32 avail_scratch_ram_locations;
1075 u32 reg_restore_list_size;
1076 u32 reg_list_format_start;
1077 u32 reg_list_format_separate_start;
1078 u32 starting_offsets_start;
1079 u32 reg_list_format_size_bytes;
1080 u32 reg_list_size_bytes;
1081
1082 u32 *register_list_format;
1083 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001084};
1085
1086struct amdgpu_mec {
1087 struct amdgpu_bo *hpd_eop_obj;
1088 u64 hpd_eop_gpu_addr;
1089 u32 num_pipe;
1090 u32 num_mec;
1091 u32 num_queue;
1092};
1093
1094/*
1095 * GPU scratch registers structures, functions & helpers
1096 */
1097struct amdgpu_scratch {
1098 unsigned num_reg;
1099 uint32_t reg_base;
1100 bool free[32];
1101 uint32_t reg[32];
1102};
1103
1104/*
1105 * GFX configurations
1106 */
1107struct amdgpu_gca_config {
1108 unsigned max_shader_engines;
1109 unsigned max_tile_pipes;
1110 unsigned max_cu_per_sh;
1111 unsigned max_sh_per_se;
1112 unsigned max_backends_per_se;
1113 unsigned max_texture_channel_caches;
1114 unsigned max_gprs;
1115 unsigned max_gs_threads;
1116 unsigned max_hw_contexts;
1117 unsigned sc_prim_fifo_size_frontend;
1118 unsigned sc_prim_fifo_size_backend;
1119 unsigned sc_hiz_tile_fifo_size;
1120 unsigned sc_earlyz_tile_fifo_size;
1121
1122 unsigned num_tile_pipes;
1123 unsigned backend_enable_mask;
1124 unsigned mem_max_burst_length_bytes;
1125 unsigned mem_row_size_in_kb;
1126 unsigned shader_engine_tile_size;
1127 unsigned num_gpus;
1128 unsigned multi_gpu_tile_size;
1129 unsigned mc_arb_ramcfg;
1130 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001131 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001132
1133 uint32_t tile_mode_array[32];
1134 uint32_t macrotile_mode_array[16];
1135};
1136
Alex Deucher7dae69a2016-05-03 16:25:53 -04001137struct amdgpu_cu_info {
1138 uint32_t number; /* total active CU number */
1139 uint32_t ao_cu_mask;
1140 uint32_t bitmap[4][4];
1141};
1142
Alex Deucher97b2e202015-04-20 16:51:00 -04001143struct amdgpu_gfx {
1144 struct mutex gpu_clock_mutex;
1145 struct amdgpu_gca_config config;
1146 struct amdgpu_rlc rlc;
1147 struct amdgpu_mec mec;
1148 struct amdgpu_scratch scratch;
1149 const struct firmware *me_fw; /* ME firmware */
1150 uint32_t me_fw_version;
1151 const struct firmware *pfp_fw; /* PFP firmware */
1152 uint32_t pfp_fw_version;
1153 const struct firmware *ce_fw; /* CE firmware */
1154 uint32_t ce_fw_version;
1155 const struct firmware *rlc_fw; /* RLC firmware */
1156 uint32_t rlc_fw_version;
1157 const struct firmware *mec_fw; /* MEC firmware */
1158 uint32_t mec_fw_version;
1159 const struct firmware *mec2_fw; /* MEC2 firmware */
1160 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001161 uint32_t me_feature_version;
1162 uint32_t ce_feature_version;
1163 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001164 uint32_t rlc_feature_version;
1165 uint32_t mec_feature_version;
1166 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001167 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1168 unsigned num_gfx_rings;
1169 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1170 unsigned num_compute_rings;
1171 struct amdgpu_irq_src eop_irq;
1172 struct amdgpu_irq_src priv_reg_irq;
1173 struct amdgpu_irq_src priv_inst_irq;
1174 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001175 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001176 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001177 unsigned ce_ram_size;
1178 struct amdgpu_cu_info cu_info;
Alex Deucher97b2e202015-04-20 16:51:00 -04001179};
1180
Christian Königb07c60c2016-01-31 12:29:04 +01001181int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001182 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001183void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1184 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001185int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001186 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001187 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001188int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1189void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1190int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001191int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001192void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001193void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001194void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001195void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001196unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1197 uint32_t **data);
1198int amdgpu_ring_restore(struct amdgpu_ring *ring,
1199 unsigned size, uint32_t *data);
1200int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1201 unsigned ring_size, u32 nop, u32 align_mask,
1202 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1203 enum amdgpu_ring_type ring_type);
1204void amdgpu_ring_fini(struct amdgpu_ring *ring);
1205
1206/*
1207 * CS.
1208 */
1209struct amdgpu_cs_chunk {
1210 uint32_t chunk_id;
1211 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001212 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001213};
1214
1215struct amdgpu_cs_parser {
1216 struct amdgpu_device *adev;
1217 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001218 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001219
Alex Deucher97b2e202015-04-20 16:51:00 -04001220 /* chunks */
1221 unsigned nchunks;
1222 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001223
Christian König50838c82016-02-03 13:44:52 +01001224 /* scheduler job object */
1225 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001226
Christian Königc3cca412015-12-15 14:41:33 +01001227 /* buffer objects */
1228 struct ww_acquire_ctx ticket;
1229 struct amdgpu_bo_list *bo_list;
1230 struct amdgpu_bo_list_entry vm_pd;
1231 struct list_head validated;
1232 struct fence *fence;
1233 uint64_t bytes_moved_threshold;
1234 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001235
1236 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001237 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001238};
1239
Chunming Zhoubb977d32015-08-18 15:16:40 +08001240struct amdgpu_job {
1241 struct amd_sched_job base;
1242 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001243 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001244 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001245 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001246 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001247 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001248 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001249 void *owner;
Christian König92f25092016-05-06 15:57:42 +02001250 uint64_t ctx;
Christian Königd88bf582016-05-06 17:50:03 +02001251 unsigned vm_id;
1252 uint64_t vm_pd_addr;
1253 uint32_t gds_base, gds_size;
1254 uint32_t gws_base, gws_size;
1255 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001256
1257 /* user fence handling */
1258 struct amdgpu_bo *uf_bo;
1259 uint32_t uf_offset;
1260 uint64_t uf_sequence;
1261
Chunming Zhoubb977d32015-08-18 15:16:40 +08001262};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001263#define to_amdgpu_job(sched_job) \
1264 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001265
Christian König7270f832016-01-31 11:00:41 +01001266static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1267 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001268{
Christian König50838c82016-02-03 13:44:52 +01001269 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001270}
1271
Christian König7270f832016-01-31 11:00:41 +01001272static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1273 uint32_t ib_idx, int idx,
1274 uint32_t value)
1275{
Christian König50838c82016-02-03 13:44:52 +01001276 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001277}
1278
Alex Deucher97b2e202015-04-20 16:51:00 -04001279/*
1280 * Writeback
1281 */
1282#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1283
1284struct amdgpu_wb {
1285 struct amdgpu_bo *wb_obj;
1286 volatile uint32_t *wb;
1287 uint64_t gpu_addr;
1288 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1289 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1290};
1291
1292int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1293void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1294
Alex Deucher97b2e202015-04-20 16:51:00 -04001295
Alex Deucher97b2e202015-04-20 16:51:00 -04001296
1297enum amdgpu_int_thermal_type {
1298 THERMAL_TYPE_NONE,
1299 THERMAL_TYPE_EXTERNAL,
1300 THERMAL_TYPE_EXTERNAL_GPIO,
1301 THERMAL_TYPE_RV6XX,
1302 THERMAL_TYPE_RV770,
1303 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1304 THERMAL_TYPE_EVERGREEN,
1305 THERMAL_TYPE_SUMO,
1306 THERMAL_TYPE_NI,
1307 THERMAL_TYPE_SI,
1308 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1309 THERMAL_TYPE_CI,
1310 THERMAL_TYPE_KV,
1311};
1312
1313enum amdgpu_dpm_auto_throttle_src {
1314 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1315 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1316};
1317
1318enum amdgpu_dpm_event_src {
1319 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1320 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1321 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1322 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1323 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1324};
1325
1326#define AMDGPU_MAX_VCE_LEVELS 6
1327
1328enum amdgpu_vce_level {
1329 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1330 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1331 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1332 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1333 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1334 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1335};
1336
1337struct amdgpu_ps {
1338 u32 caps; /* vbios flags */
1339 u32 class; /* vbios flags */
1340 u32 class2; /* vbios flags */
1341 /* UVD clocks */
1342 u32 vclk;
1343 u32 dclk;
1344 /* VCE clocks */
1345 u32 evclk;
1346 u32 ecclk;
1347 bool vce_active;
1348 enum amdgpu_vce_level vce_level;
1349 /* asic priv */
1350 void *ps_priv;
1351};
1352
1353struct amdgpu_dpm_thermal {
1354 /* thermal interrupt work */
1355 struct work_struct work;
1356 /* low temperature threshold */
1357 int min_temp;
1358 /* high temperature threshold */
1359 int max_temp;
1360 /* was last interrupt low to high or high to low */
1361 bool high_to_low;
1362 /* interrupt source */
1363 struct amdgpu_irq_src irq;
1364};
1365
1366enum amdgpu_clk_action
1367{
1368 AMDGPU_SCLK_UP = 1,
1369 AMDGPU_SCLK_DOWN
1370};
1371
1372struct amdgpu_blacklist_clocks
1373{
1374 u32 sclk;
1375 u32 mclk;
1376 enum amdgpu_clk_action action;
1377};
1378
1379struct amdgpu_clock_and_voltage_limits {
1380 u32 sclk;
1381 u32 mclk;
1382 u16 vddc;
1383 u16 vddci;
1384};
1385
1386struct amdgpu_clock_array {
1387 u32 count;
1388 u32 *values;
1389};
1390
1391struct amdgpu_clock_voltage_dependency_entry {
1392 u32 clk;
1393 u16 v;
1394};
1395
1396struct amdgpu_clock_voltage_dependency_table {
1397 u32 count;
1398 struct amdgpu_clock_voltage_dependency_entry *entries;
1399};
1400
1401union amdgpu_cac_leakage_entry {
1402 struct {
1403 u16 vddc;
1404 u32 leakage;
1405 };
1406 struct {
1407 u16 vddc1;
1408 u16 vddc2;
1409 u16 vddc3;
1410 };
1411};
1412
1413struct amdgpu_cac_leakage_table {
1414 u32 count;
1415 union amdgpu_cac_leakage_entry *entries;
1416};
1417
1418struct amdgpu_phase_shedding_limits_entry {
1419 u16 voltage;
1420 u32 sclk;
1421 u32 mclk;
1422};
1423
1424struct amdgpu_phase_shedding_limits_table {
1425 u32 count;
1426 struct amdgpu_phase_shedding_limits_entry *entries;
1427};
1428
1429struct amdgpu_uvd_clock_voltage_dependency_entry {
1430 u32 vclk;
1431 u32 dclk;
1432 u16 v;
1433};
1434
1435struct amdgpu_uvd_clock_voltage_dependency_table {
1436 u8 count;
1437 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1438};
1439
1440struct amdgpu_vce_clock_voltage_dependency_entry {
1441 u32 ecclk;
1442 u32 evclk;
1443 u16 v;
1444};
1445
1446struct amdgpu_vce_clock_voltage_dependency_table {
1447 u8 count;
1448 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1449};
1450
1451struct amdgpu_ppm_table {
1452 u8 ppm_design;
1453 u16 cpu_core_number;
1454 u32 platform_tdp;
1455 u32 small_ac_platform_tdp;
1456 u32 platform_tdc;
1457 u32 small_ac_platform_tdc;
1458 u32 apu_tdp;
1459 u32 dgpu_tdp;
1460 u32 dgpu_ulv_power;
1461 u32 tj_max;
1462};
1463
1464struct amdgpu_cac_tdp_table {
1465 u16 tdp;
1466 u16 configurable_tdp;
1467 u16 tdc;
1468 u16 battery_power_limit;
1469 u16 small_power_limit;
1470 u16 low_cac_leakage;
1471 u16 high_cac_leakage;
1472 u16 maximum_power_delivery_limit;
1473};
1474
1475struct amdgpu_dpm_dynamic_state {
1476 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1477 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1478 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1479 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1480 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1481 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1482 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1483 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1484 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1485 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1486 struct amdgpu_clock_array valid_sclk_values;
1487 struct amdgpu_clock_array valid_mclk_values;
1488 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1489 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1490 u32 mclk_sclk_ratio;
1491 u32 sclk_mclk_delta;
1492 u16 vddc_vddci_delta;
1493 u16 min_vddc_for_pcie_gen2;
1494 struct amdgpu_cac_leakage_table cac_leakage_table;
1495 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1496 struct amdgpu_ppm_table *ppm_table;
1497 struct amdgpu_cac_tdp_table *cac_tdp_table;
1498};
1499
1500struct amdgpu_dpm_fan {
1501 u16 t_min;
1502 u16 t_med;
1503 u16 t_high;
1504 u16 pwm_min;
1505 u16 pwm_med;
1506 u16 pwm_high;
1507 u8 t_hyst;
1508 u32 cycle_delay;
1509 u16 t_max;
1510 u8 control_mode;
1511 u16 default_max_fan_pwm;
1512 u16 default_fan_output_sensitivity;
1513 u16 fan_output_sensitivity;
1514 bool ucode_fan_control;
1515};
1516
1517enum amdgpu_pcie_gen {
1518 AMDGPU_PCIE_GEN1 = 0,
1519 AMDGPU_PCIE_GEN2 = 1,
1520 AMDGPU_PCIE_GEN3 = 2,
1521 AMDGPU_PCIE_GEN_INVALID = 0xffff
1522};
1523
1524enum amdgpu_dpm_forced_level {
1525 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1526 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1527 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001528 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001529};
1530
1531struct amdgpu_vce_state {
1532 /* vce clocks */
1533 u32 evclk;
1534 u32 ecclk;
1535 /* gpu clocks */
1536 u32 sclk;
1537 u32 mclk;
1538 u8 clk_idx;
1539 u8 pstate;
1540};
1541
1542struct amdgpu_dpm_funcs {
1543 int (*get_temperature)(struct amdgpu_device *adev);
1544 int (*pre_set_power_state)(struct amdgpu_device *adev);
1545 int (*set_power_state)(struct amdgpu_device *adev);
1546 void (*post_set_power_state)(struct amdgpu_device *adev);
1547 void (*display_configuration_changed)(struct amdgpu_device *adev);
1548 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1549 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1550 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1551 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1552 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1553 bool (*vblank_too_short)(struct amdgpu_device *adev);
1554 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001555 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001556 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1557 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1558 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1559 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1560 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1561};
1562
1563struct amdgpu_dpm {
1564 struct amdgpu_ps *ps;
1565 /* number of valid power states */
1566 int num_ps;
1567 /* current power state that is active */
1568 struct amdgpu_ps *current_ps;
1569 /* requested power state */
1570 struct amdgpu_ps *requested_ps;
1571 /* boot up power state */
1572 struct amdgpu_ps *boot_ps;
1573 /* default uvd power state */
1574 struct amdgpu_ps *uvd_ps;
1575 /* vce requirements */
1576 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1577 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001578 enum amd_pm_state_type state;
1579 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001580 u32 platform_caps;
1581 u32 voltage_response_time;
1582 u32 backbias_response_time;
1583 void *priv;
1584 u32 new_active_crtcs;
1585 int new_active_crtc_count;
1586 u32 current_active_crtcs;
1587 int current_active_crtc_count;
1588 struct amdgpu_dpm_dynamic_state dyn_state;
1589 struct amdgpu_dpm_fan fan;
1590 u32 tdp_limit;
1591 u32 near_tdp_limit;
1592 u32 near_tdp_limit_adjusted;
1593 u32 sq_ramping_threshold;
1594 u32 cac_leakage;
1595 u16 tdp_od_limit;
1596 u32 tdp_adjustment;
1597 u16 load_line_slope;
1598 bool power_control;
1599 bool ac_power;
1600 /* special states active */
1601 bool thermal_active;
1602 bool uvd_active;
1603 bool vce_active;
1604 /* thermal handling */
1605 struct amdgpu_dpm_thermal thermal;
1606 /* forced levels */
1607 enum amdgpu_dpm_forced_level forced_level;
1608};
1609
1610struct amdgpu_pm {
1611 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001612 u32 current_sclk;
1613 u32 current_mclk;
1614 u32 default_sclk;
1615 u32 default_mclk;
1616 struct amdgpu_i2c_chan *i2c_bus;
1617 /* internal thermal controller on rv6xx+ */
1618 enum amdgpu_int_thermal_type int_thermal_type;
1619 struct device *int_hwmon_dev;
1620 /* fan control parameters */
1621 bool no_fan;
1622 u8 fan_pulses_per_revolution;
1623 u8 fan_min_rpm;
1624 u8 fan_max_rpm;
1625 /* dpm */
1626 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001627 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001628 struct amdgpu_dpm dpm;
1629 const struct firmware *fw; /* SMC firmware */
1630 uint32_t fw_version;
1631 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001632 uint32_t pcie_gen_mask;
1633 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001634 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001635};
1636
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001637void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1638
Alex Deucher97b2e202015-04-20 16:51:00 -04001639/*
1640 * UVD
1641 */
Arindam Nathc0365542016-04-12 13:46:15 +02001642#define AMDGPU_DEFAULT_UVD_HANDLES 10
1643#define AMDGPU_MAX_UVD_HANDLES 40
1644#define AMDGPU_UVD_STACK_SIZE (200*1024)
1645#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1646#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1647#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001648
1649struct amdgpu_uvd {
1650 struct amdgpu_bo *vcpu_bo;
1651 void *cpu_addr;
1652 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001653 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001654 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001655 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001656 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1657 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1658 struct delayed_work idle_work;
1659 const struct firmware *fw; /* UVD firmware */
1660 struct amdgpu_ring ring;
1661 struct amdgpu_irq_src irq;
1662 bool address_64_bit;
Christian Königead833e2016-02-10 14:35:19 +01001663 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001664};
1665
1666/*
1667 * VCE
1668 */
1669#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001670#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1671
Alex Deucher6a585772015-07-10 14:16:24 -04001672#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1673#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1674
Alex Deucher97b2e202015-04-20 16:51:00 -04001675struct amdgpu_vce {
1676 struct amdgpu_bo *vcpu_bo;
1677 uint64_t gpu_addr;
1678 unsigned fw_version;
1679 unsigned fb_version;
1680 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1681 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001682 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001683 struct delayed_work idle_work;
1684 const struct firmware *fw; /* VCE firmware */
1685 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1686 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001687 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001688 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001689};
1690
1691/*
1692 * SDMA
1693 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001694struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001695 /* SDMA firmware */
1696 const struct firmware *fw;
1697 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001698 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001699
1700 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001701 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001702};
1703
Alex Deucherc113ea12015-10-08 16:30:37 -04001704struct amdgpu_sdma {
1705 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1706 struct amdgpu_irq_src trap_irq;
1707 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001708 int num_instances;
Alex Deucherc113ea12015-10-08 16:30:37 -04001709};
1710
Alex Deucher97b2e202015-04-20 16:51:00 -04001711/*
1712 * Firmware
1713 */
1714struct amdgpu_firmware {
1715 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1716 bool smu_load;
1717 struct amdgpu_bo *fw_buf;
1718 unsigned int fw_size;
1719};
1720
1721/*
1722 * Benchmarking
1723 */
1724void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1725
1726
1727/*
1728 * Testing
1729 */
1730void amdgpu_test_moves(struct amdgpu_device *adev);
1731void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1732 struct amdgpu_ring *cpA,
1733 struct amdgpu_ring *cpB);
1734void amdgpu_test_syncing(struct amdgpu_device *adev);
1735
1736/*
1737 * MMU Notifier
1738 */
1739#if defined(CONFIG_MMU_NOTIFIER)
1740int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1741void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1742#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001743static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001744{
1745 return -ENODEV;
1746}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001747static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001748#endif
1749
1750/*
1751 * Debugfs
1752 */
1753struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001754 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001755 unsigned num_files;
1756};
1757
1758int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001759 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001760 unsigned nfiles);
1761int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1762
1763#if defined(CONFIG_DEBUG_FS)
1764int amdgpu_debugfs_init(struct drm_minor *minor);
1765void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1766#endif
1767
1768/*
1769 * amdgpu smumgr functions
1770 */
1771struct amdgpu_smumgr_funcs {
1772 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1773 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1774 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1775};
1776
1777/*
1778 * amdgpu smumgr
1779 */
1780struct amdgpu_smumgr {
1781 struct amdgpu_bo *toc_buf;
1782 struct amdgpu_bo *smu_buf;
1783 /* asic priv smu data */
1784 void *priv;
1785 spinlock_t smu_lock;
1786 /* smumgr functions */
1787 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1788 /* ucode loading complete flag */
1789 uint32_t fw_flags;
1790};
1791
1792/*
1793 * ASIC specific register table accessible by UMD
1794 */
1795struct amdgpu_allowed_register_entry {
1796 uint32_t reg_offset;
1797 bool untouched;
1798 bool grbm_indexed;
1799};
1800
Alex Deucher97b2e202015-04-20 16:51:00 -04001801/*
1802 * ASIC specific functions.
1803 */
1804struct amdgpu_asic_funcs {
1805 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001806 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1807 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001808 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1809 u32 sh_num, u32 reg_offset, u32 *value);
1810 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1811 int (*reset)(struct amdgpu_device *adev);
1812 /* wait for mc_idle */
1813 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1814 /* get the reference clock */
1815 u32 (*get_xclk)(struct amdgpu_device *adev);
1816 /* get the gpu clock counter */
1817 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001818 /* MM block clocks */
1819 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1820 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1821};
1822
1823/*
1824 * IOCTL.
1825 */
1826int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1827 struct drm_file *filp);
1828int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1829 struct drm_file *filp);
1830
1831int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1832 struct drm_file *filp);
1833int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1834 struct drm_file *filp);
1835int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1836 struct drm_file *filp);
1837int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1838 struct drm_file *filp);
1839int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1840 struct drm_file *filp);
1841int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1842 struct drm_file *filp);
1843int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1844int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1845
1846int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1847 struct drm_file *filp);
1848
1849/* VRAM scratch page for HDP bug, default vram page */
1850struct amdgpu_vram_scratch {
1851 struct amdgpu_bo *robj;
1852 volatile uint32_t *ptr;
1853 u64 gpu_addr;
1854};
1855
1856/*
1857 * ACPI
1858 */
1859struct amdgpu_atif_notification_cfg {
1860 bool enabled;
1861 int command_code;
1862};
1863
1864struct amdgpu_atif_notifications {
1865 bool display_switch;
1866 bool expansion_mode_change;
1867 bool thermal_state;
1868 bool forced_power_state;
1869 bool system_power_state;
1870 bool display_conf_change;
1871 bool px_gfx_switch;
1872 bool brightness_change;
1873 bool dgpu_display_event;
1874};
1875
1876struct amdgpu_atif_functions {
1877 bool system_params;
1878 bool sbios_requests;
1879 bool select_active_disp;
1880 bool lid_state;
1881 bool get_tv_standard;
1882 bool set_tv_standard;
1883 bool get_panel_expansion_mode;
1884 bool set_panel_expansion_mode;
1885 bool temperature_change;
1886 bool graphics_device_types;
1887};
1888
1889struct amdgpu_atif {
1890 struct amdgpu_atif_notifications notifications;
1891 struct amdgpu_atif_functions functions;
1892 struct amdgpu_atif_notification_cfg notification_cfg;
1893 struct amdgpu_encoder *encoder_for_bl;
1894};
1895
1896struct amdgpu_atcs_functions {
1897 bool get_ext_state;
1898 bool pcie_perf_req;
1899 bool pcie_dev_rdy;
1900 bool pcie_bus_width;
1901};
1902
1903struct amdgpu_atcs {
1904 struct amdgpu_atcs_functions functions;
1905};
1906
Alex Deucher97b2e202015-04-20 16:51:00 -04001907/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001908 * CGS
1909 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001910struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1911void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001912
1913
Alex Deucher7e471e62016-02-01 11:13:04 -05001914/* GPU virtualization */
1915struct amdgpu_virtualization {
1916 bool supports_sr_iov;
1917};
1918
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001919/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001920 * Core structure, functions and helpers.
1921 */
1922typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1923typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1924
1925typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1926typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1927
Alex Deucher8faf0e02015-07-28 11:50:31 -04001928struct amdgpu_ip_block_status {
1929 bool valid;
1930 bool sw;
1931 bool hw;
1932};
1933
Alex Deucher97b2e202015-04-20 16:51:00 -04001934struct amdgpu_device {
1935 struct device *dev;
1936 struct drm_device *ddev;
1937 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001938
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001939#ifdef CONFIG_DRM_AMD_ACP
1940 struct amdgpu_acp acp;
1941#endif
1942
Alex Deucher97b2e202015-04-20 16:51:00 -04001943 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001944 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001945 uint32_t family;
1946 uint32_t rev_id;
1947 uint32_t external_rev_id;
1948 unsigned long flags;
1949 int usec_timeout;
1950 const struct amdgpu_asic_funcs *asic_funcs;
1951 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001952 bool need_dma32;
1953 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001954 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001955 struct notifier_block acpi_nb;
1956 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1957 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001958 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001959#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001960 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001961#endif
1962 struct amdgpu_atif atif;
1963 struct amdgpu_atcs atcs;
1964 struct mutex srbm_mutex;
1965 /* GRBM index mutex. Protects concurrent access to GRBM index */
1966 struct mutex grbm_idx_mutex;
1967 struct dev_pm_domain vga_pm_domain;
1968 bool have_disp_power_ref;
1969
1970 /* BIOS */
1971 uint8_t *bios;
1972 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001973 struct amdgpu_bo *stollen_vga_memory;
1974 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1975
1976 /* Register/doorbell mmio */
1977 resource_size_t rmmio_base;
1978 resource_size_t rmmio_size;
1979 void __iomem *rmmio;
1980 /* protects concurrent MM_INDEX/DATA based register access */
1981 spinlock_t mmio_idx_lock;
1982 /* protects concurrent SMC based register access */
1983 spinlock_t smc_idx_lock;
1984 amdgpu_rreg_t smc_rreg;
1985 amdgpu_wreg_t smc_wreg;
1986 /* protects concurrent PCIE register access */
1987 spinlock_t pcie_idx_lock;
1988 amdgpu_rreg_t pcie_rreg;
1989 amdgpu_wreg_t pcie_wreg;
1990 /* protects concurrent UVD register access */
1991 spinlock_t uvd_ctx_idx_lock;
1992 amdgpu_rreg_t uvd_ctx_rreg;
1993 amdgpu_wreg_t uvd_ctx_wreg;
1994 /* protects concurrent DIDT register access */
1995 spinlock_t didt_idx_lock;
1996 amdgpu_rreg_t didt_rreg;
1997 amdgpu_wreg_t didt_wreg;
1998 /* protects concurrent ENDPOINT (audio) register access */
1999 spinlock_t audio_endpt_idx_lock;
2000 amdgpu_block_rreg_t audio_endpt_rreg;
2001 amdgpu_block_wreg_t audio_endpt_wreg;
2002 void __iomem *rio_mem;
2003 resource_size_t rio_mem_size;
2004 struct amdgpu_doorbell doorbell;
2005
2006 /* clock/pll info */
2007 struct amdgpu_clock clock;
2008
2009 /* MC */
2010 struct amdgpu_mc mc;
2011 struct amdgpu_gart gart;
2012 struct amdgpu_dummy_page dummy_page;
2013 struct amdgpu_vm_manager vm_manager;
2014
2015 /* memory management */
2016 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002017 struct amdgpu_vram_scratch vram_scratch;
2018 struct amdgpu_wb wb;
2019 atomic64_t vram_usage;
2020 atomic64_t vram_vis_usage;
2021 atomic64_t gtt_usage;
2022 atomic64_t num_bytes_moved;
Marek Olšákd94aed52015-05-05 21:13:49 +02002023 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002024
2025 /* display */
2026 struct amdgpu_mode_info mode_info;
2027 struct work_struct hotplug_work;
2028 struct amdgpu_irq_src crtc_irq;
2029 struct amdgpu_irq_src pageflip_irq;
2030 struct amdgpu_irq_src hpd_irq;
2031
2032 /* rings */
Alex Deucher97b2e202015-04-20 16:51:00 -04002033 unsigned fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002034 unsigned num_rings;
2035 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2036 bool ib_pool_ready;
2037 struct amdgpu_sa_manager ring_tmp_bo;
2038
2039 /* interrupts */
2040 struct amdgpu_irq irq;
2041
Alex Deucher1f7371b2015-12-02 17:46:21 -05002042 /* powerplay */
2043 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002044 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002045 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002046
Alex Deucher97b2e202015-04-20 16:51:00 -04002047 /* dpm */
2048 struct amdgpu_pm pm;
2049 u32 cg_flags;
2050 u32 pg_flags;
2051
2052 /* amdgpu smumgr */
2053 struct amdgpu_smumgr smu;
2054
2055 /* gfx */
2056 struct amdgpu_gfx gfx;
2057
2058 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002059 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002060
2061 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002062 struct amdgpu_uvd uvd;
2063
2064 /* vce */
2065 struct amdgpu_vce vce;
2066
2067 /* firmwares */
2068 struct amdgpu_firmware firmware;
2069
2070 /* GDS */
2071 struct amdgpu_gds gds;
2072
2073 const struct amdgpu_ip_block_version *ip_blocks;
2074 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002075 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002076 struct mutex mn_lock;
2077 DECLARE_HASHTABLE(mn_hash, 7);
2078
2079 /* tracking pinned memory */
2080 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002081 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002082 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002083
2084 /* amdkfd interface */
2085 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002086
Alex Deucher7e471e62016-02-01 11:13:04 -05002087 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002088};
2089
2090bool amdgpu_device_is_px(struct drm_device *dev);
2091int amdgpu_device_init(struct amdgpu_device *adev,
2092 struct drm_device *ddev,
2093 struct pci_dev *pdev,
2094 uint32_t flags);
2095void amdgpu_device_fini(struct amdgpu_device *adev);
2096int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2097
2098uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2099 bool always_indirect);
2100void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2101 bool always_indirect);
2102u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2103void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2104
2105u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2106void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2107
2108/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002109 * Registers read & write functions.
2110 */
2111#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2112#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2113#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2114#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2115#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2116#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2117#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2118#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2119#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2120#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2121#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2122#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2123#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2124#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2125#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2126#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2127#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2128#define WREG32_P(reg, val, mask) \
2129 do { \
2130 uint32_t tmp_ = RREG32(reg); \
2131 tmp_ &= (mask); \
2132 tmp_ |= ((val) & ~(mask)); \
2133 WREG32(reg, tmp_); \
2134 } while (0)
2135#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2136#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2137#define WREG32_PLL_P(reg, val, mask) \
2138 do { \
2139 uint32_t tmp_ = RREG32_PLL(reg); \
2140 tmp_ &= (mask); \
2141 tmp_ |= ((val) & ~(mask)); \
2142 WREG32_PLL(reg, tmp_); \
2143 } while (0)
2144#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2145#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2146#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2147
2148#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2149#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2150
2151#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2152#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2153
2154#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2155 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2156 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2157
2158#define REG_GET_FIELD(value, reg, field) \
2159 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2160
2161/*
2162 * BIOS helpers.
2163 */
2164#define RBIOS8(i) (adev->bios[i])
2165#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2166#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2167
2168/*
2169 * RING helpers.
2170 */
2171static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2172{
2173 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002174 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002175 ring->ring[ring->wptr++] = v;
2176 ring->wptr &= ring->ptr_mask;
2177 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002178}
2179
Alex Deucherc113ea12015-10-08 16:30:37 -04002180static inline struct amdgpu_sdma_instance *
2181amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002182{
2183 struct amdgpu_device *adev = ring->adev;
2184 int i;
2185
Alex Deucherc113ea12015-10-08 16:30:37 -04002186 for (i = 0; i < adev->sdma.num_instances; i++)
2187 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002188 break;
2189
2190 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002191 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002192 else
2193 return NULL;
2194}
2195
Alex Deucher97b2e202015-04-20 16:51:00 -04002196/*
2197 * ASICs macro.
2198 */
2199#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2200#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
2201#define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
2202#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2203#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2204#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2205#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2206#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002207#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 -04002208#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 -04002209#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2210#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2211#define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Christian Königb07c9d22015-11-30 13:26:07 +01002212#define amdgpu_vm_write_pte(adev, ib, pa, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pa), (pe), (addr), (count), (incr), (flags)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002213#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 -04002214#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2215#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2216#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002217#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2218#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2219#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002220#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 +01002221#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002222#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002223#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002224#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 +02002225#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002226#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002227#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002228#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2229#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04002230#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2231#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2232#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2233#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2234#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2235#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2236#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2237#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2238#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2239#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2240#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2241#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2242#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002243#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 -04002244#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2245#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2246#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))
2247#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2248#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002249#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 +08002250#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 -04002251#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2252#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2253#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2254#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002255#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002256#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002257#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Rex Zhu3af76f22015-10-15 17:23:43 +08002258
2259#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002260 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002261 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002262 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002263
2264#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002265 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002266 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002267 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002268
2269#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002270 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002271 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002272 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002273
2274#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002275 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002276 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002277 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002278
2279#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002280 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002281 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002282 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002283
Rex Zhu1b5708f2015-11-10 18:25:24 -05002284#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002285 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002286 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002287 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002288
2289#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002290 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002291 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002292 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002293
2294
2295#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002296 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002297 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002298 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002299
2300#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002301 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002302 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002303 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002304
2305#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002306 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002307 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002308 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002309
2310#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002311 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002312 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002313 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002314
2315#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002316 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002317
2318#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002319 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002320
Eric Huangf3898ea2015-12-11 16:24:34 -05002321#define amdgpu_dpm_get_pp_num_states(adev, data) \
2322 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2323
2324#define amdgpu_dpm_get_pp_table(adev, table) \
2325 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2326
2327#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2328 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2329
2330#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2331 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2332
2333#define amdgpu_dpm_force_clock_level(adev, type, level) \
2334 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2335
Jammy Zhoue61710c2015-11-10 18:31:08 -05002336#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002337 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002338
2339#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2340
2341/* Common functions */
2342int amdgpu_gpu_reset(struct amdgpu_device *adev);
2343void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2344bool amdgpu_card_posted(struct amdgpu_device *adev);
2345void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002346
Alex Deucher97b2e202015-04-20 16:51:00 -04002347int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2348int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2349 u32 ip_instance, u32 ring,
2350 struct amdgpu_ring **out_ring);
2351void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2352bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002353int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002354int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2355 uint32_t flags);
2356bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002357struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002358bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2359 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002360bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2361 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002362bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2363uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2364 struct ttm_mem_reg *mem);
2365void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2366void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2367void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2368void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2369 const u32 *registers,
2370 const u32 array_size);
2371
2372bool amdgpu_device_is_px(struct drm_device *dev);
2373/* atpx handler */
2374#if defined(CONFIG_VGA_SWITCHEROO)
2375void amdgpu_register_atpx_handler(void);
2376void amdgpu_unregister_atpx_handler(void);
2377#else
2378static inline void amdgpu_register_atpx_handler(void) {}
2379static inline void amdgpu_unregister_atpx_handler(void) {}
2380#endif
2381
2382/*
2383 * KMS
2384 */
2385extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002386extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002387
2388int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2389int amdgpu_driver_unload_kms(struct drm_device *dev);
2390void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2391int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2392void amdgpu_driver_postclose_kms(struct drm_device *dev,
2393 struct drm_file *file_priv);
2394void amdgpu_driver_preclose_kms(struct drm_device *dev,
2395 struct drm_file *file_priv);
2396int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2397int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002398u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2399int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2400void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2401int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002402 int *max_error,
2403 struct timeval *vblank_time,
2404 unsigned flags);
2405long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2406 unsigned long arg);
2407
2408/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002409 * functions used by amdgpu_encoder.c
2410 */
2411struct amdgpu_afmt_acr {
2412 u32 clock;
2413
2414 int n_32khz;
2415 int cts_32khz;
2416
2417 int n_44_1khz;
2418 int cts_44_1khz;
2419
2420 int n_48khz;
2421 int cts_48khz;
2422
2423};
2424
2425struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2426
2427/* amdgpu_acpi.c */
2428#if defined(CONFIG_ACPI)
2429int amdgpu_acpi_init(struct amdgpu_device *adev);
2430void amdgpu_acpi_fini(struct amdgpu_device *adev);
2431bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2432int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2433 u8 perf_req, bool advertise);
2434int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2435#else
2436static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2437static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2438#endif
2439
2440struct amdgpu_bo_va_mapping *
2441amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2442 uint64_t addr, struct amdgpu_bo **bo);
2443
2444#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002445#endif