blob: 9f0049563b71d82f3a60ec764b289f006e3dd9a2 [file] [log] [blame]
Alex Deucher97b2e202015-04-20 16:51:00 -04001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#ifndef __AMDGPU_H__
29#define __AMDGPU_H__
30
31#include <linux/atomic.h>
32#include <linux/wait.h>
33#include <linux/list.h>
34#include <linux/kref.h>
35#include <linux/interval_tree.h>
36#include <linux/hashtable.h>
37#include <linux/fence.h>
38
39#include <ttm/ttm_bo_api.h>
40#include <ttm/ttm_bo_driver.h>
41#include <ttm/ttm_placement.h>
42#include <ttm/ttm_module.h>
43#include <ttm/ttm_execbuf_util.h>
44
Chunming Zhoud03846a2015-07-28 14:20:03 -040045#include <drm/drmP.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040046#include <drm/drm_gem.h>
Chunming Zhou7e5a5472015-04-24 17:37:30 +080047#include <drm/amdgpu_drm.h>
Alex Deucher97b2e202015-04-20 16:51:00 -040048
yanyang15fc3aee2015-05-22 14:39:35 -040049#include "amd_shared.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040050#include "amdgpu_mode.h"
51#include "amdgpu_ih.h"
52#include "amdgpu_irq.h"
53#include "amdgpu_ucode.h"
Flora Cuic632d792016-08-02 11:32:41 +080054#include "amdgpu_ttm.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040055#include "amdgpu_gds.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050056#include "amd_powerplay.h"
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -040057#include "amdgpu_acp.h"
Alex Deucher97b2e202015-04-20 16:51:00 -040058
Alex Deucherb80d8472015-08-16 22:55:02 -040059#include "gpu_scheduler.h"
60
Alex Deucher97b2e202015-04-20 16:51:00 -040061/*
62 * Modules parameters.
63 */
64extern int amdgpu_modeset;
65extern int amdgpu_vram_limit;
66extern int amdgpu_gart_size;
Marek Olšák95844d22016-08-17 23:49:27 +020067extern int amdgpu_moverate;
Alex Deucher97b2e202015-04-20 16:51:00 -040068extern int amdgpu_benchmarking;
69extern int amdgpu_testing;
70extern int amdgpu_audio;
71extern int amdgpu_disp_priority;
72extern int amdgpu_hw_i2c;
73extern int amdgpu_pcie_gen2;
74extern int amdgpu_msi;
75extern int amdgpu_lockup_timeout;
76extern int amdgpu_dpm;
77extern int amdgpu_smc_load_fw;
78extern int amdgpu_aspm;
79extern int amdgpu_runtime_pm;
Alex Deucher97b2e202015-04-20 16:51:00 -040080extern unsigned amdgpu_ip_block_mask;
81extern int amdgpu_bapm;
82extern int amdgpu_deep_color;
83extern int amdgpu_vm_size;
84extern int amdgpu_vm_block_size;
Christian Königd9c13152015-09-28 12:31:26 +020085extern int amdgpu_vm_fault_stop;
Christian Königb495bd32015-09-10 14:00:35 +020086extern int amdgpu_vm_debug;
Jammy Zhou1333f722015-07-30 16:36:58 +080087extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080088extern int amdgpu_sched_hw_submission;
Alex Deucher1f7371b2015-12-02 17:46:21 -050089extern int amdgpu_powerplay;
Huang Rui6bb6b292016-05-24 13:47:05 +080090extern int amdgpu_powercontainment;
Alex Deuchercd474ba2016-02-04 10:21:23 -050091extern unsigned amdgpu_pcie_gen_cap;
92extern unsigned amdgpu_pcie_lane_cap;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +020093extern unsigned amdgpu_cg_mask;
94extern unsigned amdgpu_pg_mask;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +020095extern char *amdgpu_disable_cu;
Rex Zhu66bc3f72016-07-28 17:36:35 +080096extern int amdgpu_sclk_deep_sleep_en;
Emily Deng9accf2f2016-08-10 16:01:25 +080097extern char *amdgpu_virtual_display;
Rex Zhu5141e9d2016-09-06 16:34:37 +080098extern unsigned amdgpu_pp_feature_mask;
Alex Deucher97b2e202015-04-20 16:51:00 -040099
Chunming Zhou4b559c92015-07-21 15:53:04 +0800100#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -0400101#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
102#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
103/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
104#define AMDGPU_IB_POOL_SIZE 16
105#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
106#define AMDGPUFB_CONN_LIMIT 4
107#define AMDGPU_BIOS_NUM_SCRATCH 8
108
Alex Deucher97b2e202015-04-20 16:51:00 -0400109/* max number of rings */
110#define AMDGPU_MAX_RINGS 16
111#define AMDGPU_MAX_GFX_RINGS 1
112#define AMDGPU_MAX_COMPUTE_RINGS 8
Alex Deucher6f0359f2016-08-24 17:15:33 -0400113#define AMDGPU_MAX_VCE_RINGS 3
Alex Deucher97b2e202015-04-20 16:51:00 -0400114
Jammy Zhou36f523a2015-09-01 12:54:27 +0800115/* max number of IP instances */
116#define AMDGPU_MAX_SDMA_INSTANCES 2
117
Alex Deucher97b2e202015-04-20 16:51:00 -0400118/* hardcode that limit for now */
119#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
120
121/* hard reset data */
122#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
123
124/* reset flags */
125#define AMDGPU_RESET_GFX (1 << 0)
126#define AMDGPU_RESET_COMPUTE (1 << 1)
127#define AMDGPU_RESET_DMA (1 << 2)
128#define AMDGPU_RESET_CP (1 << 3)
129#define AMDGPU_RESET_GRBM (1 << 4)
130#define AMDGPU_RESET_DMA1 (1 << 5)
131#define AMDGPU_RESET_RLC (1 << 6)
132#define AMDGPU_RESET_SEM (1 << 7)
133#define AMDGPU_RESET_IH (1 << 8)
134#define AMDGPU_RESET_VMC (1 << 9)
135#define AMDGPU_RESET_MC (1 << 10)
136#define AMDGPU_RESET_DISPLAY (1 << 11)
137#define AMDGPU_RESET_UVD (1 << 12)
138#define AMDGPU_RESET_VCE (1 << 13)
139#define AMDGPU_RESET_VCE1 (1 << 14)
140
Alex Deucher97b2e202015-04-20 16:51:00 -0400141/* GFX current status */
142#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
143#define AMDGPU_GFX_SAFE_MODE 0x00000001L
144#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
145#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
146#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
147
148/* max cursor sizes (in pixels) */
149#define CIK_CURSOR_WIDTH 128
150#define CIK_CURSOR_HEIGHT 128
151
152struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400153struct amdgpu_ib;
154struct amdgpu_vm;
155struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400156struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800157struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400158struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400159struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400160
161enum amdgpu_cp_irq {
162 AMDGPU_CP_IRQ_GFX_EOP = 0,
163 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
164 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
165 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
166 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
167 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
168 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
169 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
170 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
171
172 AMDGPU_CP_IRQ_LAST
173};
174
175enum amdgpu_sdma_irq {
176 AMDGPU_SDMA_IRQ_TRAP0 = 0,
177 AMDGPU_SDMA_IRQ_TRAP1,
178
179 AMDGPU_SDMA_IRQ_LAST
180};
181
182enum amdgpu_thermal_irq {
183 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
184 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
185
186 AMDGPU_THERMAL_IRQ_LAST
187};
188
Alex Deucher97b2e202015-04-20 16:51:00 -0400189int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400190 enum amd_ip_block_type block_type,
191 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400192int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400193 enum amd_ip_block_type block_type,
194 enum amd_powergating_state state);
Alex Deucher5dbbb602016-06-23 11:41:04 -0400195int amdgpu_wait_for_idle(struct amdgpu_device *adev,
196 enum amd_ip_block_type block_type);
197bool amdgpu_is_idle(struct amdgpu_device *adev,
198 enum amd_ip_block_type block_type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400199
200struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400201 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400202 u32 major;
203 u32 minor;
204 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400205 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400206};
207
208int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400209 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400210 u32 major, u32 minor);
211
212const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
213 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400214 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400215
216/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
217struct amdgpu_buffer_funcs {
218 /* maximum bytes in a single operation */
219 uint32_t copy_max_bytes;
220
221 /* number of dw to reserve per operation */
222 unsigned copy_num_dw;
223
224 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800225 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400226 /* src addr in bytes */
227 uint64_t src_offset,
228 /* dst addr in bytes */
229 uint64_t dst_offset,
230 /* number of byte to transfer */
231 uint32_t byte_count);
232
233 /* maximum bytes in a single operation */
234 uint32_t fill_max_bytes;
235
236 /* number of dw to reserve per operation */
237 unsigned fill_num_dw;
238
239 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800240 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400241 /* value to write to memory */
242 uint32_t src_data,
243 /* dst addr in bytes */
244 uint64_t dst_offset,
245 /* number of byte to fill */
246 uint32_t byte_count);
247};
248
249/* provided by hw blocks that can write ptes, e.g., sdma */
250struct amdgpu_vm_pte_funcs {
251 /* copy pte entries from GART */
252 void (*copy_pte)(struct amdgpu_ib *ib,
253 uint64_t pe, uint64_t src,
254 unsigned count);
255 /* write pte one entry at a time with addr mapping */
Christian Königde9ea7b2016-08-12 11:33:30 +0200256 void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
257 uint64_t value, unsigned count,
258 uint32_t incr);
Alex Deucher97b2e202015-04-20 16:51:00 -0400259 /* for linear pte/pde updates without addr mapping */
260 void (*set_pte_pde)(struct amdgpu_ib *ib,
261 uint64_t pe,
262 uint64_t addr, unsigned count,
263 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400264};
265
266/* provided by the gmc block */
267struct amdgpu_gart_funcs {
268 /* flush the vm tlb via mmio */
269 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
270 uint32_t vmid);
271 /* write pte/pde updates using the cpu */
272 int (*set_pte_pde)(struct amdgpu_device *adev,
273 void *cpu_pt_addr, /* cpu addr of page table */
274 uint32_t gpu_page_idx, /* pte/pde to update */
275 uint64_t addr, /* addr to write into pte/pde */
276 uint32_t flags); /* access flags */
277};
278
279/* provided by the ih block */
280struct amdgpu_ih_funcs {
281 /* ring read/write ptr handling, called from interrupt context */
282 u32 (*get_wptr)(struct amdgpu_device *adev);
283 void (*decode_iv)(struct amdgpu_device *adev,
284 struct amdgpu_iv_entry *entry);
285 void (*set_rptr)(struct amdgpu_device *adev);
286};
287
288/* provided by hw blocks that expose a ring buffer for commands */
289struct amdgpu_ring_funcs {
290 /* ring read/write ptr handling */
291 u32 (*get_rptr)(struct amdgpu_ring *ring);
292 u32 (*get_wptr)(struct amdgpu_ring *ring);
293 void (*set_wptr)(struct amdgpu_ring *ring);
294 /* validating and patching of IBs */
295 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
296 /* command emit functions */
297 void (*emit_ib)(struct amdgpu_ring *ring,
Christian Königd88bf582016-05-06 17:50:03 +0200298 struct amdgpu_ib *ib,
299 unsigned vm_id, bool ctx_switch);
Alex Deucher97b2e202015-04-20 16:51:00 -0400300 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800301 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100302 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400303 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
304 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200305 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800306 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400307 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
308 uint32_t gds_base, uint32_t gds_size,
309 uint32_t gws_base, uint32_t gws_size,
310 uint32_t oa_base, uint32_t oa_size);
311 /* testing functions */
312 int (*test_ring)(struct amdgpu_ring *ring);
Christian Königbbec97a2016-07-05 21:07:17 +0200313 int (*test_ib)(struct amdgpu_ring *ring, long timeout);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800314 /* insert NOP packets */
315 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100316 /* pad the indirect buffer to the necessary number of dw */
317 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800318 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
319 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Christian Königf06505b2016-07-20 13:49:34 +0200320 /* note usage for clock and power gating */
321 void (*begin_use)(struct amdgpu_ring *ring);
322 void (*end_use)(struct amdgpu_ring *ring);
Monk Liuc2167a62016-08-26 14:12:37 +0800323 void (*emit_switch_buffer) (struct amdgpu_ring *ring);
Monk Liu753ad492016-08-26 13:28:28 +0800324 void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
Alex Deucherb6384ff2016-09-16 10:55:50 -0400325 unsigned (*get_emit_ib_size) (struct amdgpu_ring *ring);
326 unsigned (*get_dma_frame_size) (struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400327};
328
329/*
330 * BIOS.
331 */
332bool amdgpu_get_bios(struct amdgpu_device *adev);
333bool amdgpu_read_bios(struct amdgpu_device *adev);
334
335/*
336 * Dummy page
337 */
338struct amdgpu_dummy_page {
339 struct page *page;
340 dma_addr_t addr;
341};
342int amdgpu_dummy_page_init(struct amdgpu_device *adev);
343void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
344
345
346/*
347 * Clocks
348 */
349
350#define AMDGPU_MAX_PPLL 3
351
352struct amdgpu_clock {
353 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
354 struct amdgpu_pll spll;
355 struct amdgpu_pll mpll;
356 /* 10 Khz units */
357 uint32_t default_mclk;
358 uint32_t default_sclk;
359 uint32_t default_dispclk;
360 uint32_t current_dispclk;
361 uint32_t dp_extclk;
362 uint32_t max_pixel_clock;
363};
364
365/*
366 * Fences.
367 */
368struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400369 uint64_t gpu_addr;
370 volatile uint32_t *cpu_addr;
371 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100372 uint32_t sync_seq;
373 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400374 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400375 struct amdgpu_irq_src *irq_src;
376 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100377 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100378 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100379 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100380 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400381};
382
383/* some special values for the owner field */
384#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
385#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400386
Chunming Zhou890ee232015-06-01 14:35:03 +0800387#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
388#define AMDGPU_FENCE_FLAG_INT (1 << 1)
389
Alex Deucher97b2e202015-04-20 16:51:00 -0400390int amdgpu_fence_driver_init(struct amdgpu_device *adev);
391void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
392void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
393
Christian Könige6151a02016-03-15 14:52:26 +0100394int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
395 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400396int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
397 struct amdgpu_irq_src *irq_src,
398 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400399void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
400void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100401int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400402void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400403int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
404unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
405
Alex Deucher97b2e202015-04-20 16:51:00 -0400406/*
Flora Cuic632d792016-08-02 11:32:41 +0800407 * BO.
Alex Deucher97b2e202015-04-20 16:51:00 -0400408 */
Christian König29b32592016-04-15 17:19:16 +0200409
Alex Deucher97b2e202015-04-20 16:51:00 -0400410struct amdgpu_bo_list_entry {
411 struct amdgpu_bo *robj;
412 struct ttm_validate_buffer tv;
413 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400414 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100415 struct page **user_pages;
416 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400417};
418
419struct amdgpu_bo_va_mapping {
420 struct list_head list;
421 struct interval_tree_node it;
422 uint64_t offset;
423 uint32_t flags;
424};
425
426/* bo virtual addresses in a specific vm */
427struct amdgpu_bo_va {
428 /* protected by bo being reserved */
429 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800430 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400431 unsigned ref_count;
432
Christian König7fc11952015-07-30 11:53:42 +0200433 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400434 struct list_head vm_status;
435
Christian König7fc11952015-07-30 11:53:42 +0200436 /* mappings for this bo_va */
437 struct list_head invalids;
438 struct list_head valids;
439
Alex Deucher97b2e202015-04-20 16:51:00 -0400440 /* constant after initialization */
441 struct amdgpu_vm *vm;
442 struct amdgpu_bo *bo;
443};
444
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800445#define AMDGPU_GEM_DOMAIN_MAX 0x3
446
Alex Deucher97b2e202015-04-20 16:51:00 -0400447struct amdgpu_bo {
448 /* Protected by gem.mutex */
449 struct list_head list;
450 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100451 u32 prefered_domains;
452 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800453 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400454 struct ttm_placement placement;
455 struct ttm_buffer_object tbo;
456 struct ttm_bo_kmap_obj kmap;
457 u64 flags;
458 unsigned pin_count;
459 void *kptr;
460 u64 tiling_flags;
461 u64 metadata_flags;
462 void *metadata;
463 u32 metadata_size;
464 /* list of all virtual address to which this bo
465 * is associated to
466 */
467 struct list_head va;
468 /* Constant after initialization */
469 struct amdgpu_device *adev;
470 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100471 struct amdgpu_bo *parent;
Chunming Zhoue7893c42016-07-26 14:13:21 +0800472 struct amdgpu_bo *shadow;
Alex Deucher97b2e202015-04-20 16:51:00 -0400473
474 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400475 struct amdgpu_mn *mn;
476 struct list_head mn_list;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +0800477 struct list_head shadow_list;
Alex Deucher97b2e202015-04-20 16:51:00 -0400478};
479#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
480
481void amdgpu_gem_object_free(struct drm_gem_object *obj);
482int amdgpu_gem_object_open(struct drm_gem_object *obj,
483 struct drm_file *file_priv);
484void amdgpu_gem_object_close(struct drm_gem_object *obj,
485 struct drm_file *file_priv);
486unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
487struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200488struct drm_gem_object *
489amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
490 struct dma_buf_attachment *attach,
491 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400492struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
493 struct drm_gem_object *gobj,
494 int flags);
495int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
496void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
497struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
498void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
499void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
500int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
501
502/* sub-allocation manager, it has to be protected by another lock.
503 * By conception this is an helper for other part of the driver
504 * like the indirect buffer or semaphore, which both have their
505 * locking.
506 *
507 * Principe is simple, we keep a list of sub allocation in offset
508 * order (first entry has offset == 0, last entry has the highest
509 * offset).
510 *
511 * When allocating new object we first check if there is room at
512 * the end total_size - (last_object_offset + last_object_size) >=
513 * alloc_size. If so we allocate new object there.
514 *
515 * When there is not enough room at the end, we start waiting for
516 * each sub object until we reach object_offset+object_size >=
517 * alloc_size, this object then become the sub object we return.
518 *
519 * Alignment can't be bigger than page size.
520 *
521 * Hole are not considered for allocation to keep things simple.
522 * Assumption is that there won't be hole (all object on same
523 * alignment).
524 */
Christian König6ba60b82016-03-11 14:50:08 +0100525
526#define AMDGPU_SA_NUM_FENCE_LISTS 32
527
Alex Deucher97b2e202015-04-20 16:51:00 -0400528struct amdgpu_sa_manager {
529 wait_queue_head_t wq;
530 struct amdgpu_bo *bo;
531 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100532 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400533 struct list_head olist;
534 unsigned size;
535 uint64_t gpu_addr;
536 void *cpu_ptr;
537 uint32_t domain;
538 uint32_t align;
539};
540
Alex Deucher97b2e202015-04-20 16:51:00 -0400541/* sub-allocation buffer */
542struct amdgpu_sa_bo {
543 struct list_head olist;
544 struct list_head flist;
545 struct amdgpu_sa_manager *manager;
546 unsigned soffset;
547 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800548 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400549};
550
551/*
552 * GEM objects.
553 */
Christian König418aa0c2016-02-15 16:59:57 +0100554void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400555int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
556 int alignment, u32 initial_domain,
557 u64 flags, bool kernel,
558 struct drm_gem_object **obj);
559
560int amdgpu_mode_dumb_create(struct drm_file *file_priv,
561 struct drm_device *dev,
562 struct drm_mode_create_dumb *args);
563int amdgpu_mode_dumb_mmap(struct drm_file *filp,
564 struct drm_device *dev,
565 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400566/*
567 * Synchronization
568 */
569struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800570 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800571 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400572};
573
574void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200575int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
576 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400577int amdgpu_sync_resv(struct amdgpu_device *adev,
578 struct amdgpu_sync *sync,
579 struct reservation_object *resv,
580 void *owner);
Christian König1fbb2e92016-06-01 10:47:36 +0200581struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
582 struct amdgpu_ring *ring);
Christian Könige61235d2015-08-25 11:05:36 +0200583struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100584void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100585int amdgpu_sync_init(void);
586void amdgpu_sync_fini(void);
Rex Zhud573de22016-05-12 13:27:28 +0800587int amdgpu_fence_slab_init(void);
588void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400589
590/*
591 * GART structures, functions & helpers
592 */
593struct amdgpu_mc;
594
595#define AMDGPU_GPU_PAGE_SIZE 4096
596#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
597#define AMDGPU_GPU_PAGE_SHIFT 12
598#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
599
600struct amdgpu_gart {
601 dma_addr_t table_addr;
602 struct amdgpu_bo *robj;
603 void *ptr;
604 unsigned num_gpu_pages;
605 unsigned num_cpu_pages;
606 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200607#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400608 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200609#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400610 bool ready;
611 const struct amdgpu_gart_funcs *gart_funcs;
612};
613
614int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
615void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
616int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
617void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
618int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
619void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
620int amdgpu_gart_init(struct amdgpu_device *adev);
621void amdgpu_gart_fini(struct amdgpu_device *adev);
622void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
623 int pages);
624int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
625 int pages, struct page **pagelist,
626 dma_addr_t *dma_addr, uint32_t flags);
Chunming Zhou2c0d7312016-08-30 16:36:25 +0800627int amdgpu_ttm_recover_gart(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400628
629/*
630 * GPU MC structures, functions & helpers
631 */
632struct amdgpu_mc {
633 resource_size_t aper_size;
634 resource_size_t aper_base;
635 resource_size_t agp_base;
636 /* for some chips with <= 32MB we need to lie
637 * about vram size near mc fb location */
638 u64 mc_vram_size;
639 u64 visible_vram_size;
640 u64 gtt_size;
641 u64 gtt_start;
642 u64 gtt_end;
643 u64 vram_start;
644 u64 vram_end;
645 unsigned vram_width;
646 u64 real_vram_size;
647 int vram_mtrr;
648 u64 gtt_base_align;
649 u64 mc_mask;
650 const struct firmware *fw; /* MC firmware */
651 uint32_t fw_version;
652 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800653 uint32_t vram_type;
Chunming Zhou50b01972016-07-18 16:59:24 +0800654 uint32_t srbm_soft_reset;
655 struct amdgpu_mode_mc_save save;
Alex Deucher97b2e202015-04-20 16:51:00 -0400656};
657
658/*
659 * GPU doorbell structures, functions & helpers
660 */
661typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
662{
663 AMDGPU_DOORBELL_KIQ = 0x000,
664 AMDGPU_DOORBELL_HIQ = 0x001,
665 AMDGPU_DOORBELL_DIQ = 0x002,
666 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
667 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
668 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
669 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
670 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
671 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
672 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
673 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
674 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
675 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
676 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
677 AMDGPU_DOORBELL_IH = 0x1E8,
678 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
679 AMDGPU_DOORBELL_INVALID = 0xFFFF
680} AMDGPU_DOORBELL_ASSIGNMENT;
681
682struct amdgpu_doorbell {
683 /* doorbell mmio */
684 resource_size_t base;
685 resource_size_t size;
686 u32 __iomem *ptr;
687 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
688};
689
690void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
691 phys_addr_t *aperture_base,
692 size_t *aperture_size,
693 size_t *start_offset);
694
695/*
696 * IRQS.
697 */
698
699struct amdgpu_flip_work {
Michel Dänzer325cbba2016-08-04 12:39:37 +0900700 struct delayed_work flip_work;
Alex Deucher97b2e202015-04-20 16:51:00 -0400701 struct work_struct unpin_work;
702 struct amdgpu_device *adev;
703 int crtc_id;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900704 u32 target_vblank;
Alex Deucher97b2e202015-04-20 16:51:00 -0400705 uint64_t base;
706 struct drm_pending_vblank_event *event;
707 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200708 struct fence *excl;
709 unsigned shared_count;
710 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100711 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400712 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400713};
714
715
716/*
717 * CP & rings.
718 */
719
720struct amdgpu_ib {
721 struct amdgpu_sa_bo *sa_bo;
722 uint32_t length_dw;
723 uint64_t gpu_addr;
724 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800725 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400726};
727
728enum amdgpu_ring_type {
729 AMDGPU_RING_TYPE_GFX,
730 AMDGPU_RING_TYPE_COMPUTE,
731 AMDGPU_RING_TYPE_SDMA,
732 AMDGPU_RING_TYPE_UVD,
733 AMDGPU_RING_TYPE_VCE
734};
735
Nils Wallménius62250a92016-04-10 16:30:00 +0200736extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800737
Christian König50838c82016-02-03 13:44:52 +0100738int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800739 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100740int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
741 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800742
Christian Königa5fb4ec2016-06-29 15:10:31 +0200743void amdgpu_job_free_resources(struct amdgpu_job *job);
Christian König50838c82016-02-03 13:44:52 +0100744void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100745int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100746 struct amd_sched_entity *entity, void *owner,
747 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800748
Alex Deucher97b2e202015-04-20 16:51:00 -0400749struct amdgpu_ring {
750 struct amdgpu_device *adev;
751 const struct amdgpu_ring_funcs *funcs;
752 struct amdgpu_fence_driver fence_drv;
Christian Königedf600d2016-05-03 15:54:54 +0200753 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400754
Alex Deucher97b2e202015-04-20 16:51:00 -0400755 struct amdgpu_bo *ring_obj;
756 volatile uint32_t *ring;
757 unsigned rptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400758 unsigned wptr;
759 unsigned wptr_old;
760 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100761 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400762 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400763 uint64_t gpu_addr;
764 uint32_t align_mask;
765 uint32_t ptr_mask;
766 bool ready;
767 u32 nop;
768 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400769 u32 me;
770 u32 pipe;
771 u32 queue;
772 struct amdgpu_bo *mqd_obj;
773 u32 doorbell_index;
774 bool use_doorbell;
775 unsigned wptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400776 unsigned fence_offs;
Christian Königaa3b73f2016-05-03 15:17:40 +0200777 uint64_t current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400778 enum amdgpu_ring_type type;
779 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800780 unsigned cond_exe_offs;
Christian König92c023c2016-07-19 14:34:17 +0200781 u64 cond_exe_gpu_addr;
782 volatile u32 *cond_exe_cpu_addr;
Monk Liua909c6b2016-06-14 12:02:21 -0400783#if defined(CONFIG_DEBUG_FS)
784 struct dentry *ent;
785#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400786};
787
788/*
789 * VM
790 */
791
792/* maximum number of VMIDs */
793#define AMDGPU_NUM_VM 16
794
Christian König96105e52016-08-12 12:59:59 +0200795/* Maximum number of PTEs the hardware can write with one command */
796#define AMDGPU_VM_MAX_UPDATE_SIZE 0x3FFFF
797
Alex Deucher97b2e202015-04-20 16:51:00 -0400798/* number of entries in page table */
799#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
800
801/* PTBs (Page Table Blocks) need to be aligned to 32K */
802#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
Alex Deucher97b2e202015-04-20 16:51:00 -0400803
Christian König1303c732016-08-03 17:46:42 +0200804/* LOG2 number of continuous pages for the fragment field */
805#define AMDGPU_LOG2_PAGES_PER_FRAG 4
806
Alex Deucher97b2e202015-04-20 16:51:00 -0400807#define AMDGPU_PTE_VALID (1 << 0)
808#define AMDGPU_PTE_SYSTEM (1 << 1)
809#define AMDGPU_PTE_SNOOPED (1 << 2)
810
811/* VI only */
812#define AMDGPU_PTE_EXECUTABLE (1 << 4)
813
814#define AMDGPU_PTE_READABLE (1 << 5)
815#define AMDGPU_PTE_WRITEABLE (1 << 6)
816
Christian König1303c732016-08-03 17:46:42 +0200817#define AMDGPU_PTE_FRAG(x) ((x & 0x1f) << 7)
Alex Deucher97b2e202015-04-20 16:51:00 -0400818
Christian Königd9c13152015-09-28 12:31:26 +0200819/* How to programm VM fault handling */
820#define AMDGPU_VM_FAULT_STOP_NEVER 0
821#define AMDGPU_VM_FAULT_STOP_FIRST 1
822#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
823
Alex Deucher97b2e202015-04-20 16:51:00 -0400824struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100825 struct amdgpu_bo_list_entry entry;
826 uint64_t addr;
Chunming Zhou6557e3d2016-08-15 11:36:54 +0800827 uint64_t shadow_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400828};
829
Alex Deucher97b2e202015-04-20 16:51:00 -0400830struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100831 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400832 struct rb_root va;
833
Christian König7fc11952015-07-30 11:53:42 +0200834 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400835 spinlock_t status_lock;
836
837 /* BOs moved, but not yet updated in the PT */
838 struct list_head invalidated;
839
Christian König7fc11952015-07-30 11:53:42 +0200840 /* BOs cleared in the PT because of a move */
841 struct list_head cleared;
842
843 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400844 struct list_head freed;
845
846 /* contains the page directory */
847 struct amdgpu_bo *page_directory;
848 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200849 struct fence *page_directory_fence;
Christian König5a712a82016-06-21 16:28:15 +0200850 uint64_t last_eviction_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400851
852 /* array of page tables, one for each page directory entry */
853 struct amdgpu_vm_pt *page_tables;
854
855 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100856 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100857
jimqu81d75a32015-12-04 17:17:00 +0800858 /* protecting freed */
859 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100860
861 /* Scheduler entity for page table updates */
862 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800863
864 /* client id */
865 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400866};
867
Christian Königbcb1ba32016-03-08 15:40:11 +0100868struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100869 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100870 struct fence *first;
871 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100872 struct fence *last_flush;
Christian König0ea54b92016-05-04 10:20:01 +0200873 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100874
Christian Königbcb1ba32016-03-08 15:40:11 +0100875 uint64_t pd_gpu_addr;
876 /* last flushed PD/PT update */
877 struct fence *flushed_updates;
878
Chunming Zhou6adb0512016-06-27 17:06:01 +0800879 uint32_t current_gpu_reset_count;
880
Christian König971fe9a92016-03-01 15:09:25 +0100881 uint32_t gds_base;
882 uint32_t gds_size;
883 uint32_t gws_base;
884 uint32_t gws_size;
885 uint32_t oa_base;
886 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100887};
Christian König8d0a7ce2015-11-03 20:58:50 +0100888
Christian Königa9a78b32016-01-21 10:19:11 +0100889struct amdgpu_vm_manager {
890 /* Handling of VMIDs */
891 struct mutex lock;
892 unsigned num_ids;
893 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100894 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100895
Christian König1fbb2e92016-06-01 10:47:36 +0200896 /* Handling of VM fences */
897 u64 fence_context;
898 unsigned seqno[AMDGPU_MAX_RINGS];
899
Christian König8b4fb002015-11-15 16:04:16 +0100900 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400901 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100902 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400903 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100904 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400905 /* vm pte handling */
906 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100907 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
908 unsigned vm_pte_num_rings;
909 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800910 /* client id counter */
911 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400912};
913
Christian Königa9a78b32016-01-21 10:19:11 +0100914void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100915void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100916int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
917void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100918void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
919 struct list_head *validated,
920 struct amdgpu_bo_list_entry *entry);
Christian König5a712a82016-06-21 16:28:15 +0200921void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
922 struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100923void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
924 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100925int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100926 struct amdgpu_sync *sync, struct fence *fence,
Chunming Zhoufd53be32016-07-01 17:59:01 +0800927 struct amdgpu_job *job);
928int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
Christian König971fe9a92016-03-01 15:09:25 +0100929void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian König8b4fb002015-11-15 16:04:16 +0100930int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
931 struct amdgpu_vm *vm);
932int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
933 struct amdgpu_vm *vm);
934int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
935 struct amdgpu_sync *sync);
936int amdgpu_vm_bo_update(struct amdgpu_device *adev,
937 struct amdgpu_bo_va *bo_va,
Christian König99e124f2016-08-16 14:43:17 +0200938 bool clear);
Christian König8b4fb002015-11-15 16:04:16 +0100939void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
940 struct amdgpu_bo *bo);
941struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
942 struct amdgpu_bo *bo);
943struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
944 struct amdgpu_vm *vm,
945 struct amdgpu_bo *bo);
946int amdgpu_vm_bo_map(struct amdgpu_device *adev,
947 struct amdgpu_bo_va *bo_va,
948 uint64_t addr, uint64_t offset,
949 uint64_t size, uint32_t flags);
950int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
951 struct amdgpu_bo_va *bo_va,
952 uint64_t addr);
953void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
954 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100955
Alex Deucher97b2e202015-04-20 16:51:00 -0400956/*
957 * context related structures
958 */
959
Christian König21c16bf2015-07-07 17:24:49 +0200960struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200961 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800962 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200963 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200964};
965
Alex Deucher97b2e202015-04-20 16:51:00 -0400966struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400967 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800968 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400969 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200970 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800971 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200972 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Monk Liu753ad492016-08-26 13:28:28 +0800973 bool preamble_presented;
Alex Deucher97b2e202015-04-20 16:51:00 -0400974};
975
976struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400977 struct amdgpu_device *adev;
978 struct mutex lock;
979 /* protected by lock */
980 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400981};
982
Alex Deucher0b492a42015-08-16 22:48:26 -0400983struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
984int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
985
Christian König21c16bf2015-07-07 17:24:49 +0200986uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200987 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200988struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
989 struct amdgpu_ring *ring, uint64_t seq);
990
Alex Deucher0b492a42015-08-16 22:48:26 -0400991int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
992 struct drm_file *filp);
993
Christian Königefd4ccb2015-08-04 16:20:31 +0200994void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
995void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400996
Alex Deucher97b2e202015-04-20 16:51:00 -0400997/*
998 * file private structure
999 */
1000
1001struct amdgpu_fpriv {
1002 struct amdgpu_vm vm;
1003 struct mutex bo_list_lock;
1004 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001005 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001006};
1007
1008/*
1009 * residency list
1010 */
1011
1012struct amdgpu_bo_list {
1013 struct mutex lock;
1014 struct amdgpu_bo *gds_obj;
1015 struct amdgpu_bo *gws_obj;
1016 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001017 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001018 unsigned num_entries;
1019 struct amdgpu_bo_list_entry *array;
1020};
1021
1022struct amdgpu_bo_list *
1023amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001024void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1025 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001026void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1027void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1028
1029/*
1030 * GFX stuff
1031 */
1032#include "clearstate_defs.h"
1033
Alex Deucher79e54122016-04-08 15:45:13 -04001034struct amdgpu_rlc_funcs {
1035 void (*enter_safe_mode)(struct amdgpu_device *adev);
1036 void (*exit_safe_mode)(struct amdgpu_device *adev);
1037};
1038
Alex Deucher97b2e202015-04-20 16:51:00 -04001039struct amdgpu_rlc {
1040 /* for power gating */
1041 struct amdgpu_bo *save_restore_obj;
1042 uint64_t save_restore_gpu_addr;
1043 volatile uint32_t *sr_ptr;
1044 const u32 *reg_list;
1045 u32 reg_list_size;
1046 /* for clear state */
1047 struct amdgpu_bo *clear_state_obj;
1048 uint64_t clear_state_gpu_addr;
1049 volatile uint32_t *cs_ptr;
1050 const struct cs_section_def *cs_data;
1051 u32 clear_state_size;
1052 /* for cp tables */
1053 struct amdgpu_bo *cp_table_obj;
1054 uint64_t cp_table_gpu_addr;
1055 volatile uint32_t *cp_table_ptr;
1056 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001057
1058 /* safe mode for updating CG/PG state */
1059 bool in_safe_mode;
1060 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001061
1062 /* for firmware data */
1063 u32 save_and_restore_offset;
1064 u32 clear_state_descriptor_offset;
1065 u32 avail_scratch_ram_locations;
1066 u32 reg_restore_list_size;
1067 u32 reg_list_format_start;
1068 u32 reg_list_format_separate_start;
1069 u32 starting_offsets_start;
1070 u32 reg_list_format_size_bytes;
1071 u32 reg_list_size_bytes;
1072
1073 u32 *register_list_format;
1074 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001075};
1076
1077struct amdgpu_mec {
1078 struct amdgpu_bo *hpd_eop_obj;
1079 u64 hpd_eop_gpu_addr;
1080 u32 num_pipe;
1081 u32 num_mec;
1082 u32 num_queue;
1083};
1084
1085/*
1086 * GPU scratch registers structures, functions & helpers
1087 */
1088struct amdgpu_scratch {
1089 unsigned num_reg;
1090 uint32_t reg_base;
1091 bool free[32];
1092 uint32_t reg[32];
1093};
1094
1095/*
1096 * GFX configurations
1097 */
1098struct amdgpu_gca_config {
1099 unsigned max_shader_engines;
1100 unsigned max_tile_pipes;
1101 unsigned max_cu_per_sh;
1102 unsigned max_sh_per_se;
1103 unsigned max_backends_per_se;
1104 unsigned max_texture_channel_caches;
1105 unsigned max_gprs;
1106 unsigned max_gs_threads;
1107 unsigned max_hw_contexts;
1108 unsigned sc_prim_fifo_size_frontend;
1109 unsigned sc_prim_fifo_size_backend;
1110 unsigned sc_hiz_tile_fifo_size;
1111 unsigned sc_earlyz_tile_fifo_size;
1112
1113 unsigned num_tile_pipes;
1114 unsigned backend_enable_mask;
1115 unsigned mem_max_burst_length_bytes;
1116 unsigned mem_row_size_in_kb;
1117 unsigned shader_engine_tile_size;
1118 unsigned num_gpus;
1119 unsigned multi_gpu_tile_size;
1120 unsigned mc_arb_ramcfg;
1121 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001122 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001123
1124 uint32_t tile_mode_array[32];
1125 uint32_t macrotile_mode_array[16];
1126};
1127
Alex Deucher7dae69a2016-05-03 16:25:53 -04001128struct amdgpu_cu_info {
1129 uint32_t number; /* total active CU number */
1130 uint32_t ao_cu_mask;
1131 uint32_t bitmap[4][4];
1132};
1133
Alex Deucherb95e31f2016-07-07 15:01:42 -04001134struct amdgpu_gfx_funcs {
1135 /* get the gpu clock counter */
1136 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -04001137 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Alex Deucherb95e31f2016-07-07 15:01:42 -04001138};
1139
Alex Deucher97b2e202015-04-20 16:51:00 -04001140struct amdgpu_gfx {
1141 struct mutex gpu_clock_mutex;
1142 struct amdgpu_gca_config config;
1143 struct amdgpu_rlc rlc;
1144 struct amdgpu_mec mec;
1145 struct amdgpu_scratch scratch;
1146 const struct firmware *me_fw; /* ME firmware */
1147 uint32_t me_fw_version;
1148 const struct firmware *pfp_fw; /* PFP firmware */
1149 uint32_t pfp_fw_version;
1150 const struct firmware *ce_fw; /* CE firmware */
1151 uint32_t ce_fw_version;
1152 const struct firmware *rlc_fw; /* RLC firmware */
1153 uint32_t rlc_fw_version;
1154 const struct firmware *mec_fw; /* MEC firmware */
1155 uint32_t mec_fw_version;
1156 const struct firmware *mec2_fw; /* MEC2 firmware */
1157 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001158 uint32_t me_feature_version;
1159 uint32_t ce_feature_version;
1160 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001161 uint32_t rlc_feature_version;
1162 uint32_t mec_feature_version;
1163 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001164 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1165 unsigned num_gfx_rings;
1166 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1167 unsigned num_compute_rings;
1168 struct amdgpu_irq_src eop_irq;
1169 struct amdgpu_irq_src priv_reg_irq;
1170 struct amdgpu_irq_src priv_inst_irq;
1171 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001172 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001173 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001174 unsigned ce_ram_size;
1175 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001176 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +08001177
1178 /* reset mask */
1179 uint32_t grbm_soft_reset;
1180 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001181};
1182
Christian Königb07c60c2016-01-31 12:29:04 +01001183int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001184 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001185void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1186 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001187int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001188 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001189 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001190int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1191void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1192int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001193int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001194void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001195void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001196void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001197void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001198int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1199 unsigned ring_size, u32 nop, u32 align_mask,
1200 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1201 enum amdgpu_ring_type ring_type);
1202void amdgpu_ring_fini(struct amdgpu_ring *ring);
1203
1204/*
1205 * CS.
1206 */
1207struct amdgpu_cs_chunk {
1208 uint32_t chunk_id;
1209 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001210 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001211};
1212
1213struct amdgpu_cs_parser {
1214 struct amdgpu_device *adev;
1215 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001216 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001217
Alex Deucher97b2e202015-04-20 16:51:00 -04001218 /* chunks */
1219 unsigned nchunks;
1220 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001221
Christian König50838c82016-02-03 13:44:52 +01001222 /* scheduler job object */
1223 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001224
Christian Königc3cca412015-12-15 14:41:33 +01001225 /* buffer objects */
1226 struct ww_acquire_ctx ticket;
1227 struct amdgpu_bo_list *bo_list;
1228 struct amdgpu_bo_list_entry vm_pd;
1229 struct list_head validated;
1230 struct fence *fence;
1231 uint64_t bytes_moved_threshold;
1232 uint64_t bytes_moved;
Christian König662bfa62016-09-01 12:13:18 +02001233 struct amdgpu_bo_list_entry *evictable;
Alex Deucher97b2e202015-04-20 16:51:00 -04001234
1235 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001236 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001237};
1238
Monk Liu753ad492016-08-26 13:28:28 +08001239#define AMDGPU_PREAMBLE_IB_PRESENT (1 << 0) /* bit set means command submit involves a preamble IB */
1240#define AMDGPU_PREAMBLE_IB_PRESENT_FIRST (1 << 1) /* bit set means preamble IB is first presented in belonging context */
1241#define AMDGPU_HAVE_CTX_SWITCH (1 << 2) /* bit set means context switch occured */
1242
Chunming Zhoubb977d32015-08-18 15:16:40 +08001243struct amdgpu_job {
1244 struct amd_sched_job base;
1245 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001246 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001247 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001248 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001249 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001250 struct fence *fence; /* the hw fence */
Monk Liu753ad492016-08-26 13:28:28 +08001251 uint32_t preamble_status;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001252 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001253 void *owner;
Monk Liu3aecd242016-08-25 15:40:48 +08001254 uint64_t fence_ctx; /* the fence_context this job uses */
Chunming Zhoufd53be32016-07-01 17:59:01 +08001255 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +02001256 unsigned vm_id;
1257 uint64_t vm_pd_addr;
1258 uint32_t gds_base, gds_size;
1259 uint32_t gws_base, gws_size;
1260 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001261
1262 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +02001263 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +02001264 uint64_t uf_sequence;
1265
Chunming Zhoubb977d32015-08-18 15:16:40 +08001266};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001267#define to_amdgpu_job(sched_job) \
1268 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001269
Christian König7270f832016-01-31 11:00:41 +01001270static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1271 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001272{
Christian König50838c82016-02-03 13:44:52 +01001273 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001274}
1275
Christian König7270f832016-01-31 11:00:41 +01001276static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1277 uint32_t ib_idx, int idx,
1278 uint32_t value)
1279{
Christian König50838c82016-02-03 13:44:52 +01001280 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001281}
1282
Alex Deucher97b2e202015-04-20 16:51:00 -04001283/*
1284 * Writeback
1285 */
1286#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1287
1288struct amdgpu_wb {
1289 struct amdgpu_bo *wb_obj;
1290 volatile uint32_t *wb;
1291 uint64_t gpu_addr;
1292 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1293 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1294};
1295
1296int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1297void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1298
Alex Deucher97b2e202015-04-20 16:51:00 -04001299
Alex Deucher97b2e202015-04-20 16:51:00 -04001300
1301enum amdgpu_int_thermal_type {
1302 THERMAL_TYPE_NONE,
1303 THERMAL_TYPE_EXTERNAL,
1304 THERMAL_TYPE_EXTERNAL_GPIO,
1305 THERMAL_TYPE_RV6XX,
1306 THERMAL_TYPE_RV770,
1307 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1308 THERMAL_TYPE_EVERGREEN,
1309 THERMAL_TYPE_SUMO,
1310 THERMAL_TYPE_NI,
1311 THERMAL_TYPE_SI,
1312 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1313 THERMAL_TYPE_CI,
1314 THERMAL_TYPE_KV,
1315};
1316
1317enum amdgpu_dpm_auto_throttle_src {
1318 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1319 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1320};
1321
1322enum amdgpu_dpm_event_src {
1323 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1324 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1325 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1326 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1327 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1328};
1329
1330#define AMDGPU_MAX_VCE_LEVELS 6
1331
1332enum amdgpu_vce_level {
1333 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1334 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1335 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1336 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1337 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1338 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1339};
1340
1341struct amdgpu_ps {
1342 u32 caps; /* vbios flags */
1343 u32 class; /* vbios flags */
1344 u32 class2; /* vbios flags */
1345 /* UVD clocks */
1346 u32 vclk;
1347 u32 dclk;
1348 /* VCE clocks */
1349 u32 evclk;
1350 u32 ecclk;
1351 bool vce_active;
1352 enum amdgpu_vce_level vce_level;
1353 /* asic priv */
1354 void *ps_priv;
1355};
1356
1357struct amdgpu_dpm_thermal {
1358 /* thermal interrupt work */
1359 struct work_struct work;
1360 /* low temperature threshold */
1361 int min_temp;
1362 /* high temperature threshold */
1363 int max_temp;
1364 /* was last interrupt low to high or high to low */
1365 bool high_to_low;
1366 /* interrupt source */
1367 struct amdgpu_irq_src irq;
1368};
1369
1370enum amdgpu_clk_action
1371{
1372 AMDGPU_SCLK_UP = 1,
1373 AMDGPU_SCLK_DOWN
1374};
1375
1376struct amdgpu_blacklist_clocks
1377{
1378 u32 sclk;
1379 u32 mclk;
1380 enum amdgpu_clk_action action;
1381};
1382
1383struct amdgpu_clock_and_voltage_limits {
1384 u32 sclk;
1385 u32 mclk;
1386 u16 vddc;
1387 u16 vddci;
1388};
1389
1390struct amdgpu_clock_array {
1391 u32 count;
1392 u32 *values;
1393};
1394
1395struct amdgpu_clock_voltage_dependency_entry {
1396 u32 clk;
1397 u16 v;
1398};
1399
1400struct amdgpu_clock_voltage_dependency_table {
1401 u32 count;
1402 struct amdgpu_clock_voltage_dependency_entry *entries;
1403};
1404
1405union amdgpu_cac_leakage_entry {
1406 struct {
1407 u16 vddc;
1408 u32 leakage;
1409 };
1410 struct {
1411 u16 vddc1;
1412 u16 vddc2;
1413 u16 vddc3;
1414 };
1415};
1416
1417struct amdgpu_cac_leakage_table {
1418 u32 count;
1419 union amdgpu_cac_leakage_entry *entries;
1420};
1421
1422struct amdgpu_phase_shedding_limits_entry {
1423 u16 voltage;
1424 u32 sclk;
1425 u32 mclk;
1426};
1427
1428struct amdgpu_phase_shedding_limits_table {
1429 u32 count;
1430 struct amdgpu_phase_shedding_limits_entry *entries;
1431};
1432
1433struct amdgpu_uvd_clock_voltage_dependency_entry {
1434 u32 vclk;
1435 u32 dclk;
1436 u16 v;
1437};
1438
1439struct amdgpu_uvd_clock_voltage_dependency_table {
1440 u8 count;
1441 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1442};
1443
1444struct amdgpu_vce_clock_voltage_dependency_entry {
1445 u32 ecclk;
1446 u32 evclk;
1447 u16 v;
1448};
1449
1450struct amdgpu_vce_clock_voltage_dependency_table {
1451 u8 count;
1452 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1453};
1454
1455struct amdgpu_ppm_table {
1456 u8 ppm_design;
1457 u16 cpu_core_number;
1458 u32 platform_tdp;
1459 u32 small_ac_platform_tdp;
1460 u32 platform_tdc;
1461 u32 small_ac_platform_tdc;
1462 u32 apu_tdp;
1463 u32 dgpu_tdp;
1464 u32 dgpu_ulv_power;
1465 u32 tj_max;
1466};
1467
1468struct amdgpu_cac_tdp_table {
1469 u16 tdp;
1470 u16 configurable_tdp;
1471 u16 tdc;
1472 u16 battery_power_limit;
1473 u16 small_power_limit;
1474 u16 low_cac_leakage;
1475 u16 high_cac_leakage;
1476 u16 maximum_power_delivery_limit;
1477};
1478
1479struct amdgpu_dpm_dynamic_state {
1480 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1481 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1482 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1483 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1484 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1485 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1486 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1487 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1488 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1489 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1490 struct amdgpu_clock_array valid_sclk_values;
1491 struct amdgpu_clock_array valid_mclk_values;
1492 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1493 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1494 u32 mclk_sclk_ratio;
1495 u32 sclk_mclk_delta;
1496 u16 vddc_vddci_delta;
1497 u16 min_vddc_for_pcie_gen2;
1498 struct amdgpu_cac_leakage_table cac_leakage_table;
1499 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1500 struct amdgpu_ppm_table *ppm_table;
1501 struct amdgpu_cac_tdp_table *cac_tdp_table;
1502};
1503
1504struct amdgpu_dpm_fan {
1505 u16 t_min;
1506 u16 t_med;
1507 u16 t_high;
1508 u16 pwm_min;
1509 u16 pwm_med;
1510 u16 pwm_high;
1511 u8 t_hyst;
1512 u32 cycle_delay;
1513 u16 t_max;
1514 u8 control_mode;
1515 u16 default_max_fan_pwm;
1516 u16 default_fan_output_sensitivity;
1517 u16 fan_output_sensitivity;
1518 bool ucode_fan_control;
1519};
1520
1521enum amdgpu_pcie_gen {
1522 AMDGPU_PCIE_GEN1 = 0,
1523 AMDGPU_PCIE_GEN2 = 1,
1524 AMDGPU_PCIE_GEN3 = 2,
1525 AMDGPU_PCIE_GEN_INVALID = 0xffff
1526};
1527
1528enum amdgpu_dpm_forced_level {
1529 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1530 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1531 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001532 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001533};
1534
1535struct amdgpu_vce_state {
1536 /* vce clocks */
1537 u32 evclk;
1538 u32 ecclk;
1539 /* gpu clocks */
1540 u32 sclk;
1541 u32 mclk;
1542 u8 clk_idx;
1543 u8 pstate;
1544};
1545
1546struct amdgpu_dpm_funcs {
1547 int (*get_temperature)(struct amdgpu_device *adev);
1548 int (*pre_set_power_state)(struct amdgpu_device *adev);
1549 int (*set_power_state)(struct amdgpu_device *adev);
1550 void (*post_set_power_state)(struct amdgpu_device *adev);
1551 void (*display_configuration_changed)(struct amdgpu_device *adev);
1552 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1553 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1554 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1555 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1556 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1557 bool (*vblank_too_short)(struct amdgpu_device *adev);
1558 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001559 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001560 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1561 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1562 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1563 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1564 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001565 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1566 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001567 int (*get_sclk_od)(struct amdgpu_device *adev);
1568 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001569 int (*get_mclk_od)(struct amdgpu_device *adev);
1570 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001571};
1572
1573struct amdgpu_dpm {
1574 struct amdgpu_ps *ps;
1575 /* number of valid power states */
1576 int num_ps;
1577 /* current power state that is active */
1578 struct amdgpu_ps *current_ps;
1579 /* requested power state */
1580 struct amdgpu_ps *requested_ps;
1581 /* boot up power state */
1582 struct amdgpu_ps *boot_ps;
1583 /* default uvd power state */
1584 struct amdgpu_ps *uvd_ps;
1585 /* vce requirements */
1586 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1587 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001588 enum amd_pm_state_type state;
1589 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001590 u32 platform_caps;
1591 u32 voltage_response_time;
1592 u32 backbias_response_time;
1593 void *priv;
1594 u32 new_active_crtcs;
1595 int new_active_crtc_count;
1596 u32 current_active_crtcs;
1597 int current_active_crtc_count;
1598 struct amdgpu_dpm_dynamic_state dyn_state;
1599 struct amdgpu_dpm_fan fan;
1600 u32 tdp_limit;
1601 u32 near_tdp_limit;
1602 u32 near_tdp_limit_adjusted;
1603 u32 sq_ramping_threshold;
1604 u32 cac_leakage;
1605 u16 tdp_od_limit;
1606 u32 tdp_adjustment;
1607 u16 load_line_slope;
1608 bool power_control;
1609 bool ac_power;
1610 /* special states active */
1611 bool thermal_active;
1612 bool uvd_active;
1613 bool vce_active;
1614 /* thermal handling */
1615 struct amdgpu_dpm_thermal thermal;
1616 /* forced levels */
1617 enum amdgpu_dpm_forced_level forced_level;
1618};
1619
1620struct amdgpu_pm {
1621 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001622 u32 current_sclk;
1623 u32 current_mclk;
1624 u32 default_sclk;
1625 u32 default_mclk;
1626 struct amdgpu_i2c_chan *i2c_bus;
1627 /* internal thermal controller on rv6xx+ */
1628 enum amdgpu_int_thermal_type int_thermal_type;
1629 struct device *int_hwmon_dev;
1630 /* fan control parameters */
1631 bool no_fan;
1632 u8 fan_pulses_per_revolution;
1633 u8 fan_min_rpm;
1634 u8 fan_max_rpm;
1635 /* dpm */
1636 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001637 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001638 struct amdgpu_dpm dpm;
1639 const struct firmware *fw; /* SMC firmware */
1640 uint32_t fw_version;
1641 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001642 uint32_t pcie_gen_mask;
1643 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001644 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001645};
1646
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001647void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1648
Alex Deucher97b2e202015-04-20 16:51:00 -04001649/*
1650 * UVD
1651 */
Arindam Nathc0365542016-04-12 13:46:15 +02001652#define AMDGPU_DEFAULT_UVD_HANDLES 10
1653#define AMDGPU_MAX_UVD_HANDLES 40
1654#define AMDGPU_UVD_STACK_SIZE (200*1024)
1655#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1656#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1657#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001658
1659struct amdgpu_uvd {
1660 struct amdgpu_bo *vcpu_bo;
1661 void *cpu_addr;
1662 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001663 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001664 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001665 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001666 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1667 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1668 struct delayed_work idle_work;
1669 const struct firmware *fw; /* UVD firmware */
1670 struct amdgpu_ring ring;
1671 struct amdgpu_irq_src irq;
1672 bool address_64_bit;
Christian König4cb5877c2016-07-26 12:05:40 +02001673 bool use_ctx_buf;
Christian Königead833e2016-02-10 14:35:19 +01001674 struct amd_sched_entity entity;
Chunming Zhoufc0b3b92016-07-18 17:18:01 +08001675 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001676};
1677
1678/*
1679 * VCE
1680 */
1681#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001682#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1683
Alex Deucher6a585772015-07-10 14:16:24 -04001684#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1685#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1686
Alex Deucher97b2e202015-04-20 16:51:00 -04001687struct amdgpu_vce {
1688 struct amdgpu_bo *vcpu_bo;
1689 uint64_t gpu_addr;
1690 unsigned fw_version;
1691 unsigned fb_version;
1692 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1693 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001694 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001695 struct delayed_work idle_work;
Christian Königebff4852016-07-20 16:53:36 +02001696 struct mutex idle_mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001697 const struct firmware *fw; /* VCE firmware */
1698 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1699 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001700 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001701 struct amd_sched_entity entity;
Chunming Zhou115933a2016-07-18 17:38:50 +08001702 uint32_t srbm_soft_reset;
Alex Deucher75c65482016-08-24 16:56:21 -04001703 unsigned num_rings;
Alex Deucher97b2e202015-04-20 16:51:00 -04001704};
1705
1706/*
1707 * SDMA
1708 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001709struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001710 /* SDMA firmware */
1711 const struct firmware *fw;
1712 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001713 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001714
1715 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001716 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001717};
1718
Alex Deucherc113ea12015-10-08 16:30:37 -04001719struct amdgpu_sdma {
1720 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
Ken Wang30d15742016-01-19 14:05:23 +08001721#ifdef CONFIG_DRM_AMDGPU_SI
1722 //SI DMA has a difference trap irq number for the second engine
1723 struct amdgpu_irq_src trap_irq_1;
1724#endif
Alex Deucherc113ea12015-10-08 16:30:37 -04001725 struct amdgpu_irq_src trap_irq;
1726 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001727 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001728 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001729};
1730
Alex Deucher97b2e202015-04-20 16:51:00 -04001731/*
1732 * Firmware
1733 */
1734struct amdgpu_firmware {
1735 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1736 bool smu_load;
1737 struct amdgpu_bo *fw_buf;
1738 unsigned int fw_size;
1739};
1740
1741/*
1742 * Benchmarking
1743 */
1744void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1745
1746
1747/*
1748 * Testing
1749 */
1750void amdgpu_test_moves(struct amdgpu_device *adev);
1751void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1752 struct amdgpu_ring *cpA,
1753 struct amdgpu_ring *cpB);
1754void amdgpu_test_syncing(struct amdgpu_device *adev);
1755
1756/*
1757 * MMU Notifier
1758 */
1759#if defined(CONFIG_MMU_NOTIFIER)
1760int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1761void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1762#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001763static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001764{
1765 return -ENODEV;
1766}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001767static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001768#endif
1769
1770/*
1771 * Debugfs
1772 */
1773struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001774 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001775 unsigned num_files;
1776};
1777
1778int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001779 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001780 unsigned nfiles);
1781int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1782
1783#if defined(CONFIG_DEBUG_FS)
1784int amdgpu_debugfs_init(struct drm_minor *minor);
1785void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1786#endif
1787
Huang Rui50ab2532016-06-12 15:51:09 +08001788int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1789
Alex Deucher97b2e202015-04-20 16:51:00 -04001790/*
1791 * amdgpu smumgr functions
1792 */
1793struct amdgpu_smumgr_funcs {
1794 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1795 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1796 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1797};
1798
1799/*
1800 * amdgpu smumgr
1801 */
1802struct amdgpu_smumgr {
1803 struct amdgpu_bo *toc_buf;
1804 struct amdgpu_bo *smu_buf;
1805 /* asic priv smu data */
1806 void *priv;
1807 spinlock_t smu_lock;
1808 /* smumgr functions */
1809 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1810 /* ucode loading complete flag */
1811 uint32_t fw_flags;
1812};
1813
1814/*
1815 * ASIC specific register table accessible by UMD
1816 */
1817struct amdgpu_allowed_register_entry {
1818 uint32_t reg_offset;
1819 bool untouched;
1820 bool grbm_indexed;
1821};
1822
Alex Deucher97b2e202015-04-20 16:51:00 -04001823/*
1824 * ASIC specific functions.
1825 */
1826struct amdgpu_asic_funcs {
1827 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001828 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1829 u8 *bios, u32 length_bytes);
Monk Liu4e99a442016-03-31 13:26:59 +08001830 void (*detect_hw_virtualization) (struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001831 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1832 u32 sh_num, u32 reg_offset, u32 *value);
1833 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1834 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001835 /* get the reference clock */
1836 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001837 /* MM block clocks */
1838 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1839 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Maruthi Bayyavarapu841686d2016-08-01 12:42:32 -04001840 /* static power management */
1841 int (*get_pcie_lanes)(struct amdgpu_device *adev);
1842 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001843};
1844
1845/*
1846 * IOCTL.
1847 */
1848int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1849 struct drm_file *filp);
1850int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1851 struct drm_file *filp);
1852
1853int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1854 struct drm_file *filp);
1855int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1856 struct drm_file *filp);
1857int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1858 struct drm_file *filp);
1859int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1860 struct drm_file *filp);
1861int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1862 struct drm_file *filp);
1863int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1864 struct drm_file *filp);
1865int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1866int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1867
1868int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1869 struct drm_file *filp);
1870
1871/* VRAM scratch page for HDP bug, default vram page */
1872struct amdgpu_vram_scratch {
1873 struct amdgpu_bo *robj;
1874 volatile uint32_t *ptr;
1875 u64 gpu_addr;
1876};
1877
1878/*
1879 * ACPI
1880 */
1881struct amdgpu_atif_notification_cfg {
1882 bool enabled;
1883 int command_code;
1884};
1885
1886struct amdgpu_atif_notifications {
1887 bool display_switch;
1888 bool expansion_mode_change;
1889 bool thermal_state;
1890 bool forced_power_state;
1891 bool system_power_state;
1892 bool display_conf_change;
1893 bool px_gfx_switch;
1894 bool brightness_change;
1895 bool dgpu_display_event;
1896};
1897
1898struct amdgpu_atif_functions {
1899 bool system_params;
1900 bool sbios_requests;
1901 bool select_active_disp;
1902 bool lid_state;
1903 bool get_tv_standard;
1904 bool set_tv_standard;
1905 bool get_panel_expansion_mode;
1906 bool set_panel_expansion_mode;
1907 bool temperature_change;
1908 bool graphics_device_types;
1909};
1910
1911struct amdgpu_atif {
1912 struct amdgpu_atif_notifications notifications;
1913 struct amdgpu_atif_functions functions;
1914 struct amdgpu_atif_notification_cfg notification_cfg;
1915 struct amdgpu_encoder *encoder_for_bl;
1916};
1917
1918struct amdgpu_atcs_functions {
1919 bool get_ext_state;
1920 bool pcie_perf_req;
1921 bool pcie_dev_rdy;
1922 bool pcie_bus_width;
1923};
1924
1925struct amdgpu_atcs {
1926 struct amdgpu_atcs_functions functions;
1927};
1928
Alex Deucher97b2e202015-04-20 16:51:00 -04001929/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001930 * CGS
1931 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001932struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1933void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001934
1935
Monk Liu4e99a442016-03-31 13:26:59 +08001936#define AMDGPU_SRIOV_CAPS_SRIOV_VBIOS (1 << 0) /* vBIOS is sr-iov ready */
1937#define AMDGPU_SRIOV_CAPS_ENABLE_IOV (1 << 1) /* sr-iov is enabled on this GPU */
1938#define AMDGPU_SRIOV_CAPS_IS_VF (1 << 2) /* this GPU is a virtual function */
1939#define AMDGPU_PASSTHROUGH_MODE (1 << 3) /* thw whole GPU is pass through for VM */
Alex Deucher7e471e62016-02-01 11:13:04 -05001940/* GPU virtualization */
1941struct amdgpu_virtualization {
Monk Liu4e99a442016-03-31 13:26:59 +08001942 uint32_t virtual_caps;
Alex Deucher7e471e62016-02-01 11:13:04 -05001943};
1944
Monk Liu4e99a442016-03-31 13:26:59 +08001945#define amdgpu_sriov_enabled(adev) \
1946((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_ENABLE_IOV)
1947
1948#define amdgpu_sriov_vf(adev) \
1949((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_IS_VF)
1950
1951#define amdgpu_sriov_bios(adev) \
1952((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS)
1953
1954#define amdgpu_passthrough(adev) \
1955((adev)->virtualization.virtual_caps & AMDGPU_PASSTHROUGH_MODE)
1956
1957static inline bool is_virtual_machine(void)
1958{
1959#ifdef CONFIG_X86
1960 return boot_cpu_has(X86_FEATURE_HYPERVISOR);
1961#else
1962 return false;
1963#endif
1964}
1965
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001966/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001967 * Core structure, functions and helpers.
1968 */
1969typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1970typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1971
1972typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1973typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1974
Alex Deucher8faf0e02015-07-28 11:50:31 -04001975struct amdgpu_ip_block_status {
1976 bool valid;
1977 bool sw;
1978 bool hw;
Chunming Zhou63fbf422016-07-15 11:19:20 +08001979 bool hang;
Alex Deucher8faf0e02015-07-28 11:50:31 -04001980};
1981
Alex Deucher97b2e202015-04-20 16:51:00 -04001982struct amdgpu_device {
1983 struct device *dev;
1984 struct drm_device *ddev;
1985 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001986
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001987#ifdef CONFIG_DRM_AMD_ACP
1988 struct amdgpu_acp acp;
1989#endif
1990
Alex Deucher97b2e202015-04-20 16:51:00 -04001991 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001992 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001993 uint32_t family;
1994 uint32_t rev_id;
1995 uint32_t external_rev_id;
1996 unsigned long flags;
1997 int usec_timeout;
1998 const struct amdgpu_asic_funcs *asic_funcs;
1999 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04002000 bool need_dma32;
2001 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02002002 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04002003 struct notifier_block acpi_nb;
2004 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
2005 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02002006 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04002007#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04002008 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04002009#endif
2010 struct amdgpu_atif atif;
2011 struct amdgpu_atcs atcs;
2012 struct mutex srbm_mutex;
2013 /* GRBM index mutex. Protects concurrent access to GRBM index */
2014 struct mutex grbm_idx_mutex;
2015 struct dev_pm_domain vga_pm_domain;
2016 bool have_disp_power_ref;
2017
2018 /* BIOS */
2019 uint8_t *bios;
2020 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04002021 struct amdgpu_bo *stollen_vga_memory;
2022 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
2023
2024 /* Register/doorbell mmio */
2025 resource_size_t rmmio_base;
2026 resource_size_t rmmio_size;
2027 void __iomem *rmmio;
2028 /* protects concurrent MM_INDEX/DATA based register access */
2029 spinlock_t mmio_idx_lock;
2030 /* protects concurrent SMC based register access */
2031 spinlock_t smc_idx_lock;
2032 amdgpu_rreg_t smc_rreg;
2033 amdgpu_wreg_t smc_wreg;
2034 /* protects concurrent PCIE register access */
2035 spinlock_t pcie_idx_lock;
2036 amdgpu_rreg_t pcie_rreg;
2037 amdgpu_wreg_t pcie_wreg;
Huang Rui36b9a952016-08-31 13:23:25 +08002038 amdgpu_rreg_t pciep_rreg;
2039 amdgpu_wreg_t pciep_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04002040 /* protects concurrent UVD register access */
2041 spinlock_t uvd_ctx_idx_lock;
2042 amdgpu_rreg_t uvd_ctx_rreg;
2043 amdgpu_wreg_t uvd_ctx_wreg;
2044 /* protects concurrent DIDT register access */
2045 spinlock_t didt_idx_lock;
2046 amdgpu_rreg_t didt_rreg;
2047 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08002048 /* protects concurrent gc_cac register access */
2049 spinlock_t gc_cac_idx_lock;
2050 amdgpu_rreg_t gc_cac_rreg;
2051 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04002052 /* protects concurrent ENDPOINT (audio) register access */
2053 spinlock_t audio_endpt_idx_lock;
2054 amdgpu_block_rreg_t audio_endpt_rreg;
2055 amdgpu_block_wreg_t audio_endpt_wreg;
2056 void __iomem *rio_mem;
2057 resource_size_t rio_mem_size;
2058 struct amdgpu_doorbell doorbell;
2059
2060 /* clock/pll info */
2061 struct amdgpu_clock clock;
2062
2063 /* MC */
2064 struct amdgpu_mc mc;
2065 struct amdgpu_gart gart;
2066 struct amdgpu_dummy_page dummy_page;
2067 struct amdgpu_vm_manager vm_manager;
2068
2069 /* memory management */
2070 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002071 struct amdgpu_vram_scratch vram_scratch;
2072 struct amdgpu_wb wb;
2073 atomic64_t vram_usage;
2074 atomic64_t vram_vis_usage;
2075 atomic64_t gtt_usage;
2076 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02002077 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02002078 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002079
Marek Olšák95844d22016-08-17 23:49:27 +02002080 /* data for buffer migration throttling */
2081 struct {
2082 spinlock_t lock;
2083 s64 last_update_us;
2084 s64 accum_us; /* accumulated microseconds */
2085 u32 log2_max_MBps;
2086 } mm_stats;
2087
Alex Deucher97b2e202015-04-20 16:51:00 -04002088 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08002089 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04002090 struct amdgpu_mode_info mode_info;
2091 struct work_struct hotplug_work;
2092 struct amdgpu_irq_src crtc_irq;
2093 struct amdgpu_irq_src pageflip_irq;
2094 struct amdgpu_irq_src hpd_irq;
2095
2096 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02002097 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002098 unsigned num_rings;
2099 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2100 bool ib_pool_ready;
2101 struct amdgpu_sa_manager ring_tmp_bo;
2102
2103 /* interrupts */
2104 struct amdgpu_irq irq;
2105
Alex Deucher1f7371b2015-12-02 17:46:21 -05002106 /* powerplay */
2107 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002108 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002109 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002110
Alex Deucher97b2e202015-04-20 16:51:00 -04002111 /* dpm */
2112 struct amdgpu_pm pm;
2113 u32 cg_flags;
2114 u32 pg_flags;
2115
2116 /* amdgpu smumgr */
2117 struct amdgpu_smumgr smu;
2118
2119 /* gfx */
2120 struct amdgpu_gfx gfx;
2121
2122 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002123 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002124
2125 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002126 struct amdgpu_uvd uvd;
2127
2128 /* vce */
2129 struct amdgpu_vce vce;
2130
2131 /* firmwares */
2132 struct amdgpu_firmware firmware;
2133
2134 /* GDS */
2135 struct amdgpu_gds gds;
2136
2137 const struct amdgpu_ip_block_version *ip_blocks;
2138 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002139 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002140 struct mutex mn_lock;
2141 DECLARE_HASHTABLE(mn_hash, 7);
2142
2143 /* tracking pinned memory */
2144 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002145 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002146 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002147
2148 /* amdkfd interface */
2149 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002150
Alex Deucher7e471e62016-02-01 11:13:04 -05002151 struct amdgpu_virtualization virtualization;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +08002152
2153 /* link all shadow bo */
2154 struct list_head shadow_list;
2155 struct mutex shadow_list_lock;
Chunming Zhou5c1354b2016-08-30 16:13:10 +08002156 /* link all gtt */
2157 spinlock_t gtt_list_lock;
2158 struct list_head gtt_list;
2159
Alex Deucher97b2e202015-04-20 16:51:00 -04002160};
2161
2162bool amdgpu_device_is_px(struct drm_device *dev);
2163int amdgpu_device_init(struct amdgpu_device *adev,
2164 struct drm_device *ddev,
2165 struct pci_dev *pdev,
2166 uint32_t flags);
2167void amdgpu_device_fini(struct amdgpu_device *adev);
2168int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2169
2170uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2171 bool always_indirect);
2172void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2173 bool always_indirect);
2174u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2175void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2176
2177u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2178void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2179
2180/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002181 * Registers read & write functions.
2182 */
2183#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2184#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2185#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2186#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2187#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2188#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2189#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2190#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2191#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
Huang Rui36b9a952016-08-31 13:23:25 +08002192#define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
2193#define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04002194#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2195#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2196#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2197#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2198#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2199#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08002200#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
2201#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04002202#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2203#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2204#define WREG32_P(reg, val, mask) \
2205 do { \
2206 uint32_t tmp_ = RREG32(reg); \
2207 tmp_ &= (mask); \
2208 tmp_ |= ((val) & ~(mask)); \
2209 WREG32(reg, tmp_); \
2210 } while (0)
2211#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2212#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2213#define WREG32_PLL_P(reg, val, mask) \
2214 do { \
2215 uint32_t tmp_ = RREG32_PLL(reg); \
2216 tmp_ &= (mask); \
2217 tmp_ |= ((val) & ~(mask)); \
2218 WREG32_PLL(reg, tmp_); \
2219 } while (0)
2220#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2221#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2222#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2223
2224#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2225#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2226
2227#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2228#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2229
2230#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2231 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2232 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2233
2234#define REG_GET_FIELD(value, reg, field) \
2235 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2236
Tom St Denis61cb8ce2016-08-09 10:13:21 -04002237#define WREG32_FIELD(reg, field, val) \
2238 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
2239
Alex Deucher97b2e202015-04-20 16:51:00 -04002240/*
2241 * BIOS helpers.
2242 */
2243#define RBIOS8(i) (adev->bios[i])
2244#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2245#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2246
2247/*
2248 * RING helpers.
2249 */
2250static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2251{
2252 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002253 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002254 ring->ring[ring->wptr++] = v;
2255 ring->wptr &= ring->ptr_mask;
2256 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002257}
2258
Alex Deucherc113ea12015-10-08 16:30:37 -04002259static inline struct amdgpu_sdma_instance *
2260amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002261{
2262 struct amdgpu_device *adev = ring->adev;
2263 int i;
2264
Alex Deucherc113ea12015-10-08 16:30:37 -04002265 for (i = 0; i < adev->sdma.num_instances; i++)
2266 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002267 break;
2268
2269 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002270 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002271 else
2272 return NULL;
2273}
2274
Alex Deucher97b2e202015-04-20 16:51:00 -04002275/*
2276 * ASICs macro.
2277 */
2278#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2279#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002280#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2281#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2282#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 -04002283#define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
2284#define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
2285#define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002286#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002287#define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
Monk Liu4e99a442016-03-31 13:26:59 +08002288#define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002289#define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002290#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2291#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2292#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 +02002293#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 -04002294#define amdgpu_vm_set_pte_pde(adev, ib, pe, addr, count, incr, flags) ((adev)->vm_manager.vm_pte_funcs->set_pte_pde((ib), (pe), (addr), (count), (incr), (flags)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002295#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2296#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02002297#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04002298#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2299#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2300#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002301#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 +01002302#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002303#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002304#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002305#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 +02002306#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002307#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Monk Liuc2167a62016-08-26 14:12:37 +08002308#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
Monk Liu753ad492016-08-26 13:28:28 +08002309#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
Christian König9e5d53092016-01-31 12:20:55 +01002310#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002311#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2312#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucherb6384ff2016-09-16 10:55:50 -04002313#define amdgpu_ring_get_emit_ib_size(r) (r)->funcs->get_emit_ib_size((r))
2314#define amdgpu_ring_get_dma_frame_size(r) (r)->funcs->get_dma_frame_size((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002315#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2316#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2317#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2318#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2319#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2320#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2321#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2322#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2323#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2324#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2325#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2326#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2327#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002328#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 -04002329#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2330#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2331#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))
2332#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2333#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002334#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 +08002335#define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
Alex Deucher97b2e202015-04-20 16:51:00 -04002336#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2337#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2338#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2339#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002340#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002341#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002342#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04002343#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04002344#define amdgpu_gfx_select_se_sh(adev, se, sh, instance) (adev)->gfx.funcs->select_se_sh((adev), (se), (sh), (instance))
Rex Zhu3af76f22015-10-15 17:23:43 +08002345
Tom St Denis3de4ec52016-09-19 12:48:52 -04002346#define amdgpu_dpm_read_sensor(adev, idx, value) \
2347 ((adev)->pp_enabled ? \
2348 (adev)->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, (idx), (value)) : \
2349 -EINVAL)
2350
Rex Zhu3af76f22015-10-15 17:23:43 +08002351#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002352 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002353 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002354 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002355
2356#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002357 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002358 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002359 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002360
2361#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002362 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002363 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002364 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002365
2366#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002367 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002368 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002369 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002370
2371#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002372 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002373 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002374 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002375
Rex Zhu1b5708f2015-11-10 18:25:24 -05002376#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002377 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002378 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002379 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002380
2381#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002382 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002383 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002384 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002385
2386
2387#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002388 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002389 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002390 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002391
2392#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002393 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002394 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002395 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002396
2397#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002398 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002399 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002400 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002401
Rex Zhu1b5708f2015-11-10 18:25:24 -05002402#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002403 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002404
2405#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002406 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002407
Eric Huangf3898ea2015-12-11 16:24:34 -05002408#define amdgpu_dpm_get_pp_num_states(adev, data) \
2409 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2410
2411#define amdgpu_dpm_get_pp_table(adev, table) \
2412 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2413
2414#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2415 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2416
2417#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2418 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2419
2420#define amdgpu_dpm_force_clock_level(adev, type, level) \
2421 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2422
Eric Huang428bafa2016-05-12 14:51:21 -04002423#define amdgpu_dpm_get_sclk_od(adev) \
2424 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2425
2426#define amdgpu_dpm_set_sclk_od(adev, value) \
2427 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2428
Eric Huangf2bdc052016-05-24 15:11:17 -04002429#define amdgpu_dpm_get_mclk_od(adev) \
2430 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2431
2432#define amdgpu_dpm_set_mclk_od(adev, value) \
2433 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2434
Jammy Zhoue61710c2015-11-10 18:31:08 -05002435#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002436 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002437
2438#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2439
2440/* Common functions */
2441int amdgpu_gpu_reset(struct amdgpu_device *adev);
Chunming Zhou3ad81f12016-08-05 17:30:17 +08002442bool amdgpu_need_backup(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002443void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2444bool amdgpu_card_posted(struct amdgpu_device *adev);
2445void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002446
Alex Deucher97b2e202015-04-20 16:51:00 -04002447int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2448int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2449 u32 ip_instance, u32 ring,
2450 struct amdgpu_ring **out_ring);
2451void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2452bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002453int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002454int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2455 uint32_t flags);
2456bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002457struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002458bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2459 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002460bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2461 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002462bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2463uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2464 struct ttm_mem_reg *mem);
2465void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2466void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2467void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Ken Wanga693e052016-07-27 19:18:01 +08002468u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2469int amdgpu_ttm_global_init(struct amdgpu_device *adev);
Baoyou Xie9f31a0b2016-09-15 21:43:26 +08002470int amdgpu_ttm_init(struct amdgpu_device *adev);
2471void amdgpu_ttm_fini(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002472void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2473 const u32 *registers,
2474 const u32 array_size);
2475
2476bool amdgpu_device_is_px(struct drm_device *dev);
2477/* atpx handler */
2478#if defined(CONFIG_VGA_SWITCHEROO)
2479void amdgpu_register_atpx_handler(void);
2480void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002481bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002482bool amdgpu_is_atpx_hybrid(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002483#else
2484static inline void amdgpu_register_atpx_handler(void) {}
2485static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002486static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002487static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002488#endif
2489
2490/*
2491 * KMS
2492 */
2493extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002494extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002495
2496int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2497int amdgpu_driver_unload_kms(struct drm_device *dev);
2498void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2499int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2500void amdgpu_driver_postclose_kms(struct drm_device *dev,
2501 struct drm_file *file_priv);
2502void amdgpu_driver_preclose_kms(struct drm_device *dev,
2503 struct drm_file *file_priv);
Alex Deucher810ddc32016-08-23 13:25:49 -04002504int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
2505int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002506u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2507int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2508void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2509int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002510 int *max_error,
2511 struct timeval *vblank_time,
2512 unsigned flags);
2513long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2514 unsigned long arg);
2515
2516/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002517 * functions used by amdgpu_encoder.c
2518 */
2519struct amdgpu_afmt_acr {
2520 u32 clock;
2521
2522 int n_32khz;
2523 int cts_32khz;
2524
2525 int n_44_1khz;
2526 int cts_44_1khz;
2527
2528 int n_48khz;
2529 int cts_48khz;
2530
2531};
2532
2533struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2534
2535/* amdgpu_acpi.c */
2536#if defined(CONFIG_ACPI)
2537int amdgpu_acpi_init(struct amdgpu_device *adev);
2538void amdgpu_acpi_fini(struct amdgpu_device *adev);
2539bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2540int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2541 u8 perf_req, bool advertise);
2542int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2543#else
2544static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2545static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2546#endif
2547
2548struct amdgpu_bo_va_mapping *
2549amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2550 uint64_t addr, struct amdgpu_bo **bo);
Christian Königc855e252016-09-05 17:00:57 +02002551int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
Alex Deucher97b2e202015-04-20 16:51:00 -04002552
2553#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002554#endif