blob: 3ba97ea5e62cfa523bdaa207affeb02e35fbae7e [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"
Alex Deucher1f7371b2015-12-02 17:46:21 -050058#include "amd_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040059#include "amdgpu_acp.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040060
Alex Deucherb80d8472015-08-16 22:55:02 -040061#include "gpu_scheduler.h"
Monk Liuceeb50e2016-09-19 12:13:58 +080062#include "amdgpu_virt.h"
Alex Deucherb80d8472015-08-16 22:55:02 -040063
Alex Deucher97b2e202015-04-20 16:51:00 -040064/*
65 * Modules parameters.
66 */
67extern int amdgpu_modeset;
68extern int amdgpu_vram_limit;
69extern int amdgpu_gart_size;
Marek Olšák95844d22016-08-17 23:49:27 +020070extern int amdgpu_moverate;
Alex Deucher97b2e202015-04-20 16:51:00 -040071extern int amdgpu_benchmarking;
72extern int amdgpu_testing;
73extern int amdgpu_audio;
74extern int amdgpu_disp_priority;
75extern int amdgpu_hw_i2c;
76extern int amdgpu_pcie_gen2;
77extern int amdgpu_msi;
78extern int amdgpu_lockup_timeout;
79extern int amdgpu_dpm;
80extern int amdgpu_smc_load_fw;
81extern int amdgpu_aspm;
82extern int amdgpu_runtime_pm;
Alex Deucher97b2e202015-04-20 16:51:00 -040083extern unsigned amdgpu_ip_block_mask;
84extern int amdgpu_bapm;
85extern int amdgpu_deep_color;
86extern int amdgpu_vm_size;
87extern int amdgpu_vm_block_size;
Christian Königd9c13152015-09-28 12:31:26 +020088extern int amdgpu_vm_fault_stop;
Christian Königb495bd32015-09-10 14:00:35 +020089extern int amdgpu_vm_debug;
Jammy Zhou1333f722015-07-30 16:36:58 +080090extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080091extern int amdgpu_sched_hw_submission;
Alex Deucher1f7371b2015-12-02 17:46:21 -050092extern int amdgpu_powerplay;
Huang Rui6bb6b292016-05-24 13:47:05 +080093extern int amdgpu_powercontainment;
Alex Deuchercd474ba2016-02-04 10:21:23 -050094extern unsigned amdgpu_pcie_gen_cap;
95extern unsigned amdgpu_pcie_lane_cap;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +020096extern unsigned amdgpu_cg_mask;
97extern unsigned amdgpu_pg_mask;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +020098extern char *amdgpu_disable_cu;
Rex Zhu66bc3f72016-07-28 17:36:35 +080099extern int amdgpu_sclk_deep_sleep_en;
Emily Deng9accf2f2016-08-10 16:01:25 +0800100extern char *amdgpu_virtual_display;
Rex Zhu5141e9d2016-09-06 16:34:37 +0800101extern unsigned amdgpu_pp_feature_mask;
Christian König6a7f76e2016-08-24 15:51:49 +0200102extern int amdgpu_vram_page_split;
Alex Deucher97b2e202015-04-20 16:51:00 -0400103
Chunming Zhou4b559c92015-07-21 15:53:04 +0800104#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -0400105#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
106#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
107/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
108#define AMDGPU_IB_POOL_SIZE 16
109#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
110#define AMDGPUFB_CONN_LIMIT 4
111#define AMDGPU_BIOS_NUM_SCRATCH 8
112
Jammy Zhou36f523a2015-09-01 12:54:27 +0800113/* max number of IP instances */
114#define AMDGPU_MAX_SDMA_INSTANCES 2
115
Alex Deucher97b2e202015-04-20 16:51:00 -0400116/* hardcode that limit for now */
117#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
118
119/* hard reset data */
120#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
121
122/* reset flags */
123#define AMDGPU_RESET_GFX (1 << 0)
124#define AMDGPU_RESET_COMPUTE (1 << 1)
125#define AMDGPU_RESET_DMA (1 << 2)
126#define AMDGPU_RESET_CP (1 << 3)
127#define AMDGPU_RESET_GRBM (1 << 4)
128#define AMDGPU_RESET_DMA1 (1 << 5)
129#define AMDGPU_RESET_RLC (1 << 6)
130#define AMDGPU_RESET_SEM (1 << 7)
131#define AMDGPU_RESET_IH (1 << 8)
132#define AMDGPU_RESET_VMC (1 << 9)
133#define AMDGPU_RESET_MC (1 << 10)
134#define AMDGPU_RESET_DISPLAY (1 << 11)
135#define AMDGPU_RESET_UVD (1 << 12)
136#define AMDGPU_RESET_VCE (1 << 13)
137#define AMDGPU_RESET_VCE1 (1 << 14)
138
Alex Deucher97b2e202015-04-20 16:51:00 -0400139/* GFX current status */
140#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
141#define AMDGPU_GFX_SAFE_MODE 0x00000001L
142#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
143#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
144#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
145
146/* max cursor sizes (in pixels) */
147#define CIK_CURSOR_WIDTH 128
148#define CIK_CURSOR_HEIGHT 128
149
150struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400151struct amdgpu_ib;
152struct amdgpu_vm;
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änzer325cbba12016-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änzer325cbba12016-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/*
632 * VM
633 */
634
635/* maximum number of VMIDs */
636#define AMDGPU_NUM_VM 16
637
Christian König96105e52016-08-12 12:59:59 +0200638/* Maximum number of PTEs the hardware can write with one command */
639#define AMDGPU_VM_MAX_UPDATE_SIZE 0x3FFFF
640
Alex Deucher97b2e202015-04-20 16:51:00 -0400641/* number of entries in page table */
642#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
643
644/* PTBs (Page Table Blocks) need to be aligned to 32K */
645#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
Alex Deucher97b2e202015-04-20 16:51:00 -0400646
Christian König1303c732016-08-03 17:46:42 +0200647/* LOG2 number of continuous pages for the fragment field */
648#define AMDGPU_LOG2_PAGES_PER_FRAG 4
649
Alex Deucher97b2e202015-04-20 16:51:00 -0400650#define AMDGPU_PTE_VALID (1 << 0)
651#define AMDGPU_PTE_SYSTEM (1 << 1)
652#define AMDGPU_PTE_SNOOPED (1 << 2)
653
654/* VI only */
655#define AMDGPU_PTE_EXECUTABLE (1 << 4)
656
657#define AMDGPU_PTE_READABLE (1 << 5)
658#define AMDGPU_PTE_WRITEABLE (1 << 6)
659
Christian König1303c732016-08-03 17:46:42 +0200660#define AMDGPU_PTE_FRAG(x) ((x & 0x1f) << 7)
Alex Deucher97b2e202015-04-20 16:51:00 -0400661
Christian Königd9c13152015-09-28 12:31:26 +0200662/* How to programm VM fault handling */
663#define AMDGPU_VM_FAULT_STOP_NEVER 0
664#define AMDGPU_VM_FAULT_STOP_FIRST 1
665#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
666
Alex Deucher97b2e202015-04-20 16:51:00 -0400667struct amdgpu_vm_pt {
Christian König914b4dc2016-09-28 12:27:37 +0200668 struct amdgpu_bo *bo;
669 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400670};
671
Alex Deucher97b2e202015-04-20 16:51:00 -0400672struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100673 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400674 struct rb_root va;
675
Christian König7fc11952015-07-30 11:53:42 +0200676 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400677 spinlock_t status_lock;
678
679 /* BOs moved, but not yet updated in the PT */
680 struct list_head invalidated;
681
Christian König7fc11952015-07-30 11:53:42 +0200682 /* BOs cleared in the PT because of a move */
683 struct list_head cleared;
684
685 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400686 struct list_head freed;
687
688 /* contains the page directory */
689 struct amdgpu_bo *page_directory;
690 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200691 struct fence *page_directory_fence;
Christian König5a712a82016-06-21 16:28:15 +0200692 uint64_t last_eviction_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400693
694 /* array of page tables, one for each page directory entry */
695 struct amdgpu_vm_pt *page_tables;
696
697 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100698 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100699
jimqu81d75a32015-12-04 17:17:00 +0800700 /* protecting freed */
701 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100702
703 /* Scheduler entity for page table updates */
704 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800705
706 /* client id */
707 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400708};
709
Christian Königbcb1ba32016-03-08 15:40:11 +0100710struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100711 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100712 struct fence *first;
713 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100714 struct fence *last_flush;
Christian König0ea54b92016-05-04 10:20:01 +0200715 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100716
Christian Königbcb1ba32016-03-08 15:40:11 +0100717 uint64_t pd_gpu_addr;
718 /* last flushed PD/PT update */
719 struct fence *flushed_updates;
720
Chunming Zhou6adb0512016-06-27 17:06:01 +0800721 uint32_t current_gpu_reset_count;
722
Christian König971fe9a92016-03-01 15:09:25 +0100723 uint32_t gds_base;
724 uint32_t gds_size;
725 uint32_t gws_base;
726 uint32_t gws_size;
727 uint32_t oa_base;
728 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100729};
Christian König8d0a7ce2015-11-03 20:58:50 +0100730
Christian Königa9a78b32016-01-21 10:19:11 +0100731struct amdgpu_vm_manager {
732 /* Handling of VMIDs */
733 struct mutex lock;
734 unsigned num_ids;
735 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100736 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100737
Christian König1fbb2e92016-06-01 10:47:36 +0200738 /* Handling of VM fences */
739 u64 fence_context;
740 unsigned seqno[AMDGPU_MAX_RINGS];
741
Christian König8b4fb002015-11-15 16:04:16 +0100742 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400743 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100744 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400745 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100746 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400747 /* vm pte handling */
748 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100749 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
750 unsigned vm_pte_num_rings;
751 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800752 /* client id counter */
753 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400754};
755
Christian Königa9a78b32016-01-21 10:19:11 +0100756void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100757void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100758int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
759void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100760void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
761 struct list_head *validated,
762 struct amdgpu_bo_list_entry *entry);
Christian Königf7da30d2016-09-28 12:03:04 +0200763int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
764 int (*callback)(void *p, struct amdgpu_bo *bo),
765 void *param);
Christian Königeceb8a12016-01-11 15:35:21 +0100766void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
767 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100768int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100769 struct amdgpu_sync *sync, struct fence *fence,
Chunming Zhoufd53be32016-07-01 17:59:01 +0800770 struct amdgpu_job *job);
771int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
Christian König971fe9a92016-03-01 15:09:25 +0100772void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian König8b4fb002015-11-15 16:04:16 +0100773int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
774 struct amdgpu_vm *vm);
775int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
776 struct amdgpu_vm *vm);
777int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
778 struct amdgpu_sync *sync);
779int amdgpu_vm_bo_update(struct amdgpu_device *adev,
780 struct amdgpu_bo_va *bo_va,
Christian König99e124f2016-08-16 14:43:17 +0200781 bool clear);
Christian König8b4fb002015-11-15 16:04:16 +0100782void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
783 struct amdgpu_bo *bo);
784struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
785 struct amdgpu_bo *bo);
786struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
787 struct amdgpu_vm *vm,
788 struct amdgpu_bo *bo);
789int amdgpu_vm_bo_map(struct amdgpu_device *adev,
790 struct amdgpu_bo_va *bo_va,
791 uint64_t addr, uint64_t offset,
792 uint64_t size, uint32_t flags);
793int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
794 struct amdgpu_bo_va *bo_va,
795 uint64_t addr);
796void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
797 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100798
Alex Deucher97b2e202015-04-20 16:51:00 -0400799/*
800 * context related structures
801 */
802
Christian König21c16bf2015-07-07 17:24:49 +0200803struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200804 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800805 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200806 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200807};
808
Alex Deucher97b2e202015-04-20 16:51:00 -0400809struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400810 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800811 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400812 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200813 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800814 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200815 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Monk Liu753ad492016-08-26 13:28:28 +0800816 bool preamble_presented;
Alex Deucher97b2e202015-04-20 16:51:00 -0400817};
818
819struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400820 struct amdgpu_device *adev;
821 struct mutex lock;
822 /* protected by lock */
823 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400824};
825
Alex Deucher0b492a42015-08-16 22:48:26 -0400826struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
827int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
828
Christian König21c16bf2015-07-07 17:24:49 +0200829uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200830 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200831struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
832 struct amdgpu_ring *ring, uint64_t seq);
833
Alex Deucher0b492a42015-08-16 22:48:26 -0400834int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
835 struct drm_file *filp);
836
Christian Königefd4ccb2015-08-04 16:20:31 +0200837void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
838void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400839
Alex Deucher97b2e202015-04-20 16:51:00 -0400840/*
841 * file private structure
842 */
843
844struct amdgpu_fpriv {
845 struct amdgpu_vm vm;
846 struct mutex bo_list_lock;
847 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -0400848 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400849};
850
851/*
852 * residency list
853 */
854
855struct amdgpu_bo_list {
856 struct mutex lock;
857 struct amdgpu_bo *gds_obj;
858 struct amdgpu_bo *gws_obj;
859 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +0100860 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400861 unsigned num_entries;
862 struct amdgpu_bo_list_entry *array;
863};
864
865struct amdgpu_bo_list *
866amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +0100867void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
868 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -0400869void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
870void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
871
872/*
873 * GFX stuff
874 */
875#include "clearstate_defs.h"
876
Alex Deucher79e54122016-04-08 15:45:13 -0400877struct amdgpu_rlc_funcs {
878 void (*enter_safe_mode)(struct amdgpu_device *adev);
879 void (*exit_safe_mode)(struct amdgpu_device *adev);
880};
881
Alex Deucher97b2e202015-04-20 16:51:00 -0400882struct amdgpu_rlc {
883 /* for power gating */
884 struct amdgpu_bo *save_restore_obj;
885 uint64_t save_restore_gpu_addr;
886 volatile uint32_t *sr_ptr;
887 const u32 *reg_list;
888 u32 reg_list_size;
889 /* for clear state */
890 struct amdgpu_bo *clear_state_obj;
891 uint64_t clear_state_gpu_addr;
892 volatile uint32_t *cs_ptr;
893 const struct cs_section_def *cs_data;
894 u32 clear_state_size;
895 /* for cp tables */
896 struct amdgpu_bo *cp_table_obj;
897 uint64_t cp_table_gpu_addr;
898 volatile uint32_t *cp_table_ptr;
899 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -0400900
901 /* safe mode for updating CG/PG state */
902 bool in_safe_mode;
903 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -0400904
905 /* for firmware data */
906 u32 save_and_restore_offset;
907 u32 clear_state_descriptor_offset;
908 u32 avail_scratch_ram_locations;
909 u32 reg_restore_list_size;
910 u32 reg_list_format_start;
911 u32 reg_list_format_separate_start;
912 u32 starting_offsets_start;
913 u32 reg_list_format_size_bytes;
914 u32 reg_list_size_bytes;
915
916 u32 *register_list_format;
917 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -0400918};
919
920struct amdgpu_mec {
921 struct amdgpu_bo *hpd_eop_obj;
922 u64 hpd_eop_gpu_addr;
923 u32 num_pipe;
924 u32 num_mec;
925 u32 num_queue;
926};
927
928/*
929 * GPU scratch registers structures, functions & helpers
930 */
931struct amdgpu_scratch {
932 unsigned num_reg;
933 uint32_t reg_base;
934 bool free[32];
935 uint32_t reg[32];
936};
937
938/*
939 * GFX configurations
940 */
941struct amdgpu_gca_config {
942 unsigned max_shader_engines;
943 unsigned max_tile_pipes;
944 unsigned max_cu_per_sh;
945 unsigned max_sh_per_se;
946 unsigned max_backends_per_se;
947 unsigned max_texture_channel_caches;
948 unsigned max_gprs;
949 unsigned max_gs_threads;
950 unsigned max_hw_contexts;
951 unsigned sc_prim_fifo_size_frontend;
952 unsigned sc_prim_fifo_size_backend;
953 unsigned sc_hiz_tile_fifo_size;
954 unsigned sc_earlyz_tile_fifo_size;
955
956 unsigned num_tile_pipes;
957 unsigned backend_enable_mask;
958 unsigned mem_max_burst_length_bytes;
959 unsigned mem_row_size_in_kb;
960 unsigned shader_engine_tile_size;
961 unsigned num_gpus;
962 unsigned multi_gpu_tile_size;
963 unsigned mc_arb_ramcfg;
964 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -0500965 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400966
967 uint32_t tile_mode_array[32];
968 uint32_t macrotile_mode_array[16];
969};
970
Alex Deucher7dae69a2016-05-03 16:25:53 -0400971struct amdgpu_cu_info {
972 uint32_t number; /* total active CU number */
973 uint32_t ao_cu_mask;
974 uint32_t bitmap[4][4];
975};
976
Alex Deucherb95e31f2016-07-07 15:01:42 -0400977struct amdgpu_gfx_funcs {
978 /* get the gpu clock counter */
979 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -0400980 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Alex Deucherb95e31f2016-07-07 15:01:42 -0400981};
982
Alex Deucher97b2e202015-04-20 16:51:00 -0400983struct amdgpu_gfx {
984 struct mutex gpu_clock_mutex;
985 struct amdgpu_gca_config config;
986 struct amdgpu_rlc rlc;
987 struct amdgpu_mec mec;
988 struct amdgpu_scratch scratch;
989 const struct firmware *me_fw; /* ME firmware */
990 uint32_t me_fw_version;
991 const struct firmware *pfp_fw; /* PFP firmware */
992 uint32_t pfp_fw_version;
993 const struct firmware *ce_fw; /* CE firmware */
994 uint32_t ce_fw_version;
995 const struct firmware *rlc_fw; /* RLC firmware */
996 uint32_t rlc_fw_version;
997 const struct firmware *mec_fw; /* MEC firmware */
998 uint32_t mec_fw_version;
999 const struct firmware *mec2_fw; /* MEC2 firmware */
1000 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001001 uint32_t me_feature_version;
1002 uint32_t ce_feature_version;
1003 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001004 uint32_t rlc_feature_version;
1005 uint32_t mec_feature_version;
1006 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001007 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1008 unsigned num_gfx_rings;
1009 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1010 unsigned num_compute_rings;
1011 struct amdgpu_irq_src eop_irq;
1012 struct amdgpu_irq_src priv_reg_irq;
1013 struct amdgpu_irq_src priv_inst_irq;
1014 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001015 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001016 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001017 unsigned ce_ram_size;
1018 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001019 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +08001020
1021 /* reset mask */
1022 uint32_t grbm_soft_reset;
1023 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001024};
1025
Christian Königb07c60c2016-01-31 12:29:04 +01001026int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001027 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001028void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1029 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001030int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001031 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001032 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001033int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1034void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1035int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001036
1037/*
1038 * CS.
1039 */
1040struct amdgpu_cs_chunk {
1041 uint32_t chunk_id;
1042 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001043 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001044};
1045
1046struct amdgpu_cs_parser {
1047 struct amdgpu_device *adev;
1048 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001049 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001050
Alex Deucher97b2e202015-04-20 16:51:00 -04001051 /* chunks */
1052 unsigned nchunks;
1053 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001054
Christian König50838c82016-02-03 13:44:52 +01001055 /* scheduler job object */
1056 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001057
Christian Königc3cca412015-12-15 14:41:33 +01001058 /* buffer objects */
1059 struct ww_acquire_ctx ticket;
1060 struct amdgpu_bo_list *bo_list;
1061 struct amdgpu_bo_list_entry vm_pd;
1062 struct list_head validated;
1063 struct fence *fence;
1064 uint64_t bytes_moved_threshold;
1065 uint64_t bytes_moved;
Christian König662bfa62016-09-01 12:13:18 +02001066 struct amdgpu_bo_list_entry *evictable;
Alex Deucher97b2e202015-04-20 16:51:00 -04001067
1068 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001069 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001070};
1071
Monk Liu753ad492016-08-26 13:28:28 +08001072#define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */
1073#define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1074#define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */
1075
Chunming Zhoubb977d32015-08-18 15:16:40 +08001076struct amdgpu_job {
1077 struct amd_sched_job base;
1078 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001079 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001080 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001081 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001082 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001083 struct fence *fence; /* the hw fence */
Monk Liu753ad492016-08-26 13:28:28 +08001084 uint32_t preamble_status;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001085 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001086 void *owner;
Monk Liu3aecd242016-08-25 15:40:48 +08001087 uint64_t fence_ctx; /* the fence_context this job uses */
Chunming Zhoufd53be32016-07-01 17:59:01 +08001088 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +02001089 unsigned vm_id;
1090 uint64_t vm_pd_addr;
1091 uint32_t gds_base, gds_size;
1092 uint32_t gws_base, gws_size;
1093 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001094
1095 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +02001096 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +02001097 uint64_t uf_sequence;
1098
Chunming Zhoubb977d32015-08-18 15:16:40 +08001099};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001100#define to_amdgpu_job(sched_job) \
1101 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001102
Christian König7270f832016-01-31 11:00:41 +01001103static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1104 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001105{
Christian König50838c82016-02-03 13:44:52 +01001106 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001107}
1108
Christian König7270f832016-01-31 11:00:41 +01001109static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1110 uint32_t ib_idx, int idx,
1111 uint32_t value)
1112{
Christian König50838c82016-02-03 13:44:52 +01001113 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001114}
1115
Alex Deucher97b2e202015-04-20 16:51:00 -04001116/*
1117 * Writeback
1118 */
1119#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1120
1121struct amdgpu_wb {
1122 struct amdgpu_bo *wb_obj;
1123 volatile uint32_t *wb;
1124 uint64_t gpu_addr;
1125 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1126 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1127};
1128
1129int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1130void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1131
Alex Deucher97b2e202015-04-20 16:51:00 -04001132
Alex Deucher97b2e202015-04-20 16:51:00 -04001133
1134enum amdgpu_int_thermal_type {
1135 THERMAL_TYPE_NONE,
1136 THERMAL_TYPE_EXTERNAL,
1137 THERMAL_TYPE_EXTERNAL_GPIO,
1138 THERMAL_TYPE_RV6XX,
1139 THERMAL_TYPE_RV770,
1140 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1141 THERMAL_TYPE_EVERGREEN,
1142 THERMAL_TYPE_SUMO,
1143 THERMAL_TYPE_NI,
1144 THERMAL_TYPE_SI,
1145 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1146 THERMAL_TYPE_CI,
1147 THERMAL_TYPE_KV,
1148};
1149
1150enum amdgpu_dpm_auto_throttle_src {
1151 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1152 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1153};
1154
1155enum amdgpu_dpm_event_src {
1156 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1157 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1158 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1159 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1160 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1161};
1162
1163#define AMDGPU_MAX_VCE_LEVELS 6
1164
1165enum amdgpu_vce_level {
1166 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1167 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1168 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1169 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1170 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1171 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1172};
1173
1174struct amdgpu_ps {
1175 u32 caps; /* vbios flags */
1176 u32 class; /* vbios flags */
1177 u32 class2; /* vbios flags */
1178 /* UVD clocks */
1179 u32 vclk;
1180 u32 dclk;
1181 /* VCE clocks */
1182 u32 evclk;
1183 u32 ecclk;
1184 bool vce_active;
1185 enum amdgpu_vce_level vce_level;
1186 /* asic priv */
1187 void *ps_priv;
1188};
1189
1190struct amdgpu_dpm_thermal {
1191 /* thermal interrupt work */
1192 struct work_struct work;
1193 /* low temperature threshold */
1194 int min_temp;
1195 /* high temperature threshold */
1196 int max_temp;
1197 /* was last interrupt low to high or high to low */
1198 bool high_to_low;
1199 /* interrupt source */
1200 struct amdgpu_irq_src irq;
1201};
1202
1203enum amdgpu_clk_action
1204{
1205 AMDGPU_SCLK_UP = 1,
1206 AMDGPU_SCLK_DOWN
1207};
1208
1209struct amdgpu_blacklist_clocks
1210{
1211 u32 sclk;
1212 u32 mclk;
1213 enum amdgpu_clk_action action;
1214};
1215
1216struct amdgpu_clock_and_voltage_limits {
1217 u32 sclk;
1218 u32 mclk;
1219 u16 vddc;
1220 u16 vddci;
1221};
1222
1223struct amdgpu_clock_array {
1224 u32 count;
1225 u32 *values;
1226};
1227
1228struct amdgpu_clock_voltage_dependency_entry {
1229 u32 clk;
1230 u16 v;
1231};
1232
1233struct amdgpu_clock_voltage_dependency_table {
1234 u32 count;
1235 struct amdgpu_clock_voltage_dependency_entry *entries;
1236};
1237
1238union amdgpu_cac_leakage_entry {
1239 struct {
1240 u16 vddc;
1241 u32 leakage;
1242 };
1243 struct {
1244 u16 vddc1;
1245 u16 vddc2;
1246 u16 vddc3;
1247 };
1248};
1249
1250struct amdgpu_cac_leakage_table {
1251 u32 count;
1252 union amdgpu_cac_leakage_entry *entries;
1253};
1254
1255struct amdgpu_phase_shedding_limits_entry {
1256 u16 voltage;
1257 u32 sclk;
1258 u32 mclk;
1259};
1260
1261struct amdgpu_phase_shedding_limits_table {
1262 u32 count;
1263 struct amdgpu_phase_shedding_limits_entry *entries;
1264};
1265
1266struct amdgpu_uvd_clock_voltage_dependency_entry {
1267 u32 vclk;
1268 u32 dclk;
1269 u16 v;
1270};
1271
1272struct amdgpu_uvd_clock_voltage_dependency_table {
1273 u8 count;
1274 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1275};
1276
1277struct amdgpu_vce_clock_voltage_dependency_entry {
1278 u32 ecclk;
1279 u32 evclk;
1280 u16 v;
1281};
1282
1283struct amdgpu_vce_clock_voltage_dependency_table {
1284 u8 count;
1285 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1286};
1287
1288struct amdgpu_ppm_table {
1289 u8 ppm_design;
1290 u16 cpu_core_number;
1291 u32 platform_tdp;
1292 u32 small_ac_platform_tdp;
1293 u32 platform_tdc;
1294 u32 small_ac_platform_tdc;
1295 u32 apu_tdp;
1296 u32 dgpu_tdp;
1297 u32 dgpu_ulv_power;
1298 u32 tj_max;
1299};
1300
1301struct amdgpu_cac_tdp_table {
1302 u16 tdp;
1303 u16 configurable_tdp;
1304 u16 tdc;
1305 u16 battery_power_limit;
1306 u16 small_power_limit;
1307 u16 low_cac_leakage;
1308 u16 high_cac_leakage;
1309 u16 maximum_power_delivery_limit;
1310};
1311
1312struct amdgpu_dpm_dynamic_state {
1313 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1314 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1315 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1316 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1317 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1318 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1319 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1320 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1321 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1322 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1323 struct amdgpu_clock_array valid_sclk_values;
1324 struct amdgpu_clock_array valid_mclk_values;
1325 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1326 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1327 u32 mclk_sclk_ratio;
1328 u32 sclk_mclk_delta;
1329 u16 vddc_vddci_delta;
1330 u16 min_vddc_for_pcie_gen2;
1331 struct amdgpu_cac_leakage_table cac_leakage_table;
1332 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1333 struct amdgpu_ppm_table *ppm_table;
1334 struct amdgpu_cac_tdp_table *cac_tdp_table;
1335};
1336
1337struct amdgpu_dpm_fan {
1338 u16 t_min;
1339 u16 t_med;
1340 u16 t_high;
1341 u16 pwm_min;
1342 u16 pwm_med;
1343 u16 pwm_high;
1344 u8 t_hyst;
1345 u32 cycle_delay;
1346 u16 t_max;
1347 u8 control_mode;
1348 u16 default_max_fan_pwm;
1349 u16 default_fan_output_sensitivity;
1350 u16 fan_output_sensitivity;
1351 bool ucode_fan_control;
1352};
1353
1354enum amdgpu_pcie_gen {
1355 AMDGPU_PCIE_GEN1 = 0,
1356 AMDGPU_PCIE_GEN2 = 1,
1357 AMDGPU_PCIE_GEN3 = 2,
1358 AMDGPU_PCIE_GEN_INVALID = 0xffff
1359};
1360
1361enum amdgpu_dpm_forced_level {
1362 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1363 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1364 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001365 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001366};
1367
1368struct amdgpu_vce_state {
1369 /* vce clocks */
1370 u32 evclk;
1371 u32 ecclk;
1372 /* gpu clocks */
1373 u32 sclk;
1374 u32 mclk;
1375 u8 clk_idx;
1376 u8 pstate;
1377};
1378
1379struct amdgpu_dpm_funcs {
1380 int (*get_temperature)(struct amdgpu_device *adev);
1381 int (*pre_set_power_state)(struct amdgpu_device *adev);
1382 int (*set_power_state)(struct amdgpu_device *adev);
1383 void (*post_set_power_state)(struct amdgpu_device *adev);
1384 void (*display_configuration_changed)(struct amdgpu_device *adev);
1385 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1386 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1387 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1388 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1389 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1390 bool (*vblank_too_short)(struct amdgpu_device *adev);
1391 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a077692015-05-28 15:47:53 -04001392 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001393 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1394 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1395 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1396 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1397 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001398 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1399 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001400 int (*get_sclk_od)(struct amdgpu_device *adev);
1401 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001402 int (*get_mclk_od)(struct amdgpu_device *adev);
1403 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001404};
1405
1406struct amdgpu_dpm {
1407 struct amdgpu_ps *ps;
1408 /* number of valid power states */
1409 int num_ps;
1410 /* current power state that is active */
1411 struct amdgpu_ps *current_ps;
1412 /* requested power state */
1413 struct amdgpu_ps *requested_ps;
1414 /* boot up power state */
1415 struct amdgpu_ps *boot_ps;
1416 /* default uvd power state */
1417 struct amdgpu_ps *uvd_ps;
1418 /* vce requirements */
1419 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1420 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001421 enum amd_pm_state_type state;
1422 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001423 u32 platform_caps;
1424 u32 voltage_response_time;
1425 u32 backbias_response_time;
1426 void *priv;
1427 u32 new_active_crtcs;
1428 int new_active_crtc_count;
1429 u32 current_active_crtcs;
1430 int current_active_crtc_count;
1431 struct amdgpu_dpm_dynamic_state dyn_state;
1432 struct amdgpu_dpm_fan fan;
1433 u32 tdp_limit;
1434 u32 near_tdp_limit;
1435 u32 near_tdp_limit_adjusted;
1436 u32 sq_ramping_threshold;
1437 u32 cac_leakage;
1438 u16 tdp_od_limit;
1439 u32 tdp_adjustment;
1440 u16 load_line_slope;
1441 bool power_control;
1442 bool ac_power;
1443 /* special states active */
1444 bool thermal_active;
1445 bool uvd_active;
1446 bool vce_active;
1447 /* thermal handling */
1448 struct amdgpu_dpm_thermal thermal;
1449 /* forced levels */
1450 enum amdgpu_dpm_forced_level forced_level;
1451};
1452
1453struct amdgpu_pm {
1454 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001455 u32 current_sclk;
1456 u32 current_mclk;
1457 u32 default_sclk;
1458 u32 default_mclk;
1459 struct amdgpu_i2c_chan *i2c_bus;
1460 /* internal thermal controller on rv6xx+ */
1461 enum amdgpu_int_thermal_type int_thermal_type;
1462 struct device *int_hwmon_dev;
1463 /* fan control parameters */
1464 bool no_fan;
1465 u8 fan_pulses_per_revolution;
1466 u8 fan_min_rpm;
1467 u8 fan_max_rpm;
1468 /* dpm */
1469 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001470 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001471 struct amdgpu_dpm dpm;
1472 const struct firmware *fw; /* SMC firmware */
1473 uint32_t fw_version;
1474 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001475 uint32_t pcie_gen_mask;
1476 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001477 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001478};
1479
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001480void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1481
Alex Deucher97b2e202015-04-20 16:51:00 -04001482/*
1483 * UVD
1484 */
Arindam Nathc0365542016-04-12 13:46:15 +02001485#define AMDGPU_DEFAULT_UVD_HANDLES 10
1486#define AMDGPU_MAX_UVD_HANDLES 40
1487#define AMDGPU_UVD_STACK_SIZE (200*1024)
1488#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1489#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1490#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001491
1492struct amdgpu_uvd {
1493 struct amdgpu_bo *vcpu_bo;
1494 void *cpu_addr;
1495 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001496 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001497 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001498 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001499 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1500 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1501 struct delayed_work idle_work;
1502 const struct firmware *fw; /* UVD firmware */
1503 struct amdgpu_ring ring;
1504 struct amdgpu_irq_src irq;
1505 bool address_64_bit;
Christian König4cb5877c2016-07-26 12:05:40 +02001506 bool use_ctx_buf;
Christian Königead833e2016-02-10 14:35:19 +01001507 struct amd_sched_entity entity;
Chunming Zhoufc0b3b92016-07-18 17:18:01 +08001508 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001509};
1510
1511/*
1512 * VCE
1513 */
1514#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001515#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1516
Alex Deucher6a585772015-07-10 14:16:24 -04001517#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1518#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1519
Alex Deucher97b2e202015-04-20 16:51:00 -04001520struct amdgpu_vce {
1521 struct amdgpu_bo *vcpu_bo;
1522 uint64_t gpu_addr;
1523 unsigned fw_version;
1524 unsigned fb_version;
1525 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1526 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001527 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001528 struct delayed_work idle_work;
Christian Königebff4852016-07-20 16:53:36 +02001529 struct mutex idle_mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001530 const struct firmware *fw; /* VCE firmware */
1531 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1532 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001533 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001534 struct amd_sched_entity entity;
Chunming Zhou115933a2016-07-18 17:38:50 +08001535 uint32_t srbm_soft_reset;
Alex Deucher75c65482016-08-24 16:56:21 -04001536 unsigned num_rings;
Alex Deucher97b2e202015-04-20 16:51:00 -04001537};
1538
1539/*
1540 * SDMA
1541 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001542struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001543 /* SDMA firmware */
1544 const struct firmware *fw;
1545 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001546 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001547
1548 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001549 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001550};
1551
Alex Deucherc113ea12015-10-08 16:30:37 -04001552struct amdgpu_sdma {
1553 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
Ken Wang30d15742016-01-19 14:05:23 +08001554#ifdef CONFIG_DRM_AMDGPU_SI
1555 //SI DMA has a difference trap irq number for the second engine
1556 struct amdgpu_irq_src trap_irq_1;
1557#endif
Alex Deucherc113ea12015-10-08 16:30:37 -04001558 struct amdgpu_irq_src trap_irq;
1559 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001560 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001561 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001562};
1563
Alex Deucher97b2e202015-04-20 16:51:00 -04001564/*
1565 * Firmware
1566 */
1567struct amdgpu_firmware {
1568 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1569 bool smu_load;
1570 struct amdgpu_bo *fw_buf;
1571 unsigned int fw_size;
1572};
1573
1574/*
1575 * Benchmarking
1576 */
1577void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1578
1579
1580/*
1581 * Testing
1582 */
1583void amdgpu_test_moves(struct amdgpu_device *adev);
1584void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1585 struct amdgpu_ring *cpA,
1586 struct amdgpu_ring *cpB);
1587void amdgpu_test_syncing(struct amdgpu_device *adev);
1588
1589/*
1590 * MMU Notifier
1591 */
1592#if defined(CONFIG_MMU_NOTIFIER)
1593int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1594void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1595#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001596static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001597{
1598 return -ENODEV;
1599}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001600static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001601#endif
1602
1603/*
1604 * Debugfs
1605 */
1606struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001607 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001608 unsigned num_files;
1609};
1610
1611int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001612 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001613 unsigned nfiles);
1614int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1615
1616#if defined(CONFIG_DEBUG_FS)
1617int amdgpu_debugfs_init(struct drm_minor *minor);
1618void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1619#endif
1620
Huang Rui50ab2532016-06-12 15:51:09 +08001621int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1622
Alex Deucher97b2e202015-04-20 16:51:00 -04001623/*
1624 * amdgpu smumgr functions
1625 */
1626struct amdgpu_smumgr_funcs {
1627 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1628 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1629 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1630};
1631
1632/*
1633 * amdgpu smumgr
1634 */
1635struct amdgpu_smumgr {
1636 struct amdgpu_bo *toc_buf;
1637 struct amdgpu_bo *smu_buf;
1638 /* asic priv smu data */
1639 void *priv;
1640 spinlock_t smu_lock;
1641 /* smumgr functions */
1642 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1643 /* ucode loading complete flag */
1644 uint32_t fw_flags;
1645};
1646
1647/*
1648 * ASIC specific register table accessible by UMD
1649 */
1650struct amdgpu_allowed_register_entry {
1651 uint32_t reg_offset;
1652 bool untouched;
1653 bool grbm_indexed;
1654};
1655
Alex Deucher97b2e202015-04-20 16:51:00 -04001656/*
1657 * ASIC specific functions.
1658 */
1659struct amdgpu_asic_funcs {
1660 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001661 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1662 u8 *bios, u32 length_bytes);
Monk Liu4e99a442016-03-31 13:26:59 +08001663 void (*detect_hw_virtualization) (struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001664 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1665 u32 sh_num, u32 reg_offset, u32 *value);
1666 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1667 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001668 /* get the reference clock */
1669 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001670 /* MM block clocks */
1671 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1672 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Maruthi Bayyavarapu841686d2016-08-01 12:42:32 -04001673 /* static power management */
1674 int (*get_pcie_lanes)(struct amdgpu_device *adev);
1675 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001676};
1677
1678/*
1679 * IOCTL.
1680 */
1681int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1682 struct drm_file *filp);
1683int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1684 struct drm_file *filp);
1685
1686int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1687 struct drm_file *filp);
1688int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1689 struct drm_file *filp);
1690int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1691 struct drm_file *filp);
1692int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1693 struct drm_file *filp);
1694int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1695 struct drm_file *filp);
1696int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1697 struct drm_file *filp);
1698int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1699int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1700
1701int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1702 struct drm_file *filp);
1703
1704/* VRAM scratch page for HDP bug, default vram page */
1705struct amdgpu_vram_scratch {
1706 struct amdgpu_bo *robj;
1707 volatile uint32_t *ptr;
1708 u64 gpu_addr;
1709};
1710
1711/*
1712 * ACPI
1713 */
1714struct amdgpu_atif_notification_cfg {
1715 bool enabled;
1716 int command_code;
1717};
1718
1719struct amdgpu_atif_notifications {
1720 bool display_switch;
1721 bool expansion_mode_change;
1722 bool thermal_state;
1723 bool forced_power_state;
1724 bool system_power_state;
1725 bool display_conf_change;
1726 bool px_gfx_switch;
1727 bool brightness_change;
1728 bool dgpu_display_event;
1729};
1730
1731struct amdgpu_atif_functions {
1732 bool system_params;
1733 bool sbios_requests;
1734 bool select_active_disp;
1735 bool lid_state;
1736 bool get_tv_standard;
1737 bool set_tv_standard;
1738 bool get_panel_expansion_mode;
1739 bool set_panel_expansion_mode;
1740 bool temperature_change;
1741 bool graphics_device_types;
1742};
1743
1744struct amdgpu_atif {
1745 struct amdgpu_atif_notifications notifications;
1746 struct amdgpu_atif_functions functions;
1747 struct amdgpu_atif_notification_cfg notification_cfg;
1748 struct amdgpu_encoder *encoder_for_bl;
1749};
1750
1751struct amdgpu_atcs_functions {
1752 bool get_ext_state;
1753 bool pcie_perf_req;
1754 bool pcie_dev_rdy;
1755 bool pcie_bus_width;
1756};
1757
1758struct amdgpu_atcs {
1759 struct amdgpu_atcs_functions functions;
1760};
1761
Alex Deucher97b2e202015-04-20 16:51:00 -04001762/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001763 * CGS
1764 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001765struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1766void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001767
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001768/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001769 * Core structure, functions and helpers.
1770 */
1771typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1772typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1773
1774typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1775typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1776
Alex Deucher8faf0e082015-07-28 11:50:31 -04001777struct amdgpu_ip_block_status {
1778 bool valid;
1779 bool sw;
1780 bool hw;
Grazvydas Ignotas8a2eef12016-10-03 00:06:44 +03001781 bool late_initialized;
Chunming Zhou63fbf422016-07-15 11:19:20 +08001782 bool hang;
Alex Deucher8faf0e082015-07-28 11:50:31 -04001783};
1784
Alex Deucher97b2e202015-04-20 16:51:00 -04001785struct amdgpu_device {
1786 struct device *dev;
1787 struct drm_device *ddev;
1788 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001789
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001790#ifdef CONFIG_DRM_AMD_ACP
1791 struct amdgpu_acp acp;
1792#endif
1793
Alex Deucher97b2e202015-04-20 16:51:00 -04001794 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001795 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001796 uint32_t family;
1797 uint32_t rev_id;
1798 uint32_t external_rev_id;
1799 unsigned long flags;
1800 int usec_timeout;
1801 const struct amdgpu_asic_funcs *asic_funcs;
1802 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001803 bool need_dma32;
1804 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001805 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001806 struct notifier_block acpi_nb;
1807 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1808 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001809 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001810#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001811 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001812#endif
1813 struct amdgpu_atif atif;
1814 struct amdgpu_atcs atcs;
1815 struct mutex srbm_mutex;
1816 /* GRBM index mutex. Protects concurrent access to GRBM index */
1817 struct mutex grbm_idx_mutex;
1818 struct dev_pm_domain vga_pm_domain;
1819 bool have_disp_power_ref;
1820
1821 /* BIOS */
1822 uint8_t *bios;
1823 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001824 struct amdgpu_bo *stollen_vga_memory;
1825 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1826
1827 /* Register/doorbell mmio */
1828 resource_size_t rmmio_base;
1829 resource_size_t rmmio_size;
1830 void __iomem *rmmio;
1831 /* protects concurrent MM_INDEX/DATA based register access */
1832 spinlock_t mmio_idx_lock;
1833 /* protects concurrent SMC based register access */
1834 spinlock_t smc_idx_lock;
1835 amdgpu_rreg_t smc_rreg;
1836 amdgpu_wreg_t smc_wreg;
1837 /* protects concurrent PCIE register access */
1838 spinlock_t pcie_idx_lock;
1839 amdgpu_rreg_t pcie_rreg;
1840 amdgpu_wreg_t pcie_wreg;
Huang Rui36b9a952016-08-31 13:23:25 +08001841 amdgpu_rreg_t pciep_rreg;
1842 amdgpu_wreg_t pciep_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001843 /* protects concurrent UVD register access */
1844 spinlock_t uvd_ctx_idx_lock;
1845 amdgpu_rreg_t uvd_ctx_rreg;
1846 amdgpu_wreg_t uvd_ctx_wreg;
1847 /* protects concurrent DIDT register access */
1848 spinlock_t didt_idx_lock;
1849 amdgpu_rreg_t didt_rreg;
1850 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08001851 /* protects concurrent gc_cac register access */
1852 spinlock_t gc_cac_idx_lock;
1853 amdgpu_rreg_t gc_cac_rreg;
1854 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001855 /* protects concurrent ENDPOINT (audio) register access */
1856 spinlock_t audio_endpt_idx_lock;
1857 amdgpu_block_rreg_t audio_endpt_rreg;
1858 amdgpu_block_wreg_t audio_endpt_wreg;
1859 void __iomem *rio_mem;
1860 resource_size_t rio_mem_size;
1861 struct amdgpu_doorbell doorbell;
1862
1863 /* clock/pll info */
1864 struct amdgpu_clock clock;
1865
1866 /* MC */
1867 struct amdgpu_mc mc;
1868 struct amdgpu_gart gart;
1869 struct amdgpu_dummy_page dummy_page;
1870 struct amdgpu_vm_manager vm_manager;
1871
1872 /* memory management */
1873 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04001874 struct amdgpu_vram_scratch vram_scratch;
1875 struct amdgpu_wb wb;
1876 atomic64_t vram_usage;
1877 atomic64_t vram_vis_usage;
1878 atomic64_t gtt_usage;
1879 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02001880 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02001881 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04001882
Marek Olšák95844d22016-08-17 23:49:27 +02001883 /* data for buffer migration throttling */
1884 struct {
1885 spinlock_t lock;
1886 s64 last_update_us;
1887 s64 accum_us; /* accumulated microseconds */
1888 u32 log2_max_MBps;
1889 } mm_stats;
1890
Alex Deucher97b2e202015-04-20 16:51:00 -04001891 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08001892 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04001893 struct amdgpu_mode_info mode_info;
1894 struct work_struct hotplug_work;
1895 struct amdgpu_irq_src crtc_irq;
1896 struct amdgpu_irq_src pageflip_irq;
1897 struct amdgpu_irq_src hpd_irq;
1898
1899 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02001900 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04001901 unsigned num_rings;
1902 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1903 bool ib_pool_ready;
1904 struct amdgpu_sa_manager ring_tmp_bo;
1905
1906 /* interrupts */
1907 struct amdgpu_irq irq;
1908
Alex Deucher1f7371b2015-12-02 17:46:21 -05001909 /* powerplay */
1910 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05001911 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05001912 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05001913
Alex Deucher97b2e202015-04-20 16:51:00 -04001914 /* dpm */
1915 struct amdgpu_pm pm;
1916 u32 cg_flags;
1917 u32 pg_flags;
1918
1919 /* amdgpu smumgr */
1920 struct amdgpu_smumgr smu;
1921
1922 /* gfx */
1923 struct amdgpu_gfx gfx;
1924
1925 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04001926 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04001927
1928 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04001929 struct amdgpu_uvd uvd;
1930
1931 /* vce */
1932 struct amdgpu_vce vce;
1933
1934 /* firmwares */
1935 struct amdgpu_firmware firmware;
1936
1937 /* GDS */
1938 struct amdgpu_gds gds;
1939
1940 const struct amdgpu_ip_block_version *ip_blocks;
1941 int num_ip_blocks;
Alex Deucher8faf0e082015-07-28 11:50:31 -04001942 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04001943 struct mutex mn_lock;
1944 DECLARE_HASHTABLE(mn_hash, 7);
1945
1946 /* tracking pinned memory */
1947 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08001948 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001949 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03001950
1951 /* amdkfd interface */
1952 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08001953
Alex Deucher7e471e62016-02-01 11:13:04 -05001954 struct amdgpu_virtualization virtualization;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +08001955
1956 /* link all shadow bo */
1957 struct list_head shadow_list;
1958 struct mutex shadow_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08001959 /* link all gtt */
1960 spinlock_t gtt_list_lock;
1961 struct list_head gtt_list;
1962
Alex Deucher97b2e202015-04-20 16:51:00 -04001963};
1964
Christian Königa7d64de2016-09-15 14:58:48 +02001965static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1966{
1967 return container_of(bdev, struct amdgpu_device, mman.bdev);
1968}
1969
Alex Deucher97b2e202015-04-20 16:51:00 -04001970bool amdgpu_device_is_px(struct drm_device *dev);
1971int amdgpu_device_init(struct amdgpu_device *adev,
1972 struct drm_device *ddev,
1973 struct pci_dev *pdev,
1974 uint32_t flags);
1975void amdgpu_device_fini(struct amdgpu_device *adev);
1976int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1977
1978uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
1979 bool always_indirect);
1980void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
1981 bool always_indirect);
1982u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1983void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1984
1985u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1986void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
1987
1988/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001989 * Registers read & write functions.
1990 */
1991#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
1992#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
1993#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
1994#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
1995#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
1996#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1997#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1998#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1999#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
Huang Rui36b9a952016-08-31 13:23:25 +08002000#define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
2001#define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04002002#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2003#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2004#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2005#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2006#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2007#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08002008#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
2009#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04002010#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2011#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2012#define WREG32_P(reg, val, mask) \
2013 do { \
2014 uint32_t tmp_ = RREG32(reg); \
2015 tmp_ &= (mask); \
2016 tmp_ |= ((val) & ~(mask)); \
2017 WREG32(reg, tmp_); \
2018 } while (0)
2019#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2020#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2021#define WREG32_PLL_P(reg, val, mask) \
2022 do { \
2023 uint32_t tmp_ = RREG32_PLL(reg); \
2024 tmp_ &= (mask); \
2025 tmp_ |= ((val) & ~(mask)); \
2026 WREG32_PLL(reg, tmp_); \
2027 } while (0)
2028#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2029#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2030#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2031
2032#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2033#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2034
2035#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2036#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2037
2038#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2039 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2040 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2041
2042#define REG_GET_FIELD(value, reg, field) \
2043 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2044
Tom St Denis61cb8ce2016-08-09 10:13:21 -04002045#define WREG32_FIELD(reg, field, val) \
2046 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
2047
Alex Deucher97b2e202015-04-20 16:51:00 -04002048/*
2049 * BIOS helpers.
2050 */
2051#define RBIOS8(i) (adev->bios[i])
2052#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2053#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2054
2055/*
2056 * RING helpers.
2057 */
2058static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2059{
2060 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002061 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002062 ring->ring[ring->wptr++] = v;
2063 ring->wptr &= ring->ptr_mask;
2064 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002065}
2066
Alex Deucherc113ea12015-10-08 16:30:37 -04002067static inline struct amdgpu_sdma_instance *
2068amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002069{
2070 struct amdgpu_device *adev = ring->adev;
2071 int i;
2072
Alex Deucherc113ea12015-10-08 16:30:37 -04002073 for (i = 0; i < adev->sdma.num_instances; i++)
2074 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002075 break;
2076
2077 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002078 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002079 else
2080 return NULL;
2081}
2082
Alex Deucher97b2e202015-04-20 16:51:00 -04002083/*
2084 * ASICs macro.
2085 */
2086#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2087#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002088#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2089#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2090#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 -04002091#define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
2092#define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
2093#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002094#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002095#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 +08002096#define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002097#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 -04002098#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2099#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2100#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 +02002101#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 -04002102#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 -04002103#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2104#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02002105#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04002106#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2107#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2108#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002109#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 +01002110#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002111#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002112#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002113#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 +02002114#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002115#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Monk Liuc2167a62016-08-26 14:12:37 +08002116#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
Monk Liu753ad492016-08-26 13:28:28 +08002117#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
Christian König9e5d53092016-01-31 12:20:55 +01002118#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002119#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2120#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucherb6384ff2016-09-16 10:55:50 -04002121#define amdgpu_ring_get_emit_ib_size(r) (r)->funcs->get_emit_ib_size((r))
2122#define amdgpu_ring_get_dma_frame_size(r) (r)->funcs->get_dma_frame_size((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002123#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2124#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2125#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2126#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2127#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2128#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2129#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2130#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2131#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2132#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2133#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2134#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2135#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002136#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 -04002137#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2138#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2139#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))
2140#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2141#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002142#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 +08002143#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 -04002144#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2145#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2146#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2147#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002148#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002149#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002150#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04002151#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04002152#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 +08002153
Tom St Denis3de4ec52016-09-19 12:48:52 -04002154#define amdgpu_dpm_read_sensor(adev, idx, value) \
2155 ((adev)->pp_enabled ? \
2156 (adev)->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, (idx), (value)) : \
2157 -EINVAL)
2158
Rex Zhu3af76f22015-10-15 17:23:43 +08002159#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002160 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002161 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002162 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002163
2164#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002165 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002166 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002167 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002168
2169#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002170 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002171 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002172 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002173
2174#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002175 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002176 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002177 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002178
2179#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002180 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002181 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002182 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002183
Rex Zhu1b5708f2015-11-10 18:25:24 -05002184#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002185 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002186 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002187 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002188
2189#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002190 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002191 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002192 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002193
2194
2195#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002196 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002197 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002198 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002199
2200#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002201 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002202 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002203 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002204
2205#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002206 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002207 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002208 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002209
Rex Zhu1b5708f2015-11-10 18:25:24 -05002210#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002211 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002212
2213#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002214 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002215
Eric Huangf3898ea2015-12-11 16:24:34 -05002216#define amdgpu_dpm_get_pp_num_states(adev, data) \
2217 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2218
2219#define amdgpu_dpm_get_pp_table(adev, table) \
2220 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2221
2222#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2223 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2224
2225#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2226 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2227
2228#define amdgpu_dpm_force_clock_level(adev, type, level) \
2229 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2230
Eric Huang428bafa2016-05-12 14:51:21 -04002231#define amdgpu_dpm_get_sclk_od(adev) \
2232 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2233
2234#define amdgpu_dpm_set_sclk_od(adev, value) \
2235 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2236
Eric Huangf2bdc052016-05-24 15:11:17 -04002237#define amdgpu_dpm_get_mclk_od(adev) \
2238 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2239
2240#define amdgpu_dpm_set_mclk_od(adev, value) \
2241 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2242
Jammy Zhoue61710c2015-11-10 18:31:08 -05002243#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002244 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002245
2246#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2247
2248/* Common functions */
2249int amdgpu_gpu_reset(struct amdgpu_device *adev);
Chunming Zhou3ad81f12016-08-05 17:30:17 +08002250bool amdgpu_need_backup(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002251void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2252bool amdgpu_card_posted(struct amdgpu_device *adev);
2253void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002254
Alex Deucher97b2e202015-04-20 16:51:00 -04002255int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2256int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2257 u32 ip_instance, u32 ring,
2258 struct amdgpu_ring **out_ring);
Christian König765e7fb2016-09-15 15:06:50 +02002259void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
Alex Deucher97b2e202015-04-20 16:51:00 -04002260bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002261int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002262int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2263 uint32_t flags);
2264bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002265struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002266bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2267 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002268bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2269 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002270bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2271uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2272 struct ttm_mem_reg *mem);
2273void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2274void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2275void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Ken Wanga693e052016-07-27 19:18:01 +08002276u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2277int amdgpu_ttm_global_init(struct amdgpu_device *adev);
Baoyou Xie9f31a0b2016-09-15 21:43:26 +08002278int amdgpu_ttm_init(struct amdgpu_device *adev);
2279void amdgpu_ttm_fini(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002280void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2281 const u32 *registers,
2282 const u32 array_size);
2283
2284bool amdgpu_device_is_px(struct drm_device *dev);
2285/* atpx handler */
2286#if defined(CONFIG_VGA_SWITCHEROO)
2287void amdgpu_register_atpx_handler(void);
2288void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002289bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002290bool amdgpu_is_atpx_hybrid(void);
Alex Deucherefc83cf2016-09-14 14:01:41 -04002291bool amdgpu_atpx_dgpu_req_power_for_displays(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002292#else
2293static inline void amdgpu_register_atpx_handler(void) {}
2294static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002295static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002296static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucherefc83cf2016-09-14 14:01:41 -04002297static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002298#endif
2299
2300/*
2301 * KMS
2302 */
2303extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002304extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002305
2306int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2307int amdgpu_driver_unload_kms(struct drm_device *dev);
2308void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2309int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2310void amdgpu_driver_postclose_kms(struct drm_device *dev,
2311 struct drm_file *file_priv);
2312void amdgpu_driver_preclose_kms(struct drm_device *dev,
2313 struct drm_file *file_priv);
Alex Deucher810ddc32016-08-23 13:25:49 -04002314int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
2315int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002316u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2317int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2318void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2319int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002320 int *max_error,
2321 struct timeval *vblank_time,
2322 unsigned flags);
2323long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2324 unsigned long arg);
2325
2326/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002327 * functions used by amdgpu_encoder.c
2328 */
2329struct amdgpu_afmt_acr {
2330 u32 clock;
2331
2332 int n_32khz;
2333 int cts_32khz;
2334
2335 int n_44_1khz;
2336 int cts_44_1khz;
2337
2338 int n_48khz;
2339 int cts_48khz;
2340
2341};
2342
2343struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2344
2345/* amdgpu_acpi.c */
2346#if defined(CONFIG_ACPI)
2347int amdgpu_acpi_init(struct amdgpu_device *adev);
2348void amdgpu_acpi_fini(struct amdgpu_device *adev);
2349bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2350int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2351 u8 perf_req, bool advertise);
2352int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2353#else
2354static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2355static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2356#endif
2357
2358struct amdgpu_bo_va_mapping *
2359amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2360 uint64_t addr, struct amdgpu_bo **bo);
Christian Königc855e252016-09-05 17:00:57 +02002361int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
Alex Deucher97b2e202015-04-20 16:51:00 -04002362
2363#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002364#endif