blob: fa99c0d6158c67346e57e530285bacb8c7015642 [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"
Flora Cuic632d792016-08-02 11:32:41 +080054#include "amdgpu_ttm.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040055#include "amdgpu_gds.h"
Christian König56113502016-09-28 12:36:44 +020056#include "amdgpu_sync.h"
Christian König78023012016-09-28 15:33:18 +020057#include "amdgpu_ring.h"
Christian König073440d2016-09-28 15:41:50 +020058#include "amdgpu_vm.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050059#include "amd_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040060#include "amdgpu_acp.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040061
Alex Deucherb80d8472015-08-16 22:55:02 -040062#include "gpu_scheduler.h"
Monk Liuceeb50e2016-09-19 12:13:58 +080063#include "amdgpu_virt.h"
Alex Deucherb80d8472015-08-16 22:55:02 -040064
Alex Deucher97b2e202015-04-20 16:51:00 -040065/*
66 * Modules parameters.
67 */
68extern int amdgpu_modeset;
69extern int amdgpu_vram_limit;
70extern int amdgpu_gart_size;
Marek Olšák95844d22016-08-17 23:49:27 +020071extern int amdgpu_moverate;
Alex Deucher97b2e202015-04-20 16:51:00 -040072extern int amdgpu_benchmarking;
73extern int amdgpu_testing;
74extern int amdgpu_audio;
75extern int amdgpu_disp_priority;
76extern int amdgpu_hw_i2c;
77extern int amdgpu_pcie_gen2;
78extern int amdgpu_msi;
79extern int amdgpu_lockup_timeout;
80extern int amdgpu_dpm;
81extern int amdgpu_smc_load_fw;
82extern int amdgpu_aspm;
83extern int amdgpu_runtime_pm;
Alex Deucher97b2e202015-04-20 16:51:00 -040084extern unsigned amdgpu_ip_block_mask;
85extern int amdgpu_bapm;
86extern int amdgpu_deep_color;
87extern int amdgpu_vm_size;
88extern int amdgpu_vm_block_size;
Christian Königd9c13152015-09-28 12:31:26 +020089extern int amdgpu_vm_fault_stop;
Christian Königb495bd32015-09-10 14:00:35 +020090extern int amdgpu_vm_debug;
Jammy Zhou1333f722015-07-30 16:36:58 +080091extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080092extern int amdgpu_sched_hw_submission;
Alex Deucher1f7371b2015-12-02 17:46:21 -050093extern int amdgpu_powerplay;
Huang Rui6bb6b292016-05-24 13:47:05 +080094extern int amdgpu_powercontainment;
Alex Deuchercd474ba2016-02-04 10:21:23 -050095extern unsigned amdgpu_pcie_gen_cap;
96extern unsigned amdgpu_pcie_lane_cap;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +020097extern unsigned amdgpu_cg_mask;
98extern unsigned amdgpu_pg_mask;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +020099extern char *amdgpu_disable_cu;
Rex Zhu66bc3f72016-07-28 17:36:35 +0800100extern int amdgpu_sclk_deep_sleep_en;
Emily Deng9accf2f2016-08-10 16:01:25 +0800101extern char *amdgpu_virtual_display;
Rex Zhu5141e9d2016-09-06 16:34:37 +0800102extern unsigned amdgpu_pp_feature_mask;
Christian König6a7f76e2016-08-24 15:51:49 +0200103extern int amdgpu_vram_page_split;
Alex Deucher97b2e202015-04-20 16:51:00 -0400104
Chunming Zhou4b559c92015-07-21 15:53:04 +0800105#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -0400106#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
107#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
108/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
109#define AMDGPU_IB_POOL_SIZE 16
110#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
111#define AMDGPUFB_CONN_LIMIT 4
112#define AMDGPU_BIOS_NUM_SCRATCH 8
113
Jammy Zhou36f523a2015-09-01 12:54:27 +0800114/* max number of IP instances */
115#define AMDGPU_MAX_SDMA_INSTANCES 2
116
Alex Deucher97b2e202015-04-20 16:51:00 -0400117/* hardcode that limit for now */
118#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
119
120/* hard reset data */
121#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
122
123/* reset flags */
124#define AMDGPU_RESET_GFX (1 << 0)
125#define AMDGPU_RESET_COMPUTE (1 << 1)
126#define AMDGPU_RESET_DMA (1 << 2)
127#define AMDGPU_RESET_CP (1 << 3)
128#define AMDGPU_RESET_GRBM (1 << 4)
129#define AMDGPU_RESET_DMA1 (1 << 5)
130#define AMDGPU_RESET_RLC (1 << 6)
131#define AMDGPU_RESET_SEM (1 << 7)
132#define AMDGPU_RESET_IH (1 << 8)
133#define AMDGPU_RESET_VMC (1 << 9)
134#define AMDGPU_RESET_MC (1 << 10)
135#define AMDGPU_RESET_DISPLAY (1 << 11)
136#define AMDGPU_RESET_UVD (1 << 12)
137#define AMDGPU_RESET_VCE (1 << 13)
138#define AMDGPU_RESET_VCE1 (1 << 14)
139
Alex Deucher97b2e202015-04-20 16:51:00 -0400140/* GFX current status */
141#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
142#define AMDGPU_GFX_SAFE_MODE 0x00000001L
143#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
144#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
145#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
146
147/* max cursor sizes (in pixels) */
148#define CIK_CURSOR_WIDTH 128
149#define CIK_CURSOR_HEIGHT 128
150
151struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400152struct amdgpu_ib;
Alex Deucher97b2e202015-04-20 16:51:00 -0400153struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800154struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400155struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400156struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400157
158enum amdgpu_cp_irq {
159 AMDGPU_CP_IRQ_GFX_EOP = 0,
160 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
161 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
162 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
163 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
164 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
165 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
166 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
167 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
168
169 AMDGPU_CP_IRQ_LAST
170};
171
172enum amdgpu_sdma_irq {
173 AMDGPU_SDMA_IRQ_TRAP0 = 0,
174 AMDGPU_SDMA_IRQ_TRAP1,
175
176 AMDGPU_SDMA_IRQ_LAST
177};
178
179enum amdgpu_thermal_irq {
180 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
181 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
182
183 AMDGPU_THERMAL_IRQ_LAST
184};
185
Alex Deucher97b2e202015-04-20 16:51:00 -0400186int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400187 enum amd_ip_block_type block_type,
188 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400189int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400190 enum amd_ip_block_type block_type,
191 enum amd_powergating_state state);
Alex Deucher5dbbb602016-06-23 11:41:04 -0400192int amdgpu_wait_for_idle(struct amdgpu_device *adev,
193 enum amd_ip_block_type block_type);
194bool amdgpu_is_idle(struct amdgpu_device *adev,
195 enum amd_ip_block_type block_type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400196
197struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400198 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400199 u32 major;
200 u32 minor;
201 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400202 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400203};
204
205int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400206 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400207 u32 major, u32 minor);
208
209const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
210 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400211 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400212
213/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
214struct amdgpu_buffer_funcs {
215 /* maximum bytes in a single operation */
216 uint32_t copy_max_bytes;
217
218 /* number of dw to reserve per operation */
219 unsigned copy_num_dw;
220
221 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800222 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400223 /* src addr in bytes */
224 uint64_t src_offset,
225 /* dst addr in bytes */
226 uint64_t dst_offset,
227 /* number of byte to transfer */
228 uint32_t byte_count);
229
230 /* maximum bytes in a single operation */
231 uint32_t fill_max_bytes;
232
233 /* number of dw to reserve per operation */
234 unsigned fill_num_dw;
235
236 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800237 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400238 /* value to write to memory */
239 uint32_t src_data,
240 /* dst addr in bytes */
241 uint64_t dst_offset,
242 /* number of byte to fill */
243 uint32_t byte_count);
244};
245
246/* provided by hw blocks that can write ptes, e.g., sdma */
247struct amdgpu_vm_pte_funcs {
248 /* copy pte entries from GART */
249 void (*copy_pte)(struct amdgpu_ib *ib,
250 uint64_t pe, uint64_t src,
251 unsigned count);
252 /* write pte one entry at a time with addr mapping */
Christian Königde9ea7b2016-08-12 11:33:30 +0200253 void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
254 uint64_t value, unsigned count,
255 uint32_t incr);
Alex Deucher97b2e202015-04-20 16:51:00 -0400256 /* for linear pte/pde updates without addr mapping */
257 void (*set_pte_pde)(struct amdgpu_ib *ib,
258 uint64_t pe,
259 uint64_t addr, unsigned count,
260 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400261};
262
263/* provided by the gmc block */
264struct amdgpu_gart_funcs {
265 /* flush the vm tlb via mmio */
266 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
267 uint32_t vmid);
268 /* write pte/pde updates using the cpu */
269 int (*set_pte_pde)(struct amdgpu_device *adev,
270 void *cpu_pt_addr, /* cpu addr of page table */
271 uint32_t gpu_page_idx, /* pte/pde to update */
272 uint64_t addr, /* addr to write into pte/pde */
273 uint32_t flags); /* access flags */
274};
275
276/* provided by the ih block */
277struct amdgpu_ih_funcs {
278 /* ring read/write ptr handling, called from interrupt context */
279 u32 (*get_wptr)(struct amdgpu_device *adev);
280 void (*decode_iv)(struct amdgpu_device *adev,
281 struct amdgpu_iv_entry *entry);
282 void (*set_rptr)(struct amdgpu_device *adev);
283};
284
Alex Deucher97b2e202015-04-20 16:51:00 -0400285/*
286 * BIOS.
287 */
288bool amdgpu_get_bios(struct amdgpu_device *adev);
289bool amdgpu_read_bios(struct amdgpu_device *adev);
290
291/*
292 * Dummy page
293 */
294struct amdgpu_dummy_page {
295 struct page *page;
296 dma_addr_t addr;
297};
298int amdgpu_dummy_page_init(struct amdgpu_device *adev);
299void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
300
301
302/*
303 * Clocks
304 */
305
306#define AMDGPU_MAX_PPLL 3
307
308struct amdgpu_clock {
309 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
310 struct amdgpu_pll spll;
311 struct amdgpu_pll mpll;
312 /* 10 Khz units */
313 uint32_t default_mclk;
314 uint32_t default_sclk;
315 uint32_t default_dispclk;
316 uint32_t current_dispclk;
317 uint32_t dp_extclk;
318 uint32_t max_pixel_clock;
319};
320
321/*
Flora Cuic632d792016-08-02 11:32:41 +0800322 * BO.
Alex Deucher97b2e202015-04-20 16:51:00 -0400323 */
Alex Deucher97b2e202015-04-20 16:51:00 -0400324struct amdgpu_bo_list_entry {
325 struct amdgpu_bo *robj;
326 struct ttm_validate_buffer tv;
327 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400328 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100329 struct page **user_pages;
330 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400331};
332
333struct amdgpu_bo_va_mapping {
334 struct list_head list;
335 struct interval_tree_node it;
336 uint64_t offset;
337 uint32_t flags;
338};
339
340/* bo virtual addresses in a specific vm */
341struct amdgpu_bo_va {
342 /* protected by bo being reserved */
343 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800344 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400345 unsigned ref_count;
346
Christian König7fc11952015-07-30 11:53:42 +0200347 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400348 struct list_head vm_status;
349
Christian König7fc11952015-07-30 11:53:42 +0200350 /* mappings for this bo_va */
351 struct list_head invalids;
352 struct list_head valids;
353
Alex Deucher97b2e202015-04-20 16:51:00 -0400354 /* constant after initialization */
355 struct amdgpu_vm *vm;
356 struct amdgpu_bo *bo;
357};
358
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800359#define AMDGPU_GEM_DOMAIN_MAX 0x3
360
Alex Deucher97b2e202015-04-20 16:51:00 -0400361struct amdgpu_bo {
Alex Deucher97b2e202015-04-20 16:51:00 -0400362 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100363 u32 prefered_domains;
364 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800365 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400366 struct ttm_placement placement;
367 struct ttm_buffer_object tbo;
368 struct ttm_bo_kmap_obj kmap;
369 u64 flags;
370 unsigned pin_count;
371 void *kptr;
372 u64 tiling_flags;
373 u64 metadata_flags;
374 void *metadata;
375 u32 metadata_size;
376 /* list of all virtual address to which this bo
377 * is associated to
378 */
379 struct list_head va;
380 /* Constant after initialization */
Alex Deucher97b2e202015-04-20 16:51:00 -0400381 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100382 struct amdgpu_bo *parent;
Chunming Zhoue7893c42016-07-26 14:13:21 +0800383 struct amdgpu_bo *shadow;
Alex Deucher97b2e202015-04-20 16:51:00 -0400384
385 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400386 struct amdgpu_mn *mn;
387 struct list_head mn_list;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +0800388 struct list_head shadow_list;
Alex Deucher97b2e202015-04-20 16:51:00 -0400389};
390#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
391
392void amdgpu_gem_object_free(struct drm_gem_object *obj);
393int amdgpu_gem_object_open(struct drm_gem_object *obj,
394 struct drm_file *file_priv);
395void amdgpu_gem_object_close(struct drm_gem_object *obj,
396 struct drm_file *file_priv);
397unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
398struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200399struct drm_gem_object *
400amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
401 struct dma_buf_attachment *attach,
402 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400403struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
404 struct drm_gem_object *gobj,
405 int flags);
406int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
407void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
408struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
409void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
410void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
411int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
412
413/* sub-allocation manager, it has to be protected by another lock.
414 * By conception this is an helper for other part of the driver
415 * like the indirect buffer or semaphore, which both have their
416 * locking.
417 *
418 * Principe is simple, we keep a list of sub allocation in offset
419 * order (first entry has offset == 0, last entry has the highest
420 * offset).
421 *
422 * When allocating new object we first check if there is room at
423 * the end total_size - (last_object_offset + last_object_size) >=
424 * alloc_size. If so we allocate new object there.
425 *
426 * When there is not enough room at the end, we start waiting for
427 * each sub object until we reach object_offset+object_size >=
428 * alloc_size, this object then become the sub object we return.
429 *
430 * Alignment can't be bigger than page size.
431 *
432 * Hole are not considered for allocation to keep things simple.
433 * Assumption is that there won't be hole (all object on same
434 * alignment).
435 */
Christian König6ba60b82016-03-11 14:50:08 +0100436
437#define AMDGPU_SA_NUM_FENCE_LISTS 32
438
Alex Deucher97b2e202015-04-20 16:51:00 -0400439struct amdgpu_sa_manager {
440 wait_queue_head_t wq;
441 struct amdgpu_bo *bo;
442 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100443 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400444 struct list_head olist;
445 unsigned size;
446 uint64_t gpu_addr;
447 void *cpu_ptr;
448 uint32_t domain;
449 uint32_t align;
450};
451
Alex Deucher97b2e202015-04-20 16:51:00 -0400452/* sub-allocation buffer */
453struct amdgpu_sa_bo {
454 struct list_head olist;
455 struct list_head flist;
456 struct amdgpu_sa_manager *manager;
457 unsigned soffset;
458 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800459 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400460};
461
462/*
463 * GEM objects.
464 */
Christian König418aa0c2016-02-15 16:59:57 +0100465void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400466int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
467 int alignment, u32 initial_domain,
468 u64 flags, bool kernel,
469 struct drm_gem_object **obj);
470
471int amdgpu_mode_dumb_create(struct drm_file *file_priv,
472 struct drm_device *dev,
473 struct drm_mode_create_dumb *args);
474int amdgpu_mode_dumb_mmap(struct drm_file *filp,
475 struct drm_device *dev,
476 uint32_t handle, uint64_t *offset_p);
Rex Zhud573de22016-05-12 13:27:28 +0800477int amdgpu_fence_slab_init(void);
478void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400479
480/*
481 * GART structures, functions & helpers
482 */
483struct amdgpu_mc;
484
485#define AMDGPU_GPU_PAGE_SIZE 4096
486#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
487#define AMDGPU_GPU_PAGE_SHIFT 12
488#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
489
490struct amdgpu_gart {
491 dma_addr_t table_addr;
492 struct amdgpu_bo *robj;
493 void *ptr;
494 unsigned num_gpu_pages;
495 unsigned num_cpu_pages;
496 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200497#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400498 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200499#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400500 bool ready;
501 const struct amdgpu_gart_funcs *gart_funcs;
502};
503
504int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
505void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
506int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
507void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
508int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
509void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
510int amdgpu_gart_init(struct amdgpu_device *adev);
511void amdgpu_gart_fini(struct amdgpu_device *adev);
Felix Kuehlingcab0b8d2016-08-12 19:25:21 -0400512void amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
Alex Deucher97b2e202015-04-20 16:51:00 -0400513 int pages);
Felix Kuehlingcab0b8d2016-08-12 19:25:21 -0400514int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
Alex Deucher97b2e202015-04-20 16:51:00 -0400515 int pages, struct page **pagelist,
516 dma_addr_t *dma_addr, uint32_t flags);
Chunming Zhou2c0d7312016-08-30 16:36:25 +0800517int amdgpu_ttm_recover_gart(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400518
519/*
520 * GPU MC structures, functions & helpers
521 */
522struct amdgpu_mc {
523 resource_size_t aper_size;
524 resource_size_t aper_base;
525 resource_size_t agp_base;
526 /* for some chips with <= 32MB we need to lie
527 * about vram size near mc fb location */
528 u64 mc_vram_size;
529 u64 visible_vram_size;
530 u64 gtt_size;
531 u64 gtt_start;
532 u64 gtt_end;
533 u64 vram_start;
534 u64 vram_end;
535 unsigned vram_width;
536 u64 real_vram_size;
537 int vram_mtrr;
538 u64 gtt_base_align;
539 u64 mc_mask;
540 const struct firmware *fw; /* MC firmware */
541 uint32_t fw_version;
542 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800543 uint32_t vram_type;
Chunming Zhou50b01972016-07-18 16:59:24 +0800544 uint32_t srbm_soft_reset;
545 struct amdgpu_mode_mc_save save;
Alex Deucher97b2e202015-04-20 16:51:00 -0400546};
547
548/*
549 * GPU doorbell structures, functions & helpers
550 */
551typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
552{
553 AMDGPU_DOORBELL_KIQ = 0x000,
554 AMDGPU_DOORBELL_HIQ = 0x001,
555 AMDGPU_DOORBELL_DIQ = 0x002,
556 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
557 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
558 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
559 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
560 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
561 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
562 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
563 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
564 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
565 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
566 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
567 AMDGPU_DOORBELL_IH = 0x1E8,
568 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
569 AMDGPU_DOORBELL_INVALID = 0xFFFF
570} AMDGPU_DOORBELL_ASSIGNMENT;
571
572struct amdgpu_doorbell {
573 /* doorbell mmio */
574 resource_size_t base;
575 resource_size_t size;
576 u32 __iomem *ptr;
577 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
578};
579
580void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
581 phys_addr_t *aperture_base,
582 size_t *aperture_size,
583 size_t *start_offset);
584
585/*
586 * IRQS.
587 */
588
589struct amdgpu_flip_work {
Michel Dänzer325cbba2016-08-04 12:39:37 +0900590 struct delayed_work flip_work;
Alex Deucher97b2e202015-04-20 16:51:00 -0400591 struct work_struct unpin_work;
592 struct amdgpu_device *adev;
593 int crtc_id;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900594 u32 target_vblank;
Alex Deucher97b2e202015-04-20 16:51:00 -0400595 uint64_t base;
596 struct drm_pending_vblank_event *event;
Christian König765e7fb2016-09-15 15:06:50 +0200597 struct amdgpu_bo *old_abo;
Christian König1ffd2652015-08-11 17:29:52 +0200598 struct fence *excl;
599 unsigned shared_count;
600 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100601 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400602 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400603};
604
605
606/*
607 * CP & rings.
608 */
609
610struct amdgpu_ib {
611 struct amdgpu_sa_bo *sa_bo;
612 uint32_t length_dw;
613 uint64_t gpu_addr;
614 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800615 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400616};
617
Nils Wallménius62250a92016-04-10 16:30:00 +0200618extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800619
Christian König50838c82016-02-03 13:44:52 +0100620int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800621 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100622int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
623 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800624
Christian Königa5fb4ec2016-06-29 15:10:31 +0200625void amdgpu_job_free_resources(struct amdgpu_job *job);
Christian König50838c82016-02-03 13:44:52 +0100626void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100627int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100628 struct amd_sched_entity *entity, void *owner,
629 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800630
Alex Deucher97b2e202015-04-20 16:51:00 -0400631/*
Alex Deucher97b2e202015-04-20 16:51:00 -0400632 * context related structures
633 */
634
Christian König21c16bf2015-07-07 17:24:49 +0200635struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200636 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800637 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200638 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200639};
640
Alex Deucher97b2e202015-04-20 16:51:00 -0400641struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400642 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800643 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400644 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200645 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800646 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200647 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Monk Liu753ad492016-08-26 13:28:28 +0800648 bool preamble_presented;
Alex Deucher97b2e202015-04-20 16:51:00 -0400649};
650
651struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400652 struct amdgpu_device *adev;
653 struct mutex lock;
654 /* protected by lock */
655 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400656};
657
Alex Deucher0b492a42015-08-16 22:48:26 -0400658struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
659int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
660
Christian König21c16bf2015-07-07 17:24:49 +0200661uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200662 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200663struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
664 struct amdgpu_ring *ring, uint64_t seq);
665
Alex Deucher0b492a42015-08-16 22:48:26 -0400666int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
667 struct drm_file *filp);
668
Christian Königefd4ccb2015-08-04 16:20:31 +0200669void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
670void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400671
Alex Deucher97b2e202015-04-20 16:51:00 -0400672/*
673 * file private structure
674 */
675
676struct amdgpu_fpriv {
677 struct amdgpu_vm vm;
678 struct mutex bo_list_lock;
679 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -0400680 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400681};
682
683/*
684 * residency list
685 */
686
687struct amdgpu_bo_list {
688 struct mutex lock;
689 struct amdgpu_bo *gds_obj;
690 struct amdgpu_bo *gws_obj;
691 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +0100692 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400693 unsigned num_entries;
694 struct amdgpu_bo_list_entry *array;
695};
696
697struct amdgpu_bo_list *
698amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +0100699void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
700 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -0400701void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
702void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
703
704/*
705 * GFX stuff
706 */
707#include "clearstate_defs.h"
708
Alex Deucher79e54122016-04-08 15:45:13 -0400709struct amdgpu_rlc_funcs {
710 void (*enter_safe_mode)(struct amdgpu_device *adev);
711 void (*exit_safe_mode)(struct amdgpu_device *adev);
712};
713
Alex Deucher97b2e202015-04-20 16:51:00 -0400714struct amdgpu_rlc {
715 /* for power gating */
716 struct amdgpu_bo *save_restore_obj;
717 uint64_t save_restore_gpu_addr;
718 volatile uint32_t *sr_ptr;
719 const u32 *reg_list;
720 u32 reg_list_size;
721 /* for clear state */
722 struct amdgpu_bo *clear_state_obj;
723 uint64_t clear_state_gpu_addr;
724 volatile uint32_t *cs_ptr;
725 const struct cs_section_def *cs_data;
726 u32 clear_state_size;
727 /* for cp tables */
728 struct amdgpu_bo *cp_table_obj;
729 uint64_t cp_table_gpu_addr;
730 volatile uint32_t *cp_table_ptr;
731 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -0400732
733 /* safe mode for updating CG/PG state */
734 bool in_safe_mode;
735 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -0400736
737 /* for firmware data */
738 u32 save_and_restore_offset;
739 u32 clear_state_descriptor_offset;
740 u32 avail_scratch_ram_locations;
741 u32 reg_restore_list_size;
742 u32 reg_list_format_start;
743 u32 reg_list_format_separate_start;
744 u32 starting_offsets_start;
745 u32 reg_list_format_size_bytes;
746 u32 reg_list_size_bytes;
747
748 u32 *register_list_format;
749 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -0400750};
751
752struct amdgpu_mec {
753 struct amdgpu_bo *hpd_eop_obj;
754 u64 hpd_eop_gpu_addr;
755 u32 num_pipe;
756 u32 num_mec;
757 u32 num_queue;
758};
759
760/*
761 * GPU scratch registers structures, functions & helpers
762 */
763struct amdgpu_scratch {
764 unsigned num_reg;
765 uint32_t reg_base;
766 bool free[32];
767 uint32_t reg[32];
768};
769
770/*
771 * GFX configurations
772 */
Alex Deuchere3fa7632016-10-10 10:56:21 -0400773#define AMDGPU_GFX_MAX_SE 4
774#define AMDGPU_GFX_MAX_SH_PER_SE 2
775
776struct amdgpu_rb_config {
777 uint32_t rb_backend_disable;
778 uint32_t user_rb_backend_disable;
779 uint32_t raster_config;
780 uint32_t raster_config_1;
781};
782
Alex Deucher97b2e202015-04-20 16:51:00 -0400783struct amdgpu_gca_config {
784 unsigned max_shader_engines;
785 unsigned max_tile_pipes;
786 unsigned max_cu_per_sh;
787 unsigned max_sh_per_se;
788 unsigned max_backends_per_se;
789 unsigned max_texture_channel_caches;
790 unsigned max_gprs;
791 unsigned max_gs_threads;
792 unsigned max_hw_contexts;
793 unsigned sc_prim_fifo_size_frontend;
794 unsigned sc_prim_fifo_size_backend;
795 unsigned sc_hiz_tile_fifo_size;
796 unsigned sc_earlyz_tile_fifo_size;
797
798 unsigned num_tile_pipes;
799 unsigned backend_enable_mask;
800 unsigned mem_max_burst_length_bytes;
801 unsigned mem_row_size_in_kb;
802 unsigned shader_engine_tile_size;
803 unsigned num_gpus;
804 unsigned multi_gpu_tile_size;
805 unsigned mc_arb_ramcfg;
806 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -0500807 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400808
809 uint32_t tile_mode_array[32];
810 uint32_t macrotile_mode_array[16];
Alex Deuchere3fa7632016-10-10 10:56:21 -0400811
812 struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
Alex Deucher97b2e202015-04-20 16:51:00 -0400813};
814
Alex Deucher7dae69a2016-05-03 16:25:53 -0400815struct amdgpu_cu_info {
816 uint32_t number; /* total active CU number */
817 uint32_t ao_cu_mask;
818 uint32_t bitmap[4][4];
819};
820
Alex Deucherb95e31f2016-07-07 15:01:42 -0400821struct amdgpu_gfx_funcs {
822 /* get the gpu clock counter */
823 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -0400824 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Alex Deucherb95e31f2016-07-07 15:01:42 -0400825};
826
Alex Deucher97b2e202015-04-20 16:51:00 -0400827struct amdgpu_gfx {
828 struct mutex gpu_clock_mutex;
829 struct amdgpu_gca_config config;
830 struct amdgpu_rlc rlc;
831 struct amdgpu_mec mec;
832 struct amdgpu_scratch scratch;
833 const struct firmware *me_fw; /* ME firmware */
834 uint32_t me_fw_version;
835 const struct firmware *pfp_fw; /* PFP firmware */
836 uint32_t pfp_fw_version;
837 const struct firmware *ce_fw; /* CE firmware */
838 uint32_t ce_fw_version;
839 const struct firmware *rlc_fw; /* RLC firmware */
840 uint32_t rlc_fw_version;
841 const struct firmware *mec_fw; /* MEC firmware */
842 uint32_t mec_fw_version;
843 const struct firmware *mec2_fw; /* MEC2 firmware */
844 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +0800845 uint32_t me_feature_version;
846 uint32_t ce_feature_version;
847 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +0800848 uint32_t rlc_feature_version;
849 uint32_t mec_feature_version;
850 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -0400851 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
852 unsigned num_gfx_rings;
853 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
854 unsigned num_compute_rings;
855 struct amdgpu_irq_src eop_irq;
856 struct amdgpu_irq_src priv_reg_irq;
857 struct amdgpu_irq_src priv_inst_irq;
858 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -0400859 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +0800860 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -0400861 unsigned ce_ram_size;
862 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -0400863 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +0800864
865 /* reset mask */
866 uint32_t grbm_soft_reset;
867 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400868};
869
Christian Königb07c60c2016-01-31 12:29:04 +0100870int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -0400871 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +0200872void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
873 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +0100874int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +0100875 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +0800876 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400877int amdgpu_ib_pool_init(struct amdgpu_device *adev);
878void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
879int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400880
881/*
882 * CS.
883 */
884struct amdgpu_cs_chunk {
885 uint32_t chunk_id;
886 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +0200887 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -0400888};
889
890struct amdgpu_cs_parser {
891 struct amdgpu_device *adev;
892 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +0200893 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +0100894
Alex Deucher97b2e202015-04-20 16:51:00 -0400895 /* chunks */
896 unsigned nchunks;
897 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -0400898
Christian König50838c82016-02-03 13:44:52 +0100899 /* scheduler job object */
900 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400901
Christian Königc3cca412015-12-15 14:41:33 +0100902 /* buffer objects */
903 struct ww_acquire_ctx ticket;
904 struct amdgpu_bo_list *bo_list;
905 struct amdgpu_bo_list_entry vm_pd;
906 struct list_head validated;
907 struct fence *fence;
908 uint64_t bytes_moved_threshold;
909 uint64_t bytes_moved;
Christian König662bfa62016-09-01 12:13:18 +0200910 struct amdgpu_bo_list_entry *evictable;
Alex Deucher97b2e202015-04-20 16:51:00 -0400911
912 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +0100913 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -0400914};
915
Monk Liu753ad492016-08-26 13:28:28 +0800916#define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */
917#define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */
918#define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */
919
Chunming Zhoubb977d32015-08-18 15:16:40 +0800920struct amdgpu_job {
921 struct amd_sched_job base;
922 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +0200923 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +0100924 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +0100925 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800926 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +0800927 struct fence *fence; /* the hw fence */
Monk Liu753ad492016-08-26 13:28:28 +0800928 uint32_t preamble_status;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800929 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +0100930 void *owner;
Monk Liu3aecd242016-08-25 15:40:48 +0800931 uint64_t fence_ctx; /* the fence_context this job uses */
Chunming Zhoufd53be32016-07-01 17:59:01 +0800932 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +0200933 unsigned vm_id;
934 uint64_t vm_pd_addr;
935 uint32_t gds_base, gds_size;
936 uint32_t gws_base, gws_size;
937 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +0200938
939 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +0200940 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +0200941 uint64_t uf_sequence;
942
Chunming Zhoubb977d32015-08-18 15:16:40 +0800943};
Junwei Zhanga6db8a32015-09-09 09:21:19 +0800944#define to_amdgpu_job(sched_job) \
945 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +0800946
Christian König7270f832016-01-31 11:00:41 +0100947static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
948 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -0400949{
Christian König50838c82016-02-03 13:44:52 +0100950 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -0400951}
952
Christian König7270f832016-01-31 11:00:41 +0100953static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
954 uint32_t ib_idx, int idx,
955 uint32_t value)
956{
Christian König50838c82016-02-03 13:44:52 +0100957 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +0100958}
959
Alex Deucher97b2e202015-04-20 16:51:00 -0400960/*
961 * Writeback
962 */
963#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
964
965struct amdgpu_wb {
966 struct amdgpu_bo *wb_obj;
967 volatile uint32_t *wb;
968 uint64_t gpu_addr;
969 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
970 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
971};
972
973int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
974void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
975
Alex Deucher97b2e202015-04-20 16:51:00 -0400976
Alex Deucher97b2e202015-04-20 16:51:00 -0400977
978enum amdgpu_int_thermal_type {
979 THERMAL_TYPE_NONE,
980 THERMAL_TYPE_EXTERNAL,
981 THERMAL_TYPE_EXTERNAL_GPIO,
982 THERMAL_TYPE_RV6XX,
983 THERMAL_TYPE_RV770,
984 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
985 THERMAL_TYPE_EVERGREEN,
986 THERMAL_TYPE_SUMO,
987 THERMAL_TYPE_NI,
988 THERMAL_TYPE_SI,
989 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
990 THERMAL_TYPE_CI,
991 THERMAL_TYPE_KV,
992};
993
994enum amdgpu_dpm_auto_throttle_src {
995 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
996 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
997};
998
999enum amdgpu_dpm_event_src {
1000 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1001 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1002 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1003 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1004 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1005};
1006
1007#define AMDGPU_MAX_VCE_LEVELS 6
1008
1009enum amdgpu_vce_level {
1010 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1011 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1012 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1013 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1014 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1015 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1016};
1017
1018struct amdgpu_ps {
1019 u32 caps; /* vbios flags */
1020 u32 class; /* vbios flags */
1021 u32 class2; /* vbios flags */
1022 /* UVD clocks */
1023 u32 vclk;
1024 u32 dclk;
1025 /* VCE clocks */
1026 u32 evclk;
1027 u32 ecclk;
1028 bool vce_active;
1029 enum amdgpu_vce_level vce_level;
1030 /* asic priv */
1031 void *ps_priv;
1032};
1033
1034struct amdgpu_dpm_thermal {
1035 /* thermal interrupt work */
1036 struct work_struct work;
1037 /* low temperature threshold */
1038 int min_temp;
1039 /* high temperature threshold */
1040 int max_temp;
1041 /* was last interrupt low to high or high to low */
1042 bool high_to_low;
1043 /* interrupt source */
1044 struct amdgpu_irq_src irq;
1045};
1046
1047enum amdgpu_clk_action
1048{
1049 AMDGPU_SCLK_UP = 1,
1050 AMDGPU_SCLK_DOWN
1051};
1052
1053struct amdgpu_blacklist_clocks
1054{
1055 u32 sclk;
1056 u32 mclk;
1057 enum amdgpu_clk_action action;
1058};
1059
1060struct amdgpu_clock_and_voltage_limits {
1061 u32 sclk;
1062 u32 mclk;
1063 u16 vddc;
1064 u16 vddci;
1065};
1066
1067struct amdgpu_clock_array {
1068 u32 count;
1069 u32 *values;
1070};
1071
1072struct amdgpu_clock_voltage_dependency_entry {
1073 u32 clk;
1074 u16 v;
1075};
1076
1077struct amdgpu_clock_voltage_dependency_table {
1078 u32 count;
1079 struct amdgpu_clock_voltage_dependency_entry *entries;
1080};
1081
1082union amdgpu_cac_leakage_entry {
1083 struct {
1084 u16 vddc;
1085 u32 leakage;
1086 };
1087 struct {
1088 u16 vddc1;
1089 u16 vddc2;
1090 u16 vddc3;
1091 };
1092};
1093
1094struct amdgpu_cac_leakage_table {
1095 u32 count;
1096 union amdgpu_cac_leakage_entry *entries;
1097};
1098
1099struct amdgpu_phase_shedding_limits_entry {
1100 u16 voltage;
1101 u32 sclk;
1102 u32 mclk;
1103};
1104
1105struct amdgpu_phase_shedding_limits_table {
1106 u32 count;
1107 struct amdgpu_phase_shedding_limits_entry *entries;
1108};
1109
1110struct amdgpu_uvd_clock_voltage_dependency_entry {
1111 u32 vclk;
1112 u32 dclk;
1113 u16 v;
1114};
1115
1116struct amdgpu_uvd_clock_voltage_dependency_table {
1117 u8 count;
1118 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1119};
1120
1121struct amdgpu_vce_clock_voltage_dependency_entry {
1122 u32 ecclk;
1123 u32 evclk;
1124 u16 v;
1125};
1126
1127struct amdgpu_vce_clock_voltage_dependency_table {
1128 u8 count;
1129 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1130};
1131
1132struct amdgpu_ppm_table {
1133 u8 ppm_design;
1134 u16 cpu_core_number;
1135 u32 platform_tdp;
1136 u32 small_ac_platform_tdp;
1137 u32 platform_tdc;
1138 u32 small_ac_platform_tdc;
1139 u32 apu_tdp;
1140 u32 dgpu_tdp;
1141 u32 dgpu_ulv_power;
1142 u32 tj_max;
1143};
1144
1145struct amdgpu_cac_tdp_table {
1146 u16 tdp;
1147 u16 configurable_tdp;
1148 u16 tdc;
1149 u16 battery_power_limit;
1150 u16 small_power_limit;
1151 u16 low_cac_leakage;
1152 u16 high_cac_leakage;
1153 u16 maximum_power_delivery_limit;
1154};
1155
1156struct amdgpu_dpm_dynamic_state {
1157 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1158 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1159 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1160 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1161 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1162 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1163 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1164 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1165 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1166 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1167 struct amdgpu_clock_array valid_sclk_values;
1168 struct amdgpu_clock_array valid_mclk_values;
1169 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1170 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1171 u32 mclk_sclk_ratio;
1172 u32 sclk_mclk_delta;
1173 u16 vddc_vddci_delta;
1174 u16 min_vddc_for_pcie_gen2;
1175 struct amdgpu_cac_leakage_table cac_leakage_table;
1176 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1177 struct amdgpu_ppm_table *ppm_table;
1178 struct amdgpu_cac_tdp_table *cac_tdp_table;
1179};
1180
1181struct amdgpu_dpm_fan {
1182 u16 t_min;
1183 u16 t_med;
1184 u16 t_high;
1185 u16 pwm_min;
1186 u16 pwm_med;
1187 u16 pwm_high;
1188 u8 t_hyst;
1189 u32 cycle_delay;
1190 u16 t_max;
1191 u8 control_mode;
1192 u16 default_max_fan_pwm;
1193 u16 default_fan_output_sensitivity;
1194 u16 fan_output_sensitivity;
1195 bool ucode_fan_control;
1196};
1197
1198enum amdgpu_pcie_gen {
1199 AMDGPU_PCIE_GEN1 = 0,
1200 AMDGPU_PCIE_GEN2 = 1,
1201 AMDGPU_PCIE_GEN3 = 2,
1202 AMDGPU_PCIE_GEN_INVALID = 0xffff
1203};
1204
1205enum amdgpu_dpm_forced_level {
1206 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1207 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1208 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001209 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001210};
1211
1212struct amdgpu_vce_state {
1213 /* vce clocks */
1214 u32 evclk;
1215 u32 ecclk;
1216 /* gpu clocks */
1217 u32 sclk;
1218 u32 mclk;
1219 u8 clk_idx;
1220 u8 pstate;
1221};
1222
1223struct amdgpu_dpm_funcs {
1224 int (*get_temperature)(struct amdgpu_device *adev);
1225 int (*pre_set_power_state)(struct amdgpu_device *adev);
1226 int (*set_power_state)(struct amdgpu_device *adev);
1227 void (*post_set_power_state)(struct amdgpu_device *adev);
1228 void (*display_configuration_changed)(struct amdgpu_device *adev);
1229 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1230 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1231 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1232 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1233 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1234 bool (*vblank_too_short)(struct amdgpu_device *adev);
1235 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a077692015-05-28 15:47:53 -04001236 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001237 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1238 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1239 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1240 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1241 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001242 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1243 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001244 int (*get_sclk_od)(struct amdgpu_device *adev);
1245 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001246 int (*get_mclk_od)(struct amdgpu_device *adev);
1247 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001248};
1249
1250struct amdgpu_dpm {
1251 struct amdgpu_ps *ps;
1252 /* number of valid power states */
1253 int num_ps;
1254 /* current power state that is active */
1255 struct amdgpu_ps *current_ps;
1256 /* requested power state */
1257 struct amdgpu_ps *requested_ps;
1258 /* boot up power state */
1259 struct amdgpu_ps *boot_ps;
1260 /* default uvd power state */
1261 struct amdgpu_ps *uvd_ps;
1262 /* vce requirements */
1263 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1264 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001265 enum amd_pm_state_type state;
1266 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001267 u32 platform_caps;
1268 u32 voltage_response_time;
1269 u32 backbias_response_time;
1270 void *priv;
1271 u32 new_active_crtcs;
1272 int new_active_crtc_count;
1273 u32 current_active_crtcs;
1274 int current_active_crtc_count;
1275 struct amdgpu_dpm_dynamic_state dyn_state;
1276 struct amdgpu_dpm_fan fan;
1277 u32 tdp_limit;
1278 u32 near_tdp_limit;
1279 u32 near_tdp_limit_adjusted;
1280 u32 sq_ramping_threshold;
1281 u32 cac_leakage;
1282 u16 tdp_od_limit;
1283 u32 tdp_adjustment;
1284 u16 load_line_slope;
1285 bool power_control;
1286 bool ac_power;
1287 /* special states active */
1288 bool thermal_active;
1289 bool uvd_active;
1290 bool vce_active;
1291 /* thermal handling */
1292 struct amdgpu_dpm_thermal thermal;
1293 /* forced levels */
1294 enum amdgpu_dpm_forced_level forced_level;
1295};
1296
1297struct amdgpu_pm {
1298 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001299 u32 current_sclk;
1300 u32 current_mclk;
1301 u32 default_sclk;
1302 u32 default_mclk;
1303 struct amdgpu_i2c_chan *i2c_bus;
1304 /* internal thermal controller on rv6xx+ */
1305 enum amdgpu_int_thermal_type int_thermal_type;
1306 struct device *int_hwmon_dev;
1307 /* fan control parameters */
1308 bool no_fan;
1309 u8 fan_pulses_per_revolution;
1310 u8 fan_min_rpm;
1311 u8 fan_max_rpm;
1312 /* dpm */
1313 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001314 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001315 struct amdgpu_dpm dpm;
1316 const struct firmware *fw; /* SMC firmware */
1317 uint32_t fw_version;
1318 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001319 uint32_t pcie_gen_mask;
1320 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001321 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001322};
1323
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001324void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1325
Alex Deucher97b2e202015-04-20 16:51:00 -04001326/*
1327 * UVD
1328 */
Arindam Nathc0365542016-04-12 13:46:15 +02001329#define AMDGPU_DEFAULT_UVD_HANDLES 10
1330#define AMDGPU_MAX_UVD_HANDLES 40
1331#define AMDGPU_UVD_STACK_SIZE (200*1024)
1332#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1333#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1334#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001335
1336struct amdgpu_uvd {
1337 struct amdgpu_bo *vcpu_bo;
1338 void *cpu_addr;
1339 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001340 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001341 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001342 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001343 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1344 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1345 struct delayed_work idle_work;
1346 const struct firmware *fw; /* UVD firmware */
1347 struct amdgpu_ring ring;
1348 struct amdgpu_irq_src irq;
1349 bool address_64_bit;
Christian König4cb5877c2016-07-26 12:05:40 +02001350 bool use_ctx_buf;
Christian Königead833e2016-02-10 14:35:19 +01001351 struct amd_sched_entity entity;
Chunming Zhoufc0b3b92016-07-18 17:18:01 +08001352 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001353};
1354
1355/*
1356 * VCE
1357 */
1358#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001359#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1360
Alex Deucher6a585772015-07-10 14:16:24 -04001361#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1362#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1363
Alex Deucher97b2e202015-04-20 16:51:00 -04001364struct amdgpu_vce {
1365 struct amdgpu_bo *vcpu_bo;
1366 uint64_t gpu_addr;
1367 unsigned fw_version;
1368 unsigned fb_version;
1369 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1370 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001371 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001372 struct delayed_work idle_work;
Christian Königebff4852016-07-20 16:53:36 +02001373 struct mutex idle_mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001374 const struct firmware *fw; /* VCE firmware */
1375 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1376 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001377 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001378 struct amd_sched_entity entity;
Chunming Zhou115933a2016-07-18 17:38:50 +08001379 uint32_t srbm_soft_reset;
Alex Deucher75c65482016-08-24 16:56:21 -04001380 unsigned num_rings;
Alex Deucher97b2e202015-04-20 16:51:00 -04001381};
1382
1383/*
1384 * SDMA
1385 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001386struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001387 /* SDMA firmware */
1388 const struct firmware *fw;
1389 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001390 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001391
1392 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001393 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001394};
1395
Alex Deucherc113ea12015-10-08 16:30:37 -04001396struct amdgpu_sdma {
1397 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
Ken Wang30d15742016-01-19 14:05:23 +08001398#ifdef CONFIG_DRM_AMDGPU_SI
1399 //SI DMA has a difference trap irq number for the second engine
1400 struct amdgpu_irq_src trap_irq_1;
1401#endif
Alex Deucherc113ea12015-10-08 16:30:37 -04001402 struct amdgpu_irq_src trap_irq;
1403 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001404 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001405 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001406};
1407
Alex Deucher97b2e202015-04-20 16:51:00 -04001408/*
1409 * Firmware
1410 */
1411struct amdgpu_firmware {
1412 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1413 bool smu_load;
1414 struct amdgpu_bo *fw_buf;
1415 unsigned int fw_size;
1416};
1417
1418/*
1419 * Benchmarking
1420 */
1421void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1422
1423
1424/*
1425 * Testing
1426 */
1427void amdgpu_test_moves(struct amdgpu_device *adev);
1428void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1429 struct amdgpu_ring *cpA,
1430 struct amdgpu_ring *cpB);
1431void amdgpu_test_syncing(struct amdgpu_device *adev);
1432
1433/*
1434 * MMU Notifier
1435 */
1436#if defined(CONFIG_MMU_NOTIFIER)
1437int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1438void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1439#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001440static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001441{
1442 return -ENODEV;
1443}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001444static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001445#endif
1446
1447/*
1448 * Debugfs
1449 */
1450struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001451 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001452 unsigned num_files;
1453};
1454
1455int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001456 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001457 unsigned nfiles);
1458int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1459
1460#if defined(CONFIG_DEBUG_FS)
1461int amdgpu_debugfs_init(struct drm_minor *minor);
1462void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1463#endif
1464
Huang Rui50ab2532016-06-12 15:51:09 +08001465int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1466
Alex Deucher97b2e202015-04-20 16:51:00 -04001467/*
1468 * amdgpu smumgr functions
1469 */
1470struct amdgpu_smumgr_funcs {
1471 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1472 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1473 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1474};
1475
1476/*
1477 * amdgpu smumgr
1478 */
1479struct amdgpu_smumgr {
1480 struct amdgpu_bo *toc_buf;
1481 struct amdgpu_bo *smu_buf;
1482 /* asic priv smu data */
1483 void *priv;
1484 spinlock_t smu_lock;
1485 /* smumgr functions */
1486 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1487 /* ucode loading complete flag */
1488 uint32_t fw_flags;
1489};
1490
1491/*
1492 * ASIC specific register table accessible by UMD
1493 */
1494struct amdgpu_allowed_register_entry {
1495 uint32_t reg_offset;
1496 bool untouched;
1497 bool grbm_indexed;
1498};
1499
Alex Deucher97b2e202015-04-20 16:51:00 -04001500/*
1501 * ASIC specific functions.
1502 */
1503struct amdgpu_asic_funcs {
1504 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001505 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1506 u8 *bios, u32 length_bytes);
Monk Liu4e99a442016-03-31 13:26:59 +08001507 void (*detect_hw_virtualization) (struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001508 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1509 u32 sh_num, u32 reg_offset, u32 *value);
1510 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1511 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001512 /* get the reference clock */
1513 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001514 /* MM block clocks */
1515 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1516 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Maruthi Bayyavarapu841686d2016-08-01 12:42:32 -04001517 /* static power management */
1518 int (*get_pcie_lanes)(struct amdgpu_device *adev);
1519 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001520};
1521
1522/*
1523 * IOCTL.
1524 */
1525int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1526 struct drm_file *filp);
1527int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1528 struct drm_file *filp);
1529
1530int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1531 struct drm_file *filp);
1532int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1533 struct drm_file *filp);
1534int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1535 struct drm_file *filp);
1536int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1537 struct drm_file *filp);
1538int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1539 struct drm_file *filp);
1540int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1541 struct drm_file *filp);
1542int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1543int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1544
1545int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1546 struct drm_file *filp);
1547
1548/* VRAM scratch page for HDP bug, default vram page */
1549struct amdgpu_vram_scratch {
1550 struct amdgpu_bo *robj;
1551 volatile uint32_t *ptr;
1552 u64 gpu_addr;
1553};
1554
1555/*
1556 * ACPI
1557 */
1558struct amdgpu_atif_notification_cfg {
1559 bool enabled;
1560 int command_code;
1561};
1562
1563struct amdgpu_atif_notifications {
1564 bool display_switch;
1565 bool expansion_mode_change;
1566 bool thermal_state;
1567 bool forced_power_state;
1568 bool system_power_state;
1569 bool display_conf_change;
1570 bool px_gfx_switch;
1571 bool brightness_change;
1572 bool dgpu_display_event;
1573};
1574
1575struct amdgpu_atif_functions {
1576 bool system_params;
1577 bool sbios_requests;
1578 bool select_active_disp;
1579 bool lid_state;
1580 bool get_tv_standard;
1581 bool set_tv_standard;
1582 bool get_panel_expansion_mode;
1583 bool set_panel_expansion_mode;
1584 bool temperature_change;
1585 bool graphics_device_types;
1586};
1587
1588struct amdgpu_atif {
1589 struct amdgpu_atif_notifications notifications;
1590 struct amdgpu_atif_functions functions;
1591 struct amdgpu_atif_notification_cfg notification_cfg;
1592 struct amdgpu_encoder *encoder_for_bl;
1593};
1594
1595struct amdgpu_atcs_functions {
1596 bool get_ext_state;
1597 bool pcie_perf_req;
1598 bool pcie_dev_rdy;
1599 bool pcie_bus_width;
1600};
1601
1602struct amdgpu_atcs {
1603 struct amdgpu_atcs_functions functions;
1604};
1605
Alex Deucher97b2e202015-04-20 16:51:00 -04001606/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001607 * CGS
1608 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001609struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1610void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001611
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001612/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001613 * Core structure, functions and helpers.
1614 */
1615typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1616typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1617
1618typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1619typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1620
Alex Deucher8faf0e082015-07-28 11:50:31 -04001621struct amdgpu_ip_block_status {
1622 bool valid;
1623 bool sw;
1624 bool hw;
Grazvydas Ignotas8a2eef12016-10-03 00:06:44 +03001625 bool late_initialized;
Chunming Zhou63fbf422016-07-15 11:19:20 +08001626 bool hang;
Alex Deucher8faf0e082015-07-28 11:50:31 -04001627};
1628
Alex Deucher97b2e202015-04-20 16:51:00 -04001629struct amdgpu_device {
1630 struct device *dev;
1631 struct drm_device *ddev;
1632 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001633
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001634#ifdef CONFIG_DRM_AMD_ACP
1635 struct amdgpu_acp acp;
1636#endif
1637
Alex Deucher97b2e202015-04-20 16:51:00 -04001638 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001639 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001640 uint32_t family;
1641 uint32_t rev_id;
1642 uint32_t external_rev_id;
1643 unsigned long flags;
1644 int usec_timeout;
1645 const struct amdgpu_asic_funcs *asic_funcs;
1646 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001647 bool need_dma32;
1648 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001649 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001650 struct notifier_block acpi_nb;
1651 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1652 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001653 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001654#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001655 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001656#endif
1657 struct amdgpu_atif atif;
1658 struct amdgpu_atcs atcs;
1659 struct mutex srbm_mutex;
1660 /* GRBM index mutex. Protects concurrent access to GRBM index */
1661 struct mutex grbm_idx_mutex;
1662 struct dev_pm_domain vga_pm_domain;
1663 bool have_disp_power_ref;
1664
1665 /* BIOS */
1666 uint8_t *bios;
1667 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001668 struct amdgpu_bo *stollen_vga_memory;
1669 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1670
1671 /* Register/doorbell mmio */
1672 resource_size_t rmmio_base;
1673 resource_size_t rmmio_size;
1674 void __iomem *rmmio;
1675 /* protects concurrent MM_INDEX/DATA based register access */
1676 spinlock_t mmio_idx_lock;
1677 /* protects concurrent SMC based register access */
1678 spinlock_t smc_idx_lock;
1679 amdgpu_rreg_t smc_rreg;
1680 amdgpu_wreg_t smc_wreg;
1681 /* protects concurrent PCIE register access */
1682 spinlock_t pcie_idx_lock;
1683 amdgpu_rreg_t pcie_rreg;
1684 amdgpu_wreg_t pcie_wreg;
Huang Rui36b9a952016-08-31 13:23:25 +08001685 amdgpu_rreg_t pciep_rreg;
1686 amdgpu_wreg_t pciep_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001687 /* protects concurrent UVD register access */
1688 spinlock_t uvd_ctx_idx_lock;
1689 amdgpu_rreg_t uvd_ctx_rreg;
1690 amdgpu_wreg_t uvd_ctx_wreg;
1691 /* protects concurrent DIDT register access */
1692 spinlock_t didt_idx_lock;
1693 amdgpu_rreg_t didt_rreg;
1694 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08001695 /* protects concurrent gc_cac register access */
1696 spinlock_t gc_cac_idx_lock;
1697 amdgpu_rreg_t gc_cac_rreg;
1698 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001699 /* protects concurrent ENDPOINT (audio) register access */
1700 spinlock_t audio_endpt_idx_lock;
1701 amdgpu_block_rreg_t audio_endpt_rreg;
1702 amdgpu_block_wreg_t audio_endpt_wreg;
1703 void __iomem *rio_mem;
1704 resource_size_t rio_mem_size;
1705 struct amdgpu_doorbell doorbell;
1706
1707 /* clock/pll info */
1708 struct amdgpu_clock clock;
1709
1710 /* MC */
1711 struct amdgpu_mc mc;
1712 struct amdgpu_gart gart;
1713 struct amdgpu_dummy_page dummy_page;
1714 struct amdgpu_vm_manager vm_manager;
1715
1716 /* memory management */
1717 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04001718 struct amdgpu_vram_scratch vram_scratch;
1719 struct amdgpu_wb wb;
1720 atomic64_t vram_usage;
1721 atomic64_t vram_vis_usage;
1722 atomic64_t gtt_usage;
1723 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02001724 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02001725 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04001726
Marek Olšák95844d22016-08-17 23:49:27 +02001727 /* data for buffer migration throttling */
1728 struct {
1729 spinlock_t lock;
1730 s64 last_update_us;
1731 s64 accum_us; /* accumulated microseconds */
1732 u32 log2_max_MBps;
1733 } mm_stats;
1734
Alex Deucher97b2e202015-04-20 16:51:00 -04001735 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08001736 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04001737 struct amdgpu_mode_info mode_info;
1738 struct work_struct hotplug_work;
1739 struct amdgpu_irq_src crtc_irq;
1740 struct amdgpu_irq_src pageflip_irq;
1741 struct amdgpu_irq_src hpd_irq;
1742
1743 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02001744 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04001745 unsigned num_rings;
1746 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1747 bool ib_pool_ready;
1748 struct amdgpu_sa_manager ring_tmp_bo;
1749
1750 /* interrupts */
1751 struct amdgpu_irq irq;
1752
Alex Deucher1f7371b2015-12-02 17:46:21 -05001753 /* powerplay */
1754 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05001755 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05001756 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05001757
Alex Deucher97b2e202015-04-20 16:51:00 -04001758 /* dpm */
1759 struct amdgpu_pm pm;
1760 u32 cg_flags;
1761 u32 pg_flags;
1762
1763 /* amdgpu smumgr */
1764 struct amdgpu_smumgr smu;
1765
1766 /* gfx */
1767 struct amdgpu_gfx gfx;
1768
1769 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04001770 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04001771
1772 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04001773 struct amdgpu_uvd uvd;
1774
1775 /* vce */
1776 struct amdgpu_vce vce;
1777
1778 /* firmwares */
1779 struct amdgpu_firmware firmware;
1780
1781 /* GDS */
1782 struct amdgpu_gds gds;
1783
1784 const struct amdgpu_ip_block_version *ip_blocks;
1785 int num_ip_blocks;
Alex Deucher8faf0e082015-07-28 11:50:31 -04001786 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04001787 struct mutex mn_lock;
1788 DECLARE_HASHTABLE(mn_hash, 7);
1789
1790 /* tracking pinned memory */
1791 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08001792 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001793 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03001794
1795 /* amdkfd interface */
1796 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08001797
Alex Deucher7e471e62016-02-01 11:13:04 -05001798 struct amdgpu_virtualization virtualization;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +08001799
1800 /* link all shadow bo */
1801 struct list_head shadow_list;
1802 struct mutex shadow_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08001803 /* link all gtt */
1804 spinlock_t gtt_list_lock;
1805 struct list_head gtt_list;
1806
Alex Deucher97b2e202015-04-20 16:51:00 -04001807};
1808
Christian Königa7d64de2016-09-15 14:58:48 +02001809static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1810{
1811 return container_of(bdev, struct amdgpu_device, mman.bdev);
1812}
1813
Alex Deucher97b2e202015-04-20 16:51:00 -04001814bool amdgpu_device_is_px(struct drm_device *dev);
1815int amdgpu_device_init(struct amdgpu_device *adev,
1816 struct drm_device *ddev,
1817 struct pci_dev *pdev,
1818 uint32_t flags);
1819void amdgpu_device_fini(struct amdgpu_device *adev);
1820int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1821
1822uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
1823 bool always_indirect);
1824void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
1825 bool always_indirect);
1826u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1827void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1828
1829u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1830void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1831
1832/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001833 * Registers read & write functions.
1834 */
1835#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
1836#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
1837#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
1838#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
1839#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
1840#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1841#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1842#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1843#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
Huang Rui36b9a952016-08-31 13:23:25 +08001844#define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
1845#define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001846#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
1847#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
1848#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
1849#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
1850#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
1851#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08001852#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1853#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001854#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
1855#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
1856#define WREG32_P(reg, val, mask) \
1857 do { \
1858 uint32_t tmp_ = RREG32(reg); \
1859 tmp_ &= (mask); \
1860 tmp_ |= ((val) & ~(mask)); \
1861 WREG32(reg, tmp_); \
1862 } while (0)
1863#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1864#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1865#define WREG32_PLL_P(reg, val, mask) \
1866 do { \
1867 uint32_t tmp_ = RREG32_PLL(reg); \
1868 tmp_ &= (mask); \
1869 tmp_ |= ((val) & ~(mask)); \
1870 WREG32_PLL(reg, tmp_); \
1871 } while (0)
1872#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
1873#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1874#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1875
1876#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
1877#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1878
1879#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1880#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1881
1882#define REG_SET_FIELD(orig_val, reg, field, field_val) \
1883 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
1884 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1885
1886#define REG_GET_FIELD(value, reg, field) \
1887 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1888
Tom St Denis61cb8ce2016-08-09 10:13:21 -04001889#define WREG32_FIELD(reg, field, val) \
1890 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1891
Alex Deucher97b2e202015-04-20 16:51:00 -04001892/*
1893 * BIOS helpers.
1894 */
1895#define RBIOS8(i) (adev->bios[i])
1896#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1897#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1898
1899/*
1900 * RING helpers.
1901 */
1902static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
1903{
1904 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08001905 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04001906 ring->ring[ring->wptr++] = v;
1907 ring->wptr &= ring->ptr_mask;
1908 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04001909}
1910
Alex Deucherc113ea12015-10-08 16:30:37 -04001911static inline struct amdgpu_sdma_instance *
1912amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001913{
1914 struct amdgpu_device *adev = ring->adev;
1915 int i;
1916
Alex Deucherc113ea12015-10-08 16:30:37 -04001917 for (i = 0; i < adev->sdma.num_instances; i++)
1918 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001919 break;
1920
1921 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04001922 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001923 else
1924 return NULL;
1925}
1926
Alex Deucher97b2e202015-04-20 16:51:00 -04001927/*
1928 * ASICs macro.
1929 */
1930#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1931#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001932#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1933#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1934#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
Maruthi Bayyavarapu841686d2016-08-01 12:42:32 -04001935#define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1936#define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1937#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001938#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05001939#define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
Monk Liu4e99a442016-03-31 13:26:59 +08001940#define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001941#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
Alex Deucher97b2e202015-04-20 16:51:00 -04001942#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
1943#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
1944#define amdgpu_vm_copy_pte(adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Christian Königde9ea7b2016-08-12 11:33:30 +02001945#define amdgpu_vm_write_pte(adev, ib, pe, value, count, incr) ((adev)->vm_manager.vm_pte_funcs->write_pte((ib), (pe), (value), (count), (incr)))
Alex Deucher97b2e202015-04-20 16:51:00 -04001946#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 -04001947#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
1948#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02001949#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04001950#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
1951#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
1952#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02001953#define amdgpu_ring_emit_ib(r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))
Christian Königb8c7b392016-03-01 15:42:52 +01001954#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04001955#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08001956#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04001957#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 +02001958#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08001959#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Monk Liuc2167a62016-08-26 14:12:37 +08001960#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
Monk Liu753ad492016-08-26 13:28:28 +08001961#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
Christian König9e5d53092016-01-31 12:20:55 +01001962#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08001963#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
1964#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04001965#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
1966#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
1967#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
1968#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
1969#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
1970#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
1971#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
1972#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
1973#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
1974#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
1975#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
1976#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
1977#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04001978#define amdgpu_display_page_flip(adev, crtc, base, async) (adev)->mode_info.funcs->page_flip((adev), (crtc), (base), (async))
Alex Deucher97b2e202015-04-20 16:51:00 -04001979#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
1980#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
1981#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))
1982#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
1983#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08001984#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 +08001985#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 -04001986#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
1987#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
1988#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
1989#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001990#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04001991#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001992#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04001993#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04001994#define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
Rex Zhu3af76f22015-10-15 17:23:43 +08001995
Tom St Denis3de4ec52016-09-19 12:48:52 -04001996#define amdgpu_dpm_read_sensor(adev, idx, value) \
1997 ((adev)->pp_enabled ? \
1998 (adev)->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, (idx), (value)) : \
1999 -EINVAL)
2000
Rex Zhu3af76f22015-10-15 17:23:43 +08002001#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002002 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002003 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002004 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002005
2006#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002007 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002008 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002009 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002010
2011#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002012 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002013 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002014 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002015
2016#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002017 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002018 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002019 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002020
2021#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002022 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002023 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002024 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002025
Rex Zhu1b5708f2015-11-10 18:25:24 -05002026#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002027 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002028 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002029 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002030
2031#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002032 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002033 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002034 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002035
2036
2037#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002038 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002039 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002040 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002041
2042#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002043 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002044 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002045 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002046
2047#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002048 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002049 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002050 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002051
Rex Zhu1b5708f2015-11-10 18:25:24 -05002052#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002053 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002054
2055#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002056 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002057
Eric Huangf3898ea2015-12-11 16:24:34 -05002058#define amdgpu_dpm_get_pp_num_states(adev, data) \
2059 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2060
2061#define amdgpu_dpm_get_pp_table(adev, table) \
2062 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2063
2064#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2065 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2066
2067#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2068 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2069
2070#define amdgpu_dpm_force_clock_level(adev, type, level) \
2071 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2072
Eric Huang428bafa2016-05-12 14:51:21 -04002073#define amdgpu_dpm_get_sclk_od(adev) \
2074 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2075
2076#define amdgpu_dpm_set_sclk_od(adev, value) \
2077 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2078
Eric Huangf2bdc052016-05-24 15:11:17 -04002079#define amdgpu_dpm_get_mclk_od(adev) \
2080 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2081
2082#define amdgpu_dpm_set_mclk_od(adev, value) \
2083 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2084
Jammy Zhoue61710c2015-11-10 18:31:08 -05002085#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002086 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002087
2088#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2089
2090/* Common functions */
2091int amdgpu_gpu_reset(struct amdgpu_device *adev);
Chunming Zhou3ad81f12016-08-05 17:30:17 +08002092bool amdgpu_need_backup(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002093void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2094bool amdgpu_card_posted(struct amdgpu_device *adev);
2095void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002096
Alex Deucher97b2e202015-04-20 16:51:00 -04002097int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2098int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2099 u32 ip_instance, u32 ring,
2100 struct amdgpu_ring **out_ring);
Christian König765e7fb2016-09-15 15:06:50 +02002101void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
Alex Deucher97b2e202015-04-20 16:51:00 -04002102bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002103int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002104int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2105 uint32_t flags);
2106bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002107struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002108bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2109 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002110bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2111 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002112bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2113uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2114 struct ttm_mem_reg *mem);
2115void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2116void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2117void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Ken Wanga693e052016-07-27 19:18:01 +08002118u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2119int amdgpu_ttm_global_init(struct amdgpu_device *adev);
Baoyou Xie9f31a0b02016-09-15 21:43:26 +08002120int amdgpu_ttm_init(struct amdgpu_device *adev);
2121void amdgpu_ttm_fini(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002122void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2123 const u32 *registers,
2124 const u32 array_size);
2125
2126bool amdgpu_device_is_px(struct drm_device *dev);
2127/* atpx handler */
2128#if defined(CONFIG_VGA_SWITCHEROO)
2129void amdgpu_register_atpx_handler(void);
2130void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002131bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002132bool amdgpu_is_atpx_hybrid(void);
Alex Deucherefc83cf2016-09-14 14:01:41 -04002133bool amdgpu_atpx_dgpu_req_power_for_displays(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002134#else
2135static inline void amdgpu_register_atpx_handler(void) {}
2136static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002137static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002138static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucherefc83cf2016-09-14 14:01:41 -04002139static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002140#endif
2141
2142/*
2143 * KMS
2144 */
2145extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002146extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002147
2148int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2149int amdgpu_driver_unload_kms(struct drm_device *dev);
2150void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2151int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2152void amdgpu_driver_postclose_kms(struct drm_device *dev,
2153 struct drm_file *file_priv);
2154void amdgpu_driver_preclose_kms(struct drm_device *dev,
2155 struct drm_file *file_priv);
Alex Deucher810ddc32016-08-23 13:25:49 -04002156int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
2157int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002158u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2159int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2160void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2161int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002162 int *max_error,
2163 struct timeval *vblank_time,
2164 unsigned flags);
2165long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2166 unsigned long arg);
2167
2168/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002169 * functions used by amdgpu_encoder.c
2170 */
2171struct amdgpu_afmt_acr {
2172 u32 clock;
2173
2174 int n_32khz;
2175 int cts_32khz;
2176
2177 int n_44_1khz;
2178 int cts_44_1khz;
2179
2180 int n_48khz;
2181 int cts_48khz;
2182
2183};
2184
2185struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2186
2187/* amdgpu_acpi.c */
2188#if defined(CONFIG_ACPI)
2189int amdgpu_acpi_init(struct amdgpu_device *adev);
2190void amdgpu_acpi_fini(struct amdgpu_device *adev);
2191bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2192int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2193 u8 perf_req, bool advertise);
2194int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2195#else
2196static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2197static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2198#endif
2199
2200struct amdgpu_bo_va_mapping *
2201amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2202 uint64_t addr, struct amdgpu_bo **bo);
Christian Königc855e252016-09-05 17:00:57 +02002203int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
Alex Deucher97b2e202015-04-20 16:51:00 -04002204
2205#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002206#endif