blob: 96cbe028d537cb31e06b8d57c1aa41385bce0a98 [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;
Junwei Zhang8fe73322016-03-10 14:20:39 +0800610 /* apertures */
611 u64 shared_aperture_start;
612 u64 shared_aperture_end;
613 u64 private_aperture_start;
614 u64 private_aperture_end;
Alex Xiee60f8db2017-03-09 11:36:26 -0500615 /* protects concurrent invalidation */
616 spinlock_t invalidate_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -0400617};
618
619/*
620 * GPU doorbell structures, functions & helpers
621 */
622typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
623{
624 AMDGPU_DOORBELL_KIQ = 0x000,
625 AMDGPU_DOORBELL_HIQ = 0x001,
626 AMDGPU_DOORBELL_DIQ = 0x002,
627 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
628 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
629 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
630 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
631 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
632 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
633 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
634 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
635 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
636 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
637 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
638 AMDGPU_DOORBELL_IH = 0x1E8,
639 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
640 AMDGPU_DOORBELL_INVALID = 0xFFFF
641} AMDGPU_DOORBELL_ASSIGNMENT;
642
643struct amdgpu_doorbell {
644 /* doorbell mmio */
645 resource_size_t base;
646 resource_size_t size;
647 u32 __iomem *ptr;
648 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
649};
650
Ken Wang39807b92016-03-18 15:41:42 +0800651/*
652 * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
653 */
654typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
655{
656 /*
657 * All compute related doorbells: kiq, hiq, diq, traditional compute queue, user queue, should locate in
658 * a continues range so that programming CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
659 * Compute related doorbells are allocated from 0x00 to 0x8a
660 */
661
662
663 /* kernel scheduling */
664 AMDGPU_DOORBELL64_KIQ = 0x00,
665
666 /* HSA interface queue and debug queue */
667 AMDGPU_DOORBELL64_HIQ = 0x01,
668 AMDGPU_DOORBELL64_DIQ = 0x02,
669
670 /* Compute engines */
671 AMDGPU_DOORBELL64_MEC_RING0 = 0x03,
672 AMDGPU_DOORBELL64_MEC_RING1 = 0x04,
673 AMDGPU_DOORBELL64_MEC_RING2 = 0x05,
674 AMDGPU_DOORBELL64_MEC_RING3 = 0x06,
675 AMDGPU_DOORBELL64_MEC_RING4 = 0x07,
676 AMDGPU_DOORBELL64_MEC_RING5 = 0x08,
677 AMDGPU_DOORBELL64_MEC_RING6 = 0x09,
678 AMDGPU_DOORBELL64_MEC_RING7 = 0x0a,
679
680 /* User queue doorbell range (128 doorbells) */
681 AMDGPU_DOORBELL64_USERQUEUE_START = 0x0b,
682 AMDGPU_DOORBELL64_USERQUEUE_END = 0x8a,
683
684 /* Graphics engine */
685 AMDGPU_DOORBELL64_GFX_RING0 = 0x8b,
686
687 /*
688 * Other graphics doorbells can be allocated here: from 0x8c to 0xef
689 * Graphics voltage island aperture 1
690 * default non-graphics QWORD index is 0xF0 - 0xFF inclusive
691 */
692
693 /* sDMA engines */
694 AMDGPU_DOORBELL64_sDMA_ENGINE0 = 0xF0,
695 AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
696 AMDGPU_DOORBELL64_sDMA_ENGINE1 = 0xF2,
697 AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
698
699 /* Interrupt handler */
700 AMDGPU_DOORBELL64_IH = 0xF4, /* For legacy interrupt ring buffer */
701 AMDGPU_DOORBELL64_IH_RING1 = 0xF5, /* For page migration request log */
702 AMDGPU_DOORBELL64_IH_RING2 = 0xF6, /* For page migration translation/invalidation log */
703
Monk Liue6b3ecb2016-12-30 16:18:56 +0800704 /* VCN engine use 32 bits doorbell */
705 AMDGPU_DOORBELL64_VCN0_1 = 0xF8, /* lower 32 bits for VNC0 and upper 32 bits for VNC1 */
706 AMDGPU_DOORBELL64_VCN2_3 = 0xF9,
707 AMDGPU_DOORBELL64_VCN4_5 = 0xFA,
708 AMDGPU_DOORBELL64_VCN6_7 = 0xFB,
709
710 /* overlap the doorbell assignment with VCN as they are mutually exclusive
711 * VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
712 */
713 AMDGPU_DOORBELL64_RING0_1 = 0xF8,
714 AMDGPU_DOORBELL64_RING2_3 = 0xF9,
715 AMDGPU_DOORBELL64_RING4_5 = 0xFA,
716 AMDGPU_DOORBELL64_RING6_7 = 0xFB,
717
718 AMDGPU_DOORBELL64_UVD_RING0_1 = 0xFC,
719 AMDGPU_DOORBELL64_UVD_RING2_3 = 0xFD,
720 AMDGPU_DOORBELL64_UVD_RING4_5 = 0xFE,
721 AMDGPU_DOORBELL64_UVD_RING6_7 = 0xFF,
Ken Wang39807b92016-03-18 15:41:42 +0800722
723 AMDGPU_DOORBELL64_MAX_ASSIGNMENT = 0xFF,
724 AMDGPU_DOORBELL64_INVALID = 0xFFFF
725} AMDGPU_DOORBELL64_ASSIGNMENT;
726
727
Alex Deucher97b2e202015-04-20 16:51:00 -0400728void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
729 phys_addr_t *aperture_base,
730 size_t *aperture_size,
731 size_t *start_offset);
732
733/*
734 * IRQS.
735 */
736
737struct amdgpu_flip_work {
Michel Dänzer325cbba2016-08-04 12:39:37 +0900738 struct delayed_work flip_work;
Alex Deucher97b2e202015-04-20 16:51:00 -0400739 struct work_struct unpin_work;
740 struct amdgpu_device *adev;
741 int crtc_id;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900742 u32 target_vblank;
Alex Deucher97b2e202015-04-20 16:51:00 -0400743 uint64_t base;
744 struct drm_pending_vblank_event *event;
Christian König765e7fb2016-09-15 15:06:50 +0200745 struct amdgpu_bo *old_abo;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100746 struct dma_fence *excl;
Christian König1ffd2652015-08-11 17:29:52 +0200747 unsigned shared_count;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100748 struct dma_fence **shared;
749 struct dma_fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400750 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400751};
752
753
754/*
755 * CP & rings.
756 */
757
758struct amdgpu_ib {
759 struct amdgpu_sa_bo *sa_bo;
760 uint32_t length_dw;
761 uint64_t gpu_addr;
762 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800763 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400764};
765
Nils Wallménius62250a92016-04-10 16:30:00 +0200766extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800767
Christian König50838c82016-02-03 13:44:52 +0100768int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800769 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100770int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
771 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800772
Christian Königa5fb4ec2016-06-29 15:10:31 +0200773void amdgpu_job_free_resources(struct amdgpu_job *job);
Christian König50838c82016-02-03 13:44:52 +0100774void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100775int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100776 struct amd_sched_entity *entity, void *owner,
Chris Wilsonf54d1862016-10-25 13:00:45 +0100777 struct dma_fence **f);
Christian König8b4fb002015-11-15 16:04:16 +0100778
Alex Deucher97b2e202015-04-20 16:51:00 -0400779/*
Andres Rodriguezeffd9242017-02-16 00:47:32 -0500780 * Queue manager
781 */
782struct amdgpu_queue_mapper {
783 int hw_ip;
784 struct mutex lock;
785 /* protected by lock */
786 struct amdgpu_ring *queue_map[AMDGPU_MAX_RINGS];
787};
788
789struct amdgpu_queue_mgr {
790 struct amdgpu_queue_mapper mapper[AMDGPU_MAX_IP_NUM];
791};
792
793int amdgpu_queue_mgr_init(struct amdgpu_device *adev,
794 struct amdgpu_queue_mgr *mgr);
795int amdgpu_queue_mgr_fini(struct amdgpu_device *adev,
796 struct amdgpu_queue_mgr *mgr);
797int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
798 struct amdgpu_queue_mgr *mgr,
799 int hw_ip, int instance, int ring,
800 struct amdgpu_ring **out_ring);
801
802/*
Alex Deucher97b2e202015-04-20 16:51:00 -0400803 * context related structures
804 */
805
Christian König21c16bf2015-07-07 17:24:49 +0200806struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200807 uint64_t sequence;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100808 struct dma_fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200809 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200810};
811
Alex Deucher97b2e202015-04-20 16:51:00 -0400812struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400813 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800814 struct amdgpu_device *adev;
Andres Rodriguezeffd9242017-02-16 00:47:32 -0500815 struct amdgpu_queue_mgr queue_mgr;
Alex Deucher0b492a42015-08-16 22:48:26 -0400816 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200817 spinlock_t ring_lock;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100818 struct dma_fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200819 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Monk Liu753ad492016-08-26 13:28:28 +0800820 bool preamble_presented;
Alex Deucher97b2e202015-04-20 16:51:00 -0400821};
822
823struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400824 struct amdgpu_device *adev;
825 struct mutex lock;
826 /* protected by lock */
827 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400828};
829
Alex Deucher0b492a42015-08-16 22:48:26 -0400830struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
831int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
832
Christian König21c16bf2015-07-07 17:24:49 +0200833uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Chris Wilsonf54d1862016-10-25 13:00:45 +0100834 struct dma_fence *fence);
835struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
Christian König21c16bf2015-07-07 17:24:49 +0200836 struct amdgpu_ring *ring, uint64_t seq);
837
Alex Deucher0b492a42015-08-16 22:48:26 -0400838int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
839 struct drm_file *filp);
840
Christian Königefd4ccb2015-08-04 16:20:31 +0200841void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
842void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400843
Alex Deucher97b2e202015-04-20 16:51:00 -0400844/*
845 * file private structure
846 */
847
848struct amdgpu_fpriv {
849 struct amdgpu_vm vm;
Junwei Zhangb85891b2017-01-16 13:59:01 +0800850 struct amdgpu_bo_va *prt_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400851 struct mutex bo_list_lock;
852 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -0400853 struct amdgpu_ctx_mgr ctx_mgr;
Chunming Zhouf1892132017-05-15 16:48:27 +0800854 u32 vram_lost_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400855};
856
857/*
858 * residency list
859 */
860
861struct amdgpu_bo_list {
862 struct mutex lock;
863 struct amdgpu_bo *gds_obj;
864 struct amdgpu_bo *gws_obj;
865 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +0100866 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400867 unsigned num_entries;
868 struct amdgpu_bo_list_entry *array;
869};
870
871struct amdgpu_bo_list *
872amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +0100873void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
874 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -0400875void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
876void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
877
878/*
879 * GFX stuff
880 */
881#include "clearstate_defs.h"
882
Alex Deucher79e54122016-04-08 15:45:13 -0400883struct amdgpu_rlc_funcs {
884 void (*enter_safe_mode)(struct amdgpu_device *adev);
885 void (*exit_safe_mode)(struct amdgpu_device *adev);
886};
887
Alex Deucher97b2e202015-04-20 16:51:00 -0400888struct amdgpu_rlc {
889 /* for power gating */
890 struct amdgpu_bo *save_restore_obj;
891 uint64_t save_restore_gpu_addr;
892 volatile uint32_t *sr_ptr;
893 const u32 *reg_list;
894 u32 reg_list_size;
895 /* for clear state */
896 struct amdgpu_bo *clear_state_obj;
897 uint64_t clear_state_gpu_addr;
898 volatile uint32_t *cs_ptr;
899 const struct cs_section_def *cs_data;
900 u32 clear_state_size;
901 /* for cp tables */
902 struct amdgpu_bo *cp_table_obj;
903 uint64_t cp_table_gpu_addr;
904 volatile uint32_t *cp_table_ptr;
905 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -0400906
907 /* safe mode for updating CG/PG state */
908 bool in_safe_mode;
909 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -0400910
911 /* for firmware data */
912 u32 save_and_restore_offset;
913 u32 clear_state_descriptor_offset;
914 u32 avail_scratch_ram_locations;
915 u32 reg_restore_list_size;
916 u32 reg_list_format_start;
917 u32 reg_list_format_separate_start;
918 u32 starting_offsets_start;
919 u32 reg_list_format_size_bytes;
920 u32 reg_list_size_bytes;
921
922 u32 *register_list_format;
923 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -0400924};
925
Andres Rodriguez78c16832017-02-02 00:38:22 -0500926#define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
927
Alex Deucher97b2e202015-04-20 16:51:00 -0400928struct amdgpu_mec {
929 struct amdgpu_bo *hpd_eop_obj;
930 u64 hpd_eop_gpu_addr;
Ken Wangb1023572017-03-03 17:59:39 -0500931 struct amdgpu_bo *mec_fw_obj;
932 u64 mec_fw_gpu_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400933 u32 num_mec;
Andres Rodriguez42794b22017-02-01 19:08:23 -0500934 u32 num_pipe_per_mec;
935 u32 num_queue_per_pipe;
Xiangliang Yu59a82d72017-02-17 16:03:10 +0800936 void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS + 1];
Andres Rodriguez78c16832017-02-02 00:38:22 -0500937
938 /* These are the resources for which amdgpu takes ownership */
939 DECLARE_BITMAP(queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
Alex Deucher97b2e202015-04-20 16:51:00 -0400940};
941
Xiangliang Yu4e638ae2016-12-23 15:00:01 +0800942struct amdgpu_kiq {
943 u64 eop_gpu_addr;
944 struct amdgpu_bo *eop_obj;
Shaoyun Liucdf6adb2017-04-28 17:18:26 -0400945 struct mutex ring_mutex;
Xiangliang Yu4e638ae2016-12-23 15:00:01 +0800946 struct amdgpu_ring ring;
947 struct amdgpu_irq_src irq;
948};
949
Alex Deucher97b2e202015-04-20 16:51:00 -0400950/*
951 * GPU scratch registers structures, functions & helpers
952 */
953struct amdgpu_scratch {
954 unsigned num_reg;
955 uint32_t reg_base;
Nils Wallménius50261152017-01-16 21:56:48 +0100956 uint32_t free_mask;
Alex Deucher97b2e202015-04-20 16:51:00 -0400957};
958
959/*
960 * GFX configurations
961 */
Alex Deuchere3fa7632016-10-10 10:56:21 -0400962#define AMDGPU_GFX_MAX_SE 4
963#define AMDGPU_GFX_MAX_SH_PER_SE 2
964
965struct amdgpu_rb_config {
966 uint32_t rb_backend_disable;
967 uint32_t user_rb_backend_disable;
968 uint32_t raster_config;
969 uint32_t raster_config_1;
970};
971
Andrey Grodzovskyd0e95752016-12-12 13:40:37 -0500972struct gb_addr_config {
973 uint16_t pipe_interleave_size;
974 uint8_t num_pipes;
975 uint8_t max_compress_frags;
976 uint8_t num_banks;
977 uint8_t num_se;
978 uint8_t num_rb_per_se;
979};
980
Junwei Zhangea323f82017-02-21 10:32:37 +0800981struct amdgpu_gfx_config {
Alex Deucher97b2e202015-04-20 16:51:00 -0400982 unsigned max_shader_engines;
983 unsigned max_tile_pipes;
984 unsigned max_cu_per_sh;
985 unsigned max_sh_per_se;
986 unsigned max_backends_per_se;
987 unsigned max_texture_channel_caches;
988 unsigned max_gprs;
989 unsigned max_gs_threads;
990 unsigned max_hw_contexts;
991 unsigned sc_prim_fifo_size_frontend;
992 unsigned sc_prim_fifo_size_backend;
993 unsigned sc_hiz_tile_fifo_size;
994 unsigned sc_earlyz_tile_fifo_size;
995
996 unsigned num_tile_pipes;
997 unsigned backend_enable_mask;
998 unsigned mem_max_burst_length_bytes;
999 unsigned mem_row_size_in_kb;
1000 unsigned shader_engine_tile_size;
1001 unsigned num_gpus;
1002 unsigned multi_gpu_tile_size;
1003 unsigned mc_arb_ramcfg;
1004 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001005 unsigned num_rbs;
Junwei Zhang408bfe72017-04-27 11:12:07 +08001006 unsigned gs_vgt_table_depth;
1007 unsigned gs_prim_buffer_depth;
Alex Deucher97b2e202015-04-20 16:51:00 -04001008
1009 uint32_t tile_mode_array[32];
1010 uint32_t macrotile_mode_array[16];
Alex Deuchere3fa7632016-10-10 10:56:21 -04001011
Andrey Grodzovskyd0e95752016-12-12 13:40:37 -05001012 struct gb_addr_config gb_addr_config_fields;
Alex Deuchere3fa7632016-10-10 10:56:21 -04001013 struct amdgpu_rb_config rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
Junwei Zhangdf6e2c42017-02-17 11:05:49 +08001014
1015 /* gfx configure feature */
1016 uint32_t double_offchip_lds_buf;
Alex Deucher97b2e202015-04-20 16:51:00 -04001017};
1018
Alex Deucher7dae69a2016-05-03 16:25:53 -04001019struct amdgpu_cu_info {
1020 uint32_t number; /* total active CU number */
1021 uint32_t ao_cu_mask;
Junwei Zhang408bfe72017-04-27 11:12:07 +08001022 uint32_t wave_front_size;
Alex Deucher7dae69a2016-05-03 16:25:53 -04001023 uint32_t bitmap[4][4];
1024};
1025
Alex Deucherb95e31f2016-07-07 15:01:42 -04001026struct amdgpu_gfx_funcs {
1027 /* get the gpu clock counter */
1028 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -04001029 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Tom St Denis472259f2016-10-14 09:49:09 -04001030 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 -05001031 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);
1032 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 -04001033};
1034
Alex Deucherbce23e02017-03-28 12:52:08 -04001035struct amdgpu_ngg_buf {
1036 struct amdgpu_bo *bo;
1037 uint64_t gpu_addr;
1038 uint32_t size;
1039 uint32_t bo_size;
1040};
1041
1042enum {
Guenter Roeckaf8baf12017-05-03 23:49:18 -07001043 NGG_PRIM = 0,
1044 NGG_POS,
1045 NGG_CNTL,
1046 NGG_PARAM,
Alex Deucherbce23e02017-03-28 12:52:08 -04001047 NGG_BUF_MAX
1048};
1049
1050struct amdgpu_ngg {
1051 struct amdgpu_ngg_buf buf[NGG_BUF_MAX];
1052 uint32_t gds_reserve_addr;
1053 uint32_t gds_reserve_size;
1054 bool init;
1055};
1056
Alex Deucher97b2e202015-04-20 16:51:00 -04001057struct amdgpu_gfx {
1058 struct mutex gpu_clock_mutex;
Junwei Zhangea323f82017-02-21 10:32:37 +08001059 struct amdgpu_gfx_config config;
Alex Deucher97b2e202015-04-20 16:51:00 -04001060 struct amdgpu_rlc rlc;
1061 struct amdgpu_mec mec;
Xiangliang Yu4e638ae2016-12-23 15:00:01 +08001062 struct amdgpu_kiq kiq;
Alex Deucher97b2e202015-04-20 16:51:00 -04001063 struct amdgpu_scratch scratch;
1064 const struct firmware *me_fw; /* ME firmware */
1065 uint32_t me_fw_version;
1066 const struct firmware *pfp_fw; /* PFP firmware */
1067 uint32_t pfp_fw_version;
1068 const struct firmware *ce_fw; /* CE firmware */
1069 uint32_t ce_fw_version;
1070 const struct firmware *rlc_fw; /* RLC firmware */
1071 uint32_t rlc_fw_version;
1072 const struct firmware *mec_fw; /* MEC firmware */
1073 uint32_t mec_fw_version;
1074 const struct firmware *mec2_fw; /* MEC2 firmware */
1075 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001076 uint32_t me_feature_version;
1077 uint32_t ce_feature_version;
1078 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001079 uint32_t rlc_feature_version;
1080 uint32_t mec_feature_version;
1081 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001082 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1083 unsigned num_gfx_rings;
1084 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1085 unsigned num_compute_rings;
1086 struct amdgpu_irq_src eop_irq;
1087 struct amdgpu_irq_src priv_reg_irq;
1088 struct amdgpu_irq_src priv_inst_irq;
1089 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001090 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001091 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001092 unsigned ce_ram_size;
1093 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001094 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +08001095
1096 /* reset mask */
1097 uint32_t grbm_soft_reset;
1098 uint32_t srbm_soft_reset;
Monk Liu223049c2017-01-26 15:32:16 +08001099 bool in_reset;
David Panaritib4e40672017-03-28 12:57:31 -04001100 /* s3/s4 mask */
1101 bool in_suspend;
Alex Deucherbce23e02017-03-28 12:52:08 -04001102 /* NGG */
1103 struct amdgpu_ngg ngg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001104};
1105
Christian Königb07c60c2016-01-31 12:29:04 +01001106int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001107 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001108void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
Chris Wilsonf54d1862016-10-25 13:00:45 +01001109 struct dma_fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001110int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Junwei Zhang50ddc752017-01-23 16:30:38 +08001111 struct amdgpu_ib *ibs, struct amdgpu_job *job,
1112 struct dma_fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001113int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1114void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1115int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001116
1117/*
1118 * CS.
1119 */
1120struct amdgpu_cs_chunk {
1121 uint32_t chunk_id;
1122 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001123 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001124};
1125
1126struct amdgpu_cs_parser {
1127 struct amdgpu_device *adev;
1128 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001129 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001130
Alex Deucher97b2e202015-04-20 16:51:00 -04001131 /* chunks */
1132 unsigned nchunks;
1133 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001134
Christian König50838c82016-02-03 13:44:52 +01001135 /* scheduler job object */
1136 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001137
Christian Königc3cca412015-12-15 14:41:33 +01001138 /* buffer objects */
1139 struct ww_acquire_ctx ticket;
1140 struct amdgpu_bo_list *bo_list;
1141 struct amdgpu_bo_list_entry vm_pd;
1142 struct list_head validated;
Chris Wilsonf54d1862016-10-25 13:00:45 +01001143 struct dma_fence *fence;
Christian Königc3cca412015-12-15 14:41:33 +01001144 uint64_t bytes_moved_threshold;
1145 uint64_t bytes_moved;
Christian König662bfa62016-09-01 12:13:18 +02001146 struct amdgpu_bo_list_entry *evictable;
Alex Deucher97b2e202015-04-20 16:51:00 -04001147
1148 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001149 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001150};
1151
Monk Liu753ad492016-08-26 13:28:28 +08001152#define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */
1153#define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1154#define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */
1155
Chunming Zhoubb977d32015-08-18 15:16:40 +08001156struct amdgpu_job {
1157 struct amd_sched_job base;
1158 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001159 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001160 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001161 struct amdgpu_sync sync;
Chunming Zhoua340c7b2017-05-18 15:19:03 +08001162 struct amdgpu_sync dep_sync;
Chunming Zhoudf83d1e2017-05-09 15:50:22 +08001163 struct amdgpu_sync sched_sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001164 struct amdgpu_ib *ibs;
Chris Wilsonf54d1862016-10-25 13:00:45 +01001165 struct dma_fence *fence; /* the hw fence */
Monk Liu753ad492016-08-26 13:28:28 +08001166 uint32_t preamble_status;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001167 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001168 void *owner;
Monk Liu3aecd242016-08-25 15:40:48 +08001169 uint64_t fence_ctx; /* the fence_context this job uses */
Chunming Zhoufd53be32016-07-01 17:59:01 +08001170 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +02001171 unsigned vm_id;
1172 uint64_t vm_pd_addr;
1173 uint32_t gds_base, gds_size;
1174 uint32_t gws_base, gws_size;
1175 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001176
1177 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +02001178 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +02001179 uint64_t uf_sequence;
1180
Chunming Zhoubb977d32015-08-18 15:16:40 +08001181};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001182#define to_amdgpu_job(sched_job) \
1183 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001184
Christian König7270f832016-01-31 11:00:41 +01001185static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1186 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001187{
Christian König50838c82016-02-03 13:44:52 +01001188 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001189}
1190
Christian König7270f832016-01-31 11:00:41 +01001191static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1192 uint32_t ib_idx, int idx,
1193 uint32_t value)
1194{
Christian König50838c82016-02-03 13:44:52 +01001195 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001196}
1197
Alex Deucher97b2e202015-04-20 16:51:00 -04001198/*
1199 * Writeback
1200 */
1201#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1202
1203struct amdgpu_wb {
1204 struct amdgpu_bo *wb_obj;
1205 volatile uint32_t *wb;
1206 uint64_t gpu_addr;
1207 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1208 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1209};
1210
1211int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1212void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
Ken Wang70142852016-03-18 15:08:49 +08001213int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);
1214void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);
Alex Deucher97b2e202015-04-20 16:51:00 -04001215
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001216void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1217
Alex Deucher97b2e202015-04-20 16:51:00 -04001218/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001219 * SDMA
1220 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001221struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001222 /* SDMA firmware */
1223 const struct firmware *fw;
1224 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001225 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001226
1227 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001228 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001229};
1230
Alex Deucherc113ea12015-10-08 16:30:37 -04001231struct amdgpu_sdma {
1232 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
Ken Wang30d15742016-01-19 14:05:23 +08001233#ifdef CONFIG_DRM_AMDGPU_SI
1234 //SI DMA has a difference trap irq number for the second engine
1235 struct amdgpu_irq_src trap_irq_1;
1236#endif
Alex Deucherc113ea12015-10-08 16:30:37 -04001237 struct amdgpu_irq_src trap_irq;
1238 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001239 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001240 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001241};
1242
Alex Deucher97b2e202015-04-20 16:51:00 -04001243/*
1244 * Firmware
1245 */
Huang Ruie635ee02016-11-01 15:35:38 +08001246enum amdgpu_firmware_load_type {
1247 AMDGPU_FW_LOAD_DIRECT = 0,
1248 AMDGPU_FW_LOAD_SMU,
1249 AMDGPU_FW_LOAD_PSP,
1250};
1251
Alex Deucher97b2e202015-04-20 16:51:00 -04001252struct amdgpu_firmware {
1253 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
Huang Ruie635ee02016-11-01 15:35:38 +08001254 enum amdgpu_firmware_load_type load_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001255 struct amdgpu_bo *fw_buf;
1256 unsigned int fw_size;
Huang Rui2445b222017-03-03 16:20:35 -05001257 unsigned int max_ucodes;
Huang Rui0e5ca0d2017-03-03 18:37:23 -05001258 /* firmwares are loaded by psp instead of smu from vega10 */
1259 const struct amdgpu_psp_funcs *funcs;
1260 struct amdgpu_bo *rbuf;
1261 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001262};
1263
1264/*
1265 * Benchmarking
1266 */
1267void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1268
1269
1270/*
1271 * Testing
1272 */
1273void amdgpu_test_moves(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001274
1275/*
1276 * MMU Notifier
1277 */
1278#if defined(CONFIG_MMU_NOTIFIER)
1279int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1280void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1281#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001282static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001283{
1284 return -ENODEV;
1285}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001286static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001287#endif
1288
1289/*
1290 * Debugfs
1291 */
1292struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001293 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001294 unsigned num_files;
1295};
1296
1297int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001298 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001299 unsigned nfiles);
1300int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1301
1302#if defined(CONFIG_DEBUG_FS)
1303int amdgpu_debugfs_init(struct drm_minor *minor);
Alex Deucher97b2e202015-04-20 16:51:00 -04001304#endif
1305
Huang Rui50ab2532016-06-12 15:51:09 +08001306int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1307
Alex Deucher97b2e202015-04-20 16:51:00 -04001308/*
1309 * amdgpu smumgr functions
1310 */
1311struct amdgpu_smumgr_funcs {
1312 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1313 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1314 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1315};
1316
1317/*
1318 * amdgpu smumgr
1319 */
1320struct amdgpu_smumgr {
1321 struct amdgpu_bo *toc_buf;
1322 struct amdgpu_bo *smu_buf;
1323 /* asic priv smu data */
1324 void *priv;
1325 spinlock_t smu_lock;
1326 /* smumgr functions */
1327 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1328 /* ucode loading complete flag */
1329 uint32_t fw_flags;
1330};
1331
1332/*
1333 * ASIC specific register table accessible by UMD
1334 */
1335struct amdgpu_allowed_register_entry {
1336 uint32_t reg_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001337 bool grbm_indexed;
1338};
1339
Alex Deucher97b2e202015-04-20 16:51:00 -04001340/*
1341 * ASIC specific functions.
1342 */
1343struct amdgpu_asic_funcs {
1344 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001345 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1346 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001347 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1348 u32 sh_num, u32 reg_offset, u32 *value);
1349 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1350 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001351 /* get the reference clock */
1352 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001353 /* MM block clocks */
1354 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1355 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Maruthi Bayyavarapu841686d2016-08-01 12:42:32 -04001356 /* static power management */
1357 int (*get_pcie_lanes)(struct amdgpu_device *adev);
1358 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
Alex Deucherbbf282d2017-03-03 17:26:10 -05001359 /* get config memsize register */
1360 u32 (*get_config_memsize)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001361};
1362
1363/*
1364 * IOCTL.
1365 */
1366int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1367 struct drm_file *filp);
1368int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1369 struct drm_file *filp);
1370
1371int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1372 struct drm_file *filp);
1373int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1374 struct drm_file *filp);
1375int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1376 struct drm_file *filp);
1377int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1378 struct drm_file *filp);
1379int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1380 struct drm_file *filp);
1381int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1382 struct drm_file *filp);
1383int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1384int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
Junwei Zhangeef18a82016-11-04 16:16:10 -04001385int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
1386 struct drm_file *filp);
Alex Deucher97b2e202015-04-20 16:51:00 -04001387
1388int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1389 struct drm_file *filp);
1390
1391/* VRAM scratch page for HDP bug, default vram page */
1392struct amdgpu_vram_scratch {
1393 struct amdgpu_bo *robj;
1394 volatile uint32_t *ptr;
1395 u64 gpu_addr;
1396};
1397
1398/*
1399 * ACPI
1400 */
1401struct amdgpu_atif_notification_cfg {
1402 bool enabled;
1403 int command_code;
1404};
1405
1406struct amdgpu_atif_notifications {
1407 bool display_switch;
1408 bool expansion_mode_change;
1409 bool thermal_state;
1410 bool forced_power_state;
1411 bool system_power_state;
1412 bool display_conf_change;
1413 bool px_gfx_switch;
1414 bool brightness_change;
1415 bool dgpu_display_event;
1416};
1417
1418struct amdgpu_atif_functions {
1419 bool system_params;
1420 bool sbios_requests;
1421 bool select_active_disp;
1422 bool lid_state;
1423 bool get_tv_standard;
1424 bool set_tv_standard;
1425 bool get_panel_expansion_mode;
1426 bool set_panel_expansion_mode;
1427 bool temperature_change;
1428 bool graphics_device_types;
1429};
1430
1431struct amdgpu_atif {
1432 struct amdgpu_atif_notifications notifications;
1433 struct amdgpu_atif_functions functions;
1434 struct amdgpu_atif_notification_cfg notification_cfg;
1435 struct amdgpu_encoder *encoder_for_bl;
1436};
1437
1438struct amdgpu_atcs_functions {
1439 bool get_ext_state;
1440 bool pcie_perf_req;
1441 bool pcie_dev_rdy;
1442 bool pcie_bus_width;
1443};
1444
1445struct amdgpu_atcs {
1446 struct amdgpu_atcs_functions functions;
1447};
1448
Alex Deucher97b2e202015-04-20 16:51:00 -04001449/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001450 * CGS
1451 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001452struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1453void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001454
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001455/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001456 * Core structure, functions and helpers.
1457 */
1458typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1459typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1460
1461typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1462typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1463
Chunming Zhou0c49e0b2017-05-15 14:20:00 +08001464#define AMDGPU_RESET_MAGIC_NUM 64
Alex Deucher97b2e202015-04-20 16:51:00 -04001465struct amdgpu_device {
1466 struct device *dev;
1467 struct drm_device *ddev;
1468 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001469
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001470#ifdef CONFIG_DRM_AMD_ACP
1471 struct amdgpu_acp acp;
1472#endif
1473
Alex Deucher97b2e202015-04-20 16:51:00 -04001474 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001475 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001476 uint32_t family;
1477 uint32_t rev_id;
1478 uint32_t external_rev_id;
1479 unsigned long flags;
1480 int usec_timeout;
1481 const struct amdgpu_asic_funcs *asic_funcs;
1482 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001483 bool need_dma32;
1484 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001485 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001486 struct notifier_block acpi_nb;
1487 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1488 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001489 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001490#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001491 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001492#endif
1493 struct amdgpu_atif atif;
1494 struct amdgpu_atcs atcs;
1495 struct mutex srbm_mutex;
1496 /* GRBM index mutex. Protects concurrent access to GRBM index */
1497 struct mutex grbm_idx_mutex;
1498 struct dev_pm_domain vga_pm_domain;
1499 bool have_disp_power_ref;
1500
1501 /* BIOS */
Alex Deucher0cdd5002017-02-13 16:01:58 -05001502 bool is_atom_fw;
Alex Deucher97b2e202015-04-20 16:51:00 -04001503 uint8_t *bios;
Evan Quana9f5db92016-12-07 09:56:46 +08001504 uint32_t bios_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001505 struct amdgpu_bo *stollen_vga_memory;
Alex Deuchera5bde2f2016-09-23 16:23:41 -04001506 uint32_t bios_scratch_reg_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001507 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1508
1509 /* Register/doorbell mmio */
1510 resource_size_t rmmio_base;
1511 resource_size_t rmmio_size;
1512 void __iomem *rmmio;
1513 /* protects concurrent MM_INDEX/DATA based register access */
1514 spinlock_t mmio_idx_lock;
1515 /* protects concurrent SMC based register access */
1516 spinlock_t smc_idx_lock;
1517 amdgpu_rreg_t smc_rreg;
1518 amdgpu_wreg_t smc_wreg;
1519 /* protects concurrent PCIE register access */
1520 spinlock_t pcie_idx_lock;
1521 amdgpu_rreg_t pcie_rreg;
1522 amdgpu_wreg_t pcie_wreg;
Huang Rui36b9a952016-08-31 13:23:25 +08001523 amdgpu_rreg_t pciep_rreg;
1524 amdgpu_wreg_t pciep_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001525 /* protects concurrent UVD register access */
1526 spinlock_t uvd_ctx_idx_lock;
1527 amdgpu_rreg_t uvd_ctx_rreg;
1528 amdgpu_wreg_t uvd_ctx_wreg;
1529 /* protects concurrent DIDT register access */
1530 spinlock_t didt_idx_lock;
1531 amdgpu_rreg_t didt_rreg;
1532 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08001533 /* protects concurrent gc_cac register access */
1534 spinlock_t gc_cac_idx_lock;
1535 amdgpu_rreg_t gc_cac_rreg;
1536 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04001537 /* protects concurrent ENDPOINT (audio) register access */
1538 spinlock_t audio_endpt_idx_lock;
1539 amdgpu_block_rreg_t audio_endpt_rreg;
1540 amdgpu_block_wreg_t audio_endpt_wreg;
1541 void __iomem *rio_mem;
1542 resource_size_t rio_mem_size;
1543 struct amdgpu_doorbell doorbell;
1544
1545 /* clock/pll info */
1546 struct amdgpu_clock clock;
1547
1548 /* MC */
1549 struct amdgpu_mc mc;
1550 struct amdgpu_gart gart;
1551 struct amdgpu_dummy_page dummy_page;
1552 struct amdgpu_vm_manager vm_manager;
Alex Xiee60f8db2017-03-09 11:36:26 -05001553 struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001554
1555 /* memory management */
1556 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04001557 struct amdgpu_vram_scratch vram_scratch;
1558 struct amdgpu_wb wb;
1559 atomic64_t vram_usage;
1560 atomic64_t vram_vis_usage;
1561 atomic64_t gtt_usage;
1562 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02001563 atomic64_t num_evictions;
Marek Olšák68e2c5f2017-05-17 20:05:08 +02001564 atomic64_t num_vram_cpu_page_faults;
Marek Olšákd94aed52015-05-05 21:13:49 +02001565 atomic_t gpu_reset_counter;
Chunming Zhouf1892132017-05-15 16:48:27 +08001566 atomic_t vram_lost_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04001567
Marek Olšák95844d22016-08-17 23:49:27 +02001568 /* data for buffer migration throttling */
1569 struct {
1570 spinlock_t lock;
1571 s64 last_update_us;
1572 s64 accum_us; /* accumulated microseconds */
1573 u32 log2_max_MBps;
1574 } mm_stats;
1575
Alex Deucher97b2e202015-04-20 16:51:00 -04001576 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08001577 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04001578 struct amdgpu_mode_info mode_info;
1579 struct work_struct hotplug_work;
1580 struct amdgpu_irq_src crtc_irq;
1581 struct amdgpu_irq_src pageflip_irq;
1582 struct amdgpu_irq_src hpd_irq;
1583
1584 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02001585 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04001586 unsigned num_rings;
1587 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
1588 bool ib_pool_ready;
1589 struct amdgpu_sa_manager ring_tmp_bo;
1590
1591 /* interrupts */
1592 struct amdgpu_irq irq;
1593
Alex Deucher1f7371b2015-12-02 17:46:21 -05001594 /* powerplay */
1595 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05001596 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05001597 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05001598
Alex Deucher97b2e202015-04-20 16:51:00 -04001599 /* dpm */
1600 struct amdgpu_pm pm;
1601 u32 cg_flags;
1602 u32 pg_flags;
1603
1604 /* amdgpu smumgr */
1605 struct amdgpu_smumgr smu;
1606
1607 /* gfx */
1608 struct amdgpu_gfx gfx;
1609
1610 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04001611 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04001612
Leo Liu95d09062016-12-21 13:21:52 -05001613 union {
1614 struct {
1615 /* uvd */
1616 struct amdgpu_uvd uvd;
Alex Deucher97b2e202015-04-20 16:51:00 -04001617
Leo Liu95d09062016-12-21 13:21:52 -05001618 /* vce */
1619 struct amdgpu_vce vce;
1620 };
1621
1622 /* vcn */
1623 struct amdgpu_vcn vcn;
1624 };
Alex Deucher97b2e202015-04-20 16:51:00 -04001625
1626 /* firmwares */
1627 struct amdgpu_firmware firmware;
1628
Huang Rui0e5ca0d2017-03-03 18:37:23 -05001629 /* PSP */
1630 struct psp_context psp;
1631
Alex Deucher97b2e202015-04-20 16:51:00 -04001632 /* GDS */
1633 struct amdgpu_gds gds;
1634
Alex Deuchera1255102016-10-13 17:41:13 -04001635 struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM];
Alex Deucher97b2e202015-04-20 16:51:00 -04001636 int num_ip_blocks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001637 struct mutex mn_lock;
1638 DECLARE_HASHTABLE(mn_hash, 7);
1639
1640 /* tracking pinned memory */
1641 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08001642 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04001643 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03001644
1645 /* amdkfd interface */
1646 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08001647
Shirish S2dc80b02017-05-25 10:05:25 +05301648 /* delayed work_func for deferring clockgating during resume */
1649 struct delayed_work late_init_work;
1650
Xiangliang Yu5a5099c2017-01-09 18:06:57 -05001651 struct amdgpu_virt virt;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +08001652
1653 /* link all shadow bo */
1654 struct list_head shadow_list;
1655 struct mutex shadow_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08001656 /* link all gtt */
1657 spinlock_t gtt_list_lock;
1658 struct list_head gtt_list;
Andres Rodriguez795f2812017-03-06 16:27:55 -05001659 /* keep an lru list of rings by HW IP */
1660 struct list_head ring_lru_list;
1661 spinlock_t ring_lru_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08001662
Jim Quc836fec2017-02-10 15:59:59 +08001663 /* record hw reset is performed */
1664 bool has_hw_reset;
Chunming Zhou0c49e0b2017-05-15 14:20:00 +08001665 u8 reset_magic[AMDGPU_RESET_MAGIC_NUM];
Jim Quc836fec2017-02-10 15:59:59 +08001666
Alex Deucher97b2e202015-04-20 16:51:00 -04001667};
1668
Christian Königa7d64de2016-09-15 14:58:48 +02001669static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
1670{
1671 return container_of(bdev, struct amdgpu_device, mman.bdev);
1672}
1673
Alex Deucher97b2e202015-04-20 16:51:00 -04001674bool amdgpu_device_is_px(struct drm_device *dev);
1675int amdgpu_device_init(struct amdgpu_device *adev,
1676 struct drm_device *ddev,
1677 struct pci_dev *pdev,
1678 uint32_t flags);
1679void amdgpu_device_fini(struct amdgpu_device *adev);
1680int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
1681
1682uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
Monk Liu15d72fd2017-01-25 15:07:40 +08001683 uint32_t acc_flags);
Alex Deucher97b2e202015-04-20 16:51:00 -04001684void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
Monk Liu15d72fd2017-01-25 15:07:40 +08001685 uint32_t acc_flags);
Alex Deucher97b2e202015-04-20 16:51:00 -04001686u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
1687void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
1688
1689u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
1690void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
Ken Wang832be402016-03-18 15:23:08 +08001691u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index);
1692void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
Alex Deucher97b2e202015-04-20 16:51:00 -04001693
1694/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001695 * Registers read & write functions.
1696 */
Monk Liu15d72fd2017-01-25 15:07:40 +08001697
1698#define AMDGPU_REGS_IDX (1<<0)
1699#define AMDGPU_REGS_NO_KIQ (1<<1)
1700
1701#define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
1702#define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
1703
1704#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
1705#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
1706#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
1707#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
1708#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
Alex Deucher97b2e202015-04-20 16:51:00 -04001709#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1710#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1711#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
1712#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
Huang Rui36b9a952016-08-31 13:23:25 +08001713#define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
1714#define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001715#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
1716#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
1717#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
1718#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
1719#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
1720#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08001721#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
1722#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001723#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
1724#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
1725#define WREG32_P(reg, val, mask) \
1726 do { \
1727 uint32_t tmp_ = RREG32(reg); \
1728 tmp_ &= (mask); \
1729 tmp_ |= ((val) & ~(mask)); \
1730 WREG32(reg, tmp_); \
1731 } while (0)
1732#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
1733#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
1734#define WREG32_PLL_P(reg, val, mask) \
1735 do { \
1736 uint32_t tmp_ = RREG32_PLL(reg); \
1737 tmp_ &= (mask); \
1738 tmp_ |= ((val) & ~(mask)); \
1739 WREG32_PLL(reg, tmp_); \
1740 } while (0)
1741#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
1742#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
1743#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
1744
1745#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
1746#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
Ken Wang832be402016-03-18 15:23:08 +08001747#define RDOORBELL64(index) amdgpu_mm_rdoorbell64(adev, (index))
1748#define WDOORBELL64(index, v) amdgpu_mm_wdoorbell64(adev, (index), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04001749
1750#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
1751#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
1752
1753#define REG_SET_FIELD(orig_val, reg, field, field_val) \
1754 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
1755 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
1756
1757#define REG_GET_FIELD(value, reg, field) \
1758 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
1759
Tom St Denis61cb8ce2016-08-09 10:13:21 -04001760#define WREG32_FIELD(reg, field, val) \
1761 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1762
Tom St Denisccaf3572017-04-04 09:14:13 -04001763#define WREG32_FIELD_OFFSET(reg, offset, field, val) \
1764 WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
1765
Alex Deucher97b2e202015-04-20 16:51:00 -04001766/*
1767 * BIOS helpers.
1768 */
1769#define RBIOS8(i) (adev->bios[i])
1770#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1771#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1772
1773/*
1774 * RING helpers.
1775 */
1776static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
1777{
1778 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08001779 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Ken Wang536fbf92016-03-12 09:32:30 +08001780 ring->ring[ring->wptr++ & ring->buf_mask] = v;
Alex Deucher97b2e202015-04-20 16:51:00 -04001781 ring->wptr &= ring->ptr_mask;
1782 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04001783}
1784
Monk Liu0a8e1472017-01-17 10:52:33 +08001785static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *src, int count_dw)
1786{
1787 unsigned occupied, chunk1, chunk2;
1788 void *dst;
1789
Nikola Pajkovsky5b9c58f2017-05-04 12:39:50 -04001790 if (unlikely(ring->count_dw < count_dw)) {
Monk Liu0a8e1472017-01-17 10:52:33 +08001791 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Nikola Pajkovsky5b9c58f2017-05-04 12:39:50 -04001792 return;
Monk Liu0a8e1472017-01-17 10:52:33 +08001793 }
Nikola Pajkovsky5b9c58f2017-05-04 12:39:50 -04001794
1795 occupied = ring->wptr & ring->buf_mask;
1796 dst = (void *)&ring->ring[occupied];
1797 chunk1 = ring->buf_mask + 1 - occupied;
1798 chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
1799 chunk2 = count_dw - chunk1;
1800 chunk1 <<= 2;
1801 chunk2 <<= 2;
1802
1803 if (chunk1)
1804 memcpy(dst, src, chunk1);
1805
1806 if (chunk2) {
1807 src += chunk1;
1808 dst = (void *)ring->ring;
1809 memcpy(dst, src, chunk2);
1810 }
1811
1812 ring->wptr += count_dw;
1813 ring->wptr &= ring->ptr_mask;
1814 ring->count_dw -= count_dw;
Monk Liu0a8e1472017-01-17 10:52:33 +08001815}
1816
Alex Deucherc113ea12015-10-08 16:30:37 -04001817static inline struct amdgpu_sdma_instance *
1818amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001819{
1820 struct amdgpu_device *adev = ring->adev;
1821 int i;
1822
Alex Deucherc113ea12015-10-08 16:30:37 -04001823 for (i = 0; i < adev->sdma.num_instances; i++)
1824 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001825 break;
1826
1827 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04001828 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08001829 else
1830 return NULL;
1831}
1832
Andres Rodriguez7b2124a2017-04-06 00:10:53 -04001833static inline int amdgpu_queue_to_bit(struct amdgpu_device *adev,
1834 int mec, int pipe, int queue)
Andres Rodrigueze33fec42017-02-03 17:31:38 -05001835{
1836 int bit = 0;
1837
1838 bit += mec * adev->gfx.mec.num_pipe_per_mec
1839 * adev->gfx.mec.num_queue_per_pipe;
1840 bit += pipe * adev->gfx.mec.num_queue_per_pipe;
1841 bit += queue;
1842
Andres Rodriguez7b2124a2017-04-06 00:10:53 -04001843 return bit;
1844}
1845
1846static inline void amdgpu_bit_to_queue(struct amdgpu_device *adev, int bit,
1847 int *mec, int *pipe, int *queue)
1848{
1849 *queue = bit % adev->gfx.mec.num_queue_per_pipe;
1850 *pipe = (bit / adev->gfx.mec.num_queue_per_pipe)
1851 % adev->gfx.mec.num_pipe_per_mec;
1852 *mec = (bit / adev->gfx.mec.num_queue_per_pipe)
1853 / adev->gfx.mec.num_pipe_per_mec;
1854
1855}
1856static inline bool amdgpu_is_mec_queue_enabled(struct amdgpu_device *adev,
1857 int mec, int pipe, int queue)
1858{
1859 return test_bit(amdgpu_queue_to_bit(adev, mec, pipe, queue),
1860 adev->gfx.mec.queue_bitmap);
Andres Rodrigueze33fec42017-02-03 17:31:38 -05001861}
1862
Alex Deucher97b2e202015-04-20 16:51:00 -04001863/*
1864 * ASICs macro.
1865 */
1866#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
1867#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001868#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
1869#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
1870#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 -04001871#define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
1872#define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
1873#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001874#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05001875#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 -04001876#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 -05001877#define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04001878#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
1879#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 +02001880#define amdgpu_gart_get_vm_pde(adev, addr) (adev)->gart.gart_funcs->get_vm_pde((adev), (addr))
Alex Deucher97b2e202015-04-20 16:51:00 -04001881#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 +02001882#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 -04001883#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 -05001884#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 -04001885#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
1886#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02001887#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04001888#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
1889#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
1890#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02001891#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 +01001892#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04001893#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08001894#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04001895#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 +02001896#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08001897#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Monk Liuc2167a62016-08-26 14:12:37 +08001898#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
Monk Liu753ad492016-08-26 13:28:28 +08001899#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
Xiangliang Yub6091c12017-01-10 12:53:52 +08001900#define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
1901#define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
Monk Liu3b4d68e2017-05-01 18:09:22 +08001902#define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
Christian König9e5d53092016-01-31 12:20:55 +01001903#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08001904#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
1905#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04001906#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
1907#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
1908#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
1909#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
1910#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
1911#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
Alex Deucher97b2e202015-04-20 16:51:00 -04001912#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
1913#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
1914#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
1915#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
1916#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
1917#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04001918#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 -04001919#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
1920#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
1921#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))
1922#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
1923#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08001924#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 +08001925#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 -04001926#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04001927#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 -04001928#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 -05001929#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 -04001930
1931/* Common functions */
1932int amdgpu_gpu_reset(struct amdgpu_device *adev);
Chunming Zhou3ad81f12016-08-05 17:30:17 +08001933bool amdgpu_need_backup(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001934void amdgpu_pci_config_reset(struct amdgpu_device *adev);
Jim Quc836fec2017-02-10 15:59:59 +08001935bool amdgpu_need_post(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001936void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08001937
Alex Deucher97b2e202015-04-20 16:51:00 -04001938int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
Samuel Pitoisetfad06122017-02-09 11:33:37 +01001939void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes);
Christian König765e7fb2016-09-15 15:06:50 +02001940void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
Alex Deucher97b2e202015-04-20 16:51:00 -04001941bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01001942int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04001943int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
1944 uint32_t flags);
1945bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01001946struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01001947bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
1948 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01001949bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
1950 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001951bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
Chunming Zhou6b777602016-09-21 16:19:19 +08001952uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001953 struct ttm_mem_reg *mem);
1954void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
1955void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
1956void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Baoyou Xie9f31a0b2016-09-15 21:43:26 +08001957int amdgpu_ttm_init(struct amdgpu_device *adev);
1958void amdgpu_ttm_fini(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001959void amdgpu_program_register_sequence(struct amdgpu_device *adev,
1960 const u32 *registers,
1961 const u32 array_size);
1962
1963bool amdgpu_device_is_px(struct drm_device *dev);
1964/* atpx handler */
1965#if defined(CONFIG_VGA_SWITCHEROO)
1966void amdgpu_register_atpx_handler(void);
1967void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04001968bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04001969bool amdgpu_is_atpx_hybrid(void);
Alex Deucherefc83cf2016-09-14 14:01:41 -04001970bool amdgpu_atpx_dgpu_req_power_for_displays(void);
Alex Xie714f88e2017-04-05 11:07:13 -04001971bool amdgpu_has_atpx(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04001972#else
1973static inline void amdgpu_register_atpx_handler(void) {}
1974static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04001975static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04001976static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucherefc83cf2016-09-14 14:01:41 -04001977static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
Alex Xie714f88e2017-04-05 11:07:13 -04001978static inline bool amdgpu_has_atpx(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04001979#endif
1980
1981/*
1982 * KMS
1983 */
1984extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02001985extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04001986
Chunming Zhouf1892132017-05-15 16:48:27 +08001987bool amdgpu_kms_vram_lost(struct amdgpu_device *adev,
1988 struct amdgpu_fpriv *fpriv);
Alex Deucher97b2e202015-04-20 16:51:00 -04001989int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
Gabriel Krisman Bertazi11b3c202017-01-06 15:57:31 -02001990void amdgpu_driver_unload_kms(struct drm_device *dev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001991void amdgpu_driver_lastclose_kms(struct drm_device *dev);
1992int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
1993void amdgpu_driver_postclose_kms(struct drm_device *dev,
1994 struct drm_file *file_priv);
Alex Deucherfaefba92016-12-06 10:38:29 -05001995int amdgpu_suspend(struct amdgpu_device *adev);
Alex Deucher810ddc32016-08-23 13:25:49 -04001996int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
1997int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02001998u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
1999int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2000void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
Alex Deucher97b2e202015-04-20 16:51:00 -04002001long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2002 unsigned long arg);
2003
2004/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002005 * functions used by amdgpu_encoder.c
2006 */
2007struct amdgpu_afmt_acr {
2008 u32 clock;
2009
2010 int n_32khz;
2011 int cts_32khz;
2012
2013 int n_44_1khz;
2014 int cts_44_1khz;
2015
2016 int n_48khz;
2017 int cts_48khz;
2018
2019};
2020
2021struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2022
2023/* amdgpu_acpi.c */
2024#if defined(CONFIG_ACPI)
2025int amdgpu_acpi_init(struct amdgpu_device *adev);
2026void amdgpu_acpi_fini(struct amdgpu_device *adev);
2027bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2028int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2029 u8 perf_req, bool advertise);
2030int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2031#else
2032static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2033static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2034#endif
2035
2036struct amdgpu_bo_va_mapping *
2037amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2038 uint64_t addr, struct amdgpu_bo **bo);
Christian Königc855e252016-09-05 17:00:57 +02002039int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
Alex Deucher97b2e202015-04-20 16:51:00 -04002040
2041#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002042#endif