blob: ef34ff2140832e652226f6d0cd3f75f050cac188 [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>
Christian Königa9f87f62017-03-30 14:03:59 +020035#include <linux/rbtree.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040036#include <linux/hashtable.h>
Chris Wilsonf54d1862016-10-25 13:00:45 +010037#include <linux/dma-fence.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040038
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
Andres Rodriguez78c16832017-02-02 00:38:22 -050049#include <kgd_kfd_interface.h>
50
yanyang15fc3aee2015-05-22 14:39:35 -040051#include "amd_shared.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040052#include "amdgpu_mode.h"
53#include "amdgpu_ih.h"
54#include "amdgpu_irq.h"
55#include "amdgpu_ucode.h"
Flora Cuic632d792016-08-02 11:32:41 +080056#include "amdgpu_ttm.h"
Huang Rui0e5ca0d2017-03-03 18:37:23 -050057#include "amdgpu_psp.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040058#include "amdgpu_gds.h"
Christian König56113502016-09-28 12:36:44 +020059#include "amdgpu_sync.h"
Christian König78023012016-09-28 15:33:18 +020060#include "amdgpu_ring.h"
Christian König073440d2016-09-28 15:41:50 +020061#include "amdgpu_vm.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050062#include "amd_powerplay.h"
Alex Deuchercf0978812016-10-07 11:40:09 -040063#include "amdgpu_dpm.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040064#include "amdgpu_acp.h"
Leo Liu4df654d2017-01-02 10:07:33 -050065#include "amdgpu_uvd.h"
Leo Liu5e568172017-01-10 11:02:58 -050066#include "amdgpu_vce.h"
Leo Liu95aa13f2017-05-11 16:27:33 -040067#include "amdgpu_vcn.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040068
Alex Deucherb80d8472015-08-16 22:55:02 -040069#include "gpu_scheduler.h"
Monk Liuceeb50e2016-09-19 12:13:58 +080070#include "amdgpu_virt.h"
Alex Deucherb80d8472015-08-16 22:55:02 -040071
Alex Deucher97b2e202015-04-20 16:51:00 -040072/*
73 * Modules parameters.
74 */
75extern int amdgpu_modeset;
76extern int amdgpu_vram_limit;
77extern int amdgpu_gart_size;
Marek Olšák95844d22016-08-17 23:49:27 +020078extern int amdgpu_moverate;
Alex Deucher97b2e202015-04-20 16:51:00 -040079extern int amdgpu_benchmarking;
80extern int amdgpu_testing;
81extern int amdgpu_audio;
82extern int amdgpu_disp_priority;
83extern int amdgpu_hw_i2c;
84extern int amdgpu_pcie_gen2;
85extern int amdgpu_msi;
86extern int amdgpu_lockup_timeout;
87extern int amdgpu_dpm;
Huang Ruie635ee02016-11-01 15:35:38 +080088extern int amdgpu_fw_load_type;
Alex Deucher97b2e202015-04-20 16:51:00 -040089extern int amdgpu_aspm;
90extern int amdgpu_runtime_pm;
Alex Deucher97b2e202015-04-20 16:51:00 -040091extern unsigned amdgpu_ip_block_mask;
92extern int amdgpu_bapm;
93extern int amdgpu_deep_color;
94extern int amdgpu_vm_size;
95extern int amdgpu_vm_block_size;
Christian Königd9c13152015-09-28 12:31:26 +020096extern int amdgpu_vm_fault_stop;
Christian Königb495bd32015-09-10 14:00:35 +020097extern int amdgpu_vm_debug;
Jammy Zhou1333f722015-07-30 16:36:58 +080098extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080099extern int amdgpu_sched_hw_submission;
Rex Zhu3ca67302016-11-02 13:38:37 +0800100extern int amdgpu_no_evict;
101extern int amdgpu_direct_gma_size;
Alex Deuchercd474ba2016-02-04 10:21:23 -0500102extern unsigned amdgpu_pcie_gen_cap;
103extern unsigned amdgpu_pcie_lane_cap;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +0200104extern unsigned amdgpu_cg_mask;
105extern unsigned amdgpu_pg_mask;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +0200106extern char *amdgpu_disable_cu;
Emily Deng9accf2f2016-08-10 16:01:25 +0800107extern char *amdgpu_virtual_display;
Rex Zhu5141e9d2016-09-06 16:34:37 +0800108extern unsigned amdgpu_pp_feature_mask;
Christian König6a7f76e2016-08-24 15:51:49 +0200109extern int amdgpu_vram_page_split;
Alex Deucherbce23e02017-03-28 12:52:08 -0400110extern int amdgpu_ngg;
111extern int amdgpu_prim_buf_per_se;
112extern int amdgpu_pos_buf_per_se;
113extern int amdgpu_cntl_sb_buf_per_se;
114extern int amdgpu_param_buf_per_se;
Monk Liu65781c72017-05-11 13:36:44 +0800115extern int amdgpu_job_hang_limit;
Hawking Zhange8835e02017-05-26 14:40:36 +0800116extern int amdgpu_lbpw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400117
Chunming Zhou55ed8caf2017-04-21 16:40:00 +0800118#define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */
Chunming Zhou4b559c92015-07-21 15:53:04 +0800119#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -0400120#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
121#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
122/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
123#define AMDGPU_IB_POOL_SIZE 16
124#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
125#define AMDGPUFB_CONN_LIMIT 4
Alex Deuchera5bde2f2016-09-23 16:23:41 -0400126#define AMDGPU_BIOS_NUM_SCRATCH 16
Alex Deucher97b2e202015-04-20 16:51:00 -0400127
Jammy Zhou36f523a2015-09-01 12:54:27 +0800128/* max number of IP instances */
129#define AMDGPU_MAX_SDMA_INSTANCES 2
130
Alex Deucher97b2e202015-04-20 16:51:00 -0400131/* hard reset data */
132#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
133
134/* reset flags */
135#define AMDGPU_RESET_GFX (1 << 0)
136#define AMDGPU_RESET_COMPUTE (1 << 1)
137#define AMDGPU_RESET_DMA (1 << 2)
138#define AMDGPU_RESET_CP (1 << 3)
139#define AMDGPU_RESET_GRBM (1 << 4)
140#define AMDGPU_RESET_DMA1 (1 << 5)
141#define AMDGPU_RESET_RLC (1 << 6)
142#define AMDGPU_RESET_SEM (1 << 7)
143#define AMDGPU_RESET_IH (1 << 8)
144#define AMDGPU_RESET_VMC (1 << 9)
145#define AMDGPU_RESET_MC (1 << 10)
146#define AMDGPU_RESET_DISPLAY (1 << 11)
147#define AMDGPU_RESET_UVD (1 << 12)
148#define AMDGPU_RESET_VCE (1 << 13)
149#define AMDGPU_RESET_VCE1 (1 << 14)
150
Alex Deucher97b2e202015-04-20 16:51:00 -0400151/* GFX current status */
152#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
153#define AMDGPU_GFX_SAFE_MODE 0x00000001L
154#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
155#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
156#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
157
158/* max cursor sizes (in pixels) */
159#define CIK_CURSOR_WIDTH 128
160#define CIK_CURSOR_HEIGHT 128
161
162struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400163struct amdgpu_ib;
Alex Deucher97b2e202015-04-20 16:51:00 -0400164struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800165struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400166struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400167struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400168
169enum amdgpu_cp_irq {
170 AMDGPU_CP_IRQ_GFX_EOP = 0,
171 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
172 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
173 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
174 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
175 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
176 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
177 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
178 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
179
180 AMDGPU_CP_IRQ_LAST
181};
182
183enum amdgpu_sdma_irq {
184 AMDGPU_SDMA_IRQ_TRAP0 = 0,
185 AMDGPU_SDMA_IRQ_TRAP1,
186
187 AMDGPU_SDMA_IRQ_LAST
188};
189
190enum amdgpu_thermal_irq {
191 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
192 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
193
194 AMDGPU_THERMAL_IRQ_LAST
195};
196
Xiangliang Yu4e638ae2016-12-23 15:00:01 +0800197enum amdgpu_kiq_irq {
198 AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
199 AMDGPU_CP_KIQ_IRQ_LAST
200};
201
Alex Deucher97b2e202015-04-20 16:51:00 -0400202int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400203 enum amd_ip_block_type block_type,
204 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400205int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400206 enum amd_ip_block_type block_type,
207 enum amd_powergating_state state);
Huang Rui6cb2d4e2017-01-05 18:44:41 +0800208void amdgpu_get_clockgating_state(struct amdgpu_device *adev, u32 *flags);
Alex Deucher5dbbb602016-06-23 11:41:04 -0400209int amdgpu_wait_for_idle(struct amdgpu_device *adev,
210 enum amd_ip_block_type block_type);
211bool amdgpu_is_idle(struct amdgpu_device *adev,
212 enum amd_ip_block_type block_type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400213
Alex Deuchera1255102016-10-13 17:41:13 -0400214#define AMDGPU_MAX_IP_NUM 16
215
216struct amdgpu_ip_block_status {
217 bool valid;
218 bool sw;
219 bool hw;
220 bool late_initialized;
221 bool hang;
222};
223
Alex Deucher97b2e202015-04-20 16:51:00 -0400224struct amdgpu_ip_block_version {
Alex Deuchera1255102016-10-13 17:41:13 -0400225 const enum amd_ip_block_type type;
226 const u32 major;
227 const u32 minor;
228 const u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400229 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400230};
231
Alex Deuchera1255102016-10-13 17:41:13 -0400232struct amdgpu_ip_block {
233 struct amdgpu_ip_block_status status;
234 const struct amdgpu_ip_block_version *version;
235};
236
Alex Deucher97b2e202015-04-20 16:51:00 -0400237int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400238 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400239 u32 major, u32 minor);
240
Alex Deuchera1255102016-10-13 17:41:13 -0400241struct amdgpu_ip_block * amdgpu_get_ip_block(struct amdgpu_device *adev,
242 enum amd_ip_block_type type);
243
244int amdgpu_ip_block_add(struct amdgpu_device *adev,
245 const struct amdgpu_ip_block_version *ip_block_version);
Alex Deucher97b2e202015-04-20 16:51:00 -0400246
247/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
248struct amdgpu_buffer_funcs {
249 /* maximum bytes in a single operation */
250 uint32_t copy_max_bytes;
251
252 /* number of dw to reserve per operation */
253 unsigned copy_num_dw;
254
255 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800256 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400257 /* src addr in bytes */
258 uint64_t src_offset,
259 /* dst addr in bytes */
260 uint64_t dst_offset,
261 /* number of byte to transfer */
262 uint32_t byte_count);
263
264 /* maximum bytes in a single operation */
265 uint32_t fill_max_bytes;
266
267 /* number of dw to reserve per operation */
268 unsigned fill_num_dw;
269
270 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800271 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400272 /* value to write to memory */
273 uint32_t src_data,
274 /* dst addr in bytes */
275 uint64_t dst_offset,
276 /* number of byte to fill */
277 uint32_t byte_count);
278};
279
280/* provided by hw blocks that can write ptes, e.g., sdma */
281struct amdgpu_vm_pte_funcs {
282 /* copy pte entries from GART */
283 void (*copy_pte)(struct amdgpu_ib *ib,
284 uint64_t pe, uint64_t src,
285 unsigned count);
286 /* write pte one entry at a time with addr mapping */
Christian Königde9ea7b2016-08-12 11:33:30 +0200287 void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
288 uint64_t value, unsigned count,
289 uint32_t incr);
Alex Deucher97b2e202015-04-20 16:51:00 -0400290 /* for linear pte/pde updates without addr mapping */
291 void (*set_pte_pde)(struct amdgpu_ib *ib,
292 uint64_t pe,
293 uint64_t addr, unsigned count,
Chunming Zhou6b777602016-09-21 16:19:19 +0800294 uint32_t incr, uint64_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400295};
296
297/* provided by the gmc block */
298struct amdgpu_gart_funcs {
299 /* flush the vm tlb via mmio */
300 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
301 uint32_t vmid);
302 /* write pte/pde updates using the cpu */
303 int (*set_pte_pde)(struct amdgpu_device *adev,
304 void *cpu_pt_addr, /* cpu addr of page table */
305 uint32_t gpu_page_idx, /* pte/pde to update */
306 uint64_t addr, /* addr to write into pte/pde */
Chunming Zhou6b777602016-09-21 16:19:19 +0800307 uint64_t flags); /* access flags */
Christian König284710f2017-01-30 11:09:31 +0100308 /* enable/disable PRT support */
309 void (*set_prt)(struct amdgpu_device *adev, bool enable);
Alex Xie54635452017-02-14 12:22:57 -0500310 /* set pte flags based per asic */
311 uint64_t (*get_vm_pte_flags)(struct amdgpu_device *adev,
312 uint32_t flags);
Christian Königb1166322017-05-12 15:39:39 +0200313 /* get the pde for a given mc addr */
314 u64 (*get_vm_pde)(struct amdgpu_device *adev, u64 addr);
Christian König03f89fe2017-04-04 16:07:45 +0200315 uint32_t (*get_invalidate_req)(unsigned int vm_id);
Alex Xiee60f8db2017-03-09 11:36:26 -0500316};
317
Alex Deucher97b2e202015-04-20 16:51:00 -0400318/* provided by the ih block */
319struct amdgpu_ih_funcs {
320 /* ring read/write ptr handling, called from interrupt context */
321 u32 (*get_wptr)(struct amdgpu_device *adev);
322 void (*decode_iv)(struct amdgpu_device *adev,
323 struct amdgpu_iv_entry *entry);
324 void (*set_rptr)(struct amdgpu_device *adev);
325};
326
Alex Deucher97b2e202015-04-20 16:51:00 -0400327/*
328 * BIOS.
329 */
330bool amdgpu_get_bios(struct amdgpu_device *adev);
331bool amdgpu_read_bios(struct amdgpu_device *adev);
332
333/*
334 * Dummy page
335 */
336struct amdgpu_dummy_page {
337 struct page *page;
338 dma_addr_t addr;
339};
340int amdgpu_dummy_page_init(struct amdgpu_device *adev);
341void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
342
343
344/*
345 * Clocks
346 */
347
348#define AMDGPU_MAX_PPLL 3
349
350struct amdgpu_clock {
351 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
352 struct amdgpu_pll spll;
353 struct amdgpu_pll mpll;
354 /* 10 Khz units */
355 uint32_t default_mclk;
356 uint32_t default_sclk;
357 uint32_t default_dispclk;
358 uint32_t current_dispclk;
359 uint32_t dp_extclk;
360 uint32_t max_pixel_clock;
361};
362
363/*
Flora Cuic632d792016-08-02 11:32:41 +0800364 * BO.
Alex Deucher97b2e202015-04-20 16:51:00 -0400365 */
Alex Deucher97b2e202015-04-20 16:51:00 -0400366struct amdgpu_bo_list_entry {
367 struct amdgpu_bo *robj;
368 struct ttm_validate_buffer tv;
369 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400370 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100371 struct page **user_pages;
372 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400373};
374
375struct amdgpu_bo_va_mapping {
376 struct list_head list;
Christian Königa9f87f62017-03-30 14:03:59 +0200377 struct rb_node rb;
378 uint64_t start;
379 uint64_t last;
380 uint64_t __subtree_last;
Alex Deucher97b2e202015-04-20 16:51:00 -0400381 uint64_t offset;
Christian König268c3002017-01-18 14:49:43 +0100382 uint64_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400383};
384
385/* bo virtual addresses in a specific vm */
386struct amdgpu_bo_va {
387 /* protected by bo being reserved */
388 struct list_head bo_list;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100389 struct dma_fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400390 unsigned ref_count;
391
Christian König7fc11952015-07-30 11:53:42 +0200392 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400393 struct list_head vm_status;
394
Christian König7fc11952015-07-30 11:53:42 +0200395 /* mappings for this bo_va */
396 struct list_head invalids;
397 struct list_head valids;
398
Alex Deucher97b2e202015-04-20 16:51:00 -0400399 /* constant after initialization */
400 struct amdgpu_vm *vm;
401 struct amdgpu_bo *bo;
402};
403
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800404#define AMDGPU_GEM_DOMAIN_MAX 0x3
405
Alex Deucher97b2e202015-04-20 16:51:00 -0400406struct amdgpu_bo {
Alex Deucher97b2e202015-04-20 16:51:00 -0400407 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100408 u32 prefered_domains;
409 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800410 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400411 struct ttm_placement placement;
412 struct ttm_buffer_object tbo;
413 struct ttm_bo_kmap_obj kmap;
414 u64 flags;
415 unsigned pin_count;
416 void *kptr;
417 u64 tiling_flags;
418 u64 metadata_flags;
419 void *metadata;
420 u32 metadata_size;
Mario Kleiner8e94a462016-11-09 02:25:15 +0100421 unsigned prime_shared_count;
Alex Deucher97b2e202015-04-20 16:51:00 -0400422 /* list of all virtual address to which this bo
423 * is associated to
424 */
425 struct list_head va;
426 /* Constant after initialization */
Alex Deucher97b2e202015-04-20 16:51:00 -0400427 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100428 struct amdgpu_bo *parent;
Chunming Zhoue7893c42016-07-26 14:13:21 +0800429 struct amdgpu_bo *shadow;
Alex Deucher97b2e202015-04-20 16:51:00 -0400430
431 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400432 struct amdgpu_mn *mn;
433 struct list_head mn_list;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +0800434 struct list_head shadow_list;
Alex Deucher97b2e202015-04-20 16:51:00 -0400435};
436#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
437
438void amdgpu_gem_object_free(struct drm_gem_object *obj);
439int amdgpu_gem_object_open(struct drm_gem_object *obj,
440 struct drm_file *file_priv);
441void amdgpu_gem_object_close(struct drm_gem_object *obj,
442 struct drm_file *file_priv);
443unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
444struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200445struct drm_gem_object *
446amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
447 struct dma_buf_attachment *attach,
448 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400449struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
450 struct drm_gem_object *gobj,
451 int flags);
452int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
453void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
454struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
455void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
456void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
457int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
458
459/* sub-allocation manager, it has to be protected by another lock.
460 * By conception this is an helper for other part of the driver
461 * like the indirect buffer or semaphore, which both have their
462 * locking.
463 *
464 * Principe is simple, we keep a list of sub allocation in offset
465 * order (first entry has offset == 0, last entry has the highest
466 * offset).
467 *
468 * When allocating new object we first check if there is room at
469 * the end total_size - (last_object_offset + last_object_size) >=
470 * alloc_size. If so we allocate new object there.
471 *
472 * When there is not enough room at the end, we start waiting for
473 * each sub object until we reach object_offset+object_size >=
474 * alloc_size, this object then become the sub object we return.
475 *
476 * Alignment can't be bigger than page size.
477 *
478 * Hole are not considered for allocation to keep things simple.
479 * Assumption is that there won't be hole (all object on same
480 * alignment).
481 */
Christian König6ba60b82016-03-11 14:50:08 +0100482
483#define AMDGPU_SA_NUM_FENCE_LISTS 32
484
Alex Deucher97b2e202015-04-20 16:51:00 -0400485struct amdgpu_sa_manager {
486 wait_queue_head_t wq;
487 struct amdgpu_bo *bo;
488 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100489 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400490 struct list_head olist;
491 unsigned size;
492 uint64_t gpu_addr;
493 void *cpu_ptr;
494 uint32_t domain;
495 uint32_t align;
496};
497
Alex Deucher97b2e202015-04-20 16:51:00 -0400498/* sub-allocation buffer */
499struct amdgpu_sa_bo {
500 struct list_head olist;
501 struct list_head flist;
502 struct amdgpu_sa_manager *manager;
503 unsigned soffset;
504 unsigned eoffset;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100505 struct dma_fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400506};
507
508/*
509 * GEM objects.
510 */
Christian König418aa0c2016-02-15 16:59:57 +0100511void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400512int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
513 int alignment, u32 initial_domain,
514 u64 flags, bool kernel,
515 struct drm_gem_object **obj);
516
517int amdgpu_mode_dumb_create(struct drm_file *file_priv,
518 struct drm_device *dev,
519 struct drm_mode_create_dumb *args);
520int amdgpu_mode_dumb_mmap(struct drm_file *filp,
521 struct drm_device *dev,
522 uint32_t handle, uint64_t *offset_p);
Rex Zhud573de22016-05-12 13:27:28 +0800523int amdgpu_fence_slab_init(void);
524void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400525
526/*
527 * GART structures, functions & helpers
528 */
529struct amdgpu_mc;
530
531#define AMDGPU_GPU_PAGE_SIZE 4096
532#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
533#define AMDGPU_GPU_PAGE_SHIFT 12
534#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
535
536struct amdgpu_gart {
537 dma_addr_t table_addr;
538 struct amdgpu_bo *robj;
539 void *ptr;
540 unsigned num_gpu_pages;
541 unsigned num_cpu_pages;
542 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200543#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400544 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200545#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400546 bool ready;
Alex Xie4b98e0c2017-02-14 12:31:36 -0500547
548 /* Asic default pte flags */
549 uint64_t gart_pte_flags;
550
Alex Deucher97b2e202015-04-20 16:51:00 -0400551 const struct amdgpu_gart_funcs *gart_funcs;
552};
553
554int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
555void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
556int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
557void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
558int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
559void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
560int amdgpu_gart_init(struct amdgpu_device *adev);
561void amdgpu_gart_fini(struct amdgpu_device *adev);
Roger.He738f64c2017-05-05 13:27:10 +0800562int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
Alex Deucher97b2e202015-04-20 16:51:00 -0400563 int pages);
Felix Kuehlingcab0b8d2016-08-12 19:25:21 -0400564int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
Alex Deucher97b2e202015-04-20 16:51:00 -0400565 int pages, struct page **pagelist,
Chunming Zhou6b777602016-09-21 16:19:19 +0800566 dma_addr_t *dma_addr, uint64_t flags);
Chunming Zhou2c0d7312016-08-30 16:36:25 +0800567int amdgpu_ttm_recover_gart(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400568
569/*
Alex Xiee60f8db2017-03-09 11:36:26 -0500570 * VMHUB structures, functions & helpers
571 */
572struct amdgpu_vmhub {
573 uint32_t ctx0_ptb_addr_lo32;
574 uint32_t ctx0_ptb_addr_hi32;
575 uint32_t vm_inv_eng0_req;
576 uint32_t vm_inv_eng0_ack;
577 uint32_t vm_context0_cntl;
578 uint32_t vm_l2_pro_fault_status;
579 uint32_t vm_l2_pro_fault_cntl;
Alex Xiee60f8db2017-03-09 11:36:26 -0500580};
581
582/*
Alex Deucher97b2e202015-04-20 16:51:00 -0400583 * GPU MC structures, functions & helpers
584 */
585struct amdgpu_mc {
586 resource_size_t aper_size;
587 resource_size_t aper_base;
588 resource_size_t agp_base;
589 /* for some chips with <= 32MB we need to lie
590 * about vram size near mc fb location */
591 u64 mc_vram_size;
592 u64 visible_vram_size;
593 u64 gtt_size;
594 u64 gtt_start;
595 u64 gtt_end;
596 u64 vram_start;
597 u64 vram_end;
598 unsigned vram_width;
599 u64 real_vram_size;
600 int vram_mtrr;
601 u64 gtt_base_align;
602 u64 mc_mask;
603 const struct firmware *fw; /* MC firmware */
604 uint32_t fw_version;
605 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800606 uint32_t vram_type;
Chunming Zhou50b01972016-07-18 16:59:24 +0800607 uint32_t srbm_soft_reset;
608 struct amdgpu_mode_mc_save save;
Christian Königf7c35ab2017-01-27 11:56:05 +0100609 bool prt_warning;
Huang Rui916910a2017-05-31 10:35:42 +0800610 uint64_t stolen_size;
Junwei Zhang8fe73322016-03-10 14:20:39 +0800611 /* apertures */
612 u64 shared_aperture_start;
613 u64 shared_aperture_end;
614 u64 private_aperture_start;
615 u64 private_aperture_end;
Alex Xiee60f8db2017-03-09 11:36:26 -0500616 /* protects concurrent invalidation */
617 spinlock_t invalidate_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400618};
619
620/*
621 * GPU doorbell structures, functions & helpers
622 */
623typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
624{
625 AMDGPU_DOORBELL_KIQ = 0x000,
626 AMDGPU_DOORBELL_HIQ = 0x001,
627 AMDGPU_DOORBELL_DIQ = 0x002,
628 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
629 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
630 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
631 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
632 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
633 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
634 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
635 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
636 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
637 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
638 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
639 AMDGPU_DOORBELL_IH = 0x1E8,
640 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
641 AMDGPU_DOORBELL_INVALID = 0xFFFF
642} AMDGPU_DOORBELL_ASSIGNMENT;
643
644struct amdgpu_doorbell {
645 /* doorbell mmio */
646 resource_size_t base;
647 resource_size_t size;
648 u32 __iomem *ptr;
649 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
650};
651
Ken Wang39807b92016-03-18 15:41:42 +0800652/*
653 * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
654 */
655typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
656{
657 /*
658 * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
659 * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
660 * Compute related doorbells are allocated from 0x00 to 0x8a
661 */
662
663
664 /* kernel scheduling */
665 AMDGPU_DOORBELL64_KIQ = 0x00,
666
667 /* HSA interface queue and debug queue */
668 AMDGPU_DOORBELL64_HIQ = 0x01,
669 AMDGPU_DOORBELL64_DIQ = 0x02,
670
671 /* Compute engines */
672 AMDGPU_DOORBELL64_MEC_RING0 = 0x03,
673 AMDGPU_DOORBELL64_MEC_RING1 = 0x04,
674 AMDGPU_DOORBELL64_MEC_RING2 = 0x05,
675 AMDGPU_DOORBELL64_MEC_RING3 = 0x06,
676 AMDGPU_DOORBELL64_MEC_RING4 = 0x07,
677 AMDGPU_DOORBELL64_MEC_RING5 = 0x08,
678 AMDGPU_DOORBELL64_MEC_RING6 = 0x09,
679 AMDGPU_DOORBELL64_MEC_RING7 = 0x0a,
680
681 /* User queue doorbell range (128 doorbells) */
682 AMDGPU_DOORBELL64_USERQUEUE_START = 0x0b,
683 AMDGPU_DOORBELL64_USERQUEUE_END = 0x8a,
684
685 /* Graphics engine */
686 AMDGPU_DOORBELL64_GFX_RING0 = 0x8b,
687
688 /*
689 * Other graphics doorbells can be allocated here: from 0x8c to 0xef
690 * Graphics voltage island aperture 1
691 * default non-graphics QWORD index is 0xF0 - 0xFF inclusive
692 */
693
694 /* sDMA engines */
695 AMDGPU_DOORBELL64_sDMA_ENGINE0 = 0xF0,
696 AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
697 AMDGPU_DOORBELL64_sDMA_ENGINE1 = 0xF2,
698 AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
699
700 /* Interrupt handler */
701 AMDGPU_DOORBELL64_IH = 0xF4, /* For legacy interrupt ring buffer */
702 AMDGPU_DOORBELL64_IH_RING1 = 0xF5, /* For page migration request log */
703 AMDGPU_DOORBELL64_IH_RING2 = 0xF6, /* For page migration translation/invalidation log */
704
Monk Liue6b3ecb2016-12-30 16:18:56 +0800705 /* VCN engine use 32 bits doorbell */
706 AMDGPU_DOORBELL64_VCN0_1 = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
707 AMDGPU_DOORBELL64_VCN2_3 = 0xF9,
708 AMDGPU_DOORBELL64_VCN4_5 = 0xFA,
709 AMDGPU_DOORBELL64_VCN6_7 = 0xFB,
710
711 /* overlap the doorbell assignment with VCN as they are mutually exclusive
712 * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
713 */
714 AMDGPU_DOORBELL64_RING0_1 = 0xF8,
715 AMDGPU_DOORBELL64_RING2_3 = 0xF9,
716 AMDGPU_DOORBELL64_RING4_5 = 0xFA,
717 AMDGPU_DOORBELL64_RING6_7 = 0xFB,
718
719 AMDGPU_DOORBELL64_UVD_RING0_1 = 0xFC,
720 AMDGPU_DOORBELL64_UVD_RING2_3 = 0xFD,
721 AMDGPU_DOORBELL64_UVD_RING4_5 = 0xFE,
722 AMDGPU_DOORBELL64_UVD_RING6_7 = 0xFF,
Ken Wang39807b92016-03-18 15:41:42 +0800723
724 AMDGPU_DOORBELL64_MAX_ASSIGNMENT = 0xFF,
725 AMDGPU_DOORBELL64_INVALID = 0xFFFF
726} AMDGPU_DOORBELL64_ASSIGNMENT;
727
728
Alex Deucher97b2e202015-04-20 16:51:00 -0400729void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
730 phys_addr_t *aperture_base,
731 size_t *aperture_size,
732 size_t *start_offset);
733
734/*
735 * IRQS.
736 */
737
738struct amdgpu_flip_work {
Michel Dänzer325cbba2016-08-04 12:39:37 +0900739 struct delayed_work flip_work;
Alex Deucher97b2e202015-04-20 16:51:00 -0400740 struct work_struct unpin_work;
741 struct amdgpu_device *adev;
742 int crtc_id;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900743 u32 target_vblank;
Alex Deucher97b2e202015-04-20 16:51:00 -0400744 uint64_t base;
745 struct drm_pending_vblank_event *event;
Christian König765e7fb2016-09-15 15:06:50 +0200746 struct amdgpu_bo *old_abo;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100747 struct dma_fence *excl;
Christian König1ffd2652015-08-11 17:29:52 +0200748 unsigned shared_count;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100749 struct dma_fence **shared;
750 struct dma_fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400751 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400752};
753
754
755/*
756 * CP & rings.
757 */
758
759struct amdgpu_ib {
760 struct amdgpu_sa_bo *sa_bo;
761 uint32_t length_dw;
762 uint64_t gpu_addr;
763 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800764 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400765};
766
Nils Wallménius62250a92016-04-10 16:30:00 +0200767extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800768
Christian König50838c82016-02-03 13:44:52 +0100769int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800770 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100771int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
772 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800773
Christian Königa5fb4ec2016-06-29 15:10:31 +0200774void amdgpu_job_free_resources(struct amdgpu_job *job);
Christian König50838c82016-02-03 13:44:52 +0100775void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100776int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100777 struct amd_sched_entity *entity, void *owner,
Chris Wilsonf54d1862016-10-25 13:00:45 +0100778 struct dma_fence **f);
Christian König8b4fb002015-11-15 16:04:16 +0100779
Alex Deucher97b2e202015-04-20 16:51:00 -0400780/*
Andres Rodriguezeffd9242017-02-16 00:47:32 -0500781 * Queue manager
782 */
783struct amdgpu_queue_mapper {
784 int hw_ip;
785 struct mutex lock;
786 /* protected by lock */
787 struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
788};
789
790struct amdgpu_queue_mgr {
791 struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
792};
793
794int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
795 struct amdgpu_queue_mgr *mgr);
796int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
797 struct amdgpu_queue_mgr *mgr);
798int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
799 struct amdgpu_queue_mgr *mgr,
800 int hw_ip, int instance, int ring,
801 struct amdgpu_ring **out_ring);
802
803/*
Alex Deucher97b2e202015-04-20 16:51:00 -0400804 * context related structures
805 */
806
Christian König21c16bf2015-07-07 17:24:49 +0200807struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200808 uint64_t sequence;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100809 struct dma_fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200810 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200811};
812
Alex Deucher97b2e202015-04-20 16:51:00 -0400813struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400814 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800815 struct amdgpu_device *adev;
Andres Rodriguezeffd9242017-02-16 00:47:32 -0500816 struct amdgpu_queue_mgr queue_mgr;
Alex Deucher0b492a42015-08-16 22:48:26 -0400817 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200818 spinlock_t ring_lock;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100819 struct dma_fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200820 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Monk Liu753ad492016-08-26 13:28:28 +0800821 bool preamble_presented;
Alex Deucher97b2e202015-04-20 16:51:00 -0400822};
823
824struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400825 struct amdgpu_device *adev;
826 struct mutex lock;
827 /* protected by lock */
828 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400829};
830
Alex Deucher0b492a42015-08-16 22:48:26 -0400831struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
832int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
833
Christian König21c16bf2015-07-07 17:24:49 +0200834uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Chris Wilsonf54d1862016-10-25 13:00:45 +0100835 struct dma_fence *fence);
836struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
Christian König21c16bf2015-07-07 17:24:49 +0200837 struct amdgpu_ring *ring, uint64_t seq);
838
Alex Deucher0b492a42015-08-16 22:48:26 -0400839int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
840 struct drm_file *filp);
841
Christian Königefd4ccb2015-08-04 16:20:31 +0200842void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
843void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400844
Alex Deucher97b2e202015-04-20 16:51:00 -0400845/*
846 * file private structure
847 */
848
849struct amdgpu_fpriv {
850 struct amdgpu_vm vm;
Junwei Zhangb85891b2017-01-16 13:59:01 +0800851 struct amdgpu_bo_va *prt_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400852 struct mutex bo_list_lock;
853 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -0400854 struct amdgpu_ctx_mgr ctx_mgr;
Chunming Zhouf1892132017-05-15 16:48:27 +0800855 u32 vram_lost_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400856};
857
858/*
859 * residency list
860 */
861
862struct amdgpu_bo_list {
863 struct mutex lock;
864 struct amdgpu_bo *gds_obj;
865 struct amdgpu_bo *gws_obj;
866 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +0100867 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400868 unsigned num_entries;
869 struct amdgpu_bo_list_entry *array;
870};
871
872struct amdgpu_bo_list *
873amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +0100874void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
875 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -0400876void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
877void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
878
879/*
880 * GFX stuff
881 */
882#include "clearstate_defs.h"
883
Alex Deucher79e54122016-04-08 15:45:13 -0400884struct amdgpu_rlc_funcs {
885 void (*enter_safe_mode)(struct amdgpu_device *adev);
886 void (*exit_safe_mode)(struct amdgpu_device *adev);
887};
888
Alex Deucher97b2e202015-04-20 16:51:00 -0400889struct amdgpu_rlc {
890 /* for power gating */
891 struct amdgpu_bo *save_restore_obj;
892 uint64_t save_restore_gpu_addr;
893 volatile uint32_t *sr_ptr;
894 const u32 *reg_list;
895 u32 reg_list_size;
896 /* for clear state */
897 struct amdgpu_bo *clear_state_obj;
898 uint64_t clear_state_gpu_addr;
899 volatile uint32_t *cs_ptr;
900 const struct cs_section_def *cs_data;
901 u32 clear_state_size;
902 /* for cp tables */
903 struct amdgpu_bo *cp_table_obj;
904 uint64_t cp_table_gpu_addr;
905 volatile uint32_t *cp_table_ptr;
906 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -0400907
908 /* safe mode for updating CG/PG state */
909 bool in_safe_mode;
910 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -0400911
912 /* for firmware data */
913 u32 save_and_restore_offset;
914 u32 clear_state_descriptor_offset;
915 u32 avail_scratch_ram_locations;
916 u32 reg_restore_list_size;
917 u32 reg_list_format_start;
918 u32 reg_list_format_separate_start;
919 u32 starting_offsets_start;
920 u32 reg_list_format_size_bytes;
921 u32 reg_list_size_bytes;
922
923 u32 *register_list_format;
924 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -0400925};
926
Andres Rodriguez78c16832017-02-02 00:38:22 -0500927#define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
928
Alex Deucher97b2e202015-04-20 16:51:00 -0400929struct amdgpu_mec {
930 struct amdgpu_bo *hpd_eop_obj;
931 u64 hpd_eop_gpu_addr;
Ken Wangb1023572017-03-03 17:59:39 -0500932 struct amdgpu_bo *mec_fw_obj;
933 u64 mec_fw_gpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400934 u32 num_mec;
Andres Rodriguez42794b22017-02-01 19:08:23 -0500935 u32 num_pipe_per_mec;
936 u32 num_queue_per_pipe;
Xiangliang Yu59a82d72017-02-17 16:03:10 +0800937 void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
Andres Rodriguez78c16832017-02-02 00:38:22 -0500938
939 /* These are the resources for which amdgpu takes ownership */
940 DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
Alex Deucher97b2e202015-04-20 16:51:00 -0400941};
942
Xiangliang Yu4e638ae2016-12-23 15:00:01 +0800943struct amdgpu_kiq {
944 u64 eop_gpu_addr;
945 struct amdgpu_bo *eop_obj;
Shaoyun Liucdf6adb2017-04-28 17:18:26 -0400946 struct mutex ring_mutex;
Xiangliang Yu4e638ae2016-12-23 15:00:01 +0800947 struct amdgpu_ring ring;
948 struct amdgpu_irq_src irq;
949};
950
Alex Deucher97b2e202015-04-20 16:51:00 -0400951/*
952 * GPU scratch registers structures, functions & helpers
953 */
954struct amdgpu_scratch {
955 unsigned num_reg;
956 uint32_t reg_base;
Nils Wallménius50261152017-01-16 21:56:48 +0100957 uint32_t free_mask;
Alex Deucher97b2e202015-04-20 16:51:00 -0400958};
959
960/*
961 * GFX configurations
962 */
Alex Deuchere3fa7632016-10-10 10:56:21 -0400963#define AMDGPU_GFX_MAX_SE 4
964#define AMDGPU_GFX_MAX_SH_PER_SE 2
965
966struct amdgpu_rb_config {
967 uint32_t rb_backend_disable;
968 uint32_t user_rb_backend_disable;
969 uint32_t raster_config;
970 uint32_t raster_config_1;
971};
972
Andrey Grodzovskyd0e95752016-12-12 13:40:37 -0500973struct gb_addr_config {
974 uint16_t pipe_interleave_size;
975 uint8_t num_pipes;
976 uint8_t max_compress_frags;
977 uint8_t num_banks;
978 uint8_t num_se;
979 uint8_t num_rb_per_se;
980};
981
Junwei Zhangea323f82017-02-21 10:32:37 +0800982struct amdgpu_gfx_config {
Alex Deucher97b2e202015-04-20 16:51:00 -0400983 unsigned max_shader_engines;
984 unsigned max_tile_pipes;
985 unsigned max_cu_per_sh;
986 unsigned max_sh_per_se;
987 unsigned max_backends_per_se;
988 unsigned max_texture_channel_caches;
989 unsigned max_gprs;
990 unsigned max_gs_threads;
991 unsigned max_hw_contexts;
992 unsigned sc_prim_fifo_size_frontend;
993 unsigned sc_prim_fifo_size_backend;
994 unsigned sc_hiz_tile_fifo_size;
995 unsigned sc_earlyz_tile_fifo_size;
996
997 unsigned num_tile_pipes;
998 unsigned backend_enable_mask;
999 unsigned mem_max_burst_length_bytes;
1000 unsigned mem_row_size_in_kb;
1001 unsigned shader_engine_tile_size;
1002 unsigned num_gpus;
1003 unsigned multi_gpu_tile_size;
1004 unsigned mc_arb_ramcfg;
1005 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001006 unsigned num_rbs;
Junwei Zhang408bfe72017-04-27 11:12:07 +08001007 unsigned gs_vgt_table_depth;
1008 unsigned gs_prim_buffer_depth;
Alex Deucher97b2e202015-04-20 16:51:00 -04001009
1010 uint32_t tile_mode_array[32];
1011 uint32_t macrotile_mode_array[16];
Alex Deuchere3fa7632016-10-10 10:56:21 -04001012
Andrey Grodzovskyd0e95752016-12-12 13:40:37 -05001013 struct gb_addr_config gb_addr_config_fields;
Alex Deuchere3fa7632016-10-10 10:56:21 -04001014 struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
Junwei Zhangdf6e2c42017-02-17 11:05:49 +08001015
1016 /* gfx configure feature */
1017 uint32_t double_offchip_lds_buf;
Alex Deucher97b2e202015-04-20 16:51:00 -04001018};
1019
Alex Deucher7dae69a2016-05-03 16:25:53 -04001020struct amdgpu_cu_info {
1021 uint32_t number; /* total active CU number */
1022 uint32_t ao_cu_mask;
Junwei Zhang408bfe72017-04-27 11:12:07 +08001023 uint32_t wave_front_size;
Alex Deucher7dae69a2016-05-03 16:25:53 -04001024 uint32_t bitmap[4][4];
1025};
1026
Alex Deucherb95e31f2016-07-07 15:01:42 -04001027struct amdgpu_gfx_funcs {
1028 /* get the gpu clock counter */
1029 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -04001030 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Tom St Denis472259f2016-10-14 09:49:09 -04001031 void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);
Tom St Denisc5a60ce2016-12-05 11:39:19 -05001032 void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t thread, uint32_t start, uint32_t size, uint32_t *dst);
1033 void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst);
Alex Deucherb95e31f2016-07-07 15:01:42 -04001034};
1035
Alex Deucherbce23e02017-03-28 12:52:08 -04001036struct amdgpu_ngg_buf {
1037 struct amdgpu_bo *bo;
1038 uint64_t gpu_addr;
1039 uint32_t size;
1040 uint32_t bo_size;
1041};
1042
1043enum {
Guenter Roeckaf8baf12017-05-03 23:49:18 -07001044 NGG_PRIM = 0,
1045 NGG_POS,
1046 NGG_CNTL,
1047 NGG_PARAM,
Alex Deucherbce23e02017-03-28 12:52:08 -04001048 NGG_BUF_MAX
1049};
1050
1051struct amdgpu_ngg {
1052 struct amdgpu_ngg_buf buf[NGG_BUF_MAX];
1053 uint32_t gds_reserve_addr;
1054 uint32_t gds_reserve_size;
1055 bool init;
1056};
1057
Alex Deucher97b2e202015-04-20 16:51:00 -04001058struct amdgpu_gfx {
1059 struct mutex gpu_clock_mutex;
Junwei Zhangea323f82017-02-21 10:32:37 +08001060 struct amdgpu_gfx_config config;
Alex Deucher97b2e202015-04-20 16:51:00 -04001061 struct amdgpu_rlc rlc;
1062 struct amdgpu_mec mec;
Xiangliang Yu4e638ae2016-12-23 15:00:01 +08001063 struct amdgpu_kiq kiq;
Alex Deucher97b2e202015-04-20 16:51:00 -04001064 struct amdgpu_scratch scratch;
1065 const struct firmware *me_fw; /* ME firmware */
1066 uint32_t me_fw_version;
1067 const struct firmware *pfp_fw; /* PFP firmware */
1068 uint32_t pfp_fw_version;
1069 const struct firmware *ce_fw; /* CE firmware */
1070 uint32_t ce_fw_version;
1071 const struct firmware *rlc_fw; /* RLC firmware */
1072 uint32_t rlc_fw_version;
1073 const struct firmware *mec_fw; /* MEC firmware */
1074 uint32_t mec_fw_version;
1075 const struct firmware *mec2_fw; /* MEC2 firmware */
1076 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001077 uint32_t me_feature_version;
1078 uint32_t ce_feature_version;
1079 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001080 uint32_t rlc_feature_version;
1081 uint32_t mec_feature_version;
1082 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001083 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1084 unsigned num_gfx_rings;
1085 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1086 unsigned num_compute_rings;
1087 struct amdgpu_irq_src eop_irq;
1088 struct amdgpu_irq_src priv_reg_irq;
1089 struct amdgpu_irq_src priv_inst_irq;
1090 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001091 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001092 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001093 unsigned ce_ram_size;
1094 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001095 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +08001096
1097 /* reset mask */
1098 uint32_t grbm_soft_reset;
1099 uint32_t srbm_soft_reset;
Monk Liu223049c2017-01-26 15:32:16 +08001100 bool in_reset;
David Panaritib4e40672017-03-28 12:57:31 -04001101 /* s3/s4 mask */
1102 bool in_suspend;
Alex Deucherbce23e02017-03-28 12:52:08 -04001103 /* NGG */
1104 struct amdgpu_ngg ngg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001105};
1106
Christian Königb07c60c2016-01-31 12:29:04 +01001107int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001108 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001109void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
Chris Wilsonf54d1862016-10-25 13:00:45 +01001110 struct dma_fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001111int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Junwei Zhang50ddc752017-01-23 16:30:38 +08001112 struct amdgpu_ib *ibs, struct amdgpu_job *job,
1113 struct dma_fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001114int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1115void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1116int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001117
1118/*
1119 * CS.
1120 */
1121struct amdgpu_cs_chunk {
1122 uint32_t chunk_id;
1123 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001124 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001125};
1126
1127struct amdgpu_cs_parser {
1128 struct amdgpu_device *adev;
1129 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001130 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001131
Alex Deucher97b2e202015-04-20 16:51:00 -04001132 /* chunks */
1133 unsigned nchunks;
1134 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001135
Christian König50838c82016-02-03 13:44:52 +01001136 /* scheduler job object */
1137 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001138
Christian Königc3cca412015-12-15 14:41:33 +01001139 /* buffer objects */
1140 struct ww_acquire_ctx ticket;
1141 struct amdgpu_bo_list *bo_list;
1142 struct amdgpu_bo_list_entry vm_pd;
1143 struct list_head validated;
Chris Wilsonf54d1862016-10-25 13:00:45 +01001144 struct dma_fence *fence;
Christian Königc3cca412015-12-15 14:41:33 +01001145 uint64_t bytes_moved_threshold;
1146 uint64_t bytes_moved;
Christian König662bfa62016-09-01 12:13:18 +02001147 struct amdgpu_bo_list_entry *evictable;
Alex Deucher97b2e202015-04-20 16:51:00 -04001148
1149 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001150 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001151};
1152
Monk Liu753ad492016-08-26 13:28:28 +08001153#define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */
1154#define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1155#define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */
1156
Chunming Zhoubb977d32015-08-18 15:16:40 +08001157struct amdgpu_job {
1158 struct amd_sched_job base;
1159 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001160 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001161 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001162 struct amdgpu_sync sync;
Chunming Zhoua340c7b2017-05-18 15:19:03 +08001163 struct amdgpu_sync dep_sync;
Chunming Zhoudf83d1e2017-05-09 15:50:22 +08001164 struct amdgpu_sync sched_sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001165 struct amdgpu_ib *ibs;
Chris Wilsonf54d1862016-10-25 13:00:45 +01001166 struct dma_fence *fence; /* the hw fence */
Monk Liu753ad492016-08-26 13:28:28 +08001167 uint32_t preamble_status;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001168 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001169 void *owner;
Monk Liu3aecd242016-08-25 15:40:48 +08001170 uint64_t fence_ctx; /* the fence_context this job uses */
Chunming Zhoufd53be32016-07-01 17:59:01 +08001171 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +02001172 unsigned vm_id;
1173 uint64_t vm_pd_addr;
1174 uint32_t gds_base, gds_size;
1175 uint32_t gws_base, gws_size;
1176 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001177
1178 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +02001179 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +02001180 uint64_t uf_sequence;
1181
Chunming Zhoubb977d32015-08-18 15:16:40 +08001182};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001183#define to_amdgpu_job(sched_job) \
1184 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001185
Christian König7270f832016-01-31 11:00:41 +01001186static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1187 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001188{
Christian König50838c82016-02-03 13:44:52 +01001189 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001190}
1191
Christian König7270f832016-01-31 11:00:41 +01001192static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1193 uint32_t ib_idx, int idx,
1194 uint32_t value)
1195{
Christian König50838c82016-02-03 13:44:52 +01001196 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001197}
1198
Alex Deucher97b2e202015-04-20 16:51:00 -04001199/*
1200 * Writeback
1201 */
1202#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1203
1204struct amdgpu_wb {
1205 struct amdgpu_bo *wb_obj;
1206 volatile uint32_t *wb;
1207 uint64_t gpu_addr;
1208 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1209 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1210};
1211
1212int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1213void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
Ken Wang70142852016-03-18 15:08:49 +08001214int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);
1215void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);
Alex Deucher97b2e202015-04-20 16:51:00 -04001216
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001217void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1218
Alex Deucher97b2e202015-04-20 16:51:00 -04001219/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001220 * SDMA
1221 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001222struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001223 /* SDMA firmware */
1224 const struct firmware *fw;
1225 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001226 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001227
1228 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001229 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001230};
1231
Alex Deucherc113ea12015-10-08 16:30:37 -04001232struct amdgpu_sdma {
1233 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
Ken Wang30d15742016-01-19 14:05:23 +08001234#ifdef CONFIG_DRM_AMDGPU_SI
1235 //SI DMA has a difference trap irq number for the second engine
1236 struct amdgpu_irq_src trap_irq_1;
1237#endif
Alex Deucherc113ea12015-10-08 16:30:37 -04001238 struct amdgpu_irq_src trap_irq;
1239 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001240 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001241 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001242};
1243
Alex Deucher97b2e202015-04-20 16:51:00 -04001244/*
1245 * Firmware
1246 */
Huang Ruie635ee02016-11-01 15:35:38 +08001247enum amdgpu_firmware_load_type {
1248 AMDGPU_FW_LOAD_DIRECT = 0,
1249 AMDGPU_FW_LOAD_SMU,
1250 AMDGPU_FW_LOAD_PSP,
1251};
1252
Alex Deucher97b2e202015-04-20 16:51:00 -04001253struct amdgpu_firmware {
1254 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
Huang Ruie635ee02016-11-01 15:35:38 +08001255 enum amdgpu_firmware_load_type load_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001256 struct amdgpu_bo *fw_buf;
1257 unsigned int fw_size;
Huang Rui2445b222017-03-03 16:20:35 -05001258 unsigned int max_ucodes;
Huang Rui0e5ca0d2017-03-03 18:37:23 -05001259 /* firmwares are loaded by psp instead of smu from vega10 */
1260 const struct amdgpu_psp_funcs *funcs;
1261 struct amdgpu_bo *rbuf;
1262 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001263};
1264
1265/*
1266 * Benchmarking
1267 */
1268void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1269
1270
1271/*
1272 * Testing
1273 */
1274void amdgpu_test_moves(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001275
1276/*
1277 * MMU Notifier
1278 */
1279#if defined(CONFIG_MMU_NOTIFIER)
1280int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1281void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1282#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001283static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001284{
1285 return -ENODEV;
1286}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001287static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001288#endif
1289
1290/*
1291 * Debugfs
1292 */
1293struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001294 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001295 unsigned num_files;
1296};
1297
1298int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001299 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001300 unsigned nfiles);
1301int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1302
1303#if defined(CONFIG_DEBUG_FS)
1304int amdgpu_debugfs_init(struct drm_minor *minor);
Alex Deucher97b2e202015-04-20 16:51:00 -04001305#endif
1306
Huang Rui50ab2532016-06-12 15:51:09 +08001307int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1308
Alex Deucher97b2e202015-04-20 16:51:00 -04001309/*
1310 * amdgpu smumgr functions
1311 */
1312struct amdgpu_smumgr_funcs {
1313 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1314 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1315 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1316};
1317
1318/*
1319 * amdgpu smumgr
1320 */
1321struct amdgpu_smumgr {
1322 struct amdgpu_bo *toc_buf;
1323 struct amdgpu_bo *smu_buf;
1324 /* asic priv smu data */
1325 void *priv;
1326 spinlock_t smu_lock;
1327 /* smumgr functions */
1328 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1329 /* ucode loading complete flag */
1330 uint32_t fw_flags;
1331};
1332
1333/*
1334 * ASIC specific register table accessible by UMD
1335 */
1336struct amdgpu_allowed_register_entry {
1337 uint32_t reg_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001338 bool grbm_indexed;
1339};
1340
Alex Deucher97b2e202015-04-20 16:51:00 -04001341/*
1342 * ASIC specific functions.
1343 */
1344struct amdgpu_asic_funcs {
1345 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001346 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1347 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001348 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1349 u32 sh_num, u32 reg_offset, u32 *value);
1350 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1351 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001352 /* get the reference clock */
1353 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001354 /* MM block clocks */
1355 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1356 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Maruthi Bayyavarapu841686d2016-08-01 12:42:32 -04001357 /* static power management */
1358 int (*get_pcie_lanes)(struct amdgpu_device *adev);
1359 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
Alex Deucherbbf282d2017-03-03 17:26:10 -05001360 /* get config memsize register */
1361 u32 (*get_config_memsize)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001362};
1363
1364/*
1365 * IOCTL.
1366 */
1367int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1368 struct drm_file *filp);
1369int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1370 struct drm_file *filp);
1371
1372int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1373 struct drm_file *filp);
1374int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1375 struct drm_file *filp);
1376int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1377 struct drm_file *filp);
1378int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1379 struct drm_file *filp);
1380int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1381 struct drm_file *filp);
1382int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1383 struct drm_file *filp);
1384int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1385int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
Junwei Zhangeef18a82016-11-04 16:16:10 -04001386int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
1387 struct drm_file *filp);
Alex Deucher97b2e202015-04-20 16:51:00 -04001388
1389int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1390 struct drm_file *filp);
1391
1392/* VRAM scratch page for HDP bug, default vram page */
1393struct amdgpu_vram_scratch {
1394 struct amdgpu_bo *robj;
1395 volatile uint32_t *ptr;
1396 u64 gpu_addr;
1397};
1398
1399/*
1400 * ACPI
1401 */
1402struct amdgpu_atif_notification_cfg {
1403 bool enabled;
1404 int command_code;
1405};
1406
1407struct amdgpu_atif_notifications {
1408 bool display_switch;
1409 bool expansion_mode_change;
1410 bool thermal_state;
1411 bool forced_power_state;
1412 bool system_power_state;
1413 bool display_conf_change;
1414 bool px_gfx_switch;
1415 bool brightness_change;
1416 bool dgpu_display_event;
1417};
1418
1419struct amdgpu_atif_functions {
1420 bool system_params;
1421 bool sbios_requests;
1422 bool select_active_disp;
1423 bool lid_state;
1424 bool get_tv_standard;
1425 bool set_tv_standard;
1426 bool get_panel_expansion_mode;
1427 bool set_panel_expansion_mode;
1428 bool temperature_change;
1429 bool graphics_device_types;
1430};
1431
1432struct amdgpu_atif {
1433 struct amdgpu_atif_notifications notifications;
1434 struct amdgpu_atif_functions functions;
1435 struct amdgpu_atif_notification_cfg notification_cfg;
1436 struct amdgpu_encoder *encoder_for_bl;
1437};
1438
1439struct amdgpu_atcs_functions {
1440 bool get_ext_state;
1441 bool pcie_perf_req;
1442 bool pcie_dev_rdy;
1443 bool pcie_bus_width;
1444};
1445
1446struct amdgpu_atcs {
1447 struct amdgpu_atcs_functions functions;
1448};
1449
Alex Deucher97b2e202015-04-20 16:51:00 -04001450/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001451 * CGS
1452 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001453struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1454void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001455
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001456/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001457 * Core structure, functions and helpers.
1458 */
1459typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1460typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1461
1462typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1463typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1464
Chunming Zhou0c49e0b2017-05-15 14:20:00 +08001465#define AMDGPU_RESET_MAGIC_NUM 64
Alex Deucher97b2e202015-04-20 16:51:00 -04001466struct amdgpu_device {
1467 struct device *dev;
1468 struct drm_device *ddev;
1469 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001470
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001471#ifdef CONFIG_DRM_AMD_ACP
1472 struct amdgpu_acp acp;
1473#endif
1474
Alex Deucher97b2e202015-04-20 16:51:00 -04001475 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001476 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001477 uint32_t family;
1478 uint32_t rev_id;
1479 uint32_t external_rev_id;
1480 unsigned long flags;
1481 int usec_timeout;
1482 const struct amdgpu_asic_funcs *asic_funcs;
1483 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001484 bool need_dma32;
1485 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001486 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001487 struct notifier_block acpi_nb;
1488 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1489 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001490 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001491#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001492 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001493#endif
1494 struct amdgpu_atif atif;
1495 struct amdgpu_atcs atcs;
1496 struct mutex srbm_mutex;
1497 /* GRBM index mutex. Protects concurrent access to GRBM index */
1498 struct mutex grbm_idx_mutex;
1499 struct dev_pm_domain vga_pm_domain;
1500 bool have_disp_power_ref;
1501
1502 /* BIOS */
Alex Deucher0cdd5002017-02-13 16:01:58 -05001503 bool is_atom_fw;
Alex Deucher97b2e202015-04-20 16:51:00 -04001504 uint8_t *bios;
Evan Quana9f5db92016-12-07 09:56:46 +08001505 uint32_t bios_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001506 struct amdgpu_bo *stollen_vga_memory;
Alex Deuchera5bde2f2016-09-23 16:23:41 -04001507 uint32_t bios_scratch_reg_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001508 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1509
1510 /* Register/doorbell mmio */
1511 resource_size_t rmmio_base;
1512 resource_size_t rmmio_size;
1513 void __iomem *rmmio;
1514 /* protects concurrent MM_INDEX/DATA based register access */
1515 spinlock_t mmio_idx_lock;
1516 /* protects concurrent SMC based register access */
1517 spinlock_t smc_idx_lock;
1518 amdgpu_rreg_t smc_rreg;
1519 amdgpu_wreg_t smc_wreg;
1520 /* protects concurrent PCIE register access */
1521 spinlock_t pcie_idx_lock;
1522 amdgpu_rreg_t pcie_rreg;
1523 amdgpu_wreg_t pcie_wreg;
Huang Rui36b9a952016-08-31 13:23:25 +08001524 amdgpu_rreg_t pciep_rreg;
1525 amdgpu_wreg_t pciep_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001526 /* protects concurrent UVD register access */
1527 spinlock_t uvd_ctx_idx_lock;
1528 amdgpu_rreg_t uvd_ctx_rreg;
1529 amdgpu_wreg_t uvd_ctx_wreg;
1530 /* protects concurrent DIDT register access */
1531 spinlock_t didt_idx_lock;
1532 amdgpu_rreg_t didt_rreg;
1533 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08001534 /* protects concurrent gc_cac register access */
1535 spinlock_t gc_cac_idx_lock;
1536 amdgpu_rreg_t gc_cac_rreg;
1537 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001538 /* protects concurrent ENDPOINT (audio) register access */
1539 spinlock_t audio_endpt_idx_lock;
1540 amdgpu_block_rreg_t audio_endpt_rreg;
1541 amdgpu_block_wreg_t audio_endpt_wreg;
1542 void __iomem *rio_mem;
1543 resource_size_t rio_mem_size;
1544 struct amdgpu_doorbell doorbell;
1545
1546 /* clock/pll info */
1547 struct amdgpu_clock clock;
1548
1549 /* MC */
1550 struct amdgpu_mc mc;
1551 struct amdgpu_gart gart;
1552 struct amdgpu_dummy_page dummy_page;
1553 struct amdgpu_vm_manager vm_manager;
Alex Xiee60f8db2017-03-09 11:36:26 -05001554 struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001555
1556 /* memory management */
1557 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04001558 struct amdgpu_vram_scratch vram_scratch;
1559 struct amdgpu_wb wb;
1560 atomic64_t vram_usage;
1561 atomic64_t vram_vis_usage;
1562 atomic64_t gtt_usage;
1563 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02001564 atomic64_t num_evictions;
Marek Olšák68e2c5f2017-05-17 20:05:08 +02001565 atomic64_t num_vram_cpu_page_faults;
Marek Olšákd94aed52015-05-05 21:13:49 +02001566 atomic_t gpu_reset_counter;
Chunming Zhouf1892132017-05-15 16:48:27 +08001567 atomic_t vram_lost_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04001568
Marek Olšák95844d22016-08-17 23:49:27 +02001569 /* data for buffer migration throttling */
1570 struct {
1571 spinlock_t lock;
1572 s64 last_update_us;
1573 s64 accum_us; /* accumulated microseconds */
1574 u32 log2_max_MBps;
1575 } mm_stats;
1576
Alex Deucher97b2e202015-04-20 16:51:00 -04001577 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08001578 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04001579 struct amdgpu_mode_info mode_info;
1580 struct work_struct hotplug_work;
1581 struct amdgpu_irq_src crtc_irq;
1582 struct amdgpu_irq_src pageflip_irq;
1583 struct amdgpu_irq_src hpd_irq;
1584
1585 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02001586 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04001587 unsigned num_rings;
1588 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1589 bool ib_pool_ready;
1590 struct amdgpu_sa_manager ring_tmp_bo;
1591
1592 /* interrupts */
1593 struct amdgpu_irq irq;
1594
Alex Deucher1f7371b2015-12-02 17:46:21 -05001595 /* powerplay */
1596 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05001597 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05001598 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05001599
Alex Deucher97b2e202015-04-20 16:51:00 -04001600 /* dpm */
1601 struct amdgpu_pm pm;
1602 u32 cg_flags;
1603 u32 pg_flags;
1604
1605 /* amdgpu smumgr */
1606 struct amdgpu_smumgr smu;
1607
1608 /* gfx */
1609 struct amdgpu_gfx gfx;
1610
1611 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04001612 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04001613
Leo Liu95d09062016-12-21 13:21:52 -05001614 union {
1615 struct {
1616 /* uvd */
1617 struct amdgpu_uvd uvd;
Alex Deucher97b2e202015-04-20 16:51:00 -04001618
Leo Liu95d09062016-12-21 13:21:52 -05001619 /* vce */
1620 struct amdgpu_vce vce;
1621 };
1622
1623 /* vcn */
1624 struct amdgpu_vcn vcn;
1625 };
Alex Deucher97b2e202015-04-20 16:51:00 -04001626
1627 /* firmwares */
1628 struct amdgpu_firmware firmware;
1629
Huang Rui0e5ca0d2017-03-03 18:37:23 -05001630 /* PSP */
1631 struct psp_context psp;
1632
Alex Deucher97b2e202015-04-20 16:51:00 -04001633 /* GDS */
1634 struct amdgpu_gds gds;
1635
Alex Deuchera1255102016-10-13 17:41:13 -04001636 struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM];
Alex Deucher97b2e202015-04-20 16:51:00 -04001637 int num_ip_blocks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001638 struct mutex mn_lock;
1639 DECLARE_HASHTABLE(mn_hash, 7);
1640
1641 /* tracking pinned memory */
1642 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08001643 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001644 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03001645
1646 /* amdkfd interface */
1647 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08001648
Shirish S2dc80b02017-05-25 10:05:25 +05301649 /* delayed work_func for deferring clockgating during resume */
1650 struct delayed_work late_init_work;
1651
Xiangliang Yu5a5099c2017-01-09 18:06:57 -05001652 struct amdgpu_virt virt;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +08001653
1654 /* link all shadow bo */
1655 struct list_head shadow_list;
1656 struct mutex shadow_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08001657 /* link all gtt */
1658 spinlock_t gtt_list_lock;
1659 struct list_head gtt_list;
Andres Rodriguez795f2812017-03-06 16:27:55 -05001660 /* keep an lru list of rings by HW IP */
1661 struct list_head ring_lru_list;
1662 spinlock_t ring_lru_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08001663
Jim Quc836fec2017-02-10 15:59:59 +08001664 /* record hw reset is performed */
1665 bool has_hw_reset;
Chunming Zhou0c49e0b2017-05-15 14:20:00 +08001666 u8 reset_magic[AMDGPU_RESET_MAGIC_NUM];
Jim Quc836fec2017-02-10 15:59:59 +08001667
Alex Deucher97b2e202015-04-20 16:51:00 -04001668};
1669
Christian Königa7d64de2016-09-15 14:58:48 +02001670static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1671{
1672 return container_of(bdev, struct amdgpu_device, mman.bdev);
1673}
1674
Alex Deucher97b2e202015-04-20 16:51:00 -04001675bool amdgpu_device_is_px(struct drm_device *dev);
1676int amdgpu_device_init(struct amdgpu_device *adev,
1677 struct drm_device *ddev,
1678 struct pci_dev *pdev,
1679 uint32_t flags);
1680void amdgpu_device_fini(struct amdgpu_device *adev);
1681int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1682
1683uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
Monk Liu15d72fd2017-01-25 15:07:40 +08001684 uint32_t acc_flags);
Alex Deucher97b2e202015-04-20 16:51:00 -04001685void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
Monk Liu15d72fd2017-01-25 15:07:40 +08001686 uint32_t acc_flags);
Alex Deucher97b2e202015-04-20 16:51:00 -04001687u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1688void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1689
1690u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1691void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
Ken Wang832be402016-03-18 15:23:08 +08001692u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1693void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
Alex Deucher97b2e202015-04-20 16:51:00 -04001694
1695/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001696 * Registers read & write functions.
1697 */
Monk Liu15d72fd2017-01-25 15:07:40 +08001698
1699#define AMDGPU_REGS_IDX (1<<0)
1700#define AMDGPU_REGS_NO_KIQ (1<<1)
1701
1702#define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
1703#define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
1704
1705#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
1706#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
1707#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
1708#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
1709#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
Alex Deucher97b2e202015-04-20 16:51:00 -04001710#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1711#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1712#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1713#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
Huang Rui36b9a952016-08-31 13:23:25 +08001714#define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
1715#define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001716#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
1717#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
1718#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
1719#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
1720#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
1721#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08001722#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1723#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001724#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
1725#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
1726#define WREG32_P(reg, val, mask) \
1727 do { \
1728 uint32_t tmp_ = RREG32(reg); \
1729 tmp_ &= (mask); \
1730 tmp_ |= ((val) & ~(mask)); \
1731 WREG32(reg, tmp_); \
1732 } while (0)
1733#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1734#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1735#define WREG32_PLL_P(reg, val, mask) \
1736 do { \
1737 uint32_t tmp_ = RREG32_PLL(reg); \
1738 tmp_ &= (mask); \
1739 tmp_ |= ((val) & ~(mask)); \
1740 WREG32_PLL(reg, tmp_); \
1741 } while (0)
1742#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
1743#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1744#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1745
1746#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
1747#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
Ken Wang832be402016-03-18 15:23:08 +08001748#define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1749#define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001750
1751#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1752#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1753
1754#define REG_SET_FIELD(orig_val, reg, field, field_val) \
1755 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
1756 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1757
1758#define REG_GET_FIELD(value, reg, field) \
1759 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1760
Tom St Denis61cb8ce2016-08-09 10:13:21 -04001761#define WREG32_FIELD(reg, field, val) \
1762 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1763
Tom St Denisccaf3572017-04-04 09:14:13 -04001764#define WREG32_FIELD_OFFSET(reg, offset, field, val) \
1765 WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1766
Alex Deucher97b2e202015-04-20 16:51:00 -04001767/*
1768 * BIOS helpers.
1769 */
1770#define RBIOS8(i) (adev->bios[i])
1771#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1772#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1773
1774/*
1775 * RING helpers.
1776 */
1777static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
1778{
1779 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08001780 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Ken Wang536fbf92016-03-12 09:32:30 +08001781 ring->ring[ring->wptr++ & ring->buf_mask] = v;
Alex Deucher97b2e202015-04-20 16:51:00 -04001782 ring->wptr &= ring->ptr_mask;
1783 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04001784}
1785
Monk Liu0a8e1472017-01-17 10:52:33 +08001786static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *src, int count_dw)
1787{
1788 unsigned occupied, chunk1, chunk2;
1789 void *dst;
1790
Nikola Pajkovsky5b9c58f2017-05-04 12:39:50 -04001791 if (unlikely(ring->count_dw < count_dw)) {
Monk Liu0a8e1472017-01-17 10:52:33 +08001792 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Nikola Pajkovsky5b9c58f2017-05-04 12:39:50 -04001793 return;
Monk Liu0a8e1472017-01-17 10:52:33 +08001794 }
Nikola Pajkovsky5b9c58f2017-05-04 12:39:50 -04001795
1796 occupied = ring->wptr & ring->buf_mask;
1797 dst = (void *)&ring->ring[occupied];
1798 chunk1 = ring->buf_mask + 1 - occupied;
1799 chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
1800 chunk2 = count_dw - chunk1;
1801 chunk1 <<= 2;
1802 chunk2 <<= 2;
1803
1804 if (chunk1)
1805 memcpy(dst, src, chunk1);
1806
1807 if (chunk2) {
1808 src += chunk1;
1809 dst = (void *)ring->ring;
1810 memcpy(dst, src, chunk2);
1811 }
1812
1813 ring->wptr += count_dw;
1814 ring->wptr &= ring->ptr_mask;
1815 ring->count_dw -= count_dw;
Monk Liu0a8e1472017-01-17 10:52:33 +08001816}
1817
Alex Deucherc113ea12015-10-08 16:30:37 -04001818static inline struct amdgpu_sdma_instance *
1819amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001820{
1821 struct amdgpu_device *adev = ring->adev;
1822 int i;
1823
Alex Deucherc113ea12015-10-08 16:30:37 -04001824 for (i = 0; i < adev->sdma.num_instances; i++)
1825 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001826 break;
1827
1828 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04001829 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001830 else
1831 return NULL;
1832}
1833
Andres Rodriguez7b2124a2017-04-06 00:10:53 -04001834static inline int amdgpu_queue_to_bit(struct amdgpu_device *adev,
1835 int mec, int pipe, int queue)
Andres Rodrigueze33fec42017-02-03 17:31:38 -05001836{
1837 int bit = 0;
1838
1839 bit += mec * adev->gfx.mec.num_pipe_per_mec
1840 * adev->gfx.mec.num_queue_per_pipe;
1841 bit += pipe * adev->gfx.mec.num_queue_per_pipe;
1842 bit += queue;
1843
Andres Rodriguez7b2124a2017-04-06 00:10:53 -04001844 return bit;
1845}
1846
1847static inline void amdgpu_bit_to_queue(struct amdgpu_device *adev, int bit,
1848 int *mec, int *pipe, int *queue)
1849{
1850 *queue = bit % adev->gfx.mec.num_queue_per_pipe;
1851 *pipe = (bit / adev->gfx.mec.num_queue_per_pipe)
1852 % adev->gfx.mec.num_pipe_per_mec;
1853 *mec = (bit / adev->gfx.mec.num_queue_per_pipe)
1854 / adev->gfx.mec.num_pipe_per_mec;
1855
1856}
1857static inline bool amdgpu_is_mec_queue_enabled(struct amdgpu_device *adev,
1858 int mec, int pipe, int queue)
1859{
1860 return test_bit(amdgpu_queue_to_bit(adev, mec, pipe, queue),
1861 adev->gfx.mec.queue_bitmap);
Andres Rodrigueze33fec42017-02-03 17:31:38 -05001862}
1863
Alex Deucher97b2e202015-04-20 16:51:00 -04001864/*
1865 * ASICs macro.
1866 */
1867#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1868#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001869#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1870#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1871#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 -04001872#define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1873#define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1874#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001875#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05001876#define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
Alex Deucher97b2e202015-04-20 16:51:00 -04001877#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
Alex Deucherbbf282d2017-03-03 17:26:10 -05001878#define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001879#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
1880#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
Christian Königb1166322017-05-12 15:39:39 +02001881#define amdgpu_gart_get_vm_pde(adev, addr) (adev)->gart.gart_funcs->get_vm_pde((adev), (addr))
Alex Deucher97b2e202015-04-20 16:51:00 -04001882#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 +02001883#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 -04001884#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 Xie54635452017-02-14 12:22:57 -05001885#define amdgpu_vm_get_pte_flags(adev, flags) (adev)->gart.gart_funcs->get_vm_pte_flags((adev),(flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04001886#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
1887#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02001888#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04001889#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
1890#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
1891#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02001892#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 +01001893#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04001894#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08001895#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04001896#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 +02001897#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08001898#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Monk Liuc2167a62016-08-26 14:12:37 +08001899#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
Monk Liu753ad492016-08-26 13:28:28 +08001900#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
Xiangliang Yub6091c12017-01-10 12:53:52 +08001901#define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
1902#define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
Monk Liu3b4d68e2017-05-01 18:09:22 +08001903#define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
Christian König9e5d53092016-01-31 12:20:55 +01001904#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08001905#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
1906#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04001907#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
1908#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
1909#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
1910#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
1911#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
1912#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
Alex Deucher97b2e202015-04-20 16:51:00 -04001913#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
1914#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
1915#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
1916#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
1917#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
1918#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04001919#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 -04001920#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
1921#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
1922#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))
1923#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
1924#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08001925#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 +08001926#define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
Alex Deucherb95e31f2016-07-07 15:01:42 -04001927#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04001928#define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
Alex Deucher97b2e202015-04-20 16:51:00 -04001929#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
Huang Rui0e5ca0d2017-03-03 18:37:23 -05001930#define amdgpu_psp_check_fw_loading_status(adev, i) (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
Alex Deucher97b2e202015-04-20 16:51:00 -04001931
1932/* Common functions */
1933int amdgpu_gpu_reset(struct amdgpu_device *adev);
Chunming Zhou3ad81f12016-08-05 17:30:17 +08001934bool amdgpu_need_backup(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001935void amdgpu_pci_config_reset(struct amdgpu_device *adev);
Jim Quc836fec2017-02-10 15:59:59 +08001936bool amdgpu_need_post(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001937void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08001938
Alex Deucher97b2e202015-04-20 16:51:00 -04001939int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
Samuel Pitoisetfad06122017-02-09 11:33:37 +01001940void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes);
Christian König765e7fb2016-09-15 15:06:50 +02001941void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
Alex Deucher97b2e202015-04-20 16:51:00 -04001942bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01001943int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04001944int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
1945 uint32_t flags);
1946bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01001947struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01001948bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
1949 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01001950bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
1951 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001952bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
Chunming Zhou6b777602016-09-21 16:19:19 +08001953uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001954 struct ttm_mem_reg *mem);
1955void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
1956void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
1957void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Baoyou Xie9f31a0b02016-09-15 21:43:26 +08001958int amdgpu_ttm_init(struct amdgpu_device *adev);
1959void amdgpu_ttm_fini(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001960void amdgpu_program_register_sequence(struct amdgpu_device *adev,
1961 const u32 *registers,
1962 const u32 array_size);
1963
1964bool amdgpu_device_is_px(struct drm_device *dev);
1965/* atpx handler */
1966#if defined(CONFIG_VGA_SWITCHEROO)
1967void amdgpu_register_atpx_handler(void);
1968void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04001969bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04001970bool amdgpu_is_atpx_hybrid(void);
Alex Deucherefc83cf2016-09-14 14:01:41 -04001971bool amdgpu_atpx_dgpu_req_power_for_displays(void);
Alex Xie714f88e2017-04-05 11:07:13 -04001972bool amdgpu_has_atpx(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04001973#else
1974static inline void amdgpu_register_atpx_handler(void) {}
1975static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04001976static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04001977static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucherefc83cf2016-09-14 14:01:41 -04001978static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
Alex Xie714f88e2017-04-05 11:07:13 -04001979static inline bool amdgpu_has_atpx(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04001980#endif
1981
1982/*
1983 * KMS
1984 */
1985extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02001986extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04001987
Chunming Zhouf1892132017-05-15 16:48:27 +08001988bool amdgpu_kms_vram_lost(struct amdgpu_device *adev,
1989 struct amdgpu_fpriv *fpriv);
Alex Deucher97b2e202015-04-20 16:51:00 -04001990int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
Gabriel Krisman Bertazi11b3c202017-01-06 15:57:31 -02001991void amdgpu_driver_unload_kms(struct drm_device *dev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001992void amdgpu_driver_lastclose_kms(struct drm_device *dev);
1993int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
1994void amdgpu_driver_postclose_kms(struct drm_device *dev,
1995 struct drm_file *file_priv);
Alex Deucherfaefba92016-12-06 10:38:29 -05001996int amdgpu_suspend(struct amdgpu_device *adev);
Alex Deucher810ddc32016-08-23 13:25:49 -04001997int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1998int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02001999u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2000int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2001void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
Alex Deucher97b2e202015-04-20 16:51:00 -04002002long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2003 unsigned long arg);
2004
2005/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002006 * functions used by amdgpu_encoder.c
2007 */
2008struct amdgpu_afmt_acr {
2009 u32 clock;
2010
2011 int n_32khz;
2012 int cts_32khz;
2013
2014 int n_44_1khz;
2015 int cts_44_1khz;
2016
2017 int n_48khz;
2018 int cts_48khz;
2019
2020};
2021
2022struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2023
2024/* amdgpu_acpi.c */
2025#if defined(CONFIG_ACPI)
2026int amdgpu_acpi_init(struct amdgpu_device *adev);
2027void amdgpu_acpi_fini(struct amdgpu_device *adev);
2028bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2029int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2030 u8 perf_req, bool advertise);
2031int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2032#else
2033static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2034static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2035#endif
2036
2037struct amdgpu_bo_va_mapping *
2038amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2039 uint64_t addr, struct amdgpu_bo **bo);
Christian Königc855e252016-09-05 17:00:57 +02002040int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
Alex Deucher97b2e202015-04-20 16:51:00 -04002041
2042#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002043#endif