blob: 62a778012fe06cc572964b463f873c987ca34755 [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);
Alex Deucher97b2e202015-04-20 16:51:00 -0400305};
306
307/*
308 * BIOS.
309 */
310bool amdgpu_get_bios(struct amdgpu_device *adev);
311bool amdgpu_read_bios(struct amdgpu_device *adev);
312
313/*
314 * Dummy page
315 */
316struct amdgpu_dummy_page {
317 struct page *page;
318 dma_addr_t addr;
319};
320int amdgpu_dummy_page_init(struct amdgpu_device *adev);
321void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
322
323
324/*
325 * Clocks
326 */
327
328#define AMDGPU_MAX_PPLL 3
329
330struct amdgpu_clock {
331 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
332 struct amdgpu_pll spll;
333 struct amdgpu_pll mpll;
334 /* 10 Khz units */
335 uint32_t default_mclk;
336 uint32_t default_sclk;
337 uint32_t default_dispclk;
338 uint32_t current_dispclk;
339 uint32_t dp_extclk;
340 uint32_t max_pixel_clock;
341};
342
343/*
344 * Fences.
345 */
346struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400347 uint64_t gpu_addr;
348 volatile uint32_t *cpu_addr;
349 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100350 uint32_t sync_seq;
351 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400352 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400353 struct amdgpu_irq_src *irq_src;
354 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100355 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100356 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100357 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100358 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400359};
360
361/* some special values for the owner field */
362#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
363#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400364
Chunming Zhou890ee232015-06-01 14:35:03 +0800365#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
366#define AMDGPU_FENCE_FLAG_INT (1 << 1)
367
Alex Deucher97b2e202015-04-20 16:51:00 -0400368struct amdgpu_user_fence {
369 /* write-back bo */
370 struct amdgpu_bo *bo;
371 /* write-back address offset to bo start */
372 uint32_t offset;
373};
374
375int amdgpu_fence_driver_init(struct amdgpu_device *adev);
376void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
377void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
378
Christian Könige6151a02016-03-15 14:52:26 +0100379int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
380 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400381int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
382 struct amdgpu_irq_src *irq_src,
383 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400384void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
385void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100386int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400387void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400388int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
389unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
390
Alex Deucher97b2e202015-04-20 16:51:00 -0400391/*
392 * TTM.
393 */
394struct amdgpu_mman {
395 struct ttm_bo_global_ref bo_global_ref;
396 struct drm_global_reference mem_global_ref;
397 struct ttm_bo_device bdev;
398 bool mem_global_referenced;
399 bool initialized;
400
401#if defined(CONFIG_DEBUG_FS)
402 struct dentry *vram;
403 struct dentry *gtt;
404#endif
405
406 /* buffer handling */
407 const struct amdgpu_buffer_funcs *buffer_funcs;
408 struct amdgpu_ring *buffer_funcs_ring;
Christian König703297c2016-02-10 14:20:50 +0100409 /* Scheduler entity for buffer moves */
410 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -0400411};
412
413int amdgpu_copy_buffer(struct amdgpu_ring *ring,
414 uint64_t src_offset,
415 uint64_t dst_offset,
416 uint32_t byte_count,
417 struct reservation_object *resv,
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800418 struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400419int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma);
420
421struct amdgpu_bo_list_entry {
422 struct amdgpu_bo *robj;
423 struct ttm_validate_buffer tv;
424 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400425 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100426 struct page **user_pages;
427 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400428};
429
430struct amdgpu_bo_va_mapping {
431 struct list_head list;
432 struct interval_tree_node it;
433 uint64_t offset;
434 uint32_t flags;
435};
436
437/* bo virtual addresses in a specific vm */
438struct amdgpu_bo_va {
439 /* protected by bo being reserved */
440 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800441 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400442 unsigned ref_count;
443
Christian König7fc11952015-07-30 11:53:42 +0200444 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400445 struct list_head vm_status;
446
Christian König7fc11952015-07-30 11:53:42 +0200447 /* mappings for this bo_va */
448 struct list_head invalids;
449 struct list_head valids;
450
Alex Deucher97b2e202015-04-20 16:51:00 -0400451 /* constant after initialization */
452 struct amdgpu_vm *vm;
453 struct amdgpu_bo *bo;
454};
455
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800456#define AMDGPU_GEM_DOMAIN_MAX 0x3
457
Alex Deucher97b2e202015-04-20 16:51:00 -0400458struct amdgpu_bo {
459 /* Protected by gem.mutex */
460 struct list_head list;
461 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100462 u32 prefered_domains;
463 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800464 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400465 struct ttm_placement placement;
466 struct ttm_buffer_object tbo;
467 struct ttm_bo_kmap_obj kmap;
468 u64 flags;
469 unsigned pin_count;
470 void *kptr;
471 u64 tiling_flags;
472 u64 metadata_flags;
473 void *metadata;
474 u32 metadata_size;
475 /* list of all virtual address to which this bo
476 * is associated to
477 */
478 struct list_head va;
479 /* Constant after initialization */
480 struct amdgpu_device *adev;
481 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100482 struct amdgpu_bo *parent;
Alex Deucher97b2e202015-04-20 16:51:00 -0400483
484 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400485 struct amdgpu_mn *mn;
486 struct list_head mn_list;
487};
488#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
489
490void amdgpu_gem_object_free(struct drm_gem_object *obj);
491int amdgpu_gem_object_open(struct drm_gem_object *obj,
492 struct drm_file *file_priv);
493void amdgpu_gem_object_close(struct drm_gem_object *obj,
494 struct drm_file *file_priv);
495unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
496struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
497struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
498 struct dma_buf_attachment *attach,
499 struct sg_table *sg);
500struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
501 struct drm_gem_object *gobj,
502 int flags);
503int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
504void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
505struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
506void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
507void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
508int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
509
510/* sub-allocation manager, it has to be protected by another lock.
511 * By conception this is an helper for other part of the driver
512 * like the indirect buffer or semaphore, which both have their
513 * locking.
514 *
515 * Principe is simple, we keep a list of sub allocation in offset
516 * order (first entry has offset == 0, last entry has the highest
517 * offset).
518 *
519 * When allocating new object we first check if there is room at
520 * the end total_size - (last_object_offset + last_object_size) >=
521 * alloc_size. If so we allocate new object there.
522 *
523 * When there is not enough room at the end, we start waiting for
524 * each sub object until we reach object_offset+object_size >=
525 * alloc_size, this object then become the sub object we return.
526 *
527 * Alignment can't be bigger than page size.
528 *
529 * Hole are not considered for allocation to keep things simple.
530 * Assumption is that there won't be hole (all object on same
531 * alignment).
532 */
Christian König6ba60b82016-03-11 14:50:08 +0100533
534#define AMDGPU_SA_NUM_FENCE_LISTS 32
535
Alex Deucher97b2e202015-04-20 16:51:00 -0400536struct amdgpu_sa_manager {
537 wait_queue_head_t wq;
538 struct amdgpu_bo *bo;
539 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100540 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400541 struct list_head olist;
542 unsigned size;
543 uint64_t gpu_addr;
544 void *cpu_ptr;
545 uint32_t domain;
546 uint32_t align;
547};
548
Alex Deucher97b2e202015-04-20 16:51:00 -0400549/* sub-allocation buffer */
550struct amdgpu_sa_bo {
551 struct list_head olist;
552 struct list_head flist;
553 struct amdgpu_sa_manager *manager;
554 unsigned soffset;
555 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800556 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400557};
558
559/*
560 * GEM objects.
561 */
Christian König418aa0c2016-02-15 16:59:57 +0100562void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400563int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
564 int alignment, u32 initial_domain,
565 u64 flags, bool kernel,
566 struct drm_gem_object **obj);
567
568int amdgpu_mode_dumb_create(struct drm_file *file_priv,
569 struct drm_device *dev,
570 struct drm_mode_create_dumb *args);
571int amdgpu_mode_dumb_mmap(struct drm_file *filp,
572 struct drm_device *dev,
573 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400574/*
575 * Synchronization
576 */
577struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800578 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800579 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400580};
581
582void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200583int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
584 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400585int amdgpu_sync_resv(struct amdgpu_device *adev,
586 struct amdgpu_sync *sync,
587 struct reservation_object *resv,
588 void *owner);
Christian Könige61235d2015-08-25 11:05:36 +0200589struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian Königf91b3a62015-08-20 14:47:40 +0800590int amdgpu_sync_wait(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100591void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100592int amdgpu_sync_init(void);
593void amdgpu_sync_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400594
595/*
596 * GART structures, functions & helpers
597 */
598struct amdgpu_mc;
599
600#define AMDGPU_GPU_PAGE_SIZE 4096
601#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
602#define AMDGPU_GPU_PAGE_SHIFT 12
603#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
604
605struct amdgpu_gart {
606 dma_addr_t table_addr;
607 struct amdgpu_bo *robj;
608 void *ptr;
609 unsigned num_gpu_pages;
610 unsigned num_cpu_pages;
611 unsigned table_size;
612 struct page **pages;
613 dma_addr_t *pages_addr;
614 bool ready;
615 const struct amdgpu_gart_funcs *gart_funcs;
616};
617
618int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
619void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
620int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
621void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
622int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
623void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
624int amdgpu_gart_init(struct amdgpu_device *adev);
625void amdgpu_gart_fini(struct amdgpu_device *adev);
626void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
627 int pages);
628int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
629 int pages, struct page **pagelist,
630 dma_addr_t *dma_addr, uint32_t flags);
631
632/*
633 * GPU MC structures, functions & helpers
634 */
635struct amdgpu_mc {
636 resource_size_t aper_size;
637 resource_size_t aper_base;
638 resource_size_t agp_base;
639 /* for some chips with <= 32MB we need to lie
640 * about vram size near mc fb location */
641 u64 mc_vram_size;
642 u64 visible_vram_size;
643 u64 gtt_size;
644 u64 gtt_start;
645 u64 gtt_end;
646 u64 vram_start;
647 u64 vram_end;
648 unsigned vram_width;
649 u64 real_vram_size;
650 int vram_mtrr;
651 u64 gtt_base_align;
652 u64 mc_mask;
653 const struct firmware *fw; /* MC firmware */
654 uint32_t fw_version;
655 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800656 uint32_t vram_type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400657};
658
659/*
660 * GPU doorbell structures, functions & helpers
661 */
662typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
663{
664 AMDGPU_DOORBELL_KIQ = 0x000,
665 AMDGPU_DOORBELL_HIQ = 0x001,
666 AMDGPU_DOORBELL_DIQ = 0x002,
667 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
668 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
669 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
670 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
671 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
672 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
673 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
674 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
675 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
676 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
677 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
678 AMDGPU_DOORBELL_IH = 0x1E8,
679 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
680 AMDGPU_DOORBELL_INVALID = 0xFFFF
681} AMDGPU_DOORBELL_ASSIGNMENT;
682
683struct amdgpu_doorbell {
684 /* doorbell mmio */
685 resource_size_t base;
686 resource_size_t size;
687 u32 __iomem *ptr;
688 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
689};
690
691void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
692 phys_addr_t *aperture_base,
693 size_t *aperture_size,
694 size_t *start_offset);
695
696/*
697 * IRQS.
698 */
699
700struct amdgpu_flip_work {
701 struct work_struct flip_work;
702 struct work_struct unpin_work;
703 struct amdgpu_device *adev;
704 int crtc_id;
705 uint64_t base;
706 struct drm_pending_vblank_event *event;
707 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200708 struct fence *excl;
709 unsigned shared_count;
710 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100711 struct fence_cb cb;
Alex Deucher97b2e202015-04-20 16:51:00 -0400712};
713
714
715/*
716 * CP & rings.
717 */
718
719struct amdgpu_ib {
720 struct amdgpu_sa_bo *sa_bo;
721 uint32_t length_dw;
722 uint64_t gpu_addr;
723 uint32_t *ptr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400724 struct amdgpu_user_fence *user;
725 struct amdgpu_vm *vm;
Christian König4ff37a82016-02-26 16:18:26 +0100726 unsigned vm_id;
727 uint64_t vm_pd_addr;
Christian König3cb485f2015-05-11 15:34:59 +0200728 struct amdgpu_ctx *ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400729 uint32_t gds_base, gds_size;
730 uint32_t gws_base, gws_size;
731 uint32_t oa_base, oa_size;
Jammy Zhoude807f82015-05-11 23:41:41 +0800732 uint32_t flags;
Christian König5430a3f2015-07-21 18:02:21 +0200733 /* resulting sequence number */
734 uint64_t sequence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400735};
736
737enum amdgpu_ring_type {
738 AMDGPU_RING_TYPE_GFX,
739 AMDGPU_RING_TYPE_COMPUTE,
740 AMDGPU_RING_TYPE_SDMA,
741 AMDGPU_RING_TYPE_UVD,
742 AMDGPU_RING_TYPE_VCE
743};
744
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800745extern struct amd_sched_backend_ops amdgpu_sched_ops;
746
Christian König50838c82016-02-03 13:44:52 +0100747int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
748 struct amdgpu_job **job);
Christian Königd71518b2016-02-01 12:20:25 +0100749int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
750 struct amdgpu_job **job);
Christian König50838c82016-02-03 13:44:52 +0100751void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100752int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100753 struct amd_sched_entity *entity, void *owner,
754 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800755
Alex Deucher97b2e202015-04-20 16:51:00 -0400756struct amdgpu_ring {
757 struct amdgpu_device *adev;
758 const struct amdgpu_ring_funcs *funcs;
759 struct amdgpu_fence_driver fence_drv;
Christian König4f839a22015-09-08 20:22:31 +0200760 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400761
Chunming Zhou176e1ab2015-07-24 10:49:47 +0800762 spinlock_t fence_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400763 struct amdgpu_bo *ring_obj;
764 volatile uint32_t *ring;
765 unsigned rptr_offs;
766 u64 next_rptr_gpu_addr;
767 volatile u32 *next_rptr_cpu_addr;
768 unsigned wptr;
769 unsigned wptr_old;
770 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100771 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400772 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400773 uint64_t gpu_addr;
774 uint32_t align_mask;
775 uint32_t ptr_mask;
776 bool ready;
777 u32 nop;
778 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400779 u32 me;
780 u32 pipe;
781 u32 queue;
782 struct amdgpu_bo *mqd_obj;
783 u32 doorbell_index;
784 bool use_doorbell;
785 unsigned wptr_offs;
786 unsigned next_rptr_offs;
787 unsigned fence_offs;
Christian König3cb485f2015-05-11 15:34:59 +0200788 struct amdgpu_ctx *current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400789 enum amdgpu_ring_type type;
790 char name[16];
791};
792
793/*
794 * VM
795 */
796
797/* maximum number of VMIDs */
798#define AMDGPU_NUM_VM 16
799
800/* number of entries in page table */
801#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
802
803/* PTBs (Page Table Blocks) need to be aligned to 32K */
804#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
805#define AMDGPU_VM_PTB_ALIGN_MASK (AMDGPU_VM_PTB_ALIGN_SIZE - 1)
806#define AMDGPU_VM_PTB_ALIGN(a) (((a) + AMDGPU_VM_PTB_ALIGN_MASK) & ~AMDGPU_VM_PTB_ALIGN_MASK)
807
808#define AMDGPU_PTE_VALID (1 << 0)
809#define AMDGPU_PTE_SYSTEM (1 << 1)
810#define AMDGPU_PTE_SNOOPED (1 << 2)
811
812/* VI only */
813#define AMDGPU_PTE_EXECUTABLE (1 << 4)
814
815#define AMDGPU_PTE_READABLE (1 << 5)
816#define AMDGPU_PTE_WRITEABLE (1 << 6)
817
818/* PTE (Page Table Entry) fragment field for different page sizes */
819#define AMDGPU_PTE_FRAG_4KB (0 << 7)
820#define AMDGPU_PTE_FRAG_64KB (4 << 7)
821#define AMDGPU_LOG2_PAGES_PER_FRAG 4
822
Christian Königd9c13152015-09-28 12:31:26 +0200823/* How to programm VM fault handling */
824#define AMDGPU_VM_FAULT_STOP_NEVER 0
825#define AMDGPU_VM_FAULT_STOP_FIRST 1
826#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
827
Alex Deucher97b2e202015-04-20 16:51:00 -0400828struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100829 struct amdgpu_bo_list_entry entry;
830 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400831};
832
833struct amdgpu_vm_id {
Christian König4ff37a82016-02-26 16:18:26 +0100834 struct amdgpu_vm_manager_id *mgr_id;
835 uint64_t pd_gpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400836 /* last flushed PD/PT update */
Christian König4ff37a82016-02-26 16:18:26 +0100837 struct fence *flushed_updates;
Alex Deucher97b2e202015-04-20 16:51:00 -0400838};
839
840struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100841 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400842 struct rb_root va;
843
Christian König7fc11952015-07-30 11:53:42 +0200844 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400845 spinlock_t status_lock;
846
847 /* BOs moved, but not yet updated in the PT */
848 struct list_head invalidated;
849
Christian König7fc11952015-07-30 11:53:42 +0200850 /* BOs cleared in the PT because of a move */
851 struct list_head cleared;
852
853 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400854 struct list_head freed;
855
856 /* contains the page directory */
857 struct amdgpu_bo *page_directory;
858 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200859 struct fence *page_directory_fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400860
861 /* array of page tables, one for each page directory entry */
862 struct amdgpu_vm_pt *page_tables;
863
864 /* for id and flush management per ring */
865 struct amdgpu_vm_id ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100866
jimqu81d75a32015-12-04 17:17:00 +0800867 /* protecting freed */
868 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100869
870 /* Scheduler entity for page table updates */
871 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -0400872};
873
Christian Königa9a78b32016-01-21 10:19:11 +0100874struct amdgpu_vm_manager_id {
875 struct list_head list;
876 struct fence *active;
877 atomic_long_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100878
879 uint32_t gds_base;
880 uint32_t gds_size;
881 uint32_t gws_base;
882 uint32_t gws_size;
883 uint32_t oa_base;
884 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100885};
Christian König8d0a7ce2015-11-03 20:58:50 +0100886
Christian Königa9a78b32016-01-21 10:19:11 +0100887struct amdgpu_vm_manager {
888 /* Handling of VMIDs */
889 struct mutex lock;
890 unsigned num_ids;
891 struct list_head ids_lru;
892 struct amdgpu_vm_manager_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100893
Christian König8b4fb002015-11-15 16:04:16 +0100894 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400895 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100896 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400897 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100898 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400899 /* vm pte handling */
900 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100901 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
902 unsigned vm_pte_num_rings;
903 atomic_t vm_pte_next_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400904};
905
Christian Königa9a78b32016-01-21 10:19:11 +0100906void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100907void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100908int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
909void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100910void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
911 struct list_head *validated,
912 struct amdgpu_bo_list_entry *entry);
Christian Königee1782c2015-12-11 21:01:23 +0100913void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100914void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
915 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100916int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100917 struct amdgpu_sync *sync, struct fence *fence,
918 unsigned *vm_id, uint64_t *vm_pd_addr);
Christian König8b4fb002015-11-15 16:04:16 +0100919void amdgpu_vm_flush(struct amdgpu_ring *ring,
Christian Königcffadc82016-03-01 13:34:49 +0100920 unsigned vm_id, uint64_t pd_addr,
921 uint32_t gds_base, uint32_t gds_size,
922 uint32_t gws_base, uint32_t gws_size,
923 uint32_t oa_base, uint32_t oa_size);
Christian König971fe9a92016-03-01 15:09:25 +0100924void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian Königb07c9d22015-11-30 13:26:07 +0100925uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr);
Christian König8b4fb002015-11-15 16:04:16 +0100926int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
927 struct amdgpu_vm *vm);
928int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
929 struct amdgpu_vm *vm);
930int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
931 struct amdgpu_sync *sync);
932int amdgpu_vm_bo_update(struct amdgpu_device *adev,
933 struct amdgpu_bo_va *bo_va,
934 struct ttm_mem_reg *mem);
935void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
936 struct amdgpu_bo *bo);
937struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
938 struct amdgpu_bo *bo);
939struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
940 struct amdgpu_vm *vm,
941 struct amdgpu_bo *bo);
942int amdgpu_vm_bo_map(struct amdgpu_device *adev,
943 struct amdgpu_bo_va *bo_va,
944 uint64_t addr, uint64_t offset,
945 uint64_t size, uint32_t flags);
946int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
947 struct amdgpu_bo_va *bo_va,
948 uint64_t addr);
949void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
950 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100951
Alex Deucher97b2e202015-04-20 16:51:00 -0400952/*
953 * context related structures
954 */
955
Christian König21c16bf2015-07-07 17:24:49 +0200956struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200957 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800958 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200959 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200960};
961
Alex Deucher97b2e202015-04-20 16:51:00 -0400962struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400963 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800964 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400965 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200966 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800967 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200968 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400969};
970
971struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400972 struct amdgpu_device *adev;
973 struct mutex lock;
974 /* protected by lock */
975 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400976};
977
Alex Deucher0b492a42015-08-16 22:48:26 -0400978struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
979int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
980
Christian König21c16bf2015-07-07 17:24:49 +0200981uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200982 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200983struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
984 struct amdgpu_ring *ring, uint64_t seq);
985
Alex Deucher0b492a42015-08-16 22:48:26 -0400986int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
987 struct drm_file *filp);
988
Christian Königefd4ccb2015-08-04 16:20:31 +0200989void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
990void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400991
Alex Deucher97b2e202015-04-20 16:51:00 -0400992/*
993 * file private structure
994 */
995
996struct amdgpu_fpriv {
997 struct amdgpu_vm vm;
998 struct mutex bo_list_lock;
999 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001000 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001001};
1002
1003/*
1004 * residency list
1005 */
1006
1007struct amdgpu_bo_list {
1008 struct mutex lock;
1009 struct amdgpu_bo *gds_obj;
1010 struct amdgpu_bo *gws_obj;
1011 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001012 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001013 unsigned num_entries;
1014 struct amdgpu_bo_list_entry *array;
1015};
1016
1017struct amdgpu_bo_list *
1018amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001019void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1020 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001021void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1022void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1023
1024/*
1025 * GFX stuff
1026 */
1027#include "clearstate_defs.h"
1028
1029struct amdgpu_rlc {
1030 /* for power gating */
1031 struct amdgpu_bo *save_restore_obj;
1032 uint64_t save_restore_gpu_addr;
1033 volatile uint32_t *sr_ptr;
1034 const u32 *reg_list;
1035 u32 reg_list_size;
1036 /* for clear state */
1037 struct amdgpu_bo *clear_state_obj;
1038 uint64_t clear_state_gpu_addr;
1039 volatile uint32_t *cs_ptr;
1040 const struct cs_section_def *cs_data;
1041 u32 clear_state_size;
1042 /* for cp tables */
1043 struct amdgpu_bo *cp_table_obj;
1044 uint64_t cp_table_gpu_addr;
1045 volatile uint32_t *cp_table_ptr;
1046 u32 cp_table_size;
1047};
1048
1049struct amdgpu_mec {
1050 struct amdgpu_bo *hpd_eop_obj;
1051 u64 hpd_eop_gpu_addr;
1052 u32 num_pipe;
1053 u32 num_mec;
1054 u32 num_queue;
1055};
1056
1057/*
1058 * GPU scratch registers structures, functions & helpers
1059 */
1060struct amdgpu_scratch {
1061 unsigned num_reg;
1062 uint32_t reg_base;
1063 bool free[32];
1064 uint32_t reg[32];
1065};
1066
1067/*
1068 * GFX configurations
1069 */
1070struct amdgpu_gca_config {
1071 unsigned max_shader_engines;
1072 unsigned max_tile_pipes;
1073 unsigned max_cu_per_sh;
1074 unsigned max_sh_per_se;
1075 unsigned max_backends_per_se;
1076 unsigned max_texture_channel_caches;
1077 unsigned max_gprs;
1078 unsigned max_gs_threads;
1079 unsigned max_hw_contexts;
1080 unsigned sc_prim_fifo_size_frontend;
1081 unsigned sc_prim_fifo_size_backend;
1082 unsigned sc_hiz_tile_fifo_size;
1083 unsigned sc_earlyz_tile_fifo_size;
1084
1085 unsigned num_tile_pipes;
1086 unsigned backend_enable_mask;
1087 unsigned mem_max_burst_length_bytes;
1088 unsigned mem_row_size_in_kb;
1089 unsigned shader_engine_tile_size;
1090 unsigned num_gpus;
1091 unsigned multi_gpu_tile_size;
1092 unsigned mc_arb_ramcfg;
1093 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001094 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001095
1096 uint32_t tile_mode_array[32];
1097 uint32_t macrotile_mode_array[16];
1098};
1099
1100struct amdgpu_gfx {
1101 struct mutex gpu_clock_mutex;
1102 struct amdgpu_gca_config config;
1103 struct amdgpu_rlc rlc;
1104 struct amdgpu_mec mec;
1105 struct amdgpu_scratch scratch;
1106 const struct firmware *me_fw; /* ME firmware */
1107 uint32_t me_fw_version;
1108 const struct firmware *pfp_fw; /* PFP firmware */
1109 uint32_t pfp_fw_version;
1110 const struct firmware *ce_fw; /* CE firmware */
1111 uint32_t ce_fw_version;
1112 const struct firmware *rlc_fw; /* RLC firmware */
1113 uint32_t rlc_fw_version;
1114 const struct firmware *mec_fw; /* MEC firmware */
1115 uint32_t mec_fw_version;
1116 const struct firmware *mec2_fw; /* MEC2 firmware */
1117 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001118 uint32_t me_feature_version;
1119 uint32_t ce_feature_version;
1120 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001121 uint32_t rlc_feature_version;
1122 uint32_t mec_feature_version;
1123 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001124 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1125 unsigned num_gfx_rings;
1126 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1127 unsigned num_compute_rings;
1128 struct amdgpu_irq_src eop_irq;
1129 struct amdgpu_irq_src priv_reg_irq;
1130 struct amdgpu_irq_src priv_inst_irq;
1131 /* gfx status */
1132 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001133 /* ce ram size*/
1134 unsigned ce_ram_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001135};
1136
Christian Königb07c60c2016-01-31 12:29:04 +01001137int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001138 unsigned size, struct amdgpu_ib *ib);
Monk Liucc55c452016-03-17 10:47:07 +08001139void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001140int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001141 struct amdgpu_ib *ib, struct fence *last_vm_update,
Christian Königec72b802016-02-01 11:56:35 +01001142 struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001143int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1144void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1145int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001146int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001147void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001148void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001149void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001150void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001151unsigned amdgpu_ring_backup(struct amdgpu_ring *ring,
1152 uint32_t **data);
1153int amdgpu_ring_restore(struct amdgpu_ring *ring,
1154 unsigned size, uint32_t *data);
1155int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1156 unsigned ring_size, u32 nop, u32 align_mask,
1157 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1158 enum amdgpu_ring_type ring_type);
1159void amdgpu_ring_fini(struct amdgpu_ring *ring);
1160
1161/*
1162 * CS.
1163 */
1164struct amdgpu_cs_chunk {
1165 uint32_t chunk_id;
1166 uint32_t length_dw;
1167 uint32_t *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001168};
1169
1170struct amdgpu_cs_parser {
1171 struct amdgpu_device *adev;
1172 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001173 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001174
Alex Deucher97b2e202015-04-20 16:51:00 -04001175 /* chunks */
1176 unsigned nchunks;
1177 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001178
Christian König50838c82016-02-03 13:44:52 +01001179 /* scheduler job object */
1180 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001181
Christian Königc3cca412015-12-15 14:41:33 +01001182 /* buffer objects */
1183 struct ww_acquire_ctx ticket;
1184 struct amdgpu_bo_list *bo_list;
1185 struct amdgpu_bo_list_entry vm_pd;
1186 struct list_head validated;
1187 struct fence *fence;
1188 uint64_t bytes_moved_threshold;
1189 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001190
1191 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001192 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001193};
1194
Chunming Zhoubb977d32015-08-18 15:16:40 +08001195struct amdgpu_job {
1196 struct amd_sched_job base;
1197 struct amdgpu_device *adev;
Christian Königb07c60c2016-01-31 12:29:04 +01001198 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001199 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001200 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001201 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001202 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001203 void *owner;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001204 struct amdgpu_user_fence uf;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001205};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001206#define to_amdgpu_job(sched_job) \
1207 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001208
Christian König7270f832016-01-31 11:00:41 +01001209static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1210 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001211{
Christian König50838c82016-02-03 13:44:52 +01001212 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001213}
1214
Christian König7270f832016-01-31 11:00:41 +01001215static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1216 uint32_t ib_idx, int idx,
1217 uint32_t value)
1218{
Christian König50838c82016-02-03 13:44:52 +01001219 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001220}
1221
Alex Deucher97b2e202015-04-20 16:51:00 -04001222/*
1223 * Writeback
1224 */
1225#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1226
1227struct amdgpu_wb {
1228 struct amdgpu_bo *wb_obj;
1229 volatile uint32_t *wb;
1230 uint64_t gpu_addr;
1231 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1232 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1233};
1234
1235int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1236void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1237
Alex Deucher97b2e202015-04-20 16:51:00 -04001238
Alex Deucher97b2e202015-04-20 16:51:00 -04001239
1240enum amdgpu_int_thermal_type {
1241 THERMAL_TYPE_NONE,
1242 THERMAL_TYPE_EXTERNAL,
1243 THERMAL_TYPE_EXTERNAL_GPIO,
1244 THERMAL_TYPE_RV6XX,
1245 THERMAL_TYPE_RV770,
1246 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1247 THERMAL_TYPE_EVERGREEN,
1248 THERMAL_TYPE_SUMO,
1249 THERMAL_TYPE_NI,
1250 THERMAL_TYPE_SI,
1251 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1252 THERMAL_TYPE_CI,
1253 THERMAL_TYPE_KV,
1254};
1255
1256enum amdgpu_dpm_auto_throttle_src {
1257 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1258 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1259};
1260
1261enum amdgpu_dpm_event_src {
1262 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1263 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1264 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1265 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1266 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1267};
1268
1269#define AMDGPU_MAX_VCE_LEVELS 6
1270
1271enum amdgpu_vce_level {
1272 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1273 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1274 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1275 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1276 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1277 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1278};
1279
1280struct amdgpu_ps {
1281 u32 caps; /* vbios flags */
1282 u32 class; /* vbios flags */
1283 u32 class2; /* vbios flags */
1284 /* UVD clocks */
1285 u32 vclk;
1286 u32 dclk;
1287 /* VCE clocks */
1288 u32 evclk;
1289 u32 ecclk;
1290 bool vce_active;
1291 enum amdgpu_vce_level vce_level;
1292 /* asic priv */
1293 void *ps_priv;
1294};
1295
1296struct amdgpu_dpm_thermal {
1297 /* thermal interrupt work */
1298 struct work_struct work;
1299 /* low temperature threshold */
1300 int min_temp;
1301 /* high temperature threshold */
1302 int max_temp;
1303 /* was last interrupt low to high or high to low */
1304 bool high_to_low;
1305 /* interrupt source */
1306 struct amdgpu_irq_src irq;
1307};
1308
1309enum amdgpu_clk_action
1310{
1311 AMDGPU_SCLK_UP = 1,
1312 AMDGPU_SCLK_DOWN
1313};
1314
1315struct amdgpu_blacklist_clocks
1316{
1317 u32 sclk;
1318 u32 mclk;
1319 enum amdgpu_clk_action action;
1320};
1321
1322struct amdgpu_clock_and_voltage_limits {
1323 u32 sclk;
1324 u32 mclk;
1325 u16 vddc;
1326 u16 vddci;
1327};
1328
1329struct amdgpu_clock_array {
1330 u32 count;
1331 u32 *values;
1332};
1333
1334struct amdgpu_clock_voltage_dependency_entry {
1335 u32 clk;
1336 u16 v;
1337};
1338
1339struct amdgpu_clock_voltage_dependency_table {
1340 u32 count;
1341 struct amdgpu_clock_voltage_dependency_entry *entries;
1342};
1343
1344union amdgpu_cac_leakage_entry {
1345 struct {
1346 u16 vddc;
1347 u32 leakage;
1348 };
1349 struct {
1350 u16 vddc1;
1351 u16 vddc2;
1352 u16 vddc3;
1353 };
1354};
1355
1356struct amdgpu_cac_leakage_table {
1357 u32 count;
1358 union amdgpu_cac_leakage_entry *entries;
1359};
1360
1361struct amdgpu_phase_shedding_limits_entry {
1362 u16 voltage;
1363 u32 sclk;
1364 u32 mclk;
1365};
1366
1367struct amdgpu_phase_shedding_limits_table {
1368 u32 count;
1369 struct amdgpu_phase_shedding_limits_entry *entries;
1370};
1371
1372struct amdgpu_uvd_clock_voltage_dependency_entry {
1373 u32 vclk;
1374 u32 dclk;
1375 u16 v;
1376};
1377
1378struct amdgpu_uvd_clock_voltage_dependency_table {
1379 u8 count;
1380 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1381};
1382
1383struct amdgpu_vce_clock_voltage_dependency_entry {
1384 u32 ecclk;
1385 u32 evclk;
1386 u16 v;
1387};
1388
1389struct amdgpu_vce_clock_voltage_dependency_table {
1390 u8 count;
1391 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1392};
1393
1394struct amdgpu_ppm_table {
1395 u8 ppm_design;
1396 u16 cpu_core_number;
1397 u32 platform_tdp;
1398 u32 small_ac_platform_tdp;
1399 u32 platform_tdc;
1400 u32 small_ac_platform_tdc;
1401 u32 apu_tdp;
1402 u32 dgpu_tdp;
1403 u32 dgpu_ulv_power;
1404 u32 tj_max;
1405};
1406
1407struct amdgpu_cac_tdp_table {
1408 u16 tdp;
1409 u16 configurable_tdp;
1410 u16 tdc;
1411 u16 battery_power_limit;
1412 u16 small_power_limit;
1413 u16 low_cac_leakage;
1414 u16 high_cac_leakage;
1415 u16 maximum_power_delivery_limit;
1416};
1417
1418struct amdgpu_dpm_dynamic_state {
1419 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1420 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1421 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1422 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1423 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1424 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1425 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1426 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1427 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1428 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1429 struct amdgpu_clock_array valid_sclk_values;
1430 struct amdgpu_clock_array valid_mclk_values;
1431 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1432 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1433 u32 mclk_sclk_ratio;
1434 u32 sclk_mclk_delta;
1435 u16 vddc_vddci_delta;
1436 u16 min_vddc_for_pcie_gen2;
1437 struct amdgpu_cac_leakage_table cac_leakage_table;
1438 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1439 struct amdgpu_ppm_table *ppm_table;
1440 struct amdgpu_cac_tdp_table *cac_tdp_table;
1441};
1442
1443struct amdgpu_dpm_fan {
1444 u16 t_min;
1445 u16 t_med;
1446 u16 t_high;
1447 u16 pwm_min;
1448 u16 pwm_med;
1449 u16 pwm_high;
1450 u8 t_hyst;
1451 u32 cycle_delay;
1452 u16 t_max;
1453 u8 control_mode;
1454 u16 default_max_fan_pwm;
1455 u16 default_fan_output_sensitivity;
1456 u16 fan_output_sensitivity;
1457 bool ucode_fan_control;
1458};
1459
1460enum amdgpu_pcie_gen {
1461 AMDGPU_PCIE_GEN1 = 0,
1462 AMDGPU_PCIE_GEN2 = 1,
1463 AMDGPU_PCIE_GEN3 = 2,
1464 AMDGPU_PCIE_GEN_INVALID = 0xffff
1465};
1466
1467enum amdgpu_dpm_forced_level {
1468 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1469 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1470 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001471 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001472};
1473
1474struct amdgpu_vce_state {
1475 /* vce clocks */
1476 u32 evclk;
1477 u32 ecclk;
1478 /* gpu clocks */
1479 u32 sclk;
1480 u32 mclk;
1481 u8 clk_idx;
1482 u8 pstate;
1483};
1484
1485struct amdgpu_dpm_funcs {
1486 int (*get_temperature)(struct amdgpu_device *adev);
1487 int (*pre_set_power_state)(struct amdgpu_device *adev);
1488 int (*set_power_state)(struct amdgpu_device *adev);
1489 void (*post_set_power_state)(struct amdgpu_device *adev);
1490 void (*display_configuration_changed)(struct amdgpu_device *adev);
1491 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1492 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1493 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1494 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1495 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1496 bool (*vblank_too_short)(struct amdgpu_device *adev);
1497 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001498 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001499 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1500 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1501 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1502 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1503 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
1504};
1505
1506struct amdgpu_dpm {
1507 struct amdgpu_ps *ps;
1508 /* number of valid power states */
1509 int num_ps;
1510 /* current power state that is active */
1511 struct amdgpu_ps *current_ps;
1512 /* requested power state */
1513 struct amdgpu_ps *requested_ps;
1514 /* boot up power state */
1515 struct amdgpu_ps *boot_ps;
1516 /* default uvd power state */
1517 struct amdgpu_ps *uvd_ps;
1518 /* vce requirements */
1519 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1520 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001521 enum amd_pm_state_type state;
1522 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001523 u32 platform_caps;
1524 u32 voltage_response_time;
1525 u32 backbias_response_time;
1526 void *priv;
1527 u32 new_active_crtcs;
1528 int new_active_crtc_count;
1529 u32 current_active_crtcs;
1530 int current_active_crtc_count;
1531 struct amdgpu_dpm_dynamic_state dyn_state;
1532 struct amdgpu_dpm_fan fan;
1533 u32 tdp_limit;
1534 u32 near_tdp_limit;
1535 u32 near_tdp_limit_adjusted;
1536 u32 sq_ramping_threshold;
1537 u32 cac_leakage;
1538 u16 tdp_od_limit;
1539 u32 tdp_adjustment;
1540 u16 load_line_slope;
1541 bool power_control;
1542 bool ac_power;
1543 /* special states active */
1544 bool thermal_active;
1545 bool uvd_active;
1546 bool vce_active;
1547 /* thermal handling */
1548 struct amdgpu_dpm_thermal thermal;
1549 /* forced levels */
1550 enum amdgpu_dpm_forced_level forced_level;
1551};
1552
1553struct amdgpu_pm {
1554 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001555 u32 current_sclk;
1556 u32 current_mclk;
1557 u32 default_sclk;
1558 u32 default_mclk;
1559 struct amdgpu_i2c_chan *i2c_bus;
1560 /* internal thermal controller on rv6xx+ */
1561 enum amdgpu_int_thermal_type int_thermal_type;
1562 struct device *int_hwmon_dev;
1563 /* fan control parameters */
1564 bool no_fan;
1565 u8 fan_pulses_per_revolution;
1566 u8 fan_min_rpm;
1567 u8 fan_max_rpm;
1568 /* dpm */
1569 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001570 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001571 struct amdgpu_dpm dpm;
1572 const struct firmware *fw; /* SMC firmware */
1573 uint32_t fw_version;
1574 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001575 uint32_t pcie_gen_mask;
1576 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001577 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001578};
1579
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001580void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1581
Alex Deucher97b2e202015-04-20 16:51:00 -04001582/*
1583 * UVD
1584 */
1585#define AMDGPU_MAX_UVD_HANDLES 10
1586#define AMDGPU_UVD_STACK_SIZE (1024*1024)
1587#define AMDGPU_UVD_HEAP_SIZE (1024*1024)
1588#define AMDGPU_UVD_FIRMWARE_OFFSET 256
1589
1590struct amdgpu_uvd {
1591 struct amdgpu_bo *vcpu_bo;
1592 void *cpu_addr;
1593 uint64_t gpu_addr;
Leo Liu3f99dd82016-04-01 10:36:06 -04001594 void *saved_bo;
Alex Deucher97b2e202015-04-20 16:51:00 -04001595 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1596 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1597 struct delayed_work idle_work;
1598 const struct firmware *fw; /* UVD firmware */
1599 struct amdgpu_ring ring;
1600 struct amdgpu_irq_src irq;
1601 bool address_64_bit;
Christian Königead833e2016-02-10 14:35:19 +01001602 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001603};
1604
1605/*
1606 * VCE
1607 */
1608#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001609#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1610
Alex Deucher6a585772015-07-10 14:16:24 -04001611#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1612#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1613
Alex Deucher97b2e202015-04-20 16:51:00 -04001614struct amdgpu_vce {
1615 struct amdgpu_bo *vcpu_bo;
1616 uint64_t gpu_addr;
1617 unsigned fw_version;
1618 unsigned fb_version;
1619 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1620 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001621 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001622 struct delayed_work idle_work;
1623 const struct firmware *fw; /* VCE firmware */
1624 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1625 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001626 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001627 struct amd_sched_entity entity;
Alex Deucher97b2e202015-04-20 16:51:00 -04001628};
1629
1630/*
1631 * SDMA
1632 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001633struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001634 /* SDMA firmware */
1635 const struct firmware *fw;
1636 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001637 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001638
1639 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001640 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001641};
1642
Alex Deucherc113ea12015-10-08 16:30:37 -04001643struct amdgpu_sdma {
1644 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1645 struct amdgpu_irq_src trap_irq;
1646 struct amdgpu_irq_src illegal_inst_irq;
1647 int num_instances;
1648};
1649
Alex Deucher97b2e202015-04-20 16:51:00 -04001650/*
1651 * Firmware
1652 */
1653struct amdgpu_firmware {
1654 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1655 bool smu_load;
1656 struct amdgpu_bo *fw_buf;
1657 unsigned int fw_size;
1658};
1659
1660/*
1661 * Benchmarking
1662 */
1663void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1664
1665
1666/*
1667 * Testing
1668 */
1669void amdgpu_test_moves(struct amdgpu_device *adev);
1670void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1671 struct amdgpu_ring *cpA,
1672 struct amdgpu_ring *cpB);
1673void amdgpu_test_syncing(struct amdgpu_device *adev);
1674
1675/*
1676 * MMU Notifier
1677 */
1678#if defined(CONFIG_MMU_NOTIFIER)
1679int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1680void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1681#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001682static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001683{
1684 return -ENODEV;
1685}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001686static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001687#endif
1688
1689/*
1690 * Debugfs
1691 */
1692struct amdgpu_debugfs {
1693 struct drm_info_list *files;
1694 unsigned num_files;
1695};
1696
1697int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
1698 struct drm_info_list *files,
1699 unsigned nfiles);
1700int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1701
1702#if defined(CONFIG_DEBUG_FS)
1703int amdgpu_debugfs_init(struct drm_minor *minor);
1704void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1705#endif
1706
1707/*
1708 * amdgpu smumgr functions
1709 */
1710struct amdgpu_smumgr_funcs {
1711 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1712 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1713 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1714};
1715
1716/*
1717 * amdgpu smumgr
1718 */
1719struct amdgpu_smumgr {
1720 struct amdgpu_bo *toc_buf;
1721 struct amdgpu_bo *smu_buf;
1722 /* asic priv smu data */
1723 void *priv;
1724 spinlock_t smu_lock;
1725 /* smumgr functions */
1726 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1727 /* ucode loading complete flag */
1728 uint32_t fw_flags;
1729};
1730
1731/*
1732 * ASIC specific register table accessible by UMD
1733 */
1734struct amdgpu_allowed_register_entry {
1735 uint32_t reg_offset;
1736 bool untouched;
1737 bool grbm_indexed;
1738};
1739
1740struct amdgpu_cu_info {
1741 uint32_t number; /* total active CU number */
1742 uint32_t ao_cu_mask;
1743 uint32_t bitmap[4][4];
1744};
1745
1746
1747/*
1748 * ASIC specific functions.
1749 */
1750struct amdgpu_asic_funcs {
1751 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001752 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1753 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001754 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1755 u32 sh_num, u32 reg_offset, u32 *value);
1756 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1757 int (*reset)(struct amdgpu_device *adev);
1758 /* wait for mc_idle */
1759 int (*wait_for_mc_idle)(struct amdgpu_device *adev);
1760 /* get the reference clock */
1761 u32 (*get_xclk)(struct amdgpu_device *adev);
1762 /* get the gpu clock counter */
1763 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
1764 int (*get_cu_info)(struct amdgpu_device *adev, struct amdgpu_cu_info *info);
1765 /* MM block clocks */
1766 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1767 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
1768};
1769
1770/*
1771 * IOCTL.
1772 */
1773int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1774 struct drm_file *filp);
1775int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1776 struct drm_file *filp);
1777
1778int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1779 struct drm_file *filp);
1780int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1781 struct drm_file *filp);
1782int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1783 struct drm_file *filp);
1784int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1785 struct drm_file *filp);
1786int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1787 struct drm_file *filp);
1788int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1789 struct drm_file *filp);
1790int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1791int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1792
1793int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1794 struct drm_file *filp);
1795
1796/* VRAM scratch page for HDP bug, default vram page */
1797struct amdgpu_vram_scratch {
1798 struct amdgpu_bo *robj;
1799 volatile uint32_t *ptr;
1800 u64 gpu_addr;
1801};
1802
1803/*
1804 * ACPI
1805 */
1806struct amdgpu_atif_notification_cfg {
1807 bool enabled;
1808 int command_code;
1809};
1810
1811struct amdgpu_atif_notifications {
1812 bool display_switch;
1813 bool expansion_mode_change;
1814 bool thermal_state;
1815 bool forced_power_state;
1816 bool system_power_state;
1817 bool display_conf_change;
1818 bool px_gfx_switch;
1819 bool brightness_change;
1820 bool dgpu_display_event;
1821};
1822
1823struct amdgpu_atif_functions {
1824 bool system_params;
1825 bool sbios_requests;
1826 bool select_active_disp;
1827 bool lid_state;
1828 bool get_tv_standard;
1829 bool set_tv_standard;
1830 bool get_panel_expansion_mode;
1831 bool set_panel_expansion_mode;
1832 bool temperature_change;
1833 bool graphics_device_types;
1834};
1835
1836struct amdgpu_atif {
1837 struct amdgpu_atif_notifications notifications;
1838 struct amdgpu_atif_functions functions;
1839 struct amdgpu_atif_notification_cfg notification_cfg;
1840 struct amdgpu_encoder *encoder_for_bl;
1841};
1842
1843struct amdgpu_atcs_functions {
1844 bool get_ext_state;
1845 bool pcie_perf_req;
1846 bool pcie_dev_rdy;
1847 bool pcie_bus_width;
1848};
1849
1850struct amdgpu_atcs {
1851 struct amdgpu_atcs_functions functions;
1852};
1853
Alex Deucher97b2e202015-04-20 16:51:00 -04001854/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001855 * CGS
1856 */
1857void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1858void amdgpu_cgs_destroy_device(void *cgs_device);
1859
1860
1861/*
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001862 * CGS
1863 */
1864void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1865void amdgpu_cgs_destroy_device(void *cgs_device);
1866
1867
Alex Deucher7e471e62016-02-01 11:13:04 -05001868/* GPU virtualization */
1869struct amdgpu_virtualization {
1870 bool supports_sr_iov;
1871};
1872
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001873/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001874 * Core structure, functions and helpers.
1875 */
1876typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1877typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1878
1879typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1880typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1881
Alex Deucher8faf0e02015-07-28 11:50:31 -04001882struct amdgpu_ip_block_status {
1883 bool valid;
1884 bool sw;
1885 bool hw;
1886};
1887
Alex Deucher97b2e202015-04-20 16:51:00 -04001888struct amdgpu_device {
1889 struct device *dev;
1890 struct drm_device *ddev;
1891 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001892
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001893#ifdef CONFIG_DRM_AMD_ACP
1894 struct amdgpu_acp acp;
1895#endif
1896
Alex Deucher97b2e202015-04-20 16:51:00 -04001897 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001898 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001899 uint32_t family;
1900 uint32_t rev_id;
1901 uint32_t external_rev_id;
1902 unsigned long flags;
1903 int usec_timeout;
1904 const struct amdgpu_asic_funcs *asic_funcs;
1905 bool shutdown;
1906 bool suspend;
1907 bool need_dma32;
1908 bool accel_working;
Alex Deucher97b2e202015-04-20 16:51:00 -04001909 struct work_struct reset_work;
1910 struct notifier_block acpi_nb;
1911 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1912 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
1913 unsigned debugfs_count;
1914#if defined(CONFIG_DEBUG_FS)
1915 struct dentry *debugfs_regs;
1916#endif
1917 struct amdgpu_atif atif;
1918 struct amdgpu_atcs atcs;
1919 struct mutex srbm_mutex;
1920 /* GRBM index mutex. Protects concurrent access to GRBM index */
1921 struct mutex grbm_idx_mutex;
1922 struct dev_pm_domain vga_pm_domain;
1923 bool have_disp_power_ref;
1924
1925 /* BIOS */
1926 uint8_t *bios;
1927 bool is_atom_bios;
1928 uint16_t bios_header_start;
1929 struct amdgpu_bo *stollen_vga_memory;
1930 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1931
1932 /* Register/doorbell mmio */
1933 resource_size_t rmmio_base;
1934 resource_size_t rmmio_size;
1935 void __iomem *rmmio;
1936 /* protects concurrent MM_INDEX/DATA based register access */
1937 spinlock_t mmio_idx_lock;
1938 /* protects concurrent SMC based register access */
1939 spinlock_t smc_idx_lock;
1940 amdgpu_rreg_t smc_rreg;
1941 amdgpu_wreg_t smc_wreg;
1942 /* protects concurrent PCIE register access */
1943 spinlock_t pcie_idx_lock;
1944 amdgpu_rreg_t pcie_rreg;
1945 amdgpu_wreg_t pcie_wreg;
1946 /* protects concurrent UVD register access */
1947 spinlock_t uvd_ctx_idx_lock;
1948 amdgpu_rreg_t uvd_ctx_rreg;
1949 amdgpu_wreg_t uvd_ctx_wreg;
1950 /* protects concurrent DIDT register access */
1951 spinlock_t didt_idx_lock;
1952 amdgpu_rreg_t didt_rreg;
1953 amdgpu_wreg_t didt_wreg;
1954 /* protects concurrent ENDPOINT (audio) register access */
1955 spinlock_t audio_endpt_idx_lock;
1956 amdgpu_block_rreg_t audio_endpt_rreg;
1957 amdgpu_block_wreg_t audio_endpt_wreg;
1958 void __iomem *rio_mem;
1959 resource_size_t rio_mem_size;
1960 struct amdgpu_doorbell doorbell;
1961
1962 /* clock/pll info */
1963 struct amdgpu_clock clock;
1964
1965 /* MC */
1966 struct amdgpu_mc mc;
1967 struct amdgpu_gart gart;
1968 struct amdgpu_dummy_page dummy_page;
1969 struct amdgpu_vm_manager vm_manager;
1970
1971 /* memory management */
1972 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04001973 struct amdgpu_vram_scratch vram_scratch;
1974 struct amdgpu_wb wb;
1975 atomic64_t vram_usage;
1976 atomic64_t vram_vis_usage;
1977 atomic64_t gtt_usage;
1978 atomic64_t num_bytes_moved;
Marek Olšákd94aed52015-05-05 21:13:49 +02001979 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04001980
1981 /* display */
1982 struct amdgpu_mode_info mode_info;
1983 struct work_struct hotplug_work;
1984 struct amdgpu_irq_src crtc_irq;
1985 struct amdgpu_irq_src pageflip_irq;
1986 struct amdgpu_irq_src hpd_irq;
1987
1988 /* rings */
Alex Deucher97b2e202015-04-20 16:51:00 -04001989 unsigned fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04001990 unsigned num_rings;
1991 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1992 bool ib_pool_ready;
1993 struct amdgpu_sa_manager ring_tmp_bo;
1994
1995 /* interrupts */
1996 struct amdgpu_irq irq;
1997
Alex Deucher1f7371b2015-12-02 17:46:21 -05001998 /* powerplay */
1999 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002000 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002001 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002002
Alex Deucher97b2e202015-04-20 16:51:00 -04002003 /* dpm */
2004 struct amdgpu_pm pm;
2005 u32 cg_flags;
2006 u32 pg_flags;
2007
2008 /* amdgpu smumgr */
2009 struct amdgpu_smumgr smu;
2010
2011 /* gfx */
2012 struct amdgpu_gfx gfx;
2013
2014 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002015 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002016
2017 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002018 struct amdgpu_uvd uvd;
2019
2020 /* vce */
2021 struct amdgpu_vce vce;
2022
2023 /* firmwares */
2024 struct amdgpu_firmware firmware;
2025
2026 /* GDS */
2027 struct amdgpu_gds gds;
2028
2029 const struct amdgpu_ip_block_version *ip_blocks;
2030 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002031 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002032 struct mutex mn_lock;
2033 DECLARE_HASHTABLE(mn_hash, 7);
2034
2035 /* tracking pinned memory */
2036 u64 vram_pin_size;
2037 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002038
2039 /* amdkfd interface */
2040 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002041
Alex Deucher7e471e62016-02-01 11:13:04 -05002042 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002043};
2044
2045bool amdgpu_device_is_px(struct drm_device *dev);
2046int amdgpu_device_init(struct amdgpu_device *adev,
2047 struct drm_device *ddev,
2048 struct pci_dev *pdev,
2049 uint32_t flags);
2050void amdgpu_device_fini(struct amdgpu_device *adev);
2051int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2052
2053uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2054 bool always_indirect);
2055void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2056 bool always_indirect);
2057u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2058void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2059
2060u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2061void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2062
2063/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002064 * Registers read & write functions.
2065 */
2066#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2067#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2068#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2069#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2070#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2071#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2072#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2073#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2074#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2075#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2076#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2077#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2078#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2079#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2080#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
2081#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2082#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2083#define WREG32_P(reg, val, mask) \
2084 do { \
2085 uint32_t tmp_ = RREG32(reg); \
2086 tmp_ &= (mask); \
2087 tmp_ |= ((val) & ~(mask)); \
2088 WREG32(reg, tmp_); \
2089 } while (0)
2090#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2091#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2092#define WREG32_PLL_P(reg, val, mask) \
2093 do { \
2094 uint32_t tmp_ = RREG32_PLL(reg); \
2095 tmp_ &= (mask); \
2096 tmp_ |= ((val) & ~(mask)); \
2097 WREG32_PLL(reg, tmp_); \
2098 } while (0)
2099#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2100#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2101#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2102
2103#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2104#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2105
2106#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2107#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2108
2109#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2110 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2111 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2112
2113#define REG_GET_FIELD(value, reg, field) \
2114 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2115
2116/*
2117 * BIOS helpers.
2118 */
2119#define RBIOS8(i) (adev->bios[i])
2120#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2121#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2122
2123/*
2124 * RING helpers.
2125 */
2126static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2127{
2128 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002129 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002130 ring->ring[ring->wptr++] = v;
2131 ring->wptr &= ring->ptr_mask;
2132 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002133}
2134
Alex Deucherc113ea12015-10-08 16:30:37 -04002135static inline struct amdgpu_sdma_instance *
2136amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002137{
2138 struct amdgpu_device *adev = ring->adev;
2139 int i;
2140
Alex Deucherc113ea12015-10-08 16:30:37 -04002141 for (i = 0; i < adev->sdma.num_instances; i++)
2142 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002143 break;
2144
2145 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002146 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002147 else
2148 return NULL;
2149}
2150
Alex Deucher97b2e202015-04-20 16:51:00 -04002151/*
2152 * ASICs macro.
2153 */
2154#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2155#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
2156#define amdgpu_asic_wait_for_mc_idle(adev) (adev)->asic_funcs->wait_for_mc_idle((adev))
2157#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2158#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2159#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
2160#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
2161#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002162#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 -04002163#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
2164#define amdgpu_asic_get_cu_info(adev, info) (adev)->asic_funcs->get_cu_info((adev), (info))
2165#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2166#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2167#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 +01002168#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 -04002169#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 -04002170#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2171#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
2172#define amdgpu_ring_test_ib(r) (r)->funcs->test_ib((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002173#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2174#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2175#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
2176#define amdgpu_ring_emit_ib(r, ib) (r)->funcs->emit_ib((r), (ib))
Christian Königb8c7b392016-03-01 15:42:52 +01002177#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002178#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002179#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002180#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 +02002181#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002182#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002183#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002184#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2185#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2186#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2187#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2188#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2189#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2190#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2191#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2192#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2193#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2194#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2195#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2196#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
2197#define amdgpu_display_page_flip(adev, crtc, base) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base))
2198#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2199#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2200#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))
2201#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2202#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002203#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 +08002204#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 -04002205#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2206#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2207#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2208#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002209#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002210#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002211#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Rex Zhu3af76f22015-10-15 17:23:43 +08002212
2213#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002214 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002215 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002216 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002217
2218#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002219 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002220 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002221 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002222
2223#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002224 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002225 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002226 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002227
2228#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002229 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002230 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002231 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002232
2233#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002234 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002235 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002236 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002237
Rex Zhu1b5708f2015-11-10 18:25:24 -05002238#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002239 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002240 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002241 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002242
2243#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002244 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002245 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002246 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002247
2248
2249#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002250 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002251 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002252 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002253
2254#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002255 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002256 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002257 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002258
2259#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002260 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002261 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002262 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002263
2264#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002265 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002266 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002267 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002268
2269#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002270 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002271
2272#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002273 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002274
Eric Huangf3898ea2015-12-11 16:24:34 -05002275#define amdgpu_dpm_get_pp_num_states(adev, data) \
2276 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2277
2278#define amdgpu_dpm_get_pp_table(adev, table) \
2279 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2280
2281#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2282 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2283
2284#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2285 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2286
2287#define amdgpu_dpm_force_clock_level(adev, type, level) \
2288 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2289
Jammy Zhoue61710c2015-11-10 18:31:08 -05002290#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002291 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002292
2293#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2294
2295/* Common functions */
2296int amdgpu_gpu_reset(struct amdgpu_device *adev);
2297void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2298bool amdgpu_card_posted(struct amdgpu_device *adev);
2299void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002300
Alex Deucher97b2e202015-04-20 16:51:00 -04002301int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2302int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2303 u32 ip_instance, u32 ring,
2304 struct amdgpu_ring **out_ring);
2305void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2306bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002307int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002308int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2309 uint32_t flags);
2310bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002311struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002312bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2313 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002314bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2315 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002316bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2317uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2318 struct ttm_mem_reg *mem);
2319void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2320void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2321void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
2322void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2323 const u32 *registers,
2324 const u32 array_size);
2325
2326bool amdgpu_device_is_px(struct drm_device *dev);
2327/* atpx handler */
2328#if defined(CONFIG_VGA_SWITCHEROO)
2329void amdgpu_register_atpx_handler(void);
2330void amdgpu_unregister_atpx_handler(void);
2331#else
2332static inline void amdgpu_register_atpx_handler(void) {}
2333static inline void amdgpu_unregister_atpx_handler(void) {}
2334#endif
2335
2336/*
2337 * KMS
2338 */
2339extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
2340extern int amdgpu_max_kms_ioctl;
2341
2342int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2343int amdgpu_driver_unload_kms(struct drm_device *dev);
2344void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2345int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2346void amdgpu_driver_postclose_kms(struct drm_device *dev,
2347 struct drm_file *file_priv);
2348void amdgpu_driver_preclose_kms(struct drm_device *dev,
2349 struct drm_file *file_priv);
2350int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2351int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002352u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2353int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2354void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2355int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002356 int *max_error,
2357 struct timeval *vblank_time,
2358 unsigned flags);
2359long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2360 unsigned long arg);
2361
2362/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002363 * functions used by amdgpu_encoder.c
2364 */
2365struct amdgpu_afmt_acr {
2366 u32 clock;
2367
2368 int n_32khz;
2369 int cts_32khz;
2370
2371 int n_44_1khz;
2372 int cts_44_1khz;
2373
2374 int n_48khz;
2375 int cts_48khz;
2376
2377};
2378
2379struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2380
2381/* amdgpu_acpi.c */
2382#if defined(CONFIG_ACPI)
2383int amdgpu_acpi_init(struct amdgpu_device *adev);
2384void amdgpu_acpi_fini(struct amdgpu_device *adev);
2385bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2386int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2387 u8 perf_req, bool advertise);
2388int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2389#else
2390static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2391static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2392#endif
2393
2394struct amdgpu_bo_va_mapping *
2395amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2396 uint64_t addr, struct amdgpu_bo **bo);
2397
2398#include "amdgpu_object.h"
2399
2400#endif