blob: 7d30a8e03bedc35e096c8fd10c1e084f7112c741 [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 */
773struct amdgpu_gca_config {
774 unsigned max_shader_engines;
775 unsigned max_tile_pipes;
776 unsigned max_cu_per_sh;
777 unsigned max_sh_per_se;
778 unsigned max_backends_per_se;
779 unsigned max_texture_channel_caches;
780 unsigned max_gprs;
781 unsigned max_gs_threads;
782 unsigned max_hw_contexts;
783 unsigned sc_prim_fifo_size_frontend;
784 unsigned sc_prim_fifo_size_backend;
785 unsigned sc_hiz_tile_fifo_size;
786 unsigned sc_earlyz_tile_fifo_size;
787
788 unsigned num_tile_pipes;
789 unsigned backend_enable_mask;
790 unsigned mem_max_burst_length_bytes;
791 unsigned mem_row_size_in_kb;
792 unsigned shader_engine_tile_size;
793 unsigned num_gpus;
794 unsigned multi_gpu_tile_size;
795 unsigned mc_arb_ramcfg;
796 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -0500797 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400798
799 uint32_t tile_mode_array[32];
800 uint32_t macrotile_mode_array[16];
801};
802
Alex Deucher7dae69a2016-05-03 16:25:53 -0400803struct amdgpu_cu_info {
804 uint32_t number; /* total active CU number */
805 uint32_t ao_cu_mask;
806 uint32_t bitmap[4][4];
807};
808
Alex Deucherb95e31f2016-07-07 15:01:42 -0400809struct amdgpu_gfx_funcs {
810 /* get the gpu clock counter */
811 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -0400812 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Alex Deucherb95e31f2016-07-07 15:01:42 -0400813};
814
Alex Deucher97b2e202015-04-20 16:51:00 -0400815struct amdgpu_gfx {
816 struct mutex gpu_clock_mutex;
817 struct amdgpu_gca_config config;
818 struct amdgpu_rlc rlc;
819 struct amdgpu_mec mec;
820 struct amdgpu_scratch scratch;
821 const struct firmware *me_fw; /* ME firmware */
822 uint32_t me_fw_version;
823 const struct firmware *pfp_fw; /* PFP firmware */
824 uint32_t pfp_fw_version;
825 const struct firmware *ce_fw; /* CE firmware */
826 uint32_t ce_fw_version;
827 const struct firmware *rlc_fw; /* RLC firmware */
828 uint32_t rlc_fw_version;
829 const struct firmware *mec_fw; /* MEC firmware */
830 uint32_t mec_fw_version;
831 const struct firmware *mec2_fw; /* MEC2 firmware */
832 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +0800833 uint32_t me_feature_version;
834 uint32_t ce_feature_version;
835 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +0800836 uint32_t rlc_feature_version;
837 uint32_t mec_feature_version;
838 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -0400839 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
840 unsigned num_gfx_rings;
841 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
842 unsigned num_compute_rings;
843 struct amdgpu_irq_src eop_irq;
844 struct amdgpu_irq_src priv_reg_irq;
845 struct amdgpu_irq_src priv_inst_irq;
846 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -0400847 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +0800848 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -0400849 unsigned ce_ram_size;
850 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -0400851 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +0800852
853 /* reset mask */
854 uint32_t grbm_soft_reset;
855 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400856};
857
Christian Königb07c60c2016-01-31 12:29:04 +0100858int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -0400859 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +0200860void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
861 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +0100862int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +0100863 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +0800864 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400865int amdgpu_ib_pool_init(struct amdgpu_device *adev);
866void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
867int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400868
869/*
870 * CS.
871 */
872struct amdgpu_cs_chunk {
873 uint32_t chunk_id;
874 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +0200875 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -0400876};
877
878struct amdgpu_cs_parser {
879 struct amdgpu_device *adev;
880 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +0200881 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +0100882
Alex Deucher97b2e202015-04-20 16:51:00 -0400883 /* chunks */
884 unsigned nchunks;
885 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -0400886
Christian König50838c82016-02-03 13:44:52 +0100887 /* scheduler job object */
888 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400889
Christian Königc3cca412015-12-15 14:41:33 +0100890 /* buffer objects */
891 struct ww_acquire_ctx ticket;
892 struct amdgpu_bo_list *bo_list;
893 struct amdgpu_bo_list_entry vm_pd;
894 struct list_head validated;
895 struct fence *fence;
896 uint64_t bytes_moved_threshold;
897 uint64_t bytes_moved;
Christian König662bfa62016-09-01 12:13:18 +0200898 struct amdgpu_bo_list_entry *evictable;
Alex Deucher97b2e202015-04-20 16:51:00 -0400899
900 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +0100901 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -0400902};
903
Monk Liu753ad492016-08-26 13:28:28 +0800904#define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */
905#define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */
906#define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */
907
Chunming Zhoubb977d32015-08-18 15:16:40 +0800908struct amdgpu_job {
909 struct amd_sched_job base;
910 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +0200911 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +0100912 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +0100913 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800914 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +0800915 struct fence *fence; /* the hw fence */
Monk Liu753ad492016-08-26 13:28:28 +0800916 uint32_t preamble_status;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800917 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +0100918 void *owner;
Monk Liu3aecd242016-08-25 15:40:48 +0800919 uint64_t fence_ctx; /* the fence_context this job uses */
Chunming Zhoufd53be32016-07-01 17:59:01 +0800920 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +0200921 unsigned vm_id;
922 uint64_t vm_pd_addr;
923 uint32_t gds_base, gds_size;
924 uint32_t gws_base, gws_size;
925 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +0200926
927 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +0200928 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +0200929 uint64_t uf_sequence;
930
Chunming Zhoubb977d32015-08-18 15:16:40 +0800931};
Junwei Zhanga6db8a32015-09-09 09:21:19 +0800932#define to_amdgpu_job(sched_job) \
933 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +0800934
Christian König7270f832016-01-31 11:00:41 +0100935static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
936 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -0400937{
Christian König50838c82016-02-03 13:44:52 +0100938 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -0400939}
940
Christian König7270f832016-01-31 11:00:41 +0100941static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
942 uint32_t ib_idx, int idx,
943 uint32_t value)
944{
Christian König50838c82016-02-03 13:44:52 +0100945 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +0100946}
947
Alex Deucher97b2e202015-04-20 16:51:00 -0400948/*
949 * Writeback
950 */
951#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
952
953struct amdgpu_wb {
954 struct amdgpu_bo *wb_obj;
955 volatile uint32_t *wb;
956 uint64_t gpu_addr;
957 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
958 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
959};
960
961int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
962void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
963
Alex Deucher97b2e202015-04-20 16:51:00 -0400964
Alex Deucher97b2e202015-04-20 16:51:00 -0400965
966enum amdgpu_int_thermal_type {
967 THERMAL_TYPE_NONE,
968 THERMAL_TYPE_EXTERNAL,
969 THERMAL_TYPE_EXTERNAL_GPIO,
970 THERMAL_TYPE_RV6XX,
971 THERMAL_TYPE_RV770,
972 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
973 THERMAL_TYPE_EVERGREEN,
974 THERMAL_TYPE_SUMO,
975 THERMAL_TYPE_NI,
976 THERMAL_TYPE_SI,
977 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
978 THERMAL_TYPE_CI,
979 THERMAL_TYPE_KV,
980};
981
982enum amdgpu_dpm_auto_throttle_src {
983 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
984 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
985};
986
987enum amdgpu_dpm_event_src {
988 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
989 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
990 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
991 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
992 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
993};
994
995#define AMDGPU_MAX_VCE_LEVELS 6
996
997enum amdgpu_vce_level {
998 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
999 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1000 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1001 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1002 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1003 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1004};
1005
1006struct amdgpu_ps {
1007 u32 caps; /* vbios flags */
1008 u32 class; /* vbios flags */
1009 u32 class2; /* vbios flags */
1010 /* UVD clocks */
1011 u32 vclk;
1012 u32 dclk;
1013 /* VCE clocks */
1014 u32 evclk;
1015 u32 ecclk;
1016 bool vce_active;
1017 enum amdgpu_vce_level vce_level;
1018 /* asic priv */
1019 void *ps_priv;
1020};
1021
1022struct amdgpu_dpm_thermal {
1023 /* thermal interrupt work */
1024 struct work_struct work;
1025 /* low temperature threshold */
1026 int min_temp;
1027 /* high temperature threshold */
1028 int max_temp;
1029 /* was last interrupt low to high or high to low */
1030 bool high_to_low;
1031 /* interrupt source */
1032 struct amdgpu_irq_src irq;
1033};
1034
1035enum amdgpu_clk_action
1036{
1037 AMDGPU_SCLK_UP = 1,
1038 AMDGPU_SCLK_DOWN
1039};
1040
1041struct amdgpu_blacklist_clocks
1042{
1043 u32 sclk;
1044 u32 mclk;
1045 enum amdgpu_clk_action action;
1046};
1047
1048struct amdgpu_clock_and_voltage_limits {
1049 u32 sclk;
1050 u32 mclk;
1051 u16 vddc;
1052 u16 vddci;
1053};
1054
1055struct amdgpu_clock_array {
1056 u32 count;
1057 u32 *values;
1058};
1059
1060struct amdgpu_clock_voltage_dependency_entry {
1061 u32 clk;
1062 u16 v;
1063};
1064
1065struct amdgpu_clock_voltage_dependency_table {
1066 u32 count;
1067 struct amdgpu_clock_voltage_dependency_entry *entries;
1068};
1069
1070union amdgpu_cac_leakage_entry {
1071 struct {
1072 u16 vddc;
1073 u32 leakage;
1074 };
1075 struct {
1076 u16 vddc1;
1077 u16 vddc2;
1078 u16 vddc3;
1079 };
1080};
1081
1082struct amdgpu_cac_leakage_table {
1083 u32 count;
1084 union amdgpu_cac_leakage_entry *entries;
1085};
1086
1087struct amdgpu_phase_shedding_limits_entry {
1088 u16 voltage;
1089 u32 sclk;
1090 u32 mclk;
1091};
1092
1093struct amdgpu_phase_shedding_limits_table {
1094 u32 count;
1095 struct amdgpu_phase_shedding_limits_entry *entries;
1096};
1097
1098struct amdgpu_uvd_clock_voltage_dependency_entry {
1099 u32 vclk;
1100 u32 dclk;
1101 u16 v;
1102};
1103
1104struct amdgpu_uvd_clock_voltage_dependency_table {
1105 u8 count;
1106 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1107};
1108
1109struct amdgpu_vce_clock_voltage_dependency_entry {
1110 u32 ecclk;
1111 u32 evclk;
1112 u16 v;
1113};
1114
1115struct amdgpu_vce_clock_voltage_dependency_table {
1116 u8 count;
1117 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1118};
1119
1120struct amdgpu_ppm_table {
1121 u8 ppm_design;
1122 u16 cpu_core_number;
1123 u32 platform_tdp;
1124 u32 small_ac_platform_tdp;
1125 u32 platform_tdc;
1126 u32 small_ac_platform_tdc;
1127 u32 apu_tdp;
1128 u32 dgpu_tdp;
1129 u32 dgpu_ulv_power;
1130 u32 tj_max;
1131};
1132
1133struct amdgpu_cac_tdp_table {
1134 u16 tdp;
1135 u16 configurable_tdp;
1136 u16 tdc;
1137 u16 battery_power_limit;
1138 u16 small_power_limit;
1139 u16 low_cac_leakage;
1140 u16 high_cac_leakage;
1141 u16 maximum_power_delivery_limit;
1142};
1143
1144struct amdgpu_dpm_dynamic_state {
1145 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1146 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1147 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1148 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1149 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1150 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1151 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1152 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1153 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1154 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1155 struct amdgpu_clock_array valid_sclk_values;
1156 struct amdgpu_clock_array valid_mclk_values;
1157 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1158 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1159 u32 mclk_sclk_ratio;
1160 u32 sclk_mclk_delta;
1161 u16 vddc_vddci_delta;
1162 u16 min_vddc_for_pcie_gen2;
1163 struct amdgpu_cac_leakage_table cac_leakage_table;
1164 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1165 struct amdgpu_ppm_table *ppm_table;
1166 struct amdgpu_cac_tdp_table *cac_tdp_table;
1167};
1168
1169struct amdgpu_dpm_fan {
1170 u16 t_min;
1171 u16 t_med;
1172 u16 t_high;
1173 u16 pwm_min;
1174 u16 pwm_med;
1175 u16 pwm_high;
1176 u8 t_hyst;
1177 u32 cycle_delay;
1178 u16 t_max;
1179 u8 control_mode;
1180 u16 default_max_fan_pwm;
1181 u16 default_fan_output_sensitivity;
1182 u16 fan_output_sensitivity;
1183 bool ucode_fan_control;
1184};
1185
1186enum amdgpu_pcie_gen {
1187 AMDGPU_PCIE_GEN1 = 0,
1188 AMDGPU_PCIE_GEN2 = 1,
1189 AMDGPU_PCIE_GEN3 = 2,
1190 AMDGPU_PCIE_GEN_INVALID = 0xffff
1191};
1192
1193enum amdgpu_dpm_forced_level {
1194 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1195 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1196 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001197 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001198};
1199
1200struct amdgpu_vce_state {
1201 /* vce clocks */
1202 u32 evclk;
1203 u32 ecclk;
1204 /* gpu clocks */
1205 u32 sclk;
1206 u32 mclk;
1207 u8 clk_idx;
1208 u8 pstate;
1209};
1210
1211struct amdgpu_dpm_funcs {
1212 int (*get_temperature)(struct amdgpu_device *adev);
1213 int (*pre_set_power_state)(struct amdgpu_device *adev);
1214 int (*set_power_state)(struct amdgpu_device *adev);
1215 void (*post_set_power_state)(struct amdgpu_device *adev);
1216 void (*display_configuration_changed)(struct amdgpu_device *adev);
1217 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1218 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1219 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1220 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1221 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1222 bool (*vblank_too_short)(struct amdgpu_device *adev);
1223 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a077692015-05-28 15:47:53 -04001224 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001225 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1226 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1227 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1228 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1229 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001230 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1231 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001232 int (*get_sclk_od)(struct amdgpu_device *adev);
1233 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001234 int (*get_mclk_od)(struct amdgpu_device *adev);
1235 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001236};
1237
1238struct amdgpu_dpm {
1239 struct amdgpu_ps *ps;
1240 /* number of valid power states */
1241 int num_ps;
1242 /* current power state that is active */
1243 struct amdgpu_ps *current_ps;
1244 /* requested power state */
1245 struct amdgpu_ps *requested_ps;
1246 /* boot up power state */
1247 struct amdgpu_ps *boot_ps;
1248 /* default uvd power state */
1249 struct amdgpu_ps *uvd_ps;
1250 /* vce requirements */
1251 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1252 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001253 enum amd_pm_state_type state;
1254 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001255 u32 platform_caps;
1256 u32 voltage_response_time;
1257 u32 backbias_response_time;
1258 void *priv;
1259 u32 new_active_crtcs;
1260 int new_active_crtc_count;
1261 u32 current_active_crtcs;
1262 int current_active_crtc_count;
1263 struct amdgpu_dpm_dynamic_state dyn_state;
1264 struct amdgpu_dpm_fan fan;
1265 u32 tdp_limit;
1266 u32 near_tdp_limit;
1267 u32 near_tdp_limit_adjusted;
1268 u32 sq_ramping_threshold;
1269 u32 cac_leakage;
1270 u16 tdp_od_limit;
1271 u32 tdp_adjustment;
1272 u16 load_line_slope;
1273 bool power_control;
1274 bool ac_power;
1275 /* special states active */
1276 bool thermal_active;
1277 bool uvd_active;
1278 bool vce_active;
1279 /* thermal handling */
1280 struct amdgpu_dpm_thermal thermal;
1281 /* forced levels */
1282 enum amdgpu_dpm_forced_level forced_level;
1283};
1284
1285struct amdgpu_pm {
1286 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001287 u32 current_sclk;
1288 u32 current_mclk;
1289 u32 default_sclk;
1290 u32 default_mclk;
1291 struct amdgpu_i2c_chan *i2c_bus;
1292 /* internal thermal controller on rv6xx+ */
1293 enum amdgpu_int_thermal_type int_thermal_type;
1294 struct device *int_hwmon_dev;
1295 /* fan control parameters */
1296 bool no_fan;
1297 u8 fan_pulses_per_revolution;
1298 u8 fan_min_rpm;
1299 u8 fan_max_rpm;
1300 /* dpm */
1301 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001302 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001303 struct amdgpu_dpm dpm;
1304 const struct firmware *fw; /* SMC firmware */
1305 uint32_t fw_version;
1306 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001307 uint32_t pcie_gen_mask;
1308 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001309 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001310};
1311
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001312void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1313
Alex Deucher97b2e202015-04-20 16:51:00 -04001314/*
1315 * UVD
1316 */
Arindam Nathc0365542016-04-12 13:46:15 +02001317#define AMDGPU_DEFAULT_UVD_HANDLES 10
1318#define AMDGPU_MAX_UVD_HANDLES 40
1319#define AMDGPU_UVD_STACK_SIZE (200*1024)
1320#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1321#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1322#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001323
1324struct amdgpu_uvd {
1325 struct amdgpu_bo *vcpu_bo;
1326 void *cpu_addr;
1327 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001328 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001329 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001330 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001331 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1332 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1333 struct delayed_work idle_work;
1334 const struct firmware *fw; /* UVD firmware */
1335 struct amdgpu_ring ring;
1336 struct amdgpu_irq_src irq;
1337 bool address_64_bit;
Christian König4cb5877c2016-07-26 12:05:40 +02001338 bool use_ctx_buf;
Christian Königead833e2016-02-10 14:35:19 +01001339 struct amd_sched_entity entity;
Chunming Zhoufc0b3b92016-07-18 17:18:01 +08001340 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001341};
1342
1343/*
1344 * VCE
1345 */
1346#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001347#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1348
Alex Deucher6a585772015-07-10 14:16:24 -04001349#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1350#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1351
Alex Deucher97b2e202015-04-20 16:51:00 -04001352struct amdgpu_vce {
1353 struct amdgpu_bo *vcpu_bo;
1354 uint64_t gpu_addr;
1355 unsigned fw_version;
1356 unsigned fb_version;
1357 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1358 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001359 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001360 struct delayed_work idle_work;
Christian Königebff4852016-07-20 16:53:36 +02001361 struct mutex idle_mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001362 const struct firmware *fw; /* VCE firmware */
1363 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1364 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001365 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001366 struct amd_sched_entity entity;
Chunming Zhou115933a2016-07-18 17:38:50 +08001367 uint32_t srbm_soft_reset;
Alex Deucher75c65482016-08-24 16:56:21 -04001368 unsigned num_rings;
Alex Deucher97b2e202015-04-20 16:51:00 -04001369};
1370
1371/*
1372 * SDMA
1373 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001374struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001375 /* SDMA firmware */
1376 const struct firmware *fw;
1377 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001378 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001379
1380 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001381 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001382};
1383
Alex Deucherc113ea12015-10-08 16:30:37 -04001384struct amdgpu_sdma {
1385 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
Ken Wang30d15742016-01-19 14:05:23 +08001386#ifdef CONFIG_DRM_AMDGPU_SI
1387 //SI DMA has a difference trap irq number for the second engine
1388 struct amdgpu_irq_src trap_irq_1;
1389#endif
Alex Deucherc113ea12015-10-08 16:30:37 -04001390 struct amdgpu_irq_src trap_irq;
1391 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001392 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001393 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001394};
1395
Alex Deucher97b2e202015-04-20 16:51:00 -04001396/*
1397 * Firmware
1398 */
1399struct amdgpu_firmware {
1400 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1401 bool smu_load;
1402 struct amdgpu_bo *fw_buf;
1403 unsigned int fw_size;
1404};
1405
1406/*
1407 * Benchmarking
1408 */
1409void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1410
1411
1412/*
1413 * Testing
1414 */
1415void amdgpu_test_moves(struct amdgpu_device *adev);
1416void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1417 struct amdgpu_ring *cpA,
1418 struct amdgpu_ring *cpB);
1419void amdgpu_test_syncing(struct amdgpu_device *adev);
1420
1421/*
1422 * MMU Notifier
1423 */
1424#if defined(CONFIG_MMU_NOTIFIER)
1425int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1426void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1427#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001428static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001429{
1430 return -ENODEV;
1431}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001432static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001433#endif
1434
1435/*
1436 * Debugfs
1437 */
1438struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001439 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001440 unsigned num_files;
1441};
1442
1443int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001444 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001445 unsigned nfiles);
1446int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1447
1448#if defined(CONFIG_DEBUG_FS)
1449int amdgpu_debugfs_init(struct drm_minor *minor);
1450void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1451#endif
1452
Huang Rui50ab2532016-06-12 15:51:09 +08001453int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1454
Alex Deucher97b2e202015-04-20 16:51:00 -04001455/*
1456 * amdgpu smumgr functions
1457 */
1458struct amdgpu_smumgr_funcs {
1459 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1460 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1461 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1462};
1463
1464/*
1465 * amdgpu smumgr
1466 */
1467struct amdgpu_smumgr {
1468 struct amdgpu_bo *toc_buf;
1469 struct amdgpu_bo *smu_buf;
1470 /* asic priv smu data */
1471 void *priv;
1472 spinlock_t smu_lock;
1473 /* smumgr functions */
1474 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1475 /* ucode loading complete flag */
1476 uint32_t fw_flags;
1477};
1478
1479/*
1480 * ASIC specific register table accessible by UMD
1481 */
1482struct amdgpu_allowed_register_entry {
1483 uint32_t reg_offset;
1484 bool untouched;
1485 bool grbm_indexed;
1486};
1487
Alex Deucher97b2e202015-04-20 16:51:00 -04001488/*
1489 * ASIC specific functions.
1490 */
1491struct amdgpu_asic_funcs {
1492 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001493 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1494 u8 *bios, u32 length_bytes);
Monk Liu4e99a442016-03-31 13:26:59 +08001495 void (*detect_hw_virtualization) (struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001496 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1497 u32 sh_num, u32 reg_offset, u32 *value);
1498 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1499 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001500 /* get the reference clock */
1501 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001502 /* MM block clocks */
1503 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1504 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Maruthi Bayyavarapu841686d2016-08-01 12:42:32 -04001505 /* static power management */
1506 int (*get_pcie_lanes)(struct amdgpu_device *adev);
1507 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001508};
1509
1510/*
1511 * IOCTL.
1512 */
1513int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1514 struct drm_file *filp);
1515int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1516 struct drm_file *filp);
1517
1518int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1519 struct drm_file *filp);
1520int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1521 struct drm_file *filp);
1522int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1523 struct drm_file *filp);
1524int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1525 struct drm_file *filp);
1526int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1527 struct drm_file *filp);
1528int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1529 struct drm_file *filp);
1530int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1531int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1532
1533int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1534 struct drm_file *filp);
1535
1536/* VRAM scratch page for HDP bug, default vram page */
1537struct amdgpu_vram_scratch {
1538 struct amdgpu_bo *robj;
1539 volatile uint32_t *ptr;
1540 u64 gpu_addr;
1541};
1542
1543/*
1544 * ACPI
1545 */
1546struct amdgpu_atif_notification_cfg {
1547 bool enabled;
1548 int command_code;
1549};
1550
1551struct amdgpu_atif_notifications {
1552 bool display_switch;
1553 bool expansion_mode_change;
1554 bool thermal_state;
1555 bool forced_power_state;
1556 bool system_power_state;
1557 bool display_conf_change;
1558 bool px_gfx_switch;
1559 bool brightness_change;
1560 bool dgpu_display_event;
1561};
1562
1563struct amdgpu_atif_functions {
1564 bool system_params;
1565 bool sbios_requests;
1566 bool select_active_disp;
1567 bool lid_state;
1568 bool get_tv_standard;
1569 bool set_tv_standard;
1570 bool get_panel_expansion_mode;
1571 bool set_panel_expansion_mode;
1572 bool temperature_change;
1573 bool graphics_device_types;
1574};
1575
1576struct amdgpu_atif {
1577 struct amdgpu_atif_notifications notifications;
1578 struct amdgpu_atif_functions functions;
1579 struct amdgpu_atif_notification_cfg notification_cfg;
1580 struct amdgpu_encoder *encoder_for_bl;
1581};
1582
1583struct amdgpu_atcs_functions {
1584 bool get_ext_state;
1585 bool pcie_perf_req;
1586 bool pcie_dev_rdy;
1587 bool pcie_bus_width;
1588};
1589
1590struct amdgpu_atcs {
1591 struct amdgpu_atcs_functions functions;
1592};
1593
Alex Deucher97b2e202015-04-20 16:51:00 -04001594/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001595 * CGS
1596 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001597struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1598void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001599
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001600/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001601 * Core structure, functions and helpers.
1602 */
1603typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1604typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1605
1606typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1607typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1608
Alex Deucher8faf0e082015-07-28 11:50:31 -04001609struct amdgpu_ip_block_status {
1610 bool valid;
1611 bool sw;
1612 bool hw;
Grazvydas Ignotas8a2eef12016-10-03 00:06:44 +03001613 bool late_initialized;
Chunming Zhou63fbf422016-07-15 11:19:20 +08001614 bool hang;
Alex Deucher8faf0e082015-07-28 11:50:31 -04001615};
1616
Alex Deucher97b2e202015-04-20 16:51:00 -04001617struct amdgpu_device {
1618 struct device *dev;
1619 struct drm_device *ddev;
1620 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001621
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001622#ifdef CONFIG_DRM_AMD_ACP
1623 struct amdgpu_acp acp;
1624#endif
1625
Alex Deucher97b2e202015-04-20 16:51:00 -04001626 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001627 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001628 uint32_t family;
1629 uint32_t rev_id;
1630 uint32_t external_rev_id;
1631 unsigned long flags;
1632 int usec_timeout;
1633 const struct amdgpu_asic_funcs *asic_funcs;
1634 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001635 bool need_dma32;
1636 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001637 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001638 struct notifier_block acpi_nb;
1639 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1640 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001641 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001642#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001643 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001644#endif
1645 struct amdgpu_atif atif;
1646 struct amdgpu_atcs atcs;
1647 struct mutex srbm_mutex;
1648 /* GRBM index mutex. Protects concurrent access to GRBM index */
1649 struct mutex grbm_idx_mutex;
1650 struct dev_pm_domain vga_pm_domain;
1651 bool have_disp_power_ref;
1652
1653 /* BIOS */
1654 uint8_t *bios;
1655 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001656 struct amdgpu_bo *stollen_vga_memory;
1657 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1658
1659 /* Register/doorbell mmio */
1660 resource_size_t rmmio_base;
1661 resource_size_t rmmio_size;
1662 void __iomem *rmmio;
1663 /* protects concurrent MM_INDEX/DATA based register access */
1664 spinlock_t mmio_idx_lock;
1665 /* protects concurrent SMC based register access */
1666 spinlock_t smc_idx_lock;
1667 amdgpu_rreg_t smc_rreg;
1668 amdgpu_wreg_t smc_wreg;
1669 /* protects concurrent PCIE register access */
1670 spinlock_t pcie_idx_lock;
1671 amdgpu_rreg_t pcie_rreg;
1672 amdgpu_wreg_t pcie_wreg;
Huang Rui36b9a952016-08-31 13:23:25 +08001673 amdgpu_rreg_t pciep_rreg;
1674 amdgpu_wreg_t pciep_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001675 /* protects concurrent UVD register access */
1676 spinlock_t uvd_ctx_idx_lock;
1677 amdgpu_rreg_t uvd_ctx_rreg;
1678 amdgpu_wreg_t uvd_ctx_wreg;
1679 /* protects concurrent DIDT register access */
1680 spinlock_t didt_idx_lock;
1681 amdgpu_rreg_t didt_rreg;
1682 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08001683 /* protects concurrent gc_cac register access */
1684 spinlock_t gc_cac_idx_lock;
1685 amdgpu_rreg_t gc_cac_rreg;
1686 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001687 /* protects concurrent ENDPOINT (audio) register access */
1688 spinlock_t audio_endpt_idx_lock;
1689 amdgpu_block_rreg_t audio_endpt_rreg;
1690 amdgpu_block_wreg_t audio_endpt_wreg;
1691 void __iomem *rio_mem;
1692 resource_size_t rio_mem_size;
1693 struct amdgpu_doorbell doorbell;
1694
1695 /* clock/pll info */
1696 struct amdgpu_clock clock;
1697
1698 /* MC */
1699 struct amdgpu_mc mc;
1700 struct amdgpu_gart gart;
1701 struct amdgpu_dummy_page dummy_page;
1702 struct amdgpu_vm_manager vm_manager;
1703
1704 /* memory management */
1705 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04001706 struct amdgpu_vram_scratch vram_scratch;
1707 struct amdgpu_wb wb;
1708 atomic64_t vram_usage;
1709 atomic64_t vram_vis_usage;
1710 atomic64_t gtt_usage;
1711 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02001712 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02001713 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04001714
Marek Olšák95844d22016-08-17 23:49:27 +02001715 /* data for buffer migration throttling */
1716 struct {
1717 spinlock_t lock;
1718 s64 last_update_us;
1719 s64 accum_us; /* accumulated microseconds */
1720 u32 log2_max_MBps;
1721 } mm_stats;
1722
Alex Deucher97b2e202015-04-20 16:51:00 -04001723 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08001724 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04001725 struct amdgpu_mode_info mode_info;
1726 struct work_struct hotplug_work;
1727 struct amdgpu_irq_src crtc_irq;
1728 struct amdgpu_irq_src pageflip_irq;
1729 struct amdgpu_irq_src hpd_irq;
1730
1731 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02001732 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04001733 unsigned num_rings;
1734 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1735 bool ib_pool_ready;
1736 struct amdgpu_sa_manager ring_tmp_bo;
1737
1738 /* interrupts */
1739 struct amdgpu_irq irq;
1740
Alex Deucher1f7371b2015-12-02 17:46:21 -05001741 /* powerplay */
1742 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05001743 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05001744 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05001745
Alex Deucher97b2e202015-04-20 16:51:00 -04001746 /* dpm */
1747 struct amdgpu_pm pm;
1748 u32 cg_flags;
1749 u32 pg_flags;
1750
1751 /* amdgpu smumgr */
1752 struct amdgpu_smumgr smu;
1753
1754 /* gfx */
1755 struct amdgpu_gfx gfx;
1756
1757 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04001758 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04001759
1760 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04001761 struct amdgpu_uvd uvd;
1762
1763 /* vce */
1764 struct amdgpu_vce vce;
1765
1766 /* firmwares */
1767 struct amdgpu_firmware firmware;
1768
1769 /* GDS */
1770 struct amdgpu_gds gds;
1771
1772 const struct amdgpu_ip_block_version *ip_blocks;
1773 int num_ip_blocks;
Alex Deucher8faf0e082015-07-28 11:50:31 -04001774 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04001775 struct mutex mn_lock;
1776 DECLARE_HASHTABLE(mn_hash, 7);
1777
1778 /* tracking pinned memory */
1779 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08001780 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001781 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03001782
1783 /* amdkfd interface */
1784 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08001785
Alex Deucher7e471e62016-02-01 11:13:04 -05001786 struct amdgpu_virtualization virtualization;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +08001787
1788 /* link all shadow bo */
1789 struct list_head shadow_list;
1790 struct mutex shadow_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08001791 /* link all gtt */
1792 spinlock_t gtt_list_lock;
1793 struct list_head gtt_list;
1794
Alex Deucher97b2e202015-04-20 16:51:00 -04001795};
1796
Christian Königa7d64de2016-09-15 14:58:48 +02001797static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1798{
1799 return container_of(bdev, struct amdgpu_device, mman.bdev);
1800}
1801
Alex Deucher97b2e202015-04-20 16:51:00 -04001802bool amdgpu_device_is_px(struct drm_device *dev);
1803int amdgpu_device_init(struct amdgpu_device *adev,
1804 struct drm_device *ddev,
1805 struct pci_dev *pdev,
1806 uint32_t flags);
1807void amdgpu_device_fini(struct amdgpu_device *adev);
1808int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1809
1810uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
1811 bool always_indirect);
1812void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
1813 bool always_indirect);
1814u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1815void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1816
1817u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1818void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1819
1820/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001821 * Registers read & write functions.
1822 */
1823#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
1824#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
1825#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
1826#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
1827#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
1828#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1829#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1830#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1831#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
Huang Rui36b9a952016-08-31 13:23:25 +08001832#define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
1833#define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001834#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
1835#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
1836#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
1837#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
1838#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
1839#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08001840#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1841#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001842#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
1843#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
1844#define WREG32_P(reg, val, mask) \
1845 do { \
1846 uint32_t tmp_ = RREG32(reg); \
1847 tmp_ &= (mask); \
1848 tmp_ |= ((val) & ~(mask)); \
1849 WREG32(reg, tmp_); \
1850 } while (0)
1851#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1852#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1853#define WREG32_PLL_P(reg, val, mask) \
1854 do { \
1855 uint32_t tmp_ = RREG32_PLL(reg); \
1856 tmp_ &= (mask); \
1857 tmp_ |= ((val) & ~(mask)); \
1858 WREG32_PLL(reg, tmp_); \
1859 } while (0)
1860#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
1861#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1862#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1863
1864#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
1865#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
1866
1867#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1868#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1869
1870#define REG_SET_FIELD(orig_val, reg, field, field_val) \
1871 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
1872 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1873
1874#define REG_GET_FIELD(value, reg, field) \
1875 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1876
Tom St Denis61cb8ce2016-08-09 10:13:21 -04001877#define WREG32_FIELD(reg, field, val) \
1878 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1879
Alex Deucher97b2e202015-04-20 16:51:00 -04001880/*
1881 * BIOS helpers.
1882 */
1883#define RBIOS8(i) (adev->bios[i])
1884#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1885#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1886
1887/*
1888 * RING helpers.
1889 */
1890static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
1891{
1892 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08001893 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04001894 ring->ring[ring->wptr++] = v;
1895 ring->wptr &= ring->ptr_mask;
1896 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04001897}
1898
Alex Deucherc113ea12015-10-08 16:30:37 -04001899static inline struct amdgpu_sdma_instance *
1900amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001901{
1902 struct amdgpu_device *adev = ring->adev;
1903 int i;
1904
Alex Deucherc113ea12015-10-08 16:30:37 -04001905 for (i = 0; i < adev->sdma.num_instances; i++)
1906 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001907 break;
1908
1909 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04001910 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001911 else
1912 return NULL;
1913}
1914
Alex Deucher97b2e202015-04-20 16:51:00 -04001915/*
1916 * ASICs macro.
1917 */
1918#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1919#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001920#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1921#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1922#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 -04001923#define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1924#define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1925#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001926#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05001927#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 +08001928#define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001929#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 -04001930#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
1931#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
1932#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 +02001933#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 -04001934#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 -04001935#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
1936#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02001937#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04001938#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
1939#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
1940#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02001941#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 +01001942#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04001943#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08001944#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04001945#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 +02001946#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08001947#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Monk Liuc2167a62016-08-26 14:12:37 +08001948#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
Monk Liu753ad492016-08-26 13:28:28 +08001949#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
Christian König9e5d53092016-01-31 12:20:55 +01001950#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08001951#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
1952#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucherb6384ff2016-09-16 10:55:50 -04001953#define amdgpu_ring_get_emit_ib_size(r) (r)->funcs->get_emit_ib_size((r))
1954#define amdgpu_ring_get_dma_frame_size(r) (r)->funcs->get_dma_frame_size((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04001955#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
1956#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
1957#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
1958#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
1959#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
1960#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
1961#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
1962#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
1963#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
1964#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
1965#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
1966#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
1967#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04001968#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 -04001969#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
1970#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
1971#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))
1972#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
1973#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08001974#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 +08001975#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 -04001976#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
1977#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
1978#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
1979#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001980#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04001981#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001982#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04001983#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04001984#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 +08001985
Tom St Denis3de4ec52016-09-19 12:48:52 -04001986#define amdgpu_dpm_read_sensor(adev, idx, value) \
1987 ((adev)->pp_enabled ? \
1988 (adev)->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, (idx), (value)) : \
1989 -EINVAL)
1990
Rex Zhu3af76f22015-10-15 17:23:43 +08001991#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05001992 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05001993 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05001994 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08001995
1996#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05001997 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05001998 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05001999 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002000
2001#define amdgpu_dpm_get_fan_control_mode(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_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002004 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002005
2006#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
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_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002009 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002010
2011#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
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_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002014 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002015
Rex Zhu1b5708f2015-11-10 18:25:24 -05002016#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002017 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002018 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002019 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002020
2021#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002022 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002023 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002024 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002025
2026
2027#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002028 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002029 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002030 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002031
2032#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002033 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002034 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002035 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002036
2037#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002038 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002039 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002040 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002041
Rex Zhu1b5708f2015-11-10 18:25:24 -05002042#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002043 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002044
2045#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002046 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002047
Eric Huangf3898ea2015-12-11 16:24:34 -05002048#define amdgpu_dpm_get_pp_num_states(adev, data) \
2049 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2050
2051#define amdgpu_dpm_get_pp_table(adev, table) \
2052 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2053
2054#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2055 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2056
2057#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2058 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2059
2060#define amdgpu_dpm_force_clock_level(adev, type, level) \
2061 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2062
Eric Huang428bafa2016-05-12 14:51:21 -04002063#define amdgpu_dpm_get_sclk_od(adev) \
2064 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2065
2066#define amdgpu_dpm_set_sclk_od(adev, value) \
2067 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2068
Eric Huangf2bdc052016-05-24 15:11:17 -04002069#define amdgpu_dpm_get_mclk_od(adev) \
2070 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2071
2072#define amdgpu_dpm_set_mclk_od(adev, value) \
2073 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2074
Jammy Zhoue61710c2015-11-10 18:31:08 -05002075#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002076 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002077
2078#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2079
2080/* Common functions */
2081int amdgpu_gpu_reset(struct amdgpu_device *adev);
Chunming Zhou3ad81f12016-08-05 17:30:17 +08002082bool amdgpu_need_backup(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002083void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2084bool amdgpu_card_posted(struct amdgpu_device *adev);
2085void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002086
Alex Deucher97b2e202015-04-20 16:51:00 -04002087int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2088int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2089 u32 ip_instance, u32 ring,
2090 struct amdgpu_ring **out_ring);
Christian König765e7fb2016-09-15 15:06:50 +02002091void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
Alex Deucher97b2e202015-04-20 16:51:00 -04002092bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002093int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002094int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2095 uint32_t flags);
2096bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002097struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002098bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2099 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002100bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2101 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002102bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2103uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2104 struct ttm_mem_reg *mem);
2105void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2106void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2107void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Ken Wanga693e052016-07-27 19:18:01 +08002108u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2109int amdgpu_ttm_global_init(struct amdgpu_device *adev);
Baoyou Xie9f31a0b02016-09-15 21:43:26 +08002110int amdgpu_ttm_init(struct amdgpu_device *adev);
2111void amdgpu_ttm_fini(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002112void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2113 const u32 *registers,
2114 const u32 array_size);
2115
2116bool amdgpu_device_is_px(struct drm_device *dev);
2117/* atpx handler */
2118#if defined(CONFIG_VGA_SWITCHEROO)
2119void amdgpu_register_atpx_handler(void);
2120void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002121bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002122bool amdgpu_is_atpx_hybrid(void);
Alex Deucherefc83cf2016-09-14 14:01:41 -04002123bool amdgpu_atpx_dgpu_req_power_for_displays(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002124#else
2125static inline void amdgpu_register_atpx_handler(void) {}
2126static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002127static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002128static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucherefc83cf2016-09-14 14:01:41 -04002129static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002130#endif
2131
2132/*
2133 * KMS
2134 */
2135extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002136extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002137
2138int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2139int amdgpu_driver_unload_kms(struct drm_device *dev);
2140void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2141int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2142void amdgpu_driver_postclose_kms(struct drm_device *dev,
2143 struct drm_file *file_priv);
2144void amdgpu_driver_preclose_kms(struct drm_device *dev,
2145 struct drm_file *file_priv);
Alex Deucher810ddc32016-08-23 13:25:49 -04002146int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
2147int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002148u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2149int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2150void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2151int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002152 int *max_error,
2153 struct timeval *vblank_time,
2154 unsigned flags);
2155long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2156 unsigned long arg);
2157
2158/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002159 * functions used by amdgpu_encoder.c
2160 */
2161struct amdgpu_afmt_acr {
2162 u32 clock;
2163
2164 int n_32khz;
2165 int cts_32khz;
2166
2167 int n_44_1khz;
2168 int cts_44_1khz;
2169
2170 int n_48khz;
2171 int cts_48khz;
2172
2173};
2174
2175struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2176
2177/* amdgpu_acpi.c */
2178#if defined(CONFIG_ACPI)
2179int amdgpu_acpi_init(struct amdgpu_device *adev);
2180void amdgpu_acpi_fini(struct amdgpu_device *adev);
2181bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2182int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2183 u8 perf_req, bool advertise);
2184int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2185#else
2186static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2187static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2188#endif
2189
2190struct amdgpu_bo_va_mapping *
2191amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2192 uint64_t addr, struct amdgpu_bo **bo);
Christian Königc855e252016-09-05 17:00:57 +02002193int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
Alex Deucher97b2e202015-04-20 16:51:00 -04002194
2195#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002196#endif