blob: e42b0a357fb8cd5533085dd53aaea611376fc065 [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,
286 struct amdgpu_ib *ib);
287 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800288 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100289 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400290 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
291 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200292 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800293 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400294 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
295 uint32_t gds_base, uint32_t gds_size,
296 uint32_t gws_base, uint32_t gws_size,
297 uint32_t oa_base, uint32_t oa_size);
298 /* testing functions */
299 int (*test_ring)(struct amdgpu_ring *ring);
300 int (*test_ib)(struct amdgpu_ring *ring);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800301 /* insert NOP packets */
302 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100303 /* pad the indirect buffer to the necessary number of dw */
304 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800305 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
306 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Alex Deucher97b2e202015-04-20 16:51:00 -0400307};
308
309/*
310 * BIOS.
311 */
312bool amdgpu_get_bios(struct amdgpu_device *adev);
313bool amdgpu_read_bios(struct amdgpu_device *adev);
314
315/*
316 * Dummy page
317 */
318struct amdgpu_dummy_page {
319 struct page *page;
320 dma_addr_t addr;
321};
322int amdgpu_dummy_page_init(struct amdgpu_device *adev);
323void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
324
325
326/*
327 * Clocks
328 */
329
330#define AMDGPU_MAX_PPLL 3
331
332struct amdgpu_clock {
333 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
334 struct amdgpu_pll spll;
335 struct amdgpu_pll mpll;
336 /* 10 Khz units */
337 uint32_t default_mclk;
338 uint32_t default_sclk;
339 uint32_t default_dispclk;
340 uint32_t current_dispclk;
341 uint32_t dp_extclk;
342 uint32_t max_pixel_clock;
343};
344
345/*
346 * Fences.
347 */
348struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400349 uint64_t gpu_addr;
350 volatile uint32_t *cpu_addr;
351 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100352 uint32_t sync_seq;
353 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400354 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400355 struct amdgpu_irq_src *irq_src;
356 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100357 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100358 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100359 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100360 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400361};
362
363/* some special values for the owner field */
364#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
365#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Chunming Zhou031e2982016-04-25 10:19:13 +0800366#define AMDGPU_CLIENT_ID_RESERVED 2
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 -0400371struct amdgpu_user_fence {
372 /* write-back bo */
373 struct amdgpu_bo *bo;
374 /* write-back address offset to bo start */
375 uint32_t offset;
376};
377
378int amdgpu_fence_driver_init(struct amdgpu_device *adev);
379void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
380void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
381
Christian Könige6151a02016-03-15 14:52:26 +0100382int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
383 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400384int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
385 struct amdgpu_irq_src *irq_src,
386 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400387void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
388void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100389int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400390void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400391int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
392unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
393
Alex Deucher97b2e202015-04-20 16:51:00 -0400394/*
395 * TTM.
396 */
Christian König29b32592016-04-15 17:19:16 +0200397
398#define AMDGPU_TTM_LRU_SIZE 20
399
400struct amdgpu_mman_lru {
401 struct list_head *lru[TTM_NUM_MEM_TYPES];
402 struct list_head *swap_lru;
403};
404
Alex Deucher97b2e202015-04-20 16:51:00 -0400405struct amdgpu_mman {
406 struct ttm_bo_global_ref bo_global_ref;
407 struct drm_global_reference mem_global_ref;
408 struct ttm_bo_device bdev;
409 bool mem_global_referenced;
410 bool initialized;
411
412#if defined(CONFIG_DEBUG_FS)
413 struct dentry *vram;
414 struct dentry *gtt;
415#endif
416
417 /* buffer handling */
418 const struct amdgpu_buffer_funcs *buffer_funcs;
419 struct amdgpu_ring *buffer_funcs_ring;
Christian König703297c2016-02-10 14:20:50 +0100420 /* Scheduler entity for buffer moves */
421 struct amd_sched_entity entity;
Christian König29b32592016-04-15 17:19:16 +0200422
423 /* custom LRU management */
424 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE];
Alex Deucher97b2e202015-04-20 16:51:00 -0400425};
426
427int amdgpu_copy_buffer(struct amdgpu_ring *ring,
428 uint64_t src_offset,
429 uint64_t dst_offset,
430 uint32_t byte_count,
431 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800432 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400433int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
434
435struct amdgpu_bo_list_entry {
436 struct amdgpu_bo *robj;
437 struct ttm_validate_buffer tv;
438 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400439 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100440 struct page **user_pages;
441 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400442};
443
444struct amdgpu_bo_va_mapping {
445 struct list_head list;
446 struct interval_tree_node it;
447 uint64_t offset;
448 uint32_t flags;
449};
450
451/* bo virtual addresses in a specific vm */
452struct amdgpu_bo_va {
453 /* protected by bo being reserved */
454 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800455 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400456 unsigned ref_count;
457
Christian König7fc11952015-07-30 11:53:42 +0200458 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400459 struct list_head vm_status;
460
Christian König7fc11952015-07-30 11:53:42 +0200461 /* mappings for this bo_va */
462 struct list_head invalids;
463 struct list_head valids;
464
Alex Deucher97b2e202015-04-20 16:51:00 -0400465 /* constant after initialization */
466 struct amdgpu_vm *vm;
467 struct amdgpu_bo *bo;
468};
469
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800470#define AMDGPU_GEM_DOMAIN_MAX 0x3
471
Alex Deucher97b2e202015-04-20 16:51:00 -0400472struct amdgpu_bo {
473 /* Protected by gem.mutex */
474 struct list_head list;
475 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100476 u32 prefered_domains;
477 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800478 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400479 struct ttm_placement placement;
480 struct ttm_buffer_object tbo;
481 struct ttm_bo_kmap_obj kmap;
482 u64 flags;
483 unsigned pin_count;
484 void *kptr;
485 u64 tiling_flags;
486 u64 metadata_flags;
487 void *metadata;
488 u32 metadata_size;
489 /* list of all virtual address to which this bo
490 * is associated to
491 */
492 struct list_head va;
493 /* Constant after initialization */
494 struct amdgpu_device *adev;
495 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100496 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400497
498 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400499 struct amdgpu_mn *mn;
500 struct list_head mn_list;
501};
502#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
503
504void amdgpu_gem_object_free(struct drm_gem_object *obj);
505int amdgpu_gem_object_open(struct drm_gem_object *obj,
506 struct drm_file *file_priv);
507void amdgpu_gem_object_close(struct drm_gem_object *obj,
508 struct drm_file *file_priv);
509unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
510struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200511struct drm_gem_object *
512amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
513 struct dma_buf_attachment *attach,
514 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400515struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
516 struct drm_gem_object *gobj,
517 int flags);
518int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
519void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
520struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
521void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
522void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
523int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
524
525/* sub-allocation manager, it has to be protected by another lock.
526 * By conception this is an helper for other part of the driver
527 * like the indirect buffer or semaphore, which both have their
528 * locking.
529 *
530 * Principe is simple, we keep a list of sub allocation in offset
531 * order (first entry has offset == 0, last entry has the highest
532 * offset).
533 *
534 * When allocating new object we first check if there is room at
535 * the end total_size - (last_object_offset + last_object_size) >=
536 * alloc_size. If so we allocate new object there.
537 *
538 * When there is not enough room at the end, we start waiting for
539 * each sub object until we reach object_offset+object_size >=
540 * alloc_size, this object then become the sub object we return.
541 *
542 * Alignment can't be bigger than page size.
543 *
544 * Hole are not considered for allocation to keep things simple.
545 * Assumption is that there won't be hole (all object on same
546 * alignment).
547 */
Christian König6ba60b82016-03-11 14:50:08 +0100548
549#define AMDGPU_SA_NUM_FENCE_LISTS 32
550
Alex Deucher97b2e202015-04-20 16:51:00 -0400551struct amdgpu_sa_manager {
552 wait_queue_head_t wq;
553 struct amdgpu_bo *bo;
554 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100555 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400556 struct list_head olist;
557 unsigned size;
558 uint64_t gpu_addr;
559 void *cpu_ptr;
560 uint32_t domain;
561 uint32_t align;
562};
563
Alex Deucher97b2e202015-04-20 16:51:00 -0400564/* sub-allocation buffer */
565struct amdgpu_sa_bo {
566 struct list_head olist;
567 struct list_head flist;
568 struct amdgpu_sa_manager *manager;
569 unsigned soffset;
570 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800571 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400572};
573
574/*
575 * GEM objects.
576 */
Christian König418aa0c2016-02-15 16:59:57 +0100577void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400578int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
579 int alignment, u32 initial_domain,
580 u64 flags, bool kernel,
581 struct drm_gem_object **obj);
582
583int amdgpu_mode_dumb_create(struct drm_file *file_priv,
584 struct drm_device *dev,
585 struct drm_mode_create_dumb *args);
586int amdgpu_mode_dumb_mmap(struct drm_file *filp,
587 struct drm_device *dev,
588 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400589/*
590 * Synchronization
591 */
592struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800593 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800594 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400595};
596
597void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200598int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
599 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400600int amdgpu_sync_resv(struct amdgpu_device *adev,
601 struct amdgpu_sync *sync,
602 struct reservation_object *resv,
603 void *owner);
Christian König832a9022016-02-15 12:33:02 +0100604bool amdgpu_sync_is_idle(struct amdgpu_sync *sync);
605int amdgpu_sync_cycle_fences(struct amdgpu_sync *dst, struct amdgpu_sync *src,
606 struct fence *fence);
Christian Könige61235d2015-08-25 11:05:36 +0200607struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian Königf91b3a62015-08-20 14:47:40 +0800608int amdgpu_sync_wait(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100609void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100610int amdgpu_sync_init(void);
611void amdgpu_sync_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400612
613/*
614 * GART structures, functions & helpers
615 */
616struct amdgpu_mc;
617
618#define AMDGPU_GPU_PAGE_SIZE 4096
619#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
620#define AMDGPU_GPU_PAGE_SHIFT 12
621#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
622
623struct amdgpu_gart {
624 dma_addr_t table_addr;
625 struct amdgpu_bo *robj;
626 void *ptr;
627 unsigned num_gpu_pages;
628 unsigned num_cpu_pages;
629 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200630#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400631 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200632#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400633 bool ready;
634 const struct amdgpu_gart_funcs *gart_funcs;
635};
636
637int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
638void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
639int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
640void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
641int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
642void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
643int amdgpu_gart_init(struct amdgpu_device *adev);
644void amdgpu_gart_fini(struct amdgpu_device *adev);
645void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
646 int pages);
647int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
648 int pages, struct page **pagelist,
649 dma_addr_t *dma_addr, uint32_t flags);
650
651/*
652 * GPU MC structures, functions & helpers
653 */
654struct amdgpu_mc {
655 resource_size_t aper_size;
656 resource_size_t aper_base;
657 resource_size_t agp_base;
658 /* for some chips with <= 32MB we need to lie
659 * about vram size near mc fb location */
660 u64 mc_vram_size;
661 u64 visible_vram_size;
662 u64 gtt_size;
663 u64 gtt_start;
664 u64 gtt_end;
665 u64 vram_start;
666 u64 vram_end;
667 unsigned vram_width;
668 u64 real_vram_size;
669 int vram_mtrr;
670 u64 gtt_base_align;
671 u64 mc_mask;
672 const struct firmware *fw; /* MC firmware */
673 uint32_t fw_version;
674 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800675 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400676};
677
678/*
679 * GPU doorbell structures, functions & helpers
680 */
681typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
682{
683 AMDGPU_DOORBELL_KIQ = 0x000,
684 AMDGPU_DOORBELL_HIQ = 0x001,
685 AMDGPU_DOORBELL_DIQ = 0x002,
686 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
687 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
688 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
689 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
690 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
691 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
692 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
693 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
694 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
695 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
696 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
697 AMDGPU_DOORBELL_IH = 0x1E8,
698 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
699 AMDGPU_DOORBELL_INVALID = 0xFFFF
700} AMDGPU_DOORBELL_ASSIGNMENT;
701
702struct amdgpu_doorbell {
703 /* doorbell mmio */
704 resource_size_t base;
705 resource_size_t size;
706 u32 __iomem *ptr;
707 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
708};
709
710void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
711 phys_addr_t *aperture_base,
712 size_t *aperture_size,
713 size_t *start_offset);
714
715/*
716 * IRQS.
717 */
718
719struct amdgpu_flip_work {
720 struct work_struct flip_work;
721 struct work_struct unpin_work;
722 struct amdgpu_device *adev;
723 int crtc_id;
724 uint64_t base;
725 struct drm_pending_vblank_event *event;
726 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200727 struct fence *excl;
728 unsigned shared_count;
729 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100730 struct fence_cb cb;
Alex Deucher97b2e202015-04-20 16:51:00 -0400731};
732
733
734/*
735 * CP & rings.
736 */
737
738struct amdgpu_ib {
739 struct amdgpu_sa_bo *sa_bo;
740 uint32_t length_dw;
741 uint64_t gpu_addr;
742 uint32_t *ptr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400743 struct amdgpu_user_fence *user;
Christian König4ff37a82016-02-26 16:18:26 +0100744 unsigned vm_id;
745 uint64_t vm_pd_addr;
Christian König3cb485f2015-05-11 15:34:59 +0200746 struct amdgpu_ctx *ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400747 uint32_t gds_base, gds_size;
748 uint32_t gws_base, gws_size;
749 uint32_t oa_base, oa_size;
Jammy Zhoude807f82015-05-11 23:41:41 +0800750 uint32_t flags;
Christian König5430a3f2015-07-21 18:02:21 +0200751 /* resulting sequence number */
752 uint64_t sequence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400753};
754
755enum amdgpu_ring_type {
756 AMDGPU_RING_TYPE_GFX,
757 AMDGPU_RING_TYPE_COMPUTE,
758 AMDGPU_RING_TYPE_SDMA,
759 AMDGPU_RING_TYPE_UVD,
760 AMDGPU_RING_TYPE_VCE
761};
762
Nils Wallménius62250a92016-04-10 16:30:00 +0200763extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800764
Christian König50838c82016-02-03 13:44:52 +0100765int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800766 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100767int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
768 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800769
Christian König50838c82016-02-03 13:44:52 +0100770void amdgpu_job_free(struct amdgpu_job *job);
Monk Liub6723c82016-03-10 12:14:44 +0800771void amdgpu_job_free_func(struct kref *refcount);
Christian Königd71518b2016-02-01 12:20:25 +0100772int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100773 struct amd_sched_entity *entity, void *owner,
774 struct fence **f);
Monk Liu0de24792016-03-04 18:51:02 +0800775void amdgpu_job_timeout_func(struct work_struct *work);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800776
Alex Deucher97b2e202015-04-20 16:51:00 -0400777struct amdgpu_ring {
778 struct amdgpu_device *adev;
779 const struct amdgpu_ring_funcs *funcs;
780 struct amdgpu_fence_driver fence_drv;
Christian König4f839a22015-09-08 20:22:31 +0200781 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400782
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800783 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400784 struct amdgpu_bo *ring_obj;
785 volatile uint32_t *ring;
786 unsigned rptr_offs;
787 u64 next_rptr_gpu_addr;
788 volatile u32 *next_rptr_cpu_addr;
789 unsigned wptr;
790 unsigned wptr_old;
791 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100792 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400793 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400794 uint64_t gpu_addr;
795 uint32_t align_mask;
796 uint32_t ptr_mask;
797 bool ready;
798 u32 nop;
799 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400800 u32 me;
801 u32 pipe;
802 u32 queue;
803 struct amdgpu_bo *mqd_obj;
804 u32 doorbell_index;
805 bool use_doorbell;
806 unsigned wptr_offs;
807 unsigned next_rptr_offs;
808 unsigned fence_offs;
Christian König3cb485f2015-05-11 15:34:59 +0200809 struct amdgpu_ctx *current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400810 enum amdgpu_ring_type type;
811 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800812 unsigned cond_exe_offs;
813 u64 cond_exe_gpu_addr;
814 volatile u32 *cond_exe_cpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400815};
816
817/*
818 * VM
819 */
820
821/* maximum number of VMIDs */
822#define AMDGPU_NUM_VM 16
823
824/* number of entries in page table */
825#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
826
827/* PTBs (Page Table Blocks) need to be aligned to 32K */
828#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
829#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
830#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
831
832#define AMDGPU_PTE_VALID (1 << 0)
833#define AMDGPU_PTE_SYSTEM (1 << 1)
834#define AMDGPU_PTE_SNOOPED (1 << 2)
835
836/* VI only */
837#define AMDGPU_PTE_EXECUTABLE (1 << 4)
838
839#define AMDGPU_PTE_READABLE (1 << 5)
840#define AMDGPU_PTE_WRITEABLE (1 << 6)
841
842/* PTE (Page Table Entry) fragment field for different page sizes */
843#define AMDGPU_PTE_FRAG_4KB (0 << 7)
844#define AMDGPU_PTE_FRAG_64KB (4 << 7)
845#define AMDGPU_LOG2_PAGES_PER_FRAG 4
846
Christian Königd9c13152015-09-28 12:31:26 +0200847/* How to programm VM fault handling */
848#define AMDGPU_VM_FAULT_STOP_NEVER 0
849#define AMDGPU_VM_FAULT_STOP_FIRST 1
850#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
851
Alex Deucher97b2e202015-04-20 16:51:00 -0400852struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100853 struct amdgpu_bo_list_entry entry;
854 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400855};
856
Alex Deucher97b2e202015-04-20 16:51:00 -0400857struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100858 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400859 struct rb_root va;
860
Christian König7fc11952015-07-30 11:53:42 +0200861 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400862 spinlock_t status_lock;
863
864 /* BOs moved, but not yet updated in the PT */
865 struct list_head invalidated;
866
Christian König7fc11952015-07-30 11:53:42 +0200867 /* BOs cleared in the PT because of a move */
868 struct list_head cleared;
869
870 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400871 struct list_head freed;
872
873 /* contains the page directory */
874 struct amdgpu_bo *page_directory;
875 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200876 struct fence *page_directory_fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400877
878 /* array of page tables, one for each page directory entry */
879 struct amdgpu_vm_pt *page_tables;
880
881 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100882 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100883
jimqu81d75a32015-12-04 17:17:00 +0800884 /* protecting freed */
885 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100886
887 /* Scheduler entity for page table updates */
888 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800889
890 /* client id */
891 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400892};
893
Christian Königbcb1ba32016-03-08 15:40:11 +0100894struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100895 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100896 struct fence *first;
897 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100898 struct fence *last_flush;
Chunming Zhou68befeb2016-04-14 13:42:32 +0800899 struct amdgpu_ring *last_user;
Christian Königa9a78b32016-01-21 10:19:11 +0100900 atomic_long_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100901
Christian Königbcb1ba32016-03-08 15:40:11 +0100902 uint64_t pd_gpu_addr;
903 /* last flushed PD/PT update */
904 struct fence *flushed_updates;
905
Christian König971fe9a92016-03-01 15:09:25 +0100906 uint32_t gds_base;
907 uint32_t gds_size;
908 uint32_t gws_base;
909 uint32_t gws_size;
910 uint32_t oa_base;
911 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100912};
Christian König8d0a7ce2015-11-03 20:58:50 +0100913
Christian Königa9a78b32016-01-21 10:19:11 +0100914struct amdgpu_vm_manager {
915 /* Handling of VMIDs */
916 struct mutex lock;
917 unsigned num_ids;
918 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100919 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100920
Christian König8b4fb002015-11-15 16:04:16 +0100921 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400922 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100923 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400924 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100925 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400926 /* vm pte handling */
927 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100928 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
929 unsigned vm_pte_num_rings;
930 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800931 /* client id counter */
932 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400933};
934
Christian Königa9a78b32016-01-21 10:19:11 +0100935void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100936void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100937int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
938void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100939void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
940 struct list_head *validated,
941 struct amdgpu_bo_list_entry *entry);
Christian Königee1782c2015-12-11 21:01:23 +0100942void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100943void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
944 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100945int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100946 struct amdgpu_sync *sync, struct fence *fence,
947 unsigned *vm_id, uint64_t *vm_pd_addr);
Christian König41d9eb22016-03-01 16:46:18 +0100948int amdgpu_vm_flush(struct amdgpu_ring *ring,
949 unsigned vm_id, uint64_t pd_addr,
950 uint32_t gds_base, uint32_t gds_size,
951 uint32_t gws_base, uint32_t gws_size,
952 uint32_t oa_base, uint32_t oa_size);
Christian König971fe9a92016-03-01 15:09:25 +0100953void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian Königb07c9d22015-11-30 13:26:07 +0100954uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
Christian König8b4fb002015-11-15 16:04:16 +0100955int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
956 struct amdgpu_vm *vm);
957int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
958 struct amdgpu_vm *vm);
959int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
960 struct amdgpu_sync *sync);
961int amdgpu_vm_bo_update(struct amdgpu_device *adev,
962 struct amdgpu_bo_va *bo_va,
963 struct ttm_mem_reg *mem);
964void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
965 struct amdgpu_bo *bo);
966struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
967 struct amdgpu_bo *bo);
968struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
969 struct amdgpu_vm *vm,
970 struct amdgpu_bo *bo);
971int amdgpu_vm_bo_map(struct amdgpu_device *adev,
972 struct amdgpu_bo_va *bo_va,
973 uint64_t addr, uint64_t offset,
974 uint64_t size, uint32_t flags);
975int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
976 struct amdgpu_bo_va *bo_va,
977 uint64_t addr);
978void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
979 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100980
Alex Deucher97b2e202015-04-20 16:51:00 -0400981/*
982 * context related structures
983 */
984
Christian König21c16bf2015-07-07 17:24:49 +0200985struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200986 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800987 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200988 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200989};
990
Alex Deucher97b2e202015-04-20 16:51:00 -0400991struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400992 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800993 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400994 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200995 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800996 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200997 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400998};
999
1000struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -04001001 struct amdgpu_device *adev;
1002 struct mutex lock;
1003 /* protected by lock */
1004 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001005};
1006
Alex Deucher0b492a42015-08-16 22:48:26 -04001007struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
1008int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
1009
Christian König21c16bf2015-07-07 17:24:49 +02001010uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +02001011 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +02001012struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
1013 struct amdgpu_ring *ring, uint64_t seq);
1014
Alex Deucher0b492a42015-08-16 22:48:26 -04001015int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1016 struct drm_file *filp);
1017
Christian Königefd4ccb2015-08-04 16:20:31 +02001018void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1019void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -04001020
Alex Deucher97b2e202015-04-20 16:51:00 -04001021/*
1022 * file private structure
1023 */
1024
1025struct amdgpu_fpriv {
1026 struct amdgpu_vm vm;
1027 struct mutex bo_list_lock;
1028 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001029 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001030};
1031
1032/*
1033 * residency list
1034 */
1035
1036struct amdgpu_bo_list {
1037 struct mutex lock;
1038 struct amdgpu_bo *gds_obj;
1039 struct amdgpu_bo *gws_obj;
1040 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001041 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001042 unsigned num_entries;
1043 struct amdgpu_bo_list_entry *array;
1044};
1045
1046struct amdgpu_bo_list *
1047amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001048void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1049 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001050void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1051void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1052
1053/*
1054 * GFX stuff
1055 */
1056#include "clearstate_defs.h"
1057
Alex Deucher79e54122016-04-08 15:45:13 -04001058struct amdgpu_rlc_funcs {
1059 void (*enter_safe_mode)(struct amdgpu_device *adev);
1060 void (*exit_safe_mode)(struct amdgpu_device *adev);
1061};
1062
Alex Deucher97b2e202015-04-20 16:51:00 -04001063struct amdgpu_rlc {
1064 /* for power gating */
1065 struct amdgpu_bo *save_restore_obj;
1066 uint64_t save_restore_gpu_addr;
1067 volatile uint32_t *sr_ptr;
1068 const u32 *reg_list;
1069 u32 reg_list_size;
1070 /* for clear state */
1071 struct amdgpu_bo *clear_state_obj;
1072 uint64_t clear_state_gpu_addr;
1073 volatile uint32_t *cs_ptr;
1074 const struct cs_section_def *cs_data;
1075 u32 clear_state_size;
1076 /* for cp tables */
1077 struct amdgpu_bo *cp_table_obj;
1078 uint64_t cp_table_gpu_addr;
1079 volatile uint32_t *cp_table_ptr;
1080 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001081
1082 /* safe mode for updating CG/PG state */
1083 bool in_safe_mode;
1084 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001085
1086 /* for firmware data */
1087 u32 save_and_restore_offset;
1088 u32 clear_state_descriptor_offset;
1089 u32 avail_scratch_ram_locations;
1090 u32 reg_restore_list_size;
1091 u32 reg_list_format_start;
1092 u32 reg_list_format_separate_start;
1093 u32 starting_offsets_start;
1094 u32 reg_list_format_size_bytes;
1095 u32 reg_list_size_bytes;
1096
1097 u32 *register_list_format;
1098 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001099};
1100
1101struct amdgpu_mec {
1102 struct amdgpu_bo *hpd_eop_obj;
1103 u64 hpd_eop_gpu_addr;
1104 u32 num_pipe;
1105 u32 num_mec;
1106 u32 num_queue;
1107};
1108
1109/*
1110 * GPU scratch registers structures, functions & helpers
1111 */
1112struct amdgpu_scratch {
1113 unsigned num_reg;
1114 uint32_t reg_base;
1115 bool free[32];
1116 uint32_t reg[32];
1117};
1118
1119/*
1120 * GFX configurations
1121 */
1122struct amdgpu_gca_config {
1123 unsigned max_shader_engines;
1124 unsigned max_tile_pipes;
1125 unsigned max_cu_per_sh;
1126 unsigned max_sh_per_se;
1127 unsigned max_backends_per_se;
1128 unsigned max_texture_channel_caches;
1129 unsigned max_gprs;
1130 unsigned max_gs_threads;
1131 unsigned max_hw_contexts;
1132 unsigned sc_prim_fifo_size_frontend;
1133 unsigned sc_prim_fifo_size_backend;
1134 unsigned sc_hiz_tile_fifo_size;
1135 unsigned sc_earlyz_tile_fifo_size;
1136
1137 unsigned num_tile_pipes;
1138 unsigned backend_enable_mask;
1139 unsigned mem_max_burst_length_bytes;
1140 unsigned mem_row_size_in_kb;
1141 unsigned shader_engine_tile_size;
1142 unsigned num_gpus;
1143 unsigned multi_gpu_tile_size;
1144 unsigned mc_arb_ramcfg;
1145 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001146 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001147
1148 uint32_t tile_mode_array[32];
1149 uint32_t macrotile_mode_array[16];
1150};
1151
1152struct amdgpu_gfx {
1153 struct mutex gpu_clock_mutex;
1154 struct amdgpu_gca_config config;
1155 struct amdgpu_rlc rlc;
1156 struct amdgpu_mec mec;
1157 struct amdgpu_scratch scratch;
1158 const struct firmware *me_fw; /* ME firmware */
1159 uint32_t me_fw_version;
1160 const struct firmware *pfp_fw; /* PFP firmware */
1161 uint32_t pfp_fw_version;
1162 const struct firmware *ce_fw; /* CE firmware */
1163 uint32_t ce_fw_version;
1164 const struct firmware *rlc_fw; /* RLC firmware */
1165 uint32_t rlc_fw_version;
1166 const struct firmware *mec_fw; /* MEC firmware */
1167 uint32_t mec_fw_version;
1168 const struct firmware *mec2_fw; /* MEC2 firmware */
1169 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001170 uint32_t me_feature_version;
1171 uint32_t ce_feature_version;
1172 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001173 uint32_t rlc_feature_version;
1174 uint32_t mec_feature_version;
1175 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001176 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1177 unsigned num_gfx_rings;
1178 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1179 unsigned num_compute_rings;
1180 struct amdgpu_irq_src eop_irq;
1181 struct amdgpu_irq_src priv_reg_irq;
1182 struct amdgpu_irq_src priv_inst_irq;
1183 /* gfx status */
1184 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001185 /* ce ram size*/
1186 unsigned ce_ram_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001187};
1188
Christian Königb07c60c2016-01-31 12:29:04 +01001189int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001190 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001191void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1192 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001193int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001194 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001195 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001196int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1197void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1198int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001199int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001200void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001201void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001202void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001203void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001204unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1205 uint32_t **data);
1206int amdgpu_ring_restore(struct amdgpu_ring *ring,
1207 unsigned size, uint32_t *data);
1208int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1209 unsigned ring_size, u32 nop, u32 align_mask,
1210 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1211 enum amdgpu_ring_type ring_type);
1212void amdgpu_ring_fini(struct amdgpu_ring *ring);
1213
1214/*
1215 * CS.
1216 */
1217struct amdgpu_cs_chunk {
1218 uint32_t chunk_id;
1219 uint32_t length_dw;
1220 uint32_t *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001221};
1222
1223struct amdgpu_cs_parser {
1224 struct amdgpu_device *adev;
1225 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001226 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001227
Alex Deucher97b2e202015-04-20 16:51:00 -04001228 /* chunks */
1229 unsigned nchunks;
1230 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001231
Christian König50838c82016-02-03 13:44:52 +01001232 /* scheduler job object */
1233 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001234
Christian Königc3cca412015-12-15 14:41:33 +01001235 /* buffer objects */
1236 struct ww_acquire_ctx ticket;
1237 struct amdgpu_bo_list *bo_list;
1238 struct amdgpu_bo_list_entry vm_pd;
1239 struct list_head validated;
1240 struct fence *fence;
1241 uint64_t bytes_moved_threshold;
1242 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001243
1244 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001245 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001246};
1247
Chunming Zhoubb977d32015-08-18 15:16:40 +08001248struct amdgpu_job {
1249 struct amd_sched_job base;
1250 struct amdgpu_device *adev;
Monk Liuc5637832016-04-19 20:11:32 +08001251 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001252 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001253 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001254 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001255 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001256 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001257 void *owner;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001258 struct amdgpu_user_fence uf;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001259};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001260#define to_amdgpu_job(sched_job) \
1261 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001262
Christian König7270f832016-01-31 11:00:41 +01001263static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1264 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001265{
Christian König50838c82016-02-03 13:44:52 +01001266 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001267}
1268
Christian König7270f832016-01-31 11:00:41 +01001269static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1270 uint32_t ib_idx, int idx,
1271 uint32_t value)
1272{
Christian König50838c82016-02-03 13:44:52 +01001273 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001274}
1275
Alex Deucher97b2e202015-04-20 16:51:00 -04001276/*
1277 * Writeback
1278 */
1279#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1280
1281struct amdgpu_wb {
1282 struct amdgpu_bo *wb_obj;
1283 volatile uint32_t *wb;
1284 uint64_t gpu_addr;
1285 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1286 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1287};
1288
1289int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1290void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1291
Alex Deucher97b2e202015-04-20 16:51:00 -04001292
Alex Deucher97b2e202015-04-20 16:51:00 -04001293
1294enum amdgpu_int_thermal_type {
1295 THERMAL_TYPE_NONE,
1296 THERMAL_TYPE_EXTERNAL,
1297 THERMAL_TYPE_EXTERNAL_GPIO,
1298 THERMAL_TYPE_RV6XX,
1299 THERMAL_TYPE_RV770,
1300 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1301 THERMAL_TYPE_EVERGREEN,
1302 THERMAL_TYPE_SUMO,
1303 THERMAL_TYPE_NI,
1304 THERMAL_TYPE_SI,
1305 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1306 THERMAL_TYPE_CI,
1307 THERMAL_TYPE_KV,
1308};
1309
1310enum amdgpu_dpm_auto_throttle_src {
1311 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1312 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1313};
1314
1315enum amdgpu_dpm_event_src {
1316 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1317 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1318 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1319 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1320 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1321};
1322
1323#define AMDGPU_MAX_VCE_LEVELS 6
1324
1325enum amdgpu_vce_level {
1326 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1327 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1328 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1329 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1330 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1331 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1332};
1333
1334struct amdgpu_ps {
1335 u32 caps; /* vbios flags */
1336 u32 class; /* vbios flags */
1337 u32 class2; /* vbios flags */
1338 /* UVD clocks */
1339 u32 vclk;
1340 u32 dclk;
1341 /* VCE clocks */
1342 u32 evclk;
1343 u32 ecclk;
1344 bool vce_active;
1345 enum amdgpu_vce_level vce_level;
1346 /* asic priv */
1347 void *ps_priv;
1348};
1349
1350struct amdgpu_dpm_thermal {
1351 /* thermal interrupt work */
1352 struct work_struct work;
1353 /* low temperature threshold */
1354 int min_temp;
1355 /* high temperature threshold */
1356 int max_temp;
1357 /* was last interrupt low to high or high to low */
1358 bool high_to_low;
1359 /* interrupt source */
1360 struct amdgpu_irq_src irq;
1361};
1362
1363enum amdgpu_clk_action
1364{
1365 AMDGPU_SCLK_UP = 1,
1366 AMDGPU_SCLK_DOWN
1367};
1368
1369struct amdgpu_blacklist_clocks
1370{
1371 u32 sclk;
1372 u32 mclk;
1373 enum amdgpu_clk_action action;
1374};
1375
1376struct amdgpu_clock_and_voltage_limits {
1377 u32 sclk;
1378 u32 mclk;
1379 u16 vddc;
1380 u16 vddci;
1381};
1382
1383struct amdgpu_clock_array {
1384 u32 count;
1385 u32 *values;
1386};
1387
1388struct amdgpu_clock_voltage_dependency_entry {
1389 u32 clk;
1390 u16 v;
1391};
1392
1393struct amdgpu_clock_voltage_dependency_table {
1394 u32 count;
1395 struct amdgpu_clock_voltage_dependency_entry *entries;
1396};
1397
1398union amdgpu_cac_leakage_entry {
1399 struct {
1400 u16 vddc;
1401 u32 leakage;
1402 };
1403 struct {
1404 u16 vddc1;
1405 u16 vddc2;
1406 u16 vddc3;
1407 };
1408};
1409
1410struct amdgpu_cac_leakage_table {
1411 u32 count;
1412 union amdgpu_cac_leakage_entry *entries;
1413};
1414
1415struct amdgpu_phase_shedding_limits_entry {
1416 u16 voltage;
1417 u32 sclk;
1418 u32 mclk;
1419};
1420
1421struct amdgpu_phase_shedding_limits_table {
1422 u32 count;
1423 struct amdgpu_phase_shedding_limits_entry *entries;
1424};
1425
1426struct amdgpu_uvd_clock_voltage_dependency_entry {
1427 u32 vclk;
1428 u32 dclk;
1429 u16 v;
1430};
1431
1432struct amdgpu_uvd_clock_voltage_dependency_table {
1433 u8 count;
1434 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1435};
1436
1437struct amdgpu_vce_clock_voltage_dependency_entry {
1438 u32 ecclk;
1439 u32 evclk;
1440 u16 v;
1441};
1442
1443struct amdgpu_vce_clock_voltage_dependency_table {
1444 u8 count;
1445 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1446};
1447
1448struct amdgpu_ppm_table {
1449 u8 ppm_design;
1450 u16 cpu_core_number;
1451 u32 platform_tdp;
1452 u32 small_ac_platform_tdp;
1453 u32 platform_tdc;
1454 u32 small_ac_platform_tdc;
1455 u32 apu_tdp;
1456 u32 dgpu_tdp;
1457 u32 dgpu_ulv_power;
1458 u32 tj_max;
1459};
1460
1461struct amdgpu_cac_tdp_table {
1462 u16 tdp;
1463 u16 configurable_tdp;
1464 u16 tdc;
1465 u16 battery_power_limit;
1466 u16 small_power_limit;
1467 u16 low_cac_leakage;
1468 u16 high_cac_leakage;
1469 u16 maximum_power_delivery_limit;
1470};
1471
1472struct amdgpu_dpm_dynamic_state {
1473 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1474 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1475 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1476 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1477 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1478 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1479 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1480 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1481 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1482 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1483 struct amdgpu_clock_array valid_sclk_values;
1484 struct amdgpu_clock_array valid_mclk_values;
1485 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1486 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1487 u32 mclk_sclk_ratio;
1488 u32 sclk_mclk_delta;
1489 u16 vddc_vddci_delta;
1490 u16 min_vddc_for_pcie_gen2;
1491 struct amdgpu_cac_leakage_table cac_leakage_table;
1492 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1493 struct amdgpu_ppm_table *ppm_table;
1494 struct amdgpu_cac_tdp_table *cac_tdp_table;
1495};
1496
1497struct amdgpu_dpm_fan {
1498 u16 t_min;
1499 u16 t_med;
1500 u16 t_high;
1501 u16 pwm_min;
1502 u16 pwm_med;
1503 u16 pwm_high;
1504 u8 t_hyst;
1505 u32 cycle_delay;
1506 u16 t_max;
1507 u8 control_mode;
1508 u16 default_max_fan_pwm;
1509 u16 default_fan_output_sensitivity;
1510 u16 fan_output_sensitivity;
1511 bool ucode_fan_control;
1512};
1513
1514enum amdgpu_pcie_gen {
1515 AMDGPU_PCIE_GEN1 = 0,
1516 AMDGPU_PCIE_GEN2 = 1,
1517 AMDGPU_PCIE_GEN3 = 2,
1518 AMDGPU_PCIE_GEN_INVALID = 0xffff
1519};
1520
1521enum amdgpu_dpm_forced_level {
1522 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1523 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1524 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001525 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001526};
1527
1528struct amdgpu_vce_state {
1529 /* vce clocks */
1530 u32 evclk;
1531 u32 ecclk;
1532 /* gpu clocks */
1533 u32 sclk;
1534 u32 mclk;
1535 u8 clk_idx;
1536 u8 pstate;
1537};
1538
1539struct amdgpu_dpm_funcs {
1540 int (*get_temperature)(struct amdgpu_device *adev);
1541 int (*pre_set_power_state)(struct amdgpu_device *adev);
1542 int (*set_power_state)(struct amdgpu_device *adev);
1543 void (*post_set_power_state)(struct amdgpu_device *adev);
1544 void (*display_configuration_changed)(struct amdgpu_device *adev);
1545 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1546 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1547 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1548 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1549 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1550 bool (*vblank_too_short)(struct amdgpu_device *adev);
1551 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001552 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001553 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1554 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1555 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1556 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1557 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1558};
1559
1560struct amdgpu_dpm {
1561 struct amdgpu_ps *ps;
1562 /* number of valid power states */
1563 int num_ps;
1564 /* current power state that is active */
1565 struct amdgpu_ps *current_ps;
1566 /* requested power state */
1567 struct amdgpu_ps *requested_ps;
1568 /* boot up power state */
1569 struct amdgpu_ps *boot_ps;
1570 /* default uvd power state */
1571 struct amdgpu_ps *uvd_ps;
1572 /* vce requirements */
1573 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1574 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001575 enum amd_pm_state_type state;
1576 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001577 u32 platform_caps;
1578 u32 voltage_response_time;
1579 u32 backbias_response_time;
1580 void *priv;
1581 u32 new_active_crtcs;
1582 int new_active_crtc_count;
1583 u32 current_active_crtcs;
1584 int current_active_crtc_count;
1585 struct amdgpu_dpm_dynamic_state dyn_state;
1586 struct amdgpu_dpm_fan fan;
1587 u32 tdp_limit;
1588 u32 near_tdp_limit;
1589 u32 near_tdp_limit_adjusted;
1590 u32 sq_ramping_threshold;
1591 u32 cac_leakage;
1592 u16 tdp_od_limit;
1593 u32 tdp_adjustment;
1594 u16 load_line_slope;
1595 bool power_control;
1596 bool ac_power;
1597 /* special states active */
1598 bool thermal_active;
1599 bool uvd_active;
1600 bool vce_active;
1601 /* thermal handling */
1602 struct amdgpu_dpm_thermal thermal;
1603 /* forced levels */
1604 enum amdgpu_dpm_forced_level forced_level;
1605};
1606
1607struct amdgpu_pm {
1608 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001609 u32 current_sclk;
1610 u32 current_mclk;
1611 u32 default_sclk;
1612 u32 default_mclk;
1613 struct amdgpu_i2c_chan *i2c_bus;
1614 /* internal thermal controller on rv6xx+ */
1615 enum amdgpu_int_thermal_type int_thermal_type;
1616 struct device *int_hwmon_dev;
1617 /* fan control parameters */
1618 bool no_fan;
1619 u8 fan_pulses_per_revolution;
1620 u8 fan_min_rpm;
1621 u8 fan_max_rpm;
1622 /* dpm */
1623 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001624 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001625 struct amdgpu_dpm dpm;
1626 const struct firmware *fw; /* SMC firmware */
1627 uint32_t fw_version;
1628 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001629 uint32_t pcie_gen_mask;
1630 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001631 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001632};
1633
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001634void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1635
Alex Deucher97b2e202015-04-20 16:51:00 -04001636/*
1637 * UVD
1638 */
Arindam Nathc0365542016-04-12 13:46:15 +02001639#define AMDGPU_DEFAULT_UVD_HANDLES 10
1640#define AMDGPU_MAX_UVD_HANDLES 40
1641#define AMDGPU_UVD_STACK_SIZE (200*1024)
1642#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1643#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1644#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001645
1646struct amdgpu_uvd {
1647 struct amdgpu_bo *vcpu_bo;
1648 void *cpu_addr;
1649 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001650 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001651 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001652 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001653 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1654 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1655 struct delayed_work idle_work;
1656 const struct firmware *fw; /* UVD firmware */
1657 struct amdgpu_ring ring;
1658 struct amdgpu_irq_src irq;
1659 bool address_64_bit;
Christian Königead833e2016-02-10 14:35:19 +01001660 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001661};
1662
1663/*
1664 * VCE
1665 */
1666#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001667#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1668
Alex Deucher6a585772015-07-10 14:16:24 -04001669#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1670#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1671
Alex Deucher97b2e202015-04-20 16:51:00 -04001672struct amdgpu_vce {
1673 struct amdgpu_bo *vcpu_bo;
1674 uint64_t gpu_addr;
1675 unsigned fw_version;
1676 unsigned fb_version;
1677 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1678 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001679 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001680 struct delayed_work idle_work;
1681 const struct firmware *fw; /* VCE firmware */
1682 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1683 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001684 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001685 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001686};
1687
1688/*
1689 * SDMA
1690 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001691struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001692 /* SDMA firmware */
1693 const struct firmware *fw;
1694 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001695 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001696
1697 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001698 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001699};
1700
Alex Deucherc113ea12015-10-08 16:30:37 -04001701struct amdgpu_sdma {
1702 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1703 struct amdgpu_irq_src trap_irq;
1704 struct amdgpu_irq_src illegal_inst_irq;
1705 int num_instances;
1706};
1707
Alex Deucher97b2e202015-04-20 16:51:00 -04001708/*
1709 * Firmware
1710 */
1711struct amdgpu_firmware {
1712 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1713 bool smu_load;
1714 struct amdgpu_bo *fw_buf;
1715 unsigned int fw_size;
1716};
1717
1718/*
1719 * Benchmarking
1720 */
1721void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1722
1723
1724/*
1725 * Testing
1726 */
1727void amdgpu_test_moves(struct amdgpu_device *adev);
1728void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1729 struct amdgpu_ring *cpA,
1730 struct amdgpu_ring *cpB);
1731void amdgpu_test_syncing(struct amdgpu_device *adev);
1732
1733/*
1734 * MMU Notifier
1735 */
1736#if defined(CONFIG_MMU_NOTIFIER)
1737int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1738void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1739#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001740static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001741{
1742 return -ENODEV;
1743}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001744static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001745#endif
1746
1747/*
1748 * Debugfs
1749 */
1750struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001751 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001752 unsigned num_files;
1753};
1754
1755int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001756 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001757 unsigned nfiles);
1758int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1759
1760#if defined(CONFIG_DEBUG_FS)
1761int amdgpu_debugfs_init(struct drm_minor *minor);
1762void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1763#endif
1764
1765/*
1766 * amdgpu smumgr functions
1767 */
1768struct amdgpu_smumgr_funcs {
1769 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1770 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1771 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1772};
1773
1774/*
1775 * amdgpu smumgr
1776 */
1777struct amdgpu_smumgr {
1778 struct amdgpu_bo *toc_buf;
1779 struct amdgpu_bo *smu_buf;
1780 /* asic priv smu data */
1781 void *priv;
1782 spinlock_t smu_lock;
1783 /* smumgr functions */
1784 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1785 /* ucode loading complete flag */
1786 uint32_t fw_flags;
1787};
1788
1789/*
1790 * ASIC specific register table accessible by UMD
1791 */
1792struct amdgpu_allowed_register_entry {
1793 uint32_t reg_offset;
1794 bool untouched;
1795 bool grbm_indexed;
1796};
1797
1798struct amdgpu_cu_info {
1799 uint32_t number; /* total active CU number */
1800 uint32_t ao_cu_mask;
1801 uint32_t bitmap[4][4];
1802};
1803
1804
1805/*
1806 * ASIC specific functions.
1807 */
1808struct amdgpu_asic_funcs {
1809 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001810 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1811 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001812 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1813 u32 sh_num, u32 reg_offset, u32 *value);
1814 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1815 int (*reset)(struct amdgpu_device *adev);
1816 /* wait for mc_idle */
1817 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1818 /* get the reference clock */
1819 u32 (*get_xclk)(struct amdgpu_device *adev);
1820 /* get the gpu clock counter */
1821 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
1822 int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
1823 /* MM block clocks */
1824 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1825 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1826};
1827
1828/*
1829 * IOCTL.
1830 */
1831int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1832 struct drm_file *filp);
1833int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1834 struct drm_file *filp);
1835
1836int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1837 struct drm_file *filp);
1838int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1839 struct drm_file *filp);
1840int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1841 struct drm_file *filp);
1842int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1843 struct drm_file *filp);
1844int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1845 struct drm_file *filp);
1846int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1847 struct drm_file *filp);
1848int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1849int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1850
1851int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1852 struct drm_file *filp);
1853
1854/* VRAM scratch page for HDP bug, default vram page */
1855struct amdgpu_vram_scratch {
1856 struct amdgpu_bo *robj;
1857 volatile uint32_t *ptr;
1858 u64 gpu_addr;
1859};
1860
1861/*
1862 * ACPI
1863 */
1864struct amdgpu_atif_notification_cfg {
1865 bool enabled;
1866 int command_code;
1867};
1868
1869struct amdgpu_atif_notifications {
1870 bool display_switch;
1871 bool expansion_mode_change;
1872 bool thermal_state;
1873 bool forced_power_state;
1874 bool system_power_state;
1875 bool display_conf_change;
1876 bool px_gfx_switch;
1877 bool brightness_change;
1878 bool dgpu_display_event;
1879};
1880
1881struct amdgpu_atif_functions {
1882 bool system_params;
1883 bool sbios_requests;
1884 bool select_active_disp;
1885 bool lid_state;
1886 bool get_tv_standard;
1887 bool set_tv_standard;
1888 bool get_panel_expansion_mode;
1889 bool set_panel_expansion_mode;
1890 bool temperature_change;
1891 bool graphics_device_types;
1892};
1893
1894struct amdgpu_atif {
1895 struct amdgpu_atif_notifications notifications;
1896 struct amdgpu_atif_functions functions;
1897 struct amdgpu_atif_notification_cfg notification_cfg;
1898 struct amdgpu_encoder *encoder_for_bl;
1899};
1900
1901struct amdgpu_atcs_functions {
1902 bool get_ext_state;
1903 bool pcie_perf_req;
1904 bool pcie_dev_rdy;
1905 bool pcie_bus_width;
1906};
1907
1908struct amdgpu_atcs {
1909 struct amdgpu_atcs_functions functions;
1910};
1911
Alex Deucher97b2e202015-04-20 16:51:00 -04001912/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001913 * CGS
1914 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001915struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1916void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001917
1918
Alex Deucher7e471e62016-02-01 11:13:04 -05001919/* GPU virtualization */
1920struct amdgpu_virtualization {
1921 bool supports_sr_iov;
1922};
1923
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001924/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001925 * Core structure, functions and helpers.
1926 */
1927typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1928typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1929
1930typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1931typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1932
Alex Deucher8faf0e02015-07-28 11:50:31 -04001933struct amdgpu_ip_block_status {
1934 bool valid;
1935 bool sw;
1936 bool hw;
1937};
1938
Alex Deucher97b2e202015-04-20 16:51:00 -04001939struct amdgpu_device {
1940 struct device *dev;
1941 struct drm_device *ddev;
1942 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001943
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001944#ifdef CONFIG_DRM_AMD_ACP
1945 struct amdgpu_acp acp;
1946#endif
1947
Alex Deucher97b2e202015-04-20 16:51:00 -04001948 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001949 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001950 uint32_t family;
1951 uint32_t rev_id;
1952 uint32_t external_rev_id;
1953 unsigned long flags;
1954 int usec_timeout;
1955 const struct amdgpu_asic_funcs *asic_funcs;
1956 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001957 bool need_dma32;
1958 bool accel_working;
Alex Deucher97b2e202015-04-20 16:51:00 -04001959 struct work_struct reset_work;
1960 struct notifier_block acpi_nb;
1961 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1962 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1963 unsigned debugfs_count;
1964#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001965 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001966#endif
1967 struct amdgpu_atif atif;
1968 struct amdgpu_atcs atcs;
1969 struct mutex srbm_mutex;
1970 /* GRBM index mutex. Protects concurrent access to GRBM index */
1971 struct mutex grbm_idx_mutex;
1972 struct dev_pm_domain vga_pm_domain;
1973 bool have_disp_power_ref;
1974
1975 /* BIOS */
1976 uint8_t *bios;
1977 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001978 struct amdgpu_bo *stollen_vga_memory;
1979 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1980
1981 /* Register/doorbell mmio */
1982 resource_size_t rmmio_base;
1983 resource_size_t rmmio_size;
1984 void __iomem *rmmio;
1985 /* protects concurrent MM_INDEX/DATA based register access */
1986 spinlock_t mmio_idx_lock;
1987 /* protects concurrent SMC based register access */
1988 spinlock_t smc_idx_lock;
1989 amdgpu_rreg_t smc_rreg;
1990 amdgpu_wreg_t smc_wreg;
1991 /* protects concurrent PCIE register access */
1992 spinlock_t pcie_idx_lock;
1993 amdgpu_rreg_t pcie_rreg;
1994 amdgpu_wreg_t pcie_wreg;
1995 /* protects concurrent UVD register access */
1996 spinlock_t uvd_ctx_idx_lock;
1997 amdgpu_rreg_t uvd_ctx_rreg;
1998 amdgpu_wreg_t uvd_ctx_wreg;
1999 /* protects concurrent DIDT register access */
2000 spinlock_t didt_idx_lock;
2001 amdgpu_rreg_t didt_rreg;
2002 amdgpu_wreg_t didt_wreg;
2003 /* protects concurrent ENDPOINT (audio) register access */
2004 spinlock_t audio_endpt_idx_lock;
2005 amdgpu_block_rreg_t audio_endpt_rreg;
2006 amdgpu_block_wreg_t audio_endpt_wreg;
2007 void __iomem *rio_mem;
2008 resource_size_t rio_mem_size;
2009 struct amdgpu_doorbell doorbell;
2010
2011 /* clock/pll info */
2012 struct amdgpu_clock clock;
2013
2014 /* MC */
2015 struct amdgpu_mc mc;
2016 struct amdgpu_gart gart;
2017 struct amdgpu_dummy_page dummy_page;
2018 struct amdgpu_vm_manager vm_manager;
2019
2020 /* memory management */
2021 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002022 struct amdgpu_vram_scratch vram_scratch;
2023 struct amdgpu_wb wb;
2024 atomic64_t vram_usage;
2025 atomic64_t vram_vis_usage;
2026 atomic64_t gtt_usage;
2027 atomic64_t num_bytes_moved;
Marek Olšákd94aed52015-05-05 21:13:49 +02002028 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002029
2030 /* display */
2031 struct amdgpu_mode_info mode_info;
2032 struct work_struct hotplug_work;
2033 struct amdgpu_irq_src crtc_irq;
2034 struct amdgpu_irq_src pageflip_irq;
2035 struct amdgpu_irq_src hpd_irq;
2036
2037 /* rings */
Alex Deucher97b2e202015-04-20 16:51:00 -04002038 unsigned fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002039 unsigned num_rings;
2040 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2041 bool ib_pool_ready;
2042 struct amdgpu_sa_manager ring_tmp_bo;
2043
2044 /* interrupts */
2045 struct amdgpu_irq irq;
2046
Alex Deucher1f7371b2015-12-02 17:46:21 -05002047 /* powerplay */
2048 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002049 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002050 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002051
Alex Deucher97b2e202015-04-20 16:51:00 -04002052 /* dpm */
2053 struct amdgpu_pm pm;
2054 u32 cg_flags;
2055 u32 pg_flags;
2056
2057 /* amdgpu smumgr */
2058 struct amdgpu_smumgr smu;
2059
2060 /* gfx */
2061 struct amdgpu_gfx gfx;
2062
2063 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002064 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002065
2066 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002067 struct amdgpu_uvd uvd;
2068
2069 /* vce */
2070 struct amdgpu_vce vce;
2071
2072 /* firmwares */
2073 struct amdgpu_firmware firmware;
2074
2075 /* GDS */
2076 struct amdgpu_gds gds;
2077
2078 const struct amdgpu_ip_block_version *ip_blocks;
2079 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002080 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002081 struct mutex mn_lock;
2082 DECLARE_HASHTABLE(mn_hash, 7);
2083
2084 /* tracking pinned memory */
2085 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002086 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002087 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002088
2089 /* amdkfd interface */
2090 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002091
Alex Deucher7e471e62016-02-01 11:13:04 -05002092 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002093};
2094
2095bool amdgpu_device_is_px(struct drm_device *dev);
2096int amdgpu_device_init(struct amdgpu_device *adev,
2097 struct drm_device *ddev,
2098 struct pci_dev *pdev,
2099 uint32_t flags);
2100void amdgpu_device_fini(struct amdgpu_device *adev);
2101int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2102
2103uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2104 bool always_indirect);
2105void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2106 bool always_indirect);
2107u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2108void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2109
2110u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2111void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2112
2113/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002114 * Registers read & write functions.
2115 */
2116#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2117#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2118#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2119#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2120#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2121#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2122#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2123#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2124#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2125#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2126#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2127#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2128#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2129#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2130#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2131#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2132#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2133#define WREG32_P(reg, val, mask) \
2134 do { \
2135 uint32_t tmp_ = RREG32(reg); \
2136 tmp_ &= (mask); \
2137 tmp_ |= ((val) & ~(mask)); \
2138 WREG32(reg, tmp_); \
2139 } while (0)
2140#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2141#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2142#define WREG32_PLL_P(reg, val, mask) \
2143 do { \
2144 uint32_t tmp_ = RREG32_PLL(reg); \
2145 tmp_ &= (mask); \
2146 tmp_ |= ((val) & ~(mask)); \
2147 WREG32_PLL(reg, tmp_); \
2148 } while (0)
2149#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2150#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2151#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2152
2153#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2154#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2155
2156#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2157#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2158
2159#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2160 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2161 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2162
2163#define REG_GET_FIELD(value, reg, field) \
2164 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2165
2166/*
2167 * BIOS helpers.
2168 */
2169#define RBIOS8(i) (adev->bios[i])
2170#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2171#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2172
2173/*
2174 * RING helpers.
2175 */
2176static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2177{
2178 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002179 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002180 ring->ring[ring->wptr++] = v;
2181 ring->wptr &= ring->ptr_mask;
2182 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002183}
2184
Alex Deucherc113ea12015-10-08 16:30:37 -04002185static inline struct amdgpu_sdma_instance *
2186amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002187{
2188 struct amdgpu_device *adev = ring->adev;
2189 int i;
2190
Alex Deucherc113ea12015-10-08 16:30:37 -04002191 for (i = 0; i < adev->sdma.num_instances; i++)
2192 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002193 break;
2194
2195 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002196 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002197 else
2198 return NULL;
2199}
2200
Alex Deucher97b2e202015-04-20 16:51:00 -04002201/*
2202 * ASICs macro.
2203 */
2204#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2205#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
2206#define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
2207#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2208#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2209#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2210#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2211#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002212#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 -04002213#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
2214#define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
2215#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2216#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2217#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 +01002218#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 -04002219#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 -04002220#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2221#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2222#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002223#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2224#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2225#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2226#define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
Christian Königb8c7b392016-03-01 15:42:52 +01002227#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002228#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002229#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002230#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 +02002231#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002232#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002233#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002234#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2235#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04002236#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2237#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2238#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2239#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2240#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2241#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2242#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2243#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2244#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2245#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2246#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2247#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2248#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2249#define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
2250#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2251#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2252#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))
2253#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2254#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002255#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 +08002256#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 -04002257#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2258#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2259#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2260#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002261#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002262#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002263#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Rex Zhu3af76f22015-10-15 17:23:43 +08002264
2265#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002266 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002267 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002268 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002269
2270#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002271 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002272 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002273 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002274
2275#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002276 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002277 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002278 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002279
2280#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002281 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002282 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002283 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002284
2285#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002286 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002287 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002288 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002289
Rex Zhu1b5708f2015-11-10 18:25:24 -05002290#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002291 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002292 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002293 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002294
2295#define amdgpu_dpm_get_mclk(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->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002298 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002299
2300
2301#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002302 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002303 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002304 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002305
2306#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002307 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002308 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002309 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002310
2311#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002312 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002313 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002314 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002315
2316#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002317 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002318 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002319 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002320
2321#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002322 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002323
2324#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002325 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002326
Eric Huangf3898ea2015-12-11 16:24:34 -05002327#define amdgpu_dpm_get_pp_num_states(adev, data) \
2328 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2329
2330#define amdgpu_dpm_get_pp_table(adev, table) \
2331 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2332
2333#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2334 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2335
2336#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2337 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2338
2339#define amdgpu_dpm_force_clock_level(adev, type, level) \
2340 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2341
Jammy Zhoue61710c2015-11-10 18:31:08 -05002342#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002343 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002344
2345#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2346
2347/* Common functions */
2348int amdgpu_gpu_reset(struct amdgpu_device *adev);
2349void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2350bool amdgpu_card_posted(struct amdgpu_device *adev);
2351void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002352
Alex Deucher97b2e202015-04-20 16:51:00 -04002353int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2354int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2355 u32 ip_instance, u32 ring,
2356 struct amdgpu_ring **out_ring);
2357void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2358bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002359int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002360int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2361 uint32_t flags);
2362bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002363struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002364bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2365 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002366bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2367 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002368bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2369uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2370 struct ttm_mem_reg *mem);
2371void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2372void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2373void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2374void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2375 const u32 *registers,
2376 const u32 array_size);
2377
2378bool amdgpu_device_is_px(struct drm_device *dev);
2379/* atpx handler */
2380#if defined(CONFIG_VGA_SWITCHEROO)
2381void amdgpu_register_atpx_handler(void);
2382void amdgpu_unregister_atpx_handler(void);
2383#else
2384static inline void amdgpu_register_atpx_handler(void) {}
2385static inline void amdgpu_unregister_atpx_handler(void) {}
2386#endif
2387
2388/*
2389 * KMS
2390 */
2391extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002392extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002393
2394int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2395int amdgpu_driver_unload_kms(struct drm_device *dev);
2396void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2397int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2398void amdgpu_driver_postclose_kms(struct drm_device *dev,
2399 struct drm_file *file_priv);
2400void amdgpu_driver_preclose_kms(struct drm_device *dev,
2401 struct drm_file *file_priv);
2402int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2403int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002404u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2405int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2406void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2407int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002408 int *max_error,
2409 struct timeval *vblank_time,
2410 unsigned flags);
2411long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2412 unsigned long arg);
2413
2414/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002415 * functions used by amdgpu_encoder.c
2416 */
2417struct amdgpu_afmt_acr {
2418 u32 clock;
2419
2420 int n_32khz;
2421 int cts_32khz;
2422
2423 int n_44_1khz;
2424 int cts_44_1khz;
2425
2426 int n_48khz;
2427 int cts_48khz;
2428
2429};
2430
2431struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2432
2433/* amdgpu_acpi.c */
2434#if defined(CONFIG_ACPI)
2435int amdgpu_acpi_init(struct amdgpu_device *adev);
2436void amdgpu_acpi_fini(struct amdgpu_device *adev);
2437bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2438int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2439 u8 perf_req, bool advertise);
2440int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2441#else
2442static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2443static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2444#endif
2445
2446struct amdgpu_bo_va_mapping *
2447amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2448 uint64_t addr, struct amdgpu_bo **bo);
2449
2450#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002451#endif